Skip to content

Commit

Permalink
rcbus-z8: more work on Z8 bring up
Browse files Browse the repository at this point in the history
  • Loading branch information
EtchedPixels committed Mar 8, 2024
1 parent da2ba26 commit c520836
Show file tree
Hide file tree
Showing 8 changed files with 240 additions and 50 deletions.
6 changes: 4 additions & 2 deletions Kernel/platform/platform-rcbus-z8/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ 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
DISCARD_DSRCS += ../../dev/tinyide_discard.c
DSRCS = ../../dev/tinydisk.c ../../dev/tinysd.c ../../dev/tinyide.c

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

Expand Down Expand Up @@ -55,8 +56,9 @@ image:
../../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.o ../../dev/tinysd.o ../../dev/tinyide.o \
../../dev/tinydisk_discard.o ../../dev/tinysd_discard.o \
../../dev/tinyide_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
cp fuzix.bin ../../fuzix.bin
Expand Down
4 changes: 4 additions & 0 deletions Kernel/platform/platform-rcbus-z8/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#define CONFIG_TD_SD
#define TD_SD_NUM 1

#define CONFIG_TD_IDE
#define TD_IDE_NUM 2
#define CONFIG_TINYIDE_INDIRECT

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

Expand Down
44 changes: 13 additions & 31 deletions Kernel/platform/platform-rcbus-z8/crt0.S
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "../../cpu-z8/kernel-z8.def"

.code

.export init

.word 0x5A38
.word 0x5A38 ; magic
; Next 5 words and this get trampled by IRQ vectors

init:
di
Expand All @@ -14,43 +14,25 @@ init:

call init_early

; Common is packed in the BSS space

; Shuffle up the segments we packed at the end and which
; cover E000-FFFF areas. We put them in the upper 8K of
; the data area in the load (C000-DFFF)
ld r12,#0xC0
clr r13
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
copy_common:
lde r9,@rr12
ldc @rr14,r9 ; From data to code map
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
jr nz, copy_common

nextbyted:
decw rr12
decw rr14
lde r0,@rr12
lde @rr14,r0
decw rr10
jr nz, nextbyted
copy_commondata:
; Currently no commondata - add if needed

ld r12,#>__bss
ld r13,#<__bss
Expand Down
71 changes: 66 additions & 5 deletions Kernel/platform/platform-rcbus-z8/devtty.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,72 @@ tcflag_t termios_mask[NUM_DEV_TTY + 1] = {
_CSYS
};

/* Low bits are T0, upper bits are divider */
/* The requirement is clock / (128 * divider * prescale) */

#ifdef CONFIG_CLK_14M7
static const uint16_t baudtab[] = {
0,
/* Prescale by 12 */
0x39C0, /* 50 */
0x3980, /* 75 */
/* Prescale by 8 */
0x2183, /* 110 */
/* Prescale by 6 */
0x0DAE, /* 134.5 */
0x1180, /* 150 */
/* Prescale by 3 */
0x0D80, /* 300 */
0x0D40, /* 600 */
0x0D20, /* 1200 */
0x0D10, /* 2400 */
0x0D08, /* 4800 */
0x0D04, /* 9600 */
0x0D02, /* 19200 */
0x0D01, /* 38400 */
/* Prescale by 1 */
0x0502, /* 57600 */
0x0501, /* 115200 */
};
#else
/* Curently set up for 7.3728MHz */
static const uint16_t baudtab[] = {
0,
/* Prescale by 6 */
0x19C0, /* 50 */
0x1980, /* 75 */
/* Need 523, which alas is prime so go closest */
/* Prescale by 4 */
0x19C0, /* 110 */
/* Prescale by 3 */
0x0DAE, /* 134.5 */
0x0D80, /* 150 */
0x0D40, /* 300 */
0x0D20, /* 600 */
0x0D10, /* 1200 */
0x0D08, /* 2400 */
0x0D04, /* 4800 */
0x0D02, /* 9600 */
0x0D01, /* 19200 */
0x00, /* 38400 */
/* Prescale by 1 */
0x0501, /* 57600 */
0x00, /* 115200 */
};
#endif

void tty_setup(uint_fast8_t minor, uint_fast8_t flags)
{
minor;
/* Only some parts do parity and only even so don't bother */
register struct termios *t = &ttydata[minor].termios;
register uint16_t baud = t->c_cflag & CBAUD;
if (baudtab[baud] == 0) {
t->c_cflag &= ~CBAUD;
t->c_cflag |= B1200;
baud = B1200;
}
/* Has to be via an asm belper */
/* TODO set_t0(baudtab[baud]); */
}

/* For the moment */
Expand Down Expand Up @@ -57,16 +120,14 @@ 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)
if (z8tty_status() & 0x10)
return TTY_READY_NOW;
else
return TTY_READY_SOON;
}

/* kernel writes to system console -- never sleep! */
void kputchar(unsigned c)
void kputchar(register unsigned c)
{
while(tty_writeready(TTYDEV) != TTY_READY_NOW);
tty_putc(TTYDEV & 0xFF, c);
Expand Down
6 changes: 2 additions & 4 deletions Kernel/platform/platform-rcbus-z8/discard.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ void pagemap_init(void)
{
/* Low 0 is kernel map, high 0 unused except at boot */
/* 0xC3 is the kernel data */
/* pagemap_add(0xC3); */
pagemap_add(0x33);
/* 0x11 Kernel code, 0x33 Kernel data */
pagemap_add(0xC3);
pagemap_add(0xF3);
pagemap_add(0x0F);
pagemap_add(0xCF);
pagemap_add(0x3F);
/* This one weill be picked up by init and must be first to
match crt0.S */
pagemap_add(0xFF);
}

Expand Down
65 changes: 65 additions & 0 deletions Kernel/platform/platform-rcbus-z8/loader.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
;
; We are loaded from the boot block by the firmware and are somewhere
; in the original mapping 0 low, 1 high at E000. Stack is at FExx
; somewhere.
;

.code
.byte 'Z'
.byte 8

start:
;
; Fix up the MMU mappings so we have RAM low as well
;
di ; We are about to map out the irqvecs
ld r14,#0xFF
ld r15,r14
ld r13,#0x11
and 2,#0xBF ; I/O on for upper data space
lde @rr14,r13
or 2,#0x10
; We now have lowest ram bank mapped for all of memory
; Load the code segment
clr r14
clr r15
ld r13,#112 ; load 56K of blocks
call load_data
;
; Now switch the data bank for our new data bank
;
ld r14,#0xFF
ld r15,r14
ld r13,#0x31
and 2,#0xBF
lde @rr14,r13
or 2,#0x10
;
; Now load the data segment
;
clr r14
clr r15
ld r13,#112 ; Will be plenty
call load_data
;
; Switch the maps and call the program
;
ld r14,#0xFF
ld r15,#0xFF
and 2,#0xBF
ld r13,#0x33 ; Set data
lde @rr14,r13
dec r15
ld r13,#0x11 ; Set code
lde @rr14,r13
or 2,#0x10
;
; We now have code mapping of
; 0000-DFFF : code RAM bank 0
; E000-FFFF : loader etc RAM bank 0
; Data mapping of
; 0000-7FFF : data RAM bank 1
; E000-FFFF : data RAM bank 1
;
jmp 6

2 changes: 1 addition & 1 deletion Kernel/platform/platform-rcbus-z8/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ uaddr_t ramtop = PROGTOP;
void plt_idle(void)
{
/* We don't want an idle poll and IRQ driven tty poll at the same moment */
irqflags_t irq = di();
register irqflags_t irq = di();
tty_pollirq();
irqrestore(irq);
}
Expand Down
Loading

0 comments on commit c520836

Please sign in to comment.