David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2012 Regents of the University of California |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef _ASM_RISCV_BUG_H |
| 7 | #define _ASM_RISCV_BUG_H |
| 8 | |
| 9 | #include <linux/compiler.h> |
| 10 | #include <linux/const.h> |
| 11 | #include <linux/types.h> |
| 12 | |
| 13 | #include <asm/asm.h> |
| 14 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15 | #define __INSN_LENGTH_MASK _UL(0x3) |
| 16 | #define __INSN_LENGTH_32 _UL(0x3) |
| 17 | #define __COMPRESSED_INSN_MASK _UL(0xffff) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 18 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 19 | #define __BUG_INSN_32 _UL(0x00100073) /* ebreak */ |
| 20 | #define __BUG_INSN_16 _UL(0x9002) /* c.ebreak */ |
| 21 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 22 | typedef u32 bug_insn_t; |
| 23 | |
| 24 | #ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS |
| 25 | #define __BUG_ENTRY_ADDR RISCV_INT " 1b - 2b" |
| 26 | #define __BUG_ENTRY_FILE RISCV_INT " %0 - 2b" |
| 27 | #else |
| 28 | #define __BUG_ENTRY_ADDR RISCV_PTR " 1b" |
| 29 | #define __BUG_ENTRY_FILE RISCV_PTR " %0" |
| 30 | #endif |
| 31 | |
| 32 | #ifdef CONFIG_DEBUG_BUGVERBOSE |
| 33 | #define __BUG_ENTRY \ |
| 34 | __BUG_ENTRY_ADDR "\n\t" \ |
| 35 | __BUG_ENTRY_FILE "\n\t" \ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 36 | RISCV_SHORT " %1\n\t" \ |
| 37 | RISCV_SHORT " %2" |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 38 | #else |
| 39 | #define __BUG_ENTRY \ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 40 | __BUG_ENTRY_ADDR "\n\t" \ |
| 41 | RISCV_SHORT " %2" |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 42 | #endif |
| 43 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 44 | #ifdef CONFIG_GENERIC_BUG |
| 45 | #define __BUG_FLAGS(flags) \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 46 | do { \ |
| 47 | __asm__ __volatile__ ( \ |
| 48 | "1:\n\t" \ |
| 49 | "ebreak\n" \ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 50 | ".pushsection __bug_table,\"aw\"\n\t" \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 51 | "2:\n\t" \ |
| 52 | __BUG_ENTRY "\n\t" \ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 53 | ".org 2b + %3\n\t" \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 54 | ".popsection" \ |
| 55 | : \ |
| 56 | : "i" (__FILE__), "i" (__LINE__), \ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 57 | "i" (flags), \ |
| 58 | "i" (sizeof(struct bug_entry))); \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 59 | } while (0) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 60 | #else /* CONFIG_GENERIC_BUG */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 61 | #define __BUG_FLAGS(flags) do { \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 62 | __asm__ __volatile__ ("ebreak\n"); \ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 63 | } while (0) |
| 64 | #endif /* CONFIG_GENERIC_BUG */ |
| 65 | |
| 66 | #define BUG() do { \ |
| 67 | __BUG_FLAGS(0); \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 68 | unreachable(); \ |
| 69 | } while (0) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 70 | |
| 71 | #define __WARN_FLAGS(flags) __BUG_FLAGS(BUGFLAG_WARNING|(flags)) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 72 | |
| 73 | #define HAVE_ARCH_BUG |
| 74 | |
| 75 | #include <asm-generic/bug.h> |
| 76 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 77 | struct pt_regs; |
| 78 | struct task_struct; |
| 79 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 80 | void die(struct pt_regs *regs, const char *str); |
| 81 | void do_trap(struct pt_regs *regs, int signo, int code, unsigned long addr); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 82 | |
| 83 | #endif /* _ASM_RISCV_BUG_H */ |