Page 1 of 1
__asm("text:"); Function. Where is it defined?
Posted: Wed Aug 01, 2007 11:27 am
by Derek8588
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
Posted: Wed Aug 01, 2007 11:58 am
by Jim
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
ahh
Posted: Wed Aug 01, 2007 2:34 pm
by Derek8588
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:");
Posted: Wed Aug 01, 2007 3:05 pm
by Jim
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
Posted: Thu Aug 02, 2007 2:08 pm
by Derek8588
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?
Posted: Thu Aug 02, 2007 3:37 pm
by Jim
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
Posted: Fri Aug 03, 2007 12:38 pm
by Derek8588
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'
Posted: Fri Aug 03, 2007 4:34 pm
by jimparis
Posted: Sun Aug 05, 2007 3:32 pm
by Derek8588
ty very much
Posted: Tue Aug 07, 2007 4:10 pm
by Derek8588
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: Select all
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
Posted: Tue Aug 07, 2007 5:16 pm
by radad
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.
Posted: Tue Aug 07, 2007 5:58 pm
by Derek8588
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.
Posted: Tue Aug 07, 2007 6:33 pm
by Mihawk
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: Select all
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)).
Posted: Tue Aug 07, 2007 7:29 pm
by radad
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.
Posted: Wed Aug 08, 2007 2:35 pm
by Derek8588
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.