Compiling a C program for my Assembly OS
Posted: Thu Oct 23, 2008 10:45 am
Hello everyone,
I'm looking for some help with properly compiling a C program for my Assembly-based OS.
Here is some background info:
My OS is written in 64-bit x86 assembly.
The C program also needs to be 64-bit.
Currently I am not interested in any library calls (like stdio, stlib, etc).
I can compile the program in Linux using GCC (Using Arch Linux in 64-bit mode).
I have had some success with this using the following:
I compile the code with these commands:
I can then run testc1.bin and upon execution it sets EAX to 0x12345678. (Not sure why I can't return with a 64-bit integer.. Any insight?)
The real issue is trying to get a C program to be able to write to the screen:
I can compile the code with the same example above but it does not include the "Hello, world" string in the binary. Is there something wrong with my arguments to "ld" or "objcopy"?
Thanks,
-Ian
I'm looking for some help with properly compiling a C program for my Assembly-based OS.
Here is some background info:
My OS is written in 64-bit x86 assembly.
The C program also needs to be 64-bit.
Currently I am not interested in any library calls (like stdio, stlib, etc).
I can compile the program in Linux using GCC (Using Arch Linux in 64-bit mode).
I have had some success with this using the following:
Code: Select all
int main()
{
return 0x12345678;
}
Code: Select all
gcc -c testc1.c
ld -r -Tdata 0x100 -e _start -s -o testc1.out testc1.o
objcopy -O binary -j .text testc1.out testc1.bin
The real issue is trying to get a C program to be able to write to the screen:
Code: Select all
int main(void)
{
char *str = "Hello, world", *ch;
unsigned short *vidmem = (unsigned short*) 0xb8000;
unsigned i;
for (ch = str, i = 0; *ch; ch++, i++)
vidmem[i] = (unsigned char) *ch | 0x0700;
return 0x12345678;
}
Thanks,
-Ian