I have made the steps in babystep 2 tutorial and it worked fine (the first code on the page, it prints a string to the screen with BIOS). Now I would like to do the same thing with the GNU Assembler, as part of GCC.
First I have built an i586-elf GCC cross compiler for my system. (Could not build libgcc too but that is not neccessary yet.)
Then I have changed the syntax to GAS syntax (not that hard).
After that I assemble it:
i586-elf-gcc -c boot.s -o boot
But this gets an elf format, so I strip it to be only the binary:
objcopy -O binary boot boot.bin
This binary does not work, when I try it, it prints 3 characters (junk) they do not change if I change the string to be printed.
Now if I compare this binary with the one got from NASM, the only difference is that two 0x66 bytes are inserted in the one assembled with GAS.
Are those some unneccesary symbols left inside? How can I fix it either with generating the binary directly with gcc, or with some extra option with objcopy? The problem is NOT with the GAS syntax assembly code, because I have tried producing elf format with NASM and stripping that too with objcopy, and it ended up with the two 0x66 bytes as well.
I have also tried
Code: Select all
as yadda.s -o yadda.o
ld yadda.o -o yadda --oformat=binary
or:
gcc yadda.s -o yadda -Xlinker --oformat=binary
Here are the two hex files:
The one assembled with NASM:
Code: Select all
00000000 b8 c0 07 8e d8 be 15 00 ac 08 c0 74 06 b4 0e cd |...........t....|
00000010 10 eb f5 eb fe 57 65 6c 63 6f 6d 65 20 74 6f 20 |.....Welcome to |
00000020 4d 61 63 69 6e 74 6f 73 68 0d 0a 00 00 00 00 00 |Macintosh.......|
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
00000200
Code: Select all
00000000 66 b8 c0 07 8e d8 66 be 17 00 ac 08 c0 74 06 b4 |f.....f......t..|
00000010 0e cd 10 eb f5 eb fe 57 65 6c 63 6f 6d 65 20 74 |.......Welcome t|
00000020 6f 20 4d 61 63 69 6e 74 6f 73 68 0d 0a 00 00 00 |o Macintosh.....|
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
00000200
Thank you for your help.