1 | /* |
---|
2 | * Opencore OR1K CPU Dependent Source |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 2014-2015 Hesham ALMatary <heshamelmatary@gmail.com> |
---|
5 | * COPYRIGHT (c) 1989-1999. |
---|
6 | * On-Line Applications Research Corporation (OAR). |
---|
7 | * |
---|
8 | * The license and distribution terms for this file may be |
---|
9 | * found in the file LICENSE in this distribution or at |
---|
10 | * http://www.rtems.org/license/LICENSE. |
---|
11 | * |
---|
12 | */ |
---|
13 | |
---|
14 | #include <rtems/score/isr.h> |
---|
15 | #include <rtems/score/cpu.h> |
---|
16 | |
---|
17 | /* bsp_start_vector_table_begin is the start address of the vector table |
---|
18 | * containing addresses to ISR Handlers. It's defined at the BSP linkcmds |
---|
19 | * and may differ from one BSP to another. |
---|
20 | */ |
---|
21 | extern char bsp_start_vector_table_begin[]; |
---|
22 | |
---|
23 | /** |
---|
24 | * @brief Performs processor dependent initialization. |
---|
25 | */ |
---|
26 | void _CPU_Initialize(void) |
---|
27 | { |
---|
28 | /* Do nothing */ |
---|
29 | } |
---|
30 | |
---|
31 | /** |
---|
32 | * @brief Sets the hardware interrupt level by the level value. |
---|
33 | * |
---|
34 | * @param[in] level for or1k can only range over two values: |
---|
35 | * 0 (enable interrupts) and 1 (disable interrupts). In future |
---|
36 | * implementations if fast context switch is implemented, the level |
---|
37 | * can range from 0 to 15. @see OpenRISC architecture manual. |
---|
38 | * |
---|
39 | */ |
---|
40 | void _CPU_ISR_Set_level(uint32_t level) |
---|
41 | { |
---|
42 | uint32_t sr = 0; |
---|
43 | level = (level > 0)? 1 : 0; |
---|
44 | |
---|
45 | /* map level bit to or1k interrupt enable/disable bit in sr register */ |
---|
46 | level <<= CPU_OR1K_SPR_SR_SHAMT_IEE; |
---|
47 | |
---|
48 | sr = _OR1K_mfspr(CPU_OR1K_SPR_SR); |
---|
49 | |
---|
50 | if (level == 0){ /* Enable all interrupts */ |
---|
51 | sr |= CPU_OR1K_SPR_SR_IEE | CPU_OR1K_SPR_SR_TEE; |
---|
52 | |
---|
53 | } else{ |
---|
54 | sr &= ~CPU_OR1K_SPR_SR_IEE; |
---|
55 | } |
---|
56 | |
---|
57 | _OR1K_mtspr(CPU_OR1K_SPR_SR, sr); |
---|
58 | } |
---|
59 | |
---|
60 | uint32_t _CPU_ISR_Get_level( void ) |
---|
61 | { |
---|
62 | uint32_t sr = 0; |
---|
63 | |
---|
64 | sr = _OR1K_mfspr(CPU_OR1K_SPR_SR); |
---|
65 | |
---|
66 | return (sr & CPU_OR1K_SPR_SR_IEE)? 0 : 1; |
---|
67 | } |
---|
68 | |
---|
69 | void _CPU_ISR_install_raw_handler( |
---|
70 | uint32_t vector, |
---|
71 | CPU_ISR_raw_handler new_handler, |
---|
72 | CPU_ISR_raw_handler *old_handler |
---|
73 | ) |
---|
74 | { |
---|
75 | CPU_ISR_raw_handler *table = |
---|
76 | (CPU_ISR_raw_handler *) bsp_start_vector_table_begin; |
---|
77 | CPU_ISR_raw_handler current_handler; |
---|
78 | |
---|
79 | ISR_Level level; |
---|
80 | |
---|
81 | _ISR_Local_disable( level ); |
---|
82 | |
---|
83 | current_handler = table [vector]; |
---|
84 | |
---|
85 | /* The current handler is now the old one */ |
---|
86 | if (old_handler != NULL) { |
---|
87 | *old_handler = current_handler; |
---|
88 | } |
---|
89 | |
---|
90 | /* Write only if necessary to avoid writes to a maybe read-only memory */ |
---|
91 | if (current_handler != new_handler) { |
---|
92 | table [vector] = new_handler; |
---|
93 | } |
---|
94 | |
---|
95 | _ISR_Local_enable( level ); |
---|
96 | } |
---|
97 | |
---|
98 | void *_CPU_Thread_Idle_body( uintptr_t ignored ) |
---|
99 | { |
---|
100 | do { |
---|
101 | _OR1K_CPU_Sleep(); |
---|
102 | } while (1); |
---|
103 | } |
---|