From owner-freebsd-hackers Mon Jun 29 13:57:53 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id NAA07959 for freebsd-hackers-outgoing; Mon, 29 Jun 1998 13:57:53 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from mail.camalott.com (root@[208.203.140.2]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id NAA07931 for ; Mon, 29 Jun 1998 13:57:31 -0700 (PDT) (envelope-from joelh@gnu.org) Received: from detlev.UUCP (tex-152.camalott.com [208.229.74.152]) by mail.camalott.com (8.8.7/8.8.5) with ESMTP id PAA04096; Mon, 29 Jun 1998 15:57:10 -0500 Received: (from joelh@localhost) by detlev.UUCP (8.8.8/8.8.8) id PAA28923; Mon, 29 Jun 1998 15:57:02 -0500 (CDT) (envelope-from joelh) Date: Mon, 29 Jun 1998 15:57:02 -0500 (CDT) Message-Id: <199806292057.PAA28923@detlev.UUCP> To: smoergrd@oslo.geco-prakla.slb.com CC: belkovic@albert.osu.cz, smoergrd@oslo.geco-prakla.slb.com, freebsd-hackers@FreeBSD.ORG In-reply-to: (smoergrd@oslo.geco-prakla.slb.com) Subject: Re: BROKEN_KEYBOARD_RESET From: Joel Ray Holveck Reply-to: joelh@gnu.org References: Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG >> I wrote mail, because i don't know FreeBSD-asembler syntax > It's not 'FreeBSD-assembler syntax", but AT&T assembler syntax, upon > which gas (the GNU assembler), which FreeBSD uses, is based. So, here's a real quick bit on the differences between what you know and what you need to. Most of it was taken from the 'as' info pages (which you should read). I am giving you information here which mostly pertains to a.out without debugging information. I'll probably be putting this online soon, so anybody's suggestions are welcome. * Name your source file with a .S if it needs to be preprocessed with cpp, or .s if it doesn't. Invoke gcc to assemble, as if it were a C file. * Registers are prefixed by '%'. Immediate operands (including labels) are prefixed by '$'. Absolute jump/call operands are prefixed by '*'. (Relative jump/call operands have no prefix.) EXAMPLE: INTEL / MASM AT&T / GAS push 4 pushl $4 push eax pushl %eax jmp A200 jmp *A200 * Intel and MASM use 'opcode dest, source' (eg 'add eax, 4'). AT&T Unix uses 'opcode source, dest'. (eg 'addl $4, %eax'). * Opcodes need to have their operand sizes specified with suffixes of 'b', 'w', and 'l' for 8, 16, and 32 bits. This replaces Intel/MASM's 'byte ptr', 'word ptr', and 'dword ptr', respectively. For example, 'mov eax, dword ptr IDENT' becomes 'movl IDENT, %eax'. (Note that some other Unix assemblers assume an 'l' suffix.) * The sign extend and zero extend opcodes (which are changed from 'movsx' and 'movzx' to 'movs' and 'movz') take two operand size suffixes, first from source, second for destination. (eg: 'movsbl %al, %edx') * Some sign-extend mnemonics have aliases. (The Intel forms are also accepted, but the AT&T forms are preferred.) INTEL / MASM AT&T / GAS cbw cbtw cwde cwtl cwd cwtd cdq cltd * Long jumps and calls are 'ljmp $SEGMENT,$OFFSET' instead of 'jmp far SEGMENT:OFFSET'. Also, far return is 'lret' instead of 'ret far'. * The segment prefixes 'cs:', 'ds:' still work fine (don't forget the %). If they are given on the line before the instruction (like debug's `u' command shows, as opposed to as part of the memory operand, as is traditionally written), the colon is omitted. If a segment prefix specifies the default segment, then it is omitted from the emitted code. * Indirection is written differently. Intel writes [BASE + INDEX*SCALE + DISP] (where BASE and INDEX are the base and index registers, DISP is the optional diplacement, and SCALE is a data width for INDEX). AT&T writes DISP(BASE, INDEX, SCALE) instead. * I don't believe that the 'repz' aliases for the 'repe' opcodes are supported. * Packed BCD is not supported. (If you're doing kernel work, then floating-point operations are a no-no anyway, IIRC.) * The 16-, 32-, and 64-bit expanding multiplies can be output only in the one operand form. Thus, `imul %ebx, %eax' does *not* select the expanding multiply; the expanding multiply would clobber the `%edx' register, and this would confuse `gcc' output. Use `imul %ebx' to get the 64-bit product in `%edx:%eax'. A two operand form of `imul' has been added, where the first operand is an immediate mode expression and the second operand is a register. This is just a shorthand, so that, multiplying `%eax' by 69, for example, can be done with `imul $69, %eax' rather than `imul $69, %eax, %eax'. * The following section pseudo-ops are used. They affect the code up to the next section pseudo-op. .data For read-write memory (global variables, etc) .text For program code or other read-only memory * Symbols are created in the following ways: SYMBOL: What you're used to. SYM = EXPR Used as SYMBOL EQU nn. (May be used as .set SYM, EXPR or .equ SYM, EXPR) . Refers to the current address, as with MASM. .comm SYM, LEN Declares an exported zero-initialized symbol LEN bytes long that is allocated at load-time. This may be in several source files and will result in only one symbol. (These are placed in the 'bss' section.) .lcomm SYM, LEN Same as .comm, but is not exported. * The following pseudo-ops insert literals. Except fill and space, each can have several listed. .ascii, .asciz (adds a \0), .byte (8-bit), .hword (16-bit), .int (32-bit) (aliases: .int, .short, .long), .octa (16-byte bignums), .quad (8-byte bignums), .single (alias: .float), .double, .fill (see below), .space (see see below) * The following various pseudo-ops are availible: .abort Stops assembly. .if / .else / .endif Figure it out. .ifdef SYM / .ifndef SYM Assembles if SYM is defined. .include "FILE" Figure it out. .global SYM Exports a symbol. (Alias: .globl) .extern Clue to a human that a symbol is external. (This is assumed if a symbol is not found in the source.) .lsym SYM, EXP Creates a local symbol that cannot be referenced by the assembler. .align EXP, PAD Pads with PAD (default 0) to a location divisable by 2^EXP. .fill CNT,LEN,VAL Inserts a repeated expression LEN bytes long. .space CNT,VAL Same as .fill CNT,1,VAL .org LC, FILL Fills with FILL until the location LC. * The following pseudo-ops control assembly listings: .list Turn on listings. .nolist Turn off listings. .eject Emit a page break. .psize LINES, COLS Declare a page size. .title "TEXT" Declare a title. .sbttl "TEXT" Declare a subtitle. * When calling C functions, push the first arguments last, the last arguments first. Don't forget the leading _. Return values are in %eax. If your function takes arguments, remember that the return address is 4 bytes at %esp when you start. This means that your int arguments start at 8(%esp) then 12(%esp) then 16(%esp) and so on. (Normally, you will be using %ebp instead, of course.) When you return, have the stack pointer where you found it when you started. * You can see how gcc will generate the assembly code for your C sources by running gcc -S, eg 'gcc -S hello.c' will create hello.s as an assembly code file. Recommended reading includes: "Using as: The GNU Assembler" (the as texinfo page), ld(1), a.out(5), Intel Architecture Software Developer's Manual, Happy hacking, joelh -- Joel Ray Holveck - joelh@gnu.org - http://www.wp.com/piquan Fourth law of programming: Anything that can go wrong wi sendmail: segmentation violation - core dumped To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message