Kernel size problem
Moderator:Moderators
-
- Posts:63
- Joined:Wed Jul 22, 2009 6:44 am
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....
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...
Think it, build it, bit by bit...
Re: Kernel size problem
Can you guarentee you are loading all of your kernel into memory?
Look at the loop which loads it off disk.
Look at the loop which loads it off disk.

-
- Posts:63
- Joined:Wed Jul 22, 2009 6:44 am
Re: Kernel size problem
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
That will tell for certain whether it is a bug in your kernel or a bug in your loader

-
- Posts:63
- Joined:Wed Jul 22, 2009 6:44 am
Re: Kernel size problem
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...
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...
Think it, build it, bit by bit...
Re: Kernel size problem
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.
-
- Posts:63
- Joined:Wed Jul 22, 2009 6:44 am
Re: Kernel size problem
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)
am I right?
...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'
_____________
Think it, build it, bit by bit...
Think it, build it, bit by bit...
Re: Kernel size problem
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
See http://wiki.osdev.org/Memory_Map_%28x86%29
Also, your calculation is wrong:
0x3000 + 53760 Bytes long (0300:D200) = 0x10200
~Andrew

-
- Posts:63
- Joined:Wed Jul 22, 2009 6:44 am
Re: Kernel size problem
you are right. sorry about that... (something failed pasting the value)
But, as you can see, it is loaded at the free space...
But, as you can see, it is loaded at the free space...
_____________
Think it, build it, bit by bit...
Think it, build it, bit by bit...
Re: Kernel size problem
In which case, are you sure the crash is not because you have some dud code in your kernel?

-
- Posts:63
- Joined:Wed Jul 22, 2009 6:44 am
Re: Kernel size problem
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...
Think it, build it, bit by bit...
-
- Posts:63
- Joined:Wed Jul 22, 2009 6:44 am
Re: Kernel size problem
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...
I'm trying to figure out the reason is crashing...
_____________
Think it, build it, bit by bit...
Think it, build it, bit by bit...
Re: Kernel size problem
Which line is causing it to crash?
-
- Posts:63
- Joined:Wed Jul 22, 2009 6:44 am
Re: Kernel size problem
in line "(here)"...
...but the real problem is 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...
Think it, build it, bit by bit...