Hello Frank,
at last I,ve got time now for a reply:
I'm working with NASM version 0.98.39 compiled on Sep 21 2007
Here's my assembler code. It's only a simple translation from a C-Syscall to NASM. (The using of the regs is without any context) But first of all the C routine. It's only a ececve()-function to change a few vars in the environment:
/* execve.c */
#include
#include
int main (void) {
int j;
char filename[]={"/usr/bin/printenv"};
char *args[] = {"printenv", NULL};
char *env[] = {
"SHELL=/bin/bash",
"LOGNAME=a_username",
"OSTYPE=L1NuX", NULL
};
int value;
value=execve(filename, args, env);
if(value==-1)
printf("\n\nObviously a mistake.\n\n");
printf("\n\nThis point is never reached!?\n\n");
return value;
}
Now the assembler tranlation which also works fine:
section .data
filename db '/usr/bin/printenv',0
argvek db 'printenv',0
envek db 'SHELL=/bin/bash',00Ah
db 'LOGNAME=a_Username',00Ah
db 'OSTYPE=L1N!!!???',0
msg db 00Ah,'If this is printed '
db 'call to exec failed ,',00Ah
db 'even if there is no error message!',00Ah,00Ah
len equ $-msg
msgf db 00Ah,'Obviously a mistake. Returned with -1!',00Ah,00Ah
lenf equ $-msgf
section .text
global _start
_start:
;;;;;;;;;;;;;;;;;;;;; BEGINN MAIN PROGRAMM ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; HERE IS THE TEST ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov rax,1 ; Three lines only to test the regs
mov r8,1
mov xmm0,1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
xor eax,eax
mov ebx,filename
push eax
push argvek
mov ecx,esp
push eax
push envek
mov edx,esp
mov al,11
int 0x80
mov eax,4 ; syscall write
mov ebx,1 ; 1 = stdout
mov ecx,msg ; Show no error message
mov edx,len
int 0x80
cmp al,-1
jnz jumpit
mov eax,4 ; syscall write
mov ebx,1 ; 1 = stdout
mov ecx,msgf ; show error message
mov edx,lenf
int 0x80
jumpit:
mov eax, 1 ; End of programm, call to exit
mov ebx, 0
int 0x80
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
I also think, NASM should be able to handle the three lines above
> mov rax,1
> mov r8,1
> mov xmm0,1
But perhaps I need a spezial compiler switch? Or something for the linker?
(nasm -f elf execve.asm)
michel@linux-ms64:~/sysprog/jwclinux> make PROGLIST='exec2v0 exec2v0.asm'
exec2v0.asm:43: error: symbol `rax' undefined
exec2v0.asm:44: error: symbol `r8' undefined
exec2v0.asm:45: error: invalid combination of opcode and operands
ld -s -o execve execve.o -m elf_i386
So what can I do? As I said, gas is working without any problems if I use the huge regs and my 64 Bit-system also should know them.