2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989, 1988 Carnegie Mellon University
28 * All Rights Reserved.
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.
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.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
56 * Author: Avadis Tevanian, Jr., Michael Wayne Young
58 * Copyright (C) 1986, Avadis Tevanian, Jr., Michael Wayne Young
60 * Basic initialization for I386 - ISA bus machines.
64 #include <platforms.h>
68 #include <fast_idle.h>
70 #include <mach/i386/vm_param.h>
73 #include <mach/vm_param.h>
74 #include <mach/vm_prot.h>
75 #include <mach/machine.h>
76 #include <mach/time_value.h>
77 #include <kern/etap_macros.h>
79 #include <kern/assert.h>
80 #include <kern/debug.h>
81 #include <kern/misc_protos.h>
82 #include <kern/startup.h>
83 #include <kern/clock.h>
84 #include <kern/time_out.h>
86 #include <kern/cpu_data.h>
87 #include <vm/vm_page.h>
89 #include <vm/vm_kern.h>
91 #include <i386/pmap.h>
94 #include <i386/misc_protos.h>
95 #include <i386/cpuid.h>
96 #include <i386/rtclock_entries.h>
97 #include <i386/AT386/mp/mp.h>
99 #include <ddb/db_aout.h>
100 #endif /* MACH_KDB */
103 #include <i386/AT386/kernBootStruct.h>
104 #include <mach/boot_info.h>
105 #include <mach/thread_status.h>
109 #include <i386/mp_desc.h>
113 #include <i386/AT386/mp/mp_v1_1.h>
116 #include <IOKit/IOPlatformExpert.h>
118 vm_size_t mem_size
= 0;
119 vm_offset_t first_addr
= 0; /* set by start.s - keep out of bss */
120 vm_offset_t first_avail
= 0;/* first after page tables */
121 vm_offset_t last_addr
;
123 vm_offset_t avail_start
, avail_end
;
124 vm_offset_t virtual_avail
, virtual_end
;
125 vm_offset_t hole_start
, hole_end
;
126 vm_offset_t avail_next
;
127 unsigned int avail_remaining
;
129 /* parameters passed from bootstrap loader */
130 int cnvmem
= 0; /* must be in .data section */
133 /* FIXME!! REMOVE WHEN OSFMK DEVICES ARE COMPLETELY PULLED OUT */
134 int dev_name_count
= 0;
135 int dev_name_list
= 0;
138 extern char edata
, end
;
141 extern char version
[];
143 void parse_arguments(void);
144 const char *getenv(const char *);
146 #define BOOT_LINE_LENGTH 160
147 char boot_string_store
[BOOT_LINE_LENGTH
] = {0};
148 char *boot_string
= (char *)0;
149 int boot_string_sz
= BOOT_LINE_LENGTH
;
153 #include <mach-o/loader.h>
154 vm_offset_t edata
, etext
, end
;
156 extern struct mach_header _mh_execute_header
;
157 void *sectTEXTB
; int sectSizeTEXT
;
158 void *sectDATAB
; int sectSizeDATA
;
159 void *sectOBJCB
; int sectSizeOBJC
;
160 void *sectLINKB
; int sectSizeLINK
;
162 /* Kernel boot information */
163 KERNBOOTSTRUCT kernBootStructData
;
164 KERNBOOTSTRUCT
*kernBootStruct
;
167 vm_offset_t kern_args_start
= 0; /* kernel arguments */
168 vm_size_t kern_args_size
= 0; /* size of kernel arguments */
176 struct segment_command
*sgp
;
179 sgp
= (struct segment_command
*) getsegbyname("__DATA");
181 sp
= (struct section
*) firstsect(sgp
);
184 if (sp
->flags
& S_ZEROFILL
)
185 bzero((char *) sp
->addr
, sp
->size
);
186 } while (sp
= (struct section
*)nextsect(sgp
, sp
));
190 bcopy((char *) KERNSTRUCT_ADDR
, (char *) &kernBootStructData
,
191 sizeof(kernBootStructData
));
193 kernBootStruct
= &kernBootStructData
;
195 end
= round_page( kernBootStruct
->kaddr
+ kernBootStruct
->ksize
);
202 * Cpu initialization. Running virtual, but without MACH VM
203 * set up. First C routine called.
206 machine_startup(void)
210 /* Now copy over various bits.. */
211 cnvmem
= kernBootStruct
->convmem
;
212 extmem
= kernBootStruct
->extmem
;
213 kern_args_start
= (vm_offset_t
) kernBootStruct
->bootString
;
214 kern_args_size
= strlen(kernBootStruct
->bootString
);
215 boottype
= kernBootStruct
->rootdev
;
217 /* Now retrieve addresses for end, edata, and etext
218 * from MACH-O headers.
221 sectTEXTB
= (void *) getsegdatafromheader(
222 &_mh_execute_header
, "__TEXT", §SizeTEXT
);
223 sectDATAB
= (void *) getsegdatafromheader(
224 &_mh_execute_header
, "__DATA", §SizeDATA
);
225 sectOBJCB
= (void *) getsegdatafromheader(
226 &_mh_execute_header
, "__OBJC", §SizeOBJC
);
227 sectLINKB
= (void *) getsegdatafromheader(
228 &_mh_execute_header
, "__LINKEDIT", §SizeLINK
);
230 etext
= (vm_offset_t
) sectTEXTB
+ sectSizeTEXT
;
231 edata
= (vm_offset_t
) sectDATAB
+ sectSizeDATA
;
234 printf_init(); /* Init this in case we need debugger */
235 panic_init(); /* Init this in case we need debugger */
237 PE_init_platform(FALSE
, kernBootStruct
);
238 PE_init_kprintf(FALSE
);
239 PE_init_printf(FALSE
);
242 * Parse startup arguments
247 * Set up initial thread so current_thread() works early on
249 pageout_thread
.top_act
= &pageout_act
;
250 pageout_act
.thread
= &pageout_thread
;
251 thread_machine_set_current(&pageout_thread
);
254 * Do basic VM initialization
258 PE_init_platform(TRUE
, kernBootStruct
);
259 PE_init_kprintf(TRUE
);
260 PE_init_printf(TRUE
);
264 * Initialize the kernel debugger.
269 * Cause a breakpoint trap to the debugger before proceeding
270 * any further if the proper option bit was specified in
274 if (halt_in_debugger
) {
275 printf("inline call to debugger(machine_startup)\n");
276 Debugger("inline call");
278 #endif /* MACH_KDB */
284 machine_slot
[0].is_cpu
= TRUE
;
285 machine_slot
[0].running
= TRUE
;
288 machine_slot
[0].cpu_type
= CPU_TYPE_I386
;
289 machine_slot
[0].cpu_subtype
= CPU_SUBTYPE_PENTPRO
;
291 machine_slot
[0].cpu_type
= cpuid_cputype(0);
292 machine_slot
[0].cpu_subtype
= CPU_SUBTYPE_AT386
;
306 vm_offset_t env_start
= 0; /* environment */
307 vm_size_t env_size
= 0; /* size of environment */
310 * Parse command line arguments.
313 parse_arguments(void)
315 unsigned int boot_arg
;
317 if (PE_parse_boot_arg("maxmem", &boot_arg
))
319 mem_size
= boot_arg
* (1024 * 1024);
322 if (PE_parse_boot_arg("debug", &boot_arg
))
324 if (boot_arg
& DB_HALT
) halt_in_debugger
= 1;
325 if (boot_arg
& DB_PRT
) disableDebugOuput
= FALSE
;
330 getenv(const char *name
)
332 int len
= strlen(name
);
333 const char *p
= (const char *)env_start
;
334 const char *endp
= p
+ env_size
;
339 if (strncmp(name
, p
, len
) == 0 && *(p
+ len
) == '=')
348 calibrate_delay(void);
351 * Find devices. The system is alive.
361 * Adjust delay count before entering drivers
367 * Display CPU identification
369 cpuid_cpu_display("CPU identification", 0);
370 cpuid_cache_display("CPU configuration", 0);
377 * Set up to use floating point.
384 #endif /* NPCI > 0 */
388 * Configure clock devices.
399 halt_all_cpus(FALSE
);
402 int reset_mem_on_reboot
= 1;
405 * Halt the system or reboot.
408 halt_all_cpus(boolean_t reboot
)
413 * Tell the BIOS not to clear and test memory.
415 if (!reset_mem_on_reboot
)
416 *(unsigned short *)phystokv(0x472) = 0x1234;
418 printf("MACH Reboot\n");
419 PEHaltRestart( kPERestartCPU
);
423 printf("CPU halted\n");
424 PEHaltRestart( kPEHaltCPU
);
430 * Basic VM initialization.
436 int i
,j
; /* Standard index vars. */
437 vm_size_t bios_hole_size
;
444 bzero((char *)&edata
,(unsigned)(&end
- &edata
));
447 boot_string
= &boot_string_store
[0];
450 * Initialize the pic prior to any possible call to an spl.
457 * Initialize the Event Trace Analysis Package
458 * Static Phase: 1 of 2
463 * Compute the memory size.
468 * fdisk needs to change to use a sysctl instead of
469 * opening /dev/kmem and reading out the kernboot structure
472 first_addr
= (char *)(KERNSTRUCT_ADDR
) + sizeof(KERNBOOTSTRUCT
);
477 /* First two pages are used to boot the other cpus. */
478 /* TODO - reclaim pages after all cpus have booted */
484 /* BIOS leaves data in low memory */
485 last_addr
= 1024*1024 + extmem
*1024;
487 /* extended memory starts at 1MB */
489 bios_hole_size
= 1024*1024 - trunc_page((vm_offset_t
)(1024 * cnvmem
));
492 * Initialize for pmap_free_pages and pmap_next_page.
493 * These guys should be page-aligned.
496 hole_start
= trunc_page((vm_offset_t
)(1024 * cnvmem
));
497 hole_end
= round_page((vm_offset_t
)first_avail
);
504 if (mem_size
< (last_addr
) - bios_hole_size
)
505 last_addr
= mem_size
+ bios_hole_size
;
508 first_addr
= round_page(first_addr
);
509 last_addr
= trunc_page(last_addr
);
510 mem_size
= last_addr
- bios_hole_size
;
512 avail_start
= first_addr
;
513 avail_end
= last_addr
;
514 avail_next
= avail_start
;
517 * Initialize kernel physical map, mapping the
518 * region from loadpt to avail_start.
519 * Kernel virtual address starts at VM_KERNEL_MIN_ADDRESS.
523 #if NCPUS > 1 && AT386
525 * Must Allocate interrupt stacks before kdb is called and also
526 * before vm is initialized. Must find out number of cpus first.
529 * Get number of cpus to boot, passed as an optional argument
530 * boot: mach [-sah#] # from 0 to 9 is the number of cpus to boot
534 * "-1" check above is to allow for old boot loader to pass
535 * wncpu through boothowto. New boot loader uses environment.
538 if ((cpus
= getenv("cpus")) != NULL
) {
539 /* only a single digit for now */
540 if ((*cpus
> '0') && (*cpus
<= '9'))
546 interrupt_stack_alloc();
548 #endif /* NCPUS > 1 && AT386 */
552 avail_remaining
= atop((avail_end
- avail_start
) -
553 (hole_end
- hole_start
));
557 pmap_free_pages(void)
559 return avail_remaining
;
566 if (avail_next
== avail_end
)
571 if (avail_next
== hole_start
)
572 avail_next
= hole_end
;
575 avail_next
+= PAGE_SIZE
;
585 return ((avail_start
<= x
) && (x
< avail_end
));
589 void fc_get(mach_timespec_t
*ts
);
590 #include <kern/clock.h>
591 #include <i386/rtclock_entries.h>
592 extern kern_return_t
sysclk_gettime(
593 mach_timespec_t
*cur_time
);
594 void fc_get(mach_timespec_t
*ts
) {
595 (void )sysclk_gettime(ts
);
602 printf("Debugger called: <%s>\n", message
);
608 display_syscall(int syscall
)
610 printf("System call happened %d\n", syscall
);
613 #if XPR_DEBUG && (NCPUS == 1 || MP_V1_1)
615 extern kern_return_t
sysclk_gettime_interrupts_disabled(
616 mach_timespec_t
*cur_time
);
620 mach_timespec_t time
;
622 sysclk_gettime_interrupts_disabled(&time
);
623 return(time
.tv_sec
*1000000 + time
.tv_nsec
/1000);
625 #endif /* XPR_DEBUG && (NCPUS == 1 || MP_V1_1) */
635 machine_boot_info(char *buf
, vm_size_t size
)