How are asm labeled functions called? [Resolved]

Victoria Nope
Posts: 75
Joined: Fri Dec 04, 2020 9:56 pm

How are asm labeled functions called? [Resolved]

Postby Victoria Nope » Mon Dec 21, 2020 8:02 am

Hello,

would somebody be so kind and post me here disassembly of the following code, specifically calls mentioned in the comments, please?

1. Direct calling IDF and FreeRTOS functions

main.c

Code: Select all

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/timer.h"

void app_main() {
    vTaskDelay(1000); // 1.1. disassembly of direct FreeRTOS function call
    timer_set_counter_value(0, 1, 100); // 1.2. disassembly of direct IDF function call
}
2. Calling asm labeled IDF and FreeRTOS functions

myaliases.h

Code: Select all

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/timer.h"

void MyTaskDelay(const TickType_t MyTicksToDelay) asm ("vTaskDelay");
esp_err_t MyTimerSetCounterValue(timer_group_t MyGroupNum, timer_idx_t MyTimerNum, uint64_t MyLoadVal) asm ("timer_set_counter_value");
main.c

Code: Select all

#include <stdio.h>
#include "myaliases.h"

void app_main() {
    MyTaskDelay(1000); // 2.1. disassembly of the asm labeled FreeRTOS function call
    MyTimerSetCounterValue(0, 1, 100); // 2.2. disassembly of the asm labeled IDF function call
}
All I would like to know is whether the function calls are different or not. I don't have any debuggable HW and as far as I understamd, there is no debugging emulator, so I cannot see disassembly myself. Could somebody post here disassembly of those 4 function calls, please?

This is related to my previous questions:

- Function alias for IDF
- How to show disassembly using VS Code without debugging HW?

Thank you
Have a nice day
Last edited by Victoria Nope on Tue Dec 22, 2020 5:39 am, edited 2 times in total.

Dazza0
Espressif staff
Espressif staff
Posts: 308
Joined: Fri Jun 02, 2017 6:50 am

Re: How are asm labeled functions called?

Postby Dazza0 » Mon Dec 21, 2020 9:07 am

You can get the disassembly yourself by running either objdump or gdb:

Assuming your project folder is "hello-world":

Code: Select all

cd hello-world
xtensa-esp32-elf-gdb ./build/hello-world.elf
Once in GDB, run:

Code: Select all

disassemble app_main

Victoria Nope
Posts: 75
Joined: Fri Dec 04, 2020 9:56 pm

Re: How are asm labeled functions called?

Postby Victoria Nope » Tue Dec 22, 2020 3:16 am

1. Solution

Thank you very much! I have used the xtensa-esp32-elf-gdb way.

2. Off topic

So the dump shown me that a function asm label works essentially as an alias because the disassembly code equals in both code snippets from my question:

Code: Select all

Dump of assembler code for function app_main:
   0x400d08fc <+0>:     entry   a1, 32
   0x400d08ff <+3>:     movi    a10, 1
   0x400d0902 <+6>:     call8   0x40085f04 <vTaskDelay>                ; same for call 1.1. and 2.1.
   0x400d0905 <+9>:     l32r    a12, 0x400d0020 <_stext>
   0x400d0908 <+12>:    l32r    a13, 0x400d0024 <_stext+4>
   0x400d090b <+15>:    movi    a11, 3
   0x400d090e <+18>:    movi    a10, 2
   0x400d0911 <+21>:    call8   0x400d0938 <timer_set_counter_value>   ; same for call 1.2. and 2.2.
   0x400d0914 <+24>:    retw.n
End of assembler dump.
Which (I hope with no hidden problems; except the maintenance) allows one to create e.g. library with own function aliases and parameter names that are further suggested e.g. in VS Code PlatformIO extension's Code Insight system.

Why is aliased function called directly even if I put alias definition before the function definition I cannot explain. For the code like e.g.:

myaliases.h

Code: Select all

int MyFunction(int MyParameter) asm ("my_function");

int my_function(int my_parameter) {
    return my_parameter;
}
main.c

Code: Select all

#include <stdio.h>
#include "myaliases.h"

void app_main() {
    MyFunction(1);
}
is generated disassembly:

Code: Select all

Dump of assembler code for function app_main:
   0x400d08d8 <+0>:     entry   a1, 32
   0x400d08db <+3>:     movi.n  a10, 1
   0x400d08dd <+5>:     call8   0x400e225c <my_function>
   0x400d08e0 <+8>:     retw.n
End of assembler dump.
According to GCC, the alias should be used in the assembler code. But in such case I would expect the MyFunction to be called rather than my_function. But that's a different topic...

Who is online

Users browsing this forum: Applebot, Baidu [Spider], ChatGPT-User, Google [Bot], PerplexityBot, PetalBot, Qwantbot and 6 guests