| 1 | /* |
| 2 | * This file is part of the MicroPython project, http://micropython.org/ |
| 3 | * |
| 4 | * The MIT License (MIT) |
| 5 | * |
| 6 | * Copyright (c) 2013, 2014 Damien P. George |
| 7 | * |
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | * of this software and associated documentation files (the "Software"), to deal |
| 10 | * in the Software without restriction, including without limitation the rights |
| 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | * copies of the Software, and to permit persons to whom the Software is |
| 13 | * furnished to do so, subject to the following conditions: |
| 14 | * |
| 15 | * The above copyright notice and this permission notice shall be included in |
| 16 | * all copies or substantial portions of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | * THE SOFTWARE. |
| 25 | */ |
| 26 | |
| 27 | // Options to control how MicroPython is built for this port, |
| 28 | // overriding defaults in py/mpconfig.h. |
| 29 | |
| 30 | // Variant-specific definitions. |
| 31 | #include "mpconfigvariant.h" |
| 32 | |
| 33 | // The minimal variant's config covers everything. |
| 34 | // If we're building the minimal variant, ignore the rest of this file. |
| 35 | #ifndef MICROPY_UNIX_MINIMAL |
| 36 | |
| 37 | #define MICROPY_ALLOC_PATH_MAX (PATH_MAX) |
| 38 | #define MICROPY_PERSISTENT_CODE_LOAD (1) |
| 39 | #if !defined(MICROPY_EMIT_X64) && defined(__x86_64__) |
| 40 | #define MICROPY_EMIT_X64 (1) |
| 41 | #endif |
| 42 | #if !defined(MICROPY_EMIT_X86) && defined(__i386__) |
| 43 | #define MICROPY_EMIT_X86 (1) |
| 44 | #endif |
| 45 | #if !defined(MICROPY_EMIT_THUMB) && defined(__thumb2__) |
| 46 | #define MICROPY_EMIT_THUMB (1) |
| 47 | #define MICROPY_MAKE_POINTER_CALLABLE(p) ((void *)((mp_uint_t)(p) | 1)) |
| 48 | #endif |
| 49 | // Some compilers define __thumb2__ and __arm__ at the same time, let |
| 50 | // autodetected thumb2 emitter have priority. |
| 51 | #if !defined(MICROPY_EMIT_ARM) && defined(__arm__) && !defined(__thumb2__) |
| 52 | #define MICROPY_EMIT_ARM (1) |
| 53 | #endif |
| 54 | #define MICROPY_COMP_MODULE_CONST (1) |
| 55 | #define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (1) |
| 56 | #define MICROPY_COMP_RETURN_IF_EXPR (1) |
| 57 | #define MICROPY_ENABLE_GC (1) |
| 58 | #define MICROPY_ENABLE_FINALISER (1) |
| 59 | #define MICROPY_STACK_CHECK (1) |
| 60 | #define MICROPY_MALLOC_USES_ALLOCATED_SIZE (1) |
| 61 | #define MICROPY_MEM_STATS (1) |
| 62 | #define MICROPY_DEBUG_PRINTERS (1) |
| 63 | // Printing debug to stderr may give tests which |
| 64 | // check stdout a chance to pass, etc. |
| 65 | #define MICROPY_DEBUG_PRINTER (&mp_stderr_print) |
| 66 | #define MICROPY_READER_POSIX (1) |
| 67 | #define MICROPY_USE_READLINE_HISTORY (1) |
| 68 | #define MICROPY_HELPER_REPL (1) |
| 69 | #define MICROPY_REPL_EMACS_KEYS (1) |
| 70 | #define MICROPY_REPL_AUTO_INDENT (1) |
| 71 | #define MICROPY_HELPER_LEXER_UNIX (1) |
| 72 | #define MICROPY_ENABLE_SOURCE_LINE (1) |
| 73 | #ifndef MICROPY_FLOAT_IMPL |
| 74 | #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE) |
| 75 | #endif |
| 76 | #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ) |
| 77 | #ifndef MICROPY_STREAMS_NON_BLOCK |
| 78 | #define MICROPY_STREAMS_NON_BLOCK (1) |
| 79 | #endif |
| 80 | #define MICROPY_STREAMS_POSIX_API (1) |
| 81 | #define MICROPY_OPT_COMPUTED_GOTO (1) |
| 82 | #ifndef MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE |
| 83 | #define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (1) |
| 84 | #endif |
| 85 | #define MICROPY_MODULE_WEAK_LINKS (1) |
| 86 | #define MICROPY_CAN_OVERRIDE_BUILTINS (1) |
| 87 | #define MICROPY_VFS_POSIX_FILE (1) |
| 88 | #define MICROPY_PY_FUNCTION_ATTRS (1) |
| 89 | #define MICROPY_PY_DESCRIPTORS (1) |
| 90 | #define MICROPY_PY_DELATTR_SETATTR (1) |
| 91 | #define MICROPY_PY_BUILTINS_STR_UNICODE (1) |
| 92 | #define MICROPY_PY_BUILTINS_STR_CENTER (1) |
| 93 | #define MICROPY_PY_BUILTINS_STR_PARTITION (1) |
| 94 | #define MICROPY_PY_BUILTINS_STR_SPLITLINES (1) |
| 95 | #define MICROPY_PY_BUILTINS_MEMORYVIEW (1) |
| 96 | #define MICROPY_PY_BUILTINS_FROZENSET (1) |
| 97 | #define MICROPY_PY_BUILTINS_COMPILE (1) |
| 98 | #define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (1) |
| 99 | #define MICROPY_PY_BUILTINS_INPUT (1) |
| 100 | #define MICROPY_PY_BUILTINS_POW3 (1) |
| 101 | #define MICROPY_PY_BUILTINS_ROUND_INT (1) |
| 102 | #define MICROPY_PY_MICROPYTHON_MEM_INFO (1) |
| 103 | #define MICROPY_PY_ALL_SPECIAL_METHODS (1) |
| 104 | #define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) |
| 105 | #define MICROPY_PY_ARRAY_SLICE_ASSIGN (1) |
| 106 | #define MICROPY_PY_BUILTINS_SLICE_ATTRS (1) |
| 107 | #define MICROPY_PY_BUILTINS_SLICE_INDICES (1) |
| 108 | #define MICROPY_PY_SYS_EXIT (1) |
| 109 | #define MICROPY_PY_SYS_ATEXIT (1) |
| 110 | #if MICROPY_PY_SYS_SETTRACE |
| 111 | #define MICROPY_PERSISTENT_CODE_SAVE (1) |
| 112 | #define MICROPY_COMP_CONST (0) |
| 113 | #endif |
| 114 | #ifndef MICROPY_PY_SYS_PLATFORM |
| 115 | #if defined(__APPLE__) && defined(__MACH__) |
| 116 | #define MICROPY_PY_SYS_PLATFORM "darwin" |
| 117 | #else |
| 118 | #define MICROPY_PY_SYS_PLATFORM "linux" |
| 119 | #endif |
| 120 | #endif |
| 121 | #define MICROPY_PY_SYS_MAXSIZE (1) |
| 122 | #define MICROPY_PY_SYS_STDFILES (1) |
| 123 | #define MICROPY_PY_SYS_EXC_INFO (1) |
| 124 | #define MICROPY_PY_COLLECTIONS_DEQUE (1) |
| 125 | #define MICROPY_PY_COLLECTIONS_ORDEREDDICT (1) |
| 126 | #ifndef MICROPY_PY_MATH_SPECIAL_FUNCTIONS |
| 127 | #define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (1) |
| 128 | #endif |
| 129 | #define MICROPY_PY_MATH_ISCLOSE (MICROPY_PY_MATH_SPECIAL_FUNCTIONS) |
| 130 | #define MICROPY_PY_CMATH (1) |
| 131 | #define MICROPY_PY_IO_IOBASE (1) |
| 132 | #define MICROPY_PY_IO_FILEIO (1) |
| 133 | #define MICROPY_PY_GC_COLLECT_RETVAL (1) |
| 134 | |
| 135 | #ifndef MICROPY_STACKLESS |
| 136 | #define MICROPY_STACKLESS (0) |
| 137 | #define MICROPY_STACKLESS_STRICT (0) |
| 138 | #endif |
| 139 | |
| 140 | #define MICROPY_PY_OS_STATVFS (1) |
| 141 | #define MICROPY_PY_UTIME (1) |
| 142 | #define MICROPY_PY_UTIME_MP_HAL (1) |
| 143 | #define MICROPY_PY_UERRNO (1) |
| 144 | #define MICROPY_PY_UCTYPES (1) |
| 145 | #define MICROPY_PY_UZLIB (1) |
| 146 | #define MICROPY_PY_UJSON (1) |
| 147 | #define MICROPY_PY_URE (1) |
| 148 | #define MICROPY_PY_UHEAPQ (1) |
| 149 | #define MICROPY_PY_UTIMEQ (1) |
| 150 | #define MICROPY_PY_UHASHLIB (1) |
| 151 | #if MICROPY_PY_USSL |
| 152 | #define MICROPY_PY_UHASHLIB_MD5 (1) |
| 153 | #define MICROPY_PY_UHASHLIB_SHA1 (1) |
| 154 | #define MICROPY_PY_UCRYPTOLIB (1) |
| 155 | #endif |
| 156 | #define MICROPY_PY_UBINASCII (1) |
| 157 | #define MICROPY_PY_UBINASCII_CRC32 (1) |
| 158 | #define MICROPY_PY_URANDOM (1) |
| 159 | #ifndef MICROPY_PY_USELECT_POSIX |
| 160 | #define MICROPY_PY_USELECT_POSIX (1) |
| 161 | #endif |
| 162 | #define MICROPY_PY_UWEBSOCKET (1) |
| 163 | #define MICROPY_PY_MACHINE (1) |
| 164 | #define MICROPY_PY_MACHINE_PULSE (1) |
| 165 | #define MICROPY_MACHINE_MEM_GET_READ_ADDR mod_machine_mem_get_addr |
| 166 | #define MICROPY_MACHINE_MEM_GET_WRITE_ADDR mod_machine_mem_get_addr |
| 167 | |
| 168 | #define MICROPY_FATFS_ENABLE_LFN (1) |
| 169 | #define MICROPY_FATFS_RPATH (2) |
| 170 | #define MICROPY_FATFS_MAX_SS (4096) |
| 171 | #define MICROPY_FATFS_LFN_CODE_PAGE 437 /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */ |
| 172 | |
| 173 | // Define to MICROPY_ERROR_REPORTING_DETAILED to get function, etc. |
| 174 | // names in exception messages (may require more RAM). |
| 175 | #define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_DETAILED) |
| 176 | #define MICROPY_WARNINGS (1) |
| 177 | #define MICROPY_ERROR_PRINTER (&mp_stderr_print) |
| 178 | #define MICROPY_PY_STR_BYTES_CMP_WARN (1) |
| 179 | |
| 180 | // VFS stat functions should return time values relative to 1970/1/1 |
| 181 | #define MICROPY_EPOCH_IS_1970 (1) |
| 182 | |
| 183 | extern const struct _mp_print_t mp_stderr_print; |
| 184 | |
| 185 | #if !(defined(MICROPY_GCREGS_SETJMP) || defined(__x86_64__) || defined(__i386__) || defined(__thumb2__) || defined(__thumb__) || defined(__arm__)) |
| 186 | // Fall back to setjmp() implementation for discovery of GC pointers in registers. |
| 187 | #define MICROPY_GCREGS_SETJMP (1) |
| 188 | #endif |
| 189 | |
| 190 | #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1) |
| 191 | #define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (256) |
| 192 | #define MICROPY_KBD_EXCEPTION (1) |
| 193 | #define MICROPY_ASYNC_KBD_INTR (1) |
| 194 | |
| 195 | #define mp_type_fileio mp_type_vfs_posix_fileio |
| 196 | #define mp_type_textio mp_type_vfs_posix_textio |
| 197 | |
| 198 | extern const struct _mp_obj_module_t mp_module_machine; |
| 199 | extern const struct _mp_obj_module_t mp_module_os; |
| 200 | extern const struct _mp_obj_module_t mp_module_uos_vfs; |
| 201 | extern const struct _mp_obj_module_t mp_module_uselect; |
| 202 | extern const struct _mp_obj_module_t mp_module_time; |
| 203 | extern const struct _mp_obj_module_t mp_module_termios; |
| 204 | extern const struct _mp_obj_module_t mp_module_socket; |
| 205 | extern const struct _mp_obj_module_t mp_module_ffi; |
| 206 | extern const struct _mp_obj_module_t mp_module_jni; |
| 207 | |
| 208 | #if MICROPY_PY_UOS_VFS |
| 209 | #define MICROPY_PY_UOS_DEF { MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&mp_module_uos_vfs) }, |
| 210 | #else |
| 211 | #define MICROPY_PY_UOS_DEF { MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&mp_module_os) }, |
| 212 | #endif |
| 213 | #if MICROPY_PY_FFI |
| 214 | #define MICROPY_PY_FFI_DEF { MP_ROM_QSTR(MP_QSTR_ffi), MP_ROM_PTR(&mp_module_ffi) }, |
| 215 | #else |
| 216 | #define MICROPY_PY_FFI_DEF |
| 217 | #endif |
| 218 | #if MICROPY_PY_JNI |
| 219 | #define MICROPY_PY_JNI_DEF { MP_ROM_QSTR(MP_QSTR_jni), MP_ROM_PTR(&mp_module_jni) }, |
| 220 | #else |
| 221 | #define MICROPY_PY_JNI_DEF |
| 222 | #endif |
| 223 | #if MICROPY_PY_UTIME |
| 224 | #define MICROPY_PY_UTIME_DEF { MP_ROM_QSTR(MP_QSTR_utime), MP_ROM_PTR(&mp_module_time) }, |
| 225 | #else |
| 226 | #define MICROPY_PY_UTIME_DEF |
| 227 | #endif |
| 228 | #if MICROPY_PY_TERMIOS |
| 229 | #define MICROPY_PY_TERMIOS_DEF { MP_ROM_QSTR(MP_QSTR_termios), MP_ROM_PTR(&mp_module_termios) }, |
| 230 | #else |
| 231 | #define MICROPY_PY_TERMIOS_DEF |
| 232 | #endif |
| 233 | #if MICROPY_PY_SOCKET |
| 234 | #define MICROPY_PY_SOCKET_DEF { MP_ROM_QSTR(MP_QSTR_usocket), MP_ROM_PTR(&mp_module_socket) }, |
| 235 | #else |
| 236 | #define MICROPY_PY_SOCKET_DEF |
| 237 | #endif |
| 238 | #if MICROPY_PY_USELECT_POSIX |
| 239 | #define MICROPY_PY_USELECT_DEF { MP_ROM_QSTR(MP_QSTR_uselect), MP_ROM_PTR(&mp_module_uselect) }, |
| 240 | #else |
| 241 | #define MICROPY_PY_USELECT_DEF |
| 242 | #endif |
| 243 | |
| 244 | #define MICROPY_PORT_BUILTIN_MODULES \ |
| 245 | MICROPY_PY_FFI_DEF \ |
| 246 | MICROPY_PY_JNI_DEF \ |
| 247 | MICROPY_PY_UTIME_DEF \ |
| 248 | MICROPY_PY_SOCKET_DEF \ |
| 249 | { MP_ROM_QSTR(MP_QSTR_umachine), MP_ROM_PTR(&mp_module_machine) }, \ |
| 250 | MICROPY_PY_UOS_DEF \ |
| 251 | MICROPY_PY_USELECT_DEF \ |
| 252 | MICROPY_PY_TERMIOS_DEF \ |
| 253 | |
| 254 | // type definitions for the specific machine |
| 255 | |
| 256 | // For size_t and ssize_t |
| 257 | #include <unistd.h> |
| 258 | |
| 259 | // assume that if we already defined the obj repr then we also defined types |
| 260 | #ifndef MICROPY_OBJ_REPR |
| 261 | #ifdef __LP64__ |
| 262 | typedef long mp_int_t; // must be pointer size |
| 263 | typedef unsigned long mp_uint_t; // must be pointer size |
| 264 | #else |
| 265 | // These are definitions for machines where sizeof(int) == sizeof(void*), |
| 266 | // regardless of actual size. |
| 267 | typedef int mp_int_t; // must be pointer size |
| 268 | typedef unsigned int mp_uint_t; // must be pointer size |
| 269 | #endif |
| 270 | #endif |
| 271 | |
| 272 | // Cannot include <sys/types.h>, as it may lead to symbol name clashes |
| 273 | #if _FILE_OFFSET_BITS == 64 && !defined(__LP64__) |
| 274 | typedef long long mp_off_t; |
| 275 | #else |
| 276 | typedef long mp_off_t; |
| 277 | #endif |
| 278 | |
| 279 | void mp_unix_alloc_exec(size_t min_size, void **ptr, size_t *size); |
| 280 | void mp_unix_free_exec(void *ptr, size_t size); |
| 281 | void mp_unix_mark_exec(void); |
| 282 | #define MP_PLAT_ALLOC_EXEC(min_size, ptr, size) mp_unix_alloc_exec(min_size, ptr, size) |
| 283 | #define MP_PLAT_FREE_EXEC(ptr, size) mp_unix_free_exec(ptr, size) |
| 284 | #ifndef MICROPY_FORCE_PLAT_ALLOC_EXEC |
| 285 | // Use MP_PLAT_ALLOC_EXEC for any executable memory allocation, including for FFI |
| 286 | // (overriding libffi own implementation) |
| 287 | #define MICROPY_FORCE_PLAT_ALLOC_EXEC (1) |
| 288 | #endif |
| 289 | |
| 290 | #ifdef __linux__ |
| 291 | // Can access physical memory using /dev/mem |
| 292 | #define MICROPY_PLAT_DEV_MEM (1) |
| 293 | #endif |
| 294 | |
| 295 | // Assume that select() call, interrupted with a signal, and erroring |
| 296 | // with EINTR, updates remaining timeout value. |
| 297 | #define MICROPY_SELECT_REMAINING_TIME (1) |
| 298 | |
| 299 | #ifdef __ANDROID__ |
| 300 | #include <android/api-level.h> |
| 301 | #if __ANDROID_API__ < 4 |
| 302 | // Bionic libc in Android 1.5 misses these 2 functions |
| 303 | #define MP_NEED_LOG2 (1) |
| 304 | #define nan(x) NAN |
| 305 | #endif |
| 306 | #endif |
| 307 | |
| 308 | #define MICROPY_PORT_BUILTINS \ |
| 309 | { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) }, |
| 310 | |
| 311 | #define MP_STATE_PORT MP_STATE_VM |
| 312 | |
| 313 | #if MICROPY_PY_BLUETOOTH |
| 314 | #if MICROPY_BLUETOOTH_BTSTACK |
| 315 | struct _mp_bluetooth_btstack_root_pointers_t; |
| 316 | #define MICROPY_BLUETOOTH_ROOT_POINTERS struct _mp_bluetooth_btstack_root_pointers_t *bluetooth_btstack_root_pointers; |
| 317 | #endif |
| 318 | #if MICROPY_BLUETOOTH_NIMBLE |
| 319 | struct _mp_bluetooth_nimble_root_pointers_t; |
| 320 | struct _mp_bluetooth_nimble_malloc_t; |
| 321 | #define MICROPY_BLUETOOTH_ROOT_POINTERS struct _mp_bluetooth_nimble_malloc_t *bluetooth_nimble_memory; struct _mp_bluetooth_nimble_root_pointers_t *bluetooth_nimble_root_pointers; |
| 322 | #endif |
| 323 | #else |
| 324 | #define MICROPY_BLUETOOTH_ROOT_POINTERS |
| 325 | #endif |
| 326 | |
| 327 | #define MICROPY_PORT_ROOT_POINTERS \ |
| 328 | const char *readline_hist[50]; \ |
| 329 | void *mmap_region_head; \ |
| 330 | MICROPY_BLUETOOTH_ROOT_POINTERS \ |
| 331 | |
| 332 | // We need to provide a declaration/definition of alloca() |
| 333 | // unless support for it is disabled. |
| 334 | #if !defined(MICROPY_NO_ALLOCA) || MICROPY_NO_ALLOCA == 0 |
| 335 | #ifdef __FreeBSD__ |
| 336 | #include <stdlib.h> |
| 337 | #else |
| 338 | #include <alloca.h> |
| 339 | #endif |
| 340 | #endif |
| 341 | |
| 342 | // From "man readdir": "Under glibc, programs can check for the availability |
| 343 | // of the fields [in struct dirent] not defined in POSIX.1 by testing whether |
| 344 | // the macros [...], _DIRENT_HAVE_D_TYPE are defined." |
| 345 | // Other libc's don't define it, but proactively assume that dirent->d_type |
| 346 | // is available on a modern *nix system. |
| 347 | #ifndef _DIRENT_HAVE_D_TYPE |
| 348 | #define _DIRENT_HAVE_D_TYPE (1) |
| 349 | #endif |
| 350 | // This macro is not provided by glibc but we need it so ports that don't have |
| 351 | // dirent->d_ino can disable the use of this field. |
| 352 | #ifndef _DIRENT_HAVE_D_INO |
| 353 | #define _DIRENT_HAVE_D_INO (1) |
| 354 | #endif |
| 355 | |
| 356 | #ifndef __APPLE__ |
| 357 | // For debugging purposes, make printf() available to any source file. |
| 358 | #include <stdio.h> |
| 359 | #endif |
| 360 | |
| 361 | #if MICROPY_PY_THREAD |
| 362 | #define MICROPY_BEGIN_ATOMIC_SECTION() (mp_thread_unix_begin_atomic_section(), 0xffffffff) |
| 363 | #define MICROPY_END_ATOMIC_SECTION(x) (void)x; mp_thread_unix_end_atomic_section() |
| 364 | #endif |
| 365 | |
| 366 | #define MICROPY_EVENT_POLL_HOOK \ |
| 367 | do { \ |
| 368 | extern void mp_handle_pending(bool); \ |
| 369 | mp_handle_pending(true); \ |
| 370 | mp_hal_delay_us(500); \ |
| 371 | } while (0); |
| 372 | |
| 373 | #include <sched.h> |
| 374 | #define MICROPY_UNIX_MACHINE_IDLE sched_yield(); |
| 375 | |
| 376 | #endif // MICROPY_UNIX_MINIMAL |
| 377 | |