| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2012 Regents of the University of California |
|---|
| 3 | | - * |
|---|
| 4 | | - * This program is free software; you can redistribute it and/or |
|---|
| 5 | | - * modify it under the terms of the GNU General Public License |
|---|
| 6 | | - * as published by the Free Software Foundation, version 2. |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 9 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | | - * GNU General Public License for more details. |
|---|
| 12 | 4 | */ |
|---|
| 13 | 5 | |
|---|
| 14 | 6 | #ifndef _ASM_RISCV_BUG_H |
|---|
| .. | .. |
|---|
| 20 | 12 | |
|---|
| 21 | 13 | #include <asm/asm.h> |
|---|
| 22 | 14 | |
|---|
| 23 | | -#ifdef CONFIG_GENERIC_BUG |
|---|
| 24 | | -#define __BUG_INSN _AC(0x00100073, UL) /* ebreak */ |
|---|
| 15 | +#define __INSN_LENGTH_MASK _UL(0x3) |
|---|
| 16 | +#define __INSN_LENGTH_32 _UL(0x3) |
|---|
| 17 | +#define __COMPRESSED_INSN_MASK _UL(0xffff) |
|---|
| 25 | 18 | |
|---|
| 26 | | -#ifndef __ASSEMBLY__ |
|---|
| 19 | +#define __BUG_INSN_32 _UL(0x00100073) /* ebreak */ |
|---|
| 20 | +#define __BUG_INSN_16 _UL(0x9002) /* c.ebreak */ |
|---|
| 21 | + |
|---|
| 22 | +#define GET_INSN_LENGTH(insn) \ |
|---|
| 23 | +({ \ |
|---|
| 24 | + unsigned long __len; \ |
|---|
| 25 | + __len = ((insn & __INSN_LENGTH_MASK) == __INSN_LENGTH_32) ? \ |
|---|
| 26 | + 4UL : 2UL; \ |
|---|
| 27 | + __len; \ |
|---|
| 28 | +}) |
|---|
| 29 | + |
|---|
| 27 | 30 | typedef u32 bug_insn_t; |
|---|
| 28 | 31 | |
|---|
| 29 | 32 | #ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS |
|---|
| .. | .. |
|---|
| 38 | 41 | #define __BUG_ENTRY \ |
|---|
| 39 | 42 | __BUG_ENTRY_ADDR "\n\t" \ |
|---|
| 40 | 43 | __BUG_ENTRY_FILE "\n\t" \ |
|---|
| 41 | | - RISCV_SHORT " %1" |
|---|
| 44 | + RISCV_SHORT " %1\n\t" \ |
|---|
| 45 | + RISCV_SHORT " %2" |
|---|
| 42 | 46 | #else |
|---|
| 43 | 47 | #define __BUG_ENTRY \ |
|---|
| 44 | | - __BUG_ENTRY_ADDR |
|---|
| 48 | + __BUG_ENTRY_ADDR "\n\t" \ |
|---|
| 49 | + RISCV_SHORT " %2" |
|---|
| 45 | 50 | #endif |
|---|
| 46 | 51 | |
|---|
| 47 | | -#define BUG() \ |
|---|
| 52 | +#ifdef CONFIG_GENERIC_BUG |
|---|
| 53 | +#define __BUG_FLAGS(flags) \ |
|---|
| 48 | 54 | do { \ |
|---|
| 49 | 55 | __asm__ __volatile__ ( \ |
|---|
| 50 | 56 | "1:\n\t" \ |
|---|
| 51 | 57 | "ebreak\n" \ |
|---|
| 52 | | - ".pushsection __bug_table,\"a\"\n\t" \ |
|---|
| 58 | + ".pushsection __bug_table,\"aw\"\n\t" \ |
|---|
| 53 | 59 | "2:\n\t" \ |
|---|
| 54 | 60 | __BUG_ENTRY "\n\t" \ |
|---|
| 55 | | - ".org 2b + %2\n\t" \ |
|---|
| 61 | + ".org 2b + %3\n\t" \ |
|---|
| 56 | 62 | ".popsection" \ |
|---|
| 57 | 63 | : \ |
|---|
| 58 | 64 | : "i" (__FILE__), "i" (__LINE__), \ |
|---|
| 59 | | - "i" (sizeof(struct bug_entry))); \ |
|---|
| 60 | | - unreachable(); \ |
|---|
| 65 | + "i" (flags), \ |
|---|
| 66 | + "i" (sizeof(struct bug_entry))); \ |
|---|
| 61 | 67 | } while (0) |
|---|
| 62 | | -#endif /* !__ASSEMBLY__ */ |
|---|
| 63 | 68 | #else /* CONFIG_GENERIC_BUG */ |
|---|
| 64 | | -#ifndef __ASSEMBLY__ |
|---|
| 65 | | -#define BUG() \ |
|---|
| 66 | | -do { \ |
|---|
| 69 | +#define __BUG_FLAGS(flags) do { \ |
|---|
| 67 | 70 | __asm__ __volatile__ ("ebreak\n"); \ |
|---|
| 71 | +} while (0) |
|---|
| 72 | +#endif /* CONFIG_GENERIC_BUG */ |
|---|
| 73 | + |
|---|
| 74 | +#define BUG() do { \ |
|---|
| 75 | + __BUG_FLAGS(0); \ |
|---|
| 68 | 76 | unreachable(); \ |
|---|
| 69 | 77 | } while (0) |
|---|
| 70 | | -#endif /* !__ASSEMBLY__ */ |
|---|
| 71 | | -#endif /* CONFIG_GENERIC_BUG */ |
|---|
| 78 | + |
|---|
| 79 | +#define __WARN_FLAGS(flags) __BUG_FLAGS(BUGFLAG_WARNING|(flags)) |
|---|
| 72 | 80 | |
|---|
| 73 | 81 | #define HAVE_ARCH_BUG |
|---|
| 74 | 82 | |
|---|
| 75 | 83 | #include <asm-generic/bug.h> |
|---|
| 76 | 84 | |
|---|
| 77 | | -#ifndef __ASSEMBLY__ |
|---|
| 78 | | - |
|---|
| 79 | 85 | struct pt_regs; |
|---|
| 80 | 86 | struct task_struct; |
|---|
| 81 | 87 | |
|---|
| 82 | | -extern void die(struct pt_regs *regs, const char *str); |
|---|
| 83 | | -extern void do_trap(struct pt_regs *regs, int signo, int code, |
|---|
| 84 | | - unsigned long addr, struct task_struct *tsk); |
|---|
| 85 | | - |
|---|
| 86 | | -#endif /* !__ASSEMBLY__ */ |
|---|
| 88 | +void die(struct pt_regs *regs, const char *str); |
|---|
| 89 | +void do_trap(struct pt_regs *regs, int signo, int code, unsigned long addr); |
|---|
| 87 | 90 | |
|---|
| 88 | 91 | #endif /* _ASM_RISCV_BUG_H */ |
|---|