|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24: /* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
25: *
26: * myDriver.c - simple driver example. This driver is started up by
27: * Config, from which a devicePort is obtained. We then load
28: * a loadable kernel server into the kernel and pass the device
29: * port to the LKS.
30: *
31: * HISTORY
32: * 18-Dec-92 Doug Mitchell at NeXT
33: * Created.
34: */
35:
36: #import <driverkit/generalFuncs.h>
37: #import <driverkit/userConfigServer.h>
38: #import <mach/mach.h>
39: #import <servers/netname.h>
40: #import "kl_com.h"
41: #import <myHandler.h> // MIG generated, in the build directory
42:
43: #define MAX_DEVICE_PORTS 2
44:
45: #define RELOCATABLE_FILE \
46: "/Net/grrr/mknrw/dmitch/DRIVERKIT/driverkit/Examples/loadable/Kernel/m88krelocdebug/myHandler_reloc"
47:
48: #define SERVER_NAME "myHandler"
49: #define SERVER_PORT_NAME "myHandler"
50:
51:
52: static port_t driverSigPort; // created for us by IOGetDevicePorts()
53: static port_t serverPort; // communication with LKS via this
54:
55: static int loadServer();
56:
57: /*
58: * When true, main() wait for debugger connection before proceeding.
59: */
60: #define WAIT_FOR_DEBUG 0
61:
62: int main(int arcg, char **argv)
63: {
64: port_t devicePorts[MAX_DEVICE_PORTS];
65: int numDevPorts;
66: IOConfigReturn crtn;
67:
68: /*
69: * Initialize libraries.
70: */
71: IOInitGeneralFuncs();
72:
73: #if WAIT_FOR_DEBUG
74: {
75: volatile int proceed = 0;
76:
77: IOLog("myDriver: waiting for debugger connection\n");
78: while(!proceed) {
79: IOSleep(100);
80: }
81: }
82: #endif WAIT_FOR_DEBUG
83:
84: /*
85: * Get device ports for each instance of the printer hardware
86: * from Config.
87: */
88: crtn = IOGetDevicePorts(MAX_DEVICE_PORTS,
89: "myDriver",
90: devicePorts,
91: &numDevPorts,
92: &driverSigPort);
93: if(crtn) {
94: exit(1);
95: }
96: if(numDevPorts == 0) {
97: IOLog("myDevice: No Device Ports available; aborting\n");
98: exit(1);
99: }
100:
101: /*
102: * Load in the LKS.
103: */
104: if(loadServer()) {
105: exit(1);
106: }
107: IOLog("myDriver: server %s loaded\n", SERVER_NAME);
108:
109: /*
110: * Pass down the device port and initialize device.
111: */
112: setDevicePort(serverPort, devicePorts[0]);
113: initDevice(serverPort);
114:
115: /*
116: * Shut down driver.
117: */
118: shutDown(serverPort);
119: IOLog("myDriver: Done; exiting\n");
120: return 0;
121: }
122:
123: /*
124: * Load the server into kernel memory and initiate
125: * communication with it. Returns 0 if successful.
126: */
127: static int
128: loadServer()
129: {
130: int rtn;
131: kern_return_t krtn;
132:
133: /*
134: * First load the parasite server into kernel memory.
135: */
136: rtn = kl_com_add(RELOCATABLE_FILE, SERVER_NAME);
137: if(rtn) {
138: return(1);
139: }
140: rtn = kl_com_load(SERVER_NAME);
141: if(rtn) {
142: return(1);
143: }
144:
145: /*
146: * Sync up with kern_loader.
147: */
148: kl_com_wait();
149:
150: /*
151: * Establish contact with the server.
152: */
153: krtn = netname_look_up(name_server_port,
154: "", // must be local host
155: SERVER_PORT_NAME,
156: &serverPort);
157: if(krtn) {
158: IOLog("myDriver: Can\'t find server port (error %d)", krtn);
159: return 1;
160: }
161:
162: return 0;
163: }
164:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.