Autor Thema: C-Funktionen...  (Gelesen 3958 mal)

Another Stupid Coder

  • Beiträge: 749
    • Profil anzeigen
Gespeichert
« am: 12. December 2004, 14:39 »
Hallo,
Mein neuestes Problem, bei dem ich wirklich nicht weiter weiß...neben globalen Variablen kann ich nun auch keine Funktionen benutzen...Es sollte am C-Kernel liegen, alles andere hatte ich schon zum testen ausprobiert...ich habe den Kernel 2 mal nur von C in Assembler übersetzen lassen, 1mal mit dem Code in der Main-Funktion (klappt) einmal mit dem Code in "void PutCharA()" (klappt nicht!) wäre nett wenn jemand wüsste was da los ist...
C-Code: (der funzt. Im 2. Asm-Code wurde dann alles nach "PutCharA();" aus der Main-Funktion in die PutCharA-Funktion kopiert.)

unsigned char *VGA;

void PutCharA();

void main()
{
VGA = (unsigned char *)0xA0000;
PutCharA();

unsigned int PositionOfTheChar = 1 * 80 * 10;

VGA[PositionOfTheChar] = 0x3C; // 00 11 11 00
VGA[PositionOfTheChar + 80] = 0x42; // 01 00 00 10
VGA[PositionOfTheChar + 160] = 0x81; // 10 00 00 01
VGA[PositionOfTheChar + 240] = 0xFF; // 11 11 11 11
VGA[PositionOfTheChar + 320] = 0x81; // 10 00 00 01
VGA[PositionOfTheChar + 400] = 0x81; // 10 00 00 01
VGA[PositionOfTheChar + 480] = 0x81; // 10 00 00 01
VGA[PositionOfTheChar + 560] = 0x81; // 10 00 00 01

};

void PutCharA()
{

};

1. Asm-Code (Wo alles in der Main-Funktion steht)

.file "Main.c"
.text
.globl PutCharA
.type PutCharA, @function
PutCharA:
pushl %ebp
movl %esp, %ebp
popl %ebp
ret
.size PutCharA, .-PutCharA
.globl main
.type main, @function
main:
pushl %ebp
movl $655360, VGA
movl %esp, %ebp
call PutCharA
movb $60, 656160
movb $66, 656240
movb $-127, 656320
movb $-1, 656400
movb $-127, 656480
movb $-127, 656560
movb $-127, 656640
movb $-127, 656720
popl %ebp
ret
.size main, .-main
.comm VGA,4,4
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.3.3"

Und so sieht das ganze aus, wenn der Code in die PutCharA-Funktion ausgelagert wurde:

.file "Main.c"
.text
.globl PutCharA
.type PutCharA, @function
PutCharA:
movl VGA, %eax
pushl %ebp
movl %esp, %ebp
movb $60, 800(%eax)
movl VGA, %eax
movb $66, 880(%eax)
movl VGA, %eax
movb $-127, 960(%eax)
movl VGA, %eax
movb $-1, 1040(%eax)
movl VGA, %eax
movb $-127, 1120(%eax)
movl VGA, %eax
movb $-127, 1200(%eax)
movl VGA, %eax
movb $-127, 1280(%eax)
movl VGA, %eax
movb $-127, 1360(%eax)
popl %ebp
ret
.size PutCharA, .-PutCharA
.globl main
.type main, @function
main:
pushl %ebp
movl $655360, VGA
movl %esp, %ebp
popl %ebp
jmp PutCharA
.size main, .-main
.comm VGA,4,4
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.3.3"


gcc --freestanding -Os -fno-builtin -c  -o Main.obj Main.c
ld --oformat "binary" -o Kernel.bin Start32.obj Main.obj

Also, falls jemand gerade Zeit hat :)

Roshl

  • Beiträge: 1 128
    • Profil anzeigen
    • http://www.lowlevel.net.tc
