Line data Source code
1 1 : /*
2 : * Copyright (c) 2019-2020 Cobham Gaisler AB
3 : *
4 : * SPDX-License-Identifier: Apache-2.0
5 : */
6 :
7 : /**
8 : * @file
9 : * @brief SPARC specific kernel interface header
10 : *
11 : * This header contains the SPARC specific kernel interface. It is
12 : * included by the kernel interface architecture-abstraction header
13 : * (include/zephyr/arch/cpu.h).
14 : */
15 :
16 : #ifndef ZEPHYR_INCLUDE_ARCH_SPARC_ARCH_H_
17 : #define ZEPHYR_INCLUDE_ARCH_SPARC_ARCH_H_
18 :
19 : #include <zephyr/arch/exception.h>
20 : #include <zephyr/arch/sparc/thread.h>
21 : #include <zephyr/arch/sparc/sparc.h>
22 : #include <zephyr/arch/common/sys_bitops.h>
23 : #include <zephyr/arch/common/sys_io.h>
24 : #include <zephyr/arch/common/ffs.h>
25 :
26 : #include <zephyr/irq.h>
27 : #include <zephyr/sw_isr_table.h>
28 : #include <soc.h>
29 : #include <zephyr/devicetree.h>
30 :
31 : /* stacks, for SPARC architecture stack shall be 8byte-aligned */
32 0 : #define ARCH_STACK_PTR_ALIGN 8
33 :
34 : /*
35 : * Software trap numbers.
36 : * Assembly usage: "ta SPARC_SW_TRAP_<TYPE>"
37 : */
38 0 : #define SPARC_SW_TRAP_FLUSH_WINDOWS 0x03
39 0 : #define SPARC_SW_TRAP_SET_PIL 0x09
40 0 : #define SPARC_SW_TRAP_EXCEPT 0x0F
41 :
42 : #ifndef _ASMLANGUAGE
43 : #include <zephyr/sys/util.h>
44 :
45 : #ifdef __cplusplus
46 : extern "C" {
47 : #endif
48 :
49 0 : #define STACK_ROUND_UP(x) ROUND_UP(x, ARCH_STACK_PTR_ALIGN)
50 :
51 : /*
52 : * SOC specific function to translate from processor interrupt request level
53 : * (1..15) to logical interrupt source number. For example by probing the
54 : * interrupt controller.
55 : */
56 : int z_sparc_int_get_source(int irl);
57 : void z_irq_spurious(const void *unused);
58 :
59 :
60 0 : #define ARCH_IRQ_CONNECT(irq_p, priority_p, isr_p, isr_param_p, flags_p) \
61 : { \
62 : Z_ISR_DECLARE(irq_p, 0, isr_p, isr_param_p); \
63 : }
64 :
65 :
66 : static ALWAYS_INLINE unsigned int z_sparc_set_pil_inline(unsigned int newpil)
67 : {
68 : register uint32_t oldpil __asm__ ("o0") = newpil;
69 :
70 : __asm__ volatile (
71 : "ta %1\nnop\n" :
72 : "=r" (oldpil) :
73 : "i" (SPARC_SW_TRAP_SET_PIL), "r" (oldpil) :
74 : "memory"
75 : );
76 : return oldpil;
77 : }
78 :
79 0 : static ALWAYS_INLINE unsigned int arch_irq_lock(void)
80 : {
81 : return z_sparc_set_pil_inline(15);
82 : }
83 :
84 0 : static ALWAYS_INLINE void arch_irq_unlock(unsigned int key)
85 : {
86 : z_sparc_set_pil_inline(key);
87 : }
88 :
89 0 : static ALWAYS_INLINE bool arch_irq_unlocked(unsigned int key)
90 : {
91 : return key == 0;
92 : }
93 :
94 0 : static ALWAYS_INLINE void arch_nop(void)
95 : {
96 : __asm__ volatile ("nop");
97 : }
98 :
99 0 : extern uint32_t sys_clock_cycle_get_32(void);
100 :
101 0 : static inline uint32_t arch_k_cycle_get_32(void)
102 : {
103 : return sys_clock_cycle_get_32();
104 : }
105 :
106 0 : extern uint64_t sys_clock_cycle_get_64(void);
107 :
108 0 : static inline uint64_t arch_k_cycle_get_64(void)
109 : {
110 : return sys_clock_cycle_get_64();
111 : }
112 :
113 0 : #define ARCH_EXCEPT(reason_p) \
114 : do { \
115 : register uint32_t _g1 __asm__("g1") = reason_p; \
116 : \
117 : __asm__ volatile ( \
118 : "ta %[vector]\n\t" \
119 : : \
120 : : [vector] "i" (SPARC_SW_TRAP_EXCEPT), "r" (_g1) \
121 : : "memory" \
122 : ); \
123 : CODE_UNREACHABLE; \
124 : } while (false)
125 :
126 : #ifdef __cplusplus
127 : }
128 : #endif
129 :
130 : #endif /*_ASMLANGUAGE */
131 :
132 : #endif /* ZEPHYR_INCLUDE_ARCH_SPARC_ARCH_H_ */
|