summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/defs.h5
-rw-r--r--include/kdefs.h5
-rw-r--r--include/offsets.h85
-rw-r--r--include/params.h6
-rw-r--r--include/procs.h6
-rw-r--r--include/user.h3
-rw-r--r--include/vm.h131
7 files changed, 194 insertions, 47 deletions
diff --git a/include/defs.h b/include/defs.h
index cb29fc3..018b14e 100644
--- a/include/defs.h
+++ b/include/defs.h
@@ -36,9 +36,6 @@
#define CHAN_CIO 0
#define CHAN_SIO 1
-// maximum allowable number of command-line arguments
-#define MAX_ARGS 10
-
// sizes of various things
#define NUM_1KB 0x00000400 // 2^10
#define NUM_4KB 0x00001000 // 2^12
@@ -46,7 +43,7 @@
#define NUM_4MB 0x00400000 // 2^22
#define NUM_1GB 0x40000000 // 2^30
#define NUM_2GB 0x80000000 // 2^31
-#define NUM_3GB 0xc0000000
+#define NUM_3GB 0xc0000000 // 1GB + 2GB
#ifndef ASM_SRC
diff --git a/include/kdefs.h b/include/kdefs.h
index 80ee3c7..d26fa3d 100644
--- a/include/kdefs.h
+++ b/include/kdefs.h
@@ -30,6 +30,11 @@
// declarations for modulus checking of (e.g.) sizes and addresses
+#define LOW_9_BITS 0x00000fff
+#define LOW_22_BITS 0x003fffff
+#define HIGH_20_BITS 0xfffff000
+#define HIGH_10_BITS 0xffc00000
+
#define MOD4_BITS 0x00000003
#define MOD4_MASK 0xfffffffc
#define MOD4_INC 0x00000004
diff --git a/include/offsets.h b/include/offsets.h
new file mode 100644
index 0000000..c0cc029
--- /dev/null
+++ b/include/offsets.h
@@ -0,0 +1,85 @@
+/**
+** @file offsets.h
+**
+** GENERATED AUTOMATICALLY - DO NOT EDIT
+**
+** Creation date: Mon Mar 31 11:38:04 2025
+**
+** This header file contains C Preprocessor macros which expand
+** into the byte offsets needed to reach fields within structs
+** used in the baseline system. Should those struct declarations
+** change, the Offsets program should be modified (if needed),
+** recompiled, and re-run to recreate this file.
+*/
+
+#ifndef OFFSETS_H_
+#define OFFSETS_H_
+
+// Sizes of basic types
+
+#define SZ_char 1
+#define SZ_short 2
+#define SZ_int 4
+#define SZ_long 4
+#define SZ_long_long 8
+#define SZ_pointer 4
+
+// Sizes of our types
+
+#define SZ_int8_t 1
+#define SZ_uint8_t 1
+#define SZ_int16_t 2
+#define SZ_uint16_t 2
+#define SZ_int32_t 4
+#define SZ_uint32_t 4
+#define SZ_int64_t 8
+#define SZ_uint64_t 8
+#define SZ_bool_t 1
+
+// context_t structure
+
+#define SZ_CTX 72
+
+#define CTX_ss 0
+#define CTX_gs 4
+#define CTX_fs 8
+#define CTX_es 12
+#define CTX_ds 16
+#define CTX_edi 20
+#define CTX_esi 24
+#define CTX_ebp 28
+#define CTX_esp 32
+#define CTX_ebx 36
+#define CTX_edx 40
+#define CTX_ecx 44
+#define CTX_eax 48
+#define CTX_vector 52
+#define CTX_code 56
+#define CTX_eip 60
+#define CTX_cs 64
+#define CTX_eflags 68
+
+// section_t structure
+
+#define SZ_SCT 8
+
+#define SCT_length 0
+#define SCT_addr 4
+
+// pcb_t structure
+
+#define SZ_PCB 72
+
+#define PCB_context 0
+#define PCB_pdir 4
+#define PCB_sects 8
+#define PCB_next 40
+#define PCB_parent 44
+#define PCB_wakeup 48
+#define PCB_exit_status 52
+#define PCB_pid 56
+#define PCB_state 60
+#define PCB_priority 64
+#define PCB_ticks 68
+
+#endif
diff --git a/include/params.h b/include/params.h
index dabbe8d..7a41e02 100644
--- a/include/params.h
+++ b/include/params.h
@@ -20,11 +20,13 @@
// Upper bound on the number of simultaneous user-level
// processes in the system (completely arbitrary)
-
#define N_PROCS 25
-// Clock frequency (Hz)
+// Limit on the number of entries in argv[], INCLUDING
+// the trailing NULL pointer (also completely arbitrary)
+#define N_ARGS 10
+// Clock frequency (Hz)
#define CLOCK_FREQ 1000
#define TICKS_PER_MS 1
diff --git a/include/procs.h b/include/procs.h
index 9e4d8e6..bc5b705 100644
--- a/include/procs.h
+++ b/include/procs.h
@@ -205,13 +205,13 @@ extern uint_t next_pid;
extern pcb_t *init_pcb;
// table of state name strings
-extern const char *state_str[N_STATES];
+extern const char state_str[N_STATES][4];
// table of priority name strings
-extern const char *prio_str[N_PRIOS];
+extern const char prio_str[N_PRIOS][5];
// table of queue ordering name strings
-extern const char *ord_str[N_ORDERINGS];
+extern const char ord_str[N_ORDERINGS][5];
/*
** Prototypes
diff --git a/include/user.h b/include/user.h
index 8eef187..672f916 100644
--- a/include/user.h
+++ b/include/user.h
@@ -118,10 +118,11 @@ int user_duplicate(pcb_t *new, pcb_t *old);
** @param prog A pointer to the program table entry to be loaded
** @param pcb The PCB for the program being loaded
** @param args The argument vector for the program
+** @param sys Is the argument vector from kernel code?
**
** @return the status of the load attempt
*/
-int user_load(prog_t *prog, pcb_t *pcb, const char **args);
+int user_load(prog_t *prog, pcb_t *pcb, const char **args, bool_t sys);
/**
** Name: user_cleanup
diff --git a/include/vm.h b/include/vm.h
index 8eac999..dc12568 100644
--- a/include/vm.h
+++ b/include/vm.h
@@ -64,16 +64,20 @@
*/
// user virtual addresses
+#define USER_BASE 0x00000000
+#define USER_MAX 0x003fffff
#define USER_TEXT 0x00001000
#define USER_STACK 0x003fe000
+#define USER_STACK_P1 USER_STACK
+#define USER_STACK_P2 0x003ff000
#define USER_STK_END 0x00400000
// how to find the addresses of the stack pages in the VM hierarchy
// user address space is the first 4MB of virtual memory
#define USER_PDE 0
-// the stack occupies the last two pages of the address space
-#define USER_STK_PTE1 1022
-#define USER_STK_PTE2 1023
+// the stack occupies this range of pages in the user address space
+#define USER_STK_FIRST_PTE 1022
+#define USER_STK_LAST_PTE 1023
// some important memory addresses
#define KERN_BASE 0x80000000 // start of "kernel" memory
@@ -173,7 +177,7 @@
#define IS_USER(entry) (((entry) & PDE_US) != 0)
// low-order nine bits of PDEs and PTEs hold "permission" flag bits
-#define PERMS_MASK MOD4K_MASK
+#define PERMS_MASK MOD4K_BITS
// 4KB frame numbers are 20 bits wide
#define FRAME_4K_SHIFT 12
@@ -200,10 +204,14 @@
// everything has nine bits of permission flags
#define PERMS(p) (((uint32_t)(p)) & PERMS_MASK)
-// extract the table indices from a 32-bit address
+// extract the table indices from a 32-bit VA
#define PDIX(v) ((((uint32_t)(v)) >> PDIX_SHIFT) & PIX2I_MASK)
#define PTIX(v) ((((uint32_t)(v)) >> PTIX_SHIFT) & PIX2I_MASK)
+// extract the byte offset from a 32-bit VA
+#define OFFSET_4K(v) (((uint32_t)(v)) & MOD4K_BITS)
+#define OFFSET_4M(v) (((uint32_t)(v)) & MOD4M_BITS)
+
/*
** Types
*/
@@ -215,31 +223,34 @@
// PDE for 4KB pages
typedef struct pdek_s {
- uint_t p : 1; // present
- uint_t rw : 1; // writable
- uint_t us : 1; // user/supervisor
- uint_t pwt : 1; // cache write-through
- uint_t pcd : 1; // cache disable
- uint_t a : 1; // accessed
- uint_t avl1 : 1; // ignored (available)
- uint_t ps : 1; // page size (must be 0)
- uint_t avl2 : 4; // ignored (available)
- uint_t fa : 20; // frame address
+ uint_t p : 1; // 0: present
+ uint_t rw : 1; // 1: writable
+ uint_t us : 1; // 2: user/supervisor
+ uint_t pwt : 1; // 3: cache write-through
+ uint_t pcd : 1; // 4: cache disable
+ uint_t a : 1; // 5: accessed
+ uint_t avl1 : 1; // 6: ignored (available)
+ uint_t ps : 1; // 7: page size (must be 0)
+ uint_t avl2 : 4; // 11-8: ignored (available)
+ uint_t fa : 20; // 31-12: frame address
} pdek_f_t;
// PDE for 4MB pages
typedef struct pdem_s {
- uint_t p : 1; // present
- uint_t rw : 1; // writable
- uint_t us : 1; // user/supervisor
- uint_t pwt : 1; // cache write-through
- uint_t pcd : 1; // cache disable
- uint_t a : 1; // accessed
- uint_t d : 1; // dirty
- uint_t ps : 1; // page size (must be 1)
- uint_t g : 1; // global
- uint_t avl : 3; // ignored (available)
- uint_t fa : 20; // frame address
+ uint_t p : 1; // 0: present
+ uint_t rw : 1; // 1: writable
+ uint_t us : 1; // 2: user/supervisor
+ uint_t pwt : 1; // 3: cache write-through
+ uint_t pcd : 1; // 4: cache disable
+ uint_t a : 1; // 5: accessed
+ uint_t d : 1; // 6: dirty
+ uint_t ps : 1; // 7: page size (must be 1)
+ uint_t g : 1; // 8: global
+ uint_t avl : 3; // 11-9: ignored (available)
+ uint_t pat : 1; // 12: page attribute table in use
+ uint_t fa2 : 4; // 16-13: bits 35-32 of frame address (36-bit addrs)
+ uint_t rsv : 5; // 21-17: reserved - must be zero
+ uint_t fa : 10; // 31-22: bits 31-22 of frame address
} pdem_f_t;
// page table entries
@@ -249,17 +260,17 @@ typedef struct pdem_s {
// broken out into fields
typedef struct pte_s {
- uint_t p : 1; // present
- uint_t rw : 1; // writable
- uint_t us : 1; // user/supervisor
- uint_t pwt : 1; // cache write-through
- uint_t pcd : 1; // cache disable
- uint_t a : 1; // accessed
- uint_t d : 1; // dirty
- uint_t pat : 1; // page attribute table in use
- uint_t g : 1; // global
- uint_t avl : 3; // ignored (available)
- uint_t fa : 20; // frame address
+ uint_t p : 1; // 0: present
+ uint_t rw : 1; // 1: writable
+ uint_t us : 1; // 2: user/supervisor
+ uint_t pwt : 1; // 3: cache write-through
+ uint_t pcd : 1; // 4: cache disable
+ uint_t a : 1; // 5: accessed
+ uint_t d : 1; // 6: dirty
+ uint_t pat : 1; // 7: page attribute table in use
+ uint_t g : 1; // 8: global
+ uint_t avl : 3; // 11-9: ignored (available)
+ uint_t fa : 20; // 31-12: frame address
} ptef_t;
// page fault error code bits
@@ -291,6 +302,17 @@ typedef struct mapping_t {
uint32_t perm; // access control
} mapping_t;
+// Modes for dumping out page hierarchies
+enum vmmode_e {
+ Simple = 0, // just count 'present' entries at each level
+ OneLevel, // top-level only: count entries, decode 'present'
+ TwoLevel, // count entries & decode at each level
+ Full // ??? in case we need more?
+ // sentinel
+ ,
+ N_VMMODES
+};
+
/*
** Globals
*/
@@ -313,6 +335,19 @@ extern pde_t *kpdir;
void vm_init(void);
/**
+** Name: vm_uva2kva
+**
+** Convert a user VA into a kernel address. Works for all addresses -
+** if the address is a page address, the low-order nine bits will be
+** zeroes; otherwise, they is the offset into the page, which is
+** unchanged within the address spaces.
+**
+** @param pdir Pointer to the page directory to examine
+** @param va Virtual address to check
+*/
+void *vm_uva2kva(pde_t *pdir, void *va);
+
+/**
** Name: vm_pagedup
**
** Duplicate a page of memory
@@ -324,6 +359,17 @@ void vm_init(void);
void *vm_pagedup(void *old);
/**
+** Name: vm_pdedup
+**
+** Duplicate a page directory entry
+**
+** @param entry The entry to be duplicated
+**
+** @return the new entry, or -1 on error.
+*/
+pde_t vm_pdedup(pde_t entry);
+
+/**
** Name: vm_ptdup
**
** Duplicate a page directory entry
@@ -439,6 +485,17 @@ int vm_map(pde_t *pdir, void *va, uint32_t pa, uint32_t size, int perm);
*/
int vm_uvmdup(pde_t *new, pde_t *old);
+/**
+** Name: vm_print
+**
+** Print out a paging hierarchy.
+**
+** @param pt Page table to display
+** @param dir Is it a page directory (vs. a page table)?
+** @param mode How to display the entries
+*/
+void vm_print(void *pt, bool_t dir, enum vmmode_e mode);
+
#endif /* !ASM_SRC */
#endif