Plan 9 from Bell Labs’s /usr/web/sources/plan9/sys/src/9/teg2/notes/byte-order

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


static void
forcele(void)
{
#ifdef BIGENDCHECK
	union {
		ulong 	ul;
		uchar	uc[sizeof(ulong)];
	} u;

	u.ul = 0;
	coherence();
	u.uc[0] = 1;
	coherence();
	if (u.ul == 1)
		return;

	emerge('?');
	emerge('e');
	if ((u.ul & MASK(8)) == 0) {
		emerge('B');
		panic("rdbaseticks: cpu%d is big-endian", m->machno);
	} else {
		emerge('W');
		panic("rdbaseticks: cpu%d is whacked-endian", m->machno);
	}
#endif
}

void
ckbigendian(char *state)
{
	int wrong;

	wrong = 0;
	if (getpsr() & PsrBigend) {
		setendlittle();
		wrong++;
		wave('?');
		wave('e');
		wave('p');
		if (state == nil)
			state = "running";
		iprint("cpu%d: %s in big-endian mode\n", m->machno, state);
	}
	if (controlget() & CpCee) {
		wrong++;
		wave('?');
		wave('e');
		wave('e');
		if (state == nil)
			state = "running";
		iprint("cpu%d: %s with big-endian exceptions\n", m->machno, state);
	}
	if (wrong) {
		dumpstack();
		delay(3000);
		panic("cpu%d: big-endian", m->machno);
	}
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].