Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Macpaul Lin | 463d47f | 2011-10-11 22:33:19 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2002 |
| 4 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 5 | * Alex Zuepke <azu@sysgo.de> |
| 6 | * |
| 7 | * Copyright (C) 2011 Andes Technology Corporation |
| 8 | * Shawn Lin, Andes Technology Corporation <nobuhiro@andestech.com> |
| 9 | * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com> |
Macpaul Lin | 463d47f | 2011-10-11 22:33:19 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <common.h> |
Simon Glass | 9a3b4ce | 2019-12-28 10:45:01 -0700 | [diff] [blame] | 13 | #include <cpu_func.h> |
Simon Glass | c30b7ad | 2019-11-14 12:57:41 -0700 | [diff] [blame] | 14 | #include <irq_func.h> |
Macpaul Lin | 463d47f | 2011-10-11 22:33:19 +0000 | [diff] [blame] | 15 | #include <asm/ptrace.h> |
| 16 | #include <asm/system.h> |
| 17 | #undef INTERRUPT_MODE |
| 18 | |
| 19 | static int int_flag; |
| 20 | |
| 21 | int irq_flags; /* needed by asm-nds32/system.h */ |
| 22 | |
| 23 | int GIE_STATUS(void) |
| 24 | { |
| 25 | int ret; |
| 26 | |
| 27 | __asm__ __volatile__ ( |
| 28 | "mfsr $p0, $psw\n\t" |
| 29 | "andi %0, %0, 0x1\n\t" |
| 30 | : "=r" (ret) |
| 31 | : |
| 32 | : "memory" |
| 33 | ); |
| 34 | return ret; |
| 35 | } |
| 36 | |
| 37 | #ifdef CONFIG_USE_INTERRUPT |
| 38 | |
Kun-Hua Huang | 2e88bb2 | 2015-08-24 14:52:35 +0800 | [diff] [blame] | 39 | int interrupt_init(void) |
| 40 | { |
| 41 | return 0; |
| 42 | } |
Macpaul Lin | 463d47f | 2011-10-11 22:33:19 +0000 | [diff] [blame] | 43 | /* enable interrupts */ |
| 44 | void enable_interrupts(void) |
| 45 | { |
| 46 | local_irq_restore(int_flag); |
| 47 | } |
| 48 | |
| 49 | /* |
| 50 | * disable interrupts |
York Sun | 472d546 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 51 | * Return true if GIE is enabled before we disable it. |
Macpaul Lin | 463d47f | 2011-10-11 22:33:19 +0000 | [diff] [blame] | 52 | */ |
| 53 | int disable_interrupts(void) |
| 54 | { |
| 55 | |
| 56 | int gie_ori_status; |
| 57 | |
| 58 | gie_ori_status = GIE_STATUS(); |
| 59 | |
| 60 | local_irq_save(int_flag); |
| 61 | |
| 62 | return gie_ori_status; |
| 63 | } |
| 64 | #endif |
| 65 | |
| 66 | void bad_mode(void) |
| 67 | { |
| 68 | panic("Resetting CPU ...\n"); |
Harald Seiler | 35b65dd | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 69 | reset_cpu(); |
Macpaul Lin | 463d47f | 2011-10-11 22:33:19 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | void show_regs(struct pt_regs *regs) |
| 73 | { |
| 74 | const char *processor_modes[] = {"USER", "SuperUser" , "HyperVisor"}; |
| 75 | |
| 76 | printf("\n"); |
| 77 | printf("pc : [<%08lx>] sp: [<%08lx>]\n" |
| 78 | "lp : %08lx gp : %08lx fp : %08lx\n", |
| 79 | regs->ipc, regs->sp, regs->lp, regs->gp, regs->fp); |
| 80 | printf("D1H: %08lx D1L: %08lx D0H: %08lx D0L: %08lx\n", |
| 81 | regs->d1hi, regs->d1lo, regs->d0hi, regs->d0lo); |
| 82 | printf("r27: %08lx r26: %08lx r25: %08lx r24: %08lx\n", |
Macpaul Lin | b0c4fae | 2012-03-11 16:30:18 +0800 | [diff] [blame] | 83 | regs->p1, regs->p0, regs->r[25], regs->r[24]); |
Macpaul Lin | 463d47f | 2011-10-11 22:33:19 +0000 | [diff] [blame] | 84 | printf("r23: %08lx r22: %08lx r21: %08lx r20: %08lx\n", |
| 85 | regs->r[23], regs->r[22], regs->r[21], regs->r[20]); |
| 86 | printf("r19: %08lx r18: %08lx r17: %08lx r16: %08lx\n", |
| 87 | regs->r[19], regs->r[18], regs->r[17], regs->r[16]); |
| 88 | printf("r15: %08lx r14: %08lx r13: %08lx r12: %08lx\n", |
| 89 | regs->r[15], regs->r[14], regs->r[13], regs->r[12]); |
| 90 | printf("r11: %08lx r10: %08lx r9 : %08lx r8 : %08lx\n", |
| 91 | regs->r[11], regs->r[10], regs->r[9], regs->r[8]); |
| 92 | printf("r7 : %08lx r6 : %08lx r5 : %08lx r4 : %08lx\n", |
| 93 | regs->r[7], regs->r[6], regs->r[5], regs->r[4]); |
| 94 | printf("r3 : %08lx r2 : %08lx r1 : %08lx r0 : %08lx\n", |
| 95 | regs->r[3], regs->r[2], regs->r[1], regs->r[0]); |
| 96 | printf(" Interrupts %s Mode %s\n", |
| 97 | interrupts_enabled(regs) ? "on" : "off", |
| 98 | processor_modes[processor_mode(regs)]); |
| 99 | } |
| 100 | |
| 101 | void do_interruption(struct pt_regs *pt_regs, int EVIC_num) |
| 102 | { |
| 103 | const char *interruption_type[] = { |
| 104 | "Reset", |
| 105 | "TLB Fill", |
| 106 | "TLB Not Present", |
| 107 | "TLB Misc", |
| 108 | "VLPT Miss", |
| 109 | "Cache Parity Error", |
| 110 | "Debug", |
| 111 | "General Exception", |
| 112 | "External Interrupt" |
| 113 | }; |
| 114 | |
| 115 | printf("%s\n", interruption_type[EVIC_num]); |
| 116 | show_regs(pt_regs); |
| 117 | bad_mode(); |
| 118 | } |