-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d5e23d
commit e374ee4
Showing
29 changed files
with
426 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
#ifdef __cplusplus | ||
extern "C" void abort_with_message(const char*); | ||
#else | ||
extern void abort_with_message(const char*); | ||
#endif | ||
|
||
#define xstr(s) str(s) | ||
#define str(s) #s | ||
|
||
#define assert(x) \ | ||
if(!(x)) abort_with_message("Assertion \"" #x "\" failed! file: \"" __FILE__ "\" line:" xstr(__LINE__)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#pragma once | ||
#include "assert.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#pragma once | ||
#include "limits.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#pragma once | ||
#include "stddef.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#pragma once | ||
#include "stdint.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
#include "stdlib.h" | ||
|
||
#ifdef __cplusplus | ||
namespace std { | ||
inline void abort() { | ||
::abort(); | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#pragma once | ||
#include "string.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#pragma once | ||
|
||
#undef CHAR_BIT | ||
#define CHAR_BIT __CHAR_BIT__ | ||
|
||
/* Maximum length of a multibyte character. */ | ||
#ifndef MB_LEN_MAX | ||
#define MB_LEN_MAX 1 | ||
#endif | ||
|
||
/* Minimum and maximum values a `signed char' can hold. */ | ||
#undef SCHAR_MIN | ||
#define SCHAR_MIN (-SCHAR_MAX - 1) | ||
#undef SCHAR_MAX | ||
#define SCHAR_MAX __SCHAR_MAX__ | ||
|
||
/* Maximum value an `unsigned char' can hold. (Minimum is 0). */ | ||
#undef UCHAR_MAX | ||
#define UCHAR_MAX (SCHAR_MAX * 2 + 1) | ||
|
||
/* Minimum and maximum values a `char' can hold. */ | ||
#ifdef __CHAR_UNSIGNED__ | ||
# undef CHAR_MIN | ||
# if __SCHAR_MAX__ == __INT_MAX__ | ||
# define CHAR_MIN 0U | ||
# else | ||
# define CHAR_MIN 0 | ||
# endif | ||
# undef CHAR_MAX | ||
# define CHAR_MAX UCHAR_MAX | ||
#else | ||
# undef CHAR_MIN | ||
# define CHAR_MIN SCHAR_MIN | ||
# undef CHAR_MAX | ||
# define CHAR_MAX SCHAR_MAX | ||
#endif | ||
|
||
/* Minimum and maximum values a `signed short int' can hold. */ | ||
#undef SHRT_MIN | ||
#define SHRT_MIN (-SHRT_MAX - 1) | ||
#undef SHRT_MAX | ||
#define SHRT_MAX __SHRT_MAX__ | ||
|
||
#define USHRT_MAX (SHRT_MAX * 2 + 1) | ||
|
||
/* Minimum and maximum values a `signed int' can hold. */ | ||
#undef INT_MIN | ||
#define INT_MIN (-INT_MAX - 1) | ||
#undef INT_MAX | ||
#define INT_MAX __INT_MAX__ | ||
|
||
/* Maximum value an `unsigned int' can hold. (Minimum is 0). */ | ||
#undef UINT_MAX | ||
#define UINT_MAX (INT_MAX * 2U + 1U) | ||
|
||
/* Minimum and maximum values a `signed long int' can hold. | ||
(Same as `int'). */ | ||
#undef LONG_MIN | ||
#define LONG_MIN (-LONG_MAX - 1L) | ||
#undef LONG_MAX | ||
#define LONG_MAX __LONG_MAX__ | ||
|
||
/* Maximum value an `unsigned long int' can hold. (Minimum is 0). */ | ||
#undef ULONG_MAX | ||
#define ULONG_MAX (LONG_MAX * 2UL + 1UL) | ||
|
||
# undef LLONG_MIN | ||
# define LLONG_MIN (-LLONG_MAX - 1LL) | ||
# undef LLONG_MAX | ||
# define LLONG_MAX __LONG_LONG_MAX__ | ||
|
||
/* Maximum value an `unsigned long long int' can hold. (Minimum is 0). */ | ||
# undef ULLONG_MAX | ||
# define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
#pragma once | ||
#include <stddef.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
extern size_t strlen(const char* str); | ||
extern void* memset(void* ptr, int value, size_t num); | ||
extern void* memcpy(void* destination, const void* source, size_t num); | ||
extern int memcmp(const void* destination, const void* source, size_t num); | ||
|
||
extern int strcmp(const char* str1, const char* str2); | ||
extern char * strchr ( const char *, int ); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,54 @@ | ||
#include "util/trace.h" | ||
#include "threadx_api/txm_module.h" | ||
#include <cstdint> | ||
|
||
#define TRACE_TAG "abort" | ||
|
||
void backtrace() { | ||
if(_txm_module_kernel_call_dispatcher == NULL) return; | ||
|
||
uint32_t* fp = 0; | ||
asm volatile("mov %0, fp":"=r"(fp)); | ||
uint32_t lr = 0; | ||
asm volatile("mov %0, lr":"=r"(lr)); | ||
|
||
TX_THREAD *cthread = tx_thread_identify(); | ||
char* name = NULL; | ||
if(cthread == NULL || tx_thread_info_get(cthread, &name, NULL, NULL, NULL, NULL, NULL, NULL, NULL) != TX_SUCCESS) | ||
TRACE("failed to get thread name\r\n"); | ||
else TRACE("backtrace of thread %x %s\r\n", cthread, name); | ||
|
||
TRACE("fp=%x lr=%x\r\n", fp, lr); | ||
if(fp == NULL || fp[0] != lr) { | ||
TRACE("fp does not match link register, compile with frame pointer enabled!\r\n"); | ||
return; | ||
} | ||
|
||
int i=0; | ||
uint32_t pc = 0; | ||
asm volatile("mov %0, pc":"=r"(pc)); | ||
TRACE("[%d] %x\r\n", i++, pc); | ||
while(fp != NULL && fp[0] > 0x42000000 && fp[0] < 0x42300000) { | ||
TRACE("[%d] %x\r\n", i++, fp[0]); | ||
fp = (uint32_t*)fp[1]; | ||
} | ||
TRACE("done\r\n"); | ||
} | ||
|
||
void abort(void) { | ||
if(_txm_module_kernel_call_dispatcher) TRACE("abort called\r\n"); | ||
backtrace(); | ||
while(_txm_module_kernel_call_dispatcher) { | ||
tx_thread_sleep(100); | ||
} | ||
for(;;) {} | ||
} | ||
|
||
void abort_with_message(const char* msg) { | ||
if(msg && _txm_module_kernel_call_dispatcher) TRACE("abort called: %s\r\n", msg); | ||
backtrace(); | ||
while(_txm_module_kernel_call_dispatcher) { | ||
tx_thread_sleep(100); | ||
} | ||
for(;;) {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.