home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / compiler / nasm20b / nasm_src / segment.c < prev    next >
C/C++ Source or Header  |  1993-01-19  |  3KB  |  125 lines

  1. /* ---------------------------------------------------------------------- */
  2. /*                   Copyright (C) 1991 by Natürlich!                  */
  3. /*                      This file is copyrighted!                         */
  4. /*                Refer to the documentation for details.                 */
  5. /* ---------------------------------------------------------------------- */
  6. #include "defines.h"
  7. #include "nasm.h"
  8. #include "debug.h"
  9. #include OSBIND
  10. #include NMALLOC_H
  11. #include "code.h"
  12. #include "seg.h"
  13.  
  14. seg huge  *h_seg = 0,
  15.     huge  *sp = 0;
  16.  
  17. make_mallocer( seg, SEGMAX, seg_alloc)
  18.  
  19.  
  20. /* ---------------------------------------------------------- */
  21. /* The old segment style was a bit more efficient, but it got */
  22. /* really too complicated for my worn-out neurons. So we use  */
  23. /* the way normal people would have written this.             */
  24. /* ---------------------------------------------------------- */
  25. #if LINKER
  26. word   plus1;
  27.  
  28. void  build_seg( index, type, size)
  29. word  index, size;
  30. {
  31.    static word       offset;
  32.    extern seg huge   *l_seg;
  33.    extern int        bootable;
  34.    register seg huge *p = seg_alloc();
  35.  
  36.    p->size   = size;
  37.    p->index  = index + plus1;
  38.    if( ! offset)
  39.       offset = index;
  40.    p->offset = offset;
  41.    offset    = offset + p->size;
  42.  
  43.    if( ! h_seg)                     /* set head pointer  */
  44.       h_seg = p;
  45.    else
  46.       sp->next = p;
  47.  
  48.    if( (p->type = type) == S_DS)
  49.       plus1 += 4;
  50.    (sp = p)->next = 0;
  51. }
  52.  
  53. #else
  54.  
  55. char  ovf_loss[] = "Too much code";
  56.  
  57. void  build_rseg( type, size)
  58. word  size;
  59. {
  60.    register seg huge *p = seg_alloc();
  61.    register lword    tmp;
  62.  
  63.    if( (tmp = __p - __program) >= MAXMODULE)
  64.       nferror( ovf_loss);
  65.  
  66.    if( ! h_seg)                     /* set head pointer  */
  67.       h_seg = p;
  68.    else                             /* calc segment size */
  69.    {
  70.       register seg huge *q = sp;
  71.  
  72.       q->next = p;
  73.       if( sis_code( q))
  74.          q->size = calc_index();
  75.    }
  76.    (sp = p)->next = 0;
  77.    p->type  = type;
  78.    p->index = (word) tmp;
  79.    p->size  = size;
  80. }
  81.  
  82. #endif
  83.  
  84. #if ! VERSION && ! LINKER
  85. extern int  runnable;
  86.  
  87. void  check_fseg( p, t)       
  88. seg huge *p;
  89. {
  90.    if( runnable)                 
  91.    {                             
  92.       if( sis_unknown( p))       
  93.          p->type = S_SDATA;
  94.    }                             
  95.    else                          
  96.       if( (t) != p->type)        
  97.          if( sis_unknown( p))    
  98.             p->type = t;         
  99.          else                    
  100.             build_rseg( t, 0);
  101. }
  102.  
  103. void check_dseg( p, t, val)  
  104. seg huge *p;
  105. word     val;
  106. {
  107.    if( runnable)                 
  108.    {                             
  109.       if( sis_unknown( p))       
  110.          p->type = S_SDATA;      
  111.    }                             
  112.    else                          
  113.       if( (t) != p->type)        
  114.          if( sis_unknown( p))    
  115.          {                       
  116.             p->type = t;         
  117.             p->size = val;       
  118.          }                       
  119.          else                    
  120.             build_rseg( t, val); 
  121.       else                       
  122.          p->size += val;
  123. }
  124. #endif
  125.