1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-30 22:08:08 +11:00
collapseos/recipes/rc2014/zasm
Virgil Dupras 019d05f64c Make the shell a userspace app
That's my mega-commit you've all been waiting for.

The code for the shell share more routines with userspace apps than with kernel
units, because, well, its behavior is that of a userspace app, not a device
driver.

This created a weird situation with libraries and jump tables. Some routine
belonging to the `kernel/` directory felt weird there.

And then comes `apps/basic`, which will likely share even more code with the
shell. I was seeing myself creating huge jump tables to reuse code from the
shell. It didn't feel right.

Moreover, we'll probably want basic-like apps to optionnally replace the shell.

So here I am with this huge change in the project structure. I didn't test all
recipes on hardware yet, I will do later. I might have broken some...

But now, the structure feels better and the line between what belongs to
`kernel` and what belongs to `apps` feels clearer.
2019-11-15 15:37:49 -05:00
..
cfsin zasm: rename #inc to .inc 2019-10-06 14:32:23 -04:00
.gitignore recipes/rc2014/zasm: zasm can now assemble *and* write to file 2019-06-07 19:53:50 -04:00
glue.asm Make the shell a userspace app 2019-11-15 15:37:49 -05:00
Makefile Make the shell a userspace app 2019-11-15 15:37:49 -05:00
README.md recipes/rc2014/zasm: we can now assemble the recipe's kernel 2019-06-18 22:07:44 -04:00
user.h Make the shell a userspace app 2019-11-15 15:37:49 -05:00

Assembling binaries

For a system to be able to self-reproduce, it needs to assemble source z80 assembly to binary.

Goals

Have a RC2014 assemble a Collapse OS kernel with its source living on a CFS on a SD card.

Gathering parts

The zasm binary

To achieve our goal in this recipe, we'll need a zasm binary on the SD card. This zasm binary needs to be compiled with the right jump offsets for the kernel we build in this recipe. These offsets are in user.h and are closely in sync with the configuration in glue.asm.

user.h is then included in apps/zasm/glue.asm.

The makefile in this recipe takes care of compiling zasm with the proper user.h file and place it in cfsin/zasm

The userland source

The code we're going to compile is cfsin/hello.asm. As you can see, we also include user.h in this source code or else ld hl, sAwesome would load the wrong offset.

Because of this, the Makefile takes care of copying user.h in our filesystem.

Preparing the card and kernel

After running make, you'll end up with sdcard.cfs which you can load the same way you did in the SD card recipe.

You will also have os.bin, which you can flash on your EEPROM the same way you already did before.

Running it

Compiling and running hello.asm is done very much like in the shell emulator:

Collapse OS
> sdci
> fson
> fopn 0 hello.asm
> fnew 1 dest
> fopn 1 dest
> zasm 1 2
> dest
Assembled from a RC2014
>

That RC2014 is starting to feel powerful now, right?

Test your hardware

Now that you have a fully functional filesystem that can load programs and run them easily, you'll see that this recipe's CFS include a couple of programs besides zasm. Among them, there's sdct that stress tests reading and writing on the SD card and memt that stress tests RAM. You might be interested in running them. Look at their description in apps/. All you need to to do run them is to type their name.

Assembling the kernel

Now let's go for something a little more fun! Jiu-jitsu? No, you're not going to learn jiu-jitsu! You're going to assemble the kernel from within your RC2014!

The makefile doesn't prepare a CFS blob for this, let's learn to build that blob yourself. First of all, we'll need to have what we already had in sdcard.cfs because it has zasm and user.h. But we're going to add the contents of the /kernel/ directory to it.

$ cp ../../../kernel/*.{h,asm} cfsin

You'll also need your glue file:

$ cp glue.asm cfsin

You're now ready to re-make your CFS:

$ rm sdcard.cfs && make

Now you can write this into your card and boot Collapse OS:

Collapse OS
> sdci
> fson
> fopn 0 glue.asm
> fnew 10 dest
> fopn 1 dest
> zasm 1 2          # This takes a while. About 7 minutes.
> sdcf              # success! sdcf flushes SD card buffers to the card.

Now let's go verify that we assembled the right thing. Pop out the card and plug it in your "modern" computer. Pipe the device directly through cfsunpack to unpack the FS into a directory (it will stop reading when it stops seeing CFS blocks):

$ sudo cat /dev/sdX | ../../../tools/cfspack/cfsunpack cfsout
$ cmp cfsout/dest ../os.bin

They're the same! Your RC2014 assembled a full Collapse OS kernel all by itself!