executable.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <bio.h>
  4. #include <bootexec.h>
  5. #include <mach.h>
  6. #include "elf.h"
  7. /*
  8. * All a.out header types. The dummy entry allows canonical
  9. * processing of the union as a sequence of longs
  10. */
  11. typedef struct {
  12. union{
  13. Exec; /* in a.out.h */
  14. Ehdr; /* in elf.h */
  15. struct mipsexec;
  16. struct mips4kexec;
  17. struct sparcexec;
  18. struct nextexec;
  19. struct i960exec;
  20. } e;
  21. long dummy; /* padding to ensure extra long */
  22. } ExecHdr;
  23. static int i960boot(int, Fhdr*, ExecHdr*);
  24. static int nextboot(int, Fhdr*, ExecHdr*);
  25. static int sparcboot(int, Fhdr*, ExecHdr*);
  26. static int mipsboot(int, Fhdr*, ExecHdr*);
  27. static int mips4kboot(int, Fhdr*, ExecHdr*);
  28. static int common(int, Fhdr*, ExecHdr*);
  29. static int adotout(int, Fhdr*, ExecHdr*);
  30. static int elfdotout(int, Fhdr*, ExecHdr*);
  31. static int armdotout(int, Fhdr*, ExecHdr*);
  32. static int alphadotout(int, Fhdr*, ExecHdr*);
  33. static void setsym(Fhdr*, long, long, long, long);
  34. static void setdata(Fhdr*, long, long, long, long);
  35. static void settext(Fhdr*, long, long, long, long);
  36. static void hswal(long*, int, long(*)(long));
  37. static long _round(long, long);
  38. /*
  39. * definition of per-executable file type structures
  40. */
  41. typedef struct Exectable{
  42. long magic; /* big-endian magic number of file */
  43. char *name; /* executable identifier */
  44. int type; /* Internal code */
  45. Mach *mach; /* Per-machine data */
  46. ulong hsize; /* header size */
  47. long (*swal)(long); /* beswal or leswal */
  48. int (*hparse)(int, Fhdr*, ExecHdr*);
  49. } ExecTable;
  50. extern Mach mmips;
  51. extern Mach mmips2le;
  52. extern Mach mmips2be;
  53. extern Mach msparc;
  54. extern Mach m68020;
  55. extern Mach mi386;
  56. extern Mach mi960;
  57. extern Mach m3210;
  58. extern Mach m29000;
  59. extern Mach marm;
  60. extern Mach mpower;
  61. extern Mach malpha;
  62. ExecTable exectab[] =
  63. {
  64. { V_MAGIC, /* Mips v.out */
  65. "mips plan 9 executable",
  66. FMIPS,
  67. &mmips,
  68. sizeof(Exec),
  69. beswal,
  70. adotout },
  71. { M_MAGIC, /* Mips 4.out */
  72. "mips 4k plan 9 executable BE",
  73. FMIPS2BE,
  74. &mmips2be,
  75. sizeof(Exec),
  76. beswal,
  77. adotout },
  78. { N_MAGIC, /* Mips 0.out */
  79. "mips 4k plan 9 executable LE",
  80. FMIPS2LE,
  81. &mmips2le,
  82. sizeof(Exec),
  83. beswal,
  84. adotout },
  85. { 0x160<<16, /* Mips boot image */
  86. "mips plan 9 boot image",
  87. FMIPSB,
  88. &mmips,
  89. sizeof(struct mipsexec),
  90. beswal,
  91. mipsboot },
  92. { (0x160<<16)|3, /* Mips boot image */
  93. "mips 4k plan 9 boot image",
  94. FMIPSB,
  95. &mmips2be,
  96. sizeof(struct mips4kexec),
  97. beswal,
  98. mips4kboot },
  99. { K_MAGIC, /* Sparc k.out */
  100. "sparc plan 9 executable",
  101. FSPARC,
  102. &msparc,
  103. sizeof(Exec),
  104. beswal,
  105. adotout },
  106. { 0x01030107, /* Sparc boot image */
  107. "sparc plan 9 boot image",
  108. FSPARCB,
  109. &msparc,
  110. sizeof(struct sparcexec),
  111. beswal,
  112. sparcboot },
  113. { A_MAGIC, /* 68020 2.out & boot image */
  114. "68020 plan 9 executable",
  115. F68020,
  116. &m68020,
  117. sizeof(Exec),
  118. beswal,
  119. common },
  120. { 0xFEEDFACE, /* Next boot image */
  121. "next plan 9 boot image",
  122. FNEXTB,
  123. &m68020,
  124. sizeof(struct nextexec),
  125. beswal,
  126. nextboot },
  127. { I_MAGIC, /* I386 8.out & boot image */
  128. "386 plan 9 executable",
  129. FI386,
  130. &mi386,
  131. sizeof(Exec),
  132. beswal,
  133. common },
  134. { I_MAGIC|DYN_MAGIC, /* I386 dynamic load module */
  135. "386 plan 9 dynamically loaded module",
  136. FI386,
  137. &mi386,
  138. sizeof(Exec),
  139. beswal,
  140. common },
  141. { J_MAGIC, /* I960 6.out (big-endian) */
  142. "960 plan 9 executable",
  143. FI960,
  144. &mi960,
  145. sizeof(Exec),
  146. beswal,
  147. adotout },
  148. { 0x61010200, /* I960 boot image (little endian) */
  149. "960 plan 9 boot image",
  150. FI960B,
  151. &mi960,
  152. sizeof(struct i960exec),
  153. leswal,
  154. i960boot },
  155. { X_MAGIC, /* 3210 x.out */
  156. "3210 plan 9 executable",
  157. F3210,
  158. &m3210,
  159. sizeof(Exec),
  160. beswal,
  161. adotout },
  162. { D_MAGIC, /* 29000 9.out */
  163. "29000 plan 9 executable",
  164. F29000,
  165. &m29000,
  166. sizeof(Exec),
  167. beswal,
  168. adotout },
  169. { Q_MAGIC, /* PowerPC q.out & boot image */
  170. "power plan 9 executable",
  171. FPOWER,
  172. &mpower,
  173. sizeof(Exec),
  174. beswal,
  175. common },
  176. { ELF_MAG,
  177. "Irix 5.X Elf executable",
  178. FMIPS,
  179. &mmips,
  180. sizeof(Ehdr),
  181. beswal,
  182. elfdotout },
  183. { E_MAGIC, /* Arm 5.out */
  184. "Arm plan 9 executable",
  185. FARM,
  186. &marm,
  187. sizeof(Exec),
  188. beswal,
  189. common },
  190. { (143<<16)|0413, /* (Free|Net)BSD Arm */
  191. "Arm *BSD executable",
  192. FARM,
  193. &marm,
  194. sizeof(Exec),
  195. leswal,
  196. armdotout },
  197. { L_MAGIC, /* alpha 7.out */
  198. "alpha plan 9 executable",
  199. FALPHA,
  200. &malpha,
  201. sizeof(Exec),
  202. beswal,
  203. common },
  204. { 0x0700e0c3, /* alpha boot image */
  205. "alpha plan 9 boot image",
  206. FALPHAB,
  207. &malpha,
  208. sizeof(Exec),
  209. beswal,
  210. alphadotout },
  211. { 0 },
  212. };
  213. Mach *mach = &mi386; /* Global current machine table */
  214. static ExecTable*
  215. couldbe4k(ExecTable *mp)
  216. {
  217. Dir *d;
  218. ExecTable *f;
  219. if((d=dirstat("/proc/1/regs")) == nil)
  220. return mp;
  221. if(d->length < 32*8){ /* R3000 */
  222. free(d);
  223. return mp;
  224. }
  225. free(d);
  226. for (f = exectab; f->magic; f++)
  227. if(f->magic == M_MAGIC) {
  228. f->name = "mips plan 9 executable on mips2 kernel";
  229. return f;
  230. }
  231. return mp;
  232. }
  233. int
  234. crackhdr(int fd, Fhdr *fp)
  235. {
  236. ExecTable *mp;
  237. ExecHdr d;
  238. int nb, magic, ret;
  239. fp->type = FNONE;
  240. nb = read(fd, (char *)&d.e, sizeof(d.e));
  241. if (nb <= 0)
  242. return 0;
  243. ret = 0;
  244. fp->magic = magic = beswal(d.e.magic); /* big-endian */
  245. for (mp = exectab; mp->magic; mp++) {
  246. if (mp->magic == magic && nb >= mp->hsize) {
  247. if(mp->magic == V_MAGIC)
  248. mp = couldbe4k(mp);
  249. hswal((long *) &d, sizeof(d.e)/sizeof(long), mp->swal);
  250. fp->type = mp->type;
  251. fp->name = mp->name;
  252. fp->hdrsz = mp->hsize; /* zero on bootables */
  253. mach = mp->mach;
  254. ret = mp->hparse(fd, fp, &d);
  255. seek(fd, mp->hsize, 0); /* seek to end of header */
  256. break;
  257. }
  258. }
  259. if(mp->magic == 0)
  260. werrstr("unknown header type");
  261. return ret;
  262. }
  263. /*
  264. * Convert header to canonical form
  265. */
  266. static void
  267. hswal(long *lp, int n, long (*swap) (long))
  268. {
  269. while (n--) {
  270. *lp = (*swap) (*lp);
  271. lp++;
  272. }
  273. }
  274. /*
  275. * Crack a normal a.out-type header
  276. */
  277. static int
  278. adotout(int fd, Fhdr *fp, ExecHdr *hp)
  279. {
  280. long pgsize;
  281. USED(fd);
  282. pgsize = mach->pgsize;
  283. settext(fp, hp->e.entry, pgsize+sizeof(Exec),
  284. hp->e.text, sizeof(Exec));
  285. setdata(fp, _round(pgsize+fp->txtsz+sizeof(Exec), pgsize),
  286. hp->e.data, fp->txtsz+sizeof(Exec), hp->e.bss);
  287. setsym(fp, hp->e.syms, hp->e.spsz, hp->e.pcsz, fp->datoff+fp->datsz);
  288. return 1;
  289. }
  290. /*
  291. * 68020 2.out and 68020 bootable images
  292. * 386I 8.out and 386I bootable images
  293. * alpha plan9-style bootable images for axp "headerless" boot
  294. *
  295. */
  296. static int
  297. common(int fd, Fhdr *fp, ExecHdr *hp)
  298. {
  299. long kbase;
  300. adotout(fd, fp, hp);
  301. if(hp->e.magic & DYN_MAGIC) {
  302. fp->txtaddr = 0;
  303. fp->dataddr = fp->txtsz;
  304. return 1;
  305. }
  306. kbase = mach->kbase;
  307. if ((fp->entry & kbase) == kbase) { /* Boot image */
  308. switch(fp->type) {
  309. case F68020:
  310. fp->type = F68020B;
  311. fp->name = "68020 plan 9 boot image";
  312. fp->hdrsz = 0; /* header stripped */
  313. break;
  314. case FI386:
  315. fp->type = FI386B;
  316. fp->txtaddr = sizeof(Exec);
  317. fp->name = "386 plan 9 boot image";
  318. fp->hdrsz = 0; /* header stripped */
  319. fp->dataddr = fp->txtaddr+fp->txtsz;
  320. break;
  321. case FARM:
  322. fp->txtaddr = kbase+0x8010;
  323. fp->name = "ARM plan 9 boot image";
  324. fp->hdrsz = 0; /* header stripped */
  325. fp->dataddr = fp->txtaddr+fp->txtsz;
  326. return 1;
  327. case FALPHA:
  328. fp->type = FALPHAB;
  329. fp->txtaddr = fp->entry;
  330. fp->name = "alpha plan 9 boot image?";
  331. fp->hdrsz = 0; /* header stripped */
  332. fp->dataddr = fp->txtaddr+fp->txtsz;
  333. break;
  334. case FPOWER:
  335. fp->type = FPOWERB;
  336. fp->txtaddr = fp->entry;
  337. fp->name = "power plan 9 boot image";
  338. fp->hdrsz = 0; /* header stripped */
  339. fp->dataddr = fp->txtaddr+fp->txtsz;
  340. break;
  341. default:
  342. break;
  343. }
  344. fp->txtaddr |= kbase;
  345. fp->entry |= kbase;
  346. fp->dataddr |= kbase;
  347. }
  348. return 1;
  349. }
  350. /*
  351. * mips bootable image.
  352. */
  353. static int
  354. mipsboot(int fd, Fhdr *fp, ExecHdr *hp)
  355. {
  356. USED(fd);
  357. switch(hp->e.amagic) {
  358. default:
  359. case 0407: /* some kind of mips */
  360. fp->type = FMIPSB;
  361. settext(fp, hp->e.mentry, hp->e.text_start, hp->e.tsize,
  362. sizeof(struct mipsexec)+4);
  363. setdata(fp, hp->e.data_start, hp->e.dsize,
  364. fp->txtoff+hp->e.tsize, hp->e.bsize);
  365. break;
  366. case 0413: /* some kind of mips */
  367. fp->type = FMIPSB;
  368. settext(fp, hp->e.mentry, hp->e.text_start, hp->e.tsize, 0);
  369. setdata(fp, hp->e.data_start, hp->e.dsize, hp->e.tsize,
  370. hp->e.bsize);
  371. break;
  372. }
  373. setsym(fp, hp->e.nsyms, 0, hp->e.pcsize, hp->e.symptr);
  374. fp->hdrsz = 0; /* header stripped */
  375. return 1;
  376. }
  377. /*
  378. * mips4k bootable image.
  379. */
  380. static int
  381. mips4kboot(int fd, Fhdr *fp, ExecHdr *hp)
  382. {
  383. USED(fd);
  384. switch(hp->e.h.amagic) {
  385. default:
  386. case 0407: /* some kind of mips */
  387. fp->type = FMIPSB;
  388. settext(fp, hp->e.h.mentry, hp->e.h.text_start, hp->e.h.tsize,
  389. sizeof(struct mips4kexec));
  390. setdata(fp, hp->e.h.data_start, hp->e.h.dsize,
  391. fp->txtoff+hp->e.h.tsize, hp->e.h.bsize);
  392. break;
  393. case 0413: /* some kind of mips */
  394. fp->type = FMIPSB;
  395. settext(fp, hp->e.h.mentry, hp->e.h.text_start, hp->e.h.tsize, 0);
  396. setdata(fp, hp->e.h.data_start, hp->e.h.dsize, hp->e.h.tsize,
  397. hp->e.h.bsize);
  398. break;
  399. }
  400. setsym(fp, hp->e.h.nsyms, 0, hp->e.h.pcsize, hp->e.h.symptr);
  401. fp->hdrsz = 0; /* header stripped */
  402. return 1;
  403. }
  404. /*
  405. * sparc bootable image
  406. */
  407. static int
  408. sparcboot(int fd, Fhdr *fp, ExecHdr *hp)
  409. {
  410. USED(fd);
  411. fp->type = FSPARCB;
  412. settext(fp, hp->e.sentry, hp->e.sentry, hp->e.stext,
  413. sizeof(struct sparcexec));
  414. setdata(fp, hp->e.sentry+hp->e.stext, hp->e.sdata,
  415. fp->txtoff+hp->e.stext, hp->e.sbss);
  416. setsym(fp, hp->e.ssyms, 0, hp->e.sdrsize, fp->datoff+hp->e.sdata);
  417. fp->hdrsz = 0; /* header stripped */
  418. return 1;
  419. }
  420. /*
  421. * next bootable image
  422. */
  423. static int
  424. nextboot(int fd, Fhdr *fp, ExecHdr *hp)
  425. {
  426. USED(fd);
  427. fp->type = FNEXTB;
  428. settext(fp, hp->e.textc.vmaddr, hp->e.textc.vmaddr,
  429. hp->e.texts.size, hp->e.texts.offset);
  430. setdata(fp, hp->e.datac.vmaddr, hp->e.datas.size,
  431. hp->e.datas.offset, hp->e.bsss.size);
  432. setsym(fp, hp->e.symc.nsyms, hp->e.symc.spoff, hp->e.symc.pcoff,
  433. hp->e.symc.symoff);
  434. fp->hdrsz = 0; /* header stripped */
  435. return 1;
  436. }
  437. /*
  438. * I960 bootable image
  439. */
  440. static int
  441. i960boot(int fd, Fhdr *fp, ExecHdr *hp)
  442. {
  443. /* long n = hp->e.i6comments.fptrlineno-hp->e.i6comments.fptrreloc; */
  444. USED(fd);
  445. settext(fp, hp->e.i6entry, hp->e.i6texts.virt, hp->e.i6texts.size,
  446. hp->e.i6texts.fptr);
  447. setdata(fp, hp->e.i6datas.virt, hp->e.i6datas.size,
  448. hp->e.i6datas.fptr, hp->e.i6bsssize);
  449. setsym(fp, 0, 0, 0, 0);
  450. /*setsym(fp, n, 0, hp->e.i6comments.size-n, hp->e.i6comments.fptr); */
  451. fp->hdrsz = 0; /* header stripped */
  452. return 1;
  453. }
  454. static Shdr*
  455. elfsectbyname(int fd, Ehdr *hp, Shdr *sp, char *name)
  456. {
  457. int i, offset, n;
  458. char s[64];
  459. offset = sp[hp->shstrndx].offset;
  460. for(i = 1; i < hp->shnum; i++) {
  461. seek(fd, offset+sp[i].name, 0);
  462. n = read(fd, s, sizeof(s)-1);
  463. if(n < 0)
  464. continue;
  465. s[n] = 0;
  466. if(strcmp(s, name) == 0)
  467. return &sp[i];
  468. }
  469. return 0;
  470. }
  471. /*
  472. * Decode an Irix 5.x ELF header
  473. */
  474. static int
  475. elfdotout(int fd, Fhdr *fp, ExecHdr *hp)
  476. {
  477. Ehdr *ep;
  478. Shdr *es, *txt, *init, *s;
  479. long addr, size, offset, bsize;
  480. ep = &hp->e;
  481. if(ep->type != 8 || ep->machine != 2 || ep->version != 1)
  482. return 0;
  483. fp->magic = ELF_MAG;
  484. fp->hdrsz = (ep->ehsize+ep->phnum*ep->phentsize+16)&~15;
  485. if(ep->shnum <= 0) {
  486. werrstr("no ELF header sections");
  487. return 0;
  488. }
  489. es = malloc(sizeof(Shdr)*ep->shnum);
  490. if(es == 0)
  491. return 0;
  492. seek(fd, ep->shoff, 0);
  493. if(read(fd, es, sizeof(Shdr)*ep->shnum) < 0){
  494. free(es);
  495. return 0;
  496. }
  497. txt = elfsectbyname(fd, ep, es, ".text");
  498. init = elfsectbyname(fd, ep, es, ".init");
  499. if(txt == 0 || init == 0 || init != txt+1)
  500. goto bad;
  501. if(txt->addr+txt->size != init->addr)
  502. goto bad;
  503. settext(fp, ep->elfentry, txt->addr, txt->size+init->size, txt->offset);
  504. addr = 0;
  505. offset = 0;
  506. size = 0;
  507. s = elfsectbyname(fd, ep, es, ".data");
  508. if(s) {
  509. addr = s->addr;
  510. size = s->size;
  511. offset = s->offset;
  512. }
  513. s = elfsectbyname(fd, ep, es, ".rodata");
  514. if(s) {
  515. if(addr){
  516. if(addr+size != s->addr)
  517. goto bad;
  518. } else {
  519. addr = s->addr;
  520. offset = s->offset;
  521. }
  522. size += s->size;
  523. }
  524. s = elfsectbyname(fd, ep, es, ".got");
  525. if(s) {
  526. if(addr){
  527. if(addr+size != s->addr)
  528. goto bad;
  529. } else {
  530. addr = s->addr;
  531. offset = s->offset;
  532. }
  533. size += s->size;
  534. }
  535. bsize = 0;
  536. s = elfsectbyname(fd, ep, es, ".bss");
  537. if(s) {
  538. if(addr){
  539. if(addr+size != s->addr)
  540. goto bad;
  541. } else {
  542. addr = s->addr;
  543. offset = s->offset;
  544. }
  545. bsize = s->size;
  546. }
  547. if(addr == 0)
  548. goto bad;
  549. setdata(fp, addr, size, offset, bsize);
  550. fp->name = "IRIX Elf a.out executable";
  551. free(es);
  552. return 1;
  553. bad:
  554. free(es);
  555. werrstr("ELF sections scrambled");
  556. return 0;
  557. }
  558. /*
  559. * alpha bootable
  560. */
  561. static int
  562. alphadotout(int fd, Fhdr *fp, ExecHdr *hp)
  563. {
  564. long kbase;
  565. USED(fd);
  566. settext(fp, hp->e.entry, sizeof(Exec), hp->e.text, sizeof(Exec));
  567. setdata(fp, fp->txtsz+sizeof(Exec), hp->e.data, fp->txtsz+sizeof(Exec), hp->e.bss);
  568. setsym(fp, hp->e.syms, hp->e.spsz, hp->e.pcsz, fp->datoff+fp->datsz);
  569. /*
  570. * Boot images have some of bits <31:28> set:
  571. * 0x80400000 kernel
  572. * 0x20000000 secondary bootstrap
  573. */
  574. kbase = 0xF0000000;
  575. if (fp->entry & kbase) {
  576. fp->txtaddr = fp->entry;
  577. fp->name = "alpha plan 9 boot image";
  578. fp->hdrsz = 0; /* header stripped */
  579. fp->dataddr = fp->entry+fp->txtsz;
  580. }
  581. return 1;
  582. }
  583. /*
  584. * (Free|Net)BSD ARM header.
  585. */
  586. static int
  587. armdotout(int fd, Fhdr *fp, ExecHdr *hp)
  588. {
  589. long kbase;
  590. USED(fd);
  591. settext(fp, hp->e.entry, sizeof(Exec), hp->e.text, sizeof(Exec));
  592. setdata(fp, fp->txtsz, hp->e.data, fp->txtsz, hp->e.bss);
  593. setsym(fp, hp->e.syms, hp->e.spsz, hp->e.pcsz, fp->datoff+fp->datsz);
  594. kbase = 0xF0000000;
  595. if ((fp->entry & kbase) == kbase) { /* Boot image */
  596. fp->txtaddr = kbase+sizeof(Exec);
  597. fp->name = "ARM *BSD boot image";
  598. fp->hdrsz = 0; /* header stripped */
  599. fp->dataddr = kbase+fp->txtsz;
  600. }
  601. return 1;
  602. }
  603. static void
  604. settext(Fhdr *fp, long e, long a, long s, long off)
  605. {
  606. fp->txtaddr = a;
  607. fp->entry = e;
  608. fp->txtsz = s;
  609. fp->txtoff = off;
  610. }
  611. static void
  612. setdata(Fhdr *fp, long a, long s, long off, long bss)
  613. {
  614. fp->dataddr = a;
  615. fp->datsz = s;
  616. fp->datoff = off;
  617. fp->bsssz = bss;
  618. }
  619. static void
  620. setsym(Fhdr *fp, long sy, long sppc, long lnpc, long symoff)
  621. {
  622. fp->symsz = sy;
  623. fp->symoff = symoff;
  624. fp->sppcsz = sppc;
  625. fp->sppcoff = fp->symoff+fp->symsz;
  626. fp->lnpcsz = lnpc;
  627. fp->lnpcoff = fp->sppcoff+fp->sppcsz;
  628. }
  629. static long
  630. _round(long a, long b)
  631. {
  632. long w;
  633. w = (a/b)*b;
  634. if (a!=w)
  635. w += b;
  636. return(w);
  637. }