Changeset 5247 for trunk/src/win32k/dev32/d32init.c
- Timestamp:
- Feb 23, 2001, 3:57:55 AM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/win32k/dev32/d32init.c
r5224 r5247 1 /* $Id: d32init.c,v 1.3 7 2001-02-21 07:44:57bird Exp $1 /* $Id: d32init.c,v 1.38 2001-02-23 02:57:53 bird Exp $ 2 2 * 3 3 * d32init.c - 32-bits init routines. … … 15 15 * Calltab entry sizes. 16 16 */ 17 #define OVERLOAD16_ENTRY 0x18 17 #define OVERLOAD16_ENTRY 0x18 /* This is intentionally 4 bytes larger than the one defined in calltaba.asm. */ 18 18 #define OVERLOAD32_ENTRY 0x14 19 19 #define IMPORT16_ENTRY 0x08 … … 24 24 #define kprintf2(a) kprintf 25 25 #else 26 #define kprintf2(a) {}//26 #define kprintf2(a) (void)0 27 27 #endif 28 28 … … 56 56 #ifdef R3TST 57 57 #include "test.h" 58 #define x86DisableWriteProtect() 0 59 #define x86RestoreWriteProtect(a) (void)0 58 60 #endif 59 61 … … 96 98 /* extern(s) located in calltab.asm */ 97 99 extern char callTab[1]; 100 extern char callTab16[1]; 98 101 extern unsigned auFuncs[NBR_OF_KRNLIMPORTS]; 99 102 … … 415 418 416 419 /* callgate */ 420 #ifndef R3TST 417 421 if ((rc = InitCallGate()) != NO_ERROR) 418 422 { … … 420 424 return (USHORT)rc; 421 425 } 426 #endif 422 427 423 428 … … 442 447 if (rc != NO_ERROR) 443 448 kprintf(("data segment lock failed with with rc=%d\n", rc)); 444 445 /* 16-bit data segment - is this really necessary? - no!!! */446 #if 0 /* This should not be necessary!!! it's allocated from the kernel resident heap if I am not much mistaken. */447 memset(SSToDS(&lockhandle), 0, sizeof(lockhandle));448 rc = D32Hlp_VMLock2(&DATA16START,449 &DATA16END - &DATA16START,450 VMDHL_LONG | VMDHL_WRITE,451 SSToDS(&lockhandle));452 if (rc != NO_ERROR)453 kprintf(("16-bit data segment lock failed with with rc=%d\n", rc));454 #endif455 449 456 450 return NO_ERROR; … … 1027 1021 * Check for the well known prolog (the only that is supported now) 1028 1022 * which is: 1029 * push 21030 1023 */ 1031 if (*pach == 0x6A) /* push 2 (don't check for the 2) */ 1024 if ((*pach == 0x6A && !fOverload) /* push 2 (don't check for the 2) */ 1025 || 1026 *pach == 0x60 /* pushf */ 1027 || 1028 (*pach == 0x53 && pach[1] == 0x51) /* push bx, push cx */ 1029 || 1030 (*pach == 0x8c && pach[1] == 0xd8) /* mov ax, ds */ 1031 || 1032 (*pach == 0xb8) /* mov ax, imm16 */ 1033 ) 1032 1034 { 1033 1035 BOOL fForce; 1034 1036 int cOpPrefix = 0; 1035 1037 cb = 0; 1036 while (cb < 8 || fForce) /* 8 is the size of a 66h prefixedfar jump instruction. */1038 while (cb < 5 || fForce) /* 5 is the size of a 16:16 far jump instruction. */ 1037 1039 { 1038 1040 int cb2; … … 1064 1066 case 0x56: /* push si */ 1065 1067 case 0x57: /* push di */ 1068 case 0x60: /* pusha */ 1069 break; 1070 1071 /* simple three byte instructions */ 1072 case 0xb8: /* mov eax, imm16 */ 1073 case 0xb9: /* mov ecx, imm16 */ 1074 case 0xba: /* mov edx, imm16 */ 1075 case 0xbb: /* mov ebx, imm16 */ 1076 case 0xbc: /* mov esx, imm16 */ 1077 case 0xbd: /* mov ebx, imm16 */ 1078 case 0xbe: /* mov esi, imm16 */ 1079 case 0xbf: /* mov edi, imm16 */ 1080 case 0x2d: /* sub eax, imm16 */ 1081 case 0x35: /* xor eax, imm16 */ 1082 case 0x3d: /* cmp eax, imm16 */ 1083 case 0x68: /* push <dword> */ 1084 case 0xa1: /* mov eax, moffs16 */ 1085 case 0xa3: /* mov moffs16, eax */ 1086 if (cOpPrefix > 0) /* FIXME see 32-bit interpreter. */ 1087 { 1088 pach += 2; 1089 cb += 2; 1090 } 1091 pach += 2; 1092 cb += 2; 1066 1093 break; 1067 1094 … … 1083 1110 1084 1111 case 0x6a: /* push <byte> */ 1112 case 0x3c: /* mov al, imm8 */ 1085 1113 pach++; 1086 1114 cb++; 1087 1115 break; 1088 1116 1089 case 0x68: /* push <word> */1090 if (cOpPrefix > 0)1091 {1092 pach += 2;1093 cb += 2;1094 }1095 pach += 2;1096 cb += 2;1097 break;1098 1099 1117 case 0x8b: /* mov /r */ 1118 case 0x8c: /* mov r/m16,Sreg (= mov /r) */ 1119 case 0x8e: /* mov Sreg, r/m16 (= mov /r) */ 1100 1120 if ((pach[1] & 0xc0) == 0x80 /* ex. mov ax,bp+1114h */ 1101 1121 || ((pach[1] & 0xc0) == 0 && (pach[1] & 0x7) == 6)) /* ex. mov bp,0ff23h */ … … 1150 1170 } 1151 1171 } 1172 else 1173 kprintf(("interpretFunctionProlog16: unknown prolog 0x%x 0x%x 0x%x\n", pach[0], pach[1], pach[2])); 1174 1152 1175 1153 1176 fOverload = fOverload; … … 1243 1266 { 1244 1267 cb = interpretFunctionProlog16((char*)aImportTab[i].ulAddress, EPT16Proc(aImportTab[i])); 1245 cbmax = OVERLOAD16_ENTRY - 7; /* 7 = Size of the farjump instruction */1268 cbmax = OVERLOAD16_ENTRY - 5; /* 5 = Size of the jump instruction */ 1246 1269 } 1247 1270 … … 1251 1274 if (cb <= 0 || cb > cbmax) 1252 1275 { /* failed, too small or too large. */ 1253 kprintf(("VerifyImportTab32 : verify failed for procedure no.%d (cb=%d), %s\n", i, cb, aImportTab[i].achName));1276 kprintf(("VerifyImportTab32/16: verify failed for procedure no.%d (cb=%d), %s\n", i, cb, aImportTab[i].achName)); 1254 1277 return (USHORT)(ERROR_D32_TOO_INVALID_PROLOG | (i << ERROR_D32_PROC_SHIFT) | ERROR_D32_PROC_FLAG); 1255 1278 } … … 1281 1304 int cb; 1282 1305 int cbmax; 1283 char * pchCTEntry; /* Pointer to current calltab entry. */ 1306 char * pchCTEntry; /* Pointer to current 32-bit calltab entry. */ 1307 char * pchCTEntry16; /* Pointer to current 16-bit calltab entry. */ 1284 1308 ULONG flWP; /* CR0 WP flag restore value. */ 1285 1309 … … 1324 1348 { 1325 1349 cb = interpretFunctionProlog16((char*)aImportTab[i].ulAddress, EPT16Proc(aImportTab[i])); 1326 cbmax = OVERLOAD16_ENTRY - 7; /* 7 = Size of the farjump instruction */1350 cbmax = OVERLOAD16_ENTRY - 5; /* 5 = Size of the jump instruction */ 1327 1351 } 1328 1352 if (cb <= 0 || cb > cbmax) … … 1337 1361 */ 1338 1362 pchCTEntry = &callTab[0]; 1363 pchCTEntry16 = &callTab16[0]; 1339 1364 flWP = x86DisableWriteProtect(); 1340 1365 for (i = 0; i < NBR_OF_KRNLIMPORTS; i++) … … 1391 1416 case EPT_PROC16: 1392 1417 { 1393 kprintf(("ImportTabInit: Overloading 16-bit procedures are not supported yet!!! Calltable in 32-bit segment!\n", i));1394 Int3();1395 1396 1418 cb = interpretFunctionProlog16((char*)aImportTab[i].ulAddress, TRUE); 1397 1419 aImportTab[i].cbProlog = (char)cb; 1398 if (cb >= 8 && cb + 7 < OVERLOAD16_ENTRY) /* 8: size of a 16:32 jump which jumps to my overloading function (prefixed with 66h in a 16-bit segment)*/1399 { /* 7: size of a 16:32jump which is added to the call tab */1420 if (cb >= 5 && cb + 5 < OVERLOAD16_ENTRY) /* 5: size of a 16:16 jump which jumps to my overloading function */ 1421 { /* cb+5: size of a 16:16 jump which is added to the call tab */ 1400 1422 /* 1401 1423 * Copy function prolog which is to be overwritten. 1402 1424 */ 1403 memcpy(pchCTEntry , (void*)aImportTab[i].ulAddress, (size_t)cb);1425 memcpy(pchCTEntry16, (void*)aImportTab[i].ulAddress, (size_t)cb); 1404 1426 1405 1427 /* 1406 1428 * Create far jump from calltab to original function. 1407 * 0xEA < fourbyte target address> <two byte target selector>1429 * 0xEA <two byte target address> <two byte target selector> 1408 1430 */ 1409 pchCTEntry[cb] = 0xEA; /* jmp far ptr */ 1410 *(unsigned long*)(void*)&pchCTEntry[cb+1] = aImportTab[i].offObject; 1411 *(unsigned short*)(void*)&pchCTEntry[cb+5] = aImportTab[i].usSel; 1431 pchCTEntry16[cb] = 0xEA; /* jmp far ptr */ 1432 *(unsigned short*)(void*)&pchCTEntry16[cb+1] = (unsigned short)aImportTab[i].offObject + cb; 1433 *(unsigned short*)(void*)&pchCTEntry16[cb+3] = aImportTab[i].usSel; 1434 1435 /* 1436 * We store the far 16:16 pointer to the function in the last four 1437 * bytes of the entry. Set them! 1438 */ 1439 *(unsigned short*)(void*)&pchCTEntry16[OVERLOAD16_ENTRY-4] = (unsigned short)aImportTab[i].offObject; 1440 *(unsigned short*)(void*)&pchCTEntry16[OVERLOAD16_ENTRY-2] = aImportTab[i].usSel; 1412 1441 1413 1442 /* 1414 1443 * jump from original function to my function - an cli(?) could be needed here 1415 * 0x 66 0xEA <fourbyte target address> <two byte target selector>1444 * 0xEA <two byte target address> <two byte target selector> 1416 1445 */ 1417 *(char*)(aImportTab[i].ulAddress ) = 0x66; /* operandsize prefix */ 1418 *(char*)(aImportTab[i].ulAddress + 1) = 0xEA; /* jmp far ptr */ 1419 *(unsigned long*)(aImportTab[i].ulAddress + 2) = auFuncs[i]; /* FIXME? */ 1420 *(unsigned short*)(aImportTab[i].ulAddress + 6) = _R0FlatCS16; /* FIXME */ 1446 *(char*)(aImportTab[i].ulAddress) = 0xEA; /* jmp far ptr */ 1447 *(unsigned long*)(aImportTab[i].ulAddress + 1) = auFuncs[i]; /* The auFuncs entry is a far pointer. */ 1421 1448 } 1422 1449 else … … 1427 1454 return ERROR_D32_IPE | (i << ERROR_D32_PROC_SHIFT) | ERROR_D32_PROC_FLAG; 1428 1455 } 1429 pchCTEntry += OVERLOAD16_ENTRY;1456 pchCTEntry16 += OVERLOAD16_ENTRY; 1430 1457 break; 1431 1458 }
Note:
See TracChangeset
for help on using the changeset viewer.