summaryrefslogtreecommitdiff
path: root/stage2
diff options
context:
space:
mode:
authorLizzy Fleckenstein <lizzy@vlhl.dev>2024-04-11 20:58:38 +0200
committerLizzy Fleckenstein <lizzy@vlhl.dev>2024-04-11 21:05:47 +0200
commit8b90c1f407b4f4aa3802858e23aa90d7dfbe17ad (patch)
tree4080e975e33df6f3c57ff5f3486f97923c9bbbe3 /stage2
parenta6669e496e46ef89673103b3330226c7d0201a1a (diff)
downloadcuddles-8b90c1f407b4f4aa3802858e23aa90d7dfbe17ad.tar.xz
bootinfo struct
Diffstat (limited to 'stage2')
-rw-r--r--stage2/elf.asm9
-rw-r--r--stage2/main.asm27
-rw-r--r--stage2/mmap.asm24
-rw-r--r--stage2/vesa.asm47
4 files changed, 57 insertions, 50 deletions
diff --git a/stage2/elf.asm b/stage2/elf.asm
index 01759b3..d1d15e3 100644
--- a/stage2/elf.asm
+++ b/stage2/elf.asm
@@ -11,7 +11,7 @@ load_kernel_elf:
.header:
cmp rdx, 0
- je .start
+ je .done
mov edi, [r8] ; type
cmp edi, 0
@@ -48,14 +48,11 @@ load_kernel_elf:
dec rdx
jmp .header
-.start:
- ; more stack space
- mov rsp, 0x80000
- xor rbp, rbp
+.done:
; ELF entry point
mov rax, [kernel_elf+24]
- call rax
+ ret
.fail:
cli
diff --git a/stage2/main.asm b/stage2/main.asm
index fae8d5a..1964720 100644
--- a/stage2/main.asm
+++ b/stage2/main.asm
@@ -1,14 +1,12 @@
[org 0x7E00]
%define PAGETABLE 0x1000
-%define VESAINFO 0x0500
-%define VESAMODE VESAINFO+512
-%define OWNMODE VESAMODE+256
-%define GFXINFO PAGETABLE-10
-;%define MEMMAPCNT GFXINFO-2
+%define VESAMODES 0x500
%define MEMMAP 0x500
setup:
+ mov [bootinfo.ksize], edi
+
; print message
mov ebx, .msg
call print_str
@@ -28,6 +26,15 @@ setup:
.msg:
db 10, 13, "cuddles stage2", 10, 13, 0
+bootinfo:
+ .ksize: dq 0
+ .gfx_pitch: dw 0
+ .gfx_width: dw 0
+ .gfx_height: dw 0
+ .gfx_framebuffer: dq 0
+ .mmap_len: dq 0
+ .mmap_ptr: dq 0
+
%include "stage2/vesa.asm"
%include "stage2/mmap.asm"
%include "stage2/paging.asm"
@@ -46,6 +53,14 @@ long_mode:
mov gs, ax
mov ss, ax
- call load_kernel_elf
+ call load_kernel_elf ; returns entry point in rax
+
+ ; more stack space
+ mov rsp, 0x80000
+ xor rbp, rbp
+
+ ; pass bootinfo as arg
+ mov rdi, bootinfo
+ call rax
kernel_elf:
diff --git a/stage2/mmap.asm b/stage2/mmap.asm
index 72f188a..b719f84 100644
--- a/stage2/mmap.asm
+++ b/stage2/mmap.asm
@@ -6,6 +6,7 @@ mmap:
xor ebx, ebx ; counter for interrupt
mov di, MEMMAP
+ xor esi, esi ; number of regions
.loop:
; issue an INT 0x15, EAX = 0xE820 interrupt
@@ -17,32 +18,19 @@ mmap:
cmp eax, MAPMAGIC ; detect failure
jne .fail
- cmp dword[di+16], 1
- ; jne .next
-
- cmp dword[di+4], 0
- jne .keep
-
- cmp dword[di+0], 0x100000
- jb .next
-
-.keep:
- mov dword[di+20], 0
+ inc esi
add di, 24
-.next:
cmp ebx, 0
jne .loop
mov dword[di+0], 0
mov dword[di+4], 0
- ;mov ax, di
- ;sub ax, MEMMAP
- ;xor dx, dx
- ;mov bx, 24
- ;div bx
- ;mov [MEMMAPCNT], ax
+ mov dword[bootinfo.mmap_len+0], esi
+ mov dword[bootinfo.mmap_len+4], 0
+ mov dword[bootinfo.mmap_ptr+0], MEMMAP
+ mov dword[bootinfo.mmap_ptr+4], 0
ret
diff --git a/stage2/vesa.asm b/stage2/vesa.asm
index da7eb81..8038ba4 100644
--- a/stage2/vesa.asm
+++ b/stage2/vesa.asm
@@ -1,3 +1,6 @@
+vesainfo: times 512 db 0
+vesamode: times 256 db 0
+
vesa:
; print message
mov ebx, .msg
@@ -5,16 +8,16 @@ vesa:
; get vesa bios info
mov eax, dword[.vbe2]
- mov dword[VESAINFO], eax ; move "VBE2" to start of vesainfo struct
+ mov dword[vesainfo], eax ; move "VBE2" to start of vesainfo struct
mov ax, 0x4F00 ; get VESA BIOS information
- mov di, VESAINFO ; struct buffer
+ mov di, vesainfo ; struct buffer
int 0x10
cmp ax, 0x004F ; check ax for correct magic number
jne .fail_getinfo
mov eax, dword[.vesa]
- cmp dword[VESAINFO], eax ; check if "VESA" is at start of stuct
+ cmp dword[vesainfo], eax ; check if "VESA" is at start of struct
jne .fail_getinfo
; print select message
@@ -22,8 +25,8 @@ vesa:
call print_str
; get segment:offset pointer to video modes into gs:ebx
- movzx ebx, word[VESAINFO+14]
- mov ax, word[VESAINFO+16]
+ movzx ebx, word[vesainfo+14]
+ mov ax, word[vesainfo+16]
mov gs, ax
; convert modes to own structure
@@ -36,17 +39,17 @@ vesa:
cmp cx, 0xFFFF ; 0xFFFF is terminator, no suitable mode has been found
je .mode_done
mov ax, 0x4F01 ; get VESA mode information
- mov di, VESAMODE ; vesa mode info struct buffer
+ mov di, vesamode ; vesa mode info struct buffer
int 0x10
cmp ax, 0x004F ; check ax for correct magic number
jne .fail_modeinfo
- mov al, byte[VESAMODE] ; get attributes
+ mov al, byte[vesamode] ; get attributes
and al, 0b10000000 ; extract bit 7, indicates linear framebuffer support
jz .mode_next
- mov al, byte[VESAMODE+25] ; get bpp (bits per pixel)
+ mov al, byte[vesamode+25] ; get bpp (bits per pixel)
cmp al, 32
jne .mode_next
@@ -56,7 +59,7 @@ vesa:
mov ebx, 12
mul ebx
mov edi, eax
- add edi, OWNMODE
+ add edi, VESAMODES
mov [edi+10], cx ; copy mode
@@ -74,22 +77,22 @@ vesa:
mov al, ' '
call print_chr
- mov ax, [VESAMODE+16] ; copy pitch
+ mov ax, [vesamode+16] ; copy pitch
mov [edi+0], ax
- movzx eax, word[VESAMODE+18] ; copy width
+ movzx eax, word[vesamode+18] ; copy width
mov [edi+2], ax
call print_dec
mov al, 'x'
call print_chr
- movzx eax, word[VESAMODE+20] ; copy height
+ movzx eax, word[vesamode+20] ; copy height
mov [edi+4], ax
call print_dec
call newline
- mov eax, [VESAMODE+40] ; copy framebuffer
+ mov eax, [vesamode+40] ; copy framebuffer
mov [edi+6], eax
pop ebx
@@ -132,17 +135,21 @@ vesa:
mov eax, edi
mov ebx, 12
mul ebx
- add eax, OWNMODE
+ add eax, VESAMODES
; copy to final gfx info location
- mov ebx, [eax+0]
- mov [GFXINFO+0], ebx
+ mov bx, [eax+0]
+ mov [bootinfo.gfx_pitch], bx
+
+ mov bx, [eax+2]
+ mov [bootinfo.gfx_width], bx
- mov ebx, [eax+4]
- mov [GFXINFO+4], ebx
+ mov bx, [eax+4]
+ mov [bootinfo.gfx_height], bx
- mov bx, [eax+8]
- mov [GFXINFO+8], bx
+ mov ebx, [eax+6]
+ mov dword[bootinfo.gfx_framebuffer+0], ebx
+ mov dword[bootinfo.gfx_framebuffer+4], 0
;mov edi, eax
;mov eax, [edi+6]