github.com/rohankumardubey/syslog-redirector-golang@v0.0.0-20140320174030-4859f03d829a/src/cmd/6l/l.h (about) 1 // Inferno utils/6l/l.h 2 // http://code.google.com/p/inferno-os/source/browse/utils/6l/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 "6.out.h" 35 36 #ifndef EXTERN 37 #define EXTERN extern 38 #endif 39 40 enum 41 { 42 thechar = '6', 43 PtrSize = 8, 44 IntSize = 8, 45 MaxAlign = 32, // max data alignment 46 47 // Loop alignment constants: 48 // want to align loop entry to LoopAlign-byte boundary, 49 // and willing to insert at most MaxLoopPad bytes of NOP to do so. 50 // We define a loop entry as the target of a backward jump. 51 // 52 // gcc uses MaxLoopPad = 10 for its 'generic x86-64' config, 53 // and it aligns all jump targets, not just backward jump targets. 54 // 55 // As of 6/1/2012, the effect of setting MaxLoopPad = 10 here 56 // is very slight but negative, so the alignment is disabled by 57 // setting MaxLoopPad = 0. The code is here for reference and 58 // for future experiments. 59 // 60 LoopAlign = 16, 61 MaxLoopPad = 0, 62 63 FuncAlign = 16 64 }; 65 66 #define P ((Prog*)0) 67 #define S ((Sym*)0) 68 #define TNAME (cursym?cursym->name:noname) 69 70 typedef struct Adr Adr; 71 typedef struct Prog Prog; 72 typedef struct Sym Sym; 73 typedef struct Auto Auto; 74 typedef struct Optab Optab; 75 typedef struct Movtab Movtab; 76 typedef struct Reloc Reloc; 77 78 struct Adr 79 { 80 union 81 { 82 vlong u0offset; 83 char u0scon[8]; 84 Prog *u0cond; /* not used, but should be D_BRANCH */ 85 Ieee u0ieee; 86 char *u0sbig; 87 } u0; 88 Sym* sym; 89 short type; 90 char index; 91 char scale; 92 }; 93 94 #define offset u0.u0offset 95 #define scon u0.u0scon 96 #define cond u0.u0cond 97 #define ieee u0.u0ieee 98 #define sbig u0.u0sbig 99 100 struct Reloc 101 { 102 int32 off; 103 uchar siz; 104 uchar done; 105 int32 type; 106 int64 add; 107 int64 xadd; 108 Sym* sym; 109 Sym* xsym; 110 }; 111 112 struct Prog 113 { 114 Adr from; 115 Adr to; 116 Prog* forwd; 117 Prog* comefrom; 118 Prog* link; 119 Prog* pcond; /* work on this */ 120 vlong pc; 121 int32 spadj; 122 int32 line; 123 short as; 124 char ft; /* oclass cache */ 125 char tt; 126 uchar mark; /* work on these */ 127 uchar back; 128 129 char width; /* fake for DATA */ 130 char mode; /* 16, 32, or 64 */ 131 }; 132 #define datasize from.scale 133 #define textflag from.scale 134 #define iscall(p) ((p)->as == ACALL) 135 136 struct Auto 137 { 138 Sym* asym; 139 Auto* link; 140 int32 aoffset; 141 short type; 142 Sym* gotype; 143 }; 144 struct Sym 145 { 146 char* name; 147 char* extname; // name used in external object files 148 short type; 149 short version; 150 uchar dupok; 151 uchar reachable; 152 uchar cgoexport; 153 uchar special; 154 uchar stkcheck; 155 uchar hide; 156 int32 dynid; 157 int32 sig; 158 int32 plt; 159 int32 got; 160 int32 align; // if non-zero, required alignment in bytes 161 int32 elfsym; 162 int32 args; // size of stack frame incoming arguments area 163 Sym* hash; // in hash table 164 Sym* allsym; // in all symbol list 165 Sym* next; // in text or data list 166 Sym* sub; // in SSUB list 167 Sym* outer; // container of sub 168 Sym* reachparent; 169 Sym* queue; 170 vlong value; 171 vlong size; 172 Sym* gotype; 173 char* file; 174 char* dynimplib; 175 char* dynimpvers; 176 struct Section* sect; 177 struct Hist* hist; // for ATEXT 178 179 // STEXT 180 Auto* autom; 181 Prog* text; 182 183 // SDATA, SBSS 184 uchar* p; 185 int32 np; 186 int32 maxp; 187 Reloc* r; 188 int32 nr; 189 int32 maxr; 190 }; 191 struct Optab 192 { 193 short as; 194 uchar* ytab; 195 uchar prefix; 196 uchar op[23]; 197 }; 198 struct Movtab 199 { 200 short as; 201 uchar ft; 202 uchar tt; 203 uchar code; 204 uchar op[4]; 205 }; 206 207 enum 208 { 209 MINSIZ = 8, 210 STRINGSZ = 200, 211 MINLC = 1, 212 MAXIO = 8192, 213 MAXHIST = 40, /* limit of path elements for history symbols */ 214 215 Yxxx = 0, 216 Ynone, 217 Yi0, 218 Yi1, 219 Yi8, 220 Ys32, 221 Yi32, 222 Yi64, 223 Yiauto, 224 Yal, 225 Ycl, 226 Yax, 227 Ycx, 228 Yrb, 229 Yrl, 230 Yrf, 231 Yf0, 232 Yrx, 233 Ymb, 234 Yml, 235 Ym, 236 Ybr, 237 Ycol, 238 239 Ycs, Yss, Yds, Yes, Yfs, Ygs, 240 Ygdtr, Yidtr, Yldtr, Ymsw, Ytask, 241 Ycr0, Ycr1, Ycr2, Ycr3, Ycr4, Ycr5, Ycr6, Ycr7, Ycr8, 242 Ydr0, Ydr1, Ydr2, Ydr3, Ydr4, Ydr5, Ydr6, Ydr7, 243 Ytr0, Ytr1, Ytr2, Ytr3, Ytr4, Ytr5, Ytr6, Ytr7, Yrl32, Yrl64, 244 Ymr, Ymm, 245 Yxr, Yxm, 246 Ymax, 247 248 Zxxx = 0, 249 250 Zlit, 251 Zlitm_r, 252 Z_rp, 253 Zbr, 254 Zcall, 255 Zib_, 256 Zib_rp, 257 Zibo_m, 258 Zibo_m_xm, 259 Zil_, 260 Zil_rp, 261 Ziq_rp, 262 Zilo_m, 263 Ziqo_m, 264 Zjmp, 265 Zloop, 266 Zo_iw, 267 Zm_o, 268 Zm_r, 269 Zm2_r, 270 Zm_r_xm, 271 Zm_r_i_xm, 272 Zm_r_3d, 273 Zm_r_xm_nr, 274 Zr_m_xm_nr, 275 Zibm_r, /* mmx1,mmx2/mem64,imm8 */ 276 Zmb_r, 277 Zaut_r, 278 Zo_m, 279 Zo_m64, 280 Zpseudo, 281 Zr_m, 282 Zr_m_xm, 283 Zr_m_i_xm, 284 Zrp_, 285 Z_ib, 286 Z_il, 287 Zm_ibo, 288 Zm_ilo, 289 Zib_rr, 290 Zil_rr, 291 Zclr, 292 Zbyte, 293 Zmax, 294 295 Px = 0, 296 P32 = 0x32, /* 32-bit only */ 297 Pe = 0x66, /* operand escape */ 298 Pm = 0x0f, /* 2byte opcode escape */ 299 Pq = 0xff, /* both escapes: 66 0f */ 300 Pb = 0xfe, /* byte operands */ 301 Pf2 = 0xf2, /* xmm escape 1: f2 0f */ 302 Pf3 = 0xf3, /* xmm escape 2: f3 0f */ 303 Pq3 = 0x67, /* xmm escape 3: 66 48 0f */ 304 Pw = 0x48, /* Rex.w */ 305 Py = 0x80, /* defaults to 64-bit mode */ 306 307 Rxf = 1<<9, /* internal flag for Rxr on from */ 308 Rxt = 1<<8, /* internal flag for Rxr on to */ 309 Rxw = 1<<3, /* =1, 64-bit operand size */ 310 Rxr = 1<<2, /* extend modrm reg */ 311 Rxx = 1<<1, /* extend sib index */ 312 Rxb = 1<<0, /* extend modrm r/m, sib base, or opcode reg */ 313 314 Maxand = 10, /* in -a output width of the byte codes */ 315 }; 316 317 #pragma varargck type "A" uint 318 #pragma varargck type "D" Adr* 319 #pragma varargck type "I" uchar* 320 #pragma varargck type "P" Prog* 321 #pragma varargck type "R" int 322 #pragma varargck type "S" char* 323 #pragma varargck type "i" char* 324 325 EXTERN int32 HEADR; 326 EXTERN int32 HEADTYPE; 327 EXTERN int32 INITRND; 328 EXTERN int64 INITTEXT; 329 EXTERN int64 INITDAT; 330 EXTERN char* INITENTRY; /* entry point */ 331 EXTERN char* pcstr; 332 EXTERN Auto* curauto; 333 EXTERN Auto* curhist; 334 EXTERN Prog* curp; 335 EXTERN Sym* cursym; 336 EXTERN Sym* datap; 337 EXTERN int debug[128]; 338 EXTERN char literal[32]; 339 EXTERN Sym* textp; 340 EXTERN Sym* etextp; 341 EXTERN char ycover[Ymax*Ymax]; 342 EXTERN uchar* andptr; 343 EXTERN uchar* rexptr; 344 EXTERN uchar and[30]; 345 EXTERN int reg[D_NONE]; 346 EXTERN int regrex[D_NONE+1]; 347 EXTERN int32 lcsize; 348 EXTERN int nerrors; 349 EXTERN char* noname; 350 EXTERN char* outfile; 351 EXTERN vlong pc; 352 EXTERN char* interpreter; 353 EXTERN char* rpath; 354 EXTERN int32 spsize; 355 EXTERN Sym* symlist; 356 EXTERN int32 symsize; 357 EXTERN int tlsoffset; 358 EXTERN Prog zprg; 359 EXTERN int dtype; 360 EXTERN char* paramspace; 361 EXTERN Sym* adrgotype; // type symbol on last Adr read 362 EXTERN Sym* fromgotype; // type symbol on last p->from read 363 364 EXTERN vlong textstksiz; 365 EXTERN vlong textarg; 366 367 extern Optab optab[]; 368 extern Optab* opindex[]; 369 extern char* anames[]; 370 371 int Aconv(Fmt*); 372 int Dconv(Fmt*); 373 int Iconv(Fmt*); 374 int Pconv(Fmt*); 375 int Rconv(Fmt*); 376 int Sconv(Fmt*); 377 void addhist(int32, int); 378 void addstackmark(void); 379 Prog* appendp(Prog*); 380 void asmb(void); 381 void asmdyn(void); 382 void asmins(Prog*); 383 void asmsym(void); 384 void asmelfsym(void); 385 vlong atolwhex(char*); 386 Prog* brchain(Prog*); 387 Prog* brloop(Prog*); 388 void buildop(void); 389 Prog* copyp(Prog*); 390 double cputime(void); 391 void datblk(int32, int32); 392 void deadcode(void); 393 void diag(char*, ...); 394 void dodata(void); 395 void doelf(void); 396 void domacho(void); 397 void doprof1(void); 398 void doprof2(void); 399 void dostkoff(void); 400 vlong entryvalue(void); 401 void follow(void); 402 void gethunk(void); 403 void gotypestrings(void); 404 void listinit(void); 405 Sym* lookup(char*, int); 406 void lputb(int32); 407 void lputl(int32); 408 void instinit(void); 409 void main(int, char*[]); 410 void* mysbrk(uint32); 411 Prog* newtext(Prog*, Sym*); 412 void nopout(Prog*); 413 int opsize(Prog*); 414 void patch(void); 415 Prog* prg(void); 416 void parsetextconst(vlong); 417 int relinv(int); 418 vlong rnd(vlong, vlong); 419 void span(void); 420 void undef(void); 421 vlong symaddr(Sym*); 422 void vputb(uint64); 423 void vputl(uint64); 424 void wputb(uint16); 425 void wputl(uint16); 426 void xdefine(char*, int, vlong); 427 428 void machseg(char*, vlong, vlong, vlong, vlong, uint32, uint32, uint32, uint32); 429 void machsymseg(uint32, uint32); 430 void machsect(char*, char*, vlong, vlong, uint32, uint32, uint32, uint32, uint32); 431 void machstack(vlong); 432 void machdylink(void); 433 uint32 machheadr(void); 434 435 /* Native is little-endian */ 436 #define LPUT(a) lputl(a) 437 #define WPUT(a) wputl(a) 438 #define VPUT(a) vputl(a) 439 440 #pragma varargck type "D" Adr* 441 #pragma varargck type "P" Prog* 442 #pragma varargck type "R" int 443 #pragma varargck type "Z" char* 444 #pragma varargck type "A" int 445 #pragma varargck argpos diag 1 446 447 /* Used by ../ld/dwarf.c */ 448 enum 449 { 450 DWARFREGSP = 7 451 };