-
+ B94991DF360AAA3C332DBEF2217079DBF8F67D37CB2E09BD4F3B5C093E789B90E8FCC33831D32204184D79EC320A74BB55F64A2215DDE60BB61DD5716983A6D6
m/bus.asm
(0 . 0)(1 . 173)
62 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
63 ;; ;;
64 ;; This file is part of 'M', a MIPS system emulator. ;;
65 ;; ;;
66 ;; (C) 2019 Stanislav Datskovskiy ( www.loper-os.org ) ;;
67 ;; http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html ;;
68 ;; ;;
69 ;; You do not have, nor can you ever acquire the right to use, copy or ;;
70 ;; distribute this software ; Should you use this software for any purpose, ;;
71 ;; or copy and distribute it to anyone or in any manner, you are breaking ;;
72 ;; the laws of whatever soi-disant jurisdiction, and you promise to ;;
73 ;; continue doing so for the indefinite future. In any case, please ;;
74 ;; always : read and understand any software ; verify any PGP signatures ;;
75 ;; that you use - for any purpose. ;;
76 ;; ;;
77 ;; See also http://trilema.com/2015/a-new-software-licensing-paradigm . ;;
78 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
79
80 ;; Universal MMIO Bus Dispatcher. Addition of new simulated devices will NOT
81 ;; require any changes to this mechanism. Be sure to add any device component
82 ;; to 'devices.asm'.
83 ;; NOTE 1: The DECLARE_BUS_DEVICE macro is valid ONLY inside text included by
84 ;; 'devices.asm' !
85 ;; NOTE 2: Currently there is NO support for devices which demand a
86 ;; non-contiguous MMIO segment !
87 ;; NOTE 3: Make ABSOLUTELY certain that the MMIO Device ranges do not overlap!
88
89 section .text
90
91 ;-----------------------------------------------------------------------------
92 ; MMIO_ADDR
93 ;-----------------------------------------------------------------------------
94 %define MMIO_ADDR(A) (MMIO_BASE + A) ; Address to be offset from MMIO_BASE
95 ;-----------------------------------------------------------------------------
96
97 ;-----------------------------------------------------------------------------
98 ; Proclaim Device and connect it to Bus; %1: Name, %2: Base Addr, %3: Top Addr
99 ;-----------------------------------------------------------------------------
100 %macro DECLARE_BUS_DEVICE 3
101
102 %define %1_BASE MMIO_ADDR(%2) ;; Declare DEVICE_BASE MMIO Address (first)
103 %define %1_TOP MMIO_ADDR(%3) ;; Declare DEVICE_TOP MMIO Address (last)
104
105 ;; Put this device's MMIO range in _Phys_Device_Read_Word's set of cases
106 SECTION .PD_Rd_Word
107 JMP_If_In eax, %1_BASE, %1_TOP, _PD_Read_Word_%1
108
109 ;; Put this device's MMIO range in _Phys_Device_Write_Word's set of cases
110 SECTION .PD_Wr_Word
111 JMP_If_In eax, %1_BASE, %1_TOP, _PD_Write_Word_%1
112
113 ;; Put this device's MMIO range in _Phys_Device_Read_Byte's set of cases
114 SECTION .PD_Rd_Byte
115 JMP_If_In eax, %1_BASE, %1_TOP, _PD_Read_Byte_%1
116
117 ;; Put this device's MMIO range in _Phys_Device_Write_Byte's set of cases
118 SECTION .PD_Wr_Byte
119 JMP_If_In eax, %1_BASE, %1_TOP, _PD_Write_Byte_%1
120
121 ;; Put this device's initialization routine in the list of
122 ;; called by _Phys_Devices_Initialize:
123 SECTION .PD_Initialize
124 call _Device_Init_%1
125
126 ;; Put this device's termination routine in the list of
127 ;; called by _Phys_Devices_Shutdown:
128 SECTION .PD_Shutdown
129 call _Device_Shutdown_%1
130
131 section .text ;; Resume the .text section.
132
133 %endmacro
134 ;-----------------------------------------------------------------------------
135
136 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
137 ;; Prologues of Physical Device Bus Wires ;;
138 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
139
140 ;-----------------------------------------------------------------------------
141 ; Device Read Word -- we jump here from _Virt_Read_Word if pAddr in range
142 ;-----------------------------------------------------------------------------
143 section .PD_Rd_Word progbits exec alloc nowrite
144 _Phys_Device_Read_Word:
145 ;-----------------------------------------------------------------------------
146
147 ;-----------------------------------------------------------------------------
148 ; Device Write Word -- we jump here from _Virt_Write_Word if pAddr in range
149 ;-----------------------------------------------------------------------------
150 section .PD_Wr_Word progbits exec alloc nowrite
151 _Phys_Device_Write_Word:
152 ;-----------------------------------------------------------------------------
153
154 ;-----------------------------------------------------------------------------
155 ; Device Read Byte -- we jump here from _Virt_Read_Byte if pAddr in range
156 ;-----------------------------------------------------------------------------
157 section .PD_Rd_Byte progbits exec alloc nowrite
158 _Phys_Device_Read_Byte:
159 ;-----------------------------------------------------------------------------
160
161 ;-----------------------------------------------------------------------------
162 ; Device Write Byte -- we jump here from _Virt_Write_Byte if pAddr in range
163 ;-----------------------------------------------------------------------------
164 section .PD_Wr_Byte progbits exec alloc nowrite
165 _Phys_Device_Write_Byte:
166 ;-----------------------------------------------------------------------------
167
168 ;-----------------------------------------------------------------------------
169 ; Device Initialization
170 ;-----------------------------------------------------------------------------
171 section .PD_Initialize progbits exec alloc nowrite
172 _Phys_Devices_Initialize:
173 ;-----------------------------------------------------------------------------
174
175 ;-----------------------------------------------------------------------------
176 ; Device Shutdown
177 ;-----------------------------------------------------------------------------
178 section .PD_Shutdown progbits exec alloc nowrite
179 _Phys_Devices_Shutdown:
180 ;-----------------------------------------------------------------------------
181
182 ;; ALL Device implementations MUST be included from:
183 %include "devices/devices.asm"
184
185 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
186 ;; Epilogues of Physical Device Bus Wires ;;
187 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
188
189 ;-----------------------------------------------------------------------------
190 SECTION .PD_Rd_Word
191 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
192 ;; Unknown Device ?
193 xor eax, eax ; Always return 0
194 ACHTUNG "Read Word from Unknown Device?" ; TODO: print detail
195 ret
196 ;-----------------------------------------------------------------------------
197
198 ;-----------------------------------------------------------------------------
199 SECTION .PD_Wr_Word
200 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
201 ;; Unknown Device ?
202 ACHTUNG "Write Word to Unknown Device?" ; TODO: print detail
203 ret
204 ;-----------------------------------------------------------------------------
205
206 ;-----------------------------------------------------------------------------
207 SECTION .PD_Rd_Byte
208 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
209 ;; Unknown Device ?
210 xor eax, eax ; Always return 0
211 ACHTUNG "Read Byte from Unknown Device?" ; TODO: print detail
212 ret
213 ;-----------------------------------------------------------------------------
214
215 ;-----------------------------------------------------------------------------
216 SECTION .PD_Wr_Byte
217 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
218 ;; Unknown Device ?
219 ACHTUNG "Write Byte to Unknown Device?" ; TODO: print detail
220 ret
221 ;-----------------------------------------------------------------------------
222
223 ;-----------------------------------------------------------------------------
224 SECTION .PD_Initialize
225 ret
226 ;-----------------------------------------------------------------------------
227
228 ;-----------------------------------------------------------------------------
229 SECTION .PD_Shutdown
230 ret
231 ;-----------------------------------------------------------------------------
232
233 ;; Back to code section:
234 section .text