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