cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; $Id$
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;; @file
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; bootsector2 common routines - template containing code specific to each mode.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; Copyright (C) 2007-2014 Oracle Corporation
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;
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;
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;
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;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%include "bootsector2-template-header.mac"
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncALIGNCODE(32)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncGLOBALNAME TMPL_NM(g_szMode)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync db TMPL_MODE_STR, 0
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; Prints a string on the screen.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; @param ds:ax The string to print (null terminated).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; @uses nothing
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncBEGINPROC TMPL_NM(PrintStr)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync push xBP
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov xBP, xSP
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync push xAX
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync push xBX
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync push xSI
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov xSI, xAX
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync.next:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync lodsb
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync test al, al
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync jz .done
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%ifdef TMPL_HAVE_BIOS
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov bx, 0ff00h
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov ah, 0eh
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync int 10h
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%else
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call TMPL_NM(PrintChr)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%endif
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync jmp .next
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync.done:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync pop xSI
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync pop xBX
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync pop xAX
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync leave
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ret
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncENDPROC TMPL_NM(PrintStr)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; Prints a string on the screen.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; @param al The character to print.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; @uses nothing
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncBEGINCODELOW
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncBEGINPROC TMPL_NM(PrintChr)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync push xBP
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov xBP, xSP
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync push xAX
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync push xBX
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%ifndef TMPL_HAVE_BIOS
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %ifdef BS2_WITH_TRAPS
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov bx, cs
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and xBX, 0x3
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync push xBX
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync jz .ring_ok
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call TMPL_NM_CMN(Bs2ToRing0)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync.ring_ok:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %endif
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov bl, al
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call TMPL_NM(LeaveCpuMode)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov al, bl
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncBITS 16
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%endif
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov bx, 0ff00h
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov ah, 0eh
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync int 10h
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%ifndef TMPL_HAVE_BIOS
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call TMPL_NM(EnterCpuMode)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncBITS TMPL_BITS
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %ifdef BS2_WITH_TRAPS
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync pop xAX
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync test al, al
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync jz .ring_restored
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync call TMPL_NM_CMN(Bs2ToRingN)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync.ring_restored:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %endif
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%endif
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync pop xBX
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync pop xAX
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync leave
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ret
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncENDPROC TMPL_NM(PrintChr)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncTMPL_BEGINCODE
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%ifndef TMPL_HAVE_BIOS
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; Leaves the current CPU mode and returns to real mode.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; @uses nothing
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncBEGINPROC TMPL_NM(LeaveCpuMode)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync jmp TMPL_NM(Bs2ExitMode)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncENDPROC TMPL_NM(LeaveCpuMode)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; Undo what LeaveCpuMode did.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; @uses nothing
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncBEGINCODELOW
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncBITS 16
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncBEGINPROC TMPL_NM(EnterCpuMode)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync jmp TMPL_NM(Bs2EnterMode_rm)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncENDPROC TMPL_NM(EnterCpuMode)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncTMPL_BEGINCODE
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncBITS TMPL_BITS
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%endif ; TMPL_HAVE_BIOS
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; Sets the global variable for the current CPU mode.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync; @uses nothing.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncBEGINPROC TMPL_NM(SetCpuModeGlobals)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%ifdef TMPL_CMN_PE
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %ifdef BS2_INC_PE16
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov word [g_pfnPrintStrInternal_p16], PrintStr_pe16
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov word [g_pfnPrintChrInternal_p16], PrintChr_pe16
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %endif
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %ifdef BS2_INC_PE32
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov dword [g_pfnPrintStrInternal_p32], PrintStr_pe32
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov dword [g_pfnPrintChrInternal_p32], PrintChr_pe32
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %endif
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%elifdef TMPL_CMN_PP
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %ifdef BS2_INC_PP16
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov word [g_pfnPrintStrInternal_p16], PrintStr_pp16
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov word [g_pfnPrintChrInternal_p16], PrintChr_pp16
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %endif
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %ifdef BS2_INC_PP32
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov dword [g_pfnPrintStrInternal_p32], PrintStr_pp32
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov dword [g_pfnPrintChrInternal_p32], PrintChr_pp32
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %endif
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%elifdef TMPL_CMN_PAE
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %ifdef BS2_INC_PAE16
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov word [g_pfnPrintStrInternal_p16], PrintStr_pae16
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov word [g_pfnPrintChrInternal_p16], PrintChr_pae16
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %endif
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %ifdef BS2_INC_PAE32
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov dword [g_pfnPrintStrInternal_p32], PrintStr_pae32
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov dword [g_pfnPrintChrInternal_p32], PrintChr_pae32
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %endif
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%elifdef TMPL_CMN_LM
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %ifdef BS2_INC_LM16
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov word [g_pfnPrintStrInternal_p16], PrintStr_lm16
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov word [g_pfnPrintChrInternal_p16], PrintChr_lm16
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %endif
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %ifdef BS2_INC_LM32
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov dword [g_pfnPrintStrInternal_p32], PrintStr_lm32
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov dword [g_pfnPrintChrInternal_p32], PrintChr_lm32
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %endif
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %ifdef BS2_INC_LM64
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov dword [g_pfnPrintStrInternal_p64], PrintStr_lm64
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov dword [g_pfnPrintChrInternal_p64], PrintChr_lm64
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %endif
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%elifdef TMPL_16BIT
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov word [TMPL_NM_CMN(g_pfnPrintStrInternal)], TMPL_NM(PrintStr)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov word [TMPL_NM_CMN(g_pfnPrintChrInternal)], TMPL_NM(PrintChr)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%else
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync %error "missing case"
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%endif
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ret
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncENDPROC TMPL_NM(SetCpuModeGlobals)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync%include "bootsector2-template-footer.mac"
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync