U bekijkt momenteel de Netherlands versie van de site.
Wilt u overschakelen naar uw lokale site?
14 MIN LEESTIJD

ASSEMBLY

Coding Arm 64-bit assembly language

Continue writing 64-bit assembly code for the Pi with John Schwartzman, who calls on Linux kernel services and the C run-time library.

Part Two!

Grab the last issue to get part one, see page 74!

OUR EXPERT

John Schwartzman is a long-time engineering consultant to business and government. He also teaches computer science at a local college.

L ast month we used assembly language to directly access the Raspberry Pi’s Linux kernel services. In this issue’s concluding instalment we’re going to use the C run-time library, glibc, instead of calling the kernel services directly. The glibc functions are in many cases thin wrappers around the Linux kernel services. But using the C library is the preferred way to access the kernel services.

Kernel system calls are limited to six arguments, but that’s not enough for the C library. We use X0 through X7 for the first eight arguments, but any number of additional arguments can be passed on the stack. We populate the registers listed above with the arguments to the function in left to right order. We then PUSH the arguments on to the stack in right to left order and remove them from the stack after the C library function has executed. You’ll see an example of this in environment.asm. When using the kernel system calls we called a common location using the software interrupt instruction SYSCALL and passed the ID of the specific service in the X8 register. When using the C library we call the specific function we want by name. X0 (or sometimes W0, the lower half of X0) is used to return a result to the caller.

Here, the command cmdline.c lists arguments to the c program.

Our next programs are cmdline.c and cmdline.asm (see screenshots below and on page 88). When a main function is invoked it can include arguments that the user types on the command line. If you type ./cmdline alpha beta goldfish at the command prompt, Linux will execute the program cmdline. The program will receive as parameters, argc, which is the total number of string arguments (four in this case) followed by an array of pointers to the strings on the command line that are in an array of arrays called argv[]. In this case, cmdline will receive as strings ./cmdline , alpha , beta and goldfish . Cmdline.c and cmdline.asm read and print argc and argv[]. Since this is Linux, you can guess how we receive these parameters. W0 will have the integer argc (the first argument), and X1 will have the vector of pointers, **argv. cmdline.c should be easy to understand. The prototype for main is int main(int argc, char* argv[]) .

Ontgrendel dit artikel en nog veel meer met
Je kunt genieten:
Geniet volledig van deze editie
Direct toegang tot 600+ titels
Duizenden oude edities
Geen contract of verplichting
ABONNEER NU
30 dagen proberen, dan gewoon €11,99 / maand. Op elk moment opzeggen. Alleen nieuwe abonnees.


Meer informatie
Pocketmags Plus
Pocketmags Plus

Dit artikel komt uit...


View Issues
Linux Format
March 2021
IN DE WINKEL BEKIJKEN

Andere artikelen in dit nummer


