source: mainline/kernel/arch/ia32/src/boot/boot.S@ 3f085132

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3f085132 was 5328d63, checked in by Jakub Jermar <jakub@…>, 16 years ago

Do not insist on SYSENTER support.

  • Property mode set to 100644
File size: 5.0 KB
Line 
1#
2# Copyright (c) 2001-2004 Jakub Jermar
3# Copyright (c) 2005-2006 Martin Decky
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9#
10# - Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer.
12# - Redistributions in binary form must reproduce the above copyright
13# notice, this list of conditions and the following disclaimer in the
14# documentation and/or other materials provided with the distribution.
15# - The name of the author may not be used to endorse or promote products
16# derived from this software without specific prior written permission.
17#
18# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28#
29
30#include <arch/boot/boot.h>
31#include <arch/boot/memmap.h>
32#include <arch/mm/page.h>
33#include <arch/pm.h>
34#include <arch/cpuid.h>
35
36#define START_STACK (BOOT_OFFSET - BOOT_STACK_SIZE)
37
38.section K_TEXT_START, "ax"
39
40.code32
41.align 4
42.global multiboot_image_start
43multiboot_header:
44 .long MULTIBOOT_HEADER_MAGIC
45 .long MULTIBOOT_HEADER_FLAGS
46 .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) # checksum
47 .long multiboot_header
48 .long unmapped_ktext_start
49 .long 0
50 .long 0
51 .long multiboot_image_start
52
53multiboot_image_start:
54 cld
55 movl $START_STACK, %esp # initialize stack pointer
56 lgdt KA2PA(bootstrap_gdtr) # initialize Global Descriptor Table register
57
58 movw $gdtselector(KDATA_DES), %cx
59 movw %cx, %es
60 movw %cx, %fs
61 movw %cx, %gs
62 movw %cx, %ds # kernel data + stack
63 movw %cx, %ss
64
65 jmpl $gdtselector(KTEXT_DES), $multiboot_meeting_point
66 multiboot_meeting_point:
67
68 movl %eax, grub_eax # save parameters from GRUB
69 movl %ebx, grub_ebx
70
71 movl $(INTEL_CPUID_LEVEL), %eax
72 cpuid
73 cmp $0x0, %eax # any function > 0?
74 jbe pse_unsupported
75
76 movl $(INTEL_CPUID_STANDARD), %eax
77 cpuid
78 bt $(INTEL_PSE), %edx
79 jc pse_supported
80
81 pse_unsupported:
82 movl $pse_msg, %esi
83 jmp error_halt
84
85 pse_supported:
86
87#include "vesa_prot.inc"
88
89 # map kernel and turn paging on
90 call map_kernel
91
92 # call arch_pre_main(grub_eax, grub_ebx)
93 pushl grub_ebx
94 pushl grub_eax
95 call arch_pre_main
96
97 call main_bsp
98
99 # not reached
100 cli
101 hlt0:
102 hlt
103 jmp hlt0
104
105.global map_kernel
106map_kernel:
107 #
108 # Here we setup mapping for both the unmapped and mapped sections of the kernel.
109 # For simplicity, we map the entire 4G space.
110 #
111 movl %cr4, %ecx
112 orl $(1 << 4), %ecx # turn PSE on
113 andl $(~(1 << 5)), %ecx # turn PAE off
114 movl %ecx, %cr4
115
116 movl $(page_directory + 0), %esi
117 movl $(page_directory + 2048), %edi
118 xorl %ecx, %ecx
119 xorl %ebx, %ebx
120
121 floop:
122 movl $((1 << 7) | (1 << 1) | (1 << 0)), %eax
123 orl %ebx, %eax
124 movl %eax, (%esi, %ecx, 4) # mapping 0x00000000 + %ecx * 4M => 0x00000000 + %ecx * 4M
125 movl %eax, (%edi, %ecx, 4) # mapping 0x80000000 + %ecx * 4M => 0x00000000 + %ecx * 4M
126 addl $(4 * 1024 * 1024), %ebx
127
128 incl %ecx
129 cmpl $512, %ecx
130 jl floop
131
132 movl %esi, %cr3
133
134 movl %cr0, %ebx
135 orl $(1 << 31), %ebx # turn paging on
136 movl %ebx, %cr0
137 ret
138
139# Print string from %esi to EGA display (in red) and halt
140error_halt:
141 movl $0xb8000, %edi # base of EGA text mode memory
142 xorl %eax, %eax
143
144 movw $0x3d4, %dx # read bits 8 - 15 of the cursor address
145 movb $0xe, %al
146 outb %al, %dx
147
148 movw $0x3d5, %dx
149 inb %dx, %al
150 shl $8, %ax
151
152 movw $0x3d4, %dx # read bits 0 - 7 of the cursor address
153 movb $0xf, %al
154 outb %al, %dx
155
156 movw $0x3d5, %dx
157 inb %dx, %al
158
159 cmp $1920, %ax
160 jbe cursor_ok
161
162 movw $1920, %ax # sanity check for the cursor on the last line
163
164 cursor_ok:
165
166 movw %ax, %bx
167 shl $1, %eax
168 addl %eax, %edi
169
170 movw $0x0c00, %ax # black background, light red foreground
171
172 ploop:
173 lodsb
174 cmp $0, %al
175 je ploop_end
176 stosw
177 inc %bx
178 jmp ploop
179 ploop_end:
180
181 movw $0x3d4, %dx # write bits 8 - 15 of the cursor address
182 movb $0xe, %al
183 outb %al, %dx
184
185 movw $0x3d5, %dx
186 movb %bh, %al
187 outb %al, %dx
188
189 movw $0x3d4, %dx # write bits 0 - 7 of the cursor address
190 movb $0xf, %al
191 outb %al, %dx
192
193 movw $0x3d5, %dx
194 movb %bl, %al
195 outb %al, %dx
196
197 cli
198 hlt1:
199 hlt
200 jmp hlt1
201
202#include "vesa_real.inc"
203
204.section K_DATA_START, "aw", @progbits
205
206.align 4096
207page_directory:
208 .space 4096, 0
209
210grub_eax:
211 .long 0
212
213grub_ebx:
214 .long 0
215
216pse_msg:
217 .asciz "Page Size Extension not supported. System halted."
218
Note: See TracBrowser for help on using the repository browser.