Skip to content

Commit

Permalink
z8: kernel experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
EtchedPixels committed Feb 14, 2024
1 parent 81772b7 commit e6a3c19
Show file tree
Hide file tree
Showing 16 changed files with 943 additions and 0 deletions.
84 changes: 84 additions & 0 deletions Kernel/platform/platform-rcbus-z8/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
LIBPATH=../../Library/libs

CSRCS += devices.c main.c devtty.c
DISCARD_CSRCS = discard.c

DISCARD_DSRCS = ../../dev/tinydisk_discard.c ../../dev/tinysd_discard.c
DSRCS = ../../dev/tinydisk.c ../../dev/tinysd.c

CROSS_CCOPTS += -I../../dev/

ASRCS = crt0.S commonmem.S rcbus-z8.S tricks.S
DASRCS =

AOBJS = $(ASRCS:.S=.o)
COBJS = $(CSRCS:.c=.o)
DISCARD_COBJS = $(DISCARD_CSRCS:.c=.o)
DISCARD_DOBJS = $(patsubst ../../dev/%.c,%.o, $(DISCARD_DSRCS))
DOBJS = $(patsubst ../../dev/%.c,%.o, $(DSRCS))
DAOBJS = $(patsubst ../../dev/%.S,%.o, $(DASRCS))

OBJS = $(AOBJS) $(COBJS) $(DISCARD_COBJS) $(DISCARD_DOBJS) $(DAOBJS) $(DOBJS)

JUNK = *.o *.lst *.asm *.sym *.rst

all: $(OBJS)

$(AOBJS): %.o: %.S
$(CROSS_AS) $(ASOPTS) $<

$(COBJS): %.o: %.c
$(CROSS_CC) $(CROSS_CCOPTS) $<

$(DISCARD_COBJS): %.o: %.c
$(CROSS_CC) $(CROSS_CCOPTS) -Tdiscard $<

$(DOBJS): %.o: ../../dev/%.c
$(CROSS_CC) $(CROSS_CCOPTS) $<

$(DAOBJS): %.o: ../../dev/%.s
$(CROSS_AS) $(ASOPTS) $<

# Need to make discard work yet
$(DISCARD_DOBJS): %.o: ../../dev/%.c
$(CROSS_CC) $(CROSS_CCOPTS) -Tdiscard $<

clean:
rm -f $(OBJS) $(JUNK) core *~ bootblock.bin bootblock fuzix.bin loader.tmp

image:
$(CROSS_LD) -t -b -C 0x0100 -S 0xF000 -f CLDBbXSs -o fuzix.bin crt0.o devices.o main.o \
discard.o commonmem.o tricks.o rcbus-z8.o devtty.o \
../../start.o ../../version.o ../../cpu-z8/lowlevel-z8.o \
../../mm/bankfixed.o ../../timer.o ../../kdata.o ../../mm/memalloc_none.o \
../../devio.o ../../filesys.o ../../process.o ../../inode.o ../../syscall_fs.o \
../../syscall_proc.o ../../syscall_other.o ../../mm.o ../../swap.o \
../../tty.o ../../devsys.o ../../usermem.o ../../syscall_fs2.o \
../../syscall_fs3.o ../../syscall_exec.o ../../syscall_exec16.o \
../../dev/tinydisk.o ../../dev/tinysd.o \
../../dev/tinydisk_discard.o ../../dev/tinysd_discard.o \
../../blk512.o ../../cpu-z8/usermem_std-z8.o -m fuzix.tmpmap /opt/fcc/lib/z8/libz8.a
perl -lpe '$$_=hex' fuzix.tmpmap | paste -d" " - fuzix.tmpmap | sort -n | cut -d" " -f 2- >../../fuzix.map
../../tools/pack85 <../../fuzix.map fuzix.bin ../../fuzix.bin

loader.o: loader.S
$(CROSS_AS) $(ASOPS) loader.S

loader: loader.o
$(CROSS_LD) -b -C 0xFE00 loader.o -o loader.tmp
dd if=loader.tmp of=loader bs=256 skip=254

IMAGES = $(FUZIX_ROOT)/Images/$(TARGET)