WELCOME
Orchestral Manoeuvres in the Docker
Jonni’s been arguing with me this issue –
REGULARS AT A GLANCE
Is online privacy the hot topic for 2021?
PRIVACY
Linus vs Intel
Linus Torvalds blasts Intel for not supporting ECC memory
Affordable RISC-V PC arrives
BeagleV is a RISC-V computer designed to run Linux
THE END IS NIGH, SO…?
Matt Yonkovit is Percona’s Chief Experience Officer and
SPRING CLEANING
Keith Edmunds is MD of Tiger Computing Ltd,
Apple M1 Macs get Linux support
Apple’s OS 11.2 now supports booting custom kernels
FOSS watch
PineTime takes on the Apple Watch and other wearables
Faster Firefox
Firefox 84 brings HW acceleration to Linux
Distro watch
What’s down the side of the free software sofa?
IT’S GOOD TO SHARE
Alyssa Rosenzweig is a software engineer based at
TIME’S UP FOR OLD KIT
Jon Masters has been involved with Linux for
Kernel Watch
Jon Masters summarises the latest happenings in the Linux kernel, so you don’t have to
Mailserver
Write to us at Linux Format, Future Publishing, Quay House, The Ambury, Bath BA1 1UA or lxf.letters@futurenet.com.
Helpdex
shane_collinge@yahoo.com WRITE TO US Do you have a
Answers
Got a burning question about open source or the kernel? Whatever your level, email it to lxf.answers@futurenet.com
SUBSCRIBE!
EiskaltDC++
FILE-SHARING APPLICATION
TabFS
FILE SYSTEM
TuxPaint
DRAWING APPLICATION
Chipmunk
LOG VIEWER
Darktable
PHOTO EDITOR
EasyLogic Studio
CSS AND SVG EDITOR
Zenith
SYSTEM MONITOR
Tux Vs Yeti
PLATFORMER GAME
Invasion
ARCADE GAME
Qsnapstore
SNAP STORE VIEWER
REVIEWS
AMD Ryzen 5 5600X
As Alan Dexter discovers, this chip may be the runt of the Zen 3 family, but it delivers where it counts most: gaming
Slackel 7.4
Before he couldn’t work with Arch, he couldn’t work with Slackware, which is why Mayank Sharma jumps at everything that mentions the venerable distro
RebornOS 2020.12.28
The constant deluge of Arch-based distros can put anyone to sleep, but this one makes Mayank Sharma wake up from his slumber
Rescuezilla 2.1
With perennial fat fingers, Mayank Sharma has been messing with hard disks long enough to know that good rescue tools are worth their weight in gold
Garuda Linux 210101
Mayank Sharma has enjoyed one Arch-based distribution this month, but will lightning strike twice or has he been taken in by the distro’s tall claims?
Wasteland 3
Management simply hates weirdos and snow, so this is a bad time of year for them and they’re taking it out on Jody Macgregor
Roundup
Game engines
There’s never been a better time to get into game development on Linux. Michael Reed puts five capable engines under the microscope
How free is it?
There are different kinds of free…
Community and support
A game engine is useless without a way of learning how to use it
Programming environment and GUI
A difficult environment can lead to eventual loss of interest
2D workflow and features
Top down, overhead, side on or something else?
3D workflow and features
How easy is it to create a world to move around in?
Extras
Anything that makes it stand out from the rest?
Ease of use
This is relative because some engines are more capable in terms of what they can do
Game engines
The Verdict
Better virtual machines
BETTER VIRTUAL MACHINES
Forget about the draconian confines of reality and immerse yourself (well, your computing) in a virtual world. Jonni Bidwell’s here with a machines-inside-machines extravaganza
A virtual history
Datacentres are full of VMs, but why and how did they get that way?
QEMU, KVM and the other ones
Learn about virtualising the Linux way, with libvir t and Virtual Machine Manager, and jokes about Inception
Orchestrating with Xen
Set up a machine dedicated to hosting VMs with yet another high-powered hypervisor, XCP-ng
INSTALL XCP-NG
1 Launch the installer Fetch the latest ISO
Contain yourself
Containerisation is even more of an ugly word than virtualisation, but it’s a big deal too. A Docker whale-sized big deal, as we’ll discover…
IN-DEPTH
THE LINUX GAMBIT
Jonni Bidwell once again sets a graphics card on fire, this time calculating chess positions…
Pi USER
PASSING ON THE KNOWLEDGE
Thierry Chantier is a French coder and maker.
Pi Foundation boosts support for teachers
Over 300 free curriculum-mapped video lessons now available via the Oak National Academy
Cool HAT dude!
This Pi Smart Fan HAT is stackable and GPIO friendly, too
Raspberry Pi Pico
In a break from the norm Les Pounder tests the latest Pi: a $4 microcontroller featuring the first ‘Pi Silicon’ created by Raspberry Pi
Turn a Pi HAT into a Magic 8-ball project
SENSEHAT
Build a Pi-powered helicopter diorama
Sean Conway uses a helicopter model to demonstrate how lighting, sound and motion can be accomplished using a Raspberry Pi
Connect, configure and use gamepads
GAMING
TUTORIALS
A terminal multiple window manager
You can’t use the mouse or run multiple windows in a text environment… unless you’re Shashank Sharma and know just the right tool for the job
Construct your own mind-maps
Nick Peers reveals how you can easily manage all of your thoughts – from simple ideas to fully formed projects – with this powerful free tool
Next-gen filesystem management
ZFS is a lot more than a filesystem. Neil Bothwick tells all about this advanced volume manager and Swiss Army Knife of filesystems
Run a classic BBC Micro under Ubuntu
Les Pounder reminisces about that one time when he caused a core meltdown in a nuclear reactor, then flew away in a spaceship
Decode signals from weather satellites
Weather satellites transmit signals that you can receive and decode to generate images of the Earth. Mike Bedford shows you how
Dify
IMAGE COMPARISON TOOL
Using Active Directory with Debian & Samba
Stuart Burns rolls up his sleeves and
CODING ACADEMY
Write a maze runner game in Python
One way in, and only one way out… video game aficionado Calvin Robinson reveals how to create a vintage maze runner-style game
REGULARS AT GLANCE
On the disc
Discover the highlights from this month’s packed DVD!
GeckoLinux 152
SUPER GECKO MUSCLES
Chat
X
Pocketmags ondersteuning