VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Thunk/EfiThunk.asm@ 23979

Last change on this file since 23979 was 23400, checked in by vboxsync, 15 years ago

Filemuncher fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.2 KB
Line 
1; $Id: EfiThunk.asm 23400 2009-09-29 09:02:40Z vboxsync $
2;; @file
3; 16-bit EFI Thunk - 16-bit code executed immediately after CPU startup/reset,
4; performs minimal setup, switches CPU to 32-bit mode
5; and passes control to the 32-bit firmware entry point
6;
7;; @todo yasm 0.8.0 got binary sections which could simplify things in this file,
8; see: http://www.tortall.net/projects/yasm/manual/html/manual.html#objfmt-bin-section
9
10;
11; Copyright (C) 2009 Sun Microsystems, Inc.
12;
13; This file is part of VirtualBox Open Source Edition (OSE), as
14; available from http://www.virtualbox.org. This file is free software;
15; you can redistribute it and/or modify it under the terms of the GNU
16; General Public License (GPL) as published by the Free Software
17; Foundation, in version 2 as it comes in the "COPYING" file of the
18; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
19; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
20;
21; Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
22; Clara, CA 95054 USA or visit http://www.sun.com if you need
23; additional information or have any questions.
24;
25
26;*******************************************************************************
27;* Defined Constants And Macros *
28;*******************************************************************************
29;; we'll use no more than 128 vectors atm
30%define IDT_VECTORS 128
31;; keep in sync with actual GDT size
32%define GDT_SELECTORS 7
33
34
35;*******************************************************************************
36;* Header Files *
37;*******************************************************************************
38%include "VBox/asmdefs.mac"
39%include "VBox/x86.mac"
40%include "DevEFI.mac"
41
42;
43; 0xfffff000/0xf000 - Where we start.
44;
45 ORG 0xf000
46
47;
48; 0xfffff000/0xf000 - Parameters passed by DevEFI, DEVEFIINFO.
49;
50DevEfiParameters:
51 times DEVEFIINFO_size db 0
52
53;
54; The IDT.
55; The first 16 vectors have dedicated handlers to ease debugging.
56; The remaining uses a common handler.
57;
58align 16
59efi_thunk_IDT:
60%assign i 0
61%rep 16
62 dw Trap_ %+ i, 0x10, 0x8e00, 0xffff
63 %assign i i+1
64%endrep
65 times IDT_VECTORS-16 dw DefaultTrap, 0x10, 0x8e00, 0xffff
66
67
68;
69; The GDT.
70; Note! Keep this in sync with GDT_SELECTORS.
71;
72align 16
73efi_thunk_GDT:
74 dw 0, 0, 0, 0 ; null selector
75 dw 0, 0, 0, 0 ; ditto
76 dw 0xffff, 0, 0x9b00, 0x00cf ; 32 bit flat code segment (0x10)
77 dw 0xffff, 0, 0x9300, 0x00cf ; 32 bit flat data segment (0x18)
78 dw 0xffff, 0, 0x9b00, 0x0000 ; 16 bit code segment base=0xf0000 limit=0xffff - FIXME: the base is 0, not f0000 here.
79 dw 0xffff, 0, 0x9300, 0x0000 ; 16 bit data segment base=0x0 limit=0xffff - FIXME: ditto.
80 dw 0xffff, 0, 0x9300, 0x00cf ; 32 bit flat stack segment (0x30)
81
82;; For lidt
83efi_thunk_idtr:
84 dw 8*IDT_VECTORS-1 ; limit 15:00
85 dw efi_thunk_IDT ; base 15:00
86 db 0x0f ; base 23:16
87 db 0x00 ; unused
88
89;; For lgdt
90efi_thunk_gdtr:
91 dw 8*GDT_SELECTORS-1 ; limit 15:00
92 dw efi_thunk_GDT ; base 15:00
93 db 0x0f ; base 23:16
94 db 0x00 ; unused
95
96
97BITS 32
98
99;;
100; The default trap/interrupt handler.
101;
102DefaultTrap:
103 push ebp
104 mov ebp, esp
105 mov eax, EFI_PANIC_CMD_THUNK_TRAP
106 mov edx, EFI_PANIC_PORT
107 out dx, al
108 jmp HaltForEver
109
110;;
111; Generate 16 Trap_N handlers that pushes trap number on the stack.
112%assign i 0
113%rep 16
114Trap_ %+ i:
115 push ebp ; Create a valid stackframe for the debugger. (not
116 push byte i ; quite true if there is an error value pushed)
117 jmp CommonTrap
118 %assign i i+1
119%endrep
120
121;;
122; Common trap handler for the 16 dedicated ones.
123;
124CommonTrap:
125 lea ebp, [esp + 4] ; stack frame part 2.
126 push edx
127 push eax
128 mov edx, EFI_PANIC_PORT
129 mov eax, EFI_PANIC_CMD_THUNK_TRAP
130 out dx, al
131
132HaltForEver:
133 cli
134 hlt
135 jmp short HaltForEver ; In case of NMI.
136
137BITS 16
138;;
139; This is the place where we jump immediately after boot and
140; switch the CPU into protected mode.
141;
142genesis:
143%ifdef DISABLED_CODE
144 ; Say 'Hi' to the granny!
145 mov al, 0x41
146 mov dx, EFI_DEBUG_PORT
147 out dx, al
148%endif
149 cli ; paranoia
150
151
152 ; enable a20
153 in al, 0x92
154 or al, 0x02
155 out 0x92, al
156
157 ; check that we loaded in the right place
158 cmp word [cs:efi_thunk_gdtr], 8*GDT_SELECTORS-1
159 je load_ok
160 ; panic if our offset is wrong, which most likely means invalid ORG
161 mov ax, EFI_PANIC_CMD_BAD_ORG
162 mov dx, EFI_PANIC_PORT
163 out dx, al
164load_ok:
165
166 ; load IDTR and GDTR.
167 cs lidt [efi_thunk_idtr]
168 cs lgdt [efi_thunk_gdtr]
169
170 ; set PE bit in CR0, not paged
171 mov eax, cr0
172 or al, X86_CR0_PE
173 mov cr0, eax
174
175 ; start protected mode code: ljmpl 0x10:code_32
176 db 0x66, 0xea
177 dw code_32 ; low offset word
178 dw 0xffff ; high offset word
179 dw 0x0010 ; protected mode CS selector
180
181 ;
182 ; At this point we're in 32-bit protected mode
183 ;
184BITS 32
185code_32:
186 ; load some segments
187 mov ax, 0x18 ; Flat 32-bit data segment
188 mov ds, ax
189 mov es, ax
190 mov ax, 0x30 ; Flat 32-bit stack segment
191 mov ss, ax
192 ; load the null selector into FS/GS (catches unwanted accesses)
193 xor ax, ax
194 mov gs, ax
195 mov fs, ax
196
197 ;
198 ; Switch stack, have it start at the last page before 2M
199 ;
200 mov esp, 0x200000 - 0x10
201
202 ;
203 ; Jump to 32-bit entry point of the firmware, interrupts still disabled.
204 ;
205 ; It's up to the firmware init code to setup a working IDT (and optionally
206 ; GDT and TSS) before enabling interrupts. It may also switch the stack
207 ; around all it wants for all we care.
208 ;
209 mov ebp, [0xfffff000 + DEVEFIINFO.PhysFwVol]
210 mov esi, [0xfffff000 + DEVEFIINFO.pfnFirmwareEP]
211 mov edi, [0xfffff000 + DEVEFIINFO.pfnPeiEP]
212 jmp [0xfffff000 + DEVEFIINFO.pfnFirmwareEP]
213 jmp HaltForEver
214
215 ;
216 ; 0xfffffff0/0xfff0 - This is where the CPU starts executing.
217 ;
218 ;; @todo yasm 0.8.0: SECTION .text start=0fff0h vstart=0fff0h ?
219 times 0xff0-$+DevEfiParameters db 0cch ; Note! $ isn't moved by ORG (yasm v0.6.2).
220cpu_start:
221 BITS 16
222 jmp genesis
223 times (16 - 3) db 0cch
224
225end:
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