Skip to content

Commit

Permalink
sbcv2: begin conversion
Browse files Browse the repository at this point in the history
Work in progress
  • Loading branch information
EtchedPixels committed Oct 28, 2023
1 parent c3af69a commit 6c10dea
Show file tree
Hide file tree
Showing 16 changed files with 1,743 additions and 576 deletions.
44 changes: 22 additions & 22 deletions Kernel/platform/platform-sbcv2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,52 @@ CSRCS += devices.c main.c wiznet.c

DISCSRCS = discard.c

ASRCS = sbcv2.s crt0.s
ASRCS += tricks.s commonmem.s
ASRCS = sbcv2.S crt0.S
ASRCS += tricks.S commonmem.S

DISCARD_DSRCS = ../../dev/tinydisk_discard.c ../../dev/tinyide_discard.c
DISCARD_DSRCS += ../../dev/ds1302_discard.c
DSRCS = ../../dev/tinydisk.c ../../dev/tinyide.c ../../dev/mbr.c
DSRCS += ../../dev/propio2.c ../../dev/ds1302.c
DSRCS += ../../dev/devfd.c ../../dev/tinyide_ppide_rbc.c
DSRCS += ../../dev/devfd.c
NSRCS = ../../dev/net/net_w5x00.c ../../dev/net/net_native.c

DASRCS = ../../dev/rbcfd9266_hw.s ../../dev/ds1302_rbc.s
DASRCS = ../../dev/rbcfd9266_hw.S ../../dev/ds1302_rbc.S ../../dev/tinyide_ppide_rbc.S

COBJS = $(CSRCS:.c=.rel)
AOBJS = $(ASRCS:.s=.rel)
NOBJS = $(patsubst ../../dev/net/%.c,%.rel, $(NSRCS))
DISCOBJS = $(DISCSRCS:.c=.rel)
DISCARD_DOBJS = $(patsubst ../../dev/%.c,%.rel, $(DISCARD_DSRCS))
DOBJS = $(patsubst ../../dev/%.c,%.rel, $(DSRCS))
DAOBJS = $(patsubst ../../dev/%.s,%.rel, $(DASRCS))
COBJS = $(CSRCS:.c=.o)
AOBJS = $(ASRCS:.S=.o)
NOBJS = $(patsubst ../../dev/net/%.c,%.o, $(NSRCS))
DISCOBJS = $(DISCSRCS:.c=.o)
DISCARD_DOBJS = $(patsubst ../../dev/%.c,%.o, $(DISCARD_DSRCS))
DOBJS = $(patsubst ../../dev/%.c,%.o, $(DSRCS))
DAOBJS = $(patsubst ../../dev/%.S,%.o, $(DASRCS))

OBJS = $(COBJS) $(AOBJS) $(NOBJS) $(DISCOBJS) $(DOBJS) $(DISCARD_DOBJS) $(DAOBJS)

JUNK = *.lst *.asm *.sym *.rst *.lst
JUNK = *.lst *.asm *.Sym *.rst *.lst

all: $(OBJS)

$(COBJS): %.rel: %.c
$(COBJS): %.o: %.c
$(CROSS_CC) $(CROSS_CCOPTS) -c $<

$(DISCOBJS): %.rel: %.c
$(DISCOBJS): %.o: %.c
$(CROSS_CC) $(CROSS_CCOPTS) $(CROSS_CC_SEGDISC) -c $<

$(DOBJS): %.rel: ../../dev/%.c
$(DOBJS): %.o: ../../dev/%.c
$(CROSS_CC) $(CROSS_CCOPTS) -c $<

$(DISCARD_DOBJS): %.rel: ../../dev/%.c
$(DISCARD_DOBJS): %.o: ../../dev/%.c
$(CROSS_CC) $(CROSS_CCOPTS) $(CROSS_CC_SEGDISC) -c $<

$(NOBJS): %.rel: ../../dev/net/%.c
$(NOBJS): %.o: ../../dev/net/%.c
$(CROSS_CC) $(CROSS_CCOPTS) -c $<

$(AOBJS): %.rel: %.s
$(AOBJS): %.o: %.S
$(CROSS_AS) $(ASOPTS) $<

$(DAOBJS): %.rel: ../../dev/%.s
$(CROSS_AS) $(ASOPTS) $@ $<
$(DAOBJS): %.o: ../../dev/%.S
$(CROSS_AS) $(ASOPTS) $<

clean:
rm -f $(OBJS) $(JUNK) core *~
Expand All @@ -65,8 +65,8 @@ image: bootblock
# Compile up the boot block
#
bootblock:
sdasz80 -o boot-romwbw.s
sdldz80 -i boot-romwbw.rel
sdasz80 -o boot-romwbw.S
sdldz80 -i boot-romwbw.o
# This makes us a binary from physical 0
makebin -s 62464 boot-romwbw.ihx boot-romwbw.tmp
# Chop off the leading 61440 bytes we don't want
Expand Down
9 changes: 9 additions & 0 deletions Kernel/platform/platform-sbcv2/commonmem.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
;
; The common memory area traditionally starts with the udata and the
; interrupt stacks. As this is standard in almost all cases you can
; just include the standard implementation.
;
.common

#include "../../cpu-z80u/std-commonmem.s"

