summaryrefslogtreecommitdiff
path: root/libcpu/arm/common/backtrace.c
blob: f61c69ef013da9ce100c9563b842c877d7130af2 (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
/*
 * Copyright (c) 2006-2018, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2008-07-29     Bernard      first version from QiuYi implementation
 */

#include <rtthread.h>

#ifdef __GNUC__
/*
-->High Address,Stack Top
PC<-----|
LR	 	 |
IP	 	 |
FP	 	 |
......		 |
PC<-|	 |
LR	 |	 |
IP	 |	 |
FP---|-- |
......	 |
PC	 |
LR	 |
IP 	 |
FP---
-->Low Address,Stack Bottom
*/
void rt_hw_backtrace(rt_uint32_t *fp, rt_uint32_t thread_entry)
{
	rt_uint32_t i, pc, func_entry;

	pc = *fp;
	rt_kprintf("[0x%x]\n", pc-0xC);

	for(i=0; i<10; i++)
	{
		fp = (rt_uint32_t *)*(fp - 3);
		pc = *fp ;

		func_entry = pc - 0xC;

		if(func_entry <= 0x30000000) break;

		if(func_entry == thread_entry)
		{
			rt_kprintf("EntryPoint:0x%x\n", func_entry);

			break;
		}

		rt_kprintf("[0x%x]\n", func_entry);
	}
}
#else
void rt_hw_backtrace(rt_uint32_t *fp, rt_uint32_t thread_entry)
{
	/* old compiler implementation */
}
#endif