Home > Software engineering >  How to write a bare-metal hello world program for PowerPC
How to write a bare-metal hello world program for PowerPC

Time:01-18

I need to write a program on bare-metal PowerPC system. As a newbie to bare-metal programming without OS/bootloarder, I decide to write a hello world program to start. I googled some post about this, and found out something about ARM like Beagleboard bare metal programming or Hello world, bare metal Beagleboard.

I don't very clear if they are suitable for porting to PowerPC platform. I cannot find PowerPC's hello world example for beginner. Anyone have experience of bare-metal development for PowerPC, without bootloader or OS?

Thanks.

CodePudding user response:

Random notes/links I collected for trying to get a bare metal PPC system to boot in Qemu There are plenty of examples all around for doing embedded, bare-metal programming on ARM platforms, but the PowerPC examples seem to be sparse.

Some ARM links:

http://opensourceforu.com/2011/07/qemu-for-embedded-systems-development-part-2/ https://balau82.wordpress.com/2010/02/28/hello-world-for-bare-metal-arm-using-qemu/

Building GNU GCC cross compiler

1) Packages Needed

binutils https://ftp.gnu.org/gnu/binutils/

GCC https://ftp.gnu.org/gnu/gcc/gcc-4.1.1/

newlib ftp://sourceware.org/pub/newlib/index.html

GDB http://www.gnu.org/software/gdb/gdb.html

2) Set environment variables

$ export TARGET=powerpc-eabi
$ export PREFIX=/usr/local/$TARGET
$ export PATH=$PATH:$PREFIX/bin

3) Build binutils

$ tar xjfv binutils-2.17.tar.bz2
$ mkdir build-binutils
$ cd build-binutils
$ ../binutils-2.17/configure --target=$TARGET --prefix=$PREFIX
$ make all
$ make install

4) Build bootstrap GCC

$ tar xjfv gcc-4.1.1.tar.bz2
$ mkdir build-gcc
$ cd build-gcc
$ ../gcc-4.1.1/configure --target=$TARGET --prefix=$PREFIX --without-headers --with-newlib  --with-gnu-as --with-gnu-ld
$ make all-gcc
$ make install-gcc

5) Build newlib

$ tar xzfv newlib-1.14.0.tar.gz 
$ mkdir build-newlib
$ cd build-newlib
$ ../newlib-1.14.0/configure --target=$TARGET --prefix=$PREFIX
$ make all
$ make install

6) Build GCC again with newlib

$ cd build-gcc
$ ../gcc-4.1.1/configure --target=$TARGET --prefix=$PREFIX --with-newlib --with-gnu-as --with-gnu-ld --disable-shared --disable-libssp
$ make all
$ make install

7) Build GDB

$ tar xjfv gdb-6.3.tar.bz2  
$ mkdir build-gdb
$ cd build-gdb
$ ../gdb-6.3/configure --target=$TARGET --prefix=$PREFIX --enable-sim-powerpc --enable-sim-stdio
$ make all
$ make install

Example bare metal hello world!!! https://github.com/ara4711/ppc_hw

  • In makefile change, PREFIX=$(PROC)-$(TYPE)- to PREFIX=/usr/local/powerpc-eabi/bin/$(PROC)-$(TYPE)-

  • In makefile give path of qemu-system-ppc to QEMU variable.

  • Command make will generate the test.bin.

  • Command make run will load the binary and the print “Test Hello
    world!“ is displayed on the console

  • Command make debug to debug test program.

  • Press Ctrl a and x to terminate QEMU

QEMU implements a gdb connector using a TCP connection. To do so, run make debug

this command freezes the system before executing any guest code and waits for a connection on the TCP port 1234. From another terminal, run powerpc-eabi-gdb and enter the commands:

target remote localhost:1234
file test.elf

This connects to the QEMU system and loads the debugging symbols of the test program, whose binary image is already loaded in the system memory. From there, it is possible to run the program with the continue command, single-step the program and debug it in general. The exit command in gdb closes both the debugger and the emulator.

CodePudding user response:

First of all, which CPU is this? Secondly, the CPU is not everything.

If you have no starting point, you can study up the BIOS of the architecture you want to write this code for. Then you can write a boot sector which gives you the output you want. Check this page for some examples: Rough guide to assembly

  • Related