1 | /* $Id: init.c,v 1.1.1.1 2003/07/02 13:56:56 eleph Exp $ */
|
---|
2 | /*
|
---|
3 | * Init strategy handler
|
---|
4 | *
|
---|
5 | * (C) 2000-2002 InnoTek Systemberatung GmbH
|
---|
6 | * (C) 2000-2001 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
7 | *
|
---|
8 | * This program is free software; you can redistribute it and/or
|
---|
9 | * modify it under the terms of the GNU General Public License as
|
---|
10 | * published by the Free Software Foundation; either version 2 of
|
---|
11 | * the License, or (at your option) any later version.
|
---|
12 | *
|
---|
13 | * This program is distributed in the hope that it will be useful,
|
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
16 | * GNU General Public License for more details.
|
---|
17 | *
|
---|
18 | * You should have received a copy of the GNU General Public
|
---|
19 | * License along with this program; if not, write to the Free
|
---|
20 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
|
---|
21 | * USA.
|
---|
22 | *
|
---|
23 | */
|
---|
24 |
|
---|
25 | #define INCL_NOPMAPI
|
---|
26 | #define INCL_DOSINFOSEG // Need Global info seg in rm.cpp algorithms
|
---|
27 | #include <os2.h>
|
---|
28 | #include <string.h>
|
---|
29 |
|
---|
30 | // Device support
|
---|
31 | #include <devhelp.h>
|
---|
32 | #include <devtype.h>
|
---|
33 | #include <devrp.h>
|
---|
34 | #include "devown.h"
|
---|
35 | #include <version.h>
|
---|
36 | #include <ossidc32.h>
|
---|
37 | #include <dbgos2.h>
|
---|
38 | #include <irqos2.h>
|
---|
39 | //#include <bsedos16.h>
|
---|
40 | #ifdef KEE
|
---|
41 | #include <kee.h>
|
---|
42 | #endif
|
---|
43 | #include "parse.h"
|
---|
44 | #include "malloc.h"
|
---|
45 |
|
---|
46 | const char ERR_ERROR[] = "ERROR: ";
|
---|
47 | const char ERR_LOCK[] = "Unable to lock 32 bit data & code segments, exiting...\r\r\n";
|
---|
48 | const char ERR_INIT[] = "Initialization failed\r\r\n";
|
---|
49 | const char ERR_NAMES[] = "Query names failed\r\r\n";
|
---|
50 | #ifdef DEBUG
|
---|
51 | const char szALSA[] = "\r\n"PRODUCT_NAME" v"UNIAUD_VERSION"-DEBUG\r\nBased on ALSA "ALSA_VERSION"\r\n";
|
---|
52 | #else
|
---|
53 | const char szALSA[] = "\r\n"PRODUCT_NAME" v"UNIAUD_VERSION"\r\nBased on ALSA "ALSA_VERSION"\r\n";
|
---|
54 | #endif
|
---|
55 |
|
---|
56 | //const char szCopyRight1[]= "Copyright 2000-2002 InnoTek Systemberatung GmbH\r\n";
|
---|
57 | const char szCopyRight2[]= "Copyright 2000-2010 The ALSA Project\r\n\r\n";
|
---|
58 | const char szCopyRight3[]= "Copyright 2005-2010 Netlabs http://www.netlabs.org\r\n";
|
---|
59 |
|
---|
60 | const char szCodeStartEnd[] = "Code 0x%0x - 0x%0x\r\n\r\n";
|
---|
61 | const char szMixerFound[]= "Detected Mixer: ";
|
---|
62 | const char szEOL[] = "\r\n";
|
---|
63 |
|
---|
64 | typedef struct {
|
---|
65 | USHORT MsgLength;
|
---|
66 | WORD32 MsgPtr;
|
---|
67 | } MSG_TABLE;
|
---|
68 |
|
---|
69 | extern "C" FARPTR16 MSG_TABLE32;
|
---|
70 | extern "C" char szLastALSAError1[];
|
---|
71 | extern "C" char szLastALSAError2[];
|
---|
72 | extern "C" int sprintf (char *buffer, const char *format, ...);
|
---|
73 |
|
---|
74 | extern "C" APIRET APIENTRY DOS16OPEN(PSZ pszFileName, PHFILE phf, PULONG pulAction, ULONG cbFile, ULONG ulAttribute, ULONG fsOpenFlags, ULONG fsOpenMode, PEAOP2 peaop2 );
|
---|
75 | extern "C" APIRET APIENTRY DOS16CLOSE(HFILE hFile);
|
---|
76 | extern "C" APIRET APIENTRY DOS16WRITE(HFILE hFile, PVOID pBuffer, ULONG cbWrite, PULONG pcbActual);
|
---|
77 | extern "C" void SaveBuffer(void);
|
---|
78 |
|
---|
79 | #define VMDHA_FIXED 0x0002
|
---|
80 |
|
---|
81 | extern "C" APIRET VMAlloc(ULONG size, ULONG flags, char NEAR* *pAddr);
|
---|
82 |
|
---|
83 | //Print messages with DosWrite when init is done or has failed (see startup.asm)
|
---|
84 | void DevSaveMessage(char FAR48 *str, int length)
|
---|
85 | {
|
---|
86 | MSG_TABLE FAR48 *msg = (MSG_TABLE FAR48 *)MAKE_FARPTR32(MSG_TABLE32);
|
---|
87 | char FAR48 *str16 = (char FAR48 *)MAKE_FARPTR32(msg->MsgPtr);
|
---|
88 | int i;
|
---|
89 |
|
---|
90 | for(i=0;i<length;i++) {
|
---|
91 | str16[msg->MsgLength + i] = str[i];
|
---|
92 | }
|
---|
93 | str16[msg->MsgLength + length] = 0;
|
---|
94 | msg->MsgLength += length;
|
---|
95 |
|
---|
96 | return;
|
---|
97 | }
|
---|
98 |
|
---|
99 | //SvL: Lock our 32 bits data & code segments
|
---|
100 | int LockSegments(void)
|
---|
101 | {
|
---|
102 | #ifdef KEE
|
---|
103 | KEEVMLock lock;
|
---|
104 | #else
|
---|
105 | char lock[12];
|
---|
106 | ULONG PgCount;
|
---|
107 | #endif
|
---|
108 | ULONG segsize;
|
---|
109 |
|
---|
110 | /*
|
---|
111 | * Locks DGROUP into physical memory
|
---|
112 | */
|
---|
113 | //NOTE: VMLock rounds base address down to nearest page
|
---|
114 | // So we MUST take this into account when calculating the
|
---|
115 | // size of our code/data
|
---|
116 | segsize = OffsetFinalDS32 - ((OffsetBeginDS32) & ~0xFFF);
|
---|
117 | if(segsize & 0xFFF) {
|
---|
118 | segsize += PAGE_SIZE;
|
---|
119 | }
|
---|
120 | segsize &= ~0xFFF;
|
---|
121 | #ifdef KEE
|
---|
122 | if(KernVMLock(VMDHL_LONG,
|
---|
123 | (PVOID)((OffsetBeginDS32) & ~0xFFF),
|
---|
124 | segsize,
|
---|
125 | &lock,
|
---|
126 | (KEEVMPageList*)-1,
|
---|
127 | 0)) {
|
---|
128 | #else
|
---|
129 | if(DevVMLock(VMDHL_LONG,
|
---|
130 | ((OffsetBeginDS32) & ~0xFFF),
|
---|
131 | segsize,
|
---|
132 | (LINEAR)-1,
|
---|
133 | (LINEAR)lock,
|
---|
134 | (LINEAR)&PgCount)) {
|
---|
135 | #endif
|
---|
136 | return(1);
|
---|
137 | }
|
---|
138 | /*
|
---|
139 | * Locks CODE32 into physical memory
|
---|
140 | */
|
---|
141 | segsize = OffsetFinalCS32 - ((OffsetBeginCS32) & ~0xFFF);
|
---|
142 | if(segsize & 0xFFF) {
|
---|
143 | segsize += PAGE_SIZE;
|
---|
144 | }
|
---|
145 | segsize &= ~0xFFF;
|
---|
146 | #ifdef KEE
|
---|
147 | if(KernVMLock(VMDHL_LONG,
|
---|
148 | (PVOID)((OffsetBeginCS32) & ~0xFFF),
|
---|
149 | segsize,
|
---|
150 | &lock,
|
---|
151 | (KEEVMPageList*)-1,
|
---|
152 | 0)) {
|
---|
153 | #else
|
---|
154 | if(DevVMLock(VMDHL_LONG,
|
---|
155 | ((OffsetBeginCS32) & ~0xFFF),
|
---|
156 | segsize,
|
---|
157 | (LINEAR)-1,
|
---|
158 | (LINEAR)lock,
|
---|
159 | (LINEAR)&PgCount)) {
|
---|
160 | #endif
|
---|
161 | return(1);
|
---|
162 | }
|
---|
163 | return 0;
|
---|
164 | }
|
---|
165 |
|
---|
166 | // Write a string of specified length
|
---|
167 | static VOID WriteString(const char __far* str, int length)
|
---|
168 | {
|
---|
169 | // Write the string
|
---|
170 | DevSaveMessage((char __far *)str, length);
|
---|
171 | return;
|
---|
172 | }
|
---|
173 |
|
---|
174 | #if 0
|
---|
175 | void SaveBuffer(void)
|
---|
176 | {
|
---|
177 | ULONG result;
|
---|
178 | HFILE hFile;
|
---|
179 | ULONG usAction;
|
---|
180 | // write log to file at end of INIT strategy
|
---|
181 | if(DOS16OPEN((PSZ)"uniaud.log", &hFile, &usAction, 0,
|
---|
182 | FILE_NORMAL, FILE_OPEN | OPEN_ACTION_CREATE_IF_NEW,
|
---|
183 | OPEN_ACCESS_READWRITE |
|
---|
184 | OPEN_SHARE_DENYNONE | OPEN_FLAGS_WRITE_THROUGH,
|
---|
185 | NULL ) == 0)
|
---|
186 | {
|
---|
187 | if (szprintBuf)
|
---|
188 | DOS16WRITE(hFile, szprintBuf, wrOffset, &result);
|
---|
189 |
|
---|
190 | DOS16CLOSE(hFile);
|
---|
191 | }
|
---|
192 |
|
---|
193 | return;
|
---|
194 | }
|
---|
195 | #endif
|
---|
196 | // Initialize device driver
|
---|
197 | WORD32 DiscardableInit(RPInit __far* rp)
|
---|
198 | {
|
---|
199 | char debugmsg[64];
|
---|
200 | char FAR48 *args;
|
---|
201 |
|
---|
202 | #ifdef KEE
|
---|
203 | GetTKSSBase();
|
---|
204 | #endif
|
---|
205 |
|
---|
206 | if(LockSegments()) {
|
---|
207 | WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1);
|
---|
208 | WriteString(ERR_LOCK, sizeof(ERR_LOCK)-1);
|
---|
209 | return RPDONE | RPERR_COMMAND;
|
---|
210 | }
|
---|
211 |
|
---|
212 | DebugLevel = 1;
|
---|
213 | rp->Out.FinalCS = 0;
|
---|
214 | rp->Out.FinalDS = 0;
|
---|
215 |
|
---|
216 | if ( szprintBuf == 0 ) {
|
---|
217 | VMAlloc( DBG_MAX_BUF_SIZE, VMDHA_FIXED, &szprintBuf );
|
---|
218 | if (szprintBuf) {
|
---|
219 | memset( szprintBuf, 0, DBG_MAX_BUF_SIZE );
|
---|
220 | wrOffset= 0;
|
---|
221 | }
|
---|
222 | }
|
---|
223 | if (!HeapInit(HEAP_SIZE)) {
|
---|
224 | rprintf(("HeapInit failed!"));
|
---|
225 | }
|
---|
226 |
|
---|
227 | args = MAKE_FARPTR32(rp->In.Args);
|
---|
228 | GetParms(args);
|
---|
229 |
|
---|
230 | #ifdef DEBUG
|
---|
231 | rprintf(("Uniaud32 version %s-DEBUG",UNIAUD_VERSION));
|
---|
232 | #else
|
---|
233 | rprintf(("Uniaud32 version %s",UNIAUD_VERSION));
|
---|
234 | #endif
|
---|
235 |
|
---|
236 | if(fVerbose) {
|
---|
237 | WriteString(szALSA, sizeof(szALSA)-1);
|
---|
238 | WriteString(szCopyRight3, sizeof(szCopyRight3)-1);
|
---|
239 | WriteString(szCopyRight2, sizeof(szCopyRight2)-1);
|
---|
240 | }
|
---|
241 |
|
---|
242 |
|
---|
243 | if(fDebug) {
|
---|
244 | sprintf(debugmsg, szCodeStartEnd, OffsetBeginCS32, OffsetFinalCS32);
|
---|
245 | WriteString(debugmsg, strlen(debugmsg));
|
---|
246 | }
|
---|
247 |
|
---|
248 | //get the current time (to force retrieval of GIS pointer)
|
---|
249 | os2gettimemsec();
|
---|
250 |
|
---|
251 | char szMixerName[64];
|
---|
252 | char szDeviceName[128];
|
---|
253 |
|
---|
254 | if(OSS32_Initialize() != OSSERR_SUCCESS)
|
---|
255 | {
|
---|
256 | WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1);
|
---|
257 | WriteString(ERR_INIT, sizeof(ERR_INIT)-1);
|
---|
258 | if(szLastALSAError1[0]) {
|
---|
259 | WriteString(szLastALSAError1, strlen(szLastALSAError1));
|
---|
260 | }
|
---|
261 | if(szLastALSAError2[0]) {
|
---|
262 | WriteString(szLastALSAError2, strlen(szLastALSAError2));
|
---|
263 | }
|
---|
264 | // !! dont exit when error !! return RPDONE | RPERR_COMMAND;
|
---|
265 | } else if (OSS32_QueryNames(OSS32_DEFAULT_DEVICE, szDeviceName,
|
---|
266 | sizeof(szDeviceName),szMixerName,
|
---|
267 | sizeof(szMixerName), TRUE) != OSSERR_SUCCESS)
|
---|
268 | {
|
---|
269 | WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1);
|
---|
270 | WriteString(ERR_NAMES, sizeof(ERR_INIT)-1);
|
---|
271 | if(szLastALSAError1[0]) {
|
---|
272 | WriteString(szLastALSAError1, strlen(szLastALSAError1));
|
---|
273 | }
|
---|
274 | if(szLastALSAError2[0]) {
|
---|
275 | WriteString(szLastALSAError2, strlen(szLastALSAError2));
|
---|
276 | }
|
---|
277 |
|
---|
278 | // !! dont exit when error !! return RPDONE | RPERR_COMMAND;
|
---|
279 | }
|
---|
280 | else
|
---|
281 | if(fVerbose) {
|
---|
282 | WriteString(szDeviceName, strlen(szDeviceName));
|
---|
283 | WriteString(szEOL, sizeof(szEOL)-1);
|
---|
284 | WriteString(szMixerFound, sizeof(szMixerFound)-1);
|
---|
285 | WriteString(szMixerName, strlen(szMixerName));
|
---|
286 | WriteString(szEOL, sizeof(szEOL)-1);
|
---|
287 |
|
---|
288 | #if 0
|
---|
289 | for(int i=1;i<OSS32_MAX_AUDIOCARDS;i++) {
|
---|
290 | if(OSS32_QueryNames(i, szDeviceName, sizeof(szDeviceName), szMixerName, sizeof(szMixerName)) == OSSERR_SUCCESS)
|
---|
291 | {
|
---|
292 | WriteString(szDeviceName, strlen(szDeviceName));
|
---|
293 | WriteString(szEOL, sizeof(szEOL)-1);
|
---|
294 | WriteString(szMixerFound, sizeof(szMixerFound)-1);
|
---|
295 | WriteString(szMixerName, strlen(szMixerName));
|
---|
296 | WriteString(szEOL, sizeof(szEOL)-1);
|
---|
297 | }
|
---|
298 | else break;
|
---|
299 | }
|
---|
300 | #endif
|
---|
301 | WriteString(szEOL, sizeof(szEOL)-1);
|
---|
302 | }
|
---|
303 | // Complete the installation
|
---|
304 | rp->Out.FinalCS = _OffsetFinalCS16;
|
---|
305 | rp->Out.FinalDS = _OffsetFinalDS16;
|
---|
306 |
|
---|
307 | //SaveBuffer();
|
---|
308 |
|
---|
309 | // Confirm a successful installation
|
---|
310 | return RPDONE;
|
---|
311 | }
|
---|
312 |
|
---|