Page 1 of 1

Large file bug in Stage2 ?

Posted: Tue Jun 09, 2009 7:10 am
by gedd
Hello

I use Brokenthorn tutorials to devellop my os, specialy the boot (stage 1 and stage 2).
Recently, while testing my new add on my os, it hang with no reason.
With a little investigation, i found it was because my kernel was "too big".

At a certain size, if i add some function or data which are making growing up the size, the system hang.
The problem is in stage 2, Fat12-> LoadFile, and more precisely maybe in Floppy16->ReadSector

Because i have modified stage2 for my OS, i have made some other test.
- take a BrokenThorn Tutorial demo (last for example)
- build project, test it : it works
- just had some data in a source file , ex: char data[n] = { 0,0,0,0,0,0, ...n};
increase executable size untill 50-55 kb
- build project , test it : it fails

It just a size problem, i think

Have you ever had same problem ?
Bug or not ?
I investigate more to have a solution, but if you had one, you're welcome

Re: Large file bug in Stage2 ?

Posted: Tue Jun 09, 2009 6:56 pm
by Wolf
That may be true, but it has never happened to me. Post any of your findings here, would you? I will edit my version if that is the case.

Re: Large file bug in Stage2 ?

Posted: Wed Jun 10, 2009 6:35 am
by gedd
Wolf wrote:but it has never happened to me

All right , what is your kernel size ?

Wolf wrote:Post any of your findings here, would you?

Done, have your made test with step decribed in my first post ?

Re: Large file bug in Stage2 ?

Posted: Wed Jun 10, 2009 3:52 pm
by Andyhhp
There is a bug in the code that reads sectors from disk.

It is specifically to do with not putting the correct values into CH/CL for the int 0x13 call

The code is currently being corrected and should be updated soon.

~Andyhhp

Re: Large file bug in Stage2 ?

Posted: Thu Jun 11, 2009 8:49 am
by gedd
I have made some test

whatever the size (after critical size limit), the ReadSectors function fail at the same place and same parameters

......
jnc .SUCCESS ; test for read error
xor ax, ax ; BIOS reset disk
int 0x13 ; invoke BIOS
dec di ; decrement error counter
.....

with this parameters
LBA : 0x88
Track : 0x03
Sector : 0x0B
Head : 0x01
Drive : 0x00

May help you

Re: Large file bug in Stage2 ?

Posted: Thu Jun 11, 2009 1:00 pm
by Andyhhp
whatever the size (after critical size limit), the ReadSectors function fail at the same place and same parameters


Are you certain that it fails at that point?

That code is the FDD reset command and has nothing relevent to do with reading

~Andrew

Re: Large file bug in Stage2 ?

Posted: Thu Jun 11, 2009 1:07 pm
by gedd
Sorry, bad COPY/PASTE
2 lines up here
...
int 0x13 ; invoke BIOS
jnc .SUCCESS ; test for read error
xor ax, ax ; BIOS reset disk
int 0x13 ; invoke BIOS
...

But i think the error comme before in LoadFile
I try a solution and give you the result

Re: Large file bug in Stage2 ?

Posted: Thu Jun 11, 2009 2:23 pm
by gedd
seems to be a segment overflow

ES: 0x0000 | BX: 0xFE00

before call int 13h

0xFE00 + 0x200 > 0xFFFF

Re: Large file bug in Stage2 ?

Posted: Sat Jun 13, 2009 1:12 pm
by gedd
Ok when int 13 function 02 (read sector ) is called, it need ES:BX point to a buffer
At first sector read the value is 0x0000:0x3000, and when your kernel file is more 51 kb (0xFFFF - 0x3000)
you write memory at 0x0000:0x0000
Solution is to add BX/16 to ES and reset BX before continue