Annotation of XNU/osfmk/kern/bootstrap.c, revision 1.1.1.1

1.1       root        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:  * @OSF_FREE_COPYRIGHT@
                     24:  */
                     25: /* 
                     26:  * Mach Operating System
                     27:  * Copyright (c) 1991,1990,1989 Carnegie Mellon University
                     28:  * All Rights Reserved.
                     29:  * 
                     30:  * Permission to use, copy, modify and distribute this software and its
                     31:  * documentation is hereby granted, provided that both the copyright
                     32:  * notice and this permission notice appear in all copies of the
                     33:  * software, derivative works or modified versions, and any portions
                     34:  * thereof, and that both notices appear in supporting documentation.
                     35:  * 
                     36:  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
                     37:  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
                     38:  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
                     39:  * 
                     40:  * Carnegie Mellon requests users of this software to return to
                     41:  * 
                     42:  *  Software Distribution Coordinator  or  [email protected]
                     43:  *  School of Computer Science
                     44:  *  Carnegie Mellon University
                     45:  *  Pittsburgh PA 15213-3890
                     46:  * 
                     47:  * any improvements or extensions that they make and grant Carnegie Mellon
                     48:  * the rights to redistribute these changes.
                     49:  */
                     50: /*
                     51:  */
                     52: /*
                     53:  * Bootstrap the various built-in servers.
                     54:  */
                     55: 
                     56: #include <mach_kdb.h>
                     57: #include <bootstrap_symbols.h>
                     58: #include <dipc.h>
                     59: 
                     60: #include <cputypes.h>
                     61: #include <mach/port.h>
                     62: #include <mach/message.h>
                     63: #include <mach/machine/vm_types.h>
                     64: #include <mach/vm_prot.h>
                     65: #include <mach/boolean.h>
                     66: #include <mach/boot_info.h>
                     67: #include <mach/mach_port_server.h>
                     68: #include <mach/bootstrap_server.h>
                     69: 
                     70: #include <device/device_port.h>
                     71: #include <ipc/ipc_space.h>
                     72: 
                     73: #include <kern/thread.h>
                     74: #include <ipc/ipc_port.h>
                     75: #include <ipc/ipc_entry.h>
                     76: #include <kern/host.h>
                     77: #include <kern/ledger.h>
                     78: #include <kern/processor.h>
                     79: #include <kern/zalloc.h>
                     80: #include <kern/misc_protos.h>
                     81: #include <vm/vm_object.h>
                     82: #include <vm/vm_page.h>
                     83: #include <vm/vm_map.h>
                     84: #include <vm/vm_fault.h>
                     85: 
                     86: #if    MACH_KDB
                     87: #include <ddb/db_sym.h>
                     88: 
                     89: #if defined(__alpha)
                     90: extern boolean_t       use_kdb;
                     91: extern int             stpages;
                     92: #endif /* defined(__alpha) */
                     93: 
                     94: #endif /* MACH_KDB */
                     95: 
                     96: vm_offset_t    kern_sym_start = 0;     /* pointer to kernel symbols */
                     97: vm_size_t      kern_sym_size = 0;      /* size of kernel symbols */
                     98: vm_offset_t    kern_args_start = 0;    /* kernel arguments */
                     99: vm_size_t      kern_args_size = 0;     /* size of kernel arguments */
                    100: vm_offset_t    boot_sym_start = 0;     /* pointer to bootstrap symbols */
                    101: vm_size_t      boot_sym_size = 0;      /* size of bootstrap symbols */
                    102: vm_offset_t    boot_args_start = 0;    /* bootstrap arguments */
                    103: vm_size_t      boot_args_size = 0;     /* size of bootstrap arguments */
                    104: vm_offset_t    boot_start = 0;         /* pointer to bootstrap image */
                    105: vm_size_t      boot_size = 0;          /* size of bootstrap image */
                    106: vm_offset_t    boot_region_desc = 0;   /* bootstrap region descriptions */
                    107: vm_size_t      boot_region_count = 0;  /* number of regions */
                    108: int            boot_thread_state_flavor = 0;
                    109: thread_state_t boot_thread_state = 0;
                    110: unsigned int   boot_thread_state_count = 0;
                    111: vm_offset_t    env_start = 0;          /* environment */
                    112: vm_size_t      env_size = 0;           /* size of environment */
                    113: 
                    114: vm_offset_t    load_info_start = 0;    /* pointer to bootstrap load info */
                    115: vm_size_t      load_info_size = 0;     /* size of bootstrap load info */
                    116: 
                    117: kern_return_t
                    118: do_bootstrap_ports(
                    119:         ipc_port_t bootstrap,
                    120:         ipc_port_t *priv_hostp,
                    121:         ipc_port_t *priv_devicep,
                    122:         ipc_port_t *wired_ledgerp,
                    123:         ipc_port_t *paged_ledgerp,
                    124:         ipc_port_t *host_securityp)
                    125: {
                    126: #ifdef lint
                    127:     bootstrap = ipc_port_make_send(realhost.host_priv_self);
                    128: #endif /* lint */
                    129: 
                    130:     *priv_hostp = ipc_port_make_send(realhost.host_priv_self);
                    131:     *priv_devicep = ipc_port_make_send(master_device_port);
                    132:     *wired_ledgerp = ipc_port_make_send(root_wired_ledger_port);
                    133:     *paged_ledgerp = ipc_port_make_send(root_paged_ledger_port);
                    134:     *host_securityp = ipc_port_make_send(realhost.host_security_self);
                    135:     return KERN_SUCCESS;
                    136: }
                    137: 
                    138: kern_return_t
                    139: do_bootstrap_arguments(
                    140:        ipc_port_t              bootstrap_port,
                    141:        task_t                  task,
                    142:        vm_offset_t             *arguments_ptr,
                    143:        mach_msg_type_number_t  *arguments_count)
                    144: {
                    145:        vm_offset_t args_addr;
                    146:        unsigned int args_size;
                    147:        kern_return_t kr;
                    148:        vm_map_copy_t copy;
                    149: 
                    150: #ifdef lint
                    151:        bootstrap_port = (ipc_port_t) 0;
                    152:        task->map = VM_MAP_NULL;
                    153: #endif /* lint */
                    154: 
                    155:        if (boot_args_size == 0)
                    156:                args_size = PAGE_SIZE;
                    157:        else
                    158:                args_size = round_page(boot_args_size);
                    159:        kr = kmem_alloc_pageable(ipc_kernel_map, &args_addr, args_size);
                    160:        if (kr != KERN_SUCCESS)
                    161:                return kr;
                    162:        if (boot_args_size)
                    163:                bcopy((char *)boot_args_start, (char *)args_addr,
                    164:                      boot_args_size);
                    165:        if (args_size != boot_args_size)
                    166:                bzero((char *) args_addr + boot_args_size,
                    167:                      args_size - boot_args_size);
                    168:        kr = vm_map_copyin(ipc_kernel_map, args_addr, args_size, TRUE, &copy);
                    169:        assert(kr == KERN_SUCCESS);
                    170:        *arguments_ptr = (vm_offset_t) copy;
                    171:        *arguments_count = boot_args_size;
                    172:        return KERN_SUCCESS;
                    173: }
                    174: 
                    175: 
                    176: kern_return_t
                    177: do_bootstrap_environment(
                    178:        ipc_port_t              bootstrap_port,
                    179:        task_t                  task,
                    180:        vm_offset_t             *environment_ptr,
                    181:        mach_msg_type_number_t  *environment_count)
                    182: {
                    183:        vm_offset_t env_addr;
                    184:        vm_size_t alloc_size;
                    185:        kern_return_t kr;
                    186:        vm_map_copy_t copy;
                    187: 
                    188: #ifdef lint
                    189:        task->map = VM_MAP_NULL;
                    190:        bootstrap_port = (ipc_port_t) 0;
                    191: #endif /* lint */
                    192: 
                    193:        if (env_size == 0)
                    194:                alloc_size = PAGE_SIZE;
                    195:        else
                    196:                alloc_size = round_page(env_size);
                    197:        kr = kmem_alloc_pageable(ipc_kernel_map, &env_addr, alloc_size);
                    198:        if (kr != KERN_SUCCESS)
                    199:                return kr;
                    200:        if (env_size)
                    201:                bcopy((char *)env_start, (char *)env_addr, env_size);
                    202:        if (alloc_size != env_size)
                    203:                bzero((char *) env_addr + env_size,
                    204:                      alloc_size - env_size);
                    205:        kr = vm_map_copyin(ipc_kernel_map, env_addr, alloc_size, TRUE, &copy);
                    206:        assert(kr == KERN_SUCCESS);
                    207:        *environment_ptr = (vm_offset_t) copy;
                    208:        *environment_count = env_size;
                    209:        return KERN_SUCCESS;
                    210: }
                    211: 
                    212: kern_return_t 
                    213: do_bootstrap_completed(
                    214:        ipc_port_t bootstrap_port,
                    215:        task_t task)
                    216: {
                    217:     /* Need do nothing; only the bootstrap task cares when a
                    218:        server signals bootstrap_completed.  */
                    219:     return KERN_SUCCESS;
                    220: }
                    221: 
                    222: void   load_info_print(void);
                    223: 
                    224: #if    DEBUG
                    225: void
                    226: load_info_print(void)
                    227: {
                    228:        struct loader_info *lp = (struct loader_info *)load_info_start;
                    229: 
                    230:        printf("Load info: text (%#x, %#x, %#x)\n",
                    231:                lp->text_start, lp->text_size, lp->text_offset);
                    232:        printf("           data (%#x, %#x, %#x)\n",
                    233:                lp->data_start, lp->data_size, lp->data_offset);
                    234:        printf("           bss  (%#x)\n", lp->bss_size);
                    235:        printf("           syms (%#x, %#x)\n",
                    236:                lp->sym_offset, lp->sym_size);
                    237:        printf("           entry(%#x, %#x)\n",
                    238:                lp->entry_1, lp->entry_2);
                    239: }
                    240: #endif

unix.superglobalmegacorp.com

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