Skip to content

Commit f1cd896

Browse files
committed
Pull in newer MRI code
The MRI file layout has been updated to be more compatible with the Arduino build system. Rather than adding core/ to the INCLUDE path, the root of the MRI project is instead added and the core/ is explicitly prepended to the header names when #include'ing them. I updated the copyright messages to use my github account URL instead of the mbed URL. I also use #include <> and #include "" more consistently than I did previously. Note: This commit also includes the removal of a lot of trailing whitespace that my old editor setup used to leave around in my source files. Update MRI version to 1.1 for changes being worked on for this Portenta project.
1 parent c6f5d35 commit f1cd896

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+366
-366
lines changed

libraries/MRI/src/architectures/armv7-m/armv7-m.c

+47-47
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2017 Adam Green (http://mbed.org/users/AdamGreen/)
1+
/* Copyright 2017 Adam Green (https://github.com/adamgreen/)
22
33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.
@@ -16,8 +16,8 @@
1616
#include <errno.h>
1717
#include <string.h>
1818
#include <signal.h>
19-
#include "core/platforms.h"
20-
#include "core/gdb_console.h"
19+
#include <core/platforms.h>
20+
#include <core/gdb_console.h>
2121
#include "debug_cm3.h"
2222
#include "armv7-m.h"
2323

@@ -60,7 +60,7 @@ CortexMState __mriCortexMState;
6060
<reg name="xpsr" bitsize="32" regnum="25"/>
6161
</feature>
6262
*/
63-
static const char g_targetXml[] =
63+
static const char g_targetXml[] =
6464
"<?xml version=\"1.0\"?>\n"
6565
"<!DOCTYPE feature SYSTEM \"gdb-target.dtd\">\n"
6666
"<target>\n"
@@ -201,7 +201,7 @@ void Platform_EnableSingleStep(void)
201201
enableSingleStep();
202202
return;
203203
}
204-
204+
205205
__try
206206
{
207207
__throwing_func( setHardwareBreakpointOnSvcHandler() );
@@ -223,7 +223,7 @@ static int doesPCPointToSVCInstruction(void)
223223
static const uint16_t svcMachineCodeMask = 0xff00;
224224
static const uint16_t svcMachineCode = 0xdf00;
225225
uint16_t instructionWord;
226-
226+
227227
__try
228228
{
229229
instructionWord = getFirstHalfWordOfCurrentInstruction();
@@ -233,7 +233,7 @@ static int doesPCPointToSVCInstruction(void)
233233
clearExceptionCode();
234234
return 0;
235235
}
236-
236+
237237
return ((instructionWord & svcMachineCodeMask) == svcMachineCode);
238238
}
239239

@@ -270,7 +270,7 @@ static int doesPCPointToBASEPRIUpdateInstruction(void)
270270
{
271271
uint16_t firstWord = 0;
272272
uint16_t secondWord = 0;
273-
273+
274274
__try
275275
{
276276
__throwing_func( firstWord = getFirstHalfWordOfCurrentInstruction() );
@@ -281,7 +281,7 @@ static int doesPCPointToBASEPRIUpdateInstruction(void)
281281
clearExceptionCode();
282282
return 0;
283283
}
284-
284+
285285
return isFirstHalfWordOfMSR(firstWord) && isSecondHalfWordOfMSRModifyingBASEPRI(secondWord);
286286
}
287287

@@ -371,7 +371,7 @@ static uint8_t determineCauseOfDebugEvent(void);
371371
uint8_t Platform_DetermineCauseOfException(void)
372372
{
373373
uint32_t exceptionNumber = getCurrentlyExecutingExceptionNumber();
374-
374+
375375
switch(exceptionNumber)
376376
{
377377
case 2:
@@ -419,7 +419,7 @@ static uint8_t determineCauseOfDebugEvent(void)
419419
};
420420
uint32_t debugFaultStatus = SCB->DFSR;
421421
size_t i;
422-
422+
423423
for (i = 0 ; i < sizeof(debugEventToSignalMap)/sizeof(debugEventToSignalMap[0]) ; i++)
424424
{
425425
if (debugFaultStatus & debugEventToSignalMap[i].statusBit)
@@ -428,7 +428,7 @@ static uint8_t determineCauseOfDebugEvent(void)
428428
return debugEventToSignalMap[i].signalToReturn;
429429
}
430430
}
431-
431+
432432
/* NOTE: Default catch all signal is SIGSTOP. */
433433
return SIGSTOP;
434434
}
@@ -470,11 +470,11 @@ static void displayHardFaultCauseToGdbConsole(void)
470470
static const uint32_t forcedBit = 1 << 30;
471471
static const uint32_t vectorTableReadBit = 1 << 1;
472472
uint32_t hardFaultStatusRegister = SCB->HFSR;
473-
473+
474474
WriteStringToGdbConsole("\n**Hard Fault**");
475475
WriteStringToGdbConsole("\n Status Register: ");
476476
WriteHexValueToGdbConsole(hardFaultStatusRegister);
477-
477+
478478
if (hardFaultStatusRegister & debugEventBit)
479479
WriteStringToGdbConsole("\n Debug Event");
480480

