 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
a_noob
Joined: 17 Sep 2006 Posts: 97 Location: _start: jr 0xDEADBEEF
|
Posted: Tue Sep 29, 2009 12:01 am Post subject: vshmain replacement |
|
|
Ok, well I did a little digging, but not enough it seems. I want to replace vshmain.prx. However, I can't be arsed to reverse it. Especially since I am new at reversing. So that would take me for ever. Plus I don't exactly need the source of vshmain. But rather I need to know what makes it tick. So far I dug around a bit trying to get the propery thread and module attributes, but there is not really a clear definition. I read somewhere on here that 0x0800 is "VSH mode" (module) but psplink spits out 0x0000. So I went over to the asm and took a look at the only call the sceKernelCreateThread, and got the attr 0x4000, but psplink shows 0xC00040FF. I have tried mixed combinations of these, but to no avail when I replace vshmain.prx I get a black screen of death. However in psplink, if I run reset vsh thenn my module it works as intended. So my question is what am I missing at this point in time? Do I need to create a special export table of some sort? I mean I am not going to use any of the modules in flash0:/vsh/module so that shouldn't be necessary. Help would be appreciated.
| Code: | /*
* vshmain.c
* vshmain
*
* Created by Zachry Thayer on 9/28/09.
* Copyright 2009 A_Nub. All rights reserved.
*
*/
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspidstorage.h>
#include <pspdisplay.h>
PSP_MODULE_INFO("VSH", 0x0000, 1, 1);
PSP_HEAP_SIZE_KB(0x00010000);
#define SCR_WIDTH (480)
#define SCR_HEIGHT (272)
#define BUF_WIDTH (512)
#define PIXEL_SIZE (4)
#define FRAME_SIZE (BUF_WIDTH * SCR_HEIGHT * PIXEL_SIZE)
unsigned int *vramTop = (unsigned int*)0x04000000;
void clearScreen(unsigned int col){
int y = 0,x = 0;
for(y = 0; y < SCR_HEIGHT; y++)
for(x = 0; x < SCR_WIDTH; x++){
vramTop[x + y * BUF_WIDTH] = col;
}
}
void putRect(int X, int Y, int W, int H, unsigned int col){
int y = 0,x = 0;
for(y = Y; y < Y + H; y++)
for(x = X; x < X + W; x++){
putPixel(x,y,col);
}
}
void putPixel(int x, int y, unsigned int col){
if(x < 0 || x > SCR_WIDTH) return;
if(y < 0 || y > SCR_HEIGHT) return;
vramTop[x + y * BUF_WIDTH] = col;
}
SceUID main_thread_uid;
int main_thread(SceSize args, void *argp){
sceDisplaySetFrameBuf(vramTop, BUF_WIDTH, PSP_DISPLAY_PIXEL_FORMAT_8888, PSP_DISPLAY_SETBUF_IMMEDIATE);
sceDisplaySetMode(0, SCR_WIDTH, SCR_HEIGHT);
while(1){
clearScreen(0xff00ff00);
putRect(10,10,100,100,0xffff0000);
sceKernelDelayThread(1);
}
return 0;
}
int module_start(SceSize args, void *argp){
main_thread_uid = sceKernelCreateThread("VSH_MAIN",main_thread, 32, 0x00010000, 0x4000, NULL);
if(main_thread_uid >= 0)
sceKernelStartThread(main_thread_uid, 0, NULL);
return 0;
}
int module_stop(SceSize args, void *argp){
sceKernelTerminateDeleteThread(main_thread_uid);
return 0;
}
|
_________________
| Code: | .øOº'ºOø.
'ºOo.oOº' |
|
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Tue Sep 29, 2009 2:10 am Post subject: |
|
|
You can replace vshmain.prx with any ordinary user mode module. Just make it VSH mode 0x800. Don't allocate too big a heap depending on Phat/Slim since memory allocation is done before by paf.prx which is loaded before vshmain.prx. If you replace paf.prx you get the whole memory, but then for some reason the vshargs aren't received by vshmain.prx (or your replacement vshmain.prx) so it will appear to have cold rebooted everytime.
In case you want to load the real vshmain.prx later you must use a kernel module to unload your replacement vshmain.prx and only then load and start the real vshmain.prx so that the user memory doesn't get fragmented. |
|
| Back to top |
|
 |
