Add convenience macros RAS_{START,END}_ASM() and RAS_{START,END}_ASM_HIDDEN()

to simplify coding RASs in assembly.
This commit is contained in:
scw 2008-04-29 20:50:42 +00:00
parent 5804d4a96d
commit ebbad0004d
1 changed files with 43 additions and 2 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ras.h,v 1.11 2008/04/28 20:24:11 martin Exp $ */
/* $NetBSD: ras.h,v 1.12 2008/04/29 20:50:42 scw Exp $ */
/*-
* Copyright (c) 2002, 2004, 2007 The NetBSD Foundation, Inc.
@ -32,6 +32,7 @@
#ifndef _SYS_RAS_H_
#define _SYS_RAS_H_
#ifndef __ASSEMBLER__
#include <sys/types.h>
#include <sys/queue.h>
@ -44,16 +45,21 @@ struct ras {
#define RAS_INSTALL 0
#define RAS_PURGE 1
#define RAS_PURGE_ALL 2
#else
#include <sys/cdefs.h>
#endif /* __ASSEMBLER__ */
#ifdef _KERNEL
#ifndef __ASSEMBLER__
struct proc;
void *ras_lookup(struct proc *, void *);
int ras_fork(struct proc *, struct proc *);
int ras_purgeall(void);
#endif /* __ASSEMBLER__ */
#else
#else /* !_KERNEL */
#ifndef RAS_DECL
@ -65,6 +71,9 @@ extern void __CONCAT(name,_ras_start(void)), __CONCAT(name,_ras_end(void))
/*
* RAS_START and RAS_END contain implicit instruction reordering
* barriers. See __insn_barrier() in <sys/cdefs.h>.
*
* Note: You are strongly advised to avoid coding RASs in C. There is a
* good chance the compiler will generate code which cannot be restarted.
*/
#define RAS_START(name) \
__asm volatile(".globl " ___STRING(name) "_ras_start\n" \
@ -80,10 +89,42 @@ extern void __CONCAT(name,_ras_start(void)), __CONCAT(name,_ras_end(void))
#define RAS_SIZE(name) ((size_t)((uintptr_t) __CONCAT(name,_ras_end) - \
(uintptr_t) __CONCAT(name,_ras_start)))
#ifndef __ASSEMBLER__
__BEGIN_DECLS
int rasctl(void *, size_t, int);
__END_DECLS
#else /* __ASSEMBLER__ */
/*
* RAS_START_ASM and RAS_END_ASM are for use within assembly code.
* This is the prefered method of coding a RAS.
*/
#define RAS_START_ASM(name) \
.globl _C_LABEL(__CONCAT(name,_ras_start)); \
_C_LABEL(__CONCAT(name,_ras_start)):
#define RAS_END_ASM(name) \
.globl _C_LABEL(__CONCAT(name,_ras_end)); \
_C_LABEL(__CONCAT(name,_ras_end)):
/*
* RAS_START_ASM_HIDDEN and RAS_END_ASM_HIDDEN are similar to the above,
* except that they limit the scope of the symbol such that it will not
* be placed into the dynamic symbol table. Thus no other module (executable
* or shared library) can reference it directly.
*/
#define RAS_START_ASM_HIDDEN(name) \
.globl _C_LABEL(__CONCAT(name,_ras_start)); \
.hidden _C_LABEL(__CONCAT(name,_ras_start)); \
_C_LABEL(__CONCAT(name,_ras_start)):
#define RAS_END_ASM_HIDDEN(name) \
.globl _C_LABEL(__CONCAT(name,_ras_end)); \
.hidden _C_LABEL(__CONCAT(name,_ras_start)); \
_C_LABEL(__CONCAT(name,_ras_end)):
#endif /* __ASSEMBLER__ */
#endif /* _KERNEL */
#endif /* !_SYS_RAS_H_ */