1 \ *****************************************************************************
2 \ * Copyright (c) 2004, 2011 IBM Corporation
3 \ * All rights reserved.
4 \ * This program and the accompanying materials
5 \ * are made available under the terms of the BSD License
6 \ * which accompanies this distribution, and is available at
7 \ * http://www.opensource.org/licenses/bsd-license.php
10 \ * IBM Corporation - initial implementation
11 \ ****************************************************************************/
14 : fcode-revision ( -- n )
15 00030000 \ major * 65536 + minor
19 next-ip read-fcode-num32
20 ?compile-mode IF literal, THEN
24 next-ip read-fcode-string
25 ?compile-mode IF fc-string, align postpone count THEN
29 next-ip read-fcode# get-token drop ?compile-mode IF literal, THEN
32 : ?jump-direction ( n -- )
34 10000 - \ Create cell-sized negative value
36 fcode-offset - \ IP is already behind offset, so subtract offset size
44 0 >r BEGIN dup @ 0= WHILE >r REPEAT
45 BEGIN r> dup WHILE swap REPEAT
55 dup 80 and IF FF00 or THEN \ Fake 16-bit signed offset
59 : b?branch ( flag -- )
61 read-fcode-offset ?negative IF
62 dest-on-top postpone until
68 fcode-offset jump-n-ip \ Skip over offset value
71 ?jump-direction jump-n-ip
80 dest-on-top postpone again
83 get-ip next-ip fcode@ B2 = IF
90 read-fcode-offset ?jump-direction jump-n-ip
95 ?compile-mode IF postpone begin THEN
99 ?compile-mode IF postpone then THEN
103 <semicolon> compile, reveal
111 : b(case) ( sel -- sel )
121 read-fcode-offset drop \ read and discard offset
126 read-fcode-offset drop
131 read-fcode-offset drop
136 read-fcode-offset drop
141 read-fcode-offset drop
146 read-fcode-offset drop
155 : fc-instance ( -- ) \ Mark next defining word as instance-specific.
159 : new-token \ unnamed local fcode function
160 align here next-ip read-fcode# 0 swap set-token
163 : external-token ( -- ) \ named local fcode function
164 next-ip read-fcode-string
165 \ fc-instance? IF cr ." ext instance token: " 2dup type ." in " pwd cr THEN
166 header ( str len -- ) \ create a header in the current dictionary entry
172 s" x" get-ip >r next-ip read-fcode# r> set-ip (u.) $cat strdup
178 \ decide wether or not to give a new token an own name in the dictionary
183 next-ip read-fcode-string 2drop \ Forget about the name
190 get-token drop ( val xt )
192 dup <value> = over <defer> = OR IF
193 \ Destination is value or defer
203 <create> <> IF ( val xt )
204 TRUE ABORT" Invalid destination for FCODE b(to)"
206 dup cell+ @ ( val xt @xt+1cell )
207 dup <instancevalue> <> swap <instancedefer> <> AND IF
208 TRUE ABORT" Invalid destination for FCODE b(to)"
210 \ Destination is instance-value or instance-defer
211 >body @ ( val instance-offset )
213 literal, postpone >instance postpone !
223 <create> , \ Needed for "(instance?)" for example
225 (create-instance-var)
226 FALSE TO fc-instance?
235 <create> , \ Needed for "(instance?)"
237 0 (create-instance-var)
238 FALSE TO fc-instance?
246 <constant> , , reveal
250 cr cr ." Uninitialized defer word has been executed!" cr cr
256 <create> , \ Needed for "(instance?)"
258 ['] undefined-defer (create-instance-var)
260 FALSE TO fc-instance?
263 postpone undefined-defer
272 : b(field) ( E: addr -- addr+offset ) ( F: offset size -- offset+size )
273 <colon> , over literal,
280 : b(buffer:) ( E: -- a-addr) ( F: size -- )
282 <create> , \ Needed for "(instance?)"
284 (create-instance-buf)
285 FALSE TO fc-instance?
292 : suspend-fcode ( -- )
293 noop \ has to be implemented more efficiently ;-)
340 cr ." FCode# " fcode-num @ . ." not assigned!"
341 cr ." FCode evaluation aborted." cr
342 ." ( -- S:" depth . ." R:" rdepth . ." ) " .s cr
347 FFF 800 DO ['] ferror 0 i set-token LOOP
350 : byte-load ( addr xt -- )
356 dup 1 = IF drop ['] rb@ THEN to fcode-rb@
363 cr ." Ambiguous stack depth after byte-load!"
364 cr ." FCode evaluation aborted." cr cr
366 restore-evaluator-state
371 \ Functions for accessing memory ... since some FCODE programs use the normal
372 \ memory access functions for accessing MMIO memory, too, we got to use a little
373 \ hack to support them: When address is bigger than MIN-RAM-SIZE, assume the
374 \ FCODE is trying to access MMIO memory and use the register based access
376 : fc-c@ ( addr -- byte ) dup MIN-RAM-SIZE > IF rb@ ELSE c@ THEN ;
377 : fc-w@ ( addr -- word ) dup MIN-RAM-SIZE > IF rw@ ELSE w@ THEN ;
378 : fc-<w@ ( addr -- word ) fc-w@ dup 8000 >= IF 10000 - THEN ;
379 : fc-l@ ( addr -- long ) dup MIN-RAM-SIZE > IF rl@ ELSE l@ THEN ;
380 : fc-<l@ ( addr -- long ) fc-l@ signed ;
381 : fc-x@ ( addr -- dlong ) dup MIN-RAM-SIZE > IF rx@ ELSE x@ THEN ;
382 : fc-c! ( byte addr -- ) dup MIN-RAM-SIZE > IF rb! ELSE c! THEN ;
383 : fc-w! ( word addr -- ) dup MIN-RAM-SIZE > IF rw! ELSE w! THEN ;
384 : fc-l! ( long addr -- ) dup MIN-RAM-SIZE > IF rl! ELSE l! THEN ;
385 : fc-x! ( dlong addr -- ) dup MIN-RAM-SIZE > IF rx! ELSE x! THEN ;
387 : fc-fill ( add len byte -- ) 2 pick MIN-RAM-SIZE > IF rfill ELSE fill THEN ;
388 : fc-move ( src dst len -- )
389 2 pick MIN-RAM-SIZE > \ Check src
390 2 pick MIN-RAM-SIZE > \ Check dst
391 OR IF rmove ELSE move THEN
394 \ Destroy virtual mapping (should maybe also update "address" property here?)
395 : free-virtual ( virt size -- )
396 s" map-out" $call-parent
399 \ Map the specified region, return virtual address
400 : map-low ( phys.lo ... size -- virt )
401 my-space swap s" map-in" $call-parent
405 : mac-address ( -- mac-str mac-len )
406 s" local-mac-address" get-my-property IF
411 \ Output line and column number - not used yet
417 \ Display device status
418 : display-status ( n -- )
419 ." Device status: " . cr
422 \ Obsolete variables:
426 \ Obsolete: Allocate memory for DMA
427 : dma-alloc ( byte -- virtual )
428 s" dma-alloc" $call-parent
431 \ Obsolete: Get params property
432 : my-params ( -- addr len )
433 s" params" get-my-property IF
438 \ Obsolete: Convert SBus interrupt level to CPU interrupt level
439 : sbus-intr>cpu ( sbus-intr# -- cpu-intr# )
442 \ Obsolete: Set "intr" property
443 : intr ( interrupt# vector -- )
444 >r sbus-intr>cpu encode-int r> encode-int+ s" intr" property
447 \ Obsolete: Create the "name" property
448 : driver ( addr len -- )
449 encode-string s" name" property
452 \ Obsolete: Return type of CPU
453 : processor-type ( -- cpu-type )
457 \ Obsolete: Return firmware version
458 : firmware-version ( -- n )
459 10000 \ Just a dummy value
462 \ Obsolete: Return fcode-version
463 : fcode-version ( -- n )