1 /* $Id: m68k.h,v 1.8 2009/08/29 18:02:48 fredette Exp $ */
2 
3 /* tme/ic/m68k.h - public header file for Motorola 68k emulation */
4 
5 /*
6  * Copyright (c) 2002, 2003 Matt Fredette
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *      This product includes software developed by Matt Fredette.
20  * 4. The name of the author may not be used to endorse or promote products
21  *    derived from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
27  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #ifndef _TME_IC_M68K_H
37 #define _TME_IC_M68K_H
38 
39 #include <tme/common.h>
40 _TME_RCSID("$Id: m68k.h,v 1.8 2009/08/29 18:02:48 fredette Exp $");
41 
42 /* includes: */
43 #include <tme/element.h>
44 #include <tme/generic/bus.h>
45 
46 /* macros: */
47 
48 /* function codes: */
49 #define TME_M68K_FC_0	(0)
50 #define TME_M68K_FC_UD	(1)
51 #define TME_M68K_FC_UP	(2)
52 #define TME_M68K_FC_3	(3)
53 #define TME_M68K_FC_4	(4)
54 #define TME_M68K_FC_SD	(5)
55 #define TME_M68K_FC_SP	(6)
56 #define TME_M68K_FC_7	(7)
57 
58 /* the minimum and maximum IPL levels: */
59 #define TME_M68K_IPL_NONE	(0)
60 #define TME_M68K_IPL_MIN	(1)
61 #define TME_M68K_IPL_MAX	(7)
62 #define TME_M68K_IPL_NMI	(7)
63 
64 /* these busy and unbusy a TLB entry: */
65 #define tme_m68k_tlb_busy(tlb)					\
66   tme_token_busy(&(tlb)->tme_m68k_tlb_token)
67 #define tme_m68k_tlb_unbusy(tlb)				\
68   tme_token_unbusy(&(tlb)->tme_m68k_tlb_token)
69 
70 /* these test the validity of a TLB entry: */
71 #define tme_m68k_tlb_is_valid(tlb)				\
72   tme_token_is_valid(&(tlb)->tme_m68k_tlb_token)
73 #define tme_m68k_tlb_is_invalid(tlb)				\
74   tme_token_is_invalid(&(tlb)->tme_m68k_tlb_token)
75 
76 /* this indexes an m68k bus router array for an m68k with a port size
77    of 8 * (2 ^ siz_lg2) bits: */
78 #define TME_M68K_BUS_ROUTER_INDEX(siz_lg2, cycle_size, address)	\
79 (((								\
80    /* by the maximum cycle size: */				\
81    ((cycle_size) - 1)						\
82 								\
83    /* by the address alignment: */				\
84    << siz_lg2)							\
85   + ((address) & ((1 << (siz_lg2)) - 1)))			\
86 								\
87  /* factor in the size of the generic bus router array: */	\
88  * TME_BUS_ROUTER_SIZE(siz_lg2))
89 
90 /* this gives the number of entries that must be in a generic bus
91    router array for a device with a bus size of 8 * (2 ^ siz_lg2)
92    bits: */
93 #define TME_M68K_BUS_ROUTER_SIZE(siz_lg2)			\
94   TME_M68K_BUS_ROUTER_INDEX(siz_lg2, (1 << (siz_lg2)) + 1, 0)
95 
96 /* structures: */
97 
98 /* an m68k TLB entry: */
99 struct tme_m68k_tlb {
100 
101   /* the generic bus TLB associated with this TLB entry: */
102   struct tme_bus_tlb tme_m68k_tlb_bus_tlb;
103 #define tme_m68k_tlb_linear_first tme_m68k_tlb_bus_tlb.tme_bus_tlb_addr_first
104 #define tme_m68k_tlb_linear_last tme_m68k_tlb_bus_tlb.tme_bus_tlb_addr_last
105 #define tme_m68k_tlb_bus_rwlock tme_m68k_tlb_bus_tlb.tme_bus_tlb_rwlock
106 #define tme_m68k_tlb_cycles_ok tme_m68k_tlb_bus_tlb.tme_bus_tlb_cycles_ok
107 #define tme_m68k_tlb_addr_offset tme_m68k_tlb_bus_tlb.tme_bus_tlb_addr_offset
108 #define tme_m68k_tlb_addr_shift tme_m68k_tlb_bus_tlb.tme_bus_tlb_addr_shift
109 #define tme_m68k_tlb_emulator_off_read tme_m68k_tlb_bus_tlb.tme_bus_tlb_emulator_off_read
110 #define tme_m68k_tlb_emulator_off_write tme_m68k_tlb_bus_tlb.tme_bus_tlb_emulator_off_write
111 
112   /* the token for this TLB entry: */
113   struct tme_token tme_m68k_tlb_token;
114 
115   /* the bus context for this TLB entry: */
116   tme_bus_context_t tme_m68k_tlb_bus_context;
117 
118   /* the function codes handled by this entry: */
119   unsigned int tme_m68k_tlb_function_codes_mask;
120 };
121 
122 /* an m68k bus connection: */
123 struct tme_m68k_bus_connection {
124 
125   /* a generic bus connection: */
126   struct tme_bus_connection tme_m68k_bus_connection;
127 
128   /* the m68k interrupt function: */
129   int (*tme_m68k_bus_interrupt) _TME_P((struct tme_m68k_bus_connection *, unsigned int));
130 
131   /* the m68k TLB entry filler: */
132   int (*tme_m68k_bus_tlb_fill) _TME_P((struct tme_m68k_bus_connection *, struct tme_m68k_tlb *,
133 				       unsigned int, tme_uint32_t, unsigned int));
134 
135   /* the m68k m6888x enabler: */
136   int (*tme_m68k_bus_m6888x_enable) _TME_P((struct tme_m68k_bus_connection *, int));
137 };
138 
139 /* globals: */
140 extern _tme_const tme_bus_lane_t tme_m68k_router_16[];
141 extern _tme_const tme_bus_lane_t tme_m68k_router_32[];
142 
143 #endif /* !_TME_IC_M68K_H */
144