Kernel size problem

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

Moderator: Moderators

Insightsoft
Posts: 63
Joined: Wed Jul 22, 2009 6:44 am

Kernel size problem

Post by Insightsoft » Wed May 25, 2011 6:10 pm

Hi,

Following the 'Operating System Development Series', and adding some functions to debug and testing while running... makes, as expected, increase the kernel size...

but I verified that at:
- 53248 bytes (104 sectors of 512 bytes) - it works!
- 53760 bytes (105 sectors of 512 bytes) - it crash!

Any clue?

thanks....
_____________
Think it, build it, bit by bit...

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

Re: Kernel size problem

Post by Andyhhp » Thu May 26, 2011 7:22 pm

Can you guarentee you are loading all of your kernel into memory?

Look at the loop which loads it off disk.
Image

Insightsoft
Posts: 63
Joined: Wed Jul 22, 2009 6:44 am

Re: Kernel size problem

Post by Insightsoft » Thu May 26, 2011 8:28 pm

Yap...
_____________
Think it, build it, bit by bit...

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

Re: Kernel size problem

Post by Andyhhp » Thu May 26, 2011 8:31 pm

One useful debugging measure is to have your kernel loader write a known value into the sector after the final one it loads in memory, and have the start routine of your kernel search for this known value and verify it.

That will tell for certain whether it is a bug in your kernel or a bug in your loader
Image

Insightsoft
Posts: 63
Joined: Wed Jul 22, 2009 6:44 am

Re: Kernel size problem

Post by Insightsoft » Sun May 29, 2011 2:11 am

That was what i did... the kernel is fully load into the memory...

On disk file, I've changed the very last two bytes... then, after being loaded, this two bytes were found in memory (as expected)! (so, kernel fully loaded)...
I'm wondering if is not about the "InitializeConstructors"... I realy don't understand why, with simple next 512 bytes (1 sector), even with no relevant data, is enough to make the system crash...
_____________
Think it, build it, bit by bit...

Hoozim
Posts: 34
Joined: Sun Nov 21, 2010 6:40 pm

Re: Kernel size problem

Post by Hoozim » Sun May 29, 2011 3:17 am

The error could be caused by the fact that the loader loads the kernel into 16bit space. That means that the extra 512 bytes (1 sector) could be written into a vital data structure. This would cause a crash. For example, the kernel could expand into the page tables. When memory is next accessed, it will read/write random memory and that would quickly lead to a crash. If this turns out to be the problem. Try making another loader that the bootloader loads into 32bit space. This loader can then load the kernel and not have to worry about memory restrictions.

Insightsoft
Posts: 63
Joined: Wed Jul 22, 2009 6:44 am

Re: Kernel size problem

Post by Insightsoft » Sun May 29, 2011 11:26 pm

I see...

...but is not the case (I hope), since I load it to 0x0300:0000 (0x000003000)

0x3000 + 53760 Bytes long (0300:D200) = 0x5D00 (I think this range is free)

Code: Select all

0x00000----->   0x003FF      (0000:0000----->0000:03FF)   (    1.024 bytes)      - BIOS Data Area (BDA) - IVT
0x00400----->   0x006FF      (xxxx:xxxx----->xxxx:xxxx)   (      767 bytes)      - BIOS Data Area (BDA) - Various
0x00700----->   0x7FFFF      (xxxx:xxxx----->xxxx:xxxx)   (  653.567 bytes)      - <free memory> Part of RAM 640 kb
0xA0000----->   0xBFFFF      (xxxx:xxxx----->xxxx:xxxx)   (  131.071 bytes)      - Video Display RAM
0xC0000----->   0xC7FFF      (xxxx:xxxx----->xxxx:xxxx)   (   32.767 bytes)      - ROM Expansion 32 Kb
0xC8000----->   0xC9FFF      (xxxx:xxxx----->xxxx:xxxx)   (    8.191 bytes)      - Disk Controller ROM
0xCA000----->   0xF3FFF      (xxxx:xxxx----->xxxx:xxxx)   (  172.031 bytes)      - ROM Expansion 168 Kb
0xF4000----->   0xF5FFF      (xxxx:xxxx----->xxxx:xxxx)   (    8.191 bytes)      - User ROM 8 Kb (Spare)
0xF6000----->   0xFDFFF      (xxxx:xxxx----->xxxx:xxxx)   (   32.767 bytes)      - BASIC Compiler
0xFE000----->   0xFFFFF      (xxxx:xxxx----->xxxx:xxxx)   (    8.191 bytes)      - BIOS 8 Kb
----------------------------------------------------------------------------------------------------------------------------------------
0x00000----->   0xfffff      (xxxx:xxxx----->ffff:ffff)   (1.048.575 bytes)      - Full range on Real Mode

