Trying to get 'hello world' to work ...

Discuss the development of software, tools, libraries and anything else that helps make ps2dev happen.

Moderators: cheriff, Herben

Post Reply
Oscar
Posts: 3
Joined: Sat May 21, 2005 3:51 am

Trying to get 'hello world' to work ...

Post by Oscar »

Hi,

I have an umodded PS2 with the independece exploit on my MC.
I've installed the toolchain using Cygwin on Windows XP.

Now I try to get the 'Hello world !' program to work on my PS2.
It builds, but when I ty to execute it on my PS2 using PS2Menu Loader
(v2.1) nothing happens (at least not what I expect to happen).

I've put the hello.elf in /mc/0/BEDATA-SYSTEM.
After executing I get;
PSMENU Loader v.2.1.
Init Mr Brown sbv(?) patches
argv[0]=/mc/0/... path to hello.elf
argv[1]=hdd0:... last installed game hdloader
Loading mc0:/... path again
EE:LoadElf returned 0
EE:Creating User Thread ( .. some numbers ..)
Created user thread 12
LoadElf returned 12

... and then it 'hangs'.


This is my source:

#include <tamtypes.h>
#include <sifcmd.h>
#include <kernel.h>
#include <sifrpc.h>
#include "sio.h"

int main(int argc, char *argv[])
{
int i;
SifInitRpc(0);
printf("Oscar Says: Hello, world!\n");


printf("I am called %s\n", argv[0]);
for (i=0;i< argc; i++)
printf("Oscar says Arg[%d]: %s\n",i, argv);

sio_init(115200, 0, 0, 0, 0);
sio_printf("Hello from EE SIO!\n");

/* Return to the bootloader or PS2 browser. */
return 0;
}

I don't think the Rpc init is nessecary because I don't do RPC.

Is the above program supposed to work of my MC ?

If anyone could give me some info that would be nice (I do RTFM but
there are many FM's :-))

BTW: I've changed the original hello.c a bit but the original did not
work either ...

Cheers for any comments,
Oscar
cory1492
Posts: 216
Joined: Fri Dec 10, 2004 1:49 pm

Post by cory1492 »

Its probably working fine, but printf in that sample echos through the ps2link console (when you run the elf off the pc using inlink/ps2link the text appears on the pc inlink console) , you need scr_printf (in debug.h) to output to the screen:

Code: Select all

#include <tamtypes.h>
#include <sifcmd.h>
#include <kernel.h>
#include <sifrpc.h>
#include <debug.h>
#include "sio.h"

int main&#40;&#41;
&#123;   
   SifInitRpc&#40;0&#41;; 

   init_scr&#40;&#41;;
   scr_printf&#40;"Hello, world!\n"&#41;; /* hello world in the screen */

   printf&#40;"Hello, world!\n"&#41;; /* hello world across the ps2link rpc*/
   nprintf&#40;"Hello, again, from Naplink RPC!\n"&#41;;

   sio_init&#40;115200, 0, 0, 0, 0&#41;; /* hello world out the sio interface*/
   sio_printf&#40;"Hello from EE SIO!\n"&#41;;

   /* Return to the bootloader or PS2 browser. */
   return 0;
&#125;
I think this should still work, not sure if you need to init the Sif, but it worked for me when I tried it a long while back.
Oscar
Posts: 3
Joined: Sat May 21, 2005 3:51 am

Post by Oscar »

Thanks for replying. I'm going to try the scr_printf tonight (it
was commented out in the original hello.c so I thought I did
not need it and removed it).

Probably also going to learn a bit more about this ilink/ps2link thing.
Sounds cool.

Thanks again.
Kojima
Posts: 275
Joined: Mon Jun 26, 2006 3:49 am

Post by Kojima »

I'm having the same problem, I tried adding init_scr();
but it fails to compile, saying it's an undefined reference.

Here's my source,

Code: Select all


#include <stdio.h>
#include <erl.h>
#include <tamtypes.h> 
#include <sifcmd.h> 
#include <kernel.h> 
#include <sifrpc.h> 
#include <debug.h> 
#include "sio.h"
char * erl_id = "hello";
char * erl_dependancies&#91;&#93; = &#123;
    "libc",
    0
