This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Baremetal program jumps to 0x200

Hello, I am trying to run a "hello world" program with C/C++ standard library support on Morello board (hardware), using Arm Development Studio Morello edition.

I previously followed the standalone-baremetal-readme.rst guide which worked well (following the advice from this topic), but it did not allow to use functions like "printf".

I tried to use examples from:

https://git.morello-project.org/morello/llvm-project-releases/-/tree/morello/baremetal-release-1.6?ref_type=heads

I ran make and the "make-bm-image.sh" with "-e" flag to produce "howdy-purecap-bm-image.elf" and "howdy-morello-bm-image.elf" (in the "make-bm-image.sh" script I added a line to preserve a copy of the .elf file), then I loaded these in the development studio.

It appears that the program goes to address 0x200 after executing the "MRS" instruction.

Does anyone know why that happens?

Also, in the standalone-baremetal-readme.rst guide it was necessary to specify UART address (0x2A400000) in the program, is it correct to assume that examples from baremetal-release-1.6 branch of llvm-project-releases will use that address (without the need to specify it anywhere in the program) and the printf/cout messages will appear in the AP com port of Morello hardware board? Or is it necessary to do some adjustments to achieve that?

Parents
  • In attempt to run a baremetal program using C standard library function on hardware, I also tried using GNU Morello toolchain (arm-gnu-toolchain-10.1.morello-alp2-x86_64-aarch64-none-elf.tar.xz),

    I am not familiar with integrating standard library to embedded systems so I tried to follow this tutorial:

    https://www.youtube.com/watch?v=AzYC5hO2uJk

    I used the following makefile, linker script and "syscalls.c" trying to compile a "hello_world" program (I uploaded all files to Github):

    - Makefile

    - linker_script.ld

    - hello_world.c

    - syscalls.c (with modified _read and _write functions to use 0x2a400000 address, and modified _sbrk to use the HEAP_START symbol from the linker script, I verified that this kind of setup worked well using riscv-unknown-elf toolchain before)

    During compilation I got error about undefined functions like this:

    michal@ubuntu22-04:~/morello/standalone_build/helloworld$ make
    aarch64-none-elf-gcc -march=morello+c64 -mabi=purecap -static -fvisibility=hidden -I../include -g -o hello_world hello_world.o ./syscalls.o -T linker_script.ld
    /home/michal/arm-gnu-toolchain-10.1.morello-alp2-x86_64-aarch64-none-elf/bin/../lib/gcc/aarch64-none-elf/10.1.0/../../../../aarch64-none-elf/bin/ld: /home/michal/arm-gnu-toolchain-10.1.morello-alp2-x86_64-aarch64-none-elf/bin/../lib/gcc/aarch64-none-elf/10.1.0/../../../../aarch64-none-elf/lib/purecap/c64/crt0.o: in function `.pure':
    /data/jenkins/workspace/GNU-toolchain/morello-trunk/src/newlib-cygwin/libgloss/aarch64/crt0.S:243: undefined reference to `__init_global_caps'
    /data/jenkins/workspace/GNU-toolchain/morello-trunk/src/newlib-cygwin/libgloss/aarch64/crt0.S:243:(.text+0x184): relocation truncated to fit: R_MORELLO_CALL26 against undefined symbol `__init_global_caps'
    /home/michal/arm-gnu-toolchain-10.1.morello-alp2-x86_64-aarch64-none-elf/bin/../lib/gcc/aarch64-none-elf/10.1.0/../../../../aarch64-none-elf/bin/ld: /data/jenkins/workspace/GNU-toolchain/morello-trunk/src/newlib-cygwin/libgloss/aarch64/crt0.S:244: undefined reference to `__processRelocs'
    /data/jenkins/workspace/GNU-toolchain/morello-trunk/src/newlib-cygwin/libgloss/aarch64/crt0.S:244:(.text+0x188): relocation truncated to fit: R_MORELLO_CALL26 against undefined symbol `__processRelocs'
    /home/michal/arm-gnu-toolchain-10.1.morello-alp2-x86_64-aarch64-none-elf/bin/../lib/gcc/aarch64-none-elf/10.1.0/../../../../aarch64-none-elf/bin/ld: hello_world.o(.rela.got+0xf0): warning: relocation R_MORELLO_ADR_GOT_PAGE against symbol 'SBSS_START' in section without permission flags '.sbss'.  Assuming Read-Write.
    /home/michal/arm-gnu-toolchain-10.1.morello-alp2-x86_64-aarch64-none-elf/bin/../lib/gcc/aarch64-none-elf/10.1.0/../../../../aarch64-none-elf/bin/ld: hello_world.o(.rela.got+0x10): warning: relocation R_MORELLO_ADR_GOT_PAGE against symbol 'SBSS_END' in section without permission flags '.sbss'.  Assuming Read-Write.
    collect2: error: ld returned 1 exit status
    make: *** [Makefile:43: hello_world] Error 1

    From what I see, the __init_global_caps and __process_relocs functions are in the following file (assumming that the newlib from link below is the same newlib used in the GNU toolchain):

    https://git.morello-project.org/morello/newlib/-/blob/morello/master/libgloss/aarch64/relocs.c

    But for some reason the error message says these functions/symbols are undefined.

Reply
  • In attempt to run a baremetal program using C standard library function on hardware, I also tried using GNU Morello toolchain (arm-gnu-toolchain-10.1.morello-alp2-x86_64-aarch64-none-elf.tar.xz),

    I am not familiar with integrating standard library to embedded systems so I tried to follow this tutorial:

    https://www.youtube.com/watch?v=AzYC5hO2uJk

    I used the following makefile, linker script and "syscalls.c" trying to compile a "hello_world" program (I uploaded all files to Github):

    - Makefile

    - linker_script.ld

    - hello_world.c

    - syscalls.c (with modified _read and _write functions to use 0x2a400000 address, and modified _sbrk to use the HEAP_START symbol from the linker script, I verified that this kind of setup worked well using riscv-unknown-elf toolchain before)

    During compilation I got error about undefined functions like this:

    michal@ubuntu22-04:~/morello/standalone_build/helloworld$ make
    aarch64-none-elf-gcc -march=morello+c64 -mabi=purecap -static -fvisibility=hidden -I../include -g -o hello_world hello_world.o ./syscalls.o -T linker_script.ld
    /home/michal/arm-gnu-toolchain-10.1.morello-alp2-x86_64-aarch64-none-elf/bin/../lib/gcc/aarch64-none-elf/10.1.0/../../../../aarch64-none-elf/bin/ld: /home/michal/arm-gnu-toolchain-10.1.morello-alp2-x86_64-aarch64-none-elf/bin/../lib/gcc/aarch64-none-elf/10.1.0/../../../../aarch64-none-elf/lib/purecap/c64/crt0.o: in function `.pure':
    /data/jenkins/workspace/GNU-toolchain/morello-trunk/src/newlib-cygwin/libgloss/aarch64/crt0.S:243: undefined reference to `__init_global_caps'
    /data/jenkins/workspace/GNU-toolchain/morello-trunk/src/newlib-cygwin/libgloss/aarch64/crt0.S:243:(.text+0x184): relocation truncated to fit: R_MORELLO_CALL26 against undefined symbol `__init_global_caps'
    /home/michal/arm-gnu-toolchain-10.1.morello-alp2-x86_64-aarch64-none-elf/bin/../lib/gcc/aarch64-none-elf/10.1.0/../../../../aarch64-none-elf/bin/ld: /data/jenkins/workspace/GNU-toolchain/morello-trunk/src/newlib-cygwin/libgloss/aarch64/crt0.S:244: undefined reference to `__processRelocs'
    /data/jenkins/workspace/GNU-toolchain/morello-trunk/src/newlib-cygwin/libgloss/aarch64/crt0.S:244:(.text+0x188): relocation truncated to fit: R_MORELLO_CALL26 against undefined symbol `__processRelocs'
    /home/michal/arm-gnu-toolchain-10.1.morello-alp2-x86_64-aarch64-none-elf/bin/../lib/gcc/aarch64-none-elf/10.1.0/../../../../aarch64-none-elf/bin/ld: hello_world.o(.rela.got+0xf0): warning: relocation R_MORELLO_ADR_GOT_PAGE against symbol 'SBSS_START' in section without permission flags '.sbss'.  Assuming Read-Write.
    /home/michal/arm-gnu-toolchain-10.1.morello-alp2-x86_64-aarch64-none-elf/bin/../lib/gcc/aarch64-none-elf/10.1.0/../../../../aarch64-none-elf/bin/ld: hello_world.o(.rela.got+0x10): warning: relocation R_MORELLO_ADR_GOT_PAGE against symbol 'SBSS_END' in section without permission flags '.sbss'.  Assuming Read-Write.
    collect2: error: ld returned 1 exit status
    make: *** [Makefile:43: hello_world] Error 1

    From what I see, the __init_global_caps and __process_relocs functions are in the following file (assumming that the newlib from link below is the same newlib used in the GNU toolchain):

    https://git.morello-project.org/morello/newlib/-/blob/morello/master/libgloss/aarch64/relocs.c

    But for some reason the error message says these functions/symbols are undefined.

Children