Skip to content

Commit

Permalink
p90mb: get actually booting
Browse files Browse the repository at this point in the history
  • Loading branch information
EtchedPixels committed Mar 4, 2024
1 parent 873f085 commit f77b725
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 34 deletions.
9 changes: 4 additions & 5 deletions Kernel/platform/platform-p90mb/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ image:
68000usercopy.o ../../cpu-68000/usermem_std-68000.o devtty.o libc.o ../../malloc.o \
../../level2.o ../../syscall_level2.o ../../select.o > ../../fuzix.map
$(CROSS_COMPILE)objcopy fuzix.elf -O binary ../../fuzix.bin

$(CROSS_CC) -c loader.S
$(CROSS_LD) -M -o loader.elf -T loader.ld loader.o >loader.map
$(CROSS_COMPILE)objcopy loader.elf -O binary loader.bin
Expand All @@ -57,12 +56,12 @@ IMAGES = $(FUZIX_ROOT)/Images/$(TARGET)

diskimage:
# Make a blank disk image with partition
dd if=$(FUZIX_ROOT)/Standalone/filesystem-src/parttab.40M of=$(IMAGES)/disk.img bs=40017920 conv=sync,swab
dd if=$(FUZIX_ROOT)/Standalone/filesystem-src/parttab.40M of=$(IMAGES)/disk.img bs=40017920 conv=sync
# Add the bootstrap loader
dd if=loader.bin of=$(IMAGES)/disk.img bs=512 seek=1 conv=notrunc,swab
dd if=loader.bin of=$(IMAGES)/disk.img bs=512 conv=notrunc
# Add the file system
dd if=$(IMAGES)/filesys.img of=$(IMAGES)/disk.img bs=512 seek=2048 conv=notrunc,swab
dd if=$(IMAGES)/filesys.img of=$(IMAGES)/disk.img bs=512 seek=2048 conv=notrunc
# Add the kernel
dd if=../../fuzix.bin of=$(IMAGES)/disk.img bs=512 seek=2 conv=notrunc,swab
dd if=../../fuzix.bin of=$(IMAGES)/disk.img bs=512 seek=1 conv=notrunc
# Make an emulator image of it
cat $(FUZIX_ROOT)/Standalone/filesystem-src/idehdr.40M $(IMAGES)/disk.img > $(IMAGES)/emu-ide.img
8 changes: 4 additions & 4 deletions Kernel/platform/platform-p90mb/README
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Fuzix test for the P90MB

This assumes the 'RetroDOS' ROM is being used for now

