Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function main in main.sail Not Reflected in C_emulator #515

Open
KotorinMinami opened this issue Jul 16, 2024 · 3 comments
Open

Function main in main.sail Not Reflected in C_emulator #515

KotorinMinami opened this issue Jul 16, 2024 · 3 comments

Comments

@KotorinMinami
Copy link
Contributor

In main.sail, the main function contains annotations for the PC (Program Counter) and uses a try...catch module for the correct operation of the simulator.

function main() : unit -> unit = {
  // initialize extensions
  ext_init();

  PC = get_entry_point();
  print_bits("PC = ", PC);

  try {
    init_model();
    sail_end_cycle();
    loop()
  } catch {
    Error_not_implemented(s) => print_string("Error: Not implemented: ", s),
    Error_internal_error() => print("Error: internal error")
  }
}

However, in the riscv_sim.c , we can see that these functionalities implemented in the main function are not correspondingly reflected.

...
step_exception:
  fprintf(stderr, "Sail exception!");
  goto dump_state;
}

Does this lead to redundancy in the code within the main function? Or can we separate these functionalities and reflect them in riscv_sim.c?

@Timmmm
Copy link
Collaborator

Timmmm commented Jul 22, 2024

Yeah I'm not sure anything really uses that main(). Make make interpret, which runs the Sail interpreter? I'm not sure.

The simulator can't use Sail's main() function because it needs to do stuff after each step. I guess you could technically change it so that Sail's main() called a C callback function after every step, but I think inverting the control like that gets pretty awkward.

@Alasdair
Copy link
Collaborator

https://github.com/rems-project/isla requires a main function to be written in Sail when executing litmus tests. The sail_end_cycle function is essentially doing what you suggest where it executes a callback that modifies the symbolic execution state as needed after each instruction.

@KotorinMinami
Copy link
Contributor Author

My idea is : currently, the exception handling in riscv_sim.c is still marked as TODO. However, the implementation in main.sail, based on my understanding (or perhaps I misunderstood?), has fairly decent implementation of some exception handling as defined in our sail specifications within the generated C code.

if (!(have_exception)) goto post_exception_handlers_11095;
  have_exception = false;
  {
    if ((*current_exception).kind != Kind_zError_not_implemented) goto try_11096;
    sail_string zs;
    CREATE(sail_string)(&zs);
    COPY(sail_string)(&zs, (*current_exception).zError_not_implemented);
    zgsz312274 = print_string("Error: Not implemented: ", zs);
    KILL(sail_string)(&zs);
    goto post_exception_handlers_11095;
  }
try_11096: ;
  {
    if ((*current_exception).kind != Kind_zError_internal_error) goto try_11097;
    zgsz312274 = print_endline("Error: internal error");
    goto post_exception_handlers_11095;
  }
try_11097: ;
  have_exception = true;

Perhaps we can take this as the first step towards implementation? Also, it may be awkward to split the step of handling exceptions in the try...catch block

Timmmm pushed a commit to Timmmm/sail-riscv that referenced this issue Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants