4 ; Display a backtrace of the call stack
6 ; © 1994-1998 Straylight
9 ;----- Licensing note -------------------------------------------------------
11 ; This file is part of Straylight's Steel library.
13 ; Steel is free software; you can redistribute it and/or modify
14 ; it under the terms of the GNU General Public License as published by
15 ; the Free Software Foundation; either version 2, or (at your option)
18 ; Steel is distributed in the hope that it will be useful,
19 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ; GNU General Public License for more details.
23 ; You should have received a copy of the GNU General Public License
24 ; along with Steel. If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 IMPORT |_kernel_unwind|
31 IMPORT |_kernel_procname|
33 AREA |C$$Code|,CODE,READONLY
38 DCD &FF000000+{PC}-%b99
44 STMFD sp!,{fp,ip,lr,pc}
46 SUB sp,sp,#20 ;Make a small buffer
48 ; --- Start displaying the command window ---
51 SWI Wimp_CommandWindow
54 ; --- Set up dunny `frame pointer' ---
58 00 ; --- Print address from which it's called ---
60 LDR a1,[ip,#-4] ;Get the link regiser
61 BIC a1,a1,#&FC000003 ;Strip off saved PSR
62 SUB a1,a1,#4 ;Find the call address
63 MOV a2,sp ;Point to the buffer
64 MOV a3,#20 ;Buffer size
65 SWI XOS_ConvertHex8 ;Convert the address
66 SWI XOS_Write0 ;Display it on screen
70 ; --- Print procedure name ---
73 LDR a4,[ip,#0] ;Where's the stacked pc?
74 BIC a4,a4,#&FC000003 ;Mask off the PSR bits
75 SUB a4,a4,#20 ;Point to procedure word
76 LDR a2,[a4,#0] ;And load it
77 AND a3,a2,#&FF000000 ;Check the top byte is right
78 CMP a3,#&FF000000 ;Is it the right pattern?
79 BICEQ a3,a2,#&FF000000 ;Yes: Find the string length
80 SUBEQ a1,a4,a3 ; Point to the proc name
81 ADRNE a1,anon ;No: Point to `anonymous'
82 SWI XOS_Write0 ;Display the procedure name
84 SWI XOS_NewLine ;Move on to next line
86 ; --- Unwind the stack another level ---
88 LDR a1,[ip,#-12] ;Get the stacked frame ptr
89 CMP a1,#0 ;Is there a real stack frame?
90 BNE %00 ;Yes -- dump that one out
92 ; --- Turn the command window off ---
94 01 SWI Wimp_CommandWindow
98 wintitle DCB "Stack backtrace",0
99 anon DCB "Anonymous function",0