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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [frv/] [arch/] [v2_0/] [src/] [vectors.S] - Blame information for rev 27

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
// #========================================================================
2
// #
3
// #    vectors.S
4
// #
5
// #    Fujitsu exception vectors
6
// #
7
// #========================================================================
8
//####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under
14
// the terms of the GNU General Public License as published by the Free
15
// Software Foundation; either version 2 or (at your option) any later version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
//
36
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37
// at http://sources.redhat.com/ecos/ecos-license/
38
// -------------------------------------------
39
//####ECOSGPLCOPYRIGHTEND####
40
// #========================================================================
41
// ######DESCRIPTIONBEGIN####
42
// #
43
// # Author(s):     gthomas
44
// # Contributors:  gthomas
45
// # Date:          2001-09-16
46
// # Purpose:       Fujitsu exception vectors
47
// # Description:   This file defines the code placed into the exception
48
// #                vectors. It also contains the first level default VSRs
49
// #                that save and restore state for both exceptions and
50
// #                interrupts.
51
// #
52
// #####DESCRIPTIONEND####
53
// #
54
// #========================================================================
55
 
56
#include 
57
#include CYGBLD_HAL_PLF_DEFS_H
58
#include "frv.inc"
59
#include 
60
 
61
        .macro  lda a r
62
        sethi   #gprelhi(\a),\r
63
        setlo   #gprello(\a),\r
64
        add     \r,gr16,\r
65
        .endm
66
 
67
        .macro  li v r
68
        sethi   #((\v)>>16),\r
69
        setlo   #((\v)&0xFFFF),\r
70
        .endm
71
 
72
        .macro  save_GDB_exception_regs base,orig
73
        // 'orig' points to an area where some registers were already saved
74
        // orig+0:      GPR4
75
        // orig+4:      GPR5
76
        // orig+8:      GPR6
77
        // orig+12:     GPR16
78
        // orig+16:     LR
79
        // orig+20:     CCR
80
        sti     gr4,@(\base,_TS_VECTOR)
81
        addi    \orig,24,gr5
82
        sti     gr5,@(\base,_TS_SP)
83
        ldi     @(\orig,0),gr5
84
        sti     gr5,@(\base,_TS_GPR4)
85
        ldi     @(\orig,4),gr5
86
        sti     gr5,@(\base,_TS_GPR5)
87
        ldi     @(\orig,8),gr5
88
        sti     gr5,@(\base,_TS_GPR6)
89
        ldi     @(\orig,12),gr5
90
        sti     gr5,@(\base,_TS_GPR16)
91
        ldi     @(\orig,16),gr5
92
        sti     gr5,@(\base,_TS_LR)
93
        ldi     @(\orig,20),gr5
94
        sti     gr5,@(\base,_TS_CCR)
95
        .endm
96
 
97
        .macro  save_exception_regs base
98
        sti     gr4,@(\base,_TS_VECTOR)
99
        sti     gr5,@(\base,_TS_GPR5)
100
        addi    sp,_TS_size,gr5
101
        sti     gr5,@(\base,_TS_SP)
102
        sti     gr6,@(\base,_TS_GPR6)
103
        sti     gr16,@(\base,_TS_GPR16)
104
        movsg   lr,gr5
105
        sti     gr5,@(\base,_TS_LR)
106
        movsg   ccr,gr5
107
        sti     gr5,@(\base,_TS_CCR)
108
        .endm
109
 
110
        // Save the machine state after an interrupt/exception
111
        // Note: it might be possible to use stdi/lddi instructions here,
112
        // but it would require that the stack pointer always be 64 bit
113
        // (doubleword) aligned.
114
        .macro  save_state base
115
        sti     gr0,@(\base,_TS_GPR0)
116
        sti     gr2,@(\base,_TS_GPR2)
117
        sti     gr3,@(\base,_TS_GPR3)
118
        sti     gr7,@(\base,_TS_GPR7)
119
        sti     gr8,@(\base,_TS_GPR8)
120
        sti     gr9,@(\base,_TS_GPR9)
121
        sti     gr10,@(\base,_TS_GPR10)
122
        sti     gr11,@(\base,_TS_GPR11)
123
        sti     gr12,@(\base,_TS_GPR12)
124
        sti     gr13,@(\base,_TS_GPR13)
125
        sti     gr14,@(\base,_TS_GPR14)
126
        sti     gr15,@(\base,_TS_GPR15)
127
        sti     gr17,@(\base,_TS_GPR17)
128
        sti     gr18,@(\base,_TS_GPR18)
129
        sti     gr19,@(\base,_TS_GPR19)
130
        sti     gr20,@(\base,_TS_GPR20)
131
        sti     gr21,@(\base,_TS_GPR21)
132
        sti     gr22,@(\base,_TS_GPR22)
133
        sti     gr23,@(\base,_TS_GPR23)
134
        sti     gr24,@(\base,_TS_GPR24)
135
        sti     gr25,@(\base,_TS_GPR25)
136
        sti     gr26,@(\base,_TS_GPR26)
137
        sti     gr27,@(\base,_TS_GPR27)
138
        sti     gr28,@(\base,_TS_GPR28)
139
        sti     gr29,@(\base,_TS_GPR29)
140
        sti     gr30,@(\base,_TS_GPR30)
141
        sti     gr31,@(\base,_TS_GPR31)
142
#if _NGPR != 32
143
        sti     gr32,@(\base,_TS_GPR32)
144
        sti     gr33,@(\base,_TS_GPR33)
145
        sti     gr34,@(\base,_TS_GPR34)
146
        sti     gr35,@(\base,_TS_GPR35)
147
        sti     gr36,@(\base,_TS_GPR36)
148
        sti     gr37,@(\base,_TS_GPR37)
149
        sti     gr38,@(\base,_TS_GPR38)
150
        sti     gr39,@(\base,_TS_GPR39)
151
        sti     gr40,@(\base,_TS_GPR40)
152
        sti     gr41,@(\base,_TS_GPR41)
153
        sti     gr42,@(\base,_TS_GPR42)
154
        sti     gr43,@(\base,_TS_GPR43)
155
        sti     gr44,@(\base,_TS_GPR44)
156
        sti     gr45,@(\base,_TS_GPR45)
157
        sti     gr46,@(\base,_TS_GPR46)
158
        sti     gr47,@(\base,_TS_GPR47)
159
        sti     gr48,@(\base,_TS_GPR48)
160
        sti     gr49,@(\base,_TS_GPR49)
161
        sti     gr50,@(\base,_TS_GPR50)
162
        sti     gr51,@(\base,_TS_GPR51)
163
        sti     gr52,@(\base,_TS_GPR52)
164
        sti     gr53,@(\base,_TS_GPR53)
165
        sti     gr54,@(\base,_TS_GPR54)
166
        sti     gr55,@(\base,_TS_GPR55)
167
        sti     gr56,@(\base,_TS_GPR56)
168
        sti     gr57,@(\base,_TS_GPR57)
169
        sti     gr58,@(\base,_TS_GPR58)
170
        sti     gr59,@(\base,_TS_GPR59)
171
        sti     gr60,@(\base,_TS_GPR60)
172
        sti     gr61,@(\base,_TS_GPR61)
173
        sti     gr62,@(\base,_TS_GPR62)
174
        sti     gr63,@(\base,_TS_GPR63)
175
#endif
176
        movsg   psr,gr5
177
        sti     gr5,@(\base,_TS_PSR)
178
        movsg   lcr,gr5
179
        sti     gr5,@(\base,_TS_LCR)
180
        movsg   cccr,gr5
181
        sti     gr5,@(\base,_TS_CCCR)
182
        movsg   bpcsr,gr5
183
#if defined( CYGSEM_HAL_FRV_HW_DEBUG ) || defined(CYGPKG_HAL_FRV_FRV400)
184
        cmpi    gr4,#CYGNUM_HAL_VECTOR_BREAKPOINT,icc0
185
        beq     icc0,0,10f
186
#endif
187
5:      movsg   pcsr,gr5
188
        cmpi    gr4,#CYGNUM_HAL_VECTOR_SYSCALL,icc0
189
        blt     icc0,0,10f
190
6:      subi    gr5,#4,gr5              // traps show PC+4
191
10:     sti     gr5,@(\base,_TS_PC)
192
        .endm
193
 
194
        // Restore the machine state after an interrupt/exception
195
        .macro  restore_state base,pcreg,retv
196
        ldi     @(\base,_TS_PC),gr5
197
        movgs   gr5,\pcreg
198
        ldi     @(\base,_TS_CCR),gr5
199
        movgs   gr5,ccr
200
        ldi     @(\base,_TS_LR),gr5
201
        movgs   gr5,lr
202
        ldi     @(\base,_TS_PSR),gr5
203
        movgs   gr5,psr
204
        ldi     @(\base,_TS_LCR),gr5
205
        movgs   gr5,lcr
206
        ldi     @(\base,_TS_CCCR),gr5
207
        movgs   gr5,cccr
208
        ldi     @(\base,_TS_GPR2),gr2
209
        ldi     @(\base,_TS_GPR3),gr3
210
        ldi     @(\base,_TS_GPR4),gr4
211
        ldi     @(\base,_TS_GPR5),gr5
212
        ldi     @(\base,_TS_GPR6),gr6
213
        ldi     @(\base,_TS_GPR7),gr7
214
        ldi     @(\base,_TS_GPR8),gr8
215
        ldi     @(\base,_TS_GPR9),gr9
216
        ldi     @(\base,_TS_GPR10),gr10
217
        ldi     @(\base,_TS_GPR11),gr11
218
        ldi     @(\base,_TS_GPR12),gr12
219
        ldi     @(\base,_TS_GPR13),gr13
220
        ldi     @(\base,_TS_GPR14),gr14
221
        ldi     @(\base,_TS_GPR15),gr15
222
        ldi     @(\base,_TS_GPR16),gr16
223
        ldi     @(\base,_TS_GPR17),gr17
224
        ldi     @(\base,_TS_GPR18),gr18
225
        ldi     @(\base,_TS_GPR19),gr19
226
        ldi     @(\base,_TS_GPR20),gr20
227
        ldi     @(\base,_TS_GPR21),gr21
228
        ldi     @(\base,_TS_GPR22),gr22
229
        ldi     @(\base,_TS_GPR23),gr23
230
        ldi     @(\base,_TS_GPR24),gr24
231
        ldi     @(\base,_TS_GPR25),gr25
232
        ldi     @(\base,_TS_GPR26),gr26
233
        ldi     @(\base,_TS_GPR27),gr27
234
        ldi     @(\base,_TS_GPR28),gr28
235
        ldi     @(\base,_TS_GPR29),gr29
236
        ldi     @(\base,_TS_GPR30),gr30
237
        ldi     @(\base,_TS_GPR31),gr31
238
#if _NGPR != 32
239
        ldi     @(\base,_TS_GPR32),gr32
240
        ldi     @(\base,_TS_GPR33),gr33
241
        ldi     @(\base,_TS_GPR34),gr34
242
        ldi     @(\base,_TS_GPR35),gr35
243
        ldi     @(\base,_TS_GPR36),gr36
244
        ldi     @(\base,_TS_GPR37),gr37
245
        ldi     @(\base,_TS_GPR38),gr38
246
        ldi     @(\base,_TS_GPR39),gr39
247
        ldi     @(\base,_TS_GPR40),gr40
248
        ldi     @(\base,_TS_GPR41),gr41
249
        ldi     @(\base,_TS_GPR42),gr42
250
        ldi     @(\base,_TS_GPR43),gr43
251
        ldi     @(\base,_TS_GPR44),gr44
252
        ldi     @(\base,_TS_GPR45),gr45
253
        ldi     @(\base,_TS_GPR46),gr46
254
        ldi     @(\base,_TS_GPR47),gr47
255
        ldi     @(\base,_TS_GPR48),gr48
256
        ldi     @(\base,_TS_GPR49),gr49
257
        ldi     @(\base,_TS_GPR50),gr50
258
        ldi     @(\base,_TS_GPR51),gr51
259
        ldi     @(\base,_TS_GPR52),gr52
260
        ldi     @(\base,_TS_GPR53),gr53
261
        ldi     @(\base,_TS_GPR54),gr54
262
        ldi     @(\base,_TS_GPR55),gr55
263
        ldi     @(\base,_TS_GPR56),gr56
264
        ldi     @(\base,_TS_GPR57),gr57
265
        ldi     @(\base,_TS_GPR58),gr58
266
        ldi     @(\base,_TS_GPR59),gr59
267
        ldi     @(\base,_TS_GPR60),gr60
268
        ldi     @(\base,_TS_GPR61),gr61
269
        ldi     @(\base,_TS_GPR62),gr62
270
        ldi     @(\base,_TS_GPR63),gr63
271
#endif
272
        ldi     @(\base,_TS_SP),gr1   // This has to be last - Stack pointer
273
        rett    #\retv
274
        .endm
275
 
276
#if defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
277
 
278
        .macro  exception_VSR
279
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
280
        subi    sp,24,sp
281
        sti     gr4,@(sp,0)
282
#else
283
        subi    sp,_TS_size,sp
284
        sti     gr4,@(sp,_TS_GPR4)
285
#endif
286
        addi    gr0,#((.-8)-_vectors)/16,gr4
287
        bra     _exception
288
        .endm
289
 
290
#if defined(CYGPKG_HAL_FRV_FRV400) && defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS)
291
        .macro  break_VSR
292
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
293
        subi    sp,24,sp
294
        sti     gr4,@(sp,0)
295
#else
296
        subi    sp,_TS_size,sp
297
        sti     gr4,@(sp,_TS_GPR4)
298
#endif
299
        addi    gr0,#((.-8)-_vectors)/16,gr4
300
        bra     _break
301
        .endm
302
#endif // CYGPKG_HAL_FRV_FRV400 && STUBS
303
 
304
        .macro  interrupt_VSR
305
        subi    sp,_TS_size,sp
306
        sti     gr4,@(sp,_TS_GPR4)
307
        addi    gr0,#((.-8)-_vectors)/16,gr4
308
        bra     _interrupt
309
        .endm
310
 
311
        .section ".rom_vectors","ax"
312
_vectors:
313
        call    reset_vector
314
        nop     // I hate fencepost stuff like this....
315
        nop     // (NEXT_INDEX_AFTER_THIS - 1) - (PREVIOUS_INDEX_FILLED)
316
        nop     // (LAST_INDEX_TO_FILL)        - (PREVIOUS_INDEX_FILLED)
317
        .rept   (CYGNUM_HAL_VECTOR_EXTERNAL_INTERRUPT_LEVEL_1-1)-0
318
        exception_VSR
319
        .endr
320
        .rept   (CYGNUM_HAL_VECTOR_EXTERNAL_INTERRUPT_LEVEL_15) - (CYGNUM_HAL_VECTOR_EXTERNAL_INTERRUPT_LEVEL_1-1)
321
        interrupt_VSR
322
        .endr
323
        .rept   (254) - CYGNUM_HAL_VECTOR_EXTERNAL_INTERRUPT_LEVEL_15
324
        exception_VSR
325
        .endr
326
#if defined(CYGPKG_HAL_FRV_FRV400) && defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS)
327
        break_VSR // in index 255
328
#else
329
        exception_VSR // another one
330
#endif // CYGPKG_HAL_FRV_FRV400 && STUBS
331
 
332
//
333
// Handle a break
334
//
335
// just like _exception, but it calls break_handler instead.
336
//
337
#if defined(CYGPKG_HAL_FRV_FRV400) && defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS)
338
        _break:
339
        // Save current register state
340
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
341
        sti     gr5,@(sp,4)
342
 
343
        // First, check BRR to see whether we're processing a break
344
        // instruction.  The stub uses this instruction to enter debug mode.
345
        movsg   brr,gr5
346
        andicc  gr5,#2,gr0,icc0
347
        beq     icc0,#0,1f
348
 
349
        // It is a break instruction.  Clear BRR to acknowledge it.
350
        movgs   gr0,brr
351
 
352
        // Set LR to the address of the instruction after the break.
353
        // Since software breaks are post-execution ones, BPCSR already
354
        // contains the right address.
355
        movsg   bpcsr,gr5
356
        movgs   gr5,lr
357
 
358
        // Restore the other registers and return as if the break were a
359
        // call.  Don't worry, the user of the break instruction knows
360
        // that LR will be clobbered!
361
        ldi     @(sp,0),gr4
362
        ldi     @(sp,4),gr5
363
        addi    sp,#24,sp
364
        ret
365
 
366
1:
367
        // We didn't come here from a break instruction so assume a
368
        // breakpoint or watchpoint has been triggered.  Since the
369
        // interrupt and exception handlers save their registers on the
370
        // application stack, there's a chance that these handlers could
371
        // trigger watchpoints accidentally.  We should just ignore
372
        // the watchpoint when that happens.
373
 
374
        // Use the previous value of SPR:ET to decide whether the break
375
        // was triggered by stub or user code.  The stub runs with traps
376
        // disabled, while any user code that disables traps will not be
377
        // debuggable.
378
        movsg   bpsr,gr5
379
        andicc  gr5,#1,gr0,icc0
380
        bne     icc0,#2,1f
381
 
382
        // Hmm, it looks like the GDB stub has triggered an old watchpoint.
383
        // Acknowledge it by clearing brr and return as if nothing had
384
        // happened.
385
        movgs   gr0,brr
386
        ldi     @(sp,0),gr4
387
        ldi     @(sp,4),gr5
388
        addi    sp,#24,sp
389
        rett    #1
390
1:
391
        sti     gr6,@(sp,8)
392
        sti     gr16,@(sp,12)
393
        movsg   lr,gr5
394
        sti     gr5,@(sp,16)
395
        movsg   ccr,gr5
396
        sti     gr5,@(sp,20)
397
        // Set the global offset register (gr16)
398
        call    .Lbrk
399
.Lbrk:  movsg   lr,gr16
400
        sethi   #gprelhi(.Lbrk),gr5
401
        setlo   #gprello(.Lbrk),gr5
402
        sub     gr16,gr5,gr16
403
        mov     sp,gr6                  // Original stack pointer
404
        lda     __GDB_stack,gr5         // already on GDB stack?
405
        cmp     sp,gr5,icc0
406
        bhi     icc0,0,10f              // no - need to switch
407
        lda     __GDB_stack_base,gr5
408
        cmp     sp,gr5,icc0
409
        bhi     icc0,0,11f
410
10:     lda     __GDB_stack,sp          // already on GDB stack?
411
11:
412
        subi    sp,_TS_size,sp          // Space for scratch saves
413
        save_GDB_exception_regs sp,gr6
414
        save_state sp
415
#else
416
        save_exception_regs sp
417
        save_state sp
418
#endif
419
        LED     0x0FFF
420
        add     sp,gr0,gr8
421
        call    break_handler
422
        restore_state sp,bpcsr,1
423
#endif // CYGPKG_HAL_FRV_FRV400 && STUBS
424
 
425
//
426
// Handle an exception
427
//
428
_exception:
429
        // Save current register state
430
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
431
        sti     gr5,@(sp,4)
432
        sti     gr6,@(sp,8)
433
        sti     gr16,@(sp,12)
434
        movsg   lr,gr5
435
        sti     gr5,@(sp,16)
436
        movsg   ccr,gr5
437
        sti     gr5,@(sp,20)
438
        // Set the global offset register (gr16)
439
        call    .Lexp
440
.Lexp:  movsg   lr,gr16
441
        sethi   #gprelhi(.Lexp),gr5
442
        setlo   #gprello(.Lexp),gr5
443
        sub     gr16,gr5,gr16
444
        mov     sp,gr6                  // Original stack pointer
445
        lda     __GDB_stack,gr5         // already on GDB stack?
446
        cmp     sp,gr5,icc0
447
        bhi     icc0,0,10f              // no - need to switch
448
        lda     __GDB_stack_base,gr5
449
        cmp     sp,gr5,icc0
450
        bhi     icc0,0,11f
451
10:     lda     __GDB_stack,sp          // already on GDB stack?
452
11:
453
        subi    sp,_TS_size,sp          // Space for scratch saves
454
        save_GDB_exception_regs sp,gr6
455
        save_state sp
456
#else
457
        save_exception_regs sp
458
        save_state sp
459
#endif
460
        LED     0x0FFF
461
        add     sp,gr0,gr8
462
        call    exception_handler
463
        bra     _exception_return
464
 
465
//
466
// Handle an interrupt
467
//   Separated from exception handling to support eCos multi-level
468
//  (ISR/DSR) interrupt structure.
469
//
470
_interrupt:
471
        save_exception_regs sp
472
        save_state sp
473
 
474
        mov     gr4,gr30                // save vector #
475
 
476
        // Set the global offset register (gr16)
477
        call    .Lexp1
478
.Lexp1: movsg   lr,gr16
479
        sethi   #gprelhi(.Lexp1),gr5
480
        setlo   #gprello(.Lexp1),gr5
481
        sub     gr16,gr5,gr16
482
        LED     0x0700
483
 
484
        lda     hal_vsr_table,gr8
485
        slli    gr30,#2,gr4             // Vector in GR30
486
        ld      @(gr8,gr4),gr8          // Handler (VSR) defined?
487
        cmpi    gr8,0,icc0
488
        beq     icc0,0,10f              // No - use default
489
        LED     0x0702
490
        callil  @(gr8,0)                // Yes - call it
491
        bra     _exception_return
492
 
493
//
494
// Default interrupt processing
495
//
496
10:
497
#if defined(CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT) \
498
    || defined(CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT)
499
        // If we are supporting Ctrl-C interrupts from GDB, we must squirrel
500
        // away a pointer to the save interrupt state here so that we can
501
        // plant a breakpoint at some later time.
502
 
503
       .extern  hal_saved_interrupt_state
504
        lda     hal_saved_interrupt_state,gr5
505
        sti     sp,@(gr5,0)
506
#endif
507
        lda     hal_interrupt_data,gr5
508
        lda     hal_interrupt_handlers,gr6
509
        mov     gr30,gr8                // Interrupt vector #
510
        slli    gr30,#2,gr4
511
        ld      @(gr5,gr4),gr9         // data pointer
512
        ld      @(gr6,gr4),gr6         // function
513
        callil  @(gr6,0)
514
        LED     0x0701
515
        // FIXME - no DSR processing
516
 
517
//
518
// Return from an exception/interrupt
519
//
520
_exception_return:
521
        LED     0x0000
522
        restore_state sp,pcsr,0
523
 
524
        .global reset_vector
525
reset_vector:
526
 
527
        // Make sure the CPU is in the proper mode (system), interrupts disabled
528
        movsg   psr,gr4
529
        li      ~(_PSR_ET|_PSR_PS|_PSR_PIVL_MASK),gr5
530
        and     gr4,gr5,gr4
531
        li      (_PSR_S|_PSR_ET|(0x0F<<_PSR_PIVL_SHIFT)),gr5
532
        or      gr4,gr5,gr4
533
        movgs   gr4,psr
534
 
535
        // Make sure caches, MMUs are disabled
536
        movsg   hsr0,gr4
537
        li      ~(_HSR0_ICE|_HSR0_DCE|_HSR0_IMMU|_HSR0_DMMU),gr5
538
        and     gr4,gr5,gr4
539
        movgs   gr4,hsr0
540
 
541
        // Initialize hardware platform - this macro only contains
542
        // code which must be run before any "normal" accesses are
543
        // allowed, such as enabling DRAM controllers, etc.
544
        platform_init
545
 
546
#if defined(CYG_HAL_STARTUP_ROMRAM)
547
// Relocate code from ROM to static RAM
548
        call    10f             // Actual address loaded at
549
5:      .long   _vectors
550
        .long   20f
551
        .long   5b-_vectors
552
        .long   __rom_data_end
553
10:     movsg   lr,gr4
554
        ldi     @(gr4,0),gr6
555
        ldi     @(gr4,4),gr10
556
        ldi     @(gr4,8),gr7
557
        ldi     @(gr4,12),gr8
558
        sub     gr4,gr7,gr4     // GR4 - absolute base address
559
        subi    gr4,#4,gr4
560
        subi    gr6,#4,gr6
561
        setlos  #4,gr7
562
15:     ldu     @(gr4,gr7),gr5
563
        stu     gr5,@(gr6,gr7)
564
        cmp     gr6,gr8,icc0
565
        bne     icc0,0,15b
566
        jmpl    @(gr10,gr0)
567
20:     nop
568
#endif
569
 
570
        // Fall through to normal program startup
571
 
572
#endif  //  CYG_HAL_STARTUP_ROM
573
 
574
        .text
575
 
576
        .global _start
577
_start:
578
        // Set the global offset register (gr16)
579
        call    .Lcall
580
    .Lcall:
581
        movsg   lr,gr4
582
        sethi   #gprelhi(.Lcall),gr5
583
        setlo   #gprello(.Lcall),gr5
584
        sub     gr4,gr5,gr16
585
 
586
        LED     0x0000
587
 
588
#if defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
589
        // Set up trap base register
590
        lda     _vectors,gr4
591
        movgs   gr4,tbr
592
 
593
        LED     0x0001
594
 
595
        // Relocate [copy] data from ROM to RAM
596
        lda     __rom_data_start,gr4
597
        lda     __ram_data_start,gr5
598
        lda     __ram_data_end,gr6
599
        cmp     gr5,gr6,icc0
600
        beq     icc0,0,2f
601
        setlos  #4,gr7
602
        sub     gr4,gr7,gr4
603
        sub     gr5,gr7,gr5
604
1:      ldu     @(gr4,gr7),gr8
605
        stu     gr8,@(gr5,gr7)
606
        cmp     gr5,gr6,icc0
607
        bne     icc0,0,1b
608
2:
609
#endif
610
 
611
        // Set up stack, initial environment
612
        lda     __startup_stack,gr4
613
        mov     gr4,sp
614
 
615
        // Enable caches early, based on configuration
