zephyr/arch/sparc/core/window_trap.S
Martin Åberg 07160fa153 arch: Add SPARC processor architecture
SPARC is an open and royalty free processor architecture.

This commit provides SPARC architecture support to Zephyr. It is
compatible with the SPARC V8 specification and the SPARC ABI and is
independent of processor implementation.

Functionality specific to SPRAC processor implementations should
go in soc/sparc. One example is the LEON3 SOC which is part of this
patch set.

The architecture port is fully SPARC ABI compatible, including trap
handlers and interrupt context.

Number of implemented register windows can be configured.

Some SPARC V8 processors borrow the CASA (compare-and-swap) atomic
instructions from SPARC V9. An option has been defined in the
architecture port to forward the corresponding code-generation option
to the compiler.

Stack size related config options have been defined in sparc/Kconfig
to match the SPARC ABI.

Co-authored-by: Nikolaus Huber <nikolaus.huber.melk@gmail.com>
Signed-off-by: Martin Åberg <martin.aberg@gaisler.com>
2020-11-13 14:53:55 -08:00

76 lines
1.6 KiB
ArmAsm

/*
* Copyright (c) 2019-2020 Cobham Gaisler AB
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* This file contains standard handlers for the SPARC V8 window overflow and
* underflow traps.
*/
#include <toolchain.h>
#include <linker/sections.h>
GTEXT(__sparc_trap_window_overflow)
GTEXT(__sparc_trap_window_underflow)
SECTION_FUNC(TEXT, __sparc_trap_window_overflow)
/* Enter the window to be stored. */
save
/* Save local register set. */
std %l0, [%sp + 0x00]
std %l2, [%sp + 0x08]
std %l4, [%sp + 0x10]
rd %wim, %l3
std %l6, [%sp + 0x18]
/* l2 := WIM << (NWIN-1) */
sll %l3, (CONFIG_SPARC_NWIN-1), %l2
/* Save input register set. */
std %i0, [%sp + 0x20]
/* l3 := WIM >> 1 */
srl %l3, 1, %l3
std %i2, [%sp + 0x28]
/* WIM := (WIM >> 1) ^ (WIM << (NWIN-1)) */
wr %l3, %l2, %wim
/* NOTE: 3 instruction before restore (delayed write instruction) */
std %i4, [%sp + 0x30]
nop
std %i6, [%sp + 0x38]
/* Go back to trap window. */
restore
/* Re-execute save. */
jmp %l1
rett %l2
SECTION_FUNC(TEXT, __sparc_trap_window_underflow)
rd %wim, %l3
/* l4 := WIM << 1 */
sll %l3, 1, %l4
/* l5 := WIM >> (NWIN-1) */
srl %l3, (CONFIG_SPARC_NWIN-1), %l5
/* WIM := (WIM << 1) ^ (WIM >> (NWIN-1)) */
wr %l4, %l5, %wim
/* WIM is implicitly read so nops are needed. */
nop
nop
nop
/* Enter the window to restore requires two restore instructions. */
restore
restore
ldd [%sp + 0x00], %l0
ldd [%sp + 0x08], %l2
ldd [%sp + 0x10], %l4
ldd [%sp + 0x18], %l6
ldd [%sp + 0x20], %i0
ldd [%sp + 0x28], %i2
ldd [%sp + 0x30], %i4
ldd [%sp + 0x38], %i6
/* Go back to the trap window. */
save
save
/* Re-execute restore. */
jmp %l1
rett %l2