void exc_handler(u32 type, u32 spsr, u32 *regs) { if (type > 8) type = 8; debug_printf("\nException %d (%s):\n", type, exceptions[type]); u32 pc, fsr; switch(type) { case 1: // UND case 2: // SWI case 3: // INSTR ABORT case 7: // FIQ pc = regs[15] - 4; break; case 4: // DATA ABORT pc = regs[15] - 8; break; default: pc = regs[15]; break; } debug_printf("Registers (%p):\n", regs); debug_printf(" R0-R3: %08x %08x %08x %08x\n", regs[0], regs[1], regs[2], regs[3]); debug_printf(" R4-R7: %08x %08x %08x %08x\n", regs[4], regs[5], regs[6], regs[7]); debug_printf(" R8-R11: %08x %08x %08x %08x\n", regs[8], regs[9], regs[10], regs[11]); debug_printf("R12-R15: %08x %08x %08x %08x\n", regs[12], regs[13], regs[14], pc); debug_printf("SPSR: %08x\n", spsr); debug_printf("CPSR: %08x\n", get_cpsr()); debug_printf("CR: %08x\n", get_cr()); debug_printf("TTBR: %08x\n", get_ttbr()); debug_printf("DACR: %08x\n", get_dacr()); switch (type) { case 3: // INSTR ABORT case 4: // DATA ABORT if(type == 3) fsr = get_ifsr(); else fsr = get_dfsr(); debug_printf("Abort type: %s\n", aborts[fsr&0xf]); if(domvalid[fsr&0xf]) debug_printf("Domain: %d\n", (fsr>>4)&0xf); if(type == 4) debug_printf("Address: 0x%08x\n", get_far()); break; default: break; } if(type != 3) { debug_printf("Code dump:\n"); debug_printf("%08x: %08x %08x %08x %08x\n", pc-16, read32(pc-16), read32(pc-12), read32(pc-8), read32(pc-4)); debug_printf("%08x: *%08x %08x %08x %08x\n", pc, read32(pc), read32(pc+4), read32(pc+8), read32(pc+12)); debug_printf("%08x: %08x %08x %08x %08x\n", pc+16, read32(pc+16), read32(pc+20), read32(pc+24), read32(pc+28)); } panic2(0, PANIC_EXCEPTION); }
static void _panic(struct request *r, char *msg) { char buf[MSG_SIZE]; if (r) panic(log_strcpy3(buf, sizeof buf, r->verb,r->algorithm,msg)); else panic2("sha", msg); }
int module_boot() { int i; static char nm[] = "module_boot"; char buf[MSG_SIZE]; module_count = sizeof modules / sizeof *modules; snprintf(buf, sizeof buf, "%d compiled signature modules",module_count); info2(nm, buf); if (module_count == 0) panic2(nm, "no compiled signature modules"); /* * Double check that modules are stored lexical order by name. */ for (i = 1; i < module_count; i++) { if (strcmp(modules[i - 1]->name, modules[i]->name) >= 0) panic3("module_init: modules out of order", modules[i - 1]->name, modules[i]->name); } for (i = 0; i < module_count; i++) { struct digest_module *mp = modules[i]; info2("booting signature digest module", mp->name); if (mp->boot) { int status; status = (*mp->boot)(); if (status != 0) panic3(nm, mp->name, "boot() failed"); } } return 0; }
/* * Synopsis: * Accept incoming socket. * Returns: * 0 new socket accepted * 1 timed out the request * -1 accept() error, see errno. * Notes: * Unfortunatley, only the accept() error code is returned to the caller. * The sigaction()/settime() failures cause a panic. * * client_fd only changes on success. */ int net_accept(int listen_fd, struct sockaddr *addr, socklen_t *len, int *client_fd, unsigned timeout) { int fd, e; struct sigaction a; struct itimerval t; /* * Set the timeout alarm handler. */ memset(&a, 0, sizeof a); alarm_caught = 0; a.sa_handler = catch_SIGALRM; a.sa_flags = 0; sigemptyset(&a.sa_mask); t.it_interval.tv_sec = 0; t.it_interval.tv_usec = 0; t.it_value.tv_sec = timeout; t.it_value.tv_usec = 0; again: /* * Set the ALRM handler. */ if (sigaction(SIGALRM, &a, (struct sigaction *)0)) panic2("io_accept: sigaction(ALRM) failed", strerror(errno)); /* * Set the timer */ if (setitimer(ITIMER_REAL, &t, (struct itimerval *)0)) panic2("io_accept: setitimer(REAL) failed", strerror(errno)); /* * Accept an incoming client connection. */ fd = accept(listen_fd, addr, len); e = errno; /* * Disable timer. * * Note: * Does setitimer(t.it_interval.tv_sec == 0) above imply * timer never refires? */ t.it_value.tv_sec = 0; t.it_value.tv_usec = 0; if (setitimer(ITIMER_REAL, &t, (struct itimerval *)0)) panic2("io_accept: settimer(REAL, 0) failed", strerror(errno)); if (fd > -1) { *client_fd = fd; return 0; } /* * Retry or timeout. */ if (e == EINTR || e == EAGAIN) { /* * Timeout. */ if (alarm_caught) { alarm_caught = 0; return 1; } goto again; } errno = e; return -1; }
u32 _main(void *base) { FRESULT fres; int res; u32 vector; (void)base; gecko_init(); gecko_printf("mini %s loading\n", git_version); gecko_printf("Initializing exceptions...\n"); exception_initialize(); gecko_printf("Configuring caches and MMU...\n"); mem_initialize(); gecko_printf("IOSflags: %08x %08x %08x\n", read32(0xffffff00), read32(0xffffff04), read32(0xffffff08)); gecko_printf(" %08x %08x %08x\n", read32(0xffffff0c), read32(0xffffff10), read32(0xffffff14)); irq_initialize(); irq_enable(IRQ_TIMER); // irq_enable(IRQ_GPIO1B); irq_enable(IRQ_GPIO1); irq_enable(IRQ_RESET); gecko_timer_initialize(); gecko_printf("Interrupts initialized\n"); crypto_initialize(); gecko_printf("crypto support initialized\n"); nand_initialize(); gecko_printf("NAND initialized.\n"); boot2_init(); gecko_printf("Initializing IPC...\n"); ipc_initialize(); gecko_printf("Initializing SDHC...\n"); sdhc_init(); gecko_printf("Mounting SD...\n"); fres = f_mount(0, &fatfs); if (read32(0x0d800190) & 2) { gecko_printf("GameCube compatibility mode detected...\n"); vector = boot2_run(1, 0x101); goto shutdown; } if(fres != FR_OK) { gecko_printf("Error %d while trying to mount SD\n", fres); panic2(0, PANIC_MOUNT); } gecko_printf("Trying to boot:" PPC_BOOT_FILE "\n"); res = powerpc_boot_file(PPC_BOOT_FILE); if(res < 0) { gecko_printf("Failed to boot PPC: %d\n", res); gecko_printf("Continuing anyway\n"); } gecko_printf("Going into IPC mainloop...\n"); vector = ipc_process_slow(); gecko_printf("IPC mainloop done!\n"); gecko_printf("Shutting down IPC...\n"); ipc_shutdown(); shutdown: gecko_printf("Shutting down interrupts...\n"); irq_shutdown(); gecko_printf("Shutting down caches and MMU...\n"); mem_shutdown(); gecko_printf("Vectoring to 0x%08x...\n", vector); return vector; }