Hi Folks,
After installing DragonFly on a spare box at work, I was trying out asimple
"Hello World" in assembly, and found that one needed to do alittle more than
"as -o hello.o hello.s; ld -o hello hello.o" to getit to work; here's what I
did:
1. Wrote a "Hello World" in assembly:
============ hello.s =====================================.section .data
helloworld: .ascii "Hello, World\n"len : .long . - helloworld
.section .text
.globl _start
syscall: int $0x80 ret
_start: pushl $len pushl $helloworld pushl $1 movl $4, %eax
call syscall add $12, %esp # clean up stack
pushl $0 movl $1, %eax call
syscall==========================================================
2. Ran "as -o hello.o hello.s; ld -o hello hello.o; ./hello", and sawthis on
the console:
ELF binary type "0" not known.Abort trap
3. Running "file hello" produced this output:
hello: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),statically
linked,not stripped
4. Scratched head a little. Inspired by the lead of [1], wrote a small"Hello,
World" in C, ran objdump on the executable. Et Voila, it lookedlike I had found
what was required:
Contents of section .note.ABI-tag: 8048110 0a000000 04000000 01000000 44726167
............Drag 8048120 6f6e466c 79000000 d6fb0100
onFly.......
5. I then added the following to the original hello.s:
=============================================================.section
.note.ABI-tag, "a" .long 0xA .long 0x4 .long 0x1 .string
"DragonFly" .long
0x1fbd6==============================================================
And it works!
This probably isn't of much use to anybody except for crazy guys likeme who
like to code in assembly once in a while - but I thought I'dpost it here anyway.
Cheers,Karthik.
--References:
1. http://mail-index.netbsd.org/port-i386/2001/08/21/0018.html, and
http://mail-index.netbsd.org/port-i386/2001/09/03/0004.html
2. http://www.netbsd.org/Documentation/kernel/elf-notes.html#note-creation