Re: Still stuck with this assembly stuff (amd64)

2005-07-21 Thread Artur Grabowski
Brian [EMAIL PROTECTED] writes:

 I spent the last three days reading through all the archives.
 And I have no clue what I am doing wrong.  I only started down
 this road because of some of the other posters.  I figured I
 would give assembly a shot.

Why? Do you like pain?

 I read Assembly Step by Step, which is really geared toward
 DOS and linux, but it's a pretty good overview.  

Right. And i386 too I suspect, which is a different architecture than
amd64, but that just sounds like such a minor problem. There are
probably some alpha and sparc examples out there too, try them, they
might work.

Never mind that the way that code does syscalls is unsupported even on
i386. Never mind that the calling conventions on amd64 are different.
Never mind that you're using 32-bit pointers on a 64-bit architecture.
Never mind that the syscall entry point you're using shouldn't even be
there.

 From what I have read of the history, openBSD went from aout
 to ELF around 3.0 with the addition of some extra information.

Ah, yes. The painful switch from a.out to elf on amd64. Two years
before the first processors were released we had a flag day to deal
with all the legacy binaries out there.

You will find that the tolerance for people who like pain is slightly
low on these mailing lists. Find your pain somewhere else, please.

//art



Re: Still stuck with this assembly stuff (amd64)

2005-07-21 Thread Brett Lymn
On Thu, Jul 21, 2005 at 11:17:31AM +0200, Artur Grabowski wrote:
 
 Never mind that the way that code does syscalls is unsupported even on
 i386. Never mind that the calling conventions on amd64 are different.
 Never mind that you're using 32-bit pointers on a 64-bit architecture.
 Never mind that the syscall entry point you're using shouldn't even be
 there.
 

Of course Art is right here... what you should be doing is trawling
the web with Google looking for the amd64 ABI specification so you can
understand how embarressing that code really is.  One also wonders
why, if you are determined to do this, you don't just compile a
hello_world.c and disassemble the output (or just make the compiler
output the .s file for you...)

-- 
Brett Lymn



Re: Still stuck with this assembly stuff (amd64)

2005-07-21 Thread Brian
Thanks.  I just wasn't sure if my problem was an openBSD problem or an assembly
problem.  It's definitely the later.  And I just found the amd64 ABI, which is
making the problems clear for me.  Pushing those args on the stack is
definitely wrong.

Anyway, I appreciate the feedback.  And thanks Art for pointing out that the
assembly was wrong.  That put me on the right track to finding a solution.  The
recent threads about the notes section just confused me and put me down the
wrong track.

Thanks,

Brian

--- STeve Andre' [EMAIL PROTECTED] wrote:

 
 Brian, its always good idea to learn stuff, but this isn't the right
 place to talk about assembly problems.  One of the newsgroups
 devoted to programming would be a far better source, or one of
 the many web forums out there.
 
 As someone said, compiling programs and looking at the code 
 is a great way of seeing how things are done.  Thats one of the
 ways I learned, quite some time ago with Digital Research C, an
 awful compiler that gave me lots of pain...
 
 The other thing you might want to think about is getting experience
 on a simpler cpu, perhaps the z80.  There are tons and tons of 
 documents on it, and I'm pretty sure that you could write stuff and
 then run it on an emulator, faster than the hardware I had, back
 when I used them.
 
 At any rate, misc@ isn't the best place for your questions.  I'm sure
 there are some assembler freaks out there who would just love to
 talk with you and help out.
 
 --STeve Andre'
 
 





Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 



Still stuck with this assembly stuff (amd64)

2005-07-20 Thread Brian
I spent the last three days reading through all the archives.
And I have no clue what I am doing wrong.  I only started down
this road because of some of the other posters.  I figured I
would give assembly a shot.

I read Assembly Step by Step, which is really geared toward
DOS and linux, but it's a pretty good overview.  

From what I have read of the history, openBSD went from aout
to ELF around 3.0 with the addition of some extra information.

I am guessing that my problem is related to doing something
wrong with the amd64.  But I'm not sure what to read next.
I did go through the first hundred pages of the amd programmers
guide on the amd website.

I am assembling and linking:

as -o test1.o test1.s
ld -o test1 test1.o

file type reads as:

test1: ELF 64-bit LSB executable, AMD64, version 1, for OpenBSD, statically
linked, not stripped

so it's set as OpenBSD.

And readelf gives me:

ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
  Class: ELF64
  Data:  2's complement, little endian
  Version:   1 (current)
  OS/ABI:UNIX - System V
  ABI Version:   0
  Type:  EXEC (Executable file)
  Machine:   Advanced Micro Devices X86-64
  Version:   0x1
  Entry point address:   0x400218
  Start of program headers:  64 (bytes into file)
  Start of section headers:  664 (bytes into file)
  Flags: 0x0
  Size of this header:   64 (bytes)
  Size of program headers:   56 (bytes)
  Number of program headers: 4
  Size of section headers:   64 (bytes)
  Number of section headers: 10
  Section header string table index: 7

Section Headers:
  [Nr] Name  Type Address   Offset
   Size  EntSize  Flags  Link  Info  Align
  [ 0]   NULL   
        0 0 0
  [ 1] .text PROGBITS 00400218  0218
   0015    AX   0 0 4
  [ 2] .data PROGBITS 00600230  0230
   000d    WA   0 0 4
  [ 3] .gotpad0  PROGBITS 0070023d  0240
        W   0 0 1
  [ 4] .gotpad1  PROGBITS 0070023d  0240
        W   0 0 1
  [ 5] .bss  NOBITS   00800240  0240
       WA   0 0 4
  [ 6] .note.openbsd.ide NOTE 00400200  0200
   0018     A   0 0 4
  [ 7] .shstrtab STRTAB     0240
   0052     0 0 1
  [ 8] .symtab   SYMTAB     0518
   01b0  0018   9 c 8
  [ 9] .strtab   STRTAB     06c8
   003e     0 0 1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)

Program Headers:
  Type   Offset VirtAddr   PhysAddr
 FileSizMemSiz  Flags  Align
  LOAD   0x 0x0040 0x0040
 0x022d 0x022d  R E10
  LOAD   0x0230 0x00600230 0x00600230
 0x000d 0x000d  RW 10
  LOAD   0x0240 0x00800240 0x00800240
 0x 0x  RW 10
  NOTE   0x0200 0x00400200 0x00400200
 0x0018 0x0018  R  4

 Section to Segment mapping:
  Segment Sections...
   00 .text .note.openbsd.ident
   01 .data
   02
   03 .note.openbsd.ident

There is no dynamic segment in this file.

There are no relocations in this file.

Here is my current code:

.section .note.openbsd.ident, a
.p2align 2
.long   8
.long   4
.long   1
.ascii OpenBSD\0
.long   0
.p2align 2


.section .data

msg: .asciz hello world\n
len = . - msg - 1

.section .text   

.global _start  

_start:
push $len
push $msg
push $1
movb $4, %al
push %rax
int  $0x80

push $0
movb $1, %al
push %rax
int  $0x80

Any