![]() |
Weird Stuff in ifi_startup.c
I was poking through the default code in an effort to determine if we could program the Master PIC as well as the User PIC, and I found this odd stuff thither.
Code:
void |
First of all, "thither", in modern English, translates to "to there".
Sorry, I just like to nitpick English. More to the point... In Microchip's PIC C, assembly language programming is done using "_asm" as a starting point, and "_endasm" as an endpoint. Anything between these two points is interpreted as assembly language programming. As for the functionality of the code you're referencing, I have no idea. A cursory inspection leads me to believe, as you do, that the _entry function isn't necessary, but I didn't write the stuff. In the _startup function, the lines between the "_asm" and "_endasm" lines start with the PIC instruction mnemonics, and are followed by arguments. BCF and BSF are "bit clear following" and "bit set following", respectively, and LFSR is "Move literal (12-bit) 2nd word to FSRx1st word". The entire instruction set is well-documented in the PIC18F8520 datasheet. I'm sorry that I don't know the specifics, and can't be very helpful. |
You are correct that in c most programs start with a main(), but that assumes that the Operating systems is present. In embedded systems with no OS _entry is the address that the CPU jumps to at power-up. The entry point usually contains processor initialization code. Since this code must run without the CPU being fully setup the developer usually will use ASM as the c runtime libraries are not available yet. You will notice that this code sets up the stack pointer which points to the memory location that stores function arguments and local variables, initializes floating point, configures memory and then calls _do_cinit () which initializes the c runtime so that c code can be used. The jump to main() is where the c code starts.
Rich |
Re: Weird Stuff in ifi_startup.c
Quote:
The underscore in the function name is usually used to signify an internal library function. This is a design decision that provides a few benefits to the end programmer. The first is that it is easy to identify the functions that are provided. The second is that the library authors are able to use meaningful names within their functions, yet they don't take valid function names away. For example, in your example above, if the library used entry() instead of _entry(), the end programmer may not be allowed to write a function named entry. Hope this makes sense :) |
Re: Weird Stuff in ifi_startup.c
Quote:
Doing this work is very dependent on the architecture, so special code has to be written for each platform (Macintosh, Linux, Windows, Edu RC, etc), generally in assembly. This is done by some combination of the OS folks and the compiler support programmers since some is specific to the OS and some is specific to the language being used. Thankfully, C programmers generally don't need to know anything about that preamble code except in very unusual circumstances. |
| All times are GMT -5. The time now is 00:36. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi