|
From: darcagn <da...@us...> - 2024-06-27 04:46:15
|
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 f3e270e97b3fb71da3c7b2da2d9b6fd9965b6813 (commit)
via 2da0522fd5b03419d93de29822ddb052e9ba2bb4 (commit)
via 420be8d196d4f96bf08fc50c65b77b70725cf747 (commit)
via 1279aa2ab78042ab51c71845e4b57f37761e0cff (commit)
via 1b813ec79f479ec47dbffef8632ef81fb549f52a (commit)
via f34c9f30ac28fdae651da16cbc3618192f96626b (commit)
via 6d4b1146be8f2813fa84f0197ae359f4f649724d (commit)
via d035be9fd2f2d06e8bdf263e06bb6ff5966f424e (commit)
via c64b160e296fe925d2dc9eee00d2626e03133638 (commit)
via 8514b10c11b01ec6c8b63e0136ce91c2fa53c1c4 (commit)
from 738b3274a85bab21a3ea81489ec2fe5ebb75158a (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 f3e270e97b3fb71da3c7b2da2d9b6fd9965b6813
Author: darcagn <da...@pr...>
Date: Wed Jun 26 22:45:30 2024 -0600
dc-chain: Update 12.x profile to 12.4 (#640)
commit 2da0522fd5b03419d93de29822ddb052e9ba2bb4
Author: Paul Cercueil <pa...@cr...>
Date: Thu Jun 27 05:12:50 2024 +0200
Create romdisks with bin2c instead of bin2o (#641)
* bin2c: Fix invalid generated code
The generated C was not valid as it was missing a semicolon on one of
its lines.
Signed-off-by: Paul Cercueil <pa...@cr...>
* romdisks: Constify __kos_romdisk
The romdisk data isn't supposed to be modified, so modify the
__kos_romdisk pointer to add the "const" specifier.
Signed-off-by: Paul Cercueil <pa...@cr...>
* romdisks: Create romdisks using bin2c instead of bin2o
bin2o creates a romdisk.o from a romdisk.img using the linker. On the
other hand, bin2c creates a C file with a char array that contains the
whole romdisk.img.
The problem with the first approach is that the romdisk.o generated has
technically not been compiled. This is a problem when building a project
with LTO, as the linker will refuse to perform whole-program
optimizations if some of the object files haven't been compiled with
LTO.
It then issues the following warning:
ld: warning: incremental linking of LTO and non-LTO objects; using
-flinker-output=nolto-rel which will bypass whole program optimization
Creating romdisks with bin2c then allows the linker to perform
whole-program optimizations.
Signed-off-by: Paul Cercueil <pa...@cr...>
commit 420be8d196d4f96bf08fc50c65b77b70725cf747
Author: Paul Cercueil <pa...@cr...>
Date: Thu Jun 27 05:10:12 2024 +0200
fs_dcload: Set errno on error in dcload_stat() (#642)
The fs_dcload code doesn't seem to set errno anywhere. It means that on
error, the calling code will get whatever errno value was set by
anything that came before it.
In dcload_stat(), if the PC communication could not be done, set errno
to ENOENT - "No such file or directory". This will cause the upper
layers to not attempt to open the directory.
Signed-off-by: Paul Cercueil <pa...@cr...>
commit 1279aa2ab78042ab51c71845e4b57f37761e0cff
Merge: f34c9f30 1b813ec7
Author: Lawrence Sebald <ljs...@us...>
Date: Wed Jun 26 23:08:01 2024 -0400
Merge pull request #643 from pcercuei/fix-mutexes
mutex: Fix mutexes not mutexing
commit 1b813ec79f479ec47dbffef8632ef81fb549f52a
Author: Paul Cercueil <pa...@cr...>
Date: Wed Jun 26 20:22:25 2024 +0200
mutex: Fix mutexes not mutexing
Imagine a scenario where thread #0 holds a lock. Thread #1 attempts to
lock it, doesn't get it, and is put to sleep with genwait_wait().
Thread #0 wakes up, releases the lock, which triggers
genwait_wake_one(), placing thread #1 back into the running queue.
However, before leaving hand, thread #0 gets the lock once again.
Thread #1 would then wake up, and incorrectly set itself as the lock
owner, without checking first that the lock was free.
Address this issue by checking that the lock is indeed free after being
awaken, and if not, go back to sleep.
Signed-off-by: Paul Cercueil <pa...@cr...>
commit f34c9f30ac28fdae651da16cbc3618192f96626b
Author: Paul Cercueil <pa...@cr...>
Date: Wed Jun 26 07:34:15 2024 +0200
Some CMake stuff (#624)
* CMake: Set CMAKE_SIZEOF_VOID_P
For some reason this variable is expected to be set in the
GNUInstallDirs CMake module, which is pretty common.
Signed-off-by: Paul Cercueil <pa...@cr...>
* CMake: Don't remove intermediate object
Removing the temporary object means it will have to be re-generated
from romdisk.img every time a new build is done.
Signed-off-by: Paul Cercueil <pa...@cr...>
---------
Signed-off-by: Paul Cercueil <pa...@cr...>
Co-authored-by: Falco Girgis <gyr...@gm...>
commit 6d4b1146be8f2813fa84f0197ae359f4f649724d
Author: darcagn <da...@pr...>
Date: Fri Jun 21 12:21:56 2024 -0600
dc-chain: Remove default-jit patch from rustc-dev profile as it has now been upstreamed (#639)
commit d035be9fd2f2d06e8bdf263e06bb6ff5966f424e
Author: Andy Barajas <and...@gm...>
Date: Tue Jun 18 23:38:23 2024 -0700
Update startup (#621)
* Update crt1.o when startup.o is rebuilt
* Add hyphen
* Update kernel/arch/dreamcast/kernel/Makefile
Co-authored-by: darcagn <da...@pr...>
commit c64b160e296fe925d2dc9eee00d2626e03133638
Author: Andy Barajas <and...@gm...>
Date: Mon Jun 17 22:45:59 2024 -0700
Fix texturing and closing opened files (#607)
* Fix texturing and closing opened files
commit 8514b10c11b01ec6c8b63e0136ce91c2fa53c1c4
Author: Falco Girgis <gyr...@gm...>
Date: Tue Jun 18 00:41:22 2024 -0500
Thread bugfixes: Stack ownership, Genwait object release upon death (#622)
* Thread bugfixes: stack ownership, genwait on death
1) Stack ownership
- We were previously creating a thread for the main kernel thread
using thd_create() which gave it a duplicated, default-initialized
32KB stack rather than having it utilize its static 64KB stack range.
- To utilize its own stack, we have to internally maintain whether
or not we are the owner of the stack (ie we allocated it), so that
we know not to free it.
- This model also fixes issues created by supporting POSIX threads
via the pthread API which assign their own stacks.
- The new model/rule: you allocate and provide your own stack, you
clean up your own stack too!
2) Genwait cleanup upon thread death
- We were properly notifying other threads waiting upon the dying
thread that they should wake up.
- We were NOT properly cancelling any pending genwait objects that the
dying thread was awaiting! So it could potentially later try to
wake up + notify a dead thread when the object becomes available.
- We now remove the thread's genwait object (if it has one) upon its
death.
-----------------------------------------------------------------------
Summary of changes:
Makefile.rules | 5 +-
doc/CHANGELOG | 3 +
examples/dreamcast/cpp/gltest/gltest.cpp | 124 ++++++++-------------
examples/dreamcast/gldc/basic/gl/pvr-texture.c | 1 +
examples/dreamcast/gldc/nehe/nehe06/pvr-texture.c | 1 +
examples/dreamcast/gldc/nehe/nehe08/pvr-texture.c | 1 +
examples/dreamcast/gldc/nehe/nehe09/pvr-texture.c | 1 +
examples/dreamcast/gldc/nehe/nehe16/pvr-texture.c | 1 +
examples/dreamcast/png/example.c | 2 +-
examples/dreamcast/video/screenshot/screenshot.c | 3 +-
include/kos/init.h | 4 +-
include/kos/thread.h | 1 +
kernel/arch/dreamcast/fs/fs_dcload.c | 1 +
kernel/arch/dreamcast/include/arch/arch.h | 3 +
kernel/arch/dreamcast/kernel/Makefile | 3 +
kernel/arch/dreamcast/kernel/mm.c | 2 +-
kernel/romdisk/romdiskbase.c | 4 +-
kernel/thread/mutex.c | 35 ++++--
kernel/thread/thread.c | 40 +++++--
utils/bin2c/bin2c.c | 2 +-
utils/cmake/dreamcast.cmake | 17 ++-
utils/cmake/dreamcast.toolchain.cmake | 1 +
utils/dc-chain/Makefile.default.cfg | 2 +-
.../{gcc-12.3.0-kos.diff => gcc-12.4.0-kos.diff} | 58 +++++-----
utils/dc-chain/patches/gcc-rustc-kos.diff | 16 ---
.../patches/{ => historical}/gcc-12.3.0-kos.diff | 0
.../{profile.12.3.0.mk => profile.12.4.0.mk} | 2 +-
utils/dc-chain/profiles/profile.rustc-dev.mk | 2 +-
28 files changed, 171 insertions(+), 164 deletions(-)
copy utils/dc-chain/patches/{gcc-12.3.0-kos.diff => gcc-12.4.0-kos.diff} (73%)
rename utils/dc-chain/patches/{ => historical}/gcc-12.3.0-kos.diff (100%)
rename utils/dc-chain/profiles/{profile.12.3.0.mk => profile.12.4.0.mk} (98%)
diff --git a/Makefile.rules b/Makefile.rules
index 329413f3..487b9028 100644
--- a/Makefile.rules
+++ b/Makefile.rules
@@ -71,9 +71,10 @@ romdisk.img:
$(KOS_GENROMFS) -f romdisk.img -d $(KOS_ROMDISK_DIR) -v -x .svn -x .keepme
romdisk.o: romdisk.img
- $(KOS_BASE)/utils/bin2o/bin2o romdisk.img romdisk romdisk_tmp.o
+ $(KOS_BASE)/utils/bin2c/bin2c romdisk.img romdisk_tmp.c romdisk
+ $(KOS_CC) $(KOS_CFLAGS) -o romdisk_tmp.o -c romdisk_tmp.c
$(KOS_CC) -o romdisk.o -r romdisk_tmp.o $(KOS_LIB_PATHS) -Wl,--whole-archive -lromdiskbase
- rm romdisk_tmp.o
+ rm romdisk_tmp.c romdisk_tmp.o
endif
# Define KOS_GCCVER_MIN in your Makefile if you want to enforce a minimum GCC version.
diff --git a/doc/CHANGELOG b/doc/CHANGELOG
index d7e1e4c5..0755a8e5 100644
--- a/doc/CHANGELOG
+++ b/doc/CHANGELOG
@@ -229,6 +229,9 @@ KallistiOS version 2.1.0 -----------------------------------------------
- *** Added support for one-shot timers [PC]
- DC Use one-shot timers for timeout and a proper polling mechanism in modem [PC]
- *** Added full support for <time.h> additions from C23 standard. [FG]
+- *** Fixes mutexes not working properly [PC]
+- DC fs_dcload: Set errno on error in dcload_stat() [PC]
+- *** Create romdisks with bin2c instead of bin2o [PC]
KallistiOS version 2.0.0 -----------------------------------------------
- DC Broadband Adapter driver fixes [Megan Potter == MP]
diff --git a/examples/dreamcast/cpp/gltest/gltest.cpp b/examples/dreamcast/cpp/gltest/gltest.cpp
index 56f167c3..0dc6d9ed 100644
--- a/examples/dreamcast/cpp/gltest/gltest.cpp
+++ b/examples/dreamcast/cpp/gltest/gltest.cpp
@@ -11,6 +11,8 @@
#include <GL/glext.h>
#include <GL/glkos.h>
+#define PVR_HDR_SIZE 0x20
+
/*
This is a really simple KallistiGL example. It shows off several things:
@@ -157,93 +159,65 @@ public:
/* Load a PVR texture using glTexImage2D */
void loadtxr(const char *fname, GLuint *txr) {
-#define PVR_HDR_SIZE 0x20
FILE *tex = NULL;
unsigned char *texBuf;
+ uint8_t HDR[PVR_HDR_SIZE];
unsigned int texSize;
-
+
tex = fopen(fname, "rb");
if(tex == NULL) {
- printf("FILE READ ERROR: %s\n", fname);
-
+ fprintf(stderr, "FILE READ ERROR: %s\n", fname);
while(1);
}
fseek(tex, 0, SEEK_END);
- texSize = ftell(tex);
-
- texBuf = (unsigned char*)malloc(texSize);
+ texSize = ftell(tex) - PVR_HDR_SIZE;
fseek(tex, 0, SEEK_SET);
- fread(texBuf, 1, texSize, tex);
- fclose(tex);
-
- int texW = texBuf[PVR_HDR_SIZE - 4] | texBuf[PVR_HDR_SIZE - 3] << 8;
- int texH = texBuf[PVR_HDR_SIZE - 2] | texBuf[PVR_HDR_SIZE - 1] << 8;
- int texFormat, texColor;
-
- switch((unsigned int)texBuf[PVR_HDR_SIZE - 8]) {
- case 0x00:
- texColor = PVR_TXRFMT_ARGB1555;
- break; //(bilevel translucent alpha 0,255)
-
- case 0x01:
- texColor = PVR_TXRFMT_RGB565;
- break; //(non translucent RGB565 )
-
- case 0x02:
- texColor = PVR_TXRFMT_ARGB4444;
- break; //(translucent alpha 0-255)
-
- case 0x03:
- texColor = PVR_TXRFMT_YUV422;
- break; //(non translucent UYVY )
-
- case 0x04:
- texColor = PVR_TXRFMT_BUMP;
- break; //(special bump-mapping format)
-
- case 0x05:
- texColor = PVR_TXRFMT_PAL4BPP;
- break; //(4-bit palleted texture)
- case 0x06:
- texColor = PVR_TXRFMT_PAL8BPP;
- break; //(8-bit palleted texture)
+ /* Read in the PVR texture file header */
+ fread(HDR, 1, PVR_HDR_SIZE, tex);
- default:
- texColor = PVR_TXRFMT_RGB565;
- break;
- }
-
- switch((unsigned int)texBuf[PVR_HDR_SIZE - 7]) {
- case 0x01:
- texFormat = PVR_TXRFMT_TWIDDLED;
- break;//SQUARE TWIDDLED
-
- case 0x03:
- texFormat = PVR_TXRFMT_VQ_ENABLE;
- break;//VQ TWIDDLED
-
- case 0x09:
- texFormat = PVR_TXRFMT_NONTWIDDLED;
- break;//RECTANGLE
-
- case 0x0B:
- texFormat = PVR_TXRFMT_STRIDE | PVR_TXRFMT_NONTWIDDLED;
- break;//RECTANGULAR STRIDE
-
- case 0x0D:
- texFormat = PVR_TXRFMT_TWIDDLED;
- break;//RECTANGULAR TWIDDLED
-
- case 0x10:
- texFormat = PVR_TXRFMT_VQ_ENABLE | PVR_TXRFMT_NONTWIDDLED;
- break;//SMALL VQ
+ texBuf = (unsigned char*)malloc(texSize);
+ fread(texBuf, 1, texSize, tex); /* Read in the PVR texture data */
+ fclose(tex);
- default:
- texFormat = PVR_TXRFMT_NONE;
- break;
+ int texW = HDR[PVR_HDR_SIZE - 4] | HDR[PVR_HDR_SIZE - 3] << 8;
+ int texH = HDR[PVR_HDR_SIZE - 2] | HDR[PVR_HDR_SIZE - 1] << 8;
+ uint32_t color = (uint32_t)HDR[PVR_HDR_SIZE - 8];
+ uint32_t format = (uint32_t)HDR[PVR_HDR_SIZE - 7];
+ bool twiddled = format == 0x01;
+ bool compressed = (format == 0x10 || format == 0x03);
+ int texFormat = GL_UNSIGNED_SHORT_5_6_5;
+
+ if(compressed) {
+ if(twiddled) {
+ switch(color) {
+ case 0x0:
+ texFormat = GL_COMPRESSED_ARGB_1555_VQ_TWID_KOS;
+ break;
+ case 0x01:
+ texFormat = GL_COMPRESSED_RGB_565_VQ_TWID_KOS;
+ break;
+ case 0x02:
+ texFormat = GL_COMPRESSED_ARGB_4444_VQ_TWID_KOS;
+ break;
+ }
+ } else {
+ switch(color) {
+ case 0:
+ texFormat = GL_COMPRESSED_ARGB_1555_VQ_KOS;
+ break;
+ case 1:
+ texFormat = GL_COMPRESSED_RGB_565_VQ_KOS;
+ break;
+ case 2:
+ texFormat = GL_COMPRESSED_ARGB_4444_VQ_KOS;
+ break;
+ }
+ }
+ } else if(color == 1) {
+ texFormat = GL_UNSIGNED_SHORT_5_6_5;
}
printf("TEXTURE Resolution: %ix%i\n", texW, texH);
@@ -254,7 +228,7 @@ void loadtxr(const char *fname, GLuint *txr) {
if(texFormat & PVR_TXRFMT_VQ_ENABLE)
glCompressedTexImage2D(GL_TEXTURE_2D,
0,
- texFormat | texColor,
+ texFormat,
texW,
texH,
0,
@@ -267,7 +241,7 @@ void loadtxr(const char *fname, GLuint *txr) {
texW, texH,
0,
GL_RGB,
- texFormat | texColor,
+ texFormat,
texBuf);
}
diff --git a/examples/dreamcast/gldc/basic/gl/pvr-texture.c b/examples/dreamcast/gldc/basic/gl/pvr-texture.c
index 05c5af77..829ba721 100644
--- a/examples/dreamcast/gldc/basic/gl/pvr-texture.c
+++ b/examples/dreamcast/gldc/basic/gl/pvr-texture.c
@@ -85,6 +85,7 @@ GLuint glTextureLoadPVR(char *fname, unsigned char isMipMapped, unsigned char gl
TEX0 = malloc(texSize);
fread(TEX0, 1, texSize, tex); /* Read in the PVR texture data */
+ fclose(tex);
/* Generate and bind a texture as normal for Open GL */
glGenTextures(1, &texID);
diff --git a/examples/dreamcast/gldc/nehe/nehe06/pvr-texture.c b/examples/dreamcast/gldc/nehe/nehe06/pvr-texture.c
index 05c5af77..829ba721 100644
--- a/examples/dreamcast/gldc/nehe/nehe06/pvr-texture.c
+++ b/examples/dreamcast/gldc/nehe/nehe06/pvr-texture.c
@@ -85,6 +85,7 @@ GLuint glTextureLoadPVR(char *fname, unsigned char isMipMapped, unsigned char gl
TEX0 = malloc(texSize);
fread(TEX0, 1, texSize, tex); /* Read in the PVR texture data */
+ fclose(tex);
/* Generate and bind a texture as normal for Open GL */
glGenTextures(1, &texID);
diff --git a/examples/dreamcast/gldc/nehe/nehe08/pvr-texture.c b/examples/dreamcast/gldc/nehe/nehe08/pvr-texture.c
index 05c5af77..829ba721 100644
--- a/examples/dreamcast/gldc/nehe/nehe08/pvr-texture.c
+++ b/examples/dreamcast/gldc/nehe/nehe08/pvr-texture.c
@@ -85,6 +85,7 @@ GLuint glTextureLoadPVR(char *fname, unsigned char isMipMapped, unsigned char gl
TEX0 = malloc(texSize);
fread(TEX0, 1, texSize, tex); /* Read in the PVR texture data */
+ fclose(tex);
/* Generate and bind a texture as normal for Open GL */
glGenTextures(1, &texID);
diff --git a/examples/dreamcast/gldc/nehe/nehe09/pvr-texture.c b/examples/dreamcast/gldc/nehe/nehe09/pvr-texture.c
index 05c5af77..829ba721 100644
--- a/examples/dreamcast/gldc/nehe/nehe09/pvr-texture.c
+++ b/examples/dreamcast/gldc/nehe/nehe09/pvr-texture.c
@@ -85,6 +85,7 @@ GLuint glTextureLoadPVR(char *fname, unsigned char isMipMapped, unsigned char gl
TEX0 = malloc(texSize);
fread(TEX0, 1, texSize, tex); /* Read in the PVR texture data */
+ fclose(tex);
/* Generate and bind a texture as normal for Open GL */
glGenTextures(1, &texID);
diff --git a/examples/dreamcast/gldc/nehe/nehe16/pvr-texture.c b/examples/dreamcast/gldc/nehe/nehe16/pvr-texture.c
index 05c5af77..829ba721 100644
--- a/examples/dreamcast/gldc/nehe/nehe16/pvr-texture.c
+++ b/examples/dreamcast/gldc/nehe/nehe16/pvr-texture.c
@@ -85,6 +85,7 @@ GLuint glTextureLoadPVR(char *fname, unsigned char isMipMapped, unsigned char gl
TEX0 = malloc(texSize);
fread(TEX0, 1, texSize, tex); /* Read in the PVR texture data */
+ fclose(tex);
/* Generate and bind a texture as normal for Open GL */
glGenTextures(1, &texID);
diff --git a/examples/dreamcast/png/example.c b/examples/dreamcast/png/example.c
index e9115610..4b3a9896 100644
--- a/examples/dreamcast/png/example.c
+++ b/examples/dreamcast/png/example.c
@@ -97,7 +97,7 @@ void draw_back(void) {
vert.v = 0.0f;
pvr_prim(&vert, sizeof(vert));
- vert.x = 1.0f;
+ vert.x = 0.0f;
vert.y = 480.0f;
vert.z = 1.0f;
vert.u = 0.0f;
diff --git a/examples/dreamcast/video/screenshot/screenshot.c b/examples/dreamcast/video/screenshot/screenshot.c
index 51074b34..1f77d807 100644
--- a/examples/dreamcast/video/screenshot/screenshot.c
+++ b/examples/dreamcast/video/screenshot/screenshot.c
@@ -90,8 +90,7 @@ int main(int argc, char **argv) {
bfont_draw_str(vram_s + font_height_offset, 640, SHOW_BLACK_BG,
"Press A to take a screen shot");
- /* Without this the bfont wont show on the screen */
- thd_sleep(10);
+ vid_flip(-1);
}
return 0;
diff --git a/include/kos/init.h b/include/kos/init.h
index bb14f069..de199b9e 100644
--- a/include/kos/init.h
+++ b/include/kos/init.h
@@ -96,13 +96,13 @@ extern const uint32_t __kos_init_flags;
/** \brief Deprecated and not useful anymore. */
#define KOS_INIT_ROMDISK(rd) \
- void *__kos_romdisk = (rd); \
+ const void *__kos_romdisk = (rd); \
extern void fs_romdisk_mount_builtin_legacy(void); \
void (*fs_romdisk_mount_builtin_legacy_weak)(void) = fs_romdisk_mount_builtin_legacy
/** \brief Built-in romdisk. Do not modify this directly! */
-extern void * __kos_romdisk;
+extern const void * __kos_romdisk;
/** \brief State that you don't want a romdisk. */
#define KOS_INIT_ROMDISK_NONE NULL
diff --git a/include/kos/thread.h b/include/kos/thread.h
index d8cfba6c..e5c80a3a 100644
--- a/include/kos/thread.h
+++ b/include/kos/thread.h
@@ -131,6 +131,7 @@ LIST_HEAD(ktlist, kthread);
#define THD_USER 1 /**< \brief Thread runs in user mode */
#define THD_QUEUED 2 /**< \brief Thread is in the run queue */
#define THD_DETACHED 4 /**< \brief Thread is detached */
+#define THD_OWNS_STACK 8 /**< \brief Thread manages stack lifetime */
/** @} */
/** \brief Kernel thread flags type */
diff --git a/kernel/arch/dreamcast/fs/fs_dcload.c b/kernel/arch/dreamcast/fs/fs_dcload.c
index a937f125..891e6fa9 100644
--- a/kernel/arch/dreamcast/fs/fs_dcload.c
+++ b/kernel/arch/dreamcast/fs/fs_dcload.c
@@ -397,6 +397,7 @@ static int dcload_stat(vfs_handler_t *vfs, const char *fn, struct stat *rv,
return 0;
}
+ errno = ENOENT;
return -1;
}
diff --git a/kernel/arch/dreamcast/include/arch/arch.h b/kernel/arch/dreamcast/include/arch/arch.h
index 0562fc36..7f19655d 100644
--- a/kernel/arch/dreamcast/include/arch/arch.h
+++ b/kernel/arch/dreamcast/include/arch/arch.h
@@ -67,6 +67,9 @@ extern uint32 _arch_mem_top;
/** \brief Default thread stack size. */
#define THD_STACK_SIZE 32768
+/** \brief Main/kernel thread's stack size. */
+#define THD_KERNEL_STACK_SIZE (64 * 1024)
+
/** \brief Default video mode. */
#define DEFAULT_VID_MODE DM_640x480
diff --git a/kernel/arch/dreamcast/kernel/Makefile b/kernel/arch/dreamcast/kernel/Makefile
index 95db3e42..566efc80 100644
--- a/kernel/arch/dreamcast/kernel/Makefile
+++ b/kernel/arch/dreamcast/kernel/Makefile
@@ -18,9 +18,12 @@ COPYOBJS += uname.o
OBJS = $(COPYOBJS) startup.o
SUBDIRS =
+CRT1_PATH = $(shell $(KOS_CC) $(KOS_CFLAGS) -print-file-name=crt1.o)
+
myall: $(OBJS)
-cp $(COPYOBJS) $(KOS_BASE)/kernel/build/
-rm banner.h authors.h banner.o uname.o
+ -cp startup.o $(CRT1_PATH)
include $(KOS_BASE)/Makefile.prefab
diff --git a/kernel/arch/dreamcast/kernel/mm.c b/kernel/arch/dreamcast/kernel/mm.c
index ebb0a16d..cce8885b 100644
--- a/kernel/arch/dreamcast/kernel/mm.c
+++ b/kernel/arch/dreamcast/kernel/mm.c
@@ -47,7 +47,7 @@ void* mm_sbrk(unsigned long increment) {
sbrk_base = (void *)(increment + (unsigned long)sbrk_base);
- if(((uint32)sbrk_base) >= (_arch_mem_top - 65536)) {
+ if(((uint32)sbrk_base) >= (_arch_mem_top - THD_KERNEL_STACK_SIZE)) {
dbglog(DBG_CRITICAL, "Out of memory. Requested sbrk_base %p, was %p, diff %lu\n",
sbrk_base, base, increment);
sbrk_base = base; /* Restore old value and mark failed */
diff --git a/kernel/romdisk/romdiskbase.c b/kernel/romdisk/romdiskbase.c
index d5f28f51..254e0545 100644
--- a/kernel/romdisk/romdiskbase.c
+++ b/kernel/romdisk/romdiskbase.c
@@ -6,9 +6,9 @@
#include <kos/fs_romdisk.h>
-extern unsigned char romdisk[];
+extern const unsigned char romdisk_data[];
-void *__kos_romdisk = romdisk;
+const void *__kos_romdisk = romdisk_data;
extern void fs_romdisk_mount_builtin(void);
diff --git a/kernel/thread/mutex.c b/kernel/thread/mutex.c
index 14a60bb9..1b38196d 100644
--- a/kernel/thread/mutex.c
+++ b/kernel/thread/mutex.c
@@ -14,6 +14,7 @@
#include <kos/dbglog.h>
#include <arch/irq.h>
+#include <arch/timer.h>
mutex_t *mutex_create(void) {
mutex_t *rv;
@@ -83,6 +84,7 @@ int mutex_lock(mutex_t *m) {
}
int mutex_lock_timed(mutex_t *m, int timeout) {
+ uint64_t deadline = 0;
int old, rv = 0;
if((rv = irq_inside_int())) {
@@ -123,14 +125,31 @@ int mutex_lock_timed(mutex_t *m, int timeout) {
rv = -1;
}
else {
- if(!(rv = genwait_wait(m, timeout ? "mutex_lock_timed" : "mutex_lock",
- timeout, NULL))) {
- m->holder = thd_current;
- m->count = 1;
- }
- else {
- errno = ETIMEDOUT;
- rv = -1;
+ if(timeout)
+ deadline = timer_ms_gettime64() + timeout;
+
+ for(;;) {
+ rv = genwait_wait(m, timeout ? "mutex_lock_timed" : "mutex_lock",
+ timeout, NULL);
+ if(rv < 0) {
+ errno = ETIMEDOUT;
+ break;
+ }
+
+ if(!m->holder) {
+ m->holder = thd_current;
+ m->count = 1;
+ break;
+ }
+
+ if(timeout) {
+ timeout = deadline - timer_ms_gettime64();
+ if(timeout <= 0) {
+ errno = ETIMEDOUT;
+ rv = -1;
+ break;
+ }
+ }
}
}
diff --git a/kernel/thread/thread.c b/kernel/thread/thread.c
index dbe5075d..2ed74191 100644
--- a/kernel/thread/thread.c
+++ b/kernel/thread/thread.c
@@ -407,7 +407,7 @@ static void *thd_create_tls_data(void) {
assert(!((uintptr_t)tcbhead % 8));
/* Since we aren't using either member within it, zero out tcbhead. */
- memset(tcbhead, 0, sizeof(tcbhead_t));
+ memset(tcbhead, 0, sizeof(tcbhead_t));
/* Initialize .TDATA */
if(tdata_size) {
@@ -444,7 +444,7 @@ kthread_t *thd_create_ex(const kthread_attr_t *restrict attr,
tid_t tid;
uint32_t params[4];
int oldirq = 0;
- kthread_attr_t real_attr = { 0, THD_STACK_SIZE, NULL, PRIO_DEFAULT, NULL };
+ kthread_attr_t real_attr = { false, THD_STACK_SIZE, NULL, PRIO_DEFAULT, NULL };
if(attr)
real_attr = *attr;
@@ -475,6 +475,9 @@ kthread_t *thd_create_ex(const kthread_attr_t *restrict attr,
/* Clear out potentially unused stuff */
memset(nt, 0, sizeof(kthread_t));
+ /* Initialize the flags to defaults immediately. */
...<truncated>...
hooks/post-receive
--
A pseudo Operating System for the Dreamcast.
|