1/* 2 * Copyright 2021, Haiku, Inc. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7#include <asm_defs.h> 8#include "arch_traps.h" 9#include "asm_offsets.h" 10 11 12.align 4 13FUNCTION(SVec): 14 PushTrapFrame IFRAME_ra 15 sd fp, IFRAME_sp(sp) 16 csrr t0, sepc 17 sd t0, IFRAME_epc(sp) 18 19 csrr t0, sstatus 20 sd t0, IFRAME_status(sp) 21 csrr t0, scause 22 sd t0, IFRAME_cause(sp) 23 csrr t0, stval 24 sd t0, IFRAME_tval(sp) 25 26 mv a0, sp 27 call STrap 28 29FUNCTION(SVecRet): 30 ld t0, IFRAME_status(sp) 31 csrw sstatus, t0 32 33 ld t0, IFRAME_epc(sp) 34 csrw sepc, t0 35 PopTrapFrame IFRAME_ra 36 sret 37FUNCTION_END(SVec) 38 39 40.align 4 41FUNCTION(SVecU): 42 # switch to kernel stack, SSCRATCH will hold user SP 43 csrrw sp, sscratch, sp 44 45 PushTrapFrame IFRAME_ra 46 csrr t0, sscratch 47 sd t0, IFRAME_sp(sp) 48 csrr t0, sepc 49 sd t0, IFRAME_epc(sp) 50 51 csrr t0, sstatus 52 sd t0, IFRAME_status(sp) 53 csrr t0, scause 54 sd t0, IFRAME_cause(sp) 55 csrr t0, stval 56 sd t0, IFRAME_tval(sp) 57 58 ld tp, ARCH_STACK_thread(fp) 59 60 la t0, SVec 61 csrw stvec, t0 62 63 mv a0, sp 64 call STrap 65 66FUNCTION(SVecURet): 67 csrw sscratch, fp # save kernel SP 68 69 la t0, SVecU 70 csrw stvec, t0 71 72 ld t0, IFRAME_status(sp) 73 csrw sstatus, t0 74 75 ld tp, IFRAME_tp(sp) 76 ld t0, IFRAME_epc(sp) 77 csrw sepc, t0 78 PopTrapFrame IFRAME_ra 79 sret 80FUNCTION_END(SVecU) 81