Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#5 Moop Video/exception overhaul #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Makefile.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ TARGETCCVER = 4

# You generally shouldn't change this unless you are making forked
# versions (or test versions)
VERSION = 1.0.5
VERSION = 1.1.1

# Define this if you want a standalone, statically linked, no dependency binary
# This is on by default for MinGW/MSYS
Expand All @@ -98,6 +98,11 @@ VERSION = 1.0.5
# Set to 1 to enable, 0 to disable.
SAVE_MY_FANS = 0

# This sets the number of seconds to show the register dump on-screen if an
# exception occurs. Maximum is 60 seconds, minimum is 0 seconds (no display),
# default is 15 seconds.
EXCEPTION_SECONDS = 15

#
# IMPORTANT IP ADDRESS INFORMATION:
#
Expand Down
2 changes: 1 addition & 1 deletion NETWORK
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ dcload-ip implements (to some extent) the following protocols:

* UDP - dcload-ip uses UDP for transfering data and commands


* DHCP - dcload-ip can use IPv4 DHCP to get an IP address now


26 changes: 13 additions & 13 deletions example-src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,44 @@ include ../Makefile.cfg

CC = $(TARGETCC)
INCLUDE = -I../target-inc
CFLAGS = $(TARGETCFLAGS)
CFLAGS = $(TARGETCFLAGS) -Wall -Wextra -Wno-unused -ffreestanding -fno-zero-initialized-in-bss -fomit-frame-pointer -fno-strict-aliasing -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-exceptions -fno-delete-null-pointer-checks -fno-stack-protector -fno-stack-check -fmerge-constants -fmerge-all-constants -std=gnu11
OBJCOPY = $(TARGETOBJCOPY)

OBJECTS = crt0.o dcload-syscall.o dcload-syscalls.o memcpy.o
OBJECTS = crt0.o startup_support.o dcload-syscall.o dcload-syscalls.o memcpy.o

