Linux Format

Coding Arm 64-bit assembly language

Last 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.

Our next programs are and (). 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 . The program will receive as will receive as strings ./cmdline , alpha , beta and goldfish . and 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.

You’re reading a preview, subscribe to read more.

More from Linux Format

Linux Format1 min read
Video Stars
Italo Vignoli is one of the founders of LibreOffice and the Document Foundation. “LibreOffice 24.8 was announced in August, and at the same time the documentation team released the Getting Started Guide. This was the first time the manual was immedia
Linux Format3 min read
Ubuntu Unity 24.10
The Unity interface was originally developed as an alternative to Gnome 2 by Canonical and included in Ubuntu from April 2011. Ultimately, Canonical abandoned Unity in favour of switching back to Gnome. This decision didn’t sit well with Ubuntu devel
Linux Format3 min read
Stay Alert With System Email Warnings!
Within Linux, lots of jobs send output to various log files and emails to users. Thing is, forwarding this important information to the appropriate users is more complicated than needed. It used to involve setting up sendmail servers and all sorts of

Related Books & Audiobooks