
sS`c           @   s}  d  d l  Z  d  d l Z d Z d Z d   Z d   Z d d d  Z d	 Z d
 Z d Z	 d Z
 d Z d   Z d   Z d   Z d   Z d d) d     YZ d   Z d g  d d  Z d d  Z d d  Z d   Z d d  Z d   Z d   Z d   Z d   Z d   Z d d* d      YZ d! d+ d"     YZ d# d, d$     YZ d%   Z  d&   Z! d'   Z" e# d( k rye"   n  d S(-   iNs   
/* DO NOT EDIT!  This is an autogenerated file.  See scripts/layoutrom.py. */
OUTPUT_FORMAT("elf32-i386")
OUTPUT_ARCH("i386")
SECTIONS
{
sW  

        /* Discard regular data sections to force a link error if
         * code attempts to access data not marked with VAR16 (or other
         * appropriate macro)
         */
        /DISCARD/ : {
                *(.text*) *(.data*) *(.bss*) *(.rodata*)
                *(COMMON) *(.discard*) *(.eh_frame) *(.note*)
                }
}
c         C   s   | d } |  | | @S(   Ni   (    (   t   post
   alignbytest   mask(    (    s-   /work/Dorado/qnx/seabios/scripts/layoutrom.pyt   alignpos&   s    
c         C   s   | d } |  | @S(   Ni   (    (   R    R   R   (    (    s-   /work/Dorado/qnx/seabios/scripts/layoutrom.pyt	   aligndown+   s    
i   i    c         C   s   d } x9 |  D]1 } t  | | j  } t | | j  | j } q Wt | | |  | } | } xC |  D]; } t | | j  } | | _ | | | _ | | j 7} qg W| | f S(   Ni    (   t   maxt   alignR   t   sizet   intt   finalloct   finalsegloc(   t   sectionst   endaddrt   minalignt	   segoffsett   totspacet   sectiont	   startaddrt   curaddr(    (    s-   /work/Dorado/qnx/seabios/scripts/layoutrom.pyt   setSectionsStart1   s    	i   i   i   i  
 i   c         C   s  g  } x |  D] } | j  j d  r t | j  d d  } | t | _ | | _ | j | | f  | j d k r d | j  | j f GHt j	 d  q q q W| j
 d t j d   | d d } g  } x t t |   D]q } | | } | \ } } | t |  d k rt }	 n | | d d }	 |	 | | j }
 | j |
 | f  q W| j
 d t j d   g  | D]! } | j | j | j  | f ^ qt} | j
   g  | D] \ } } } } | ^ q} d } x | D] \ } } | j | j } | | j 7} | | } x d  } x\ | D]T } | | j | k r7Pn  t | | j  | j } | | k rbqn  | | f } qW| d  k rPn  | \ } } | j |  | t | _ | | _ | } | | j 7} qWqWt | } | | } d | t | | t |  | d	 f GH| t S(
   Ns   .fixedaddr.i   i   i   s3   Error: Fixed section %s has non-zero alignment (%d)t   keyi    sC   Fixed space: 0x%x-0x%x  total: %d  slack: %d  Percent slack: %.1f%%g      Y@(   t   namet
   startswithR   t   BUILD_BIOS_ADDRR	   R
   t   appendR   t   syst   exitt   sortt   operatort
   itemgettert   ranget   lent   BUILD_BIOS_SIZER   t   NoneR   t   removet   float(   R   t   fillsectionst   fixedsectionsR   t   addrt
   firstfixedt	   fixedAddrt   it   fixedsectioninfot   nextaddrt   availt   canrelocateR   R   R   t	   totalusedt	   freespacet   fixedsectiont   addpost   nextfixedaddrt   canfitt
   fitsectiont   fitnextaddrt   totalt   slack(    (    s-   /work/Dorado/qnx/seabios/scripts/layoutrom.pyt   fitSectionsJ   sn    	
	+
%
	

c         C   s&   g  |  D] } | j  | k r | ^ q S(   N(   t   category(   R   R9   R   (    (    s-   /work/Dorado/qnx/seabios/scripts/layoutrom.pyt   getSectionsCategory   s    c         C   s&   g  |  D] } | j  | k r | ^ q S(   N(   t   fileid(   R   R;   R   (    (    s-   /work/Dorado/qnx/seabios/scripts/layoutrom.pyt   getSectionsFileid   s    c         C   s)   g  |  D] } | j  j |  r | ^ q S(   N(   R   R   (   R   t   prefixR   (    (    s-   /work/Dorado/qnx/seabios/scripts/layoutrom.pyt   getSectionsPrefix   s    t
   LayoutInfoc           B   sV   e  Z d  Z d  Z d  Z d  Z Z Z d  Z	 Z
 d  Z Z d  Z Z d  Z d  Z Z RS(   N(   t   __name__t
   __module__R!   R   t   configt   genreloct   sec32init_startt   sec32init_endt   sec32init_alignt   sec32low_startt   sec32low_endt   zonelow_baset   final_sec32low_startt   zonefseg_startt   zonefseg_endt   final_readonly_startt
   varlowsymst   entrysym(    (    (    s-   /work/Dorado/qnx/seabios/scripts/layoutrom.pyR?      s   


c   2      C   s{  t    } | | _ |  | _ | | _ t |  d  } t | d  } t | d  } t | d  } t |  d  } t | |  }	 g  | | | D] }
 |
 j d  k r |
 ^ q } t	 | |	 d t
 \ } } t |  d  } t | d  } t | d  } t | d  } t	 | | | | d t
 \ } } t |  d	  } t	 | | d
  \ } } t |  d  } t	 | | d
 d t
 \ } } t |  d  } t | d  } t | d  } t | d  } t | d  } t	 | | | | | d
  \ } } t |  d  } t | d  } t | d  } t | d  } t | d  } t	 | | | | | d
  \ }  }! | }" | so|  }" n  t
 }# |# t |" k r| }" |" t }# t	 | | | | |# d
  \ } } t	 | | | | | d
  \ }  }! n  |  | _ | | _ |! | _ t t
 |  }$ | s"t t
 |   }$ n  |# | _ |" | _ |$ | _ t |  d  }% |  }& | j d  r|$ }' |' d }( t t t |( d   }( n t }' |' d }( |' |& }) t	 |% |& d
 d |( |) \ | _ }* |& | _ |( | _ | j |) | _ t
 t | }+ | | }, | | }- | | }. | | }/ | |  }0 | j | j }1 d |+ GHd |, GHd |/ |- GHd |0 GHd |1 GHd |. GH| S(   Nt   16s   .text.s   .rodatas   .data16.t   fixedR   t   32segs   .data32seg.t
   32textfsegi   t   32fsegt   32flats   .data.s   .bss.t   32initt   32lowt   CONFIG_MALLOC_UPPERMEMORYi@   i   i   s   16bit size:           %ds   32bit segmented size: %ds   32bit flat size:      %ds   32bit flat init size: %ds   Lowmem size:          %ds   f-segment var size:   %di   i   i   (   R?   RB   R   RC   R:   R>   R8   R	   R!   R   R   t   BUILD_MIN_BIOSTABLERD   RE   RF   t   minRK   RL   RM   t   getR   t   BUILD_ROM_STARTR   t   BUILD_LOWRAM_ENDRG   RH   RI   RJ   R    (2   R   RB   RC   t   lit
   sections16t   textsectionst   rodatasectionst   datasectionsR%   R'   t   st   remsectionst   sec16_startt   sec16_alignt   sections32segt   sec32seg_startt   sec32seg_alignt   sections32textfsegt   sec32textfseg_startt   sec32textfseg_alignt   sections32fsegt   sec32fseg_startt   sec32fseg_alignt   sections32flatt   bsssectionst   sec32flat_startt   sec32flat_alignt   sections32initt   init32_textsectionst   init32_rodatasectionst   init32_datasectionst   init32_bsssectionsRD   RF   RL   RK   RM   t   sections32lowRH   t   final_sec32low_endRI   t
   relocdeltat   sec32low_alignt   size16t	   size32segt   size32textfsegt
   size32fsegt
   size32flatt
   size32initt   sizelow(    (    s-   /work/Dorado/qnx/seabios/scripts/layoutrom.pyt   doLayout   s    					
						


		




					c         C   s  t  g  | D] } | j | f ^ q
  } d } xq |  D]i } x` | j D]U } | j } | j d  k	 rE | j j | j k s | j | j k rE | | | j <qE qE Wq5 WxZ | j   D]L \ }	 } | j j	 }
 | r | j j
 }
 n  | d |	 |
 | | j f 7} q W| S(   Nt    s   %s = 0x%x ;
(   t   dictR   t   relocst   symbolR   R!   R;   t
   symbolnamet   itemsR	   R
   t   offset(   R   t   usesegt
   exportsymst
   forcedeltaR   t   xrefst   outR   t   relocR   t   loc(    (    s-   /work/Dorado/qnx/seabios/scripts/layoutrom.pyt   outXRefs1  s    (	#c         C   sS   d } xF |  D]> } | j  } | r. | j } n  | d | j | | j f 7} q W| S(   NR   s   %s 0x%x : { *(%s) }
(   R	   R
   R   (   R   R   R   R   R   (    (    s-   /work/Dorado/qnx/seabios/scripts/layoutrom.pyt   outSectionsC  s    	!c         C   s   g  |  D]$ } | j  d  k	 r | j  | f ^ q }  |  j d t j d   d } x |  D]{ \ } } | j  } | r~ | j } n  | d | | f 7} | j d	 k r | d | j f 7} n  | d | j | j f 7} qW W| S(
   NR   i    R   s   . = ( 0x%x - %s ) ;
s   .rodata.str1.1s   .rodatas   _rodata%s = . ;
s
   *%s.*(%s)
(   s   .rodata.str1.1s   .rodata(   R	   R!   R   R   R   R
   R   R;   (   R   t   startsymR   R   R   R&   R   (    (    s-   /work/Dorado/qnx/seabios/scripts/layoutrom.pyt   outRelSectionsM  s    $	c         C   sJ   | j    d |  f d j g  | D] } d | | f ^ q!  d |  f S(   Ns!           %s_start = ABSOLUTE(.) ;
R   s   LONG(0x%x - %s)
s           %s_end = ABSOLUTE(.) ;
(   R   t   join(   t   outnamet   outrelR   R    (    (    s-   /work/Dorado/qnx/seabios/scripts/layoutrom.pyt	   strRelocs]  s    
c         C   s^   g  |  D]S } | j  D]C } | j j | k r | d  k sG | j | k r | j | j ^ q q S(   N(   R   R   R   R!   t   typeR	   R   (   R   t	   tosectionR   R   R   (    (    s-   /work/Dorado/qnx/seabios/scripts/layoutrom.pyt	   getRelocse  s
    
c         C   sE  t  |  j d  } t | d d d |  j t |  j d  t | d d f } t | d  } | j t | t	  | j
   t  |  j d  } t | d d t | d d } t | d  } | j t | t	  | j
   |  j } d }	 |  j rt g  t |  j d	  D] }
 |
 d f ^ q } t g  |  j D] }
 |
 | k r7|
 d f ^ q7 } t | | d
 d } t | | d
 d } t | |  } t d d |  t d d |  t d d |  }	 t | | |  } | | d 8} n  t  |  j d  } t g  d |  j d |  j |  j } d } |  j j d  rPd } | d 8} n  t g  |  j D] } | j ^ q] } t | |  } | t | d |  j g d |  j |  j |  j |  j |  j |  j |  j |  j |  j |  j  | | |	 t! |  j d  f 7} t | t	 d |  j j" f } t | d  } | j |  | j
   d  S(   NRP   R   i   s9   
    zonelow_base = 0x%x ;
    _zonelow_seg = 0x%x ;

%s
i   t   wRR   R   RV   R   t   R_386_32t
   R_386_PC32t
   _reloc_abst   code32init_startt
   _reloc_relt   _reloc_initt   code32flat_starti   RU   R   R   t   CONFIG_MULTIBOOTs*   LONG(0x1BADB002) LONG(0) LONG(-0x1BADB002)i   s  
    _reloc_min_align = 0x%x ;
    zonefseg_start = 0x%x ;
    zonefseg_end = 0x%x ;
    zonelow_base = 0x%x ;
    final_varlow_start = 0x%x ;
    final_readonly_start = 0x%x ;
    varlow_start = 0x%x ;
    varlow_end = 0x%x ;
    code32init_start = 0x%x ;
    code32init_end = 0x%x ;

    code32flat_start = 0x%x ;
    .text code32flat_start : {
%s
%s
%s
        code32flat_end = ABSOLUTE(.) ;
    } :text
sD   
ENTRY(%s)
PHDRS
{
        text PT_LOAD AT ( code32flat_start ) ;
}
i   (#   R<   R   R   RI   R   R   t   opent   writet   COMMONHEADERt   COMMONTRAILERt   closeRG   RC   R   R:   R   R   R   RN   RJ   RB   R[   R   R   R   RO   RF   RK   RL   RM   RH   RD   RE   R   R   (   R^   t   out16t   out32segt	   out32flatt   filesections16R   t   outfilet   filesections32segt   sec32all_startt   relocstrRc   t   initsectionst   noninitsectionst	   absrelocst	   relrelocst
   initrelocst	   numrelocst   filesections32flatt   multiboot_headerR   t   sec32all_align(    (    s-   /work/Dorado/qnx/seabios/scripts/layoutrom.pyt   writeLinkerScriptsm  sp    	

		.!2%	c         C   s   t  g  |  D] } | g  f ^ q
  }  t |   } x | r | j   } xr | j D]g } |  | | j g } | | | | |  s qP n  | j j } | |  k rP | |  | <| j |  qP qP Wq4 W|  S(   N(   R   t   listt   popR   R   R   R   R   (   t   anchorsectionst
   checkreloct   dataR   t   pendingR   t   chaint   nextsection(    (    s-   /work/Dorado/qnx/seabios/scripts/layoutrom.pyt   findReachable  s    %	
c         C   s`   |  j  j } | d  k s' d | j k r+ d Sd | j k r\ d | j | f GHt j d  n  d S(   Ns   .init.i    s   .data.varinit.s-   ERROR: %s is VARVERIFY32INIT but used from %si   (   R   R   R!   R   R   R   (   R   t   rsectionR   R   R   (    (    s-   /work/Dorado/qnx/seabios/scripts/layoutrom.pyt   checkRuntime  s    c   	      C   s   |  j  } | j d  } | rR d | d } | j |  s? d S| t |  } n  | j |  } | d  k s | j d  k s | j j j d  r d S| j j j d  o | j j j d  } | r | s | r | r | r d S| |  _ d S(   Nt   _cfunct   _i    s	   .discard.s   .text.s
   .text.asm.i   (   R   R   R   R[   R!   R   R   R   (	   R   t   symsR;   t   isxrefR   t   mustbecfunct	   symprefixR   t   isdestcfunc(    (    s-   /work/Dorado/qnx/seabios/scripts/layoutrom.pyt   checkKeepSym  s$    		c         C   ss   t  |  | | j | j d  } | r) | SxC d D]; } | | j k r0 t  |  | | | d  } | rk | Sq0 q0 Wd S(   Ni    RP   RR   RU   i   (   RP   RR   RU   (   R   R;   (   R   R   t   symbolsR   t   retR;   (    (    s-   /work/Dorado/qnx/seabios/scripts/layoutrom.pyt	   checkKeep  s    t   Sectionc           B   s,   e  Z d  Z Z Z Z Z d  Z Z	 Z
 RS(   N(   R@   RA   R!   R   R   t	   alignmentR;   R   R	   R
   R9   (    (    (    s-   /work/Dorado/qnx/seabios/scripts/layoutrom.pyR     s   t   Relocc           B   s   e  Z d  Z Z Z Z RS(   N(   R@   RA   R!   R   R   R   R   (    (    (    s-   /work/Dorado/qnx/seabios/scripts/layoutrom.pyR     s   t   Symbolc           B   s   e  Z d  Z Z Z RS(   N(   R@   RA   R!   R   R   R   (    (    (    s-   /work/Dorado/qnx/seabios/scripts/layoutrom.pyR     s   c         C   sY  g  } i  } i  } d  } x4|  j   D]&} | j   } | d k rO d } q% n  | d k rg d } q% n  | j d  r | d d !} | j d  r d  } q% n  d	 } | | } q% n  | d k ryy | j   \ }	 }
 } } } } } | d
  d k r w% n  t   } |
 | _ t | d  | _ d t | d
  | _	 | | _
 g  | _ | j |  | | |
 <Wq% t k
 rrq% Xq% n  | d k rgy | d j   } t |  d
 k r| \ } } }
 n: t |  d k r| d d k r| \ } } } }
 n w% t   } t | d  | _ t | d  d  | _ |
 | _ | j |  | _ | | |
 <Wq% t k
 r`q% Xq% n  | d	 k r% y | j   \ } } } t   } t | d  | _ | | _ | | _ | j |  | _ | j d  k r#t   | _ } d | _ d | _ | | _ | j |  | _ | | | <n  | j j |  WqKt k
 rGqKXq% q% W| | f S(   Ns	   Sections:R   s   SYMBOL TABLE:R   s   RELOCATION RECORDS FOR [i   is   .debug_R   i   s   2**i   i   i   i   s   .hiddeni   i    (   R!   t	   readlinest   rstripR   t   splitR   R   R   R   R   R;   R   R   t
   ValueErrorR   R   R   R[   R   R   R   R   R   (   t   fileR;   R   t
   sectionmapR   t   statet   linet   sectionnamet   relocsectiont   idxR   R   t   vmat   lmat   fileoffR   R   t   partst   hiddenR   t   offR   R   R   (    (    s-   /work/Dorado/qnx/seabios/scripts/layoutrom.pyt   parseObjDump  s    
!				"								c         C   s   t  |  d  } i  } x | j   D] } | j   } t |  d k rL q" n  | d d k rb q" n  | d } | j   s | j d  r | d j   r t | d  } n  | | | d <q" W| S(   Nt   ri   i    s   #definei   t   0xi   (   R   R   R   R   t   isdigitR   R   (   R   t   ft   optst   lR   t   value(    (    s-   /work/Dorado/qnx/seabios/scripts/layoutrom.pyt
   scanconfign  s    
+c          C   se  t  j d \ }  } } } } } } t |  d  } t | d  } t | d  }	 t | d  }
 t | d  } t |	 d  } t |  } |
 d | d | d } i |
 d d 6| d d 6| d d 6} | j d  r | d j d  } n8 | j d	  r| d j d
  } n | d j d  } | j g g  | D] } | j j d  r6| ^ q6} t	 | t
 |  } g  | D] } | | k rt| ^ qt} g  | D]H } d | j k sd | j k sd | j k sd | j k r| ^ q} t	 | t d   } x | D] } | j j d  r$d | _ q | j j d  rBd | _ q | j j d  r`d | _ q | j j d  r~d | _ q | j d k r| | k rd | _ q | j | _ q Wd | d k } t | | |  } g  | d j   D]T } | j d  k	 r| j j d  k	 rd | j j k r| j | j j k r| ^ q| _ | | _ t | | | |  d  S(   Ni   R   RP   RR   RU   i    t   CONFIG_COREBOOTt	   entry_elft
   CONFIG_CSMt	   entry_csmt   reset_vectors   .fixedaddr.s   .data.varlow.s   .data.varfseg.s	   .runtime.RW   RT   s   .text.32fseg.RS   RQ   RV   t   _reloc_abs_start(   R   t   argvR   R   R   R[   R   R   R   R   R   R   R!   R9   R;   R   t   valuesR	   RN   RO   R   (   t   in16t   in32segt   in32flatt   cfgfileR   R   R   t   infile16t   infile32segt   infile32flatt   info16t	   info32segt
   info32flatRB   t   allsectionsR   RO   R   R   t   keepsectionsR   t   runtimesectionsRC   R^   R   (    (    s-   /work/Dorado/qnx/seabios/scripts/layoutrom.pyt   main}  sZ    "'	%*$	t   __main__(    (    (    (    ($   R   R   R   R   R   R   R   R   R    R\   R]   RY   R8   R:   R<   R>   R?   R   R   R   R   R   R!   R   R   R   R   R   R   R   R   R   R   R   R  R@   (    (    (    s-   /work/Dorado/qnx/seabios/scripts/layoutrom.pyt   <module>   sF   				O				
		c					S		C