1 /* $OpenBSD: asm_macro.h,v 1.11 2024/06/26 01:40:49 jsg Exp $ */
2 /*
3 * Mach Operating System
4 * Copyright (c) 1993-1991 Carnegie Mellon University
5 * Copyright (c) 1991 OMRON Corporation
6 * All Rights Reserved.
7 *
8 * Permission to use, copy, modify and distribute this software and its
9 * documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation.
13 *
14 * CARNEGIE MELLON AND OMRON ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 * CONDITION. CARNEGIE MELLON AND OMRON DISCLAIM ANY LIABILITY OF ANY KIND
16 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 *
18 * Carnegie Mellon requests users of this software to return to
19 *
20 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
24 *
25 * any improvements or extensions that they make and grant Carnegie the
26 * rights to redistribute these changes.
27 */
28
29 #ifndef _M88K_ASM_MACRO_H_
30 #define _M88K_ASM_MACRO_H_
31
32 /*
33 * Various compiler macros used for speed and efficiency.
34 * Anyone can include.
35 */
36
37 /*
38 * Flush the data pipeline.
39 */
40 #define flush_pipeline() \
41 __asm__ volatile ("tb1 0, %%r0, 0" ::: "memory")
42
43 /*
44 * Set the PSR.
45 */
46 static __inline__ void
set_psr(u_int psr)47 set_psr(u_int psr)
48 {
49 __asm__ volatile ("stcr %0, %%cr1" :: "r" (psr));
50 flush_pipeline();
51 }
52
53 /*
54 * Get the PSR.
55 */
56 static __inline__ u_int
get_psr(void)57 get_psr(void)
58 {
59 u_int psr;
60 __asm__ volatile ("ldcr %0, %%cr1" : "=r" (psr));
61 return (psr);
62 }
63
64 /*
65 * Provide access from C code to the assembly instruction ff1
66 */
67 static __inline__ u_int
ff1(u_int val)68 ff1(u_int val)
69 {
70 __asm__ volatile ("ff1 %0, %0" : "=r" (val) : "0" (val));
71 return (val);
72 }
73
74 static __inline__ u_int
get_cpu_pid(void)75 get_cpu_pid(void)
76 {
77 u_int pid;
78 __asm__ volatile ("ldcr %0, %%cr0" : "=r" (pid));
79 return (pid);
80 }
81
82 #endif /* _M88K_ASM_MACRO_H_ */
83