|
|
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: /*
25: * Copyright (c) 1992 NeXT Computer, Inc.
26: *
27: * Kernel Debugger Category for Ethernet Class.
28: *
29: * HISTORY
30: *
31: * 7 December 1992 David E. Bohman at NeXT
32: * Created.
33: *
34: * 29 May 1997 Dieter Siegmund at NeXT
35: * - Added debugger registration call, and made
36: * en_send_pkt() and en_recv_pkt static
37: */
38:
39: #import <mach/boolean.h>
40: #import <mach/machine/simple_lock.h>
41: #import <sys/types.h>
42: #import <sys/socket.h>
43: #import <driverkit/IOEthernet.h>
44: #import <driverkit/IOEthernetPrivate.h>
45: #import <kern/kdp_en_debugger.h>
46:
47: #ifndef ppc
48: extern int spl3();
49: #else
50: extern int splbio();
51: #endif
52:
53: static id debuggerDevice;
54: #ifndef sparc /* [ */
55: static int savedIpl;
56: #ifndef ppc
57: int (*debuggerIplRoutine)() = spl3;
58: #else
59: int (*debuggerIplRoutine)() = splbio;
60: #endif
61: static BOOL _kernDebuggerLocked = NO;
62: extern simple_lock_t _kernDebuggerLock;
63: #endif sparc /* ] */
64:
65: static void
66: en_recv_pkt(
67: void *pkt,
68: unsigned int *pkt_len,
69: unsigned int timeout);
70:
71: static void
72: en_send_pkt(
73: void *pkt,
74: unsigned int pkt_len);
75:
76: static void
77: (*recvPkt_methd)(
78: id, SEL,
79: void * pkt,
80: unsigned int * pkt_len,
81: unsigned int timeout);
82: #define RECV_PKT_SEL @selector(receivePacket:length:timeout:)
83:
84: static void
85: (*sendPkt_methd)(
86: id, SEL,
87: void * pkt,
88: unsigned int pkt_len);
89: #define SEND_PKT_SEL @selector(sendPacket:length:)
90:
91: #ifdef sparc
92: static BOOL
93: (*reset_method)(
94: id, SEL,
95: BOOL enable);
96: #define RESET_SEL @selector(resetAndEnable:)
97: #endif sparc
98:
99: @implementation IOEthernet(EthernetDebugger)
100:
101: - (void)registerAsDebuggerDevice
102: {
103: if (debuggerDevice == nil) {
104: /* register our debugger routines */
105: kdp_register_send_receive(&en_send_pkt, &en_recv_pkt);
106: (IMP)recvPkt_methd = [self methodFor:RECV_PKT_SEL];
107: (IMP)sendPkt_methd = [self methodFor:SEND_PKT_SEL];
108: #ifndef sparc
109: if ((IMP)recvPkt_methd && (IMP)sendPkt_methd)
110: debuggerDevice = self;
111: #else
112: (IMP)reset_method = [self methodFor:RESET_SEL];
113: if ((IMP)recvPkt_methd && (IMP)sendPkt_methd && (IMP)reset_method)
114: debuggerDevice = self;
115: #endif sparc
116: }
117: }
118:
119: #ifndef sparc /* [ */
120: - (void)reserveDebuggerLock
121: {
122: if (self == debuggerDevice) {
123: if (_kernDebuggerLocked) {
124: IOLog("reserveDebuggerLock: already locked\n");
125: return;
126: }
127: savedIpl = (*debuggerIplRoutine)();
128: simple_lock(_kernDebuggerLock);
129: _kernDebuggerLocked = YES;
130: }
131: }
132:
133: - (void)releaseDebuggerLock
134: {
135: if (self == debuggerDevice) {
136: if (!_kernDebuggerLocked) {
137: return;
138: }
139: simple_unlock(_kernDebuggerLock);
140: _kernDebuggerLocked = NO;
141: splx(savedIpl);
142: }
143: }
144:
145: #endif sparc /* ] */
146: @end
147:
148: #ifndef sparc /* [ */
149: void reserveDebuggerLock(id debuggerDeviceObject)
150: {
151: if (debuggerDeviceObject == debuggerDevice) {
152: if (_kernDebuggerLocked) {
153: IOLog("reserveDebuggerLock: already locked\n");
154: return;
155: }
156: simple_lock(_kernDebuggerLock);
157: _kernDebuggerLocked = YES;
158: }
159: }
160:
161: void releaseDebuggerLock(id debuggerDeviceObject)
162: {
163: if (debuggerDeviceObject == debuggerDevice) {
164: if (!_kernDebuggerLocked) {
165: return;
166: }
167: simple_unlock(_kernDebuggerLock);
168: _kernDebuggerLocked = NO;
169: }
170: }
171:
172: #endif sparc /* ] */
173:
174: static void
175: en_recv_pkt(
176: void *pkt,
177: unsigned int *pkt_len,
178: unsigned int timeout
179: )
180: {
181: *pkt_len = 0;
182:
183: if (debuggerDevice)
184: (*recvPkt_methd)(debuggerDevice, RECV_PKT_SEL, pkt, pkt_len, timeout);
185: }
186:
187: static void
188: en_send_pkt(
189: void *pkt,
190: unsigned int pkt_len
191: )
192: {
193: if (debuggerDevice)
194: (*sendPkt_methd)(debuggerDevice, SEND_PKT_SEL, pkt, pkt_len);
195: }
196:
197: #ifdef sparc
198: void
199: en_reset(
200: BOOL enable
201: )
202: {
203: if (debuggerDevice)
204: (*reset_method)(debuggerDevice, RESET_SEL, enable);
205: }
206: #endif sparc
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.