| 1 | /* A YACC grammer to parse a superset of the AT&T linker scripting languaue. |
| 2 | Copyright (C) 1991 Free Software Foundation, Inc. |
| 3 | Written by Steve Chamberlain of Cygnus Support (steve@cygnus.com). |
| 4 | |
| 5 | This file is part of GNU ld. |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
| 20 | |
| 21 | %{ |
| 22 | /* |
| 23 | |
| 24 | */ |
| 25 | |
| 26 | #define DONTDECLARE_MALLOC |
| 27 | |
| 28 | #include "bfd.h" |
| 29 | #include "sysdep.h" |
| 30 | #include "ld.h" |
| 31 | #include "ldexp.h" |
| 32 | #include "ldver.h" |
| 33 | #include "ldlang.h" |
| 34 | #include "ldemul.h" |
| 35 | #include "ldfile.h" |
| 36 | #include "ldmisc.h" |
| 37 | #include "mri.h" |
| 38 | |
| 39 | #define YYDEBUG 1 |
| 40 | |
| 41 | boolean option_v; |
| 42 | extern unsigned int lineno; |
| 43 | extern boolean trace_files; |
| 44 | extern boolean write_map; |
| 45 | extern boolean option_longmap; |
| 46 | boolean hex_mode; |
| 47 | static int typebits; |
| 48 | strip_symbols_type strip_symbols=STRIP_NONE; |
| 49 | discard_locals_type discard_locals=DISCARD_NONE; |
| 50 | |
| 51 | |
| 52 | lang_memory_region_type *region; |
| 53 | |
| 54 | |
| 55 | lang_memory_region_type *lang_memory_region_lookup(); |
| 56 | lang_output_section_statement_type *lang_output_section_statement_lookup(); |
| 57 | etree_type *lang_atin(); |
| 58 | #ifdef __STDC__ |
| 59 | |
| 60 | void lang_add_data(int type, union etree_union *exp); |
| 61 | void lang_enter_output_section_statement(char *output_section_statement_name, etree_type *address_exp, int flags, bfd_vma block_value,etree_type*,etree_type*, etree_type*); |
| 62 | |
| 63 | #else |
| 64 | |
| 65 | void lang_add_data(); |
| 66 | void lang_enter_output_section_statement(); |
| 67 | |
| 68 | #endif /* __STDC__ */ |
| 69 | |
| 70 | extern args_type command_line; |
| 71 | char *current_file; |
| 72 | boolean ldgram_want_filename = true; |
| 73 | boolean had_script = false; |
| 74 | boolean force_make_executable = false; |
| 75 | |
| 76 | boolean ldgram_in_script = false; |
| 77 | boolean ldgram_had_equals = false; |
| 78 | /* LOCALS */ |
| 79 | |
| 80 | |
| 81 | #define ERROR_NAME_MAX 20 |
| 82 | static char *error_names[ERROR_NAME_MAX]; |
| 83 | static int error_index; |
| 84 | #define PUSH_ERROR(x) if (error_index < ERROR_NAME_MAX) error_names[error_index] = x; error_index++; |
| 85 | #define POP_ERROR() error_index--; |
| 86 | %} |
| 87 | %union { |
| 88 | bfd_vma integer; |
| 89 | int voidval; |
| 90 | char *name; |
| 91 | int token; |
| 92 | union etree_union *etree; |
| 93 | struct sec *section; |
| 94 | struct lang_output_section_statement_struct *output_section_statement; |
| 95 | union lang_statement_union **statement_ptr; |
| 96 | int lineno; |
| 97 | struct { |
| 98 | FILE *file; |
| 99 | char *name; |
| 100 | unsigned int lineno; |
| 101 | } state; |
| 102 | |
| 103 | |
| 104 | } |
| 105 | |
| 106 | %type <etree> exp opt_exp_with_type mustbe_exp opt_at |
| 107 | %type <integer> fill_opt |
| 108 | %type <name> memspec_opt |
| 109 | %token <integer> INT |
| 110 | %token <name> NAME |
| 111 | %type <integer> length |
| 112 | |
| 113 | %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ |
| 114 | %right <token> '?' ':' |
| 115 | %left <token> OROR |
| 116 | %left <token> ANDAND |
| 117 | %left <token> '|' |
| 118 | %left <token> '^' |
| 119 | %left <token> '&' |
| 120 | %left <token> EQ NE |
| 121 | %left <token> '<' '>' LE GE |
| 122 | %left <token> LSHIFT RSHIFT |
| 123 | |
| 124 | %left <token> '+' '-' |
| 125 | %left <token> '*' '/' '%' |
| 126 | |
| 127 | /*%token <token> '+' '-' '*' '/' '%'*/ |
| 128 | %right UNARY |
| 129 | %token END |
| 130 | %left <token> '(' |
| 131 | %token <token> ALIGN_K BLOCK LONG SHORT BYTE |
| 132 | %token SECTIONS |
| 133 | %token '{' '}' |
| 134 | %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH |
| 135 | %token SIZEOF_HEADERS |
| 136 | %token INCLUDE |
| 137 | %token MEMORY DEFSYMEND |
| 138 | %token NOLOAD DSECT COPY INFO OVERLAY |
| 139 | %token NAME DEFINED TARGET_K SEARCH_DIR MAP ENTRY |
| 140 | %token OPTION_e OPTION_c OPTION_noinhibit_exec OPTION_s OPTION_S OPTION_sort_common |
| 141 | %token OPTION_EB OPTION_EL |
| 142 | %token OPTION_format OPTION_F OPTION_u OPTION_Bstatic OPTION_N |
| 143 | %token <integer> SIZEOF NEXT ADDR |
| 144 | %token OPTION_d OPTION_dc OPTION_dp OPTION_x OPTION_X OPTION_defsym |
| 145 | %token OPTION_v OPTION_V OPTION_M OPTION_t STARTUP HLL SYSLIB FLOAT NOFLOAT |
| 146 | %token OPTION_Map |
| 147 | %token OPTION_n OPTION_r OPTION_o OPTION_b OPTION_R OPTION_relax |
| 148 | %token <name> OPTION_l OPTION_L OPTION_T OPTION_Aarch OPTION_Tfile OPTION_Texp |
| 149 | %token <name> OPTION_y |
| 150 | %token OPTION_Ur |
| 151 | %token ORIGIN FILL OPTION_g |
| 152 | %token LENGTH CREATE_OBJECT_SYMBOLS INPUT OUTPUT CONSTRUCTORS |
| 153 | %token OPTION_RETAIN_SYMBOLS_FILE ALIGNMOD AT |
| 154 | |
| 155 | %type <token> assign_op |
| 156 | |
| 157 | %type <name> filename |
| 158 | |
| 159 | |
| 160 | %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD |
| 161 | %token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE |
| 162 | |
| 163 | %{ |
| 164 | ld_config_type config; |
| 165 | %} |
| 166 | |
| 167 | %% |
| 168 | |
| 169 | file: command_line { lang_final(); }; |
| 170 | |
| 171 | |
| 172 | filename: NAME; |
| 173 | |
| 174 | |
| 175 | command_line: |
| 176 | command_line command_line_option |
| 177 | | |
| 178 | ; |
| 179 | |
| 180 | command_line_option: |
| 181 | OPTION_Bstatic { } |
| 182 | | OPTION_v |
| 183 | { |
| 184 | ldversion(0); |
| 185 | option_v = true; |
| 186 | } |
| 187 | | OPTION_V |
| 188 | { |
| 189 | ldversion(1); |
| 190 | option_v = true; |
| 191 | } |
| 192 | | OPTION_t { |
| 193 | trace_files = true; |
| 194 | } |
| 195 | | OPTION_Map NAME |
| 196 | { |
| 197 | write_map = true; |
| 198 | config.map_filename = $2; |
| 199 | } |
| 200 | | OPTION_M |
| 201 | { |
| 202 | config.map_filename = "-"; |
| 203 | } |
| 204 | | OPTION_n { |
| 205 | config.magic_demand_paged = false; |
| 206 | } |
| 207 | | OPTION_N { |
| 208 | config.text_read_only = false; |
| 209 | config.magic_demand_paged = false; |
| 210 | } |
| 211 | | OPTION_s { |
| 212 | strip_symbols = STRIP_ALL; |
| 213 | } |
| 214 | | OPTION_S { |
| 215 | strip_symbols = STRIP_DEBUGGER; |
| 216 | } |
| 217 | | OPTION_u NAME { |
| 218 | ldlang_add_undef($2); |
| 219 | } |
| 220 | |
| 221 | | OPTION_r { |
| 222 | config.relocateable_output = true; |
| 223 | config.build_constructors = false; |
| 224 | config.magic_demand_paged = false; |
| 225 | config.text_read_only = false; |
| 226 | } |
| 227 | | OPTION_Ur { |
| 228 | config.relocateable_output = true; |
| 229 | config.build_constructors = true; |
| 230 | config.magic_demand_paged = false; |
| 231 | config.text_read_only = false; |
| 232 | } |
| 233 | | OPTION_o filename |
| 234 | { |
| 235 | lang_add_output($2); |
| 236 | } |
| 237 | | OPTION_e NAME |
| 238 | { lang_add_entry($2); |
| 239 | } |
| 240 | | OPTION_X { |
| 241 | discard_locals = DISCARD_L; |
| 242 | } |
| 243 | | OPTION_x { |
| 244 | discard_locals = DISCARD_ALL; |
| 245 | } |
| 246 | |
| 247 | | OPTION_noinhibit_exec |
| 248 | { |
| 249 | force_make_executable = true; |
| 250 | } |
| 251 | | OPTION_sort_common { |
| 252 | config.sort_common = true; |
| 253 | } |
| 254 | | OPTION_d { |
| 255 | command_line.force_common_definition = true; |
| 256 | } |
| 257 | |
| 258 | | OPTION_relax { |
| 259 | command_line.relax = true; |
| 260 | } |
| 261 | | OPTION_dc |
| 262 | { |
| 263 | command_line.force_common_definition = true; |
| 264 | } |
| 265 | | OPTION_g |
| 266 | { |
| 267 | /* Ignored */ |
| 268 | } |
| 269 | | OPTION_dp |
| 270 | { |
| 271 | command_line.force_common_definition = true; |
| 272 | } |
| 273 | | OPTION_format NAME |
| 274 | { |
| 275 | lang_add_target($2); |
| 276 | } |
| 277 | | OPTION_Texp |
| 278 | { ldlex_expression(); |
| 279 | hex_mode = 16; |
| 280 | } |
| 281 | INT |
| 282 | { ldlex_popstate(); |
| 283 | lang_section_start($1,exp_intop($3)); |
| 284 | hex_mode = 0; |
| 285 | } |
| 286 | | OPTION_y |
| 287 | { |
| 288 | add_ysym($1); |
| 289 | } |
| 290 | | OPTION_Aarch |
| 291 | { |
| 292 | ldfile_add_arch($1); |
| 293 | } |
| 294 | | OPTION_b NAME |
| 295 | { |
| 296 | lang_add_target($2); |
| 297 | } |
| 298 | | OPTION_L |
| 299 | { |
| 300 | ldfile_add_library_path($1); |
| 301 | } |
| 302 | | OPTION_F |
| 303 | { |
| 304 | /* Ignore */ |
| 305 | } |
| 306 | | NAME |
| 307 | { lang_add_input_file($1,lang_input_file_is_file_enum, |
| 308 | (char *)NULL); } |
| 309 | | OPTION_c filename |
| 310 | { ldfile_open_command_file($2); } mri_script_file END { ldlex_command();} |
| 311 | |
| 312 | | OPTION_Tfile |
| 313 | { ldfile_open_command_file($1); } script_file |
| 314 | END { ldlex_command();} |
| 315 | |
| 316 | | OPTION_T filename |
| 317 | { ldfile_open_command_file($2); } script_file |
| 318 | END { ldlex_command();} |
| 319 | |
| 320 | | OPTION_l |
| 321 | { |
| 322 | lang_add_input_file($1, |
| 323 | lang_input_file_is_l_enum, |
| 324 | (char *)NULL); |
| 325 | } |
| 326 | | OPTION_R filename |
| 327 | { |
| 328 | lang_add_input_file($2, |
| 329 | lang_input_file_is_symbols_only_enum, |
| 330 | (char *)NULL); |
| 331 | } |
| 332 | |
| 333 | | OPTION_defsym { ldlex_defsym(); } |
| 334 | NAME '=' exp DEFSYMEND { ldlex_popstate(); |
| 335 | lang_add_assignment(exp_assop($4,$3,$5)); |
| 336 | } |
| 337 | | OPTION_RETAIN_SYMBOLS_FILE filename |
| 338 | { lang_add_keepsyms_file ($2); } |
| 339 | | OPTION_EB |
| 340 | { |
| 341 | /* FIXME: This is currently ignored. It means |
| 342 | ``produce a big-endian object file''. It could |
| 343 | be used to select an output format. */ |
| 344 | } |
| 345 | | OPTION_EL |
| 346 | { |
| 347 | /* FIXME: This is currently ignored. It means |
| 348 | ``produce a little-endian object file''. It could |
| 349 | be used to select an output format. */ |
| 350 | } |
| 351 | | '-' NAME |
| 352 | { info("%P%F Unrecognized option -%s\n", $2); } |
| 353 | |
| 354 | | '{' script_file '}' |
| 355 | ; |
| 356 | |
| 357 | |
| 358 | /* SYNTAX WITHIN AN MRI SCRIPT FILE */ |
| 359 | mri_script_file: |
| 360 | { ldlex_mri_script(); |
| 361 | PUSH_ERROR("MRI style script"); |
| 362 | } |
| 363 | mri_script_lines |
| 364 | { ldlex_popstate(); |
| 365 | POP_ERROR(); |
| 366 | } |
| 367 | ; |
| 368 | |
| 369 | mri_script_lines: |
| 370 | mri_script_lines mri_script_command NEWLINE |
| 371 | | |
| 372 | ; |
| 373 | |
| 374 | mri_script_command: |
| 375 | CHIP exp |
| 376 | | CHIP exp ',' exp |
| 377 | | NAME { |
| 378 | einfo("%P%F: unrecognised keyword in MRI style script '%s'\n",$1); |
| 379 | } |
| 380 | | LIST { |
| 381 | write_map = true; |
| 382 | config.map_filename = "-"; |
| 383 | } |
| 384 | | ORDER ordernamelist |
| 385 | | ENDWORD |
| 386 | | PUBLIC NAME '=' exp |
| 387 | { mri_public($2, $4); } |
| 388 | | PUBLIC NAME ',' exp |
| 389 | { mri_public($2, $4); } |
| 390 | | PUBLIC NAME exp |
| 391 | { mri_public($2, $3); } |
| 392 | | FORMAT NAME |
| 393 | { mri_format($2); } |
| 394 | | SECT NAME ',' exp |
| 395 | { mri_output_section($2, $4);} |
| 396 | | SECT NAME exp |
| 397 | { mri_output_section($2, $3);} |
| 398 | | SECT NAME '=' exp |
| 399 | { mri_output_section($2, $4);} |
| 400 | | ALIGN_K NAME '=' exp |
| 401 | { mri_align($2,$4); } |
| 402 | | ALIGNMOD NAME '=' exp |
| 403 | { mri_alignmod($2,$4); } |
| 404 | | ABSOLUTE mri_abs_name_list |
| 405 | | LOAD mri_load_name_list |
| 406 | | NAMEWORD NAME |
| 407 | { mri_name($2); } |
| 408 | | ALIAS NAME ',' NAME |
| 409 | { mri_alias($2,$4,0);} |
| 410 | | ALIAS NAME ',' INT |
| 411 | { mri_alias($2,0,$4);} |
| 412 | | BASE exp |
| 413 | { mri_base($2); } |
| 414 | | TRUNCATE INT |
| 415 | { mri_truncate($2); } |
| 416 | | |
| 417 | ; |
| 418 | |
| 419 | ordernamelist: |
| 420 | ordernamelist ',' NAME { mri_order($3); } |
| 421 | | ordernamelist NAME { mri_order($2); } |
| 422 | | |
| 423 | ; |
| 424 | |
| 425 | mri_load_name_list: |
| 426 | NAME |
| 427 | { mri_load($1); } |
| 428 | | mri_load_name_list ',' NAME { mri_load($3); } |
| 429 | ; |
| 430 | |
| 431 | mri_abs_name_list: |
| 432 | NAME |
| 433 | { mri_only_load($1); } |
| 434 | | mri_abs_name_list ',' NAME |
| 435 | { mri_only_load($3); } |
| 436 | ; |
| 437 | |
| 438 | script_file: |
| 439 | { |
| 440 | ldlex_both(); |
| 441 | } |
| 442 | ifile_list |
| 443 | { |
| 444 | ldlex_popstate(); |
| 445 | } |
| 446 | ; |
| 447 | |
| 448 | |
| 449 | ifile_list: |
| 450 | ifile_list ifile_p1 |
| 451 | | |
| 452 | ; |
| 453 | |
| 454 | |
| 455 | |
| 456 | ifile_p1: |
| 457 | memory |
| 458 | | sections |
| 459 | | startup |
| 460 | | high_level_library |
| 461 | | low_level_library |
| 462 | | floating_point_support |
| 463 | | statement_anywhere |
| 464 | | ';' |
| 465 | | TARGET_K '(' NAME ')' |
| 466 | { lang_add_target($3); } |
| 467 | | SEARCH_DIR '(' filename ')' |
| 468 | { ldfile_add_library_path($3); } |
| 469 | | OUTPUT '(' filename ')' |
| 470 | { lang_add_output($3); } |
| 471 | | OUTPUT_FORMAT '(' NAME ')' |
| 472 | { lang_add_output_format($3); } |
| 473 | | OUTPUT_ARCH '(' NAME ')' |
| 474 | { ldfile_set_output_arch($3); } |
| 475 | | FORCE_COMMON_ALLOCATION |
| 476 | { command_line.force_common_definition = true ; } |
| 477 | | INPUT '(' input_list ')' |
| 478 | | MAP '(' filename ')' |
| 479 | { lang_add_map($3); } |
| 480 | | INCLUDE filename |
| 481 | { ldfile_open_command_file($2); } ifile_list END |
| 482 | ; |
| 483 | |
| 484 | input_list: |
| 485 | NAME |
| 486 | { lang_add_input_file($1,lang_input_file_is_file_enum, |
| 487 | (char *)NULL); } |
| 488 | | input_list ',' NAME |
| 489 | { lang_add_input_file($3,lang_input_file_is_file_enum, |
| 490 | (char *)NULL); } |
| 491 | | input_list NAME |
| 492 | { lang_add_input_file($2, |
| 493 | lang_input_file_is_file_enum, |
| 494 | (char *)NULL); } |
| 495 | ; |
| 496 | |
| 497 | sections: |
| 498 | SECTIONS '{' sec_or_group_p1 '}' |
| 499 | ; |
| 500 | |
| 501 | sec_or_group_p1: |
| 502 | sec_or_group_p1 section |
| 503 | | sec_or_group_p1 statement_anywhere |
| 504 | | |
| 505 | ; |
| 506 | |
| 507 | statement_anywhere: |
| 508 | ENTRY '(' NAME ')' |
| 509 | { lang_add_entry($3); } |
| 510 | | assignment end |
| 511 | ; |
| 512 | |
| 513 | file_NAME_list: |
| 514 | NAME |
| 515 | { lang_add_wild($1, current_file); } |
| 516 | | file_NAME_list opt_comma NAME |
| 517 | { lang_add_wild($3, current_file); } |
| 518 | ; |
| 519 | |
| 520 | input_section_spec: |
| 521 | NAME |
| 522 | { |
| 523 | lang_add_wild((char *)NULL, $1); |
| 524 | } |
| 525 | | '[' |
| 526 | { |
| 527 | current_file = (char *)NULL; |
| 528 | } |
| 529 | file_NAME_list |
| 530 | ']' |
| 531 | | NAME |
| 532 | { |
| 533 | current_file =$1; |
| 534 | } |
| 535 | '(' file_NAME_list ')' |
| 536 | | '*' |
| 537 | { |
| 538 | current_file = (char *)NULL; |
| 539 | } |
| 540 | '(' file_NAME_list ')' |
| 541 | ; |
| 542 | |
| 543 | statement: |
| 544 | assignment end |
| 545 | | CREATE_OBJECT_SYMBOLS |
| 546 | { |
| 547 | lang_add_attribute(lang_object_symbols_statement_enum); |
| 548 | } |
| 549 | | ';' |
| 550 | | CONSTRUCTORS |
| 551 | { |
| 552 | |
| 553 | lang_add_attribute(lang_constructors_statement_enum); |
| 554 | } |
| 555 | | input_section_spec |
| 556 | | length '(' exp ')' |
| 557 | { |
| 558 | lang_add_data($1,$3); |
| 559 | } |
| 560 | |
| 561 | | FILL '(' exp ')' |
| 562 | { |
| 563 | lang_add_fill |
| 564 | (exp_get_value_int($3, |
| 565 | 0, |
| 566 | "fill value", |
| 567 | lang_first_phase_enum)); |
| 568 | } |
| 569 | ; |
| 570 | |
| 571 | statement_list: |
| 572 | statement_list statement |
| 573 | | statement |
| 574 | ; |
| 575 | |
| 576 | length: |
| 577 | LONG |
| 578 | { $$ = $1; } |
| 579 | | SHORT |
| 580 | { $$ = $1; } |
| 581 | | BYTE |
| 582 | { $$ = $1; } |
| 583 | ; |
| 584 | |
| 585 | fill_opt: |
| 586 | '=' mustbe_exp |
| 587 | { |
| 588 | $$ = exp_get_value_int($2, |
| 589 | 0, |
| 590 | "fill value", |
| 591 | lang_first_phase_enum); |
| 592 | } |
| 593 | | { $$ = 0; } |
| 594 | ; |
| 595 | |
| 596 | |
| 597 | |
| 598 | assign_op: |
| 599 | PLUSEQ |
| 600 | { $$ = '+'; } |
| 601 | | MINUSEQ |
| 602 | { $$ = '-'; } |
| 603 | | MULTEQ |
| 604 | { $$ = '*'; } |
| 605 | | DIVEQ |
| 606 | { $$ = '/'; } |
| 607 | | LSHIFTEQ |
| 608 | { $$ = LSHIFT; } |
| 609 | | RSHIFTEQ |
| 610 | { $$ = RSHIFT; } |
| 611 | | ANDEQ |
| 612 | { $$ = '&'; } |
| 613 | | OREQ |
| 614 | { $$ = '|'; } |
| 615 | |
| 616 | ; |
| 617 | |
| 618 | end: ';' | ',' |
| 619 | ; |
| 620 | |
| 621 | |
| 622 | assignment: |
| 623 | NAME '=' mustbe_exp |
| 624 | { |
| 625 | lang_add_assignment(exp_assop($2,$1,$3)); |
| 626 | } |
| 627 | | NAME assign_op mustbe_exp |
| 628 | { |
| 629 | |
| 630 | lang_add_assignment(exp_assop('=',$1,exp_binop($2,exp_nameop(NAME,$1),$3))); |
| 631 | } |
| 632 | |
| 633 | ; |
| 634 | |
| 635 | |
| 636 | opt_comma: |
| 637 | ',' | ; |
| 638 | |
| 639 | |
| 640 | memory: |
| 641 | MEMORY '{' memory_spec memory_spec_list '}' |
| 642 | ; |
| 643 | |
| 644 | memory_spec_list: |
| 645 | memory_spec_list memory_spec |
| 646 | | memory_spec_list ',' memory_spec |
| 647 | | |
| 648 | ; |
| 649 | |
| 650 | |
| 651 | memory_spec: NAME |
| 652 | { region = lang_memory_region_lookup($1); } |
| 653 | attributes_opt ':' |
| 654 | origin_spec opt_comma length_spec |
| 655 | |
| 656 | ; origin_spec: |
| 657 | ORIGIN '=' mustbe_exp |
| 658 | { region->current = |
| 659 | region->origin = |
| 660 | exp_get_vma($3, 0L,"origin", lang_first_phase_enum); |
| 661 | } |
| 662 | ; length_spec: |
| 663 | LENGTH '=' mustbe_exp |
| 664 | { region->length = exp_get_vma($3, |
| 665 | ~((bfd_vma)0), |
| 666 | "length", |
| 667 | lang_first_phase_enum); |
| 668 | } |
| 669 | |
| 670 | |
| 671 | attributes_opt: |
| 672 | '(' NAME ')' |
| 673 | { |
| 674 | lang_set_flags(®ion->flags, $2); |
| 675 | } |
| 676 | | |
| 677 | |
| 678 | ; |
| 679 | |
| 680 | startup: |
| 681 | STARTUP '(' filename ')' |
| 682 | { lang_startup($3); } |
| 683 | ; |
| 684 | |
| 685 | high_level_library: |
| 686 | HLL '(' high_level_library_NAME_list ')' |
| 687 | | HLL '(' ')' |
| 688 | { ldemul_hll((char *)NULL); } |
| 689 | ; |
| 690 | |
| 691 | high_level_library_NAME_list: |
| 692 | high_level_library_NAME_list opt_comma filename |
| 693 | { ldemul_hll($3); } |
| 694 | | filename |
| 695 | { ldemul_hll($1); } |
| 696 | |
| 697 | ; |
| 698 | |
| 699 | low_level_library: |
| 700 | SYSLIB '(' low_level_library_NAME_list ')' |
| 701 | ; low_level_library_NAME_list: |
| 702 | low_level_library_NAME_list opt_comma filename |
| 703 | { ldemul_syslib($3); } |
| 704 | | |
| 705 | ; |
| 706 | |
| 707 | floating_point_support: |
| 708 | FLOAT |
| 709 | { lang_float(true); } |
| 710 | | NOFLOAT |
| 711 | { lang_float(false); } |
| 712 | ; |
| 713 | |
| 714 | |
| 715 | mustbe_exp: { ldlex_expression(); } |
| 716 | exp |
| 717 | { ldlex_popstate(); $$=$2;} |
| 718 | ; |
| 719 | |
| 720 | exp : |
| 721 | '-' exp %prec UNARY |
| 722 | { $$ = exp_unop('-', $2); } |
| 723 | | '(' exp ')' |
| 724 | { $$ = $2; } |
| 725 | | NEXT '(' exp ')' %prec UNARY |
| 726 | { $$ = exp_unop($1,$3); } |
| 727 | | '!' exp %prec UNARY |
| 728 | { $$ = exp_unop('!', $2); } |
| 729 | | '+' exp %prec UNARY |
| 730 | { $$ = $2; } |
| 731 | | '~' exp %prec UNARY |
| 732 | { $$ = exp_unop('~', $2);} |
| 733 | |
| 734 | | exp '*' exp |
| 735 | { $$ = exp_binop('*', $1, $3); } |
| 736 | | exp '/' exp |
| 737 | { $$ = exp_binop('/', $1, $3); } |
| 738 | | exp '%' exp |
| 739 | { $$ = exp_binop('%', $1, $3); } |
| 740 | | exp '+' exp |
| 741 | { $$ = exp_binop('+', $1, $3); } |
| 742 | | exp '-' exp |
| 743 | { $$ = exp_binop('-' , $1, $3); } |
| 744 | | exp LSHIFT exp |
| 745 | { $$ = exp_binop(LSHIFT , $1, $3); } |
| 746 | | exp RSHIFT exp |
| 747 | { $$ = exp_binop(RSHIFT , $1, $3); } |
| 748 | | exp EQ exp |
| 749 | { $$ = exp_binop(EQ , $1, $3); } |
| 750 | | exp NE exp |
| 751 | { $$ = exp_binop(NE , $1, $3); } |
| 752 | | exp LE exp |
| 753 | { $$ = exp_binop(LE , $1, $3); } |
| 754 | | exp GE exp |
| 755 | { $$ = exp_binop(GE , $1, $3); } |
| 756 | | exp '<' exp |
| 757 | { $$ = exp_binop('<' , $1, $3); } |
| 758 | | exp '>' exp |
| 759 | { $$ = exp_binop('>' , $1, $3); } |
| 760 | | exp '&' exp |
| 761 | { $$ = exp_binop('&' , $1, $3); } |
| 762 | | exp '^' exp |
| 763 | { $$ = exp_binop('^' , $1, $3); } |
| 764 | | exp '|' exp |
| 765 | { $$ = exp_binop('|' , $1, $3); } |
| 766 | | exp '?' exp ':' exp |
| 767 | { $$ = exp_trinop('?' , $1, $3, $5); } |
| 768 | | exp ANDAND exp |
| 769 | { $$ = exp_binop(ANDAND , $1, $3); } |
| 770 | | exp OROR exp |
| 771 | { $$ = exp_binop(OROR , $1, $3); } |
| 772 | | DEFINED '(' NAME ')' |
| 773 | { $$ = exp_nameop(DEFINED, $3); } |
| 774 | | INT |
| 775 | { $$ = exp_intop($1); } |
| 776 | | SIZEOF_HEADERS |
| 777 | { $$ = exp_nameop(SIZEOF_HEADERS,0); } |
| 778 | |
| 779 | | SIZEOF '(' NAME ')' |
| 780 | { $$ = exp_nameop(SIZEOF,$3); } |
| 781 | | ADDR '(' NAME ')' |
| 782 | { $$ = exp_nameop(ADDR,$3); } |
| 783 | | ABSOLUTE '(' exp ')' |
| 784 | { $$ = exp_unop(ABSOLUTE, $3); } |
| 785 | | ALIGN_K '(' exp ')' |
| 786 | { $$ = exp_unop(ALIGN_K,$3); } |
| 787 | | NAME |
| 788 | { $$ = exp_nameop(NAME,$1); } |
| 789 | ; |
| 790 | |
| 791 | |
| 792 | opt_at: |
| 793 | AT '(' exp ')' { $$ = $3; } |
| 794 | | { $$ = 0; } |
| 795 | ; |
| 796 | |
| 797 | section: NAME { ldlex_expression(); } |
| 798 | opt_exp_with_type |
| 799 | opt_at { ldlex_popstate(); } |
| 800 | '{' |
| 801 | { |
| 802 | lang_enter_output_section_statement($1,$3,typebits,0,0,0,$4); |
| 803 | } |
| 804 | statement_list |
| 805 | '}' {ldlex_expression();} fill_opt memspec_opt |
| 806 | { |
| 807 | ldlex_popstate(); |
| 808 | lang_leave_output_section_statement($11, $12); |
| 809 | } |
| 810 | opt_comma |
| 811 | |
| 812 | ; |
| 813 | |
| 814 | type: |
| 815 | NOLOAD { typebits = SEC_NEVER_LOAD; } |
| 816 | | DSECT { typebits = 0; } |
| 817 | | COPY { typebits = 0; } |
| 818 | | INFO { typebits = 0; } |
| 819 | | OVERLAY { typebits = 0; } |
| 820 | | { typebits = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS; } |
| 821 | ; |
| 822 | |
| 823 | |
| 824 | opt_exp_with_type: |
| 825 | exp ':' { $$ = $1; typebits =0;} |
| 826 | | exp '(' type ')' ':' { $$ = $1; } |
| 827 | | ':' { $$= (etree_type *)NULL; typebits = 0; } |
| 828 | | '(' type ')' ':' { $$= (etree_type *)NULL; } |
| 829 | ; |
| 830 | |
| 831 | memspec_opt: |
| 832 | '>' NAME |
| 833 | { $$ = $2; } |
| 834 | | { $$ = "*default*"; } |
| 835 | ; |
| 836 | %% |
| 837 | void |
| 838 | yyerror(arg) |
| 839 | char *arg; |
| 840 | { |
| 841 | if (error_index> 0 && error_index < ERROR_NAME_MAX) |
| 842 | einfo("%P%F: %S syntax error in %s\n",error_names[error_index-1]); |
| 843 | else |
| 844 | einfo("%P%F: %S syntax error\n"); |
| 845 | } |