rems-project / rmem

rmem public repo
Other
40 stars 9 forks source link

riscv: elf: taking privilege exception #16

Open VarunKoyyalagunta opened 2 years ago

VarunKoyyalagunta commented 2 years ago

I am unable to execute any of the riscv elf tests on the web interface or the CLI.

For example, if I load the loop5-O0 test on https://www.cl.cam.ac.uk/~sf502/regressions/rmem/, and execute step 20, I get this exception -

0:1    0x01010c (_start) fetch error          
  micro_op_state: MOS_pending_exception decode error: Internal error Type_check.Type_error(_, 0, _)
  waiting to raise an exception
  0 0:1    raise exception: decode error: Internal error Type_check.Type_error(_, 0, _)
          t @ 0x11170
          i @ 0xfffff0003ec

On the CLI, if I take the same loop5-O0 binary (compiled from https://github.com/litmus-tests/litmus-tests-riscv/tree/master/elf-tests/basic), and run ./rmem -model relaxed -model flat -cmds "step 20" I get this exception -

Failure while taking transition (from the state above):                                                                                                                                               
  0:2    register read: cur_privilege = 2b_1'10 from initialstate of 0-1:2b_0'10                                                                                                                      

Fail: Pattern match failure at model/riscv_types.sail 78:2 - 82:3. regval_privilege                                                                                                                   

Fatal error: exception Failure("Fail: Pattern match failure at model/riscv_types.sail 78:2 - 82:3. regval_privilege")                                                                                 
Raised at file "list.ml", line 187, characters 10-25                                                                                                                                                  
Called from file "src_top/pp.ml", line 359, characters 4-42   

I was able to fix the problem on the CLI with the following change - https://github.com/VarunKoyyalagunta/rmem/commit/8737b47f813cd55ee99bb5badc6fdecc3e4a6e93

I can create a PR for that if that is the appropriate fix. I just copied the initial cur_privilege and mstatus settings from https://github.com/rems-project/rmem/blob/9de95224f6293acb3cd6022471219a0a01b9b260/src_top/litmus_test_file.ml#L425-L427