After quite the lengthy tread through GCC and C-land (mind you everything discussed before was written in C), we finally find ourselves back at C++. C++ exception semantics seem simple, but actually hide many surprising edge cases. Functions Like before, let’s discuss the API of the C++ exception handling regime. Note that while you’re not supposed to call these functions directly, these functions are called in compiler generated code anyways, so are a part of the public ABI....
Exceptions Explained Part 3: libunwind
Last time I mentioned libunwind, but now I’m going to go over the implementation of libunwind in GCC. As mentioned before, libunwind used to be a library developed by HP, but it got vendored into GCC as a part of libgcc. libgcc itself is a small library containing, besides libunwind, various intrinsics for floating point and integer math. libunwind One might reasonably ask the question of how one can unwind a stack while using functions that modify the stack?...
Exceptions Explained Part 2: Frame Information
Last time I talked about the broad architecture of how exceptions work. Today I’m focusing on how debug information is contained in the eh_frame section. To explain why exception information is held in the format it is today, we need to dive a little into the history of libunwind. Much of what is here comes from linux reference documents, found here. History Libunwind was originally developed by HP back in the days of the unix wars....
Exceptions Explained Part 1: Architecture
As it turns out there’s not really a good in depth explanation of how exceptions work. There are disparate explanations of how separate parts of exceptions in C++ work, but not really the whole picture. So I’m writing this down here as a reference to how everything in C++ exceptions work. Disclaimer My experiences are exclusively in GCC. Broadly, Clang should follow the same Architecture as GCC, but may vary in implementation details....
BLDC Driver
I got very bored and decided to create a brushless DC motor driver pcb. It was pretty fun going through all of the design considerations, so here we go. Architecture The BLDC driver is intended to be run by a MicroMod controller. This is mostly because the club I’m at uses MicroMods extensively, and I wanted to put this in that same ecosystem. Despite what the schematic implies, power does actually come from the power section, it’s just that power symbols in KiCad are global and don’t show up on hierarchal schematics....
Modifying GCC
Quite a while ago, I’ve integrated my exceptions work into a fork of GCC. At that point, I was already modifying GCC to suppress the libunwind symbols, so putting all of my code into GCC was a no brainer. Moreover, it isn’t actually that hard to build GCC. Editing GCC GCC is built via the autoconf build system. Autoconf is a collection of scripts that is somewhat like CMake, but written entirely in shell script and is intended to be portable for any system that runs shell scripts and has a C compiler....
Exceptions
For the past couple months, I’ve been trying to get exceptions to work on AVR as a hobby project. After several months of work, I’ve done it. Exceptions work, you can just include <vector> and it just works. How to use it Currently I put prebuilt toolchains on github. My changes are currently a bunch of patches to gcc 13.2.0, binutils, and a few others. What I actually did I’ve reimplemented libunwind, the personality function, and also cfi macros by replacing them with my own stuff....
Bitstruct
I was looking at I2C code, and noted that there was an awful lot of manual bit manipulation. Unfortunately the native solution in c++, bitfields, are non-portable and for that reason is discouraged in code bases. For that reason, I have written a library called bitstructs, which aims to do what bitfields do but portably. What are bitfields Bitfields are a bit of an obscure feature in C++, aimed at embedded developers....
Blog Infrastructure
As is tradition, I’ve hosted the blog manually using AWS. Last time I created configured an Apache server manually. However, as I grew more knowledgeable about web development, I realized that this was a woefully out-dated solution. So here’s my retelling of how I created this blog. Hugo To begin with, I began by using Hugo as my static website generator. I’ve had enough experience with it that using it was relatively painless....
First
At this point, this is my third time writing a blog, and the first since I have become an adult. Since I now have a semi-stable source of income, I can actually rent a domain name and server resources with confidence that I can pay for it in the future. In any case, I’ll probably post stuff about personal projects I’ve done. First I should put some of my more recent projects though....