Re: [Flashforth-devel] Fwd: Re: C function with more parameters in W0-W7
Brought to you by:
oh2aun
From: om1zz <om...@vo...> - 2015-06-09 07:08:46
|
Have you read my note in the Ctest.c header? :) After some experimenting I found out following trick (my current undrestanding how it works): 1. you have to enable "Init data segments" in the xc16-ld settings 2. it puts crt0 at the beginning 3. after that it places all calls to .external libs/functions 5. after that it puts FF.s 6. it jumps from crt0 at the point in FF.s you marked as ".text" (COLDLIT/WARMLIT) 7. then it runs through the FF.s as usual. I have got both floats (single lib) and Ctest (9degree test function with double lib) placed in the segment from 0x0200 to 0x2000 and FF.s from 0x2000 up (see your map file). Of course, that is ok for 128kB flash parts (43kWords), but we need to place all the external functions somewhere above 196kB flash, as it is my understanding FF can only address "lower 64kWords" (what is still quite a lot for a forth when you can call external functions out of it). With a 512kB dspic33EP flash parts it could be an interesting combination. When using double (64bit), ie. in the Ctest.c 9degree demo, you must enable "Use 64-bit double" in xc16-gcc settings, otherwise the double will work as a float only (even when declared as a double). Igor. ______________________________________________________________ > Od: Mikael Nordman <mik...@fl...> > Komu: <fla...@li...> > Datum: 08.06.2015 22:18 > Předmět: Re: [Flashforth-devel] Fwd: Re: C function with more parameters in W0-W7 > >And to answer my own question. >It can be done like below > > >__attribute__((address(0x1000))) >float Ctest(unsigned short a, unsigned short b, unsigned long int c, >float x, float y) >{ > a = a + 100; > b = b / a; > c = c * b; > x = sqrtf( (float)c - x ); > y = y / x; > return y; // 4.5894021E-1 >} > > >On 08.06.2015 23:03, Mikael Nordman wrote: >> How did you solve it ? >> >> In my tests you get this problem because the Ctest.c file is linked after >> the FF binary code into a the area where FF thinks is free space for the >> dictionary. Compiling some FF code will then overwrite the C code. >> >> This happens if you also include the float package into the compilation. >> If you do not include the float package, Ctest code will fit into memory >> before the FF binary code and all is fine. >> >> How can the linker be forced to link the C-code before the FF code ? >> Bu defining some new sections for the linker perhaps. >> >> There is no reason to save W0..W7 before calling the C function because >> these registers are not 'live' in FF between words. >> >> Mikael >> >> On 06.06.2015 19:30, om1zz wrote: >>> Solved, see examples. >>> I. >>> >>> _____________________________________________________________ >>>>> Od: "om1zz" <om...@vo...> >>>>> Komu: Mikael Nordman <mik...@fl...> >>>>> Datum: 04.06.2015 19:00 >>>>> Předmět: C function with more parameters in W0-W7 >>>>> >>>>> MIke, I cope with following issue: >>>>> >>>>> I have a Cfunction, with 5 parameters, returning float. >>>>> >>>>> So I am using W0-W7 for params. >>>>> >>>>> The strange: >>>>> First time after the fresh flash the Cfun (when pasting the below >>>>> into teraterm) returns good result: >>>>> >>>>> decimal 100 2000 5. $0fdb $4049 $0fdb $4049 Ctest hex ok<#,ram> fa36 >>>>> 3eea >>>>> >>>>> I can do it repeatedly, I always get good results. >>>>> >>>>> decimal 100 2000 5. $0fdb $4049 $0fdb $4049 Ctest hex ok<#,ram> fa36 >>>>> 3eea >>>>> decimal 100 2000 5. $0fdb $4049 $0fdb $4049 Ctest hex ok<#,ram> fa36 >>>>> 3eea fa36 3eea >>>>> decimal 100 2000 5. $0fdb $4049 $0fdb $4049 Ctest hex ok<#,ram> fa36 >>>>> 3eea fa36 3eea fa36 3eea >>>>> >>>>> In the moment as I do something via prompt (before or after playing >>>>> with Cfun), the Cfun returns garbage (and also it corrupts the system). >>>>> >>>>> For example, I cannot get good results when after the fresh flash I do: >>>>> $0fdb $4049 2constant pi >>>>> decimal 100 2000 5. pi pi Ctest hex >>>>> >>>>> I've tried push/pop W4-W7, but the same. >>>>> I. >>>>> >>>> >>>> >>>> >>>> ------------------------------------------------------------------------------ >>>> >>>> _______________________________________________ >>>> Flashforth-devel mailing list >>>> Fla...@li... >>>> https://lists.sourceforge.net/lists/listinfo/flashforth-devel >>>> > >------------------------------------------------------------------------------ >_______________________________________________ >Flashforth-devel mailing list >Fla...@li... >https://lists.sourceforge.net/lists/listinfo/flashforth-devel > |