Re: Assembly in DragonFly

2006-03-14 Thread Emiel Kollof
Op dinsdag 14 maart 2006 08:17, schreef Karthik Subramanian:
 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:

Maybe you should check out nasm, unless when you actually like the ATT asm 
syntax.

Cheers,
Emiel
-- 
This night methinks is but the daylight sick.
-- William Shakespeare, The Merchant of Venice


Re: Assembly in DragonFly

2006-03-14 Thread joerg
On Tue, Mar 14, 2006 at 12:47:56PM +0530, Karthik Subramanian wrote:
 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

Sure. DragonFly uses the ELF ABI note as you found out later to decide
which kernel ABI to use. Using ld directly and not linking crt1.o
doesn't create the section. It would also be possible to use brandelf,
but that is a nasty hack which should die.

Joerg


Assembly in DragonFly

2006-03-13 Thread Karthik Subramanian
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\nlen  : .long . - helloworld
.section .text
.globl _start
syscall:int $0x80ret
_start:pushl $lenpushl $helloworldpushl $1movl  $4, %eax
call  syscalladd   $12, %esp # clean up stack
pushl $0movl  $1, %eaxcall 
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 smallHello, 
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 0a00 0400 0100 44726167  
Drag 8048120 6f6e466c 7900 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