Browse Source

tests on new SLRboot loader

SLRboot
Jørn Guldberg 5 years ago
parent
commit
ecbd46af17
3 changed files with 212 additions and 228 deletions
  1. +205
    -191
      bootloader.nasm
  2. +3
    -0
      kernel.nasm
  3. +4
    -37
      vbr.nasm

+ 205
- 191
bootloader.nasm View File

@ -1,13 +1,12 @@
ORG 0x7C00
BITS 16
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; SLRboot
; Bootloader for SingOS
; version 0.1.0.9-exp
;
; Please edit the version number if any changes is made, the last number
; represent the build number.
; version 0.2.0.0-exp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
cli
mov [disk_identifier], dl
mov ax, 0x1000
mov ss, ax
mov sp, 0xb000
@ -19,191 +18,218 @@ mov si, 0x7c00
mov di, 0x600
mov cx, 0x200
rep movsb
jmp long 0:0x621
mov si, 0x7be
cmp byte [si], al
jne 0x33
add si, 0x10
cmp si, 0x7fe
jne 0x24
jmp 0x49
mov bx, relocated
sub bx, 0x7600 ; Calculate the offset.
push bx
ret ; Return far
;jmp long 0:bx
relocated:
mov si, message ; Put address of the null-terminated string to output into 'si'
call print ; Call our string-printing routine
;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
mov ah, 2
mov al, 1
mov al, 0x08
mov bx, 0x7c00
mov dl, 0x80
mov dh, byte [si + 1]
mov cx, word [si + 2]
mov BYTE dl, [disk_identifier]
mov BYTE dh, [partition_1.start_CHS + 1] ;byte [si + 1]
mov BYTE cl, [partition_1.start_CHS + 2]
mov BYTE ch, [partition_1.start_CHS] ;First sector to read (bits 0-5), upper bits of cylinder (bits 6-7)
int 0x13
jmp long 0:0x7c00
jmp 0x49
;mov ax, 0x0
;mov ds, ax
mov ax, 89 ; lba adress
jmp long 0x0:0x7c00
cli
hlt
%IF 1
cli
jmp long 0x0000:start
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
%ENDIF
; 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 dl, [disk_identifier]
xor ax, ax
mov al, dl
call dumpax
call printCRLF
mov ax, 0x50
mov ds, ax
mov ax, 89 ; lba adress
jmp 0x50:0x0000 ; Jump to the kernel
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:
cli ; Clear the Interrupt Flag (disable external interrupts)
hlt ; Halt the CPU (until the next external interrupt)
cli ; Clear the Interrupt Flag (disable external interrupts)
hlt ; Halt the CPU (until the next external interrupt)
debug_mode:
mov si, .welcome_debug
call print
cli ; Clear the Interrupt Flag (disable external interrupts)
hlt
mov si, .welcome_debug
call print
cli ; Clear the Interrupt Flag (disable external interrupts)
hlt
.welcome_debug db 'This is debug mode', 0
.welcome_debug db 'This is debug mode', 0
;Routine for printing a 'ax' as hex
dumpax:
pusha ; save registers
mov bx, ax
mov ah, 0xE ; Teletype output
mov cx, 4 ; 4 nipples in a 16 bit word
.loop:
rol bx, 4 ; rotate to next nipple
mov al, bl ; we copy to al because we need to mask only the low 4 bits
and al, 1111b ; Do the masking
add al, '0' ; convert to ASCII
cmp al, '9' ; If we are greater than 9 ascii, we add 7 to make digit 10 be represented as 'A'
jbe .skip ; -|-
add al, 7 ; -|-
.skip: ; -|-
int 0x10 ; BIOS call 'output'
loop .loop
popa ; restore registers
ret
pusha ; save registers
mov bx, ax
mov ah, 0xE ; Teletype output
printCRLF:
mov ah, 0xE
mov al, 13
int 0x10
mov al, 10
int 0x10
ret
mov cx, 4 ; 4 nipples in a 16 bit word
.loop:
rol bx, 4 ; rotate to next nipple
mov al, bl ; we copy to al because we need to mask only the low 4 bits
and al, 1111b ; Do the masking
add al, '0' ; convert to ASCII
cmp al, '9' ; If we are greater than 9 ascii, we add 7 to make digit 10 be represented as 'A'
jbe .skip ; -|-
add al, 7 ; -|-
.skip: ; -|-
int 0x10 ; BIOS call 'output'
loop .loop
popa ; restore registers
ret
printCRLF:
mov ah, 0xE
mov al, 13
int 0x10
mov al, 10
int 0x10
ret
%ENDIF
; Routine for outputting string in 'si' register to screen
print:
mov ah, 0xE ; Specify 'int 0x10' 'teletype output' function
; [AL = Character, BH = Page Number, BL = Colour (in graphics mode)]
mov ah, 0xE ; Specify 'int 0x10' 'teletype output' function
; [AL = Character, BH = Page Number, BL = Colour (in graphics mode)]
.printchar:
lodsb ; Load byte at address SI into AL, and increment SI
cmp al, 0
je .done ; If the character is zero (NUL), stop writing the string
int 0x10 ; Otherwise, print the character via 'int 0x10'
jmp .printchar ; Repeat for the next character
lodsb ; Load byte at address SI into AL, and increment SI
cmp al, 0
je .done ; If the character is zero (NUL), stop writing the string
int 0x10 ; Otherwise, print the character via 'int 0x10'
jmp .printchar ; Repeat for the next character
.done:
ret
ret
data:
message db 'Bootloader for SingOS! v0.1.0.9-exp',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
boot_system db 'Read SingOS from disk', 13, 10, 0
error_str db 'Error', 0
success_str db 'Success', 0
disk_identifier db 0
message db 'SLRboot for SingOS! v0.2.0.0-exp',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
boot_system db 'Read SingOS from disk', 13, 10, 0
error_str db 'Error', 0
success_str db 'Success', 0
disk_identifier db 0
; Pad to 510 bytes (boot sector size minus 2) with 0s, and finish with the two-byte standard boot signature
times 446-($-$$) db 0 ; First partion entry
db 0x80 ; active partition
db 0, 0x00, 0x17 ; First sector CHS
db 0x00 ; Disk type (Other)
db 0xff, 0xff, 0xff ; Ending CHS values
db 0x17, 0, 0, 0x00 ; Staring LBA
db 0, 0xff, 0xff, 0xff ; Size
partition_1:
.active_partition db 0x00
.start_CHS db 0x00, 0x00, 0x11;0x20, 0x21, 0x00
.disk_type db 0x83
.end_CHS db 0x8C, 0x3D, 0x0F
.start_LBA db 0x00, 0x08, 0x00, 0x00
.size db 0x00, 0xC8, 0x03, 0x00
db 0x00
db 0x0, 0x0, 0x0
db 0x0
db 0x0, 0x0, 0x0
db 0x00, 0x00, 0x00, 0x00
db 0x0, 0x00, 0x00, 0x00
partition_2:
.active_partition db 0x80
.start_CHS db 0x8C, 0x3E, 0x0F
.disk_type db 0x83
.end_CHS db 0xFF, 0xFF, 0xFF
.start_LBA db 0x00, 0xD0, 0x03, 0x00
.size db 0x00, 0x28, 0x1C, 0x03
times 478-($-$$) db 0 ; Third partion entry
partition_3:
.active_partition db 0x00
.start_CHS db 0x00, 0x00, 0x00
.disk_type db 0x00
.end_CHS db 0x00, 0x00, 0x00
.start_LBA db 0x00, 0x00, 0x00, 0x00
.size db 0x00, 0x00, 0x00, 0x00
times 494-($-$$) db 0 ; Forth partion entry
partition_4:
.active_partition db 0x00
.start_CHS db 0x00, 0x00, 0x00
.disk_type db 0x00
.end_CHS db 0x00, 0x00, 0x00
.start_LBA db 0x00, 0x00, 0x00, 0x00
.size db 0x00, 0x00, 0x00, 0x00
times 510-($-$$) db 0
dw 0xAA55 ; => 0x55 0xAA (little endian byte order)
@ -211,34 +237,22 @@ dw 0xAA55 ; => 0x55 0xAA (little endian byte order)
times 8192-($-$$) db 0
; From Version 0.0.3 we are concatinate the bootloader and the kernel after compile time
;%include "kernel.nasm"
;times 8192-($-$$) db 0
;80
;00 01 00
;00
;3F 60 21
;00 00 00 00
;00 10 09 00
;00
;FE FF FF
;EF
;FE FF FF
;B0 0E 00 00
;40 03 00 00
;00
;00 00 00
;00
;00 00 00
;00 00 00 00
;00 00 00 00
;00
;00
;00 00 00 00
;00 00 00 00
;00 00 00
; 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

