]> git.saurik.com Git - apple/xnu.git/blob - bsd/kern/bsd_init.c
3042dfd6722f766812787d5386e81562995cd969
[apple/xnu.git] / bsd / kern / bsd_init.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * Copyright (c) 1982, 1986, 1989, 1991, 1992, 1993
24 * The Regents of the University of California. All rights reserved.
25 * (c) UNIX System Laboratories, Inc.
26 * All or some portions of this file are derived from material licensed
27 * to the University of California by American Telephone and Telegraph
28 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
29 * the permission of UNIX System Laboratories, Inc.
30 *
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
33 * are met:
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
39 * 3. All advertising materials mentioning features or use of this software
40 * must display the following acknowledgement:
41 * This product includes software developed by the University of
42 * California, Berkeley and its contributors.
43 * 4. Neither the name of the University nor the names of its contributors
44 * may be used to endorse or promote products derived from this software
45 * without specific prior written permission.
46 *
47 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * SUCH DAMAGE.
58 *
59 * @(#)init_main.c 8.16 (Berkeley) 5/14/95
60 */
61
62 /*
63 *
64 * Mach Operating System
65 * Copyright (c) 1987 Carnegie-Mellon University
66 * All rights reserved. The CMU software License Agreement specifies
67 * the terms and conditions for use and redistribution.
68 */
69 /*
70 * HISTORY
71 * 16-Apr-98 A. Ramesh at Apple
72 * Created for Apple Core from DR2 init_main.c.
73 */
74
75 #include <quota.h>
76
77 #include <sys/param.h>
78 #include <sys/filedesc.h>
79 #include <sys/kernel.h>
80 #include <sys/mount.h>
81 #include <sys/proc.h>
82 #include <sys/systm.h>
83 #include <sys/vnode.h>
84 #include <sys/conf.h>
85 #include <sys/buf.h>
86 #include <sys/clist.h>
87 #include <sys/user.h>
88 #include <ufs/ufs/quota.h>
89
90 #include <sys/malloc.h>
91 #include <sys/dkstat.h>
92
93 #include <machine/spl.h>
94 #include <kern/thread.h>
95 #include <kern/task.h>
96 #include <kern/ast.h>
97
98 #include <mach/vm_param.h>
99
100 #include <vm/vm_map.h>
101 #include <vm/vm_kern.h>
102
103 #include <sys/ux_exception.h>
104
105 #include <sys/reboot.h>
106 #include <mach/exception_types.h>
107 #include <dev/busvar.h>
108 #include <sys/kdebug.h>
109
110 extern shared_region_mapping_t system_shared_region;
111
112 char copyright[] =
113 "Copyright (c) 1982, 1986, 1989, 1991, 1993\n\tThe Regents of the University of California. All rights reserved.\n\n";
114
115 extern void ux_handler();
116
117 /* Components of the first process -- never freed. */
118 struct proc proc0;
119 struct session session0;
120 struct pgrp pgrp0;
121 struct pcred cred0;
122 struct filedesc filedesc0;
123 struct plimit limit0;
124 struct pstats pstats0;
125 struct sigacts sigacts0;
126 struct proc *kernproc, *initproc;
127
128
129 long cp_time[CPUSTATES];
130 long dk_seek[DK_NDRIVE];
131 long dk_time[DK_NDRIVE];
132 long dk_wds[DK_NDRIVE];
133 long dk_wpms[DK_NDRIVE];
134 long dk_xfer[DK_NDRIVE];
135 long dk_bps[DK_NDRIVE];
136
137 int dk_busy;
138 int dk_ndrive;
139
140 long tk_cancc;
141 long tk_nin;
142 long tk_nout;
143 long tk_rawcc;
144
145 /* Global variables to make pstat happy. We do swapping differently */
146 int nswdev, nswap;
147 int nswapmap;
148 void *swapmap;
149 struct swdevt swdevt[1];
150
151 dev_t rootdev; /* device of the root */
152 dev_t dumpdev; /* device to take dumps on */
153 long dumplo; /* offset into dumpdev */
154 long hostid;
155 char hostname[MAXHOSTNAMELEN];
156 int hostnamelen;
157 char domainname[MAXDOMNAMELEN];
158 int domainnamelen;
159
160 char rootdevice[16]; /* hfs device names have at least 9 chars */
161 struct timeval boottime; /* GRODY! This has to go... */
162 #if FIXME /* [ */
163 struct timeval time;
164 #endif /* FIXME ] */
165
166 #ifdef KMEMSTATS
167 struct kmemstats kmemstats[M_LAST];
168 #endif
169
170 int lbolt; /* awoken once a second */
171 struct vnode *rootvp;
172 int boothowto = RB_DEBUG;
173
174 vm_map_t bsd_pageable_map;
175 vm_map_t mb_map;
176
177 int cmask = CMASK;
178
179 int parse_bsd_args(void);
180 extern int bsd_hardclockinit;
181 extern vm_address_t bsd_init_task;
182 extern char init_task_failure_data[];
183
184 funnel_t * kernel_flock;
185 funnel_t * network_flock;
186 int disable_funnel = 0; /* disables split funnel */
187 int enable_funnel = 0; /* disables split funnel */
188
189 /*
190 * Initialization code.
191 * Called from cold start routine as
192 * soon as a stack and segmentation
193 * have been established.
194 * Functions:
195 * clear and free user core
196 * turn on clock
197 * hand craft 0th process
198 * call all initialization routines
199 * fork - process 0 to schedule
200 * - process 1 execute bootstrap
201 * - process 2 to page out
202 */
203
204 /*
205 * Sets the name for the given task.
206 */
207 void proc_name(s, p)
208 char *s;
209 struct proc *p;
210 {
211 int length = strlen(s);
212
213 bcopy(s, p->p_comm,
214 length >= sizeof(p->p_comm) ? sizeof(p->p_comm) :
215 length + 1);
216 }
217
218
219 /* To allow these values to be patched, they're globals here */
220 #include <machine/vmparam.h>
221 struct rlimit vm_initial_limit_stack = { DFLSSIZ, MAXSSIZ };
222 struct rlimit vm_initial_limit_data = { DFLDSIZ, MAXDSIZ };
223 struct rlimit vm_initial_limit_core = { DFLCSIZ, MAXCSIZ };
224
225 extern thread_t first_thread;
226
227 #define SPL_DEBUG 0
228 #if SPL_DEBUG
229 #define dprintf(x) printf x
230 #else SPL_DEBUG
231 #define dprintf(x)
232 #endif /* SPL_DEBUG */
233
234 extern thread_t cloneproc(struct proc *, int);
235
236 void
237 bsd_init()
238 {
239 register struct proc *p;
240 extern struct ucred *rootcred;
241 register int i;
242 int s;
243 thread_t th;
244 extern void bsdinit_task();
245 void lightning_bolt(void );
246 kern_return_t ret;
247 boolean_t funnel_state;
248 extern void uthread_zone_init();
249
250 extern int (*mountroot) __P((void));
251
252
253 #if 1
254 /* split funnel is enabled by default */
255 PE_parse_boot_arg("dfnl", &disable_funnel);
256 #else
257 /* split funnel is disabled befault */
258 disable_funnel = 1;
259 PE_parse_boot_arg("efnl", &enable_funnel);
260 if (enable_funnel) {
261 /* enable only if efnl is set in bootarg */
262 disable_funnel = 0;
263 }
264 #endif
265
266 kernel_flock = funnel_alloc(KERNEL_FUNNEL);
267 if (kernel_flock == (funnel_t *)0 ) {
268 panic("fail to allocate kernel mutex lock\n");
269 }
270
271
272 funnel_state = thread_funnel_set(kernel_flock, TRUE);
273
274 if (!disable_funnel) {
275 network_flock = funnel_alloc(NETWORK_FUNNEL);
276 if (network_flock == (funnel_t *)0 ) {
277 panic("fail to allocate network mutex lock\n");
278 }
279 } else {
280 network_flock = kernel_flock;
281 }
282
283
284 printf(copyright);
285
286 kmeminit();
287
288 parse_bsd_args();
289
290 bsd_bufferinit();
291
292 /* Initialize the uthread zone */
293 uthread_zone_init();
294
295 /*
296 * Initialize process and pgrp structures.
297 */
298 procinit();
299
300 kernproc = &proc0;
301
302 p = kernproc;
303
304 /* kernel_task->proc = kernproc; */
305 set_bsdtask_info(kernel_task,(void *)kernproc);
306 p->p_pid = 0;
307
308 /* give kernproc a name */
309 proc_name("kernel_task", p);
310
311 if (current_task() != kernel_task)
312 printf("We are in for problem, current task in not kernel task\n");
313
314 /*
315 * Create process 0.
316 */
317 LIST_INSERT_HEAD(&allproc, p, p_list);
318 p->p_pgrp = &pgrp0;
319 LIST_INSERT_HEAD(PGRPHASH(0), &pgrp0, pg_hash);
320 LIST_INIT(&pgrp0.pg_members);
321 LIST_INSERT_HEAD(&pgrp0.pg_members, p, p_pglist);
322
323 pgrp0.pg_session = &session0;
324 session0.s_count = 1;
325 session0.s_leader = p;
326
327 p->task = kernel_task;
328
329 p->p_stat = SRUN;
330 p->p_flag = P_INMEM|P_SYSTEM;
331 p->p_nice = NZERO;
332 p->p_pptr = p;
333 lockinit(&p->signal_lock, PVM, "signal", 0, 0);
334 p->sigwait = FALSE;
335 p->sigwait_thread = THREAD_NULL;
336 p->exit_thread = THREAD_NULL;
337
338 /* Create credentials. */
339 lockinit(&cred0.pc_lock, PLOCK, "proc0 cred", 0, 0);
340 cred0.p_refcnt = 1;
341 p->p_cred = &cred0;
342 p->p_ucred = crget();
343 p->p_ucred->cr_ngroups = 1; /* group 0 */
344
345 /* Create the file descriptor table. */
346 filedesc0.fd_refcnt = 1+1; /* +1 so shutdown will not _FREE_ZONE */
347 p->p_fd = &filedesc0;
348 filedesc0.fd_cmask = cmask;
349
350 /* Create the limits structures. */
351 p->p_limit = &limit0;
352 for (i = 0; i < sizeof(p->p_rlimit)/sizeof(p->p_rlimit[0]); i++)
353 limit0.pl_rlimit[i].rlim_cur =
354 limit0.pl_rlimit[i].rlim_max = RLIM_INFINITY;
355 limit0.pl_rlimit[RLIMIT_NOFILE].rlim_cur = NOFILE;
356 limit0.pl_rlimit[RLIMIT_NPROC].rlim_cur = MAXUPRC;
357 limit0.pl_rlimit[RLIMIT_STACK] = vm_initial_limit_stack;
358 limit0.pl_rlimit[RLIMIT_DATA] = vm_initial_limit_data;
359 limit0.pl_rlimit[RLIMIT_CORE] = vm_initial_limit_core;
360 limit0.p_refcnt = 1;
361
362 p->p_stats = &pstats0;
363 p->p_sigacts = &sigacts0;
364
365 /*
366 * Charge root for one process.
367 */
368 (void)chgproccnt(0, 1);
369
370
371 /*
372 * Allocate a kernel submap for pageable memory
373 * for temporary copying (table(), execve()).
374 */
375 {
376 vm_offset_t min;
377
378 ret = kmem_suballoc(kernel_map,
379 &min,
380 (vm_size_t)512*1024,
381 TRUE,
382 TRUE,
383 &bsd_pageable_map);
384 if (ret != KERN_SUCCESS)
385 panic("Failed to allocare bsd pageable map\n");
386 }
387
388 /*
389 * Initialize the calendar.
390 */
391 IOKitResetTime();
392
393 ubc_init();
394
395 /* Initialize the file systems. */
396 vfsinit();
397
398 /* Initialize mbuf's. */
399 mbinit();
400
401 /* Initialize syslog */
402 log_init();
403
404 /* Initialize SysV shm */
405 shminit();
406
407 /* POSIX Shm and Sem */
408 pshm_cache_init();
409 psem_cache_init();
410
411 /*
412 * Initialize protocols. Block reception of incoming packets
413 * until everything is ready.
414 */
415 s = splimp();
416 sysctl_register_fixed();
417 dlil_init();
418 socketinit();
419 domaininit();
420 splx(s);
421
422 /*
423 * Create kernel idle cpu processes. This must be done
424 * before a context switch can occur (and hence I/O can
425 * happen in the binit() call).
426 */
427 p->p_fd->fd_cdir = NULL;
428 p->p_fd->fd_rdir = NULL;
429
430
431 #ifdef GPROF
432 /* Initialize kernel profiling. */
433 kmstartup();
434 #endif
435
436 /* kick off timeout driven events by calling first time */
437 thread_wakeup(&lbolt);
438 timeout(lightning_bolt,0,hz);
439
440 bsd_autoconf();
441
442 /*
443 * We attach the loopback interface *way* down here to ensure
444 * it happens after autoconf(), otherwise it becomes the
445 * "primary" interface.
446 */
447 #include <loop.h>
448 #if NLOOP > 0
449 loopattach(); /* XXX */
450 #endif
451
452 vnode_pager_bootstrap();
453
454 /* Mount the root file system. */
455 while( TRUE) {
456 int err;
457
458 setconf();
459 /*
460 * read the time after clock_initialize_calendar()
461 * and before nfs mount
462 */
463 microtime(&time);
464
465 if (0 == (err = vfs_mountroot()))
466 break;
467 printf("cannot mount root, errno = %d\n", err);
468 boothowto |= RB_ASKNAME;
469 }
470
471 mountlist.cqh_first->mnt_flag |= MNT_ROOTFS;
472
473 /* Get the vnode for '/'. Set fdp->fd_fd.fd_cdir to reference it. */
474 if (VFS_ROOT(mountlist.cqh_first, &rootvnode))
475 panic("cannot find root vnode");
476 filedesc0.fd_cdir = rootvnode;
477 VREF(rootvnode);
478 VOP_UNLOCK(rootvnode, 0, p);
479
480
481 /*
482 * Now can look at time, having had a chance to verify the time
483 * from the file system. Reset p->p_rtime as it may have been
484 * munched in mi_switch() after the time got set.
485 */
486 p->p_stats->p_start = boottime = time;
487 p->p_rtime.tv_sec = p->p_rtime.tv_usec = 0;
488
489 #ifdef DEVFS
490 {
491 extern void devfs_kernel_mount(char * str);
492
493 devfs_kernel_mount("/dev");
494 }
495 #endif DEVFS
496
497 /* Initialize signal state for process 0. */
498 siginit(p);
499
500 /* printf("Launching user process\n"); */
501
502 bsd_utaskbootstrap();
503
504 (void) thread_funnel_set(kernel_flock, FALSE);
505 }
506
507 void
508 bsdinit_task()
509 {
510 struct proc *p = current_proc();
511 struct uthread *ut;
512 kern_return_t kr;
513 thread_act_t th_act;
514 boolean_t funnel_state;
515
516 funnel_state = thread_funnel_set(kernel_flock, TRUE);
517
518 #if FIXME /* [ */
519
520 ipc_port_t master_bootstrap_port;
521 task_t bootstrap_task;
522 thread_act_t bootstrap_thr_act;
523 ipc_port_t root_device_port;
524
525 master_bootstrap_port = ipc_port_alloc_kernel();
526 if (master_bootstrap_port == IP_NULL)
527 panic("can't allocate master bootstrap port");
528 printf("setting bootstrap port \n");
529 task_set_special_port(bootstrap_task,
530 TASK_BOOTSTRAP_PORT,
531 ipc_port_make_send(master_bootstrap_port));
532
533 printf("Setting exception port for the init task\n");
534 (void) task_set_exception_ports(get_threadtask(th),
535 EXC_MASK_ALL &
536 ~(EXC_MASK_SYSCALL |
537 EXC_MASK_MACH_SYSCALL | EXC_MASK_RPC_ALERT),
538 ux_exception_port,
539 EXCEPTION_DEFAULT, 0);
540
541 #endif /* FIXME ] */
542 proc_name("init", p);
543
544 ux_handler_init();
545 /* port_reference(ux_exception_port);*/
546
547 th_act = current_act();
548 (void) host_set_exception_ports(host_priv_self(),
549 EXC_MASK_ALL & ~(EXC_MASK_SYSCALL |
550 EXC_MASK_MACH_SYSCALL |
551 EXC_MASK_RPC_ALERT),
552 ux_exception_port,
553 EXCEPTION_DEFAULT, 0);
554
555 (void) task_set_exception_ports(get_threadtask(th_act),
556 EXC_MASK_ALL & ~(EXC_MASK_SYSCALL |
557 EXC_MASK_MACH_SYSCALL |
558 EXC_MASK_RPC_ALERT),
559 ux_exception_port,
560 EXCEPTION_DEFAULT, 0);
561
562
563
564
565 ut = (uthread_t)get_bsdthread_info(th_act);
566 ut->uu_ar0 = (void *)get_user_regs(th_act);
567
568 bsd_hardclockinit = 1; /* Start bsd hardclock */
569 bsd_init_task = get_threadtask(th_act);
570 init_task_failure_data[0] = 0;
571 vm_set_shared_region(get_threadtask(th_act), system_shared_region);
572 load_init_program(p);
573
574 (void) thread_funnel_set(kernel_flock, FALSE);
575
576 }
577
578 void
579 lightning_bolt()
580 {
581 boolean_t funnel_state;
582 extern void klogwakeup(void);
583
584 funnel_state = thread_funnel_set(kernel_flock, TRUE);
585
586 thread_wakeup(&lbolt);
587 timeout(lightning_bolt,0,hz);
588 klogwakeup();
589
590 (void) thread_funnel_set(kernel_flock, FALSE);
591 }
592
593 bsd_autoconf(){
594 extern kern_return_t IOKitBSDInit( void );
595
596 kminit();
597
598 /*
599 * Early startup for bsd pseudodevices.
600 */
601 {
602 struct pseudo_init *pi;
603
604 for (pi = pseudo_inits; pi->ps_func; pi++)
605 (*pi->ps_func) (pi->ps_count);
606 }
607
608 return( IOKitBSDInit());
609 }
610
611
612 #include <sys/disklabel.h> // for MAXPARTITIONS
613
614 setconf()
615 {
616 extern kern_return_t IOFindBSDRoot( char * rootName,
617 dev_t * root, u_int32_t * flags );
618
619 extern int (*mountroot) __P((void));
620 extern int nfs_mountroot(); /* nfs_vfsops.c */
621
622 u_int32_t flags;
623 kern_return_t err;
624
625 /*
626 * calls into IOKit can generate networking registrations
627 * which needs to be under network funnel. Right thing to do
628 * here is to drop the funnel alltogether and regrab it afterwards
629 */
630 thread_funnel_set(kernel_flock, FALSE);
631 err = IOFindBSDRoot( rootdevice, &rootdev, &flags );
632 thread_funnel_set(kernel_flock, TRUE);
633 if( err) {
634 printf("setconf: IOFindBSDRoot returned an error (%d);"
635 "setting rootdevice to 'sd0a'.\n", err); /* XXX DEBUG TEMP */
636 rootdev = makedev( 6, 0 );
637 strcpy( rootdevice, "sd0a" );
638 flags = 0;
639 }
640
641 /* if network device then force nfs root */
642 if( flags & 1 ) {
643 printf("mounting nfs root\n");
644 mountroot = nfs_mountroot;
645 } else {
646 /* otherwise have vfs determine root filesystem */
647 mountroot = NULL;
648 }
649
650 }
651
652 bsd_utaskbootstrap()
653 {
654 thread_act_t th_act;
655
656 th_act = (thread_act_t)cloneproc(kernproc, 0);
657 initproc = pfind(1);
658 thread_hold(th_act);
659 (void) thread_stop_wait(getshuttle_thread(th_act));
660 thread_ast_set(th_act,AST_BSD_INIT);
661 thread_release(th_act);
662 thread_unstop(getshuttle_thread(th_act));
663 (void) thread_resume(th_act);
664 }
665
666 parse_bsd_args()
667 {
668 extern char init_args[];
669 char namep[16];
670 extern int boothowto;
671 extern int srv;
672 extern int ncl;
673
674 int len;
675
676 if (PE_parse_boot_arg("-s", namep)) {
677 boothowto |= RB_SINGLE;
678 len = strlen(init_args);
679 if(len != 0)
680 strcat(init_args," -s");
681 else
682 strcat(init_args,"-s");
683 }
684 if (PE_parse_boot_arg("-b", namep)) {
685 boothowto |= RB_NOBOOTRC;
686 len = strlen(init_args);
687 if(len != 0)
688 strcat(init_args," -b");
689 else
690 strcat(init_args,"-b");
691 }
692
693 if (PE_parse_boot_arg("-F", namep)) {
694 len = strlen(init_args);
695 if(len != 0)
696 strcat(init_args," -F");
697 else
698 strcat(init_args,"-F");
699 }
700
701 if (PE_parse_boot_arg("-v", namep)) {
702 len = strlen(init_args);
703 if(len != 0)
704 strcat(init_args," -v");
705 else
706 strcat(init_args,"-v");
707 }
708
709 if (PE_parse_boot_arg("-x", namep)) { /* safe boot */
710 len = strlen(init_args);
711 if(len != 0)
712 strcat(init_args," -x");
713 else
714 strcat(init_args,"-x");
715 }
716
717 PE_parse_boot_arg("srv", &srv);
718 PE_parse_boot_arg("ncl", &ncl);
719 PE_parse_boot_arg("nbuf", &nbuf);
720
721 return 0;
722 }
723
724 boolean_t
725 thread_funnel_switch(
726 int oldfnl,
727 int newfnl)
728 {
729 thread_t cur_thread;
730 boolean_t funnel_state_prev;
731 int curfnl;
732 funnel_t * curflock;
733 funnel_t * oldflock;
734 funnel_t * newflock;
735 funnel_t * exist_funnel;
736 extern int disable_funnel;
737
738
739 if (disable_funnel)
740 return(TRUE);
741
742 if(oldfnl == newfnl) {
743 panic("thread_funnel_switch: can't switch to same funnel");
744 }
745
746 if ((oldfnl != NETWORK_FUNNEL) && (oldfnl != KERNEL_FUNNEL))
747 {
748 panic("thread_funnel_switch: invalid oldfunnel");
749 }
750 if ((newfnl != NETWORK_FUNNEL) && (newfnl != KERNEL_FUNNEL))
751 {
752 panic("thread_funnel_switch: invalid oldfunnel");
753 }
754
755 if((curflock = thread_funnel_get()) == THR_FUNNEL_NULL) {
756 panic("thread_funnel_switch: no funnel held");
757 }
758
759 cur_thread = current_thread();
760
761 if ((oldfnl == NETWORK_FUNNEL) && (curflock != network_flock))
762 panic("thread_funnel_switch: network funnel not held");
763
764 if ((oldfnl == KERNEL_FUNNEL) && (curflock != kernel_flock))
765 panic("thread_funnel_switch: network funnel not held");
766
767 if(oldfnl == NETWORK_FUNNEL) {
768 oldflock = network_flock;
769 newflock = kernel_flock;
770 } else {
771 oldflock = kernel_flock;
772 newflock = network_flock;
773 }
774 KERNEL_DEBUG(0x603242c | DBG_FUNC_NONE, oldflock, 1, 0, 0, 0);
775 thread_funnel_set(oldflock, FALSE);
776 KERNEL_DEBUG(0x6032428 | DBG_FUNC_NONE, newflock, 1, 0, 0, 0);
777 thread_funnel_set(newflock, TRUE);
778 KERNEL_DEBUG(0x6032434 | DBG_FUNC_NONE, newflock, 1, 0, 0, 0);
779
780 return(TRUE);
781 }