@@ -499,15 +499,15 @@ static void displayMemFaultCauseToGdbConsole(void)
499499
static const uint32_t dataAccess = 1 << 1;
500500
static const uint32_t instructionFetch = 1;
501501
uint32_t memManageFaultStatusRegister = SCB->CFSR & 0xFF;
502-
502+
503503
/* Check to make sure that there is a memory fault to display. */
504504
if (memManageFaultStatusRegister == 0)
505505
return;
506-
506+
507507
WriteStringToGdbConsole("\n**MPU Fault**");
508508
WriteStringToGdbConsole("\n Status Register: ");
509509
WriteHexValueToGdbConsole(memManageFaultStatusRegister);
510-
510+
511511
if (memManageFaultStatusRegister & MMARValidBit)
512512
{
513513
WriteStringToGdbConsole("\n Fault Address: ");
@@ -543,15 +543,15 @@ static void displayBusFaultCauseToGdbConsole(void)
543543
static const uint32_t preciseDataAccessBit = 1 << 1;
544544
static const uint32_t instructionPrefetch = 1;
545545
uint32_t busFaultStatusRegister = (SCB->CFSR >> 8) & 0xFF;
546-
546+
547547
/* Check to make sure that there is a bus fault to display. */
548548
if (busFaultStatusRegister == 0)
549549
return;
550-
550+
551551
WriteStringToGdbConsole("\n**Bus Fault**");
552552
WriteStringToGdbConsole("\n Status Register: ");
553553
WriteHexValueToGdbConsole(busFaultStatusRegister);
554-
554+
555555
if (busFaultStatusRegister & BFARValidBit)
556556
{
557557
WriteStringToGdbConsole("\n Fault Address: ");
@@ -589,15 +589,15 @@ static void displayUsageFaultCauseToGdbConsole(void)
589589
static const uint32_t invalidStateBit = 1 << 1;
590590
static const uint32_t undefinedInstructionBit = 1;
591591
uint32_t usageFaultStatusRegister = SCB->CFSR >> 16;
592-
592+
593593
/* Make sure that there is a usage fault to display. */
594594
if (usageFaultStatusRegister == 0)
595595
return;
596-
596+
597597
WriteStringToGdbConsole("\n**Usage Fault**");
598598
WriteStringToGdbConsole("\n Status Register: ");
599599
WriteHexValueToGdbConsole(usageFaultStatusRegister);
600-
600+
601601
if (usageFaultStatusRegister & divideByZeroBit)
602602
WriteStringToGdbConsole("\n Divide by Zero");
603603

@@ -647,7 +647,7 @@ static void configureMpuToAccessAllMemoryWithNoCaching(void)
647647
{
648648
saveOriginalMpuConfiguration();
649649
disableMPU();
650-
configureHighestMpuRegionToAccessAllMemoryWithNoCaching();
650+
configureHighestMpuRegionToAccessAllMemoryWithNoCaching();
651651
enableMPUWithHardAndNMIFaults();
652652
}
653653

@@ -667,7 +667,7 @@ static void configureHighestMpuRegionToAccessAllMemoryWithNoCaching(void)
667667
static const uint32_t regionSizeAt4GB = 31 << MPU_RASR_SIZE_SHIFT; /* 4GB = 2^(31+1) */
668668
static const uint32_t regionEnable = MPU_RASR_ENABLE;
669669
static const uint32_t regionSizeAndAttributes = regionReadWrite | regionSizeAt4GB | regionEnable;
670-
670+
671671
prepareToAccessMPURegion(getHighestMPUDataRegionIndex());
672672
setMPURegionAddress(regionToStartAtAddress0);
673673
setMPURegionAttributeAndSize(regionSizeAndAttributes);
@@ -749,7 +749,7 @@ static void checkStack(void)
749749
uint32_t* pCurr = (uint32_t*)__mriCortexMState.debuggerStack;
750750
uint8_t* pEnd = (uint8_t*)__mriCortexMState.debuggerStack + sizeof(__mriCortexMState.debuggerStack);
751751
int spaceUsed;
752-
752+
753753
while ((uint8_t*)pCurr < pEnd && *pCurr == CORTEXM_DEBUGGER_STACK_FILL)
754754
pCurr++;
755755

@@ -775,7 +775,7 @@ static int isInstruction32Bit(uint16_t firstWordOfInstruction);
775775
void Platform_AdvanceProgramCounterToNextInstruction(void)
776776
{
777777
uint16_t firstWordOfCurrentInstruction;
778-
778+
779779
__try
780780
{
781781
firstWordOfCurrentInstruction = getFirstHalfWordOfCurrentInstruction();
@@ -786,7 +786,7 @@ void Platform_AdvanceProgramCounterToNextInstruction(void)
786786
clearExceptionCode();
787787
return;
788788
}
789-
789+
790790
if (isInstruction32Bit(firstWordOfCurrentInstruction))
791791
{
792792
/* 32-bit Instruction. */
@@ -802,8 +802,8 @@ void Platform_AdvanceProgramCounterToNextInstruction(void)
802802
static int isInstruction32Bit(uint16_t firstWordOfInstruction)
803803
{
804804
uint16_t maskedOffUpper5BitsOfWord = firstWordOfInstruction & 0xF800;
805-
806-
/* 32-bit instructions start with 0b11101, 0b11110, 0b11111 according to page A5-152 of the
805+
806+
/* 32-bit instructions start with 0b11101, 0b11110, 0b11111 according to page A5-152 of the
807807
ARMv7-M Architecture Manual. */
808808
return (maskedOffUpper5BitsOfWord == 0xE800 ||
809809
maskedOffUpper5BitsOfWord == 0xF000 ||
@@ -823,7 +823,7 @@ static int isInstructionHardcodedBreakpoint(uint16_t instruction);
823823
PlatformInstructionType Platform_TypeOfCurrentInstruction(void)
824824
{
825825
uint16_t currentInstruction;
826-
826+
827827
__try
828828
{
829829
currentInstruction = getFirstHalfWordOfCurrentInstruction();
@@ -834,7 +834,7 @@ PlatformInstructionType Platform_TypeOfCurrentInstruction(void)
834834
clearExceptionCode();
835835
return MRI_PLATFORM_INSTRUCTION_OTHER;
836836
}
837-
837+
838838
if (isInstructionMbedSemihostBreakpoint(currentInstruction))
839839
return MRI_PLATFORM_INSTRUCTION_MBED_SEMIHOST_CALL;
840840
else if (isInstructionNewlibSemihostBreakpoint(currentInstruction))
@@ -870,12 +870,12 @@ static int isInstructionHardcodedBreakpoint(uint16_t instruction)
870870
PlatformSemihostParameters Platform_GetSemihostCallParameters(void)
871871
{
872872
PlatformSemihostParameters parameters;
873-
873+
874874
parameters.parameter1 = __mriCortexMState.context.R0;
875875
parameters.parameter2 = __mriCortexMState.context.R1;
876876
parameters.parameter3 = __mriCortexMState.context.R2;
877877
parameters.parameter4 = __mriCortexMState.context.R3;
878-
878+
879879
return parameters;
880880
}
881881

@@ -891,12 +891,12 @@ void Platform_SetSemihostCallReturnAndErrnoValues(int returnValue, int err)
891891
int Platform_WasMemoryFaultEncountered(void)
892892
{
893893
int wasFaultEncountered;
894-
894+
895895
__DSB();
896896
wasFaultEncountered = __mriCortexMState.flags & CORTEXM_FLAGS_FAULT_DURING_DEBUG;
897897
clearMemoryFaultFlag();
898-
899-
return wasFaultEncountered;
898+
899+
return wasFaultEncountered;
900900
}
901901

902902

@@ -922,7 +922,7 @@ static void writeBytesToBufferAsHex(Buffer* pBuffer, void* pBytes, size_t byteCo
922922
{
923923
uint8_t* pByte = (uint8_t*)pBytes;
924924
size_t i;
925-
925+
926926
for (i = 0 ; i < byteCount ; i++)
927927
Buffer_WriteByteAsHex(pBuffer, *pByte++);
928928
}
@@ -944,7 +944,7 @@ static void readBytesFromBufferAsHex(Buffer* pBuffer, void* pBytes, size_t byteC
944944
{
945945
uint8_t* pByte = (uint8_t*)pBytes;
946946
size_t i;
947-
947+
948948
for (i = 0 ; i < byteCount; i++)
949949
*pByte++ = Buffer_ReadByteAsHex(pBuffer);
950950
}
@@ -955,12 +955,12 @@ void Platform_SetHardwareBreakpoint(uint32_t address, uint32_t kind)
955955
{
956956
uint32_t* pFPBBreakpointComparator;
957957
int is32BitInstruction;
958-
958+
959959
__try
960960
is32BitInstruction = doesKindIndicate32BitInstruction(kind);
961961
__catch
962962
__rethrow;
963-
963+
964964
pFPBBreakpointComparator = enableFPBBreakpoint(address, is32BitInstruction);
965965
if (!pFPBBreakpointComparator)
966966
__throw(exceededHardwareResourcesException);
@@ -984,12 +984,12 @@ static int doesKindIndicate32BitInstruction(uint32_t kind)
984984
void Platform_ClearHardwareBreakpoint(uint32_t address, uint32_t kind)
985985
{
986986
int is32BitInstruction;
987-
987+
988988
__try
989989
is32BitInstruction = doesKindIndicate32BitInstruction(kind);
990990
__catch
991991
__rethrow;
992-
992+
993993
disableFPBBreakpointComparator(address, is32BitInstruction);
994994
}
995995

@@ -999,10 +999,10 @@ void Platform_SetHardwareWatchpoint(uint32_t address, uint32_t size, PlatformWat
999999
{
10001000
uint32_t nativeType = convertWatchpointTypeToCortexMType(type);
10011001
DWT_COMP_Type* pComparator;
1002-
1002+
10031003
if (!isValidDWTComparatorSetting(address, size, nativeType))
10041004
__throw(invalidArgumentException);
1005-
1005+
10061006
pComparator = enableDWTWatchpoint(address, size, nativeType);
10071007
if (!pComparator)
10081008
__throw(exceededHardwareResourcesException);
@@ -1027,10 +1027,10 @@ static uint32_t convertWatchpointTypeToCortexMType(PlatformWatchpointType type)
10271027
void Platform_ClearHardwareWatchpoint(uint32_t address, uint32_t size, PlatformWatchpointType type)
10281028
{
10291029
uint32_t nativeType = convertWatchpointTypeToCortexMType(type);
1030-
1030+
10311031
if (!isValidDWTComparatorSetting(address, size, nativeType))
10321032
__throw(invalidArgumentException);
1033-
1033+
10341034
disableDWTWatchpoint(address, size, nativeType);
10351035
}
10361036

libraries/MRI/src/architectures/armv7-m/armv7-m.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2017 Adam Green (http://mbed.org/users/AdamGreen/)
1+
/* Copyright 2017 Adam Green (https://github.com/adamgreen/)
22
33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.
@@ -49,7 +49,7 @@
4949
#endif
5050

5151
#include <stdint.h>
52-
#include "core/token.h"
52+
#include <core/token.h>
5353

5454
/* NOTE: The MriExceptionHandler function definition in mriasm.S is dependent on the layout of this structure. It
5555
is also dictated by the version of gdb which supports the ARM processors. It should only be changed if the
@@ -118,7 +118,7 @@ typedef struct
118118
#endif
119119
} Context;
120120

121-
/* NOTE: The largest buffer is required for receiving the 'G' command which receives the contents of the registers from
121+
/* NOTE: The largest buffer is required for receiving the 'G' command which receives the contents of the registers from
122122
the debugger as two hex digits per byte. Also need a character for the 'G' command itself. */
123123
#define CORTEXM_PACKET_BUFFER_SIZE (1 + 2 * sizeof(Context))
124124

0 commit comments

Comments
 (0)