LD kernel memory allocation (important for all)

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
Thunder

LD kernel memory allocation (important for all)

Post by Thunder »

Hi,

I have one problem, my kernel size is 21 KB and I've allocaded kernel text section to 0x100000 (1MB).
When I create a pointer to structure and try to write to it, it works but after a few other commands, when I read it it shows not correct values. When i try to make this pointer with 5 elements, kernel crashes:

struct{
short some_variable;
...
} *pointer; // it shows not correct values

struct{
...
} pointer[5]; // kernel crashes

P.S. on win32 program test it works fine it both ways.

Can the problem be connected with bss and data allocation?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:LD kernel memory allocation (important for all)

Post by Pype.Clicker »

hmm, you are of course aware of the fact that
struct {...} *pointer; never allocates memory for your struct, but only for the pointer ! If just after this, you write pointer->field, you're referencing the void (NULL pointer at best if you cleared your BSS section)

For struct {...} array[5], things are a bit different, but the 5 arrays will go to the BSS aswell. Now, depending on how you organize your kernel (and if there can be some collision or if you forget the BSS in your linker script), you may have something else at that location.

Try to get a link map of your kernel to figure out what's happening ... And if you're using a bootloader of your own, make sure it correctly supports BSS sections and that it has correctly initialized A20 gate (though 21K shouldn't be enough to wrap around, but who knows ;)
Post Reply