recipe/rc2014/zasm: new recipe

This commit is contained in:
Virgil Dupras 2019-06-03 13:34:16 -04:00
parent dfe19e20e4
commit 50a26f6e39
9 changed files with 277 additions and 0 deletions

View File

@ -24,6 +24,7 @@ This recipe is for installing a minimal Collapse OS system on the RC2014. There
are other recipes related to the RC2014:
* [Accessing a MicroSD card](sdcard/README.md)
* [Assembling binaries](zasm/README.md)
## Goal

1
recipes/rc2014/zasm/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/cfsin/zasm

View File

@ -0,0 +1,25 @@
CFSTARGETS = cfsin/zasm cfsin/user.h
BASE = ../../..
TOOLS = $(BASE)/tools
ZASM = $(TOOLS)/zasm.sh
KERNEL = $(BASE)/kernel
APPS = $(BASE)/apps
CFSPACK = $(TOOLS)/cfspack/cfspack
.PHONY: all
all: os.bin sdcard.cfs
os.bin: glue.asm
$(ZASM) $(KERNEL) < $< > $@
$(CFSPACK):
make -C $(TOOLS)/cfspack
sdcard.cfs: $(CFSTARGETS) $(CFSPACK)
$(CFSPACK) cfsin > $@
cfsin/zasm: $(ZASMBIN)
$(ZASM) $(KERNEL) $(APPS) user.h < $(APPS)/zasm/glue.asm > $@
cfsin/user.h: user.h
cp $< $@

View File

@ -0,0 +1,62 @@
# 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.
**Work in progress: for now, we compile a simple hello.asm source file.**
## Gathering parts
* Same parts as the [SD card recipe](../sdcard).
## 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](../../../doc/zasm.md):
Collapse OS
> sdci
> fson
> fopn 0 hello.asm
> zasm 2 1
> mptr 8600
> bsel 1
> seek 00 0000
> load ff
> call 00 0000
Assembled from a RC2014
That RC2014 is starting to feel powerful now, right?

View File

@ -0,0 +1,11 @@
#include "user.h"
.org USER_CODE
ld hl, sAwesome
call printstr
xor a ; success
ret
sAwesome:
.db "Assembled from a RC2014", 0x0d, 0x0a, 0

View File

@ -0,0 +1,26 @@
.equ USER_CODE 0x8600
.equ USER_RAMSTART USER_CODE+0x1800
.equ FS_HANDLE_SIZE 8
; *** JUMP TABLE ***
.equ strncmp 0x03
.equ addDE 0x06
.equ addHL 0x09
.equ upcase 0x0c
.equ unsetZ 0x0f
.equ intoDE 0x12
.equ intoHL 0x15
.equ writeHLinDE 0x18
.equ findchar 0x1b
.equ parseHex 0x1e
.equ parseHexPair 0x21
.equ blkSel 0x24
.equ fsFindFN 0x27
.equ fsOpen 0x2a
.equ fsGetC 0x2d
.equ fsSeek 0x30
.equ fsTell 0x33
.equ cpHLDE 0x3b
.equ parseArgs 0x3e
.equ printstr 0x41

View File

