Subversion Repositories freemyipod

Rev

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
	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
560 theseven 202
	.word 0xFDFFFFE5 @ R1 - PWRCON(0)
203
	.word 0xFFFFEFC9 @ R2 - PWRCON(1)
273 theseven 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
560 theseven 783
	bic	r12, r3, #0xa00000
784
	ldr	r1, [r12,#0x4c]
785
	orr	r1, r1, #4
786
	str	r1, [r12,#0x4c]
273 theseven 787
	mov	lr, #0x08000000
788
	b	flushcache
789
compressed:
790
    	mov	r1, #0x09000000
791
	bl	bootflash_read
560 theseven 792
	bic	r12, r3, #0xa00000
793
	ldr	r1, [r12,#0x4c]
794
	orr	r1, r1, #4
795
	str	r1, [r12,#0x4c]
273 theseven 796
	mov	r0, #0x09000000
797
	mov	r2, #0x08000000
798
	blx	thumb_nrv2e_d8
799
 
800
 
801
rendertext:
802
	ldrb	r3, [r0], #1
803
	cmp	r3, #0
804
	moveq	pc, lr
805
	adr	r6, font
806
	sub	r3, r3, #0x20
807
	cmp	r3, #0x5f
808
	addcc	r6, r3,lsl#2
809
	addcc	r6, r3
810
	mov	r3, #5
811
rendertext_col:
812
	mov	r7, r1
813
	ldrb	r9, [r6], #1
814
rendertext_row:
815
	tst	r9, #1
816
	strneh	r2, [r7]
817
	add	r7, r7, #640
818
	movs	r9, r9,lsr#1
819
	bne	rendertext_row
820
	add	r1, r1, #2
821
	subs	r3, r3, #1
822
	bne	rendertext_col
823
	add	r1, r1, #2
824
	b	rendertext
825
 
826
spisend:
827
	mov	r6, #1
828
	str	r6, [r7,#0x34]
829
spisend_wait:
830
	ldr	r6, [r7,#0x8]
831
	and	r6, r6, #0x1f0
832
	cmp	r6, #0x100
833
	beq	spisend_wait
834
	str	r0, [r7,#0x10]
835
spisend_wait2:
836
	ldr	r6, [r7,#0x8]
837
	ands	r6, r6, #0x3e00
838
	beq	spisend_wait2
839
	ldr	r0, [r7,#0x20]
840
	mov	pc, lr
841
 
842
spirecv:
843
	str	r0, [r7,#0x34]
844
	ldr	r6, [r7,#0x4]
845
	orr	r6, r6, #1
846
	str	r6, [r7,#0x4]
847
spirecv_loop:
848
	ldr	r6, [r7,#0x8]
849
	ands	r6, r6, #0x3e00
850
	beq	spirecv_loop
851
	ldr	r6, [r7,#0x20]
852
	strb	r6, [r1], #1
853
	subs	r0, r0, #1
854
	bne	spirecv_loop
855
	ldr	r6, [r7,#0x4]
856
	bic	r6, r6, #1
857
	str	r6, [r7,#0x4]
858
	mov	pc, lr
859
 
860
bootflash_read:
861
	mov	sp, lr
862
bootflash_wait:
863
	ldr	r0, [r3,#0x4]
864
	bic	r0, r0, #1
865
	str	r0, [r3,#0x4]
866
	mov	r0, #5
867
	bl	spisend
868
	mov	r0, #0xff
869
	bl	spisend
870
	tst	r0, #1
871
	ldr	r0, [r3,#0x4]
872
	orr	r0, r0, #1
873
	str	r0, [r3,#0x4]
874
	bne	bootflash_wait
875
	ldr	r0, [r3,#0x4]
876
	bic	r0, r0, #1
877
	str	r0, [r3,#0x4]
878
	mov	r0, #3
879
	bl	spisend
880
	mov	r0, r11,lsr#16
881
	bl	spisend
882
	mov	r0, r11,lsr#8
883
	and	r0, r0, #0xff
884
	bl	spisend
885
	and	r0, r11, #0xff
886
	bl	spisend
887
	mov	r0, r12
888
	bl	spirecv
889
	ldr	r0, [r3,#0x4]
890
	orr	r0, r0, #1
891
	str	r0, [r3,#0x4]
892
	mov	pc, sp
893
 
894
lcdbyteseq:
895
	mov	r9, r0,lsr#8
896
	and	r0, r0, #0xff
897
	bl	sendlcdc
898
lcdbyteseqloop:
899
	ldrb	r0, [sp], #1
900
	bl	sendlcdd
901
	subs	r9, r9, #1
902
	bne	lcdbyteseqloop
903
	b	lcdloop
904
 
905
sendlcdc:
906
	ldr	r6, [r4,#0x1c]
907
	ands	r6, r6, #0x10
908
	bne	sendlcdc
909
	str	r0, [r4,#0x04]
910
	mov	pc, lr
911
 
912
sendlcdd:
913
	ldr	r6, [r4,#0x1c]
914
	ands	r6, r6, #0x10
915
	bne	sendlcdd
916
	str	r0, [r4,#0x40]
917
	mov	pc, lr
918
 
919
i2cwaitrdy:
920
	ldr	r6, [r5,#0x10]
921
	cmp	r6, #0
922
	bne	i2cwaitrdy
923
	mov	pc, lr
924
 
925
i2cwait:
926
	ldr	r6, [r5]
927
	tst	r6, #0x10
928
	beq	i2cwait
929
	mov	pc, lr
930
 
931
pmutransfer:
932
	mov	r7, lr
933
	mov	lr, #0xb7
934
	str	lr, [r5]
935
	mov	lr, #0xe6
936
	str	lr, [r5,#0xc]
937
	mov	lr, #0xf0
938
	str	lr, [r5,#0x4]
939
	bl	i2cwait
940
	str	r3, [r5,#0xc]
941
	mov	lr, #0xb7
942
	str	lr, [r5]
943
	bl	i2cwait
944
	cmn	r4, #1
945
	beq	pmuskip
946
	str	r4, [r5,#0xc]
947
	mov	lr, #0xb7
948
	str	lr, [r5]
949
	bl	i2cwait
950
	mov	lr, #0xd0
951
	b	pmudone
952
pmuskip:
953
	mov	lr, #0xe7
954
	str	lr, [r5,#0xc]
955
	mov	lr, #0xb0
956
	str	lr, [r5,#0x4]
957
	mov	lr, #0xb7
958
	str	lr, [r5]
959
	bl	i2cwait
960
	mov	lr, #0x37
961
	str	lr, [r5]
962
	bl	i2cwait
963
	ldr	r3, [r5,#0xc]
964
	mov	lr, #0x90
965
pmudone:
966
	str	lr, [r5,#0x4]
967
	mov	lr, #0xb7
968
	str	lr, [r5]
969
pmuwait:
970
	ldr	lr, [r5,#0x4]
971
	tst	lr, #0x20
972
	bne	pmuwait
973
	mov	pc, r7
974
 
975
udelay:
976
	ldr	r6, [r1,#0xb4]
977
	add	r0, r0, r6
978
udelayloop:
979
	ldr	r6, [r1,#0xb4]
980
	cmp	r6, r0
981
	bmi	udelayloop
982
	mov	pc, lr
983
 
984
 
985
pwrok:
986
	sub	r7, r5, #0x04500000  @ R7 = MIUBASE (temporary)
987
	cmp	r0, #0
988
	moveq	r6, #0x11
989
	streq	r6, [r7]
990
	str	r8, [r7]
991
	str	r2, [r7,#0xf0]
992
	str	r9, [r7,#0x8]
993
	str	r10, [r7,#0x10]
994
	mov	r8, #0x1800
995
	orr	r6, r8, #0x45
996
	str	r6, [r7,#0x200]
997
	str	r6, [r7,#0x204]
998
	str	r8, [r7,#0x210]
999
	str	r8, [r7,#0x214]
1000
	str	r6, [r7,#0x220]
1001
	str	r6, [r7,#0x224]
1002
	add	r6, r6, #0x40
1003
	str	r6, [r7,#0x230]
1004
	str	r6, [r7,#0x234]
1005
	mov	r6, #0x19
1006
	str	r6, [r7,#0x14]
1007
	str	r6, [r7,#0x18]
1008
	str	r11, [r7,#0x1c]
1009
	ldr	r6, [r7,#0x314]
1010
	bic	r6, r6, #0x10
1011
	str	r6, [r7,#0x314]
1012
	add	r8, r7, #0x2c
1013
	mov	r9, #0x24
1014
sdramloop:
1015
	ldr	r6, [r8]
1016
	bic	r6, r6, #0x01000000
1017
	str	r6, [r8], #4
1018
	subs	r9, r9, #1
1019
	bne	sdramloop
1020
	mov	r6, #0x540
1021
	str	r6, [r7,#0x1cc]
1022
	ldr	r6, [r7,#0x1d4]
1023
	orr	r6, r6, #0x80
1024
	str	r6, [r7,#0x1d4]
1025
	mov	r6, #0x33
1026
	str	r6, [r7,#0x4]
1027
	str	r6, [r7,#0x4]
1028
	orr	r8, r6, #0x200
1029
	str	r8, [r7,#0x4]
1030
	str	r6, [r7,#0x4]
1031
	str	r6, [r7,#0x4]
1032
	str	r6, [r7,#0x4]
1033
	orr	r8, r8, #0x100
1034
	str	r8, [r7,#0x4]
1035
	str	r6, [r7,#0x4]
1036
	str	r6, [r7,#0x4]
1037
	str	r6, [r7,#0x4]
1038
	str	r8, [r7,#0x4]
1039
	str	r6, [r7,#0x4]
1040
	str	r6, [r7,#0x4]
1041
	str	r6, [r7,#0x4]
1042
	cmp	r0, #0
1043
	strne	r6, [r7,#0xc]
1044
	bicne	r8, r8, #0x200
1045
	strne	r8, [r7,#0x4]
1046
	strne	r6, [r7,#0x4]
1047
	strne	r6, [r7,#0x4]
1048
	strne	r6, [r7,#0x4]
1049
	strne	r12, [r7,#0xc]
1050
	strne	r8, [r7,#0x4]
1051
	strne	r6, [r7,#0x4]
1052
	strne	r6, [r7,#0x4]
1053
	strne	r6, [r7,#0x4]
1054
	ldr	r6, [r7,#0x8]
1055
	orr	r6, r6, #0x61000
1056
	str	r6, [r7,#0x8]
1057
	orr	r3, r1, #0x00800000  @ R3 = GPIOBASE
1058
	sub	r4, r1, #0x04400000  @ R4 = LCDBASE
1059
	ldr	r0, [r3,#0xc4]
1060
	and	r8, r0, #0x30        @ R8 = LCD type GPIO bits << 4
378 theseven 1061
	mov	r6, #0x80000000
273 theseven 1062
	add	sp, sp, r8,lsr#3
378 theseven 1063
	tst	r8, #0x20
273 theseven 1064
	ldrh	r0, [sp]
378 theseven 1065
	orrne	r6, r6, #0x188
273 theseven 1066
	add	sp, sp, r0
378 theseven 1067
	orr	r6, r6, #0xc20
273 theseven 1068
	mov	r0, #0x33
378 theseven 1069
	str	r6, [r4]
273 theseven 1070
	str	r0, [r4,#0x20]
1071
lcdloop:
1072
	adr	lr, lcdloop
1073
	ldrb	r6, [sp], #1
1074
	ldrb	r7, [sp], #1
1075
	orr	r6, r6, r7,lsl#8
1076
	mov	r7, r6,lsr#14
1077
	bics	r0, r6, #0xc000
1078
	add	pc, pc, r7,lsl#2
1079
val_80100db0:
1080
	.word 0x80100db0
1081
	b	sendlcdd
1082
	b	sendlcdc
1083
	bne	lcdbyteseq
1084
	movne	r0, r0,lsl#4
1085
	bne	udelay
1086
	mov	r10, #0x22000000
419 theseven 1087
	ldr	r6, val_80100db0
273 theseven 1088
	orr	r10, r10, #0x10000
419 theseven 1089
	str	r6, [r4]
273 theseven 1090
	add	r11, r10, #0x25800
1091
	mov	r0, #-1
1092
fillbuff:
1093
	str	r0, [r11,#-4]!
1094
	cmp	r10, r11
1095
	bne	fillbuff
1096
	mov	r1, r11
1097
	adr	r0, text
1098
	bl	rendertext
1099
	add	r1, r11, #0x2800
1100
printerror:
1101
	bl	rendertext
1102
	bl	flushcache
378 theseven 1103
	tst	r8, #0x20
1104
	beq	leadisprotocol
273 theseven 1105
	mov	r9, #0x200
1106
	add	r0, r9, #0x10
1107
	bl	sendlcdc
1108
	mov	r0, #0
1109
	bl	sendlcdd
1110
	add	r0, r9, #0x11
1111
	bl	sendlcdc
419 theseven 1112
	add	r0, r9, #0x3f
273 theseven 1113
	bl	sendlcdd
1114
	add	r0, r9, #0x12
1115
	bl	sendlcdc
1116
	mov	r0, #0
1117
	bl	sendlcdd
1118
	add	r0, r9, #0x13
1119
	bl	sendlcdc
1120
	mov	r0, #0xef
1121
	bl	sendlcdd
1122
	mov	r0, r9
1123
	bl	sendlcdc
1124
	mov	r0, #0
1125
	bl	sendlcdd
1126
	add	r0, r9, #1
1127
	bl	sendlcdc
1128
	mov	r0, #0
1129
	bl	sendlcdd
1130
	add	r0, r9, #2
1131
	bl	sendlcdc
1132
	b	blit
1133
leadisprotocol:
1134
	mov	r0, #0x2a
1135
	bl	sendlcdc
1136
	mov	r0, #0
1137
	bl	sendlcdd
1138
	mov	r0, #0
1139
	bl	sendlcdd
1140
	mov	r0, #1
1141
	bl	sendlcdd
1142
	mov	r0, #0x3f
1143
	bl	sendlcdd
1144
	mov	r0, #0x2b
1145
	bl	sendlcdc
1146
	mov	r0, #0
1147
	bl	sendlcdd
1148
	mov	r0, #0
1149
	bl	sendlcdd
1150
	mov	r0, #0
1151
	bl	sendlcdd
1152
	mov	r0, #0xef
1153
	bl	sendlcdd
1154
	mov	r0, #0x2c
1155
	bl	sendlcdc
1156
blit:
1157
	sub	r7, r4, #0x00100000  @ R7 = DMA0BASE (temporary)
1158
	mov	r0, #1
1159
	str	r0, [r7,#0x30]
1160
	mov	r0, #0x22000000
1161
	orr	r0, r0, #0x3d000
1162
	add	r1, r7, #0x100
1163
	mov	r13, #0x8800
1164
	orr	r13, r13, #0xc1
1165
	ldmia	r0, {r9-r12}
1166
	stmia	r1, {r9-r13}
1167
	tst	r5, #0xff
1168
failed:
1169
	bne	failed
1170
	mov	r3, #0x2b
1171
	mov	r4, #4
1172
	bl	pmutransfer
1173
	mov	r3, #0x28
1174
	mov	r4, #14
1175
	bl	pmutransfer
1176
	mov	r3, #0x29
1177
	mov	r4, #1
1178
	bl	pmutransfer
1179
	sub	r7, r5, #0x00300000  @ R7 = SPIBASE
1180
	orr	r3, r5, #0x00900000  @ R3 = GPIOBASE
1181
	mov	r0, #0xf
1182
	str	r0, [r7,#0x8]
1183
	ldr	r0, [r7]
1184
	orr	r0, r0, #0xc
1185
	str	r0, [r7]
1186
	mov	r0, #4
1187
	str	r0, [r7,#0x30]
1188
	mov	r0, #6
1189
	str	r0, [r7,#0xc]
1190
	ldr	r0, val_00010618
1191
	str	r0, [r7,#0x4]
1192
	ldr	r0, [r7]
1193
	orr	r0, r0, #0xc
1194
	str	r0, [r7]
1195
	mov	r0, #1
1196
	str	r0, [r7]
1197
    	sub	r1, r9, #0x1000
1198
	mov	r11, #0
1199
	mov	r12, #0x1000
1200
	bl	bootflash_read
1201
    	sub	r11, r9, #0x1000
1202
	ldrd	r4, bootfilename
1203
searchfile:
1204
	ldrd	r12, [r11]
1205
	cmp	r4, r12
1206
	cmpeq	r5, r13
1207
	beq	foundfile
1208
	add	r11, r11, #0x10
1209
	tst	r11, #0x10000
1210
	beq	searchfile
1211
	adr	r0, errormessage
1212
	sub	r4, r3, #0x04c00000  @ R4 = LCDBASE
1213
	mov	r1, #0x22000000
1214
	orr	r1, r1, #0x13c00
1215
	b	printerror
1216
 
1217
val_00010618:
1218
	.word 0x00010618
1219
 
1220
bootfilename:
427 farthen 1221
	.ascii "emcore  "
273 theseven 1222
 
1223
text:
427 farthen 1224
	.ascii "emCORE Loader v"
273 theseven 1225
	.ascii VERSION
1226
	.ascii " r"
1227
	.ascii VERSION_SVN
1228
	.ascii "\0"
427 farthen 1229
	.ascii "Loading emCORE...\0"
273 theseven 1230
 
1231
errormessage:
1232
	.ascii "File not found!\0"