Skip to content

Commit

Permalink
Add new project on memory protection and exception
Browse files Browse the repository at this point in the history
  • Loading branch information
yhzhang0128 committed May 31, 2022
1 parent 4e3457c commit 1664ae1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ github.com/AlDanial/cloc v 1.92 T=0.03 s (1668.0 files/s, 105414.7 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
C 35 454 490 1565
C/C++ Header 11 74 105 313
C 35 467 507 1563
C/C++ Header 11 74 105 315
Assembly 3 6 24 68
make 1 11 0 54
-------------------------------------------------------------------------------
SUM: 50 545 619 2000 << exactly 2000!
SUM: 50 558 636 2000 << exactly 2000!
-------------------------------------------------------------------------------
```
Expand Down
23 changes: 23 additions & 0 deletions grass/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,31 @@

void intr_entry(int id);

void excp_entry(int id) {
/* Student's code goes here: */

/* Kill the process if curr_pid is a user app instead of a grass server */

/* Student's code ends here. */

FATAL("excp_entry: kernel got exception %d", id);
}

void proc_init() {
earth->intr_register(intr_entry);
earth->excp_register(excp_entry);

/* Student's code goes here: */

/* Setup PMP TOR region 0x00000000 - 0x08008000 as r/w/x */

/* Setup PMP NAPOT region 0x20400000 - 0x20800000 as r/-/x */

/* Setup PMP NAPOT region 0x20800000 - 0x20C00000 as r/-/- */

/* Setup PMP NAPOT region 0x80000000 - 0x80004000 as r/w/- */

/* Student's code ends here. */

/* The first process is currently running */
proc_set_running(proc_alloc());
Expand Down
2 changes: 2 additions & 0 deletions grass/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ struct process{
};
extern int proc_curr_idx;
extern struct process proc_set[MAX_NPROCESS];
#define curr_pid proc_set[proc_curr_idx].pid
#define curr_status proc_set[proc_curr_idx].status

enum {
PROC_UNUSED,
Expand Down
12 changes: 9 additions & 3 deletions grass/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ static void proc_syscall();
static void (*kernel_entry)();

int proc_curr_idx;
struct process proc_set[MAX_NPROCESS];
#define curr_pid proc_set[proc_curr_idx].pid
#define curr_status proc_set[proc_curr_idx].status
struct process proc_set[MAX_NPROCESS];

void intr_entry(int id) {
if (curr_pid < GPID_SHELL && id == INTR_ID_TMR) {
Expand Down Expand Up @@ -85,6 +83,14 @@ static void proc_yield() {
earth->mmu_switch(curr_pid);
timer_reset();

/* Student's code goes here: */

/* Modify mstatus.MPP to enter machine or user mode during mret
* depending on whether curr_pid is a grass server or a user app
*/

/* Student's code ends here. */

if (curr_status == PROC_READY) {
proc_set_running(curr_pid);
/* Prepare argc and argv */
Expand Down

0 comments on commit 1664ae1

Please sign in to comment.