├── .gitignore ├── .gitmodules ├── LICENSE ├── Makefile ├── README.md ├── architectures └── armv7-m │ ├── armv7-m.c │ ├── armv7-m.h │ ├── armv7-m_asm.S │ └── debug_cm3.h ├── boards ├── bambino210 │ └── bambino210.c ├── mbed1768 │ ├── mbed1768.c │ ├── mbed1768_asm.S │ └── mbed1768_asm.h ├── nrf52dk │ └── nrf52dk.c ├── stm32f411-blackpill │ └── stm32f411-blackpill.c └── stm32f429-disco │ └── stm32f429-disco.c ├── cmsis ├── LPC17xx │ ├── LPC17xx.h │ ├── cmsis.h │ ├── cmsis_nvic.h │ └── system_LPC17xx.h ├── LPC43xx │ ├── LPC43xx.h │ ├── cmsis.h │ ├── cmsis_nvic.h │ └── system_LPC43xx.h ├── NRF52 │ ├── cmsis.h │ ├── nrf52.h │ └── system_nrf52.h ├── STM32F411xx │ ├── cmsis.h │ ├── cmsis_nvic.h │ ├── hal_tick.h │ ├── stm32f411xe.h │ ├── stm32f4xx.h │ ├── stm32f4xx_hal_conf.h │ └── system_stm32f4xx.h ├── STM32F429xx │ ├── cmsis.h │ ├── cmsis_nvic.h │ ├── hal_tick.h │ ├── stm32f429xx.h │ ├── stm32f4xx.h │ ├── stm32f4xx_hal_conf.h │ └── system_stm32f4xx.h ├── cmsis_compiler.h ├── cmsis_gcc.h ├── cmsis_version.h ├── core_cm3.h ├── core_cm4.h ├── core_cm4_simd.h ├── core_cm7.h ├── core_cmFunc.h ├── core_cmInstr.h └── mpu_armv7.h ├── core ├── buffer.c ├── buffer.h ├── cmd_break_watch.c ├── cmd_break_watch.h ├── cmd_common.c ├── cmd_common.h ├── cmd_continue.c ├── cmd_continue.h ├── cmd_file.c ├── cmd_file.h ├── cmd_memory.c ├── cmd_memory.h ├── cmd_query.c ├── cmd_query.h ├── cmd_registers.c ├── cmd_registers.h ├── cmd_step.c ├── cmd_step.h ├── cmd_thread.c ├── cmd_thread.h ├── cmd_vcont.c ├── cmd_vcont.h ├── context.c ├── context.h ├── core.h ├── fileio.h ├── gdb_console.c ├── gdb_console.h ├── hex_convert.h ├── libc.c ├── libc.h ├── mbedsys.h ├── memory.c ├── memory.h ├── mri.c ├── mri.h ├── mri_int.h ├── packet.c ├── packet.h ├── platforms.h ├── semihost.h ├── signal.h ├── token.c ├── token.h ├── try_catch.c ├── try_catch.h └── version.h ├── deploy ├── devices ├── lpc176x │ ├── lpc176x_asm.S │ ├── lpc176x_init.c │ ├── lpc176x_init.h │ ├── lpc176x_uart.c │ └── lpc176x_uart.h ├── lpc43xx │ ├── lpc43xx_asm.S │ ├── lpc43xx_init.c │ ├── lpc43xx_init.h │ ├── lpc43xx_uart.c │ └── lpc43xx_uart.h ├── nrf52 │ ├── nrf52_init.c │ ├── nrf52_init.h │ ├── nrf52_uart.c │ └── nrf52_uart.h ├── stm32f411xx │ ├── stm32f411xx_asm.S │ ├── stm32f411xx_init.c │ ├── stm32f411xx_init.h │ ├── stm32f411xx_usart.c │ └── stm32f411xx_usart.h └── stm32f429xx │ ├── stm32f429xx_asm.S │ ├── stm32f429xx_init.c │ ├── stm32f429xx_init.h │ ├── stm32f429xx_usart.c │ └── stm32f429xx_usart.h ├── memory └── native │ └── native-mem.c ├── notes ├── mri-devices.creole ├── mri-faq.creole ├── mri-getting-started.creole ├── mri-platforms.creole ├── mri-porting.md ├── mri-pros-cons.creole └── mri-report-problem.creole ├── rtos └── rtos_weak.c ├── semihost ├── arm │ ├── semihost_arm.c │ └── semihost_arm.h ├── newlib │ ├── newlib_stubs.S │ ├── newlib_stubs.h │ └── semihost_newlib.c └── semihost.c └── tests ├── globalchk ├── mocks ├── platformMock.cpp └── platformMock.h └── tests ├── AllTests.cpp ├── bufferTests.cpp ├── cmd_break_watchTests.cpp ├── cmd_continueTests.cpp ├── cmd_fileTests.cpp ├── cmd_memoryTests.cpp ├── cmd_queryTests.cpp ├── cmd_registersTests.cpp ├── cmd_stepTests.cpp ├── cmd_threadTests.cpp ├── cmd_vcontTests.cpp ├── contextTests.cpp ├── gdb_consoleTests.cpp ├── hex_convertTests.cpp ├── libcTests.cpp ├── mriTests.cpp ├── nativememTests.cpp ├── packetTests.cpp ├── platformMockTests.cpp ├── tokenTests.cpp └── try_catchTests.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.o 3 | *.d 4 | *.a 5 | *_tests.txt 6 | *_tests 7 | *_tests_gcov 8 | gcov/ 9 | 10 | # Sublime Text Project Files 11 | *.sublime* 12 | 13 | # vim swap files 14 | *.swp 15 | *~ 16 | 17 | # VSCode project files 18 | .vscode/ -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "CppUTest"] 2 | path = CppUTest 3 | url = ../CppUTest.git 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## MRI - Monitor for Remote Inspection 2 | MRI is a debug monitor which allows the GNU debugger, GDB, to debug Cortex-M3/M4 processors. This makes it possible to debug applications running on Cortex-M devices using a full featured source level debugger with no extra hardware other than a serial connection. 3 | 4 | **Important Notes:** 5 | * MRI is meant to work with [arm-none-eabi-gdb](https://developer.arm.com/Tools%20and%20Software/GNU%20Toolchain). See notes [here](https://github.com/adamgreen/mri/pull/32#issuecomment-1221658927) about running other OS ABI versions of GDB with ARM target support. 6 | * This project just contains the sources to build the MRI debug monitor library but doesn't show how to link it into your program and make use of it. Such an example is provided by the [GCC4MBED project.](https://github.com/adamgreen/gcc4mbed) 7 | 8 | 9 | ## MRI Features 10 | * 6+ hardware breakpoints (actual number depends on device) 11 | * 4+ data watchpoints (actual number depends on device) 12 | * single stepping 13 | * runs over any of the UART ports on the device (selected when user compiles their code) 14 | * baud rate is determined at runtime (through GDB command line) on devices that support auto-baud detection 15 | * semi-host functionality: 16 | * stdout/stderr/stdin are redirected to/from the GDB console 17 | * mbed LocalFileSystem semi-host support (fopen, fwrite, fread, fseek, and fclose) - **mbed-LPC1768 only** 18 | * maintains access to mbed device's unique ethernet address - **mbed-LPC1768 only** 19 | * works with free [GNU Tools for ARM Embedded Processors](https://launchpad.net/gcc-arm-embedded) 20 | * no program binary size limitations 21 | * open source (Apache Licensed) 22 | 23 | 24 | ## Devices Supported 25 | | Device | Sample Boards | 26 | |-------------|---------------| 27 | | NXP LPC17xx | [mbed-1768](https://developer.mbed.org/platforms/mbed-LPC1768/) | 28 | | | [LPC1769 LPCXpresso Board](https://www.embeddedartists.com/products/lpcxpresso/lpc1769_xpr.php) | 29 | | NXP LPC43xx | [Micromint Bambino 210](http://www.micromint.com/index.php?option=com_content&view=article&id=199:bambino210&catid=53:products) | 30 | | STM32F429XX | [STM32F429 Discovery kit](http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/PF259090) | 31 | 32 | 33 | ## How to Clone 34 | This project uses submodules (CppUTest for unit testing). Cloning requires a few more steps to get all of the necessary 35 | code. 36 | 37 | ``` 38 | git clone git@github.com:adamgreen/mri.git 39 | cd mri 40 | git submodule init 41 | git submodule update 42 | ``` 43 | 44 | **- or -** 45 | 46 | ``` 47 | git clone --recursive git@github.com:adamgreen/mri.git 48 | ``` 49 | 50 | 51 | ## More MRI Information 52 | **[Getting started with MRI in GCC4MBED](notes/mri-getting-started.creole#installation):** Documents how to setup the mbed device and GCC4MBED project to use MRI for debugging binaries. Also provides a walk through of a debugging session with one of the GCC4MBED samples. 53 | 54 | **[Supported Host Platforms](notes/mri-platforms.creole#supported-host-platforms):** Which platforms has GDB been run on while connected to MRI. 55 | 56 | **[Supported Devices](notes/mri-devices.creole#supported-devices):** Which devices can currently be debugged with MRI. 57 | 58 | **[Why use MRI](notes/mri-pros-cons.creole):** Documents the advantages of using a debug monitor like MRI and its known limitations. 59 | 60 | **[Porting MRI](notes/mri-porting.md):** Notes on how to port MRI to new devices. 61 | 62 | **[Reporting a Problem](notes/mri-report-problem.creole#hit-a-problem):** How to extract information from your PC to show what was happening at the time a problem occurs in a MRI debugging session. 63 | 64 | **[FAQ](notes/mri-faq.creole#frequently-asked-questions)** 65 | -------------------------------------------------------------------------------- /architectures/armv7-m/armv7-m.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2022 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Routines and globals which expose the Cortex-M functionality to the mri debugger. Also describes global architecture 16 | state which is shared between cortex-m.c and cortex-m_asm.S */ 17 | #ifndef CORTEXM_H_ 18 | #define CORTEXM_H_ 19 | 20 | 21 | /* Definitions used by C and Assembler code. */ 22 | /* In some other build systems, MRI_DEVICE_HAS_FPU won't be passed in on compiler's command line so use the 23 | target Cortex-M type to determine if it has a FPU or not. 24 | */ 25 | #ifndef MRI_DEVICE_HAS_FPU 26 | #ifdef __ARM_ARCH_7EM__ 27 | #define MRI_DEVICE_HAS_FPU 1 28 | #else 29 | #define MRI_DEVICE_HAS_FPU 0 30 | #endif 31 | #endif 32 | 33 | /* Flag bits used in mriCortexMFlags global. */ 34 | #define CORTEXM_FLAGS_ACTIVE_DEBUG (1 << 0) 35 | #define CORTEXM_FLAGS_FAULT_DURING_DEBUG (1 << 1) 36 | #define CORTEXM_FLAGS_SINGLE_STEPPING (1 << 2) 37 | #define CORTEXM_FLAGS_RESTORE_PRI (1 << 3) 38 | #define CORTEXM_FLAGS_SVC_STEP (1 << 4) 39 | #define CORTEXM_FLAGS_CTRL_C (1 << 5) 40 | #define CORTEXM_FLAGS_NO_DEBUG_STACK (1 << 6) 41 | #define CORTEXM_FLAGS_PEND_FROM_FAULT (1 << 7) 42 | 43 | /* Special memory area used by the debugger for its stack so that it doesn't interfere with the task's 44 | stack contents. 45 | 46 | The stack sizes below are based on actual test runs on LPC1768 (non-FPU) and LPC4330 (FPU) based boards with a 47 | roughly 25% reservation for future growth. 48 | */ 49 | #define CORTEXM_DEBUGGER_STACK_FILL 0xDEADBEEF 50 | #if MRI_DEVICE_HAS_FPU 51 | #define CORTEXM_DEBUGGER_STACK_SIZE 113 52 | #else 53 | #define CORTEXM_DEBUGGER_STACK_SIZE 58 54 | #endif 55 | 56 | 57 | 58 | /* Definitions only required from C code. */ 59 | #if !__ASSEMBLER__ 60 | 61 | #include 62 | #include 63 | #include 64 | #include 65 | 66 | 67 | /* Give friendly names to the indices of important registers in the context scatter gather list. */ 68 | #define R0 0 69 | #define R1 1 70 | #define R2 2 71 | #define R3 3 72 | #define R7 7 73 | #define SP 13 74 | #define LR 14 75 | #define PC 15 76 | #define CPSR 16 77 | #define MSP 17 78 | #define PSP 18 79 | #define PRIMASK 19 80 | #define BASEPRI 20 81 | 82 | 83 | #if MRI_THREAD_MRI 84 | #define SPECIAL_REGISTER_COUNT 0 85 | #else 86 | #define SPECIAL_REGISTER_COUNT 6 87 | #endif 88 | #if MRI_DEVICE_HAS_FPU 89 | #define CONTEXT_SIZE (17 + 33 + SPECIAL_REGISTER_COUNT) 90 | #else 91 | #define CONTEXT_SIZE (17 + SPECIAL_REGISTER_COUNT) 92 | #endif 93 | 94 | /* NOTE: The largest buffer is required for receiving the 'G' command which receives the contents of the registers from 95 | the debugger as two hex digits per byte. Also need a character for the 'G' command itself and another 4 for the '$', 96 | '#', and 2-byte checksum. */ 97 | #define CORTEXM_PACKET_BUFFER_SIZE (1 + 2 * sizeof(uint32_t) * CONTEXT_SIZE + 4) 98 | 99 | typedef struct 100 | { 101 | MriContext context; 102 | PlatformTrapReason reason; 103 | uint32_t taskSP; 104 | uint32_t sp; 105 | uint32_t exceptionNumber; 106 | uint32_t dfsr; 107 | uint32_t hfsr; 108 | uint32_t cfsr; 109 | uint32_t mmfar; 110 | uint32_t bfar; 111 | uint32_t originalPC; 112 | uint32_t basepri; 113 | uint32_t primask; 114 | uint32_t priorityBitShift; 115 | int maxStackUsed; 116 | char packetBuffer[CORTEXM_PACKET_BUFFER_SIZE]; 117 | } CortexMState; 118 | 119 | extern uint64_t mriCortexMDebuggerStack[CORTEXM_DEBUGGER_STACK_SIZE]; 120 | extern volatile uint32_t mriCortexMFlags; 121 | extern CortexMState mriCortexMState; 122 | 123 | void mriCortexMInit(Token* pParameterTokens, uint8_t debugMonPriority, uint32_t highestExternalIrq); 124 | void mriCortexMSetPriority(uint32_t irq, uint8_t priority, uint8_t subPriority); 125 | uint8_t mriCortexMGetPriority(uint32_t irq); 126 | 127 | 128 | #endif /* !__ASSEMBLER__ */ 129 | 130 | #endif /* CORTEXM_H_ */ 131 | -------------------------------------------------------------------------------- /boards/bambino210/bambino210.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Routines which expose Micromint Bambino210 specific functionality to the mri debugger. */ 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | 23 | void Platform_Init(Token* pParameterTokens) 24 | { 25 | mriLpc43xx_Init(pParameterTokens); 26 | } 27 | 28 | 29 | const uint8_t* Platform_GetUid(void) 30 | { 31 | return NULL; 32 | } 33 | 34 | 35 | size_t Platform_GetUidSize(void) 36 | { 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /boards/mbed1768/mbed1768.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Routines which expose mbed1768 specific functionality to the mri debugger. */ 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include "mbed1768_asm.h" 22 | 23 | #define FLAGS_MBED_DETECTED 1 24 | 25 | #define MBED1768_UID_SIZE 36 26 | 27 | typedef struct 28 | { 29 | uint32_t flags; 30 | uint8_t mbedUid[MBED1768_UID_SIZE]; 31 | } Mbed1768State; 32 | 33 | static Mbed1768State g_state; 34 | 35 | 36 | static void initModuleState(void); 37 | static void disableMbedInterface(void); 38 | static void fetchAndSaveMbedUid(void); 39 | static void setMbedDetectedFlag(void); 40 | void Platform_Init(Token* pParameterTokens) 41 | { 42 | initModuleState(); 43 | 44 | __try 45 | { 46 | __throwing_func( disableMbedInterface() ); 47 | __throwing_func( mriLpc176x_Init(pParameterTokens) ); 48 | } 49 | __catch 50 | { 51 | __rethrow; 52 | } 53 | } 54 | 55 | static void initModuleState(void) 56 | { 57 | static const uint8_t defaultMbedUid[MBED1768_UID_SIZE] = "101000000000000000000002F7F00000\0\0\0"; 58 | 59 | g_state.flags = 0; 60 | mri_memcpy(g_state.mbedUid, defaultMbedUid, sizeof(g_state.mbedUid)); 61 | } 62 | 63 | static void disableMbedInterface(void) 64 | { 65 | static const uint32_t debugDetachWaitTimeout = 5000; 66 | 67 | /* mbed interface exists on JTAG bus so if no debugger, then no potential for mbed interface. */ 68 | if (!isDebuggerAttached()) 69 | return; 70 | 71 | fetchAndSaveMbedUid(); 72 | mriDisableMbed(); 73 | 74 | __try 75 | waitForDebuggerToDetach(debugDetachWaitTimeout); 76 | __catch 77 | __rethrow; 78 | 79 | setMbedDetectedFlag(); 80 | } 81 | 82 | static void fetchAndSaveMbedUid(void) 83 | { 84 | mriGetMbedUid(g_state.mbedUid); 85 | } 86 | 87 | static void setMbedDetectedFlag(void) 88 | { 89 | g_state.flags |= FLAGS_MBED_DETECTED; 90 | } 91 | 92 | 93 | const uint8_t* Platform_GetUid(void) 94 | { 95 | return g_state.mbedUid; 96 | } 97 | 98 | 99 | size_t Platform_GetUidSize(void) 100 | { 101 | return sizeof(g_state.mbedUid); 102 | } 103 | 104 | 105 | int mriMbed1768_IsMbedDevice(void) 106 | { 107 | return (int)(g_state.flags & FLAGS_MBED_DETECTED); 108 | } 109 | -------------------------------------------------------------------------------- /boards/mbed1768/mbed1768_asm.S: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2011 ARM Limited. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | */ 21 | /* The mriDisableMbed() and mriGetMbedUid() routines were extracted from 22 | the mbed SDK libraries to allow the use of the MRI debugger on mbed devices 23 | without requiring the mbed SDK. The assembly language code itself 24 | was written by the mbed team at ARM Limited but the function naming and 25 | commenting were done by Adam Green (https://github.com/adamgreen/) in 26 | 2012. 27 | */ 28 | .text 29 | .code 16 30 | .syntax unified 31 | 32 | .global mriDisableMbed 33 | .thumb_func 34 | /* extern "C" int mriDisableMbed(void); 35 | Attempts to disable the debug interface on the mbed device. 36 | 37 | Returns -1 on failure. 38 | */ 39 | mriDisableMbed: 40 | sub sp, #8 // Allocate 4 byte parameter block on stack (round up to maintain 8 byte alignment.) 41 | add r1, sp, #4 // R1 = pointer to 4 byte parameter block on stack. 42 | movw r0, #261 // R0 = semi-host id for disabling JTAG port use from mbed interface chip. 43 | bkpt 0xab // Semi-host breakpoint. 44 | cmp r0, #0 // Was the call successful (returned 0 in R0)? 45 | ite eq 46 | ldreq r0, [sp, #4] // If so load R0 with the first word from parameter block. 47 | movne.w r0, #-1 // If not then set R0 to -1. 48 | add sp, #8 // Restore stack pointer 49 | bx lr // and return to caller. 50 | 51 | 52 | .global mriGetMbedUid 53 | .thumb_func 54 | /* extern "C" int mriGetMbedUid(uint8_t* pOutputBuffer); 55 | Reads the unique device id from the mbed interface chip. 56 | 57 | Returns -1 on failure. 58 | */ 59 | mriGetMbedUid: 60 | sub sp, #8 // Allocate 8 byte parameter block on stack. 61 | str r0, [sp, #0] // param[0] = pOutputBuffer Pointer to output buffer for UID. 62 | movs r0, #33 63 | str r0, [sp, #4] // param[1] = 33 Size of UID output buffer in bytes. 64 | mov r1, sp // R1 = pointer to 8 byte parameter block on stack. 65 | movw r0, #257 // R0 = semi-host id for fetching mbed UID. 66 | bkpt 0xab // Semi-host breakpoint. 67 | add sp, #8 // Restore stack pointer 68 | bx lr // and return to caller. 69 | -------------------------------------------------------------------------------- /boards/mbed1768/mbed1768_asm.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2012 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Assembly Language routines which expose mbed1768 board specifc functionality to the mri debugger. */ 16 | #ifndef MBED1768_ASM_H_ 17 | #define MBED1768_ASM_H_ 18 | 19 | int mriDisableMbed(void); 20 | int mriGetMbedUid(uint8_t* pOutputBuffer); 21 | 22 | #endif /* MBED1768_ASM_H_ */ 23 | -------------------------------------------------------------------------------- /boards/nrf52dk/nrf52dk.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Routines which expose nRF52-DK specific functionality to the mri debugger. */ 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | 22 | static const char g_memoryMapXml[] = "" 23 | "" 24 | "" 25 | " 0x1000" 26 | " " 27 | ""; 28 | 29 | 30 | void Platform_Init(Token* pParameterTokens) 31 | { 32 | mriNRF52_Init(pParameterTokens); 33 | } 34 | 35 | 36 | const uint8_t* Platform_GetUid(void) 37 | { 38 | return NULL; 39 | } 40 | 41 | 42 | size_t Platform_GetUidSize(void) 43 | { 44 | return 0; 45 | } 46 | 47 | 48 | size_t Platform_GetDeviceMemoryMapXmlSize(void) 49 | { 50 | return sizeof(g_memoryMapXml) - 1; 51 | } 52 | 53 | 54 | const char* Platform_GetDeviceMemoryMapXml(void) 55 | { 56 | return g_memoryMapXml; 57 | } 58 | -------------------------------------------------------------------------------- /boards/stm32f411-blackpill/stm32f411-blackpill.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 Adam Green (https://github.com/adamgreen/) 2 | Copyright 2015 Chang,Jia-Rung (https://github.com/JaredCJR) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /* Routines which expose STM32F411 Blackpill specific functionality to the mri debugger. */ 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | 24 | void Platform_Init(Token* pParameterTokens) 25 | { 26 | mriStm32f411xx_Init(pParameterTokens); 27 | } 28 | 29 | 30 | const uint8_t* Platform_GetUid(void) 31 | { 32 | return NULL; 33 | } 34 | 35 | 36 | size_t Platform_GetUidSize(void) 37 | { 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /boards/stm32f429-disco/stm32f429-disco.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 Adam Green (https://github.com/adamgreen/) 2 | Copyright 2015 Chang,Jia-Rung (https://github.com/JaredCJR) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /* Routines which expose STM32F429 Discovery specific functionality to the mri debugger. */ 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | 24 | void Platform_Init(Token* pParameterTokens) 25 | { 26 | mriStm32f429xx_Init(pParameterTokens); 27 | } 28 | 29 | 30 | const uint8_t* Platform_GetUid(void) 31 | { 32 | return NULL; 33 | } 34 | 35 | 36 | size_t Platform_GetUidSize(void) 37 | { 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /cmsis/LPC17xx/cmsis.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library - CMSIS 2 | * Copyright (C) 2009-2011 ARM Limited. All rights reserved. 3 | * 4 | * A generic CMSIS include header, pulling in LPC1768 specifics 5 | */ 6 | 7 | #ifndef MBED_CMSIS_H 8 | #define MBED_CMSIS_H 9 | 10 | #include "LPC17xx.h" 11 | #include "cmsis_nvic.h" 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /cmsis/LPC17xx/cmsis_nvic.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * CMSIS-style functionality to support dynamic vectors 3 | ******************************************************************************* 4 | * Copyright (c) 2011 ARM Limited. All rights reserved. 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 3. Neither the name of ARM Limited nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | ******************************************************************************* 30 | */ 31 | 32 | #ifndef MBED_CMSIS_NVIC_H 33 | #define MBED_CMSIS_NVIC_H 34 | 35 | #include "cmsis.h" 36 | 37 | #define NVIC_NUM_VECTORS (16 + 33) 38 | #define NVIC_USER_IRQ_OFFSET 16 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector); 45 | uint32_t NVIC_GetVector(IRQn_Type IRQn); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /cmsis/LPC17xx/system_LPC17xx.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * @file: system_LPC17xx.h 3 | * @purpose: CMSIS Cortex-M3 Device Peripheral Access Layer Header File 4 | * for the NXP LPC17xx Device Series 5 | * @version: V1.02 6 | * @date: 27. July 2009 7 | *---------------------------------------------------------------------------- 8 | * 9 | * Copyright (C) 2009 ARM Limited. All rights reserved. 10 | * 11 | * ARM Limited (ARM) is supplying this software for use with Cortex-M3 12 | * processor based microcontrollers. This file can be freely distributed 13 | * within development tools that are supporting such ARM based processors. 14 | * 15 | * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED 16 | * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF 17 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. 18 | * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR 19 | * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. 20 | * 21 | ******************************************************************************/ 22 | 23 | 24 | #ifndef __SYSTEM_LPC17xx_H 25 | #define __SYSTEM_LPC17xx_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 32 | 33 | 34 | /** 35 | * Initialize the system 36 | * 37 | * @param none 38 | * @return none 39 | * 40 | * @brief Setup the microcontroller system. 41 | * Initialize the System and update the SystemCoreClock variable. 42 | */ 43 | extern void SystemInit (void); 44 | 45 | /** 46 | * Update SystemCoreClock variable 47 | * 48 | * @param none 49 | * @return none 50 | * 51 | * @brief Updates the SystemCoreClock with current core Clock 52 | * retrieved from cpu registers. 53 | */ 54 | extern void SystemCoreClockUpdate (void); 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif /* __SYSTEM_LPC17xx_H */ 61 | -------------------------------------------------------------------------------- /cmsis/LPC43xx/cmsis.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library - CMSIS 2 | * Copyright (C) 2009-2011 ARM Limited. All rights reserved. 3 | * 4 | * A generic CMSIS include header, pulling in LPC43xx specifics 5 | * 6 | * Ported to NXP LPC43XX by Micromint USA 7 | */ 8 | 9 | #ifndef MBED_CMSIS_H 10 | #define MBED_CMSIS_H 11 | 12 | #include "LPC43xx.h" 13 | #include "cmsis_nvic.h" 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /cmsis/LPC43xx/cmsis_nvic.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * CMSIS-style functionality to support dynamic vectors 3 | ******************************************************************************* 4 | * Copyright (c) 2011 ARM Limited. All rights reserved. 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 3. Neither the name of ARM Limited nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | ******************************************************************************* 30 | */ 31 | 32 | #ifndef MBED_CMSIS_NVIC_H 33 | #define MBED_CMSIS_NVIC_H 34 | 35 | #define NVIC_NUM_VECTORS (16 + 53) // CORE + MCU Peripherals 36 | #define NVIC_USER_IRQ_OFFSET 16 37 | 38 | #include "cmsis.h" 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector); 45 | uint32_t NVIC_GetVector(IRQn_Type IRQn); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /cmsis/LPC43xx/system_LPC43xx.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @brief LPC43xx/LPC18xx mcu header 3 | * 4 | * Copyright(C) NXP Semiconductors, 2012 5 | * All rights reserved. 6 | * 7 | * Software that is described herein is for illustrative purposes only 8 | * which provides customers with programming information regarding the 9 | * LPC products. This software is supplied "AS IS" without any warranties of 10 | * any kind, and NXP Semiconductors and its licensor disclaim any and 11 | * all warranties, express or implied, including all implied warranties of 12 | * merchantability, fitness for a particular purpose and non-infringement of 13 | * intellectual property rights. NXP Semiconductors assumes no responsibility 14 | * or liability for the use of the software, conveys no license or rights under any 15 | * patent, copyright, mask work right, or any other intellectual property rights in 16 | * or to any products. NXP Semiconductors reserves the right to make changes 17 | * in the software without notification. NXP Semiconductors also makes no 18 | * representation or warranty that such application will be suitable for the 19 | * specified use without further testing or modification. 20 | * 21 | * Permission to use, copy, modify, and distribute this software and its 22 | * documentation is hereby granted, under NXP Semiconductors' and its 23 | * licensor's relevant copyrights in the software, without fee, provided that it 24 | * is used in conjunction with NXP Semiconductors microcontrollers. This 25 | * copyright, permission, and disclaimer notice must appear in all copies of 26 | * this code. 27 | */ 28 | 29 | #ifndef __SYSTEM_LPC43XX_H 30 | #define __SYSTEM_LPC43XX_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* System initialization options */ 37 | #define PIN_SETUP 1 /* Configure pins during initialization */ 38 | #define CLOCK_SETUP 1 /* Configure clocks during initialization */ 39 | #define MEMORY_SETUP 0 /* Configure external memory during init */ 40 | #define SPIFI_INIT 1 /* Initialize SPIFI */ 41 | 42 | /* Crystal frequency into device */ 43 | #define CRYSTAL_MAIN_FREQ_IN 12000000 44 | 45 | /* Crystal frequency into device for RTC/32K input */ 46 | #define CRYSTAL_32K_FREQ_IN 32768 47 | 48 | /* Default CPU clock frequency */ 49 | #if defined(CHIP_LPC43XX) 50 | #define MAX_CLOCK_FREQ (204000000) 51 | #else 52 | #define MAX_CLOCK_FREQ (180000000) 53 | #endif 54 | 55 | #if defined(__FPU_PRESENT) && __FPU_PRESENT == 1 56 | /* FPU declarations */ 57 | #define LPC_CPACR 0xE000ED88 58 | 59 | #define SCB_MVFR0 0xE000EF40 60 | #define SCB_MVFR0_RESET 0x10110021 61 | 62 | #define SCB_MVFR1 0xE000EF44 63 | #define SCB_MVFR1_RESET 0x11000011 64 | 65 | #if defined(__ARMCC_VERSION) 66 | void fpuInit(void) __attribute__ ((section("BOOTSTRAP_CODE"))); 67 | #else 68 | extern void fpuInit(void); 69 | #endif 70 | #endif 71 | 72 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 73 | 74 | /** 75 | * Initialize the system 76 | * 77 | * @param none 78 | * @return none 79 | * 80 | * @brief Setup the microcontroller system. 81 | * Initialize the System and update the SystemCoreClock variable. 82 | */ 83 | extern void SystemInit (void); 84 | extern void SystemCoreClockUpdate(void); 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif 89 | 90 | #endif /* __SYSTEM_LPC43XX_H */ 91 | -------------------------------------------------------------------------------- /cmsis/NRF52/cmsis.h: -------------------------------------------------------------------------------- 1 | #ifndef CMSIS_H_ 2 | #define CMSIS_H_ 3 | 4 | #include "nrf52.h" 5 | 6 | #endif /* CMSIS_H_ */ 7 | -------------------------------------------------------------------------------- /cmsis/NRF52/system_nrf52.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012 ARM LIMITED 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 10 | * * Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * * Neither the name of ARM nor the names of its contributors may be used to 15 | * endorse or promote products derived from this software without specific 16 | * prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | */ 30 | 31 | #ifndef SYSTEM_NRF52_H 32 | #define SYSTEM_NRF52_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include 39 | 40 | 41 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 42 | 43 | /** 44 | * Initialize the system 45 | * 46 | * @param none 47 | * @return none 48 | * 49 | * @brief Setup the microcontroller system. 50 | * Initialize the System and update the SystemCoreClock variable. 51 | */ 52 | extern void SystemInit (void); 53 | 54 | /** 55 | * Update SystemCoreClock variable 56 | * 57 | * @param none 58 | * @return none 59 | * 60 | * @brief Updates the SystemCoreClock with current core Clock 61 | * retrieved from cpu registers. 62 | */ 63 | extern void SystemCoreClockUpdate (void); 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif /* SYSTEM_NRF52_H */ 70 | -------------------------------------------------------------------------------- /cmsis/STM32F411xx/cmsis.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * A generic CMSIS include header 3 | ******************************************************************************* 4 | * Copyright (c) 2014, STMicroelectronics 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | ******************************************************************************* 30 | */ 31 | 32 | #ifndef MBED_CMSIS_H 33 | #define MBED_CMSIS_H 34 | 35 | #include "stm32f4xx.h" 36 | #include "cmsis_nvic.h" 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /cmsis/STM32F411xx/cmsis_nvic.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * CMSIS-style functionality to support dynamic vectors 3 | ******************************************************************************* 4 | * Copyright (c) 2014, STMicroelectronics 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | ******************************************************************************* 30 | */ 31 | 32 | #ifndef MBED_CMSIS_NVIC_H 33 | #define MBED_CMSIS_NVIC_H 34 | 35 | // STM32F411CE 36 | // CORE: 16 vectors = 64 bytes from 0x00 to 0x3F 37 | // MCU Peripherals: 86 vectors = 344 bytes from 0x40 to 0x198 38 | // Total: 102 vectors = 408 bytes (0x198) to be reserved in RAM 39 | #define NVIC_NUM_VECTORS 102 40 | #define NVIC_USER_IRQ_OFFSET 16 41 | 42 | #include "cmsis.h" 43 | 44 | #ifdef __cplusplus 45 | extern "C" { 46 | #endif 47 | 48 | void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector); 49 | uint32_t NVIC_GetVector(IRQn_Type IRQn); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /cmsis/STM32F411xx/hal_tick.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file hal_tick.h 4 | * @author MCD Application Team 5 | * @brief Initialization of HAL tick 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© COPYRIGHT(c) 2014 STMicroelectronics

