Skip to content

Commit

Permalink
systest: Produce a WB/CLI executable as well as raw disk image.
Browse files Browse the repository at this point in the history
  • Loading branch information
keirf committed May 6, 2016
1 parent ddae478 commit ac18b37
Show file tree
Hide file tree
Showing 11 changed files with 261 additions and 66 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
*.hex
*.orig
*.rej
*.exe
*.zip
degzip
rom-swizzle
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
include base/Rules.mk

SUBDIRS := base overscan systest

.PHONY: all
all:

clean:: $(addsuffix clean,$(SUBDIRS))
%clean: %
$(MAKE) -C $< clean
1 change: 1 addition & 0 deletions base/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../base/Rules.mk
72 changes: 12 additions & 60 deletions base/bootblock.S
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* bootblock.S
*
* Amiga floppy-disk bootblock loader.
*
* Written & released by Keir Fraser <keir.xen@gmail.com>
*
* This is free and unencumbered software released into the public domain.
* See the file COPYING for more details, or visit <http://unlicense.org>.
*/

.section .text.init
.global start
start:
Expand Down Expand Up @@ -46,63 +57,4 @@ start:
jmp (a0)

.begin:
/* Initialise custom chips */
lea.l (0xdff000).l,a6
move.w #0x7fff,d0
move.w d0,0x9a(a6) /* intena = 0 */
move.w d0,0x9c(a6) /* intreq = 0 */
move.w d0,0x96(a6) /* dmacon = 0 */
move.w d0,0x9e(a6) /* adkcon = 0 */
move.w #0x8200,0x96(a6) /* enable master DMA */
move.w #0xc000,0x9a(a6) /* enable master IRQ */
moveq #0,d0
move.w d0,0x180(a6) /* color0 = black */

/* Initialise CPU state */
lea.l .priv(pc),a0
move.l a0,(0x20).w
.priv: move.w #0x2700,sr /* SR = 0x2700 (supervisor mode, no irqs) */
lea.l .skip(pc),a0
move.l a0,(0x10).w
dc.l 0x4e7b0002 /* movec.l d0,cacr (CACR = 0) */
.skip: lea.l (SUPER_SP).l,sp /* SSP */
lea.l (USER_SP).l,a0
move.l a0,usp /* USP */

lea.l start(pc),a0
move.l a0,d0 /* a0 = d0 = current location */
move.l #start,d1 /* d1 = destination */
moveq #4,d2
swap d2 /* d2 = 0x40000 (256kB) */
eor.l d1,d0 /* *Very* conservative test: could current */
and.l d2,d0 /* location and destination overlap? */
jne 1f
/* Temp. copy to other half of bottom 512kB */
eor.l d2,d1
jsr copy
eor.l d2,d1
move.l #1f,d0
eor.l d2,d0
move.l d0,a0
jmp (a0)
1: /* Main copy to final relocation point */
move.l #main,-(sp)

copy: lea.l start(pc),a0 /* a0 = current location */
move.l d1,a1 /* a1 = destination */
move.l #_end-start,d0
lsr.l #2,d0
1: move.l (a0)+,(a1)+
dbf d0,1b
rts

main: move.w #0x2000,sr /* allow CPU interrupts now that we are */
/* definitely executing clear of the stack */

/* motors off */
lea (0xBFD100).l,a5
ori.b #0xF8,(a5)
andi.b #0x87,(a5)
ori.b #0x78,(a5)

jra cstart
#include "init.S"
101 changes: 101 additions & 0 deletions base/dos_entry.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* dos_entry.S
*
* Entry code for startup from Amiga Workbench or CLI.
*
* Written & released by Keir Fraser <keir.xen@gmail.com>
*
* This is free and unencumbered software released into the public domain.
* See the file COPYING for more details, or visit <http://unlicense.org>.
*/

/* Exec Library Vector Offsets */
#define EXEC_Forbid -0x84
#define EXEC_FindTask -0x126
#define EXEC_GetMsg -0x174
#define EXEC_ReplyMsg -0x17a
#define EXEC_WaitPort -0x180
#define EXEC_OpenLibrary -0x198
#define EXEC_CloseLibrary -0x19e

