Skip to content

Commit c2eb26a

Browse files
authored
build: add data overflow checks (#139)
Issue build warnings if any of the data sections overflows into another. Signed-off-by: Aleksey Gurtovoy <aleks@wildbitscomputing.com>
1 parent 8f81c1e commit c2eb26a

5 files changed

Lines changed: 76 additions & 78 deletions

File tree

source/_basic.asm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,4 @@ StartModuleCode:
196196
.cwarn * > $8000, "BROKEN BUILD: page 2 code overflows into SuperBASIC ROM space ($8000-$BFFF) by ", * - $8000," bytes"
197197
.endlogical
198198
.send page2
199+
.include "./common/aa.system/_dataoverflowchecks.asm"

source/common/aa.system/01common.inc

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
; ************************************************************************************************
2-
; ************************************************************************************************
3-
;
4-
; Name: 01common.inc
5-
; Purpose: Common includes/defines/setups
6-
; Created: 18th September 2022
7-
; Reviewed: 17th November 2022
8-
; Author: Paul Robson (paul@robsons.org.uk)
9-
;
10-
; ************************************************************************************************
11-
; ************************************************************************************************
1+
;;
2+
; Common includes/defines/setups
3+
;;
124

135
; ************************************************************************************************
146
;
@@ -20,24 +12,28 @@
2012
;
2113
; Variables that have to be in zero page because it's used in (xx),y
2214
;
23-
ZeroPageMandatory = $30
15+
ZeroPageMandatory = $0030
2416
;
2517
; Variables that would be nice to be in zero page, but it's not required
2618
;
27-
ZeroPagePreference = $50
19+
ZeroPagePreference = $0050
20+
21+
; 6502 hardware stack ($0100-$01FF)
22+
HardwareStack = $0100
23+
2824
;
2925
; Command line arguments for pexec - page aligned, and by convention these should reside
3026
; at $200 for maximum compatibility
3127
;
32-
ArgumentStorage = $200
28+
ArgumentStorage = $0200
3329
;
3430
; Control Variables - low usage control variables.
3531
;
36-
ControlStorage = $400
32+
ControlStorage = $0400
3733
;
3834
; Variables that can go anywhere
3935
;
40-
MemoryStorage = $420
36+
MemoryStorage = $0420
4137
;
4238
; Where program memory starts and stops (banked through MMU slot 1)
4339
;
@@ -108,15 +104,3 @@ MaxLineSize = 80
108104
109105
* = CodeStart ; main code at $8000
110106
.dsection code
111-
112-
; ************************************************************************************************
113-
;
114-
; Changes and Updates
115-
;
116-
; ************************************************************************************************
117-
;
118-
; Date Notes
119-
; ==== =====
120-
; 26/11/22 Stack moved into Zero Page for speed/space, okayed by Jessie O.
121-
;
122-
; ************************************************************************************************

source/common/aa.system/04data.inc

Lines changed: 37 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
; ************************************************************************************************
2-
; ************************************************************************************************
3-
;
4-
; Name: 04data.inc
5-
; Purpose: Main Data
6-
; Created: 18th September 2022
7-
; Reviewed: 23rd November 2022
8-
; Author: Paul Robson (paul@robsons.org.uk)
9-
;
10-
; ************************************************************************************************
11-
; ************************************************************************************************
1+
;;
2+
; Main data declarations
3+
;;
124

135
; ************************************************************************************************
146
;
@@ -21,7 +13,7 @@
2113
codePtr: ; address of current line (allow for 32 bit)
2214
.fill 4
2315
basicStack: ; BASIC stack address
24-
.fill 2
16+
.fill 2
2517
zTemp0: ; temporary words used in the interpreter.
2618
.fill 2
2719
zTemp1:
@@ -32,9 +24,14 @@ zsTemp: ; allocated string temporary.
3224
.fill 2
3325
zaTemp: ; allocated array temporary
3426
.fill 2
35-
27+
3628
safePtr = codePtr ; minimise direct tinkering
37-
29+
30+
; unused reserve; declared for visibility, adjust accordingly when adding new variables;
31+
; overflows are diagnosed automatically, see `makebuild.py`
32+
_zeropageReserve:
33+
.fill 14
34+
3835
.send zeropage
3936

4037
; ************************************************************************************************
@@ -79,6 +76,11 @@ NSExponent: ; Exponent , 0 = Mantissa is integer
7976
fnStackLevel: ; saved stack level for function evaluation
8077
.fill 1
8178

79+
; unused reserve; declared for visibility, adjust accordingly when adding new variables;
80+
; overflows are diagnosed automatically, see `makebuild.py`
81+
_zeroprefReserve:
82+
.fill 79
83+
8284
.send zeropref
8385

8486

@@ -95,7 +97,7 @@ identStart: ; start of identifier in line buffer
9597
identTypeStart: ; start of type information (#$ and ( in the line buffer)
9698
.fill 1
9799
identTypeEnd: ; character after end of type information in the line buffer
98-
.fill 1
100+
.fill 1
99101
identHash: ; hash of identifier (including the type characters)
100102
.fill 1
101103
identTypeByte: ; type descriptor in format used in identifier record
@@ -113,63 +115,63 @@ lowMemPtr: ; memory allocation after program.
113115
arrayMemPtr: ; array/alloc storage pointer (slots 2-3, $4000-$7FFF)
114116
.fill 2
115117
stringMemory: ; allocate concrete strings from here
116-
.fill 2
117-
stringInitialised: ; string
118-
.fill 1
118+
.fill 2
119+
stringInitialised: ; string
120+
.fill 1
119121
stringTempPointer: ; temporary string
120-
.fill 2
122+
.fill 2
121123

122124
breakCheck: ; break check counter/shift
123125
.fill 1
124-
126+
125127
decimalPlaces: ; no of decimals.
126128
.fill 1
127129
dbOffset: ; offset into decimal buffer.
128-
.fill 1
130+
.fill 1
129131

130132
lastParameter: ; final stack offset when all parameters handled.
131133
.fill 1
132-
134+
133135
dataPointer: ; operates like code pointer for DATA statements
134136
.fill 5
135137
inDataStatement: ; non zero when in data statement, e.g. pointing to data
136-
.fill 1
138+
.fill 1
137139

138140
tbOffset: ; offset into token buffer
139-
.fill 1
141+
.fill 1
140142

141143
AssemblerAddress: ; address being assembled at
142144
.fill 2
143145
AssemblerControl: ; assembler control byte - bit 0 (errors ok), bit 1 (listing on)
144-
.fill 1
146+
.fill 1
145147
ParamStart: ; offset of parameter.
146-
.fill 2
148+
.fill 2
147149
IsGroup1: ; flag set if group.1
148-
.fill 1
150+
.fill 1
149151
BaseOpcode: ; base opcode
150-
.fill 1
152+
.fill 1
151153
ModeMask: ; modes allowed
152-
.fill 1
154+
.fill 1
153155
listIndent: ; list indent level.
154156
.fill 1
155157
listElseFound: ; flag set when ELSE found on line (for indent fix)
156158
.fill 1
157159
listEndToken: ; closing token for LIST proc/fn
158160
.fill 1
159161
lcLastCharacter: ; last character output.
160-
.fill 1
162+
.fill 1
161163
isPrintFlag: ; zero if input, non-zero if print, bit 6 zero = character print
162-
.fill 1
164+
.fill 1
163165
currentListColour: ; current set colour when listing.
164166
.fill 1
165167
;
166168
; New tokenised line - these three *must* be contiguous as they are used as a single entity
167-
;
169+
;
168170
tokenOffset: ; used for tokenising - tokenised result goes here
169-
.fill 1
171+
.fill 1
170172
tokenLineNumber:
171-
.fill 2
172-
tokenBuffer:
173+
.fill 2
174+
tokenBuffer:
173175
.fill 253
174176

175177
lineBuffer: ; used for input - ASCII line goes here
@@ -194,18 +196,3 @@ decimalBuffer: ; buffer for number -> string conversion.
194196

195197
.send storage
196198

197-
; ************************************************************************************************
198-
;
199-
; Changes and Updates
200-
;
201-
; ************************************************************************************************
202-
;
203-
; Date Notes
204-
; ==== =====
205-
; 1/12/2022 Changed the recorded values used in the reference byte size which were
206-
; incorrect, no code change.
207-
; 2/12/2022 Made line buffer long again, as long lines can be entered via cross
208-
; development which would crash the interpreter.
209-
;
210-
; ************************************************************************************************
211-
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
;
2+
; End-of-program overflow checks; issuing warnings instead of an error so one can examine output listing for details
3+
;
4+
.section zeropage
5+
.cwarn * > ZeroPagePreference, "BROKEN BUILD: zeropage section overflowed by ", * - ZeroPagePreference," bytes"
6+
.send zeropage
7+
8+
.section zeropref
9+
.cwarn * > HardwareStack, "BROKEN BUILD: zeropref section overflowed into hardware stack by ", * - HardwareStack," bytes"
10+
.send zeropref
11+
12+
.section arguments
13+
.cwarn * > ControlStorage, "BROKEN BUILD: arguments section overflowed into control storage by ", * - ControlStorage," bytes"
14+
.send arguments
15+
16+
.section storage
17+
.cwarn * > BasicStackBase, "BROKEN BUILD: storage section overflowed into BASIC stack by ", * - BasicStackBase," bytes"
18+
.send storage
19+
20+
.section boot
21+
.cwarn * > CodeStart, "BROKEN BUILD: boot section overflowed into code by ", * - CodeStart," bytes"
22+
.send boot

source/scripts/makebuild.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,9 @@ def include_directive(path: Path) -> str:
148148
.send page2
149149
""")
150150

151+
# data overflow checks; keep these at the end!
152+
h.write(
153+
include_directive(root_dir / "common" / "aa.system" / "_dataoverflowchecks.asm")
154+
)
151155

152156
h.close()

0 commit comments

Comments
 (0)