Skip to content

Commit

Permalink
cleanup mmu
Browse files Browse the repository at this point in the history
  • Loading branch information
yhzhang0128 committed Mar 31, 2022
1 parent 22395d3 commit c9530dc
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 18 deletions.
7 changes: 2 additions & 5 deletions earth/cpu_mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct translation_table_t {
} frame[NFRAMES];
} translate_table;

#define F_INUSE 0x1
#define FRAME_INUSE(x) (translate_table.frame[x].flag & F_INUSE)

int curr_vm_pid;
Expand Down Expand Up @@ -64,16 +65,12 @@ int mmu_free(int pid) {
return 0;
}

int mmu_map(int pid, int page_no, int frame_no, int flag) {
if (flag != F_ALL)
FATAL("Memory protection not implemented");

int mmu_map(int pid, int page_no, int frame_no) {
if (!FRAME_INUSE(frame_no))
FATAL("Frame %d has not been allocated", frame_no);

translate_table.frame[frame_no].pid = pid;
translate_table.frame[frame_no].page_no = page_no;
translate_table.frame[frame_no].flag = flag;
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion earth/earth.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ int intr_register(handler_t handler);
int excp_register(handler_t handler);

int mmu_alloc(int* frame_no, int* cached_addr);
int mmu_map(int pid, int page_no, int frame_no, int flag);
int mmu_map(int pid, int page_no, int frame_no);
int mmu_switch(int pid);
int mmu_free(int pid);

Expand Down
2 changes: 1 addition & 1 deletion library/egos.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct earth {

int (*mmu_alloc)(int* frame_no, int* cached_addr);
int (*mmu_free)(int pid);
int (*mmu_map)(int pid, int page_no, int frame_no, int flag);
int (*mmu_map)(int pid, int page_no, int frame_no);
int (*mmu_switch)(int pid);

/* Disk and tty device driver interface */
Expand Down
8 changes: 4 additions & 4 deletions library/elf/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static void load_app(int pid,
for (int off = 0; off < pheader->p_filesz; off += BLOCK_SIZE) {
if (off % PAGE_SIZE == 0) {
earth->mmu_alloc(&frame_no, &base);
earth->mmu_map(pid, page_no++, frame_no, F_ALL);
earth->mmu_map(pid, page_no++, frame_no);
}
reader(block_offset++, ((char*)base) + (off % PAGE_SIZE));
}
Expand All @@ -96,13 +96,13 @@ static void load_app(int pid,

while (page_no < APPS_SIZE / PAGE_SIZE) {
earth->mmu_alloc(&frame_no, &base);
earth->mmu_map(pid, page_no++, frame_no, F_ALL);
earth->mmu_map(pid, page_no++, frame_no);
memset((char*)base, 0, PAGE_SIZE);
}

/* allocate two pages for argc, argv and stack */
earth->mmu_alloc(&frame_no, &base);
earth->mmu_map(pid, page_no++, frame_no, F_ALL);
earth->mmu_map(pid, page_no++, frame_no);

/* base is at virtual address APPS_MAIN_ARG */
int* argc_addr = (int*)base;
Expand All @@ -116,7 +116,7 @@ static void load_app(int pid,
argv_addr[i] = (int)((char*)args_addr + i * CMD_ARG_LEN);

earth->mmu_alloc(&frame_no, &base);
earth->mmu_map(pid, page_no++, frame_no, F_ALL);
earth->mmu_map(pid, page_no++, frame_no);
}


7 changes: 0 additions & 7 deletions library/memory/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@
#define ITIM_START 0x08000000 /* 12KB earth data+stack */
/* earth code is in QSPI flash */

/* F stands for memory frame */
#define F_INUSE 0x1
#define F_READ 0x2
#define F_WRITE 0x4
#define F_EXEC 0x8
#define F_ALL 0xf

#undef malloc
#define malloc my_alloc
void* my_alloc(unsigned int size);
Expand Down

0 comments on commit c9530dc

Please sign in to comment.