Rev 1809 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1809 | Rev 1810 | ||
---|---|---|---|
Line 37... | Line 37... | ||
37 | .ascii "HYPERCALL_PAGE=0x2," |
37 | .ascii "HYPERCALL_PAGE=0x2," |
38 | .ascii "LOADER=generic," |
38 | .ascii "LOADER=generic," |
39 | .ascii "PT_MODE_WRITABLE" |
39 | .ascii "PT_MODE_WRITABLE" |
40 | .byte 0 |
40 | .byte 0 |
41 | 41 | ||
42 | .section K_TEXT_START, "ax" |
- | |
43 | - | ||
44 | KTEXT=8 |
42 | .text |
45 | KDATA=16 |
- | |
46 | 43 | ||
47 | .code32 |
44 | .code32 |
48 | .align 4 |
45 | .align 4 |
49 | .global kernel_image_start |
46 | .global kernel_image_start |
50 | 47 | ||
51 | kernel_image_start: |
48 | kernel_image_start: |
52 | lgdt KA2PA(bootstrap_gdtr) # initialize Global Descriptor Table register |
- | |
53 | - | ||
54 | movw $KDATA, %cx |
- | |
55 | movw %cx, %es |
- | |
56 | movw %cx, %fs |
- | |
57 | movw %cx, %gs |
- | |
58 | movw %cx, %ds # kernel data + stack |
- | |
59 | movw %cx, %ss |
- | |
60 | - | ||
61 | jmpl $KTEXT, $multiboot_meeting_point |
- | |
62 | multiboot_meeting_point: |
- | |
63 | - | ||
64 | pushl %ebx # save parameters from GRUB |
- | |
65 | pushl %eax |
- | |
66 | - | ||
67 | #ifdef CONFIG_FB |
- | |
68 | mov $vesa_init, %esi |
- | |
69 | mov $VESA_INIT_SEGMENT << 4, %edi |
- | |
70 | mov $e_vesa_init - vesa_init, %ecx |
- | |
71 | cld |
49 | cld |
72 | rep movsb |
- | |
73 | - | ||
74 | mov $VESA_INIT_SEGMENT << 4, %edi |
- | |
75 | jmpl %edi |
- | |
76 | - | ||
77 | vesa_meeting_point: |
- | |
78 | - | ||
79 | mov %esi, KA2PA(vesa_ph_addr) |
- | |
80 | mov %di, KA2PA(vesa_height) |
- | |
81 | shr $16, %edi |
- | |
82 | mov %di, KA2PA(vesa_width) |
- | |
83 | mov %bx, KA2PA(vesa_scanline) |
- | |
84 | shr $16, %ebx |
- | |
85 | mov %bx, KA2PA(vesa_bpp) |
- | |
86 | #endif |
- | |
87 | - | ||
88 | call map_kernel # map kernel and turn paging on |
50 | movl $kernel_stack, %esp # initialize stack pointer |
89 | - | ||
90 | popl %eax |
- | |
91 | popl %ebx |
- | |
92 | 51 | ||
93 | call main_bsp # never returns |
52 | call main_bsp # never returns |
94 | 53 | ||
95 | cli |
54 | cli |
96 | hlt |
55 | hlt |
97 | 56 | ||
98 | .global map_kernel |
- | |
99 | map_kernel: |
- | |
100 | # |
- | |
101 | # Here we setup mapping for both the unmapped and mapped sections of the kernel. |
- | |
102 | # For simplicity, we map the entire 4G space. |
- | |
103 | # |
- | |
104 | movl %cr4, %ecx |
- | |
105 | orl $(1<<4), %ecx |
- | |
106 | movl %ecx, %cr4 # turn PSE on |
- | |
107 | - | ||
108 | movl $(page_directory+0), %esi |
- | |
109 | movl $(page_directory+2048), %edi |
- | |
110 | xorl %ecx, %ecx |
- | |
111 | xorl %ebx, %ebx |
- | |
112 | 0: |
- | |
113 | movl $((1<<7)|(1<<0)), %eax |
- | |
114 | orl %ebx, %eax |
- | |
115 | movl %eax, (%esi,%ecx,4) # mapping 0x00000000+%ecx*4M => 0x00000000+%ecx*4M |
- | |
116 | movl %eax, (%edi,%ecx,4) # mapping 0x80000000+%ecx*4M => 0x00000000+%ecx*4M |
- | |
117 | addl $(4*1024*1024), %ebx |
- | |
118 | - | ||
119 | incl %ecx |
- | |
120 | cmpl $512, %ecx |
- | |
121 | jl 0b |
- | |
122 | - | ||
123 | movl %esi, %cr3 |
- | |
124 | - | ||
125 | # turn paging on |
- | |
126 | movl %cr0, %ebx |
- | |
127 | orl $(1<<31), %ebx |
- | |
128 | movl %ebx, %cr0 |
- | |
129 | ret |
57 | .data |
130 | - | ||
131 | #ifdef CONFIG_FB |
- | |
132 | vesa_init: |
- | |
133 | jmp $selector(VESA_INIT_DES), $vesa_init_real - vesa_init |
- | |
134 | - | ||
135 | .code16 |
- | |
136 | vesa_init_real: |
- | |
137 | - | ||
138 | mov %cr0, %eax |
- | |
139 | and $~1, %eax |
- | |
140 | mov %eax, %cr0 |
- | |
141 | - | ||
142 | jmp $VESA_INIT_SEGMENT, $vesa_init_real2 - vesa_init |
- | |
143 | - | ||
144 | vesa_init_real2: |
- | |
145 | - | ||
146 | mov $VESA_INIT_SEGMENT, %bx |
- | |
147 | - | ||
148 | mov %bx, %es |
- | |
149 | mov %bx, %fs |
- | |
150 | mov %bx, %gs |
- | |
151 | mov %bx, %ds |
- | |
152 | mov %bx, %ss |
- | |
153 | - | ||
154 | movl %esp, %eax |
- | |
155 | movl $0x0000fffc, %esp |
- | |
156 | movl $0x0000fffc, %ebp |
- | |
157 | pushl %eax |
- | |
158 | - | ||
159 | #define VESA_INFO_SIZE 1024 |
- | |
160 | - | ||
161 | #define VESA_MODE_LIST_PTR_OFFSET 14 |
- | |
162 | #define VESA_MODE_WIDTH_OFFSET 18 |
- | |
163 | #define VESA_MODE_HEIGHT_OFFSET 20 |
- | |
164 | #define VESA_MODE_BPP_OFFSET 25 |
- | |
165 | #define VESA_MODE_SCANLINE_OFFSET 16 |
- | |
166 | #define VESA_MODE_PHADDR_OFFSET 40 |
- | |
167 | - | ||
168 | #define VESA_END_OF_MODES 0xffff |
- | |
169 | - | ||
170 | #define VESA_OK 0x4f |
- | |
171 | - | ||
172 | #define VESA_GET_INFO 0x4f00 |
- | |
173 | #define VESA_GET_MODE_INFO 0x4f01 |
- | |
174 | #define VESA_SET_MODE 0x4f02 |
- | |
175 | - | ||
176 | #define CONFIG_VESA_BPP_a 255 |
- | |
177 | - | ||
178 | #if CONFIG_VESA_BPP == 24 |
- | |
179 | #undef CONFIG_VESA_BPP_a |
- | |
180 | #define CONFIG_VESA_BPP_a 32 |
- | |
181 | #endif |
- | |
182 | - | ||
183 | mov $VESA_GET_INFO, %ax |
- | |
184 | mov $e_vesa_init - vesa_init, %di |
- | |
185 | push %di |
- | |
186 | int $0x10 |
- | |
187 | - | ||
188 | pop %di |
- | |
189 | cmp $VESA_OK, %al |
- | |
190 | jnz 0f |
- | |
191 | - | ||
192 | mov 2 + VESA_MODE_LIST_PTR_OFFSET(%di), %si |
- | |
193 | mov %si, %gs |
- | |
194 | mov VESA_MODE_LIST_PTR_OFFSET(%di), %si |
- | |
195 | - | ||
196 | add $VESA_INFO_SIZE, %di |
- | |
197 | - | ||
198 | 1:# Try next mode |
- | |
199 | mov %gs:(%si), %cx |
- | |
200 | cmp $VESA_END_OF_MODES, %cx |
- | |
201 | jz 0f |
- | |
202 | - | ||
203 | inc %si |
- | |
204 | inc %si |
- | |
205 | push %cx |
- | |
206 | push %di |
- | |
207 | push %si |
- | |
208 | mov $VESA_GET_MODE_INFO, %ax |
- | |
209 | int $0x10 |
- | |
210 | - | ||
211 | pop %si |
- | |
212 | pop %di |
- | |
213 | pop %cx |
- | |
214 | cmp $VESA_OK, %al |
- | |
215 | jnz 0f |
- | |
216 | - | ||
217 | mov $CONFIG_VESA_WIDTH, %ax |
- | |
218 | cmp VESA_MODE_WIDTH_OFFSET(%di), %ax |
- | |
219 | jnz 1b |
- | |
220 | - | ||
221 | mov $CONFIG_VESA_HEIGHT,%ax |
- | |
222 | cmp VESA_MODE_HEIGHT_OFFSET(%di), %ax |
- | |
223 | jnz 1b |
- | |
224 | - | ||
225 | mov $CONFIG_VESA_BPP, %al |
- | |
226 | cmp VESA_MODE_BPP_OFFSET(%di), %al |
- | |
227 | jz 2f |
- | |
228 | - | ||
229 | mov $CONFIG_VESA_BPP_a, %al |
- | |
230 | cmp VESA_MODE_BPP_OFFSET(%di), %al |
- | |
231 | jnz 1b |
- | |
232 | - | ||
233 | 2: |
- | |
234 | - | ||
235 | mov %cx, %bx |
- | |
236 | or $0xc000, %bx |
- | |
237 | push %di |
- | |
238 | mov $VESA_SET_MODE, %ax |
- | |
239 | int $0x10 |
- | |
240 | - | ||
241 | pop %di |
- | |
242 | cmp $VESA_OK, %al |
- | |
243 | jnz 0f |
- | |
244 | - | ||
245 | mov VESA_MODE_PHADDR_OFFSET(%di), %esi |
- | |
246 | mov VESA_MODE_WIDTH_OFFSET(%di), %ax |
- | |
247 | shl $16, %eax |
- | |
248 | mov VESA_MODE_HEIGHT_OFFSET(%di), %ax |
- | |
249 | mov VESA_MODE_BPP_OFFSET(%di), %bl |
- | |
250 | xor %bh, %bh |
- | |
251 | shl $16, %ebx |
- | |
252 | mov VESA_MODE_SCANLINE_OFFSET(%di), %bx |
- | |
253 | mov %eax, %edi |
- | |
254 | - | ||
255 | 8: |
- | |
256 | - | ||
257 | mov %cr0, %eax |
- | |
258 | or $1, %eax |
- | |
259 | mov %eax, %cr0 |
- | |
260 | - | ||
261 | jmp 9f |
- | |
262 | 9: |
- | |
263 | - | ||
264 | ljmpl $KTEXT, $(vesa_init_protect - vesa_init + VESA_INIT_SEGMENT << 4) |
- | |
265 | - | ||
266 | 0:# No prefered mode found |
- | |
267 | mov $0x111, %cx |
- | |
268 | push %di |
- | |
269 | push %cx |
- | |
270 | mov $VESA_GET_MODE_INFO, %ax |
- | |
271 | int $0x10 |
- | |
272 | - | ||
273 | pop %cx |
- | |
274 | pop %di |
- | |
275 | cmp $VESA_OK, %al |
- | |
276 | jnz 1f |
- | |
277 | jz 2b # Force relative jump |
- | |
278 | - | ||
279 | 1: |
- | |
280 | mov $0x0003, %ax |
- | |
281 | int $0x10 |
- | |
282 | mov $0xffffffff, %edi # EGA text mode used, because of problems with VESA |
- | |
283 | xor %ax, %ax |
- | |
284 | jz 8b # Force relative jump |
- | |
285 | - | ||
286 | - | ||
287 | .code32 |
- | |
288 | vesa_init_protect: |
- | |
289 | popl %esp |
- | |
290 | - | ||
291 | movw $KDATA, %cx |
- | |
292 | movw %cx, %es |
- | |
293 | movw %cx, %fs |
- | |
294 | movw %cx, %gs |
- | |
295 | movw %cx, %ds # kernel data + stack |
- | |
296 | movw %cx, %ss |
- | |
297 | - | ||
298 | jmpl $KTEXT, $vesa_meeting_point |
- | |
299 | - | ||
300 | .align 4 |
- | |
301 | e_vesa_init: |
- | |
302 | #endif |
- | |
303 | - | ||
304 | .section K_DATA_START, "aw", @progbits |
- | |
305 | 58 | ||
306 | .align 4096 |
59 | .align 4096 |
307 | page_directory: |
60 | page_directory: |
308 | .space 4096, 0 |
61 | .space 4096, 0 |
- | 62 | ||
- | 63 | kernel_stack_bottom: |
|
- | 64 | .space TEMP_STACK_SIZE |
|
- | 65 | kernel_stack: |