From 0a0231599069942db8c3837b0c7a03342e380cef Mon Sep 17 00:00:00 2001 From: Harry Chen Date: Tue, 2 Apr 2019 01:41:48 +0800 Subject: [PATCH] Add kernel stack for exception handling Signed-off-by: Harry Chen --- .gitignore | 2 ++ kernel/src/arch/mipsel/boot/entry.S | 17 +++++++++++++++-- kernel/src/arch/mipsel/boot/linker.ld | 2 ++ kernel/src/arch/mipsel/boot/trap.S | 20 ++++++++++++++------ 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 00657e5..dc3bbf3 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ Cargo.lock # for eclipse .project + +.vscode diff --git a/kernel/src/arch/mipsel/boot/entry.S b/kernel/src/arch/mipsel/boot/entry.S index 5d2ad14..0d0e70b 100644 --- a/kernel/src/arch/mipsel/boot/entry.S +++ b/kernel/src/arch/mipsel/boot/entry.S @@ -5,9 +5,22 @@ .globl _start _start: - la sp, bootstacktop - la gp, _gp + # setup stack and gp + la sp, bootstacktop + la gp, _gp + # set ebase + la t0, trap_entry + mfc0 t1, 15 # C0_EBASE + or t1, t1, t0 + mtc0 t1, 15 + + # exit bootstrap mode + mfc0 t0, 12 # C0_STATUS + andi t0, t0, 0xFFBFFFFF # set BEV (bit 22) to 0 + mtc0 t0, 12 + + # directly jump to main function b rust_main nop diff --git a/kernel/src/arch/mipsel/boot/linker.ld b/kernel/src/arch/mipsel/boot/linker.ld index 8d09ddb..8570468 100644 --- a/kernel/src/arch/mipsel/boot/linker.ld +++ b/kernel/src/arch/mipsel/boot/linker.ld @@ -17,6 +17,8 @@ SECTIONS *(.text.entry) *(.text .text.*) . = ALIGN(4K); + *(.text.ebase) + . = ALIGN(4K); etext = .; } diff --git a/kernel/src/arch/mipsel/boot/trap.S b/kernel/src/arch/mipsel/boot/trap.S index 4da8de4..f6d891e 100644 --- a/kernel/src/arch/mipsel/boot/trap.S +++ b/kernel/src/arch/mipsel/boot/trap.S @@ -2,8 +2,10 @@ .set noat .set noreorder - .section .text + .section .text.ebase .globl trap_entry + +.org 0x0 trap_entry: # +0x000: TLB-miss vector b general_trap_vec @@ -18,10 +20,9 @@ general_trap_vec: nop # delayslot trap_from_user: - # TODO: load kstack, we can use k0 to store something - # la k0, address_of_kstack - # addiu sp, k0, size_of_kstack - nop + # load kstack, we can use k0 to store something + la k0, kernel_stack + la sp, kernel_stack_top trap_from_kernel: /* @@ -92,7 +93,7 @@ trap_from_kernel: # prepare to call rust_trap jal rust_trap - addiu a0, sp, 16 /* set argument */ + addiu a0, sp, 16 /* set argument (trapframe) */ .globl trap_return trap_return: @@ -148,3 +149,10 @@ trap_return: eret nop + .section .bss.stack + .align 12 #PGSHIFT + .global kernel_stack +kernel_stack: + .space 1024 * 16 # 16KB for kernel stack + .global kernel_stack_top +kernel_stack_top: