I wrote an HTTP server in ARM64 Assembly to have fun with some low-level stuff.
You can check out the code at server.s
.
I'm talking to macOS directly through syscalls, which you're not supposed to do since, being a private API, they can change at any point. However, I did so anyway since I just wanted to explore the lowest level.
To prevent hardcoding all the constants needed to talk to the OS, I'm generating a const.s
file from the C headers of the system lib. I cannot distribute binaries, but at least I should have better luck building it in the future.
- Use
fork
to handle many connections at once - Handle
SIGINT
to gracefully close the server - Send
Content-Length
On an Apple Silicon mac, run:
$ make
...and check out http://localhost:4520.
Some stuff that helped me get this working:
- AArch64 Instruction Set Architecture
- x86 and A64 common instructions comparison
- Assembly Preprocessor Directives
- Beej's Guide to Network Programming (for C)
- LLDB cheat sheet
- HTTP flow
Also just running man <SYSCALL>
can be super helpful. I wish we had something like that for modern stuff :)