amiga_boottest
changeset 0:51422ea54b9d
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 21 Feb 2018 12:00:13 +0200 |
parents | |
children | 48093e4bd99a |
files | Makefile amiga.ld src/boot/boot.s src/startup.s tools/mk_adf.py |
diffstat | 5 files changed, 169 insertions(+), 0 deletions(-) [+] |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/Makefile Wed Feb 21 12:00:13 2018 +0200 1.3 @@ -0,0 +1,35 @@ 1.4 +asrc = $(wildcard src/*.s) 1.5 +obj = $(asrc:.s=.o) 1.6 + 1.7 +name = test 1.8 +elf = $(name).elf 1.9 +bin = $(name).bin 1.10 +adf = $(name).adf 1.11 +bootblock = boot.bin 1.12 + 1.13 +tool_prefix = m68k-linux-gnu- 1.14 + 1.15 +CC = $(tool_prefix)gcc 1.16 +AS = $(tool_prefix)as 1.17 +LD = $(tool_prefix)ld 1.18 +OBJCOPY = $(tool_prefix)objcopy 1.19 + 1.20 +ASFLAGS = -m68000 1.21 +LDFLAGS = -T amiga.ld -print-gc-sections \ 1.22 + -L/usr/lib/gcc-cross/m68k-linux-gnu/6 -lgcc 1.23 + 1.24 +$(adf): $(bin) $(bootblock) 1.25 + tools/mk_adf.py $(bootblock) $(bin) $@ 1.26 + 1.27 +$(bin): $(elf) 1.28 + $(OBJCOPY) -O binary $< $@ 1.29 + 1.30 +$(elf): $(obj) 1.31 + $(LD) -o $@ $(obj) -Map link.map $(LDFLAGS) 1.32 + 1.33 +$(bootblock): src/boot/boot.o 1.34 + $(OBJCOPY) -O binary $< $@ 1.35 + 1.36 +.PHONY: clean 1.37 +clean: 1.38 + rm -f $(obj) $(bin) $(elf)
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/amiga.ld Wed Feb 21 12:00:13 2018 +0200 2.3 @@ -0,0 +1,27 @@ 2.4 +OUTPUT_ARCH(m68k) 2.5 + 2.6 +MEMORY 2.7 +{ 2.8 + chipram : ORIGIN = 0, LENGTH = 0x80000 2.9 +} 2.10 + 2.11 +PROVIDE (_stacktop = 0x80000); 2.12 + 2.13 +SECTIONS { 2.14 + /* bootblock will load us at 100h, after the interrupt vectors */ 2.15 + . = 0x100; 2.16 + 2.17 + .text : { * (.text); } >chipram 2.18 + .rodata : { * (.rodata); } >chipram 2.19 + .data : { * (.data); } >chipram 2.20 + 2.21 + .bss ALIGN(4): { 2.22 + _bss_start = .; 2.23 + * (.bss); 2.24 + . = ALIGN(4); 2.25 + _bss_end = .; 2.26 + } >chipram 2.27 + _bss_size = SIZEOF(.bss); 2.28 + 2.29 + .dummy ALIGN(4): { LONG(42); } >chipram 2.30 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/src/boot/boot.s Wed Feb 21 12:00:13 2018 +0200 3.3 @@ -0,0 +1,24 @@ 3.4 +| vi:filetype=gas68k: 3.5 + 3.6 + .equ CMD_READ, 2 3.7 + 3.8 + .equ EXEC_DO_IO, -0x1c8 3.9 + 3.10 +| starting with trackdisk device I/O request pointer in a1 3.11 +| load the program at 0x100 and return with that value in a0 3.12 +| program length is patched by mk_adf at start - 4 3.13 +start: 3.14 + move.l #0x100, 0x28(%a1) | I/O data pointer 3.15 + move.l start - 4, 0x24(%a1) | I/O length (1 sector for now) 3.16 + move.l #512, 0x2c(%a1) | I/O offset (skip first sector) 3.17 + move.w #CMD_READ, 0x1c(%a1) | I/O command 3.18 + move.l %a1, -(%sp) 3.19 + jsr EXEC_DO_IO(%a6) 3.20 + move.l (%sp)+, %a1 3.21 + move.b 0x1f(%a1), %d0 3.22 + 3.23 + move.l #0x100, %a0 3.24 + rts 3.25 + 3.26 + .ascii "bootblock_end" 3.27 + .align 4
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/src/startup.s Wed Feb 21 12:00:13 2018 +0200 4.3 @@ -0,0 +1,27 @@ 4.4 +| vi:filetype=gas68k: 4.5 + .text 4.6 + 4.7 + .equ REG_COL0, 0xdff180 4.8 + 4.9 + .global start 4.10 + .global halt_cpu 4.11 + 4.12 +start: 4.13 + | zero the .bss section 4.14 + move.l #_bss_start, %a0 4.15 + move.l #_bss_end, %a1 4.16 + cmp.l %a0, %a1 4.17 + beq.s 1f | skip zeroing if the section is empty 4.18 +0: clr.l (%a0)+ 4.19 + cmp.l %a0, %a1 4.20 + bne.s 0b 4.21 +1: 4.22 + | setup the stack 4.23 + move.l #_stacktop, %sp 4.24 + 4.25 + | test output 4.26 + move.w #0xf0f, REG_COL0 4.27 +0: bra.b 0b | infloop 4.28 + 4.29 +halt_cpu: 4.30 + stop #0x2700
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/tools/mk_adf.py Wed Feb 21 12:00:13 2018 +0200 5.3 @@ -0,0 +1,56 @@ 5.4 +#!/usr/bin/python 5.5 +# mk_adf.py <bootblock> <payload> <output_adf> 5.6 +# 5.7 +# Stuff a given bootblock and payload into an output ADF image. 5.8 +# 5.9 +# Written & released by Keir Fraser <keir.xen@gmail.com> 5.10 +# 5.11 +# This is free and unencumbered software released into the public domain. 5.12 +# See the file COPYING for more details, or visit <http://unlicense.org>. 5.13 + 5.14 +import struct, sys 5.15 + 5.16 +# Amiga bootblock checksum 5.17 +def checksum(bb, sum=0): 5.18 + while len(bb): 5.19 + x, bb = struct.unpack(">L",bb[:4]), bb[4:] 5.20 + sum += x[0] 5.21 + if sum >= (1<<32): 5.22 + sum -= (1<<32)-1 5.23 + return sum 5.24 + 5.25 +def main(argv): 5.26 + bb_f = open(argv[1], "rb") 5.27 + pl_f = open(argv[2], "rb") 5.28 + out_f = open(argv[3], "wb") 5.29 + bb_dat = bb_f.read() 5.30 + pl_dat = pl_f.read() 5.31 + 5.32 + # Construct bootblock header. We will splice in the checksum later. 5.33 + header = struct.pack(">ccccLLLL", 5.34 + 'D', 'O', 'S', '\0', # Bootblock signature 5.35 + 0, # Checksum (placeholder) 5.36 + 880, # Root block 5.37 + 0x60060000, # BRA.B +6 5.38 + (len(pl_dat) + 511) & ~511) # Payload length, padded 5.39 + 5.40 + 5.41 + # Compute checksum over header, bootblock, and first 512 bytes of payload. 5.42 + sum = checksum(pl_dat[:512], checksum(bb_dat, checksum(header))) 5.43 + sum ^= 0xFFFFFFFF 5.44 + # Splice the computed checksum into the header 5.45 + header = header[:4] + struct.pack(">L", sum) + header[8:] 5.46 + # Write out the header and bootblock code 5.47 + out_f.write(header) 5.48 + out_f.write(bb_dat) 5.49 + # Pad bootblock to 512 bytes 5.50 + for x in xrange((512-len(bb_dat)-len(header))/4): 5.51 + out_f.write(struct.pack(">L", 0)) 5.52 + # Write the payload from sector 1 onwards 5.53 + out_f.write(pl_dat) 5.54 + # Pad the ADF image to 880kB 5.55 + for x in xrange((901120-len(pl_dat)-512)/4): 5.56 + out_f.write(struct.pack(">L", 0)) 5.57 + 5.58 +if __name__ == "__main__": 5.59 + main(sys.argv)