Load a outside .BIN in KOS ?

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
User avatar
Arqueiro
DCEmu Nutter
DCEmu Nutter
Posts: 785
Joined: Tue Jul 02, 2002 9:29 am
Contact:

Load a outside .BIN in KOS ?

Post by Arqueiro » Wed May 05, 2004 6:18 am

is anyway to run a outside program in KOS ?

for exemple, if i want that my program run the file /cd/dcdivx.bin its possible ?


thanks again !
3d graphics and visualization ?
http://www.arquiteturadigital.com
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am

Post by BlackAura » Wed May 05, 2004 7:38 am

Load the bin into memory, and call arch_exec()

See kos/kernel/arch/dreamcast/include/arch/exec.h

Basically, you do something like:

Code: Select all

void *blob;
ssize_t length = fs_load("/cd/dcdivx.bin", &blob);
assert(length > 0);
arch_exec(blob, length);
speud
DCEmu Uncool Newbie
DCEmu Uncool Newbie
Posts: 1459
Joined: Sat Dec 27, 2003 10:40 pm
Contact:

Post by speud » Wed May 05, 2004 7:45 am

is that what demomenu/dchakker use? i always wondered how it could boot external apps
http://blueswirl.fr.st - DC Online Tools and Downloads

thx to Wack0 for the avatar ;)
User avatar
Arqueiro
DCEmu Nutter
DCEmu Nutter
Posts: 785
Joined: Tue Jul 02, 2002 9:29 am
Contact:

Post by Arqueiro » Wed May 05, 2004 7:59 am

very cool ! i will try make some testes later....
3d graphics and visualization ?
http://www.arquiteturadigital.com
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am

Post by BlackAura » Wed May 05, 2004 8:05 am

Actually, it isn't. They don't use KOS's built-in way of doing it, but they all work on the same principles.

The arch_exec function has to replace the currently running program with the new program, and then jump to it. Obviously, this is impossible, because you'd be overwriting the code that's doing the overwriting.

arch_exec contains code for a small assembly program, known as a trampoline. It allocates enough memory to hold the trampoline, then copies it over. Then it writes the new program's address and length into pre-defined locations withing the trampoline, shuts down KOS, and runs the trampoline function.

The trampoline function copies the new program to the standard start address, clears the data and instruction caches, and does the same kind of initialization as the IP.BIN bootstrap normally does. It then starts the new program, which doesn't have any idea that there was a program here before.

In the case of DemoMenu, it uses it's own custom trampoline which does a lot more than the KOS one. It stays resident in memory, much like DCLoad does, and it's supposed to return to the DemoMenu menu when your program's finished. It also causes severe problems (like a system crash) if you try to use KOS's arch_exec function to load another program.

DreamInducer is more like KOS's arch_exec, but the trampoline appears to be stored in a separate file, for some reason.
speud
DCEmu Uncool Newbie
DCEmu Uncool Newbie
Posts: 1459
Joined: Sat Dec 27, 2003 10:40 pm
Contact:

Post by speud » Wed May 05, 2004 8:15 am

i see, its much clearer now, thanks.

would people be interested by an app working about like dchakker but being able to load bins from the pc?

WaCk0 asked me if it was possible some time ago, i said i think it would be quite easy to implement in something like dchakker if it was open source, but if its possible to do it using a simple function and its useful for people i think i could do something like that.

but it wouldnt be possible to return to the list like in dchakker though since it requires more than what kos function offers if i understood correctly.
http://blueswirl.fr.st - DC Online Tools and Downloads

thx to Wack0 for the avatar ;)
Post Reply