Skip to content

Commit

Permalink
z80pack: move to new compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
EtchedPixels committed Oct 25, 2023
1 parent 05a2850 commit 493fa7a
Show file tree
Hide file tree
Showing 13 changed files with 1,267 additions and 440 deletions.
47 changes: 31 additions & 16 deletions Kernel/platform/platform-z80pack/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,57 @@ NSRCS = ../../dev/net/net_native.c
#NSRCS = ../../dev/net/net_z80pack.c
CSRCS += devices.c main.c

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

AOBJS = $(ASRCS:.s=.rel)
COBJS = $(CSRCS:.c=.rel)
DOBJS = $(patsubst ../../dev/z80pack/%.c,%.rel, $(DSRCS))
NOBJS = $(patsubst ../../dev/net/%.c,%.rel, $(NSRCS))
AOBJS = $(ASRCS:.S=.o)
COBJS = $(CSRCS:.c=.o)
DOBJS = $(patsubst ../../dev/z80pack/%.c,%.o, $(DSRCS))
NOBJS = $(patsubst ../../dev/net/%.c,%.o, $(NSRCS))

OBJS = $(AOBJS) $(COBJS) $(DOBJS) $(NOBJS)

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

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

all: $(OBJS)

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

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

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

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


clean:
rm -f $(OBJS) $(JUNK) core *~
rm -f *.o core *~
rm -f bootblock.bin

image:
sdasz80 -o bootblock.s
sdldz80 -m -i bootblock.rel
makebin -s 128 bootblock.ihx > bootblock.bin
$(CROSS_LD) -b -C 0x0088 -S 0xF400 -X 0xE900 -f CLDBbXSs -o fuzix.bin \
crt0.o commonmem.o z80pack.o main.o \
../../start.o ../../version.o \
../../cpu-z80u/lowlevel-z80u.o ../../cpu-z80u/usermem_std-z80u.o \
tricks.o ../../timer.o ../../kdata.o ../../usermem.o \
../../dev/z80pack/devfd.o devices.o ../../devio.o ../../filesys.o \
../../blk512.o ../../process.o ../../inode.o ../../syscall_exec16.o \
../../syscall_exec.o ../../syscall_fs.o ../../syscall_fs2.o \
../../syscall_fs3.o ../../syscall_proc.o ../../syscall_other.o \
../../tty.o ../../mm.o ../../mm/memalloc_none.o ../../mm/bankfixed.o \
../../swap.o ../../devsys.o ../../dev/z80pack/devlpr.o \
../../dev/z80pack/devtty.o ../../dev/z80pack/devrtc.o \
../../level2.o ../../syscall_level2.o ../../syscall_net.o \
../../select.o ../../dev/net/net_native.o \
/opt/ccz80/lib/libz80.a -m fuzix.tmpmap
perl -lpe '$$_=hex' fuzix.tmpmap | paste -d" " - fuzix.tmpmap | sort -n | cut -d" " -f 2- >../../fuzix.map
../../tools/pack85 <../../fuzix.map fuzix.bin ../../fuzix.bin
asz80 bootblock.S -o bootblock.o
ldz80 -b bootblock.o -o bootblock.bin

IMAGES = $(FUZIX_ROOT)/Images/$(TARGET)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,45 @@
;
; assemble with sdasz80
;
.area ASEG(ABS)
.abs

.org 0

start: jr diskload

rootdev: .dw 0 ; patched by hand
swapdev: .dw 0 ; ditto
.dw 0 ; spare
rootdev: .word 0 ; patched by hand
swapdev: .word 0 ; ditto
.word 0 ; spare

progress: .db '/', '-', '\', '|'
progress: .byte '/', '-', '\', '|'

