[RevEng][x86][x64][C][newbies] Software reset in embedded devices

Happy New Year!

This is a popular recipe for embedded (pure) C, to reset device:

void reset()
{
        ((void(*)(void))0)();
};

Looks creepy!

It's easier to understand it if to compile.

GCC 14.2 non-optimized:

reset:
    endbr64
    push    rbp
    mov rbp, rsp
    mov eax, 0
    call    rax
    nop
    pop rbp
    ret

GCC 14.2 optimized:

reset:
    endbr64
    xor eax, eax
    jmp rax

Many embedded CPUs starts at 0th address upon power on or reset. Here we simply jump to address 0, where (presumably) firmware is located.

That pure C code simply calls a function by pointer. There is no (portable) way in pure C to jump to 0th address, but we can call some 'function' there. What about stack? Local variables? All that is dropped by firmware code at 0th address.

void(*)(void) is type of function pointer, that accepts no arguments (void) and return no result (void again).

(void(*)(void))0 is zero address is casted to that type.

((void(*)(void))0)(); is function call.

Bottom line - sometimes compilation can help in understanding such tricks.

(the post first published at 20260101.)


List of my other blog posts. Subscribe to my news feed,
If you enjoy my work, you can support it on patreon.
Some time ago (before 24-Mar-2025) there was Disqus JS script for comments. I dropped it --- it was so motley, distracting, animated, with too much ads. I never liked it. Also, comments din't appeared correctly (Disqus was buggy). Also, my blog is too chamberlike --- not many people write comments here. So I decided to switch to the model I once had at least in 2020 --- send me your comments by email (don't forget to include URL to this blog post) and I will copy&paste it here manually.
Let's party like it's ~1993-1996, in this ultimate, radical and uncompromisingly primitive pre-web1.0-style blog and website. This website is best viewed under lynx/links/elinks/w3m.