145 lines
		
	
	
	
		
			2.4 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
			
		
		
	
	
			145 lines
		
	
	
	
		
			2.4 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
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 80 ; 640/720
 | 
						|
VHEIGHT equ 25 ; 480
 | 
						|
VDEPTH  equ 0  ; 24/32, zero in textmode
 | 
						|
 | 
						|
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 1	; 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
 | 
						|
 | 
						|
	call con_disable_cursor
 | 
						|
	call conclear
 | 
						|
 | 
						|
	mov esi, msg.roskainiting
 | 
						|
	call conwriteln
 | 
						|
 | 
						|
 | 
						|
hang:
 | 
						|
	;cli
 | 
						|
	.loop:
 | 
						|
		;hlt
 | 
						|
		jmp .loop
 | 
						|
 | 
						|
;give character in AL
 | 
						|
conputchar:
 | 
						|
	mov ah, [txtbuf.col]
 | 
						|
	mov dx, ax
 | 
						|
	; dx has the whole character cell now
 | 
						|
	xor eax, eax
 | 
						|
	mov al, [txtbuf.y]
 | 
						|
	mov bl, 25
 | 
						|
	mul bl
 | 
						|
	movzx bx, [txtbuf.x]
 | 
						|
	add ax, bx
 | 
						|
	add ax, ax
 | 
						|
	add eax, 0xb8000
 | 
						|
	mov [eax], dx
 | 
						|
	cmp bl, 24
 | 
						|
	je connewline
 | 
						|
	inc bl
 | 
						|
	mov [txtbuf.x], bl
 | 
						|
	ret
 | 
						|
conwriteln:
 | 
						|
	lodsb
 | 
						|
	cmp al, 0
 | 
						|
	je connewline
 | 
						|
	call conputchar
 | 
						|
	jmp conwriteln
 | 
						|
connewline:
 | 
						|
	mov [txtbuf.x], 0
 | 
						|
	mov al, [txtbuf.y]
 | 
						|
	cmp al, 24
 | 
						|
	je conscroll
 | 
						|
	inc al
 | 
						|
	mov [txtbuf.y], al
 | 
						|
	ret
 | 
						|
conscroll:
 | 
						|
	ret
 | 
						|
 | 
						|
conclear:
 | 
						|
	mov ecx, 80*25
 | 
						|
	mov edi, 0xb8000
 | 
						|
	mov ah, 0x07
 | 
						|
	mov al, 0
 | 
						|
	rep stosw
 | 
						|
	mov [txtbuf.col], ah
 | 
						|
	mov [txtbuf.x], 0
 | 
						|
	mov [txtbuf.y], 0
 | 
						|
	ret
 | 
						|
 | 
						|
con_disable_cursor:
 | 
						|
	mov dx, 0x3D4
 | 
						|
	mov al, 0xA	; low cursor shape register
 | 
						|
	out dx, al
 | 
						|
 | 
						|
	inc dx
 | 
						|
	mov al, 0x20	; bits 6-7 unused, bit 5 disables the cursor, bits 0-4 control the cursor shape
 | 
						|
	out dx, al
 | 
						|
	ret
 | 
						|
 | 
						|
mbootaddr: dd 0
 | 
						|
mbootmagic: dd 0
 | 
						|
txtbuf:
 | 
						|
	.x db 0
 | 
						|
	.y db 0
 | 
						|
	.col db 0x07 ;gray on black
 | 
						|
 | 
						|
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
 | 
						|
 | 
						|
msg:
 | 
						|
	.roskainiting db "rOSka initializing...", 0
 | 
						|
 | 
						|
align 4096
 | 
						|
bss_start:
 | 
						|
align 4096
 | 
						|
stack_bottom:
 | 
						|
rb 16384
 | 
						|
stack_top:
 | 
						|
bss_end:
 |