list.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #define EXTERN
  10. #include "gc.h"
  11. void
  12. listinit(void)
  13. {
  14. fmtinstall('A', Aconv);
  15. fmtinstall('B', Bconv);
  16. fmtinstall('P', Pconv);
  17. fmtinstall('S', Sconv);
  18. fmtinstall('D', Dconv);
  19. fmtinstall('R', Rconv);
  20. }
  21. int
  22. Bconv(Fmt *fp)
  23. {
  24. char str[STRINGSZ], ss[STRINGSZ], *s;
  25. Bits bits;
  26. int i;
  27. str[0] = 0;
  28. bits = va_arg(fp->args, Bits);
  29. while(bany(&bits)) {
  30. i = bnum(bits);
  31. if(str[0])
  32. strcat(str, " ");
  33. if(var[i].sym == S) {
  34. sprint(ss, "$%lld", var[i].offset);
  35. s = ss;
  36. } else
  37. s = var[i].sym->name;
  38. if(strlen(str) + strlen(s) + 1 >= STRINGSZ)
  39. break;
  40. strcat(str, s);
  41. bits.b[i/32] &= ~(1L << (i%32));
  42. }
  43. return fmtstrcpy(fp, str);
  44. }
  45. int
  46. Pconv(Fmt *fp)
  47. {
  48. char str[STRINGSZ];
  49. Prog *p;
  50. p = va_arg(fp->args, Prog*);
  51. if(p->as == ADATA)
  52. sprint(str, " %A %D/%d,%D",
  53. p->as, &p->from, p->from.scale, &p->to);
  54. else if(p->as == ATEXT)
  55. sprint(str, " %A %D,%d,%D",
  56. p->as, &p->from, p->from.scale, &p->to);
  57. else
  58. sprint(str, " %A %D,%D",
  59. p->as, &p->from, &p->to);
  60. return fmtstrcpy(fp, str);
  61. }
  62. int
  63. Aconv(Fmt *fp)
  64. {
  65. int i;
  66. i = va_arg(fp->args, int);
  67. return fmtstrcpy(fp, anames[i]);
  68. }
  69. int
  70. Dconv(Fmt *fp)
  71. {
  72. char str[40], s[20];
  73. Adr *a;
  74. int i;
  75. a = va_arg(fp->args, Adr*);
  76. i = a->type;
  77. if(i >= D_INDIR) {
  78. if(a->offset)
  79. sprint(str, "%lld(%R)", a->offset, i-D_INDIR);
  80. else
  81. sprint(str, "(%R)", i-D_INDIR);
  82. goto brk;
  83. }
  84. switch(i) {
  85. default:
  86. if(a->offset)
  87. sprint(str, "$%lld,%R", a->offset, i);
  88. else
  89. sprint(str, "%R", i);
  90. break;
  91. case D_NONE:
  92. str[0] = 0;
  93. break;
  94. case D_BRANCH:
  95. sprint(str, "%lld(PC)", a->offset-pc);
  96. break;
  97. case D_EXTERN:
  98. sprint(str, "%s+%lld(SB)", a->sym->name, a->offset);
  99. break;
  100. case D_STATIC:
  101. sprint(str, "%s<>+%lld(SB)", a->sym->name,
  102. a->offset);
  103. break;
  104. case D_AUTO:
  105. sprint(str, "%s+%lld(SP)", a->sym->name, a->offset);
  106. break;
  107. case D_PARAM:
  108. if(a->sym)
  109. sprint(str, "%s+%lld(FP)", a->sym->name, a->offset);
  110. else
  111. sprint(str, "%lld(FP)", a->offset);
  112. break;
  113. case D_CONST:
  114. sprint(str, "$%lld", a->offset);
  115. break;
  116. case D_FCONST:
  117. sprint(str, "$(%.17e)", a->dval);
  118. break;
  119. case D_SCONST:
  120. sprint(str, "$\"%S\"", a->sval);
  121. break;
  122. case D_ADDR:
  123. a->type = a->index;
  124. a->index = D_NONE;
  125. sprint(str, "$%D", a);
  126. a->index = a->type;
  127. a->type = D_ADDR;
  128. goto conv;
  129. }
  130. brk:
  131. if(a->index != D_NONE) {
  132. sprint(s, "(%R*%d)", (int)a->index, (int)a->scale);
  133. strcat(str, s);
  134. }
  135. conv:
  136. return fmtstrcpy(fp, str);
  137. }
  138. char* regstr[] =
  139. {
  140. "AL", /* [D_AL] */
  141. "CL",
  142. "DL",
  143. "BL",
  144. "SPB",
  145. "BPB",
  146. "SIB",
  147. "DIB",
  148. "R8B",
  149. "R9B",
  150. "R10B",
  151. "R11B",
  152. "R12B",
  153. "R13B",
  154. "R14B",
  155. "R15B",
  156. "AX", /* [D_AX] */
  157. "CX",
  158. "DX",
  159. "BX",
  160. "SP",
  161. "BP",
  162. "SI",
  163. "DI",
  164. "R8",
  165. "R9",
  166. "R10",
  167. "R11",
  168. "R12",
  169. "R13",
  170. "R14",
  171. "R15",
  172. "AH",
  173. "CH",
  174. "DH",
  175. "BH",
  176. "F0", /* [D_F0] */
  177. "F1",
  178. "F2",
  179. "F3",
  180. "F4",
  181. "F5",
  182. "F6",
  183. "F7",
  184. "M0",
  185. "M1",
  186. "M2",
  187. "M3",
  188. "M4",
  189. "M5",
  190. "M6",
  191. "M7",
  192. "X0",
  193. "X1",
  194. "X2",
  195. "X3",
  196. "X4",
  197. "X5",
  198. "X6",
  199. "X7",
  200. "X8",
  201. "X9",
  202. "X10",
  203. "X11",
  204. "X12",
  205. "X13",
  206. "X14",
  207. "X15",
  208. "CS", /* [D_CS] */
  209. "SS",
  210. "DS",
  211. "ES",
  212. "FS",
  213. "GS",
  214. "GDTR", /* [D_GDTR] */
  215. "IDTR", /* [D_IDTR] */
  216. "LDTR", /* [D_LDTR] */
  217. "MSW", /* [D_MSW] */
  218. "TASK", /* [D_TASK] */
  219. "CR0", /* [D_CR] */
  220. "CR1",
  221. "CR2",
  222. "CR3",
  223. "CR4",
  224. "CR5",
  225. "CR6",
  226. "CR7",
  227. "CR8",
  228. "CR9",
  229. "CR10",
  230. "CR11",
  231. "CR12",
  232. "CR13",
  233. "CR14",
  234. "CR15",
  235. "DR0", /* [D_DR] */
  236. "DR1",
  237. "DR2",
  238. "DR3",
  239. "DR4",
  240. "DR5",
  241. "DR6",
  242. "DR7",
  243. "TR0", /* [D_TR] */
  244. "TR1",
  245. "TR2",
  246. "TR3",
  247. "TR4",
  248. "TR5",
  249. "TR6",
  250. "TR7",
  251. "NONE", /* [D_NONE] */
  252. };
  253. int
  254. Rconv(Fmt *fp)
  255. {
  256. char str[20];
  257. int r;
  258. r = va_arg(fp->args, int);
  259. if(r >= D_AL && r <= D_NONE)
  260. sprint(str, "%s", regstr[r-D_AL]);
  261. else
  262. sprint(str, "gok(%d)", r);
  263. return fmtstrcpy(fp, str);
  264. }
  265. int
  266. Sconv(Fmt *fp)
  267. {
  268. int i, c;
  269. char str[30], *p, *a;
  270. a = va_arg(fp->args, char*);
  271. p = str;
  272. for(i=0; i<sizeof(double); i++) {
  273. c = a[i] & 0xff;
  274. if(c >= 'a' && c <= 'z' ||
  275. c >= 'A' && c <= 'Z' ||
  276. c >= '0' && c <= '9') {
  277. *p++ = c;
  278. continue;
  279. }
  280. *p++ = '\\';
  281. switch(c) {
  282. default:
  283. if(c < 040 || c >= 0177)
  284. break; /* not portable */
  285. p[-1] = c;
  286. continue;
  287. case 0:
  288. *p++ = 'z';
  289. continue;
  290. case '\\':
  291. case '"':
  292. *p++ = c;
  293. continue;
  294. case '\n':
  295. *p++ = 'n';
  296. continue;
  297. case '\t':
  298. *p++ = 't';
  299. continue;
  300. }
  301. *p++ = (c>>6) + '0';
  302. *p++ = ((c>>3) & 7) + '0';
  303. *p++ = (c & 7) + '0';
  304. }
  305. *p = 0;
  306. return fmtstrcpy(fp, str);
  307. }