-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrfcrawl.cul
147 lines (111 loc) · 4.5 KB
/
rfcrawl.cul
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
( $Id: rfcrawl.cul,v 1.10 2016/05/26 19:18:31 albert Exp $ )
( Copyright{2000}: Albert van der Horst, HCC FIG Holland by GNU Public License)
( Uses Richard Stallmans convention. Uppercased word are parameters. )
\ In retroforth all calls return and ``INT 80'' too.
ASSEMBLER
'CALL, UNCONDITIONAL-TRANSFERS BAG-
'CALLO, UNCONDITIONAL-TRANSFERS BAG-
'INT, UNCONDITIONAL-TRANSFERS BAG-
PREVIOUS
\ 'CALLFAR, , 'CALLFARO, , 'CALLO, , , 'INT3, , 'INTO, ,
: \D POSTPONE \ ; \ Get rid of debug
HEX INIT-ALL
INCLUDE elf.cul
\ Don't want them to show up as labels.
0804,879D CONSTANT last_dea_forth
0804,85E5 CONSTANT last_dea_macro
0804,839C LABEL dovar
0804,80BF EQU X_bye
0804,80C6 EQU H_syscall
\ Name buffer for words
CREATE NAME-BUFFER 0 , 200 ALLOT
\ Prefix: "N_" for forth words, "N_m" for macro words.
CREATE N_PREFIX 6 CELL+ ALLOT \ Count plus 6 letters.
\ Prepend to NAME a from ``N_PREFIX'', return prefixed NAME in a static buffer.
: >N_ N_PREFIX $@ NAME-BUFFER $! NAME-BUFFER $+! NAME-BUFFER $@ ;
\ ADDRESS points to a valid name. Add a label to address the name.
: ADD-NAME-LABEL DUP th COUNT >N_ INSERT-EQU ;
\ ADDRESS points in the target area. Assume that just before the dea's
\ name has been analysed, change its first character to CHAR and add
\ the address with that label name.
: ADD-XXX-LABEL NAME-BUFFER CELL+ C! NAME-BUFFER $@ INSERT-EQU ;
\ ADDRESS points to a valid dea. Add a label to address the dea(header).
\ Assume that just before the dea's name has been analysed.
: ADD-DEA-LABEL &H ADD-XXX-LABEL ;
\ ADDRESS points to a valid code address. Lets call that an execution token.
\ Assume that just before the dea's name has been analysed.
: ADD-CODE-LABEL &X ADD-XXX-LABEL ;
\ ADDRESS points to a variable's content. Lets call that an v-thing.
\ Assume that just before the dea's name has been analysed.
: ADD-VAR-LABEL &V ADD-XXX-LABEL ;
\ ADDRESS points to a valid name.
\ Add an anonymous section to disassemble the name.
: ADD-NAME-SECTION DUP B@ OVER + 1 + -d$- ;
\ ADDRESS points to a dea.
\ Add an anonymous section to disassemble the dea.
: ADD-DEA-SECTION DUP 8 + -dl- ;
\ Add an anonymous section to disassemble the code (5 byte call) of a
\ variable whose code ADDRESS is given. And a 4 byte section for the
\ content. Add a symbolic name for the content.
: ADD-VAR-INFO DUP 5 + DUP >R -dc- R>
DUP ADD-VAR-LABEL DUP 4 + -dl- ;
\ Add the information that ADDRESS is a nfa.
: IS-A-NAME DUP B@ 0 31 WITHIN 0= ABORT" UNPLAUSIBLE LENGTH"
DUP ADD-NAME-LABEL ADD-NAME-SECTION ;
\ Accumulate the information that ADDRESS contains a code field address.
\ For variables the code ends after the call, so we don't want to crawl.
: IS-A-CFA L@ DUP ADD-CODE-LABEL
DUP 1+ L@ OVER 5 + + dovar = IF ADD-VAR-INFO ELSE CRAWL THEN ;
\ Accumulate the information that DEA is a dea.
: IS-A-DEA DUP 8 + IS-A-NAME DUP ADD-DEA-LABEL
DUP 4 + IS-A-CFA DUP ADD-DEA-SECTION
DROP ;
\ Accumulate the information from DEA, follow the link field.
: CRAWL-DEA BEGIN DUP IS-A-DEA L@ DUP PLAUSIBLE-LABEL? 0= UNTIL DROP ;
SORT-ALL
X_bye H_syscall -dc- \ !! Instead of CRAWL-DEA
"N_" N_PREFIX $! last_dea_forth CRAWL-DEA
"N_m" N_PREFIX $! last_dea_macro CRAWL-DEA
_start H_emit -dc- \ !! Instead of ELF-CRAWL
\ Code addresses that float somehow.
dovar CRAWL
0804,84C8 CRAWL
0804,84B6 CRAWL
0804,840E CRAWL
0804,8404 CRAWL
0804,839B CRAWL
0804,8191 CRAWL
\ The equ file results from manual work.
"INCLUDE rf751equ.cul" 0804,8000 DIRECTIVE
V_base
4 + DUP EQU tail DUP COMMENT: Allow tail-calls?
4 + DUP EQU buffer DUP COMMENT: Buffer (for ports to use as needed)
4 + DUP EQU source DUP COMMENT: Evaluate from RAM or KBD
4 + DUP EQU tin DUP COMMENT: >IN
4 + DUP EQU tp DUP COMMENT: TP (pointer to input buffer)
4 + DUP EQU bases DUP COMMENT: $hex %bin &oct 'ascii
4 + DUP EQU last DUP COMMENT: Last word in dictionary
4 + DUP EQU flast DUP COMMENT: Last word in 'forth'
4 + DUP EQU mlast DUP COMMENT: Last word in 'macro'
4 + DUP EQU retroforth_f
DROP
INCLUDE rf751equ.cul
tail bases -dl-
bases last -db-
last retroforth_f -dl-
\D MAKE-CUL
\D "----------------" TYPE CR
SORT-LABELS
CLEAN-LABELS
\ MAKE-CUL
\D
\D "----------------" TYPE CR
\D DISASSEMBLE-ALL
CLEANUP-RANGES
\ MAKE-CUL
PLUG-HOLES
\ Now spit out a cul file that is used going on.
"\ This file is generated, stored in RCS for comparison only.
" TYPE
MAKE-CUL
\ DISASSEMBLE-ALL