TODO
- Loader
- Serial baud rate setting
- I2C
- UART 2 stop bits via mode 3 ?
- Interrupt testing (emulator doesn't yet handle interrupts)
- I2C
- External devices ?
- Watchdog

Longer Term
- Play with soft control of upper address bits and buddy allocator

4 changes: 0 additions & 4 deletions Kernel/platform/platform-p90mb/crt0.S
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
.globl __bss_start

.mri 1
byte $15
byte $05
byte $C0
byte $DE
start:
or #$0700,sr
move.l #__bss_start,a0
Expand Down
38 changes: 31 additions & 7 deletions Kernel/platform/platform-p90mb/devtty.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static uint8_t sleeping;

tcflag_t termios_mask[NUM_DEV_TTY + 1] = {
0,
_CSYS|CBAUD,
_CSYS|CBAUD|PARENB|PARODD|CMSPAR,
};

static volatile uint8_t *uart_base = (volatile uint8_t *)0x80000000;
Expand Down Expand Up @@ -49,15 +49,39 @@ ttyready_t tty_writeready(uint8_t minor)

void tty_putc(uint8_t minor, unsigned char c)
{
PUTB(SBUF, c);
PUTB(SBUF, tty_add_parity(minor, c));
}

static uint16_t baud_div[] = {
78, /* B0: off */
14976, /* 50 */
9984, /* 75 */
6807, /* 110 */
5567, /* 134.5 */
2496, /* 300 */
1248, /* 600 */
624, /* 1200 */
312, /* 2400 */
156, /* 4800 */
78, /* 9600 */
39, /* 19200 */
19, /* 38400 - a bit off (39410) */
13, /* 57600 */
0 /* 115200 */
};

void tty_setup(uint8_t minor, uint8_t flags)
{
/* Set up baud rate timer */
*(volatile uint16_t *)0x8002052 = 0xFFF3;
*(volatile uint8_t *)0x8002055 = 0x34;
/* FFD9 is 19200, FFB2 is 9600 etc */
struct termios *t = &ttydata[minor].termios;
uint8_t baud = t->c_cflag & CBAUD;

if (baud == B115200) {
baud = B57600;
t->c_cflag &= ~CBAUD;
t->c_cflag |= baud;
}
*(volatile uint16_t *)0x8002052 = -baud_div[baud];
/* TODO: we can in theory do two stop bits by abusing mode 3 */
}

/* Not wired on this board */
Expand All @@ -83,7 +107,7 @@ void tty_interrupt(void)
r = GETB(SBUF);
/* Clear received bit by hand - ugly */
PUTB(SCON, GETB(SCON) & 0xFE);
tty_inproc(1,r);
tty_inproc_softparity(1,r);
}
/* Ugly - need to move to full IRQ serial I think ? */
if (r & 0x02)
Expand Down
49 changes: 49 additions & 0 deletions Kernel/platform/platform-p90mb/loader.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* We are loaded somewhere out of the memory window and run
* Our stack is a C call stack of the form
*
* bootloader(uint8_t bootdev, uint8_t *base, uint32_t len, syscallvec)
*
* Needs to bne relocatable.
*/
.globl start
.globl loader

.mri 1

/* We load the binary into the memory space RetroDOS provided. We will then
relocate it once we are ready to dump RetroDOS overboard */

ascii "RETRODOSBOOT68"
loader:
lea.l syscb(pc),a0
move.l 4(sp),4(a0) ; drive
move.l 8(sp),8(a0) ; load address

move.l 16(sp),a4 ; syscall vector

move.l a0,-(sp)
jsr (a4) ; C call into disk loader
addq #4,sp

/* Now dump RetroDOS and run it. This assumes we move the image down which
happens to be a safe bet but we ought to check and do either direction */

move.l 8(sp),a0
move.l #$0400,a1
move.w #$3FFF,d0 ; 64K

copy:
move.l (a0)+,(a1)+
dbra d0,copy

jmp $0400

syscb:
long $F1 ; raw read
cbdrive:
long 0 ; drive
cbaddr:
long 0 ; buffer
long 1 ; LBA
long 128 ; length (64K for now)
86 changes: 86 additions & 0 deletions Kernel/platform/platform-p90mb/loader.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
OUTPUT_ARCH(m68k)

SEARCH_DIR(.)

MEMORY
{
ram (rwx) : ORIGIN = 0x15000, LENGTH = 0x200
}

