Large file bug in Stage2 ?

If you are new to OS Development, plan on spending some time here first before going into the other forums.

Moderator:Moderators

Post Reply
gedd
Posts:12
Joined:Mon Jun 08, 2009 7:08 am
Large file bug in Stage2 ?

Post by gedd » Tue Jun 09, 2009 7:10 am

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

User avatar
Wolf
Posts:11
Joined:Mon May 18, 2009 10:35 pm

Re: Large file bug in Stage2 ?

Post by Wolf » Tue Jun 09, 2009 6:56 pm

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.

gedd
Posts:12
Joined:Mon Jun 08, 2009 7:08 am

Re: Large file bug in Stage2 ?

Post by gedd » Wed Jun 10, 2009 6:35 am

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 ?

Andyhhp
Moderator
Posts:387
Joined:Tue Oct 23, 2007 10:05 am
Location:127.0.0.1
Contact:

Re: Large file bug in Stage2 ?

Post by Andyhhp » Wed Jun 10, 2009 3:52 pm

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
Image

gedd
Posts:12
Joined:Mon Jun 08, 2009 7:08 am

Re: Large file bug in Stage2 ?

Post by gedd » Thu Jun 11, 2009 8:49 am

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

Andyhhp
Moderator
Posts:387
Joined:Tue Oct 23, 2007 10:05 am
Location:127.0.0.1
Contact:

Re: Large file bug in Stage2 ?

Post by Andyhhp » Thu Jun 11, 2009 1:00 pm

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
Image

gedd
Posts:12
Joined:Mon Jun 08, 2009 7:08 am

Re: Large file bug in Stage2 ?

Post by gedd » Thu Jun 11, 2009 1:07 pm

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

gedd
Posts:12
Joined:Mon Jun 08, 2009 7:08 am

Re: Large file bug in Stage2 ?

Post by gedd » Thu Jun 11, 2009 2:23 pm

seems to be a segment overflow

ES: 0x0000 | BX: 0xFE00

before call int 13h

0xFE00 + 0x200 > 0xFFFF

gedd
Posts:12
Joined:Mon Jun 08, 2009 7:08 am

Re: Large file bug in Stage2 ?

Post by gedd » Sat Jun 13, 2009 1:12 pm

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

Post Reply