10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************** 34 | */ 35 | #ifndef __HAL_TICK_H 36 | #define __HAL_TICK_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | #include "stm32f4xx.h" 43 | #include "cmsis_nvic.h" 44 | 45 | #define TIM_MST TIM5 46 | #define TIM_MST_IRQ TIM5_IRQn 47 | #define TIM_MST_RCC __TIM5_CLK_ENABLE() 48 | 49 | #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() 50 | #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() 51 | 52 | #define HAL_TICK_DELAY (1000) // 1 ms 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif // __HAL_TICK_H 59 | 60 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 61 | -------------------------------------------------------------------------------- /cmsis/STM32F411xx/system_stm32f4xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f4xx.h 4 | * @author MCD Application Team 5 | * @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /** @addtogroup CMSIS 20 | * @{ 21 | */ 22 | 23 | /** @addtogroup stm32f4xx_system 24 | * @{ 25 | */ 26 | 27 | /** 28 | * @brief Define to prevent recursive inclusion 29 | */ 30 | #ifndef __SYSTEM_STM32F4XX_H 31 | #define __SYSTEM_STM32F4XX_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /** @addtogroup STM32F4xx_System_Includes 38 | * @{ 39 | */ 40 | 41 | /** 42 | * @} 43 | */ 44 | 45 | 46 | /** @addtogroup STM32F4xx_System_Exported_types 47 | * @{ 48 | */ 49 | /* This variable is updated in three ways: 50 | 1) by calling CMSIS function SystemCoreClockUpdate() 51 | 2) by calling HAL API function HAL_RCC_GetSysClockFreq() 52 | 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency 53 | Note: If you use this function to configure the system clock; then there 54 | is no need to call the 2 first functions listed above, since SystemCoreClock 55 | variable is updated automatically. 56 | */ 57 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 58 | 59 | extern const uint8_t AHBPrescTable[16]; /*!< AHB prescalers table values */ 60 | extern const uint8_t APBPrescTable[8]; /*!< APB prescalers table values */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @addtogroup STM32F4xx_System_Exported_Constants 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @addtogroup STM32F4xx_System_Exported_Macros 75 | * @{ 76 | */ 77 | 78 | /** 79 | * @} 80 | */ 81 | 82 | /** @addtogroup STM32F4xx_System_Exported_Functions 83 | * @{ 84 | */ 85 | 86 | extern void SystemInit(void); 87 | extern void SystemCoreClockUpdate(void); 88 | /** 89 | * @} 90 | */ 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif /*__SYSTEM_STM32F4XX_H */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /** 103 | * @} 104 | */ 105 | -------------------------------------------------------------------------------- /cmsis/STM32F429xx/cmsis.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * A generic CMSIS include header 3 | ******************************************************************************* 4 | * Copyright (c) 2014, STMicroelectronics 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | ******************************************************************************* 30 | */ 31 | 32 | #ifndef MBED_CMSIS_H 33 | #define MBED_CMSIS_H 34 | 35 | #include "stm32f4xx.h" 36 | #include "cmsis_nvic.h" 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /cmsis/STM32F429xx/cmsis_nvic.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * CMSIS-style functionality to support dynamic vectors 3 | ******************************************************************************* 4 | * Copyright (c) 2014, STMicroelectronics 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | ******************************************************************************* 30 | */ 31 | 32 | #ifndef MBED_CMSIS_NVIC_H 33 | #define MBED_CMSIS_NVIC_H 34 | 35 | // STM32F429ZI 36 | // CORE: 16 vectors = 64 bytes from 0x00 to 0x3F 37 | // MCU Peripherals: 91 vectors = 364 bytes from 0x40 to 0x1AB 38 | // Total: 107 vectors = 428 bytes (0x1AC) to be reserved in RAM 39 | #define NVIC_NUM_VECTORS 107 40 | #define NVIC_USER_IRQ_OFFSET 16 41 | 42 | #include "cmsis.h" 43 | 44 | #ifdef __cplusplus 45 | extern "C" { 46 | #endif 47 | 48 | void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector); 49 | uint32_t NVIC_GetVector(IRQn_Type IRQn); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /cmsis/STM32F429xx/hal_tick.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file hal_tick.h 4 | * @author MCD Application Team 5 | * @brief Initialization of HAL tick 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© COPYRIGHT(c) 2014 STMicroelectronics

