~ubuntu-branches/ubuntu/trusty/qemu/trusty

« back to all changes in this revision

Viewing changes to target-i386/seg_helper.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2013-10-22 22:47:07 UTC
  • mfrom: (1.8.3) (10.1.42 sid)
  • Revision ID: package-import@ubuntu.com-20131022224707-1lya34fw3k3f24tv
Tags: 1.6.0+dfsg-2ubuntu1
* Merge 1.6.0~rc0+dfsg-2exp from debian experimental.  Remaining changes:
  - debian/control
    * update maintainer
    * remove libiscsi, usb-redir, vde, vnc-jpeg, and libssh2-1-dev
      from build-deps
    * enable rbd
    * add qemu-system and qemu-common B/R to qemu-keymaps
    * add D:udev, R:qemu, R:qemu-common and B:qemu-common to
      qemu-system-common
    * qemu-system-arm, qemu-system-ppc, qemu-system-sparc:
      - add qemu-kvm to Provides
      - add qemu-common, qemu-kvm, kvm to B/R
      - remove openbios-sparc from qemu-system-sparc D
      - drop openbios-ppc and openhackware Depends to Suggests (for now)
    * qemu-system-x86:
      - add qemu-common to Breaks/Replaces.
      - add cpu-checker to Recommends.
    * qemu-user: add B/R:qemu-kvm
    * qemu-kvm:
      - add armhf armel powerpc sparc to Architecture
      - C/R/P: qemu-kvm-spice
    * add qemu-common package
    * drop qemu-slof which is not packaged in ubuntu
  - add qemu-system-common.links for tap ifup/down scripts and OVMF link.
  - qemu-system-x86.links:
    * remove pxe rom links which are in kvm-ipxe
    * add symlink for kvm.1 manpage
  - debian/rules
    * add kvm-spice symlink to qemu-kvm
    * call dh_installmodules for qemu-system-x86
    * update dh_installinit to install upstart script
    * run dh_installman (Closes: #709241) (cherrypicked from 1.5.0+dfsg-2)
  - Add qemu-utils.links for kvm-* symlinks.
  - Add qemu-system-x86.qemu-kvm.upstart and .default
  - Add qemu-system-x86.modprobe to set nesting=1
  - Add qemu-system-common.preinst to add kvm group
  - qemu-system-common.postinst: remove bad group acl if there, then have
    udev relabel /dev/kvm.
  - New linaro patches from qemu-linaro rebasing branch
  - Dropped patches:
    * xen-simplify-xen_enabled.patch
    * sparc-linux-user-fix-missing-symbols-in-.rel-.rela.plt-sections.patch
    * main_loop-do-not-set-nonblocking-if-xen_enabled.patch
    * xen_machine_pv-do-not-create-a-dummy-CPU-in-machine-.patch
    * virtio-rng-fix-crash
  - Kept patches:
    * expose_vms_qemu64cpu.patch - updated
    * linaro arm patches from qemu-linaro rebasing branch
  - New patches:
    * fix-pci-add: change CONFIG variable in ifdef to make sure that
      pci_add is defined.
* Add linaro patches
* Add experimental mach-virt patches for arm virtualization.
* qemu-system-common.install: add debian/tmp/usr/lib to install the
  qemu-bridge-helper

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
#ifdef DEBUG_PCALL
32
32
# define LOG_PCALL(...) qemu_log_mask(CPU_LOG_PCALL, ## __VA_ARGS__)
33
 
# define LOG_PCALL_STATE(env)                                  \
34
 
    log_cpu_state_mask(CPU_LOG_PCALL, (env), CPU_DUMP_CCOP)
 
33
# define LOG_PCALL_STATE(cpu)                                  \
 
34
    log_cpu_state_mask(CPU_LOG_PCALL, (cpu), CPU_DUMP_CCOP)
35
35
#else
36
36
# define LOG_PCALL(...) do { } while (0)
37
 
# define LOG_PCALL_STATE(env) do { } while (0)
 
37
# define LOG_PCALL_STATE(cpu) do { } while (0)
38
38
#endif
39
39
 
40
40
/* return non zero if error */
324
324
        /* 32 bit */
325
325
        cpu_stl_kernel(env, env->tr.base + 0x20, next_eip);
326
326
        cpu_stl_kernel(env, env->tr.base + 0x24, old_eflags);
327
 
        cpu_stl_kernel(env, env->tr.base + (0x28 + 0 * 4), EAX);
328
 
        cpu_stl_kernel(env, env->tr.base + (0x28 + 1 * 4), ECX);
329
 
        cpu_stl_kernel(env, env->tr.base + (0x28 + 2 * 4), EDX);
330
 
        cpu_stl_kernel(env, env->tr.base + (0x28 + 3 * 4), EBX);
331
 
        cpu_stl_kernel(env, env->tr.base + (0x28 + 4 * 4), ESP);
332
 
        cpu_stl_kernel(env, env->tr.base + (0x28 + 5 * 4), EBP);
333
 
        cpu_stl_kernel(env, env->tr.base + (0x28 + 6 * 4), ESI);
334
 
        cpu_stl_kernel(env, env->tr.base + (0x28 + 7 * 4), EDI);
 
327
        cpu_stl_kernel(env, env->tr.base + (0x28 + 0 * 4), env->regs[R_EAX]);
 
328
        cpu_stl_kernel(env, env->tr.base + (0x28 + 1 * 4), env->regs[R_ECX]);
 
329
        cpu_stl_kernel(env, env->tr.base + (0x28 + 2 * 4), env->regs[R_EDX]);
 
330
        cpu_stl_kernel(env, env->tr.base + (0x28 + 3 * 4), env->regs[R_EBX]);
 
331
        cpu_stl_kernel(env, env->tr.base + (0x28 + 4 * 4), env->regs[R_ESP]);
 
332
        cpu_stl_kernel(env, env->tr.base + (0x28 + 5 * 4), env->regs[R_EBP]);
 
333
        cpu_stl_kernel(env, env->tr.base + (0x28 + 6 * 4), env->regs[R_ESI]);
 
334
        cpu_stl_kernel(env, env->tr.base + (0x28 + 7 * 4), env->regs[R_EDI]);
335
335
        for (i = 0; i < 6; i++) {
336
336
            cpu_stw_kernel(env, env->tr.base + (0x48 + i * 4),
337
337
                           env->segs[i].selector);
340
340
        /* 16 bit */
341
341
        cpu_stw_kernel(env, env->tr.base + 0x0e, next_eip);
342
342
        cpu_stw_kernel(env, env->tr.base + 0x10, old_eflags);
343
 
        cpu_stw_kernel(env, env->tr.base + (0x12 + 0 * 2), EAX);
344
 
        cpu_stw_kernel(env, env->tr.base + (0x12 + 1 * 2), ECX);
345
 
        cpu_stw_kernel(env, env->tr.base + (0x12 + 2 * 2), EDX);
346
 
        cpu_stw_kernel(env, env->tr.base + (0x12 + 3 * 2), EBX);
347
 
        cpu_stw_kernel(env, env->tr.base + (0x12 + 4 * 2), ESP);
348
 
        cpu_stw_kernel(env, env->tr.base + (0x12 + 5 * 2), EBP);
349
 
        cpu_stw_kernel(env, env->tr.base + (0x12 + 6 * 2), ESI);
350
 
        cpu_stw_kernel(env, env->tr.base + (0x12 + 7 * 2), EDI);
 
343
        cpu_stw_kernel(env, env->tr.base + (0x12 + 0 * 2), env->regs[R_EAX]);
 
344
        cpu_stw_kernel(env, env->tr.base + (0x12 + 1 * 2), env->regs[R_ECX]);
 
345
        cpu_stw_kernel(env, env->tr.base + (0x12 + 2 * 2), env->regs[R_EDX]);
 
346
        cpu_stw_kernel(env, env->tr.base + (0x12 + 3 * 2), env->regs[R_EBX]);
 
347
        cpu_stw_kernel(env, env->tr.base + (0x12 + 4 * 2), env->regs[R_ESP]);
 
348
        cpu_stw_kernel(env, env->tr.base + (0x12 + 5 * 2), env->regs[R_EBP]);
 
349
        cpu_stw_kernel(env, env->tr.base + (0x12 + 6 * 2), env->regs[R_ESI]);
 
350
        cpu_stw_kernel(env, env->tr.base + (0x12 + 7 * 2), env->regs[R_EDI]);
351
351
        for (i = 0; i < 4; i++) {
352
352
            cpu_stw_kernel(env, env->tr.base + (0x22 + i * 4),
353
353
                           env->segs[i].selector);
396
396
    }
397
397
    cpu_load_eflags(env, new_eflags, eflags_mask);
398
398
    /* XXX: what to do in 16 bit case? */
399
 
    EAX = new_regs[0];
400
 
    ECX = new_regs[1];
401
 
    EDX = new_regs[2];
402
 
    EBX = new_regs[3];
403
 
    ESP = new_regs[4];
404
 
    EBP = new_regs[5];
405
 
    ESI = new_regs[6];
406
 
    EDI = new_regs[7];
 
399
    env->regs[R_EAX] = new_regs[0];
 
400
    env->regs[R_ECX] = new_regs[1];
 
401
    env->regs[R_EDX] = new_regs[2];
 
402
    env->regs[R_EBX] = new_regs[3];
 
403
    env->regs[R_ESP] = new_regs[4];
 
404
    env->regs[R_EBP] = new_regs[5];
 
405
    env->regs[R_ESI] = new_regs[6];
 
406
    env->regs[R_EDI] = new_regs[7];
407
407
    if (new_eflags & VM_MASK) {
408
408
        for (i = 0; i < 6; i++) {
409
409
            load_seg_vm(env, i, new_segs[i]);
457
457
        tss_load_seg(env, R_GS, new_segs[R_GS]);
458
458
    }
459
459
 
460
 
    /* check that EIP is in the CS segment limits */
 
460
    /* check that env->eip is in the CS segment limits */
461
461
    if (new_eip > env->segs[R_CS].limit) {
462
462
        /* XXX: different exception if CALL? */
463
463
        raise_exception_err(env, EXCP0D_GPF, 0);
502
502
}
503
503
 
504
504
#ifdef TARGET_X86_64
505
 
#define SET_ESP(val, sp_mask)                           \
506
 
    do {                                                \
507
 
        if ((sp_mask) == 0xffff) {                      \
508
 
            ESP = (ESP & ~0xffff) | ((val) & 0xffff);   \
509
 
        } else if ((sp_mask) == 0xffffffffLL) {         \
510
 
            ESP = (uint32_t)(val);                      \
511
 
        } else {                                        \
512
 
            ESP = (val);                                \
513
 
        }                                               \
 
505
#define SET_ESP(val, sp_mask)                                   \
 
506
    do {                                                        \
 
507
        if ((sp_mask) == 0xffff) {                              \
 
508
            env->regs[R_ESP] = (env->regs[R_ESP] & ~0xffff) |   \
 
509
                ((val) & 0xffff);                               \
 
510
        } else if ((sp_mask) == 0xffffffffLL) {                 \
 
511
            env->regs[R_ESP] = (uint32_t)(val);                 \
 
512
        } else {                                                \
 
513
            env->regs[R_ESP] = (val);                           \
 
514
        }                                                       \
514
515
    } while (0)
515
516
#else
516
 
#define SET_ESP(val, sp_mask)                           \
517
 
    do {                                                \
518
 
        ESP = (ESP & ~(sp_mask)) | ((val) & (sp_mask)); \
 
517
#define SET_ESP(val, sp_mask)                                   \
 
518
    do {                                                        \
 
519
        env->regs[R_ESP] = (env->regs[R_ESP] & ~(sp_mask)) |    \
 
520
            ((val) & (sp_mask));                                \
519
521
    } while (0)
520
522
#endif
521
523
 
598
600
            } else {
599
601
                mask = 0xffff;
600
602
            }
601
 
            esp = (ESP - (2 << shift)) & mask;
 
603
            esp = (env->regs[R_ESP] - (2 << shift)) & mask;
602
604
            ssp = env->segs[R_SS].base + esp;
603
605
            if (shift) {
604
606
                cpu_stl_kernel(env, ssp, error_code);
680
682
        new_stack = 0;
681
683
        sp_mask = get_sp_mask(env->segs[R_SS].flags);
682
684
        ssp = env->segs[R_SS].base;
683
 
        esp = ESP;
 
685
        esp = env->regs[R_ESP];
684
686
        dpl = cpl;
685
687
    } else {
686
688
        raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc);
709
711
                PUSHL(ssp, esp, sp_mask, env->segs[R_ES].selector);
710
712
            }
711
713
            PUSHL(ssp, esp, sp_mask, env->segs[R_SS].selector);
712
 
            PUSHL(ssp, esp, sp_mask, ESP);
 
714
            PUSHL(ssp, esp, sp_mask, env->regs[R_ESP]);
713
715
        }
714
716
        PUSHL(ssp, esp, sp_mask, cpu_compute_eflags(env));
715
717
        PUSHL(ssp, esp, sp_mask, env->segs[R_CS].selector);
726
728
                PUSHW(ssp, esp, sp_mask, env->segs[R_ES].selector);
727
729
            }
728
730
            PUSHW(ssp, esp, sp_mask, env->segs[R_SS].selector);
729
 
            PUSHW(ssp, esp, sp_mask, ESP);
 
731
            PUSHW(ssp, esp, sp_mask, env->regs[R_ESP]);
730
732
        }
