| 1 |
|
| 2 | |
| 3 | * Copyright (C) 2012 Regents of the University of California
|
| 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 |
|
| 15 | #define __INSN_LENGTH_MASK _UL(0x3)
|
| 16 | #define __INSN_LENGTH_32 _UL(0x3)
|
| 17 | #define __COMPRESSED_INSN_MASK _UL(0xffff)
|
| 18 |
|
| 19 | #define __BUG_INSN_32 _UL(0x00100073)
|
| 20 | #define __BUG_INSN_16 _UL(0x9002)
|
| 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 |
|
| 30 | typedef u32 bug_insn_t;
|
| 31 |
|
| 32 | #define __BUG_ENTRY_ADDR RISCV_INT " 1b - ."
|
| 33 | #define __BUG_ENTRY_FILE(file) RISCV_INT " " file " - ."
|
| 34 |
|
| 35 | #ifdef CONFIG_DEBUG_BUGVERBOSE
|
| 36 | #define __BUG_ENTRY(file, line, flags) \
|
| 37 | __BUG_ENTRY_ADDR "\n\t" \
|
| 38 | __BUG_ENTRY_FILE(file) "\n\t" \
|
| 39 | RISCV_SHORT " " line "\n\t" \
|
| 40 | RISCV_SHORT " " flags
|
| 41 | #else
|
| 42 | #define __BUG_ENTRY(file, line, flags) \
|
| 43 | __BUG_ENTRY_ADDR "\n\t" \
|
| 44 | RISCV_SHORT " " flags
|
| 45 | #endif
|
| 46 |
|
| 47 | #ifdef CONFIG_GENERIC_BUG
|
| 48 |
|
| 49 | #define ARCH_WARN_ASM(file, line, flags, size) \
|
| 50 | "1:\n\t" \
|
| 51 | "ebreak\n" \
|
| 52 | ".pushsection __bug_table,\"aw\"\n\t" \
|
| 53 | "2:\n\t" \
|
| 54 | __BUG_ENTRY(file, line, flags) "\n\t" \
|
| 55 | ".org 2b + " size "\n\t" \
|
| 56 | ".popsection" \
|
| 57 |
|
| 58 | #define __BUG_FLAGS(cond_str, flags) \
|
| 59 | do { \
|
| 60 | __asm__ __volatile__ ( \
|
| 61 | ARCH_WARN_ASM("%0", "%1", "%2", "%3") \
|
| 62 | : \
|
| 63 | : "i" (WARN_CONDITION_STR(cond_str) __FILE__), "i" (__LINE__), \
|
| 64 | "i" (flags), \
|
| 65 | "i" (sizeof(struct bug_entry))); \
|
| 66 | } while (0)
|
| 67 |
|
| 68 | #else
|
| 69 | #define __BUG_FLAGS(cond_str, flags) do { \
|
| 70 | __asm__ __volatile__ ("ebreak\n"); \
|
| 71 | } while (0)
|
| 72 | #endif
|
| 73 |
|
| 74 | #define BUG() do { \
|
| 75 | __BUG_FLAGS("", 0); \
|
| 76 | unreachable(); \
|
| 77 | } while (0)
|
| 78 |
|
| 79 | #define __WARN_FLAGS(cond_str, flags) __BUG_FLAGS(cond_str, BUGFLAG_WARNING|(flags))
|
| 80 |
|
| 81 | #define ARCH_WARN_REACHABLE
|
| 82 |
|
| 83 | #define HAVE_ARCH_BUG
|
| 84 |
|
| 85 | #include <asm-generic/bug.h>
|
| 86 |
|
| 87 | struct pt_regs;
|
| 88 | struct task_struct;
|
| 89 |
|
| 90 | void __show_regs(struct pt_regs *regs);
|
| 91 | void die(struct pt_regs *regs, const char *str);
|
| 92 | void do_trap(struct pt_regs *regs, int signo, int code, unsigned long addr);
|
| 93 |
|
| 94 | #endif
|