Rev 3386 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | jermar | 1 | # |
2071 | jermar | 2 | # Copyright (c) 2001-2004 Jakub Jermar |
3 | # Copyright (c) 2005-2006 Martin Decky |
||
1 | jermar | 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 | |||
222 | decky | 30 | #include <arch/boot/boot.h> |
506 | decky | 31 | #include <arch/boot/memmap.h> |
300 | palkovsky | 32 | #include <arch/mm/page.h> |
33 | #include <arch/pm.h> |
||
222 | decky | 34 | |
693 | decky | 35 | #define START_STACK (BOOT_OFFSET - BOOT_STACK_SIZE) |
36 | |||
406 | jermar | 37 | .section K_TEXT_START, "ax" |
1 | jermar | 38 | |
112 | jermar | 39 | .code32 |
222 | decky | 40 | .align 4 |
693 | decky | 41 | .global multiboot_image_start |
222 | decky | 42 | multiboot_header: |
43 | .long MULTIBOOT_HEADER_MAGIC |
||
44 | .long MULTIBOOT_HEADER_FLAGS |
||
4153 | mejdrech | 45 | .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) # checksum |
693 | decky | 46 | .long multiboot_header |
47 | .long unmapped_ktext_start |
||
222 | decky | 48 | .long 0 |
49 | .long 0 |
||
693 | decky | 50 | .long multiboot_image_start |
4153 | mejdrech | 51 | |
222 | decky | 52 | multiboot_image_start: |
2784 | jermar | 53 | cld |
4153 | mejdrech | 54 | movl $START_STACK, %esp # initialize stack pointer |
55 | lgdt KA2PA(bootstrap_gdtr) # initialize Global Descriptor Table register |
||
56 | |||
57 | movw $gdtselector(KDATA_DES), %cx |
||
280 | decky | 58 | movw %cx, %es |
1639 | decky | 59 | movw %cx, %fs |
280 | decky | 60 | movw %cx, %gs |
4153 | mejdrech | 61 | movw %cx, %ds # kernel data + stack |
280 | decky | 62 | movw %cx, %ss |
235 | decky | 63 | |
4153 | mejdrech | 64 | jmpl $gdtselector(KTEXT_DES), $multiboot_meeting_point |
271 | decky | 65 | multiboot_meeting_point: |
66 | |||
4153 | mejdrech | 67 | movl %eax, grub_eax # save parameters from GRUB |
2222 | decky | 68 | movl %ebx, grub_ebx |
1639 | decky | 69 | |
4153 | mejdrech | 70 | xorl %eax, %eax |
71 | cpuid |
||
72 | cmp $0x0, %eax # any function > 0? |
||
2220 | decky | 73 | jbe pse_unsupported |
4153 | mejdrech | 74 | movl $0x1, %eax # basic function code 1 |
2220 | decky | 75 | cpuid |
4153 | mejdrech | 76 | bt $3, %edx # test if PSE is supported |
2220 | decky | 77 | jc pse_supported |
4153 | mejdrech | 78 | |
2220 | decky | 79 | pse_unsupported: |
80 | movl $pse_msg, %esi |
||
81 | jmp error_halt |
||
82 | |||
83 | pse_supported: |
||
1287 | vana | 84 | |
4153 | mejdrech | 85 | #include "vesa_prot.inc" |
86 | |||
87 | # map kernel and turn paging on |
||
88 | call map_kernel |
||
1639 | decky | 89 | |
4153 | mejdrech | 90 | # call arch_pre_main(grub_eax, grub_ebx) |
91 | pushl grub_ebx |
||
92 | pushl grub_eax |
||
93 | call arch_pre_main |
||
1639 | decky | 94 | |
4153 | mejdrech | 95 | call main_bsp |
280 | decky | 96 | |
4153 | mejdrech | 97 | # not reached |
110 | jermar | 98 | cli |
4153 | mejdrech | 99 | hlt0: |
100 | hlt |
||
101 | jmp hlt0 |
||
110 | jermar | 102 | |
103 | .global map_kernel |
||
104 | map_kernel: |
||
105 | jermar | 105 | # |
106 | # Here we setup mapping for both the unmapped and mapped sections of the kernel. |
||
371 | jermar | 107 | # For simplicity, we map the entire 4G space. |
105 | jermar | 108 | # |
109 | movl %cr4, %ecx |
||
4153 | mejdrech | 110 | orl $(1 << 4), %ecx # turn PSE on |
111 | andl $(~(1 << 5)), %ecx # turn PAE off |
||
2220 | decky | 112 | movl %ecx, %cr4 |
1 | jermar | 113 | |
2220 | decky | 114 | movl $(page_directory + 0), %esi |
115 | movl $(page_directory + 2048), %edi |
||
371 | jermar | 116 | xorl %ecx, %ecx |
117 | xorl %ebx, %ebx |
||
4153 | mejdrech | 118 | |
119 | floop: |
||
120 | movl $((1 << 7) | (1 << 1) | (1 << 0)), %eax |
||
121 | orl %ebx, %eax |
||
122 | movl %eax, (%esi, %ecx, 4) # mapping 0x00000000 + %ecx * 4M => 0x00000000 + %ecx * 4M |
||
123 | movl %eax, (%edi, %ecx, 4) # mapping 0x80000000 + %ecx * 4M => 0x00000000 + %ecx * 4M |
||
124 | addl $(4 * 1024 * 1024), %ebx |
||
125 | |||
126 | incl %ecx |
||
127 | cmpl $512, %ecx |
||
128 | jl floop |
||
129 | |||
371 | jermar | 130 | movl %esi, %cr3 |
105 | jermar | 131 | |
132 | movl %cr0, %ebx |
||
4153 | mejdrech | 133 | orl $(1 << 31), %ebx # turn paging on |
105 | jermar | 134 | movl %ebx, %cr0 |
110 | jermar | 135 | ret |
105 | jermar | 136 | |
2220 | decky | 137 | # Print string from %esi to EGA display (in red) and halt |
138 | error_halt: |
||
4153 | mejdrech | 139 | movl $0xb8000, %edi # base of EGA text mode memory |
2220 | decky | 140 | xorl %eax, %eax |
141 | |||
4153 | mejdrech | 142 | movw $0x3d4, %dx # read bits 8 - 15 of the cursor address |
2220 | decky | 143 | movb $0xe, %al |
144 | outb %al, %dx |
||
145 | |||
146 | movw $0x3d5, %dx |
||
147 | inb %dx, %al |
||
148 | shl $8, %ax |
||
149 | |||
4153 | mejdrech | 150 | movw $0x3d4, %dx # read bits 0 - 7 of the cursor address |
2220 | decky | 151 | movb $0xf, %al |
152 | outb %al, %dx |
||
153 | |||
154 | movw $0x3d5, %dx |
||
155 | inb %dx, %al |
||
156 | |||
157 | cmp $1920, %ax |
||
158 | jbe cursor_ok |
||
4153 | mejdrech | 159 | |
160 | movw $1920, %ax # sanity check for the cursor on the last line |
||
161 | |||
2220 | decky | 162 | cursor_ok: |
163 | |||
164 | movw %ax, %bx |
||
165 | shl $1, %eax |
||
166 | addl %eax, %edi |
||
167 | |||
4153 | mejdrech | 168 | movw $0x0c00, %ax # black background, light red foreground |
2220 | decky | 169 | |
170 | ploop: |
||
171 | lodsb |
||
172 | cmp $0, %al |
||
173 | je ploop_end |
||
174 | stosw |
||
4153 | mejdrech | 175 | inc %bx |
2220 | decky | 176 | jmp ploop |
177 | ploop_end: |
||
178 | |||
4153 | mejdrech | 179 | movw $0x3d4, %dx # write bits 8 - 15 of the cursor address |
2220 | decky | 180 | movb $0xe, %al |
181 | outb %al, %dx |
||
182 | |||
183 | movw $0x3d5, %dx |
||
184 | movb %bh, %al |
||
185 | outb %al, %dx |
||
186 | |||
4153 | mejdrech | 187 | movw $0x3d4, %dx # write bits 0 - 7 of the cursor address |
2220 | decky | 188 | movb $0xf, %al |
189 | outb %al, %dx |
||
190 | |||
191 | movw $0x3d5, %dx |
||
192 | movb %bl, %al |
||
193 | outb %al, %dx |
||
4153 | mejdrech | 194 | |
2220 | decky | 195 | cli |
4153 | mejdrech | 196 | hlt1: |
197 | hlt |
||
198 | jmp hlt1 |
||
2220 | decky | 199 | |
4153 | mejdrech | 200 | #include "vesa_real.inc" |
1287 | vana | 201 | |
406 | jermar | 202 | .section K_DATA_START, "aw", @progbits |
105 | jermar | 203 | |
204 | .align 4096 |
||
205 | page_directory: |
||
206 | .space 4096, 0 |
||
2220 | decky | 207 | |
2222 | decky | 208 | grub_eax: |
209 | .long 0 |
||
210 | |||
211 | grub_ebx: |
||
212 | .long 0 |
||
213 | |||
2220 | decky | 214 | pse_msg: |
2302 | decky | 215 | .asciz "Page Size Extension not supported. System halted." |