731
733
        PUSHW(ssp, esp, sp_mask, cpu_compute_eflags(env));
732
734
        PUSHW(ssp, esp, sp_mask, env->segs[R_CS].selector);
888
890
        if (ist != 0) {
889
891
            esp = get_rsp_from_tss(env, ist + 3);
890
892
        } else {
891
 
            esp = ESP;
 
893
            esp = env->regs[R_ESP];
892
894
        }
893
895
        esp &= ~0xfLL; /* align stack */
894
896
        dpl = cpl;
899
901
    }
900
902
 
901
903
    PUSHQ(esp, env->segs[R_SS].selector);
902
 
    PUSHQ(esp, ESP);
 
904
    PUSHQ(esp, env->regs[R_ESP]);
903
905
    PUSHQ(esp, cpu_compute_eflags(env));
904
906
    PUSHQ(esp, env->segs[R_CS].selector);
905
907
    PUSHQ(esp, old_eip);
911
913
        ss = 0 | dpl;
912
914
        cpu_x86_load_seg_cache(env, R_SS, ss, 0, 0, 0);
913
915
    }
914
 
    ESP = esp;
 
916
    env->regs[R_ESP] = esp;
915
917
 
916
918
    selector = (selector & ~3) | dpl;
917
919
    cpu_x86_load_seg_cache(env, R_CS, selector,
949
951
    if (env->hflags & HF_LMA_MASK) {
950
952
        int code64;
951
953
 
952
 
        ECX = env->eip + next_eip_addend;
 
954
        env->regs[R_ECX] = env->eip + next_eip_addend;
953
955
        env->regs[11] = cpu_compute_eflags(env);
954
956
 
955
957
        code64 = env->hflags & HF_CS64_MASK;
974
976
            env->eip = env->cstar;
975
977
        }
976
978
    } else {
977
 
        ECX = (uint32_t)(env->eip + next_eip_addend);
 
979
        env->regs[R_ECX] = (uint32_t)(env->eip + next_eip_addend);
978
980
 
979
981
        cpu_x86_set_cpl(env, 0);
980
982
        cpu_x86_load_seg_cache(env, R_CS, selector & 0xfffc,
1015
1017
                                   DESC_S_MASK | (3 << DESC_DPL_SHIFT) |
1016
1018
                                   DESC_CS_MASK | DESC_R_MASK | DESC_A_MASK |
1017
1019
                                   DESC_L_MASK);
1018
 
            env->eip = ECX;
 
1020
            env->eip = env->regs[R_ECX];
1019
1021
        } else {
1020
1022
            cpu_x86_load_seg_cache(env, R_CS, selector | 3,
1021
1023
                                   0, 0xffffffff,
1022
1024
                                   DESC_G_MASK | DESC_B_MASK | DESC_P_MASK |
1023
1025
                                   DESC_S_MASK | (3 << DESC_DPL_SHIFT) |
1024
1026
                                   DESC_CS_MASK | DESC_R_MASK | DESC_A_MASK);
1025
 
            env->eip = (uint32_t)ECX;
 
1027
            env->eip = (uint32_t)env->regs[R_ECX];
1026
1028
        }
