Re: Freebsd Asm
I already visited int80h.org and linuxassembly.org and others, And did not find any resources or include files.. If anyone can share his own files, or give any tips, would be nice. It is straightforward: The assembly syntax is whatever is supported by gas(1) for your architecture. 'info gas' should be of help. The BSD make(1) infrastructure supports creating objects from assembler sources; just name your assembler files with a .S or .s suffix and include these names in your 'SRCS' make variable. Files with a .S suffix are preprocessed by cpp(1) before being fed into the assembler. Files with a .s suffix are fed into the assembler without preprocessing. See src/share/mk/sys.mk. There are some convenient CPP macros for assembly language programmers in machine/asm.h and machine/asmacros.h. You can also study the assembly sources under src/lib/libc/*. -- FreeBSD Volunteer, http://people.freebsd.org/~jkoshy ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Freebsd Asm
klowd9 - wrote: If anyone can share his own files, or give any tips, would be nice. You aren't going to find many, if any, userland include files for assembly. The system is designed to be very portable and assembly is not. My first response, and likely that of anyone else, would be what are you doing that it needs to be done in assembly? If all you are looking for is some experience working with assembly then that's fine; there are a lot of good guides out there that teach the basics. Otherwise though if you're looking to get into developing on FreeBSD I'd recommend sticking with a higher level language. I think I remember a few guides out there on doing assembly on FreeBSD, can't remember them off the top of my head though. Honestly, coming from someone that went through that learning curve, a good ol copy of MSDOS can be a better teaching aid than doing assembly on a modern OS. I imagine almost every modern OS running on x86 will run in protected mode and therefore somewhat shield you from getting down and dirty with the processor. Using DOS will let you mess around with entering protected mode and other things. Another note, careful about using Linux guides on FreeBSD. Specifically be careful when it comes to system calls. Linux, like Windows, uses registers for passing arguments to syscalls, extras spill onto the stack, FreeBSD however passes all parameters on the stack. -- Ryan Sommers [EMAIL PROTECTED] ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: freebsd asm
On Monday 14 June 2004 07:04, Peter Pentchev wrote: On Mon, Jun 14, 2004 at 01:59:11PM +0200, Jos? Nicol?s Castellano wrote: Hello to all, I'm proud to join this mailing, having posibilities to learn some new features of freebsd system. I have to mention i did some tests in asm from freebsd-devel and i get surprised, look at this: [demon]~$ uname -a FreeBSD demon.noconname.org 5.2.1-RELEASE-p4 FreeBSD 5.2.1-RELEASE-p4 #0: Tue Apr 6 19:35:49 CEST 2004 [EMAIL PROTECTED]:/usr/obj/usr/src/sys/NocONName i386 [demon]~$ cat hello.asm %include 'system.inc' section .data holadb 'Hola', 0Ah hbytes equ $-hola section .text global _start _start: pushdword hbytes pushdword hola pushdword stdout sys.write pushdword 0 sys.exit [demon]~$ nasm -f elf hello.asm hello.asm:1: fatal: unable to open include file `system.inc' ?Where is that file?... the -current port of nasm is incomplete ? I assume you are referring to the system.inc file mentioned in http://www.freebsd.org/doc/en_US.ISO8859-1/books/developers-handbook/x86- portable-code.html If so, note that this page says that you need to create this file yourself, it is neither part of nasm nor part of the standard FreeBSD distribution :) See the last paragraph on the page - Go ahead, enter it into your editor and save it as system.inc. :) Gee, maybe somebody should do that and submit the file to krion@ for inclusion in the port patches. ;^) -- Where am I, and what am I doing in this handbasket? Wes Peters [EMAIL PROTECTED] ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: freebsd asm
On Wed, Jun 16, 2004 at 09:01:02AM -0700, Wes Peters wrote: On Monday 14 June 2004 07:04, Peter Pentchev wrote: On Mon, Jun 14, 2004 at 01:59:11PM +0200, Jos? Nicol?s Castellano wrote: Hello to all, I'm proud to join this mailing, having posibilities to learn some new features of freebsd system. I have to mention i did some tests in asm from freebsd-devel and i get surprised, look at this: [demon]~$ uname -a FreeBSD demon.noconname.org 5.2.1-RELEASE-p4 FreeBSD 5.2.1-RELEASE-p4 #0: Tue Apr 6 19:35:49 CEST 2004 [EMAIL PROTECTED]:/usr/obj/usr/src/sys/NocONName i386 [demon]~$ cat hello.asm %include 'system.inc' section .data holadb 'Hola', 0Ah hbytes equ $-hola section .text global _start _start: pushdword hbytes pushdword hola pushdword stdout sys.write pushdword 0 sys.exit [demon]~$ nasm -f elf hello.asm hello.asm:1: fatal: unable to open include file `system.inc' ?Where is that file?... the -current port of nasm is incomplete ? I assume you are referring to the system.inc file mentioned in http://www.freebsd.org/doc/en_US.ISO8859-1/books/developers-handbook/x86- portable-code.html If so, note that this page says that you need to create this file yourself, it is neither part of nasm nor part of the standard FreeBSD distribution :) See the last paragraph on the page - Go ahead, enter it into your editor and save it as system.inc. :) Gee, maybe somebody should do that and submit the file to krion@ for inclusion in the port patches. ;^) Well, there would have to be several versions, or it would have to be automatically generated from syscalls.master... though that would require parsing C syntax. Nah, several versions should be fine, updated each time a syscall is added/removed/changed - that should not be too often, would it now? :) I'll see if I can whip up something like that. G'luck, Peter -- Peter Pentchev [EMAIL PROTECTED][EMAIL PROTECTED][EMAIL PROTECTED] PGP key:http://people.FreeBSD.org/~roam/roam.key.asc Key fingerprint FDBA FD79 C26F 3C51 C95E DF9E ED18 B68D 1619 4553 I am the thought you are now thinking. pgp0rHL3G5VQJ.pgp Description: PGP signature
Re: freebsd asm
On Mon, Jun 14, 2004 at 01:59:11PM +0200, Jos? Nicol?s Castellano wrote: Hello to all, I'm proud to join this mailing, having posibilities to learn some new features of freebsd system. I have to mention i did some tests in asm from freebsd-devel and i get surprised, look at this: [demon]~$ uname -a FreeBSD demon.noconname.org 5.2.1-RELEASE-p4 FreeBSD 5.2.1-RELEASE-p4 #0: Tue Apr 6 19:35:49 CEST 2004 [EMAIL PROTECTED]:/usr/obj/usr/src/sys/NocONName i386 [demon]~$ cat hello.asm %include 'system.inc' section .data holadb 'Hola', 0Ah hbytes equ $-hola section .text global _start _start: pushdword hbytes pushdword hola pushdword stdout sys.write pushdword 0 sys.exit [demon]~$ nasm -f elf hello.asm hello.asm:1: fatal: unable to open include file `system.inc' ?Where is that file?... the -current port of nasm is incomplete ? I assume you are referring to the system.inc file mentioned in http://www.freebsd.org/doc/en_US.ISO8859-1/books/developers-handbook/x86-portable-code.html If so, note that this page says that you need to create this file yourself, it is neither part of nasm nor part of the standard FreeBSD distribution :) See the last paragraph on the page - Go ahead, enter it into your editor and save it as system.inc. :) G'luck, Peter -- Peter Pentchev [EMAIL PROTECTED][EMAIL PROTECTED][EMAIL PROTECTED] PGP key:http://people.FreeBSD.org/~roam/roam.key.asc Key fingerprint FDBA FD79 C26F 3C51 C95E DF9E ED18 B68D 1619 4553 yields falsehood, when appended to its quotation. yields falsehood, when appended to its quotation. pgpCPU36CpqdH.pgp Description: PGP signature
Re: freebsd asm
[EMAIL PROTECTED] said this stuff: [...] [demon]~$ cat hello.asm %include 'system.inc' section .data holadb 'Hola', 0Ah hbytes equ $-hola section .text global _start _start: pushdword hbytes pushdword hola pushdword stdout sys.write pushdword 0 sys.exit [demon]~$ nasm -f elf hello.asm hello.asm:1: fatal: unable to open include file `system.inc' ?Where is that file?... the -current port of nasm is incomplete ? system.inc is not a part of nasm. Ok... we take some modifications... %include 'system.inc' pushdword stdout , and we replace it with pushdword 1 nasm also has no knowledge of sys.func style directives, so they are ignored. The directives in question would be located in the system.inc file that you don't have, and your program may as well be: holadb 'Hola', 0Ah hbytes equ $-hola section .text global _start _start: pushdword hbytes pushdword hola pushdword 1 pushdword 0 ... which doesn't exit, therefore your program accesses memory addresses that aren't meant to supply program code, and it crashes. Freebsd system calls are generally accessed using interrupt vector 0x80. The function that deals with this interrupt in the kernel expects the number of the system call in eax, and it expects the program to have called a function along the way. Thus, it's looking for the following stack structure: [][][][] : return address, inserted by 'call' instruction : descriptor vector : string address : number of bytes to write. To get this, you can try something like the following: holadb 'Hola', 0Ah hbytes equ $-hola section .text global _start _start: pushdword hbytes pushdword hola pushdword 1 mov eax,4 ; SYS_write calldoint pushdword 0 mov eax,1 ; SYS_exit calldoint doint: int 0x80 ret You can find the necessary system call numbers in /usr/include/sys/syscall.h . ari ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: freebsd asm
- Original Message - ... which doesn't exit, therefore your program accesses memory addresses that aren't meant to supply program code, and it crashes. Freebsd system calls are generally accessed using interrupt vector 0x80. The function that deals with this interrupt in the kernel expects the number of the system call in eax, and it expects the program to have called a function along the way. Thus, it's looking for the following stack structure: [][][][] : return address, inserted by 'call' instruction : descriptor vector : string address : number of bytes to write. ... You can find the necessary system call numbers in /usr/include/sys/syscall.h . Tnaks a lot! i understand all perfectly ;-) ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: FreeBSD asm problem
Thanks a lot for your help! Now i see that i have read int80h.org's manual not enough well :( (i'm so stupid!) RTFM and again RTFM! NKritsky - SysAdmin InternetHelp.Ru http://www.internethelp.ru e-mail: [EMAIL PROTECTED] To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: FreeBSD asm problem
-BEGIN PGP SIGNED MESSAGE- On Tue, 13 Mar 2001, Nickolay A. Kritsky wrote: Hi all! It seems to me that you guys are my last hope, but if i am asking in the wrong place - sorry. I wrote my first asm program for FreeBSD: section.code global _start _start: push dword envp push dword argvp push dword fname mov eax,59 ; execve Here you must push long (dword) because int 0x80 expects EIP main : pushl 3rd pushl 2nd pushl 1st call execve --- call will push EIP on stack execve : leal $0x3b,%eax int $0x80 Stack should be - [EIP][1st][2nd][3rd] but instead EIP you can just push anything you want. Vojislav Milunovic [EMAIL PROTECTED] -BEGIN PGP SIGNATURE- Version: PGPfreeware 5.0i for non-commercial use Charset: noconv iQEVAwUBOq486y3gPLld8IkLAQEy2gf9HLvwmii7QTyNuHBt6qQqf5jBqMPFPw8j kcW/5Oss05kfayh6tmrLVRCzP3MYNYXXKSgxjAKzH+OmN/FHlaTsZIIfQFnU561z a1Qau+CWjJ5hUuIfE1xGPPVDaWC8e3MF83ZwH9CN3pnIZVUh/3OectyiTGwgwyEV iGo65HAlgW9GBZznmzYK7PXOkWrRV3olcflIverL1dKMZbow0MCOQ57LMLnNY4ck Kl6dt8lVLd+K1sHnXdO09eqogiyXPmJEmIJJGRiR2iKMo3Zl5ptGfN/pb00NnNiT 5eNeOQbVEmDJg0swig6VrY2kSqUsMjCpWFW2TDItvtUp8nW9uJ1mtA== =6Qs3 -END PGP SIGNATURE- To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: FreeBSD asm problem
ex.S #include sys/syscall.h .globl main main: popl%eax/* cick ret */ popl%eax/* cick argc */ movl(%esp),%eax /* eax=av */ movl$fname, %ebx/* ebx=fname */ movl%ebx,(%eax) /* av[0]=fname */ pushl %ebx/* needs to be on the stack too */ movl$SYS_execve,%eax/* execve */ callsyscall movl$SYS_exit,%eax /* exit */ callsyscall syscall: int $0x80 ret fname: .asciz "/bin/sh" On Tue, 13 Mar 2001, Nickolay A. Kritsky wrote: Hi all! It seems to me that you guys are my last hope, but if i am asking in the wrong place - sorry. I wrote my first asm program for FreeBSD: section.code global _start _start: push dword envp push dword argvp push dword fname mov eax,59 ; execve int 80h hlt ; i should never get here section .data fname db '/bin/sh',0 envp dd 0 argvp dd 0 ;End of program after compiling and linking i run it and got SIGBUS error when run under gdb i can see that int 80h returns with eax=2 (ENOENT? does it mean file not found?) I have a feeling that i have missed something very important. Thank you. NKritsky - SysAdmin InternetHelp.Ru http://www.internethelp.ru e-mail: [EMAIL PROTECTED] To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message