133965Sjdp/* ldexp.h - 2130561Sobrien Copyright 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2000, 2001, 2002, 3218822Sdim 2003, 2004, 2005 Free Software Foundation, Inc. 433965Sjdp 533965Sjdp This file is part of GLD, the Gnu Linker. 633965Sjdp 733965Sjdp GLD is free software; you can redistribute it and/or modify 833965Sjdp it under the terms of the GNU General Public License as published by 933965Sjdp the Free Software Foundation; either version 2, or (at your option) 1033965Sjdp any later version. 1133965Sjdp 1233965Sjdp GLD is distributed in the hope that it will be useful, 1333965Sjdp but WITHOUT ANY WARRANTY; without even the implied warranty of 1433965Sjdp MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1533965Sjdp GNU General Public License for more details. 1633965Sjdp 1733965Sjdp You should have received a copy of the GNU General Public License 1860484Sobrien along with GLD; see the file COPYING. If not, write to the Free 19218822Sdim Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 20218822Sdim 02110-1301, USA. */ 2133965Sjdp 2233965Sjdp#ifndef LDEXP_H 2333965Sjdp#define LDEXP_H 2433965Sjdp 2533965Sjdp/* The result of an expression tree */ 2677298Sobrientypedef struct { 2733965Sjdp bfd_vma value; 28104834Sobrien char *str; 29218822Sdim asection *section; 30130561Sobrien bfd_boolean valid_p; 3133965Sjdp} etree_value_type; 3233965Sjdp 3377298Sobrientypedef struct { 3433965Sjdp int node_code; 35218822Sdim unsigned int lineno; 36130561Sobrien enum { 37130561Sobrien etree_binary, 38130561Sobrien etree_trinary, 39130561Sobrien etree_unary, 40130561Sobrien etree_name, 41130561Sobrien etree_assign, 42130561Sobrien etree_provide, 43130561Sobrien etree_provided, 44130561Sobrien etree_value, 45130561Sobrien etree_assert, 46130561Sobrien etree_rel 47130561Sobrien } node_class; 4833965Sjdp} node_type; 4933965Sjdp 5077298Sobrientypedef union etree_union { 5133965Sjdp node_type type; 5233965Sjdp struct { 5333965Sjdp node_type type; 5433965Sjdp union etree_union *lhs; 5533965Sjdp union etree_union *rhs; 5633965Sjdp } binary; 5733965Sjdp struct { 5833965Sjdp node_type type; 5933965Sjdp union etree_union *cond; 6033965Sjdp union etree_union *lhs; 6133965Sjdp union etree_union *rhs; 6233965Sjdp } trinary; 6333965Sjdp struct { 6433965Sjdp node_type type; 65104834Sobrien const char *dst; 6633965Sjdp union etree_union *src; 67218822Sdim bfd_boolean hidden; 6833965Sjdp } assign; 6933965Sjdp struct { 7033965Sjdp node_type type; 7177298Sobrien union etree_union *child; 7233965Sjdp } unary; 7333965Sjdp struct { 7433965Sjdp node_type type; 75104834Sobrien const char *name; 7633965Sjdp } name; 7733965Sjdp struct { 7833965Sjdp node_type type; 7933965Sjdp bfd_vma value; 80104834Sobrien char *str; 8133965Sjdp } value; 8233965Sjdp struct { 8333965Sjdp node_type type; 8433965Sjdp asection *section; 8533965Sjdp bfd_vma value; 8633965Sjdp } rel; 8760484Sobrien struct { 8860484Sobrien node_type type; 8960484Sobrien union etree_union *child; 9060484Sobrien const char *message; 9160484Sobrien } assert_s; 9233965Sjdp} etree_type; 9333965Sjdp 94218822Sdimtypedef enum { 95218822Sdim lang_first_phase_enum, 96218822Sdim lang_mark_phase_enum, 97218822Sdim lang_allocating_phase_enum, 98218822Sdim lang_final_phase_enum 99218822Sdim} lang_phase_type; 100104834Sobrien 101218822Sdimstruct ldexp_control { 102218822Sdim /* Modify expression evaluation depending on this. */ 103218822Sdim lang_phase_type phase; 104218822Sdim 105218822Sdim /* Principally used for diagnostics. */ 106218822Sdim bfd_boolean assigning_to_dot; 107218822Sdim 108218822Sdim /* Working results. */ 109218822Sdim etree_value_type result; 110218822Sdim bfd_vma dot; 111218822Sdim 112218822Sdim /* Current dot and section passed to ldexp folder. */ 113218822Sdim bfd_vma *dotp; 114218822Sdim asection *section; 115218822Sdim 116218822Sdim /* State machine and results for DATASEG. */ 117218822Sdim struct { 118218822Sdim enum { 119218822Sdim exp_dataseg_none, 120218822Sdim exp_dataseg_align_seen, 121218822Sdim exp_dataseg_relro_seen, 122218822Sdim exp_dataseg_end_seen, 123218822Sdim exp_dataseg_relro_adjust, 124218822Sdim exp_dataseg_adjust 125218822Sdim } phase; 126218822Sdim 127218822Sdim bfd_vma base, min_base, relro_end, end, pagesize, maxpagesize; 128218822Sdim } dataseg; 129218822Sdim}; 130218822Sdim 131218822Sdimextern struct ldexp_control expld; 132218822Sdim 133218822Sdim/* A maps from a segment name to a base address. */ 134218822Sdimtypedef struct segment_struct { 135218822Sdim /* The next segment in the linked list. */ 136218822Sdim struct segment_struct *next; 137218822Sdim /* The name of the sgement. */ 138218822Sdim const char *name; 139218822Sdim /* The base address for the segment. */ 140218822Sdim bfd_vma value; 141218822Sdim /* True if a SEGMENT_START directive corresponding to this segment 142218822Sdim has been seen. */ 143218822Sdim bfd_boolean used; 144218822Sdim} segment_type; 145218822Sdim 146218822Sdim/* The segments specified by the user on the command-line. */ 147218822Sdimextern segment_type *segments; 148218822Sdim 149104834Sobrientypedef struct _fill_type fill_type; 150104834Sobrien 151130561Sobrienetree_type *exp_intop 152130561Sobrien (bfd_vma); 153130561Sobrienetree_type *exp_bigintop 154130561Sobrien (bfd_vma, char *); 155130561Sobrienetree_type *exp_relop 156130561Sobrien (asection *, bfd_vma); 157218822Sdimvoid exp_fold_tree 158218822Sdim (etree_type *, asection *, bfd_vma *); 159130561Sobrienetree_type *exp_binop 160130561Sobrien (int, etree_type *, etree_type *); 161130561Sobrienetree_type *exp_trinop 162130561Sobrien (int,etree_type *, etree_type *, etree_type *); 163130561Sobrienetree_type *exp_unop 164130561Sobrien (int, etree_type *); 165130561Sobrienetree_type *exp_nameop 166130561Sobrien (int, const char *); 167130561Sobrienetree_type *exp_assop 168130561Sobrien (int, const char *, etree_type *); 169130561Sobrienetree_type *exp_provide 170218822Sdim (const char *, etree_type *, bfd_boolean); 171130561Sobrienetree_type *exp_assert 172130561Sobrien (etree_type *, const char *); 173130561Sobrienvoid exp_print_tree 174130561Sobrien (etree_type *); 175130561Sobrienbfd_vma exp_get_vma 176218822Sdim (etree_type *, bfd_vma, char *); 177130561Sobrienint exp_get_value_int 178218822Sdim (etree_type *, int, char *); 179130561Sobrienfill_type *exp_get_fill 180218822Sdim (etree_type *, fill_type *, char *); 181130561Sobrienbfd_vma exp_get_abs_int 182218822Sdim (etree_type *, int, char *); 18333965Sjdp 18433965Sjdp#endif 185