Archive / / / / boot.asm
2002-10-05 01:27:59 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 msg_no_command_line db 10,10,'You must 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: mov ebx, [esp+4] mov eax, [ebx] ; Get multiboot structure bitfield bt eax, 2 ; Check for command line jnc .no_command_line mov eax, [ebx+16] ; Get address of command line string push eax .command_line_loop: push arg_init call compare_argument_string add esp, 4 cmp eax, dword 0 jne .found_init call skip_argument add esp, 4 push eax jmp .command_line_loop .found_init: push eax call end_argument add esp, 4 .hang: jmp .hang .no_command_line: push msg_failed push 0x0C call print_string add esp, 8 push msg_no_command_line push 0x07 call print_string add esp, 8 .no_command_line.hang: jmp .no_command_line.hang 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 ; ----------------------------------------------------------------------- ; ; int compare_argument_string(char *argument_name, char *command_line) ; ; ----------------------------------------------------------------------- ; compare_argument_string: mov esi, [esp+4] mov edi, [esp+8] mov ecx, 30 repe cmpsb cmp [esi], byte 0 jne .not_equal cmp [edi], byte 32 ; Space je .trim_space .check_equal_sign: cmp [edi], byte 61 ; = sign je .trim_equal .trim_space: ; Change this to use SCASB inc edi cmp [edi], byte 32 ; Space je .trim_space jmp .check_equal_sign .trim_space2: inc edi cmp [edi], byte 32 ; Space je .trim_space2 jmp .equal .trim_equal: inc edi cmp [edi], byte 32 ; Space je .trim_space2 .equal: mov eax, edi ret .not_equal: xor eax, eax ; Return 0 ret ; ----------------------------------------------------------------------- ; ; 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