/*
* stick everything in ram (of course)
*/
SECTIONS
{
.text :
{
CREATE_OBJECT_SYMBOLS
*(.text .text.*)

. = ALIGN(0x4);
/* These are for running static constructors and destructors under ELF. */
KEEP (*crtbegin.o(.ctors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))

*(.rodata .rodata.*)

. = ALIGN(0x4);
*(.gcc_except_table)

. = ALIGN(0x4);
*(.eh_frame)

. = ALIGN(0x4);
__INIT_SECTION__ = . ;
LONG (0x4e560000) /* linkw %fp,#0 */
*(.init)
SHORT (0x4e5e) /* unlk %fp */
SHORT (0x4e75) /* rts */

. = ALIGN(0x4);
__FINI_SECTION__ = . ;
LONG (0x4e560000) /* linkw %fp,#0 */
*(.fini)
SHORT (0x4e5e) /* unlk %fp */
SHORT (0x4e75) /* rts */

. = ALIGN(0x4);
_etext = .;
*(.lit)
} > ram

.data :
{
*(.got.plt) *(.got)
*(.shdata)
*(.data .data.*)
_edata = .;
} > ram

.bss :
{
. = ALIGN(0x4);
__bss_start = . ;
*(.shbss)
*(.bss .bss.*)
*(COMMON)
_end = ALIGN (0x8);
__end = _end;
} > ram

.stab 0 (NOLOAD) :
{
*(.stab)
}

.stabstr 0 (NOLOAD) :
{
*(.stabstr)
}
}
11 changes: 8 additions & 3 deletions Kernel/platform/platform-p90mb/p68000.S
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define RCAPH0 $80002032
#define T0CON $80002035
#define T0IR $80002037
#define URIR $80002025

#define T100HZ $E525

Expand Down Expand Up @@ -37,6 +38,7 @@ init_early:

plt_idle:
stop #($2000+EI_MASK)
; jsr tty_interrupt
rts
;
; FIXME: could be in discard if we wanted
Expand All @@ -56,14 +58,17 @@ init_hardware:

move.w #T100HZ,RCAPH0 ; 100Hz tick
move.b #4,T0CON
move.b #3,T0IR ; Interrupt autovector 3
move.b #3,T0IR ; Interrupt autovector 3 (timer)

move.b #4,URIR ; Interrupt autovector 4 (rx)
rts

timer_irq:
; C will save and restore a2+/d2+
movem.l a0-a1/a5/d0-d1,-(sp)
move.l udata_shadow,a5 ; set up the register global
move.b #1,U_DATA__U_ININTERRUPT(a5)
bclr.b #7,T0CON
jsr plt_interrupt
clr.b U_DATA__U_ININTERRUPT(a5)

Expand Down Expand Up @@ -143,7 +148,7 @@ outcharw:
;
devide_read_data:
move.l blk_op,a0
move.l #$12000000,a1
move.l #$01200000,a1
move.w #255,d0
devide_read_l:
move.b (a1),(a0)+
Expand All @@ -153,7 +158,7 @@ devide_read_l:

devide_write_data:
move.l blk_op,a0
move.l #$12000000,a1
move.l #$01200000,a1
move.w #255,d0
devide_write_l:
move.b (a0)+,(a1)
Expand Down
22 changes: 11 additions & 11 deletions Kernel/platform/platform-p90mb/platform_ide.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#define IDE_IS_MMIO 1 /* MMIO IDE */

#define IDE_REG_DATA 0x12000000
#define IDE_REG_ERROR 0x12000001
#define IDE_REG_FEATURES 0x12000001
#define IDE_REG_SEC_COUNT 0x12000002
#define IDE_REG_LBA_0 0x12000003
#define IDE_REG_LBA_1 0x12000004
#define IDE_REG_LBA_2 0x12000005
#define IDE_REG_LBA_3 0x12000006
#define IDE_REG_DEVHEAD 0x12000006
#define IDE_REG_STATUS 0x12000007
#define IDE_REG_COMMAND 0x12000007
#define IDE_REG_DATA 0x01200000
#define IDE_REG_ERROR 0x01200001
#define IDE_REG_FEATURES 0x01200001
#define IDE_REG_SEC_COUNT 0x01200002
#define IDE_REG_LBA_0 0x01200003
#define IDE_REG_LBA_1 0x01200004
#define IDE_REG_LBA_2 0x01200005
#define IDE_REG_LBA_3 0x01200006
#define IDE_REG_DEVHEAD 0x01200006
#define IDE_REG_STATUS 0x01200007
#define IDE_REG_COMMAND 0x01200007

/* FIXME: Check altstatus/control mapping */

Expand Down

0 comments on commit f77b725

Please sign in to comment.