Skip to content

Commit

Permalink
z80all: initial support for Z80ALL
Browse files Browse the repository at this point in the history
Still need to add the quad 16x50 UART card but the rest is present
  • Loading branch information
EtchedPixels committed Apr 6, 2024
1 parent e2ef3d3 commit c885dec
Show file tree
Hide file tree
Showing 21 changed files with 1,403 additions and 0 deletions.
90 changes: 90 additions & 0 deletions Kernel/platform/platform-z80all/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
CROSS_CCOPTS += -I../../dev/

CSRCS = devtty.c devinput.o devices.c main.c

DISCSRCS = discard.c

ASRCS = crt0.S z80all.S video.S
ASRCS += tricks.S commonmem.S

DISCARD_DSRCS = ../../dev/tinydisk_discard.c ../../dev/tinyide_discard.c
DSRCS = ../../dev/tinydisk.c ../../dev/tinyide.c ../../dev/ps2kbd.o

COBJS = $(CSRCS:.c=.o)
AOBJS = $(ASRCS:.S=.o)
DISCOBJS = $(DISCSRCS:.c=.o)
DISCARD_DOBJS = $(DISCARD_DSRCS:.c=.o)
DOBJS = $(DSRCS:.c=.o)
DAOBJS = $(DASRCS:.S=.o)

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

JUNK = *.o

all: $(OBJS)

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

$(DISCOBJS): %.o: %.c
$(CROSS_CC) $(CROSS_CCOPTS) $(CROSS_CC_SEGDISC) -c $<

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

$(DISCARD_DOBJS): %.o: %.c
$(CROSS_CC) $(CROSS_CCOPTS) $(CROSS_CC_SEGDISC) -c $<

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

$(DAOBJS): %.o: %.S
$(CROSS_AS) $(ASOPTS) $@ $<

clean:
rm -f $(OBJS) $(JUNK) core *~ boot.ihx boot.o boot

#
# Attach the kernel to the boot block
#
image: boot
$(CROSS_LD) -b -C 0x0100 -S 0xF400 -f CLDBbXSs -o fuzix.bin \
crt0.o commonmem.o z80all.o ../../start.o \
../../version.o ../../cpu-z80u/lowlevel-z80u.o \
../../usermem.o tricks.o main.o discard.o \
../../timer.o ../../kdata.o devices.o ../../devio.o \
../../filesys.o ../../blk512.o ../../process.o \
../../inode.o ../../syscall_exec.o ../../syscall_exec16.o \
../../syscall_fs.o ../../syscall_fs2.o ../../syscall_fs3.o \
../../syscall_proc.o ../../syscall_other.o ../../syscall_net.o \
../../network.o ../../tty.o ../../mm.o ../../mm/memalloc_none.o \
../../swap.o ../../mm/bankfixed.o ../../devsys.o \
../../font/font8x8.o ../../vt.o video.o \
devtty.o ../../dev/tinydisk.o ../../dev/tinydisk_discard.o \
../../dev/tinyide.o ../../dev/tinyide_discard.o \
../../dev/ps2kbd.o ../../devinput.o devinput.o \
/opt/fcc/lib/z80/libz80.a -m fuzix.tmpmap
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

#
# Compile up the boot block
#
boot: boot.s
asz80 boot.s -o boot.o
ldz80 -b -C 0 boot.o -o boot.bin
../../tools/doubleup <boot.bin >boot

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

diskimage:
# Make a blank disk image with partition
dd if=$(FUZIX_ROOT)/Standalone/filesystem-src/parttab.20M of=$(IMAGES)/disk.img bs=20152320 conv=sync
# Add the file system
dd if=$(IMAGES)/filesys8.img of=$(IMAGES)/disk.img bs=512 seek=2048 conv=notrunc
# Add the kernel
dd if=../../fuzix.bin of=$(IMAGES)/disk.img bs=256 seek=4 skip=1 conv=notrunc
# Add the z80all bootstrap
dd if=boot of=$(IMAGES)/disk.img bs=446 count=1 conv=notrunc
# Make an emulator image of it
cat $(FUZIX_ROOT)/Standalone/filesystem-src/idehdr.20M $(IMAGES)/disk.img > $(IMAGES)/emu-ide.img
32 changes: 32 additions & 0 deletions Kernel/platform/platform-z80all/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Z80ALL

Bill Shen's 25.175MHz VGA and PS/2 capable Z80 Machine.

## Memory map

Kernel
0000-7FFF Kernel
8000-FFFF Kernel (fixed)

User
0000-7DFF Process
7E00-7FFF Udata stash

## Hardware:

Currently this build supports
- Onboard video
- PS/2 port
- CF interface
- Time tick

## TODO

- Allow for a second console with F1/F2 switch
- Support the Quad serial 16x50 @0xC0 (and maybe KIO ?)

## Installation

make diskimage

boot it. It does not need or want a softloaded ROMWBW.
77 changes: 77 additions & 0 deletions Kernel/platform/platform-z80all/boot.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@

.abs

.org 0x0000

start:
di
ld sp, 0x0000 ; safe spot
ld a, 0x80
out (0x1f),a ; ROM out
xor a
out (0x1f),a
ld hl, 0xB000
ld de, 0x0000
ld bc, 0x0100
ldir
jp go
go:
; Init the ATA CF
ld a, 0xE0
out (0x16),a
xor a
out (0x14),a
out (0x15),a
; Set 8bit mode
call wait_ready
ld a, 1 ; 8bit PIO
out (0x11),a
ld a, 0xEF ; SET FEATURES (8bit PIO)
out (0x17),a
call wait_ready

