Writing an OS targeting ARMv8

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
phase
Posts: 4
Joined: Sat Jan 30, 2016 11:03 pm

Writing an OS targeting ARMv8

Post by phase »

I'd like to write an OS targeting the ARMv8 (64-bit), but I haven't found any sort of Bare Bones like there is for the ARMv6. QEMU contains a qemu-system-aarch64 which should be able to run one, but compiling the Raspberry Pi Tutorial for aarch64 didn't seem to work (QEMU exits w/o anything, which from past experience usually signifies something went wrong).

Here are the commands I used for compiling the boot.S and kernel.c files from the tutorial.

Code: Select all

arm-none-eabi-gcc -march=armv8-a -fpic -ffreestanding -c boot.S
arm-none-eabi-gcc -march=armv8-a -fpic -ffreestanding -std=gnu99 -O2 -Wall -Wextra -c kernel.c
arm-none-eabi-gcc -T link.ld -o os.elf -ffreestanding -O2 -nostdlib boot.o kernel.o
arm-none-eabi-objcopy os.elf -O binary os.bin
This gave me a bin which I called qemu with:

Code: Select all

qemu-system-aarch64 -kernel os.bin
And bam, nothing happened! I know that the GPIO offset is probably wrong (as it changed from ARMv6 to ARMv7), but I couldn't find the address for ARMv8 anywhere.
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Writing an OS targeting ARMv8

Post by iansjack »

The location of the GPIO(s) will be determined by which development board you are emulating. Details are available in the ARM documentation. E.g.: http://infocenter.arm.com/help/index.js ... EGAAB.html
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: Writing an OS targeting ARMv8

Post by Owen »

arm-none-eabi-gcc compiles AArch32 code (-march=armv8 means "using the ARMv8 extensions to AArch32")


For a start, you want an aarch64-none-elf gcc. You will additionally want to rewrite any assembly for the different (A64, not old A32/ARM or T32/Thumb) instruction set.

You will also need the documentation for whatever system QEMU is emulating (and also the -kernel option normally takes an ELF, not flat binary)
User avatar
phase
Posts: 4
Joined: Sat Jan 30, 2016 11:03 pm

Re: Writing an OS targeting ARMv8

Post by phase »

Owen wrote:arm-none-eabi-gcc compiles AArch32 code (-march=armv8 means "using the ARMv8 extensions to AArch32")


For a start, you want an aarch64-none-elf gcc. You will additionally want to rewrite any assembly for the different (A64, not old A32/ARM or T32/Thumb) instruction set.

You will also need the documentation for whatever system QEMU is emulating (and also the -kernel option normally takes an ELF, not flat binary)
I got the aarch64-none-elf toolchain and am now having difficulties with the Assembly.

Using the RPI tutorial boot code, I ran it through the assembler hoping to get something out of it and got this message on a lot of different lines:

Code: Select all

kernel/boot.S:16: Error: operand 1 should be an integer register -- `ldr r4,=__bss_start'
So I looked through the ARMv8 Instruction Set Manual and found that the registers needed a w or a x in front of them, adding that changed nothing:

Code: Select all

kernel/boot.S:16: Error: operand 1 should be an integer register -- `ldr wr4,=__bss_start'
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Writing an OS targeting ARMv8

Post by iansjack »

You might want to read this white paper: http://malideveloper.arm.com/downloads/ ... 64-bit.pdf

Note that the registers are x1, etc., or w1, etc., depending upon whether you use them as 64- or 32-bit registers.
User avatar
phase
Posts: 4
Joined: Sat Jan 30, 2016 11:03 pm

Re: Writing an OS targeting ARMv8

Post by phase »

iansjack wrote:You might want to read this white paper: http://malideveloper.arm.com/downloads/ ... 64-bit.pdf

Note that the registers are x1, etc., or w1, etc., depending upon whether you use them as 64- or 32-bit registers.
I've fixed the boot code and here's what I have so far:

Code: Select all

.section ".text.boot"

.globl _start

_start:
    // Setup the stack.
    mov sp, #0x8000
 
    // Clear out bss.
    ldr x4, 0
    ldr x9, =__bss_end
    mov x5, #0
    mov x6, #0
    mov x7, #0
    mov x8, #0
    b       2f
 
1:
    // store multiple at r4.
    stp x5, x8, [x4], #8
2:
    cmp x4, x9
    blo 1b
 
    // Call kmain
    bl kmain
 
    // halt
halt:
    wfe
    b halt
And I have a blank C function called kmain that has a while(1) loop in it. I get no compiler or linker errors, but QEMU doesn't come up with anything and stops as soon as I start it.
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Writing an OS targeting ARMv8

Post by iansjack »

You appear to be overwriting a range of memory starting at location 0. Why do you do this, and what do you expect to happen? Which development board are you targeting?
User avatar
phase
Posts: 4
Joined: Sat Jan 30, 2016 11:03 pm

Re: Writing an OS targeting ARMv8

Post by phase »

iansjack wrote:You appear to be overwriting a range of memory starting at location 0. Why do you do this, and what do you expect to happen? Which development board are you targeting?
I was just copying the RPi tutorial. I want to target both RPi 2 Model B and Snapdragon 410 processor, the latter if doing both isn't an option. How would I be able to build for both?
User avatar
Schol-R-LEA
Member
Member
Posts: 1925
Joined: Fri Oct 27, 2006 9:42 am
Location: Athens, GA, USA

Re: Writing an OS targeting ARMv8

Post by Schol-R-LEA »

I realize that it's quite late to be commenting on this, but I felt that this needed clarification:
iansjack wrote:The location of the GPIO(s) will be determined by which development board you are emulating. Details are available in the ARM documentation. E.g.: http://infocenter.arm.com/help/index.js ... EGAAB.html
To be more specific, the GPIO lines have nothing to do with the CPUs themselves; 'General-Purpose I/O' pins are hardware data lines that are part of the peripheral chips' pinouts, not the CPU pinout. Thus, the model of the CPU is relevant only insofar as different SBCs (e.g., different models of RPi) use different CPU models, and often cannot change out the CPU. It is the design of the hardware that the CPU is attached to that counts regarding the location of the GPIO offsets, not the CPU model per se.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
Post Reply