struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / device / lib / tlcs90 / crt0_org.s
blobfbb750f22f7a0ad3fa488c534a5cab6a67bbbb71
1 ;; crt0_asm.s - tlcs90
3 .t90
5 .module crt0
7 .globl _meminit
8 .globl _main
9 .globl _xxaddr
10 .globl _xxby
11 .globl _xxdata
13 .globl _ser_putchar_irq
14 .globl _ser_puts
16 ;; put as abs in dat at end of file..
17 ;.globl _ser_irq_flags
18 ;.globl _ser_char
20 .globl _xget_byte_asm
21 .globl _xset_byte_asm
24 ;; for interrupts the pc and af are pushed on the stack
26 .globl _irq_info_swi
27 .globl _irq_info_intwd
28 .globl _irq_info_intt0
29 .globl _irq_info_intt1
30 .globl _timer1_irq
31 .globl _irq_info_intt3
32 .globl _irq_info_intt4
33 .globl _irq_info_int1
34 .globl _irq_info_intt5
36 .globl _ticks16
37 .globl _xflag
39 ;; NOTE: header might get trashed by linker when code loc ist not used!?
40 .area _HEADER (ABS)
42 .org 0
44 .include "t90regs.s"
46 ;; _ser_irq_flags
47 TX_ACTIVE .equ 0
48 RX_READY .equ 1
50 L0:
51 ;halt
52 ;jr L0
53 jp _astart
54 nop
55 nop
56 nop
57 nop
58 nop
59 nop
60 nop
61 nop
62 nop
63 nop
64 nop
65 nop
66 nop
67 L10:
68 ; SWI
69 jp _swi_irq
70 nop
71 nop
72 nop
73 nop
74 nop
76 L18:
77 nop ; NMI
78 nop
79 nop
80 nop
81 nop
82 nop
83 nop
84 nop
86 L20:
87 ; INTWD
88 jp _intwd_irq
89 nop
90 nop
91 nop
92 nop
93 nop
94 L28:
95 reti ; INT0
96 nop
97 nop
98 nop
99 nop
100 nop
101 nop
102 nop
103 L30:
104 ; INTT0
105 jp _intt0_irq
106 nop
107 nop
108 nop
109 nop
111 L38:
112 ; INTT1
113 jp _intt1_irq
114 nop
115 nop
116 nop
117 nop
119 L40:
120 ; INTAD
121 reti
122 nop
123 nop
124 nop
125 nop
126 nop
127 nop
129 L48:
130 ; INTT3
131 jp _intt3_irq
132 nop
133 nop
134 nop
135 nop
137 L50:
138 ; INTT4
139 jp _intt4_irq
140 nop
141 nop
142 nop
143 nop
145 L58:
146 ; INT1
147 jp _int1_irq
148 nop
149 nop
150 nop
151 nop
153 L60:
154 ; INTT5
155 jp _intt5_irq
156 nop
157 nop
158 nop
159 nop
161 L68:
162 reti ; INT2
163 nop
164 nop
165 nop
166 nop
167 nop
168 nop
170 L70:
171 jp _serial_rx_irq
172 nop
173 nop
174 nop
175 nop
177 L78:
178 jp _serial_tx_irq
179 nop
180 nop
181 nop
182 nop
184 L80:
185 nop
187 .org 0x100
189 _astart:
190 ld sp, #0x0FFA0 ; stack
192 ;halt
193 ;swi
195 or (P01CR), #0x04
197 ld (P3), #0xF7
198 ld (P3CR), #0xA5 ; P30 = RXD, P31 = IN:PaperOut CN3, P32 = TXD, P33 = OUT:CN2.LF P34:IN, P37:IN
200 ld (P4), #0x00
201 ld (P4CR), #0x03 ; address output
202 ld (P7), #0x03
203 ld (P67CR), #0xF0
204 ld (SMMOD), #0xA0
205 ld (SMCR), #0x00
206 ld (T4MOD), #0x35
207 ld (P8), #0x08
208 ld (P8CR), #0x08
209 ld (T4FFCR), #0x01
211 ld (TMOD), #0x40
213 ;ld (SCMOD), #0x03 ; 9600
214 ld (SCMOD), #0x01 ; 19200
215 or (SCMOD), #0x08 ; 8-bit data
216 or (SCMOD), #0x20 ; receiver enable
218 ld (SCCR), #0x00
220 ld (WDMOD), #0xC0
221 ld (TRUN), #0x20 ; PRRUN, start prescaler
222 or (TRUN), #0xE0 ; BRATE, 19200 baud
224 ;; enable rx/tx irqs
225 set 0,(INTEL) ; tx
226 set 1,(INTEL) ; rx
228 ;call _boot1
230 ld hl, #0xFF20 ; data start
231 ld a, #0x00
233 clear_ram:
234 call _wd_reset_asm
236 ld (hl),a
237 inc hl
238 cp hl, #0xFFC0 ; io start, 160 bytes data
239 jr nz, clear_ram
241 call _wd_reset_asm
243 res TX_ACTIVE,(_ser_irq_flags)
245 ;call _boot2
246 call _meminit
248 call _wd_reset_asm
250 ;; Initialise global variables
252 ;call _boot3
254 call gsinit
256 ;call _boot4
258 call _main
259 halt
261 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
263 .area _CODE
265 ;; get far byte using by
267 _xget_byte_asm:
268 push bc
269 ld iy, (_xxaddr)
270 ld b, (BY)
271 ld a, (_xxby)
272 ld (BY), a
273 ld a,(iy)
274 ld (BY), b
275 ld (_xxdata), a
276 pop bc
279 _xset_byte_asm:
280 push bc
281 ld iy, (_xxaddr)
282 ld b, (BY)
283 ld a, (_xxby)
284 ld (BY), a
285 ld a, (_xxdata)
286 ld (iy), a
287 ld (BY), b
288 pop bc
291 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
293 _serial_rx_irq:
294 ld a, (SCBUF)
295 ld (_ser_char), a
296 set RX_READY, (_ser_irq_flags)
297 reti
299 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
301 _serial_tx_irq:
302 res TX_ACTIVE,(_ser_irq_flags)
303 ld (IRFH), #0x0F ; clear tx request flag (vector 0x78/8 = 0x0F)
304 reti
306 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
308 _swi_irq:
309 push hl
310 ld hl, 4(sp)
311 ld (_swi_pc), hl ; pc
312 ld hl, 2(sp)
313 ld (_swi_af), hl ; af
314 call _irq_info_swi
315 pop hl
316 reti
317 _intwd_irq:
318 call _irq_info_intwd
319 reti
320 _intt0_irq:
321 call _irq_info_intt0
322 reti
323 _intt1_irq:
324 ;call _irq_info_intt1
325 ;exx
327 ; hangs when exx is used?
328 incw (_ticks16)
330 ; hangs when exx is used?
331 ;; ld hl, (_ticks16)
332 ;; inc hl
333 ;; ld (_ticks16), hl
335 ld (WDCR), #0x4E
336 ld (IRFL), #0x10;
337 ;call _timer1_irq
338 ;exx
339 reti
340 _intt3_irq:
341 call _irq_info_intt3
342 reti
343 _intt4_irq:
344 call _irq_info_intt4
345 reti
346 _int1_irq:
347 call _irq_info_int1
348 reti
349 _intt5_irq:
350 call _irq_info_intt5
351 reti
353 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
355 _ser_putchar_irq:
356 ld a, 2(sp)
358 _ser_putchar_asm:
360 loop1:
362 ;; check tx active flag
363 bit TX_ACTIVE,(_ser_irq_flags)
364 jr z, send1
367 bit 0,(IRFH) ; check irq
368 jr nz, send1
373 call _wd_reset_asm
374 jr loop1 ; loop, wait for irq
376 send1:
378 ld (IRFH),#0x0F ; clear tx request flag (vector 0x78/8 = 0x0F)
379 ld (SCBUF),a ; send
380 set TX_ACTIVE,(_ser_irq_flags) ; tx active..
384 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
386 _ser_puts:
387 ld hl, 2(sp)
389 ser_puts1:
390 ld a,(hl)
391 or a, a
392 ret z
394 call _ser_putchar_asm
395 inc hl
396 jr ser_puts1
398 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
400 _WatchDogDisable:
401 ld (WDMOD), #0x00 ; wd disable code
402 ld (WDCR), #0xB1 ; wd disable code
405 _wd_reset_asm:
406 ld (WDCR), #0x4E ; wd clear code
408 .if 0
409 ; STAR ASIC? Not needed..
410 push bc
411 push iy
413 ld b,(BY)
414 ld (BY), #0x01
415 ld iy, #0x4001
416 set 1,(iy)
417 nop
418 nop
419 res 1,(iy)
420 ld (BY),b
422 pop iy
423 pop bc
425 .endif
429 ;; Ordering of segments for the linker.
430 .area _HOME
431 .area _CODE
432 .area _INITIALIZER
433 .area _GSINIT
434 .area _GSFINAL
436 .area _DATA
437 .area _INITIALIZED
438 .area _BSEG
439 .area _BSS
440 .area _HEAP
442 .area _CODE
444 .area _GSINIT
445 gsinit::
446 ld bc, #l__INITIALIZER
447 ld a, b
448 or a, c
449 jr Z, gsinit_next
450 ld de, #s__INITIALIZED
451 ld hl, #s__INITIALIZER
452 ldir
453 gsinit_next:
455 .area _GSFINAL
458 .area _DATA
459 ; __sfr __at
460 _ser_irq_flags = 0xffbf
461 _ser_char = 0xffbe
462 _swi_pc = 0xffbc
463 _swi_af = 0xffba
464 _ticks16 = 0xffb8
465 _xflag = 0xffb7