/* Graphics Linrary Vector Offsets */
#define GFX_LoadView -0xde
#define GFX_WaitTOF -0x10e

/* Offsets into DOS Process structure (extends Exec Task) */
#define pr_MsgPort 0x5c
#define pr_CLI 0xac

/* Offsets into GfxBase */
#define gfx_ActiView 0x22
#define gfx_cop1 0x26
#define gfx_cop2 0x32

.section .text.init
.global start
start:
move.l 4,a6
/* Find our Process structure and determine how we were started. */
sub.l a1,a1
move.l a1,-(sp) /* no wb startup msg yet */
jsr EXEC_FindTask(a6) /* FindTask(NULL) */
move.l d0,a4
tst.l pr_CLI(a4) /* Running from CLI? */
bne .nowb

/* Started from Workbench: wait for start message */
lea pr_MsgPort(a4),a0
jsr EXEC_WaitPort(a6)
lea pr_MsgPort(a4),a0
jsr EXEC_GetMsg(a6)
move.l d0,(sp) /* Save the startup msg */
.nowb:
/* graphics.library set up a compatible view */
lea .gfx(pc),a1
moveq #0,d0
jsr EXEC_OpenLibrary(a6)
move.l d0,a6
move.l gfx_ActiView(a6),-(sp)
sub.l a1,a1
jsr GFX_LoadView(a6) /* LoadView(NULL) */
jsr GFX_WaitTOF(a6)
jsr GFX_WaitTOF(a6)
move.l a6,-(sp)

bsr .begin
move.l d0,d7

/* d7 = return code */
/* 0(sp) = gfxbase */
/* 4(sp) = original view */
/* 8(sp) = wb msg (or null) */

/* Restore original view */
move.l (sp)+,a6
jsr GFX_WaitTOF(a6)
jsr GFX_WaitTOF(a6)
lea.l (0xdff000).l,a5
move.l gfx_cop1(a6),0x80(a5) /* cop1lc */
move.l gfx_cop2(a6),0x84(a5) /* cop2lc */
move.l (sp)+,a1
jsr GFX_LoadView(a6) /* original view */

/* Close graphics library */
movel a6,a1
move.l 4,a6
jsr EXEC_CloseLibrary(a6)

move.l (sp)+,d3 /* d3 = workbench msg */
beq .quit
/* Workbench: Return the startup message to our parent */
jsr EXEC_Forbid(a6)
move.l d3,a1
jsr EXEC_ReplyMsg(a6)
.quit: move.l d7,d0
rts

.gfx: .asciz "graphics.library"
.align 2

.begin:
#include "init.S"
86 changes: 86 additions & 0 deletions base/init.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* entry.S
*
* Common startup/entry code
*
* Written & released by Keir Fraser <keir.xen@gmail.com>
*
* This is free and unencumbered software released into the public domain.
* See the file COPYING for more details, or visit <http://unlicense.org>.
*/

#define EXEC_Supervisor -0x1e

/* a4 = current VBR */
move.l 4,a6
sub.l a4,a4
btst.b #0,297(a6) /* check for 68010+ in AttnFlags */
jeq .novbr /* If a mere 68000 then there is no VBR */
lea getvbr(pc),a5
jsr EXEC_Supervisor(a6)
.novbr:

/* Initialise custom chips */
lea.l (0xdff000).l,a6
move.w #0x7fff,d0
move.w d0,0x9a(a6) /* intena = 0 */
move.w d0,0x9c(a6) /* intreq = 0 */
move.w d0,0x96(a6) /* dmacon = 0 */
move.w d0,0x9e(a6) /* adkcon = 0 */
move.w #0x8200,0x96(a6) /* enable master DMA */
move.w #0xc000,0x9a(a6) /* enable master IRQ */
moveq #0,d0
move.w d0,0x180(a6) /* color0 = black */

/* Floppy motors off */
lea (0xbfd100).l,a5
ori.b #0xf8,(a5)
andi.b #0x87,(a5)
ori.b #0x78,(a5)

