5 Copyright (C) 2000-2008 Neil Cafferkey
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 #include <exec/types.h>
26 #include <exec/resident.h>
27 #include <utility/utility.h>
29 #include <proto/exec.h>
33 #include "device_protos.h"
36 /* Private prototypes */
38 static struct DevBase
*MOSDevInit(struct DevBase
*dev_base
, APTR seg_list
,
39 struct DevBase
*base
);
40 static BYTE
MOSDevOpen();
41 static APTR
MOSDevClose();
42 static APTR
MOSDevExpunge();
43 static VOID
MOSDevBeginIO();
44 static VOID
MOSDevAbortIO();
45 static BOOL
RXFunction(struct IOSana2Req
*request
, APTR buffer
, ULONG size
);
46 static BOOL
TXFunction(APTR buffer
, struct IOSana2Req
*request
, ULONG size
);
47 static UBYTE
*DMATXFunction(struct IOSana2Req
*request
);
50 extern const APTR init_data
;
51 extern const struct Resident rom_tag
;
52 extern const TEXT device_name
[];
53 extern const TEXT version_string
[];
56 static const APTR mos_vectors
[] =
58 (APTR
)FUNCARRAY_32BIT_NATIVE
,
69 static const APTR mos_init_table
[] =
71 (APTR
)sizeof(struct DevBase
),
78 const struct Resident mos_rom_tag
=
81 (struct Resident
*)&mos_rom_tag
,
83 RTF_AUTOINIT
| RTF_PPC
,
88 (STRPTR
)version_string
,
93 static const struct EmulLibEntry int_trap
=
102 /****i* atheros.device/MOSDevInit ******************************************
107 ****************************************************************************
111 static struct DevBase
*MOSDevInit(struct DevBase
*dev_base
, APTR seg_list
,
112 struct DevBase
*base
)
114 base
= DevInit(dev_base
, seg_list
, base
);
118 base
->wrapper_int_code
= (APTR
)&int_trap
;
125 /****i* atheros.device/MOSDevOpen ******************************************
130 ****************************************************************************
134 static BYTE
MOSDevOpen()
136 struct IOSana2Req
*request
;
137 struct Opener
*opener
;
140 request
= (APTR
)REG_A1
;
141 error
= DevOpen(request
, REG_D0
, REG_D1
, (APTR
)REG_A6
);
143 /* Set up wrapper hooks to hide 68k emulation */
147 opener
= request
->ios2_BufferManagement
;
148 opener
->real_rx_function
= opener
->rx_function
;
149 opener
->real_tx_function
= opener
->tx_function
;
150 opener
->rx_function
= (APTR
)RXFunction
;
151 opener
->tx_function
= (APTR
)TXFunction
;
152 if(opener
->dma_tx_function
!= NULL
)
154 opener
->real_dma_tx_function
= opener
->dma_tx_function
;
155 opener
->dma_tx_function
= (APTR
)DMATXFunction
;
164 /****i* atheros.device/MOSDevClose *****************************************
169 ****************************************************************************
173 static APTR
MOSDevClose()
175 return DevClose((APTR
)REG_A1
, (APTR
)REG_A6
);
180 /****i* atheros.device/MOSDevExpunge ***************************************
185 ****************************************************************************
189 static APTR
MOSDevExpunge()
191 return DevExpunge((APTR
)REG_A6
);
196 /****i* atheros.device/MOSDevBeginIO ***************************************
201 ****************************************************************************
205 static VOID
MOSDevBeginIO()
207 struct IOSana2Req
*request
= (APTR
)REG_A1
;
209 /* Replace caller's cookie with our own */
211 switch(request
->ios2_Req
.io_Command
)
218 request
->ios2_StatData
= request
->ios2_Data
;
219 request
->ios2_Data
= request
;
222 DevBeginIO(request
, (APTR
)REG_A6
);
229 /****i* atheros.device/MOSDevAbortIO ***************************************
232 * MOSDevAbortIO -- Try to stop a request.
234 ****************************************************************************
238 static VOID
MOSDevAbortIO()
240 DevAbortIO((APTR
)REG_A1
, (APTR
)REG_A6
);
245 /****i* atheros.device/RXFunction ******************************************
250 ****************************************************************************
254 static BOOL
RXFunction(struct IOSana2Req
*request
, APTR buffer
, ULONG size
)
256 struct DevBase
*base
;
257 struct EmulCaos context
;
258 struct Opener
*opener
;
261 base
= (struct DevBase
*)request
->ios2_Req
.io_Device
;
262 opener
= request
->ios2_BufferManagement
;
263 cookie
= request
->ios2_StatData
;
264 request
->ios2_Data
= cookie
;
266 context
.caos_Un
.Function
= (APTR
)opener
->real_rx_function
;
267 context
.reg_a0
= (ULONG
)cookie
;
268 context
.reg_a1
= (ULONG
)buffer
;
269 context
.reg_d0
= size
;
270 return MyEmulHandle
->EmulCall68k(&context
);
275 /****i* atheros.device/TXFunction ******************************************
280 ****************************************************************************
284 static BOOL
TXFunction(APTR buffer
, struct IOSana2Req
*request
, ULONG size
)
286 struct DevBase
*base
;
287 struct EmulCaos context
;
288 struct Opener
*opener
;
291 base
= (struct DevBase
*)request
->ios2_Req
.io_Device
;
292 opener
= request
->ios2_BufferManagement
;
293 cookie
= request
->ios2_StatData
;
294 request
->ios2_Data
= cookie
;
296 context
.caos_Un
.Function
= (APTR
)opener
->real_tx_function
;
297 context
.reg_a0
= (ULONG
)buffer
;
298 context
.reg_a1
= (ULONG
)cookie
;
299 context
.reg_d0
= size
;
300 return MyEmulHandle
->EmulCall68k(&context
);
305 /****i* atheros.device/DMATXFunction ***************************************
310 ****************************************************************************
314 static UBYTE
*DMATXFunction(struct IOSana2Req
*request
)
316 struct DevBase
*base
;
317 struct EmulCaos context
;
318 struct Opener
*opener
;
321 base
= (struct DevBase
*)request
->ios2_Req
.io_Device
;
322 opener
= request
->ios2_BufferManagement
;
323 cookie
= request
->ios2_StatData
;
324 request
->ios2_Data
= cookie
;
326 context
.caos_Un
.Function
= (APTR
)opener
->real_dma_tx_function
;
327 context
.reg_a0
= (ULONG
)cookie
;
328 return (UBYTE
*)MyEmulHandle
->EmulCall68k(&context
);
333 /****i* atheros.device/MOSInt **********************************************
338 ****************************************************************************
345 BOOL (*int_code
)(APTR
, APTR
);
347 int_data
= (APTR
)REG_A1
;
348 int_code
= int_data
[0];
349 return int_code(int_data
[1], int_code
);