| View previous topic :: View next topic |
| Author |
Message |
Derek8588
Joined: 22 Oct 2004 Posts: 62
|
Posted: Wed Aug 01, 2007 11:27 am Post subject: __asm("text:"); Function. Where is it defined? |
|
|
I have searched high and low but I cannot find a header file that contains the function __asm(""); nor its args. I have seen it used such as this...
if(new_pad & PAD_CROSS)
{
__asm("cross:");
more code..
more code..
Any help is greatly appreciated. Thanks |
|
| Back to top |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Wed Aug 01, 2007 11:58 am Post subject: |
|
|
It's not a function, it's a way of putting assembler inline with the C code. It's always compiler specific, and depending what you're compiling, the assembler may not be compatible with ps2.
Jim _________________ http://www.dbfinteractive.com |
|
| Back to top |
|
 |
Derek8588
Joined: 22 Oct 2004 Posts: 62
|
Posted: Wed Aug 01, 2007 2:34 pm Post subject: ahh |
|
|
Oh, so basically __asm(""); allows you to perform assembly operations within your C source code? eh nifty. well so what would this accomplish?
__asm("cross:"); |
|
| Back to top |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Wed Aug 01, 2007 3:05 pm Post subject: |
|
|
That just defines a label called 'cross' which can be the target of a branch or jump instruction. You should refer to the platform specific docs of 'gcc' and '(g)as' to see what else can go there.
Jim _________________ http://www.dbfinteractive.com |
|
| Back to top |
|
 |
Derek8588
Joined: 22 Oct 2004 Posts: 62
|
Posted: Thu Aug 02, 2007 2:08 pm Post subject: |
|
|
| ahh ok thanks. Also, do you happen to know what the _RESIDENT_ keyword means when declaring a variable? Im guessing it keeps the variable in memory regardless of what tries to erase it? |
|
| Back to top |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Thu Aug 02, 2007 3:37 pm Post subject: |
|
|
No idea. I guess it's a macro defined somewhere in one of the headers. Perhaps it defines a calling convention or a storage class.
Jim _________________ http://www.dbfinteractive.com |
|
| Back to top |
|
 |
Derek8588
Joined: 22 Oct 2004 Posts: 62
|
Posted: Fri Aug 03, 2007 12:38 pm Post subject: |
|
|
I never found it, but o well. Sorry for asking so many questions, but where can I find a list of the Directives that the asm compiler supports?
such as...
.set
.ent
etc' |
|
| Back to top |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
|
| Back to top |
|
 |
Derek8588
Joined: 22 Oct 2004 Posts: 62
|
Posted: Sun Aug 05, 2007 3:32 pm Post subject: |
|
|
| ty very much |
|
| Back to top |
|
 |
Derek8588
Joined: 22 Oct 2004 Posts: 62
|
Posted: Tue Aug 07, 2007 4:10 pm Post subject: |
|
|
Iv been struggling on this one for two nights. I have been trying to copy a function from one place in memory to another. Heres example code...
| Code: |
some_function(); /* multiple lines of code within this function */
u32 memory;
u32 *buffer, *new_location;
buffer = &some_function;
memory = sizeof(buffer);
printf(" Some_function occupies %d bytes of memory\n", memory);
memcpy(new_location, buffer, sizeof(buffer));
|
sizeof returns 4 bytes of memory, and it should return much more. So only the first instruction of the function is copied to the new location in memory. Can anyone help me find the proper way to copy a function from one place to another? Thanks for all your help!
edit: ahh i discovered that its returning the size of the pointer var ( i think lol) Well the only thing I can think to do is create a loop that increments the address of where the function is stored in memory by 4. then check if its value is != 0 and then add 4 to a var. 4 bytes will be added to the var for every address that contains data. then when the end of the function is reached ( is = NULL), the size of the function will be contained in the variable. Ureeka! I am about to test this...lol |
|
| Back to top |
|
 |
radad
Joined: 19 May 2004 Posts: 246 Location: Melbourne, Australia
|
Posted: Tue Aug 07, 2007 5:16 pm Post subject: |
|
|
What makes you think the function is terminated with a NULL?
And why are you copying it? You cant guarantee that once it is copied that you can call it. |
|
| Back to top |
|
 |
Derek8588
Joined: 22 Oct 2004 Posts: 62
|
Posted: Tue Aug 07, 2007 5:58 pm Post subject: |
|
|
well instead of NULL i could use 0 or 0x00000000 correct?
and once its in memory I will call it with a JAL (addr)
yay! that method described above worked. used the value 0. idk why i said NULL. stupid me. |
|
| Back to top |
|
 |
Mihawk
Joined: 03 Apr 2007 Posts: 29
|
Posted: Tue Aug 07, 2007 6:33 pm Post subject: |
|
|
What makes you think the function is terminated with 0, 0x00000000 or whatever?
0x00000000 as an opcode would be a "nop" IIRC. So if you're lucky and you have a nop somewhere in the middle of your function only half of that function will be copied.
One method I used some time ago when I was doing something similar was to get the label/function after that function, then you just get the difference between those two.
| Code: |
void theFunctionYouWantToCopy(void) { ... }
void someDummyFunction(void) {}
lenghtOfFunctionYouWantToCopy = (unsigned)someDummyFunction - (unsigned)theFunctionYouWantToCopy;
|
or something like that.
(But there might be the possibility that functions may be reordered (? I'm not sure)). |
|
| Back to top |
|
 |
radad
Joined: 19 May 2004 Posts: 246 Location: Melbourne, Australia
|
Posted: Tue Aug 07, 2007 7:29 pm Post subject: |
|
|
Thats what I meant. There is nothing to mark the end of a function. The best way is to get the address of the next function. That isnt always guaranteed to work but will most of the time.
And due to relative references a copy may not always work. |
|
| Back to top |
|
 |
Derek8588
Joined: 22 Oct 2004 Posts: 62
|
Posted: Wed Aug 08, 2007 2:35 pm Post subject: |
|
|
| Well I understand what ur saying that if a function has a nop in the middle it will copy half. But I have been using SIOSHELL and insuring that the function that is being copied does not contain any nop's scattered throughout it. the function writes data to specified addresses. So when the nop after the jr ra is reached, the size is returned. I know its a screwy way to do it, but it works :). I will consider using your method described above sometime soon. Oh, heres a question. SIOSHELL runs in the background and waits for the terminal app to call it. How is it possible to do this? Like say I had a program in kernel memory (not cleared) that recieves and writes data to memory without interrupting the program currently running. Basically, like making SIOSHELL not interrupt the current process. Any suggestions? Thanks once again. |
|
| Back to top |
|
 |
|