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 Format2 min read
OBS Studio
Version: 30.0.2 Web: https://obsproject.com There are lots of good options for recording screencasts, but if you want to live-stream T your desktop, one of the best options is OBS Studio. The app works with all the major online streaming providers, s
Linux Format1 min read
Wine For Wayland
2023 was a great year for the Wayland driver for Wine. The goal was to move forward from the experimental phase and make the driver a proper upstream component. A year later, after several merge requests, many people are now already able to use the l
Linux Format2 min read
Back Issues Missed One?
ISSUE 313 April 2024 Product code: LXFDB0313 In the magazine Discover how to use the ultimate hacker’s toolkit, staying out of trouble while doing so. And join us as we take the Puppy Linux developer’s new distro for a run and explore its container

Related Books & Audiobooks