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
));
192 bcopy((char *) KERNSTRUCT_ADDR
, (char *) &kernBootStructData
,
193 sizeof(kernBootStructData
));
195 kernBootStruct
= &kernBootStructData
;
199 for (i
= 0; i
< kernBootStruct
->numBootDrivers
; i
++)
200 end
+= kernBootStruct
->driverConfig
[i
].size
;
202 end
= round_page(end
);
209 * Cpu initialization. Running virtual, but without MACH VM
210 * set up. First C routine called.
213 machine_startup(void)
219 /* Now copy over various bits.. */
220 cnvmem
= kernBootStruct
->convmem
;
221 extmem
= kernBootStruct
->extmem
;
222 kern_args_start
= (vm_offset_t
) kernBootStruct
->bootString
;
223 kern_args_size
= strlen(kernBootStruct
->bootString
);
224 boottype
= kernBootStruct
->rootdev
;
226 /* Now retrieve addresses for end, edata, and etext
227 * from MACH-O headers.
230 sectTEXTB
= (void *) getsegdatafromheader(
231 &_mh_execute_header
, "__TEXT", §SizeTEXT
);
232 sectDATAB
= (void *) getsegdatafromheader(
233 &_mh_execute_header
, "__DATA", §SizeDATA
);
234 sectOBJCB
= (void *) getsegdatafromheader(
235 &_mh_execute_header
, "__OBJC", §SizeOBJC
);
236 sectLINKB
= (void *) getsegdatafromheader(
237 &_mh_execute_header
, "__LINKEDIT", §SizeLINK
);
239 etext
= (vm_offset_t
) sectTEXTB
+ sectSizeTEXT
;
240 edata
= (vm_offset_t
) sectDATAB
+ sectSizeDATA
;
244 * Parse startup arguments
248 disableDebugOuput
= FALSE
;
251 printf_init(); /* Init this in case we need debugger */
252 panic_init(); /* Init this in case we need debugger */
254 PE_init_platform(FALSE
, kernBootStruct
);
255 PE_init_kprintf(FALSE
);
256 PE_init_printf(FALSE
);
259 * Do basic VM initialization
263 PE_init_platform(TRUE
, kernBootStruct
);
264 PE_init_kprintf(TRUE
);
265 PE_init_printf(TRUE
);
270 * Initialize the kernel debugger.
275 * Cause a breakpoint trap to the debugger before proceeding
276 * any further if the proper option bit was specified in
279 * XXX use -a switch to invoke kdb, since there's no
280 * boot-program switch to turn on RB_HALT!
283 if (halt_in_debugger
) {
284 printf("inline call to debugger(machine_startup)\n");
285 Debugger("inline call");
287 #endif /* MACH_KDB */
292 machine_slot
[0].is_cpu
= TRUE
;
293 machine_slot
[0].running
= TRUE
;
296 machine_slot
[0].cpu_type
= CPU_TYPE_I386
;
297 machine_slot
[0].cpu_subtype
= CPU_SUBTYPE_PENTPRO
;
299 machine_slot
[0].cpu_type
= cpuid_cputype(0);
300 machine_slot
[0].cpu_subtype
= CPU_SUBTYPE_AT386
;
314 vm_offset_t env_start
= 0; /* environment */
315 vm_size_t env_size
= 0; /* size of environment */
318 * Parse command line arguments.
321 parse_arguments(void)
323 char *p
= (char *) kern_args_start
;
324 char *endp
= (char *) kern_args_start
+ kern_args_size
- 1;
327 if (kern_args_start
== 0)
338 halt_in_debugger
= 1;
340 case 'm': /* -m??: memory size Mbytes*/
341 mem_size
= atoi_term(p
, &p
)*1024*1024;
343 case 'k': /* -k??: memory size Kbytes */
344 mem_size
= atoi_term(p
, &p
)*1024;
347 #if NCPUS > 1 && AT386
348 if (ch
> '0' && ch
<= '9')
350 #endif /* NCPUS > 1 && AT386 */
358 getenv(const char *name
)
360 int len
= strlen(name
);
361 const char *p
= (const char *)env_start
;
362 const char *endp
= p
+ env_size
;
367 if (strncmp(name
, p
, len
) == 0 && *(p
+ len
) == '=')
376 calibrate_delay(void);
379 * Find devices. The system is alive.
389 * Adjust delay count before entering drivers
395 * Display CPU identification
397 cpuid_cpu_display("CPU identification", 0);
398 cpuid_cache_display("CPU configuration", 0);
405 * Set up to use floating point.
412 #endif /* NPCI > 0 */
416 * Configure clock devices.
427 halt_all_cpus(FALSE
);
430 int reset_mem_on_reboot
= 1;
433 * Halt the system or reboot.
441 * Tell the BIOS not to clear and test memory.
443 if (! reset_mem_on_reboot
)
444 *(unsigned short *)phystokv(0x472) = 0x1234;
450 printf("In tight loop: hit ctl-alt-del to reboot\n");
458 * Basic VM initialization.
464 int i
,j
; /* Standard index vars. */
465 vm_size_t bios_hole_size
;
472 bzero((char *)&edata
,(unsigned)(&end
- &edata
));
475 boot_string
= &boot_string_store
[0];
478 * Initialize the pic prior to any possible call to an spl.
485 * Initialize the Event Trace Analysis Package
486 * Static Phase: 1 of 2
491 * Compute the memory size.
496 * fdisk needs to change to use a sysctl instead of
497 * opening /dev/kmem and reading out the kernboot structure
500 first_addr
= (char *)(KERNSTRUCT_ADDR
) + sizeof(KERNBOOTSTRUCT
);
505 /* First two pages are used to boot the other cpus. */
506 /* TODO - reclaim pages after all cpus have booted */
512 /* BIOS leaves data in low memory */
513 last_addr
= 1024*1024 + extmem
*1024;
514 /* extended memory starts at 1MB */
516 bios_hole_size
= 1024*1024 - trunc_page((vm_offset_t
)(1024 * cnvmem
));
519 * Initialize for pmap_free_pages and pmap_next_page.
520 * These guys should be page-aligned.
523 hole_start
= trunc_page((vm_offset_t
)(1024 * cnvmem
));
524 hole_end
= round_page((vm_offset_t
)first_avail
);
531 if (mem_size
< (last_addr
) - bios_hole_size
)
532 last_addr
= mem_size
+ bios_hole_size
;
535 first_addr
= round_page(first_addr
);
536 last_addr
= trunc_page(last_addr
);
537 mem_size
= last_addr
- bios_hole_size
;
539 avail_start
= first_addr
;
540 avail_end
= last_addr
;
541 avail_next
= avail_start
;
544 * Initialize kernel physical map, mapping the
545 * region from loadpt to avail_start.
546 * Kernel virtual address starts at VM_KERNEL_MIN_ADDRESS.
550 #if NCPUS > 1 && AT386
552 * Must Allocate interrupt stacks before kdb is called and also
553 * before vm is initialized. Must find out number of cpus first.
556 * Get number of cpus to boot, passed as an optional argument
557 * boot: mach [-sah#] # from 0 to 9 is the number of cpus to boot
561 * "-1" check above is to allow for old boot loader to pass
562 * wncpu through boothowto. New boot loader uses environment.
565 if ((cpus
= getenv("cpus")) != NULL
) {
566 /* only a single digit for now */
567 if ((*cpus
> '0') && (*cpus
<= '9'))
573 interrupt_stack_alloc();
575 #endif /* NCPUS > 1 && AT386 */
579 avail_remaining
= atop((avail_end
- avail_start
) -
580 (hole_end
- hole_start
));
584 pmap_free_pages(void)
586 return avail_remaining
;
593 if (avail_next
== avail_end
)
598 if (avail_next
== hole_start
)
599 avail_next
= hole_end
;
602 avail_next
+= PAGE_SIZE
;
612 return ((avail_start
<= x
) && (x
< avail_end
));
616 void fc_get(mach_timespec_t
*ts
);
617 #include <kern/clock.h>
618 #include <i386/rtclock_entries.h>
619 extern kern_return_t
sysclk_gettime(
620 mach_timespec_t
*cur_time
);
621 void fc_get(mach_timespec_t
*ts
) {
622 (void )sysclk_gettime(ts
);
629 printf("Debugger called: <%s>\n", message
);
635 display_syscall(int syscall
)
637 printf("System call happened %d\n", syscall
);
640 #if XPR_DEBUG && (NCPUS == 1 || MP_V1_1)
642 extern kern_return_t
sysclk_gettime_interrupts_disabled(
643 mach_timespec_t
*cur_time
);
647 mach_timespec_t time
;
649 sysclk_gettime_interrupts_disabled(&time
);
650 return(time
.tv_sec
*1000000 + time
.tv_nsec
/1000);
652 #endif /* XPR_DEBUG && (NCPUS == 1 || MP_V1_1) */
662 machine_boot_info(char *buf
, vm_size_t size
)