1027
1029
        cpu_x86_load_seg_cache(env, R_SS, selector + 8,
1028
1030
                               0, 0xffffffff,
1039
1041
                               DESC_G_MASK | DESC_B_MASK | DESC_P_MASK |
1040
1042
                               DESC_S_MASK | (3 << DESC_DPL_SHIFT) |
1041
1043
                               DESC_CS_MASK | DESC_R_MASK | DESC_A_MASK);
1042
 
        env->eip = (uint32_t)ECX;
 
1044
        env->eip = (uint32_t)env->regs[R_ECX];
1043
1045
        cpu_x86_load_seg_cache(env, R_SS, selector + 8,
1044
1046
                               0, 0xffffffff,
1045
1047
                               DESC_G_MASK | DESC_B_MASK | DESC_P_MASK |
1069
1071
    ptr = dt->base + intno * 4;
1070
1072
    offset = cpu_lduw_kernel(env, ptr);
1071
1073
    selector = cpu_lduw_kernel(env, ptr + 2);
1072
 
    esp = ESP;
 
1074
    esp = env->regs[R_ESP];
1073
1075
    ssp = env->segs[R_SS].base;
1074
1076
    if (is_int) {
1075
1077
        old_eip = next_eip;
1083
1085
    PUSHW(ssp, esp, 0xffff, old_eip);
1084
1086
 
1085
1087
    /* update processor state */
1086
 
    ESP = (ESP & ~0xffff) | (esp & 0xffff);
 
1088
    env->regs[R_ESP] = (env->regs[R_ESP] & ~0xffff) | (esp & 0xffff);
1087
1089
    env->eip = offset;
1088
1090
    env->segs[R_CS].selector = selector;
1089
1091
    env->segs[R_CS].base = (selector << 4);
1120
1122
       exiting the emulation with the suitable exception and error
1121
1123
       code */
1122
1124
    if (is_int) {
1123
 
        EIP = next_eip;
 
1125
        env->eip = next_eip;
1124
1126
    }
1125
1127
}
1126
1128
 
1155
1157
 
1156
1158
/*
1157
1159
 * Begin execution of an interruption. is_int is TRUE if coming from
1158
 
 * the int instruction. next_eip is the EIP value AFTER the interrupt
 
1160
 * the int instruction. next_eip is the env->eip value AFTER the interrupt
1159
1161
 * instruction. It is only relevant if is_int is TRUE.
1160
1162
 */
1161
 
static void do_interrupt_all(CPUX86State *env, int intno, int is_int,
 
1163
static void do_interrupt_all(X86CPU *cpu, int intno, int is_int,
1162
1164
                             int error_code, target_ulong next_eip, int is_hw)
1163
1165
{
 
1166
    CPUX86State *env = &cpu->env;
 
1167
 
1164
1168
    if (qemu_loglevel_mask(CPU_LOG_INT)) {
1165
1169
        if ((env->cr[0] & CR0_PE_MASK)) {
1166
1170
            static int count;
1169
1173
                     " pc=" TARGET_FMT_lx " SP=%04x:" TARGET_FMT_lx,
1170
1174
                     count, intno, error_code, is_int,
1171
1175
                     env->hflags & HF_CPL_MASK,
1172
 
                     env->segs[R_CS].selector, EIP,
1173
 
                     (int)env->segs[R_CS].base + EIP,
1174
 
                     env->segs[R_SS].selector, ESP);
 
1176
                     env->segs[R_CS].selector, env->eip,
 
1177
                     (int)env->segs[R_CS].base + env->eip,
 
1178
                     env->segs[R_SS].selector, env->regs[R_ESP]);
1175
1179
            if (intno == 0x0e) {
1176
1180
                qemu_log(" CR2=" TARGET_FMT_lx, env->cr[2]);
1177
1181
            } else {
1178
 
                qemu_log(" EAX=" TARGET_FMT_lx, EAX);
 
1182
                qemu_log(" env->regs[R_EAX]=" TARGET_FMT_lx, env->regs[R_EAX]);
1179
1183
            }
1180
1184
            qemu_log("\n");
1181
 
            log_cpu_state(env, CPU_DUMP_CCOP);
 
1185
            log_cpu_state(CPU(cpu), CPU_DUMP_CCOP);
1182
1186
#if 0
1183
1187
            {
1184
1188
                int i;
1250
1254
    /* simulate a real cpu exception. On i386, it can
1251
1255
       trigger new exceptions, but we do not handle
1252
1256
       double or triple faults yet. */
1253
 
    do_interrupt_all(env, env->exception_index,
 
1257
    do_interrupt_all(cpu, env->exception_index,
1254
1258
                     env->exception_is_int,
1255
1259
                     env->error_code,
1256
1260
                     env->exception_next_eip, 0);
1261
1265
 
1262
1266
void do_interrupt_x86_hardirq(CPUX86State *env, int intno, int is_hw)
1263
1267
{
1264
 
    do_interrupt_all(env, intno, 0, 0, 0, is_hw);
 
1268
    do_interrupt_all(x86_env_get_cpu(env), intno, 0, 0, 0, is_hw);
1265
1269
}
1266
1270
 
1267
1271
void helper_enter_level(CPUX86State *env, int level, int data32,
1272
1276
 
1273
1277
    esp_mask = get_sp_mask(env->segs[R_SS].flags);
1274
1278
    ssp = env->segs[R_SS].base;
1275
 
    ebp = EBP;
1276
 
    esp = ESP;
 
1279
    ebp = env->regs[R_EBP];
 
1280
    esp = env->regs[R_ESP];
1277
1281
    if (data32) {
1278
1282
        /* 32 bit */
1279
1283
        esp -= 4;
1305
1309
{
1306
1310
    target_ulong esp, ebp;
1307
1311
 
1308
 
    ebp = EBP;
1309
 
    esp = ESP;
 
1312
    ebp = env->regs[R_EBP];
 
1313
    esp = env->regs[R_ESP];
1310
1314
 
1311
1315
    if (data64) {
1312
1316
        /* 64 bit */
1582
1586
        }
1583
1587
        cpu_x86_load_seg_cache(env, R_CS, (new_cs & 0xfffc) | cpl,
1584
1588
                       get_seg_base(e1, e2), limit, e2);
1585
 
        EIP = new_eip;
 
1589
        env->eip = new_eip;
1586
1590
    } else {
1587
1591
        /* jump to call or task gate */
1588
1592
        dpl = (e2 >> DESC_DPL_SHIFT) & 3;
1635
1639
            }
1636
1640
            cpu_x86_load_seg_cache(env, R_CS, (gate_cs & 0xfffc) | cpl,
1637
1641
                                   get_seg_base(e1, e2), limit, e2);
1638
 
            EIP = new_eip;
 
1642
            env->eip = new_eip;
1639
1643
            break;
1640
1644
        default:
1641
1645
            raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc);
1653
1657
    target_ulong ssp;
1654
1658
 
1655
1659
    new_eip = new_eip1;
1656
 
    esp = ESP;
 
1660
    esp = env->regs[R_ESP];
1657
1661
    esp_mask = get_sp_mask(env->segs[R_SS].flags);
1658
1662
    ssp = env->segs[R_SS].base;
1659
1663
    if (shift) {
1682
1686
 
1683
1687
    next_eip = env->eip + next_eip_addend;
1684
1688
    LOG_PCALL("lcall %04x:%08x s=%d\n", new_cs, (uint32_t)new_eip, shift);
1685
 
    LOG_PCALL_STATE(env);
 
1689
    LOG_PCALL_STATE(CPU(x86_env_get_cpu(env)));
1686
1690
    if ((new_cs & 0xfffc) == 0) {
1687
1691
        raise_exception_err(env, EXCP0D_GPF, 0);
1688
1692
    }
1721
1725
            target_ulong rsp;
1722
1726
 
1723
1727
            /* 64 bit case */
1724
 
            rsp = ESP;
 
1728
            rsp = env->regs[R_ESP];
1725
1729
            PUSHQ(rsp, env->segs[R_CS].selector);
1726
1730
            PUSHQ(rsp, next_eip);
1727
1731
            /* from this point, not restartable */
1728
 
            ESP = rsp;
 
1732
            env->regs[R_ESP] = rsp;
1729
1733
            cpu_x86_load_seg_cache(env, R_CS, (new_cs & 0xfffc) | cpl,
1730
1734
                                   get_seg_base(e1, e2),
1731
1735
                                   get_seg_limit(e1, e2), e2);
1732
 
            EIP = new_eip;
 
1736
            env->eip = new_eip;
1733
1737
        } else
1734
1738
#endif
1735
1739
        {
1736
 
            sp = ESP;
 
1740
            sp = env->regs[R_ESP];
1737
1741
            sp_mask = get_sp_mask(env->segs[R_SS].flags);
1738
1742
            ssp = env->segs[R_SS].base;
1739
1743
            if (shift) {
1752
1756
            SET_ESP(sp, sp_mask);
1753
1757
            cpu_x86_load_seg_cache(env, R_CS, (new_cs & 0xfffc) | cpl,
1754
1758
                                   get_seg_base(e1, e2), limit, e2);
1755
 
            EIP = new_eip;
 
1759
            env->eip = new_eip;
1756
1760
        }
1757
1761
    } else {
1758
1762
        /* check gate type */
1809
1813
        if (!(e2 & DESC_C_MASK) && dpl < cpl) {
1810
1814
            /* to inner privilege */
1811
1815
            get_ss_esp_from_tss(env, &ss, &sp, dpl);
1812
 
            LOG_PCALL("new ss:esp=%04x:%08x param_count=%d ESP=" TARGET_FMT_lx
1813
 
                      "\n",
1814
 
                      ss, sp, param_count, ESP);
 
1816
            LOG_PCALL("new ss:esp=%04x:%08x param_count=%d env->regs[R_ESP]="
 
1817
                      TARGET_FMT_lx "\n", ss, sp, param_count,
 
1818
                      env->regs[R_ESP]);
1815
1819
            if ((ss & 0xfffc) == 0) {
1816
1820
                raise_exception_err(env, EXCP0A_TSS, ss & 0xfffc);
1817
1821
            }
1843
1847
            ssp = get_seg_base(ss_e1, ss_e2);
1844
1848
            if (shift) {
1845
1849
                PUSHL(ssp, sp, sp_mask, env->segs[R_SS].selector);
1846
 
                PUSHL(ssp, sp, sp_mask, ESP);
 
1850
                PUSHL(ssp, sp, sp_mask, env->regs[R_ESP]);
1847
1851
                for (i = param_count - 1; i >= 0; i--) {
1848
 
                    val = cpu_ldl_kernel(env, old_ssp + ((ESP + i * 4) &
1849
 
                                                         old_sp_mask));
 
1852
                    val = cpu_ldl_kernel(env, old_ssp +
 
1853
                                         ((env->regs[R_ESP] + i * 4) &
 
1854
                                          old_sp_mask));
1850
1855
                    PUSHL(ssp, sp, sp_mask, val);
1851
1856
                }
1852
1857
            } else {
1853
1858
                PUSHW(ssp, sp, sp_mask, env->segs[R_SS].selector);
1854
 
                PUSHW(ssp, sp, sp_mask, ESP);
 
1859
                PUSHW(ssp, sp, sp_mask, env->regs[R_ESP]);
1855
1860
                for (i = param_count - 1; i >= 0; i--) {
1856
 
                    val = cpu_lduw_kernel(env, old_ssp + ((ESP + i * 2) &
1857
 
                                                          old_sp_mask));
 
1861
                    val = cpu_lduw_kernel(env, old_ssp +
 
1862
                                          ((env->regs[R_ESP] + i * 2) &
 
1863
                                           old_sp_mask));
1858
1864
                    PUSHW(ssp, sp, sp_mask, val);
1859
1865
                }
1860
1866
            }
1861
1867
            new_stack = 1;
1862
1868
        } else {
1863
1869
            /* to same privilege */
1864
 
            sp = ESP;
 
1870
            sp = env->regs[R_ESP];
1865
1871
            sp_mask = get_sp_mask(env->segs[R_SS].flags);
1866
1872
            ssp = env->segs[R_SS].base;
1867
1873
            /* push_size = (4 << shift); */
1893
1899
                       e2);
1894
1900
        cpu_x86_set_cpl(env, dpl);
1895
1901
        SET_ESP(sp, sp_mask);
1896
 
        EIP = offset;
 
1902
        env->eip = offset;
1897
1903
    }
1898
1904
}
1899
1905
 
1905
1911
    int eflags_mask;
1906
1912
 
1907
1913
    sp_mask = 0xffff; /* XXXX: use SS segment size? */
1908
 
    sp = ESP;
 
1914
    sp = env->regs[R_ESP];
1909
1915
    ssp = env->segs[R_SS].base;
1910
1916
    if (shift == 1) {
1911
1917
        /* 32 bits */
1919
1925
        POPW(ssp, sp, sp_mask, new_cs);
1920
1926
        POPW(ssp, sp, sp_mask, new_eflags);
1921
1927
    }
1922
 
    ESP = (ESP & ~sp_mask) | (sp & sp_mask);
 
1928
    env->regs[R_ESP] = (env->regs[R_ESP] & ~sp_mask) | (sp & sp_mask);
1923
1929
    env->segs[R_CS].selector = new_cs;
1924
1930
    env->segs[R_CS].base = (new_cs << 4);
1925
1931
    env->eip = new_eip;
1978
1984
    {
1979
1985
        sp_mask = get_sp_mask(env->segs[R_SS].flags);
1980
1986
    }
1981
 
    sp = ESP;
 
1987
    sp = env->regs[R_ESP];
1982
1988
    ssp = env->segs[R_SS].base;
1983
1989
    new_eflags = 0; /* avoid warning */
1984
1990
#ifdef TARGET_X86_64
2014
2020
    }
2015
2021
    LOG_PCALL("lret new %04x:" TARGET_FMT_lx " s=%d addend=0x%x\n",
2016
2022
              new_cs, new_eip, shift, addend);
2017
 
    LOG_PCALL_STATE(env);
 
2023
    LOG_PCALL_STATE(CPU(x86_env_get_cpu(env)));
2018
2024
    if ((new_cs & 0xfffc) == 0) {
2019
2025
        raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc);
2020
2026
    }
2179
2185
    load_seg_vm(env, R_GS, new_gs & 0xffff);
2180
2186
 
2181
2187
    env->eip = new_eip & 0xffff;
2182
 
    ESP = new_esp;
 
2188
    env->regs[R_ESP] = new_esp;
2183
2189
}
2184
2190
 
2185
2191
void helper_iret_protected(CPUX86State *env, int shift, int next_eip)
2248
2254
                           DESC_G_MASK | DESC_B_MASK | DESC_P_MASK |
2249
2255
                           DESC_S_MASK |
2250
2256
                           DESC_W_MASK | DESC_A_MASK);
2251
 
    ESP = env->sysenter_esp;
2252
 
    EIP = env->sysenter_eip;
 
2257
    env->regs[R_ESP] = env->sysenter_esp;
 
2258
    env->eip = env->sysenter_eip;
2253
2259
}
2254
2260
 
2255
2261
void helper_sysexit(CPUX86State *env, int dflag)
2288
2294
                               DESC_S_MASK | (3 << DESC_DPL_SHIFT) |
2289
2295
                               DESC_W_MASK | DESC_A_MASK);
2290
2296
    }
2291
 
    ESP = ECX;
2292
 
    EIP = EDX;
 
2297
    env->regs[R_ESP] = env->regs[R_ECX];
 
2298
    env->eip = env->regs[R_EDX];
2293
2299
}
2294
2300
 
2295
2301
target_ulong helper_lsl(CPUX86State *env, target_ulong selector1)