Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add a custom bootloader #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 37 additions & 26 deletions bootloader/boot.asm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,43 @@ boot:
or eax, 0x1 ; on special
mov cr0, eax ; CPU reg cr0


; ---------------------------------------------------------------------
; now we will read the disk for our kernel code
; it is recommended that the disk read must be tried atleast thrice

load_disk:

mov ah, 0x02 ; the BIOS routine for reading disk sectors
mov al, 0x01 ; the number of sectors to read
mov ch, 0x0 ; track/cylinder number
mov cl, 0x3 ; sector number
mov dh, 0x0 ; head number
mov dl, 0x1 ; drive number

int 13h ; on return, ah = status, al = number of sectors read,
jc load_disk_error ; carry = 0 if success, 1 if fail
jmp load_disk_done

;cmp al, 0x01
;jne load_disk_error

load_disk_error:
jmp load_disk

load_disk_done:
cli
hlt



mov ax, 0x1000
mov es, ax
mov bx, 0x0

jmp 0x1000:0x0
hlt

jmp CODE_SEG:boot2 ; long jump to the code segment


Expand Down Expand Up @@ -79,32 +116,6 @@ boot2:
mov gs, ax
mov ss, ax


; ---------------------------------------------------------------------
; let's print something using VGA text

mov ebx, 0xb8000 ; the VGA buffer is located at 0xb8000
; we will be sending all text to this

mov esi, hello ; load the string to be printed

.loop:
lodsb ; load a byte
add al, 0x0 ; check if it is zero
jz halt ; halt if it is
or eax, 0x0200 ; add formatting info
mov word [ebx], ax ; send to VGA
add ebx, 2 ; increment address
jmp .loop

halt:
cli ; clear interrupts flag (block interrupts)
hlt ; hlt

hello:
db "I love OSDev. My bootloader is awesome!", 0


; ---------------------------------------------------------------------
; mark this as bootable

Expand Down
25 changes: 25 additions & 0 deletions shit.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
; ---------------------------------------------------------------------
; let's print something using VGA text

mov ebx, 0xb8000 ; the VGA buffer is located at 0xb8000
; we will be sending all text to this

mov esi, hello ; load the string to be printed

.loop:
lodsb ; load a byte
add al, 0x0 ; check if it is zero
jz halt ; halt if it is
or eax, 0x0200 ; add formatting info
mov word [ebx], ax ; send to VGA
add ebx, 2 ; increment address
jmp .loop

halt:
cli ; clear interrupts flag (block interrupts)
hlt ; hlt

hello:
db "I love OSDev. My bootloader is awesome!", 0