3 Copyright (C) 2000-2008 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>
27 #include <proto/exec.h>
31 #include "device_protos.h"
34 /* Private prototypes */
36 static struct DevBase
*MOSDevInit(struct DevBase
*dev_base
, APTR seg_list
,
37 struct DevBase
*base
);
38 static BYTE
MOSDevOpen();
39 static APTR
MOSDevClose();
40 static APTR
MOSDevExpunge();
41 static VOID
MOSDevBeginIO();
42 static VOID
MOSDevAbortIO();
43 static BOOL
RXFunction(struct IOSana2Req
*request
, APTR buffer
, ULONG size
);
44 static BOOL
TXFunction(APTR buffer
, struct IOSana2Req
*request
, ULONG size
);
45 static UBYTE
*DMATXFunction(struct IOSana2Req
*request
);
48 extern const APTR init_data
;
49 extern const struct Resident rom_tag
;
50 extern const TEXT device_name
[];
51 extern const TEXT version_string
[];
54 static const TEXT openpci_name
[] = "openpci.library";
57 static const APTR mos_vectors
[] =
59 (APTR
)FUNCARRAY_32BIT_NATIVE
,
70 static const APTR mos_init_table
[] =
72 (APTR
)sizeof(struct DevBase
),
79 const struct Resident mos_rom_tag
=
82 (struct Resident
*)&mos_rom_tag
,
84 RTF_AUTOINIT
| RTF_PPC
,
89 (STRPTR
)version_string
,
94 static const struct EmulLibEntry int_trap
=
103 /****i* etherlink3.device/MOSDevInit ***************************************
108 ****************************************************************************
112 static struct DevBase
*MOSDevInit(struct DevBase
*dev_base
, APTR seg_list
,
113 struct DevBase
*base
)
115 base
= DevInit(dev_base
, seg_list
, base
);
119 base
->openpci_base
= OpenLibrary(openpci_name
, OPENPCI_VERSION
);
120 base
->wrapper_int_code
= (APTR
)&int_trap
;
127 /****i* etherlink3.device/MOSDevOpen ***************************************
132 ****************************************************************************
136 static BYTE
MOSDevOpen()
138 struct IOSana2Req
*request
;
139 struct Opener
*opener
;
142 request
= (APTR
)REG_A1
;
143 error
= DevOpen(request
, REG_D0
, REG_D1
, (APTR
)REG_A6
);
145 /* Set up wrapper hooks to hide 68k emulation */
149 opener
= request
->ios2_BufferManagement
;
150 opener
->real_rx_function
= opener
->rx_function
;
151 opener
->real_tx_function
= opener
->tx_function
;
152 opener
->rx_function
= (APTR
)RXFunction
;
153 opener
->tx_function
= (APTR
)TXFunction
;
154 if(opener
->dma_tx_function
!= NULL
)
156 opener
->real_dma_tx_function
= opener
->dma_tx_function
;
157 opener
->dma_tx_function
= (APTR
)DMATXFunction
;
166 /****i* etherlink3.device/MOSDevClose **************************************
171 ****************************************************************************
175 static APTR
MOSDevClose()
177 return DevClose((APTR
)REG_A1
, (APTR
)REG_A6
);
182 /****i* etherlink3.device/MOSDevExpunge ************************************
187 ****************************************************************************
191 static APTR
MOSDevExpunge()
193 return DevExpunge((APTR
)REG_A6
);
198 /****i* etherlink3.device/MOSDevBeginIO ************************************
203 ****************************************************************************
207 static VOID
MOSDevBeginIO()
209 struct IOSana2Req
*request
= (APTR
)REG_A1
;
211 /* Replace caller's cookie with our own */
213 switch(request
->ios2_Req
.io_Command
)
220 request
->ios2_StatData
= request
->ios2_Data
;
221 request
->ios2_Data
= request
;
224 DevBeginIO(request
, (APTR
)REG_A6
);
231 /****i* etherlink3.device/MOSDevAbortIO ************************************
234 * MOSDevAbortIO -- Try to stop a request.
236 ****************************************************************************
240 static VOID
MOSDevAbortIO()
242 DevAbortIO((APTR
)REG_A1
, (APTR
)REG_A6
);
247 /****i* etherlink3.device/RXFunction ***************************************
252 ****************************************************************************
256 static BOOL
RXFunction(struct IOSana2Req
*request
, APTR buffer
, ULONG size
)
258 struct DevBase
*base
;
259 struct EmulCaos context
;
260 struct Opener
*opener
;
263 base
= (struct DevBase
*)request
->ios2_Req
.io_Device
;
264 opener
= request
->ios2_BufferManagement
;
265 cookie
= request
->ios2_StatData
;
266 request
->ios2_Data
= cookie
;
268 context
.caos_Un
.Function
= (APTR
)opener
->real_rx_function
;
269 context
.reg_a0
= (ULONG
)cookie
;
270 context
.reg_a1
= (ULONG
)buffer
;
271 context
.reg_d0
= size
;
272 return MyEmulHandle
->EmulCall68k(&context
);
277 /****i* etherlink3.device/TXFunction ***************************************
282 ****************************************************************************
286 static BOOL
TXFunction(APTR buffer
, struct IOSana2Req
*request
, ULONG size
)
288 struct DevBase
*base
;
289 struct EmulCaos context
;
290 struct Opener
*opener
;
293 base
= (struct DevBase
*)request
->ios2_Req
.io_Device
;
294 opener
= request
->ios2_BufferManagement
;
295 cookie
= request
->ios2_StatData
;
296 request
->ios2_Data
= cookie
;
298 context
.caos_Un
.Function
= (APTR
)opener
->real_tx_function
;
299 context
.reg_a0
= (ULONG
)buffer
;
300 context
.reg_a1
= (ULONG
)cookie
;
301 context
.reg_d0
= size
;
302 return MyEmulHandle
->EmulCall68k(&context
);
307 /****i* etherlink3.device/DMATXFunction ************************************
312 ****************************************************************************
316 static UBYTE
*DMATXFunction(struct IOSana2Req
*request
)
318 struct DevBase
*base
;
319 struct EmulCaos context
;
320 struct Opener
*opener
;
323 base
= (struct DevBase
*)request
->ios2_Req
.io_Device
;
324 opener
= request
->ios2_BufferManagement
;
325 cookie
= request
->ios2_StatData
;
326 request
->ios2_Data
= cookie
;
328 context
.caos_Un
.Function
= (APTR
)opener
->real_dma_tx_function
;
329 context
.reg_a0
= (ULONG
)cookie
;
330 return (UBYTE
*)MyEmulHandle
->EmulCall68k(&context
);
335 /****i* etherlink3.device/MOSInt *******************************************
340 ****************************************************************************
347 BOOL (*int_code
)(APTR
, APTR
);
349 int_data
= (APTR
)REG_A1
;
350 int_code
= int_data
[0];
351 return int_code(int_data
[1], int_code
);