above is the 'deep whiter'



am I right?
_____________
Think it, build it, bit by bit...

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

Re: Kernel size problem

Post by Andyhhp » Sun May 29, 2011 11:35 pm

Close, but you have more memory that that.

See http://wiki.osdev.org/Memory_Map_%28x86%29

Also, your calculation is wrong:

0x3000 + 53760 Bytes long (0300:D200) = 0x10200

~Andrew
Image

Insightsoft
Posts: 63
Joined: Wed Jul 22, 2009 6:44 am

Re: Kernel size problem

Post by Insightsoft » Mon May 30, 2011 1:00 am

you are right. sorry about that... (something failed pasting the value)
But, as you can see, it is loaded at the free space...
_____________
Think it, build it, bit by bit...

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

Re: Kernel size problem

Post by Andyhhp » Mon May 30, 2011 11:26 am

In which case, are you sure the crash is not because you have some dud code in your kernel?
Image

Insightsoft
Posts: 63
Joined: Wed Jul 22, 2009 6:44 am

Re: Kernel size problem

Post by Insightsoft » Mon May 30, 2011 7:21 pm

it crash exactly here:

Code: Select all

void fsysFatMount () {

   //! Boot sector info
   PBOOTSECTOR bootsector;

   //! read boot sector
   bootsector = (PBOOTSECTOR) flpydsk_read_sector (0);

   //! store mount info
   _MountInfo.numSectors     = bootsector->Bpb.NumSectors;
   _MountInfo.fatOffset      = 1;
   _MountInfo.fatSize        = bootsector->Bpb.SectorsPerFat;
   _MountInfo.fatEntrySize   = 8;
   _MountInfo.numRootEntries = bootsector->Bpb.NumDirEntries;
   _MountInfo.rootOffset     = (bootsector->Bpb.NumberOfFats * bootsector->Bpb.SectorsPerFat) + 1;
   _MountInfo.rootSize       = ( bootsector->Bpb.NumDirEntries * 32 ) / bootsector->Bpb.BytesPerSector;          (here)
}
_____________
Think it, build it, bit by bit...

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

Re: Kernel size problem

Post by Andyhhp » Mon May 30, 2011 7:31 pm

Try asserting that bootsector->Bpb.BytesPerSector is not 0;
Image

Insightsoft
Posts: 63
Joined: Wed Jul 22, 2009 6:44 am

Re: Kernel size problem

Post by Insightsoft » Mon May 30, 2011 10:23 pm

remember that with 53248 bytes (104 sectors of 512 bytes) the same code works just fine...
I'm trying to figure out the reason is crashing...
_____________
Think it, build it, bit by bit...

Hoozim
Posts: 34
Joined: Sun Nov 21, 2010 6:40 pm

Re: Kernel size problem

Post by Hoozim » Wed Jun 01, 2011 1:20 am

Which line is causing it to crash?

Insightsoft
Posts: 63
Joined: Wed Jul 22, 2009 6:44 am

Re: Kernel size problem

Post by Insightsoft » Wed Jun 01, 2011 2:53 pm

in line "(here)"...
...but the real problem is here:

Code: Select all

void _cdecl InitializeConstructors()
{
   _atexit_uint32_t();
   _uint32_tterm(__xc_a, __xc_z);                     (here)
}
_____________
Think it, build it, bit by bit...

Post Reply