forked from turbo9team/turbo9
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtb_dv_asm.asm
235 lines (192 loc) · 6.46 KB
/
tb_dv_asm.asm
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
; [TURBO9_HEADER_START]
; ////////////////////////////////////////////////////////////////////////////
; Turbo9 Microprocessor IP
; ////////////////////////////////////////////////////////////////////////////
; Website: www.turbo9.org
; Contact: team[at]turbo9[dot]org
; ////////////////////////////////////////////////////////////////////////////
; [TURBO9_LICENSE_START]
; BSD-1-Clause
;
; Copyright (c) 2020-2023
; Kevin Phillipson
; Michael Rywalt
; All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are met:
;
; 1. Redistributions of source code must retain the above copyright notice,
; this list of conditions and the following disclaimer.
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
; POSSIBILITY OF SUCH DAMAGE.
; [TURBO9_LICENSE_END]
; ////////////////////////////////////////////////////////////////////////////
; Engineer: Kevin Phillipson
; Description: Template assemply program used by the DV testbench
;
; ////////////////////////////////////////////////////////////////////////////
; History:
; 07.14.2023 - Kevin Phillipson
; File header added
;
; ////////////////////////////////////////////////////////////////////////////
; [TURBO9_HEADER_END]
; ////////////////////////////////////////////////////////////////////////////
; Turbo9 / 6809 testbench program
; ////////////////////////////////////////////////////////////////////////////
output_port equ $0000
org $fc00
; ////////////////////////////////////////////////////////////////////////////
; Testbench Program Start (S Stack Pointer)
; ////////////////////////////////////////////////////////////////////////////
start_s_ptr:
; initalize output_port[7:0] = 8'h00
lda #$00
sta >output_port
; Delay a few cycles
nop
nop
nop
nop
; set start flag (output_port[0] = 1'b1)
lda #$01
sta >output_port
; Use S as stack pointer
lds #init_stack_data
puls pc,u,y,x,dp,b,a,cc ; pulling PC will jump to code_under_test
; ////////////////////////////////////////////////////////////////////////////
; Testbench Program Start (U Stack Pointer)
; ////////////////////////////////////////////////////////////////////////////
start_u_ptr:
; initalize output_port[7:0] = 8'h00
lda #$00
sta >output_port
; Delay a few cycles
nop
nop
nop
nop
; set start flag (output_port[0] = 1'b1)
lda #$01
sta >output_port
; Use U as stack pointer
ldu #init_stack_data
pulu pc,s,y,x,dp,b,a,cc ; pulling PC will jump to code_under_test
; ////////////////////////////////////////////////////////////////////////////
; Testbench Program Done (S Stack Pointer)
; ////////////////////////////////////////////////////////////////////////////
done_s_ptr
pshs pc,u,y,x,dp,b,a,cc
; set done flag (output_port[7] = 1'b1)
lda >output_port
ora #$80
sta >output_port
done_s_ptr_loop:
nop ; make the PC change in sim model
bra done_s_ptr_loop
; ////////////////////////////////////////////////////////////////////////////
; Testbench Program Done (U Stack Pointer)
; ////////////////////////////////////////////////////////////////////////////
done_u_ptr
pshu pc,s,y,x,dp,b,a,cc
; set done flag (output_port[7] = 1'b1)
lda >output_port
ora #$80
sta >output_port
done_u_ptr_loop:
nop ; make the PC change in sim model
bra done_u_ptr_loop
; ////////////////////////////////////////////////////////////////////////////
; Code Under Test
; ////////////////////////////////////////////////////////////////////////////
code_under_test:
; replace the following with code to test
jmp done_s_ptr
org code_under_test_mid-128+2
code_under_test_br_bwd
; the maximum range for branching backward
inca
jmp done_s_ptr
org code_under_test_mid-128+3
code_under_test_idx_pc8_bwd
; the maximum range for pc8 index backward
org (code_under_test+data_block_end)/2
code_under_test_mid
; a midpoint in the code/data block
beq code_under_test_br_bwd
jmp done_s_ptr
org code_under_test_mid+127+2
code_under_test_br_fwd
; the maximum range for branching forward
incb
jmp done_s_ptr
org code_under_test_mid+127+3
code_under_test_idx_pc8_fwd
; the maximum range for pc8 index forward
; ////////////////////////////////////////////////////////////////////////////
; Data Block
; ////////////////////////////////////////////////////////////////////////////
data_addr:
fcb $7f
org stack_end-1
data_block_last_byte:
org stack_end
data_block_end:
; ////////////////////////////////////////////////////////////////////////////
; Stack (32 bytes)
; ////////////////////////////////////////////////////////////////////////////
; Used to load initial state and save run-time data for code under test
; and save the processor state after code under test complete
org vector_table-32
stack_end:
org vector_table-12
init_stack_data:
init_cc:
fcb $78 ;cc
init_a:
fcb $67 ;a
init_b:
fcb $56 ;b
init_dp:
fcb data_addr/$100 ;dp
init_x:
fdb $3443 ;x
init_y:
fdb $2332 ;y
init_u_s:
fdb $1221 ;u or s
init_pc:
fdb code_under_test ;pc
stack_start:
; ////////////////////////////////////////////////////////////////////////////
; reset / interrupt vector
; ////////////////////////////////////////////////////////////////////////////
org $fff0
vector_table:
reserved_vector:
fdb start_s_ptr
swi3_vector:
fdb start_s_ptr
swi2_vector:
fdb start_s_ptr
firq_vector:
fdb start_s_ptr
irq_vector:
fdb start_s_ptr
swi_vector:
fdb start_s_ptr
nmi_vector:
fdb start_s_ptr
reset_vector:
fdb start_s_ptr