@ -0,0 +1,124 @@
; classic RC2014 setup (8K ROM + 32K RAM) and a stock Serial I/O module
; The RAM module is selected on A15, so it has the range 0x8000-0xffff
.equ RAMSTART 0x8000
; kernel RAM usage is under 0x300 bytes. We give ourselves at least 0x300 bytes
; for the stack.
.equ RAMEND 0x8600
.equ PGM_CODEADDR RAMEND
.equ ACIA_CTL 0x80 ; Control and status. RS off.
.equ ACIA_IO 0x81 ; Transmit. RS on.
jp init ; 3 bytes
; *** Jump Table ***
jp strncmp
jp addDE
jp addHL
jp upcase
jp unsetZ
jp intoDE
jp intoHL
jp writeHLinDE
jp findchar
jp parseHex
jp parseHexPair
jp blkSel
jp fsFindFN
jp fsOpen
jp fsGetC
jp fsSeek
jp fsTell ; approaching 0x38...
; interrupt hook
.fill 0x38-$
jp aciaInt
; *** Jump Table (cont.) ***
jp cpHLDE
jp parseArgs
jp printstr
#include "err.h"
#include "core.asm"
#include "parse.asm"
.equ ACIA_RAMSTART RAMSTART
#include "acia.asm"
.equ BLOCKDEV_RAMSTART ACIA_RAMEND
.equ BLOCKDEV_COUNT 3
#include "blockdev.asm"
; List of devices
.dw sdcGetC, sdcPutC, sdcSeek, sdcTell
.dw mmapGetC, mmapPutC, mmapSeek, mmapTell
.dw blk2GetC, blk2PutC, blk2Seek, blk2Tell
#include "blockdev_cmds.asm"
.equ MMAP_RAMSTART BLOCKDEV_RAMEND
.equ MMAP_START 0xe000
#include "mmap.asm"
.equ STDIO_RAMSTART MMAP_RAMEND
#include "stdio.asm"
.equ FS_RAMSTART STDIO_RAMEND
.equ FS_HANDLE_COUNT 1
#include "fs.asm"
#include "fs_cmds.asm"
.equ SHELL_RAMSTART FS_RAMEND
.equ SHELL_EXTRA_CMD_COUNT 11
#include "shell.asm"
.dw sdcInitializeCmd, sdcFlushCmd
.dw blkBselCmd, blkSeekCmd, blkLoadCmd, blkSaveCmd
.dw fsOnCmd, flsCmd, fnewCmd, fdelCmd, fopnCmd
.equ PGM_RAMSTART SHELL_RAMEND
#include "pgm.asm"
.equ SDC_RAMSTART PGM_RAMEND
.equ SDC_PORT_CSHIGH 6
.equ SDC_PORT_CSLOW 5
.equ SDC_PORT_SPI 4
#include "sdc.asm"
.out SDC_RAMEND
init:
di
; setup stack
ld hl, RAMEND
ld sp, hl
im 1
call aciaInit
ld hl, aciaGetC
ld de, aciaPutC
call stdioInit
call mmapInit
call shellInit
ld hl, pgmShellHook
ld (SHELL_CMDHOOK), hl
xor a
ld de, BLOCKDEV_GETC
call blkSel
ei
jp shellLoop
; *** blkdev 2: file handle 0 ***
blk2GetC:
ld ix, FS_HANDLES
jp fsGetC
blk2PutC:
ld ix, FS_HANDLES
jp fsPutC
blk2Seek:
ld ix, FS_HANDLES
jp fsSeek
blk2Tell:
ld ix, FS_HANDLES
jp fsTell

View File

@ -0,0 +1,26 @@
.equ USER_CODE 0x8600
.equ USER_RAMSTART USER_CODE+0x1800
.equ FS_HANDLE_SIZE 8
; *** JUMP TABLE ***
.equ strncmp 0x03
.equ addDE 0x06
.equ addHL 0x09
.equ upcase 0x0c
.equ unsetZ 0x0f
.equ intoDE 0x12
.equ intoHL 0x15
.equ writeHLinDE 0x18
.equ findchar 0x1b
.equ parseHex 0x1e
.equ parseHexPair 0x21
.equ blkSel 0x24
.equ fsFindFN 0x27
.equ fsOpen 0x2a
.equ fsGetC 0x2d
.equ fsSeek 0x30
.equ fsTell 0x33
.equ cpHLDE 0x3b
.equ parseArgs 0x3e
.equ printstr 0x41

View File

@ -81,6 +81,7 @@ init:
ld hl, emulGetC
ld de, emulPutC
call stdioInit
call mmapInit
call fsInit
ld a, 0 ; select fsdev
ld de, BLOCKDEV_GETC