Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:26

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @brief Addresses Incompatible Flavors Problems
0007  *
0008  *  This include file attempts to address the problems
0009  *  caused by incompatible flavors of assemblers and
0010  *  toolsets.  It primarily addresses variations in the
0011  *  use of leading underscores on symbols and the requirement
0012  *  that register names be preceded by a %.
0013  *
0014  *  NOTE: The spacing in the use of these macros
0015  *        is critical to them working as advertised.
0016  */
0017 
0018 /*
0019  *  COPYRIGHT:
0020  *
0021  *  This file is based on similar code found in newlib available
0022  *  from ftp.cygnus.com.  The file which was used had no copyright
0023  *  notice.  This file is freely distributable as long as the source
0024  *  of the file is noted.  This file is:
0025  *
0026  *  COPYRIGHT (c) 2018 Amaan Cheval <amaan.cheval@gmail.com>
0027  *
0028  *  COPYRIGHT (c) 1994-2006.
0029  *  On-Line Applications Research Corporation (OAR).
0030  */
0031 
0032 #ifndef _RTEMS_ASM_H
0033 #define _RTEMS_ASM_H
0034 
0035 /*
0036  *  Indicate we are in an assembly file and get the basic CPU definitions.
0037  */
0038 
0039 #ifndef ASM
0040 #define ASM
0041 #endif
0042 #include <rtems/score/cpuopts.h>
0043 #include <rtems/score/x86_64.h>
0044 #include <rtems/score/percpu.h>
0045 
0046 /**
0047  * @defgroup RTEMSScoreCPUx86-64ASM x86-64 Assembler Support
0048  *
0049  * @ingroup RTEMSScoreCPUx86-64
0050  *
0051  * @brief x86-64 Assembler Support
0052  *
0053  * @{
0054  */
0055 
0056 #ifndef __USER_LABEL_PREFIX__
0057 /**
0058  *  Recent versions of GNU cpp define variables which indicate the
0059  *  need for underscores and percents.  If not using GNU cpp or
0060  *  the version does not support this, then you will obviously
0061  *  have to define these as appropriate.
0062  *
0063  *  This symbol is prefixed to all C program symbols.
0064  */
0065 #define __USER_LABEL_PREFIX__ _
0066 #endif
0067 
0068 #undef __REGISTER_PREFIX__
0069 #define __REGISTER_PREFIX__ %
0070 
0071 #include <rtems/concat.h>
0072 
0073 /** Use the right prefix for global labels.  */
0074 #define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
0075 
0076 /** Use the right prefix for registers.  */
0077 #define REG(x) CONCAT1 (__REGISTER_PREFIX__, x)
0078 
0079 /*
0080  *  define macros for all of the registers on this CPU
0081  */
0082 #define rax REG (rax)
0083 #define rbx REG (rbx)
0084 #define rcx REG (rcx)
0085 #define rdx REG (rdx)
0086 #define rdi REG (rdi)
0087 #define rsi REG (rsi)
0088 #define rbp REG (rbp)
0089 #define rsp REG (rsp)
0090 #define r8  REG (r8)
0091 #define r9  REG (r9)
0092 #define r10 REG (r10)
0093 #define r11 REG (r11)
0094 #define r12 REG (r12)
0095 #define r13 REG (r13)
0096 #define r14 REG (r14)
0097 #define r15 REG (r15)
0098 
0099 /*
0100  * Order of register usage for function arguments as per the calling convention
0101  */
0102 #define REG_ARG0 rdi
0103 #define REG_ARG1 rsi
0104 #define REG_ARG2 rdx
0105 #define REG_ARG3 rcx
0106 #define REG_ARG4 r8
0107 #define REG_ARG5 r9
0108 
0109 // XXX: eax, ax, etc., segment registers
0110 
0111 /*
0112  *  Define macros to handle section beginning and ends.
0113  */
0114 
0115 /** This macro is used to denote the beginning of a code declaration. */
0116 #define BEGIN_CODE_DCL .text
0117 /** This macro is used to denote the end of a code declaration. */
0118 #define END_CODE_DCL
0119 /** This macro is used to denote the beginning of a data declaration section. */
0120 #define BEGIN_DATA_DCL .data
0121 /** This macro is used to denote the end of a data declaration section. */
0122 #define END_DATA_DCL
0123 /** This macro is used to denote the beginning of a code section. */
0124 #define BEGIN_CODE .text
0125 /** This macro is used to denote the end of a code section. */
0126 #define END_CODE
0127 /** This macro is used to denote the beginning of a data section. */
0128 #define BEGIN_DATA
0129 /** This macro is used to denote the end of a data section. */
0130 #define END_DATA
0131 /** This macro is used to denote the beginning of the
0132  *  unitialized data section.
0133  */
0134 #define BEGIN_BSS
0135 /** This macro is used to denote the end of the unitialized data section.  */
0136 #define END_BSS
0137 /** This macro is used to denote the end of the assembly file.  */
0138 #define END
0139 
0140 /**
0141  *  This macro is used to declare a public global symbol.
0142  *
0143  *  @note This must be tailored for a particular flavor of the C compiler.
0144  *  They may need to put underscores in front of the symbols.
0145  */
0146 #define PUBLIC(sym) .globl SYM (sym)
0147 
0148 /**
0149  *  This macro is used to prototype a public global symbol.
0150  *
0151  *  @note This must be tailored for a particular flavor of the C compiler.
0152  *  They may need to put underscores in front of the symbols.
0153  */
0154 #define EXTERN(sym) .globl SYM (sym)
0155 
0156 #ifdef RTEMS_SMP
0157 /* REG32 must be the lower 32 bits of REG */
0158 .macro GET_CPU_INDEX REG REG32
0159     .set LAPIC_ID,       0x20
0160     .set LAPIC_ID_SHIFT, 24
0161     movq amd64_lapic_base, \REG
0162     movl LAPIC_ID(\REG), \REG32
0163     shrq $LAPIC_ID_SHIFT, \REG                /* LAPIC_ID in REG */
0164     movzbq amd64_lapic_to_cpu_map(\REG), \REG /* CPU ID in REG */
0165 .endm
0166 
0167 /* REG32 must be the lower 32 bits of REG */
0168 .macro GET_SELF_CPU_CONTROL REG REG32
0169     GET_CPU_INDEX \REG \REG32
0170     shlq $PER_CPU_CONTROL_SIZE_LOG2, \REG /* Calculate offset for CPU structure */
0171     leaq _Per_CPU_Information(\REG), \REG /* Address of info for current CPU in REG */
0172 .endm
0173 #else
0174 .macro GET_CPU_INDEX REG REG32
0175     movq $0, \REG
0176 .endm
0177 
0178 .macro GET_SELF_CPU_CONTROL REG REG32
0179     leaq _Per_CPU_Information, \REG
0180 .endm
0181 #endif
0182 
0183 /* Couldn't find a better way to do this under the GNU as macro limitations */
0184 .macro GET_SELF_CPU_CONTROL_RAX
0185     GET_SELF_CPU_CONTROL rax,%eax
0186 .endm
0187 .macro GET_SELF_CPU_CONTROL_RBX
0188     GET_SELF_CPU_CONTROL rbx,%ebx
0189 .endm
0190 .macro GET_SELF_CPU_CONTROL_RCX
0191     GET_SELF_CPU_CONTROL rcx,%ecx
0192 .endm
0193 .macro GET_SELF_CPU_CONTROL_RDX
0194     GET_SELF_CPU_CONTROL rdx,%edx
0195 .endm
0196 .macro GET_SELF_CPU_CONTROL_RDI
0197     GET_SELF_CPU_CONTROL rdi,%edi
0198 .endm
0199 .macro GET_SELF_CPU_CONTROL_RSI
0200     GET_SELF_CPU_CONTROL rsi,%esi
0201 .endm
0202 .macro GET_SELF_CPU_CONTROL_R8
0203     GET_SELF_CPU_CONTROL r8,%r8d
0204 .endm
0205 .macro GET_SELF_CPU_CONTROL_R9
0206     GET_SELF_CPU_CONTROL r9,%r9d
0207 .endm
0208 .macro GET_SELF_CPU_CONTROL_R10
0209     GET_SELF_CPU_CONTROL r10,%r10d
0210 .endm
0211 .macro GET_SELF_CPU_CONTROL_R11
0212     GET_SELF_CPU_CONTROL r11,%r11d
0213 .endm
0214 .macro GET_SELF_CPU_CONTROL_R12
0215     GET_SELF_CPU_CONTROL r12,%r12d
0216 .endm
0217 .macro GET_SELF_CPU_CONTROL_R13
0218     GET_SELF_CPU_CONTROL r13,%r13d
0219 .endm
0220 .macro GET_SELF_CPU_CONTROL_R14
0221     GET_SELF_CPU_CONTROL r14,%r14d
0222 .endm
0223 .macro GET_SELF_CPU_CONTROL_R15
0224     GET_SELF_CPU_CONTROL r15,%r15d
0225 .endm
0226 
0227 #endif // _RTEMS_ASM_H
0228 
0229 /** @} */