Merge branch 'isr_test' of git://github.com/theStack/ppcskel into isr_test
[ppcskel.git] / main.c
1 /*
2         BootMii - a Free Software replacement for the Nintendo/BroadOn bootloader.
3         Requires mini.
4
5 Copyright (C) 2008, 2009        Haxx Enterprises <bushing@gmail.com>
6 Copyright (C) 2009              Andre Heider "dhewg" <dhewg@wiibrew.org>
7 Copyright (C) 2008, 2009        Hector Martin "marcan" <marcan@marcansoft.com>
8 Copyright (C) 2008, 2009        Sven Peter <svenpeter@gmail.com>
9 Copyright (C) 2009              John Kelley <wiidev@kelley.ca>
10
11 # This code is licensed to you under the terms of the GNU GPL, version 2;
12 # see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
13 */
14
15 #include "bootmii_ppc.h"
16 #include "string.h"
17 #include "ipc.h"
18 #include "mini_ipc.h"
19 #include "nandfs.h"
20 #include "fat.h"
21 #include "malloc.h"
22 #include "diskio.h"
23 #include "printf.h"
24 #include "video_low.h"
25 #include "input.h"
26 #include "console.h"
27 #include "ohci.h"
28 #include "irq.h"
29
30 #define MINIMUM_MINI_VERSION 0x00010001
31
32 otp_t otp;
33 seeprom_t seeprom;
34
35 static void dsp_reset(void)
36 {
37         write16(0x0c00500a, read16(0x0c00500a) & ~0x01f8);
38         write16(0x0c00500a, read16(0x0c00500a) | 0x0010);
39         write16(0x0c005036, 0);
40 }
41
42 static char ascii(char s) {
43   if(s < 0x20) return '.';
44   if(s > 0x7E) return '.';
45   return s;
46 }
47
48 void hexdump(void *d, int len) {
49   u8 *data;
50   int i, off;
51   data = (u8*)d;
52   for (off=0; off<len; off += 16) {
53     printf("%08x  ",off);
54     for(i=0; i<16; i++)
55       if((i+off)>=len) printf("   ");
56       else printf("%02x ",data[off+i]);
57
58     printf(" ");
59     for(i=0; i<16; i++)
60       if((i+off)>=len) printf(" ");
61       else printf("%c",ascii(data[off+i]));
62     printf("\n");
63   }
64 }
65         
66 void testOTP(void)
67 {
68         printf("reading OTP...\n");
69         getotp(&otp);
70         printf("read OTP!\n");
71         printf("OTP:\n");
72         hexdump(&otp, sizeof(otp));
73
74         printf("reading SEEPROM...\n");
75         getseeprom(&seeprom);
76         printf("read SEEPROM!\n");
77         printf("SEEPROM:\n");
78         hexdump(&seeprom, sizeof(seeprom));
79 }
80
81 int main(void)
82 {
83         int vmode = -1;
84         exception_init();
85         dsp_reset();
86
87         irq_initialize();
88         irq_enable(IRQ_OHCI0);
89         
90         ipc_initialize();
91         ipc_slowping();
92
93         gecko_init();
94     input_init();
95         init_fb(vmode);
96         ohci_init();
97
98         VIDEO_Init(vmode);
99         VIDEO_SetFrameBuffer(get_xfb());
100         VISetupEncoder();
101
102         u32 version = ipc_getvers();
103         u16 mini_version_major = version >> 16 & 0xFFFF;
104         u16 mini_version_minor = version & 0xFFFF;
105         printf("Mini version: %d.%0d\n", mini_version_major, mini_version_minor);
106
107         if (version < MINIMUM_MINI_VERSION) {
108                 printf("Sorry, this version of MINI (armboot.bin)\n"
109                         "is too old, please update to at least %d.%0d.\n", 
110                         (MINIMUM_MINI_VERSION >> 16), (MINIMUM_MINI_VERSION & 0xFFFF));
111                 for (;;) 
112                         ; // better ideas welcome!
113         }
114
115     print_str_noscroll(112, 112, "ohai, world!\n");
116
117         testOTP();
118
119         printf("bye, world!\n");
120
121         while(1) {
122                 // just to get sure we are still in this loop
123                 //wtf? _CPU_ISR_Enable() // don't know why this is needed...
124                 udelay(100000);
125                 printf("x");
126         }
127
128         return 0;
129 }
130