Zephyr Project API
3.5.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
arch.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2019 Intel Corp.
3
* SPDX-License-Identifier: Apache-2.0
4
*/
5
6
#ifndef ZEPHYR_INCLUDE_ARCH_X86_INTEL64_ARCH_H_
7
#define ZEPHYR_INCLUDE_ARCH_X86_INTEL64_ARCH_H_
8
9
#include <
zephyr/arch/x86/intel64/thread.h
>
10
#include <
zephyr/arch/x86/thread_stack.h
>
11
#if defined(CONFIG_PCIE) && !defined(_ASMLANGUAGE)
12
#include <
zephyr/sys/iterable_sections.h
>
13
#endif
14
15
#if CONFIG_ISR_STACK_SIZE != (CONFIG_ISR_SUBSTACK_SIZE * CONFIG_ISR_DEPTH)
16
#error "Check ISR stack configuration (CONFIG_ISR_*)"
17
#endif
18
19
#if CONFIG_ISR_SUBSTACK_SIZE % ARCH_STACK_PTR_ALIGN
20
#error "CONFIG_ISR_SUBSTACK_SIZE must be a multiple of 16"
21
#endif
22
23
#ifndef _ASMLANGUAGE
24
25
static
ALWAYS_INLINE
void
sys_write64
(
uint64_t
data
,
mm_reg_t
addr)
26
{
27
__asm__
volatile
(
"movq %0, %1"
28
:
29
:
"r"
(
data
),
"m"
(*(
volatile
uint64_t
*)
30
(
uintptr_t
) addr)
31
:
"memory"
);
32
}
33
34
static
ALWAYS_INLINE
uint64_t
sys_read64
(
mm_reg_t
addr)
35
{
36
uint64_t
ret
;
37
38
__asm__
volatile
(
"movq %1, %0"
39
:
"=r"
(
ret
)
40
:
"m"
(*(
volatile
uint64_t
*)(
uintptr_t
) addr)
41
:
"memory"
);
42
43
return
ret
;
44
}
45
46
static
ALWAYS_INLINE
unsigned
int
arch_irq_lock
(
void
)
47
{
48
unsigned
long
key
;
49
50
__asm__
volatile
(
"pushfq; cli; popq %0"
:
"=g"
(
key
) : :
"memory"
);
51
52
return
(
unsigned
int
)
key
;
53
}
54
55
/*
56
* the exception stack frame
57
*/
58
59
struct
x86_esf
{
60
#ifdef CONFIG_EXCEPTION_DEBUG
61
/* callee-saved */
62
unsigned
long
rbx;
63
unsigned
long
r12;
64
unsigned
long
r13;
65
unsigned
long
r14;
66
unsigned
long
r15;
67
#endif
/* CONFIG_EXCEPTION_DEBUG */
68
unsigned
long
rbp
;
69
70
/* Caller-saved regs */
71
unsigned
long
rax
;
72
unsigned
long
rcx
;
73
unsigned
long
rdx
;
74
unsigned
long
rsi
;
75
unsigned
long
rdi
;
76
unsigned
long
r8
;
77
unsigned
long
r9
;
78
unsigned
long
r10
;
79
/* Must be aligned 16 bytes from the end of this struct due to
80
* requirements of 'fxsave (%rsp)'
81
*/
82
char
fxsave
[
X86_FXSAVE_SIZE
];
83
unsigned
long
r11
;
84
85
/* Pushed by CPU or assembly stub */
86
unsigned
long
vector
;
87
unsigned
long
code
;
88
unsigned
long
rip
;
89
unsigned
long
cs
;
90
unsigned
long
rflags
;
91
unsigned
long
rsp
;
92
unsigned
long
ss
;
93
};
94
95
typedef
struct
x86_esf
z_arch_esf_t;
96
97
struct
x86_ssf
{
98
unsigned
long
rip
;
99
unsigned
long
rflags
;
100
unsigned
long
r10
;
101
unsigned
long
r9
;
102
unsigned
long
r8
;
103
unsigned
long
rdx
;
104
unsigned
long
rsi
;
105
char
fxsave
[
X86_FXSAVE_SIZE
];
106
unsigned
long
rdi
;
107
unsigned
long
rsp
;
108
};
109
110
#define ARCH_EXCEPT(reason_p) do { \
111
__asm__ volatile( \
112
"movq %[reason], %%rax\n\t" \
113
"int $32\n\t" \
114
: \
115
: [reason] "i" (reason_p)); \
116
CODE_UNREACHABLE;
/* LCOV_EXCL_LINE */
\
117
} while (false)
118
119
#ifdef CONFIG_PCIE
120
#define X86_RESERVE_IRQ(irq_p, name) \
121
static TYPE_SECTION_ITERABLE(uint8_t, name, irq_alloc, name) = irq_p
122
#else
123
#define X86_RESERVE_IRQ(irq_p, name)
124
#endif
125
126
#endif
/* _ASMLANGUAGE */
127
128
/*
129
* All Intel64 interrupts are dynamically connected.
130
*/
131
132
#define ARCH_IRQ_CONNECT(irq_p, priority_p, isr_p, isr_param_p, flags_p) \
133
X86_RESERVE_IRQ(irq_p, _CONCAT(_irq_alloc_fixed, __COUNTER__)); \
134
arch_irq_connect_dynamic(irq_p, priority_p, \
135
(void (*)(const void *))isr_p, \
136
isr_param_p, flags_p)
137
138
#ifdef CONFIG_PCIE
139
140
#define ARCH_PCIE_IRQ_CONNECT(bdf_p, irq_p, priority_p, \
141
isr_p, isr_param_p, flags_p) \
142
X86_RESERVE_IRQ(irq_p, _CONCAT(_irq_alloc_fixed, __COUNTER__)); \
143
pcie_connect_dynamic_irq(bdf_p, irq_p, priority_p, \
144
(void (*)(const void *))isr_p, \
145
isr_param_p, flags_p)
146
147
#endif
/* CONFIG_PCIE */
148
149
/*
150
* Thread object needs to be 16-byte aligned.
151
*/
152
#define ARCH_DYNAMIC_OBJ_K_THREAD_ALIGNMENT 16
153
154
#endif
/* ZEPHYR_INCLUDE_ARCH_X86_INTEL64_ARCH_H_ */
thread.h
X86_FXSAVE_SIZE
#define X86_FXSAVE_SIZE
Definition
thread.h:37
thread_stack.h
ALWAYS_INLINE
#define ALWAYS_INLINE
Definition
common.h:129
ret
static ZTEST_BMEM int ret
Definition
main.c:16
arch_irq_lock
static ALWAYS_INLINE unsigned int arch_irq_lock(void)
Definition
arch.h:63
key
static k_spinlock_key_t key
Definition
spinlock_error_case.c:15
uint64_t
__UINT64_TYPE__ uint64_t
Definition
stdint.h:91
uintptr_t
__UINTPTR_TYPE__ uintptr_t
Definition
stdint.h:105
x86_esf
Definition
arch.h:59
x86_esf::rsp
unsigned long rsp
Definition
arch.h:91
x86_esf::r11
unsigned long r11
Definition
arch.h:83
x86_esf::vector
unsigned long vector
Definition
arch.h:86
x86_esf::cs
unsigned long cs
Definition
arch.h:89
x86_esf::rip
unsigned long rip
Definition
arch.h:88
x86_esf::ss
unsigned long ss
Definition
arch.h:92
x86_esf::r8
unsigned long r8
Definition
arch.h:76
x86_esf::rbp
unsigned long rbp
Definition
arch.h:68
x86_esf::r10
unsigned long r10
Definition
arch.h:78
x86_esf::rcx
unsigned long rcx
Definition
arch.h:72
x86_esf::code
unsigned long code
Definition
arch.h:87
x86_esf::r9
unsigned long r9
Definition
arch.h:77
x86_esf::rdx
unsigned long rdx
Definition
arch.h:73
x86_esf::rsi
unsigned long rsi
Definition
arch.h:74
x86_esf::rdi
unsigned long rdi
Definition
arch.h:75
x86_esf::rax
unsigned long rax
Definition
arch.h:71
x86_esf::fxsave
char fxsave[X86_FXSAVE_SIZE]
Definition
arch.h:82
x86_esf::rflags
unsigned long rflags
Definition
arch.h:90
x86_ssf
Definition
arch.h:97
x86_ssf::rsp
unsigned long rsp
Definition
arch.h:107
x86_ssf::r8
unsigned long r8
Definition
arch.h:102
x86_ssf::r9
unsigned long r9
Definition
arch.h:101
x86_ssf::r10
unsigned long r10
Definition
arch.h:100
x86_ssf::rdx
unsigned long rdx
Definition
arch.h:103
x86_ssf::rflags
unsigned long rflags
Definition
arch.h:99
x86_ssf::fxsave
char fxsave[X86_FXSAVE_SIZE]
Definition
arch.h:105
x86_ssf::rdi
unsigned long rdi
Definition
arch.h:106
x86_ssf::rip
unsigned long rip
Definition
arch.h:98
x86_ssf::rsi
unsigned long rsi
Definition
arch.h:104
iterable_sections.h
mm_reg_t
uintptr_t mm_reg_t
Definition
sys_io.h:20
data
static fdata_t data[2]
Definition
test_fifo_contexts.c:15
sys_read64
static ALWAYS_INLINE uint64_t sys_read64(mm_reg_t addr)
Definition
arch.h:34
sys_write64
static ALWAYS_INLINE void sys_write64(uint64_t data, mm_reg_t addr)
Definition
arch.h:25
include
zephyr
arch
x86
intel64
arch.h
Generated on Tue Mar 5 2024 08:42:06 for Zephyr Project API by
1.9.8