From d5c3d73e7d1ea90cd6e293881bda1a13bd20e3d4 Mon Sep 17 00:00:00 2001 From: iximeow Date: Sat, 27 Sep 2014 12:35:35 -0700 Subject: Strip down bootloader and tweak to load multiple blocks --- bootloader.asm | 75 +++++++++-------------------- excessive.asm | 147 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ linker.ld | 4 +- 3 files changed, 170 insertions(+), 56 deletions(-) create mode 100644 excessive.asm diff --git a/bootloader.asm b/bootloader.asm index 2993726..cf8ccb4 100644 --- a/bootloader.asm +++ b/bootloader.asm @@ -10,21 +10,10 @@ start: mov si, HELLO call write_str call disk_read - mov si, VERIFY + call verify_read + mov si, READ_NERR call write_str - mov ax, 0x61 - call cursor_next_line - call write_char_default_attr - mov ax, 0x62 - call cursor_next_line - call write_char_default_attr - mov ax, 0x63 - call cursor_next_line - call write_char_default_attr - call write_char_default_attr - call write_char_default_attr - call cursor_back_one - call cursor_backspace + jmp 0x7e00 jmp hang read_err: @@ -33,6 +22,21 @@ read_err: hang: jmp hang +verify_read: + mov al, 0x66 + cmp al, [0x7e00] + jne read_err + mov al, 0x55 + cmp al, [0x7e01] + jne read_err + mov al, 0x66 + cmp al, [0x7e02] + jne read_err + mov al, 0x89 + cmp al, [0x7e03] + jne read_err + ret + write_str: push ax push si @@ -86,14 +90,12 @@ disk_read: mov ah, 0x42 int 0x13 jc read_err - mov si, READ_SUCC - call write_str ret READ_ERR: db 'Read failed: ', 0 -READ_SUCC: - db 'Read didnt fail: ', 0 +READ_NERR: + db 'No err reading, continuing: ', 0 HELLO: db 'Bootloader init: ', 0 CURSOR_LOC: @@ -103,45 +105,12 @@ CURSOR_LOC: LBA_DISK_READ_PACKET: db 0x10 db 0 - dw 1 ; number of blocks to read, reset to # actually read when done + dw 32 ; number of blocks to read, reset to # actually read when done dw 0x7e00 ; read destination address - dw 0 + dw 0x0000 dd 1 ; lba to read from dd 0 ; for extended lba adresses (not really used here) times 510-($-$$) db 0 db 0x55 db 0xAA - -cursor_next_line: - mov di, [CURSOR_LOC] - add di, 160 - mov [CURSOR_LOC], di - ret - -cursor_prev_line: - mov di, [CURSOR_LOC] - sub di, 160 - mov [CURSOR_LOC], di - ret - -cursor_backspace: - push ax - call cursor_back_one - mov ax, 0x00 - call write_char_default_attr - call cursor_back_one - pop ax - ret - -cursor_back_one: - mov di, [CURSOR_LOC] - dec di - dec di - mov [CURSOR_LOC], di - ret - -VERIFY: - db '[x] read next block: ', 0 - - times 1024-($-$$) db 0 diff --git a/excessive.asm b/excessive.asm new file mode 100644 index 0000000..2993726 --- /dev/null +++ b/excessive.asm @@ -0,0 +1,147 @@ +[BITS 16] +[ORG 7c00h] + +init: + mov cx, 0xB800 + mov gs, cx + +start: + call clr_vga + mov si, HELLO + call write_str + call disk_read + mov si, VERIFY + call write_str + mov ax, 0x61 + call cursor_next_line + call write_char_default_attr + mov ax, 0x62 + call cursor_next_line + call write_char_default_attr + mov ax, 0x63 + call cursor_next_line + call write_char_default_attr + call write_char_default_attr + call write_char_default_attr + call cursor_back_one + call cursor_backspace + jmp hang + +read_err: + mov si, READ_ERR + call write_str +hang: + jmp hang + +write_str: + push ax + push si + xor ax, ax +write_str_each_char: + mov al, byte [si] + cmp al, 0 + je write_str_done + inc si + call write_char_default_attr + jmp write_str_each_char +write_str_done: + pop si + pop ax + ret + +write_char_default_attr: + push bx + mov bl, 0x07 + jmp write_char_inner +write_char: + push bx +write_char_inner: + push di + mov di, [CURSOR_LOC] + mov byte [gs:di], al + inc di + mov byte [gs:di], bl + inc di + mov [CURSOR_LOC], di + pop di + pop bx + ret + +clr_vga: + mov di, 4000 +clr_vga_loop: + dec di + mov byte [gs:di], 0x00 + cmp di, 0 + jne clr_vga_loop + mov word [CURSOR_LOC], 0 + ret + +disk_read: + ; ax = disk number to read from + ; reference: http://www.delorie.com/djgpp/doc/rbinter/id/14/7.html + mov dx, 0x80 + or ax, dx + mov si, LBA_DISK_READ_PACKET + mov ah, 0x42 + int 0x13 + jc read_err + mov si, READ_SUCC + call write_str + ret + +READ_ERR: + db 'Read failed: ', 0 +READ_SUCC: + db 'Read didnt fail: ', 0 +HELLO: + db 'Bootloader init: ', 0 +CURSOR_LOC: + dw 0 + + ; reference: http://www.delorie.com/djgpp/doc/rbinter/it/72/2.html +LBA_DISK_READ_PACKET: + db 0x10 + db 0 + dw 1 ; number of blocks to read, reset to # actually read when done + dw 0x7e00 ; read destination address + dw 0 + dd 1 ; lba to read from + dd 0 ; for extended lba adresses (not really used here) + + times 510-($-$$) db 0 + db 0x55 + db 0xAA + +cursor_next_line: + mov di, [CURSOR_LOC] + add di, 160 + mov [CURSOR_LOC], di + ret + +cursor_prev_line: + mov di, [CURSOR_LOC] + sub di, 160 + mov [CURSOR_LOC], di + ret + +cursor_backspace: + push ax + call cursor_back_one + mov ax, 0x00 + call write_char_default_attr + call cursor_back_one + pop ax + ret + +cursor_back_one: + mov di, [CURSOR_LOC] + dec di + dec di + mov [CURSOR_LOC], di + ret + +VERIFY: + db '[x] read next block: ', 0 + + times 1024-($-$$) db 0 diff --git a/linker.ld b/linker.ld index 1b34e93..7486136 100644 --- a/linker.ld +++ b/linker.ld @@ -8,14 +8,13 @@ SECTIONS { /* Begin putting sections at 1 MiB, a conventional place for kernels to be loaded at by the bootloader. */ - . = 1M; + . = 10K; /* First put the multiboot header, as it is required to be put very early early in the image or the bootloader won't recognize the file format. Next we'll put the .text section. */ .text BLOCK(4K) : ALIGN(4K) { - *(.multiboot) *(.text) } @@ -34,7 +33,6 @@ SECTIONS /* Read-write data (uninitialized) and stack */ .bss BLOCK(4K) : ALIGN(4K) { - *(COMMON) *(.bss) *(.bootstrap_stack) } -- cgit v1.1