1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include "optionrom.h"
25
26#define BOOT_ROM_PRODUCT "PVH loader"
27
28#define GS_PROT_JUMP 0
29#define GS_GDT_DESC 6
30
31#ifdef OPTION_ROM_START
32#undef OPTION_ROM_START
33#endif
34#ifdef OPTION_ROM_END
35#undef OPTION_ROM_END
36#endif
37
38
39
40
41
42
43#define OPTION_ROM_START \
44 .code16; \
45 .text; \
46 .global _start; \
47 _start:; \
48 .short 0xaa55; \
49 .byte 3;
50
51#define OPTION_ROM_END \
52 _end:
53
54BOOT_ROM_START
55
56run_pvhboot:
57
58 cli
59 cld
60
61 mov %cs, %eax
62 shl $0x4, %eax
63
64
65
66
67 mov %ss, %ecx
68 shl $0x4, %ecx
69 mov %esp, %ebx
70 add %ebx, %ecx
71 sub $0x20, %ecx
72 sub $0x30, %esp
73 shr $0x4, %ecx
74 mov %cx, %gs
75
76
77 mov (prot_jump), %ebx
78 add %eax, %ebx
79 movl %ebx, %gs:GS_PROT_JUMP
80 mov $8, %bx
81 movw %bx, %gs:GS_PROT_JUMP + 4
82
83
84 movw (gdt_desc), %bx
85 movw %bx, %gs:GS_GDT_DESC
86 movl (gdt_desc+2), %ebx
87 add %eax, %ebx
88 movl %ebx, %gs:GS_GDT_DESC + 2
89
90
91
92
93 mov $pvh_e820, %eax
94 shr $4, %eax
95 mov %ax, %es
96
97
98 mov $8,%edi
99 xor %ebx, %ebx
100 jmp memmap_loop
101
102memmap_loop_check:
103
104 cmp $128, %ebx
105 je memmap_done
106
107memmap_loop:
108
109 movl $24, %ecx
110
111 movl $0x0000e820, %eax
112
113 movl $0x534d4150, %edx
114
115 movl %ebx, %es:0
116
117 int $0x15
118
119 jb memmap_err
120
121
122 add $24, %edi
123
124
125 test %ebx, %ebx
126 jnz memmap_loop_check
127
128
129 movl %es:0, %ebx
130 inc %ebx
131
132memmap_done:
133 movl %ebx, %es:0
134
135memmap_err:
136
137
138lgdt:
139 data32 lgdt %gs:GS_GDT_DESC
140
141
142 movl $1, %eax
143 movl %eax, %cr0
144
145
146ljmp:
147 data32 ljmp *%gs:GS_PROT_JUMP
148
149prot_mode:
150.code32
151
152
153 movl $0x10, %eax
154 movl %eax, %ss
155 movl %eax, %ds
156 movl %eax, %es
157 movl %eax, %fs
158 movl %eax, %gs
159
160 jmp pvh_load_kernel
161
162
163.align 4, 0
164prot_jump: .long prot_mode
165 .short 8
166
167.align 4, 0
168gdt:
169
170.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
171
172
173
174
175
176.byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x9a, 0xcf, 0x00
177
178
179
180
181
182.byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x92, 0xcf, 0x00
183
184
185
186
187
188.byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x9e, 0x00, 0x00
189
190
191
192
193
194.byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x92, 0x00, 0x00
195
196gdt_desc:
197.short (5 * 8) - 1
198.long gdt
199
200BOOT_ROM_END
201