* same with xv6
[mascara-docs.git] / i386 / ucla / src / lab5 / inc / env.h
blob6e1ea988fb06c9a9fdc4eadae16f380ae41e175a
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 // Special environment IDs
39 #define ENVID_BUFCACHE 0x1100
41 struct Env {
42 struct Env *env_next; // Next env on the free list
44 envid_t env_id; // Unique environment identifier
45 envid_t env_parent_id; // env_id of this env's parent
46 unsigned env_status; // Status of the environment
48 pde_t *env_pgdir; // Kernel virtual address of page dir
49 struct Trapframe env_tf; // Saved registers
50 uint32_t env_runs; // Number of times environment has run
52 // Exception handling
53 uintptr_t env_pgfault_upcall; // page fault upcall entry point
55 // Lab 4 IPC
56 bool env_ipc_recving; // env is blocked receiving
57 uintptr_t env_ipc_dstva; // va at which to map received page
58 uint32_t env_ipc_value; // data value sent to us
59 envid_t env_ipc_from; // envid of the sender
60 int env_ipc_perm; // perm of page mapping received
63 #endif // !JOS_INC_ENV_H