xref: /plan9/sys/src/9/teg2/notes/byte-order (revision 3de6a9c0b3d5cf34fc4090d0bf1930d83799a7fd)
1static void
2forcele(void)
3{
4#ifdef BIGENDCHECK
5	union {
6		ulong 	ul;
7		uchar	uc[sizeof(ulong)];
8	} u;
9
10	u.ul = 0;
11	coherence();
12	u.uc[0] = 1;
13	coherence();
14	if (u.ul == 1)
15		return;
16
17	emerge('?');
18	emerge('e');
19	if ((u.ul & MASK(8)) == 0) {
20		emerge('B');
21		panic("rdbaseticks: cpu%d is big-endian", m->machno);
22	} else {
23		emerge('W');
24		panic("rdbaseticks: cpu%d is whacked-endian", m->machno);
25	}
26#endif
27}
28
29void
30ckbigendian(char *state)
31{
32	int wrong;
33
34	wrong = 0;
35	if (getpsr() & PsrBigend) {
36		setendlittle();
37		wrong++;
38		wave('?');
39		wave('e');
40		wave('p');
41		if (state == nil)
42			state = "running";
43		iprint("cpu%d: %s in big-endian mode\n", m->machno, state);
44	}
45	if (controlget() & CpCee) {
46		wrong++;
47		wave('?');
48		wave('e');
49		wave('e');
50		if (state == nil)
51			state = "running";
52		iprint("cpu%d: %s with big-endian exceptions\n", m->machno, state);
53	}
54	if (wrong) {
55		dumpstack();
56		delay(3000);
57		panic("cpu%d: big-endian", m->machno);
58	}
59}
60