Autor Thema: C-Kernel und globale Variablen...  (Gelesen 2314 mal)

Another Stupid Coder

  • Beiträge: 749
    • Profil anzeigen
Gespeichert
« am: 23. April 2005, 10:41 »
Hallo :)
Ich hab jetzt mal wieder nen C-Kernel und damit auch gleich ein Problem. Wenn ich Variablen Global deklariere und ihnen gleich einen Wert zuweise, so funktioniert das nicht, aber wenn ich sie global deklariere und ihnen den Wert erst in der Main-Funktion gebe, funktioniert es, Beispiel:

int Bla = 1;

void Main()
{
// Bla ist trotzdem 0.
}


int Bla;

void Main()
{
// Bla ist 1.
}

Tja, gibts da irgendwelche speziellen Register die GCC benutzt, oder macht er was spezielles am Stack oder halt IRGENDWAS, was ich beachten sollte? Wäre sehr nett, wenn jemand was wüsste :)
Hier noch der Code vom Kernelstarter:

;      _/    _/  _/_/_/_/  _/        _/  _/_/_/_/  _/_/_/_/
;     _/    _/  _/        _/        _/  _/    _/  _/
;    _/    _/  _/        _/        _/  _/    _/  _/
;   _/_/_/_/  _/_/_/    _/        _/  _/    _/  _/_/_/_/
;  _/    _/  _/        _/        _/  _/    _/        _/
; _/    _/  _/_/_/_/  _/_/_/_/  _/  _/_/_/_/  _/_/_/_/
; =======================================================
; = (C) 2005 by Paul Anselm Haerle =
; = Mail: paulhaerle@gmx.at =
; = ICQ: 214604864 =
; =======================================================
[bits 32] ; yeah, the power of 32bit ;).
[extern Main]
[global start]
[global LinearFrameBuffer]
start:
mov ax, 0x0010 ; move the code selector to ax.
mov ds, ax ; move the cs to ds.
mov es, ax ; move the cs to es.
mov fs, ax ; move the cs to fs.
mov gs, ax ; move the cs to gs.
mov ss, ax ; move the cs to ss.
mov esp, 0x9FFFF ; set the stackpointer to 0x9FFFF

mov edi, [0x30000+40]
mov dword [LinearFrameBuffer], edi ; lfbadress was stored in edi during our time in rm.
; -------------------------------------------------------
; - This turns off the floppymotor. -
; -------------------------------------------------------
mov dx, 0x3F2 ; floppydrive port.
mov al, 0x0C ; command "stop the motor.".
out dx, al ; send this command.
; =======================================================
; = The C-Kernel. =
; =======================================================
call Main

cli
hlt
; =======================================================
; = Data. =
; =======================================================
LinearFrameBuffer dd 0

(Im Bootloader wird in den Pmode geschalten und dann eben in diesen Kernelstarter fargejumpt...

Another Stupid Coder

  • Beiträge: 749
    • Profil anzeigen
Gespeichert
« Antwort #1 am: 23. April 2005, 10:55 »
Hat sich schon erledigt, war ein sehr dummer Fehler. Für alle die das gleiche Problem haben: Das Offset in Link.ld war falsch, ich hatte mich vertippt und 0x100000 statt 0x10000 angegeben.

Vielen Dank an Stefan2005, der mich auf die Idee gebracht hat, das nochmal zu prüfen :)

 

Einloggen