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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-7.1/] [sim/] [rx/] [mem.c] - Diff between revs 834 and 842

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 834 Rev 842
/* mem.c --- memory for RX simulator.
/* mem.c --- memory for RX simulator.
 
 
Copyright (C) 2005, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
Copyright (C) 2005, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
Contributed by Red Hat, Inc.
Contributed by Red Hat, Inc.
 
 
This file is part of the GNU simulators.
This file is part of the GNU simulators.
 
 
This program is free software; you can redistribute it and/or modify
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
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
(at your option) any later version.
 
 
This program is distributed in the hope that it will be useful,
This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 
/* This slows down the simulator and we get some false negatives from
/* This slows down the simulator and we get some false negatives from
   gcc, like when it uses a long-sized hole to hold a byte-sized
   gcc, like when it uses a long-sized hole to hold a byte-sized
   variable, knowing that it doesn't care about the other bits.  But,
   variable, knowing that it doesn't care about the other bits.  But,
   if you need to track down a read-from-unitialized bug, set this to
   if you need to track down a read-from-unitialized bug, set this to
   1.  */
   1.  */
#define RDCHECK 0
#define RDCHECK 0
 
 
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
 
 
#include "mem.h"
#include "mem.h"
#include "cpu.h"
#include "cpu.h"
#include "syscalls.h"
#include "syscalls.h"
#include "misc.h"
#include "misc.h"
#include "err.h"
#include "err.h"
 
 
#define L1_BITS  (10)
#define L1_BITS  (10)
#define L2_BITS  (10)
#define L2_BITS  (10)
#define OFF_BITS (12)
#define OFF_BITS (12)
 
 
#define L1_LEN  (1 << L1_BITS)
#define L1_LEN  (1 << L1_BITS)
#define L2_LEN  (1 << L2_BITS)
#define L2_LEN  (1 << L2_BITS)
#define OFF_LEN (1 << OFF_BITS)
#define OFF_LEN (1 << OFF_BITS)
 
 
static unsigned char **pt[L1_LEN];
static unsigned char **pt[L1_LEN];
static unsigned char **ptr[L1_LEN];
static unsigned char **ptr[L1_LEN];
 
 
/* [ get=0/put=1 ][ byte size ] */
/* [ get=0/put=1 ][ byte size ] */
static unsigned int mem_counters[2][5];
static unsigned int mem_counters[2][5];
 
 
#define COUNT(isput,bytes)                                      \
#define COUNT(isput,bytes)                                      \
  if (verbose && enable_counting) mem_counters[isput][bytes]++
  if (verbose && enable_counting) mem_counters[isput][bytes]++
 
 
