OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [NEC_78K0R_IAR/] [cstartup.s26] - Blame information for rev 584

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 584 jeremybenn
;
2
; This file should only be included in the 78K0R_Kx3L demo.  The 78K0R_Kx3 demo
3
; uses the standard startup file.  This is work around a bug in the startup
4
; file provided with the IAR tools.
5
;
6
 
7
 
8
;------------------------------------------------------------------------------
9
;       CSTARTUP source for 78K
10
;
11
;       This module contains the code executed before the C/C++ "main"
12
;       function is called.
13
;
14
;       The code usually must be tailored to suit a specific hardware
15
;       configuration.
16
;
17
;       Assembler options:
18
;
19
;       -D__STANDARD_MODEL__    To assemble for use with compiler standard
20
;                               code model.
21
;
22
;       -D__BANKED_MODEL__      To assemble for use with compiler banked
23
;                               code model.
24
;
25
;       -D__NEAR_MODEL__        To assemble for use with compiler near
26
;                               code model.
27
;
28
;       -D__FAR_MODEL__         To assemble for use with compiler far
29
;                               code model.
30
;
31
;       Linker options:
32
;
33
;       -D_CODEBANK_REG=0       To link for use with "standard" code model,
34
;                               no banked functions.
35
;
36
;       -D_CODEBANK_REG='addr'  To link for use with "banked" code model or
37
;                               "standard" code model with banked functions.
38
;                               'addr' = bank switch register address.
39
;
40
;------------------------------------------------------------------------------
41
;       Copyright (c) 2003-2008 IAR Systems AB.
42
;       $Revision: 2 $
43
;------------------------------------------------------------------------------
44
 
45
#if !defined(__STANDARD_MODEL__) && !defined(__BANKED_MODEL__) && !defined(__NEAR_MODEL__) && !defined(__FAR_MODEL__)
46
  #error One of the macros __STANDARD_MODEL__, __BANKED_MODEL__, __NEAR_MODEL__ or __FAR_MODEL__ must be defined !
47
#endif
48
 
49
;------------------------------------------------------------------------------
50
;       The stack segment.
51
;       The stack size is defined in the linker command file
52
;------------------------------------------------------------------------------
53
 
54
        MODULE  ?CSTARTUP
55
 
56
        RSEG    CSTACK:DATA:ROOT(1)
57
 
58
 
59
;------------------------------------------------------------------------------
60
;       The interrupt vector segment.
61
;       Interrupt functions with defined vectors will reserve
62
;       space in this area as well as conformingly written assembly
63
;       language interrupt handlers
64
;------------------------------------------------------------------------------
65
 
66
        COMMON  INTVEC:CODE:ROOT(1)
67
 
68
        DC16    __program_start_fr                 ; Reset vector
69
 
70
 
71
;------------------------------------------------------------------------------
72
;       The actual startup code
73
;
74
;       Entry:  __program_start
75
;------------------------------------------------------------------------------
76
 
77
        RSEG    RCODE:CODE:ROOT(0)
78
 
79
        PUBLIC  ?C_STARTUP
80
        PUBLIC  `@cstart`             ; NEC debugger specific
81
        PUBLIC  __program_start_fr
82
 
83
        EXTERN  __low_level_init
84
        EXTERN  __MAIN_CALL
85
 
86
#if defined(__STANDARD_MODEL__) || defined(__BANKED_MODEL__)
87
        EXTERN  _CODEBANK_REG
88
#else
89
        EXTERN  _NEAR_CONST_LOCATION
90
PMC     DEFINE  0xFFFFE
91
#endif
92
#if defined(__BANKED_MODEL__)
93
        EXTERN  ?FAR_CALL_L07
94
 
95
        SFRTYPE BANK_REG BYTE, READ, WRITE = _CODEBANK_REG
96
#endif
97
 
98
        REQUIRE __MAIN_CALL
99
 
100
 
101
;------------------------------------------------------------------------------
102
;       Perform the run-time initialization.
103
;------------------------------------------------------------------------------
104
 
105
?C_STARTUP:
106
`@cstart`:
107
__program_start_fr:
108
        DI
