LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-08-2007, 02:29 AM   #1
BiThian
Member
 
Registered: Aug 2006
Location: Romania
Distribution: NetBSD 3.1
Posts: 118

Rep: Reputation: 15
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).

Last edited by BiThian; 01-08-2007 at 02:54 AM.
 
Old 01-08-2007, 04:35 AM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
Run the program under gdb, grab the assember listing, and have a blast!
 
Old 01-08-2007, 05:36 AM   #3
BiThian
Member
 
Registered: Aug 2006
Location: Romania
Distribution: NetBSD 3.1
Posts: 118

Original Poster
Rep: Reputation: 15
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
 
Old 01-08-2007, 06:33 AM   #4
introuble
Member
 
Registered: Apr 2004
Distribution: Debian -unstable
Posts: 700

Rep: Reputation: 31
Well.. isn't THAT clear.
 
Old 01-08-2007, 07:13 AM   #5
BiThian
Member
 
Registered: Aug 2006
Location: Romania
Distribution: NetBSD 3.1
Posts: 118

Original Poster
Rep: Reputation: 15
@introuble: I don't see why did you bother to post
 
Old 01-08-2007, 11:20 AM   #6
BiThian
Member
 
Registered: Aug 2006
Location: Romania
Distribution: NetBSD 3.1
Posts: 118

Original Poster
Rep: Reputation: 15
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?
 
Old 01-10-2007, 04:50 AM   #7
BiThian
Member
 
Registered: Aug 2006
Location: Romania
Distribution: NetBSD 3.1
Posts: 118

Original Poster
Rep: Reputation: 15
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?
 
Old 01-10-2007, 11:40 AM   #8
BiThian
Member
 
Registered: Aug 2006
Location: Romania
Distribution: NetBSD 3.1
Posts: 118

Original Poster
Rep: Reputation: 15
Well, no one answered. Could someone move this thread to BSD section? Thanks!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to create an object file from an assembly program, with org 100h manas_sem Programming 9 12-18-2006 06:30 PM
hash routine into assembly program rblampain Linux - Security 3 08-06-2005 01:49 AM
Problem linking assembly program with C lib. 95se Programming 1 03-08-2005 09:44 PM
Please help me with my assembly program flamesrock Programming 2 01-30-2005 10:27 PM
puzzle about g++ compile options for inline assembly program markbeth Programming 2 09-20-2004 04:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration