VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bootsector-pae.asm@ 100714

Last change on this file since 100714 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 KB
Line 
1; $Id: bootsector-pae.asm 98103 2023-01-17 14:15:46Z vboxsync $
2;; @file
3; Bootsector that switches the CPU info PAE mode.
4;
5
6;
7; Copyright (C) 2007-2023 Oracle and/or its affiliates.
8;
9; This file is part of VirtualBox base platform packages, as
10; available from https://www.virtualbox.org.
11;
12; This program is free software; you can redistribute it and/or
13; modify it under the terms of the GNU General Public License
14; as published by the Free Software Foundation, in version 3 of the
15; License.
16;
17; This program is distributed in the hope that it will be useful, but
18; WITHOUT ANY WARRANTY; without even the implied warranty of
19; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20; General Public License for more details.
21;
22; You should have received a copy of the GNU General Public License
23; along with this program; if not, see <https://www.gnu.org/licenses>.
24;
25; The contents of this file may alternatively be used under the terms
26; of the Common Development and Distribution License Version 1.0
27; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28; in the VirtualBox distribution, in which case the provisions of the
29; CDDL are applicable instead of those of the GPL.
30;
31; You may elect to license modified versions of this file under the
32; terms and conditions of either the GPL or the CDDL or both.
33;
34; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35;
36
37%include "iprt/asmdefs.mac"
38%include "iprt/x86.mac"
39%include "VBox/bios.mac"
40
41
42;; The boot sector load address.
43%define BS_ADDR 0x7c00
44%define PDP_ADDR 0x9000
45%define PD_ADDR 0xa000
46
47
48BITS 16
49start:
50 ; Start with a jump just to follow the convention.
51 jmp short the_code
52 nop
53times 3ah db 0
54
55the_code:
56 cli
57 xor edx, edx
58 mov ds, dx ; Use 0 based addresses
59
60 ;
61 ; Create a paging hierarchy
62 ;
63 mov cx, 4
64 xor esi, esi ; physical address
65 mov ebx, PDP_ADDR
66 mov edi, PD_ADDR
67pdptr_loop:
68 ; The page directory pointer entry.
69 mov dword [ebx], edi
70 or word [bx], X86_PDPE_P
71 mov dword [ebx + 4], edx
72
73 ; The page directory.
74pd_loop:
75 mov dword [edi], esi
76 or word [di], X86_PDE4M_P | X86_PDE4M_RW | X86_PDE4M_PS
77 mov dword [edi + 4], 0
78 add esi, 0x00200000 ; 2MB
79 add di, 8
80 test di, 0fffh
81 jnz pd_loop
82
83 add bx, 8
84 loop pdptr_loop
85
86 ;
87 ; Switch to protected mode.
88 ;
89 lgdt [(gdtr - start) + BS_ADDR]
90 lidt [(idtr_null - start) + BS_ADDR]
91
92 mov eax, PDP_ADDR
93 mov cr3, eax
94
95 mov eax, cr4
96 or eax, X86_CR4_PAE | X86_CR4_PSE
97 mov cr4, eax
98
99 mov eax, cr0
100 or eax, X86_CR0_PE | X86_CR0_PG
101 mov cr0, eax
102 jmp far 0x0008:((code32_start - start) + BS_ADDR) ; 8=32-bit CS
103
104BITS 32
105code32_start:
106 mov ax, 0x10
107 mov ds, ax
108 mov es, ax
109 mov fs, ax
110 mov gs, ax
111 mov ax, 0x18
112 mov es, ax
113 mov esp, 0x80000
114
115 ; eye catchers
116 mov eax, 0xCafeBabe
117 mov ebx, eax
118 mov ecx, eax
119 mov edx, eax
120 mov edi, eax
121 mov esi, eax
122 mov ebp, eax
123
124 ;
125 ; Boch shutdown request.
126 ;
127 mov bl, 64
128 mov dx, VBOX_BIOS_SHUTDOWN_PORT
129 mov ax, VBOX_BIOS_OLD_SHUTDOWN_PORT
130retry:
131 mov ecx, 8
132 mov esi, (szShutdown - start) + BS_ADDR
133 rep outsb
134 xchg dx, ax ; alternate between the new (VBox) and old (Bochs) ports.
135 dec bl
136 jnz retry
137 ; Shutdown failed!
138hlt_again:
139 hlt
140 cli
141 jmp hlt_again
142
143 ;
144 ; The GDT.
145 ;
146align 8, db 0
147gdt:
148 dw 0, 0, 0, 0 ; null selector
149 dw 0xffff, 0, 0x9b00, 0x00cf ; 32 bit flat code segment (0x08)
150 dw 0xffff, 0, 0x9300, 0x00cf ; 32 bit flat data segment (0x10)
151 dw 0xffff, 0, 0x9300, 0x00cf ; 32 bit flat stack segment (0x18)
152
153gdtr:
154 dw 8*4-1 ; limit 15:00
155 dw (gdt - start) + BS_ADDR ; base 15:00
156 db 0 ; base 23:16
157 db 0 ; unused
158
159idtr_null:
160 dw 0 ; limit 15:00
161 dw (gdt - start) + BS_ADDR ; base 15:00
162 db 0 ; base 23:16
163 db 0 ; unused
164
165szShutdown:
166 db 'Shutdown', 0
167
168 ;
169 ; Padd the remainder of the sector with zeros and
170 ; end it with the dos signature.
171 ;
172padding:
173times 510 - (padding - start) db 0
174 db 055h, 0aah
175
Note: See TracBrowser for help on using the repository browser.

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