+ 3
- 0
kernel.nasm View File

@ -2,6 +2,9 @@ BITS 16
ORG 0x512
start_sing:
; loading essentials for SingOS to run
mov cx, 0x50
mov ds, cx
mov es, cx
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
;call lsfs_check_extended_support ; Check that the int 0x13 extended read and write is available

+ 4
- 37
vbr.nasm View File

@ -1,37 +1,7 @@
ORG 0x7C00
BITS 16
%define DISK_SERVICE 0x0050:0x0256
%define KERNEL 0x0050:0x0512
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
jmp short vbr_lfsf
nop ; Used later as a FLAG byte for extended INT 13 Disk Func.'s (See instruction at: 7CADh).
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Disk description table, to make it a valid floppy
; Note: some of these values are hard-coded in the source!
; Values are those used by IBM for 1.44 MB, 3.5" diskette
; NOTE(jakob): From MikeOS
; Why do we need this... damn BIOS
;times 71 - ($-$$) db 0
OEMLabel db "SingOs " ; Disk label
; BytesPerSector dw 512 ; Bytes per sector
; SectorsPerCluster db 1 ; Sectors per cluster
; ReservedForBoot dw 1 ; Reserved sectors for boot record
; NumberOfFats db 2 ; Number of copies of the FAT
; RootDirEntries dw 224 ; Number of entries in root dir
; ; (224 * 32 = 7168 = 14 sectors to read)
; LogicalSectors dw 0x4000 ; Number of logical sectors
; MediumByte db 0xF0 ; Medium descriptor byte
; SectorsPerFat dw 9 ; Sectors per FAT
; SectorsPerTrack dw 18 ; Sectors per track (36/cylinder)
; Sides dw 2 ; Number of sides/heads
; HiddenSectors dd 0 ; Number of hidden sectors
; LargeSectors dd 0 ; Number of LBA sectors
; DriveNo dw 0 ; Drive No: 0
; Signature db 0 ; Drive signature: 41 for floppy
; VolumeID dd 0x00000000 ; Volume ID: any number
; VolumeLabel db "SingOs "; Volume Label: any 11 chars
; FileSystem db "VSFS " ; File system type: don't change!
vbr_lfsf:
; Volume Boot Record
; This will start SingOS from the disk
@ -63,13 +33,10 @@ vbr_lfsf:
mov [vbr_disk_identifier], dl ; saving disk_identifier, this is the number the disk that we are booting from.
; This number is set by the bios
xor ax, ax
mov al, dl
mov al, [vbr_disk_identifier]
mov [vbr_lba_position_at_disk], ax ; From the MBR we need information of where we are located at the disk.
; If this fails, we could lookup our self, in the MBR where we are located.
call dumpax
mov [vbr_lba_position_at_disk], ax ; From the MBR we need information of where we are located at the disk.
; If this fails, we could lookup our self, in the MBR where we are located.
;mov ax, 0x50
;mov cs, ax
;mov ds, ax

Loading…
Cancel
Save