|
|
@ -1,6 +1,19 @@ |
|
|
|
ORG 0x7C00 |
|
|
|
BITS 16 |
|
|
|
;http://www.ousob.com/ng/bios/ng1223.php |
|
|
|
start: |
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
|
|
; Bootloader for SingOS |
|
|
|
; version 0.1.0.0 |
|
|
|
; |
|
|
|
; Please edit the version number if any changes is made, the last number |
|
|
|
; represent the build number. |
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
|
|
|
|
|
|
xor ax, ax |
|
|
|
mov ds, ax |
|
|
|
mov es, ax |
|
|
|
mov ss, ax |
|
|
|
|
|
|
|
; initialize stack |
|
|
|
; Set up 4K stack after this bootloader |
|
|
|
; [Remember: Effective Address = Segment*16 + Offset] |
|
|
|
mov ax, 0x7C0 ; Set 'ax' equal to the location of this bootloader divided by 16 |
|
|
@ -8,12 +21,18 @@ start: |
|
|
|
mov ss, ax ; Set 'ss' to this location (the beginning of our stack region) |
|
|
|
mov sp, 8192 ; Set 'ss:sp' to the top of our 8K stack |
|
|
|
|
|
|
|
; Set data segment to where we're loaded so we can implicitly access all 64K from here |
|
|
|
mov ax, 0x7C0 ; Set 'ax' equal to the location of this bootloader divided by 16 |
|
|
|
mov ds, ax ; Set 'ds' to the this location |
|
|
|
jmp long 0x0000:start |
|
|
|
nop |
|
|
|
|
|
|
|
start: |
|
|
|
nop |
|
|
|
nop |
|
|
|
nop |
|
|
|
nop |
|
|
|
nop |
|
|
|
nop |
|
|
|
|
|
|
|
mov [disk_identifier], dl |
|
|
|
; Print our message and stop execution |
|
|
|
mov si, message ; Put address of the null-terminated string to output into 'si' |
|
|
|
call print ; Call our string-printing routine |
|
|
|
mov si, enter_debug_mode |
|
|
@ -52,32 +71,28 @@ start: |
|
|
|
mov dl, [disk_identifier] ;0x0 ;Drive number |
|
|
|
mov bx, 0x500 ;Offset into section |
|
|
|
int 0x13 ;Low level disk services |
|
|
|
;mov [0x7000], es ; saving retult of read |
|
|
|
; |
|
|
|
;Debug dump of loaded memory |
|
|
|
;mov si, 500 |
|
|
|
;mov cx, 512 |
|
|
|
;call b_dumpmem |
|
|
|
|
|
|
|
jnc notcarry |
|
|
|
mov si, error_str |
|
|
|
call print |
|
|
|
jmp endcarrycheck |
|
|
|
; |
|
|
|
|
|
|
|
notcarry: |
|
|
|
mov si, success_str |
|
|
|
call print |
|
|
|
call printCRLF |
|
|
|
call printCRLF |
|
|
|
mov ax, cs |
|
|
|
call dumpax |
|
|
|
mov ax, start |
|
|
|
call dumpax |
|
|
|
call printCRLF |
|
|
|
|
|
|
|
; xor ax, ax |
|
|
|
; mov al, [disk_identifier] |
|
|
|
; call dumpax |
|
|
|
mov dl, [disk_identifier] |
|
|
|
|
|
|
|
mov ax, 0x50 |
|
|
|
mov ds, ax |
|
|
|
jmp 0x50:0x00 ; 0x500 |
|
|
|
jmp 0x50:0x00 ; Jump to the kernel |
|
|
|
|
|
|
|
endcarrycheck: |
|
|
|
cli ; Clear the Interrupt Flag (disable external interrupts) |
|
|
@ -91,7 +106,7 @@ debug_mode: |
|
|
|
|
|
|
|
.welcome_debug db 'This is debug mode', 0 |
|
|
|
data: |
|
|
|
message db 'Bootloader for SingOS! v0.0.3',13,10,0 |
|
|
|
message db 'Bootloader for SingOS! v0.1.0.0',13,10,0 |
|
|
|
enter_debug_mode db 'Press d to enter bootloader debug mode',13,10,0 |
|
|
|
enter_system_check db 'Performing system check:',13,10,0 |
|
|
|
sys_check_ok db 'System check ok', 13, 10, 0 |
|
|
@ -122,64 +137,64 @@ dumpax: |
|
|
|
popa ; restore registers |
|
|
|
ret |
|
|
|
|
|
|
|
dumpax10: ; Prints ax as 16-bit decimal number |
|
|
|
pusha |
|
|
|
; dumpax10: ; Prints ax as 16-bit decimal number |
|
|
|
; pusha |
|
|
|
|
|
|
|
mov bx, 10 ; Divisor |
|
|
|
; mov bx, 10 ; Divisor |
|
|
|
|
|
|
|
mov cx, 5 ; Loop 5 times |
|
|
|
.loop1: ; finds digits and pushes them to stack |
|
|
|
xor dx, dx |
|
|
|
div bx |
|
|
|
add dl, '0' |
|
|
|
push dx |
|
|
|
loop .loop1 |
|
|
|
; mov cx, 5 ; Loop 5 times |
|
|
|
; .loop1: ; finds digits and pushes them to stack |
|
|
|
; xor dx, dx |
|
|
|
; div bx |
|
|
|
; add dl, '0' |
|
|
|
; push dx |
|
|
|
; loop .loop1 |
|
|
|
|
|
|
|
|
|
|
|
mov ah, 0xE |
|
|
|
mov cx, 5 ; Loop 5 times |
|
|
|
mov bl, '0' |
|
|
|
|
|
|
|
.loop2: ; Pops from stack until it hits a non-'0' value. It then jumps to nonzero_nopop to print it. |
|
|
|
pop dx |
|
|
|
mov al, dl |
|
|
|
cmp al, bl |
|
|
|
jne .nonzero_nopop |
|
|
|
loop .loop2 |
|
|
|
|
|
|
|
.nonzero_loop: ; Pops values from the stack and prints them. |
|
|
|
pop dx |
|
|
|
mov al, dl |
|
|
|
.nonzero_nopop: ; Part of the loop that prints the value. Jump to here to print without popping on first iteration. |
|
|
|
int 0x10 |
|
|
|
loop .nonzero_loop |
|
|
|
|
|
|
|
popa |
|
|
|
ret |
|
|
|
|
|
|
|
dumpax10_rev: ; Prints ax as 16-bit decimal number in reverse |
|
|
|
pusha |
|
|
|
|
|
|
|
mov cx, 10 ; Divisor |
|
|
|
.loop: |
|
|
|
xor dx, dx ; zero dx |
|
|
|
div cx ; Divide dx:ax by 10 -> quotient in ax, remainder in dx |
|
|
|
; mov ah, 0xE |
|
|
|
; mov cx, 5 ; Loop 5 times |
|
|
|
; mov bl, '0' |
|
|
|
|
|
|
|
; .loop2: ; Pops from stack until it hits a non-'0' value. It then jumps to nonzero_nopop to print it. |
|
|
|
; pop dx |
|
|
|
; mov al, dl |
|
|
|
; cmp al, bl |
|
|
|
; jne .nonzero_nopop |
|
|
|
; loop .loop2 |
|
|
|
|
|
|
|
; .nonzero_loop: ; Pops values from the stack and prints them. |
|
|
|
; pop dx |
|
|
|
; mov al, dl |
|
|
|
; .nonzero_nopop: ; Part of the loop that prints the value. Jump to here to print without popping on first iteration. |
|
|
|
; int 0x10 |
|
|
|
; loop .nonzero_loop |
|
|
|
|
|
|
|
; popa |
|
|
|
; ret |
|
|
|
|
|
|
|
; dumpax10_rev: ; Prints ax as 16-bit decimal number in reverse |
|
|
|
; pusha |
|
|
|
|
|
|
|
; mov cx, 10 ; Divisor |
|
|
|
; .loop: |
|
|
|
; xor dx, dx ; zero dx |
|
|
|
; div cx ; Divide dx:ax by 10 -> quotient in ax, remainder in dx |
|
|
|
|
|
|
|
mov bx, ax ; save quotient in bx |
|
|
|
; mov bx, ax ; save quotient in bx |
|
|
|
|
|
|
|
mov al, dl ; put remainder in al |
|
|
|
add al, '0' ; Make ASCII |
|
|
|
; mov al, dl ; put remainder in al |
|
|
|
; add al, '0' ; Make ASCII |
|
|
|
|
|
|
|
mov ah, 0xE ; Set teletype output |
|
|
|
int 0x10 ; BIOS: write one char |
|
|
|
; mov ah, 0xE ; Set teletype output |
|
|
|
; int 0x10 ; BIOS: write one char |
|
|
|
|
|
|
|
mov ax, bx |
|
|
|
;test ax, ax |
|
|
|
cmp ax, 0 |
|
|
|
jnz .loop |
|
|
|
; mov ax, bx |
|
|
|
; ;test ax, ax |
|
|
|
; cmp ax, 0 |
|
|
|
; jnz .loop |
|
|
|
|
|
|
|
popa |
|
|
|
ret |
|
|
|
; popa |
|
|
|
; ret |
|
|
|
|
|
|
|
printCRLF: |
|
|
|
mov ah, 0xE |
|
|
|