Yet another kernel problem YaKP (global variables)

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
guest

Yet another kernel problem YaKP (global variables)

Post by guest »

Hi this is a second try. OK every global variables is set to zero.

f.e.:

Code: Select all

int test = 10;

void main()
{
   // test is == 0, why???
}
( should i setup some registers after enable paging?? )
Curufir

Re:Yet another kernel problem YaKP (global variables)

Post by Curufir »

I came up against something quite similar yesterday.

After 3 hours of frustration, cursing the computer, questioning my memory of C programming, and wondering if stamp collecting might be a more amusing hobby I finally tracked it down to my linker script. I'd put one extra 0 in the address, so the global data was in the binary, but the linker was using the wrong when pointing things at it.

My advice would be to check your addresses.

***

On the plus side I now have a much better understanding of pointers in C than I've ever had before ;D.
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:Yet another kernel problem YaKP (global variables)

Post by Pype.Clicker »

hmm ... a few things first:
1) would you mind registering, so that we all know you're always the *same* guest ?
2) please try to stay in the same thread when you're posting on the same topic ... that way we won't wonder "say, i said something alike yesterday, didn't i?"

btw. your linker script looks fine, but did your loader (which one do you use?) did its job properly ? (for instance, did it load *enough* sectors so that all your data are there ?) if you have something that wipes the BSS, are you sure it doesn't wipe *too much* data.

finally, if you have something like

Code: Select all

   int magic=0xdeadbeef;
can you see 'deadbeef' in the binary stuff you'll give to your loader ? if not, this is probably a linking problem.
If you do, add a small asm function that will look for it in memory (if you're on real hardware) before you enable paging or things like these -- or simply look for it in memory dump if you're using bochs ...

Hope this helps.

Code: Select all

    mov esi,_code
    cmp esi,_end
    je .notfound
    mov eax,[esi]
    xor eax,0x21524110 ;; deadbeef's complement, so that you
                               ;; don't get false hits
    cmp eax,0xffffffff ;; 0xdead beef ^ 0x2152 4110 = 0xffff ffff
    je .found
ich_will

Re:Yet another kernel problem YaKP (global variables)

Post by ich_will »

Now I'm a member. 8)
btw. your linker script looks fine, but did your loader (which one do you use?) did its job properly ?
I use my own bootloader, but i don't know if i have forgotten something.
if you have something that wipes the BSS, are you sure it doesn't wipe *too much* data.
how can I do this?? I think the bootf02 doesn't do this, or.



do you mean a magic header??

[attachment deleted by admin]
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Yet another kernel problem YaKP (global variables)

Post by Candy »

Curufir wrote: After 3 hours of frustration, cursing the computer, questioning my memory of C programming, and wondering if stamp collecting might be a more amusing hobby
You found a bug after only 3 hours and were thinking about other hobbies instead? 3 hours on a real OS bug is quite fast ;)
My advice would be to check your addresses.
Can double on that, and all the arithmetic... forgot a +1 yesterday which caused my new paging code to NOT reserve the data section of my code as reserved (which it is) but to overwrite it with page frame tables... All of a sudden all my mutexes were zero! :D

hardest bug for me up to now was a week of debugging...
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:Yet another kernel problem YaKP (global variables)

Post by Pype.Clicker »

A few things that you can do to check your bootloader job is:
- use the video memory as a 'buffer' when loading: this will roughly display sectors on screen so that you can check what you load is not garbage but your preciousss data... Once you know that work, revert to another memory area.
- while loading sectors/track, sum up all the words in a Checksum variable and display the content of that variable on screen when done. Then compare the result with the same computation performed "offline" on the file you wished to load. If results are different, something went wrong while loading and you should abort ... If results are the same, there are chances (but chances only) that the loading process was okay.
- before starting your image, put zeroes between __end_data and __end_image: this is where the BSS section should be.
- set up a new stack before you jump to the kernel. Make sure your stack and your data segment have the very same base. This sounds silly, but make sure it has enough space to run (preferably by placing it somewhere in the .bss section)

Code: Select all

section .bss
align 4
end_of_stack:
     resd 1024 ;; a 4Kb stack might be enough ??
top_of_stack:
     dd halt_instruction

section .code

halt_instruction:
     cli
     hlt

_start:
     mov esp, top_of_stack
     ;; other stuff
ich_will

Re:Yet another kernel problem YaKP (global variables)

Post by ich_will »

OK now all works fine, sometimes its better to use old versions of progamms. :)

I use the new version of Bochs, this version restarts if I halt the cpu, so I think oh there must be an error, but there is no. After my first post of this thread i add the stack setup to my bootloader, and try it with the new Bochs, but it restarts. Now I use a for-loop at the end of the kernel and see, all is displayed and works fine.

Thank You.

P.S.: SAY NOTHING TO THIS. ::)
Post Reply