mirror of
https://github.com/openhwgroup/cvw
synced 2025-02-02 09:45:18 +00:00
Fixed timer offset in RV32 WALLY-wfi; simplified in RV64 WALLY-wfi
This commit is contained in:
parent
ce0be9a9c9
commit
147f62d9a5
@ -36,20 +36,20 @@ WRITE_READ_CSR mie, 0xFFF // Enable interrupts from all sources
|
|||||||
|
|
||||||
// Code copied from test library to cause m time interrupt, with time loop replaced with wfi.
|
// Code copied from test library to cause m time interrupt, with time loop replaced with wfi.
|
||||||
|
|
||||||
/* Note: the following line might cause problems in the future. If more than 0x50 cycles are needed before the wfi
|
/* Note: the following line might cause problems in the future. If more than 0x100 cycles are needed before the wfi
|
||||||
instruction begins, then the program might fall into a loop and run forever*/
|
instruction begins, then the program might fall into a loop and run forever*/
|
||||||
li x28, 0x50 // Desired offset from the present time
|
li x28, 0x100 // Desired offset from the present time
|
||||||
mv a3, x28 // copy value in to know to stop waiting for interrupt after this many cycles
|
mv a3, x28 // copy value in to know to stop waiting for interrupt after this many cycles
|
||||||
la x29, 0x02004000 // MTIMECMP register in CLINT
|
la x29, 0x02004000 // MTIMECMP register in CLINT
|
||||||
la x30, 0x0200BFF8 // MTIME register in CLINT
|
la x30, 0x0200BFF8 // MTIME register in CLINT
|
||||||
lw x7, 0(x30) // low word of MTIME
|
lw x7, 0(x30) // low word of MTIME
|
||||||
lw x31, 4(x30) // high word of MTIME
|
lw x31, 4(x30) // high word of MTIME
|
||||||
add x28, x7, x28 // add desired offset to the current time
|
add x28, x7, x28 // add desired offset to the current time
|
||||||
bgtu x28, x7, nowrap // check new time exceeds current time (no wraparound)
|
bgtu x28, x7, nowrap // check new time exceeds current time (no wraparound)
|
||||||
addi x31, x31, 1 // if wrap, increment most significant word
|
addi x31, x31, 1 // if wrap, increment most significant word
|
||||||
sw x31,4(x29) // store into most significant word of MTIMECMP
|
|
||||||
|
|
||||||
nowrap:
|
nowrap:
|
||||||
|
sw x31,4(x29) // store into most significant word of MTIMECMP
|
||||||
sw x28, 0(x29) // store into least significant word of MTIMECMP
|
sw x28, 0(x29) // store into least significant word of MTIMECMP
|
||||||
|
|
||||||
auipc ra, 0x0
|
auipc ra, 0x0
|
||||||
|
@ -35,30 +35,24 @@ WRITE_READ_CSR mie, 0xFFF // Enable interrupts from all sources
|
|||||||
|
|
||||||
// Code copied from test library to cause m time interrupt, with time loop replaced with wfi.
|
// Code copied from test library to cause m time interrupt, with time loop replaced with wfi.
|
||||||
|
|
||||||
li x28, 0x60 // Desired offset from the present time
|
li x28, 0x60 // Desired offset from the present time
|
||||||
mv a3, x28 // copy value in to know to stop waiting for interrupt after this many cycles
|
mv a3, x28 // copy value in to know to stop waiting for interrupt after this many cycles
|
||||||
la x29, 0x02004000 // MTIMECMP register in CLINT
|
la x29, 0x02004000 // MTIMECMP register in CLINT
|
||||||
la x30, 0x0200BFF8 // MTIME register in CLINT
|
la x30, 0x0200BFF8 // MTIME register in CLINT
|
||||||
lw x7, 0(x30) // low word of MTIME
|
ld x7, 0(x30) // read MTIME
|
||||||
lw x31, 4(x30) // high word of MTIME
|
add x28, x7, x28 // add offset
|
||||||
add x28, x7, x28 // add desired offset to the current time
|
sw x28, 0(x29) // MTIMECMP = MTIME + offset
|
||||||
bgtu x28, x7, nowrap // check new time exceeds current time (no wraparound)
|
|
||||||
addi x31, x31, 1 // if wrap, increment most significant word
|
|
||||||
sw x31,4(x29) // store into most significant word of MTIMECMP
|
|
||||||
|
|
||||||
nowrap:
|
auipc ra, 0x0
|
||||||
sw x28, 0(x29) // store into least significant word of MTIMECMP
|
addi ra, ra, 0xC // load address after wfi into ra so we return to the right place after handling the time interrupt
|
||||||
|
|
||||||
auipc ra, 0x0
|
wfi // test wfi until trap goes off
|
||||||
addi ra, ra, 0xC // load address after wfi into ra so we return to the right place after handling the time interrupt
|
|
||||||
|
|
||||||
wfi // test wfi until trap goes off
|
li x28, 0x600d111 // magic number "good 111" to write to output after interrupt goes off.
|
||||||
|
// this tests whether wfi is a nop or not since we should get the output for the interrupt before this one
|
||||||
li x28, 0x600d111 // magic number "good 111" to write to output after interrupt goes off.
|
sd x28, 0(x6)
|
||||||
// this tests whether wfi is a nop or not since we should get the output for the interrupt before this one
|
addi x6, x6, 8
|
||||||
sd x28, 0(x6)
|
addi x16, x16, 8
|
||||||
addi x6, x6, 8
|
|
||||||
addi x16, x16, 8
|
|
||||||
|
|
||||||
END_TESTS
|
END_TESTS
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user