cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; Bootsector that shows/tests the content of hidden CPU registers.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; Requires VMMDevTesting. Enable it via VBoxManage:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; VBoxManage setextradata bs-cpu-hidden-regs-1 VBoxInternal/Devices/VMMDev/0/Config/TestingEnabled 1
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; Copyright (C) 2007-2014 Oracle Corporation
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; This file is part of VirtualBox Open Source Edition (OSE), as
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; available from http://www.virtualbox.org. This file is free software;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; you can redistribute it and/or modify it under the terms of the GNU
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; General Public License (GPL) as published by the Free Software
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; Foundation, in version 2 as it comes in the "COPYING" file of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; The contents of this file may alternatively be used under the terms
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; of the Common Development and Distribution License Version 1.0
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; VirtualBox OSE distribution, in which case the provisions of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; CDDL are applicable instead of those of the GPL.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; You may elect to license modified versions of this file under the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; terms and conditions of either the GPL or the CDDL or both.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; Include and execute the init code.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %define BS2_INIT_RM
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %define BS2_INC_PE16
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %define BS2_INC_PE32
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %define BS2_INC_PP32
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %define BS2_INC_LM64
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %define BS2_WITH_TRAPS
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %define BS2_WITH_MANUAL_LTR
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; The benchmark driver
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncBEGINPROC main
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ; Test prologue.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov ax, .s_szTstName
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call TestInit_r86
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call Bs2EnableA20_r86
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call Bs2PanicIfVMMDevTestingIsMissing_r86
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call reportPostBiosValues
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call rmTests
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call doTests_rm_pe32
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call doTests_rm_pp32
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call doTests_rm_lm64
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ; We're done.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call TestTerm_r86
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call Bs2Panic
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync.s_szTstName:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'tstCpuHidRegs', 0
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncENDPROC main
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; Reports the values of interesting hidden registers as we start the test, i.e.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; right after the BIOS completed.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncBEGINPROC reportPostBiosValues
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov ax, .s_szTstInitial
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call TestSub_r86
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov ax, .s_szzStart
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call TestValueRegSZZ_rm
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync.s_szzStart:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'BIOS - ldtr:ldtr', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'BIOS - ldtr_base:ldtr_base', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'BIOS - ldtr_limit:ldtr_lim', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'BIOS - ldtr_attr:ldtr_attr', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'BIOS - tr:tr', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'BIOS - tr_base:tr_base', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'BIOS - tr_limit:tr_lim', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'BIOS - tr_attr:tr_attr', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'BIOS - cs:cs', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'BIOS - cs_base:cs_base', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'BIOS - cs_limit:cs_lim', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'BIOS - cs_attr:cs_attr', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'BIOS - ss:ss', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'BIOS - ss_base:ss_base', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'BIOS - ss_limit:ss_lim', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'BIOS - ss_attr:ss_attr', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'BIOS - ds:ds', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'BIOS - ds_base:ds_base', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'BIOS - ds_limit:ds_lim', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'BIOS - ds_attr:ds_attr', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 0,0,0,0 ; terminator
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync.s_szTstInitial:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'Post BIOS Values', 0
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncENDPROC reportPostBiosValues
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; Reports the values of interesting hidden registers as we start the test, i.e.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; right after the BIOS completed.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncBEGINPROC rmTests
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov ax, .s_szTstRM
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call TestSub_r86
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ; Check if CS changes when leaving protected mode.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov ax, .s_szzRMPre
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call TestValueRegSZZ_rm
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov byte [cs:.s_dwDummy], 1
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call Bs2EnterMode_rm_pe32
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov eax, .s_szzProt32
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call TestValueRegSZZ_pe32
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ; mov word [cs:.s_dwDummy], 2 - this shall GP(CS).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call Bs2ExitMode_pe32
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov ax, .s_szzRMPost
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call TestValueRegSZZ_rm
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov dword [cs:.s_dwDummy], 3
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ; What happens if we make CS32 execute-only and return to real-mode.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov byte [cs:.s_dwDummy], 1
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call Bs2EnterMode_rm_pe16
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync jmp BS2_SEL_CS16_EO:.loaded_cs16_eo
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync.loaded_cs16_eo:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov eax, .s_szzProtEO
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call TestValueRegSZZ_pe16
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ; mov ax, word [cs:.s_dwDummy] - this shall GP(CS).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ; mov word [cs:.s_dwDummy], 2 - this shall GP(CS).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ; Leave real-mode ourselves.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov eax, cr0
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and eax, ~X86_CR0_PE
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov cr0, eax
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ; All but cs gets reloaded.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ; Display CS and do a test.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov ax, .s_szzRMEO
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call TestValueRegSZZ_rm
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov ax, [cs:.s_dwDummy] ; works on intel
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov dword [cs:.s_dwDummy], 3 ; ditto
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync jmp far 0000:.load_rm_cs
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync.load_rm_cs:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ; Display CS to check that it remained unchanged.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov ax, .s_szzRMEO2
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call TestValueRegSZZ_rm
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ; Cleanup everything properly.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call Bs2EnterMode_rm_pe32
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call Bs2ExitMode_pe32
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync.s_szzRMPre:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'RM Pre - cs:cs', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'RM Pre - cs_base:cs_base', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'RM Pre - cs_limit:cs_lim', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'RM Pre - cs_attr:cs_attr', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 0,0,0,0 ; terminator
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync.s_szzProt32:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'Prot32 - cs:cs', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'Prot32 - cs_base:cs_base', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'Prot32 - cs_limit:cs_lim', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'Prot32 - cs_attr:cs_attr', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 0,0,0,0 ; terminator
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync.s_szzRMPost:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'RM Post - cs:cs', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'RM Post - cs_base:cs_base', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'RM Post - cs_limit:cs_lim', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'RM Post - cs_attr:cs_attr', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 0,0,0,0 ; terminator
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync.s_szzProtEO:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'Prot 16 EO,L-1,NA - cs:cs', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'Prot 16 EO,L-1,NA - cs_base:cs_base', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'Prot 16 EO,L-1,NA - cs_limit:cs_lim', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'Prot 16 EO,L-1,NA - cs_attr:cs_attr', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 0,0,0,0 ; terminator
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'RM Post EO,L-1,NA - cs:cs', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'RM Post EO,L-1,NA - cs_base:cs_base', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'RM Post EO,L-1,NA - cs_limit:cs_lim', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'RM Post EO,L-1,NA - cs_attr:cs_attr', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 0,0,0,0 ; terminator
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync.s_szzRMEO2:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'RM CS(0) EO,L-1 - cs:cs', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'RM CS(0) EO,L-1 - cs_base:cs_base', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'RM CS(0) EO,L-1 - cs_limit:cs_lim', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'RM CS(0) EO,L-1 - cs_attr:cs_attr', 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 0,0,0,0 ; terminator
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db 'Real Mode Test', 0
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncENDPROC rmTests
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; Instantiate the template code.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%include "bootsector2-template-footer.mac" ; reset the initial environemnt.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%define TMPL_RM
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%include "bootsector2-cpu-hidden-regs-1-template.mac"
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;%define TMPL_CMN_V86
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;%include "bootsector2-cpu-hidden-regs-1-template.mac"
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%define TMPL_PE16
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%include "bootsector2-cpu-hidden-regs-1-template.mac"
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%define TMPL_PE32
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%include "bootsector2-cpu-hidden-regs-1-template.mac"
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;%define TMPL_PP16
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;%include "bootsector2-cpu-hidden-regs-1-template.mac"
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%define TMPL_PP32
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%include "bootsector2-cpu-hidden-regs-1-template.mac"
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;%define TMPL_PAE16
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;%include "bootsector2-cpu-hidden-regs-1-template.mac"
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;%define TMPL_PAE32
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;%include "bootsector2-cpu-hidden-regs-1-template.mac"
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;%define TMPL_LM16
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;%include "bootsector2-cpu-hidden-regs-1-template.mac"
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;%define TMPL_LM32
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;%include "bootsector2-cpu-hidden-regs-1-template.mac"
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%define TMPL_LM64
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%include "bootsector2-cpu-hidden-regs-1-template.mac"
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; End sections and image.