llThis update is to be remembered for two things:
After a few times of breaking main this round, this may also be remembered as the point at which I started doing proper branching. All development work now happpens on the dev branch and is only merged to main after it’s confirmed working on all targets.
First, to recap, the goal of NanoOs’s userspace has always been to be Unix-like. I was starting to have trouble remembering everything on the filesystem and was getting annoyed that I had no way to find out from the OS, so I figured it was time to put together a real ls command. Now, my goal was not to support all options of the command. I really just wanted the output of ls -al.
The first thing I needed for this was proper dirent.h support. That’s standard POSIX functionality on top of FAT32, so Claude to the rescue on that one. That much got me the output of a basis ls. I’ve never implemented this command before, so I then started tracking down what I needed to get the rest of the output. It turned out that the answer was the lstat call, so, with a little more work from Claude, I implemented that as well.
And… I hated it. For the most part it was fine, but on the Agon Light 2, which is my main target these days, it was abysmally slow. One of the main problems was that lstat takes the path to a filename, which means that, for each file, I first had to construct the full path to the filename in dynamic memory, then walk the directory structure until I found the file, and THEN populate a stat structure. That’s a lot of system calls and seemed like a waste to me.
One of the things that a dirent struct contains is the inode of the file. It seemed to me that I should be able to directly grab all the information I needed straight out of the inode. I went looking for an equivalent to lstat that took an inode, but couldn’t find one. So, I made one. Simple enough. Then I realized I had a problem: FAT32 doesn’t have true “inodes” so I had used the starting cluster of the file. This in no way allowed me to find the information I needed. So, I changed what I used as the inode value to be the position of the file’s entry location within the directory. THAT got me what I needed and the istat call I made was much faster than the duplicate allocate + lookup way of doing it with lstat.
It was still pretty slow, though. Listing a directory with 15 entries was taking a little over 5 seconds. I’ve got a couple of 86Box instances that I run for comparison and that speed was roughly on par with what an 8088 ran at with the dir command. The eZ80 board I have should be running closer to what a 12 MHz 286 ran at. Now, to be fair, ls does quite a bit more work than dir does and I’m using almost all POSIX calls here where dir has the luxury of making whatever arbitrary calls it wants to get the job done. Still, I wasn’t happy with this and wanted to improve the speed.
My suspicion was that the extra time was being sent polling from the UART. I still hadn’t gotten to the point of being able to put the console into a blocking state and only wake it when there was data to process, so it was still waking up and polling every UART port it owned every loop the scheduler made. Due to the architecture of the Arduinos, I wasn’t able to use interrupts on that platform, so it never made any sense to develop that capability. Now, I needed it badly.
So, I started working on that. I obviously needed a solution for the eZ80, but I also needed to be able to test this in software. So, I needed a solution for the simulation/test harness environment as well. Basically, the flow looks like this:
read call on a dedicated threadtrue to indicate that there’s data for the porttrue to indicate that there’s data available at allread callRETI instructionNeedless to say, this was all a lot of work and it took me the better part of two (2) weeks to do everything. But when I finally got everything put together, I discovered that I was absolutely right about the Console polling having been consuming a lot of the processor. Listing that same 15-entry directory on the eZ80 now took about 3 seconds, so less than half the time that it had taken previously. This is much closer to the 286-like performance I was hoping for.
The great thing about this performance enhancement, though, is that it’s not the only one I can make. I’ve got some ideas about how I can cache overlays on the eZ80 board so that I can make swapping them even faster. If I’m right, that should improve things a lot, too. I know the system is spending a lot of time loading overlays, if only for the initial part of a command’s main function.
One of the reasons this took me so long to complete is that I realized part way through this that my multi-user support on the Arduino was broken. I hadn’t tested that out and I decided to do ll commands on two different login terminals. I discovered that I was getting stack overflows and hadn’t noticed before. I was also running out of enough dynamic memory to pipe the output between three different commands. I spent about a week hammering the OS on memory usage (both stack and heap) and correctness and adding more unit tests to help ensure that I don’t regress again.
When I sat back and looked at the final output, I was honestly kind of amazed. I was looking at the output of ls -al running natively on an Arduino and on an eZ80. These were not terminals into a “real” operating system, they were actually running the live OS with native filesystem implementations. The ouput of ll / on the Agon Light 2 (the eZ80) now looks like this:
mush root@brian-AgonLight2-1:/root# ll /
-rwxrwxrwx root root 41 Sat 2026-10-03 18:19:24 autoexec.txt
drwxrwxrwx root root 0 Sat 2026-10-03 18:19:24 .git/
-rwxrwxrwx root root 81050 Sat 2026-10-03 18:19:24 MOS.bin
-rwxrwxrwx root root 4692 Sat 2026-10-03 18:19:24 README.md
drwxrwxrwx root root 0 Sat 2026-10-03 18:19:24 bin/
drwxrwxrwx root root 0 Sat 2026-10-03 18:19:24 demos/
drwxrwxrwx root root 0 Sat 2026-10-03 18:19:24 docs/
-rwxrwxrwx root root 1035264 Sat 2026-10-03 18:19:24 firmware.bin
drwxrwxrwx root root 0 Sat 2026-10-03 18:19:24 fonts/
drwxrwxrwx root root 0 Sat 2026-10-03 18:19:24 games/
drwxrwxrwx root root 0 Sat 2026-10-03 18:19:24 mos/
drwxrwxrwx root root 0 Sat 2026-10-03 18:19:24 usr/
drwxrwxrwx root root 0 Sat 2026-10-03 18:19:24 etc/
drwxrwxrwx root root 0 Sat 2026-10-03 18:19:24 root/
drwxrwxrwx root root 0 Sat 2026-10-03 18:19:24 home/
mush root@brian-AgonLight2-1:/root#
I could get rid of the MOS-specific stuff at this point, but it’s fun to have something different to display in the output.
In terms of this being an environment that resembles early Unix, I think the only thing that I’m missing is a way to modify files. I’m thinking of implementing something like ed for that. We’ll see what I come up with.
To be continued…