Initial revision
[ssr] / StraySrc / Hammer / s / hammer
1 ;
2 ; hammer.s
3 ;
4 ; Main definitions for Sledgehammer (TMA & MDW)
5 ;
6 ; © 1994-1998 Straylight
7 ;
8
9 ;----- Licensing note -------------------------------------------------------
10 ;
11 ; This file is part of Straylight's Sledgehammer debugger.
12 ;
13 ; Sledgehammer 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)
16 ; any later version.
17 ;
18 ; Sledgehammer 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.
22 ;
23 ; You should have received a copy of the GNU General Public License
24 ; along with Sledgehammer. If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27 ;----- Standard header ------------------------------------------------------
28
29 GET libs:header
30 GET libs:swis
31
32 ;----- External dependencies ------------------------------------------------
33
34 GET quartz:quartz
35
36 GET sh.armEmul
37 GET sh.asm
38 GET sh.diss
39 GET sh.brkpt
40 IMPORT ae_addr
41
42 ;----- Module information ---------------------------------------------------
43
44 AREA |Hammer$$Code|,CODE,READONLY
45
46 EXPORT quartz_name
47 quartz_name DCB "Sledgehammer",0
48
49 ;----- SWI information ------------------------------------------------------
50
51 EXPORT quartz_swiChunk
52 quartz_swiChunk EQU &4A380
53
54 EXPORT quartz_swiNames
55 quartz_swiNames DCB "Sledgehammer",0
56
57 DCB "SetDissOptions",0 ;Sledgehammer_0
58 DCB "DissAddress",0 ;Sledgehammer_1
59 DCB "Disassemble",0 ;Sledgehammer_2
60 DCB "Assemble",0 ;Sledgehammer_3
61 DCB "Step",0 ;Sledgehammer_4
62 DCB "StepAddr",0 ;Sledgehammer_5
63 DCB "SetBP",0 ;Sledgehammer_6
64 DCB "RemoveBP",0 ;Sledgehammer_7
65 DCB "Translate",0 ;Sledgehammer_8
66 DCB "BreakPoint",0 ;Sledgehammer_9
67 DCB 0
68
69 EXPORT quartz_swiCode
70 quartz_swiCode ROUT
71
72 CMP R11,#(%10-%00)/4 ;Is the SWI in range?
73 ADDCC PC,PC,R11,LSL #2 ;Yes -- dispatch it then
74 B %10quartz_swiCode ;Return an error if not
75
76 ; --- SWI dispatch table ---
77
78 00 B diss_setOptions ;Sledgehammer_SetDissOptions
79 B diss_address ;Sledgehammer_DissAddress
80 B diss_disassemble ;Sledgehammer_Disassemble
81 B asm_assemble ;Sledgehammer_Assemble
82 B armEmul ;Sledgehammer_Step
83 B ae_addr ;Sledgehammer_StepAddr
84 B brkpt_set ;Sledgehammer_BreakSet
85 B brkpt_remove ;Sledgehammer_Remove
86 B brkpt_translate ;Sledgehammer_Translate
87 B brkpt_hardBreak ;Sledgehammer_BreakPoint
88
89 ; --- Unknown SWI found ---
90
91 10 ADR R0,hammer__badSwi ;Point at the error block
92 ORRS PC,R14,#V_flag ;And return the error
93
94 hammer__badSwi DCD &1E6
95 DCB "Unknown Sledgehammer operation",0
96
97 LTORG
98
99 ;---- Some standard routines ------------------------------------------------
100
101 ; --- hammer_confirm ---
102 ;
103 ; On entry: R0 == pointer to confirmation message
104 ;
105 ; On exit: C set to proceed with whatever it was you wanted to confirm
106 ;
107 ; Use: Displays a message with a confirmation prompt and waits
108 ; for a response from the user.
109
110 EXPORT hammer_confirm
111 hammer_confirm ROUT
112
113 STMFD R13!,{R0-R2,R14} ;Save some registers
114 SWI XOS_Write0 ;Display caller's message
115 SWI XOS_WriteS ;And now display the prompt
116 DCB " [yn]",0
117
118 MOV R0,#229 ;Set escape action
119 MOV R1,#1 ;Just generate key code
120 MOV R2,#0 ;Set the state
121 SWI XOS_Byte ;Do it
122
123 00 SWI XOS_ReadC ;Read a byte from the user
124 CMP R0,#13 ;Is it return?
125 CMPNE R0,#32 ;Or a space
126 MOVEQ R0,#'y' ;Yes -- take that as a yes
127 CMP R0,#27 ;Was it escape?
128 MOVEQ R0,#'n' ;Yes -- guess that's a no
129 ORR R0,R0,#&20 ;Make it lower case
130 CMP R0,#'y' ;Is it a yes?
131 CMPNE R0,#'n' ;Or a no, that'll do too
132 BNE %00hammer_confirm ;Neither -- try again then
133
134 SWI XOS_WriteI+' ' ;Put a space in nicely
135 SWI XOS_WriteC ;Display the response
136 SWI OS_NewLine ;And move to the next line
137 CMP R0,#'y' ;Was it a yes again?
138
139 MOV R0,#229 ;Set escape action
140 MOV R2,#0 ;Set the state
141 SWI XOS_Byte ;Restore the old action
142
143 LDMFD R13!,{R0-R2,R14} ;Restore the registers
144 ORREQS PC,R14,#C_flag ;If so, set C on exit
145 BICNES PC,R14,#C_flag ;Otherwise clear it
146
147 LTORG
148
149 ; --- hammer_getStack ---
150 ;
151 ; On entry: --
152 ;
153 ; On exit R13 == pointer to the sledghammer stack
154 ;
155 ; Use: Returns a pointer to the sledgehammer stack!
156
157 EXPORT hammer_getStack
158 hammer_getStack ROUT
159
160 LDR R13,hammer__wSpace ;Get workspace pointer
161 ADD R13,R13,#:INDEX: ws__stackBase
162 MOVS PC,R14 ;Return to caller
163
164 LTORG
165
166 hammer__wSpace DCD 0
167
168 ;----- Workspace ------------------------------------------------------------
169
170 ^ 0,R12
171
172 ws__start # 0
173
174 ws__stackTop # 1024 ;Just a 1K stack
175 ws__stackBase # 0 ;The top of the stack!
176
177 ws__size EQU {VAR}-ws__start ;The workspace size
178
179 AREA |Quartz$$Table|,CODE,READONLY
180
181 DCD ws__size
182 DCD hammer__wSpace
183 DCD 0
184 DCD 0
185
186 ;----- That's all folks -----------------------------------------------------
187
188 END