From: ljsebald <ljs...@us...> - 2023-09-08 00:54:24
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via 269160a8056325dda09163a433ab3756c88cfd50 (commit) from cc16fee4d4ebbe969a65bf3cc220deeb924de8f2 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 269160a8056325dda09163a433ab3756c88cfd50 Author: Falco Girgis <gyr...@gm...> Date: Thu Sep 7 19:49:51 2023 -0500 environ.sh.sample cleanup + documentation + optimizations (#288) * Cleaned up environ.sh.sample to more closely reflect the model we're using for the dc-chain config files. * more optimization flags added * more detailed descriptions added * legacy comments removed * Beautified pvr_mem.c with 80 character columns * Address review feedback. ----------------------------------------------------------------------- Summary of changes: doc/environ.sh.sample | 184 +++++++++++++++------- include/kos/opts.h | 9 ++ kernel/arch/dreamcast/hardware/pvr/pvr_mem.c | 23 ++- kernel/arch/dreamcast/hardware/pvr/pvr_mem_core.c | 6 +- kernel/libc/koslib/malloc.c | 6 +- 5 files changed, 158 insertions(+), 70 deletions(-) diff --git a/doc/environ.sh.sample b/doc/environ.sh.sample index 9ed3aae..fe55a61 100644 --- a/doc/environ.sh.sample +++ b/doc/environ.sh.sample @@ -1,69 +1,107 @@ -# KallistiOS environment variable settings +# KallistiOS Environment Settings # -# This is a sample script. Configure to suit your setup. Some possible -# alternatives for the values below are included as an example. +# This is a sample script for configuring and customizing your +# KOS build environment. Modify it to suit your setup. Several +# settings may be enabled optionally or are provided with +# alternative values. # -# This script should be sourced in your current shell environment (probably -# by bashrc or something similar). +# This script is typically sourced in your current shell environment +# (probably by .bashrc, .bash_profile, or something similar), so that +# the KOS environment is set up automatically for each shell session. # -# Build architecture. Set the major architecture you'll be building for. +# Build Architecture +# +# Set the major architecture you'll be building for. # The only option here is "dreamcast" as of KOS 2.0.0. +# export KOS_ARCH="dreamcast" -# Build sub-architecture. If you need a particular sub-architecture, then set -# that here; otherwise use "pristine". -# Possible subarch options include: -# "pristine" - a normal Dreamcast console or HKT-0120 devkit -# "naomi" - a NAOMI or NAOMI 2 arcade board -# You can also pre-define it in eg the build config of your IDE +# Build Sub-Architecture +# +# Defines the sub architecture your configuration +# is targeting or uses an existing value that +# can be set externally via your IDE. +# +# Valid values: +# "pristine" - Dreamcast console or HKT-0120 devkit (default) +# "naomi" - NAOMI or NAOMI 2 arcade board +# if [ -z "${KOS_SUBARCH}" ] ; then export KOS_SUBARCH="pristine" else export KOS_SUBARCH fi -# KOS main base path +# KOS Root Path +# +# Specifies the path to the KOS root directory +# export KOS_BASE="/opt/toolchains/dc/kos" + +# KOS-Ports Path +# +# Specifies the path to the KOS-ports directory +# export KOS_PORTS="${KOS_BASE}/../kos-ports" -# Make utility -export KOS_MAKE="make" -#export KOS_MAKE="gmake" +# SH Compiler Prefixes +# +# Specifies the path to and prefix for the main SH +# GCC toolchain used to target the Dreamcast's SH4 CPU. +# +export KOS_CC_BASE="/opt/toolchains/dc/sh-elf" +export KOS_CC_PREFIX="sh-elf" -# CMake toolchain -export KOS_CMAKE_TOOLCHAIN="${KOS_BASE}/utils/cmake/dreamcast.toolchain.cmake" +# ARM Compiler Prefixes +# +# Specifies the path to and prefix for the additional ARM +# GCC toolchain used to target the Dreamcast's AICA SPU. +# +export DC_ARM_BASE="/opt/toolchains/dc/arm-eabi" +export DC_ARM_PREFIX="arm-eabi" -# Load utility -export KOS_LOADER="dc-tool -x" # dcload, preconfigured -# export KOS_LOADER="dc-tool-ser -t /dev/ttyS0 -x" # dcload-serial +# CMake Toolchain Path +# +# Specifies the path to the toolchain file used to target +# KOS with the "cmake" build utility. +# +export KOS_CMAKE_TOOLCHAIN="${KOS_BASE}/utils/cmake/dreamcast.toolchain.cmake" -# Genromfs utility +# Genromfs Utility Path +# +# Specifies the path to the utility which is used by KOS +# to create romdisk filesystem images. +# export KOS_GENROMFS="${KOS_BASE}/utils/genromfs/genromfs" -#export KOS_GENROMFS="genromfs" - -# Compiler prefixes -#export KOS_CC_BASE="/usr/local/dc/dc-elf" -#export KOS_CC_PREFIX="dc" -export KOS_CC_BASE="/opt/toolchains/dc/sh-elf" # DC -export KOS_CC_PREFIX="sh-elf" -# If you are compiling for DC and have an ARM compiler, use these too. -# If you're using a newer compiler (GCC 4.7.0 and newer), you should probably be -# using arm-eabi as the target, rather than arm-elf. dc-chain now defaults to -# arm-eabi, so that's the default here. -#export DC_ARM_BASE="/usr/local/dc/arm-elf" -#export DC_ARM_PREFIX="arm-elf" -export DC_ARM_BASE="/opt/toolchains/dc/arm-eabi" -export DC_ARM_PREFIX="arm-eabi" +# Make Utility +# +# Configures the tool to be used as the main "make" utility +# for building GNU Makefiles. On a platform such as BSD, +# the default can be changed to "gmake," for the GNU +# implementation. +# +export KOS_MAKE="make" +#export KOS_MAKE="gmake" -# Expand PATH if not already set (comment out if you don't want this done here) -if [[ ":$PATH:" != *":${KOS_CC_BASE}/bin:/opt/toolchains/dc/bin"* ]]; then - export PATH="${PATH}:${KOS_CC_BASE}/bin:/opt/toolchains/dc/bin" -fi +# Loader Utility +# +# Specifies the loader to be used with the "make run" targets +# in the KOS examples. Defaults to using a preconfigured version +# of dc-tool. Use one of the other options for a manual dc-tool-ip +# or dc-tool-serial configuration, remembering to change the values +# for the Dreamcast's IP address or the serial port interface. +# +export KOS_LOADER="dc-tool -x" +#export KOS_LOADER="dc-tool-ip -t 192.168.1.100 -x" +#export KOS_LOADER="dc-tool-ser -t /dev/ttyS0 -x" -# reset some options because there's no reason for them to persist across -# multiple sourcing of this +# Default Compiler Flags +# +# Resets build flags. You can also initialize them to some preset +# default values here if you wish. +# export KOS_INC_PATHS="" export KOS_CFLAGS="" export KOS_CPPFLAGS="" @@ -71,32 +109,66 @@ export KOS_LDFLAGS="" export KOS_AFLAGS="" export DC_ARM_LDFLAGS="" -# Setup some default CFLAGS for compilation. The things that will go here -# are user specifyable, like optimization level and whether you want stack -# traces enabled. Some platforms may have optimization restrictions, -# please check README. -# GCC seems to have made -fomit-frame-pointer the default on many targets, so -# hence you may need -fno-omit-frame-pointer to actually have GCC spit out frame -# pointers. It won't hurt to have it in there either way. -# Link-time optimizations can be enabled by adding -flto. It however requires a -# recent toolchain (GCC 10+), and has not been thoroughly tested. -export KOS_CFLAGS="-O2 -fomit-frame-pointer" -# export KOS_CFLAGS="-O2 -DFRAME_POINTERS -fno-omit-frame-pointer" +# Optimization Level +# +# Controls the baseline optimization level to use when building. +# Typically this is -Og (debugging), -O0, -01, -02, or -03. +# NOTE: For our target, -O4 is a valid optimization level that has +# been seen to have some performance impact as well. +# +export KOS_CFLAGS="${KOS_CFLAGS} -O2" + +# Additional Optimizations +# +# Uncomment this to enable what has been found emperically to be +# the optimal set of additional flags for release build performance +# on the current stable toolchain. NOTE: Certain KOS-ports and examples +# do not work properly with "-flto=auto"! +# +#export KOS_CFLAGS="${KOS_CFLAGS} -freorder-blocks-algorithm=simple -flto=auto" + +# Frame Pointers +# +# Controls whether frame pointers are emitted or not. Disabled by +# default. Enable them if you plan to use GDB for debugging. +# +export KOS_CFLAGS="${KOS_CFLAGS} -fomit-frame-pointer" +#export KOS_CFLAGS="${KOS_CFLAGS} -fno-omit-frame-pointer -DFRAME_POINTERS" +# GCC Builtin Functions +# # Comment out this line to enable GCC to use its own builtin implementations of # certain standard library functions. Under certain conditions, this can allow # compiler-optimized implementations to replace standard function invocations. # The downside of this is that it COULD interfere with Newlib or KOS implementations # of these functions, and it has not been tested thoroughly to ensure compatibility. +# export KOS_CFLAGS="${KOS_CFLAGS} -fno-builtin" +# Fast Math Instructions +# # Uncomment this line to enable the optimized fast-math instructions (FSSRA, # FSCA, and FSQRT) for calculating sin/cos, inverse square root, and square roots. # These can result in substantial performance gains for these kinds of operations; # however, they do so at the price of accuracy and are not IEEE compliant. # NOTE: This also requires -fno-builtin be removed from KOS_CFLAGS to take effect! +# # export KOS_CFLAGS="${KOS_CFLAGS} -ffast-math -ffp-contract=fast -mfsrra -mfsca" -# Everything else is pretty much shared. If you want to configure compiler -# options or other such things, look at this file. +# Additional Tools Path +# +# If not already set, add "bin" directory to PATH variable, which is where +# additional tools such as dc-tool-ip and dc-tool-serial are typically +# installed. Comment this out if you don't want this included within your PATH. +# +if [[ ":$PATH:" != *":${KOS_CC_BASE}/bin:/opt/toolchains/dc/bin"* ]]; then + export PATH="${PATH}:${KOS_CC_BASE}/bin:/opt/toolchains/dc/bin" +fi + +# Shared Compiler Configuration +# +# Include sub architecture-independent configuration file for shared +# environment settings. If you want to configure additional compiler +# options or see where other build flags are set, look at this file. +# . ${KOS_BASE}/environ_base.sh diff --git a/include/kos/opts.h b/include/kos/opts.h index 8b27c41..8287c24 100644 --- a/include/kos/opts.h +++ b/include/kos/opts.h @@ -83,6 +83,9 @@ __BEGIN_DECLS malloc, as well as everything in level 2. */ /* #define KOS_DEBUG 3 */ +#ifndef KOS_DEBUG +#define KOS_DEBUG 0 +#endif #if KOS_DEBUG >= 1 #define MALLOC_DEBUG 1 @@ -101,13 +104,19 @@ __BEGIN_DECLS #endif /** \brief The maximum number of cd files that can be open at a time. */ +#ifndef FS_CD_MAX_FILES #define FS_CD_MAX_FILES 8 +#endif /** \brief The maximum number of romdisk files that can be open at a time. */ +#ifndef FS_ROMDISK_MAX_FILES #define FS_ROMDISK_MAX_FILES 16 +#endif /** \brief The maximum number of ramdisk files that can be open at a time. */ +#ifndef FS_RAMDISK_MAX_FILES #define FS_RAMDISK_MAX_FILES 8 +#endif __END_DECLS diff --git a/kernel/arch/dreamcast/hardware/pvr/pvr_mem.c b/kernel/arch/dreamcast/hardware/pvr/pvr_mem.c index 56c9162..7207581 100644 --- a/kernel/arch/dreamcast/hardware/pvr/pvr_mem.c +++ b/kernel/arch/dreamcast/hardware/pvr/pvr_mem.c @@ -58,8 +58,9 @@ static LIST_HEAD(memctl_list, memctl) block_list; /* PVR RAM base; NULL is considered invalid */ static pvr_ptr_t pvr_mem_base = NULL; -#define CHECK_MEM_BASE assert_msg(pvr_mem_base != NULL, \ - "pvr_mem_* used, but PVR hasn't been initialized yet") +#define CHECK_MEM_BASE \ + assert_msg(pvr_mem_base != NULL, \ + "pvr_mem_* used, but PVR hasn't been initialized yet") /* Used in pvr_mem_core.c */ void * pvr_int_sbrk(size_t amt) { @@ -94,7 +95,8 @@ pvr_ptr_t pvr_mem_malloc(size_t size) { rv32 = (uint32)pvr_int_malloc(size); assert_msg((rv32 & 0x1f) == 0, - "dlmalloc's alignment is broken; please make a bug report"); + "dlmalloc's alignment is broken; " + "please make a bug report"); #ifdef PVR_KM_DBG ctl = malloc(sizeof(memctl_t)); @@ -106,7 +108,7 @@ pvr_ptr_t pvr_mem_malloc(size_t size) { #endif /* PVR_KM_DBG */ #ifdef PVR_KM_DBG_VERBOSE - printf("Thread %d/%08lx allocated %d bytes at %08lx\n", + printf("Thread %d/%08lx allocated %lu bytes at %08lx\n", ctl->thread, ctl->addr, ctl->size, rv32); #endif @@ -141,7 +143,9 @@ void pvr_mem_free(pvr_ptr_t chunk) { } if(!found) { - dbglog(DBG_ERROR, "pvr_mem_free: trying to free non-alloc'd block %08lx (called from %d/%08lx\n", + dbglog(DBG_ERROR, + "pvr_mem_free: trying to free non-alloc'd block " + "%08lx (called from %d/%08lx\n", (uint32)chunk, thd_current->tid, ra); } @@ -157,8 +161,10 @@ void pvr_mem_print_list(void) { printf("pvr_mem_print_list block list:\n"); LIST_FOREACH(ctl, &block_list, list) { - printf(" unfreed block at %08lx size %d, allocated by thread %d/%08lx\n", - ctl->block, ctl->size, ctl->thread, ctl->addr); + printf(" unfreed block at %08lx size %lu, " + "allocated by thread %d/%08lx\n", + (unsigned long)ctl->block, ctl->size, + ctl->thread, (unsigned long)ctl->addr); } printf("pvr_mem_print_list end block list\n"); #endif /* PVR_KM_DBG */ @@ -175,7 +181,8 @@ static uint32 pvr_mem_available_int(void) { uint32 pvr_mem_available(void) { CHECK_MEM_BASE; - return pvr_mem_available_int() + (PVR_RAM_INT_TOP - (uint32)pvr_mem_base); + return pvr_mem_available_int() + + (PVR_RAM_INT_TOP - (uint32)pvr_mem_base); } /* Reset the memory pool, equivalent to freeing all textures currently diff --git a/kernel/arch/dreamcast/hardware/pvr/pvr_mem_core.c b/kernel/arch/dreamcast/hardware/pvr/pvr_mem_core.c index fcc449b..6859b09 100644 --- a/kernel/arch/dreamcast/hardware/pvr/pvr_mem_core.c +++ b/kernel/arch/dreamcast/hardware/pvr/pvr_mem_core.c @@ -1333,7 +1333,7 @@ static void do_check_malloc_state(void) { max_fast_bin = fastbin_index(av->max_fast); - for(i = 0; i < NFASTBINS; ++i) { + for(i = 0; i < (int)NFASTBINS; ++i) { p = av->fastbins[i]; /* all bins past max_fast are empty */ @@ -1345,7 +1345,7 @@ static void do_check_malloc_state(void) { do_check_inuse_chunk(p); total += chunksize(p); /* chunk belongs in this bin */ - assert(fastbin_index(chunksize(p)) == i); + assert(fastbin_index(chunksize(p)) == (unsigned)i); p = p->fd; } } @@ -1379,7 +1379,7 @@ static void do_check_malloc_state(void) { if(i >= 2) { /* chunk belongs in bin */ idx = bin_index(size); - assert(idx == i); + assert(idx == (unsigned)i); /* lists are sorted */ assert(p->bk == b || (unsigned long)chunksize(p->bk) >= (unsigned long)chunksize(p)); diff --git a/kernel/libc/koslib/malloc.c b/kernel/libc/koslib/malloc.c index c4e1f15..7ed6233 100644 --- a/kernel/libc/koslib/malloc.c +++ b/kernel/libc/koslib/malloc.c @@ -1719,7 +1719,7 @@ Void_t* public_mALLOc(size_t bytes) { m = (void *)(nt1 + BUFFER_SIZE / 4); #ifdef KM_DBG_VERBOSE - printf("Thread %d/%08lx allocated %d bytes at %08lx\n", + printf("Thread %d/%08lx allocated %lu bytes at %08lx\n", ctl->thread, ctl->addr, ctl->size, (uint32)m); #endif @@ -2070,7 +2070,7 @@ Void_t* public_mEMALIGn(size_t alignment, size_t bytes) { assert(!((uint32)m % alignment)); #ifdef KM_DBG_VERBOSE - printf("Thread %d/%08lx memalign allocated %d bytes at %08lx\n", + printf("Thread %d/%08lx memalign allocated %lu bytes at %08lx\n", ctl->thread, ctl->addr, ctl->size, (uint32)m); #endif @@ -2145,7 +2145,7 @@ Void_t* public_cALLOc(size_t n, size_t elem_size) { memset(m, 0, bytes); #ifdef KM_DBG_VERBOSE - printf("Thread %d/%08lx calloc allocated %d bytes at %08lx\n", + printf("Thread %d/%08lx calloc allocated %lu bytes at %08lx\n", ctl->thread, ctl->addr, ctl->size, (uint32)m); #endif hooks/post-receive -- A pseudo Operating System for the Dreamcast. |