1 | /** |
---|
2 | * @file tms570-pom.c |
---|
3 | * |
---|
4 | * @ingroup tms570 |
---|
5 | * |
---|
6 | * @brief TMS570 Parameter Overlay Module functions definitions. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2014 Pavel Pisa <pisa@cmp.felk.cvut.cz> |
---|
11 | * |
---|
12 | * Czech Technical University in Prague |
---|
13 | * Zikova 1903/4 |
---|
14 | * 166 36 Praha 6 |
---|
15 | * Czech Republic |
---|
16 | * |
---|
17 | * The license and distribution terms for this file may be |
---|
18 | * found in the file LICENSE in this distribution or at |
---|
19 | * http://www.rtems.org/license/LICENSE. |
---|
20 | */ |
---|
21 | |
---|
22 | #include <stdint.h> |
---|
23 | #include <bsp/tms570-pom.h> |
---|
24 | #include <bsp/linker-symbols.h> |
---|
25 | #include <rtems/score/armv4.h> |
---|
26 | #include <bsp.h> |
---|
27 | |
---|
28 | /* |
---|
29 | * Placement of exceptions target addresses in memory |
---|
30 | * when insructions with opcode 0xe59ff018 |
---|
31 | * ldr pc, [pc, #0x18] |
---|
32 | * are used to fill ARM exception vectors area |
---|
33 | */ |
---|
34 | typedef struct{ |
---|
35 | uint32_t reserved1; |
---|
36 | uint32_t except_addr_undef; |
---|
37 | uint32_t except_addr_swi; |
---|
38 | uint32_t except_addr_prefetch; |
---|
39 | uint32_t except_addr_abort; |
---|
40 | uint32_t reserved2; |
---|
41 | uint32_t except_addr_irq; |
---|
42 | uint32_t except_addr_fiq; |
---|
43 | }vec_remap_table; |
---|
44 | |
---|
45 | void bsp_block_on_exception(void); |
---|
46 | |
---|
47 | void bsp_block_on_exception(void){ |
---|
48 | while(1); |
---|
49 | } |
---|
50 | |
---|
51 | extern char bsp_int_vec_overlay_start[]; |
---|
52 | |
---|
53 | /* |
---|
54 | * Global overlay target address holds shared MSB bits for all regions |
---|
55 | * It is set to linker RAM_INT_VEC region - i.e. area reserved |
---|
56 | * at internal SRAM memory start, address 0x08000000 |
---|
57 | */ |
---|
58 | uint32_t pom_global_overlay_target_address_start = |
---|
59 | (uintptr_t)bsp_int_vec_overlay_start; |
---|
60 | |
---|
61 | /** |
---|
62 | * @brief initialize and clear parameters overlay module (POM) |
---|
63 | * |
---|
64 | * clears all remap regions. The actual POM enable is left to the first user. |
---|
65 | * |
---|
66 | * @retval Void |
---|
67 | */ |
---|
68 | void tms570_initialize_and_clear(void) |
---|
69 | { |
---|
70 | int i; |
---|
71 | |
---|
72 | TMS570_POM.GLBCTRL = 0 | (TMS570_POM_GLBCTRL_OTADDR(~0) & |
---|
73 | pom_global_overlay_target_address_start); |
---|
74 | |
---|
75 | for ( i = 0; i < TMS570_POM_REGIONS; ++i ) { |
---|
76 | TMS570_POM.REG[i].REGSIZE = TMS570_POM_REGSIZE_SIZE(TMS570_POM_REGSIZE_DISABLED); |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | /** |
---|
81 | * @brief remaps vector table |
---|
82 | * |
---|
83 | * transfer the rtems start vector table to address 0x0 |
---|
84 | * |
---|
85 | * @retval Void |
---|
86 | */ |
---|
87 | void tms570_pom_remap(void) |
---|
88 | { |
---|
89 | uint32_t vec_overlay_start = pom_global_overlay_target_address_start; |
---|
90 | |
---|
91 | /* |
---|
92 | * Copy RTEMS the first level exception processing code |
---|
93 | * to RAM area which can be used for later as POM overlay |
---|
94 | * of Flash vectors. The code is expected to have for of eight |
---|
95 | * ldr pc, [pc,#0x18] |
---|
96 | * instructions followed by eight words with actual exception |
---|
97 | * service routines target addresses. This is case of RTEMS default |
---|
98 | * table found in |
---|
99 | * c/src/lib/libbsp/arm/shared/start/start.S |
---|
100 | */ |
---|
101 | memcpy((void*)vec_overlay_start, bsp_start_vector_table_begin, 64); |
---|
102 | |
---|
103 | #if 0 |
---|
104 | { |
---|
105 | /* Fill exception table by catch error infinite loop for debugging */ |
---|
106 | vec_remap_table* vec_table = (vec_remap_table*)(vec_overlay_start+32); |
---|
107 | vec_table->except_addr_undef = (uint32_t)bsp_block_on_exception; |
---|
108 | vec_table->except_addr_swi = (uint32_t)bsp_block_on_exception; |
---|
109 | vec_table->except_addr_prefetch = (uint32_t)bsp_block_on_exception;//_ARMV4_Exception_prefetch_abort; |
---|
110 | vec_table->except_addr_abort = (uint32_t)bsp_block_on_exception;//_ARMV4_Exception_data_abort; |
---|
111 | vec_table->except_addr_irq = (uint32_t)_ARMV4_Exception_interrupt; |
---|
112 | vec_table->except_addr_fiq = (uint32_t)bsp_block_on_exception;//_ARMV4_Exception_interrupt; |
---|
113 | } |
---|
114 | #endif |
---|
115 | |
---|
116 | /* |
---|
117 | * The overlay vectors replacement area cannot be used directly |
---|
118 | * to replace jump instructions on start of Flash because instruction |
---|
119 | * fetch through POM is not reliable supported (works in most times |
---|
120 | * but sometimes fails). |
---|
121 | * Area of 64 bytes starting at address 0x00000040 is replaced. |
---|
122 | * This way target addresses are placed between 0x00000060 |
---|
123 | * and 0x0000007F. If boot loader startup code contains instructions |
---|
124 | * ldr pc,[pc,#0x58] |
---|
125 | * (opcode 0xe59ff058) then the jump target addresses are replaced |
---|
126 | * by pointers to actual RTEMS exceptions service functions. |
---|
127 | */ |
---|
128 | TMS570_POM.REG[0].PROGSTART = TMS570_POM_PROGSTART_STARTADDRESS(64); |
---|
129 | TMS570_POM.REG[0].OVLSTART = TMS570_POM_OVLSTART_STARTADDRESS(vec_overlay_start); |
---|
130 | TMS570_POM.REG[0].REGSIZE = TMS570_POM_REGSIZE_SIZE(TMS570_POM_REGSIZE_64B); |
---|
131 | TMS570_POM.GLBCTRL = TMS570_POM_GLBCTRL_ON_OFF(0xa) | |
---|
132 | TMS570_POM_GLBCTRL_ETO(0xa) | |
---|
133 | (TMS570_POM_GLBCTRL_OTADDR(~0) & |
---|
134 | pom_global_overlay_target_address_start); |
---|
135 | } |
---|