SX720 Porting thread - page 7 - DryOS Development - CHDK Forum  

SX720 Porting thread

  • 158 Replies
  • 42414 Views
*

Offline reyalp

  • ******
  • 12297
Re: SX720 Porting thread
« Reply #60 on: 03 / April / 2016, 15:27:42 »
Advertisements
I am calling that with a BL but not sure which registers are trashed, will use better ASM_SAFE("BL...
Function calls can change R0-R3, R12 and CPSR

If you make a function that returns it's first argument, it's pretty much safe to call after any canon function call (except conditional stuff, the compiler might generate things like MOVS even if your code does nothing conditional). E.g.
Code: [Select]
int turn_on_led(int x) {
 *(volatile int*)0xd20b0994 = 0x4d0002;
  return x;
}
This works because the canon compiler knows R1-R3, R12 and CPSR are trashed, and the return value from the previous call is preserved as x.

I haven't actually tried ASM_SAFE in thumb2, but if it compiles it should be OK. Note that IT blocks have special rules, so you can't just put arbitrary code there even with ASM_SAFE
Don't forget what the H stands for.

*

Offline asm1989

  • *****
  • 527
  • SX720, SX260, SX210 & SX200
Re: SX720 Porting thread
« Reply #61 on: 09 / April / 2016, 06:42:45 »
I am still stuck in boot, blink works ok, but seems to hang here "ldr     r0, =hook_CreateTask\n"  before that I can blink ok,  any clue?
Code: [Select]



void __attribute__((naked,noinline)) boot() {


//sx720
    asm volatile ( // 0xfc02000c
"    movw    r0, #0x4000\n"
"    movt    r0, #0\n"
"    mov     sp, r0\n"
"    bl      sub_fc02007e\n"
"    ldr     r2, =0xc0242010\n"
"    ldr     r1, [r2]\n"
"    orr     r1, r1, #1\n"
"    str     r1, [r2]\n"
"    ldr     r0, =0xfcd3b79c\n"  // code copied from ROM
"    ldr     r1, =0x010e1000\n"   // to ram
"    ldr     r3, =0x010fce10\n"
"loc_fc02002a:\n"
"    cmp     r1, r3\n"
"    itt     lo\n"
"    ldrlo   r2, [r0], #4\n"
"    strlo   r2, [r1], #4\n"
"    blo     loc_fc02002a\n"
"    ldr     r0, =0x010e1000\n"
"    ldr     r1, =0x0001be10\n"
"    bl      sub_fc13d49a\n"     // cache stuff, function used in loader
"    ldr     r0, =0xfcd575ac\n"  // DATA copied
"    ldr     r1, =0xbfe10800\n"  // to RAM
"    ldr     r3, =0xbfe1751d\n"


"loc_fc020046:\n"
"    cmp     r1, r3\n"
"    itt     lo\n"
"    ldrlo   r2, [r0], #4\n"
"    strlo   r2, [r1], #4\n"
"    blo     loc_fc020046\n"     /// task hook here due to dual ram sugested by reyalp
   // Install CreateTask patch
        "adr     r0, patch_CreateTask\n"    // Patch data
        "ldm     r0, {r1,r2}\n"             // Get two patch instructions
        "ldr     r0, =hook_CreateTask\n"    // Address to patch (hook_ has thumb bit off)
        "stm     r0, {r1,r2}\n"             // Store patch instructions

*

Offline srsa_4c

  • ******
  • 4078
Re: SX720 Porting thread
« Reply #62 on: 09 / April / 2016, 08:40:37 »
I am still stuck in boot, blink works ok, but seems to hang here "ldr     r0, =hook_CreateTask\n"  before that I can blink ok,  any clue?
How does your main.bin.dump (in platform/sx720/sub/100e) look like (the one that hangs)? Can you share it (and perhaps the current source) on a site such as this one: http://filebin.net/ ?

Also, I think it has already been mentioned that for the first attempt, you should try booting without task replacement code - just leave out that taskhook patch.

*

Offline asm1989

  • *****
  • 527
  • SX720, SX260, SX210 & SX200
Re: SX720 Porting thread
« Reply #63 on: 09 / April / 2016, 09:14:20 »
Thanks srsa_4c, attached dump, and the full sources with the last build are here http://filebin.net/j8v0njj83i
without the 4 hook lines in boot it gets to a few lines bellow in boot but fails too




*

Offline srsa_4c

  • ******
  • 4078
Re: SX720 Porting thread
« Reply #64 on: 09 / April / 2016, 09:53:52 »
Thanks srsa_4c, attached dump, and the full sources with the last build are here http://filebin.net/j8v0njj83i
without the 4 hook lines in boot it gets to a few lines bellow in boot but fails too
I think you're still trashing registers. I'll post safe asm versions of the LED routines.

*

Offline asm1989

  • *****
  • 527
  • SX720, SX260, SX210 & SX200
Re: SX720 Porting thread
« Reply #65 on: 09 / April / 2016, 09:58:51 »
I am using this two
Code: [Select]
int blinkout(int x)
{
    *(volatile int*)0xd20b0994 = 0x4c0003;
    return x;
}
int blinkin(int x)
{
    *(volatile int*)0xd20b0994 = 0x4d0002;
    return x;
}


*

Offline srsa_4c

  • ******
  • 4078
Re: SX720 Porting thread
« Reply #66 on: 09 / April / 2016, 10:09:13 »
I am using this two
Code: [Select]
int blinkout(int x)
{
    *(volatile int*)0xd20b0994 = 0x4c0003;
    return x;
}
int blinkin(int x)
{
    *(volatile int*)0xd20b0994 = 0x4d0002;
    return x;
}
They might look innocent, but this is their compiled version:
Code: [Select]
00395564 <blinkout>:
  395564: 4a01      ldr r2, [pc, #4] ; (39556c <blinkout+0x8>)
  395566: 4b02      ldr r3, [pc, #8] ; (395570 <blinkout+0xc>)
  395568: 601a      str r2, [r3, #0]
  39556a: 4770      bx lr
  39556c: 004c0003 .word 0x004c0003
  395570: d20b0994 .word 0xd20b0994

00395574 <blinkin>:
  395574: 4a01      ldr r2, [pc, #4] ; (39557c <blinkin+0x8>)
  395576: 4b02      ldr r3, [pc, #8] ; (395580 <blinkin+0xc>)
  395578: 601a      str r2, [r3, #0]
  39557a: 4770      bx lr
  39557c: 004d0002 .word 0x004d0002
  395580: d20b0994 .word 0xd20b0994
They are trashing r2 and r3.

Use these instead:
Code: [Select]
void __attribute__((naked,noinline)) blinkin() {
    asm volatile (
"    push    {r0, r1} \n"
"    ldr     r0, =0xd20b0994 \n"
"    ldr     r1, =0x4d0002 \n"
"    str     r1, [r0] \n"
"    pop     {r0, r1} \n"
"    bx      lr \n"
    );
}

void __attribute__((naked,noinline)) blinkout() {
    asm volatile (
"    push    {r0, r1} \n"
"    ldr     r0, =0xd20b0994 \n"
"    ldr     r1, =0x4c0003 \n"
"    str     r1, [r0] \n"
"    pop     {r0, r1} \n"
"    bx      lr \n"
    );
}

*

Offline asm1989

  • *****
  • 527
  • SX720, SX260, SX210 & SX200
Re: SX720 Porting thread
« Reply #67 on: 09 / April / 2016, 10:19:20 »
Thanks srsa_4c using these two get the crash in the same places


*

Offline srsa_4c

  • ******
  • 4078
Re: SX720 Porting thread
« Reply #68 on: 09 / April / 2016, 10:23:47 »
Thanks srsa_4c using these two get the crash in the same places
Okay. Now, can you upload the boot.c that is crashing and the corresponding main.bin.dump created during build? Just the 2 files.

*

Offline asm1989

  • *****
  • 527
  • SX720, SX260, SX210 & SX200
Re: SX720 Porting thread
« Reply #69 on: 09 / April / 2016, 10:36:15 »

 

Related Topics