void
void
init_mem (void)
init_mem (void)
{
{
  int i, j;
  int i, j;
 
 
  for (i = 0; i < L1_LEN; i++)
  for (i = 0; i < L1_LEN; i++)
    if (pt[i])
    if (pt[i])
      {
      {
        for (j = 0; j < L2_LEN; j++)
        for (j = 0; j < L2_LEN; j++)
          if (pt[i][j])
          if (pt[i][j])
            free (pt[i][j]);
            free (pt[i][j]);
        free (pt[i]);
        free (pt[i]);
      }
      }
  memset (pt, 0, sizeof (pt));
  memset (pt, 0, sizeof (pt));
  memset (ptr, 0, sizeof (ptr));
  memset (ptr, 0, sizeof (ptr));
  memset (mem_counters, 0, sizeof (mem_counters));
  memset (mem_counters, 0, sizeof (mem_counters));
}
}
 
 
enum mem_ptr_action
enum mem_ptr_action
{
{
  MPA_WRITING,
  MPA_WRITING,
  MPA_READING,
  MPA_READING,
  MPA_CONTENT_TYPE
  MPA_CONTENT_TYPE
};
};
 
 
static unsigned char *
static unsigned char *
mem_ptr (unsigned long address, enum mem_ptr_action action)
mem_ptr (unsigned long address, enum mem_ptr_action action)
{
{
  int pt1 = (address >> (L2_BITS + OFF_BITS)) & ((1 << L1_BITS) - 1);
  int pt1 = (address >> (L2_BITS + OFF_BITS)) & ((1 << L1_BITS) - 1);
  int pt2 = (address >> OFF_BITS) & ((1 << L2_BITS) - 1);
  int pt2 = (address >> OFF_BITS) & ((1 << L2_BITS) - 1);
  int pto = address & ((1 << OFF_BITS) - 1);
  int pto = address & ((1 << OFF_BITS) - 1);
 
 
  if (address == 0)
  if (address == 0)
    execution_error (SIM_ERR_NULL_POINTER_DEREFERENCE, 0);
    execution_error (SIM_ERR_NULL_POINTER_DEREFERENCE, 0);
 
 
  if (pt[pt1] == 0)
  if (pt[pt1] == 0)
    {
    {
      pt[pt1] = (unsigned char **) calloc (L2_LEN, sizeof (char **));
      pt[pt1] = (unsigned char **) calloc (L2_LEN, sizeof (char **));
      ptr[pt1] = (unsigned char **) calloc (L2_LEN, sizeof (char **));
      ptr[pt1] = (unsigned char **) calloc (L2_LEN, sizeof (char **));
    }
    }
  if (pt[pt1][pt2] == 0)
  if (pt[pt1][pt2] == 0)
    {
    {
      if (action == MPA_READING)
      if (action == MPA_READING)
        execution_error (SIM_ERR_READ_UNWRITTEN_PAGES, address);
        execution_error (SIM_ERR_READ_UNWRITTEN_PAGES, address);
 
 
      pt[pt1][pt2] = (unsigned char *) malloc (OFF_LEN);
      pt[pt1][pt2] = (unsigned char *) malloc (OFF_LEN);
      memset (pt[pt1][pt2], 0, OFF_LEN);
      memset (pt[pt1][pt2], 0, OFF_LEN);
      ptr[pt1][pt2] = (unsigned char *) malloc (OFF_LEN);
      ptr[pt1][pt2] = (unsigned char *) malloc (OFF_LEN);
      memset (ptr[pt1][pt2], MC_UNINIT, OFF_LEN);
      memset (ptr[pt1][pt2], MC_UNINIT, OFF_LEN);
    }
    }
  else if (action == MPA_READING
  else if (action == MPA_READING
           && ptr[pt1][pt2][pto] == MC_UNINIT)
           && ptr[pt1][pt2][pto] == MC_UNINIT)
    execution_error (SIM_ERR_READ_UNWRITTEN_BYTES, address);
    execution_error (SIM_ERR_READ_UNWRITTEN_BYTES, address);
 
 
  if (action == MPA_WRITING)
  if (action == MPA_WRITING)
    {
    {
      if (ptr[pt1][pt2][pto] == MC_PUSHED_PC)
      if (ptr[pt1][pt2][pto] == MC_PUSHED_PC)
        execution_error (SIM_ERR_CORRUPT_STACK, address);
        execution_error (SIM_ERR_CORRUPT_STACK, address);
      ptr[pt1][pt2][pto] = MC_DATA;
      ptr[pt1][pt2][pto] = MC_DATA;
    }
    }
 
 
  if (action == MPA_CONTENT_TYPE)
  if (action == MPA_CONTENT_TYPE)
    return ptr[pt1][pt2] + pto;
    return ptr[pt1][pt2] + pto;
 
 
  return pt[pt1][pt2] + pto;
  return pt[pt1][pt2] + pto;
}
}
 
 
static inline int
static inline int
is_reserved_address (unsigned int address)
is_reserved_address (unsigned int address)
{
{
  return (address >= 0x00020000 && address < 0x00080000)
  return (address >= 0x00020000 && address < 0x00080000)
    ||   (address >= 0x00100000 && address < 0x01000000)
    ||   (address >= 0x00100000 && address < 0x01000000)
    ||   (address >= 0x08000000 && address < 0xff000000);
    ||   (address >= 0x08000000 && address < 0xff000000);
}
}
 
 
static void
static void
used (int rstart, int i, int j)
used (int rstart, int i, int j)
{
{
  int rend = i << (L2_BITS + OFF_BITS);
  int rend = i << (L2_BITS + OFF_BITS);
  rend += j << OFF_BITS;
  rend += j << OFF_BITS;
  if (rstart == 0xe0000 && rend == 0xe1000)
  if (rstart == 0xe0000 && rend == 0xe1000)
    return;
    return;
  printf ("mem:   %08x - %08x (%dk bytes)\n", rstart, rend - 1,
  printf ("mem:   %08x - %08x (%dk bytes)\n", rstart, rend - 1,
          (rend - rstart) / 1024);
          (rend - rstart) / 1024);
}
}
 
 
static char *
static char *
mcs (int isput, int bytes)
mcs (int isput, int bytes)
{
{
  return comma (mem_counters[isput][bytes]);
  return comma (mem_counters[isput][bytes]);
}
}
 
 
void
void
mem_usage_stats ()
mem_usage_stats ()
{
{
  int i, j;
  int i, j;
  int rstart = 0;
  int rstart = 0;
  int pending = 0;
  int pending = 0;
 
 
  for (i = 0; i < L1_LEN; i++)
  for (i = 0; i < L1_LEN; i++)
    if (pt[i])
    if (pt[i])
      {
      {
        for (j = 0; j < L2_LEN; j++)
        for (j = 0; j < L2_LEN; j++)
          if (pt[i][j])
          if (pt[i][j])
            {
            {
              if (!pending)
              if (!pending)
                {
                {
                  pending = 1;
                  pending = 1;
                  rstart = (i << (L2_BITS + OFF_BITS)) + (j << OFF_BITS);
                  rstart = (i << (L2_BITS + OFF_BITS)) + (j << OFF_BITS);
                }
                }
            }
            }
          else if (pending)
          else if (pending)
            {
            {
              pending = 0;
              pending = 0;
              used (rstart, i, j);
              used (rstart, i, j);
            }
            }
      }
      }
    else
    else
      {
      {
        if (pending)
        if (pending)
          {
          {
            pending = 0;
            pending = 0;
            used (rstart, i, 0);
            used (rstart, i, 0);
          }
          }
      }
      }
  /*       mem foo: 123456789012 123456789012 123456789012 123456789012
  /*       mem foo: 123456789012 123456789012 123456789012 123456789012
            123456789012 */
            123456789012 */
  printf ("                 byte        short        3byte         long"
  printf ("                 byte        short        3byte         long"
          "       opcode\n");
          "       opcode\n");
  if (verbose > 1)
  if (verbose > 1)
    {
    {
      /* Only use comma separated numbers when being very verbose.
      /* Only use comma separated numbers when being very verbose.
         Comma separated numbers are hard to parse in awk scripts.  */
         Comma separated numbers are hard to parse in awk scripts.  */
      printf ("mem get: %12s %12s %12s %12s %12s\n", mcs (0, 1), mcs (0, 2),
      printf ("mem get: %12s %12s %12s %12s %12s\n", mcs (0, 1), mcs (0, 2),
              mcs (0, 3), mcs (0, 4), mcs (0, 0));
              mcs (0, 3), mcs (0, 4), mcs (0, 0));
      printf ("mem put: %12s %12s %12s %12s\n", mcs (1, 1), mcs (1, 2),
      printf ("mem put: %12s %12s %12s %12s\n", mcs (1, 1), mcs (1, 2),
              mcs (1, 3), mcs (1, 4));
              mcs (1, 3), mcs (1, 4));
    }
    }
  else
  else
    {
    {
      printf ("mem get: %12u %12u %12u %12u %12u\n",
      printf ("mem get: %12u %12u %12u %12u %12u\n",
              mem_counters[0][1], mem_counters[0][2],
              mem_counters[0][1], mem_counters[0][2],
              mem_counters[0][3], mem_counters[0][4],
              mem_counters[0][3], mem_counters[0][4],
              mem_counters[0][0]);
              mem_counters[0][0]);
      printf ("mem put: %12u %12u %12u %12u\n",
      printf ("mem put: %12u %12u %12u %12u\n",
              mem_counters [1][1], mem_counters [1][2],
              mem_counters [1][1], mem_counters [1][2],
              mem_counters [1][3], mem_counters [1][4]);
              mem_counters [1][3], mem_counters [1][4]);
    }
    }
}
}
 
 
unsigned long
unsigned long
mem_usage_cycles (void)
mem_usage_cycles (void)
{
{
  unsigned long rv = mem_counters[0][0];
  unsigned long rv = mem_counters[0][0];
  rv += mem_counters[0][1] * 1;
  rv += mem_counters[0][1] * 1;
  rv += mem_counters[0][2] * 2;
  rv += mem_counters[0][2] * 2;
  rv += mem_counters[0][3] * 3;
  rv += mem_counters[0][3] * 3;
  rv += mem_counters[0][4] * 4;
  rv += mem_counters[0][4] * 4;
  rv += mem_counters[1][1] * 1;
  rv += mem_counters[1][1] * 1;
  rv += mem_counters[1][2] * 2;
  rv += mem_counters[1][2] * 2;
  rv += mem_counters[1][3] * 3;
  rv += mem_counters[1][3] * 3;
  rv += mem_counters[1][4] * 4;
  rv += mem_counters[1][4] * 4;
  return rv;
  return rv;
}
}
 
 
static int tpr = 0;
static int tpr = 0;
static void
static void
s (int address, char *dir)
s (int address, char *dir)
{
{
  if (tpr == 0)
  if (tpr == 0)
    printf ("MEM[%08x] %s", address, dir);
    printf ("MEM[%08x] %s", address, dir);
  tpr++;
  tpr++;
}
}
 
 
#define S(d) if (trace) s(address, d)
#define S(d) if (trace) s(address, d)
static void
static void
e ()
e ()
{
{
  if (!trace)
  if (!trace)
    return;
    return;
  tpr--;
  tpr--;
  if (tpr == 0)
  if (tpr == 0)
    printf ("\n");
    printf ("\n");
}
}
 
 
static char
static char
mtypec (int address)
mtypec (int address)
{
{
  unsigned char *cp = mem_ptr (address, MPA_CONTENT_TYPE);
  unsigned char *cp = mem_ptr (address, MPA_CONTENT_TYPE);
  return "udp"[*cp];
  return "udp"[*cp];
}
}
 
 
#define E() if (trace) e()
#define E() if (trace) e()
 
 
void
void
mem_put_byte (unsigned int address, unsigned char value)
mem_put_byte (unsigned int address, unsigned char value)
{
{
  unsigned char *m;
  unsigned char *m;
  char tc = ' ';
  char tc = ' ';
 
 
  if (trace)
  if (trace)
    tc = mtypec (address);
    tc = mtypec (address);
  m = mem_ptr (address, MPA_WRITING);
  m = mem_ptr (address, MPA_WRITING);
  if (trace)
  if (trace)
    printf (" %02x%c", value, tc);
    printf (" %02x%c", value, tc);
  *m = value;
  *m = value;
  switch (address)
  switch (address)
    {
    {
    case 0x00e1:
    case 0x00e1:
      {
      {
        static int old_led = -1;
        static int old_led = -1;
        static char *led_on[] =
        static char *led_on[] =
          { "\033[31m O ", "\033[32m O ", "\033[34m O " };
          { "\033[31m O ", "\033[32m O ", "\033[34m O " };
        static char *led_off[] = { "\033[0m · ", "\033[0m · ", "\033[0m · " };
        static char *led_off[] = { "\033[0m · ", "\033[0m · ", "\033[0m · " };
        int i;
        int i;
        if (old_led != value)
        if (old_led != value)
          {
          {
            fputs ("  ", stdout);
            fputs ("  ", stdout);
            for (i = 0; i < 3; i++)
            for (i = 0; i < 3; i++)
              if (value & (1 << i))
              if (value & (1 << i))
                fputs (led_off[i], stdout);
                fputs (led_off[i], stdout);
              else
              else
                fputs (led_on[i], stdout);
                fputs (led_on[i], stdout);
            fputs ("\033[0m\r", stdout);
            fputs ("\033[0m\r", stdout);
            fflush (stdout);
            fflush (stdout);
            old_led = value;
            old_led = value;
          }
          }
      }
      }
      break;
      break;
 
 
    case 0x3aa: /* uart1tx */
    case 0x3aa: /* uart1tx */
      {
      {
        static int pending_exit = 0;
        static int pending_exit = 0;
        if (value == 0)
        if (value == 0)
          {
          {
            if (pending_exit)
            if (pending_exit)
              {
              {
                step_result = RX_MAKE_EXITED(value);
                step_result = RX_MAKE_EXITED(value);
                return;
                return;
              }
              }
            pending_exit = 1;
            pending_exit = 1;
          }
          }
        else
        else
          putchar(value);
          putchar(value);
      }
      }
      break;
      break;
 
 
    default:
    default:
      if (is_reserved_address (address))
      if (is_reserved_address (address))
        generate_access_exception ();
        generate_access_exception ();
    }
    }
}
}
 
 
void
void
mem_put_qi (int address, unsigned char value)
mem_put_qi (int address, unsigned char value)
{
{
  S ("<=");
  S ("<=");
  mem_put_byte (address, value & 0xff);
  mem_put_byte (address, value & 0xff);
  E ();
  E ();
  COUNT (1, 1);
  COUNT (1, 1);
}
}
 
 
void
void
mem_put_hi (int address, unsigned short value)
mem_put_hi (int address, unsigned short value)
{
{
  S ("<=");
  S ("<=");
  if (rx_big_endian)
  if (rx_big_endian)
    {
    {
      mem_put_byte (address, value >> 8);
      mem_put_byte (address, value >> 8);
      mem_put_byte (address + 1, value & 0xff);
      mem_put_byte (address + 1, value & 0xff);
    }
    }
  else
  else
    {
    {
      mem_put_byte (address, value & 0xff);
      mem_put_byte (address, value & 0xff);
      mem_put_byte (address + 1, value >> 8);
      mem_put_byte (address + 1, value >> 8);
    }
    }
  E ();
  E ();
  COUNT (1, 2);
  COUNT (1, 2);
}
}
 
 
void
void
mem_put_psi (int address, unsigned long value)
mem_put_psi (int address, unsigned long value)
{
{
  S ("<=");
  S ("<=");
  if (rx_big_endian)
  if (rx_big_endian)
    {
    {
      mem_put_byte (address, value >> 16);
      mem_put_byte (address, value >> 16);
      mem_put_byte (address + 1, (value >> 8) & 0xff);
      mem_put_byte (address + 1, (value >> 8) & 0xff);
      mem_put_byte (address + 2, value & 0xff);
      mem_put_byte (address + 2, value & 0xff);
    }
    }
  else
  else
    {
    {
      mem_put_byte (address, value & 0xff);
      mem_put_byte (address, value & 0xff);
      mem_put_byte (address + 1, (value >> 8) & 0xff);
      mem_put_byte (address + 1, (value >> 8) & 0xff);
      mem_put_byte (address + 2, value >> 16);
      mem_put_byte (address + 2, value >> 16);
    }
    }
  E ();
  E ();
  COUNT (1, 3);
  COUNT (1, 3);
}
}
 
 
void
void
mem_put_si (int address, unsigned long value)
mem_put_si (int address, unsigned long value)
{
{
  S ("<=");
  S ("<=");
  if (rx_big_endian)
  if (rx_big_endian)
    {
    {
      mem_put_byte (address + 0, (value >> 24) & 0xff);
      mem_put_byte (address + 0, (value >> 24) & 0xff);
      mem_put_byte (address + 1, (value >> 16) & 0xff);
      mem_put_byte (address + 1, (value >> 16) & 0xff);
      mem_put_byte (address + 2, (value >> 8) & 0xff);
      mem_put_byte (address + 2, (value >> 8) & 0xff);
      mem_put_byte (address + 3, value & 0xff);
      mem_put_byte (address + 3, value & 0xff);
    }
    }
  else
  else
    {
    {
      mem_put_byte (address + 0, value & 0xff);
      mem_put_byte (address + 0, value & 0xff);
      mem_put_byte (address + 1, (value >> 8) & 0xff);
      mem_put_byte (address + 1, (value >> 8) & 0xff);
      mem_put_byte (address + 2, (value >> 16) & 0xff);
      mem_put_byte (address + 2, (value >> 16) & 0xff);
      mem_put_byte (address + 3, (value >> 24) & 0xff);
      mem_put_byte (address + 3, (value >> 24) & 0xff);
    }
    }
  E ();
  E ();
  COUNT (1, 4);
  COUNT (1, 4);
}
}
 
 
void
void
mem_put_blk (int address, void *bufptr, int nbytes)
mem_put_blk (int address, void *bufptr, int nbytes)
{
{
  S ("<=");
  S ("<=");
  if (enable_counting)
  if (enable_counting)
    mem_counters[1][1] += nbytes;
    mem_counters[1][1] += nbytes;
  while (nbytes--)
  while (nbytes--)
    mem_put_byte (address++, *(unsigned char *) bufptr++);
    mem_put_byte (address++, *(unsigned char *) bufptr++);
  E ();
  E ();
}
}
 
 
unsigned char
unsigned char
mem_get_pc (int address)
mem_get_pc (int address)
{
{
  unsigned char *m = mem_ptr (address, MPA_READING);
  unsigned char *m = mem_ptr (address, MPA_READING);
  COUNT (0, 0);
  COUNT (0, 0);
  return *m;
  return *m;
}
}
 
 
static unsigned char
static unsigned char
mem_get_byte (unsigned int address)
mem_get_byte (unsigned int address)
{
{
  unsigned char *m;
  unsigned char *m;
 
 
  S ("=>");
  S ("=>");
  m = mem_ptr (address, MPA_READING);
  m = mem_ptr (address, MPA_READING);
  switch (address)
  switch (address)
    {
    {
    case 0x3ad: /* uart1c1 */
    case 0x3ad: /* uart1c1 */
      E();
      E();
      return 2; /* transmitter empty */
      return 2; /* transmitter empty */
      break;
      break;
    default:
    default:
      if (trace)
      if (trace)
        printf (" %02x%c", *m, mtypec (address));
        printf (" %02x%c", *m, mtypec (address));
      if (is_reserved_address (address))
      if (is_reserved_address (address))
        generate_access_exception ();
        generate_access_exception ();
      break;
      break;
    }
    }
  E ();
  E ();
  return *m;
  return *m;
}
}
 
 
unsigned char
unsigned char
mem_get_qi (int address)
mem_get_qi (int address)
{
{
  unsigned char rv;
  unsigned char rv;
  S ("=>");
  S ("=>");
  rv = mem_get_byte (address);
  rv = mem_get_byte (address);
  COUNT (0, 1);
  COUNT (0, 1);
  E ();
  E ();
  return rv;
  return rv;
}
}
 
 
unsigned short
unsigned short
mem_get_hi (int address)
mem_get_hi (int address)
{
{
  unsigned short rv;
  unsigned short rv;
  S ("=>");
  S ("=>");
  if (rx_big_endian)
  if (rx_big_endian)
    {
    {
      rv = mem_get_byte (address) << 8;
      rv = mem_get_byte (address) << 8;
      rv |= mem_get_byte (address + 1);
      rv |= mem_get_byte (address + 1);
    }
    }
  else
  else
    {
    {
      rv = mem_get_byte (address);
      rv = mem_get_byte (address);
      rv |= mem_get_byte (address + 1) << 8;
      rv |= mem_get_byte (address + 1) << 8;
    }
    }
  COUNT (0, 2);
  COUNT (0, 2);
  E ();
  E ();
  return rv;
  return rv;
}
}
 
 
unsigned long
unsigned long
mem_get_psi (int address)
mem_get_psi (int address)
{
{
  unsigned long rv;
  unsigned long rv;
  S ("=>");
  S ("=>");
  if (rx_big_endian)
  if (rx_big_endian)
    {
    {
      rv = mem_get_byte (address + 2);
      rv = mem_get_byte (address + 2);
      rv |= mem_get_byte (address + 1) << 8;
      rv |= mem_get_byte (address + 1) << 8;
      rv |= mem_get_byte (address) << 16;
      rv |= mem_get_byte (address) << 16;
    }
    }
  else
  else
    {
    {
      rv = mem_get_byte (address);
      rv = mem_get_byte (address);
      rv |= mem_get_byte (address + 1) << 8;
      rv |= mem_get_byte (address + 1) << 8;
      rv |= mem_get_byte (address + 2) << 16;
      rv |= mem_get_byte (address + 2) << 16;
    }
    }
  COUNT (0, 3);
  COUNT (0, 3);
  E ();
  E ();
  return rv;
  return rv;
}
}
 
 
unsigned long
unsigned long
mem_get_si (int address)
mem_get_si (int address)
{
{
  unsigned long rv;
  unsigned long rv;
  S ("=>");
  S ("=>");
  if (rx_big_endian)
  if (rx_big_endian)
    {
    {
      rv = mem_get_byte (address + 3);
      rv = mem_get_byte (address + 3);
      rv |= mem_get_byte (address + 2) << 8;
      rv |= mem_get_byte (address + 2) << 8;
      rv |= mem_get_byte (address + 1) << 16;
      rv |= mem_get_byte (address + 1) << 16;
      rv |= mem_get_byte (address) << 24;
      rv |= mem_get_byte (address) << 24;
    }
    }
  else
  else
    {
    {
      rv = mem_get_byte (address);
      rv = mem_get_byte (address);
      rv |= mem_get_byte (address + 1) << 8;
      rv |= mem_get_byte (address + 1) << 8;
      rv |= mem_get_byte (address + 2) << 16;
      rv |= mem_get_byte (address + 2) << 16;
      rv |= mem_get_byte (address + 3) << 24;
      rv |= mem_get_byte (address + 3) << 24;
    }
    }
  COUNT (0, 4);
  COUNT (0, 4);
  E ();
  E ();
  return rv;
  return rv;
}
}
 
 
void
void
mem_get_blk (int address, void *bufptr, int nbytes)
mem_get_blk (int address, void *bufptr, int nbytes)
{
{
  S ("=>");
  S ("=>");
  if (enable_counting)
  if (enable_counting)
    mem_counters[0][1] += nbytes;
    mem_counters[0][1] += nbytes;
  while (nbytes--)
  while (nbytes--)
    *(char *) bufptr++ = mem_get_byte (address++);
    *(char *) bufptr++ = mem_get_byte (address++);
  E ();
  E ();
}
}
 
 
int
int
sign_ext (int v, int bits)
sign_ext (int v, int bits)
{
{
  if (bits < 32)
  if (bits < 32)
    {
    {
      v &= (1 << bits) - 1;
      v &= (1 << bits) - 1;
      if (v & (1 << (bits - 1)))
      if (v & (1 << (bits - 1)))
        v -= (1 << bits);
        v -= (1 << bits);
    }
    }
  return v;
  return v;
}
}
 
 
void
void
mem_set_content_type (int address, enum mem_content_type type)
mem_set_content_type (int address, enum mem_content_type type)
{
{
  unsigned char *mt = mem_ptr (address, MPA_CONTENT_TYPE);
  unsigned char *mt = mem_ptr (address, MPA_CONTENT_TYPE);
  *mt = type;
  *mt = type;
}
}
 
 
void
void
mem_set_content_range (int start_address, int end_address, enum mem_content_type type)
mem_set_content_range (int start_address, int end_address, enum mem_content_type type)
{
{
  while (start_address < end_address)
  while (start_address < end_address)
    {
    {
      int sz, ofs;
      int sz, ofs;
      unsigned char *mt;
      unsigned char *mt;
 
 
      sz = end_address - start_address;
      sz = end_address - start_address;
      ofs = start_address % L1_LEN;
      ofs = start_address % L1_LEN;
      if (sz + ofs > L1_LEN)
      if (sz + ofs > L1_LEN)
        sz = L1_LEN - ofs;
        sz = L1_LEN - ofs;
 
 
      mt = mem_ptr (start_address, MPA_CONTENT_TYPE);
      mt = mem_ptr (start_address, MPA_CONTENT_TYPE);
      memset (mt, type, sz);
      memset (mt, type, sz);
 
 
      start_address += sz;
      start_address += sz;
    }
    }
}
}
 
 
enum mem_content_type
enum mem_content_type
mem_get_content_type (int address)
mem_get_content_type (int address)
{
{
  unsigned char *mt = mem_ptr (address, MPA_CONTENT_TYPE);
  unsigned char *mt = mem_ptr (address, MPA_CONTENT_TYPE);
  return *mt;
  return *mt;
}
}
 
 

powered by: WebSVN 2.1.0

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