zephyr/include/arch/sparc/arch.h
Martin Åberg 83f733ce59 SPARC: improve fatal log
The fatal log now contains
- Trap type in human readable representation
- Integer registers visible to the program when trap was taken
- Special register values such as PC and PSR
- Backtrace with PC and SP

If CONFIG_EXTRA_EXCEPTION_INFO is enabled, then all the above is
logged. If not, only the special registers are logged.

The format is inspired by the GRMON debug monitor and TSIM simulator.
A quick guide on how to use the values is in fatal.c.

It now looks like this:

E: tt = 0x02, illegal_instruction
E:
E:       INS        LOCALS     OUTS       GLOBALS
E:   0:  00000000   f3900fc0   40007c50   00000000
E:   1:  00000000   40004bf0   40008d30   40008c00
E:   2:  00000000   40004bf4   40008000   00000003
E:   3:  40009158   00000000   40009000   00000002
E:   4:  40008fa8   40003c00   40008fa8   00000008
E:   5:  40009000   f3400fc0   00000000   00000080
E:   6:  4000a1f8   40000050   4000a190   00000000
E:   7:  40002308   00000000   40001fb8   000000c1
E:
E: psr: f30000c7   wim: 00000008   tbr: 40000020   y: 00000000
E:  pc: 4000a1f4   npc: 4000a1f8
E:
E:       pc         sp
E:  #0   4000a1f4   4000a190
E:  #1   40002308   4000a1f8
E:  #2   40003b24   4000a258

Signed-off-by: Martin Åberg <martin.aberg@gaisler.com>
2021-03-25 17:48:23 +01:00

136 lines
2.8 KiB
C

/*
* Copyright (c) 2019-2020 Cobham Gaisler AB
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief SPARC specific kernel interface header
* This header contains the SPARC specific kernel interface. It is
* included by the generic kernel interface header (arch/cpu.h)
*/
#ifndef ZEPHYR_INCLUDE_ARCH_SPARC_ARCH_H_
#define ZEPHYR_INCLUDE_ARCH_SPARC_ARCH_H_
#include <arch/sparc/thread.h>
#include <arch/sparc/sparc.h>
#include <arch/common/sys_bitops.h>
#include <arch/common/sys_io.h>
#include <arch/common/ffs.h>
#include <irq.h>
#include <sw_isr_table.h>
#include <soc.h>
#include <devicetree.h>
/* stacks, for SPARC architecture stack shall be 8byte-aligned */
#define ARCH_STACK_PTR_ALIGN 8
/*
* Software trap numbers.
* Assembly usage: "ta SPARC_SW_TRAP_<TYPE>"
*/
#define SPARC_SW_TRAP_FLUSH_WINDOWS 0x03
#define SPARC_SW_TRAP_SET_PIL 0x09
#define SPARC_SW_TRAP_EXCEPT 0x0F
#ifndef _ASMLANGUAGE
#include <sys/util.h>
#ifdef __cplusplus
extern "C" {
#endif
#define STACK_ROUND_UP(x) ROUND_UP(x, ARCH_STACK_PTR_ALIGN)
/*
* SOC specific function to translate from processor interrupt request level
* (1..15) to logical interrupt source number. For example by probing the
* interrupt controller.
*/
int z_sparc_int_get_source(int irl);
void z_irq_spurious(const void *unused);
#define ARCH_IRQ_CONNECT(irq_p, priority_p, isr_p, isr_param_p, flags_p) \
{ \
Z_ISR_DECLARE(irq_p, 0, isr_p, isr_param_p); \
}
static ALWAYS_INLINE unsigned int z_sparc_set_pil_inline(unsigned int newpil)
{
register uint32_t oldpil __asm__ ("o0") = newpil;
__asm__ volatile (
"ta %1\nnop\n" :
"=r" (oldpil) :
"i" (SPARC_SW_TRAP_SET_PIL), "r" (oldpil) :
"memory"
);
return oldpil;
}
static ALWAYS_INLINE unsigned int arch_irq_lock(void)
{
return z_sparc_set_pil_inline(15);
}
static ALWAYS_INLINE void arch_irq_unlock(unsigned int key)
{
z_sparc_set_pil_inline(key);
}
static ALWAYS_INLINE bool arch_irq_unlocked(unsigned int key)
{
return key == 0;
}
static ALWAYS_INLINE void arch_nop(void)
{
__asm__ volatile ("nop");
}
extern uint32_t sys_clock_cycle_get_32(void);
static inline uint32_t arch_k_cycle_get_32(void)
{
return sys_clock_cycle_get_32();
}
struct __esf {
uint32_t out[8];
uint32_t global[8];
uint32_t psr;
uint32_t pc;
uint32_t npc;
uint32_t wim;
uint32_t tbr;
uint32_t y;
};
typedef struct __esf z_arch_esf_t;
#define ARCH_EXCEPT(reason_p) \
do { \
register uint32_t _g1 __asm__("g1") = reason_p; \
\
__asm__ volatile ( \
"ta %[vector]\n\t" \
: \
: [vector] "i" (SPARC_SW_TRAP_EXCEPT), "r" (_g1) \
: "memory" \
); \
CODE_UNREACHABLE; \
} while (false)
#ifdef __cplusplus
}
#endif
#endif /*_ASMLANGUAGE */
#endif /* ZEPHYR_INCLUDE_ARCH_SPARC_ARCH_H_ */