; Load the kernel
ld d, 1
ld bc, 0x10 ; c = data port b = 0
ld hl, 0x0100 ; Load 0x0100-F000 (should be sufficient)
loader:
inc d
call load_sector
ld a, 0xF1
cp h
jr nz, loader

ld hl,(0x0103)
ld de, 0x10DE
or a
sbc hl,de
jr nz, badimage

jp 0x0100
badimage:
di
halt
;
; Load sector d from disk into HL and advance HL accordingly
;
load_sector:
ld a,d
out (0x13),a ; LBA
ld a, 1
out (0x12),a ; 1 sector
ld a, 0x20
out (0x17),a ; command
; Wait
wait_drq:
in a,(0x17)
bit 3,a
jr z, wait_drq
; Get data, leave HL pointing to next byte, leaves B as 0 again
inir
inir
ret
wait_ready:
in a,(0x17)
bit 6,a
jr z,wait_ready
ret
9 changes: 9 additions & 0 deletions Kernel/platform/platform-z80all/commonmem.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
;
; The common memory area traditionally starts with the udata and the
; interrupt stacks. As this is standard in almost all cases you can
; just include the standard implementation.
;
.common

#include "../../cpu-z80u/std-commonmem.s"

72 changes: 72 additions & 0 deletions Kernel/platform/platform-z80all/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* 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

/* Select a banked memory set up */
#define CONFIG_BANK_FIXED
#define MAX_MAPS 2 /* 128K */
#define MAP_SIZE 0x8000
#define CONFIG_BANKS 2 /* 2 x 32K */

/*
* Define the program loading area (needs to match kernel.def)
*/
#define PROGBASE 0x0000 /* Base of user */
#define PROGLOAD 0x0100 /* Load and run here */
#define PROGTOP 0x7E00 /* Top of program, base of U_DATA stash */
#define PROC_SIZE 32 /* Memory needed per process including stash */

#define CONFIG_SWAP
#define CONFIG_DYNAMIC_SWAP
#define SWAPDEV (swap_dev)
extern uint16_t swap_dev;

#define SWAP_SIZE 0x40 /* 32K in blocks */
#define SWAPBASE 0x0000 /* We swap the lot in one, include the */
#define SWAPTOP 0x8000 /* vectors so its a round number of sectors */

#define MAX_SWAPS 16

#define swap_map(x) ((uint8_t *)(x))

#define CONFIG_TD_NUM 2
/* RC2014 style CF IDE */
#define CONFIG_TD_IDE
#define CONFIG_TINYIDE_8BIT
#define CONFIG_TINYIDE_INDIRECT
#define IDE_IS_8BIT(x) 1

#define BOOTDEVICENAMES "hd#"

/* We will resize the buffers available after boot. This is the normal setting */
#define CONFIG_DYNAMIC_BUFPOOL

#define CONFIG_LARGE_IO_DIRECT(x) 1

#define TICKSPERSEC 60 /* Ticks per second */

#define CONFIG_VT
#define VT_WIDTH 64
#define VT_HEIGHT 48
#define VT_RIGHT 63
#define VT_BOTTOM 47
#define CONFIG_FONT8X8
#define CONFIG_FONT8X8SMALL
#define CONFIG_INPUT
#define CONFIG_INPUT_GRABMAX 3

#define BOOT_TTY (512 + 1) /* Set this to default device for stdio, stderr */
#define CMDLINE NULL /* Location of root dev name */
#define NUM_DEV_TTY 1 /* How many tty devices does the platform support */
#define TTYDEV BOOT_TTY /* Device used by kernel for messages, panics */
#define NBUFS 5 /* Number of block buffers. Must be 4+ and must match
kernel.def */
#define NMOUNTS 3 /* Number of mounts at a time */
#define TTY_INIT_BAUD B115200 /* Actually fixed */

#define plt_copyright()
46 changes: 46 additions & 0 deletions Kernel/platform/platform-z80all/crt0.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
; startup code
.code

; Load at 0x0100
start:
jp go
.word 0x10DE
go:
di
ld sp, kstack_top
ld hl, __bss
ld de, __common
ld bc, __common_size
ldir
ld de, __commondata
ld bc, __commondata_size
ldir
ld de, __discard
ld bc, __discard_size - 1
ex de,hl
add hl,bc
ex de,hl
add hl,bc
lddr
ldd

; Zero the data area
ld hl, __bss
ld de, __bss + 1
ld bc, __bss_size - 1
ld (hl), 0
ldir

; Zero buffers area
ld hl, __buffers
ld de, __buffers+1
ld bc, __buffers_size - 1
ld (hl), 0
ldir

call init_early
call init_hardware
call _fuzix_main
di
stop: halt
jr stop
33 changes: 33 additions & 0 deletions Kernel/platform/platform-z80all/devices.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <kernel.h>
#include <tty.h>
#include <version.h>
#include <kdata.h>
#include <devsys.h>
#include <devtty.h>
#include <tinydisk.h>
#include <printf.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 */
{ no_open, no_close, no_rdwr, no_rdwr, no_ioctl },
/* 2: /dev/tty TTY devices */
{ tty_open, tty_close, tty_read, tty_write, vga_ioctl },
/* 3: /dev/lpr Printer devices */
{ nxio_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 },
/* 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;
}
Loading

0 comments on commit c885dec

Please sign in to comment.