5 changed files with 187 additions and 22 deletions
@ -0,0 +1,38 @@ |
|||
#include "../riscv/encoding.h" |
|||
#define PGSHIFT 12 |
|||
|
|||
.global main |
|||
|
|||
.section .text |
|||
main: |
|||
# Set up a page table entry that maps 0x0... to 0x8... |
|||
la t0, page_table |
|||
srli t0, t0, PGSHIFT |
|||
csrw CSR_SPTBR, t0 |
|||
|
|||
# update mstatus |
|||
csrr t1, CSR_MSTATUS |
|||
li t0, (MSTATUS_MPRV | (VM_SV39 << 24)) |
|||
#li t0, ((VM_SV39 << 24)) |
|||
or t1, t0, t1 |
|||
csrw CSR_MSTATUS, t1 |
|||
|
|||
la t0, (loop - 0x80000000) |
|||
csrw CSR_MEPC, t0 |
|||
|
|||
# Exit supervisor mode, entering user mode at loop. |
|||
mret |
|||
|
|||
loop: |
|||
la t0, data |
|||
lw t1, 0(t0) |
|||
j loop |
|||
|
|||
.section .data |
|||
data: |
|||
.word 0xbead |
|||
|
|||
.balign 0x1000 |
|||
page_table: |
|||
.word ((0x80000000 >> 2) | PTE_V | PTE_TYPE_URWX_SRWX) |
|||
.word 0 |
|||
@ -0,0 +1,90 @@ |
|||
OUTPUT_ARCH( "riscv" ) |
|||
|
|||
ENTRY( main ) |
|||
|
|||
SECTIONS |
|||
{ |
|||
|
|||
/*--------------------------------------------------------------------*/ |
|||
/* Code and read-only segment */ |
|||
/*--------------------------------------------------------------------*/ |
|||
|
|||
/* Begining of code and text segment */ |
|||
. = 0x80000000; |
|||
_ftext = .; |
|||
PROVIDE( eprol = . ); |
|||
|
|||
.text : |
|||
{ |
|||
*(.text.init) |
|||
} |
|||
|
|||
/* text: Program code section */ |
|||
.text : |
|||
{ |
|||
*(.text) |
|||
*(.text.*) |
|||
*(.gnu.linkonce.t.*) |
|||
} |
|||
|
|||
/* rodata: Read-only data */ |
|||
.rodata : |
|||
{ |
|||
*(.rdata) |
|||
*(.rodata) |
|||
*(.rodata.*) |
|||
*(.gnu.linkonce.r.*) |
|||
} |
|||
|
|||
/* End of code and read-only segment */ |
|||
PROVIDE( etext = . ); |
|||
_etext = .; |
|||
|
|||
/*--------------------------------------------------------------------*/ |
|||
/* Initialized data segment */ |
|||
/*--------------------------------------------------------------------*/ |
|||
|
|||
/* Start of initialized data segment */ |
|||
. = ALIGN(16); |
|||
_fdata = .; |
|||
|
|||
/* data: Writable data */ |
|||
.data : |
|||
{ |
|||
*(.data) |
|||
*(.data.*) |
|||
*(.srodata*) |
|||
*(.gnu.linkonce.d.*) |
|||
*(.comment) |
|||
} |
|||
|
|||
/* End of initialized data segment */ |
|||
. = ALIGN(4); |
|||
PROVIDE( edata = . ); |
|||
_edata = .; |
|||
|
|||
/*--------------------------------------------------------------------*/ |
|||
/* Uninitialized data segment */ |
|||
/*--------------------------------------------------------------------*/ |
|||
|
|||
/* Start of uninitialized data segment */ |
|||
. = .; |
|||
_fbss = .; |
|||
|
|||
/* sbss: Uninitialized writeable small data section */ |
|||
. = .; |
|||
|
|||
/* bss: Uninitialized writeable data section */ |
|||
. = .; |
|||
_bss_start = .; |
|||
.bss : |
|||
{ |
|||
*(.bss) |
|||
*(.bss.*) |
|||
*(.sbss*) |
|||
*(.gnu.linkonce.b.*) |
|||
*(COMMON) |
|||
} |
|||
|
|||
_end = .; |
|||
} |
|||
Loading…
Reference in new issue