diff options
Diffstat (limited to 'py')
-rw-r--r-- | py/asmarm.c | 25 | ||||
-rw-r--r-- | py/asmthumb.c | 9 | ||||
-rw-r--r-- | py/asmx64.c | 28 | ||||
-rw-r--r-- | py/mpconfig.h | 8 |
4 files changed, 39 insertions, 31 deletions
diff --git a/py/asmarm.c b/py/asmarm.c index 8ba22faa07..fff95fddb6 100644 --- a/py/asmarm.c +++ b/py/asmarm.c @@ -40,8 +40,8 @@ struct _asm_arm_t { uint pass; - uint code_offset; - uint code_size; + mp_uint_t code_offset; + mp_uint_t code_size; byte *code_base; byte dummy_data[4]; @@ -64,7 +64,7 @@ asm_arm_t *asm_arm_new(uint max_num_labels) { void asm_arm_free(asm_arm_t *as, bool free_code) { if (free_code) { - m_del(byte, as->code_base, as->code_size); + MP_PLAT_FREE_EXEC(as->code_base, as->code_size); } m_del_obj(asm_arm_t, as); @@ -80,9 +80,22 @@ void asm_arm_start_pass(asm_arm_t *as, uint pass) { void asm_arm_end_pass(asm_arm_t *as) { if (as->pass == ASM_ARM_PASS_COMPUTE) { - // calculate size of code in bytes - as->code_size = as->code_offset; - as->code_base = m_new(byte, as->code_size); + MP_PLAT_ALLOC_EXEC(as->code_offset, (void**) &as->code_base, &as->code_size); + if(as->code_base == NULL) { + assert(0); + } + } + else if(as->pass == ASM_ARM_PASS_EMIT) { +#ifdef __arm__ + // flush I- and D-cache + asm volatile( + "0:" + "mrc p15, 0, r15, c7, c10, 3\n" + "bne 0b\n" + "mov r0, #0\n" + "mcr p15, 0, r0, c7, c7, 0\n" + : : : "r0", "cc"); +#endif } } diff --git a/py/asmthumb.c b/py/asmthumb.c index 1102bb74ab..95f87783ad 100644 --- a/py/asmthumb.c +++ b/py/asmthumb.c @@ -67,7 +67,7 @@ asm_thumb_t *asm_thumb_new(uint max_num_labels) { void asm_thumb_free(asm_thumb_t *as, bool free_code) { if (free_code) { - m_del(byte, as->code_base, as->code_size); + MP_PLAT_FREE_EXEC(as->code_base, as->code_size); } /* if (as->label != NULL) { @@ -94,9 +94,10 @@ void asm_thumb_start_pass(asm_thumb_t *as, uint pass) { void asm_thumb_end_pass(asm_thumb_t *as) { if (as->pass == ASM_THUMB_PASS_COMPUTE) { - // calculate size of code in bytes - as->code_size = as->code_offset; - as->code_base = m_new(byte, as->code_size); + MP_PLAT_ALLOC_EXEC(as->code_offset, (void**) &as->code_base, &as->code_size); + if(as->code_base == NULL) { + assert(0); + } //printf("code_size: %u\n", as->code_size); } diff --git a/py/asmx64.c b/py/asmx64.c index 4695bdc731..cf9d8b0f23 100644 --- a/py/asmx64.c +++ b/py/asmx64.c @@ -113,8 +113,8 @@ struct _asm_x64_t { uint pass; - uint code_offset; - uint code_size; + mp_uint_t code_offset; + mp_uint_t code_size; byte *code_base; byte dummy_data[8]; @@ -123,18 +123,6 @@ struct _asm_x64_t { int num_locals; }; -// for allocating memory, see src/v8/src/platform-linux.cc -void *alloc_mem(uint req_size, uint *alloc_size, bool is_exec) { - req_size = (req_size + 0xfff) & (~0xfff); - int prot = PROT_READ | PROT_WRITE | (is_exec ? PROT_EXEC : 0); - void *ptr = mmap(NULL, req_size, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - if (ptr == MAP_FAILED) { - assert(0); - } - *alloc_size = req_size; - return ptr; -} - asm_x64_t *asm_x64_new(uint max_num_labels) { asm_x64_t *as; @@ -147,8 +135,7 @@ asm_x64_t *asm_x64_new(uint max_num_labels) { void asm_x64_free(asm_x64_t *as, bool free_code) { if (free_code) { - // need to un-mmap - //m_free(as->code_base); + MP_PLAT_FREE_EXEC(as->code_base, as->code_size); } /* if (as->label != NULL) { @@ -176,11 +163,10 @@ void asm_x64_start_pass(asm_x64_t *as, uint pass) { void asm_x64_end_pass(asm_x64_t *as) { if (as->pass == ASM_X64_PASS_COMPUTE) { - // calculate size of code in bytes - as->code_size = as->code_offset; - //as->code_base = m_new(byte, as->code_size); need to allocale executable memory - uint actual_alloc; - as->code_base = alloc_mem(as->code_size, &actual_alloc, true); + MP_PLAT_ALLOC_EXEC(as->code_offset, (void**) &as->code_base, &as->code_size); + if(as->code_base == NULL) { + assert(0); + } //printf("code_size: %u\n", as->code_size); } diff --git a/py/mpconfig.h b/py/mpconfig.h index 2b89fab237..78c288d7c3 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -440,6 +440,14 @@ typedef double mp_float_t; #define MICROPY_MAKE_POINTER_CALLABLE(p) (p) #endif +#ifndef MP_PLAT_ALLOC_EXEC +#define MP_PLAT_ALLOC_EXEC(min_size, ptr, size) do { *ptr = m_new(byte, min_size); *size = min_size; } while(0) +#endif + +#ifndef MP_PLAT_FREE_EXEC +#define MP_PLAT_FREE_EXEC(ptr, size) m_del(byte, ptr, size) +#endif + // printf format spec to use for mp_int_t and friends #ifndef INT_FMT #ifdef __LP64__ |