Skip to content

Commit ae5874e

Browse files
committed
minim8: A mini11 derived 68HC11 machine
1 parent 1a34add commit ae5874e

File tree

20 files changed

+2601
-0
lines changed

20 files changed

+2601
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
2+
CSRCS = devtty.c
3+
CSRCS += devices.c main.c
4+
5+
ASRCS = m8.S crt0.S sci.S
6+
ASRCS += tricks.S commonmem.S
7+
8+
CDSRCS = discard.c
9+
10+
DSRCS = ../../dev/tinydisk.c ../../dev/tinysd.c
11+
DNSRCS = ../../dev/net/net_w5x00.c
12+
DISCARD_DSRCS = ../../dev/tinydisk_discard.c ../../dev/tinysd_discard.c
13+
14+
COBJS = $(CSRCS:.c=$(BINEXT))
15+
CDOBJS = $(CDSRCS:.c=$(BINEXT))
16+
AOBJS = $(ASRCS:.S=$(BINEXT))
17+
A68OBJS = $(patsubst ../../dev/68hc11/%.S,%.o, $(A68SRCS))
18+
DOBJS = $(patsubst ../../dev/%.c,%.o, $(DSRCS))
19+
DNOBJS = $(patsubst ../../dev/net/%.c,%.o, $(DNSRCS))
20+
DAOBJS = $(DASRCS:.S=$(BINEXT))
21+
DISCARD_DOBJS = $(patsubst ../../dev/%.c,%.o, $(DISCARD_DSRCS))
22+
23+
OBJS = $(COBJS) $(CDOBJS) $(AOBJS) $(A68OBJS) $(DOBJS) $(DAOBJS) $(DISCARD_DOBJS) $(DNOBJS)
24+
25+
CROSS_CCOPTS += -I../../dev/ -I../../dev/68hc11/ -I../../dev/net/
26+
27+
all: $(OBJS)
28+
29+
$(COBJS): %$(BINEXT): %.c
30+
$(CROSS_CC) $(CROSS_CCOPTS) $(CROSS_CC_SEG1) $<
31+
32+
$(CDOBJS): %$(BINEXT): %.c
33+
$(CROSS_CC) $(CROSS_CCOPTS) $(CROSS_CC_SEGDISC) $<
34+
35+
$(AOBJS): %$(BINEXT): %.S
36+
cpp -E $< >$*.s
37+
$(CROSS_AS) $(ASOPTS) $*.s -o $*.o
38+
39+
$(DOBJS): %$(BINEXT): ../../dev/%.c
40+
$(CROSS_CC) $(CROSS_CCOPTS) $(CROSS_CC_SEG1) -c $<
41+
42+
$(DNOBJS): %$(BINEXT): ../../dev/net/%.c
43+
$(CROSS_CC) $(CROSS_CCOPTS) $(CROSS_CC_SEG1) -c $<
44+
45+
$(DAOBJS): %$(BINEXT): ../../dev/%.S
46+
$(CROSS_CC) $(CROSS_CCOPTS) $(CROSS_CC_SEG1) -c $<
47+
48+
$(DISCARD_DOBJS): %$(BINEXT): ../../dev/%.c
49+
$(CROSS_CC) $(CROSS_CCOPTS) $(CROSS_CC_SEGDISC) -c $<
50+
51+
clean:
52+
rm -f $(DOBJS) $(DAOBJS) $(OBJS) *.o *.s core *~ fuzix.bin fuzix.tmpmap
53+
rm -f loadsd.elf loadsd
54+
55+
image: loadsd
56+
$(CROSS_LD) -M -T memory.x -relax -o ../../fuzix.elf crt0.o commonmem.o \
57+
m8.o ../../start.o ../../version.o ../../cpu-68hc11/lowlevel-68hc11-flat.o \
58+
tricks.o main.o discard.o ../../timer.o ../../kdata.o devices.o \
59+
tinydisk.o tinydisk_discard.o tinysd.o tinysd_discard.o \
60+
sci.o ../../syscall_net.o ../../network.o net_w5x00.o \
61+
../../devio.o ../../filesys.o ../../process.o ../../inode.o ../../syscall_fs.o \
62+
../../syscall_proc.o ../../syscall_other.o ../../mm.o ../../swap.o ../../bankfixed.o \
63+
../../tty.o ../../devsys.o ../../syscall_fs2.o ../../syscall_fs3.o \
64+
../../syscall_exec.o ../../syscall_exec16.o ../../blk512.o ../../memalloc_none.o \
65+
../../usermem.o ../../cpu-68hc11/usermem_std-68hc11-flat.o devtty.o >../../fuzix.map
66+
$(CROSS_OBJCOPY) ../../fuzix.elf -O binary ../../fuzix.bin
67+
68+
loadsd: loadsd.S loadsd.x
69+
$(CROSS_CC) -c loadsd.S
70+
$(CROSS_LD) -M -T loadsd.x -relax -o loadsd.elf loadsd.o >loadsd.map
71+
$(CROSS_OBJCOPY) loadsd.elf -O binary loadsd
72+
73+
IMAGES = $(FUZIX_ROOT)/Images/$(TARGET)
74+
75+
diskimage: loadsd
76+
# Make a blank disk image with partition
77+
dd if=$(FUZIX_ROOT)/Standalone/filesystem-src/parttab.40M of=$(IMAGES)/sd.img bs=40017920 conv=sync
78+
# Add the bootstrap loader
79+
dd if=loadsd of=$(IMAGES)/sd.img conv=notrunc
80+
# Add the file system
81+
dd if=$(IMAGES)/filesys.img of=$(IMAGES)/sd.img bs=512 seek=2048 conv=notrunc
82+
# Add the kernel
83+
dd if=../../fuzix.bin of=$(IMAGES)/sd.img bs=512 seek=1 conv=notrunc
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Fuzix for the Mini11/M8 derived from the Mini11
2+
3+
This is a 68HC11, 2K of ROM at F800-FFFF (fixed) and 512K of RAM with a latch
4+
allowing the lower and upper 32K to be banked individually.
5+
6+
The normal setup is an SD card on the SPI and the onboard serial at 9600 baud
7+
with a 7.3728MHz clock.
8+
9+
Memory mapping
10+
11+
Kernel (bank 0)
12+
0x0000-0x00FF Direct page (kernel)
13+
0x0100-0x01FF Loader space for now (can be reclaimed later)
14+
0x0200-0xDFFF Kernel
15+
0xE200-0xEDFF Common
16+
0xEE00-0xEEFF SCI serial buffers (set in m8.S)
17+
0xEF00-0xEFFF Vectors and firmware glue
18+
0xF000-0xF03F Internal I/O (only I/O)
19+
0xF040-0xF1FF Internal common RAM (but only 256 bytes on 68HC11Ax)
20+
0xF200-0xF3FF Gap
21+
0xF400-0xF7FF External I/O (not yet used)
22+
0xF800-0xFFFF ROM / memory latch
23+
24+
In user space
25+
26+
0x0000-0x00FF Direct page (user)
27+
0x0100-0xDDFF User space
28+
0xDE00-0xDFFF Udata stash
29+
0xE000-0xEFFF Common
30+
0xF000-0xF03F Internal I/O
31+
0xF040-0xF1FF Internal RAM (unbankable)
32+
33+
This requires a thunked 68HC11 model. We pack helper data in the common
34+
memory and as we have so little we copy common code into each bank to
35+
have the same effect.
36+
37+
There is a fair bit of space in the kernel and common maps and some holes that
38+
could also be tidied up if needed.
39+
40+
TODO
41+
42+
Would it make sense to compact the DP usage and overlap the udata at
43+
0x0080 in the kernel map with kernel DP at 0x00 ? This would turn a lot
44+
of accesses into DP mode
45+
46+
Optimize fork and other copiers. Several could be a chunk faster with
47+
more self modifying code and also by using the upper/lower split for the bits
48+
that can be accessed via both windows.
49+
50+
Add SPI mux support and WizNet 5500 for internet
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
;
2+
; Common space for stacks and user data
3+
;
4+
; exported symbols
5+
.globl ub
6+
.globl udata
7+
.globl kstack_top
8+
.globl istack_top
9+
.globl istack_switched_sp
10+
11+
.section .data
12+
13+
;
14+
; The stacks are a bit odd. The stack pointer points to the next byte
15+
; that will be written on a push so we want the top to be the last
16+
; byte inclusive, not exclusive as on most processors.
17+
;
18+
; .ds is in words for this assembler ????
19+
;
20+
ub: ; first 512 bytes: starts with struct u_block, with the kernel stack working down from above
21+
udata:
22+
kstack_base:
23+
.ds 255,0
24+
.byte 0
25+
kstack_top:
26+
.byte 0
27+
28+
istack_base:
29+
.ds 126,0
30+
.byte 0
31+
istack_top:
32+
.byte 0
33+
istack_switched_sp: .word 0
34+
35+
;
36+
; We have a tiny writable common area in the internal ram
37+
;
38+
.section .commondata
39+
40+
.globl shared_sp
41+
.globl shared_syscall
42+
.globl shared_map
43+
.globl shared_mlatch
44+
.globl shared_argn
45+
.globl shared_argn1
46+
.globl shared_argn2
47+
.globl shared_argn3
48+
.globl shared_retval
49+
.globl shared_error
50+
.globl shared_signal
51+
.globl shared_sigvec
52+
.globl shared_preempt
53+
.globl int_stack
54+
.globl syscall_stack
55+
.globl sci_stack
56+
57+
shared_sp:
58+
.word 0
59+
shared_syscall:
60+
.byte 0
61+
shared_map:
62+
.byte 0
63+
shared_mlatch:
64+
.byte 0
65+
shared_argn:
66+
.word 0
67+
shared_argn1:
68+
.word 0
69+
shared_argn2:
70+
.word 0
71+
shared_argn3:
72+
.word 0
73+
shared_retval:
74+
.word 0
75+
shared_error:
76+
.word 0
77+
shared_signal:
78+
.byte 0
79+
shared_sigvec:
80+
.word 0
81+
shared_preempt:
82+
.byte 0
83+
.ds 16 ; words
84+
int_stack:
85+
.byte 0
86+
87+
.ds 16
88+
89+
syscall_stack:
90+
.byte 0
91+
92+
.ds 16 ; Stack for serial interrupt
93+
sci_stack:
94+
.byte 0
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/* Enable to make ^Z dump the inode table for debug */
2+
#undef CONFIG_IDUMP
3+
/* Enable to make ^A drop back into the monitor */
4+
#undef CONFIG_MONITOR
5+
/* Profil syscall support (not yet complete) */
6+
#undef CONFIG_PROFIL
7+
/* Acct syscall support */
8+
#undef CONFIG_ACCT
9+
/* Multiple processes in memory at once */
10+
#define CONFIG_MULTI
11+
12+
#define CONFIG_BANK_FIXED
13+
#define MAX_MAPS 7
14+
#define MAP_SIZE 0xE000
15+
#define CONFIG_BANKS 1
16+
17+
/* Permit large I/O requests to bypass cache and go direct to userspace */
18+
#define CONFIG_LARGE_IO_DIRECT(x) 1
19+
20+
/* Arguments are tricky. The 680x binaries stack one way the 68HC11 the other.
21+
We deal with that in the syscall stubs and in crt0 */
22+
#define CONFIG_CALL_R2L
23+
24+
#define TICKSPERSEC 10 /* Ticks per second */
25+
26+
#define MAPBASE 0x0000 /* We map from 0 */
27+
#define PROGBASE 0x0000 /* also data base */
28+
#define PROGLOAD 0x0100
29+
#define PROGTOP 0xDE00 /* udata stash at DE-DF */
30+
31+
#define SWAPDEV (swap_dev) /* A variable for dynamic, or a device major/minor */
32+
extern uint16_t swap_dev;
33+
/* We swap a range including the internal I/O window. This is safe because we
34+
map the memory into the swap window not directly */
35+
#define SWAP_SIZE 0x70 /* 56K in blocks (prog + udata) */
36+
#define SWAPBASE 0x0000 /* start at the base of user mem */
37+
#define SWAPTOP 0xE000 /* Swap out udata and program */
38+
#define MAX_SWAPS 16 /* We will size if from the partition */
39+
/* Swap will be set up when a suitably labelled partition is seen */
40+
#define CONFIG_DYNAMIC_SWAP
41+
/*
42+
* When the kernel swaps something it needs to map the right page into
43+
* memory using map_for_swap and then turn the user address into a
44+
* physical address. We use the second 16K window.
45+
*/
46+
#define swap_map(x) ((uint8_t *)(x))
47+
48+
#define CONFIG_TD_NUM 1
49+
#define CONFIG_TD_SD
50+
#define TD_SD_NUM 1
51+
52+
#define BOOT_TTY 513 /* Set this to default device for stdio, stderr */
53+
54+
/* We need a tidier way to do this from the loader */
55+
#define CMDLINE NULL /* Location of root dev name */
56+
57+
/* Device parameters */
58+
#define NUM_DEV_TTY 1
59+
#define TTYDEV BOOT_TTY /* Device used by kernel for messages, panics */
60+
#define NBUFS 5 /* Number of block buffers */
61+
#define NMOUNTS 2 /* Number of mounts at a time */
62+
63+
#define CONFIG_NET
64+
#define CONFIG_NET_WIZNET
65+
#define CONFIG_NET_W5500
66+
67+
#define plt_discard()
68+
#define plt_copyright()
69+
70+
#define BOOTDEVICENAMES "hd#"
71+
72+
/* 68HC11 specific stuff */
73+
#define IOBASE 0xF000
74+
75+
#define DP_BASE 0x0000
76+
#define DP_SIZE 0x00C0 /* C0-FF is for the kernel */
77+
78+
#define TTY_INIT_BAUD B9600
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
;
2+
; So we end up first in the image
3+
;
4+
5+
.section .text
6+
7+
entry:
8+
sei ; interrupts off
9+
lds #kstack_top ; C stack
10+
11+
; Clear the udata (probably not needed as we did the move
12+
ldx #udata
13+
wipeud:
14+
clr 0,x
15+
inx
16+
cpx #istack_switched_sp
17+
bne wipeud
18+
19+
ldx #__bss_start
20+
ldd #__bss_size
21+
bss_wipe: clr ,x
22+
inx
23+
subd #1
24+
bne bss_wipe
25+
26+
gogogo:
27+
jsr init_early
28+
jsr init_hardware
29+
jsr fuzix_main ; Should never return
30+
sei ; Spin
31+
stop: jmp stop
32+
33+
34+
;
35+
; Force our custom sections to be allocated so they appear in the
36+
; final binary. That was fun to find....
37+
;
38+
.section .discard,"a"
39+
.section .common,"a"
40+
.section .commondata,"a"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <kernel.h>
2+
#include <version.h>
3+
#include <kdata.h>
4+
#include <devsys.h>
5+
#include <tinydisk.h>
6+
#include <tty.h>
7+
#include <devtty.h>
8+
9+
struct devsw dev_tab[] = /* The device driver switch table */
10+
{
11+
// minor open close read write ioctl
12+
// -----------------------------------------------------------------
13+
/* 0: /dev/hd - block device interface */
14+
{ td_open, no_close, td_read, td_write, td_ioctl},
15+
/* 1: /dev/fd - Floppy disk block devices */
16+
{ no_open, no_close, no_rdwr, no_rdwr, no_ioctl},
17+
/* 2: /dev/tty TTY devices */
18+
{ tty_open, tty_close, tty_read, tty_write, tty_ioctl },
19+
/* 3: /dev/lpr Printer devices */
20+
{ no_open, no_close, no_rdwr, no_rdwr, no_ioctl },
21+
/* 4: /dev/mem etc System devices (one offs) */
22+
{ no_open, no_close, sys_read, sys_write, sys_ioctl },
23+
/* Pack to 7 with nxio if adding private devices and start at 8 */
24+
};
25+
26+
bool validdev(uint16_t dev)
27+
{
28+
/* This is a bit uglier than needed but the right hand side is
29+
a constant this way */
30+
if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1)
31+
return false;
32+
else
33+
return true;
34+
}
35+

0 commit comments

Comments
 (0)