Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- section .multiboot2
- align 8
- HEADER_START:
- dd 0xE85250D6
- dd 0
- dd (HEADER_END - HEADER_START)
- dd -(0xE85250D6 + (HEADER_END - HEADER_START))
- ; Request 640x480 framebuffer.
- align 8
- dw 5
- dw 0
- dd 20
- dd 640
- dd 480
- dd 32
- align 8
- dw 0
- dw 0
- dd 8
- HEADER_END:
- section .bss
- STACK_BOTTOM: resb 16384
- STACK_TOP:
- align 4096
- BOOT_PAGE_DIR0: resb 4096
- ; Tables directly next to eachother for cleanliness.
- BOOT_PAGE_TBL0: resb 4096
- BOOT_PAGE_TBL1: resb 4096
- section .text
- extern main
- extern _kernel_start
- extern _kernel_end
- global _start:function (_start.end - _start)
- _start:
- mov esp, STACK_TOP - 0xE0000000
- mov edi, BOOT_PAGE_TBL0 - 0xE0000000
- mov esi, 0
- mov ecx, 2048 - 301 ; 301 pages for the framebuffer in case they're not page aligned, which I'm not sure of yet.
- .loo:
- cmp esi, _kernel_start - 0xE0000000
- jl .loopcond
- cmp esi, _kernel_end - 0xE0000000
- jge .loopend
- mov eax, esi
- or eax, 3
- mov [edi], eax
- .loopcond:
- add esi, 4096
- add edi, 4
- loop .loo
- .loopend:
- call _find_framebuffer - 0xE0000000
- call _page_framebuffer - 0xE0000000
- ; Identity mapping.
- ; +3 is the flags.
- mov dword [BOOT_PAGE_DIR0 - 0xE0000000 + (000 * 4)], (BOOT_PAGE_TBL0 - 0xE0000000 + 3)
- mov dword [BOOT_PAGE_DIR0 - 0xE0000000 + (001 * 4)], (BOOT_PAGE_TBL1 - 0xE0000000 + 3)
- ; Mapping to 0xE0000000.
- mov dword [BOOT_PAGE_DIR0 - 0xE0000000 + (896 * 4)], (BOOT_PAGE_TBL0 - 0xE0000000 + 3)
- mov dword [BOOT_PAGE_DIR0 - 0xE0000000 + (897 * 4)], (BOOT_PAGE_TBL1 - 0xE0000000 + 3)
- mov ecx, BOOT_PAGE_DIR0 - 0xE0000000
- mov cr3, ecx
- mov ecx, cr0
- or ecx, 0x80010000
- mov cr0, ecx
- add esp, 0xE0000000
- jmp .afterpage ; Higher-half jump.
- .afterpage:
- push ebx
- call main
- cli
- .hlt:
- hlt
- jmp .hlt
- .end:
- ; Expects multiboot data to be in ebx.
- _find_framebuffer:
- add ebx, 8
- .loop:
- cmp dword [ebx], 0 ; End tag type.
- jne .notzero
- ret
- .notzero:
- cmp dword [ebx], 8 ; Framebuffer tag type.
- je .isfb
- add ebx, [ebx + 4] ; Add size of tag to address, multiboot2 spec says it's at offset 4.
- ; Align the address, as according to
- add ebx, 7
- and ebx, ~7
- jmp .loop
- .isfb:
- mov ebx, [ebx + 8] ; Get framebuffer address, at offset 8.
- ret
- ; Maps to the page at edi, which was set before in _start.
- _page_framebuffer:
- mov ecx, 301 ; 301 in case the framebuffer address is not page aligned, to fit it perfectly. Might come up with a nicer solution later.
- mov esi, ebx ; Copy to esi for readability and to keep ebx unchanged, as we pass it later to main.
- and esi, ~4096 ; Align to page.
- .loo:
- mov eax, esi
- or eax, 3
- mov [edi], eax
- loop .loo
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement