SDL patch for optional kernel mode

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Archaemic
Posts: 38
Joined: Sun Mar 18, 2007 7:23 am

SDL patch for optional kernel mode

Post by Archaemic »

As it is, SDL on the PSP is compiled to use kernel mode. So here's a patch to optionally compile it with or without. This is based on a patch by Dark_AleX, just replacing the commented out code with ifdefs.

Code: Select all

--- src/main/psp/SDL_psp_main.c 2007-11-15 23:57:58.000000000 -0500
+++ src/main/psp/SDL_psp_main.c 2007-11-15 13:12:27.000000000 -0500
@@ -47,7 +47,11 @@
 
 static void cleanup_output(void);
 
+#ifdef PSPKMODE
 PSP_MODULE_INFO("SDL App", 0x1000, 1, 1);
+#else
+PSP_MODULE_INFO("SDL App", 0, 1, 1);
+#endif
 PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
 
 int sdl_psp_exit_callback(int arg1, int arg2, void *common)
@@ -76,6 +80,7 @@
        return thid;
 }
 
+#ifdef PSPKMODE
 void sdl_psp_exception_handler(PspDebugRegBlock *regs)
 {
        pspDebugScreenInit();
@@ -91,11 +96,13 @@
                "\tpsp-addr2line -e target.elf -f -C 0x%x 0x%x 0x%x\n",
                regs->epc, regs->badvaddr, regs->r[31]);
 }
+#endif
 
 /* If this flag is set to 1, the _init() function was called and all
    global/static constructors have been called. */
 static int init_was_called = 0;
 
+#ifdef PSPKMODE
 __attribute__ ((constructor))
 void loaderInit()
 {
@@ -109,6 +116,7 @@
 
        init_was_called = 1;
 }
+#endif
 
 /* Remove the output files if there was no output written */
 static void cleanup_output(void)
@@ -148,6 +156,7 @@
 
 int main(int argc, char *argv[])
 {
+       #ifdef PSPKMODE
        /* Fanjita's EBOOT loader can be configured to skip the call to _init().
           Since we need _init() for C++, we check to see if _init() has been
           called.  If it hasn't we call it manually, after determining whether or
@@ -155,6 +164,7 @@
        if (!init_was_called) {
                _init();
        }
+       #endif
 
        pspDebugScreenInit();
        sdl_psp_setup_callbacks();
and

Code: Select all

--- configure.in        2007-11-18 21:32:07.000000000 -0500
+++ configure.in        2007-11-18 21:29:35.000000000 -0500
@@ -1914,6 +1914,13 @@
        CFLAGS="$CFLAGS -DPSPIRKEYB"
        SYSTEM_LIBS="$SYSTEM_LIBS -lpspirkeyb -lpsppower"
     fi
+
+    AC_ARG_ENABLE(pspkmode,
+                 [  --enable-pspkmode       enable PSP kernel mode functions [default=yes]],
+                  , enable_pspkmode=yes)
+    if test x$enable_pspkmode = xyes ; then
+       CFLAGS="$CFLAGS -DPSPKMODE"
+    fi
 }
 
 case "$target" in
E] You know, I'm not sure what _init and _fini are, so if there's a good reason for _init not to be ifdef'd out, by all means keep them, but that's how they were in the original patch I saw.
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

Why make it optional?
I think we should do away with it entirely.
Are there compelling reasons to keep it?
Viper8896
Posts: 110
Joined: Thu Jan 26, 2006 6:20 pm

Post by Viper8896 »

I think SDL should be user only. Especially with the way new firmwares operate. Anyway I don't like SDL and would like to encourage alternatives in every aspect that SDL provides.
fungos
Posts: 41
Joined: Wed Oct 31, 2007 10:43 am
Location: cwb br
Contact:

Post by fungos »

Yes, I agree with jimparis.

I read somewhere somebody saying that It was hard to find homebrew for new firmwares and that developers only dev for 1.50 and that was crap. After that I saw that I was developing for 1.50 only and I haven't saw anywhere how to not develop for 1.50. Well, my problem was that I was using SDL and developing based on old samples. Now, that I'm trying to develop for 3.xx I'm getting too much trouble :D

Updating SDL to be 3.xx is a huge help for newbies as me do not develop for 1.50 :)
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

Well, I'm looking for technical arguments, not just "yeah that sounds good".
Removing kernel mode means we remove functionality, so I want to know if anyone relies on it. Will anyone miss the exception handler? Does anyone need the stdio redirection or the no-device-check patches? Of course, those people can always choose to just implement main() themselves and not link libSDL_main, but some input from people using the library would be useful before we go and break stuff.
danzel
Posts: 182
Joined: Fri Nov 04, 2005 11:03 pm

Post by danzel »

I use SDL for all my apps/games, and I support removing the Kernel mode dependency.

The things that patch will remove are un-needed as far as I'm concerned.
Add a note to the README.PSP that they are gone. Not that anyone reads it :-(
Chrighton
Posts: 58
Joined: Wed Jun 15, 2005 8:24 pm

Post by Chrighton »

It's not worth bothering with (IMO). The exception handling is useful under 1.5, and if you're developing under 3.x/cfw, simply don't link SDL_main. If you want the app to work under both 1.5/3.x, simply don't link SDL_main. Updating the readme to merely emphasize this would probably be enough, I would think.
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

Well as I pointed in the other thread kernel mode really isn't necessary anymore (*cough* psplink *cough* ;P) but that said breaking the code cause you are lazy is hardly the best option. If anything kmode should be the default to maintain legacy and people are encouraged to enabled a user mode only version or it should build both a user and kernel SDL_main.

Unfortunate but there we go, not that I expect masses of people to come here bitching about the change the fact but then just being the most vocal doesn't induce me to change it.

Still, why should I care :)
Post Reply