Skip to content

Commit

Permalink
Try to run PMP protection on QEMU
Browse files Browse the repository at this point in the history
  • Loading branch information
yhzhang0128 committed Dec 25, 2022
1 parent e2bd778 commit 0f5cd70
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions earth/cpu_mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,16 @@ void mmu_init() {

char buf[2];
for (buf[0] = 0; buf[0] != '0' && buf[0] != '1'; earth->tty_read(buf, 2));
INFO("%s translation is chosen", (buf[0] == '0')? "Page table" : "Software");
earth->translation = (buf[0] == '0') ? PAGE_TABLE : SOFT_TLB;
INFO("%s translation is chosen", earth->translation == PAGE_TABLE ? "Page table" : "Software");

/* Check whether the hardware platform supports supervisor mode */
earth->platform = QEMU;
earth->excp_register(platform_detect);
/* This memory access triggers an exception on Arty, but not QEMU */
*(int*)(0x1000) = 1;
earth->excp_register(NULL);
if (earth->platform == ARTY && buf[0] == '0')
if (earth->platform == ARTY && earth->translation == PAGE_TABLE)
FATAL("Arty board doesn't support page tables (supervisor mode).");

/* Initialize MMU interface functions */
Expand All @@ -165,7 +166,7 @@ void mmu_init() {
earth->mmu_map = soft_mmu_map;
earth->mmu_switch = soft_mmu_switch;

if (buf[0] == '0') {
if (earth->translation == PAGE_TABLE) {
pagetable_identity_mapping(0);
earth->mmu_map = pagetable_mmu_map;
earth->mmu_switch = pagetable_mmu_switch;
Expand Down
2 changes: 1 addition & 1 deletion earth/earth.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int main() {
earth_init();
elf_load(0, grass_read, 0, 0);

if (earth->platform == ARTY){
if (earth->translation == SOFT_TLB){
/* Arty board does not support supervisor mode */
void (*grass_entry)() = (void*)GRASS_ENTRY;
grass_entry();
Expand Down
2 changes: 1 addition & 1 deletion grass/grass.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int main() {

timer_reset();
/* For QEMU, interrupt has been enabled in machine-mode earth layer */
if (earth->platform == ARTY) earth->intr_enable();
if (earth->translation == SOFT_TLB) earth->intr_enable();

void (*sys_proc_entry)() = (void*)APPS_ENTRY;
asm("mv a0, %0" ::"r"(APPS_ARG));
Expand Down
1 change: 1 addition & 0 deletions library/egos.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct earth {

/* QEMU or Arty, detected in mmu_init() */
enum { QEMU, ARTY } platform;
enum { PAGE_TABLE, SOFT_TLB } translation;
};

#define MAX_NPROCESS 16
Expand Down

0 comments on commit 0f5cd70

Please sign in to comment.