ohci0 interrupt will be thrown - hooray++ \o/
[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
29 #define MINIMUM_MINI_VERSION 0x00010001
30
31 otp_t otp;
32 seeprom_t seeprom;
33
34 static void dsp_reset(void)
35 {
36         write16(0x0c00500a, read16(0x0c00500a) & ~0x01f8);
37         write16(0x0c00500a, read16(0x0c00500a) | 0x0010);
38         write16(0x0c005036, 0);
39 }
40
41 static char ascii(char s) {
42   if(s < 0x20) return '.';
43   if(s > 0x7E) return '.';
44   return s;
45 }
46
47 void hexdump(void *d, int len) {
48   u8 *data;
49   int i, off;
50   data = (u8*)d;
51   for (off=0; off<len; off += 16) {
52     printf("%08x  ",off);
53     for(i=0; i<16; i++)
54       if((i+off)>=len) printf("   ");
55       else printf("%02x ",data[off+i]);
56
57     printf(" ");
58     for(i=0; i<16; i++)
59       if((i+off)>=len) printf(" ");
60       else printf("%c",ascii(data[off+i]));
61     printf("\n");
62   }
63 }
64         
65 void testOTP(void)
66 {
67         printf("reading OTP...\n");
68         getotp(&otp);
69         printf("read OTP!\n");
70         printf("OTP:\n");
71         hexdump(&otp, sizeof(otp));
72
73         printf("reading SEEPROM...\n");
74         getseeprom(&seeprom);
75         printf("read SEEPROM!\n");
76         printf("SEEPROM:\n");
77         hexdump(&seeprom, sizeof(seeprom));
78 }
79
80 int main(void)
81 {
82         int vmode = -1;
83         exception_init();
84         dsp_reset();
85
86         // clear interrupt mask
87         write32(0x0c003004, 0);
88
89         ipc_initialize();
90         ipc_slowping();
91
92         gecko_init();
93     input_init();
94         init_fb(vmode);
95         ohci_init();
96
97         VIDEO_Init(vmode);
98         VIDEO_SetFrameBuffer(get_xfb());
99         VISetupEncoder();
100
101         u32 version = ipc_getvers();
102         u16 mini_version_major = version >> 16 & 0xFFFF;
103         u16 mini_version_minor = version & 0xFFFF;
104         printf("Mini version: %d.%0d\n", mini_version_major, mini_version_minor);
105
106         if (version < MINIMUM_MINI_VERSION) {
107                 printf("Sorry, this version of MINI (armboot.bin)\n"
108                         "is too old, please update to at least %d.%0d.\n", 
109                         (MINIMUM_MINI_VERSION >> 16), (MINIMUM_MINI_VERSION & 0xFFFF));
110                 for (;;) 
111                         ; // better ideas welcome!
112         }
113
114     print_str_noscroll(112, 112, "ohai, world!\n");
115
116         testOTP();
117
118         printf("bye, world!\n");
119
120         // enable OHCI0 interrupt on hollywood-pic
121 #define HW_PPCIRQFLAG (0x0d800030)
122 #define HW_PPCIRQMASK (0x0d800034)
123         write32(HW_PPCIRQFLAG, ~0);
124         write32(HW_PPCIRQMASK, 1<<5);
125         // enable RESET and PIC (#14) interrupts on processor interface
126         write32(0x0c003004, (1<<1) | (1<<14));
127 #define _CPU_ISR_Enable() \
128         { register u32 _val = 0; \
129           __asm__ __volatile__ ( \
130                 "mfmsr %0\n" \
131                 "ori %0,%0,0x8000\n" \
132                 "mtmsr %0" \
133                 : "=&r" ((_val)) : "0" ((_val)) \
134           ); \
135         }
136         _CPU_ISR_Enable()
137
138         while(1) {}
139
140         return 0;
141 }
142