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 vm_size_t mem_size
= 0;
117 vm_offset_t first_addr
= 0; /* set by start.s - keep out of bss */
118 vm_offset_t first_avail
= 0;/* first after page tables */
119 vm_offset_t last_addr
;
121 vm_offset_t avail_start
, avail_end
;
122 vm_offset_t virtual_avail
, virtual_end
;
123 vm_offset_t hole_start
, hole_end
;
124 vm_offset_t avail_next
;
125 unsigned int avail_remaining
;
127 /* parameters passed from bootstrap loader */
128 int cnvmem
= 0; /* must be in .data section */
131 /* FIXME!! REMOVE WHEN OSFMK DEVICES ARE COMPLETELY PULLED OUT */
132 int dev_name_count
= 0;
133 int dev_name_list
= 0;
136 extern char edata
, end
;
139 extern char version
[];
141 int rebootflag
= 0; /* exported to kdintr */
144 void parse_arguments(void);
145 const char *getenv(const char *);
147 #define BOOT_LINE_LENGTH 160
148 char boot_string_store
[BOOT_LINE_LENGTH
] = {0};
149 char *boot_string
= (char *)0;
150 int boot_string_sz
= BOOT_LINE_LENGTH
;
154 #include <mach-o/loader.h>
155 vm_offset_t edata
, etext
, end
;
157 extern struct mach_header _mh_execute_header
;
158 void *sectTEXTB
; int sectSizeTEXT
;
159 void *sectDATAB
; int sectSizeDATA
;
160 void *sectOBJCB
; int sectSizeOBJC
;
161 void *sectLINKB
; int sectSizeLINK
;
163 /* Kernel boot information */
164 KERNBOOTSTRUCT kernBootStructData
;
165 KERNBOOTSTRUCT
*kernBootStruct
;
168 vm_offset_t kern_args_start
= 0; /* kernel arguments */
169 vm_size_t kern_args_size
= 0; /* size of kernel arguments */
177 struct segment_command
*sgp
;
180 sgp
= (struct segment_command
*) getsegbyname("__DATA");
182 sp
= (struct section
*) firstsect(sgp
);
185 if (sp
->flags
& S_ZEROFILL
)
186 bzero((char *) sp
->addr
, sp
->size
);
187 } while (sp
= (struct section
*)nextsect(sgp
, sp
));
191 bcopy((char *) KERNSTRUCT_ADDR
, (char *) &kernBootStructData
,
192 sizeof(kernBootStructData
));
194 kernBootStruct
= &kernBootStructData
;
196 end
= round_page( kernBootStruct
->kaddr
+ kernBootStruct
->ksize
);
203 * Cpu initialization. Running virtual, but without MACH VM
204 * set up. First C routine called.
207 machine_startup(void)
213 /* Now copy over various bits.. */
214 cnvmem
= kernBootStruct
->convmem
;
215 extmem
= kernBootStruct
->extmem
;
216 kern_args_start
= (vm_offset_t
) kernBootStruct
->bootString
;
217 kern_args_size
= strlen(kernBootStruct
->bootString
);
218 boottype
= kernBootStruct
->rootdev
;
220 /* Now retrieve addresses for end, edata, and etext
221 * from MACH-O headers.
224 sectTEXTB
= (void *) getsegdatafromheader(
225 &_mh_execute_header
, "__TEXT", §SizeTEXT
);
226 sectDATAB
= (void *) getsegdatafromheader(
227 &_mh_execute_header
, "__DATA", §SizeDATA
);
228 sectOBJCB
= (void *) getsegdatafromheader(
229 &_mh_execute_header
, "__OBJC", §SizeOBJC
);
230 sectLINKB
= (void *) getsegdatafromheader(
231 &_mh_execute_header
, "__LINKEDIT", §SizeLINK
);
233 etext
= (vm_offset_t
) sectTEXTB
+ sectSizeTEXT
;
234 edata
= (vm_offset_t
) sectDATAB
+ sectSizeDATA
;
238 * Parse startup arguments
242 disableDebugOuput
= FALSE
;
245 printf_init(); /* Init this in case we need debugger */
246 panic_init(); /* Init this in case we need debugger */
248 PE_init_platform(FALSE
, kernBootStruct
);
249 PE_init_kprintf(FALSE
);
250 PE_init_printf(FALSE
);
253 * Do basic VM initialization
257 PE_init_platform(TRUE
, kernBootStruct
);
258 PE_init_kprintf(TRUE
);
259 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
273 * XXX use -a switch to invoke kdb, since there's no
274 * boot-program switch to turn on RB_HALT!
277 if (halt_in_debugger
) {
278 printf("inline call to debugger(machine_startup)\n");
279 Debugger("inline call");
281 #endif /* MACH_KDB */
286 machine_slot
[0].is_cpu
= TRUE
;
287 machine_slot
[0].running
= TRUE
;
290 machine_slot
[0].cpu_type
= CPU_TYPE_I386
;
291 machine_slot
[0].cpu_subtype
= CPU_SUBTYPE_PENTPRO
;
293 machine_slot
[0].cpu_type
= cpuid_cputype(0);
294 machine_slot
[0].cpu_subtype
= CPU_SUBTYPE_AT386
;
308 vm_offset_t env_start
= 0; /* environment */
309 vm_size_t env_size
= 0; /* size of environment */
312 * Parse command line arguments.
315 parse_arguments(void)
317 char *p
= (char *) kern_args_start
;
318 char *endp
= (char *) kern_args_start
+ kern_args_size
- 1;
321 if (kern_args_start
== 0)
325 * handle switches in exact format of -h or -m64
327 while ( (p
< endp
) && (*p
!= '\0')) {
332 halt_in_debugger
= 1;
335 mem_size
= atoi_term(p
,&p
)*1024*1024;
338 mem_size
= atoi_term(p
,&p
)*1024;
348 getenv(const char *name
)
350 int len
= strlen(name
);
351 const char *p
= (const char *)env_start
;
352 const char *endp
= p
+ env_size
;
357 if (strncmp(name
, p
, len
) == 0 && *(p
+ len
) == '=')
366 calibrate_delay(void);
369 * Find devices. The system is alive.
379 * Adjust delay count before entering drivers
385 * Display CPU identification
387 cpuid_cpu_display("CPU identification", 0);
388 cpuid_cache_display("CPU configuration", 0);
395 * Set up to use floating point.
402 #endif /* NPCI > 0 */
406 * Configure clock devices.
417 halt_all_cpus(FALSE
);
420 int reset_mem_on_reboot
= 1;
423 * Halt the system or reboot.
431 * Tell the BIOS not to clear and test memory.
433 if (! reset_mem_on_reboot
)
434 *(unsigned short *)phystokv(0x472) = 0x1234;
440 printf("In tight loop: hit ctl-alt-del to reboot\n");
448 * Basic VM initialization.
454 int i
,j
; /* Standard index vars. */
455 vm_size_t bios_hole_size
;
462 bzero((char *)&edata
,(unsigned)(&end
- &edata
));
465 boot_string
= &boot_string_store
[0];
468 * Initialize the pic prior to any possible call to an spl.
475 * Initialize the Event Trace Analysis Package
476 * Static Phase: 1 of 2
481 * Compute the memory size.
486 * fdisk needs to change to use a sysctl instead of
487 * opening /dev/kmem and reading out the kernboot structure
490 first_addr
= (char *)(KERNSTRUCT_ADDR
) + sizeof(KERNBOOTSTRUCT
);
495 /* First two pages are used to boot the other cpus. */
496 /* TODO - reclaim pages after all cpus have booted */
502 /* BIOS leaves data in low memory */
503 last_addr
= 1024*1024 + extmem
*1024;
504 /* extended memory starts at 1MB */
506 bios_hole_size
= 1024*1024 - trunc_page((vm_offset_t
)(1024 * cnvmem
));
509 * Initialize for pmap_free_pages and pmap_next_page.
510 * These guys should be page-aligned.
513 hole_start
= trunc_page((vm_offset_t
)(1024 * cnvmem
));
514 hole_end
= round_page((vm_offset_t
)first_avail
);
521 if (mem_size
< (last_addr
) - bios_hole_size
)
522 last_addr
= mem_size
+ bios_hole_size
;
525 first_addr
= round_page(first_addr
);
526 last_addr
= trunc_page(last_addr
);
527 mem_size
= last_addr
- bios_hole_size
;
529 avail_start
= first_addr
;
530 avail_end
= last_addr
;
531 avail_next
= avail_start
;
534 * Initialize kernel physical map, mapping the
535 * region from loadpt to avail_start.
536 * Kernel virtual address starts at VM_KERNEL_MIN_ADDRESS.
540 #if NCPUS > 1 && AT386
542 * Must Allocate interrupt stacks before kdb is called and also
543 * before vm is initialized. Must find out number of cpus first.
546 * Get number of cpus to boot, passed as an optional argument
547 * boot: mach [-sah#] # from 0 to 9 is the number of cpus to boot
551 * "-1" check above is to allow for old boot loader to pass
552 * wncpu through boothowto. New boot loader uses environment.
555 if ((cpus
= getenv("cpus")) != NULL
) {
556 /* only a single digit for now */
557 if ((*cpus
> '0') && (*cpus
<= '9'))
563 interrupt_stack_alloc();
565 #endif /* NCPUS > 1 && AT386 */
569 avail_remaining
= atop((avail_end
- avail_start
) -
570 (hole_end
- hole_start
));
574 pmap_free_pages(void)
576 return avail_remaining
;
583 if (avail_next
== avail_end
)
588 if (avail_next
== hole_start
)
589 avail_next
= hole_end
;
592 avail_next
+= PAGE_SIZE
;
602 return ((avail_start
<= x
) && (x
< avail_end
));
606 void fc_get(mach_timespec_t
*ts
);
607 #include <kern/clock.h>
608 #include <i386/rtclock_entries.h>
609 extern kern_return_t
sysclk_gettime(
610 mach_timespec_t
*cur_time
);
611 void fc_get(mach_timespec_t
*ts
) {
612 (void )sysclk_gettime(ts
);
619 printf("Debugger called: <%s>\n", message
);
625 display_syscall(int syscall
)
627 printf("System call happened %d\n", syscall
);
630 #if XPR_DEBUG && (NCPUS == 1 || MP_V1_1)
632 extern kern_return_t
sysclk_gettime_interrupts_disabled(
633 mach_timespec_t
*cur_time
);
637 mach_timespec_t time
;
639 sysclk_gettime_interrupts_disabled(&time
);
640 return(time
.tv_sec
*1000000 + time
.tv_nsec
/1000);
642 #endif /* XPR_DEBUG && (NCPUS == 1 || MP_V1_1) */
652 machine_boot_info(char *buf
, vm_size_t size
)