Newer
Older
kernel_base dq 0x100000
kernel_size dq 0
startup:
; enable A20-Line via IO-Port 92, might not work on all motherboards
in al, 0x92
or al, 2
out 0x92, al
%ifdef KERNEL
mov edi, [kernel_base]
mov ecx, (kernel_file.end - kernel_file)
mov [kernel_size], ecx
mov eax, (kernel_file - boot)/512
add ecx, 511
shr ecx, 9
call load_extent
jmp .loaded_kernel
%endif
%ifdef FILESYSTEM
call redoxfs
jmp .loaded_kernel
%endif
.loaded_kernel:
mov si, init_fpu_msg
call printrm
call initialize.fpu
mov si, init_sse_msg
call printrm
call initialize.sse
mov si, startup_arch_msg
call printrm
# load a disk extent into high memory
# eax - sector address
# ecx - sector count
# edi - destination
load_extent:
; 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
buffer_size_sectors equ 127
.lp:
cmp ecx, buffer_size_sectors
jb .break
; saving counter
push eax
push ecx
; populating buffer
mov ecx, buffer_size_sectors
mov bx, startup_end
pop edi
; move data
mov esi, startup_end
mov ecx, buffer_size_sectors * 512 / 4
cld
add eax, buffer_size_sectors
sub ecx, buffer_size_sectors
jmp .lp
.break:
; load the part of the kernel that does not fill the buffer completely
test ecx, ecx
jz .finish ; if cx = 0 => skip
mov bx, startup_end
mov dx, 0x0
call load
; moving remnants of kernel
call unreal
pop edi
pop ecx
mov esi, startup_end
shl ecx, 7 ; * 512 / 4
cld
a32 rep movsd
.finish:
call print_line
ret
%include "descriptor_flags.inc"
%include "gdt_entry.inc"
%include "unreal.asm"
%include "memory_map.asm"
%include "vesa.asm"
%include "initialize.asm"
%ifdef FILESYSTEM
%include "redoxfs.asm"
%endif
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