Re: Minimal c program

Posted:
Sun Jun 16, 2013 3:55 pm
by ysapir
There are a couple of things to note here:
In C, the leading underscore in a function's name is added implicitly by the compiler. So, a function func() in your code is renamed to _func() internally, and this is how it appears in the object file (when you do e-objdump these are the names you see). Thus, you should call your startup function as "start()" instead.
The bigger problem is that on the Epiphany, the start() function, being the first to be invoked after reset (or SYNC interrupt, to be more precise) should be mapped to the first vector in the IVT (address 0x00000000). Thus, the function itself should contain only one instruction which is the "b <addr-of-the-actual-function>" branch instruction. Alternatively, you should put that "b" instruction in the IVT manually (as a replacement for CRT0) and use your start() as the target address.
The current program flow, with the default stdlib is:
_start() - the IVT entry
.normal_start() - the actual start() function, which merely jumps to:
_epiphany_start() - initialization of stack and buffers, then jump to
main()
and you can see how it's done in file "libgloss/epiphany/crt0.S" in the epiphany-sourceware repo:
Re: Minimal c program

Posted:
Mon Jun 17, 2013 7:54 am
by yuumei
Ah, thank you for the information!
I think I will need to look at how the stack works a bit more

The reason I was looking at this was because a simple "int main() { return 0; }" was 33K... which I believe would not fit onto the local memory. So could I ask, is there a way to use c and still fit on the epiphany local memory? Maybe I am including something I shouldn't.
Re: Minimal c program

Posted:
Mon Jun 17, 2013 11:46 am
by ysapir
Of course there is, and we do it all the time. A simple, empty "int main()" will not occupy 33KB. I don't know how you got this output.
Re: Minimal c program

Posted:
Mon Jun 17, 2013 6:37 pm
by timpart
The size of the object file on disc is often bigger than the amount of memory it occupies on chip. It seems to have plenty of debugging information in there. Not sure if it has the source code but some cases I've tried seem big enough to fit that in as well.
Tim
Re: Minimal c program

Posted:
Wed Jun 19, 2013 12:53 pm
by aolofsson
Here's a pretty good tutorial on creating REALLY small programs I saw a while back.
http://www.muppetlabs.com/~breadbox/sof ... eensy.htmlAndreas
Re: Minimal c program

Posted:
Thu Jun 20, 2013 6:42 am
by LamsonNguyen
Agreed, no words can express how awesome it is.
