Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathloader.c
More file actions
Latest commit
160 lines (135 loc) · 3.71 KB
/
Copy pathloader.c
File metadata and controls
160 lines (135 loc) · 3.71 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
* loader.c - iPodLinux loader
* Copyright (c) 2003, Daniel Palffy (dpalffy (at) rainstorm.org)
* Copyright (c) 2003, Bernard Leach (leachbj@bouncycastle.org)
* - Keyboard initialization, I/O
* Copyright (C) 1996-2000 Russell King
* - inb, outb
* Copyright (C) 1991, 1992 Linus Torvalds
* - memmove
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include"tools.h"
typedefstruct_image {
unsignedtype; /* '' */
unsignedid; /* */
unsignedpad1; /* 0000 0000 */
unsigneddevOffset; /* byte offset of start of image code */
unsignedlen; /* length in bytes of image */
void*addr; /* load address */
unsignedentryOffset; /* execution start within image */
unsignedchksum; /* checksum for image */
unsignedvers; /* image version */
unsignedloadAddr; /* load address for image */
} image_t;
#defineTBL ((char **)0x40000000)
#defineMASK 0x1
externimage_tboot_table[];
externimgtux_hdr;
externimghappymac_hdr;
intipod_ver=0;
/* black magic */
staticvoid
init_keyboard(void)
{
if (ipod_ver<4) {
/* 1..3g keyboard init */
outb(~inb(0xcf000030), 0xcf000060);
outb(inb(0xcf000040), 0xcf000070);
outb(inb(0xcf000004) | 0x1, 0xcf000004);
outb(inb(0xcf000014) | 0x1, 0xcf000014);
outb(inb(0xcf000024) | 0x1, 0xcf000024);
outb(0xff, 0xcf000050);
} elseif (ipod_ver==4) {
/* mini keyboard init */
outl(inl(0x6000d000) | 0x3f, 0x6000d000);
outl(inl(0x6000d010) & ~0x3f, 0x6000d010);
} elseif (ipod_ver >= 5) {
/* 4g/photo keyboard init */
/* nothing to do */
}
}
staticint
key_pressed(void)
{
unsigned charstate;
if (ipod_ver<4) {
state=inb(0xcf000030);
if ((ipod_ver==3) && ((state&0x20) ==0)) return0; /* hold on */
if ((state&0x08) ==0) return1;
if ((state&0x10) ==0) return2;
if ((state&0x04) ==0) return3;
if ((state&0x01) ==0) return4;
} elseif(ipod_ver==4) {
/* mini buttons */
state=inb(0x6000d030);
if ((state&0x10) ==0) return1;
if ((state&0x2) ==0) return2;
if ((state&0x04) ==0) return3;
if ((state&0x08) ==0) return4;
} elseif(ipod_ver >= 5) {
state=opto_keypad_read();
if ((state&0x4) ==0) return1;
if ((state&0x10) ==0) return2;
if ((state&0x8) ==0) return3;
if ((state&0x2) ==0) return4;
}
return0;
}
staticvoid
memmove16(void*dest, constvoid*src, unsignedcount)
{
structbufstr {
unsigned_buf[4];
} *d, *s;
if (src >= dest) {
count= (count+15) >> 4;
d= (structbufstr*) dest;
s= (structbufstr*) src;
while (count--)
*d++=*s++;
} else {
count= (count+15) >> 4;
d= (structbufstr*)(dest+ (count <<4));
s= (structbufstr*)(src+ (count <<4));
while (count--)
*--d=*--s;
}
}
void*
loader(void)
{
intimageno=0;
intpadding=0x4400;
image_t*tblp=boot_table;
void*entry;
get_ipod_rev();
if (ipod_ver>3) padding=0x4600;
display_image(&tux_hdr, 0x0);
wait_usec(300);
init_keyboard();
imageno=key_pressed();
if (!tblp[imageno].type) imageno=0;
/* for appleOS as default, 0=happymac_hdr, 1=tux_hdr
for linux as default, 0=tux_hdr, 1=happymac_hdr
*/
switch (imageno) {
case0:
display_image(&happymac_hdr, 0x0);
break;
case1:
default:
display_image(&tux_hdr, 0x0);
break;
}
tblp+=imageno;
entry=tblp->addr+tblp->entryOffset;
if (imageno|| ((int)tblp->addr&0xffffff) !=0) {
memmove16(tblp->addr, tblp->addr+tblp->devOffset-padding,
tblp->len);
}
returnentry;
}