ms_iprint.c 1.87 KB
/*
 * Copyright (C) 1996-1998 by the Board of Trustees
 *    of Leland Stanford Junior University.
 * 
 * This file is part of the SimOS distribution. 
 * See LICENSE file for terms of the license. 
 *
 */


	/*
	 *  ms_iprint  -  Print out a mips instruction
	 *
	 *	Jim Bennett
	 *	1993, 1994
	 */

#include <stdio.h>
#include "ms.h"

void print_inst (FILE *stream, INST *ip)
	{
	int	need_comma = 0;

	fprintf (stream, "%s ", opcode_mnemonics[ip->op]);
	if (ip->r1 != -1)
		{
		print_reg (stream, ip->r1);
		fprintf (stream, " = ");
		}
	if (ip->r2 != -1)
		{
		print_reg (stream, ip->r2);
		need_comma = 1;
		}
	if (ip->r3 != -1)
		{
		if (need_comma) fprintf (stream, ", ");
		print_reg (stream, ip->r3);
		need_comma = 1;
		}
	if (need_comma) fprintf (stream, ", ");
	fprintf (stream, "0x%x", ip->imm);
	}


	/*
	 *  print_reg  -  Print out the name of the register to the
	 *		  given output stream.
	 */

void print_reg (FILE *stream, int r)
	{
	if (r < 0)
		fprintf (stream, "XXX");
	else if (r < FPREG)
		{
		if (r == SP)
			fprintf (stream, "SP");
		else if (r == LP)
			fprintf (stream, "LP");
		else
			fprintf (stream, "R%d", r);
		}
	else if (r < HILOREG)
		fprintf (stream, "F%d", r - FPREG);
	else if (r < FPCTL)
		fprintf (stream, (r == HIREG ? "HI" : "LO"));
	else if (r < TOT_REG)
		fprintf (stream, "C%d", r - FPCTL);
	else if (r < MAX_FP)
		fprintf (stream, "F%d", r);
	else
		fprintf (stream, "R%d", r);
	}


	/*
	 *  print_reg_contents  -  Print out register contents
	 */

void print_reg_contents (FILE *stream, int r, void *ptr)
	{
	if (r < 0)
		fprintf (stream, "XXX");
	else if (r < FPREG)
		fprintf (stream, "0x%8.8x", *(int *)ptr);
	else if (r < HILOREG)
		fprintf (stream, "%f", *(double *)ptr);
	else if (r < TOT_REG)
		fprintf (stream, "0x%8.8x", *(int *)ptr);
	else if (r < MAX_FP)
		fprintf (stream, "%f", *(double *)ptr);
	else
		fprintf (stream, "0x%8.8x", *(int *)ptr);
	}