118 lines
2.3 KiB
ArmAsm
118 lines
2.3 KiB
ArmAsm
/*
|
|
* Multiboot Entry
|
|
*/
|
|
|
|
#define STACK_SIZE 0x4000
|
|
|
|
#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
|
|
#define MULTIBOOT_HEADER_FLAGS 0x00010003
|
|
|
|
.extern mb_entry
|
|
|
|
.text
|
|
|
|
.globl _start
|
|
_start: .code32
|
|
jmp multiboot_entry
|
|
|
|
.align 4
|
|
multiboot_header: .code32
|
|
.long MULTIBOOT_HEADER_MAGIC
|
|
.long MULTIBOOT_HEADER_FLAGS
|
|
.long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
|
|
.long multiboot_header
|
|
.long _start
|
|
.long _edata
|
|
.long _end
|
|
.long multiboot_entry
|
|
|
|
//
|
|
// Multiboot entry
|
|
// %eax: Magic (0x2BADB002)
|
|
// %ebx: multiboot info structure
|
|
//
|
|
multiboot_entry: .code32
|
|
movl %eax, %edx // Save multiboot magic
|
|
|
|
movl $(lmfarptr), %edi
|
|
movw $(0x7000 + 'A'), (0xB8000)
|
|
movl $(stack + STACK_SIZE), %esp
|
|
|
|
movw $(0x7000 + 'B'), (0xB8002)
|
|
pushl $0
|
|
popf
|
|
|
|
movw $(0x7000 + 'C'), (0xB8004)
|
|
movl %cr4, %eax
|
|
orl $0x0000006A0, %eax
|
|
movl %eax, %cr4
|
|
|
|
movw $(0x7000 + 'D'), (0xB8006)
|
|
movl $bootpgtbl1, %eax
|
|
movl %eax, %cr3
|
|
|
|
movw $(0x7000 + 'E'), (0xB8008)
|
|
movl $0xC0000080, %ecx
|
|
rdmsr
|
|
orl $0x0900, %eax
|
|
wrmsr
|
|
|
|
movw $(0x7000 + 'E'), (0xB800A)
|
|
movl $bootgdtdesc, %eax
|
|
lgdt (%eax)
|
|
|
|
movw $(0x7000 + 'F'), (0xB800C)
|
|
movl %cr0, %eax
|
|
orl $0x8005002B, %eax
|
|
movl %eax, %cr0
|
|
|
|
movw $(0x7000 + '0'), (0xB800E)
|
|
ljmp *(%edi)
|
|
|
|
lmenter: .code64
|
|
movw $(0x7000 + '1'), (0xB8010)
|
|
movw $0x10, %ax
|
|
movw %ax, %ss
|
|
movw %ax, %ds
|
|
movw %ax, %es
|
|
movw %ax, %fs
|
|
movw %ax, %gs
|
|
|
|
movw $(0x7000 + '2'), (0xB8012)
|
|
|
|
movq %rdx, %rdi // Magic
|
|
movq %rbx, %rsi // Multiboot info pointer
|
|
|
|
call mb_entry
|
|
|
|
movw $(0x5000 + 'H'), (0xB8098)
|
|
movw $(0x5000 + 'A'), (0xB809A)
|
|
movw $(0x5000 + 'L'), (0xB809C)
|
|
movw $(0x5000 + 'T'), (0xB809E)
|
|
loop:
|
|
hlt
|
|
jmp loop
|
|
|
|
lmfarptr:
|
|
.long lmenter
|
|
.word 0x08
|
|
|
|
.p2align 12
|
|
bootgdt:
|
|
.quad 0x0000000000000000 /* Null */
|
|
.quad 0x00AF9A000000FFFF /* Kernel CS */
|
|
.quad 0x00CF92000000FFFF /* Kernel DS */
|
|
.quad 0x0000000000000000
|
|
.quad 0x0000000000000000
|
|
.quad 0x0000000000000000
|
|
.quad 0x0000000000000000
|
|
|
|
.p2align 4
|
|
bootgdtdesc:
|
|
.word 0x0040
|
|
.quad bootgdt
|
|
|
|
// Boot stack
|
|
.comm stack, STACK_SIZE
|
|
|