home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 10: Diskmags / nf_archive_10.iso / MAGS / PURE_B / PBMAG22A.MSA / MINT095S.ZIP / SRC / PROC.H < prev    next >
C/C++ Source or Header  |  1987-04-22  |  7KB  |  211 lines

  1. /*
  2. Copyright 1990,1991,1992 Eric R. Smith. All rights reserved.
  3. */
  4.  
  5. /* proc.h: defines for various process related things */
  6. #ifndef _proc_h
  7. #define _proc_h
  8.  
  9. #include "file.h"
  10.  
  11. /* a process context consists, for now, of its registers */
  12.  
  13. typedef struct _context {
  14.     long    regs[15];    /* registers d0-d7, a0-a6 */
  15.     long    usp;        /* user stack pointer (a7) */
  16.     short    sr;        /* status register */
  17.     long    pc;        /* program counter */
  18.     long    ssp;        /* supervisor stack pointer */
  19.     long    term_vec;    /* GEMDOS terminate vector (0x102) */
  20. /*
  21.  * AGK: if running on a TT and the user is playing with the FPU then we
  22.  * must save and restore the context. We should also consider this for
  23.  * I/O based co-processors, although this may be difficult due to
  24.  * possibility of a context switch in the middle of an I/O handshaking
  25.  * exchange.
  26.  */
  27.     char    fstate[216];    /* FPU internal state */
  28.     char    fregs[12*8];    /* registers fp0-fp7 */
  29.     long    fctrl[3];        /* FPCR/FPSR/FPIAR */
  30. /*
  31.  * AGK: for long (time-wise) co-processor instructions (FMUL etc.), the
  32.  * FPU returns NULL, come-again with interrupts allowed primitives. It
  33.  * is highly likely that a context switch will occur in one of these if
  34.  * running a mathematically intensive application, hence we must handle
  35.  * the mid-instruction interrupt stack. We do this by saving the extra
  36.  * 3 long words and the stack format word here.
  37.  */
  38.     short    sfmt;            /* stack frame format identifier */
  39.     long    iar;            /* instruction address */
  40.     short    internal[4];    /* four words of internal info */
  41. } CONTEXT;
  42.  
  43. #define PROC_CTXTS    2
  44. #define SYSCALL        0    /* saved context from system call    */
  45. #define CURRENT        1    /* current saved context        */
  46.  
  47. /*
  48.  * Timeout events are stored in a list; the "when" field in the event
  49.  * specifies the number of milliseconds *after* the last entry in the
  50.  * list that the timeout should occur, so routines that manipulate
  51.  * the list only need to check the first entry.
  52.  */
  53.  
  54. typedef struct timeout {
  55.     struct timeout *next;
  56.     struct proc    *proc;
  57.     long    when;
  58.     void    (*func) P_((struct proc *)); /* function to call at timeout */
  59. } TIMEOUT;
  60.  
  61. extern TIMEOUT *tlist;
  62.  
  63. #define NUM_REGIONS    64    /* max. number of memory regions for a proc */
  64. #define MIN_HANDLE    (-5)    /* minimum handle number        */
  65. #define MIN_OPEN    6    /* 0..MIN_OPEN-1 are reserved for system */
  66. #define MAX_OPEN    32    /* max. number of open files for a proc    */
  67. #define SSTKSIZE    8000    /* size of supervisor stack (in bytes)     */
  68. #define ISTKSIZE    2000    /* size of interrupt stack (in bytes)    */
  69. #define STKSIZE        (ISTKSIZE + SSTKSIZE)
  70.  
  71. #define FRAME_MAGIC    0xf4a3e000
  72.                 /* magic for signal call stack */
  73. #define CTXT_MAGIC    0xabcdef98
  74. #define CTXT2_MAGIC    0x87654321
  75.                 /* magic #'s for contexts */
  76.  
  77. #define PNAMSIZ        8    /* no. of characters in a process name */
  78.  
  79. #define DOM_TOS        0    /* TOS process domain */
  80. #define DOM_MINT    1    /* MiNT process domain */
  81.  
  82. typedef struct proc {
  83. /* this is stuff that the public can know about */
  84. /* NOTE: some assembly code (in intr.s and contxt.s) makes
  85.  * assumptions about the offsets of sysstack, ctxt[0], systime,
  86.  * and usrtime.
  87.  */
  88.     long    sysstack;        /* must be first        */
  89.     CONTEXT    ctxt[PROC_CTXTS];    /* must be second        */
  90.  
  91.     long    magic;            /* validation for proc struct    */
  92.  
  93.     BASEPAGE *base;            /* process base page        */
  94.     short    pid, ppid, pgrp;
  95.     short    ruid;            /* process real user id     */
  96.     short    rgid;            /* process real group id     */
  97.     short    euid, egid;        /* effective user and group ids */
  98.  
  99.     ushort    memflags;        /* e.g. malloc from alternate ram */
  100.     short    pri;            /* base process priority     */
  101.     short    wait_q;            /* current process queue    */
  102.  
  103. /* note: wait_cond should be unique for each kind of condition we might
  104.  * want to wait for. Put a define below, or use an address in the
  105.  * kernel as the wait condition to ensure uniqueness.
  106.  */
  107.     long    wait_cond;        /* condition we're waiting on    */
  108.                     /* (also return code from wait) */
  109.  
  110. #define WAIT_MB        0x3a140001L    /* wait_cond for p_msg call    */
  111. #define WAIT_SEMA    0x3a140003L    /* wait_cond for p_semaphore    */
  112.  
  113.     /* (all times are in milliseconds) */
  114.     ulong    systime;        /* time spent in kernel        */
  115.     ulong    usrtime;        /* time spent out of kernel    */
  116.     ulong    chldstime;        /* children's kernel time     */
  117.     ulong    chldutime;        /* children's user time        */
  118.  
  119.     ulong    maxmem;            /* max. amount of memory to use */
  120.     ulong    maxdata;        /* max. data region for process */
  121.     ulong    maxcore;        /* max. core memory for process */
  122.     ulong    maxcpu;            /* max. cpu time to use     */
  123.  
  124.     short    domain;            /* process domain (TOS or UNIX)    */
  125.  
  126.     short    curpri;            /* current process priority    */
  127. #define MIN_NICE -20
  128. #define MAX_NICE 20
  129.  
  130. /* EVERYTHING BELOW THIS LINE IS SUBJECT TO CHANGE:
  131.  * programs should *not* try to read this stuff via the U:\PROC dir.
  132.  */
  133.  
  134.     char    name[PNAMSIZ+1];    /* process name            */
  135.     TIMEOUT    *alarmtim;        /* alarm() event        */
  136.     short    slices;            /* number of time slices before this
  137.                        process gets to run again */
  138.  
  139.     short    bconmap;        /* Bconmap mapping        */
  140.     FILEPTR *midiout;        /* MIDI output            */
  141.     FILEPTR *midiin;        /* MIDI input            */
  142.     FILEPTR    *prn;            /* printer            */
  143.     FILEPTR *aux;            /* auxiliary tty        */
  144.     FILEPTR    *control;        /* control tty            */
  145.     FILEPTR    *handle[MAX_OPEN];    /* file handles            */
  146.  
  147.     uchar    fdflags[MAX_OPEN];    /* file descriptor flags    */
  148.  
  149.     ushort    num_reg;        /* number of memory regions allocated */
  150.     MEMREGION **mem;        /* allocated memory regions    */
  151.     virtaddr *addr;            /* addresses of regions        */
  152.  
  153.     ulong    sigpending;        /* pending signals        */
  154.     ulong    sigmask;        /* signals that are masked    */
  155.     ulong    sighandle[NSIG];    /* signal handlers        */
  156.     ushort    sigflags[NSIG];        /* signal flags            */
  157.     ulong    sigextra[NSIG];        /* additional signals to be masked
  158.                        on delivery     */
  159.     char    *mb_ptr;        /* p_msg buffer ptr        */
  160.     long    mb_long1, mb_long2;    /* p_msg storage        */
  161.     long    mb_mbid;        /* p_msg id being waited for    */
  162.     short    mb_mode;        /* p_msg mode being waiting in    */
  163.     short    mb_writer;        /* p_msg pid of writer of msg    */
  164.  
  165.     short    curdrv;            /* current drive        */
  166.     fcookie root[NUM_DRIVES];    /* root directories        */
  167.     fcookie    curdir[NUM_DRIVES];    /* current directory        */
  168.  
  169.     long    usrdata;        /* user-supplied data        */
  170.     ushort    umask;            /* file creation mask        */
  171.  
  172.     DTABUF    *dta;            /* current DTA            */
  173. #define NUM_SEARCH    6        /* max. number of searches    */
  174.     DTABUF *srchdta[NUM_SEARCH];    /* for Fsfirst/next        */
  175.     DIR    srchdir[NUM_SEARCH];    /* for Fsfirst/next        */
  176.     long    srchtim[NUM_SEARCH];    /* for Fsfirst/next        */
  177.     
  178.     long    txtsize;        /* size of text region (for fork()) */
  179.  
  180.     long    (*criticerr) P_((long)); /* critical error handler    */
  181.     void    *logbase;        /* logical screen base        */
  182.  
  183.     short    starttime;        /* time and date when process    */
  184.     short    startdate;        /* was started            */
  185.  
  186.     struct    proc *q_next;        /* next process on queue    */
  187.     struct     proc *gl_next;        /* next process in system    */
  188.     char    stack[STKSIZE+4];    /* stack for system calls    */
  189. } PROC;
  190.  
  191.  
  192. /* different process queues */
  193.  
  194. #define CURPROC_Q    0
  195. #define READY_Q        1
  196. #define WAIT_Q        2
  197. #define IO_Q        3
  198. #define ZOMBIE_Q    4
  199. #define TSR_Q        5
  200. #define STOP_Q        6
  201. #define SELECT_Q    7
  202.  
  203. #define NUM_QUEUES    8
  204.  
  205. extern PROC *proclist;            /* list of all active processes */
  206. extern PROC *curproc;            /* current process        */
  207. extern PROC *rootproc;            /* pid 0 -- MiNT itself        */
  208. extern PROC *sys_q[NUM_QUEUES];        /* process queues        */
  209.  
  210. #endif /* _proc_h */
  211.