From 6344f80a9bae5804dfc281ad49eab492aef96049 Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Wed, 15 May 2019 23:12:06 +0800 Subject: [PATCH] Support efault fixup for riscv --- kernel/src/arch/riscv32/board/k210/linker.ld | 3 +++ kernel/src/arch/riscv32/board/rocket_chip/linker.ld | 3 +++ kernel/src/arch/riscv32/board/u540/linker.ld | 3 +++ kernel/src/arch/riscv32/boot/linker.ld | 3 +++ kernel/src/arch/riscv32/boot/linker64.ld | 3 +++ kernel/src/arch/riscv32/interrupt.rs | 9 +++++++++ user | 2 +- 7 files changed, 25 insertions(+), 1 deletion(-) diff --git a/kernel/src/arch/riscv32/board/k210/linker.ld b/kernel/src/arch/riscv32/board/k210/linker.ld index 7abc05b..7377957 100644 --- a/kernel/src/arch/riscv32/board/k210/linker.ld +++ b/kernel/src/arch/riscv32/board/k210/linker.ld @@ -17,6 +17,9 @@ SECTIONS .text : { stext = .; *(.text.entry) + _copy_user_start = .; + *(.text.copy_user) + _copy_user_end = .; *(.text .text.*) . = ALIGN(4K); etext = .; diff --git a/kernel/src/arch/riscv32/board/rocket_chip/linker.ld b/kernel/src/arch/riscv32/board/rocket_chip/linker.ld index ba9d08a..e5dc177 100644 --- a/kernel/src/arch/riscv32/board/rocket_chip/linker.ld +++ b/kernel/src/arch/riscv32/board/rocket_chip/linker.ld @@ -17,6 +17,9 @@ SECTIONS .text : { stext = .; *(.text.entry) + _copy_user_start = .; + *(.text.copy_user) + _copy_user_end = .; *(.text .text.*) . = ALIGN(4K); etext = .; diff --git a/kernel/src/arch/riscv32/board/u540/linker.ld b/kernel/src/arch/riscv32/board/u540/linker.ld index 87ca826..3cd94fc 100644 --- a/kernel/src/arch/riscv32/board/u540/linker.ld +++ b/kernel/src/arch/riscv32/board/u540/linker.ld @@ -17,6 +17,9 @@ SECTIONS .text : { stext = .; *(.text.entry) + _copy_user_start = .; + *(.text.copy_user) + _copy_user_end = .; *(.text .text.*) . = ALIGN(4K); etext = .; diff --git a/kernel/src/arch/riscv32/boot/linker.ld b/kernel/src/arch/riscv32/boot/linker.ld index b9efafa..3f0c386 100644 --- a/kernel/src/arch/riscv32/boot/linker.ld +++ b/kernel/src/arch/riscv32/boot/linker.ld @@ -22,6 +22,9 @@ SECTIONS .text : { stext = .; *(.text.entry) + _copy_user_start = .; + *(.text.copy_user) + _copy_user_end = .; *(.text .text.*) . = ALIGN(4K); etext = .; diff --git a/kernel/src/arch/riscv32/boot/linker64.ld b/kernel/src/arch/riscv32/boot/linker64.ld index 87ca826..3cd94fc 100644 --- a/kernel/src/arch/riscv32/boot/linker64.ld +++ b/kernel/src/arch/riscv32/boot/linker64.ld @@ -17,6 +17,9 @@ SECTIONS .text : { stext = .; *(.text.entry) + _copy_user_start = .; + *(.text.copy_user) + _copy_user_end = .; *(.text .text.*) . = ALIGN(4K); etext = .; diff --git a/kernel/src/arch/riscv32/interrupt.rs b/kernel/src/arch/riscv32/interrupt.rs index 12735f6..d8dfa78 100644 --- a/kernel/src/arch/riscv32/interrupt.rs +++ b/kernel/src/arch/riscv32/interrupt.rs @@ -132,6 +132,15 @@ fn page_fault(tf: &mut TrapFrame) { trace!("\nEXCEPTION: Page Fault @ {:#x}", addr); if !crate::memory::handle_page_fault(addr) { + extern "C" { + fn _copy_user_start(); + fn _copy_user_end(); + } + if tf.sepc >= _copy_user_start as usize && tf.sepc < _copy_user_end as usize { + debug!("fixup for addr {:x?}", addr); + tf.sepc = crate::memory::read_user_fixup as usize; + return; + } crate::trap::error(tf); } } diff --git a/user b/user index ad822e6..bf02e72 160000 --- a/user +++ b/user @@ -1 +1 @@ -Subproject commit ad822e6d3b626b598874bb52a407e90f549c5ab9 +Subproject commit bf02e72b85784af3555c7abe6b985aefc215023e