1 /*
2  * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef _PICO_PLATFORM_H
8 #define _PICO_PLATFORM_H
9 
10 #include "hardware/platform_defs.h"
11 #include <stdint.h>
12 #include <stddef.h>
13 
14 #ifdef __unix__
15 
16 #include <sys/cdefs.h>
17 
18 #endif
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 #define __not_in_flash(group)
25 #define __not_in_flash_func(func) func
26 #define __no_inline_not_in_flash_func(func) func
27 #define __in_flash(group)
28 #define __scratch_x(group)
29 #define __scratch_y(group)
30 
31 #ifndef _MSC_VER
32 #define __packed __attribute__((packed))
33 #define __packed_aligned __packed __attribute((aligned))
34 #else
35 // MSVC requires #pragma pack which isn't compatible with a single attribute style define
36 #define __packed
37 #define __packed_aligned
38 #endif
39 
40 #define __time_critical_func(x) x
41 #define __after_data(group)
42 
43 //int running_on_fpga() { return false; }
44 extern void tight_loop_contents();
45 
46 #ifndef __STRING
47 #define __STRING(x) #x
48 #endif
49 
50 #ifndef _MSC_VER
51 #ifndef __noreturn
52 #define __noreturn __attribute((noreturn))
53 #endif
54 
55 #ifndef __unused
56 #define __unused __attribute__((unused))
57 #endif
58 
59 #ifndef __noinline
60 #define __noinline __attribute__((noinline))
61 #endif
62 
63 #ifndef __aligned
64 #define __aligned(x) __attribute__((aligned(x)))
65 #endif
66 
67 #define PICO_WEAK_FUNCTION_DEF(x) _Pragma(__STRING(weak x))
68 #define PICO_WEAK_FUNCTION_IMPL_NAME(x) x
69 
70 #else
71 #ifndef __noreturn
72 #define __noreturn __declspec(noreturn)
73 #endif
74 
75 #ifndef __unused
76 #define __unused
77 #endif
78 
79 #ifndef __noinline
80 #define __noinline __declspec(noinline)
81 #endif
82 
83 #ifndef __aligned
84 #define __aligned(x) __declspec(align(x))
85 #endif
86 
87 #ifndef __CONCAT
88 #define __CONCAT(x,y) x ## y
89 #endif
90 
91 #define __thread __declspec( thread )
92 
93 #define PICO_WEAK_FUNCTION_DEF(x) __pragma(comment(linker, __STRING(/alternatename:_##x=_##x##__weak)));
94 #define PICO_WEAK_FUNCTION_IMPL_NAME(x) x ## __weak
95 
__builtin_unreachable()96 static __noreturn void __builtin_unreachable() {
97 }
98 
99 #include <intrin.h>
100 #define __builtin_clz __lzcnt
101 #endif
102 
103 #ifndef count_of
104 #define count_of(a) (sizeof(a)/sizeof((a)[0]))
105 #endif
106 
107 #ifndef MAX
108 #define MAX(a, b) ((a)>(b)?(a):(b))
109 #endif
110 
111 #ifndef MIN
112 #define MIN(a, b) ((b)>(a)?(a):(b))
113 #endif
114 
115 // abort in our case
116 void __noreturn __breakpoint();
117 
118 void __noreturn panic_unsupported();
119 
120 void __noreturn panic(const char *fmt, ...);
121 
122 // arggggghhhh there is a weak function called sem_init used by SDL
123 #define sem_init sem_init_alternative
124 
125 extern uint32_t host_safe_hw_ptr_impl(uintptr_t x);
126 // return a 32 bit handle for a raw ptr; DMA chaining for example embeds pointers in 32 bit values
127 // which of course does not work if we're running the code natively on a 64 bit platforms. Therefore
128 // we provide this macro which allows that code to provide a 64->32 bit mapping in host mode
129 #define host_safe_hw_ptr(x) host_safe_hw_ptr_impl((uintptr_t)(x))
130 void *decode_host_safe_hw_ptr(uint32_t ptr);
131 
132 #define __fast_mul(a,b) ((a)*(b))
133 
134 typedef unsigned int uint;
135 
__mul_instruction(int32_t a,int32_t b)136 static inline int32_t __mul_instruction(int32_t a,int32_t b)
137 {
138     return a*b;
139 }
140 
__compiler_memory_barrier(void)141 static inline void __compiler_memory_barrier(void) {
142 }
143 
144 uint get_core_num();
145 
__get_current_exception(void)146 static inline uint __get_current_exception(void) {
147     return 0;
148 }
149 #ifdef __cplusplus
150 }
151 #endif
152 #endif
153