| 1 : |
anton
|
1.1
|
\ ASSEMBLER, CODE etc. |
| 2 : |
|
|
|
| 3 : |
anton
|
1.23
|
\ Copyright (C) 1995,1996,1997,1999,2003,2007,2010 Free Software Foundation, Inc. |
| 4 : |
anton
|
1.2
|
|
| 5 : |
|
|
\ This file is part of Gforth. |
| 6 : |
|
|
|
| 7 : |
|
|
\ Gforth is free software; you can redistribute it and/or |
| 8 : |
|
|
\ modify it under the terms of the GNU General Public License |
| 9 : |
anton
|
1.16
|
\ as published by the Free Software Foundation, either version 3 |
| 10 : |
anton
|
1.2
|
\ of the License, or (at your option) any later version. |
| 11 : |
|
|
|
| 12 : |
|
|
\ This program is distributed in the hope that it will be useful, |
| 13 : |
|
|
\ but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 : |
|
|
\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 : |
|
|
\ GNU General Public License for more details. |
| 16 : |
|
|
|
| 17 : |
|
|
\ You should have received a copy of the GNU General Public License |
| 18 : |
anton
|
1.16
|
\ along with this program. If not, see http://www.gnu.org/licenses/. |
| 19 : |
anton
|
1.2
|
|
| 20 : |
anton
|
1.1
|
\ does not include the actual assembler (which is machine-dependent), |
| 21 : |
|
|
\ only words like CODE that are implementation-dependent, but can be |
| 22 : |
|
|
\ defined for all machines. |
| 23 : |
|
|
|
| 24 : |
|
|
vocabulary assembler ( -- ) \ tools-ext |
| 25 : |
anton
|
1.21
|
\g A vocubulary: Replaces the wordlist at the top of the search order |
| 26 : |
|
|
\g with the assembler wordlist. |
| 27 : |
anton
|
1.1
|
|
| 28 : |
crook
|
1.9
|
: init-asm ( -- ) \ gforth |
| 29 : |
anton
|
1.21
|
\g Pushes the assembler wordlist on the search order. |
| 30 : |
anton
|
1.1
|
also assembler ; |
| 31 : |
anton
|
1.21
|
|
| 32 : |
anton
|
1.7
|
: code ( "name" -- colon-sys ) \ tools-ext |
| 33 : |
anton
|
1.21
|
\G Start a native code definition that runs in the context of the |
| 34 : |
|
|
\G Gforth virtual machine (engine). Such a definition is not |
| 35 : |
|
|
\G portable between Gforth installations, so we recommend using |
| 36 : |
|
|
\G @code{abi-code} instead of @code{code}. You have to end a |
| 37 : |
|
|
\G @code{code} definition with a dispatch to the next virtual |
| 38 : |
|
|
\G machine instruction. |
| 39 : |
anton
|
1.6
|
header |
| 40 : |
anton
|
1.12
|
here >body cfa, |
| 41 : |
anton
|
1.6
|
defstart init-asm ; |
| 42 : |
anton
|
1.1
|
|
| 43 : |
dvdkhlng
|
1.19
|
[ifdef] doabicode: |
| 44 : |
anton
|
1.22
|
: abi-code ( "name" -- colon-sys ) \ gforth abi-code |
| 45 : |
dvdkhlng
|
1.20
|
\G Start a native code definition that is called using the platform's |
| 46 : |
|
|
\G ABI conventions corresponding to the C-prototype: |
| 47 : |
|
|
\G @example |
| 48 : |
anton
|
1.21
|
\G Cell *function(Cell *sp, Float **fpp); |
| 49 : |
dvdkhlng
|
1.20
|
\G @end example |
| 50 : |
anton
|
1.21
|
\G The FP stack pointer is passed in by providing a reference to a |
| 51 : |
|
|
\G memory location containing the FP stack pointer and is passed |
| 52 : |
|
|
\G out by storing the changed FP stack pointer there (if necessary). |
| 53 : |
dvdkhlng
|
1.18
|
header |
| 54 : |
|
|
doabicode: cfa, |
| 55 : |
|
|
defstart init-asm ; |
| 56 : |
dvdkhlng
|
1.19
|
[endif] |
| 57 : |
dvdkhlng
|
1.18
|
|
| 58 : |
anton
|
1.1
|
: (;code) ( -- ) \ gforth |
| 59 : |
|
|
\ execution semantics of @code{;code} |
| 60 : |
anton
|
1.15
|
r> latestxt code-address! ; |
| 61 : |
anton
|
1.1
|
|
| 62 : |
anton
|
1.6
|
:noname ( -- colon-sys ) |
| 63 : |
anton
|
1.15
|
align here latestxt code-address! |
| 64 : |
anton
|
1.6
|
defstart init-asm ; |
| 65 : |
pazsan
|
1.4
|
:noname ( colon-sys1 -- colon-sys2 ) \ tools-ext semicolon-code |
| 66 : |
anton
|
1.1
|
( create the [;code] part of a low level defining word ) |
| 67 : |
anton
|
1.13
|
;-hook postpone (;code) basic-block-end finish-code ?struc postpone [ |
| 68 : |
anton
|
1.3
|
defstart init-asm ; |
| 69 : |
anton
|
1.7
|
interpret/compile: ;code ( compilation. colon-sys1 -- colon-sys2 ) \ tools-ext semicolon-code |
| 70 : |
anton
|
1.21
|
\g The code after @code{;code} becomes the behaviour of the last |
| 71 : |
|
|
\g defined word (which must be a @code{create}d word). The same |
| 72 : |
anton
|
1.22
|
\g caveats apply as for @code{code}, so we recommend using |
| 73 : |
|
|
\g @code{;abi-code} instead. |
| 74 : |
anton
|
1.1
|
|
| 75 : |
anton
|
1.22
|
[ifdef] do;abicode: |
| 76 : |
|
|
: !;abi-code ( addr -- ) |
| 77 : |
|
|
latestxt do;abicode: any-code! ; |
| 78 : |
|
|
|
| 79 : |
|
|
: ;abi-code ( -- ) \ gforth semicolon-abi-code |
| 80 : |
|
|
['] !;abi-code does>-like postpone [ init-asm ; immediate |
| 81 : |
|
|
[then] |
| 82 : |
|
|
|
| 83 : |
anton
|
1.1
|
: end-code ( colon-sys -- ) \ gforth end_code |
| 84 : |
anton
|
1.21
|
\G End a code definition. Note that you have to assemble the |
| 85 : |
|
|
\G return from the ABI call (for @code{abi-code}) or the dispatch |
| 86 : |
|
|
\G to the next VM instruction (for @code{code} and @code{;code}) |
| 87 : |
|
|
\G yourself. |
| 88 : |
anton
|
1.15
|
latestxt here over - flush-icache |
| 89 : |
anton
|
1.1
|
previous ?struc reveal ; |