From: Nick Sampanis <nicksampanis@gmail.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Richard Henderson <richard.henderson@linaro.org>,
Nick Sampanis <Nicksampanis@gmail.com>
Subject: [PATCH 3/3] target/i386/tcg: Set EXT bit in error codes during event delivery
Date: Fri, 4 Dec 2026 23:26:40 +0200 [thread overview]
Message-ID: <20261204212641.2770-4-Nicksampanis@gmail.com> (raw)
In-Reply-To: <20261204212641.2770-1-Nicksampanis@gmail.com>
The EXT flag (bit 0 of an exception error code) marks faults raised
while delivering an event, including hardware interrupts and prior
exceptions, while staying clear for software interrupts such as INT n,
INT3, and INTO (Intel SDM Vol. 3A 7.13 "Error Code").
Currently, QEMU never sets EXT for faults raised during interrupt or
exception delivery. As a result, error codes are inaccurate across IDT
gate checks, target code-segment checks, TSS stack switching (#TS/#SS),
and task-gate transitions (#TS/#NP/#GP).
Vendor rules differ on when EXT applies (AMD64 APM Vol. 2 8.4.1
"Selector-Error Code"). On AMD, EXT is set when the exception source
is external to the processor (is_hw), whereas Intel sets it for any
event except software interrupts, including exceptions (!is_int).
Add an ext argument for switch_tss_ra(), tss_load_seg(),
get_ss_esp_from_tss(), and get_rsp_from_tss().
Signed-off-by: Nick Sampanis <Nicksampanis@gmail.com>
---
target/i386/tcg/seg_helper.c | 176 ++++++++++++++++++++---------------
1 file changed, 102 insertions(+), 74 deletions(-)
diff --git a/target/i386/tcg/seg_helper.c b/target/i386/tcg/seg_helper.c
index 1a986ce7a9..ea1eb827e8 100644
--- a/target/i386/tcg/seg_helper.c
+++ b/target/i386/tcg/seg_helper.c
@@ -224,7 +224,7 @@ static inline void load_seg_vm(CPUX86State *env, int seg, int selector)
static inline void get_ss_esp_from_tss(CPUX86State *env, uint32_t *ss_ptr,
uint32_t *esp_ptr, int dpl,
- uintptr_t retaddr)
+ uintptr_t retaddr, uint8_t ext)
{
X86CPU *cpu = env_archcpu(env);
int type, index, shift;
@@ -253,7 +253,8 @@ static inline void get_ss_esp_from_tss(CPUX86State *env, uint32_t *ss_ptr,
shift = type >> 3;
index = (dpl * 4 + 2) << shift;
if (index + (4 << shift) - 1 > env->tr.limit) {
- raise_exception_err_ra(env, EXCP0A_TSS, env->tr.selector & 0xfffc, retaddr);
+ raise_exception_err_ra(env, EXCP0A_TSS,
+ (env->tr.selector & 0xfffc) | ext, retaddr);
}
if (shift == 0) {
*esp_ptr = cpu_lduw_kernel_ra(env, env->tr.base + index, retaddr);
@@ -265,49 +266,58 @@ static inline void get_ss_esp_from_tss(CPUX86State *env, uint32_t *ss_ptr,
}
static void tss_load_seg(CPUX86State *env, X86Seg seg_reg, int selector,
- int cpl, uintptr_t retaddr)
+ int cpl, uintptr_t retaddr, uint8_t ext)
{
uint32_t e1, e2;
int rpl, dpl;
if ((selector & 0xfffc) != 0) {
if (load_segment_ra(env, &e1, &e2, selector, retaddr) != 0) {
- raise_exception_err_ra(env, EXCP0A_TSS, selector & 0xfffc, retaddr);
+ raise_exception_err_ra(env, EXCP0A_TSS, (selector & 0xfffc) | ext,
+ retaddr);
}
if (!(e2 & DESC_S_MASK)) {
- raise_exception_err_ra(env, EXCP0A_TSS, selector & 0xfffc, retaddr);
+ raise_exception_err_ra(env, EXCP0A_TSS, (selector & 0xfffc) | ext,
+ retaddr);
}
rpl = selector & 3;
dpl = (e2 >> DESC_DPL_SHIFT) & 3;
if (seg_reg == R_CS) {
if (!(e2 & DESC_CS_MASK)) {
- raise_exception_err_ra(env, EXCP0A_TSS, selector & 0xfffc, retaddr);
+ raise_exception_err_ra(env, EXCP0A_TSS,
+ (selector & 0xfffc) | ext, retaddr);
}
if (dpl != rpl) {
- raise_exception_err_ra(env, EXCP0A_TSS, selector & 0xfffc, retaddr);
+ raise_exception_err_ra(env, EXCP0A_TSS,
+ (selector & 0xfffc) | ext, retaddr);
}
} else if (seg_reg == R_SS) {
/* SS must be writable data */
if ((e2 & DESC_CS_MASK) || !(e2 & DESC_W_MASK)) {
- raise_exception_err_ra(env, EXCP0A_TSS, selector & 0xfffc, retaddr);
+ raise_exception_err_ra(env, EXCP0A_TSS,
+ (selector & 0xfffc) | ext, retaddr);
}
if (dpl != cpl || dpl != rpl) {
- raise_exception_err_ra(env, EXCP0A_TSS, selector & 0xfffc, retaddr);
+ raise_exception_err_ra(env, EXCP0A_TSS,
+ (selector & 0xfffc) | ext, retaddr);
}
} else {
/* not readable code */
if ((e2 & DESC_CS_MASK) && !(e2 & DESC_R_MASK)) {
- raise_exception_err_ra(env, EXCP0A_TSS, selector & 0xfffc, retaddr);
+ raise_exception_err_ra(env, EXCP0A_TSS,
+ (selector & 0xfffc) | ext, retaddr);
}
/* if data or non conforming code, checks the rights */
if (((e2 >> DESC_TYPE_SHIFT) & 0xf) < 12) {
if (dpl < cpl || dpl < rpl) {
- raise_exception_err_ra(env, EXCP0A_TSS, selector & 0xfffc, retaddr);
+ raise_exception_err_ra(env, EXCP0A_TSS,
+ (selector & 0xfffc) | ext, retaddr);
}
}
}
if (!(e2 & DESC_P_MASK)) {
- raise_exception_err_ra(env, EXCP0B_NOSEG, selector & 0xfffc, retaddr);
+ raise_exception_err_ra(env, EXCP0B_NOSEG, (selector & 0xfffc) | ext,
+ retaddr);
}
set_seg_accessed(env, selector, &e2, retaddr);
cpu_x86_load_seg_cache(env, seg_reg, selector,
@@ -316,7 +326,8 @@ static void tss_load_seg(CPUX86State *env, X86Seg seg_reg, int selector,
e2);
} else {
if (seg_reg == R_SS || seg_reg == R_CS) {
- raise_exception_err_ra(env, EXCP0A_TSS, selector & 0xfffc, retaddr);
+ raise_exception_err_ra(env, EXCP0A_TSS, (selector & 0xfffc) | ext,
+ retaddr);
}
}
}
@@ -343,7 +354,7 @@ static void tss_set_busy(CPUX86State *env, int tss_selector, bool value,
static void switch_tss_ra(CPUX86State *env, int tss_selector,
uint32_t e1, uint32_t e2, int source,
uint32_t next_eip, bool has_error_code,
- uint32_t error_code, uintptr_t retaddr)
+ uint32_t error_code, uintptr_t retaddr, uint8_t ext)
{
int tss_limit, tss_limit_max, type, old_tss_limit_max, old_type, i;
target_ulong tss_base;
@@ -362,26 +373,32 @@ static void switch_tss_ra(CPUX86State *env, int tss_selector,
/* if task gate, we read the TSS segment and we load it */
if (type == 5) {
if (!(e2 & DESC_P_MASK)) {
- raise_exception_err_ra(env, EXCP0B_NOSEG, tss_selector & 0xfffc, retaddr);
+ raise_exception_err_ra(env, EXCP0B_NOSEG,
+ (tss_selector & 0xfffc) | ext, retaddr);
}
tss_selector = e1 >> 16;
if (tss_selector & 4) {
- raise_exception_err_ra(env, EXCP0A_TSS, tss_selector & 0xfffc, retaddr);
+ raise_exception_err_ra(env, EXCP0A_TSS,
+ (tss_selector & 0xfffc) | ext, retaddr);
}
if (load_segment_ra(env, &e1, &e2, tss_selector, retaddr) != 0) {
- raise_exception_err_ra(env, EXCP0D_GPF, tss_selector & 0xfffc, retaddr);
+ raise_exception_err_ra(env, EXCP0D_GPF,
+ (tss_selector & 0xfffc) | ext, retaddr);
}
if (e2 & DESC_S_MASK) {
- raise_exception_err_ra(env, EXCP0D_GPF, tss_selector & 0xfffc, retaddr);
+ raise_exception_err_ra(env, EXCP0D_GPF,
+ (tss_selector & 0xfffc) | ext, retaddr);
}
type = (e2 >> DESC_TYPE_SHIFT) & 0xf;
if ((type & 7) != 1) {
- raise_exception_err_ra(env, EXCP0D_GPF, tss_selector & 0xfffc, retaddr);
+ raise_exception_err_ra(env, EXCP0D_GPF,
+ (tss_selector & 0xfffc) | ext, retaddr);
}
}
if (!(e2 & DESC_P_MASK)) {
- raise_exception_err_ra(env, EXCP0B_NOSEG, tss_selector & 0xfffc, retaddr);
+ raise_exception_err_ra(env, EXCP0B_NOSEG, (tss_selector & 0xfffc) | ext,
+ retaddr);
}
if (type & 8) {
@@ -393,7 +410,8 @@ static void switch_tss_ra(CPUX86State *env, int tss_selector,
tss_base = get_seg_base(e1, e2);
if ((tss_selector & 4) != 0 ||
tss_limit < tss_limit_max) {
- raise_exception_err_ra(env, EXCP0A_TSS, tss_selector & 0xfffc, retaddr);
+ raise_exception_err_ra(env, EXCP0A_TSS, (tss_selector & 0xfffc) | ext,
+ retaddr);
}
old_type = (env->tr.flags >> DESC_TYPE_SHIFT) & 0xf;
if (old_type & 8) {
@@ -404,7 +422,8 @@ static void switch_tss_ra(CPUX86State *env, int tss_selector,
/* new TSS must be busy iff the source is an IRET instruction */
if (!!(e2 & DESC_TSS_BUSY_MASK) != (source == SWITCH_TSS_IRET)) {
- raise_exception_err_ra(env, EXCP0A_TSS, tss_selector & 0xfffc, retaddr);
+ raise_exception_err_ra(env, EXCP0A_TSS, (tss_selector & 0xfffc) | ext,
+ retaddr);
}
/* X86Access avoids memory exceptions during the task switch */
@@ -565,23 +584,27 @@ static void switch_tss_ra(CPUX86State *env, int tss_selector,
/* load the LDT */
if (new_ldt & 4) {
- raise_exception_err_ra(env, EXCP0A_TSS, new_ldt & 0xfffc, retaddr);
+ raise_exception_err_ra(env, EXCP0A_TSS, (new_ldt & 0xfffc) | ext,
+ retaddr);
}
if ((new_ldt & 0xfffc) != 0) {
dt = &env->gdt;
index = new_ldt & ~7;
if ((index + 7) > dt->limit) {
- raise_exception_err_ra(env, EXCP0A_TSS, new_ldt & 0xfffc, retaddr);
+ raise_exception_err_ra(env, EXCP0A_TSS, (new_ldt & 0xfffc) | ext,
+ retaddr);
}
ptr = dt->base + index;
e1 = cpu_ldl_kernel_ra(env, ptr, retaddr);
e2 = cpu_ldl_kernel_ra(env, ptr + 4, retaddr);
if ((e2 & DESC_S_MASK) || ((e2 >> DESC_TYPE_SHIFT) & 0xf) != 2) {
- raise_exception_err_ra(env, EXCP0A_TSS, new_ldt & 0xfffc, retaddr);
+ raise_exception_err_ra(env, EXCP0A_TSS, (new_ldt & 0xfffc) | ext,
+ retaddr);
}
if (!(e2 & DESC_P_MASK)) {
- raise_exception_err_ra(env, EXCP0A_TSS, new_ldt & 0xfffc, retaddr);
+ raise_exception_err_ra(env, EXCP0A_TSS, (new_ldt & 0xfffc) | ext,
+ retaddr);
}
load_seg_cache_raw_dt(&env->ldt, e1, e2);
}
@@ -589,18 +612,18 @@ static void switch_tss_ra(CPUX86State *env, int tss_selector,
/* load the segments */
if (!(new_eflags & VM_MASK)) {
int cpl = new_segs[R_CS] & 3;
- tss_load_seg(env, R_CS, new_segs[R_CS], cpl, retaddr);
- tss_load_seg(env, R_SS, new_segs[R_SS], cpl, retaddr);
- tss_load_seg(env, R_ES, new_segs[R_ES], cpl, retaddr);
- tss_load_seg(env, R_DS, new_segs[R_DS], cpl, retaddr);
- tss_load_seg(env, R_FS, new_segs[R_FS], cpl, retaddr);
- tss_load_seg(env, R_GS, new_segs[R_GS], cpl, retaddr);
+ tss_load_seg(env, R_CS, new_segs[R_CS], cpl, retaddr, ext);
+ tss_load_seg(env, R_SS, new_segs[R_SS], cpl, retaddr, ext);
+ tss_load_seg(env, R_ES, new_segs[R_ES], cpl, retaddr, ext);
+ tss_load_seg(env, R_DS, new_segs[R_DS], cpl, retaddr, ext);
+ tss_load_seg(env, R_FS, new_segs[R_FS], cpl, retaddr, ext);
+ tss_load_seg(env, R_GS, new_segs[R_GS], cpl, retaddr, ext);
}
/* check that env->eip is in the CS segment limits */
if (new_eip > env->segs[R_CS].limit) {
/* XXX: different exception if CALL? */
- raise_exception_err_ra(env, EXCP0D_GPF, 0, retaddr);
+ raise_exception_err_ra(env, EXCP0D_GPF, ext, retaddr);
}
#ifndef CONFIG_USER_ONLY
@@ -642,10 +665,10 @@ static void switch_tss_ra(CPUX86State *env, int tss_selector,
static void switch_tss(CPUX86State *env, int tss_selector,
uint32_t e1, uint32_t e2, int source,
uint32_t next_eip, bool has_error_code,
- int error_code)
+ int error_code, uint8_t ext)
{
switch_tss_ra(env, tss_selector, e1, e2, source, next_eip,
- has_error_code, error_code, 0);
+ has_error_code, error_code, 0, ext);
}
static inline unsigned int get_sp_mask(unsigned int e2)
@@ -709,7 +732,9 @@ static void do_interrupt_protected(CPUX86State *env, int intno, int is_int,
int vm86 = env->eflags & VM_MASK;
StackAccess sa;
bool set_rf;
+ uint8_t ext;
+ ext = IS_AMD_CPU(env) ? !!is_hw : !is_int;
has_error_code = 0;
if (!is_int && !is_hw) {
has_error_code = exception_has_error_code(intno);
@@ -724,7 +749,7 @@ static void do_interrupt_protected(CPUX86State *env, int intno, int is_int,
dt = &env->idt;
if (intno * 8 + 7 > dt->limit) {
- raise_exception_err(env, EXCP0D_GPF, intno * 8 + 2);
+ raise_exception_err(env, EXCP0D_GPF, (intno * 8) | 2 | ext);
}
ptr = dt->base + intno * 8;
e1 = cpu_ldl_kernel(env, ptr);
@@ -739,14 +764,14 @@ static void do_interrupt_protected(CPUX86State *env, int intno, int is_int,
case 15: /* 386 trap gate */
break;
default:
- raise_exception_err(env, EXCP0D_GPF, intno * 8 + 2);
+ raise_exception_err(env, EXCP0D_GPF, (intno * 8) | 2 | ext);
break;
}
dpl = (e2 >> DESC_DPL_SHIFT) & 3;
cpl = env->hflags & HF_CPL_MASK;
/* check privilege if software int */
if (is_int && dpl < cpl) {
- raise_exception_err(env, EXCP0D_GPF, intno * 8 + 2);
+ raise_exception_err(env, EXCP0D_GPF, (intno * 8) | 2 | ext);
}
sa.env = env;
@@ -756,10 +781,10 @@ static void do_interrupt_protected(CPUX86State *env, int intno, int is_int,
/* task gate */
/* must do that check here to return the correct error code */
if (!(e2 & DESC_P_MASK)) {
- raise_exception_err(env, EXCP0B_NOSEG, intno * 8 + 2);
+ raise_exception_err(env, EXCP0B_NOSEG, (intno * 8) | 2 | ext);
}
switch_tss(env, intno * 8, e1, e2, SWITCH_TSS_CALL, old_eip,
- has_error_code, error_code);
+ has_error_code, error_code, ext);
return;
}
@@ -767,25 +792,25 @@ static void do_interrupt_protected(CPUX86State *env, int intno, int is_int,
/* check valid bit */
if (!(e2 & DESC_P_MASK)) {
- raise_exception_err(env, EXCP0B_NOSEG, intno * 8 + 2);
+ raise_exception_err(env, EXCP0B_NOSEG, (intno * 8) | 2 | ext);
}
selector = e1 >> 16;
offset = (e2 & 0xffff0000) | (e1 & 0x0000ffff);
if ((selector & 0xfffc) == 0) {
- raise_exception_err(env, EXCP0D_GPF, 0);
+ raise_exception_err(env, EXCP0D_GPF, ext);
}
if (load_segment(env, &e1, &e2, selector) != 0) {
- raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc);
+ raise_exception_err(env, EXCP0D_GPF, (selector & 0xfffc) | ext);
}
if (!(e2 & DESC_S_MASK) || !(e2 & (DESC_CS_MASK))) {
- raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc);
+ raise_exception_err(env, EXCP0D_GPF, (selector & 0xfffc) | ext);
}
dpl = (e2 >> DESC_DPL_SHIFT) & 3;
if (dpl > cpl) {
- raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc);
+ raise_exception_err(env, EXCP0D_GPF, (selector & 0xfffc) | ext);
}
if (!(e2 & DESC_P_MASK)) {
- raise_exception_err(env, EXCP0B_NOSEG, selector & 0xfffc);
+ raise_exception_err(env, EXCP0B_NOSEG, (selector & 0xfffc) | ext);
}
set_seg_accessed(env, selector, &e2, 0);
if (e2 & DESC_C_MASK) {
@@ -795,27 +820,27 @@ static void do_interrupt_protected(CPUX86State *env, int intno, int is_int,
if (dpl < cpl) {
/* to inner privilege */
uint32_t esp;
- get_ss_esp_from_tss(env, &ss, &esp, dpl, 0);
+ get_ss_esp_from_tss(env, &ss, &esp, dpl, 0, ext);
if ((ss & 0xfffc) == 0) {
- raise_exception_err(env, EXCP0A_TSS, ss & 0xfffc);
+ raise_exception_err(env, EXCP0A_TSS, (ss & 0xfffc) | ext);
}
if ((ss & 3) != dpl) {
- raise_exception_err(env, EXCP0A_TSS, ss & 0xfffc);
+ raise_exception_err(env, EXCP0A_TSS, (ss & 0xfffc) | ext);
}
if (load_segment(env, &ss_e1, &ss_e2, ss) != 0) {
- raise_exception_err(env, EXCP0A_TSS, ss & 0xfffc);
+ raise_exception_err(env, EXCP0A_TSS, (ss & 0xfffc) | ext);
}
ss_dpl = (ss_e2 >> DESC_DPL_SHIFT) & 3;
if (ss_dpl != dpl) {
- raise_exception_err(env, EXCP0A_TSS, ss & 0xfffc);
+ raise_exception_err(env, EXCP0A_TSS, (ss & 0xfffc) | ext);
}
if (!(ss_e2 & DESC_S_MASK) ||
(ss_e2 & DESC_CS_MASK) ||
!(ss_e2 & DESC_W_MASK)) {
- raise_exception_err(env, EXCP0A_TSS, ss & 0xfffc);
+ raise_exception_err(env, EXCP0A_TSS, (ss & 0xfffc) | ext);
}
if (!(ss_e2 & DESC_P_MASK)) {
- raise_exception_err(env, EXCP0A_TSS, ss & 0xfffc);
+ raise_exception_err(env, EXCP0A_TSS, (ss & 0xfffc) | ext);
}
set_seg_accessed(env, ss, &ss_e2, 0);
new_stack = 1;
@@ -825,7 +850,7 @@ static void do_interrupt_protected(CPUX86State *env, int intno, int is_int,
} else {
/* to same privilege */
if (vm86) {
- raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc);
+ raise_exception_err(env, EXCP0D_GPF, (selector & 0xfffc) | ext);
}
new_stack = 0;
sa.sp = env->regs[R_ESP];
@@ -930,7 +955,8 @@ static uint64_t popq(StackAccess *sa)
return ret;
}
-static inline target_ulong get_rsp_from_tss(CPUX86State *env, int level)
+static inline target_ulong get_rsp_from_tss(CPUX86State *env, int level,
+ uint8_t ext)
{
X86CPU *cpu = env_archcpu(env);
int index, pg_mode;
@@ -947,7 +973,7 @@ static inline target_ulong get_rsp_from_tss(CPUX86State *env, int level)
}
index = 8 * level + 4;
if ((index + 7) > env->tr.limit) {
- raise_exception_err(env, EXCP0A_TSS, env->tr.selector & 0xfffc);
+ raise_exception_err(env, EXCP0A_TSS, (env->tr.selector & 0xfffc) | ext);
}
rsp = cpu_ldq_kernel(env, env->tr.base + index);
@@ -956,7 +982,7 @@ static inline target_ulong get_rsp_from_tss(CPUX86State *env, int level)
pg_mode = get_pg_mode(env);
sext = (int64_t)rsp >> (pg_mode & PG_MODE_LA57 ? 56 : 47);
if (sext != 0 && sext != -1) {
- raise_exception_err(env, EXCP0C_STACK, 0);
+ raise_exception_err(env, EXCP0C_STACK, ext);
}
return rsp;
@@ -974,7 +1000,9 @@ static void do_interrupt64(CPUX86State *env, int intno, int is_int,
target_ulong old_eip, offset;
bool set_rf;
StackAccess sa;
+ uint8_t ext;
+ ext = IS_AMD_CPU(env) ? !!is_hw : !is_int;
has_error_code = 0;
if (!is_int && !is_hw) {
has_error_code = exception_has_error_code(intno);
@@ -989,7 +1017,7 @@ static void do_interrupt64(CPUX86State *env, int intno, int is_int,
dt = &env->idt;
if (intno * 16 + 15 > dt->limit) {
- raise_exception_err(env, EXCP0D_GPF, intno * 8 + 2);
+ raise_exception_err(env, EXCP0D_GPF, (intno * 8) | 2 | ext);
}
ptr = dt->base + intno * 16;
e1 = cpu_ldl_kernel(env, ptr);
@@ -1002,41 +1030,41 @@ static void do_interrupt64(CPUX86State *env, int intno, int is_int,
case 15: /* 386 trap gate */
break;
default:
- raise_exception_err(env, EXCP0D_GPF, intno * 8 + 2);
+ raise_exception_err(env, EXCP0D_GPF, (intno * 8) | 2 | ext);
break;
}
dpl = (e2 >> DESC_DPL_SHIFT) & 3;
cpl = env->hflags & HF_CPL_MASK;
/* check privilege if software int */
if (is_int && dpl < cpl) {
- raise_exception_err(env, EXCP0D_GPF, intno * 8 + 2);
+ raise_exception_err(env, EXCP0D_GPF, (intno * 8) | 2 | ext);
}
/* check valid bit */
if (!(e2 & DESC_P_MASK)) {
- raise_exception_err(env, EXCP0B_NOSEG, intno * 8 + 2);
+ raise_exception_err(env, EXCP0B_NOSEG, (intno * 8) | 2 | ext);
}
selector = e1 >> 16;
offset = ((target_ulong)e3 << 32) | (e2 & 0xffff0000) | (e1 & 0x0000ffff);
ist = e2 & 7;
if ((selector & 0xfffc) == 0) {
- raise_exception_err(env, EXCP0D_GPF, 0);
+ raise_exception_err(env, EXCP0D_GPF, ext);
}
if (load_segment(env, &e1, &e2, selector) != 0) {
- raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc);
+ raise_exception_err(env, EXCP0D_GPF, (selector & 0xfffc) | ext);
}
if (!(e2 & DESC_S_MASK) || !(e2 & (DESC_CS_MASK))) {
- raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc);
+ raise_exception_err(env, EXCP0D_GPF, (selector & 0xfffc) | ext);
}
dpl = (e2 >> DESC_DPL_SHIFT) & 3;
if (dpl > cpl) {
- raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc);
+ raise_exception_err(env, EXCP0D_GPF, (selector & 0xfffc) | ext);
}
if (!(e2 & DESC_P_MASK)) {
- raise_exception_err(env, EXCP0B_NOSEG, selector & 0xfffc);
+ raise_exception_err(env, EXCP0B_NOSEG, (selector & 0xfffc) | ext);
}
if (!(e2 & DESC_L_MASK) || (e2 & DESC_B_MASK)) {
- raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc);
+ raise_exception_err(env, EXCP0D_GPF, (selector & 0xfffc) | ext);
}
set_seg_accessed(env, selector, &e2, 0);
if (e2 & DESC_C_MASK) {
@@ -1051,11 +1079,11 @@ static void do_interrupt64(CPUX86State *env, int intno, int is_int,
if (dpl < cpl || ist != 0) {
/* to inner privilege */
new_stack = 1;
- sa.sp = get_rsp_from_tss(env, ist != 0 ? ist + 3 : dpl);
+ sa.sp = get_rsp_from_tss(env, ist != 0 ? ist + 3 : dpl, ext);
} else {
/* to same privilege */
if (env->eflags & VM_MASK) {
- raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc);
+ raise_exception_err(env, EXCP0D_GPF, (selector & 0xfffc) | ext);
}
new_stack = 0;
sa.sp = env->regs[R_ESP];
@@ -1571,7 +1599,7 @@ void HELPER(ljmp_protected)(CPUX86State *env, int new_cs, target_ulong new_eip,
raise_exception_err_ra(env, EXCP0D_GPF, new_cs & 0xfffc, GETPC());
}
switch_tss_ra(env, new_cs, e1, e2, SWITCH_TSS_JMP, next_eip,
- false, 0, GETPC());
+ false, 0, GETPC(), 0);
break;
case 4: /* 286 call gate */
case 12: /* 386 call gate */
@@ -1791,7 +1819,7 @@ void HELPER(lcall_protected)(CPUX86State *env, int new_cs, target_ulong new_eip,
raise_exception_err_ra(env, EXCP0D_GPF, new_cs & 0xfffc, GETPC());
}
switch_tss_ra(env, new_cs, e1, e2, SWITCH_TSS_CALL, next_eip,
- false, 0, GETPC());
+ false, 0, GETPC(), 0);
return;
case 4: /* 286 call gate */
case 12: /* 386 call gate */
@@ -1864,7 +1892,7 @@ void HELPER(lcall_protected)(CPUX86State *env, int new_cs, target_ulong new_eip,
if (shift == 2) {
ss = dpl; /* SS = NULL selector with RPL = new CPL */
new_stack = 1;
- sa.sp = get_rsp_from_tss(env, dpl);
+ sa.sp = get_rsp_from_tss(env, dpl, 0);
sa.sp_mask = -1;
sa.ss_base = 0; /* SS base is always zero in IA-32e mode */
LOG_PCALL("new ss:rsp=%04x:%016llx env->regs[R_ESP]="
@@ -1873,7 +1901,7 @@ void HELPER(lcall_protected)(CPUX86State *env, int new_cs, target_ulong new_eip,
#endif
{
uint32_t sp32;
- get_ss_esp_from_tss(env, &ss, &sp32, dpl, GETPC());
+ get_ss_esp_from_tss(env, &ss, &sp32, dpl, GETPC(), 0);
LOG_PCALL("new ss:esp=%04x:%08x param_count=%d env->regs[R_ESP]="
TARGET_FMT_lx "\n", ss, sp32, param_count,
env->regs[R_ESP]);
@@ -2313,7 +2341,7 @@ void HELPER(iret_protected)(CPUX86State *env, int shift, int next_eip)
raise_exception_err_ra(env, EXCP0A_TSS, tss_selector & 0xfffc, GETPC());
}
switch_tss_ra(env, tss_selector, e1, e2, SWITCH_TSS_IRET, next_eip,
- false, 0, GETPC());
+ false, 0, GETPC(), 0);
} else {
helper_ret_protected(env, shift, 1, 0, GETPC());
}
--
2.51.0.windows.2
prev parent reply other threads:[~2026-12-04 21:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 21:26 [PATCH 0/3] target/i386: seg_helper fixes for segment, TSS, and EXT behavior Nick Sampanis
2026-12-04 21:26 ` [PATCH 1/3] target/i386/tcg: Set accessed bit on CS, SS and TSS segment loads Nick Sampanis
2026-12-04 21:26 ` [PATCH 2/3] target/i386/tcg: Keep busy TSS type in TR hidden state Nick Sampanis
2026-12-04 21:26 ` Nick Sampanis [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204212641.2770-4-Nicksampanis@gmail.com \
--to=nicksampanis@gmail.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.