2011-02-28 06:14:03 +03:00
|
|
|
; ToAruOS Start Up / Entry Point
|
|
|
|
; vim:syntax=nasm
|
2011-03-05 03:18:14 +03:00
|
|
|
; vim:tabstop=4
|
2011-02-28 06:14:03 +03:00
|
|
|
;
|
|
|
|
; Copyright 2011 ToAruOS Kernel Development Group
|
|
|
|
; See main.c for licensing terms (NCSA)
|
|
|
|
;
|
2011-03-05 03:18:14 +03:00
|
|
|
BITS 32
|
2011-01-16 04:01:19 +03:00
|
|
|
ALIGN 4
|
2011-01-29 01:48:58 +03:00
|
|
|
|
|
|
|
|
2011-01-16 04:01:19 +03:00
|
|
|
mboot:
|
2011-03-05 03:18:14 +03:00
|
|
|
; Multiboot headers:
|
|
|
|
; Page aligned loading, please
|
2011-01-16 04:01:19 +03:00
|
|
|
MULTIBOOT_PAGE_ALIGN equ 1<<0
|
2011-03-05 03:18:14 +03:00
|
|
|
; We require memory information
|
2011-01-16 04:01:19 +03:00
|
|
|
MULTIBOOT_MEMORY_INFO equ 1<<1
|
2011-03-05 03:18:14 +03:00
|
|
|
; We are multiboot compatible!
|
2011-01-16 04:01:19 +03:00
|
|
|
MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
|
2011-03-05 03:18:14 +03:00
|
|
|
; Load up those flags.
|
2011-01-18 02:11:21 +03:00
|
|
|
MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO
|
2011-03-05 03:18:14 +03:00
|
|
|
; Checksum the result
|
2011-01-16 04:01:19 +03:00
|
|
|
MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
|
2011-03-05 03:18:14 +03:00
|
|
|
; Load the headers into the binary image.
|
2011-01-16 04:01:19 +03:00
|
|
|
dd MULTIBOOT_HEADER_MAGIC
|
|
|
|
dd MULTIBOOT_HEADER_FLAGS
|
|
|
|
dd MULTIBOOT_CHECKSUM
|
|
|
|
|
2011-03-05 03:18:14 +03:00
|
|
|
|
|
|
|
; Some external references.
|
|
|
|
extern code, bss, end
|
|
|
|
|
2011-01-16 04:01:19 +03:00
|
|
|
; Main entrypoint
|
2011-01-18 02:11:21 +03:00
|
|
|
global start
|
|
|
|
start:
|
2011-02-28 06:19:54 +03:00
|
|
|
; Set up stack pointer.
|
|
|
|
mov esp, 0x7FFFF
|
2011-03-02 02:48:39 +03:00
|
|
|
push esp
|
2011-01-29 01:48:58 +03:00
|
|
|
; Push the incoming mulitboot headers
|
2011-02-28 06:19:54 +03:00
|
|
|
push eax ; Header magic
|
2011-02-08 08:51:11 +03:00
|
|
|
push ebx ; Header pointer
|
2011-01-29 01:48:58 +03:00
|
|
|
; Disable interrupts
|
2011-01-19 09:04:27 +03:00
|
|
|
cli
|
2011-01-29 01:48:58 +03:00
|
|
|
; Call the C entry
|
2011-01-16 04:01:19 +03:00
|
|
|
extern main
|
|
|
|
call main
|
|
|
|
jmp $
|
|
|
|
|
2011-01-19 09:04:27 +03:00
|
|
|
|
2011-01-16 06:11:17 +03:00
|
|
|
; Global Descriptor Table
|
2011-01-16 04:59:11 +03:00
|
|
|
global gdt_flush
|
|
|
|
extern gp
|
|
|
|
gdt_flush:
|
2011-02-28 06:19:54 +03:00
|
|
|
; Load the GDT
|
2011-01-16 04:59:11 +03:00
|
|
|
lgdt [gp]
|
2011-02-28 06:19:54 +03:00
|
|
|
; Flush the values to 0x10
|
2011-01-16 04:59:11 +03:00
|
|
|
mov ax, 0x10
|
|
|
|
mov ds, ax
|
|
|
|
mov es, ax
|
|
|
|
mov fs, ax
|
|
|
|
mov gs, ax
|
|
|
|
mov ss, ax
|
|
|
|
jmp 0x08:flush2
|
|
|
|
flush2:
|
|
|
|
ret
|
2011-01-16 04:01:19 +03:00
|
|
|
|
2011-01-16 06:11:17 +03:00
|
|
|
; Interrupt Descriptor Table
|
|
|
|
global idt_load
|
|
|
|
extern idtp
|
|
|
|
idt_load:
|
|
|
|
lidt [idtp]
|
|
|
|
ret
|
|
|
|
|
2011-01-16 04:01:19 +03:00
|
|
|
; Interrupt Service Routines
|
2011-01-18 23:52:08 +03:00
|
|
|
%macro ISR_NOERR 1
|
|
|
|
global _isr%1
|
|
|
|
_isr%1:
|
|
|
|
cli
|
|
|
|
push byte 0
|
|
|
|
push byte %1
|
|
|
|
jmp isr_common_stub
|
|
|
|
%endmacro
|
|
|
|
|
|
|
|
%macro ISR_ERR 1
|
|
|
|
global _isr%1
|
|
|
|
_isr%1:
|
|
|
|
cli
|
|
|
|
push byte %1
|
|
|
|
jmp isr_common_stub
|
|
|
|
%endmacro
|
|
|
|
|
2011-02-28 06:19:54 +03:00
|
|
|
%macro IRQ_ENTRY 2
|
|
|
|
global _irq%1
|
|
|
|
_irq%1:
|
|
|
|
cli
|
|
|
|
push byte 0
|
|
|
|
push byte %2
|
|
|
|
jmp irq_common_stub
|
|
|
|
%endmacro
|
|
|
|
|
2011-01-29 01:48:58 +03:00
|
|
|
; Standard X86 interrupt service routines
|
2011-01-18 23:52:08 +03:00
|
|
|
ISR_NOERR 0
|
|
|
|
ISR_NOERR 1
|
|
|
|
ISR_NOERR 2
|
|
|
|
ISR_NOERR 3
|
|
|
|
ISR_NOERR 4
|
|
|
|
ISR_NOERR 5
|
|
|
|
ISR_NOERR 6
|
|
|
|
ISR_NOERR 7
|
|
|
|
ISR_ERR 8
|
|
|
|
ISR_NOERR 9
|
|
|
|
ISR_ERR 10
|
|
|
|
ISR_ERR 11
|
|
|
|
ISR_ERR 12
|
|
|
|
ISR_ERR 13
|
|
|
|
ISR_ERR 14
|
|
|
|
ISR_NOERR 15
|
|
|
|
ISR_NOERR 16
|
|
|
|
ISR_NOERR 17
|
|
|
|
ISR_NOERR 18
|
|
|
|
ISR_NOERR 19
|
|
|
|
ISR_NOERR 20
|
|
|
|
ISR_NOERR 21
|
|
|
|
ISR_NOERR 22
|
|
|
|
ISR_NOERR 23
|
|
|
|
ISR_NOERR 24
|
|
|
|
ISR_NOERR 25
|
|
|
|
ISR_NOERR 26
|
|
|
|
ISR_NOERR 27
|
|
|
|
ISR_NOERR 28
|
|
|
|
ISR_NOERR 29
|
|
|
|
ISR_NOERR 30
|
|
|
|
ISR_NOERR 31
|
2011-03-30 06:08:56 +04:00
|
|
|
ISR_NOERR 127
|
2011-01-16 06:41:17 +03:00
|
|
|
|
|
|
|
|
2011-02-28 06:19:54 +03:00
|
|
|
; Interrupt Requests
|
|
|
|
IRQ_ENTRY 0, 32
|
|
|
|
IRQ_ENTRY 1, 33
|
|
|
|
IRQ_ENTRY 2, 34
|
|
|
|
IRQ_ENTRY 3, 35
|
|
|
|
IRQ_ENTRY 4, 36
|
|
|
|
IRQ_ENTRY 5, 37
|
|
|
|
IRQ_ENTRY 6, 38
|
|
|
|
IRQ_ENTRY 7, 39
|
|
|
|
IRQ_ENTRY 8, 40
|
|
|
|
IRQ_ENTRY 9, 41
|
|
|
|
IRQ_ENTRY 10, 42
|
|
|
|
IRQ_ENTRY 11, 43
|
|
|
|
IRQ_ENTRY 12, 44
|
|
|
|
IRQ_ENTRY 13, 45
|
|
|
|
IRQ_ENTRY 14, 46
|
|
|
|
IRQ_ENTRY 15, 47
|
|
|
|
|
|
|
|
; Interrupt handlers
|
|
|
|
extern fault_handler
|
2011-01-16 06:41:17 +03:00
|
|
|
isr_common_stub:
|
|
|
|
pusha
|
|
|
|
push ds
|
|
|
|
push es
|
|
|
|
push fs
|
|
|
|
push gs
|
|
|
|
mov ax, 0x10
|
|
|
|
mov ds, ax
|
|
|
|
mov es, ax
|
|
|
|
mov fs, ax
|
|
|
|
mov gs, ax
|
|
|
|
mov eax, esp
|
|
|
|
push eax
|
2011-01-29 01:48:58 +03:00
|
|
|
; Call the C kernel fault handler
|
2011-01-16 06:41:17 +03:00
|
|
|
mov eax, fault_handler
|
|
|
|
call eax
|
|
|
|
pop eax
|
|
|
|
pop gs
|
|
|
|
pop fs
|
|
|
|
pop es
|
|
|
|
pop ds
|
|
|
|
popa
|
|
|
|
add esp, 8
|
|
|
|
iret
|
2011-01-16 06:11:17 +03:00
|
|
|
|
2011-01-16 07:17:42 +03:00
|
|
|
extern irq_handler
|
|
|
|
irq_common_stub:
|
|
|
|
pusha
|
|
|
|
push ds
|
|
|
|
push es
|
|
|
|
push fs
|
|
|
|
push gs
|
|
|
|
mov ax, 0x10
|
|
|
|
mov ds, ax
|
|
|
|
mov es, ax
|
|
|
|
mov fs, ax
|
|
|
|
mov gs, ax
|
|
|
|
mov eax, esp
|
|
|
|
push eax
|
2011-01-29 01:48:58 +03:00
|
|
|
; Call the C kernel hardware interrupt handler
|
2011-01-16 07:17:42 +03:00
|
|
|
mov eax, irq_handler
|
|
|
|
call eax
|
|
|
|
pop eax
|
|
|
|
pop gs
|
|
|
|
pop fs
|
|
|
|
pop es
|
|
|
|
pop ds
|
|
|
|
popa
|
|
|
|
add esp, 8
|
|
|
|
iret
|
|
|
|
|
2011-03-02 02:48:39 +03:00
|
|
|
global read_eip
|
|
|
|
read_eip: ; Clever girl
|
2011-12-16 01:31:18 +04:00
|
|
|
pop eax
|
|
|
|
jmp eax
|
2011-03-02 02:48:39 +03:00
|
|
|
|
|
|
|
global copy_page_physical
|
|
|
|
copy_page_physical:
|
|
|
|
push ebx
|
|
|
|
pushf
|
|
|
|
cli
|
|
|
|
mov ebx, [esp+12]
|
|
|
|
mov ecx, [esp+16]
|
|
|
|
mov edx, cr0
|
|
|
|
and edx, 0x7FFFFFFF
|
|
|
|
mov cr0, edx
|
|
|
|
mov edx, 0x400
|
|
|
|
.page_loop:
|
|
|
|
mov eax, [ebx]
|
|
|
|
mov [ecx], eax
|
|
|
|
add ebx, 4
|
|
|
|
add ecx, 4
|
|
|
|
dec edx
|
|
|
|
jnz .page_loop
|
|
|
|
mov edx, cr0
|
|
|
|
or edx, 0x80000000
|
|
|
|
mov cr0, edx
|
|
|
|
popf
|
|
|
|
pop ebx
|
|
|
|
ret
|
2011-01-16 07:17:42 +03:00
|
|
|
|
2011-03-30 06:08:56 +04:00
|
|
|
global tss_flush
|
|
|
|
tss_flush:
|
|
|
|
mov ax, 0x2B
|
|
|
|
ltr ax
|
2011-03-29 05:34:53 +04:00
|
|
|
ret
|
|
|
|
|
2011-01-16 04:01:19 +03:00
|
|
|
; BSS Section
|
|
|
|
SECTION .bss
|
|
|
|
resb 8192 ; 8KB of memory reserved
|
|
|
|
|