|
|
1.1 root 1: /*
2: * UAE - The Un*x Amiga Emulator
3: *
4: * memory management
5: *
6: * Copyright 1995 Bernd Schmidt
1.1.1.2 root 7: *
8: * Adaptation to Hatari by Thomas Huth
1.1.1.4 root 9: *
1.1.1.7 root 10: * This file is distributed under the GNU General Public License, version 2
11: * or at your option any later version. Read the file gpl.txt for details.
1.1 root 12: */
13:
1.1.1.3 root 14: #ifndef UAE_MEMORY_H
15: #define UAE_MEMORY_H
16:
17: #include "maccess.h"
1.1 root 18:
1.1.1.5 root 19: #define call_mem_get_func(func, addr) ((*func)(addr))
20: #define call_mem_put_func(func, addr, v) ((*func)(addr, v))
21:
1.1 root 22:
23: /* Enabling this adds one additional native memory reference per 68k memory
24: * access, but saves one shift (on the x86). Enabling this is probably
25: * better for the cache. My favourite benchmark (PP2) doesn't show a
26: * difference, so I leave this enabled. */
27: #if 1 || defined SAVE_MEMORY
28: #define SAVE_MEMORY_BANKS
29: #endif
30:
31:
32: typedef uae_u32 (*mem_get_func)(uaecptr) REGPARAM;
33: typedef void (*mem_put_func)(uaecptr, uae_u32) REGPARAM;
34: typedef uae_u8 *(*xlate_func)(uaecptr) REGPARAM;
35: typedef int (*check_func)(uaecptr, uae_u32) REGPARAM;
36:
37: extern char *address_space, *good_address_map;
38:
39:
1.1.1.8 ! root 40: enum
! 41: {
! 42: ABFLAG_UNK = 0, ABFLAG_RAM = 1, ABFLAG_ROM = 2, ABFLAG_ROMIN = 4, ABFLAG_IO = 8,
! 43: ABFLAG_NONE = 16, ABFLAG_SAFE = 32, ABFLAG_INDIRECT = 64, ABFLAG_NOALLOC = 128,
! 44: ABFLAG_RTG = 256, ABFLAG_THREADSAFE = 512, ABFLAG_DIRECTMAP = 1024
! 45: };
1.1 root 46: typedef struct {
47: /* These ones should be self-explanatory... */
48: mem_get_func lget, wget, bget;
49: mem_put_func lput, wput, bput;
1.1.1.4 root 50: /* Use xlateaddr to translate an Atari address to a uae_u8 * that can
1.1 root 51: * be used to address memory without calling the wget/wput functions.
52: * This doesn't work for all memory banks, so this function may call
53: * abort(). */
54: xlate_func xlateaddr;
55: /* To prevent calls to abort(), use check before calling xlateaddr.
56: * It checks not only that the memory bank can do xlateaddr, but also
57: * that the pointer points to an area of at least the specified size.
58: * This is used for example to translate bitplane pointers in custom.c */
59: check_func check;
1.1.1.8 ! root 60: /* For those banks that refer to real memory, we can save the whole trouble
! 61: of going through function calls, and instead simply grab the memory
! 62: ourselves. This holds the memory address where the start of memory is
! 63: for this particular bank. */
! 64: uae_u8 *baseaddr;
! 65: int flags;
! 66: uae_u32 mask;
! 67: uae_u32 start;
1.1 root 68: } addrbank;
69:
70:
71: #define bankindex(addr) (((uaecptr)(addr)) >> 16)
72:
73: #ifdef SAVE_MEMORY_BANKS
74: extern addrbank *mem_banks[65536];
75: #define get_mem_bank(addr) (*mem_banks[bankindex(addr)])
76: #define put_mem_bank(addr, b) (mem_banks[bankindex(addr)] = (b))
77: #else
78: extern addrbank mem_banks[65536];
79: #define get_mem_bank(addr) (mem_banks[bankindex(addr)])
80: #define put_mem_bank(addr, b) (mem_banks[bankindex(addr)] = *(b))
81: #endif
82:
1.1.1.8 ! root 83: extern bool memory_region_bus_error ( uaecptr addr );
1.1.1.6 root 84: extern void memory_init(uae_u32 nNewSTMemSize, uae_u32 nNewTTMemSize, uae_u32 nNewRomMemStart);
1.1.1.4 root 85: extern void memory_uninit (void);
1.1 root 86: extern void map_banks(addrbank *bank, int first, int count);
87:
88: #ifndef NO_INLINE_MEMORY_ACCESS
89:
90: #define longget(addr) (call_mem_get_func(get_mem_bank(addr).lget, addr))
91: #define wordget(addr) (call_mem_get_func(get_mem_bank(addr).wget, addr))
92: #define byteget(addr) (call_mem_get_func(get_mem_bank(addr).bget, addr))
93: #define longput(addr,l) (call_mem_put_func(get_mem_bank(addr).lput, addr, l))
94: #define wordput(addr,w) (call_mem_put_func(get_mem_bank(addr).wput, addr, w))
95: #define byteput(addr,b) (call_mem_put_func(get_mem_bank(addr).bput, addr, b))
96:
97: #else
98:
99: extern uae_u32 alongget(uaecptr addr);
100: extern uae_u32 awordget(uaecptr addr);
101: extern uae_u32 longget(uaecptr addr);
102: extern uae_u32 wordget(uaecptr addr);
103: extern uae_u32 byteget(uaecptr addr);
104: extern void longput(uaecptr addr, uae_u32 l);
105: extern void wordput(uaecptr addr, uae_u32 w);
106: extern void byteput(uaecptr addr, uae_u32 b);
107:
108: #endif
109:
110:
1.1.1.5 root 111: static inline uae_u32 get_long(uaecptr addr)
1.1 root 112: {
1.1.1.5 root 113: return longget(addr);
1.1 root 114: }
1.1.1.5 root 115:
116: static inline uae_u32 get_word(uaecptr addr)
1.1 root 117: {
1.1.1.5 root 118: return wordget(addr);
1.1 root 119: }
1.1.1.5 root 120:
121: static inline uae_u32 get_byte(uaecptr addr)
1.1 root 122: {
1.1.1.5 root 123: return byteget(addr);
1.1 root 124: }
1.1.1.5 root 125:
126: static inline void put_long(uaecptr addr, uae_u32 l)
1.1 root 127: {
1.1.1.5 root 128: longput(addr, l);
1.1 root 129: }
1.1.1.5 root 130:
131: static inline void put_word(uaecptr addr, uae_u32 w)
1.1 root 132: {
1.1.1.5 root 133: wordput(addr, w);
1.1 root 134: }
1.1.1.5 root 135:
136: static inline void put_byte(uaecptr addr, uae_u32 b)
1.1 root 137: {
1.1.1.5 root 138: byteput(addr, b);
1.1 root 139: }
140:
1.1.1.5 root 141: static inline uae_u8 *get_real_address(uaecptr addr)
1.1 root 142: {
143: return get_mem_bank(addr).xlateaddr(addr);
144: }
145:
1.1.1.5 root 146: static inline int valid_address(uaecptr addr, uae_u32 size)
1.1 root 147: {
148: return get_mem_bank(addr).check(addr, size);
149: }
150:
151:
1.1.1.3 root 152: #endif /* UAE_MEMORY_H */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.