Subversion Repositories freemyipod

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
273 theseven 1
@
2
@
358 theseven 3
@    emBIOS Loader for iPod Classic
273 theseven 4
@
5
@    Copyright 2010 TheSeven
6
@
7
@
8
@    This file is part of emBIOS.
9
@
10
@    emBIOS is free software: you can redistribute it and/or
11
@    modify it under the terms of the GNU General Public License as
12
@    published by the Free Software Foundation, either version 2 of the
13
@    License, or (at your option) any later version.
14
@
15
@    emBIOS is distributed in the hope that it will be useful,
16
@    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
@    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
@    See the GNU General Public License for more details.
19
@
20
@    You should have received a copy of the GNU General Public License along
21
@    with emBIOS.  If not, see <http://www.gnu.org/licenses/>.
22
@
23
@
24
 
25
 
26
#include "build/version.h"
27
 
28
 
29
.global _start
30
_start:
31
 
32
	msr	cpsr_c, #0xd3
33
	mrc	p15, 0, r0,c1,c0
34
	bic	r0, r0, #1
35
	mcr	p15, 0, r0,c1,c0
36
	mov	r0, #0
37
	mcr	p15, 0, r0,c7,c5
38
	mcr	p15, 0, r0,c8,c7
39
	mcr	p15, 0, r0,c13,c0
40
	adr	lr, cacheflush_done
358 theseven 41
 
273 theseven 42
flushcache:
43
	mrc	p15, 0, r15,c7,c14,3
44
	bne	flushcache
45
	mov	r0, #0
46
	mcr	p15, 0, r0,c7,c10,4
47
	bx	lr
358 theseven 48
 
273 theseven 49
cacheflush_done:
50
	adr	sp, values1
51
	ldmia	sp!, {r4-r12}
52
	mcr	p15, 0, r11,c2,c0
53
	mov	r0, #-1
54
	mcr	p15, 0, r0,c3,c0
55
mmuloop:
56
	str	r12, [r11], #4
57
	add	r12, r12, #0x00100000
58
	cmp	r12, #0x38000000
59
	biccs	r12, r12, #0xc
60
	tst	r12, #0x40000000
61
	beq	mmuloop
62
	mcr	p15, 0, r10,c1,c0
63
dmaloop:
64
	add	r8, r8, #0x10
65
	bic	r9, r9, r4
66
	cmp	r4, r5
67
	movcs	r4, r5
68
	movcs	r8, #0
69
	orr	r9, r9, r4
70
	stmia	r11!, {r6-r9}
71
	add	r6, r6, r4,lsl#1
72
	subs	r5, r5, r4
73
	bne	dmaloop
74
	ldmia	sp!, {r0-r12}        @ R0 = SYSCONBASE (temporary)
