Problems with creating a flat binary for x64 using mingw-w64
Posted: Wed Jan 30, 2013 5:21 am
Hi,
Every time I want to start my OS development, I start using some assembler and I create great boot-code. But then, when I see how much work it will be to continue in assembler, I want to get started in C and get very very VERY frustrated that I can't get to an x64-flat-binary, and I give up. Sad, because I think I have great ideas for my OS.
So, can someone please help me get started. I really want to do this in Windows.
I installed MinGW-w64 on my system.
I created a test.c file which will just print out a text to 0xb8000.
The code compiles correctly and links to some kind of binary file which at first glance looks ok, but... ever since I added the function to write text to the 0xb8000 address, it seems that the binary file does not contain the text I am trying to output. The text is of course a constant and I think it is in another segment or something, but I don't know enough about that and I just want everything to be in one continuous block of binary.
This is the C-code:
And this is how I change it to a flat binary:
The .exe file contains the "This is a text", but the flat binary doesn't anymore. I would like the text to be there right after the code. How can I do this?
I'm an experienced programmer, but I don't have any experience with other compilers than Borland/Visual, so I'm quite sure I need to add some parameters to gcc or something.
Any help?
Every time I want to start my OS development, I start using some assembler and I create great boot-code. But then, when I see how much work it will be to continue in assembler, I want to get started in C and get very very VERY frustrated that I can't get to an x64-flat-binary, and I give up. Sad, because I think I have great ideas for my OS.
So, can someone please help me get started. I really want to do this in Windows.
I installed MinGW-w64 on my system.
I created a test.c file which will just print out a text to 0xb8000.
The code compiles correctly and links to some kind of binary file which at first glance looks ok, but... ever since I added the function to write text to the 0xb8000 address, it seems that the binary file does not contain the text I am trying to output. The text is of course a constant and I think it is in another segment or something, but I don't know enough about that and I just want everything to be in one continuous block of binary.
This is the C-code:
Code: Select all
void write_string(int colour, const char *string)
{
volatile char *video = (volatile char*)0xB8000;
while (*string != 0)
{
*video++ = *string++;
*video++ = colour;
}
}
int start(void)
{
write_string(0xF0, "This is a text");
mylabel:
goto mylabel;
}
Code: Select all
C:\MinGW-w64\bin\x86_64-w64-mingw32-gcc.exe -Wall -pedantic-errors test.c -o test.exe -nostdlib -ffreestanding -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow -Wl,-Ttext=0x20000
C:\MinGW-w64\x86_64-w64-mingw32\bin\objcopy -O binary -j .text test.exe test.bin
I'm an experienced programmer, but I don't have any experience with other compilers than Borland/Visual, so I'm quite sure I need to add some parameters to gcc or something.
Any help?