diskload: di
ld sp, #stack
ld hl, #0x88
ld sp, stack
ld hl, 0x88
exx
xor a
ld h, a
ld b, a
out (17), a ; sector high always 0
out (10), a ; drive always 0
ld a, #57 ; start on track 58
ld a, 57 ; start on track 58
out (11), a
exx
ld c, #19 ; number of tracks to load (56Kish)
ld c, 19 ; number of tracks to load (56Kish)
load_tracks: in a, (11)
inc a ; track
out (11), a
xor a
out (12), a
ld b, #26 ; sectors
ld b, 26 ; sectors
load_sectors: exx
ld a, b
and #3
add #progress
and 3
add a,progress
ld l, a
ld a, (hl)
out (01), a
ld a, #8
ld a, 8
out (01), a
inc b
exx
Expand All @@ -63,19 +64,19 @@ load_sectors: exx
xor a ; read
out (13), a ; go
in a, (14) ; status
ld de, #128
ld de, 128
add hl, de
djnz load_sectors ; 26 sectors = 3328 bytes
dec c
jr nz, load_tracks
ld a, #0xc9 ; to help debug
ld a, 0xc9 ; to help debug
ld (start), a
ld a, #13
ld a, 13
out (1), a
ld a, #10
ld a, 10
out (1), a
jp 0x88

.ds 26
stack:
.db 0xff
.byte 0xff
7 changes: 7 additions & 0 deletions Kernel/platform/platform-z80pack/commonmem.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
;
; Common on z80pack is at 0xF000 as defined by hardware.
;

.common

#include "../../cpu-z80u/std-commonmem.s"
58 changes: 54 additions & 4 deletions Kernel/platform/platform-z80pack/commonmem.s
Original file line number Diff line number Diff line change
@@ -1,9 +1,59 @@
# 0 "commonmem.S"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "commonmem.S"
;
; Common on z80pack is at 0xF000 as defined by hardware.
; Common on z80pack is at 0xF000 as defined by hardware.
;

.module commonmem
.common

.area _COMMONMEM
# 1 "../../cpu-z80u/std-commonmem.s" 1
;
;
; 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


_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, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0
istack_top:
istack_switched_sp: .word 0
# 8 "commonmem.S" 2
40 changes: 40 additions & 0 deletions Kernel/platform/platform-z80pack/crt0.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
; startup code
.code

init:
di
ld sp, kstack_top

; Configure memory map
call init_early

; 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
; and the discard
ld de, __discard
ld bc, __discard_size
ldir
; then zero the data area
ld hl, __bss
ld de, __bss + 1
ld bc, __bss_size - 1
ld (hl), 0
ldir

; Hardware setup
call init_hardware

; Call the C main routine
call _fuzix_main

; main shouldn't return, but if it does...
di
stop: halt
jr stop

92 changes: 29 additions & 63 deletions Kernel/platform/platform-z80pack/crt0.s
Original file line number Diff line number Diff line change
@@ -1,79 +1,45 @@
; 2013-12-18 William R Sowerbutts

.module crt0

; Ordering of segments for the linker.
; WRS: Note we list all our segments here, even though
; we don't use them all, because their ordering is set
; when they are first seen.
.area _CODE
.area _CODE2
.area _CONST
.area _INITIALIZED
.area _DATA
.area _BSEG
.area _BSS
.area _HEAP
; note that areas below here may be overwritten by the heap at runtime, so
; put initialisation stuff in here
.area _INITIALIZER
.area _GSINIT
.area _GSFINAL
.area _DISCARD
.area _COMMONMEM
.area _COMMONDATA

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

# 0 "crt0.S"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
# 1 "crt0.S"
; startup code
.area _CODE
.code

init:
di
ld sp, #kstack_top
ld sp, kstack_top

; Configure memory map
call init_early

; 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
; and the discard
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
; 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
; and the discard
ld de, __discard
ld bc, __discard_size
ldir
; then zero the data area
ld hl, __bss
ld de, __bss + 1
ld bc, __bss_size - 1
ld (hl), 0
ldir

; Hardware setup
call init_hardware

; Call the C main routine
call _fuzix_main

; main shouldn't return, but if it does...
di
stop: halt
stop: halt
jr stop

19 changes: 0 additions & 19 deletions Kernel/platform/platform-z80pack/kernel.def

This file was deleted.

Loading

0 comments on commit 493fa7a

Please sign in to comment.