1
- /* Copyright 2017 Adam Green (http ://mbed.org/users/AdamGreen /)
1
+ /* Copyright 2017 Adam Green (https ://github.com/adamgreen /)
2
2
3
3
Licensed under the Apache License, Version 2.0 (the "License");
4
4
you may not use this file except in compliance with the License.
16
16
#include <errno.h>
17
17
#include <string.h>
18
18
#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>
21
21
#include "debug_cm3.h"
22
22
#include "armv7-m.h"
23
23
@@ -60,7 +60,7 @@ CortexMState __mriCortexMState;
60
60
<reg name="xpsr" bitsize="32" regnum="25"/>
61
61
</feature>
62
62
*/
63
- static const char g_targetXml [] =
63
+ static const char g_targetXml [] =
64
64
"<?xml version=\"1.0\"?>\n"
65
65
"<!DOCTYPE feature SYSTEM \"gdb-target.dtd\">\n"
66
66
"<target>\n"
@@ -201,7 +201,7 @@ void Platform_EnableSingleStep(void)
201
201
enableSingleStep ();
202
202
return ;
203
203
}
204
-
204
+
205
205
__try
206
206
{
207
207
__throwing_func ( setHardwareBreakpointOnSvcHandler () );
@@ -223,7 +223,7 @@ static int doesPCPointToSVCInstruction(void)
223
223
static const uint16_t svcMachineCodeMask = 0xff00 ;
224
224
static const uint16_t svcMachineCode = 0xdf00 ;
225
225
uint16_t instructionWord ;
226
-
226
+
227
227
__try
228
228
{
229
229
instructionWord = getFirstHalfWordOfCurrentInstruction ();
@@ -233,7 +233,7 @@ static int doesPCPointToSVCInstruction(void)
233
233
clearExceptionCode ();
234
234
return 0 ;
235
235
}
236
-
236
+
237
237
return ((instructionWord & svcMachineCodeMask ) == svcMachineCode );
238
238
}
239
239
@@ -270,7 +270,7 @@ static int doesPCPointToBASEPRIUpdateInstruction(void)
270
270
{
271
271
uint16_t firstWord = 0 ;
272
272
uint16_t secondWord = 0 ;
273
-
273
+
274
274
__try
275
275
{
276
276
__throwing_func ( firstWord = getFirstHalfWordOfCurrentInstruction () );
@@ -281,7 +281,7 @@ static int doesPCPointToBASEPRIUpdateInstruction(void)
281
281
clearExceptionCode ();
282
282
return 0 ;
283
283
}
284
-
284
+
285
285
return isFirstHalfWordOfMSR (firstWord ) && isSecondHalfWordOfMSRModifyingBASEPRI (secondWord );
286
286
}
287
287
@@ -371,7 +371,7 @@ static uint8_t determineCauseOfDebugEvent(void);
371
371
uint8_t Platform_DetermineCauseOfException (void )
372
372
{
373
373
uint32_t exceptionNumber = getCurrentlyExecutingExceptionNumber ();
374
-
374
+
375
375
switch (exceptionNumber )
376
376
{
377
377
case 2 :
@@ -419,7 +419,7 @@ static uint8_t determineCauseOfDebugEvent(void)
419
419
};
420
420
uint32_t debugFaultStatus = SCB -> DFSR ;
421
421
size_t i ;
422
-
422
+
423
423
for (i = 0 ; i < sizeof (debugEventToSignalMap )/sizeof (debugEventToSignalMap [0 ]) ; i ++ )
424
424
{
425
425
if (debugFaultStatus & debugEventToSignalMap [i ].statusBit )
@@ -428,7 +428,7 @@ static uint8_t determineCauseOfDebugEvent(void)
428
428
return debugEventToSignalMap [i ].signalToReturn ;
429
429
}
430
430
}
431
-
431
+
432
432
/* NOTE: Default catch all signal is SIGSTOP. */
433
433
return SIGSTOP ;
434
434
}
@@ -470,11 +470,11 @@ static void displayHardFaultCauseToGdbConsole(void)
470
470
static const uint32_t forcedBit = 1 << 30 ;
471
471
static const uint32_t vectorTableReadBit = 1 << 1 ;
472
472
uint32_t hardFaultStatusRegister = SCB -> HFSR ;
473
-
473
+
474
474
WriteStringToGdbConsole ("\n**Hard Fault**" );
475
475
WriteStringToGdbConsole ("\n Status Register: " );
476
476
WriteHexValueToGdbConsole (hardFaultStatusRegister );
477
-
477
+
478
478
if (hardFaultStatusRegister & debugEventBit )
479
479
WriteStringToGdbConsole ("\n Debug Event" );
480
480
@@ -499,15 +499,15 @@ static void displayMemFaultCauseToGdbConsole(void)
499
499
static const uint32_t dataAccess = 1 << 1 ;
500
500
static const uint32_t instructionFetch = 1 ;
501
501
uint32_t memManageFaultStatusRegister = SCB -> CFSR & 0xFF ;
502
-
502
+
503
503
/* Check to make sure that there is a memory fault to display. */
504
504
if (memManageFaultStatusRegister == 0 )
505
505
return ;
506
-
506
+
507
507
WriteStringToGdbConsole ("\n**MPU Fault**" );
508
508
WriteStringToGdbConsole ("\n Status Register: " );
509
509
WriteHexValueToGdbConsole (memManageFaultStatusRegister );
510
-
510
+
511
511
if (memManageFaultStatusRegister & MMARValidBit )
512
512
{
513
513
WriteStringToGdbConsole ("\n Fault Address: " );
@@ -543,15 +543,15 @@ static void displayBusFaultCauseToGdbConsole(void)
543
543
static const uint32_t preciseDataAccessBit = 1 << 1 ;
544
544
static const uint32_t instructionPrefetch = 1 ;
545
545
uint32_t busFaultStatusRegister = (SCB -> CFSR >> 8 ) & 0xFF ;
546
-
546
+
547
547
/* Check to make sure that there is a bus fault to display. */
548
548
if (busFaultStatusRegister == 0 )
549
549
return ;
550
-
550
+
551
551
WriteStringToGdbConsole ("\n**Bus Fault**" );
552
552
WriteStringToGdbConsole ("\n Status Register: " );
553
553
WriteHexValueToGdbConsole (busFaultStatusRegister );
554
-
554
+
555
555
if (busFaultStatusRegister & BFARValidBit )
556
556
{
557
557
WriteStringToGdbConsole ("\n Fault Address: " );
@@ -589,15 +589,15 @@ static void displayUsageFaultCauseToGdbConsole(void)
589
589
static const uint32_t invalidStateBit = 1 << 1 ;
590
590
static const uint32_t undefinedInstructionBit = 1 ;
591
591
uint32_t usageFaultStatusRegister = SCB -> CFSR >> 16 ;
592
-
592
+
593
593
/* Make sure that there is a usage fault to display. */
594
594
if (usageFaultStatusRegister == 0 )
595
595
return ;
596
-
596
+
597
597
WriteStringToGdbConsole ("\n**Usage Fault**" );
598
598
WriteStringToGdbConsole ("\n Status Register: " );
599
599
WriteHexValueToGdbConsole (usageFaultStatusRegister );
600
-
600
+
601
601
if (usageFaultStatusRegister & divideByZeroBit )
602
602
WriteStringToGdbConsole ("\n Divide by Zero" );
603
603
@@ -647,7 +647,7 @@ static void configureMpuToAccessAllMemoryWithNoCaching(void)
647
647
{
648
648
saveOriginalMpuConfiguration ();
649
649
disableMPU ();
650
- configureHighestMpuRegionToAccessAllMemoryWithNoCaching ();
650
+ configureHighestMpuRegionToAccessAllMemoryWithNoCaching ();
651
651
enableMPUWithHardAndNMIFaults ();
652
652
}
653
653
@@ -667,7 +667,7 @@ static void configureHighestMpuRegionToAccessAllMemoryWithNoCaching(void)
667
667
static const uint32_t regionSizeAt4GB = 31 << MPU_RASR_SIZE_SHIFT ; /* 4GB = 2^(31+1) */
668
668
static const uint32_t regionEnable = MPU_RASR_ENABLE ;
669
669
static const uint32_t regionSizeAndAttributes = regionReadWrite | regionSizeAt4GB | regionEnable ;
670
-
670
+
671
671
prepareToAccessMPURegion (getHighestMPUDataRegionIndex ());
672
672
setMPURegionAddress (regionToStartAtAddress0 );
673
673
setMPURegionAttributeAndSize (regionSizeAndAttributes );
@@ -749,7 +749,7 @@ static void checkStack(void)
749
749
uint32_t * pCurr = (uint32_t * )__mriCortexMState .debuggerStack ;
750
750
uint8_t * pEnd = (uint8_t * )__mriCortexMState .debuggerStack + sizeof (__mriCortexMState .debuggerStack );
751
751
int spaceUsed ;
752
-
752
+
753
753
while ((uint8_t * )pCurr < pEnd && * pCurr == CORTEXM_DEBUGGER_STACK_FILL )
754
754
pCurr ++ ;
755
755
@@ -775,7 +775,7 @@ static int isInstruction32Bit(uint16_t firstWordOfInstruction);
775
775
void Platform_AdvanceProgramCounterToNextInstruction (void )
776
776
{
777
777
uint16_t firstWordOfCurrentInstruction ;
778
-
778
+
779
779
__try
780
780
{
781
781
firstWordOfCurrentInstruction = getFirstHalfWordOfCurrentInstruction ();
@@ -786,7 +786,7 @@ void Platform_AdvanceProgramCounterToNextInstruction(void)
786
786
clearExceptionCode ();
787
787
return ;
788
788
}
789
-
789
+
790
790
if (isInstruction32Bit (firstWordOfCurrentInstruction ))
791
791
{
792
792
/* 32-bit Instruction. */
@@ -802,8 +802,8 @@ void Platform_AdvanceProgramCounterToNextInstruction(void)
802
802
static int isInstruction32Bit (uint16_t firstWordOfInstruction )
803
803
{
804
804
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
807
807
ARMv7-M Architecture Manual. */
808
808
return (maskedOffUpper5BitsOfWord == 0xE800 ||
809
809
maskedOffUpper5BitsOfWord == 0xF000 ||
@@ -823,7 +823,7 @@ static int isInstructionHardcodedBreakpoint(uint16_t instruction);
823
823
PlatformInstructionType Platform_TypeOfCurrentInstruction (void )
824
824
{
825
825
uint16_t currentInstruction ;
826
-
826
+
827
827
__try
828
828
{
829
829
currentInstruction = getFirstHalfWordOfCurrentInstruction ();
@@ -834,7 +834,7 @@ PlatformInstructionType Platform_TypeOfCurrentInstruction(void)
834
834
clearExceptionCode ();
835
835
return MRI_PLATFORM_INSTRUCTION_OTHER ;
836
836
}
837
-
837
+
838
838
if (isInstructionMbedSemihostBreakpoint (currentInstruction ))
839
839
return MRI_PLATFORM_INSTRUCTION_MBED_SEMIHOST_CALL ;
840
840
else if (isInstructionNewlibSemihostBreakpoint (currentInstruction ))
@@ -870,12 +870,12 @@ static int isInstructionHardcodedBreakpoint(uint16_t instruction)
870
870
PlatformSemihostParameters Platform_GetSemihostCallParameters (void )
871
871
{
872
872
PlatformSemihostParameters parameters ;
873
-
873
+
874
874
parameters .parameter1 = __mriCortexMState .context .R0 ;
875
875
parameters .parameter2 = __mriCortexMState .context .R1 ;
876
876
parameters .parameter3 = __mriCortexMState .context .R2 ;
877
877
parameters .parameter4 = __mriCortexMState .context .R3 ;
878
-
878
+
879
879
return parameters ;
880
880
}
881
881
@@ -891,12 +891,12 @@ void Platform_SetSemihostCallReturnAndErrnoValues(int returnValue, int err)
891
891
int Platform_WasMemoryFaultEncountered (void )
892
892
{
893
893
int wasFaultEncountered ;
894
-
894
+
895
895
__DSB ();
896
896
wasFaultEncountered = __mriCortexMState .flags & CORTEXM_FLAGS_FAULT_DURING_DEBUG ;
897
897
clearMemoryFaultFlag ();
898
-
899
- return wasFaultEncountered ;
898
+
899
+ return wasFaultEncountered ;
900
900
}
901
901
902
902
@@ -922,7 +922,7 @@ static void writeBytesToBufferAsHex(Buffer* pBuffer, void* pBytes, size_t byteCo
922
922
{
923
923
uint8_t * pByte = (uint8_t * )pBytes ;
924
924
size_t i ;
925
-
925
+
926
926
for (i = 0 ; i < byteCount ; i ++ )
927
927
Buffer_WriteByteAsHex (pBuffer , * pByte ++ );
928
928
}
@@ -944,7 +944,7 @@ static void readBytesFromBufferAsHex(Buffer* pBuffer, void* pBytes, size_t byteC
944
944
{
945
945
uint8_t * pByte = (uint8_t * )pBytes ;
946
946
size_t i ;
947
-
947
+
948
948
for (i = 0 ; i < byteCount ; i ++ )
949
949
* pByte ++ = Buffer_ReadByteAsHex (pBuffer );
950
950
}
@@ -955,12 +955,12 @@ void Platform_SetHardwareBreakpoint(uint32_t address, uint32_t kind)
955
955
{
956
956
uint32_t * pFPBBreakpointComparator ;
957
957
int is32BitInstruction ;
958
-
958
+
959
959
__try
960
960
is32BitInstruction = doesKindIndicate32BitInstruction (kind );
961
961
__catch
962
962
__rethrow ;
963
-
963
+
964
964
pFPBBreakpointComparator = enableFPBBreakpoint (address , is32BitInstruction );
965
965
if (!pFPBBreakpointComparator )
966
966
__throw (exceededHardwareResourcesException );
@@ -984,12 +984,12 @@ static int doesKindIndicate32BitInstruction(uint32_t kind)
984
984
void Platform_ClearHardwareBreakpoint (uint32_t address , uint32_t kind )
985
985
{
986
986
int is32BitInstruction ;
987
-
987
+
988
988
__try
989
989
is32BitInstruction = doesKindIndicate32BitInstruction (kind );
990
990
__catch
991
991
__rethrow ;
992
-
992
+
993
993
disableFPBBreakpointComparator (address , is32BitInstruction );
994
994
}
995
995
@@ -999,10 +999,10 @@ void Platform_SetHardwareWatchpoint(uint32_t address, uint32_t size, PlatformWat
999
999
{
1000
1000
uint32_t nativeType = convertWatchpointTypeToCortexMType (type );
1001
1001
DWT_COMP_Type * pComparator ;
1002
-
1002
+
1003
1003
if (!isValidDWTComparatorSetting (address , size , nativeType ))
1004
1004
__throw (invalidArgumentException );
1005
-
1005
+
1006
1006
pComparator = enableDWTWatchpoint (address , size , nativeType );
1007
1007
if (!pComparator )
1008
1008
__throw (exceededHardwareResourcesException );
@@ -1027,10 +1027,10 @@ static uint32_t convertWatchpointTypeToCortexMType(PlatformWatchpointType type)
1027
1027
void Platform_ClearHardwareWatchpoint (uint32_t address , uint32_t size , PlatformWatchpointType type )
1028
1028
{
1029
1029
uint32_t nativeType = convertWatchpointTypeToCortexMType (type );
1030
-
1030
+
1031
1031
if (!isValidDWTComparatorSetting (address , size , nativeType ))
1032
1032
__throw (invalidArgumentException );
1033
-
1033
+
1034
1034
disableDWTWatchpoint (address , size , nativeType );
1035
1035
}
1036
1036
0 commit comments