/* Initialise CPU state */
lea.l .priv(pc),a0
move.l a0,0x20(a4)
.priv: move.w #0x2700,sr /* SR = 0x2700 (supervisor mode, no irqs) */
lea.l .skip(pc),a0
move.l a0,(0x10).w
dc.l 0x4e7b0801 /* movec.l d0,vbr (VBR = 0) */
dc.l 0x4e7b0002 /* movec.l d0,cacr (CACR = 0) */
.skip: lea.l (SUPER_SP).l,sp /* SSP */
lea.l (USER_SP).l,a0
move.l a0,usp /* USP */

lea.l start(pc),a0
move.l a0,d0 /* a0 = d0 = current location */
move.l #start,d1 /* d1 = destination */
moveq #4,d2
swap d2 /* d2 = 0x40000 (256kB) */
eor.l d1,d0 /* *Very* conservative test: could current */
and.l d2,d0 /* location and destination overlap? */
jne 1f
/* Temp. copy to other half of bottom 512kB */
eor.l d2,d1
jsr copy
eor.l d2,d1
move.l #1f,d0
eor.l d2,d0
move.l d0,a0
jmp (a0)
1: /* Main copy to final relocation point */
move.l #main,-(sp)

copy: lea.l start(pc),a0 /* a0 = current location */
move.l d1,a1 /* a1 = destination */
move.l #_end-start,d0
lsr.l #2,d0
1: move.l (a0)+,(a1)+
dbf d0,1b
rts

main: move.w #0x2000,sr /* allow CPU interrupts now that we are */
/* definitely executing clear of the stack */

jra cstart

getvbr: dc.l 0x4e7ac801 /* movec.l vbr,a4 */
rte
29 changes: 29 additions & 0 deletions base/mk_amiga_exe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# mk_amiga_exe.py
#
# Convert a raw binary into a simple AmigaDOS executable
# file with one loadable hunk and no relocations
#
# Written & released by Keir Fraser <keir.xen@gmail.com>
#
# This is free and unencumbered software released into the public domain.
# See the file COPYING for more details, or visit <http://unlicense.org>.

import struct, sys

HUNK_CODE = 0x3e9
HUNK_END = 0x3f2
HUNK_HEADER = 0x3f3

def main(argv):
in_f = open(argv[1], "rb")
out_f = open(argv[2], "wb")
in_dat = in_f.read()
in_len = len(in_dat)
assert (in_len & 3) == 0, "input is not longword padded"
out_f.write(struct.pack(">LLLLLL", HUNK_HEADER, 0, 1, 0, 0, in_len/4))
out_f.write(struct.pack(">LL", HUNK_CODE, in_len/4))
out_f.write(in_dat)
out_f.write(struct.pack(">L", HUNK_END))

if __name__ == "__main__":
main(sys.argv)
2 changes: 1 addition & 1 deletion overscan/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ overscan.adf: overscan.bin
adfwrite $@ $< 0 21 -r -c

clean::
$(RM) *.adf
$(RM) *.adf ../base/*.o
1 change: 1 addition & 0 deletions systest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SysTest
25 changes: 20 additions & 5 deletions systest/Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
OBJS += ../base/bootblock.o
OBJS += ../base/util.o
OBJS += disk.o
OBJS += systest.o

include ../base/Rules.mk

.PHONY: all
all: systest.adf
all: systest.zip

systest.adf: systest.bin
dd if=/dev/zero of=$@ bs=512 count=1760
systest.zip: systest.adf systest.exe SysTest.info
cp systest.exe SysTest
chmod 0755 SysTest
$(RM) $@
zip -q $@ $(subst systest.exe,SysTest,$^)
$(RM) SysTest

systest_exe.elf: OBJS := ../base/dos_entry.o $(OBJS)
systest_exe.elf: ../base/dos_entry.o

systest_adf.elf: OBJS := ../base/bootblock.o $(OBJS)
systest_adf.elf: ../base/bootblock.o

systest.exe: systest_exe.bin
python ../base/mk_amiga_exe.py $< $@

systest.adf: systest_adf.bin
dd if=/dev/zero of=$@ bs=512 count=1760 status=none
adfwrite $@ $< 0 43 -r -c

clean::
$(RM) *.adf
$(RM) *.adf *.exe *.zip ../base/*.o SysTest
Binary file added systest/SysTest.info
Binary file not shown.

0 comments on commit ac18b37

Please sign in to comment.