VirtualBox

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

Last change on this file since 66145 was 66145, checked in by vboxsync, 8 years ago

bootsectors: Relocated shutdown port.

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