166 lines
3.1 KiB
NASM
166 lines
3.1 KiB
NASM
format binary
|
|
use32
|
|
org 0x100000
|
|
|
|
MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
|
|
MULTIBOOT_PAGE_ALIGN equ (1 shl 0)
|
|
MULTIBOOT_MEMORY_INFO equ (1 shl 1)
|
|
MULTIBOOT_VIDEO_REQUEST equ (1 shl 2)
|
|
MULTIBOOT_AOUT_KLUDGE equ (1 shl 16)
|
|
MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN or MULTIBOOT_MEMORY_INFO or MULTIBOOT_VIDEO_REQUEST
|
|
MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN or MULTIBOOT_MEMORY_INFO or MULTIBOOT_VIDEO_REQUEST or MULTIBOOT_AOUT_KLUDGE
|
|
MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
|
|
|
|
multiboot:
|
|
dd MULTIBOOT_HEADER_MAGIC
|
|
dd MULTIBOOT_HEADER_FLAGS
|
|
dd MULTIBOOT_CHECKSUM
|
|
dd multiboot ; header address
|
|
dd 0x100000 ; load address
|
|
dd bss ; load end address
|
|
dd stack_top ; bss end address
|
|
dd start ; entry address
|
|
dd 0 ; video mode_type (0:fb, 1:txt) (set flags[2]!)
|
|
dd 1024 ; video width
|
|
dd 768 ; video height
|
|
dd 32 ; video depth
|
|
|
|
start:
|
|
; Setup stack
|
|
mov ebp, stack_top
|
|
mov esp, stack_top
|
|
|
|
push ebx
|
|
push eax
|
|
|
|
call serialinit
|
|
push stuff.bootmsg
|
|
call serialwrite
|
|
add esp, 4
|
|
|
|
call mbootgetinfo
|
|
add esp, 2*4
|
|
|
|
mov eax, [mbootinfo.fb_addr]
|
|
mov dword [eax], 0xffffffff
|
|
|
|
|
|
push stuff.fbaddrmsgpfx
|
|
call serialwrite
|
|
add esp, 4
|
|
|
|
sub esp, 36 ;Reserve stack for return
|
|
push dword esp ;Destination address
|
|
push dword 16 ;Base
|
|
push dword [mbootinfo.fb_addr] ;source
|
|
call __uitoa
|
|
add esp, 3*4
|
|
push esp
|
|
call serialwrite
|
|
add esp, 4
|
|
|
|
push stuff.fbdimensionsmsgpfx
|
|
call serialwrite
|
|
add esp, 4
|
|
push dword esp ;destination address
|
|
push dword 10 ;base
|
|
push dword [mbootinfo.fb_width]
|
|
call __uitoa
|
|
add esp, 3*4
|
|
push esp
|
|
call serialwrite
|
|
add esp, 4
|
|
push stuff.x
|
|
call serialwrite
|
|
add esp, 4
|
|
|
|
push dword esp ;destination address
|
|
push dword 10 ;base
|
|
push dword [mbootinfo.fb_height]
|
|
call __uitoa
|
|
add esp, 3*4
|
|
push esp
|
|
call serialwrite
|
|
add esp, 4
|
|
push stuff.x
|
|
call serialwrite
|
|
|
|
add esp, 4
|
|
push dword esp ;destination address
|
|
push dword 10 ;base
|
|
xor eax, eax
|
|
mov al, [mbootinfo.fb_bpp]
|
|
push dword eax
|
|
call __uitoa
|
|
add esp, 3*4
|
|
push esp
|
|
call serialwrite
|
|
add esp, 4
|
|
|
|
add esp, 36 ;Clean reserved uitoa return string from stack
|
|
|
|
|
|
;; Setup paging
|
|
;; Clear pagedir
|
|
cld
|
|
mov eax, 0x00000002 ;Supervisor only, Write enabled, Not present
|
|
mov ecx, 1024
|
|
mov edi, pagedir
|
|
rep stosd
|
|
|
|
;; Clear pagetable1
|
|
mov edi, pagetable1
|
|
mov cx, 0
|
|
.clearpt1loop:
|
|
mov eax, 0x00001000
|
|
mul ecx
|
|
or eax, 011b ;supervisor, rw, present
|
|
stosd
|
|
inc cx
|
|
cmp cx, 1024
|
|
jne .clearpt1loop
|
|
|
|
;; put table1 in dir
|
|
mov eax, pagetable1
|
|
or eax, 011b ;supervisor, rw, present
|
|
mov [pagedir], eax
|
|
|
|
;; Enable paging
|
|
mov eax, pagedir
|
|
mov cr3, eax
|
|
mov eax, cr0
|
|
or eax, 0x80000000
|
|
mov cr0, eax
|
|
|
|
jmp hang
|
|
|
|
hang:
|
|
push .msg
|
|
call serialwrite
|
|
cli
|
|
.loop:
|
|
hlt
|
|
jmp .loop
|
|
.msg db 10, "Halting...", 10, 0
|
|
|
|
include "src/serial.asm"
|
|
include "src/mbootinfo.asm"
|
|
include "src/itoa.asm"
|
|
|
|
stuff:
|
|
.bootmsg db 10, "=== rOSka ===", 10, 0
|
|
.fbaddrmsgpfx db 10, "Framebuffer address: 0x", 0
|
|
.fbdimensionsmsgpfx db 10, "Framebuffer dimensions: ", 0
|
|
.x db "x", 0
|
|
|
|
bss:
|
|
align 4096
|
|
pagedir:
|
|
rb 4096
|
|
align 4096
|
|
pagetable1:
|
|
rb 4096
|
|
align 4096
|
|
stack_bottom:
|
|
rb 16384
|
|
stack_top:
|