Subversion Repositories freemyipod

Rev

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
378 theseven 446
	.hword 0xc000
273 theseven 447
lcddata_2:
448
lcddata_3:
419 theseven 449
	.hword 0xc010
273 theseven 450
	.hword 0x4008
451
	.hword 0x0808
452
	.hword 0x8110
453
	.byte 0x13
454
	.hword 0x4011
455
	.hword 0x0300
456
	.hword 0x4012
457
	.hword 0x0101
458
	.hword 0x4013
459
	.hword 0x0a03
460
	.hword 0x4014
461
	.hword 0x0a0e
462
	.hword 0x4015
463
	.hword 0x0a19
464
	.hword 0x4016
465
	.hword 0x2402
466
	.hword 0x8118
467
	.byte 0x01
468
	.hword 0x8190
469
	.byte 0x21
470
	.hword 0x4300
378 theseven 471
	.hword 0x0307
273 theseven 472
	.hword 0x4301
378 theseven 473
	.hword 0x0003
474
	.hword 0x4302
273 theseven 475
	.hword 0x0402
476
	.hword 0x4303
477
	.hword 0x0303
478
	.hword 0x4304
378 theseven 479
	.hword 0x0300
273 theseven 480
	.hword 0x4305
378 theseven 481
	.hword 0x0407
273 theseven 482
	.hword 0x4306
378 theseven 483
	.hword 0x1c04
273 theseven 484
	.hword 0x4307
378 theseven 485
	.hword 0x0307
273 theseven 486
	.hword 0x4308
378 theseven 487
	.hword 0x0003
488
	.hword 0x4309
273 theseven 489
	.hword 0x0402
490
	.hword 0x430a
491
	.hword 0x0303
492
	.hword 0x430b
378 theseven 493
	.hword 0x0300
273 theseven 494
	.hword 0x430c
378 theseven 495
	.hword 0x0407
273 theseven 496
	.hword 0x430d
378 theseven 497
	.hword 0x1c04
273 theseven 498
	.hword 0x4310
378 theseven 499
	.hword 0x0707
273 theseven 500
	.hword 0x4311
378 theseven 501
	.hword 0x0407
273 theseven 502
	.hword 0x4312
378 theseven 503
	.hword 0x0306
273 theseven 504
	.hword 0x4313
505
	.hword 0x0303
506
	.hword 0x4314
378 theseven 507
	.hword 0x0300
273 theseven 508
	.hword 0x4315
378 theseven 509
	.hword 0x0407
273 theseven 510
	.hword 0x4316
378 theseven 511
	.hword 0x1c01
273 theseven 512
	.hword 0x4317
378 theseven 513
	.hword 0x0707
273 theseven 514
	.hword 0x4318
378 theseven 515
	.hword 0x0407
273 theseven 516
	.hword 0x4319
378 theseven 517
	.hword 0x0306
273 theseven 518
	.hword 0x431a
519
	.hword 0x0303
520
	.hword 0x431b
378 theseven 521
	.hword 0x0300
273 theseven 522
	.hword 0x431c
378 theseven 523
	.hword 0x0407
273 theseven 524
	.hword 0x431d
378 theseven 525
	.hword 0x1c01
273 theseven 526
	.hword 0x4320
378 theseven 527
	.hword 0x0206
273 theseven 528
	.hword 0x4321
378 theseven 529
	.hword 0x0102
273 theseven 530
	.hword 0x4322
378 theseven 531
	.hword 0x0404
273 theseven 532
	.hword 0x4323
533
	.hword 0x0303
534
	.hword 0x4324
535
	.hword 0x0300
536
	.hword 0x4325
378 theseven 537
	.hword 0x0407
273 theseven 538
	.hword 0x4326
378 theseven 539
	.hword 0x1c1f
273 theseven 540
	.hword 0x4327
378 theseven 541
	.hword 0x0206
273 theseven 542
	.hword 0x4328
378 theseven 543
	.hword 0x0102
273 theseven 544
	.hword 0x4329
378 theseven 545
	.hword 0x0404
273 theseven 546
	.hword 0x432a
547
	.hword 0x0303
548
	.hword 0x432b
549
	.hword 0x0300
550
	.hword 0x432c
378 theseven 551
	.hword 0x0407
273 theseven 552
	.hword 0x432d
378 theseven 553
	.hword 0x1c1f
273 theseven 554
	.hword 0x4400
555
	.hword 0x001d
556
	.hword 0x4401
557
	.hword 0x0001
558
	.hword 0x4205
559
	.hword 0x0060
560
	.hword 0x8107
561
	.byte 0x01
562
	.hword 0x8131
563
	.byte 0x71
564
	.hword 0x4110
565
	.hword 0x0001
566
	.hword 0x4100
567
	.hword 0x17b0
568
	.hword 0x4101
569
	.hword 0x0220
570
	.hword 0x4102
378 theseven 571
	.hword 0x00bd
273 theseven 572
	.hword 0x4103
378 theseven 573
	.hword 0x1500
273 theseven 574
	.hword 0x4105
575
	.hword 0x0103
576
	.hword 0x4106
577
	.hword 0x0105
578
	.hword 0x8107
579
	.byte 0x21
580
	.hword 0x4102
581
	.hword 0x00bd
582
	.hword 0x4001
583
	.hword 0x0110
584
	.hword 0x4003
585
	.hword 0x0230
586
	.hword 0x4002
587
	.hword 0x0500
588
	.hword 0x8107
589
	.byte 0x31
378 theseven 590
	.hword 0x8130
273 theseven 591
	.byte 0x07
592
	.hword 0xc744
593
	.hword 0x4030
594
	.hword 0x03ff
595
	.hword 0xce88
596
	.hword 0x8107
597
	.byte 0x72
598
	.hword 0xe454
599
	.hword 0x4007
600
	.hword 0x0173
601
	.hword 0xc000
602
 
419 theseven 603
	.code 16
604
 
605
thumb_nrv2e_d8:
606
	mov r7,r2
607
        mov r4,#1; neg r5,r4 @ r5= -1 initial condition
608
        lsl r4,#31 @ 1<<31: refill next time
609
        mov r6,#5
610
        lsl r6,#8 @ 0x500 @ nrv2e M2_MAX_OFFSET
611
        b top_n2e
612
 
613
nrv2e_done:
614
	blx flushcache
615
	bx r7
616
 
617
get1_n2e: @ In: Carry set [from adding 0x80000000 (1<<31) to itself]
618
        ldrb r4,[r0] @ zero-extend next byte
619
        adc r4,r4 @ double and insert CarryIn as low bit
620
        add r0,#1
621
        lsl r4,#24 @ move to top byte, and set CarryOut from old bit 8
622
        mov pc,lr @ return, stay in current (THUMB) mode
623
 
624
lit_n2e:
625
        ldrb r3,[r0]; add r0,#1
626
        strb r3,[r2]; add r2,#1
627
top_n2e:
628
        add r4,r4; mov lr,pc; beq get1_n2e; bcs lit_n2e
629
        mov r1,#1; b getoff_n2e
630
 
631
off_n2e:
632
        sub r1,#1
633
        add r4,r4; mov lr,pc; beq get1_n2e; adc r1,r1
634
getoff_n2e:
635
        add r4,r4; mov lr,pc; beq get1_n2e; adc r1,r1
636
        add r4,r4; mov lr,pc; beq get1_n2e; bcc off_n2e
637
 
638
        sub r3,r1,#3 @ set Carry
639
        mov r1,#0 @ Carry unaffected
640
        blo offprev_n2e @ r1 was 2; tests Carry only
641
        lsl r3,#8
642
        ldrb r5,[r0]; add r0,#1 @ low 7+1 r4
643
        orr r5,r3
644
        mvn r5,r5; beq nrv2e_done @ r5= ~r5
645
        asr r5,#1; bcs lenlast_n2e
646
        b lenmore_n2e
