From: falcovorbis <fal...@us...> - 2024-05-10 18:10:40
|
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 9a1358bc2e4636d1333b52160fdbef5b41131d02 (commit) from 8493f97e5570ce1fcb5c9a16a8fab466e034b339 (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 9a1358bc2e4636d1333b52160fdbef5b41131d02 Author: Paul Cercueil <pa...@cr...> Date: Fri May 10 20:10:07 2024 +0200 Avoid conditionally-compiled code & fix NAOMI build (#566) * Avoid conditionally-compiled code Conditionally-compiled code (wrapped by #ifdef/#ifndef guards) is problematic; because it is very difficult to compile-test all possible combinations of the various flags verified by the guard macros. Instead, evaluate compile-time constants, which will cause the compiler to compile the exact same code independently of the configuration, which means if it compiles for one configuration, it will compile for all configurations. The compiler will then be smart enough to garbage-collect dead code, dropping everything not included in the current configuration. Signed-off-by: Paul Cercueil <pa...@cr...> * dc: Call cdrom_shutdown() only on Dreamcast The NAOMI has no CD-ROM player. Signed-off-by: Paul Cercueil <pa...@cr...> --------- Signed-off-by: Paul Cercueil <pa...@cr...> ----------------------------------------------------------------------- Summary of changes: include/kos/platform.h | 28 +++++++++++++++++++++ kernel/arch/dreamcast/hardware/hardware.c | 25 ++++++++----------- kernel/arch/dreamcast/hardware/maple/vmu.c | 10 +++----- kernel/arch/dreamcast/hardware/video.c | 13 +++++----- kernel/arch/dreamcast/kernel/init.c | 40 ++++++++++++------------------ 5 files changed, 66 insertions(+), 50 deletions(-) create mode 100644 include/kos/platform.h diff --git a/include/kos/platform.h b/include/kos/platform.h new file mode 100644 index 00000000..4548ae26 --- /dev/null +++ b/include/kos/platform.h @@ -0,0 +1,28 @@ +/* KallistiOS ##version## + + include/kos/platform.h + Copyright (C) 2024 Paul Cercueil + +*/ + +/** \file kos/platform.h + \brief Platform detection macros. + \author Paul Cercueil +*/ + +#ifndef __KOS_PLATFORM_H +#define __KOS_PLATFORM_H + +#ifdef __NAOMI__ +# define KOS_PLATFORM_IS_NAOMI 1 +#else +# define KOS_PLATFORM_IS_NAOMI 0 +#endif + +#ifdef __DREAMCAST__ +# define KOS_PLATFORM_IS_DREAMCAST 1 +#else +# define KOS_PLATFORM_IS_DREAMCAST 0 +#endif + +#endif /* __KOS_PLATFORM_H */ diff --git a/kernel/arch/dreamcast/hardware/hardware.c b/kernel/arch/dreamcast/hardware/hardware.c index a91a0ba6..d97130f8 100644 --- a/kernel/arch/dreamcast/hardware/hardware.c +++ b/kernel/arch/dreamcast/hardware/hardware.c @@ -8,6 +8,7 @@ #include <stdbool.h> #include <arch/arch.h> #include <kos/init.h> +#include <kos/platform.h> #include <dc/spu.h> #include <dc/video.h> #include <dc/cdrom.h> @@ -57,21 +58,18 @@ void bba_la_shutdown(void) { KOS_INIT_FLAG_WEAK(bba_la_init, false); KOS_INIT_FLAG_WEAK(bba_la_shutdown, false); KOS_INIT_FLAG_WEAK(maple_init, true); - -#ifndef _arch_sub_naomi KOS_INIT_FLAG_WEAK(cdrom_init, true); KOS_INIT_FLAG_WEAK(cdrom_shutdown, true); -#endif int hardware_periph_init(void) { /* Init sound */ spu_init(); g2_dma_init(); -#ifndef _arch_sub_naomi - /* Init CD-ROM.. NOTE: NO GD-ROM SUPPORT. ONLY CDs/CDRs. */ - KOS_INIT_FLAG_CALL(cdrom_init); -#endif + if (!KOS_PLATFORM_IS_NAOMI) { + /* Init CD-ROM.. NOTE: NO GD-ROM SUPPORT. ONLY CDs/CDRs. */ + KOS_INIT_FLAG_CALL(cdrom_init); + } /* Setup maple bus */ KOS_INIT_FLAG_CALL(maple_init); @@ -79,9 +77,8 @@ int hardware_periph_init(void) { /* Init video */ vid_init(DEFAULT_VID_MODE, DEFAULT_PIXEL_MODE); -#ifndef _arch_sub_naomi - KOS_INIT_FLAG_CALL(bba_la_init); -#endif + if (!KOS_PLATFORM_IS_NAOMI) + KOS_INIT_FLAG_CALL(bba_la_init); initted = 2; @@ -93,11 +90,11 @@ KOS_INIT_FLAG_WEAK(maple_shutdown, true); void hardware_shutdown(void) { switch(initted) { case 2: -#ifndef _arch_sub_naomi - KOS_INIT_FLAG_CALL(bba_la_shutdown); -#endif + if (!KOS_PLATFORM_IS_NAOMI) + KOS_INIT_FLAG_CALL(bba_la_shutdown); KOS_INIT_FLAG_CALL(maple_shutdown); - KOS_INIT_FLAG_CALL(cdrom_shutdown); + if (!KOS_PLATFORM_IS_NAOMI) + KOS_INIT_FLAG_CALL(cdrom_shutdown); g2_dma_shutdown(); spu_shutdown(); vid_shutdown(); diff --git a/kernel/arch/dreamcast/hardware/maple/vmu.c b/kernel/arch/dreamcast/hardware/maple/vmu.c index d1854fcb..aa984531 100644 --- a/kernel/arch/dreamcast/hardware/maple/vmu.c +++ b/kernel/arch/dreamcast/hardware/maple/vmu.c @@ -18,6 +18,7 @@ #include <stdio.h> #include <kos/thread.h> #include <kos/genwait.h> +#include <kos/platform.h> #include <dc/maple.h> #include <dc/maple/vmu.h> #include <dc/math.h> @@ -237,9 +238,11 @@ int vmu_set_custom_color(maple_device_t *dev, uint8_t red, uint8_t green, uint8_ for icon_shape are listed in the biosfont.h and start with BFONT_ICON_VMUICON. */ int vmu_set_icon_shape(maple_device_t *dev, uint8_t icon_shape) { -#ifndef _arch_sub_naomi vmu_root_t root; + if (KOS_PLATFORM_IS_NAOMI) + return -1; + if(icon_shape < BFONT_ICON_VMUICON || icon_shape > BFONT_ICON_EMBROIDERY) return -1; @@ -255,11 +258,6 @@ int vmu_set_icon_shape(maple_device_t *dev, uint8_t icon_shape) { return -1; return 0; -#else - (void)dev; - (void)icon_shape; - return -1; -#endif } /* These interfaces will probably change eventually, but for now they diff --git a/kernel/arch/dreamcast/hardware/video.c b/kernel/arch/dreamcast/hardware/video.c index 73551fed..6cae86f9 100644 --- a/kernel/arch/dreamcast/hardware/video.c +++ b/kernel/arch/dreamcast/hardware/video.c @@ -10,6 +10,7 @@ #include <dc/video.h> #include <dc/pvr.h> #include <dc/sq.h> +#include <kos/platform.h> #include <string.h> #include <stdio.h> @@ -210,18 +211,18 @@ uint32_t *vram_l; [This is the old KOS function by Megan.] */ int8_t vid_check_cable(void) { -#ifndef _arch_sub_naomi volatile uint32_t * porta = (vuint32 *)0xff80002c; + if (KOS_PLATFORM_IS_NAOMI) { + /* XXXX: This still needs to be figured out for NAOMI. For now, assume + VGA mode. */ + return CT_VGA; + } + *porta = (*porta & 0xfff0ffff) | 0x000a0000; /* Read port8 and port9 */ return (*((volatile uint16_t*)(porta + 1)) >> 8) & 3; -#else - /* XXXX: This still needs to be figured out for NAOMI. For now, assume - VGA mode. */ - return CT_VGA; -#endif } /*-----------------------------------------------------------------------------*/ diff --git a/kernel/arch/dreamcast/kernel/init.c b/kernel/arch/dreamcast/kernel/init.c index 45d391d9..e28dbb62 100644 --- a/kernel/arch/dreamcast/kernel/init.c +++ b/kernel/arch/dreamcast/kernel/init.c @@ -12,6 +12,7 @@ #include <stdlib.h> #include <kos/dbgio.h> #include <kos/init.h> +#include <kos/platform.h> #include <arch/arch.h> #include <arch/irq.h> #include <arch/memory.h> @@ -42,11 +43,9 @@ void (*__kos_init_early_fn)(void) __attribute__((weak,section(".data"))) = NULL; int main(int argc, char **argv); uint32 _fs_dclsocket_get_ip(void); -#ifdef _arch_sub_naomi #define SAR2 ((vuint32 *)0xFFA00020) #define CHCR2 ((vuint32 *)0xFFA0002C) #define DMAOR ((vuint32 *)0xFFA00040) -#endif /* We have to put this here so we can include plat-specific devices */ dbgio_handler_t * dbgio_handlers[] = { @@ -125,11 +124,8 @@ KOS_INIT_FLAG_WEAK(fs_romdisk_mount_builtin, false); KOS_INIT_FLAG_WEAK(fs_romdisk_mount_builtin_legacy, false); KOS_INIT_FLAG_WEAK(vmu_fs_init, true); KOS_INIT_FLAG_WEAK(vmu_fs_shutdown, true); - -#ifndef _arch_sub_naomi KOS_INIT_FLAG_WEAK(fs_iso9660_init, true); KOS_INIT_FLAG_WEAK(fs_iso9660_shutdown, true); -#endif void dcload_init(void) { if (*DCLOADMAGICADDR == DCLOADMAGICVALUE) { @@ -209,9 +205,8 @@ int __weak arch_auto_init(void) { KOS_INIT_FLAG_CALL(dcload_init); -#ifndef _arch_sub_naomi - KOS_INIT_FLAG_CALL(fs_iso9660_init); -#endif + if (!KOS_PLATFORM_IS_NAOMI) + KOS_INIT_FLAG_CALL(fs_iso9660_init); KOS_INIT_FLAG_CALL(vmu_fs_init); @@ -224,18 +219,16 @@ int __weak arch_auto_init(void) { KOS_INIT_FLAG_CALL(maple_wait_scan); /* Wait for the maple scan to complete */ } -#ifndef _arch_sub_naomi - KOS_INIT_FLAG_CALL(arch_init_net); -#endif + if (!KOS_PLATFORM_IS_NAOMI) + KOS_INIT_FLAG_CALL(arch_init_net); return 0; } void __weak arch_auto_shutdown(void) { KOS_INIT_FLAG_CALL(fs_dclsocket_shutdown); -#ifndef _arch_sub_naomi - KOS_INIT_FLAG_CALL(net_shutdown); -#endif + if (!KOS_PLATFORM_IS_NAOMI) + KOS_INIT_FLAG_CALL(net_shutdown); irq_disable(); snd_shutdown(); @@ -245,9 +238,8 @@ void __weak arch_auto_shutdown(void) { library_shutdown(); KOS_INIT_FLAG_CALL(fs_dcload_shutdown); KOS_INIT_FLAG_CALL(vmu_fs_shutdown); -#ifndef _arch_sub_naomi - KOS_INIT_FLAG_CALL(fs_iso9660_shutdown); -#endif + if (!KOS_PLATFORM_IS_NAOMI) + KOS_INIT_FLAG_CALL(fs_iso9660_shutdown); #if defined(__NEWLIB__) && !(__NEWLIB__ < 2 && __NEWLIB_MINOR__ < 4) fs_rnd_shutdown(); #endif @@ -267,13 +259,13 @@ void arch_main(void) { uint8 *bss_end = (uint8 *)(&end); int rv; -#ifdef _arch_sub_naomi - /* Ugh. I'm really not sure why we have to set up these DMA registers this - way on boot, but failing to do so breaks maple... */ - *SAR2 = 0; - *CHCR2 = 0x1201; - *DMAOR = 0x8201; -#endif /* _arch_sub_naomi */ + if (KOS_PLATFORM_IS_NAOMI) { + /* Ugh. I'm really not sure why we have to set up these DMA registers this + way on boot, but failing to do so breaks maple... */ + *SAR2 = 0; + *CHCR2 = 0x1201; + *DMAOR = 0x8201; + } /* Ensure the WDT is not enabled from a previous session */ wdt_disable(); hooks/post-receive -- A pseudo Operating System for the Dreamcast. |