&#125;;

int main&#40;&#41;
&#123;   
		init_scr&#40;&#41;;
    printf&#40;"Hello world!\n"&#41;;
    
    return 0;
&#125;

Am I missing an include file?
User avatar
Drakonite
Site Admin
Posts: 990
Joined: Sat Jan 17, 2004 1:30 am
Contact:

Post by Drakonite »

You need to link with -ldebug to use scr_printf


ps2link console output is much better anyways ;)
Shoot Pixels Not People!
Makeshift Development
Kojima
Posts: 275
Joined: Mon Jun 26, 2006 3:49 am

Post by Kojima »

Yeah I'd be much happier using that, but I'm stuck with a ps2 emulator till my new powerpack gets here.(Sticks another pin in voodoo doll of brother) Atm without a working text output I'm not even sure if what I'm compiling runs on the emu or just hangs.

I tried your suggestion but I now get a new error, here's the make output.
C:\ps2dev\ps2sdk\samples\hello>make
ee-gcc -D_EE -O2 -G0 -Wall -IC:/ps2dev/ps2sdk/ee/include -IC:/ps2dev/ps2sdk/com
mon/include -I. -c hello.c -o hello.o
ee-gcc -mno-crt0 -TC:/ps2dev/ps2sdk/ee/startup/linkfile -LC:/ps2dev/ps2sdk/ee/li
b \
-o hello.elf C:/ps2dev/ps2sdk/ee/startup/crt0.o hello.o -lc -lkernel -ld
ebug
C:/ps2dev/ps2sdk/ee/lib/libdebug.a(scr_printf.o)(.text+0x38): In function `Init_
GS':
src/scr_printf.c: undefined reference to `GsPutIMR'
C:/ps2dev/ps2sdk/ee/lib/libdebug.a(scr_printf.o)(.text+0x48):src/scr_printf.c: u
ndefined reference to `SetGsCrt'
C:/ps2dev/ps2sdk/ee/lib/libdebug.a(scr_printf.o)(.text+0x384): In function `scr_
printf':
src/scr_printf.c: undefined reference to `vsnprintf'
collect2: ld returned 1 exit status
make: *** [hello.elf] Error 1
here's the source I used,

Code: Select all

#include <stdio.h>
#include <erl.h>
#include <debug.h>
char * erl_id = "hello";
char * erl_dependancies&#91;&#93; = &#123;
    "libc",
    0
&#125;;

int main&#40;&#41;
&#123;   
		init_scr&#40;&#41;;
    printf&#40;"Hello world!\n"&#41;;
    
    return 0;
&#125;

Any idea what could be causing it?
tmator_
Posts: 9
Joined: Sat Jun 10, 2006 11:52 pm
Contact:

Post by tmator_ »

Hi,

just add "-ldebug -lc -lkernel" to link it with libdeug whic contain src_printf functions.
misfire
Posts: 110
Joined: Mon Sep 06, 2004 7:53 am
Location: Germany

Post by misfire »

To sum it up:

makefile:

Code: Select all

EE_BIN = hello.elf
EE_OBJS = hello.o
EE_LIBS = -ldebug

all&#58; $&#40;EE_BIN&#41;

clean&#58;
	rm -f *.elf *.o *.a

include $&#40;PS2SDK&#41;/Makefile.pref
include $&#40;PS2SDK&#41;/Makefile.eeglobal
hello.c

Code: Select all

#include <tamtypes.h>
#include <kernel.h>
#include <sifrpc.h>
#include <stdio.h>
#include <debug.h>

int main&#40;int argc, char *argv&#91;&#93;&#41;
&#123;
	SifInitRpc&#40;0&#41;;

	init_scr&#40;&#41;;
	scr_printf&#40;"Hello, world!\n"&#41;;
	printf&#40;"Hello, world!\n"&#41;;

	return 0;
&#125;
This prints to screen and debug console.
Kojima
Posts: 275
Joined: Mon Jun 26, 2006 3:49 am

Post by Kojima »

Great, that worked. Thanks guys.
Post Reply