Skip to content

Commit

Permalink
Issue #7: Added code to retry on int13 read failures
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Kelly committed Jan 21, 2012
1 parent f0c14b5 commit a29ce6f
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 29 deletions.
50 changes: 34 additions & 16 deletions boot/cdboot.S
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ STACK_LOC equ STAGE2
KERN_LBA equ STAGE2+8 ; where stage2 wants to find kernel info
KERN_SIZE equ KERN_LBA+4
SECT_SIZE equ KERN_SIZE+4 ; to tell stage2 about sector size

INT13_TRIES equ 0x05 ; how many times in13 should try

[bits 16] ; using 16 bit assembly
[org 0x7C00] ; standard location of bootloader
Expand All @@ -42,7 +42,7 @@ real_start:
mov si,st_loaded ; notify user that we've loaded
call putstr

; so now we begin the task of finding PVD
; so now we begin the task of finding PVD on ISO9660
; descriptors start at 0x10
; load one (2kib) sector
; check first byte to see if it's 1 (id of PVD)
Expand Down Expand Up @@ -138,9 +138,9 @@ load_pvd:
.loadsec: mov dword [lbanum], eax
; set up for int 13
mov si, DAP ; address of packet
mov ah, 0x42 ; function number
int 0x13 ; execute!
jc .done ; if carry is set, error
call readmem
cmp ah, 0 ; see if we failed
jnz .done
cmp byte [ds:DIR_LOC],0x01 ; found the PVD
jz .success
cmp byte [ds:DIR_LOC],0xFF ; reached end of descriptors
Expand Down Expand Up @@ -168,16 +168,16 @@ load_pvd:
load_pt:
mov eax,[ds:DIR_LOC+132] ; PT size (bytes)
shr eax,11 ; bytes -> blocks (divide by 2k)
add ax,1 ; add one in case it was < 2k
add ax,1 ; add one to cover less significant digits
mov word [numsect], ax ; number of sectors to read
mov word [destoff], DIR_LOC ; place to put them
mov word [destseg], ds
mov eax,[ds:DIR_LOC+140] ; LBA of PT
mov dword [lbanum], eax
mov si, DAP ; address of packet
mov ah,0x42 ; function number
int 0x13 ; perform read
jc .done
call readmem
cmp ah,0 ; see if we failed
jnz .done
mov ax, 0x00
.done: ret

Expand Down Expand Up @@ -234,11 +234,10 @@ load_boot:
mov eax, [ds:bx+2] ; offset to lba num in PT
mov dword [lbanum], eax ; lba offset
mov si, DAP ; address of packet
mov ah, 0x42 ; function number
int 0x13 ; do it.
jc .done
call readmem
cmp ah, 0
jnz .done
mov ax,0
;mov al, [ds:bx+8] ; put first letter in al (for dbg purposes)
.done: ret


Expand Down Expand Up @@ -280,9 +279,9 @@ load_stage2:
mov eax, [ds:bx+2]
mov dword [lbanum], eax
mov si, DAP
mov ah, 0x42
int 0x13
jc .done
call readmem
cmp ah, 0
jnz .done
mov ax, 0
.done: ret

Expand Down Expand Up @@ -374,6 +373,24 @@ strcmp:
.done: ret


; readmem
; 16 bit, real mode
; executes int13 ah=42, retrying appropriately in case of failure
; input: address of DAP in ds:si
; output: ah=0 on sucess, nonzero if fail
; destroyed: ax, cx
readmem:
mov cx, INT13_TRIES ; number of times to try
.retry: mov ah, 0x42
int 0x13
jnc .done
dec cx
cmp cx, 0
jz .done
jmp .retry
.done: ret



;------------------------------------------------------------
; Data
Expand Down Expand Up @@ -405,6 +422,7 @@ st_ldpt db 'Loading Path Table..................',0
st_ldboot db 'Loading /boot.......................',0
st_ldstg2 db 'Loading stage2......................',0
st_findkern db 'Finding Kernel......................',0
st_try db 'Try',13,10,0
; Success and fail strings
success db 'Done',13,10,0
fail db 'Fail',13,10,0
Expand Down
48 changes: 36 additions & 12 deletions boot/stage2.S
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
;--------------------------------------------------------
; Environment Variables
;--------------------------------------------------------
KERNEL_LOC equ 0x1000
INT13_TRIES equ 0x05
KERNEL_LOC equ 0x7C00
KERNEL equ 0x100000

start:
Expand Down Expand Up @@ -165,18 +166,23 @@ wait_for_kbd_out:
; output: ax = 0 on success, nonzero on fail
; destroyed: eax, bx, cx, esi, edi
loadkernel:
mov eax, [kernsize] ; set up DAP
mov word [numsect], ax
mov eax, [kernloc]
mov dword [lbanum], eax
mov word [destoff], KERNEL_LOC ; load to < 1mb
mov word [destseg], ds
mov si, DAP
mov ah, 0x42
int 0x13 ; do the read
jc .done

; So, there are some issues here
; #1) There's only a limited amount of space to load to in <1mb
; #2) int 13 might fail. Retry
; #3) There's a limited recommended amount of bytes to read with int13
mov eax, [kernsize] ; set up DAP
mov word [numsect], ax
mov eax, [kernloc]
mov dword [lbanum], eax
mov word [destoff], KERNEL_LOC ; load to < 1mb
mov word [destseg], ds
mov si, DAP
call readmem ; do the read
cmp ah, 0 ; see if we failed
jnz .done

; now we have to move to > 1mb
; now we have to move to > 1mb
call unrealmode ; setup unreal mode
mov esi,KERNEL_LOC ; place we're moving from
mov edi,KERNEL ; place we're moving to
Expand Down Expand Up @@ -241,6 +247,24 @@ putstr:
.done: ret


; readmem
; 16 bit, real mode
; executes int13 ah=42, retrying appropriately in case of failure
; input: address of DAP in ds:si
; output: ah=0 on sucess, nonzero if fail
; destroyed: ax, cx
readmem:
mov cx, INT13_TRIES ; number of times to try
.retry: mov ah, 0x42
int 0x13
jnc .done
dec cx
cmp cx, 0
jz .done
jmp .retry
.done: ret


; start_pmode
; label in 32bit assembly used in the far jump to clear pipeline for switching from
; real16bit to protected32bit mode
Expand Down
Empty file modified docs/milestoneplan.txt
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion kernel/start_kernel.S
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ start_kernel:
sti
.end:hlt
jmp .end
times 4000 db 0
;times 1000000 db 0

0 comments on commit a29ce6f

Please sign in to comment.