109
 
110
#if defined(__BANKED_MODEL__)
111
        MOV     BANK_REG, #0                    ; Banked, clear bank register
112
#elif defined(__STANDARD_MODEL__)
113
        MOVW    AX, #_CODEBANK_REG
114
        OR      A, X
115
        BZ      nobank                          ; Standard, no banked functions, no bank register (=0)
116
        MOVW    HL, #_CODEBANK_REG
117
        XOR     A, A
118
        MOV     [HL], A                         ; Standard with banked functions, clear bank register
119
nobank:
120
#else
121
        MOV     A, #(_NEAR_CONST_LOCATION & 1)  ; Near/Far, set mirror area
122
        MOV1    CY, A.0
123
        MOV1    PMC.0, CY
124
#endif
125
 
126
#if __CORE__ != __78K0S__
127
        MOVW    SP, #sfe(CSTACK)
128
#else
129
        MOVW    AX, #sfe(CSTACK)
130
        MOVW    SP, AX
131
#endif
132
 
133
 
134
        ; Init stack segment for 78K0R, as the generated code may sometimes
135
        ; access the 4th byte of a return address before it is initialized
136
#if __CORE__ == __78K0R__
137
        MOVW    HL, #sfb(CSTACK)
138
        MOVW    BC, #LWRD(sizeof(CSTACK))
139
        CMP0    C
140
        SKZ
141
        INC     B
142
        MOV     A, #0xCD
143
loop_s:
144
        MOV     [HL], A
145
        INCW    HL
146
        DEC     C
147
        BNZ     loop_s
148
        DEC     B
149
        BNZ     loop_s
150
#endif
151
 
152
#if __CORE__ == __78K0R__
153
        MOV     CS, #0
154
#endif
155
 
156
;------------------------------------------------------------------------------
157
;       Here is the place to put user initializations.
158
;------------------------------------------------------------------------------
159
 
160
;       User initialization code
161
 
162
;------------------------------------------------------------------------------
163
;       Call __low_level_init to perform initialization before initializing
164
;       segments and calling main.
165
;       If the function returns 0, no segment initialization should take place.
166
;
167
;       Link with your own version of __low_level_init to override the
168
;       default action: to do nothing but return 1.
169
;------------------------------------------------------------------------------
170
 
171
#if defined(__FAR_MODEL__)
172
        CALL    F:__low_level_init
173
#elif defined(__BANKED_MODEL__)
174
        MOV     E,  #byte3(__low_level_init)
175
        MOVW    HL, #lwrd(__low_level_init)
176
        CALL    ?FAR_CALL_L07
177
#else
178
        CALL    __low_level_init
179
#endif
180
        OR      A, X
181
#if __CORE__ == __78K0R__
182
        SKNZ
183
        BR      N:__MAIN_CALL
184
#else
185
        BZ      __MAIN_CALL
186
#endif
187
        ENDMOD
188
 
189
#if defined(__NEAR_MODEL__) || defined(__FAR_MODEL__)
190
;------------------------------------------------------------------------------
191
;       Segment initialization
192
;
193
;       FAR_Z  "uninitialized far data" are filled with zero
194
;------------------------------------------------------------------------------
195
 
196
        MODULE  ?__INIT_FAR_Z
197
 
198
        RSEG    FAR_Z:DATA(0)
199
        RSEG    RCODE:CODE:NOROOT(0)
200
 
201
        PUBLIC  __INIT_FAR_Z
202
 
203
__INIT_FAR_Z:
204
        MOV     ES, #BYTE3(sfb(FAR_Z))
205
        MOVW    HL, #LWRD(sfb(FAR_Z))
206
        MOV     D, #BYTE3(sizeof(FAR_Z))
207
        MOVW    BC, #LWRD(sizeof(FAR_Z))
208
        CMP0    C
209
        SKZ
210
        INC     B
211
        CMP0    B
212
        SKZ
213
        INC     D
214
        CLRB    A
215
loop:
216
        MOV     ES:[HL], A
217
        INCW    HL
218
        MOV     A, H
219
        OR      A, L
220
        CLRB    A
221
        SKNZ
222
        INC     ES
