3 Copyright (C) 2000-2005 Neil Cafferkey
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23 #include <exec/types.h>
24 #include <exec/resident.h>
25 #include <utility/utility.h>
29 /* Private prototypes */
31 static BYTE
MOSDevOpen();
32 static APTR
MOSDevClose();
33 static APTR
MOSDevExpunge();
34 static VOID
MOSDevBeginIO();
35 static VOID
MOSDevAbortIO();
36 static BOOL
RXFunction(struct IOSana2Req
*request
, APTR buffer
, ULONG size
);
37 static BOOL
TXFunction(APTR buffer
, struct IOSana2Req
*request
, ULONG size
);
38 static UBYTE
*DMATXFunction(struct IOSana2Req
*request
);
41 extern const APTR mos_vectors
[];
42 extern const APTR mos_init_table
[];
43 extern const struct Resident rom_tag
;
44 extern const APTR init_table
[];
45 extern const TEXT device_name
[];
46 extern const TEXT version_string
[];
49 static const TEXT openpci_name
[] = "openpci.library";
52 const struct Resident mos_rom_tag
=
55 (struct Resident
*)&mos_rom_tag
,
57 RTF_AUTOINIT
| RTF_PPC
,
62 (STRPTR
)version_string
,
67 static const struct EmulLibEntry int_trap
=
78 static const APTR mos_vectors
[] =
80 (APTR
)FUNCARRAY_32BIT_NATIVE
,
91 static const APTR mos_init_table
[] =
93 (APTR
)sizeof(struct DevBase
),
101 /****i* intelpro100.device/MOSDevOpen **************************************
106 ****************************************************************************
110 static BYTE
MOSDevOpen()
112 struct IOSana2Req
*request
;
113 struct Opener
*opener
;
116 request
= (APTR
)REG_A1
;
117 error
= DevOpen(request
, REG_D0
, REG_D1
, (APTR
)REG_A6
);
119 /* Set up wrapper hooks to hide 68k emulation */
123 opener
= request
->ios2_BufferManagement
;
124 opener
->real_rx_function
= opener
->rx_function
;
125 opener
->real_tx_function
= opener
->tx_function
;
126 opener
->rx_function
= (APTR
)RXFunction
;
127 opener
->tx_function
= (APTR
)TXFunction
;
128 if(opener
->dma_tx_function
!= NULL
)
130 opener
->real_dma_tx_function
= opener
->dma_tx_function
;
131 opener
->dma_tx_function
= (APTR
)DMATXFunction
;
140 /****i* intelpro100.device/MOSDevClose *************************************
145 ****************************************************************************
149 static APTR
MOSDevClose()
151 return DevClose((APTR
)REG_A1
, (APTR
)REG_A6
);
156 /****i* intelpro100.device/MOSDevExpunge ***********************************
161 ****************************************************************************
165 static APTR
MOSDevExpunge()
167 return DevExpunge((APTR
)REG_A6
);
172 /****i* intelpro100.device/MOSDevBeginIO ***********************************
177 ****************************************************************************
181 static VOID
MOSDevBeginIO()
183 struct IOSana2Req
*request
= (APTR
)REG_A1
;
185 /* Replace caller's cookie with our own */
187 switch(request
->ios2_Req
.io_Command
)
194 request
->ios2_StatData
= request
->ios2_Data
;
195 request
->ios2_Data
= request
;
198 DevBeginIO(request
, (APTR
)REG_A6
);
205 /****i* intelpro100.device/MOSDevAbortIO ***********************************
208 * MOSDevAbortIO -- Try to stop a request.
210 ****************************************************************************
214 static VOID
MOSDevAbortIO()
216 DevAbortIO((APTR
)REG_A1
, (APTR
)REG_A6
);
221 /****i* intelpro100.device/RXFunction **************************************
226 ****************************************************************************
230 static BOOL
RXFunction(struct IOSana2Req
*request
, APTR buffer
, ULONG size
)
232 struct DevBase
*base
;
233 struct EmulCaos context
;
234 struct Opener
*opener
;
237 base
= (struct DevBase
*)request
->ios2_Req
.io_Device
;
238 opener
= request
->ios2_BufferManagement
;
239 cookie
= request
->ios2_StatData
;
240 request
->ios2_Data
= cookie
;
242 context
.caos_Un
.Function
= (APTR
)opener
->real_rx_function
;
243 context
.reg_a0
= (ULONG
)cookie
;
244 context
.reg_a1
= (ULONG
)buffer
;
245 context
.reg_d0
= size
;
246 return MyEmulHandle
->EmulCall68k(&context
);
251 /****i* intelpro100.device/TXFunction **************************************
256 ****************************************************************************
260 static BOOL
TXFunction(APTR buffer
, struct IOSana2Req
*request
, ULONG size
)
262 struct DevBase
*base
;
263 struct EmulCaos context
;
264 struct Opener
*opener
;
267 base
= (struct DevBase
*)request
->ios2_Req
.io_Device
;
268 opener
= request
->ios2_BufferManagement
;
269 cookie
= request
->ios2_StatData
;
270 request
->ios2_Data
= cookie
;
272 context
.caos_Un
.Function
= (APTR
)opener
->real_tx_function
;
273 context
.reg_a0
= (ULONG
)buffer
;
274 context
.reg_a1
= (ULONG
)cookie
;
275 context
.reg_d0
= size
;
276 return MyEmulHandle
->EmulCall68k(&context
);
281 /****i* intelpro100.device/DMATXFunction ***********************************
286 ****************************************************************************
290 static UBYTE
*DMATXFunction(struct IOSana2Req
*request
)
292 struct DevBase
*base
;
293 struct EmulCaos context
;
294 struct Opener
*opener
;
297 base
= (struct DevBase
*)request
->ios2_Req
.io_Device
;
298 opener
= request
->ios2_BufferManagement
;
299 cookie
= request
->ios2_StatData
;
300 request
->ios2_Data
= cookie
;
302 context
.caos_Un
.Function
= (APTR
)opener
->real_dma_tx_function
;
303 context
.reg_a0
= (ULONG
)cookie
;
304 return (UBYTE
*)MyEmulHandle
->EmulCall68k(&context
);
309 /****i* intelpro100.device/MOSInt ******************************************
314 ****************************************************************************
321 BOOL (*int_code
)(APTR
, APTR
);
323 int_data
= (APTR
)REG_A1
;
324 int_code
= int_data
[0];
325 return int_code(int_data
[1], int_code
);