Mesaje recente

Members
Stats
  • Total Posts: 17,786
  • Total Topics: 1,234
  • Online today: 234
  • Online ever: 340
  • (22 November 2024, 00:10)
Users Online
Users: 0
Guests: 195
Total: 195

Probleme cu programele scrise in assembler (gas)

Started by BiThian, 11 January 2007, 21:18

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

BiThian

Lucrez pe NetBSD(i386) cu kernelul GENERIC.MPACPI. De fiecare data cand execut o aplicatie, primesc urmatoarea eroare:
Quote
Segmentation fault (core dumped)

Utilizand ktrace si kdump pentru a vedea ce se intampla, aflu ca:
Quote
289 ktrace EMUL "netbsd"
289 ktrace CALL execve(0xbfbfee53,0xbfbfed98,0xbfbfeda0)
289 ktrace NAMI "./nume_program"
289 nume_program EMUL "svr4"
289 nume_program RET execve JUSTRETURN
289 nume_program PSIG SIGSEGV SIG_DFL

Din output-ul lui gdb,se pare ca prima intructiune (oricare ar fi ea: nop, movl, pushl etc.) de dupa label-ul _start, provoaca intreruperea programului.
Stiti care ar putea fi cauza?

PS: Aceeasi chestie mi se intampla si cand rulez kernelul GENERIC.

Posted on: 08 January 2007, 22:50
Am revenit...:D

Am dezactivat emularea SVR4, inserand inainte de codul propriu-zis secventa urmatoare:

.section ".note.netbsd.ident", "a"
        .long   2f-1f
        .long   4f-3f
        .long   1
1:      .asciz "NetBSD"
2:      .p2align 2
3:      .long   199905
4:      .p2align 2
(http://www.netbsd.org/Documentation/kernel/elf-notes.html#note-creation)

Buuuuun... Acum, am scapat de segmentation fault, dar programul continua sa "crape"  ( de data asta, numai dupa ce executa comanda: int $0x80).
Astept nerabdator solutii. :D

Posted on: 09 January 2007, 18:31
Quote from: http://mail-index.netbsd.org/port-i386/2001/08/21/0018.htmlI'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.

Un alt link foarte interesant:  http://mail-index.netbsd.org/port-i386/2001/09/03/0004.html
Posted on: 10 January 2007, 11:19
Ce pot face ca un program banal creat in assembler sa se comporte pe NetBSD ca si cum ar fi rulat in Linux?
De exemplu:

.section .data
.section .text
.globl _start
_start:
movl $1, %eax
movl $0, %ebx
int $0x80

sa returneze 0, nu alte dracii.

Multumesc anticipat pentru eventualele raspunsuri.
"A man who would not die for something is not fit to live." - Martin Luther King

BiThian

In mod normal, byte-ul ABI (din headerul ELF) are valoarea 00H. Pentru ca programele sa ruleze normal, acesta trebuie sa fie 03H (Linux ABI).

ktrace ./lolo
kdump
 
1004 ktrace   EMUL  "netbsd"
1004 ktrace   CALL  execve(0xbfbfedbf,0xbfbfecec,0xbfbfecf4)
1004 ktrace   NAMI  "./lolo"
1004 lolo     EMUL  "linux"
...
"A man who would not die for something is not fit to live." - Martin Luther King