Rev 314 | Rev 347 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 314 | Rev 323 | ||
---|---|---|---|
Line 51... | Line 51... | ||
51 | kernel_image_start: |
51 | kernel_image_start: |
52 | cli |
52 | cli |
53 | xorw %ax, %ax |
53 | xorw %ax, %ax |
54 | movw %ax, %ds |
54 | movw %ax, %ds |
55 | movw %ax, %ss # initialize stack segment register |
55 | movw %ax, %ss # initialize stack segment register |
56 | movl $BOOTSTRAP_OFFSET - 0x400, %esp # initialize stack pointer |
56 | movl $BOOTSTRAP_OFFSET - 0x400, %esp # initialize stack pointer |
57 | 57 | ||
58 | call memmap_arch_init |
58 | call memmap_arch_init |
59 | 59 | ||
60 | lgdt real_bootstrap_gdtr_boot # initialize Global Descriptor Table register |
60 | lgdt real_bootstrap_gdtr_boot # initialize Global Descriptor Table register |
61 | 61 | ||
62 | movl %cr0, %eax |
62 | movl %cr0, %eax |
63 | orl $0x1, %eax |
63 | orl $0x1, %eax |
64 | movl %eax, %cr0 # switch to protected mode |
64 | movl %eax, %cr0 # switch to protected mode |
65 | 65 | ||
Line 80... | Line 80... | ||
80 | boot_image_start: |
80 | boot_image_start: |
81 | movw $KDATA, %ax |
81 | movw $KDATA, %ax |
82 | movw %ax, %es |
82 | movw %ax, %es |
83 | movw %ax, %gs |
83 | movw %ax, %gs |
84 | movw %ax, %fs |
84 | movw %ax, %fs |
85 | movw %ax, %ds # kernel data + stack |
85 | movw %ax, %ds # kernel data + stack |
86 | movw %ax, %ss |
86 | movw %ax, %ss |
87 | 87 | ||
88 | movb $0xd1, %al # enable A20 using the keyboard controller |
88 | movb $0xd1, %al # enable A20 using the keyboard controller |
89 | outb %al, $0x64 |
89 | outb %al, $0x64 |
90 | movb $0xdf, %al |
90 | movb $0xdf, %al |
91 | outb %al, $0x60 |
91 | outb %al, $0x60 |
92 | 92 | ||
93 | movl $BOOTSTRAP_OFFSET, %esi |
93 | movl $BOOTSTRAP_OFFSET, %esi |
94 | movl $BOOTSTRAP_OFFSET + BOOT_OFFSET, %edi |
94 | movl $BOOTSTRAP_OFFSET + BOOT_OFFSET, %edi |
95 | movl $_hardcoded_kernel_size, %ecx |
95 | movl $_hardcoded_kernel_size, %ecx |
96 | cld |
96 | cld |
97 | rep movsb |
97 | rep movsb |
98 | 98 | ||
99 | call map_kernel # map kernel and turn paging on |
99 | call map_kernel # map kernel and turn paging on |
100 | 100 | ||
101 | call main_bsp # never returns |
101 | call main_bsp # never returns |
102 | 102 | ||
103 | cli |
103 | cli |
104 | hlt |
104 | hlt |
105 | 105 | ||
106 | multiboot_image_start: |
106 | multiboot_image_start: |
107 | movl $BOOTSTRAP_OFFSET - 0x400, %esp # initialize stack pointer |
107 | movl $BOOTSTRAP_OFFSET - 0x400, %esp # initialize stack pointer |
108 | 108 | ||
109 | lgdt protected_bootstrap_gdtr - 0x80000000 # initialize Global Descriptor Table register |
109 | lgdt protected_bootstrap_gdtr - 0x80000000 # initialize Global Descriptor Table register |
110 | 110 | ||
111 | movw $KDATA, %cx |
111 | movw $KDATA, %cx |
112 | movw %cx, %es |
112 | movw %cx, %es |
113 | movw %cx, %gs |
113 | movw %cx, %gs |
114 | movw %cx, %fs |
114 | movw %cx, %fs |
115 | movw %cx, %ds # kernel data + stack |
115 | movw %cx, %ds # kernel data + stack |
116 | movw %cx, %ss |
116 | movw %cx, %ss |
117 | 117 | ||
118 | jmpl $KTEXT, $multiboot_meeting_point + BOOT_OFFSET |
118 | jmpl $KTEXT, $multiboot_meeting_point + BOOT_OFFSET |
119 | multiboot_meeting_point: |
119 | multiboot_meeting_point: |
120 | 120 | ||
121 | pushl %ebx # save parameters from GRUB |
121 | pushl %ebx # save parameters from GRUB |
122 | pushl %eax |
122 | pushl %eax |
123 | 123 | ||
124 | movl $BOOTSTRAP_OFFSET + BOOT_OFFSET, %esi |
124 | movl $BOOTSTRAP_OFFSET + BOOT_OFFSET, %esi |
125 | movl $BOOTSTRAP_OFFSET, %edi |
125 | movl $BOOTSTRAP_OFFSET, %edi |
126 | movl $_hardcoded_unmapped_size, %ecx |
126 | movl $_hardcoded_unmapped_size, %ecx |
127 | cld |
127 | cld |
128 | rep movsb |
128 | rep movsb |
129 | 129 | ||
130 | call map_kernel # map kernel and turn paging on |
130 | call map_kernel # map kernel and turn paging on |
131 | 131 | ||
132 | popl %eax |
132 | popl %eax |
133 | popl %ebx |
133 | popl %ebx |
134 | cmpl $MULTIBOOT_LOADER_MAGIC, %eax # compare GRUB signature |
134 | cmpl $MULTIBOOT_LOADER_MAGIC, %eax # compare GRUB signature |
135 | je valid_boot |
135 | je valid_boot |
136 | 136 | ||
137 | xorl %ecx, %ecx # no memory size or map available |
137 | xorl %ecx, %ecx # no memory size or map available |
138 | movl %ecx, e801memorysize |
138 | movl %ecx, e801memorysize |
139 | movl %ecx, e820counter |
139 | movl %ecx, e820counter |
Line 201... | Line 201... | ||
201 | mmap_invalid: |
201 | mmap_invalid: |
202 | movl %edx, e820counter |
202 | movl %edx, e820counter |
203 | 203 | ||
204 | invalid_boot: |
204 | invalid_boot: |
205 | 205 | ||
206 | call main_bsp - BOOT_OFFSET # never returns |
206 | call main_bsp - BOOT_OFFSET # never returns |
207 | 207 | ||
208 | cli |
208 | cli |
209 | hlt |
209 | hlt |
210 | 210 | ||
211 | .global map_kernel |
211 | .global map_kernel |
Line 214... | Line 214... | ||
214 | # Here we setup mapping for both the unmapped and mapped sections of the kernel. |
214 | # Here we setup mapping for both the unmapped and mapped sections of the kernel. |
215 | # For simplicity, we set only one 4M page for 0x00000000 and one for 0x80000000. |
215 | # For simplicity, we set only one 4M page for 0x00000000 and one for 0x80000000. |
216 | # |
216 | # |
217 | movl %cr4, %ecx |
217 | movl %cr4, %ecx |
218 | orl $(1<<4), %ecx |
218 | orl $(1<<4), %ecx |
219 | movl %ecx, %cr4 # turn PSE on |
219 | movl %ecx, %cr4 # turn PSE on |
220 | 220 | ||
221 | movl $((1<<7)|(1<<0)), %eax |
221 | movl $((1<<7)|(1<<0)), %eax |
222 | movl %eax, page_directory # mapping 0x00000000 => 0x00000000 |
222 | movl %eax, page_directory # mapping 0x00000000 => 0x00000000 |
223 | 223 | ||
224 | movl $(page_directory+2048), %edx |
224 | movl $(page_directory+2048), %edx |
225 | movl %eax, (%edx) # mapping 0x80000000 => 0x00000000 |
225 | movl %eax, (%edx) # mapping 0x80000000 => 0x00000000 |
226 | 226 | ||
227 | leal page_directory, %eax |
227 | leal page_directory, %eax |
228 | movl %eax, %cr3 |
228 | movl %eax, %cr3 |
229 | 229 | ||
230 | # turn paging on |
230 | # turn paging on |