Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ARM assembly using Qemu [closed]

Well i've searched whole internet for code that will run using arm-linux-gnueabi-as and qemu. To print a integer value. From string. A routine will help.

like image 782
Waqas Avatar asked Apr 04 '13 04:04

Waqas


1 Answers

obviously you have not searched the whole internet...because, if nothing else, the qemu source code contains all the answers to your questions...

QEMU emulates systems. Are you trying to do something bare metal on an emulated arm system? Or are you trying to run an arm linux operating system and within the operating system create a program in assembly that runs on the operating system which is running on qemu? if it is the latter it has nothing to do with qemu, it is an operating system question not a qemu question. and it is not a language question (asm) but an operating system question. asm and low level are two different things. asm does not imply low level access and is definitely not required (and rarely used) for low level stuff.

If you are not interested in an operating system but just bare metal, here is one of many ways to get serial output on the qemu console. strings and integers and such are a language-less problem (same solution can apply to any programming language, asm, c, python, etc solve the problem THEN apply the language to the problem).

start.s

.globl _start
_start:
    ldr r0,=0x101f1000
    mov r1,#0
loop:
    add r1,r1,#1
    and r1,r1,#7
    add r1,r1,#0x30
    str r1,[r0]
    mov r2,#0x0D
    str r2,[r0]
    mov r2,#0x0A
    str r2,[r0]
    b loop

memmap

MEMORY
{
    rom  : ORIGIN = 0x00010000, LENGTH = 32K
}

SECTIONS
{
   .text : { *(.text*) } > rom
}

Makefile

CROSS_COMPILE ?= arm-none-linux-gnueabi

AOPS = --warn --fatal-warnings 
COPS = -Wall -Werror -O2 -nostdlib -nostartfiles -ffreestanding 

hello_world.bin : startup.s memmap
    $(CROSS_COMPILE)-as $(AOPS) startup.s -o startup.o
    $(CROSS_COMPILE)-ld startup.o -T memmap -o hello_world.elf
    $(CROSS_COMPILE)-objdump -D hello_world.elf > hello_world.list
    $(CROSS_COMPILE)-objcopy hello_world.elf -O binary hello_world.bin

run with

qemu-system-arm -M versatilepb -m 128M -nographic -kernel hello_world.bin

but I dont know how to get out of the console

Instead if you do this:

qemu-system-arm -M versatilepb -m 128M -kernel hello_world.bin

and then ctrl-alt-3 (not F3 but 3) will switch to the serial console and you can see the output, and can close out of qemu by closing the console window.

The uart tx register in the versatilepb qemu target is at address 0x101f1000. Because this is a simulation, you can "just try" and find out that writing to this address without doing any real-world uart setup "just works", and being an emulated system it probably instantly transmits the character so you dont have to wait for it to complete or poll for an empty tx buffer slot or anything like that. Just blast away. This will get you started, then you can try to do real-world stuff later if that is of interest. (other uarts in other targets may be closer to real-world like and require some initialization, and waiting for an empty tx buf).

asm makes the above more painful, just use C instead for your low level/bare metal programs.

Also if doing arm bare metal you can use arm-none-linux-gnueabi, if you know what you are doing, but will eventually find arm-none-eabi a better fit since you are not using an operating system much less linux.

like image 200
old_timer Avatar answered Nov 03 '22 00:11

old_timer