github.com/spotify/syslog-redirector-golang@v0.0.0-20140320174030-4859f03d829a/src/cmd/5l/l.h (about) 1 // Inferno utils/5l/l.h 2 // http://code.google.com/p/inferno-os/source/browse/utils/5l/l.h 3 // 4 // Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. 5 // Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net) 6 // Portions Copyright © 1997-1999 Vita Nuova Limited 7 // Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com) 8 // Portions Copyright © 2004,2006 Bruce Ellis 9 // Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net) 10 // Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others 11 // Portions Copyright © 2009 The Go Authors. All rights reserved. 12 // 13 // Permission is hereby granted, free of charge, to any person obtaining a copy 14 // of this software and associated documentation files (the "Software"), to deal 15 // in the Software without restriction, including without limitation the rights 16 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 // copies of the Software, and to permit persons to whom the Software is 18 // furnished to do so, subject to the following conditions: 19 // 20 // The above copyright notice and this permission notice shall be included in 21 // all copies or substantial portions of the Software. 22 // 23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 // THE SOFTWARE. 30 31 #include <u.h> 32 #include <libc.h> 33 #include <bio.h> 34 #include "5.out.h" 35 36 enum 37 { 38 thechar = '5', 39 PtrSize = 4, 40 IntSize = 4, 41 MaxAlign = 8, // max data alignment 42 FuncAlign = 4 // single-instruction alignment 43 }; 44 45 #ifndef EXTERN 46 #define EXTERN extern 47 #endif 48 49 /* do not undefine this - code will be removed eventually */ 50 #define CALLEEBX 51 52 #define dynptrsize 0 53 54 typedef struct Adr Adr; 55 typedef struct Sym Sym; 56 typedef struct Autom Auto; 57 typedef struct Prog Prog; 58 typedef struct Reloc Reloc; 59 typedef struct Optab Optab; 60 typedef struct Oprang Oprang; 61 typedef uchar Opcross[32][2][32]; 62 typedef struct Count Count; 63 64 #define P ((Prog*)0) 65 #define S ((Sym*)0) 66 #define TNAME (cursym?cursym->name:noname) 67 68 struct Adr 69 { 70 union 71 { 72 struct { 73 int32 u0offset; 74 int32 u0offset2; // argsize 75 } u0off; 76 char* u0sval; 77 Ieee u0ieee; 78 char* u0sbig; 79 } u0; 80 Sym* sym; 81 Sym* gotype; 82 char type; 83 char reg; 84 char name; 85 char class; 86 }; 87 88 #define offset u0.u0off.u0offset 89 #define offset2 u0.u0off.u0offset2 90 #define sval u0.u0sval 91 #define scon sval 92 #define ieee u0.u0ieee 93 #define sbig u0.u0sbig 94 95 struct Reloc 96 { 97 int32 off; 98 uchar siz; 99 uchar done; 100 int16 type; 101 int32 add; 102 int32 xadd; 103 Sym* sym; 104 Sym* xsym; 105 }; 106 107 struct Prog 108 { 109 Adr from; 110 Adr to; 111 union 112 { 113 int32 u0regused; 114 Prog* u0forwd; 115 } u0; 116 Prog* cond; 117 Prog* link; 118 Prog* pcrel; 119 int32 pc; 120 int32 line; 121 int32 spadj; 122 uchar mark; 123 uchar optab; 124 uchar as; 125 uchar scond; 126 uchar reg; 127 uchar align; // unused 128 }; 129 130 #define regused u0.u0regused 131 #define forwd u0.u0forwd 132 #define datasize reg 133 #define textflag reg 134 135 #define iscall(p) ((p)->as == ABL) 136 137 struct Sym 138 { 139 char* name; 140 char* extname; // name used in external object files 141 short type; 142 short version; 143 uchar dupok; 144 uchar reachable; 145 uchar cgoexport; 146 uchar leaf; 147 int32 dynid; 148 int32 plt; 149 int32 got; 150 int32 value; 151 int32 sig; 152 int32 size; 153 int32 align; // if non-zero, required alignment in bytes 154 int32 elfsym; 155 int32 locals; // size of stack frame locals area 156 int32 args; // size of stack frame incoming arguments area 157 uchar special; 158 uchar fnptr; // used as fn ptr 159 uchar stkcheck; 160 uchar hide; 161 Sym* hash; // in hash table 162 Sym* allsym; // in all symbol list 163 Sym* next; // in text or data list 164 Sym* sub; // in SSUB list 165 Sym* outer; // container of sub 166 Sym* gotype; 167 Sym* reachparent; 168 Sym* queue; 169 char* file; 170 char* dynimplib; 171 char* dynimpvers; 172 struct Section* sect; 173 struct Hist* hist; 174 175 // STEXT 176 Auto* autom; 177 Prog* text; 178 179 // SDATA, SBSS 180 uchar* p; 181 int32 np; 182 int32 maxp; 183 Reloc* r; 184 int32 nr; 185 int32 maxr; 186 }; 187 188 #define SIGNINTERN (1729*325*1729) 189 190 struct Autom 191 { 192 Sym* asym; 193 Auto* link; 194 int32 aoffset; 195 short type; 196 Sym* gotype; 197 }; 198 struct Optab 199 { 200 char as; 201 uchar a1; 202 char a2; 203 uchar a3; 204 uchar type; 205 char size; 206 char param; 207 char flag; 208 uchar pcrelsiz; 209 }; 210 struct Oprang 211 { 212 Optab* start; 213 Optab* stop; 214 }; 215 struct Count 216 { 217 int32 count; 218 int32 outof; 219 }; 220 221 enum 222 { 223 LFROM = 1<<0, 224 LTO = 1<<1, 225 LPOOL = 1<<2, 226 LPCREL = 1<<3, 227 228 C_NONE = 0, 229 C_REG, 230 C_REGREG, 231 C_REGREG2, 232 C_SHIFT, 233 C_FREG, 234 C_PSR, 235 C_FCR, 236 237 C_RCON, /* 0xff rotated */ 238 C_NCON, /* ~RCON */ 239 C_SCON, /* 0xffff */ 240 C_LCON, 241 C_LCONADDR, 242 C_ZFCON, 243 C_SFCON, 244 C_LFCON, 245 246 C_RACON, 247 C_LACON, 248 249 C_SBRA, 250 C_LBRA, 251 252 C_HAUTO, /* halfword insn offset (-0xff to 0xff) */ 253 C_FAUTO, /* float insn offset (0 to 0x3fc, word aligned) */ 254 C_HFAUTO, /* both H and F */ 255 C_SAUTO, /* -0xfff to 0xfff */ 256 C_LAUTO, 257 258 C_HOREG, 259 C_FOREG, 260 C_HFOREG, 261 C_SOREG, 262 C_ROREG, 263 C_SROREG, /* both S and R */ 264 C_LOREG, 265 266 C_PC, 267 C_SP, 268 C_HREG, 269 270 C_ADDR, /* reference to relocatable address */ 271 272 C_GOK, 273 274 /* mark flags */ 275 FOLL = 1<<0, 276 LABEL = 1<<1, 277 LEAF = 1<<2, 278 279 STRINGSZ = 200, 280 MINSIZ = 64, 281 NENT = 100, 282 MAXIO = 8192, 283 MAXHIST = 40, /* limit of path elements for history symbols */ 284 MINLC = 4, 285 }; 286 287 #ifndef COFFCVT 288 289 EXTERN int32 HEADR; /* length of header */ 290 EXTERN int HEADTYPE; /* type of header */ 291 EXTERN int32 INITDAT; /* data location */ 292 EXTERN int32 INITRND; /* data round above text location */ 293 EXTERN int32 INITTEXT; /* text location */ 294 EXTERN char* INITENTRY; /* entry point */ 295 EXTERN int32 autosize; 296 EXTERN Auto* curauto; 297 EXTERN Auto* curhist; 298 EXTERN Prog* curp; 299 EXTERN Sym* cursym; 300 EXTERN Sym* datap; 301 EXTERN int debug[128]; 302 EXTERN Sym* etextp; 303 EXTERN char* noname; 304 EXTERN Prog* lastp; 305 EXTERN int32 lcsize; 306 EXTERN char literal[32]; 307 EXTERN int nerrors; 308 EXTERN int32 instoffset; 309 EXTERN Opcross opcross[8]; 310 EXTERN Oprang oprange[ALAST]; 311 EXTERN char* outfile; 312 EXTERN int32 pc; 313 EXTERN uchar repop[ALAST]; 314 EXTERN char* interpreter; 315 EXTERN char* rpath; 316 EXTERN uint32 stroffset; 317 EXTERN int32 symsize; 318 EXTERN Sym* textp; 319 EXTERN char xcmp[C_GOK+1][C_GOK+1]; 320 EXTERN Prog zprg; 321 EXTERN int dtype; 322 EXTERN int tlsoffset; 323 EXTERN int armsize; 324 EXTERN int goarm; 325 EXTERN Sym* adrgotype; // type symbol on last Adr read 326 EXTERN Sym* fromgotype; // type symbol on last p->from read 327 328 extern char* anames[]; 329 extern Optab optab[]; 330 331 void addpool(Prog*, Adr*); 332 EXTERN Prog* blitrl; 333 EXTERN Prog* elitrl; 334 335 EXTERN int goarm; 336 337 void initdiv(void); 338 EXTERN Prog* prog_div; 339 EXTERN Prog* prog_divu; 340 EXTERN Prog* prog_mod; 341 EXTERN Prog* prog_modu; 342 343 #pragma varargck type "A" int 344 #pragma varargck type "C" int 345 #pragma varargck type "D" Adr* 346 #pragma varargck type "I" uchar* 347 #pragma varargck type "N" Adr* 348 #pragma varargck type "P" Prog* 349 #pragma varargck type "S" char* 350 #pragma varargck type "Z" char* 351 #pragma varargck type "i" char* 352 353 int Aconv(Fmt*); 354 int Cconv(Fmt*); 355 int Dconv(Fmt*); 356 int Iconv(Fmt*); 357 int Nconv(Fmt*); 358 int Oconv(Fmt*); 359 int Pconv(Fmt*); 360 int Sconv(Fmt*); 361 int aclass(Adr*); 362 void addhist(int32, int); 363 Prog* appendp(Prog*); 364 void asmb(void); 365 void asmout(Prog*, Optab*, int32*, Sym*); 366 int32 atolwhex(char*); 367 Prog* brloop(Prog*); 368 void buildop(void); 369 void buildrep(int, int); 370 void cflush(void); 371 int chipzero(Ieee*); 372 int chipfloat(Ieee*); 373 int cmp(int, int); 374 int compound(Prog*); 375 double cputime(void); 376 void diag(char*, ...); 377 void divsig(void); 378 void dodata(void); 379 void doprof1(void); 380 void doprof2(void); 381 int32 entryvalue(void); 382 void exchange(Prog*); 383 void follow(void); 384 void hputl(int); 385 int isnop(Prog*); 386 void listinit(void); 387 Sym* lookup(char*, int); 388 void cput(int); 389 void hput(int32); 390 void lput(int32); 391 void lputb(int32); 392 void lputl(int32); 393 void* mysbrk(uint32); 394 void names(void); 395 void nocache(Prog*); 396 int ocmp(const void*, const void*); 397 int32 opirr(int); 398 Optab* oplook(Prog*); 399 int32 oprrr(int, int); 400 int32 olr(int32, int, int, int); 401 int32 olhr(int32, int, int, int); 402 int32 olrr(int, int, int, int); 403 int32 olhrr(int, int, int, int); 404 int32 osr(int, int, int32, int, int); 405 int32 oshr(int, int32, int, int); 406 int32 ofsr(int, int, int32, int, int, Prog*); 407 int32 osrr(int, int, int, int); 408 int32 oshrr(int, int, int, int); 409 int32 omvl(Prog*, Adr*, int); 410 void patch(void); 411 void prasm(Prog*); 412 void prepend(Prog*, Prog*); 413 Prog* prg(void); 414 int pseudo(Prog*); 415 int32 regoff(Adr*); 416 int relinv(int); 417 int32 rnd(int32, int32); 418 void softfloat(void); 419 void span(void); 420 void strnput(char*, int); 421 int32 symaddr(Sym*); 422 void undef(void); 423 void vputb(uint64); 424 void vputl(uint64); 425 void wputb(uint16); 426 void wput(int32); 427 void wputl(ushort w); 428 void xdefine(char*, int, int32); 429 void noops(void); 430 int32 immrot(uint32); 431 int32 immaddr(int32); 432 int32 opbra(int, int); 433 int brextra(Prog*); 434 int isbranch(Prog*); 435 void doelf(void); 436 void dozerostk(void); // used by -Z 437 438 vlong addaddr(Sym *s, Sym *t); 439 vlong addsize(Sym *s, Sym *t); 440 vlong addstring(Sym *s, char *str); 441 vlong adduint16(Sym *s, uint16 v); 442 vlong adduint32(Sym *s, uint32 v); 443 vlong adduint64(Sym *s, uint64 v); 444 vlong adduint8(Sym *s, uint8 v); 445 vlong adduintxx(Sym *s, uint64 v, int wid); 446 447 /* Native is little-endian */ 448 #define LPUT(a) lputl(a) 449 #define WPUT(a) wputl(a) 450 #define VPUT(a) abort() 451 452 #endif 453 454 /* Used by ../ld/dwarf.c */ 455 enum 456 { 457 DWARFREGSP = 13 458 };