223
        DEC     C
224
        BNZ     loop
225
        DEC     B
226
        BNZ     loop
227
        DEC     D
228
        BNZ     loop
229
 
230
        ENDMOD
231
#endif
232
 
233
 
234
;------------------------------------------------------------------------------
235
;       Segment initialization
236
;
237
;       NEAR_Z  "uninitialized near data" are filled with zero
238
;------------------------------------------------------------------------------
239
 
240
        MODULE  ?__INIT_NEAR_Z
241
 
242
        RSEG    NEAR_Z:DATA(0)
243
        RSEG    RCODE:CODE:NOROOT(0)
244
 
245
        PUBLIC  __INIT_NEAR_Z
246
 
247
__INIT_NEAR_Z:
248
#if __CORE__ == __78K0R__
249
        LIMIT   sfb(NEAR_Z)>=0xF0000,1,1,"NEAR_I not placed in near memory"
250
#endif
251
        MOVW    HL, #sfb(NEAR_Z)
252
        MOVW    BC, #sizeof(NEAR_Z)
253
#if __CORE__ == __78K0R__
254
        CMP0    C
255
        SKZ
256
        INC     B
257
        CLRB    A
258
#else
259
        MOV     A, C
260
        OR      A, A
261
        BZ      cont
262
        INC     B
263
        XOR     A, A
264
cont:
265
#endif
266
loop:
267
        MOV     [HL], A
268
        INCW    HL
269
#if __CORE__ == __78K0R__
270
        DEC     C
271
        BNZ     loop
272
        DEC     B
273
        BNZ     loop
274
#else
275
        DBNZ    C, loop
276
        DBNZ    B, loop
277
#endif
278
 
279
        ENDMOD
280
 
281
 
282
;------------------------------------------------------------------------------
283
;       Segment initialization
284
;
285
;       SADDR_Z "uninitialized saddr data" are filled with zero
286
;------------------------------------------------------------------------------
287
 
288
        MODULE  ?__INIT_SADDR_Z
289
 
290
        RSEG    SADDR_Z:DATA(0)
291
        RSEG    RCODE:CODE:NOROOT(0)
292
 
293
        PUBLIC  __INIT_SADDR_Z
294
 
295
__INIT_SADDR_Z:
296
#if __CORE__ == __78K0R__
297
        LIMIT   sfb(SADDR_Z),0xFFE20,0xFFF1F,"SADDR_Z not within saddr memory range"
298
        LIMIT   sfe(SADDR_Z),0xFFE20,0xFFF1F,"SADDR_Z not within saddr memory range"
299
#else
300
        LIMIT   sfb(SADDR_Z),0xFE20,0xFF1F,"SADDR_Z not within saddr memory range"
301
        LIMIT   sfe(SADDR_Z),0xFE20,0xFF1F,"SADDR_Z not within saddr memory range"
302
#endif
303
        MOVW    HL, #sfb(SADDR_Z)
304
        MOV     B, #sizeof(SADDR_Z)
305
#if __CORE__ == __78K0R__
306
        CLRB    A
307
#else
308
        XOR     A, A
309
#endif
310
loop:
311
        MOV     [HL], A
312
        INCW    HL
313
#if __CORE__ == __78K0R__
314
        DEC     B
315
        BNZ     loop
316
#else
317
        DBNZ    B, loop
318
#endif
319
 
320
        ENDMOD
321
 
322
 
323
;------------------------------------------------------------------------------
324
;       Segment initialization
325
;
326
;       WRKSEG short address work area is filled with zero
327
;------------------------------------------------------------------------------
328
 
329
        MODULE  ?__INIT_WRKSEG
330
 
331
        RSEG    WRKSEG:DATA(0)
332
        RSEG    RCODE:CODE:NOROOT(0)
333
 
334
        PUBLIC  __INIT_WRKSEG
335
 
336
__INIT_WRKSEG:
337
#if __CORE__ == __78K0R__
338
        LIMIT   sfb(WRKSEG),0xFFE20,0xFFF1F,"WRKSEG not within saddr memory range"
