Hello, Assembly World in Haiku x86

Vegard Wærp
2 min readNov 27, 2018

I’ve always been a big fan of the BeOS operating system. I used it as my main operating system for a while, and I’m also a fan of the Haiku project, which is an open source re-implementation of BeOS.

Currently I’m studying for the Penetration Testing with Kali Linux (PWK) course and the OSCP certification. The course manual has a couple of chapters on buffer overflow and shellcode which made me want to brush up on my very limited assembly skills. And since Haiku beta 1 was just released, I thought trying to to write some assembly in Haiku would be a fun exercise. I started with the x86 version, as I’m not very versed in x64 assembly. I used the x86 beta1 image located at https://www.haiku-os.org/get-haiku/

Googling for places to start, I found a page at the Haiku website describing Haiku syscalls with an example how to write a simple “Hello, World” application in Assembly.

When trying to assemble and run the example however, it just crashed with a segfault, and after a while I found out this was because the article was old, and the actual syscall numbers had changed. The file with the syscall numbers, syscalls.S.inc, isn’t a part of the Haiku source tree either, but is generated when building the system.

So to get the correct numbers, I had to download the haiku source, and either run the generating command by itself or generate it during the build of the Operating System. Poking around I found that the file was generated when building libroot, so I generated the file using the following commands:

git clone https://git.haiku-os.org/haiku
cd haiku
./configure --target-arch x86_gcc2 --target-arch x86
cd src/system/libroot
jam

After running this command, I found the generated file at generated/objects/haiku/x86_gcc2/common/system/libroot/os/syscalls.S.inc in the haiku source directory. I’ve also uploaded it to a GitHub gist, but the numbers can change, so to be sure you have the correct numbers, it’s best to generate it yourself.

Looking at the file, I saw that the correct syscall numbers were 144 for the write syscall, and 38 for the exit syscall. I then changed the numbers in the example code, assembled and linked, and got the following result:

Hello, Haiku World

The completed hello_haiku.asm

hello_haiku.asm source code

For a 64 bit version for Haiku x86_64, go here.

--

--