/
read.c
2098 lines (1920 loc) · 54.2 KB
/
read.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* read.c - read a source file -
Copyright (C) 1986,1987 Free Software Foundation, Inc.
This file is part of GAS, the GNU Assembler.
GAS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
GAS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GAS; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
change this a bit. But then, GNU isn't
spozed to run on your machine anyway.
(RMS is so shortsighted sometimes.)
*/
#define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
/* This is the largest known floating point */
/* format (for now). It will grow when we */
/* do 4361 style flonums. */
/* Routines that read assembler source text to build spagetti in memory. */
/* Another group of these functions is in the as-expr.c module */
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "as.h"
#include "read.h"
#include "md.h"
#include "hash.h"
#include "obstack.h"
#include "frags.h"
#include "flonum.h"
#include "struc-symbol.h"
#include "expr.h"
#include "symbols.h"
#ifdef SPARC
#include "sparc.h"
#define OTHER_ALIGN
#endif
#ifdef I860
#include "i860.h"
#endif
char * input_line_pointer; /* -> next char of source file to parse. */
#if BITS_PER_CHAR != 8
The following table is indexed by [ (char) ] and will break if
a char does not have exactly 256 states (hopefully 0:255!) !
#endif
const char /* used by is_... macros. our ctype[] */
lex_type [256] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 3, /* PQRSTUVWXYZ[\]^_ */
0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, /* pqrstuvwxyz{|}~. */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
/*
* In: a character.
* Out: TRUE if this character ends a line.
*/
#define _ (0)
const char is_end_of_line [256] = {
_, _, _, _, _, _, _, _, _, _,99, _, _, _, _, _, /* @abcdefghijklmno */
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
_, _, _, _, _, _, _, _, _, _, _,99, _, _, _, _, /* 0123456789:;<=>? */
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ /* */
};
#undef _
/* Functions private to this file. */
void equals();
void big_cons();
void cons();
static char* demand_copy_C_string();
static char* demand_copy_string();
void demand_empty_rest_of_line();
void float_cons();
long int get_absolute_expression();
static char get_absolute_expression_and_terminator();
static segT get_known_segmented_expression();
void ignore_rest_of_line();
static int is_it_end_of_statement();
static void pobegin();
static void pseudo_set();
static void stab();
static void stringer();
extern char line_comment_chars[];
static char * buffer_limit; /* -> 1 + last char in buffer. */
static char * bignum_low; /* Lowest char of bignum. */
static char * bignum_limit; /* 1st illegal address of bignum. */
static char * bignum_high; /* Highest char of bignum. */
/* May point to (bignum_start-1). */
/* Never >= bignum_limit. */
static char *old_buffer = 0; /* JF a hack */
static char *old_input;
static char *old_limit;
#ifndef WORKING_DOT_WORD
struct broken_word *broken_words;
int new_broken_words = 0;
#endif
static void grow_bignum ();
static int next_char_of_string ();
void
read_begin()
{
pobegin();
obstack_begin( ¬es, 5000 );
#define BIGNUM_BEGIN_SIZE (16)
bignum_low = xmalloc((long)BIGNUM_BEGIN_SIZE);
bignum_limit = bignum_low + BIGNUM_BEGIN_SIZE;
}
/* set up pseudo-op tables */
static struct hash_control *
po_hash = NULL; /* use before set up: NULL-> address error */
void s_abort(), s_align(), s_comm(), s_data();
void s_desc(), s_even(), s_file(), s_fill();
void s_globl(), s_lcomm(), s_line(), s_lsym();
void s_org(), s_set(), s_space(), s_text();
#ifdef VMS
char const_flag = 0;
void s_const();
#endif
#ifdef DONTDEF
void s_gdbline(), s_gdblinetab();
void s_gdbbeg(), s_gdbblock(), s_gdbend(), s_gdbsym();
#endif
void stringer();
void cons();
void float_cons();
void big_cons();
void stab();
static const pseudo_typeS
potable[] =
{
{ "abort", s_abort, 0 },
{ "align", s_align, 0 },
{ "ascii", stringer, 0 },
{ "asciz", stringer, 1 },
{ "byte", cons, 1 },
{ "comm", s_comm, 0 },
#ifdef VMS
{ "const", s_const, 0 },
#endif
{ "data", s_data, 0 },
{ "desc", s_desc, 0 },
{ "double", float_cons, 'd' },
{ "file", s_file, 0 },
{ "fill", s_fill, 0 },
{ "float", float_cons, 'f' },
#ifdef DONTDEF
{ "gdbbeg", s_gdbbeg, 0 },
{ "gdbblock", s_gdbblock, 0 },
{ "gdbend", s_gdbend, 0 },
{ "gdbsym", s_gdbsym, 0 },
{ "gdbline", s_gdbline, 0 },
{ "gdblinetab",s_gdblinetab, 0 },
#endif
{ "globl", s_globl, 0 },
{ "int", cons, 4 },
{ "lcomm", s_lcomm, 0 },
{ "line", s_line, 0 },
{ "long", cons, 4 },
{ "lsym", s_lsym, 0 },
{ "octa", big_cons, 16 },
{ "org", s_org, 0 },
{ "quad", big_cons, 8 },
{ "set", s_set, 0 },
{ "short", cons, 2 },
{ "single", float_cons, 'f' },
{ "space", s_space, 0 },
{ "stabd", stab, 'd' },
{ "stabn", stab, 'n' },
{ "stabs", stab, 's' },
{ "text", s_text, 0 },
#ifndef SPARC
{ "word", cons, 2 },
#endif
{ NULL} /* end sentinel */
};
static void
pobegin()
{
char * errtxt; /* error text */
const pseudo_typeS * pop;
po_hash = hash_new();
errtxt = ""; /* OK so far */
for (pop=potable; pop->poc_name && !*errtxt; pop++)
{
errtxt = hash_insert (po_hash, pop->poc_name, (char *)pop);
}
for(pop=md_pseudo_table; pop->poc_name && !*errtxt; pop++)
errtxt = hash_insert (po_hash, pop->poc_name, (char *)pop);
if (*errtxt)
{
as_fatal ("error constructing pseudo-op table");
}
} /* pobegin() */
/* read_a_source_file()
*
* File has already been opened, and will be closed by our caller.
*
* We read the file, putting things into a web that
* represents what we have been reading.
*/
void
read_a_source_file (buffer)
char * buffer; /* 1st character of each buffer of lines is here. */
{
register char c;
register char * s; /* string of symbol, '\0' appended */
register int temp;
/* register struct frag * fragP; JF unused */ /* a frag we just made */
pseudo_typeS *pop;
#ifdef DONTDEF
void gdb_block_beg();
void gdb_block_position();
void gdb_block_end();
void gdb_symbols_fixup();
#endif
subseg_new (SEG_TEXT, 0);
while ( buffer_limit = input_scrub_next_buffer (&buffer) )
{ /* We have another line to parse. */
know( buffer_limit [-1] == '\n' ); /* Must have a sentinel. */
input_line_pointer = buffer;
contin: /* JF this goto is my fault I admit it. Someone brave please re-write
the whole input section here? Pleeze??? */
while ( input_line_pointer < buffer_limit )
{ /* We have more of this buffer to parse. */
/*
* We now have input_line_pointer -> 1st char of next line.
* If input_line_pointer [-1] == '\n' then we just
* scanned another line: so bump line counters.
*/
if (input_line_pointer [-1] == '\n')
{
bump_line_counters ();
}
/*
* We are at the begining of a line, or similar place.
* We expect a well-formed assembler statement.
* A "symbol-name:" is a statement.
*
* Depending on what compiler is used, the order of these tests
* may vary to catch most common case 1st.
* Each test is independent of all other tests at the (top) level.
* PLEASE make a compiler that doesn't use this assembler.
* It is crufty to waste a compiler's time encoding things for this
* assembler, which then wastes more time decoding it.
* (And communicating via (linear) files is silly!
* If you must pass stuff, please pass a tree!)
*/
if ( (c= * input_line_pointer ++) == '\t' || c == ' ' || c=='\f')
{
c = * input_line_pointer ++;
}
know( c != ' ' ); /* No further leading whitespace. */
/*
* C is the 1st significant character.
* Input_line_pointer points after that character.
*/
if ( is_name_beginner(c) )
{ /* want user-defined label or pseudo/opcode */
s = -- input_line_pointer;
c = get_symbol_end(); /* name's delimiter */
/*
* C is character after symbol.
* That character's place in the input line is now '\0'.
* S points to the beginning of the symbol.
* [In case of pseudo-op, s -> '.'.]
* Input_line_pointer -> '\0' where c was.
*/
if ( c == ':' )
{
colon(s); /* user-defined label */
* input_line_pointer ++ = ':'; /* Put ':' back for error messages' sake. */
/* Input_line_pointer -> after ':'. */
SKIP_WHITESPACE();
}
else if(c=='=' || input_line_pointer[1]=='=') /* JF deal with FOO=BAR */
{
equals(s);
demand_empty_rest_of_line();
}
else
{ /* expect pseudo-op or machine instruction */
if ( *s=='.' )
{
/*
* PSEUDO - OP.
*
* WARNING: c has next char, which may be end-of-line.
* We lookup the pseudo-op table with s+1 because we
* already know that the pseudo-op begins with a '.'.
*/
pop= (pseudo_typeS *) hash_find (po_hash, s+1);
/* Print the error msg now, while we still can */
if(!pop)
as_bad("Unknown pseudo-op: '%s'",s);
/* Put it back for error messages etc. */
* input_line_pointer = c;
/* The following skip of whitespace is compulsory. */
/* A well shaped space is sometimes all that seperates keyword from operands. */
if ( c == ' ' || c == '\t' )
{ /* Skip seperator after keyword. */
input_line_pointer ++;
}
/*
* Input_line is restored.
* Input_line_pointer -> 1st non-blank char
* after pseudo-operation.
*/
if(!pop) {
ignore_rest_of_line();
break;
}
else
(*pop->poc_handler)(pop->poc_val);
}
else
{ /* machine instruction */
/* WARNING: c has char, which may be end-of-line. */
/* Also: input_line_pointer -> `\0` where c was. */
* input_line_pointer = c;
while ( ! is_end_of_line [* input_line_pointer] )
{
input_line_pointer ++;
}
c = * input_line_pointer;
* input_line_pointer = '\0';
md_assemble (s); /* Assemble 1 instruction. */
* input_line_pointer ++ = c;
/* We resume loop AFTER the end-of-line from this instruction */
} /* if (*s=='.') */
} /* if c==':' */
continue;
} /* if (is_name_beginner(c) */
if ( is_end_of_line [c] )
{ /* empty statement */
continue;
}
if ( isdigit(c) )
{ /* local label ("4:") */
temp = c - '0';
#ifdef SUN_ASM_SYNTAX
if( *input_line_pointer=='$')
input_line_pointer++;
#endif
if ( * input_line_pointer ++ == ':' )
{
local_colon (temp);
}
else
{
as_bad( "Spurious digit %d.", temp);
input_line_pointer -- ;
ignore_rest_of_line();
}
continue;
}
if(c && index(line_comment_chars,c)) { /* Its a comment. Better say APP or NO_APP */
char *ends;
char *strstr();
char *new_buf;
char *new_tmp;
int new_length;
char *tmp_buf = 0;
extern char *scrub_string,*scrub_last_string;
int scrub_from_string();
void scrub_to_string();
bump_line_counters();
s=input_line_pointer;
if(strncmp(s,"APP\n",4))
continue; /* We ignore it */
s+=4;
ends=strstr(s,"#NO_APP\n");
if(!ends) {
int tmp_len;
int num;
/* The end of the #APP wasn't in this buffer. We
keep reading in buffers until we find the #NO_APP
that goes with this #APP There is one. The specs
guarentee it. . .*/
tmp_len=buffer_limit-s;
tmp_buf=xmalloc(tmp_len);
bcopy(s,tmp_buf,tmp_len);
do {
new_tmp = input_scrub_next_buffer(&buffer);
if(!new_tmp)
break;
else
buffer_limit = new_tmp;
input_line_pointer = buffer;
ends = strstr(buffer,"#NO_APP\n");
if(ends)
num=ends-buffer;
else
num=buffer_limit-buffer;
tmp_buf=xrealloc(tmp_buf,tmp_len+num);
bcopy(buffer,tmp_buf+tmp_len,num);
tmp_len+=num;
} while(!ends);
input_line_pointer= ends ? ends+8 : NULL;
s=tmp_buf;
ends=s+tmp_len;
} else {
input_line_pointer=ends+8;
}
new_buf=xmalloc(100);
new_length=100;
new_tmp=new_buf;
scrub_string=s;
scrub_last_string = ends;
for(;;) {
int ch;
ch=do_scrub_next_char(scrub_from_string,scrub_to_string);
if(ch==EOF) break;
*new_tmp++=ch;
if(new_tmp==new_buf+new_length) {
new_buf=xrealloc(new_buf,new_length+100);
new_tmp=new_buf+new_length;
new_length+=100;
}
}
if(tmp_buf)
free(tmp_buf);
old_buffer=buffer;
old_input=input_line_pointer;
old_limit=buffer_limit;
buffer=new_buf;
input_line_pointer=new_buf;
buffer_limit=new_tmp;
continue;
}
as_bad("Junk character %d.",c);
ignore_rest_of_line();
} /* while (input_line_pointer<buffer_limit )*/
if(old_buffer) {
bump_line_counters();
if(old_input == 0)
return;
buffer=old_buffer;
input_line_pointer=old_input;
buffer_limit=old_limit;
old_buffer = 0;
goto contin;
}
} /* while (more bufrers to scan) */
} /* read_a_source_file() */
void
s_abort()
{
as_fatal(".abort detected. Abandoning ship.");
}
#ifdef OTHER_ALIGN
static void
s_align()
{
register unsigned int temp;
register long int temp_fill;
unsigned int i;
temp = get_absolute_expression ();
#define MAX_ALIGNMENT (1 << 15)
if ( temp > MAX_ALIGNMENT ) {
as_bad("Alignment too large: %d. assumed.", temp = MAX_ALIGNMENT);
}
/*
* For the sparc, `.align (1<<n)' actually means `.align n'
* so we have to convert it.
*/
if (temp != 0) {
for (i = 0; (temp & 1) == 0; temp >>= 1, ++i)
;
}
if (temp != 1)
as_bad("Alignment not a power of 2");
temp = i;
if (*input_line_pointer == ',') {
input_line_pointer ++;
temp_fill = get_absolute_expression ();
} else {
temp_fill = 0;
}
/* Only make a frag if we HAVE to. . . */
if (temp && ! need_pass_2)
frag_align (temp, (int)temp_fill);
demand_empty_rest_of_line();
}
#else
void
s_align()
{
register int temp;
register long int temp_fill;
temp = get_absolute_expression ();
#define MAX_ALIGNMENT (15)
if ( temp > MAX_ALIGNMENT )
as_bad("Alignment too large: %d. assumed.", temp = MAX_ALIGNMENT);
else if ( temp < 0 ) {
as_bad("Alignment negative. 0 assumed.");
temp = 0;
}
if ( *input_line_pointer == ',' ) {
input_line_pointer ++;
temp_fill = get_absolute_expression ();
} else
temp_fill = 0;
/* Only make a frag if we HAVE to. . . */
if ( temp && ! need_pass_2 )
frag_align (temp, (int)temp_fill);
demand_empty_rest_of_line();
}
#endif
void
s_comm()
{
register char *name;
register char c;
register char *p;
register int temp;
register symbolS * symbolP;
name = input_line_pointer;
c = get_symbol_end();
/* just after name is now '\0' */
p = input_line_pointer;
*p = c;
SKIP_WHITESPACE();
if ( * input_line_pointer != ',' ) {
as_bad("Expected comma after symbol-name");
ignore_rest_of_line();
return;
}
input_line_pointer ++; /* skip ',' */
if ( (temp = get_absolute_expression ()) < 0 ) {
as_warn(".COMMon length (%d.) <0! Ignored.", temp);
ignore_rest_of_line();
return;
}
*p = 0;
symbolP = symbol_find_or_make (name);
*p = c;
if ( (symbolP -> sy_type & N_TYPE) != N_UNDF ||
symbolP -> sy_other != 0 || symbolP -> sy_desc != 0) {
as_warn( "Ignoring attempt to re-define symbol");
ignore_rest_of_line();
return;
}
if (symbolP -> sy_value) {
if (symbolP -> sy_value != temp)
as_warn( "Length of .comm \"%s\" is already %d. Not changed to %d.",
symbolP -> sy_name, symbolP -> sy_value, temp);
} else {
symbolP -> sy_value = temp;
symbolP -> sy_type |= N_EXT;
}
#ifdef VMS
if(!temp)
symbolP->sy_other = const_flag;
#endif
know( symbolP -> sy_frag == &zero_address_frag );
demand_empty_rest_of_line();
}
#ifdef VMS
void
s_const()
{
register int temp;
temp = get_absolute_expression ();
subseg_new (SEG_DATA, (subsegT)temp);
const_flag = 1;
demand_empty_rest_of_line();
}
#endif
void
s_data()
{
register int temp;
temp = get_absolute_expression ();
subseg_new (SEG_DATA, (subsegT)temp);
#ifdef VMS
const_flag = 0;
#endif
demand_empty_rest_of_line();
}
void
s_desc()
{
register char *name;
register char c;
register char *p;
register symbolS * symbolP;
register int temp;
/*
* Frob invented at RMS' request. Set the n_desc of a symbol.
*/
name = input_line_pointer;
c = get_symbol_end();
p = input_line_pointer;
symbolP = symbol_table_lookup (name);
* p = c;
SKIP_WHITESPACE();
if ( * input_line_pointer != ',' ) {
*p = 0;
as_bad("Expected comma after name \"%s\"", name);
*p = c;
ignore_rest_of_line();
} else {
input_line_pointer ++;
temp = get_absolute_expression ();
*p = 0;
symbolP = symbol_find_or_make (name);
*p = c;
symbolP -> sy_desc = temp;
}
demand_empty_rest_of_line();
}
void
s_file()
{
register char *s;
int length;
/* Some assemblers tolerate immediately following '"' */
if ( s = demand_copy_C_string( & length ) ) {
module_name = s;
new_logical_line (s, -1);
demand_empty_rest_of_line();
}
}
void
s_fill()
{
long int temp_repeat;
long int temp_size;
register long int temp_fill;
char *p;
if ( get_absolute_expression_and_terminator(& temp_repeat) != ',' ) {
input_line_pointer --; /* Backup over what was not a ','. */
as_warn("Expect comma after rep-size in .fill");
ignore_rest_of_line();
return;
}
if ( get_absolute_expression_and_terminator( & temp_size) != ',' ) {
input_line_pointer --; /* Backup over what was not a ','. */
as_warn("Expected comma after size in .fill");
ignore_rest_of_line();
return;
}
/*
* This is to be compatible with BSD 4.2 AS, not for any rational reason.
*/
#define BSD_FILL_SIZE_CROCK_8 (8)
if ( temp_size > BSD_FILL_SIZE_CROCK_8 ) {
as_bad(".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8);
temp_size = BSD_FILL_SIZE_CROCK_8 ;
} if ( temp_size < 0 ) {
as_warn("Size negative: .fill ignored.");
temp_size = 0;
} else if ( temp_repeat <= 0 ) {
as_warn("Repeat < 0, .fill ignored");
temp_size = 0;
}
temp_fill = get_absolute_expression ();
if ( temp_size && !need_pass_2 ) {
p = frag_var (rs_fill, (int)temp_size, (int)temp_size, (relax_substateT)0, (symbolS *)0, temp_repeat, (char *)0);
bzero (p, (int)temp_size);
/*
* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX flavoured AS.
* The following bizzare behaviour is to be compatible with above.
* I guess they tried to take up to 8 bytes from a 4-byte expression
* and they forgot to sign extend. Un*x Sux.
*/
#define BSD_FILL_SIZE_CROCK_4 (4)
md_number_to_chars (p, temp_fill, temp_size > BSD_FILL_SIZE_CROCK_4 ? BSD_FILL_SIZE_CROCK_4 : (int)temp_size);
/*
* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
* but emits no error message because it seems a legal thing to do.
* It is a degenerate case of .fill but could be emitted by a compiler.
*/
}
demand_empty_rest_of_line();
}
#ifdef DONTDEF
void
s_gdbbeg()
{
register int temp;
temp = get_absolute_expression ();
if (temp < 0)
as_warn( "Block number <0. Ignored." );
else if (flagseen ['G'])
gdb_block_beg ( (long int) temp, frag_now, (long int)(obstack_next_free(& frags) - frag_now -> fr_literal));
demand_empty_rest_of_line ();
}
void
s_gdbblock()
{
register int position;
int temp;
if (get_absolute_expression_and_terminator (&temp) != ',') {
as_warn( "expected comma before position in .gdbblock");
--input_line_pointer;
ignore_rest_of_line ();
return;
}
position = get_absolute_expression ();
if (flagseen ['G'])
gdb_block_position ((long int) temp, (long int) position);
demand_empty_rest_of_line ();
}
void
s_gdbend()
{
register int temp;
temp = get_absolute_expression ();
if (temp < 0)
as_warn( "Block number <0. Ignored." );
else if (flagseen ['G'])
gdb_block_end ( (long int) temp, frag_now, (long int)(obstack_next_free(& frags) - frag_now -> fr_literal));
demand_empty_rest_of_line ();
}
void
s_gdbsym()
{
register char *name,
*p;
register char c;
register symbolS * symbolP;
register int temp;
name = input_line_pointer;
c = get_symbol_end();
p = input_line_pointer;
symbolP = symbol_find_or_make (name);
*p = c;
SKIP_WHITESPACE();
if ( * input_line_pointer != ',' ) {
as_warn("Expected comma after name");
ignore_rest_of_line();
return;
}
input_line_pointer ++;
if ( (temp = get_absolute_expression ()) < 0 ) {
as_warn("Bad GDB symbol file offset (%d.) <0! Ignored.", temp);
ignore_rest_of_line();
return;
}
if (flagseen ['G'])
gdb_symbols_fixup (symbolP, (long int)temp);
demand_empty_rest_of_line ();
}
void
s_gdbline()
{
int file_number,
lineno;
if(get_absolute_expression_and_terminator(&file_number) != ',') {
as_warn("expected comman after filenum in .gdbline");
ignore_rest_of_line();
return;
}
lineno=get_absolute_expression();
if(flagseen['G'])
gdb_line(file_number,lineno);
demand_empty_rest_of_line();
}
void
s_gdblinetab()
{
int file_number,
offset;
if(get_absolute_expression_and_terminator(&file_number) != ',') {
as_warn("expected comman after filenum in .gdblinetab");
ignore_rest_of_line();
return;
}
offset=get_absolute_expression();
if(flagseen['G'])
gdb_line_tab(file_number,offset);
demand_empty_rest_of_line();
}
#endif
void
s_globl()
{
register char *name;
register int c;
register symbolS * symbolP;
do {
name = input_line_pointer;
c = get_symbol_end();
symbolP = symbol_find_or_make (name);
* input_line_pointer = c;
SKIP_WHITESPACE();
symbolP -> sy_type |= N_EXT;
if(c==',') {
input_line_pointer++;
SKIP_WHITESPACE();
if(*input_line_pointer=='\n')
c='\n';
}
} while(c==',');
demand_empty_rest_of_line();
}
void
s_lcomm()
{
register char *name;
register char c;
register char *p;
register int temp;
register symbolS * symbolP;
name = input_line_pointer;
c = get_symbol_end();
p = input_line_pointer;
*p = c;
SKIP_WHITESPACE();
if ( * input_line_pointer != ',' ) {
as_warn("Expected comma after name");
ignore_rest_of_line();
return;
}
input_line_pointer ++;
if ( (temp = get_absolute_expression ()) < 0 ) {
as_warn("BSS length (%d.) <0! Ignored.", temp);
ignore_rest_of_line();
return;
}
*p = 0;
symbolP = symbol_find_or_make (name);
*p = c;
if ( symbolP -> sy_other == 0
&& symbolP -> sy_desc == 0
&& ( ( symbolP -> sy_type == N_BSS
&& symbolP -> sy_value == local_bss_counter)
|| ( (symbolP -> sy_type & N_TYPE) == N_UNDF
&& symbolP -> sy_value == 0))) {
symbolP -> sy_value = local_bss_counter;
symbolP -> sy_type = N_BSS;
symbolP -> sy_frag = & bss_address_frag;
local_bss_counter += temp;
} else
as_warn( "Ignoring attempt to re-define symbol from %d. to %d.",
symbolP -> sy_value, local_bss_counter );
demand_empty_rest_of_line();
}
void
s_line()
{
/* Assume delimiter is part of expression. */
/* BSD4.2 as fails with delightful bug, so we */
/* are not being incompatible here. */
new_logical_line ((char *)NULL, (int)(get_absolute_expression ()));
demand_empty_rest_of_line();
}
void
s_long()
{
cons(4);
}
void
s_int()
{
cons(4);
}
void
s_lsym()
{
register char *name;
register char c;
register char *p;
register segT segment;
expressionS exp;
register symbolS *symbolP;
/* we permit ANY expression: BSD4.2 demands constants */
name = input_line_pointer;
c = get_symbol_end();
p = input_line_pointer;
*p = c;
SKIP_WHITESPACE();
if ( * input_line_pointer != ',' ) {
*p = 0;
as_warn("Expected comma after name \"%s\"", name);
*p = c;
ignore_rest_of_line();
return;
}