How to write "enable intc" procedure?

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

Moderators: cheriff, Herben

Post Reply
MaikeruDev
Posts: 13
Joined: Mon Jul 16, 2007 3:09 am
Location: Poland
Contact:

How to write "enable intc" procedure?

Post by MaikeruDev »

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: Select all

// 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.
Mega Man
Posts: 260
Joined: Sat Jun 18, 2005 3:14 am
Contact:

Post by Mega Man »

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.
MaikeruDev
Posts: 13
Joined: Mon Jul 16, 2007 3:09 am
Location: Poland
Contact:

Post by MaikeruDev »

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 :)
Mega Man
Posts: 260
Joined: Sat Jun 18, 2005 3:14 am
Contact:

Post by Mega Man »

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.
MaikeruDev
Posts: 13
Joined: Mon Jul 16, 2007 3:09 am
Location: Poland
Contact:

Post by MaikeruDev »

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.
Post Reply