647
 
648
offprev_n2e:
649
        add r4,r4; mov lr,pc; beq get1_n2e; bcs lenlast_n2e
650
lenmore_n2e:
651
        mov r1,#1
652
        add r4,r4; mov lr,pc; beq get1_n2e; bcs lenlast_n2e
653
len_n2e:
654
        add r4,r4; mov lr,pc; beq get1_n2e; adc r1,r1
655
        add r4,r4; mov lr,pc; beq get1_n2e; bcc len_n2e
656
        add r1,#6-2
657
        b gotlen_n2e
658
 
659
lenlast_n2e:
660
        add r4,r4; mov lr,pc; beq get1_n2e; adc r1,r1 @ 0,1,2,3
661
        add r1,#2
662
gotlen_n2e: @ 'cmn': add the inputs, set condition codes, discard the sum
663
        cmn r6,r5; bcs near_n2e @ within M2_MAX_OFFSET
664
        add r1,#1 @ too far away, so minimum match length is 3
665
near_n2e:
666
        ldrb r3,[r2] @ force cacheline allocate
667
copy_n2e:
668
        ldrb r3,[r2,r5]
669
        strb r3,[r2]; add r2,#1
670
        sub r1,#1; bne copy_n2e
671
        b top_n2e
672
 
673
	.code 32
674
 
273 theseven 675
font:
676
	.byte 0, 0, 0, 0, 0
677
	.byte 0, 0, 95, 0, 0
678
	.byte 0, 7, 0, 7, 0
679
	.byte 20, 127, 20, 127, 20
680
	.byte 36, 42, 127, 42, 18
681
	.byte 35, 19, 8, 100, 98
682
	.byte 54, 73, 85, 34, 80
683
	.byte 5, 3, 0, 0, 0
684
	.byte 28, 34, 65, 0, 0
685
	.byte 0, 0, 65, 34, 28
686
	.byte 20, 8, 62, 8, 20
687
	.byte 8, 8, 62, 8, 8
688
	.byte 0, -96, 96, 0, 0
689
	.byte 8, 8, 8, 8, 8
690
	.byte 0, 96, 96, 0, 0
691
	.byte 32, 16, 8, 4, 2
692
	.byte 62, 81, 73, 69, 62
693
	.byte 0, 66, 127, 64, 0
694
	.byte 66, 97, 81, 73, 70
695
	.byte 33, 65, 69, 75, 49
696
	.byte 24, 20, 18, 127, 16
697
	.byte 39, 69, 69, 69, 57
698
	.byte 60, 74, 73, 73, 48
699
	.byte 1, 113, 9, 5, 3
700
	.byte 54, 73, 73, 73, 54
701
	.byte 6, 73, 73, 41, 30
702
	.byte 0, 54, 54, 0, 0
703
	.byte 0, 86, 54, 0, 0
704
	.byte 8, 20, 34, 65, 0
705
	.byte 20, 20, 20, 20, 20
706
	.byte 0, 65, 34, 20, 8
707
	.byte 2, 1, 81, 9, 6
708
	.byte 50, 73, 121, 65, 62
709
	.byte 124, 18, 17, 18, 124
710
	.byte 127, 73, 73, 73, 62
711
	.byte 62, 65, 65, 65, 34
712
	.byte 127, 65, 65, 34, 28
713
	.byte 127, 73, 73, 73, 65
714
	.byte 127, 9, 9, 9, 1
715
	.byte 62, 65, 73, 73, 58
716
	.byte 127, 8, 8, 8, 127
717
	.byte 0, 65, 127, 65, 0
718
	.byte 32, 64, 65, 63, 1
719
	.byte 127, 8, 20, 34, 65
720
	.byte 127, 64, 64, 64, 64
721
	.byte 127, 2, 12, 2, 127
722
	.byte 127, 4, 8, 16, 127
723
	.byte 62, 65, 65, 65, 62
724
	.byte 127, 9, 9, 9, 6
725
	.byte 62, 65, 81, 33, 94
