Archive / / / / boot.asm
2002-10-02 23:16:20 UTC
previous next
section boot progbits alloc exec write align=16 align 4 dd 0x1BADB002 dd (1<<0) | (1<<1) ; Bits 0 and 1 set (Page align and Memory fields) dd -(0x1BADB002 + ((1<<0) | (1<<1))) db 'NAME:kryptOS version 0.01',0,'VERSION:0.01',0,'SITE:http://kr4z.com/',0 times 10 dd 0 tempstack: msg_starting db 'Starting kryptOS version 0.01...',10,10,0 msg_getting_boot_info db 'Getting system information and command line from boot loader...',0 msg_failed db 'Failed',0 msg_bad_multiboot db 10,10,'You must use a multiboot compatible boot loader and supply a command line.',0 global entry: entry: mov ecx, tempstack mov esp, ecx push ebx push eax push msg_starting push 0x0F call print_string add esp, 8 call check_multiboot_magic add esp, 4 call parse_command_line parse_command_line: jmp parse_command_line check_multiboot_magic: push msg_getting_boot_info push 0x07 call print_string add esp, 8 cmp [esp+4], dword 0x2BADB002 jne .bad_multiboot ret .bad_multiboot: push msg_failed push 0x0C call print_string add esp, 8 push msg_bad_multiboot push 0x07 call print_string add esp, 8 .hang: jmp .hang ; ----------------------------------------------------------------------- ; ; void print_string(char color, char *string) ; ; ----------------------------------------------------------------------- ; print_string: xor eax, eax ; Clear eax ; -- Get Cursor position -- mov al, 0x0E mov dx, 0x3d4 out dx, al ; Get high byte of cursor address mov dx, 0x3d5 in al, dx mov bl, al mov al, 0x0F mov dx, 0x3d4 out dx, al ; Get low bytes of cursor address mov dx, 0x3d5 in al, dx mov ah, bl ; -- AX now contains the address of the cursor (row*80)+col -- shl ax, 1 ; Multiply AX by 2 so we can add this to ; 0xb8000 to find the address to print the string add eax, dword 0xb8000 mov edi, eax mov esi, [esp+8] ; Get string to print mov ebx, [esp+4] ; Get colour cld ; Clear direction flag (for lodsb/stosb instructions) .loop: lodsb cmp al, byte 0 je .loop.done cmp al, byte 10 je .loop.newline stosb mov al, bl stosb jmp .loop .loop.newline: sub edi, 0xb8000 mov edx, 0 mov eax, edi mov ecx, 160 div ecx mul ecx add eax, (160 + 0xb8000) mov edi, eax jmp .loop .loop.done: ; -- Update cursor -- mov ebx, edi sub ebx, 0xb8000 shr ebx, 1 mov al, 0x0F mov dx, 0x3d4 out dx, al ; Set low byte of cursor address mov al, bl mov dx, 0x3d5 out dx, al mov al, 0x0E mov dx, 0x3d4 out dx, al ; Set high byte of cursor address mov al, bh mov dx, 0x3d5 out dx, al ret