Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: ccall.fth | |
4 | \ | |
5 | \ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | \ | |
7 | \ - Do no alter or remove copyright notices | |
8 | \ | |
9 | \ - Redistribution and use of this software in source and binary forms, with | |
10 | \ or without modification, are permitted provided that the following | |
11 | \ conditions are met: | |
12 | \ | |
13 | \ - Redistribution of source code must retain the above copyright notice, | |
14 | \ this list of conditions and the following disclaimer. | |
15 | \ | |
16 | \ - Redistribution in binary form must reproduce the above copyright notice, | |
17 | \ this list of conditions and the following disclaimer in the | |
18 | \ documentation and/or other materials provided with the distribution. | |
19 | \ | |
20 | \ Neither the name of Sun Microsystems, Inc. or the names of contributors | |
21 | \ may be used to endorse or promote products derived from this software | |
22 | \ without specific prior written permission. | |
23 | \ | |
24 | \ This software is provided "AS IS," without a warranty of any kind. | |
25 | \ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, | |
26 | \ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A | |
27 | \ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN | |
28 | \ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR | |
29 | \ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR | |
30 | \ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN | |
31 | \ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR | |
32 | \ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE | |
33 | \ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, | |
34 | \ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF | |
35 | \ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. | |
36 | \ | |
37 | \ You acknowledge that this software is not designed, licensed or | |
38 | \ intended for use in the design, construction, operation or maintenance of | |
39 | \ any nuclear facility. | |
40 | \ | |
41 | \ ========== Copyright Header End ============================================ | |
42 | \ ccall.fth 2.6 94/09/06 | |
43 | \ Copyright 1985-1990 Bradley Forthware | |
44 | ||
45 | \ Usage: | |
46 | \ Subroutine calls: | |
47 | \ | |
48 | \ " external-procedure-name" $ccall | |
49 | \ or | |
50 | \ " external-procedure-name" $ccall: name { args -- results } | |
51 | ||
52 | \ NOTE: sc1 through sc6 (%l1 through %l6) are destroyed | |
53 | \ | |
54 | \ Data references: | |
55 | \ | |
56 | \ " external-name" <register-name> $set-external | |
57 | ||
58 | \ Assembler macro to assemble code to call a named C subroutine. | |
59 | \ This is an implementation word used by "ccall:". | |
60 | \ The code to transfer the arguments from the stack must be generated | |
61 | \ before executing this macro. Afterwards, the code to transfer the | |
62 | \ results back onto the stack must be generated. "ccall" generates: | |
63 | \ | |
64 | \ sethi %hi(c_entry_point), %l0 | |
65 | \ call do-ccall | |
66 | \ or %l0, %lo(c_entry_point), %l0 | |
67 | \ | |
68 | \ do-ccall is a shared procedure that saves and restores the Forth | |
69 | \ virtual machine state before calling the C procedure. | |
70 | ||
71 | : $ccall ( procedure-name-adr,len -- ) | |
72 | [ also assembler ] | |
73 | ?$add-symbol ( sym# ) | |
74 | ||
75 | \ To optimize the generated code, we move the "or" half of the | |
76 | \ "set" instruction into the delay slot of the call, generating | |
77 | \ relocation table entries accordingly. | |
78 | ||
79 | dictionary-size over 0 sparc-hi22 make-relocation ( sym# ) | |
80 | 0 %l0 sethi ( sym# ) | |
81 | ||
82 | do-ccall call ( sym# ) | |
83 | ||
84 | dictionary-size swap 0 sparc-lo10 make-relocation ( ) | |
85 | %l0 0 %l0 or | |
86 | [ previous ] | |
87 | ; | |
88 | : $ccall: \ name ( procedure-name$ -- procedure-name$ 'subroutine-call ) | |
89 | ['] $ccall code current token@ context token! | |
90 | ; | |
91 | also assembler definitions | |
92 | : $set-external ( name$ register -- ) | |
93 | dictionary-size 2swap $set-reference ( register ) | |
94 | 0 over sethi ( register ) | |
95 | 0 over or | |
96 | ; | |
97 | previous definitions |