home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / ixemul-45.0-src.tgz / tar.out / contrib / ixemul / library / ixemul.h < prev    next >
C/C++ Source or Header  |  1996-10-01  |  9KB  |  345 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License as published by the Free Software Foundation; either
  8.  *  version 2 of the License, or (at your option) any later version.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public
  16.  *  License along with this library; if not, write to the Free
  17.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  *  ixemul.h,v 1.1.1.1 1994/04/04 04:29:38 amiga Exp
  20.  *
  21.  *  ixemul.h,v
  22.  * Revision 1.1.1.1  1994/04/04  04:29:38  amiga
  23.  * Initial CVS check in.
  24.  *
  25.  *  Revision 1.4  1993/11/05  22:14:40  mwild
  26.  *  changes there, here...
  27.  *
  28.  *  Revision 1.3  1992/10/20  16:32:33  mwild
  29.  *  *** empty log message ***
  30.  *
  31.  *  Revision 1.2  1992/07/04  19:25:26  mwild
  32.  *  change __rwport to reflect the current state of the (now global) async port
  33.  *
  34.  * Revision 1.1  1992/05/14  20:36:14  mwild
  35.  * Initial revision
  36.  *
  37.  */
  38.  
  39. #ifndef _IXEMUL_H_
  40. #define _IXEMUL_H_
  41.  
  42. #ifdef START
  43.  
  44. /* definitions for the assembler startup file */
  45.  
  46. /* when I've REALLY lots of free time, I'll rewrite header files, but now... */
  47.  
  48. /* amazingly works, contains only defines ;-)) */
  49. #include <exec/alerts.h>
  50.  
  51. #define _LVOOpenLibrary        -0x228
  52. #define _LVOCloseLibrary     -0x19e
  53. #define _LVOAlert        -0x6c
  54. #define _LVOFreeMem        -0xd2
  55. #define _LVORemove        -0xfc
  56.  
  57. #define RTC_MATCHWORD    0x4afc
  58. #define RTF_AUTOINIT    (1<<7)
  59.  
  60. #define LIBF_CHANGED    (1<<1)
  61. #define LIBF_SUMUSED    (1<<2)
  62. /* seems there is an assembler bug in expression evaluation here.. */
  63. #define LIBF_CHANGED_SUMUSED 0x6
  64. #define LIBF_DELEXP    (1<<3)
  65. #define LIBB_DELEXP    3
  66.  
  67. #define LN_TYPE        8
  68. #define LN_NAME        10
  69. #define NT_LIBRARY    9
  70. #define MP_FLAGS    14
  71. #define PA_IGNORE    2
  72.  
  73. #define LIST_SIZEOF    14
  74.  
  75. #define THISTASK    276
  76.  
  77. #define INITBYTE(field,val)    .word 0xe000; .word (field); .byte (val); .byte 0
  78. #define INITWORD(field,val)    .word 0xd000; .word (field); .word (val)
  79. #define INITLONG(field,val)    .word 0xc000; .word (field); .long (val)
  80.  
  81. /*
  82.  * our library base.. 
  83.  */
  84.  
  85. /* struct library */
  86. #define    IXBASE_NODE    0
  87. #define IXBASE_FLAGS    14
  88. #define IXBASE_NEGSIZE    16
  89. #define IXBASE_POSSIZE    18
  90. #define IXBASE_VERSION    20
  91. #define IXBASE_REVISION    22
  92. #define IXBASE_IDSTRING    24
  93. #define IXBASE_SUM    28
  94. #define IXBASE_OPENCNT    32
  95. #define IXBASE_LIBRARY    34    /* size of library */
  96.  
  97. /* custom part */
  98. #define IXBASE_MYFLAGS        (IXBASE_LIBRARY + 0)
  99. #define IXBASE_SEGLIST        (IXBASE_MYFLAGS + 2)
  100. #define IXBASE_C_PRIVATE    (IXBASE_SEGLIST + 4)
  101.  
  102. #else  /* C-part */
  103.  
  104. #include <exec/types.h>
  105. #include <exec/libraries.h>
  106. #include <exec/execbase.h>
  107. #include <exec/ports.h>
  108. #include <libraries/dosextens.h>
  109. #include <dos/notify.h>
  110.  
  111. #include <sys/types.h>
  112.  
  113. #ifdef _KERNEL
  114. #define _INTERNAL_FILE
  115. #endif
  116.  
  117. #include <sys/file.h>
  118. #include <sys/param.h>
  119. #include <packets.h>
  120. #include <sys/syscall.h>
  121. #include <sys/ixnet_syscall.h>
  122. #include <sys/unix_socket.h>
  123. #include <signal.h>
  124. #include <user.h>
  125.  
  126. #include <errno.h>
  127.  
  128. /* ix_flags defines */
  129.  
  130.    #define ix_profile_method_mask             0x0000C000
  131.    #define ix_create_enforcer_hit             0x00002000
  132.    #define ix_do_not_flush_library             0x00001000
  133.    #define ix_allow_amiga_wildcard             0x00000800
  134.    #define ix_no_insert_disk_requester             0x00000400
  135.    #define ix_unix_pattern_matching_case_sensitive    0x00000200
  136. /* #define ix_unix_pattern_matching             0x00000100 obsolete */
  137. /* #define ix_no_ces_then_open_console             0x00000080 obsolete */
  138.    #define ix_ignore_global_env             0x00000040
  139. /* #define ix_disable_fibcache                 0x00000020 obsolete */
  140. /* #define ix_translate_dots                 0x00000010 obsolete */
  141. /* #define ix_watch_stack                 0x00000008 obsolete */
  142. /* #define ix_force_translation             0x00000004 obsolete */
  143. /* #define ix_translate_symlinks             0x00000002 obsolete */
  144.    #define ix_translate_slash                0x00000001
  145.  
  146. /* ix_profile_method defines */
  147.  
  148. /* only if the pc is in the program is a hit recorded */
  149. #define IX_PROFILE_PROGRAM     0x00000000
  150.  
  151. /* while the task is running, the last function in your program that was
  152.    entered records a hit */
  153. #define IX_PROFILE_TASK     0x00004000
  154.  
  155. /* always record a hit (again the last function that was entered), even
  156.    if another task is running */
  157. #define IX_PROFILE_ALWAYS    0x00008000
  158.  
  159. /* not used */
  160. #define IX_PROFILE_UNUSED    0x0000C000
  161.  
  162.  
  163. /* ix_network_type enum */
  164.  
  165. enum
  166. {
  167.   IX_NETWORK_AUTO,
  168.   IX_NETWORK_NONE,
  169.   IX_NETWORK_AS225,
  170.   IX_NETWORK_AMITCP,
  171.   IX_NETWORK_END_OF_ENUM
  172. };
  173.  
  174. /* configure this to the number of hash queues you like, 
  175.  * use a prime number !!
  176.  */
  177. #define IX_NUM_SLEEP_QUEUES    31
  178.  
  179. /* the number of available ptys ( '/dev/pty[p-u][0-9a-f]' ) */
  180. #define IX_NUM_PTYS        (6 * 16)
  181.  
  182. #define IX_PTY_SLAVE        0x03  /* 0011 */
  183. #define IX_PTY_MASTER        0x0c  /* 1100 */
  184.  
  185. #define IX_PTY_OPEN        0x05  /* 0101 */
  186. #define IX_PTY_CLOSE        0x0a  /* 1010 */
  187.  
  188. struct ixemul_base {
  189.   struct Library        ix_lib;
  190.  
  191. /* don't use the remainder of the library base. The contents can change
  192.    without warning in the future. */
  193. #ifdef _KERNEL
  194.   unsigned char            ix_myflags;    /* used by start.s */
  195.   unsigned char            ix_pad;
  196.   BPTR                ix_seg_list;    /* used by start.s */
  197.  
  198.   /* the global file table with current size */
  199.   struct file            *ix_file_tab;
  200.   struct file            *ix_fileNFILE;
  201.   struct file            *ix_lastf;
  202.  
  203.   struct SignalSemaphore    ix_semaph;
  204.   int                ix_membuf_limit;
  205.   
  206.   /* multiplier for id_BytesPerBlock to get to st_blksize, default 64 */
  207.   int                ix_fs_buf_factor;
  208.  
  209.   unsigned long            ix_flags;
  210.  
  211.   struct MinList        ix_sleep_queues [IX_NUM_SLEEP_QUEUES];
  212.  
  213.   struct MinList        ix_socket_list;
  214.   long                      ix_gmt_offset;
  215.   int                ix_network_type;
  216.  
  217.   int                ix_next_free_port;
  218.   struct Task                  *ix_task_switcher;
  219.   char                      **ix_global_environment;
  220.   struct NotifyRequest          ix_notify_request;
  221.   char                ix_ptys[IX_NUM_PTYS];
  222.   struct ix_unix_name          *ix_unix_names;
  223. #endif
  224. };
  225.  
  226. #define syscall(vec, args...) \
  227.   ({register int (*_sc)()=(void *)(&((char *)ixemulbase)[-((vec)+4)*6]); _sc(args);})
  228.  
  229. #define netcall(vec, args...) \
  230.   ({register int (*_sc)()=(void *)(&((char *)u.u_ixnetbase)[-((vec)+4)*6]); _sc(args);})
  231.  
  232. /* Structure to pass ixemul.library settings to/from the library base */
  233. struct ix_settings {
  234.   int version;
  235.   int revision;
  236.   unsigned long flags;
  237.   int membuf_limit;
  238.   int red_zone_size;    /* obsolete */
  239.   int fs_buf_factor;
  240.   int network_type;
  241. };
  242.  
  243. /* structure to keep track of the current SegList */
  244. struct my_seg {
  245.   BPTR    segment;    /* the thing our clients can use */
  246.   enum { LOADSEG, RESSEG } type;
  247.   char  *name;        /* name of the executable */
  248.   u_int    priv;        /* information depending on type */
  249. };
  250.  
  251. /* Environment name of ixemul settings */
  252. #define IX_ENV_SETTINGS "ixemul.prefs"
  253.  
  254. void ix_set_gmt_offset(long offset);
  255. long ix_get_gmt_offset(void);
  256. struct ix_settings *ix_get_default_settings(void);
  257. struct ix_settings *ix_get_settings(void);
  258. void ix_set_settings(struct ix_settings *settings);
  259.  
  260. /* Minimum stack size to use, used in vfork() and __stack */
  261. #define STACKSIZE (16384)
  262.  
  263. #ifdef _KERNEL
  264.  
  265. #include <ixprotos.h>
  266.  
  267. extern struct ixemul_base *ixemulbase;
  268.  
  269. #define ix          (*ixemulbase)
  270. #define u          (*(struct user *)(SysBase->ThisTask->tc_TrapData))
  271. #define getuser(p)      ((struct user *)(((struct Process *)p)->pr_Task.tc_TrapData))
  272. #define betterthan68000() (SysBase->AttnFlags & (AFF_68010 | AFF_68020 | AFF_68030 | AFF_68040))
  273. #define betterthan68010() (SysBase->AttnFlags & (AFF_68020 | AFF_68030 | AFF_68040))
  274. #define gotanfpu()      (SysBase->AttnFlags & (AFF_68881 | AFF_68882))
  275.  
  276. static inline u_int get_usp (void) 
  277.   u_int res;
  278.  
  279.   asm volatile ("movel    usp,%0" : "=a" (res));
  280.   return res;
  281. }
  282.  
  283. static inline void set_usp (u_int new_usp)
  284. {
  285.   asm volatile ("movel  %0,usp" : /* no output */ : "a" (new_usp));
  286. }
  287.  
  288. static inline u_int get_sp (void) 
  289.   u_int res;
  290.  
  291.   asm volatile ("movel    sp,%0" : "=a" (res));
  292.   return res;
  293. }
  294.  
  295. static inline void set_sp (u_int new_sp)
  296. {
  297.   asm volatile ("movel  %0,sp" : /* no output */ : "a" (new_sp));
  298. }
  299.  
  300. static inline u_short get_sr (void) 
  301.   u_short res;
  302.  
  303.   asm volatile ("movew    sr,%0" : "=g" (res));
  304.   return res;
  305. }
  306.  
  307. static inline u_int get_fp (void) 
  308.   u_int res;
  309.  
  310.   asm volatile ("movel    a5,%0" : "=g" (res));
  311.   return res;
  312. }
  313.  
  314. #define PRIVATE
  315. extern struct ExecBase *SysBase;
  316. #include <inline/exec.h>
  317. #undef PRIVATE
  318.  
  319. extern struct Library *muBase;
  320. /* Multiuser inlines */
  321. #include "multiuser_inlines.h"
  322.  
  323. extern struct DosLibrary *DOSBase;
  324. #include <inline/dos.h>
  325.  
  326. #include <inline/alib.h>
  327.  
  328. #define errno (* u.u_errno)
  329.  
  330. /* useful define */
  331. #define errno_return(e, r) do { errno = (e); return (r); } while (0)
  332.  
  333. #define __srwport (u.u_sync_mp)
  334. #define __selport (u.u_select_mp)
  335.  
  336. #endif /* _KERNEL */
  337.  
  338. #endif /* START */
  339.  
  340. #endif /* _IXEMUL_H */
  341.