2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989, 1988 Carnegie Mellon University
31 * All Rights Reserved.
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
43 * Carnegie Mellon requests users of this software to return to
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
59 * Author: Avadis Tevanian, Jr., Michael Wayne Young
61 * Copyright (C) 1986, Avadis Tevanian, Jr., Michael Wayne Young
63 * Basic initialization for I386 - ISA bus machines.
67 #include <platforms.h>
71 #include <fast_idle.h>
73 #include <mach/i386/vm_param.h>
76 #include <mach/vm_param.h>
77 #include <mach/vm_prot.h>
78 #include <mach/machine.h>
79 #include <mach/time_value.h>
80 #include <kern/etap_macros.h>
82 #include <kern/assert.h>
83 #include <kern/debug.h>
84 #include <kern/misc_protos.h>
85 #include <kern/startup.h>
86 #include <kern/clock.h>
87 #include <kern/time_out.h>
89 #include <kern/cpu_data.h>
90 #include <vm/vm_page.h>
92 #include <vm/vm_kern.h>
94 #include <i386/pmap.h>
97 #include <i386/misc_protos.h>
98 #include <i386/cpuid.h>
99 #include <i386/rtclock_entries.h>
100 #include <i386/AT386/mp/mp.h>
102 #include <ddb/db_aout.h>
103 #endif /* MACH_KDB */
106 #include <i386/AT386/kernBootStruct.h>
107 #include <mach/boot_info.h>
108 #include <mach/thread_status.h>
112 #include <i386/mp_desc.h>
116 #include <i386/AT386/mp/mp_v1_1.h>
119 #include <IOKit/IOPlatformExpert.h>
121 vm_size_t mem_size
= 0;
123 vm_offset_t first_addr
= 0; /* set by start.s - keep out of bss */
124 vm_offset_t first_avail
= 0;/* first after page tables */
125 vm_offset_t last_addr
;
127 vm_offset_t avail_start
, avail_end
;
128 vm_offset_t virtual_avail
, virtual_end
;
129 vm_offset_t hole_start
, hole_end
;
130 vm_offset_t avail_next
;
131 unsigned int avail_remaining
;
133 /* parameters passed from bootstrap loader */
134 int cnvmem
= 0; /* must be in .data section */
137 /* FIXME!! REMOVE WHEN OSFMK DEVICES ARE COMPLETELY PULLED OUT */
138 int dev_name_count
= 0;
139 int dev_name_list
= 0;
142 extern char edata
, end
;
145 extern char version
[];
147 void parse_arguments(void);
148 const char *getenv(const char *);
150 #define BOOT_LINE_LENGTH 160
151 char boot_string_store
[BOOT_LINE_LENGTH
] = {0};
152 char *boot_string
= (char *)0;
153 int boot_string_sz
= BOOT_LINE_LENGTH
;
157 #include <mach-o/loader.h>
158 vm_offset_t edata
, etext
, end
;
160 extern struct mach_header _mh_execute_header
;
161 void *sectTEXTB
; int sectSizeTEXT
;
162 void *sectDATAB
; int sectSizeDATA
;
163 void *sectOBJCB
; int sectSizeOBJC
;
164 void *sectLINKB
; int sectSizeLINK
;
166 /* Kernel boot information */
167 KERNBOOTSTRUCT kernBootStructData
;
168 KERNBOOTSTRUCT
*kernBootStruct
;
171 vm_offset_t kern_args_start
= 0; /* kernel arguments */
172 vm_size_t kern_args_size
= 0; /* size of kernel arguments */
180 struct segment_command
*sgp
;
183 sgp
= (struct segment_command
*) getsegbyname("__DATA");
185 sp
= (struct section
*) firstsect(sgp
);
188 if (sp
->flags
& S_ZEROFILL
)
189 bzero((char *) sp
->addr
, sp
->size
);
190 } while (sp
= (struct section
*)nextsect(sgp
, sp
));
194 bcopy((char *) KERNSTRUCT_ADDR
, (char *) &kernBootStructData
,
195 sizeof(kernBootStructData
));
197 kernBootStruct
= &kernBootStructData
;
199 end
= round_page( kernBootStruct
->kaddr
+ kernBootStruct
->ksize
);
206 * Cpu initialization. Running virtual, but without MACH VM
207 * set up. First C routine called.
210 machine_startup(void)
214 /* Now copy over various bits.. */
215 cnvmem
= kernBootStruct
->convmem
;
216 extmem
= kernBootStruct
->extmem
;
217 kern_args_start
= (vm_offset_t
) kernBootStruct
->bootString
;
218 kern_args_size
= strlen(kernBootStruct
->bootString
);
219 boottype
= kernBootStruct
->rootdev
;
221 /* Now retrieve addresses for end, edata, and etext
222 * from MACH-O headers.
225 sectTEXTB
= (void *) getsegdatafromheader(
226 &_mh_execute_header
, "__TEXT", §SizeTEXT
);
227 sectDATAB
= (void *) getsegdatafromheader(
228 &_mh_execute_header
, "__DATA", §SizeDATA
);
229 sectOBJCB
= (void *) getsegdatafromheader(
230 &_mh_execute_header
, "__OBJC", §SizeOBJC
);
231 sectLINKB
= (void *) getsegdatafromheader(
232 &_mh_execute_header
, "__LINKEDIT", §SizeLINK
);
234 etext
= (vm_offset_t
) sectTEXTB
+ sectSizeTEXT
;
235 edata
= (vm_offset_t
) sectDATAB
+ sectSizeDATA
;
238 printf_init(); /* Init this in case we need debugger */
239 panic_init(); /* Init this in case we need debugger */
241 PE_init_platform(FALSE
, kernBootStruct
);
242 PE_init_kprintf(FALSE
);
243 PE_init_printf(FALSE
);
246 * Parse startup arguments
251 * Set up initial thread so current_thread() works early on
253 pageout_thread
.top_act
= &pageout_act
;
254 pageout_act
.thread
= &pageout_thread
;
255 thread_machine_set_current(&pageout_thread
);
258 * Do basic VM initialization
262 PE_init_platform(TRUE
, kernBootStruct
);
263 PE_init_kprintf(TRUE
);
264 PE_init_printf(TRUE
);
268 * Initialize the kernel debugger.
273 * Cause a breakpoint trap to the debugger before proceeding
274 * any further if the proper option bit was specified in
278 if (halt_in_debugger
) {
279 printf("inline call to debugger(machine_startup)\n");
280 Debugger("inline call");
282 #endif /* MACH_KDB */
288 machine_slot
[0].is_cpu
= TRUE
;
289 machine_slot
[0].running
= TRUE
;
292 machine_slot
[0].cpu_type
= CPU_TYPE_I386
;
293 machine_slot
[0].cpu_subtype
= CPU_SUBTYPE_PENTPRO
;
295 machine_slot
[0].cpu_type
= cpuid_cputype(0);
296 machine_slot
[0].cpu_subtype
= CPU_SUBTYPE_AT386
;
310 vm_offset_t env_start
= 0; /* environment */
311 vm_size_t env_size
= 0; /* size of environment */
314 * Parse command line arguments.
317 parse_arguments(void)
319 unsigned int boot_arg
;
321 if (PE_parse_boot_arg("maxmem", &boot_arg
))
323 mem_size
= boot_arg
* (1024 * 1024);
326 if (PE_parse_boot_arg("debug", &boot_arg
))
328 if (boot_arg
& DB_HALT
) halt_in_debugger
= 1;
329 if (boot_arg
& DB_PRT
) disableDebugOuput
= FALSE
;
334 getenv(const char *name
)
336 int len
= strlen(name
);
337 const char *p
= (const char *)env_start
;
338 const char *endp
= p
+ env_size
;
343 if (strncmp(name
, p
, len
) == 0 && *(p
+ len
) == '=')
352 calibrate_delay(void);
355 * Find devices. The system is alive.
365 * Adjust delay count before entering drivers
371 * Display CPU identification
373 cpuid_cpu_display("CPU identification", 0);
374 cpuid_cache_display("CPU configuration", 0);
381 * Set up to use floating point.
388 #endif /* NPCI > 0 */
392 * Configure clock devices.
403 halt_all_cpus(FALSE
);
406 int reset_mem_on_reboot
= 1;
409 * Halt the system or reboot.
412 halt_all_cpus(boolean_t reboot
)
417 * Tell the BIOS not to clear and test memory.
419 if (!reset_mem_on_reboot
)
420 *(unsigned short *)phystokv(0x472) = 0x1234;
422 printf("MACH Reboot\n");
423 PEHaltRestart( kPERestartCPU
);
427 printf("CPU halted\n");
428 PEHaltRestart( kPEHaltCPU
);
434 * Basic VM initialization.
440 int i
,j
; /* Standard index vars. */
441 vm_size_t bios_hole_size
;
448 bzero((char *)&edata
,(unsigned)(&end
- &edata
));
451 boot_string
= &boot_string_store
[0];
454 * Initialize the pic prior to any possible call to an spl.
461 * Initialize the Event Trace Analysis Package
462 * Static Phase: 1 of 2
467 * Compute the memory size.
472 * fdisk needs to change to use a sysctl instead of
473 * opening /dev/kmem and reading out the kernboot structure
476 first_addr
= (char *)(KERNSTRUCT_ADDR
) + sizeof(KERNBOOTSTRUCT
);
481 /* First two pages are used to boot the other cpus. */
482 /* TODO - reclaim pages after all cpus have booted */
488 /* BIOS leaves data in low memory */
489 last_addr
= 1024*1024 + extmem
*1024;
491 /* extended memory starts at 1MB */
493 bios_hole_size
= 1024*1024 - trunc_page((vm_offset_t
)(1024 * cnvmem
));
496 * Initialize for pmap_free_pages and pmap_next_page.
497 * These guys should be page-aligned.
500 hole_start
= trunc_page((vm_offset_t
)(1024 * cnvmem
));
501 hole_end
= round_page((vm_offset_t
)first_avail
);
508 if (mem_size
< (last_addr
) - bios_hole_size
)
509 last_addr
= mem_size
+ bios_hole_size
;
512 first_addr
= round_page(first_addr
);
513 last_addr
= trunc_page(last_addr
);
514 mem_size
= last_addr
- bios_hole_size
;
517 avail_start
= first_addr
;
518 avail_end
= last_addr
;
519 avail_next
= avail_start
;
522 * Initialize kernel physical map, mapping the
523 * region from loadpt to avail_start.
524 * Kernel virtual address starts at VM_KERNEL_MIN_ADDRESS.
528 #if NCPUS > 1 && AT386
530 * Must Allocate interrupt stacks before kdb is called and also
531 * before vm is initialized. Must find out number of cpus first.
534 * Get number of cpus to boot, passed as an optional argument
535 * boot: mach [-sah#] # from 0 to 9 is the number of cpus to boot
539 * "-1" check above is to allow for old boot loader to pass
540 * wncpu through boothowto. New boot loader uses environment.
543 if ((cpus
= getenv("cpus")) != NULL
) {
544 /* only a single digit for now */
545 if ((*cpus
> '0') && (*cpus
<= '9'))
551 interrupt_stack_alloc();
553 #endif /* NCPUS > 1 && AT386 */
557 avail_remaining
= atop((avail_end
- avail_start
) -
558 (hole_end
- hole_start
));
562 pmap_free_pages(void)
564 return avail_remaining
;
571 if (avail_next
== avail_end
)
576 if (avail_next
== hole_start
)
577 avail_next
= hole_end
;
580 avail_next
+= PAGE_SIZE
;
590 return ((avail_start
<= x
) && (x
< avail_end
));
594 void fc_get(mach_timespec_t
*ts
);
595 #include <kern/clock.h>
596 #include <i386/rtclock_entries.h>
597 extern kern_return_t
sysclk_gettime(
598 mach_timespec_t
*cur_time
);
599 void fc_get(mach_timespec_t
*ts
) {
600 (void )sysclk_gettime(ts
);
607 printf("Debugger called: <%s>\n", message
);
613 display_syscall(int syscall
)
615 printf("System call happened %d\n", syscall
);
618 #if XPR_DEBUG && (NCPUS == 1 || MP_V1_1)
620 extern kern_return_t
sysclk_gettime_interrupts_disabled(
621 mach_timespec_t
*cur_time
);
625 mach_timespec_t time
;
627 sysclk_gettime_interrupts_disabled(&time
);
628 return(time
.tv_sec
*1000000 + time
.tv_nsec
/1000);
630 #endif /* XPR_DEBUG && (NCPUS == 1 || MP_V1_1) */
640 machine_boot_info(char *buf
, vm_size_t size
)