162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * traps.h:  Format of entries for the Sparc trap table.
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#ifndef _UAPI_SPARC_TRAPS_H
962306a36Sopenharmony_ci#define _UAPI_SPARC_TRAPS_H
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#define NUM_SPARC_TRAPS  255
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#ifndef __ASSEMBLY__
1462306a36Sopenharmony_ci#endif /* !(__ASSEMBLY__) */
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci/* For patching the trap table at boot time, we need to know how to
1762306a36Sopenharmony_ci * form various common Sparc instructions.  Thus these macros...
1862306a36Sopenharmony_ci */
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci#define SPARC_MOV_CONST_L3(const) (0xa6102000 | (const&0xfff))
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci/* The following assumes that the branch lies before the place we
2362306a36Sopenharmony_ci * are branching to.  This is the case for a trap vector...
2462306a36Sopenharmony_ci * You have been warned.
2562306a36Sopenharmony_ci */
2662306a36Sopenharmony_ci#define SPARC_BRANCH(dest_addr, inst_addr) \
2762306a36Sopenharmony_ci          (0x10800000 | (((dest_addr-inst_addr)>>2)&0x3fffff))
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci#define SPARC_RD_PSR_L0  (0xa1480000)
3062306a36Sopenharmony_ci#define SPARC_RD_WIM_L3  (0xa7500000)
3162306a36Sopenharmony_ci#define SPARC_NOP (0x01000000)
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci/* Various interesting trap levels. */
3462306a36Sopenharmony_ci/* First, hardware traps. */
3562306a36Sopenharmony_ci#define SP_TRAP_TFLT    0x1          /* Text fault */
3662306a36Sopenharmony_ci#define SP_TRAP_II      0x2          /* Illegal Instruction */
3762306a36Sopenharmony_ci#define SP_TRAP_PI      0x3          /* Privileged Instruction */
3862306a36Sopenharmony_ci#define SP_TRAP_FPD     0x4          /* Floating Point Disabled */
3962306a36Sopenharmony_ci#define SP_TRAP_WOVF    0x5          /* Window Overflow */
4062306a36Sopenharmony_ci#define SP_TRAP_WUNF    0x6          /* Window Underflow */
4162306a36Sopenharmony_ci#define SP_TRAP_MNA     0x7          /* Memory Address Unaligned */
4262306a36Sopenharmony_ci#define SP_TRAP_FPE     0x8          /* Floating Point Exception */
4362306a36Sopenharmony_ci#define SP_TRAP_DFLT    0x9          /* Data Fault */
4462306a36Sopenharmony_ci#define SP_TRAP_TOF     0xa          /* Tag Overflow */
4562306a36Sopenharmony_ci#define SP_TRAP_WDOG    0xb          /* Watchpoint Detected */
4662306a36Sopenharmony_ci#define SP_TRAP_IRQ1    0x11         /* IRQ level 1 */
4762306a36Sopenharmony_ci#define SP_TRAP_IRQ2    0x12         /* IRQ level 2 */
4862306a36Sopenharmony_ci#define SP_TRAP_IRQ3    0x13         /* IRQ level 3 */
4962306a36Sopenharmony_ci#define SP_TRAP_IRQ4    0x14         /* IRQ level 4 */
5062306a36Sopenharmony_ci#define SP_TRAP_IRQ5    0x15         /* IRQ level 5 */
5162306a36Sopenharmony_ci#define SP_TRAP_IRQ6    0x16         /* IRQ level 6 */
5262306a36Sopenharmony_ci#define SP_TRAP_IRQ7    0x17         /* IRQ level 7 */
5362306a36Sopenharmony_ci#define SP_TRAP_IRQ8    0x18         /* IRQ level 8 */
5462306a36Sopenharmony_ci#define SP_TRAP_IRQ9    0x19         /* IRQ level 9 */
5562306a36Sopenharmony_ci#define SP_TRAP_IRQ10   0x1a         /* IRQ level 10 */
5662306a36Sopenharmony_ci#define SP_TRAP_IRQ11   0x1b         /* IRQ level 11 */
5762306a36Sopenharmony_ci#define SP_TRAP_IRQ12   0x1c         /* IRQ level 12 */
5862306a36Sopenharmony_ci#define SP_TRAP_IRQ13   0x1d         /* IRQ level 13 */
5962306a36Sopenharmony_ci#define SP_TRAP_IRQ14   0x1e         /* IRQ level 14 */
6062306a36Sopenharmony_ci#define SP_TRAP_IRQ15   0x1f         /* IRQ level 15 Non-maskable */
6162306a36Sopenharmony_ci#define SP_TRAP_RACC    0x20         /* Register Access Error ??? */
6262306a36Sopenharmony_ci#define SP_TRAP_IACC    0x21         /* Instruction Access Error */
6362306a36Sopenharmony_ci#define SP_TRAP_CPDIS   0x24         /* Co-Processor Disabled */
6462306a36Sopenharmony_ci#define SP_TRAP_BADFL   0x25         /* Unimplemented Flush Instruction */
6562306a36Sopenharmony_ci#define SP_TRAP_CPEXP   0x28         /* Co-Processor Exception */
6662306a36Sopenharmony_ci#define SP_TRAP_DACC    0x29         /* Data Access Error */
6762306a36Sopenharmony_ci#define SP_TRAP_DIVZ    0x2a         /* Divide By Zero */
6862306a36Sopenharmony_ci#define SP_TRAP_DSTORE  0x2b         /* Data Store Error ??? */
6962306a36Sopenharmony_ci#define SP_TRAP_DMM     0x2c         /* Data Access MMU Miss ??? */
7062306a36Sopenharmony_ci#define SP_TRAP_IMM     0x3c         /* Instruction Access MMU Miss ??? */
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci/* Now the Software Traps... */
7362306a36Sopenharmony_ci#define SP_TRAP_SUNOS   0x80         /* SunOS System Call */
7462306a36Sopenharmony_ci#define SP_TRAP_SBPT    0x81         /* Software Breakpoint */
7562306a36Sopenharmony_ci#define SP_TRAP_SDIVZ   0x82         /* Software Divide-by-Zero trap */
7662306a36Sopenharmony_ci#define SP_TRAP_FWIN    0x83         /* Flush Windows */
7762306a36Sopenharmony_ci#define SP_TRAP_CWIN    0x84         /* Clean Windows */
7862306a36Sopenharmony_ci#define SP_TRAP_RCHK    0x85         /* Range Check */
7962306a36Sopenharmony_ci#define SP_TRAP_FUNA    0x86         /* Fix Unaligned Access */
8062306a36Sopenharmony_ci#define SP_TRAP_IOWFL   0x87         /* Integer Overflow */
8162306a36Sopenharmony_ci#define SP_TRAP_SOLARIS 0x88         /* Solaris System Call */
8262306a36Sopenharmony_ci#define SP_TRAP_NETBSD  0x89         /* NetBSD System Call */
8362306a36Sopenharmony_ci#define SP_TRAP_LINUX   0x90         /* Linux System Call */
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci/* Names used for compatibility with SunOS */
8662306a36Sopenharmony_ci#define ST_SYSCALL              0x00
8762306a36Sopenharmony_ci#define ST_BREAKPOINT           0x01
8862306a36Sopenharmony_ci#define ST_DIV0                 0x02
8962306a36Sopenharmony_ci#define ST_FLUSH_WINDOWS        0x03
9062306a36Sopenharmony_ci#define ST_CLEAN_WINDOWS        0x04
9162306a36Sopenharmony_ci#define ST_RANGE_CHECK          0x05
9262306a36Sopenharmony_ci#define ST_FIX_ALIGN            0x06
9362306a36Sopenharmony_ci#define ST_INT_OVERFLOW         0x07
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci/* Special traps... */
9662306a36Sopenharmony_ci#define SP_TRAP_KBPT1   0xfe         /* KADB/PROM Breakpoint one */
9762306a36Sopenharmony_ci#define SP_TRAP_KBPT2   0xff         /* KADB/PROM Breakpoint two */
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci/* Handy Macros */
10062306a36Sopenharmony_ci/* Is this a trap we never expect to get? */
10162306a36Sopenharmony_ci#define BAD_TRAP_P(level) \
10262306a36Sopenharmony_ci        ((level > SP_TRAP_WDOG && level < SP_TRAP_IRQ1) || \
10362306a36Sopenharmony_ci	 (level > SP_TRAP_IACC && level < SP_TRAP_CPDIS) || \
10462306a36Sopenharmony_ci	 (level > SP_TRAP_BADFL && level < SP_TRAP_CPEXP) || \
10562306a36Sopenharmony_ci	 (level > SP_TRAP_DMM && level < SP_TRAP_IMM) || \
10662306a36Sopenharmony_ci	 (level > SP_TRAP_IMM && level < SP_TRAP_SUNOS) || \
10762306a36Sopenharmony_ci	 (level > SP_TRAP_LINUX && level < SP_TRAP_KBPT1))
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ci/* Is this a Hardware trap? */
11062306a36Sopenharmony_ci#define HW_TRAP_P(level) ((level > 0) && (level < SP_TRAP_SUNOS))
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci/* Is this a Software trap? */
11362306a36Sopenharmony_ci#define SW_TRAP_P(level) ((level >= SP_TRAP_SUNOS) && (level <= SP_TRAP_KBPT2))
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci/* Is this a system call for some OS we know about? */
11662306a36Sopenharmony_ci#define SCALL_TRAP_P(level) ((level == SP_TRAP_SUNOS) || \
11762306a36Sopenharmony_ci			     (level == SP_TRAP_SOLARIS) || \
11862306a36Sopenharmony_ci			     (level == SP_TRAP_NETBSD) || \
11962306a36Sopenharmony_ci			     (level == SP_TRAP_LINUX))
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci#endif /* _UAPI_SPARC_TRAPS_H */
122