diskimage: loader
dd if=../../fuzix.bin of=fuzix.img bs=256 skip=1
# Make a blank disk image with partition
dd if=$(FUZIX_ROOT)/Standalone/filesystem-src/parttab.40M of=$(IMAGES)/disk.img bs=40017920 conv=sync
# Add the bootstrap loader
dd if=loader of=$(IMAGES)/disk.img conv=notrunc
# Add the file system
dd if=$(IMAGES)/filesys.img of=$(IMAGES)/disk.img bs=512 seek=2048 conv=notrunc
# Add the kernel
dd if=fuzix.img of=$(IMAGES)/disk.img bs=512 seek=1 conv=notrunc
# Make an emulator image of it
cat $(FUZIX_ROOT)/Standalone/filesystem-src/idehdr.40M $(IMAGES)/disk.img > $(IMAGES)/emu-ide.img
4 changes: 4 additions & 0 deletions Kernel/platform/platform-rcbus-z8/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Initial sketch to see if Z8 is doable

Currently the compiler can't generate dense enough code to make it fit.

4 changes: 4 additions & 0 deletions Kernel/platform/platform-rcbus-z8/commonmem.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "../../cpu-z8/kernel-z8.def"

.common
#include "../../cpu-z8/std-commonmem.s"
62 changes: 62 additions & 0 deletions Kernel/platform/platform-rcbus-z8/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* We have an RTC */
#undef CONFIG_RTC
/* And we can read ToD from it */
#undef CONFIG_RTC_FULL
/* Enable to make ^Z dump the inode table for debug */
#undef CONFIG_IDUMP
/* Enable to make ^A drop back into the monitor */
#undef CONFIG_MONITOR
/* Profil syscall support (not yet complete) */
#undef CONFIG_PROFIL
/* Multiple processes in memory at once */
#define CONFIG_MULTI
/* Fixed banking */
#define CONFIG_BANK_FIXED
/* 2 32K banks, + 64K is kernel */
/* When we run from flash we'll fix this to 2 x 64K */
#define MAX_MAPS 2
#define MAP_SIZE 0x8000U

#define CONFIG_TD_NUM 1
#define TD_SD_NUM 1

/* Read processes and big I/O direct into process space */
#define CONFIG_LARGE_IO_DIRECT(x) 1

/* Banks as reported to user space */
#define CONFIG_BANKS 1

#define TICKSPERSEC 200 /* Ticks per second */
#define PROGBASE 0x0000 /* also data base */
#define PROGLOAD 0x0100 /* also data base */
#define PROGTOP 0xBE00 /* Top of program, base of U_DATA copy */
#define PROC_SIZE 48 /* Memory needed per process */

/* Swap not enabled yet */
#define SWAP_SIZE 0x60 /* 48K in blocks (we actually don't need the low 256) */
#define SWAPBASE 0x0000 /* We swap the lot in one, include the */
#define SWAPTOP 0xC000 /* vectors so its a round number of sectors */
#define MAX_SWAPS 16 /* The full drive would actually be 85! */

#define swap_map(x) ((uint8_t *)(x)) /* Simple zero based mapping */

#define BOOT_TTY (512 + 1)/* Set this to default device for stdio, stderr */
/* In this case, the default is the first TTY device */

/* We need a tidier way to do this from the loader */
#define CMDLINE NULL /* Location of root dev name */

/* Device parameters */
#define NUM_DEV_TTY 3

#define TTYDEV BOOT_TTY /* Device used by kernel for messages, panics */
#if 0
#define SWAPDEV (256 + 1) /* Device for swapping. (FIXME) */
#endif
#define NBUFS 8 /* Number of block buffers */
#define NMOUNTS 4 /* Number of mounts at a time */

#define plt_discard()
#define plt_copyright()

#define BOOTDEVICENAMES "hd#"
71 changes: 71 additions & 0 deletions Kernel/platform/platform-rcbus-z8/crt0.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include "../../cpu-z8/kernel-z8.def"

.code

.export init

.word 0x5A38

init:
di
srp #10
ld 254,#>kstack_top
ld 255,#<kstack_top

call init_early

; Common is packed in the BSS space

ld r14,#>__common
ld r15,#<__common
ld r12,#>__bss
ld r13,#<__bss
ld r10,#>__common_size
ld r11,#<__common_size

; Copy it high
nextbyte:
lde r0,@rr12
lde @rr14,r0
incw rr12
incw rr14
decw rr10
jr nz, nextbyte

; The discard follows the common
ld r14,#>__discard
ld r15,#<__discard
ld r10,#>__discard_size
ld r11,#<__discard_size
; Go from the end as we want to copy backwards in case of
; an overlap
add r15,r11
adc r14,r10
add r13,r11
adc r12,r10

nextbyted:
decw rr12
decw rr14
lde r0,@rr12
lde @rr14,r0
decw rr10
jr nz, nextbyted

ld r12,#>__bss
ld r13,#<__bss
ld r10,#>__bss_size
ld r11,#<__bss_size
clr r0
wipe:
lde @rr12,r0
incw rr12
decw rr10
jr nz, wipe

