home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / gdb-4.14-src.lha / gdb-4.14 / sim / z8k / mem.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-29  |  2.6 KB  |  121 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. static 
  29. long
  30. sitoptr (si)
  31. long si;
  32. {
  33.   return ((si & 0xff000000) >> 8) | (si & 0xffff);
  34. }
  35.  
  36. static
  37. unsigned short *
  38. get_page_and_offset (context, where, offset_ptr)
  39.      sim_state_type *context;
  40.      sim_phys_addr_type where;
  41.      int *offset_ptr;
  42. {
  43.   /* Is the page allocated ? */
  44.  
  45.   if (context->memory == 0)
  46.     {
  47.       context->memory  = (unsigned short *)calloc(64*1024*64,2);
  48.  
  49.     }
  50.   *offset_ptr = sitoptr(where);
  51.   return context->memory;
  52. }
  53.  
  54. void
  55. sim_write_byte (context, where, what)
  56.      sim_state_type *context;
  57.      sim_phys_addr_type where;
  58.      int what;
  59. {
  60.   unsigned int offset;
  61.   char *ptr = (char *)get_page_and_offset (context, where, &offset);
  62.  
  63.   ptr[offset] = what;
  64. }
  65.  
  66. void
  67. sim_write_short (context, where, what)
  68.      sim_state_type *context;
  69.      sim_phys_addr_type where;
  70.      int what;
  71. {
  72.   int offset;
  73.   char *ptr = (char *)get_page_and_offset (context, where, &offset);
  74.  
  75.   ptr[offset] = what >> 8;
  76.   ptr[offset + 1] = what;
  77. }
  78.  
  79. void
  80. sim_write_long (context, where, what)
  81.      sim_state_type *context;
  82.      sim_phys_addr_type where;
  83.      int what;
  84. {
  85.   int offset;
  86.   char *ptr = (char *)get_page_and_offset (context, where, &offset);
  87.  
  88.   ptr[offset] = what >> 24;
  89.   ptr[offset + 1] = what >> 16;
  90.   ptr[offset + 3] = what >> 8;
  91.   ptr[offset + 4] = what;
  92. }
  93.  
  94. int
  95. sim_read_byte (context, where)
  96.      sim_state_type *context;
  97.      sim_phys_addr_type where;
  98. {
  99.   int offset;
  100.   char *ptr = (char *)get_page_and_offset (context, where, &offset);
  101.  
  102.  return ptr[offset];
  103. }
  104.  
  105. unsigned
  106. sim_read_short (context, where)
  107.      sim_state_type *context;
  108.      sim_phys_addr_type where;
  109. {
  110.   int what;
  111.   int offset;
  112.  
  113.   char *ptr = (char *)get_page_and_offset (context, where, &offset);
  114.  
  115.   what = (ptr[offset] << 8) | ptr[offset + 1];
  116.   return what;
  117. }
  118.  
  119.  
  120.  
  121.