a_noob
Joined: 17 Sep 2006 Posts: 97 Location: _start: jr 0xDEADBEEF
|
Posted: Tue Sep 29, 2009 4:13 am Post subject: |
|
|
Thanks for the reply, but I did try that as I stated. So do you think I am allocating too much memory? Hmm I should check how much vsh_module takes.
So far its not working. I just get a black screen. And I haven't a clue as to why. I mean my code is simple, I only rely on sceDisplay, which should be loaded before vshmain.prx otherwise there would be major problems.
It seems vsh_main loads the following kernel modules
| Code: |
0x00037FF4: "flash0:/kd/mpeg_vsh.prx"
0x0003800C: "flash0:/kd/usbstor.prx"
0x00038024: "flash0:/kd/usbstormgr.prx"
0x00038040: "flash0:/kd/mlnbridge.prx"
0x0003809C: "flash0:/kd/usbstorms.prx"
0x000380B8: "flash0:/kd/usbstorboot.prx"
0x000380D4: "flash0:/kd/lflash_fatfmt.prx"
0x0003AE2C: "flash0:/kd/ifhandle.prx"
0x0003AE44: "flash0:/kd/pspnet.prx"
0x0003AE5C: "flash0:/kd/pspnet_inet.prx"
0x0003AE78: "flash0:/kd/memab.prx"
0x0003AE90: "flash0:/kd/pspnet_adhoc.prx"
0x0003AEAC: "flash0:/kd/pspnet_adhoc_auth.prx"
0x0003AED0: "flash0:/kd/pspnet_adhocctl.prx"
0x0003AEF8: "flash0:/kd/pspnet_apctl.prx"
0x0003AF14: "flash0:/kd/pspnet_resolver.prx"
0x0003AF34: "flash0:/kd/libparse_http.prx"
0x0003AF54: "flash0:/kd/libparse_uri.prx"
0x0003AF70: "flash0:/kd/libhttp.prx"
0x0003AF88: "flash0:/kd/cert_loader.prx"
0x0003AFA4: "flash0:/kd/libssl.prx"
0x0003AFBC: "flash0:/kd/mcctrl.prx"
0x0003AFD4: "flash0:/kd/libdnas_core.prx"
0x0003AFF0: "flash0:/kd/libdnas.prx"
0x0003B008: "flash0:/kd/np_core.prx"
0x0003B020: "flash0:/kd/np.prx"
0x0003B034: "flash0:/kd/np_auth.prx"
0x0003B04C: "flash0:/kd/np_service.prx"
0x0003B068: "flash0:/kd/np_commerce2.prx"
0x0003B084: "flash0:/kd/np_commerce2_store.prx"
0x0003B0A8: "flash0:/kd/np_commerce2_regcam.prx"
|
To my knowledge none of these are required for a psp to run a simple program such as mine. Any thoughts as to why I am getting a black screen of death.
5.00 kernel btw. (M33-4)
Ok I did a little more digging. I adde some sceIo* to write a test file to see if my code was running. And it is. So it seems something is wrong with my direct framebuffer writing :/ I don't get it. Maybe I should try using the GU rather? _________________
| Code: | .øOº'ºOø.
'ºOo.oOº' |
|
|
| Back to top |
|
 |
