[142] | 1 | /* $Id: init.c 176 2001-04-14 17:03:36Z sandervl $ */
|
---|
| 2 |
|
---|
| 3 | //******************************************************************************
|
---|
| 4 | // Init strategy handler
|
---|
| 5 | //
|
---|
| 6 | // Copyright 2000 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 | extern "C" { // 16-bit header files are not C++ aware
|
---|
| 25 | #define INCL_NOPMAPI
|
---|
| 26 | #define INCL_DOSMISC
|
---|
| 27 | #include <os2.h>
|
---|
| 28 | }
|
---|
[151] | 29 | #include <string.h>
|
---|
[142] | 30 |
|
---|
| 31 | // Device support
|
---|
| 32 | #include <devhelp.h>
|
---|
| 33 | #include <devtype.h>
|
---|
| 34 | #include <devrp.h>
|
---|
| 35 | #include "devown.h"
|
---|
| 36 | #include <sbversion.h>
|
---|
| 37 | #include <dbgos2.h>
|
---|
| 38 | #ifdef KEE
|
---|
| 39 | #include <kee.h>
|
---|
| 40 | #endif
|
---|
| 41 |
|
---|
| 42 | const char ERR_ERROR[] = "ERROR: ";
|
---|
| 43 | const char ERR_LOCK[] = "\r\nUnable to lock 32 bit data & code segments, exiting...\r\r\n";
|
---|
| 44 | #ifdef KEE
|
---|
| 45 | const char szSBLive[] = "\r\n\r\nSoundBlaster Live! Audio Driver v"SBLIVE_VERSION" (32 Bits KEE)\r\n";
|
---|
| 46 | #else
|
---|
| 47 | const char szSBLive[] = "\r\n\r\nSoundBlaster Live! Audio Driver v"SBLIVE_VERSION" (32 Bits)\r\n";
|
---|
| 48 | #endif
|
---|
| 49 | const char szCopyRight1[]= "Copyright 1999, 2000 Creative Labs, Inc.\r\n";
|
---|
[176] | 50 | const char szCopyRight2[]= "Copyright 2000-2001 Sander van Leeuwen (OS/2 Port)\r\n\r\n";
|
---|
[151] | 51 | const char szCodeStartEnd[] = "Code 0x%0x - 0x%0x\r\n\r\n";
|
---|
| 52 |
|
---|
[142] | 53 | typedef struct {
|
---|
| 54 | USHORT MsgLength;
|
---|
| 55 | WORD32 MsgPtr;
|
---|
| 56 | } MSG_TABLE;
|
---|
| 57 |
|
---|
| 58 | extern "C" WORD32 MSG_TABLE32;
|
---|
| 59 |
|
---|
[151] | 60 | extern "C" int sprintf (char *buffer, const char *format, ...);
|
---|
| 61 |
|
---|
[142] | 62 | //Print messages with DosWrite when init is done or has failed (see startup.asm)
|
---|
| 63 | void DevSaveMessage(char __far *str, int length)
|
---|
| 64 | {
|
---|
| 65 | MSG_TABLE __far *msg = (MSG_TABLE __far *)__Make48Pointer(MSG_TABLE32);
|
---|
| 66 | char __far *str16 = (char __far *)__Make48Pointer(msg->MsgPtr);
|
---|
| 67 | int i;
|
---|
| 68 |
|
---|
| 69 | for(i=0;i<length;i++) {
|
---|
| 70 | str16[msg->MsgLength + i] = str[i];
|
---|
| 71 | }
|
---|
| 72 | str16[msg->MsgLength + length] = 0;
|
---|
| 73 | msg->MsgLength += length;
|
---|
| 74 |
|
---|
| 75 | return;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | //SvL: Lock our 32 bits data & code segments
|
---|
| 79 | int LockSegments(void)
|
---|
| 80 | {
|
---|
| 81 | #ifdef KEE
|
---|
| 82 | KEEVMLock lock;
|
---|
| 83 | #else
|
---|
| 84 | char lock[12];
|
---|
| 85 | ULONG PgCount;
|
---|
| 86 | #endif
|
---|
| 87 | ULONG segsize;
|
---|
| 88 |
|
---|
| 89 | /*
|
---|
| 90 | * Locks DGROUP into physical memory
|
---|
| 91 | */
|
---|
| 92 | //NOTE: VMLock rounds base address down to nearest page
|
---|
| 93 | // So we MUST take this into account when calculating the
|
---|
| 94 | // size of our code/data
|
---|
| 95 | segsize = OffsetFinalDS32 - ((OffsetBeginDS32) & ~0xFFF);
|
---|
| 96 | if(segsize & 0xFFF) {
|
---|
| 97 | segsize += PAGE_SIZE;
|
---|
| 98 | }
|
---|
| 99 | segsize &= ~0xFFF;
|
---|
| 100 | #ifdef KEE
|
---|
| 101 | if(KernVMLock(VMDHL_LONG,
|
---|
| 102 | (PVOID)((OffsetBeginDS32) & ~0xFFF),
|
---|
| 103 | segsize,
|
---|
| 104 | &lock,
|
---|
| 105 | (KEEVMPageList*)-1,
|
---|
| 106 | 0)) {
|
---|
| 107 | #else
|
---|
| 108 | if(DevVMLock(VMDHL_LONG,
|
---|
| 109 | ((OffsetBeginDS32) & ~0xFFF),
|
---|
| 110 | segsize,
|
---|
| 111 | (LINEAR)-1,
|
---|
| 112 | __StackToFlat((ULONG)lock),
|
---|
| 113 | (LINEAR)__StackToFlat((ULONG)&PgCount))) {
|
---|
| 114 | #endif
|
---|
| 115 | return(1);
|
---|
| 116 | }
|
---|
| 117 | /*
|
---|
| 118 | * Locks CODE32 into physical memory
|
---|
| 119 | */
|
---|
| 120 | segsize = OffsetFinalCS32 - ((OffsetBeginCS32) & ~0xFFF);
|
---|
| 121 | if(segsize & 0xFFF) {
|
---|
| 122 | segsize += PAGE_SIZE;
|
---|
| 123 | }
|
---|
| 124 | segsize &= ~0xFFF;
|
---|
| 125 | #ifdef KEE
|
---|
| 126 | if(KernVMLock(VMDHL_LONG,
|
---|
| 127 | (PVOID)((OffsetBeginCS32) & ~0xFFF),
|
---|
| 128 | segsize,
|
---|
| 129 | &lock,
|
---|
| 130 | (KEEVMPageList*)-1,
|
---|
| 131 | 0)) {
|
---|
| 132 | #else
|
---|
| 133 | if(DevVMLock(VMDHL_LONG,
|
---|
| 134 | ((OffsetBeginCS32) & ~0xFFF),
|
---|
| 135 | segsize,
|
---|
| 136 | (LINEAR)-1,
|
---|
| 137 | __StackToFlat((ULONG)lock),
|
---|
| 138 | (LINEAR)__StackToFlat((ULONG)&PgCount))) {
|
---|
| 139 | #endif
|
---|
| 140 | return(1);
|
---|
| 141 | }
|
---|
| 142 | return 0;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 |
|
---|
| 146 | // Write a string of specified length
|
---|
| 147 | static VOID WriteString(const char __far* str, int length)
|
---|
| 148 | {
|
---|
| 149 | // Write the string
|
---|
| 150 | DevSaveMessage((char __far *)str, length);
|
---|
| 151 | return;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | // Initialize device driver
|
---|
| 155 | WORD32 DiscardableInit(RPInit __far* rp)
|
---|
| 156 | {
|
---|
[151] | 157 | char debugmsg[64];
|
---|
| 158 | char FAR48 *args;
|
---|
| 159 |
|
---|
[142] | 160 | GetTKSSBase();
|
---|
| 161 | if(LockSegments()) {
|
---|
[151] | 162 | WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1);
|
---|
| 163 | WriteString(ERR_LOCK, sizeof(ERR_LOCK)-1);
|
---|
| 164 | return RPDONE | RPERR;
|
---|
[142] | 165 | }
|
---|
| 166 |
|
---|
| 167 | rp->Out.FinalCS = 0;
|
---|
| 168 | rp->Out.FinalDS = 0;
|
---|
| 169 |
|
---|
| 170 | //Do you init here:
|
---|
| 171 |
|
---|
| 172 | WriteString(szSBLive, sizeof(szSBLive)-1);
|
---|
| 173 | WriteString(szCopyRight1, sizeof(szCopyRight1)-1);
|
---|
| 174 | WriteString(szCopyRight2, sizeof(szCopyRight2)-1);
|
---|
| 175 |
|
---|
[151] | 176 | args = __Make48Pointer(rp->In.Args);
|
---|
| 177 | while(*args && *args == ' ') args++;
|
---|
| 178 | while(*args && *args != ' ') args++;
|
---|
| 179 | while(*args && *args == ' ') args++;
|
---|
| 180 | while(*args && *args != '/') args++;
|
---|
| 181 | if(*args) args++;
|
---|
| 182 |
|
---|
| 183 | if(*args == 'D' || *args == 'd') {
|
---|
| 184 | sprintf(debugmsg, szCodeStartEnd, OffsetBeginCS32, OffsetFinalCS32);
|
---|
| 185 | WriteString(debugmsg, strlen(debugmsg));
|
---|
| 186 | }
|
---|
| 187 |
|
---|
[142] | 188 | // Complete the installation
|
---|
| 189 | rp->Out.FinalCS = _OffsetFinalCS16;
|
---|
| 190 | rp->Out.FinalDS = _OffsetFinalDS16;
|
---|
| 191 |
|
---|
| 192 | // Confirm a successful installation
|
---|
| 193 | return RPDONE;
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 |
|
---|
| 197 |
|
---|
| 198 |
|
---|