75
	str	r1, [r0,#0x48]
76
	str	r2, [r0,#0x4c]
77
	mov	r2, #0               @ R2 = 0
78
	str	r2, [r0]
79
	str	r2, [r0,#0x4]
80
	mov	r1, #7
81
	str	r1, [r0,#0x44]
82
	mov	r1, #0x30
83
	str	r1, [r0,#0x44]
84
	str	r2, [r0,#0x60]
85
	str	r3, [r0,#0x28]
86
	str	r4, [r0,#0x38]
87
	mov	r1, #0x34
88
	str	r1, [r0,#0x44]
89
	orr	r1, r1, #0x40000
90
	str	r1, [r0,#0x44]
91
waitpll:
92
	ldr	r1, [r0,#0x40]
93
	tst	r1, #4
94
	beq	waitpll
95
	str	r5, [r0,#0x04]
96
	mov	r1, #0x3000
97
	str	r1, [r0]
98
	mov	r1, #0x8000
99
	orr	r3, r1, #0x80000000
100
	str	r3, [r0,#0x8]
101
	str	r3, [r0,#0xc]
102
	str	r1, [r0,#0x10]
103
	str	r1, [r0,#0x14]
104
	mov	r3, #3
105
	str	r3, [r6]
106
	orr	r1, r0, #0x00200000  @ R1 = TIMERBASE
107
	mov	r4, #0x440
108
	str	r4, [r1,#0xa0]
109
	mov	r4, #0xb
110
	str	r4, [r1,#0xb0]
111
	mvn	r4, r2
112
	str	r4, [r1,#0xa8]
113
	str	r3, [r1,#0xa4]
114
	orr	r3, r1, #0x00800000  @ R3 = GPIOBASE (temporary)
115
gpioloop:
116
	ldr	r4, [sp], #4
117
	str	r4, [r3], #0xc
118
	str	r2, [r3], #0x4
119
	str	r2, [r3], #0x10
120
	tst	r3, #0x200
121
	beq	gpioloop
122
	str	r7, [r3]
123
	add	r7, r7, #0x100
124
	str	r7, [r3]
125
	ldr	r7, [r3,#-0x30]
126
	bic	r7, r7, #0x40
127
	str	r7, [r3,#-0x30]
128
	ldr	r7, [r3,#-0x34]
129
	orr	r7, r7, #0x40
130
	str	r7, [r3,#-0x34]
131
	add	r5, r0, #0x00100000  @ R5 = I2CBASE
132
	bl	i2cwaitrdy           @ R3 = I2C address (temporary)
133
	mov	r7, #0x40            @ R4 = I2C data (temporary)
134
	str	r7, [r5,#8]          @ R6 = I2C scratch register (temporary)
135
	bl	i2cwaitrdy           @ R7 = I2C return address (temporary)
136
	str	r2, [r5,#0x14]       @ R0 = coldboot flag (temporary)
137
	bl	i2cwaitrdy
138
	str	r2, [r5,#0x18]
139
	bl	i2cwaitrdy
140
	mov	r6, #0x80
141
	str	r6, [r5,#0x4]
142
	bl	i2cwaitrdy
143
	str	r2, [r5]
144
	bl	i2cwaitrdy
145
	str	r2, [r5,#0x4]
146
	bl	i2cwaitrdy
147
	str	r7, [r5,#0xc]
148
	bl	i2cwaitrdy
149
	mov	r6, #0x184
150
	str	r6, [r5]
151
	bl	i2cwaitrdy
152
	mov	r6, #0x10
153
	str	r6, [r5,#0x4]
154
	bl	i2cwaitrdy
155
	mov	r3, #0x16
156
	mvn	r4, r2
157
	bl	pmutransfer
158
	and	r0, r4, #7
159
	mov	r3, #0xc
160
	mvn	r4, r2
161
	bl	pmutransfer
162
	and	r4, r4, #8
163
	orr	r0, r0, r4
164
pmuloop:
165
	ldrb	r3, [sp], #1
166
	ldrb	r4, [sp], #1
167
	cmp	r3, #0xff
168
	adrne	lr, pmuloop
169
	bne	pmutransfer
170
	mov	r3, #0x19
171
	mvn	r4, r2
172
	bl	pmutransfer
173
	tst	r4, #1
174
	beq	pwrok
175
	mov	r3, #0x4b
176
	mvn	r4, r2
177
	bl	pmutransfer
178
	tst	r4, #4
179
	bne	pwrok
180
	mov	r3, #0x12
181
	mvn	r4, r2
182
	bl	pmutransfer
183
	tst	r4, #4
184
	bne	pwrok
185
poweroff:
186
	mov	r3, #0xc
187
	mov	r4, #1
188
	bl	pmutransfer
189
	b	poweroff
190
 
191
values1:
192
	.word 0x00000FFF @ R4 - DMA maximum transfer size
193
	.word 0x00012C00 @ R5 - LCD framebuffer pixel count
194
	.word 0x22010000 @ R6 - LCD framebuffer address
195
	.word 0x38300040 @ R7 - LCD data port address
196
	.word 0x2203D000 @ R8 - LCD DMA linked list address
197
	.word 0x74240000 @ R9 - LCD DMA channel settings
198
	.word 0x0005107D @ R10 - CP15r1
199
	.word 0x2203C000 @ R11 - First level page table
200
	.word 0x00000C1E @ R12 - Default segment flags
201
	.word 0x3C500000 @ R0 - SYSCON base
202
	.word 0x2007CE65 @ R1 - PWRCON(0)
203
	.word 0x0003EFC9 @ R2 - PWRCON(1)
204
	.word 0x01002401 @ R3
205
	.word 0x00007E90 @ R4
206
	.word 0x00404101 @ R5
207
	.word 0x38501000 @ R6
208
	.word 0x00060400 @ R7
209
	.word 0x0000080D @ R8
210
	.word 0x0006105D @ R9
211
	.word 0x001FB621 @ R10
212
	.word 0x0790682B @ R11
213
	.word 0x00008040 @ R12
214
 
215
	.word 0x5322222F @ PCON0
216
	.word 0xEEEEEE00 @ PCON1
217
	.word 0x2332EEEE @ PCON2
218
	.word 0x3333E222 @ PCON3
219
	.word 0x33333333 @ PCON4
220
	.word 0x33333333 @ PCON5
221
	.word 0x3F000E33 @ PCON6
222
	.word 0xEEEEEEEE @ PCON7
223
	.word 0xEEEEEEEE @ PCON8
224
	.word 0xEEEEEEEE @ PCON9
320 theseven 225
	.word 0xE0EEEEEE @ PCONA
315 theseven 226
	.word 0xEF00EE0E @ PCONB
227
	.word 0xEEEE0EEF @ PCONC
273 theseven 228
	.word 0xEEEEEEEE @ PCOND
229
	.word 0x202222EE @ PCONE
230
	.word 0xEEEE0E22 @ PCONF
231
 
232
	.byte 0x0c, 0    @ PMU init address-data pairs
233
	.byte 0x2d, 0x15
234
	.byte 0x2e, 1
235
	.byte 0x37, 0x15
236
	.byte 0x38, 4
237
	.byte 0x2f, 0x15
238
	.byte 0x30, 1
239
	.byte 0x3b, 0
240
	.byte 0x3c, 0x8c
241
	.byte 0x13, 3
242
	.byte 0x14, 0
243
	.byte 0x15, 0
244
	.byte 0x22, 0x2f
245
	.byte 0x23, 1
246
	.byte 0x24, 0
247
	.byte 0x25, 0x10
248
	.byte 0x26, 9
249
	.byte 0x27, 1
250
	.byte 0x1a, 0x6f
251
	.byte 0x1b, 0
252
	.byte 0x1c, 0
253
	.byte 0x1d, 0x59
254
	.byte 0x33, 9
255
	.byte 0x34, 1
256
	.byte 0x39, 0x18
257
	.byte 0x3a, 0
258
	.byte 0x18, 0xa
259
	.byte 0x19, 4
260
	.byte 0x58, 0
261
	.byte 0x07, 0xb0
262
	.byte 0x08, 3
263
	.byte 0x09, 0xfe
264
	.byte 0x0a, 0xfc
265
	.byte 0x0b, 0xff
266
	.byte 0x86, 0xfd
267
	.byte 0x0d, 0xdf
268
	.byte 0x0e, 0xaa
269
	.byte 0x0f, 0x4a
270
	.byte 0x10, 5
271
	.byte 0x11, 0x27
272
	.byte 0x17, 1
273
	.byte 0x2a, 5
274
	.byte 0xff, 0xff @ PMU init terminator
275
 
276
lcddata_ref:
277
	.hword lcddata_0 - lcddata_ref
278
	.hword lcddata_1 - lcddata_ref - 2
279
	.hword lcddata_2 - lcddata_ref - 4
280
	.hword lcddata_3 - lcddata_ref - 6
281
lcddata_0:
282
	.hword 0x4011
283
	.hword 0xc78f
284
	.hword 0x8135
285
	.byte 0x00
286
	.hword 0x813a
287
	.byte 0x06
288
	.hword 0x8136
289
	.byte 0x00
290
	.hword 0x4013
291
	.hword 0x4029
292
	.hword 0xc000
293
lcddata_1:
294
	.hword 0x95b0
295
	.byte 0x3a
296
	.byte 0x3a
297
	.byte 0x80
298
	.byte 0x80
299
	.byte 0x0a
300
	.byte 0x0a
301
	.byte 0x0a
302
	.byte 0x0a
303
	.byte 0x0a
304
	.byte 0x0a
305
	.byte 0x0a
306
	.byte 0x0a
307
	.byte 0x3c
308
	.byte 0x30
309
	.byte 0x0f
310
	.byte 0x00
311
	.byte 0x01
312
	.byte 0x54
313
	.byte 0x06
314
	.byte 0x66
315
	.byte 0x66
316
	.hword 0x81b8
317
	.byte 0xd8
318
	.hword 0x9eb1
319
	.byte 0x14
320
	.byte 0x59
321
	.byte 0x00
322
	.byte 0x15
323
	.byte 0x57
324
	.byte 0x27
325
	.byte 0x04
326
	.byte 0x85
327
	.byte 0x14
328
	.byte 0x59
329
	.byte 0x00
330
	.byte 0x15
331
	.byte 0x57
332
	.byte 0x27
333
	.byte 0x04
334
	.byte 0x85
335
	.byte 0x14
336
	.byte 0x09
337
	.byte 0x15
338
	.byte 0x57
339
	.byte 0x27
340
	.byte 0x04
341
	.byte 0x05
342
	.byte 0x14
343
	.byte 0x09
344
	.byte 0x15
345
	.byte 0x57
346
	.byte 0x27
347
	.byte 0x04
348
	.byte 0x05
349
	.hword 0x40d2
350
	.hword 0x0101
351
	.hword 0x8de0
352
	.byte 0x00
353
	.byte 0x00
354
	.byte 0x00
355
	.byte 0x05
356
	.byte 0x0b
357
	.byte 0x12
358
	.byte 0x16
359
	.byte 0x1f
360
	.byte 0x25
361
	.byte 0x22
362
	.byte 0x24
363
	.byte 0x29
364
	.byte 0x1c
365
	.hword 0x8de1
366
	.byte 0x08
367
	.byte 0x01
368
	.byte 0x01
369
	.byte 0x06
370
	.byte 0x0b
371
	.byte 0x11
372
	.byte 0x15
373
	.byte 0x1f
374
	.byte 0x27
375
	.byte 0x26
376
	.byte 0x29
377
	.byte 0x2f
378
	.byte 0x1e
379
	.hword 0x8de2
380
	.byte 0x07
381
	.byte 0x01
382
	.byte 0x01
383
	.byte 0x05
384
	.byte 0x09
385
	.byte 0x0f
386
	.byte 0x13
387
	.byte 0x1e
388
	.byte 0x26
389
	.byte 0x25
390
	.byte 0x28
391
	.byte 0x2e
392
	.byte 0x1e
393
	.hword 0x8de3
394
	.byte 0x0d
395
	.byte 0x00
396
	.byte 0x00
397
	.byte 0x00
398
	.byte 0x05
399
	.byte 0x0b
400
	.byte 0x12
401
	.byte 0x16
402
	.byte 0x1f
403
	.byte 0x25
404
	.byte 0x22
405
	.byte 0x24
406
	.byte 0x29
407
	.byte 0x1c
408
	.hword 0x8de4
409
	.byte 0x08
410
	.byte 0x01
411
	.byte 0x01
412
	.byte 0x06
413
	.byte 0x0b
414
	.byte 0x11
415
	.byte 0x15
416
	.byte 0x1f
417
	.byte 0x27
418
	.byte 0x26
419
	.byte 0x29
420
	.byte 0x2f
421
	.byte 0x1e
422
	.hword 0x8de5
423
	.byte 0x07
424
	.byte 0x01
425
	.byte 0x01
426
	.byte 0x05
427
	.byte 0x09
428
	.byte 0x0f
429
	.byte 0x13
430
	.byte 0x1e
431
	.byte 0x26
432
	.byte 0x25
433
	.byte 0x28
434
	.byte 0x2e
435
	.byte 0x1e
436
	.hword 0x813a
437
	.byte 0x06
438
	.hword 0x81c2
439
	.byte 0x00
440
	.hword 0x8135
441
	.byte 0x00
442
	.hword 0x4011
443
	.hword 0xce88
444
	.hword 0x4013
445
	.hword 0x4029
446
lcddata_2:
447
	.hword 0xc000
448
lcddata_3:
449
	.hword 0x4008
450
	.hword 0x0808
451
	.hword 0x8110
452
	.byte 0x13
453
	.hword 0x4011
454
	.hword 0x0300
455
	.hword 0x4012
456
	.hword 0x0101
457
	.hword 0x4013
458
	.hword 0x0a03
459
	.hword 0x4014
460
	.hword 0x0a0e
461
	.hword 0x4015
462
	.hword 0x0a19
463
	.hword 0x4016
464
	.hword 0x2402
465
	.hword 0x8118
466
	.byte 0x01
467
	.hword 0x8190
468
	.byte 0x21
469
	.hword 0x4300
470
	.hword 0x0506
471
	.hword 0x4301
472
	.hword 0x0402
473
	.hword 0x4302
474
	.hword 0x0706
475
	.hword 0x4303
476
	.hword 0x0303
477
	.hword 0x4304
478
	.hword 0x0100
479
	.hword 0x4305
480
	.hword 0x0207
481
	.hword 0x4306
482
	.hword 0x170e
483
	.hword 0x4307
484
	.hword 0x0506
485
	.hword 0x4308
486
	.hword 0x0402
487
	.hword 0x4309
488
	.hword 0x0706
489
	.hword 0x430a
490
	.hword 0x0303
491
	.hword 0x430b
492
	.hword 0x0100
493
	.hword 0x430c
494
	.hword 0x0207
495
	.hword 0x430d
496
	.hword 0x170e
497
	.hword 0x4310
498
	.hword 0x0606
499
	.hword 0x4311
500
	.hword 0x0506
501
	.hword 0x4312
502
	.hword 0x0707
503
	.hword 0x4313
504
	.hword 0x0303
505
	.hword 0x4314
506
	.hword 0x0200
507
	.hword 0x4315
508
	.hword 0x0307
509
	.hword 0x4316
510
	.hword 0x170e
511
	.hword 0x4317
512
	.hword 0x0606
513
	.hword 0x4318
514
	.hword 0x0506
515
	.hword 0x4319
516
	.hword 0x0707
517
	.hword 0x431a
518
	.hword 0x0303
519
	.hword 0x431b
520
	.hword 0x0200
521
	.hword 0x431c
522
	.hword 0x0307
523
	.hword 0x431d
524
	.hword 0x170e
525
	.hword 0x4320
526
	.hword 0x0707
527
	.hword 0x4321
528
	.hword 0x0005
529
	.hword 0x4322
530
	.hword 0x0705
531
	.hword 0x4323
532
	.hword 0x0303
533
	.hword 0x4324
534
	.hword 0x0300
535
	.hword 0x4325
536
	.hword 0x0707
537
	.hword 0x4326
538
	.hword 0x1f16
539
	.hword 0x4327
540
	.hword 0x0707
541
	.hword 0x4328
542
	.hword 0x0005
543
	.hword 0x4329
544
	.hword 0x0705
545
	.hword 0x432a
546
	.hword 0x0303
547
	.hword 0x432b
548
	.hword 0x0300
549
	.hword 0x432c
550
	.hword 0x0707
551
	.hword 0x432d
552
	.hword 0x1f16
553
	.hword 0x4400
554
	.hword 0x001d
555
	.hword 0x4401
556
	.hword 0x0001
557
	.hword 0x4205
558
	.hword 0x0060
559
	.hword 0x8107
560
	.byte 0x01
561
	.hword 0x8131
562
	.byte 0x71
563
	.hword 0x4110
564
	.hword 0x0001
565
	.hword 0x4100
566
	.hword 0x17b0
567
	.hword 0x4101
568
	.hword 0x0220
569
	.hword 0x4102
570
	.hword 0x009b
571
	.hword 0x4103
572
	.hword 0x1200
573
	.hword 0x4105
574
	.hword 0x0103
575
	.hword 0x4106
576
	.hword 0x0105
577
	.hword 0x8107
578
	.byte 0x21
579
	.hword 0x4102
580
	.hword 0x00bd
581
	.hword 0x4001
582
	.hword 0x0110
583
	.hword 0x4003
584
	.hword 0x0230
585
	.hword 0x4002
586
	.hword 0x0500
587
	.hword 0x8107
588
	.byte 0x31
589
	.hword 0x4130
590
	.byte 0x07
591
	.hword 0xc744
592
	.hword 0x4030
593
	.hword 0x03ff
594
	.hword 0xce88
595
	.hword 0x8107
596
	.byte 0x72
597
	.hword 0xe454
598
	.hword 0x4007
599
	.hword 0x0173
600
	.hword 0xc000
601
 
602
font:
603
	.byte 0, 0, 0, 0, 0
604
	.byte 0, 0, 95, 0, 0
605
	.byte 0, 7, 0, 7, 0
606
	.byte 20, 127, 20, 127, 20
607
	.byte 36, 42, 127, 42, 18
608
	.byte 35, 19, 8, 100, 98
609
	.byte 54, 73, 85, 34, 80
610
	.byte 5, 3, 0, 0, 0
611
	.byte 28, 34, 65, 0, 0
612
	.byte 0, 0, 65, 34, 28
613
	.byte 20, 8, 62, 8, 20
614
	.byte 8, 8, 62, 8, 8
615
	.byte 0, -96, 96, 0, 0
616
	.byte 8, 8, 8, 8, 8
617
	.byte 0, 96, 96, 0, 0
618
	.byte 32, 16, 8, 4, 2
619
	.byte 62, 81, 73, 69, 62
620
	.byte 0, 66, 127, 64, 0
621
	.byte 66, 97, 81, 73, 70
622
	.byte 33, 65, 69, 75, 49
623
	.byte 24, 20, 18, 127, 16
624
	.byte 39, 69, 69, 69, 57
625
	.byte 60, 74, 73, 73, 48
626
	.byte 1, 113, 9, 5, 3
627
	.byte 54, 73, 73, 73, 54
628
	.byte 6, 73, 73, 41, 30
629
	.byte 0, 54, 54, 0, 0
630
	.byte 0, 86, 54, 0, 0
631
	.byte 8, 20, 34, 65, 0
632
	.byte 20, 20, 20, 20, 20
633
	.byte 0, 65, 34, 20, 8
634
	.byte 2, 1, 81, 9, 6
635
	.byte 50, 73, 121, 65, 62
636
	.byte 124, 18, 17, 18, 124
637
	.byte 127, 73, 73, 73, 62
638
	.byte 62, 65, 65, 65, 34
639
	.byte 127, 65, 65, 34, 28
640
	.byte 127, 73, 73, 73, 65
641
	.byte 127, 9, 9, 9, 1
642
	.byte 62, 65, 73, 73, 58
643
	.byte 127, 8, 8, 8, 127
644
	.byte 0, 65, 127, 65, 0
645
	.byte 32, 64, 65, 63, 1
646
	.byte 127, 8, 20, 34, 65
647
	.byte 127, 64, 64, 64, 64
648
	.byte 127, 2, 12, 2, 127
649
	.byte 127, 4, 8, 16, 127
650
	.byte 62, 65, 65, 65, 62
651
	.byte 127, 9, 9, 9, 6
652
	.byte 62, 65, 81, 33, 94
653
	.byte 127, 9, 25, 41, 70
654
	.byte 38, 73, 73, 73, 50
655
	.byte 1, 1, 127, 1, 1
656
	.byte 63, 64, 64, 64, 63
657
	.byte 31, 32, 64, 32, 31
658
	.byte 127, 32, 24, 32, 127
659
	.byte 99, 20, 8, 20, 99
660
	.byte 3, 4, 120, 4, 3
661
	.byte 97, 81, 73, 69, 67
662
	.byte 0, 127, 65, 65, 0
663
	.byte 2, 4, 8, 16, 32
664
	.byte 0, 65, 65, 127, 0
665
	.byte 4, 2, 1, 2, 4
666
	.byte 64, 64, 64, 64, 64
667
	.byte 1, 2, 4, 0, 0
668
	.byte 32, 84, 84, 84, 120
669
	.byte 127, 68, 68, 68, 56
670
	.byte 56, 68, 68, 68, 40
671
	.byte 56, 68, 68, 68, 127
672
	.byte 56, 84, 84, 84, 24
673
	.byte 8, 126, 9, 1, 2
674
	.byte 8, 84, 84, 84, 60
675
	.byte 127, 4, 4, 4, 120
676
	.byte 0, 68, 125, 64, 0
677
	.byte 32, 64, 64, 61, 0
678
	.byte 127, 16, 40, 68, 0
679
	.byte 0, 65, 127, 64, 0
680
	.byte 124, 4, 24, 4, 120
681
	.byte 124, 8, 4, 4, 120
682
	.byte 56, 68, 68, 68, 56
683
	.byte 124, 20, 20, 20, 24
684
	.byte 8, 20, 20, 20, 124
685
	.byte 124, 8, 4, 4, 8
686
	.byte 72, 84, 84, 84, 32
687
	.byte 4, 63, 68, 64, 32
688
	.byte 60, 64, 64, 32, 124
689
	.byte 28, 32, 64, 32, 28
690
	.byte 60, 64, 56, 64, 60
691
	.byte 68, 40, 16, 40, 68
692
	.byte 12, 80, 80, 80, 60
693
	.byte 68, 100, 84, 76, 68
694
	.byte 0, 8, 54, 65, 0
695
	.byte 0, 0, 119, 0, 0
696
	.byte 0, 65, 54, 8, 0
697
	.byte 2, 1, 2, 4, 2
698
 
699
	.code 16
700
	.align 1
701
 
702
thumb_nrv2e_d8:
703
	mov r7,r2
704
        mov r4,#1; neg r5,r4 @ r5= -1 initial condition
705
        lsl r4,#31 @ 1<<31: refill next time
706
        mov r6,#5
707
        lsl r6,#8 @ 0x500 @ nrv2e M2_MAX_OFFSET
708
        b top_n2e
709
 
710
nrv2e_done:
711
	blx flushcache
712
	bx r7
713
 
714
get1_n2e: @ In: Carry set [from adding 0x80000000 (1<<31) to itself]
715
        ldrb r4,[r0] @ zero-extend next byte
716
        adc r4,r4 @ double and insert CarryIn as low bit
717
        add r0,#1
718
        lsl r4,#24 @ move to top byte, and set CarryOut from old bit 8
719
        mov pc,lr @ return, stay in current (THUMB) mode
720
 
721
lit_n2e:
722
        ldrb r3,[r0]; add r0,#1
723
        strb r3,[r2]; add r2,#1
724
top_n2e:
725
        add r4,r4; mov lr,pc; beq get1_n2e; bcs lit_n2e
726
        mov r1,#1; b getoff_n2e
727
 
728
off_n2e:
729
        sub r1,#1
730
        add r4,r4; mov lr,pc; beq get1_n2e; adc r1,r1
731
getoff_n2e:
732
        add r4,r4; mov lr,pc; beq get1_n2e; adc r1,r1
733
        add r4,r4; mov lr,pc; beq get1_n2e; bcc off_n2e
734
 
735
        sub r3,r1,#3 @ set Carry
736
        mov r1,#0 @ Carry unaffected
737
        blo offprev_n2e @ r1 was 2; tests Carry only
738
        lsl r3,#8
739
        ldrb r5,[r0]; add r0,#1 @ low 7+1 r4
740
        orr r5,r3
741
        mvn r5,r5; beq nrv2e_done @ r5= ~r5
742
        asr r5,#1; bcs lenlast_n2e
743
        b lenmore_n2e
744
 
745
offprev_n2e:
746
        add r4,r4; mov lr,pc; beq get1_n2e; bcs lenlast_n2e
747
lenmore_n2e:
748
        mov r1,#1
749
        add r4,r4; mov lr,pc; beq get1_n2e; bcs lenlast_n2e
750
len_n2e:
751
        add r4,r4; mov lr,pc; beq get1_n2e; adc r1,r1
752
        add r4,r4; mov lr,pc; beq get1_n2e; bcc len_n2e
753
        add r1,#6-2
754
        b gotlen_n2e
755
 
756
lenlast_n2e:
757
        add r4,r4; mov lr,pc; beq get1_n2e; adc r1,r1 @ 0,1,2,3
758
        add r1,#2
759
gotlen_n2e: @ 'cmn': add the inputs, set condition codes, discard the sum
760
        cmn r6,r5; bcs near_n2e @ within M2_MAX_OFFSET
761
        add r1,#1 @ too far away, so minimum match length is 3
762
near_n2e:
763
        ldrb r3,[r2] @ force cacheline allocate
764
copy_n2e:
765
        ldrb r3,[r2,r5]
766
        strb r3,[r2]; add r2,#1
767
        sub r1,#1; bne copy_n2e
768
        b top_n2e
769
 
770
	.code 32
771
	.align 2
772
 
773
foundfile:
774
	ldr	r12, [r11,#0xc]
775
	ldr	r11, [r11,#0x8]
776
	tst	r12, #0x80000000
777
	bic	r12, r12, #0xff000000
778
	bic	r12, r12, #0xf00000
779
	bne	compressed
780
    	mov	r1, #0x08000000
781
	bl	bootflash_read
782
	mov	lr, #0x08000000
783
	b	flushcache
784
compressed:
785
    	mov	r1, #0x09000000
786
	bl	bootflash_read
787
	mov	r0, #0x09000000
788
	mov	r2, #0x08000000
789
	blx	thumb_nrv2e_d8
790
 
791
 
792
rendertext:
793
	ldrb	r3, [r0], #1
794
	cmp	r3, #0
795
	moveq	pc, lr
796
	adr	r6, font
797
	sub	r3, r3, #0x20
798
	cmp	r3, #0x5f
799
	addcc	r6, r3,lsl#2
800
	addcc	r6, r3
801
	mov	r3, #5
802
rendertext_col:
803
	mov	r7, r1
804
	ldrb	r9, [r6], #1
805
rendertext_row:
806
	tst	r9, #1
807
	strneh	r2, [r7]
808
	add	r7, r7, #640
809
	movs	r9, r9,lsr#1
810
	bne	rendertext_row
811
	add	r1, r1, #2
812
	subs	r3, r3, #1
813
	bne	rendertext_col
814
	add	r1, r1, #2
815
	b	rendertext
816
 
817
spisend:
818
	mov	r6, #1
819
	str	r6, [r7,#0x34]
820
spisend_wait:
821
	ldr	r6, [r7,#0x8]
822
	and	r6, r6, #0x1f0
823
	cmp	r6, #0x100
824
	beq	spisend_wait
825
	str	r0, [r7,#0x10]
826
spisend_wait2:
827
	ldr	r6, [r7,#0x8]
828
	ands	r6, r6, #0x3e00
829
	beq	spisend_wait2
830
	ldr	r0, [r7,#0x20]
831
	mov	pc, lr
832
 
833
spirecv:
834
	str	r0, [r7,#0x34]
835
	ldr	r6, [r7,#0x4]
836
	orr	r6, r6, #1
837
	str	r6, [r7,#0x4]
838
spirecv_loop:
839
	ldr	r6, [r7,#0x8]
840
	ands	r6, r6, #0x3e00
841
	beq	spirecv_loop
842
	ldr	r6, [r7,#0x20]
843
	strb	r6, [r1], #1
844
	subs	r0, r0, #1
845
	bne	spirecv_loop
846
	ldr	r6, [r7,#0x4]
847
	bic	r6, r6, #1
848
	str	r6, [r7,#0x4]
849
	mov	pc, lr
850
 
851
bootflash_read:
852
	mov	sp, lr
853
bootflash_wait:
854
	ldr	r0, [r3,#0x4]
855
	bic	r0, r0, #1
856
	str	r0, [r3,#0x4]
857
	mov	r0, #5
858
	bl	spisend
859
	mov	r0, #0xff
860
	bl	spisend
861
	tst	r0, #1
862
	ldr	r0, [r3,#0x4]
863
	orr	r0, r0, #1
864
	str	r0, [r3,#0x4]
865
	bne	bootflash_wait
866
	ldr	r0, [r3,#0x4]
867
	bic	r0, r0, #1
868
	str	r0, [r3,#0x4]
869
	mov	r0, #3
870
	bl	spisend
871
	mov	r0, r11,lsr#16
872
	bl	spisend
873
	mov	r0, r11,lsr#8
874
	and	r0, r0, #0xff
875
	bl	spisend
876
	and	r0, r11, #0xff
877
	bl	spisend
878
	mov	r0, r12
879
	bl	spirecv
880
	ldr	r0, [r3,#0x4]
881
	orr	r0, r0, #1
882
	str	r0, [r3,#0x4]
883
	mov	pc, sp
884
 
885
lcdbyteseq:
886
	mov	r9, r0,lsr#8
887
	and	r0, r0, #0xff
888
	bl	sendlcdc
889
lcdbyteseqloop:
890
	ldrb	r0, [sp], #1
891
	bl	sendlcdd
892
	subs	r9, r9, #1
893
	bne	lcdbyteseqloop
894
	b	lcdloop
895
 
896
sendlcdc:
897
	ldr	r6, [r4,#0x1c]
898
	ands	r6, r6, #0x10
899
	bne	sendlcdc
900
	str	r0, [r4,#0x04]
901
	mov	pc, lr
902
 
903
sendlcdd:
904
	ldr	r6, [r4,#0x1c]
905
	ands	r6, r6, #0x10
906
	bne	sendlcdd
907
	str	r0, [r4,#0x40]
908
	mov	pc, lr
909
 
910
i2cwaitrdy:
911
	ldr	r6, [r5,#0x10]
912
	cmp	r6, #0
913
	bne	i2cwaitrdy
914
	mov	pc, lr
915
 
916
i2cwait:
917
	ldr	r6, [r5]
918
	tst	r6, #0x10
919
	beq	i2cwait
920
	mov	pc, lr
921
 
922
pmutransfer:
923
	mov	r7, lr
924
	mov	lr, #0xb7
925
	str	lr, [r5]
926
	mov	lr, #0xe6
927
	str	lr, [r5,#0xc]
928
	mov	lr, #0xf0
929
	str	lr, [r5,#0x4]
930
	bl	i2cwait
931
	str	r3, [r5,#0xc]
932
	mov	lr, #0xb7
933
	str	lr, [r5]
934
	bl	i2cwait
935
	cmn	r4, #1
936
	beq	pmuskip
937
	str	r4, [r5,#0xc]
938
	mov	lr, #0xb7
939
	str	lr, [r5]
940
	bl	i2cwait
941
	mov	lr, #0xd0
942
	b	pmudone
943
pmuskip:
944
	mov	lr, #0xe7
945
	str	lr, [r5,#0xc]
946
	mov	lr, #0xb0
947
	str	lr, [r5,#0x4]
948
	mov	lr, #0xb7
949
	str	lr, [r5]
950
	bl	i2cwait
951
	mov	lr, #0x37
952
	str	lr, [r5]
953
	bl	i2cwait
954
	ldr	r3, [r5,#0xc]
955
	mov	lr, #0x90
956
pmudone:
957
	str	lr, [r5,#0x4]
958
	mov	lr, #0xb7
959
	str	lr, [r5]
960
pmuwait:
961
	ldr	lr, [r5,#0x4]
962
	tst	lr, #0x20
963
	bne	pmuwait
964
	mov	pc, r7
965
 
966
udelay:
967
	ldr	r6, [r1,#0xb4]
968
	add	r0, r0, r6
969
udelayloop:
970
	ldr	r6, [r1,#0xb4]
971
	cmp	r6, r0
972
	bmi	udelayloop
973
	mov	pc, lr
974
 
975
 
976
pwrok:
977
	sub	r7, r5, #0x04500000  @ R7 = MIUBASE (temporary)
978
	cmp	r0, #0
979
	moveq	r6, #0x11
980
	streq	r6, [r7]
981
	str	r8, [r7]
982
	str	r2, [r7,#0xf0]
983
	str	r9, [r7,#0x8]
984
	str	r10, [r7,#0x10]
985
	mov	r8, #0x1800
986
	orr	r6, r8, #0x45
987
	str	r6, [r7,#0x200]
988
	str	r6, [r7,#0x204]
989
	str	r8, [r7,#0x210]
990
	str	r8, [r7,#0x214]
991
	str	r6, [r7,#0x220]
992
	str	r6, [r7,#0x224]
993
	add	r6, r6, #0x40
994
	str	r6, [r7,#0x230]
995
	str	r6, [r7,#0x234]
996
	mov	r6, #0x19
997
	str	r6, [r7,#0x14]
998
	str	r6, [r7,#0x18]
999
	str	r11, [r7,#0x1c]
1000
	ldr	r6, [r7,#0x314]
1001
	bic	r6, r6, #0x10
1002
	str	r6, [r7,#0x314]
1003
	add	r8, r7, #0x2c
1004
	mov	r9, #0x24
1005
sdramloop:
1006
	ldr	r6, [r8]
1007
	bic	r6, r6, #0x01000000
1008
	str	r6, [r8], #4
1009
	subs	r9, r9, #1
1010
	bne	sdramloop
1011
	mov	r6, #0x540
1012
	str	r6, [r7,#0x1cc]
1013
	ldr	r6, [r7,#0x1d4]
1014
	orr	r6, r6, #0x80
1015
	str	r6, [r7,#0x1d4]
1016
	mov	r6, #0x33
1017
	str	r6, [r7,#0x4]
1018
	str	r6, [r7,#0x4]
1019
	orr	r8, r6, #0x200
1020
	str	r8, [r7,#0x4]
1021
	str	r6, [r7,#0x4]
1022
	str	r6, [r7,#0x4]
1023
	str	r6, [r7,#0x4]
1024
	orr	r8, r8, #0x100
1025
	str	r8, [r7,#0x4]
1026
	str	r6, [r7,#0x4]
1027
	str	r6, [r7,#0x4]
1028
	str	r6, [r7,#0x4]
1029
	str	r8, [r7,#0x4]
1030
	str	r6, [r7,#0x4]
1031
	str	r6, [r7,#0x4]
1032
	str	r6, [r7,#0x4]
1033
	cmp	r0, #0
1034
	strne	r6, [r7,#0xc]
1035
	bicne	r8, r8, #0x200
1036
	strne	r8, [r7,#0x4]
1037
	strne	r6, [r7,#0x4]
1038
	strne	r6, [r7,#0x4]
1039
	strne	r6, [r7,#0x4]
1040
	strne	r12, [r7,#0xc]
1041
	strne	r8, [r7,#0x4]
1042
	strne	r6, [r7,#0x4]
1043
	strne	r6, [r7,#0x4]
1044
	strne	r6, [r7,#0x4]
1045
	ldr	r6, [r7,#0x8]
1046
	orr	r6, r6, #0x61000
1047
	str	r6, [r7,#0x8]
1048
	orr	r3, r1, #0x00800000  @ R3 = GPIOBASE
1049
	sub	r4, r1, #0x04400000  @ R4 = LCDBASE
1050
	ldr	r0, [r3,#0xc4]
1051
	and	r8, r0, #0x30        @ R8 = LCD type GPIO bits << 4
1052
	add	sp, sp, r8,lsr#3
1053
	ldrh	r0, [sp]
1054
	add	sp, sp, r0
1055
	ldr	r0, val_80100db0
1056
	str	r0, [r4]
1057
	mov	r0, #0x33
1058
	str	r0, [r4,#0x20]
1059
lcdloop:
1060
	adr	lr, lcdloop
1061
	ldrb	r6, [sp], #1
1062
	ldrb	r7, [sp], #1
1063
	orr	r6, r6, r7,lsl#8
1064
	mov	r7, r6,lsr#14
1065
	bics	r0, r6, #0xc000
1066
	add	pc, pc, r7,lsl#2
1067
val_80100db0:
1068
	.word 0x80100db0
1069
	b	sendlcdd
1070
	b	sendlcdc
1071
	bne	lcdbyteseq
1072
	movne	r0, r0,lsl#4
1073
	bne	udelay
1074
	mov	r10, #0x22000000
1075
	orr	r10, r10, #0x10000
1076
	add	r11, r10, #0x25800
1077
	mov	r0, #-1
1078
fillbuff:
1079
	str	r0, [r11,#-4]!
1080
	cmp	r10, r11
1081
	bne	fillbuff
1082
	mov	r1, r11
1083
	adr	r0, text
1084
	bl	rendertext
1085
	add	r1, r11, #0x2800
1086
printerror:
1087
	bl	rendertext
1088
	bl	flushcache
1089
	cmp	r8, #0x30
1090
	bne	leadisprotocol
1091
	mov	r9, #0x200
1092
	add	r0, r9, #0x10
1093
	bl	sendlcdc
1094
	mov	r0, #0
1095
	bl	sendlcdd
1096
	add	r0, r9, #0x11
1097
	bl	sendlcdc
1098
	sub	r0, r9, #0xc1
1099
	bl	sendlcdd
1100
	add	r0, r9, #0x12
1101
	bl	sendlcdc
1102
	mov	r0, #0
1103
	bl	sendlcdd
1104
	add	r0, r9, #0x13
1105
	bl	sendlcdc
1106
	mov	r0, #0xef
1107
	bl	sendlcdd
1108
	mov	r0, r9
1109
	bl	sendlcdc
1110
	mov	r0, #0
1111
	bl	sendlcdd
1112
	add	r0, r9, #1
1113
	bl	sendlcdc
1114
	mov	r0, #0
1115
	bl	sendlcdd
1116
	add	r0, r9, #2
1117
	bl	sendlcdc
1118
	b	blit
1119
leadisprotocol:
1120
	mov	r0, #0x2a
1121
	bl	sendlcdc
1122
	mov	r0, #0
1123
	bl	sendlcdd
1124
	mov	r0, #0
1125
	bl	sendlcdd
1126
	mov	r0, #1
1127
	bl	sendlcdd
1128
	mov	r0, #0x3f
1129
	bl	sendlcdd
1130
	mov	r0, #0x2b
1131
	bl	sendlcdc
1132
	mov	r0, #0
1133
	bl	sendlcdd
1134
	mov	r0, #0
1135
	bl	sendlcdd
1136
	mov	r0, #0
1137
	bl	sendlcdd
1138
	mov	r0, #0xef
1139
	bl	sendlcdd
1140
	mov	r0, #0x2c
1141
	bl	sendlcdc
1142
blit:
1143
	sub	r7, r4, #0x00100000  @ R7 = DMA0BASE (temporary)
1144
	mov	r0, #1
1145
	str	r0, [r7,#0x30]
1146
	mov	r0, #0x22000000
1147
	orr	r0, r0, #0x3d000
1148
	add	r1, r7, #0x100
1149
	mov	r13, #0x8800
1150
	orr	r13, r13, #0xc1
1151
	ldmia	r0, {r9-r12}
1152
	stmia	r1, {r9-r13}
1153
	tst	r5, #0xff
1154
failed:
1155
	bne	failed
1156
	mov	r3, #0x2b
1157
	mov	r4, #4
1158
	bl	pmutransfer
1159
	mov	r3, #0x28
1160
	mov	r4, #14
1161
	bl	pmutransfer
1162
	mov	r3, #0x29
1163
	mov	r4, #1
1164
	bl	pmutransfer
1165
	sub	r7, r5, #0x00300000  @ R7 = SPIBASE
1166
	orr	r3, r5, #0x00900000  @ R3 = GPIOBASE
1167
	mov	r0, #0xf
1168
	str	r0, [r7,#0x8]
1169
	ldr	r0, [r7]
1170
	orr	r0, r0, #0xc
1171
	str	r0, [r7]
1172
	mov	r0, #4
1173
	str	r0, [r7,#0x30]
1174
	mov	r0, #6
1175
	str	r0, [r7,#0xc]
1176
	ldr	r0, val_00010618
1177
	str	r0, [r7,#0x4]
1178
	ldr	r0, [r7]
1179
	orr	r0, r0, #0xc
1180
	str	r0, [r7]
1181
	mov	r0, #1
1182
	str	r0, [r7]
1183
    	sub	r1, r9, #0x1000
1184
	mov	r11, #0
1185
	mov	r12, #0x1000
1186
	bl	bootflash_read
1187
    	sub	r11, r9, #0x1000
1188
	ldrd	r4, bootfilename
1189
searchfile:
1190
	ldrd	r12, [r11]
1191
	cmp	r4, r12
1192
	cmpeq	r5, r13
1193
	beq	foundfile
1194
	add	r11, r11, #0x10
1195
	tst	r11, #0x10000
1196
	beq	searchfile
1197
	adr	r0, errormessage
1198
	sub	r4, r3, #0x04c00000  @ R4 = LCDBASE
1199
	mov	r1, #0x22000000
1200
	orr	r1, r1, #0x13c00
1201
	b	printerror
1202
 
1203
val_00010618:
1204
	.word 0x00010618
1205
 
1206
bootfilename:
1207
	.ascii "embios  "
1208
 
1209
text:
1210
	.ascii "emBIOS Loader v"
1211
	.ascii VERSION
1212
	.ascii " r"
1213
	.ascii VERSION_SVN
1214
	.ascii "\0"
1215
	.ascii "Loading emBIOS...\0"
1216
 
1217
errormessage:
1218
	.ascii "File not found!\0"