1 /* -*-C-*-
2 
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4     1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
5     2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Massachusetts
6     Institute of Technology
7 
8 This file is part of MIT/GNU Scheme.
9 
10 MIT/GNU Scheme is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or (at
13 your option) any later version.
14 
15 MIT/GNU Scheme is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with MIT/GNU Scheme; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
23 USA.
24 
25 */
26 
27 /* Headers for the FFI (foreign function interface). */
28 
29 /* This file declares all of the C functions needed by a shim.  It is
30    installed as mit-scheme.h and represents the interface between the
31    shims and the machine.  It should not include any other headers,
32    and should minimize dependencies on the exact configuration of the
33    machine.  Thus it declares teensy functions like empty_list(). */
34 
35 /* This is redundant, but avoids the need for object.h, config.h, types.h... */
36 typedef unsigned long SCM;
37 
38 extern char* cstack_top (void);
39 extern void cstack_push (void * addr, int bytes);
40 extern char* cstack_lpop (char* tos, int bytes);
41 extern void cstack_pop (char* tos);
42 
43 #define CSTACK_PUSH(TYPE,VAR)					\
44   cstack_push (((void *)(&VAR)), sizeof (TYPE));
45 
46 /* "Local" CStack pops keep the top-of-stack in a local variable
47    (TOS).  Thus after an abort the trampoline can start again from the
48    undisturbed top of the obstack. */
49 #define CSTACK_LPOP(TYPE,VAR,TOS)					\
50   TOS = cstack_lpop (TOS, sizeof (TYPE));				\
51   VAR = *(TYPE *)TOS;
52 
53 typedef SCM (*CalloutTrampOut)(void);
54 typedef SCM (*CalloutTrampIn)(void);
55 extern void callout_seal (CalloutTrampIn tramp);
56 extern void callout_unseal (CalloutTrampIn expected);
57 extern SCM callout_continue (CalloutTrampIn tramp);
58 extern char* callout_lunseal (CalloutTrampIn expected);
59 extern void callout_pop (char* tos);
60 
61 typedef void (*CallbackKernel)(void);
62 extern void callback_run_kernel (long callback_id, CallbackKernel kernel);
63 extern char* callback_lunseal (CallbackKernel expected);
64 extern void callback_run_handler (long callback_id, SCM arglist);
65 extern void callback_return (char* tos);
66 
67 /* Converters. */
68 
69 extern long arg_long (int argn);
70 extern unsigned long arg_ulong (int argn);
71 extern double arg_double (int argn);
72 extern void* arg_alien_entry (int argn);
73 extern void* arg_pointer (int argn);
74 
75 extern SCM long_to_scm (const long i);
76 extern SCM ulong_to_scm (const unsigned long i);
77 extern SCM double_to_scm (const double d);
78 extern SCM pointer_to_scm (const void* p);
79 extern SCM struct_to_scm (const void* p, int size);
80 
81 extern SCM cons_alien (const void* p);
82 
83 extern long long_value (void);
84 extern unsigned long ulong_value (void);
85 extern double double_value (void);
86 extern void* pointer_value (void);
87 
88 /* Utilities: */
89 
90 extern void check_number_of_args (int num);
91 extern SCM unspecific (void);
92 extern SCM empty_list (void);
93 extern int flovec_length (SCM vector);
94 extern double* flovec_loc (SCM vector);
95 extern double flovec_ref (SCM vector, int index);
96 
97 #ifndef MIT_SCHEME /* Do not include in the microcode, just shims. */
98 extern SCM cons (SCM car, SCM cdr);
99 /* For debugging messages from shim code. */
100 extern void outf_error (const char *, ...);
101 extern void outf_flush_error (void);
102 extern void error_external_return (void);
103 #endif
104