SummerGift 6 лет назад
Родитель
Сommit
e103e00493

+ 34 - 0
lib/utils/gchelper.h

@@ -0,0 +1,34 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2019 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.
+ */
+#ifndef MICROPY_INCLUDED_LIB_UTILS_GCHELPER_H
+#define MICROPY_INCLUDED_LIB_UTILS_GCHELPER_H
+
+#include <stdint.h>
+
+uintptr_t gc_helper_get_sp(void);
+uintptr_t gc_helper_get_regs_and_sp(uintptr_t *regs);
+
+#endif // MICROPY_INCLUDED_LIB_UTILS_GCHELPER_H

+ 61 - 0
lib/utils/gchelper_m0.s

@@ -0,0 +1,61 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2018 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.
+ */
+
+    .syntax unified
+    .cpu cortex-m0
+    .thumb
+
+    .section .text
+    .align 2
+
+    .global gc_helper_get_regs_and_sp
+    .type gc_helper_get_regs_and_sp, %function
+
+@ uint gc_helper_get_regs_and_sp(r0=uint regs[10])
+gc_helper_get_regs_and_sp:
+    @ store registers into given array
+    str    r4, [r0, #0]
+    str    r5, [r0, #4]
+    str    r6, [r0, #8]
+    str    r7, [r0, #12]
+    mov    r1, r8
+    str    r1, [r0, #16]
+    mov    r1, r9
+    str    r1, [r0, #20]
+    mov    r1, r10
+    str    r1, [r0, #24]
+    mov    r1, r11
+    str    r1, [r0, #28]
+    mov    r1, r12
+    str    r1, [r0, #32]
+    mov    r1, r13
+    str    r1, [r0, #36]
+
+    @ return the sp
+    mov    r0, sp
+    bx     lr
+
+    .size gc_helper_get_regs_and_sp, .-gc_helper_get_regs_and_sp

+ 67 - 0
lib/utils/gchelper_m3.s

@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+
+    .syntax unified
+    .cpu cortex-m3
+    .thumb
+
+    .section .text
+    .align  2
+
+    .global gc_helper_get_sp
+    .type gc_helper_get_sp, %function
+
+@ uint gc_helper_get_sp(void)
+gc_helper_get_sp:
+    @ return the sp
+    mov     r0, sp
+    bx      lr
+
+    .size gc_helper_get_sp, .-gc_helper_get_sp
+
+
+    .global gc_helper_get_regs_and_sp
+    .type gc_helper_get_regs_and_sp, %function
+
+@ uint gc_helper_get_regs_and_sp(r0=uint regs[10])
+gc_helper_get_regs_and_sp:
+    @ store registers into given array
+    str     r4, [r0], #4
+    str     r5, [r0], #4
+    str     r6, [r0], #4
+    str     r7, [r0], #4
+    str     r8, [r0], #4
+    str     r9, [r0], #4
+    str     r10, [r0], #4
+    str     r11, [r0], #4
+    str     r12, [r0], #4
+    str     r13, [r0], #4
+
+    @ return the sp
+    mov     r0, sp
+    bx      lr
+
+    .size gc_helper_get_regs_and_sp, .-gc_helper_get_regs_and_sp

+ 1 - 1
lib/utils/interrupt_char.c

@@ -29,7 +29,7 @@
 
 
 #if MICROPY_KBD_EXCEPTION
 #if MICROPY_KBD_EXCEPTION
 
 
-int mp_interrupt_char;
+int mp_interrupt_char = -1;
 
 
 void mp_hal_set_interrupt_char(int c) {
 void mp_hal_set_interrupt_char(int c) {
     if (c != -1) {
     if (c != -1) {

+ 0 - 2
lib/utils/mpirq.c

@@ -78,10 +78,8 @@ void mp_irq_handler(mp_irq_obj_t *self) {
             }
             }
             gc_unlock();
             gc_unlock();
         } else {
         } else {
-#if MICROPY_ENABLE_SCHEDULER
             // Schedule call to user function
             // Schedule call to user function
             mp_sched_schedule(self->handler, self->parent);
             mp_sched_schedule(self->handler, self->parent);
-#endif
         }
         }
     }
     }
 }
 }

+ 14 - 3
lib/utils/pyexec.c

@@ -89,7 +89,7 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input
             // source is a lexer, parse and compile the script
             // source is a lexer, parse and compile the script
             qstr source_name = lex->source_name;
             qstr source_name = lex->source_name;
             mp_parse_tree_t parse_tree = mp_parse(lex, input_kind);
             mp_parse_tree_t parse_tree = mp_parse(lex, input_kind);
-            module_fun = mp_compile(&parse_tree, source_name, MP_EMIT_OPT_NONE, exec_flags & EXEC_FLAG_IS_REPL);
+            module_fun = mp_compile(&parse_tree, source_name, exec_flags & EXEC_FLAG_IS_REPL);
             #else
             #else
             mp_raise_msg(&mp_type_RuntimeError, "script compilation not supported");
             mp_raise_msg(&mp_type_RuntimeError, "script compilation not supported");
             #endif
             #endif
@@ -482,8 +482,7 @@ friendly_repl_reset:
         } else if (ret == CHAR_CTRL_D) {
         } else if (ret == CHAR_CTRL_D) {
             // exit for a soft reset
             // exit for a soft reset
             mp_hal_stdout_tx_str("\r\n");
             mp_hal_stdout_tx_str("\r\n");
-            //TODO it will occur assert on RT-Thread platform, so comment it
-//            vstr_clear(&line);
+            vstr_clear(&line);
             return PYEXEC_FORCED_EXIT;
             return PYEXEC_FORCED_EXIT;
         } else if (ret == CHAR_CTRL_E) {
         } else if (ret == CHAR_CTRL_E) {
             // paste mode
             // paste mode
@@ -542,6 +541,18 @@ int pyexec_file(const char *filename) {
     return parse_compile_execute(filename, MP_PARSE_FILE_INPUT, EXEC_FLAG_SOURCE_IS_FILENAME);
     return parse_compile_execute(filename, MP_PARSE_FILE_INPUT, EXEC_FLAG_SOURCE_IS_FILENAME);
 }
 }
 
 
+int pyexec_file_if_exists(const char *filename) {
+    #if MICROPY_MODULE_FROZEN
+    if (mp_frozen_stat(filename) == MP_IMPORT_STAT_FILE) {
+        return pyexec_frozen_module(filename);
+    }
+    #endif
+    if (mp_import_stat(filename) != MP_IMPORT_STAT_FILE) {
+        return 1; // success (no file is the same as an empty file executing without fail)
+    }
+    return pyexec_file(filename);
+}
+
 #if MICROPY_MODULE_FROZEN
 #if MICROPY_MODULE_FROZEN
 int pyexec_frozen_module(const char *name) {
 int pyexec_frozen_module(const char *name) {
     void *frozen_data;
     void *frozen_data;

+ 1 - 0
lib/utils/pyexec.h

@@ -46,6 +46,7 @@ extern int pyexec_system_exit;
 int pyexec_raw_repl(void);
 int pyexec_raw_repl(void);
 int pyexec_friendly_repl(void);
 int pyexec_friendly_repl(void);
 int pyexec_file(const char *filename);
 int pyexec_file(const char *filename);
+int pyexec_file_if_exists(const char *filename);
 int pyexec_frozen_module(const char *name);
 int pyexec_frozen_module(const char *name);
 void pyexec_event_repl_init(void);
 void pyexec_event_repl_init(void);
 int pyexec_event_repl_process_char(int c);
 int pyexec_event_repl_process_char(int c);

+ 14 - 1
lib/utils/sys_stdio_mphal.c

@@ -3,7 +3,7 @@
  *
  *
  * The MIT License (MIT)
  * The MIT License (MIT)
  *
  *
- * Copyright (c) 2013-2017 Damien P. George
+ * Copyright (c) 2013-2019 Damien P. George
  *
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  * of this software and associated documentation files (the "Software"), to deal
@@ -85,6 +85,17 @@ STATIC mp_uint_t stdio_write(mp_obj_t self_in, const void *buf, mp_uint_t size,
     }
     }
 }
 }
 
 
+// TODO NOT IMPLEMENT STDIO_IOCTL ON RT-THREAD YET
+// STATIC mp_uint_t stdio_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
+//     (void)self_in;
+//     if (request == MP_STREAM_POLL) {
+//         return mp_hal_stdio_poll(arg);
+//     } else {
+//         *errcode = MP_EINVAL;
+//         return MP_STREAM_ERROR;
+//     }
+// }
+
 STATIC mp_obj_t stdio_obj___exit__(size_t n_args, const mp_obj_t *args) {
 STATIC mp_obj_t stdio_obj___exit__(size_t n_args, const mp_obj_t *args) {
     return mp_const_none;
     return mp_const_none;
 }
 }
@@ -112,6 +123,7 @@ STATIC MP_DEFINE_CONST_DICT(stdio_locals_dict, stdio_locals_dict_table);
 STATIC const mp_stream_p_t stdio_obj_stream_p = {
 STATIC const mp_stream_p_t stdio_obj_stream_p = {
     .read = stdio_read,
     .read = stdio_read,
     .write = stdio_write,
     .write = stdio_write,
+    // .ioctl = stdio_ioctl,
     .is_text = true,
     .is_text = true,
 };
 };
 
 
@@ -146,6 +158,7 @@ STATIC mp_uint_t stdio_buffer_write(mp_obj_t self_in, const void *buf, mp_uint_t
 STATIC const mp_stream_p_t stdio_buffer_obj_stream_p = {
 STATIC const mp_stream_p_t stdio_buffer_obj_stream_p = {
     .read = stdio_buffer_read,
     .read = stdio_buffer_read,
     .write = stdio_buffer_write,
     .write = stdio_buffer_write,
+    // .ioctl = stdio_ioctl,
     .is_text = false,
     .is_text = false,
 };
 };