2727
2828#% set labels.next_tick = 14
2929
30- #% set labels.end_instruction_with_rd_and_poll_interrupts = 155
30+ #% set labels.end_instruction_with_rd_and_poll_interrupts = 154
3131#% set labels.end_instruction_with_rd_and_fire_interrupts = _labels_vals|last + 1
3232#% set labels.end_instruction_with_rd = _labels_vals|last + 1
3333#% set labels.end_instruction = _labels_vals|last + 2
8383 read csr_mtimecmp prev_proc "csr_mtimecmp"
8484 read csr_mtimecmph prev_proc "csr_mtimecmph"
8585 read csr_mtimeh prev_proc "csr_mtimeh"
86- read csr_satp prev_proc "csr_satp"
8786 read csr_stimecmp prev_proc "csr_stimecmp"
8887 read csr_stimecmph prev_proc "csr_stimecmph"
8988 read effective_privilege_mode prev_proc "effective_privilege_mode"
@@ -530,19 +529,20 @@ get_effective_privilege_mode__normal:
530529# ret: ret3
531530# clobbers: locals, nonlocal2
532531translate_virtual_address:
532+ #% do declare_locals("$$a")
533533 # if this function is called, we know that the current effective privilege mode permits address translation
534534 # so the only thing we need to check here is satp.MODE
535- jump translate_virtual_address__unchanged lessThan csr_satp 0x80000000
535+ read $satp {{CSRS}} "{{ 'satp'|csr }}"
536+ jump translate_virtual_address__unchanged lessThan $satp 0x80000000
536537
537538 # begin virtual address translation algorithm
538539 # PAGESIZE=2^12, LEVELS=2, PTESIZE=4
539540
540541 # step 1
541542
542543 # a = satp.ppn * PAGESIZE
543- #% do reset_locals()
544- op and $a csr_satp 0x3fffff # satp.ppn
545- op mul $a $a {{PAGESIZE}}
544+ op and $$a $satp 0x3fffff # satp.ppn
545+ op mul $$a $$a {{PAGESIZE}}
546546 # i = LEVELS - 1 = 1
547547 # nonlocal2 = (i + 1) * 10
548548 # i is stored in this form because it simplifies step 2 and doesn't really matter for other steps
@@ -558,7 +558,7 @@ translate_virtual_address__step_2:
558558 # = load(a + (va >> (x - 2))[11:2])
559559 op shr address mtval nonlocal2
560560 op and address address 0b111111111100
561- op add address address $a
561+ op add address address $$ a
562562
563563 op add ret @counter 1
564564 jump load_word always
@@ -623,9 +623,9 @@ translate_virtual_address__step_2:
623623 jump translate_virtual_address__page_fault notEqual nonlocal2 20
624624
625625 # otherwise, let a=pte.ppn * PAGESIZE, let i=i-1, and go to step 2
626- #% do reset_locals( )
627- op and $a result 0xfffffc00
628- op shl $a $a 2
626+ #% do declare_locals("$$a" )
627+ op and $$ a result 0xfffffc00
628+ op shl $$a $ $a 2
629629 set nonlocal2 10 # i=0
630630 jump translate_virtual_address__step_2 always
631631
@@ -2556,18 +2556,15 @@ csr_write_mie:
25562556csr_read_satp:
25572557#% do declare_locals(modify_csr_locals)
25582558 # if executing in S-mode, raise an illegal instruction exception if TVM=1
2559- jump csr_read_satp__ok notEqual privilege_mode 0b01
2559+ jump csr_read_csrs notEqual privilege_mode 0b01
25602560 op and $mstatus.tvm csr_mstatus 0b100000000000000000000
2561- jump ILLEGAL_OP notEqual $mstatus.tvm 0
2562- csr_read_satp__ok:
2563-
2564- set rd csr_satp
2565- set @counter $$modify_csr_op
2561+ jump csr_read_csrs equal $mstatus.tvm 0
2562+ jump ILLEGAL_OP always
25662563
25672564csr_write_satp:
25682565 # we don't use ASID for anything, but riscv-sail doesn't allow us to configure ASIDLEN, so the tests will fail if we zero ASID
25692566 # https://github.com/riscv/sail-riscv/blob/d8c3006f0ff4dbd33be876d9d62abb085c7f5298/model/riscv_xlen.sail#L25
2570- set csr_satp result
2567+ write result {{CSRS}} variable
25712568
25722569 # invalidate icache_var when writing satp because next_pc may now point to a different page
25732570 # TODO: this may not be strictly required by the spec
0 commit comments