Zephyr API Documentation  3.6.99
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
11#if defined(CONFIG_PCIE) && !defined(_ASMLANGUAGE)
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
26{
27 __asm__ volatile("movq %0, %1"
28 :
29 : "r"(data), "m" (*(volatile uint64_t *)
30 (uintptr_t) addr)
31 : "memory");
32}
33
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
46static 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
59struct 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 */
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
95typedef struct x86_esf z_arch_esf_t;
96
97struct 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;
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_ */
#define X86_FXSAVE_SIZE
Definition: thread.h:37
#define ALWAYS_INLINE
Definition: common.h:129
static ALWAYS_INLINE unsigned int arch_irq_lock(void)
Definition: arch.h:63
__UINT64_TYPE__ uint64_t
Definition: stdint.h:91
__UINTPTR_TYPE__ uintptr_t
Definition: stdint.h:105
Definition: arch.h:59
unsigned long rsp
Definition: arch.h:91
unsigned long r11
Definition: arch.h:83
unsigned long vector
Definition: arch.h:86
unsigned long cs
Definition: arch.h:89
unsigned long rip
Definition: arch.h:88
unsigned long ss
Definition: arch.h:92
unsigned long r8
Definition: arch.h:76
unsigned long rbp
Definition: arch.h:68
unsigned long r10
Definition: arch.h:78
unsigned long rcx
Definition: arch.h:72
unsigned long code
Definition: arch.h:87
unsigned long r9
Definition: arch.h:77
unsigned long rdx
Definition: arch.h:73
unsigned long rsi
Definition: arch.h:74
unsigned long rdi
Definition: arch.h:75
unsigned long rax
Definition: arch.h:71
char fxsave[X86_FXSAVE_SIZE]
Definition: arch.h:82
unsigned long rflags
Definition: arch.h:90
Definition: arch.h:97
unsigned long rsp
Definition: arch.h:107
unsigned long r8
Definition: arch.h:102
unsigned long r9
Definition: arch.h:101
unsigned long r10
Definition: arch.h:100
unsigned long rdx
Definition: arch.h:103
unsigned long rflags
Definition: arch.h:99
char fxsave[X86_FXSAVE_SIZE]
Definition: arch.h:105
unsigned long rdi
Definition: arch.h:106
unsigned long rip
Definition: arch.h:98
unsigned long rsi
Definition: arch.h:104
uintptr_t mm_reg_t
Definition: sys_io.h:20
static ALWAYS_INLINE uint64_t sys_read64(mm_reg_t addr)
Definition: arch.h:34
static ALWAYS_INLINE void sys_write64(uint64_t data, mm_reg_t addr)
Definition: arch.h:25