.c.o:
$(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $<
$(CC) $(CFLAGS) $(INCLUDE) -Wa,-adghlmns=$*.asm -o $@ -c $<

.S.o:
$(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $<
$(CC) $(CFLAGS) $(INCLUDE) -Wa,-adghlmns=$*.asm -o $@ -c $<

.s.o:
$(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $<
$(CC) $(CFLAGS) $(INCLUDE) -Wa,-adghlmns=$*.asm -o $@ -c $<

all: console-test.bin exception-test.bin gethostinfo.bin

console-test.bin: console-test
$(OBJCOPY) -O binary $< $@
$(OBJCOPY) -O binary $< $@

exception-test.bin: exception-test
$(OBJCOPY) -O binary $< $@
$(OBJCOPY) -O binary $< $@

gethostinfo.bin: gethostinfo
$(OBJCOPY) -O binary $< $@
$(OBJCOPY) -O binary $< $@

console-test: $(OBJECTS) console-test.o
$(CC) $(CFLAGS) -Wl,-Tdc$(TARGETCCVER).x -nostartfiles -nostdlib $^ -o $@ -lgcc
$(CC) $(CFLAGS) -Wl,--warn-common -Wl,--no-undefined -Wl,-Map,console-test.map -Wl,-Tdc$(TARGETCCVER).x -nostartfiles -nostdlib $^ -o $@ -lgcc

gethostinfo: $(OBJECTS) gethostinfo.o
$(CC) $(CFLAGS) -Wl,-Tdc$(TARGETCCVER).x -nostartfiles -nostdlib $^ -o $@ -lgcc
$(CC) $(CFLAGS) -Wl,--warn-common -Wl,--no-undefined -Wl,-Map,gethostinfo.map -Wl,-Tdc$(TARGETCCVER).x -nostartfiles -nostdlib $^ -o $@ -lgcc

exception-test: $(OBJECTS) exception-test.o
$(CC) $(CFLAGS) -Wl,-Tdc$(TARGETCCVER).x -nostartfiles -nostdlib $^ -o $@ -lgcc
$(CC) $(CFLAGS) -Wl,--warn-common -Wl,--no-undefined -Wl,-Map,exception-test.map -Wl,-Tdc$(TARGETCCVER).x -nostartfiles -nostdlib $^ -o $@ -lgcc

.PHONY : clean
clean:
rm -f *.o console-test exception-test gethostinfo
rm -f *.o console-test exception-test gethostinfo *.map *.asm

.PHONY : distclean
distclean: clean
distclean: clean
rm -f *.bin
2 changes: 2 additions & 0 deletions example-src/README
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
crt0.S a version of crt0.S
startup_support.c a helper file for crt0.S
dc.x a linker script for the Dreamcast
dcload-syscall.S assembly to call a dcload syscall
dcload-syscall.h lowlevel dcload syscall header
dcload-syscalls.c dcload syscall c source
dcload-syscalls.h dcload syscall header

To use this stuff in your own code, #include "dcload-syscalls.h" and link with dcload-syscalls.o and dcload-syscall.o.
(Well, it's not quite that simple. There are a bunch of headers in target-inc that are needed, as well. The way this was put together initially was very sloppily and did not stand the test of time.)

You're welcome to use any of the code in this directory in any way you please.
I'm not responsible if it causes you to fart fire, grow a third eye, etc, etc.
2 changes: 1 addition & 1 deletion example-src/console-test.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "dcload-syscalls.h"

int main(void)
void main(void)
{
int fd;
unsigned char buffer[2048];
Expand Down
36 changes: 24 additions & 12 deletions example-src/crt0.S
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ setup_cache:
mov.l ccr_addr,r0
mov.w ccr_data,r1
mov.l r1,@r0
mov.l start_2_k,r0
mov.l start_2_k,r0
nop
nop
nop
nop
nop
nop
nop
jmp @r0
jmp @r0
nop
start_2:
start_2:
mov.l old_stack_k,r14
mov.l r15,@r14
mov.l old_pr_k,r14
Expand All @@ -33,21 +33,30 @@ start_2:
! zero out bss
mov.l edata_k,r0
mov.l end_k,r1
cmp/eq r0,r1 ! unless there is no bss
bt no_bss
mov #0,r2
start_l:
mov.l r2,@r0
add #4,r0
cmp/ge r0,r1
cmp/hi r0,r1 ! This was cmp/ge before, which would always write 4 bytes beyond the end...
bt start_l

no_bss:
#if defined (__SH3E__) || defined(__SH4_SINGLE__) || defined(__SH4__) || defined(__SH4_SINGLE_ONLY)
mov.l set_fpscr_k, r1
jsr @r1
mov #0,r4
lds r3,fpscr
! lds r3,fpscr ! This isn't necessary.
#endif /* defined (__SH3E__) || defined(__SH4_SINGLE__) || defined(__SH4__) || defined(__SH4_SINGLE_ONLY__) */
! enable exceptions and the FPU
stc sr,r0
mov.l sr_mask,r1
and r1,r0
or #0xf0,r0
ldc r0,sr

! call the mainline
! call the mainline
mov.l main_k,r0
jsr @r0
or r0,r0
Expand All @@ -60,10 +69,10 @@ start_l:

___exit:
mov.l old_pr_k,r14
mov.l @r14,r15
mov.l @r14,r15
lds r15,pr
mov.l old_stack_k,r14
mov.l @r14,r15
mov.l @r14,r15
rts
nop

Expand All @@ -72,12 +81,15 @@ _atexit:
nop

.align 4
sr_mask:
.long 0xefff7fff
#if defined (__SH3E__) || defined(__SH4_SINGLE__) || defined(__SH4__) || defined(__SH4_SINGLE_ONLY__)
set_fpscr_k:
.long ___set_fpscr
! __set_fpscr() is deprecated, use this wrapper for builtin instead
.long ___call_builtin_sh_set_fpscr
#endif /* defined (__SH3E__) || defined(__SH4_SINGLE__) || defined(__SH4__) || defined(SH4_SINGLE_ONLY) */
stack_k:
.long _stack
.long _stack
edata_k:
.long _edata
end_k:
Expand All @@ -100,7 +112,7 @@ _old_pr:
setup_cache_k:
.long setup_cache
start_2_k:
.long start_2
.long start_2
p2_mask:
.long 0xa0000000
ccr_addr:
Expand All @@ -109,7 +121,7 @@ ccr_data:
.word 0x090b

.align 4

#ifdef __ELF__
.section .stack,"aw"
#else
Expand Down
11 changes: 6 additions & 5 deletions example-src/dc3.x
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ SECTIONS
.rela.bss : { *(.rela.bss) }
.rel.plt : { *(.rel.plt) }
.rela.plt : { *(.rela.plt) }
.init :
{
.init :
{
KEEP (*(.init))
} =0
.plt : { *(.plt) }
Expand Down Expand Up @@ -123,7 +123,7 @@ SECTIONS
.data1 : { *(.data1) }
.eh_frame : { *(.eh_frame) }
.gcc_except_table : { *(.gcc_except_table) }
.ctors ALIGN(4):
.ctors ALIGN(4):
{
___ctors = .;
/* gcc uses crtbegin.o to find the start of
Expand Down Expand Up @@ -159,12 +159,13 @@ SECTIONS
/* We want the small data sections together, so single-instruction offsets
can access them all, and initialized data all before uninitialized, so
we can shorten the on-disk segment size. */
.sdata :
.sdata :
{
*(.sdata)
*(.sdata)
*(.sdata.*)
*(.gnu.linkonce.s.*)
}
. = ALIGN(32 / 8);
_edata = .;
PROVIDE (edata = .);
__bss_start = .;
Expand Down
12 changes: 10 additions & 2 deletions example-src/dc4.x
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ SECTIONS
{
*(.sdata .sdata.* .gnu.linkonce.s.*)
}
. = ALIGN(32 / 8);
_edata = .; PROVIDE (edata = .);
__bss_start = .;
.sbss :
Expand All @@ -179,9 +180,16 @@ SECTIONS
/* Align here to ensure that the .bss section occupies space up to
_end. Align after .bss to ensure correct alignment even if the
.bss section disappears because there are no input sections.
FIXME: Why do we need it? When there is no .bss section, we don't
Question: Why do we need it? When there is no .bss section, we don't
pad the .data section. */
. = ALIGN(. != 0 ? 32 / 8 : 1);
/* Answer: bss must exist and be at least 4 bytes in size because
crt0.S will try to zero out bss even if there isn't one. So we
always need a bss section, and moreover it (_edata in particular)
must be aligned to 4 bytes as 'mov.l Rm,@Rn' will crash otherwise.
This now still needs to be aligned to 4 bytes (to line up with _end if
there is no bss), but with a change to crt0.S it at least will check if
there is a bss section first... */
. = ALIGN(. != 0 ? 32 /8 : 1);
}
. = ALIGN(32 / 8);
. = ALIGN(32 / 8);
Expand Down
4 changes: 3 additions & 1 deletion example-src/dcload-syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define __DCLOAD_SYSCALL_H__

int dcloadsyscall(unsigned int syscall, ...);
void __exit(int status);
void __call_builtin_sh_set_fpscr(unsigned int value);

#define pcreadnr 0
#define pcwritenr 1
Expand All @@ -11,7 +13,7 @@ int dcloadsyscall(unsigned int syscall, ...);
#define pclinknr 5
#define pcunlinknr 6
#define pcchdirnr 7
#define pcchmodnr 8
#define pcchmodnr 8
#define pclseeknr 9
#define pcfstatnr 10
#define pctimenr 11
Expand Down
Loading