1 ;; Native x86 GNU/Linux Forth System, Direct Threaded Code
3 ;; Copyright (C) 2020 Ketmar Dark // Invisible Vector
5 ;; This program is free software: you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation, version 3 of the License ONLY.
9 ;; This program is distributed in the hope that it will be useful,
10 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ;; GNU General Public License for more details.
14 ;; You should have received a copy of the GNU General Public License
15 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
18 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19 ;; currently, debug info is very simple, it contains only PC->LINE mapping
22 ;; dd itemcount ; this may be used as "extended" later, so bit 31 is resv
28 ;; itemcount bit 31 should always be 0
30 ;; the compiler doesn't store each PC, it only stores line changes
31 ;; that is, the range for the line lasts until the next item
32 ;; items should be sorted by PC (but the code should not fail on
36 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
37 urword_value
"(DBGINFO-ENABLED?)",dbginfo_enabledq
,1
40 urword_value
"(DBG-BUF-PTR)", dbuf_addr
,0
42 urword_value
"(DBG-BUF-SIZE)",dbuf_size
,1024*64
44 urword_value
"(DBGINFO-ACTIVE?)",dbginfo_activeq
,0
48 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
49 urword_forth
"DEBUG-INFO-ON",debug_info_on
54 urword_forth
"DEBUG-INFO-OFF",debug_info_off
60 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
61 urword_forth
"(DBGINFO-RESET)",debug_info_reset
73 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
74 urword_forth
"(DBGINFO-GET-ADDR-SIZE)",debug_info_addr_size
76 ;; ( -- addr bytes 1 )
78 UF dbginfo_activeq dbginfo_enabledq land
90 UF dup
0xffffffff equal
95 UF
2 cells umul cellinc
102 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
103 urword_forth
"(DBGINFO-DUMP-AT)",debug_info_dump_at
116 urprint
"debug info containts "
120 UF rpeek @
2 cells umul cellinc rpeek
+
136 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
137 urword_forth
"(DBGINFO-DUMP)",debug_info_dump
142 urprintnl
"debug info disabled"
147 urprintnl
"no debug info"
152 urprintnl
"debug info overflowed"
155 UF dbuf_addr debug_info_dump_at
159 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
160 urword_forth
"(DBGINFO-ADD-PC)",debug_info_add_pc
163 ; never put zero line
175 ; yes, store the item
176 ; assume that we always have room for at least one
178 UF swap dbuf_addr cellinc
!
179 UF dbuf_addr
2 addcells
!
182 ; special? -1 items means "out of room"
183 UF dup
0xffffffff equal
187 ; calculate address of the last item
188 UF
1dec 2 cells umul cellinc dbuf_addr
+
189 ; check if the line is the same
190 ;TODO: check for sorted PC here?
191 UF
2dup cellinc @ equal
193 ; no need to store this item
198 ; check if we have enough room
199 UF dup dbuf_size dbuf_addr
+ ugreat
201 ; out of buffer, abort debug info generation
202 UF drop
2drop
0xffffffff dbuf_addr
! exit
205 ; ok, we have enough room, store new item
207 UF rpush base @ rpush
209 urprint
"adding pc 0x"
215 UF rot over
! cellinc
!
216 ; and increment the counter
217 UF
1 dbuf_addr addpoke
221 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
222 urword_forth
"(DBGINFO-ADD-HERE)",dbginfo_add_here
225 UF dbginfo_activeq dbginfo_enabledq land
227 UF here tiblineno @ debug_info_add_pc