2009-04-03 16:27:19 +02:00
|
|
|
/*
|
|
|
|
mini - a Free Software replacement for the Nintendo/BroadOn IOS.
|
|
|
|
|
2009-04-13 22:13:45 +02:00
|
|
|
Copyright (C) 2008, 2009 Haxx Enterprises <bushing@gmail.com>
|
|
|
|
Copyright (C) 2008, 2009 Sven Peter <svenpeter@gmail.com>
|
2009-04-10 18:15:10 +02:00
|
|
|
Copyright (C) 2008, 2009 Hector Martin "marcan" <marcan@marcansoft.com>
|
2009-04-13 22:13:45 +02:00
|
|
|
Copyright (C) 2009 Andre Heider "dhewg" <dhewg@wiibrew.org>
|
2009-04-14 01:32:37 +02:00
|
|
|
Copyright (C) 2009 John Kelley <wiidev@kelley.ca>
|
2009-04-03 16:27:19 +02:00
|
|
|
|
2009-05-11 07:53:16 +02:00
|
|
|
# This code is licensed to you under the terms of the GNU GPL, version 2;
|
|
|
|
# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
|
2009-04-03 16:27:19 +02:00
|
|
|
*/
|
2009-05-11 07:53:16 +02:00
|
|
|
|
2008-12-28 14:35:37 +01:00
|
|
|
#include "types.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "start.h"
|
|
|
|
#include "hollywood.h"
|
2009-10-24 13:30:58 +02:00
|
|
|
#include "sdhc.h"
|
2008-12-28 14:35:37 +01:00
|
|
|
#include "string.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "gecko.h"
|
|
|
|
#include "ff.h"
|
|
|
|
#include "panic.h"
|
|
|
|
#include "powerpc_elf.h"
|
2009-01-08 23:27:22 +01:00
|
|
|
#include "irq.h"
|
2009-01-16 08:51:51 +01:00
|
|
|
#include "ipc.h"
|
2009-01-16 08:53:57 +01:00
|
|
|
#include "exception.h"
|
2009-01-17 15:05:13 +01:00
|
|
|
#include "crypto.h"
|
|
|
|
#include "nand.h"
|
2009-02-24 16:20:28 +01:00
|
|
|
#include "boot2.h"
|
2009-05-11 04:19:57 +02:00
|
|
|
#include "git_version.h"
|
2009-01-17 15:05:13 +01:00
|
|
|
|
2009-04-18 13:47:11 +02:00
|
|
|
#define PPC_BOOT_FILE "/bootmii/ppcboot.elf"
|
2008-12-28 14:35:37 +01:00
|
|
|
|
|
|
|
FATFS fatfs;
|
|
|
|
|
2009-04-10 17:25:13 +02:00
|
|
|
u32 _main(void *base)
|
2008-12-28 14:35:37 +01:00
|
|
|
{
|
|
|
|
FRESULT fres;
|
|
|
|
int res;
|
2009-04-10 17:25:13 +02:00
|
|
|
u32 vector;
|
2009-04-13 15:42:46 +02:00
|
|
|
(void)base;
|
2009-04-13 22:13:45 +02:00
|
|
|
|
2009-01-06 00:13:39 +01:00
|
|
|
gecko_init();
|
2009-05-15 14:54:55 +02:00
|
|
|
gecko_printf("mini %s loading\n", git_version);
|
2008-12-28 14:35:37 +01:00
|
|
|
|
2009-04-05 15:43:25 +02:00
|
|
|
gecko_printf("Initializing exceptions...\n");
|
2009-01-16 08:53:57 +01:00
|
|
|
exception_initialize();
|
2009-04-05 15:43:25 +02:00
|
|
|
gecko_printf("Configuring caches and MMU...\n");
|
2009-01-16 08:53:03 +01:00
|
|
|
mem_initialize();
|
|
|
|
|
2009-03-06 05:28:43 +01:00
|
|
|
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));
|
|
|
|
|
2009-01-08 23:27:22 +01:00
|
|
|
irq_initialize();
|
|
|
|
irq_enable(IRQ_TIMER);
|
2009-04-11 23:42:53 +02:00
|
|
|
// irq_enable(IRQ_GPIO1B);
|
2009-01-08 23:27:22 +01:00
|
|
|
irq_enable(IRQ_GPIO1);
|
|
|
|
irq_enable(IRQ_RESET);
|
2009-04-10 11:25:10 +02:00
|
|
|
gecko_timer_initialize();
|
2009-04-05 15:43:25 +02:00
|
|
|
gecko_printf("Interrupts initialized\n");
|
2009-01-06 00:13:39 +01:00
|
|
|
|
2009-01-17 15:05:13 +01:00
|
|
|
crypto_initialize();
|
2009-04-05 15:43:25 +02:00
|
|
|
gecko_printf("crypto support initialized\n");
|
2009-01-17 15:05:13 +01:00
|
|
|
|
|
|
|
nand_initialize();
|
2009-04-05 15:43:25 +02:00
|
|
|
gecko_printf("NAND initialized.\n");
|
2009-01-17 15:05:13 +01:00
|
|
|
|
2009-02-24 16:20:28 +01:00
|
|
|
boot2_init();
|
|
|
|
|
2009-04-05 15:43:25 +02:00
|
|
|
gecko_printf("Initializing IPC...\n");
|
2009-01-16 08:51:51 +01:00
|
|
|
ipc_initialize();
|
2009-01-06 00:13:39 +01:00
|
|
|
|
2010-05-10 09:51:37 +02:00
|
|
|
gecko_printf("Initializing SDHC...\n");
|
|
|
|
sdhc_init();
|
|
|
|
|
|
|
|
gecko_printf("Mounting SD...\n");
|
|
|
|
fres = f_mount(0, &fatfs);
|
|
|
|
|
2010-07-16 14:04:57 +02:00
|
|
|
if (read32(0x0d800190) & 2) {
|
|
|
|
gecko_printf("GameCube compatibility mode detected...\n");
|
|
|
|
vector = boot2_run(1, 0x101);
|
|
|
|
goto shutdown;
|
|
|
|
}
|
|
|
|
|
2009-01-16 08:51:51 +01:00
|
|
|
if(fres != FR_OK) {
|
|
|
|
gecko_printf("Error %d while trying to mount SD\n", fres);
|
|
|
|
panic2(0, PANIC_MOUNT);
|
|
|
|
}
|
|
|
|
|
2009-04-05 15:43:25 +02:00
|
|
|
gecko_printf("Trying to boot:" PPC_BOOT_FILE "\n");
|
2009-01-06 00:13:39 +01:00
|
|
|
|
2009-04-08 16:30:32 +02:00
|
|
|
res = powerpc_boot_file(PPC_BOOT_FILE);
|
2008-12-28 14:35:37 +01:00
|
|
|
if(res < 0) {
|
|
|
|
gecko_printf("Failed to boot PPC: %d\n", res);
|
2010-07-16 14:04:57 +02:00
|
|
|
gecko_printf("Booting System Menu\n");
|
|
|
|
vector = boot2_run(1, 2);
|
2010-05-10 09:51:37 +02:00
|
|
|
goto shutdown;
|
2008-12-28 14:35:37 +01:00
|
|
|
}
|
|
|
|
|
2009-04-05 15:43:25 +02:00
|
|
|
gecko_printf("Going into IPC mainloop...\n");
|
2009-04-10 17:25:13 +02:00
|
|
|
vector = ipc_process_slow();
|
2009-04-05 15:43:25 +02:00
|
|
|
gecko_printf("IPC mainloop done!\n");
|
|
|
|
gecko_printf("Shutting down IPC...\n");
|
2009-01-16 08:51:51 +01:00
|
|
|
ipc_shutdown();
|
2009-04-03 18:04:55 +02:00
|
|
|
|
|
|
|
shutdown:
|
2009-04-05 15:43:25 +02:00
|
|
|
gecko_printf("Shutting down interrupts...\n");
|
2009-01-16 08:51:51 +01:00
|
|
|
irq_shutdown();
|
2009-04-05 15:43:25 +02:00
|
|
|
gecko_printf("Shutting down caches and MMU...\n");
|
2009-01-16 08:53:03 +01:00
|
|
|
mem_shutdown();
|
2009-01-06 00:13:39 +01:00
|
|
|
|
2009-04-10 17:25:13 +02:00
|
|
|
gecko_printf("Vectoring to 0x%08x...\n", vector);
|
2009-01-16 08:51:51 +01:00
|
|
|
return vector;
|
2008-12-28 14:35:37 +01:00
|
|
|
}
|
2009-04-13 22:13:45 +02:00
|
|
|
|