asm.h revision 50477
123571Sbde/*- 223571Sbde * Copyright (c) 1990 The Regents of the University of California. 323571Sbde * All rights reserved. 423571Sbde * 523571Sbde * This code is derived from software contributed to Berkeley by 623571Sbde * William Jolitz. 723571Sbde * 823571Sbde * Redistribution and use in source and binary forms, with or without 923571Sbde * modification, are permitted provided that the following conditions 1023571Sbde * are met: 1123571Sbde * 1. Redistributions of source code must retain the above copyright 1223571Sbde * notice, this list of conditions and the following disclaimer. 1323571Sbde * 2. Redistributions in binary form must reproduce the above copyright 1423571Sbde * notice, this list of conditions and the following disclaimer in the 1523571Sbde * documentation and/or other materials provided with the distribution. 1623571Sbde * 3. All advertising materials mentioning features or use of this software 1723571Sbde * must display the following acknowledgement: 1823571Sbde * This product includes software developed by the University of 1923571Sbde * California, Berkeley and its contributors. 2023571Sbde * 4. Neither the name of the University nor the names of its contributors 2123571Sbde * may be used to endorse or promote products derived from this software 2223571Sbde * without specific prior written permission. 2323571Sbde * 2423571Sbde * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2523571Sbde * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2623571Sbde * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2723571Sbde * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2823571Sbde * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2923571Sbde * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3023571Sbde * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3123571Sbde * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3223571Sbde * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3323571Sbde * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3423571Sbde * SUCH DAMAGE. 3523571Sbde * 3623571Sbde * from: @(#)DEFS.h 5.1 (Berkeley) 4/23/90 3750477Speter * $FreeBSD: head/sys/i386/include/asm.h 50477 1999-08-28 01:08:13Z peter $ 3823571Sbde */ 3923571Sbde 4025111Sbde#ifndef _MACHINE_ASM_H_ 4125111Sbde#define _MACHINE_ASM_H_ 4225111Sbde 4323571Sbde#include <sys/cdefs.h> 4423571Sbde 4523571Sbde#ifdef PIC 4623571Sbde#define PIC_PROLOGUE \ 4723571Sbde pushl %ebx; \ 4823571Sbde call 1f; \ 4923571Sbde1: \ 5023571Sbde popl %ebx; \ 5123571Sbde addl $_GLOBAL_OFFSET_TABLE_+[.-1b],%ebx 5223571Sbde#define PIC_EPILOGUE \ 5323571Sbde popl %ebx 5423571Sbde#define PIC_PLT(x) x@PLT 5523571Sbde#define PIC_GOT(x) x@GOT(%ebx) 5623571Sbde#define PIC_GOTOFF(x) x@GOTOFF(%ebx) 5723571Sbde#else 5823571Sbde#define PIC_PROLOGUE 5923571Sbde#define PIC_EPILOGUE 6023571Sbde#define PIC_PLT(x) x 6123571Sbde#define PIC_GOT(x) x 6223571Sbde#define PIC_GOTOFF(x) x 6323571Sbde#endif 6423571Sbde 6523571Sbde/* 6623571Sbde * CNAME and HIDENAME manage the relationship between symbol names in C 6723571Sbde * and the equivalent assembly language names. CNAME is given a name as 6823571Sbde * it would be used in a C program. It expands to the equivalent assembly 6923571Sbde * language name. HIDENAME is given an assembly-language name, and expands 7023571Sbde * to a possibly-modified form that will be invisible to C programs. 7123571Sbde */ 7225111Sbde#ifdef __ELF__ 7323571Sbde#define CNAME(csym) csym 7423571Sbde#define HIDENAME(asmsym) __CONCAT(.,asmsym) 7525111Sbde#else 7623571Sbde#define CNAME(csym) __CONCAT(_,csym) 7723571Sbde#define HIDENAME(asmsym) asmsym 7825111Sbde#endif 7923571Sbde 8025111Sbde/* XXX should use .p2align 4,0x90 for -m486. */ 8125111Sbde#define _START_ENTRY .text; .p2align 2,0x90 8223571Sbde 8325111Sbde#define _ENTRY(x) _START_ENTRY; \ 8425111Sbde .globl CNAME(x); .type CNAME(x),@function; CNAME(x): 8525111Sbde 8625111Sbde#ifdef PROF 8725111Sbde#define ENTRY(x) _ENTRY(x); \ 8825111Sbde pushl %ebp; movl %esp,%ebp; \ 8925111Sbde call PIC_PLT(HIDENAME(mcount)); \ 9025111Sbde popl %ebp 9123571Sbde#else 9225111Sbde#define ENTRY(x) _ENTRY(x) 9323571Sbde#endif 9423571Sbde 9525111Sbde#define RCSID(x) .text; .asciz x 9623571Sbde 9724965Sbde#ifdef _ARCH_INDIRECT 9823576Sbde/* 9924965Sbde * Generate code to select between the generic functions and _ARCH_INDIRECT 10024965Sbde * specific ones. 10124965Sbde * XXX nested __CONCATs don't work with non-ANSI cpp's. 10223576Sbde */ 10324965Sbde#define ANAME(x) CNAME(__CONCAT(__CONCAT(__,_ARCH_INDIRECT),x)) 10423576Sbde#define ASELNAME(x) CNAME(__CONCAT(__arch_select_,x)) 10523576Sbde#define AVECNAME(x) CNAME(__CONCAT(__arch_,x)) 10623576Sbde#define GNAME(x) CNAME(__CONCAT(__generic_,x)) 10723576Sbde 10823576Sbde/* Don't bother profiling this. */ 10923576Sbde#ifdef PIC 11023576Sbde#define ARCH_DISPATCH(x) \ 11123576Sbde _START_ENTRY; \ 11223576Sbde .globl CNAME(x); .type CNAME(x),@function; CNAME(x): ; \ 11323576Sbde PIC_PROLOGUE; \ 11423576Sbde movl PIC_GOT(AVECNAME(x)),%eax; \ 11523576Sbde PIC_EPILOGUE; \ 11623576Sbde jmpl *(%eax) 11723576Sbde 11823576Sbde#define ARCH_SELECT(x) _START_ENTRY; \ 11923576Sbde .type ASELNAME(x),@function; \ 12023576Sbde ASELNAME(x): \ 12123576Sbde PIC_PROLOGUE; \ 12223576Sbde call PIC_PLT(CNAME(__get_hw_float)); \ 12323576Sbde testl %eax,%eax; \ 12423576Sbde movl PIC_GOT(ANAME(x)),%eax; \ 12523576Sbde jne 8f; \ 12623576Sbde movl PIC_GOT(GNAME(x)),%eax; \ 12723576Sbde 8: \ 12823576Sbde movl PIC_GOT(AVECNAME(x)),%edx; \ 12923576Sbde movl %eax,(%edx); \ 13023576Sbde PIC_EPILOGUE; \ 13123576Sbde jmpl *%eax 13223576Sbde#else /* !PIC */ 13323576Sbde#define ARCH_DISPATCH(x) \ 13423576Sbde _START_ENTRY; \ 13523576Sbde .globl CNAME(x); .type CNAME(x),@function; CNAME(x): ; \ 13623576Sbde jmpl *AVECNAME(x) 13723576Sbde 13823576Sbde#define ARCH_SELECT(x) _START_ENTRY; \ 13923576Sbde .type ASELNAME(x),@function; \ 14023576Sbde ASELNAME(x): \ 14123576Sbde call CNAME(__get_hw_float); \ 14223576Sbde testl %eax,%eax; \ 14323576Sbde movl $ANAME(x),%eax; \ 14423576Sbde jne 8f; \ 14523576Sbde movl $GNAME(x),%eax; \ 14623576Sbde 8: \ 14723576Sbde movl %eax,AVECNAME(x); \ 14823576Sbde jmpl *%eax 14923576Sbde#endif /* PIC */ 15023576Sbde 15125111Sbde#define ARCH_VECTOR(x) .data; .p2align 2; \ 15223576Sbde .globl AVECNAME(x); \ 15323576Sbde .type AVECNAME(x),@object; \ 15423576Sbde .size AVECNAME(x),4; \ 15523576Sbde AVECNAME(x): .long ASELNAME(x) 15623576Sbde 15725111Sbde#undef _ENTRY 15825111Sbde#define _ENTRY(x) ARCH_VECTOR(x); ARCH_SELECT(x); ARCH_DISPATCH(x); \ 15923576Sbde _START_ENTRY; \ 16023576Sbde .globl ANAME(x); .type ANAME(x),@function; ANAME(x): 16123576Sbde 16224965Sbde#endif /* _ARCH_INDIRECT */ 16324965Sbde 16425111Sbde#endif /* !_MACHINE_ASM_H_ */ 165