-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadsym.asm
More file actions
263 lines (216 loc) · 4.51 KB
/
loadsym.asm
File metadata and controls
263 lines (216 loc) · 4.51 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
;
; loadsym.asm
;
;
; 27.9.1993 -- adding some buffering...
;
;
; this module defines the following public routine:
;
; load_symbols
;
nolist
include "exec/types.i"
include "exec/memory.i"
include "dos/dos.i"
include "dos/doshunks.i"
include "offsets.i"
list
include "monitor.i"
xref out_memory_error
RBUFSIZE equ 4096
;
; data structure used by load_symbols-routine
;
STRUCTURE LSymData,0
WORD lsym_RBufOffs
WORD lsym_RBufMax
STRUCT lsym_ReadBuf,RBUFSIZE
STRUCT lsym_Buffer,256+4
LONG lsym_SLen
LABEL LSymData_SIZE
;
; read symbol information from executable file
;
pub load_symbols
movem.l d2-d7/a2/a3/a5,-(sp)
move.l a0,a2
move.l #LSymData_SIZE,d0
move.l #MEMF_CLEAR,d1
lib Exec,AllocMem
tst.l d0
beq out_memory_error
move.l d0,a5
move.w #RBUFSIZE,lsym_RBufOffs(a5)
move.l mon_NumHunks(a4),d0
lsl.l #(2+1),d0 ;allocate 2*4*NumHunks bytes
move.l #MEMF_CLEAR,d1
lib AllocMem
move.l d0,mon_HunkTypeTable(a4)
beq out_mem1
move.l d0,a3
move.l a2,d1
move.l #MODE_OLDFILE,d2
lib Dos,Open
move.l d0,d6
beq lsym_open_err
bsr lsym_GetLong
cmp.l #HUNK_HEADER,d0
bne lsym_fmt_err
bsr lsym_GetLong
tst.l d0
bne lsym_fmt_err ;reslibs not supported...
bsr lsym_GetLong ;table size
move.l d0,a2
bsr lsym_GetLong ;first hunk #
tst.l d0
bne lsym_fmt_err ;error if not zero
bsr lsym_GetLong ;last hunk #
addq.l #1,d0
cmp.l a2,d0
bne overlay_err
cmp.l mon_NumHunks(a4),d0
bne lsym_fmt_err ;wrong number of hunks
lsl.l #2,d0 ;-># of longwords
bsr lsym_Skip
moveq #0,d7 ;hunk counter
moveq #0,d4 ;symbol counter
move.l mon_SegList(a4),d5
lsl.l #2,d5
lsym_hunkloop bsr lsym_GetLong
move.l d0,d1
and.l #$3fffffff,d0
cmp.l #HUNK_CODE,d0
bne.s no_code
move.l d1,(a3)+
bra.s skip_n
no_code cmp.l #HUNK_DATA,d0
bne.s no_data
move.l d1,(a3)+
skip_n bsr lsym_GetLong
lsl.l #2,d0
move.l d0,(a3)+
skip_n1 bsr lsym_Skip
bra.s lsym_hunkloop
no_data cmp.l #HUNK_BSS,d0
bne.s no_bss
move.l d1,(a3)+
bsr lsym_GetLong ;skip bss length
lsl.l #2,d0
move.l d0,(a3)+
bra.s lsym_hunkloop
no_bss cmp.l #HUNK_DEBUG,d0
bne.s no_debug
bsr lsym_GetLong
lsl.l #2,d0
bra.s skip_n1
no_debug cmp.l #HUNK_OVERLAY,d0
beq overlay_err
cmp.l #HUNK_END,d0
bne.s no_end
move.l d5,a0
move.l (a0),d5
lsl.l #2,d5
beq lsym_end
addq.l #1,d7
cmp.l mon_NumHunks(a4),d7
bcs.s lsym_hunkloop
bra lsym_end
no_end cmp.l #HUNK_RELOC32,d0
bne.s no_reloc
reloc_loop bsr lsym_GetLong
tst.l d0
beq lsym_hunkloop
addq.l #1,d0
lsl.l #2,d0
bsr lsym_Skip
bra.s reloc_loop
no_reloc cmp.l #HUNK_SYMBOL,d0
bne lsym_fmt_err
symbol_loop bsr lsym_GetLong
tst.l d0
beq lsym_hunkloop
cmp.l #64,d0 ;4 * 64 = 256
bcc lsym_fmt_err
addq.l #1,d0
lsl.l #2,d0
move.l d0,lsym_SLen(a5)
exg a2,d7
moveq #0,d7
sym_read_loop bsr.w lsym_GetLong
lea lsym_Buffer(a5),a0
move.l d0,0(a0,d7.l)
addq.l #4,d7
cmp.l lsym_SLen(a5),d7
bcs.b sym_read_loop
exg a2,d7
move.l -4(a0,a2.l),d0
clr.b -4(a0,a2.l)
add.l d5,d0
addq.l #4,d0
lea lsym_Buffer(a5),a0
move.l d7,d1
call set_variable
tst.l d0
beq lsym_mem_err
addq.l #1,d4
bra symbol_loop
lsym_end move.l d4,d0
lea nsym_fmt(pc),a0
call printf
lsym_ex97 move.l d6,d1
lib Dos,Close
lsym_ex98 move.l a5,a1
move.l #LSymData_SIZE,d0
lib Exec,FreeMem
movem.l (sp)+,d2-d7/a2/a3/a5
rts
out_mem1 move.l a5,a1
move.l #LSymData_SIZE,d0
lib Exec,FreeMem
bra out_memory_error
lsym_Skip move.l d6,d1
move.l d0,d2
moveq #0,d0
move.w lsym_RBufMax(a5),d0
sub.w lsym_RBufOffs(a5),d0
sub.l d0,d2
moveq #OFFSET_CURRENT,d3
lib Dos,Seek
tst.l d0
bmi.s lsym_read_err1
move.w #RBUFSIZE,lsym_RBufOffs(a5)
rts
lsym_read_err1 addq.l #4,sp
lsym_fmt_err
lsym_mem_err
lsym_read_err lea read_errtxt(pc),a0
lsym_msg1 call printstring_a0_window
bra.s lsym_ex97
overlay_err lea overlay_err_txt(pc),a0
bra.s lsym_msg1
lsym_open_err lea open_errtxt(pc),a0
call printstring_a0_window
bra.s lsym_ex98
lsym_GetLong move.w lsym_RBufOffs(a5),d0
cmp.w lsym_RBufMax(a5),d0
bcc.b rd_more
move.l lsym_ReadBuf(a5,d0.w),d0
addq.w #4,lsym_RBufOffs(a5)
rts
rd_more move.l d6,d1
move.l a5,d2
addq.l #lsym_ReadBuf,d2
move.l #RBUFSIZE,d3
lib Dos,Read
moveq #4,d1
cmp.l d1,d0
blt.b lsym_read_err1
move.w d0,lsym_RBufMax(a5)
clr.w lsym_RBufOffs(a5)
bra.b lsym_GetLong
read_errtxt
open_errtxt dc.b 'Problems reading symbols',LF,0
overlay_err_txt dc.b 'Overlays not supported',LF,0
nsym_fmt dc.b '(%ld symbols)',LF,0
end