[ESP8266 nonOS sdk] Can't execute my own function pointer

sedlacek.david
Posts: 15
Joined: Thu Jul 12, 2018 2:06 pm

[ESP8266 nonOS sdk] Can't execute my own function pointer

Postby sedlacek.david » Fri May 03, 2019 3:23 am

Hi, have a strange problem. Trying to manually load IRAM/DRAM contents from the flash and execute an entry function. Basically I'm trying to mimic a simple bootloader.

I have managed to load everything correctly = verified by reading out the memory. What is really strange to me is when I execute a memory where is supposed to be call_user_main(), it crashes on:

Code: Select all

Fatal exception (0):
                                                         
epc1=0x4010fd7d, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x0
0000000


The code is:

Code: Select all

void Cache_Read_Enable(UINT8 odd_even, UINT8 mb_count, UINT8 no_idea);
//void Cache_Read_Enable(uint32 odd_even, uint32 mb_count, uint32 no_idea);
typedef void usercode(void);

void call_user_start()
{
    UINT32 ret = 0x40260000 + 0x1000 + sizeof(header_t);
   
    usercode* user = (usercode*)loadrom(ret);   //0x40100004
    Cache_Read_Enable(0, 0, 1);
   [b]user(); [/b] //this throws the exception!!

    while(1)
    {
       ;
    }
}


I have verified that IRAM address 0x40100004 contains what it supposed to contain. It is value "21 FF FF 20" and the double word before on address 0x40100000 contains value 0x40100000.

As I understood, the value is probably not correct instruction - assuming from Exception #0 = invalid instruction.

What can be possibly wrong? Thank you David.
Last edited by sedlacek.david on Fri May 03, 2019 3:51 am, edited 1 time in total.

sedlacek.david
Posts: 15
Joined: Thu Jul 12, 2018 2:06 pm

Re: Can't execute my own function pointer

Postby sedlacek.david » Fri May 03, 2019 3:26 am

Forgot to mention that loadrom() returns exactly 0x40100004 - thats where the entry point of an application I'm loading sits.

And epc1=0x4010fd7d is an address somewhere at the end of call_user_start() function I posted above.

sedlacek.david
Posts: 15
Joined: Thu Jul 12, 2018 2:06 pm

Re: Can't execute my own function pointer

Postby sedlacek.david » Fri May 03, 2019 3:31 am

I'm sorry for the confusion, but I just figured out that it is not my pointer what is causing the exception. It is the Cache_Read_Enable function... And don't know why.

sedlacek.david
Posts: 15
Joined: Thu Jul 12, 2018 2:06 pm

Re: Can't execute my own function pointer

Postby sedlacek.david » Fri May 03, 2019 3:50 am

If I remove the Cache_Read_Enable I got this:

Code: Select all

sp 0x3ffff7c0
                                                               
epc1=0x40001800, epc2=0x00000000, epc3=0x00000000, excvaddr=0x0068e0f1, depc=0x0
0000000
                                                                       
Fatal exception (28):
                                                       
epc1=0x40001800, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00637ff0, depc=0x0
0000000
                                                                       
Fatal exception (28):
                                                       
epc1=0x40001800, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00637ff0, depc=0x0
0000000

sedlacek.david
Posts: 15
Joined: Thu Jul 12, 2018 2:06 pm

Re: [ESP8266 nonOS sdk] Can't execute my own function pointer

Postby sedlacek.david » Sun May 05, 2019 12:37 am

Just for the others. It was my mistake - the address I was loading wasn't correct.

Who is online

Users browsing this forum: No registered users and 274 guests