home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / gdb-4.9 / sim / z8k / mem.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-12  |  2.5 KB  |  114 lines

  1. /* memory support for Z8KSIM
  2.    Copyright (C) 1987, 1992 Free Software Foundation, Inc.
  3.  
  4. This file is part of Z8KSIM
  5.  
  6. Z8KSIM is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. Z8KSIM is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with Z8KSIM; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include <ansidecl.h>
  21. #include "sysdep.h"
  22.  
  23. #include "tm.h"
  24. #include "mem.h"
  25. #include "sim.h"
  26.  
  27. #define INLINE
  28.  
  29. static
  30. unsigned short *
  31. get_page_and_offset (context, where, offset_ptr)
  32.      sim_state_type *context;
  33.      sim_phys_addr_type where;
  34.      int *offset_ptr;
  35. {
  36.   /* Is the page allocated ? */
  37.  
  38.   if (context->memory == 0)
  39.     {
  40.       context->memory  = (unsigned short *)calloc(64*1024*64,2);
  41.  
  42.     }
  43.   *offset_ptr = sitoptr(where);
  44.   return context->memory;
  45. }
  46.  
  47. void
  48. sim_write_byte (context, where, what)
  49.      sim_state_type *context;
  50.      sim_phys_addr_type where;
  51.      int what;
  52. {
  53.   unsigned int offset;
  54.   char *ptr = (char *)get_page_and_offset (context, where, &offset);
  55.  
  56.   ptr[offset] = what;
  57. }
  58.  
  59. void
  60. sim_write_short (context, where, what)
  61.      sim_state_type *context;
  62.      sim_phys_addr_type where;
  63.      int what;
  64. {
  65.   int offset;
  66.   char *ptr = (char *)get_page_and_offset (context, where, &offset);
  67.  
  68.   ptr[offset] = what >> 8;
  69.   ptr[offset + 1] = what;
  70. }
  71.  
  72. void
  73. sim_write_long (context, where, what)
  74.      sim_state_type *context;
  75.      sim_phys_addr_type where;
  76.      int what;
  77. {
  78.   int offset;
  79.   char *ptr = (char *)get_page_and_offset (context, where, &offset);
  80.  
  81.   ptr[offset] = what >> 24;
  82.   ptr[offset + 1] = what >> 16;
  83.   ptr[offset + 3] = what >> 8;
  84.   ptr[offset + 4] = what;
  85. }
  86.  
  87. int
  88. sim_read_byte (context, where)
  89.      sim_state_type *context;
  90.      sim_phys_addr_type where;
  91. {
  92.   int offset;
  93.   char *ptr = (char *)get_page_and_offset (context, where, &offset);
  94.  
  95.  return ptr[offset];
  96. }
  97.  
  98. unsigned
  99. sim_read_short (context, where)
  100.      sim_state_type *context;
  101.      sim_phys_addr_type where;
  102. {
  103.   int what;
  104.   int offset;
  105.  
  106.   char *ptr = (char *)get_page_and_offset (context, where, &offset);
  107.  
  108.   what = (ptr[offset] << 8) | ptr[offset + 1];
  109.   return what;
  110. }
  111.  
  112.  
  113.  
  114.