OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [or1k-1_0/] [or1ksim/] [cpu/] [common/] [abstract.c] - Rev 1778

Go to most recent revision | Compare with Previous | Blame | View Log

/* abstract.c -- Abstract entities
   Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
 
This file is part of OpenRISC 1000 Architectural Simulator.
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
/* Abstract memory and routines that goes with this. I need to
add all sorts of other abstract entities. Currently we have
only memory. */
 
#include <stdio.h>
#include <ctype.h>
#include <string.h>
 
#include "parse.h"
#include "abstract.h"
#include "arch.h"
#include "trace.h"
#include "execute.h"
 
extern unsigned long reg[];
 
/* This is an abstract memory array rather than physical memory array */
struct mem_entry mem[MEMORY_LEN];
 
void dumpmemory(unsigned int from, unsigned int to)
{
	unsigned int i;
 
	for(i = from; i < to; i++)
		if (strlen(mem[i].insn)) {
			printf("\n%.4x:  ", i);
			if (strlen(mem[i].label))
				printf("%s%s\n", mem[i].label, LABELEND_CHAR);
			printf("\t\t%s\t%s", mem[i].insn, mem[i].op1);
			if (strlen(mem[i].op2))
				printf("%s%s", OPERAND_DELIM, mem[i].op2);
			if (strlen(mem[i].op3))
				printf("%s%s", OPERAND_DELIM, mem[i].op3);
			if (strlen(mem[i].op4))
				printf("%s%s", OPERAND_DELIM, mem[i].op4);
			i += 3;	/* insn long 4 bytes */
		} else
		{
			if (i % 8 == 0)
				printf("\n%.4x:  ", i);
 
			/* don't print ascii chars below 0x20. */
			if (mem[i].data < 0x20)
				printf("0x%.2x     ", (unsigned char)mem[i].data);
			else
				printf("0x%.2x'%c'  ", (unsigned char)mem[i].data, mem[i].data);
 
		}
}
 
/* Searches mem array for a particular label and returns label's address.
   If label does not exist, returns 0. */
 
unsigned long eval_label(char *label)
{
	int i;
 
        for(i = 0; i < MEMORY_LEN; i++)
        	if (strcmp(label, mem[i].label) == 0)
        		return i;
 
        printf("\nINTERNAL ERROR: undefined label %s\n", label);
        cont_run = 0;
        return 0;
 
}
 
/* Returns 32-bit values from mem array. Big endian version. */
 
unsigned long eval_mem32(unsigned long memaddr)
{
	unsigned long temp;
 
	if (memaddr < MEMORY_LEN) {
/*		temp = ((unsigned long)(mem[memaddr].data << 24) & 0xff000000);
		temp +=	((unsigned long)(mem[memaddr + 1].data << 16) & 0x00ff0000);
		temp +=	((unsigned long)(mem[memaddr + 2].data << 8) & 0x0000ff00);
		temp +=	((unsigned long)mem[memaddr + 3].data & 0x000000ff); */
		temp = mem[memaddr].data << 24;
		temp +=	mem[memaddr + 1].data << 16;
		temp +=	mem[memaddr + 2].data << 8;
		temp +=	mem[memaddr + 3].data;
 
	} else {
		printf("EXCEPTION: read out of memory (32-bit access to %.8lx)\n", memaddr);
		cont_run = 0;
		temp = ((unsigned long)(mem[0].data << 24) & 0xff000000);
		temp +=	((unsigned long)(mem[1].data << 16) & 0x00ff0000);
		temp +=	((unsigned long)(mem[2].data << 8) & 0x0000ff00);
		temp +=	((unsigned long)mem[3].data & 0x000000ff);
	}
	return temp;
}
 
/* Returns 16-bit values from mem array. Big endian version. */
 
unsigned short eval_mem16(unsigned long memaddr)
{
	unsigned short temp;
 
	if (memaddr < MEMORY_LEN) {
		temp = ((unsigned short)(mem[memaddr].data << 8) & 0xff00);
		temp +=	((unsigned short)mem[memaddr + 1].data & 0x00ff);
	} else {
		printf("EXCEPTION: read out of memory (16-bit access to %.8lx)\n", memaddr);
		cont_run = 0;
		temp = ((unsigned short)(mem[0].data << 8) & 0xff00);
		temp +=	((unsigned short)mem[1].data & 0x00ff);
	}
	return temp;
}
 
 
/* Returns 8-bit values from mem array. Big endian version. */
 
unsigned char eval_mem8(unsigned long memaddr)
{	
	if (memaddr < MEMORY_LEN) {
		return (unsigned char)mem[memaddr].data;
	} else {
		printf("EXCEPTION: read out of memory (16-bit access to %.8lx)\n", memaddr);
		cont_run = 0;
		return (unsigned char)mem[0].data;
	}
}
 
/* Set mem, 32-bit. Big endian version. */
 
void set_mem32(unsigned long memaddr, unsigned long value)
{
	if (memaddr < MEMORY_LEN) {
		mem[memaddr].data = (value >> 24);
		mem[memaddr + 1].data = (char)(value >> 16);
		mem[memaddr + 2].data = (char)(value >> 8);
		mem[memaddr + 3].data = (char)(value);
	} else {
		printf("EXCEPTION: write out of memory (32-bit access to %.8lx)\n", memaddr);
		cont_run = 0;
	}
 
	return;
}
 
/* Set mem, 16-bit. Big endian version. */
 
void set_mem16(unsigned long memaddr, unsigned short value)
{
	if (memaddr < MEMORY_LEN) {
		mem[memaddr].data = (value >> 8);
		mem[memaddr + 1].data = (char)(value);
	} else {
		printf("EXCEPTION: write out of memory (16-bit access to %.8lx)\n", memaddr);
		cont_run = 0;
	}
 
	return;
}
 
/* Set mem, 8-bit. Big endian version. */
 
void set_mem8(unsigned long memaddr, unsigned char value)
{
	if (memaddr < MEMORY_LEN) {
		mem[memaddr].data = value;
	} else {
		printf("EXCEPTION: write out of memory (8-bit access to %.8lx)\n", memaddr);
		cont_run = 0;
	}
 
	return;
}
 

Go to most recent revision | Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.