This commit is contained in:
Anish Athalye
2018-10-06 09:52:47 -04:00
parent a9d7717cc4
commit da1f8392b1
56 changed files with 2696 additions and 37 deletions

View File

@@ -51,9 +51,20 @@ struct Env {
enum EnvType env_type; // Indicates special system environments
unsigned env_status; // Status of the environment
uint32_t env_runs; // Number of times environment has run
int env_cpunum; // The CPU that the env is running on
// Address space
pde_t *env_pgdir; // Kernel virtual address of page dir
// Exception handling
void *env_pgfault_upcall; // Page fault upcall entry point
// Lab 4 IPC
bool env_ipc_recving; // Env is blocked receiving
void *env_ipc_dstva; // VA at which to map received page
uint32_t env_ipc_value; // Data value sent to us
envid_t env_ipc_from; // envid of the sender
int env_ipc_perm; // Perm of page mapping received
};
#endif // !JOS_INC_ENV_H

View File

@@ -14,6 +14,9 @@ enum {
// the maximum allowed
E_FAULT , // Memory fault
E_IPC_NOT_RECV , // Attempt to send to env that is not recving
E_EOF , // Unexpected end of file
MAXERROR
};

View File

@@ -16,6 +16,7 @@
#include <inc/env.h>
#include <inc/memlayout.h>
#include <inc/syscall.h>
#include <inc/trap.h>
#define USED(x) (void)(x)
@@ -31,6 +32,9 @@ extern const volatile struct PageInfo pages[];
// exit.c
void exit(void);
// pgfault.c
void set_pgfault_handler(void (*handler)(struct UTrapframe *utf));
// readline.c
char* readline(const char *buf);
@@ -39,6 +43,37 @@ void sys_cputs(const char *string, size_t len);
int sys_cgetc(void);
envid_t sys_getenvid(void);
int sys_env_destroy(envid_t);
void sys_yield(void);
static envid_t sys_exofork(void);
int sys_env_set_status(envid_t env, int status);
int sys_env_set_pgfault_upcall(envid_t env, void *upcall);
int sys_page_alloc(envid_t env, void *pg, int perm);
int sys_page_map(envid_t src_env, void *src_pg,
envid_t dst_env, void *dst_pg, int perm);
int sys_page_unmap(envid_t env, void *pg);
int sys_ipc_try_send(envid_t to_env, uint32_t value, void *pg, int perm);
int sys_ipc_recv(void *rcv_pg);
// This must be inlined. Exercise for reader: why?
static inline envid_t __attribute__((always_inline))
sys_exofork(void)
{
envid_t ret;
asm volatile("int %2"
: "=a" (ret)
: "a" (SYS_exofork), "i" (T_SYSCALL));
return ret;
}
// ipc.c
void ipc_send(envid_t to_env, uint32_t value, void *pg, int perm);
int32_t ipc_recv(envid_t *from_env_store, void *pg, int *perm_store);
envid_t ipc_find_env(enum EnvType type);
// fork.c
#define PTE_SHARE 0x400
envid_t fork(void);
envid_t sfork(void); // Challenge!

View File

@@ -138,6 +138,9 @@
// The location of the user-level STABS data structure
#define USTABDATA (PTSIZE / 2)
// Physical address of startup code for non-boot CPUs (APs)
#define MPENTRY_PADDR 0x7000
#ifndef __ASSEMBLER__
typedef uint32_t pte_t;

View File

@@ -7,6 +7,15 @@ enum {
SYS_cgetc,
SYS_getenvid,
SYS_env_destroy,
SYS_page_alloc,
SYS_page_map,
SYS_page_unmap,
SYS_exofork,
SYS_env_set_status,
SYS_env_set_pgfault_upcall,
SYS_yield,
SYS_ipc_try_send,
SYS_ipc_recv,
NSYSCALLS
};

View File

@@ -74,6 +74,17 @@ struct Trapframe {
uint16_t tf_padding4;
} __attribute__((packed));
struct UTrapframe {
/* information about the fault */
uint32_t utf_fault_va; /* va for T_PGFLT, 0 otherwise */
uint32_t utf_err;
/* trap-time return state */
struct PushRegs utf_regs;
uintptr_t utf_eip;
uint32_t utf_eflags;
/* the trap-time stack to return to */
uintptr_t utf_esp;
} __attribute__((packed));
#endif /* !__ASSEMBLER__ */