Framebuffer putpixel LEGGOOO! (disabled paging lol)

This commit is contained in:
Jarkko Toivanen 2023-08-02 20:16:43 +03:00
parent 8709de5747
commit 3c121e97f4
Signed by: jt
GPG key ID: 9151B109B73ECAD5
3 changed files with 121 additions and 41 deletions

74
src/framebuffer.asm Normal file
View file

@ -0,0 +1,74 @@
;; x, y, r, g, b
putpixel:
push ebp
mov ebp, esp
push eax
push ebx
push ecx
push edi
; Destination
std
mov edi, [mbootinfo.fb_addr]
mov eax, [mbootinfo.fb_pitch]
mul dword [ebp+12] ;y
add edi, eax
mov eax, [ebp+8] ;x
mul byte [mbootinfo.fb_bytespp]
dec eax
add edi, eax
movzx eax, [mbootinfo.fb_bytespp]
dec eax
add edi, eax
; Blue
mov ebx, [ebp + 24]
mov cl, [mbootinfo.fb_bpos]
shl ebx, cl
or eax, ebx
; Green
mov ebx, [ebp + 20]
mov cl, [mbootinfo.fb_gpos]
shl ebx, cl
or eax, ebx
; Red
mov ebx, [ebp + 16]
mov cl, [mbootinfo.fb_rpos]
shl ebx, cl
or eax, ebx
cmp [mbootinfo.fb_bpp], 24
je .24bpp
jne .32bpp
.done:
pop edi
pop ecx
pop ebx
pop eax
pop ebp
ret
.32bpp:
stosb
shr eax, 8
stosb
shr eax, 8
stosb
shr eax, 8
stosb
jmp .done
.24bpp:
;shr eax, 8
stosb
shr eax, 8
stosb
shr eax, 8
stosb
jmp .done
.msg db 10, ":D", 10, 0

View file

@ -65,6 +65,12 @@ mbootgetinfo:
mov edi, mbootinfo.fb_rpos mov edi, mbootinfo.fb_rpos
rep movsb rep movsb
.bytesppcalc:
xor eax, eax
mov al, [mbootinfo.fb_bpp]
mov ebx, 8
div bl
mov [mbootinfo.fb_bytespp], al
.done: .done:
pop edi pop edi
pop esi pop esi
@ -116,3 +122,4 @@ mbootinfo:
.fb_gmasksize db 0 .fb_gmasksize db 0
.fb_bpos db 0 .fb_bpos db 0
.fb_bmasksize db 0 .fb_bmasksize db 0
.fb_bytespp db 0

View file

@ -11,6 +11,9 @@ MB_HEADER_FLAGS equ MB_PAGE_ALIGN or MB_MEMORY_INFO or MB_VIDEO_REQUEST
MB_HEADER_FLAGS equ MB_PAGE_ALIGN or MB_MEMORY_INFO or MB_VIDEO_REQUEST or MB_AOUT_KLUDGE MB_HEADER_FLAGS equ MB_PAGE_ALIGN or MB_MEMORY_INFO or MB_VIDEO_REQUEST or MB_AOUT_KLUDGE
MB_CHECKSUM equ -(MB_HEADER_MAGIC + MB_HEADER_FLAGS) MB_CHECKSUM equ -(MB_HEADER_MAGIC + MB_HEADER_FLAGS)
VWIDTH equ 1024
VHEIGHT equ 768
multiboot: multiboot:
dd MB_HEADER_MAGIC dd MB_HEADER_MAGIC
dd MB_HEADER_FLAGS dd MB_HEADER_FLAGS
@ -21,8 +24,8 @@ multiboot:
dd bss_end ; bss end address dd bss_end ; bss end address
dd start ; entry address dd start ; entry address
dd 0 ; video mode_type (0:fb, 1:txt) (set flags[2]!) dd 0 ; video mode_type (0:fb, 1:txt) (set flags[2]!)
dd 1024 ; video width dd VWIDTH ; video width
dd 768 ; video height dd VHEIGHT ; video height
dd 32 ; video depth dd 32 ; video depth
start: start:
@ -41,10 +44,6 @@ start:
call mbootgetinfo call mbootgetinfo
add esp, 2*4 add esp, 2*4
mov eax, [mbootinfo.fb_addr]
mov dword [eax], 0xffffffff
push stuff.fbaddrmsgpfx push stuff.fbaddrmsgpfx
call serialwrite call serialwrite
add esp, 4 add esp, 4
@ -84,8 +83,8 @@ start:
add esp, 4 add esp, 4
push stuff.x push stuff.x
call serialwrite call serialwrite
add esp, 4 add esp, 4
push dword esp ;destination address push dword esp ;destination address
push dword 10 ;base push dword 10 ;base
xor eax, eax xor eax, eax
@ -100,37 +99,35 @@ start:
add esp, 36 ;Clean reserved uitoa return string from stack 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 ebx, 1
mov edi, pagetable1 mov eax, 1
mov cx, 0
.clearpt1loop: push 0x00 ;B
mov eax, 0x00001000 push 0x00 ;G
mul ecx push 0xff ;R
or eax, 011b ;supervisor, rw, present push ebx ;y
stosd push eax ;x
inc cx call putpixel
cmp cx, 1024 add esp, 20 ;clean stack
jne .clearpt1loop inc eax
push 0x00 ;B
push 0x00 ;G
push 0xff ;R
push ebx ;y
push eax ;x
call putpixel
add esp, 20 ;clean stack
inc ebx
push 0x00 ;B
push 0x00 ;G
push 0xff ;R
push ebx ;y
push eax ;x
call putpixel
add esp, 20 ;clean stack
;; 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 jmp hang
@ -146,6 +143,7 @@ hang:
include "src/serial.asm" include "src/serial.asm"
include "src/mbootinfo.asm" include "src/mbootinfo.asm"
include "src/itoa.asm" include "src/itoa.asm"
include "src/framebuffer.asm"
stuff: stuff:
.bootmsg db 10, "=== rOSka ===", 10, 0 .bootmsg db 10, "=== rOSka ===", 10, 0
@ -153,13 +151,14 @@ stuff:
.fbdimensionsmsgpfx db 10, "Framebuffer dimensions: ", 0 .fbdimensionsmsgpfx db 10, "Framebuffer dimensions: ", 0
.x db "x", 0 .x db "x", 0
align 4096
bss_start: bss_start:
align 4096 ;align 4096
pagedir: ;pagedir:
rb 4096 ; rb 4096
align 4096 ;align 4096
pagetable1: ;pagetable1:
rb 4096 ; rb 4096
align 4096 align 4096
stack_bottom: stack_bottom:
rb 16384 rb 16384