feat: fetch VESA information

This commit is contained in:
d0p1 🏳️‍⚧️ 2024-06-29 16:29:15 +02:00
parent c682f38209
commit 16d9802872
3 changed files with 50 additions and 19 deletions

View file

@ -59,7 +59,7 @@ _start:
; StupidFS layout ; StupidFS layout
; +---------+---------+---------....--+----....---+ ; +---------+---------+---------....--+----....---+
; | bootsec | stpd sb | i-nodes ... | data | ; | bootsec | stpd sb | i-nodes ... | data |
; +---------+---------+---------0...--+----....---+ ; +---------+---------+---------....--+----....---+
; 0 512 1024 XXXX XXXX ; 0 512 1024 XXXX XXXX
; ;
@ -95,7 +95,6 @@ _start:
xor bx, bx xor bx, bx
call fat_load_binary call fat_load_binary
xchg bx, bx
; fetch memory map from bios ; fetch memory map from bios
call memory_get_map call memory_get_map
jc .error_memory jc .error_memory
@ -187,8 +186,8 @@ common32:
jl .2 jl .2
.2: .2:
.3:
.3:
push STPDBOOT_MAGIC push STPDBOOT_MAGIC

View file

@ -48,9 +48,15 @@ defn AddressRange
;; ECX - Buffer Size ;; ECX - Buffer Size
;; EBX - Continuation ;; EBX - Continuation
memory_e820_get_map: memory_e820_get_map:
clc
@@:
mov eax, 0xE820 mov eax, 0xE820
mov ebx, 0x0 mov ebx, 0x0
mov ecx, 'SMAP' mov edx, 'SMAP'
jc @f
cmp eax, 'SMAP'
jne @f
@@:
ret ret
@ -71,10 +77,8 @@ memory_get_for_large_conf:
int 0x15 int 0x15
jc @f jc @f
xor ecx, ecx xor ecx, ecx
mov cx, ax push ax
push ecx push bx
mov cx, bx
push ecx
mov si, szMsgLarge mov si, szMsgLarge
call bios_log call bios_log
@@: @@:
@ -89,6 +93,9 @@ memory_get_for_large_conf:
;; CF - Non-Carry - indicates no error ;; CF - Non-Carry - indicates no error
;; AX - Number of contiguous KB above 1MB ;; AX - Number of contiguous KB above 1MB
memory_get_map: memory_get_map:
call memory_e820_get_map
jnc .end
call memory_get_for_large_conf call memory_get_for_large_conf
jnc .end jnc .end
clc clc
@ -115,4 +122,4 @@ memory_get_map:
szMsgMaxMemKB db "%x KB above 1MB", 0 szMsgMaxMemKB db "%x KB above 1MB", 0
szMsgMaxPage db "%x pages", 0 szMsgMaxPage db "%x pages", 0
szMsgLarge db "%x KB above 1MB - %x * 64 KB above 16MB", 0 szMsgLarge db "%d KB above 1MB - %d * 64 KB above 16MB", 0

View file

@ -1,11 +1,10 @@
struc VesaInfo struc VesaInfo
{ {
.Signature dd ? .Signature dd 'VBE2'
.Version dw ? .Version dw ?
.OEMNamePtr dd ? .OEMNamePtr dd ?
.Capabilities dd ? .Capabilities dd ?
.VideoModesOffset dw ? .VideoModesPtr dw ?
.VideoModesSegment dw ?
.CountOf64KBlocks dw ? .CountOf64KBlocks dw ?
.OEMSoftwareRevision dw ? .OEMSoftwareRevision dw ?
.OEMVendorNamePtr dd ? .OEMVendorNamePtr dd ?
@ -14,7 +13,6 @@ struc VesaInfo
.Reserved db 222 dup(?) .Reserved db 222 dup(?)
.OEMData db 256 dup(?) .OEMData db 256 dup(?)
} }
defn VesaInfo
struc VesaModeInfo struc VesaModeInfo
{ {
@ -57,32 +55,59 @@ struc VesaModeInfo
.OffScreenMemorySize dd ? .OffScreenMemorySize dd ?
.Reserved2 db 206 dup(?) .Reserved2 db 206 dup(?)
} }
defn VesaModeInfo
video_setup: video_setup:
mov si, szMsgDetectVideo
call bios_log
clc clc
mov di, [vesa_block_buffer] xchg bx, bx
xor ax, ax
mov es, ax
mov di, vesa_block_buffer
mov ax, 0x4F00 mov ax, 0x4F00
int 0x10 int 0x10
cmp ax, 0x004F cmp ax, 0x004F
jne .err jne .err
cmp [vesa_block_buffer.Signature], 'VESA'
jne .err
push [vesa_block_buffer.OEMProductNamePtr]
push [vesa_block_buffer.OEMVendorNamePtr]
push [vesa_block_buffer.CountOf64KBlocks]
push [vesa_block_buffer.OEMNamePtr]
xor ecx, ecx
mov cx, [vesa_block_buffer.Version]
push ecx
mov si, szMsgVesaInfo
call bios_log
push word [vesa_block_buffer + VesaInfo.VideoModesSegment]
pop es
mov di, vesa_info_block_buffer mov di, vesa_info_block_buffer
mov bx, [vesa_block_buffer + VesaInfo.VideoModesOffset] mov bx, [vesa_block_buffer.VideoModesPtr]
mov cx, [bx] mov cx, [bx]
cmp cx, 0xFFFF cmp cx, 0xFFFF
je .err je .err
clc
mov ax, 0x4F01 mov ax, 0x4F01
int 0x10 int 0x10
cmp ax, 0x004F cmp ax, 0x004F
jne .err jne .err
push dword [vesa_info_block_buffer.Framebuffer]
mov si, szMsgFramebuffer
call bios_log
ret ret
.err: .err:
mov si, szMsgErrorVesa
call bios_log
stc stc
ret ret
align 4
vesa_block_buffer VesaInfo vesa_block_buffer VesaInfo
vesa_info_block_buffer VesaModeInfo vesa_info_block_buffer VesaModeInfo
szMsgVesaInfo db "Version: %x", CR, LF, "OEM Name: %s", CR, LF, "Total Memory: %d", CR, LF, "Vendor name: %s", CR, LF, "Product name: %s", 0
szMsgDetectVideo db "Fetch video information.", 0
szMsgFramebuffer db "Fb: 0x%x", 0
szMsgErrorVesa db "Failed to detect VBE mode", 0