[Update] chg rv to la

This commit is contained in:
bLueriVerLHR
2023-07-20 18:43:45 +08:00
parent 29abfe4101
commit 104518d875
4 changed files with 135 additions and 97 deletions

View File

@@ -0,0 +1,36 @@
#ifndef CSR_H__
#define CSR_H__
// CSR infos
#define CRMD 0x000 /* 当前模式信息 */
#define PRMD 0x001 /* 例外前模式信息 */
#define EUEN 0x002 /* 拓展部件使能 */
#define ECFG 0x004 /* 例外配置 */
#define ESTAT 0x005 /* 例外状态 */
#define ERA 0x006 /* 例外返回地址 */
#define BADV 0x007 /* 出错虚地址 */
#define EENTRY 0x00c /* 例外地址入口 */
#define TLBIDX 0x010 /* TLB 索引 */
#define TLBEHI 0x011 /* TLB 表项高位 */
#define TLBELO0 0x012 /* TLB 表项低位 0 */
#define TLBELO1 0x013 /* TLB 表项低位 1 */
#define ASID 0x018 /* 地址空间标识符 */
#define PGDL 0x019 /* 低半地址空间全局目录基址 */
#define PGDH 0x01a /* 高半地址空间全局目录基址 */
#define PGD 0x01b /* 全局目录基址 */
#define CPUID 0x020 /* 处理器编号 */
#define SAVE0 0x030 /* 数据保存 0*/
#define SAVE1 0x031 /* 数据保存 1*/
#define SAVE2 0x032 /* 数据保存 2 */
#define SAVE3 0x033 /* 数据保存 3 */
#define TID 0x040 /* 定时器编号 */
#define TCFG 0x041 /* 定时器配置 */
#define TVAL 0x042 /* 定时器值 */
#define TICLR 0x044 /* 定时中断清除 */
#define LLBCTL 0x060 /* LLBit 控制 */
#define TLBRENTRY 0x088 /* TLB 重填例外入口 */
#define CTAG 0x098 /* 高速缓存标签 */
#define DMW0 0x180 /* 直接映射配置窗口 0 */
#define DMW1 0x181 /* 直接映射配置窗口 1 */
#endif

View File

@@ -1,3 +1,5 @@
#include "types.h"
// Format of an ELF executable file // Format of an ELF executable file
#define ELF_MAGIC 0x464C457FU // "\x7FELF" in little endian #define ELF_MAGIC 0x464C457FU // "\x7FELF" in little endian

View File

@@ -9,13 +9,13 @@ _entry:
# stack0 is declared in start.c, # stack0 is declared in start.c,
# with a 4096-byte stack per CPU. # with a 4096-byte stack per CPU.
# sp = stack0 + (hartid * 4096) # sp = stack0 + (hartid * 4096)
la sp, stack0 la.global $sp, stack0
li a0, 1024*4 li.w $a0, 1024*4
csrr a1, mhartid csrrd $a1, CPUID
addi a1, a1, 1 addi.w $a1, $a1, 1
mul a0, a0, a1 mul.w $a0, $a0, $a1
add sp, sp, a0 add.w $sp, $sp, $a0
# jump to start() in start.c # jump to start() in start.c
call start bl start
spin: spin:
j spin b spin

View File

