source: GPL/trunk/drv32/init.c@ 235

Last change on this file since 235 was 235, checked in by Brendan Oakley, 18 years ago

New mkversion thanks to Mike, with BLDLEVEL and driver load output fixes from Allan

File size: 9.0 KB
Line 
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 <printfos2.h>
39#include <irqos2.h>
40//#include <bsedos16.h>
41#ifdef KEE
42#include <kee.h>
43#endif
44#include "parse.h"
45
46const char ERR_ERROR[] = "ERROR: ";
47const char ERR_LOCK[] = "Unable to lock 32 bit data & code segments, exiting...\r\r\n";
48const char ERR_INIT[] = "Initialization failed\r\r\n";
49const char ERR_NAMES[] = "Query names failed\r\r\n";
50const char szALSA[] = "\r\n"PRODUCT_NAME" v"UNIAUD_VERSION"\r\nBased on ALSA "ALSA_VERSION"\r\n";
51
52const char szCopyRight1[]= "Copyright 2000-2002 InnoTek Systemberatung GmbH\r\n";
53const char szCopyRight2[]= "Copyright 2000-2007 The ALSA Project\r\n\r\n";
54const char szCopyRight3[]= "Copyright 2005-2007 Netlabs http://www.netlabs.org\r\n";
55//const char szCopyRight3[]= "Maintained by http://os2.kiev.ua/en/uniaud.php\r\n\r\n";
56
57const char szCodeStartEnd[] = "Code 0x%0x - 0x%0x\r\n\r\n";
58const char szMixerFound[]= "Detected Mixer: ";
59const char szEOL[] = "\r\n";
60
61typedef struct {
62 USHORT MsgLength;
63 WORD32 MsgPtr;
64} MSG_TABLE;
65
66extern "C" FARPTR16 MSG_TABLE32;
67extern "C" char szLastALSAError1[];
68extern "C" char szLastALSAError2[];
69extern "C" int sprintf (char *buffer, const char *format, ...);
70
71extern "C" int wrOffset;
72extern "C" char *szprintBuf;
73extern "C" APIRET APIENTRY DOS16OPEN(PSZ pszFileName, PHFILE phf, PULONG pulAction, ULONG cbFile, ULONG ulAttribute, ULONG fsOpenFlags, ULONG fsOpenMode, PEAOP2 peaop2 );
74extern "C" APIRET APIENTRY DOS16CLOSE(HFILE hFile);
75extern "C" APIRET APIENTRY DOS16WRITE(HFILE hFile, PVOID pBuffer, ULONG cbWrite, PULONG pcbActual);
76extern "C" void SaveBuffer(void);
77
78//Print messages with DosWrite when init is done or has failed (see startup.asm)
79void DevSaveMessage(char FAR48 *str, int length)
80{
81 MSG_TABLE FAR48 *msg = (MSG_TABLE FAR48 *)MAKE_FARPTR32(MSG_TABLE32);
82 char FAR48 *str16 = (char FAR48 *)MAKE_FARPTR32(msg->MsgPtr);
83 int i;
84
85 for(i=0;i<length;i++) {
86 str16[msg->MsgLength + i] = str[i];
87 }
88 str16[msg->MsgLength + length] = 0;
89 msg->MsgLength += length;
90
91 return;
92}
93
94void _cdecl printfos2(char *string)
95{
96 DevSaveMessage(string, strlen(string));
97}
98
99//SvL: Lock our 32 bits data & code segments
100int 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
167static 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
175void 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
197WORD32 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 rp->Out.FinalCS = 0;
213 rp->Out.FinalDS = 0;
214
215 args = MAKE_FARPTR32(rp->In.Args);
216 GetParms(args);
217
218 if(fVerbose) {
219 WriteString(szCopyRight3, sizeof(szCopyRight3)-1);
220 WriteString(szALSA, sizeof(szALSA)-1);
221 WriteString(szCopyRight2, sizeof(szCopyRight2)-1);
222 }
223
224 if(fDebug) {
225 sprintf(debugmsg, szCodeStartEnd, OffsetBeginCS32, OffsetFinalCS32);
226 WriteString(debugmsg, strlen(debugmsg));
227 }
228
229 //get the current time (to force retrieval of GIS pointer)
230 os2gettimemsec();
231
232 char szMixerName[64];
233 char szDeviceName[128];
234
235 if(OSS32_Initialize() != OSSERR_SUCCESS)
236 {
237 WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1);
238 WriteString(ERR_INIT, sizeof(ERR_INIT)-1);
239 if(szLastALSAError1[0]) {
240 WriteString(szLastALSAError1, strlen(szLastALSAError1));
241 }
242 if(szLastALSAError2[0]) {
243 WriteString(szLastALSAError2, strlen(szLastALSAError2));
244 }
245 // !! dont exit when error !! return RPDONE | RPERR_COMMAND;
246 } else if (OSS32_QueryNames(OSS32_DEFAULT_DEVICE, szDeviceName,
247 sizeof(szDeviceName),szMixerName,
248 sizeof(szMixerName), TRUE) != OSSERR_SUCCESS)
249 {
250 WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1);
251 WriteString(ERR_NAMES, sizeof(ERR_INIT)-1);
252 if(szLastALSAError1[0]) {
253 WriteString(szLastALSAError1, strlen(szLastALSAError1));
254 }
255 if(szLastALSAError2[0]) {
256 WriteString(szLastALSAError2, strlen(szLastALSAError2));
257 }
258
259 // !! dont exit when error !! return RPDONE | RPERR_COMMAND;
260 }
261 else
262 if(fVerbose) {
263 WriteString(szDeviceName, strlen(szDeviceName));
264 WriteString(szEOL, sizeof(szEOL)-1);
265 WriteString(szMixerFound, sizeof(szMixerFound)-1);
266 WriteString(szMixerName, strlen(szMixerName));
267 WriteString(szEOL, sizeof(szEOL)-1);
268
269#if 0
270 for(int i=1;i<OSS32_MAX_AUDIOCARDS;i++) {
271 if(OSS32_QueryNames(i, szDeviceName, sizeof(szDeviceName), szMixerName, sizeof(szMixerName)) == OSSERR_SUCCESS)
272 {
273 WriteString(szDeviceName, strlen(szDeviceName));
274 WriteString(szEOL, sizeof(szEOL)-1);
275 WriteString(szMixerFound, sizeof(szMixerFound)-1);
276 WriteString(szMixerName, strlen(szMixerName));
277 WriteString(szEOL, sizeof(szEOL)-1);
278 }
279 else break;
280 }
281#endif
282 WriteString(szEOL, sizeof(szEOL)-1);
283 }
284#ifdef DEBUG
285 dprintf(("DiscardableInit. cp1"));
286#endif
287 // Complete the installation
288 rp->Out.FinalCS = _OffsetFinalCS16;
289 rp->Out.FinalDS = _OffsetFinalDS16;
290#ifdef DEBUG
291 dprintf(("DiscardableInit. cp2"));
292#endif
293
294// SaveBuffer();
295
296 // Confirm a successful installation
297 return RPDONE;
298}
299
Note: See TracBrowser for help on using the repository browser.