megadrive_test1

changeset 0:909c22dc18d2

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 30 Jan 2017 08:21:53 +0200
parents
children 9e7f64c4fe7a
files .hgignore Makefile megadrive.ldscript src/intr.s src/main.s src/romhdr.S src/startup.s
diffstat 7 files changed, 213 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/.hgignore	Mon Jan 30 08:21:53 2017 +0200
     1.3 @@ -0,0 +1,6 @@
     1.4 +\.o$
     1.5 +\.d$
     1.6 +\.swp$
     1.7 +\.elf$
     1.8 +\.bin$
     1.9 +link\.map$
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/Makefile	Mon Jan 30 08:21:53 2017 +0200
     2.3 @@ -0,0 +1,32 @@
     2.4 +asrc = $(wildcard src/*.s)
     2.5 +aSsrc = $(wildcard src/*.S)
     2.6 +obj = $(asrc:.s=.o) $(aSsrc:.S=.o)
     2.7 +
     2.8 +name = test1
     2.9 +elf = $(name).elf
    2.10 +bin = $(name).bin
    2.11 +
    2.12 +warn = -pedantic -Wall
    2.13 +dbg = -g
    2.14 +def = -DGAMENAME=\"testgame\" -DVERSTR=\"01\"
    2.15 +
    2.16 +tool_prefix = m68k-linux-gnu-
    2.17 +
    2.18 +CC = $(tool_prefix)gcc
    2.19 +AS = $(tool_prefix)as
    2.20 +LD = $(tool_prefix)ld
    2.21 +OBJCOPY = $(tool_prefix)objcopy
    2.22 +
    2.23 +CFLAGS = -m68000 -nostdinc -fno-builtin $(warn) $(dbg) $(opt) $(def)
    2.24 +ASFLAGS = -m68000
    2.25 +LDFLAGS = -T megadrive.ldscript -print-gc-sections
    2.26 +
    2.27 +$(bin): $(elf)
    2.28 +	$(OBJCOPY) -O binary $< $@
    2.29 +
    2.30 +$(elf): $(obj)
    2.31 +	$(LD) -o $@ $(LDFLAGS) $(obj) -Map link.map
    2.32 +
    2.33 +.PHONY: clean
    2.34 +clean:
    2.35 +	rm -f $(obj) $(elf) $(bin)
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/megadrive.ldscript	Mon Jan 30 08:21:53 2017 +0200
     3.3 @@ -0,0 +1,44 @@
     3.4 +OUTPUT_ARCH(m68k)
     3.5 +
     3.6 +MEMORY
     3.7 +{
     3.8 +	rom : ORIGIN = 0x00000000, LENGTH = 0x00a00000
     3.9 +	ram : ORIGIN = 0x00ff0000, LENGTH = 0x00010000
    3.10 +}
    3.11 +
    3.12 +PROVIDE (_stacktop = 0x01000000);
    3.13 +
    3.14 +SECTIONS {
    3.15 +	/* ---- start of ROM ---- */
    3.16 +	/* .vect section is used to place the m68k exception vectors at the
    3.17 +	 * beginning of the address space
    3.18 +	 */
    3.19 +	.vect : { KEEP (* (.vect)); } >rom
    3.20 +	/* .romhdr section is used to place the SEGA ROM header at 0x100 */
    3.21 +	. = 0x100;
    3.22 +	.romhdr : { KEEP (* (.romhdr)); } >rom
    3.23 +	.text : { * (.text); } >rom
    3.24 +	.rodata : { * (.rodata); } >rom
    3.25 +
    3.26 +	/* place the load address of the .data section after .rodata */
    3.27 +	_data_lma = .;
    3.28 +	_rom_end = _data_lma + _data_size;
    3.29 +
    3.30 +	/* ---- start of RAM ---- */
    3.31 +	. = 0xff0000;
    3.32 +	/* place the .data section at the start of RAM */
    3.33 +	.data : AT (_data_lma) {
    3.34 +		_data_start = .;
    3.35 +		* (.data);
    3.36 +		_data_end = .;
    3.37 +	} >ram
    3.38 +	_data_size = SIZEOF(.data);
    3.39 +
    3.40 +	/* place the .bss section at the end */
    3.41 +	.bss : {
    3.42 +		_bss_start = .;
    3.43 +		* (.bss);
    3.44 +		_bss_end = .;
    3.45 +	} >ram
    3.46 +	_bss_size = SIZEOF(.bss);
    3.47 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/intr.s	Mon Jan 30 08:21:53 2017 +0200
     4.3 @@ -0,0 +1,82 @@
     4.4 +| the following will go into the .vect section which will be placed at the very
     4.5 +| begining of the binary at address 0 by the linker (see lnkscript).
     4.6 +	.section .vect,"a"
     4.7 +	.extern start
     4.8 +| exception vectors
     4.9 +	.long _stacktop		| 00 reset - initial SSP
    4.10 +	.long start		| 01 reset - initial PC
    4.11 +	.long intr_fatal	| 02 bus error
    4.12 +	.long intr_fatal	| 03 address error
    4.13 +	.long intr_fatal	| 04 illegal instruction
    4.14 +	.long intr_fatal	| 05 zero divide
    4.15 +	.long intr_fatal	| 06 chk instruction
    4.16 +	.long intr_fatal	| 07 trapv instruction
    4.17 +	.long intr_fatal	| 08 privilege violation
    4.18 +	.long intr_fatal	| 09 trace
    4.19 +	.long intr_fatal	| 0a line 1010 emulator
    4.20 +	.long intr_fatal	| 0b line 1111 emulator
    4.21 +	.long intr_fatal	| 0c reserved
    4.22 +	.long intr_fatal	| 0d reserved
    4.23 +	.long intr_fatal	| 0e format error (mc68010 only)
    4.24 +	.long intr_fatal	| 0f uninitialized interrupt vector
    4.25 +	.long intr_fatal	| 10 \
    4.26 +	.long intr_fatal	| 11 |
    4.27 +	.long intr_fatal	| 12 |
    4.28 +	.long intr_fatal	| 13  > reserved
    4.29 +	.long intr_fatal	| 14 |
    4.30 +	.long intr_fatal	| 15 |
    4.31 +	.long intr_fatal	| 16 |
    4.32 +	.long intr_fatal	| 17 /
    4.33 +	.long intr_fatal	| 18 spurious interrupt 
    4.34 +	.long intr_fatal	| 19 level 1 interrupt
    4.35 +	.long intr_fatal	| 1a level 2 interrupt
    4.36 +	.long intr_fatal	| 1b level 3 interrupt
    4.37 +	.long intr_hblank	| 1c level 4 interrupt (hblank in the mega drive)
    4.38 +	.long intr_fatal	| 1d level 5 interrupt
    4.39 +	.long intr_vblank	| 1e level 6 interrupt (vblank in the mega drive)
    4.40 +	.long intr_fatal	| 1f level 7 interrupt
    4.41 +	.long intr_fatal	| 20 trap 0
    4.42 +	.long intr_fatal	| 21 trap 1
    4.43 +	.long intr_fatal	| 22 trap 2
    4.44 +	.long intr_fatal	| 23 trap 3
    4.45 +	.long intr_fatal	| 24 trap 4
    4.46 +	.long intr_fatal	| 25 trap 5
    4.47 +	.long intr_fatal	| 26 trap 6
    4.48 +	.long intr_fatal	| 27 trap 7
    4.49 +	.long intr_fatal	| 28 trap 8
    4.50 +	.long intr_fatal	| 29 trap 9
    4.51 +	.long intr_fatal	| 2a trap a
    4.52 +	.long intr_fatal	| 2b trap b
    4.53 +	.long intr_fatal	| 2c trap c
    4.54 +	.long intr_fatal	| 2d trap d
    4.55 +	.long intr_fatal	| 2e trap e
    4.56 +	.long intr_fatal	| 2f trap f
    4.57 +	.long intr_fatal	| 30 \
    4.58 +	.long intr_fatal	| 31 |
    4.59 +	.long intr_fatal	| 32 |
    4.60 +	.long intr_fatal	| 33 |
    4.61 +	.long intr_fatal	| 34 |
    4.62 +	.long intr_fatal	| 35 |
    4.63 +	.long intr_fatal	| 36 |
    4.64 +	.long intr_fatal	| 37 |
    4.65 +	.long intr_fatal	| 38  > reserved
    4.66 +	.long intr_fatal	| 39 |
    4.67 +	.long intr_fatal	| 3a |
    4.68 +	.long intr_fatal	| 3b |
    4.69 +	.long intr_fatal	| 3c |
    4.70 +	.long intr_fatal	| 3d |
    4.71 +	.long intr_fatal	| 3e |
    4.72 +	.long intr_fatal	| 3f /
    4.73 +
    4.74 +| from here on we continue in the regular .text section since we don't care
    4.75 +| where this code ends up.
    4.76 +	.text
    4.77 +| interrupt handlers
    4.78 +intr_fatal:
    4.79 +	stop #0x2700
    4.80 +
    4.81 +| TODO hblank/vblank code
    4.82 +intr_hblank:
    4.83 +	rte
    4.84 +intr_vblank:
    4.85 +	rte
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/main.s	Mon Jan 30 08:21:53 2017 +0200
     5.3 @@ -0,0 +1,4 @@
     5.4 +	.text
     5.5 +	.global main
     5.6 +main:
     5.7 +	rts
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/romhdr.S	Mon Jan 30 08:21:53 2017 +0200
     6.3 @@ -0,0 +1,37 @@
     6.4 +| the following will go into the custom .romhdr section which will be placed at
     6.5 +| address 100 of the binary by the linker (see lnkscript).
     6.6 +	.section .romhdr,"a"
     6.7 +
     6.8 +#ifndef GAMENAME
     6.9 +#define GAMENAME "unnamed"
    6.10 +#endif
    6.11 +#ifndef VERSTR
    6.12 +#define VERSTR "00"
    6.13 +#endif
    6.14 +
    6.15 +	.ascii "SEGA MEGA DRIVE (C)MINDLAPSE2017"
    6.16 +hdr_game_dom:
    6.17 +	.ascii GAMENAME
    6.18 +hdr_game_dom_end:
    6.19 +	.fill 48 - (hdr_game_dom_end - hdr_game_dom),1,32 | pad to 48 bytes with spaces
    6.20 +hdr_game_int:
    6.21 +	.ascii GAMENAME
    6.22 +hdr_game_int_end:
    6.23 +	.fill 48 - (hdr_game_int_end - hdr_game_int),1,32 | pad to 48 bytes with spaces
    6.24 +	.ascii "GM"		| it's a game (who cares what it is?)
    6.25 +	.ascii "0000000-"	| product code
    6.26 +	.ascii VERSTR		| version string
    6.27 +	.short 0		| checksum
    6.28 +	.ascii "J               " | I/O support (joypad)
    6.29 +	.long 0			| start address of ROM
    6.30 +	.long _rom_end		| last address of ROM
    6.31 +	.long 0xff0000		| start address of RAM
    6.32 +	.long 0xffffff		| last address of RAM
    6.33 +	.long 0			| SRAM enabled(?)
    6.34 +	.long 0			| ???
    6.35 +	.long 0			| start address of SRAM
    6.36 +	.long 0			| last address of SRAM
    6.37 +	.long 0			| ???
    6.38 +	.long 0			| ???
    6.39 +	.fill 40,1,32		| notes (fill with spaces for now TODO)
    6.40 +	.ascii "JUE             " | country codes
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/startup.s	Mon Jan 30 08:21:53 2017 +0200
     7.3 @@ -0,0 +1,8 @@
     7.4 +| TODO: copy .data and zero .bss
     7.5 +	.text
     7.6 +	.extern main
     7.7 +
     7.8 +	.global start
     7.9 +start:
    7.10 +	jsr main
    7.11 +	stop #0x2700