@@ -11,81 +11,81 @@
.align 4 .align 4
kernelvec: kernelvec:
# make room to save registers. # make room to save registers.
addi sp, sp, -256 addi.w $sp, $sp, -128
# save the registers. # save the registers.
sd ra, 0(sp) st.w $ra, $sp, 0
sd sp, 8(sp) st.w $tp, $sp, 4
sd gp, 16(sp) st.w $sp, $sp, 8
sd tp, 24(sp) st.w $a0, $sp, 12
sd t0, 32(sp) st.w $a1, $sp, 16
sd t1, 40(sp) st.w $a2, $sp, 20
sd t2, 48(sp) st.w $a3, $sp, 24
sd s0, 56(sp) st.w $a4, $sp, 28
sd s1, 64(sp) st.w $a5, $sp, 32
sd a0, 72(sp) st.w $a6, $sp, 36
sd a1, 80(sp) st.w $a7, $sp, 40
sd a2, 88(sp) st.w $t0, $sp, 44
sd a3, 96(sp) st.w $t1, $sp, 48
sd a4, 104(sp) st.w $t2, $sp, 52
sd a5, 112(sp) st.w $t3, $sp, 56
sd a6, 120(sp) st.w $t4, $sp, 60
sd a7, 128(sp) st.w $t5, $sp, 64
sd s2, 136(sp) st.w $t6, $sp, 68
sd s3, 144(sp) st.w $t7, $sp, 72
sd s4, 152(sp) st.w $t8, $sp, 76
sd s5, 160(sp) st.w $u0, $sp, 80
sd s6, 168(sp) st.w $fp, $sp, 84
sd s7, 176(sp) st.w $s0, $sp, 88
sd s8, 184(sp) st.w $s1, $sp, 92
sd s9, 192(sp) st.w $s2, $sp, 96
sd s10, 200(sp) st.w $s3, $sp, 100
sd s11, 208(sp) st.w $s4, $sp, 104
sd t3, 216(sp) st.w $s5, $sp, 108
sd t4, 224(sp) st.w $s6, $sp, 112
sd t5, 232(sp) st.w $s7, $sp, 116
sd t6, 240(sp) st.w $s8, $sp, 120
# call the C trap handler in trap.c # call the C trap handler in trap.c
call kerneltrap bl kerneltrap
# restore registers. # restore registers.
ld ra, 0(sp) ld.w $ra, $sp, 0
ld sp, 8(sp)
ld gp, 16(sp)
# not tp (contains hartid), in case we moved CPUs # not tp (contains hartid), in case we moved CPUs
ld t0, 32(sp) ld.w $sp, $sp, 8
ld t1, 40(sp) ld.w $a0, $sp, 12
ld t2, 48(sp) ld.w $a1, $sp, 16
ld s0, 56(sp) ld.w $a2, $sp, 20
ld s1, 64(sp) ld.w $a3, $sp, 24
ld a0, 72(sp) ld.w $a4, $sp, 28
ld a1, 80(sp) ld.w $a5, $sp, 32
ld a2, 88(sp) ld.w $a6, $sp, 36
ld a3, 96(sp) ld.w $a7, $sp, 40
ld a4, 104(sp) ld.w $t0, $sp, 44
ld a5, 112(sp) ld.w $t1, $sp, 48
ld a6, 120(sp) ld.w $t2, $sp, 52
ld a7, 128(sp) ld.w $t3, $sp, 56
ld s2, 136(sp) ld.w $t4, $sp, 60
ld s3, 144(sp) ld.w $t5, $sp, 64
ld s4, 152(sp) ld.w $t6, $sp, 68
ld s5, 160(sp) ld.w $t7, $sp, 72
ld s6, 168(sp) ld.w $t8, $sp, 76
ld s7, 176(sp) ld.w $u0, $sp, 80
ld s8, 184(sp) ld.w $fp, $sp, 84
ld s9, 192(sp) ld.w $s0, $sp, 88
ld s10, 200(sp) ld.w $s1, $sp, 92
ld s11, 208(sp) ld.w $s2, $sp, 96
ld t3, 216(sp) ld.w $s3, $sp, 100
ld t4, 224(sp) ld.w $s4, $sp, 104
ld t5, 232(sp) ld.w $s5, $sp, 108
ld t6, 240(sp) ld.w $s6, $sp, 112
ld.w $s7, $sp, 116
ld.w $s8, $sp, 120
addi sp, sp, 256 addi sp, sp, 128
# return to whatever we were doing in the kernel. # return to whatever we were doing in the kernel.
sret ertn
# #
# machine-mode timer interrupt. # machine-mode timer interrupt.
@@ -93,32 +93,32 @@ kernelvec:
.globl timervec .globl timervec
.align 4 .align 4
timervec: timervec:
# start.c has set up the memory that mscratch points to: # # start.c has set up the memory that mscratch points to:
# scratch[0,8,16] : register save area. # # scratch[0,8,16] : register save area.
# scratch[24] : address of CLINT's MTIMECMP register. # # scratch[24] : address of CLINT's MTIMECMP register.
# scratch[32] : desired interval between interrupts. # # scratch[32] : desired interval between interrupts.
csrrw a0, mscratch, a0 # csrrw a0, mscratch, a0
sd a1, 0(a0) # sd a1, 0(a0)
sd a2, 8(a0) # sd a2, 8(a0)
sd a3, 16(a0) # sd a3, 16(a0)
# schedule the next timer interrupt # # schedule the next timer interrupt
# by adding interval to mtimecmp. # # by adding interval to mtimecmp.
ld a1, 24(a0) # CLINT_MTIMECMP(hart) # ld a1, 24(a0) # CLINT_MTIMECMP(hart)
ld a2, 32(a0) # interval # ld a2, 32(a0) # interval
ld a3, 0(a1) # ld a3, 0(a1)
add a3, a3, a2 # add a3, a3, a2
sd a3, 0(a1) # sd a3, 0(a1)
# arrange for a supervisor software interrupt # # arrange for a supervisor software interrupt
# after this handler returns. # # after this handler returns.
li a1, 2 # li a1, 2
csrw sip, a1 # csrw sip, a1
ld a3, 16(a0) # ld a3, 16(a0)
ld a2, 8(a0) # ld a2, 8(a0)
ld a1, 0(a0) # ld a1, 0(a0)
csrrw a0, mscratch, a0 # csrrw a0, mscratch, a0
mret ertn