Collate ASM files

All ASM now uses Intel syntax.
isr.s and gdt.s are now collated into the main file.
It's bulky, but ¯\_(ツ)_/¯
UNTESTED, cause i'm thick.
This commit is contained in:
Curle 2019-05-14 23:57:03 +01:00
parent 64737e06e3
commit f5dc9b961b
3 changed files with 176 additions and 53 deletions

View File

@ -1,38 +1,183 @@
.set ALIGN, 1<<0
.set MEMINFO, 1<<1
.set FLAGS, ALIGN | MEMINFO
.set MAGIC, 0x1BADB002
.set CHECKSUM, -(MAGIC + FLAGS)
MBOOT_ALIGN equ <<0
MBOOT_MEMINFO equ 1<<1
MBOOT_FLAGS equ MBOOT_ALIGN | MBOOT_MEMINFO
MBOOT_MAGIC equ 0x1BADB002
MBOOT_CHECKSUM equ -(MAGIC + FLAGS)
.section .multiboot
.align 4
.long MAGIC
.long FLAGS
.long CHECKSUM
[BITS 32]
# C stack startup
.section .bss
.align 16
stack_bottom:
.skip 16384
stack_top:
[GLOBAL mboot]
# start function - calls kernel_main
.section .text
.global _start
.type _start, @function
_start:
movl $stack_top, %esp
[EXTERN code]
[EXTERN bss]
[EXTERN end]
mboot:
dd MBOOT_MAGIC
dd MBOOT_FLAGS
dd mboot
dd code
dd bss
dd end
dd start
call _init
call kernel_main
[GLOBAL start]
[EXTERN kernel_main]
start:
push ebx
cli
1: hlt
jmp 1b
.size _start, . - _start
call kernel_main
jmp $
[GLOBAL load_gdt] ; Allows the C code to call gdt_flush().
[EXTERN gp]
load_gdt:
mov eax, [esp+4] ; Get the pointer to the GDT, passed as a parameter.
lgdt [eax] ; Load the new GDT pointer
mov ax, 0x10 ; 0x10 is the offset in the GDT to our data segment
mov ds, ax ; Load all data segment selectors
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
jmp 0x08:flush ; 0x08 is the offset to our code segment: Far jump!
flush:
ret
%macro ISR 1
global isr%1
isr%1:
cli
push byte 0
push byte %1
jmp isr_common
%endmacro
%macro ISR_ERR 1
global isr%1
isr%1:
cli
push byte %1
jmp isr_common
%endmacro
%macro IRQ 2
global irq%1
irq%1:
cli
push byte 0
push byte %2
jmp irq_common
%endmacro
ISR 0
ISR 1
ISR 2
ISR 3
ISR 4
ISR 5
ISR 6
ISR 7
ISR_ERR 8
ISR 9
ISR_ERR 10
ISR_ERR 11
ISR_ERR 12
ISR_ERR 13
ISR_ERR 14
ISR 15
ISR 16
ISR_ERR 17
ISR 18
ISR 19
ISR 20
ISR 21
ISR 22
ISR 23
ISR 24
ISR 25
ISR 26
ISR 27
ISR 28
ISR 29
ISR_ERR 30
ISR 31
IRQ 0, 32
IRQ 1, 33
IRQ 2, 34
IRQ 3, 35
IRQ 4, 36
IRQ 5, 37
IRQ 6, 38
IRQ 7, 39
IRQ 8, 40
IRQ 9, 41
IRQ 10, 42
IRQ 11, 43
IRQ 12, 44
IRQ 13, 45
IRQ 14, 46
IRQ 15, 47
extern fault_handler
isr_common:
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
mov eax, fault_handler
call eax
pop eax
pop gs
pop fs
pop es
pop ds
popa
add esp, 8
iret
extern irq_handler
irq_common:
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
mov eax, irq_handler
call eax
pop eax
pop gs
pop fs
pop es
pop ds
popa
add esp, 8
iret
idt_load:
mov eax, [esp+4]
lidt [eax]
ret

View File

@ -1,15 +0,0 @@
.section .init
.global _init
.type _init, @function
_init:
push %ebp
movl %esp, %ebp
.section .fini
.global _fini
.type _fini, @function
_fini:
push %ebp
movl %esp, %ebp

View File

@ -1,7 +0,0 @@
.section .init
popl %ebp
ret
.section .fini
popl %ebp
ret