2018-05-06 20:25:29 +01:00
|
|
|
.set MBALIGN, 1<<0 # align loaded modules on page boundaries
|
|
|
|
.set MEMINFO, 1<<1 # provide memory map
|
|
|
|
.set FLAGS, MBALIGN | MEMINFO # this is the Multiboot 'flag' field
|
|
|
|
.set MAGIC, 0x1BADB002 # 'magic number' lets bootloader find the header
|
|
|
|
.set CHECKSUM, -(MAGIC + FLAGS) # checksum of above, to prove we are multiboot
|
2017-10-21 17:11:36 +01:00
|
|
|
|
2018-05-06 20:23:43 +01:00
|
|
|
.section .multiboot
|
|
|
|
.align 4
|
|
|
|
.long MAGIC
|
|
|
|
.long FLAGS
|
|
|
|
.long CHECKSUM
|
2017-10-21 17:11:36 +01:00
|
|
|
|
2018-05-11 22:41:52 +01:00
|
|
|
.section .bootstrap_stack, "aw", @nobits
|
2018-05-06 20:25:29 +01:00
|
|
|
.align 16
|
2017-10-21 17:11:36 +01:00
|
|
|
stack_bottom:
|
2018-05-06 20:23:43 +01:00
|
|
|
.skip 16384 # 16 KiB
|
2017-10-21 17:11:36 +01:00
|
|
|
stack_top:
|
|
|
|
|
2018-05-11 22:41:52 +01:00
|
|
|
.section .bss, "aw", @nobits
|
|
|
|
.align 4096
|
|
|
|
boot_pagedir:
|
|
|
|
.skip 4096
|
|
|
|
boot_pagetab1:
|
|
|
|
.skip 4096
|
|
|
|
|
2018-05-06 20:23:43 +01:00
|
|
|
.section .text
|
|
|
|
.global _start
|
|
|
|
.type _start, @function
|
2017-10-21 17:11:36 +01:00
|
|
|
_start:
|
2018-05-11 22:41:52 +01:00
|
|
|
mov $(boot_pagetab1 - 0xC0000000), %edi
|
|
|
|
mov $0, %esi
|
|
|
|
mov $1023, %ecx
|
|
|
|
1:
|
|
|
|
cmp $(_kernel_start - 0xC0000000), %esi
|
|
|
|
jl 2f
|
2018-05-16 01:47:52 +01:00
|
|
|
# + 0x1000 for the GRUB memory map
|
|
|
|
cmp $(_kernel_end - 0xC0000000 + 0x1000), %esi
|
2018-05-11 22:41:52 +01:00
|
|
|
jge 3f
|
|
|
|
mov %esi, %edx
|
|
|
|
or $0x003, %edx
|
|
|
|
mov %edx, (%edi)
|
|
|
|
2:
|
|
|
|
add $4096, %esi
|
|
|
|
add $4, %edi
|
|
|
|
loop 1b
|
|
|
|
3:
|
|
|
|
movl $(boot_pagetab1 - 0xC0000000 + 0x003), boot_pagedir - 0xC0000000 + 0
|
|
|
|
movl $(boot_pagetab1 - 0xC0000000 + 0x003), boot_pagedir - 0xC0000000 + 768 * 4
|
|
|
|
movl $(boot_pagedir - 0xC0000000), %ecx
|
|
|
|
mov %ecx, %cr3
|
|
|
|
mov %cr0, %ecx
|
|
|
|
or $0x80010000, %ecx
|
|
|
|
mov %ecx, %cr0
|
|
|
|
lea 4f, %ecx
|
|
|
|
jmp *%ecx
|
|
|
|
|
|
|
|
4:
|
|
|
|
movl $0, boot_pagedir + 0
|
|
|
|
mov %cr3, %ecx
|
|
|
|
mov %ecx, %cr3
|
2018-05-06 20:23:43 +01:00
|
|
|
mov $stack_top, %esp
|
2017-10-21 17:11:36 +01:00
|
|
|
call kernel_main
|
|
|
|
cli
|
|
|
|
.hang: hlt
|
|
|
|
jmp .hang
|
|
|
|
.end:
|
2018-05-06 20:25:29 +01:00
|
|
|
|
|
|
|
.size _start, . - _start
|