a_noob
Joined: 17 Sep 2006 Posts: 97 Location: _start: jr 0xDEADBEEF
|
Posted: Tue Sep 29, 2009 5:45 am Post subject: |
|
|
If anyone was still wondering I actually got it to work by using the GU :D
heres the code for those interested
| Code: |
/*
* vshmain.c
* vshmain
*
* Created by Zachry Thayer on 9/28/09.
* Copyright 2009 A_Nub. All rights reserved.
*
*/
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspidstorage.h>
#include <pspdisplay.h>
PSP_MODULE_INFO("VSH", 0x800, 1, 1);
PSP_HEAP_SIZE_KB(0x00010000);
#include <pspgu.h>
#include <pspgum.h>
static unsigned int __attribute__((aligned(16))) list[262144];
#define BUF_WIDTH (512)
#define SCR_WIDTH (480)
#define SCR_HEIGHT (272)
struct Vertex
{
unsigned int color;
float x, y, z;
};
struct Vertex __attribute__((aligned(16))) vertices[1*3] =
{
{0xFF0000FF, 0.0f, -50.0f, 0.0f}, // Top, red
{0xFF00FF00, 50.0f, 50.0f, 0.0f}, // Right, green
{0xFFFF0000, -50.0f, 50.0f, 0.0f}, // Left, blue
};
void start_gu(){
sceGuInit();
sceGuStart(GU_DIRECT,list);
sceGuDrawBuffer(GU_PSM_8888,(void*)0,BUF_WIDTH);
sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,(void*)0x88000,BUF_WIDTH);
sceGuDepthBuffer((void*)0x110000,BUF_WIDTH);
sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2));
sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT);
sceGuDepthRange(65535,0);
sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
sceGuEnable(GU_SCISSOR_TEST);
sceGuFrontFace(GU_CW);
sceGuShadeModel(GU_SMOOTH);
sceGuDisable(GU_TEXTURE_2D);
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuDisplay(1);
}
SceUID main_thread_uid;
int main_thread(SceSize args, void *argp){
start_gu();
ScePspFVector3 pos = {240.0f, 136.0f, 0.0f};
while(1){
sceGuStart(GU_DIRECT,list);
sceGuClearColor(0);
sceGuClearDepth(0);
sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);
sceGumMatrixMode(GU_PROJECTION);
sceGumLoadIdentity();
sceGumOrtho(0, 480, 272, 0, -1, 1);
sceGumMatrixMode(GU_VIEW);
sceGumLoadIdentity();
sceGumMatrixMode(GU_MODEL);
sceGumLoadIdentity();
// Draw triangle
sceGumTranslate(&pos);
sceGumDrawArray(GU_TRIANGLES,GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,3,0,vertices);
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuSwapBuffers();
}
return 0;
}
int module_start(SceSize args, void *argp){
main_thread_uid = sceKernelCreateThread("VSH_MAIN",main_thread, 32, 0x00010000, 0xC00040FF, NULL);
if(main_thread_uid >= 0)
sceKernelStartThread(main_thread_uid, 0, NULL);
return 0;
}
int module_stop(SceSize args, void *argp){
sceKernelTerminateDeleteThread(main_thread_uid);
return 0;
}
|
So now I just need to customize and IPL to not load paf and such, since they are a waste of memory, since I am not using them, but rather linking in the pspsdk GU etc. _________________
| Code: | .øOº'ºOø.
'ºOo.oOº' |
|
|
| Back to top |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Tue Sep 29, 2009 7:13 am Post subject: |
|
|
I think the original problem was you were using cached addresses for the screen and never flushing the dcache.
Jim _________________ http://www.dbfinteractive.com |
|
| Back to top |
|
 |
a_noob
Joined: 17 Sep 2006 Posts: 97 Location: _start: jr 0xDEADBEEF
|
Posted: Tue Sep 29, 2009 10:01 am Post subject: |
|
|
Couldnt be cached. Its a global. That is set at compile time. _________________
| Code: | .øOº'ºOø.
'ºOo.oOº' |
|
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Tue Sep 29, 2009 1:35 pm Post subject: |
|
|
| Jim wrote: | I think the original problem was you were using cached addresses for the screen and never flushing the dcache.
Jim |
Even then only 3-4 rows of pixels would be missing at most and they'd start filling in on their own even when the CPU is idle.
| a_noob wrote: | | Couldnt be cached. Its a global. That is set at compile time. |
(unsigned int*)0x04000000; is a cached address, it goes through the CPU cache first before being written to VRAM and hence needs to be flushed. Using this with GU functions will cause a crash/artifacts since the GU only reads from vRam and won't see unflushed data in the CPU cache.
(unsigned int*)0x44000000; will write straight to vRam but is obviously slow. |
|
| Back to top |
|
 |
m0skit0
Joined: 02 Jun 2009 Posts: 226
|
Posted: Tue Sep 29, 2009 7:47 pm Post subject: |
|
|
Bit 30 in address controls caching: 0 -> use cache; 1 -> do not use cache. _________________
| The Incredible Bill Gates wrote: | | The obvious mathematical breakthrough would be development of an easy way to factor large prime numbers. |
|
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Tue Sep 29, 2009 8:21 pm Post subject: |
|
|
| m0skit0 wrote: | | Bit 30 in address controls caching: 0 -> use cache; 1 -> do not use cache. |
When you start counting bits from from zero I assume. |
|
| Back to top |
|
 |
m0skit0
Joined: 02 Jun 2009 Posts: 226
|
Posted: Wed Sep 30, 2009 12:22 am Post subject: |
|
|
Yes, as always xD _________________
| The Incredible Bill Gates wrote: | | The obvious mathematical breakthrough would be development of an easy way to factor large prime numbers. |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|