home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / gcc / ixemulsrc.lha / ixemul / library / ix_resident.c < prev    next >
C/C++ Source or Header  |  1996-12-11  |  3KB  |  117 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *  Portions Copyright (C) 1994 Rafael W. Luebbert
  5.  *
  6.  *  This library is free software; you can redistribute it and/or
  7.  *  modify it under the terms of the GNU Library General Public
  8.  *  License as published by the Free Software Foundation; either
  9.  *  version 2 of the License, or (at your option) any later version.
  10.  *
  11.  *  This library is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  *  Library General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU Library General Public
  17.  *  License along with this library; if not, write to the Free
  18.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  *  $Id: ix_resident.c,v 1.5 1994/06/19 19:30:31 rluebbert Exp $
  21.  *
  22.  *  $Log: ix_resident.c,v $
  23.  *  Revision 1.5  1994/06/19  19:30:31  rluebbert
  24.  *  Optimization of subroutines
  25.  *
  26.  *  Revision 1.4  1994/06/19  15:13:14  rluebbert
  27.  *  *** empty log message ***
  28.  *
  29.  *  Revision 1.2  1992/09/14  01:42:52  mwild
  30.  *  if out of memory, exit. There's no reason to continue, the programs would
  31.  *  just plain crash...
  32.  *
  33.  *  Revision 1.1  1992/05/14  19:55:40  mwild
  34.  *  Initial revision
  35.  *
  36.  */
  37.  
  38. #define _KERNEL
  39. #include "ixemul.h"
  40. #include "kprintf.h"
  41. #include <sys/exec.h>
  42.  
  43.  
  44. void
  45. ix_resident (int numpar, int a4, int databss_size, long *relocs)
  46. {
  47.   /* for now, only a4 management is supported. relocation is for later, 
  48.      and isn't defined yet */
  49.  
  50.   if ((numpar == 3 || numpar == 4) && databss_size)
  51.     {
  52.       int mem = (int)kmalloc (databss_size);
  53.       if (! mem)
  54.         {
  55.       ix_panic ("Out of memory.");
  56.       _exit (20);
  57.     }
  58.       else
  59.     {
  60.       int origmem = a4 - 0x7ffe;
  61.  
  62.       memcpy((void *)mem, (void *)origmem, databss_size);
  63.  
  64.       if (numpar == 4 && relocs[0] > 0)
  65.         {
  66.           int i, num_rel = relocs[0];
  67.  
  68.           for (i = 0, relocs++; i < num_rel; i++, relocs++)
  69.               *(long *)(mem + *relocs) -= origmem - mem;
  70.         }
  71.  
  72.       if (u.p_flag & SFREEA4)
  73.         kfree ((void *)origmem);
  74.       else
  75.         u.p_flag |= SFREEA4;
  76.  
  77.       a4 = mem + 0x7ffe;
  78.     }
  79.     }
  80.  
  81.   
  82.   if (numpar >= 2 && numpar <= 4)
  83.     {
  84.       /* need output parameter, or the asm is optimized away */
  85.       asm volatile ("movel %0, a4" : "=g" (a4) : "0" (a4));
  86.       
  87.       u.u_a4 = a4;
  88.     }
  89.   else
  90.     ix_warning("Unsupported ix_resident call.");
  91. }
  92.  
  93. void ix_geta4 (void)
  94. {
  95.   if (u.u_a4) {
  96.     asm volatile ("movel %0, a4" : "=g" (u.u_a4) : "0" (u.u_a4));
  97.   }
  98. }
  99.  
  100. /* This function isn't used at the moment, but it is meant to be called
  101.  * at the start of an executable. This function should check if the
  102.  * executable can run on the CPU of this computer.
  103.  */
  104. void ix_check_cpu (int machtype)
  105. {
  106. #if notyet
  107.   if (machtype == MID_SUN020)
  108.     {
  109.       if (!(SysBase->AttnFlags & AFF_68020))
  110.     {
  111.       ix_panic ("This program requires at least a 68020 cpu.");
  112.       syscall (SYS_exit, 20);
  113.     }
  114.     }
  115. #endif
  116. }
  117.