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.
Uff..Im an ex-user of tcc, tasm and tlink, and now having a few problems with gcc, nasm and ld. Why doesnt my _Test function doesnt work?? and why doesnt ld warn me for the function called but not implemented? is there a parameter for it?(I mean in a file I call an extern function but it doesnt exists, for ins. due to bad spelling...)
nullify: I dont think that's true.... I call _main in my code from asm and it works correctly.
What exactly isn't working Fosur? You're asking why it doesn't complain about a function called but not implemented, but I don't see any? you call main and you call Test, both of which have implementations. Please describe more what's happening and what isn't working.
bkilgore wrote:
nullify: I dont think that's true.... I call _main in my code from asm and it works correctly.
I have a similar situation here. I call "kmain" from my assembly code and it correctly calls "kmain()" in my C code, without any name-mangling. What C compiler are you using, bkilgore?
What exactly isn't working Fosur? You're asking why it doesn't complain about a function called but not implemented, but I don't see any? you call main and you call Test, both of which have implementations
Yes, here sure.. But for instance, if I have misspelled Test as Teest, it also compiles and links. And I want linker warn me for the functions that dont have implementations anywhere..
And my real problem is the other one..Indeed I just can not call Test function. Im sure bootsector jumps the kernelentry and from there jump to main in my C code. Indeed I have some else C functions and they also works fine. But when I want to jump a function, implemented in assembly, bochs gives me an error like, "weird VGA writing...." and stucks. It means that, I can jump C code from my asm kernelentry, jump between C codes but can not jump asm code from C. When I add a section name in my asm file, the bochs doesnt give any error but the function still doesnt works... uff..sorry for my poor English and my silly problem.. please help mee... I just want a kernel, which may jump between C and asm codess...
Ok, it appears I misunderstood the problem before...
Try removing the "mov ax, 1" line to see if it can cleanly enter and leave the _Test function without problems. If that still fails, try putting a "cli;hlt" as soon as you enter _Test, to see if it even enters the assembly routine properly.
Also you might want to test your kernel on a real computer, in case your configuration of Bochs is the problem.
bkilgore wrote:
nullify: I dont think that's true.... I call _main in my code from asm and it works correctly.
I might be wrong here, but wasn't _main where all the initializing stuff is being done - setting up stdin, stdout, argc, argv, initializing statics etc.?
Every good solution is obvious once you've found it.
I think the kernel never jumps to _Test function. Because I put a code just to write screen a char and it didnt work. Must I put them in a section??I mean when I wrote a section name in my asm file, bochs dont give an error but it still stucks..?is it necessarry to write a section name and put functions after it??like:
Bochs is exiting with the following message:
[VGA ] Weird VGA write size
Im attaching the code.This is so simple an error but as I said Im new to gcc, nasm and ld and ld script(Im used to use tcc, tasm and tlink). So please someone help me...
And as for another question, tlink(my ex linker) warns me for the functions not implemented (I mean when I call an extern function, and at linking step if linker cant find such a function it gives error that such a function not implemented). I couldnt find any parameter for ld to warn me for those kinda functions. Is there such a parameter for ld??
df wrote:
elf v djgpp for name mangling. iirc, djgpp adds a _ where as elf does not add a _ to the name.
Actually, the difference is between the ELF and COFF executable formats. COFF (COmmon Object File Format) is an older Unix standard which follows the classical C name-mangling convention; it is still used by some commercial Unices, last I checked. DJGPP v.1.12 and earlier produces COFF object files by default, and uses a special program, go32, to load them (v.2.0 and later produces OMF/.EXE files by default instead, which run directly under DOS and DPMI, IIRC). Thus, assembly code linked under DJGPP must be name-mangled.
Linux and most other modern Unices have since switched to ELF format, which is considerably more flexible and has fewer legacy issues. One of the legacy issues it specifically dropped was name mangling. It is not necessary to name-mangle a program linked from ELF object files.
Could the problem be calling an 32 bit function?? ([BITS 32])
Or must I specify a section name? Because when I specify a section name, bochs dont give an error but still stucks....
Or is my problem due to a bad linker script or bad makefile??
uff...please help me... Im stucked here and become crazy with this simple hello world problem.. Ill be glad if some one send me a working example, calling an asm function from C (compilable with nasm and asm, and linkable with ld)..This hello world problem make me sick:((
First, i would remove the section label as it isn't needed.
BTW, you won't be able to compile your code under *nix. To fix that, pass gcc the -fno_leading_underscores param. In *nix it will be ignored and in djgpp, it won't mangle the names.
After that, the kernel "worked". It hung at virtual address 0x102A (your infinite for() loop).
What a weird bug. The call to TestA20() was converted into a CALL to absolute address 0.
Advice:
1. compile with debug info (gcc -g ...)
2. link as a COFF or ELF file instead of binary
3. use "objdump --source ..." to disassemble the resulting COFF or ELF kernel, then examine the listing to make sure everything is correct
4. use "objcopy -O binary ..." to convert the kernel to binary.