-
Notifications
You must be signed in to change notification settings - Fork 2
ume: Add interpolation to rv64ume and custom template tags #834
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
Open
arcane-quill
wants to merge
28
commits into
master
Choose a base branch
from
wip/ume-viam-def
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
cef416f
ume: Add interpolation and specific pass for ume template tags #757
arcane-quill 33bf7f8
ume: Add specific tags for regs and exceptions #757
arcane-quill 95cdeb5
ume: Fix subdir in meson
arcane-quill 2a65a6c
ume: Add interpolation and specific pass for ume template tags #757
arcane-quill 8749792
ume: Remove everything related to frontend #757
arcane-quill 275af19
ume: Add ume definition #757
arcane-quill f9870ad
ume: Add more values for interpolation #757
arcane-quill fec5dc8
ume: Add missing interpolation #757
arcane-quill fc5e22e
ume: Fix checkstyle violations #757
arcane-quill 1440cb7
ume: Fix more checkstyle violations #757
arcane-quill 28c1e59
ume: Remove duplicate line #757
arcane-quill 3f37df9
ume: Revert frontend changes #757
arcane-quill 3f7de33
ume: Revert atg file changes #757
arcane-quill b6d7912
ume: Use proper viam objects and fix templates #757
arcane-quill 488a431
ume: Revert misc file
arcane-quill 8c54fa7
ume: Fix signal.c reigster handling #757
arcane-quill 5fde96b
ume: Add ifs for causevar and signal to template #757
arcane-quill dcb3847
ume: Refactor UME definitions #757
arcane-quill daec0b8
ume: Add UME section to vadl file, remove exceptions from cpuloop #757
arcane-quill a6a88bf
ume: Add syscall section to vadl file #757
arcane-quill 1379c83
iss: Fix UME pass order
Jozott00 53fbd00
ume: Fix registers #757
arcane-quill 4f2a2ec
ume: Use hardcoded arguments #757
arcane-quill 16ea90b
ume: Improve register hardcoding #757
arcane-quill 93f5a2b
ume: Add syscall #757
arcane-quill ad2f2e5
ume: Remove sepc #757
arcane-quill e39efaf
ume: Add synthetic exception #757
arcane-quill 20f20ff
ume: Add more synth syscall logic #757
arcane-quill File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
vadl/main/resources/templates/iss/linux-user/gen-arch/meson.build
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| syscall_nr_generators += { | ||
| 'rv64ume': generator(sh, | ||
| '[(${gen_arch_lower})]': generator(sh, | ||
| arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ], | ||
| output: '@BASENAME@_nr.h') | ||
| } |
162 changes: 12 additions & 150 deletions
162
vadl/main/resources/templates/iss/linux-user/gen-arch/signal.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,171 +1,33 @@ | ||
| /* | ||
| * Emulation of Linux signals for rv64ume user-mode. | ||
| */ | ||
|
|
||
| #include "qemu/osdep.h" | ||
| #include "qemu.h" | ||
| #include "user-internals.h" | ||
| #include "signal-common.h" | ||
| #include "linux-user/trace.h" | ||
|
|
||
| /* | ||
| * Minimal sigcontext matching rv64ume state: | ||
| * - pc | ||
| * - x1..x31 (x0 is always zero and omitted) | ||
| */ | ||
| struct target_sigcontext { | ||
| abi_long pc; | ||
| abi_long gpr[31]; | ||
| }; | ||
|
|
||
| struct target_ucontext { | ||
| abi_ulong uc_flags; | ||
| abi_ptr uc_link; | ||
| target_stack_t uc_stack; | ||
| target_sigset_t uc_sigmask; | ||
| uint8_t __unused[1024 / 8 - sizeof(target_sigset_t)]; | ||
| struct target_sigcontext uc_mcontext QEMU_ALIGNED(16); | ||
| }; | ||
|
|
||
| struct target_rt_sigframe { | ||
| struct target_siginfo info; | ||
| struct target_ucontext uc; | ||
| }; | ||
|
|
||
| static abi_ulong get_sigframe(struct target_sigaction *ka, | ||
| CPURV64UMEState *regs, size_t framesize) | ||
| { | ||
| abi_ulong sp = get_sp_from_cpustate(regs); | ||
|
|
||
| if (on_sig_stack(sp) && !likely(on_sig_stack(sp - framesize))) { | ||
| return -1L; | ||
| } | ||
|
|
||
| sp = target_sigsp(sp, ka) - framesize; | ||
| sp &= ~0xf; | ||
|
|
||
| return sp; | ||
| } | ||
|
|
||
| static void setup_sigcontext(struct target_sigcontext *sc, CPURV64UMEState *env) | ||
| { | ||
| int i; | ||
|
|
||
| __put_user(env->pc, &sc->pc); | ||
| for (i = 1; i < 32; i++) { | ||
| __put_user(env->x[i], &sc->gpr[i - 1]); | ||
| } | ||
| } | ||
|
|
||
| static void setup_ucontext(struct target_ucontext *uc, | ||
| CPURV64UMEState *env, target_sigset_t *set) | ||
| { | ||
| int i; | ||
|
|
||
| __put_user(0, &(uc->uc_flags)); | ||
| __put_user(0, &(uc->uc_link)); | ||
|
|
||
| target_save_altstack(&uc->uc_stack, env); | ||
|
|
||
| for (i = 0; i < TARGET_NSIG_WORDS; i++) { | ||
| __put_user(set->sig[i], &(uc->uc_sigmask.sig[i])); | ||
| } | ||
|
|
||
| setup_sigcontext(&uc->uc_mcontext, env); | ||
| } | ||
|
|
||
| void setup_rt_frame(int sig, struct target_sigaction *ka, | ||
| target_siginfo_t *info, | ||
| target_sigset_t *set, CPURV64UMEState *env) | ||
| target_sigset_t *set, CPU[(${gen_arch_upper})]State *env) | ||
| { | ||
| abi_ulong frame_addr; | ||
| struct target_rt_sigframe *frame; | ||
|
|
||
| frame_addr = get_sigframe(ka, env, sizeof(*frame)); | ||
| trace_user_setup_rt_frame(env, frame_addr); | ||
| (void)ka; | ||
| (void)info; | ||
| (void)set; | ||
| (void)env; | ||
|
|
||
| if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) { | ||
| goto badframe; | ||
| } | ||
|
|
||
| setup_ucontext(&frame->uc, env, set); | ||
| frame->info = *info; | ||
|
|
||
| env->pc = ka->_sa_handler; | ||
| env->x[RV64UME_REG_SP] = frame_addr; | ||
| env->x[RV64UME_REG_A0] = sig; | ||
| env->x[RV64UME_REG_A1] = frame_addr + offsetof(struct target_rt_sigframe, info); | ||
| env->x[RV64UME_REG_A2] = frame_addr + offsetof(struct target_rt_sigframe, uc); | ||
| env->x[RV64UME_REG_RA] = default_rt_sigreturn; | ||
|
|
||
| return; | ||
|
|
||
| badframe: | ||
| unlock_user_struct(frame, frame_addr, 1); | ||
| if (sig == TARGET_SIGSEGV) { | ||
| ka->_sa_handler = TARGET_SIG_DFL; | ||
| force_sig(TARGET_SIGSEGV); | ||
| } else { | ||
| force_sig(sig); | ||
| } | ||
| force_sig(TARGET_SIGSEGV); | ||
| } | ||
|
|
||
| static void restore_sigcontext(CPURV64UMEState *env, struct target_sigcontext *sc) | ||
| long do_rt_sigreturn(CPU[(${gen_arch_upper})]State *env) | ||
| { | ||
| int i; | ||
|
|
||
| __get_user(env->pc, &sc->pc); | ||
| for (i = 1; i < 32; ++i) { | ||
| __get_user(env->x[i], &sc->gpr[i - 1]); | ||
| } | ||
| } | ||
|
|
||
| static void restore_ucontext(CPURV64UMEState *env, struct target_ucontext *uc) | ||
| { | ||
| sigset_t blocked; | ||
| target_sigset_t target_set; | ||
| int i; | ||
|
|
||
| target_sigemptyset(&target_set); | ||
| for (i = 0; i < TARGET_NSIG_WORDS; i++) { | ||
| __get_user(target_set.sig[i], &(uc->uc_sigmask.sig[i])); | ||
| } | ||
| (void)env; | ||
|
|
||
| target_to_host_sigset_internal(&blocked, &target_set); | ||
| set_sigmask(&blocked); | ||
|
|
||
| restore_sigcontext(env, &uc->uc_mcontext); | ||
| } | ||
|
|
||
| long do_rt_sigreturn(CPURV64UMEState *env) | ||
| { | ||
| struct target_rt_sigframe *frame; | ||
| abi_ulong frame_addr; | ||
|
|
||
| frame_addr = env->x[RV64UME_REG_SP]; | ||
| trace_user_do_sigreturn(env, frame_addr); | ||
| if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) { | ||
| goto badframe; | ||
| } | ||
|
|
||
| restore_ucontext(env, &frame->uc); | ||
| target_restore_altstack(&frame->uc.uc_stack, env); | ||
|
|
||
| unlock_user_struct(frame, frame_addr, 0); | ||
| return -QEMU_ESIGRETURN; | ||
|
|
||
| badframe: | ||
| unlock_user_struct(frame, frame_addr, 0); | ||
| force_sig(TARGET_SIGSEGV); | ||
| return 0; | ||
| } | ||
|
|
||
| void setup_sigtramp(abi_ulong sigtramp_page) | ||
| { | ||
| uint32_t *tramp = lock_user(VERIFY_WRITE, sigtramp_page, 8, 0); | ||
| assert(tramp != NULL); | ||
|
|
||
| __put_user(0x08b00893, tramp + 0); /* li a7, 139 = __NR_rt_sigreturn */ | ||
| __put_user(0x00000073, tramp + 1); /* ecall */ | ||
|
|
||
| default_rt_sigreturn = sigtramp_page; | ||
| unlock_user(tramp, sigtramp_page, 8); | ||
| } | ||
| (void)sigtramp_page; | ||
| } |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor: This whole table is currently hardcoded. However, I think we should do the dynamic interpolation in a separate PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Fine for now, later this should be minimized to a minimal set of definitions that is required for the UME (#968).