It’s well-known that null-terminated C strings are bug-prone and unsafe to use. They’re the stereotypical footgun. I’ve been tinkering in a bare-metal environment recently, writing all code myself, including the common types and routines you find in libc or similar. In all the code I wrote, there is not at single null-terminated string, and I...
People say there are things that are complex and there are things that are just complicated. Complexity is considered interesting, complicatedness is considered harmful. The process of setting up an x86_64 CPU is mostly complicated. I’ll describe one way to go from a boot sector loaded by the BIOS with the CPU in 16-bit real mode to the CPU set...
I’ve been upset with my output lately. Just overall. For a few months, I felt I did a good (at least decent) job posting inspired content on this site. I was also learning steadily and making good progress on my programming. But in recent months, less so. I tried to focus on specific projects, but I couldn’t stick to any of them for long. As...
Parsing numerical expressions by recursive descent is a joy in Haskell! It is incredibly concise and elegant, yet very simple. What we want to parse are binary expressions like 7 + 42 * 9, 2 * 3 / 4 * 5, or 8 * (10 - 6). As always, when parsing such expressions, we have to be aware of the associativity of the operators involved and of their...
Recently, I’ve been working on a C debugger. This requires reading and processing the DWARF debugging information that’s part of the binary. Since this is a rather complex task, I figured I might use a library that exports a nice interface to the debugging information. One such library that I found early on was libelfin. It wasn’t perfect from...