From 6139ea78751bcb2ba086d141caade1486a3786f7 Mon Sep 17 00:00:00 2001 From: Lauren Toivanen Date: Tue, 28 Oct 2025 22:00:29 +0200 Subject: [PATCH] We put R, G and B pixel on top left to see if framebuffer works. Why wouldn't it! --- .gitignore | 2 + README.md | 34 ++++++++++ roska.fasm | 188 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 224 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 roska.fasm diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8ce1068 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.bin +mnt/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..e453605 --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ +# rOSka + + - Probably useless hobby OS project + - Targets 32bit legacy systems with graphical framebuffer + - Boots with multiboot compatible bootloader, such as GRUB + - Assembles with FASM + - We'll probably use ext2 filesystem + + ## GRUB disk creation + + 1. Format disk. Create ext2 partition + 2. Create directory mnt and mount your partition to it + ``` + mkdir mnt + sudo mount /dev/sdX mnt + ``` + 3. Intall grub using `sudo grub-install --target=i386-pc --removable --boot-dir=mnt/boot /dev/sdX` + 4. Create config + ``` mnt/boot/grub/grub.cfg + menuentry "rOSka" { + multiboot /boot/roska.bin + boot + } + ``` +5. Copy assembled kernel to `mnt/boot/roska.bin` + + + + + + + +Oh yeah heres a montrosity I currently use. +`fasm roska.fasm && sudo mount /dev/sdd1 mnt/ && sudo cp roska.bin mnt/boot/roska.bin && sudo umount /dev/sdd1 && sudo sync && sudo qemu-system-i386 /dev/sdd` diff --git a/roska.fasm b/roska.fasm new file mode 100644 index 0000000..9857b2a --- /dev/null +++ b/roska.fasm @@ -0,0 +1,188 @@ +format binary +use32 +org 0x100000 + +MB_HEADER_MAGIC equ 0x1BADB002 +MB_PAGE_ALIGN equ (1 shl 0) +MB_MEMORY_INFO equ (1 shl 1) +MB_VIDEO_REQUEST equ (1 shl 2) +MB_AOUT_KLUDGE equ (1 shl 16) +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_CHECKSUM equ -(MB_HEADER_MAGIC + MB_HEADER_FLAGS) + +;; safe modes according to https://wiki.osdev.org/VESA_Video_Modes +VWIDTH equ 640 ; 640/720 +VHEIGHT equ 480 ; 480 +VDEPTH equ 32 ; 24/32 + +multiboot: + dd MB_HEADER_MAGIC + dd MB_HEADER_FLAGS + dd MB_CHECKSUM + dd multiboot ; header address + dd 0x100000 ; load address + dd bss_start ; load end address + dd bss_end ; bss end address + dd start ; entry address + + dd 0 ; video mode_type (0:fb, 1:txt) (set flags[2]!) + dd VWIDTH ; video width + dd VHEIGHT ; video height + dd VDEPTH ; video depth + +start: + ; Setup stack + mov ebp, stack_top + mov esp, stack_top + + ;push ebx ; mboot info struct addr + ;push eax ; 0x2BADB002 + + ;mov [mbootmagic], eax + ;mov [mbootaddr], ebx + + ; store video info + mov ecx, [ebx+88] + mov [fb.addr], ecx + mov ecx, [ebx+98] + mov [fb.pitch], ecx + mov ecx, [ebx+100] + mov [fb.width], ecx + mov ecx, [ebx+104] + mov [fb.height], ecx + mov cl, [ebx+108] + mov [fb.depth], cl + + ; calculate bytespp + movzx eax, cl + mov cl, 8 + div byte cl + mov [fb.bytespp], al + + ; color component positions + mov cl, [ebx+110+2] + mov [fb.rpos], cl + ;mov cl, [ebx+111] + ;mov [fb.rmasksize], cl + mov cl, [ebx+112+2] + mov [fb.gpos], cl + ;mov cl, [ebx+113] + ;mov [fb.gmasksize], cl + mov cl, [ebx+114+2] + mov [fb.bpos], cl + ;mov cl, [ebx+115] + ;mov [fb.bmasksize], cl +testpixels: + ; construct pixel R + mov al, 0xff ;r + mov ah, 0x00 ;g + mov ch, 0x00 ;b + xor edx, edx ;final pixel + ;ebx is temp pixel + movzx ebx, al + mov cl, [fb.rpos] + shl ebx, cl + ;and ebx, [fb.rmasksize] + or edx, ebx + movzx ebx, ah + mov cl, [fb.gpos] + shl ebx, cl + ;and ebx, [fb.gmasksize] + or edx, ebx + movzx ebx, ch + mov cl, [fb.bpos] + shl ebx, cl + ;and ebx, [fb.bmasksize] + or edx, ebx + mov ecx, [fb.addr] + mov [ecx], edx + + ; construct pixel G + mov al, 0x00 ;r + mov ah, 0xff ;g + mov ch, 0x00 ;b + xor edx, edx ;final pixel + ;ebx is temp pixel + movzx ebx, al + mov cl, [fb.rpos] + shl ebx, cl + ;and ebx, [fb.rmasksize] + or edx, ebx + movzx ebx, ah + mov cl, [fb.gpos] + shl ebx, cl + ;and ebx, [fb.gmasksize] + or edx, ebx + movzx ebx, ch + mov cl, [fb.bpos] + shl ebx, cl + ;and ebx, [fb.bmasksize] + or edx, ebx + mov ecx, [fb.addr] + movzx ebx, [fb.bytespp] + add ecx, ebx + mov [ecx], edx + + ; construct pixel B + mov al, 0x00 ;r + mov ah, 0x00 ;g + mov ch, 0xff ;b + xor edx, edx ;final pixel + ;ebx is temp pixel + movzx ebx, al + mov cl, [fb.rpos] + shl ebx, cl + ;and ebx, [fb.rmasksize] + or edx, ebx + movzx ebx, ah + mov cl, [fb.gpos] + shl ebx, cl + ;and ebx, [fb.gmasksize] + or edx, ebx + movzx ebx, ch + mov cl, [fb.bpos] + shl ebx, cl + ;and ebx, [fb.bmasksize] + or edx, ebx + mov ecx, [fb.addr] + movzx ebx, [fb.bytespp] + add ecx, ebx + add ecx, ebx + mov [ecx], edx + + ;mov dword [edx], 0xff00ff00 +testpixels_end: + +hang: + ;cli + .loop: + ;hlt + jmp .loop +error: + mov dword [0xFD000000], 0x00FF0000 + jmp hang + +mbootaddr: dd 0 +mbootmagic: dd 0 +fb: + .addr dd 0 + .pitch dd 0 + .width dd 0 + .height dd 0 + .depth db 0 + .bytespp db 0 + .rpos db 0 + ;.rmasksize db 0 + .gpos db 0 + ;.gmasksize db 0 + .bpos db 0 + ;.bmasksize db 0 + +align 4096 +bss_start: +align 4096 +stack_bottom: +rb 16384 +stack_top: +bss_end: