[444] | 1 | /* interrupts.c -- interrupt handling for OpenRISC 1000. |
---|
| 2 | * |
---|
| 3 | * Copyright (c) 2014 Authors |
---|
| 4 | * |
---|
| 5 | * Contributor Stefan Wallentowitz <stefan.wallentowitz@tum.de> |
---|
| 6 | * |
---|
| 7 | * The authors hereby grant permission to use, copy, modify, distribute, |
---|
| 8 | * and license this software and its documentation for any purpose, provided |
---|
| 9 | * that existing copyright notices are retained in all copies and that this |
---|
| 10 | * notice is included verbatim in any distributions. No written agreement, |
---|
| 11 | * license, or royalty fee is required for any of the authorized uses. |
---|
| 12 | * Modifications to this software may be copyrighted by their authors |
---|
| 13 | * and need not follow the licensing terms described here, provided that |
---|
| 14 | * the new terms are clearly indicated on the first page of each file where |
---|
| 15 | * they apply. |
---|
| 16 | */ |
---|
| 17 | |
---|
| 18 | #include "include/or1k-support.h" |
---|
| 19 | #include "include/or1k-sprs.h" |
---|
| 20 | #include <stdint.h> |
---|
| 21 | |
---|
| 22 | #include "or1k-internals.h" |
---|
| 23 | |
---|
| 24 | #ifdef __OR1K_MULTICORE__ |
---|
| 25 | or1k_interrupt_handler_table_t *_or1k_interrupt_handler_table; |
---|
| 26 | or1k_interrupt_handler_data_ptr_table_t *_or1k_interrupt_handler_data_ptr_table; |
---|
| 27 | #else |
---|
| 28 | or1k_interrupt_handler_table_t _or1k_interrupt_handler_table; |
---|
| 29 | or1k_interrupt_handler_data_ptr_table_t _or1k_interrupt_handler_data_ptr_table; |
---|
| 30 | #endif |
---|
| 31 | |
---|
| 32 | void or1k_interrupt_handler_add(uint32_t id, |
---|
| 33 | or1k_interrupt_handler_fptr handler, |
---|
| 34 | void *data_ptr) |
---|
| 35 | { |
---|
| 36 | #ifdef __OR1K_MULTICORE__ |
---|
| 37 | _or1k_interrupt_handler_table[or1k_coreid()][id] = handler; |
---|
| 38 | _or1k_interrupt_handler_data_ptr_table[or1k_coreid()][id] = (uint32_t) data_ptr; |
---|
| 39 | #else |
---|
| 40 | _or1k_interrupt_handler_table[id] = handler; |
---|
| 41 | _or1k_interrupt_handler_data_ptr_table[id] = (uint32_t) data_ptr; |
---|
| 42 | #endif |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | void |
---|
| 46 | or1k_interrupts_enable(void) |
---|
| 47 | { |
---|
| 48 | uint32_t sr = or1k_mfspr(OR1K_SPR_SYS_SR_ADDR); |
---|
| 49 | sr = OR1K_SPR_SYS_SR_IEE_SET(sr, 1); |
---|
| 50 | or1k_mtspr(OR1K_SPR_SYS_SR_ADDR, sr); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | uint32_t |
---|
| 54 | or1k_interrupts_disable(void) |
---|
| 55 | { |
---|
| 56 | uint32_t oldsr, newsr; |
---|
| 57 | oldsr= or1k_mfspr(OR1K_SPR_SYS_SR_ADDR); |
---|
| 58 | newsr = OR1K_SPR_SYS_SR_IEE_SET(oldsr, 0); |
---|
| 59 | or1k_mtspr(OR1K_SPR_SYS_SR_ADDR, newsr); |
---|
| 60 | return OR1K_SPR_SYS_SR_IEE_GET(oldsr); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | void |
---|
| 64 | or1k_interrupts_restore(uint32_t sr_iee) |
---|
| 65 | { |
---|
| 66 | uint32_t sr = or1k_mfspr(OR1K_SPR_SYS_SR_ADDR); |
---|
| 67 | sr = OR1K_SPR_SYS_SR_IEE_SET(sr, sr_iee); |
---|
| 68 | or1k_mtspr(OR1K_SPR_SYS_SR_ADDR, sr); |
---|
| 69 | } |
---|