Annotation of driverkit/Examples/KStub/IOStubKernLoad.m, revision 1.1.1.1

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) 1991 NeXT Computer, Inc.  All rights reserved. 
                     25:  *
                     26:  * IOStubKernLoad.m - kernload module for IOStub.
                     27:  *
                     28:  * HISTORY
                     29:  * 25-Apr-91    Doug Mitchell at NeXT
                     30:  *      Created. 
                     31:  */
                     32: 
                     33: #undef MACH_USER_API
                     34: #define KERNEL_PRIVATE 1
                     35: 
                     36: #define STUB_BLOCK_DEVICE      7
                     37: #define STUB_RAW_DEVICE                16
                     38: 
                     39: #import <kernserv/kern_server_types.h>
                     40: #import <mach/message.h>
                     41: #import "IOStub.h"
                     42: #import "IOStubPrivate.h"
                     43: #import "IOStubUnix.h"
                     44: #import <bsd/sys/conf.h>
                     45: #import <bsd/dev/ldd.h>
                     46: 
                     47: kern_server_t stub_var;
                     48: 
                     49: struct cdevsw stub_saved_cdevsw;
                     50: struct bdevsw stub_saved_bdevsw;
                     51: 
                     52: extern int nulldev();
                     53: extern int nodev();
                     54: extern int seltrue();
                     55: #define        nullstr 0
                     56: 
                     57: /*
                     58:  * these get copied into bdevsw/cdevsw at load time.
                     59:  */
                     60: struct bdevsw stub_bdevsw =  { (PFI)stub_open, 
                     61:                               (PFI)stub_close, 
                     62:                               (PFI)stub_strategy,      
                     63:                               nodev,
                     64:                               nodev,   
                     65:                               0 };
                     66: struct cdevsw stub_cdevsw =  { (PFI)stub_open,
                     67:                               (PFI)stub_close, 
                     68:                               (PFI)stub_read,  
                     69:                               (PFI)stub_write,
                     70:                               (PFI)stub_ioctl, 
                     71:                               nodev,           
                     72:                               nulldev, 
                     73:                               seltrue, 
                     74:                               nodev,           
                     75:                               nodev,
                     76:                               nodev };
                     77: 
                     78: void stub_announce(int unit);
                     79: void stub_port_gone(port_name_t port);
                     80: void stub_terminate(int unit);
                     81: void stub_server(msg_header_t *in_p, int unit);
                     82: 
                     83: /* 
                     84:  * we're just placed into memory here. Actual device initialization
                     85:  * and instantiation is done in stub_server().
                     86:  */
                     87: void stub_announce(int unit) 
                     88: {
                     89:        IOLog("stub%d: IOStub device Loaded\n", unit);
                     90: } /* stub_announce() */
                     91: 
                     92: void stub_port_gone(port_name_t port) 
                     93: {
                     94:        /* no-op, we don't really care about any ports. */
                     95:        
                     96: } /* stub_port_gone() */
                     97: 
                     98: void stub_terminate(int unit) 
                     99: {
                    100:        int i;
                    101:        
                    102:        xpr_stub("stub_terminate\n", 1,2,3,4,5);
                    103:        
                    104:        /* 
                    105:         * remove ourself from devsw's.
                    106:         */
                    107:        bdevsw[STUB_BLOCK_DEVICE] = stub_saved_bdevsw;
                    108:        cdevsw[STUB_RAW_DEVICE]   = stub_saved_cdevsw;
                    109:        for(i=0; i<NUM_IOSTUBS; i++) {
                    110:                if(stub_object[i].stub_id != nil) {
                    111:                        [stub_object[i].stub_id free];
                    112:                        stub_object[i].stub_id = nil;
                    113:                        IOFree(stub_object[i].physbuf, sizeof(struct buf));
                    114:                }
                    115:        }       
                    116:        
                    117:        IOLog("stub%d: Stub Device Unloaded\n", unit);
                    118: } /* stub_terminate() */
                    119: 
                    120: /*
                    121:  * Initialize and instantiate. This is invoked upon receipt of any message.
                    122:  *
                    123:  * FIXME: this could share common code with stub_probe() when we're no longer
                    124:  * a loadable module.
                    125:  */
                    126: static int stub_is_initialized = 0;
                    127: 
                    128: void stub_server(msg_header_t *in_p, int unit)
                    129: {
                    130:        int Unit;
                    131: 
                    132:        if(stub_is_initialized) {
                    133:                IOLog("stub_server already initialized\n");
                    134:                goto done;
                    135:        }
                    136:        
                    137: #if    m68k
                    138:        /*
                    139:         * First initialize the libraries we'll use.
                    140:         */
                    141:        IOlibIOInit();          
                    142: #endif m68k
                    143: #ifdef XPR_DEBUG
                    144: #if    m68k
                    145:        xprInit(500);
                    146: #endif m68k
                    147:        xprSetBitmask(XPR_IODEVICE_INDEX, XPR_DEVICE | XPR_STUB);
                    148: #endif XPR_DEBUG
                    149:        xpr_stub("stub_server\n", 1,2,3,4,5);
                    150:        
                    151:        for(Unit=0; Unit<NUM_IOSTUBS; Unit++) {
                    152:                stub_object[Unit].stub_id = [IOStub stubProbe:Unit];
                    153:                if(stub_object[Unit].stub_id != nil) {
                    154:                        stub_object[Unit].physbuf = 
                    155:                                IOMalloc(sizeof(struct buf));
                    156:                        stub_object[Unit].physbuf->b_flags = 0;
                    157:                }
                    158:        }
                    159:        
                    160:        /* 
                    161:         * place ourself in cdevsw and bdevsw.
                    162:         */
                    163:        stub_saved_bdevsw = bdevsw[STUB_BLOCK_DEVICE];
                    164:        stub_saved_cdevsw = cdevsw[STUB_RAW_DEVICE];
                    165:        bdevsw[STUB_BLOCK_DEVICE] = stub_bdevsw;
                    166:        cdevsw[STUB_RAW_DEVICE]   = stub_cdevsw;
                    167: 
                    168:        IOLog("IOStub device Installed\n");
                    169: 
                    170:        /*
                    171:         * return message to loader.
                    172:         */
                    173: done:
                    174:        msg_send(in_p, 
                    175:                MSG_OPTION_NONE,
                    176:                0);     
                    177: } /* stub_server() */
                    178: 
                    179: 
                    180: /* end of stub_ks.m */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.