VirtualBox

Changeset 60728 in vbox


Ignore:
Timestamp:
Apr 28, 2016 12:14:54 AM (8 years ago)
Author:
vboxsync
Message:

bs3-cpu-basic-2: Completed testcase for LIDT and LGDT.

Location:
trunk/src/VBox/ValidationKit/bootsectors
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-template.c

    r60724 r60728  
    4848/** Indicating that we've got operand size prefix and that it matters. */
    4949# define BS3CB2SIDTSGDT_F_OPSIZE    UINT8_C(0x01)
     50/** Worker requires 386 or later. */
     51# define BS3CB2SIDTSGDT_F_386PLUS   UINT8_C(0x02)
    5052#endif
    5153
     
    9294typedef struct BS3CB2SIDTSGDT
    9395{
     96    const char *pszDesc;
    9497    FPFNBS3FAR  fpfnWorker;
    9598    uint8_t     cbInstr;
     
    146149extern FNBS3FAR     bs3CpuBasic2_lidt_rexw_bx__sidt_es_di__lidt_es_si__ud2_c64;
    147150extern FNBS3FAR     bs3CpuBasic2_lidt_opsize_bx__sidt_es_di__lidt_es_si__ud2_c16;
     151extern FNBS3FAR     bs3CpuBasic2_lidt_opsize_bx__sidt32_es_di__lidt_es_si__ud2_c16;
    148152extern FNBS3FAR     bs3CpuBasic2_lidt_opsize_bx__sidt_es_di__lidt_es_si__ud2_c32;
    149153extern FNBS3FAR     bs3CpuBasic2_lidt_opsize_bx__sidt_es_di__lidt_es_si__ud2_c64;
     
    151155extern FNBS3FAR     bs3CpuBasic2_lidt_opsize_ss_bx__sidt_es_di__lidt_es_si__ud2_c32;
    152156extern FNBS3FAR     bs3CpuBasic2_lidt_opsize_rexw_bx__sidt_es_di__lidt_es_si__ud2_c64;
     157
     158extern FNBS3FAR     bs3CpuBasic2_lgdt_bx__sgdt_es_di__lgdt_es_si__ud2_c16;
     159extern FNBS3FAR     bs3CpuBasic2_lgdt_bx__sgdt_es_di__lgdt_es_si__ud2_c32;
     160extern FNBS3FAR     bs3CpuBasic2_lgdt_bx__sgdt_es_di__lgdt_es_si__ud2_c64;
     161extern FNBS3FAR     bs3CpuBasic2_lgdt_ss_bx__sgdt_es_di__lgdt_es_si__ud2_c16;
     162extern FNBS3FAR     bs3CpuBasic2_lgdt_ss_bx__sgdt_es_di__lgdt_es_si__ud2_c32;
     163extern FNBS3FAR     bs3CpuBasic2_lgdt_rexw_bx__sgdt_es_di__lgdt_es_si__ud2_c64;
     164extern FNBS3FAR     bs3CpuBasic2_lgdt_opsize_bx__sgdt_es_di__lgdt_es_si__ud2_c16;
     165extern FNBS3FAR     bs3CpuBasic2_lgdt_opsize_bx__sgdt_es_di__lgdt_es_si__ud2_c32;
     166extern FNBS3FAR     bs3CpuBasic2_lgdt_opsize_bx__sgdt_es_di__lgdt_es_si__ud2_c64;
     167extern FNBS3FAR     bs3CpuBasic2_lgdt_opsize_ss_bx__sgdt_es_di__lgdt_es_si__ud2_c16;
     168extern FNBS3FAR     bs3CpuBasic2_lgdt_opsize_ss_bx__sgdt_es_di__lgdt_es_si__ud2_c32;
     169extern FNBS3FAR     bs3CpuBasic2_lgdt_opsize_rexw_bx__sgdt_es_di__lgdt_es_si__ud2_c64;
    153170
    154171#endif
     
    170187static BS3CB2SIDTSGDT const g_aSidtWorkers[] =
    171188{
    172     { bs3CpuBasic2_sidt_bx_ud2_c16,             3, false,   BS3_MODE_CODE_16 | BS3_MODE_CODE_V86 },
    173     { bs3CpuBasic2_sidt_ss_bx_ud2_c16,          4, true,    BS3_MODE_CODE_16 | BS3_MODE_CODE_V86 },
    174     { bs3CpuBasic2_sidt_opsize_bx_ud2_c16,      4, false,   BS3_MODE_CODE_16 | BS3_MODE_CODE_V86 },
    175     { bs3CpuBasic2_sidt_opsize_ss_bx_ud2_c16,   5, true,    BS3_MODE_CODE_16 | BS3_MODE_CODE_V86 },
    176     { bs3CpuBasic2_sidt_bx_ud2_c32,             3, false,   BS3_MODE_CODE_32 },
    177     { bs3CpuBasic2_sidt_ss_bx_ud2_c32,          4, true,    BS3_MODE_CODE_32 },
    178     { bs3CpuBasic2_sidt_opsize_bx_ud2_c32,      4, false,   BS3_MODE_CODE_32 },
    179     { bs3CpuBasic2_sidt_opsize_ss_bx_ud2_c32,   5, true,    BS3_MODE_CODE_32 },
    180     { bs3CpuBasic2_sidt_bx_ud2_c64,             3, false,   BS3_MODE_CODE_64 },
    181     { bs3CpuBasic2_sidt_rexw_bx_ud2_c64,        4, false,   BS3_MODE_CODE_64 },
    182     { bs3CpuBasic2_sidt_opsize_bx_ud2_c64,      4, false,   BS3_MODE_CODE_64 },
    183     { bs3CpuBasic2_sidt_opsize_rexw_bx_ud2_c64, 5, false,   BS3_MODE_CODE_64 },
     189    { "", bs3CpuBasic2_sidt_bx_ud2_c16,             3, false,   BS3_MODE_CODE_16 | BS3_MODE_CODE_V86, 0 },
     190    { "", bs3CpuBasic2_sidt_ss_bx_ud2_c16,          4, true,    BS3_MODE_CODE_16 | BS3_MODE_CODE_V86, 0 },
     191    { "", bs3CpuBasic2_sidt_opsize_bx_ud2_c16,      4, false,   BS3_MODE_CODE_16 | BS3_MODE_CODE_V86, BS3CB2SIDTSGDT_F_386PLUS },
     192    { "", bs3CpuBasic2_sidt_opsize_ss_bx_ud2_c16,   5, true,    BS3_MODE_CODE_16 | BS3_MODE_CODE_V86, BS3CB2SIDTSGDT_F_386PLUS },
     193    { "", bs3CpuBasic2_sidt_bx_ud2_c32,             3, false,   BS3_MODE_CODE_32, 0 },
     194    { "", bs3CpuBasic2_sidt_ss_bx_ud2_c32,          4, true,    BS3_MODE_CODE_32, 0 },
     195    { "", bs3CpuBasic2_sidt_opsize_bx_ud2_c32,      4, false,   BS3_MODE_CODE_32, 0 },
     196    { "", bs3CpuBasic2_sidt_opsize_ss_bx_ud2_c32,   5, true,    BS3_MODE_CODE_32, 0 },
     197    { "", bs3CpuBasic2_sidt_bx_ud2_c64,             3, false,   BS3_MODE_CODE_64, 0 },
     198    { "", bs3CpuBasic2_sidt_rexw_bx_ud2_c64,        4, false,   BS3_MODE_CODE_64, 0 },
     199    { "", bs3CpuBasic2_sidt_opsize_bx_ud2_c64,      4, false,   BS3_MODE_CODE_64, 0 },
     200    { "", bs3CpuBasic2_sidt_opsize_rexw_bx_ud2_c64, 5, false,   BS3_MODE_CODE_64, 0 },
    184201};
    185202
     
    187204static BS3CB2SIDTSGDT const g_aSgdtWorkers[] =
    188205{
    189     { bs3CpuBasic2_sgdt_bx_ud2_c16,             3, false,   BS3_MODE_CODE_16 | BS3_MODE_CODE_V86 },
    190     { bs3CpuBasic2_sgdt_ss_bx_ud2_c16,          4, true,    BS3_MODE_CODE_16 | BS3_MODE_CODE_V86 },
    191     { bs3CpuBasic2_sgdt_opsize_bx_ud2_c16,      4, false,   BS3_MODE_CODE_16 | BS3_MODE_CODE_V86 },
    192     { bs3CpuBasic2_sgdt_opsize_ss_bx_ud2_c16,   5, true,    BS3_MODE_CODE_16 | BS3_MODE_CODE_V86 },
    193     { bs3CpuBasic2_sgdt_bx_ud2_c32,             3, false,   BS3_MODE_CODE_32 },
    194     { bs3CpuBasic2_sgdt_ss_bx_ud2_c32,          4, true,    BS3_MODE_CODE_32 },
    195     { bs3CpuBasic2_sgdt_opsize_bx_ud2_c32,      4, false,   BS3_MODE_CODE_32 },
    196     { bs3CpuBasic2_sgdt_opsize_ss_bx_ud2_c32,   5, true,    BS3_MODE_CODE_32 },
    197     { bs3CpuBasic2_sgdt_bx_ud2_c64,             3, false,   BS3_MODE_CODE_64 },
    198     { bs3CpuBasic2_sgdt_rexw_bx_ud2_c64,        4, false,   BS3_MODE_CODE_64 },
    199     { bs3CpuBasic2_sgdt_opsize_bx_ud2_c64,      4, false,   BS3_MODE_CODE_64 },
    200     { bs3CpuBasic2_sgdt_opsize_rexw_bx_ud2_c64, 5, false,   BS3_MODE_CODE_64 },
     206    { "", bs3CpuBasic2_sgdt_bx_ud2_c16,             3, false,   BS3_MODE_CODE_16 | BS3_MODE_CODE_V86, 0 },
     207    { "", bs3CpuBasic2_sgdt_ss_bx_ud2_c16,          4, true,    BS3_MODE_CODE_16 | BS3_MODE_CODE_V86, 0 },
     208    { "", bs3CpuBasic2_sgdt_opsize_bx_ud2_c16,      4, false,   BS3_MODE_CODE_16 | BS3_MODE_CODE_V86, BS3CB2SIDTSGDT_F_386PLUS },
     209    { "", bs3CpuBasic2_sgdt_opsize_ss_bx_ud2_c16,   5, true,    BS3_MODE_CODE_16 | BS3_MODE_CODE_V86, BS3CB2SIDTSGDT_F_386PLUS },
     210    { "", bs3CpuBasic2_sgdt_bx_ud2_c32,             3, false,   BS3_MODE_CODE_32, 0 },
     211    { "", bs3CpuBasic2_sgdt_ss_bx_ud2_c32,          4, true,    BS3_MODE_CODE_32, 0 },
     212    { "", bs3CpuBasic2_sgdt_opsize_bx_ud2_c32,      4, false,   BS3_MODE_CODE_32, 0 },
     213    { "", bs3CpuBasic2_sgdt_opsize_ss_bx_ud2_c32,   5, true,    BS3_MODE_CODE_32, 0 },
     214    { "", bs3CpuBasic2_sgdt_bx_ud2_c64,             3, false,   BS3_MODE_CODE_64, 0 },
     215    { "", bs3CpuBasic2_sgdt_rexw_bx_ud2_c64,        4, false,   BS3_MODE_CODE_64, 0 },
     216    { "", bs3CpuBasic2_sgdt_opsize_bx_ud2_c64,      4, false,   BS3_MODE_CODE_64, 0 },
     217    { "", bs3CpuBasic2_sgdt_opsize_rexw_bx_ud2_c64, 5, false,   BS3_MODE_CODE_64, 0 },
    201218};
    202219
     
    204221static BS3CB2SIDTSGDT const g_aLidtWorkers[] =
    205222{
    206     { bs3CpuBasic2_lidt_bx__sidt_es_di__lidt_es_si__ud2_c16,             11, false,   BS3_MODE_CODE_16 | BS3_MODE_CODE_V86, 0 },
    207     { bs3CpuBasic2_lidt_ss_bx__sidt_es_di__lidt_es_si__ud2_c16,          12, true,    BS3_MODE_CODE_16 | BS3_MODE_CODE_V86, 0 },
    208     { bs3CpuBasic2_lidt_opsize_bx__sidt_es_di__lidt_es_si__ud2_c16,      12, false,   BS3_MODE_CODE_16 | BS3_MODE_CODE_V86, 0 },
    209     { bs3CpuBasic2_lidt_opsize_ss_bx__sidt_es_di__lidt_es_si__ud2_c16,   13, true,    BS3_MODE_CODE_16 | BS3_MODE_CODE_V86, 0 },
    210     { bs3CpuBasic2_lidt_bx__sidt_es_di__lidt_es_si__ud2_c32,             11, false,   BS3_MODE_CODE_32, 0 },
    211     { bs3CpuBasic2_lidt_ss_bx__sidt_es_di__lidt_es_si__ud2_c32,          12, true,    BS3_MODE_CODE_32, 0 },
    212     { bs3CpuBasic2_lidt_opsize_bx__sidt_es_di__lidt_es_si__ud2_c32,      12, false,   BS3_MODE_CODE_32, BS3CB2SIDTSGDT_F_OPSIZE },
    213     { bs3CpuBasic2_lidt_opsize_ss_bx__sidt_es_di__lidt_es_si__ud2_c32,   13, true,    BS3_MODE_CODE_32, BS3CB2SIDTSGDT_F_OPSIZE },
    214     { bs3CpuBasic2_lidt_bx__sidt_es_di__lidt_es_si__ud2_c64,              9, false,   BS3_MODE_CODE_64, 0 },
    215     { bs3CpuBasic2_lidt_rexw_bx__sidt_es_di__lidt_es_si__ud2_c64,        10, false,   BS3_MODE_CODE_64, 0 },
    216     { bs3CpuBasic2_lidt_opsize_bx__sidt_es_di__lidt_es_si__ud2_c64,      10, false,   BS3_MODE_CODE_64, 0 },
    217     { bs3CpuBasic2_lidt_opsize_rexw_bx__sidt_es_di__lidt_es_si__ud2_c64, 11, false,   BS3_MODE_CODE_64, 0 },
     223    { "lidt [bx]",              bs3CpuBasic2_lidt_bx__sidt_es_di__lidt_es_si__ud2_c16,             11, false,   BS3_MODE_CODE_16 | BS3_MODE_CODE_V86, 0 },
     224    { "lidt [ss:bx]",           bs3CpuBasic2_lidt_ss_bx__sidt_es_di__lidt_es_si__ud2_c16,          12, true,    BS3_MODE_CODE_16 | BS3_MODE_CODE_V86, 0 },
     225    { "o32 lidt [bx]",          bs3CpuBasic2_lidt_opsize_bx__sidt_es_di__lidt_es_si__ud2_c16,      12, false,   BS3_MODE_CODE_16 | BS3_MODE_CODE_V86, BS3CB2SIDTSGDT_F_OPSIZE | BS3CB2SIDTSGDT_F_386PLUS },
     226    { "o32 lidt [bx]; sidt32",  bs3CpuBasic2_lidt_opsize_bx__sidt32_es_di__lidt_es_si__ud2_c16,    27, false,   BS3_MODE_CODE_16 | BS3_MODE_CODE_V86, BS3CB2SIDTSGDT_F_OPSIZE | BS3CB2SIDTSGDT_F_386PLUS },
     227    { "o32 lidt [ss:bx]",       bs3CpuBasic2_lidt_opsize_ss_bx__sidt_es_di__lidt_es_si__ud2_c16,   13, true,    BS3_MODE_CODE_16 | BS3_MODE_CODE_V86, BS3CB2SIDTSGDT_F_OPSIZE | BS3CB2SIDTSGDT_F_386PLUS },
     228    { "lidt [ebx]",             bs3CpuBasic2_lidt_bx__sidt_es_di__lidt_es_si__ud2_c32,             11, false,   BS3_MODE_CODE_32, 0 },
     229    { "lidt [ss:ebx]",          bs3CpuBasic2_lidt_ss_bx__sidt_es_di__lidt_es_si__ud2_c32,          12, true,    BS3_MODE_CODE_32, 0 },
     230    { "o16 lidt [ebx]",         bs3CpuBasic2_lidt_opsize_bx__sidt_es_di__lidt_es_si__ud2_c32,      12, false,   BS3_MODE_CODE_32, BS3CB2SIDTSGDT_F_OPSIZE },
     231    { "o16 lidt [ss:ebx]",      bs3CpuBasic2_lidt_opsize_ss_bx__sidt_es_di__lidt_es_si__ud2_c32,   13, true,    BS3_MODE_CODE_32, BS3CB2SIDTSGDT_F_OPSIZE },
     232    { "lidt [rbx]",             bs3CpuBasic2_lidt_bx__sidt_es_di__lidt_es_si__ud2_c64,              9, false,   BS3_MODE_CODE_64, 0 },
     233    { "o64 lidt [rbx]",         bs3CpuBasic2_lidt_rexw_bx__sidt_es_di__lidt_es_si__ud2_c64,        10, false,   BS3_MODE_CODE_64, 0 },
     234    { "o32 lidt [rbx]",         bs3CpuBasic2_lidt_opsize_bx__sidt_es_di__lidt_es_si__ud2_c64,      10, false,   BS3_MODE_CODE_64, 0 },
     235    { "o32 o64 lidt [rbx]",     bs3CpuBasic2_lidt_opsize_rexw_bx__sidt_es_di__lidt_es_si__ud2_c64, 11, false,   BS3_MODE_CODE_64, 0 },
     236};
     237
     238/** LGDT test workers. */
     239static BS3CB2SIDTSGDT const g_aLgdtWorkers[] =
     240{
     241    { "lgdt [bx]",              bs3CpuBasic2_lgdt_bx__sgdt_es_di__lgdt_es_si__ud2_c16,             11, false,   BS3_MODE_CODE_16 | BS3_MODE_CODE_V86, 0 },
     242    { "lgdt [ss:bx]",           bs3CpuBasic2_lgdt_ss_bx__sgdt_es_di__lgdt_es_si__ud2_c16,          12, true,    BS3_MODE_CODE_16 | BS3_MODE_CODE_V86, 0 },
     243    { "o32 lgdt [bx]",          bs3CpuBasic2_lgdt_opsize_bx__sgdt_es_di__lgdt_es_si__ud2_c16,      12, false,   BS3_MODE_CODE_16 | BS3_MODE_CODE_V86, BS3CB2SIDTSGDT_F_OPSIZE | BS3CB2SIDTSGDT_F_386PLUS },
     244    { "o32 lgdt [ss:bx]",       bs3CpuBasic2_lgdt_opsize_ss_bx__sgdt_es_di__lgdt_es_si__ud2_c16,   13, true,    BS3_MODE_CODE_16 | BS3_MODE_CODE_V86, BS3CB2SIDTSGDT_F_OPSIZE | BS3CB2SIDTSGDT_F_386PLUS },
     245    { "lgdt [ebx]",             bs3CpuBasic2_lgdt_bx__sgdt_es_di__lgdt_es_si__ud2_c32,             11, false,   BS3_MODE_CODE_32, 0 },
     246    { "lgdt [ss:ebx]",          bs3CpuBasic2_lgdt_ss_bx__sgdt_es_di__lgdt_es_si__ud2_c32,          12, true,    BS3_MODE_CODE_32, 0 },
     247    { "o16 lgdt [ebx]",         bs3CpuBasic2_lgdt_opsize_bx__sgdt_es_di__lgdt_es_si__ud2_c32,      12, false,   BS3_MODE_CODE_32, BS3CB2SIDTSGDT_F_OPSIZE },
     248    { "o16 lgdt [ss:ebx]",      bs3CpuBasic2_lgdt_opsize_ss_bx__sgdt_es_di__lgdt_es_si__ud2_c32,   13, true,    BS3_MODE_CODE_32, BS3CB2SIDTSGDT_F_OPSIZE },
     249    { "lgdt [rbx]",             bs3CpuBasic2_lgdt_bx__sgdt_es_di__lgdt_es_si__ud2_c64,              9, false,   BS3_MODE_CODE_64, 0 },
     250    { "o64 lgdt [rbx]",         bs3CpuBasic2_lgdt_rexw_bx__sgdt_es_di__lgdt_es_si__ud2_c64,        10, false,   BS3_MODE_CODE_64, 0 },
     251    { "o32 lgdt [rbx]",         bs3CpuBasic2_lgdt_opsize_bx__sgdt_es_di__lgdt_es_si__ud2_c64,      10, false,   BS3_MODE_CODE_64, 0 },
     252    { "o32 o64 lgdt [rbx]",     bs3CpuBasic2_lgdt_opsize_rexw_bx__sgdt_es_di__lgdt_es_si__ud2_c64, 11, false,   BS3_MODE_CODE_64, 0 },
    218253};
    219254
     
    20262061                                               uint8_t const *pbRestore, size_t cbRestore, uint8_t const *pbExpected)
    20272062{
     2063    static const struct
     2064    {
     2065        bool        fGP;
     2066        uint16_t    cbLimit;
     2067        uint64_t    u64Base;
     2068    } s_aValues64[] =
     2069    {
     2070        { false, 0x0000, UINT64_C(0x0000000000000000) },
     2071        { false, 0x0001, UINT64_C(0x0000000000000001) },
     2072        { false, 0x0002, UINT64_C(0x0000000000000010) },
     2073        { false, 0x0003, UINT64_C(0x0000000000000123) },
     2074        { false, 0x0004, UINT64_C(0x0000000000001234) },
     2075        { false, 0x0005, UINT64_C(0x0000000000012345) },
     2076        { false, 0x0006, UINT64_C(0x0000000000123456) },
     2077        { false, 0x0007, UINT64_C(0x0000000001234567) },
     2078        { false, 0x0008, UINT64_C(0x0000000012345678) },
     2079        { false, 0x0009, UINT64_C(0x0000000123456789) },
     2080        { false, 0x000a, UINT64_C(0x000000123456789a) },
     2081        { false, 0x000b, UINT64_C(0x00000123456789ab) },
     2082        { false, 0x000c, UINT64_C(0x0000123456789abc) },
     2083        { false, 0x001c, UINT64_C(0x00007ffffeefefef) },
     2084        { false, 0xffff, UINT64_C(0x00007fffffffffff) },
     2085        {  true, 0xf3f1, UINT64_C(0x0000800000000000) },
     2086        {  true, 0x0000, UINT64_C(0x0000800000000000) },
     2087        {  true, 0x0000, UINT64_C(0x0000800000000333) },
     2088        {  true, 0x00f0, UINT64_C(0x0001000000000000) },
     2089        {  true, 0x0ff0, UINT64_C(0x0012000000000000) },
     2090        {  true, 0x0eff, UINT64_C(0x0123000000000000) },
     2091        {  true, 0xe0fe, UINT64_C(0x1234000000000000) },
     2092        {  true, 0x00ad, UINT64_C(0xffff300000000000) },
     2093        {  true, 0x0000, UINT64_C(0xffff7fffffffffff) },
     2094        {  true, 0x00f0, UINT64_C(0xffff7fffffffffff) },
     2095        { false, 0x5678, UINT64_C(0xffff800000000000) },
     2096        { false, 0x2969, UINT64_C(0xffffffffffeefefe) },
     2097        { false, 0x1221, UINT64_C(0xffffffffffffffff) },
     2098        { false, 0x1221, UINT64_C(0xffffffffffffffff) },
     2099    };
     2100    static const struct
     2101    {
     2102        uint16_t    cbLimit;
     2103        uint32_t    u32Base;
     2104    } s_aValues32[] =
     2105    {
     2106        { 0xdfdf, UINT32_C(0xefefefef) },
     2107        { 0x0000, UINT32_C(0x00000000) },
     2108        { 0x0001, UINT32_C(0x00000001) },
     2109        { 0x0002, UINT32_C(0x00000012) },
     2110        { 0x0003, UINT32_C(0x00000123) },
     2111        { 0x0004, UINT32_C(0x00001234) },
     2112        { 0x0005, UINT32_C(0x00012345) },
     2113        { 0x0006, UINT32_C(0x00123456) },
     2114        { 0x0007, UINT32_C(0x01234567) },
     2115        { 0x0008, UINT32_C(0x12345678) },
     2116        { 0x0009, UINT32_C(0x80204060) },
     2117        { 0x000a, UINT32_C(0xddeeffaa) },
     2118        { 0x000b, UINT32_C(0xfdecdbca) },
     2119        { 0x000c, UINT32_C(0x6098456b) },
     2120        { 0x000d, UINT32_C(0x98506099) },
     2121        { 0x000e, UINT32_C(0x206950bc) },
     2122        { 0x000f, UINT32_C(0x9740395d) },
     2123        { 0x0334, UINT32_C(0x64a9455e) },
     2124        { 0xb423, UINT32_C(0xd20b6eff) },
     2125        { 0x4955, UINT32_C(0x85296d46) },
     2126        { 0xffff, UINT32_C(0x07000039) },
     2127        { 0xefe1, UINT32_C(0x0007fe00) },
     2128    };
     2129
    20282130    BS3TRAPFRAME        TrapCtx;
    20292131    BS3REGCTX           Ctx;
     
    20372139    uint8_t BS3_FAR    *pbBufRestore;           /* Correctly aligned pointer into abBufRestore. */
    20382140    uint8_t const       cbIdtr        = BS3_MODE_IS_64BIT_CODE(bTestMode) ? 2+8 : 2+4;
    2039     uint8_t const       cbBaseLoaded  = BS3_MODE_IS_16BIT_CODE(bTestMode) || (pWorker->fFlags & BS3CB2SIDTSGDT_F_OPSIZE)
    2040                                       ? 3 : cbIdtr - 2;
     2141    uint8_t const       cbBaseLoaded  = BS3_MODE_IS_64BIT_CODE(bTestMode) ? 8
     2142                                      : BS3_MODE_IS_16BIT_CODE(bTestMode) == !(pWorker->fFlags & BS3CB2SIDTSGDT_F_OPSIZE)
     2143                                      ? 3 : 4;
    20412144    bool const          f286          = (g_uBs3CpuDetected & BS3CPU_TYPE_MASK) == BS3CPU_80286;
    20422145    uint8_t const       bTop16BitBase = f286 ? 0xff : 0x00;
    20432146    uint8_t             bFiller1;               /* For filling abBufLoad.  */
    20442147    uint8_t             bFiller2;               /* For filling abBufSave and expectations. */
    2045 //    int                 off;
    2046 //    int                 off2;
    2047 //    unsigned            cb;
    2048 //    uint8_t BS3_FAR    *pbTest;
     2148    int                 off;
     2149    uint8_t BS3_FAR    *pbTest;
    20492150    unsigned            i;
    20502151
     
    20692170    if (BS3_MODE_IS_16BIT_SYS(bTestMode))
    20702171        g_uBs3TrapEipHint = Ctx.rip.u32;
     2172    Ctx.rflags.u16 &= ~X86_EFL_IF;
    20712173    Bs3RegCtxSetGrpSegFromCurPtr(&Ctx, &Ctx.rbx, pWorker->fSs ? &Ctx.ss : &Ctx.ds, abBufLoad);
    20722174
     
    20932195     */
    20942196    Bs3MemZero(abBufLoad, sizeof(abBufLoad));
    2095     Bs3MemCpy(abBufLoad, pbBufRestore, cbRestore);
     2197    Bs3MemCpy(abBufLoad, pbBufRestore, cbIdtr);
    20962198    Bs3MemZero(abBufSave, sizeof(abBufSave));
    20972199    Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
     
    21232225    /* Again with a buffer filled with a byte not occuring in the previous result. */
    21242226    Bs3MemSet(abBufLoad, bFiller1, sizeof(abBufLoad));
    2125     Bs3MemCpy(abBufLoad, pbBufRestore, cbRestore);
     2227    Bs3MemCpy(abBufLoad, pbBufRestore, cbIdtr);
    21262228    Bs3MemSet(abBufSave, bFiller2, sizeof(abBufSave));
    21272229    Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
     
    21422244    if (BS3_MODE_IS_64BIT_CODE(bTestMode))
    21432245    {
    2144         static const struct
    2145         {
    2146             bool        fGP;
    2147             uint16_t    cbLimit;
    2148             uint64_t    u64Base;
    2149         } s_aValues[] =
    2150         {
    2151             { false, 0x0000, UINT64_C(0x0000000000000000) },
    2152             { false, 0x0001, UINT64_C(0x0000000000000001) },
    2153             { false, 0x0002, UINT64_C(0x0000000000000010) },
    2154             { false, 0x0003, UINT64_C(0x0000000000000123) },
    2155             { false, 0x0004, UINT64_C(0x0000000000001234) },
    2156             { false, 0x0005, UINT64_C(0x0000000000012345) },
    2157             { false, 0x0006, UINT64_C(0x0000000000123456) },
    2158             { false, 0x0007, UINT64_C(0x0000000001234567) },
    2159             { false, 0x0008, UINT64_C(0x0000000012345678) },
    2160             { false, 0x0009, UINT64_C(0x0000000123456789) },
    2161             { false, 0x000a, UINT64_C(0x000000123456789a) },
    2162             { false, 0x000b, UINT64_C(0x00000123456789ab) },
    2163             { false, 0x000c, UINT64_C(0x0000123456789abc) },
    2164             { false, 0x001c, UINT64_C(0x00007ffffeefefef) },
    2165             { false, 0xffff, UINT64_C(0x00007fffffffffff) },
    2166             {  true, 0xf3f1, UINT64_C(0x0000800000000000) },
    2167             {  true, 0x0000, UINT64_C(0x0000800000000000) },
    2168             {  true, 0x0000, UINT64_C(0x0000800000000333) },
    2169             {  true, 0x00f0, UINT64_C(0x0001000000000000) },
    2170             {  true, 0x0ff0, UINT64_C(0x0012000000000000) },
    2171             {  true, 0x0eff, UINT64_C(0x0123000000000000) },
    2172             {  true, 0xe0fe, UINT64_C(0x1234000000000000) },
    2173             {  true, 0x00ad, UINT64_C(0xffff300000000000) },
    2174             {  true, 0x0000, UINT64_C(0xffff7fffffffffff) },
    2175             {  true, 0x00f0, UINT64_C(0xffff7fffffffffff) },
    2176             { false, 0x5678, UINT64_C(0xffff800000000000) },
    2177             { false, 0x2969, UINT64_C(0xffffffffffeefefe) },
    2178             { false, 0x1221, UINT64_C(0xffffffffffffffff) },
    2179             { false, 0x1221, UINT64_C(0xffffffffffffffff) },
    2180         };
    2181         for (i = 0; i < RT_ELEMENTS(s_aValues); i++)
    2182         {
    2183             Bs3MemSet(abBufSave, bFiller1, sizeof(abBufSave));
    2184             Bs3MemCpy(&abBufLoad[0], &s_aValues[i].cbLimit, 2);
    2185             Bs3MemCpy(&abBufLoad[2], &s_aValues[i].u64Base, 8);
     2246        for (i = 0; i < RT_ELEMENTS(s_aValues64); i++)
     2247        {
     2248            Bs3MemSet(abBufLoad, bFiller1, sizeof(abBufLoad));
     2249            Bs3MemCpy(&abBufLoad[0], &s_aValues64[i].cbLimit, 2);
     2250            Bs3MemCpy(&abBufLoad[2], &s_aValues64[i].u64Base, 8);
    21862251            Bs3MemSet(abBufSave, bFiller2, sizeof(abBufSave));
    21872252            Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
    2188             if (bRing != 0 || s_aValues[i].fGP)
     2253            if (bRing != 0 || s_aValues64[i].fGP)
    21892254                bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
    21902255            else
    21912256            {
    21922257                bs3CpuBasic2_CompareUdCtx(&TrapCtx, &CtxUdExpected);
    2193                 if (   Bs3MemCmp(&pbBufSave[0], &s_aValues[i].cbLimit, 2) != 0
    2194                     || Bs3MemCmp(&pbBufSave[2], &s_aValues[i].u64Base, 8) != 0
     2258                if (   Bs3MemCmp(&pbBufSave[0], &s_aValues64[i].cbLimit, 2) != 0
     2259                    || Bs3MemCmp(&pbBufSave[2], &s_aValues64[i].u64Base, 8) != 0
    21952260                    || !ASMMemIsAllU8(&pbBufSave[10], cbIdtr, bFiller2))
    21962261                    Bs3TestFailedF("Mismatch (#2): expected %04RX16:%016RX64, fillers %#x %#x, got %.*Rhxs\n",
    2197                                    s_aValues[i].cbLimit, s_aValues[i].u64Base, bFiller1, bFiller2, cbIdtr*2, pbBufSave);
     2262                                   s_aValues64[i].cbLimit, s_aValues64[i].u64Base, bFiller1, bFiller2, cbIdtr*2, pbBufSave);
    21982263            }
    21992264            g_usBs3TestStep++;
     
    22022267    else
    22032268    {
    2204         static const struct
    2205         {
    2206             uint16_t    cbLimit;
    2207             uint32_t    u32Base;
    2208         } s_aValues[] =
    2209         {
    2210             { 0x0000, UINT32_C(0x00000000) },
    2211             { 0x0001, UINT32_C(0x00000001) },
    2212             { 0x0002, UINT32_C(0x00000012) },
    2213             { 0x0003, UINT32_C(0x00000123) },
    2214             { 0x0004, UINT32_C(0x00001234) },
    2215             { 0x0005, UINT32_C(0x00012345) },
    2216             { 0x0006, UINT32_C(0x00123456) },
    2217             { 0x0007, UINT32_C(0x01234567) },
    2218             { 0x0008, UINT32_C(0x12345678) },
    2219             { 0x0009, UINT32_C(0x80204060) },
    2220             { 0x000a, UINT32_C(0xddeeffaa) },
    2221             { 0x000b, UINT32_C(0xfdecdbca) },
    2222             { 0x000c, UINT32_C(0x6098456b) },
    2223             { 0x000d, UINT32_C(0x98506099) },
    2224             { 0x000e, UINT32_C(0x206950bc) },
    2225             { 0x000f, UINT32_C(0x9740395d) },
    2226             { 0x0334, UINT32_C(0x64a9455e) },
    2227             { 0xb423, UINT32_C(0xd20b6eff) },
    2228             { 0x4955, UINT32_C(0x85296d46) },
    2229             { 0xffff, UINT32_C(0x07000039) },
    2230             { 0xefe1, UINT32_C(0x0007fe00) },
    2231         };
    2232         for (i = 0; i < RT_ELEMENTS(s_aValues); i++)
    2233         {
    2234             Bs3MemSet(abBufSave, bFiller1, sizeof(abBufSave));
    2235             Bs3MemCpy(&abBufLoad[0], &s_aValues[i].cbLimit, 2);
    2236             Bs3MemCpy(&abBufLoad[2], &s_aValues[i].u32Base, cbBaseLoaded);
     2269        for (i = 0; i < RT_ELEMENTS(s_aValues32); i++)
     2270        {
     2271            Bs3MemSet(abBufLoad, bFiller1, sizeof(abBufLoad));
     2272            Bs3MemCpy(&abBufLoad[0], &s_aValues32[i].cbLimit, 2);
     2273            Bs3MemCpy(&abBufLoad[2], &s_aValues32[i].u32Base, cbBaseLoaded);
    22372274            Bs3MemSet(abBufSave, bFiller2, sizeof(abBufSave));
    22382275            Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
     
    22422279            {
    22432280                bs3CpuBasic2_CompareUdCtx(&TrapCtx, &CtxUdExpected);
    2244                 if (   Bs3MemCmp(&pbBufSave[0], &s_aValues[i].cbLimit, 2) != 0
    2245                     || Bs3MemCmp(&pbBufSave[2], &s_aValues[i].u32Base, cbBaseLoaded) != 0
     2281                if (   Bs3MemCmp(&pbBufSave[0], &s_aValues32[i].cbLimit, 2) != 0
     2282                    || Bs3MemCmp(&pbBufSave[2], &s_aValues32[i].u32Base, cbBaseLoaded) != 0
    22462283                    || (   cbBaseLoaded != 4
    22472284                        && pbBufSave[2+3] != bTop16BitBase)
    22482285                    || !ASMMemIsAllU8(&pbBufSave[8], cbIdtr, bFiller2))
    2249                     Bs3TestFailedF("Mismatch (#3): loaded %04RX16:%08RX32, fillers %#x %#x%s%s (cbIns=%d), got %.*Rhxs\n",
    2250                                    s_aValues[i].cbLimit, s_aValues[i].u32Base, bFiller1, bFiller2, f286 ? ", 286" : "",
    2251                                    pWorker->fFlags ? ", opsize" : "", pWorker->cbInstr, cbIdtr*2, pbBufSave);
     2286                    Bs3TestFailedF("Mismatch (#3): loaded %04RX16:%08RX32, fillers %#x %#x%s, %s, got %.*Rhxs\n",
     2287                                   s_aValues32[i].cbLimit, s_aValues32[i].u32Base, bFiller1, bFiller2, f286 ? ", 286" : "",
     2288                                   pWorker->pszDesc, cbIdtr*2, pbBufSave);
    22522289            }
    22532290            g_usBs3TestStep++;
    22542291        }
    2255 
    2256     }
    2257 
    2258 
    2259 
    2260 #if 0
     2292    }
    22612293
    22622294    /*
     
    22652297    for (off = 0; off < 8; off++)
    22662298    {
    2267         pbBuf = &abBuf[off];
    2268         Bs3RegCtxSetGrpSegFromCurPtr(&Ctx, &Ctx.rbx, pWorker->fSs ? &Ctx.ss : &Ctx.ds, &abBuf[off]);
     2299        Bs3RegCtxSetGrpSegFromCurPtr(&Ctx, &Ctx.rbx, pWorker->fSs ? &Ctx.ss : &Ctx.ds, &abBufLoad[off]);
    22692300        CtxUdExpected.rbx.u = Ctx.rbx.u;
    22702301
    2271         /* First with zero buffer. */
    2272         Bs3MemZero(abBuf, sizeof(abBuf));
     2302        Bs3MemSet(abBufLoad, bFiller1, sizeof(abBufLoad));
     2303        Bs3MemCpy(&abBufLoad[off], pbBufRestore, cbIdtr);
     2304        Bs3MemSet(abBufSave, bFiller2, sizeof(abBufSave));
    22732305        Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
    2274         bs3CpuBasic2_CompareUdCtx(&TrapCtx, &CtxUdExpected);
    2275         if (off > 0 && !ASMMemIsZero(abBuf, off))
    2276             Bs3TestFailedF("Unexpected buffer bytes set before (#3): cbIdtr=%u off=%u abBuf=%.*Rhxs\n",
    2277                            cbIdtr, off, off + cbBuf, abBuf);
    2278         if (!ASMMemIsZero(&abBuf[off + cbIdtr], sizeof(abBuf) - cbIdtr - off))
    2279             Bs3TestFailedF("Unexpected buffer bytes set after (#3): cbIdtr=%u off=%u abBuf=%.*Rhxs\n",
    2280                            cbIdtr, off, off + cbBuf, abBuf);
    2281         if (f286 && abBuf[off + cbIdtr - 1] != 0xff)
    2282             Bs3TestFailedF("286: Top base byte isn't 0xff (#3): %#x\n", abBuf[off + cbIdtr - 1]);
    2283         if (Bs3MemCmp(&abBuf[off], pbExpected, cbIdtr) != 0)
    2284             Bs3TestFailedF("Mismatch (#3): expected %.*Rhxs, got %.*Rhxs\n", cbIdtr, pbExpected, cbIdtr, &abBuf[off]);
     2306        if (bRing != 0)
     2307            bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
     2308        else
     2309        {
     2310            bs3CpuBasic2_CompareUdCtx(&TrapCtx, &CtxUdExpected);
     2311            if (Bs3MemCmp(pbBufSave, abExpectedFilled, cbIdtr * 2) != 0)
     2312                Bs3TestFailedF("Mismatch (#4): expected %.*Rhxs, got %.*Rhxs\n", cbIdtr*2, abExpectedFilled, cbIdtr*2, pbBufSave);
     2313        }
    22852314        g_usBs3TestStep++;
    2286 
    2287         /* Again with a buffer filled with a byte not occuring in the previous result. */
    2288         Bs3MemSet(abBuf, bFiller, sizeof(abBuf));
    2289         Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
    2290         bs3CpuBasic2_CompareUdCtx(&TrapCtx, &CtxUdExpected);
    2291         if (off > 0 && !ASMMemIsAllU8(abBuf, off, bFiller))
    2292             Bs3TestFailedF("Unexpected buffer bytes set before (#4): cbIdtr=%u off=%u bFiller=%#x abBuf=%.*Rhxs\n",
    2293                            cbIdtr, off, bFiller, off + cbBuf, abBuf);
    2294         if (!ASMMemIsAllU8(&abBuf[off + cbIdtr], sizeof(abBuf) - cbIdtr - off, bFiller))
    2295             Bs3TestFailedF("Unexpected buffer bytes set after (#4): cbIdtr=%u off=%u bFiller=%#x abBuf=%.*Rhxs\n",
    2296                            cbIdtr, off, bFiller, off + cbBuf, abBuf);
    2297         if (Bs3MemChr(&abBuf[off], bFiller, cbIdtr) != NULL)
    2298             Bs3TestFailedF("Not all bytes touched (#4): cbIdtr=%u off=%u bFiller=%#x abBuf=%.*Rhxs\n",
    2299                            cbIdtr, off, bFiller, off + cbBuf, abBuf);
    2300         if (f286 && abBuf[off + cbIdtr - 1] != 0xff)
    2301             Bs3TestFailedF("286: Top base byte isn't 0xff (#4): %#x\n", abBuf[off + cbIdtr - 1]);
    2302         if (Bs3MemCmp(&abBuf[off], pbExpected, cbIdtr) != 0)
    2303             Bs3TestFailedF("Mismatch (#4): expected %.*Rhxs, got %.*Rhxs\n", cbIdtr, pbExpected, cbIdtr, &abBuf[off]);
    2304         g_usBs3TestStep++;
    2305     }
    2306     pbBuf = abBuf;
    2307     Bs3RegCtxSetGrpSegFromCurPtr(&Ctx, &Ctx.rbx, pWorker->fSs ? &Ctx.ss : &Ctx.ds, abBuf);
     2315    }
     2316    Bs3RegCtxSetGrpSegFromCurPtr(&Ctx, &Ctx.rbx, pWorker->fSs ? &Ctx.ss : &Ctx.ds, abBufLoad);
    23082317    CtxUdExpected.rbx.u = Ctx.rbx.u;
    23092318
     
    23162325    {
    23172326        uint16_t cbLimit;
    2318         uint32_t uFlatBuf = Bs3SelPtrToFlat(abBuf);
     2327        uint32_t uFlatBuf = Bs3SelPtrToFlat(abBufLoad);
    23192328        Bs3GdteTestPage00 = Bs3Gdte_DATA16;
    23202329        Bs3GdteTestPage00.Gen.u2Dpl       = bRing;
     
    23352344            {
    23362345                Bs3GdteTestPage00.Gen.u16LimitLow = cbLimit;
    2337                 Bs3MemSet(abBuf, bFiller, sizeof(abBuf));
     2346
     2347                Bs3MemSet(abBufLoad, bFiller1, sizeof(abBufLoad));
     2348                Bs3MemCpy(&abBufLoad[off], pbBufRestore, cbIdtr);
     2349                Bs3MemSet(abBufSave, bFiller2, sizeof(abBufSave));
    23382350                Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
    2339                 if (off + cbIdtr <= cbLimit + 1)
     2351                if (bRing != 0)
     2352                    bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
     2353                else if (off + cbIdtr <= cbLimit + 1)
    23402354                {
    23412355                    bs3CpuBasic2_CompareUdCtx(&TrapCtx, &CtxUdExpected);
    2342                     if (Bs3MemChr(&abBuf[off], bFiller, cbIdtr) != NULL)
    2343                         Bs3TestFailedF("Not all bytes touched (#5): cbIdtr=%u off=%u cbLimit=%u bFiller=%#x abBuf=%.*Rhxs\n",
    2344                                        cbIdtr, off, cbLimit, bFiller, off + cbBuf, abBuf);
    2345                     if (Bs3MemCmp(&abBuf[off], pbExpected, cbIdtr) != 0)
    2346                         Bs3TestFailedF("Mismatch (#5): expected %.*Rhxs, got %.*Rhxs\n", cbIdtr, pbExpected, cbIdtr, &abBuf[off]);
    2347                     if (f286 && abBuf[off + cbIdtr - 1] != 0xff)
    2348                         Bs3TestFailedF("286: Top base byte isn't 0xff (#5): %#x\n", abBuf[off + cbIdtr - 1]);
     2356                    if (Bs3MemCmp(pbBufSave, abExpectedFilled, cbIdtr * 2) != 0)
     2357                        Bs3TestFailedF("Mismatch (#5): expected %.*Rhxs, got %.*Rhxs\n",
     2358                                       cbIdtr*2, abExpectedFilled, cbIdtr*2, pbBufSave);
    23492359                }
     2360                else if (pWorker->fSs)
     2361                    bs3CpuBasic2_CompareSsCtx(&TrapCtx, &Ctx, 0, false /*f486ResumeFlagHint*/);
    23502362                else
    2351                 {
    2352                     if (pWorker->fSs)
    2353                         bs3CpuBasic2_CompareSsCtx(&TrapCtx, &Ctx, 0, false /*f486ResumeFlagHint*/);
    2354                     else
    2355                         bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
    2356                     if (off + 2 <= cbLimit + 1)
    2357                     {
    2358                         if (Bs3MemChr(&abBuf[off], bFiller, 2) != NULL)
    2359                             Bs3TestFailedF("Limit bytes not touched (#6): cbIdtr=%u off=%u cbLimit=%u bFiller=%#x abBuf=%.*Rhxs\n",
    2360                                            cbIdtr, off, cbLimit, bFiller, off + cbBuf, abBuf);
    2361                         if (Bs3MemCmp(&abBuf[off], pbExpected, 2) != 0)
    2362                             Bs3TestFailedF("Mismatch (#6): expected %.2Rhxs, got %.2Rhxs\n", pbExpected, &abBuf[off]);
    2363                         if (!ASMMemIsAllU8(&abBuf[off + 2], cbIdtr - 2, bFiller))
    2364                             Bs3TestFailedF("Base bytes touched on #GP (#6): cbIdtr=%u off=%u cbLimit=%u bFiller=%#x abBuf=%.*Rhxs\n",
    2365                                            cbIdtr, off, cbLimit, bFiller, off + cbBuf, abBuf);
    2366                     }
    2367                     else if (!ASMMemIsAllU8(abBuf, sizeof(abBuf), bFiller))
    2368                         Bs3TestFailedF("Bytes touched on #GP: cbIdtr=%u off=%u cbLimit=%u bFiller=%#x abBuf=%.*Rhxs\n",
    2369                                        cbIdtr, off, cbLimit, bFiller, off + cbBuf, abBuf);
    2370                 }
    2371 
    2372                 if (off > 0 && !ASMMemIsAllU8(abBuf, off, bFiller))
    2373                     Bs3TestFailedF("Leading bytes touched (#7): cbIdtr=%u off=%u cbLimit=%u bFiller=%#x abBuf=%.*Rhxs\n",
    2374                                    cbIdtr, off, cbLimit, bFiller, off + cbBuf, abBuf);
    2375                 if (!ASMMemIsAllU8(&abBuf[off + cbIdtr], sizeof(abBuf) - off - cbIdtr, bFiller))
    2376                     Bs3TestFailedF("Trailing bytes touched (#7): cbIdtr=%u off=%u cbLimit=%u bFiller=%#x abBuf=%.*Rhxs\n",
    2377                                    cbIdtr, off, cbLimit, bFiller, off + cbBuf, abBuf);
    2378 
     2363                    bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
    23792364                g_usBs3TestStep++;
     2365
     2366                /* Again with zero limit and messed up base (should trigger tripple fault if partially loaded). */
     2367                abBufLoad[off] = abBufLoad[off + 1] = 0;
     2368                abBufLoad[off + 2] |= 1;
     2369                abBufLoad[off + cbIdtr - 2] ^= 0x5a;
     2370                abBufLoad[off + cbIdtr - 1] ^= 0xa5;
     2371                Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
     2372                if (bRing != 0)
     2373                    bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
     2374                else if (off + cbIdtr <= cbLimit + 1)
     2375                    bs3CpuBasic2_CompareUdCtx(&TrapCtx, &CtxUdExpected);
     2376                else if (pWorker->fSs)
     2377                    bs3CpuBasic2_CompareSsCtx(&TrapCtx, &Ctx, 0, false /*f486ResumeFlagHint*/);
     2378                else
     2379                    bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
    23802380            }
    23812381        }
     
    23942394            {
    23952395                Bs3GdteTestPage00.Gen.u16LimitLow = cbLimit;
    2396                 Bs3MemSet(abBuf, bFiller, sizeof(abBuf));
     2396
     2397                Bs3MemSet(abBufLoad, bFiller1, sizeof(abBufLoad));
     2398                Bs3MemCpy(&abBufLoad[off], pbBufRestore, cbIdtr);
     2399                Bs3MemSet(abBufSave, bFiller2, sizeof(abBufSave));
    23972400                Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
    2398 
    2399                 if (off > cbLimit)
     2401                if (bRing != 0)
     2402                    bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
     2403                else if (off > cbLimit)
    24002404                {
    24012405                    bs3CpuBasic2_CompareUdCtx(&TrapCtx, &CtxUdExpected);
    2402                     if (Bs3MemChr(&abBuf[off], bFiller, cbIdtr) != NULL)
    2403                         Bs3TestFailedF("Not all bytes touched (#8): cbIdtr=%u off=%u cbLimit=%u bFiller=%#x abBuf=%.*Rhxs\n",
    2404                                        cbIdtr, off, cbLimit, bFiller, off + cbBuf, abBuf);
    2405                     if (Bs3MemCmp(&abBuf[off], pbExpected, cbIdtr) != 0)
    2406                         Bs3TestFailedF("Mismatch (#8): expected %.*Rhxs, got %.*Rhxs\n", cbIdtr, pbExpected, cbIdtr, &abBuf[off]);
    2407                     if (f286 && abBuf[off + cbIdtr - 1] != 0xff)
    2408                         Bs3TestFailedF("286: Top base byte isn't 0xff (#8): %#x\n", abBuf[off + cbIdtr - 1]);
     2406                    if (Bs3MemCmp(pbBufSave, abExpectedFilled, cbIdtr * 2) != 0)
     2407                        Bs3TestFailedF("Mismatch (#6): expected %.*Rhxs, got %.*Rhxs\n",
     2408                                       cbIdtr*2, abExpectedFilled, cbIdtr*2, pbBufSave);
    24092409                }
     2410                else if (pWorker->fSs)
     2411                    bs3CpuBasic2_CompareSsCtx(&TrapCtx, &Ctx, 0, false /*f486ResumeFlagHint*/);
    24102412                else
    2411                 {
    2412                     if (pWorker->fSs)
    2413                         bs3CpuBasic2_CompareSsCtx(&TrapCtx, &Ctx, 0, false /*f486ResumeFlagHint*/);
    2414                     else
    2415                         bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
    2416                     if (!ASMMemIsAllU8(abBuf, sizeof(abBuf), bFiller))
    2417                         Bs3TestFailedF("Bytes touched on #GP: cbIdtr=%u off=%u cbLimit=%u bFiller=%#x abBuf=%.*Rhxs\n",
    2418                                        cbIdtr, off, cbLimit, bFiller, off + cbBuf, abBuf);
    2419                 }
    2420 
    2421                 if (off > 0 && !ASMMemIsAllU8(abBuf, off, bFiller))
    2422                     Bs3TestFailedF("Leading bytes touched (#9): cbIdtr=%u off=%u cbLimit=%u bFiller=%#x abBuf=%.*Rhxs\n",
    2423                                    cbIdtr, off, cbLimit, bFiller, off + cbBuf, abBuf);
    2424                 if (!ASMMemIsAllU8(&abBuf[off + cbIdtr], sizeof(abBuf) - off - cbIdtr, bFiller))
    2425                     Bs3TestFailedF("Trailing bytes touched (#9): cbIdtr=%u off=%u cbLimit=%u bFiller=%#x abBuf=%.*Rhxs\n",
    2426                                    cbIdtr, off, cbLimit, bFiller, off + cbBuf, abBuf);
    2427 
    2428                 g_usBs3TestStep++;
    2429             }
    2430         }
    2431 
    2432         Bs3RegCtxSetGrpSegFromCurPtr(&Ctx, &Ctx.rbx, pWorker->fSs ? &Ctx.ss : &Ctx.ds, abBuf);
     2413                    bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
     2414               g_usBs3TestStep++;
     2415
     2416               /* Again with zero limit and messed up base (should trigger triple fault if partially loaded). */
     2417               abBufLoad[off] = abBufLoad[off + 1] = 0;
     2418               abBufLoad[off + 2] |= 3;
     2419               abBufLoad[off + cbIdtr - 2] ^= 0x55;
     2420               abBufLoad[off + cbIdtr - 1] ^= 0xaa;
     2421               Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
     2422               if (bRing != 0)
     2423                   bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
     2424               else if (off > cbLimit)
     2425                   bs3CpuBasic2_CompareUdCtx(&TrapCtx, &CtxUdExpected);
     2426               else if (pWorker->fSs)
     2427                   bs3CpuBasic2_CompareSsCtx(&TrapCtx, &Ctx, 0, false /*f486ResumeFlagHint*/);
     2428               else
     2429                   bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
     2430            }
     2431        }
     2432
     2433        Bs3RegCtxSetGrpSegFromCurPtr(&Ctx, &Ctx.rbx, pWorker->fSs ? &Ctx.ss : &Ctx.ds, abBufLoad);
    24332434        CtxUdExpected.rbx.u = Ctx.rbx.u;
    24342435        CtxUdExpected.ss = Ctx.ss;
     
    24462447
    24472448        /*
    2448          * Slide the buffer towards the trailing guard page.  We'll observe the
    2449          * first word being written entirely separately from the 2nd dword/qword.
     2449         * Slide the load buffer towards the trailing guard page.
    24502450         */
     2451        Bs3RegCtxSetGrpSegFromCurPtr(&Ctx, &Ctx.rbx, pWorker->fSs ? &Ctx.ss : &Ctx.ds, &pbTest[X86_PAGE_SIZE]);
     2452        CtxUdExpected.ss = Ctx.ss;
     2453        CtxUdExpected.ds = Ctx.ds;
    24512454        for (off = X86_PAGE_SIZE - cbIdtr - 4; off < X86_PAGE_SIZE + 4; off++)
    24522455        {
    2453             Bs3MemSet(&pbTest[X86_PAGE_SIZE - cbIdtr * 2], bFiller, cbIdtr * 2);
     2456            Bs3MemSet(&pbTest[X86_PAGE_SIZE - cbIdtr * 2], bFiller1, cbIdtr*2);
     2457            if (off < X86_PAGE_SIZE)
     2458                Bs3MemCpy(&pbTest[off], pbBufRestore, RT_MIN(X86_PAGE_SIZE - off, cbIdtr));
    24542459            Bs3RegCtxSetGrpSegFromCurPtr(&Ctx, &Ctx.rbx, pWorker->fSs ? &Ctx.ss : &Ctx.ds, &pbTest[off]);
     2460            Bs3MemSet(abBufSave, bFiller2, sizeof(abBufSave));
    24552461            Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
    2456             if (off + cbIdtr <= X86_PAGE_SIZE)
     2462            if (bRing != 0)
     2463                bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
     2464            else if (off + cbIdtr <= X86_PAGE_SIZE)
    24572465            {
    24582466                CtxUdExpected.rbx = Ctx.rbx;
    2459                 CtxUdExpected.ss  = Ctx.ss;
    2460                 CtxUdExpected.ds  = Ctx.ds;
    24612467                bs3CpuBasic2_CompareUdCtx(&TrapCtx, &CtxUdExpected);
    2462                 if (Bs3MemCmp(&pbTest[off], pbExpected, cbIdtr) != 0)
    2463                     Bs3TestFailedF("Mismatch (#9): expected %.*Rhxs, got %.*Rhxs\n", cbIdtr, pbExpected, cbIdtr, &pbTest[off]);
     2468                if (Bs3MemCmp(pbBufSave, abExpectedFilled, cbIdtr*2) != 0)
     2469                    Bs3TestFailedF("Mismatch (#7): expected %.*Rhxs, got %.*Rhxs\n",
     2470                                   cbIdtr*2, abExpectedFilled, cbIdtr*2, pbBufSave);
    24642471            }
    24652472            else
    2466             {
    2467                 bs3CpuBasic2_ComparePfCtx(&TrapCtx, &Ctx, X86_TRAP_PF_RW | (Ctx.bCpl == 3 ? X86_TRAP_PF_US : 0),
    2468                                           uFlatTest + RT_MAX(off, X86_PAGE_SIZE));
    2469                 if (   off <= X86_PAGE_SIZE - 2
    2470                     && Bs3MemCmp(&pbTest[off], pbExpected, 2) != 0)
    2471                     Bs3TestPrintf("Mismatch (#10): Expected limit %.2Rhxs, got %.2Rhxs; off=%#x\n",
    2472                                   pbExpected, &pbTest[off], off);
    2473                 if (   off < X86_PAGE_SIZE - 2
    2474                     && !ASMMemIsAllU8(&pbTest[off + 2], X86_PAGE_SIZE - off - 2, bFiller))
    2475                     Bs3TestPrintf("Wrote partial base on #PF (#10): bFiller=%#x, got %.*Rhxs; off=%#x\n",
    2476                                   bFiller, X86_PAGE_SIZE - off - 2, &pbTest[off + 2], off);
    2477                 if (off == X86_PAGE_SIZE - 1 && pbTest[off] != bFiller)
    2478                     Bs3TestPrintf("Wrote partial limit on #PF (#10): Expected %02x, got %02x\n", bFiller, pbTest[off]);
    2479             }
     2473                bs3CpuBasic2_ComparePfCtx(&TrapCtx, &Ctx, 0, uFlatTest + RT_MAX(off, X86_PAGE_SIZE));
    24802474            g_usBs3TestStep++;
     2475
     2476            /* Again with zero limit and maybe messed up base as well (triple fault if buggy).
     2477               The 386DX-40 here triple faults (or something) with off == 0xffe, nothing else. */
     2478            if (   off < X86_PAGE_SIZE && off + cbIdtr > X86_PAGE_SIZE
     2479                && (   off != X86_PAGE_SIZE - 2
     2480                    || (g_uBs3CpuDetected & BS3CPU_TYPE_MASK) != BS3CPU_80386)
     2481                )
     2482            {
     2483                pbTest[off] = 0;
     2484                if (off + 1 < X86_PAGE_SIZE)
     2485                    pbTest[off + 1] = 0;
     2486                if (off + 2 < X86_PAGE_SIZE)
     2487                    pbTest[off + 2] |= 7;
     2488                Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
     2489                if (bRing != 0)
     2490                    bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
     2491                else
     2492                    bs3CpuBasic2_ComparePfCtx(&TrapCtx, &Ctx, 0, uFlatTest + RT_MAX(off, X86_PAGE_SIZE));
     2493                g_usBs3TestStep++;
     2494            }
    24812495        }
    24822496
     
    24872501        for (off = cbIdtr + 4; off >= -cbIdtr - 4; off--)
    24882502        {
    2489             Bs3MemSet(pbTest, bFiller, 48);
     2503            Bs3MemSet(pbTest, bFiller1, 48);
     2504            if (off >= 0)
     2505                Bs3MemCpy(&pbTest[off], pbBufRestore, cbIdtr);
     2506            else if (off + cbIdtr > 0)
     2507                Bs3MemCpy(pbTest, &pbBufRestore[-off], cbIdtr + off);
    24902508            Bs3RegCtxSetGrpSegFromCurPtr(&Ctx, &Ctx.rbx, pWorker->fSs ? &Ctx.ss : &Ctx.ds, &pbTest[off]);
     2509            Bs3MemSet(abBufSave, bFiller2, sizeof(abBufSave));
    24912510            Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
    2492             if (off >= 0)
     2511            if (bRing != 0)
     2512                bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
     2513            else if (off >= 0)
    24932514            {
    24942515                CtxUdExpected.rbx = Ctx.rbx;
    2495                 CtxUdExpected.ss  = Ctx.ss;
    2496                 CtxUdExpected.ds  = Ctx.ds;
    24972516                bs3CpuBasic2_CompareUdCtx(&TrapCtx, &CtxUdExpected);
    2498                 if (Bs3MemCmp(&pbTest[off], pbExpected, cbIdtr) != 0)
    2499                     Bs3TestFailedF("Mismatch (#11): expected %.*Rhxs, got %.*Rhxs\n", cbIdtr, pbExpected, cbIdtr, &pbTest[off]);
     2517                if (Bs3MemCmp(pbBufSave, abExpectedFilled, cbIdtr*2) != 0)
     2518                    Bs3TestFailedF("Mismatch (#8): expected %.*Rhxs, got %.*Rhxs\n",
     2519                                   cbIdtr*2, abExpectedFilled, cbIdtr*2, pbBufSave);
    25002520            }
    25012521            else
    2502             {
    2503                 bs3CpuBasic2_ComparePfCtx(&TrapCtx, &Ctx, X86_TRAP_PF_RW | (Ctx.bCpl == 3 ? X86_TRAP_PF_US : 0), uFlatTest + off);
    2504                 if (   -off < cbIdtr
    2505                     && !ASMMemIsAllU8(pbTest, cbIdtr + off, bFiller))
    2506                     Bs3TestPrintf("Wrote partial content on #PF (#12): bFiller=%#x, found %.*Rhxs; off=%d\n",
    2507                                   bFiller, cbIdtr + off, pbTest, off);
    2508             }
    2509             if (!ASMMemIsAllU8(&pbTest[RT_MAX(cbIdtr + off, 0)], 16, bFiller))
    2510                 Bs3TestPrintf("Wrote beyond expected area (#13): bFiller=%#x, found %.16Rhxs; off=%d\n",
    2511                               bFiller, &pbTest[RT_MAX(cbIdtr + off, 0)], off);
     2522                bs3CpuBasic2_ComparePfCtx(&TrapCtx, &Ctx, 0, uFlatTest + off);
    25122523            g_usBs3TestStep++;
     2524
     2525            /* Again with messed up base as well (triple fault if buggy). */
     2526            if (off < 0 && off > -cbIdtr)
     2527            {
     2528                if (off + 2 >= 0)
     2529                    pbTest[off + 2] |= 15;
     2530                pbTest[off + cbIdtr - 1] ^= 0xaa;
     2531                Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
     2532                if (bRing != 0)
     2533                    bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
     2534                else
     2535                    bs3CpuBasic2_ComparePfCtx(&TrapCtx, &Ctx, 0, uFlatTest + off);
     2536                g_usBs3TestStep++;
     2537            }
    25132538        }
    25142539
     
    25162541         * Combine paging and segment limit and check ordering.
    25172542         * This is kind of interesting here since it the instruction seems to
    2518          * be doing two separate writes.
     2543         * actually be doing two separate read, just like it's S[IG]DT counterpart.
    25192544         */
    25202545        if (   !BS3_MODE_IS_RM_OR_V86(bTestMode)
     
    25412566                {
    25422567                    Bs3GdteTestPage00.Gen.u16LimitLow = cbLimit;
    2543                     Bs3MemSet(&pbTest[X86_PAGE_SIZE - cbIdtr * 2], bFiller, cbIdtr * 2);
     2568                    Bs3MemSet(&pbTest[X86_PAGE_SIZE - cbIdtr * 2], bFiller1, cbIdtr * 2);
     2569                    if (off < X86_PAGE_SIZE)
     2570                        Bs3MemCpy(&pbTest[off], pbBufRestore, RT_MIN(cbIdtr, X86_PAGE_SIZE - off));
     2571                    Bs3MemSet(abBufSave, bFiller2, sizeof(abBufSave));
    25442572                    Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
    2545                     if (off + cbIdtr <= cbLimit + 1)
     2573                    if (bRing != 0)
     2574                        bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
     2575                    else if (off + cbIdtr <= cbLimit + 1)
    25462576                    {
    25472577                        /* No #GP, but maybe #PF. */
     
    25492579                        {
    25502580                            bs3CpuBasic2_CompareUdCtx(&TrapCtx, &CtxUdExpected);
    2551                             if (Bs3MemCmp(&pbTest[off], pbExpected, cbIdtr) != 0)
    2552                                 Bs3TestFailedF("Mismatch (#14): expected %.*Rhxs, got %.*Rhxs\n",
    2553                                                cbIdtr, pbExpected, cbIdtr, &pbTest[off]);
     2581                            if (Bs3MemCmp(pbBufSave, abExpectedFilled, cbIdtr * 2) != 0)
     2582                                Bs3TestFailedF("Mismatch (#9): expected %.*Rhxs, got %.*Rhxs\n",
     2583                                               cbIdtr*2, abExpectedFilled, cbIdtr*2, pbBufSave);
    25542584                        }
    25552585                        else
    2556                         {
    2557                             bs3CpuBasic2_ComparePfCtx(&TrapCtx, &Ctx, X86_TRAP_PF_RW | (Ctx.bCpl == 3 ? X86_TRAP_PF_US : 0),
    2558                                                       uFlatTest + RT_MAX(off, X86_PAGE_SIZE));
    2559                             if (   off <= X86_PAGE_SIZE - 2
    2560                                 && Bs3MemCmp(&pbTest[off], pbExpected, 2) != 0)
    2561                                 Bs3TestPrintf("Mismatch (#15): Expected limit %.2Rhxs, got %.2Rhxs; off=%#x\n",
    2562                                               pbExpected, &pbTest[off], off);
    2563                             cb = X86_PAGE_SIZE - off - 2;
    2564                             if (   off < X86_PAGE_SIZE - 2
    2565                                 && !ASMMemIsAllU8(&pbTest[off + 2], cb, bFiller))
    2566                                 Bs3TestPrintf("Wrote partial base on #PF (#15): bFiller=%#x, got %.*Rhxs; off=%#x\n",
    2567                                               bFiller, cb, &pbTest[off + 2], off);
    2568                             if (off == X86_PAGE_SIZE - 1 && pbTest[off] != bFiller)
    2569                                 Bs3TestPrintf("Wrote partial limit on #PF (#15): Expected %02x, got %02x\n", bFiller, pbTest[off]);
    2570                         }
     2586                            bs3CpuBasic2_ComparePfCtx(&TrapCtx, &Ctx, 0, uFlatTest + RT_MAX(off, X86_PAGE_SIZE));
    25712587                    }
    2572                     else if (off + 2 <= cbLimit + 1)
    2573                     {
    2574                         /* [ig]tr.limit writing does not cause #GP, but may cause #PG, if not writing the base causes #GP. */
    2575                         if (off <= X86_PAGE_SIZE - 2)
    2576                         {
    2577                             if (pWorker->fSs)
    2578                                 bs3CpuBasic2_CompareSsCtx(&TrapCtx, &Ctx, 0, false /*f486ResumeFlagHint*/);
    2579                             else
    2580                                 bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
    2581                             if (Bs3MemCmp(&pbTest[off], pbExpected, 2) != 0)
    2582                                 Bs3TestPrintf("Mismatch (#16): Expected limit %.2Rhxs, got %.2Rhxs; off=%#x\n",
    2583                                               pbExpected, &pbTest[off], off);
    2584                             cb = X86_PAGE_SIZE - off - 2;
    2585                             if (   off < X86_PAGE_SIZE - 2
    2586                                 && !ASMMemIsAllU8(&pbTest[off + 2], cb, bFiller))
    2587                                 Bs3TestPrintf("Wrote partial base with limit (#16): bFiller=%#x, got %.*Rhxs; off=%#x\n",
    2588                                               bFiller, cb, &pbTest[off + 2], off);
    2589                         }
    2590                         else
    2591                         {
    2592                             bs3CpuBasic2_ComparePfCtx(&TrapCtx, &Ctx, X86_TRAP_PF_RW | (Ctx.bCpl == 3 ? X86_TRAP_PF_US : 0),
    2593                                                       uFlatTest + RT_MAX(off, X86_PAGE_SIZE));
    2594                             if (   off < X86_PAGE_SIZE
    2595                                 && !ASMMemIsAllU8(&pbTest[off], X86_PAGE_SIZE - off, bFiller))
    2596                                 Bs3TestPrintf("Mismatch (#16): Partial limit write on #PF: bFiller=%#x, got %.*Rhxs\n",
    2597                                               bFiller, X86_PAGE_SIZE - off, &pbTest[off]);
    2598                         }
    2599                     }
     2588                    /* No #GP/#SS on limit, but instead #PF? */
     2589                    else if (off < cbLimit && off >= 0xfff)
     2590                        bs3CpuBasic2_ComparePfCtx(&TrapCtx, &Ctx, 0, uFlatTest + RT_MAX(off, X86_PAGE_SIZE));
     2591                    /* #GP/#SS on limit or base. */
     2592                    else if (pWorker->fSs)
     2593                        bs3CpuBasic2_CompareSsCtx(&TrapCtx, &Ctx, 0, false /*f486ResumeFlagHint*/);
    26002594                    else
    2601                     {
    2602                         /* #GP/#SS on limit. */
    2603                         if (pWorker->fSs)
    2604                             bs3CpuBasic2_CompareSsCtx(&TrapCtx, &Ctx, 0, false /*f486ResumeFlagHint*/);
    2605                         else
    2606                             bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
    2607                         if (   off < X86_PAGE_SIZE
    2608                             && !ASMMemIsAllU8(&pbTest[off], X86_PAGE_SIZE - off, bFiller))
    2609                             Bs3TestPrintf("Mismatch (#17): Partial write on #GP: bFiller=%#x, got %.*Rhxs\n",
    2610                                           bFiller, X86_PAGE_SIZE - off, &pbTest[off]);
    2611                     }
    2612 
    2613                     cb = RT_MIN(cbIdtr * 2, off - (X86_PAGE_SIZE - cbIdtr*2));
    2614                     if (!ASMMemIsAllU8(&pbTest[X86_PAGE_SIZE - cbIdtr * 2], cb, bFiller))
    2615                         Bs3TestFailedF("Leading bytes touched (#18): cbIdtr=%u off=%u cbLimit=%u bFiller=%#x pbTest=%.*Rhxs\n",
    2616                                        cbIdtr, off, cbLimit, bFiller, cb, pbTest[X86_PAGE_SIZE - cbIdtr * 2]);
     2595                        bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
    26172596
    26182597                    g_usBs3TestStep++;
     
    26452624                {
    26462625                    Bs3GdteTestPage00.Gen.u16LimitLow = cbLimit;
    2647                     Bs3MemSet(&pbTest[X86_PAGE_SIZE], bFiller, cbIdtr * 2);
     2626                    Bs3MemSet(&pbTest[X86_PAGE_SIZE], bFiller1, cbIdtr * 2);
     2627                    if (off >= X86_PAGE_SIZE)
     2628                        Bs3MemCpy(&pbTest[off], pbBufRestore, cbIdtr);
     2629                    else if (off > X86_PAGE_SIZE - cbIdtr)
     2630                        Bs3MemCpy(&pbTest[X86_PAGE_SIZE], &pbBufRestore[X86_PAGE_SIZE - off], cbIdtr - (X86_PAGE_SIZE - off));
     2631                    Bs3MemSet(abBufSave, bFiller2, sizeof(abBufSave));
    26482632                    Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
    2649                     if (cbLimit < off && off >= X86_PAGE_SIZE)
     2633                    if (bRing != 0)
     2634                        bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
     2635                    else if (cbLimit < off && off >= X86_PAGE_SIZE)
    26502636                    {
    26512637                        bs3CpuBasic2_CompareUdCtx(&TrapCtx, &CtxUdExpected);
    2652                         if (Bs3MemCmp(&pbTest[off], pbExpected, cbIdtr) != 0)
    2653                             Bs3TestFailedF("Mismatch (#19): expected %.*Rhxs, got %.*Rhxs\n",
    2654                                            cbIdtr, pbExpected, cbIdtr, &pbTest[off]);
    2655                         cb = X86_PAGE_SIZE + cbIdtr*2 - off;
    2656                         if (!ASMMemIsAllU8(&pbTest[off + cbIdtr], cb, bFiller))
    2657                             Bs3TestFailedF("Trailing bytes touched (#20): cbIdtr=%u off=%u cbLimit=%u bFiller=%#x pbTest=%.*Rhxs\n",
    2658                                            cbIdtr, off, cbLimit, bFiller, cb, pbTest[off + cbIdtr]);
     2638                        if (Bs3MemCmp(pbBufSave, abExpectedFilled, cbIdtr * 2) != 0)
     2639                            Bs3TestFailedF("Mismatch (#10): expected %.*Rhxs, got %.*Rhxs\n",
     2640                                           cbIdtr*2, abExpectedFilled, cbIdtr*2, pbBufSave);
    26592641                    }
     2642                    else if (cbLimit < off && off < X86_PAGE_SIZE)
     2643                        bs3CpuBasic2_ComparePfCtx(&TrapCtx, &Ctx, 0, uFlatTest + off);
     2644                    else if (pWorker->fSs)
     2645                        bs3CpuBasic2_CompareSsCtx(&TrapCtx, &Ctx, 0, false /*f486ResumeFlagHint*/);
    26602646                    else
    2661                     {
    2662                         if (cbLimit < off && off < X86_PAGE_SIZE)
    2663                             bs3CpuBasic2_ComparePfCtx(&TrapCtx, &Ctx, X86_TRAP_PF_RW | (Ctx.bCpl == 3 ? X86_TRAP_PF_US : 0),
    2664                                                       uFlatTest + off);
    2665                         else if (pWorker->fSs)
    2666                             bs3CpuBasic2_CompareSsCtx(&TrapCtx, &Ctx, 0, false /*f486ResumeFlagHint*/);
    2667                         else
    2668                             bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
    2669                         cb = cbIdtr*2;
    2670                         if (!ASMMemIsAllU8(&pbTest[X86_PAGE_SIZE], cb, bFiller))
    2671                             Bs3TestFailedF("Trailing bytes touched (#20): cbIdtr=%u off=%u cbLimit=%u bFiller=%#x pbTest=%.*Rhxs\n",
    2672                                            cbIdtr, off, cbLimit, bFiller, cb, pbTest[X86_PAGE_SIZE]);
    2673                     }
     2647                        bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
    26742648                    g_usBs3TestStep++;
    26752649                }
     
    26962670        {
    26972671            Ctx.rbx.u = CtxUdExpected.rbx.u = UINT64_C(0x0000800000000000) + off;
    2698             Bs3MemSet(&pbTest[-64], bFiller, 64*2);
     2672            Bs3MemSet(&pbTest[-64], bFiller1, 64*2);
     2673            Bs3MemCpy(&pbTest[off], pbBufRestore, cbIdtr);
     2674            Bs3MemSet(abBufSave, bFiller2, sizeof(abBufSave));
    26992675            Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
    2700             if (off + cbIdtr <= 0)
     2676            if (off + cbIdtr > 0 || bRing != 0)
     2677                bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
     2678            else
    27012679            {
    27022680                bs3CpuBasic2_CompareUdCtx(&TrapCtx, &CtxUdExpected);
    2703                 if (Bs3MemCmp(&pbTest[off], pbExpected, cbIdtr) != 0)
    2704                     Bs3TestFailedF("Mismatch (#21): expected %.*Rhxs, got %.*Rhxs\n", cbIdtr, pbExpected, cbIdtr, &pbTest[off]);
    2705             }
    2706             else
    2707             {
    2708                 bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
    2709                 if (off <= -2 && Bs3MemCmp(&pbTest[off], pbExpected, 2) != 0)
    2710                     Bs3TestFailedF("Mismatch (#21): expected limit %.2Rhxs, got %.2Rhxs\n", pbExpected, &pbTest[off]);
    2711                 off2 = off <= -2 ? 2 : 0;
    2712                 cb   = cbIdtr - off2;
    2713                 if (!ASMMemIsAllU8(&pbTest[off + off2], cb, bFiller))
    2714                     Bs3TestFailedF("Mismatch (#21): touched base %.*Rhxs, got %.*Rhxs\n",
    2715                                    cb, &pbExpected[off], cb, &pbTest[off + off2]);
    2716             }
    2717             if (!ASMMemIsAllU8(&pbTest[off - 16], 16, bFiller))
    2718                 Bs3TestFailedF("Leading bytes touched (#21): bFiller=%#x, got %.16Rhxs\n", bFiller, &pbTest[off]);
    2719             if (!ASMMemIsAllU8(&pbTest[off + cbIdtr], 16, bFiller))
    2720                 Bs3TestFailedF("Trailing bytes touched (#21): bFiller=%#x, got %.16Rhxs\n", bFiller, &pbTest[off + cbIdtr]);
     2681                if (Bs3MemCmp(pbBufSave, abExpectedFilled, cbIdtr * 2) != 0)
     2682                    Bs3TestFailedF("Mismatch (#18): expected %.*Rhxs, got %.*Rhxs\n",
     2683                                   cbIdtr*2, abExpectedFilled, cbIdtr*2, pbBufSave);
     2684            }
    27212685        }
    27222686
     
    27252689        {
    27262690            Ctx.rbx.u = CtxUdExpected.rbx.u = UINT64_C(0xffff800000000000) + off;
    2727             Bs3MemSet(&pbTest[-64], bFiller, 64*2);
     2691            Bs3MemSet(&pbTest[-64], bFiller1, 64*2);
     2692            Bs3MemCpy(&pbTest[off], pbBufRestore, cbIdtr);
     2693            Bs3MemSet(abBufSave, bFiller2, sizeof(abBufSave));
    27282694            Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
    2729             if (off >= 0)
     2695            if (off < 0 || bRing != 0)
     2696                bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
     2697            else
    27302698            {
    27312699                bs3CpuBasic2_CompareUdCtx(&TrapCtx, &CtxUdExpected);
    2732                 if (Bs3MemCmp(&pbTest[off], pbExpected, cbIdtr) != 0)
    2733                     Bs3TestFailedF("Mismatch (#22): expected %.*Rhxs, got %.*Rhxs\n", cbIdtr, pbExpected, cbIdtr, &pbTest[off]);
    2734             }
    2735             else
    2736             {
    2737                 bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
    2738                 if (!ASMMemIsAllU8(&pbTest[off], cbIdtr, bFiller))
    2739                     Bs3TestFailedF("Mismatch (#22): touched base %.*Rhxs, got %.*Rhxs\n",
    2740                                    cbIdtr, &pbExpected[off], cbIdtr, &pbTest[off]);
    2741             }
    2742             if (!ASMMemIsAllU8(&pbTest[off - 16], 16, bFiller))
    2743                 Bs3TestFailedF("Leading bytes touched (#22): bFiller=%#x, got %.16Rhxs\n", bFiller, &pbTest[off]);
    2744             if (!ASMMemIsAllU8(&pbTest[off + cbIdtr], 16, bFiller))
    2745                 Bs3TestFailedF("Trailing bytes touched (#22): bFiller=%#x, got %.16Rhxs\n", bFiller, &pbTest[off + cbIdtr]);
    2746         }
    2747 
    2748     }
    2749 #endif
     2700                if (Bs3MemCmp(pbBufSave, abExpectedFilled, cbIdtr * 2) != 0)
     2701                    Bs3TestFailedF("Mismatch (#19): expected %.*Rhxs, got %.*Rhxs\n",
     2702                                   cbIdtr*2, abExpectedFilled, cbIdtr*2, pbBufSave);
     2703            }
     2704        }
     2705
     2706    }
    27502707}
    27512708
     
    27652722        for (idx = 0; idx < cWorkers; idx++)
    27662723            if (    (paWorkers[idx].bMode & (bTestMode & BS3_MODE_CODE_MASK))
    2767                 && (!paWorkers[idx].fSs || bRing != 0 /** @todo || BS3_MODE_IS_64BIT_SYS(bTestMode)*/ ))
     2724                && (!paWorkers[idx].fSs || bRing != 0 /** @todo || BS3_MODE_IS_64BIT_SYS(bTestMode)*/ )
     2725                && (   !(paWorkers[idx].fFlags & BS3CB2SIDTSGDT_F_386PLUS)
     2726                    || (   bTestMode > BS3_MODE_PE16
     2727                        || (   bTestMode == BS3_MODE_PE16
     2728                            && (g_uBs3CpuDetected & BS3CPU_TYPE_MASK) >= BS3CPU_80386)) ) )
    27682729            {
    27692730                //Bs3TestPrintf("idx=%-2d fpfnWorker=%p fSs=%d cbInstr=%d\n",
     
    31513112}
    31523113
    3153 #if 0
    31543114BS3_DECL_FAR(uint8_t) TMPL_NM(bs3CpuBasic2_lgdt)(uint8_t bMode)
    31553115{
    3156     uint64_t const uOrgAddr = Bs3Lgdt_Gdt.uAddr;
    3157     uint64_t       uNew     = 0;
    31583116    union
    31593117    {
    31603118        RTGDTR  Gdtr;
    3161         uint8_t ab[16];
     3119        uint8_t ab[32]; /* At least cbIdtr*2! */
    31623120    } Expected;
    31633121
     
    31653123    g_bTestMode   = bMode;
    31663124    g_f16BitSys   = BS3_MODE_IS_16BIT_SYS(TMPL_MODE);
     3125
    31673126    BS3_ASSERT(bMode == TMPL_MODE);
    31683127
     
    31703129     * Pass to common worker which is only compiled once per mode.
    31713130     */
     3131    if (BS3_MODE_IS_RM_SYS(bMode))
     3132        ASMSetGDTR((PRTGDTR)&Bs3LgdtDef_Gdt);
    31723133    Bs3MemZero(&Expected, sizeof(Expected));
    31733134    ASMGetGDTR(&Expected.Gdtr);
    3174     bs3CpuBasic2_lidt_lgdt_Common(bMode, g_aSgdtWorkers, RT_ELEMENTS(g_aSgdtWorkers), Expected.ab);
    3175 
    3176     /*
    3177      * Unalias the GDT.
    3178      */
    3179     if (uNew != 0)
    3180     {
    3181         Bs3Lgdt_Gdt.uAddr = uOrgAddr;
    3182         Bs3UtilSetFullGdtr(Bs3Lgdt_Gdt.cb, uOrgAddr);
    3183         Bs3PagingUnalias(uNew, Bs3Lgdt_Gdt.cb);
    3184     }
     3135
     3136    bs3CpuBasic2_lidt_lgdt_Common(bMode, g_aLgdtWorkers, RT_ELEMENTS(g_aLgdtWorkers),
     3137                                  &Bs3LgdtDef_Gdt, sizeof(Bs3LgdtDef_Gdt), Expected.ab);
    31853138
    31863139    /*
     
    31903143    return 0;
    31913144}
    3192 #endif
    31933145
    31943146#endif /* BS3_INSTANTIATING_MODE */
  • trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-template.mac

    r60724 r60728  
    178178BS3_PROC_END_CMN   bs3CpuBasic2_lidt_opsize_bx__sidt_es_di__lidt_es_si__ud2
    179179
     180%if TMPL_BITS == 16
     181BS3_PROC_BEGIN_CMN bs3CpuBasic2_lidt_opsize_bx__sidt32_es_di__lidt_es_si__ud2, BS3_PBC_NEAR
     182        db      X86_OP_PRF_SIZE_OP
     183        lidt    [xBX]
     184        jmp     dword BS3_SEL_R0_CS32:.in_32bit wrt FLAT
     185        BS3_SET_BITS 32
     186.in_32bit:
     187        sidt    [es:edi]
     188        lidt    [es:esi]
     189        jmp     dword BS3_SEL_R0_CS16:.again wrt CGROUP16
     190        BS3_SET_BITS 16
     191.again:
     192        ud2
     193        jmp     .again
     194AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_lidt_opsize_bx__sidt32_es_di__lidt_es_si__ud2) == 27)
     195BS3_PROC_END_CMN   bs3CpuBasic2_lidt_opsize_bx__sidt32_es_di__lidt_es_si__ud2
     196%endif
     197
    180198 %if TMPL_BITS == 64
    181199BS3_PROC_BEGIN_CMN bs3CpuBasic2_lidt_rexw_bx__sidt_es_di__lidt_es_si__ud2, BS3_PBC_NEAR
     
    227245
    228246
     247;
     248; LGDT
     249;
     250BS3_PROC_BEGIN_CMN bs3CpuBasic2_lgdt_bx__sgdt_es_di__lgdt_es_si__ud2, BS3_PBC_NEAR
     251        lgdt    [xBX]
     252        sgdt    [BS3_NOT_64BIT(es:) xDI]
     253        lgdt    [BS3_NOT_64BIT(es:) xSI]
     254.again:
     255        ud2
     256        jmp     .again
     257AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_lgdt_bx__sgdt_es_di__lgdt_es_si__ud2) == BS3_IF_64BIT_OTHERWISE(9,11))
     258BS3_PROC_END_CMN   bs3CpuBasic2_lgdt_bx__sgdt_es_di__lgdt_es_si__ud2
     259
     260BS3_PROC_BEGIN_CMN bs3CpuBasic2_lgdt_opsize_bx__sgdt_es_di__lgdt_es_si__ud2, BS3_PBC_NEAR
     261        db      X86_OP_PRF_SIZE_OP
     262        lgdt    [xBX]
     263        sgdt    [BS3_NOT_64BIT(es:) xDI]
     264        lgdt    [BS3_NOT_64BIT(es:) xSI]
     265.again:
     266        ud2
     267        jmp     .again
     268AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_lgdt_opsize_bx__sgdt_es_di__lgdt_es_si__ud2) == BS3_IF_64BIT_OTHERWISE(10,12))
     269BS3_PROC_END_CMN   bs3CpuBasic2_lgdt_opsize_bx__sgdt_es_di__lgdt_es_si__ud2
     270
     271 %if TMPL_BITS == 64
     272BS3_PROC_BEGIN_CMN bs3CpuBasic2_lgdt_rexw_bx__sgdt_es_di__lgdt_es_si__ud2, BS3_PBC_NEAR
     273        db      X86_OP_REX_W
     274        lgdt    [xBX]
     275        sgdt    [xDI]
     276        lgdt    [xSI]
     277.again:
     278        ud2
     279        jmp     .again
     280AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_lgdt_rexw_bx__sgdt_es_di__lgdt_es_si__ud2) == 10)
     281BS3_PROC_END_CMN   bs3CpuBasic2_lgdt_rexw_bx__sgdt_es_di__lgdt_es_si__ud2
     282
     283BS3_PROC_BEGIN_CMN bs3CpuBasic2_lgdt_opsize_rexw_bx__sgdt_es_di__lgdt_es_si__ud2, BS3_PBC_NEAR
     284        db      X86_OP_PRF_SIZE_OP
     285        db      X86_OP_REX_W
     286        lgdt    [xBX]
     287        sgdt    [xDI]
     288        lgdt    [xSI]
     289.again:
     290        ud2
     291        jmp     .again
     292AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_lgdt_opsize_rexw_bx__sgdt_es_di__lgdt_es_si__ud2) == 11)
     293BS3_PROC_END_CMN   bs3CpuBasic2_lgdt_opsize_rexw_bx__sgdt_es_di__lgdt_es_si__ud2
     294 %endif
     295
     296 %if TMPL_BITS != 64
     297BS3_PROC_BEGIN_CMN bs3CpuBasic2_lgdt_ss_bx__sgdt_es_di__lgdt_es_si__ud2, BS3_PBC_NEAR
     298        lgdt    [ss:xBX]
     299        sgdt    [BS3_NOT_64BIT(es:) xDI]
     300        lgdt    [BS3_NOT_64BIT(es:) xSI]
     301.again:
     302        ud2
     303        jmp     .again
     304AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_lgdt_ss_bx__sgdt_es_di__lgdt_es_si__ud2) == 12)
     305BS3_PROC_END_CMN   bs3CpuBasic2_lgdt_ss_bx__sgdt_es_di__lgdt_es_si__ud2
     306
     307BS3_PROC_BEGIN_CMN bs3CpuBasic2_lgdt_opsize_ss_bx__sgdt_es_di__lgdt_es_si__ud2, BS3_PBC_NEAR
     308        db      X86_OP_PRF_SIZE_OP
     309        lgdt    [ss:xBX]
     310        sgdt    [BS3_NOT_64BIT(es:) xDI]
     311        lgdt    [BS3_NOT_64BIT(es:) xSI]
     312.again:
     313        ud2
     314        jmp     .again
     315AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_lgdt_opsize_ss_bx__sgdt_es_di__lgdt_es_si__ud2) == 13)
     316BS3_PROC_END_CMN   bs3CpuBasic2_lgdt_opsize_ss_bx__sgdt_es_di__lgdt_es_si__ud2
     317 %endif
     318
     319
    229320%endif ; BS3_INSTANTIATING_CMN
    230321
  • trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2.c

    r60724 r60728  
    6060#endif
    6161    BS3TESTMODEENTRY_MODE("lidt", bs3CpuBasic2_lidt),
     62    BS3TESTMODEENTRY_MODE("lgdt", bs3CpuBasic2_lgdt),
    6263};
    6364
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-rm-InitAll.c

    r60585 r60728  
    3434#include <iprt/asm-amd64-x86.h>
    3535
     36BS3_MODE_PROTO_NOSB(void, Bs3EnteredMode,(void));
     37
    3638
    3739BS3_DECL(void) Bs3InitAll_rm(void)
    3840{
     41    uint32_t volatile BS3_FAR *pcTicks = (uint32_t volatile BS3_FAR *)BS3_FP_MAKE(0x40, 0x6c);
     42    uint32_t                   cInitialTicks = *pcTicks;
     43    int                        i = 3;
     44
    3945    Bs3CpuDetect_rm_far();
    4046    Bs3InitMemory_rm_far();
    4147    Bs3InitGdt_rm_far();
    4248
     49    /* For for floppy to stop (a couple of ticks), then disable interrupts. */
     50    ASMIntEnable();
     51    while (i-- > 0)
     52    {
     53        while (*pcTicks == cInitialTicks)
     54            ASMHalt();
     55        *pcTicks = cInitialTicks;
     56    }
    4357    ASMIntDisable();
    4458    Bs3PicMaskAll();
     
    5165        Bs3Trap16Init();
    5266    Bs3TrapRmV86Init();
     67    Bs3EnteredMode_rm();
    5368}
    5469
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette