~ubuntu-branches/ubuntu/raring/codeblocks/raring-proposed

« back to all changes in this revision

Viewing changes to src/plugins/scriptedwizard/resources/arm/files/olimex-lpc213x/src/vectors.S

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-08-09 04:38:38 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20100809043838-a59ygguym4eg0jgw
Tags: 10.05-0ubuntu1
* New upstream release. Closes (LP: #322350)
 - Switch to dpkg-source 3.0 (quilt) format
 - Remove unneeded README.source
 - Add debian/get-source-orig script that removes all
   Windows prebuilt binaries
* Bump Standards-Version to 3.9.1
 - Stop shipping *.la files
* debian/control
 - Add cdbs package as Build-Depend
 - Add libbz2-dev and zlib1g-dev packages as
   Build-Depends (needed by libhelp_plugin.so)
 - Remove dpatch package of Build-Depends
 - Add codeblocks-contrib-debug package
 - Split architecture-independent files of codeblocks
   package in codeblocks-common package
* debian/rules
 - Switch to CDBS rules system
 - Add parallel build support
 - Add a call to debian/get-source-orig script
 - Use lzma compression (saves 23,5 MB of free space)
* debian/patches
 - Refresh 01_codeblocks_plugin_path
 - Add 02_no_Makefiles_in_debian_dir to remove any link
   in codeblocks build system to deleted Makefiles of debian directory
 - Drop 02_ftbfs_gcc44 and 03_ftbfs_glib221 (merged in upstream)
* debian/watch
 - Update to use the new host (berlios.de)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// #========================================================================
 
2
// #
 
3
// # vectors.S
 
4
// #
 
5
// # ARM exception vectors (Olimex LPC-P2138)
 
6
// #
 
7
// #
 
8
// # Copyright HighTec EDV-Systeme GmbH 1982-2007
 
9
// #
 
10
// #========================================================================
 
11
 
 
12
 
 
13
#define CPSR_IRQ_DISABLE        0x80    /* IRQ disabled when = 1 */
 
14
#define CPSR_FIQ_DISABLE        0x40    /* FIQ disabled when = 1 */
 
15
#define CPSR_THUMB_ENABLE       0x20    /* Thumb mode   when = 1 */
 
16
#define CPSR_MODE32_ENABLE      0x10    /* 32 bit mode  when = 1 */
 
17
 
 
18
#define CPSR_MODE_BITS          0x1F
 
19
#define CPSR_USER_MODE          0x10
 
20
#define CPSR_FIQ_MODE           0x11
 
21
#define CPSR_IRQ_MODE           0x12
 
22
#define CPSR_SVC_MODE           0x13
 
23
#define CPSR_ABORT_MODE         0x17
 
24
#define CPSR_UNDEF_MODE         0x1B
 
25
#define CPSR_SYSTEM_MODE        0x1F
 
26
 
 
27
#define SWI_Location            0x28    /* HiMo: address of SWI handler */
 
28
#define IRQ_Location            0x38    /* HiMo: address of IRQ handler */
 
29
 
 
30
//;
 
31
//; # Platform specific definition for LPC213x
 
32
//;
 
33
 
 
34
/*-----------------------*/
 
35
/* PLL Control Registers */
 
36
/*-----------------------*/
 
37
#define SCB_BASE        0xE01FC000
 
38
#define PLL_BASE        (SCB_BASE + 0x080)
 
39
 
 
40
/* PLL Control Register */
 
41
#define PLLCON          (SCB_BASE + 0x80)
 
42
/* PLL Configuration Register */
 
43
#define PLLCFG          (SCB_BASE + 0x84)
 
44
/* PLL Status Register */
 
45
#define PLLSTAT         (SCB_BASE + 0x88)
 
46
/* PLL Feed Register */
 
47
#define PLLFEED         (SCB_BASE + 0x8C)
 
48
 
 
49
#define PLLCON_PLLE     0x01    /* PLL Enable */
 
50
#define PLLCON_PLLC     0x02    /* PLL Connect */
 
51
 
 
52
#define PLLCFG_VAL      0x23    /* P=2,M=4 */
 
53
 
 
54
#define PLL_PLLC        0x100   /* Status of PLL Enable */
 
55
#define PLL_PLLE        0x200   /* Status of PLL Connect */
 
56
#define PLL_PLOCK       0x400   /* PLL Lock Status */
 
57
 
 
58
#define PLLFEED_PW0     0xAA
 
59
#define PLLFEED_PW1     0x55
 
60
 
 
61
/* Memory Mapping Control Register */
 
62
#define MEMMAP          (SCB_BASE + 0x40)
 
63
 
 
64
#define MEMMAP_BOOT     0x00    /* vectors mapped to Boot Block */
 
65
#define MEMMAP_FLASH    0x01    /* vectors at 0 (internal Flash) */
 
66
#define MEMMAP_ISRAM    0x02    /* vectors mapped to internal SRAM */
 
67
 
 
68
#define ISRAM_START     0x40000000
 
69
 
 
70
/* APB Divider Register */
 
71
#define APBDIV          (SCB_BASE + 0x100)
 
72
 
 
73
#define APBDIV_4        0       /* peripherals clock == CPU/4 clock */
 
74
#define APBDIV_2        2       /* peripherals clock == CPU/2 clock */
 
75
#define APBDIV_1        1       /* peripherals clock == CPU clock */
 
76
 
 
77
 
 
78
/*-----------------------------------------*/
 
79
/* Vectored Interrupt Controller Registers */
 
80
/*-----------------------------------------*/
 
81
#define VIC_BASE        0xFFFFF000
 
82
 
 
83
/* Interrupt Enable Clear Register */
 
84
#define VICIEC          (VIC_BASE + 0x14)
 
85
/* IRQ Vector Register */
 
86
#define VICVADDR        (VIC_BASE + 0x30)
 
87
 
 
88
#define ISR_VALID_MASK  0x003FFFFF
 
89
 
 
90
 
 
91
//; #==========================================================================
 
92
//; #  Hardware exception vectors.
 
93
//; #  The vector table will be copied to location 0x0000 at startup time.
 
94
//;
 
95
        .code   32
 
96
        .section ".vectors","ax"
 
97
        .global __exception_handlers
 
98
 
 
99
//; # LPC2xxx boot code looks for a valid vector table at start of flash.
 
100
//; # A vector table is valid if the word sum over the 8 vector entries is zero.
 
101
//; # The unused word at location 0x14 is used for adjusting the checksum.
 
102
__exception_handlers:
 
103
__vector_table_start:
 
104
        ldr     pc,.reset_vector
 
105
        ldr     pc,.undefined_instruction
 
106
        ldr     pc,.software_interrupt
 
107
        ldr     pc,.abort_prefetch
 
108
        ldr     pc,.abort_data
 
109
        .word   0xB8A06F58      //; ==> checksum = 0
 
110
        ldr     pc,.IRQ
 
111
        ldr     pc,.FIQ
 
112
 
 
113
//; # The layout of these pointers should match the vector table above since
 
114
//; # they are copied in pairs.
 
115
        .global vectors
 
116
vectors:
 
117
.reset_vector:
 
118
        .word   reset_vector
 
119
.undefined_instruction:
 
120
        .word   undefined_instruction
 
121
.software_interrupt:
 
122
        .word   software_interrupt
 
123
.abort_prefetch:
 
124
        .word   abort_prefetch
 
125
.abort_data:
 
126
        .word   abort_data
 
127
        .word   0
 
128
.IRQ:
 
129
        .word   IRQ
 
130
.FIQ:
 
131
        .word   FIQ
 
132
 
 
133
__vector_table_end:
 
134
 
 
135
        .text
 
136
//; begin of startup code
 
137
start:
 
138
 
 
139
        .global reset_vector
 
140
        .type   reset_vector,function
 
141
reset_vector:
 
142
 
 
143
//; #   PLATFORM_SETUP1         //; # Early stage platform initialization
 
144
 
 
145
        ldr     r0,=SCB_BASE
 
146
        ldr     r1,[r0,#(PLLSTAT-SCB_BASE)]
 
147
        ldr     r2,=(PLL_PLOCK + PLL_PLLE + PLL_PLLC)
 
148
        and     r1,r1,r2
 
149
        cmp     r1,#(PLL_PLOCK + PLL_PLLE + PLL_PLLC)
 
150
        beq     10f                             /* clock is already running */
 
151
 
 
152
        ldr     r1,=PLLCFG_VAL
 
153
        str     r1,[r0,#(PLLCFG-SCB_BASE)]
 
154
 
 
155
        ldr     r1,=PLLCON_PLLE                 /* PLLCON.0 = 0x01 -> PLL enabled */
 
156
        str     r1,[r0,#(PLLCON-SCB_BASE)]
 
157
 
 
158
        ldr     r1,=PLLFEED_PW0                 /* write feed sequence */
 
159
        str     r1,[r0,#(PLLFEED-SCB_BASE)]
 
160
        ldr     r1,=PLLFEED_PW1
 
161
        str     r1,[r0,#(PLLFEED-SCB_BASE)]
 
162
02:
 
163
        ldr     r1,[r0,#(PLLSTAT-SCB_BASE)]
 
164
        ands    r1,r1,#PLL_PLOCK
 
165
        beq     02b                             /* wait until oscillator is stabilized */
 
166
 
 
167
        ldr     r1,=(PLLCON_PLLE+PLLCON_PLLC)   /* PLLCON.0 = 1, PLLCON.1 = 1 */
 
168
        str     r1,[r0,#(PLLCON-SCB_BASE)]
 
169
 
 
170
        ldr     r1,=PLLFEED_PW0                 /* write feed sequence */
 
171
        str     r1,[r0,#(PLLFEED-SCB_BASE)]
 
172
        ldr     r1,=PLLFEED_PW1
 
173
        str     r1,[r0,#(PLLFEED-SCB_BASE)]
 
174
 
 
175
04:
 
176
        ldr     r1,[r0,#(PLLSTAT-SCB_BASE)]
 
177
        ands    r1,r1,#PLL_PLOCK
 
178
        beq     04b                             /* wait until PLL is stabilized */
 
179
 
 
180
10:
 
181
        mov     r1,#APBDIV_1                    /* peripherals clock == CPU clock */
 
182
        str     r1,[r0,#(APBDIV-SCB_BASE)]
 
183
 
 
184
warm_reset:
 
185
        ldr     r1,=VICIEC
 
186
        ldr     r0,=ISR_VALID_MASK              /* disable all interrupts */
 
187
        str     r0,[r1]
 
188
 
 
189
//
 
190
//; # copy the vector table (__vector_table_start .. __vector_table_end) to internal SRAM
 
191
//
 
192
#ifndef USE_HIMO
 
193
//; #  HiMo needs its own exception handlers --> don't overwrite these!!
 
194
        mov     r8,#ISRAM_START
 
195
        ldr     r9,=__exception_handlers
 
196
        ldmia   r9!,{r0-r7}
 
197
        stmia   r8!,{r0-r7}
 
198
        ldmia   r9!,{r0-r7}
 
199
        stmia   r8!,{r0-r7}
 
200
#endif /* USE_HIMO */
 
201
 
 
202
//; then remap vectors to point to internal SRAM
 
203
        ldr     r0,=SCB_BASE
 
204
        mov     r1,#MEMMAP_ISRAM                /* map vectors to internal SRAM */
 
205
        str     r1,[r0,#(MEMMAP-SCB_BASE)]
 
206
 
 
207
//      ; Relocate [copy] data from ROM to RAM
 
208
        ldr     r0,=__rom_data_start
 
209
        ldr     r1,=__ram_data_start
 
210
        ldr     r2,=__ram_data_end
 
211
1:
 
212
        cmp     r1,r2           //; #  while (r1 < r2)
 
213
        ldrcc   r3,[r0],#4      //; #  {
 
214
        strcc   r3,[r1],#4      //; #    *r1++ = *r0++;
 
215
        bcc     1b              //; #  }
 
216
 
 
217
//      ; clear BSS
 
218
        ldr     r1,=__bss_start
 
219
        ldr     r2,=__bss_end
 
220
        mov     r0,#0
 
221
1:
 
222
        cmp     r1,r2           //; # while (r1 < r2)
 
223
        strcc   r0,[r1],#4      //; #   *r1++ = 0;
 
224
        bcc     1b
 
225
 
 
226
#if defined(USE_IRQ) && defined(USE_HIMO)
 
227
//; replace IRQ handler by our own handler
 
228
        ldr     r1,=IRQ_Location
 
229
        ldr     r0,=HIMO_IRQ_Address
 
230
        ldr     r2,[r1]
 
231
        str     r2,[r0]
 
232
        ldr     r2,=IRQ
 
233
        str     r2,[r1]
 
234
#endif /* USE_IRQ && USE_HIMO */
 
235
 
 
236
//      ; # initialize interrupt/exception environments
 
237
        ldr     sp,=__startup_stack
 
238
        mov     r0,#(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_IRQ_MODE)
 
239
        msr     cpsr,r0
 
240
        ldr     sp,=__interrupt_stack
 
241
        mov     r0,#(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_FIQ_MODE)
 
242
        msr     cpsr,r0
 
243
        ldr     sp,=__FIQ_exception_stack
 
244
        mov     r0,#(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_UNDEF_MODE)
 
245
        msr     cpsr,r0
 
246
        ldr     sp,=__exception_stack
 
247
        mov     r0,#(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_ABORT_MODE)
 
248
        msr     cpsr,r0
 
249
        ldr     sp,=__exception_stack
 
250
 
 
251
//      ; # initialize CPSR (machine state register)
 
252
        mov     r0,#(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_SVC_MODE)
 
253
        msr     cpsr,r0
 
254
 
 
255
//      ; # Note: some functions in LIBGCC1 will cause a "restore from SPSR"!!
 
256
        msr     spsr,r0
 
257
 
 
258
#ifdef USE_IRQ
 
259
//; # initialize interrupt tables
 
260
        bl      IrqInit
 
261
#endif /* USE_IRQ */
 
262
 
 
263
 
 
264
#if 1
 
265
//; # do low level PXROS initialization if we are in a PXROS environment
 
266
        ldr     r0,=PxPrepareInit
 
267
        cmp     r0,#0
 
268
        movne   lr,pc
 
269
        movne   pc,r0
 
270
#endif
 
271
 
 
272
 
 
273
//      ; # switch to user mode, evtl. IRQs enabled
 
274
#ifdef USE_IRQ
 
275
        mov     r0,#(CPSR_FIQ_DISABLE|CPSR_USER_MODE)
 
276
#else
 
277
        mov     r0,#(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_USER_MODE)
 
278
#endif /* USE_IRQ */
 
279
        msr     cpsr,r0
 
280
        ldr     sp,=__user_stack
 
281
 
 
282
#ifndef __NO_CTOR_DTOR_SUPPORT__
 
283
#ifdef __USES_INITFINI__
 
284
        /* Some arm/elf targets use the .init and .fini sections
 
285
           to create constructors and destructors, and for these
 
286
           targets we need to call the _init function and arrange
 
287
           for _fini to be called at program exit.  */
 
288
        ldr     r0,=_fini
 
289
        bl      atexit
 
290
        bl      _init
 
291
#endif /* __USES_INITFINI__ */
 
292
#endif /* __NO_CTOR_DTOR_SUPPORT__ */
 
293
 
 
294
        mov     a1,#0           //; # set argc to 0
 
295
        mov     a2,#0           //; # and argv to NUL
 
296
        bl      main
 
297
#ifdef USE_HIMO
 
298
#ifdef USE_IRQ
 
299
        bl      IrqInit         //; # stop interrupts
 
300
        bl      RestoreHIMO     //; # restore HIMO environment
 
301
#endif /* USE_IRQ */
 
302
#endif /* USE_HIMO */
 
303
 
 
304
#ifdef __NO_CTOR_DTOR_SUPPORT__
 
305
        bl      _exit
 
306
#else
 
307
        mov     a1,#0
 
308
        bl      exit            //; # exit(0)
 
309
#endif /* __NO_CTOR_DTOR_SUPPORT__ */
 
310
 
 
311
 
 
312
 
 
313
//;
 
314
//; # Exception handlers
 
315
//; # Assumption: get here from a Supervisor context [mode]
 
316
//;
 
317
        .code   32
 
318
undefined_instruction:
 
319
        b       undefined_instruction
 
320
 
 
321
        .code   32
 
322
software_interrupt:
 
323
        b       software_interrupt
 
324
 
 
325
        .code   32
 
326
abort_prefetch:
 
327
        b       abort_prefetch
 
328
 
 
329
        .code   32
 
330
abort_data:
 
331
        b       abort_data
 
332
 
 
333
 
 
334
        .code   32
 
335
FIQ:
 
336
        b       FIQ
 
337
 
 
338
 
 
339
 
 
340
IRQ:
 
341
#ifdef USE_IRQ
 
342
        sub     lr,lr,#4                //; adjust return address before saving it
 
343
        str     lr,[sp,#-4]!
 
344
        mrs     lr,spsr                 //; and status bits
 
345
        stmfd   sp!,{r0-r3,r12,lr}      //; save APCS working register and SPSR
 
346
 
 
347
 
 
348
        ldr     r0,=VIC_BASE
 
349
        ldr     r12,[r0,#(VICVADDR-VIC_BASE)]   //; load the vector routine
 
350
 
 
351
//      ; switch to another mode (to avoid  problem with C language handler code)
 
352
//      ; SVC mode if interrupted service else SYSTEM mode (interrupted task)
 
353
        mrs     r0,cpsr                 //; read the current status register
 
354
        bic     r0,r0,#CPSR_MODE_BITS   //; clear the mode bits
 
355
        and     lr,lr,#CPSR_MODE_BITS   //; extract the mode bits of interrupted state
 
356
        cmp     lr,#CPSR_SVC_MODE
 
357
        orreq   r0,r0,#CPSR_SVC_MODE    //; switch to SVC mode
 
358
        orrne   r0,r0,#CPSR_SYSTEM_MODE //; switch to SYSTEM mode
 
359
        msr     cpsr_cf,r0
 
360
 
 
361
        stmfd   sp!,{lr}                //; save original lr (lr_svc|lr)
 
362
        adr     lr,Back_From_Handler    //; set the return address
 
363
 
 
364
//      ; now read-modify-write the CPSR to enable interrupts
 
365
        mrs     r0,cpsr                 //; read the status register
 
366
        bic     r0,r0,#CPSR_IRQ_DISABLE //; clear the IRQ disable bit
 
367
        msr     cpsr_cf,r0              //; reenable interrupts
 
368
 
 
369
//      ; jump to the correct handler
 
370
        movs    r12,r12
 
371
        movne   pc,r12
 
372
 
 
373
 
 
374
Back_From_Handler:
 
375
//      ; now read-modify-write the CPSR to disable interrupts
 
376
        mrs     r0,cpsr                 //; read the status register
 
377
        orr     r0,r0,#CPSR_IRQ_DISABLE //; set the IRQ disable bit
 
378
        msr     cpsr_cf,r0              //; write it back to disable interrupts
 
379
 
 
380
        ldmfd   sp!,{lr}                //; restore original lr (lr_svc|lr)
 
381
//      ; and switch back to IRQ mode
 
382
        mrs     r12,cpsr                //; read the status register
 
383
        bic     r12,r12,#CPSR_MODE_BITS //; clear the mode bits
 
384
        orr     r12,r12,#CPSR_IRQ_MODE  //; switch to IRQ mode
 
385
        msr     cpsr_cf,r12             //; write it back
 
386
 
 
387
        ldr     r1,=VIC_BASE            //; signal end of interrupt to VIC
 
388
        str     r1,[r1,#(VICVADDR-VIC_BASE)]
 
389
 
 
390
        ldmfd   sp!,{r0-r3,r12,lr}      //; restore APCS working register and SPSR
 
391
        msr     spsr_cf,lr
 
392
        ldmfd   sp!,{pc}^               //; and return from interrupt and restore CPSR
 
393
#else
 
394
        b       IRQ
 
395
#endif /* USE_IRQ */
 
396
 
 
397
 
 
398
 
 
399
#if defined(USE_IRQ) && defined(USE_HIMO)
 
400
//; restore HIMO's original exception handler environment
 
401
 
 
402
        .global RestoreHIMO
 
403
RestoreHIMO:
 
404
        ldr     r0,=HIMO_IRQ_Address
 
405
        ldr     r0,[r0]
 
406
        ldr     r1,=IRQ_Location
 
407
        str     r0,[r1]
 
408
 
 
409
//; restore HIMO's SWI handler if it's a PXROS application
 
410
        ldr     r0,=PxPrepareInit
 
411
        cmp     r0,#0
 
412
        moveq   pc,lr
 
413
 
 
414
        ldr     r0,=oldSWIHandler
 
415
        ldr     r0,[r0]
 
416
        ldr     r1,=SWI_Location
 
417
        str     r0,[r1]
 
418
 
 
419
        mov     pc,lr
 
420
#endif /* USE_IRQ && USE_HIMO */
 
421
 
 
422
 
 
423
 
 
424
 
 
425
//; # -------------------------------------------------------------------------
 
426
//; # data section used by startup code
 
427
 
 
428
        .data
 
429
 
 
430
//; # -------------------------------------------------------------------------
 
431
//; # Temporary interrupt stack
 
432
 
 
433
        .section ".bss"
 
434
 
 
435
#if defined(USE_IRQ) && defined(USE_HIMO)
 
436
HIMO_IRQ_Address:
 
437
        .long   0
 
438
#endif /* USE_IRQ && USE_HIMO */
 
439
 
 
440
        .global __interrupt_stack
 
441
        .global __startup_stack
 
442
        .global _PxSysstackend
 
443
 
 
444
//; # Small stacks, only used for saving information between CPU modes
 
445
__exception_stack_base:
 
446
        .rept   16
 
447
        .long   0
 
448
        .endr
 
449
__FIQ_exception_stack:
 
450
        .rept   16
 
451
        .long   0
 
452
        .endr
 
453
__exception_stack:
 
454
 
 
455
//; # Runtime stack used during all IRQ interrupt processing
 
456
#ifndef IRQ_STACK_SIZE
 
457
#ifdef USE_IRQ
 
458
#define IRQ_STACK_SIZE          512
 
459
#else
 
460
#define IRQ_STACK_SIZE          16*4
 
461
#endif /* USE_IRQ */
 
462
#endif /* IRQ_STACK_SIZE */
 
463
 
 
464
        .balign 16
 
465
__interrupt_stack_base:
 
466
        .rept   IRQ_STACK_SIZE
 
467
        .byte   0
 
468
        .endr
 
469
        .balign 16
 
470
__interrupt_stack:
 
471
//; # the following 2 words are used for PXROS taskret storage
 
472
        .long   0
 
473
        .long   0
 
474
 
 
475
#ifndef STARTUP_STACK_SIZE
 
476
#define STARTUP_STACK_SIZE      512
 
477
#endif /* STARTUP_STACK_SIZE */
 
478
 
 
479
        .balign 16
 
480
_PxSysstackend:
 
481
__startup_stack_base:
 
482
        .rept   STARTUP_STACK_SIZE
 
483
        .byte   0
 
484
        .endr
 
485
        .balign 16
 
486
__startup_stack:
 
487
 
 
488
#ifndef USER_STACK_SIZE
 
489
#define USER_STACK_SIZE         512
 
490
#endif /* USER_STACK_SIZE */
 
491
 
 
492
        .balign 16
 
493
__user_stack_base:
 
494
        .rept   USER_STACK_SIZE
 
495
        .byte   0
 
496
        .endr
 
497
        .balign 16
 
498
__user_stack:
 
499
 
 
500
 
 
501
//; # --------------------------------------------------------------------------
 
502
//; #  end of vectors.S