616
#ifdef CYGSEM_HAL_ENABLE_ICACHE_ON_STARTUP
617
        icei    @(gr4,gr0),1    // purges current contents
618
        movsg   hsr0,gr4
619
        li      _HSR0_ICE,gr5   // enable instruction cache
620
        or      gr4,gr5,gr4
621
        movgs   gr4,hsr0
622
#endif
623
#ifdef CYGSEM_HAL_ENABLE_DCACHE_ON_STARTUP
624
        dcef    @(gr4,gr0),1    // flush contents to memory
625
        dcei    @(gr4,gr0),1    // purges current contents
626
        movsg   hsr0,gr4
627
        li      _HSR0_DCE,gr5   // enable data cache
628
        or      gr4,gr5,gr4
629
        movgs   gr4,hsr0
630
#endif
631
 
632
        LED     0x0002
633
 
634
        // Clear BSS space
635
        lda     __bss_start,gr4
636
        lda     __bss_end,gr5
637
1:      sti     gr0,@(gr4,0)
638
        addi    gr4,#4,gr4
639
        cmp     gr4,gr5,icc0
640
        bne     icc0,0,1b
641
 
642
        // Initialize interrupt handlers, etc
643
        li      CYGNUM_HAL_ISR_COUNT,gr4
644
        lda     hal_interrupt_handlers,gr5
645
        subi    gr5,4,gr5
646
        lda     hal_default_isr,gr6
647
        lda     hal_vsr_table,gr8
648
        subi    gr8,4,gr8
649
        // Note: this should be controlled by a CDL option
650
        lda     _handle_interrupt,gr9
651
        setlos  #4,gr7
652
10:     stu     gr6,@(gr5,gr7)
653
        stu     gr9,@(gr8,gr7)
654
        subi    gr4,1,gr4
655
        cmp     gr4,gr0,icc0
656
        bne     icc0,0,10b
657
 
658
        LED     0x0003
659
 
660
        // Initialize hardware
661
        call    hal_hardware_init
662
 
663
        LED     0x0004
664
 
665
        // Run any C++ initializations
666
        call    cyg_hal_invoke_constructors
667
 
668
        LED     0x0005
669
 
670
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
671
        call    initialize_stub
672
#endif
673
 
674
        LED     0x0006
675
 
676
        // Start eCos application
677
        call    cyg_start
678
 
679
0:      LED     0x0999          // Should never get here
680
        bra     0b
681
 
682
//
683
// Interrupt processing
684
//
685
_handle_interrupt:
686
        mov     sp,gr31         // Save pointer to state frame
687
        movsg   lr,gr29
688
 
689
        // Set the global offset register (gr16)
690
        call    10f
691
10:     movsg   lr,gr4
692
        sethi   #gprelhi(10b),gr5
693
        setlo   #gprello(10b),gr5
694
        sub     gr4,gr5,gr16
695
 
696
#ifdef CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK
697
        // Switch to interrupt stack
698
#endif
699
        // The entire CPU state is now stashed on the stack,
700
        // increment the scheduler lock and handle the interrupt
701
 
702
#ifdef CYGFUN_HAL_COMMON_KERNEL_SUPPORT
703
        .extern cyg_scheduler_sched_lock
704
        lda     cyg_scheduler_sched_lock,gr8
705
        ldi     @(gr8,0),gr9
706
        addi    gr9,1,gr9
707
        sti     gr9,@(gr8,0)
708
#endif
709
 
710
#if defined(CYGPKG_KERNEL_INSTRUMENT) && \
711
    defined(CYGDBG_KERNEL_INSTRUMENT_INTR)
712
        setlos  #RAISE_INTR,gr8         // arg0 = type = INTR,RAISE
713
        ldi     @(gr31,_TS_VECTOR),gr9  // arg1 = vector
714
        mov     gr0,gr10                // arg2 = 0
715
        call    cyg_instrument          // call instrument function
716
#endif
717
 
718
#if defined(CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT) \
719
    || defined(CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT)
720
        // If we are supporting Ctrl-C interrupts from GDB, we must squirrel
721
        // away a pointer to the save interrupt state here so that we can
722
        // plant a breakpoint at some later time.
723
 
724
       .extern  hal_saved_interrupt_state
725
        lda     hal_saved_interrupt_state,gr5
726
        sti     sp,@(gr5,0)
727
#endif
728
        lda     hal_interrupt_data,gr5
729
        lda     hal_interrupt_handlers,gr7
730
        mov     gr30,gr8                // Interrupt vector #
