[444] | 1 | /* Initialization code for coldfire boards. |
---|
| 2 | * |
---|
| 3 | * Copyright (c) 2006 CodeSourcery Inc |
---|
| 4 | * |
---|
| 5 | * The authors hereby grant permission to use, copy, modify, distribute, |
---|
| 6 | * and license this software and its documentation for any purpose, provided |
---|
| 7 | * that existing copyright notices are retained in all copies and that this |
---|
| 8 | * notice is included verbatim in any distributions. No written agreement, |
---|
| 9 | * license, or royalty fee is required for any of the authorized uses. |
---|
| 10 | * Modifications to this software may be copyrighted by their authors |
---|
| 11 | * and need not follow the licensing terms described here, provided that |
---|
| 12 | * the new terms are clearly indicated on the first page of each file where |
---|
| 13 | * they apply. |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | #include <stdlib.h> |
---|
| 17 | |
---|
| 18 | extern const int __interrupt_vector[]; |
---|
| 19 | extern void __reset (void); |
---|
| 20 | |
---|
| 21 | extern const char __data_load[] __attribute__ ((aligned (4))); |
---|
| 22 | extern char __data_start[] __attribute__ ((aligned (4))); |
---|
| 23 | extern char __bss_start[] __attribute__ ((aligned (4))); |
---|
| 24 | extern char __end[] __attribute__ ((aligned (4))); |
---|
| 25 | void *__heap_limit; |
---|
| 26 | extern void software_init_hook (void) __attribute__ ((weak)); |
---|
| 27 | extern void hardware_init_hook (void) __attribute__ ((weak)); |
---|
| 28 | extern void _init (void); |
---|
| 29 | extern void _fini (void); |
---|
| 30 | |
---|
| 31 | extern int main (int, char **, char **); |
---|
| 32 | |
---|
| 33 | /* This is called from a tiny assembly stub. */ |
---|
| 34 | void __start1 (void *heap_limit) |
---|
| 35 | { |
---|
| 36 | unsigned ix; |
---|
| 37 | |
---|
| 38 | if (hardware_init_hook) |
---|
| 39 | hardware_init_hook (); |
---|
| 40 | |
---|
| 41 | /* Initialize memory */ |
---|
| 42 | if (__data_load != __data_start) |
---|
| 43 | memcpy (__data_start, __data_load, __bss_start - __data_start); |
---|
| 44 | memset (__bss_start, 0, __end - __bss_start); |
---|
| 45 | |
---|
| 46 | __heap_limit = heap_limit; |
---|
| 47 | |
---|
| 48 | if (software_init_hook) |
---|
| 49 | software_init_hook (); |
---|
| 50 | |
---|
| 51 | _init (); |
---|
| 52 | |
---|
| 53 | /* I'm not sure how useful it is to have a fini_section in an |
---|
| 54 | embedded system. */ |
---|
| 55 | atexit (_fini); |
---|
| 56 | |
---|
| 57 | ix = main (0, NULL, NULL); |
---|
| 58 | exit (ix); |
---|
| 59 | |
---|
| 60 | while (1) |
---|
| 61 | __reset (); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | /* A default hardware init hook. */ |
---|
| 65 | |
---|
| 66 | void __attribute__ ((weak)) hardware_init_hook (void) |
---|
| 67 | { |
---|
| 68 | /* Set the VBR. */ |
---|
| 69 | __asm__ __volatile__ ("movec.l %0,%/vbr" :: "r" (__interrupt_vector)); |
---|
| 70 | |
---|
| 71 | #if !defined(__mcf_family_5213) && !defined(__mcf_family_51qe) && !defined(__mcf_family_51) |
---|
| 72 | /* Flush & enable the caches */ |
---|
| 73 | #define CACR_CINV (1 << 24) |
---|
| 74 | #define CACR_CENB (1 << 31) |
---|
| 75 | __asm__ __volatile__ ("movec.l %0,%/cacr" :: "r" (CACR_CINV | CACR_CENB)); |
---|
| 76 | #endif |
---|
| 77 | |
---|
| 78 | /* Should we drop into user mode here? */ |
---|
| 79 | } |
---|