Garbage inline assembly?
Posted: Sun Nov 22, 2009 6:57 pm
There is a reason why I use VC++ over GCC. Because AT&T took a perfectly good language, assembly, and destroyed the syntax. And then GCC decided to take the butchered syntax of AT&T's assembly and make it even worse.
I seriously need some help cause this code works in VC++ but not in GCC:
Firstly, I'm calling a system from a program in kernel space, so here's what I did in GCC:
main.c:
Running the code the switchboard (API) reports that EAX is a garbage value, ESI being the same garbage value.
I'm honestly stumped because it destroys all the volatile registers.
It may possibly be my linker.ld:
or my entry.s:
I honestly don't see the problem here.
Note: I tested the assembly code in my kernel, compiled in VC++ and it works perfectly, just to rule out any external variables.
Full source: http://firefly-os.com/downloads/tmp/programs.zip
ld-elf: http://firefly-os.com/downloads/tmp/ld-elf.exe
EDIT: Updated the code and now it halts, no idea why it was ignoring me previously.
Any help as to what's going wrong would be greatly appreciated.
Thanks. ^-^
I seriously need some help cause this code works in VC++ but not in GCC:
Firstly, I'm calling a system from a program in kernel space, so here's what I did in GCC:
main.c:
Code: Select all
int main(){
static char* str = "Hello World!";
__asm__("mov $1, %eax");
__asm__("mov %0, %%esi \n\t int $0x30" :: "r" (str) );
__asm__("cli");
__asm__("hlt");
return 0;
}
I'm honestly stumped because it destroys all the volatile registers.
It may possibly be my linker.ld:
Code: Select all
ENTRY(entrypoint)
SECTIONS{
. = 0x00100000;
.text :{
*(.text)
}
.rodata ALIGN (0x1000) : {
*(.rodata)
}
.data ALIGN (0x1000) : {
*(.data)
}
.bss : {
sbss = .;
*(COMMON)
*(.bss)
ebss = .;
}
}
Code: Select all
global entrypoint
extern main
section .text
align 4
entrypoint:
call main
ret
Note: I tested the assembly code in my kernel, compiled in VC++ and it works perfectly, just to rule out any external variables.
Full source: http://firefly-os.com/downloads/tmp/programs.zip
ld-elf: http://firefly-os.com/downloads/tmp/ld-elf.exe
EDIT: Updated the code and now it halts, no idea why it was ignoring me previously.
Any help as to what's going wrong would be greatly appreciated.
Thanks. ^-^