Gespeichert
« Antwort #1 am: 12. December 2004, 15:49 »
Vielleicht irritert ihn das nach dem PutCharA(); nichts mehr kommt, denn seltsamerweise compiled er den aufruf ja dann als jmp nicht als call, und da die routine dann ja trotzdem per ret beenden will gibts n fehler weil keine rücksprungaddi aufm stack ist
Setz mal noch andre befehle dahinter, vielleicht macht er dann nen call draus
[schild=1]Wieder ein wertvoller(?) Beitrag von Roshl[/schild]

GhostCoder

  • Beiträge: 187
    • Profil anzeigen
Gespeichert
« Antwort #2 am: 12. December 2004, 16:37 »
@Roshl:

Nee, der Code ist schon richtig, da nach dem PutChar Aufruf nichts mehr kommt, kann er auch direkt zu PutChar springen, und das ret von PutChar springt dann zurück zu dem Punkt, nach dem "call _main". Sieht wie ne kleine Optimierung aus. Schreib doch mal hinter dem PutChar aufruf

asm("cli\n\thlt")


Was passiert den dann?

MfG GhostCoder
A man, a legend!

Another Stupid Coder

  • Beiträge: 749
    • Profil anzeigen
Gespeichert
« Antwort #3 am: 12. December 2004, 16:45 »
Es ändert sich praktisch nichts...außer das halt die 2 Befehle eingefügt werden: EDIT: Doch es ist jetzt ein call...aber trotzdem wird nichts ausgegeben (VGA-Mode 0x12)

.file "Main.c"
.text
.globl PutCharA
.type PutCharA, @function
PutCharA:
movl VGA, %eax
pushl %ebp
movl %esp, %ebp
movb $60, 800(%eax)
movl VGA, %eax
movb $66, 880(%eax)
movl VGA, %eax
movb $-127, 960(%eax)
movl VGA, %eax
movb $-1, 1040(%eax)
movl VGA, %eax
movb $-127, 1120(%eax)
movl VGA, %eax
movb $-127, 1200(%eax)
movl VGA, %eax
movb $-127, 1280(%eax)
movl VGA, %eax
movb $-127, 1360(%eax)
popl %ebp
ret
.size PutCharA, .-PutCharA
.globl main
.type main, @function
main:
pushl %ebp
movl $655360, VGA
movl %esp, %ebp
call PutCharA
#APP
cli
hlt
#NO_APP
popl %ebp
ret
.size main, .-main
.comm VGA,4,4
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.3.3"

Btw. wenn ich es ohne Optimierung mache, klappts auch nicht...der Code ohne Optimierung ist ein wenig lang, wenn er aber benötigt wird poste ich ihn gerne, ansonsten hat ja jeder der in sich ansehen will oben den GCC-Befehl und den C-Code :)

GhostCoder

  • Beiträge: 187
    • Profil anzeigen
Gespeichert
« Antwort #4 am: 12. December 2004, 17:44 »
Wird den überhaupt was ausgegeben, wenn du wie ein verrückter nach 0xA0000 schreibst? :)
Ansonsten kann ich dir net helfen, mit Video mach ich im Moment noch nichts...

MfG GhostCoder
A man, a legend!

Another Stupid Coder

  • Beiträge: 749
    • Profil anzeigen
Gespeichert
« Antwort #5 am: 12. December 2004, 17:48 »
Ja, in dem Modus, liegt der Videospeicher an der Stelle...und wenn alles in der Main-Funktion steht klappts ja auch.

Roshl

  • Beiträge: 1 128
    • Profil anzeigen
    • http://www.lowlevel.net.tc
Gespeichert
« Antwort #6 am: 13. December 2004, 16:26 »
Wenn der Stack  nicht gehen würde, dann würde es ja auch in der Mainfunktion nicht gehen.
Biste schonmal mit Bochs schrittweise durchgegangen?
[schild=1]Wieder ein wertvoller(?) Beitrag von Roshl[/schild]

 

Einloggen