I am checking some terrible C source code; I haven't got any idea about how to maintain it or cooperate with it. But I found a very fundamental problem. It does NOT have a startup.asm; it has a startup.c using the powerful C extension "#pragma". So, the C runtime environment is setup by "#pragma section", "#pragma intvect", "#pragma asm". I quite worry about such a startup.c; so I contacted the FAE of our local distributor. The FAE is an experienced good engineer, but he told me that, this is not their standard way to setup C runtime environment; they definitely provided the startup.s from Day 1.
What will be the side-effect, when the C runtime environment is setup by the C extension "#pragma"?
Per Westermark => If we ignore potential timing issues, a comparison of that startup file with the code you have should be able to tell if the current code does try to recreate all steps performed by the compiler-supplied startup file.
Hans-Bernhard Broeker => If you really don't believe in that startup code getting the job done properly, compile it to asm and look at what you get.
I have done the comparison for Fujitsu's startup.asm and the mentioned startup.c yesterday. The Fujitsu's startup.asm has some features/supports, that the mentioned startup.c doesn't provide.
And also:
Fujitsu's startup.asm
; Use word aligned stack section. Stack symbols are ignored. #define SSTACK_L ((SSTACK + 1) & ~1) #define SSTACK_H ((SSTACK + SIZEOF(SSTACK)) & ~1) #define SSTACK_BNK BNKSEC SSTACK [......] MOVL A, #SSTACK_H MOVW SP,A ; load offset of stack top to pointer MOV A, #SSTACK_BNK ; load bank of stack start address to A MOV SSB, A
the mentioned startup.c
#pragma asm .SECTION STACK, STACK, ALIGN=2 .RES.B SSTACK_SIZE - 2 SSTACK_TOP: .RES.B 2 #pragma endasm [......] [ I can NOT find the define of BNKSYM in the startup.c ] ;--- setup SSTACK MOV A, #BNKSYM SSTACK_TOP MOV SSB, A MOVW A, #SSTACK_TOP + 2 MOVW SP, A
It is embarrassing that, I may be able to read the Assembly code, but my knowledge about Assembly programming is very poor.
( I am a member of http://fujitsu-mcubbs.com/ but it is almost a frozen forum. )
I decided to take the opinions from Mike and Hans-Bernhard.
I got an original paper copy of the startup.c and other c-files, they look better. Most of the suspicious portions are not written by the mentioned third party, it is added by users.
Of course, the Fujitsu startup.asm is much better, and more reliable.
But, to minimize the effort, and maintain the compatibility, I will remedy the current startup.c, based on the original paper copy; and focus on the other critical problems, like a very huge single main.c .
"But, to minimize the effort, and maintain the compatibility, I will remedy the current startup.c, based on the original paper copy; and focus on the other critical problems, like a very huge single main.c ."
I would find it risky to attempt changing something you don't fully understand.
from what you described, the .c startup file seems to be working and the problem of its poor documentation can be remedied later, probably after you have fixed other problems, like introducing more structure to the user code.
it allows you more time to learn about the start-up and the .c startup code.
but then that's just me.
[ I can NOT find the define of BNKSYM in the startup.c ]
That's becaus it's not in there. BNKSYM (and BNKSEC in the Fuji, which you failed to stumble over) is an assembler operator. Look it up in the assembler manual.
but my knowledge about Assembly programming is very poor.
In that case I have to warn you against messing with the startup code unless you know for sure there's an actual problem in there that you have to fix. You seem to have more important fish to fry than that one. Starting with what sounded quite a lot like a stack overflow described in one of your earlier posts.
Hi Hans-Bernhard,
Many Thanks for your help.
( I saw someone calls you "Hans" before, But as I am a Taiwanese/Chinese, I don't know which is proper. )