10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************** 34 | */ 35 | #ifndef __HAL_TICK_H 36 | #define __HAL_TICK_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | #include "stm32f4xx.h" 43 | #include "cmsis_nvic.h" 44 | 45 | #define TIM_MST TIM5 46 | #define TIM_MST_IRQ TIM5_IRQn 47 | #define TIM_MST_RCC __TIM5_CLK_ENABLE() 48 | 49 | #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() 50 | #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() 51 | 52 | #define HAL_TICK_DELAY (1000) // 1 ms 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif // __HAL_TICK_H 59 | 60 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 61 | -------------------------------------------------------------------------------- /cmsis/STM32F429xx/stm32f429xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adamgreen/mri/6f56f9017be87d2571e5881dcfee3ed147f7f342/cmsis/STM32F429xx/stm32f429xx.h -------------------------------------------------------------------------------- /cmsis/STM32F429xx/stm32f4xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adamgreen/mri/6f56f9017be87d2571e5881dcfee3ed147f7f342/cmsis/STM32F429xx/stm32f4xx.h -------------------------------------------------------------------------------- /cmsis/STM32F429xx/system_stm32f4xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f4xx.h 4 | * @author MCD Application Team 5 | * @version V2.3.2 6 | * @date 26-June-2015 7 | * @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2015 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /** @addtogroup CMSIS 39 | * @{ 40 | */ 41 | 42 | /** @addtogroup stm32f4xx_system 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @brief Define to prevent recursive inclusion 48 | */ 49 | #ifndef __SYSTEM_STM32F4XX_H 50 | #define __SYSTEM_STM32F4XX_H 51 | 52 | #ifdef __cplusplus 53 | extern "C" { 54 | #endif 55 | 56 | /** @addtogroup STM32F4xx_System_Includes 57 | * @{ 58 | */ 59 | 60 | /** 61 | * @} 62 | */ 63 | 64 | 65 | /** @addtogroup STM32F4xx_System_Exported_types 66 | * @{ 67 | */ 68 | /* This variable is updated in three ways: 69 | 1) by calling CMSIS function SystemCoreClockUpdate() 70 | 2) by calling HAL API function HAL_RCC_GetSysClockFreq() 71 | 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency 72 | Note: If you use this function to configure the system clock; then there 73 | is no need to call the 2 first functions listed above, since SystemCoreClock 74 | variable is updated automatically. 75 | */ 76 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 77 | 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /** @addtogroup STM32F4xx_System_Exported_Constants 84 | * @{ 85 | */ 86 | 87 | /** 88 | * @} 89 | */ 90 | 91 | /** @addtogroup STM32F4xx_System_Exported_Macros 92 | * @{ 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | 99 | /** @addtogroup STM32F4xx_System_Exported_Functions 100 | * @{ 101 | */ 102 | 103 | extern void SystemInit(void); 104 | extern void SystemCoreClockUpdate(void); 105 | extern void SetSysClock(void); 106 | /** 107 | * @} 108 | */ 109 | 110 | #ifdef __cplusplus 111 | } 112 | #endif 113 | 114 | #endif /*__SYSTEM_STM32F4XX_H */ 115 | 116 | /** 117 | * @} 118 | */ 119 | 120 | /** 121 | * @} 122 | */ 123 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 124 | -------------------------------------------------------------------------------- /cmsis/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.2 5 | * @date 19. April 2017 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2017 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 1U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /core/buffer.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* 'Class' which represents a text buffer. Has routines to both extract and inject strings of various types into the 16 | buffer while verifying that no overflow takes place. */ 17 | #ifndef BUFFER_H_ 18 | #define BUFFER_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | typedef struct 25 | { 26 | char* pStart; 27 | char* pEnd; 28 | char* pCurrent; 29 | } Buffer; 30 | 31 | /* Real name of functions are in mri namespace. */ 32 | void mriBuffer_Init(Buffer* pBuffer, char* pBufferStart, size_t bufferSize); 33 | void mriBuffer_Reset(Buffer* pBuffer); 34 | void mriBuffer_SetEndOfBuffer(Buffer* pBuffer); 35 | void mriBuffer_Advance(Buffer* pBuffer, size_t amount); 36 | size_t mriBuffer_BytesLeft(Buffer* pBuffer); 37 | int mriBuffer_OverrunDetected(Buffer* pBuffer); 38 | size_t mriBuffer_GetLength(Buffer* pBuffer); 39 | char* mriBuffer_GetArray(Buffer* pBuffer); 40 | void mriBuffer_WriteChar(Buffer* pBuffer, char character); 41 | char mriBuffer_ReadChar(Buffer* pBuffer); 42 | void mriBuffer_WriteByteAsHex(Buffer* pBuffer, uint8_t byte); 43 | uint8_t mriBuffer_ReadByteAsHex(Buffer* pBuffer); 44 | void mriBuffer_WriteString(Buffer* pBuffer, const char* pString); 45 | void mriBuffer_WriteSizedString(Buffer* pBuffer, const char* pString, size_t length); 46 | size_t mriBuffer_WriteStringAsHex(Buffer* pBuffer, const char* pString); 47 | size_t mriBuffer_WriteSizedStringAsHex(Buffer* pBuffer, const char* pString, size_t length); 48 | uintmri_t mriBuffer_ReadUIntegerAsHex(Buffer* pBuffer); 49 | void mriBuffer_WriteUIntegerAsHex(Buffer* pBuffer, uintmri_t value); 50 | intmri_t mriBuffer_ReadIntegerAsHex(Buffer* pBuffer); 51 | void mriBuffer_WriteIntegerAsHex(Buffer* pBuffer, intmri_t value); 52 | int mriBuffer_IsNextCharEqualTo(Buffer* pBuffer, char thisChar); 53 | int mriBuffer_MatchesString(Buffer* pBuffer, const char* pString, size_t stringLength); 54 | int mriBuffer_MatchesHexString(Buffer* pBuffer, const char* pString, size_t stringLength); 55 | 56 | /* Macroes which allow code to drop the mri namespace prefix. */ 57 | #define Buffer_Init mriBuffer_Init 58 | #define Buffer_Reset mriBuffer_Reset 59 | #define Buffer_SetEndOfBuffer mriBuffer_SetEndOfBuffer 60 | #define Buffer_Advance mriBuffer_Advance 61 | #define Buffer_BytesLeft mriBuffer_BytesLeft 62 | #define Buffer_OverrunDetected mriBuffer_OverrunDetected 63 | #define Buffer_GetLength mriBuffer_GetLength 64 | #define Buffer_GetArray mriBuffer_GetArray 65 | #define Buffer_WriteChar mriBuffer_WriteChar 66 | #define Buffer_ReadChar mriBuffer_ReadChar 67 | #define Buffer_WriteByteAsHex mriBuffer_WriteByteAsHex 68 | #define Buffer_ReadByteAsHex mriBuffer_ReadByteAsHex 69 | #define Buffer_WriteString mriBuffer_WriteString 70 | #define Buffer_WriteSizedString mriBuffer_WriteSizedString 71 | #define Buffer_WriteStringAsHex mriBuffer_WriteStringAsHex 72 | #define Buffer_WriteSizedStringAsHex mriBuffer_WriteSizedStringAsHex 73 | #define Buffer_ReadUIntegerAsHex mriBuffer_ReadUIntegerAsHex 74 | #define Buffer_WriteUIntegerAsHex mriBuffer_WriteUIntegerAsHex 75 | #define Buffer_ReadIntegerAsHex mriBuffer_ReadIntegerAsHex 76 | #define Buffer_WriteIntegerAsHex mriBuffer_WriteIntegerAsHex 77 | #define Buffer_IsNextCharEqualTo mriBuffer_IsNextCharEqualTo 78 | #define Buffer_MatchesString mriBuffer_MatchesString 79 | #define Buffer_MatchesHexString mriBuffer_MatchesHexString 80 | 81 | #endif /* BUFFER_H_ */ 82 | -------------------------------------------------------------------------------- /core/cmd_break_watch.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2012 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Handlers for gdb breakpoint and watchpoint commands. */ 16 | #ifndef CMD_BREAK_WATCH_H_ 17 | #define CMD_BREAK_WATCH_H_ 18 | 19 | #include 20 | 21 | /* Real name of functions are in mri namespace. */ 22 | uint32_t mriCmd_HandleBreakpointWatchpointSetCommand(void); 23 | uint32_t mriCmd_HandleBreakpointWatchpointRemoveCommand(void); 24 | 25 | /* Macroes which allow code to drop the mri namespace prefix. */ 26 | #define HandleBreakpointWatchpointSetCommand mriCmd_HandleBreakpointWatchpointSetCommand 27 | #define HandleBreakpointWatchpointRemoveCommand mriCmd_HandleBreakpointWatchpointRemoveCommand 28 | 29 | #endif /* CMD_BREAK_WATCH_H_ */ 30 | -------------------------------------------------------------------------------- /core/cmd_common.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Common functionality shared between gdb command handlers in mri. */ 16 | #include 17 | 18 | 19 | void ReadAddressAndLengthArguments(Buffer* pBuffer, AddressLength* pArguments) 20 | { 21 | __try 22 | { 23 | __throwing_func( pArguments->address = ReadUIntegerArgument(pBuffer) ); 24 | __throwing_func( ThrowIfNextCharIsNotEqualTo(pBuffer, ',') ); 25 | __throwing_func( pArguments->length = ReadUIntegerArgument(pBuffer) ); 26 | } 27 | __catch 28 | { 29 | __rethrow; 30 | } 31 | } 32 | 33 | 34 | void ReadAddressAndLengthArgumentsWithColon(Buffer* pBuffer, AddressLength* pArguments) 35 | { 36 | __try 37 | { 38 | __throwing_func( ReadAddressAndLengthArguments(pBuffer, pArguments) ); 39 | __throwing_func( ThrowIfNextCharIsNotEqualTo(pBuffer, ':') ); 40 | } 41 | __catch 42 | { 43 | __rethrow; 44 | } 45 | } 46 | 47 | 48 | uintmri_t ReadUIntegerArgument(Buffer* pBuffer) 49 | { 50 | uintmri_t value; 51 | 52 | __try 53 | value = Buffer_ReadUIntegerAsHex(pBuffer); 54 | __catch 55 | __rethrow_and_return(0); 56 | 57 | return value; 58 | } 59 | 60 | 61 | void ThrowIfNextCharIsNotEqualTo(Buffer* pBuffer, char thisChar) 62 | { 63 | if (!Buffer_IsNextCharEqualTo(pBuffer, thisChar)) 64 | __throw(invalidArgumentException); 65 | } 66 | -------------------------------------------------------------------------------- /core/cmd_common.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Common functionality shared between gdb command handlers in mri. */ 16 | #ifndef CMD_COMMON_H_ 17 | #define CMD_COMMON_H_ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | /* The bits that can be set in the return value from a command handler to indicate if the caller should return 25 | immediately or send the prepared response back to gdb. It also indicates whether program execution should be 26 | resumed for commands like continue and single step. */ 27 | #define HANDLER_RETURN_RESUME_PROGRAM (1 << 0) 28 | #define HANDLER_RETURN_RETURN_IMMEDIATELY (1 << 1) 29 | #define HANDLER_RETURN_SKIPPED_OVER_BREAK (1 << 2) 30 | #define HANDLER_RETURN_HANDLED (1 << 31) 31 | 32 | typedef struct 33 | { 34 | uintmri_t address; 35 | uintmri_t length; 36 | } AddressLength; 37 | 38 | /* Real name of functions are in mri namespace. */ 39 | __throws void mriCmd_ReadAddressAndLengthArguments(Buffer* pBuffer, AddressLength* pArguments); 40 | __throws void mriCmd_ReadAddressAndLengthArgumentsWithColon(Buffer* pBuffer, AddressLength* pArguments); 41 | __throws uintmri_t mriCmd_ReadUIntegerArgument(Buffer* pBuffer); 42 | __throws void mriCmd_ThrowIfNextCharIsNotEqualTo(Buffer* pBuffer, char thisChar); 43 | 44 | /* Macroes which allow code to drop the mri namespace prefix. */ 45 | #define ReadAddressAndLengthArguments mriCmd_ReadAddressAndLengthArguments 46 | #define ReadAddressAndLengthArgumentsWithColon mriCmd_ReadAddressAndLengthArgumentsWithColon 47 | #define ReadUIntegerArgument mriCmd_ReadUIntegerArgument 48 | #define ThrowIfNextCharIsNotEqualTo mriCmd_ThrowIfNextCharIsNotEqualTo 49 | 50 | #endif /* CMD_COMMON_H_ */ 51 | -------------------------------------------------------------------------------- /core/cmd_continue.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Handler for continue gdb command. */ 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | 24 | static int shouldSkipHardcodedBreakpoint(void); 25 | static int isCurrentInstructionHardcodedBreakpoint(void); 26 | uint32_t ContinueExecution(int setPC, uint32_t newPC) 27 | { 28 | if (Platform_RtosIsSetThreadStateSupported()) 29 | Platform_RtosSetThreadState(MRI_PLATFORM_ALL_THREADS, MRI_PLATFORM_THREAD_THAWED); 30 | uint32_t returnValue = SkipHardcodedBreakpoint(); 31 | if (setPC) 32 | Platform_SetProgramCounter(newPC); 33 | return (returnValue | HANDLER_RETURN_RESUME_PROGRAM | HANDLER_RETURN_RETURN_IMMEDIATELY); 34 | } 35 | 36 | uint32_t SkipHardcodedBreakpoint(void) 37 | { 38 | if (shouldSkipHardcodedBreakpoint()) 39 | { 40 | Platform_AdvanceProgramCounterToNextInstruction(); 41 | return HANDLER_RETURN_SKIPPED_OVER_BREAK; 42 | } 43 | 44 | return 0; 45 | } 46 | 47 | static int shouldSkipHardcodedBreakpoint(void) 48 | { 49 | return !Platform_WasProgramCounterModifiedByUser() && isCurrentInstructionHardcodedBreakpoint(); 50 | } 51 | 52 | static int isCurrentInstructionHardcodedBreakpoint(void) 53 | { 54 | return Platform_TypeOfCurrentInstruction() == MRI_PLATFORM_INSTRUCTION_HARDCODED_BREAKPOINT; 55 | } 56 | 57 | 58 | /* Handle the 'c' command which is sent from gdb to tell the debugger to continue execution of the currently halted 59 | program. 60 | 61 | Command Format: cAAAAAAAA 62 | Response Format: Blank until the next exception, at which time a 'T' stop response packet will be sent. 63 | 64 | Where AAAAAAAA is an optional value to be used for the Program Counter when restarting the program. 65 | */ 66 | uint32_t HandleContinueCommand(void) 67 | { 68 | Buffer* pBuffer = GetBuffer(); 69 | int setPC = 0; 70 | uint32_t newPC = 0; 71 | 72 | /* New program counter value is optional parameter. */ 73 | __try 74 | { 75 | __throwing_func( newPC = ReadUIntegerArgument(pBuffer) ); 76 | setPC = 1; 77 | } 78 | __catch 79 | { 80 | clearExceptionCode(); 81 | } 82 | return ContinueExecution(setPC, newPC); 83 | } 84 | 85 | 86 | 87 | /* Handle the 'C' command which is sent from gdb to tell the debugger to continue execution of the currently halted 88 | program. It is similar to the 'c' command but it also provides a signal level, which MRI ignores. 89 | 90 | Command Format: cAA;BBBBBBBB 91 | Response Format: Blank until the next exception, at which time a 'T' stop response packet will be sent. 92 | 93 | Where AA is the signal to be set, and 94 | BBBBBBBB is an optional value to be used for the Program Counter when restarting the program. 95 | */ 96 | uint32_t HandleContinueWithSignalCommand(void) 97 | { 98 | Buffer* pBuffer = GetBuffer(); 99 | int setPC = 0; 100 | uint32_t newPC = 0; 101 | 102 | __try 103 | { 104 | /* Fetch signal value but ignore it. */ 105 | __throwing_func( ReadUIntegerArgument(pBuffer) ); 106 | if (Buffer_BytesLeft(pBuffer) && Buffer_IsNextCharEqualTo(pBuffer, ';')) 107 | { 108 | __throwing_func( newPC = ReadUIntegerArgument(pBuffer) ); 109 | setPC = 1; 110 | } 111 | } 112 | __catch 113 | { 114 | PrepareStringResponse(MRI_ERROR_INVALID_ARGUMENT); 115 | return 0; 116 | } 117 | return ContinueExecution(setPC, newPC); 118 | } 119 | 120 | 121 | /* Handle the 'D' command which is sent from gdb to resume execution before it detaches and exits. 122 | 123 | Command Format: D 124 | Response Format: OK 125 | 126 | */ 127 | uint32_t HandleDetachCommand(void) 128 | { 129 | if (Platform_RtosIsSetThreadStateSupported()) 130 | Platform_RtosSetThreadState(MRI_PLATFORM_ALL_THREADS, MRI_PLATFORM_THREAD_THAWED); 131 | SkipHardcodedBreakpoint(); 132 | PrepareStringResponse("OK"); 133 | return HANDLER_RETURN_RESUME_PROGRAM; 134 | } 135 | -------------------------------------------------------------------------------- /core/cmd_continue.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Handler for continue gdb command. */ 16 | #ifndef CMD_CONTINUE_H_ 17 | #define CMD_CONTINUE_H_ 18 | 19 | #include 20 | 21 | /* Real name of functions are in mri namespace. */ 22 | uint32_t mriCmd_ContinueExecution(int setPC, uint32_t newPC); 23 | uint32_t mriCmd_SkipHardcodedBreakpoint(void); 24 | uint32_t mriCmd_HandleContinueCommand(void); 25 | uint32_t mriCmd_HandleContinueWithSignalCommand(void); 26 | uint32_t mriCmd_HandleDetachCommand(void); 27 | 28 | /* Macroes which allow code to drop the mri namespace prefix. */ 29 | #define ContinueExecution mriCmd_ContinueExecution 30 | #define SkipHardcodedBreakpoint mriCmd_SkipHardcodedBreakpoint 31 | #define HandleContinueCommand mriCmd_HandleContinueCommand 32 | #define HandleContinueWithSignalCommand mriCmd_HandleContinueWithSignalCommand 33 | #define HandleDetachCommand mriCmd_HandleDetachCommand 34 | 35 | #endif /* CMD_CONTINUE_H_ */ 36 | -------------------------------------------------------------------------------- /core/cmd_file.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2014 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Handling and issuing routines for gdb file commands. */ 16 | #ifndef CMD_FILE_H_ 17 | #define CMD_FILE_H_ 18 | 19 | #include 20 | #include 21 | 22 | typedef struct 23 | { 24 | uint32_t filenameAddress; 25 | uint32_t filenameLength; 26 | uint32_t flags; 27 | uint32_t mode; 28 | } OpenParameters; 29 | 30 | typedef struct 31 | { 32 | uint32_t fileDescriptor; 33 | uint32_t bufferAddress; 34 | int32_t bufferSize; 35 | } TransferParameters; 36 | 37 | typedef struct 38 | { 39 | uint32_t fileDescriptor; 40 | int32_t offset; 41 | int32_t whence; 42 | } SeekParameters; 43 | 44 | typedef struct 45 | { 46 | uint32_t filenameAddress; 47 | uint32_t filenameLength; 48 | } RemoveParameters; 49 | 50 | typedef struct 51 | { 52 | uint32_t filenameAddress; 53 | uint32_t filenameLength; 54 | uint32_t fileStatBuffer; 55 | } StatParameters; 56 | 57 | typedef struct 58 | { 59 | uint32_t origFilenameAddress; 60 | uint32_t origFilenameLength; 61 | uint32_t newFilenameAddress; 62 | uint32_t newFilenameLength; 63 | } RenameParameters; 64 | 65 | /* Real name of functions are in mri namespace. */ 66 | int mriIssueGdbFileOpenRequest(const OpenParameters* pParameters); 67 | int mriIssueGdbFileWriteRequest(const TransferParameters* pParameters); 68 | int mriIssueGdbFileReadRequest(const TransferParameters* pParameters); 69 | int mriIssueGdbFileCloseRequest(uint32_t fileDescriptor); 70 | int mriIssueGdbFileSeekRequest(const SeekParameters* pParameters); 71 | int mriIssueGdbFileFStatRequest(uint32_t fileDescriptor, uint32_t fileStatBuffer); 72 | int mriIssueGdbFileUnlinkRequest(const RemoveParameters* pParameters); 73 | int mriIssueGdbFileStatRequest(const StatParameters* pParameters); 74 | int mriIssueGdbFileRenameRequest(const RenameParameters* pParameters); 75 | uint32_t mriHandleFileIOCommand(void); 76 | 77 | /* Macroes which allow code to drop the mri namespace prefix. */ 78 | #define IssueGdbFileOpenRequest mriIssueGdbFileOpenRequest 79 | #define IssueGdbFileWriteRequest mriIssueGdbFileWriteRequest 80 | #define IssueGdbFileReadRequest mriIssueGdbFileReadRequest 81 | #define IssueGdbFileCloseRequest mriIssueGdbFileCloseRequest 82 | #define IssueGdbFileSeekRequest mriIssueGdbFileSeekRequest 83 | #define IssueGdbFileFStatRequest mriIssueGdbFileFStatRequest 84 | #define IssueGdbFileUnlinkRequest mriIssueGdbFileUnlinkRequest 85 | #define IssueGdbFileStatRequest mriIssueGdbFileStatRequest 86 | #define IssueGdbFileRenameRequest mriIssueGdbFileRenameRequest 87 | #define HandleFileIOCommand mriHandleFileIOCommand 88 | 89 | #endif /* CMD_FILE_H_ */ 90 | -------------------------------------------------------------------------------- /core/cmd_memory.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Handlers for memory related gdb commands. */ 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | 25 | /* Handle the 'm' command which is to read the specified address range from memory. 26 | 27 | Command Format: mAAAAAAAA,LLLLLLLL 28 | Response Format: xx... 29 | 30 | Where AAAAAAAA is the hexadecimal representation of the address where the read is to start. 31 | LLLLLLLL is the hexadecimal representation of the length (in bytes) of the read to be conducted. 32 | xx is the hexadecimal representation of the first byte read from the specified location. 33 | ... continue returning the rest of LLLLLLLL-1 bytes in hexadecimal format. 34 | */ 35 | uint32_t HandleMemoryReadCommand(void) 36 | { 37 | Buffer* pBuffer = GetBuffer(); 38 | AddressLength addressLength; 39 | uint32_t result; 40 | 41 | __try 42 | { 43 | ReadAddressAndLengthArguments(pBuffer, &addressLength); 44 | } 45 | __catch 46 | { 47 | PrepareStringResponse(MRI_ERROR_INVALID_ARGUMENT); 48 | return 0; 49 | } 50 | 51 | InitPacketBuffers(); 52 | result = ReadMemoryIntoHexBuffer(pBuffer, addressLength.address, addressLength.length); 53 | if (result == 0) 54 | PrepareStringResponse(MRI_ERROR_MEMORY_ACCESS_FAILURE); 55 | 56 | return 0; 57 | } 58 | 59 | 60 | /* Handle the 'M' command which is to write to the specified address range in memory. 61 | 62 | Command Format: MAAAAAAAA,LLLLLLLL:xx... 63 | Response Format: OK 64 | 65 | Where AAAAAAAA is the hexadecimal representation of the address where the write is to start. 66 | LLLLLLLL is the hexadecimal representation of the length (in bytes) of the write to be conducted. 67 | xx is the hexadecimal representation of the first byte to be written to the specified location. 68 | ... continue returning the rest of LLLLLLLL-1 bytes in hexadecimal format. 69 | */ 70 | uint32_t HandleMemoryWriteCommand(void) 71 | { 72 | Buffer* pBuffer = GetBuffer(); 73 | AddressLength addressLength; 74 | 75 | __try 76 | { 77 | ReadAddressAndLengthArgumentsWithColon(pBuffer, &addressLength); 78 | } 79 | __catch 80 | { 81 | PrepareStringResponse(MRI_ERROR_INVALID_ARGUMENT); 82 | return 0; 83 | } 84 | 85 | if (WriteHexBufferToMemory(pBuffer, addressLength.address, addressLength.length)) 86 | { 87 | PrepareStringResponse("OK"); 88 | } 89 | else 90 | { 91 | if (Buffer_OverrunDetected(pBuffer)) 92 | PrepareStringResponse( MRI_ERROR_BUFFER_OVERRUN); 93 | else 94 | PrepareStringResponse(MRI_ERROR_MEMORY_ACCESS_FAILURE); 95 | } 96 | 97 | return 0; 98 | } 99 | 100 | 101 | /* Handle the 'X' command which is to write to the specified address range in memory. 102 | 103 | Command Format: XAAAAAAAA,LLLLLLLL:xx... 104 | Response Format: OK 105 | 106 | Where AAAAAAAA is the hexadecimal representation of the address where the write is to start. 107 | LLLLLLLL is the hexadecimal representation of the length (in bytes) of the write to be conducted. 108 | xx is the hexadecimal representation of the first byte to be written to the specified location. 109 | ... continue returning the rest of LLLLLLLL-1 bytes in hexadecimal format. 110 | */ 111 | uint32_t HandleBinaryMemoryWriteCommand(void) 112 | { 113 | Buffer* pBuffer = GetBuffer(); 114 | AddressLength addressLength; 115 | uintmri_t address; 116 | uintmri_t length; 117 | 118 | __try 119 | { 120 | ReadAddressAndLengthArgumentsWithColon(pBuffer, &addressLength); 121 | } 122 | __catch 123 | { 124 | PrepareStringResponse(MRI_ERROR_INVALID_ARGUMENT); 125 | return 0; 126 | } 127 | 128 | address = addressLength.address; 129 | length = addressLength.length; 130 | if (WriteBinaryBufferToMemory(pBuffer, address, length)) 131 | { 132 | Platform_SyncICacheToDCache(address, length); 133 | PrepareStringResponse("OK"); 134 | } 135 | else 136 | { 137 | if (Buffer_OverrunDetected(pBuffer)) 138 | PrepareStringResponse(MRI_ERROR_BUFFER_OVERRUN); 139 | else 140 | PrepareStringResponse(MRI_ERROR_MEMORY_ACCESS_FAILURE); 141 | } 142 | 143 | return 0; 144 | } 145 | -------------------------------------------------------------------------------- /core/cmd_memory.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2014 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Handlers for memory read and write gdb commands. */ 16 | #ifndef CMD_MEMORY_H_ 17 | #define CMD_MEMORY_H_ 18 | 19 | #include 20 | 21 | /* Real name of functions are in mri namespace. */ 22 | uint32_t mriCmd_HandleMemoryReadCommand(void); 23 | uint32_t mriCmd_HandleMemoryWriteCommand(void); 24 | uint32_t mriCmd_HandleBinaryMemoryWriteCommand(void); 25 | 26 | /* Macroes which allow code to drop the mri namespace prefix. */ 27 | #define HandleMemoryReadCommand mriCmd_HandleMemoryReadCommand 28 | #define HandleMemoryWriteCommand mriCmd_HandleMemoryWriteCommand 29 | #define HandleBinaryMemoryWriteCommand mriCmd_HandleBinaryMemoryWriteCommand 30 | 31 | #endif /* CMD_MEMORY_H_ */ 32 | -------------------------------------------------------------------------------- /core/cmd_query.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2012 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Handler for gdb query commands. */ 16 | #ifndef CMD_QUERY_H_ 17 | #define CMD_QUERY_H_ 18 | 19 | #include 20 | 21 | /* Real name of functions are in mri namespace. */ 22 | uint32_t mriCmd_HandleQueryCommand(void); 23 | 24 | /* Macroes which allow code to drop the mri namespace prefix. */ 25 | #define HandleQueryCommand mriCmd_HandleQueryCommand 26 | 27 | #endif /* CMD_QUERY_H_ */ 28 | -------------------------------------------------------------------------------- /core/cmd_registers.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Command handler for gdb commands related to CPU registers. */ 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | 25 | static void writeThreadIdToBuffer(Buffer* pBuffer, uint32_t threadId); 26 | static void writeTrapReasonToBuffer(Buffer* pBuffer); 27 | /* Sent when an exception occurs while program is executing because of previous 'c' (Continue) or 's' (Step) commands. 28 | 29 | Data Format: Tssii:xxxxxxxx;ii:xxxxxxxx;... 30 | 31 | Where ss is the hex value of the signal which caused the exception. 32 | ii is the hex offset of the 32-bit register value following the ':' The offset is relative to the register 33 | contents in the g response packet and the SContext structure. 34 | xxxxxxxx is the 32-bit value of the specified register in hex format. 35 | The above ii:xxxxxxxx; patterns can be repeated for whichever register values should be sent with T response. 36 | */ 37 | uint32_t Send_T_StopResponse(void) 38 | { 39 | uint8_t signalValue = GetSignalValue(); 40 | Buffer* pBuffer = GetInitializedBuffer(); 41 | uint32_t threadId = Platform_RtosGetHaltedThreadId(); 42 | 43 | Buffer_WriteChar(pBuffer, 'T'); 44 | Buffer_WriteByteAsHex(pBuffer, signalValue); 45 | if (threadId != 0) 46 | writeThreadIdToBuffer(pBuffer, threadId); 47 | if (signalValue == SIGTRAP) 48 | writeTrapReasonToBuffer(pBuffer); 49 | Platform_WriteTResponseRegistersToBuffer(pBuffer); 50 | 51 | SendPacketToGdb(); 52 | return HANDLER_RETURN_RETURN_IMMEDIATELY; 53 | } 54 | 55 | static void writeThreadIdToBuffer(Buffer* pBuffer, uint32_t threadId) 56 | { 57 | Buffer_WriteString(pBuffer, "thread"); 58 | Buffer_WriteChar(pBuffer, ':'); 59 | Buffer_WriteUIntegerAsHex(pBuffer, threadId); 60 | Buffer_WriteChar(pBuffer, ';'); 61 | } 62 | 63 | static void writeTrapReasonToBuffer(Buffer* pBuffer) 64 | { 65 | const char* pReason; 66 | int outputAddress; 67 | 68 | PlatformTrapReason reason = Platform_GetTrapReason(); 69 | switch (reason.type) 70 | { 71 | case MRI_PLATFORM_TRAP_TYPE_WATCH: 72 | pReason = "watch"; 73 | outputAddress = 1; 74 | break; 75 | case MRI_PLATFORM_TRAP_TYPE_RWATCH: 76 | pReason = "rwatch"; 77 | outputAddress = 1; 78 | break; 79 | case MRI_PLATFORM_TRAP_TYPE_AWATCH: 80 | pReason = "awatch"; 81 | outputAddress = 1; 82 | break; 83 | default: 84 | /* Don't dump trap reason if it is unknown. */ 85 | return; 86 | } 87 | 88 | Buffer_WriteString(pBuffer, pReason); 89 | Buffer_WriteChar(pBuffer, ':'); 90 | if (outputAddress) 91 | Buffer_WriteUIntegerAsHex(pBuffer, reason.address); 92 | Buffer_WriteChar(pBuffer, ';'); 93 | } 94 | 95 | 96 | /* Handle the 'g' command which is to send the contents of the registers back to gdb. 97 | 98 | Command Format: g 99 | Response Format: xxxxxxxxyyyyyyyy... 100 | 101 | Where xxxxxxxx is the hexadecimal representation of the 32-bit R0 register. 102 | yyyyyyyy is the hexadecimal representation of the 32-bit R1 register. 103 | ... and so on through the members of the SContext structure. 104 | */ 105 | uint32_t HandleRegisterReadCommand(void) 106 | { 107 | Context_CopyToBuffer(GetContext(), GetInitializedBuffer()); 108 | return 0; 109 | } 110 | 111 | /* Handle the 'G' command which is to receive the new contents of the registers from gdb for the program to use when 112 | it resumes execution. 113 | 114 | Command Format: Gxxxxxxxxyyyyyyyy... 115 | Response Format: OK 116 | 117 | Where xxxxxxxx is the hexadecimal representation of the 32-bit R0 register. 118 | yyyyyyyy is the hexadecimal representation of the 32-bit R1 register. 119 | ... and so on through the members of the SContext structure. 120 | */ 121 | uint32_t HandleRegisterWriteCommand(void) 122 | { 123 | Buffer* pBuffer = GetBuffer(); 124 | 125 | Context_CopyFromBuffer(GetContext(), pBuffer); 126 | 127 | if (Buffer_OverrunDetected(pBuffer)) 128 | PrepareStringResponse(MRI_ERROR_BUFFER_OVERRUN); 129 | else 130 | PrepareStringResponse("OK"); 131 | 132 | return 0; 133 | } 134 | -------------------------------------------------------------------------------- /core/cmd_registers.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2014 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Command handler for gdb commands related to CPU registers. */ 16 | #ifndef CMD_REGISTERS_H_ 17 | #define CMD_REGISTERS_H_ 18 | 19 | #include 20 | 21 | /* Real name of functions are in mri namespace. */ 22 | uint32_t mriCmd_Send_T_StopResponse(void); 23 | uint32_t mriCmd_HandleRegisterReadCommand(void); 24 | uint32_t mriCmd_HandleRegisterWriteCommand(void); 25 | 26 | /* Macroes which allow code to drop the mri namespace prefix. */ 27 | #define Send_T_StopResponse mriCmd_Send_T_StopResponse 28 | #define HandleRegisterReadCommand mriCmd_HandleRegisterReadCommand 29 | #define HandleRegisterWriteCommand mriCmd_HandleRegisterWriteCommand 30 | 31 | #endif /* CMD_REGISTERS_H_ */ 32 | -------------------------------------------------------------------------------- /core/cmd_step.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2022 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Handler for single step gdb command. */ 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | 23 | static uint32_t justAdvancedPastBreakpoint(uint32_t continueReturn); 24 | /* Handle the 's' command which is sent from gdb to tell the debugger to single step over the next instruction in the 25 | currently halted program. 26 | 27 | Command Format: sAAAAAAAA 28 | Response Format: Blank until the next exception, at which time a 'T' stop response packet will be sent. 29 | 30 | Where AAAAAAAA is an optional value to be used for the Program Counter when restarting the program. 31 | */ 32 | uint32_t HandleSingleStepCommand(void) 33 | { 34 | /* Single step is pretty much like continue except processor is told to only execute 1 instruction. */ 35 | uint32_t returnValue = HandleContinueCommand(); 36 | if (justAdvancedPastBreakpoint(returnValue)) 37 | { 38 | /* Treat the advance as the single step and don't resume execution. */ 39 | return Send_T_StopResponse(); 40 | } 41 | 42 | if (returnValue) 43 | { 44 | uint32_t pcBefore = Platform_GetProgramCounter(); 45 | Platform_EnableSingleStep(); 46 | if (Platform_GetProgramCounter() != pcBefore) 47 | { 48 | /* Platform code ended up advancing the program counter instead of enabling single step so just return 49 | stop response to GDB. */ 50 | return Send_T_StopResponse(); 51 | } 52 | if (Platform_RtosIsSetThreadStateSupported()) 53 | { 54 | Platform_RtosSetThreadState(Platform_RtosGetHaltedThreadId(), MRI_PLATFORM_THREAD_SINGLE_STEPPING); 55 | } 56 | } 57 | 58 | return returnValue; 59 | } 60 | 61 | static uint32_t justAdvancedPastBreakpoint(uint32_t continueReturn) 62 | { 63 | return continueReturn & HANDLER_RETURN_SKIPPED_OVER_BREAK; 64 | } 65 | 66 | 67 | /* Handle the 'S' command which is sent from gdb to tell the debugger to single step over the next instruction in the 68 | currently halted program. It is similar to the 's' command but it also provides a signal, which MRI ignores. 69 | 70 | Command Format: sAA;BBBBBBBB 71 | Response Format: Blank until the next exception, at which time a 'T' stop response packet will be sent. 72 | 73 | Where AA is the signal to be set 74 | BBBBBBBB is an optional value to be used for the Program Counter when restarting the program. 75 | */ 76 | uint32_t HandleSingleStepWithSignalCommand(void) 77 | { 78 | /* Single step is pretty much like continue except processor is told to only execute 1 instruction. */ 79 | uint32_t returnValue = HandleContinueWithSignalCommand(); 80 | if (justAdvancedPastBreakpoint(returnValue)) 81 | { 82 | /* Treat the advance as the single step and don't resume execution. */ 83 | return Send_T_StopResponse(); 84 | } 85 | 86 | if (returnValue) 87 | { 88 | if (Platform_RtosIsSetThreadStateSupported()) 89 | Platform_RtosSetThreadState(Platform_RtosGetHaltedThreadId(), MRI_PLATFORM_THREAD_SINGLE_STEPPING); 90 | Platform_EnableSingleStep(); 91 | } 92 | 93 | return returnValue; 94 | } 95 | -------------------------------------------------------------------------------- /core/cmd_step.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Handler for single step gdb command. */ 16 | #ifndef CMD_STEP_H_ 17 | #define CMD_STEP_H_ 18 | 19 | #include 20 | 21 | /* Real name of functions are in mri namespace. */ 22 | uint32_t mriCmd_HandleSingleStepCommand(void); 23 | uint32_t mriCmd_HandleSingleStepWithSignalCommand(void); 24 | 25 | /* Macroes which allow code to drop the mri namespace prefix. */ 26 | #define HandleSingleStepCommand mriCmd_HandleSingleStepCommand 27 | #define HandleSingleStepWithSignalCommand mriCmd_HandleSingleStepWithSignalCommand 28 | 29 | #endif /* CMD_STEP_H_ */ 30 | -------------------------------------------------------------------------------- /core/cmd_thread.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Command handler for gdb commands related to threads. */ 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | 23 | /* Handle the 'H' command which is sent to switch thread register context. 24 | 25 | Command Format: Hgxxxxxxxx 26 | Response Format: OK 27 | 28 | Where xxxxxxxx is the hexadecimal representation of the ID for the thread to use for future register read/write 29 | commands. 30 | */ 31 | uint32_t HandleThreadContextCommand(void) 32 | { 33 | Buffer* pBuffer = GetBuffer(); 34 | 35 | __try 36 | { 37 | uint32_t threadId = 0; 38 | MriContext* pContext = NULL; 39 | char ch; 40 | 41 | __throwing_func( ch = Buffer_ReadChar(pBuffer) ); 42 | if (ch != 'g') 43 | { 44 | setExceptionCode(invalidArgumentException); 45 | break; 46 | } 47 | __throwing_func( threadId = Buffer_ReadUIntegerAsHex(pBuffer) ); 48 | pContext = Platform_RtosGetThreadContext(threadId); 49 | if (pContext == NULL) 50 | { 51 | setExceptionCode(invalidArgumentException); 52 | break; 53 | } 54 | SetContext(pContext); 55 | PrepareStringResponse("OK"); 56 | } 57 | __catch 58 | { 59 | PrepareStringResponse(MRI_ERROR_INVALID_ARGUMENT); 60 | } 61 | 62 | return 0; 63 | } 64 | 65 | 66 | /* Handle the 'T' command which is sent to see if a thread ID is still active. 67 | 68 | Command Format: Txxxxxxxx 69 | Response Format: OK if thread is still active. 70 | E01 is thread isn't active. 71 | 72 | Where xxxxxxxx is the hexadecimal representation of the thread ID. 73 | */ 74 | uint32_t HandleIsThreadActiveCommand(void) 75 | { 76 | Buffer* pBuffer = GetBuffer(); 77 | 78 | __try 79 | { 80 | uint32_t threadId = 0; 81 | int isActive = 0; 82 | 83 | __throwing_func( threadId = Buffer_ReadUIntegerAsHex(pBuffer) ); 84 | isActive = Platform_RtosIsThreadActive(threadId); 85 | if (!isActive) 86 | { 87 | setExceptionCode(invalidArgumentException); 88 | break; 89 | } 90 | PrepareStringResponse("OK"); 91 | } 92 | __catch 93 | { 94 | PrepareStringResponse(MRI_ERROR_INVALID_ARGUMENT); 95 | } 96 | 97 | return 0; 98 | } 99 | -------------------------------------------------------------------------------- /core/cmd_thread.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Command handler for gdb commands related to threads. */ 16 | #ifndef CMD_THREAD_H_ 17 | #define CMD_THREAD_H_ 18 | 19 | #include 20 | 21 | /* Real name of functions are in mri namespace. */ 22 | uint32_t mriCmd_HandleThreadContextCommand(void); 23 | uint32_t mriCmd_HandleIsThreadActiveCommand(void); 24 | 25 | /* Macroes which allow code to drop the mri namespace prefix. */ 26 | #define HandleThreadContextCommand mriCmd_HandleThreadContextCommand 27 | #define HandleIsThreadActiveCommand mriCmd_HandleIsThreadActiveCommand 28 | 29 | #endif /* CMD_THREAD_H_ */ 30 | -------------------------------------------------------------------------------- /core/cmd_vcont.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Handler for gdb's vCont and vCont? commands which support multithreaded single stepping/continuing. */ 16 | #ifndef CMD_VCONT_H_ 17 | #define CMD_VCONT_H_ 18 | 19 | #include 20 | 21 | /* Real name of functions are in mri namespace. */ 22 | uint32_t mriCmd_HandleVContCommands(void); 23 | void mriCmd_RestoreThreadStates(void); 24 | 25 | /* Macroes which allow code to drop the mri namespace prefix. */ 26 | #define HandleVContCommands mriCmd_HandleVContCommands 27 | #define RestoreThreadStates mriCmd_RestoreThreadStates 28 | 29 | #endif /* CMD_VCONT_H_ */ 30 | -------------------------------------------------------------------------------- /core/context.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* 'Class' which represents a scatter gather list of registers so that blocks of them can be pulled from various 16 | locations on the stack and they don't all need to be placed in one contiguous place in memory. 17 | */ 18 | #include 19 | #include 20 | 21 | 22 | void Context_Init(MriContext* pThis, ContextSection* pSections, size_t sectionCount) 23 | { 24 | pThis->pSections = pSections; 25 | pThis->sectionCount = sectionCount; 26 | } 27 | 28 | size_t Context_Count(MriContext* pThis) 29 | { 30 | size_t i; 31 | size_t count = 0; 32 | for (i = 0 ; i < pThis->sectionCount ; i++) 33 | { 34 | count += pThis->pSections[i].count; 35 | } 36 | return count; 37 | } 38 | 39 | uintmri_t Context_Get(const MriContext* pThis, size_t index) 40 | { 41 | size_t i; 42 | size_t count = 0; 43 | size_t base = 0; 44 | for (i = 0 ; i < pThis->sectionCount ; i++) 45 | { 46 | base = count; 47 | count += pThis->pSections[i].count; 48 | if (index < count) 49 | { 50 | return pThis->pSections[i].pValues[index - base]; 51 | } 52 | } 53 | __throw_and_return(bufferOverrunException, 0); 54 | } 55 | 56 | void Context_Set(MriContext* pThis, size_t index, uintmri_t newValue) 57 | { 58 | size_t i; 59 | size_t count = 0; 60 | size_t base = 0; 61 | for (i = 0 ; i < pThis->sectionCount ; i++) 62 | { 63 | base = count; 64 | count += pThis->pSections[i].count; 65 | if (index < count) 66 | { 67 | pThis->pSections[i].pValues[index - base] = newValue; 68 | return; 69 | } 70 | } 71 | __throw(bufferOverrunException); 72 | } 73 | 74 | 75 | static void writeBytesToBufferAsHex(Buffer* pBuffer, void* pBytes, size_t byteCount); 76 | void Context_CopyToBuffer(MriContext* pThis, Buffer* pBuffer) 77 | { 78 | size_t count = Context_Count(pThis); 79 | size_t i; 80 | 81 | for (i = 0 ; i < count ; i++) 82 | { 83 | uintmri_t reg = Context_Get(pThis, i); 84 | writeBytesToBufferAsHex(pBuffer, ®, sizeof(reg)); 85 | } 86 | } 87 | 88 | static void writeBytesToBufferAsHex(Buffer* pBuffer, void* pBytes, size_t byteCount) 89 | { 90 | uint8_t* pByte = (uint8_t*)pBytes; 91 | while (byteCount--) 92 | Buffer_WriteByteAsHex(pBuffer, *pByte++); 93 | } 94 | 95 | 96 | static void readBytesFromBufferAsHex(Buffer* pBuffer, void* pBytes, size_t byteCount); 97 | void Context_CopyFromBuffer(MriContext* pThis, Buffer* pBuffer) 98 | { 99 | size_t count = Context_Count(pThis); 100 | size_t i; 101 | 102 | for (i = 0 ; i < count ; i++) { 103 | uintmri_t reg; 104 | readBytesFromBufferAsHex(pBuffer, ®, sizeof(reg)); 105 | Context_Set(pThis, i, reg); 106 | } 107 | } 108 | 109 | static void readBytesFromBufferAsHex(Buffer* pBuffer, void* pBytes, size_t byteCount) 110 | { 111 | uint8_t* pByte = (uint8_t*)pBytes; 112 | while (byteCount--) 113 | *pByte++ = Buffer_ReadByteAsHex(pBuffer); 114 | } -------------------------------------------------------------------------------- /core/context.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* 'Class' which represents a scatter gather list of registers so that blocks of them can be pulled from various 16 | locations on the stack and they don't all need to be placed in one contiguous place in memory. 17 | */ 18 | #ifndef CONTEXT_H_ 19 | #define CONTEXT_H_ 20 | 21 | #include 22 | #include 23 | 24 | typedef struct 25 | { 26 | uintmri_t* pValues; 27 | size_t count; 28 | } ContextSection; 29 | 30 | typedef struct 31 | { 32 | ContextSection* pSections; 33 | size_t sectionCount; 34 | } MriContext; 35 | 36 | /* Real name of functions are in mri namespace. */ 37 | void mriContext_Init(MriContext* pThis, ContextSection* pSections, size_t sectionCount); 38 | size_t mriContext_Count(MriContext* pThis); 39 | uintmri_t mriContext_Get(const MriContext* pThis, size_t index); 40 | void mriContext_Set(MriContext* pThis, size_t index, uintmri_t newValue); 41 | void mriContext_CopyToBuffer(MriContext* pThis, Buffer* pBuffer); 42 | void mriContext_CopyFromBuffer(MriContext* pThis, Buffer* pBuffer); 43 | 44 | /* Macroes which allow code to drop the mri namespace prefix. */ 45 | #define Context_Init mriContext_Init 46 | #define Context_Count mriContext_Count 47 | #define Context_Get mriContext_Get 48 | #define Context_Set mriContext_Set 49 | #define Context_CopyToBuffer mriContext_CopyToBuffer 50 | #define Context_CopyFromBuffer mriContext_CopyFromBuffer 51 | 52 | #endif /* CONTEXT_H_ */ 53 | -------------------------------------------------------------------------------- /core/core.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Core mri functionality exposed to other modules within the debug monitor. These are the private routines exposed 16 | from within mri.c. The public functionality is exposed via mri.h. */ 17 | #ifndef CORE_H_ 18 | #define CORE_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | 26 | typedef struct 27 | { 28 | uint32_t start; 29 | uint32_t end; 30 | } AddressRange; 31 | 32 | 33 | /* Real name of functions are in mri namespace. */ 34 | void mriDebugException(MriContext* pContext); 35 | 36 | void mriCore_InitPacketBuffers(void); 37 | Buffer* mriCore_GetBuffer(void); 38 | Buffer* mriCore_GetInitializedBuffer(void); 39 | void mriCore_PrepareStringResponse(const char* pErrorString); 40 | #define PrepareEmptyResponseForUnknownCommand() mriCore_PrepareStringResponse("") 41 | 42 | int mriCore_WasControlCFlagSentFromGdb(void); 43 | void mriCore_RecordControlCFlagSentFromGdb(int controlCFlag); 44 | int mriCore_WasControlCEncountered(void); 45 | void mriCore_ControlCEncountered(void); 46 | int mriCore_WasSemihostCallCancelledByGdb(void); 47 | void mriCore_FlagSemihostCallAsHandled(void); 48 | int mriCore_IsFirstException(void); 49 | int mriCore_WasSuccessfullyInit(void); 50 | void mriCore_RequestResetOnNextContinue(void); 51 | void mriCore_CancelResetRequestOnNextContinue(void); 52 | int mriCore_WasResetOnNextContinueRequested(void); 53 | void mriCore_SetSingleSteppingRange(const AddressRange* pRange); 54 | 55 | MriContext* mriCore_GetContext(void); 56 | void mriCore_SetContext(MriContext* pContext); 57 | 58 | void mriCore_SetSignalValue(uint8_t signalValue); 59 | uint8_t mriCore_GetSignalValue(void); 60 | void mriCore_SetSemihostReturnValues(int semihostReturnCode, int semihostErrNo); 61 | int mriCore_GetSemihostReturnCode(void); 62 | int mriCore_GetSemihostErrno(void); 63 | 64 | void mriCore_SendPacketToGdb(void); 65 | void mriCore_GdbCommandHandlingLoop(void); 66 | 67 | typedef int (*TempBreakpointCallbackPtr)(void*); 68 | int mriCore_SetTempBreakpoint(uint32_t breakpointAddress, TempBreakpointCallbackPtr pCallback, void* pvContext); 69 | 70 | void mriCoreSetDebuggerHooks(MriDebuggerHookPtr pEnteringHook, MriDebuggerHookPtr pLeavingHook, void* pvContext); 71 | 72 | 73 | /* Macroes which allow code to drop the mri namespace prefix. */ 74 | #define InitPacketBuffers mriCore_InitPacketBuffers 75 | #define GetBuffer mriCore_GetBuffer 76 | #define GetInitializedBuffer mriCore_GetInitializedBuffer 77 | #define PrepareStringResponse mriCore_PrepareStringResponse 78 | #define WasControlCFlagSentFromGdb mriCore_WasControlCFlagSentFromGdb 79 | #define RecordControlCFlagSentFromGdb mriCore_RecordControlCFlagSentFromGdb 80 | #define WasControlCEncountered mriCore_WasControlCEncountered 81 | #define ControlCEncountered mriCore_ControlCEncountered 82 | #define WasSemihostCallCancelledByGdb mriCore_WasSemihostCallCancelledByGdb 83 | #define FlagSemihostCallAsHandled mriCore_FlagSemihostCallAsHandled 84 | #define IsFirstException mriCore_IsFirstException 85 | #define WasSuccessfullyInit mriCore_WasSuccessfullyInit 86 | #define RequestResetOnNextContinue mriCore_RequestResetOnNextContinue 87 | #define CancelResetRequestOnNextContinue mriCore_CancelResetRequestOnNextContinue 88 | #define WasResetOnNextContinueRequested mriCore_WasResetOnNextContinueRequested 89 | #define SetSingleSteppingRange mriCore_SetSingleSteppingRange 90 | #define GetContext mriCore_GetContext 91 | #define SetContext mriCore_SetContext 92 | #define SetSignalValue mriCore_SetSignalValue 93 | #define GetSignalValue mriCore_GetSignalValue 94 | #define SetSemihostReturnValues mriCore_SetSemihostReturnValues 95 | #define GetSemihostReturnCode mriCore_GetSemihostReturnCode 96 | #define GetSemihostErrno mriCore_GetSemihostErrno 97 | #define SendPacketToGdb mriCore_SendPacketToGdb 98 | #define GdbCommandHandlingLoop mriCore_GdbCommandHandlingLoop 99 | #define SetTempBreakpoint mriCore_SetTempBreakpoint 100 | #define SetDebuggerHooks mriCoreSetDebuggerHooks 101 | 102 | #endif /* CORE_H_ */ 103 | -------------------------------------------------------------------------------- /core/fileio.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2012 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Constants used by gdb for remote file APIs. */ 16 | #ifndef FILEIO_H_ 17 | #define FILEIO_H_ 18 | 19 | #include 20 | 21 | #define GDB_O_RDONLY 0x0 22 | #define GDB_O_WRONLY 0x1 23 | #define GDB_O_RDWR 0x2 24 | #define GDB_O_APPEND 0x8 25 | #define GDB_O_CREAT 0x200 26 | #define GDB_O_TRUNC 0x400 27 | #define GDB_O_EXCL 0x800 28 | 29 | #define GDB_S_IFREG 0100000 30 | #define GDB_S_IFDIR 040000 31 | #define GDB_S_IRUSR 0400 32 | #define GDB_S_IWUSR 0200 33 | #define GDB_S_IXUSR 0100 34 | #define GDB_S_IRGRP 040 35 | #define GDB_S_IWGRP 020 36 | #define GDB_S_IXGRP 010 37 | #define GDB_S_IROTH 04 38 | #define GDB_S_IWOTH 02 39 | #define GDB_S_IXOTH 01 40 | 41 | #define GDB_SEEK_SET 0 42 | #define GDB_SEEK_CUR 1 43 | #define GDB_SEEK_END 2 44 | 45 | typedef struct 46 | { 47 | uint32_t device; 48 | uint32_t inode; 49 | uint32_t mode; 50 | uint32_t numberOfLinks; 51 | uint32_t userId; 52 | uint32_t groupId; 53 | uint32_t deviceType; 54 | uint32_t totalSizeUpperWord; 55 | uint32_t totalSizeLowerWord; 56 | uint32_t blockSizeUpperWord; 57 | uint32_t blockSizeLowerWord; 58 | uint32_t blockCountUpperWord; 59 | uint32_t blockCountLowerWord; 60 | uint32_t lastAccessTime; 61 | uint32_t lastModifiedTime; 62 | uint32_t lastChangeTime; 63 | } GdbStats; 64 | 65 | #endif /* FILEIO_H_ */ 66 | -------------------------------------------------------------------------------- /core/gdb_console.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2022 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Routines to output text to stdout on the gdb console. */ 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | 25 | size_t WriteStringToGdbConsole(const char* pString) 26 | { 27 | return WriteSizedStringToGdbConsole(pString, mri_strlen(pString)); 28 | } 29 | 30 | /* Send the 'O' command to gdb to output text to its console. 31 | 32 | Command Format: OXX... 33 | Where XX is the hexadecimal representation of each character in the string to be sent to the gdb console. 34 | */ 35 | size_t WriteSizedStringToGdbConsole(const char* pString, size_t length) 36 | { 37 | Buffer* pBuffer = GetInitializedBuffer(); 38 | size_t charsWritten = 0; 39 | 40 | Buffer_WriteChar(pBuffer, 'O'); 41 | charsWritten = Buffer_WriteSizedStringAsHex(pBuffer, pString, length); 42 | SendPacketToGdb(); 43 | 44 | return charsWritten; 45 | } 46 | 47 | 48 | void WriteHexValueToGdbConsole(uint32_t Value) 49 | { 50 | Buffer BufferObject; 51 | char StringBuffer[11]; 52 | 53 | Buffer_Init(&BufferObject, StringBuffer, sizeof(StringBuffer)); 54 | Buffer_WriteString(&BufferObject, "0x"); 55 | Buffer_WriteUIntegerAsHex(&BufferObject, Value); 56 | Buffer_SetEndOfBuffer(&BufferObject); 57 | 58 | WriteSizedStringToGdbConsole(Buffer_GetArray(&BufferObject), Buffer_GetLength(&BufferObject)); 59 | } 60 | -------------------------------------------------------------------------------- /core/gdb_console.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2022 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Routines to output text to stdout on the gdb console. */ 16 | #ifndef GDB_CONSOLE_H_ 17 | #define GDB_CONSOLE_H_ 18 | 19 | #include 20 | 21 | /* Real name of functions are in mri namespace. */ 22 | size_t mriGdbConsole_WriteString(const char* pString); 23 | size_t mriGdbConsole_WriteSizedString(const char* pString, size_t length); 24 | void mriGdbConsole_WriteHexValue(uint32_t value); 25 | 26 | /* Macroes which allow code to drop the mri namespace prefix. */ 27 | #define WriteStringToGdbConsole mriGdbConsole_WriteString 28 | #define WriteSizedStringToGdbConsole mriGdbConsole_WriteSizedString 29 | #define WriteHexValueToGdbConsole mriGdbConsole_WriteHexValue 30 | 31 | #endif /* GDB_CONSOLE_H_ */ 32 | -------------------------------------------------------------------------------- /core/hex_convert.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2012 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Hexadecimal to/from text conversion helpers. */ 16 | #ifndef HEX_CONVERT_H_ 17 | #define HEX_CONVERT_H_ 18 | 19 | #include 20 | 21 | #define EXTRACT_HI_NIBBLE(X) (((X) >> 4) & 0xF) 22 | #define EXTRACT_LO_NIBBLE(X) ((X) & 0xF) 23 | 24 | static const char NibbleToHexChar[16] = { '0', '1', '2', '3', '4', '5', '6', '7', 25 | '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; 26 | 27 | static inline int HexCharToNibble(unsigned char HexChar) 28 | { 29 | if (HexChar >= 'a' && HexChar <= 'f') 30 | { 31 | return HexChar - 'a' + 10; 32 | } 33 | if (HexChar >= 'A' && HexChar <= 'F') 34 | { 35 | return HexChar - 'A' + 10; 36 | } 37 | if (HexChar >= '0' && HexChar <= '9') 38 | { 39 | return HexChar - '0'; 40 | } 41 | 42 | __throw_and_return(invalidHexDigitException, -1); 43 | } 44 | 45 | #endif /* HEX_CONVERT_H_ */ 46 | -------------------------------------------------------------------------------- /core/libc.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2022 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Implementation of Standard C Library functions that MRI makes use of. 16 | 17 | Having its own implementation of these means that users won't hit difficulties if they try to single step 18 | through the real Standard C Library. 19 | 20 | NOTE: The debuggee shouldn't call these versions as that would defeat their purpose. 21 | */ 22 | #include 23 | #include 24 | 25 | void* mri_memcpy(void* pvDest, const void* pvSrc, size_t len) 26 | { 27 | uint8_t* pDest = (uint8_t*)pvDest; 28 | const uint8_t* pSrc = (const uint8_t*)pvSrc; 29 | 30 | while (len--) 31 | { 32 | *pDest++ = *pSrc++; 33 | } 34 | return pvDest; 35 | } 36 | 37 | 38 | 39 | void* mri_memset(void *pvDest, int val, size_t len) 40 | { 41 | uint8_t* pDest = (uint8_t*)pvDest; 42 | while (len--) 43 | { 44 | *pDest++ = (uint8_t)val; 45 | } 46 | return pvDest; 47 | } 48 | 49 | 50 | 51 | int mri_strcmp(const char* pc1, const char* pc2) 52 | { 53 | uint8_t* p1 = (uint8_t*)pc1; 54 | uint8_t* p2 = (uint8_t*)pc2; 55 | int cmp = 0; 56 | 57 | do 58 | { 59 | cmp = *p1 - *p2++; 60 | } while (cmp == 0 && *p1++); 61 | return cmp; 62 | } 63 | 64 | 65 | 66 | 67 | int mri_strncmp(const char* pc1, const char* pc2, size_t len) 68 | { 69 | uint8_t* p1 = (uint8_t*)pc1; 70 | uint8_t* p2 = (uint8_t*)pc2; 71 | int cmp = 0; 72 | 73 | if (len == 0) 74 | { 75 | return 0; 76 | } 77 | 78 | do 79 | { 80 | cmp = *p1 - *p2++; 81 | } while (cmp == 0 && --len > 0 && *p1++); 82 | return cmp; 83 | } 84 | 85 | 86 | 87 | size_t mri_strlen(const char* p) 88 | { 89 | const char* pStart = p; 90 | while (*p) 91 | { 92 | p++; 93 | } 94 | return p - pStart; 95 | } 96 | 97 | 98 | 99 | char* mri_strstr(const char* pHaystack, const char* pNeedle) 100 | { 101 | size_t len = mri_strlen(pNeedle); 102 | 103 | while (*pHaystack) 104 | { 105 | if (mri_strncmp(pHaystack, pNeedle, len) == 0) 106 | { 107 | return (char*)pHaystack; 108 | } 109 | pHaystack++; 110 | } 111 | return NULL; 112 | } 113 | 114 | 115 | 116 | void* mri_memmove(void* pvDest, const void* pvSrc, size_t len) 117 | { 118 | uint8_t* pDest = (uint8_t*)pvDest; 119 | uint8_t* pDestEnd = pDest + len; 120 | uint8_t* pSrc = (uint8_t*)pvSrc; 121 | uint8_t* pSrcEnd = pSrc + len; 122 | int dir = 1; 123 | uint8_t* pDestCurr = pDest; 124 | uint8_t* pSrcCurr = pSrc; 125 | 126 | if (pDest > pSrc && pDest < pSrcEnd) 127 | { 128 | dir = -1; 129 | pDestCurr = pDestEnd - 1; 130 | pSrcCurr = pSrcEnd - 1; 131 | } 132 | 133 | while (len--) 134 | { 135 | *pDestCurr = *pSrcCurr; 136 | pDestCurr += dir; 137 | pSrcCurr += dir; 138 | } 139 | 140 | return pvDest; 141 | } 142 | -------------------------------------------------------------------------------- /core/libc.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2022 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Implementation of Standard C Library functions that MRI makes use of. 16 | 17 | Having its own implementation of these means that users won't hit difficulties if they try to single step 18 | through the real Standard C Library. 19 | 20 | NOTE: The debuggee shouldn't call these versions as that would defeat their purpose. 21 | */ 22 | #ifndef LIBC_H_ 23 | #define LIBC_H_ 24 | 25 | #include 26 | 27 | void* mri_memcpy(void* pDest, const void* pSrc, size_t len); 28 | void* mri_memset(void* pDest, int val, size_t len); 29 | int mri_strcmp(const char* p1, const char* p2); 30 | int mri_strncmp(const char* p1, const char* p2, size_t len); 31 | size_t mri_strlen(const char* p); 32 | char* mri_strstr(const char* pHaystack, const char* pNeedle); 33 | void* mri_memmove(void* pvDest, const void* pvSrc, size_t len); 34 | 35 | #endif /* LIBC_H_ */ 36 | -------------------------------------------------------------------------------- /core/mbedsys.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2014 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Definition of _sys_*() functions and associated constants implemented in mbed/capi.ar */ 16 | 17 | #ifndef MBEDSYS_H_ 18 | #define MBEDSYS_H_ 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | 25 | /* Types used by functions implemented in mbed.ar */ 26 | typedef int FILEHANDLE; 27 | 28 | /* File openmode values for mbed _sys_open() */ 29 | #define OPENMODE_R 0 30 | #define OPENMODE_B 1 31 | #define OPENMODE_PLUS 2 32 | #define OPENMODE_W 4 33 | #define OPENMODE_A 8 34 | 35 | /* Functions implemented in mbed.ar */ 36 | FILEHANDLE _sys_open(const char* name, int openmode); 37 | int _sys_close(FILEHANDLE fh); 38 | int _sys_write(FILEHANDLE fh, const unsigned char* buf, unsigned len, int mode); 39 | int _sys_read(FILEHANDLE fh, unsigned char* buf, unsigned len, int mode); 40 | int _sys_seek(FILEHANDLE fh, long pos); 41 | long _sys_flen(FILEHANDLE fh); 42 | int _sys_istty(FILEHANDLE fh); 43 | 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif /* MBEDSYS_H_ */ -------------------------------------------------------------------------------- /core/memory.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Routines to read/write memory and detect any faults that might occur while attempting to do so. */ 16 | #ifndef MEMORY_H_ 17 | #define MEMORY_H_ 18 | 19 | #include 20 | #include 21 | 22 | /* Real name of functions are in mri namespace. */ 23 | uintmri_t mriMem_ReadMemoryIntoHexBuffer(Buffer* pBuffer, uintmri_t address, uintmri_t readByteCount); 24 | int mriMem_WriteHexBufferToMemory(Buffer* pBuffer, uintmri_t address, uintmri_t writeByteCount); 25 | int mriMem_WriteBinaryBufferToMemory(Buffer* pBuffer, uintmri_t address, uintmri_t writeByteCount); 26 | 27 | /* Macroes which allow code to drop the mri namespace prefix. */ 28 | #define ReadMemoryIntoHexBuffer mriMem_ReadMemoryIntoHexBuffer 29 | #define WriteHexBufferToMemory mriMem_WriteHexBufferToMemory 30 | #define WriteBinaryBufferToMemory mriMem_WriteBinaryBufferToMemory 31 | 32 | #endif /* MEMORY_H_ */ 33 | -------------------------------------------------------------------------------- /core/mri_int.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Integer types used by MRI for debuggee registers, pointer addresses, etc. */ 16 | #ifndef MRI_INT_H_ 17 | #define MRI_INT_H_ 18 | 19 | #include 20 | 21 | /* The MRI_UINT_TYPE and MRI_INT_TYP macros should be set when calling the compiler to indicate what type should be 22 | used for integers on your platform. This allows support for 16/32/64-bit integers. */ 23 | #ifndef MRI_UINT_TYPE 24 | #define MRI_UINT_TYPE uintptr_t 25 | #endif 26 | #ifndef MRI_INT_TYPE 27 | #define MRI_INT_TYPE intptr_t 28 | #endif 29 | typedef MRI_UINT_TYPE uintmri_t; 30 | typedef MRI_INT_TYPE intmri_t; 31 | 32 | 33 | #endif /* MRI_INT_H_ */ 34 | -------------------------------------------------------------------------------- /core/packet.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2022 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* 'Class' to manage the sending and receiving of packets to/from gdb. Takes care of crc and ack/nak handling too. */ 16 | #ifndef PACKET_H_ 17 | #define PACKET_H_ 18 | 19 | #include 20 | #include 21 | 22 | typedef struct 23 | { 24 | /* This is the complete buffer with room for '$', '#', and 2-byte checksum. */ 25 | Buffer packetBuffer; 26 | /* This is a subset of pPacketBuffer, after room has been made for '$', '#', and 2-byte checksum. */ 27 | Buffer dataBuffer; 28 | char lastChar; 29 | unsigned char calculatedChecksum; 30 | unsigned char expectedChecksum; 31 | } Packet; 32 | 33 | /* Real name of functions are in mri namespace. */ 34 | void mriPacket_Init(Packet* pPacket, char* pBufferStart, size_t bufferSize); 35 | void mriPacket_GetFromGDB(Packet* pPacket); 36 | void mriPacket_SendToGDB(Packet* pPacket); 37 | 38 | /* Macroes which allow code to drop the mri namespace prefix. */ 39 | #define Packet_Init mriPacket_Init 40 | #define Packet_GetFromGDB mriPacket_GetFromGDB 41 | #define Packet_SendToGDB mriPacket_SendToGDB 42 | 43 | 44 | #endif /* PACKET_H_ */ 45 | -------------------------------------------------------------------------------- /core/semihost.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2022 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Semihost functionality for redirecting operations such as file I/O to the GNU debugger. */ 16 | #ifndef SEMIHOST_H_ 17 | #define SEMIHOST_H_ 18 | 19 | #include 20 | #include 21 | 22 | /* Real name of functions are in mri namespace. */ 23 | int mriSemihost_IsDebuggeeMakingSemihostCall(void); 24 | int mriSemihost_HandleSemihostRequest(void); 25 | int mriSemihost_WriteToFileOrConsole(const TransferParameters* pParameters); 26 | int mriSemihost_HandleNewlibSemihostRequest(PlatformSemihostParameters* pSemihostParameters); 27 | int mriSemihost_HandleArmSemihostRequest(PlatformSemihostParameters* pParameters); 28 | 29 | /* Macroes which allow code to drop the mri namespace prefix. */ 30 | #define Semihost_IsDebuggeeMakingSemihostCall mriSemihost_IsDebuggeeMakingSemihostCall 31 | #define Semihost_HandleSemihostRequest mriSemihost_HandleSemihostRequest 32 | #define Semihost_WriteToFileOrConsole mriSemihost_WriteToFileOrConsole 33 | #define Semihost_HandleNewlibSemihostRequest mriSemihost_HandleNewlibSemihostRequest 34 | #define Semihost_HandleArmSemihostRequest mriSemihost_HandleArmSemihostRequest 35 | 36 | #endif /* SEMIHOST_H_ */ 37 | -------------------------------------------------------------------------------- /core/signal.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2014 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Monitor for Remote Inspection. */ 16 | #ifndef SIGNAL_H_ 17 | #define SIGNAL_H_ 18 | 19 | #include 20 | 21 | #ifndef SIGTRAP 22 | #define SIGTRAP 5 23 | #endif 24 | 25 | #ifndef SIGBUS 26 | #define SIGBUS 10 27 | #endif 28 | 29 | #ifndef SIGSTOP 30 | #define SIGSTOP 18 31 | #endif 32 | 33 | #endif /* SIGNAL_H_ */ 34 | -------------------------------------------------------------------------------- /core/token.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2012 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* 'Class' used to parse and tokenize a string based on provided list of separators. */ 16 | #ifndef TOKEN_H_ 17 | #define TOKEN_H_ 18 | 19 | #include 20 | #include 21 | 22 | /* Maximum number of tokens that a string can be separated into. */ 23 | #define TOKEN_MAX_TOKENS 10 24 | 25 | /* Maximum size of string that can be split into tokens. */ 26 | #define TOKEN_MAX_STRING 64 27 | 28 | struct Token 29 | { 30 | const char* tokenPointers[TOKEN_MAX_TOKENS]; 31 | const char* pTokenSeparators; 32 | size_t tokenCount; 33 | char copyOfString[TOKEN_MAX_STRING + 1]; 34 | }; 35 | typedef struct Token Token; 36 | 37 | 38 | /* Real name of functions are in mri namespace. */ 39 | void mriToken_Init(Token* pToken); 40 | void mriToken_InitWith(Token* pToken, const char* pTheseTokenSeparators); 41 | __throws void mriToken_SplitString(Token* pToken, const char* pStringToSplit); 42 | size_t mriToken_GetTokenCount(Token* pToken); 43 | __throws const char* mriToken_GetToken(Token* pToken, size_t tokenIndex); 44 | const char* mriToken_MatchingString(Token* pToken, const char* pTokenToSearchFor); 45 | const char* mriToken_MatchingStringPrefix(Token* pToken, const char* pTokenPrefixToSearchFor); 46 | void mriToken_Copy(Token* pTokenCopy, Token* pTokenOriginal); 47 | 48 | /* Macroes which allow code to drop the mri namespace prefix. */ 49 | #define Token_Init mriToken_Init 50 | #define Token_InitWith mriToken_InitWith 51 | #define Token_SplitString mriToken_SplitString 52 | #define Token_GetTokenCount mriToken_GetTokenCount 53 | #define Token_GetToken mriToken_GetToken 54 | #define Token_MatchingString mriToken_MatchingString 55 | #define Token_MatchingStringPrefix mriToken_MatchingStringPrefix 56 | #define Token_Copy mriToken_Copy 57 | 58 | #endif /* TOKEN_H_ */ 59 | -------------------------------------------------------------------------------- /core/try_catch.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2012 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Very rough exception handling like macros for C. */ 16 | #include 17 | 18 | int mriExceptionCode; 19 | -------------------------------------------------------------------------------- /core/try_catch.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2014 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Very rough exception handling like macros for C. */ 16 | #ifndef MRI_TRY_CATCH_H_ 17 | #define MRI_TRY_CATCH_H_ 18 | 19 | #define noException 0 20 | #define bufferOverrunException 1 21 | #define invalidHexDigitException 2 22 | #define invalidValueException 3 23 | #define invalidArgumentException 4 24 | #define timeoutException 5 25 | #define invalidIndexException 6 26 | #define notFoundException 7 27 | #define exceededHardwareResourcesException 8 28 | #define invalidDecDigitException 9 29 | #define memFaultException 10 30 | #define mriMaxException 15 31 | 32 | extern int mriExceptionCode; 33 | 34 | 35 | /* Allow an application including MRI to extend with their own exception codes and replace the below declarations. */ 36 | #ifndef MRI_SKIP_TRY_CATCH_MACRO_DEFINES 37 | 38 | /* On Linux, it is possible that __try and __catch are already defined. */ 39 | #undef __try 40 | #undef __catch 41 | 42 | #define __throws 43 | 44 | #define __try \ 45 | do \ 46 | { \ 47 | clearExceptionCode(); 48 | 49 | #define __throwing_func(X) \ 50 | X; \ 51 | if (mriExceptionCode) \ 52 | break; 53 | 54 | #define __catch \ 55 | } while (0); \ 56 | if (mriExceptionCode) 57 | 58 | #define __throw(EXCEPTION) return ((void)setExceptionCode(EXCEPTION)) 59 | 60 | #define __throw_and_return(EXCEPTION, RETURN) return (setExceptionCode(EXCEPTION), (RETURN)) 61 | 62 | #define __rethrow return 63 | 64 | #define __rethrow_and_return(RETURN) return RETURN 65 | 66 | static inline int getExceptionCode(void) 67 | { 68 | return mriExceptionCode; 69 | } 70 | 71 | static inline void setExceptionCode(int exceptionCode) 72 | { 73 | mriExceptionCode = exceptionCode > mriExceptionCode ? exceptionCode : mriExceptionCode; 74 | } 75 | 76 | static inline void clearExceptionCode(void) 77 | { 78 | mriExceptionCode = noException; 79 | } 80 | 81 | #endif /* MRI_SKIP_TRY_CATCH_MACRO_DEFINES */ 82 | #endif /* MRI_TRY_CATCH_H_ */ 83 | -------------------------------------------------------------------------------- /core/version.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef MRI_VERSION_STRING 4 | 5 | #define MRI_BRANCH "https://github.com/adamgreen/mri" 6 | 7 | #define MRI_VERSION_MAJOR 1 8 | #define MRI_VERSION_MINOR 6 9 | #define MRI_VERSION_BUILD 20240815 10 | #define MRI_VERSION_SUBBUILD 0 11 | 12 | #define MRI_STR(X) MRI_STR2(X) 13 | #define MRI_STR2(X) #X 14 | 15 | #define MRI_VERSION_STRING MRI_STR(MRI_VERSION_MAJOR) "." MRI_STR(MRI_VERSION_MINOR) "-" MRI_STR(MRI_VERSION_BUILD) "." MRI_STR(MRI_VERSION_SUBBUILD) 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /deploy: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | GCC4MBED=../gcc4mbed.back/mri 3 | 4 | set -x 5 | 6 | make clean arm 7 | 8 | cp lib/armv7-m/libmri_mbed1768.a $GCC4MBED/ 9 | cp lib/armv7-m/libmri_bambino210.a $GCC4MBED/ 10 | cp lib/armv7-m/libmri_stm32f429-disco.a $GCC4MBED/ 11 | 12 | cp LICENSE $GCC4MBED 13 | cat core/mri.h core/version.h >$GCC4MBED/mri.h 14 | -------------------------------------------------------------------------------- /devices/lpc176x/lpc176x_asm.S: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Implementation of LPC176x UART0 function to be intercepted and sent to mri instead. */ 16 | .text 17 | .code 16 18 | .syntax unified 19 | 20 | 21 | .global UART0_IRQHandler 22 | .weak UART0_IRQHandler 23 | .type UART0_IRQHandler, function 24 | .thumb_func 25 | /* extern "C" void UART0_IRQHandler(void); 26 | Override UART0 exceptions and send to mriExceptionHandler. 27 | */ 28 | UART0_IRQHandler: 29 | b mriExceptionHandler 30 | 31 | .global UART1_IRQHandler 32 | .weak UART1_IRQHandler 33 | .type UART1_IRQHandler, function 34 | .thumb_func 35 | /* extern "C" void UART1_IRQHandler(void); 36 | Override UART1 exceptions and send to mriExceptionHandler. 37 | */ 38 | UART1_IRQHandler: 39 | b mriExceptionHandler 40 | 41 | .global UART2_IRQHandler 42 | .weak UART2_IRQHandler 43 | .type UART2_IRQHandler, function 44 | .thumb_func 45 | /* extern "C" void UART2_IRQHandler(void); 46 | Override UART2 exceptions and send to mriExceptionHandler. 47 | */ 48 | UART2_IRQHandler: 49 | b mriExceptionHandler 50 | 51 | .global UART3_IRQHandler 52 | .weak UART3_IRQHandler 53 | .type UART3_IRQHandler, function 54 | .thumb_func 55 | /* extern "C" void UART3_IRQHandler(void); 56 | Override UART3 exceptions and send to mriExceptionHandler. 57 | */ 58 | UART3_IRQHandler: 59 | b mriExceptionHandler 60 | -------------------------------------------------------------------------------- /devices/lpc176x/lpc176x_init.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Routines used by mri that are specific to the LPC176x device. */ 16 | #include 17 | #include 18 | #include "lpc176x_init.h" 19 | #include 20 | #include 21 | 22 | 23 | static const char g_memoryMapXml[] = "" 24 | "" 25 | "" 26 | " 0x1000" 27 | " 0x8000" 28 | " " 29 | " " 30 | " " 31 | " " 32 | " " 33 | " " 34 | " " 35 | " " 36 | " " 37 | " " 38 | " " 39 | " " 40 | " " 41 | " " 42 | " " 43 | " " 44 | " " 45 | ""; 46 | Lpc176xState mriLpc176xState; 47 | 48 | 49 | /* Reference this handler in the ASM module to make sure that it gets linked in. */ 50 | void UART0_IRQHandler(void); 51 | 52 | 53 | void mriLpc176x_Init(Token* pParameterTokens) 54 | { 55 | /* Reference handler in ASM module to make sure that is gets linked in. */ 56 | void (* volatile dummyReference)(void) = UART0_IRQHandler; 57 | (void)dummyReference; 58 | 59 | __try 60 | mriCortexMInit(pParameterTokens, 0, CANActivity_IRQn); 61 | __catch 62 | __rethrow; 63 | 64 | /* mriCortexInit() sets all interrupts to lower priority than debug monitor. Interrupt for UART used by GDB must be 65 | elevated to the same level as DebugMon_Handler, so initialize it after calling mriCortexInit(). 66 | */ 67 | mriLpc176xUart_Init(pParameterTokens); 68 | } 69 | 70 | 71 | size_t Platform_GetDeviceMemoryMapXmlSize(void) 72 | { 73 | return sizeof(g_memoryMapXml) - 1; 74 | } 75 | 76 | 77 | const char* Platform_GetDeviceMemoryMapXml(void) 78 | { 79 | return g_memoryMapXml; 80 | } 81 | -------------------------------------------------------------------------------- /devices/lpc176x/lpc176x_init.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Routines used by mri that are specific to the LPC176x device. */ 16 | #ifndef LPC176X_H_ 17 | #define LPC176X_H_ 18 | 19 | #include 20 | #include 21 | #include "lpc176x_uart.h" 22 | 23 | /* Flag to indicate whether context will contain FPU registers or not. */ 24 | #define MRI_DEVICE_HAS_FPU 0 25 | 26 | typedef struct 27 | { 28 | const UartConfiguration* pCurrentUart; 29 | } Lpc176xState; 30 | 31 | extern Lpc176xState mriLpc176xState; 32 | 33 | void mriLpc176x_Init(Token* pParameterTokens); 34 | 35 | #endif /* LPC176X_H_ */ 36 | -------------------------------------------------------------------------------- /devices/lpc176x/lpc176x_uart.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2012 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Routines used to provide LPC176x UART functionality to the mri debugger. */ 16 | #ifndef LPC176X_UART_H_ 17 | #define LPC176X_UART_H_ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | typedef struct 24 | { 25 | volatile uint32_t* pPeripheralClockSelection; 26 | volatile uint32_t* pTxPinSelection; 27 | volatile uint32_t* pRxPinSelection; 28 | LPC_UART_TypeDef* pUartRegisters; 29 | uint32_t powerConfigurationBit; 30 | uint32_t peripheralClockSelectionBitmask; 31 | uint32_t txPinSelectionMask; 32 | uint32_t rxPinSelectionMask; 33 | uint32_t pinSelectionValue; 34 | } UartConfiguration; 35 | 36 | void mriLpc176xUart_Init(Token* pParameterTokens); 37 | 38 | #endif /* LPC176X_UART_H_ */ 39 | -------------------------------------------------------------------------------- /devices/lpc43xx/lpc43xx_asm.S: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Implementation of LPC176x UART0 function to be intercepted and sent to mri instead. */ 16 | .text 17 | .code 16 18 | .syntax unified 19 | 20 | 21 | .global USART0_IRQHandler 22 | .weak USART0_IRQHandler 23 | .type USART0_IRQHandler, function 24 | .thumb_func 25 | /* extern "C" void USART0_IRQHandler(void); 26 | Override UART0 exceptions and send to mriExceptionHandler. 27 | */ 28 | USART0_IRQHandler: 29 | b mriExceptionHandler 30 | 31 | .global UART1_IRQHandler 32 | .weak UART1_IRQHandler 33 | .type UART1_IRQHandler, function 34 | .thumb_func 35 | /* extern "C" void UART1_IRQHandler(void); 36 | Override UART1 exceptions and send to mriExceptionHandler. 37 | */ 38 | UART1_IRQHandler: 39 | b mriExceptionHandler 40 | 41 | .global USART2_IRQHandler 42 | .weak USART2_IRQHandler 43 | .type USART2_IRQHandler, function 44 | .thumb_func 45 | /* extern "C" void USART2_IRQHandler(void); 46 | Override UART2 exceptions and send to mriExceptionHandler. 47 | */ 48 | USART2_IRQHandler: 49 | b mriExceptionHandler 50 | 51 | .global USART3_IRQHandler 52 | .weak USART3_IRQHandler 53 | .type USART3_IRQHandler, function 54 | .thumb_func 55 | /* extern "C" void USART3_IRQHandler(void); 56 | Override UART3 exceptions and send to mriExceptionHandler. 57 | */ 58 | USART3_IRQHandler: 59 | b mriExceptionHandler 60 | -------------------------------------------------------------------------------- /devices/lpc43xx/lpc43xx_init.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Routines used by mri that are specific to the LPC176x device. */ 16 | #include 17 | #include 18 | #include "lpc43xx_init.h" 19 | #include 20 | #include 21 | 22 | 23 | static const char g_memoryMapXml4330[] = "" 24 | "" 25 | "" 26 | " 0x400" 27 | " " 28 | " " 29 | " " 30 | " " 31 | ""; 32 | static const char g_memoryMapXml4337[] = "" 33 | "" 34 | "" 35 | " 0x400" 36 | " 0x400" 37 | " " 38 | " " 39 | " " 40 | " " 41 | ""; 42 | Lpc43xxState mriLpc43xxState; 43 | 44 | 45 | 46 | /* Reference this handler in the ASM module to make sure that it gets linked in. */ 47 | void USART0_IRQHandler(void); 48 | 49 | 50 | void mriLpc43xx_Init(Token* pParameterTokens) 51 | { 52 | /* Reference handler in ASM module to make sure that is gets linked in. */ 53 | void (* volatile dummyReference)(void) = USART0_IRQHandler; 54 | (void)dummyReference; 55 | 56 | __try 57 | mriCortexMInit(pParameterTokens, 0, QEI_IRQn); 58 | __catch 59 | __rethrow; 60 | 61 | /* mriCortexInit() sets all interrupts to lower priority than debug monitor. Interrupt for UART used by GDB must be 62 | elevated to the same level as DebugMon_Handler, so initialize it after calling mriCortexInit(). 63 | */ 64 | mriLpc43xxUart_Init(pParameterTokens); 65 | } 66 | 67 | 68 | static int isLpc4337(void); 69 | size_t Platform_GetDeviceMemoryMapXmlSize(void) 70 | { 71 | if (isLpc4337()) 72 | return sizeof(g_memoryMapXml4337) - 1; 73 | else 74 | return sizeof(g_memoryMapXml4330) - 1; 75 | } 76 | 77 | static int isLpc4337(void) 78 | { 79 | /* Code running on the LPC4337 will be in internal FLASH which is at higher address than LPC4330 SPIFI FLASH. */ 80 | return ((uint32_t)mriLpc43xx_Init >= 0x1A000000); 81 | } 82 | 83 | 84 | const char* Platform_GetDeviceMemoryMapXml(void) 85 | { 86 | if (isLpc4337()) 87 | return g_memoryMapXml4337; 88 | else 89 | return g_memoryMapXml4330; 90 | } 91 | -------------------------------------------------------------------------------- /devices/lpc43xx/lpc43xx_init.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Routines used by mri that are specific to the LPC43xx device. */ 16 | #ifndef LPC43XX_H_ 17 | #define LPC43XX_H_ 18 | 19 | #include 20 | #include 21 | #include "lpc43xx_uart.h" 22 | 23 | /* Flag to indicate whether context will contain FPU registers or not. */ 24 | #define MRI_DEVICE_HAS_FPU 1 25 | 26 | typedef struct 27 | { 28 | const UartConfiguration* pCurrentUart; 29 | } Lpc43xxState; 30 | 31 | extern Lpc43xxState mriLpc43xxState; 32 | 33 | void mriLpc43xx_Init(Token* pParameterTokens); 34 | 35 | #endif /* LPC43XX_H_ */ 36 | -------------------------------------------------------------------------------- /devices/lpc43xx/lpc43xx_uart.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Routines used to provide LPC176x UART functionality to the mri debugger. */ 16 | #ifndef LPC43XX_UART_H_ 17 | #define LPC43XX_UART_H_ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #define SCU_PIN(GROUP, NUM) (((GROUP) << 16) | (NUM)) 24 | 25 | typedef struct 26 | { 27 | LPC_USART_T* pUartRegisters; 28 | CGU_BASE_CLK_T baseClock; 29 | CCU_CLK_T registerClock; 30 | CCU_CLK_T peripheralClock; 31 | uint32_t txPin; 32 | uint32_t txFunction; 33 | uint32_t rxPin; 34 | uint32_t rxFunction; 35 | } UartConfiguration; 36 | 37 | void mriLpc43xxUart_Init(Token* pParameterTokens); 38 | 39 | #endif /* LPC43XX_UART_H_ */ 40 | -------------------------------------------------------------------------------- /devices/nrf52/nrf52_init.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2022 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Routines used by mri that are specific to nRF52xxx devices. */ 16 | #include 17 | #include "nrf52_init.h" 18 | #include 19 | #include 20 | #include 21 | 22 | 23 | 24 | static uint32_t parseDebugMonPriorityLevel(Token* pParameterTokens); 25 | void mriNRF52_Init(Token* pParameterTokens) 26 | { 27 | uint32_t debugMonPriorityLevel = parseDebugMonPriorityLevel(pParameterTokens); 28 | 29 | __try 30 | mriCortexMInit(pParameterTokens, debugMonPriorityLevel, FPU_IRQn); 31 | __catch 32 | __rethrow; 33 | 34 | /* mriCortexInit() sets all interrupts to lower priority than debug monitor. Interrupt for UART used by GDB must be 35 | elevated to the same level as DebugMon_Handler, so initialize it after calling mriCortexInit(). 36 | */ 37 | mriNRF52Uart_Init(pParameterTokens, debugMonPriorityLevel); 38 | } 39 | 40 | static uint32_t parseDebugMonPriorityLevel(Token* pParameterTokens) 41 | { 42 | static const char priorityLevelPrefix[] = "MRI_PRIORITY="; 43 | const char* pMatchingPrefix = NULL; 44 | 45 | /* Default the debug monitor to run at the highest priority. */ 46 | uint32_t priorityLevel = 0; 47 | 48 | /* Check for user provided override. */ 49 | if ((pMatchingPrefix = Token_MatchingStringPrefix(pParameterTokens, priorityLevelPrefix)) != NULL) 50 | priorityLevel = uint32FromString(pMatchingPrefix + sizeof(priorityLevelPrefix)-1); 51 | return priorityLevel; 52 | } 53 | 54 | 55 | static uint32_t getDecimalDigit(char currChar); 56 | uint32_t mriNRF52_Uint32FromString(const char* pString) 57 | { 58 | uint32_t value = 0; 59 | 60 | while (*pString) 61 | { 62 | uint32_t digit; 63 | 64 | __try 65 | { 66 | digit = getDecimalDigit(*pString++); 67 | } 68 | __catch 69 | { 70 | clearExceptionCode(); 71 | break; 72 | } 73 | 74 | value = value * 10 + digit; 75 | } 76 | 77 | return value; 78 | } 79 | 80 | static uint32_t getDecimalDigit(char currChar) 81 | { 82 | if (currChar >= '0' && currChar <= '9') 83 | return currChar - '0'; 84 | else 85 | __throw_and_return(invalidDecDigitException, 0); 86 | } 87 | 88 | -------------------------------------------------------------------------------- /devices/nrf52/nrf52_init.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2022 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Routines used by mri that are specific to nRF52xxx devices. */ 16 | #ifndef NRF52_H_ 17 | #define NRF52_H_ 18 | 19 | #include 20 | #include 21 | #include "nrf52_uart.h" 22 | 23 | /* Flag to indicate whether context will contain FPU registers or not. */ 24 | #define MRI_DEVICE_HAS_FPU 1 25 | 26 | 27 | void mriNRF52_Init(Token* pParameterTokens); 28 | 29 | uint32_t mriNRF52_Uint32FromString(const char* pString); 30 | 31 | #define uint32FromString mriNRF52_Uint32FromString 32 | 33 | #endif /* NRF52_H_ */ 34 | -------------------------------------------------------------------------------- /devices/nrf52/nrf52_uart.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2022 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Routines used to provide NRF52xxx UART functionality to the mri debugger. */ 16 | #ifndef NRF52_UART_H_ 17 | #define NRF52_UART_H_ 18 | 19 | #include 20 | #include 21 | 22 | void mriNRF52Uart_Init(Token* pParameterTokens, uint32_t debugMonPriorityLevel); 23 | 24 | #endif /* NRF52_UART_H_ */ 25 | -------------------------------------------------------------------------------- /devices/stm32f411xx/stm32f411xx_asm.S: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 Adam Green (https://github.com/adamgreen/) 2 | Copyright 2015 Chang,Jia-Rung (https://github.com/JaredCJR) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /* Implementation of STM32F411xx USART1 function to be intercepted and sent to mri instead. */ 17 | .text 18 | .code 16 19 | .syntax unified 20 | 21 | 22 | .global USART1_IRQHandler 23 | .weak USART1_IRQHandler 24 | .type USART1_IRQHandler, function 25 | .thumb_func 26 | /* extern "C" void USART1_IRQHandler(void); 27 | Override USART1 exceptions and send to mriExceptionHandler. 28 | */ 29 | USART1_IRQHandler: 30 | b mriExceptionHandler 31 | 32 | 33 | .global USART2_IRQHandler 34 | .weak USART2_IRQHandler 35 | .type USART2_IRQHandler, function 36 | .thumb_func 37 | /* extern "C" void USART2_IRQHandler(void); 38 | Override USART2 exceptions and send to mriExceptionHandler. 39 | */ 40 | USART2_IRQHandler: 41 | b mriExceptionHandler 42 | 43 | -------------------------------------------------------------------------------- /devices/stm32f411xx/stm32f411xx_init.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 Adam Green (https://github.com/adamgreen/) 2 | Copyright 2015 Chang,Jia-Rung (https://github.com/JaredCJR) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /* Routines used by mri that are specific to the STM32F411xx device. */ 17 | #include 18 | #include 19 | #include "stm32f411xx_init.h" 20 | #include 21 | #include 22 | 23 | 24 | static const char g_memoryMapXml[] = 25 | "" 26 | "" 27 | "" 28 | " 0x4000" 29 | " 0x10000" 30 | " 0x20000" 31 | " " 32 | ""; 33 | Stm32f411xxState mriStm32f411xxState; 34 | 35 | 36 | void mriStm32f411xx_Init(Token* pParameterTokens) 37 | { 38 | __try 39 | mriCortexMInit(pParameterTokens, 0, SPI5_IRQn); 40 | __catch 41 | __rethrow; 42 | 43 | /* mriCortexInit() sets all interrupts to lower priority than debug monitor. Interrupt for UART used by GDB must be 44 | elevated to the same level as DebugMon_Handler, so initialize it after calling mriCortexInit(). 45 | */ 46 | mriStm32f411xxUart_Init(pParameterTokens); 47 | } 48 | 49 | 50 | 51 | size_t Platform_GetDeviceMemoryMapXmlSize(void) 52 | { 53 | return sizeof(g_memoryMapXml) - 1; 54 | } 55 | 56 | 57 | const char* Platform_GetDeviceMemoryMapXml(void) 58 | { 59 | return g_memoryMapXml; 60 | } 61 | -------------------------------------------------------------------------------- /devices/stm32f411xx/stm32f411xx_init.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2012 Adam Green (https://github.com/adamgreen/) 2 | Copyright 2015 Chang,Jia-Rung (https://github.com/JaredCJR) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /* Routines used by mri that are specific to the STM32F411xx device. */ 17 | #ifndef STM32F411XX_H_ 18 | #define STM32F411XX_H_ 19 | 20 | #include 21 | #include 22 | #include "stm32f411xx_usart.h" 23 | 24 | /* Flags that can be set in Stm32f411xxState::flags */ 25 | #define STM32F411XX_UART_FLAGS_SHARE 1 26 | #define STM32F411XX_UART_FLAGS_MANUAL_BAUD 2 27 | 28 | /* Flag to indicate whether context will contain FPU registers or not. */ 29 | #define MRI_DEVICE_HAS_FPU 1 30 | 31 | typedef struct 32 | { 33 | const UartConfiguration* pCurrentUart; 34 | uint32_t flags; 35 | } Stm32f411xxState; 36 | 37 | extern Stm32f411xxState mriStm32f411xxState; 38 | 39 | void mriStm32f411xx_Init(Token* pParameterTokens); 40 | 41 | #endif /* STM32F411XX_H_ */ 42 | -------------------------------------------------------------------------------- /devices/stm32f411xx/stm32f411xx_usart.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2012 Adam Green (https://github.com/adamgreen/) 2 | Copyright 2015 Chang,Jia-Rung (https://github.com/JaredCJR) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /* Routines used to provide STM32F429xx USART functionality to the mri debugger. */ 17 | #ifndef STM32F411XX_USART_H_ 18 | #define STM32F411XX_USART_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | typedef struct 25 | { 26 | USART_TypeDef* pUartRegisters; 27 | uint32_t txFunction; 28 | uint32_t rxFunction; 29 | } UartConfiguration; 30 | 31 | 32 | void mriStm32f411xxUart_Init(Token* pParameterTokens); 33 | 34 | #endif /* STM32F411XX_USART_H_ */ 35 | -------------------------------------------------------------------------------- /devices/stm32f429xx/stm32f429xx_asm.S: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 Adam Green (https://github.com/adamgreen/) 2 | Copyright 2015 Chang,Jia-Rung (https://github.com/JaredCJR) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /* Implementation of STM32F429xx USART1 function to be intercepted and sent to mri instead. */ 17 | .text 18 | .code 16 19 | .syntax unified 20 | 21 | 22 | .global USART1_IRQHandler 23 | .weak USART1_IRQHandler 24 | .type USART1_IRQHandler, function 25 | .thumb_func 26 | /* extern "C" void USART1_IRQHandler(void); 27 | Override USART1 exceptions and send to mriExceptionHandler. 28 | */ 29 | USART1_IRQHandler: 30 | b mriExceptionHandler 31 | 32 | 33 | .global USART2_IRQHandler 34 | .weak USART2_IRQHandler 35 | .type USART2_IRQHandler, function 36 | .thumb_func 37 | /* extern "C" void USART2_IRQHandler(void); 38 | Override USART2 exceptions and send to mriExceptionHandler. 39 | */ 40 | USART2_IRQHandler: 41 | b mriExceptionHandler 42 | 43 | 44 | .global USART3_IRQHandler 45 | .weak USART3_IRQHandler 46 | .type USART3_IRQHandler, function 47 | .thumb_func 48 | /* extern "C" void USART3_IRQHandler(void); 49 | Override USART3 exceptions and send to mriExceptionHandler. 50 | */ 51 | USART3_IRQHandler: 52 | b mriExceptionHandler 53 | 54 | -------------------------------------------------------------------------------- /devices/stm32f429xx/stm32f429xx_init.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 Adam Green (https://github.com/adamgreen/) 2 | Copyright 2015 Chang,Jia-Rung (https://github.com/JaredCJR) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /* Routines used by mri that are specific to the STM32F429xx device. */ 17 | #include 18 | #include 19 | #include "stm32f429xx_init.h" 20 | #include 21 | #include 22 | 23 | 24 | static const char g_memoryMapXml[] = "" 25 | "" 26 | "" 27 | " 0x4000" 28 | " 0x10000" 29 | " 0x20000" 30 | " 0x4000" 31 | " 0x10000" 32 | " 0x20000" 33 | " " 34 | " " 35 | " " 36 | ""; 37 | Stm32f429xxState mriStm32f429xxState; 38 | 39 | 40 | /* Reference this handler in the ASM module to make sure that it gets linked in. */ 41 | void USART1_IRQHandler(void); 42 | 43 | 44 | void mriStm32f429xx_Init(Token* pParameterTokens) 45 | { 46 | /* Reference handler in ASM module to make sure that is gets linked in. */ 47 | void (* volatile dummyReference)(void) = USART1_IRQHandler; 48 | (void)dummyReference; 49 | 50 | __try 51 | mriCortexMInit(pParameterTokens, 0, DMA2D_IRQn); 52 | __catch 53 | __rethrow; 54 | 55 | /* mriCortexInit() sets all interrupts to lower priority than debug monitor. Interrupt for UART used by GDB must be 56 | elevated to the same level as DebugMon_Handler, so initialize it after calling mriCortexInit(). 57 | */ 58 | mriStm32f429xxUart_Init(pParameterTokens); 59 | } 60 | 61 | 62 | 63 | size_t Platform_GetDeviceMemoryMapXmlSize(void) 64 | { 65 | return sizeof(g_memoryMapXml) - 1; 66 | } 67 | 68 | 69 | const char* Platform_GetDeviceMemoryMapXml(void) 70 | { 71 | return g_memoryMapXml; 72 | } 73 | -------------------------------------------------------------------------------- /devices/stm32f429xx/stm32f429xx_init.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2012 Adam Green (https://github.com/adamgreen/) 2 | Copyright 2015 Chang,Jia-Rung (https://github.com/JaredCJR) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /* Routines used by mri that are specific to the STM32F429xx device. */ 17 | #ifndef STM32F429XX_H_ 18 | #define STM32F429XX_H_ 19 | 20 | #include 21 | #include 22 | #include "stm32f429xx_usart.h" 23 | 24 | /* Flags that can be set in Stm32f429xxState::flags */ 25 | #define STM32F429XX_UART_FLAGS_SHARE 1 26 | #define STM32F429XX_UART_FLAGS_MANUAL_BAUD 2 27 | 28 | /* Flag to indicate whether context will contain FPU registers or not. */ 29 | #define MRI_DEVICE_HAS_FPU 1 30 | 31 | typedef struct 32 | { 33 | const UartConfiguration* pCurrentUart; 34 | uint32_t flags; 35 | } Stm32f429xxState; 36 | 37 | extern Stm32f429xxState mriStm32f429xxState; 38 | 39 | void mriStm32f429xx_Init(Token* pParameterTokens); 40 | 41 | #endif /* STM32F429XX_H_ */ 42 | -------------------------------------------------------------------------------- /devices/stm32f429xx/stm32f429xx_usart.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2012 Adam Green (https://github.com/adamgreen/) 2 | Copyright 2015 Chang,Jia-Rung (https://github.com/JaredCJR) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /* Routines used to provide STM32F429xx USART functionality to the mri debugger. */ 17 | #ifndef STM32F429XX_USART_H_ 18 | #define STM32F429XX_USART_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | typedef struct 25 | { 26 | USART_TypeDef* pUartRegisters; 27 | uint32_t txFunction; 28 | uint32_t rxFunction; 29 | } UartConfiguration; 30 | 31 | 32 | void mriStm32f429xxUart_Init(Token* pParameterTokens); 33 | 34 | #endif /* STM32F429XX_USART_H_ */ 35 | -------------------------------------------------------------------------------- /memory/native/native-mem.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2023 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Routines to access memory on target device when running on target itself. */ 16 | #include 17 | #include 18 | 19 | uint64_t Platform_MemRead64(uintmri_t address) 20 | { 21 | return *(volatile const uint64_t*)address; 22 | } 23 | 24 | uint32_t Platform_MemRead32(uintmri_t address) 25 | { 26 | return *(volatile const uint32_t*)address; 27 | } 28 | 29 | uint16_t Platform_MemRead16(uintmri_t address) 30 | { 31 | return *(volatile const uint16_t*)address; 32 | } 33 | 34 | uint8_t Platform_MemRead8(uintmri_t address) 35 | { 36 | return *(volatile const uint8_t*)address; 37 | } 38 | 39 | void Platform_MemWrite64(uintmri_t address, uint64_t value) 40 | { 41 | *(volatile uint64_t*)address = value; 42 | } 43 | 44 | void Platform_MemWrite32(uintmri_t address, uint32_t value) 45 | { 46 | *(volatile uint32_t*)address = value; 47 | } 48 | 49 | void Platform_MemWrite16(uintmri_t address, uint16_t value) 50 | { 51 | *(volatile uint16_t*)address = value; 52 | } 53 | 54 | void Platform_MemWrite8(uintmri_t address, uint8_t value) 55 | { 56 | *(volatile uint8_t*)address = value; 57 | } 58 | 59 | uintmri_t Platform_ReadMemory(void* pvBuffer, uintmri_t address, uintmri_t readByteCount) 60 | { 61 | mri_memcpy(pvBuffer, (const void*)address, readByteCount); 62 | return readByteCount; 63 | } 64 | -------------------------------------------------------------------------------- /notes/mri-devices.creole: -------------------------------------------------------------------------------- 1 | =Supported Devices 2 | ==NXP LPC1768 3 | The MRI experience was initially optimized for the [[http://mbed.org/handbook/mbed-NXP-LPC1768|mbed 1768 device]] as the 4 | primary goal was to provide a production quality debug solution for this specific device. This was before mbed had added 5 | the CMSIS-DAP debugging functionality to the device. The project has however been architected so that it already works 6 | on other boards featuring a LPC176x processor and is easy to port to other Cortex-M3/M4 based devices. As long as you 7 | are using a LPX17xx device which doesn't have a JTAG debugger attached and you can connect the PC to one of the UARTs on 8 | the device, MRI should have a good chance of working with it. 9 | 10 | **Note:** When a JTAG debugger is attached to the device, as you have with the LPCXpresso 1769 device, then MRI will 11 | hang during startup and debugging will not be possible. This happens because MRI will assume the JTAG debugger is the 12 | mbed interface chip and attempt to disable it with special semi-host calls. In these scenarios the user should take 13 | advantage of the existing JTAG debugger and skip MRI. 14 | 15 | == Other Devices 16 | Support for other devices has been added over time. The current list of supported devices can be seen in the 17 | [[https://github.com/adamgreen/mri#devices-supported | following table]]. 18 | -------------------------------------------------------------------------------- /notes/mri-platforms.creole: -------------------------------------------------------------------------------- 1 | ==Supported Host Platforms 2 | GDB has been tested to work properly with MRI on the following platforms so far: 3 | * macOS Sierra 4 | * Windows 10 5 | * Ubuntu 16.04 6 | -------------------------------------------------------------------------------- /notes/mri-pros-cons.creole: -------------------------------------------------------------------------------- 1 | =Advantages and Disadvantages 2 | Why use a debug monitor like MRI instead of hardware debugging solutions like JTAG or SWD? When should you consider JTAG or SWD instead? 3 | 4 | ==If You Have It, Really Use It! 5 | Many Cortex-M3/4 based products are likely to already have a serial port exposed for simplistic printf() style of debugging. If the serial port is already available then adding a debug monitor to your code is really just super charging your existing debug channel. For no extra hardware you are getting 99% of the debugging features available from JTAG or SWD solutions. 6 | 7 | ==If They Have It, Use It! 8 | If a Cortex-M3/4 based product should fail in the field on a customer, it is often easier for them to connect via the ubiquitous serial protocol. Without purchasing a JTAG/SWD debug pod they can still connect GDB to your product and extract valuable debugging information. Even during internal and/or beta testing, it is often easier and cheaper to have the tester use the serial protocol for extracting information critical for you to help diagnose an issue. 9 | 10 | ==CMSIS-DAP 11 | ARM's recent introduction of the CMSIS-DAP USB based JTAG/SWD debugging solution is likely to make hardware debugging solutions much cheaper and more common in the future. This could really flip around the advantages currently held by serial solutions like MRI. 12 | 13 | ==UART Conflicts 14 | MRI communicates with GDB via one of the serial ports on the mbed device. Since MRI requires exclusive access to its serial connection, the user must make sure to not use the same serial port from within their application. This may require the use of another serial connection between the user's PC and their mbed through something like this [[http://www.sparkfun.com/products/9717|FTDI USB to TTL serial cable.]] Your makefile can be used to override the mbed serial pins used by MRI. For example to switch to the UART on pins 9 and 10 of the mbed, you could add this line to your makefile:\\ \\{{{MRI_UART=MRI_UART_MBED_P9_P10}}}\\ \\ 15 | You can find all of the supported MRI_UART_* selections in the public mri/mri.h source file. 16 | 17 | If your only contention on the serial port is for printf() output then simply calling the standard C library functions (and never trying to override the baud rate or make other method calls on a Serial object) will allow MRI to intercept the data destined to stdout and redirect it to the GDB console. 18 | 19 | ==Interrupt Priority Conflicts 20 | MRI runs its ISRs at priority level 0 and everything else in the system should run at a lower priority if you want to to be able to debug it. If you never call NVIC_SetPriority() to customize the priorities of your interrupt handlers then you should have no problems. If you do make calls to this function then only use priorities lower than 0 (a value of 1 or greater.) 21 | 22 | ==Memory Resources 23 | Unlike a JTAG debugger, MRI does run on the microcontroller itself. It doesn't use any CPU resources until a breakpoint or other debug event is encountered and you are interacting with it via GDB. It does however take up code space in FLASH (<14k) and data space in RAM (<700 bytes) which could have been otherwise used by your code. 24 | 25 | ==mbed Interface Chip 26 | The mbed interface chip uses the JTAG connection to the LPC1768 to provide special (and very useful) functionality on the mbed. The biggest feature provided is programming via the USB mass storage device. This awesome mbed feature remains intact while you are using the MRI debugging solution. Other runtime features supplied by the interface chip such as obtaining a unique ethernet address for your mbed device and the LocalFileSystem are still available when using MRI but with slightly less fidelity. The ethernet address is still available when MRI is running. If your program does use the LocalFileSystem module to access files on the embedded FLASH drive then they will also be supported by MRI. Calls to fopen, fread, fwrite, and fseek for files in the LocalFileSystem will be redirected to GDB where they provide access to GDB's current directory on the host PC. This does introduce a few limitations to the LocalFileSystem functionality for Debug builds: 27 | 28 | * Slower performance since I/O is being redirected over the serial port to the gdb host computer. 29 | * No directory enumeration support (opendir,readdir,closedir). Calling such functions for the LocalFileSystem while running under MRI will result in stops like: 30 | {{{ 31 | Program received signal SIGTRAP, Trace/breakpoint trap. 32 | 0x00011a00 in mbed::LocalDirHandle::readdir() () 33 | }}} 34 | -------------------------------------------------------------------------------- /notes/mri-report-problem.creole: -------------------------------------------------------------------------------- 1 | ==Hit a Problem! 2 | GDB allows for all of the data sent between your PC and the remote MRI target to be captured to a log file. If you enter the following command in GDB before issuing the "target remote" command then everything for your session will be logged to a file called mri.log in the current directory where GDB was launched: 3 | {{{ 4 | set remotelogfile mri.log 5 | }}} 6 | 7 | Describe as clearly as possible what you were doing when you encountered the problem and then e-mail me this description along with a log file captured as described above. I have an electronic mail account at yahoo.com. The alias I use there is adamgrym. -------------------------------------------------------------------------------- /rtos/rtos_weak.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | #include 16 | 17 | 18 | __attribute__((weak)) uint32_t Platform_RtosGetHaltedThreadId(void) 19 | { 20 | return 0; 21 | } 22 | 23 | __attribute__((weak)) uint32_t Platform_RtosGetFirstThreadId(void) 24 | { 25 | return 0; 26 | } 27 | 28 | __attribute__((weak)) uint32_t Platform_RtosGetNextThreadId(void) 29 | { 30 | return 0; 31 | } 32 | 33 | __attribute__((weak)) const char* Platform_RtosGetExtraThreadInfo(uint32_t threadId) 34 | { 35 | return NULL; 36 | } 37 | 38 | __attribute__((weak)) MriContext* Platform_RtosGetThreadContext(uint32_t threadId) 39 | { 40 | return NULL; 41 | } 42 | 43 | __attribute__((weak)) int Platform_RtosIsThreadActive(uint32_t threadId) 44 | { 45 | return 0; 46 | } 47 | 48 | __attribute__((weak)) int Platform_RtosIsSetThreadStateSupported(void) 49 | { 50 | return 0; 51 | } 52 | 53 | __attribute__((weak)) void Platform_RtosSetThreadState(uint32_t threadId, PlatformThreadState state) 54 | { 55 | } 56 | 57 | __attribute__((weak)) void Platform_RtosRestorePrevThreadState(void) 58 | { 59 | } 60 | -------------------------------------------------------------------------------- /semihost/arm/semihost_arm.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Breakpoint constants shared between assembly language stubs and MRI's semihost hooks. */ 16 | 17 | #ifndef MRI_SEMIHOST_ARM_H_ 18 | #define MRI_SEMIHOST_ARM_H_ 19 | 20 | #define MRI_ARM_SEMIHOST_BKPT_NO 0xab 21 | 22 | #define MRI_ARM_SEMIHOST_OPEN 1 23 | #define MRI_ARM_SEMIHOST_CLOSE 2 24 | #define MRI_ARM_SEMIHOST_WRITE 5 25 | #define MRI_ARM_SEMIHOST_READ 6 26 | #define MRI_ARM_SEMIHOST_IS_TTY 9 27 | #define MRI_ARM_SEMIHOST_SEEK 10 28 | #define MRI_ARM_SEMIHOST_FILE_LENGTH 12 29 | #define MRI_ARM_SEMIHOST_REMOVE 14 30 | #define MRI_ARM_SEMIHOST_RENAME 15 31 | #define MRI_ARM_SEMIHOST_ERR_NO 19 32 | #define MRI_ARM_SEMIHOST_UUID 257 33 | 34 | #endif /* MRI_SEMIHOST_ARM_H_ */ 35 | -------------------------------------------------------------------------------- /semihost/newlib/newlib_stubs.S: -------------------------------------------------------------------------------- 1 | /* Copyright 2022 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Implementation of semihost assembly language routines to be used to redirect standard I/O (stdin/stdout/stderr) 16 | from the newlib library to the MRI debug monitor. */ 17 | #include "newlib_stubs.h" 18 | 19 | .text 20 | .code 16 21 | .syntax unified 22 | 23 | .global mriNewlib_SemihostWrite 24 | .section .text.mriNewlib_SemihostWrite 25 | .type mriNewlib_SemihostWrite, function 26 | /* extern "C" int mriNewlib_SemihostWrite(int file, char *ptr, int len); 27 | Issues semihost write call to PC via gdb. 28 | */ 29 | mriNewlib_SemihostWrite: 30 | bkpt MRI_NEWLIB_SEMIHOST_WRITE 31 | bx lr 32 | 33 | 34 | .global mriNewlib_SemihostRead 35 | .section .text.mriNewlib_SemihostRead 36 | .type mriNewlib_SemihostRead, function 37 | /* extern "C" int mriNewlib_SemihostRead(int file, char *ptr, int len); 38 | Issues semihost read call to PC via gdb. 39 | */ 40 | mriNewlib_SemihostRead: 41 | bkpt MRI_NEWLIB_SEMIHOST_READ 42 | bx lr 43 | 44 | 45 | .global mriNewLib_SemihostOpen 46 | .section .text.mriNewLib_SemihostOpen 47 | .type mriNewLib_SemihostOpen, function 48 | /* extern "C" int mriNewLib_SemihostOpen(const char *pFilename, int flags, int mode); 49 | Issues semihost open file call to PC via gdb. 50 | */ 51 | mriNewLib_SemihostOpen: 52 | bkpt MRI_NEWLIB_SEMIHOST_OPEN 53 | bx lr 54 | 55 | 56 | .global mriNewLib_SemihostRename 57 | .section .text.mriNewLib_SemihostRename 58 | .type mriNewLib_SemihostRename, function 59 | /* extern "C" int mriNewLib_SemihostRename(const char *pOldFilename, const char *pNewFilename); 60 | Issues file rename call to PC via GDB. 61 | */ 62 | mriNewLib_SemihostRename: 63 | bkpt MRI_NEWLIB_SEMIHOST_RENAME 64 | bx lr 65 | 66 | .global mriNewLib_SemihostUnlink 67 | .section .text.mriNewLib_SemihostUnlink 68 | .type mriNewLib_SemihostUnlink, function 69 | /* extern "C" int mriNewLib_SemihostUnlink(const char *pFilename); 70 | Issues file delete (unlink) call to PC via GDB. 71 | */ 72 | mriNewLib_SemihostUnlink: 73 | bkpt MRI_NEWLIB_SEMIHOST_UNLINK 74 | bx lr 75 | 76 | 77 | .global mriNewLib_SemihostStat 78 | .section .text.mriNewLib_SemihostStat 79 | .type mriNewLib_SemihostStat, function 80 | /* extern "C" int mriNewLib_SemihostStat(const char *pFilename, struct stat *pStat); 81 | Issues stat call to PC via GDB. 82 | */ 83 | mriNewLib_SemihostStat: 84 | bkpt MRI_NEWLIB_SEMIHOST_STAT 85 | bx lr 86 | 87 | 88 | .global mriNewlib_SemihostLSeek 89 | .section .text.mriNewlib_SemihostLSeek 90 | .type mriNewlib_SemihostLSeek, function 91 | /* extern "C" int mriNewlib_SemihostLSeek(int file, int offset, int whence); 92 | Issues seek call to PC via GDB. 93 | */ 94 | mriNewlib_SemihostLSeek: 95 | bkpt MRI_NEWLIB_SEMIHOST_LSEEK 96 | bx lr 97 | 98 | 99 | .global mriNewlib_SemihostClose 100 | .section .text.mriNewlib_SemihostClose 101 | .type mriNewlib_SemihostClose, function 102 | /* extern "C" int mriNewlib_SemihostClose(int file); 103 | Issues file close call to PC via GDB. 104 | */ 105 | mriNewlib_SemihostClose: 106 | bkpt MRI_NEWLIB_SEMIHOST_CLOSE 107 | bx lr 108 | 109 | 110 | .global mriNewlib_SemihostFStat 111 | .section .text.mriNewlib_SemihostFStat 112 | .type mriNewlib_SemihostFStat, function 113 | /* extern "C" int mriNewlib_SemihostFStat(int file, struct stat *pStat); 114 | Issues stat call to PC via GDB. 115 | */ 116 | mriNewlib_SemihostFStat: 117 | bkpt MRI_NEWLIB_SEMIHOST_FSTAT 118 | bx lr 119 | 120 | 121 | .global mriNewlib_SemihostGetErrNo 122 | .section .text.mriNewlib_SemihostGetErrNo 123 | .type mriNewlib_SemihostGetErrNo, function 124 | /* extern "C" int mriNewlib_SemihostGetErrNo(); 125 | Retrieves the errno recorded for the last failed newlib semihost call. 126 | */ 127 | mriNewlib_SemihostGetErrNo: 128 | bkpt MRI_NEWLIB_SEMIHOST_GET_ERRNO 129 | bx lr 130 | 131 | 132 | .global mriSetDebuggerHooks 133 | .section .text.mriSetDebuggerHooks 134 | .type mriSetDebuggerHooks, function 135 | /* extern "C" void mriSetDebuggerHooks(MriDebuggerHookPtr pEnteringHook, MriDebuggerHookPtr pLeavingHook, void* pvContext); 136 | Tells MRI which hook functions to call when entering and leaving the debugger. 137 | */ 138 | mriSetDebuggerHooks: 139 | bkpt MRI_NEWLIB_SEMIHOST_SET_HOOKS 140 | bx lr 141 | -------------------------------------------------------------------------------- /semihost/newlib/newlib_stubs.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2022 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Breakpoint constants shared between assembly language stubs and MRI's semihost hooks. */ 16 | 17 | #ifndef MRI_NEWLIB_STUBS_H_ 18 | #define MRI_NEWLIB_STUBS_H_ 19 | 20 | #define MRI_NEWLIB_SEMIHOST_MIN 0xf5 21 | 22 | #define MRI_NEWLIB_SEMIHOST_SET_HOOKS 0xf5 23 | #define MRI_NEWLIB_SEMIHOST_GET_ERRNO 0xf6 24 | #define MRI_NEWLIB_SEMIHOST_WRITE 0xf7 25 | #define MRI_NEWLIB_SEMIHOST_READ 0xf8 26 | #define MRI_NEWLIB_SEMIHOST_OPEN 0xf9 27 | #define MRI_NEWLIB_SEMIHOST_RENAME 0xfa 28 | #define MRI_NEWLIB_SEMIHOST_UNLINK 0xfb 29 | #define MRI_NEWLIB_SEMIHOST_STAT 0xfc 30 | #define MRI_NEWLIB_SEMIHOST_LSEEK 0xfd 31 | #define MRI_NEWLIB_SEMIHOST_CLOSE 0xfe 32 | #define MRI_NEWLIB_SEMIHOST_FSTAT 0xff 33 | 34 | #define MRI_NEWLIB_SEMIHOST_MAX 0xff 35 | 36 | #endif /* MRI_NEWLIB_STUBS_H_ */ 37 | -------------------------------------------------------------------------------- /semihost/semihost.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2022 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | /* Semihost functionality for redirecting operations such as file I/O to the GNU debugger. */ 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | 23 | int Semihost_IsDebuggeeMakingSemihostCall(void) 24 | { 25 | PlatformInstructionType instructionType = Platform_TypeOfCurrentInstruction(); 26 | 27 | return (instructionType == MRI_PLATFORM_INSTRUCTION_ARM_SEMIHOST_CALL || 28 | instructionType == MRI_PLATFORM_INSTRUCTION_NEWLIB_SEMIHOST_CALL); 29 | } 30 | 31 | int Semihost_HandleSemihostRequest(void) 32 | { 33 | PlatformInstructionType instructionType = Platform_TypeOfCurrentInstruction(); 34 | PlatformSemihostParameters parameters = Platform_GetSemihostCallParameters(); 35 | 36 | if (instructionType == MRI_PLATFORM_INSTRUCTION_ARM_SEMIHOST_CALL) 37 | return Semihost_HandleArmSemihostRequest(¶meters); 38 | else if (instructionType == MRI_PLATFORM_INSTRUCTION_NEWLIB_SEMIHOST_CALL) 39 | return Semihost_HandleNewlibSemihostRequest(¶meters); 40 | else 41 | return 0; 42 | } 43 | 44 | 45 | static int writeToGdbConsole(const TransferParameters* pParameters); 46 | int Semihost_WriteToFileOrConsole(const TransferParameters* pParameters) 47 | { 48 | const uint32_t STDOUT_FILE_NO = 1; 49 | if (pParameters->fileDescriptor == STDOUT_FILE_NO) 50 | { 51 | return writeToGdbConsole(pParameters); 52 | } 53 | return IssueGdbFileWriteRequest(pParameters); 54 | } 55 | 56 | static int writeToGdbConsole(const TransferParameters* pParameters) 57 | { 58 | const char* pBuffer = (const char*)pParameters->bufferAddress; 59 | size_t length = pParameters->bufferSize; 60 | 61 | size_t charsWritten = WriteSizedStringToGdbConsole(pBuffer, length); 62 | 63 | SetSemihostReturnValues(charsWritten, 0); 64 | FlagSemihostCallAsHandled(); 65 | 66 | if (WasControlCEncountered()) 67 | { 68 | SetSignalValue(SIGINT); 69 | return 0; 70 | } 71 | return 1; 72 | } 73 | -------------------------------------------------------------------------------- /tests/globalchk: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | echo Checking ../lib/armv7-m/libmri_mbed1768.a 3 | arm-none-eabi-nm -g --defined-only ../lib/armv7-m/libmri_mbed1768.a | grep "........ . .*" | grep -v "........ . mri.*" | grep -v "........ . .*_.*Handler$" 4 | arm-none-eabi-nm -u ../lib/armv7-m/libmri_mbed1768.a | grep "........ . .*" | grep -v "........ . mri.*" | grep -v "........ . .*_.*Handler$" | grep -v "........ . SystemCoreClock$" | sort -u 5 | echo Checking ../lib/armv7-m/libmri_bambino210.a 6 | arm-none-eabi-nm -g --defined-only ../lib/armv7-m/libmri_bambino210.a | grep "........ . .*" | grep -v "........ . mri.*" | grep -v "........ . .*_.*Handler$" 7 | arm-none-eabi-nm -u ../lib/armv7-m/libmri_bambino210.a | grep "........ . .*" | grep -v "........ . mri.*" | grep -v "........ . .*_.*Handler$" | grep -v "........ . SystemCoreClock$" | sort -u 8 | echo Checking ../lib/armv7-m/libmri_nrf52dk_fpu_soft.a 9 | arm-none-eabi-nm -g --defined-only ../lib/armv7-m/libmri_nrf52dk_fpu_soft.a | grep "........ . .*" | grep -v "........ . mri.*" | grep -v "........ . .*_.*Handler$" 10 | arm-none-eabi-nm -u ../lib/armv7-m/libmri_nrf52dk_fpu_soft.a | grep "........ . .*" | grep -v "........ . mri.*" | grep -v "........ . .*_.*Handler$" | grep -v "........ . SystemCoreClock$" | sort -u 11 | echo Checking ../lib/armv7-m/libmri_nrf52dk_fpu_hard.a 12 | arm-none-eabi-nm -g --defined-only ../lib/armv7-m/libmri_nrf52dk_fpu_hard.a | grep "........ . .*" | grep -v "........ . mri.*" | grep -v "........ . .*_.*Handler$" 13 | arm-none-eabi-nm -u ../lib/armv7-m/libmri_nrf52dk_fpu_hard.a | grep "........ . .*" | grep -v "........ . mri.*" | grep -v "........ . .*_.*Handler$" | grep -v "........ . SystemCoreClock$" | sort -u 14 | echo Checking ../lib/armv7-m/libmri_stm32f429-disco.a 15 | arm-none-eabi-nm -g --defined-only ../lib/armv7-m/libmri_stm32f429-disco.a | grep "........ . .*" | grep -v "........ . mri.*" | grep -v "........ . .*_.*Handler$" 16 | arm-none-eabi-nm -u ../lib/armv7-m/libmri_stm32f429-disco.a | grep "........ . .*" | grep -v "........ . mri.*" | grep -v "........ . .*_.*Handler$" | grep -v "........ . SystemCoreClock$" | sort -u 17 | echo Checking ../lib/armv7-m/libmri_stm32f411-blackpill.a 18 | arm-none-eabi-nm -g --defined-only ../lib/armv7-m/libmri_stm32f411-blackpill.a | grep "........ . .*" | grep -v "........ . mri.*" | grep -v "........ . .*_.*Handler$" 19 | arm-none-eabi-nm -u ../lib/armv7-m/libmri_stm32f411-blackpill.a | grep "........ . .*" | grep -v "........ . mri.*" | grep -v "........ . .*_.*Handler$" | grep -v "........ . SystemCoreClock$" | sort -u 20 | -------------------------------------------------------------------------------- /tests/tests/AllTests.cpp: -------------------------------------------------------------------------------- 1 | #include "CppUTest/CommandLineTestRunner.h" 2 | 3 | int main(int argc, char** argv) 4 | { 5 | return CommandLineTestRunner::RunAllTests(argc, argv); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /tests/tests/gdb_consoleTests.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2022 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | extern "C" 17 | { 18 | #include 19 | #include 20 | #include 21 | } 22 | #include 23 | 24 | // Include C++ headers for test harness. 25 | #include "CppUTest/TestHarness.h" 26 | 27 | 28 | TEST_GROUP(gdbConsole) 29 | { 30 | int m_expectedException; 31 | 32 | void setup() 33 | { 34 | m_expectedException = noException; 35 | platformMock_Init(); 36 | mriInit("MRI_UART_MBED_USB"); 37 | } 38 | 39 | void teardown() 40 | { 41 | LONGS_EQUAL ( m_expectedException, getExceptionCode() ); 42 | clearExceptionCode(); 43 | platformMock_Uninit(); 44 | } 45 | 46 | void validateExceptionCode(int expectedExceptionCode) 47 | { 48 | m_expectedException = expectedExceptionCode; 49 | LONGS_EQUAL ( expectedExceptionCode, getExceptionCode() ); 50 | } 51 | }; 52 | 53 | TEST(gdbConsole, WriteStringToGdbConsole_SendAsGdbPacket) 54 | { 55 | size_t charsWritten = WriteStringToGdbConsole("Test\n"); 56 | LONGS_EQUAL( 5, charsWritten ); 57 | STRCMP_EQUAL ( platformMock_CommChecksumData("$O546573740a#"), platformMock_CommGetTransmittedData() ); 58 | } 59 | 60 | TEST(gdbConsole, WriteStringToGdbConsole_TruncateWriteBecauseOfSmallBuffer) 61 | { 62 | platformMock_SetPacketBufferSize(1+2*4+4); 63 | size_t charsWritten = WriteStringToGdbConsole("Test\n"); 64 | LONGS_EQUAL ( 4, charsWritten ); 65 | STRCMP_EQUAL ( platformMock_CommChecksumData("$O54657374#"), platformMock_CommGetTransmittedData() ); 66 | } 67 | 68 | TEST(gdbConsole, WriteHexValueToGdbConsole_SendMinimumValue) 69 | { 70 | WriteHexValueToGdbConsole(0); 71 | STRCMP_EQUAL ( platformMock_CommChecksumData("$O30783030#"), platformMock_CommGetTransmittedData() ); 72 | } 73 | 74 | TEST(gdbConsole, WriteHexValueToGdbConsole_SendMaximumValue) 75 | { 76 | WriteHexValueToGdbConsole(~0U); 77 | STRCMP_EQUAL ( platformMock_CommChecksumData("$O30786666666666666666#"), platformMock_CommGetTransmittedData() ); 78 | } 79 | -------------------------------------------------------------------------------- /tests/tests/hex_convertTests.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2012 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | extern "C" 17 | { 18 | #include 19 | } 20 | 21 | // Include C++ headers for test harness. 22 | #include "CppUTest/TestHarness.h" 23 | 24 | TEST_GROUP(HexConvert) 25 | { 26 | void setup() 27 | { 28 | } 29 | 30 | void teardown() 31 | { 32 | } 33 | }; 34 | 35 | TEST(HexConvert, ExtractLowNibble) 36 | { 37 | uint8_t value = 0xaf; 38 | 39 | LONGS_EQUAL( 0xf, EXTRACT_LO_NIBBLE(value) ); 40 | } 41 | 42 | TEST(HexConvert, ExtractHighNibble) 43 | { 44 | uint8_t value = 0xfa; 45 | 46 | LONGS_EQUAL( 0xf, EXTRACT_HI_NIBBLE(value) ); 47 | } 48 | 49 | TEST(HexConvert, NibbleToHexChar0) 50 | { 51 | uint8_t nibble = 0x0; 52 | 53 | BYTES_EQUAL( '0', NibbleToHexChar[nibble] ); 54 | } 55 | 56 | TEST(HexConvert, NibbleToHexCharF) 57 | { 58 | uint8_t nibble = 0xF; 59 | 60 | BYTES_EQUAL( 'f', NibbleToHexChar[nibble] ); 61 | } 62 | 63 | TEST(HexConvert, HexCharToNibble_0) 64 | { 65 | __try 66 | { 67 | BYTES_EQUAL( 0, HexCharToNibble('0') ); 68 | } 69 | __catch 70 | { 71 | FAIL( "HexCharToNibble threw unexpected exception." ); 72 | } 73 | } 74 | 75 | TEST(HexConvert, HexCharToNibble_9) 76 | { 77 | __try 78 | { 79 | BYTES_EQUAL( 9, HexCharToNibble('9') ); 80 | } 81 | __catch 82 | { 83 | FAIL( "HexCharToNibble threw unexpected exception." ); 84 | } 85 | } 86 | 87 | TEST(HexConvert, HexCharToNibble_a) 88 | { 89 | __try 90 | { 91 | BYTES_EQUAL( 0xa, HexCharToNibble('a') ); 92 | } 93 | __catch 94 | { 95 | FAIL( "HexCharToNibble threw unexpected exception." ); 96 | } 97 | } 98 | 99 | TEST(HexConvert, HexCharToNibble_f) 100 | { 101 | __try 102 | { 103 | BYTES_EQUAL( 0xf, HexCharToNibble('f') ); 104 | } 105 | __catch 106 | { 107 | FAIL( "HexCharToNibble threw unexpected exception." ); 108 | } 109 | } 110 | 111 | TEST(HexConvert, HexCharToNibble_A) 112 | { 113 | __try 114 | { 115 | BYTES_EQUAL( 0xa, HexCharToNibble('A') ); 116 | } 117 | __catch 118 | { 119 | FAIL( "HexCharToNibble threw unexpected exception." ); 120 | } 121 | } 122 | 123 | TEST(HexConvert, HexCharToNibble_F) 124 | { 125 | __try 126 | { 127 | BYTES_EQUAL( 0xf, HexCharToNibble('F') ); 128 | } 129 | __catch 130 | { 131 | FAIL( "HexCharToNibble threw unexpected exception." ); 132 | } 133 | } 134 | 135 | TEST(HexConvert, HexCharToNibble_InvalidG) 136 | { 137 | int value; 138 | int exceptionThrown = 0; 139 | 140 | __try 141 | value = HexCharToNibble('G'); 142 | __catch 143 | exceptionThrown = 1; 144 | 145 | LONGS_EQUAL( -1, value ); 146 | CHECK_TRUE( exceptionThrown ); 147 | LONGS_EQUAL( invalidHexDigitException, getExceptionCode() ); 148 | } 149 | 150 | TEST(HexConvert, HexCharToNibble_Invalidg) 151 | { 152 | int value; 153 | int exceptionThrown = 0; 154 | 155 | __try 156 | value = HexCharToNibble('g'); 157 | __catch 158 | exceptionThrown = 1; 159 | 160 | LONGS_EQUAL( -1, value ); 161 | CHECK_TRUE( exceptionThrown ); 162 | LONGS_EQUAL( invalidHexDigitException, getExceptionCode() ); 163 | } 164 | -------------------------------------------------------------------------------- /tests/tests/nativememTests.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | #include 16 | #include 17 | 18 | extern "C" 19 | { 20 | #include 21 | } 22 | 23 | // Include C++ headers for test harness. 24 | #include "CppUTest/TestHarness.h" 25 | 26 | TEST_GROUP(NativeMem) 27 | { 28 | void setup() 29 | { 30 | } 31 | 32 | void teardown() 33 | { 34 | } 35 | }; 36 | 37 | TEST(NativeMem, Platform_MemoryRead) 38 | { 39 | const uint8_t srcBuffer[8] = { 0, 1, 2, 3, 4, 5, 6, 7 }; 40 | uint8_t destBuffer[8] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; 41 | 42 | uintmri_t bytesRead = Platform_ReadMemory(destBuffer, (uintmri_t)&srcBuffer[0], sizeof(destBuffer)); 43 | CHECK_EQUAL(sizeof(destBuffer), bytesRead); 44 | CHECK_EQUAL(0, memcmp(destBuffer, srcBuffer, sizeof(destBuffer))); 45 | } 46 | -------------------------------------------------------------------------------- /tests/tests/try_catchTests.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2012 Adam Green (https://github.com/adamgreen/) 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | extern "C" 17 | { 18 | #include 19 | } 20 | 21 | // Include C++ headers for test harness. 22 | #include "CppUTest/TestHarness.h" 23 | 24 | TEST_GROUP(TryCatch) 25 | { 26 | int m_exceptionThrown; 27 | 28 | void setup() 29 | { 30 | m_exceptionThrown = 0; 31 | } 32 | 33 | void teardown() 34 | { 35 | } 36 | 37 | void flagExceptionHit() 38 | { 39 | m_exceptionThrown = 1; 40 | } 41 | 42 | void throwNoException() 43 | { 44 | } 45 | 46 | void throwBufferAndArgumentExceptions() 47 | { 48 | throwBufferOverrunException(); 49 | throwInvalidArgumentException(); 50 | } 51 | 52 | void throwArgumentAndBufferExceptions() 53 | { 54 | throwInvalidArgumentException(); 55 | throwBufferOverrunException(); 56 | } 57 | 58 | void throwBufferOverrunException() 59 | { 60 | __throw(bufferOverrunException); 61 | } 62 | 63 | void throwInvalidArgumentException() 64 | { 65 | __throw(invalidArgumentException); 66 | } 67 | 68 | int throwBufferOverrunExceptionAndReturnNegative1() 69 | { 70 | __throw_and_return(bufferOverrunException, -1); 71 | } 72 | 73 | void rethrowBufferOverrunException() 74 | { 75 | __try 76 | throwBufferOverrunException(); 77 | __catch 78 | __rethrow; 79 | __throw(invalidArgumentException); 80 | } 81 | 82 | int rethrowBufferOverrunExceptionAndReturnNegative1() 83 | { 84 | __try 85 | throwBufferOverrunException(); 86 | __catch 87 | __rethrow_and_return(-1); 88 | __throw_and_return(invalidArgumentException, 0); 89 | } 90 | 91 | void validateException(int expectedExceptionCode) 92 | { 93 | if (expectedExceptionCode == noException) 94 | { 95 | CHECK_FALSE(m_exceptionThrown); 96 | } 97 | else 98 | { 99 | CHECK_TRUE(m_exceptionThrown); 100 | } 101 | LONGS_EQUAL(expectedExceptionCode, getExceptionCode()); 102 | } 103 | }; 104 | 105 | TEST(TryCatch, NoException) 106 | { 107 | __try 108 | throwNoException(); 109 | __catch 110 | flagExceptionHit(); 111 | validateException(noException); 112 | } 113 | 114 | TEST(TryCatch, bufferOverrunException) 115 | { 116 | __try 117 | throwBufferOverrunException(); 118 | __catch 119 | flagExceptionHit(); 120 | validateException(bufferOverrunException); 121 | } 122 | 123 | TEST(TryCatch, EscalatingExceptions) 124 | { 125 | __try 126 | throwBufferAndArgumentExceptions(); 127 | __catch 128 | flagExceptionHit(); 129 | 130 | validateException(invalidArgumentException); 131 | } 132 | 133 | TEST(TryCatch, NonEscalatingExceptions) 134 | { 135 | __try 136 | throwArgumentAndBufferExceptions(); 137 | __catch 138 | flagExceptionHit(); 139 | 140 | validateException(invalidArgumentException); 141 | } 142 | 143 | TEST(TryCatch, CatchFirstThrow) 144 | { 145 | __try 146 | { 147 | __throwing_func( throwBufferOverrunException() ); 148 | __throwing_func( throwInvalidArgumentException() ); 149 | } 150 | __catch 151 | { 152 | flagExceptionHit(); 153 | } 154 | 155 | validateException(bufferOverrunException); 156 | } 157 | 158 | TEST(TryCatch, CatchSecondThrow) 159 | { 160 | __try 161 | { 162 | __throwing_func( throwNoException() ); 163 | __throwing_func( throwInvalidArgumentException() ); 164 | } 165 | __catch 166 | { 167 | flagExceptionHit(); 168 | } 169 | 170 | validateException(invalidArgumentException); 171 | } 172 | 173 | TEST(TryCatch, ThrowAndReturn) 174 | { 175 | int value; 176 | 177 | __try 178 | value = throwBufferOverrunExceptionAndReturnNegative1(); 179 | __catch 180 | flagExceptionHit(); 181 | 182 | LONGS_EQUAL( -1, value ); 183 | validateException(bufferOverrunException); 184 | } 185 | 186 | TEST(TryCatch, RethrowBufferOverrunException) 187 | { 188 | __try 189 | rethrowBufferOverrunException(); 190 | __catch 191 | flagExceptionHit(); 192 | validateException(bufferOverrunException); 193 | } 194 | 195 | TEST(TryCatch, RethrowBufferOverrunExceptionAndReturnNegative1) 196 | { 197 | int value; 198 | 199 | __try 200 | value = rethrowBufferOverrunExceptionAndReturnNegative1(); 201 | __catch 202 | flagExceptionHit(); 203 | 204 | LONGS_EQUAL( -1, value ); 205 | validateException(bufferOverrunException); 206 | } 207 | --------------------------------------------------------------------------------