-
Notifications
You must be signed in to change notification settings - Fork 31
/
print_bt.h.S
68 lines (59 loc) · 1.49 KB
/
print_bt.h.S
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
/*
* print_bt.h.S -- Print the backtrace of a function
*
* Copyright (C) Youness Alaoui (KaKaRoTo)
*
* This software is distributed under the terms of the GNU General Public
* License ("GPL") version 3, as published by the Free Software Foundation.
*
*/
#ifndef __PRINT_BT_H_S__
#define __PRINT_BT_H_S__
/*
* print_backtrace:
* @buffer: %r3 must contain a pointer to a buffer to be filled with the BT
* @len: %r4 must contain the max size of the buffer
*
* This will use the stack to look for the call chain and print the backtrace
* in @buffer up to the top of the backtrace or until @buffer is filled with
* @len bytes
* The format will be a packed list of 64bit pointers to the previous callers
* in the backtrace, in reverse order (first pointer is the function calling
* you, etc..)
* The backtrace does not include the function that called print_backtrace.
*
*/
print_backtrace:
mr %r5, %r1
l_print_backtrace_next:
ld %r5, 0(%r5)
cmpldi %r5, 0
beq l_print_backtrace_done
ld %r6, 0x10(%r5)
std %r6, 0(%r3)
addi %r3, %r3, 0x08
addi %r4, %r4, -0x08
cmpldi %r4, 0
bne l_print_backtrace_next
l_print_backtrace_done:
blr
bt_buffer:
.space 0x50
send_bt:
mflr %r0
stdu %r1, -0xA0(%r1)
std %r0, 0x70(%r1)
std %r31, 0x90(%r1)
MEM_BASE (%r31)
LOAD_LABEL2 (%r3, %r31, bt_buffer)
li %r4, 0x50
bl print_backtrace
LOAD_LABEL2 (%r3, %r31, bt_buffer)
li %r4, 0x50
bl send_eth
ld %r31, 0x90(%r1)
ld %r0, 0x70(%r1)
addi %r1, %r1, 0xA0
mtlr %r0
blr
#endif /* __PRINT_BT_H_S__ */