Skip to content

Commit

Permalink
Merge pull request #1045 from NollKollTroll/master
Browse files Browse the repository at this point in the history
PZ1: Blockdevice, names & formatting
  • Loading branch information
EtchedPixels authored Feb 19, 2024
2 parents aacad03 + e9778e0 commit 5ff2d5e
Show file tree
Hide file tree
Showing 13 changed files with 263 additions and 256 deletions.
19 changes: 15 additions & 4 deletions Kernel/platform/platform-pz1/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
CSRCS = devtty.c devhd.c
CSRCS += main.c devices.c

CDSRCS = ../../dev/tinydisk_discard.c

DSRCS = ../../dev/tinydisk.c

ASRCS = pz1.s crt0.s
ASRCS += tricks.s commonmem.s

COBJS = $(CSRCS:.c=$(BINEXT))
AOBJS = $(ASRCS:.s=$(BINEXT))
DOBJS = $(patsubst ../../dev/%.c,%.o, $(DSRCS))
CDOBJS = $(CDSRCS:.c=$(BINEXT))

OBJS = $(COBJS) $(AOBJS)
OBJS = $(COBJS) $(AOBJS) $(DOBJS) $(CDOBJS)

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

Expand All @@ -17,6 +23,12 @@ all: $(OBJS)
$(COBJS): %$(BINEXT): %.c
$(CROSS_CC) $(CROSS_CCOPTS) $(CROSS_CC_SEG1) $<

$(CDOBJS): %$(BINEXT): %.c
$(CROSS_CC) $(CROSS_CCOPTS) $(CROSS_CC_SEGDISC) -c $<

$(DOBJS): %$(BINEXT): ../../dev/%.c
$(CROSS_CC) $(CROSS_CCOPTS) $(HIGH) -c $<

$(AOBJS): %$(BINEXT): %.s
$(CROSS_AS) $(ASOPTS) $< -o $*$(BINEXT)

Expand All @@ -27,18 +39,17 @@ image:
$(CROSS_LD) -o ../../fuzix.bin --mapfile ../../fuzix.map -C ld65.cfg crt0.o commonmem.o \
pz1.o ../../start.o ../../version.o ../../cpu-6502/lowlevel-6502.o \
tricks.o main.o ../../timer.o ../../kdata.o devices.o \
devhd.o ../../mm/memalloc_none.o \
devhd.o ../../mm/memalloc_none.o ../../dev/tinydisk.o ../../dev/tinydisk_discard.o \
../../devio.o ../../filesys.o ../../process.o ../../inode.o ../../syscall_fs.o \
../../syscall_proc.o ../../syscall_other.o ../../mm.o ../../mm/bankfixed.o \
../../tty.o ../../devsys.o ../../syscall_fs2.o ../../syscall_fs3.o \
../../syscall_exec16.o ../../syscall_exec.o ../../blk512.o \
../../usermem.o ../../cpu-6502/usermem_std-6502.o devtty.o
dd if=../../fuzix.bin of=fuzix.img bs=256 skip=4

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

diskimage: image
cp fuzix.img $(IMAGES)/fuzix.rom
cp ../../fuzix.bin $(IMAGES)/fuzix.rom
# 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 file system
Expand Down
29 changes: 16 additions & 13 deletions Kernel/platform/platform-pz1/README
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Initial support for the PZ1
Support for the PZ1 platform

Use a modern cc65 from https://github.com/cc65/cc65 (2.18 as shipped in
many Linux distributions is just fine).
many Linux distributions works well).

Although the memory card can operate as 4 independent 16K pages for simplicity
at this point we treat it as if it just provided 16K and 48K
Although the memory can operate as 4 independent 16K pages, for simplicity
at this point we treat it as if it just provided 16K and 48K.

Interrupts deal wth the shared ZP by swapping the ZP back and forth with the
interrupt copies (about 20 bytes involved)
Expand All @@ -28,11 +28,14 @@ User space:

The memory banks are allocated as follows

