Files
RockOS/kernel/prekernel.s

119 lines
1.6 KiB
ArmAsm
Raw Normal View History

2026-06-09 23:16:25 -05:00
.code16
.text
.global _start
_start:
jmp everything
.org 20
.global kernel_size
kernel_size:
.long _end - _start
everything:
2026-06-10 09:39:37 -04:00
mov $0x1000, %ax
mov %ax, %es
mov %ax, %ds
2026-06-09 23:16:25 -05:00
# reset disk
mov $0, %ah
int $0x13
# stop the cursor
mov $1, %ah
2026-06-10 09:39:37 -04:00
mov $0,%cl
mov $0x20,%ch
int $0x11
2026-06-09 23:16:25 -05:00
# get the system memory, if this call fails then halt
clc
mov $0, %bx
mov $0xe801, %ax
int $0x15
jc halt
shr $10, %ax
shr $4, %bx
add %ax, %bx
mov %bx, total_mem_mb-_start
2026-06-10 09:39:37 -04:00
# vga text mode
mov $0x0003, %ax
int $0x10
2026-06-09 23:16:25 -05:00
enable_a20:
#enable the a20 gate
inb $0x92, %al
orb $2, %al
outb %al, $0x92
prep_protected:
cli
2026-06-10 09:39:37 -04:00
lgdt gdt_init-_start
2026-06-09 23:16:25 -05:00
mov %cr0, %eax
or $0x01, %eax
mov %eax, %cr0 # protected bit set
2026-06-10 09:39:37 -04:00
ljmpl $8, $protected
2026-06-09 23:16:25 -05:00
halt16:
jmp halt16
.code32
protected:
2026-06-10 09:39:37 -04:00
mov $16, %ax
mov %ax, %es
2026-06-09 23:16:25 -05:00
mov %ax, %ds
mov %ax, %ss
mov $5*8, %ax
ltr %ax
mov $0, %ax
mov %ax, %fs
mov %ax, %gs
mov $0xFFF0, %sp
mov $0xFFF0, %bp
ljmpl $8, $kmain
# some assembly stubs we can call from the kernel
.global idt_load
.extern idtr
idt_load:
2026-06-10 09:39:37 -04:00
lidt idtr
2026-06-09 23:16:25 -05:00
ret
.global reboot
reboot:
cli
lidt reboot_struct
int $1
reboot_struct:
.word 0
.long 0
.global halt
halt:
cli
hlt
jmp halt
# kernel data structures
.align 16
.global gdt
gdt:
.word 0,0,0,0
.word 0xffff, 0x0000, 0x9a00, 0x00cf
2026-06-10 09:39:37 -04:00
.word 0xffff, 0x0000, 0x9200, 0x00cf
.word 0xffff, 0x0000, 0xfa00, 0x00cf
.word 0xffff, 0x0000, 0xf200, 0x00cf
.word 0x0068, (tss-_start), 0x8901, 0x00cf
2026-06-09 23:16:25 -05:00
gdt_init:
.word gdt_init-gdt
.long gdt
.align 16
.global tss
tss:
.long 0
.global total_mem_mb
total_mem_mb:
.word 0