339
        LIMIT   sfe(WRKSEG),0xFFE20,0xFFF1F,"WRKSEG not within saddr memory range"
340
#else
341
        LIMIT   sfb(WRKSEG),0xFE20,0xFF1F,"WRKSEG not within saddr memory range"
342
        LIMIT   sfe(WRKSEG),0xFE20,0xFF1F,"WRKSEG not within saddr memory range"
343
#endif
344
        MOVW    HL, #sfb(WRKSEG)
345
        MOV     B, #sizeof(WRKSEG)
346
#if __CORE__ == __78K0R__
347
        CLRB    A
348
#else
349
        XOR     A, A
350
#endif
351
loop:
352
        MOV     [HL], A
353
        INCW    HL
354
#if __CORE__ == __78K0R__
355
        DEC     B
356
        BNZ     loop
357
#else
358
        DBNZ    B, loop
359
#endif
360
 
361
        ENDMOD
362
 
363
 
364
#if defined(__NEAR_MODEL__) || defined(__FAR_MODEL__)
365
;------------------------------------------------------------------------------
366
;       Segment initialization
367
;
368
;       FAR_ID is copied to FAR_I    "initialized far data"
369
;------------------------------------------------------------------------------
370
 
371
        MODULE  ?__INIT_FAR_I
372
 
373
        RSEG    FAR_I:DATA(0)
374
        RSEG    FAR_ID:DATA(0)
375
        RSEG    RCODE:CODE:NOROOT(0)
376
 
377
        PUBLIC  __INIT_FAR_I
378
 
379
__INIT_FAR_I:
380
        ; First make sure FAR_I and FAR_ID have the same size
381
        LIMIT   sizeof(FAR_I)-sizeof(FAR_ID),0,0,"FAR_I and FAR_ID not same size"
382
 
383
        ; Sanity check
384
        LIMIT   (sfb(FAR_I)-sfb(FAR_ID))==0,0,0,"FAR_I and FAR_ID have same start address"
385
 
386
        ; FAR_I and FAR_ID must start at the same offset in a 64k page, unless sizeof
387
        ; FAR_I is less than 64k, then it's enugh if both segments reside within a 64k
388
        ; boundary
389
        LIMIT   (((sfb(FAR_I)^sfb(FAR_ID)) & 0xFFFF) == 0) || ( (sizeof(FAR_I)< 0x10000) && (((sfb(FAR_I)^sfe(FAR_I)) & 0xF0000) == 0) && (((sfb(FAR_I)^sfe(FAR_I)) & 0xF0000) == 0) ),1,1,"FAR_I and FAR_ID have same start address"
390
 
391
 
392
 
393
        ;         LIMIT   (sfb(FAR_I)^sfb(FAR_ID)) & 0xFFFF,0,0,"FAR_I and FAR_ID must start at the same offset into a 64k page"
394
        MOV     ES, #BYTE3(sfb(FAR_ID))
395
        MOVW    HL, #LWRD(sfb(FAR_ID))
396
        MOV     CS, #BYTE3(sizeof(FAR_ID))    ; CS is used as counter
397
        MOVW    AX, #LWRD(sizeof(FAR_ID))
398
        MOVW    BC, AX
399
        CMP0    C
400
        SKZ
401
        INC     B
402
        CMP0    B
403
        SKZ
404
        INC     CS                            ; counter
405
        MOV     A, #BYTE3(sfb(FAR_I))
406
        MOVW    DE, #LWRD(sfb(FAR_I))
407
        MOV     X, A
408
loop:
409
        MOV     A, ES:[HL]
410
        XCH     A, X
411
        XCH     A, ES
412
        XCH     A, X
413
        MOV     ES:[DE], A
414
        XCH     A, X
415
        XCH     A, ES
416
        XCH     A, X
417
        INCW    HL
418
        MOV     A, H
419
        OR      A, L
420
        SKNZ
421
        INC     ES
422
        INCW    DE
423
        MOV     A, D
424
        OR      A, E
425
        SKNZ
426
        INC     X
427
        DEC     C
428
        BNZ     loop
429
        DEC     B
430
        BNZ     loop
431
        DEC     CS                            ; counter
