-
Notifications
You must be signed in to change notification settings - Fork 107
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
Refine the API in the public header #340
Conversation
085b562
to
19dd832
Compare
As discuss before, exit code shall be stored and maybe not to output to console directly. Unfortunately, CI/host-x64 and CI/host-arm run |
After a RISC-V program ends, it is important to verify the exit code (i.e., |
Sure, a build macro can be added to |
Due to the memory size being changed to a runtime-defined value, do we need to check if the addresses of load and store instructions exceed the specified range? |
I would like to express a concern regarding the |
19dd832
to
fde9ce2
Compare
The PRINT_EXIT_CODE build macro do not used in default build, thus make CI/host-x64 or CI/host-arm64 failed. Shall I add it to default build? Personally, I am prefer default build without PRINT_EXIT_CODE. Another way to pass CI is that modifying the CI flow, build |
Drop macro |
Sound reasonable. Maybe in future PR. |
For minimal changes, printing |
fde9ce2
to
b4b5227
Compare
Actually, we could introduce some helper functions or getter functions to access the specific field of userdata without losing the encapsulation. For example, some helper functions for memory viewing instead of returning whole userdata. |
.emu_data.vm_user = malloc(sizeof(vm_user_t)), | ||
.cycle_per_step = 100, | ||
.allow_misalign = opt_misaligned, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are going to make these parameters user-defined now, I will suggest having some checks (check_vm_attr()
) on the vm_attr_t
before the emulator creation stage, otherwise bad parameters can lead to a crash which is not easy to figure out quickly. For example: mem_size
should be larger than stack_size + args_offset_size
.
Note that mem_size
should also be larger than the ELF mapping range to load correctly, but this may not be easy to check before the emulator creation stage. As an alternative, maybe applying the range check for memory_write
at the emulator running stage is a simple idea to solve this. We may need to take care of the possible performance drop for the extra comparison on this solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice perspective. I think validation of vm_attr_t
could be complex. For example, shall we check the invalid file during validation or propagate to elf_open
to verify the invalidation. Similar situation for memory, if the user-provided memory size is not enough to run emulation, shall we simply abort before rv_create
or propagate to segmentation fault. We may need more discussion about this. Maybe in future PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. We can leave these at other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. We can leave these at other places.
I have mentioned it in the commit message.
Since we have introduced |
Another way: we can introduce |
Exactly. It is time to drop |
Including the callback function as part of the emulator's context is possible, but it’s not necessary to have a separate function like |
8e73895
to
2cb0104
Compare
2cb0104
to
ea51b2d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm good with the changes now! Let's see if other guys have more comments.
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In your git commit messages, it is more appropriate to mention "this commit" rather than "this PR," as "PR" refers to a pull request, not a commit.
ea51b2d
to
60aebce
Compare
The following should be included in an emulator's simple and clear public API: 1. create/init core 2. run emulation 3. delete/destroy core Other components, including as memory, file systems, program data, etc., should be abstracted from the user, as a result, setting a configuration value (vm_attr_t) is sufficient. The user needs to manage about memory (state_t) and elf stuff before this commit. The user can just construct a core, run it, and shut it down after this commit, so they won't need to worry about them anymore. The vm_attr_t has multiple fields and they are commented clearly in the code. As you can see in "main", there are various mode to run the emulator such as "run_and_trace", "gdbstub", and "profiling". Thus, a field call "run_flag" is introduced in vm_attr_t. For standard stream remapping, rv_remap_stdstream function is introduced. The emulator can remap default standard stream to required streams after creating the emulator by calling the rv_remap_stdstream function. rv_userdata has been dropped since PRIV macro is sufficient for internal implemntation. Also, application will not need to access it directly. elf is reopened in dump_test_signature because elf is allocated during rv_create. It is acceptable to reopen elf since it is only for testing. Print inferior exit code to console inside main instead of syscall_exit because the actual usage of exit code depends on applications of using riscv public API. The io interface is not changed in this commit because it could maybe reused with semu in some way, still need to be investigated. Logging feature and system emulator integration are not implemented yet. Also, a validator for validating the user-defined vm_attr_t might need to be introduced. related: sysprog21#310
60aebce
to
820cd9b
Compare
The changes also look good to me. Thanks! |
Since commit sysprog21#340, the size of memory can be changed. As a result, this commit has removed outdated comments. Some comments are added to describe the IO functions in order to increase consistency.
Refine the API in the public header
Since commit sysprog21#340, the size of memory can be changed. As a result, this commit has removed outdated comments. Some comments are added to describe the IO functions in order to increase consistency.
The following should be included in an emulator's simple and clear public API:
Other components, including as memory, file systems, program data, etc., should be abstracted from the user, as a result, setting a configuration value (
vm_attr_t
) is sufficient. The user should manage about memory (state_t
) and elf stuff before this PR. The user may just construct a core, run it, and shut it down after this PR, so they won't need to worry about them anymore.For stdio remapping,
rv_remap_stdstream
function is introduced.The
vm_attr_t
has multiple fields and they are commented clearly in the code.elf is reopened in
dump_test_signature
because elf is allocated duringrv_create
. It is acceptable to reopen elf since it is only for testing. Print inferior exit code to console inside main instead ofsyscall_exit
because the actual usage of exit code depends on applications of using riscv public API.The
io
interface is not changed in this PR because it could maybe reused withsemu
in some way, still need to be investigated. Also, Logging feature and system emulator integration are not implemented yet.