annotate libdha/sysdep/libdha_win32.c @ 11740:c0e744330722

sync
author nauj27
date Sat, 03 Jan 2004 23:08:26 +0000
parents e687fa1d55c6
children 3a727f52c4a2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
1 /*
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
2 MAPDEV.h - include file for VxD MAPDEV
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
3 Copyright (c) 1996 Vireo Software, Inc.
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
4 Modified for libdha by Nick Kurshev.
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
5 */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
6
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
7 #include <windows.h>
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
8 /*
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
9 This is the request structure that applications use
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
10 to request services from the MAPDEV VxD.
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
11 */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
12
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
13 typedef struct _MapDevRequest
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
14 {
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
15 DWORD mdr_ServiceID; /* supplied by caller */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
16 LPVOID mdr_PhysicalAddress; /* supplied by caller */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
17 DWORD mdr_SizeInBytes; /* supplied by caller */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
18 LPVOID mdr_LinearAddress; /* returned by VxD */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
19 WORD mdr_Selector; /* returned if 16-bit caller */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
20 WORD mdr_Status; /* MDR_xxxx code below */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
21 } MAPDEVREQUEST, *PMAPDEVREQUEST;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
22
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
23 #define MDR_SERVICE_MAP CTL_CODE(FILE_DEVICE_UNKNOWN, 1, METHOD_NEITHER, FILE_ANY_ACCESS)
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
24 #define MDR_SERVICE_UNMAP CTL_CODE(FILE_DEVICE_UNKNOWN, 2, METHOD_NEITHER, FILE_ANY_ACCESS)
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
25
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
26 #define MDR_STATUS_SUCCESS 1
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
27 #define MDR_STATUS_ERROR 0
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
28 /*#include "winioctl.h"*/
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
29 #define FILE_DEVICE_UNKNOWN 0x00000022
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
30 #define METHOD_NEITHER 3
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
31 #define FILE_ANY_ACCESS 0
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
32 #define CTL_CODE( DeviceType, Function, Method, Access ) ( \
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
33 ((DeviceType)<<16) | ((Access)<<14) | ((Function)<<2) | (Method) )
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
34
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
35 /* Memory Map a piece of Real Memory */
10980
e687fa1d55c6 port libdha to mingw
faust3
parents: 4164
diff changeset
36 void *map_phys_mem(unsigned long base, unsigned long size) {
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
37
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
38 HANDLE hDevice ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
39 PVOID inBuf[1] ; /* buffer for struct pointer to VxD */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
40 DWORD RetInfo[2] ; /* buffer to receive data from VxD */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
41 DWORD cbBytesReturned ; /* count of bytes returned from VxD */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
42 MAPDEVREQUEST req ; /* map device request structure */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
43 DWORD *pNicstar, Status, Time ; int i ; char *endptr ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
44 const PCHAR VxDName = "\\\\.\\MAPDEV.VXD" ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
45 const PCHAR VxDNameAlreadyLoaded = "\\\\.\\MAPDEV" ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
46
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
47 hDevice = CreateFile(VxDName, 0,0,0,
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
48 CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0) ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
49 if (hDevice == INVALID_HANDLE_VALUE)
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
50 hDevice = CreateFile(VxDNameAlreadyLoaded, 0,0,0,
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
51 CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0) ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
52 if (hDevice == INVALID_HANDLE_VALUE) {
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
53 fprintf(stderr, "Cannot open driver, error=%08lx\n", GetLastError()) ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
54 exit(1) ; }
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
55
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
56 req.mdr_ServiceID = MDR_SERVICE_MAP ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
57 req.mdr_PhysicalAddress = (PVOID)base ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
58 req.mdr_SizeInBytes = size ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
59 inBuf[0] = &req ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
60
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
61 if ( ! DeviceIoControl(hDevice, MDR_SERVICE_MAP, inBuf, sizeof(PVOID),
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
62 NULL, 0, &cbBytesReturned, NULL) ) {
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
63 fprintf(stderr, "Failed to map device\n") ; exit(1) ; }
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
64
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
65 return (void*)req.mdr_LinearAddress ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
66 }
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
67
10980
e687fa1d55c6 port libdha to mingw
faust3
parents: 4164
diff changeset
68 void unmap_phys_mem(void *ptr, unsigned long size) { }