瀏覽代碼

Bootloader v0.1.0.0 - Support for some more BIOS versions

go32
Rhodez-x 5 年之前
父節點
當前提交
d034135691
共有 3 個檔案被更改,包括 95 行新增77 行删除
  1. +82
    -67
      bootloader.nasm
  2. +7
    -8
      kernel.nasm
  3. +6
    -2
      lib/debug_tools.nasm

+ 82
- 67
bootloader.nasm 查看文件

@ -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

+ 7
- 8
kernel.nasm 查看文件

@ -6,7 +6,7 @@ start_sing:
; VSFS is loaded:
mov [global_disk_identifier], dl ; saving disk_identifier, this is the number the disk that we are booting from.
; This number is set by the bios
jmp sing_ready
jmp sing_loaded
%include "mem_lib/mem_lib.nasm"
%include "lib/os_lib.nasm"
%include "lib/string.nasm"
@ -16,14 +16,15 @@ jmp sing_ready
%include "vsfs/vsfs.nasm"
%include "CLI/CLI.nasm"
sing_ready: ; SingOS is ready for the user:
sing_loaded: ; SingOS is ready for the user:
mov ax, 0x8fc0
mov ss, ax ; Set 'ss' to this location (the beginning of our stack region)
mov sp, 0xffff ; Set 'ss:sp' to the top of our 8K stack
mov bp, sp
call os_clear_screen
sing_ready: ; SingOS is ready for the user:
;call os_clear_screen
mov si, welcome ; Put address of the null-terminated string to output into 'si'
call print ; Call our string-printing routine
@ -45,9 +46,6 @@ sing_ready: ; SingOS is ready for the user:
call print_help_message
; call dump_status_flags
; call printCRLF
mov si, command_line
call print
jmp terminal
@ -76,6 +74,7 @@ wait_for_key:
cmp cx, 0x0e08 ; backspace key
;je .backspace_handler
jne .dont_backspace
call CLI_DELETE
popa
ret
@ -97,7 +96,7 @@ wait_for_key:
;mov ax, [.tmp_buf]
;mov [bx], ax
.return_enter:
mov ax, [.tmp_buf]
;mov ax, [.tmp_buf]
popa ; But restore all other regs
ret

+ 6
- 2
lib/debug_tools.nasm 查看文件

@ -58,9 +58,12 @@
BITS 16
dumpmem_hardcoded_args:
push ds ; THIS IS ALSO HACKY
mov si, sp
mov si, [si]
mov cx, 400
mov ax, ss
mov ds, ax
;mov si, [si]
mov cx, 256
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
dumpmem:
; Dumps memory
@ -81,6 +84,7 @@ dumpmem:
.end:
popa
pop ds ; THIS IS ONLY FOR DEBUG - REMOVE REMOVE REMOVE
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Loading…
取消
儲存