| 1 | #ifndef ARCH_H |
| 2 | #define ARCH_H |
| 3 | |
| 4 | #ifdef __cplusplus |
| 5 | #include <atomic> |
| 6 | #else |
| 7 | #include <stdatomic.h> |
| 8 | #endif |
| 9 | |
| 10 | #include "../lib/types.h" |
| 11 | |
| 12 | enum { |
| 13 | arch_x86_64 = 1, |
| 14 | arch_x86, |
| 15 | arch_ppc, |
| 16 | arch_ia64, |
| 17 | arch_s390, |
| 18 | arch_alpha, |
| 19 | arch_sparc, |
| 20 | arch_sparc64, |
| 21 | arch_arm, |
| 22 | arch_sh, |
| 23 | arch_hppa, |
| 24 | arch_mips, |
| 25 | arch_aarch64, |
| 26 | arch_loongarch64, |
| 27 | arch_riscv64, |
| 28 | |
| 29 | arch_generic, |
| 30 | |
| 31 | arch_nr, |
| 32 | }; |
| 33 | |
| 34 | enum { |
| 35 | ARCH_FLAG_1 = 1 << 0, |
| 36 | ARCH_FLAG_2 = 1 << 1, |
| 37 | ARCH_FLAG_3 = 1 << 2, |
| 38 | ARCH_FLAG_4 = 1 << 3, |
| 39 | }; |
| 40 | |
| 41 | extern unsigned long arch_flags; |
| 42 | |
| 43 | #define ARCH_CPU_CLOCK_WRAPS |
| 44 | |
| 45 | #ifdef __cplusplus |
| 46 | #define atomic_add(p, v) \ |
| 47 | std::atomic_fetch_add(p, (v)) |
| 48 | #define atomic_sub(p, v) \ |
| 49 | std::atomic_fetch_sub(p, (v)) |
| 50 | #define atomic_load_relaxed(p) \ |
| 51 | std::atomic_load_explicit(p, \ |
| 52 | std::memory_order_relaxed) |
| 53 | #define atomic_load_acquire(p) \ |
| 54 | std::atomic_load_explicit(p, \ |
| 55 | std::memory_order_acquire) |
| 56 | #define atomic_store_release(p, v) \ |
| 57 | std::atomic_store_explicit(p, (v), \ |
| 58 | std::memory_order_release) |
| 59 | #else |
| 60 | #define atomic_add(p, v) \ |
| 61 | atomic_fetch_add((_Atomic typeof(*(p)) *)(p), v) |
| 62 | #define atomic_sub(p, v) \ |
| 63 | atomic_fetch_sub((_Atomic typeof(*(p)) *)(p), v) |
| 64 | #define atomic_load_relaxed(p) \ |
| 65 | atomic_load_explicit((_Atomic typeof(*(p)) *)(p), \ |
| 66 | memory_order_relaxed) |
| 67 | #define atomic_load_acquire(p) \ |
| 68 | atomic_load_explicit((_Atomic typeof(*(p)) *)(p), \ |
| 69 | memory_order_acquire) |
| 70 | #define atomic_store_release(p, v) \ |
| 71 | atomic_store_explicit((_Atomic typeof(*(p)) *)(p), (v), \ |
| 72 | memory_order_release) |
| 73 | #endif |
| 74 | |
| 75 | /* IWYU pragma: begin_exports */ |
| 76 | #if defined(__i386__) |
| 77 | #include "arch-x86.h" |
| 78 | #elif defined(__x86_64__) |
| 79 | #include "arch-x86_64.h" |
| 80 | #elif defined(__powerpc__) || defined(__powerpc64__) || defined(__ppc__) |
| 81 | #include "arch-ppc.h" |
| 82 | #elif defined(__ia64__) |
| 83 | #include "arch-ia64.h" |
| 84 | #elif defined(__alpha__) |
| 85 | #include "arch-alpha.h" |
| 86 | #elif defined(__s390x__) || defined(__s390__) |
| 87 | #include "arch-s390.h" |
| 88 | #elif defined(__sparc__) |
| 89 | #include "arch-sparc.h" |
| 90 | #elif defined(__sparc64__) |
| 91 | #include "arch-sparc64.h" |
| 92 | #elif defined(__arm__) |
| 93 | #include "arch-arm.h" |
| 94 | #elif defined(__mips__) || defined(__mips64__) |
| 95 | #include "arch-mips.h" |
| 96 | #elif defined(__sh__) |
| 97 | #include "arch-sh.h" |
| 98 | #elif defined(__hppa__) |
| 99 | #include "arch-hppa.h" |
| 100 | #elif defined(__aarch64__) |
| 101 | #include "arch-aarch64.h" |
| 102 | #elif defined(__loongarch64) |
| 103 | #include "arch-loongarch64.h" |
| 104 | #elif defined(__riscv) && __riscv_xlen == 64 |
| 105 | #include "arch-riscv64.h" |
| 106 | #else |
| 107 | #warning "Unknown architecture, attempting to use generic model." |
| 108 | #include "arch-generic.h" |
| 109 | #endif |
| 110 | |
| 111 | #if !defined(__x86_64__) && defined(CONFIG_SYNC_SYNC) |
| 112 | static inline void tsc_barrier(void) |
| 113 | { |
| 114 | __sync_synchronize(); |
| 115 | } |
| 116 | #endif |
| 117 | |
| 118 | #include "../lib/ffz.h" |
| 119 | /* IWYU pragma: end_exports */ |
| 120 | |
| 121 | #ifndef ARCH_HAVE_INIT |
| 122 | static inline int arch_init(char *envp[]) |
| 123 | { |
| 124 | return 0; |
| 125 | } |
| 126 | #endif |
| 127 | |
| 128 | #ifdef __alpha__ |
| 129 | /* |
| 130 | * alpha is the only exception, all other architectures |
| 131 | * have common numbers for new system calls. |
| 132 | */ |
| 133 | # ifndef __NR_io_uring_setup |
| 134 | # define __NR_io_uring_setup 535 |
| 135 | # endif |
| 136 | # ifndef __NR_io_uring_enter |
| 137 | # define __NR_io_uring_enter 536 |
| 138 | # endif |
| 139 | # ifndef __NR_io_uring_register |
| 140 | # define __NR_io_uring_register 537 |
| 141 | # endif |
| 142 | #else /* !__alpha__ */ |
| 143 | # ifndef __NR_io_uring_setup |
| 144 | # define __NR_io_uring_setup 425 |
| 145 | # endif |
| 146 | # ifndef __NR_io_uring_enter |
| 147 | # define __NR_io_uring_enter 426 |
| 148 | # endif |
| 149 | # ifndef __NR_io_uring_register |
| 150 | # define __NR_io_uring_register 427 |
| 151 | # endif |
| 152 | #endif |
| 153 | |
| 154 | #define ARCH_HAVE_IOURING |
| 155 | |
| 156 | #endif |