432
        BNZ     loop
433
 
434
        ENDMOD
435
#endif
436
 
437
 
438
;------------------------------------------------------------------------------
439
;       Segment initialization
440
;
441
;       NEAR_ID is copied to NEAR_I    "initialized near data"
442
;------------------------------------------------------------------------------
443
 
444
        MODULE  ?__INIT_NEAR_I
445
 
446
        RSEG    NEAR_I:DATA(0)
447
        RSEG    NEAR_ID:DATA(0)
448
        RSEG    RCODE:CODE:NOROOT(0)
449
 
450
        PUBLIC  __INIT_NEAR_I
451
 
452
__INIT_NEAR_I:
453
#if __CORE__ == __78K0R__
454
        LIMIT   sfb(NEAR_I)>=0xF0000,1,1,"NEAR_I not placed in near memory"
455
#endif
456
        LIMIT   sizeof(NEAR_I)-sizeof(NEAR_ID),0,0,"NEAR_I and NEAR_ID not same size"
457
#if __CORE__ == __78K0R__
458
        MOV     ES, #BYTE3(sfb(NEAR_ID))
459
#endif
460
        MOVW    HL, #sfb(NEAR_ID)
461
        MOVW    BC, #sizeof(NEAR_ID)
462
#if __CORE__ == __78K0R__
463
        CMP0    C
464
        SKZ
465
        INC     B
466
#else
467
        MOV     A, C
468
        OR      A, A
469
        BZ      cont
470
        INC     B
471
cont:
472
#endif
473
        MOVW    DE, #sfb(NEAR_I)
474
loop:
475
#if __CORE__ != __78K0R__
476
        MOV     A, [HL]
477
#else
478
        MOV     A, ES:[HL]
479
#endif
480
        MOV     [DE], A
481
        INCW    HL
482
        INCW    DE
483
#if __CORE__ == __78K0R__
484
        DEC     C
485
        BNZ     loop
486
        DEC     B
487
        BNZ     loop
488
#else
489
        DBNZ    C, loop
490
        DBNZ    B, loop
491
#endif
492
 
493
        ENDMOD
494
 
495
 
496
;------------------------------------------------------------------------------
497
;       Segment initialization
498
;
499
;       SADDR_ID is copied to SADDR_I  "initialized saddr data"
500
;------------------------------------------------------------------------------
501
 
502
        MODULE  ?__INIT_SADDR_I
503
 
504
        RSEG    SADDR_I:DATA(0)
505
        RSEG    SADDR_ID:DATA(0)
506
        RSEG    RCODE:CODE:NOROOT(0)
507
 
508
        PUBLIC  __INIT_SADDR_I
509
 
510
__INIT_SADDR_I:
511
#if __CORE__ == __78K0R__
512
        LIMIT   sfb(SADDR_I),0xFFE20,0xFFF1F,"SADDR_I not within saddr memory range"
513
        LIMIT   sfe(SADDR_I),0xFFE20,0xFFF1F,"SADDR_I not within saddr memory range"
514
#else
515
        LIMIT   sfb(SADDR_I),0xFE20,0xFF1F,"SADDR_I not within saddr memory range"
516
        LIMIT   sfe(SADDR_I),0xFE20,0xFF1F,"SADDR_I not within saddr memory range"
517
#endif
518
        LIMIT   sizeof(SADDR_I)-sizeof(SADDR_ID),0,0,"SADDR_I and SADDR_ID not same size"
519
#if __CORE__ == __78K0R__
520
        MOV     ES, #BYTE3(sfb(SADDR_ID))
521
#endif
522
        MOVW    HL, #sfb(SADDR_ID)
523
        MOV     B, #sizeof(SADDR_ID)
524
        MOVW    DE, #sfb(SADDR_I)
525
loop:
526
#if __CORE__ != __78K0R__
527
        MOV     A, [HL]
528
#else
529
        MOV     A, ES:[HL]
530
#endif
531
        MOV     [DE], A
532
        INCW    HL
533
        INCW    DE
534
#if __CORE__ == __78K0R__
535
        DEC     B
536
        BNZ     loop
537
#else
538
        DBNZ    B, loop
