summaryrefslogtreecommitdiff
path: root/ports/cortex_m7/ghs/src/txr_ghs.c
blob: 19572e2b1febc3c5e15ecae028fda9ac4d2c384c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 *            ThreadX API Runtime Error Support
 *
 *      Copyright 1983-2019 Green Hills Software LLC.
 *
 *  This program is the property of Green Hills Software LLC.,
 *  its contents are proprietary information and no part of it
 *  is to be disclosed to anyone except employees of Green Hills
 *  Software LLC., or as agreed in writing signed by the President
 *  of Green Hills Software LLC.
 */

/* #include "tx_ghs.h" */
#ifndef TX_DISABLE_ERROR_CHECKING
#define TX_DISABLE_ERROR_CHECKING
#endif
#include "tx_api.h"

/* Customized ThreadX API runtime error support routine. */

void _rnerr(int num, int linenum, const char*str, void*ptr, ...);

/* __ghs_rnerr()
   This is the custom runtime error checking routine.
   This implementation uses the existing __rnerr() routine.
   Another implementation could use the .syscall mechanism,
   provided MULTI was modified to understand that.
 */
void __ghs_rnerr(char *errMsg, int stackLevels, int stackTraceDisplay, void *hexVal) {
    TX_INTERRUPT_SAVE_AREA
    int num;
    /*
       Initialize the stack levels value.

       Add 3 to account for the calls to _rnerr, __rnerr, and
       __ghs_rnerr.

       If the implementation changes, calls to __ghs_rnerr
       will not need to be changed.

       Zero is not permitted, so substitute 3 in that case.
       */
    num = (stackLevels+3) & 0xf;
    if (!num) {
        num = 3;
    }
    /*
       Shift the stack levels value to bits 12..15 and
       insert the stack trace display value in bit 11.
       Bits 0..10 are unused.
     */
    num = (num << 12) | (stackTraceDisplay ? 0x800 : 0);

    /* This will mask all interrupts in the RTEC code, which is probably
       unacceptable for many targets. */
    TX_DISABLE
    _rnerr(num, -1, (const char *)hexVal, (void *)errMsg);
    TX_RESTORE
}


/* ThreadX thread stack checking runtime support routine. */

extern char              __ghsbegin_stack[];
extern TX_THREAD        *_tx_thread_current_ptr;

void __stkchk(void) {
    int i;
    if(_tx_thread_current_ptr)
    {
        if((unsigned)(&i) <=
                (unsigned)(_tx_thread_current_ptr -> tx_thread_stack_start))
        {
            _rnerr(21, -1, 0, 0);
        }
    }
    else
    {
        if((unsigned)(&i) <= (unsigned)__ghsbegin_stack)
        {
            _rnerr(21, -1, 0, 0);
        }
    }
}