1 | /******************************************************************************
|
---|
2 | * idctest.c - main and only source file for the OS2AHCI IDC test driver
|
---|
3 | *
|
---|
4 | * This driver is used to test the ring 0 IDC interface of OS2AHCI.
|
---|
5 | * When this driver is opened by a Ring 3 process, it uses OS2AHCI's
|
---|
6 | * IDC interface to send it a test IOCTL that does nothing but beep.
|
---|
7 | *
|
---|
8 | * Authors: Christian Mueller, Markus Thielen
|
---|
9 | *
|
---|
10 | * This program is free software; you can redistribute it and/or modify
|
---|
11 | * it under the terms of the GNU General Public License as published by
|
---|
12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
13 | * (at your option) any later version.
|
---|
14 | *
|
---|
15 | * This program is distributed in the hope that it will be useful,
|
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | * GNU General Public License for more details.
|
---|
19 | *
|
---|
20 | * You should have received a copy of the GNU General Public License
|
---|
21 | * along with this program; if not, write to the Free Software
|
---|
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
23 | */
|
---|
24 |
|
---|
25 | /*---- includes --------------------------------------------------------------*/
|
---|
26 |
|
---|
27 | #define INCL_NOPMAPI
|
---|
28 | #define INCL_DOSINFOSEG
|
---|
29 | #define INCL_NO_SCB
|
---|
30 | #define INCL_DOSERRORS
|
---|
31 | #include <os2.h>
|
---|
32 | #include <dos.h>
|
---|
33 | #include <bseerr.h>
|
---|
34 | #include <dskinit.h>
|
---|
35 | #include <scb.h>
|
---|
36 |
|
---|
37 | #include <devhdr.h>
|
---|
38 | #include <iorb.h>
|
---|
39 | #include <strat2.h>
|
---|
40 | #include <reqpkt.h>
|
---|
41 |
|
---|
42 | #include <dhcalls.h>
|
---|
43 |
|
---|
44 | #include <addcalls.h>
|
---|
45 | #include <rmcalls.h>
|
---|
46 | #include <devclass.h>
|
---|
47 | #include <devcmd.h>
|
---|
48 | #include <rmbase.h>
|
---|
49 | #include "ahci-idc.h"
|
---|
50 |
|
---|
51 |
|
---|
52 | /*---- function proEtotypes ---------------------------------------------------*/
|
---|
53 |
|
---|
54 | extern APIRET APIENTRY DosPutMessage (USHORT hf,
|
---|
55 | USHORT cbMsg,
|
---|
56 | PCHAR pchMsg);
|
---|
57 |
|
---|
58 | static unsigned int strlen (PSZ s);
|
---|
59 |
|
---|
60 | static void memset (void _far *p,
|
---|
61 | unsigned int cb,
|
---|
62 | unsigned char byte);
|
---|
63 |
|
---|
64 | int init (RPINITIN _far *req);
|
---|
65 |
|
---|
66 | int c_strat (RPH _far *req);
|
---|
67 |
|
---|
68 | void drv_open (void);
|
---|
69 |
|
---|
70 |
|
---|
71 | /*---- global data -----------------------------------------------------------*/
|
---|
72 |
|
---|
73 | char init_msg[] = "\r\nOS2AHCI IDC Test Driver\r\n";
|
---|
74 | char init_fail[] = "Failed to attach to OS2AHCI$";
|
---|
75 | char init_ok[] = "up and running...\r\n";
|
---|
76 |
|
---|
77 | PFN Device_Help = 0;
|
---|
78 |
|
---|
79 | AHCI_ATTACH_AREA attach_data;
|
---|
80 | int last_cmd;
|
---|
81 |
|
---|
82 | extern char _cdecl end_of_data; /* label at the end of all data segments */
|
---|
83 | extern void _cdecl _near end_of_code(); /* label at the end of all code segments */
|
---|
84 |
|
---|
85 | /******************************************************************************
|
---|
86 | * c_strat_idc - IDC test driver entry point
|
---|
87 | */
|
---|
88 | int c_strat_idc(RPH _far *req)
|
---|
89 |
|
---|
90 | {
|
---|
91 | USHORT result = STDON;
|
---|
92 | last_cmd = req->Cmd;
|
---|
93 |
|
---|
94 | switch (last_cmd) {
|
---|
95 |
|
---|
96 | case CMDInit:
|
---|
97 | return (init((RPINITIN _far *) req));
|
---|
98 |
|
---|
99 | case CMDOpen:
|
---|
100 | drv_open();
|
---|
101 | return(STDON);
|
---|
102 |
|
---|
103 | case CMDGenIOCTL:
|
---|
104 | drv_open();
|
---|
105 | return(STDON);
|
---|
106 |
|
---|
107 | case CMDClose:
|
---|
108 | return(STDON);
|
---|
109 |
|
---|
110 | default:
|
---|
111 | break;
|
---|
112 |
|
---|
113 | }
|
---|
114 |
|
---|
115 | return STDON | STERR | ERROR_BAD_COMMAND;
|
---|
116 | }
|
---|
117 |
|
---|
118 | /******************************************************************************
|
---|
119 | * init
|
---|
120 | */
|
---|
121 | int init(RPINITIN _far *req)
|
---|
122 | {
|
---|
123 |
|
---|
124 | char *ahci_name = "OS2AHCI$ ";
|
---|
125 | RPINITOUT _far *rsp = (RPINITOUT _far *) req;
|
---|
126 | int ret = STDON;
|
---|
127 |
|
---|
128 | /* store DevHelp entry point */
|
---|
129 | Device_Help = req->DevHlpEP;
|
---|
130 |
|
---|
131 | DosPutMessage(1, strlen(init_msg), init_msg);
|
---|
132 |
|
---|
133 | /* attach to OS2AHCI.ADD */
|
---|
134 | if (DevHelp_AttachDD(ahci_name, (NPBYTE) &attach_data)) {
|
---|
135 | /* failed to attach */
|
---|
136 | DosPutMessage(1, strlen(init_fail), init_fail);
|
---|
137 | rsp->CodeEnd = 0;
|
---|
138 | rsp->DataEnd = 0;
|
---|
139 | ret = STDON | ERROR_I24_QUIET_INIT_FAIL;
|
---|
140 |
|
---|
141 | } else {
|
---|
142 | /* successfully attached */
|
---|
143 | DosPutMessage(1, strlen(init_ok), init_ok);
|
---|
144 | rsp->CodeEnd = (USHORT) end_of_code;
|
---|
145 | rsp->DataEnd = (USHORT) &end_of_data;
|
---|
146 | ret = STDON;
|
---|
147 | }
|
---|
148 |
|
---|
149 | return ret;
|
---|
150 | }
|
---|
151 |
|
---|
152 | /******************************************************************************
|
---|
153 | * drv_open() - this is called when a ring 3 process opens us with DosOpen.
|
---|
154 | * We then call into OS2AHCI's IDC interface with a test IOCTL that causes
|
---|
155 | * OS2AHCI to beep.
|
---|
156 | */
|
---|
157 | void drv_open(void)
|
---|
158 | {
|
---|
159 | RP_GENIOCTL rp_ioctl;
|
---|
160 | unsigned short target_ds = attach_data.prot_ds;
|
---|
161 | PFN_AHCI_IDC_ENTRY func = attach_data.prot_entry_point;
|
---|
162 |
|
---|
163 | memset((void _far*) &rp_ioctl, sizeof(rp_ioctl), 0x00);
|
---|
164 |
|
---|
165 | /* prepare request packet */
|
---|
166 | rp_ioctl.rph.Len = (UCHAR) sizeof(rp_ioctl);
|
---|
167 | rp_ioctl.rph.Cmd = CMDGenIOCTL;
|
---|
168 | rp_ioctl.Category = OS2AHCI_IDC_CATEGORY;
|
---|
169 | rp_ioctl.Function = OS2AHCI_IDC_BEEP;
|
---|
170 |
|
---|
171 | /* call IDC entry point in Assembler;
|
---|
172 | * IDC calling convention is to set DS to the data segment of
|
---|
173 | * the target driver and ES to the segment of the request packet.
|
---|
174 | */
|
---|
175 | _asm {
|
---|
176 | push ds
|
---|
177 | push es
|
---|
178 | push bx
|
---|
179 | push si
|
---|
180 | push di
|
---|
181 |
|
---|
182 | push ss
|
---|
183 | pop es
|
---|
184 | lea bx, rp_ioctl
|
---|
185 | mov ds, target_ds
|
---|
186 | call dword ptr [func]
|
---|
187 |
|
---|
188 | pop di
|
---|
189 | pop si
|
---|
190 | pop bx
|
---|
191 | pop es
|
---|
192 | pop ds
|
---|
193 | }
|
---|
194 |
|
---|
195 |
|
---|
196 | }
|
---|
197 |
|
---|
198 |
|
---|
199 | /******************************************************************************
|
---|
200 | * strlen
|
---|
201 | */
|
---|
202 | static unsigned int strlen(PSZ s)
|
---|
203 | {
|
---|
204 | int i = 0;
|
---|
205 | while (*s++) {
|
---|
206 | i++;
|
---|
207 | }
|
---|
208 |
|
---|
209 | return (i);
|
---|
210 | }
|
---|
211 |
|
---|
212 | /******************************************************************************
|
---|
213 | * memset
|
---|
214 | */
|
---|
215 | static void memset(void _far *d, unsigned int cb, unsigned char byte)
|
---|
216 | {
|
---|
217 | unsigned int i;
|
---|
218 | unsigned char _far *p = (unsigned char _far*) d;
|
---|
219 |
|
---|
220 | for (i = 0; i < cb; i++) {
|
---|
221 | p[i] = byte;
|
---|
222 | }
|
---|
223 |
|
---|
224 | }
|
---|