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