haiku/headers/private/kernel/arch/sparc/arch_int.h
PulkoMandy 0da81fed54 sparc: fix interrupt enable/disable code
The manually written code was all wrong (missing branch delay slots,
wrong type of return instruction used, probably more bugs). Use the same
approach as x86 to have inline functions instead, which is much better
for performance and simpler to write.

Change-Id: Iac0fc814c15311658f983da58ac7f9d3edd75b81
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3595
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2021-01-01 22:04:13 +00:00

76 lines
1.5 KiB
C

/*
* Copyright 2005-2021, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Axel Dörfler <axeld@pinc-software.de>
* Ingo Weinhold <bonefish@cs.tu-berlin.de>
* Adrien Destugues <pulkomandy@pulkomandy.tk>
*/
#ifndef _KERNEL_ARCH_SPARC_INT_H
#define _KERNEL_ARCH_SPARC_INT_H
#include <SupportDefs.h>
#define NUM_IO_VECTORS 256
static inline void
arch_int_enable_interrupts_inline(void)
{
int tmp;
asm volatile(
"rdpr %%pstate, %0\n"
"or %0, 2, %0\n"
"wrpr %0, %%pstate\n"
: "=r" (tmp)
);
}
static inline int
arch_int_disable_interrupts_inline(void)
{
int flags;
int tmp;
asm volatile(
"rdpr %%pstate, %0\n"
"andn %0, 2, %1\n"
"wrpr %1, %%pstate\n"
: "=r" (flags), "=r" (tmp)
);
return flags & 2;
}
static inline void
arch_int_restore_interrupts_inline(int oldState)
{
if (oldState)
arch_int_enable_interrupts_inline();
}
static inline bool
arch_int_are_interrupts_enabled_inline(void)
{
int flags;
asm volatile(
"rdpr %%pstate, %0\n"
: "=r" (flags)
);
return flags & 2;
}
// map the functions to the inline versions
#define arch_int_enable_interrupts() arch_int_enable_interrupts_inline()
#define arch_int_disable_interrupts() arch_int_disable_interrupts_inline()
#define arch_int_restore_interrupts(status) \
arch_int_restore_interrupts_inline(status)
#define arch_int_are_interrupts_enabled() \
arch_int_are_interrupts_enabled_inline()
#endif /* _KERNEL_ARCH_SPARC_INT_H */