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 

Including asm in C source

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



Joined: 22 Oct 2004
Posts: 62

PostPosted: Sun Aug 12, 2007 5:59 pm    Post subject: Including asm in C source Reply with quote

I believe its called inline asm. But anyway. In my source code, main() calls and stores a function at a specific memory address. Further within my program, I want to jump to this functions memory adr to execute it.
so how would I set this up?

asm __volatile__("\n\
j $Address\
");

I know thats wrong because the compiler throws errors at me. Whats the correct way to do this, besides calling the function by its name..? Thx
Back to top
View user's profile Send private message
Lukasz



Joined: 19 Jan 2004
Posts: 248
Location: Denmark

PostPosted: Sun Aug 12, 2007 7:28 pm    Post subject: Reply with quote

http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html

If you want to call a function you need to use the instruction "jal" instead of "j", so the return address is stored in a register and check the link above for GCC inline syntax.

I'd recommend compiling some C source and using ee-objdump to disassemble the code and see what asm GCC generates and try to understand it, instead of creating new threads and asking trivial questions such as these, as you will get ignored eventually.

As for a EE instruction manual, use this: http://lukasz.dk/files/tx79architecture.pdf

Spend alot studying these things yourself, this way you will learn more and be able to solve problems on your own.
_________________
Lukasz.dk
Back to top
View user's profile Send private message Visit poster's website
Derek8588



Joined: 22 Oct 2004
Posts: 62

PostPosted: Mon Aug 13, 2007 3:02 am    Post subject: Reply with quote

I appreciate it. I know it was useless to make a thread to ask such a simple question. I spent approx 1-2 hrs google searching for the syntax of a j and jal op in asm. I have a basic understand of MIPS and its op codes. I'm just not to sure as of how to write it with the correct syntax in a C source file. All the ones that I have seen dont give an immediate value, but rather a variable.

jal some_value

I have tried preloading a variable pointer with an addr and attempt to jump to it. It says "undefined reference to the some_value variable." Even though it was just previously declared.. But anyway. Thanks for your help. I wish there was a IRC channel that actually had dev's on it.
#PS2DEV at efnet never has anyone on it. I would have asked in this mannor, but I couldnt. So my last resort was to turn here to the forums. As you can see I am rather new to PS2 programming. I took it up as a hobby until I go back to college...

Well I will read the docs you gave me and try the obj-dump in gcc. If all else fails, I will figure out some way to impliment this. Thanks
Back to top
View user's profile Send private message
ragnarok2040



Joined: 09 Aug 2006
Posts: 230

PostPosted: Mon Aug 13, 2007 3:52 am    Post subject: Reply with quote

http://ps2dev.ofcode.com/modules/wordpress/?page_id=37

That site has a ton of documents about the EE as well including opcodes and registers and etc. Maybe it'll be of some help.
Back to top
View user's profile Send private message
Mihawk



Joined: 03 Apr 2007
Posts: 29

PostPosted: Mon Aug 13, 2007 6:04 am    Post subject: Reply with quote

I'm not sure, but are you looking for something like this?
Code:

void* ptr = specificMemoryAddress;
asm __volatile__(
   "jalr   $ra,%0\n"
   "nop\n"
   :
   : "r"(ptr)
   :
);
Back to top
View user's profile Send private message
Derek8588



Joined: 22 Oct 2004
Posts: 62

PostPosted: Mon Aug 13, 2007 1:31 pm    Post subject: Reply with quote

Thanks for all your help. Carefully reading through the Inline Assembly Tutorial that Lukasz pointed me to, and 20 min of fiddling around. I finally figured it out. Heres what I was trying to do.

Code:

asm __volatile__(
   "jal\t 0x01bdea28\n\t"
   );


So simple eh? Heh. One of my previous roadblocks was that I was trying to prefix the address to be jumped to with a $ and not 0x. I even forgot the "" around each line. And another occured when I was using variable names with other opcodes, such as v0. I never including the proper header (as_reg_compat.h) Stupid me :( Once again, thanks for having patience with me.
Back to top
View user's profile Send private message
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