Skip to content

[FR] Suggest adding support for later 64-bit #1

@OutsourcedGuru

Description

@OutsourcedGuru

The book suggests that it might cover 64-bit coding (later) so I created two testing platforms on a Raspberry Pi 4B with 4GB RAM:

  • Raspbian Buster Lite 2019-09-26 (32-bit)
  • Ubuntu Server 19.10 64-bit

I made an attempt to use any of your Chapter 1 code for the 64-bit environment and it of course failed badly.

For your 2nd edition of the book I might suggest the following. The assumption would be that you cover 64-bit and to incorporate it in such a way that the transition is easier with the same scripts.

build

#!/bin/sh

# (This test should be modified to allow the Pi Zero's armv6l to be seen as 32-bit)
if uname -snrvm | grep -q armv7l; then
    echo "32-bit detected"
    BITS=32
else
    echo "64-bit detected"
    BITS=64
fi

as -o helloworld.o helloworld-$BITS.s
ld -o bin/helloworld helloworld.o

Next, I would rename all the *.s files to *-32.s in your existing code.

helloworld-32.s

.section .text
.global _start
_start:
        mov r0, #1
        ldr r1, =helloworld
        mov r2, #13
        mov r7, #0x04
        svc 0
        mov r0, #0x0
        mov r7, #1
        svc 0

.section .data
helloworld: .ascii "Hello World!\n"

helloworld-64.s

.section .text
.global _start
_start:
        mov x0, #1
        ldr x1, =helloworld
        mov x2, #13
        mov x8, #0x40
        svc 0
        mov x0, #0x0
        mov x8, #93
        svc 0

.section .data
helloworld: .ascii "Hello World!\n"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions