* same with xv6
[mascara-docs.git] / i386 / ucla / src / lab4 / inc / env.h
blob7c79b32bdb3b6c53b74b524bfcd5922d8837701f
1 /* See COPYRIGHT for copyright information. */
3 #ifndef JOS_INC_ENV_H
4 #define JOS_INC_ENV_H
6 #include <inc/types.h>
7 #include <inc/queue.h>
8 #include <inc/trap.h>
9 #include <inc/memlayout.h>
11 typedef int32_t envid_t;
13 // An environment ID 'envid_t' has three parts:
15 // +1+---------------21-----------------+--------10--------+
16 // |0| Uniqueifier | Environment |
17 // | | | Index |
18 // +------------------------------------+------------------+
19 // \--- ENVX(eid) --/
21 // The environment index ENVX(eid) equals the environment's offset in the
22 // 'envs[]' array. The uniqueifier distinguishes environments that were
23 // created at different times, but share the same environment index.
25 // All real environments are greater than 0 (so the sign bit is zero).
26 // envid_ts less than 0 signify errors. The envid_t == 0 is special, and
27 // stands for the current environment.
29 #define LOG2NENV 10
30 #define NENV (1 << LOG2NENV)
31 #define ENVX(envid) ((envid) & (NENV - 1))
33 // Values of env_status in struct Env
34 #define ENV_FREE 0
35 #define ENV_RUNNABLE 1
36 #define ENV_NOT_RUNNABLE 2
38 struct Env {
39 struct Env *env_next; // Next env on the free list
41 envid_t env_id; // Unique environment identifier
42 envid_t env_parent_id; // env_id of this env's parent
43 unsigned env_status; // Status of the environment
45 pde_t *env_pgdir; // Kernel virtual address of page dir
46 struct Trapframe env_tf; // Saved registers
47 uint32_t env_runs; // Number of times environment has run
49 // Exception handling
50 uintptr_t env_pgfault_upcall; // page fault upcall entry point
52 // Lab 4 IPC
53 bool env_ipc_recving; // env is blocked receiving
54 uintptr_t env_ipc_dstva; // va at which to map received page
55 uint32_t env_ipc_value; // data value sent to us
56 envid_t env_ipc_from; // envid of the sender
57 int env_ipc_perm; // perm of page mapping received
60 #endif // !JOS_INC_ENV_H