@samitouri / QOSamiQemu / commits / 5d08f36983

target/i386/tcg/sysemu: Move target specific SMM code to separate functions

This code movement will make the next patch easier to read. Signed-off-by: Thomas Huth <thuth@redhat.com> Message-ID: <20260325120944.29391-2-thuth@redhat.com>

Thomas Huth committed Mar 25, 2026 at 13:09 UTC 5d08f369836aaad3d530b33bcdeb9062e8d3fc94
1 file changed +30 -17
target/i386/tcg/system/smm_helper.c
+30 -17
@@ -32,26 +32,13 @@
32 #define SMM_REVISION_ID 0x00020000
33 #endif
34
35 -void do_smm_enter(X86CPU *cpu)
35 +static void sm_state_init(X86CPU *cpu)
36 {
37 CPUX86State *env = &cpu->env;
38 CPUState *cs = CPU(cpu);
39 - target_ulong sm_state;
39 SegmentCache *dt;
40 int i, offset;
42 -
43 - qemu_log_mask(CPU_LOG_INT, "SMM: enter\n");
44 - log_cpu_state_mask(CPU_LOG_INT, CPU(cpu), CPU_DUMP_CCOP);
45 -
46 - env->msr_smi_count++;
47 - env->hflags |= HF_SMM_MASK;
48 - if (env->hflags2 & HF2_NMI_MASK) {
49 - env->hflags2 |= HF2_SMM_INSIDE_NMI_MASK;
50 - } else {
51 - env->hflags2 |= HF2_NMI_MASK;
52 - }
53 -
54 - sm_state = env->smbase + 0x8000;
41 + target_ulong sm_state = env->smbase + 0x8000;
42
43 #ifdef TARGET_X86_64
44 for (i = 0; i < 6; i++) {
@@ -156,6 +143,25 @@ void do_smm_enter(X86CPU *cpu)
143 x86_stl_phys(cs, sm_state + 0x7efc, SMM_REVISION_ID);
144 x86_stl_phys(cs, sm_state + 0x7ef8, env->smbase);
145 #endif
146 +}
147 +
148 +void do_smm_enter(X86CPU *cpu)
149 +{
150 + CPUX86State *env = &cpu->env;
151 +
152 + qemu_log_mask(CPU_LOG_INT, "SMM: enter\n");
153 + log_cpu_state_mask(CPU_LOG_INT, CPU(cpu), CPU_DUMP_CCOP);
154 +
155 + env->msr_smi_count++;
156 + env->hflags |= HF_SMM_MASK;
157 + if (env->hflags2 & HF2_NMI_MASK) {
158 + env->hflags2 |= HF2_SMM_INSIDE_NMI_MASK;
159 + } else {
160 + env->hflags2 |= HF2_NMI_MASK;
161 + }
162 +
163 + sm_state_init(cpu);
164 +
165 /* init SMM cpu state */
166
167 #ifdef TARGET_X86_64
@@ -191,9 +197,8 @@ void do_smm_enter(X86CPU *cpu)
197 DESC_G_MASK | DESC_A_MASK);
198 }
199
194 -void helper_rsm(CPUX86State *env)
200 +static void rsm_load_regs(CPUX86State *env)
201 {
196 - X86CPU *cpu = env_archcpu(env);
202 CPUState *cs = env_cpu(env);
203 target_ulong sm_state;
204 int i, offset;
@@ -308,6 +313,14 @@ void helper_rsm(CPUX86State *env)
313 env->smbase = x86_ldl_phys(cs, sm_state + 0x7ef8);
314 }
315 #endif
316 +}
317 +
318 +void helper_rsm(CPUX86State *env)
319 +{
320 + X86CPU *cpu = env_archcpu(env);
321 +
322 + rsm_load_regs(env);
323 +
324 if ((env->hflags2 & HF2_SMM_INSIDE_NMI_MASK) == 0) {
325 env->hflags2 &= ~HF2_NMI_MASK;
326 }