diff --git a/ports/windows/alloc.c b/ports/windows/alloc.c new file mode 100644 index 0000000000000..3aff36daaa846 --- /dev/null +++ b/ports/windows/alloc.c @@ -0,0 +1,101 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2014 Fabian Vogt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include +#include +#include + +#include + +#include "py/mpstate.h" +#include "py/gc.h" + +#if MICROPY_EMIT_NATIVE || (MICROPY_PY_FFI && MICROPY_FORCE_PLAT_ALLOC_EXEC) + +// The memory allocated here is not on the GC heap (and it may contain pointers +// that need to be GC'd) so we must somehow trace this memory. We do it by +// keeping a linked list of all mmap'd regions, and tracing them explicitly. + +typedef struct _mmap_region_t { + void *ptr; + size_t len; + struct _mmap_region_t *next; +} mmap_region_t; + +void mp_win_alloc_exec(size_t min_size, void **ptr, size_t *size) { + // size needs to be a multiple of the page size + *size = (min_size + 0xfff) & (~0xfff); + *ptr = VirtualAlloc(NULL, *size, MEM_RESERVE|MEM_COMMIT, PAGE_EXECUTE_READWRITE); + + // add new link to the list of mmap'd regions + mmap_region_t *rg = m_new_obj(mmap_region_t); + rg->ptr = *ptr; + rg->len = min_size; + rg->next = MP_STATE_VM(mmap_region_head); + MP_STATE_VM(mmap_region_head) = rg; +} + +void mp_win_free_exec(void *ptr, size_t size) { + VirtualFree(ptr, 0, MEM_RELEASE); + + // unlink the mmap'd region from the list + for (mmap_region_t **rg = (mmap_region_t**)&MP_STATE_VM(mmap_region_head); *rg != NULL; *rg = (*rg)->next) { + if ((*rg)->ptr == ptr) { + mmap_region_t *next = (*rg)->next; + m_del_obj(mmap_region_t, *rg); + *rg = next; + return; + } + } +} + +void mp_win_mark_exec(void) { + for (mmap_region_t *rg = MP_STATE_VM(mmap_region_head); rg != NULL; rg = rg->next) { + gc_collect_root(rg->ptr, rg->len / sizeof(mp_uint_t)); + } +} + +#if MICROPY_FORCE_PLAT_ALLOC_EXEC +// Provide implementation of libffi ffi_closure_* functions in terms +// of the functions above. On a normal Linux system, this save a lot +// of code size. +void *ffi_closure_alloc(size_t size, void **code); +void ffi_closure_free(void *ptr); + +void *ffi_closure_alloc(size_t size, void **code) { + size_t dummy; + mp_win_alloc_exec(size, code, &dummy); + return *code; +} + +void ffi_closure_free(void *ptr) { + (void)ptr; + // TODO +} +#endif + +#endif // MICROPY_EMIT_NATIVE || (MICROPY_PY_FFI && MICROPY_FORCE_PLAT_ALLOC_EXEC) diff --git a/ports/windows/gccollect.c b/ports/windows/gccollect.c new file mode 100644 index 0000000000000..dacac87bded2b --- /dev/null +++ b/ports/windows/gccollect.c @@ -0,0 +1,75 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2013, 2014 Damien P. George + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "py/mpstate.h" +#include "py/gc.h" + +#if MICROPY_ENABLE_GC + +// If MICROPY_GCREGS_SETJMP was requested explicitly, or if +// we enabled it as a fallback above. +#if MICROPY_GCREGS_SETJMP +#include + +typedef jmp_buf regs_t; + +STATIC void gc_helper_get_regs(regs_t arr) { + setjmp(arr); +} + +#endif // MICROPY_GCREGS_SETJMP + +// this function is used by mpthreadport.c +void gc_collect_regs_and_stack(void); + +void gc_collect_regs_and_stack(void) { + regs_t regs; + gc_helper_get_regs(regs); + // GC stack (and regs because we captured them) + void **regs_ptr = (void**)(void*)®s; + gc_collect_root(regs_ptr, ((uintptr_t)MP_STATE_THREAD(stack_top) - (uintptr_t)®s) / sizeof(uintptr_t)); +} + +void gc_collect(void) { + //gc_dump_info(); + + gc_collect_start(); + gc_collect_regs_and_stack(); + #if MICROPY_PY_THREAD + mp_thread_gc_others(); + #endif + #if MICROPY_EMIT_NATIVE + mp_win_mark_exec(); + #endif + gc_collect_end(); + + //printf("-----\n"); + //gc_dump_info(); +} + +#endif //MICROPY_ENABLE_GC diff --git a/ports/windows/micropython.vcxproj b/ports/windows/micropython.vcxproj index ee0b98abba871..8dfb90ffef80c 100644 --- a/ports/windows/micropython.vcxproj +++ b/ports/windows/micropython.vcxproj @@ -51,6 +51,7 @@ + @@ -82,6 +83,9 @@ + + false + @@ -100,5 +104,6 @@ + \ No newline at end of file diff --git a/ports/windows/mpconfigport.h b/ports/windows/mpconfigport.h index 81464d72a7f13..fefba5326d67f 100644 --- a/ports/windows/mpconfigport.h +++ b/ports/windows/mpconfigport.h @@ -33,7 +33,6 @@ #define MICROPY_ALLOC_PATH_MAX (260) //see minwindef.h for msvc or limits.h for mingw #define MICROPY_PERSISTENT_CODE_LOAD (1) -#define MICROPY_EMIT_X64 (0) #define MICROPY_EMIT_THUMB (0) #define MICROPY_EMIT_INLINE_THUMB (0) #define MICROPY_COMP_MODULE_CONST (1) @@ -119,9 +118,21 @@ extern const struct _mp_print_t mp_stderr_print; +#if defined(__MINGW64__) || defined(__MINGW32__) +#define MICROPY_NLR_SETJMP (1) +#endif + #ifdef _MSC_VER #define MICROPY_GCREGS_SETJMP (1) #define MICROPY_USE_INTERNAL_PRINTF (0) +#define MICROPY_NLR_SETJMP (0) + +#if defined(_WIN64) +#define MICROPY_EMIT_X64 (1) +#elif defined(_WIN32) +#define MICROPY_EMIT_X86 (1) +#endif + #endif #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1) @@ -181,10 +192,10 @@ extern const struct _mp_obj_module_t mp_module_time; { MP_ROM_QSTR(MP_QSTR_umachine), MP_ROM_PTR(&mp_module_machine) }, \ { MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&mp_module_os) }, \ -#if MICROPY_USE_READLINE == 1 #define MICROPY_PORT_ROOT_POINTERS \ - char *readline_hist[50]; -#endif + char *readline_hist[50]; \ + void *mmap_region_head; + #define MP_STATE_PORT MP_STATE_VM @@ -197,6 +208,12 @@ extern const struct _mp_obj_module_t mp_module_time; #include "init.h" #include "sleep.h" +void mp_win_alloc_exec(size_t min_size, void** ptr, size_t *size); +void mp_win_free_exec(void *ptr, size_t size); +void mp_win_mark_exec(void); +#define MP_PLAT_ALLOC_EXEC(min_size, ptr, size) mp_win_alloc_exec(min_size, ptr, size) +#define MP_PLAT_FREE_EXEC(ptr, size) mp_win_free_exec(ptr, size) + #ifdef __GNUC__ #define MP_NOINLINE __attribute__((noinline)) #endif diff --git a/ports/windows/msvc/asmnlrx64.asm b/ports/windows/msvc/asmnlrx64.asm new file mode 100644 index 0000000000000..df71964d384e1 --- /dev/null +++ b/ports/windows/msvc/asmnlrx64.asm @@ -0,0 +1,64 @@ +; +; This file is part of the MicroPython project, http://micropython.org/ +; +; The MIT License (MIT) +; +; Copyright (c) 2019 Jian Wang +; +; Permission is hereby granted, free of charge, to any person obtaining a copy +; of this software and associated documentation files (the "Software"), to deal +; in the Software without restriction, including without limitation the rights +; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +; copies of the Software, and to permit persons to whom the Software is +; furnished to do so, subject to the following conditions: +; +; The above copyright notice and this permission notice shall be included in +; all copies or substantial portions of the Software. +; +; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +; THE SOFTWARE. +; + +EXTERN nlr_push_tail:PROC + + .code + +nlr_push PROC + pop rdx ; load rip as well as fix rsp + mov [rcx + 10h], rbx + mov [rcx + 18h], rsp + mov [rcx + 20h], rbp + mov [rcx + 28h], rdi + mov [rcx + 30h], rsi + mov [rcx + 38h], r12 + mov [rcx + 40h], r13 + mov [rcx + 48h], r14 + mov [rcx + 50h], r15 + mov [rcx + 58h], rdx ; rip + + push rdx ;nlr_push_tail needs the return address + jmp nlr_push_tail ;do the rest in C +nlr_push ENDP + +asm_nlr_jump PROC + mov rbx, [rcx + 10h] + mov rsp, [rcx + 18h] + mov rbp, [rcx + 20h] + mov rdi, [rcx + 28h] + mov rsi, [rcx + 30h] + mov r12, [rcx + 38h] + mov r13, [rcx + 40h] + mov r14, [rcx + 48h] + mov r15, [rcx + 50h] + + mov rax, rdx ; set return value + jmp qword ptr [rcx + 58h] ; rip +asm_nlr_jump ENDP + + END + diff --git a/ports/windows/msvc/asmnlrx86.asm b/ports/windows/msvc/asmnlrx86.asm new file mode 100644 index 0000000000000..a181fc0ac7442 --- /dev/null +++ b/ports/windows/msvc/asmnlrx86.asm @@ -0,0 +1,58 @@ +; +; This file is part of the MicroPython project, http://micropython.org/ +; +; The MIT License (MIT) +; +; Copyright (c) 2019 Jian Wang +; +; Permission is hereby granted, free of charge, to any person obtaining a copy +; of this software and associated documentation files (the "Software"), to deal +; in the Software without restriction, including without limitation the rights +; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +; copies of the Software, and to permit persons to whom the Software is +; furnished to do so, subject to the following conditions: +; +; The above copyright notice and this permission notice shall be included in +; all copies or substantial portions of the Software. +; +; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +; THE SOFTWARE. +; + + .model flat + .code + +EXTERN _nlr_push_tail:PROC + +_nlr_push PROC + pop ecx ; ecx <- return address + mov edx, [esp] ; edx <- nlr + mov [edx + 08h], ecx ; eip value to restore in nlr_jump + mov [edx + 0Ch], ebp + mov [edx + 10h], esp + mov [edx + 14h], ebx + mov [edx + 18h], edi + mov [edx + 1Ch], esi + + push ecx ; make sure nlr_push_tail return back to nlr_push's caller() + jmp _nlr_push_tail ; do the rest in C +_nlr_push ENDP + +_asm_nlr_jump PROC + pop eax ; skip return address + pop edx ; edx <- nlr (top) + pop eax ; eax <- val + mov esi, [edx + 1Ch] + mov edi, [edx + 18h] + mov ebx, [edx + 14h] + mov esp, [edx + 10h] + mov ebp, [edx + 0Ch] + jmp dword ptr [edx + 08h] ; restore "eip" +_asm_nlr_jump ENDP + + END diff --git a/ports/windows/msvc/sources.props b/ports/windows/msvc/sources.props index 5c2076f1ea903..f7c17d8616cc1 100644 --- a/ports/windows/msvc/sources.props +++ b/ports/windows/msvc/sources.props @@ -8,7 +8,6 @@ - @@ -35,4 +34,16 @@ + + + + + + + + + + + + diff --git a/py/asmx64.c b/py/asmx64.c index b18703a9c5abb..7534a6e6ec4a4 100644 --- a/py/asmx64.c +++ b/py/asmx64.c @@ -251,7 +251,8 @@ void asm_x64_mov_r64_r64(asm_x64_t *as, int dest_r64, int src_r64) { } void asm_x64_mov_r8_to_mem8(asm_x64_t *as, int src_r64, int dest_r64, int dest_disp) { - if (src_r64 < 8 && dest_r64 < 8) { + // Access spl/bpl/sil/dil needs REX prefix + if (src_r64 < 4 && dest_r64 < 4) { asm_x64_write_byte_1(as, OPCODE_MOV_R8_TO_RM8); } else { asm_x64_write_byte_2(as, REX_PREFIX | REX_R_FROM_R64(src_r64) | REX_B_FROM_R64(dest_r64), OPCODE_MOV_R8_TO_RM8); @@ -321,9 +322,7 @@ void asm_x64_mov_mem64_to_r64(asm_x64_t *as, int src_r64, int src_disp, int dest STATIC void asm_x64_lea_disp_to_r64(asm_x64_t *as, int src_r64, int src_disp, int dest_r64) { // use REX prefix for 64 bit operation - assert(src_r64 < 8); - assert(dest_r64 < 8); - asm_x64_write_byte_2(as, REX_PREFIX | REX_W, OPCODE_LEA_MEM_TO_R64); + asm_x64_write_byte_2(as, REX_PREFIX | REX_W | REX_R_FROM_R64(dest_r64) | REX_B_FROM_R64(src_r64), OPCODE_LEA_MEM_TO_R64); asm_x64_write_r64_disp(as, dest_r64, src_r64, src_disp); } @@ -533,8 +532,13 @@ void asm_x64_entry(asm_x64_t *as, int num_locals) { assert(num_locals >= 0); asm_x64_push_r64(as, ASM_X64_REG_RBP); asm_x64_push_r64(as, ASM_X64_REG_RBX); +#if _WIN64 + asm_x64_push_r64(as, ASM_X64_REG_RSI); + asm_x64_push_r64(as, ASM_X64_REG_RDI); +#else asm_x64_push_r64(as, ASM_X64_REG_R12); asm_x64_push_r64(as, ASM_X64_REG_R13); +#endif num_locals |= 1; // make it odd so stack is aligned on 16 byte boundary asm_x64_sub_r64_i32(as, ASM_X64_REG_RSP, num_locals * WORD_SIZE); as->num_locals = num_locals; @@ -542,8 +546,13 @@ void asm_x64_entry(asm_x64_t *as, int num_locals) { void asm_x64_exit(asm_x64_t *as) { asm_x64_sub_r64_i32(as, ASM_X64_REG_RSP, -as->num_locals * WORD_SIZE); +#if _WIN64 + asm_x64_pop_r64(as, ASM_X64_REG_RDI); + asm_x64_pop_r64(as, ASM_X64_REG_RSI); +#else asm_x64_pop_r64(as, ASM_X64_REG_R13); asm_x64_pop_r64(as, ASM_X64_REG_R12); +#endif asm_x64_pop_r64(as, ASM_X64_REG_RBX); asm_x64_pop_r64(as, ASM_X64_REG_RBP); asm_x64_ret(as); @@ -625,8 +634,17 @@ void asm_x64_call_i1(asm_x64_t *as, void* func, int i1) { void asm_x64_call_ind(asm_x64_t *as, size_t fun_id, int temp_r64) { assert(temp_r64 < 8); + +#if _WIN64 + asm_x64_sub_r64_i32(as, ASM_X64_REG_RSP, 4 * WORD_SIZE); +#endif + asm_x64_mov_mem64_to_r64(as, ASM_X64_REG_FUN_TABLE, fun_id * WORD_SIZE, temp_r64); asm_x64_write_byte_2(as, OPCODE_CALL_RM32, MODRM_R64(2) | MODRM_RM_REG | MODRM_RM_R64(temp_r64)); + +#if _WIN64 + asm_x64_sub_r64_i32(as, ASM_X64_REG_RSP, -4 * WORD_SIZE); +#endif } #endif // MICROPY_EMIT_X64 diff --git a/py/asmx64.h b/py/asmx64.h index d3761b78f3399..ffa5753b2c8ad 100644 --- a/py/asmx64.h +++ b/py/asmx64.h @@ -127,23 +127,43 @@ void asm_x64_call_ind(asm_x64_t* as, size_t fun_id, int temp_r32); #define ASM_WORD_SIZE (8) -#define REG_RET ASM_X64_REG_RAX -#define REG_ARG_1 ASM_X64_REG_RDI -#define REG_ARG_2 ASM_X64_REG_RSI -#define REG_ARG_3 ASM_X64_REG_RDX -#define REG_ARG_4 ASM_X64_REG_RCX -#define REG_ARG_5 ASM_X64_REG_R08 - -// caller-save -#define REG_TEMP0 ASM_X64_REG_RAX -#define REG_TEMP1 ASM_X64_REG_RDI -#define REG_TEMP2 ASM_X64_REG_RSI - -// callee-save -#define REG_LOCAL_1 ASM_X64_REG_RBX -#define REG_LOCAL_2 ASM_X64_REG_R12 -#define REG_LOCAL_3 ASM_X64_REG_R13 -#define REG_LOCAL_NUM (3) +#ifdef _WIN64 + #define REG_RET ASM_X64_REG_RAX + #define REG_ARG_1 ASM_X64_REG_RCX + #define REG_ARG_2 ASM_X64_REG_RDX + #define REG_ARG_3 ASM_X64_REG_R08 + #define REG_ARG_4 ASM_X64_REG_R09 + #define REG_ARG_5 ASM_X64_REG_R10 + + // caller-save + #define REG_TEMP0 ASM_X64_REG_RAX + #define REG_TEMP1 ASM_X64_REG_RCX + #define REG_TEMP2 ASM_X64_REG_RDX + + // callee-save + #define REG_LOCAL_1 ASM_X64_REG_RBX + #define REG_LOCAL_2 ASM_X64_REG_RSI + #define REG_LOCAL_3 ASM_X64_REG_RDI + #define REG_LOCAL_NUM (3) +#else + #define REG_RET ASM_X64_REG_RAX + #define REG_ARG_1 ASM_X64_REG_RDI + #define REG_ARG_2 ASM_X64_REG_RSI + #define REG_ARG_3 ASM_X64_REG_RDX + #define REG_ARG_4 ASM_X64_REG_RCX + #define REG_ARG_5 ASM_X64_REG_R08 + + // caller-save + #define REG_TEMP0 ASM_X64_REG_RAX + #define REG_TEMP1 ASM_X64_REG_RDI + #define REG_TEMP2 ASM_X64_REG_RSI + + // callee-save + #define REG_LOCAL_1 ASM_X64_REG_RBX + #define REG_LOCAL_2 ASM_X64_REG_R12 + #define REG_LOCAL_3 ASM_X64_REG_R13 + #define REG_LOCAL_NUM (3) +#endif // Holds a pointer to mp_fun_table #define REG_FUN_TABLE ASM_X64_REG_FUN_TABLE diff --git a/py/emitnx64.c b/py/emitnx64.c index 4abb3ecad3a32..673b22c4a16d6 100644 --- a/py/emitnx64.c +++ b/py/emitnx64.c @@ -9,9 +9,15 @@ #include "py/asmx64.h" // Word indices of REG_LOCAL_x in nlr_buf_t +#ifdef _WIN64 +#define NLR_BUF_IDX_LOCAL_1 (2) // rbx +#define NLR_BUF_IDX_LOCAL_2 (6) // rsi +#define NLR_BUF_IDX_LOCAL_3 (5) // rdi +#else #define NLR_BUF_IDX_LOCAL_1 (5) // rbx #define NLR_BUF_IDX_LOCAL_2 (6) // r12 #define NLR_BUF_IDX_LOCAL_3 (7) // r13 +#endif #define N_X64 (1) #define EXPORT_FUN(name) emit_native_x64_##name diff --git a/py/nlr.c b/py/nlr.c index 03d01577e1419..30fdeae8bfde9 100644 --- a/py/nlr.c +++ b/py/nlr.c @@ -29,13 +29,17 @@ #if !MICROPY_NLR_SETJMP // When not using setjmp, nlr_push_tail is called from inline asm so needs special care #if MICROPY_NLR_X86 && MICROPY_NLR_OS_WINDOWS +#if defined (__GNUC__) // On these 32-bit platforms make sure nlr_push_tail doesn't have a leading underscore unsigned int nlr_push_tail(nlr_buf_t *nlr) asm("nlr_push_tail"); +#endif #else +#if defined (__GNUC__) // LTO can't see inside inline asm functions so explicitly mark nlr_push_tail as used __attribute__((used)) unsigned int nlr_push_tail(nlr_buf_t *nlr); #endif #endif +#endif unsigned int nlr_push_tail(nlr_buf_t *nlr) { nlr_buf_t **top = &MP_STATE_THREAD(nlr_top); @@ -49,3 +53,14 @@ void nlr_pop(void) { nlr_buf_t **top = &MP_STATE_THREAD(nlr_top); *top = (*top)->prev; } + +#if !MICROPY_NLR_SETJMP && defined(_WIN32) +void asm_nlr_jump(void *jmpbuf, void *val); + +NORETURN void nlr_jump(void *val) { + MP_NLR_JUMP_HEAD(val, top) + asm_nlr_jump(top, val); + for (;;); // needed to silence compiler warning +} +#endif + diff --git a/py/nlr.h b/py/nlr.h index 90595a12d37dc..8f447374d027d 100644 --- a/py/nlr.h +++ b/py/nlr.h @@ -42,10 +42,10 @@ #else #define MICROPY_NLR_OS_WINDOWS 0 #endif -#if defined(__i386__) +#if defined(__i386__) || (defined(_WIN32) && !defined(_WIN64)) #define MICROPY_NLR_X86 (1) #define MICROPY_NLR_NUM_REGS (6) -#elif defined(__x86_64__) +#elif defined(__x86_64__) || defined(_WIN64) #define MICROPY_NLR_X64 (1) #if MICROPY_NLR_OS_WINDOWS #define MICROPY_NLR_NUM_REGS (10) diff --git a/py/nlrx64.c b/py/nlrx64.c index a3a1cf341b916..8258ed840e6c6 100644 --- a/py/nlrx64.c +++ b/py/nlrx64.c @@ -27,6 +27,7 @@ #include "py/mpstate.h" #if MICROPY_NLR_X64 +#if !defined(_WIN32) #undef nlr_push @@ -111,4 +112,5 @@ NORETURN void nlr_jump(void *val) { for (;;); // needed to silence compiler warning } +#endif // !_WIN32 #endif // MICROPY_NLR_X64 diff --git a/py/nlrx86.c b/py/nlrx86.c index 59b97d8ee6a9a..eb965b9c614d3 100644 --- a/py/nlrx86.c +++ b/py/nlrx86.c @@ -27,6 +27,7 @@ #include "py/mpstate.h" #if MICROPY_NLR_X86 +#if !defined(_WIN32) #undef nlr_push @@ -103,4 +104,5 @@ NORETURN void nlr_jump(void *val) { for (;;); // needed to silence compiler warning } +#endif // !_WIN32 #endif // MICROPY_NLR_X86 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy