Skip to content

Commit 49513f9

Browse files
authored
Merge pull request #1156 from DoctorWkt/platform-rosco-r2
Kernel/platform/platform-rosco-r2: A port of FUZIX to the Rosco r2 m68k SBC.
2 parents 6c5fbd7 + 720a7d1 commit 49513f9

19 files changed

+1709
-0
lines changed
+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
2+
CSRCS = devtty.c
3+
CSRCS += devices.c main.c libc.c
4+
CSRCS += devch375.c devch375_discard.c
5+
6+
ASRCS = p68000.S crt0.S
7+
ASRCS += tricks.S
8+
9+
DSRCS = ../../dev/mbr.c ../../dev/blkdev.c
10+
DSRCS += ../../dev/devsd.c ../../dev/devsd_discard.c
11+
DOBJS = $(patsubst ../../dev/%.c,%.o, $(DSRCS))
12+
13+
LSRCS = ../../lib/68000exception.c ../../lib/68000usercopy.c
14+
LSRCS += ../../lib/68000relocate.c
15+
LOBJS = $(patsubst ../../lib/%.c,%.o, $(LSRCS))
16+
17+
COBJS = $(CSRCS:.c=$(BINEXT))
18+
AOBJS = $(ASRCS:.S=.o)
19+
OBJS = $(COBJS) $(AOBJS) $(DOBJS) $(LOBJS)
20+
21+
CROSS_CCOPTS += -I../../dev/
22+
23+
all: $(OBJS)
24+
25+
$(COBJS): %.o: %.c
26+
$(CROSS_CC) $(CROSS_CCOPTS) -c $<
27+
28+
$(AOBJS): %.o: %.S
29+
$(CROSS_AS) $(ASOPTS) $< -o $*.o
30+
31+
$(DOBJS): %.o: ../../dev/%.c
32+
$(CROSS_CC) $(CROSS_CCOPTS) -c $<
33+
34+
$(LOBJS): %.o: ../../lib/%.c
35+
$(CROSS_CC) $(CROSS_CCOPTS) -c $<
36+
37+
tricks.S: ../../lib/68000flat.S
38+
39+
clean:
40+
rm -f *.o fuzix.elf core *~ fuzix.dis
41+
42+
image:
43+
$(CROSS_LD) -M -o fuzix.elf -T fuzix.ld p68000.o ../../start.o \
44+
../../version.o ../../cpu-68000/lowlevel-68000.o tricks.o \
45+
main.o ../../timer.o ../../kdata.o 68000exception.o \
46+
devices.o ../../devio.o ../../filesys.o ../../process.o \
47+
../../inode.o ../../syscall_fs.o ../../syscall_proc.o \
48+
../../syscall_other.o ../../mm.o ../../flat.o ../../blk512.o \
49+
../../tty.o ../../devsys.o ../../usermem.o ../../syscall_fs2.o \
50+
../../syscall_fs3.o ../../syscall_exec32.o ../../syscall_exec.o \
51+
blkdev.o mbr.o 68000relocate.o \
52+
devsd.o devsd_discard.o \
53+
devch375.o devch375_discard.o \
54+
68000usercopy.o ../../cpu-68000/usermem_std-68000.o devtty.o \
55+
libc.o ../../malloc.o ../../level2.o ../../syscall_level2.o \
56+
../../select.o > ../../fuzix.map
57+
$(CROSS_COMPILE)objcopy fuzix.elf -O binary ../../fuzix.bin
58+
m68k-elf-objdump --disassemble -S fuzix.elf > fuzix.dis
59+
60+
IMAGES = $(FUZIX_ROOT)/Images/$(TARGET)
61+
62+
diskimage:
63+
# Make a blank disk image with partition
64+
dd if=$(FUZIX_ROOT)/Standalone/filesystem-src/parttab.40M of=$(IMAGES)/disk.img bs=40017920 conv=sync,swab
65+
# Add the file system
66+
dd if=$(IMAGES)/filesys.img of=$(IMAGES)/disk.img bs=512 seek=2048 conv=notrunc,swab
67+
# Add the kernel
68+
dd if=../../fuzix.bin of=$(IMAGES)/disk.img bs=512 seek=2 conv=notrunc,swab
69+
# Make an emulator image of it
70+
cat $(FUZIX_ROOT)/Standalone/filesystem-src/idehdr.40M $(IMAGES)/disk.img > $(IMAGES)/emu-ide.img
+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# FUZIX Port to the Rosco r2 SBC
2+
3+
Warren Toomey - 2025/02/05
4+
5+
## Introduction
6+
7+
This is the port of FUZIX to the Rosco r2 m68k SBC:
8+
https://github.com/rosco-m68k/rosco_m68k
9+
10+
It's a work in progress and some things don't work well yet.
11+
12+
## Building FUZIX
13+
14+
You will need the toolchain described in
15+
https://github.com/rosco-m68k/rosco_m68k/blob/develop/code/Toolchain.md
16+
17+
At the top-level FUZIX directory, you can do:
18+
19+
```
20+
make TARGET=rosco-r2 kernel # Build the kernel, which creates
21+
# the file Kernel/fuzix.bin
22+
make TARGET=rosco-r2 diskimage # Builds the libraries and applications,
23+
# and then creates the filesystem image
24+
# Images/rosco-r2/filesys.img
25+
make TARGET=rosco-r2 kclean # Clean up the kernel build. Do this if
26+
# you make any kernel config changes
27+
make TARGET=rosco-r2 clean # Clean up everything
28+
```
29+
30+
There is a shell script here called `mk_fs_img`. Once you have
31+
`Kernel/fuzix.bin` and `Images/rosco-r2/filesys.img` you can run
32+
this script to make the SD card image `sdcard.img` which has the
33+
bootable kernel in partition 1 and the populated FUZIX filesystem
34+
in partition 2.
35+
36+
## Booting with an SD Card
37+
38+
Copy the card image `sdcard.img` to your SD card. Under Linux I do:
39+
40+
```
41+
cat sdcard.img > /dev/sdc; sync; sync
42+
```
43+
44+
At boot time, the SD card should appear as `hda` with two partitions.
45+
Use the boot device `hda2` and login as `root` with no password:
46+
47+
```
48+
FUZIX version 0.5
49+
Copyright (c) 1988-2002 by H.F.Bower, D.Braun, S.Nitschke, H.Peraza
50+
Copyright (c) 1997-2001 by Arcady Schekochikhin, Adriano C. R. da Cunha
51+
Copyright (c) 2013-2015 Will Sowerbutts <will@sowerbutts.com>
52+
Copyright (c) 2014-2025 Alan Cox <alan@etchedpixels.co.uk>
53+
Devboot
54+
Motorola 68010 processor detected.
55+
1024KiB total RAM, 917KiB available to processes (125 processes max)
56+
Enabling interrupts ... ok.
57+
SD drive 0: hda: hda1 hda2
58+
CH375 device: not found
59+
bootdev: hda2
60+
...
61+
login: root
62+
```
63+
64+
## Booting with the CH375 Device and a USB Drive
65+
66+
If you have built the CH375 daughter board as described
67+
[here](https://github.com/DoctorWkt/xv6-rosco-r2/tree/ch375/hardware)
68+
then you can copy the FUZIX filesystem to a USB drive and mount it
69+
as the root device.
70+
71+
However, as the Rosco r2 SBC boots from the SD card, you need to copy
72+
the SD card image `sdcard.img` to both your SD card and your USB drive.
73+
74+
At boot time, the SD card should appear as `hdb` with two partitions.
75+
Use the boot device `hdb2` and login as `root` with no password.
76+
77+
If you have installed 1M of expansion RAM on the daughter board and closed
78+
jumper JP4, then the kernel will see the extra RAM and report that you have
79+
2M of RAM.
80+
81+
```
82+
FUZIX version 0.5
83+
Copyright (c) 1988-2002 by H.F.Bower, D.Braun, S.Nitschke, H.Peraza
84+
Copyright (c) 1997-2001 by Arcady Schekochikhin, Adriano C. R. da Cunha
85+
Copyright (c) 2013-2015 Will Sowerbutts <will@sowerbutts.com>
86+
Copyright (c) 2014-2025 Alan Cox <alan@etchedpixels.co.uk>
87+
Devboot
88+
Motorola 68010 processor detected.
89+
2048KiB total RAM, 1941KiB available to processes (125 processes max)
90+
Enabling interrupts ... ok.
91+
SD drive 0: hda: hda1 hda2
92+
CH375 device: hdb: hdb1 hdb2
93+
bootdev: hdb2
94+
...
95+
login: root
96+
```
97+
98+
## Configuration
99+
100+
Look in `config.h` for compile-time configuration defines.
101+
`TTY_INIT_BAUD` is set for 115200 baud. `CONFIG_FLAT` means we have no MMU.
102+
`CONFIG_SD` and `SD_DRIVE_COUNT` sets us up for one SD card.
103+
`CONFIG_USB` supports my USB expansion board:
104+
https://github.com/DoctorWkt/xv6-rosco-r2/tree/ch375/hardware
105+
106+
This line in `fuzix.ld`:
107+
108+
```
109+
ram (rwx) : ORIGIN = 0x2000, LENGTH = 0x100000-0x2000
110+
```
111+
112+
says that the kernel starts at $2000 and we have $100000 (1 Meg) of RAM.
113+
114+
## Booting
115+
116+
The Rosco ROM loads the kernel at address $40000. The code in `crt0.S`
117+
copies the kernel down to $2000. Then, interrupts are enabled and the
118+
BSS gets cleared. These functions are then called: `init_early()`,
119+
`init_hardware()` and `fuzix_main()`.
120+
121+
## Devices
122+
123+
`devices.c` holds a tables of devices and associated functions. The
124+
main ones are the block devices (0) and the tty device (2).
125+
`device_init()` is called to probe devices and initialise them.
126+
127+
## The DUART
128+
129+
The code to use the XR68C681 DUART is in `devtty.c`. I have made the
130+
`tty_setup()` function do essentially nothing. The Rosco ROM sets the
131+
DUART up for 115200 baud. The Fuzix code then does something which
132+
scrambles the 115200 baud setting. Until I can figure it out, I've
133+
just disabled it.
134+
135+
## The SD Card
136+
137+
The kernel is configured to have SD card support. The file `p68000.S` has
138+
assembly functions to bit-bang the SD card using the DUART:
139+
140+
```
141+
.globl sd_spi_clock
142+
.globl sd_spi_raise_cs
143+
.globl sd_spi_lower_cs
144+
.globl sd_spi_transmit_byte
145+
.globl sd_spi_receive_byte
146+
.globl sd_spi_transmit_sector
147+
.globl sd_spi_receive_sector
148+
```
149+
150+
and the high-level SD card code is in `Kernel/dev/devsd.c` and
151+
`Kernel/dev/devsd_discard.c`.
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
8+
#define CONFIG_32BIT
9+
#define CONFIG_LEVEL_2
10+
11+
#define CONFIG_MULTI
12+
#define CONFIG_FLAT
13+
#define CONFIG_SPLIT_ID
14+
#define CONFIG_PARENT_FIRST
15+
/* It's not that meaningful but we currently chunk to 512 bytes */
16+
#define CONFIG_BANKS (65536/512)
17+
18+
#define CONFIG_LARGE_IO_DIRECT(x) 1
19+
20+
#define CONFIG_SPLIT_UDATA
21+
#define UDATA_SIZE 1024
22+
#define UDATA_BLKS 2
23+
24+
#define TICKSPERSEC 100 /* Ticks per second */
25+
26+
#define BOOT_TTY (512 + 1) /* Set this to default device for stdio, stderr */
27+
/* In this case, the default is the first TTY device */
28+
/* Temp FIXME set to serial port for debug ease */
29+
30+
/* We need a tidier way to do this from the loader */
31+
#define CMDLINE NULL /* Location of root dev name */
32+
33+
/* Device parameters */
34+
#define NUM_DEV_TTY 2
35+
#define TTYDEV BOOT_TTY /* Device used by kernel for messages, panics */
36+
37+
/* Could be bigger but we need to add hashing first and it's not clearly
38+
a win with a CF card anyway */
39+
#define NBUFS 16 /* Number of block buffers */
40+
#define NMOUNTS 8 /* Number of mounts at a time */
41+
42+
#define MAX_BLKDEV 2
43+
44+
/* Block dvices */
45+
#define CONFIG_IDE
46+
#define CONFIG_SD
47+
#define SD_DRIVE_COUNT 1
48+
#define CONFIG_CH375
49+
50+
#define plt_copyright()
51+
52+
/* Note: select() in the level 2 code will not work on this configuration
53+
at the moment as select is limited to 16 processes. FIXME - support a
54+
hash ELKS style for bigger systems where wakeup aliasing is cheaper */
55+
56+
#define PTABSIZE 125
57+
#define UFTSIZE 16
58+
#define OFTSIZE 160
59+
#define ITABSIZE 176
60+
61+
#define BOOTDEVICENAMES "hd#"
62+
63+
#define TTY_INIT_BAUD B115200
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Need to wipe BSS etc once we figure out our preferred boot method
3+
*
4+
* On entry we are loaded at $40000. We copy ourselves down to $400.
5+
* We are in supervisor mode and the rest is our problem.
6+
*/
7+
#include "../../cpu-68000/kernel-68000.def"
8+
9+
.globl start
10+
.globl start2
11+
.globl __end
12+
.globl __bss_start
13+
14+
.mri 1
15+
16+
start:
17+
/* Position-independent code to copy from start to
18+
* __bss_start down to $400. Code borrowed from the
19+
* Rosco loader code.
20+
*/
21+
RELOC: /* position-independent load addr */
22+
lea.l RELOC(PC),A0 /* PC-rel source addr (load addr) */
23+
move.l #start,A1 /* absolute dest addr (run addr) */
24+
move.l #__bss_start,D0 /* init section absolute end addr */
25+
sub.l A1,D0 /* subtract dest addr for init length */
26+
lsr.l #2,D0 /* convert to long words */
27+
subq.l #1,D0 /* subtract 1 for dbra */
28+
.INIT_LOOP:
29+
move.l (A0)+,(A1)+ /* copy long word from source to dest */
30+
dbra D0,.INIT_LOOP /* loop until __bss_start */
31+
32+
move.l #start2,A0 /* Use A0, otherwise the generated code */
33+
/* is PC-relative which we don't want. */
34+
jmp (A0) /* Jump to the copied start2 code */
35+
36+
start2:
37+
or #$0700,sr
38+
move.l #__bss_start,a0
39+
move.l #__end,d0
40+
sub.l a0,d0
41+
lsr.l #2,d0
42+
wipebss:
43+
clr.l (a0)+
44+
dbra d0,wipebss
45+
46+
lea udata_block0+UBLOCK_SIZE,a7
47+
bsr init_early
48+
bsr init_hardware
49+
bsr fuzix_main
50+
or #$0700,sr
51+
stop: bra stop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*-----------------------------------------------------------------------*/
2+
/* Fuzix CH375 USB block device driver */
3+
/* 2025 Warren Toomey */
4+
/* */
5+
/* This one is different from the one in Kernel/dev as it assumes that */
6+
/* the CH375 device will send interrupts. */
7+
/*-----------------------------------------------------------------------*/
8+
9+
#include <kernel.h>
10+
#include <kdata.h>
11+
#include <printf.h>
12+
#include <timer.h>
13+
#include <stdbool.h>
14+
#include <blkdev.h>
15+
#include <devch375.h>
16+
17+
#ifdef CONFIG_CH375
18+
19+
extern uint32_t ch375_read_block(uint8_t *buf, uint32_t lba);
20+
extern uint32_t ch375_write_block(uint8_t *buf, uint32_t lba);
21+
22+
uint_fast8_t devch375_transfer_sector(void)
23+
{
24+
bool success;
25+
uint32_t lba= blk_op.lba;
26+
27+
/* Disable interrupts while we do the transfer */
28+
/* but keep IRQ5 enabled as we use it */
29+
irqflags_t irq = di();
30+
irqrestore(4); /* IRQ4 is ignored, 5 is OK */
31+
32+
if (blk_op.is_read) {
33+
success= ch375_read_block(blk_op.addr, lba);
34+
} else {
35+
success= ch375_write_block(blk_op.addr, lba);
36+
}
37+
irqrestore(irq);
38+
return(success);
39+
}
40+
41+
#endif

0 commit comments

Comments
 (0)