Archive / / / / boot.asm
2002-09-29 01:45:19 UTC
previous next
section boot.data progbits alloc noexec write align=4 loading_message db 'Starting kryptOS 0.03.02...',10,10,0 parsing_cmdline_message db 'Getting settings from command line...',0 failed_message db 'Failed',10,10,0 must_use_multiboot_message db 'You must use a multiboot compatible boot loader to boot kryptOS',0 init_argument db 'init',0 mem_argument db 'mem',0 lower_mem_argument db 'lower_mem',0 must_specify_init_message db 'You must specify a value for init on the command line',0 section boot.text progbits alloc exec nowrite align=16 MB_PAGE_ALIGN equ 1<<0 MB_MEM_FIELDS equ 1<<1 align 4 dd 0x1BADB002 dd MB_PAGE_ALIGN | MB_MEM_FIELDS dd -(0x1BADB002 + (MB_PAGE_ALIGN | MB_MEM_FIELDS)) db 'NAME:kryptOS version 0.03.02',0,'VERSION:0.03.02',0,'SITE:http://kr4z.com/',0 global entry entry: mov ecx, 0x500000 mov esp, ecx push ebx push eax push loading_message push 0x0F call print_string add esp, 8 push parsing_cmdline_message push 0x07 call print_string add esp, 8 pop eax cmp eax, 0x2BADB002 je .good_multiboot push failed_message push 0x0C call print_string ; Dont bother recovering stack space.. ; We're just gonna hang push must_use_multiboot_message push 0x07 call print_string jmp hang .good_multiboot: mov eax, [esp] ; Same as pop eax, but doesn't remove it from the stack mov ebx, [eax] push ebx ; esp+4 = pointer to structure ; esp = flags bt ebx, 2 ; Check for command line jc .command_line_exists push failed_message push 0x0C call print_string ; Dont bother recovering stack space.. ; We're just gonna hang push must_specify_init_message push 0x07 call print_string jmp hang .command_line_exists: mov eax, [esp+4] mov ebx, [eax+16] push ebx ; esp+8 = pointer to structure ; esp+4 = flags ; esp = command line address .command_line_loop: ; command line already pushed push init_argument call compare_argument_string add esp, 4 cmp eax, dword 0 jne .found_init ; command line already pushed call skip_argument add esp, 4 push eax jmp .command_line_loop .found_init: push eax call end_argument add esp, 4 push eax push 0x07 call print_string hang: jmp hang ; ----------------------------------------------------------------------- ; ; void parse_command_line(char *command_line) ; ; ----------------------------------------------------------------------- ; parse_command_line: ret ; ----------------------------------------------------------------------- ; ; 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) ; add eax, 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