-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.c
118 lines (94 loc) · 2.78 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
mini - a Free Software replacement for the Nintendo/BroadOn IOS.
Copyright (C) 2008, 2009 Haxx Enterprises <[email protected]>
Copyright (C) 2008, 2009 Sven Peter <[email protected]>
Copyright (C) 2008, 2009 Hector Martin "marcan" <[email protected]>
Copyright (C) 2009 Andre Heider "dhewg" <[email protected]>
Copyright (C) 2009 John Kelley <[email protected]>
# 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
*/
#include "types.h"
#include "utils.h"
#include "start.h"
#include "hollywood.h"
#include "sdhc.h"
#include "string.h"
#include "memory.h"
#include "gecko.h"
#include "ff.h"
#include "panic.h"
#include "powerpc_elf.h"
#include "irq.h"
#include "ipc.h"
#include "exception.h"
#include "crypto.h"
#include "nand.h"
#include "boot2.h"
#include "git_version.h"
#define PPC_BOOT_FILE "/bootmii/ppcboot.elf"
FATFS fatfs;
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_GPIO1B);
irq_enable(IRQ_GPIO1);
irq_enable(IRQ_RESET);
irq_enable(IRQ_TIMER);
irq_set_alarm(20, 1);
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("Booting System Menu\n");
vector = boot2_run(1, 2);
goto shutdown;
}
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;
}