Plan 9 from Bell Labs’s /usr/web/sources/contrib/rsc/8i/reg.c

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


#include <u.h>
#include <libc.h>
#include "8i.h"

static struct
{
	char 	*s;
	int i;
} ra[] = {
	"ax",	RAX,
	"bx", RBX,
	"cx",	RCX,
	"dx",	RDX,
	"si",	RSI,
	"di",	RDI,
	"bp", RBP,
	"sp",	RSP,
	"cs",	RCS,
	"ss",	RSS,
	"ds",	RDS,
	"es",	RES,
	"pc",	-1,
	0,	0
};

void
sreg(Cpu *cpu, char **av, int na)
{
	int i;
	long val;
	char *p;

	if(na != 3)
		sysfatal("r <name> <value>");

	val = strtoul(av[2], &p, 16);
	if(p == av[2])
		sysfatal("bad hex input");

	if(strcmp("pc", av[1]) == 0){
		cpu->pc = val;
		return;
	}
	for(i = 0; ra[i].s; i++){
		if(strcmp(ra[i].s, av[1]) == 0){
			cpu->reg[ra[i].i] = val;
			return;
		}
	}
	sysfatal("bad register '%s'", av[1]);
}

void
dumpreg(Cpu *cpu)
{
	int j;
	char buf[1024];

	j = sprint(buf, "\nAX=%4.4luX  BX=%4.4luX  CX=%4.4luX  DX=%4.4luX  ",
				cpu->reg[RAX], cpu->reg[RBX], cpu->reg[RCX], cpu->reg[RDX]);
	j += sprint(buf+j, "SP=%4.4luX  BP=%4.4luX  SI=%4.4luX  DI=%4.4luX\n",
				cpu->reg[RSP], cpu->reg[RBP], cpu->reg[RSI], cpu->reg[RDI]);
	j += sprint(buf+j, "DS=%4.4luX  ES=%4.4luX  SS=%4.4luX  CS=%4.4luX  ",
				cpu->reg[RDS], cpu->reg[RES], cpu->reg[RSS], cpu->reg[RCS]);
	j += sprint(buf+j, "IP=%4.4luX   ", cpu->pc);
	if(cpu->flags & OF)
		j += sprint(buf+j, "OV ");
	else
		j += sprint(buf+j, "NV ");
	if(cpu->flags & DF)
		j += sprint(buf+j, "DN ");
	else
		j += sprint(buf+j, "UP ");
	if(cpu->flags & IF)
		j += sprint(buf+j, "EI ");
	else
		j += sprint(buf+j, "DI ");
	if(cpu->flags & SF)
		j += sprint(buf+j, "NG ");
	else
		j += sprint(buf+j, "PL ");
	if(cpu->flags & ZF)
		j += sprint(buf+j, "ZR ");
	else
		j += sprint(buf+j, "NZ ");
	if(cpu->flags & AF)
		j += sprint(buf+j, "AF ");
	else
		j += sprint(buf+j, "NA ");
	if(cpu->flags & PF)
		j += sprint(buf+j, "PE ");
	else
		j += sprint(buf+j, "PO ");
	if(cpu->flags & CF)
		sprint(buf+j, "CY\n");
	else
		sprint(buf+j, "NC\n");
	print("%s", buf);
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.