bochs error : ctrl not ready ???

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Iniclub
Posts: 8
Joined: Sun Jul 15, 2007 3:05 am

bochs error : ctrl not ready ???

Post by Iniclub »

Hello, every body I am new to the Os developement field and I have a problem that make my hair gray.
I have a boot loader that is user in a flopy disque (FAT12 File syst) and I want to load the kernel and the Interuption hundler routine (I use INT 20H).
When I load only one file (here the kernel) every thing works well but when I try to load 2 (Kernel+IntHandler) I have this error msg in bochs
int13_diskette: ctrl not ready.
When I debuged the programme I found that the fist file is loaded but when loading the second the problem occurs and the values of (Track,Sector,Head) = (7,13,0).

And here is the code(The original boot loader is not mine):

Code: Select all

[BITS 16]
[ORG 0x0]

 jmp     short start 	           ; Standard start of boot sector
 nop

bOEM       db      'Test OS '
bSectSize  dw      512             ; bytes/sector NEEDED ! FIXED
bClustSize db      1               ; sectors/allocation unit NEEDED ! (FIXED)
bResSect   dw      1               ; # reserved sectors NEEDED ! (FIXED)
bFatCnt    db      2               ; # of fats NEEDED
bRootSize  dw      224             ; # of root directories NEEDED
bTotalSec  dw      2880            ; # sectors total in image
bMedia     db      240             ; media descrip: fd=2side9sec, etc...
bFatSize   dw      9               ; # sectors in a fat NEEDED
bTrackSec  dw      18              ; # sectors/track NEEDED ! FIXED
bHeadCnt   dw      2               ; # heads
bHiddenSec dd      0               ; # hidden sectors
bHugeSec   dd      0               ; # sectors if > 65536
bBootDrv   db      00              ; drive number NEEDED ! FIXED
bReserved  db      00
bBootSign  db      41              ; extended boot signature
bVolID     dd      0
bVolLabel  db      'TEST OSV1.0'
bFSType    db      'FAT12   '

; *********************
;     Main program
; *********************

start:
 mov   [bBootDrv], dl ; Save boot drive

 cli                  ; Disable the interrupts
 mov   ax, 0x07c0     ; setup the segment registers
 mov   ds, ax
 mov   es, ax
;It's in comment because I supected that there was a stack overflow
; mov   ax, 0x0000     ; setup the stack
 ;mov   ss, ax
; mov   sp, 0xffff
 sti                  ; Enable the interrupts


 
 mov   si, loading    ; show 'Loading'
 call  print

; ********************
;    Misc functions
; ********************
    mov   si, kernel              ; which name?

;chargerFic:
   ;PUSH   SI
getrootdir:                    ; catch the root directory
 xor   cx, cx
 xor   dx, dx
 mov   ax, 0x0020              ; ax=((32*RootSize)/512)+2
 mul   word [bRootSize]
 div   word [bSectSize]
 ;ADD   AX,2            ;**********************************
 xchg  ax, cx
 mov   al, byte [bFatCnt]
 mul   word [bFatSize]
 add   ax, word [bResSect]
 mov   word [datasector], ax
 add   word [datasector], cx
 mov   bx, 0x0200              ; load to 7c00:0200
 call  readsectors
 mov   cx, word [bRootSize]    ; counter
 mov   di, 0x0200              ; take first location
 ;POP   SI
 .loop:
 push  cx
 mov   cx, 0x000B              ; check for 11 chars
 push  di
 push  si
 rep   cmpsb                   ; is it equal?
 pop   si
 pop   di
 je    getfat
 pop   cx
 add   di, 0x0020              ; next one, please
 loop  .loop
 jmp   error

getfat:
 mov   si, dot                 ; show dot to ensure something is done
 call  print
 mov   dx, word [di + 0x001A]
 mov   word [cluster], dx      ; 1. file cluster
 xor   ax, ax
 mov   al, byte [bFatCnt]      ; Fat Count
 mul   word [bFatSize]         ; Fat Size
 mov   cx, ax
 mov   ax, word [bResSect]     ; reserved sectors
 mov   bx, 0x0200              ; copy to 7c00:0200
 call  readsectors

; Load the kernel file

 mov   ax,word[segFic]              ; load kernel to 1000:0000
 mov   es, ax
 MOV   BX,word[offsetFic]
 push  bx
 mov   si, dot                 ; show dot to ensure something is done
 call  print

