1

I'm reading the start.S assembly code for the Zircon Kernel (Fuchsia OS):

https://fuchsia.googlesource.com/fuchsia/+/master/zircon/kernel/arch/arm64/start.S

There's this line:

.text
FUNCTION(_start)

I think this is the first thing ever that get executed on the kernel. However, for it to be true, _start should be global. I couldn't determine if it is or not.

There's this other line:

// This symbol is used by image.S
.global IMAGE_ELF_ENTRY
IMAGE_ELF_ENTRY = _start

that suggests something like it.

What is FUNCTION on FUNCTION(_start)? I tried searching for "assembly FUNCTION macro" but found nothing related to this.

It looks like this is the first code run, but I could not determine where it branches to real kernel code (C++ code) so I'm in doubt.

Paprika
  • 402
  • 5
  • 18
  • [`FUNCTION` is an assembly directive for marking the start of a function.](https://www.keil.com/support/man/docs/armasm/armasm_dom1361290014133.htm) IN that link it is said it is used for DWARF symbols, I assume it also makes the symbol globally visible. Note that I searched "arm assembly FUNCTION", always include the architecture in your queries ;) The jump to the kernel should be around [here](https://fuchsia.googlesource.com/fuchsia/+/master/zircon/kernel/arch/arm64/start.S#299) but I'm not used to ARM. That just looks like an entry-point and `bl .` looks like an infinite fallback loop. – Margaret Bloom Nov 13 '20 at 09:24

1 Answers1

4

The definition of these macros can be found in //zircon/kernel/include/asm.h, it's basically a wrapper that adds all the required annotations, including CFI directives.

So FUNCTION(_start) would expand to:

.global _start;
.hidden _start;
.type _start,STT_FUNC;
_start:
  .cfi_startproc

The branching to C++ code happens on the bl lk_main instruction.

Marco
  • 2,796
  • 19
  • 24