Browse Source

Bootloader second stage

special_first_anniversary_edition
Jørn Guldberg 7 years ago
parent
commit
9378de6717
  1. BIN
      bare-bones-bootloader/bootloader.img
  2. 29
      bare-bones-bootloader/bootloader.nasm
  3. 16
      bare-bones-bootloader/kernel.nasm

BIN
bare-bones-bootloader/bootloader.img

Binary file not shown.

29
bare-bones-bootloader/bootloader.nasm

@ -55,15 +55,19 @@ start:
mov ax, 0x0 mov ax, 0x0
mov es, ax ;Section to write into mov es, ax ;Section to write into
mov ah, 0x2 ;Read sectors from drive mov ah, 0x2 ;Read sectors from drive
mov al, 0x8 ;Number of sectors to read mov al, 0x08 ;Number of sectors to read
mov ch, 0x0 ;Low 8 bits of cylinder mov ch, 0x0 ;Low 8 bits of cylinder
mov cl, 0x2 ;First sector to read (bits 0-5), upper bits of cylinder (bits 6-7) mov cl, 0x5 ;First sector to read (bits 0-5), upper bits of cylinder (bits 6-7)
mov dh, 0x0 ;Head number mov dh, 0x0 ;Head number
mov dl, 0x0 ;Drive number mov dl, 0x0 ;Drive number
mov bx, 0x7e00 ;Offset into section mov bx, 0x7e00 ;Offset into section
int 0x13 ;Low level disk services int 0x13 ;Low level disk services
;mov [0x7000], es ; saving retult of read ;mov [0x7000], es ; saving retult of read
; ;
mov si, 500
mov cx, 512
call b_dumpmem
jnc notcarry jnc notcarry
mov si, error_str mov si, error_str
call print call print
@ -143,10 +147,29 @@ print:
.done: .done:
ret ret
b_dumpmem:
push ax
push dx
call printCRLF
shr cx, 1
xor dx, dx ; zero dx
.loop:
cmp dx, cx
jae .end
mov ax, word [esi + 2*edx]
call dumpax
mov ax, 0xe20
int 0x10
inc dx
jmp .loop
.end:
pop dx
pop ax
ret
; Pad to 510 bytes (boot sector size minus 2) with 0s, and finish with the two-byte standard boot signature ; Pad to 510 bytes (boot sector size minus 2) with 0s, and finish with the two-byte standard boot signature
times 510-($-$$) db 0 times 510-($-$$) db 0
dw 0xAA55 ; => 0x55 0xAA (little endian byte order) dw 0xAA55 ; => 0x55 0xAA (little endian byte order)
times 2048-($-$$) db 0
%include "kernel.nasm" %include "kernel.nasm"

16
bare-bones-bootloader/kernel.nasm

@ -1,9 +1,15 @@
BITS 16 BITS 16
ORG 0 ORG 0
start_sing_os: start_sing_os:
mov si, welcome ; Put address of the null-terminated string to output into 'si' mov ax, welcome
sub ax, 1536
mov si, ax ; Put address of the null-terminated string to output into 'si'
call print_os ; Call our string-printing routine call print_os ; Call our string-printing routine
mov si, command_line
mov ax, command_line
sub ax, 1536
mov si, ax
call print_os call print_os
jmp terminal jmp terminal
@ -105,7 +111,7 @@ wait_for_key_os:
call stringcompare call stringcompare
jne .not_dumpmem jne .not_dumpmem
call printCRLF_os call printCRLF_os
lea si, [start_sing_os] mov si, 0x7e0 ;[start_sing_os]
mov cx, 512 mov cx, 512
call dumpmem call dumpmem
.not_dumpmem: .not_dumpmem:
@ -155,7 +161,9 @@ wait_for_key_os:
int 0x10 int 0x10
.no_str: .no_str:
mov si, command_line mov ax, command_line
sub ax, 1536
mov si, ax
call print_os call print_os
jmp .return_enter jmp .return_enter

Loading…
Cancel
Save