load:

 mov   ax, word [cluster]      ; cluster-counter
 pop   bx                      ; set buffer

 sub   ax, 0x0002              ; cluster-2
 xor   cx, cx
 mov   cl, byte [bClustSize]   ; byte -> word
 mul   cx
 add   ax, word [datasector]   ; base sector for data

 xor   cx, cx
 mov   cl, byte [bClustSize]   ; Cluster Size
 call  readsectors
 push  bx
 mov   ax, word [cluster]      ; check cluster
 mov   cx, ax                  ; copy cluster
 mov   dx, ax                  ; copy cluster
 shr   dx, 0x0001              ; dx / 2
 add   cx, dx                  ; sum for (3/2)
 mov   bx, 0x0200              ; FAT location
 add   bx, cx                  ; index into FAT
 mov   dx, word [bx]           ; read two bytes
 test  ax, 0x0001
 jnz   .odd
 .even:
 and   dx, 0000111111111111b   ; only the low twelve
 jmp   .done
 .odd:
 shr   dx, 0x0004              ; only the high twelve
 .done:
 mov   word [cluster], dx      ; store cluster
 cmp   dx, 0x0FF0              ; EOF?
 jb    load
 MOV   SI,IT
 CMP  WORD[segFic],0x0000      ;Si on a pas encore charger le fichier GESTIT.TOS alors on continue
 JE   suit
 MOV  WORD[segFic],0x0000
 MOV  WORD[offsetFic],0x0400
 mov   ax, 0x07c0     ; car on a changer ES 
 mov   es, ax
 MOV   WORD[cluster],0x0000
 ;XOR   AX,AX        ;On re-initialise le controleur de la disquette
; MOV   DL,1
 ;INT   0x13
 JMP   getrootdir
 suit:
 mov   si, dot        ; show 'a' to ensure something is done
 call  print
 jmp dword 0x1000:0x0000       ; Jump to kernel
retf

error:                         ; Damn, an error occured
 mov   si, error_
 call  print
 xor   ax, ax
 int   0x16                    ; get key
 int   0x19                    ; reboot

print:
 lodsb                         ; load byte at ds:si into al
 or    al, al                  ; test if char is 0 (end)
 jz    end
 mov   ah, 0x0E                ; put char
 mov   bx, 0007                ; attribute
 int   0x10                    ; call BIOS
 jmp   print
 end:
retn

readsectors:
 .main
 mov   di, 0x0003              ; try to read 5 times
 .sloop
 push  ax
 push  bx
 push  cx

 xor   dx, dx                  ; set dx:ax for operation
 div   word [bTrackSec]        ; calc
 inc   dl                      ; set sector 0
 mov   byte [absSector], dl
 xor   dx, dx                  ; set dx:ax for operation
 div   word [bHeadCnt]         ; calc
 mov   byte [absHead], dl
 mov   byte [absTrack], al

 mov   ax, 0x201               ; read one sector
 mov   ch, byte [absTrack]     ; track
 mov   cl, byte [absSector]    ; sector
 mov   dh, byte [absHead]      ; head
 mov   dl, byte [bBootDrv]     ; drive
 int   0x13                    ; call BIOS
 jnc   .goal                   ; error?
 xor   ax, ax                  ; reset disk
 int   0x13                    ; call BIOS
 dec   di                      ; error counter-1
 pop   cx
 pop   bx
 pop   ax
 jnz   .sloop                  ; read again
 int   0x18
 .goal
 pop   cx
 pop   bx
 pop   ax
 add   bx, word [bSectSize]    ; next buffer
 inc   ax                      ; next sector
 loop  .main                   ; read next
retn

absSector   db 0x00
absHead     db 0x00
absTrack    db 0x00

datasector  dw 0x0000
cluster     dw 0x0000
offsetFic   dw 0x0000
segFic      dw 0x1000

kernel   db "KERNEL  TOS"
IT       db "GESTINT TOS"
loading  db 'Loading',0
dot      db '.', 0
error_   db 'Error',0

TIMES 510-($-$$) DB 0
DW 0xAA55
can any one help me please.
And thank you.
Iniclub
Posts: 8
Joined: Sun Jul 15, 2007 3:05 am

Post by Iniclub »

I used anther aproche , because the first file is loaded correctly so , in the boot I load only the kernel and then the kernel loads the second file (IntHandler) but the same problem occure.
When readind the FAT and the rootdirestory there is no problem but when I try to load the first sector of the file I got the previos message .
Did any one knew how to check for controler statue?.
I tried the INT 0x13 with ah=0x16 but no result I get always as result AH=0x06 (i.e:active line active or not suported)
Post Reply