Difference: CallingCFunction (4 vs. 5)

Revision 52020-08-06 - PeterSchmid

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Calling C Functions from Forth and Vice Versa

Line: 17 to 17
 
r5 Variable register 2 Y DO Limit  
r6 Variable register 3 Y Top Of Stack TOS  
r7 Variable register 4 Y Data stack pointer SPS  
Changed:
<
<
r8 Variable register 5 Y unused  
r9 Platform register (usage defined by platform in use) Y unused  
>
>
r8 Variable register 5 Y TOS copy  
r9 Platform register (usage defined by platform in use) Y SPS copy  
 
r10 Variable register 7 Y unused  
r11 Variable register 8 Y unused  
r12 Intra-procedure-call scratch register N unused 6
Line: 57 to 57
 

Calling Forth Words from C Functions

Changed:
<
<
Data Stack Pointer SPS is in R7 and Top Of Stack TOS is in R6. R7 can't be a register variable, that's why R12 is used as a temporary storage.

register uint32_t TOS asm ("r6");
register uint32_t PSP asm ("r12");

TOS = TOS;
PSP = PSP;
>
>
Data Stack Pointer SPS is in R7 and Top Of Stack TOS is in R6. R7 can't be a register variable, that's why R9 is used as a temporary storage.
  C function FS_include() from fs.c calls the Forth words FS_type and FS_evaluate.

Line: 83 to 75
  FIL fil; /* File object */ FRESULT fr; /* FatFs return code */
Deleted:
<
<
register uint32_t TOS asm ("r6"); register uint32_t PSP asm ("r12");

TOS = TOS; PSP = PSP;

  memcpy(path, str, count); line[count] = 0;
Line: 116 to 102
 
@ -----------------------------------------------------------------------------
		Wortbirne Flag_visible, "include"

Changed:
<
<
@ ( "filename" -- ) Interprets the content of the file.
>
>
@ ( "filename" any -- any ) Interprets the content of the file.
 // void FS_include(uint8_t *str, int count) @ ----------------------------------------------------------------------------- include:
Changed:
<
<
push {r0-r3, lr} bl token // ( -- c-addr len )
>
>
push {lr} bl token @ ( -- c-addr len ) incl:
  movs r1, tos // len -> count drop movs r0, tos // c-addr -> str drop
Changed:
<
<
movs r12, psp // get psp
>
>
movs r9, psp // get psp movs r8, tos // get tos
  bl FS_include
Changed:
<
<
movs psp, r12 // update psp pop {r0-r3, pc}
>
>
movs psp, r9 // update psp movs tos, r8 // update tos pop {pc}
 

The C function FS_include() from fs.c calls the Forth word evaluate by the FS_evaluate() function.

Line: 137 to 126
 // void FS_evaluate(uint8_t* str, int count); .global FS_evaluate FS_evaluate:
Changed:
<
<
push {r4, r5, r7, lr} movs psp, r12 // get psp
>
>
push {r4-r7, lr} movs psp, r9 // get psp movs tos, r8 // get tos
  pushdatos movs tos, r0 // str pushdatos movs tos, r1 // count bl evaluate
Changed:
<
<
movs r12, psp // update psp pop {r4, r5, r7, pc}
>
>
movs r9, psp // update psp movs r8, tos // update tos pop {r4-r7, pc}
 

-- Peter Schmid - 2020-07-13

 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback