Skip to content

Commit b51ba09

Browse files
authored
Merge pull request rustsbi#44 from YdrMaster/main
fix: 改正软中断测试
2 parents cc22cee + 0b9a012 commit b51ba09

File tree

5 files changed

+41
-38
lines changed

5 files changed

+41
-38
lines changed

bench-kernel/build.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ fn main() {
44
let ld = PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("linker.ld");
55
fs::write(&ld, LINKER).unwrap();
66
println!("cargo:rerun-if-changed=build.rs");
7+
println!("cargo:rerun-if-env-changed=LOG");
78
println!("cargo:rustc-link-arg=-T{}", ld.display());
89
}
910

@@ -14,29 +15,25 @@ MEMORY {
1415
DRAM : ORIGIN = 0x80200000, LENGTH = 64M
1516
}
1617
SECTIONS {
17-
.text : ALIGN(4) {
18+
.text : {
1819
*(.text.entry)
1920
*(.text .text.*)
2021
} > DRAM
21-
.rodata : ALIGN(8) {
22-
srodata = .;
22+
.rodata : {
2323
*(.rodata .rodata.*)
2424
*(.srodata .srodata.*)
25-
. = ALIGN(8);
26-
erodata = .;
2725
} > DRAM
28-
.data : ALIGN(8) {
29-
sdata = .;
26+
.data : {
3027
*(.data .data.*)
3128
*(.sdata .sdata.*)
32-
. = ALIGN(8);
33-
edata = .;
3429
} > DRAM
35-
.bss (NOLOAD) : ALIGN(8) {
30+
.bss (NOLOAD) : {
3631
*(.bss.uninit)
32+
. = ALIGN(8);
3733
sbss = .;
3834
*(.bss .bss.*)
3935
*(.sbss .sbss.*)
36+
. = ALIGN(8);
4037
ebss = .;
4138
} > DRAM
4239
/DISCARD/ : {

bench-kernel/src/main.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extern "C" fn rust_main(hartid: usize, _dtb_pa: usize) -> ! {
4747
// 测试调用延迟
4848
let t0 = time::read();
4949

50-
for _ in 0..0xffff {
50+
for _ in 0..0x20000 {
5151
let _ = sbi_rt::get_marchid();
5252
}
5353

@@ -56,21 +56,25 @@ extern "C" fn rust_main(hartid: usize, _dtb_pa: usize) -> ! {
5656
// 测试中断响应延迟
5757
let t0 = time::read();
5858

59-
for _ in 0..0xffff {
59+
for _ in 0..0x20000 {
6060
unsafe {
6161
core::arch::asm!(
6262
" la {0}, 1f
6363
csrw stvec, {0}
64+
mv a0, a2
65+
mv a1, zero
6466
ecall
6567
wfi
6668
.align 2
67-
1:
69+
1: csrrci zero, sip, 1 << 1
70+
6871
",
6972
out(reg) _,
7073
in("a7") 0x735049,
7174
in("a6") 0,
72-
in("a0") 1 << hartid,
75+
in("a0") 0,
7376
in("a1") 0,
77+
in("a2") 1 << hartid,
7478
options(nomem),
7579
);
7680
}

rustsbi-qemu/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ fn main() {
44
let ld = &PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("linker.ld");
55
fs::write(ld, LINKER).unwrap();
66
println!("cargo:rerun-if-changed=build.rs");
7+
println!("cargo:rerun-if-env-changed=LOG");
78
println!("cargo:rustc-link-arg=-T{}", ld.display());
89
}
910

rustsbi-qemu/src/trap_vec.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ unsafe extern "C" fn mtimer() {
5353
// mscratch: S sp
5454
" csrrw sp, mscratch, sp",
5555
// 保护
56-
" sd ra, -1*8(sp)
57-
sd a0, -2*8(sp)
58-
sd a1, -3*8(sp)
59-
sd a2, -4*8(sp)
56+
" addi sp, sp, -4*8
57+
sd ra, 0*8(sp)
58+
sd a0, 1*8(sp)
59+
sd a1, 2*8(sp)
60+
sd a2, 3*8(sp)
6061
",
6162
// 清除 mtimecmp
6263
" la a0, {clint_ptr}
@@ -70,10 +71,11 @@ unsafe extern "C" fn mtimer() {
7071
csrrs zero, mip, a0
7172
",
7273
// 恢复
73-
" ld ra, -1*8(sp)
74-
ld a0, -2*8(sp)
75-
ld a1, -3*8(sp)
76-
ld a2, -4*8(sp)
74+
" ld ra, 0*8(sp)
75+
ld a0, 1*8(sp)
76+
ld a1, 2*8(sp)
77+
ld a2, 3*8(sp)
78+
addi sp, sp, 4*8
7779
",
7880
// 换栈:
7981
// sp : S sp
@@ -103,9 +105,10 @@ unsafe extern "C" fn msoft() {
103105
// mscratch: S sp
104106
" csrrw sp, mscratch, sp",
105107
// 保护
106-
" sd ra, -1*8(sp)
107-
sd a0, -2*8(sp)
108-
sd a1, -3*8(sp)
108+
" addi sp, sp, -3*8
109+
sd ra, 0*8(sp)
110+
sd a0, 1*8(sp)
111+
sd a1, 2*8(sp)
109112
",
110113
// 清除 msip 设置 ssip
111114
" la a0, {clint_ptr}
@@ -115,9 +118,10 @@ unsafe extern "C" fn msoft() {
115118
csrrsi zero, mip, 1 << 1
116119
",
117120
// 恢复
118-
" ld ra, -1*8(sp)
119-
ld a0, -2*8(sp)
120-
ld a1, -3*8(sp)
121+
" ld ra, 0*8(sp)
122+
ld a0, 1*8(sp)
123+
ld a1, 2*8(sp)
124+
addi sp, sp, 3*8
121125
",
122126
// 换栈:
123127
// sp : S sp

test-kernel/build.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ fn main() {
44
let ld = PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("linker.ld");
55
fs::write(&ld, LINKER).unwrap();
66
println!("cargo:rerun-if-changed=build.rs");
7+
println!("cargo:rerun-if-env-changed=LOG");
78
println!("cargo:rustc-link-arg=-T{}", ld.display());
89
}
910

@@ -14,29 +15,25 @@ MEMORY {
1415
DRAM : ORIGIN = 0x80200000, LENGTH = 64M
1516
}
1617
SECTIONS {
17-
.text : ALIGN(4) {
18+
.text : {
1819
*(.text.entry)
1920
*(.text .text.*)
2021
} > DRAM
21-
.rodata : ALIGN(8) {
22-
srodata = .;
22+
.rodata : {
2323
*(.rodata .rodata.*)
2424
*(.srodata .srodata.*)
25-
. = ALIGN(8);
26-
erodata = .;
2725
} > DRAM
28-
.data : ALIGN(8) {
29-
sdata = .;
26+
.data : {
3027
*(.data .data.*)
3128
*(.sdata .sdata.*)
32-
. = ALIGN(8);
33-
edata = .;
3429
} > DRAM
35-
.bss (NOLOAD) : ALIGN(8) {
30+
.bss (NOLOAD) : {
3631
*(.bss.uninit)
32+
. = ALIGN(8);
3733
sbss = .;
3834
*(.bss .bss.*)
3935
*(.sbss .sbss.*)
36+
. = ALIGN(8);
4037
ebss = .;
4138
} > DRAM
4239
/DISCARD/ : {

0 commit comments

Comments
 (0)