32 RAM mapped initially at 0-16K
33 RAM mapped initially at 16-32K
34 RAM mapped initially at 32-48K
35 RAM mapped initially at 48K-64K
36-63 Handed out in fours for process maps
0 RAM mapped initially at 0-16K
1 RAM mapped initially at 16-32K
2 RAM mapped initially at 32-48K
3 RAM mapped initially at 48K-64K
4-31 Handed out in fours for process maps

This port is based on the rcbus-6502 port, so share most of the same features
and missing bits.

The 6502 port has some interesting gotchas to be aware of and things that
need addressing
Expand Down Expand Up @@ -77,9 +80,9 @@ Swap support
Lots of features
Virtual disk partitioning or multiple volumes

Emulator:

EmulatorKit usage:
make diskimage
./pz1 -r fuzix.rom -i disk.img

./pz1 -r fuzix.img -i filesys.img

fix for erase in console:
stty erase '^?'
47 changes: 29 additions & 18 deletions Kernel/platform/platform-pz1/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,55 @@
#define CONFIG_BANKS 1
/* Permit large I/O requests to bypass cache and go direct to userspace */
#define CONFIG_LARGE_IO_DIRECT(x) (1)

#define CONFIG_CALL_R2L /* Runtime stacks arguments backwards */
/* Runtime stacks arguments backwards */
#define CONFIG_CALL_R2L

/*
* 1024K RAM (swap yet to do ) - not yet using it all
* 512K RAM (swap yet to do ) - not yet using it all
* Question: is common better top or bottom ?
* Top means we switch ZP and 6502 stacks, bottom means we don't but
* have to copy stuff/watching sharing
*/
#define CONFIG_BANK_FIXED
#define MAX_MAPS 7 /* 9 x 64K */
#define MAX_MAPS 7 /* 9 x 64K */
#define MAP_SIZE 0xDE00

#define TICKSPERSEC 100 /* Ticks per second */
#define TICKSPERSEC 100 /* Ticks per second */

/* We've not yet made the rest of the code - eg tricks match this ! */
#define MAPBASE 0x0000 /* We map from 0 */
#define PROGBASE 0x2000 /* also data base */
#define PROGLOAD 0x2000
#define PROGTOP 0xFE00
#define MAPBASE 0x0000 /* We map from 0 */
#define PROGBASE 0x2000 /* also data base */
#define PROGLOAD 0x2000
#define PROGTOP 0xFE00

/* FIXME: swap */
/* TODO: swap */
//#define SWAPDEV 1
//#define SWAP_SIZE 127 /* 0xfe00 / 512 */
//#define SWAPBASE 0x0000 /* We swap the lot in one, include the */
//#define SWAPTOP 0xfe00 /* uarea so its a round number of sectors */
//#define UDATA_BLOCKS 0 /* We swap the uarea in the data */
//#define UDATA_SWAPSIZE 0
//#define MAX_SWAPS 16
//#define swap_map(x) ((uint8_t *)(x & 0x3fff ))

#define BOOT_TTY 513 /* Set this to default device for stdio, stderr */
#define BOOT_TTY 513 /* Set this to default device for stdio, stderr */

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

/* Device parameters */
#define NUM_DEV_TTY 2
#define TTYDEV BOOT_TTY /* Device used by kernel for messages, panics */
#define NBUFS 5 /* Number of block buffers */
#define NUM_DEV_TTY 2
#define TTYDEV BOOT_TTY/* Device used by kernel for messages, panics */
#define NBUFS 5 /* Number of block buffers */

/* Block device define */
#define CONFIG_TD_NUM 1

#define plt_discard()
#define plt_copyright()

#define MAX_BLKDEV 1
#define NMOUNTS 1 /* Number of mounts at a time */
#define BOOTDEVICE 0x0000 /* Only one possible option */
#define MAX_BLKDEV 1
#define NMOUNTS 2 /* Number of mounts at a time */
#define BOOTDEVICENAMES "hda"

#define CONFIG_SMALL
87 changes: 25 additions & 62 deletions Kernel/platform/platform-pz1/devhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,77 +7,40 @@
#include <printf.h>
#include <devhd.h>
#include <ports.h>
#include <tinydisk.h>

#define BLOCK_SIZE 512

int hd_open(uint_fast8_t minor, uint16_t flag)
{
used(flag);
if(minor != 0) {
udata.u_error = ENODEV;
return -1;
}
return 0;
}

/* Asm transfer routines in common space */
extern uint8_t hd_data_in(uint8_t *ptr);
extern uint8_t hd_data_out(uint8_t *ptr);

uint8_t hd_mode;

/* The main disk read/write loop */
int hd_rw(uint_fast8_t minor, bool is_read, uint_fast8_t rawflag)
{
uint8_t *dptr;
uint16_t n = 0;

used(minor);
used(flag);

if (rawflag == 1) {
if (d_blkoff(BLKSHIFT))
return -1;
}
/* No swap support yet. In the swap case we do I/O to or from the page
in swappage */
if (rawflag == 2)
return -1;

// seek to wanted block
port_fs_prm0 = udata.u_block & 255;
port_fs_prm1 = udata.u_block >> 8;
port_fs_cmd = FS_CMD_SEEK;

if (port_fs_status != FS_STATUS_OK)
return -1;

dptr = udata.u_dptr;
hd_mode = rawflag;

// kprintf("I/O %u sector(s) from %u to address %u\n", udata.u_nblock, udata.u_block, udata.u_dptr);

while (udata.u_nblock--) {
if (is_read) {
if (hd_data_in(dptr))
break;
} else if (hd_data_out(dptr))
break;
dptr += BLKSIZE;
n += BLKSIZE;
}
// kprintf("I/O completd %u\n", n);
return n;
}

int hd_read(uint8_t minor, uint8_t rawflag, uint8_t flag)
int hd_xfer(uint8_t dev, bool is_read, uint32_t lba, uint8_t * dptr)
{
used(flag);
return hd_rw(minor, true, rawflag);
if ((dev >> 4) != 0)
return 0;

/* seek to wanted block using 24-bit LBA */
io_disk_prm0 = (uint8_t)(lba & 255);
io_disk_prm1 = (uint8_t)(lba >> 8);
io_disk_prm2 = (uint8_t)(lba >> 16);
io_disk_cmd = DISK_CMD_SEEK;
if (io_disk_status != DISK_STATUS_OK)
return 0;

/* transfer a block */
if (is_read) {
if (hd_data_in(dptr))
return 0; /* failure to read complete block */
} else {
if (hd_data_out(dptr))
return 0; /* failure to write complete block */
}
/* all is well! */
return 1;
}

int hd_write(uint8_t minor, uint8_t rawflag, uint8_t flag)
void hd_init(void)
{
used(flag);
return hd_rw(minor, false, rawflag);
td_register(0, hd_xfer, td_ioctl_none, 1);
}
4 changes: 1 addition & 3 deletions Kernel/platform/platform-pz1/devhd.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
#define __DEVHD_DOT_H__

/* public interface */
int hd_read(uint_fast8_t minor, uint_fast8_t rawflag, uint_fast8_t flag);
int hd_write(uint_fast8_t minor, uint_fast8_t rawflag, uint_fast8_t flag);
int hd_open(uint_fast8_t minor, uint16_t flag);
void hd_init(void);

#endif /* __DEVHD_DOT_H__ */

36 changes: 18 additions & 18 deletions Kernel/platform/platform-pz1/devices.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@
#include <devsys.h>
#include <tty.h>
#include <devtty.h>
#include <tinydisk.h>
#include <devhd.h>

struct devsw dev_tab[] = /* The device driver switch table */
{
// open close read write ioctl
// open close read write ioctl
// -----------------------------------------------------------------
/* 0: /dev/hd - block device interface */
{ hd_open, no_close, hd_read, hd_write, no_ioctl},
/* 1: /dev/fd - Floppy disk 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, 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},
/* Pack to 7 with nxio if adding private devices and start at 8 */
/* 0: /dev/hd - block device interface */
{ td_open, no_close, td_read, td_write, td_ioctl},
/* 1: /dev/fd - Floppy disk 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, 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},
/* 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;
/* 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 5ff2d5e

Please sign in to comment.