Compare commits

..

1 commit

Author SHA1 Message Date
33e5891931
fasm-putchar-virittelyy 2023-09-19 19:48:30 +03:00
10 changed files with 213 additions and 273 deletions

2
.gitignore vendored
View file

@ -4,5 +4,3 @@
*.bin *.bin
mnt/ mnt/
build/ build/
bx_enh_dbg.ini
serial.out

View file

@ -4,43 +4,22 @@ clean:
start32.bin: src/* start32.bin: src/*
fasm src/start32.asm start32.bin fasm src/start32.asm start32.bin
image: start32.bin mount grub-cfg roska.img mnt/roska/ image: start32.bin mount
cp start32.bin mnt/roska/ cp start32.bin mnt/roska/
sync sync
qemu-run: image roska.img qemu-multiboot: start32.bin
qemu-system-i386 -kernel start32.bin -serial stdio
qemu-image: image
qemu-system-i386 roska.img -serial stdio qemu-system-i386 roska.img -serial stdio
bochs-run: image roska.img
touch serial.out
bochs -qf bochsrc.txt
mount: roska.img mnt/ mount: roska.img mnt/
@if ! mountpoint -q "mnt/"; then \ @if ! mountpoint -q "mnt/"; then \
sudo mount -o loop,offset=1048576,umask=177,dmask=022,uid=$(shell id -u),gid=$(shell id -g) roska.img mnt/; \ sudo mount -o loop,offset=1048576,umask=177,dmask=022,uid=$(shell id -u),gid=$(shell id -g) roska.img mnt/; \
fi; fi;
umount: umount:
@if mountpoint -q "mnt/"; then \ @sudo umount mnt
sudo umount mnt/; \
fi;
mnt/: mnt/:
@mkdir -p mnt @mkdir mnt
mnt/roska/: mount roska.img
@mkdir -p mnt/roska
build/: build/:
@mkdir build @mkdir build
roska.img: mnt/
dd if=/dev/zero of=roska.img bs=1k count=16128
echo 'type=83' | sudo sfdisk roska.img
sudo losetup /dev/loop0 roska.img
sudo losetup /dev/loop1 roska.img -o1048576
sudo mkdosfs -F32 -f 2 /dev/loop1
sudo mount /dev/loop1 mnt/
sudo grub-install --target=i386-pc --root-directory=mnt --boot-directory=mnt/boot --no-floppy --modules="normal part_msdos multiboot" /dev/loop0
sudo umount mnt/
sudo losetup -d /dev/loop1
sudo losetup -d /dev/loop0
grub-cfg: grub.cfg mount
cp grub.cfg mnt/boot/grub/grub.cfg
lo-unsetup: umount
sudo losetup -d /dev/loop1
sudo losetup -d /dev/loop0

View file

@ -1,14 +0,0 @@
display_library: x, options="gui_debug"
magic_break: enabled=1
romimage: file=$BXSHARE/BIOS-bochs-legacy
vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest
clock: sync=realtime
cpu: ips=4294967295, reset_on_triple_fault=false
megs: 128
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
ata0-master: type=disk, mode=flat, path=roska.img, cylinders=32, heads=16, spt=63
boot: disk
# Use `bximage` to get disk geometry
# Serial is piped to serial.out for your `tail`ing sweetness
com1: enabled=1, mode=file, dev=serial.out

View file

@ -1,3 +0,0 @@
menuentry "rOSka" {
multiboot /roska/start32.bin
}

View file

@ -1,89 +1,38 @@
;;; Resolution: 8x16 ;; Thank you Terminus for letting us use this font under SIL licence
kfontbasicascii: kfont:
;; 0 NULL ; controlchars
db 11001100b times 31 db 0x00000000000000000000000000000000
db 11001100b ; space
db 00110011b db 11000000b
db 00110011b db 10000000b
db 11001100b db 00000000b
db 11001100b db 00000000b
db 00110011b db 00000000b
db 00110011b db 00000001b
db 11001100b db 00000001b
db 11001100b db 00000001b
db 00110011b db 00000001b
db 00110011b db 00000000b
db 11001100b db 00000000b
db 11001100b db 00000000b
db 00110011b db 00000000b
db 00110011b db 00000000b
;; 1-31 control characters db 00000001b
rb 30*16 db 00000011b
;; 32 Space ; !
db 00000000b db 00000000b
db 00000000b db 00000000b
db 00000000b db 00011000b
db 00000000b db 00011000b
db 00000000b db 00011000b
db 00000000b db 00011000b
db 00000000b db 00011000b
db 00000000b db 00011000b
db 00000000b db 00011000b
db 00000000b db 00000000b
db 00000000b db 00011000b
db 00000000b db 00011000b
db 00000000b db 00000000b
db 00000000b db 00000000b
db 00000000b db 00000000b
db 00000000b db 00000000b
;; 33 !
db 00000000b
db 00000000b
db 00000000b
db 00011000b
db 00011000b
db 00011000b
db 00011000b
db 00011000b
db 00011000b
db 00011000b
db 00011000b
db 00000000b
db 00000000b
db 00011000b
db 00011000b
db 00000000b
;; 34 "
db 00000000b
db 01100110b
db 01100110b
db 01100110b
db 01100110b
db 00000000b
db 00000000b
db 00000000b
db 00000000b
db 00000000b
db 00000000b
db 00000000b
db 00000000b
db 00000000b
db 00000000b
db 00000000b
;; 35 #
db 00000000b
db 00000000b
db 00000000b
db 01100110b
db 01100110b
db 11111111b
db 11111111b
db 01100110b
db 01100110b
db 11111111b
db 11111111b
db 01100110b
db 01100110b
db 00000000b
db 00000000b
db 00000000b

View file

@ -1,19 +1,11 @@
macro kputpixel x*, y*, r*, g*, b* { ;; x, y, brightness
push b ;b
push g ;g
push r ;r
push y ;y
push x ;x
call putpixel
add esp, 4*5
}
;; x, y, r, g, b
putpixel: putpixel:
push ebp push ebp
mov ebp, esp mov ebp, esp
push eax
push ebx push ebx
push ecx
push edi push edi
; check pixel is in screen ; check pixel is in screen
@ -36,37 +28,74 @@ putpixel:
add edi, eax add edi, eax
; Brightness
mov eax, [ebp + 16]
; Poke videomemory ; Poke videomemory
xor eax, eax cld
mov ebx, [ebp+16] rep stosb
mov cl, [mbootinfo.fb_rpos]
shl ebx, cl
or eax, ebx
mov ebx, [ebp+20]
mov cl, [mbootinfo.fb_gpos]
shl ebx, cl
or eax, ebx
mov ebx, [ebp+24]
mov cl, [mbootinfo.fb_bpos]
shl ebx, cl
or eax, ebx
cmp [mbootinfo.fb_bpp], 32
jne .bpp24
stosd
jmp .done
.bpp24:
stosb
shr eax, 8
stosb
shr eax, 8
stosb
.done: .done:
pop edi pop edi
pop ecx
pop ebx pop ebx
pop eax
pop ebp pop ebp
ret ret
; char, x, y
putchar:
push ebp
mov ebp, esp
push eax
push ebx
push ecx
push edx
; skip non printable
mov eax, [ebp+8] ;char
cmp eax, 0x20
jl .unprintable
cmp eax, 0x7e
jg .unprintable
mov ecx, 16
mul ecx
mov esi, [kfont+eax]
mov ebx, [ebp+12] ;x
mov edx, [ebp+16] ;y
cld
xor eax, eax
.loop:
lodsb ; load font row to al
mov ah, 0
.loop2:
shl al
jnc .blankpix
; draw a pixel
push 0xff
push edx ;x
push ecx ;y
.blankpix:
inc ah
cmp ah, 8
je .loop
.done:
pop edx
pop ecx
pop ebx
pop eax
pop ebp
ret
.unprintable:
push .unprintablemsg
call serialwrite
add esp, 4
jmp .done
.unprintablemsg: db 10,"Err: Unprintable char not handled!", 0
include "src/font.asm"

View file

@ -1,12 +1,8 @@
;; Modified from: https://gist.github.com/SplittyDev/8e728627012e57ac0deac196660014fb ;; Modified from: https://gist.github.com/SplittyDev/8e728627012e57ac0deac196660014fb
; __itoa(src int, target addr, base)
;target address returned in EAX
;EBX, EBP, ESP preserved as our calling convention,
;refer to docs or something
; ;
; Routine to convert a 32-bit integer to a string. ; Routine to convert a 32-bit integer to a string.
; Registers are preserved.
; ;
; EAX: Source integer ; EAX: Source integer
; EBX: Target address ; EBX: Target address
@ -30,28 +26,19 @@
; ECX: Target address (active) ; ECX: Target address (active)
; EDX: Target address (temporary) ; EDX: Target address (temporary)
; ;
; return:
; put original target at EAX
; (we trust this blindly)
macro kuitoa src*, dest*, base* {
push base
push dest
push src
call __uitoa
add esp, 3*4
}
__uitoa: __uitoa:
.start: .start:
push ebp push ebp
mov ebp, esp mov ebp, esp
push eax
push ebx push ebx
push ecx
push edx
mov eax, [ebp+8] mov eax, [ebp+8]
mov ebx, [ebp+12] mov ecx, [ebp+12]
mov ecx, [ebp+16] mov ebx, [ebp+16]
mov edx, ecx mov edx, ecx
mov ecx, ebx mov ecx, ebx
@ -88,9 +75,11 @@ __uitoa:
dec ecx dec ecx
jmp .reverse jmp .reverse
.end: .end:
pop edx
pop ecx
pop ebx pop ebx
pop eax
mov eax, [ebp+12] ; Return target address
pop ebp pop ebp
ret ret

View file

@ -1,6 +1,7 @@
mbootgetinfo: mbootgetinfo:
push ebp push ebp
mov ebp, esp mov ebp, esp
push ebx
push esi push esi
push edi push edi
cld cld
@ -9,23 +10,23 @@ mbootgetinfo:
cmp eax, 0x2badb002 cmp eax, 0x2badb002
jne mbootnomagic jne mbootnomagic
mov edx, [ebp+12] mov ebx, [ebp+12]
mov eax, [edx] mov eax, [ebx]
mov [mbootinfo.flags], eax mov [mbootinfo.flags], eax
;; Get memoryinformation ;; Get memoryinformation
test eax, 1b test eax, 1b
jz mbootnomeminfo jz mbootnomeminfo
mov eax, [edx+4] mov eax, [ebx+4]
mov [mbootinfo.mem_lower], eax mov [mbootinfo.mem_lower], eax
mov eax, [edx+8] mov eax, [ebx+8]
mov [mbootinfo.mem_upper], eax mov [mbootinfo.mem_upper], eax
;; Get videoinformation ;; Get videoinformation
test [mbootinfo.flags], (1 shl 02) test [mbootinfo.flags], (1 shl 02)
jz mbootnovideoinfo jz mbootnovideoinfo
mov esi, edx mov esi, ebx
add esi, 88 add esi, 88
mov eax, [esi] mov eax, [esi]
mov [mbootinfo.fb_addr], eax mov [mbootinfo.fb_addr], eax
@ -53,8 +54,6 @@ mbootgetinfo:
mov [mbootinfo.fb_type], al mov [mbootinfo.fb_type], al
inc esi inc esi
;garbage?
add esi, 2
;; r/g/b positions and masks ;; r/g/b positions and masks
mov ecx, 6 mov ecx, 6
mov edi, mbootinfo.fb_rpos mov edi, mbootinfo.fb_rpos
@ -63,12 +62,13 @@ mbootgetinfo:
.bytesppcalc: .bytesppcalc:
xor eax, eax xor eax, eax
mov al, [mbootinfo.fb_bpp] mov al, [mbootinfo.fb_bpp]
mov edx, 8 mov ebx, 8
div dl div bl
mov [mbootinfo.fb_bytespp], al mov [mbootinfo.fb_bytespp], al
.done: .done:
pop edi pop edi
pop esi pop esi
pop ebx
pop ebp pop ebp
ret ret

View file

@ -1,14 +1,9 @@
SERIAL_PORT equ 0x3f8 SERIAL_PORT equ 0x3f8
serialinitialized db 0 serialinitialized db 0
; Write null terminated string in address str_pointer to serial
macro serw [str_pointer*] {
push str_pointer
call serialwrite
add esp, 4
}
serialinit: serialinit:
push ax
;Disable ints ;Disable ints
mov dx, SERIAL_PORT+1 mov dx, SERIAL_PORT+1
mov al, 0x00 mov al, 0x00
@ -59,6 +54,7 @@ serialinit:
out dx, al out dx, al
mov [serialinitialized], 1 mov [serialinitialized], 1
.end: .end:
pop ax
ret ret
.errormsg db "Serial init failed", 0 .errormsg db "Serial init failed", 0
@ -68,6 +64,7 @@ serialwrite:
push ebp push ebp
mov ebp, esp mov ebp, esp
push esi push esi
push ax
cld cld
mov esi, [ebp+8] mov esi, [ebp+8]
.loop: .loop:
@ -83,6 +80,7 @@ serialwrite:
out dx, al out dx, al
jmp .loop jmp .loop
.done: .done:
pop ax
pop esi pop esi
pop ebp pop ebp
ret ret

View file

@ -13,7 +13,7 @@ MB_CHECKSUM equ -(MB_HEADER_MAGIC + MB_HEADER_FLAGS)
VWIDTH equ 640 VWIDTH equ 640
VHEIGHT equ 480 VHEIGHT equ 480
VDEPTH equ 32 VDEPTH equ 24
multiboot: multiboot:
dd MB_HEADER_MAGIC dd MB_HEADER_MAGIC
@ -29,13 +29,6 @@ multiboot:
dd VHEIGHT ; video height dd VHEIGHT ; video height
dd VDEPTH ; video depth dd VDEPTH ; video depth
; Includes yayyy
include "src/serial.asm"
include "src/mbootinfo.asm"
include "src/itoa.asm"
include "src/framebuffer.asm"
include "src/roskalogoraw.asm"
start: start:
; Setup stack ; Setup stack
mov ebp, stack_top mov ebp, stack_top
@ -45,60 +38,77 @@ start:
push eax push eax
call serialinit call serialinit
push stuff.bootmsg
serw stuff.bootmsg call serialwrite
add esp, 4
call mbootgetinfo call mbootgetinfo
add esp, 2*4 add esp, 2*4
push stuff.fbaddrmsgpfx
call serialwrite
add esp, 4
sub esp, 36 ;Reserve stack for return sub esp, 36 ;Reserve stack for return
mov ebx, esp ;Store str buff addr push dword esp ;Destination address
push dword 16 ;Base
push dword [mbootinfo.fb_addr] ;source
call __uitoa
add esp, 3*4
push esp
call serialwrite
add esp, 4
kuitoa [mbootinfo.fb_addr], ebx, 16 push stuff.fbdimensionsmsgpfx
serw stuff.fbaddrmsgpfx, ebx call serialwrite
add esp, 4
push dword esp ;destination address
push dword 10 ;base
push dword [mbootinfo.fb_width]
call __uitoa
add esp, 3*4
push esp
call serialwrite
add esp, 4
push stuff.x
call serialwrite
add esp, 4
kuitoa [mbootinfo.fb_width], ebx, 10 push dword esp ;destination address
serw stuff.fbdimensionsmsgpfx, ebx, stuff.x push dword 10 ;base
push dword [mbootinfo.fb_height]
call __uitoa
add esp, 3*4
push esp
call serialwrite
add esp, 4
push stuff.x
call serialwrite
add esp, 4
kuitoa [mbootinfo.fb_height], ebx, 10 push dword esp ;destination address
serw ebx, stuff.x push dword 10 ;base
xor eax, eax
movzx eax, byte [mbootinfo.fb_bpp] mov al, [mbootinfo.fb_bpp]
kuitoa eax, ebx, 10 push dword eax
serw ebx call __uitoa
add esp, 3*4
push esp
movzx eax, byte [mbootinfo.fb_rpos] call serialwrite
kuitoa eax, ebx, 10 add esp, 4
serw stuff.rpostxt, ebx
movzx eax, byte [mbootinfo.fb_gpos]
kuitoa eax, ebx, 10
serw stuff.gpostxt, ebx
movzx eax, byte [mbootinfo.fb_bpos]
kuitoa eax, ebx, 10
serw stuff.bpostxt, ebx
movzx eax, byte [mbootinfo.fb_rmasksize]
kuitoa eax, ebx, 10
serw stuff.rmasksizetxt, ebx
movzx eax, byte [mbootinfo.fb_gmasksize]
kuitoa eax, ebx, 10
serw stuff.gmasksizetxt, ebx
movzx eax, byte [mbootinfo.fb_bmasksize]
kuitoa eax, ebx, 10
serw stuff.bmasksizetxt, ebx
add esp, 36 ;Clean reserved uitoa return string from stack add esp, 36 ;Clean reserved uitoa return string from stack
; Draw a green test pixel to bottom-right ; Draw a test pixel to bottom right corner
kputpixel VWIDTH-1, VHEIGHT-1, 0x00, 0xff, 0x00 mov eax, 0xff
mov ebx, 767
mov ecx, 1023
push 0xff
push 479
push 639
call putpixel
add esp, 3*4
; Draw a predefined logo in magenta to top-left
rOSkalogodraw: rOSkalogodraw:
mov esi, roskalogo mov esi, roskalogo
mov eax, 0 ;Brightness mov eax, 0 ;Brightness
@ -106,12 +116,13 @@ rOSkalogodraw:
mov ecx, 0 ;x mov ecx, 0 ;x
.loop: .loop:
lodsb lodsb
push ecx
push eax push eax
kputpixel ecx, ebx, eax, 0x00, eax push ebx
pop eax push ecx
call putpixel
pop ecx pop ecx
pop ebx
pop eax
inc ecx inc ecx
cmp byte cl, [roskalogo.w] cmp byte cl, [roskalogo.w]
@ -121,32 +132,36 @@ rOSkalogodraw:
cmp byte bl, [roskalogo.h] cmp byte bl, [roskalogo.h]
jne .loop jne .loop
.done: .done:
jmp hang
push byte 0x21
push byte 0x21
push byte 0x21
call putchar
add esp, 3*4
jmp hang
hang: hang:
serw .msg push .msg
call serialwrite
cli cli
.loop: .loop:
hlt hlt
jmp .loop jmp .loop
.msg db 10, "Halting...", 10, 0 .msg db 10, "Halting...", 10, 0
include "src/serial.asm"
include "src/mbootinfo.asm"
include "src/itoa.asm"
include "src/framebuffer.asm"
include "src/roskalogoraw.asm"
stuff: stuff:
.bootmsg db 10, "=== rOSka ===", 10, 0 .bootmsg db 10, "=== rOSka ===", 10, 0
.fbaddrmsgpfx db 10, "Framebuffer address: 0x", 0 .fbaddrmsgpfx db 10, "Framebuffer address: 0x", 0
.fbdimensionsmsgpfx db 10, "Framebuffer dimensions: ", 0 .fbdimensionsmsgpfx db 10, "Framebuffer dimensions: ", 0
.x db "x", 0 .x db "x", 0
.rpostxt db 10, "rPos: ", 0
.gpostxt db 10, "gPos: ", 0
.bpostxt db 10, "bPos: ", 0
.rmasksizetxt db 10, "rMaskSize: ", 0
.gmasksizetxt db 10, "gMaskSize: ", 0
.bmasksizetxt db 10, "bMaskSize: ", 0
align 4096 align 4096
bss_start: bss_start:
;align 4096 ;align 4096