summaryrefslogtreecommitdiff
path: root/src/stage1_functions.asm
diff options
context:
space:
mode:
Diffstat (limited to 'src/stage1_functions.asm')
-rw-r--r--src/stage1_functions.asm88
1 files changed, 65 insertions, 23 deletions
diff --git a/src/stage1_functions.asm b/src/stage1_functions.asm
index c9ed1a5..8a73a9b 100644
--- a/src/stage1_functions.asm
+++ b/src/stage1_functions.asm
@@ -4,20 +4,6 @@
; subtract 1 here!)
NOF_LOAD_SECTORS equ 38
-; IN bx: begin of memory area to dump
-; IN ax: number of words to dump
-dump_range:
- mov dx, bx
- call print_hex
- mov dx, [bx]
- call print_hex
- call print_newline
- add bx, 2
- dec ax
- cmp ax, 0
- jnz dump_range
- ret
-
; IN dx: hex value to print
print_hex:
push bx
@@ -104,25 +90,76 @@ current_row:
pop ax
ret
+; data sections used for reading from disk
+SECTORS_TO_LOAD:
+ db NOF_LOAD_SECTORS ; load NOF_LOAD_SECTORS sectors in total
+CURRENT_SECTOR:
+ db 2 ; second sector after boot sector
+CURRENT_CYLINDER:
+ db 0
+CURRENT_HEAD:
+ db 0
+
+; read the whole stage2 and kernel from the disk
; IN dl: drive to read from
read_from_disk:
- mov ah, 0x02 ; read sectors from drive
-
- mov al, NOF_LOAD_SECTORS ; read 1 sector
- mov ch, 0 ; select first cylinder
- mov dh, 0 ; first head
- mov cl, 2 ; second sector after boot sector
-
+
mov bx, 0 ; where to store the data
mov es, bx
mov bx, 0x7e00 ; 512 bytes after first sector
-
+
+.read_next_sector:
+
+ call read_one_sector_from_disk
+
+ sub [SECTORS_TO_LOAD], BYTE 1 ; one less to load
+ cmp [SECTORS_TO_LOAD], BYTE 0 ; finished?
+ je .finished
+
+ add bx, 0x200 ; advance write buffer position
+ add [CURRENT_SECTOR], BYTE 1 ; next sector
+ cmp [CURRENT_SECTOR], BYTE 0x13 ; assuming 18 sectors per track for now
+ je .next_head
+ jmp .read_next_sector
+
+.next_head:
+ mov [CURRENT_SECTOR], BYTE 1 ; start from first sector again
+ add [CURRENT_HEAD], BYTE 1 ; advance head
+ cmp [CURRENT_HEAD], BYTE 0x02 ; 2 heads on floppies
+ je .next_track
+ jmp .read_next_sector
+
+.next_track:
+ mov [CURRENT_HEAD], BYTE 0 ; start from head 0 again
+ add [CURRENT_CYLINDER], BYTE 1 ; advance track
+ jmp .read_next_sector
+
+.finished:
+ ret
+
+; Read one sector after the other, if we get illegal parameter
+; errors we assume we have gone over the limit of number of
+; sectors per cylinder. This avoids to probe for this number with
+; shacky BIOS functions or with probing (as LILO does). It's not
+; very efficient though..
+; IN dl: drive to read from
+read_one_sector_from_disk:
+ mov ah, 0x02 ; read sectors from drive
+
+ mov al, 1 ; read 1 sector
+ mov ch, BYTE [CURRENT_CYLINDER]
+ mov dh, BYTE [CURRENT_HEAD]
+ mov cl, BYTE [CURRENT_SECTOR]
+
int 0x13
jc .read_error
- cmp al, NOF_LOAD_SECTORS ; 1 sector read?
+ cmp al, 1 ; 1 sector read?
jne .short_read ; if not, short read
+
+ mov al, '.'
+ call print_char
ret
@@ -139,3 +176,8 @@ read_from_disk:
call print_string
jmp $
+kill_motor:
+ mov dx, 0x3F2
+ mov al, 0x00
+ out dx, al
+ ret