731
        slli    gr30,#2,gr4
732
        ld      @(gr5,gr4),gr9         // data pointer
733
        ld      @(gr7,gr4),gr6         // function
734
        callil  @(gr6,0)
735
        LED     0x0701
736
 
737
#ifdef CYGFUN_HAL_COMMON_KERNEL_SUPPORT
738
        // The return value from the handler (in gr8) will indicate whether a
739
        // DSR is to be posted. Pass this together with a pointer to the
740
        // interrupt object we have just used to the interrupt tidy up routine.
741
 
742
        lda     hal_interrupt_objects,gr5
743
        slli    gr30,#2,gr4
744
        ld      @(gr5,gr4),gr9
745
        mov     gr31,gr10               // register frame
746
 
747
        call    interrupt_end           // post any bottom layer handler
748
                                        // threads and call scheduler
749
#endif
750
        movgs   gr29,lr
751
        ret
752
 
753
#ifdef CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK
754
// Execute pending DSRs the interrupt stack
755
// Note: this can only be called from code running on a thread stack
756
        .globl  hal_interrupt_stack_call_pending_DSRs
757
hal_interrupt_stack_call_pending_DSRs:
758
        subi    sp,32,sp                // Save important registers
759
        movsg   lr,gr8
760
        sti     gr8,@(sp,0)
761
        // Turn on interrupts, switch to interrupt stack
762
        call    cyg_interrupt_call_pending_DSRs
763
        // Turn off interrupts, switch back to thread stack
764
        ldi     @(sp,0),gr8
765
        movgs   gr8,lr
766
        addi    sp,32,sp
767
        ret
768
#endif // CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK
769
 
770
//
771
// Restore interrupt state
772
//   GR8 has state
773
//
774
        .global hal_restore_interrupts
775
hal_restore_interrupts:
776
        movsg   psr,gr4
777
        setlos  _PSR_PIVL_MASK,gr5
778
        and     gr8,gr5,gr8             // Save level being restored
779
        not     gr5,gr5
780
        and     gr4,gr5,gr4             // Clear out current level
781
        or      gr8,gr4,gr4             // Insert new level
782
        movgs   gr4,psr
783
        ret
784
 
785
        .global hal_query_interrupts
786
hal_query_interrupts:
787
        movsg   psr,gr8
788
        setlos  _PSR_PIVL_MASK,gr5
789
        and     gr8,gr5,gr8
790
        ret
791
 
792
//
793
// "Vectors" - fixed location data items
794
//    This section contains any data which might be shared between
795
// an eCos application and any other environment, e.g. the debug
796
// ROM.
797
//
798
        .section ".fixed_vectors"
799
 
800
// Space for the virtual vectors
801
        .balign 16
802
// Vectors used to communicate between eCos and ROM environments
803
        .globl  hal_virtual_vector_table
804
hal_virtual_vector_table:
805
        .rept   CYGNUM_CALL_IF_TABLE_SIZE
806
        .long   0
807
        .endr
808
 
809
        .globl  hal_vsr_table
810
hal_vsr_table:
811
        .rept   CYGNUM_HAL_ISR_COUNT            // exceptions & interrupts
812
        .long   0
813
        .endr
814
 
815
        .section ".data"
816
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
817
        .balign 16
818
__GDB_stack_base:
819
        .rept CYGNUM_HAL_COMMON_INTERRUPTS_STACK_SIZE // rather than 1k
820
        .byte 0
821
        .endr
822
__GDB_stack:
823
#endif
824
        .balign 16
825
__startup_stack_base:
826
#ifdef CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK
827
        .rept 512
828
#else
829
        .rept CYGNUM_HAL_COMMON_INTERRUPTS_STACK_SIZE
830
#endif
831
        .byte 0
832
        .endr
833
        .balign 16
834
        .global  __startup_stack
835
__startup_stack:
836
 
837
        .globl  hal_interrupt_handlers
838
hal_interrupt_handlers:
839
        .rept   CYGNUM_HAL_ISR_COUNT
840
        .long   0
841
        .endr
842
 
843
        .globl  hal_interrupt_data
844
hal_interrupt_data:
845
        .rept   CYGNUM_HAL_ISR_COUNT
846
        .long   0
847
        .endr
848
 
849
        .globl  hal_interrupt_objects
850
hal_interrupt_objects:
851
        .rept   CYGNUM_HAL_ISR_COUNT
852
        .long   0
853
        .endr

powered by: WebSVN 2.1.0

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