diff --git a/risc_v/src/elf.rs b/risc_v/src/elf.rs index d0c8712..6f1d164 100755 --- a/risc_v/src/elf.rs +++ b/risc_v/src/elf.rs @@ -47,9 +47,9 @@ pub struct ProgramHeader { pub const TYPE_EXEC: u16 = 2; -pub const PROG_READ: u8 = 4; -pub const PROG_WRITE: u8 = 2; -pub const PROG_EXECUTE: u8 = 1; +pub const PROG_READ: u32 = 4; +pub const PROG_WRITE: u32 = 2; +pub const PROG_EXECUTE: u32 = 1; pub const MACHINE_RISCV: u16 = 0xf3; pub const PH_SEG_TYPE_NULL: u32 = 0; diff --git a/risc_v/src/test.rs b/risc_v/src/test.rs index db2d9fe..8adb684 100644 --- a/risc_v/src/test.rs +++ b/risc_v/src/test.rs @@ -222,6 +222,18 @@ pub fn test_elf() { } memcpy(ptr.add(ph.off), buffer.get().add(ph.off), ph.memsz); let pages = ph.memsz / PAGE_SIZE + 1; + let mut bits = EntryBits::User.val(); + // This sucks, but we check each bit in the flags to see if + // we need to add it to the PH permissions. + if ph.flags & elf::PROG_EXECUTE != 0 { + bits |= EntryBits::Execute.val(); + } + if ph.flags & elf::PROG_READ != 0 { + bits |= EntryBits::Read.val(); + } + if ph.flags & elf::PROG_WRITE != 0 { + bits |= EntryBits::Write.val(); + } for i in 0..pages { let vaddr = ph.vaddr + i * PAGE_SIZE; let paddr = ptr as usize + i * PAGE_SIZE; @@ -229,7 +241,7 @@ pub fn test_elf() { table, vaddr, paddr, - EntryBits::UserReadExecute.val(), + bits, 0, ); }