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