summaryrefslogtreecommitdiffstats
path: root/data/sysrom/include/sys/cpu.h
blob: 818eb5b15c011e36cd7d9a6160a660d709905380 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef _SYS_CPU_H
#define _SYS_CPU_H

/*
 * Motorola 68000 CPU functions
 */

#include <stdint.h>

static inline uint16_t cpu_get_status(void)
{
	uint16_t __v;
	asm volatile("move %%sr,%0" : "=g" (__v));
	return __v;
}

static inline void cpu_set_status(uint16_t __v)
{
	asm volatile("move %0,%%sr" : : "g" (__v));
}

static inline unsigned int cpu_get_spl(void)
{
	return (cpu_get_status() >> 8) & 7;
}

static inline void cpu_set_spl(unsigned int __v)
{
	__v &= 7;
	if (__builtin_constant_p(__v)) {
		switch (__v) {
		case 0:
			asm volatile("andi #~0x700,%sr");
			break;
		case 7:
			asm volatile("ori #0x700,%sr");
			break;
		default:
			/*
			 * Always OR first, then AND, to make sure we
			 * never run at a *lower* SPL than we should be
			 */
			asm volatile("ori %0,%%sr ; andi %1,%%sr"
				     : : "i" (__v << 8), "i" (~(__v << 8)));
			break;
		}
	} else {
		uint16_t __sr;

		__sr = cpu_get_status();
		__sr &= ~0x700;
		__sr |= __v << 8;
		cpu_set_status(__sr);
	}
}

typedef void (*__ivt_entry_t)(void);
extern __ivt_entry_t __ivt[256];

#endif /* _SYS_CPU_H */