RTEMS 6.1-rc7
Loading...
Searching...
No Matches
asm.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
18/*
19 * COPYRIGHT:
20 *
21 * This file is based on similar code found in newlib available
22 * from ftp.cygnus.com. The file which was used had no copyright
23 * notice. This file is freely distributable as long as the source
24 * of the file is noted. This file is:
25 *
26 * COPYRIGHT (c) 2018 Amaan Cheval <amaan.cheval@gmail.com>
27 *
28 * COPYRIGHT (c) 1994-2006.
29 * On-Line Applications Research Corporation (OAR).
30 */
31
32#ifndef _RTEMS_ASM_H
33#define _RTEMS_ASM_H
34
35/*
36 * Indicate we are in an assembly file and get the basic CPU definitions.
37 */
38
39#ifndef ASM
40#define ASM
41#endif
42#include <rtems/score/cpuopts.h>
43#include <rtems/score/x86_64.h>
44#include <rtems/score/percpu.h>
45
56#ifndef __USER_LABEL_PREFIX__
65#define __USER_LABEL_PREFIX__ _
66#endif
67
68#undef __REGISTER_PREFIX__
69#define __REGISTER_PREFIX__ %
70
71#include <rtems/concat.h>
72
74#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
75
77#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x)
78
79/*
80 * define macros for all of the registers on this CPU
81 */
82#define rax REG (rax)
83#define rbx REG (rbx)
84#define rcx REG (rcx)
85#define rdx REG (rdx)
86#define rdi REG (rdi)
87#define rsi REG (rsi)
88#define rbp REG (rbp)
89#define rsp REG (rsp)
90#define r8 REG (r8)
91#define r9 REG (r9)
92#define r10 REG (r10)
93#define r11 REG (r11)
94#define r12 REG (r12)
95#define r13 REG (r13)
96#define r14 REG (r14)
97#define r15 REG (r15)
98
99/*
100 * Order of register usage for function arguments as per the calling convention
101 */
102#define REG_ARG0 rdi
103#define REG_ARG1 rsi
104#define REG_ARG2 rdx
105#define REG_ARG3 rcx
106#define REG_ARG4 r8
107#define REG_ARG5 r9
108
109// XXX: eax, ax, etc., segment registers
110
111/*
112 * Define macros to handle section beginning and ends.
113 */
114
116#define BEGIN_CODE_DCL .text
118#define END_CODE_DCL
120#define BEGIN_DATA_DCL .data
122#define END_DATA_DCL
124#define BEGIN_CODE .text
126#define END_CODE
128#define BEGIN_DATA
130#define END_DATA
134#define BEGIN_BSS
136#define END_BSS
138#define END
139
146#define PUBLIC(sym) .globl SYM (sym)
147
154#define EXTERN(sym) .globl SYM (sym)
155
156#ifdef RTEMS_SMP
157/* REG32 must be the lower 32 bits of REG */
158.macro GET_CPU_INDEX REG REG32
159 .set LAPIC_ID, 0x20
160 .set LAPIC_ID_SHIFT, 24
161 movq amd64_lapic_base, \REG
162 movl LAPIC_ID(\REG), \REG32
163 shrq $LAPIC_ID_SHIFT, \REG /* LAPIC_ID in REG */
164 movzbq amd64_lapic_to_cpu_map(\REG), \REG /* CPU ID in REG */
165.endm
166
167/* REG32 must be the lower 32 bits of REG */
168.macro GET_SELF_CPU_CONTROL REG REG32
169 GET_CPU_INDEX \REG \REG32
170 shlq $PER_CPU_CONTROL_SIZE_LOG2, \REG /* Calculate offset for CPU structure */
171 leaq _Per_CPU_Information(\REG), \REG /* Address of info for current CPU in REG */
172.endm
173#else
174.macro GET_CPU_INDEX REG REG32
175 movq $0, \REG
176.endm
177
178.macro GET_SELF_CPU_CONTROL REG REG32
180.endm
181#endif
182
183/* Couldn't find a better way to do this under the GNU as macro limitations */
184.macro GET_SELF_CPU_CONTROL_RAX
185 GET_SELF_CPU_CONTROL rax,%eax
186.endm
187.macro GET_SELF_CPU_CONTROL_RBX
188 GET_SELF_CPU_CONTROL rbx,%ebx
189.endm
190.macro GET_SELF_CPU_CONTROL_RCX
191 GET_SELF_CPU_CONTROL rcx,%ecx
192.endm
193.macro GET_SELF_CPU_CONTROL_RDX
194 GET_SELF_CPU_CONTROL rdx,%edx
195.endm
196.macro GET_SELF_CPU_CONTROL_RDI
197 GET_SELF_CPU_CONTROL rdi,%edi
198.endm
199.macro GET_SELF_CPU_CONTROL_RSI
200 GET_SELF_CPU_CONTROL rsi,%esi
201.endm
202.macro GET_SELF_CPU_CONTROL_R8
203 GET_SELF_CPU_CONTROL r8,%r8d
204.endm
205.macro GET_SELF_CPU_CONTROL_R9
206 GET_SELF_CPU_CONTROL r9,%r9d
207.endm
208.macro GET_SELF_CPU_CONTROL_R10
209 GET_SELF_CPU_CONTROL r10,%r10d
210.endm
211.macro GET_SELF_CPU_CONTROL_R11
212 GET_SELF_CPU_CONTROL r11,%r11d
213.endm
214.macro GET_SELF_CPU_CONTROL_R12
215 GET_SELF_CPU_CONTROL r12,%r12d
216.endm
217.macro GET_SELF_CPU_CONTROL_R13
218 GET_SELF_CPU_CONTROL r13,%r13d
219.endm
220.macro GET_SELF_CPU_CONTROL_R14
221 GET_SELF_CPU_CONTROL r14,%r14d
222.endm
223.macro GET_SELF_CPU_CONTROL_R15
224 GET_SELF_CPU_CONTROL r15,%r15d
225.endm
226
227#endif // _RTEMS_ASM_H
228
CPU_STRUCTURE_ALIGNMENT Per_CPU_Control_envelope _Per_CPU_Information[]
Set of Per CPU Core Information.
Definition: asm.h:171
This header file provides the interfaces of the Per-CPU Information.