539
#endif
540
 
541
        ENDMOD
542
 
543
 
544
;------------------------------------------------------------------------------
545
;       Initialize constructors
546
;
547
;       This segment part is required by the compiler when it is
548
;       necessary to call constructors of global objects.
549
;------------------------------------------------------------------------------
550
 
551
        MODULE  ?__INIT_CTORS
552
 
553
        RSEG    DIFUNCT(0)
554
        RSEG    RCODE:CODE:NOROOT(0)
555
 
556
        PUBLIC  __INIT_CTORS
557
 
558
        EXTERN  __call_ctors
559
#if defined(__BANKED_MODEL__)
560
        EXTERN  ?FAR_CALL_L07
561
#endif
562
 
563
__INIT_CTORS:
564
#if __CORE__ == __78K0R__
565
        MOV     X,  #byte3(sfe(DIFUNCT))
566
        PUSH    AX
567
        MOVW    AX, #lwrd(sfe(DIFUNCT))
568
        PUSH    AX
569
        MOV     X,  #byte3(sfb(DIFUNCT))
570
        PUSH    AX
571
        MOVW    AX, #lwrd(sfb(DIFUNCT))
572
        PUSH    AX
573
        CALL    F:__call_ctors
574
#elif defined(__BANKED_MODEL__)
575
        MOVW    AX, #sfb(DIFUNCT)
576
        MOVW    BC, #sfe(DIFUNCT)
577
        MOV     E,  #byte3(__call_ctors)
578
        MOVW    HL, #lwrd(__call_ctors)
579
        CALL    ?FAR_CALL_L07
580
#else
581
        MOVW    AX, #sfb(DIFUNCT)
582
        MOVW    BC, #sfe(DIFUNCT)
583
        CALL    __call_ctors
584
#endif
585
 
586
        ENDMOD
587
 
588
 
589
;------------------------------------------------------------------------------
590
;       Enter main
591
;
592
;       Call the actual "main" function
593
;------------------------------------------------------------------------------
594
 
595
        MODULE  ?__MAIN_CALL
596
 
597
        RSEG    RCODE:CODE:NOROOT(0)
598
 
599
        PUBLIC  __MAIN_CALL
600
        PUBLIC  `@cend`             ; NEC debugger specific
601
 
602
        EXTERN  main
603
        EXTERN  exit
604
#if defined(__BANKED_MODEL__)
605
        EXTERN  ?FAR_CALL_L07
606
#endif
607
 
608
__MAIN_CALL:
609
#if defined(__FAR_MODEL__)
610
        CALL    F:main
611
        CALL    F:exit
612
#elif defined(__BANKED_MODEL__)
613
        MOV     E,  #byte3(main)
614
        MOVW    HL, #lwrd(main)
615
        CALL    ?FAR_CALL_L07
616
 
617
        MOV     E,  #byte3(exit)
618
        MOVW    HL, #lwrd(exit)
619
        CALL    ?FAR_CALL_L07
620
#else
621
        CALL    main
622
        CALL    exit
623
#endif
624
 
625
`@cend`:
626
 
627
;       STOP                            ; Should not return
628
 
629
        ENDMOD
630
 
631
 
632
;------------------------------------------------------------------------------
633
;       Low level initialization function
634
;
635
;       Entry:  __low_level_init
636
;
637
;       The only action of this default version of '__low_level_init' is to
638
;       return 1. By doing so it signals that normal initialization of data
639
;       segments should be done.
640
;
641
;       A customized version of '__low_level_init' may be created in order to
642
;       perform initialization before initializing segments and calling main
643
;       and/or to skip initialization of data segments under certain
644
;       circumstances.
645
;------------------------------------------------------------------------------
646
 
647
        MODULE  ?__low_level_init_stub
648
 
649
        RSEG    RCODE:CODE:NOROOT(0)
650
 
651
        PUBLIC  __low_level_init
652
 
653
__low_level_init:                       ; By returning 1 this function
654
        MOVW    AX, #1                  ; indicates that the normal
655
        RET                             ; initialization should take place
656
 
657
        ENDMOD
658
 
659
        END

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.