github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/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 locals; // size of stack frame locals area 163 int32 args; // size of stack frame incoming arguments area 164 Sym* hash; // in hash table 165 Sym* allsym; // in all symbol list 166 Sym* next; // in text or data list 167 Sym* sub; // in SSUB list 168 Sym* outer; // container of sub 169 Sym* reachparent; 170 Sym* queue; 171 vlong value; 172 vlong size; 173 Sym* gotype; 174 char* file; 175 char* dynimplib; 176 char* dynimpvers; 177 struct Section* sect; 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 int rel_ro; 191 }; 192 struct Optab 193 { 194 short as; 195 uchar* ytab; 196 uchar prefix; 197 uchar op[22]; 198 }; 199 struct Movtab 200 { 201 short as; 202 uchar ft; 203 uchar tt; 204 uchar code; 205 uchar op[4]; 206 }; 207 208 enum 209 { 210 MINSIZ = 8, 211 STRINGSZ = 200, 212 MINLC = 1, 213 MAXIO = 8192, 214 MAXHIST = 20, /* limit of path elements for history symbols */ 215 216 Yxxx = 0, 217 Ynone, 218 Yi0, 219 Yi1, 220 Yi8, 221 Ys32, 222 Yi32, 223 Yi64, 224 Yiauto, 225 Yal, 226 Ycl, 227 Yax, 228 Ycx, 229 Yrb, 230 Yrl, 231 Yrf, 232 Yf0, 233 Yrx, 234 Ymb, 235 Yml, 236 Ym, 237 Ybr, 238 Ycol, 239 240 Ycs, Yss, Yds, Yes, Yfs, Ygs, 241 Ygdtr, Yidtr, Yldtr, Ymsw, Ytask, 242 Ycr0, Ycr1, Ycr2, Ycr3, Ycr4, Ycr5, Ycr6, Ycr7, Ycr8, 243 Ydr0, Ydr1, Ydr2, Ydr3, Ydr4, Ydr5, Ydr6, Ydr7, 244 Ytr0, Ytr1, Ytr2, Ytr3, Ytr4, Ytr5, Ytr6, Ytr7, Yrl32, Yrl64, 245 Ymr, Ymm, 246 Yxr, Yxm, 247 Ymax, 248 249 Zxxx = 0, 250 251 Zlit, 252 Zlitm_r, 253 Z_rp, 254 Zbr, 255 Zcall, 256 Zib_, 257 Zib_rp, 258 Zibo_m, 259 Zibo_m_xm, 260 Zil_, 261 Zil_rp, 262 Ziq_rp, 263 Zilo_m, 264 Ziqo_m, 265 Zjmp, 266 Zloop, 267 Zo_iw, 268 Zm_o, 269 Zm_r, 270 Zm2_r, 271 Zm_r_xm, 272 Zm_r_i_xm, 273 Zm_r_3d, 274 Zm_r_xm_nr, 275 Zr_m_xm_nr, 276 Zibm_r, /* mmx1,mmx2/mem64,imm8 */ 277 Zmb_r, 278 Zaut_r, 279 Zo_m, 280 Zo_m64, 281 Zpseudo, 282 Zr_m, 283 Zr_m_xm, 284 Zr_m_i_xm, 285 Zrp_, 286 Z_ib, 287 Z_il, 288 Zm_ibo, 289 Zm_ilo, 290 Zib_rr, 291 Zil_rr, 292 Zclr, 293 Zbyte, 294 Zmax, 295 296 Px = 0, 297 P32 = 0x32, /* 32-bit only */ 298 Pe = 0x66, /* operand escape */ 299 Pm = 0x0f, /* 2byte opcode escape */ 300 Pq = 0xff, /* both escapes: 66 0f */ 301 Pb = 0xfe, /* byte operands */ 302 Pf2 = 0xf2, /* xmm escape 1: f2 0f */ 303 Pf3 = 0xf3, /* xmm escape 2: f3 0f */ 304 Pq3 = 0x67, /* xmm escape 3: 66 48 0f */ 305 Pw = 0x48, /* Rex.w */ 306 Py = 0x80, /* defaults to 64-bit mode */ 307 308 Rxf = 1<<9, /* internal flag for Rxr on from */ 309 Rxt = 1<<8, /* internal flag for Rxr on to */ 310 Rxw = 1<<3, /* =1, 64-bit operand size */ 311 Rxr = 1<<2, /* extend modrm reg */ 312 Rxx = 1<<1, /* extend sib index */ 313 Rxb = 1<<0, /* extend modrm r/m, sib base, or opcode reg */ 314 315 Maxand = 10, /* in -a output width of the byte codes */ 316 }; 317 318 #pragma varargck type "A" uint 319 #pragma varargck type "D" Adr* 320 #pragma varargck type "I" uchar* 321 #pragma varargck type "P" Prog* 322 #pragma varargck type "R" int 323 #pragma varargck type "S" char* 324 #pragma varargck type "i" char* 325 326 EXTERN int32 HEADR; 327 EXTERN int32 HEADTYPE; 328 EXTERN int32 INITRND; 329 EXTERN int64 INITTEXT; 330 EXTERN int64 INITDAT; 331 EXTERN char* INITENTRY; /* entry point */ 332 EXTERN char* LIBINITENTRY; /* shared library entry point */ 333 EXTERN char* pcstr; 334 EXTERN Auto* curauto; 335 EXTERN Auto* curhist; 336 EXTERN Prog* curp; 337 EXTERN Sym* cursym; 338 EXTERN Sym* datap; 339 EXTERN int debug[128]; 340 EXTERN char literal[32]; 341 EXTERN Sym* textp; 342 EXTERN Sym* etextp; 343 EXTERN char ycover[Ymax*Ymax]; 344 EXTERN uchar* andptr; 345 EXTERN uchar* rexptr; 346 EXTERN uchar and[30]; 347 EXTERN int reg[D_NONE]; 348 EXTERN int regrex[D_NONE+1]; 349 EXTERN int32 lcsize; 350 EXTERN int nerrors; 351 EXTERN char* noname; 352 EXTERN char* outfile; 353 EXTERN vlong pc; 354 EXTERN char* interpreter; 355 EXTERN char* rpath; 356 EXTERN int32 spsize; 357 EXTERN Sym* symlist; 358 EXTERN int32 symsize; 359 EXTERN int tlsoffset; 360 EXTERN int version; 361 EXTERN Prog zprg; 362 EXTERN int dtype; 363 EXTERN char* paramspace; 364 EXTERN Sym* adrgotype; // type symbol on last Adr read 365 EXTERN Sym* fromgotype; // type symbol on last p->from read 366 367 EXTERN vlong textstksiz; 368 EXTERN vlong textarg; 369 370 extern Optab optab[]; 371 extern Optab* opindex[]; 372 extern char* anames[]; 373 374 int Aconv(Fmt*); 375 int Dconv(Fmt*); 376 int Iconv(Fmt*); 377 int Pconv(Fmt*); 378 int Rconv(Fmt*); 379 int Sconv(Fmt*); 380 void addhist(int32, int); 381 void addstackmark(void); 382 Prog* appendp(Prog*); 383 void asmb(void); 384 void asmdyn(void); 385 void asmins(Prog*); 386 void asmsym(void); 387 void asmelfsym(void); 388 vlong atolwhex(char*); 389 Prog* brchain(Prog*); 390 Prog* brloop(Prog*); 391 void buildop(void); 392 Prog* copyp(Prog*); 393 double cputime(void); 394 void datblk(int32, int32); 395 void deadcode(void); 396 void diag(char*, ...); 397 void dodata(void); 398 void doelf(void); 399 void domacho(void); 400 void doprof1(void); 401 void doprof2(void); 402 void dostkoff(void); 403 vlong entryvalue(void); 404 void follow(void); 405 void gethunk(void); 406 void gotypestrings(void); 407 void listinit(void); 408 Sym* lookup(char*, int); 409 void lputb(int32); 410 void lputl(int32); 411 void instinit(void); 412 void main(int, char*[]); 413 void* mysbrk(uint32); 414 Prog* newtext(Prog*, Sym*); 415 void nopout(Prog*); 416 int opsize(Prog*); 417 void patch(void); 418 Prog* prg(void); 419 void parsetextconst(vlong); 420 int relinv(int); 421 vlong rnd(vlong, vlong); 422 void span(void); 423 void undef(void); 424 vlong symaddr(Sym*); 425 void vputb(uint64); 426 void vputl(uint64); 427 void wputb(uint16); 428 void wputl(uint16); 429 void xdefine(char*, int, vlong); 430 431 void machseg(char*, vlong, vlong, vlong, vlong, uint32, uint32, uint32, uint32); 432 void machsymseg(uint32, uint32); 433 void machsect(char*, char*, vlong, vlong, uint32, uint32, uint32, uint32, uint32); 434 void machstack(vlong); 435 void machdylink(void); 436 uint32 machheadr(void); 437 438 /* Native is little-endian */ 439 #define LPUT(a) lputl(a) 440 #define WPUT(a) wputl(a) 441 #define VPUT(a) vputl(a) 442 443 #pragma varargck type "D" Adr* 444 #pragma varargck type "P" Prog* 445 #pragma varargck type "R" int 446 #pragma varargck type "Z" char* 447 #pragma varargck type "A" int 448 #pragma varargck argpos diag 1 449 450 /* Used by ../ld/dwarf.c */ 451 enum 452 { 453 DWARFREGSP = 7 454 };