ARM7 compiler doing funny things

Comments

18 comments

  • Avatar
    Paul Curtis

    A compilable piece of code would help.

           E1A0C00D   mov r12, sp

    r12 = sp_0

           E92DD800   stmfd sp!, {r11-r12, lr-pc}

    sp = sp_0 - 16


           E24CB004   sub r11, r12, #0x00000004

    r11 = sp_0 - 4


           E24DD008   sub sp, sp, #0x00000008

    sp = sp_0 - 24


           E50B0014   str r0, [r11, #-0x014]

    store r0 to sp_0 - 24

    r0 is 'this' which is stored into the stack frame; it's not outside the stack frame.

    0
    Comment actions Permalink
  • Avatar
    Michael Woods

    when you say 'this' are you refering to the instance of the class, because if you are, please be aware that the method is a static method and there is no this being passed.

    I have also attached the code that I have been using, it utilised the singleton type of class, where the Constructor is protected.

    To call the Class methods use the form

    Timing::getInstance()->(someMethod());

    0
    Comment actions Permalink
  • Avatar
    Paul Curtis

    > when you say 'this' are you refering to the instance of the class, because if you are, please be aware that the method is a static method and there is no this being passed.

    > To call the Class methods use the form
    > Timing::getInstance()->(someMethod());

    Huh?  If someMethod() is static then you don't need getInstance you just use Timing::someMethod().  If someMethod is not static and even if a singleton instance exists, then a 'this' is passed to someMethod().

    You code is, unfortunately, buggy, so you need to read a C++ book.

     

    Timing * Timing::getInstance() {
      if(instance == 0){
        Timing timer;
        instance = &timer;
      }
      return instance;
    }
    Timing * Timing::getInstance() {
      if(instance == 0){
        Timing timer;
        instance = &timer;
      }
      return instance;
    }
    

    This creates a Timing object, you take a pointer to it, then the Timing object is destroyed. Your pointer dangles. You now have no Timing objects yet you are referring to a destructed one through 'instance' in your other methods.

    0
    Comment actions Permalink
  • Avatar
    Michael Woods

    >This creates a Timing object, you take a pointer to it, then the Timing object is destroyed. Your pointer dangles. You now have no Timing objects yet you are referring to a destructed one through 'instance' in your other methods.

    This was my only option because the 'new' operator wasnt working properly I would have prefered to have the line being

    instance = new Timing();

    however this was resulting in the abort routine being called, i tried to increase the heap size but this didnt work.

    0
    Comment actions Permalink
  • Avatar
    Paul Curtis

    You will need to ensure that the heap is word-aligned.

    Alternatively, you can use placement new to construct the object.

    0
    Comment actions Permalink
  • Avatar
    Michael Woods

    I have had a quick look through all of your "How Do I..." posts that you have made, but there is nothing about ensuring that the heap is word-aligned, I have read the heap size post however this doesnt tell me how to ensure that the heap is word-aligned, and I am unsure in how to do that. This is the only code snipet that I could find that was relevant;

     

    /* Initialise the heap */
      ldr r0, = __heap_start__
      ldr r1, = __heap_end__
      sub r1, r1, r0
      cmp r1, #8
      movge r2, #0
      strge r2, [r0], #+4
      strge r1, [r0]

    this was taken from the basic crt0.s file that is supply with the lpc2138 package

    0
    Comment actions Permalink
  • Avatar
    Paul Curtis

    After this line:

    > ldr r0, = __heap_start__

    ...ensure that r0 is divisible by 4.  If not, there's a problem to be addressed.

    0
    Comment actions Permalink
  • Avatar
    Paul Curtis

    ...after this line:

    >  sub r1, r1, r0

    Ensure that r1 is divisible by 4 also.

    0
    Comment actions Permalink
  • Avatar
    Michael Woods

    yeah both r0 and r1 are divisible by 4, so that leaves just the new operator not working, unless there is anything else you can think of?

    I will try the placement new to see if this fixes the problem, because it should bypass the malloc code.

    0
    Comment actions Permalink
  • Avatar
    Paul Curtis

    ...after this line:

    >  sub r1, r1, r0

    r1 will be your heap size, in bytes.  So take a look to see what it is.  Then see what you're passing to malloc.  You could simply be running out of heap.

    0
    Comment actions Permalink
  • Avatar
    Michael Woods

    How would I work out what value I am passing to malloc? Because in the heap code that I have above i have 0x2000 size of the heap, which should be really over the top, but i dont see any of those numbers while I step through the malloc code.

    0
    Comment actions Permalink
  • Avatar
    Paul Curtis

    Place a breakpoint on malloc entry and look at r0.

    0
    Comment actions Permalink
  • Avatar
    Michael Woods

    the r0 value only appears to be 0x24, which is much less than the memory that I need to allocate, however, the r0 register doesnt change from when it enters the new operator entry

    0
    Comment actions Permalink
  • Avatar
    Paul Curtis

    > the r0 value only appears to be 0x24, which is much less than the memory that I need to allocate

    If you enter malloc with r0=0x24, you're allocating 36 bytes.  You might want to see if you enter malloc again.  The malloc code runs without issue, it's bug-free.

    0
    Comment actions Permalink
  • Avatar
    Michael Woods

    the malloc code is only entered once,

    the abort routine is activated after this line

    ldr r3, [r0, #+0x004]

    where:

    r0 = 0xe58d2004

    r3 = 0x37

     

    0
    Comment actions Permalink
  • Avatar
    Michael Woods

    it looks like its trying to access .data which looks to be only 4 bytes long, and the value that is in r0 is the value that is in the .data section, but i cant see where the .data section is defined

    0
    Comment actions Permalink
  • Avatar
    Michael Woods

    I have tried to implement a placement new to allocate the memory, but that didnt seem to be the problem ( ie memory allocation). I tried to just do an

    int *value  = new int;

    and this line still behaved in the same way as before, and since you are adamant that there is no bugs in the malloc code, the only logical next problem would be in my project configuration.

    i think the configuration settings are in the .hzp file so i will upload that

    0
    Comment actions Permalink
  • Avatar
    Paul Curtis

    > r0 = 0xe58d2004

    That's an instruction.

    0
    Comment actions Permalink

Please sign in to leave a comment.