I am designing a critical function and I trace PC for it.
Is there anyway define an idependent library to a function?
Here is the problem:
I define an address space for a special function.
This function uses compiler support routines and some other functions of the standard libraries.
I want to copy these functions and locate to specific addresses.
So while main program and other functions can use these functions,
I can call copy of them (which are at specific addresses) from the special function.
Thanks in advance.
By the way, my target is 8051.
And of course I can simply copy the function from sdcc lib files, change its name for normal library files.
But I am looking for a solution for the compiler suport routines and mabe better solution for normal library functions.
I get the feeling you are trying to write some sort of library that will be preloaded in a restricted area of your target. The users should be able to use the functions in a black box manner. They should not link to the library but to a stub.
I a case like this you should make your library __reentrant and use no global or static variables (stateless) or you'll be forced to use absolute addresses for every variable and parameter. You should either refrain from using standard libraries or include them in the preloaded area without exporting them to the user. So the user will link in his own copy of the libraries.
Maarten, thank you very much for answering all of my questions.
You are right.
I put a function by using
sdcc-sdcc -c ... --codeseg funcseg
sdcc-sdcc ... ... -Wl -bfuncseg=0x800 options.
And this function will be a black box (in fact, it will be hardcoded at the rom) to the user.
** How should I do this?
"... or include them in the preloaded area without exporting them to the user. So the user will link in his own copy of the libraries."
Should I copy and paste to the c file of the function.
For example, produced ASM includes gptrget and gptrput for generic pointers.
** I have a second question. I am using small model linker option for the function. So SP will be at the internal ram. Although user defined code will change with the one like huge model or programmer changes the location of the stack, it will come to internal ram at the start of function, Right?
SDCC will automatically link in any library it thinks it needs unless told not to. So your hex-file will contain gptrget and gptrput. No need to copy/paste them.
SDCC does not support mixing of memory models. The memory model defines how parameters for non-reentrant functions are passed. The same goes for stack options. You cannot mix code with or without --xstack.
The best chance of getting this to work is to build your library with --stack-auto. And prototype the functions for the user with the __reentrant modifier. These exported functions should be accessed with const function pointers in the user application. And I also recommend a jumptable in assembly so you can change your library implementation without forcing the user to also change his program.