LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   BSD: Problems executing an assembly program (https://www.linuxquestions.org/questions/programming-9/bsd-problems-executing-an-assembly-program-517356/)

BiThian 01-08-2007 02:29 AM

BSD: Problems executing an assembly program
 
OK, what I'm gonna write here is not very much programming related, but I hope some of you may know where is the problem.

I run NetBSD(i386) with kernel GENERIC.MPACPI. Every time, I run an assembly program, I get:
Quote:

Segmentation fault (core dumped)
I tried to find out what's really happening using ktrace & kdump. Here's the output:
Quote:

289 ktrace EMUL "netbsd"
289 ktrace CALL execve(0xbfbfee53,0xbfbfed98,0xbfbfeda0)
289 ktrace NAMI "./cpuid"
289 cpuid EMUL "svr4"
289 cpuid RET execve JUSTRETURN
289 cpuid PSIG SIGSEGV SIG_DFL
The tools I use are Gnu Assembler & ld.

PS: I get the same error when I use the GENERIC kernel (the kernel that comes with NetBSD).

wjevans_7d1@yahoo.co 01-08-2007 04:35 AM

Run the program under gdb, grab the assember listing, and have a blast!

BiThian 01-08-2007 05:36 AM

I runned it under gdb too, but program receives signal SIGEGV (Segmentation fault), as soon as the first item after _start label gets to be executed.
Example:
Code:

...
_start:
      operation1
      operation2
      ...

After running into operation1, it crashes.
Output I receive in GDB:
Quote:

Program received signal SIGSEGV, Segmentation fault.
_start () at cpuid.s:line_number
line_number operation1

introuble 01-08-2007 06:33 AM

Well.. isn't THAT clear.

BiThian 01-08-2007 07:13 AM

@introuble: I don't see why did you bother to post

BiThian 01-08-2007 11:20 AM

I want to add something in case I was misunderstood: whatever assembly code I use, the binary crashes.

Don't you have at least an idea what could cause this problem?

BiThian 01-10-2007 04:50 AM

After googling pretty much, I found out I should disable SVR4 emulation. source

Then, I expected like my programs to run normally, but, unfortunately, it didn't happen. For example, the program below should return 0, but it returns 20 in sh and 16 in bash.
Code:

header to force netbsd to recognise program as a netbsd binary
.section .data
.section .text
.globl _start
_start:
movl $1, %eax
movl $0, %ebx
int $0x80

Why it didn't work as it supposed to? source
Quote:

I'm forwarding this little "journal" to the mailing list in case others want to adapt the "Hello World" that's all over the place in the NASM/Linux/FreeBSD assembly howtos and tutorials to NetBSD. Currently their instructions are incorrect, as are all the other tutorials that lump NetBSD in with the rest of the rabble with their sample hello world routines.
Looks like there was a change recently in the "way" to use syscalls in NetBSD, because on the older kernels (around 1.5) the routine works fine without pushing a return address onto the stack.
OK, now if you could help me it would be just great! How can I make the program generated by the code above to act in NetBSD as if it's runned on Linux? One of my ideas is to "convince" NetBSD to run it in emulation mode, but how do I accomplish that?

BiThian 01-10-2007 11:40 AM

Well, no one answered. Could someone move this thread to BSD section? Thanks!


All times are GMT -5. The time now is 01:12 AM.