This might technically be "programming", but I think it fits better here. Anyway.
I've been playing with basic assembler syscalls in FreeBSD and linux. It's relatively simple on x86:
This is GNU as syntax, x86-style. Both work. My problem is: How the fsck(8) do you do this on alpha (AXP)? Just for fun the syntax for as on alpha and x86 is utterly different. For extra joy, I can't find anything like push and pop for stack handling on the alpha, either.
From what I can find, I suspect you put the syscall-number in $0 ($v0), the arguments in $16 and onwards ($a0, $a1, etc.), and possibly do a call_pal 0x83 (or 0x80?) to do it. Perhaps. It keeps pagefaulting no matter how I write it, though. So, does anyone here know any relevant alpha assembler?
I've been playing with basic assembler syscalls in FreeBSD and linux. It's relatively simple on x86:
Code:
Linux style:
eax contains the syscall number, ebx, ecx, edx the arguments
.data ; data part starts here
hello: ; "hello" is the address here
.string "Morn\n" ; The data
length = . - hello ; Length (. means "here")
.text ; code starts here
.global _start ; _start is an ELF convention
_start:
movl $4, %eax ; syscall number 4 is write
movl $1, %ebx ; 1st arg: file descriptor (1 is stdout)
movl $hello, %ecx ; 2nd arg: address to string
movl $length, %edx ; 3rd arg: length of string
int $0x80 ; Generate an interrupt to call the kernel
movl $1, %eax ; syscall number 1 is exit
movl $0, %ebx ; 1st argument: return value
int $0x80 ; do the syscall
BSD style:
eax contains the syscall number, arguments pushed onto the stack.
The topmost item is ignored (it's usually a return address).
The first argument is pushed last, so it's on top.
.data
hello:
.string "Morn\n"
length = . - hello
.text
.global _start
_start:
movl $4, %eax ; syscall 4 is write
push $length ; 3rd arg: length
push $hello ; 2nd arg: addr to string
push $1 ; 1st arg: file desc, 1 is stdout
push $0 ; discarded
int $0x80 ; *blam*
movl $1, %eax ; syscall 1 is exit
push $0 ; return value
push $0 ; discarded
int $0x80 ; go for it
This is GNU as syntax, x86-style. Both work. My problem is: How the fsck(8) do you do this on alpha (AXP)? Just for fun the syntax for as on alpha and x86 is utterly different. For extra joy, I can't find anything like push and pop for stack handling on the alpha, either.
From what I can find, I suspect you put the syscall-number in $0 ($v0), the arguments in $16 and onwards ($a0, $a1, etc.), and possibly do a call_pal 0x83 (or 0x80?) to do it. Perhaps. It keeps pagefaulting no matter how I write it, though. So, does anyone here know any relevant alpha assembler?