520 lines
7.6 KiB
ArmAsm
520 lines
7.6 KiB
ArmAsm
global loader ; making entry point visible to linker
|
|
global magic ; we will use this in kmain
|
|
global mbd ; we will use this in kmain
|
|
global _sys_stack
|
|
|
|
extern kmain ; kmain is defined in kmain.cpp
|
|
|
|
; setting up the Multiboot header - see GRUB docs for details
|
|
MODULEALIGN equ 1<<0 ; align loaded modules on page boundaries
|
|
MEMINFO equ 1<<1 ; provide memory map
|
|
GRAPHICS equ 1<<2
|
|
FLAGS equ MODULEALIGN | MEMINFO | GRAPHICS ; this is the Multiboot 'flag' field
|
|
MAGIC equ 0x1BADB002 ; 'magic number' lets bootloader find the header
|
|
CHECKSUM equ -(MAGIC + FLAGS) ; checksum required
|
|
|
|
section .text
|
|
|
|
align 4
|
|
dd MAGIC
|
|
dd FLAGS
|
|
dd CHECKSUM
|
|
dd 0
|
|
dd 0
|
|
dd 0
|
|
dd 0
|
|
dd 0
|
|
dd 0
|
|
dd 1024
|
|
dd 768
|
|
dd 32
|
|
; reserve initial kernel stack space
|
|
STACKSIZE equ 0x4000 ; that's 16k.
|
|
|
|
loader:
|
|
mov esp, _sys_stack + STACKSIZE ; set up the stack
|
|
mov [magic], eax ; Multiboot magic number
|
|
mov [mbd], ebx ; Multiboot info structure
|
|
|
|
call kmain ; call kernel proper
|
|
|
|
cli
|
|
.hang:
|
|
hlt ; halt machine should kernel return
|
|
jmp .hang
|
|
|
|
|
|
global setGdt
|
|
|
|
gdtr DW 0
|
|
DD 0
|
|
|
|
setGdt:
|
|
mov eax, [esp + 4]
|
|
mov [gdtr + 2], eax
|
|
mov ax, [esp + 8]
|
|
mov [gdtr], ax
|
|
lgdt [gdtr]
|
|
mov ax, 0x10
|
|
mov ds, ax
|
|
mov es, ax
|
|
mov ss, ax
|
|
mov fs, ax
|
|
mov gs, ax
|
|
jmp 8:flush_cpu
|
|
flush_cpu:
|
|
ret
|
|
|
|
|
|
global setIdt
|
|
|
|
idtr DW 0
|
|
DD 0
|
|
|
|
setIdt:
|
|
mov eax, [esp + 4]
|
|
mov [idtr + 2], eax
|
|
mov ax, [esp + 8]
|
|
mov [idtr], ax
|
|
lidt [idtr]
|
|
ret
|
|
|
|
|
|
global isr0
|
|
global isr1
|
|
global isr2
|
|
global isr3
|
|
global isr4
|
|
global isr5
|
|
global isr6
|
|
global isr7
|
|
global isr8
|
|
global isr9
|
|
global isr10
|
|
global isr11
|
|
global isr12
|
|
global isr13
|
|
global isr14
|
|
global isr15
|
|
global isr16
|
|
global isr17
|
|
global isr18
|
|
global isr19
|
|
global isr20
|
|
global isr21
|
|
global isr22
|
|
global isr23
|
|
global isr24
|
|
global isr25
|
|
global isr26
|
|
global isr27
|
|
global isr28
|
|
global isr29
|
|
global isr30
|
|
global isr31
|
|
global irq0
|
|
global irq1
|
|
global irq2
|
|
global irq3
|
|
global irq4
|
|
global irq5
|
|
global irq6
|
|
global irq7
|
|
global irq8
|
|
global irq9
|
|
global irq10
|
|
global irq11
|
|
global irq12
|
|
global irq13
|
|
global irq14
|
|
global irq15
|
|
global irq16
|
|
|
|
isr0:
|
|
push byte 0
|
|
push byte 0
|
|
jmp isr_common_stub
|
|
|
|
isr1:
|
|
push byte 0
|
|
push byte 1
|
|
jmp isr_common_stub
|
|
|
|
isr2:
|
|
push byte 0
|
|
push byte 2
|
|
jmp isr_common_stub
|
|
|
|
isr3:
|
|
push byte 0
|
|
push byte 3
|
|
jmp isr_common_stub
|
|
|
|
isr4:
|
|
push byte 0
|
|
push byte 4
|
|
jmp isr_common_stub
|
|
|
|
isr5:
|
|
push byte 0
|
|
push byte 5
|
|
jmp isr_common_stub
|
|
|
|
isr6:
|
|
push byte 0
|
|
push byte 6
|
|
jmp isr_common_stub
|
|
|
|
isr7:
|
|
push byte 0
|
|
push byte 7
|
|
jmp isr_common_stub
|
|
|
|
isr8:
|
|
push byte 8
|
|
jmp isr_common_stub
|
|
|
|
|
|
isr9:
|
|
push byte 0
|
|
push byte 9
|
|
jmp isr_common_stub
|
|
|
|
isr10:
|
|
push byte 10
|
|
jmp isr_common_stub
|
|
|
|
isr11:
|
|
push byte 11
|
|
jmp isr_common_stub
|
|
|
|
isr12:
|
|
push byte 12
|
|
jmp isr_common_stub
|
|
|
|
isr13:
|
|
push byte 13
|
|
jmp isr_common_stub
|
|
|
|
isr14:
|
|
push byte 14
|
|
jmp isr_common_stub
|
|
|
|
isr15:
|
|
push byte 0
|
|
push byte 15
|
|
jmp isr_common_stub
|
|
|
|
isr16:
|
|
push byte 0
|
|
push byte 16
|
|
jmp isr_common_stub
|
|
|
|
isr17:
|
|
push byte 0
|
|
push byte 17
|
|
jmp isr_common_stub
|
|
|
|
isr18:
|
|
push byte 0
|
|
push byte 18
|
|
jmp isr_common_stub
|
|
|
|
isr19:
|
|
push byte 0
|
|
push byte 19
|
|
jmp isr_common_stub
|
|
|
|
isr20:
|
|
push byte 0
|
|
push byte 20
|
|
jmp isr_common_stub
|
|
|
|
isr21:
|
|
push byte 0
|
|
push byte 21
|
|
jmp isr_common_stub
|
|
|
|
isr22:
|
|
push byte 0
|
|
push byte 22
|
|
jmp isr_common_stub
|
|
|
|
isr23:
|
|
push byte 0
|
|
push byte 23
|
|
jmp isr_common_stub
|
|
|
|
isr24:
|
|
push byte 0
|
|
push byte 24
|
|
jmp isr_common_stub
|
|
|
|
isr25:
|
|
push byte 0
|
|
push byte 25
|
|
jmp isr_common_stub
|
|
|
|
isr26:
|
|
push byte 0
|
|
push byte 26
|
|
jmp isr_common_stub
|
|
|
|
isr27:
|
|
push byte 0
|
|
push byte 27
|
|
jmp isr_common_stub
|
|
|
|
|
|
isr28:
|
|
push byte 0
|
|
push byte 28
|
|
jmp isr_common_stub
|
|
|
|
isr29:
|
|
push byte 0
|
|
push byte 29
|
|
jmp isr_common_stub
|
|
|
|
isr30:
|
|
push byte 0
|
|
push byte 30
|
|
jmp isr_common_stub
|
|
|
|
isr31:
|
|
push byte 0
|
|
push byte 31
|
|
jmp isr_common_stub
|
|
|
|
|
|
|
|
irq0:
|
|
push byte 0
|
|
push byte 32
|
|
jmp irq_common_stub
|
|
|
|
irq1:
|
|
push byte 0
|
|
push byte 33
|
|
jmp irq_common_stub
|
|
|
|
irq2:
|
|
push byte 0
|
|
push byte 34
|
|
jmp irq_common_stub
|
|
irq3:
|
|
push byte 0 ; Note that these don't push an error code on the stack:
|
|
; We need to push a dummy error code
|
|
push byte 35
|
|
jmp irq_common_stub
|
|
irq4:
|
|
push byte 0 ; Note that these don't push an error code on the stack:
|
|
; We need to push a dummy error code
|
|
push byte 36
|
|
jmp irq_common_stub
|
|
irq5:
|
|
push byte 0 ; Note that these don't push an error code on the stack:
|
|
; We need to push a dummy error code
|
|
push byte 37
|
|
jmp irq_common_stub
|
|
irq6:
|
|
push byte 0 ; Note that these don't push an error code on the stack:
|
|
; We need to push a dummy error code
|
|
push byte 38
|
|
jmp irq_common_stub
|
|
irq7:
|
|
push byte 0 ; Note that these don't push an error code on the stack:
|
|
; We need to push a dummy error code
|
|
push byte 39
|
|
jmp irq_common_stub
|
|
irq8:
|
|
push byte 0 ; Note that these don't push an error code on the stack:
|
|
; We need to push a dummy error code
|
|
push byte 40
|
|
jmp irq_common_stub
|
|
irq9:
|
|
push byte 0 ; Note that these don't push an error code on the stack:
|
|
; We need to push a dummy error code
|
|
push byte 41
|
|
jmp irq_common_stub
|
|
irq10:
|
|
push byte 0 ; Note that these don't push an error code on the stack:
|
|
; We need to push a dummy error code
|
|
push byte 42
|
|
jmp irq_common_stub
|
|
irq11:
|
|
push byte 0 ; Note that these don't push an error code on the stack:
|
|
; We need to push a dummy error code
|
|
push byte 43
|
|
jmp irq_common_stub
|
|
irq12:
|
|
push byte 0 ; Note that these don't push an error code on the stack:
|
|
; We need to push a dummy error code
|
|
push byte 44
|
|
jmp irq_common_stub
|
|
irq13:
|
|
push byte 0 ; Note that these don't push an error code on the stack:
|
|
; We need to push a dummy error code
|
|
push byte 45
|
|
jmp irq_common_stub
|
|
irq14:
|
|
push byte 0 ; Note that these don't push an error code on the stack:
|
|
; We need to push a dummy error code
|
|
push byte 46
|
|
jmp irq_common_stub
|
|
irq15:
|
|
push byte 0
|
|
|
|
push byte 47
|
|
jmp irq_common_stub
|
|
|
|
irq16:
|
|
push byte 0
|
|
push byte 48
|
|
|
|
jmp irq_common_stub
|
|
|
|
|
|
extern fault_handler
|
|
|
|
extern current_task
|
|
extern system_tss
|
|
|
|
isr_common_stub:
|
|
cld
|
|
pushad
|
|
push ds
|
|
push es
|
|
push fs
|
|
push gs
|
|
|
|
|
|
|
|
mov ax, 0x10
|
|
mov ds, ax
|
|
mov es, ax
|
|
mov fs, ax
|
|
mov gs, ax
|
|
|
|
push esp
|
|
|
|
call fault_handler
|
|
|
|
add esp, 4
|
|
pop gs
|
|
pop fs
|
|
pop es
|
|
pop ds
|
|
popad
|
|
|
|
add esp, 8
|
|
|
|
iret
|
|
|
|
extern irq_handler
|
|
|
|
irq_common_stub:
|
|
cld
|
|
pushad
|
|
push ds
|
|
push es
|
|
push fs
|
|
push gs
|
|
|
|
mov eax, [current_task]
|
|
mov [eax], esp
|
|
|
|
mov ax, 0x10
|
|
mov ds, ax
|
|
mov es, ax
|
|
mov fs, ax
|
|
mov gs, ax
|
|
|
|
push esp
|
|
|
|
call irq_handler
|
|
|
|
add esp, 4
|
|
|
|
jmp irq_common_end
|
|
|
|
global switch_to
|
|
global switch_to_force
|
|
|
|
switch_to:
|
|
mov ecx, [current_task]
|
|
mov esp, [ecx]
|
|
|
|
mov ebx, [ecx+8];put content of the k-stack field into ebx.
|
|
mov [system_tss+4],ebx ;update system tss. (esp)
|
|
|
|
mov ebx, [ecx+16]
|
|
mov cr3, ebx
|
|
|
|
mov al, 0x20
|
|
out 0x20, al
|
|
|
|
jmp irq_common_end
|
|
|
|
switch_to_force:
|
|
mov ecx, [current_task]
|
|
mov esp, [ecx]
|
|
|
|
mov ebx, [ecx+8];put content of the k-stack field into ebx.
|
|
mov [system_tss+4],ebx ;update system tss. (esp)
|
|
|
|
mov ebx, [ecx+16]
|
|
mov cr3, ebx
|
|
|
|
mov al, 0x20
|
|
out 0xA0, al
|
|
|
|
mov al, 0x20
|
|
out 0x20, al
|
|
|
|
|
|
irq_common_end:
|
|
pop gs
|
|
pop fs
|
|
pop es
|
|
pop ds
|
|
popad
|
|
|
|
add esp, 8
|
|
|
|
iret
|
|
|
|
|
|
|
|
|
|
|
|
global read_cr2
|
|
|
|
read_cr2:
|
|
mov eax, cr2
|
|
retn
|
|
|
|
global ivld_cr3
|
|
|
|
ivld_cr3:
|
|
mov eax, cr3
|
|
mov cr3, eax
|
|
retn
|
|
|
|
global ivld_tlb
|
|
|
|
ivld_tlb:
|
|
push ebp
|
|
mov ebp, esp
|
|
mov eax, [ebp+8]
|
|
invlpg [eax]
|
|
pop ebp
|
|
retn
|
|
|
|
section .bss
|
|
|
|
align 4
|
|
_sys_stack: resb STACKSIZE ; reserve 16k stack on a doubleword boundary
|
|
magic: resd 1
|
|
mbd: resd 1
|