|
@ -3,7 +3,7 @@ BITS 16 |
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
|
; SLRboot |
|
|
; SLRboot |
|
|
; Bootloader for SingOS |
|
|
; Bootloader for SingOS |
|
|
; version 0.2.0.3-exp |
|
|
; version 0.2.1.0-exp |
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
|
cli |
|
|
cli |
|
|
jmp long 0x0000:start |
|
|
jmp long 0x0000:start |
|
@ -36,34 +36,36 @@ call print ; Call our string-printing routine |
|
|
xor bx, bx |
|
|
xor bx, bx |
|
|
xor cx, cx |
|
|
xor cx, cx |
|
|
mov ax, [partition_1.active_partition] |
|
|
mov ax, [partition_1.active_partition] |
|
|
cmp ax, 0x80 |
|
|
cmp al, 0x80 |
|
|
jne check_p_2 |
|
|
jne check_p_2 |
|
|
mov bx, 0x01 ; Partion 1 active |
|
|
mov bx, 0x01 ; Partion 1 active |
|
|
inc cx |
|
|
inc cx |
|
|
|
|
|
|
|
|
check_p_2: |
|
|
check_p_2: |
|
|
mov ax, [partition_2.active_partition] |
|
|
mov ax, [partition_2.active_partition] |
|
|
cmp ax, 0x80 |
|
|
cmp al, 0x80 |
|
|
jne check_p_3 |
|
|
jne check_p_3 |
|
|
inc cx |
|
|
inc cx |
|
|
mov bx, 0x02 ; Partion 2 active |
|
|
mov bx, 0x02 ; Partion 2 active |
|
|
|
|
|
|
|
|
check_p_3: |
|
|
check_p_3: |
|
|
mov ax, [partition_3.active_partition] |
|
|
mov ax, [partition_3.active_partition] |
|
|
cmp ax, 0x80 |
|
|
cmp al, 0x80 |
|
|
jne check_p_4 |
|
|
jne check_p_4 |
|
|
inc cx |
|
|
inc cx |
|
|
mov bx, 0x03 ; Partion 3 active |
|
|
mov bx, 0x03 ; Partion 3 active |
|
|
|
|
|
|
|
|
check_p_4: |
|
|
check_p_4: |
|
|
mov ax, [partition_4.active_partition] |
|
|
mov al, [partition_4.active_partition] |
|
|
cmp ax, 0x80 |
|
|
cmp ax, 0x80 |
|
|
jne eval_active_partion_number |
|
|
jne eval_active_partion_number |
|
|
inc cx |
|
|
inc cx |
|
|
mov bx, 0x04 ; Partion 4 active |
|
|
mov bx, 0x04 ; Partion 4 active |
|
|
|
|
|
cli |
|
|
|
|
|
hlt |
|
|
eval_active_partion_number: |
|
|
eval_active_partion_number: |
|
|
cmp cx, 1 |
|
|
cmp cx, 1 |
|
|
|
|
|
|
|
|
je boot_partition |
|
|
je boot_partition |
|
|
; here goes wait call, for the user to enter debug mode. |
|
|
; here goes wait call, for the user to enter debug mode. |
|
|
; Wating for 2 seconds: |
|
|
; Wating for 2 seconds: |
|
@ -76,18 +78,14 @@ xor ax, ax |
|
|
mov ah, 0x01 ; BIOS call to wait for key |
|
|
mov ah, 0x01 ; BIOS call to wait for key |
|
|
int 0x16 |
|
|
int 0x16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boot_partition: |
|
|
boot_partition: |
|
|
; IMPORTANT bx, has to hold the value 1-4 for the partiotion that wanted to be booted. |
|
|
; IMPORTANT bx, has to hold the value 1-4 for the partiotion that wanted to be booted. |
|
|
|
|
|
|
|
|
mov bx, 2 |
|
|
|
|
|
|
|
|
|
|
|
mov ax, partition_1 |
|
|
mov ax, partition_1 |
|
|
.loop: |
|
|
.loop: |
|
|
cmp bx, 1 |
|
|
cmp bx, 1 |
|
|
je break |
|
|
je break |
|
|
add ax, 0x10 |
|
|
add ax, 0x10 |
|
|
;call dumpax |
|
|
|
|
|
dec bx |
|
|
dec bx |
|
|
jmp .loop |
|
|
jmp .loop |
|
|
break: |
|
|
break: |
|
@ -102,7 +100,6 @@ add bx, 2 ; next part |
|
|
mov ax, [bx] |
|
|
mov ax, [bx] |
|
|
mov WORD [DAPACK.lba_addr_dw_low + 1], ax |
|
|
mov WORD [DAPACK.lba_addr_dw_low + 1], ax |
|
|
call dumpax |
|
|
call dumpax |
|
|
|
|
|
|
|
|
mov WORD [DAPACK.blkcnt], 0x01 |
|
|
mov WORD [DAPACK.blkcnt], 0x01 |
|
|
mov WORD [DAPACK.db_addr_segment], 0x0000 |
|
|
mov WORD [DAPACK.db_addr_segment], 0x0000 |
|
|
mov WORD [DAPACK.db_addr_offset], 0x7c00 |
|
|
mov WORD [DAPACK.db_addr_offset], 0x7c00 |
|
@ -112,109 +109,28 @@ mov ah, 0x42 ; READ |
|
|
mov dl, [disk_identifier] |
|
|
mov dl, [disk_identifier] |
|
|
int 0x13 |
|
|
int 0x13 |
|
|
|
|
|
|
|
|
|
|
|
jc endcarrycheck ; An error ocurred when reading from disk. |
|
|
|
|
|
|
|
|
|
|
|
; If no error then jump to volume boot record |
|
|
|
|
|
notcarry: |
|
|
jmp long 0x0:0x7c00 |
|
|
jmp long 0x0:0x7c00 |
|
|
|
|
|
|
|
|
cli |
|
|
cli |
|
|
hlt |
|
|
hlt |
|
|
|
|
|
|
|
|
|
|
|
; If we did not suceed to read from disk |
|
|
%IF 0 |
|
|
|
|
|
cli |
|
|
|
|
|
jmp long 0x0000:start |
|
|
|
|
|
|
|
|
|
|
|
start: |
|
|
|
|
|
xor ax, ax |
|
|
|
|
|
mov ds, ax |
|
|
|
|
|
mov es, ax |
|
|
|
|
|
mov ss, ax |
|
|
|
|
|
mov [disk_identifier], dl |
|
|
|
|
|
|
|
|
|
|
|
; 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 |
|
|
|
|
|
add ax, 0x20 ; Skip over the size of the bootloader divided by 16 |
|
|
|
|
|
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 |
|
|
|
|
|
sti |
|
|
|
|
|
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 |
|
|
|
|
|
call print |
|
|
|
|
|
call printCRLF |
|
|
|
|
|
;%IF 0 |
|
|
|
|
|
; here goes wait call, for the user to enter debug mode. |
|
|
|
|
|
; Wating for 2 seconds: |
|
|
|
|
|
mov ah, 0x86 ; code for waiting interupt call |
|
|
|
|
|
mov cx, 0x001e ; high count of microseconds |
|
|
|
|
|
mov dx, 0x8480 ; low count |
|
|
|
|
|
int 0x15 |
|
|
|
|
|
|
|
|
|
|
|
.busy_wait_for_key: |
|
|
|
|
|
xor ax, ax |
|
|
|
|
|
mov ah, 0x01 ; BIOS call to wait for key |
|
|
|
|
|
int 0x16 |
|
|
|
|
|
jnz debug_mode |
|
|
|
|
|
|
|
|
|
|
|
; entering system check: |
|
|
|
|
|
mov si, enter_system_check |
|
|
|
|
|
|
|
|
|
|
|
mov si, sys_check_ok ; Put address of the null-terminated string to output into 'si' |
|
|
|
|
|
call print ; Call our string-printing routine |
|
|
|
|
|
|
|
|
|
|
|
mov si, boot_system ; Put address of the null-terminated string to output into 'si' |
|
|
|
|
|
call print ; Call our string-printing routine |
|
|
|
|
|
|
|
|
|
|
|
;This goes first as to now overwrite %ah and %al. |
|
|
|
|
|
;mov ax, 0x0050 |
|
|
|
|
|
;mov es, ax ;Section to write into |
|
|
|
|
|
;mov ah, 0x2 ;Read sectors from drive |
|
|
|
|
|
;mov al, 0x08 ;Number of sectors to read (31 * 512 = 15872 bytes) |
|
|
|
|
|
;mov ch, 0x0 ;Low 8 bits of cylinder |
|
|
|
|
|
;mov cl, 0x11 ;First sector to read (bits 0-5), upper bits of cylinder (bits 6-7) |
|
|
|
|
|
;mov dh, 0x0 ;Head number |
|
|
|
|
|
;mov dl, [disk_identifier] ;Drive number |
|
|
|
|
|
;mov bx, 0x0000 ;Offset into section |
|
|
|
|
|
;int 0x13 ;Low level disk services |
|
|
|
|
|
|
|
|
|
|
|
;jnc notcarry |
|
|
|
|
|
;mov si, error_str |
|
|
|
|
|
;call print |
|
|
|
|
|
;jmp endcarrycheck |
|
|
|
|
|
|
|
|
|
|
|
notcarry: |
|
|
|
|
|
;mov si, success_str |
|
|
|
|
|
;call print |
|
|
|
|
|
;call printCRLF |
|
|
|
|
|
|
|
|
|
|
|
mov ax, 0x0 |
|
|
|
|
|
mov ds, ax |
|
|
|
|
|
mov ax, 89 ; lba adress |
|
|
|
|
|
|
|
|
|
|
|
jmp 0x50:0x0000 ; Jump to the kernel |
|
|
|
|
|
|
|
|
|
|
|
endcarrycheck: |
|
|
endcarrycheck: |
|
|
|
|
|
mov si, error_str |
|
|
|
|
|
call print |
|
|
cli ; Clear the Interrupt Flag (disable external interrupts) |
|
|
cli ; Clear the Interrupt Flag (disable external interrupts) |
|
|
hlt ; Halt the CPU (until the next external interrupt) |
|
|
hlt ; Halt the CPU (until the next external interrupt) |
|
|
|
|
|
|
|
|
debug_mode: |
|
|
debug_mode: |
|
|
mov si, .welcome_debug |
|
|
mov si, welcome_debug |
|
|
call print |
|
|
call print |
|
|
cli ; Clear the Interrupt Flag (disable external interrupts) |
|
|
cli ; Clear the Interrupt Flag (disable external interrupts) |
|
|
hlt |
|
|
hlt |
|
|
|
|
|
|
|
|
.welcome_debug db 'This is debug mode', 0 |
|
|
|
|
|
|
|
|
|
|
|
printCRLF: |
|
|
|
|
|
mov ah, 0xE |
|
|
|
|
|
mov al, 13 |
|
|
|
|
|
int 0x10 |
|
|
|
|
|
mov al, 10 |
|
|
|
|
|
int 0x10 |
|
|
|
|
|
ret |
|
|
|
|
|
%ENDIF |
|
|
|
|
|
|
|
|
|
|
|
;Routine for printing a 'ax' as hex |
|
|
;Routine for printing a 'ax' as hex |
|
|
dumpax: |
|
|
dumpax: |
|
|
pusha ; save registers |
|
|
pusha ; save registers |
|
@ -237,6 +153,14 @@ loop .loop |
|
|
popa ; restore registers |
|
|
popa ; restore registers |
|
|
ret |
|
|
ret |
|
|
|
|
|
|
|
|
|
|
|
printCRLF: |
|
|
|
|
|
mov ah, 0xE |
|
|
|
|
|
mov al, 13 |
|
|
|
|
|
int 0x10 |
|
|
|
|
|
mov al, 10 |
|
|
|
|
|
int 0x10 |
|
|
|
|
|
ret |
|
|
|
|
|
|
|
|
; Routine for outputting string in 'si' register to screen |
|
|
; Routine for outputting string in 'si' register to screen |
|
|
print: |
|
|
print: |
|
|
mov ah, 0xE ; Specify 'int 0x10' 'teletype output' function |
|
|
mov ah, 0xE ; Specify 'int 0x10' 'teletype output' function |
|
@ -251,13 +175,10 @@ jmp .printchar ; Repeat for the next character |
|
|
ret |
|
|
ret |
|
|
|
|
|
|
|
|
data: |
|
|
data: |
|
|
message db 'SLRboot for SingOS! v0.2.0.3-exp',13,10,0 |
|
|
message db 'SLRboot for SingOS! v0.2.1.0-exp',13,10,0 |
|
|
;enter_debug_mode db 'Press d to enter bootloader debug mode',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 |
|
|
welcome_debug db 'Debug mode v.0.0.1:',13,10,0 |
|
|
;sys_check_ok db 'System check ok', 13, 10, 0 |
|
|
error_str db 'Error', 0 |
|
|
;boot_system db 'Read SingOS from disk', 13, 10, 0 |
|
|
|
|
|
;error_str db 'Error', 0 |
|
|
|
|
|
;success_str db 'Success', 0 |
|
|
|
|
|
boot_this_partition: dw 0 |
|
|
boot_this_partition: dw 0 |
|
|
disk_identifier db 0 |
|
|
disk_identifier db 0 |
|
|
|
|
|
|
|
@ -283,7 +204,7 @@ partition_1: |
|
|
.size db 0x00, 0xC8, 0x03, 0x00 |
|
|
.size db 0x00, 0xC8, 0x03, 0x00 |
|
|
|
|
|
|
|
|
partition_2: |
|
|
partition_2: |
|
|
.active_partition db 0x80 |
|
|
.active_partition db 0x00 |
|
|
.start_CHS db 0x8C, 0x3E, 0x0F |
|
|
.start_CHS db 0x8C, 0x3E, 0x0F |
|
|
.disk_type db 0x83 |
|
|
.disk_type db 0x83 |
|
|
.end_CHS db 0xFF, 0xFF, 0xFF |
|
|
.end_CHS db 0xFF, 0xFF, 0xFF |
|
@ -311,23 +232,3 @@ dw 0xAA55 ; => 0x55 0xAA (little endian byte order) |
|
|
; bootloder debug_mode goes here |
|
|
; bootloder debug_mode goes here |
|
|
|
|
|
|
|
|
times 8192-($-$$) db 0 |
|
|
times 8192-($-$$) db 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; mov si, 0x7be |
|
|
|
|
|
; cmp byte [si], al |
|
|
|
|
|
; jne 0x33 |
|
|
|
|
|
; add si, 0x10 |
|
|
|
|
|
; cmp si, 0x7fe |
|
|
|
|
|
; jne 0x24 |
|
|
|
|
|
; jmp 0x49 |
|
|
|
|
|
; mov ah, 2 |
|
|
|
|
|
; mov al, 1 |
|
|
|
|
|
; mov bx, 0x7c00 |
|
|
|
|
|
; mov dl, 0x80 |
|
|
|
|
|
; mov dh, byte [si + 1] |
|
|
|
|
|
; mov cx, word [si + 2] |
|
|
|
|
|
; int 0x13 |
|
|
|
|
|
; jmp long 0:0x7c00 |
|
|
|
|
|
|
|
|
|
|
|
; jmp 0x49 |
|
|
|
|
|