726
	.byte 127, 9, 25, 41, 70
727
	.byte 38, 73, 73, 73, 50
728
	.byte 1, 1, 127, 1, 1
729
	.byte 63, 64, 64, 64, 63
730
	.byte 31, 32, 64, 32, 31
731
	.byte 127, 32, 24, 32, 127
732
	.byte 99, 20, 8, 20, 99
733
	.byte 3, 4, 120, 4, 3
734
	.byte 97, 81, 73, 69, 67
735
	.byte 0, 127, 65, 65, 0
736
	.byte 2, 4, 8, 16, 32
737
	.byte 0, 65, 65, 127, 0
738
	.byte 4, 2, 1, 2, 4
739
	.byte 64, 64, 64, 64, 64
740
	.byte 1, 2, 4, 0, 0
741
	.byte 32, 84, 84, 84, 120
742
	.byte 127, 68, 68, 68, 56
743
	.byte 56, 68, 68, 68, 40
744
	.byte 56, 68, 68, 68, 127
745
	.byte 56, 84, 84, 84, 24
746
	.byte 8, 126, 9, 1, 2
747
	.byte 8, 84, 84, 84, 60
748
	.byte 127, 4, 4, 4, 120
749
	.byte 0, 68, 125, 64, 0
750
	.byte 32, 64, 64, 61, 0
751
	.byte 127, 16, 40, 68, 0
752
	.byte 0, 65, 127, 64, 0
753
	.byte 124, 4, 24, 4, 120
754
	.byte 124, 8, 4, 4, 120
755
	.byte 56, 68, 68, 68, 56
756
	.byte 124, 20, 20, 20, 24
757
	.byte 8, 20, 20, 20, 124
758
	.byte 124, 8, 4, 4, 8
759
	.byte 72, 84, 84, 84, 32
760
	.byte 4, 63, 68, 64, 32
761
	.byte 60, 64, 64, 32, 124
762
	.byte 28, 32, 64, 32, 28
763
	.byte 60, 64, 56, 64, 60
764
	.byte 68, 40, 16, 40, 68
765
	.byte 12, 80, 80, 80, 60
766
	.byte 68, 100, 84, 76, 68
767
	.byte 0, 8, 54, 65, 0
768
	.byte 0, 0, 119, 0, 0
769
	.byte 0, 65, 54, 8, 0
770
	.byte 2, 1, 2, 4, 2
771
 
772
	.align 2
773
 
