#include <debug.h>
#include <mach_kdb.h>
#include <mach_kdp.h>
#include <kern/misc_protos.h>
#include <kern/thread.h>
#include <kern/processor.h>
#include <machine/machine_routines.h>
#include <ppc/boot.h>
#include <ppc/proc_reg.h>
#include <ppc/misc_protos.h>
#include <ppc/pmap.h>
#include <ppc/new_screen.h>
#include <ppc/exception.h>
#include <ppc/Firmware.h>
#include <ppc/savearea.h>
#include <ppc/low_trace.h>
#include <ppc/Diagnostics.h>
#include <pexpert/pexpert.h>
extern const char version[];
extern const char version_variant[];
extern unsigned int intstack_top_ss;
extern unsigned int debstackptr;
extern unsigned int debstack_top_ss;
extern void thandler(void);
extern void ihandler(void);
extern void shandler(void);
extern void chandler(void);
extern void fpu_switch(void);
extern void vec_switch(void);
extern void atomic_switch_trap(void);
void (*exception_handlers[])(void) = {
thandler,
thandler,
thandler,
thandler,
thandler,
ihandler,
thandler,
thandler,
fpu_switch,
ihandler,
thandler,
thandler,
shandler,
thandler,
thandler,
thandler,
vec_switch,
thandler,
thandler,
thandler,
thandler,
ihandler,
thandler,
ihandler,
thandler,
thandler,
thandler,
thandler,
thandler,
thandler,
thandler,
thandler,
thandler,
thandler,
ihandler,
thandler,
ihandler,
ihandler,
chandler
};
int pc_trace_buf[1024] = {0};
int pc_trace_cnt = 1024;
void ppc_init(boot_args *args)
{
int i;
unsigned long *src,*dst;
char *str;
unsigned long addr, videoAddr;
unsigned int maxmem;
bat_t bat;
extern vm_offset_t static_memory_end;
per_proc_info[0].cpu_number = 0;
per_proc_info[0].cpu_flags = 0;
per_proc_info[0].istackptr = 0;
per_proc_info[0].intstack_top_ss = intstack_top_ss;
per_proc_info[0].debstackptr = debstackptr;
per_proc_info[0].debstack_top_ss = debstack_top_ss;
per_proc_info[0].interrupts_enabled = 0;
per_proc_info[0].active_kloaded = (unsigned int)
&active_kloaded[0];
per_proc_info[0].cpu_data = (unsigned int)
&cpu_data[0];
per_proc_info[0].active_stacks = (unsigned int)
&active_stacks[0];
per_proc_info[0].need_ast = (unsigned int)
&need_ast[0];
per_proc_info[0].FPU_thread = 0;
per_proc_info[0].FPU_vmmCtx = 0;
per_proc_info[0].VMX_thread = 0;
per_proc_info[0].VMX_vmmCtx = 0;
machine_slot[0].is_cpu = TRUE;
cpu_init();
processor_ptr[0] = &processor_array[0];
master_cpu = 0;
master_processor = cpu_to_processor(master_cpu);
for (i=0; i<=15; i++) {
isync();
mtsrin((KERNEL_SEG_REG0_VALUE | (i << 20)), i * 0x10000000);
sync();
}
static_memory_end = round_page(args->topOfKernelData);;
PE_init_platform(FALSE, args);
videoAddr = args->Video.v_baseAddr & 0xF0000000;
if (videoAddr) {
bat.upper.word = videoAddr;
bat.lower.word = videoAddr;
bat.upper.bits.bl = 0x7ff;
bat.upper.bits.vs = 1;
bat.upper.bits.vp = 0;
bat.lower.bits.wimg = PTE_WIMG_IO;
bat.lower.bits.pp = 2;
sync();isync();
mtdbatu(3, BAT_INVALID);
mtdbatl(3, bat.lower.word);
mtdbatu(3, bat.upper.word);
sync();isync();
}
addr = get_io_base_addr() & 0xF0000000;
if (addr != videoAddr) {
bat.upper.word = addr;
bat.lower.word = addr;
bat.upper.bits.bl = 0x7ff;
bat.upper.bits.vs = 1;
bat.upper.bits.vp = 0;
bat.lower.bits.wimg = PTE_WIMG_IO;
bat.lower.bits.pp = 2;
sync();isync();
mtdbatu(2, BAT_INVALID);
mtdbatl(2, bat.lower.word);
mtdbatu(2, bat.upper.word);
sync();isync();
}
if (!PE_parse_boot_arg("diag", &dgWork.dgFlags)) dgWork.dgFlags=0;
if(dgWork.dgFlags & enaExpTrace) trcWork.traceMask = 0xFFFFFFFF;
#if 0
GratefulDebInit((bootBumbleC *)&(args->Video));
#endif
printf_init();
panic_init();
PE_init_kprintf(FALSE);
kprintf("kprintf initialized\n");
PE_create_console();
PE_init_printf(FALSE);
kprintf("version_variant = %s\n", version_variant);
kprintf("version = %s\n", version);
#if DEBUG
printf("\n\n\nThis program was compiled using gcc %d.%d for powerpc\n",
__GNUC__,__GNUC_MINOR__);
{
unsigned int pvr;
__asm__ ("mfpvr %0" : "=r" (pvr));
printf("processor version register : 0x%08x\n",pvr);
}
for (i = 0; i < kMaxDRAMBanks; i++) {
if (args->PhysicalDRAM[i].size)
printf("DRAM at 0x%08x size 0x%08x\n",
args->PhysicalDRAM[i].base,
args->PhysicalDRAM[i].size);
}
#endif
if (!PE_parse_boot_arg("maxmem", &maxmem))
maxmem=0;
else
maxmem = maxmem * (1024 * 1024);
ppc_vm_init(maxmem, args);
PE_init_platform(TRUE, args);
machine_startup(args);
}
ppc_init_cpu(
struct per_proc_info *proc_info)
{
int i;
unsigned int gph;
savectl *sctl;
if(proc_info->savedSave) {
mtsprg(1, proc_info->savedSave);
}
else {
gph = (unsigned int)save_get_phys();
mtsprg(1, gph);
}
cpu_init();
proc_info->Lastpmap = 0;
for (i=0; i<=15; i++) {
isync();
mtsrin((KERNEL_SEG_REG0_VALUE | (i << 20)), i * 0x10000000);
sync();
}
ppc_vm_cpu_init(proc_info);
ml_thrm_init();
slave_main();
}