Problem loading first sector on head 0, track 1 in RealMode

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
bob10
Posts: 5
Joined: Wed Dec 08, 2010 5:17 am

Problem loading first sector on head 0, track 1 in RealMode

Post by bob10 »

Hi,

if i run the following code in bochs 2.3.7 with "show dbg-all" enabled,
i get this output:

Code: Select all

CPU 0: Interrupt 0x13 occured (error_code=0x0000)
00008083438i[CMOS ] CMOS read of CMOS register 0x10
00008084067i[FDD  ] drive=0
00008084067i[FDD  ] offset=18432
00008084067i[FDD  ] bytes=512
00008084067i[FDD  ] direction=from
00008084067i[FDD  ] read() on floppy image returns 0
00008084075i[SYS  ] pc_system: Setting INTR=0 on bootstrap processor 0
CPU 0: Interrupt 0x08 occured (error_code=0x0000)
CPU 0: Interrupt 0x1c occured (error_code=0x0000)
00008106800i[FDD  ] <<READ DONE>>
00008106800i[FDD  ] AFTER
00008106800i[FDD  ]   drive    = 0
00008106800i[FDD  ]   head     = 1
00008106800i[FDD  ]   cylinder = 1
00008106800i[FDD  ]   sector   = 1
Reading of all sectors in the first track (0) works but there is a problem in track 1.
I think the offset 18432 is to high for my CHS, because it is the 36th sector!
Of course there is nothing to read (returns 0) because my image is smaller. (14kB)

Are the last 4 lines the input data for the int 0x13? But then head is not correct.
And sector doesn't change if i try to read e.g. the 3rd sector.

Code: Select all

[BITS 16]
CPU 386
GLOBAL start

STACK_ADR		equ	0x7C00		; upper startaddress of the bootsector stack

SECTION .text

start:
    cli								; disable all maskable interrupts
    jmp WORD 0x0000:start2			; far jump um CS sicher auf 0x0000 zu setzen

bootlaufwerk:	; Diskettenlaufwerk von dem gebootet wurde
	db  0x00	    ; Standard: Laufwerk A

start2:
    ; wir sind bei absolut 0x07C00, der Code startet also bei 0x7C00 im Segment 0x0000
    xor ax, ax			; AX = 0 setzen
    mov ds, ax			; Datensegment DS zu 0x0000 setzen
	mov es, ax			; Extrasegment ES zu 0x0000 setzen
    mov ss, ax			; Stacksegment SS zu 0x0000 setzen

;
; Stack vorbereiten
    mov ax, STACK_ADR
    mov sp, ax			; Stackpointer SP setzen (direkt unterhalb Bootsektor)

    mov [bootlaufwerk], dl	; Bootlaufwerk aus DL sichern


; Floppy Test
_readSector_again:
	xor ax, ax
	xor dx, dx
	int 0x13		; reset floppy drive
	jc _readSector_again	; retry on error

	mov ax, 0x000
	mov es, ax			; set ES
    mov ah, 0x02		; function nr
    mov al, 1			; read only one sector

	mov ch, 1			; track (0 to N-1)
	mov cl, 1			; first sector (1 to M)
	mov dh, 0			; head (0 or 1)

	mov dl, [bootlaufwerk] ; drive A
	mov bx, 0x7E00		; offset

    int 0x13			; start reading
	jc _readSector_again	; retry on error
	
	jmp $
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Problem loading first sector on head 0, track 1 in RealM

Post by Combuster »

00008084067i[FDD ] read() on floppy image returns 0
Your floppy image is broken (not 1.4MB)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
bob10
Posts: 5
Joined: Wed Dec 08, 2010 5:17 am

Re: Problem loading first sector on head 0, track 1 in RealM

Post by bob10 »

I know, but isn't the offset in the debug output too large for the 19th sector on the floppy?
Sector 18 has an offset of 8704 but why has sector 19 an offset of 18432?
I think it should be 9216.
Where is the mistake?
bob10
Posts: 5
Joined: Wed Dec 08, 2010 5:17 am

Re: Problem loading first sector on head 0, track 1 in RealM

Post by bob10 »

I found the mistake!

After C/H/S 0/0/18 follows C/H/S 0/1/1 and not C/H/S 1/0/1.
Post Reply