Scas updates

Posted 01 Jul 2020 by Noam Preil

KnightOS holds a special place in my heart, and it probably always will. It’s lodged right next to some of the tubes, and the doctors say there’s no way I would survive attempting to remove it. It’s a tragedy really, but I make the most of it. Your pointy swords won’t ensnare me forever, KnightOS! Eventually I’ll be dead! Ha!

Jokes aside, I really love KnightOS, but I’ve spent a lot more time thinking about it than actually working on it, at least until recently. However, it did directly influence my self-studies for nearly my entire time in high school.

During my time in high school, I often spent hours on end studying whatever caught my interest. At one point, my class was on a field trip, but I couldn’t tell you where we went if my life depended on it. The entire time we were walking around, I had my face buried in an introductory book on assembly. That’s how I first learned of the concept of an ABI, parameter passing, registers, and so on.

The very fact that I consider myself a systems programmer can be directly traced back to my discovery of KnightOS. It’s no exaggeration to say that if I hadn’t found KnightOS, I would never have started working on Project Tricarbon (a compiler toolchain project), and I likely wouldn’t be a Zig contributor, and I would never have met a lot of amazing people.

I’ll probably continue working on KnightOS for a very long time. KnightOS will never die, but it has a habit of taking long naps from time to time. Recently, it decided to wake up, and gave me a bit of a nudge. Scas (the next-gen KOS assembler [at least until I decide to do it from scratch again :P]) needed some affection!

The results: with approximately six hours worth of work spread over a week, I reduced the memory leaked when building the C template program from 964251 bytes… to less than two thousand bytes. Every single compiler warning has been fixed. Where before Valgrind reported over five thousand errors, it now reports none. The only reason there are still any leaks left is because I needed CI to fail until I finished working on a different patchset, and I set it to fail if there was any memory leak whatsoever.

Now that scas is more reliable, I’m working on getting scas building the Monty Python of KnightOS: the kernel itself! I hope to finish it within a few weeks, make a few changes, and release scas 1.0! For now, we’ll have to settle for scas 0.4, which has many, many improvements over 0.3.4 (which was released way back in February of 2019):

  • Explicit imports work!
  • Relative labels work! (thanks Snektron!)
  • Nearly every single memory leak is gone
  • Every memory error with typical asm is gone (there are likely still a few on more obscure paths, which I’ll be fixing once the kernel is done)
  • Improved support for running scas on big endian systems
  • Architecture overrides
    • Now, if you write a custom ISA definition, you can run scas -a
  • 32-bit support!
    • A new directive, dl, inserts 32-bit values
  • Bugfixes galore!
  • Better error handling

We’re currently on 0.4.2; 0.4.1 added a hotfix and the -h / --help option, and 0.4.2 was the memory leak fixer-upper :)