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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.3/] [sim/] [z8k/] [mem.c] - Diff between revs 1181 and 1765

Only display areas with differences | Details | Blame | View Log

Rev 1181 Rev 1765
/* memory support for Z8KSIM
/* memory support for Z8KSIM
   Copyright (C) 1987, 1992 Free Software Foundation, Inc.
   Copyright (C) 1987, 1992 Free Software Foundation, Inc.
 
 
This file is part of Z8KSIM
This file is part of Z8KSIM
 
 
Z8KSIM is free software; you can redistribute it and/or modify
Z8KSIM is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
the Free Software Foundation; either version 2, or (at your option)
any later version.
any later version.
 
 
Z8KSIM is distributed in the hope that it will be useful,
Z8KSIM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
GNU General Public License for more details.
 
 
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with Z8KZIM; if not, write to the Free Software
along with Z8KZIM; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 
#include "config.h"
#include "config.h"
 
 
#include <ansidecl.h>
#include <ansidecl.h>
 
 
#ifdef HAVE_STDLIB_H
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#include <stdlib.h>
#endif
#endif
 
 
#include "tm.h"
#include "tm.h"
#include "mem.h"
#include "mem.h"
#include "sim.h"
#include "sim.h"
 
 
#define INLINE
#define INLINE
static
static
long
long
sitoptr (si)
sitoptr (si)
long si;
long si;
{
{
  return ((si & 0xff000000) >> 8) | (si & 0xffff);
  return ((si & 0xff000000) >> 8) | (si & 0xffff);
}
}
 
 
static
static
unsigned short *
unsigned short *
get_page_and_offset (context, where, offset_ptr)
get_page_and_offset (context, where, offset_ptr)
     sim_state_type *context;
     sim_state_type *context;
     sim_phys_addr_type where;
     sim_phys_addr_type where;
     int *offset_ptr;
     int *offset_ptr;
{
{
  /* Is the page allocated ? */
  /* Is the page allocated ? */
 
 
  if (context->memory == 0)
  if (context->memory == 0)
    {
    {
      /* Must allocate 16MB in order to run Z8001 programs.  */
      /* Must allocate 16MB in order to run Z8001 programs.  */
      context->memory  = (unsigned short *)calloc(64*1024*64,4);
      context->memory  = (unsigned short *)calloc(64*1024*64,4);
    }
    }
 
 
  *offset_ptr = sitoptr(where);
  *offset_ptr = sitoptr(where);
  return context->memory;
  return context->memory;
}
}
 
 
void
void
sim_write_byte (context, where, what)
sim_write_byte (context, where, what)
     sim_state_type *context;
     sim_state_type *context;
     sim_phys_addr_type where;
     sim_phys_addr_type where;
     int what;
     int what;
{
{
  unsigned int offset;
  unsigned int offset;
  char *ptr = (char *)get_page_and_offset (context, where, &offset);
  char *ptr = (char *)get_page_and_offset (context, where, &offset);
 
 
  ptr[offset] = what;
  ptr[offset] = what;
}
}
 
 
void
void
sim_write_short (context, where, what)
sim_write_short (context, where, what)
     sim_state_type *context;
     sim_state_type *context;
     sim_phys_addr_type where;
     sim_phys_addr_type where;
     int what;
     int what;
{
{
  int offset;
  int offset;
  char *ptr = (char *)get_page_and_offset (context, where, &offset);
  char *ptr = (char *)get_page_and_offset (context, where, &offset);
 
 
  ptr[offset] = what >> 8;
  ptr[offset] = what >> 8;
  ptr[offset + 1] = what;
  ptr[offset + 1] = what;
}
}
 
 
void
void
sim_write_long (context, where, what)
sim_write_long (context, where, what)
     sim_state_type *context;
     sim_state_type *context;
     sim_phys_addr_type where;
     sim_phys_addr_type where;
     int what;
     int what;
{
{
  int offset;
  int offset;
  char *ptr = (char *)get_page_and_offset (context, where, &offset);
  char *ptr = (char *)get_page_and_offset (context, where, &offset);
 
 
  ptr[offset] = what >> 24;
  ptr[offset] = what >> 24;
  ptr[offset + 1] = what >> 16;
  ptr[offset + 1] = what >> 16;
  ptr[offset + 3] = what >> 8;
  ptr[offset + 3] = what >> 8;
  ptr[offset + 4] = what;
  ptr[offset + 4] = what;
}
}
 
 
int
int
sim_read_byte (context, where)
sim_read_byte (context, where)
     sim_state_type *context;
     sim_state_type *context;
     sim_phys_addr_type where;
     sim_phys_addr_type where;
{
{
  int offset;
  int offset;
  char *ptr = (char *)get_page_and_offset (context, where, &offset);
  char *ptr = (char *)get_page_and_offset (context, where, &offset);
 
 
 return ptr[offset];
 return ptr[offset];
}
}
 
 
unsigned
unsigned
sim_read_short (context, where)
sim_read_short (context, where)
     sim_state_type *context;
     sim_state_type *context;
     sim_phys_addr_type where;
     sim_phys_addr_type where;
{
{
  int what;
  int what;
  int offset;
  int offset;
 
 
  char *ptr = (char *)get_page_and_offset (context, where, &offset);
  char *ptr = (char *)get_page_and_offset (context, where, &offset);
 
 
  what = (ptr[offset] << 8) | ptr[offset + 1];
  what = (ptr[offset] << 8) | ptr[offset + 1];
  return what;
  return what;
}
}
 
 
 
 
 
 
 
 

powered by: WebSVN 2.1.0

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