forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to write "enable intc" procedure?

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development
View previous topic :: View next topic  
Author Message
MaikeruDev



Joined: 16 Jul 2007
Posts: 13
Location: Poland

PostPosted: Mon Jul 16, 2007 3:46 am    Post subject: How to write "enable intc" procedure? Reply with quote

Hello everyone. I'm new in ps2 development, but on start I'm trying to write my own library like ps2sdk - of course I stuck on begining :)

Yesterday I setup my developing environment:
+ laptop
+ visual studio
+ my own makefile
+ ps2sdk linkfile
+ inlink
+ network adaptor
+ ps2
+ ps2link
- without ps2sdk

And I wrote some timer code (I was thinking that is good starting point). I set up T0 and it's works but when I try to add interrupts handler - I stuck :(

I wrote own procedure to enable interrupts from given pheriperial and ee hangs when I call 'syscall'. Heres the code

Code:

// add handler procedure - I think that procedure works ok
int add_intc_handler(int n, int(func *)(int), int next){

   int ret;

   __asm__ __volatile__ (

   "li $3, 0x10 \n"
   "add $4, $0, %1 \n"
   "add $5, $0, %2 \n"
   "add $6, $0, %3 \n"
   
   "syscall \n"
   "nop \n"
   "add %0, $0, $2 \n"

   : "=r"(ret)
   : "r"(n), "r"(func), "r"(next)
   );

   return ret; //
}

// enable interrupt handlers - this procedure hang on syscall
int enable_intc(int n){

   __asm__ __volatile__ (

   "li $3, 0x14 \n"
   "add $4, $0, %1\n"
   "syscall \n" // here ps2 show me "Exception handler" screen
   "nop \n"
   "add %0, $0, $2"
   : "=r"(ret)
   : "r"(n)

   );

   return ret;
}

// simple handler
int t0_handler(int test){
   printf("hello from handler\n");
}

// and in main i call this procedures
int h_no = add_intc_handler(0x09, t0_handler, 0);
enable_intc(0x09); // hangs





correct my if I wrong, $2 is yours v0 and it's handle syscall return value right?

So if someone could help me, that will be great :)

ps1. I don't know mips assembler very well so I use add instruction instead of mov or something to pass data between registers (I saw this on ooPo's ee-syscalls.txt :) )

ps2. sorry for my poor english skills.
Back to top
View user's profile Send private message Visit poster's website
Mega Man



Joined: 18 Jun 2005
Posts: 274

PostPosted: Mon Jul 16, 2007 10:45 am    Post subject: Reply with quote

I don't think it is a good idea to call "printf" in an interrupt handler. You said that you don't use ps2sdk and you started with timer code. Did you already tested "printf", because it is part of ps2sdk. You need a working toolchain to debug interrupts. Starting with interrupts is just crazy.

The current ps2sdk disables interrupts before changing an interrupt handler.
Back to top
View user's profile Send private message Visit poster's website
MaikeruDev



Joined: 16 Jul 2007
Posts: 13
Location: Poland

PostPosted: Tue Jul 17, 2007 3:40 am    Post subject: Reply with quote

Thanks for quick response.

When I said that I'm not using PS2SDK I meant using only this code what allows me to compile emtpy main (I know that is not equal to "not using" :) - sorry ). So actually I link libc from PS2SDK (printf sends text to my InLink perfectly) and libkernel - I know that I can use functions from this module, but I want to understand perfectly how their works. So that why I tries to write own :)
Back to top
View user's profile Send private message Visit poster's website
Mega Man



Joined: 18 Jun 2005
Posts: 274

PostPosted: Tue Jul 17, 2007 10:28 am    Post subject: Reply with quote

Did you know that the syntax of your code is incorrect.

- Function pointer declaration need to be done different. Star need to be moved before specifier "func".
- Local variable ret is missing in enable_intc.

The "printf" function in ps2sdk use things like rpc, syscalls and semaphores. I don't believe that syscalls are reentrant and semaphore handling can lead to deadlock.
You should just change a global variable in the interrupt handler and read it in your program.
Back to top
View user's profile Send private message Visit poster's website
MaikeruDev



Joined: 16 Jul 2007
Posts: 13
Location: Poland

PostPosted: Wed Jul 18, 2007 4:40 am    Post subject: Reply with quote

Mega Man wrote:

Did you know that the syntax of your code is incorrect.

- Function pointer declaration need to be done different. Star need to be moved before specifier "func".
- Local variable ret is missing in enable_intc.

Yes I know. I made this mistakes because i have two computers laptop and "normal" pc. Laptop is conected only to PS2. Normal pc is conected to internet via second lan... so I must rewrite code and I didn't check it... of course code on my laptop is ok.

Next time I will spend more time on writing post and I will check everything.
You may ask why I have two networks. Because I burned PS2LINK with standard IP configuration :)

Mega Man wrote:

The "printf" function in ps2sdk use things like rpc, syscalls and semaphores. I don't believe that syscalls are reentrant and semaphore handling can lead to deadlock.
You should just change a global variable in the interrupt handler and read it in your program.

I removed printf from handler, but when timer overflow or equal interrupt occurs, ee hangs. I think that my asm functions aren't good. When I use those from kernel lib everything is ok. So for now I will leave syscalls and write something else for start, because I don't even know that I pass arguments for syscall in right order.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
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