home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / config / amiga / boot / ils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-03  |  3.2 KB  |  130 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: ils.c,v 1.6 1997/02/03 02:53:27 ldp Exp $
  4.  
  5.     Desc: Amiga bootloader -- InternalLoadSeg support routines
  6.     Lang: C
  7. */
  8. /*
  9.     For more information: autodocs/dos/InternalLoadSeg()
  10. */
  11.  
  12. #include <exec/types.h>
  13. #include <exec/execbase.h>
  14. #include <exec/memory.h>
  15. #include <exec/lists.h>
  16.  
  17. #include <aros/asmcall.h>
  18.  
  19. #include <proto/exec.h>
  20. #include <proto/dos.h>
  21.  
  22. #include "boot.h"
  23. #include "main.h"
  24.  
  25. #define D(x) if (debug) x
  26. #define bug Printf
  27. LONG Printf(STRPTR format, ...);
  28.  
  29. extern struct ilsMemList ils_mem;
  30.  
  31. AROS_UFH4(LONG, ils_read,
  32.     AROS_UFHA(BPTR,                handle,  D1),
  33.     AROS_UFHA(void *,              buffer,  D2),
  34.     AROS_UFHA(LONG,                length,  D3),
  35.     AROS_UFHA(struct DosLibrary *, DOSBase, A6))
  36. {
  37.     D(bug(" ils_read: size %ld\n", length));
  38.  
  39.     return( Read(handle, buffer, length) );
  40. }
  41.  
  42. AROS_UFH3(void *, ils_alloc,
  43.     AROS_UFHA(ULONG,             size,    D0),
  44.     AROS_UFHA(ULONG,             attrib,  D1),
  45.     AROS_UFHA(struct ExecBase *, SysBase, A6))
  46. {
  47.     void *result;
  48.  
  49.     D(bug(" ils_alloc: size %ld == ", size));
  50.  
  51.     /*
  52.     Memory to be used for Resident modules can not be any kind of memory
  53.     available. It must be of a special type, MEMF_KICK, which indicates
  54.     that this memory is available very early during the reset procedure.
  55.     Also allocate memory from the top of the memory list, MEMF_REVERSE,
  56.     to keep all our allocations in one place, and to keep potential early
  57.     memory fragmentation down.
  58.  
  59.     Addition: Pre V39 exec doesn't know about MEMF_KICK, so fall back to
  60.     MEMF_CHIP (memtype is set in main()).
  61.     */
  62.     attrib |= memtype|MEMF_REVERSE;
  63.  
  64.     result = AllocMem(size, attrib);
  65.  
  66.     /*
  67.     all memory that is allocated during the LoadSeg has to be entered
  68.     into the KickMemPtr for protection during reset. We keep a list of
  69.     our allocations so we can later make this MemList
  70.     */
  71.     if(result)
  72.     {
  73.     struct ilsMemNode *node;
  74.  
  75.     if( (node = AllocMem(sizeof(struct ilsMemNode), MEMF_CLEAR)) )
  76.     {
  77.         node->imn_Addr = result;
  78.         node->imn_Size = size;
  79.         AddHead((struct List *)&ils_mem, (struct Node *)node);
  80.  
  81.         /*
  82.         Keep a counter so we don't have to count nodes later.
  83.         */
  84.         ils_mem.iml_Num++;
  85.  
  86.         /*
  87.         This counts number of nodes since the loading of the last
  88.         module. This field is reset in the FindResMod() routine.
  89.         */
  90.         ils_mem.iml_NewNum++;
  91.     }
  92.     D(bug("0x%08lx\n", result));
  93.     return(result);
  94.     }
  95.  
  96.     D(bug("0\n"));
  97.     return 0;
  98. }
  99.  
  100. AROS_UFH3(void, ils_free,
  101.     AROS_UFHA(void *,            block,   A1),
  102.     AROS_UFHA(ULONG,             size,    D0),
  103.     AROS_UFHA(struct ExecBase *, SysBase, A6))
  104. {
  105.     void *saveblock = block;
  106.     struct ilsMemNode *node;
  107.  
  108.     D(bug(" ils_free: block 0x%08lx  size %ld\n", block, size));
  109.  
  110.     FreeMem(block, size);
  111.  
  112.     /* now remove this block from our list */
  113.     /* find it */
  114.     for(node = (struct ilsMemNode *)ils_mem.iml_List.mlh_Head;
  115.     node->imn_Node.mln_Succ;
  116.     node = (struct ilsMemNode *)node->imn_Node.mln_Succ)
  117.     {
  118.     /* is this the right block? */
  119.     if(node->imn_Addr == saveblock)
  120.     {
  121.         /* yes: remove from list and free it's memory */
  122.         Remove((struct Node *)node);
  123.         ils_mem.iml_Num--;
  124.         ils_mem.iml_NewNum--;
  125.         FreeMem(node, sizeof(struct ilsMemNode));
  126.     }
  127.     }
  128. }
  129.  
  130.