github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/src/cmd/8l/l.h (about) 1 // Inferno utils/8l/l.h 2 // http://code.google.com/p/inferno-os/source/browse/utils/8l/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 "8.out.h" 35 36 #ifndef EXTERN 37 #define EXTERN extern 38 #endif 39 40 enum 41 { 42 thechar = '8', 43 PtrSize = 4, 44 IntSize = 4, 45 MaxAlign = 32, // max data alignment 46 FuncAlign = 16 47 }; 48 49 #define P ((Prog*)0) 50 #define S ((Sym*)0) 51 #define TNAME (cursym?cursym->name:noname) 52 53 typedef struct Adr Adr; 54 typedef struct Prog Prog; 55 typedef struct Sym Sym; 56 typedef struct Auto Auto; 57 typedef struct Optab Optab; 58 typedef struct Reloc Reloc; 59 60 struct Adr 61 { 62 union 63 { 64 int32 u0offset; 65 char u0scon[8]; 66 Prog *u0cond; /* not used, but should be D_BRANCH */ 67 Ieee u0ieee; 68 char *u0sbig; 69 } u0; 70 Sym* sym; 71 short type; 72 uchar index; 73 char scale; 74 int32 offset2; 75 }; 76 77 #define offset u0.u0offset 78 #define scon u0.u0scon 79 #define cond u0.u0cond 80 #define ieee u0.u0ieee 81 #define sbig u0.u0sbig 82 83 struct Reloc 84 { 85 int32 off; 86 uchar siz; 87 uchar done; 88 int32 type; 89 int32 add; 90 int32 xadd; 91 Sym* sym; 92 Sym* xsym; 93 }; 94 95 struct Prog 96 { 97 Adr from; 98 Adr to; 99 Prog* forwd; 100 Prog* comefrom; 101 Prog* link; 102 Prog* pcond; /* work on this */ 103 int32 pc; 104 int32 spadj; 105 int32 line; 106 short as; 107 char width; /* fake for DATA */ 108 char ft; /* oclass cache */ 109 char tt; 110 uchar mark; /* work on these */ 111 uchar back; 112 uchar bigjmp; 113 }; 114 #define datasize from.scale 115 #define textflag from.scale 116 #define iscall(p) ((p)->as == ACALL) 117 118 struct Auto 119 { 120 Sym* asym; 121 Auto* link; 122 int32 aoffset; 123 short type; 124 Sym* gotype; 125 }; 126 struct Sym 127 { 128 char* name; 129 char* extname; // name used in external object files 130 short type; 131 short version; 132 uchar dupok; 133 uchar reachable; 134 uchar cgoexport; 135 uchar special; 136 uchar stkcheck; 137 uchar hide; 138 int32 value; 139 int32 size; 140 int32 sig; 141 int32 dynid; 142 int32 plt; 143 int32 got; 144 int32 align; // if non-zero, required alignment in bytes 145 int32 elfsym; 146 int32 locals; // size of stack frame locals area 147 int32 args; // size of stack frame incoming arguments area 148 Sym* hash; // in hash table 149 Sym* allsym; // in all symbol list 150 Sym* next; // in text or data list 151 Sym* sub; // in sub list 152 Sym* outer; // container of sub 153 Sym* gotype; 154 Sym* reachparent; 155 Sym* queue; 156 char* file; 157 char* dynimplib; 158 char* dynimpvers; 159 struct Section* sect; 160 161 // STEXT 162 Auto* autom; 163 Prog* text; 164 165 // SDATA, SBSS 166 uchar* p; 167 int32 np; 168 int32 maxp; 169 Reloc* r; 170 int32 nr; 171 int32 maxr; 172 int rel_ro; 173 }; 174 struct Optab 175 { 176 short as; 177 uchar* ytab; 178 uchar prefix; 179 uchar op[12]; 180 }; 181 182 enum 183 { 184 MINSIZ = 4, 185 STRINGSZ = 200, 186 MINLC = 1, 187 MAXIO = 8192, 188 MAXHIST = 20, /* limit of path elements for history symbols */ 189 190 Yxxx = 0, 191 Ynone, 192 Yi0, 193 Yi1, 194 Yi8, 195 Yi32, 196 Yiauto, 197 Yal, 198 Ycl, 199 Yax, 200 Ycx, 201 Yrb, 202 Yrl, 203 Yrf, 204 Yf0, 205 Yrx, 206 Ymb, 207 Yml, 208 Ym, 209 Ybr, 210 Ycol, 211 212 Ycs, Yss, Yds, Yes, Yfs, Ygs, 213 Ygdtr, Yidtr, Yldtr, Ymsw, Ytask, 214 Ycr0, Ycr1, Ycr2, Ycr3, Ycr4, Ycr5, Ycr6, Ycr7, 215 Ydr0, Ydr1, Ydr2, Ydr3, Ydr4, Ydr5, Ydr6, Ydr7, 216 Ytr0, Ytr1, Ytr2, Ytr3, Ytr4, Ytr5, Ytr6, Ytr7, 217 Ymr, Ymm, 218 Yxr, Yxm, 219 Ymax, 220 221 Zxxx = 0, 222 223 Zlit, 224 Zlitm_r, 225 Z_rp, 226 Zbr, 227 Zcall, 228 Zcallcon, 229 Zcallind, 230 Zib_, 231 Zib_rp, 232 Zibo_m, 233 Zil_, 234 Zil_rp, 235 Zilo_m, 236 Zjmp, 237 Zjmpcon, 238 Zloop, 239 Zm_o, 240 Zm_r, 241 Zm2_r, 242 Zm_r_xm, 243 Zm_r_i_xm, 244 Zaut_r, 245 Zo_m, 246 Zpseudo, 247 Zr_m, 248 Zr_m_xm, 249 Zr_m_i_xm, 250 Zrp_, 251 Z_ib, 252 Z_il, 253 Zm_ibo, 254 Zm_ilo, 255 Zib_rr, 256 Zil_rr, 257 Zclr, 258 Zibm_r, /* mmx1,mmx2/mem64,imm8 */ 259 Zbyte, 260 Zmov, 261 Zmax, 262 263 Px = 0, 264 Pe = 0x66, /* operand escape */ 265 Pm = 0x0f, /* 2byte opcode escape */ 266 Pq = 0xff, /* both escape */ 267 Pb = 0xfe, /* byte operands */ 268 Pf2 = 0xf2, /* xmm escape 1 */ 269 Pf3 = 0xf3, /* xmm escape 2 */ 270 }; 271 272 #pragma varargck type "A" int 273 #pragma varargck type "D" Adr* 274 #pragma varargck type "I" uchar* 275 #pragma varargck type "P" Prog* 276 #pragma varargck type "R" int 277 #pragma varargck type "S" char* 278 #pragma varargck type "Y" Sym* 279 #pragma varargck type "Z" char* 280 #pragma varargck type "i" char* 281 282 EXTERN int32 HEADR; 283 EXTERN int32 HEADTYPE; 284 EXTERN int32 INITRND; 285 EXTERN int32 INITTEXT; 286 EXTERN int32 INITDAT; 287 EXTERN char* INITENTRY; /* entry point */ 288 EXTERN char* LIBINITENTRY; /* shared library entry point */ 289 EXTERN char* pcstr; 290 EXTERN Auto* curauto; 291 EXTERN Auto* curhist; 292 EXTERN Prog* curp; 293 EXTERN Sym* cursym; 294 EXTERN Sym* datap; 295 EXTERN int debug[128]; 296 EXTERN char literal[32]; 297 EXTERN Sym* etextp; 298 EXTERN Prog* firstp; 299 EXTERN uchar ycover[Ymax*Ymax]; 300 EXTERN uchar* andptr; 301 EXTERN uchar and[100]; 302 EXTERN char reg[D_NONE]; 303 EXTERN int32 lcsize; 304 EXTERN int maxop; 305 EXTERN int nerrors; 306 EXTERN char* noname; 307 EXTERN int32 pc; 308 EXTERN char* rpath; 309 EXTERN int32 spsize; 310 EXTERN Sym* symlist; 311 EXTERN int32 symsize; 312 EXTERN Sym* textp; 313 EXTERN int32 textsize; 314 EXTERN int version; 315 EXTERN Prog zprg; 316 EXTERN int dtype; 317 EXTERN int tlsoffset; 318 EXTERN Sym* adrgotype; // type symbol on last Adr read 319 EXTERN Sym* fromgotype; // type symbol on last p->from read 320 321 extern Optab optab[]; 322 extern char* anames[]; 323 324 int Aconv(Fmt*); 325 int Dconv(Fmt*); 326 int Iconv(Fmt*); 327 int Pconv(Fmt*); 328 int Rconv(Fmt*); 329 int Sconv(Fmt*); 330 void addhist(int32, int); 331 Prog* appendp(Prog*); 332 void asmb(void); 333 void asmdyn(void); 334 void asmins(Prog*); 335 void asmsym(void); 336 int32 atolwhex(char*); 337 Prog* brchain(Prog*); 338 Prog* brloop(Prog*); 339 void cflush(void); 340 Prog* copyp(Prog*); 341 vlong cpos(void); 342 double cputime(void); 343 void diag(char*, ...); 344 void dodata(void); 345 void doelf(void); 346 void doprof1(void); 347 void doprof2(void); 348 void dostkoff(void); 349 int32 entryvalue(void); 350 void follow(void); 351 void instinit(void); 352 void listinit(void); 353 Sym* lookup(char*, int); 354 void lputb(int32); 355 void lputl(int32); 356 void vputl(uint64); 357 void strnput(char*, int); 358 void main(int, char*[]); 359 void* mal(uint32); 360 int opsize(Prog*); 361 void patch(void); 362 Prog* prg(void); 363 int relinv(int); 364 int32 rnd(int32, int32); 365 void s8put(char*); 366 void span(void); 367 void undef(void); 368 int32 symaddr(Sym*); 369 void wput(ushort); 370 void wputl(ushort); 371 void xdefine(char*, int, int32); 372 373 uint32 machheadr(void); 374 vlong addaddr(Sym *s, Sym *t); 375 vlong addsize(Sym *s, Sym *t); 376 vlong addstring(Sym *s, char *str); 377 vlong adduint16(Sym *s, uint16 v); 378 vlong adduint32(Sym *s, uint32 v); 379 vlong adduint64(Sym *s, uint64 v); 380 vlong adduint8(Sym *s, uint8 v); 381 vlong adduintxx(Sym *s, uint64 v, int wid); 382 383 /* 384 * go.c 385 */ 386 void deadcode(void); 387 388 /* Native is little-endian */ 389 #define LPUT(a) lputl(a) 390 #define WPUT(a) wputl(a) 391 #define VPUT(a) vputl(a) 392 393 /* Used by ../ld/dwarf.c */ 394 enum 395 { 396 DWARFREGSP = 4 397 };