67 changes: 61 additions & 6 deletions Kernel/platform/platform-sbcv2/commonmem.s
Original file line number Diff line number Diff line change
@@ -1,11 +1,66 @@
# 0 "commonmem.S"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "commonmem.S"
;
; The common memory area traditionally starts with the udata and the
; interrupt stacks. As this is standard in almost all cases you can
; just include the standard implementation.
; The common memory area traditionally starts with the udata and the
; interrupt stacks. As this is standard in almost all cases you can
; just include the standard implementation.
;
.module commonmem
.common

# 1 "../../cpu-z80u/std-commonmem.s" 1
# 0 "../../cpu-z80u/std-commonmem.S"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
# 1 "../../cpu-z80u/std-commonmem.S"
;
;
; Standard Z80 common memory area blocks.
;
; Must remain a multiple of 256 bytes
;
; exported symbols
.export _ub
.export _udata
.export kstack_top
.export istack_top
.export istack_switched_sp

.area _COMMONMEM

.include "../../cpu-z80/std-commonmem.s"
_ub: ; first 512 bytes: starts with struct u_block, with the kernel stack working down from above
_udata:
kstack_base:
.byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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0, 0, 0
istack_top:
istack_switched_sp: .word 0
# 9 "commonmem.S" 2
43 changes: 43 additions & 0 deletions Kernel/platform/platform-sbcv2/crt0.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.code

; Load at 0x0100
; We are executed from ROMWBW so we live in bank 14/15
; with the HBIOS proxy at FE00
start:
di
ld sp, kstack_top
; move the common memory where it belongs
ld hl, __bss
ld de, __common
ld bc, __common_size
ldir
ld de, __commondata
ld bc, __commondata_size
ldir
; then the discard
; Discard can just be linked in but is next to the buffers
ld de, __discard
ld bc, __discard_size-1
add hl,bc
ex de,hl
add hl,bc
ex de,hl
lddr
; then zero the data area
ld hl, __bss
ld de, __bss + 1
ld bc, __bss_size - 1
ld (hl), 0
ldir
; Zero buffers area
ld hl, __buffers
ld de, __buffers + 1
ld bc, __buffers_size
ld (hl), 0
ldir
call init_early
call init_hardware
call _fuzix_main
di
stop: halt
jr stop
119 changes: 45 additions & 74 deletions Kernel/platform/platform-sbcv2/crt0.s
Original file line number Diff line number Diff line change
@@ -1,76 +1,47 @@
; Ordering of segments for the linker.
.area _CODE
.area _CODE2
.area _HOME
.area _CONST
.area _INITIALIZED
.area _DATA
.area _BSEG
.area _BSS
.area _HEAP
.area _GSINIT
.area _GSFINAL
.area _BUFFERS
.area _INITIALIZER
.area _DISCARD
.area _COMMONMEM
.area _COMMONDATA
# 0 "crt0.S"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "crt0.S"
.code

; imported symbols
.globl _fuzix_main
.globl init_early
.globl init_hardware
.globl s__DATA
.globl l__DATA
.globl s__DISCARD
.globl l__DISCARD
.globl s__BUFFERS
.globl l__BUFFERS
.globl s__COMMONMEM
.globl l__COMMONMEM
.globl s__COMMONDATA
.globl l__COMMONDATA
.globl s__INITIALIZER
.globl kstack_top
.globl map_kernel

; startup code
.area _CODE

; Load at 0x0100
; We are executed from ROMWBW so we live in bank 14/15
; with the HBIOS proxy at FE00
; Load at 0x0100
; We are executed from ROMWBW so we live in bank 14/15
; with the HBIOS proxy at FE00
start:
di
ld sp, #kstack_top
; move the common memory where it belongs
ld hl, #s__DATA
ld de, #s__COMMONMEM
ld bc, #l__COMMONMEM
ldir
ld de, #s__COMMONDATA
ld bc, #l__COMMONDATA
ldir
; then the discard
; Discard can just be linked in but is next to the buffers
ld de, #s__DISCARD
ld bc, #l__DISCARD
ldir
; then zero the data area
ld hl, #s__DATA
ld de, #s__DATA + 1
ld bc, #l__DATA - 1
ld (hl), #0
ldir
; Zero buffers area
ld hl, #s__BUFFERS
ld de, #s__BUFFERS + 1
ld bc, #l__BUFFERS - 1
ld (hl), #0
ldir
call init_early
call init_hardware
call _fuzix_main
di
stop: halt
jr stop
di
ld sp, kstack_top
; move the common memory where it belongs
ld hl, __bss
ld de, __common
ld bc, __common_size
ldir
ld de, __commondata
ld bc, __commondata_size
ldir
; then the discard
; Discard can just be linked in but is next to the buffers
ld de, __discard
ld bc, __discard_size-1
add hl,bc
ex de,hl
add hl,bc
ex de,hl
lddr
; then zero the data area
ld hl, __bss
ld de, __bss + 1
ld bc, __bss_size - 1
ld (hl), 0
ldir
; Zero buffers area
ld hl, __buffers
ld de, __buffers + 1
ld bc, __buffers_size
ld (hl), 0
ldir
call init_early
call init_hardware
call _fuzix_main
di
stop: halt
jr stop
Loading

0 comments on commit 6c10dea

Please sign in to comment.