source: trunk/platform/g12/sub/100e/boot.c @ 1294

Revision 1294, 28.7 KB checked in by philmoz, 21 months ago (diff)

Update for G12 & SX30 to support very large, partitioned SD cards, where the 2nd partition is formatted as exFat.

  • Property svn:eol-style set to native
Line 
1#include "lolevel.h"
2#include "platform.h"
3#include "core.h"
4#include "dryos31.h"
5
6#define offsetof(TYPE, MEMBER) ((int) &((TYPE *)0)->MEMBER)
7
8const char * const new_sa = &_end;
9
10// Forward declarations
11void CreateTask_PhySw();
12void CreateTask_spytask();
13extern volatile int jogdial_stopped;
14void JogDial_task_my(void);
15
16//void __attribute__((naked,noinline)) my_blinker(int n) {
17//      asm volatile (
18//"                STMFD   SP!, {R0-R5,LR}\n"
19//);
20//      int i, j;
21//      for (j=0; j<n; j++)
22//      {
23//              *((volatile int *) 0xC0220134) = 0x46; // Turn on LED
24//              for (i=0; i<0x200000; i++) { asm volatile ( "nop\n" ); }
25//
26//              *((volatile int *) 0xC0220134) = 0x44; // Turn off LED
27//              for (i=0; i<0x200000; i++) { asm volatile ( "nop\n" ); }
28//      }
29//      for (i=0; i<0x900000; i++) { asm volatile ( "nop\n" ); }
30//      asm volatile (
31//"                LDMFD   SP!, {R0-R5,PC}\n"
32//      );
33//}
34
35extern void task_CaptSeq();
36extern void task_InitFileModules();
37extern void task_RotaryEncoder();
38extern void task_MovieRecord();
39extern void task_ExpDrv();
40
41void taskHook(context_t **context)
42{
43        task_t *tcb=(task_t*)((char*)context-offsetof(task_t, context));
44
45        // Replace firmware task addresses with ours
46        if(tcb->entry == (void*)task_CaptSeq)                   tcb->entry = (void*)capt_seq_task;
47        if(tcb->entry == (void*)task_InitFileModules)   tcb->entry = (void*)init_file_modules_task;
48        if(tcb->entry == (void*)task_RotaryEncoder)             tcb->entry = (void*)JogDial_task_my;
49        if(tcb->entry == (void*)task_MovieRecord)               tcb->entry = (void*)movie_record_task;
50        if(tcb->entry == (void*)task_ExpDrv)                    tcb->entry = (void*)exp_drv_task;
51}
52
53/*---------------------------------------------------------------------
54  Memory Map:
55        0001900     MEMBASEADDR             start of data - used for initialized vars
56        0010797                             end of inited data
57        0010798                             start of bss - used for zeroed/uninited vars
58        016E81F                             end of bss
59        016E820     MEMISOSTART             start of our data / bss
60
61        0400000                             raw buffers
62        8000000                             end of raw buffers
63
64        C0xxxxxx                            I/O
65
66        FF810000    ROMBASEADDR             start of rom
67        FFFFFFFF                            end of rom
68----------------------------------------------------------------------*/
69
70/*----------------------------------------------------------------------
71        boot()
72
73        Main entry point for the CHDK code
74-----------------------------------------------------------------------*/
75
76void __attribute__((naked,noinline)) boot() {
77
78    asm volatile (
79                 "LDR     R1, =0xC0410000\n"
80                 "MOV     R0, #0\n"
81                 "STR     R0, [R1]\n"
82                 "MOV     R1, #0x78\n"
83                 "MCR     p15, 0, R1,c1,c0\n"
84                 "MOV     R1, #0\n"
85                 "MCR     p15, 0, R1,c7,c10, 4\n"
86                 "MCR     p15, 0, R1,c7,c5\n"
87                 "MCR     p15, 0, R1,c7,c6\n"
88                 "MOV     R0, #0x3D\n"
89                 "MCR     p15, 0, R0,c6,c0\n"
90                 "MOV     R0, #0xC000002F\n"
91                 "MCR     p15, 0, R0,c6,c1\n"
92                 "MOV     R0, #0x35\n"                                  // memory region & size. bits 1 - 5 = size index, actual size = 2^(size index + 1) = 128MB
93                 "MCR     p15, 0, R0,c6,c2\n"
94                 "MOV     R0, #0x40000035\n"                    // memory region & size. bits 1 - 5 = size index, actual size = 2^(size index + 1) = 128MB
95                 "MCR     p15, 0, R0,c6,c3\n"
96                 "MOV     R0, #0x80000017\n"
97                 "MCR     p15, 0, R0,c6,c4\n"
98                 "LDR     R0, =0xFF80002D\n"
99                 "MCR     p15, 0, R0,c6,c5\n"
100                 "MOV     R0, #0x34\n"
101                 "MCR     p15, 0, R0,c2,c0\n"
102                 "MOV     R0, #0x34\n"
103                 "MCR     p15, 0, R0,c2,c0, 1\n"
104                 "MOV     R0, #0x34\n"
105                 "MCR     p15, 0, R0,c3,c0\n"
106                 "LDR     R0, =0x3333330\n"
107                 "MCR     p15, 0, R0,c5,c0, 2\n"
108                 "LDR     R0, =0x3333330\n"
109                 "MCR     p15, 0, R0,c5,c0, 3\n"
110                 "MRC     p15, 0, R0,c1,c0\n"
111                 "ORR     R0, R0, #0x1000\n"
112                 "ORR     R0, R0, #4\n"
113                 "ORR     R0, R0, #1\n"
114                 "MCR     p15, 0, R0,c1,c0\n"
115                 "MOV     R1, #0x80000006\n"
116                 "MCR     p15, 0, R1,c9,c1\n"
117                 "MOV     R1, #6\n"
118                 "MCR     p15, 0, R1,c9,c1, 1\n"
119                 "MRC     p15, 0, R1,c1,c0\n"
120                 "ORR     R1, R1, #0x50000\n"
121                 "MCR     p15, 0, R1,c1,c0\n"
122                 "LDR     R2, =0xC0200000\n"
123                 "MOV     R1, #1\n"
124                 "STR     R1, [R2,#0x10C]\n"
125                 "MOV     R1, #0xFF\n"
126                 "STR     R1, [R2,#0xC]\n"
127                 "STR     R1, [R2,#0x1C]\n"
128                 "STR     R1, [R2,#0x2C]\n"
129                 "STR     R1, [R2,#0x3C]\n"
130                 "STR     R1, [R2,#0x4C]\n"
131                 "STR     R1, [R2,#0x5C]\n"
132                 "STR     R1, [R2,#0x6C]\n"
133                 "STR     R1, [R2,#0x7C]\n"
134                 "STR     R1, [R2,#0x8C]\n"
135                 "STR     R1, [R2,#0x9C]\n"
136                 "STR     R1, [R2,#0xAC]\n"
137                 "STR     R1, [R2,#0xBC]\n"
138                 "STR     R1, [R2,#0xCC]\n"
139                 "STR     R1, [R2,#0xDC]\n"
140                 "STR     R1, [R2,#0xEC]\n"
141                 "STR     R1, [R2,#0xFC]\n"
142                 "LDR     R1, =0xC0400008\n"
143                 "LDR     R2, =0x430005\n"
144                 "STR     R2, [R1]\n"
145                 "MOV     R1, #1\n"
146                 "LDR     R2, =0xC0243100\n"
147                 "STR     R2, [R1]\n"
148                 "LDR     R2, =0xC0242010\n"
149                 "LDR     R1, [R2]\n"
150                 "ORR     R1, R1, #1\n"
151                 "STR     R1, [R2]\n"
152
153                 "LDR     R0, =0xFFCB1DD0\n"
154                 "LDR     R1, =0x1900\n"
155                 "LDR     R3, =0x10798\n"
156 "loc_FF81013C:\n"
157                 "CMP     R1, R3\n"
158                 "LDRCC   R2, [R0],#4\n"
159                 "STRCC   R2, [R1],#4\n"
160                 "BCC     loc_FF81013C\n"
161                 "LDR     R1, =0x16E820\n"
162                 "MOV     R2, #0\n"
163 "loc_FF810154:\n"
164                 "CMP     R3, R1\n"
165                 "STRCC   R2, [R3],#4\n"
166                 "BCC     loc_FF810154\n"
167
168                                 "B       sub_FF810354_my" // -->
169    );
170}
171
172void __attribute__((naked,noinline)) sub_FF810354_my() {
173
174        //http://chdk.setepontos.com/index.php/topic,4194.0.html
175        *(int*)0x1938=(int)taskHook;
176        *(int*)0x193C=(int)taskHook;
177   
178        // replacement of sub_FF864BE0 for correct power-on.
179        *(int*)(0x25E0) = (*(int*)0xC0220108)&1 ? 0x100000 : 0x200000;
180
181        asm volatile (
182                 "LDR     R0, =0xFF8103CC\n"
183                 "MOV     R1, #0\n"
184                 "LDR     R3, =0xFF810404\n"
185 "loc_FF810360:\n"
186                 "CMP     R0, R3\n"
187                 "LDRCC   R2, [R0],#4\n"
188                 "STRCC   R2, [R1],#4\n"
189                 "BCC     loc_FF810360\n"
190                 "LDR     R0, =0xFF810404\n"
191                 "MOV     R1, #0x4B0\n"
192                 "LDR     R3, =0xFF810618\n"
193 "loc_FF81037C:\n"
194                 "CMP     R0, R3\n"
195                 "LDRCC   R2, [R0],#4\n"
196                 "STRCC   R2, [R1],#4\n"
197                 "BCC     loc_FF81037C\n"
198                 "MOV     R0, #0xD2\n"
199                 "MSR     CPSR_cxsf, R0\n"
200                 "MOV     SP, #0x1000\n"
201                 "MOV     R0, #0xD3\n"
202                 "MSR     CPSR_cxsf, R0\n"
203                 "MOV     SP, #0x1000\n"
204                 "LDR     R0, =0x6C4\n"
205                 "LDR     R2, =0xEEEEEEEE\n"
206                 "MOV     R3, #0x1000\n"
207 "loc_FF8103B0:\n"
208                 "CMP     R0, R3\n"
209                 "STRCC   R2, [R0],#4\n"
210                 "BCC     loc_FF8103B0\n"
211//                 "BL      sub_FF811198\n"
212                 "BL      sub_FF811198_my\n" // -->
213     );
214}
215
216void __attribute__((naked,noinline)) sub_FF811198_my() {
217
218     asm volatile (
219                 "STR     LR, [SP,#-4]!\n"
220                 "SUB     SP, SP, #0x74\n"
221                 "MOV     R0, SP\n"
222                 "MOV     R1, #0x74\n"
223                 "BL      sub_FFBB34D4\n"
224                 "MOV     R0, #0x53000\n"
225                 "STR     R0, [SP,#4]\n"
226
227#if defined(OPT_CHDK_IN_EXMEM)
228               "LDR     R0, =0x16E820\n" // use original heap offset since CHDK is loaded in high memory
229#else
230               "LDR     R0, =new_sa\n"   // otherwise use patched value
231               "LDR     R0, [R0]\n"      //
232#endif
233                                 
234"               LDR     R1, =0x379C00 \n"
235"               STR     R0, [SP,#8] \n"
236"               RSB     R0, R0, #0x1F80 \n"
237"               ADD     R0, R0, #0x370000 \n"
238"               STR     R0, [SP,#0x0c] \n"
239"               LDR     R0, =0x371F80 \n"
240"               STR     R1, [SP,#0] \n"
241"               STRD    R0, [SP,#0x10] \n"
242"               MOV     R0, #0x22 \n"
243"               STR     R0, [SP,#0x18] \n"
244"               MOV     R0, #0x68 \n"
245"               STR     R0, [SP,#0x1c] \n"
246"               LDR     R0, =0x19B \n"
247
248//"             LDR     R1, =0xFF815EE0 \n"
249"               LDR     R1, =sub_FF815EE0_my \n"                // patched
250
251"               B               sub_FF8111F0 \n"                // Continue in firmware
252     );
253}
254
255void __attribute__((naked,noinline)) sub_FF815EE0_my() {
256
257        asm volatile (
258"               STMFD   SP!, {R4,LR} \n"
259"               BL      sub_FF810B20 \n"
260"               BL      sub_FF81A33C \n"                                // dmSetup
261"               CMP     R0, #0 \n"
262
263//"             ADRLT   R0, aDmsetup \n"                        // "dmSetup"
264"               LDRLT   r0, =0xFF815FF4 \n"
265
266"               BLLT    _err_init_task \n"
267"               BL      sub_FF815B1C \n"
268"               CMP     R0, #0 \n"
269
270//"             ADRLT   R0, aTermdriverinit \n"         // "termDriverInit"
271"               LDRLT   R0, =0xFF815FFC \n"
272
273"               BLLT    _err_init_task \n"
274
275//"             ADR     R0, a_term \n"                                  // "/_term"
276"               LDR     R0, =0xFF81600C \n"
277
278"               BL      sub_FF815C04 \n"                                // termDeviceCreate
279"               CMP     R0, #0 \n"
280
281//"             ADRLT   R0, aTermdevicecrea \n"         // "termDeviceCreate"
282"               LDRLT   R0, =0xFF816014 \n"
283
284"               BLLT    _err_init_task \n"
285
286//"             ADR     R0, a_term \n"                                  // "/_term"
287"               LDR     R0, =0xFF81600C \n"
288
289"               BL      sub_FF813CA4 \n"
290"               CMP     R0, #0 \n"
291
292//"             ADRLT   R0, aStdiosetup \n"                     // "stdioSetup"
293"               LDRLT   R0, =0xFF816028 \n"
294
295"               BLLT    _err_init_task \n"
296"               BL      sub_FF819CC4 \n"
297"               CMP     R0, #0 \n"
298
299//"             ADRLT   R0, aStdlibsetup \n"            // "stdlibSetup"
300"               LDRLT   R0, =0xFF816034 \n"
301
302"               BLLT    _err_init_task \n"
303"               BL      sub_FF81167C \n"
304"               CMP     R0, #0 \n"
305
306//"             ADRLT   R0, aArmlib_setup \n"           // "armlib_setup"
307"               LDRLT   R0, =0xFF816040 \n"
308
309"               BLLT    _err_init_task \n"
310
311"               LDMFD   SP!, {R4,LR} \n"
312
313//"             B       sub_FF81FB54 \n"                                // taskcreate_Startup
314"               B       taskcreate_Startup_my \n"               // patched
315        );
316};
317
318void __attribute__((naked,noinline)) taskcreate_Startup_my() {
319
320        asm volatile (
321                "STMFD  SP!, {R3,LR}\n"
322//              "BL             j_nullsub_222\n"
323                "BL             sub_FF83C81C\n"
324                "CMP    R0, #0\n"
325                "BNE    loc_FF81FB98\n"
326                "BL             sub_FF836164\n"
327                "CMP    R0, #0\n"
328                "BNE    loc_FF81FB98\n"
329                "BL             sub_FF834738\n"
330                "CMP    R0, #0\n"
331                "BNE    loc_FF81FB98\n"
332                "BL             sub_FF833DB8\n"
333                "LDR    R1, =0xC0220000\n"
334                "MOV    R0, #0x44\n"
335                "STR    R0, [R1,#0x1C]\n"
336                "BL             sub_FF833FA8\n"
337               
338"loc_FF81FB94:\n"
339                "B              loc_FF81FB94\n"
340               
341"loc_FF81FB98:\n"
342//              "BL             sub_FF834744\n"         // see begin of sub_FF810354_my()
343//              "BL             j_nullsub_223\n"
344                "BL             sub_FF83AA2C\n"
345                "MOV     R0, #0x46 \n"
346                "BL      _SleepTask \n"
347                "LDR    R1, =0x3CE000\n"
348                "MOV    R0, #0\n"
349                "BL             sub_FF83AE74\n"
350                "BL             sub_FF83AC20\n" // KerSys
351                "MOV    R3, #0\n"
352                "STR    R3, [SP]\n"
353
354                //"ADR     R3, task_Startup\n"
355                "LDR    R3, =task_Startup_my\n" // patched
356
357                "B              sub_FF81FBC8\n" // Continue in firmware
358     );
359}
360
361void __attribute__((naked,noinline)) task_Startup_my() {
362
363        asm volatile (
364                "STMFD  SP!, {R4,LR}\n"
365                "BL             sub_FF816594\n" // taskcreate_ClockSave\n"
366                "BL             sub_FF835898\n"
367                "BL             sub_FF8339AC\n"
368//              "BL     j_nullsub_227\n"
369                "BL             sub_FF83CA4C\n"
370//              "BL             sub_FF83C8F4\n" // start diskboot.bin
371                "BL             sub_FF83CBF8\n"
372                "BL             sub_FF83247C\n"
373                "BL             sub_FF83CA7C\n"
374                "BL             sub_FF83A1D0\n"
375                "BL             sub_FF83CBFC\n"
376
377                "BL             CreateTask_spytask\n" // added
378
379//              "BL             sub_FF834620\n" //taskcreate_PhySw\n"
380                "BL             taskcreatePhySw_my\n"  // we do this here rather than hook so we don't waste the original stack
381
382                "B              sub_FF81FB24\n"         // Continue in firmware
383     );
384}
385
386void __attribute__((naked,noinline)) taskcreatePhySw_my() {
387        asm volatile (
388"                STMFD   SP!, {R3-R5,LR}\n"
389"                LDR     R4, =0x1C30\n"
390"                LDR     R0, [R4,#0x10]\n"
391"                CMP     R0, #0\n"
392"                BNE     sub_FF834654\n"
393"                MOV     R3, #0\n"
394"                STR     R3, [SP]\n"
395"                LDR     R3, =mykbd_task\n" // task_PhySw
396//"                MOV     R2, #0x800\n"
397"                MOV     R2, #0x2000\n" // stack size for new task_PhySw so we don't have to do stack switch
398"                               B       sub_FF834644 \n" // continue in firmware
399        );
400}
401
402/*----------------------------------------------------------------------
403        spytask
404-----------------------------------------------------------------------*/
405void spytask(long ua, long ub, long uc, long ud, long ue, long uf)
406{
407    core_spytask();
408}
409
410/*----------------------------------------------------------------------
411        CreateTask_spytask
412-----------------------------------------------------------------------*/
413void CreateTask_spytask() {
414        _CreateTask("SpyTask", 0x19, 0x2000, spytask, 0);
415}
416
417 ///*----------------------------------------------------------------------
418
419// @ FF89FC7C
420void __attribute__((naked,noinline)) init_file_modules_task() {
421 asm volatile(
422                 "STMFD   SP!, {R4-R6,LR}\n"
423                 "BL      sub_FF895DBC\n"
424                 "LDR     R5, =0x5006\n"
425                 "MOVS    R4, R0\n"
426                 "MOVNE   R1, #0\n"
427                 "MOVNE   R0, R5\n"
428                 "BLNE    _PostLogicalEventToUI\n"
429
430                                 //"BL      sub_FF895DE8\n"
431                 "BL      sub_FF895DE8_my\n"                    // patched
432
433                 "BL      core_spytask_can_start\n"      // CHDK: Set "it's-safe-to-start" flag for spytask
434
435                                 "B                     sub_FF89FC9C\n" // Continue in firmware
436 );
437}
438
439void __attribute__((naked,noinline)) sub_FF895DE8_my() {
440 asm volatile(
441                 "STMFD   SP!, {R4,LR}\n"
442                                 "MOV     R0, #3\n"
443
444                 //"BL      sub_FF876518\n"
445                 "BL      sub_FF876518_my\n"    // patched
446
447                                 "B             sub_FF895DF4\n" // Continue in firmware
448 );
449}
450
451void __attribute__((naked,noinline)) sub_FF876518_my() {
452 asm volatile(
453                "STMFD  SP!, {R4-R8,LR}\n"
454                "MOV    R8, R0\n"
455                "BL             sub_FF876498\n"
456                "LDR    R1, =0x3A848\n"
457                "MOV    R6, R0\n"
458                "ADD    R4, R1, R0,LSL#7\n"
459                "LDR    R0, [R4,#0x6C]\n"
460                "CMP    R0, #4\n"
461                "LDREQ  R1, =0x83f\n"
462                "LDREQ  R0, =0xFF875FD8\n"      // a_Mounter_c
463                "BLEQ   _DebugAssert\n"
464                "MOV    R1, R8\n"
465                "MOV    R0, R6\n"
466                "BL             sub_FF875D4C\n"
467                "LDR    R0, [R4,#0x38]\n"
468                "BL             sub_FF876BBC\n"
469                "CMP    R0, #0\n"
470                "STREQ  R0, [R4,#0x6C]\n"
471                "MOV    R0, R6\n"
472                "BL             sub_FF875DDC\n"
473                "MOV    R0, R6\n"
474
475                //"BL           sub_FF876140\n"
476                "BL             sub_FF876140_my\n"    // patched
477
478                "B              sub_FF876570\n" // Continue in firmware
479 );
480}
481
482void __attribute__((naked,noinline)) sub_FF876140_my() {
483 asm volatile(
484                "STMFD  SP!, {R4-R6,LR}\n"
485                "MOV    R5, R0\n"
486                "LDR    R0, =0x3A848\n"
487                "ADD    R4, R0, R5,LSL#7\n"
488                "LDR    R0, [R4,#0x6C]\n"
489                "TST    R0, #2\n"
490                "MOVNE  R0, #1\n"
491                "LDMNEFD        SP!, {R4-R6,PC}\n"
492                "LDR    R0, [R4,#0x38]\n"
493                "MOV    R1, R5\n"
494
495                //"BL           sub_FF875E60\n"
496                "BL             sub_FF875E60_my\n"    // patched
497
498                "B              sub_FF87616C\n" // Continue in firmware
499 );
500}
501//------------------------------------------------------------------
502void __attribute__((naked,noinline)) sub_FF875E60_my() {
503 asm volatile(
504                "STMFD  SP!, {R4-R10,LR}\n"
505                "MOV    R9, R0\n"
506                "LDR    R0, =0x3A848\n"
507                "MOV    R8, #0\n"
508                "ADD    R5, R0, R1,LSL#7\n"
509                "LDR    R0, [R5,#0x3C]\n"
510                "MOV    R7, #0\n"
511                "CMP    R0, #7\n"
512                "MOV    R6, #0\n"
513                "ADDLS  PC, PC, R0,LSL#2\n"
514                                "B      loc_FF875FB8\n"
515"loc_FF875E8C:   B      loc_FF875EC4\n"
516"loc_FF875E90:   B      loc_FF875EAC\n"
517"loc_FF875E94:   B      loc_FF875EAC\n"
518"loc_FF875E98:   B      loc_FF875EAC\n"
519"loc_FF875E9C:   B      loc_FF875EAC\n"
520"loc_FF875EA0:   B      loc_FF875FB0\n"
521"loc_FF875EA4:   B      loc_FF875EAC\n"
522"loc_FF875EA8:   B      loc_FF875EAC\n"
523
524"loc_FF875EAC:\n"
525                "MOV    R2, #0\n"
526                "MOV    R1, #0x200\n"
527                "MOV    R0, #2\n"
528                "BL             sub_FF88FE28\n"
529                "MOVS   R4, R0\n"
530                "BNE    loc_FF875ECC\n"
531
532"loc_FF875EC4:\n"
533                "MOV    R0, #0\n"
534                "LDMFD  SP!, {R4-R10,PC}\n"
535
536"loc_FF875ECC:\n"
537                "LDR    R12, [R5,#0x50]\n"
538                "MOV    R3, R4\n"
539                "MOV    R2, #1\n"
540                "MOV    R1, #0\n"
541                "MOV    R0, R9\n"
542                "BLX    R12\n"
543                "CMP    R0, #1\n"
544                "BNE    loc_FF875EF8\n"
545                "MOV    R0, #2\n"
546                "BL             sub_FF88FF78\n"
547                "B              loc_FF875EC4\n"
548
549"loc_FF875EF8:\n"
550                "LDR    R1, [R5,#0x64]\n"
551                "MOV    R0, R9\n"
552                "BLX    R1\n"
553
554                "MOV   R1, R4\n"           //  pointer to MBR in R1
555                "BL    mbr_read_dryos\n"   //  total sectors count in R0 before and after call
556
557        // Start of DataGhost's FAT32 autodetection code
558        // Policy: If there is a partition which has type W95 FAT32, use the first one of those for image storage
559        // According to the code below, we can use R1, R2, R3 and R12.
560        // LR wasn't really used anywhere but for storing a part of the partition signature. This is the only thing
561        // that won't work with an offset, but since we can load from LR+offset into LR, we can use this to do that :)
562        "MOV     R12, R4\n"                    // Copy the MBR start address so we have something to work with
563        "MOV     LR, R4\n"                     // Save old offset for MBR signature
564        "MOV     R1, #1\n"                     // Note the current partition number
565        "B       dg_sd_fat32_enter\n"          // We actually need to check the first partition as well, no increments yet!
566"dg_sd_fat32:\n"
567        "CMP     R1, #4\n"                     // Did we already see the 4th partition?
568        "BEQ     dg_sd_fat32_end\n"            // Yes, break. We didn't find anything, so don't change anything.
569        "ADD     R12, R12, #0x10\n"            // Second partition
570        "ADD     R1, R1, #1\n"                 // Second partition for the loop
571"dg_sd_fat32_enter:\n"
572        "LDRB    R2, [R12, #0x1BE]\n"          // Partition status
573        "LDRB    R3, [R12, #0x1C2]\n"          // Partition type (FAT32 = 0xB)
574        "CMP     R3, #0xB\n"                   // Is this a FAT32 partition?
575        "CMPNE   R3, #0xC\n"                   // Not 0xB, is it 0xC (FAT32 LBA) then?
576        "CMPNE   R3, #0x7\n"                   // exFat?
577        "BNE     dg_sd_fat32\n"                // No, it isn't. Loop again.
578        "CMP     R2, #0x00\n"                  // It is, check the validity of the partition type
579        "CMPNE   R2, #0x80\n"
580        "BNE     dg_sd_fat32\n"                // Invalid, go to next partition
581                                               // This partition is valid, it's the first one, bingo!
582        "MOV     R4, R12\n"                    // Move the new MBR offset for the partition detection.
583
584"dg_sd_fat32_end:\n"
585        // End of DataGhost's FAT32 autodetection code
586
587                "LDRB   R1, [R4,#0x1C9]\n"
588                "LDRB   R3, [R4,#0x1C8]\n"
589                "LDRB   R12, [R4,#0x1CC]\n"
590                "MOV    R1, R1,LSL#24\n"
591                "ORR    R1, R1, R3,LSL#16\n"
592                "LDRB   R3, [R4,#0x1C7]\n"
593                "LDRB   R2, [R4,#0x1BE]\n"
594//              "LDRB   LR, [R4,#0x1FF]\n"
595                "ORR    R1, R1, R3,LSL#8\n"
596                "LDRB   R3, [R4,#0x1C6]\n"
597                "CMP    R2, #0\n"
598                "CMPNE  R2, #0x80\n"
599                "ORR    R1, R1, R3\n"
600                "LDRB   R3, [R4,#0x1CD]\n"
601                "MOV    R3, R3,LSL#24\n"
602                "ORR    R3, R3, R12,LSL#16\n"
603                "LDRB   R12, [R4,#0x1CB]\n"
604                "ORR    R3, R3, R12,LSL#8\n"
605                "LDRB   R12, [R4,#0x1CA]\n"
606                "ORR    R3, R3, R12\n"
607//              "LDRB    R12, [R4,#0x1FE]\n"
608"                LDRB    R12, [LR,#0x1FE]\n" // +
609"                LDRB    LR, [LR,#0x1FF]\n" // +
610                "BNE    loc_FF875F84\n"
611                "CMP    R0, R1\n"
612                "BCC    loc_FF875F84\n"
613                "ADD    R2, R1, R3\n"
614                "CMP    R2, R0\n"
615                "CMPLS  R12, #0x55\n"
616                "CMPEQ  LR, #0xAA\n"
617                "MOVEQ  R7, R1\n"
618                "MOVEQ  R6, R3\n"
619                "MOVEQ  R4, #1\n"
620                "BEQ    loc_FF875F88\n"
621"loc_FF875F84:\n"
622                "MOV    R4, R8\n"
623"loc_FF875F88:\n"
624                "MOV    R0, #2\n"
625                "BL             sub_FF88FF78\n"
626                "CMP    R4, #0\n"
627                "BNE    loc_FF875FC4\n"
628                "LDR    R1, [R5,#0x64]\n"
629                "MOV    R7, #0\n"
630                "MOV    R0, R9\n"
631                "BLX    R1\n"
632                "MOV    R6, R0\n"
633                "B              loc_FF875FC4\n"
634
635"loc_FF875FB0:\n"
636                "MOV    R6, #0x40\n"
637                "B              loc_FF875FC4\n"
638
639"loc_FF875FB8:\n"
640                "LDR    R1, =0x597\n"
641                "LDR    R0, =0xFF875FD8\n"      // a_Mounter_c
642                "BL             _DebugAssert\n"
643
644"loc_FF875FC4:\n"
645                "STR    R7, [R5,#0x44]!\n"
646                "STMIB  R5, {R6,R8}\n"
647                "MOV    R0, #1\n"
648                "LDMFD  SP!, {R4-R10,PC}\n"
649 );
650}
651
652// Pointer to stack location where jogdial task records previous and current
653// jogdial positions
654short *jog_position;
655
656// Firmware version @ FF8657EC
657void __attribute__((naked,noinline)) JogDial_task_my() {
658 asm volatile(
659"                STMFD   SP!, {R4-R11,LR} \n"
660"                SUB     SP, SP, #0x24 \n"
661"                BL      sub_FF865B84 \n"
662"                LDR     R1, =0x25E8 \n"
663"                LDR     R6, =0xFFBB9788 \n"
664"                MOV     R0, #0 \n"
665"                ADD     R3, SP, #0x18 \n"
666
667// Save pointer for kbd.c routine
668" LDR R12, =jog_position \n"
669" STR R3, [R12] \n"
670
671"                ADD     R12, SP, #0x1C \n"
672"                ADD     R10, SP, #0x08 \n"
673"                MOV     R2, #0 \n"
674"                ADD     R9, SP, #0x10 \n"
675
676"loc_FF865818: \n"
677"                ADD     R12, SP, #0x1C \n"
678"                ADD     LR, R12, R0,LSL#1 \n"
679"                MOV     R2, #0 \n"
680"                ADD     R3, SP, #0x18 \n"
681"                STRH    R2, [LR] \n"
682"                ADD     LR, R3, R0,LSL#1 \n"
683"                STRH    R2, [LR] \n"
684"                STR     R2, [R9,R0,LSL#2] \n"
685"                STR     R2, [R10,R0,LSL#2] \n"
686"                ADD     R0, R0, #1 \n"
687"                CMP     R0, #2 \n"
688"                BLT     loc_FF865818 \n"
689
690"loc_FF865848: \n"
691"                LDR     R0, =0x25E8 \n"
692"                MOV     R2, #0 \n"
693"                LDR     R0, [R0,#8] \n"
694"                MOV     R1, SP \n"
695"                BL      sub_FF83A460 \n"
696"                CMP     R0, #0 \n"
697"                LDRNE   R1, =0x262 \n"
698"                                LDRNE   R0,=0xFF865AA8 \n" //aRotaryencoder_ ; "RotaryEncoder.c" \n"
699"                BLNE    _DebugAssert \n"
700"                LDR     R0, [SP] \n"
701"                AND     R4, R0, #0xFF \n"
702"                AND     R0, R0, #0xFF00 \n"
703"                CMP     R0, #0x100 \n"
704"                BEQ     loc_FF8658B8 \n"
705"                CMP     R0, #0x200 \n"
706"                BEQ     loc_FF8658F0 \n"
707"                CMP     R0, #0x300 \n"
708"                BEQ     loc_FF865AE8 \n"
709"                CMP     R0, #0x400 \n"
710"                BNE     loc_FF865848 \n"
711"                CMP     R4, #0 \n"
712"                LDRNE   R1, =0x2ED \n"
713"                                LDRNE   R0,=0xFF865AA8 \n" //aRotaryencoder_ ; "RotaryEncoder.c" \n"
714"                BLNE    _DebugAssert \n"
715"                RSB     R0, R4, R4,LSL#3 \n"
716"                LDR     R0, [R6,R0,LSL#2] \n"
717
718"loc_FF8658B0: \n"
719"                BL      sub_FF865B68 \n"
720"                B       loc_FF865848 \n"
721
722"loc_FF8658B8: \n"
723//------------------  added code ---------------------
724"labelA:\n"
725                "LDR     R0, =jogdial_stopped\n"
726                "LDR     R0, [R0]\n"
727                "CMP     R0, #1\n"
728                "BNE     labelB\n"
729                "MOV     R0, #40\n"
730                "BL      _SleepTask\n" //sleep
731                "B       labelA\n"
732"labelB:\n"
733//------------------  original code ------------------
734"                LDR     R7, =0x25F8 \n"
735"                LDR     R0, [R7,R4,LSL#2] \n"
736"                BL      sub_FF83B3F8 \n"
737
738//"                ADR     R2, dword_FF865738 \n"
739"                LDR     R2, =0xFF865738 \n"
740
741"                ADD     R1, R2, #0 \n"
742"                ORR     R3, R4, #0x200 \n"
743"                MOV     R0, #0x28 \n"
744"                BL      sub_FF83B314 \n"
745"                TST     R0, #1 \n"
746"                CMPNE   R0, #0x15 \n"
747"                STR     R0, [R10,R4,LSL#2] \n"
748"                BEQ     loc_FF865848 \n"
749"                MOV     R1, #0x274 \n"
750"                B       loc_FF865A94 \n"
751
752"loc_FF8658F0: \n"
753"                RSB     R5, R4, R4,LSL#3 \n"
754"                LDR     R0, [R6,R5,LSL#2] \n"
755"                LDR     R1, =0xC0240104 \n"
756"                LDR     R0, [R1,R0,LSL#8] \n"
757"                MOV     R2, R0,ASR#16 \n"
758"                ADD     R0, SP, #0x1C \n"
759"                ADD     R0, R0, R4,LSL#1 \n"
760"                STR     R0, [SP,#0x20] \n"
761"                STRH    R2, [R0] \n"
762"                ADD     R0, SP, #0x18 \n"
763"                ADD     R11, R0, R4,LSL#1 \n"
764"                LDRSH   R3, [R11] \n"
765"                SUB     R0, R2, R3 \n"
766"                CMP     R0, #0 \n"
767"                BNE     loc_FF865970 \n"
768"                LDR     R0, [R9,R4,LSL#2] \n"
769"                CMP     R0, #0 \n"
770"                BEQ     loc_FF865A50 \n"
771"                LDR     R7, =0x25F8 \n"
772"                LDR     R0, [R7,R4,LSL#2] \n"
773"                BL      sub_FF83B3F8 \n"
774
775//"                ADR     R2, sub_FF865744 \n"
776"                LDR     R2, =0xFF865744 \n"
777
778"                ADD     R1, R2, #0 \n"
779"                ORR     R3, R4, #0x300 \n"
780"                MOV     R0, #0x1F4 \n"
781"                BL      sub_FF83B314 \n"
782"                TST     R0, #1 \n"
783"                CMPNE   R0, #0x15 \n"
784"                STR     R0, [R7,R4,LSL#2] \n"
785"                BEQ     loc_FF865A50 \n"
786"                LDR     R1, =0x28D \n"
787"                B       loc_FF865A48 \n"
788
789"loc_FF865970: \n"
790"                MOV     R1, R0 \n"
791"                RSBLT   R0, R0, #0 \n"
792"                MOVLE   R7, #0 \n"
793"                MOVGT   R7, #1 \n"
794"                CMP     R0, #0xFF \n"
795"                BLS     loc_FF8659B0 \n"
796"                CMP     R1, #0 \n"
797"                RSBLE   R0, R3, #0xFF \n"
798"                ADDLE   R0, R0, #0x7F00 \n"
799"                ADDLE   R0, R0, R2 \n"
800"                RSBGT   R0, R2, #0xFF \n"
801"                ADDGT   R0, R0, #0x7F00 \n"
802"                ADDGT   R0, R0, R3 \n"
803"                ADD     R0, R0, #0x8000 \n"
804"                ADD     R0, R0, #1 \n"
805"                EOR     R7, R7, #1 \n"
806
807"loc_FF8659B0: \n"
808"                STR     R0, [SP,#0x04] \n"
809"                LDR     R0, [R9,R4,LSL#2] \n"
810"                CMP     R0, #0 \n"
811"                ADDEQ   R0, R6, R5,LSL#2 \n"
812"                LDREQ   R0, [R0,#8] \n"
813"                BEQ     loc_FF8659E8 \n"
814"                ADD     R8, R6, R5,LSL#2 \n"
815"                ADD     R1, R8, R7,LSL#2 \n"
816"                LDR     R1, [R1,#0x10] \n"
817"                CMP     R1, R0 \n"
818"                BEQ     loc_FF8659EC \n"
819"                LDR     R0, [R8,#0xC] \n"
820"                BL      sub_FF89BE30 \n"
821"                LDR     R0, [R8,#8] \n"
822
823"loc_FF8659E8: \n"
824"                BL      sub_FF89BE30 \n"
825
826"loc_FF8659EC: \n"
827"                ADD     R0, R6, R5,LSL#2 \n"
828"                ADD     R7, R0, R7,LSL#2 \n"
829"                LDR     R0, [R7,#0x10] \n"
830"                LDR     R1, [SP,#0x04] \n"
831"                BL      sub_FF89BD58 \n"
832"                LDR     R0, [R7,#0x10] \n"
833"                LDR     R7, =0x25F8 \n"
834"                STR     R0, [R9,R4,LSL#2] \n"
835"                LDR     R0, [SP,#0x20] \n"
836"                LDRH    R0, [R0] \n"
837"                STRH    R0, [R11] \n"
838"                LDR     R0, [R7,R4,LSL#2] \n"
839"                BL      sub_FF83B3F8 \n"
840
841//"                ADR     R2, sub_FF865744 \n"
842"                LDR     R2, =0xFF865744 \n"
843
844"                ADD     R1, R2, #0 \n"
845"                ORR     R3, R4, #0x300 \n"
846"                MOV     R0, #0x1F4 \n"
847"                BL      sub_FF83B314 \n"
848"                TST     R0, #1 \n"
849"                CMPNE   R0, #0x15 \n"
850"                STR     R0, [R7,R4,LSL#2] \n"
851"                BEQ     loc_FF865A50 \n"
852"                LDR     R1, =0x2CF \n"
853
854"loc_FF865A48: \n"
855"                                LDR     R0,=0xFF865AA8 \n" //aRotaryencoder_ ; "RotaryEncoder.c" \n"
856"                BL      _DebugAssert \n"
857
858"loc_FF865A50: \n"
859"                ADD     R0, R6, R5,LSL#2 \n"
860"                LDR     R0, [R0,#0x18] \n"
861"                CMP     R0, #1 \n"
862"                BNE     loc_FF865AE0 \n"
863"                LDR     R0, =0x25E8 \n"
864"                LDR     R0, [R0,#0x0C] \n"
865"                CMP     R0, #0 \n"
866"                BEQ     loc_FF865AE0 \n"
867
868//"                ADR     R2, dword_FF865738 \n"
869"                LDR     R2, =0xFF865738 \n"
870
871"                ADD     R1, R2, #0 \n"
872"                ORR     R3, R4, #0x400 \n"
873"                BL      sub_FF83B314 \n"
874"                TST     R0, #1 \n"
875"                CMPNE   R0, #0x15 \n"
876"                STR     R0, [R10,R4,LSL#2] \n"
877"                BEQ     loc_FF865848 \n"
878"                LDR     R1, =0x2D6 \n"
879
880"loc_FF865A94: \n"
881"                                LDR     R0,=0xFF865AA8 \n" //aRotaryencoder_ ; "RotaryEncoder.c" \n"
882"                BL      _DebugAssert \n"
883"                B       loc_FF865848 \n"
884
885"loc_FF865AE0: \n"
886"                LDR     R0, [R6,R5,LSL#2] \n"
887"                B       loc_FF8658B0 \n"
888
889"loc_FF865AE8: \n"
890"                LDR     R0, [R9,R4,LSL#2] \n"
891"                CMP     R0, #0 \n"
892"                MOVEQ   R1, #0x2E0 \n"
893"                                LDREQ   R0,=0xFF865AA8 \n" //aRotaryencoder_ ; "RotaryEncoder.c" \n"
894"                BLEQ    _DebugAssert \n"
895"                RSB     R0, R4, R4,LSL#3 \n"
896"                ADD     R0, R6, R0,LSL#2 \n"
897"                LDR     R0, [R0,#0xC] \n"
898"                BL      sub_FF89BE30 \n"
899"                MOV     R2, #0 \n"
900"                STR     R2, [R9,R4,LSL#2] \n"
901"                B       loc_FF865848 \n"
902);
903}
Note: See TracBrowser for help on using the repository browser.