can't load mpore than 64K from floppy

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
idiprima
Posts: 2
Joined: Thu Sep 02, 2010 7:08 am

can't load mpore than 64K from floppy

Post by idiprima »

why this piece of code dosen't work to load the whole floppy?

Code: Select all

;load kernel.bin from disk to 0x100000
read:
xor ax,ax                     ; Floppy Reset BIOS Function
mov dl,[drive]                ; Select floppy that was booted from
int 0x13 
jc read

mov ax,0xffff 
mov es,ax                     ; Data buffer for file
mov bx,0x10                   ; Start of segment
mov ah,2        	      ; Function to read disk
mov al,17                     ; Total sectors to read
mov ch,0                      ; Track
mov cl,2                      ; Sector
mov dh,0                      ; Head | Drive is already loaded
int 0x13                      ; Call BIOS read disk function
jc read 	              ; motor error, try again

mov bx, 0x2210
mov dh,1                      ; Head | Drive is already loaded
mov cl,1                      ; Sector
next_read:
mov ax,0xffff 
mov es,ax
mov ah,2        	      ; Function to read disk
mov al,18                     ; Total sectors to read
int 0x13                      ; Call BIOS read disk function
jc end_read										; reached end of disk
add bx,0x2400									; next buffer
xor dh,1											; alternate head
jnz next_read									; 
inc ch												; increment cylinder/track
jmp next_read
end_read:

mov dx,0x3F2                  ; stop the motor
mov al,0x0C                   ; from spinning
out dx,al 
it stops at offset=64000 bytes while the image is about 120K, see bochs output below:

00218236515d[FDD ] BEFORE
00218236515d[FDD ] drive = 0
00218236515d[FDD ] head = 0
00218236515d[FDD ] cylinder = 3
00218236515d[FDD ] sector = 1
00218236515d[FDD ] eot = 18
00218236515d[FDD ] floppy_xfer: drive=0, offset=55296, bytes=512, direction=from floppy
...
00218792576d[FDD ] floppy_xfer: drive=0, offset=55808, bytes=512, direction=from floppy
...



...
00226021369d[FDD ] floppy_xfer: drive=0, offset=62464, bytes=512, direction=from floppy
...
00226577430d[FDD ] floppy_xfer: drive=0, offset=62976, bytes=512, direction=from floppy
...
00227133491d[FDD ] floppy_xfer: drive=0, offset=63488, bytes=512, direction=from floppy
...
00227689552d[FDD ] floppy_xfer: drive=0, offset=64000, bytes=512, direction=from floppy
...
00228245613d[FDD ] <<READ DONE>>
00228245613d[FDD ] AFTER
00228245613d[FDD ] drive = 0
00228245613d[FDD ] head = 1
00228245613d[FDD ] cylinder = 3
00228245613d[FDD ] sector = 1

thanks
ivan
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: can't load mpore than 64K from floppy

Post by neon »

Hello,

I would suspect it is do to real mode addressing not being able to exceed 1MB+64k. A workaround (what I do) is load a part of the kernel into a buffer and move it to its real location in protected mode, repeating until loaded.

Also, you are trying to read the whole floppy disk in memory? That wont be possible in real mode and really isnt necessary.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: can't load mpore than 64K from floppy

Post by bewing »

You are setting ES: to 0xffff? That selects the "High Memory Area".

As neon implied -- do you realize that the HMA is slightly less than 64K in maximum size? Of course your read is going to fail when it gets to 64K.
You are lucky that it even gets that far. Many BIOS functions do not support reading or writing to the HMA at all.
Post Reply