call init_hardware

call _fuzix_main
di
end: stop
jp end
40 changes: 40 additions & 0 deletions Kernel/platform/platform-rcbus-z8/devices.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <kernel.h>
#include <version.h>
#include <kdata.h>
#include <tty.h>
#include <devsys.h>
#include <devtty.h>
#include <tinydisk.h>
#include <tinysd.h>

struct devsw dev_tab[] = /* The device driver switch table */
{
/* 0: /dev/hd Hard disc block devices */
{ td_open, no_close, td_read, td_write, td_ioctl },
/* 1: /dev/fd Floppy disc block devices: nope */
{ no_open, no_close, no_rdwr, no_rdwr, no_ioctl },
/* 2: /dev/tty TTY devices */
{ tty_open, tty_close, tty_read, tty_write, tty_ioctl },
/* 3: /dev/lpr Printer devices */
{ no_open, no_close, no_rdwr, no_rdwr, no_ioctl },
/* 4: /dev/mem etc System devices (one offs) */
{ no_open, no_close, sys_read, sys_write, sys_ioctl },
/* 5: Pack to 7 with nxio if adding private devices and start at 8 */
};

bool validdev(uint16_t dev)
{
/* This is a bit uglier than needed but the right hand side is
a constant this way */
if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1)
return false;
else
return true;
}

void device_init(void)
{
#ifdef CONFIG_SD
sd_probe();
#endif
}
77 changes: 77 additions & 0 deletions Kernel/platform/platform-rcbus-z8/devtty.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include <kernel.h>
#include <kdata.h>
#include <printf.h>
#include <stdbool.h>
#include <tty.h>
#include <devtty.h>

static char tbuf1[TTYSIZ];

/* For now just the Z8 console port */
struct s_queue ttyinq[NUM_DEV_TTY+1] = { /* ttyinq[0] is never used */
{ NULL, NULL, NULL, 0, 0, 0 },
{ tbuf1, tbuf1, tbuf1, TTYSIZ, 0, TTYSIZ/2 },
};

/* TODO: stty support */
tcflag_t termios_mask[NUM_DEV_TTY + 1] = {
0,
_CSYS
};

void tty_setup(uint_fast8_t minor, uint_fast8_t flags)
{
minor;
}

/* For the moment */
int tty_carrier(uint_fast8_t minor)
{
minor;
return 1;
}

/*
* Drain the interrupt queue
*/
void tty_pollirq(void)
{
uint16_t c;
while((c = z8tty_get()) != 0xFFFF)
tty_inproc(1, c);
}

void tty_putc(uint_fast8_t minor, unsigned c)
{
z8tty_put(c);
}

void tty_sleeping(uint_fast8_t minor)
{
minor;
}

void tty_data_consumed(uint_fast8_t minor)
{
}

ttyready_t tty_writeready(uint_fast8_t minor)
{
uint16_t r = z8tty_status();
/* FIXME: should go IRQ driven */
if (r & 0x10)
return TTY_READY_NOW;
else
return TTY_READY_SOON;
}

/* kernel writes to system console -- never sleep! */
void kputchar(unsigned c)
{
while(tty_writeready(TTYDEV) != TTY_READY_NOW);
tty_putc(TTYDEV & 0xFF, c);
if(c == '\n') {
while(tty_writeready(TTYDEV) != TTY_READY_NOW);
tty_putc(TTYDEV & 0xFF, '\r');
}
}
6 changes: 6 additions & 0 deletions Kernel/platform/platform-rcbus-z8/devtty.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extern void tty_pollirq(void);

extern uint16_t z8tty_get(void);
extern void z8tty_put(unsigned c);
extern uint16_t z8tty_status(void);

21 changes: 21 additions & 0 deletions Kernel/platform/platform-rcbus-z8/discard.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <kernel.h>

/* Add memory */
void pagemap_init(void)
{
register unsigned i;
/* Simple banking to get us going */
for (i = 35; i <= 63; i+=3)
pagemap_add(i);
/* TODO: do we need 35 last ? */
}

void map_init(void)
{
}

uint_fast8_t plt_param(char *p)
{
used(p);
return 0;
}
Empty file.
10 changes: 10 additions & 0 deletions Kernel/platform/platform-rcbus-z8/kernel.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
; UZI mnemonics for memory addresses etc

U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes @E000

U_DATA_STASH .equ 0xBE00 ; BE00-BFFF

PROGBASE .equ 0x0000
PROGLOAD .equ 0x0100

CONFIG_SWAP .equ 1
Loading

0 comments on commit e6a3c19

Please sign in to comment.