NO

Author Topic: global variables...  (Read 4126 times)

guest

  • Guest
global variables...
« on: March 11, 2005, 11:15:01 PM »
Hello, i want to develop my OS Kernel with Pelles C. But i have a problem with global variables. I link my kernel with /BASE:0x100000. I havent got a PE loader yet so i overwrite the bytes 0 - 0x1FF with NOP instructions  :) So that my bootloader jumps to 0x100000 and then it executes NOP till kernel entry... I know bad method but its OK for the beginning. All works but theres a problem that global variables arent defined. I can write
//global data...
int x = 5;   But x isnt 5 after.....
Please help me to fix the problem :-)

guest

  • Guest
global variables...
« Reply #1 on: March 12, 2005, 05:09:14 PM »
Hey, how to link the data section directly after the text section ??

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
global variables...
« Reply #2 on: March 13, 2005, 12:41:40 AM »
No (easy) way to change the section order in the linker. Maybe easier to combine sections with the /MERGE option?

Pelle
/Pelle

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
global variables...
« Reply #3 on: March 14, 2005, 01:01:08 PM »
Hello,
dear guest (I don't know your name, it would be nice to know)  two points:
1) Why use this way to access the code, you could jump directly @ 0x100200
2) What about disk/memory alignment (Linker option /ALIGN ?), in my code variables assignement works.
As far as I can understand your code actually is less than 512 bytes, or one page (4k), and something very bad will happen as soon as you will write more code. Keep memory and disk aligned @512.
Regards
F.
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
global variables...
« Reply #4 on: March 14, 2005, 04:53:24 PM »
Sorry I forget to add that the .text (code) section is normally the first section following the headers, so no there is no need to force its position (then follows the .rdata, .data, .idata. .rsrc and finally the debug section).
Hope to have been of some help.
F.
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide