redox/bootloader/x86_64/startup-common.asm

111 lines
2.3 KiB
NASM
Raw Normal View History

2016-08-14 02:21:46 +02:00
SECTION .text
USE16
startup:
; enable A20-Line via IO-Port 92, might not work on all motherboards
in al, 0x92
or al, 2
out 0x92, al
; loading kernel to 1MiB
; move part of kernel to startup_end via bootsector#load and then copy it up
; repeat until all of the kernel is loaded
; buffersize in multiple of sectors (512 Bytes)
; min 1
; max (0x70000 - startup_end) / 512
buffer_size_sectors equ 127
2016-08-14 02:21:46 +02:00
; buffer size in Bytes
buffer_size_bytes equ buffer_size_sectors * 512
kernel_base equ 0x100000
; how often do we need to call load and move memory
mov ecx, kernel_file.length_sectors / buffer_size_sectors
2016-09-30 16:55:29 +02:00
mov eax, (kernel_file - boot) / 512
2016-08-14 02:21:46 +02:00
mov edi, kernel_base
cld
.lp:
; saving counter
push cx
; populating buffer
mov cx, buffer_size_sectors
2016-08-25 04:31:59 +02:00
mov bx, kernel_file
2016-08-14 02:21:46 +02:00
mov dx, 0x0
2016-09-30 16:55:29 +02:00
push edi
push eax
2016-08-14 02:21:46 +02:00
call load
; moving buffer
call unreal
2016-09-30 16:55:29 +02:00
pop eax
pop edi
2016-08-14 02:21:46 +02:00
2016-08-25 04:31:59 +02:00
mov esi, kernel_file
2016-08-14 02:21:46 +02:00
mov ecx, buffer_size_bytes / 4
a32 rep movsd
; preparing next iteration
2016-09-30 16:55:29 +02:00
add eax, buffer_size_sectors
2016-08-14 02:21:46 +02:00
pop cx
loop .lp
; load the part of the kernel that does not fill the buffer completely
mov cx, kernel_file.length_sectors % buffer_size_sectors
test cx, cx
jz finished_loading ; if cx = 0 => skip
2016-08-25 04:31:59 +02:00
mov bx, kernel_file
2016-08-14 02:21:46 +02:00
mov dx, 0x0
call load
; moving remnants of kernel
call unreal
2016-08-25 04:31:59 +02:00
mov esi, kernel_file
2016-08-14 02:21:46 +02:00
mov ecx, (kernel_file.length_sectors % buffer_size_bytes) / 4
a32 rep movsd
finished_loading:
call memory_map
call vesa
2016-11-18 02:59:36 +01:00
mov si, init_fpu_msg
call printrm
2016-08-14 02:21:46 +02:00
call initialize.fpu
2016-11-18 02:59:36 +01:00
mov si, init_sse_msg
call printrm
2016-08-14 02:21:46 +02:00
call initialize.sse
2016-11-18 02:59:36 +01:00
mov si, init_pit_msg
call printrm
2016-08-14 02:21:46 +02:00
call initialize.pit
2016-11-18 02:59:36 +01:00
mov si, init_pic_msg
call printrm
2016-08-14 02:21:46 +02:00
call initialize.pic
2016-11-18 02:59:36 +01:00
mov si, startup_arch_msg
call printrm
2016-08-14 02:21:46 +02:00
jmp startup_arch
2016-10-19 01:04:06 +02:00
%include "config.asm"
2016-08-14 02:21:46 +02:00
%include "descriptor_flags.inc"
%include "gdt_entry.inc"
%include "unreal.asm"
%include "memory_map.asm"
%include "vesa.asm"
%include "initialize.asm"
2016-11-18 02:59:36 +01:00
init_fpu_msg: db "Init FPU",13,10,0
init_sse_msg: db "Init SSE",13,10,0
init_pit_msg: db "Init PIT",13,10,0
init_pic_msg: db "Init PIC",13,10,0
startup_arch_msg: db "Startup Arch",13,10,0