__asm("text:"); Function. Where is it defined?
__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
if(new_pad & PAD_CROSS)
{
__asm("cross:");
more code..
more code..
Any help is greatly appreciated. Thanks
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...
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
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));
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
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.
or something like that.
(But there might be the possibility that functions may be reordered (? I'm not sure)).
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;
(But there might be the possibility that functions may be reordered (? I'm not sure)).
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.