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

TCG: Add exception for ilink access in usermode #209

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions target/arc/translate.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,15 @@ static TCGv arc_decode_operand(const struct arc_opcode *opcode,
ret = cpu_r[operand.value];
if (operand.value == 63) {
tcg_gen_movi_tl(cpu_pcl, ctx->pcl);
} else if (operand.value == 29) {
/* ilink access in user mode raises a privilege violation */
TCGv cond = tcg_temp_new();
TCGLabel *cont = gen_new_label();
tcg_gen_andi_tl(cond, cpu_pstate, STATUS32_U);
tcg_gen_brcondi_tl(TCG_COND_EQ, cond, 0, cont);
tcg_temp_free(cond);
arc_gen_excp(ctx, EXCP_PRIVILEGEV, 0, 0);
gen_set_label(cont);
}
} else {
int64_t limm = operand.value;
Expand Down
57 changes: 57 additions & 0 deletions tests/tcg/arc/generic/check_ilink_usermode.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
.include "macros.inc"

.data
.align 4
return_addr:
.word @fail

.text
.align 4
.global EV_PrivilegeV
.type EV_PrivilegeV, @function
EV_PrivilegeV:
ld r0, [@return_addr]
sr r0, [eret]
rtie

start

; Test 1
; ilink change in kernel mode (initial mode) is allowed
; CPU exception not triggered
mov r0, @fail
st r0, [@return_addr]

mov ilink, 0x91


; Test 2
; ilink change in user mode not allowed
; CPU exception is triggered
mov r0, @success
st r0, [@return_addr]

enter_user_mode @usermode

j @fail

usermode:
mov ilink, 0x91
j @fail

success:
mov r0, 0xdecaf
print "[PASS] "
b @1f

; If a test fails, it jumps here. Although, for the sake of uniformity,
; the printed output does not say much about which test case failed,
; one can uncomment the print_number line below or set a breakpoint
; here to check the R0 register for the test case number.
fail:
mov r0, 0xbadc0ffe
print "[FAIL] "
1:
print " no ilink in usermode\n"

end
57 changes: 57 additions & 0 deletions tests/tcg/arc64/check_ilink_usermode.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
.include "macros.inc"

.data
.align 4
return_addr:
.word @fail

.text
.align 4
.global EV_PrivilegeV
.type EV_PrivilegeV, @function
EV_PrivilegeV:
ld r0, [@return_addr]
sr r0, [eret]
rtie

start

; Test 1
; ilink change in kernel mode (initial mode) is allowed
; CPU exception not triggered
mov r0, @fail
st r0, [@return_addr]

mov ilink, 0x91


; Test 2
; ilink change in user mode not allowed
; CPU exception is triggered
mov r0, @success
st r0, [@return_addr]

enter_user_mode @usermode

j @fail

usermode:
mov ilink, 0x91
j @fail

success:
mov r0, 0xdecaf
print "[PASS] "
b @1f

; If a test fails, it jumps here. Although, for the sake of uniformity,
; the printed output does not say much about which test case failed,
; one can uncomment the print_number line below or set a breakpoint
; here to check the R0 register for the test case number.
fail:
mov r0, 0xbadc0ffe
print "[FAIL] "
1:
print " ilink in usermode\n"

end