774
foundfile:
775
	ldr	r12, [r11,#0xc]
776
	ldr	r11, [r11,#0x8]
777
	tst	r12, #0x80000000
778
	bic	r12, r12, #0xff000000
779
	bic	r12, r12, #0xf00000
780
	bne	compressed
781
    	mov	r1, #0x08000000
782
	bl	bootflash_read
783
	mov	lr, #0x08000000
784
	b	flushcache
785
compressed:
786
    	mov	r1, #0x09000000
787
	bl	bootflash_read
788
	mov	r0, #0x09000000
789
	mov	r2, #0x08000000
790
	blx	thumb_nrv2e_d8
791
 
792
 
793
rendertext:
794
	ldrb	r3, [r0], #1
795
	cmp	r3, #0
796
	moveq	pc, lr
797
	adr	r6, font
798
	sub	r3, r3, #0x20
799
	cmp	r3, #0x5f
800
	addcc	r6, r3,lsl#2
801
	addcc	r6, r3
802
	mov	r3, #5
803
rendertext_col:
804
	mov	r7, r1
805
	ldrb	r9, [r6], #1
806
rendertext_row:
807
	tst	r9, #1
808
	strneh	r2, [r7]
809
	add	r7, r7, #640
810
	movs	r9, r9,lsr#1
811
	bne	rendertext_row
812
	add	r1, r1, #2
813
	subs	r3, r3, #1
814
	bne	rendertext_col
815
	add	r1, r1, #2
816
	b	rendertext
817
 
818
spisend:
819
	mov	r6, #1
820
	str	r6, [r7,#0x34]
821
spisend_wait:
822
	ldr	r6, [r7,#0x8]
823
	and	r6, r6, #0x1f0
824
	cmp	r6, #0x100
825
	beq	spisend_wait
826
	str	r0, [r7,#0x10]
827
spisend_wait2:
828
	ldr	r6, [r7,#0x8]
829
	ands	r6, r6, #0x3e00
830
	beq	spisend_wait2
831
	ldr	r0, [r7,#0x20]
832
	mov	pc, lr
833
 
834
spirecv:
835
	str	r0, [r7,#0x34]
836
	ldr	r6, [r7,#0x4]
837
	orr	r6, r6, #1
838
	str	r6, [r7,#0x4]
839
spirecv_loop:
840
	ldr	r6, [r7,#0x8]
841
	ands	r6, r6, #0x3e00
842
	beq	spirecv_loop
843
	ldr	r6, [r7,#0x20]
844
	strb	r6, [r1], #1
845
	subs	r0, r0, #1
846
	bne	spirecv_loop
847
	ldr	r6, [r7,#0x4]
848
	bic	r6, r6, #1
849
	str	r6, [r7,#0x4]
850
	mov	pc, lr
851
 
852
bootflash_read:
853
	mov	sp, lr
854
bootflash_wait:
855
	ldr	r0, [r3,#0x4]
856
	bic	r0, r0, #1
857
	str	r0, [r3,#0x4]
858
	mov	r0, #5
859
	bl	spisend
860
	mov	r0, #0xff
861
	bl	spisend
862
	tst	r0, #1
863
	ldr	r0, [r3,#0x4]
864
	orr	r0, r0, #1
865
	str	r0, [r3,#0x4]
866
	bne	bootflash_wait
867
	ldr	r0, [r3,#0x4]
868
	bic	r0, r0, #1
869
	str	r0, [r3,#0x4]
870
	mov	r0, #3
871
	bl	spisend
872
	mov	r0, r11,lsr#16
873
	bl	spisend
874
	mov	r0, r11,lsr#8
875
	and	r0, r0, #0xff
876
	bl	spisend
877
	and	r0, r11, #0xff
878
	bl	spisend
879
	mov	r0, r12
880
	bl	spirecv
881
	ldr	r0, [r3,#0x4]
882
	orr	r0, r0, #1
883
	str	r0, [r3,#0x4]
884
	mov	pc, sp
885
 
886
lcdbyteseq:
887
	mov	r9, r0,lsr#8
888
	and	r0, r0, #0xff
889
	bl	sendlcdc
890
lcdbyteseqloop:
891
	ldrb	r0, [sp], #1
892
	bl	sendlcdd
893
	subs	r9, r9, #1
894
	bne	lcdbyteseqloop
895
	b	lcdloop
896
 
897
sendlcdc:
898
	ldr	r6, [r4,#0x1c]
899
	ands	r6, r6, #0x10
900
	bne	sendlcdc
901
	str	r0, [r4,#0x04]
902
	mov	pc, lr
903
 
904
sendlcdd:
905
	ldr	r6, [r4,#0x1c]
906
	ands	r6, r6, #0x10
907
	bne	sendlcdd
908
	str	r0, [r4,#0x40]
909
	mov	pc, lr
910
 
911
i2cwaitrdy:
912
	ldr	r6, [r5,#0x10]
913
	cmp	r6, #0
914
	bne	i2cwaitrdy
915
	mov	pc, lr
916
 
917
i2cwait:
918
	ldr	r6, [r5]
919
	tst	r6, #0x10
920
	beq	i2cwait
921
	mov	pc, lr
922
 
923
pmutransfer:
924
	mov	r7, lr
925
	mov	lr, #0xb7
926
	str	lr, [r5]
927
	mov	lr, #0xe6
928
	str	lr, [r5,#0xc]
929
	mov	lr, #0xf0
930
	str	lr, [r5,#0x4]
931
	bl	i2cwait
932
	str	r3, [r5,#0xc]
933
	mov	lr, #0xb7
934
	str	lr, [r5]
935
	bl	i2cwait
936
	cmn	r4, #1
937
	beq	pmuskip
938
	str	r4, [r5,#0xc]
939
	mov	lr, #0xb7
940
	str	lr, [r5]
941
	bl	i2cwait
942
	mov	lr, #0xd0
943
	b	pmudone
944
pmuskip:
945
	mov	lr, #0xe7
946
	str	lr, [r5,#0xc]
947
	mov	lr, #0xb0
948
	str	lr, [r5,#0x4]
949
	mov	lr, #0xb7
950
	str	lr, [r5]
951
	bl	i2cwait
952
	mov	lr, #0x37
953
	str	lr, [r5]
954
	bl	i2cwait
955
	ldr	r3, [r5,#0xc]
956
	mov	lr, #0x90
957
pmudone:
958
	str	lr, [r5,#0x4]
959
	mov	lr, #0xb7
960
	str	lr, [r5]
961
pmuwait:
962
	ldr	lr, [r5,#0x4]
963
	tst	lr, #0x20
964
	bne	pmuwait
965
	mov	pc, r7
966
 
967
udelay:
968
	ldr	r6, [r1,#0xb4]
969
	add	r0, r0, r6
970
udelayloop:
971
	ldr	r6, [r1,#0xb4]
972
	cmp	r6, r0
973
	bmi	udelayloop
974
	mov	pc, lr
975
 
976
 
977
pwrok:
978
	sub	r7, r5, #0x04500000  @ R7 = MIUBASE (temporary)
979
	cmp	r0, #0
980
	moveq	r6, #0x11
981
	streq	r6, [r7]
982
	str	r8, [r7]
983
	str	r2, [r7,#0xf0]
984
	str	r9, [r7,#0x8]
985
	str	r10, [r7,#0x10]
986
	mov	r8, #0x1800
987
	orr	r6, r8, #0x45
988
	str	r6, [r7,#0x200]
989
	str	r6, [r7,#0x204]
990
	str	r8, [r7,#0x210]
991
	str	r8, [r7,#0x214]
992
	str	r6, [r7,#0x220]
993
	str	r6, [r7,#0x224]
994
	add	r6, r6, #0x40
995
	str	r6, [r7,#0x230]
996
	str	r6, [r7,#0x234]
997
	mov	r6, #0x19
998
	str	r6, [r7,#0x14]
999
	str	r6, [r7,#0x18]
1000
	str	r11, [r7,#0x1c]
1001
	ldr	r6, [r7,#0x314]
1002
	bic	r6, r6, #0x10
1003
	str	r6, [r7,#0x314]
1004
	add	r8, r7, #0x2c
1005
	mov	r9, #0x24
1006
sdramloop:
1007
	ldr	r6, [r8]
1008
	bic	r6, r6, #0x01000000
1009
	str	r6, [r8], #4
1010
	subs	r9, r9, #1
1011
	bne	sdramloop
1012
	mov	r6, #0x540
1013
	str	r6, [r7,#0x1cc]
1014
	ldr	r6, [r7,#0x1d4]
1015
	orr	r6, r6, #0x80
1016
	str	r6, [r7,#0x1d4]
1017
	mov	r6, #0x33
1018
	str	r6, [r7,#0x4]
1019
	str	r6, [r7,#0x4]
1020
	orr	r8, r6, #0x200
1021
	str	r8, [r7,#0x4]
1022
	str	r6, [r7,#0x4]
1023
	str	r6, [r7,#0x4]
1024
	str	r6, [r7,#0x4]
1025
	orr	r8, r8, #0x100
1026
	str	r8, [r7,#0x4]
1027
	str	r6, [r7,#0x4]
1028
	str	r6, [r7,#0x4]
1029
	str	r6, [r7,#0x4]
1030
	str	r8, [r7,#0x4]
1031
	str	r6, [r7,#0x4]
1032
	str	r6, [r7,#0x4]
1033
	str	r6, [r7,#0x4]
1034
	cmp	r0, #0
1035
	strne	r6, [r7,#0xc]
1036
	bicne	r8, r8, #0x200
1037
	strne	r8, [r7,#0x4]
1038
	strne	r6, [r7,#0x4]
1039
	strne	r6, [r7,#0x4]
1040
	strne	r6, [r7,#0x4]
1041
	strne	r12, [r7,#0xc]
1042
	strne	r8, [r7,#0x4]
1043
	strne	r6, [r7,#0x4]
1044
	strne	r6, [r7,#0x4]
1045
	strne	r6, [r7,#0x4]
1046
	ldr	r6, [r7,#0x8]
1047
	orr	r6, r6, #0x61000
1048
	str	r6, [r7,#0x8]
1049
	orr	r3, r1, #0x00800000  @ R3 = GPIOBASE
1050
	sub	r4, r1, #0x04400000  @ R4 = LCDBASE
1051
	ldr	r0, [r3,#0xc4]
1052
	and	r8, r0, #0x30        @ R8 = LCD type GPIO bits << 4
378 theseven 1053
	mov	r6, #0x80000000
273 theseven 1054
	add	sp, sp, r8,lsr#3
378 theseven 1055
	tst	r8, #0x20
273 theseven 1056
	ldrh	r0, [sp]
378 theseven 1057
	orrne	r6, r6, #0x188
273 theseven 1058
	add	sp, sp, r0
378 theseven 1059
	orr	r6, r6, #0xc20
273 theseven 1060
	mov	r0, #0x33
378 theseven 1061
	str	r6, [r4]
273 theseven 1062
	str	r0, [r4,#0x20]
1063
lcdloop:
1064
	adr	lr, lcdloop
1065
	ldrb	r6, [sp], #1
1066
	ldrb	r7, [sp], #1
1067
	orr	r6, r6, r7,lsl#8
1068
	mov	r7, r6,lsr#14
1069
	bics	r0, r6, #0xc000
1070
	add	pc, pc, r7,lsl#2
1071
val_80100db0:
1072
	.word 0x80100db0
1073
	b	sendlcdd
1074
	b	sendlcdc
1075
	bne	lcdbyteseq
1076
	movne	r0, r0,lsl#4
1077
	bne	udelay
1078
	mov	r10, #0x22000000
419 theseven 1079
	ldr	r6, val_80100db0
273 theseven 1080
	orr	r10, r10, #0x10000
419 theseven 1081
	str	r6, [r4]
273 theseven 1082
	add	r11, r10, #0x25800
1083
	mov	r0, #-1
1084
fillbuff:
1085
	str	r0, [r11,#-4]!
1086
	cmp	r10, r11
1087
	bne	fillbuff
1088
	mov	r1, r11
1089
	adr	r0, text
1090
	bl	rendertext
1091
	add	r1, r11, #0x2800
1092
printerror:
1093
	bl	rendertext
1094
	bl	flushcache
378 theseven 1095
	tst	r8, #0x20
1096
	beq	leadisprotocol
273 theseven 1097
	mov	r9, #0x200
1098
	add	r0, r9, #0x10
1099
	bl	sendlcdc
1100
	mov	r0, #0
1101
	bl	sendlcdd
1102
	add	r0, r9, #0x11
1103
	bl	sendlcdc
419 theseven 1104
	add	r0, r9, #0x3f
273 theseven 1105
	bl	sendlcdd
1106
	add	r0, r9, #0x12
1107
	bl	sendlcdc
1108
	mov	r0, #0
1109
	bl	sendlcdd
1110
	add	r0, r9, #0x13
1111
	bl	sendlcdc
1112
	mov	r0, #0xef
1113
	bl	sendlcdd
1114
	mov	r0, r9
1115
	bl	sendlcdc
1116
	mov	r0, #0
1117
	bl	sendlcdd
1118
	add	r0, r9, #1
1119
	bl	sendlcdc
1120
	mov	r0, #0
1121
	bl	sendlcdd
1122
	add	r0, r9, #2
1123
	bl	sendlcdc
1124
	b	blit
1125
leadisprotocol:
1126
	mov	r0, #0x2a
1127
	bl	sendlcdc
1128
	mov	r0, #0
1129
	bl	sendlcdd
1130
	mov	r0, #0
1131
	bl	sendlcdd
1132
	mov	r0, #1
1133
	bl	sendlcdd
1134
	mov	r0, #0x3f
1135
	bl	sendlcdd
1136
	mov	r0, #0x2b
1137
	bl	sendlcdc
1138
	mov	r0, #0
1139
	bl	sendlcdd
1140
	mov	r0, #0
1141
	bl	sendlcdd
1142
	mov	r0, #0
1143
	bl	sendlcdd
1144
	mov	r0, #0xef
1145
	bl	sendlcdd
1146
	mov	r0, #0x2c
1147
	bl	sendlcdc
1148
blit:
1149
	sub	r7, r4, #0x00100000  @ R7 = DMA0BASE (temporary)
1150
	mov	r0, #1
1151
	str	r0, [r7,#0x30]
1152
	mov	r0, #0x22000000
1153
	orr	r0, r0, #0x3d000
1154
	add	r1, r7, #0x100
1155
	mov	r13, #0x8800
1156
	orr	r13, r13, #0xc1
1157
	ldmia	r0, {r9-r12}
1158
	stmia	r1, {r9-r13}
1159
	tst	r5, #0xff
1160
failed:
1161
	bne	failed
1162
	mov	r3, #0x2b
1163
	mov	r4, #4
1164
	bl	pmutransfer
1165
	mov	r3, #0x28
1166
	mov	r4, #14
1167
	bl	pmutransfer
1168
	mov	r3, #0x29
1169
	mov	r4, #1
1170
	bl	pmutransfer
1171
	sub	r7, r5, #0x00300000  @ R7 = SPIBASE
1172
	orr	r3, r5, #0x00900000  @ R3 = GPIOBASE
1173
	mov	r0, #0xf
1174
	str	r0, [r7,#0x8]
1175
	ldr	r0, [r7]
1176
	orr	r0, r0, #0xc
1177
	str	r0, [r7]
1178
	mov	r0, #4
1179
	str	r0, [r7,#0x30]
1180
	mov	r0, #6
1181
	str	r0, [r7,#0xc]
1182
	ldr	r0, val_00010618
1183
	str	r0, [r7,#0x4]
1184
	ldr	r0, [r7]
1185
	orr	r0, r0, #0xc
1186
	str	r0, [r7]
1187
	mov	r0, #1
1188
	str	r0, [r7]
1189
    	sub	r1, r9, #0x1000
1190
	mov	r11, #0
1191
	mov	r12, #0x1000
1192
	bl	bootflash_read
1193
    	sub	r11, r9, #0x1000
1194
	ldrd	r4, bootfilename
1195
searchfile:
1196
	ldrd	r12, [r11]
1197
	cmp	r4, r12
1198
	cmpeq	r5, r13
1199
	beq	foundfile
1200
	add	r11, r11, #0x10
1201
	tst	r11, #0x10000
1202
	beq	searchfile
1203
	adr	r0, errormessage
1204
	sub	r4, r3, #0x04c00000  @ R4 = LCDBASE
1205
	mov	r1, #0x22000000
1206
	orr	r1, r1, #0x13c00
1207
	b	printerror
1208
 
1209
val_00010618:
1210
	.word 0x00010618
1211
 
1212
bootfilename:
1213
	.ascii "embios  "
1214
 
1215
text:
1216
	.ascii "emBIOS Loader v"
1217
	.ascii VERSION
1218
	.ascii " r"
1219
	.ascii VERSION_SVN
1220
	.ascii "\0"
1221
	.ascii "Loading emBIOS...\0"
1222
 
1223
errormessage:
1224
	.ascii "File not found!\0"