blob: d6f1ec08d97b0875ee4f222fc86f448471c92a4d [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001/* SPDX-License-Identifier: GPL-2.0-only */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002/*
3 * Copyright (C) 2012 Regents of the University of California
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00004 */
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 Brazdil0f672f62019-12-10 10:32:29 +000015#define __INSN_LENGTH_MASK _UL(0x3)
16#define __INSN_LENGTH_32 _UL(0x3)
17#define __COMPRESSED_INSN_MASK _UL(0xffff)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000018
David Brazdil0f672f62019-12-10 10:32:29 +000019#define __BUG_INSN_32 _UL(0x00100073) /* ebreak */
20#define __BUG_INSN_16 _UL(0x9002) /* c.ebreak */
21
Olivier Deprez157378f2022-04-04 15:47:50 +020022#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
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000030typedef u32 bug_insn_t;
31
32#ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
33#define __BUG_ENTRY_ADDR RISCV_INT " 1b - 2b"
34#define __BUG_ENTRY_FILE RISCV_INT " %0 - 2b"
35#else
36#define __BUG_ENTRY_ADDR RISCV_PTR " 1b"
37#define __BUG_ENTRY_FILE RISCV_PTR " %0"
38#endif
39
40#ifdef CONFIG_DEBUG_BUGVERBOSE
41#define __BUG_ENTRY \
42 __BUG_ENTRY_ADDR "\n\t" \
43 __BUG_ENTRY_FILE "\n\t" \
David Brazdil0f672f62019-12-10 10:32:29 +000044 RISCV_SHORT " %1\n\t" \
45 RISCV_SHORT " %2"
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000046#else
47#define __BUG_ENTRY \
David Brazdil0f672f62019-12-10 10:32:29 +000048 __BUG_ENTRY_ADDR "\n\t" \
49 RISCV_SHORT " %2"
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000050#endif
51
David Brazdil0f672f62019-12-10 10:32:29 +000052#ifdef CONFIG_GENERIC_BUG
53#define __BUG_FLAGS(flags) \
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000054do { \
55 __asm__ __volatile__ ( \
56 "1:\n\t" \
57 "ebreak\n" \
David Brazdil0f672f62019-12-10 10:32:29 +000058 ".pushsection __bug_table,\"aw\"\n\t" \
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000059 "2:\n\t" \
60 __BUG_ENTRY "\n\t" \
David Brazdil0f672f62019-12-10 10:32:29 +000061 ".org 2b + %3\n\t" \
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000062 ".popsection" \
63 : \
64 : "i" (__FILE__), "i" (__LINE__), \
David Brazdil0f672f62019-12-10 10:32:29 +000065 "i" (flags), \
66 "i" (sizeof(struct bug_entry))); \
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000067} while (0)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000068#else /* CONFIG_GENERIC_BUG */
David Brazdil0f672f62019-12-10 10:32:29 +000069#define __BUG_FLAGS(flags) do { \
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000070 __asm__ __volatile__ ("ebreak\n"); \
David Brazdil0f672f62019-12-10 10:32:29 +000071} while (0)
72#endif /* CONFIG_GENERIC_BUG */
73
74#define BUG() do { \
75 __BUG_FLAGS(0); \
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000076 unreachable(); \
77} while (0)
David Brazdil0f672f62019-12-10 10:32:29 +000078
79#define __WARN_FLAGS(flags) __BUG_FLAGS(BUGFLAG_WARNING|(flags))
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000080
81#define HAVE_ARCH_BUG
82
83#include <asm-generic/bug.h>
84
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000085struct pt_regs;
86struct task_struct;
87
David Brazdil0f672f62019-12-10 10:32:29 +000088void die(struct pt_regs *regs, const char *str);
89void do_trap(struct pt_regs *regs, int signo, int code, unsigned long addr);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000090
91#endif /* _ASM_RISCV_BUG_H */