#ifndef __ASM_BUG_H
 #define __ASM_BUG_H
 
-#include <linux/compiler.h>
+#include <asm/break.h>
+#include <linux/stringify.h>
+
+#ifndef CONFIG_DEBUG_BUGVERBOSE
+#define _BUGVERBOSE_LOCATION(file, line)
+#else
+#define __BUGVERBOSE_LOCATION(file, line)                      \
+               .pushsection .rodata.str, "aMS", @progbits, 1;  \
+       10002:  .string file;                                   \
+               .popsection;                                    \
+                                                               \
+               .long 10002b - .;                               \
+               .short line;
+#define _BUGVERBOSE_LOCATION(file, line) __BUGVERBOSE_LOCATION(file, line)
+#endif
 
-#ifdef CONFIG_BUG
+#ifndef CONFIG_GENERIC_BUG
+#define __BUG_ENTRY(flags)
+#else
+#define __BUG_ENTRY(flags)                                     \
+               .pushsection __bug_table, "aw";                 \
+               .align 2;                                       \
+       10000:  .long 10001f - .;                               \
+               _BUGVERBOSE_LOCATION(__FILE__, __LINE__)        \
+               .short flags;                                   \
+               .popsection;                                    \
+       10001:
+#endif
 
-#include <asm/break.h>
+#define ASM_BUG_FLAGS(flags)                                   \
+       __BUG_ENTRY(flags)                                      \
+       break           BRK_BUG
 
-static inline void __noreturn BUG(void)
-{
-       __asm__ __volatile__("break %0" : : "i" (BRK_BUG));
-       unreachable();
-}
+#define ASM_BUG()      ASM_BUG_FLAGS(0)
 
-#define HAVE_ARCH_BUG
+#define __BUG_FLAGS(flags)                                     \
+       asm_inline volatile (__stringify(ASM_BUG_FLAGS(flags)));
 
-#endif
+#define __WARN_FLAGS(flags)                                    \
+do {                                                           \
+       instrumentation_begin();                                \
+       __BUG_FLAGS(BUGFLAG_WARNING|(flags));                   \
+       instrumentation_end();                                  \
+} while (0)
+
+#define BUG()                                                  \
+do {                                                           \
+       instrumentation_begin();                                \
+       __BUG_FLAGS(0);                                         \
+       unreachable();                                          \
+} while (0)
+
+#define HAVE_ARCH_BUG
 
 #include <asm-generic/bug.h>
 
 
 #include <asm/addrspace.h>
 #include <asm/asm.h>
 #include <asm/asmmacro.h>
+#include <asm/bug.h>
 #include <asm/regdef.h>
 #include <asm/loongarch.h>
 #include <asm/stackframe.h>
        PTR_ADDI        sp, sp, -4 * SZREG      # init stack pointer
 
        bl              start_kernel
+       ASM_BUG()
 
 SYM_CODE_END(kernel_entry)
 
        ld.d            tp, t0, CPU_BOOT_TINFO
 
        bl              start_secondary
+       ASM_BUG()
+
 SYM_CODE_END(smpboot_entry)
 
 #endif /* CONFIG_SMP */
 
        irqentry_exit(regs, state);
 }
 
+#ifdef CONFIG_GENERIC_BUG
+int is_valid_bugaddr(unsigned long addr)
+{
+       return 1;
+}
+#endif /* CONFIG_GENERIC_BUG */
+
+static void bug_handler(struct pt_regs *regs)
+{
+       switch (report_bug(regs->csr_era, regs)) {
+       case BUG_TRAP_TYPE_BUG:
+       case BUG_TRAP_TYPE_NONE:
+               die_if_kernel("Oops - BUG", regs);
+               force_sig(SIGTRAP);
+               break;
+
+       case BUG_TRAP_TYPE_WARN:
+               /* Skip the BUG instruction and continue */
+               regs->csr_era += LOONGARCH_INSN_SIZE;
+               break;
+       }
+}
+
 asmlinkage void noinstr do_bp(struct pt_regs *regs)
 {
        bool user = user_mode(regs);
 
        switch (bcode) {
        case BRK_BUG:
-               die_if_kernel("Kernel bug detected", regs);
-               force_sig(SIGTRAP);
+               bug_handler(regs);
                break;
        case BRK_DIVZERO:
                die_if_kernel("Break instruction in kernel code", regs);