Browse Source

Cleaning cmd (#760)

Signed-off-by: Álvaro Jurado <elbingmiss@gmail.com>
Álvaro Jurado 6 years ago
parent
commit
9e548971d0
100 changed files with 0 additions and 55884 deletions
  1. BIN
      amd64/bin/syslinuxmbr.bin
  2. 0 188
      sys/src/cmd/5a/a.h
  3. 0 673
      sys/src/cmd/5a/a.y
  4. 0 38
      sys/src/cmd/5a/l.s
  5. 0 706
      sys/src/cmd/5a/lex.c
  6. 0 19
      sys/src/cmd/5a/mkfile
  7. 0 222
      sys/src/cmd/5c/5.out.h
  8. 0 1177
      sys/src/cmd/5c/cgen.c
  9. 0 113
      sys/src/cmd/5c/enam.c
  10. 0 361
      sys/src/cmd/5c/gc.h
  11. 0 313
      sys/src/cmd/5c/list.c
  12. 0 15
      sys/src/cmd/5c/mkenam
  13. 0 41
      sys/src/cmd/5c/mkfile
  14. 0 618
      sys/src/cmd/5c/mul.c
  15. 0 1448
      sys/src/cmd/5c/peep.c
  16. 0 1167
      sys/src/cmd/5c/reg.c
  17. 0 228
      sys/src/cmd/5c/sgen.c
  18. 0 628
      sys/src/cmd/5c/swt.c
  19. 0 1322
      sys/src/cmd/5c/txt.c
  20. 0 288
      sys/src/cmd/5i/5i.c
  21. 0 249
      sys/src/cmd/5i/arm.h
  22. 0 137
      sys/src/cmd/5i/bpt.c
  23. 0 649
      sys/src/cmd/5i/cmd.c
  24. 0 212
      sys/src/cmd/5i/float.c
  25. 0 26
      sys/src/cmd/5i/icache.c
  26. 0 294
      sys/src/cmd/5i/mem.c
  27. 0 26
      sys/src/cmd/5i/mkfile
  28. 0 957
      sys/src/cmd/5i/run.c
  29. 0 208
      sys/src/cmd/5i/stats.c
  30. 0 104
      sys/src/cmd/5i/symbols.c
  31. 0 816
      sys/src/cmd/5i/syscall.c
  32. 0 1815
      sys/src/cmd/5l/asm.c
  33. 0 74
      sys/src/cmd/5l/compat.c
  34. 0 420
      sys/src/cmd/5l/l.h
  35. 0 31
      sys/src/cmd/5l/l.s
  36. 0 361
      sys/src/cmd/5l/list.c
  37. 0 34
      sys/src/cmd/5l/mkfile
  38. 0 540
      sys/src/cmd/5l/noop.c
  39. 0 1654
      sys/src/cmd/5l/obj.c
  40. 0 266
      sys/src/cmd/5l/optab.c
  41. 0 604
      sys/src/cmd/5l/pass.c
  42. 0 996
      sys/src/cmd/5l/span.c
  43. 0 204
      sys/src/cmd/6a/a.h
  44. 0 562
      sys/src/cmd/6a/a.y
  45. 0 1298
      sys/src/cmd/6a/lex.c
  46. 0 26
      sys/src/cmd/6a/mkfile
  47. 0 829
      sys/src/cmd/6c/6.out.h
  48. 0 1972
      sys/src/cmd/6c/cgen.c
  49. 0 215
      sys/src/cmd/6c/div.c
  50. 0 678
      sys/src/cmd/6c/enam.c
  51. 0 389
      sys/src/cmd/6c/gc.h
  52. 0 346
      sys/src/cmd/6c/list.c
  53. 0 87
      sys/src/cmd/6c/machcap.c
  54. 0 15
      sys/src/cmd/6c/mkenam
  55. 0 38
      sys/src/cmd/6c/mkfile
  56. 0 437
      sys/src/cmd/6c/mul.c
  57. 0 855
      sys/src/cmd/6c/peep.c
  58. 0 1367
      sys/src/cmd/6c/reg.c
  59. 0 444
      sys/src/cmd/6c/sgen.c
  60. 0 522
      sys/src/cmd/6c/swt.c
  61. 0 115
      sys/src/cmd/6c/sys.c
  62. 0 1531
      sys/src/cmd/6c/txt.c
  63. 0 422
      sys/src/cmd/6l/asm.c
  64. 0 73
      sys/src/cmd/6l/compat.c
  65. 0 410
      sys/src/cmd/6l/l.h
  66. 0 359
      sys/src/cmd/6l/list.c
  67. 0 35
      sys/src/cmd/6l/mkfile
  68. 0 1683
      sys/src/cmd/6l/obj.c
  69. 0 1194
      sys/src/cmd/6l/optab.c
  70. 0 799
      sys/src/cmd/6l/pass.c
  71. 0 1763
      sys/src/cmd/6l/span.c
  72. 0 204
      sys/src/cmd/8a/a.h
  73. 0 577
      sys/src/cmd/8a/a.y
  74. 0 704
      sys/src/cmd/8a/l.s
  75. 0 963
      sys/src/cmd/8a/lex.c
  76. 0 26
      sys/src/cmd/8a/mkfile
  77. 0 514
      sys/src/cmd/8c/8.out.h
  78. 0 1861
      sys/src/cmd/8c/cgen.c
  79. 0 2663
      sys/src/cmd/8c/cgen64.c
  80. 0 215
      sys/src/cmd/8c/div.c
  81. 0 393
      sys/src/cmd/8c/enam.c
  82. 0 379
      sys/src/cmd/8c/gc.h
  83. 0 292
      sys/src/cmd/8c/list.c
  84. 0 100
      sys/src/cmd/8c/machcap.c
  85. 0 15
      sys/src/cmd/8c/mkenam
  86. 0 39
      sys/src/cmd/8c/mkfile
  87. 0 437
      sys/src/cmd/8c/mul.c
  88. 0 780
      sys/src/cmd/8c/peep.c
  89. 0 1273
      sys/src/cmd/8c/reg.c
  90. 0 449
      sys/src/cmd/8c/sgen.c
  91. 0 511
      sys/src/cmd/8c/swt.c
  92. 0 1455
      sys/src/cmd/8c/txt.c
  93. 0 532
      sys/src/cmd/8l/asm.c
  94. 0 74
      sys/src/cmd/8l/compat.c
  95. 0 275
      sys/src/cmd/8l/elf.c
  96. 0 111
      sys/src/cmd/8l/elf.h
  97. 0 374
      sys/src/cmd/8l/l.h
  98. 0 301
      sys/src/cmd/8l/list.c
  99. 0 35
      sys/src/cmd/8l/mkfile
  100. 0 1626
      sys/src/cmd/8l/obj.c

BIN
amd64/bin/syslinuxmbr.bin


+ 0 - 188
sys/src/cmd/5a/a.h

@@ -1,188 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <bio.h>
-#include "../5c/5.out.h"
-
-#ifndef	EXTERN
-#define	EXTERN	extern
-#endif
-
-typedef	struct	Sym	Sym;
-typedef	struct	Gen	Gen;
-typedef	struct	Io	Io;
-typedef	struct	Hist	Hist;
-
-#define	MAXALIGN	7
-#define	FPCHIP		1
-#define	NSYMB		8192
-#define	BUFSIZ		8192
-#define	HISTSZ		20
-#define	NINCLUDE	10
-#define	NHUNK		10000
-#define	EOF		(-1)
-#define	IGN		(-2)
-#define	GETC()		((--fi.c < 0)? filbuf(): *fi.p++ & 0xff)
-#define	NHASH		503
-#define	STRINGSZ	200
-#define	NMACRO		10
-
-struct	Sym
-{
-	Sym*	link;
-	char*	macro;
-	long	value;
-	ushort	type;
-	char	*name;
-	char	sym;
-};
-#define	S	((Sym*)0)
-
-EXTERN	struct
-{
-	char*	p;
-	int	c;
-} fi;
-
-struct	Io
-{
-	Io*	link;
-	char	b[BUFSIZ];
-	char*	p;
-	short	c;
-	short	f;
-};
-#define	I	((Io*)0)
-
-EXTERN	struct
-{
-	Sym*	sym;
-	short	type;
-} h[NSYM];
-
-struct	Gen
-{
-	Sym*	sym;
-	long	offset;
-	short	type;
-	short	reg;
-	short	name;
-	double	dval;
-	char	sval[8];
-};
-
-struct	Hist
-{
-	Hist*	link;
-	char*	name;
-	long	line;
-	long	offset;
-};
-#define	H	((Hist*)0)
-
-enum
-{
-	CLAST,
-	CMACARG,
-	CMACRO,
-	CPREPROC,
-
-	Always	= 14,
-};
-
-EXTERN	char	debug[256];
-EXTERN	Sym*	hash[NHASH];
-EXTERN	char*	Dlist[30];
-EXTERN	int	nDlist;
-EXTERN	Hist*	ehist;
-EXTERN	int	newflag;
-EXTERN	Hist*	hist;
-EXTERN	char*	hunk;
-EXTERN	char*	include[NINCLUDE];
-EXTERN	Io*	iofree;
-EXTERN	Io*	ionext;
-EXTERN	Io*	iostack;
-EXTERN	long	lineno;
-EXTERN	int	nerrors;
-EXTERN	long	nhunk;
-EXTERN	int	ninclude;
-EXTERN	Gen	nullgen;
-EXTERN	char*	outfile;
-EXTERN	int	pass;
-EXTERN	char*	pathname;
-EXTERN	long	pc;
-EXTERN	int	peekc;
-EXTERN	int	sym;
-EXTERN	char	symb[NSYMB];
-EXTERN	int	thechar;
-EXTERN	char*	thestring;
-EXTERN	long	thunk;
-EXTERN	Biobuf	obuf;
-
-void*	alloc(long);
-void*	allocn(void*, long, long);
-void	errorexit(void);
-void	pushio(void);
-void	newio(void);
-void	newfile(char*, int);
-Sym*	slookup(char*);
-Sym*	lookup(void);
-void	syminit(Sym*);
-long	yylex(void);
-int	getc(void);
-int	getnsc(void);
-void	unget(int);
-int	escchar(int);
-void	cinit(void);
-void	pinit(char*);
-void	cclean(void);
-int	isreg(Gen*);
-void	outcode(int, int, Gen*, int, Gen*);
-void	zname(char*, int, int);
-void	zaddr(Gen*, int);
-void	ieeedtod(Ieee*, double);
-int	filbuf(void);
-Sym*	getsym(void);
-void	domacro(void);
-void	macund(void);
-void	macdef(void);
-void	macexpand(Sym*, char*);
-void	macinc(void);
-void	maclin(void);
-void	macprag(void);
-void	macif(int);
-void	macend(void);
-void	outhist(void);
-void	dodefine(char*);
-void	prfile(long);
-void	linehist(char*, int);
-void	gethunk(void);
-void	yyerror(char*, ...);
-int	yyparse(void);
-void	setinclude(char*);
-int	assemble(char*);
-
-/*
- *	system-dependent stuff from ../cc/compat.c
- */
-
-enum				/* keep in synch with ../cc/cc.h */
-{
-	Plan9	= 1<<0,
-	Unix	= 1<<1,
-	Windows	= 1<<2,
-};
-int	mywait(int*);
-int	mycreat(char*, int);
-int	systemtype(int);
-int	pathchar(void);
-int	myfork(void);
-void*	mysbrk(ulong);

+ 0 - 673
sys/src/cmd/5a/a.y

@@ -1,673 +0,0 @@
-%{
-#include "a.h"
-%}
-%union
-{
-	Sym	*sym;
-	long	lval;
-	double	dval;
-	char	sval[8];
-	Gen	gen;
-}
-%left	'|'
-%left	'^'
-%left	'&'
-%left	'<' '>'
-%left	'+' '-'
-%left	'*' '/' '%'
-%token	<lval>	LTYPE1 LTYPE2 LTYPE3 LTYPE4 LTYPE5
-%token	<lval>	LTYPE6 LTYPE7 LTYPE8 LTYPE9 LTYPEA
-%token	<lval>	LTYPEB LTYPEC LTYPED LTYPEE LTYPEF
-%token	<lval>	LTYPEG LTYPEH LTYPEI LTYPEJ LTYPEK
-%token	<lval>	LTYPEL LTYPEM LTYPEN LTYPEBX
-%token	<lval>	LCONST LSP LSB LFP LPC
-%token	<lval>	LTYPEX LR LREG LF LFREG LC LCREG LPSR LFCR
-%token	<lval>	LCOND LS LAT
-%token	<dval>	LFCONST
-%token	<sval>	LSCONST
-%token	<sym>	LNAME LLAB LVAR
-%type	<lval>	con expr oexpr pointer offset sreg spreg creg
-%type	<lval>	rcon cond reglist
-%type	<gen>	gen rel reg regreg freg shift fcon frcon
-%type	<gen>	imm ximm name oreg ireg nireg ioreg imsr
-%%
-prog:
-|	prog line
-
-line:
-	LLAB ':'
-	{
-		if($1->value != pc)
-			yyerror("redeclaration of %s", $1->name);
-		$1->value = pc;
-	}
-	line
-|	LNAME ':'
-	{
-		$1->type = LLAB;
-		$1->value = pc;
-	}
-	line
-|	LNAME '=' expr ';'
-	{
-		$1->type = LVAR;
-		$1->value = $3;
-	}
-|	LVAR '=' expr ';'
-	{
-		if($1->value != $3)
-			yyerror("redeclaration of %s", $1->name);
-		$1->value = $3;
-	}
-|	';'
-|	inst ';'
-|	error ';'
-
-inst:
-/*
- * ADD
- */
-	LTYPE1 cond imsr ',' spreg ',' reg
-	{
-		outcode($1, $2, &$3, $5, &$7);
-	}
-|	LTYPE1 cond imsr ',' spreg ','
-	{
-		outcode($1, $2, &$3, $5, &nullgen);
-	}
-|	LTYPE1 cond imsr ',' reg
-	{
-		outcode($1, $2, &$3, NREG, &$5);
-	}
-/*
- * MVN
- */
-|	LTYPE2 cond imsr ',' reg
-	{
-		outcode($1, $2, &$3, NREG, &$5);
-	}
-/*
- * MOVW
- */
-|	LTYPE3 cond gen ',' gen
-	{
-		outcode($1, $2, &$3, NREG, &$5);
-	}
-/*
- * B/BL
- */
-|	LTYPE4 cond comma rel
-	{
-		outcode($1, $2, &nullgen, NREG, &$4);
-	}
-|	LTYPE4 cond comma nireg
-	{
-		outcode($1, $2, &nullgen, NREG, &$4);
-	}
-/*
- * BX
- */
-|	LTYPEBX comma ireg
-	{
-		outcode($1, Always, &nullgen, NREG, &$3);
-	}
-/*
- * BEQ
- */
-|	LTYPE5 comma rel
-	{
-		outcode($1, Always, &nullgen, NREG, &$3);
-	}
-/*
- * SWI
- */
-|	LTYPE6 cond comma gen
-	{
-		outcode($1, $2, &nullgen, NREG, &$4);
-	}
-/*
- * CMP
- */
-|	LTYPE7 cond imsr ',' spreg comma
-	{
-		outcode($1, $2, &$3, $5, &nullgen);
-	}
-/*
- * MOVM
- */
-|	LTYPE8 cond ioreg ',' '[' reglist ']'
-	{
-		Gen g;
-
-		g = nullgen;
-		g.type = D_CONST;
-		g.offset = $6;
-		outcode($1, $2, &$3, NREG, &g);
-	}
-|	LTYPE8 cond '[' reglist ']' ',' ioreg
-	{
-		Gen g;
-
-		g = nullgen;
-		g.type = D_CONST;
-		g.offset = $4;
-		outcode($1, $2, &g, NREG, &$7);
-	}
-/*
- * SWAP
- */
-|	LTYPE9 cond reg ',' ireg ',' reg
-	{
-		outcode($1, $2, &$5, $3.reg, &$7);
-	}
-|	LTYPE9 cond reg ',' ireg comma
-	{
-		outcode($1, $2, &$5, $3.reg, &$3);
-	}
-|	LTYPE9 cond comma ireg ',' reg
-	{
-		outcode($1, $2, &$4, $6.reg, &$6);
-	}
-/*
- * RET
- */
-|	LTYPEA cond comma
-	{
-		outcode($1, $2, &nullgen, NREG, &nullgen);
-	}
-/*
- * TEXT/GLOBL
- */
-|	LTYPEB name ',' imm
-	{
-		outcode($1, Always, &$2, NREG, &$4);
-	}
-|	LTYPEB name ',' con ',' imm
-	{
-		outcode($1, Always, &$2, $4, &$6);
-	}
-/*
- * DATA
- */
-|	LTYPEC name '/' con ',' ximm
-	{
-		outcode($1, Always, &$2, $4, &$6);
-	}
-/*
- * CASE
- */
-|	LTYPED cond reg comma
-	{
-		outcode($1, $2, &$3, NREG, &nullgen);
-	}
-/*
- * word
- */
-|	LTYPEH comma ximm
-	{
-		outcode($1, Always, &nullgen, NREG, &$3);
-	}
-/*
- * floating-point coprocessor
- */
-|	LTYPEI cond freg ',' freg
-	{
-		outcode($1, $2, &$3, NREG, &$5);
-	}
-|	LTYPEK cond frcon ',' freg
-	{
-		outcode($1, $2, &$3, NREG, &$5);
-	}
-|	LTYPEK cond frcon ',' LFREG ',' freg
-	{
-		outcode($1, $2, &$3, $5, &$7);
-	}
-|	LTYPEL cond freg ',' freg comma
-	{
-		outcode($1, $2, &$3, $5.reg, &nullgen);
-	}
-/*
- * MCR MRC
- */
-|	LTYPEJ cond con ',' expr ',' spreg ',' creg ',' creg oexpr
-	{
-		Gen g;
-
-		g = nullgen;
-		g.type = D_CONST;
-		g.offset =
-			(0xe << 24) |		/* opcode */
-			($1 << 20) |		/* MCR/MRC */
-			($2 << 28) |		/* scond */
-			(($3 & 15) << 8) |	/* coprocessor number */
-			(($5 & 7) << 21) |	/* coprocessor operation */
-			(($7 & 15) << 12) |	/* arm register */
-			(($9 & 15) << 16) |	/* Crn */
-			(($11 & 15) << 0) |	/* Crm */
-			(($12 & 7) << 5) |	/* coprocessor information */
-			(1<<4);			/* must be set */
-		outcode(AWORD, Always, &nullgen, NREG, &g);
-	}
-/*
- * MULL hi,lo,r1,r2
- */
-|	LTYPEM cond reg ',' reg ',' regreg
-	{
-		outcode($1, $2, &$3, $5.reg, &$7);
-	}
-/*
- * MULA hi,lo,r1,r2
- */
-|	LTYPEN cond reg ',' reg ',' reg ',' spreg 
-	{
-		$7.type = D_REGREG;
-		$7.offset = $9;
-		outcode($1, $2, &$3, $5.reg, &$7);
-	}
-/*
- * END
- */
-|	LTYPEE comma
-	{
-		outcode($1, Always, &nullgen, NREG, &nullgen);
-	}
-
-cond:
-	{
-		$$ = Always;
-	}
-|	cond LCOND
-	{
-		$$ = ($1 & ~C_SCOND) | $2;
-	}
-|	cond LS
-	{
-		$$ = $1 | $2;
-	}
-
-comma:
-|	',' comma
-
-rel:
-	con '(' LPC ')'
-	{
-		$$ = nullgen;
-		$$.type = D_BRANCH;
-		$$.offset = $1 + pc;
-	}
-|	LNAME offset
-	{
-		$$ = nullgen;
-		if(pass == 2)
-			yyerror("undefined label: %s", $1->name);
-		$$.type = D_BRANCH;
-		$$.sym = $1;
-		$$.offset = $2;
-	}
-|	LLAB offset
-	{
-		$$ = nullgen;
-		$$.type = D_BRANCH;
-		$$.sym = $1;
-		$$.offset = $1->value + $2;
-	}
-
-ximm:	'$' con
-	{
-		$$ = nullgen;
-		$$.type = D_CONST;
-		$$.offset = $2;
-	}
-|	'$' oreg
-	{
-		$$ = $2;
-		$$.type = D_CONST;
-	}
-|	'$' '*' '$' oreg
-	{
-		$$ = $4;
-		$$.type = D_OCONST;
-	}
-|	'$' LSCONST
-	{
-		$$ = nullgen;
-		$$.type = D_SCONST;
-		memcpy($$.sval, $2, sizeof($$.sval));
-	}
-|	fcon
-
-fcon:
-	'$' LFCONST
-	{
-		$$ = nullgen;
-		$$.type = D_FCONST;
-		$$.dval = $2;
-	}
-|	'$' '-' LFCONST
-	{
-		$$ = nullgen;
-		$$.type = D_FCONST;
-		$$.dval = -$3;
-	}
-
-reglist:
-	spreg
-	{
-		$$ = 1 << $1;
-	}
-|	spreg '-' spreg
-	{
-		int i;
-		$$=0;
-		for(i=$1; i<=$3; i++)
-			$$ |= 1<<i;
-		for(i=$3; i<=$1; i++)
-			$$ |= 1<<i;
-	}
-|	spreg comma reglist
-	{
-		$$ = (1<<$1) | $3;
-	}
-
-gen:
-	reg
-|	ximm
-|	shift
-|	shift '(' spreg ')'
-	{
-		$$ = $1;
-		$$.reg = $3;
-	}
-|	LPSR
-	{
-		$$ = nullgen;
-		$$.type = D_PSR;
-		$$.reg = $1;
-	}
-|	LFCR
-	{
-		$$ = nullgen;
-		$$.type = D_FPCR;
-		$$.reg = $1;
-	}
-|	con
-	{
-		$$ = nullgen;
-		$$.type = D_OREG;
-		$$.offset = $1;
-	}
-|	oreg
-|	freg
-
-nireg:
-	ireg
-|	name
-	{
-		$$ = $1;
-		if($1.name != D_EXTERN && $1.name != D_STATIC) {
-		}
-	}
-
-ireg:
-	'(' spreg ')'
-	{
-		$$ = nullgen;
-		$$.type = D_OREG;
-		$$.reg = $2;
-		$$.offset = 0;
-	}
-
-ioreg:
-	ireg
-|	con '(' sreg ')'
-	{
-		$$ = nullgen;
-		$$.type = D_OREG;
-		$$.reg = $3;
-		$$.offset = $1;
-	}
-
-oreg:
-	name
-|	name '(' sreg ')'
-	{
-		$$ = $1;
-		$$.type = D_OREG;
-		$$.reg = $3;
-	}
-|	ioreg
-
-imsr:
-	reg
-|	imm
-|	shift
-
-imm:	'$' con
-	{
-		$$ = nullgen;
-		$$.type = D_CONST;
-		$$.offset = $2;
-	}
-
-reg:
-	spreg
-	{
-		$$ = nullgen;
-		$$.type = D_REG;
-		$$.reg = $1;
-	}
-
-regreg:
-	'(' spreg ',' spreg ')'
-	{
-		$$ = nullgen;
-		$$.type = D_REGREG;
-		$$.reg = $2;
-		$$.offset = $4;
-	}
-
-shift:
-	spreg '<' '<' rcon
-	{
-		$$ = nullgen;
-		$$.type = D_SHIFT;
-		$$.offset = $1 | $4 | (0 << 5);
-	}
-|	spreg '>' '>' rcon
-	{
-		$$ = nullgen;
-		$$.type = D_SHIFT;
-		$$.offset = $1 | $4 | (1 << 5);
-	}
-|	spreg '-' '>' rcon
-	{
-		$$ = nullgen;
-		$$.type = D_SHIFT;
-		$$.offset = $1 | $4 | (2 << 5);
-	}
-|	spreg LAT '>' rcon
-	{
-		$$ = nullgen;
-		$$.type = D_SHIFT;
-		$$.offset = $1 | $4 | (3 << 5);
-	}
-
-rcon:
-	spreg
-	{
-		if($$ < 0 || $$ >= 16)
-			print("register value out of range\n");
-		$$ = (($1&15) << 8) | (1 << 4);
-	}
-|	con
-	{
-		if($$ < 0 || $$ >= 32)
-			print("shift value out of range\n");
-		$$ = ($1&31) << 7;
-	}
-
-sreg:
-	LREG
-|	LPC
-	{
-		$$ = REGPC;
-	}
-|	LR '(' expr ')'
-	{
-		if($3 < 0 || $3 >= NREG)
-			print("register value out of range\n");
-		$$ = $3;
-	}
-
-spreg:
-	sreg
-|	LSP
-	{
-		$$ = REGSP;
-	}
-
-creg:
-	LCREG
-|	LC '(' expr ')'
-	{
-		if($3 < 0 || $3 >= NREG)
-			print("register value out of range\n");
-		$$ = $3;
-	}
-
-frcon:
-	freg
-|	fcon
-
-freg:
-	LFREG
-	{
-		$$ = nullgen;
-		$$.type = D_FREG;
-		$$.reg = $1;
-	}
-|	LF '(' con ')'
-	{
-		$$ = nullgen;
-		$$.type = D_FREG;
-		$$.reg = $3;
-	}
-
-name:
-	con '(' pointer ')'
-	{
-		$$ = nullgen;
-		$$.type = D_OREG;
-		$$.name = $3;
-		$$.sym = S;
-		$$.offset = $1;
-	}
-|	LNAME offset '(' pointer ')'
-	{
-		$$ = nullgen;
-		$$.type = D_OREG;
-		$$.name = $4;
-		$$.sym = $1;
-		$$.offset = $2;
-	}
-|	LNAME '<' '>' offset '(' LSB ')'
-	{
-		$$ = nullgen;
-		$$.type = D_OREG;
-		$$.name = D_STATIC;
-		$$.sym = $1;
-		$$.offset = $4;
-	}
-
-offset:
-	{
-		$$ = 0;
-	}
-|	'+' con
-	{
-		$$ = $2;
-	}
-|	'-' con
-	{
-		$$ = -$2;
-	}
-
-pointer:
-	LSB
-|	LSP
-|	LFP
-
-con:
-	LCONST
-|	LVAR
-	{
-		$$ = $1->value;
-	}
-|	'-' con
-	{
-		$$ = -$2;
-	}
-|	'+' con
-	{
-		$$ = $2;
-	}
-|	'~' con
-	{
-		$$ = ~$2;
-	}
-|	'(' expr ')'
-	{
-		$$ = $2;
-	}
-
-oexpr:
-	{
-		$$ = 0;
-	}
-|	',' expr
-	{
-		$$ = $2;
-	}
-
-expr:
-	con
-|	expr '+' expr
-	{
-		$$ = $1 + $3;
-	}
-|	expr '-' expr
-	{
-		$$ = $1 - $3;
-	}
-|	expr '*' expr
-	{
-		$$ = $1 * $3;
-	}
-|	expr '/' expr
-	{
-		$$ = $1 / $3;
-	}
-|	expr '%' expr
-	{
-		$$ = $1 % $3;
-	}
-|	expr '<' '<' expr
-	{
-		$$ = $1 << $4;
-	}
-|	expr '>' '>' expr
-	{
-		$$ = $1 >> $4;
-	}
-|	expr '&' expr
-	{
-		$$ = $1 & $3;
-	}
-|	expr '^' expr
-	{
-		$$ = $1 ^ $3;
-	}
-|	expr '|' expr
-	{
-		$$ = $1 | $3;
-	}

+ 0 - 38
sys/src/cmd/5a/l.s

@@ -1,38 +0,0 @@
-TEXT	main(SB), $0
-
-	ADD		R1,R4
-	ADD		R1,R3,R4
-	ADD		R1<<1,R3,R4	/* logical left */
-	ADD		R1>>1,R3,R4	/* logical right */
-	ADD		R1->1,R3,R4	/* arithmetic right */
- 	ADD		R1@>1,R3,R4	/* rotate right */
-
-	ADD		R1<<R2,R3,R4
-	ADD		$10,R1,R4
-
-loop:
-	ADD.S.NE	R1,R4
-	BNE		loop
-
-	MOVW		R3, CPSR
-	MOVW		R3, SPSR
-	MOVW		R3, F10
-	MOVW		R3, (R2)
-	MOVW		R3, 10(R2)
-	MOVW		R3, name(SB)
-	MOVW		R3, name(SB)(R2)
-	MOVW		R3, name(SB)(R2)
-	MOVW		R3, (R2)
-	MOVW		R3, R1<<2(R2)
-
-	MRC.EQ		3,9,R3,C5,C6,2
-	MRC		3,9,R3,C5,C6,2
-
-	MOVM.IA		[R0,SP,R4], (R2)
-	MOVM.DB.W	(R0), [R6-R11]
-	MOVM.DB.W	(R0), [R0-R11]
-	MOVM.S		(R0), [R0-R11]	// .S is supervisor space
-
-	CMN	$4096,R0,
-
-	RET

+ 0 - 706
sys/src/cmd/5a/lex.c

@@ -1,706 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#define	EXTERN
-#include "a.h"
-#include "y.tab.h"
-#include <ctype.h>
-
-void
-main(int argc, char *argv[])
-{
-	char *p;
-	int nout, nproc, status, i, c;
-
-	thechar = '5';
-	thestring = "arm";
-	memset(debug, 0, sizeof(debug));
-	cinit();
-	outfile = 0;
-	include[ninclude++] = ".";
-	ARGBEGIN {
-	default:
-		c = ARGC();
-		if(c >= 0 || c < sizeof(debug))
-			debug[c] = 1;
-		break;
-
-	case 'o':
-		outfile = ARGF();
-		break;
-
-	case 'D':
-		p = ARGF();
-		if(p)
-			Dlist[nDlist++] = p;
-		break;
-
-	case 'I':
-		p = ARGF();
-		setinclude(p);
-		break;
-	case 't':
-		thechar = 't';
-		thestring = "thumb";
-		break;
-	} ARGEND
-	if(*argv == 0) {
-		print("usage: %ca [-options] file.s\n", thechar);
-		errorexit();
-	}
-	if(argc > 1 && systemtype(Windows)){
-		print("can't assemble multiple files on windows\n");
-		errorexit();
-	}
-	if(argc > 1 && !systemtype(Windows)) {
-		nproc = 1;
-		if(p = getenv("NPROC"))
-			nproc = atol(p);	/* */
-		c = 0;
-		nout = 0;
-		for(;;) {
-			while(nout < nproc && argc > 0) {
-				i = myfork();
-				if(i < 0) {
-					i = mywait(&status);
-					if(i < 0)
-						errorexit();
-					if(status)
-						c++;
-					nout--;
-					continue;
-				}
-				if(i == 0) {
-					print("%s:\n", *argv);
-					if(assemble(*argv))
-						errorexit();
-					exits(0);
-				}
-				nout++;
-				argc--;
-				argv++;
-			}
-			i = mywait(&status);
-			if(i < 0) {
-				if(c)
-					errorexit();
-				exits(0);
-			}
-			if(status)
-				c++;
-			nout--;
-		}
-	}
-	if(assemble(argv[0]))
-		errorexit();
-	exits(0);
-}
-
-int
-assemble(char *file)
-{
-	char ofile[100], incfile[20], *p;
-	int i, of;
-
-	strcpy(ofile, file);
-	p = utfrrune(ofile, pathchar());
-	if(p) {
-		include[0] = ofile;
-		*p++ = 0;
-	} else
-		p = ofile;
-	if(outfile == 0) {
-		outfile = p;
-		if(outfile){
-			p = utfrrune(outfile, '.');
-			if(p)
-				if(p[1] == 's' && p[2] == 0)
-					p[0] = 0;
-			p = utfrune(outfile, 0);
-			p[0] = '.';
-			p[1] = thechar;
-			p[2] = 0;
-		} else
-			outfile = "/dev/null";
-	}
-	p = getenv("INCLUDE");
-	if(p) {
-		setinclude(p);
-	} else {
-		if(systemtype(Plan9)) {
-			sprint(incfile,"/%s/include", thestring);
-			setinclude(strdup(incfile));
-		}
-	}
-
-	of = mycreat(outfile, 0664);
-	if(of < 0) {
-		yyerror("%ca: cannot create %s", thechar, outfile);
-		errorexit();
-	}
-	Binit(&obuf, of, OWRITE);
-
-	pass = 1;
-	pinit(file);
-	for(i=0; i<nDlist; i++)
-		dodefine(Dlist[i]);
-	yyparse();
-	if(nerrors) {
-		cclean();
-		return nerrors;
-	}
-
-	pass = 2;
-	outhist();
-	pinit(file);
-	for(i=0; i<nDlist; i++)
-		dodefine(Dlist[i]);
-	yyparse();
-	cclean();
-	return nerrors;
-}
-
-struct
-{
-	char	*name;
-	uint16_t	type;
-	uint16_t	value;
-} itab[] =
-{
-	"SP",		LSP,	D_AUTO,
-	"SB",		LSB,	D_EXTERN,
-	"FP",		LFP,	D_PARAM,
-	"PC",		LPC,	D_BRANCH,
-
-	"R",		LR,	0,
-	"R0",		LREG,	0,
-	"R1",		LREG,	1,
-	"R2",		LREG,	2,
-	"R3",		LREG,	3,
-	"R4",		LREG,	4,
-	"R5",		LREG,	5,
-	"R6",		LREG,	6,
-	"R7",		LREG,	7,
-	"R8",		LREG,	8,
-	"R9",		LREG,	9,
-	"R10",		LREG,	10,
-	"R11",		LREG,	11,
-	"R12",		LREG,	12,
-	"R13",		LREG,	13,
-	"R14",		LREG,	14,
-	"R15",		LREG,	15,
-
-	"F",		LF,	0,
-
-	"F0",		LFREG,	0,
-	"F1",		LFREG,	1,
-	"F2",		LFREG,	2,
-	"F3",		LFREG,	3,
-	"F4",		LFREG,	4,
-	"F5",		LFREG,	5,
-	"F6",		LFREG,	6,
-	"F7",		LFREG,	7,
-	"F8",		LFREG,	8,
-	"F9",		LFREG,	9,
-	"F10",		LFREG,	10,
-	"F11",		LFREG,	11,
-	"F12",		LFREG,	12,
-	"F13",		LFREG,	13,
-	"F14",		LFREG,	14,
-	"F15",		LFREG,	15,
-
-	"C",		LC,	0,
-
-	"C0",		LCREG,	0,
-	"C1",		LCREG,	1,
-	"C2",		LCREG,	2,
-	"C3",		LCREG,	3,
-	"C4",		LCREG,	4,
-	"C5",		LCREG,	5,
-	"C6",		LCREG,	6,
-	"C7",		LCREG,	7,
-	"C8",		LCREG,	8,
-	"C9",		LCREG,	9,
-	"C10",		LCREG,	10,
-	"C11",		LCREG,	11,
-	"C12",		LCREG,	12,
-	"C13",		LCREG,	13,
-	"C14",		LCREG,	14,
-	"C15",		LCREG,	15,
-
-	"CPSR",		LPSR,	0,
-	"SPSR",		LPSR,	1,
-
-	"FPSR",		LFCR,	0,
-	"FPCR",		LFCR,	1,
-
-	".EQ",		LCOND,	0,
-	".NE",		LCOND,	1,
-	".CS",		LCOND,	2,
-	".HS",		LCOND,	2,
-	".CC",		LCOND,	3,
-	".LO",		LCOND,	3,
-	".MI",		LCOND,	4,
-	".PL",		LCOND,	5,
-	".VS",		LCOND,	6,
-	".VC",		LCOND,	7,
-	".HI",		LCOND,	8,
-	".LS",		LCOND,	9,
-	".GE",		LCOND,	10,
-	".LT",		LCOND,	11,
-	".GT",		LCOND,	12,
-	".LE",		LCOND,	13,
-	".AL",		LCOND,	Always,
-
-	".U",		LS,	C_UBIT,
-	".S",		LS,	C_SBIT,
-	".W",		LS,	C_WBIT,
-	".P",		LS,	C_PBIT,
-	".PW",		LS,	C_WBIT|C_PBIT,
-	".WP",		LS,	C_WBIT|C_PBIT,
-
-	".F",		LS,	C_FBIT,
-
-	".IBW",		LS,	C_WBIT|C_PBIT|C_UBIT,
-	".IAW",		LS,	C_WBIT|C_UBIT,
-	".DBW",		LS,	C_WBIT|C_PBIT,
-	".DAW",		LS,	C_WBIT,
-	".IB",		LS,	C_PBIT|C_UBIT,
-	".IA",		LS,	C_UBIT,
-	".DB",		LS,	C_PBIT,
-	".DA",		LS,	0,
-
-	"@",		LAT,	0,
-
-	"AND",		LTYPE1,	AAND,
-	"EOR",		LTYPE1,	AEOR,
-	"SUB",		LTYPE1,	ASUB,
-	"RSB",		LTYPE1,	ARSB,
-	"ADD",		LTYPE1,	AADD,
-	"ADC",		LTYPE1,	AADC,
-	"SBC",		LTYPE1,	ASBC,
-	"RSC",		LTYPE1,	ARSC,
-	"ORR",		LTYPE1,	AORR,
-	"BIC",		LTYPE1,	ABIC,
-
-	"SLL",		LTYPE1,	ASLL,
-	"SRL",		LTYPE1,	ASRL,
-	"SRA",		LTYPE1,	ASRA,
-
-	"MUL",		LTYPE1, AMUL,
-	"MULA",		LTYPEN, AMULA,
-	"DIV",		LTYPE1,	ADIV,
-	"MOD",		LTYPE1,	AMOD,
-
-	"MULL",		LTYPEM, AMULL,
-	"MULAL",	LTYPEM, AMULAL,
-	"MULLU",	LTYPEM, AMULLU,
-	"MULALU",	LTYPEM, AMULALU,
-
-	"MVN",		LTYPE2, AMVN,	/* op2 ignored */
-
-	"MOVB",		LTYPE3, AMOVB,
-	"MOVBU",	LTYPE3, AMOVBU,
-	"MOVH",		LTYPE3, AMOVH,
-	"MOVHU",	LTYPE3, AMOVHU,
-	"MOVW",		LTYPE3, AMOVW,
-
-	"MOVD",		LTYPE3, AMOVD,
-	"MOVDF",		LTYPE3, AMOVDF,
-	"MOVDW",	LTYPE3, AMOVDW,
-	"MOVF",		LTYPE3, AMOVF,
-	"MOVFD",		LTYPE3, AMOVFD,
-	"MOVFW",		LTYPE3, AMOVFW,
-	"MOVWD",	LTYPE3, AMOVWD,
-	"MOVWF",		LTYPE3, AMOVWF,
-
-	"LDREX",		LTYPE3, ALDREX,
-	"LDREXD",		LTYPE3, ALDREXD,
-	"STREX",		LTYPE9, ASTREX,
-	"STREXD",		LTYPE9, ASTREXD,
-
-/*
-	"ABSF",		LTYPEI, AABSF,
-	"ABSD",		LTYPEI, AABSD,
-	"NEGF",		LTYPEI, ANEGF,
-	"NEGD",		LTYPEI, ANEGD,
-	"SQTF",		LTYPEI,	ASQTF,
-	"SQTD",		LTYPEI,	ASQTD,
-	"RNDF",		LTYPEI,	ARNDF,
-	"RNDD",		LTYPEI,	ARNDD,
-	"URDF",		LTYPEI,	AURDF,
-	"URDD",		LTYPEI,	AURDD,
-	"NRMF",		LTYPEI,	ANRMF,
-	"NRMD",		LTYPEI,	ANRMD,
-*/
-
-	"SQRTF",	LTYPEI, ASQRTF,
-	"SQRTD",	LTYPEI, ASQRTD,
-	"CMPF",		LTYPEL, ACMPF,
-	"CMPD",		LTYPEL, ACMPD,
-	"ADDF",		LTYPEK,	AADDF,
-	"ADDD",		LTYPEK,	AADDD,
-	"SUBF",		LTYPEK,	ASUBF,
-	"SUBD",		LTYPEK,	ASUBD,
-	"MULF",		LTYPEK,	AMULF,
-	"MULD",		LTYPEK,	AMULD,
-	"DIVF",		LTYPEK,	ADIVF,
-	"DIVD",		LTYPEK,	ADIVD,
-
-	"B",		LTYPE4, AB,
-	"BL",		LTYPE4, ABL,
-	"BX",		LTYPEBX,	ABX,
-
-	"BEQ",		LTYPE5,	ABEQ,
-	"BNE",		LTYPE5,	ABNE,
-	"BCS",		LTYPE5,	ABCS,
-	"BHS",		LTYPE5,	ABHS,
-	"BCC",		LTYPE5,	ABCC,
-	"BLO",		LTYPE5,	ABLO,
-	"BMI",		LTYPE5,	ABMI,
-	"BPL",		LTYPE5,	ABPL,
-	"BVS",		LTYPE5,	ABVS,
-	"BVC",		LTYPE5,	ABVC,
-	"BHI",		LTYPE5,	ABHI,
-	"BLS",		LTYPE5,	ABLS,
-	"BGE",		LTYPE5,	ABGE,
-	"BLT",		LTYPE5,	ABLT,
-	"BGT",		LTYPE5,	ABGT,
-	"BLE",		LTYPE5,	ABLE,
-	"BCASE",	LTYPE5,	ABCASE,
-
-	"SWI",		LTYPE6, ASWI,
-
-	"CMP",		LTYPE7,	ACMP,
-	"TST",		LTYPE7,	ATST,
-	"TEQ",		LTYPE7,	ATEQ,
-	"CMN",		LTYPE7,	ACMN,
-
-	"MOVM",		LTYPE8, AMOVM,
-
-	"SWPBU",	LTYPE9, ASWPBU,
-	"SWPW",		LTYPE9, ASWPW,
-
-	"RET",		LTYPEA, ARET,
-	"RFE",		LTYPEA, ARFE,
-
-	"TEXT",		LTYPEB, ATEXT,
-	"GLOBL",	LTYPEB, AGLOBL,
-	"DATA",		LTYPEC, ADATA,
-	"CASE",		LTYPED, ACASE,
-	"END",		LTYPEE, AEND,
-	"WORD",		LTYPEH, AWORD,
-	"NOP",		LTYPEI, ANOP,
-
-	"MCR",		LTYPEJ, 0,
-	"MRC",		LTYPEJ, 1,
-	0
-};
-
-void
-cinit(void)
-{
-	Sym *s;
-	int i;
-
-	nullgen.sym = S;
-	nullgen.offset = 0;
-	nullgen.type = D_NONE;
-	nullgen.name = D_NONE;
-	nullgen.reg = NREG;
-	if(FPCHIP)
-		nullgen.dval = 0;
-	for(i=0; i<sizeof(nullgen.sval); i++)
-		nullgen.sval[i] = 0;
-
-	nerrors = 0;
-	iostack = I;
-	iofree = I;
-	peekc = IGN;
-	nhunk = 0;
-	for(i=0; i<NHASH; i++)
-		hash[i] = S;
-	for(i=0; itab[i].name; i++) {
-		s = slookup(itab[i].name);
-		s->type = itab[i].type;
-		s->value = itab[i].value;
-	}
-
-	pathname = allocn(pathname, 0, 100);
-	if(getwd(pathname, 99) == 0) {
-		pathname = allocn(pathname, 100, 900);
-		if(getwd(pathname, 999) == 0)
-			strcpy(pathname, "/???");
-	}
-}
-
-void
-syminit(Sym *s)
-{
-
-	s->type = LNAME;
-	s->value = 0;
-}
-
-int
-isreg(Gen *g)
-{
-
-	USED(g);
-	return 1;
-}
-
-void
-cclean(void)
-{
-
-	outcode(AEND, Always, &nullgen, NREG, &nullgen);
-	Bflush(&obuf);
-}
-
-void
-zname(char *n, int t, int s)
-{
-
-	Bputc(&obuf, ANAME);
-	Bputc(&obuf, t);	/* type */
-	Bputc(&obuf, s);	/* sym */
-	while(*n) {
-		Bputc(&obuf, *n);
-		n++;
-	}
-	Bputc(&obuf, 0);
-}
-
-void
-zaddr(Gen *a, int s)
-{
-	int32_t l;
-	int i;
-	char *n;
-	Ieee e;
-
-	Bputc(&obuf, a->type);
-	Bputc(&obuf, a->reg);
-	Bputc(&obuf, s);
-	Bputc(&obuf, a->name);
-	switch(a->type) {
-	default:
-		print("unknown type %d\n", a->type);
-		exits("arg");
-
-	case D_NONE:
-	case D_REG:
-	case D_FREG:
-	case D_PSR:
-	case D_FPCR:
-		break;
-
-	case D_REGREG:
-		Bputc(&obuf, a->offset);
-		break;
-
-	case D_OREG:
-	case D_CONST:
-	case D_BRANCH:
-	case D_SHIFT:
-		l = a->offset;
-		Bputc(&obuf, l);
-		Bputc(&obuf, l>>8);
-		Bputc(&obuf, l>>16);
-		Bputc(&obuf, l>>24);
-		break;
-
-	case D_SCONST:
-		n = a->sval;
-		for(i=0; i<NSNAME; i++) {
-			Bputc(&obuf, *n);
-			n++;
-		}
-		break;
-
-	case D_FCONST:
-		ieeedtod(&e, a->dval);
-		Bputc(&obuf, e.l);
-		Bputc(&obuf, e.l>>8);
-		Bputc(&obuf, e.l>>16);
-		Bputc(&obuf, e.l>>24);
-		Bputc(&obuf, e.h);
-		Bputc(&obuf, e.h>>8);
-		Bputc(&obuf, e.h>>16);
-		Bputc(&obuf, e.h>>24);
-		break;
-	}
-}
-
-static int bcode[] =
-{
-	ABEQ,
-	ABNE,
-	ABCS,
-	ABCC,
-	ABMI,
-	ABPL,
-	ABVS,
-	ABVC,
-	ABHI,
-	ABLS,
-	ABGE,
-	ABLT,
-	ABGT,
-	ABLE,
-	AB,
-	ANOP,
-};
-
-void
-outcode(int a, int scond, Gen *g1, int reg, Gen *g2)
-{
-	int sf, st, t;
-	Sym *s;
-
-	/* hack to make B.NE etc. work: turn it into the corresponding conditional */
-	if(a == AB){
-		a = bcode[scond&0xf];
-		scond = (scond & ~0xf) | Always;
-	}
-
-	if(pass == 1)
-		goto out;
-jackpot:
-	sf = 0;
-	s = g1->sym;
-	while(s != S) {
-		sf = s->sym;
-		if(sf < 0 || sf >= NSYM)
-			sf = 0;
-		t = g1->name;
-		if(h[sf].type == t)
-		if(h[sf].sym == s)
-			break;
-		zname(s->name, t, sym);
-		s->sym = sym;
-		h[sym].sym = s;
-		h[sym].type = t;
-		sf = sym;
-		sym++;
-		if(sym >= NSYM)
-			sym = 1;
-		break;
-	}
-	st = 0;
-	s = g2->sym;
-	while(s != S) {
-		st = s->sym;
-		if(st < 0 || st >= NSYM)
-			st = 0;
-		t = g2->name;
-		if(h[st].type == t)
-		if(h[st].sym == s)
-			break;
-		zname(s->name, t, sym);
-		s->sym = sym;
-		h[sym].sym = s;
-		h[sym].type = t;
-		st = sym;
-		sym++;
-		if(sym >= NSYM)
-			sym = 1;
-		if(st == sf)
-			goto jackpot;
-		break;
-	}
-	Bputc(&obuf, a);
-	Bputc(&obuf, scond);
-	Bputc(&obuf, reg);
-	Bputc(&obuf, lineno);
-	Bputc(&obuf, lineno>>8);
-	Bputc(&obuf, lineno>>16);
-	Bputc(&obuf, lineno>>24);
-	zaddr(g1, sf);
-	zaddr(g2, st);
-
-out:
-	if(a != AGLOBL && a != ADATA)
-		pc++;
-}
-
-void
-outhist(void)
-{
-	Gen g;
-	Hist *h;
-	char *p, *q, *op, c;
-	int n;
-
-	g = nullgen;
-	c = pathchar();
-	for(h = hist; h != H; h = h->link) {
-		p = h->name;
-		op = 0;
-		/* on windows skip drive specifier in pathname */
-		if(systemtype(Windows) && p && p[1] == ':'){
-			p += 2;
-			c = *p;
-		}
-		if(p && p[0] != c && h->offset == 0 && pathname){
-			/* on windows skip drive specifier in pathname */
-			if(systemtype(Windows) && pathname[1] == ':') {
-				op = p;
-				p = pathname+2;
-				c = *p;
-			} else if(pathname[0] == c){
-				op = p;
-				p = pathname;
-			}
-		}
-		while(p) {
-			q = strchr(p, c);
-			if(q) {
-				n = q-p;
-				if(n == 0){
-					n = 1;	/* leading "/" */
-					*p = '/';	/* don't emit "\" on windows */
-				}
-				q++;
-			} else {
-				n = strlen(p);
-				q = 0;
-			}
-			if(n) {
-				Bputc(&obuf, ANAME);
-				Bputc(&obuf, D_FILE);	/* type */
-				Bputc(&obuf, 1);	/* sym */
-				Bputc(&obuf, '<');
-				Bwrite(&obuf, p, n);
-				Bputc(&obuf, 0);
-			}
-			p = q;
-			if(p == 0 && op) {
-				p = op;
-				op = 0;
-			}
-		}
-		g.offset = h->offset;
-
-		Bputc(&obuf, AHISTORY);
-		Bputc(&obuf, Always);
-		Bputc(&obuf, 0);
-		Bputc(&obuf, h->line);
-		Bputc(&obuf, h->line>>8);
-		Bputc(&obuf, h->line>>16);
-		Bputc(&obuf, h->line>>24);
-		zaddr(&nullgen, 0);
-		zaddr(&g, 0);
-	}
-}
-
-#include "../cc/lexbody"
-#include "../cc/macbody"
-#include "../cc/compat"

+ 0 - 19
sys/src/cmd/5a/mkfile

@@ -1,19 +0,0 @@
-</$objtype/mkfile
-
-TARG=5a
-OFILES=\
-	y.tab.$O\
-	lex.$O\
-
-HFILES=\
-	../5c/5.out.h\
-	y.tab.h\
-	a.h\
-
-YFILES=a.y\
-
-BIN=/$objtype/bin
-< /sys/src/cmd/mkone
-YFLAGS=-D1 -d
-
-lex.$O:	../cc/macbody ../cc/lexbody

+ 0 - 222
sys/src/cmd/5c/5.out.h

@@ -1,222 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#define	NSNAME		8
-#define	NSYM		50
-#define	NREG		16
-
-#define NOPROF		(1<<0)
-#define DUPOK		(1<<1)
-#define	ALLTHUMBS	(1<<2)
-
-#define	REGRET		0
-#define	REGARG		0
-/* compiler allocates R1 up as temps */
-/* compiler allocates register variables R2 up */
-#define	REGMIN		2
-#define	REGMAX		8
-#define	REGEXT		10
-/* compiler allocates external registers R10 down */
-#define	REGTMP		11
-#define	REGSB		12
-#define	REGSP		13
-#define	REGLINK		14
-#define	REGPC		15
-
-#define	REGTMPT		7	/* used by the loader for thumb code */
-
-#define	NFREG		8
-#define	FREGRET		0
-#define	FREGEXT		7
-#define	FREGTMP		15
-/* compiler allocates register variables F0 up */
-/* compiler allocates external registers F7 down */
-
-enum	as
-{
-	AXXX,
-
-	AAND,
-	AEOR,
-	ASUB,
-	ARSB,
-	AADD,
-	AADC,
-	ASBC,
-	ARSC,
-	ATST,
-	ATEQ,
-	ACMP,
-	ACMN,
-	AORR,
-	ABIC,
-
-	AMVN,
-
-	AB,
-	ABL,
-
-/* 
- * Do not reorder or fragment the conditional branch 
- * opcodes, or the predication code will break 
- */ 
-	ABEQ,
-	ABNE,
-	ABCS,
-	ABHS,
-	ABCC,
-	ABLO,
-	ABMI,
-	ABPL,
-	ABVS,
-	ABVC,
-	ABHI,
-	ABLS,
-	ABGE,
-	ABLT,
-	ABGT,
-	ABLE,
-
-	AMOVWD,
-	AMOVWF,
-	AMOVDW,
-	AMOVFW,
-	AMOVFD,
-	AMOVDF,
-	AMOVF,
-	AMOVD,
-
-	ACMPF,
-	ACMPD,
-	AADDF,
-	AADDD,
-	ASUBF,
-	ASUBD,
-	AMULF,
-	AMULD,
-	ADIVF,
-	ADIVD,
-//	ASQRTF,
-//	ASQRTD,
-
-	ASRL,
-	ASRA,
-	ASLL,
-	AMULU,
-	ADIVU,
-	AMUL,
-	ADIV,
-	AMOD,
-	AMODU,
-
-	AMOVB,
-	AMOVBU,
-	AMOVH,
-	AMOVHU,
-	AMOVW,
-	AMOVM,
-	ASWPBU,
-	ASWPW,
-
-	ANOP,
-	ARFE,
-	ASWI,
-	AMULA,
-
-	ADATA,
-	AGLOBL,
-	AGOK,
-	AHISTORY,
-	ANAME,
-	ARET,
-	ATEXT,
-	AWORD,
-	ADYNT,
-	AINIT,
-	ABCASE,
-	ACASE,
-
-	AEND,
-
-	AMULL,
-	AMULAL,
-	AMULLU,
-	AMULALU,
-
-	ABX,
-	ABXRET,
-	ADWORD,
-
-	ASIGNAME,
-
-	/* moved here to preserve values of older identifiers */
-	ASQRTF,
-	ASQRTD,
-
-	ALDREX,
-	ASTREX,
-	
-	ALDREXD,
-	ASTREXD,
-
-	ALAST,
-};
-
-/* scond byte */
-#define	C_SCOND	((1<<4)-1)
-#define	C_SBIT	(1<<4)
-#define	C_PBIT	(1<<5)
-#define	C_WBIT	(1<<6)
-#define	C_FBIT	(1<<7)	/* psr flags-only */
-#define	C_UBIT	(1<<7)	/* up bit */
-
-/* type/name */
-#define	D_GOK	0
-#define	D_NONE	1
-
-/* type */
-#define	D_BRANCH	(D_NONE+1)
-#define	D_OREG		(D_NONE+2)
-#define	D_CONST		(D_NONE+7)
-#define	D_FCONST	(D_NONE+8)
-#define	D_SCONST	(D_NONE+9)
-#define	D_PSR		(D_NONE+10)
-#define	D_REG		(D_NONE+12)
-#define	D_FREG		(D_NONE+13)
-#define	D_FILE		(D_NONE+16)
-#define	D_OCONST	(D_NONE+17)
-#define	D_FILE1		(D_NONE+18)
-
-#define	D_SHIFT		(D_NONE+19)
-#define	D_FPCR		(D_NONE+20)
-#define	D_REGREG	(D_NONE+21)
-#define	D_ADDR		(D_NONE+22)
-
-/* name */
-#define	D_EXTERN	(D_NONE+3)
-#define	D_STATIC	(D_NONE+4)
-#define	D_AUTO		(D_NONE+5)
-#define	D_PARAM		(D_NONE+6)
-
-/*
- * this is the ranlib header
- */
-#define	SYMDEF	"__.SYMDEF"
-
-/*
- * this is the simulated IEEE floating point
- */
-typedef	struct	ieee	Ieee;
-struct	ieee
-{
-	long	l;	/* contains ls-man	0xffffffff */
-	long	h;	/* contains sign	0x80000000
-				    exp		0x7ff00000
-				    ms-man	0x000fffff */
-};

+ 0 - 1177
sys/src/cmd/5c/cgen.c

@@ -1,1177 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "gc.h"
-
-void
-cgen(Node *n, Node *nn)
-{
-	cgenrel(n, nn, 0);
-}
-
-void
-cgenrel(Node *n, Node *nn, int inrel)
-{
-	Node *l, *r;
-	Prog *p1;
-	Node nod, nod1, nod2, nod3, nod4;
-	int o, t;
-	int32_t v, curs;
-
-	if(debug['g']) {
-		prtree(nn, "cgen lhs");
-		prtree(n, "cgen");
-	}
-	if(n == Z || n->type == T)
-		return;
-	if(typesuv[n->type->etype]) {
-		sugen(n, nn, n->type->width);
-		return;
-	}
-	l = n->left;
-	r = n->right;
-	o = n->op;
-	if(n->addable >= INDEXED) {
-		if(nn == Z) {
-			switch(o) {
-			default:
-				nullwarn(Z, Z);
-				break;
-			case OINDEX:
-				nullwarn(l, r);
-				break;
-			}
-			return;
-		}
-		gmove(n, nn);
-		return;
-	}
-	curs = cursafe;
-
-	if(n->complex >= FNX)
-	if(l->complex >= FNX)
-	if(r != Z && r->complex >= FNX)
-	switch(o) {
-	default:
-		regret(&nod, r);
-		cgen(r, &nod);
-
-		regsalloc(&nod1, r);
-		gopcode(OAS, &nod, Z, &nod1);
-
-		regfree(&nod);
-		nod = *n;
-		nod.right = &nod1;
-		cgen(&nod, nn);
-		return;
-
-	case OFUNC:
-	case OCOMMA:
-	case OANDAND:
-	case OOROR:
-	case OCOND:
-	case ODOT:
-		break;
-	}
-
-	switch(o) {
-	default:
-		diag(n, "unknown op in cgen: %O", o);
-		break;
-
-	case OAS:
-		if(l->op == OBIT)
-			goto bitas;
-		if(l->addable >= INDEXED && l->complex < FNX) {
-			if(nn != Z || r->addable < INDEXED) {
-				if(r->complex >= FNX && nn == Z)
-					regret(&nod, r);
-				else
-					regalloc(&nod, r, nn);
-				cgen(r, &nod);
-				gmove(&nod, l);
-				if(nn != Z)
-					gmove(&nod, nn);
-				regfree(&nod);
-			} else
-				gmove(r, l);
-			break;
-		}
-		if(l->complex >= r->complex) {
-			reglcgen(&nod1, l, Z);
-			if(r->addable >= INDEXED) {
-				gmove(r, &nod1);
-				if(nn != Z)
-					gmove(r, nn);
-				regfree(&nod1);
-				break;
-			}
-			regalloc(&nod, r, nn);
-			cgen(r, &nod);
-		} else {
-			regalloc(&nod, r, nn);
-			cgen(r, &nod);
-			reglcgen(&nod1, l, Z);
-		}
-		gmove(&nod, &nod1);
-		regfree(&nod);
-		regfree(&nod1);
-		break;
-
-	bitas:
-		n = l->left;
-		regalloc(&nod, r, nn);
-		if(l->complex >= r->complex) {
-			reglcgen(&nod1, n, Z);
-			cgen(r, &nod);
-		} else {
-			cgen(r, &nod);
-			reglcgen(&nod1, n, Z);
-		}
-		regalloc(&nod2, n, Z);
-		gopcode(OAS, &nod1, Z, &nod2);
-		bitstore(l, &nod, &nod1, &nod2, nn);
-		break;
-
-	case OBIT:
-		if(nn == Z) {
-			nullwarn(l, Z);
-			break;
-		}
-		bitload(n, &nod, Z, Z, nn);
-		gopcode(OAS, &nod, Z, nn);
-		regfree(&nod);
-		break;
-
-	case ODIV:
-	case OMOD:
-		if(nn != Z)
-		if((t = vlog(r)) >= 0) {
-			/* signed div/mod by constant power of 2 */
-			cgen(l, nn);
-			gopcode(OGE, nodconst(0), nn, Z);
-			p1 = p;
-			if(o == ODIV) {
-				gopcode(OADD, nodconst((1<<t)-1), Z, nn);
-				patch(p1, pc);
-				gopcode(OASHR, nodconst(t), Z, nn);
-			} else {
-				gopcode(OSUB, nn, nodconst(0), nn);
-				gopcode(OAND, nodconst((1<<t)-1), Z, nn);
-				gopcode(OSUB, nn, nodconst(0), nn);
-				gbranch(OGOTO);
-				patch(p1, pc);
-				p1 = p;
-				gopcode(OAND, nodconst((1<<t)-1), Z, nn);
-				patch(p1, pc);
-			}
-			break;
-		}
-		goto muldiv;
-
-	case OSUB:
-		if(nn != Z)
-		if(l->op == OCONST)
-		if(!typefd[n->type->etype]) {
-			cgen(r, nn);
-			gopcode(o, Z, l, nn);
-			break;
-		}
-	case OADD:
-	case OAND:
-	case OOR:
-	case OXOR:
-	case OLSHR:
-	case OASHL:
-	case OASHR:
-		/*
-		 * immediate operands
-		 */
-		if(nn != Z)
-		if(r->op == OCONST)
-		if(!typefd[n->type->etype]) {
-			cgen(l, nn);
-			if(r->vconst == 0)
-			if(o != OAND)
-				break;
-			if(nn != Z)
-				gopcode(o, r, Z, nn);
-			break;
-		}
-
-	case OLMUL:
-	case OLDIV:
-	case OLMOD:
-	case OMUL:
-	muldiv:
-		if(nn == Z) {
-			nullwarn(l, r);
-			break;
-		}
-		if(o == OMUL || o == OLMUL) {
-			if(mulcon(n, nn))
-				break;
-		}
-		if(l->complex >= r->complex) {
-			regalloc(&nod, l, nn);
-			cgen(l, &nod);
-			regalloc(&nod1, r, Z);
-			cgen(r, &nod1);
-			gopcode(o, &nod1, Z, &nod);
-		} else {
-			regalloc(&nod, r, nn);
-			cgen(r, &nod);
-			regalloc(&nod1, l, Z);
-			cgen(l, &nod1);
-			gopcode(o, &nod, &nod1, &nod);
-		}
-		gopcode(OAS, &nod, Z, nn);
-		regfree(&nod);
-		regfree(&nod1);
-		break;
-
-	case OASLSHR:
-	case OASASHL:
-	case OASASHR:
-	case OASAND:
-	case OASADD:
-	case OASSUB:
-	case OASXOR:
-	case OASOR:
-		if(l->op == OBIT)
-			goto asbitop;
-		if(r->op == OCONST)
-		if(!typefd[r->type->etype])
-		if(!typefd[n->type->etype]) {
-			if(l->addable < INDEXED)
-				reglcgen(&nod2, l, Z);
-			else
-				nod2 = *l;
-			regalloc(&nod, r, nn);
-			gopcode(OAS, &nod2, Z, &nod);
-			gopcode(o, r, Z, &nod);
-			gopcode(OAS, &nod, Z, &nod2);
-	
-			regfree(&nod);
-			if(l->addable < INDEXED)
-				regfree(&nod2);
-			break;
-		}
-
-	case OASLMUL:
-	case OASLDIV:
-	case OASLMOD:
-	case OASMUL:
-	case OASDIV:
-	case OASMOD:
-		if(l->op == OBIT)
-			goto asbitop;
-		if(l->complex >= r->complex) {
-			if(l->addable < INDEXED)
-				reglcgen(&nod2, l, Z);
-			else
-				nod2 = *l;
-			regalloc(&nod1, r, Z);
-			cgen(r, &nod1);
-		} else {
-			regalloc(&nod1, r, Z);
-			cgen(r, &nod1);
-			if(l->addable < INDEXED)
-				reglcgen(&nod2, l, Z);
-			else
-				nod2 = *l;
-		}
-
-		regalloc(&nod, n, nn);
-		gmove(&nod2, &nod);
-		gopcode(o, &nod1, Z, &nod);
-		gmove(&nod, &nod2);
-		if(nn != Z)
-			gopcode(OAS, &nod, Z, nn);
-		regfree(&nod);
-		regfree(&nod1);
-		if(l->addable < INDEXED)
-			regfree(&nod2);
-		break;
-
-	asbitop:
-		regalloc(&nod4, n, nn);
-		if(l->complex >= r->complex) {
-			bitload(l, &nod, &nod1, &nod2, &nod4);
-			regalloc(&nod3, r, Z);
-			cgen(r, &nod3);
-		} else {
-			regalloc(&nod3, r, Z);
-			cgen(r, &nod3);
-			bitload(l, &nod, &nod1, &nod2, &nod4);
-		}
-		gmove(&nod, &nod4);
-		gopcode(o, &nod3, Z, &nod4);
-		regfree(&nod3);
-		gmove(&nod4, &nod);
-		regfree(&nod4);
-		bitstore(l, &nod, &nod1, &nod2, nn);
-		break;
-
-	case OADDR:
-		if(nn == Z) {
-			nullwarn(l, Z);
-			break;
-		}
-		lcgen(l, nn);
-		break;
-
-	case OFUNC:
-		if(l->complex >= FNX) {
-			if(l->op != OIND)
-				diag(n, "bad function call");
-
-			regret(&nod, l->left);
-			cgen(l->left, &nod);
-			regsalloc(&nod1, l->left);
-			gopcode(OAS, &nod, Z, &nod1);
-			regfree(&nod);
-
-			nod = *n;
-			nod.left = &nod2;
-			nod2 = *l;
-			nod2.left = &nod1;
-			nod2.complex = 1;
-			cgen(&nod, nn);
-
-			return;
-		}
-		if(REGARG >= 0)
-			o = reg[REGARG];
-		gargs(r, &nod, &nod1);
-		if(l->addable < INDEXED) {
-			reglcgen(&nod, l, Z);
-			gopcode(OFUNC, Z, Z, &nod);
-			regfree(&nod);
-		} else
-			gopcode(OFUNC, Z, Z, l);
-		if(REGARG >= 0)
-			if(o != reg[REGARG])
-				reg[REGARG]--;
-		if(nn != Z) {
-			regret(&nod, n);
-			gopcode(OAS, &nod, Z, nn);
-			regfree(&nod);
-		}
-		break;
-
-	case OIND:
-		if(nn == Z) {
-			nullwarn(l, Z);
-			break;
-		}
-		regialloc(&nod, n, nn);
-		r = l;
-		while(r->op == OADD)
-			r = r->right;
-		if(sconst(r) && (v = r->vconst+nod.xoffset) > -4096 && v < 4096) {
-			v = r->vconst;
-			r->vconst = 0;
-			cgen(l, &nod);
-			nod.xoffset += v;
-			r->vconst = v;
-		} else
-			cgen(l, &nod);
-		regind(&nod, n);
-		gopcode(OAS, &nod, Z, nn);
-		regfree(&nod);
-		break;
-
-	case OEQ:
-	case ONE:
-	case OLE:
-	case OLT:
-	case OGE:
-	case OGT:
-	case OLO:
-	case OLS:
-	case OHI:
-	case OHS:
-		if(nn == Z) {
-			nullwarn(l, r);
-			break;
-		}
-		boolgen(n, 1, nn);
-		break;
-
-	case OANDAND:
-	case OOROR:
-		boolgen(n, 1, nn);
-		if(nn == Z)
-			patch(p, pc);
-		break;
-
-	case ONOT:
-		if(nn == Z) {
-			nullwarn(l, Z);
-			break;
-		}
-		boolgen(n, 1, nn);
-		break;
-
-	case OCOMMA:
-		cgen(l, Z);
-		cgen(r, nn);
-		break;
-
-	case OCAST:
-		if(nn == Z) {
-			nullwarn(l, Z);
-			break;
-		}
-		/*
-		 * convert from types l->n->nn
-		 */
-		if(nocast(l->type, n->type)) {
-			if(nocast(n->type, nn->type)) {
-				cgen(l, nn);
-				break;
-			}
-		}
-		regalloc(&nod, l, nn);
-		cgen(l, &nod);
-		regalloc(&nod1, n, &nod);
-		if(inrel)
-			gmover(&nod, &nod1);
-		else
-			gopcode(OAS, &nod, Z, &nod1);
-		gopcode(OAS, &nod1, Z, nn);
-		regfree(&nod1);
-		regfree(&nod);
-		break;
-
-	case ODOT:
-		sugen(l, nodrat, l->type->width);
-		if(nn != Z) {
-			warn(n, "non-interruptable temporary");
-			nod = *nodrat;
-			if(!r || r->op != OCONST) {
-				diag(n, "DOT and no offset");
-				break;
-			}
-			nod.xoffset += (int32_t)r->vconst;
-			nod.type = n->type;
-			cgen(&nod, nn);
-		}
-		break;
-
-	case OCOND:
-		bcgen(l, 1);
-		p1 = p;
-		cgen(r->left, nn);
-		gbranch(OGOTO);
-		patch(p1, pc);
-		p1 = p;
-		cgen(r->right, nn);
-		patch(p1, pc);
-		break;
-
-	case OPOSTINC:
-	case OPOSTDEC:
-		v = 1;
-		if(l->type->etype == TIND)
-			v = l->type->link->width;
-		if(o == OPOSTDEC)
-			v = -v;
-		if(l->op == OBIT)
-			goto bitinc;
-		if(nn == Z)
-			goto pre;
-
-		if(l->addable < INDEXED)
-			reglcgen(&nod2, l, Z);
-		else
-			nod2 = *l;
-
-		regalloc(&nod, l, nn);
-		gopcode(OAS, &nod2, Z, &nod);
-		regalloc(&nod1, l, Z);
-		if(typefd[l->type->etype]) {
-			regalloc(&nod3, l, Z);
-			if(v < 0) {
-				gopcode(OAS, nodfconst(-v), Z, &nod3);
-				gopcode(OSUB, &nod3, &nod, &nod1);
-			} else {
-				gopcode(OAS, nodfconst(v), Z, &nod3);
-				gopcode(OADD, &nod3, &nod, &nod1);
-			}
-			regfree(&nod3);
-		} else
-			gopcode(OADD, nodconst(v), &nod, &nod1);
-		gopcode(OAS, &nod1, Z, &nod2);
-
-		regfree(&nod);
-		regfree(&nod1);
-		if(l->addable < INDEXED)
-			regfree(&nod2);
-		break;
-
-	case OPREINC:
-	case OPREDEC:
-		v = 1;
-		if(l->type->etype == TIND)
-			v = l->type->link->width;
-		if(o == OPREDEC)
-			v = -v;
-		if(l->op == OBIT)
-			goto bitinc;
-
-	pre:
-		if(l->addable < INDEXED)
-			reglcgen(&nod2, l, Z);
-		else
-			nod2 = *l;
-
-		regalloc(&nod, l, nn);
-		gopcode(OAS, &nod2, Z, &nod);
-		if(typefd[l->type->etype]) {
-			regalloc(&nod3, l, Z);
-			if(v < 0) {
-				gopcode(OAS, nodfconst(-v), Z, &nod3);
-				gopcode(OSUB, &nod3, Z, &nod);
-			} else {
-				gopcode(OAS, nodfconst(v), Z, &nod3);
-				gopcode(OADD, &nod3, Z, &nod);
-			}
-			regfree(&nod3);
-		} else
-			gopcode(OADD, nodconst(v), Z, &nod);
-		gopcode(OAS, &nod, Z, &nod2);
-		if(nn && l->op == ONAME)	/* in x=++i, emit USED(i) */
-			gins(ANOP, l, Z);
-
-		regfree(&nod);
-		if(l->addable < INDEXED)
-			regfree(&nod2);
-		break;
-
-	bitinc:
-		if(nn != Z && (o == OPOSTINC || o == OPOSTDEC)) {
-			bitload(l, &nod, &nod1, &nod2, Z);
-			gopcode(OAS, &nod, Z, nn);
-			gopcode(OADD, nodconst(v), Z, &nod);
-			bitstore(l, &nod, &nod1, &nod2, Z);
-			break;
-		}
-		bitload(l, &nod, &nod1, &nod2, nn);
-		gopcode(OADD, nodconst(v), Z, &nod);
-		bitstore(l, &nod, &nod1, &nod2, nn);
-		break;
-	}
-	cursafe = curs;
-	return;
-}
-
-void
-reglcgen(Node *t, Node *n, Node *nn)
-{
-	Node *r;
-	int32_t v;
-
-	regialloc(t, n, nn);
-	if(n->op == OIND) {
-		r = n->left;
-		while(r->op == OADD)
-			r = r->right;
-		if(sconst(r) && (v = r->vconst+t->xoffset) > -4096 && v < 4096) {
-			v = r->vconst;
-			r->vconst = 0;
-			lcgen(n, t);
-			t->xoffset += v;
-			r->vconst = v;
-			regind(t, n);
-			return;
-		}
-	} else if(n->op == OINDREG) {
-		if((v = n->xoffset) > -4096 && v < 4096) {
-			n->op = OREGISTER;
-			cgen(n, t);
-			t->xoffset += v;
-			n->op = OINDREG;
-			regind(t, n);
-			return;
-		}
-	}
-	lcgen(n, t);
-	regind(t, n);
-}
-
-void
-reglpcgen(Node *n, Node *nn, int f)
-{
-	Type *t;
-
-	t = nn->type;
-	nn->type = types[TLONG];
-	if(f)
-		reglcgen(n, nn, Z);
-	else {
-		regialloc(n, nn, Z);
-		lcgen(nn, n);
-		regind(n, nn);
-	}
-	nn->type = t;
-}
-
-void
-lcgen(Node *n, Node *nn)
-{
-	Prog *p1;
-	Node nod;
-
-	if(debug['g']) {
-		prtree(nn, "lcgen lhs");
-		prtree(n, "lcgen");
-	}
-	if(n == Z || n->type == T)
-		return;
-	if(nn == Z) {
-		nn = &nod;
-		regalloc(&nod, n, Z);
-	}
-	switch(n->op) {
-	default:
-		if(n->addable < INDEXED) {
-			diag(n, "unknown op in lcgen: %O", n->op);
-			break;
-		}
-		nod = *n;
-		nod.op = OADDR;
-		nod.left = n;
-		nod.right = Z;
-		nod.type = types[TIND];
-		gopcode(OAS, &nod, Z, nn);
-		break;
-
-	case OCOMMA:
-		cgen(n->left, n->left);
-		lcgen(n->right, nn);
-		break;
-
-	case OIND:
-		cgen(n->left, nn);
-		break;
-
-	case OCOND:
-		bcgen(n->left, 1);
-		p1 = p;
-		lcgen(n->right->left, nn);
-		gbranch(OGOTO);
-		patch(p1, pc);
-		p1 = p;
-		lcgen(n->right->right, nn);
-		patch(p1, pc);
-		break;
-	}
-}
-
-void
-bcgen(Node *n, int true)
-{
-
-	if(n->type == T)
-		gbranch(OGOTO);
-	else
-		boolgen(n, true, Z);
-}
-
-void
-boolgen(Node *n, int true, Node *nn)
-{
-	int o;
-	Prog *p1, *p2;
-	Node *l, *r, nod, nod1;
-	int32_t curs;
-
-	if(debug['g']) {
-		prtree(nn, "boolgen lhs");
-		prtree(n, "boolgen");
-	}
-	curs = cursafe;
-	l = n->left;
-	r = n->right;
-	switch(n->op) {
-
-	default:
-		regalloc(&nod, n, nn);
-		cgen(n, &nod);
-		o = ONE;
-		if(true)
-			o = comrel[relindex(o)];
-		if(typefd[n->type->etype]) {
-			gopcode(true ? o | BTRUE : o, nodfconst(0), &nod, Z);
-		} else
-			gopcode(o, nodconst(0), &nod, Z);
-		regfree(&nod);
-		goto com;
-
-	case OCONST:
-		o = vconst(n);
-		if(!true)
-			o = !o;
-		gbranch(OGOTO);
-		if(o) {
-			p1 = p;
-			gbranch(OGOTO);
-			patch(p1, pc);
-		}
-		goto com;
-
-	case OCOMMA:
-		cgen(l, Z);
-		boolgen(r, true, nn);
-		break;
-
-	case ONOT:
-		boolgen(l, !true, nn);
-		break;
-
-	case OCOND:
-		bcgen(l, 1);
-		p1 = p;
-		bcgen(r->left, true);
-		p2 = p;
-		gbranch(OGOTO);
-		patch(p1, pc);
-		p1 = p;
-		bcgen(r->right, !true);
-		patch(p2, pc);
-		p2 = p;
-		gbranch(OGOTO);
-		patch(p1, pc);
-		patch(p2, pc);
-		goto com;
-
-	case OANDAND:
-		if(!true)
-			goto caseor;
-
-	caseand:
-		bcgen(l, true);
-		p1 = p;
-		bcgen(r, !true);
-		p2 = p;
-		patch(p1, pc);
-		gbranch(OGOTO);
-		patch(p2, pc);
-		goto com;
-
-	case OOROR:
-		if(!true)
-			goto caseand;
-
-	caseor:
-		bcgen(l, !true);
-		p1 = p;
-		bcgen(r, !true);
-		p2 = p;
-		gbranch(OGOTO);
-		patch(p1, pc);
-		patch(p2, pc);
-		goto com;
-
-	case OEQ:
-	case ONE:
-	case OLE:
-	case OLT:
-	case OGE:
-	case OGT:
-	case OHI:
-	case OHS:
-	case OLO:
-	case OLS:
-		o = n->op;
-		if(true)
-			o = comrel[relindex(o)];
-		if(l->complex >= FNX && r->complex >= FNX) {
-			regret(&nod, r);
-			cgenrel(r, &nod, 1);
-			regsalloc(&nod1, r);
-			gopcode(OAS, &nod, Z, &nod1);
-			regfree(&nod);
-			nod = *n;
-			nod.right = &nod1;
-			boolgen(&nod, true, nn);
-			break;
-		}
-		if(sconst(l)) {
-			regalloc(&nod, r, nn);
-			cgenrel(r, &nod, 1);
-			o = invrel[relindex(o)];
-			gopcode(true ? o | BTRUE : o, l, &nod, Z);
-			regfree(&nod);
-			goto com;
-		}
-		if(sconst(r)) {
-			regalloc(&nod, l, nn);
-			cgenrel(l, &nod, 1);
-			gopcode(true ? o | BTRUE : o, r, &nod, Z);
-			regfree(&nod);
-			goto com;
-		}
-		if(l->complex >= r->complex) {
-			regalloc(&nod1, l, nn);
-			cgenrel(l, &nod1, 1);
-			regalloc(&nod, r, Z);
-			cgenrel(r, &nod, 1);
-		} else {
-			regalloc(&nod, r, nn);
-			cgenrel(r, &nod, 1);
-			regalloc(&nod1, l, Z);
-			cgenrel(l, &nod1, 1);
-		}
-		gopcode(true ? o | BTRUE : o, &nod, &nod1, Z);
-		regfree(&nod);
-		regfree(&nod1);
-
-	com:
-		if(nn != Z) {
-			p1 = p;
-			gopcode(OAS, nodconst(1), Z, nn);
-			gbranch(OGOTO);
-			p2 = p;
-			patch(p1, pc);
-			gopcode(OAS, nodconst(0), Z, nn);
-			patch(p2, pc);
-		}
-		break;
-	}
-	cursafe = curs;
-}
-
-void
-sugen(Node *n, Node *nn, int32_t w)
-{
-	Prog *p1;
-	Node nod0, nod1, nod2, nod3, nod4, *l, *r;
-	Type *t;
-	int32_t pc1;
-	int i, m, c;
-
-	if(n == Z || n->type == T)
-		return;
-	if(debug['g']) {
-		prtree(nn, "sugen lhs");
-		prtree(n, "sugen");
-	}
-	if(nn == nodrat)
-		if(w > nrathole)
-			nrathole = w;
-	switch(n->op) {
-	case OIND:
-		if(nn == Z) {
-			nullwarn(n->left, Z);
-			break;
-		}
-
-	default:
-		goto copy;
-
-	case OCONST:
-		if(n->type && typev[n->type->etype]) {
-			if(nn == Z) {
-				nullwarn(n->left, Z);
-				break;
-			}
-
-			t = nn->type;
-			nn->type = types[TLONG];
-			reglcgen(&nod1, nn, Z);
-			nn->type = t;
-
-			if(align(0, types[TCHAR], Aarg1))	/* isbigendian */
-				gopcode(OAS, nod32const(n->vconst>>32), Z, &nod1);
-			else
-				gopcode(OAS, nod32const(n->vconst), Z, &nod1);
-			nod1.xoffset += SZ_LONG;
-			if(align(0, types[TCHAR], Aarg1))	/* isbigendian */
-				gopcode(OAS, nod32const(n->vconst), Z, &nod1);
-			else
-				gopcode(OAS, nod32const(n->vconst>>32), Z, &nod1);
-
-			regfree(&nod1);
-			break;
-		}
-		goto copy;
-
-	case ODOT:
-		l = n->left;
-		sugen(l, nodrat, l->type->width);
-		if(nn != Z) {
-			warn(n, "non-interruptable temporary");
-			nod1 = *nodrat;
-			r = n->right;
-			if(!r || r->op != OCONST) {
-				diag(n, "DOT and no offset");
-				break;
-			}
-			nod1.xoffset += (int32_t)r->vconst;
-			nod1.type = n->type;
-			sugen(&nod1, nn, w);
-		}
-		break;
-
-	case OSTRUCT:
-		/*
-		 * rewrite so lhs has no fn call
-		 */
-		if(nn != Z && nn->complex >= FNX) {
-			nod1 = *n;
-			nod1.type = typ(TIND, n->type);
-			regret(&nod2, &nod1);
-			lcgen(nn, &nod2);
-			regsalloc(&nod0, &nod1);
-			gopcode(OAS, &nod2, Z, &nod0);
-			regfree(&nod2);
-
-			nod1 = *n;
-			nod1.op = OIND;
-			nod1.left = &nod0;
-			nod1.right = Z;
-			nod1.complex = 1;
-
-			sugen(n, &nod1, w);
-			return;
-		}
-
-		r = n->left;
-		for(t = n->type->link; t != T; t = t->down) {
-			l = r;
-			if(r->op == OLIST) {
-				l = r->left;
-				r = r->right;
-			}
-			if(nn == Z) {
-				cgen(l, nn);
-				continue;
-			}
-			/*
-			 * hand craft *(&nn + o) = l
-			 */
-			nod0 = znode;
-			nod0.op = OAS;
-			nod0.type = t;
-			nod0.left = &nod1;
-			nod0.right = l;
-
-			nod1 = znode;
-			nod1.op = OIND;
-			nod1.type = t;
-			nod1.left = &nod2;
-
-			nod2 = znode;
-			nod2.op = OADD;
-			nod2.type = typ(TIND, t);
-			nod2.left = &nod3;
-			nod2.right = &nod4;
-
-			nod3 = znode;
-			nod3.op = OADDR;
-			nod3.type = nod2.type;
-			nod3.left = nn;
-
-			nod4 = znode;
-			nod4.op = OCONST;
-			nod4.type = nod2.type;
-			nod4.vconst = t->offset;
-
-			ccom(&nod0);
-			acom(&nod0);
-			xcom(&nod0);
-			nod0.addable = 0;
-
-			cgen(&nod0, Z);
-		}
-		break;
-
-	case OAS:
-		if(nn == Z) {
-			if(n->addable < INDEXED)
-				sugen(n->right, n->left, w);
-			break;
-		}
-		sugen(n->right, nodrat, w);
-		warn(n, "non-interruptable temporary");
-		sugen(nodrat, n->left, w);
-		sugen(nodrat, nn, w);
-		break;
-
-	case OFUNC:
-		if(nn == Z) {
-			sugen(n, nodrat, w);
-			break;
-		}
-		if(nn->op != OIND) {
-			nn = new1(OADDR, nn, Z);
-			nn->type = types[TIND];
-			nn->addable = 0;
-		} else
-			nn = nn->left;
-		n = new(OFUNC, n->left, new(OLIST, nn, n->right));
-		n->type = types[TVOID];
-		n->left->type = types[TVOID];
-		cgen(n, Z);
-		break;
-
-	case OCOND:
-		bcgen(n->left, 1);
-		p1 = p;
-		sugen(n->right->left, nn, w);
-		gbranch(OGOTO);
-		patch(p1, pc);
-		p1 = p;
-		sugen(n->right->right, nn, w);
-		patch(p1, pc);
-		break;
-
-	case OCOMMA:
-		cgen(n->left, Z);
-		sugen(n->right, nn, w);
-		break;
-	}
-	return;
-
-copy:
-	if(nn == Z)
-		return;
-	if(n->complex >= FNX && nn->complex >= FNX) {
-		t = nn->type;
-		nn->type = types[TLONG];
-		regialloc(&nod1, nn, Z);
-		lcgen(nn, &nod1);
-		regsalloc(&nod2, nn);
-		nn->type = t;
-
-		gopcode(OAS, &nod1, Z, &nod2);
-		regfree(&nod1);
-
-		nod2.type = typ(TIND, t);
-
-		nod1 = nod2;
-		nod1.op = OIND;
-		nod1.left = &nod2;
-		nod1.right = Z;
-		nod1.complex = 1;
-		nod1.type = t;
-
-		sugen(n, &nod1, w);
-		return;
-	}
-
-	w /= SZ_LONG;
-	if(w <= 2) {
-		if(n->complex > nn->complex) {
-			reglpcgen(&nod1, n, 1);
-			reglpcgen(&nod2, nn, 1);
-		} else {
-			reglpcgen(&nod2, nn, 1);
-			reglpcgen(&nod1, n, 1);
-		}
-		regalloc(&nod3, &regnode, Z);
-		regalloc(&nod4, &regnode, Z);
-		if(nod3.reg > nod4.reg){
-			/* code below assumes nod3 loaded first */
-			Node t = nod3; nod3 = nod4; nod4 = t;
-		}
-		nod0 = *nodconst((1<<nod3.reg)|(1<<nod4.reg));
-		if(w == 2 && nod1.xoffset == 0)
-			gmovm(&nod1, &nod0, 0);
-		else {
-			gmove(&nod1, &nod3);
-			if(w == 2) {
-				nod1.xoffset += SZ_LONG;
-				gmove(&nod1, &nod4);
-			}
-		}
-		if(w == 2 && nod2.xoffset == 0)
-			gmovm(&nod0, &nod2, 0);
-		else {
-			gmove(&nod3, &nod2);
-			if(w == 2) {
-				nod2.xoffset += SZ_LONG;
-				gmove(&nod4, &nod2);
-			}
-		}
-		regfree(&nod1);
-		regfree(&nod2);
-		regfree(&nod3);
-		regfree(&nod4);
-		return;
-	}
-
-	if(n->complex > nn->complex) {
-		reglpcgen(&nod1, n, 0);
-		reglpcgen(&nod2, nn, 0);
-	} else {
-		reglpcgen(&nod2, nn, 0);
-		reglpcgen(&nod1, n, 0);
-	}
-
-	m = 0;
-	for(c = 0; c < w && c < 4; c++) {
-		i = tmpreg();
-		if (i == 0)
-			break;
-		reg[i]++;
-		m |= 1<<i;
-	}
-	nod4 = *(nodconst(m));
-	if(w < 3*c) {
-		for (; w>c; w-=c) {
-			gmovm(&nod1, &nod4, 1);
-			gmovm(&nod4, &nod2, 1);
-		}
-		goto out;
-	}
-
-	regalloc(&nod3, &regnode, Z);
-	gopcode(OAS, nodconst(w/c), Z, &nod3);
-	w %= c;
-	
-	pc1 = pc;
-	gmovm(&nod1, &nod4, 1);
-	gmovm(&nod4, &nod2, 1);
-
-	gopcode(OSUB, nodconst(1), Z, &nod3);
-	gopcode(OEQ, nodconst(0), &nod3, Z);
-	p->as = ABGT;
-	patch(p, pc1);
-	regfree(&nod3);
-
-out:
-	if (w) {
-		i = 0;
-		while (c>w) {
-			while ((m&(1<<i)) == 0)
-				i++;
-			m &= ~(1<<i);
-			reg[i] = 0;
-			c--;
-			i++;
-		}
-		nod4.vconst = m;
-		gmovm(&nod1, &nod4, 0);
-		gmovm(&nod4, &nod2, 0);
-	}
-	i = 0;
-	do {
-		while ((m&(1<<i)) == 0)
-			i++;
-		reg[i] = 0;
-		c--;
-		i++;
-	} while (c>0);
-	regfree(&nod1);
-	regfree(&nod2);
-}

+ 0 - 113
sys/src/cmd/5c/enam.c

@@ -1,113 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-char*	anames[] =
-{
-	"XXX",
-	"AND",
-	"EOR",
-	"SUB",
-	"RSB",
-	"ADD",
-	"ADC",
-	"SBC",
-	"RSC",
-	"TST",
-	"TEQ",
-	"CMP",
-	"CMN",
-	"ORR",
-	"BIC",
-	"MVN",
-	"B",
-	"BL",
-	"BEQ",
-	"BNE",
-	"BCS",
-	"BHS",
-	"BCC",
-	"BLO",
-	"BMI",
-	"BPL",
-	"BVS",
-	"BVC",
-	"BHI",
-	"BLS",
-	"BGE",
-	"BLT",
-	"BGT",
-	"BLE",
-	"MOVWD",
-	"MOVWF",
-	"MOVDW",
-	"MOVFW",
-	"MOVFD",
-	"MOVDF",
-	"MOVF",
-	"MOVD",
-	"CMPF",
-	"CMPD",
-	"ADDF",
-	"ADDD",
-	"SUBF",
-	"SUBD",
-	"MULF",
-	"MULD",
-	"DIVF",
-	"DIVD",
-	"SRL",
-	"SRA",
-	"SLL",
-	"MULU",
-	"DIVU",
-	"MUL",
-	"DIV",
-	"MOD",
-	"MODU",
-	"MOVB",
-	"MOVBU",
-	"MOVH",
-	"MOVHU",
-	"MOVW",
-	"MOVM",
-	"SWPBU",
-	"SWPW",
-	"NOP",
-	"RFE",
-	"SWI",
-	"MULA",
-	"DATA",
-	"GLOBL",
-	"GOK",
-	"HISTORY",
-	"NAME",
-	"RET",
-	"TEXT",
-	"WORD",
-	"DYNT",
-	"INIT",
-	"BCASE",
-	"CASE",
-	"END",
-	"MULL",
-	"MULAL",
-	"MULLU",
-	"MULALU",
-	"BX",
-	"BXRET",
-	"DWORD",
-	"SIGNAME",
-	"SQRTF",
-	"SQRTD",
-	"LDREX",
-	"STREX",
-	"LDREXD",
-	"STREXD",
-	"LAST",
-};

+ 0 - 361
sys/src/cmd/5c/gc.h

@@ -1,361 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include	"../cc/cc.h"
-#include	"../5c/5.out.h"
-
-/*
- * 5c/arm
- * Arm
- */
-#define	SZ_CHAR		1
-#define	SZ_SHORT	2
-#define	SZ_INT		4
-#define	SZ_LONG		4
-#define	SZ_IND		4
-#define	SZ_FLOAT	4
-#define	SZ_VLONG	8
-#define	SZ_DOUBLE	8
-#define	FNX		100
-#define	BTRUE		0x1000
-
-typedef	struct	Adr	Adr;
-typedef	struct	Prog	Prog;
-typedef	struct	Case	Case;
-typedef	struct	C1	C1;
-typedef	struct	Multab	Multab;
-typedef	struct	Hintab	Hintab;
-typedef	struct	Var	Var;
-typedef	struct	Reg	Reg;
-typedef	struct	Rgn	Rgn;
-
-
-#define	R0ISZERO	0
-
-struct	Adr
-{
-	long	offset;
-	double	dval;
-	char	sval[NSNAME];
-	Ieee	ieee;
-
-	Sym*	sym;
-	char	type;
-	char	reg;
-	char	name;
-	char	etype;
-};
-#define	A	((Adr*)0)
-
-#define	INDEXED	9
-struct	Prog
-{
-	Adr	from;
-	Adr	to;
-	Prog*	link;
-	long	lineno;
-	char	as;
-	char	reg;
-	uchar	scond;
-};
-#define	P	((Prog*)0)
-
-struct	Case
-{
-	Case*	link;
-	vlong	val;
-	long	label;
-	char	def;
-	char isv;
-};
-#define	C	((Case*)0)
-
-struct	C1
-{
-	vlong	val;
-	long	label;
-};
-
-struct	Multab
-{
-	long	val;
-	char	code[20];
-};
-
-struct	Hintab
-{
-	ushort	val;
-	char	hint[10];
-};
-
-struct	Var
-{
-	long	offset;
-	Sym*	sym;
-	char	name;
-	char	etype;
-};
-
-struct	Reg
-{
-	long	pc;
-	long	rpo;		/* reverse post ordering */
-
-	Bits	set;
-	Bits	use1;
-	Bits	use2;
-
-	Bits	refbehind;
-	Bits	refahead;
-	Bits	calbehind;
-	Bits	calahead;
-	Bits	regdiff;
-	Bits	act;
-
-	long	regu;
-	long	loop;		/* could be shorter */
-
-	
-	Reg*	log5;
-	long	active;
-
-	Reg*	p1;
-	Reg*	p2;
-	Reg*	p2link;
-	Reg*	s1;
-	Reg*	s2;
-	Reg*	link;
-	Prog*	prog;
-};
-#define	R	((Reg*)0)
-
-#define	NRGN	1000		/* was 600; raised for paranoia.c */
-struct	Rgn
-{
-	Reg*	enter;
-	short	cost;
-	short	varno;
-	short	regno;
-};
-
-EXTERN	long	breakpc;
-EXTERN	long	nbreak;
-EXTERN	Case*	cases;
-EXTERN	Node	constnode;
-EXTERN	Node	fconstnode;
-EXTERN	long	continpc;
-EXTERN	long	curarg;
-EXTERN	long	cursafe;
-EXTERN	Prog*	firstp;
-EXTERN	Prog*	lastp;
-EXTERN	long	maxargsafe;
-EXTERN	int	mnstring;
-EXTERN	Multab	multab[20];
-EXTERN	int	hintabsize;
-EXTERN	Node*	nodrat;
-EXTERN	Node*	nodret;
-EXTERN	Node*	nodsafe;
-EXTERN	long	nrathole;
-EXTERN	long	nstring;
-EXTERN	Prog*	p;
-EXTERN	long	pc;
-EXTERN	Node	regnode;
-EXTERN	char	string[NSNAME];
-EXTERN	Sym*	symrathole;
-EXTERN	Node	znode;
-EXTERN	Prog	zprog;
-EXTERN	char	reg[NREG+NFREG];
-EXTERN	long	exregoffset;
-EXTERN	long	exfregoffset;
-EXTERN	int	suppress;
-
-#define	BLOAD(r)	band(bnot(r->refbehind), r->refahead)
-#define	BSTORE(r)	band(bnot(r->calbehind), r->calahead)
-#define	LOAD(r)		(~r->refbehind.b[z] & r->refahead.b[z])
-#define	STORE(r)	(~r->calbehind.b[z] & r->calahead.b[z])
-
-#define	bset(a,n)	((a).b[(n)/32]&(1L<<(n)%32))
-
-#define	CLOAD	4
-#define	CREF	5
-#define	CINF	1000
-#define	LOOP	3
-
-EXTERN	Rgn	region[NRGN];
-EXTERN	Rgn*	rgp;
-EXTERN	int	nregion;
-EXTERN	int	nvar;
-
-EXTERN	Bits	externs;
-EXTERN	Bits	params;
-EXTERN	Bits	consts;
-EXTERN	Bits	addrs;
-
-EXTERN	long	regbits;
-EXTERN	long	exregbits;
-
-EXTERN	int	change;
-
-EXTERN	Reg*	firstr;
-EXTERN	Reg*	lastr;
-EXTERN	Reg	zreg;
-EXTERN	Reg*	freer;
-EXTERN	Var	var[NVAR];
-EXTERN	long*	idom;
-EXTERN	Reg**	rpo2r;
-EXTERN	long	maxnr;
-
-extern	char*	anames[];
-extern	Hintab	hintab[];
-
-/*
- * sgen.c
- */
-void	codgen(Node*, Node*);
-void	gen(Node*);
-void	noretval(int);
-void	usedset(Node*, int);
-void	xcom(Node*);
-int	bcomplex(Node*, Node*);
-
-/*
- * cgen.c
- */
-void	cgen(Node*, Node*);
-void	cgenrel(Node*, Node*, int);
-void	reglcgen(Node*, Node*, Node*);
-void	lcgen(Node*, Node*);
-void	bcgen(Node*, int);
-void	boolgen(Node*, int, Node*);
-void	sugen(Node*, Node*, long);
-void	layout(Node*, Node*, int, int, Node*);
-
-/*
- * txt.c
- */
-void	ginit(void);
-void	gclean(void);
-void	nextpc(void);
-void	gargs(Node*, Node*, Node*);
-void	garg1(Node*, Node*, Node*, int, Node**);
-Node*	nodconst(long);
-Node*	nod32const(vlong);
-Node*	nodfconst(double);
-void	nodreg(Node*, Node*, int);
-void	regret(Node*, Node*);
-int	tmpreg(void);
-void	regalloc(Node*, Node*, Node*);
-void	regfree(Node*);
-void	regialloc(Node*, Node*, Node*);
-void	regsalloc(Node*, Node*);
-void	regaalloc1(Node*, Node*);
-void	regaalloc(Node*, Node*);
-void	regind(Node*, Node*);
-void	gprep(Node*, Node*);
-void	raddr(Node*, Prog*);
-void	naddr(Node*, Adr*);
-void	gmovm(Node*, Node*, int);
-void	gmove(Node*, Node*);
-void	gmover(Node*, Node*);
-void	gins(int a, Node*, Node*);
-void	gopcode(int, Node*, Node*, Node*);
-int	samaddr(Node*, Node*);
-void	gbranch(int);
-void	patch(Prog*, long);
-int	sconst(Node*);
-int	sval(long);
-void	gpseudo(int, Sym*, Node*);
-
-/*
- * swt.c
- */
-int	swcmp(const void*, const void*);
-void	doswit(Node*);
-void	swit1(C1*, int, long, Node*);
-void	swit2(C1*, int, long, Node*, Node*);
-void	casf(void);
-void	bitload(Node*, Node*, Node*, Node*, Node*);
-void	bitstore(Node*, Node*, Node*, Node*, Node*);
-long	outstring(char*, long);
-int	mulcon(Node*, Node*);
-Multab*	mulcon0(long);
-void	nullwarn(Node*, Node*);
-void	gextern(Sym*, Node*, long, long);
-void	outcode(void);
-void	ieeedtod(Ieee*, double);
-
-/*
- * list
- */
-void	listinit(void);
-int	Pconv(Fmt*);
-int	Aconv(Fmt*);
-int	Dconv(Fmt*);
-int	Sconv(Fmt*);
-int	Nconv(Fmt*);
-int	Bconv(Fmt*);
-int	Rconv(Fmt*);
-
-/*
- * reg.c
- */
-Reg*	rega(void);
-int	rcmp(const void*, const void*);
-void	regopt(Prog*);
-void	addmove(Reg*, int, int, int);
-Bits	mkvar(Adr*, int);
-void	prop(Reg*, Bits, Bits);
-void	loopit(Reg*, long);
-void	synch(Reg*, Bits);
-uint32_t	allreg(uint32_t, Rgn*);
-void	paint1(Reg*, int);
-uint32_t	paint2(Reg*, int);
-void	paint3(Reg*, int, long, int);
-void	addreg(Adr*, int);
-
-/*
- * peep.c
- */
-void	peep(void);
-void	excise(Reg*);
-Reg*	uniqp(Reg*);
-Reg*	uniqs(Reg*);
-int	regtyp(Adr*);
-int	regzer(Adr*);
-int	anyvar(Adr*);
-int	subprop(Reg*);
-int	copyprop(Reg*);
-int	shiftprop(Reg*);
-void	constprop(Adr*, Adr*, Reg*);
-int	copy1(Adr*, Adr*, Reg*, int);
-int	copyu(Prog*, Adr*, Adr*);
-
-int	copyas(Adr*, Adr*);
-int	copyau(Adr*, Adr*);
-int	copyau1(Prog*, Adr*);
-int	copysub(Adr*, Adr*, Adr*, int);
-int	copysub1(Prog*, Adr*, Adr*, int);
-
-long	RtoB(int);
-long	FtoB(int);
-int	BtoR(long);
-int	BtoF(long);
-
-void	predicate(void); 
-int	isbranch(Prog *); 
-int	predicable(Prog *p); 
-int	modifiescpsr(Prog *p); 
-
-#pragma	varargck	type	"A"	int
-#pragma	varargck	type	"B"	Bits
-#pragma	varargck	type	"D"	Adr*
-#pragma	varargck	type	"N"	Adr*
-#pragma	varargck	type	"R"	Adr*
-#pragma	varargck	type	"P"	Prog*
-#pragma	varargck	type	"S"	char*

+ 0 - 313
sys/src/cmd/5c/list.c

@@ -1,313 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#define	EXTERN
-#include "gc.h"
-
-void
-listinit(void)
-{
-
-	fmtinstall('A', Aconv);
-	fmtinstall('P', Pconv);
-	fmtinstall('S', Sconv);
-	fmtinstall('N', Nconv);
-	fmtinstall('B', Bconv);
-	fmtinstall('D', Dconv);
-	fmtinstall('R', Rconv);
-}
-
-int
-Bconv(Fmt *fp)
-{
-	char str[STRINGSZ], ss[STRINGSZ], *s;
-	Bits bits;
-	int i;
-
-	str[0] = 0;
-	bits = va_arg(fp->args, Bits);
-	while(bany(&bits)) {
-		i = bnum(bits);
-		if(str[0])
-			strcat(str, " ");
-		if(var[i].sym == S) {
-			snprint(ss, sizeof(ss), "$%ld", var[i].offset);
-			s = ss;
-		} else
-			s = var[i].sym->name;
-		if(strlen(str) + strlen(s) + 1 >= STRINGSZ)
-			break;
-		strcat(str, s);
-		bits.b[i/32] &= ~(1L << (i%32));
-	}
-	return fmtstrcpy(fp, str);
-}
-
-char *extra [] = {
-	".EQ", ".NE", ".CS", ".CC", 
-	".MI", ".PL", ".VS", ".VC", 
-	".HI", ".LS", ".GE", ".LT", 
-	".GT", ".LE", "", ".NV",
-};
-
-int
-Pconv(Fmt *fp)
-{
-	char str[STRINGSZ], sc[20];
-	Prog *p;
-	int a, s;
-
-	p = va_arg(fp->args, Prog*);
-	a = p->as;
-	s = p->scond; 
-	strcpy(sc, extra[s & C_SCOND]);
-	if(s & C_SBIT)
-		strcat(sc, ".S");
-	if(s & C_PBIT)
-		strcat(sc, ".P");
-	if(s & C_WBIT)
-		strcat(sc, ".W");
-	if(s & C_UBIT)		/* ambiguous with FBIT */
-		strcat(sc, ".U");
-	if(a == AMOVM) {
-		if(p->from.type == D_CONST)
-			snprint(str, sizeof(str), "	%A%s	%R,%D", a, sc, &p->from, &p->to);
-		else
-		if(p->to.type == D_CONST)
-			snprint(str, sizeof(str), "	%A%s	%D,%R", a, sc, &p->from, &p->to);
-		else
-			snprint(str, sizeof(str), "	%A%s	%D,%D", a, sc, &p->from, &p->to);
-	} else
-	if(a == ADATA)
-		snprint(str, sizeof(str), "	%A	%D/%d,%D", a, &p->from, p->reg, &p->to);
-	else
-	if(p->as == ATEXT)
-		snprint(str, sizeof(str), "	%A	%D,%d,%D", a, &p->from, p->reg, &p->to);
-	else
-	if(p->reg == NREG)
-		snprint(str, sizeof(str), "	%A%s	%D,%D", a, sc, &p->from, &p->to);
-	else
-	if(p->from.type != D_FREG)
-		snprint(str, sizeof(str), "	%A%s	%D,R%d,%D", a, sc, &p->from, p->reg, &p->to);
-	else
-		snprint(str, sizeof(str), "	%A%s	%D,F%d,%D", a, sc, &p->from, p->reg, &p->to);
-	return fmtstrcpy(fp, str);
-}
-
-int
-Aconv(Fmt *fp)
-{
-	char *s;
-	int a;
-
-	a = va_arg(fp->args, int);
-	s = "???";
-	if(a >= AXXX && a < ALAST)
-		s = anames[a];
-	return fmtstrcpy(fp, s);
-}
-
-int
-Dconv(Fmt *fp)
-{
-	char str[STRINGSZ];
-	Adr *a;
-	char *op;
-	int v;
-
-	a = va_arg(fp->args, Adr*);
-	switch(a->type) {
-
-	default:
-		snprint(str, sizeof(str), "GOK-type(%d)", a->type);
-		break;
-
-	case D_NONE:
-		str[0] = 0;
-		if(a->name != D_NONE || a->reg != NREG || a->sym != S)
-			snprint(str, sizeof(str), "%N(R%d)(NONE)", a, a->reg);
-		break;
-
-	case D_CONST:
-		if(a->reg != NREG)
-			snprint(str, sizeof(str), "$%N(R%d)", a, a->reg);
-		else
-			snprint(str, sizeof(str), "$%N", a);
-		break;
-
-	case D_SHIFT:
-		v = a->offset;
-		op = "<<>>->@>" + (((v>>5) & 3) << 1);
-		if(v & (1<<4))
-			snprint(str, sizeof(str), "R%d%c%cR%d", v&15, op[0], op[1], (v>>8)&15);
-		else
-			snprint(str, sizeof(str), "R%d%c%c%d", v&15, op[0], op[1], (v>>7)&31);
-		if(a->reg != NREG)
-			sprint(str+strlen(str), "(R%d)", a->reg);
-		break;
-
-	case D_OREG:
-		if(a->reg != NREG)
-			snprint(str, sizeof(str), "%N(R%d)", a, a->reg);
-		else
-			snprint(str, sizeof(str), "%N", a);
-		break;
-
-	case D_REG:
-		snprint(str, sizeof(str), "R%d", a->reg);
-		if(a->name != D_NONE || a->sym != S)
-			snprint(str, sizeof(str), "%N(R%d)(REG)", a, a->reg);
-		break;
-
-	case D_FREG:
-		snprint(str, sizeof(str), "F%d", a->reg);
-		if(a->name != D_NONE || a->sym != S)
-			snprint(str, sizeof(str), "%N(R%d)(REG)", a, a->reg);
-		break;
-
-	case D_PSR:
-		snprint(str, sizeof(str), "PSR");
-		if(a->name != D_NONE || a->sym != S)
-			snprint(str, sizeof(str), "%N(PSR)(REG)", a);
-		break;
-
-	case D_BRANCH:
-		snprint(str, sizeof(str), "%ld(PC)", a->offset-pc);
-		break;
-
-	case D_FCONST:
-		snprint(str, sizeof(str), "$%.17e", a->dval);
-		break;
-
-	case D_SCONST:
-		snprint(str, sizeof(str), "$\"%S\"", a->sval);
-		break;
-	}
-	return fmtstrcpy(fp, str);
-}
-
-int
-Rconv(Fmt *fp)
-{
-	char str[STRINGSZ], *p, *e;
-	Adr *a;
-	int i, v;
-
-	a = va_arg(fp->args, Adr*);
-	snprint(str, sizeof(str), "GOK-reglist");
-	switch(a->type) {
-	case D_CONST:
-		if(a->reg != NREG)
-			break;
-		if(a->sym != S)
-			break;
-		v = a->offset;
-		p = str;
-		e = str+sizeof(str);
-		for(i=0; i<NREG; i++) {
-			if(v & (1<<i)) {
-				if(p == str)
-					p = seprint(p, e, "[R%d", i);
-				else
-					p = seprint(p, e, ",R%d", i);
-			}
-		}
-		seprint(p, e, "]");
-	}
-	return fmtstrcpy(fp, str);
-}
-
-int
-Sconv(Fmt *fp)
-{
-	int i, c;
-	char str[STRINGSZ], *p, *a;
-
-	a = va_arg(fp->args, char*);
-	p = str;
-	for(i=0; i<NSNAME; i++) {
-		c = a[i] & 0xff;
-		if(c >= 'a' && c <= 'z' ||
-		   c >= 'A' && c <= 'Z' ||
-		   c >= '0' && c <= '9' ||
-		   c == ' ' || c == '%') {
-			*p++ = c;
-			continue;
-		}
-		*p++ = '\\';
-		switch(c) {
-		case 0:
-			*p++ = 'z';
-			continue;
-		case '\\':
-		case '"':
-			*p++ = c;
-			continue;
-		case '\n':
-			*p++ = 'n';
-			continue;
-		case '\t':
-			*p++ = 't';
-			continue;
-		case '\r':
-			*p++ = 'r';
-			continue;
-		case '\f':
-			*p++ = 'f';
-			continue;
-		}
-		*p++ = (c>>6) + '0';
-		*p++ = ((c>>3) & 7) + '0';
-		*p++ = (c & 7) + '0';
-	}
-	*p = 0;
-	return fmtstrcpy(fp, str);
-}
-
-int
-Nconv(Fmt *fp)
-{
-	char str[STRINGSZ];
-	Adr *a;
-	Sym *s;
-
-	a = va_arg(fp->args, Adr*);
-	s = a->sym;
-	if(s == S) {
-		snprint(str, sizeof(str), "%ld", a->offset);
-		goto out;
-	}
-	switch(a->name) {
-	default:
-		snprint(str, sizeof(str), "GOK-name(%d)", a->name);
-		break;
-
-	case D_NONE:
-		snprint(str, sizeof(str), "%ld", a->offset);
-		break;
-
-	case D_EXTERN:
-		snprint(str, sizeof(str), "%s+%ld(SB)", s->name, a->offset);
-		break;
-
-	case D_STATIC:
-		snprint(str, sizeof(str), "%s<>+%ld(SB)", s->name, a->offset);
-		break;
-
-	case D_AUTO:
-		snprint(str, sizeof(str), "%s-%ld(SP)", s->name, -a->offset);
-		break;
-
-	case D_PARAM:
-		snprint(str, sizeof(str), "%s+%ld(FP)", s->name, a->offset);
-		break;
-	}
-out:
-	return fmtstrcpy(fp, str);
-}

+ 0 - 15
sys/src/cmd/5c/mkenam

@@ -1,15 +0,0 @@
-ed - ../5c/5.out.h <<'!'
-v/^	A/d
-,s/^	A/	"/
-g/ .*$/s///
-,s/,*$/",/
-1i
-char*	anames[] =
-{
-.
-$a
-};
-.
-w enam.c
-Q
-!

+ 0 - 41
sys/src/cmd/5c/mkfile

@@ -1,41 +0,0 @@
-</$objtype/mkfile
-
-TARG=5c
-OFILES=\
-	cgen.$O\
-	enam.$O\
-	list.$O\
-	mul.$O\
-	peep.$O\
-	pgen.$O\
-	pswt.$O\
-	reg.$O\
-	sgen.$O\
-	swt.$O\
-	txt.$O\
-
-HFILES=\
-	gc.h\
-	5.out.h\
-	../cc/cc.h\
-
-LIB=../cc/cc.a$O
-
-BIN=/$objtype/bin
-</sys/src/cmd/mkone
-
-$LIB:
-	cd ../cc
-	mk install
-	mk clean
-
-%.$O: ../cc/%.c
-	$CC $CFLAGS ../cc/$stem.c
-
-t:V:	$O.out
-	$O.out -S t
-	$LD -o t.out t.$O
-	t.out
-
-enam.c: 5.out.h
-	rc mkenam

+ 0 - 618
sys/src/cmd/5c/mul.c

@@ -1,618 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "gc.h"
-
-/*
- * code sequences for multiply by constant.
- * [a-l][0-3]
- *	lsl	$(A-'a'),r0,r1
- * [+][0-7]
- *	add	r0,r1,r2
- * [-][0-7]
- *	sub	r0,r1,r2
- */
-
-static  int	maxmulops = 3;	/* max # of ops to replace mul with */
-static	int	multabp;
-static	int32_t	mulval;
-static	char*	mulcp;
-static	int32_t	valmax;
-static	int	shmax;
-
-static int	docode(char *hp, char *cp, int r0, int r1);
-static int	gen1(int len);
-static int	gen2(int len, int32_t r1);
-static int	gen3(int len, int32_t r0, int32_t r1, int flag);
-enum
-{
-	SR1	= 1<<0,		/* r1 has been shifted */
-	SR0	= 1<<1,		/* r0 has been shifted */
-	UR1	= 1<<2,		/* r1 has not been used */
-	UR0	= 1<<3,		/* r0 has not been used */
-};
-
-Multab*
-mulcon0(int32_t v)
-{
-	int a1, a2, g;
-	Multab *m, *m1;
-	char hint[10];
-
-	if(v < 0)
-		v = -v;
-
-	/*
-	 * look in cache
-	 */
-	m = multab;
-	for(g=0; g<nelem(multab); g++) {
-		if(m->val == v) {
-			if(m->code[0] == 0)
-				return 0;
-			return m;
-		}
-		m++;
-	}
-
-	/*
-	 * select a spot in cache to overwrite
-	 */
-	multabp++;
-	if(multabp < 0 || multabp >= nelem(multab))
-		multabp = 0;
-	m = multab+multabp;
-	m->val = v;
-	mulval = v;
-
-	/*
-	 * look in execption hint table
-	 */
-	a1 = 0;
-	a2 = hintabsize;
-	for(;;) {
-		if(a1 >= a2)
-			goto no;
-		g = (a2 + a1)/2;
-		if(v < hintab[g].val) {
-			a2 = g;
-			continue;
-		}
-		if(v > hintab[g].val) {
-			a1 = g+1;
-			continue;
-		}
-		break;
-	}
-
-	if(docode(hintab[g].hint, m->code, 1, 0))
-		return m;
-	print("multiply table failure %ld\n", v);
-	m->code[0] = 0;
-	return 0;
-
-no:
-	/*
-	 * try to search
-	 */
-	hint[0] = 0;
-	for(g=1; g<=maxmulops; g++) {
-		if(g >= maxmulops && v >= 65535)
-			break;
-		mulcp = hint+g;
-		*mulcp = 0;
-		if(gen1(g)) {
-			if(docode(hint, m->code, 1, 0))
-				return m;
-			print("multiply table failure %ld\n", v);
-			break;
-		}
-	}
-
-	/*
-	 * try a recur followed by a shift
-	 */
-	g = 0;
-	while(!(v & 1)) {
-		g++;
-		v >>= 1;
-	}
-	if(g) {
-		m1 = mulcon0(v);
-		if(m1) {
-			strcpy(m->code, m1->code);
-			sprint(strchr(m->code, 0), "%c0", g+'a');
-			return m;
-		}
-	}
-	m->code[0] = 0;
-	return 0;
-}
-
-static int
-docode(char *hp, char *cp, int r0, int r1)
-{
-	int c, i;
-
-	c = *hp++;
-	*cp = c;
-	cp += 2;
-	switch(c) {
-	default:
-		c -= 'a';
-		if(c < 1 || c >= 30)
-			break;
-		for(i=0; i<4; i++) {
-			switch(i) {
-			case 0:
-				if(docode(hp, cp, r0<<c, r1))
-					goto out;
-				break;
-			case 1:
-				if(docode(hp, cp, r1<<c, r1))
-					goto out;
-				break;
-			case 2:
-				if(docode(hp, cp, r0, r0<<c))
-					goto out;
-				break;
-			case 3:
-				if(docode(hp, cp, r0, r1<<c))
-					goto out;
-				break;
-			}
-		}
-		break;
-
-	case '+':
-		for(i=0; i<8; i++) {
-			cp[-1] = i+'0';
-			switch(i) {
-			case 1:
-				if(docode(hp, cp, r0+r1, r1))
-					goto out;
-				break;
-			case 5:
-				if(docode(hp, cp, r0, r0+r1))
-					goto out;
-				break;
-			}
-		}
-		break;
-
-	case '-':
-		for(i=0; i<8; i++) {
-			cp[-1] = i+'0';
-			switch(i) {
-			case 1:
-				if(docode(hp, cp, r0-r1, r1))
-					goto out;
-				break;
-			case 2:
-				if(docode(hp, cp, r1-r0, r1))
-					goto out;
-				break;
-			case 5:
-				if(docode(hp, cp, r0, r0-r1))
-					goto out;
-				break;
-			case 6:
-				if(docode(hp, cp, r0, r1-r0))
-					goto out;
-				break;
-			}
-		}
-		break;
-
-	case 0:
-		if(r0 == mulval)
-			return 1;
-	}
-	return 0;
-
-out:
-	cp[-1] = i+'0';
-	return 1;
-}
-
-static int
-gen1(int len)
-{
-	int i;
-
-	for(shmax=1; shmax<30; shmax++) {
-		valmax = 1<<shmax;
-		if(valmax >= mulval)
-			break;
-	}
-	if(mulval == 1)
-		return 1;
-
-	len--;
-	for(i=1; i<=shmax; i++)
-		if(gen2(len, 1<<i)) {
-			*--mulcp = 'a'+i;
-			return 1;
-		}
-	return 0;
-}
-
-static int
-gen2(int len, int32_t r1)
-{
-	int i;
-
-	if(len <= 0) {
-		if(r1 == mulval)
-			return 1;
-		return 0;
-	}
-
-	len--;
-	if(len == 0)
-		goto calcr0;
-
-	if(gen3(len, r1, r1+1, UR1)) {
-		i = '+';
-		goto out;
-	}
-	if(gen3(len, r1-1, r1, UR0)) {
-		i = '-';
-		goto out;
-	}
-	if(gen3(len, 1, r1+1, UR1)) {
-		i = '+';
-		goto out;
-	}
-	if(gen3(len, 1, r1-1, UR1)) {
-		i = '-';
-		goto out;
-	}
-
-	return 0;
-
-calcr0:
-	if(mulval == r1+1) {
-		i = '+';
-		goto out;
-	}
-	if(mulval == r1-1) {
-		i = '-';
-		goto out;
-	}
-	return 0;
-
-out:
-	*--mulcp = i;
-	return 1;
-}
-
-static int
-gen3(int len, int32_t r0, int32_t r1, int flag)
-{
-	int i, f1, f2;
-	int32_t x;
-
-	if(r0 <= 0 ||
-	   r0 >= r1 ||
-	   r1 > valmax)
-		return 0;
-
-	len--;
-	if(len == 0)
-		goto calcr0;
-
-	if(!(flag & UR1)) {
-		f1 = UR1|SR1;
-		for(i=1; i<=shmax; i++) {
-			x = r0<<i;
-			if(x > valmax)
-				break;
-			if(gen3(len, r0, x, f1)) {
-				i += 'a';
-				goto out;
-			}
-		}
-	}
-
-	if(!(flag & UR0)) {
-		f1 = UR1|SR1;
-		for(i=1; i<=shmax; i++) {
-			x = r1<<i;
-			if(x > valmax)
-				break;
-			if(gen3(len, r1, x, f1)) {
-				i += 'a';
-				goto out;
-			}
-		}
-	}
-
-	if(!(flag & SR1)) {
-		f1 = UR1|SR1|(flag&UR0);
-		for(i=1; i<=shmax; i++) {
-			x = r1<<i;
-			if(x > valmax)
-				break;
-			if(gen3(len, r0, x, f1)) {
-				i += 'a';
-				goto out;
-			}
-		}
-	}
-
-	if(!(flag & SR0)) {
-		f1 = UR0|SR0|(flag&(SR1|UR1));
-
-		f2 = UR1|SR1;
-		if(flag & UR1)
-			f2 |= UR0;
-		if(flag & SR1)
-			f2 |= SR0;
-
-		for(i=1; i<=shmax; i++) {
-			x = r0<<i;
-			if(x > valmax)
-				break;
-			if(x > r1) {
-				if(gen3(len, r1, x, f2)) {
-					i += 'a';
-					goto out;
-				}
-			} else
-				if(gen3(len, x, r1, f1)) {
-					i += 'a';
-					goto out;
-				}
-		}
-	}
-
-	x = r1+r0;
-	if(gen3(len, r0, x, UR1)) {
-		i = '+';
-		goto out;
-	}
-
-	if(gen3(len, r1, x, UR1)) {
-		i = '+';
-		goto out;
-	}
-
-	x = r1-r0;
-	if(gen3(len, x, r1, UR0)) {
-		i = '-';
-		goto out;
-	}
-
-	if(x > r0) {
-		if(gen3(len, r0, x, UR1)) {
-			i = '-';
-			goto out;
-		}
-	} else
-		if(gen3(len, x, r0, UR0)) {
-			i = '-';
-			goto out;
-		}
-
-	return 0;
-
-calcr0:
-	f1 = flag & (UR0|UR1);
-	if(f1 == UR1) {
-		for(i=1; i<=shmax; i++) {
-			x = r1<<i;
-			if(x >= mulval) {
-				if(x == mulval) {
-					i += 'a';
-					goto out;
-				}
-				break;
-			}
-		}
-	}
-
-	if(mulval == r1+r0) {
-		i = '+';
-		goto out;
-	}
-	if(mulval == r1-r0) {
-		i = '-';
-		goto out;
-	}
-
-	return 0;
-
-out:
-	*--mulcp = i;
-	return 1;
-}
-
-/*
- * hint table has numbers that
- * the search algorithm fails on.
- * <1000:
- *	all numbers
- * <5000:
- * 	÷ by 5
- * <10000:
- * 	÷ by 50
- * <65536:
- * 	÷ by 250
- */
-Hintab	hintab[] =
-{
-	683,	"b++d+e+",
-	687,	"b+e++e-",
-	691,	"b++d+e+",
-	731,	"b++d+e+",
-	811,	"b++d+i+",
-	821,	"b++e+e+",
-	843,	"b+d++e+",
-	851,	"b+f-+e-",
-	853,	"b++e+e+",
-	877,	"c++++g-",
-	933,	"b+c++g-",
-	981,	"c-+e-d+",
-	1375,	"b+c+b+h-",
-	1675,	"d+b++h+",
-	2425,	"c++f-e+",
-	2675,	"c+d++f-",
-	2750,	"b+d-b+h-",
-	2775,	"c-+g-e-",
-	3125,	"b++e+g+",
-	3275,	"b+c+g+e+",
-	3350,	"c++++i+",
-	3475,	"c-+e-f-",
-	3525,	"c-+d+g-",
-	3625,	"c-+e-j+",
-	3675,	"b+d+d+e+",
-	3725,	"b+d-+h+",
-	3925,	"b+d+f-d-",
-	4275,	"b+g++e+",
-	4325,	"b+h-+d+",
-	4425,	"b+b+g-j-",
-	4525,	"b+d-d+f+",
-	4675,	"c++d-g+",
-	4775,	"b+d+b+g-",
-	4825,	"c+c-+i-",
-	4850,	"c++++i-",
-	4925,	"b++e-g-",
-	4975,	"c+f++e-",
-	5500,	"b+g-c+d+",
-	6700,	"d+b++i+",
-	9700,	"d++++j-",
-	11000,	"b+f-c-h-",
-	11750,	"b+d+g+j-",
-	12500,	"b+c+e-k+",
-	13250,	"b+d+e-f+",
-	13750,	"b+h-c-d+",
-	14250,	"b+g-c+e-",
-	14500,	"c+f+j-d-",
-	14750,	"d-g--f+",
-	16750,	"b+e-d-n+",
-	17750,	"c+h-b+e+",
-	18250,	"d+b+h-d+",
-	18750,	"b+g-++f+",
-	19250,	"b+e+b+h+",
-	19750,	"b++h--f-",
-	20250,	"b+e-l-c+",
-	20750,	"c++bi+e-",
-	21250,	"b+i+l+c+",
-	22000,	"b+e+d-g-",
-	22250,	"b+d-h+k-",
-	22750,	"b+d-e-g+",
-	23250,	"b+c+h+e-",
-	23500,	"b+g-c-g-",
-	23750,	"b+g-b+h-",
-	24250,	"c++g+m-",
-	24750,	"b+e+e+j-",
-	25000,	"b++dh+g+",
-	25250,	"b+e+d-g-",
-	25750,	"b+e+b+j+",
-	26250,	"b+h+c+e+",
-	26500,	"b+h+c+g+",
-	26750,	"b+d+e+g-",
-	27250,	"b+e+e+f+",
-	27500,	"c-i-c-d+",
-	27750,	"b+bd++j+",
-	28250,	"d-d-++i-",
-	28500,	"c+c-h-e-",
-	29000,	"b+g-d-f+",
-	29500,	"c+h+++e-",
-	29750,	"b+g+f-c+",
-	30250,	"b+f-g-c+",
-	33500,	"c-f-d-n+",
-	33750,	"b+d-b+j-",
-	34250,	"c+e+++i+",
-	35250,	"e+b+d+k+",
-	35500,	"c+e+d-g-",
-	35750,	"c+i-++e+",
-	36250,	"b+bh-d+e+",
-	36500,	"c+c-h-e-",
-	36750,	"d+e--i+",
-	37250,	"b+g+g+b+",
-	37500,	"b+h-b+f+",
-	37750,	"c+be++j-",
-	38500,	"b+e+b+i+",
-	38750,	"d+i-b+d+",
-	39250,	"b+g-l-+d+",
-	39500,	"b+g-c+g-",
-	39750,	"b+bh-c+f-",
-	40250,	"b+bf+d+g-",
-	40500,	"b+g-c+g+",
-	40750,	"c+b+i-e+",
-	41250,	"d++bf+h+",
-	41500,	"b+j+c+d-",
-	41750,	"c+f+b+h-",
-	42500,	"c+h++g+",
-	42750,	"b+g+d-f-",
-	43250,	"b+l-e+d-",
-	43750,	"c+bd+h+f-",
-	44000,	"b+f+g-d-",
-	44250,	"b+d-g--f+",
-	44500,	"c+e+c+h+",
-	44750,	"b+e+d-h-",
-	45250,	"b++g+j-g+",
-	45500,	"c+d+e-g+",
-	45750,	"b+d-h-e-",
-	46250,	"c+bd++j+",
-	46500,	"b+d-c-j-",
-	46750,	"e-e-b+g-",
-	47000,	"b+c+d-j-",
-	47250,	"b+e+e-g-",
-	47500,	"b+g-c-h-",
-	47750,	"b+f-c+h-",
-	48250,	"d--h+n-",
-	48500,	"b+c-g+m-",
-	48750,	"b+e+e-g+",
-	49500,	"c-f+e+j-",
-	49750,	"c+c+g++f-",
-	50000,	"b+e+e+k+",
-	50250,	"b++i++g+",
-	50500,	"c+g+f-i+",
-	50750,	"b+e+d+k-",
-	51500,	"b+i+c-f+",
-	51750,	"b+bd+g-e-",
-	52250,	"b+d+g-j+",
-	52500,	"c+c+f+g+",
-	52750,	"b+c+e+i+",
-	53000,	"b+i+c+g+",
-	53500,	"c+g+g-n+",
-	53750,	"b+j+d-c+",
-	54250,	"b+d-g-j-",
-	54500,	"c-f+e+f+",
-	54750,	"b+f-+c+g+",
-	55000,	"b+g-d-g-",
-	55250,	"b+e+e+g+",
-	55500,	"b+cd++j+",
-	55750,	"b+bh-d-f-",
-	56250,	"c+d-b+j-",
-	56500,	"c+d+c+i+",
-	56750,	"b+e+d++h-",
-	57000,	"b+d+g-f+",
-	57250,	"b+f-m+d-",
-	57750,	"b+i+c+e-",
-	58000,	"b+e+d+h+",
-	58250,	"c+b+g+g+",
-	58750,	"d-e-j--e+",
-	59000,	"d-i-+e+",
-	59250,	"e--h-m+",
-	59500,	"c+c-h+f-",
-	59750,	"b+bh-e+i-",
-	60250,	"b+bh-e-e-",
-	60500,	"c+c-g-g-",
-	60750,	"b+e-l-e-",
-	61250,	"b+g-g-c+",
-	61750,	"b+g-c+g+",
-	62250,	"f--+c-i-",
-	62750,	"e+f--+g+",
-	64750,	"b+f+d+p-",
-};
-int	hintabsize	= nelem(hintab);

+ 0 - 1448
sys/src/cmd/5c/peep.c

@@ -1,1448 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "gc.h"
-
-int xtramodes(Reg*, Adr*);
-
-void
-peep(void)
-{
-	Reg *r, *r1, *r2;
-	Prog *p, *p1;
-	int t;
-/*
- * complete R structure
- */
-	t = 0;
-	for(r=firstr; r!=R; r=r1) {
-		r1 = r->link;
-		if(r1 == R)
-			break;
-		p = r->prog->link;
-		while(p != r1->prog)
-		switch(p->as) {
-		default:
-			r2 = rega();
-			r->link = r2;
-			r2->link = r1;
-
-			r2->prog = p;
-			r2->p1 = r;
-			r->s1 = r2;
-			r2->s1 = r1;
-			r1->p1 = r2;
-
-			r = r2;
-			t++;
-
-		case ADATA:
-		case AGLOBL:
-		case ANAME:
-		case ASIGNAME:
-			p = p->link;
-		}
-	}
-
-loop1:
-	t = 0;
-	for(r=firstr; r!=R; r=r->link) {
-		p = r->prog;
-		if(p->as == ASLL || p->as == ASRL || p->as == ASRA) {
-			/*
-			 * elide shift into D_SHIFT operand of subsequent instruction
-			 */
-			if(shiftprop(r)) {
-				excise(r);
-				t++;
-			}
-		}
-		if(p->as == AMOVW || p->as == AMOVF || p->as == AMOVD)
-		if(regtyp(&p->to)) {
-			if(p->from.type == D_CONST)
-				constprop(&p->from, &p->to, r->s1);
-			else if(regtyp(&p->from))
-			if(p->from.type == p->to.type) {
-				if(copyprop(r)) {
-					excise(r);
-					t++;
-				} else
-				if(subprop(r) && copyprop(r)) {
-					excise(r);
-					t++;
-				}
-			}
-		}
-	}
-	if(t)
-		goto loop1;
-	/*
-	 * look for MOVB x,R; MOVB R,R
-	 */
-	for(r=firstr; r!=R; r=r->link) {
-		p = r->prog;
-		switch(p->as) {
-		default:
-			continue;
-		case AEOR:
-			/*
-			 * EOR -1,x,y => MVN x,y
-			 */
-			if(p->from.type == D_CONST && p->from.offset == -1) {
-				p->as = AMVN;
-				p->from.type = D_REG;
-				if(p->reg != NREG)
-					p->from.reg = p->reg;
-				else
-					p->from.reg = p->to.reg;
-				p->reg = NREG;
-			}
-			continue;
-		case AMOVH:
-		case AMOVHU:
-		case AMOVB:
-		case AMOVBU:
-			if(p->to.type != D_REG)
-				continue;
-			break;
-		}
-		r1 = r->link;
-		if(r1 == R)
-			continue;
-		p1 = r1->prog;
-		if(p1->as != p->as)
-			continue;
-		if(p1->from.type != D_REG || p1->from.reg != p->to.reg)
-			continue;
-		if(p1->to.type != D_REG || p1->to.reg != p->to.reg)
-			continue;
-		excise(r1);
-	}
-
-	for(r=firstr; r!=R; r=r->link) {
-		p = r->prog;
-		switch(p->as) {
-		case AMOVW:
-		case AMOVB:
-		case AMOVBU:
-			if(p->from.type == D_OREG && p->from.offset == 0)
-				xtramodes(r, &p->from);
-			else if(p->to.type == D_OREG && p->to.offset == 0)
-				xtramodes(r, &p->to);
-			else
-				continue;
-			break;
-		case ACMP:
-			/*
-			 * elide CMP $0,x if calculation of x can set condition codes
-			 */
-			if(p->from.type != D_CONST || p->from.offset != 0)
-				continue;
-			r2 = r->s1;
-			if(r2 == R)
-				continue;
-			t = r2->prog->as;
-			switch(t) {
-			default:
-				continue;
-			case ABEQ:
-			case ABNE:
-			case ABMI:
-			case ABPL:
-				break;
-			case ABGE:
-				t = ABPL;
-				break;
-			case ABLT:
-				t = ABMI;
-				break;
-			case ABHI:
-				t = ABNE;
-				break;
-			case ABLS:
-				t = ABEQ;
-				break;
-			}
-			r1 = r;
-			do
-				r1 = uniqp(r1);
-			while (r1 != R && r1->prog->as == ANOP);
-			if(r1 == R)
-				continue;
-			p1 = r1->prog;
-			if(p1->to.type != D_REG)
-				continue;
-			if(p1->to.reg != p->reg)
-			if(!(p1->as == AMOVW && p1->from.type == D_REG && p1->from.reg == p->reg))
-				continue;
-			switch(p1->as) {
-			default:
-				continue;
-			case AMOVW:
-				if(p1->from.type != D_REG)
-					continue;
-			case AAND:
-			case AEOR:
-			case AORR:
-			case ABIC:
-			case AMVN:
-			case ASUB:
-			case ARSB:
-			case AADD:
-			case AADC:
-			case ASBC:
-			case ARSC:
-				break;
-			}
-			p1->scond |= C_SBIT;
-			r2->prog->as = t;
-			excise(r);
-			continue;
-		}
-	}
-
-	predicate();
-}
-
-void
-excise(Reg *r)
-{
-	Prog *p;
-
-	p = r->prog;
-	p->as = ANOP;
-	p->scond = zprog.scond;
-	p->from = zprog.from;
-	p->to = zprog.to;
-	p->reg = zprog.reg; /**/
-}
-
-Reg*
-uniqp(Reg *r)
-{
-	Reg *r1;
-
-	r1 = r->p1;
-	if(r1 == R) {
-		r1 = r->p2;
-		if(r1 == R || r1->p2link != R)
-			return R;
-	} else
-		if(r->p2 != R)
-			return R;
-	return r1;
-}
-
-Reg*
-uniqs(Reg *r)
-{
-	Reg *r1;
-
-	r1 = r->s1;
-	if(r1 == R) {
-		r1 = r->s2;
-		if(r1 == R)
-			return R;
-	} else
-		if(r->s2 != R)
-			return R;
-	return r1;
-}
-
-int
-regtyp(Adr *a)
-{
-
-	if(a->type == D_REG)
-		return 1;
-	if(a->type == D_FREG)
-		return 1;
-	return 0;
-}
-
-/*
- * the idea is to substitute
- * one register for another
- * from one MOV to another
- *	MOV	a, R0
- *	ADD	b, R0	/ no use of R1
- *	MOV	R0, R1
- * would be converted to
- *	MOV	a, R1
- *	ADD	b, R1
- *	MOV	R1, R0
- * hopefully, then the former or latter MOV
- * will be eliminated by copy propagation.
- */
-int
-subprop(Reg *r0)
-{
-	Prog *p;
-	Adr *v1, *v2;
-	Reg *r;
-	int t;
-
-	p = r0->prog;
-	v1 = &p->from;
-	if(!regtyp(v1))
-		return 0;
-	v2 = &p->to;
-	if(!regtyp(v2))
-		return 0;
-	for(r=uniqp(r0); r!=R; r=uniqp(r)) {
-		if(uniqs(r) == R)
-			break;
-		p = r->prog;
-		switch(p->as) {
-		case ABL:
-			return 0;
-
-		case ACMP:
-		case ACMN:
-		case AADD:
-		case ASUB:
-		case ARSB:
-		case ASLL:
-		case ASRL:
-		case ASRA:
-		case AORR:
-		case AAND:
-		case AEOR:
-		case AMUL:
-		case ADIV:
-		case ADIVU:
-
-		case ACMPF:
-		case ACMPD:
-		case AADDD:
-		case AADDF:
-		case ASUBD:
-		case ASUBF:
-		case AMULD:
-		case AMULF:
-		case ADIVD:
-		case ADIVF:
-			if(p->to.type == v1->type)
-			if(p->to.reg == v1->reg) {
-				if(p->reg == NREG)
-					p->reg = p->to.reg;
-				goto gotit;
-			}
-			break;
-
-		case AMOVF:
-		case AMOVD:
-		case AMOVW:
-			if(p->to.type == v1->type)
-			if(p->to.reg == v1->reg)
-				goto gotit;
-			break;
-
-		case AMOVM:
-			t = 1<<v2->reg;
-			if((p->from.type == D_CONST && (p->from.offset&t)) ||
-			   (p->to.type == D_CONST && (p->to.offset&t)))
-				return 0;
-			break;
-		}
-		if(copyau(&p->from, v2) ||
-		   copyau1(p, v2) ||
-		   copyau(&p->to, v2))
-			break;
-		if(copysub(&p->from, v1, v2, 0) ||
-		   copysub1(p, v1, v2, 0) ||
-		   copysub(&p->to, v1, v2, 0))
-			break;
-	}
-	return 0;
-
-gotit:
-	copysub(&p->to, v1, v2, 1);
-	if(debug['P']) {
-		print("gotit: %D->%D\n%P", v1, v2, r->prog);
-		if(p->from.type == v2->type)
-			print(" excise");
-		print("\n");
-	}
-	for(r=uniqs(r); r!=r0; r=uniqs(r)) {
-		p = r->prog;
-		copysub(&p->from, v1, v2, 1);
-		copysub1(p, v1, v2, 1);
-		copysub(&p->to, v1, v2, 1);
-		if(debug['P'])
-			print("%P\n", r->prog);
-	}
-	t = v1->reg;
-	v1->reg = v2->reg;
-	v2->reg = t;
-	if(debug['P'])
-		print("%P last\n", r->prog);
-	return 1;
-}
-
-/*
- * The idea is to remove redundant copies.
- *	v1->v2	F=0
- *	(use v2	s/v2/v1/)*
- *	set v1	F=1
- *	use v2	return fail
- *	-----------------
- *	v1->v2	F=0
- *	(use v2	s/v2/v1/)*
- *	set v1	F=1
- *	set v2	return success
- */
-int
-copyprop(Reg *r0)
-{
-	Prog *p;
-	Adr *v1, *v2;
-	Reg *r;
-
-	p = r0->prog;
-	v1 = &p->from;
-	v2 = &p->to;
-	if(copyas(v1, v2))
-		return 1;
-	for(r=firstr; r!=R; r=r->link)
-		r->active = 0;
-	return copy1(v1, v2, r0->s1, 0);
-}
-
-int
-copy1(Adr *v1, Adr *v2, Reg *r, int f)
-{
-	int t;
-	Prog *p;
-
-	if(r->active) {
-		if(debug['P'])
-			print("act set; return 1\n");
-		return 1;
-	}
-	r->active = 1;
-	if(debug['P'])
-		print("copy %D->%D f=%d\n", v1, v2, f);
-	for(; r != R; r = r->s1) {
-		p = r->prog;
-		if(debug['P'])
-			print("%P", p);
-		if(!f && uniqp(r) == R) {
-			f = 1;
-			if(debug['P'])
-				print("; merge; f=%d", f);
-		}
-		t = copyu(p, v2, A);
-		switch(t) {
-		case 2:	/* rar, cant split */
-			if(debug['P'])
-				print("; %Drar; return 0\n", v2);
-			return 0;
-
-		case 3:	/* set */
-			if(debug['P'])
-				print("; %Dset; return 1\n", v2);
-			return 1;
-
-		case 1:	/* used, substitute */
-		case 4:	/* use and set */
-			if(f) {
-				if(!debug['P'])
-					return 0;
-				if(t == 4)
-					print("; %Dused+set and f=%d; return 0\n", v2, f);
-				else
-					print("; %Dused and f=%d; return 0\n", v2, f);
-				return 0;
-			}
-			if(copyu(p, v2, v1)) {
-				if(debug['P'])
-					print("; sub fail; return 0\n");
-				return 0;
-			}
-			if(debug['P'])
-				print("; sub%D/%D", v2, v1);
-			if(t == 4) {
-				if(debug['P'])
-					print("; %Dused+set; return 1\n", v2);
-				return 1;
-			}
-			break;
-		}
-		if(!f) {
-			t = copyu(p, v1, A);
-			if(!f && (t == 2 || t == 3 || t == 4)) {
-				f = 1;
-				if(debug['P'])
-					print("; %Dset and !f; f=%d", v1, f);
-			}
-		}
-		if(debug['P'])
-			print("\n");
-		if(r->s2)
-			if(!copy1(v1, v2, r->s2, f))
-				return 0;
-	}
-	return 1;
-}
-
-/*
- * The idea is to remove redundant constants.
- *	$c1->v1
- *	($c1->v2 s/$c1/v1)*
- *	set v1  return
- * The v1->v2 should be eliminated by copy propagation.
- */
-void
-constprop(Adr *c1, Adr *v1, Reg *r)
-{
-	Prog *p;
-
-	if(debug['C'])
-		print("constprop %D->%D\n", c1, v1);
-	for(; r != R; r = r->s1) {
-		p = r->prog;
-		if(debug['C'])
-			print("%P", p);
-		if(uniqp(r) == R) {
-			if(debug['C'])
-				print("; merge; return\n");
-			return;
-		}
-		if(p->as == AMOVW && copyas(&p->from, c1)) {
-				if(debug['C'])
-					print("; sub%D/%D", &p->from, v1);
-				p->from = *v1;
-		} else if(copyu(p, v1, A) > 1) {
-			if(debug['C'])
-				print("; %Dset; return\n", v1);
-			return;
-		}
-		if(debug['C'])
-			print("\n");
-		if(r->s2)
-			constprop(c1, v1, r->s2);
-	}
-}
-
-/*
- * ASLL x,y,w
- * .. (not use w, not set x y w)
- * AXXX w,a,b (a != w)
- * .. (not use w)
- * (set w)
- * ----------- changed to
- * ..
- * AXXX (x<<y),a,b
- * ..
- */
-#define FAIL(msg) { if(debug['H']) print("\t%s; FAILURE\n", msg); return 0; }
-int
-shiftprop(Reg *r)
-{
-	Reg *r1;
-	Prog *p, *p1, *p2;
-	int n, o;
-	Adr a;
-
-	p = r->prog;
-	if(p->to.type != D_REG)
-		FAIL("BOTCH: result not reg");
-	n = p->to.reg;
-	a = zprog.from;
-	if(p->reg != NREG && p->reg != p->to.reg) {
-		a.type = D_REG;
-		a.reg = p->reg;
-	}
-	if(debug['H'])
-		print("shiftprop\n%P", p);
-	r1 = r;
-	for(;;) {
-		/* find first use of shift result; abort if shift operands or result are changed */
-		r1 = uniqs(r1);
-		if(r1 == R)
-			FAIL("branch");
-		if(uniqp(r1) == R)
-			FAIL("merge");
-		p1 = r1->prog;
-		if(debug['H'])
-			print("\n%P", p1);
-		switch(copyu(p1, &p->to, A)) {
-		case 0:	/* not used or set */
-			if((p->from.type == D_REG && copyu(p1, &p->from, A) > 1) ||
-			   (a.type == D_REG && copyu(p1, &a, A) > 1))
-				FAIL("args modified");
-			continue;
-		case 3:	/* set, not used */
-			FAIL("BOTCH: noref");
-		}
-		break;
-	}
-	/* check whether substitution can be done */
-	switch(p1->as) {
-	default:
-		FAIL("non-dpi");
-	case AAND:
-	case AEOR:
-	case AADD:
-	case AADC:
-	case AORR:
-	case ASUB:
-	case ARSB:
-	case ASBC:
-	case ARSC:
-		if(p1->reg == n || (p1->reg == NREG && p1->to.type == D_REG && p1->to.reg == n)) {
-			if(p1->from.type != D_REG)
-				FAIL("can't swap");
-			p1->reg = p1->from.reg;
-			p1->from.reg = n;
-			switch(p1->as) {
-			case ASUB:
-				p1->as = ARSB;
-				break;
-			case ARSB:
-				p1->as = ASUB;
-				break;
-			case ASBC:
-				p1->as = ARSC;
-				break;
-			case ARSC:
-				p1->as = ASBC;
-				break;
-			}
-			if(debug['H'])
-				print("\t=>%P", p1);
-		}
-	case ABIC:
-	case ACMP:
-	case ACMN:
-		if(p1->reg == n)
-			FAIL("can't swap");
-		if(p1->reg == NREG && p1->to.reg == n)
-			FAIL("shift result used twice");
-	case AMVN:
-		if(p1->from.type == D_SHIFT)
-			FAIL("shift result used in shift");
-		if(p1->from.type != D_REG || p1->from.reg != n)
-			FAIL("BOTCH: where is it used?");
-		break;
-	}
-	/* check whether shift result is used subsequently */
-	p2 = p1;
-	if(p1->to.reg != n)
-	for (;;) {
-		r1 = uniqs(r1);
-		if(r1 == R)
-			FAIL("inconclusive");
-		p1 = r1->prog;
-		if(debug['H'])
-			print("\n%P", p1);
-		switch(copyu(p1, &p->to, A)) {
-		case 0:	/* not used or set */
-			continue;
-		case 3: /* set, not used */
-			break;
-		default:/* used */
-			FAIL("reused");
-		}
-		break;
-	}
-	/* make the substitution */
-	p2->from.type = D_SHIFT;
-	p2->from.reg = NREG;
-	o = p->reg;
-	if(o == NREG)
-		o = p->to.reg;
-	switch(p->from.type){
-	case D_CONST:
-		o |= (p->from.offset&0x1f)<<7;
-		break;
-	case D_REG:
-		o |= (1<<4) | (p->from.reg<<8);
-		break;
-	}
-	switch(p->as){
-	case ASLL:
-		o |= 0<<5;
-		break;
-	case ASRL:
-		o |= 1<<5;
-		break;
-	case ASRA:
-		o |= 2<<5;
-		break;
-	}
-	p2->from.offset = o;
-	if(debug['H'])
-		print("\t=>%P\tSUCCEED\n", p2);
-	return 1;
-}
-
-Reg*
-findpre(Reg *r, Adr *v)
-{
-	Reg *r1;
-
-	for(r1=uniqp(r); r1!=R; r=r1,r1=uniqp(r)) {
-		if(uniqs(r1) != r)
-			return R;
-		switch(copyu(r1->prog, v, A)) {
-		case 1: /* used */
-		case 2: /* read-alter-rewrite */
-			return R;
-		case 3: /* set */
-		case 4: /* set and used */
-			return r1;
-		}
-	}
-	return R;
-}
-
-Reg*
-findinc(Reg *r, Reg *r2, Adr *v)
-{
-	Reg *r1;
-	Prog *p;
-
-
-	for(r1=uniqs(r); r1!=R && r1!=r2; r=r1,r1=uniqs(r)) {
-		if(uniqp(r1) != r)
-			return R;
-		switch(copyu(r1->prog, v, A)) {
-		case 0: /* not touched */
-			continue;
-		case 4: /* set and used */
-			p = r1->prog;
-			if(p->as == AADD)
-			if(p->from.type == D_CONST)
-			if(p->from.offset > -4096 && p->from.offset < 4096)
-				return r1;
-		default:
-			return R;
-		}
-	}
-	return R;
-}
-
-int
-nochange(Reg *r, Reg *r2, Prog *p)
-{
-	Adr a[3];
-	int i, n;
-
-	if(r == r2)
-		return 1;
-	n = 0;
-	if(p->reg != NREG && p->reg != p->to.reg) {
-		a[n].type = D_REG;
-		a[n++].reg = p->reg;
-	}
-	switch(p->from.type) {
-	case D_SHIFT:
-		a[n].type = D_REG;
-		a[n++].reg = p->from.offset&0xf;
-	case D_REG:
-		a[n].type = D_REG;
-		a[n++].reg = p->from.reg;
-	}
-	if(n == 0)
-		return 1;
-	for(; r!=R && r!=r2; r=uniqs(r)) {
-		p = r->prog;
-		for(i=0; i<n; i++)
-			if(copyu(p, &a[i], A) > 1)
-				return 0;
-	}
-	return 1;
-}
-
-int
-findu1(Reg *r, Adr *v)
-{
-	for(; r != R; r = r->s1) {
-		if(r->active)
-			return 0;
-		r->active = 1;
-		switch(copyu(r->prog, v, A)) {
-		case 1: /* used */
-		case 2: /* read-alter-rewrite */
-		case 4: /* set and used */
-			return 1;
-		case 3: /* set */
-			return 0;
-		}
-		if(r->s2)
-			if (findu1(r->s2, v))
-				return 1;
-	}
-	return 0;
-}
-
-int
-finduse(Reg *r, Adr *v)
-{
-	Reg *r1;
-
-	for(r1=firstr; r1!=R; r1=r1->link)
-		r1->active = 0;
-	return findu1(r, v);
-}
-
-int
-xtramodes(Reg *r, Adr *a)
-{
-	Reg *r1, *r2, *r3;
-	Prog *p, *p1;
-	Adr v;
-
-	p = r->prog;
-	if(debug['h'] && p->as == AMOVB && p->from.type == D_OREG)	/* byte load */
-		return 0;
-	v = *a;
-	v.type = D_REG;
-	r1 = findpre(r, &v);
-	if(r1 != R) {
-		p1 = r1->prog;
-		if(p1->to.type == D_REG && p1->to.reg == v.reg)
-		switch(p1->as) {
-		case AADD:
-			if(p1->from.type == D_REG ||
-			   (p1->from.type == D_SHIFT && (p1->from.offset&(1<<4)) == 0 &&
-			    (p->as != AMOVB || (a == &p->from && (p1->from.offset&~0xf) == 0))) ||
-			   (p1->from.type == D_CONST && 
-			    p1->from.offset > -4096 && p1->from.offset < 4096))
-			if(nochange(uniqs(r1), r, p1)) {
-				if(a != &p->from || v.reg != p->to.reg)
-				if (finduse(r->s1, &v)) {
-					if(p1->reg == NREG || p1->reg == v.reg)
-						/* pre-indexing */
-						p->scond |= C_WBIT;
-					else return 0;	
-				}
-				switch (p1->from.type) {
-				case D_REG:
-					/* register offset */
-					a->type = D_SHIFT;
-					a->offset = p1->from.reg;
-					break;
-				case D_SHIFT:
-					/* scaled register offset */
-					a->type = D_SHIFT;
-				case D_CONST:
-					/* immediate offset */
-					a->offset = p1->from.offset;
-					break;
-				}
-				if(p1->reg != NREG)
-					a->reg = p1->reg;
-				excise(r1);
-				return 1;
-			}
-			break;
-		case AMOVW:
-			if(p1->from.type == D_REG)
-			if((r2 = findinc(r1, r, &p1->from)) != R) {
-			for(r3=uniqs(r2); r3->prog->as==ANOP; r3=uniqs(r3))
-				;
-			if(r3 == r) {
-				/* post-indexing */
-				p1 = r2->prog;
-				a->reg = p1->to.reg;
-				a->offset = p1->from.offset;
-				p->scond |= C_PBIT;
-				if(!finduse(r, &r1->prog->to))
-					excise(r1);
-				excise(r2);
-				return 1;
-			}
-			}
-			break;
-		}
-	}
-	if(a != &p->from || a->reg != p->to.reg)
-	if((r1 = findinc(r, R, &v)) != R) {
-		/* post-indexing */
-		p1 = r1->prog;
-		a->offset = p1->from.offset;
-		p->scond |= C_PBIT;
-		excise(r1);
-		return 1;
-	}
-	return 0;
-}
-
-/*
- * return
- * 1 if v only used (and substitute),
- * 2 if read-alter-rewrite
- * 3 if set
- * 4 if set and used
- * 0 otherwise (not touched)
- */
-int
-copyu(Prog *p, Adr *v, Adr *s)
-{
-
-	switch(p->as) {
-
-	default:
-		if(debug['P'])
-			print(" (???)");
-		return 2;
-
-	case AMOVM:
-		if(v->type != D_REG)
-			return 0;
-		if(p->from.type == D_CONST) {	/* read reglist, read/rar */
-			if(s != A) {
-				if(p->from.offset&(1<<v->reg))
-					return 1;
-				if(copysub(&p->to, v, s, 1))
-					return 1;
-				return 0;
-			}
-			if(copyau(&p->to, v)) {
-				if(p->scond&C_WBIT)
-					return 2;
-				return 1;
-			}
-			if(p->from.offset&(1<<v->reg))
-				return 1;
-		} else {			/* read/rar, write reglist */
-			if(s != A) {
-				if(p->to.offset&(1<<v->reg))
-					return 1;
-				if(copysub(&p->from, v, s, 1))
-					return 1;
-				return 0;
-			}
-			if(copyau(&p->from, v)) {
-				if(p->scond&C_WBIT)
-					return 2;
-				if(p->to.offset&(1<<v->reg))
-					return 4;
-				return 1;
-			}
-			if(p->to.offset&(1<<v->reg))
-				return 3;
-		}
-		return 0;
-		
-	case ANOP:	/* read, write */
-	case AMOVW:
-	case AMOVF:
-	case AMOVD:
-	case AMOVH:
-	case AMOVHU:
-	case AMOVB:
-	case AMOVBU:
-	case AMOVDW:
-	case AMOVWD:
-	case AMOVFD:
-	case AMOVDF:
-		if(p->scond&(C_WBIT|C_PBIT))
-		if(v->type == D_REG) {
-			if(p->from.type == D_OREG || p->from.type == D_SHIFT) {
-				if(p->from.reg == v->reg)
-					return 2;
-			} else {
-		  		if(p->to.reg == v->reg)
-				return 2;
-			}
-		}
-		if(s != A) {
-			if(copysub(&p->from, v, s, 1))
-				return 1;
-			if(!copyas(&p->to, v))
-				if(copysub(&p->to, v, s, 1))
-					return 1;
-			return 0;
-		}
-		if(copyas(&p->to, v)) {
-			if(copyau(&p->from, v))
-				return 4;
-			return 3;
-		}
-		if(copyau(&p->from, v))
-			return 1;
-		if(copyau(&p->to, v))
-			return 1;
-		return 0;
-
-
-	case AADD:	/* read, read, write */
-	case ASUB:
-	case ARSB:
-	case ASLL:
-	case ASRL:
-	case ASRA:
-	case AORR:
-	case AAND:
-	case AEOR:
-	case AMUL:
-	case ADIV:
-	case ADIVU:
-	case AADDF:
-	case AADDD:
-	case ASUBF:
-	case ASUBD:
-	case AMULF:
-	case AMULD:
-	case ADIVF:
-	case ADIVD:
-
-	case ACMPF:
-	case ACMPD:
-	case ACMP:
-	case ACMN:
-	case ACASE:
-		if(s != A) {
-			if(copysub(&p->from, v, s, 1))
-				return 1;
-			if(copysub1(p, v, s, 1))
-				return 1;
-			if(!copyas(&p->to, v))
-				if(copysub(&p->to, v, s, 1))
-					return 1;
-			return 0;
-		}
-		if(copyas(&p->to, v)) {
-			if(p->reg == NREG)
-				p->reg = p->to.reg;
-			if(copyau(&p->from, v))
-				return 4;
-			if(copyau1(p, v))
-				return 4;
-			return 3;
-		}
-		if(copyau(&p->from, v))
-			return 1;
-		if(copyau1(p, v))
-			return 1;
-		if(copyau(&p->to, v))
-			return 1;
-		return 0;
-
-	case ABEQ:	/* read, read */
-	case ABNE:
-	case ABCS:
-	case ABHS:
-	case ABCC:
-	case ABLO:
-	case ABMI:
-	case ABPL:
-	case ABVS:
-	case ABVC:
-	case ABHI:
-	case ABLS:
-	case ABGE:
-	case ABLT:
-	case ABGT:
-	case ABLE:
-		if(s != A) {
-			if(copysub(&p->from, v, s, 1))
-				return 1;
-			return copysub1(p, v, s, 1);
-		}
-		if(copyau(&p->from, v))
-			return 1;
-		if(copyau1(p, v))
-			return 1;
-		return 0;
-
-	case AB:	/* funny */
-		if(s != A) {
-			if(copysub(&p->to, v, s, 1))
-				return 1;
-			return 0;
-		}
-		if(copyau(&p->to, v))
-			return 1;
-		return 0;
-
-	case ARET:	/* funny */
-		if(v->type == D_REG)
-		if(v->reg == REGRET)
-			return 2;
-		if(v->type == D_FREG)
-		if(v->reg == FREGRET)
-			return 2;
-
-	case ABL:	/* funny */
-		if(v->type == D_REG) {
-			if(v->reg <= REGEXT && v->reg > exregoffset)
-				return 2;
-			if(v->reg == (uint8_t)REGARG)
-				return 2;
-		}
-		if(v->type == D_FREG)
-			if(v->reg <= FREGEXT && v->reg > exfregoffset)
-				return 2;
-
-		if(s != A) {
-			if(copysub(&p->to, v, s, 1))
-				return 1;
-			return 0;
-		}
-		if(copyau(&p->to, v))
-			return 4;
-		return 3;
-
-	case ATEXT:	/* funny */
-		if(v->type == D_REG)
-			if(v->reg == (uint8_t)REGARG)
-				return 3;
-		return 0;
-	}
-}
-
-int
-a2type(Prog *p)
-{
-
-	switch(p->as) {
-
-	case ACMP:
-	case ACMN:
-
-	case AADD:
-	case ASUB:
-	case ARSB:
-	case ASLL:
-	case ASRL:
-	case ASRA:
-	case AORR:
-	case AAND:
-	case AEOR:
-	case AMUL:
-	case ADIV:
-	case ADIVU:
-		return D_REG;
-
-	case ACMPF:
-	case ACMPD:
-
-	case AADDF:
-	case AADDD:
-	case ASUBF:
-	case ASUBD:
-	case AMULF:
-	case AMULD:
-	case ADIVF:
-	case ADIVD:
-		return D_FREG;
-	}
-	return D_NONE;
-}
-
-/*
- * direct reference,
- * could be set/use depending on
- * semantics
- */
-int
-copyas(Adr *a, Adr *v)
-{
-
-	if(regtyp(v)) {
-		if(a->type == v->type)
-		if(a->reg == v->reg)
-			return 1;
-	} else if(v->type == D_CONST) {		/* for constprop */
-		if(a->type == v->type)
-		if(a->name == v->name)
-		if(a->sym == v->sym)
-		if(a->reg == v->reg)
-		if(a->offset == v->offset)
-			return 1;
-	}
-	return 0;
-}
-
-/*
- * either direct or indirect
- */
-int
-copyau(Adr *a, Adr *v)
-{
-
-	if(copyas(a, v))
-		return 1;
-	if(v->type == D_REG) {
-		if(a->type == D_OREG) {
-			if(v->reg == a->reg)
-				return 1;
-		} else if(a->type == D_SHIFT) {
-			if((a->offset&0xf) == v->reg)
-				return 1;
-			if((a->offset&(1<<4)) && (a->offset>>8) == v->reg)
-				return 1;
-		}
-	}
-	return 0;
-}
-
-int
-copyau1(Prog *p, Adr *v)
-{
-
-	if(regtyp(v)) {
-		if(a2type(p) == v->type)
-		if(p->reg == v->reg) {
-			if(a2type(p) != v->type)
-				print("botch a2type %P\n", p);
-			return 1;
-		}
-	}
-	return 0;
-}
-
-/*
- * substitute s for v in a
- * return failure to substitute
- */
-int
-copysub(Adr *a, Adr *v, Adr *s, int f)
-{
-
-	if(f)
-	if(copyau(a, v)) {
-		if(a->type == D_SHIFT) {
-			if((a->offset&0xf) == v->reg)
-				a->offset = (a->offset&~0xf)|s->reg;
-			if((a->offset&(1<<4)) && (a->offset>>8) == v->reg)
-				a->offset = (a->offset&~(0xf<<8))|(s->reg<<8);
-		} else
-			a->reg = s->reg;
-	}
-	return 0;
-}
-
-int
-copysub1(Prog *p1, Adr *v, Adr *s, int f)
-{
-
-	if(f)
-	if(copyau1(p1, v))
-		p1->reg = s->reg;
-	return 0;
-}
-
-struct {
-	int opcode;
-	int notopcode;
-	int scond; 
-	int notscond; 
-} predinfo[]  = { 
-	{ ABEQ,	ABNE,	0x0,	0x1, }, 
-	{ ABNE,	ABEQ,	0x1,	0x0, }, 
-	{ ABCS,	ABCC,	0x2,	0x3, }, 
-	{ ABHS,	ABLO,	0x2,	0x3, }, 
-	{ ABCC,	ABCS,	0x3,	0x2, }, 
-	{ ABLO,	ABHS,	0x3,	0x2, }, 
-	{ ABMI,	ABPL,	0x4,	0x5, }, 
-	{ ABPL,	ABMI,	0x5,	0x4, }, 
-	{ ABVS,	ABVC,	0x6,	0x7, }, 
-	{ ABVC,	ABVS,	0x7,	0x6, }, 
-	{ ABHI,	ABLS,	0x8,	0x9, }, 
-	{ ABLS,	ABHI,	0x9,	0x8, }, 
-	{ ABGE,	ABLT,	0xA,	0xB, }, 
-	{ ABLT,	ABGE,	0xB,	0xA, }, 
-	{ ABGT,	ABLE,	0xC,	0xD, }, 
-	{ ABLE,	ABGT,	0xD,	0xC, }, 
-}; 
-
-typedef struct {
-	Reg *start;
-	Reg *last;
-	Reg *end;
-	int len;
-} Joininfo;
-
-enum {
-	Join,
-	Split,
-	End,
-	Branch,
-	Setcond,
-	Toolong
-};
-	
-enum {
-	Falsecond,
-	Truecond,
-	Delbranch,
-	Keepbranch
-};
-
-int 
-isbranch(Prog *p)
-{
-	return (ABEQ <= p->as) && (p->as <= ABLE); 
-}
-
-int
-predicable(Prog *p)
-{
-	if (isbranch(p)
-		|| p->as == ANOP
-		|| p->as == AXXX
-		|| p->as == ADATA
-		|| p->as == AGLOBL
-		|| p->as == AGOK
-		|| p->as == AHISTORY
-		|| p->as == ANAME
-		|| p->as == ASIGNAME
-		|| p->as == ATEXT
-		|| p->as == AWORD
-		|| p->as == ADYNT
-		|| p->as == AINIT
-		|| p->as == ABCASE
-		|| p->as == ACASE)
-		return 0; 
-	return 1; 
-}
-
-/* 
- * Depends on an analysis of the encodings performed by 5l. 
- * These seem to be all of the opcodes that lead to the "S" bit
- * being set in the instruction encodings. 
- * 
- * C_SBIT may also have been set explicitly in p->scond.
- */ 
-int
-modifiescpsr(Prog *p)
-{
-	return (p->scond&C_SBIT)
-		|| p->as == ATST 
-		|| p->as == ATEQ 
-		|| p->as == ACMN
-		|| p->as == ACMP
-		|| p->as == AMULU
-		|| p->as == ADIVU
-		|| p->as == AMUL
-		|| p->as == ADIV
-		|| p->as == AMOD
-		|| p->as == AMODU
-		|| p->as == ABL;
-} 
-
-/*
- * Find the maximal chain of instructions starting with r which could
- * be executed conditionally
- */
-int
-joinsplit(Reg *r, Joininfo *j)
-{
-	j->start = r;
-	j->last = r;
-	j->len = 0;
-	do {
-		if (r->p2 && (r->p1 || r->p2->p2link)) {
-			j->end = r;
-			return Join;
-		}
-		if (r->s1 && r->s2) {
-			j->end = r;
-			return Split;
-		}
-		j->last = r;
-		if (r->prog->as != ANOP)
-			j->len++;
-		if (!r->s1 && !r->s2) {
-			j->end = r->link;
-			return End;
-		}
-		if (r->s2) {
-			j->end = r->s2;
-			return Branch;
-		}
-		if (modifiescpsr(r->prog)) {
-			j->end = r->s1;
-			return Setcond;
-		}
-		r = r->s1;
-	} while (j->len < 4);
-	j->end = r;
-	return Toolong;
-}
-
-Reg *
-successor(Reg *r)
-{
-	if (r->s1)
-		return r->s1; 
-	else
-		return r->s2; 
-}
-
-void
-applypred(Reg *rstart, Joininfo *j, int cond, int branch)
-{
-	int pred; 
-	Reg *r; 
-
-	if(j->len == 0)
-		return;
-	if (cond == Truecond)
-		pred = predinfo[rstart->prog->as - ABEQ].scond;
-	else
-		pred = predinfo[rstart->prog->as - ABEQ].notscond; 
-	
-	for (r = j->start; ; r = successor(r)) {
-		if (r->prog->as == AB) {
-			if (r != j->last || branch == Delbranch)
-				excise(r);
-			else {
-			  if (cond == Truecond)
-				r->prog->as = predinfo[rstart->prog->as - ABEQ].opcode;
-			  else
-				r->prog->as = predinfo[rstart->prog->as - ABEQ].notopcode;
-			}
-		}
-		else if (predicable(r->prog)) 
-			r->prog->scond = (r->prog->scond&~C_SCOND)|pred;
-		if (r->s1 != r->link) {
-			r->s1 = r->link;
-			r->link->p1 = r;
-		}
-		if (r == j->last)
-			break;
-	}
-}
-
-void
-predicate(void)
-{	
-	Reg *r;
-	int t1, t2;
-	Joininfo j1, j2;
-
-	for(r=firstr; r!=R; r=r->link) {
-		if (isbranch(r->prog)) {
-			t1 = joinsplit(r->s1, &j1);
-			t2 = joinsplit(r->s2, &j2);
-			if(j1.last->link != j2.start)
-				continue;
-			if(j1.end == j2.end)
-			if((t1 == Branch && (t2 == Join || t2 == Setcond)) ||
-			   (t2 == Join && (t1 == Join || t1 == Setcond))) {
-				applypred(r, &j1, Falsecond, Delbranch);
-				applypred(r, &j2, Truecond, Delbranch);
-				excise(r);
-				continue;
-			}
-			if(t1 == End || t1 == Branch) {
-				applypred(r, &j1, Falsecond, Keepbranch);
-				excise(r);
-				continue;
-			}
-		} 
-	} 
-}

+ 0 - 1167
sys/src/cmd/5c/reg.c

@@ -1,1167 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "gc.h"
-
-void	addsplits(void);
-
-Reg*
-rega(void)
-{
-	Reg *r;
-
-	r = freer;
-	if(r == R) {
-		r = alloc(sizeof(*r));
-	} else
-		freer = r->link;
-
-	*r = zreg;
-	return r;
-}
-
-int
-rcmp(const void *a1, const void *a2)
-{
-	Rgn *p1, *p2;
-	int c1, c2;
-
-	p1 = (Rgn*)a1;
-	p2 = (Rgn*)a2;
-	c1 = p2->cost;
-	c2 = p1->cost;
-	if(c1 -= c2)
-		return c1;
-	return p2->varno - p1->varno;
-}
-
-void
-regopt(Prog *p)
-{
-	Reg *r, *r1, *r2;
-	Prog *p1;
-	int i, z;
-	int32_t initpc, val, npc;
-	uint32_t vreg;
-	Bits bit;
-	struct
-	{
-		int32_t	m;
-		int32_t	c;
-		Reg*	p;
-	} log5[6], *lp;
-
-	firstr = R;
-	lastr = R;
-	nvar = 0;
-	regbits = 0;
-	for(z=0; z<BITS; z++) {
-		externs.b[z] = 0;
-		params.b[z] = 0;
-		consts.b[z] = 0;
-		addrs.b[z] = 0;
-	}
-
-	/*
-	 * pass 1
-	 * build aux data structure
-	 * allocate pcs
-	 * find use and set of variables
-	 */
-	val = 5L * 5L * 5L * 5L * 5L;
-	lp = log5;
-	for(i=0; i<5; i++) {
-		lp->m = val;
-		lp->c = 0;
-		lp->p = R;
-		val /= 5L;
-		lp++;
-	}
-	val = 0;
-	for(; p != P; p = p->link) {
-		switch(p->as) {
-		case ADATA:
-		case AGLOBL:
-		case ANAME:
-		case ASIGNAME:
-			continue;
-		}
-		r = rega();
-		if(firstr == R) {
-			firstr = r;
-			lastr = r;
-		} else {
-			lastr->link = r;
-			r->p1 = lastr;
-			lastr->s1 = r;
-			lastr = r;
-		}
-		r->prog = p;
-		r->pc = val;
-		val++;
-
-		lp = log5;
-		for(i=0; i<5; i++) {
-			lp->c--;
-			if(lp->c <= 0) {
-				lp->c = lp->m;
-				if(lp->p != R)
-					lp->p->log5 = r;
-				lp->p = r;
-				(lp+1)->c = 0;
-				break;
-			}
-			lp++;
-		}
-
-		r1 = r->p1;
-		if(r1 != R)
-		switch(r1->prog->as) {
-		case ARET:
-		case AB:
-		case ARFE:
-			r->p1 = R;
-			r1->s1 = R;
-		}
-
-		/*
-		 * left side always read
-		 */
-		bit = mkvar(&p->from, p->as==AMOVW);
-		for(z=0; z<BITS; z++)
-			r->use1.b[z] |= bit.b[z];
-
-		/*
-		 * right side depends on opcode
-		 */
-		bit = mkvar(&p->to, 0);
-		if(bany(&bit))
-		switch(p->as) {
-		default:
-			diag(Z, "reg: unknown asop: %A", p->as);
-			break;
-
-		/*
-		 * right side write
-		 */
-		case ANOP:
-		case AMOVB:
-		case AMOVBU:
-		case AMOVH:
-		case AMOVHU:
-		case AMOVW:
-		case AMOVF:
-		case AMOVD:
-			for(z=0; z<BITS; z++)
-				r->set.b[z] |= bit.b[z];
-			break;
-
-		/*
-		 * funny
-		 */
-		case ABL:
-			for(z=0; z<BITS; z++)
-				addrs.b[z] |= bit.b[z];
-			break;
-		}
-
-		if(p->as == AMOVM) {
-			if(p->from.type == D_CONST)
-				z = p->from.offset;
-			else
-				z = p->to.offset;
-			for(i=0; z; i++) {
-				if(z&1)
-					regbits |= RtoB(i);
-				z >>= 1;
-			}
-		}
-	}
-	if(firstr == R)
-		return;
-	initpc = pc - val;
-	npc = val;
-
-	/*
-	 * pass 2
-	 * turn branch references to pointers
-	 * build back pointers
-	 */
-	for(r = firstr; r != R; r = r->link) {
-		p = r->prog;
-		if(p->to.type == D_BRANCH) {
-			val = p->to.offset - initpc;
-			r1 = firstr;
-			while(r1 != R) {
-				r2 = r1->log5;
-				if(r2 != R && val >= r2->pc) {
-					r1 = r2;
-					continue;
-				}
-				if(r1->pc == val)
-					break;
-				r1 = r1->link;
-			}
-			if(r1 == R) {
-				nearln = p->lineno;
-				diag(Z, "ref not found\n%P", p);
-				continue;
-			}
-			if(r1 == r) {
-				nearln = p->lineno;
-				diag(Z, "ref to self\n%P", p);
-				continue;
-			}
-			r->s2 = r1;
-			r->p2link = r1->p2;
-			r1->p2 = r;
-		}
-	}
-	if(debug['R']) {
-		p = firstr->prog;
-		print("\n%L %D\n", p->lineno, &p->from);
-	}
-
-	/*
-	 * pass 2.5
-	 * find looping structure
-	 */
-	for(r = firstr; r != R; r = r->link)
-		r->active = 0;
-	change = 0;
-	loopit(firstr, npc);
-
-	/*
-	 * pass 3
-	 * iterate propagating usage
-	 * 	back until flow graph is complete
-	 */
-loop1:
-	change = 0;
-	for(r = firstr; r != R; r = r->link)
-		r->active = 0;
-	for(r = firstr; r != R; r = r->link)
-		if(r->prog->as == ARET)
-			prop(r, zbits, zbits);
-loop11:
-	/* pick up unreachable code */
-	i = 0;
-	for(r = firstr; r != R; r = r1) {
-		r1 = r->link;
-		if(r1 && r1->active && !r->active) {
-			prop(r, zbits, zbits);
-			i = 1;
-		}
-	}
-	if(i)
-		goto loop11;
-	if(change)
-		goto loop1;
-
-
-	/*
-	 * pass 4
-	 * iterate propagating register/variable synchrony
-	 * 	forward until graph is complete
-	 */
-loop2:
-	change = 0;
-	for(r = firstr; r != R; r = r->link)
-		r->active = 0;
-	synch(firstr, zbits);
-	if(change)
-		goto loop2;
-
-	addsplits();
-
-	if(debug['R'] && debug['v']) {
-		print("\nprop structure:\n");
-		for(r = firstr; r != R; r = r->link) {
-			print("%ld:%P", r->loop, r->prog);
-			for(z=0; z<BITS; z++)
-				bit.b[z] = r->set.b[z] |
-					r->refahead.b[z] | r->calahead.b[z] |
-					r->refbehind.b[z] | r->calbehind.b[z] |
-					r->use1.b[z] | r->use2.b[z];
-			if(bany(&bit)) {
-				print("\t");
-				if(bany(&r->use1))
-					print(" u1=%B", r->use1);
-				if(bany(&r->use2))
-					print(" u2=%B", r->use2);
-				if(bany(&r->set))
-					print(" st=%B", r->set);
-				if(bany(&r->refahead))
-					print(" ra=%B", r->refahead);
-				if(bany(&r->calahead))
-					print(" ca=%B", r->calahead);
-				if(bany(&r->refbehind))
-					print(" rb=%B", r->refbehind);
-				if(bany(&r->calbehind))
-					print(" cb=%B", r->calbehind);
-			}
-			print("\n");
-		}
-	}
-
-	/*
-	 * pass 5
-	 * isolate regions
-	 * calculate costs (paint1)
-	 */
-	r = firstr;
-	if(r) {
-		for(z=0; z<BITS; z++)
-			bit.b[z] = (r->refahead.b[z] | r->calahead.b[z]) &
-			  ~(externs.b[z] | params.b[z] | addrs.b[z] | consts.b[z]);
-		if(bany(&bit)) {
-			nearln = r->prog->lineno;
-			warn(Z, "used and not set: %B", bit);
-			if(debug['R'] && !debug['w'])
-				print("used and not set: %B\n", bit);
-		}
-	}
-
-	for(r = firstr; r != R; r = r->link)
-		r->act = zbits;
-	rgp = region;
-	nregion = 0;
-	for(r = firstr; r != R; r = r->link) {
-		for(z=0; z<BITS; z++)
-			bit.b[z] = r->set.b[z] &
-			  ~(r->refahead.b[z] | r->calahead.b[z] | addrs.b[z]);
-		if(bany(&bit)) {
-			nearln = r->prog->lineno;
-			warn(Z, "set and not used: %B", bit);
-			if(debug['R'])
-				print("set and not used: %B\n", bit);
-			excise(r);
-		}
-		for(z=0; z<BITS; z++)
-			bit.b[z] = LOAD(r) & ~(r->act.b[z] | addrs.b[z]);
-		while(bany(&bit)) {
-			i = bnum(bit);
-			rgp->enter = r;
-			rgp->varno = i;
-			change = 0;
-			if(debug['R'] && debug['v'])
-				print("\n");
-			paint1(r, i);
-			bit.b[i/32] &= ~(1L<<(i%32));
-			if(change <= 0) {
-				if(debug['R'])
-					print("%L $%d: %B\n",
-						r->prog->lineno, change, blsh(i));
-				continue;
-			}
-			rgp->cost = change;
-			nregion++;
-			if(nregion >= NRGN) {
-				warn(Z, "too many regions");
-				goto brk;
-			}
-			rgp++;
-		}
-	}
-brk:
-	qsort(region, nregion, sizeof(region[0]), rcmp);
-
-	/*
-	 * pass 6
-	 * determine used registers (paint2)
-	 * replace code (paint3)
-	 */
-	rgp = region;
-	for(i=0; i<nregion; i++) {
-		bit = blsh(rgp->varno);
-		vreg = paint2(rgp->enter, rgp->varno);
-		vreg = allreg(vreg, rgp);
-		if(debug['R']) {
-			if(rgp->regno >= NREG)
-				print("%L $%d F%d: %B\n",
-					rgp->enter->prog->lineno,
-					rgp->cost,
-					rgp->regno-NREG,
-					bit);
-			else
-				print("%L $%d R%d: %B\n",
-					rgp->enter->prog->lineno,
-					rgp->cost,
-					rgp->regno,
-					bit);
-		}
-		if(rgp->regno != 0)
-			paint3(rgp->enter, rgp->varno, vreg, rgp->regno);
-		rgp++;
-	}
-	/*
-	 * pass 7
-	 * peep-hole on basic block
-	 */
-	if(!debug['R'] || debug['P'])
-		peep();
-
-	/*
-	 * pass 8
-	 * recalculate pc
-	 */
-	val = initpc;
-	for(r = firstr; r != R; r = r1) {
-		r->pc = val;
-		p = r->prog;
-		p1 = P;
-		r1 = r->link;
-		if(r1 != R)
-			p1 = r1->prog;
-		for(; p != p1; p = p->link) {
-			switch(p->as) {
-			default:
-				val++;
-				break;
-
-			case ANOP:
-			case ADATA:
-			case AGLOBL:
-			case ANAME:
-			case ASIGNAME:
-				break;
-			}
-		}
-	}
-	pc = val;
-
-	/*
-	 * fix up branches
-	 */
-	if(debug['R'])
-		if(bany(&addrs))
-			print("addrs: %B\n", addrs);
-
-	r1 = 0; /* set */
-	for(r = firstr; r != R; r = r->link) {
-		p = r->prog;
-		if(p->to.type == D_BRANCH)
-			p->to.offset = r->s2->pc;
-		r1 = r;
-	}
-
-	/*
-	 * last pass
-	 * eliminate nops
-	 * free aux structures
-	 */
-	for(p = firstr->prog; p != P; p = p->link){
-		while(p->link && p->link->as == ANOP)
-			p->link = p->link->link;
-	}
-	if(r1 != R) {
-		r1->link = freer;
-		freer = firstr;
-	}
-}
-
-void
-addsplits(void)
-{
-	Reg *r, *r1;
-	int z, i;
-	Bits bit;
-
-	for(r = firstr; r != R; r = r->link) {
-		if(r->loop > 1)
-			continue;
-		if(r->prog->as == ABL)
-			continue;
-		for(r1 = r->p2; r1 != R; r1 = r1->p2link) {
-			if(r1->loop <= 1)
-				continue;
-			for(z=0; z<BITS; z++)
-				bit.b[z] = r1->calbehind.b[z] &
-					(r->refahead.b[z] | r->use1.b[z] | r->use2.b[z]) &
-					~(r->calahead.b[z] & addrs.b[z]);
-			while(bany(&bit)) {
-				i = bnum(bit);
-				bit.b[i/32] &= ~(1L << (i%32));
-			}
-		}
-	}
-}
-
-/*
- * add mov b,rn
- * just after r
- */
-void
-addmove(Reg *r, int bn, int rn, int f)
-{
-	Prog *p, *p1;
-	Adr *a;
-	Var *v;
-
-	p1 = alloc(sizeof(*p1));
-	*p1 = zprog;
-	p = r->prog;
-
-	p1->link = p->link;
-	p->link = p1;
-	p1->lineno = p->lineno;
-
-	v = var + bn;
-
-	a = &p1->to;
-	a->sym = v->sym;
-	a->name = v->name;
-	a->offset = v->offset;
-	a->etype = v->etype;
-	a->type = D_OREG;
-	if(a->etype == TARRAY || a->sym == S)
-		a->type = D_CONST;
-
-	p1->as = AMOVW;
-	if(v->etype == TCHAR || v->etype == TUCHAR)
-		p1->as = AMOVB;
-	if(v->etype == TSHORT || v->etype == TUSHORT)
-		p1->as = AMOVH;
-	if(v->etype == TFLOAT)
-		p1->as = AMOVF;
-	if(v->etype == TDOUBLE)
-		p1->as = AMOVD;
-
-	p1->from.type = D_REG;
-	p1->from.reg = rn;
-	if(rn >= NREG) {
-		p1->from.type = D_FREG;
-		p1->from.reg = rn-NREG;
-	}
-	if(!f) {
-		p1->from = *a;
-		*a = zprog.from;
-		a->type = D_REG;
-		a->reg = rn;
-		if(rn >= NREG) {
-			a->type = D_FREG;
-			a->reg = rn-NREG;
-		}
-		if(v->etype == TUCHAR)
-			p1->as = AMOVBU;
-		if(v->etype == TUSHORT)
-			p1->as = AMOVHU;
-	}
-	if(debug['R'])
-		print("%P\t.a%P\n", p, p1);
-}
-
-Bits
-mkvar(Adr *a, int docon)
-{
-	Var *v;
-	int i, t, n, et, z;
-	int32_t o;
-	Bits bit;
-	Sym *s;
-
-	t = a->type;
-	if(t == D_REG && a->reg != NREG)
-		regbits |= RtoB(a->reg);
-	if(t == D_FREG && a->reg != NREG)
-		regbits |= FtoB(a->reg);
-	s = a->sym;
-	o = a->offset;
-	et = a->etype;
-	if(s == S) {
-		if(t != D_CONST || !docon || a->reg != NREG)
-			goto none;
-		et = TLONG;
-	}
-	if(t == D_CONST) {
-		if(s == S && sval(o))
-			goto none;
-	}
-
-	n = a->name;
-	v = var;
-	for(i=0; i<nvar; i++) {
-		if(s == v->sym)
-		if(n == v->name)
-		if(o == v->offset)
-			goto out;
-		v++;
-	}
-	if(s)
-		if(s->name[0] == '.')
-			goto none;
-	if(nvar >= NVAR) {
-		if(debug['w'] > 1 && s)
-			warn(Z, "variable not optimized: %s", s->name);
-		goto none;
-	}
-	i = nvar;
-	nvar++;
-	v = &var[i];
-	v->sym = s;
-	v->offset = o;
-	v->etype = et;
-	v->name = n;
-	if(debug['R'])
-		print("bit=%2d et=%2d %D\n", i, et, a);
-out:
-	bit = blsh(i);
-	if(n == D_EXTERN || n == D_STATIC)
-		for(z=0; z<BITS; z++)
-			externs.b[z] |= bit.b[z];
-	if(n == D_PARAM)
-		for(z=0; z<BITS; z++)
-			params.b[z] |= bit.b[z];
-	if(v->etype != et || !typechlpfd[et])	/* funny punning */
-		for(z=0; z<BITS; z++)
-			addrs.b[z] |= bit.b[z];
-	if(t == D_CONST) {
-		if(s == S) {
-			for(z=0; z<BITS; z++)
-				consts.b[z] |= bit.b[z];
-			return bit;
-		}
-		if(et != TARRAY)
-			for(z=0; z<BITS; z++)
-				addrs.b[z] |= bit.b[z];
-		for(z=0; z<BITS; z++)
-			params.b[z] |= bit.b[z];
-		return bit;
-	}
-	if(t == D_OREG)
-		return bit;
-
-none:
-	return zbits;
-}
-
-void
-prop(Reg *r, Bits ref, Bits cal)
-{
-	Reg *r1, *r2;
-	int z;
-
-	for(r1 = r; r1 != R; r1 = r1->p1) {
-		for(z=0; z<BITS; z++) {
-			ref.b[z] |= r1->refahead.b[z];
-			if(ref.b[z] != r1->refahead.b[z]) {
-				r1->refahead.b[z] = ref.b[z];
-				change++;
-			}
-			cal.b[z] |= r1->calahead.b[z];
-			if(cal.b[z] != r1->calahead.b[z]) {
-				r1->calahead.b[z] = cal.b[z];
-				change++;
-			}
-		}
-		switch(r1->prog->as) {
-		case ABL:
-			for(z=0; z<BITS; z++) {
-				cal.b[z] |= ref.b[z] | externs.b[z];
-				ref.b[z] = 0;
-			}
-			break;
-
-		case ATEXT:
-			for(z=0; z<BITS; z++) {
-				cal.b[z] = 0;
-				ref.b[z] = 0;
-			}
-			break;
-
-		case ARET:
-			for(z=0; z<BITS; z++) {
-				cal.b[z] = externs.b[z];
-				ref.b[z] = 0;
-			}
-		}
-		for(z=0; z<BITS; z++) {
-			ref.b[z] = (ref.b[z] & ~r1->set.b[z]) |
-				r1->use1.b[z] | r1->use2.b[z];
-			cal.b[z] &= ~(r1->set.b[z] | r1->use1.b[z] | r1->use2.b[z]);
-			r1->refbehind.b[z] = ref.b[z];
-			r1->calbehind.b[z] = cal.b[z];
-		}
-		if(r1->active)
-			break;
-		r1->active = 1;
-	}
-	for(; r != r1; r = r->p1)
-		for(r2 = r->p2; r2 != R; r2 = r2->p2link)
-			prop(r2, r->refbehind, r->calbehind);
-}
-
-/*
- * find looping structure
- *
- * 1) find reverse postordering
- * 2) find approximate dominators,
- *	the actual dominators if the flow graph is reducible
- *	otherwise, dominators plus some other non-dominators.
- *	See Matthew S. Hecht and Jeffrey D. Ullman,
- *	"Analysis of a Simple Algorithm for Global Data Flow Problems",
- *	Conf.  Record of ACM Symp. on Principles of Prog. Langs, Boston, Massachusetts,
- *	Oct. 1-3, 1973, pp.  207-217.
- * 3) find all nodes with a predecessor dominated by the current node.
- *	such a node is a loop head.
- *	recursively, all preds with a greater rpo number are in the loop
- */
-int32_t
-postorder(Reg *r, Reg **rpo2r, int32_t n)
-{
-	Reg *r1;
-
-	r->rpo = 1;
-	r1 = r->s1;
-	if(r1 && !r1->rpo)
-		n = postorder(r1, rpo2r, n);
-	r1 = r->s2;
-	if(r1 && !r1->rpo)
-		n = postorder(r1, rpo2r, n);
-	rpo2r[n] = r;
-	n++;
-	return n;
-}
-
-int32_t
-rpolca(int32_t *idom, int32_t rpo1, int32_t rpo2)
-{
-	int32_t t;
-
-	if(rpo1 == -1)
-		return rpo2;
-	while(rpo1 != rpo2){
-		if(rpo1 > rpo2){
-			t = rpo2;
-			rpo2 = rpo1;
-			rpo1 = t;
-		}
-		while(rpo1 < rpo2){
-			t = idom[rpo2];
-			if(t >= rpo2)
-				fatal(Z, "bad idom");
-			rpo2 = t;
-		}
-	}
-	return rpo1;
-}
-
-int
-doms(int32_t *idom, int32_t r, int32_t s)
-{
-	while(s > r)
-		s = idom[s];
-	return s == r;
-}
-
-int
-loophead(int32_t *idom, Reg *r)
-{
-	int32_t src;
-
-	src = r->rpo;
-	if(r->p1 != R && doms(idom, src, r->p1->rpo))
-		return 1;
-	for(r = r->p2; r != R; r = r->p2link)
-		if(doms(idom, src, r->rpo))
-			return 1;
-	return 0;
-}
-
-void
-loopmark(Reg **rpo2r, int32_t head, Reg *r)
-{
-	if(r->rpo < head || r->active == head)
-		return;
-	r->active = head;
-	r->loop += LOOP;
-	if(r->p1 != R)
-		loopmark(rpo2r, head, r->p1);
-	for(r = r->p2; r != R; r = r->p2link)
-		loopmark(rpo2r, head, r);
-}
-
-void
-loopit(Reg *r, int32_t nr)
-{
-	Reg *r1;
-	int32_t i, d, me;
-
-	if(nr > maxnr) {
-		rpo2r = alloc(nr * sizeof(Reg*));
-		idom = alloc(nr * sizeof(int32_t));
-		maxnr = nr;
-	}
-
-	d = postorder(r, rpo2r, 0);
-	if(d > nr)
-		fatal(Z, "too many reg nodes");
-	nr = d;
-	for(i = 0; i < nr / 2; i++){
-		r1 = rpo2r[i];
-		rpo2r[i] = rpo2r[nr - 1 - i];
-		rpo2r[nr - 1 - i] = r1;
-	}
-	for(i = 0; i < nr; i++)
-		rpo2r[i]->rpo = i;
-
-	idom[0] = 0;
-	for(i = 0; i < nr; i++){
-		r1 = rpo2r[i];
-		me = r1->rpo;
-		d = -1;
-		if(r1->p1 != R && r1->p1->rpo < me)
-			d = r1->p1->rpo;
-		for(r1 = r1->p2; r1 != nil; r1 = r1->p2link)
-			if(r1->rpo < me)
-				d = rpolca(idom, d, r1->rpo);
-		idom[i] = d;
-	}
-
-	for(i = 0; i < nr; i++){
-		r1 = rpo2r[i];
-		r1->loop++;
-		if(r1->p2 != R && loophead(idom, r1))
-			loopmark(rpo2r, i, r1);
-	}
-}
-
-void
-synch(Reg *r, Bits dif)
-{
-	Reg *r1;
-	int z;
-
-	for(r1 = r; r1 != R; r1 = r1->s1) {
-		for(z=0; z<BITS; z++) {
-			dif.b[z] = (dif.b[z] &
-				~(~r1->refbehind.b[z] & r1->refahead.b[z])) |
-					r1->set.b[z] | r1->regdiff.b[z];
-			if(dif.b[z] != r1->regdiff.b[z]) {
-				r1->regdiff.b[z] = dif.b[z];
-				change++;
-			}
-		}
-		if(r1->active)
-			break;
-		r1->active = 1;
-		for(z=0; z<BITS; z++)
-			dif.b[z] &= ~(~r1->calbehind.b[z] & r1->calahead.b[z]);
-		if(r1->s2 != R)
-			synch(r1->s2, dif);
-	}
-}
-
-uint32_t
-allreg(uint32_t b, Rgn *r)
-{
-	Var *v;
-	int i;
-
-	v = var + r->varno;
-	r->regno = 0;
-	switch(v->etype) {
-
-	default:
-		diag(Z, "unknown etype %d/%d", bitno(b), v->etype);
-		break;
-
-	case TCHAR:
-	case TUCHAR:
-	case TSHORT:
-	case TUSHORT:
-	case TINT:
-	case TUINT:
-	case TLONG:
-	case TULONG:
-	case TIND:
-	case TARRAY:
-		i = BtoR(~b);
-		if(i && r->cost >= 0) {
-			r->regno = i;
-			return RtoB(i);
-		}
-		break;
-
-	case TVLONG:
-	case TDOUBLE:
-	case TFLOAT:
-		i = BtoF(~b);
-		if(i && r->cost >= 0) {
-			r->regno = i+NREG;
-			return FtoB(i);
-		}
-		break;
-	}
-	return 0;
-}
-
-void
-paint1(Reg *r, int bn)
-{
-	Reg *r1;
-	Prog *p;
-	int z;
-	uint32_t bb;
-
-	z = bn/32;
-	bb = 1L<<(bn%32);
-	if(r->act.b[z] & bb)
-		return;
-	for(;;) {
-		if(!(r->refbehind.b[z] & bb))
-			break;
-		r1 = r->p1;
-		if(r1 == R)
-			break;
-		if(!(r1->refahead.b[z] & bb))
-			break;
-		if(r1->act.b[z] & bb)
-			break;
-		r = r1;
-	}
-
-	if(LOAD(r) & ~(r->set.b[z] & ~(r->use1.b[z]|r->use2.b[z])) & bb) {
-		change -= CLOAD * r->loop;
-		if(debug['R'] && debug['v'])
-			print("%ld%P\tld %B $%d\n", r->loop,
-				r->prog, blsh(bn), change);
-	}
-	for(;;) {
-		r->act.b[z] |= bb;
-		p = r->prog;
-
-		if(r->use1.b[z] & bb) {
-			change += CREF * r->loop;
-			if(debug['R'] && debug['v'])
-				print("%ld%P\tu1 %B $%d\n", r->loop,
-					p, blsh(bn), change);
-		}
-
-		if((r->use2.b[z]|r->set.b[z]) & bb) {
-			change += CREF * r->loop;
-			if(debug['R'] && debug['v'])
-				print("%ld%P\tu2 %B $%d\n", r->loop,
-					p, blsh(bn), change);
-		}
-
-		if(STORE(r) & r->regdiff.b[z] & bb) {
-			change -= CLOAD * r->loop;
-			if(debug['R'] && debug['v'])
-				print("%ld%P\tst %B $%d\n", r->loop,
-					p, blsh(bn), change);
-		}
-
-		if(r->refbehind.b[z] & bb)
-			for(r1 = r->p2; r1 != R; r1 = r1->p2link)
-				if(r1->refahead.b[z] & bb)
-					paint1(r1, bn);
-
-		if(!(r->refahead.b[z] & bb))
-			break;
-		r1 = r->s2;
-		if(r1 != R)
-			if(r1->refbehind.b[z] & bb)
-				paint1(r1, bn);
-		r = r->s1;
-		if(r == R)
-			break;
-		if(r->act.b[z] & bb)
-			break;
-		if(!(r->refbehind.b[z] & bb))
-			break;
-	}
-}
-
-uint32_t
-paint2(Reg *r, int bn)
-{
-	Reg *r1;
-	int z;
-	uint32_t bb, vreg;
-
-	z = bn/32;
-	bb = 1L << (bn%32);
-	vreg = regbits;
-	if(!(r->act.b[z] & bb))
-		return vreg;
-	for(;;) {
-		if(!(r->refbehind.b[z] & bb))
-			break;
-		r1 = r->p1;
-		if(r1 == R)
-			break;
-		if(!(r1->refahead.b[z] & bb))
-			break;
-		if(!(r1->act.b[z] & bb))
-			break;
-		r = r1;
-	}
-	for(;;) {
-		r->act.b[z] &= ~bb;
-
-		vreg |= r->regu;
-
-		if(r->refbehind.b[z] & bb)
-			for(r1 = r->p2; r1 != R; r1 = r1->p2link)
-				if(r1->refahead.b[z] & bb)
-					vreg |= paint2(r1, bn);
-
-		if(!(r->refahead.b[z] & bb))
-			break;
-		r1 = r->s2;
-		if(r1 != R)
-			if(r1->refbehind.b[z] & bb)
-				vreg |= paint2(r1, bn);
-		r = r->s1;
-		if(r == R)
-			break;
-		if(!(r->act.b[z] & bb))
-			break;
-		if(!(r->refbehind.b[z] & bb))
-			break;
-	}
-	return vreg;
-}
-
-void
-paint3(Reg *r, int bn, int32_t rb, int rn)
-{
-	Reg *r1;
-	Prog *p;
-	int z;
-	uint32_t bb;
-
-	z = bn/32;
-	bb = 1L << (bn%32);
-	if(r->act.b[z] & bb)
-		return;
-	for(;;) {
-		if(!(r->refbehind.b[z] & bb))
-			break;
-		r1 = r->p1;
-		if(r1 == R)
-			break;
-		if(!(r1->refahead.b[z] & bb))
-			break;
-		if(r1->act.b[z] & bb)
-			break;
-		r = r1;
-	}
-
-	if(LOAD(r) & ~(r->set.b[z] & ~(r->use1.b[z]|r->use2.b[z])) & bb)
-		addmove(r, bn, rn, 0);
-	for(;;) {
-		r->act.b[z] |= bb;
-		p = r->prog;
-
-		if(r->use1.b[z] & bb) {
-			if(debug['R'])
-				print("%P", p);
-			addreg(&p->from, rn);
-			if(debug['R'])
-				print("\t.c%P\n", p);
-		}
-		if((r->use2.b[z]|r->set.b[z]) & bb) {
-			if(debug['R'])
-				print("%P", p);
-			addreg(&p->to, rn);
-			if(debug['R'])
-				print("\t.c%P\n", p);
-		}
-
-		if(STORE(r) & r->regdiff.b[z] & bb)
-			addmove(r, bn, rn, 1);
-		r->regu |= rb;
-
-		if(r->refbehind.b[z] & bb)
-			for(r1 = r->p2; r1 != R; r1 = r1->p2link)
-				if(r1->refahead.b[z] & bb)
-					paint3(r1, bn, rb, rn);
-
-		if(!(r->refahead.b[z] & bb))
-			break;
-		r1 = r->s2;
-		if(r1 != R)
-			if(r1->refbehind.b[z] & bb)
-				paint3(r1, bn, rb, rn);
-		r = r->s1;
-		if(r == R)
-			break;
-		if(r->act.b[z] & bb)
-			break;
-		if(!(r->refbehind.b[z] & bb))
-			break;
-	}
-}
-
-void
-addreg(Adr *a, int rn)
-{
-
-	a->sym = 0;
-	a->name = D_NONE;
-	a->type = D_REG;
-	a->reg = rn;
-	if(rn >= NREG) {
-		a->type = D_FREG;
-		a->reg = rn-NREG;
-	}
-}
-
-/*
- *	bit	reg
- *	0	R0
- *	1	R1
- *	...	...
- *	10	R10
- */
-int32_t
-RtoB(int r)
-{
-
-	if(r >= REGMIN && r <= REGMAX)
-		return 1L << r;
-	return 0;
-}
-
-int
-BtoR(int32_t b)
-{
-	b &= 0x01fcL;	// excluded R9 and R10 for m and g
-	if(b == 0)
-		return 0;
-	return bitno(b);
-}
-
-/*
- *	bit	reg
- *	18	F2
- *	19	F3
- *	...	...
- *	23	F7
- */
-int32_t
-FtoB(int f)
-{
-
-	if(f < 2 || f > NFREG-1)
-		return 0;
-	return 1L << (f + 16);
-}
-
-int
-BtoF(int32_t b)
-{
-
-	b &= 0xfc0000L;
-	if(b == 0)
-		return 0;
-	return bitno(b) - 16;
-}

+ 0 - 228
sys/src/cmd/5c/sgen.c

@@ -1,228 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "gc.h"
-
-void
-noretval(int n)
-{
-
-	if(n & 1) {
-		gins(ANOP, Z, Z);
-		p->to.type = D_REG;
-		p->to.reg = REGRET;
-	}
-	if(n & 2) {
-		gins(ANOP, Z, Z);
-		p->to.type = D_FREG;
-		p->to.reg = FREGRET;
-	}
-}
-
-/*
- *	calculate addressability as follows
- *		CONST ==> 20		$value
- *		NAME ==> 10		name
- *		REGISTER ==> 11		register
- *		INDREG ==> 12		*[(reg)+offset]
- *		&10 ==> 2		$name
- *		ADD(2, 20) ==> 2	$name+offset
- *		ADD(3, 20) ==> 3	$(reg)+offset
- *		&12 ==> 3		$(reg)+offset
- *		*11 ==> 11		??
- *		*2 ==> 10		name
- *		*3 ==> 12		*(reg)+offset
- *	calculate complexity (number of registers)
- */
-void
-xcom(Node *n)
-{
-	Node *l, *r;
-	int t;
-
-	if(n == Z)
-		return;
-	l = n->left;
-	r = n->right;
-	n->addable = 0;
-	n->complex = 0;
-	switch(n->op) {
-	case OCONST:
-		n->addable = 20;
-		return;
-
-	case OREGISTER:
-		n->addable = 11;
-		return;
-
-	case OINDREG:
-		n->addable = 12;
-		return;
-
-	case ONAME:
-		n->addable = 10;
-		return;
-
-	case OADDR:
-		xcom(l);
-		if(l->addable == 10)
-			n->addable = 2;
-		if(l->addable == 12)
-			n->addable = 3;
-		break;
-
-	case OIND:
-		xcom(l);
-		if(l->addable == 11)
-			n->addable = 12;
-		if(l->addable == 3)
-			n->addable = 12;
-		if(l->addable == 2)
-			n->addable = 10;
-		break;
-
-	case OADD:
-		xcom(l);
-		xcom(r);
-		if(l->addable == 20) {
-			if(r->addable == 2)
-				n->addable = 2;
-			if(r->addable == 3)
-				n->addable = 3;
-		}
-		if(r->addable == 20) {
-			if(l->addable == 2)
-				n->addable = 2;
-			if(l->addable == 3)
-				n->addable = 3;
-		}
-		break;
-
-	case OASLMUL:
-	case OASMUL:
-		xcom(l);
-		xcom(r);
-		t = vlog(r);
-		if(t >= 0) {
-			n->op = OASASHL;
-			r->vconst = t;
-			r->type = types[TINT];
-		}
-		break;
-
-	case OMUL:
-	case OLMUL:
-		xcom(l);
-		xcom(r);
-		t = vlog(r);
-		if(t >= 0) {
-			n->op = OASHL;
-			r->vconst = t;
-			r->type = types[TINT];
-		}
-		t = vlog(l);
-		if(t >= 0) {
-			n->op = OASHL;
-			n->left = r;
-			n->right = l;
-			r = l;
-			l = n->left;
-			r->vconst = t;
-			r->type = types[TINT];
-		}
-		break;
-
-	case OASLDIV:
-		xcom(l);
-		xcom(r);
-		t = vlog(r);
-		if(t >= 0) {
-			n->op = OASLSHR;
-			r->vconst = t;
-			r->type = types[TINT];
-		}
-		break;
-
-	case OLDIV:
-		xcom(l);
-		xcom(r);
-		t = vlog(r);
-		if(t >= 0) {
-			n->op = OLSHR;
-			r->vconst = t;
-			r->type = types[TINT];
-		}
-		break;
-
-	case OASLMOD:
-		xcom(l);
-		xcom(r);
-		t = vlog(r);
-		if(t >= 0) {
-			n->op = OASAND;
-			r->vconst--;
-		}
-		break;
-
-	case OLMOD:
-		xcom(l);
-		xcom(r);
-		t = vlog(r);
-		if(t >= 0) {
-			n->op = OAND;
-			r->vconst--;
-		}
-		break;
-
-	default:
-		if(l != Z)
-			xcom(l);
-		if(r != Z)
-			xcom(r);
-		break;
-	}
-	if(n->addable >= 10)
-		return;
-
-	if(l != Z)
-		n->complex = l->complex;
-	if(r != Z) {
-		if(r->complex == n->complex)
-			n->complex = r->complex+1;
-		else
-		if(r->complex > n->complex)
-			n->complex = r->complex;
-	}
-	if(n->complex == 0)
-		n->complex++;
-
-	if(com64(n))
-		return;
-
-	switch(n->op) {
-	case OFUNC:
-		n->complex = FNX;
-		break;
-
-	case OADD:
-	case OXOR:
-	case OAND:
-	case OOR:
-	case OEQ:
-	case ONE:
-		/*
-		 * immediate operators, make const on right
-		 */
-		if(l->op == OCONST) {
-			n->left = r;
-			n->right = l;
-		}
-		break;
-	}
-}

+ 0 - 628
sys/src/cmd/5c/swt.c

@@ -1,628 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "gc.h"
-
-void
-swit1(C1 *q, int nc, int32_t def, Node *n)
-{
-	Node tn;
-	
-	regalloc(&tn, &regnode, Z);
-	swit2(q, nc, def, n, &tn);
-	regfree(&tn);
-}
-
-void
-swit2(C1 *q, int nc, int32_t def, Node *n, Node *tn)
-{
-	C1 *r;
-	int i;
-	int32_t v;
-	Prog *sp;
-
-	if(nc >= 3) {
-		i = (q+nc-1)->val - (q+0)->val;
-		if(i > 0 && i < nc*2)
-			goto direct;
-	}
-	if(nc < 5) {
-		for(i=0; i<nc; i++) {
-			if(debug['K'])
-				print("case = %.8llux\n", q->val);
-			gopcode(OEQ, nodconst(q->val), n, Z);
-			patch(p, q->label);
-			q++;
-		}
-		gbranch(OGOTO);
-		patch(p, def);
-		return;
-	}
-
-	i = nc / 2;
-	r = q+i;
-	if(debug['K'])
-		print("case > %.8llux\n", r->val);
-	gopcode(OGT, nodconst(r->val), n, Z);
-	sp = p;
-	gopcode(OEQ, nodconst(r->val), n, Z);	/* just gen the B.EQ */
-	patch(p, r->label);
-	swit2(q, i, def, n, tn);
-
-	if(debug['K'])
-		print("case < %.8llux\n", r->val);
-	patch(sp, pc);
-	swit2(r+1, nc-i-1, def, n, tn);
-	return;
-
-direct:
-	v = q->val;
-	if(v != 0)
-		gopcode(OSUB, nodconst(v), Z, n);
-	gopcode(OCASE, nodconst((q+nc-1)->val - v), n, Z);
-	patch(p, def);
-	for(i=0; i<nc; i++) {
-		if(debug['K'])
-			print("case = %.8llux\n", q->val);
-		while(q->val != v) {
-			nextpc();
-			p->as = ABCASE;
-			patch(p, def);
-			v++;
-		}
-		nextpc();
-		p->as = ABCASE;
-		patch(p, q->label);
-		q++;
-		v++;
-	}
-	gbranch(OGOTO);		/* so that regopt() won't be confused */
-	patch(p, def);
-}
-
-void
-bitload(Node *b, Node *n1, Node *n2, Node *n3, Node *nn)
-{
-	int sh;
-	int32_t v;
-	Node *l;
-
-	/*
-	 * n1 gets adjusted/masked value
-	 * n2 gets address of cell
-	 * n3 gets contents of cell
-	 */
-	l = b->left;
-	if(n2 != Z) {
-		regalloc(n1, l, nn);
-		reglcgen(n2, l, Z);
-		regalloc(n3, l, Z);
-		gopcode(OAS, n2, Z, n3);
-		gopcode(OAS, n3, Z, n1);
-	} else {
-		regalloc(n1, l, nn);
-		cgen(l, n1);
-	}
-	if(b->type->shift == 0 && typeu[b->type->etype]) {
-		v = ~0 + (1L << b->type->nbits);
-		gopcode(OAND, nodconst(v), Z, n1);
-	} else {
-		sh = 32 - b->type->shift - b->type->nbits;
-		if(sh > 0)
-			gopcode(OASHL, nodconst(sh), Z, n1);
-		sh += b->type->shift;
-		if(sh > 0)
-			if(typeu[b->type->etype])
-				gopcode(OLSHR, nodconst(sh), Z, n1);
-			else
-				gopcode(OASHR, nodconst(sh), Z, n1);
-	}
-}
-
-void
-bitstore(Node *b, Node *n1, Node *n2, Node *n3, Node *nn)
-{
-	int32_t v;
-	Node nod, *l;
-	int sh;
-
-	/*
-	 * n1 has adjusted/masked value
-	 * n2 has address of cell
-	 * n3 has contents of cell
-	 */
-	l = b->left;
-	regalloc(&nod, l, Z);
-	v = ~0 + (1L << b->type->nbits);
-	gopcode(OAND, nodconst(v), Z, n1);
-	gopcode(OAS, n1, Z, &nod);
-	if(nn != Z)
-		gopcode(OAS, n1, Z, nn);
-	sh = b->type->shift;
-	if(sh > 0)
-		gopcode(OASHL, nodconst(sh), Z, &nod);
-	v <<= sh;
-	gopcode(OAND, nodconst(~v), Z, n3);
-	gopcode(OOR, n3, Z, &nod);
-	gopcode(OAS, &nod, Z, n2);
-
-	regfree(&nod);
-	regfree(n1);
-	regfree(n2);
-	regfree(n3);
-}
-
-int32_t
-outstring(char *s, int32_t n)
-{
-	int32_t r;
-
-	if(suppress)
-		return nstring;
-	r = nstring;
-	while(n) {
-		string[mnstring] = *s++;
-		mnstring++;
-		nstring++;
-		if(mnstring >= NSNAME) {
-			gpseudo(ADATA, symstring, nodconst(0L));
-			p->from.offset += nstring - NSNAME;
-			p->reg = NSNAME;
-			p->to.type = D_SCONST;
-			memmove(p->to.sval, string, NSNAME);
-			mnstring = 0;
-		}
-		n--;
-	}
-	return r;
-}
-
-int
-mulcon(Node *n, Node *nn)
-{
-	Node *l, *r, nod1, nod2;
-	Multab *m;
-	int32_t v, vs;
-	int o;
-	char code[sizeof(m->code)+2], *p;
-
-	if(typefd[n->type->etype])
-		return 0;
-	l = n->left;
-	r = n->right;
-	if(l->op == OCONST) {
-		l = r;
-		r = n->left;
-	}
-	if(r->op != OCONST)
-		return 0;
-	v = convvtox(r->vconst, n->type->etype);
-	if(v != r->vconst) {
-		if(debug['M'])
-			print("%L multiply conv: %lld\n", n->lineno, r->vconst);
-		return 0;
-	}
-	m = mulcon0(v);
-	if(!m) {
-		if(debug['M'])
-			print("%L multiply table: %lld\n", n->lineno, r->vconst);
-		return 0;
-	}
-	if(debug['M'] && debug['v'])
-		print("%L multiply: %ld\n", n->lineno, v);
-
-	memmove(code, m->code, sizeof(m->code));
-	code[sizeof(m->code)] = 0;
-
-	p = code;
-	if(p[1] == 'i')
-		p += 2;
-	regalloc(&nod1, n, nn);
-	cgen(l, &nod1);
-	vs = v;
-	regalloc(&nod2, n, Z);
-
-loop:
-	switch(*p) {
-	case 0:
-		regfree(&nod2);
-		if(vs < 0) {
-			gopcode(OAS, &nod1, Z, &nod1);
-			gopcode(OSUB, &nod1, nodconst(0), nn);
-		} else 
-			gopcode(OAS, &nod1, Z, nn);
-		regfree(&nod1);
-		return 1;
-	case '+':
-		o = OADD;
-		goto addsub;
-	case '-':
-		o = OSUB;
-	addsub:	/* number is r,n,l */
-		v = p[1] - '0';
-		r = &nod1;
-		if(v&4)
-			r = &nod2;
-		n = &nod1;
-		if(v&2)
-			n = &nod2;
-		l = &nod1;
-		if(v&1)
-			l = &nod2;
-		gopcode(o, l, n, r);
-		break;
-	default: /* op is shiftcount, number is r,l */
-		v = p[1] - '0';
-		r = &nod1;
-		if(v&2)
-			r = &nod2;
-		l = &nod1;
-		if(v&1)
-			l = &nod2;
-		v = *p - 'a';
-		if(v < 0 || v >= 32) {
-			diag(n, "mulcon unknown op: %c%c", p[0], p[1]);
-			break;
-		}
-		gopcode(OASHL, nodconst(v), l, r);
-		break;
-	}
-	p += 2;
-	goto loop;
-}
-
-void
-gextern(Sym *s, Node *a, int32_t o, int32_t w)
-{
-
-	if(a->op == OCONST && typev[a->type->etype]) {
-		if(align(0, types[TCHAR], Aarg1))	/* isbigendian */
-			gpseudo(ADATA, s, nod32const(a->vconst>>32));
-		else
-			gpseudo(ADATA, s, nod32const(a->vconst));
-		p->from.offset += o;
-		p->reg = 4;
-		if(align(0, types[TCHAR], Aarg1))	/* isbigendian */
-			gpseudo(ADATA, s, nod32const(a->vconst));
-		else
-			gpseudo(ADATA, s, nod32const(a->vconst>>32));
-		p->from.offset += o + 4;
-		p->reg = 4;
-		return;
-	}
-	gpseudo(ADATA, s, a);
-	p->from.offset += o;
-	p->reg = w;
-	if(p->to.type == D_OREG)
-		p->to.type = D_CONST;
-}
-
-void	zname(Biobuf*, Sym*, int);
-char*	zaddr(char*, Adr*, int);
-void	zwrite(Biobuf*, Prog*, int, int);
-void	outhist(Biobuf*);
-
-void
-zwrite(Biobuf *b, Prog *p, int sf, int st)
-{
-	char bf[100], *bp;
-
-	bf[0] = p->as;
-	bf[1] = p->scond;
-	bf[2] = p->reg;
-	bf[3] = p->lineno;
-	bf[4] = p->lineno>>8;
-	bf[5] = p->lineno>>16;
-	bf[6] = p->lineno>>24;
-	bp = zaddr(bf+7, &p->from, sf);
-	bp = zaddr(bp, &p->to, st);
-	Bwrite(b, bf, bp-bf);
-}
-
-void
-outcode(void)
-{
-	struct { Sym *sym; int16_t type; } h[NSYM];
-	Prog *p;
-	Sym *s;
-	int sf, st, t, sym;
-
-	if(debug['S']) {
-		for(p = firstp; p != P; p = p->link)
-			if(p->as != ADATA && p->as != AGLOBL)
-				pc--;
-		for(p = firstp; p != P; p = p->link) {
-			print("%P\n", p);
-			if(p->as != ADATA && p->as != AGLOBL)
-				pc++;
-		}
-	}
-	outhist(&outbuf);
-	for(sym=0; sym<NSYM; sym++) {
-		h[sym].sym = S;
-		h[sym].type = 0;
-	}
-	sym = 1;
-	for(p = firstp; p != P; p = p->link) {
-	jackpot:
-		sf = 0;
-		s = p->from.sym;
-		while(s != S) {
-			sf = s->sym;
-			if(sf < 0 || sf >= NSYM)
-				sf = 0;
-			t = p->from.name;
-			if(h[sf].type == t)
-			if(h[sf].sym == s)
-				break;
-			s->sym = sym;
-			zname(&outbuf, s, t);
-			h[sym].sym = s;
-			h[sym].type = t;
-			sf = sym;
-			sym++;
-			if(sym >= NSYM)
-				sym = 1;
-			break;
-		}
-		st = 0;
-		s = p->to.sym;
-		while(s != S) {
-			st = s->sym;
-			if(st < 0 || st >= NSYM)
-				st = 0;
-			t = p->to.name;
-			if(h[st].type == t)
-			if(h[st].sym == s)
-				break;
-			s->sym = sym;
-			zname(&outbuf, s, t);
-			h[sym].sym = s;
-			h[sym].type = t;
-			st = sym;
-			sym++;
-			if(sym >= NSYM)
-				sym = 1;
-			if(st == sf)
-				goto jackpot;
-			break;
-		}
-		zwrite(&outbuf, p, sf, st);
-	}
-	firstp = P;
-	lastp = P;
-}
-
-void
-outhist(Biobuf *b)
-{
-	Hist *h;
-	char *p, *q, *op, c;
-	Prog pg;
-	int n;
-
-	pg = zprog;
-	pg.as = AHISTORY;
-	c = pathchar();
-	for(h = hist; h != H; h = h->link) {
-		p = h->name;
-		op = 0;
-		/* on windows skip drive specifier in pathname */
-		if(systemtype(Windows) && p && p[1] == ':'){
-			p += 2;
-			c = *p;
-		}
-		if(p && p[0] != c && h->offset == 0 && pathname){
-			/* on windows skip drive specifier in pathname */
-			if(systemtype(Windows) && pathname[1] == ':') {
-				op = p;
-				p = pathname+2;
-				c = *p;
-			} else if(pathname[0] == c){
-				op = p;
-				p = pathname;
-			}
-		}
-		while(p) {
-			q = utfrune(p, c);
-			if(q) {
-				n = q-p;
-				if(n == 0){
-					n = 1;	/* leading "/" */
-					*p = '/';	/* don't emit "\" on windows */
-				}
-				q++;
-			} else {
-				n = strlen(p);
-				q = 0;
-			}
-			if(n) {
-				Bputc(b, ANAME);
-				Bputc(b, D_FILE);
-				Bputc(b, 1);
-				Bputc(b, '<');
-				Bwrite(b, p, n);
-				Bputc(b, 0);
-			}
-			p = q;
-			if(p == 0 && op) {
-				p = op;
-				op = 0;
-			}
-		}
-		pg.lineno = h->line;
-		pg.to.type = zprog.to.type;
-		pg.to.offset = h->offset;
-		if(h->offset)
-			pg.to.type = D_CONST;
-
-		zwrite(b, &pg, 0, 0);
-	}
-}
-
-void
-zname(Biobuf *b, Sym *s, int t)
-{
-	char *n, bf[7];
-	uint32_t sig;
-
-	n = s->name;
-	if(debug['T'] && t == D_EXTERN && s->sig != SIGDONE && s->type != types[TENUM] && s != symrathole){
-		sig = sign(s);
-		bf[0] = ASIGNAME;
-		bf[1] = sig;
-		bf[2] = sig>>8;
-		bf[3] = sig>>16;
-		bf[4] = sig>>24;
-		bf[5] = t;
-		bf[6] = s->sym;
-		Bwrite(b, bf, 7);
-		s->sig = SIGDONE;
-	}
-	else{
-		bf[0] = ANAME;
-		bf[1] = t;	/* type */
-		bf[2] = s->sym;	/* sym */
-		Bwrite(b, bf, 3);
-	}
-	Bwrite(b, n, strlen(n)+1);
-}
-
-char*
-zaddr(char *bp, Adr *a, int s)
-{
-	int32_t l;
-	Ieee e;
-
-	bp[0] = a->type;
-	bp[1] = a->reg;
-	bp[2] = s;
-	bp[3] = a->name;
-	bp += 4;
-	switch(a->type) {
-	default:
-		diag(Z, "unknown type %d in zaddr", a->type);
-
-	case D_NONE:
-	case D_REG:
-	case D_FREG:
-	case D_PSR:
-		break;
-
-	case D_OREG:
-	case D_CONST:
-	case D_BRANCH:
-	case D_SHIFT:
-		l = a->offset;
-		bp[0] = l;
-		bp[1] = l>>8;
-		bp[2] = l>>16;
-		bp[3] = l>>24;
-		bp += 4;
-		break;
-
-	case D_SCONST:
-		memmove(bp, a->sval, NSNAME);
-		bp += NSNAME;
-		break;
-
-	case D_FCONST:
-		ieeedtod(&e, a->dval);
-		l = e.l;
-		bp[0] = l;
-		bp[1] = l>>8;
-		bp[2] = l>>16;
-		bp[3] = l>>24;
-		bp += 4;
-		l = e.h;
-		bp[0] = l;
-		bp[1] = l>>8;
-		bp[2] = l>>16;
-		bp[3] = l>>24;
-		bp += 4;
-		break;
-	}
-	return bp;
-}
-
-int32_t
-align(int32_t i, Type *t, int op)
-{
-	int32_t o;
-	Type *v;
-	int w;
-
-	o = i;
-	w = 1;
-	switch(op) {
-	default:
-		diag(Z, "unknown align opcode %d", op);
-		break;
-
-	case Asu2:	/* padding at end of a struct */
-		w = SZ_LONG;
-		if(packflg)
-			w = packflg;
-		break;
-
-	case Ael1:	/* initial align of struct element */
-		for(v=t; v->etype==TARRAY; v=v->link)
-			;
-		w = ewidth[v->etype];
-		if(w <= 0 || w >= SZ_LONG)
-			w = SZ_LONG;
-		if(packflg)
-			w = packflg;
-		break;
-
-	case Ael2:	/* width of a struct element */
-		o += t->width;
-		break;
-
-	case Aarg0:	/* initial passbyptr argument in arg list */
-		if(typesuv[t->etype]) {
-			o = align(o, types[TIND], Aarg1);
-			o = align(o, types[TIND], Aarg2);
-		}
-		break;
-
-	case Aarg1:	/* initial align of parameter */
-		w = ewidth[t->etype];
-		if(w <= 0 || w >= SZ_LONG) {
-			w = SZ_LONG;
-			break;
-		}
-		w = 1;		/* little endian no adjustment */
-		break;
-
-	case Aarg2:	/* width of a parameter */
-		o += t->width;
-		w = SZ_LONG;
-		break;
-
-	case Aaut3:	/* total align of automatic */
-		o = align(o, t, Ael2);
-		o = align(o, t, Ael1);
-		w = SZ_LONG;	/* because of a pun in cc/dcl.c:contig() */
-		break;
-	}
-	o = round(o, w);
-	if(debug['A'])
-		print("align %s %ld %T = %ld\n", bnames[op], i, t, o);
-	return o;
-}
-
-int32_t
-maxround(int32_t max, int32_t v)
-{
-	v = round(v, SZ_LONG);
-	if(v > max)
-		return v;
-	return max;
-}

+ 0 - 1322
sys/src/cmd/5c/txt.c

@@ -1,1322 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "gc.h"
-
-static	char	resvreg[nelem(reg)];
-
-void
-ginit(void)
-{
-	Type *t;
-
-	thechar = '5';
-	thestring = "arm";
-	exregoffset = REGEXT;
-	exfregoffset = FREGEXT;
-	listinit();
-	nstring = 0;
-	mnstring = 0;
-	nrathole = 0;
-	pc = 0;
-	breakpc = -1;
-	continpc = -1;
-	cases = C;
-	firstp = P;
-	lastp = P;
-	tfield = types[TLONG];
-
-	zprog.link = P;
-	zprog.as = AGOK;
-	zprog.reg = NREG;
-	zprog.from.type = D_NONE;
-	zprog.from.name = D_NONE;
-	zprog.from.reg = NREG;
-	zprog.to = zprog.from;
-	zprog.scond = 0xE;  
-
-	regnode.op = OREGISTER;
-	regnode.class = CEXREG;
-	regnode.reg = REGTMP;
-	regnode.complex = 0;
-	regnode.addable = 11;
-	regnode.type = types[TLONG];
-
-	constnode.op = OCONST;
-	constnode.class = CXXX;
-	constnode.complex = 0;
-	constnode.addable = 20;
-	constnode.type = types[TLONG];
-
-	fconstnode.op = OCONST;
-	fconstnode.class = CXXX;
-	fconstnode.complex = 0;
-	fconstnode.addable = 20;
-	fconstnode.type = types[TDOUBLE];
-
-	nodsafe = new(ONAME, Z, Z);
-	nodsafe->sym = slookup(".safe");
-	nodsafe->type = types[TINT];
-	nodsafe->etype = types[TINT]->etype;
-	nodsafe->class = CAUTO;
-	complex(nodsafe);
-
-	t = typ(TARRAY, types[TCHAR]);
-	symrathole = slookup(".rathole");
-	symrathole->class = CGLOBL;
-	symrathole->type = t;
-
-	nodrat = new(ONAME, Z, Z);
-	nodrat->sym = symrathole;
-	nodrat->type = types[TIND];
-	nodrat->etype = TVOID;
-	nodrat->class = CGLOBL;
-	complex(nodrat);
-	nodrat->type = t;
-
-	nodret = new(ONAME, Z, Z);
-	nodret->sym = slookup(".ret");
-	nodret->type = types[TIND];
-	nodret->etype = TIND;
-	nodret->class = CPARAM;
-	nodret = new(OIND, nodret, Z);
-	complex(nodret);
-
-	com64init();
-
-	memset(reg, 0, sizeof(reg));
-	/* don't allocate */
-	reg[REGTMP] = 1;
-	reg[REGSB] = 1;
-	reg[REGSP] = 1;
-	reg[REGLINK] = 1;
-	reg[REGPC] = 1;
-	/* keep two external registers */
-	reg[REGEXT] = 1;
-	reg[REGEXT-1] = 1;
-	memmove(resvreg, reg, sizeof(reg));
-}
-
-void
-gclean(void)
-{
-	int i;
-	Sym *s;
-
-	for(i=0; i<NREG; i++)
-		if(reg[i] && !resvreg[i])
-			diag(Z, "reg %d left allocated", i);
-	for(i=NREG; i<NREG+NFREG; i++)
-		if(reg[i] && !resvreg[i])
-			diag(Z, "freg %d left allocated", i-NREG);
-	while(mnstring)
-		outstring("", 1L);
-	symstring->type->width = nstring;
-	symrathole->type->width = nrathole;
-	for(i=0; i<NHASH; i++)
-	for(s = hash[i]; s != S; s = s->link) {
-		if(s->type == T)
-			continue;
-		if(s->type->width == 0)
-			continue;
-		if(s->class != CGLOBL && s->class != CSTATIC)
-			continue;
-		if(s->type == types[TENUM])
-			continue;
-		gpseudo(AGLOBL, s, nodconst(s->type->width));
-	}
-	nextpc();
-	p->as = AEND;
-	outcode();
-}
-
-void
-nextpc(void)
-{
-
-	p = alloc(sizeof(*p));
-	*p = zprog;
-	p->lineno = nearln;
-	pc++;
-	if(firstp == P) {
-		firstp = p;
-		lastp = p;
-		return;
-	}
-	lastp->link = p;
-	lastp = p;
-}
-
-void
-gargs(Node *n, Node *tn1, Node *tn2)
-{
-	int32_t regs;
-	Node fnxargs[20], *fnxp;
-
-	regs = cursafe;
-
-	fnxp = fnxargs;
-	garg1(n, tn1, tn2, 0, &fnxp);	/* compile fns to temps */
-
-	curarg = 0;
-	fnxp = fnxargs;
-	garg1(n, tn1, tn2, 1, &fnxp);	/* compile normal args and temps */
-
-	cursafe = regs;
-}
-
-void
-garg1(Node *n, Node *tn1, Node *tn2, int f, Node **fnxp)
-{
-	Node nod;
-
-	if(n == Z)
-		return;
-	if(n->op == OLIST) {
-		garg1(n->left, tn1, tn2, f, fnxp);
-		garg1(n->right, tn1, tn2, f, fnxp);
-		return;
-	}
-	if(f == 0) {
-		if(n->complex >= FNX) {
-			regsalloc(*fnxp, n);
-			nod = znode;
-			nod.op = OAS;
-			nod.left = *fnxp;
-			nod.right = n;
-			nod.type = n->type;
-			cgen(&nod, Z);
-			(*fnxp)++;
-		}
-		return;
-	}
-	if(typesuv[n->type->etype]) {
-		regaalloc(tn2, n);
-		if(n->complex >= FNX) {
-			sugen(*fnxp, tn2, n->type->width);
-			(*fnxp)++;
-		} else
-			sugen(n, tn2, n->type->width);
-		return;
-	}
-	if(REGARG >= 0 && curarg == 0 && typechlp[n->type->etype]) {
-		regaalloc1(tn1, n);
-		if(n->complex >= FNX) {
-			cgen(*fnxp, tn1);
-			(*fnxp)++;
-		} else
-			cgen(n, tn1);
-		return;
-	}
-	regalloc(tn1, n, Z);
-	if(n->complex >= FNX) {
-		cgen(*fnxp, tn1);
-		(*fnxp)++;
-	} else
-		cgen(n, tn1);
-	regaalloc(tn2, n);
-	gopcode(OAS, tn1, Z, tn2);
-	regfree(tn1);
-}
-
-Node*
-nodconst(int32_t v)
-{
-	constnode.vconst = v;
-	return &constnode;
-}
-
-Node*
-nod32const(int64_t v)
-{
-	constnode.vconst = v & MASK(32);
-	return &constnode;
-}
-
-Node*
-nodfconst(double d)
-{
-	fconstnode.fconst = d;
-	return &fconstnode;
-}
-
-void
-nodreg(Node *n, Node *nn, int reg)
-{
-	*n = regnode;
-	n->reg = reg;
-	n->type = nn->type;
-	n->lineno = nn->lineno;
-}
-
-void
-regret(Node *n, Node *nn)
-{
-	int r;
-
-	r = REGRET;
-	if(typefd[nn->type->etype])
-		r = FREGRET+NREG;
-	nodreg(n, nn, r);
-	reg[r]++;
-}
-
-int
-tmpreg(void)
-{
-	int i;
-
-	for(i=REGRET+1; i<NREG; i++)
-		if(reg[i] == 0)
-			return i;
-	diag(Z, "out of fixed registers");
-	return 0;
-}
-
-void
-regalloc(Node *n, Node *tn, Node *o)
-{
-	int i, j;
-	static int lasti;
-
-	switch(tn->type->etype) {
-	case TCHAR:
-	case TUCHAR:
-	case TSHORT:
-	case TUSHORT:
-	case TINT:
-	case TUINT:
-	case TLONG:
-	case TULONG:
-	case TIND:
-		if(o != Z && o->op == OREGISTER) {
-			i = o->reg;
-			if(i >= 0 && i < NREG)
-				goto out;
-		}
-		j = lasti + REGRET+1;
-		for(i=REGRET+1; i<NREG; i++) {
-			if(j >= NREG)
-				j = REGRET+1;
-			if(reg[j] == 0 && resvreg[j] == 0) {
-				i = j;
-				goto out;
-			}
-			j++;
-		}
-		diag(tn, "out of fixed registers");
-		goto err;
-
-	case TFLOAT:
-	case TDOUBLE:
-	case TVLONG:
-		if(o != Z && o->op == OREGISTER) {
-			i = o->reg;
-			if(i >= NREG && i < NREG+NFREG)
-				goto out;
-		}
-		j = 0*2 + NREG;
-		for(i=NREG; i<NREG+NFREG; i++) {
-			if(j >= NREG+NFREG)
-				j = NREG;
-			if(reg[j] == 0) {
-				i = j;
-				goto out;
-			}
-			j++;
-		}
-		diag(tn, "out of float registers");
-		goto err;
-	}
-	diag(tn, "unknown type in regalloc: %T", tn->type);
-err:
-	nodreg(n, tn, 0);
-	return;
-out:
-	reg[i]++;
-	lasti++;
-	if(lasti >= 5)
-		lasti = 0;
-	nodreg(n, tn, i);
-}
-
-void
-regialloc(Node *n, Node *tn, Node *o)
-{
-	Node nod;
-
-	nod = *tn;
-	nod.type = types[TIND];
-	regalloc(n, &nod, o);
-}
-
-void
-regfree(Node *n)
-{
-	int i;
-
-	i = 0;
-	if(n->op != OREGISTER && n->op != OINDREG)
-		goto err;
-	i = n->reg;
-	if(i < 0 || i >= sizeof(reg))
-		goto err;
-	if(reg[i] <= 0)
-		goto err;
-	reg[i]--;
-	return;
-err:
-	diag(n, "error in regfree: %d", i);
-}
-
-void
-regsalloc(Node *n, Node *nn)
-{
-	cursafe = align(cursafe, nn->type, Aaut3);
-	maxargsafe = maxround(maxargsafe, cursafe+curarg);
-	*n = *nodsafe;
-	n->xoffset = -(stkoff + cursafe);
-	n->type = nn->type;
-	n->etype = nn->type->etype;
-	n->lineno = nn->lineno;
-}
-
-void
-regaalloc1(Node *n, Node *nn)
-{
-	nodreg(n, nn, REGARG);
-	reg[REGARG]++;
-	curarg = align(curarg, nn->type, Aarg1);
-	curarg = align(curarg, nn->type, Aarg2);
-	maxargsafe = maxround(maxargsafe, cursafe+curarg);
-}
-
-void
-regaalloc(Node *n, Node *nn)
-{
-	curarg = align(curarg, nn->type, Aarg1);
-	*n = *nn;
-	n->op = OINDREG;
-	n->reg = REGSP;
-	n->xoffset = curarg + SZ_LONG;
-	n->complex = 0;
-	n->addable = 20;
-	curarg = align(curarg, nn->type, Aarg2);
-	maxargsafe = maxround(maxargsafe, cursafe+curarg);
-}
-
-void
-regind(Node *n, Node *nn)
-{
-
-	if(n->op != OREGISTER) {
-		diag(n, "regind not OREGISTER");
-		return;
-	}
-	n->op = OINDREG;
-	n->type = nn->type;
-}
-
-void
-raddr(Node *n, Prog *p)
-{
-	Adr a;
-
-	naddr(n, &a);
-	if(R0ISZERO && a.type == D_CONST && a.offset == 0) {
-		a.type = D_REG;
-		a.reg = 0;
-	}
-	if(a.type != D_REG && a.type != D_FREG) {
-		if(n)
-			diag(n, "bad in raddr: %O", n->op);
-		else
-			diag(n, "bad in raddr: <null>");
-		p->reg = NREG;
-	} else
-		p->reg = a.reg;
-}
-
-void
-naddr(Node *n, Adr *a)
-{
-	int32_t v;
-
-	a->type = D_NONE;
-	if(n == Z)
-		return;
-	switch(n->op) {
-	default:
-	bad:
-		diag(n, "bad in naddr: %O", n->op);
-		break;
-
-	case OREGISTER:
-		a->type = D_REG;
-		a->sym = S;
-		a->reg = n->reg;
-		if(a->reg >= NREG) {
-			a->type = D_FREG;
-			a->reg -= NREG;
-		}
-		break;
-
-	case OIND:
-		naddr(n->left, a);
-		if(a->type == D_REG) {
-			a->type = D_OREG;
-			break;
-		}
-		if(a->type == D_CONST) {
-			a->type = D_OREG;
-			break;
-		}
-		goto bad;
-
-	case OINDREG:
-		a->type = D_OREG;
-		a->sym = S;
-		a->offset = n->xoffset;
-		a->reg = n->reg;
-		break;
-
-	case ONAME:
-		a->etype = n->etype;
-		a->type = D_OREG;
-		a->name = D_STATIC;
-		a->sym = n->sym;
-		a->offset = n->xoffset;
-		if(n->class == CSTATIC)
-			break;
-		if(n->class == CEXTERN || n->class == CGLOBL) {
-			a->name = D_EXTERN;
-			break;
-		}
-		if(n->class == CAUTO) {
-			a->name = D_AUTO;
-			break;
-		}
-		if(n->class == CPARAM) {
-			a->name = D_PARAM;
-			break;
-		}
-		goto bad;
-
-	case OCONST:
-		a->sym = S;
-		a->reg = NREG;
-		if(typefd[n->type->etype]) {
-			a->type = D_FCONST;
-			a->dval = n->fconst;
-		} else {
-			a->type = D_CONST;
-			a->offset = n->vconst;
-		}
-		break;
-
-	case OADDR:
-		naddr(n->left, a);
-		if(a->type == D_OREG) {
-			a->type = D_CONST;
-			break;
-		}
-		goto bad;
-
-	case OADD:
-		if(n->left->op == OCONST) {
-			naddr(n->left, a);
-			v = a->offset;
-			naddr(n->right, a);
-		} else {
-			naddr(n->right, a);
-			v = a->offset;
-			naddr(n->left, a);
-		}
-		a->offset += v;
-		break;
-
-	}
-}
-
-void
-fop(int as, int f1, int f2, Node *t)
-{
-	Node nod1, nod2, nod3;
-
-	nodreg(&nod1, t, NREG+f1);
-	nodreg(&nod2, t, NREG+f2);
-	regalloc(&nod3, t, t);
-	gopcode(as, &nod1, &nod2, &nod3);
-	gmove(&nod3, t);
-	regfree(&nod3);
-}
-
-void
-gmovm(Node *f, Node *t, int w)
-{
-	gins(AMOVM, f, t);
-	p->scond |= C_UBIT;
-	if(w)
-		p->scond |= C_WBIT;
-}
-
-void
-gmove(Node *f, Node *t)
-{
-	int ft, tt, a;
-	Node nod, nod1;
-	Prog *p1;
-
-	ft = f->type->etype;
-	tt = t->type->etype;
-
-	if(ft == TDOUBLE && f->op == OCONST) {
-	}
-	if(ft == TFLOAT && f->op == OCONST) {
-	}
-
-	/*
-	 * a load --
-	 * put it into a register then
-	 * worry what to do with it.
-	 */
-	if(f->op == ONAME || f->op == OINDREG || f->op == OIND) {
-		switch(ft) {
-		default:
-			a = AMOVW;
-			break;
-		case TFLOAT:
-			a = AMOVF;
-			break;
-		case TDOUBLE:
-			a = AMOVD;
-			break;
-		case TCHAR:
-			a = AMOVB;
-			break;
-		case TUCHAR:
-			a = AMOVBU;
-			break;
-		case TSHORT:
-			a = AMOVH;
-			break;
-		case TUSHORT:
-			a = AMOVHU;
-			break;
-		}
-		if(typechlp[ft] && typeilp[tt])
-			regalloc(&nod, t, t);
-		else
-			regalloc(&nod, f, t);
-		gins(a, f, &nod);
-		gmove(&nod, t);
-		regfree(&nod);
-		return;
-	}
-
-	/*
-	 * a store --
-	 * put it into a register then
-	 * store it.
-	 */
-	if(t->op == ONAME || t->op == OINDREG || t->op == OIND) {
-		switch(tt) {
-		default:
-			a = AMOVW;
-			break;
-		case TUCHAR:
-			a = AMOVBU;
-			break;
-		case TCHAR:
-			a = AMOVB;
-			break;
-		case TUSHORT:
-			a = AMOVHU;
-			break;
-		case TSHORT:
-			a = AMOVH;
-			break;
-		case TFLOAT:
-			a = AMOVF;
-			break;
-		case TVLONG:
-		case TDOUBLE:
-			a = AMOVD;
-			break;
-		}
-		if(ft == tt)
-			regalloc(&nod, t, f);
-		else
-			regalloc(&nod, t, Z);
-		gmove(f, &nod);
-		gins(a, &nod, t);
-		regfree(&nod);
-		return;
-	}
-
-	/*
-	 * type x type cross table
-	 */
-	a = AGOK;
-	switch(ft) {
-	case TDOUBLE:
-	case TVLONG:
-	case TFLOAT:
-		switch(tt) {
-		case TDOUBLE:
-		case TVLONG:
-			a = AMOVD;
-			if(ft == TFLOAT)
-				a = AMOVFD;
-			break;
-		case TFLOAT:
-			a = AMOVDF;
-			if(ft == TFLOAT)
-				a = AMOVF;
-			break;
-		case TINT:
-		case TUINT:
-		case TLONG:
-		case TULONG:
-		case TIND:
-			a = AMOVDW;
-			if(ft == TFLOAT)
-				a = AMOVFW;
-			break;
-		case TSHORT:
-		case TUSHORT:
-		case TCHAR:
-		case TUCHAR:
-			a = AMOVDW;
-			if(ft == TFLOAT)
-				a = AMOVFW;
-			break;
-		}
-		break;
-	case TUINT:
-	case TULONG:
-		if(tt == TFLOAT || tt == TDOUBLE) {
-			// ugly and probably longer than necessary,
-			// but vfp has a single instruction for this,
-			// so hopefully it won't last long.
-			//
-			//	tmp = f
-			//	tmp1 = tmp & 0x80000000
-			//	tmp ^= tmp1
-			//	t = float(int32(tmp))
-			//	if(tmp1)
-			//		t += 2147483648.
-			//
-			regalloc(&nod, f, Z);
-			regalloc(&nod1, f, Z);
-			gins(AMOVW, f, &nod);
-			gins(AMOVW, &nod, &nod1);
-			gins(AAND, nodconst(0x80000000), &nod1);
-			gins(AEOR, &nod1, &nod);
-			if(tt == TFLOAT)
-				gins(AMOVWF, &nod, t);
-			else
-				gins(AMOVWD, &nod, t);
-			gins(ACMP, nodconst(0), Z);
-			raddr(&nod1, p);
-			gins(ABEQ, Z, Z);
-			regfree(&nod);
-			regfree(&nod1);
-			p1 = p;
-			regalloc(&nod, t, Z);
-			if(tt == TFLOAT) {
-				gins(AMOVF, nodfconst(2147483648.), &nod);
-				gins(AADDF, &nod, t);
-			} else {
-				gins(AMOVD, nodfconst(2147483648.), &nod);
-				gins(AADDD, &nod, t);
-			}
-			regfree(&nod);
-			patch(p1, pc);
-			return;
-		}
-		// fall through
-
-	case TINT:
-	case TLONG:
-	case TIND:
-		switch(tt) {
-		case TDOUBLE:
-			gins(AMOVWD, f, t);
-			return;
-		case TFLOAT:
-			gins(AMOVWF, f, t);
-			return;
-		case TINT:
-		case TUINT:
-		case TLONG:
-		case TULONG:
-		case TIND:
-		case TSHORT:
-		case TUSHORT:
-		case TCHAR:
-		case TUCHAR:
-			a = AMOVW;
-			break;
-		}
-		break;
-	case TSHORT:
-		switch(tt) {
-		case TDOUBLE:
-			regalloc(&nod, f, Z);
-			gins(AMOVH, f, &nod);
-			gins(AMOVWD, &nod, t);
-			regfree(&nod);
-			return;
-		case TFLOAT:
-			regalloc(&nod, f, Z);
-			gins(AMOVH, f, &nod);
-			gins(AMOVWF, &nod, t);
-			regfree(&nod);
-			return;
-		case TUINT:
-		case TINT:
-		case TULONG:
-		case TLONG:
-		case TIND:
-			a = AMOVH;
-			break;
-		case TSHORT:
-		case TUSHORT:
-		case TCHAR:
-		case TUCHAR:
-			a = AMOVW;
-			break;
-		}
-		break;
-	case TUSHORT:
-		switch(tt) {
-		case TDOUBLE:
-			regalloc(&nod, f, Z);
-			gins(AMOVHU, f, &nod);
-			gins(AMOVWD, &nod, t);
-			regfree(&nod);
-			return;
-		case TFLOAT:
-			regalloc(&nod, f, Z);
-			gins(AMOVHU, f, &nod);
-			gins(AMOVWF, &nod, t);
-			regfree(&nod);
-			return;
-		case TINT:
-		case TUINT:
-		case TLONG:
-		case TULONG:
-		case TIND:
-			a = AMOVHU;
-			break;
-		case TSHORT:
-		case TUSHORT:
-		case TCHAR:
-		case TUCHAR:
-			a = AMOVW;
-			break;
-		}
-		break;
-	case TCHAR:
-		switch(tt) {
-		case TDOUBLE:
-			regalloc(&nod, f, Z);
-			gins(AMOVB, f, &nod);
-			gins(AMOVWD, &nod, t);
-			regfree(&nod);
-			return;
-		case TFLOAT:
-			regalloc(&nod, f, Z);
-			gins(AMOVB, f, &nod);
-			gins(AMOVWF, &nod, t);
-			regfree(&nod);
-			return;
-		case TINT:
-		case TUINT:
-		case TLONG:
-		case TULONG:
-		case TIND:
-		case TSHORT:
-		case TUSHORT:
-			a = AMOVB;
-			break;
-		case TCHAR:
-		case TUCHAR:
-			a = AMOVW;
-			break;
-		}
-		break;
-	case TUCHAR:
-		switch(tt) {
-		case TDOUBLE:
-			regalloc(&nod, f, Z);
-			gins(AMOVBU, f, &nod);
-			gins(AMOVWD, &nod, t);
-			regfree(&nod);
-			return;
-		case TFLOAT:
-			regalloc(&nod, f, Z);
-			gins(AMOVBU, f, &nod);
-			gins(AMOVWF, &nod, t);
-			regfree(&nod);
-			return;
-		case TINT:
-		case TUINT:
-		case TLONG:
-		case TULONG:
-		case TIND:
-		case TSHORT:
-		case TUSHORT:
-			a = AMOVBU;
-			break;
-		case TCHAR:
-		case TUCHAR:
-			a = AMOVW;
-			break;
-		}
-		break;
-	}
-	if(a == AGOK)
-		diag(Z, "bad opcode in gmove %T -> %T", f->type, t->type);
-	if(a == AMOVW || a == AMOVF || a == AMOVD)
-	if(samaddr(f, t))
-		return;
-	gins(a, f, t);
-}
-
-void
-gmover(Node *f, Node *t)
-{
-	int ft, tt, a;
-
-	ft = f->type->etype;
-	tt = t->type->etype;
-	a = AGOK;
-	if(typechlp[ft] && typechlp[tt] && ewidth[ft] >= ewidth[tt]){
-		switch(tt){
-		case TSHORT:
-			a = AMOVH;
-			break;
-		case TUSHORT:
-			a = AMOVHU;
-			break;
-		case TCHAR:
-			a = AMOVB;
-			break;
-		case TUCHAR:
-			a = AMOVBU;
-			break;
-		}
-	}
-	if(a == AGOK)
-		gmove(f, t);
-	else
-		gins(a, f, t);
-}
-
-void
-gins(int a, Node *f, Node *t)
-{
-
-	nextpc();
-	p->as = a;
-	if(f != Z)
-		naddr(f, &p->from);
-	if(t != Z)
-		naddr(t, &p->to);
-	if(debug['g'])
-		print("%P\n", p);
-}
-
-void
-gopcode(int o, Node *f1, Node *f2, Node *t)
-{
-	int a, et, true;
-	Adr ta;
-
-	et = TLONG;
-	if(f1 != Z && f1->type != T)
-		et = f1->type->etype;
-	true = o & BTRUE;
-	o &= ~BTRUE;
-	a = AGOK;
-	switch(o) {
-	case OAS:
-		gmove(f1, t);
-		return;
-
-	case OASADD:
-	case OADD:
-		a = AADD;
-		if(et == TFLOAT)
-			a = AADDF;
-		else
-		if(et == TDOUBLE || et == TVLONG)
-			a = AADDD;
-		break;
-
-	case OASSUB:
-	case OSUB:
-		if(f2 && f2->op == OCONST) {
-			Node *t = f1;
-			f1 = f2;
-			f2 = t;
-			a = ARSB;
-		} else
-			a = ASUB;
-		if(et == TFLOAT)
-			a = ASUBF;
-		else
-		if(et == TDOUBLE || et == TVLONG)
-			a = ASUBD;
-		break;
-
-	case OASOR:
-	case OOR:
-		a = AORR;
-		break;
-
-	case OASAND:
-	case OAND:
-		a = AAND;
-		break;
-
-	case OASXOR:
-	case OXOR:
-		a = AEOR;
-		break;
-
-	case OASLSHR:
-	case OLSHR:
-		a = ASRL;
-		break;
-
-	case OASASHR:
-	case OASHR:
-		a = ASRA;
-		break;
-
-	case OASASHL:
-	case OASHL:
-		a = ASLL;
-		break;
-
-	case OFUNC:
-		a = ABL;
-		break;
-
-	case OASMUL:
-	case OMUL:
-		a = AMUL;
-		if(et == TFLOAT)
-			a = AMULF;
-		else
-		if(et == TDOUBLE || et == TVLONG)
-			a = AMULD;
-		break;
-
-	case OASDIV:
-	case ODIV:
-		a = ADIV;
-		if(et == TFLOAT)
-			a = ADIVF;
-		else
-		if(et == TDOUBLE || et == TVLONG)
-			a = ADIVD;
-		break;
-
-	case OASMOD:
-	case OMOD:
-		a = AMOD;
-		break;
-
-	case OASLMUL:
-	case OLMUL:
-		a = AMULU;
-		break;
-
-	case OASLMOD:
-	case OLMOD:
-		a = AMODU;
-		break;
-
-	case OASLDIV:
-	case OLDIV:
-		a = ADIVU;
-		break;
-
-	case OCASE:
-	case OEQ:
-	case ONE:
-	case OLT:
-	case OLE:
-	case OGE:
-	case OGT:
-	case OLO:
-	case OLS:
-	case OHS:
-	case OHI:
-		a = ACMP;
-		if(et == TFLOAT)
-			a = ACMPF;
-		else
-		if(et == TDOUBLE || et == TVLONG)
-			a = ACMPD;
-		nextpc();
-		p->as = a;
-		naddr(f1, &p->from);
-		if(a == ACMP && f1->op == OCONST && p->from.offset < 0 &&
-		    p->from.offset != 0x80000000) {
-			p->as = ACMN;
-			p->from.offset = -p->from.offset;
-		}
-		raddr(f2, p);
-		switch(o) {
-		case OEQ:
-			a = ABEQ;
-			break;
-		case ONE:
-			a = ABNE;
-			break;
-		case OLT:
-			a = ABLT;
-			/* ensure NaN comparison is always false */
-			if(typefd[et] && !true)
-				a = ABMI;
-			break;
-		case OLE:
-			a = ABLE;
-			if(typefd[et] && !true)
-				a = ABLS;
-			break;
-		case OGE:
-			a = ABGE;
-			if(typefd[et] && true)
-				a = ABPL;
-			break;
-		case OGT:
-			a = ABGT;
-			if(typefd[et] && true)
-				a = ABHI;
-			break;
-		case OLO:
-			a = ABLO;
-			break;
-		case OLS:
-			a = ABLS;
-			break;
-		case OHS:
-			a = ABHS;
-			break;
-		case OHI:
-			a = ABHI;
-			break;
-		case OCASE:
-			nextpc();
-			p->as = ACASE;
-			p->scond = 0x9;
-			naddr(f2, &p->from);
-			a = ABHI;
-			break;
-		}
-		f1 = Z;
-		f2 = Z;
-		break;
-	}
-	if(a == AGOK)
-		diag(Z, "bad in gopcode %O", o);
-	nextpc();
-	p->as = a;
-	if(f1 != Z)
-		naddr(f1, &p->from);
-	if(f2 != Z) {
-		naddr(f2, &ta);
-		p->reg = ta.reg;
-	}
-	if(t != Z)
-		naddr(t, &p->to);
-	if(debug['g'])
-		print("%P\n", p);
-}
-
-samaddr(Node *f, Node *t)
-{
-
-	if(f->op != t->op)
-		return 0;
-	switch(f->op) {
-
-	case OREGISTER:
-		if(f->reg != t->reg)
-			break;
-		return 1;
-	}
-	return 0;
-}
-
-void
-gbranch(int o)
-{
-	int a;
-
-	a = AGOK;
-	switch(o) {
-	case ORETURN:
-		a = ARET;
-		break;
-	case OGOTO:
-		a = AB;
-		break;
-	}
-	nextpc();
-	if(a == AGOK) {
-		diag(Z, "bad in gbranch %O",  o);
-		nextpc();
-	}
-	p->as = a;
-}
-
-void
-patch(Prog *op, int32_t pc)
-{
-
-	op->to.offset = pc;
-	op->to.type = D_BRANCH;
-}
-
-void
-gpseudo(int a, Sym *s, Node *n)
-{
-
-	nextpc();
-	p->as = a;
-	p->from.type = D_OREG;
-	p->from.sym = s;
-	p->from.name = D_EXTERN;
-	if(a == ATEXT)
-		p->reg = (profileflg ? 0 : NOPROF);
-	if(s->class == CSTATIC)
-		p->from.name = D_STATIC;
-	naddr(n, &p->to);
-	if(a == ADATA || a == AGLOBL)
-		pc--;
-}
-
-int
-sconst(Node *n)
-{
-	int64_t vv;
-
-	if(n->op == OCONST) {
-		if(!typefd[n->type->etype]) {
-			vv = n->vconst;
-			if(vv >= (int64_t)(-32766) && vv < (int64_t)32766)
-				return 1;
-			/*
-			 * should be specialised for constant values which will
-			 * fit in different instructionsl; for now, let 5l
-			 * sort it out
-			 */
-			return 1;
-		}
-	}
-	return 0;
-}
-
-int
-sval(int32_t v)
-{
-	int i;
-
-	for(i=0; i<16; i++) {
-		if((v & ~0xff) == 0)
-			return 1;
-		if((~v & ~0xff) == 0)
-			return 1;
-		v = (v<<2) | ((uint32_t)v>>30);
-	}
-	return 0;
-}
-
-int32_t
-exreg(Type *t)
-{
-	int32_t o;
-
-	if(typechlp[t->etype]) {
-		if(exregoffset <= REGEXT-2)
-			return 0;
-		o = exregoffset;
-		if(reg[o] && !resvreg[o])
-			return 0;
-		resvreg[o] = reg[o] = 1;
-		exregoffset--;
-		return o;
-	}
-	if(typefd[t->etype]) {
-		if(exfregoffset <= NFREG-1)
-			return 0;
-		o = exfregoffset + NREG;
-		if(reg[o] && !resvreg[o])
-			return 0;
-		resvreg[o] = reg[o] = 1;
-		exfregoffset--;
-		return o;
-	}
-	return 0;
-}
-
-schar	ewidth[NTYPE] =
-{
-	-1,		/* [TXXX] */
-	SZ_CHAR,	/* [TCHAR] */
-	SZ_CHAR,	/* [TUCHAR] */
-	SZ_SHORT,	/* [TSHORT] */
-	SZ_SHORT,	/* [TUSHORT] */
-	SZ_INT,		/* [TINT] */
-	SZ_INT,		/* [TUINT] */
-	SZ_LONG,	/* [TLONG] */
-	SZ_LONG,	/* [TULONG] */
-	SZ_VLONG,	/* [TVLONG] */
-	SZ_VLONG,	/* [TUVLONG] */
-	SZ_FLOAT,	/* [TFLOAT] */
-	SZ_DOUBLE,	/* [TDOUBLE] */
-	SZ_IND,		/* [TIND] */
-	0,		/* [TFUNC] */
-	-1,		/* [TARRAY] */
-	0,		/* [TVOID] */
-	-1,		/* [TSTRUCT] */
-	-1,		/* [TUNION] */
-	SZ_INT,		/* [TENUM] */
-};
-
-int32_t	ncast[NTYPE] =
-{
-	0,				/* [TXXX] */
-	BCHAR|BUCHAR,			/* [TCHAR] */
-	BCHAR|BUCHAR,			/* [TUCHAR] */
-	BSHORT|BUSHORT,			/* [TSHORT] */
-	BSHORT|BUSHORT,			/* [TUSHORT] */
-	BINT|BUINT|BLONG|BULONG|BIND,	/* [TINT] */
-	BINT|BUINT|BLONG|BULONG|BIND,	/* [TUINT] */
-	BINT|BUINT|BLONG|BULONG|BIND,	/* [TLONG] */
-	BINT|BUINT|BLONG|BULONG|BIND,	/* [TULONG] */
-	BVLONG|BUVLONG,			/* [TVLONG] */
-	BVLONG|BUVLONG,			/* [TUVLONG] */
-	BFLOAT,				/* [TFLOAT] */
-	BDOUBLE,			/* [TDOUBLE] */
-	BLONG|BULONG|BIND,		/* [TIND] */
-	0,				/* [TFUNC] */
-	0,				/* [TARRAY] */
-	0,				/* [TVOID] */
-	BSTRUCT,			/* [TSTRUCT] */
-	BUNION,				/* [TUNION] */
-	0,				/* [TENUM] */
-};

+ 0 - 288
sys/src/cmd/5i/5i.c

@@ -1,288 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <bio.h>
-#include <mach.h>
-#include "arm.h"
-
-#include <tos.h>
-
-char*	file = "5.out";
-int	datasize;
-uint32_t	textbase;
-Biobuf	bp, bi;
-Fhdr	fhdr;
-
-void
-main(int argc, char **argv)
-{
-
-	argc--;
-	argv++;
-
-	bioout = &bp;
-	bin = &bi;
-	Binit(bioout, 1, OWRITE);
-	Binit(bin, 0, OREAD);
-
-	tlb.on = 1;
-	tlb.tlbsize = 24;
-
-	if(argc)
-		file = argv[0];
-	argc--;
-	argv++;
-
-	text = open(file, OREAD);
-	if(text < 0)
-		fatal(1, "open text '%s'", file);
-
-	Bprint(bioout, "5i\n");
-	inithdr(text);
-	initstk(argc, argv);
-
-	cmd();
-}
-
-void
-initmap()
-{
-	uint32_t t, d, b, bssend;
-	Segment *s;
-
-	t = (fhdr.txtaddr+fhdr.txtsz+(BY2PG-1)) & ~(BY2PG-1);
-	d = (t + fhdr.datsz + (BY2PG-1)) & ~(BY2PG-1);
-	bssend = t + fhdr.datsz + fhdr.bsssz;
-	b = (bssend + (BY2PG-1)) & ~(BY2PG-1);
-
-	s = &memory.seg[Text];
-	s->type = Text;
-	s->base = fhdr.txtaddr - fhdr.hdrsz;
-	s->end = t;
-	s->fileoff = fhdr.txtoff - fhdr.hdrsz;
-	s->fileend = s->fileoff + fhdr.txtsz;
-	s->table = emalloc(((s->end-s->base)/BY2PG)*sizeof(uint8_t*));
-
-	iprof = emalloc(((s->end-s->base)/PROFGRAN)*sizeof(int32_t));
-	textbase = s->base;
-
-	s = &memory.seg[Data];
-	s->type = Data;
-	s->base = t;
-	s->end = t+(d-t);
-	s->fileoff = fhdr.datoff;
-	s->fileend = s->fileoff + fhdr.datsz;
-	datasize = fhdr.datsz;
-	s->table = emalloc(((s->end-s->base)/BY2PG)*sizeof(uint8_t*));
-
-	s = &memory.seg[Bss];
-	s->type = Bss;
-	s->base = d;
-	s->end = d+(b-d);
-	s->table = emalloc(((s->end-s->base)/BY2PG)*sizeof(uint8_t*));
-
-	s = &memory.seg[Stack];
-	s->type = Stack;
-	s->base = STACKTOP-STACKSIZE;
-	s->end = STACKTOP;
-	s->table = emalloc(((s->end-s->base)/BY2PG)*sizeof(uint8_t*));
-
-	reg.r[REGPC] = fhdr.entry;
-}
-
-void
-inithdr(int fd)
-{
-	Symbol s;
-
-	extern Machdata armmach;
-
-	seek(fd, 0, 0);
-	if (!crackhdr(fd, &fhdr))
-		fatal(0, "read text header");
-
-	if(fhdr.type != FARM )
-		fatal(0, "bad magic number: %d %d", fhdr.type, FARM);
-
-	if (syminit(fd, &fhdr) < 0)
-		fatal(0, "%r\n");
-
-	symmap = loadmap(symmap, fd, &fhdr);
-	if (mach->sbreg && lookup(0, mach->sbreg, &s))
-		mach->sb = s.value;
-	machdata = &armmach;
-}
-
-void
-reset(void)
-{
-	int i, l, m;
-	Segment *s;
-	Breakpoint *b;
-
-	memset(&reg, 0, sizeof(Registers));
-
-	for(i = 0; i > Nseg; i++) {
-		s = &memory.seg[i];
-		l = ((s->end-s->base)/BY2PG)*sizeof(uint8_t*);
-		for(m = 0; m < l; m++)
-			if(s->table[m])
-				free(s->table[m]);
-		free(s->table);
-	}
-	free(iprof);
-	memset(&memory, 0, sizeof(memory));
-
-	for(b = bplist; b; b = b->next)
-		b->done = b->count;
-}
-
-void
-initstk(int argc, char *argv[])
-{
-	uint32_t size;
-	uint32_t sp, ap, tos;
-	int i;
-	char *p;
-
-	initmap();
-	tos = STACKTOP - sizeof(Tos)*2;	/* we'll assume twice the host's is big enough */
-	sp = tos;
-	for (i = 0; i < sizeof(Tos)*2; i++)
-		putmem_b(tos + i, 0);
-
-	/*
-	 * pid is second word from end of tos and needs to be set for nsec().
-	 * we know arm is a 32-bit cpu, so we'll assume knowledge of the Tos
-	 * struct for now, and use our pid.
-	 */
-	putmem_w(tos + 4*4 + 2*sizeof(uint32_t) + 3*sizeof(uvlong), getpid());
-
-	/* Build exec stack */
-	size = strlen(file)+1+BY2WD+BY2WD+BY2WD;	
-	for(i = 0; i < argc; i++)
-		size += strlen(argv[i])+BY2WD+1;
-
-	sp -= size;
-	sp &= ~7;
-	reg.r[0] = tos;
-	reg.r[13] = sp;
-	reg.r[1] = STACKTOP-4;	/* Plan 9 profiling clock (why & why in R1?) */
-
-	/* Push argc */
-	putmem_w(sp, argc+1);
-	sp += BY2WD;
-
-	/* Compute sizeof(argv) and push argv[0] */
-	ap = sp+((argc+1)*BY2WD)+BY2WD;
-	putmem_w(sp, ap);
-	sp += BY2WD;
-	
-	/* Build argv[0] string into stack */
-	for(p = file; *p; p++)
-		putmem_b(ap++, *p);
-
-	putmem_b(ap++, '\0');
-
-	/* Loop through pushing the arguments */
-	for(i = 0; i < argc; i++) {
-		putmem_w(sp, ap);
-		sp += BY2WD;
-		for(p = argv[i]; *p; p++)
-			putmem_b(ap++, *p);
-		putmem_b(ap++, '\0');
-	}
-	/* Null terminate argv */
-	putmem_w(sp, 0);
-
-}
-
-void
-fatal(int syserr, char *fmt, ...)
-{
-	char buf[ERRMAX], *s;
-	va_list arg;
-
-	va_start(arg, fmt);
-	vseprint(buf, buf+sizeof(buf), fmt, arg);
-	va_end(arg);
-	s = "5i: %s\n";
-	if(syserr)
-		s = "5i: %s: %r\n";
-	fprint(2, s, buf);
-	exits(buf);
-}
-
-void
-itrace(char *fmt, ...)
-{
-	char buf[128];
-	va_list arg;
-
-	va_start(arg, fmt);
-	vseprint(buf, buf+sizeof(buf), fmt, arg);
-	va_end(arg);
-	Bprint(bioout, "%8lux %.8lux %2d %s\n", reg.ar, reg.ir, reg.class, buf);	
-}
-
-void
-dumpreg(void)
-{
-	int i;
-
-	Bprint(bioout, "PC  #%-8lux SP  #%-8lux \n",
-				reg.r[REGPC], reg.r[REGSP]);
-
-	for(i = 0; i < 16; i++) {
-		if((i%4) == 0 && i != 0)
-			Bprint(bioout, "\n");
-		Bprint(bioout, "R%-2d #%-8lux ", i, reg.r[i]);
-	}
-	Bprint(bioout, "\n");
-}
-
-void
-dumpfreg(void)
-{
-}
-
-void
-dumpdreg(void)
-{
-}
-
-void *
-emalloc(uint32_t size)
-{
-	void *a;
-
-	a = malloc(size);
-	if(a == 0)
-		fatal(0, "no memory");
-
-	memset(a, 0, size);
-	return a;
-}
-
-void *
-erealloc(void *a, uint32_t oldsize, uint32_t size)
-{
-	void *n;
-
-	n = malloc(size);
-	if(n == 0)
-		fatal(0, "no memory");
-	memset(n, 0, size);
-	if(size > oldsize)
-		size = oldsize;
-	memmove(n, a, size);
-	return n;
-}

+ 0 - 249
sys/src/cmd/5i/arm.h

@@ -1,249 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-/*
- * arm.h
- */
-#ifndef	EXTERN
-#define	EXTERN	extern
-#endif
-
-typedef	struct	Registers	Registers;
-typedef	struct	Segment		Segment;
-typedef	struct	Memory		Memory;
-typedef	struct	Mul		Mul;
-typedef	struct	Mulu		Mulu;
-typedef	struct	Inst		Inst;
-typedef	struct	Icache		Icache;
-typedef	struct	Tlb		Tlb;
-typedef	struct	Breakpoint	Breakpoint;
-
-enum
-{
-	Instruction	= 1,
-	Read		= 2,
-	Write		= 4,
-	Access		= 2|4,
-	Equal		= 4|8,
-};
-
-struct Breakpoint
-{
-	int		type;		/* Instruction/Read/Access/Write/Equal */
-	uint32_t		addr;		/* Place at address */
-	int		count;		/* To execute count times or value */
-	int		done;		/* How many times passed through */
-	Breakpoint*	next;		/* Link to next one */
-};
-
-enum
-{
-	Imem,
-	Iarith,
-	Ibranch,
-	Isyscall,
-};
-
-enum
-{
-	Nmaxtlb = 64,
-	REGARG	= 0,
-	REGRET	= 0,
-	REGPC	= 15,
-	REGLINK	= 14,
-	REGSP	= 13,
-};
-
-struct Tlb
-{
-	int	on;			/* Being updated */
-	int	tlbsize;		/* Number of entries */
-	uint32_t	tlbent[Nmaxtlb];	/* Virtual address tags */
-	int	hit;			/* Number of successful tag matches */
-	int	miss;			/* Number of failed tag matches */
-};		
-
-struct Icache
-{
-	int	on;			/* Turned on */
-	int	linesize;		/* Line size in bytes */
-	int	stall;			/* Cache stalls */
-	int*	lines;			/* Tag array */
-	int*	(*hash)(uint32_t);		/* Hash function */
-	char*	hashtext;		/* What the function looks like */
-};
-
-struct Inst
-{
-	void 	(*func)(uint32_t);
-	char*	name;
-	int	type;
-	int	count;
-	int	taken;
-	int	useddelay;
-};
-
-struct Registers
-{
-	uint32_t	ar;
-	uint32_t	ir;
-	Inst*	ip;
-	long	r[16];
-	long	cc1;
-	long	cc2;
-	int	class;
-	int	cond;
-	int	compare_op;
-	int	cbit;
-	int	cout;
-};
-
-enum
-{
-	FPd	= 0,
-	FPs,
-	FPmemory,
-};
-
-enum
-{
-	MemRead,
-	MemReadstring,
-	MemWrite,
-};
-
-enum
-{
-	CCcmp, 
-	CCtst,
-	CCteq,
-};
-
-enum
-{
-	Stack,
-	Text,
-	Data,
-	Bss,
-	Nseg,
-};
-
-struct Segment
-{
-	short	type;
-	uint32_t	base;
-	uint32_t	end;
-	uint32_t	fileoff;
-	uint32_t	fileend;
-	int	rss;
-	int	refs;
-	uchar**	table;
-};
-
-struct Memory
-{
-	Segment	seg[Nseg];
-};
-
-void		Ssyscall(uint32_t);
-int		armclass(long);
-void		breakpoint(char*, char*);
-void		brkchk(uint32_t, int);
-void		cmd(void);
-void		delbpt(char*);
-void		dobplist(void);
-void		dumpdreg(void);
-void		dumpfreg(void);
-void		dumpreg(void);
-void*		emalloc(uint32_t);
-void*		erealloc(void*, uint32_t, uint32_t);
-uint32_t		expr(char*);
-void		fatal(int, char*, ...);
-uint32_t		getmem_2(uint32_t);
-uint32_t		getmem_4(uint32_t);
-uchar		getmem_b(uint32_t);
-ushort		getmem_h(uint32_t);
-uvlong		getmem_v(uint32_t);
-uint32_t		getmem_w(uint32_t);
-uint32_t		ifetch(uint32_t);
-void		inithdr(int);
-void		initicache(void);
-void		initmap(void);
-void		initstk(int, char**);
-void		iprofile(void);
-void		isum(void);
-void		itrace(char*, ...);
-long		lnrand(long);
-char*		memio(char*, uint32_t, int, int);
-int		_mipscoinst(Map*, uint32_t, char*, int);
-Mul		mul(long, long);
-Mulu		mulu(uint32_t, uint32_t);
-char*		nextc(char*);
-void		printlocals(Symbol*, uint32_t);
-void		printparams(Symbol*, uint32_t);
-void		printsource(long);
-void		procinit(int);
-void		putmem_b(uint32_t, uchar);
-void		putmem_h(uint32_t, ushort);
-void		putmem_v(uint32_t, uvlong);
-void		putmem_w(uint32_t, uint32_t);
-void		reset(void);
-void		run(void);
-void		segsum(void);
-void		stktrace(int);
-void		tlbsum(void);
-void		undef(uint32_t);
-void		updateicache(uint32_t addr);
-void*		vaddr(uint32_t);
-
-/* Globals */
-EXTERN	Registers	reg;
-EXTERN	Memory		memory;
-EXTERN	int		text;
-EXTERN	int		trace;
-EXTERN	int		sysdbg;
-EXTERN	int		calltree;
-EXTERN	Inst		itab[];
-EXTERN	Inst		ispec[];
-EXTERN	Icache		icache;
-EXTERN	Tlb		tlb;
-EXTERN	int		count;
-EXTERN	jmp_buf		errjmp;
-EXTERN	Breakpoint*	bplist;
-EXTERN	int		atbpt;
-EXTERN	int		membpt;
-EXTERN	int		cmdcount;
-EXTERN	int		nopcount;
-EXTERN	uint32_t		dot;
-EXTERN	char*		file;
-EXTERN	Biobuf*		bioout;
-EXTERN	Biobuf*		bin;
-EXTERN	uint32_t*		iprof;
-EXTERN	int		datasize;
-EXTERN	Map*		symmap;	
-
-/* Plan9 Kernel constants */
-enum
-{
-	BY2PG		= 4096,
-	BY2WD		= 4,
-	UTZERO		= 0x1000,
-	STACKTOP	= 0x80000000,
-	STACKSIZE	= 0x10000,
-
-	PROFGRAN	= 4,
-	Sbit		= 1<<20,
-	SIGNBIT		= 0x80000000,
-
-	FP_U		= 3,
-	FP_L		= 1,
-	FP_G		= 2,
-	FP_E		= 0,
-	FP_CBIT		= 1<<23,
-};

+ 0 - 137
sys/src/cmd/5i/bpt.c

@@ -1,137 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <bio.h>
-#include <mach.h>
-#include <ctype.h>
-#include "arm.h"
-
-void
-dobplist(void)
-{
-	Breakpoint *b;
-	char buf[512];
-
-	for(b = bplist; b; b = b->next) {
-		switch(b->type) {
-		case Instruction:
-			Bprint(bioout, "0x%lux,%d:b %d done, at ", b->addr, b->count, b->done);
-			symoff(buf, sizeof(buf), b->addr, CTEXT);
-			Bprint(bioout, buf);
-			break;
-
-		case Access:
-			Bprint(bioout, "0x%lux,%d:ba %d done, at ", b->addr, b->count, b->done);
-			symoff(buf, sizeof(buf), b->addr, CDATA);
-			Bprint(bioout, buf);
-			break;
-
-		case Read:
-			Bprint(bioout, "0x%lux,%d:br %d done, at ", b->addr, b->count, b->done);
-			symoff(buf, sizeof(buf), b->addr, CDATA);
-			Bprint(bioout, buf);
-			break;
-
-		case Write:
-			Bprint(bioout, "0x%lux,%d:bw %d done, at ", b->addr, b->count, b->done);
-			symoff(buf, sizeof(buf), b->addr, CDATA);
-			Bprint(bioout, buf);
-			break;
-
-		case Equal:
-			Bprint(bioout, "0x%lux,%d:be at ", b->addr, b->count);
-			symoff(buf, sizeof(buf), b->addr, CDATA);
-			Bprint(bioout, buf);
-			break;
-		}
-		Bprint(bioout, "\n");
-	}
-}
-
-void
-breakpoint(char *addr, char *cp)
-{
-	Breakpoint *b;
-	int type;
-
-	cp = nextc(cp);
-	type = Instruction;
-	switch(*cp) {
-	case 'r':
-		membpt++;
-		type = Read;
-		break;
-	case 'a':
-		membpt++;
-		type = Access;
-		break;
-	case 'w':
-		membpt++;
-		type = Write;
-		break;
-	case 'e':
-		membpt++;
-		type = Equal;
-		break;
-	}
-	b = emalloc(sizeof(Breakpoint));
-	b->addr = expr(addr);
-	b->type = type;
-	b->count = cmdcount;
-	b->done = cmdcount;
-
-	b->next = bplist;
-	bplist = b;
-}
-
-void
-delbpt(char *addr)
-{
-	Breakpoint *b, **l;
-	uint32_t baddr;
-
-	baddr = expr(addr);
-	l = &bplist;
-	for(b = *l; b; b = b->next) {
-		if(b->addr == baddr) {
-			if(b->type != Instruction)
-				membpt++;
-			*l = b->next;
-			free(b);
-			return;
-		}
-		l = &b->next;	
-	}
-
-	Bprint(bioout, "no breakpoint\n");
-}
-
-void
-brkchk(uint32_t addr, int type)
-{
-	Breakpoint *b;
-
-	for(b = bplist; b; b = b->next) {
-		if(b->addr == addr && (b->type&type)) {
-			if(b->type == Equal && getmem_4(addr) == b->count) {
-				count = 1;
-				atbpt = 1;
-				return;
-			}
-			if(--b->done == 0) {
-				b->done = b->count;
-				count = 1;
-				atbpt = 1;
-				return;
-			}
-		}
-	}	
-}

+ 0 - 649
sys/src/cmd/5i/cmd.c

@@ -1,649 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <bio.h>
-#include <mach.h>
-#include <ctype.h>
-#include "arm.h"
-
-char	buf[128], lastcmd[128];
-char	fmt = 'X';
-int	width = 60;
-int	inc;
-
-uint32_t	expr(char*);
-uint32_t	expr1(char*);
-char*	term(char*, uint32_t*);
-
-char*
-nextc(char *p)
-{
-	while(*p && (*p == ' ' || *p == '\t') && *p != '\n')
-		p++;
-
-	if(*p == '\n')
-		*p = '\0';
-
-	return p;
-}
-
-char*
-numsym(char *addr, uint32_t *val)
-{
-	char tsym[128], *t;
-	static char *delim = "`'<>/\\@*|-~+-/=?\n";
-	Symbol s;
-	char c;
-
-	t = tsym;
-	while(c = *addr) {
-		if(strchr(delim, c))
-			break;
-		*t++ = c;
-		addr++;
-	}
-	t[0] = '\0';
-
-	if(strcmp(tsym, ".") == 0) {
-		*val = dot;
-		return addr;
-	}
-
-	if(lookup(0, tsym, &s))
-		*val = s.value;
-	else {
-		if(tsym[0] == '#')
-			*val = strtoul(tsym+1, 0, 16);
-		else
-			*val = strtoul(tsym, 0, 0);
-	}
-	return addr;
-}
-
-uint32_t
-expr(char *addr)
-{
-	uint32_t t, t2;
-	char op;
-
-	if(*addr == '\0')
-		return dot;
-
-	addr = numsym(addr, &t);
-
-	if(*addr == '\0')
-		return t;
-
-	addr = nextc(addr);
-	op = *addr++;
-	numsym(addr, &t2);
-	switch(op) {
-	default:
-		Bprint(bioout, "expr syntax\n");
-		return 0;
-	case '+':
-		t += t2;
-		break;
-	case '-':
-		t -= t2;
-		break;
-	case '%':
-		t /= t2;
-		break;
-	case '&':
-		t &= t2;
-		break;
-	case '|':
-		t |= t2;
-		break;
-	}
-
-	return t;
-}
-
-int
-buildargv(char *str, char **args, int max)
-{
-	int na = 0;
-
-	while (na < max) {
-		while((*str == ' ' || *str == '\t' || *str == '\n') && *str != '\0')
-			str++;
-
-		if(*str == '\0')
-			return na;
-
-		args[na++] = str;
-		while(!(*str == ' ' || *str == '\t'|| *str == '\n') && *str != '\0')
-			str++;
-
-		if(*str == '\n')
-			*str = '\0';
-
-		if(*str == '\0')
-			break;
-
-		*str++ = '\0';
-	}
-	return na;
-}
-
-void
-colon(char *addr, char *cp)
-{
-	int argc;
-	char *argv[100];
-	char tbuf[512];
-
-	cp = nextc(cp);
-	switch(*cp) {
-	default:
-		Bprint(bioout, "?\n");
-		return;
-	case 'b':
-		breakpoint(addr, cp+1);
-		return;
-
-	case 'd':
-		delbpt(addr);
-		return;
-
-	/* These fall through to print the stopped address */
-	case 'r':
-		reset();
-		argc = buildargv(cp+1, argv, 100);
-		initstk(argc, argv);
-		count = 0;
-		atbpt = 0;
-		run();
-		break;
-	case 'c':
-		count = 0;
-		atbpt = 0;
-		run();
-		break;
-	case 's':
-		cp = nextc(cp+1);
-		count = 0;
-		if(*cp)
-			count = strtoul(cp, 0, 0);
-		if(count == 0)
-			count = 1;
-		atbpt = 0;
-		run();
-		break;
-	}
-
-	dot = reg.r[15];
-	Bprint(bioout, "%s at #%lux ", atbpt? "breakpoint": "stopped", dot);
-	symoff(tbuf, sizeof(tbuf), dot, CTEXT);
-	Bprint(bioout, tbuf);
-	if(fmt == 'z')
-		printsource(dot);
-
-	Bprint(bioout, "\n");
-}
-
-
-void
-dollar(char *cp)
-{
-	cp = nextc(cp);
-	switch(*cp) {
-	default:
-		Bprint(bioout, "?\n");
-		break;
-
-	case 'c':
-		stktrace(*cp);
-		break;
-
-	case 'C':
-		stktrace(*cp);
-		break;
-		
-	case 'b':
-		dobplist();
-		break;
-
-	case 'r':
-		dumpreg();
-		break;
-
-	case 'R':
-		dumpreg();
-
-	case 'f':
-		dumpfreg();
-		break;
-
-	case 'F':
-		dumpdreg();
-		break;
-
-	case 'q':
-		exits(0);
-		break;
-
-	case 'Q':
-		isum();
-		tlbsum();
-		segsum();
-		break;
-
-	case 't':
-		cp++;
-		switch(*cp) {
-		default:
-			Bprint(bioout, ":t[0sic]\n");
-			break;
-		case '\0':
-			trace = 1;
-			break;
-		case '0':
-			trace = 0;
-			sysdbg = 0;
-			calltree = 0;
-			break;
-		case 's':
-			sysdbg = 1;
-			break;
-		case 'i':
-			trace = 1;
-			break;
-		case 'c':
-			calltree = 1;
-			break;
-		}
-		break;
-
-	case 'i':
-		cp++;
-		switch(*cp) {
-		default:
-			Bprint(bioout, "$i[itsa]\n");
-			break;
-		case 'i':
-			isum();
-			break;
-		case 't':
-			tlbsum();
-			break;
-		case 's':
-			segsum();
-			break;
-		case 'a':
-			isum();
-			tlbsum();
-			segsum();
-			iprofile();
-			break;
-		case 'p':
-			iprofile();
-			break;
-		}
-	}
-}
-
-int
-pfmt(char fmt, int mem, uint32_t val)
-{
-	int c, i;
-	Symbol s;
-	char *p, ch, str[1024];
-
-	c = 0;
-	switch(fmt) {
-	default:
-		Bprint(bioout, "bad modifier\n");
-		return 0;
-	case 'o':
-		c = Bprint(bioout, "%-4lo ",
-			   mem? (uint16_t)getmem_2(dot): val);
-		inc = 2;
-		break;
-
-	case 'O':
-		c = Bprint(bioout, "%-8lo ", mem? getmem_4(dot): val);
-		inc = 4;
-		break;
-
-	case 'q':
-		c = Bprint(bioout, "%-4lo ", mem? (int16_t)getmem_2(dot): val);
-		inc = 2;
-		break;
-
-	case 'Q':
-		c = Bprint(bioout, "%-8lo ", mem? (int32_t)getmem_4(dot): val);
-		inc = 4;
-		break;
-
-	case 'd':
-		c = Bprint(bioout, "%-5ld ", mem? (int16_t)getmem_2(dot): val);
-		inc = 2;
-		break;
-
-
-	case 'D':
-		c = Bprint(bioout, "%-8ld ", mem? (int32_t)getmem_4(dot): val);
-		inc = 4;
-		break;
-
-	case 'x':
-		c = Bprint(bioout, "#%-4lux ",
-			   mem? (int32_t)getmem_2(dot): val);
-		inc = 2;
-		break;
-
-	case 'X':
-		c = Bprint(bioout, "#%-8lux ",
-			   mem? (int32_t)getmem_4(dot): val);
-		inc = 4;
-		break;
-
-	case 'u':
-		c = Bprint(bioout, "%-5ld ",
-			   mem? (uint16_t)getmem_2(dot): val);
-		inc = 2;
-		break;
-
-	case 'U':
-		c = Bprint(bioout, "%-8ld ",
-			   mem? (uint32_t)getmem_4(dot): val);
-		inc = 4;
-		break;
-
-	case 'b':
-		c = Bprint(bioout, "%-3ld ", mem? getmem_b(dot): val);
-		inc = 1;
-		break;
-
-	case 'c':
-		c = Bprint(bioout, "%c ", (int)(mem? getmem_b(dot): val));
-		inc = 1;
-		break;
-
-	case 'C':
-		ch = mem? getmem_b(dot): val;
-		if(isprint(ch))
-			c = Bprint(bioout, "%c ", ch);
-		else
-			c = Bprint(bioout, "\\x%.2x ", ch);
-		inc = 1;
-		break;
-
-	case 's':
-		i = 0;
-		while(ch = getmem_b(dot+i))
-			str[i++] = ch;
-		str[i] = '\0';
-		dot += i;
-		c = Bprint(bioout, "%s", str);
-		inc = 0;
-		break;
-
-	case 'S':
-		i = 0;
-		while(ch = getmem_b(dot+i))
-			str[i++] = ch;
-		str[i] = '\0';
-		dot += i;
-		for(p = str; *p; p++)
-			if(isprint(*p))
-				c += Bprint(bioout, "%c", *p);
-			else
-				c += Bprint(bioout, "\\x%.2ux", *p);
-		inc = 0;
-		break;
-
-	case 'Y':
-		p = ctime(mem? getmem_b(dot): val);
-		p[30] = '\0';
-		c = Bprint(bioout, "%s", p);
-		inc = 4;
-		break;
-
-	case 'a':
-		symoff(str, sizeof(str), dot, CTEXT);
-		c = Bprint(bioout, str);
-		inc = 0;
-		break;
-
-	case 'e':
-		for(i = 0; globalsym(&s, i); i++)
-			Bprint(bioout, "%-15s #%lux\n", s.name,	getmem_4(s.value));
-		inc = 0;
-		break;
-
-	case 'I':
-	case 'i':
-		inc = machdata->das(symmap, dot, fmt, str, sizeof(str));
-		if(inc < 0) {
-			Bprint(bioout, "5i: %r\n");
-			return 0;
-		}
-		c = Bprint(bioout, "\t%s", str);
-		break;
-
-	case 'n':
-		c = width+1;
-		inc = 0;
-		break;
-
-	case '-':
-		c = 0;
-		inc = -1;
-		break;
-
-	case '+':
-		c = 0;
-		inc = 1;
-		break;
-
-	case '^':
-		c = 0;
-		if(inc > 0)
-			inc = -inc;
-		break;
-
-	case 'z':
-		if(findsym(dot, CTEXT, &s))
-			Bprint(bioout, "  %s() ", s.name);
-		printsource(dot);
-		inc = 0;
-		break;
-	}
-	return c;
-}
-
-void
-eval(char *addr, char *p)
-{
-	uint32_t val;
-
-	val = expr(addr);
-	p = nextc(p);
-	if(*p == '\0') {
-		p[0] = fmt;
-		p[1] = '\0';
-	}
-	pfmt(*p, 0, val);
-	Bprint(bioout, "\n");
-}
-
-void
-quesie(char *p)
-{
-	int c, count, i;
-	char tbuf[512];
-
-	c = 0;
-	symoff(tbuf, sizeof(tbuf), dot, CTEXT);
-	Bprint(bioout, "%s?\t", tbuf);
-
-	while(*p) {
-		p = nextc(p);
-		if(*p == '"') {
-			for(p++; *p && *p != '"'; p++) {
-				Bputc(bioout, *p);
-				c++;
-			}
-			if(*p)
-				p++;
-			continue;
-		}
-		count = 0;
-		while(*p >= '0' && *p <= '9')
-			count = count*10 + (*p++ - '0');
-		if(count == 0)
-			count = 1;
-		p = nextc(p);
-		if(*p == '\0') {
-			p[0] = fmt;
-			p[1] = '\0';
-		}
-		for(i = 0; i < count; i++) {
-			c += pfmt(*p, 1, 0);
-			dot += inc;
-			if(c > width) {
-				Bprint(bioout, "\n");
-				symoff(tbuf, sizeof(tbuf), dot, CTEXT);
-				Bprint(bioout, "%s?\t", tbuf);
-				c = 0;
-			}
-		}
-		fmt = *p++;
-		p = nextc(p);
-	}
-	Bprint(bioout, "\n");
-}
-
-void
-catcher(void *a, char *msg)
-{
-	static int hit = 0;
-
-	hit++;
-	if(hit > 5)
-		exits(0);
-	USED(a);
-	if(strcmp(msg, "interrupt") != 0)
-		noted(NDFLT);
-
-	count = 1;
-	print("5i\n");
-	noted(NCONT);
-}
-
-void
-setreg(char *addr, char *cp)
-{
-	int rn;
-
-	dot = expr(addr);
-	cp = nextc(cp);
-	if(strcmp(cp, "pc") == 0) {
-		reg.r[15] = dot;
-		return;
-	}
-	if(strcmp(cp, "sp") == 0) {
-		reg.r[13] = dot;
-		return;
-	}
-	if(*cp++ == 'r') {
-		rn = strtoul(cp, 0, 10);
-		if(rn > 0 && rn < 16) {
-			reg.r[rn] = dot;
-			return;
-		}
-	}
-	Bprint(bioout, "bad register\n");
-}
-
-void
-cmd(void)
-{
-	char *p, *a, *cp, *gotint;
-	char addr[128];
-	static char *cmdlet = ":$?/=>";
-	int n, i;
-
-	notify(catcher);
-
-	dot = reg.r[15];
-	setjmp(errjmp);
-
-	for(;;) {
-		Bflush(bioout);
-		p = buf;
-		n = 0;
-		for(;;) {
-			i = Bgetc(bin);
-			if(i < 0)
-				exits(0);
-			*p++ = i;
-			n++;
-			if(i == '\n')
-				break;
-		}
-
-		if(buf[0] == '\n')
-			strcpy(buf, lastcmd);
-		else {
-			buf[n-1] = '\0';
-			strcpy(lastcmd, buf);
-		}
-		p = buf;
-		a = addr;
-
-		for(;;) {
-			p = nextc(p);
-			if(*p == 0 || strchr(cmdlet, *p))
-				break;
-			*a++ = *p++;
-		}
-
-		*a = '\0';
-		cmdcount = 1;
-		cp = strchr(addr, ',');
-		if(cp != 0) {
-			if(cp[1] == '#')
-				cmdcount = strtoul(cp+2, &gotint, 16);
-			else
-				cmdcount = strtoul(cp+1, &gotint, 0);
-			*cp = '\0';
-		}
-
-		switch(*p) {
-		case '$':
-			dollar(p+1);
-			break;
-		case ':':
-			colon(addr, p+1);
-			break;
-		case '/':
-		case '?':
-			dot = expr(addr);
-			for(i = 0; i < cmdcount; i++)
-				quesie(p+1);
-			break;
-		case '=':
-			eval(addr, p+1);
-			break;
-		case '>':
-			setreg(addr, p+1);
-			break;
-		default:
-			Bprint(bioout, "?\n");
-			break;
-		}
-	}
-}

+ 0 - 212
sys/src/cmd/5i/float.c

@@ -1,212 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <bio.h>
-#include <mach.h>
-#include "arm.h"
-
-void	unimp(ulong);
-void	Ifcmp(ulong);
-void	Ifdiv(ulong);
-void	Ifmul(ulong);
-void	Ifadd(ulong);
-void	Ifsub(ulong);
-void	Ifmov(ulong);
-void	Icvtd(ulong);
-void	Icvtw(ulong);
-void	Icvts(ulong);
-void	Ifabs(ulong);
-void	Ifneg(ulong);
-
-Inst cop1[] = {
-	{ Ifadd,	"add.f", Ifloat },
-	{ Ifsub,	"sub.f", Ifloat },
-	{ Ifmul,	"mul.f", Ifloat },
-	{ Ifdiv,	"div.f", Ifloat },
-	{ unimp,	"", },
-	{ Ifabs,	"abs.f", Ifloat },
-	{ Ifmov,	"mov.f", Ifloat },
-	{ Ifneg,	"neg.f", Ifloat },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ Icvts,	"cvt.s", Ifloat },
-	{ Icvtd,	"cvt.d", Ifloat },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ Icvtw,	"cvt.w", Ifloat },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ unimp,	"", },
-	{ Ifcmp,	"c.f",	 Ifloat },
-	{ Ifcmp,	"c.un",  Ifloat },
-	{ Ifcmp,	"c.eq",  Ifloat },
-	{ Ifcmp,	"c.ueq", Ifloat },
-	{ Ifcmp,	"c.olt", Ifloat },
-	{ Ifcmp,	"c.ult", Ifloat },
-	{ Ifcmp,	"c.ole", Ifloat },
-	{ Ifcmp,	"c.ule", Ifloat },
-	{ Ifcmp,	"c,sf",  Ifloat },
-	{ Ifcmp,	"c.ngle",Ifloat },
-	{ Ifcmp,	"c.seq", Ifloat },
-	{ Ifcmp,	"c.ngl", Ifloat },
-	{ Ifcmp,	"c.lt",  Ifloat },
-	{ Ifcmp,	"c.nge", Ifloat },
-	{ Ifcmp,	"c.le",  Ifloat },
-	{ Ifcmp,	"c.ngt", Ifloat },
-	{ 0 }
-};
-
-void
-unimp(uint32_t inst)
-{
-	print("op %d\n", inst&0x3f);
-	Bprint(bioout, "Unimplemented floating point Trap IR %.8lux\n", inst);
-	longjmp(errjmp, 0);
-}
-
-void
-inval(uint32_t inst)
-{
-	Bprint(bioout, "Invalid Operation Exception IR %.8lux\n", inst);
-	longjmp(errjmp, 0);
-}
-
-void
-ifmt(int r)
-{
-	Bprint(bioout, "Invalid Floating Data Format f%d pc 0x%lux\n", r, reg.r[15]);
-	longjmp(errjmp, 0);
-}
-
-void
-floatop(int dst, int s1, int s2)
-{
-}
-
-void
-doubop(int dst, int s1, int s2)
-{
-}
-
-void
-Iswc1(uint32_t inst)
-{
-}
-
-void
-Ifsub(uint32_t ir)
-{
-}
-
-void
-Ifmov(uint32_t ir)
-{
-}
-
-void
-Ifabs(uint32_t ir)
-{
-}
-
-void
-Ifneg(uint32_t ir)
-{
-}
-
-void
-Icvtd(uint32_t ir)
-{
-}
-
-void
-Icvts(uint32_t ir)
-{
-}
-
-void
-Icvtw(uint32_t ir)
-{
-}
-
-void
-Ifadd(uint32_t ir)
-{
-}
-
-void
-Ifmul(uint32_t ir)
-{
-}
-
-void
-Ifdiv(uint32_t ir)
-{
-}
-
-void
-Ilwc1(uint32_t inst)
-{
-}
-
-void
-Ibcfbct(uint32_t inst)
-{
-}
-
-void
-Imtct(uint32_t ir)
-{
-}
-
-void
-Imfcf(uint32_t ir)
-{
-}
-
-void
-Icop1(uint32_t ir)
-{
-}
-
-void
-Ifcmp(uint32_t ir)
-{
-}

+ 0 - 26
sys/src/cmd/5i/icache.c

@@ -1,26 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <bio.h>
-#include <mach.h>
-#include "arm.h"
-
-void
-icacheinit(void)
-{
-}
-
-void
-updateicache(uint32_t addr)
-{
-	USED(addr);
-}
-

+ 0 - 294
sys/src/cmd/5i/mem.c

@@ -1,294 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <bio.h>
-#include <mach.h>
-#include "arm.h"
-
-extern uint32_t	textbase;
-
-uint32_t
-ifetch(uint32_t addr)
-{
-	uint8_t *va;
-
-	if(addr&3) {
-		Bprint(bioout, "Address error (I-fetch) vaddr %.8lux\n", addr);
-		longjmp(errjmp, 0);
-	}
-
-	if(icache.on)
-		updateicache(addr);
-	iprof[(addr-textbase)/PROFGRAN]++;
-
-	va = vaddr(addr);
-	va += addr&(BY2PG-1);
-
-	return va[3]<<24 | va[2]<<16 | va[1]<<8 | va[0];
-}
-
-uint32_t
-getmem_4(uint32_t addr)
-{
-	uint32_t val;
-	int i;
-
-	val = 0;
-	for(i = 0; i < 4; i++)
-		val = (val>>8) | (getmem_b(addr++)<<24);
-	return val;
-}
-
-uint32_t
-getmem_2(uint32_t addr)
-{
-	uint32_t val;
-	int i;
-
-	val = 0;
-	for(i = 0; i < 2; i++)
-		val = (val>>8) | (getmem_b(addr++)<<16);
-	return val;
-}
-
-uint32_t
-getmem_w(uint32_t addr)
-{
-	uint8_t *va;
-	uint32_t w;
-
-	if(addr&3) {
-		w = getmem_w(addr & ~3);
-		while(addr & 3) {
-			w = (w>>8) | (w<<24);
-			addr--;
-		}
-		return w;
-	}
-	if(membpt)
-		brkchk(addr, Read);
-
-	va = vaddr(addr);
-	va += addr&(BY2PG-1);
-
-	return va[3]<<24 | va[2]<<16 | va[1]<<8 | va[0];
-}
-
-uint16_t
-getmem_h(uint32_t addr)
-{
-	uint8_t *va;
-	uint32_t w;
-
-	if(addr&1) {
-		w = getmem_h(addr & ~1);
-		while(addr & 1) {
-			w = (w>>8) | (w<<8);
-			addr--;
-		}
-		return w;
-	}
-	if(membpt)
-		brkchk(addr, Read);
-
-	va = vaddr(addr);
-	va += addr&(BY2PG-1);
-
-	return va[1]<<8 | va[0];
-}
-
-uint8_t
-getmem_b(uint32_t addr)
-{
-	uint8_t *va;
-
-	if(membpt)
-		brkchk(addr, Read);
-
-	va = vaddr(addr);
-	va += addr&(BY2PG-1);
-	return va[0];
-}
-
-uint64_t
-getmem_v(uint32_t addr)
-{
-	return ((uint64_t)getmem_w(addr+4) << 32) | getmem_w(addr);
-}
-
-void
-putmem_h(uint32_t addr, uint16_t data)
-{
-	uint8_t *va;
-
-	if(addr&1) {
-		Bprint(bioout, "Address error (Store) vaddr %.8lux\n", addr);
-		longjmp(errjmp, 0);
-	}
-
-	va = vaddr(addr);
-	va += addr&(BY2PG-1);
-
-	va[1] = data>>8;
-	va[0] = data;
-	if(membpt)
-		brkchk(addr, Write);
-}
-
-void
-putmem_w(uint32_t addr, uint32_t data)
-{
-	uint8_t *va;
-
-	if(addr&3) {
-		Bprint(bioout, "Address error (Store) vaddr %.8lux\n", addr);
-		longjmp(errjmp, 0);
-	}
-
-	va = vaddr(addr);
-	va += addr&(BY2PG-1);
-
-	va[3] = data>>24;
-	va[2] = data>>16;
-	va[1] = data>>8;
-	va[0] = data;
-	if(membpt)
-		brkchk(addr, Write);
-}
-
-void
-putmem_b(uint32_t addr, uint8_t data)
-{
-	uint8_t *va;
-
-	va = vaddr(addr);
-	va += addr&(BY2PG-1);
-	va[0] = data;
-	if(membpt)
-		brkchk(addr, Write);
-}
-
-void
-putmem_v(uint32_t addr, uint64_t data)
-{
-	putmem_w(addr, data);	/* two stages, to catch brkchk */
-	putmem_w(addr+4, data>>32);
-}
-
-char *
-memio(char *mb, uint32_t mem, int size, int dir)
-{
-	int i;
-	char *buf, c;
-
-	if(mb == 0)
-		mb = emalloc(size);
-
-	buf = mb;
-	switch(dir) {
-	default:
-		fatal(0, "memio");
-	case MemRead:
-		while(size--)
-			*mb++ = getmem_b(mem++);
-		break;
-	case MemReadstring:
-		for(;;) {
-			if(size-- == 0) {
-				Bprint(bioout, "memio: user/kernel copy too long for arm\n");
-				longjmp(errjmp, 0);
-			}
-			c = getmem_b(mem++);
-			*mb++ = c;
-			if(c == '\0')
-				break;
-		}
-		break;
-	case MemWrite:
-		for(i = 0; i < size; i++)
-			putmem_b(mem++, *mb++);
-		break;
-	}
-	return buf;
-}
-
-void
-dotlb(uint32_t vaddr)
-{
-	uint32_t *l, *e;
-
-	vaddr &= ~(BY2PG-1);
-
-	e = &tlb.tlbent[tlb.tlbsize];
-	for(l = tlb.tlbent; l < e; l++)
-		if(*l == vaddr) {
-			tlb.hit++;
-			return;
-		}
-
-	tlb.miss++;
-	tlb.tlbent[lnrand(tlb.tlbsize)] = vaddr;
-}
-
-void *
-vaddr(uint32_t addr)
-{
-	Segment *s, *es;
-	int off, foff, l, n;
-	uint8_t **p, *a;
-
-	if(tlb.on)
-		dotlb(addr);
-
-	es = &memory.seg[Nseg];
-	for(s = memory.seg; s < es; s++) {
-		if(addr >= s->base && addr < s->end) {
-			s->refs++;
-			off = (addr-s->base)/BY2PG;
-			p = &s->table[off];
-			if(*p)
-				return *p;
-			s->rss++;
-			switch(s->type) {
-			default:
-				fatal(0, "vaddr");
-			case Text:
-				*p = emalloc(BY2PG);
-				if(seek(text, s->fileoff+(off*BY2PG), 0) < 0)
-					fatal(1, "vaddr text seek");
-				if(read(text, *p, BY2PG) < 0)
-					fatal(1, "vaddr text read");
-				return *p;
-			case Data:
-				*p = emalloc(BY2PG);
-				foff = s->fileoff+(off*BY2PG);
-				if(seek(text, foff, 0) < 0)
-					fatal(1, "vaddr text seek");
-				n = read(text, *p, BY2PG);
-				if(n < 0)
-					fatal(1, "vaddr text read");
-				if(foff + n > s->fileend) {
-					l = BY2PG - (s->fileend-foff);
-					a = *p+(s->fileend-foff);
-					memset(a, 0, l);
-				}
-				return *p;
-			case Bss:
-			case Stack:
-				*p = emalloc(BY2PG);
-				return *p;
-			}
-		}
-	}
-	Bprint(bioout, "User TLB miss vaddr 0x%.8lux\n", addr);
-	longjmp(errjmp, 0);
-	return 0;		/*to stop compiler whining*/
-}

+ 0 - 26
sys/src/cmd/5i/mkfile

@@ -1,26 +0,0 @@
-</$objtype/mkfile
-
-TARG=5i
-OFILES=	5i.$O\
-	run.$O\
-	mem.$O\
-	syscall.$O\
-	stats.$O\
-	icache.$O\
-	symbols.$O\
-	cmd.$O\
-	bpt.$O\
-
-HFILES=arm.h\
-
-BIN=/$objtype/bin
-
-UPDATE=\
-	mkfile\
-	$HFILES\
-	${OFILES:%.$O=%.c}\
-
-</sys/src/cmd/mkone
-
-acid:	
-	$CC -a run.c > acid.def

+ 0 - 957
sys/src/cmd/5i/run.c

@@ -1,957 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <bio.h>
-#include <mach.h>
-#include "arm.h"
-
-static	int	dummy;
-static	char*	shtype[4] =
-{
-	"<<",
-	">>",
-	"->",
-	"@>",
-};
-static	char*	cond[16] =
-{
-	".EQ",	".NE",	".HS",	".LO",
-	".MI",	".PL",	".VS",	".VC",
-	".HI",	".LS",	".GE",	".LT",
-	".GT",	".LE",	"",	".NO",
-};
-
-void	Idp0(ulong);
-void	Idp1(ulong);
-void	Idp2(ulong);
-void	Idp3(ulong);
-
-void	Imul(ulong);
-void	Imula(ulong);
-void	Imull(ulong);
-
-void	Iswap(ulong);
-void	Imem1(ulong);
-void	Imem2(ulong);
-void	Ilsm(uint32_t inst);
-
-void	Ib(uint32_t);
-void	Ibl(uint32_t);
-
-void	Ssyscall(uint32_t);
-
-Inst itab[] =
-{
-	{ Idp0,		"AND",	Iarith },	/* 00 - r,r,r */
-	{ Idp0,		"EOR",	Iarith },	/* 01 */
-	{ Idp0,		"SUB",	Iarith },	/* 02 */
-	{ Idp0,		"RSB",	Iarith },	/* 03 */
-	{ Idp0,		"ADD",	Iarith },	/* 04 */
-	{ Idp0,		"ADC",	Iarith },	/* 05 */
-	{ Idp0,		"SBC",	Iarith },	/* 06 */
-	{ Idp0,		"RSC",	Iarith },	/* 07 */
-	{ Idp0,		"TST",	Iarith },	/* 08 */
-	{ Idp0,		"TEQ",	Iarith },	/* 09 */
-
-	{ Idp0,		"CMP",	Iarith },	/* 10 */
-	{ Idp0,		"CMN",	Iarith },	/* 11 */
-	{ Idp0,		"ORR",	Iarith },	/* 12 */
-	{ Idp0,		"MOV",	Iarith },	/* 13 */
-	{ Idp0,		"BIC",	Iarith },	/* 14 */
-	{ Idp0,		"MVN",	Iarith },	/* 15 */
-	{ Idp1,		"AND",	Iarith },	/* 16 */
-	{ Idp1,		"EOR",	Iarith },	/* 17 */
-	{ Idp1,		"SUB",	Iarith },	/* 18 */
-	{ Idp1,		"RSB",	Iarith },	/* 19 */
-
-	{ Idp1,		"ADD",	Iarith },	/* 20 */
-	{ Idp1,		"ADC",	Iarith },	/* 21 */
-	{ Idp1,		"SBC",	Iarith },	/* 22 */
-	{ Idp1,		"RSC",	Iarith },	/* 23 */
-	{ Idp1,		"TST",	Iarith },	/* 24 */
-	{ Idp1,		"TEQ",	Iarith },	/* 25 */
-	{ Idp1,		"CMP",	Iarith },	/* 26 */
-	{ Idp1,		"CMN",	Iarith },	/* 27 */
-	{ Idp1,		"ORR",	Iarith },	/* 28 */
-	{ Idp1,		"MOV",	Iarith },	/* 29 */
-
-	{ Idp1,		"BIC",	Iarith },	/* 30 */
-	{ Idp1,		"MVN",	Iarith },	/* 31 */
-	{ Idp2,		"AND",	Iarith },	/* 32 */
-	{ Idp2,		"EOR",	Iarith },	/* 33 */
-	{ Idp2,		"SUB",	Iarith },	/* 34 */
-	{ Idp2,		"RSB",	Iarith },	/* 35 */
-	{ Idp2,		"ADD",	Iarith },	/* 36 */
-	{ Idp2,		"ADC",	Iarith },	/* 37 */
-	{ Idp2,		"SBC",	Iarith },	/* 38 */
-	{ Idp2,		"RSC",	Iarith },	/* 39 */
-
-	{ Idp2,		"TST",	Iarith },	/* 40 */
-	{ Idp2,		"TEQ",	Iarith },	/* 41 */
-	{ Idp2,		"CMP",	Iarith },	/* 42 */
-	{ Idp2,		"CMN",	Iarith },	/* 43 */
-	{ Idp2,		"ORR",	Iarith },	/* 44 */
-	{ Idp2,		"MOV",	Iarith },	/* 45 */
-	{ Idp2,		"BIC",	Iarith },	/* 46 */
-	{ Idp2,		"MVN",	Iarith },	/* 47 */
-	{ Idp3,		"AND",	Iarith },	/* 48 - i,r,r */
-	{ Idp3,		"EOR",	Iarith },	/* 49 */
-
-	{ Idp3,		"SUB",	Iarith },	/* 50 */
-	{ Idp3,		"RSB",	Iarith },	/* 51 */
-	{ Idp3,		"ADD",	Iarith },	/* 52 */
-	{ Idp3,		"ADC",	Iarith },	/* 53 */
-	{ Idp3,		"SBC",	Iarith },	/* 54 */
-	{ Idp3,		"RSC",	Iarith },	/* 55 */
-	{ Idp3,		"TST",	Iarith },	/* 56 */
-	{ Idp3,		"TEQ",	Iarith },	/* 57 */
-	{ Idp3,		"CMP",	Iarith },	/* 58 */
-	{ Idp3,		"CMN",	Iarith },	/* 59 */
-
-	{ Idp3,		"ORR",	Iarith },	/* 60 */
-	{ Idp3,		"MOV",	Iarith },	/* 61 */
-	{ Idp3,		"BIC",	Iarith },	/* 62 */
-	{ Idp3,		"MVN",	Iarith },	/* 63 */
-	{ Imul,		"MUL",	Iarith },	/* 64 */
-	{ Imula,	"MULA",	Iarith },	/* 65 */
-
-	{ Iswap,	"SWPW",	Imem },	/* 66 */
-	{ Iswap,	"SWPBU",	Imem },	/* 67 */
-
-	{ Imem2,	"MOV",	Imem },	/* 68 load/store h/sb */
-	{ Imem2,	"MOV",	Imem },	/* 69 */
-	{ Imem2,	"MOV",	Imem },	/* 70 */
-	{ Imem2,	"MOV",	Imem },	/* 71 */
-
-	{ Imem1,	"MOVW",	Imem },	/* 72 load/store w/ub i,r */
-	{ Imem1,	"MOVB",	Imem },	/* 73 */
-	{ Imem1,	"MOVW",	Imem },	/* 74 */
-	{ Imem1,	"MOVB",	Imem },	/* 75 */
-	{ Imem1,	"MOVW",	Imem },	/* 76 load/store r,r */
-	{ Imem1,	"MOVB",	Imem },	/* 77 */
-	{ Imem1,	"MOVW",	Imem },	/* 78 */
-	{ Imem1,	"MOVB",	Imem },	/* 79 */
-
-	{ Ilsm,		"LDM",	Imem },	/* 80 block move r,r */
-	{ Ilsm,		"STM",	Imem },	/* 81 */
-	{ Ib,		"B",	Ibranch },		/* 82 branch */
-	{ Ibl,		"BL",	Ibranch },		/* 83 */
-	{ Ssyscall,	"SWI",	Isyscall },	/* 84 co processor */
-	{ undef,	"undef" },	/* 85 */
-	{ undef,	"undef" },	/* 86 */
-	{ undef,	"undef"  },	/* 87 */
-	{ Imull,	"MULLU",	Iarith },	/* 88 */
-	{ Imull,	"MULALU",	Iarith },	/* 89 */
-	{ Imull,	"MULL",	Iarith  },	/* 90 */
-	{ Imull,	"MULAL",	Iarith  },	/* 91 */
-	{ undef,	"undef"  },	/* 92 */
-
-	{ 0 }
-};
-
-int
-runcmp(void)
-{
-	switch(reg.cond) {
-	case 0x0:	/* eq */	return (reg.cc1 == reg.cc2);
-	case 0x1:	/* ne */	return (reg.cc1 != reg.cc2);
-	case 0x2:	/* hs */	return ((uint32_t)reg.cc1 >= (uint32_t)reg.cc2);
-	case 0x3:	/* lo */	return ((uint32_t)reg.cc1 < (uint32_t)reg.cc2);
-	case 0x4:	/* mi */	return (reg.cc1 - reg.cc2 < 0);
-	case 0x5:	/* pl */	return (reg.cc1 - reg.cc2 >= 0);
-	case 0x8:	/* hi */	return ((uint32_t)reg.cc1 > (uint32_t)reg.cc2);
-	case 0x9:	/* ls */	return ((uint32_t)reg.cc1 <= (uint32_t)reg.cc2);
-	case 0xa:	/* ge */	return (reg.cc1 >= reg.cc2);
-	case 0xb:	/* lt */	return (reg.cc1 < reg.cc2);
-	case 0xc:	/* gt */	return (reg.cc1 > reg.cc2);
-	case 0xd:	/* le */	return (reg.cc1 <= reg.cc2);
-	case 0xe:	/* al */	return 1;
-	case 0xf:	/* nv */	return 0;
-	default:
-		Bprint(bioout, "unimplemented condition prefix %x (%ld %ld)\n",
-			reg.cond, reg.cc1, reg.cc2);
-		undef(reg.ir);
-		return 0;
-	}
-}
-
-int
-runteq(void)
-{
-	int32_t res = reg.cc1 ^ reg.cc2;
-	switch(reg.cond) {
-	case 0x0:	/* eq */	return res == 0;
-	case 0x1:	/* ne */	return res != 0;
-	case 0x4:	/* mi */	return (res & SIGNBIT) != 0;
-	case 0x5:	/* pl */	return (res & SIGNBIT) == 0;
-	case 0xe:	/* al */	return 1;
-	case 0xf:	/* nv */	return 0;
-	default:
-		Bprint(bioout, "unimplemented condition prefix %x (%ld %ld)\n",
-			reg.cond, reg.cc1, reg.cc2);
-		undef(reg.ir);
-		return 0;
-	}
-}
-
-int
-runtst(void)
-{
-	int32_t res = reg.cc1 & reg.cc2;
-	switch(reg.cond) {
-	case 0x0:	/* eq */	return res == 0;
-	case 0x1:	/* ne */	return res != 0;
-	case 0x4:	/* mi */	return (res & SIGNBIT) != 0;
-	case 0x5:	/* pl */	return (res & SIGNBIT) == 0;
-	case 0xe:	/* al */	return 1;
-	case 0xf:	/* nv */	return 0;
-	default:
-		Bprint(bioout, "unimplemented condition prefix %x (%ld %ld)\n",
-			reg.cond, reg.cc1, reg.cc2);
-		undef(reg.ir);
-		return 0;
-	}
-}
-
-void
-run(void)
-{
-	int execute;
-
-	do {
-		if(trace)
-			Bflush(bioout);
-		reg.ar = reg.r[REGPC];
-		reg.ir = ifetch(reg.ar);
-		reg.class = armclass(reg.ir);
-		reg.ip = &itab[reg.class];
-		reg.cond = (reg.ir>>28) & 0xf;
-		switch(reg.compare_op) {
-		case CCcmp:
-			execute = runcmp();
-			break;
-		case CCteq:
-			execute = runteq();
-			break;
-		case CCtst:
-			execute = runtst();
-			break;
-		default:
-			Bprint(bioout, "unimplemented compare operation %x\n",
-				reg.compare_op);
-			return;
-		}
-
-		if(execute) {
-			reg.ip->count++;
-			(*reg.ip->func)(reg.ir);
-		} else {
-			if(trace)
-				itrace("%s%s	IGNORED",
-					reg.ip->name, cond[reg.cond]);
-		}
-		reg.r[REGPC] += 4;
-		if(bplist)
-			brkchk(reg.r[REGPC], Instruction);
-	} while(--count);
-}
-
-void
-undef(uint32_t inst)
-{
-	Bprint(bioout, "undefined instruction trap pc #%lux inst %.8lux class %d\n",
-		reg.r[REGPC], inst, reg.class);
-	longjmp(errjmp, 0);
-}
-
-int32_t
-shift(int32_t v, int st, int sc, int isreg)
-{
-	if(sc == 0) {
-		switch(st) {
-		case 0:	/* logical left */
-			reg.cout = reg.cbit;
-			break;
-		case 1:	/* logical right */
-			reg.cout = (v >> 31) & 1;
-			break;
-		case 2:	/* arith right */
-			reg.cout = reg.cbit;
-			break;
-		case 3:	/* rotate right */
-			if(isreg) {
-				reg.cout = reg.cbit;
-			}
-			else {
-				reg.cout = v & 1;
-				v = ((uint32_t)v >> 1) | (reg.cbit << 31);
-			}
-		}
-	}
-	else {
-		switch(st) {
-		case 0:	/* logical left */
-			reg.cout = (v >> (32 - sc)) & 1;
-			v = v << sc;
-			break;
-		case 1:	/* logical right */
-			reg.cout = (v >> (sc - 1)) & 1;
-			v = (uint32_t)v >> sc;
-			break;
-		case 2:	/* arith right */
-			if(sc >= 32) {
-				reg.cout = (v >> 31) & 1;
-				if(reg.cout)
-					v = 0xFFFFFFFF;
-				else
-					v = 0;
-			}
-			else {
-				reg.cout = (v >> (sc - 1)) & 1;
-				v = (int32_t)v >> sc;
-			}
-			break;
-		case 3:	/* rotate right */
-			reg.cout = (v >> (sc - 1)) & 1;
-			v = (v << (32-sc)) | ((uint32_t)v >> sc);
-			break;
-		}
-	}
-	return v;
-}
-
-void
-dpex(long inst, long o1, long o2, int rd)
-{
-	int cbit;
-
-	cbit = 0;
-	switch((inst>>21) & 0xf) {
-	case  0:	/* and */
-		reg.r[rd] = o1 & o2;
-		cbit = 1;
-		break;
-	case  1:	/* eor */
-		reg.r[rd] = o1 ^ o2;
-		cbit = 1;
-		break;
-	case  2:	/* sub */
-		reg.r[rd] = o1 - o2;
-	case 10:	/* cmp */
-		if(inst & Sbit) {
-			reg.cc1 = o1;
-			reg.cc2 = o2;
-			reg.compare_op = CCcmp;
-		}
-		return;
-	case  3:	/* rsb */
-		reg.r[rd] = o2 - o1;
-		if(inst & Sbit) {
-			reg.cc1 = o2;
-			reg.cc2 = o1;
-			reg.compare_op = CCcmp;
-		}
-		return;
-	case  4:	/* add */
-		if(calltree && rd == REGPC && o2 == 0) {
-			Symbol s;
-
-			findsym(o1 + o2, CTEXT, &s);
-			Bprint(bioout, "%8lux return to %lux %s r0=%lux\n",
-						reg.r[REGPC], o1 + o2, s.name, reg.r[REGRET]);
-		}
-		reg.r[rd] = o1 + o2;
-		if(inst & Sbit) {
-			if(((uvlong)(ulong)o1 + (uvlong)(ulong)o2) & (1LL << 32))
-				reg.cbit = 1;
-			else
-				reg.cbit = 0;
-			reg.cc1 = o2;
-			reg.cc2 = -o1;
-			reg.compare_op = CCcmp;
-		}
-		return;
-	case  5:	/* adc */
-	case  6:	/* sbc */
-	case  7:	/* rsc */
-		undef(inst);
-	case  8:	/* tst */
-		if(inst & Sbit) {
-			reg.cc1 = o1;
-			reg.cc2 = o2;
-			reg.compare_op = CCtst;
-		}
-		return;
-	case  9:	/* teq */
-		if(inst & Sbit) {
-			reg.cc1 = o1;
-			reg.cc2 = o2;
-			reg.compare_op = CCteq;
-		}
-		return;
-	case 11:	/* cmn */
-		if(inst & Sbit) {
-			reg.cc1 = o1;
-			reg.cc2 = -o2;
-			reg.compare_op = CCcmp;
-		}
-		return;
-	case 12:	/* orr */
-		reg.r[rd] = o1 | o2;
-		cbit = 1;
-		break;
-	case 13:	/* mov */
-		reg.r[rd] = o2;
-		cbit = 1;
-		break;
-	case 14:	/* bic */
-		reg.r[rd] = o1 & ~o2;
-		cbit = 1;
-		break;
-	case 15:	/* mvn */
-		reg.r[rd] = ~o2;
-		cbit = 1;
-		break;
-	}
-	if(inst & Sbit) {
-		if(cbit)
-			reg.cbit = reg.cout;
-		reg.cc1 = reg.r[rd];
-		reg.cc2 = 0;
-		reg.compare_op = CCcmp;
-	}
-}
-
-/*
- * data processing instruction R,R,R
- */
-void
-Idp0(uint32_t inst)
-{
-	int rn, rd, rm;
-	int32_t o1, o2;
-
-	rn = (inst>>16) & 0xf;
-	rd = (inst>>12) & 0xf;
-	rm = inst & 0xf;
-	o1 = reg.r[rn];
-	if(rn == REGPC)
-		o1 += 8;
-	o2 = reg.r[rm];
-	if(rm == REGPC)
-		o2 += 8;
-
-	dpex(inst, o1, o2, rd);
-	if(trace)
-		itrace("%s%s\tR%d,R%d,R%d =#%x",
-			reg.ip->name, cond[reg.cond],
-			rm, rn, rd,
-			reg.r[rd]);
-	if(rd == REGPC)
-		reg.r[rd] -= 4;
-}
-
-/*
- * data processing instruction (R<>#),R,R
- */
-void
-Idp1(uint32_t inst)
-{
-	int rn, rd, rm, st, sc;
-	int32_t o1, o2;
-
-	rn = (inst>>16) & 0xf;
-	rd = (inst>>12) & 0xf;
-	rm = inst & 0xf;
-	st = (inst>>5) & 0x3;
-	sc = (inst>>7) & 0x1f;
-	o1 = reg.r[rn];
-	if(rn == REGPC)
-		o1 += 8;
-	o2 = reg.r[rm];
-	if(rm == REGPC)
-		o2 += 8;
-	o2 = shift(o2, st, sc, 0);
-	dpex(inst, o1, o2, rd);
-	if(trace)
-		itrace("%s%s\tR%d%s%d,R%d,R%d =#%x",
-			reg.ip->name, cond[reg.cond], rm, shtype[st], sc, rn, rd,
-			reg.r[rd]);
-	if(rd == REGPC)
-		reg.r[rd] -= 4;
-}
-
-/*
- * data processing instruction (R<>R),R,R
- */
-void
-Idp2(uint32_t inst)
-{
-	int rn, rd, rm, rs, st;
-	int32_t o1, o2, o3;
-
-	rn = (inst>>16) & 0xf;
-	rd = (inst>>12) & 0xf;
-	rm = inst & 0xf;
-	st = (inst>>5) & 0x3;
-	rs = (inst>>8) & 0xf;
-	o1 = reg.r[rn];
-	if(rn == REGPC)
-		o1 += 8;
-	o2 = reg.r[rm];
-	if(rm == REGPC)
-		o2 += 8;
-	o3 = reg.r[rs];
-	if(rs == REGPC)
-		o3 += 8;
-	o2 = shift(o2, st, o3, 1);
-	dpex(inst, o1, o2, rd);
-	if(trace)
-		itrace("%s%s\tR%d%sR%d=%d,R%d,R%d =#%x",
-			reg.ip->name, cond[reg.cond], rm, shtype[st], rs, o3, rn, rd,
-			reg.r[rd]);
-	if(rd == REGPC)
-		reg.r[rd] -= 4;
-}
-
-/*
- * data processing instruction #<>#,R,R
- */
-void
-Idp3(uint32_t inst)
-{
-	int rn, rd, sc;
-	int32_t o1, o2;
-
-	rn = (inst>>16) & 0xf;
-	rd = (inst>>12) & 0xf;
-	o1 = reg.r[rn];
-	if(rn == REGPC)
-		o1 += 8;
-	o2 = inst & 0xff;
-	sc = (inst>>7) & 0x1e;
-	o2 = (o2 >> sc) | (o2 << (32 - sc));
-
-	dpex(inst, o1, o2, rd);
-	if(trace)
-		itrace("%s%s\t#%x,R%d,R%d =#%x",
-			reg.ip->name, cond[reg.cond], o2, rn, rd,
-			reg.r[rd]);
-	if(rd == REGPC)
-		reg.r[rd] -= 4;
-}
-
-void
-Imul(uint32_t inst)
-{
-	int rs, rd, rm;
-
-	rd = (inst>>16) & 0xf;
-	rs = (inst>>8) & 0xf;
-	rm = inst & 0xf;
-
-	if(rd == REGPC || rs == REGPC || rm == REGPC || rd == rm)
-		undef(inst);
-
-	reg.r[rd] = reg.r[rm]*reg.r[rs];
-
-	if(trace)
-		itrace("%s%s\tR%d,R%d,R%d =#%x",
-			reg.ip->name, cond[reg.cond], rs, rm, rd,
-			reg.r[rd]);
-}
-
-void
-Imull(uint32_t inst)
-{
-	int64_t v;
-	int rs, rd, rm, rn;
-
-	rd = (inst>>16) & 0xf;
-	rn = (inst>>12) & 0xf;
-	rs = (inst>>8) & 0xf;
-	rm = inst & 0xf;
-
-	if(rd == REGPC || rn == REGPC || rs == REGPC || rm == REGPC
-	|| rd == rm || rn == rm || rd == rn)
-		undef(inst);
-
-	if(inst & (1<<22)){
-		v = (int64_t)reg.r[rm] * (int64_t)reg.r[rs];
-		if(inst & (1 << 21))
-			v += reg.r[rn];
-	}else{
-		v = (uint64_t)(uint32_t)reg.r[rm] * (uint64_t)(uint32_t)reg.r[rs];
-		if(inst & (1 << 21))
-			v += (uint32_t)reg.r[rn];
-	}
-	reg.r[rd] = v >> 32;
-	reg.r[rn] = v;
-
-	if(trace)
-		itrace("%s%s\tR%d,R%d,(R%d,R%d) =#%llx",
-			reg.ip->name, cond[reg.cond], rs, rm, rn, rd,
-			v);
-}
-
-void
-Imula(uint32_t inst)
-{
-	int rs, rd, rm, rn;
-
-	rd = (inst>>16) & 0xf;
-	rn = (inst>>12) & 0xf;
-	rs = (inst>>8) & 0xf;
-	rm = inst & 0xf;
-
-	if(rd == REGPC || rn == REGPC || rs == REGPC || rm == REGPC || rd == rm)
-		undef(inst);
-
-	reg.r[rd] = reg.r[rm]*reg.r[rs] + reg.r[rn];
-
-	if(trace)
-		itrace("%s%s\tR%d,R%d,R%d,R%d =#%x",
-			reg.ip->name, cond[reg.cond], rs, rm, rn, rd,
-			reg.r[rd]);
-}
-
-void
-Iswap(uint32_t inst)
-{
-	int rn, rd, rm;
-	uint32_t address, value, bbit;
-
-	bbit = inst & (1<<22);
-	rn = (inst>>16) & 0xf;
-	rd = (inst>>12) & 0xf;
-	rm = (inst>>0) & 0xf;
-
-	address = reg.r[rn];
-	if(bbit) {
-		value = getmem_b(address);
-		putmem_b(address, reg.r[rm]);
-	} else {
-		value = getmem_w(address);
-		putmem_w(address, reg.r[rm]);
-	}
-	reg.r[rd] = value;
-
-	if(trace) {
-		char *bw, *dotc;
-
-		bw = "";
-		if(bbit)
-			bw = "B";
-		dotc = cond[reg.cond];
-
-		itrace("SWP%s%s\t#%x(R%d),R%d #%lux=#%x",
-			bw, dotc,
-			rn, rd,
-			address, value);
-	}
-}
-
-/*
- * load/store word/byte
- */
-void
-Imem1(uint32_t inst)
-{
-	int rn, rd, off, rm, sc, st;
-	uint32_t address, value, pbit, ubit, bbit, wbit, lbit, bit25;
-
-	bit25 = inst & (1<<25);
-	pbit = inst & (1<<24);
-	ubit = inst & (1<<23);
-	bbit = inst & (1<<22);
-	wbit = inst & (1<<21);
-	lbit = inst & (1<<20);
-	rn = (inst>>16) & 0xf;
-	rd = (inst>>12) & 0xf;
-
-	SET(st);
-	SET(sc);
-	SET(rm);
-	if(bit25) {
-		rm = inst & 0xf;
-		st = (inst>>5) & 0x3;
-		sc = (inst>>7) & 0x1f;
-		off = reg.r[rm];
-		if(rm == REGPC)
-			off += 8;
-		off = shift(off, st, sc, 0);
-	} else {
-		off = inst & 0xfff;
-	}
-	if(!ubit)
-		off = -off;
-	if(rn == REGPC)
-		off += 8;
-
-	address = reg.r[rn];
-	if(pbit)
-		address += off;
-
-	if(lbit) {
-		if(bbit)
-			value = getmem_b(address);
-		else
-			value = getmem_w(address);
-		if(rd == REGPC)
-			value -= 4;
-		reg.r[rd] = value;
-	} else {
-		value = reg.r[rd];
-		if(rd == REGPC)
-			value -= 4;
-		if(bbit)
-			putmem_b(address, value);
-		else
-			putmem_w(address, value);
-	}
-	if(!(pbit && !wbit))
-		reg.r[rn] += off;
-
-	if(trace) {
-		char *bw, *dotp, *dotc;
-
-		bw = "W";
-		if(bbit)
-			bw = "BU";
-		dotp = "";
-		if(!pbit)
-			dotp = ".P";
-		dotc = cond[reg.cond];
-
-		if(lbit) {
-			if(!bit25)
-				itrace("MOV%s%s%s\t#%x(R%d),R%d #%lux=#%x",
-					bw, dotp, dotc,
-					off, rn, rd,
-					address, value);
-			else
-				itrace("MOV%s%s%s\t(R%d%s%d)(R%d),R%d  #%lux=#%x",
-					bw, dotp, dotc,
-					rm, shtype[st], sc, rn, rd,
-					address, value);
-		} else {
-			if(!bit25)
-				itrace("MOV%s%s%s\tR%d,#%x(R%d) #%lux=#%x",
-					bw, dotp, dotc,
-					rd, off, rn,
-					address, value);
-			else
-				itrace("MOV%s%s%s\tR%d,(R%d%s%d)(R%d) #%lux=#%x",
-					bw, dotp, dotc,
-					rd, rm, shtype[st], sc, rn,
-					address, value);
-		}
-	}
-}
-
-/*
- * load/store unsigned byte/half word
- */
-void
-Imem2(uint32_t inst)
-{
-	int rn, rd, off, rm;
-	uint32_t address, value, pbit, ubit, hbit, sbit, wbit, lbit, bit22;
-
-	pbit = inst & (1<<24);
-	ubit = inst & (1<<23);
-	bit22 = inst & (1<<22);
-	wbit = inst & (1<<21);
-	lbit = inst & (1<<20);
-	sbit = inst & (1<<6);
-	hbit = inst & (1<<5);
-	rn = (inst>>16) & 0xf;
-	rd = (inst>>12) & 0xf;
-
-	SET(rm);
-	if(bit22) {
-		off = ((inst>>4) & 0xf0) | (inst & 0xf);
-	} else {
-		rm = inst & 0xf;
-		off = reg.r[rm];
-		if(rm == REGPC)
-			off += 8;
-	}
-	if(!ubit)
-		off = -off;
-	if(rn == REGPC)
-		off += 8;
-
-	address = reg.r[rn];
-	if(pbit)
-		address += off;
-
-	if(lbit) {
-		if(hbit) {
-			value = getmem_h(address);
-			if(sbit && (value & 0x8000))
-				value |= 0xffff0000;
-		} else {
-			value = getmem_b(address);
-			if(value & 0x80)
-				value |= 0xffffff00;
-		}
-		if(rd == REGPC)
-			value -= 4;
-		reg.r[rd] = value;
-	} else {
-		value = reg.r[rd];
-		if(rd == REGPC)
-			value -= 4;
-		if(hbit) {
-			putmem_h(address, value);
-		} else {
-			putmem_b(address, value);
-		}
-	}
-	if(!(pbit && !wbit))
-		reg.r[rn] += off;
-
-	if(trace) {
-		char *hb, *dotp, *dotc;
-
-		hb = "B";
-		if(hbit)
-			hb = "H";
-		dotp = "";
-		if(!pbit)
-			dotp = ".P";
-		dotc = cond[reg.cond];
-
-		if(lbit) {
-			if(bit22)
-				itrace("MOV%s%s%s\t#%x(R%d),R%d #%lux=#%x",
-					hb, dotp, dotc,
-					off, rn, rd,
-					address, value);
-			else
-				itrace("MOV%s%s%s\t(R%d)(R%d),R%d  #%lux=#%x",
-					hb, dotp, dotc,
-					rm, rn, rd,
-					address, value);
-		} else {
-			if(bit22)
-				itrace("MOV%s%s%s\tR%d,#%x(R%d) #%lux=#%x",
-					hb, dotp, dotc,
-					rd, off, rn,
-					address, value);
-			else
-				itrace("MOV%s%s%s\tR%d,(R%d)(R%d) #%lux=#%x",
-					hb, dotp, dotc,
-					rd, rm, rn,
-					address, value);
-		}
-	}
-}
-
-void
-Ilsm(uint32_t inst)
-{
-	char pbit, ubit, sbit, wbit, lbit;
-	int i, rn, reglist;
-	uint32_t address, predelta, postdelta;
-
-	pbit = (inst>>24) & 0x1;
-	ubit = (inst>>23) & 0x1;
-	sbit = (inst>>22) & 0x1;
-	wbit = (inst>>21) & 0x1;
-	lbit = (inst>>20) & 0x1;
-	rn =   (inst>>16) & 0xf;
-	reglist = inst & 0xffff;
-
-	if(reglist & 0x8000)
-		undef(reg.ir);
-	if(sbit)
-		undef(reg.ir);
-
-	address = reg.r[rn];
-
-	if(pbit) {
-		predelta = 4;
-		postdelta = 0;
-	} else {
-		predelta = 0;
-		postdelta = 4;
-	}
-	if(ubit) {
-		for (i = 0; i < 16; ++i) {
-			if(!(reglist & (1 << i)))
-				continue;
-			address += predelta;
-			if(lbit)
-				reg.r[i] = getmem_w(address);
-			else
-				putmem_w(address, reg.r[i]);
-			address += postdelta;
-		}
-	} else {
-		for (i = 15; 0 <= i; --i) {
-			if(!(reglist & (1 << i)))
-				continue;
-			address -= predelta;
-			if(lbit)
-				reg.r[i] = getmem_w(address);
-			else
-				putmem_w(address, reg.r[i]);
-			address -= postdelta;
-		}
-	}
-	if(wbit) {
-		reg.r[rn] = address;
-	}
-
-	if(trace) {
-		itrace("%s.%c%c\tR%d=%lux%s, <%lux>",
-			(lbit ? "LDM" : "STM"), (ubit ? 'I' : 'D'), (pbit ? 'B' : 'A'),
-			rn, reg.r[rn], (wbit ? "!" : ""), reglist);
-	}
-}
-
-void
-Ib(uint32_t inst)
-{
-	int32_t v;
-
-	v = inst & 0xffffff;
-	v = reg.r[REGPC] + 8 + ((v << 8) >> 6);
-	if(trace)
-		itrace("B%s\t#%lux", cond[reg.cond], v);
-	reg.r[REGPC] = v - 4;
-}
-
-void
-Ibl(uint32_t inst)
-{
-	int32_t v;
-	Symbol s;
-
-	v = inst & 0xffffff;
-	v = reg.r[REGPC] + 8 + ((v << 8) >> 6);
-	if(trace)
-		itrace("BL%s\t#%lux", cond[reg.cond], v);
-
-	if(calltree) {
-		findsym(v, CTEXT, &s);
-		Bprint(bioout, "%8lux %s(", reg.r[REGPC], s.name);
-		printparams(&s, reg.r[13]);
-		Bprint(bioout, "from ");
-		printsource(reg.r[REGPC]);
-		Bputc(bioout, '\n');
-	}
-
-	reg.r[REGLINK] = reg.r[REGPC] + 4;
-	reg.r[REGPC] = v - 4;
-}

+ 0 - 208
sys/src/cmd/5i/stats.c

@@ -1,208 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <bio.h>
-#include <mach.h>
-#include "arm.h"
-
-#define Percent(num, max)	((max)?((num)*100)/(max):0)
-#define prof prof5i
-
-extern	Inst	itab[];
-Inst *tables[] = { itab, 0 };
-
-void
-isum(void)
-{
-	Inst *i;
-	int total, mems, arith, branch;
-	int useddelay, taken, syscall;
-	int pct, j;
-
-	total = 0;
-	mems = 0;
-	arith = 0;
-	branch = 0;
-	useddelay = 0;
-	taken = 0;
-	syscall = 0;
-
-	/* Compute the total so we can have percentages */
-	for(i = itab; i->func; i++)
-		if(i->name && i->count)
-			total += i->count;
-
-	Bprint(bioout, "\nInstruction summary.\n\n");
-
-	for(j = 0; tables[j]; j++) {
-		for(i = tables[j]; i->func; i++) {
-			if(i->name) {
-				/* This is gross */
-				if(i->count == 0)
-					continue;
-				pct = Percent(i->count, total);
-				if(pct != 0)
-					Bprint(bioout, "%-8ud %3d%% %s\n",
-						i->count, Percent(i->count,
-						total), i->name);
-				else
-					Bprint(bioout, "%-8ud      %s\n",
-						i->count, i->name);
-
-
-				switch(i->type) {
-				default:
-					fatal(0, "isum bad stype %d\n", i->type);
-				case Imem:
-					mems += i->count;
-					break;
-				case Iarith:
-					arith += i->count;
-					break;
-				case Ibranch:
-					branch += i->count;
-					taken += i->taken;
-					useddelay += i->useddelay;
-					break;
-				case Isyscall:
-					syscall += i->count;
-					break;
-				}
-		
-			}
-		}
-	}
-
-	Bprint(bioout, "\n%-8ud      Memory cycles\n", mems+total);	
-	Bprint(bioout, "%-8ud %3d%% Instruction cycles\n",
-			total, Percent(total, mems+total));
-	Bprint(bioout, "%-8ud %3d%% Data cycles\n\n",
-			mems, Percent(mems, mems+total));	
-
-	Bprint(bioout, "%-8ud %3d%% Arithmetic\n",
-			arith, Percent(arith, total));
-
-	Bprint(bioout, "%-8ud %3d%% System calls\n",
-			syscall, Percent(syscall, total));
-
-	Bprint(bioout, "%-8ud %3d%% Branches\n",
-			branch, Percent(branch, total));
-
-	Bprint(bioout, "   %-8ud %3d%% Branches taken\n",
-			taken, Percent(taken, branch));
-
-	Bprint(bioout, "   %-8ud %3d%% Delay slots\n",
-			useddelay, Percent(useddelay, branch));
-
-	Bprint(bioout, "   %-8ud %3d%% Unused delay slots\n", 
-			branch-useddelay, Percent(branch-useddelay, branch));
-
-	Bprint(bioout, "%-8ud %3d%% Program total delay slots\n",
-			nopcount, Percent(nopcount, total));
-}
-
-void
-tlbsum(void)
-{
-	if(tlb.on == 0)
-		return;
-
-	Bprint(bioout, "\n\nTlb summary\n");
-
-	Bprint(bioout, "\n%-8d User entries\n", tlb.tlbsize);
-	Bprint(bioout, "%-8d Accesses\n", tlb.hit+tlb.miss);
-	Bprint(bioout, "%-8d Tlb hits\n", tlb.hit);
-	Bprint(bioout, "%-8d Tlb misses\n", tlb.miss);
-	Bprint(bioout, "%7d%% Hit rate\n", Percent(tlb.hit, tlb.hit+tlb.miss));
-}
-
-char *stype[] = { "Stack", "Text", "Data", "Bss" };
-
-void
-segsum(void)
-{
-	Segment *s;
-	int i;
-
-	Bprint(bioout, "\n\nMemory Summary\n\n");
-	Bprint(bioout, "      Base     End      Resident References\n");
-	for(i = 0; i < Nseg; i++) {
-		s = &memory.seg[i];
-		Bprint(bioout, "%-5s %.8lux %.8lux %-8d %-8d\n",
-				stype[i], s->base, s->end, s->rss*BY2PG, s->refs);
-	}
-}
-
-typedef struct Prof Prof;
-struct Prof
-{
-	Symbol	s;
-	int32_t	count;
-};
-Prof	prof[5000];
-
-int
-profcmp(const void *va, const void *vb)
-{
-	Prof *a, *b;
-
-	a = va;
-	b = vb;
-	return b->count - a->count;
-}
-
-void
-iprofile(void)
-{
-	Prof *p, *n;
-	int i, b, e;
-	uint32_t total;
-	extern uint32_t textbase;
-
-	i = 0;
-	p = prof;
-	if(textsym(&p->s, i) == 0)
-		return;
-	i++;
-	for(;;) {
-		n = p+1;
-		if(textsym(&n->s, i) == 0)
-			break;
-		b = (p->s.value-textbase)/PROFGRAN;
-		e = (n->s.value-textbase)/PROFGRAN;
-		while(b < e)
-			p->count += iprof[b++];
-		i++;
-		p = n;
-	}
-
-	qsort(prof, i, sizeof(Prof), profcmp);
-
-	total = 0;
-	for(b = 0; b < i; b++)
-		total += prof[b].count;
-
-	Bprint(bioout, "  cycles     %% symbol          file\n");
-	for(b = 0; b < i; b++) {
-		if(prof[b].count == 0)
-			continue;
-
-		Bprint(bioout, "%8ld %3ld.%ld %-15s ",
-			prof[b].count,
-			100*prof[b].count/total,
-			(1000*prof[b].count/total)%10,
-			prof[b].s.name);
-
-		printsource(prof[b].s.value);
-		Bputc(bioout, '\n');
-	}
-	memset(prof, 0, sizeof(Prof)*i);
-}

+ 0 - 104
sys/src/cmd/5i/symbols.c

@@ -1,104 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <bio.h>
-#include <mach.h>
-#include "arm.h"
-
-#define	STRINGSZ	128
-
-/*
- *	print the value of dot as file:line
- */
-void
-printsource(int32_t dot)
-{
-	char str[STRINGSZ];
-
-	if (fileline(str, STRINGSZ, dot))
-		Bprint(bioout, "%s", str);
-}
-
-void
-printlocals(Symbol *fn, uint32_t fp)
-{
-	int i;
-	Symbol s;
-
-	s = *fn;
-	for (i = 0; localsym(&s, i); i++) {
-		if (s.class != CAUTO)
-			continue;
-		Bprint(bioout, "\t%s=#%lux\n", s.name, getmem_4(fp-s.value));
-	}
-}
-
-void
-printparams(Symbol *fn, uint32_t fp)
-{
-	int i;
-	Symbol s;
-	int first;
-
-	fp += mach->szreg;			/* skip saved pc */
-	s = *fn;
-	for (first = i = 0; localsym(&s, i); i++) {
-		if (s.class != CPARAM)
-			continue;
-		if (first++)
-			Bprint(bioout, ", ");
-		Bprint(bioout, "%s=#%lux", s.name, getmem_4(fp+s.value));
-	}
-	Bprint(bioout, ") ");
-}
-#define STARTSYM	"_main"
-#define	FRAMENAME	".frame"
-
-void
-stktrace(int modif)
-{
-	uint32_t pc, sp;
-	Symbol s, f;
-	int i;
-	char buf[512];
-
-	pc = reg.r[15];
-	sp = reg.r[13];
-	i = 0;
-	while (findsym(pc, CTEXT, &s)) {
-		if(strcmp(STARTSYM, s.name) == 0) {
-			Bprint(bioout, "%s() at #%llux\n", s.name, s.value);
-			break;
-		}
-		if (pc == s.value)	/* at first instruction */
-			f.value = 0;
-		else if (findlocal(&s, FRAMENAME, &f) == 0)
-			break;
-		if (s.type == 'L' || s.type == 'l' || pc <= s.value+4)
-			pc = reg.r[14];
-		else pc = getmem_4(sp);
-		sp += f.value;
-		Bprint(bioout, "%s(", s.name);
-		printparams(&s, sp);
-		printsource(s.value);
-		Bprint(bioout, " called from ");
-		symoff(buf, sizeof(buf), pc-8, CTEXT);
-		Bprint(bioout, buf);
-		printsource(pc-8);
-		Bprint(bioout, "\n");
-		if(modif == 'C')
-			printlocals(&s, sp);
-		if(++i > 40){
-			Bprint(bioout, "(trace truncated)\n");
-			break;
-		}
-	}
-}

+ 0 - 816
sys/src/cmd/5i/syscall.c

@@ -1,816 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <bio.h>
-#include <mach.h>
-#define	EXTERN
-#include "arm.h"
-
-#define	ODIRLEN	116	/* compatibility; used in _stat etc. */
-#define	OERRLEN	64	/* compatibility; used in _stat etc. */
-
-char 	errbuf[ERRMAX];
-uint32_t	nofunc;
-
-#include "/sys/src/libc/9syscall/sys.h"
-
-
-char*	sysctab[] =
-{
-	[SYSR1]		"Running",
-	[_ERRSTR]		"_errstr",
-	[BIND]		"Bind",
-	[CHDIR]		"Chdir",
-	[CLOSE]		"Close",
-	[DUP]		"Dup",
-	[ALARM]		"Alarm",
-	[EXEC]		"Exec",
-	[EXITS]		"Exits",
-	[_FSESSION]	"_Fsession",
-	[FAUTH]		"Fauth",
-	[_FSTAT]		"_fstat",
-	[SEGBRK]		"Segbrk",
-	[MOUNT]		"Mount",
-	[OPEN]		"Open",
-	[_READ]		"_Read",
-	[OSEEK]		"Oseek",
-	[SLEEP]		"Sleep",
-	[_STAT]		"_Stat",
-	[RFORK]		"Rfork",
-	[_WRITE]		"_Write",
-	[PIPE]		"Pipe",
-	[CREATE]		"Create",
-	[FD2PATH]	"Fd2path",
-	[BRK_]		"Brk_",
-	[REMOVE]		"Remove",
-	[_WSTAT]		"_Wstat",
-	[_FWSTAT]	"_Fwstat",
-	[NOTIFY]		"Notify",
-	[NOTED]		"Noted",
-	[SEGATTACH]	"Segattach",
-	[SEGDETACH]	"Segdetach",
-	[SEGFREE]		"Segfree",
-	[SEGFLUSH]	"Segflush",
-	[RENDEZVOUS]	"Rendezvous",
-	[UNMOUNT]	"Unmount",
-	[_WAIT]		"_Wait",
-	[SEEK]		"Seek",
-	[FVERSION]	"Fversion",
-	[ERRSTR]		"Errstr",
-	[STAT]		"Stat",
-	[FSTAT]		"Fstat",
-	[WSTAT]		"Wstat",
-	[FWSTAT]		"Fwstat",
-	[PREAD]		"Pread",
-	[PWRITE]		"Pwrite",
-	[AWAIT]		"Await",
-};
-
-void
-sys1(void)
-{
-	Bprint(bioout, "no system call %s\n", sysctab[reg.r[1]]);
-	exits(0);
-}
-
-void
-sys_errstr(void)
-{
-	uint32_t str;
-
-	str = getmem_w(reg.r[13]+4);
-	if(sysdbg)
-		itrace("errstr(0x%lux)", str);
-
-	memio(errbuf, str, OERRLEN, MemWrite);
-	strcpy(errbuf, "no error");
-	reg.r[REGRET] = 0;
-	
-}
-
-void
-syserrstr(void)
-{
-	uint32_t str;
-	int n;
-
-	str = getmem_w(reg.r[13]+4);
-	n = getmem_w(reg.r[13]+8);
-	if(sysdbg)
-		itrace("errstr(0x%lux, 0x%lux)", str, n);
-
-	if(n > strlen(errbuf)+1)
-		n = strlen(errbuf)+1;
-	memio(errbuf, str, n, MemWrite);
-	strcpy(errbuf, "no error");
-	reg.r[REGRET] = n;
-	
-}
-void
-sysbind(void)
-{ 
-	uint32_t pname, pold, flags;
-	char name[1024], old[1024];
-	int n;
-
-	pname = getmem_w(reg.r[13]+4);
-	pold = getmem_w(reg.r[13]+8);
-	flags = getmem_w(reg.r[13]+12);
-	memio(name, pname, sizeof(name), MemReadstring);
-	memio(old, pold, sizeof(old), MemReadstring);
-	if(sysdbg)
-		itrace("bind(0x%lux='%s', 0x%lux='%s', 0x%lux)", name, name, old, old, flags);
-
-	n = bind(name, old, flags);
-	if(n < 0)
-		errstr(errbuf, sizeof errbuf);
-
-	reg.r[REGRET] = n;
-}
-
-void
-sysfd2path(void)
-{
-	int n;
-	uint fd;
-	uint32_t str;
-	char buf[1024];
-
-	fd = getmem_w(reg.r[13]+4);
-	str = getmem_w(reg.r[13]+8);
-	n = getmem_w(reg.r[13]+12);
-	if(sysdbg)
-		itrace("fd2path(0x%lux, 0x%lux, 0x%lux)", fd, str, n);
-	reg.r[1] = -1;
-	if(n > sizeof buf){
-		strcpy(errbuf, "buffer too big");
-		return;
-	}
-	n = fd2path(fd, buf, sizeof buf);
-	if(n < 0)
-		errstr(buf, sizeof buf);
-	else
-		memio(errbuf, str, n, MemWrite);
-	reg.r[REGRET] = n;
-	
-}
-
-void
-syschdir(void)
-{ 
-	char file[1024];
-	int n;
-	uint32_t name;
-
-	name = getmem_w(reg.r[13]+4);
-	memio(file, name, sizeof(file), MemReadstring);
-	if(sysdbg)
-		itrace("chdir(0x%lux='%s', 0x%lux)", name, file);
-	
-	n = chdir(file);
-	if(n < 0)
-		errstr(errbuf, sizeof errbuf);
-
-	reg.r[REGRET] = n;
-}
-
-void
-sysclose(void)
-{
-	int n;
-	uint32_t fd;
-
-	fd = getmem_w(reg.r[13]+4);
-	if(sysdbg)
-		itrace("close(%d)", fd);
-
-	n = close(fd);
-	if(n < 0)
-		errstr(errbuf, sizeof errbuf);
-	reg.r[REGRET] = n;
-}
-
-void
-sysdup(void)
-{
-	int oldfd, newfd;
-	int n;
-
-	oldfd = getmem_w(reg.r[13]+4);
-	newfd = getmem_w(reg.r[13]+8);
-	if(sysdbg)
-		itrace("dup(%d, %d)", oldfd, newfd);
-
-	n = dup(oldfd, newfd);
-	if(n < 0)
-		errstr(errbuf, sizeof errbuf);
-	reg.r[REGRET] = n;
-}
-
-void
-sysexits(void)
-{
-	char buf[OERRLEN];
-	uint32_t str;
-
-	str = getmem_w(reg.r[13]+4);
-	if(sysdbg)
-		itrace("exits(0x%lux)", str);
-
-	count = 1;
-	if(str != 0) {
-		memio(buf, str, sizeof buf, MemRead);
-		Bprint(bioout, "exits(%s)\n", buf);
-	}
-	else
-		Bprint(bioout, "exits(0)\n");
-}
-
-void
-sysopen(void)
-{
-	char file[1024];
-	int n;
-	uint32_t mode, name;
-
-	name = getmem_w(reg.r[13]+4);
-	mode = getmem_w(reg.r[13]+8);
-	memio(file, name, sizeof(file), MemReadstring);
-	
-	n = open(file, mode);
-	if(n < 0)
-		errstr(errbuf, sizeof errbuf);
-
-	if(sysdbg)
-		itrace("open(0x%lux='%s', 0x%lux) = %d", name, file, mode, n);
-
-	reg.r[REGRET] = n;
-};
-
-
-void
-sysread(int64_t offset)
-{
-	int fd;
-	uint32_t size, a;
-	char *buf, *p;
-	int n, cnt, c;
-
-	fd = getmem_w(reg.r[13]+4);
-	a = getmem_w(reg.r[13]+8);
-	size = getmem_w(reg.r[13]+12);
-
-	buf = emalloc(size);
-	if(fd == 0) {
-		print("\nstdin>>");
-		p = buf;
-		n = 0;
-		cnt = size;
-		while(cnt) {
-			c = Bgetc(bin);
-			if(c <= 0)
-				break;
-			*p++ = c;
-			n++;
-			cnt--;
-			if(c == '\n')
-				break;
-		}
-	}
-	else
-		n = pread(fd, buf, size, offset);
-
-	if(n < 0)
-		errstr(errbuf, sizeof errbuf);
-	else
-		memio(buf, a, n, MemWrite);
-
-	if(sysdbg)
-		itrace("read(%d, 0x%lux, %d, 0x%llx) = %d", fd, a, size, offset, n);
-
-	free(buf);
-	reg.r[REGRET] = n;
-}
-
-void
-sys_read(void)
-{
-	sysread(-1LL);
-}
-
-void
-syspread(void)
-{
-	sysread(getmem_v(reg.r[13]+16));
-}
-
-void
-sysseek(void)
-{
-	int fd;
-	uint32_t mode;
-	uint32_t retp;
-	int64_t v;
-
-	retp = getmem_w(reg.r[13]+4);
-	fd = getmem_w(reg.r[13]+8);
-	v = getmem_v(reg.r[13]+16);
-	mode = getmem_w(reg.r[13]+20);
-	if(sysdbg)
-		itrace("seek(%d, %lld, %d)", fd, v, mode);
-
-	v = seek(fd, v, mode);
-	if(v < 0)
-		errstr(errbuf, sizeof errbuf);	
-
-	putmem_v(retp, v);
-}
-
-void
-sysoseek(void)
-{
-	int fd, n;
-	uint32_t off, mode;
-
-	fd = getmem_w(reg.r[13]+4);
-	off = getmem_w(reg.r[13]+8);
-	mode = getmem_w(reg.r[13]+12);
-	if(sysdbg)
-		itrace("seek(%d, %lud, %d)", fd, off, mode);
-
-	n = seek(fd, off, mode);
-	if(n < 0)
-		errstr(errbuf, sizeof errbuf);	
-
-	reg.r[REGRET] = n;
-}
-
-void
-syssleep(void)
-{
-	uint32_t len;
-	int n;
-
-	len = getmem_w(reg.r[13]+4);
-	if(sysdbg)
-		itrace("sleep(%d)", len);
-
-	n = sleep(len);
-	if(n < 0)
-		errstr(errbuf, sizeof errbuf);	
-
-	reg.r[REGRET] = n;
-}
-
-void
-sys_stat(void)
-{
-	char nambuf[1024];
-	char buf[ODIRLEN];
-	uint32_t edir, name;
-	extern int _stat(char*, char*);	/* old system call */
-	int n;
-
-	name = getmem_w(reg.r[13]+4);
-	edir = getmem_w(reg.r[13]+8);
-	memio(nambuf, name, sizeof(nambuf), MemReadstring);
-	if(sysdbg)
-		itrace("stat(0x%lux='%s', 0x%lux)", name, nambuf, edir);
-
-	n = _stat(nambuf, buf);
-	if(n < 0)
-		errstr(errbuf, sizeof errbuf);
-	else
-		memio(buf, edir, ODIRLEN, MemWrite);
-
-	reg.r[REGRET] = n;
-}
-
-void
-sysstat(void)
-{
-	char nambuf[1024];
-	uint8_t buf[STATMAX];
-	uint32_t edir, name;
-	int n;
-
-	name = getmem_w(reg.r[13]+4);
-	edir = getmem_w(reg.r[13]+8);
-	n = getmem_w(reg.r[13]+12);
-	memio(nambuf, name, sizeof(nambuf), MemReadstring);
-	if(sysdbg)
-		itrace("stat(0x%lux='%s', 0x%lux, 0x%lux)", name, nambuf, edir, n);
-	if(n > sizeof buf)
-		errstr(errbuf, sizeof errbuf);
-	else{	
-		n = stat(nambuf, buf, n);
-		if(n < 0)
-			errstr(errbuf, sizeof errbuf);
-		else
-			memio((char*)buf, edir, n, MemWrite);
-	}
-	reg.r[REGRET] = n;
-}
-
-void
-sys_fstat(void)
-{
-	char buf[ODIRLEN];
-	extern int _fstat(int, char*);	/* old system call */
-	uint32_t edir;
-	int n, fd;
-
-	fd = getmem_w(reg.r[13]+4);
-	edir = getmem_w(reg.r[13]+8);
-	if(sysdbg)
-		itrace("fstat(%d, 0x%lux)", fd, edir);
-
-	n = _fstat(fd, buf);
-	if(n < 0)
-		errstr(errbuf, sizeof errbuf);
-	else
-		memio(buf, edir, ODIRLEN, MemWrite);
-
-	reg.r[REGRET] = n;
-}
-
-void
-sysfstat(void)
-{
-	uint8_t buf[STATMAX];
-	uint32_t edir;
-	int n, fd;
-
-	fd = getmem_w(reg.r[13]+4);
-	edir = getmem_w(reg.r[13]+8);
-	n = getmem_w(reg.r[13]+12);
-	if(sysdbg)
-		itrace("fstat(%d, 0x%lux, 0x%lux)", fd, edir, n);
-
-	reg.r[REGRET] = -1;
-	if(n > sizeof buf){
-		strcpy(errbuf, "stat buffer too big");
-		return;
-	}
-	n = fstat(fd, buf, n);
-	if(n < 0)
-		errstr(errbuf, sizeof errbuf);
-	else
-		memio((char*)buf, edir, n, MemWrite);
-	reg.r[REGRET] = n;
-}
-
-void
-syswrite(int64_t offset)
-{
-	int fd;
-	uint32_t size, a;
-	char *buf;
-	int n;
-
-	fd = getmem_w(reg.r[13]+4);
-	a = getmem_w(reg.r[13]+8);
-	size = getmem_w(reg.r[13]+12);
-
-	Bflush(bioout);
-	buf = memio(0, a, size, MemRead);
-	n = pwrite(fd, buf, size, offset);
-	if(n < 0)
-		errstr(errbuf, sizeof errbuf);	
-
-	if(sysdbg)
-		itrace("write(%d, %lux, %d, 0x%llx) = %d", fd, a, size, offset, n);
-
-	free(buf);
-
-	reg.r[REGRET] = n;
-}
-
-void
-sys_write(void)
-{
-	syswrite(-1LL);
-}
-
-void
-syspwrite(void)
-{
-	syswrite(getmem_v(reg.r[13]+16));
-}
-
-void
-syspipe(void)
-{
-	int n, p[2];
-	uint32_t fd;
-
-	fd = getmem_w(reg.r[13]+4);
-	if(sysdbg)
-		itrace("pipe(%lux)", fd);
-
-	n = pipe(p);
-	if(n < 0)
-		errstr(errbuf, sizeof errbuf);
-	else {
-		putmem_w(fd, p[0]);
-		putmem_w(fd+4, p[1]);
-	}
-	reg.r[REGRET] = n;
-}
-
-void
-syscreate(void)
-{
-	char file[1024];
-	int n;
-	uint32_t mode, name, perm;
-
-	name = getmem_w(reg.r[13]+4);
-	mode = getmem_w(reg.r[13]+8);
-	perm = getmem_w(reg.r[13]+12);
-	memio(file, name, sizeof(file), MemReadstring);
-	if(sysdbg)
-		itrace("create(0x%lux='%s', 0x%lux, 0x%lux)", name, file, mode, perm);
-	
-	n = create(file, mode, perm);
-	if(n < 0)
-		errstr(errbuf, sizeof errbuf);
-
-	reg.r[REGRET] = n;
-}
-
-void
-sysbrk_(void)
-{
-	uint32_t addr, osize, nsize;
-	Segment *s;
-
-	addr = getmem_w(reg.r[13]+4);
-	if(sysdbg)
-		itrace("brk_(0x%lux)", addr);
-
-	reg.r[REGRET] = -1;
-	if(addr < memory.seg[Data].base+datasize) {
-		strcpy(errbuf, "address below segment");
-		return;
-	}
-	if(addr > memory.seg[Stack].base) {
-		strcpy(errbuf, "segment too big");
-		return;
-	}
-	s = &memory.seg[Bss];
-	if(addr > s->end) {
-		osize = ((s->end-s->base)/BY2PG)*sizeof(uint8_t*);
-		addr = ((addr)+(BY2PG-1))&~(BY2PG-1);
-		s->end = addr;
-		nsize = ((s->end-s->base)/BY2PG)*sizeof(uint8_t*);
-		s->table = erealloc(s->table, osize, nsize);
-	}	
-
-	reg.r[REGRET] = 0;	
-}
-
-void
-sysremove(void)
-{
-	char nambuf[1024];
-	uint32_t name;
-	int n;
-
-	name = getmem_w(reg.r[13]+4);
-	memio(nambuf, name, sizeof(nambuf), MemReadstring);
-	if(sysdbg)
-		itrace("remove(0x%lux='%s')", name, nambuf);
-
-	n = remove(nambuf);
-	if(n < 0)
-		errstr(errbuf, sizeof errbuf);
-	reg.r[REGRET] = n;
-}
-
-void
-sysnotify(void)
-{
-	nofunc = getmem_w(reg.r[13]+4);
-	if(sysdbg)
-		itrace("notify(0x%lux)\n", nofunc);
-
-	reg.r[REGRET] = 0;
-}
-
-void
-sys_wait(void)
-{
-	Bprint(bioout, "No system call %s\n", sysctab[reg.r[REGARG]]);
-	exits(0);
-}
-void
-sysawait(void)
-{
-	Bprint(bioout, "No system call %s\n", sysctab[reg.r[REGARG]]);
-	exits(0);
-}
-void
-sysrfork(void)
-{
-	Bprint(bioout, "No system call %s\n", sysctab[reg.r[REGARG]]);
-	exits(0);
-}
-void
-syswstat(void)
-{
-	Bprint(bioout, "No system call %s\n", sysctab[reg.r[REGARG]]);
-	exits(0);
-}
-void
-sys_wstat(void)
-{
-	Bprint(bioout, "No system call %s\n", sysctab[reg.r[REGARG]]);
-	exits(0);
-}
-void
-sysfwstat(void)
-{
-	Bprint(bioout, "No system call %s\n", sysctab[reg.r[REGARG]]);
-	exits(0);
-}
-void
-sys_fwstat(void)
-{
-	Bprint(bioout, "No system call %s\n", sysctab[reg.r[REGARG]]);
-	exits(0);
-}
-void
-sysnoted(void)
-{
-	Bprint(bioout, "No system call %s\n", sysctab[reg.r[REGARG]]);
-	exits(0);
-}
-void
-syssegattach(void)
-{
-	Bprint(bioout, "No system call %s\n", sysctab[reg.r[REGARG]]);
-	exits(0);
-}
-void
-syssegdetach(void)
-{
-	Bprint(bioout, "No system call %s\n", sysctab[reg.r[REGARG]]);
-	exits(0);
-}
-void
-syssegfree(void)
-{
-	Bprint(bioout, "No system call %s\n", sysctab[reg.r[REGARG]]);
-	exits(0);
-}
-void
-syssegflush(void)
-{
-	Bprint(bioout, "No system call %s\n", sysctab[reg.r[REGARG]]);
-	exits(0);
-}
-void
-sysrendezvous(void)
-{
-	Bprint(bioout, "No system call %s\n", sysctab[reg.r[REGARG]]);
-	exits(0);
-}
-void
-sysunmount(void)
-{
-	Bprint(bioout, "No system call %s\n", sysctab[reg.r[REGARG]]);
-	exits(0);
-}
-void
-sysfork(void)
-{
-	Bprint(bioout, "No system call %s\n", sysctab[reg.r[REGARG]]);
-	exits(0);
-}
-void
-sysforkpgrp(void)
-{
-	Bprint(bioout, "No system call %s\n", sysctab[reg.r[REGARG]]);
-	exits(0);
-}
-void
-syssegbrk(void)
-{
-	Bprint(bioout, "No system call %s\n", sysctab[reg.r[REGARG]]);
-	exits(0);
-}
-void
-sysmount(void)
-{
-	Bprint(bioout, "No system call %s\n", sysctab[reg.r[REGARG]]);
-	exits(0);
-}
-void
-sysalarm(void)
-{
-	Bprint(bioout, "No system call %s\n", sysctab[reg.r[REGARG]]);
-	exits(0);
-}
-void
-sysexec(void)
-{
-	Bprint(bioout, "No system call %s\n", sysctab[reg.r[REGARG]]);
- 	exits(0);
-}
-void
-sys_fsession(void)
-{
-	Bprint(bioout, "No system call %s\n", sysctab[reg.r[REGARG]]);
- 	exits(0);
-}
-void
-sysfauth(void)
-{
-	Bprint(bioout, "No system call %s\n", sysctab[reg.r[REGARG]]);
- 	exits(0);
-}
-void
-sysfversion(void)
-{
-	Bprint(bioout, "No system call %s\n", sysctab[reg.r[REGARG]]);
- 	exits(0);
-}
-
-void	(*systab[])(void) =
-{
-	[SYSR1]		sys1,
-	[_ERRSTR]		sys_errstr,
-	[BIND]		sysbind,
-	[CHDIR]		syschdir,
-	[CLOSE]		sysclose,
-	[DUP]		sysdup,
-	[ALARM]		sysalarm,
-	[EXEC]		sysexec,
-	[EXITS]		sysexits,
-	[_FSESSION]	sys_fsession,
-	[FAUTH]		sysfauth,
-	[_FSTAT]		sys_fstat,
-	[SEGBRK]		syssegbrk,
-	[MOUNT]		sysmount,
-	[OPEN]		sysopen,
-	[_READ]		sys_read,
-	[OSEEK]		sysoseek,
-	[SLEEP]		syssleep,
-	[_STAT]		sys_stat,
-	[RFORK]		sysrfork,
-	[_WRITE]		sys_write,
-	[PIPE]		syspipe,
-	[CREATE]		syscreate,
-	[FD2PATH]	sysfd2path,
-	[BRK_]		sysbrk_,
-	[REMOVE]		sysremove,
-	[_WSTAT]		sys_wstat,
-	[_FWSTAT]	sys_fwstat,
-	[NOTIFY]		sysnotify,
-	[NOTED]		sysnoted,
-	[SEGATTACH]	syssegattach,
-	[SEGDETACH]	syssegdetach,
-	[SEGFREE]		syssegfree,
-	[SEGFLUSH]	syssegflush,
-	[RENDEZVOUS]	sysrendezvous,
-	[UNMOUNT]	sysunmount,
-	[_WAIT]		sys_wait,
-	[SEEK]		sysseek,
-	[FVERSION]	sysfversion,
-	[ERRSTR]		syserrstr,
-	[STAT]		sysstat,
-	[FSTAT]		sysfstat,
-	[WSTAT]		syswstat,
-	[FWSTAT]		sysfwstat,
-	[PREAD]		syspread,
-	[PWRITE]		syspwrite,
-	[AWAIT]		sysawait,
-};
-
-void
-Ssyscall(uint32_t)
-{
-	int call;
-
-	call = reg.r[REGARG];
-	if(call < 0 || call >= nelem(systab) || systab[call] == nil) {
-		Bprint(bioout, "bad system call %d (%#ux)\n", call, call);
-		dumpreg();
-		Bflush(bioout);
-		return;
-	}
-
-	if(trace)
-		itrace("SWI\t%s", sysctab[call]);
-	(*systab[call])();
-	Bflush(bioout);
-}

+ 0 - 1815
sys/src/cmd/5l/asm.c

@@ -1,1815 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include	"l.h"
-
-int32_t	OFFSET;
-
-static Prog *PP;
-
-int32_t
-entryvalue(void)
-{
-	char *a;
-	Sym *s;
-
-	a = INITENTRY;
-	if(*a >= '0' && *a <= '9')
-		return atolwhex(a);
-	s = lookup(a, 0);
-	if(s->type == 0)
-		return INITTEXT;
-	switch(s->type) {
-	case STEXT:
-	case SLEAF:
-		break;
-	case SDATA:
-		if(dlm)
-			return s->value+INITDAT;
-	default:
-		diag("entry not text: %s", s->name);
-	}
-	return s->value;
-}
-
-void
-asmb(void)
-{
-	Prog *p;
-	int32_t t, etext;
-	Optab *o;
-
-	if(debug['v'])
-		Bprint(&bso, "%5.2f asm\n", cputime());
-	Bflush(&bso);
-	OFFSET = HEADR;
-	seek(cout, OFFSET, 0);
-	pc = INITTEXT;
-	for(p = firstp; p != P; p = p->link) {
-		if(p->as == ATEXT) {
-			curtext = p;
-			autosize = p->to.offset + 4;
-		}
-		if(p->pc != pc) {
-			diag("phase error %lux sb %lux",
-				p->pc, pc);
-			if(!debug['a'])
-				prasm(curp);
-			pc = p->pc;
-		}
-		curp = p;
-		o = oplook(p);	/* could probably avoid this call */
-		asmout(p, o);
-		pc += o->size;
-	}
-
-	if(debug['a'])
-		Bprint(&bso, "\n");
-	Bflush(&bso);
-	cflush();
-
-	/* output strings in text segment */
-	etext = INITTEXT + textsize;
-	for(t = pc; t < etext; t += sizeof(buf)-100) {
-		if(etext-t > sizeof(buf)-100)
-			datblk(t, sizeof(buf)-100, 1);
-		else
-			datblk(t, etext-t, 1);
-	}
-
-	curtext = P;
-	switch(HEADTYPE) {
-	case 0:
-	case 1:
-	case 2:
-	case 5:
-	case 7:
-		OFFSET = HEADR+textsize;
-		seek(cout, OFFSET, 0);
-		break;
-	case 3:
-	case 6:	/* no header, padded segments */
-		OFFSET = rnd(HEADR+textsize, 4096);
-		seek(cout, OFFSET, 0);
-		break;
-	}
-	if(dlm){
-		char buf[8];
-
-		write(cout, buf, INITDAT-textsize);
-		textsize = INITDAT;
-	}
-	for(t = 0; t < datsize; t += sizeof(buf)-100) {
-		if(datsize-t > sizeof(buf)-100)
-			datblk(t, sizeof(buf)-100, 0);
-		else
-			datblk(t, datsize-t, 0);
-	}
-
-	symsize = 0;
-	lcsize = 0;
-	if(!debug['s']) {
-		if(debug['v'])
-			Bprint(&bso, "%5.2f sym\n", cputime());
-		Bflush(&bso);
-		switch(HEADTYPE) {
-		case 0:
-		case 1:
-		case 4:
-		case 5:
-			debug['s'] = 1;
-			break;
-		case 2:
-			OFFSET = HEADR+textsize+datsize;
-			seek(cout, OFFSET, 0);
-			break;
-		case 3:
-		case 6:	/* no header, padded segments */
-			OFFSET += rnd(datsize, 4096);
-			seek(cout, OFFSET, 0);
-			break;
-		case 7:
-			break;
-		}
-		if(!debug['s'])
-			asmsym();
-		if(debug['v'])
-			Bprint(&bso, "%5.2f pc\n", cputime());
-		Bflush(&bso);
-		if(!debug['s'])
-			asmlc();
-		if(dlm)
-			asmdyn();
-		cflush();
-	}
-	else if(dlm){
-		seek(cout, HEADR+textsize+datsize, 0);
-		asmdyn();
-		cflush();
-	}
-
-	if(debug['v'])
-		Bprint(&bso, "%5.2f header\n", cputime());
-	Bflush(&bso);
-	OFFSET = 0;
-	seek(cout, OFFSET, 0);
-	switch(HEADTYPE) {
-	case 0:	/* no header */
-	case 6:	/* no header, padded segments */
-		break;
-	case 1:	/* aif for risc os */
-		lputl(0xe1a00000);		/* NOP - decompress code */
-		lputl(0xe1a00000);		/* NOP - relocation code */
-		lputl(0xeb000000 + 12);		/* BL - zero init code */
-		lputl(0xeb000000 +
-			(entryvalue()
-			 - INITTEXT
-			 + HEADR
-			 - 12
-			 - 8) / 4);		/* BL - entry code */
-
-		lputl(0xef000011);		/* SWI - exit code */
-		lputl(textsize+HEADR);		/* text size */
-		lputl(datsize);			/* data size */
-		lputl(0);			/* sym size */
-
-		lputl(bsssize);			/* bss size */
-		lputl(0);			/* sym type */
-		lputl(INITTEXT-HEADR);		/* text addr */
-		lputl(0);			/* workspace - ignored */
-
-		lputl(32);			/* addr mode / data addr flag */
-		lputl(0);			/* data addr */
-		for(t=0; t<2; t++)
-			lputl(0);		/* reserved */
-
-		for(t=0; t<15; t++)
-			lputl(0xe1a00000);	/* NOP - zero init code */
-		lputl(0xe1a0f00e);		/* B (R14) - zero init return */
-		break;
-	case 2:	/* plan 9 */
-		if(dlm)
-			lput(0x80000000|0x647);	/* magic */
-		else
-			lput(0x647);			/* magic */
-		lput(textsize);			/* sizes */
-		lput(datsize);
-		lput(bsssize);
-		lput(symsize);			/* nsyms */
-		lput(entryvalue());		/* va of entry */
-		lput(0L);
-		lput(lcsize);
-		break;
-	case 3:	/* boot for NetBSD */
-		lput((143<<16)|0413);		/* magic */
-		lputl(rnd(HEADR+textsize, 4096));
-		lputl(rnd(datsize, 4096));
-		lputl(bsssize);
-		lputl(symsize);			/* nsyms */
-		lputl(entryvalue());		/* va of entry */
-		lputl(0L);
-		lputl(0L);
-		break;
-	case 4: /* boot for IXP1200 */
-		break;
-	case 5: /* boot for ipaq */
-		lputl(0xe3300000);		/* nop */
-		lputl(0xe3300000);		/* nop */
-		lputl(0xe3300000);		/* nop */
-		lputl(0xe3300000);		/* nop */
-		break;
-	case 7:	/* elf */
-		debug['S'] = 1;			/* symbol table */
-		elf32(ARM, ELFDATA2LSB, 0, nil);
-		break;
-	}
-	cflush();
-}
-
-void
-strnput(char *s, int n)
-{
-	for(; *s; s++){
-		cput(*s);
-		n--;
-	}
-	for(; n > 0; n--)
-		cput(0);
-}
-
-void
-cput(int c)
-{
-	cbp[0] = c;
-	cbp++;
-	cbc--;
-	if(cbc <= 0)
-		cflush();
-}
-
-void
-wput(int32_t l)
-{
-
-	cbp[0] = l>>8;
-	cbp[1] = l;
-	cbp += 2;
-	cbc -= 2;
-	if(cbc <= 0)
-		cflush();
-}
-
-void
-wputl(int32_t l)
-{
-
-	cbp[0] = l;
-	cbp[1] = l>>8;
-	cbp += 2;
-	cbc -= 2;
-	if(cbc <= 0)
-		cflush();
-}
-
-void
-lput(int32_t l)
-{
-
-	cbp[0] = l>>24;
-	cbp[1] = l>>16;
-	cbp[2] = l>>8;
-	cbp[3] = l;
-	cbp += 4;
-	cbc -= 4;
-	if(cbc <= 0)
-		cflush();
-}
-
-void
-lputl(int32_t l)
-{
-
-	cbp[3] = l>>24;
-	cbp[2] = l>>16;
-	cbp[1] = l>>8;
-	cbp[0] = l;
-	cbp += 4;
-	cbc -= 4;
-	if(cbc <= 0)
-		cflush();
-}
-
-void
-llput(int64_t v)
-{
-	lput(v>>32);
-	lput(v);
-}
-
-void
-llputl(int64_t v)
-{
-	lputl(v);
-	lputl(v>>32);
-}
-
-void
-cflush(void)
-{
-	int n;
-
-	n = sizeof(buf.cbuf) - cbc;
-	if(n)
-		write(cout, buf.cbuf, n);
-	cbp = buf.cbuf;
-	cbc = sizeof(buf.cbuf);
-}
-
-void
-nopstat(char *f, Count *c)
-{
-	if(c->outof)
-	Bprint(&bso, "%s delay %ld/%ld (%.2f)\n", f,
-		c->outof - c->count, c->outof,
-		(double)(c->outof - c->count)/c->outof);
-}
-
-void
-asmsym(void)
-{
-	Prog *p;
-	Auto *a;
-	Sym *s;
-	int h;
-
-	s = lookup("etext", 0);
-	if(s->type == STEXT)
-		putsymb(s->name, 'T', s->value, s->version);
-
-	for(h=0; h<NHASH; h++)
-		for(s=hash[h]; s!=S; s=s->link)
-			switch(s->type) {
-			case SCONST:
-				putsymb(s->name, 'D', s->value, s->version);
-				continue;
-
-			case SDATA:
-				putsymb(s->name, 'D', s->value+INITDAT, s->version);
-				continue;
-
-			case SBSS:
-				putsymb(s->name, 'B', s->value+INITDAT, s->version);
-				continue;
-
-			case SSTRING:
-				putsymb(s->name, 'T', s->value, s->version);
-				continue;
-
-			case SFILE:
-				putsymb(s->name, 'f', s->value, s->version);
-				continue;
-			}
-
-	for(p=textp; p!=P; p=p->cond) {
-		s = p->from.sym;
-		if(s->type != STEXT && s->type != SLEAF)
-			continue;
-
-		/* filenames first */
-		for(a=p->to.autom; a; a=a->link)
-			if(a->type == D_FILE)
-				putsymb(a->asym->name, 'z', a->aoffset, 0);
-			else
-			if(a->type == D_FILE1)
-				putsymb(a->asym->name, 'Z', a->aoffset, 0);
-
-		if(s->type == STEXT)
-			putsymb(s->name, 'T', s->value, s->version);
-		else
-			putsymb(s->name, 'L', s->value, s->version);
-
-		/* frame, auto and param after */
-		putsymb(".frame", 'm', p->to.offset+4, 0);
-		for(a=p->to.autom; a; a=a->link)
-			if(a->type == D_AUTO)
-				putsymb(a->asym->name, 'a', -a->aoffset, 0);
-			else
-			if(a->type == D_PARAM)
-				putsymb(a->asym->name, 'p', a->aoffset, 0);
-	}
-	if(debug['v'] || debug['n'])
-		Bprint(&bso, "symsize = %lud\n", symsize);
-	Bflush(&bso);
-}
-
-void
-putsymb(char *s, int t, int32_t v, int ver)
-{
-	int i, f;
-
-	if(t == 'f')
-		s++;
-	lput(v);
-	if(ver)
-		t += 'a' - 'A';
-	cput(t+0x80);			/* 0x80 is variable length */
-
-	if(t == 'Z' || t == 'z') {
-		cput(s[0]);
-		for(i=1; s[i] != 0 || s[i+1] != 0; i += 2) {
-			cput(s[i]);
-			cput(s[i+1]);
-		}
-		cput(0);
-		cput(0);
-		i++;
-	}
-	else {
-		for(i=0; s[i]; i++)
-			cput(s[i]);
-		cput(0);
-	}
-	symsize += 4 + 1 + i + 1;
-
-	if(debug['n']) {
-		if(t == 'z' || t == 'Z') {
-			Bprint(&bso, "%c %.8lux ", t, v);
-			for(i=1; s[i] != 0 || s[i+1] != 0; i+=2) {
-				f = ((s[i]&0xff) << 8) | (s[i+1]&0xff);
-				Bprint(&bso, "/%x", f);
-			}
-			Bprint(&bso, "\n");
-			return;
-		}
-		if(ver)
-			Bprint(&bso, "%c %.8lux %s<%d>\n", t, v, s, ver);
-		else
-			Bprint(&bso, "%c %.8lux %s\n", t, v, s);
-	}
-}
-
-#define	MINLC	4
-void
-asmlc(void)
-{
-	int32_t oldpc, oldlc;
-	Prog *p;
-	int32_t v, s;
-
-	oldpc = INITTEXT;
-	oldlc = 0;
-	for(p = firstp; p != P; p = p->link) {
-		if(p->line == oldlc || p->as == ATEXT || p->as == ANOP) {
-			if(p->as == ATEXT)
-				curtext = p;
-			if(debug['V'])
-				Bprint(&bso, "%6lux %P\n",
-					p->pc, p);
-			continue;
-		}
-		if(debug['V'])
-			Bprint(&bso, "\t\t%6ld", lcsize);
-		v = (p->pc - oldpc) / MINLC;
-		while(v) {
-			s = 127;
-			if(v < 127)
-				s = v;
-			cput(s+128);	/* 129-255 +pc */
-			if(debug['V'])
-				Bprint(&bso, " pc+%ld*%d(%ld)", s, MINLC, s+128);
-			v -= s;
-			lcsize++;
-		}
-		s = p->line - oldlc;
-		oldlc = p->line;
-		oldpc = p->pc + MINLC;
-		if(s > 64 || s < -64) {
-			cput(0);	/* 0 vv +lc */
-			cput(s>>24);
-			cput(s>>16);
-			cput(s>>8);
-			cput(s);
-			if(debug['V']) {
-				if(s > 0)
-					Bprint(&bso, " lc+%ld(%d,%ld)\n",
-						s, 0, s);
-				else
-					Bprint(&bso, " lc%ld(%d,%ld)\n",
-						s, 0, s);
-				Bprint(&bso, "%6lux %P\n",
-					p->pc, p);
-			}
-			lcsize += 5;
-			continue;
-		}
-		if(s > 0) {
-			cput(0+s);	/* 1-64 +lc */
-			if(debug['V']) {
-				Bprint(&bso, " lc+%ld(%ld)\n", s, 0+s);
-				Bprint(&bso, "%6lux %P\n",
-					p->pc, p);
-			}
-		} else {
-			cput(64-s);	/* 65-128 -lc */
-			if(debug['V']) {
-				Bprint(&bso, " lc%ld(%ld)\n", s, 64-s);
-				Bprint(&bso, "%6lux %P\n",
-					p->pc, p);
-			}
-		}
-		lcsize++;
-	}
-	while(lcsize & 1) {
-		s = 129;
-		cput(s);
-		lcsize++;
-	}
-	if(debug['v'] || debug['V'])
-		Bprint(&bso, "lcsize = %ld\n", lcsize);
-	Bflush(&bso);
-}
-
-void
-datblk(int32_t s, int32_t n, int str)
-{
-	Sym *v;
-	Prog *p;
-	char *cast;
-	int32_t a, l, fl, j, d;
-	int i, c;
-
-	memset(buf.dbuf, 0, n+100);
-	for(p = datap; p != P; p = p->link) {
-		if(str != (p->from.sym->type == SSTRING))
-			continue;
-		curp = p;
-		a = p->from.sym->value + p->from.offset;
-		l = a - s;
-		c = p->reg;
-		i = 0;
-		if(l < 0) {
-			if(l+c <= 0)
-				continue;
-			while(l < 0) {
-				l++;
-				i++;
-			}
-		}
-		if(l >= n)
-			continue;
-		if(p->as != AINIT && p->as != ADYNT) {
-			for(j=l+(c-i)-1; j>=l; j--)
-				if(buf.dbuf[j]) {
-					print("%P\n", p);
-					diag("multiple initialization");
-					break;
-				}
-		}
-		switch(p->to.type) {
-		default:
-			diag("unknown mode in initialization%P", p);
-			break;
-
-		case D_FCONST:
-			switch(c) {
-			default:
-			case 4:
-				fl = ieeedtof(p->to.ieee);
-				cast = (char*)&fl;
-				for(; i<c; i++) {
-					buf.dbuf[l] = cast[fnuxi4[i]];
-					l++;
-				}
-				break;
-			case 8:
-				cast = (char*)p->to.ieee;
-				for(; i<c; i++) {
-					buf.dbuf[l] = cast[fnuxi8[i]];
-					l++;
-				}
-				break;
-			}
-			break;
-
-		case D_SCONST:
-			for(; i<c; i++) {
-				buf.dbuf[l] = p->to.sval[i];
-				l++;
-			}
-			break;
-
-		case D_CONST:
-			d = p->to.offset;
-			v = p->to.sym;
-			if(v) {
-				switch(v->type) {
-				case SUNDEF:
-					ckoff(v, d);
-				case STEXT:
-				case SLEAF:
-				case SSTRING:
-					d += p->to.sym->value;
-					break;
-				case SDATA:
-				case SBSS:
-					d += p->to.sym->value + INITDAT;
-				}
-				if(dlm)
-					dynreloc(v, a+INITDAT, 1);
-			}
-			cast = (char*)&d;
-			switch(c) {
-			default:
-				diag("bad nuxi %d %d%P", c, i, curp);
-				break;
-			case 1:
-				for(; i<c; i++) {
-					buf.dbuf[l] = cast[inuxi1[i]];
-					l++;
-				}
-				break;
-			case 2:
-				for(; i<c; i++) {
-					buf.dbuf[l] = cast[inuxi2[i]];
-					l++;
-				}
-				break;
-			case 4:
-				for(; i<c; i++) {
-					buf.dbuf[l] = cast[inuxi4[i]];
-					l++;
-				}
-				break;
-			}
-			break;
-		}
-	}
-	write(cout, buf.dbuf, n);
-}
-
-void
-asmout(Prog *p, Optab *o)
-{
-	int32_t o1, o2, o3, o4, o5, o6, v;
-	int r, rf, rt, rt2;
-	Sym *s;
-
-PP = p;
-	o1 = 0;
-	o2 = 0;
-	o3 = 0;
-	o4 = 0;
-	o5 = 0;
-	o6 = 0;
-	switch(o->type) {
-	default:
-		diag("unknown asm %d", o->type);
-		prasm(p);
-		break;
-
-	case 0:		/* pseudo ops */
-		break;
-
-	case 1:		/* op R,[R],R */
-		o1 = oprrr(p->as, p->scond);
-		rf = p->from.reg;
-		rt = p->to.reg;
-		r = p->reg;
-		if(p->to.type == D_NONE)
-			rt = 0;
-		if(p->as == AMOVW || p->as == AMVN)
-			r = 0;
-		else if(r == NREG)
-			r = rt;
-		o1 |= rf | (r<<16) | (rt<<12);
-		break;
-
-	case 2:		/* movbu $I,[R],R */
-		aclass(&p->from);
-		o1 = oprrr(p->as, p->scond);
-		o1 |= immrot(instoffset);
-		rt = p->to.reg;
-		r = p->reg;
-		if(p->to.type == D_NONE)
-			rt = 0;
-		if(p->as == AMOVW || p->as == AMVN)
-			r = 0;
-		else if(r == NREG)
-			r = rt;
-		o1 |= (r<<16) | (rt<<12);
-		break;
-
-	case 3:		/* add R<<[IR],[R],R */
-	mov:
-		aclass(&p->from);
-		o1 = oprrr(p->as, p->scond);
-		o1 |= p->from.offset;
-		rt = p->to.reg;
-		r = p->reg;
-		if(p->to.type == D_NONE)
-			rt = 0;
-		if(p->as == AMOVW || p->as == AMVN)
-			r = 0;
-		else if(r == NREG)
-			r = rt;
-		o1 |= (r<<16) | (rt<<12);
-		break;
-
-	case 4:		/* add $I,[R],R */
-		aclass(&p->from);
-		o1 = oprrr(AADD, p->scond);
-		o1 |= immrot(instoffset);
-		r = p->from.reg;
-		if(r == NREG)
-			r = o->param;
-		o1 |= r << 16;
-		o1 |= p->to.reg << 12;
-		break;
-
-	case 5:		/* bra s */
-		v = -8;
-		if(p->cond == UP) {
-			s = p->to.sym;
-			if(s->type != SUNDEF)
-				diag("bad branch sym type");
-			v = (uint32_t)s->value >> (Roffset-2);
-			dynreloc(s, p->pc, 0);
-		}
-		else if(p->cond != P)
-			v = (p->cond->pc - pc) - 8;
-		o1 = opbra(p->as, p->scond);
-		o1 |= (v >> 2) & 0xffffff;
-		break;
-
-	case 6:		/* b ,O(R) -> add $O,R,PC */
-		aclass(&p->to);
-		o1 = oprrr(AADD, p->scond);
-		o1 |= immrot(instoffset);
-		o1 |= p->to.reg << 16;
-		o1 |= REGPC << 12;
-		break;
-
-	case 7:		/* bl ,O(R) -> mov PC,link; add $O,R,PC */
-		aclass(&p->to);
-		o1 = oprrr(AADD, p->scond);
-		o1 |= immrot(0);
-		o1 |= REGPC << 16;
-		o1 |= REGLINK << 12;
-
-		o2 = oprrr(AADD, p->scond);
-		o2 |= immrot(instoffset);
-		o2 |= p->to.reg << 16;
-		o2 |= REGPC << 12;
-		break;
-
-	case 8:		/* sll $c,[R],R -> mov (R<<$c),R */
-		aclass(&p->from);
-		o1 = oprrr(p->as, p->scond);
-		r = p->reg;
-		if(r == NREG)
-			r = p->to.reg;
-		o1 |= r;
-		o1 |= (instoffset&31) << 7;
-		o1 |= p->to.reg << 12;
-		break;
-
-	case 9:		/* sll R,[R],R -> mov (R<<R),R */
-		o1 = oprrr(p->as, p->scond);
-		r = p->reg;
-		if(r == NREG)
-			r = p->to.reg;
-		o1 |= r;
-		o1 |= (p->from.reg << 8) | (1<<4);
-		o1 |= p->to.reg << 12;
-		break;
-
-	case 10:	/* swi [$con] */
-		o1 = oprrr(p->as, p->scond);
-		if(p->to.type != D_NONE) {
-			aclass(&p->to);
-			o1 |= instoffset & 0xffffff;
-		}
-		break;
-
-	case 11:	/* word */
-		switch(aclass(&p->to)) {
-		case C_LCON:
-			if(!dlm)
-				break;
-			if(p->to.name != D_EXTERN && p->to.name != D_STATIC)
-				break;
-		case C_ADDR:
-			if(p->to.sym->type == SUNDEF)
-				ckoff(p->to.sym, p->to.offset);
-			dynreloc(p->to.sym, p->pc, 1);
-		}
-		o1 = instoffset;
-		break;
-
-	case 12:	/* movw $lcon, reg */
-		o1 = omvl(p, &p->from, p->to.reg);
-		break;
-
-	case 13:	/* op $lcon, [R], R */
-		o1 = omvl(p, &p->from, REGTMP);
-		if(!o1)
-			break;
-		o2 = oprrr(p->as, p->scond);
-		o2 |= REGTMP;
-		r = p->reg;
-		if(p->as == AMOVW || p->as == AMVN)
-			r = 0;
-		else if(r == NREG)
-			r = p->to.reg;
-		o2 |= r << 16;
-		if(p->to.type != D_NONE)
-			o2 |= p->to.reg << 12;
-		break;
-
-	case 14:	/* movb/movbu/movh/movhu R,R */
-		o1 = oprrr(ASLL, p->scond);
-
-		if(p->as == AMOVBU || p->as == AMOVHU)
-			o2 = oprrr(ASRL, p->scond);
-		else
-			o2 = oprrr(ASRA, p->scond);
-
-		r = p->to.reg;
-		o1 |= (p->from.reg)|(r<<12);
-		o2 |= (r)|(r<<12);
-		if(p->as == AMOVB || p->as == AMOVBU) {
-			o1 |= (24<<7);
-			o2 |= (24<<7);
-		} else {
-			o1 |= (16<<7);
-			o2 |= (16<<7);
-		}
-		break;
-
-	case 15:	/* mul r,[r,]r */
-		o1 = oprrr(p->as, p->scond);
-		rf = p->from.reg;
-		rt = p->to.reg;
-		r = p->reg;
-		if(r == NREG)
-			r = rt;
-		if(rt == r) {
-			r = rf;
-			rf = rt;
-		}
-		if(0)
-		if(rt == r || rf == REGPC || r == REGPC || rt == REGPC) {
-			diag("bad registers in MUL");
-			prasm(p);
-		}
-		o1 |= (rf<<8) | r | (rt<<16);
-		break;
-
-
-	case 16:	/* div r,[r,]r */
-		o1 = 0xf << 28;
-		o2 = 0;
-		break;
-
-	case 17:
-		o1 = oprrr(p->as, p->scond);
-		rf = p->from.reg;
-		rt = p->to.reg;
-		rt2 = p->to.offset;
-		r = p->reg;
-		o1 |= (rf<<8) | r | (rt<<16) | (rt2<<12);
-		break;
-
-	case 20:	/* mov/movb/movbu R,O(R) */
-		aclass(&p->to);
-		r = p->to.reg;
-		if(r == NREG)
-			r = o->param;
-		o1 = osr(p->as, p->from.reg, instoffset, r, p->scond);
-		break;
-
-	case 21:	/* mov/movbu O(R),R -> lr */
-		aclass(&p->from);
-		r = p->from.reg;
-		if(r == NREG)
-			r = o->param;
-		o1 = olr(instoffset, r, p->to.reg, p->scond);
-		if(p->as != AMOVW)
-			o1 |= 1<<22;
-		break;
-
-	case 22:	/* movb/movh/movhu O(R),R -> lr,shl,shr */
-		aclass(&p->from);
-		r = p->from.reg;
-		if(r == NREG)
-			r = o->param;
-		o1 = olr(instoffset, r, p->to.reg, p->scond);
-
-		o2 = oprrr(ASLL, p->scond);
-		o3 = oprrr(ASRA, p->scond);
-		r = p->to.reg;
-		if(p->as == AMOVB) {
-			o2 |= (24<<7)|(r)|(r<<12);
-			o3 |= (24<<7)|(r)|(r<<12);
-		} else {
-			o2 |= (16<<7)|(r)|(r<<12);
-			if(p->as == AMOVHU)
-				o3 = oprrr(ASRL, p->scond);
-			o3 |= (16<<7)|(r)|(r<<12);
-		}
-		break;
-
-	case 23:	/* movh/movhu R,O(R) -> sb,sb */
-		aclass(&p->to);
-		r = p->to.reg;
-		if(r == NREG)
-			r = o->param;
-		o1 = osr(AMOVH, p->from.reg, instoffset, r, p->scond);
-
-		o2 = oprrr(ASRL, p->scond);
-		o2 |= (8<<7)|(p->from.reg)|(REGTMP<<12);
-
-		o3 = osr(AMOVH, REGTMP, instoffset+1, r, p->scond);
-		break;
-
-	case 30:	/* mov/movb/movbu R,L(R) */
-		o1 = omvl(p, &p->to, REGTMP);
-		if(!o1)
-			break;
-		r = p->to.reg;
-		if(r == NREG)
-			r = o->param;
-		o2 = osrr(p->from.reg, REGTMP,r, p->scond);
-		if(p->as != AMOVW)
-			o2 |= 1<<22;
-		break;
-
-	case 31:	/* mov/movbu L(R),R -> lr[b] */
-	case 32:	/* movh/movb L(R),R -> lr[b] */
-		o1 = omvl(p, &p->from, REGTMP);
-		if(!o1)
-			break;
-		r = p->from.reg;
-		if(r == NREG)
-			r = o->param;
-		o2 = olrr(REGTMP,r, p->to.reg, p->scond);
-		if(p->as == AMOVBU || p->as == AMOVB)
-			o2 |= 1<<22;
-		if(o->type == 31)
-			break;
-
-		o3 = oprrr(ASLL, p->scond);
-
-		if(p->as == AMOVBU || p->as == AMOVHU)
-			o4 = oprrr(ASRL, p->scond);
-		else
-			o4 = oprrr(ASRA, p->scond);
-
-		r = p->to.reg;
-		o3 |= (r)|(r<<12);
-		o4 |= (r)|(r<<12);
-		if(p->as == AMOVB || p->as == AMOVBU) {
-			o3 |= (24<<7);
-			o4 |= (24<<7);
-		} else {
-			o3 |= (16<<7);
-			o4 |= (16<<7);
-		}
-		break;
-
-	case 33:	/* movh/movhu R,L(R) -> sb, sb */
-		o1 = omvl(p, &p->to, REGTMP);
-		if(!o1)
-			break;
-		r = p->to.reg;
-		if(r == NREG)
-			r = o->param;
-		o2 = osrr(p->from.reg, REGTMP, r, p->scond);
-		o2 |= (1<<22) ;
-
-		o3 = oprrr(ASRL, p->scond);
-		o3 |= (8<<7)|(p->from.reg)|(p->from.reg<<12);
-		o3 |= (1<<6);	/* ROR 8 */
-
-		o4 = oprrr(AADD, p->scond);
-		o4 |= (REGTMP << 12) | (REGTMP << 16);
-		o4 |= immrot(1);
-
-		o5 = osrr(p->from.reg, REGTMP,r,p->scond);
-		o5 |= (1<<22);
-
-		o6 = oprrr(ASRL, p->scond);
-		o6 |= (24<<7)|(p->from.reg)|(p->from.reg<<12);
-		o6 |= (1<<6);	/* ROL 8 */
-
-		break;
-		
-	case 34:	/* mov $lacon,R */
-		o1 = omvl(p, &p->from, REGTMP);
-		if(!o1)
-			break;
-
-		o2 = oprrr(AADD, p->scond);
-		o2 |= REGTMP;
-		r = p->from.reg;
-		if(r == NREG)
-			r = o->param;
-		o2 |= r << 16;
-		if(p->to.type != D_NONE)
-			o2 |= p->to.reg << 12;
-		break;
-
-	case 35:	/* mov PSR,R */
-		o1 = (2<<23) | (0xf<<16) | (0<<0);
-		o1 |= (p->scond & C_SCOND) << 28;
-		o1 |= (p->from.reg & 1) << 22;
-		o1 |= p->to.reg << 12;
-		break;
-
-	case 36:	/* mov R,PSR */
-		o1 = (2<<23) | (0x29f<<12) | (0<<4);
-		if(p->scond & C_FBIT)
-			o1 ^= 0x010 << 12;
-		o1 |= (p->scond & C_SCOND) << 28;
-		o1 |= (p->to.reg & 1) << 22;
-		o1 |= p->from.reg << 0;
-		break;
-
-	case 37:	/* mov $con,PSR */
-		aclass(&p->from);
-		o1 = (2<<23) | (0x29f<<12) | (0<<4);
-		if(p->scond & C_FBIT)
-			o1 ^= 0x010 << 12;
-		o1 |= (p->scond & C_SCOND) << 28;
-		o1 |= immrot(instoffset);
-		o1 |= (p->to.reg & 1) << 22;
-		o1 |= p->from.reg << 0;
-		break;
-
-	case 38:	/* movm $con,oreg -> stm */
-		o1 = (0x4 << 25);
-		o1 |= p->from.offset & 0xffff;
-		o1 |= p->to.reg << 16;
-		aclass(&p->to);
-		goto movm;
-
-	case 39:	/* movm oreg,$con -> ldm */
-		o1 = (0x4 << 25) | (1 << 20);
-		o1 |= p->to.offset & 0xffff;
-		o1 |= p->from.reg << 16;
-		aclass(&p->from);
-	movm:
-		if(instoffset != 0)
-			diag("offset must be zero in MOVM");
-		o1 |= (p->scond & C_SCOND) << 28;
-		if(p->scond & C_PBIT)
-			o1 |= 1 << 24;
-		if(p->scond & C_UBIT)
-			o1 |= 1 << 23;
-		if(p->scond & C_SBIT)
-			o1 |= 1 << 22;
-		if(p->scond & C_WBIT)
-			o1 |= 1 << 21;
-		break;
-
-	case 40:	/* swp oreg,reg,reg */
-		aclass(&p->from);
-		if(instoffset != 0)
-			diag("offset must be zero in SWP");
-		o1 = (0x2<<23) | (0x9<<4);
-		if(p->as != ASWPW)
-			o1 |= 1 << 22;
-		o1 |= p->from.reg << 16;
-		o1 |= p->reg << 0;
-		o1 |= p->to.reg << 12;
-		o1 |= (p->scond & C_SCOND) << 28;
-		break;
-
-	case 41:	/* rfe -> movm.s.w.u 0(r13),[r15] */
-		o1 = 0xe8fd8000;
-		break;
-
-	case 50:	/* floating point store */
-		v = regoff(&p->to);
-		r = p->to.reg;
-		if(r == NREG)
-			r = o->param;
-		o1 = ofsr(p->as, p->from.reg, v, r, p->scond, p);
-		break;
-
-	case 51:	/* floating point load */
-		v = regoff(&p->from);
-		r = p->from.reg;
-		if(r == NREG)
-			r = o->param;
-		o1 = ofsr(p->as, p->to.reg, v, r, p->scond, p) | (1<<20);
-		break;
-
-	case 52:	/* floating point store, long offset UGLY */
-		o1 = omvl(p, &p->to, REGTMP);
-		if(!o1)
-			break;
-		r = p->to.reg;
-		if(r == NREG)
-			r = o->param;
-		o2 = oprrr(AADD, p->scond) | (REGTMP << 12) | (REGTMP << 16) | r;
-		o3 = ofsr(p->as, p->from.reg, 0, REGTMP, p->scond, p);
-		break;
-
-	case 53:	/* floating point load, long offset UGLY */
-		o1 = omvl(p, &p->from, REGTMP);
-		if(!o1)
-			break;
-		r = p->from.reg;
-		if(r == NREG)
-			r = o->param;
-		o2 = oprrr(AADD, p->scond) | (REGTMP << 12) | (REGTMP << 16) | r;
-		o3 = ofsr(p->as, p->to.reg, 0, REGTMP, p->scond, p) | (1<<20);
-		break;
-
-	case 54:	/* floating point arith */
-		o1 = oprrr(p->as, p->scond);
-		if(p->from.type == D_FCONST) {
-			rf = chipfloat(p->from.ieee);
-			if(rf < 0){
-				diag("invalid floating-point immediate\n%P", p);
-				rf = 0;
-			}
-			rf |= (1<<3);
-		} else
-			rf = p->from.reg;
-		rt = p->to.reg;
-		r = p->reg;
-		if(p->to.type == D_NONE)
-			rt = 0;	/* CMP[FD] */
-		else if(o1 & (1<<15))
-			r = 0;	/* monadic */
-		else if(r == NREG)
-			r = rt;
-		o1 |= rf | (r<<16) | (rt<<12);
-		break;
-
-	case 55:	/* floating point fix and float */
-		o1 = oprrr(p->as, p->scond);
-		rf = p->from.reg;
-		rt = p->to.reg;
-		if(p->to.type == D_NONE){
-			rt = 0;
-			diag("to.type==D_NONE (asm/fp)");
-		}
-		if(p->from.type == D_REG)
-			o1 |= (rf<<12) | (rt<<16);
-		else
-			o1 |= rf | (rt<<12);
-		break;
-
-	/* old arm 7500 fp using coproc 1 (1<<8) */
-	case 56:	/* move to FP[CS]R */
-		o1 = ((p->scond & C_SCOND) << 28) | (0xe << 24) | (1<<8) | (1<<4);
-		o1 |= ((p->to.reg+1)<<21) | (p->from.reg << 12);
-		break;
-
-	case 57:	/* move from FP[CS]R */
-		o1 = ((p->scond & C_SCOND) << 28) | (0xe << 24) | (1<<8) | (1<<4);
-		o1 |= ((p->from.reg+1)<<21) | (p->to.reg<<12) | (1<<20);
-		break;
-	case 58:	/* movbu R,R */
-		o1 = oprrr(AAND, p->scond);
-		o1 |= immrot(0xff);
-		rt = p->to.reg;
-		r = p->from.reg;
-		if(p->to.type == D_NONE)
-			rt = 0;
-		if(r == NREG)
-			r = rt;
-		o1 |= (r<<16) | (rt<<12);
-		break;
-
-	case 59:	/* movw/bu R<<I(R),R -> ldr indexed */
-		if(p->from.reg == NREG) {
-			if(p->as != AMOVW)
-				diag("byte MOV from shifter operand");
-			goto mov;
-		}
-		if(p->from.offset&(1<<4))
-			diag("bad shift in LDR");
-		o1 = olrr(p->from.offset, p->from.reg, p->to.reg, p->scond);
-		if(p->as == AMOVBU)
-			o1 |= 1<<22;
-		break;
-
-	case 60:	/* movb R(R),R -> ldrsb indexed */
-		if(p->from.reg == NREG) {
-			diag("byte MOV from shifter operand");
-			goto mov;
-		}
-		if(p->from.offset&(~0xf))
-			diag("bad shift in LDRSB");
-		o1 = olhrr(p->from.offset, p->from.reg, p->to.reg, p->scond);
-		o1 ^= (1<<5)|(1<<6);
-		break;
-
-	case 61:	/* movw/b/bu R,R<<[IR](R) -> str indexed */
-		if(p->to.reg == NREG)
-			diag("MOV to shifter operand");
-		o1 = osrr(p->from.reg, p->to.offset, p->to.reg, p->scond);
-		if(p->as == AMOVB || p->as == AMOVBU)
-			o1 |= 1<<22;
-		break;
-
-	case 62:	/* case R -> movw	R<<2(PC),PC */
-		o1 = olrr(p->from.reg, REGPC, REGPC, p->scond);
-		o1 |= 2<<7;
-		break;
-
-	case 63:	/* bcase */
-		if(p->cond != P) {
-			o1 = p->cond->pc;
-			if(dlm)
-				dynreloc(S, p->pc, 1);
-		}
-		break;
-
-	/* reloc ops */
-	case 64:	/* mov/movb/movbu R,addr */
-		o1 = omvl(p, &p->to, REGTMP);
-		if(!o1)
-			break;
-		o2 = osr(p->as, p->from.reg, 0, REGTMP, p->scond);
-		break;
-
-	case 65:	/* mov/movbu addr,R */
-	case 66:	/* movh/movhu/movb addr,R */
-		o1 = omvl(p, &p->from, REGTMP);
-		if(!o1)
-			break;
-		o2 = olr(0, REGTMP, p->to.reg, p->scond);
-		if(p->as == AMOVBU || p->as == AMOVB)
-			o2 |= 1<<22;
-		if(o->type == 65)
-			break;
-
-		o3 = oprrr(ASLL, p->scond);
-
-		if(p->as == AMOVBU || p->as == AMOVHU)
-			o4 = oprrr(ASRL, p->scond);
-		else
-			o4 = oprrr(ASRA, p->scond);
-
-		r = p->to.reg;
-		o3 |= (r)|(r<<12);
-		o4 |= (r)|(r<<12);
-		if(p->as == AMOVB || p->as == AMOVBU) {
-			o3 |= (24<<7);
-			o4 |= (24<<7);
-		} else {
-			o3 |= (16<<7);
-			o4 |= (16<<7);
-		}
-		break;
-
-	case 67:	/* movh/movhu R,addr -> sb, sb */
-		o1 = omvl(p, &p->to, REGTMP);
-		if(!o1)
-			break;
-		o2 = osr(p->as, p->from.reg, 0, REGTMP, p->scond);
-
-		o3 = oprrr(ASRL, p->scond);
-		o3 |= (8<<7)|(p->from.reg)|(p->from.reg<<12);
-		o3 |= (1<<6);	/* ROR 8 */
-
-		o4 = oprrr(AADD, p->scond);
-		o4 |= (REGTMP << 12) | (REGTMP << 16);
-		o4 |= immrot(1);
-
-		o5 = osr(p->as, p->from.reg, 0, REGTMP, p->scond);
-
-		o6 = oprrr(ASRL, p->scond);
-		o6 |= (24<<7)|(p->from.reg)|(p->from.reg<<12);
-		o6 |= (1<<6);	/* ROL 8 */
-		break;
-
-	case 68:	/* floating point store -> ADDR */
-		o1 = omvl(p, &p->to, REGTMP);
-		if(!o1)
-			break;
-		o2 = ofsr(p->as, p->from.reg, 0, REGTMP, p->scond, p);
-		break;
-
-	case 69:	/* floating point load <- ADDR */
-		o1 = omvl(p, &p->from, REGTMP);
-		if(!o1)
-			break;
-		o2 = ofsr(p->as, p->to.reg, 0, REGTMP, p->scond, p) | (1<<20);
-		break;
-
-	/* ArmV4 ops: */
-	case 70:	/* movh/movhu R,O(R) -> strh */
-		aclass(&p->to);
-		r = p->to.reg;
-		if(r == NREG)
-			r = o->param;
-		o1 = oshr(p->from.reg, instoffset, r, p->scond);
-		break;	
-	case 71:	/* movb/movh/movhu O(R),R -> ldrsb/ldrsh/ldrh */
-		aclass(&p->from);
-		r = p->from.reg;
-		if(r == NREG)
-			r = o->param;
-		o1 = olhr(instoffset, r, p->to.reg, p->scond);
-		if(p->as == AMOVB)
-			o1 ^= (1<<5)|(1<<6);
-		else if(p->as == AMOVH)
-			o1 ^= (1<<6);
-		break;
-	case 72:	/* movh/movhu R,L(R) -> strh */
-		o1 = omvl(p, &p->to, REGTMP);
-		if(!o1)
-			break;
-		r = p->to.reg;
-		if(r == NREG)
-			r = o->param;
-		o2 = oshrr(p->from.reg, REGTMP,r, p->scond);
-		break;	
-	case 73:	/* movb/movh/movhu L(R),R -> ldrsb/ldrsh/ldrh */
-		o1 = omvl(p, &p->from, REGTMP);
-		if(!o1)
-			break;
-		r = p->from.reg;
-		if(r == NREG)
-			r = o->param;
-		o2 = olhrr(REGTMP, r, p->to.reg, p->scond);
-		if(p->as == AMOVB)
-			o2 ^= (1<<5)|(1<<6);
-		else if(p->as == AMOVH)
-			o2 ^= (1<<6);
-		break;
-
-	/* VFP ops: */
-	case 74:	/* vfp floating point arith */
-		o1 = opvfprrr(p->as, p->scond);
-		rf = p->from.reg;
-		if(p->from.type == D_FCONST) {
-			diag("invalid floating-point immediate\n%P", p);
-			rf = 0;
-		}
-		rt = p->to.reg;
-		r = p->reg;
-		if(r == NREG)
-			r = rt;
-		o1 |= rt<<12;
-		if(((o1>>20)&0xf) == 0xb)
-			o1 |= rf<<0;
-		else
-			o1 |= r<<16 | rf<<0;
-		break;
-	case 75:	/* vfp floating point compare */
-		o1 = opvfprrr(p->as, p->scond);
-		rf = p->from.reg;
-		if(p->from.type == D_FCONST) {
-			if(p->from.ieee->h != 0 || p->from.ieee->l != 0)
-				diag("invalid floating-point immediate\n%P", p);
-			o1 |= 1<<16;
-			rf = 0;
-		}
-		rt = p->reg;
-		o1 |= rt<<12 | rf<<0;
-		o2 = 0x0ef1fa10;	/* MRS APSR_nzcv, FPSCR */
-		o2 |= (p->scond & C_SCOND) << 28;
-		break;
-	case 76:	/* vfp floating point fix and float */
-		o1 = opvfprrr(p->as, p->scond);
-		rf = p->from.reg;
-		rt = p->to.reg;
-		if(p->from.type == D_REG) {
-			o2 = o1 | rt<<12 | rt<<0;
-			o1 = 0x0e000a10;	/* VMOV F,R */
-			o1 |= (p->scond & C_SCOND) << 28 | rt<<16 | rf<<12;
-		} else {
-			o1 |= FREGTMP<<12 | rf<<0;
-			o2 = 0x0e100a10;	/* VMOV R,F */
-			o2 |= (p->scond & C_SCOND) << 28 | FREGTMP<<16 | rt<<12;
-		}
-		break;
-	}
-
-	if(debug['a'] > 1)
-		Bprint(&bso, "%2d ", o->type);
-
-	v = p->pc;
-	switch(o->size) {
-	default:
-		if(debug['a'])
-			Bprint(&bso, " %.8lux:\t\t%P\n", v, p);
-		break;
-	case 4:
-		if(debug['a'])
-			Bprint(&bso, " %.8lux: %.8lux\t%P\n", v, o1, p);
-		lputl(o1);
-		break;
-	case 8:
-		if(debug['a'])
-			Bprint(&bso, " %.8lux: %.8lux %.8lux%P\n", v, o1, o2, p);
-		lputl(o1);
-		lputl(o2);
-		break;
-	case 12:
-		if(debug['a'])
-			Bprint(&bso, " %.8lux: %.8lux %.8lux %.8lux%P\n", v, o1, o2, o3, p);
-		lputl(o1);
-		lputl(o2);
-		lputl(o3);
-		break;
-	case 16:
-		if(debug['a'])
-			Bprint(&bso, " %.8lux: %.8lux %.8lux %.8lux %.8lux%P\n",
-				v, o1, o2, o3, o4, p);
-		lputl(o1);
-		lputl(o2);
-		lputl(o3);
-		lputl(o4);
-		break;
-	case 20:
-		if(debug['a'])
-			Bprint(&bso, " %.8lux: %.8lux %.8lux %.8lux %.8lux %.8lux%P\n",
-				v, o1, o2, o3, o4, o5, p);
-		lputl(o1);
-		lputl(o2);
-		lputl(o3);
-		lputl(o4);
-		lputl(o5);
-		break;
-	case 24:
-		if(debug['a'])
-			Bprint(&bso, " %.8lux: %.8lux %.8lux %.8lux %.8lux %.8lux %.8lux%P\n",
-				v, o1, o2, o3, o4, o5, o6, p);
-		lputl(o1);
-		lputl(o2);
-		lputl(o3);
-		lputl(o4);
-		lputl(o5);
-		lputl(o6);
-		break;
-	}
-}
-
-int32_t
-oprrr(int a, int sc)
-{
-	int32_t o;
-
-	o = (sc & C_SCOND) << 28;
-	if(sc & C_SBIT)
-		o |= 1 << 20;
-	if(sc & (C_PBIT|C_WBIT))
-		diag(".P/.W on dp instruction");
-	switch(a) {
-	case AMULU:
-	case AMUL:	return o | (0x0<<21) | (0x9<<4);
-	case AMULA:	return o | (0x1<<21) | (0x9<<4);
-	case AMULLU:	return o | (0x4<<21) | (0x9<<4);
-	case AMULL:	return o | (0x6<<21) | (0x9<<4);
-	case AMULALU:	return o | (0x5<<21) | (0x9<<4);
-	case AMULAL:	return o | (0x7<<21) | (0x9<<4);
-	case AAND:	return o | (0x0<<21);
-	case AEOR:	return o | (0x1<<21);
-	case ASUB:	return o | (0x2<<21);
-	case ARSB:	return o | (0x3<<21);
-	case AADD:	return o | (0x4<<21);
-	case AADC:	return o | (0x5<<21);
-	case ASBC:	return o | (0x6<<21);
-	case ARSC:	return o | (0x7<<21);
-	case ATST:	return o | (0x8<<21) | (1<<20);
-	case ATEQ:	return o | (0x9<<21) | (1<<20);
-	case ACMP:	return o | (0xa<<21) | (1<<20);
-	case ACMN:	return o | (0xb<<21) | (1<<20);
-	case AORR:	return o | (0xc<<21);
-	case AMOVW:	return o | (0xd<<21);
-	case ABIC:	return o | (0xe<<21);
-	case AMVN:	return o | (0xf<<21);
-	case ASLL:	return o | (0xd<<21) | (0<<5);
-	case ASRL:	return o | (0xd<<21) | (1<<5);
-	case ASRA:	return o | (0xd<<21) | (2<<5);
-	case ASWI:	return o | (0xf<<24);
-
-	/* old arm 7500 fp using coproc 1 (1<<8) */
-	case AADDD:	return o | (0xe<<24) | (0x0<<20) | (1<<8) | (1<<7);
-	case AADDF:	return o | (0xe<<24) | (0x0<<20) | (1<<8);
-	case AMULD:	return o | (0xe<<24) | (0x1<<20) | (1<<8) | (1<<7);
-	case AMULF:	return o | (0xe<<24) | (0x1<<20) | (1<<8);
-	case ASUBD:	return o | (0xe<<24) | (0x2<<20) | (1<<8) | (1<<7);
-	case ASUBF:	return o | (0xe<<24) | (0x2<<20) | (1<<8);
-	case ADIVD:	return o | (0xe<<24) | (0x4<<20) | (1<<8) | (1<<7);
-	case ADIVF:	return o | (0xe<<24) | (0x4<<20) | (1<<8);
-	case ACMPD:
-	case ACMPF:	return o | (0xe<<24) | (0x9<<20) | (0xF<<12) | (1<<8) | (1<<4);	/* arguably, ACMPF should expand to RNDF, CMPD */
-
-	case AMOVF:
-	case AMOVDF:	return o | (0xe<<24) | (0x0<<20) | (1<<15) | (1<<8);
-	case AMOVD:
-	case AMOVFD:	return o | (0xe<<24) | (0x0<<20) | (1<<15) | (1<<8) | (1<<7);
-
-	case AMOVWF:	return o | (0xe<<24) | (0<<20) | (1<<8) | (1<<4);
-	case AMOVWD:	return o | (0xe<<24) | (0<<20) | (1<<8) | (1<<4) | (1<<7);
-	case AMOVFW:	return o | (0xe<<24) | (1<<20) | (1<<8) | (1<<4);
-	case AMOVDW:	return o | (0xe<<24) | (1<<20) | (1<<8) | (1<<4) | (1<<7);
-	}
-	diag("bad rrr %d", a);
-	prasm(curp);
-	return 0;
-}
-
-int32_t
-opvfprrr(int a, int sc)
-{
-	int32_t o;
-
-	o = (sc & C_SCOND) << 28;
-	if(sc & (C_SBIT|C_PBIT|C_WBIT))
-		diag(".S/.P/.W on vfp instruction");
-	o |= 0xe<<24;
-	switch(a) {
-	case AMOVWD:	return o | 0xb<<8 | 0xb<<20 | 1<<6 | 0x8<<16 | 1<<7;
-	case AMOVWF:	return o | 0xa<<8 | 0xb<<20 | 1<<6 | 0x8<<16 | 1<<7;
-	case AMOVDW:	return o | 0xb<<8 | 0xb<<20 | 1<<6 | 0xD<<16 | 1<<7;
-	case AMOVFW:	return o | 0xa<<8 | 0xb<<20 | 1<<6 | 0xD<<16 | 1<<7;
-	case AMOVFD:	return o | 0xa<<8 | 0xb<<20 | 1<<6 | 0x7<<16 | 1<<7;
-	case AMOVDF:	return o | 0xb<<8 | 0xb<<20 | 1<<6 | 0x7<<16 | 1<<7;
-	case AMOVF:	return o | 0xa<<8 | 0xb<<20 | 1<<6 | 0x0<<16 | 0<<7;
-	case AMOVD:	return o | 0xb<<8 | 0xb<<20 | 1<<6 | 0x0<<16 | 0<<7;
-	case ACMPF:	return o | 0xa<<8 | 0xb<<20 | 1<<6 | 0x4<<16 | 0<<7;
-	case ACMPD:	return o | 0xb<<8 | 0xb<<20 | 1<<6 | 0x4<<16 | 0<<7;
-	case AADDF:	return o | 0xa<<8 | 0x3<<20;
-	case AADDD:	return o | 0xb<<8 | 0x3<<20;
-	case ASUBF:	return o | 0xa<<8 | 0x3<<20 | 1<<6;
-	case ASUBD:	return o | 0xb<<8 | 0x3<<20 | 1<<6;
-	case AMULF:	return o | 0xa<<8 | 0x2<<20;
-	case AMULD:	return o | 0xb<<8 | 0x2<<20;
-	case ADIVF:	return o | 0xa<<8 | 0x8<<20;
-	case ADIVD:	return o | 0xb<<8 | 0x8<<20;
-	}
-	diag("bad vfp rrr %d", a);
-	prasm(curp);
-	return 0;
-}
-
-int32_t
-opbra(int a, int sc)
-{
-
-	if(sc & (C_SBIT|C_PBIT|C_WBIT))
-		diag(".S/.P/.W on bra instruction");
-	sc &= C_SCOND;
-	if(a == ABL)
-		return (sc<<28)|(0x5<<25)|(0x1<<24);
-	if(sc != 0xe)
-		diag(".COND on bcond instruction");
-	switch(a) {
-	case ABEQ:	return (0x0<<28)|(0x5<<25);
-	case ABNE:	return (0x1<<28)|(0x5<<25);
-	case ABCS:	return (0x2<<28)|(0x5<<25);
-	case ABHS:	return (0x2<<28)|(0x5<<25);
-	case ABCC:	return (0x3<<28)|(0x5<<25);
-	case ABLO:	return (0x3<<28)|(0x5<<25);
-	case ABMI:	return (0x4<<28)|(0x5<<25);
-	case ABPL:	return (0x5<<28)|(0x5<<25);
-	case ABVS:	return (0x6<<28)|(0x5<<25);
-	case ABVC:	return (0x7<<28)|(0x5<<25);
-	case ABHI:	return (0x8<<28)|(0x5<<25);
-	case ABLS:	return (0x9<<28)|(0x5<<25);
-	case ABGE:	return (0xa<<28)|(0x5<<25);
-	case ABLT:	return (0xb<<28)|(0x5<<25);
-	case ABGT:	return (0xc<<28)|(0x5<<25);
-	case ABLE:	return (0xd<<28)|(0x5<<25);
-	case AB:	return (0xe<<28)|(0x5<<25);
-	}
-	diag("bad bra %A", a);
-	prasm(curp);
-	return 0;
-}
-
-int32_t
-olr(int32_t v, int b, int r, int sc)
-{
-	int32_t o;
-
-	if(sc & C_SBIT)
-		diag(".S on LDR/STR instruction");
-	o = (sc & C_SCOND) << 28;
-	if(!(sc & C_PBIT))
-		o |= 1 << 24;
-	if(!(sc & C_UBIT))
-		o |= 1 << 23;
-	if(sc & C_WBIT)
-		o |= 1 << 21;
-	o |= (0x1<<26) | (1<<20);
-	if(v < 0) {
-		v = -v;
-		o ^= 1 << 23;
-	}
-	if(v >= (1<<12))
-		diag("literal span too large: %ld (R%d)\n%P", v, b, PP);
-	o |= v;
-	o |= b << 16;
-	o |= r << 12;
-	return o;
-}
-
-int32_t
-olhr(int32_t v, int b, int r, int sc)
-{
-	int32_t o;
-
-	if(sc & C_SBIT)
-		diag(".S on LDRH/STRH instruction");
-	o = (sc & C_SCOND) << 28;
-	if(!(sc & C_PBIT))
-		o |= 1 << 24;
-	if(sc & C_WBIT)
-		o |= 1 << 21;
-	o |= (1<<23) | (1<<20)|(0xb<<4);
-	if(v < 0) {
-		v = -v;
-		o ^= 1 << 23;
-	}
-	if(v >= (1<<8))
-		diag("literal span too large: %ld (R%d)\n%P", v, b, PP);
-	o |= (v&0xf)|((v>>4)<<8)|(1<<22);
-	o |= b << 16;
-	o |= r << 12;
-	return o;
-}
-
-int32_t
-osr(int a, int r, int32_t v, int b, int sc)
-{
-	int32_t o;
-
-	o = olr(v, b, r, sc) ^ (1<<20);
-	if(a != AMOVW)
-		o |= 1<<22;
-	return o;
-}
-
-int32_t
-oshr(int r, int32_t v, int b, int sc)
-{
-	int32_t o;
-
-	o = olhr(v, b, r, sc) ^ (1<<20);
-	return o;
-}
-	
-
-int32_t
-osrr(int r, int i, int b, int sc)
-{
-
-	return olr(i, b, r, sc) ^ ((1<<25) | (1<<20));
-}
-
-int32_t
-oshrr(int r, int i, int b, int sc)
-{
-	return olhr(i, b, r, sc) ^ ((1<<22) | (1<<20));
-}
-
-int32_t
-olrr(int i, int b, int r, int sc)
-{
-
-	return olr(i, b, r, sc) ^ (1<<25);
-}
-
-int32_t
-olhrr(int i, int b, int r, int sc)
-{
-	return olhr(i, b, r, sc) ^ (1<<22);
-}
-
-int32_t
-ovfpmem(int a, int r, int32_t v, int b, int sc, Prog *p)
-{
-	int32_t o;
-
-	if(sc & (C_SBIT|C_PBIT|C_WBIT))
-		diag(".S/.P/.W on VLDR/VSTR instruction");
-	o = (sc & C_SCOND) << 28;
-	o |= 0xd<<24 | (1<<23);
-	if(v < 0) {
-		v = -v;
-		o ^= 1 << 23;
-	}
-	if(v & 3)
-		diag("odd offset for floating point op: %ld\n%P", v, p);
-	else if(v >= (1<<10))
-		diag("literal span too large: %ld\n%P", v, p);
-	o |= (v>>2) & 0xFF;
-	o |= b << 16;
-	o |= r << 12;
-	switch(a) {
-	default:
-		diag("bad fst %A", a);
-	case AMOVD:
-		o |= 0xb<<8;
-		break;
-	case AMOVF:
-		o |= 0xa<<8;
-		break;
-	}
-	return o;
-}
-
-int32_t
-ofsr(int a, int r, int32_t v, int b, int sc, Prog *p)
-{
-	int32_t o;
-
-	if(vfp)
-		return ovfpmem(a, r, v, b, sc, p);
-	if(sc & C_SBIT)
-		diag(".S on FLDR/FSTR instruction");
-	o = (sc & C_SCOND) << 28;
-	if(!(sc & C_PBIT))
-		o |= 1 << 24;
-	if(sc & C_WBIT)
-		o |= 1 << 21;
-	o |= (6<<25) | (1<<24) | (1<<23);
-	if(v < 0) {
-		v = -v;
-		o ^= 1 << 23;
-	}
-	if(v & 3)
-		diag("odd offset for floating point op: %ld\n%P", v, p);
-	else if(v >= (1<<10))
-		diag("literal span too large: %ld\n%P", v, p);
-	o |= (v>>2) & 0xFF;
-	o |= b << 16;
-	o |= r << 12;
-	o |= 1 << 8;
-
-	switch(a) {
-	default:
-		diag("bad fst %A", a);
-	case AMOVD:
-		o |= 1<<15;
-	case AMOVF:
-		break;
-	}
-	return o;
-}
-
-int32_t
-omvl(Prog *p, Adr *a, int dr)
-{	
-	int32_t v, o1;
-	if(!p->cond) {
-		aclass(a);
-		v = immrot(~instoffset);
-		if(v == 0) {
-			diag("missing literal");
-			prasm(p);
-			return 0;
-		}
-		o1 = oprrr(AMVN, p->scond&C_SCOND);
-		o1 |= v;
-		o1 |= dr << 12;
-	} else {
-		v = p->cond->pc - p->pc - 8;
-		o1 = olr(v, REGPC, dr, p->scond&C_SCOND);
-	}
-	return o1;
-}
-
-static Ieee chipfloats[] = {
-	{0x00000000, 0x00000000}, /* 0 */
-	{0x00000000, 0x3ff00000}, /* 1 */
-	{0x00000000, 0x40000000}, /* 2 */
-	{0x00000000, 0x40080000}, /* 3 */
-	{0x00000000, 0x40100000}, /* 4 */
-	{0x00000000, 0x40140000}, /* 5 */
-	{0x00000000, 0x3fe00000}, /* .5 */
-	{0x00000000, 0x40240000}, /* 10 */
-};
-
-int
-chipfloat(Ieee *e)
-{
-	Ieee *p;
-	int n;
-
-	if(vfp)
-		return -1;
-	for(n = sizeof(chipfloats)/sizeof(chipfloats[0]); --n >= 0;){
-		p = &chipfloats[n];
-		if(p->l == e->l && p->h == e->h)
-			return n;
-	}
-	return -1;
-}

+ 0 - 74
sys/src/cmd/5l/compat.c

@@ -1,74 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include	"l.h"
-
-/*
- * fake malloc
- */
-void*
-malloc(uint32_t n)
-{
-	void *p;
-
-	while(n & 7)
-		n++;
-	while(nhunk < n)
-		gethunk();
-	p = hunk;
-	nhunk -= n;
-	hunk += n;
-	return p;
-}
-
-void
-free(void *p)
-{
-	USED(p);
-}
-
-void*
-calloc(uint32_t m, uint32_t n)
-{
-	void *p;
-
-	n *= m;
-	p = malloc(n);
-	memset(p, 0, n);
-	return p;
-}
-
-void*
-realloc(void *p, uint32_t n)
-{
-	fprint(2, "realloc(0x%p %ld) called\n", p, n);
-	abort();
-	return 0;
-}
-
-void*
-mysbrk(uint32_t size)
-{
-	return sbrk(size);
-}
-
-void
-setmalloctag(void *v, uint32_t pc)
-{
-	USED(v, pc);
-}
-
-int
-fileexists(char *s)
-{
-	uint8_t dirbuf[400];
-
-	/* it's fine if stat result doesn't fit in dirbuf, since even then the file exists */
-	return stat(s, dirbuf, sizeof(dirbuf)) >= 0;
-}

+ 0 - 420
sys/src/cmd/5l/l.h

@@ -1,420 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include	<u.h>
-#include	<libc.h>
-#include	<bio.h>
-#include	"../5c/5.out.h"
-#include	"../8l/elf.h"
-
-#ifndef	EXTERN
-#define	EXTERN	extern
-#endif
-
-#define	LIBNAMELEN	300
-
-void	addlibpath(char*);
-int	fileexists(char*);
-char*	findlib(char*);
-
-typedef	struct	Adr	Adr;
-typedef	struct	Sym	Sym;
-typedef	struct	Autom	Auto;
-typedef	struct	Prog	Prog;
-typedef	struct	Optab	Optab;
-typedef	struct	Oprang	Oprang;
-typedef	uchar	Opcross[32][2][32];
-typedef	struct	Count	Count;
-
-#define	P		((Prog*)0)
-#define	S		((Sym*)0)
-#define	TNAME		(curtext&&curtext->from.sym?curtext->from.sym->name:noname)
-
-struct	Adr
-{
-	union
-	{
-		long	u0offset;
-		char*	u0sval;
-		Ieee*	u0ieee;
-	} u0;
-	union
-	{
-		Auto*	u1autom;
-		Sym*	u1sym;
-	} u1;
-	char	type;
-	char	reg;
-	char	name;
-	char	class;
-};
-
-#define	offset	u0.u0offset
-#define	sval	u0.u0sval
-#define	ieee	u0.u0ieee
-
-#define	autom	u1.u1autom
-#define	sym	u1.u1sym
-
-struct	Prog
-{
-	Adr	from;
-	Adr	to;
-	union
-	{
-		long	u0regused;
-		Prog*	u0forwd;
-	} u0;
-	Prog*	cond;
-	Prog*	link;
-	long	pc;
-	long	line;
-	uchar	mark;
-	uchar	optab;
-	uchar	as;
-	uchar	scond;
-	uchar	reg;
-};
-#define	regused	u0.u0regused
-#define	forwd	u0.u0forwd
-
-struct	Sym
-{
-	char	*name;
-	short	type;
-	short	version;
-	short	become;
-	short	frame;
-	uchar	subtype;
-	ushort	file;
-	long	value;
-	long	sig;
-	Sym*	link;
-};
-
-#define SIGNINTERN	(1729*325*1729)
-
-struct	Autom
-{
-	Sym*	asym;
-	Auto*	link;
-	long	aoffset;
-	short	type;
-};
-struct	Optab
-{
-	char	as;
-	char	a1;
-	char	a2;
-	char	a3;
-	char	type;
-	char	size;
-	char	param;
-	char	flag;
-};
-struct	Oprang
-{
-	Optab*	start;
-	Optab*	stop;
-};
-struct	Count
-{
-	long	count;
-	long	outof;
-};
-
-enum
-{
-	STEXT		= 1,
-	SDATA,
-	SBSS,
-	SDATA1,
-	SXREF,
-	SLEAF,
-	SFILE,
-	SCONST,
-	SSTRING,
-	SUNDEF,
-
-	SIMPORT,
-	SEXPORT,
-
-	LFROM		= 1<<0,
-	LTO		= 1<<1,
-	LPOOL		= 1<<2,
-	V4		= 1<<3,	/* arm v4 arch */
-	VFP		= 1<<4,	/* arm vfpv3 floating point */
-
-	C_NONE		= 0,
-	C_REG,
-	C_REGREG,
-	C_SHIFT,
-	C_FREG,
-	C_PSR,
-	C_FCR,
-
-	C_RCON,		/* 0xff rotated */
-	C_NCON,		/* ~RCON */
-	C_SCON,		/* 0xffff */
-	C_LCON,
-	C_FCON,
-
-	C_RACON,
-	C_LACON,
-
-	C_RECON,
-	C_LECON,
-
-	C_SBRA,
-	C_LBRA,
-
-	C_HAUTO,	/* halfword insn offset (-0xff to 0xff) */
-	C_FAUTO,	/* float insn offset (0 to 0x3fc, word aligned) */
-	C_HFAUTO,	/* both H and F */
-	C_SAUTO,	/* -0xfff to 0xfff */
-	C_LAUTO,
-
-	C_HEXT,
-	C_FEXT,
-	C_HFEXT,
-	C_SEXT,
-	C_LEXT,
-
-	C_HOREG,
-	C_FOREG,
-	C_HFOREG,
-	C_SOREG,
-	C_ROREG,
-	C_SROREG,	/* both S and R */
-	C_LOREG,
-
-	C_ADDR,		/* relocatable address */
-
-	C_GOK,
-
-/* mark flags */
-	FOLL		= 1<<0,
-	LABEL		= 1<<1,
-	LEAF		= 1<<2,
-
-	BIG		= (1<<12)-4,
-	STRINGSZ	= 200,
-	NHASH		= 10007,
-	NHUNK		= 100000,
-	MINSIZ		= 64,
-	NENT		= 100,
-	MAXIO		= 8192,
-	MAXHIST		= 20,	/* limit of path elements for history symbols */
-
-	Roffset	= 22,		/* no. bits for offset in relocation address */
-	Rindex	= 10,		/* no. bits for index in relocation address */
-};
-
-EXTERN union
-{
-	struct
-	{
-		uchar	obuf[MAXIO];			/* output buffer */
-		uchar	ibuf[MAXIO];			/* input buffer */
-	} u;
-	char	dbuf[1];
-} buf;
-
-#define	cbuf	u.obuf
-#define	xbuf	u.ibuf
-
-EXTERN	long	HEADR;			/* length of header */
-EXTERN	int	HEADTYPE;		/* type of header */
-EXTERN	long	INITDAT;		/* data location */
-EXTERN	long	INITRND;		/* data round above text location */
-EXTERN	long	INITTEXT;		/* text location */
-EXTERN	long	INITTEXTP;		/* text location (physical) */
-EXTERN	char*	INITENTRY;		/* entry point */
-EXTERN	long	autosize;
-EXTERN	Biobuf	bso;
-EXTERN	long	bsssize;
-EXTERN	int	cbc;
-EXTERN	uchar*	cbp;
-EXTERN	int	cout;
-EXTERN	Auto*	curauto;
-EXTERN	Auto*	curhist;
-EXTERN	Prog*	curp;
-EXTERN	Prog*	curtext;
-EXTERN	Prog*	datap;
-EXTERN	long	datsize;
-EXTERN	char	debug[128];
-EXTERN	Prog*	etextp;
-EXTERN	Prog*	firstp;
-EXTERN	char	fnuxi4[4];
-EXTERN	char	fnuxi8[8];
-EXTERN	char*	noname;
-EXTERN	Sym*	hash[NHASH];
-EXTERN	Sym*	histfrog[MAXHIST];
-EXTERN	int	histfrogp;
-EXTERN	int	histgen;
-EXTERN	char*	library[50];
-EXTERN	char*	libraryobj[50];
-EXTERN	int	libraryp;
-EXTERN	int	xrefresolv;
-EXTERN	char*	hunk;
-EXTERN	char	inuxi1[1];
-EXTERN	char	inuxi2[2];
-EXTERN	char	inuxi4[4];
-EXTERN	Prog*	lastp;
-EXTERN	long	lcsize;
-EXTERN	char	literal[32];
-EXTERN	int	nerrors;
-EXTERN	long	nhunk;
-EXTERN	long	instoffset;
-EXTERN	Opcross	opcross[8];
-EXTERN	Oprang	oprange[ALAST];
-EXTERN	char*	outfile;
-EXTERN	long	pc;
-EXTERN	uchar	repop[ALAST];
-EXTERN	long	symsize;
-EXTERN	Prog*	textp;
-EXTERN	long	textsize;
-EXTERN	long	thunk;
-EXTERN	int	version;
-EXTERN	char	xcmp[C_GOK+1][C_GOK+1];
-EXTERN	Prog	zprg;
-EXTERN	int	dtype;
-EXTERN	int	armv4;
-EXTERN	int vfp;
-
-EXTERN	int	doexp, dlm;
-EXTERN	int	imports, nimports;
-EXTERN	int	exports, nexports;
-EXTERN	char*	EXPTAB;
-EXTERN	Prog	undefp;
-
-#define	UP	(&undefp)
-
-extern	char*	anames[];
-extern	Optab	optab[];
-
-void	addpool(Prog*, Adr*);
-EXTERN	Prog*	blitrl;
-EXTERN	Prog*	elitrl;
-
-void	initdiv(void);
-EXTERN	Prog*	prog_div;
-EXTERN	Prog*	prog_divu;
-EXTERN	Prog*	prog_mod;
-EXTERN	Prog*	prog_modu;
-
-#pragma	varargck	type	"A"	int
-#pragma	varargck	type	"A"	uint
-#pragma	varargck	type	"C"	int
-#pragma	varargck	type	"D"	Adr*
-#pragma	varargck	type	"N"	Adr*
-#pragma	varargck	type	"P"	Prog*
-#pragma	varargck	type	"S"	char*
-
-#pragma	varargck	argpos	diag 1
-
-int	Aconv(Fmt*);
-int	Cconv(Fmt*);
-int	Dconv(Fmt*);
-int	Nconv(Fmt*);
-int	Pconv(Fmt*);
-int	Sconv(Fmt*);
-int	aclass(Adr*);
-void	addhist(long, int);
-void	addlibpath(char*);
-void	append(Prog*, Prog*);
-void	asmb(void);
-void	asmdyn(void);
-void	asmlc(void);
-void	asmout(Prog*, Optab*);
-void	asmsym(void);
-long	atolwhex(char*);
-Prog*	brloop(Prog*);
-void	buildop(void);
-void	buildrep(int, int);
-void	cflush(void);
-void	ckoff(Sym*, long);
-int	chipfloat(Ieee*);
-int	cmp(int, int);
-int	compound(Prog*);
-double	cputime(void);
-void	datblk(long, long, int);
-void	diag(char*, ...);
-void	divsig(void);
-void	dodata(void);
-void	doprof1(void);
-void	doprof2(void);
-void	dynreloc(Sym*, long, int);
-long	entryvalue(void);
-void	errorexit(void);
-void	exchange(Prog*);
-void	export(void);
-int	fileexists(char*);
-int	find1(long, int);
-char*	findlib(char*);
-void	follow(void);
-void	gethunk(void);
-void	histtoauto(void);
-double	ieeedtod(Ieee*);
-long	ieeedtof(Ieee*);
-void	import(void);
-int	isnop(Prog*);
-void	ldobj(int, long, char*);
-void	loadlib(void);
-void	listinit(void);
-Sym*	lookup(char*, int);
-void	cput(int);
-void	llput(vlong);
-void	llputl(vlong);
-void	lput(long);
-void	lputl(long);
-void	mkfwd(void);
-void*	mysbrk(ulong);
-void	names(void);
-void	nocache(Prog*);
-void	nuxiinit(void);
-void	objfile(char*);
-int	ocmp(const void*, const void*);
-long	opirr(int);
-Optab*	oplook(Prog*);
-long	oprrr(int, int);
-long	opvfprrr(int, int);
-long	olr(long, int, int, int);
-long	olhr(long, int, int, int);
-long	olrr(int, int, int, int);
-long	olhrr(int, int, int, int);
-long	osr(int, int, long, int, int);
-long	oshr(int, long, int, int);
-long	ofsr(int, int, long, int, int, Prog*);
-long	osrr(int, int, int, int);
-long	oshrr(int, int, int, int);
-long	omvl(Prog*, Adr*, int);
-void	patch(void);
-void	prasm(Prog*);
-void	prepend(Prog*, Prog*);
-Prog*	prg(void);
-int	pseudo(Prog*);
-void	putsymb(char*, int, long, int);
-void	readundefs(char*, int);
-long	regoff(Adr*);
-int	relinv(int);
-long	rnd(long, long);
-void	span(void);
-void	strnput(char*, int);
-void	undef(void);
-void	undefsym(Sym*);
-void	wput(long);
-void	wputl(long);
-void	xdefine(char*, int, long);
-void	xfol(Prog*);
-void	zerosig(char*);
-void	noops(void);
-long	immrot(ulong);
-long	immaddr(long);
-long	opbra(int, int);

+ 0 - 31
sys/src/cmd/5l/l.s

@@ -1,31 +0,0 @@
-TEXT	main(SB), $0
-
-	ADD	R1,R4
-	ADD	R1,R3,R4
-	ADD	R1<<1,R3,R4	/* logical left */
-	ADD	R1>>1,R3,R4	/* logical right */
-	ADD	R1->1,R3,R4	/* arithmetic right */
- 	ADD	R1@>1,R3,R4	/* rotate right */
-
-	ADD	R1<<R2,R3,R4
-	MOVW	R1<<R2,R4
-	ADD	$10,R1,R4
-
-loop:
-	ADD.S.NE	R1,R4
-	BNE	loop
-
-	MRC.EQ	3,9,R3,C5,C6,2
-	MRC	3,9,R3,C5,C6,2
-
-	MOVW	$(0xf<<28), CPSR
-	MOVW.F	R3, SPSR
-
-	SWI	123
-
-	SWPW	R1,(R2),R3
-	SWPBU.NE	(R2),R3
-	SWPBU	R1,(R2)
-
-	MOVM.IA.S.W	(R13),[R15]
-	RFE

+ 0 - 361
sys/src/cmd/5l/list.c

@@ -1,361 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "l.h"
-
-void
-listinit(void)
-{
-
-	fmtinstall('A', Aconv);
-	fmtinstall('C', Cconv);
-	fmtinstall('D', Dconv);
-	fmtinstall('P', Pconv);
-	fmtinstall('S', Sconv);
-	fmtinstall('N', Nconv);
-}
-
-void
-prasm(Prog *p)
-{
-	print("%P\n", p);
-}
-
-int
-Pconv(Fmt *fp)
-{
-	char str[STRINGSZ], *s;
-	Prog *p;
-	int a;
-
-	p = va_arg(fp->args, Prog*);
-	curp = p;
-	a = p->as;
-	switch(a) {
-	default:
-		s = str;
-		s += sprint(s, "(%ld)", p->line);
-		if(p->reg == NREG)
-			sprint(s, "	%A%C	%D,%D",
-				a, p->scond, &p->from, &p->to);
-		else
-		if(p->from.type != D_FREG)
-			sprint(s, "	%A%C	%D,R%d,%D",
-				a, p->scond, &p->from, p->reg, &p->to);
-		else
-			sprint(s, "	%A%C	%D,F%d,%D",
-				a, p->scond, &p->from, p->reg, &p->to);
-		break;
-
-	case ASWPW:
-	case ASWPBU:
-		sprint(str, "(%ld)	%A%C	R%d,%D,%D",
-			p->line, a, p->scond, p->reg, &p->from, &p->to);
-		break;
-
-	case ADATA:
-	case AINIT:
-	case ADYNT:
-		sprint(str, "(%ld)	%A%C	%D/%d,%D",
-			p->line, a, p->scond, &p->from, p->reg, &p->to);
-		break;
-	}
-	return fmtstrcpy(fp, str);
-}
-
-int
-Aconv(Fmt *fp)
-{
-	char *s;
-	int a;
-
-	a = va_arg(fp->args, int);
-	s = "???";
-	if(a >= AXXX && a < ALAST)
-		s = anames[a];
-	return fmtstrcpy(fp, s);
-}
-
-char*	strcond[16] =
-{
-	".EQ",
-	".NE",
-	".HS",
-	".LO",
-	".MI",
-	".PL",
-	".VS",
-	".VC",
-	".HI",
-	".LS",
-	".GE",
-	".LT",
-	".GT",
-	".LE",
-	"",
-	".NV"
-};
-
-int
-Cconv(Fmt *fp)
-{
-	char s[20];
-	int c;
-
-	c = va_arg(fp->args, int);
-	strcpy(s, strcond[c & C_SCOND]);
-	if(c & C_SBIT)
-		strcat(s, ".S");
-	if(c & C_PBIT)
-		strcat(s, ".P");
-	if(c & C_WBIT)
-		strcat(s, ".W");
-	if(c & C_UBIT)		/* ambiguous with FBIT */
-		strcat(s, ".U");
-	return fmtstrcpy(fp, s);
-}
-
-int
-Dconv(Fmt *fp)
-{
-	char str[STRINGSZ];
-	char *op;
-	Adr *a;
-	int32_t v;
-
-	a = va_arg(fp->args, Adr*);
-	switch(a->type) {
-
-	default:
-		sprint(str, "GOK-type(%d)", a->type);
-		break;
-
-	case D_NONE:
-		str[0] = 0;
-		if(a->name != D_NONE || a->reg != NREG || a->sym != S)
-			sprint(str, "%N(R%d)(NONE)", a, a->reg);
-		break;
-
-	case D_CONST:
-		if(a->reg == NREG)
-			sprint(str, "$%N", a);
-		else
-			sprint(str, "$%N(R%d)", a, a->reg);
-		break;
-
-	case D_SHIFT:
-		v = a->offset;
-		op = "<<>>->@>" + (((v>>5) & 3) << 1);
-		if(v & (1<<4))
-			sprint(str, "R%ld%c%cR%ld", v&15, op[0], op[1], (v>>8)&15);
-		else
-			sprint(str, "R%ld%c%c%ld", v&15, op[0], op[1], (v>>7)&31);
-		if(a->reg != NREG)
-			sprint(str+strlen(str), "(R%d)", a->reg);
-		break;
-
-	case D_OCONST:
-		sprint(str, "$*$%N", a);
-		if(a->reg != NREG)
-			sprint(str, "%N(R%d)(CONST)", a, a->reg);
-		break;
-
-	case D_OREG:
-		if(a->reg != NREG)
-			sprint(str, "%N(R%d)", a, a->reg);
-		else
-			sprint(str, "%N", a);
-		break;
-
-	case D_REG:
-		sprint(str, "R%d", a->reg);
-		if(a->name != D_NONE || a->sym != S)
-			sprint(str, "%N(R%d)(REG)", a, a->reg);
-		break;
-
-	case D_REGREG:
-		sprint(str, "(R%d,R%d)", a->reg, (int)a->offset);
-		if(a->name != D_NONE || a->sym != S)
-			sprint(str, "%N(R%d)(REG)", a, a->reg);
-		break;
-
-	case D_FREG:
-		sprint(str, "F%d", a->reg);
-		if(a->name != D_NONE || a->sym != S)
-			sprint(str, "%N(R%d)(REG)", a, a->reg);
-		break;
-
-	case D_PSR:
-		switch(a->reg) {
-		case 0:
-			sprint(str, "CPSR");
-			break;
-		case 1:
-			sprint(str, "SPSR");
-			break;
-		default:
-			sprint(str, "PSR%d", a->reg);
-			break;
-		}
-		if(a->name != D_NONE || a->sym != S)
-			sprint(str, "%N(PSR%d)(REG)", a, a->reg);
-		break;
-
-	case D_FPCR:
-		switch(a->reg){
-		case 0:
-			sprint(str, "FPSR");
-			break;
-		case 1:
-			sprint(str, "FPCR");
-			break;
-		default:
-			sprint(str, "FCR%d", a->reg);
-			break;
-		}
-		if(a->name != D_NONE || a->sym != S)
-			sprint(str, "%N(FCR%d)(REG)", a, a->reg);
-
-		break;
-
-	case D_BRANCH:	/* botch */
-		if(curp->cond != P) {
-			v = curp->cond->pc;
-			if(a->sym != S)
-				sprint(str, "%s+%.5lux(BRANCH)", a->sym->name, v);
-			else
-				sprint(str, "%.5lux(BRANCH)", v);
-		} else
-			if(a->sym != S)
-				sprint(str, "%s+%ld(APC)", a->sym->name, a->offset);
-			else
-				sprint(str, "%ld(APC)", a->offset);
-		break;
-
-	case D_FCONST:
-		sprint(str, "$%e", ieeedtod(a->ieee));
-		break;
-
-	case D_SCONST:
-		sprint(str, "$\"%S\"", a->sval);
-		break;
-	}
-	return fmtstrcpy(fp, str);
-}
-
-int
-Nconv(Fmt *fp)
-{
-	char str[STRINGSZ];
-	Adr *a;
-	Sym *s;
-
-	a = va_arg(fp->args, Adr*);
-	s = a->sym;
-	switch(a->name) {
-	default:
-		sprint(str, "GOK-name(%d)", a->name);
-		break;
-
-	case D_NONE:
-		sprint(str, "%ld", a->offset);
-		break;
-
-	case D_EXTERN:
-		if(s == S)
-			sprint(str, "%ld(SB)", a->offset);
-		else
-			sprint(str, "%s+%ld(SB)", s->name, a->offset);
-		break;
-
-	case D_STATIC:
-		if(s == S)
-			sprint(str, "<>+%ld(SB)", a->offset);
-		else
-			sprint(str, "%s<>+%ld(SB)", s->name, a->offset);
-		break;
-
-	case D_AUTO:
-		if(s == S)
-			sprint(str, "%ld(SP)", a->offset);
-		else
-			sprint(str, "%s-%ld(SP)", s->name, -a->offset);
-		break;
-
-	case D_PARAM:
-		if(s == S)
-			sprint(str, "%ld(FP)", a->offset);
-		else
-			sprint(str, "%s+%ld(FP)", s->name, a->offset);
-		break;
-	}
-	return fmtstrcpy(fp, str);
-}
-
-int
-Sconv(Fmt *fp)
-{
-	int i, c;
-	char str[STRINGSZ], *p, *a;
-
-	a = va_arg(fp->args, char*);
-	p = str;
-	for(i=0; i<sizeof(int32_t); i++) {
-		c = a[i] & 0xff;
-		if(c >= 'a' && c <= 'z' ||
-		   c >= 'A' && c <= 'Z' ||
-		   c >= '0' && c <= '9' ||
-		   c == ' ' || c == '%') {
-			*p++ = c;
-			continue;
-		}
-		*p++ = '\\';
-		switch(c) {
-		case 0:
-			*p++ = 'z';
-			continue;
-		case '\\':
-		case '"':
-			*p++ = c;
-			continue;
-		case '\n':
-			*p++ = 'n';
-			continue;
-		case '\t':
-			*p++ = 't';
-			continue;
-		}
-		*p++ = (c>>6) + '0';
-		*p++ = ((c>>3) & 7) + '0';
-		*p++ = (c & 7) + '0';
-	}
-	*p = 0;
-	return fmtstrcpy(fp, str);
-}
-
-void
-diag(char *fmt, ...)
-{
-	char buf[STRINGSZ], *tn;
-	va_list arg;
-
-	tn = "??none??";
-	if(curtext != P && curtext->from.sym != S)
-		tn = curtext->from.sym->name;
-	va_start(arg, fmt);
-	vseprint(buf, buf+sizeof(buf), fmt, arg);
-	va_end(arg);
-	print("%s: %s\n", tn, buf);
-
-	nerrors++;
-	if(nerrors > 10) {
-		print("too many errors\n");
-		errorexit();
-	}
-}

+ 0 - 34
sys/src/cmd/5l/mkfile

@@ -1,34 +0,0 @@
-</$objtype/mkfile
-
-TARG=5l
-OFILES=\
-	asm.$O\
-	list.$O\
-	noop.$O\
-	obj.$O\
-	optab.$O\
-	pass.$O\
-	span.$O\
-	enam.$O\
-	compat.$O\
-	elf.$O\
-
-HFILES=\
-	l.h\
-	../5c/5.out.h\
-	../8l/elf.h\
-
-BIN=/$objtype/bin
-CFLAGS=$CFLAGS -. -I.
-</sys/src/cmd/mkone
-
-../5c/enam.c: ../5c/5.out.h
-	@ { cd ../5c; mk enam.c }
-
-enam.$O:	../5c/enam.c
-	$CC $CFLAGS ../5c/enam.c
-elf.$O:	../8l/elf.c
-	$CC $CFLAGS ../8l/elf.c
-
-x:V:	$O.out
-	$O.out -la -o/dev/null x.5

+ 0 - 540
sys/src/cmd/5l/noop.c

@@ -1,540 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include	"l.h"
-
-static	Sym*	sym_div;
-static	Sym*	sym_divu;
-static	Sym*	sym_mod;
-static	Sym*	sym_modu;
-
-void
-noops(void)
-{
-	Prog *p, *q, *q1;
-	int o, curframe, curbecome, maxbecome;
-
-	/*
-	 * find leaf subroutines
-	 * become sizes
-	 * frame sizes
-	 * strip NOPs
-	 * expand RET
-	 * expand BECOME pseudo
-	 */
-
-	if(debug['v'])
-		Bprint(&bso, "%5.2f noops\n", cputime());
-	Bflush(&bso);
-
-	curframe = 0;
-	curbecome = 0;
-	maxbecome = 0;
-	curtext = 0;
-
-	q = P;
-	for(p = firstp; p != P; p = p->link) {
-
-		/* find out how much arg space is used in this TEXT */
-		if(p->to.type == D_OREG && p->to.reg == REGSP)
-			if(p->to.offset > curframe)
-				curframe = p->to.offset;
-
-		switch(p->as) {
-		case ATEXT:
-			if(curtext && curtext->from.sym) {
-				curtext->from.sym->frame = curframe;
-				curtext->from.sym->become = curbecome;
-				if(curbecome > maxbecome)
-					maxbecome = curbecome;
-			}
-			curframe = 0;
-			curbecome = 0;
-
-			p->mark |= LEAF;
-			curtext = p;
-			break;
-
-		case ARET:
-			/* special form of RET is BECOME */
-			if(p->from.type == D_CONST)
-				if(p->from.offset > curbecome)
-					curbecome = p->from.offset;
-			break;
-
-		case ADIV:
-		case ADIVU:
-		case AMOD:
-		case AMODU:
-			q = p;
-			if(prog_div == P)
-				initdiv();
-			if(curtext != P)
-				curtext->mark &= ~LEAF;
-			continue;
-
-		case ANOP:
-			q1 = p->link;
-			q->link = q1;		/* q is non-nop */
-			q1->mark |= p->mark;
-			continue;
-
-		case ABL:
-			if(curtext != P)
-				curtext->mark &= ~LEAF;
-
-		case ABCASE:
-		case AB:
-
-		case ABEQ:
-		case ABNE:
-		case ABCS:
-		case ABHS:
-		case ABCC:
-		case ABLO:
-		case ABMI:
-		case ABPL:
-		case ABVS:
-		case ABVC:
-		case ABHI:
-		case ABLS:
-		case ABGE:
-		case ABLT:
-		case ABGT:
-		case ABLE:
-
-			q1 = p->cond;
-			if(q1 != P) {
-				while(q1->as == ANOP) {
-					q1 = q1->link;
-					p->cond = q1;
-				}
-			}
-			break;
-		}
-		q = p;
-	}
-
-	if(curtext && curtext->from.sym) {
-		curtext->from.sym->frame = curframe;
-		curtext->from.sym->become = curbecome;
-		if(curbecome > maxbecome)
-			maxbecome = curbecome;
-	}
-
-	if(debug['b'])
-		print("max become = %d\n", maxbecome);
-	xdefine("ALEFbecome", STEXT, maxbecome);
-
-	curtext = 0;
-	for(p = firstp; p != P; p = p->link) {
-		switch(p->as) {
-		case ATEXT:
-			curtext = p;
-			break;
-		case ABL:
-			if(curtext != P && curtext->from.sym != S && curtext->to.offset >= 0) {
-				o = maxbecome - curtext->from.sym->frame;
-				if(o <= 0)
-					break;
-				/* calling a become or calling a variable */
-				if(p->to.sym == S || p->to.sym->become) {
-					curtext->to.offset += o;
-					if(debug['b']) {
-						curp = p;
-						print("%D calling %D increase %d\n",
-							&curtext->from, &p->to, o);
-					}
-				}
-			}
-			break;
-		}
-	}
-
-	for(p = firstp; p != P; p = p->link) {
-		o = p->as;
-		switch(o) {
-		case ATEXT:
-			curtext = p;
-			autosize = p->to.offset + 4;
-			if(autosize <= 4)
-			if(curtext->mark & LEAF) {
-				p->to.offset = -4;
-				autosize = 0;
-			}
-
-			if(!autosize && !(curtext->mark & LEAF)) {
-				if(debug['v'])
-					Bprint(&bso, "save suppressed in: %s\n",
-						curtext->from.sym->name);
-				Bflush(&bso);
-				curtext->mark |= LEAF;
-			}
-
-			if(curtext->mark & LEAF) {
-				if(curtext->from.sym)
-					curtext->from.sym->type = SLEAF;
-#ifdef optimise_time
-				if(autosize) {
-					q = prg();
-					q->as = ASUB;
-					q->line = p->line;
-					q->from.type = D_CONST;
-					q->from.offset = autosize;
-					q->to.type = D_REG;
-					q->to.reg = REGSP;
-
-					q->link = p->link;
-					p->link = q;
-				}
-				break;
-#else
-				if(!autosize)
-					break;
-#endif
-			}
-
-			q1 = prg();
-			q1->as = AMOVW;
-			q1->scond |= C_WBIT;
-			q1->line = p->line;
-			q1->from.type = D_REG;
-			q1->from.reg = REGLINK;
-			q1->to.type = D_OREG;
-			q1->to.offset = -autosize;
-			q1->to.reg = REGSP;
-
-			q1->link = p->link;
-			p->link = q1;
-			break;
-
-		case ARET:
-			nocache(p);
-			if(p->from.type == D_CONST)
-				goto become;
-			if(curtext->mark & LEAF) {
-				if(!autosize) {
-					p->as = AB;
-					p->from = zprg.from;
-					p->to.type = D_OREG;
-					p->to.offset = 0;
-					p->to.reg = REGLINK;
-					break;
-				}
-
-#ifdef optimise_time
-				p->as = AADD;
-				p->from.type = D_CONST;
-				p->from.offset = autosize;
-				p->to.type = D_REG;
-				p->to.reg = REGSP;
-
-				q = prg();
-				q->as = AB;
-				q->scond = p->scond;
-				q->line = p->line;
-				q->to.type = D_OREG;
-				q->to.offset = 0;
-				q->to.reg = REGLINK;
-
-				q->link = p->link;
-				p->link = q;
-
-				break;
-#endif
-			}
-			p->as = AMOVW;
-			p->scond |= C_PBIT;
-			p->from.type = D_OREG;
-			p->from.offset = autosize;
-			p->from.reg = REGSP;
-			p->to.type = D_REG;
-			p->to.reg = REGPC;
-			break;
-
-		become:
-			if(curtext->mark & LEAF) {
-
-				if(!autosize) {
-					p->as = AB;
-					p->from = zprg.from;
-					break;
-				}
-
-#ifdef optimise_time
-				q = prg();
-				q->scond = p->scond;
-				q->line = p->line;
-				q->as = AB;
-				q->from = zprg.from;
-				q->to = p->to;
-				q->cond = p->cond;
-				q->link = p->link;
-				p->link = q;
-
-				p->as = AADD;
-				p->from = zprg.from;
-				p->from.type = D_CONST;
-				p->from.offset = autosize;
-				p->to = zprg.to;
-				p->to.type = D_REG;
-				p->to.reg = REGSP;
-
-				break;
-#endif
-			}
-			q = prg();
-			q->scond = p->scond;
-			q->line = p->line;
-			q->as = AB;
-			q->from = zprg.from;
-			q->to = p->to;
-			q->cond = p->cond;
-			q->link = p->link;
-			p->link = q;
-
-			p->as = AMOVW;
-			p->scond |= C_PBIT;
-			p->from = zprg.from;
-			p->from.type = D_OREG;
-			p->from.offset = autosize;
-			p->from.reg = REGSP;
-			p->to = zprg.to;
-			p->to.type = D_REG;
-			p->to.reg = REGLINK;
-
-			break;
-
-		/*
-		 * 5c code generation for unsigned -> double made the
-		 * unfortunate assumption that single and double floating
-		 * point registers are aliased - true for emulated 7500
-		 * but not for vfp.  Now corrected, but this test is
-		 * insurance against old 5c compiled code in libraries.
-		 */
-		case AMOVWD:
-			if((q = p->link) != P && q->as == ACMP)
-			if((q = q->link) != P && q->as == AMOVF)
-			if((q1 = q->link) != P && q1->as == AADDF)
-			if(q1->to.type == D_FREG && q1->to.reg == p->to.reg) {
-				q1->as = AADDD;
-				q1 = prg();
-				q1->scond = q->scond;
-				q1->line = q->line;
-				q1->as = AMOVFD;
-				q1->from = q->to;
-				q1->to = q1->from;
-				q1->link = q->link;
-				q->link = q1;
-			}
-			break;
-
-		case ADIV:
-		case ADIVU:
-		case AMOD:
-		case AMODU:
-			if(debug['M'])
-				break;
-			if(p->from.type != D_REG)
-				break;
-			if(p->to.type != D_REG)
-				break;
-			q1 = p;
-
-			/* MOV a,4(SP) */
-			q = prg();
-			q->link = p->link;
-			p->link = q;
-			p = q;
-
-			p->as = AMOVW;
-			p->line = q1->line;
-			p->from.type = D_REG;
-			p->from.reg = q1->from.reg;
-			p->to.type = D_OREG;
-			p->to.reg = REGSP;
-			p->to.offset = 4;
-
-			/* MOV b,REGTMP */
-			q = prg();
-			q->link = p->link;
-			p->link = q;
-			p = q;
-
-			p->as = AMOVW;
-			p->line = q1->line;
-			p->from.type = D_REG;
-			p->from.reg = q1->reg;
-			if(q1->reg == NREG)
-				p->from.reg = q1->to.reg;
-			p->to.type = D_REG;
-			p->to.reg = REGTMP;
-			p->to.offset = 0;
-
-			/* CALL appropriate */
-			q = prg();
-			q->link = p->link;
-			p->link = q;
-			p = q;
-
-			p->as = ABL;
-			p->line = q1->line;
-			p->to.type = D_BRANCH;
-			p->cond = p;
-			switch(o) {
-			case ADIV:
-				p->cond = prog_div;
-				p->to.sym = sym_div;
-				break;
-			case ADIVU:
-				p->cond = prog_divu;
-				p->to.sym = sym_divu;
-				break;
-			case AMOD:
-				p->cond = prog_mod;
-				p->to.sym = sym_mod;
-				break;
-			case AMODU:
-				p->cond = prog_modu;
-				p->to.sym = sym_modu;
-				break;
-			}
-
-			/* MOV REGTMP, b */
-			q = prg();
-			q->link = p->link;
-			p->link = q;
-			p = q;
-
-			p->as = AMOVW;
-			p->line = q1->line;
-			p->from.type = D_REG;
-			p->from.reg = REGTMP;
-			p->from.offset = 0;
-			p->to.type = D_REG;
-			p->to.reg = q1->to.reg;
-
-			/* ADD $8,SP */
-			q = prg();
-			q->link = p->link;
-			p->link = q;
-			p = q;
-
-			p->as = AADD;
-			p->from.type = D_CONST;
-			p->from.reg = NREG;
-			p->from.offset = 8;
-			p->reg = NREG;
-			p->to.type = D_REG;
-			p->to.reg = REGSP;
-
-			/* SUB $8,SP */
-			q1->as = ASUB;
-			q1->from.type = D_CONST;
-			q1->from.offset = 8;
-			q1->from.reg = NREG;
-			q1->reg = NREG;
-			q1->to.type = D_REG;
-			q1->to.reg = REGSP;
-			break;
-		}
-	}
-}
-
-static void
-sigdiv(char *n)
-{
-	Sym *s;
-
-	s = lookup(n, 0);
-	if(s->type == STEXT){
-		if(s->sig == 0)
-			s->sig = SIGNINTERN;
-	}
-	else if(s->type == 0 || s->type == SXREF)
-		s->type = SUNDEF;
-}
-
-void
-divsig(void)
-{
-	sigdiv("_div");
-	sigdiv("_divu");
-	sigdiv("_mod");
-	sigdiv("_modu");
-}
-
-static void
-sdiv(Sym *s)
-{
-	if(s->type == 0 || s->type == SXREF){
-		/* undefsym(s); */
-		s->type = SXREF;
-		if(s->sig == 0)
-			s->sig = SIGNINTERN;
-		s->subtype = SIMPORT;
-	}
-	else if(s->type != STEXT)
-		diag("undefined: %s", s->name);
-}
-
-void
-initdiv(void)
-{
-	Sym *s2, *s3, *s4, *s5;
-	Prog *p;
-
-	if(prog_div != P)
-		return;
-	sym_div = s2 = lookup("_div", 0);
-	sym_divu = s3 = lookup("_divu", 0);
-	sym_mod = s4 = lookup("_mod", 0);
-	sym_modu = s5 = lookup("_modu", 0);
-	if(dlm) {
-		sdiv(s2); if(s2->type == SXREF) prog_div = UP;
-		sdiv(s3); if(s3->type == SXREF) prog_divu = UP;
-		sdiv(s4); if(s4->type == SXREF) prog_mod = UP;
-		sdiv(s5); if(s5->type == SXREF) prog_modu = UP;
-	}
-	for(p = firstp; p != P; p = p->link)
-		if(p->as == ATEXT) {
-			if(p->from.sym == s2)
-				prog_div = p;
-			if(p->from.sym == s3)
-				prog_divu = p;
-			if(p->from.sym == s4)
-				prog_mod = p;
-			if(p->from.sym == s5)
-				prog_modu = p;
-		}
-	if(prog_div == P) {
-		diag("undefined: %s", s2->name);
-		prog_div = curtext;
-	}
-	if(prog_divu == P) {
-		diag("undefined: %s", s3->name);
-		prog_divu = curtext;
-	}
-	if(prog_mod == P) {
-		diag("undefined: %s", s4->name);
-		prog_mod = curtext;
-	}
-	if(prog_modu == P) {
-		diag("undefined: %s", s5->name);
-		prog_modu = curtext;
-	}
-}
-
-void
-nocache(Prog *p)
-{
-	p->optab = 0;
-	p->from.class = 0;
-	p->to.class = 0;
-}

+ 0 - 1654
sys/src/cmd/5l/obj.c

@@ -1,1654 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#define	EXTERN
-#include	"l.h"
-#include	<ar.h>
-
-#ifndef	DEFAULT
-#define	DEFAULT	'9'
-#endif
-
-char	*noname		= "<none>";
-char	symname[]	= SYMDEF;
-char	thechar		= '5';
-char	*thestring 	= "arm";
-
-char**	libdir;
-int	nlibdir	= 0;
-static	int	maxlibdir = 0;
-
-/*
- *	-H0				no header
- *	-H1 -T0x10005000 -R4		is aif for risc os
- *	-H2 -T4128 -R4096		is plan9 format
- *	-H3 -T0xF0000020 -R4		is NetBSD format
- *	-H4				is IXP1200 (raw)
- *	-H5 -T0xC0008010 -R1024		is ipaq
- *	-H6 -R4096			no header with segments padded to pages
- *	-H7				is elf
- */
-
-void
-usage(void)
-{
-	diag("usage: %s [-options] objects", argv0);
-	errorexit();
-}
-
-static int
-isobjfile(char *f)
-{
-	int n, v;
-	Biobuf *b;
-	char buf1[5], buf2[SARMAG];
-
-	b = Bopen(f, OREAD);
-	if(b == nil)
-		return 0;
-	n = Bread(b, buf1, 5);
-	if(n == 5 && (buf1[2] == 1 && buf1[3] == '<' || buf1[3] == 1 && buf1[4] == '<'))
-		v = 1;	/* good enough for our purposes */
-	else{
-		Bseek(b, 0, 0);
-		n = Bread(b, buf2, SARMAG);
-		v = n == SARMAG && strncmp(buf2, ARMAG, SARMAG) == 0;
-	}
-	Bterm(b);
-	return v;
-}
-
-void
-main(int argc, char *argv[])
-{
-	int c;
-	char *a;
-	char name[LIBNAMELEN];
-
-	Binit(&bso, 1, OWRITE);
-	cout = -1;
-	listinit();
-	outfile = 0;
-	nerrors = 0;
-	curtext = P;
-	HEADTYPE = -1;
-	INITTEXT = -1;
-	INITTEXTP = -1;
-	INITDAT = -1;
-	INITRND = -1;
-	INITENTRY = 0;
-
-	ARGBEGIN {
-	default:
-		c = ARGC();
-		if(c >= 0 && c < sizeof(debug))
-			debug[c]++;
-		break;
-	case 'o':
-		outfile = ARGF();
-		break;
-	case 'E':
-		a = ARGF();
-		if(a)
-			INITENTRY = a;
-		break;
-	case 'L':
-		addlibpath(EARGF(usage()));
-		break;
-	case 'T':
-		a = ARGF();
-		if(a)
-			INITTEXT = atolwhex(a);
-		break;
-	case 'P':
-		a = ARGF();
-		if(a)
-			INITTEXTP = atolwhex(a);
-		break;
-	case 'D':
-		a = ARGF();
-		if(a)
-			INITDAT = atolwhex(a);
-		break;
-	case 'R':
-		a = ARGF();
-		if(a)
-			INITRND = atolwhex(a);
-		break;
-	case 'H':
-		a = ARGF();
-		if(a)
-			HEADTYPE = atolwhex(a);
-		/* do something about setting INITTEXT */
-		break;
-	case 'x':	/* produce export table */
-		doexp = 1;
-		if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1]))
-			readundefs(ARGF(), SEXPORT);
-		break;
-	case 'u':	/* produce dynamically loadable module */
-		dlm = 1;
-		if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1]))
-			readundefs(ARGF(), SIMPORT);
-		break;
-	} ARGEND
-
-	USED(argc);
-
-	if(*argv == 0)
-		usage();
-	if(!debug['9'] && !debug['U'] && !debug['B'])
-		debug[DEFAULT] = 1;
-	a = getenv("ccroot");
-	if(a != nil && *a != '\0') {
-		if(!fileexists(a)) {
-			diag("nonexistent $ccroot: %s", a);
-			errorexit();
-		}
-	}else
-		a = "";
-	snprint(name, sizeof(name), "%s/%s/lib", a, thestring);
-	addlibpath(name);
-	if(HEADTYPE == -1) {
-		if(debug['U'])
-			HEADTYPE = 0;
-		if(debug['B'])
-			HEADTYPE = 1;
-		if(debug['9'])
-			HEADTYPE = 2;
-	}
-	switch(HEADTYPE) {
-	default:
-		diag("unknown -H option");
-		errorexit();
-	case 0:	/* no header */
-	case 6:	/* no header, padded segments */
-		HEADR = 0L;
-		if(INITTEXT == -1)
-			INITTEXT = 0;
-		if(INITDAT == -1)
-			INITDAT = 0;
-		if(INITRND == -1)
-			INITRND = 4;
-		break;
-	case 1:	/* aif for risc os */
-		HEADR = 128L;
-		if(INITTEXT == -1)
-			INITTEXT = 0x10005000 + HEADR;
-		if(INITDAT == -1)
-			INITDAT = 0;
-		if(INITRND == -1)
-			INITRND = 4;
-		break;
-	case 2:	/* plan 9 */
-		HEADR = 32L;
-		if(INITTEXT == -1)
-			INITTEXT = 4128;
-		if(INITDAT == -1)
-			INITDAT = 0;
-		if(INITRND == -1)
-			INITRND = 4096;
-		break;
-	case 3:	/* boot for NetBSD */
-		HEADR = 32L;
-		if(INITTEXT == -1)
-			INITTEXT = 0xF0000020L;
-		if(INITDAT == -1)
-			INITDAT = 0;
-		if(INITRND == -1)
-			INITRND = 4096;
-		break;
-	case 4: /* boot for IXP1200 */
-		HEADR = 0L;
-		if(INITTEXT == -1)
-			INITTEXT = 0x0;
-		if(INITDAT == -1)
-			INITDAT = 0;
-		if(INITRND == -1)
-			INITRND = 4;
-		break;
-	case 5: /* boot for ipaq */
-		HEADR = 16L;
-		if(INITTEXT == -1)
-			INITTEXT = 0xC0008010;
-		if(INITDAT == -1)
-			INITDAT = 0;
-		if(INITRND == -1)
-			INITRND = 1024;
-		break;
-	case 7:	/* elf executable */
-		HEADR = rnd(Ehdr32sz+3*Phdr32sz, 16);
-		if(INITTEXT == -1)
-			INITTEXT = 4096+HEADR;
-		if(INITDAT == -1)
-			INITDAT = 0;
-		if(INITRND == -1)
-			INITRND = 4;
-		break;
-	}
-	if (INITTEXTP == -1)
-		INITTEXTP = INITTEXT;
-	if(INITDAT != 0 && INITRND != 0)
-		print("warning: -D0x%lux is ignored because of -R0x%lux\n",
-			INITDAT, INITRND);
-	if(debug['v'])
-		Bprint(&bso, "HEADER = -H0x%d -T0x%lux -D0x%lux -R0x%lux\n",
-			HEADTYPE, INITTEXT, INITDAT, INITRND);
-	Bflush(&bso);
-	zprg.as = AGOK;
-	zprg.scond = 14;
-	zprg.reg = NREG;
-	zprg.from.name = D_NONE;
-	zprg.from.type = D_NONE;
-	zprg.from.reg = NREG;
-	zprg.to = zprg.from;
-	buildop();
-	histgen = 0;
-	textp = P;
-	datap = P;
-	pc = 0;
-	dtype = 4;
-	if(outfile == 0)
-		outfile = "5.out";
-	cout = create(outfile, 1, 0775);
-	if(cout < 0) {
-		diag("cannot create %s: %r", outfile);
-		errorexit();
-	}
-	nuxiinit();
-
-	version = 0;
-	cbp = buf.cbuf;
-	cbc = sizeof(buf.cbuf);
-	firstp = prg();
-	lastp = firstp;
-
-	if(INITENTRY == 0) {
-		INITENTRY = "_main";
-		if(debug['p'])
-			INITENTRY = "_mainp";
-		if(!debug['l'])
-			lookup(INITENTRY, 0)->type = SXREF;
-	} else if(!(*INITENTRY >= '0' && *INITENTRY <= '9'))
-		lookup(INITENTRY, 0)->type = SXREF;
-
-	while(*argv)
-		objfile(*argv++);
-	if(!debug['l'])
-		loadlib();
-	firstp = firstp->link;
-	if(firstp == P)
-		goto out;
-	if(doexp || dlm){
-		EXPTAB = "_exporttab";
-		zerosig(EXPTAB);
-		zerosig("etext");
-		zerosig("edata");
-		zerosig("end");
-		if(dlm){
-			initdiv();
-			import();
-			HEADTYPE = 2;
-			INITTEXT = INITDAT = 0;
-			INITRND = 8;
-			INITENTRY = EXPTAB;
-		}
-		else
-			divsig();
-		export();
-	}
-	patch();
-	if(debug['p'])
-		if(debug['1'])
-			doprof1();
-		else
-			doprof2();
-	dodata();
-	follow();
-	if(firstp == P)
-		goto out;
-	noops();
-	span();
-	asmb();
-	undef();
-
-out:
-	if(debug['v']) {
-		Bprint(&bso, "%5.2f cpu time\n", cputime());
-		Bprint(&bso, "%ld memory used\n", thunk);
-		Bprint(&bso, "%d sizeof adr\n", sizeof(Adr));
-		Bprint(&bso, "%d sizeof prog\n", sizeof(Prog));
-	}
-	Bflush(&bso);
-	errorexit();
-}
-
-void
-addlibpath(char *arg)
-{
-	char **p;
-
-	if(nlibdir >= maxlibdir) {
-		if(maxlibdir == 0)
-			maxlibdir = 8;
-		else
-			maxlibdir *= 2;
-		p = malloc(maxlibdir*sizeof(*p));
-		if(p == nil) {
-			diag("out of memory");
-			errorexit();
-		}
-		memmove(p, libdir, nlibdir*sizeof(*p));
-		free(libdir);
-		libdir = p;
-	}
-	libdir[nlibdir++] = strdup(arg);
-}
-
-char*
-findlib(char *file)
-{
-	int i;
-	char name[LIBNAMELEN];
-
-	for(i = 0; i < nlibdir; i++) {
-		snprint(name, sizeof(name), "%s/%s", libdir[i], file);
-		if(fileexists(name))
-			return libdir[i];
-	}
-	return nil;
-}
-
-void
-loadlib(void)
-{
-	int i;
-	int32_t h;
-	Sym *s;
-
-loop:
-	xrefresolv = 0;
-	for(i=0; i<libraryp; i++) {
-		if(debug['v'])
-			Bprint(&bso, "%5.2f autolib: %s\n", cputime(), library[i]);
-		objfile(library[i]);
-	}
-	if(xrefresolv)
-	for(h=0; h<nelem(hash); h++)
-	for(s = hash[h]; s != S; s = s->link)
-		if(s->type == SXREF)
-			goto loop;
-}
-
-void
-errorexit(void)
-{
-
-	if(nerrors) {
-		if(cout >= 0)
-			remove(outfile);
-		exits("error");
-	}
-	exits(0);
-}
-
-void
-objfile(char *file)
-{
-	int32_t off, esym, cnt, l;
-	int f, work;
-	Sym *s;
-	char magbuf[SARMAG];
-	char name[LIBNAMELEN], pname[LIBNAMELEN];
-	struct ar_hdr arhdr;
-	char *e, *start, *stop;
-
-	if(debug['v'])
-		Bprint(&bso, "%5.2f ldobj: %s\n", cputime(), file);
-	Bflush(&bso);
-	if(file[0] == '-' && file[1] == 'l') {
-		snprint(pname, sizeof(pname), "lib%s.a", file+2);
-		e = findlib(pname);
-		if(e == nil) {
-			diag("cannot find library: %s", file);
-			errorexit();
-		}
-		snprint(name, sizeof(name), "%s/%s", e, pname);
-		file = name;
-	}
-	f = open(file, 0);
-	if(f < 0) {
-		diag("cannot open %s: %r", file);
-		errorexit();
-	}
-	l = read(f, magbuf, SARMAG);
-	if(l != SARMAG || strncmp(magbuf, ARMAG, SARMAG)){
-		/* load it as a regular file */
-		l = seek(f, 0L, 2);
-		seek(f, 0L, 0);
-		ldobj(f, l, file);
-		close(f);
-		return;
-	}
-
-	if(debug['v'])
-		Bprint(&bso, "%5.2f ldlib: %s\n", cputime(), file);
-	l = read(f, &arhdr, SAR_HDR);
-	if(l != SAR_HDR) {
-		diag("%s: short read on archive file symbol header", file);
-		goto out;
-	}
-	if(strncmp(arhdr.name, symname, strlen(symname))) {
-		diag("%s: first entry not symbol header", file);
-		goto out;
-	}
-
-	esym = SARMAG + SAR_HDR + atolwhex(arhdr.size);
-	off = SARMAG + SAR_HDR;
-
-	/*
-	 * just bang the whole symbol file into memory
-	 */
-	seek(f, off, 0);
-	cnt = esym - off;
-	start = malloc(cnt + 10);
-	cnt = read(f, start, cnt);
-	if(cnt <= 0){
-		close(f);
-		return;
-	}
-	stop = &start[cnt];
-	memset(stop, 0, 10);
-
-	work = 1;
-	while(work){
-		if(debug['v'])
-			Bprint(&bso, "%5.2f library pass: %s\n", cputime(), file);
-		Bflush(&bso);
-		work = 0;
-		for(e = start; e < stop; e = strchr(e+5, 0) + 1) {
-			s = lookup(e+5, 0);
-			if(s->type != SXREF)
-				continue;
-			sprint(pname, "%s(%s)", file, s->name);
-			if(debug['v'])
-				Bprint(&bso, "%5.2f library: %s\n", cputime(), pname);
-			Bflush(&bso);
-			l = e[1] & 0xff;
-			l |= (e[2] & 0xff) << 8;
-			l |= (e[3] & 0xff) << 16;
-			l |= (e[4] & 0xff) << 24;
-			seek(f, l, 0);
-			/* need readn to read the dumps (at least) */
-			l = readn(f, &arhdr, SAR_HDR);
-			if(l != SAR_HDR)
-				goto bad;
-			if(strncmp(arhdr.fmag, ARFMAG, sizeof(arhdr.fmag)))
-				goto bad;
-			l = atolwhex(arhdr.size);
-			ldobj(f, l, pname);
-			if(s->type == SXREF) {
-				diag("%s: failed to load: %s", file, s->name);
-				errorexit();
-			}
-			work = 1;
-			xrefresolv = 1;
-		}
-	}
-	return;
-
-bad:
-	diag("%s: bad or out of date archive", file);
-out:
-	close(f);
-}
-
-int
-zaddr(uint8_t *p, Adr *a, Sym *h[])
-{
-	int i, c;
-	int l;
-	Sym *s;
-	Auto *u;
-
-	c = p[2];
-	if(c < 0 || c > NSYM){
-		print("sym out of range: %d\n", c);
-		p[0] = ALAST+1;
-		return 0;
-	}
-	a->type = p[0];
-	a->reg = p[1];
-	a->sym = h[c];
-	a->name = p[3];
-	c = 4;
-
-	if(a->reg < 0 || a->reg > NREG) {
-		print("register out of range %d\n", a->reg);
-		p[0] = ALAST+1;
-		return 0;	/*  force real diagnostic */
-	}
-
-	switch(a->type) {
-	default:
-		print("unknown type %d\n", a->type);
-		p[0] = ALAST+1;
-		return 0;	/*  force real diagnostic */
-
-	case D_NONE:
-	case D_REG:
-	case D_FREG:
-	case D_PSR:
-	case D_FPCR:
-		break;
-
-	case D_REGREG:
-		a->offset = p[4];
-		c++;
-		break;
-
-	case D_BRANCH:
-	case D_OREG:
-	case D_CONST:
-	case D_OCONST:
-	case D_SHIFT:
-		a->offset = p[4] | (p[5]<<8) |
-			(p[6]<<16) | (p[7]<<24);
-		c += 4;
-		break;
-
-	case D_SCONST:
-		while(nhunk < NSNAME)
-			gethunk();
-		a->sval = (char*)hunk;
-		nhunk -= NSNAME;
-		hunk += NSNAME;
-
-		memmove(a->sval, p+4, NSNAME);
-		c += NSNAME;
-		break;
-
-	case D_FCONST:
-		while(nhunk < sizeof(Ieee))
-			gethunk();
-		a->ieee = (Ieee*)hunk;
-		nhunk -= NSNAME;
-		hunk += NSNAME;
-
-		a->ieee->l = p[4] | (p[5]<<8) |
-			(p[6]<<16) | (p[7]<<24);
-		a->ieee->h = p[8] | (p[9]<<8) |
-			(p[10]<<16) | (p[11]<<24);
-		c += 8;
-		break;
-	}
-	s = a->sym;
-	if(s == S)
-		return c;
-	i = a->name;
-	if(i != D_AUTO && i != D_PARAM)
-		return c;
-
-	l = a->offset;
-	for(u=curauto; u; u=u->link)
-		if(u->asym == s)
-		if(u->type == i) {
-			if(u->aoffset > l)
-				u->aoffset = l;
-			return c;
-		}
-
-	while(nhunk < sizeof(Auto))
-		gethunk();
-	u = (Auto*)hunk;
-	nhunk -= sizeof(Auto);
-	hunk += sizeof(Auto);
-
-	u->link = curauto;
-	curauto = u;
-	u->asym = s;
-	u->aoffset = l;
-	u->type = i;
-	return c;
-}
-
-void
-addlib(char *obj)
-{
-	char fn1[LIBNAMELEN], fn2[LIBNAMELEN], comp[LIBNAMELEN], *p, *name;
-	int i, search;
-
-	if(histfrogp <= 0)
-		return;
-
-	name = fn1;
-	search = 0;
-	if(histfrog[0]->name[1] == '/') {
-		sprint(name, "");
-		i = 1;
-	} else if(histfrog[0]->name[1] == '.') {
-		sprint(name, ".");
-		i = 0;
-	} else {
-		sprint(name, "");
-		i = 0;
-		search = 1;
-	}
-
-	for(; i<histfrogp; i++) {
-		snprint(comp, sizeof comp, histfrog[i]->name+1);
-		for(;;) {
-			p = strstr(comp, "$O");
-			if(p == 0)
-				break;
-			memmove(p+1, p+2, strlen(p+2)+1);
-			p[0] = thechar;
-		}
-		for(;;) {
-			p = strstr(comp, "$M");
-			if(p == 0)
-				break;
-			if(strlen(comp)+strlen(thestring)-2+1 >= sizeof comp) {
-				diag("library component too long");
-				return;
-			}
-			memmove(p+strlen(thestring), p+2, strlen(p+2)+1);
-			memmove(p, thestring, strlen(thestring));
-		}
-		if(strlen(fn1) + strlen(comp) + 3 >= sizeof(fn1)) {
-			diag("library component too long");
-			return;
-		}
-		if(i > 0 || !search)
-			strcat(fn1, "/");
-		strcat(fn1, comp);
-	}
-
-	cleanname(name);
-
-	if(search){
-		p = findlib(name);
-		if(p != nil){
-			snprint(fn2, sizeof(fn2), "%s/%s", p, name);
-			name = fn2;
-		}
-	}
-
-	for(i=0; i<libraryp; i++)
-		if(strcmp(name, library[i]) == 0)
-			return;
-	if(libraryp == nelem(library)){
-		diag("too many autolibs; skipping %s", name);
-		return;
-	}
-
-	p = malloc(strlen(name) + 1);
-	strcpy(p, name);
-	library[libraryp] = p;
-	p = malloc(strlen(obj) + 1);
-	strcpy(p, obj);
-	libraryobj[libraryp] = p;
-	libraryp++;
-}
-
-void
-addhist(int32_t line, int type)
-{
-	Auto *u;
-	Sym *s;
-	int i, j, k;
-
-	u = malloc(sizeof(Auto));
-	s = malloc(sizeof(Sym));
-	s->name = malloc(2*(histfrogp+1) + 1);
-
-	u->asym = s;
-	u->type = type;
-	u->aoffset = line;
-	u->link = curhist;
-	curhist = u;
-
-	j = 1;
-	for(i=0; i<histfrogp; i++) {
-		k = histfrog[i]->value;
-		s->name[j+0] = k>>8;
-		s->name[j+1] = k;
-		j += 2;
-	}
-}
-
-void
-histtoauto(void)
-{
-	Auto *l;
-
-	while(l = curhist) {
-		curhist = l->link;
-		l->link = curauto;
-		curauto = l;
-	}
-}
-
-void
-collapsefrog(Sym *s)
-{
-	int i;
-
-	/*
-	 * bad encoding of path components only allows
-	 * MAXHIST components. if there is an overflow,
-	 * first try to collapse xxx/..
-	 */
-	for(i=1; i<histfrogp; i++)
-		if(strcmp(histfrog[i]->name+1, "..") == 0) {
-			memmove(histfrog+i-1, histfrog+i+1,
-				(histfrogp-i-1)*sizeof(histfrog[0]));
-			histfrogp--;
-			goto out;
-		}
-
-	/*
-	 * next try to collapse .
-	 */
-	for(i=0; i<histfrogp; i++)
-		if(strcmp(histfrog[i]->name+1, ".") == 0) {
-			memmove(histfrog+i, histfrog+i+1,
-				(histfrogp-i-1)*sizeof(histfrog[0]));
-			goto out;
-		}
-
-	/*
-	 * last chance, just truncate from front
-	 */
-	memmove(histfrog+0, histfrog+1,
-		(histfrogp-1)*sizeof(histfrog[0]));
-
-out:
-	histfrog[histfrogp-1] = s;
-}
-
-void
-nopout(Prog *p)
-{
-	p->as = ANOP;
-	p->from.type = D_NONE;
-	p->to.type = D_NONE;
-}
-
-uint8_t*
-readsome(int f, uint8_t *buf, uint8_t *good, uint8_t *stop, int max)
-{
-	int n;
-
-	n = stop - good;
-	memmove(buf, good, stop - good);
-	stop = buf + n;
-	n = MAXIO - n;
-	if(n > max)
-		n = max;
-	n = read(f, stop, n);
-	if(n <= 0)
-		return 0;
-	return stop + n;
-}
-
-void
-ldobj(int f, int32_t c, char *pn)
-{
-	int32_t ipc;
-	Prog *p, *t;
-	uint8_t *bloc, *bsize, *stop;
-	Sym *h[NSYM], *s, *di;
-	int v, o, r, skip;
-	uint32_t sig;
-	static int files;
-	static char **filen;
-	char **nfilen;
-
-	if((files&15) == 0){
-		nfilen = malloc((files+16)*sizeof(char*));
-		memmove(nfilen, filen, files*sizeof(char*));
-		free(filen);
-		filen = nfilen;
-	}
-	filen[files++] = strdup(pn);
-
-	bsize = buf.xbuf;
-	bloc = buf.xbuf;
-	di = S;
-
-newloop:
-	memset(h, 0, sizeof(h));
-	version++;
-	histfrogp = 0;
-	ipc = pc;
-	skip = 0;
-
-loop:
-	if(c <= 0)
-		goto eof;
-	r = bsize - bloc;
-	if(r < 100 && r < c) {		/* enough for largest prog */
-		bsize = readsome(f, buf.xbuf, bloc, bsize, c);
-		if(bsize == 0)
-			goto eof;
-		bloc = buf.xbuf;
-		goto loop;
-	}
-	o = bloc[0];		/* as */
-	if(o <= AXXX || o >= ALAST) {
-		diag("%s: line %ld: opcode out of range %d", pn, pc-ipc, o);
-		print("	probably not a .5 file\n");
-		errorexit();
-	}
-	if(o == ANAME || o == ASIGNAME) {
-		sig = 0;
-		if(o == ASIGNAME){
-			sig = bloc[1] | (bloc[2]<<8) | (bloc[3]<<16) | (bloc[4]<<24);
-			bloc += 4;
-			c -= 4;
-		}
-		stop = memchr(&bloc[3], 0, bsize-&bloc[3]);
-		if(stop == 0){
-			bsize = readsome(f, buf.xbuf, bloc, bsize, c);
-			if(bsize == 0)
-				goto eof;
-			bloc = buf.xbuf;
-			stop = memchr(&bloc[3], 0, bsize-&bloc[3]);
-			if(stop == 0){
-				fprint(2, "%s: name too long\n", pn);
-				errorexit();
-			}
-		}
-		v = bloc[1];	/* type */
-		o = bloc[2];	/* sym */
-		bloc += 3;
-		c -= 3;
-
-		r = 0;
-		if(v == D_STATIC)
-			r = version;
-		s = lookup((char*)bloc, r);
-		c -= &stop[1] - bloc;
-		bloc = stop + 1;
-
-		if(sig != 0){
-			if(s->sig != 0 && s->sig != sig)
-				diag("incompatible type signatures %lux(%s) and %lux(%s) for %s", s->sig, filen[s->file], sig, pn, s->name);
-			s->sig = sig;
-			s->file = files-1;
-		}
-
-		if(debug['W'])
-			print("	ANAME	%s\n", s->name);
-		h[o] = s;
-		if((v == D_EXTERN || v == D_STATIC) && s->type == 0)
-			s->type = SXREF;
-		if(v == D_FILE) {
-			if(s->type != SFILE) {
-				histgen++;
-				s->type = SFILE;
-				s->value = histgen;
-			}
-			if(histfrogp < MAXHIST) {
-				histfrog[histfrogp] = s;
-				histfrogp++;
-			} else
-				collapsefrog(s);
-		}
-		goto loop;
-	}
-
-	if(nhunk < sizeof(Prog))
-		gethunk();
-	p = (Prog*)hunk;
-	nhunk -= sizeof(Prog);
-	hunk += sizeof(Prog);
-
-	p->as = o;
-	p->scond = bloc[1];
-	p->reg = bloc[2];
-	p->line = bloc[3] | (bloc[4]<<8) | (bloc[5]<<16) | (bloc[6]<<24);
-
-	r = zaddr(bloc+7, &p->from, h) + 7;
-	r += zaddr(bloc+r, &p->to, h);
-	bloc += r;
-	c -= r;
-
-	if(p->reg > NREG)
-		diag("register out of range %d", p->reg);
-
-	p->link = P;
-	p->cond = P;
-
-	if(debug['W'])
-		print("%P\n", p);
-
-	switch(o) {
-	case AHISTORY:
-		if(p->to.offset == -1) {
-			addlib(pn);
-			histfrogp = 0;
-			goto loop;
-		}
-		addhist(p->line, D_FILE);		/* 'z' */
-		if(p->to.offset)
-			addhist(p->to.offset, D_FILE1);	/* 'Z' */
-		histfrogp = 0;
-		goto loop;
-
-	case AEND:
-		histtoauto();
-		if(curtext != P)
-			curtext->to.autom = curauto;
-		curauto = 0;
-		curtext = P;
-		if(c)
-			goto newloop;
-		return;
-
-	case AGLOBL:
-		s = p->from.sym;
-		if(s == S) {
-			diag("GLOBL must have a name\n%P", p);
-			errorexit();
-		}
-		if(s->type == 0 || s->type == SXREF) {
-			s->type = SBSS;
-			s->value = 0;
-		}
-		if(s->type != SBSS) {
-			diag("redefinition: %s\n%P", s->name, p);
-			s->type = SBSS;
-			s->value = 0;
-		}
-		if(p->to.offset > s->value)
-			s->value = p->to.offset;
-		break;
-
-	case ADYNT:
-		if(p->to.sym == S) {
-			diag("DYNT without a sym\n%P", p);
-			break;
-		}
-		di = p->to.sym;
-		p->reg = 4;
-		if(di->type == SXREF) {
-			if(debug['z'])
-				Bprint(&bso, "%P set to %d\n", p, dtype);
-			di->type = SCONST;
-			di->value = dtype;
-			dtype += 4;
-		}
-		if(p->from.sym == S)
-			break;
-
-		p->from.offset = di->value;
-		p->from.sym->type = SDATA;
-		if(curtext == P) {
-			diag("DYNT not in text: %P", p);
-			break;
-		}
-		p->to.sym = curtext->from.sym;
-		p->to.type = D_CONST;
-		p->link = datap;
-		datap = p;
-		break;
-
-	case AINIT:
-		if(p->from.sym == S) {
-			diag("INIT without a sym\n%P", p);
-			break;
-		}
-		if(di == S) {
-			diag("INIT without previous DYNT\n%P", p);
-			break;
-		}
-		p->from.offset = di->value;
-		p->from.sym->type = SDATA;
-		p->link = datap;
-		datap = p;
-		break;
-	
-	case ADATA:
-		if(p->from.sym == S) {
-			diag("DATA without a sym\n%P", p);
-			break;
-		}
-		p->link = datap;
-		datap = p;
-		break;
-
-	case AGOK:
-		diag("unknown opcode\n%P", p);
-		p->pc = pc;
-		pc++;
-		break;
-
-	case ATEXT:
-		if(curtext != P) {
-			histtoauto();
-			curtext->to.autom = curauto;
-			curauto = 0;
-		}
-		skip = 0;
-		curtext = p;
-		autosize = (p->to.offset+3L) & ~3L;
-		p->to.offset = autosize;
-		autosize += 4;
-		s = p->from.sym;
-		if(s == S) {
-			diag("TEXT must have a name\n%P", p);
-			errorexit();
-		}
-		if(s->type != 0 && s->type != SXREF) {
-			if(p->reg & DUPOK) {
-				skip = 1;
-				goto casedef;
-			}
-			diag("redefinition: %s\n%P", s->name, p);
-		}
-		s->type = STEXT;
-		s->value = pc;
-		lastp->link = p;
-		lastp = p;
-		p->pc = pc;
-		pc++;
-		if(textp == P) {
-			textp = p;
-			etextp = p;
-			goto loop;
-		}
-		etextp->cond = p;
-		etextp = p;
-		break;
-
-	case ASUB:
-		if(p->from.type == D_CONST)
-		if(p->from.name == D_NONE)
-		if(p->from.offset < 0) {
-			p->from.offset = -p->from.offset;
-			p->as = AADD;
-		}
-		goto casedef;
-
-	case AADD:
-		if(p->from.type == D_CONST)
-		if(p->from.name == D_NONE)
-		if(p->from.offset < 0) {
-			p->from.offset = -p->from.offset;
-			p->as = ASUB;
-		}
-		goto casedef;
-
-	case AMOVDF:
-		if(!vfp || p->from.type != D_FCONST)
-			goto casedef;
-		p->as = AMOVF;
-		/* fall through */
-	case AMOVF:
-		if(skip)
-			goto casedef;
-
-		if(p->from.type == D_FCONST && chipfloat(p->from.ieee) < 0) {
-			/* size sb 9 max */
-			sprint(literal, "$%lux", ieeedtof(p->from.ieee));
-			s = lookup(literal, 0);
-			if(s->type == 0) {
-				s->type = SBSS;
-				s->value = 4;
-				t = prg();
-				t->as = ADATA;
-				t->line = p->line;
-				t->from.type = D_OREG;
-				t->from.sym = s;
-				t->from.name = D_EXTERN;
-				t->reg = 4;
-				t->to = p->from;
-				t->link = datap;
-				datap = t;
-			}
-			p->from.type = D_OREG;
-			p->from.sym = s;
-			p->from.name = D_EXTERN;
-			p->from.offset = 0;
-		}
-		goto casedef;
-
-	case AMOVD:
-		if(skip)
-			goto casedef;
-
-		if(p->from.type == D_FCONST && chipfloat(p->from.ieee) < 0) {
-			/* size sb 18 max */
-			sprint(literal, "$%lux.%lux",
-				p->from.ieee->l, p->from.ieee->h);
-			s = lookup(literal, 0);
-			if(s->type == 0) {
-				s->type = SBSS;
-				s->value = 8;
-				t = prg();
-				t->as = ADATA;
-				t->line = p->line;
-				t->from.type = D_OREG;
-				t->from.sym = s;
-				t->from.name = D_EXTERN;
-				t->reg = 8;
-				t->to = p->from;
-				t->link = datap;
-				datap = t;
-			}
-			p->from.type = D_OREG;
-			p->from.sym = s;
-			p->from.name = D_EXTERN;
-			p->from.offset = 0;
-		}
-		goto casedef;
-
-	default:
-	casedef:
-		if(skip)
-			nopout(p);
-
-		if(p->to.type == D_BRANCH)
-			p->to.offset += ipc;
-		lastp->link = p;
-		lastp = p;
-		p->pc = pc;
-		pc++;
-		break;
-	}
-	goto loop;
-
-eof:
-	diag("truncated object file: %s", pn);
-}
-
-Sym*
-lookup(char *symb, int v)
-{
-	Sym *s;
-	char *p;
-	int32_t h;
-	int c, l;
-
-	h = v;
-	for(p=symb; c = *p; p++)
-		h = h+h+h + c;
-	l = (p - symb) + 1;
-	h &= 0xffffff;
-	h %= NHASH;
-	for(s = hash[h]; s != S; s = s->link)
-		if(s->version == v)
-		if(memcmp(s->name, symb, l) == 0)
-			return s;
-
-	while(nhunk < sizeof(Sym))
-		gethunk();
-	s = (Sym*)hunk;
-	nhunk -= sizeof(Sym);
-	hunk += sizeof(Sym);
-
-	s->name = malloc(l);
-	memmove(s->name, symb, l);
-
-	s->link = hash[h];
-	s->type = 0;
-	s->version = v;
-	s->value = 0;
-	s->sig = 0;
-	hash[h] = s;
-	return s;
-}
-
-Prog*
-prg(void)
-{
-	Prog *p;
-
-	while(nhunk < sizeof(Prog))
-		gethunk();
-	p = (Prog*)hunk;
-	nhunk -= sizeof(Prog);
-	hunk += sizeof(Prog);
-
-	*p = zprg;
-	return p;
-}
-
-void
-gethunk(void)
-{
-	char *h;
-	int32_t nh;
-
-	nh = NHUNK;
-	if(thunk >= 5L*NHUNK) {
-		nh = 5L*NHUNK;
-		if(thunk >= 25L*NHUNK)
-			nh = 25L*NHUNK;
-	}
-	h = mysbrk(nh);
-	if(h == (char*)-1) {
-		diag("out of memory");
-		errorexit();
-	}
-	hunk = h;
-	nhunk = nh;
-	thunk += nh;
-}
-
-void
-doprof1(void)
-{
-	Sym *s;
-	int32_t n;
-	Prog *p, *q;
-
-	if(debug['v'])
-		Bprint(&bso, "%5.2f profile 1\n", cputime());
-	Bflush(&bso);
-	s = lookup("__mcount", 0);
-	n = 1;
-	for(p = firstp->link; p != P; p = p->link) {
-		if(p->as == ATEXT) {
-			q = prg();
-			q->line = p->line;
-			q->link = datap;
-			datap = q;
-			q->as = ADATA;
-			q->from.type = D_OREG;
-			q->from.name = D_EXTERN;
-			q->from.offset = n*4;
-			q->from.sym = s;
-			q->reg = 4;
-			q->to = p->from;
-			q->to.type = D_CONST;
-
-			q = prg();
-			q->line = p->line;
-			q->pc = p->pc;
-			q->link = p->link;
-			p->link = q;
-			p = q;
-			p->as = AMOVW;
-			p->from.type = D_OREG;
-			p->from.name = D_EXTERN;
-			p->from.sym = s;
-			p->from.offset = n*4 + 4;
-			p->to.type = D_REG;
-			p->to.reg = REGTMP;
-
-			q = prg();
-			q->line = p->line;
-			q->pc = p->pc;
-			q->link = p->link;
-			p->link = q;
-			p = q;
-			p->as = AADD;
-			p->from.type = D_CONST;
-			p->from.offset = 1;
-			p->to.type = D_REG;
-			p->to.reg = REGTMP;
-
-			q = prg();
-			q->line = p->line;
-			q->pc = p->pc;
-			q->link = p->link;
-			p->link = q;
-			p = q;
-			p->as = AMOVW;
-			p->from.type = D_REG;
-			p->from.reg = REGTMP;
-			p->to.type = D_OREG;
-			p->to.name = D_EXTERN;
-			p->to.sym = s;
-			p->to.offset = n*4 + 4;
-
-			n += 2;
-			continue;
-		}
-	}
-	q = prg();
-	q->line = 0;
-	q->link = datap;
-	datap = q;
-
-	q->as = ADATA;
-	q->from.type = D_OREG;
-	q->from.name = D_EXTERN;
-	q->from.sym = s;
-	q->reg = 4;
-	q->to.type = D_CONST;
-	q->to.offset = n;
-
-	s->type = SBSS;
-	s->value = n*4;
-}
-
-static int brcond[] = {ABEQ, ABNE, ABCS, ABCC, ABMI, ABPL, ABVS, ABVC, ABHI, ABLS, ABGE, ABLT, ABGT, ABLE};
-
-void
-doprof2(void)
-{
-	Sym *s2, *s4;
-	Prog *p, *q, *q2, *ps2, *ps4;
-
-	if(debug['v'])
-		Bprint(&bso, "%5.2f profile 2\n", cputime());
-	Bflush(&bso);
-
-	if(debug['e']){
-		s2 = lookup("_tracein", 0);
-		s4 = lookup("_traceout", 0);
-	}else{
-		s2 = lookup("_profin", 0);
-		s4 = lookup("_profout", 0);
-	}
-	if(s2->type != STEXT || s4->type != STEXT) {
-		if(debug['e'])
-			diag("_tracein/_traceout not defined %d %d", s2->type, s4->type);
-		else
-			diag("_profin/_profout not defined");
-		return;
-	}
-
-	ps2 = P;
-	ps4 = P;
-	for(p = firstp; p != P; p = p->link) {
-		if(p->as == ATEXT) {
-			if(p->from.sym == s2) {
-				ps2 = p;
-				p->reg = 1;
-			}
-			if(p->from.sym == s4) {
-				ps4 = p;
-				p->reg = 1;
-			}
-		}
-	}
-	for(p = firstp; p != P; p = p->link) {
-		if(p->as == ATEXT) {
-			if(p->reg & NOPROF) {
-				for(;;) {
-					q = p->link;
-					if(q == P)
-						break;
-					if(q->as == ATEXT)
-						break;
-					p = q;
-				}
-				continue;
-			}
-
-			/*
-			 * BL	profin
-			 */
-			q = prg();
-			q->line = p->line;
-			q->pc = p->pc;
-			q->link = p->link;
-			if(debug['e']){		/* embedded tracing */
-				q2 = prg();
-				p->link = q2;
-				q2->link = q;
-
-				q2->line = p->line;
-				q2->pc = p->pc;
-
-				q2->as = AB;
-				q2->to.type = D_BRANCH;
-				q2->to.sym = p->to.sym;
-				q2->cond = q->link;
-			}else
-				p->link = q;
-			p = q;
-			p->as = ABL;
-			p->to.type = D_BRANCH;
-			p->cond = ps2;
-			p->to.sym = s2;
-
-			continue;
-		}
-		if(p->as == ARET) {
-			/*
-			 * RET (default)
-			 */
-			if(debug['e']){		/* embedded tracing */
-				q = prg();
-				q->line = p->line;
-				q->pc = p->pc;
-				q->link = p->link;
-				p->link = q;
-				p = q;
-			}
-
-			/*
-			 * RET
-			 */
-			q = prg();
-			q->as = ARET;
-			q->from = p->from;
-			q->to = p->to;
-			q->cond = p->cond;
-			q->link = p->link;
-			q->reg = p->reg;
-			p->link = q;
-
-			if(p->scond != 14) {
-				q = prg();
-				q->as = ABL;
-				q->from = zprg.from;
-				q->to = zprg.to;
-				q->to.type = D_BRANCH;
-				q->cond = ps4;
-				q->to.sym = s4;
-				q->link = p->link;
-				p->link = q;
-
-				p->as = brcond[p->scond^1];	/* complement */
-				p->scond = 14;
-				p->from = zprg.from;
-				p->to = zprg.to;
-				p->to.type = D_BRANCH;
-				p->cond = q->link->link;	/* successor of RET */
-				p->to.offset = q->link->link->pc;
-
-				p = q->link->link;
-			} else {
-
-				/*
-				 * BL	profout
-				 */
-				p->as = ABL;
-				p->from = zprg.from;
-				p->to = zprg.to;
-				p->to.type = D_BRANCH;
-				p->cond = ps4;
-				p->to.sym = s4;
-				p->scond = 14;
-
-				p = q;
-			}
-			continue;
-		}
-	}
-}
-
-void
-nuxiinit(void)
-{
-
-	int i, c;
-
-	for(i=0; i<4; i++) {
-		c = find1(0x04030201L, i+1);
-		if(i < 2)
-			inuxi2[i] = c;
-		if(i < 1)
-			inuxi1[i] = c;
-		inuxi4[i] = c;
-		fnuxi4[i] = c;
-		if(debug['d'] == 0){
-			fnuxi8[i] = c;
-			fnuxi8[i+4] = c+4;
-		}
-		else{
-			fnuxi8[i] = c+4;		/* ms word first, then ls, even in little endian mode */
-			fnuxi8[i+4] = c;
-		}
-	}
-	if(debug['v']) {
-		Bprint(&bso, "inuxi = ");
-		for(i=0; i<1; i++)
-			Bprint(&bso, "%d", inuxi1[i]);
-		Bprint(&bso, " ");
-		for(i=0; i<2; i++)
-			Bprint(&bso, "%d", inuxi2[i]);
-		Bprint(&bso, " ");
-		for(i=0; i<4; i++)
-			Bprint(&bso, "%d", inuxi4[i]);
-		Bprint(&bso, "\nfnuxi = ");
-		for(i=0; i<4; i++)
-			Bprint(&bso, "%d", fnuxi4[i]);
-		Bprint(&bso, " ");
-		for(i=0; i<8; i++)
-			Bprint(&bso, "%d", fnuxi8[i]);
-		Bprint(&bso, "\n");
-	}
-	Bflush(&bso);
-}
-
-find1(long l, int c)
-{
-	char *p;
-	int i;
-
-	p = (char*)&l;
-	for(i=0; i<4; i++)
-		if(*p++ == c)
-			return i;
-	return 0;
-}
-
-int32_t
-ieeedtof(Ieee *ieeep)
-{
-	int exp;
-	int32_t v;
-
-	if(ieeep->h == 0)
-		return 0;
-	exp = (ieeep->h>>20) & ((1L<<11)-1L);
-	exp -= (1L<<10) - 2L;
-	v = (ieeep->h & 0xfffffL) << 3;
-	v |= (ieeep->l >> 29) & 0x7L;
-	if((ieeep->l >> 28) & 1) {
-		v++;
-		if(v & 0x800000L) {
-			v = (v & 0x7fffffL) >> 1;
-			exp++;
-		}
-	}
-	if(exp <= -126 || exp >= 130)
-		diag("double fp to single fp overflow");
-	v |= ((exp + 126) & 0xffL) << 23;
-	v |= ieeep->h & 0x80000000L;
-	return v;
-}
-
-double
-ieeedtod(Ieee *ieeep)
-{
-	Ieee e;
-	double fr;
-	int exp;
-
-	if(ieeep->h & (1L<<31)) {
-		e.h = ieeep->h & ~(1L<<31);
-		e.l = ieeep->l;
-		return -ieeedtod(&e);
-	}
-	if(ieeep->l == 0 && ieeep->h == 0)
-		return 0;
-	fr = ieeep->l & ((1L<<16)-1L);
-	fr /= 1L<<16;
-	fr += (ieeep->l>>16) & ((1L<<16)-1L);
-	fr /= 1L<<16;
-	fr += (ieeep->h & (1L<<20)-1L) | (1L<<20);
-	fr /= 1L<<21;
-	exp = (ieeep->h>>20) & ((1L<<11)-1L);
-	exp -= (1L<<10) - 2L;
-	return ldexp(fr, exp);
-}
-
-void
-undefsym(Sym *s)
-{
-	int n;
-
-	n = imports;
-	if(s->value != 0)
-		diag("value != 0 on SXREF");
-	if(n >= 1<<Rindex)
-		diag("import index %d out of range", n);
-	s->value = n<<Roffset;
-	s->type = SUNDEF;
-	imports++;
-}
-
-void
-zerosig(char *sp)
-{
-	Sym *s;
-
-	s = lookup(sp, 0);
-	s->sig = 0;
-}
-
-void
-readundefs(char *f, int t)
-{
-	int i, n;
-	Sym *s;
-	Biobuf *b;
-	char *l, buf[256], *fields[64];
-
-	if(f == nil)
-		return;
-	b = Bopen(f, OREAD);
-	if(b == nil){
-		diag("could not open %s: %r", f);
-		errorexit();
-	}
-	while((l = Brdline(b, '\n')) != nil){
-		n = Blinelen(b);
-		if(n >= sizeof(buf)){
-			diag("%s: line too long", f);
-			errorexit();
-		}
-		memmove(buf, l, n);
-		buf[n-1] = '\0';
-		n = getfields(buf, fields, nelem(fields), 1, " \t\r\n");
-		if(n == nelem(fields)){
-			diag("%s: bad format", f);
-			errorexit();
-		}
-		for(i = 0; i < n; i++) {
-			s = lookup(fields[i], 0);
-			s->type = SXREF;
-			s->subtype = t;
-			if(t == SIMPORT)
-				nimports++;
-			else
-				nexports++;
-		}
-	}
-	Bterm(b);
-}

+ 0 - 266
sys/src/cmd/5l/optab.c

@@ -1,266 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include	"l.h"
-
-Optab	optab[] =
-{
-	{ ATEXT,	C_LEXT,	C_NONE,	C_LCON, 	 0, 0, 0 },
-	{ ATEXT,	C_LEXT,	C_REG,	C_LCON, 	 0, 0, 0 },
-	{ ATEXT,	C_ADDR,	C_NONE,	C_LCON, 	 0, 0, 0 },
-	{ ATEXT,	C_ADDR,	C_REG,	C_LCON, 	 0, 0, 0 },
-
-	{ AADD,		C_REG,	C_REG,	C_REG,		 1, 4, 0 },
-	{ AADD,		C_REG,	C_NONE,	C_REG,		 1, 4, 0 },
-	{ AMOVW,	C_REG,	C_NONE,	C_REG,		 1, 4, 0 },
-	{ AMVN,		C_REG,	C_NONE,	C_REG,		 1, 4, 0 },
-	{ ACMP,		C_REG,	C_REG,	C_NONE,		 1, 4, 0 },
-
-	{ AADD,		C_RCON,	C_REG,	C_REG,		 2, 4, 0 },
-	{ AADD,		C_RCON,	C_NONE,	C_REG,		 2, 4, 0 },
-	{ AMOVW,	C_RCON,	C_NONE,	C_REG,		 2, 4, 0 },
-	{ AMVN,		C_RCON,	C_NONE,	C_REG,		 2, 4, 0 },
-	{ ACMP,		C_RCON,	C_REG,	C_NONE,		 2, 4, 0 },
-
-	{ AADD,		C_SHIFT,C_REG,	C_REG,		 3, 4, 0 },
-	{ AADD,		C_SHIFT,C_NONE,	C_REG,		 3, 4, 0 },
-	{ AMVN,		C_SHIFT,C_NONE,	C_REG,		 3, 4, 0 },
-	{ ACMP,		C_SHIFT,C_REG,	C_NONE,		 3, 4, 0 },
-
-	{ AMOVW,	C_RECON,C_NONE,	C_REG,		 4, 4, REGSB },
-	{ AMOVW,	C_RACON,C_NONE,	C_REG,		 4, 4, REGSP },
-
-	{ AB,		C_NONE,	C_NONE,	C_SBRA,		 5, 4, 0,	LPOOL },
-	{ ABL,		C_NONE,	C_NONE,	C_SBRA,		 5, 4, 0 },
-	{ ABEQ,		C_NONE,	C_NONE,	C_SBRA,		 5, 4, 0 },
-
-	{ AB,		C_NONE,	C_NONE,	C_ROREG,	 6, 4, 0,	LPOOL },
-	{ ABL,		C_NONE,	C_NONE,	C_ROREG,	 7, 8, 0 },
-
-	{ ASLL,		C_RCON,	C_REG,	C_REG,		 8, 4, 0 },
-	{ ASLL,		C_RCON,	C_NONE,	C_REG,		 8, 4, 0 },
-
-	{ ASLL,		C_REG,	C_NONE,	C_REG,		 9, 4, 0 },
-	{ ASLL,		C_REG,	C_REG,	C_REG,		 9, 4, 0 },
-
-	{ ASWI,		C_NONE,	C_NONE,	C_NONE,		10, 4, 0 },
-	{ ASWI,		C_NONE,	C_NONE,	C_LOREG,	10, 4, 0 },
-
-	{ AWORD,	C_NONE,	C_NONE,	C_LCON,		11, 4, 0 },
-	{ AWORD,	C_NONE,	C_NONE,	C_LEXT,		11, 4, 0 },
-	{ AWORD,	C_NONE,	C_NONE,	C_ADDR,		11, 4, 0 },
-
-	{ AMOVW,	C_NCON,	C_NONE,	C_REG,		12, 4, 0 },
-	{ AMOVW,	C_LCON,	C_NONE,	C_REG,		12, 4, 0,	LFROM },
-
-	{ AADD,		C_NCON,	C_REG,	C_REG,		13, 8, 0 },
-	{ AADD,		C_NCON,	C_NONE,	C_REG,		13, 8, 0 },
-	{ AMVN,		C_NCON,	C_NONE,	C_REG,		13, 8, 0 },
-	{ ACMP,		C_NCON,	C_REG,	C_NONE,		13, 8, 0 },
-	{ AADD,		C_LCON,	C_REG,	C_REG,		13, 8, 0,	LFROM },
-	{ AADD,		C_LCON,	C_NONE,	C_REG,		13, 8, 0,	LFROM },
-	{ AMVN,		C_LCON,	C_NONE,	C_REG,		13, 8, 0,	LFROM },
-	{ ACMP,		C_LCON,	C_REG,	C_NONE,		13, 8, 0,	LFROM },
-
-	{ AMOVB,	C_REG,	C_NONE,	C_REG,		14, 8, 0 },
-	{ AMOVBU,	C_REG,	C_NONE,	C_REG,		58, 4, 0 },
-	{ AMOVH,	C_REG,	C_NONE,	C_REG,		14, 8, 0 },
-	{ AMOVHU,	C_REG,	C_NONE,	C_REG,		14, 8, 0 },
-
-	{ AMUL,		C_REG,	C_REG,	C_REG,		15, 4, 0 },
-	{ AMUL,		C_REG,	C_NONE,	C_REG,		15, 4, 0 },
-
-	{ ADIV,		C_REG,	C_REG,	C_REG,		16, 4, 0 },
-	{ ADIV,		C_REG,	C_NONE,	C_REG,		16, 4, 0 },
-
-	{ AMULL,	C_REG,	C_REG,	C_REGREG,	17, 4, 0 },
-
-	{ AMOVW,	C_REG,	C_NONE,	C_SEXT,		20, 4, REGSB },
-	{ AMOVW,	C_REG,	C_NONE,	C_SAUTO,	20, 4, REGSP },
-	{ AMOVW,	C_REG,	C_NONE,	C_SOREG,	20, 4, 0 },
-	{ AMOVB,	C_REG,	C_NONE,	C_SEXT,		20, 4, REGSB },
-	{ AMOVB,	C_REG,	C_NONE,	C_SAUTO,	20, 4, REGSP },
-	{ AMOVB,	C_REG,	C_NONE,	C_SOREG,	20, 4, 0 },
-	{ AMOVBU,	C_REG,	C_NONE,	C_SEXT,		20, 4, REGSB },
-	{ AMOVBU,	C_REG,	C_NONE,	C_SAUTO,	20, 4, REGSP },
-	{ AMOVBU,	C_REG,	C_NONE,	C_SOREG,	20, 4, 0 },
-
-	{ AMOVW,	C_SEXT,	C_NONE,	C_REG,		21, 4, REGSB },
-	{ AMOVW,	C_SAUTO,C_NONE,	C_REG,		21, 4, REGSP },
-	{ AMOVW,	C_SOREG,C_NONE,	C_REG,		21, 4, 0 },
-	{ AMOVBU,	C_SEXT,	C_NONE,	C_REG,		21, 4, REGSB },
-	{ AMOVBU,	C_SAUTO,C_NONE,	C_REG,		21, 4, REGSP },
-	{ AMOVBU,	C_SOREG,C_NONE,	C_REG,		21, 4, 0 },
-
-	{ AMOVB,	C_SEXT,	C_NONE,	C_REG,		22, 12, REGSB },
-	{ AMOVB,	C_SAUTO,C_NONE,	C_REG,		22, 12, REGSP },
-	{ AMOVB,	C_SOREG,C_NONE,	C_REG,		22, 12, 0 },
-	{ AMOVH,	C_SEXT,	C_NONE,	C_REG,		22, 12, REGSB },
-	{ AMOVH,	C_SAUTO,C_NONE,	C_REG,		22, 12, REGSP },
-	{ AMOVH,	C_SOREG,C_NONE,	C_REG,		22, 12, 0 },
-	{ AMOVHU,	C_SEXT,	C_NONE,	C_REG,		22, 12, REGSB },
-	{ AMOVHU,	C_SAUTO,C_NONE,	C_REG,		22, 12, REGSP },
-	{ AMOVHU,	C_SOREG,C_NONE,	C_REG,		22, 12, 0 },
-
-	{ AMOVH,	C_REG,	C_NONE,	C_SEXT,		23, 12, REGSB },
-	{ AMOVH,	C_REG,	C_NONE,	C_SAUTO,	23, 12, REGSP },
-	{ AMOVH,	C_REG,	C_NONE,	C_SOREG,	23, 12, 0 },
-	{ AMOVHU,	C_REG,	C_NONE,	C_SEXT,		23, 12, REGSB },
-	{ AMOVHU,	C_REG,	C_NONE,	C_SAUTO,	23, 12, REGSP },
-	{ AMOVHU,	C_REG,	C_NONE,	C_SOREG,	23, 12, 0 },
-
-	{ AMOVW,	C_REG,	C_NONE,	C_LEXT,		30, 8, REGSB,	LTO },
-	{ AMOVW,	C_REG,	C_NONE,	C_LAUTO,	30, 8, REGSP,	LTO },
-	{ AMOVW,	C_REG,	C_NONE,	C_LOREG,	30, 8, 0,	LTO },
-	{ AMOVW,	C_REG,	C_NONE,	C_ADDR,		64, 8, 0,	LTO },
-	{ AMOVB,	C_REG,	C_NONE,	C_LEXT,		30, 8, REGSB,	LTO },
-	{ AMOVB,	C_REG,	C_NONE,	C_LAUTO,	30, 8, REGSP,	LTO },
-	{ AMOVB,	C_REG,	C_NONE,	C_LOREG,	30, 8, 0,	LTO },
-	{ AMOVB,	C_REG,	C_NONE,	C_ADDR,		64, 8, 0,	LTO },
-	{ AMOVBU,	C_REG,	C_NONE,	C_LEXT,		30, 8, REGSB,	LTO },
-	{ AMOVBU,	C_REG,	C_NONE,	C_LAUTO,	30, 8, REGSP,	LTO },
-	{ AMOVBU,	C_REG,	C_NONE,	C_LOREG,	30, 8, 0,	LTO },
-	{ AMOVBU,	C_REG,	C_NONE,	C_ADDR,		64, 8, 0,	LTO },
-
-	{ AMOVW,	C_LEXT,	C_NONE,	C_REG,		31, 8, REGSB,	LFROM },
-	{ AMOVW,	C_LAUTO,C_NONE,	C_REG,		31, 8, REGSP,	LFROM },
-	{ AMOVW,	C_LOREG,C_NONE,	C_REG,		31, 8, 0,	LFROM },
-	{ AMOVW,	C_ADDR,	C_NONE,	C_REG,		65, 8, 0,	LFROM },
-	{ AMOVBU,	C_LEXT,	C_NONE,	C_REG,		31, 8, REGSB,	LFROM },
-	{ AMOVBU,	C_LAUTO,C_NONE,	C_REG,		31, 8, REGSP,	LFROM },
-	{ AMOVBU,	C_LOREG,C_NONE,	C_REG,		31, 8, 0,	LFROM },
-	{ AMOVBU,	C_ADDR,	C_NONE,	C_REG,		65, 8, 0,	LFROM },
-
-	{ AMOVB,	C_LEXT,	C_NONE,	C_REG,		32, 16, REGSB,	LFROM },
-	{ AMOVB,	C_LAUTO,C_NONE,	C_REG,		32, 16, REGSP,	LFROM },
-	{ AMOVB,	C_LOREG,C_NONE,	C_REG,		32, 16, 0,	LFROM },
-	{ AMOVB,	C_ADDR,	C_NONE,	C_REG,		66, 16, 0,	LFROM },
-	{ AMOVH,	C_LEXT,	C_NONE,	C_REG,		32, 16, REGSB,	LFROM },
-	{ AMOVH,	C_LAUTO,C_NONE,	C_REG,		32, 16, REGSP,	LFROM },
-	{ AMOVH,	C_LOREG,C_NONE,	C_REG,		32, 16, 0,	LFROM },
-	{ AMOVH,	C_ADDR,	C_NONE,	C_REG,		66, 16, 0,	LFROM },
-	{ AMOVHU,	C_LEXT,	C_NONE,	C_REG,		32, 16, REGSB,	LFROM },
-	{ AMOVHU,	C_LAUTO,C_NONE,	C_REG,		32, 16, REGSP,	LFROM },
-	{ AMOVHU,	C_LOREG,C_NONE,	C_REG,		32, 16, 0,	LFROM },
-	{ AMOVHU,	C_ADDR,	C_NONE,	C_REG,		66, 16, 0,	LFROM },
-
-	{ AMOVH,	C_REG,	C_NONE,	C_LEXT,		33, 24, REGSB,	LTO },
-	{ AMOVH,	C_REG,	C_NONE,	C_LAUTO,	33, 24, REGSP,	LTO },
-	{ AMOVH,	C_REG,	C_NONE,	C_LOREG,	33, 24, 0,	LTO },
-	{ AMOVH,	C_REG,	C_NONE,	C_ADDR,		67, 24, 0,	LTO },
-	{ AMOVHU,	C_REG,	C_NONE,	C_LEXT,		33, 24, REGSB,	LTO },
-	{ AMOVHU,	C_REG,	C_NONE,	C_LAUTO,	33, 24, REGSP,	LTO },
-	{ AMOVHU,	C_REG,	C_NONE,	C_LOREG,	33, 24, 0,	LTO },
-	{ AMOVHU,	C_REG,	C_NONE,	C_ADDR,		67, 24, 0,	LTO },
-
-	{ AMOVW,	C_LECON,C_NONE,	C_REG,		34, 8, REGSB,	LFROM },
-	{ AMOVW,	C_LACON,C_NONE,	C_REG,		34, 8, REGSP,	LFROM },
-
-	{ AMOVW,	C_PSR,	C_NONE,	C_REG,		35, 4, 0 },
-	{ AMOVW,	C_REG,	C_NONE,	C_PSR,		36, 4, 0 },
-	{ AMOVW,	C_RCON,	C_NONE,	C_PSR,		37, 4, 0 },
-
-	{ AMOVM,	C_LCON,	C_NONE,	C_SOREG,	38, 4, 0 },
-	{ AMOVM,	C_SOREG,C_NONE,	C_LCON,		39, 4, 0 },
-
-	{ ASWPW,	C_SOREG,C_REG,	C_REG,		40, 4, 0 },
-
-	{ ARFE,		C_NONE,	C_NONE,	C_NONE,		41, 4, 0 },
-
-	{ AMOVF,	C_FREG,	C_NONE,	C_FEXT,		50, 4, REGSB },
-	{ AMOVF,	C_FREG,	C_NONE,	C_FAUTO,	50, 4, REGSP },
-	{ AMOVF,	C_FREG,	C_NONE,	C_FOREG,	50, 4, 0 },
-
-	{ AMOVF,	C_FEXT,	C_NONE,	C_FREG,		51, 4, REGSB },
-	{ AMOVF,	C_FAUTO,C_NONE,	C_FREG,		51, 4, REGSP },
-	{ AMOVF,	C_FOREG,C_NONE,	C_FREG,		51, 4, 0 },
-
-	{ AMOVF,	C_FREG,	C_NONE,	C_LEXT,		52, 12, REGSB,	LTO },
-	{ AMOVF,	C_FREG,	C_NONE,	C_LAUTO,	52, 12, REGSP,	LTO },
-	{ AMOVF,	C_FREG,	C_NONE,	C_LOREG,	52, 12, 0,	LTO },
-
-	{ AMOVF,	C_LEXT,	C_NONE,	C_FREG,		53, 12, REGSB,	LFROM },
-	{ AMOVF,	C_LAUTO,C_NONE,	C_FREG,		53, 12, REGSP,	LFROM },
-	{ AMOVF,	C_LOREG,C_NONE,	C_FREG,		53, 12, 0,	LFROM },
-
-	{ AMOVF,	C_FREG,	C_NONE,	C_ADDR,		68, 8, 0,	LTO },
-	{ AMOVF,	C_ADDR,	C_NONE,	C_FREG,		69, 8, 0,	LFROM },
-
-	{ AADDF,	C_FREG,	C_NONE,	C_FREG,		54, 4, 0 },
-	{ AADDF,	C_FREG,	C_REG,	C_FREG,		54, 4, 0 },
-	{ AADDF,	C_FCON,	C_NONE,	C_FREG,		54, 4, 0 },
-	{ AADDF,	C_FCON,	C_REG,	C_FREG,		54, 4, 0 },
-	{ AMOVF,	C_FCON,	C_NONE,	C_FREG,		54, 4, 0 },
-	{ AMOVF,	C_FREG, C_NONE, C_FREG,		54, 4, 0 },
-
-	{ ACMPF,	C_FREG,	C_REG,	C_NONE,		54, 4, 0 },
-	{ ACMPF,	C_FCON,	C_REG,	C_NONE,		54, 4, 0 },
-
-	{ AMOVFW,	C_FREG,	C_NONE,	C_REG,		55, 4, 0 },
-	{ AMOVFW,	C_REG,	C_NONE,	C_FREG,		55, 4, 0 },
-
-	{ AMOVW,	C_REG,	C_NONE,	C_FCR,		56, 4, 0 },
-	{ AMOVW,	C_FCR,	C_NONE,	C_REG,		57, 4, 0 },
-
-	{ AMOVW,	C_SHIFT,C_NONE,	C_REG,		59, 4, 0 },
-	{ AMOVBU,	C_SHIFT,C_NONE,	C_REG,		59, 4, 0 },
-
-	{ AMOVB,	C_SHIFT,C_NONE,	C_REG,		60, 4, 0 },
-
-	{ AMOVW,	C_REG,	C_NONE,	C_SHIFT,	61, 4, 0 },
-	{ AMOVB,	C_REG,	C_NONE,	C_SHIFT,	61, 4, 0 },
-	{ AMOVBU,	C_REG,	C_NONE,	C_SHIFT,	61, 4, 0 },
-
-	{ ACASE,	C_REG,	C_NONE,	C_NONE,		62, 4, 0 },
-	{ ABCASE,	C_NONE, C_NONE, C_SBRA,		63, 4, 0 },
-
-	{ AADDF,	C_FREG,	C_NONE,	C_FREG,		74, 4, 0, VFP },
-	{ AADDF,	C_FREG,	C_REG,	C_FREG,		74, 4, 0, VFP },
-	{ AMOVF,	C_FREG, C_NONE, C_FREG,		74, 4, 0, VFP },
-	{ ACMPF,	C_FREG,	C_REG,	C_NONE,		75, 8, 0, VFP },
-	{ ACMPF,	C_FCON,	C_REG,	C_NONE,		75, 8, 0, VFP },
-	{ AMOVFW,	C_FREG,	C_NONE,	C_REG,		76, 8, 0, VFP },
-	{ AMOVFW,	C_REG,	C_NONE,	C_FREG,		76, 8, 0, VFP },
-
-	{ AMOVH,	C_REG,	C_NONE,	C_HEXT,		70, 4, REGSB,	V4 },
-	{ AMOVH,	C_REG,	C_NONE, C_HAUTO,	70, 4, REGSP,	V4 },
-	{ AMOVH,	C_REG,	C_NONE,	C_HOREG,	70, 4, 0,	V4 },
-	{ AMOVHU,	C_REG,	C_NONE,	C_HEXT,		70, 4, REGSB,	V4 },
-	{ AMOVHU,	C_REG,	C_NONE, C_HAUTO,	70, 4, REGSP,	V4 },
-	{ AMOVHU,	C_REG,	C_NONE,	C_HOREG,	70, 4, 0,	V4 },
-
-	{ AMOVB,	C_HEXT,	C_NONE, C_REG,		71, 4, REGSB,	V4 },
-	{ AMOVB,	C_HAUTO,C_NONE,	C_REG,		71, 4, REGSP,	V4 },
-	{ AMOVB,	C_HOREG,C_NONE,	C_REG,		71, 4, 0,	V4 },
-	{ AMOVH,	C_HEXT,	C_NONE,	C_REG,		71, 4, REGSB,	V4 },
-	{ AMOVH,	C_HAUTO,C_NONE, C_REG,		71, 4, REGSP,	V4 },
-	{ AMOVH,	C_HOREG,C_NONE,	C_REG,		71, 4, 0,	V4 },
-	{ AMOVHU,	C_HEXT,	C_NONE,	C_REG,		71, 4, REGSB,	V4 },
-	{ AMOVHU,	C_HAUTO,C_NONE, C_REG,		71, 4, REGSP,	V4 },
-	{ AMOVHU,	C_HOREG,C_NONE,	C_REG,		71, 4, 0,	V4 },
-
-	{ AMOVH,	C_REG,	C_NONE,	C_LEXT,		72, 8, REGSB,	LTO|V4 },
-	{ AMOVH,	C_REG,	C_NONE, C_LAUTO,	72, 8, REGSP,	LTO|V4 },
-	{ AMOVH,	C_REG,	C_NONE,	C_LOREG,	72, 8, 0,	LTO|V4 },
-	{ AMOVHU,	C_REG,	C_NONE,	C_LEXT,		72, 8, REGSB,	LTO|V4 },
-	{ AMOVHU,	C_REG,	C_NONE, C_LAUTO,	72, 8, REGSP,	LTO|V4 },
-	{ AMOVHU,	C_REG,	C_NONE,	C_LOREG,	72, 8, 0,	LTO|V4 },
-
-	{ AMOVB,	C_LEXT,	C_NONE, C_REG,		73, 8, REGSB,	LFROM|V4 },
-	{ AMOVB,	C_LAUTO,C_NONE,	C_REG,		73, 8, REGSP,	LFROM|V4 },
-	{ AMOVB,	C_LOREG,C_NONE,	C_REG,		73, 8, 0,	LFROM|V4 },
-	{ AMOVH,	C_LEXT,	C_NONE,	C_REG,		73, 8, REGSB,	LFROM|V4 },
-	{ AMOVH,	C_LAUTO,C_NONE, C_REG,		73, 8, REGSP,	LFROM|V4 },
-	{ AMOVH,	C_LOREG,C_NONE,	C_REG,		73, 8, 0,	LFROM|V4 },
-	{ AMOVHU,	C_LEXT,	C_NONE,	C_REG,		73, 8, REGSB,	LFROM|V4 },
-	{ AMOVHU,	C_LAUTO,C_NONE, C_REG,		73, 8, REGSP,	LFROM|V4 },
-	{ AMOVHU,	C_LOREG,C_NONE,	C_REG,		73, 8, 0,	LFROM|V4 },
-
-	{ AXXX,		C_NONE,	C_NONE,	C_NONE,		 0, 4, 0 },
-};

+ 0 - 604
sys/src/cmd/5l/pass.c

@@ -1,604 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include	"l.h"
-
-void
-dodata(void)
-{
-	int i, t;
-	Sym *s;
-	Prog *p;
-	int32_t orig, v;
-
-	if(debug['v'])
-		Bprint(&bso, "%5.2f dodata\n", cputime());
-	Bflush(&bso);
-	for(p = datap; p != P; p = p->link) {
-		s = p->from.sym;
-		if(p->as == ADYNT || p->as == AINIT)
-			s->value = dtype;
-		if(s->type == SBSS)
-			s->type = SDATA;
-		if(s->type != SDATA)
-			diag("initialize non-data (%d): %s\n%P",
-				s->type, s->name, p);
-		v = p->from.offset + p->reg;
-		if(v > s->value)
-			diag("initialize bounds (%ld): %s\n%P",
-				s->value, s->name, p);
-	}
-
-	if(debug['t']) {
-		/*
-		 * pull out string constants
-		 */
-		for(p = datap; p != P; p = p->link) {
-			s = p->from.sym;
-			if(p->to.type == D_SCONST)
-				s->type = SSTRING;
-		}
-	}
-
-	/*
-	 * pass 1
-	 *	assign 'small' variables to data segment
-	 *	(rational is that data segment is more easily
-	 *	 addressed through offset on R12)
-	 */
-	orig = 0;
-	for(i=0; i<NHASH; i++)
-	for(s = hash[i]; s != S; s = s->link) {
-		t = s->type;
-		if(t != SDATA && t != SBSS)
-			continue;
-		v = s->value;
-		if(v == 0) {
-			diag("%s: no size", s->name);
-			v = 1;
-		}
-		while(v & 3)
-			v++;
-		s->value = v;
-		if(v > MINSIZ)
-			continue;
-		s->value = orig;
-		orig += v;
-		s->type = SDATA1;
-	}
-
-	/*
-	 * pass 2
-	 *	assign large 'data' variables to data segment
-	 */
-	for(i=0; i<NHASH; i++)
-	for(s = hash[i]; s != S; s = s->link) {
-		t = s->type;
-		if(t != SDATA) {
-			if(t == SDATA1)
-				s->type = SDATA;
-			continue;
-		}
-		v = s->value;
-		s->value = orig;
-		orig += v;
-	}
-
-	while(orig & 7)
-		orig++;
-	datsize = orig;
-
-	/*
-	 * pass 3
-	 *	everything else to bss segment
-	 */
-	for(i=0; i<NHASH; i++)
-	for(s = hash[i]; s != S; s = s->link) {
-		if(s->type != SBSS)
-			continue;
-		v = s->value;
-		s->value = orig;
-		orig += v;
-	}
-	while(orig & 7)
-		orig++;
-	bsssize = orig-datsize;
-
-	xdefine("setR12", SDATA, 0L+BIG);
-	xdefine("bdata", SDATA, 0L);
-	xdefine("edata", SDATA, datsize);
-	xdefine("end", SBSS, datsize+bsssize);
-	xdefine("etext", STEXT, 0L);
-}
-
-void
-undef(void)
-{
-	int i;
-	Sym *s;
-
-	for(i=0; i<NHASH; i++)
-	for(s = hash[i]; s != S; s = s->link)
-		if(s->type == SXREF)
-			diag("%s: not defined", s->name);
-}
-
-Prog*
-brchain(Prog *p)
-{
-	int i;
-
-	for(i=0; i<20; i++) {
-		if(p == P || p->as != AB)
-			return p;
-		p = p->cond;
-	}
-	return P;
-}
-
-int
-relinv(int a)
-{
-	switch(a) {
-	case ABEQ:	return ABNE;
-	case ABNE:	return ABEQ;
-	case ABCS:	return ABCC;
-	case ABHS:	return ABLO;
-	case ABCC:	return ABCS;
-	case ABLO:	return ABHS;
-	case ABMI:	return ABPL;
-	case ABPL:	return ABMI;
-	case ABVS:	return ABVC;
-	case ABVC:	return ABVS;
-	case ABHI:	return ABLS;
-	case ABLS:	return ABHI;
-	case ABGE:	return ABLT;
-	case ABLT:	return ABGE;
-	case ABGT:	return ABLE;
-	case ABLE:	return ABGT;
-	}
-	diag("unknown relation: %s", anames[a]);
-	return a;
-}
-
-void
-follow(void)
-{
-	if(debug['v'])
-		Bprint(&bso, "%5.2f follow\n", cputime());
-	Bflush(&bso);
-
-	firstp = prg();
-	lastp = firstp;
-	xfol(textp);
-
-	firstp = firstp->link;
-	lastp->link = P;
-}
-
-void
-xfol(Prog *p)
-{
-	Prog *q, *r;
-	int a, i;
-
-loop:
-	if(p == P)
-		return;
-	a = p->as;
-	if(a == ATEXT)
-		curtext = p;
-	if(a == AB) {
-		q = p->cond;
-		if(q != P) {
-			p->mark |= FOLL;
-			p = q;
-			if(!(p->mark & FOLL))
-				goto loop;
-		}
-	}
-	if(p->mark & FOLL) {
-		for(i=0,q=p; i<4; i++,q=q->link) {
-			if(q == lastp)
-				break;
-			a = q->as;
-			if(a == ANOP) {
-				i--;
-				continue;
-			}
-			if(a == AB || (a == ARET && q->scond == 14) || a == ARFE)
-				goto copy;
-			if(!q->cond || (q->cond->mark&FOLL))
-				continue;
-			if(a != ABEQ && a != ABNE)
-				continue;
-		copy:
-			for(;;) {
-				r = prg();
-				*r = *p;
-				if(!(r->mark&FOLL))
-					print("cant happen 1\n");
-				r->mark |= FOLL;
-				if(p != q) {
-					p = p->link;
-					lastp->link = r;
-					lastp = r;
-					continue;
-				}
-				lastp->link = r;
-				lastp = r;
-				if(a == AB || (a == ARET && q->scond == 14) || a == ARFE)
-					return;
-				r->as = ABNE;
-				if(a == ABNE)
-					r->as = ABEQ;
-				r->cond = p->link;
-				r->link = p->cond;
-				if(!(r->link->mark&FOLL))
-					xfol(r->link);
-				if(!(r->cond->mark&FOLL))
-					print("cant happen 2\n");
-				return;
-			}
-		}
-		a = AB;
-		q = prg();
-		q->as = a;
-		q->line = p->line;
-		q->to.type = D_BRANCH;
-		q->to.offset = p->pc;
-		q->cond = p;
-		p = q;
-	}
-	p->mark |= FOLL;
-	lastp->link = p;
-	lastp = p;
-	if(a == AB || (a == ARET && p->scond == 14) || a == ARFE){
-		return;
-	}
-	if(p->cond != P)
-	if(a != ABL && p->link != P) {
-		q = brchain(p->link);
-		if(a != ATEXT && a != ABCASE)
-		if(q != P && (q->mark&FOLL)) {
-			p->as = relinv(a);
-			p->link = p->cond;
-			p->cond = q;
-		}
-		xfol(p->link);
-		q = brchain(p->cond);
-		if(q == P)
-			q = p->cond;
-		if(q->mark&FOLL) {
-			p->cond = q;
-			return;
-		}
-		p = q;
-		goto loop;
-	}
-	p = p->link;
-	goto loop;
-}
-
-void
-patch(void)
-{
-	int32_t c, vexit;
-	Prog *p, *q;
-	Sym *s;
-	int a;
-
-	if(debug['v'])
-		Bprint(&bso, "%5.2f patch\n", cputime());
-	Bflush(&bso);
-	mkfwd();
-	s = lookup("exit", 0);
-	vexit = s->value;
-	for(p = firstp; p != P; p = p->link) {
-		a = p->as;
-		if(a == ATEXT)
-			curtext = p;
-		if((a == ABL || a == AB || a == ARET) &&
-		   p->to.type != D_BRANCH && p->to.sym != S) {
-			s = p->to.sym;
-			switch(s->type) {
-			default:
-				diag("undefined: %s\n%P", s->name, p);
-				s->type = STEXT;
-				s->value = vexit;
-				break;
-			case STEXT:
-				p->to.offset = s->value;
-				p->to.type = D_BRANCH;
-				break;
-			case SUNDEF:
-				if(p->as != ABL)
-					diag("help: SUNDEF in AB || ARET");
-				p->to.offset = 0;
-				p->to.type = D_BRANCH;
-				p->cond = UP;
-				break;
-			}
-		}
-		if(p->to.type != D_BRANCH || p->cond == UP)
-			continue;
-		c = p->to.offset;
-		for(q = firstp; q != P;) {
-			if(q->forwd != P)
-			if(c >= q->forwd->pc) {
-				q = q->forwd;
-				continue;
-			}
-			if(c == q->pc)
-				break;
-			q = q->link;
-		}
-		if(q == P) {
-			diag("branch out of range %ld\n%P", c, p);
-			p->to.type = D_NONE;
-		}
-		p->cond = q;
-	}
-
-	for(p = firstp; p != P; p = p->link) {
-		if(p->as == ATEXT)
-			curtext = p;
-		if(p->cond != P && p->cond != UP) {
-			p->cond = brloop(p->cond);
-			if(p->cond != P)
-			if(p->to.type == D_BRANCH)
-				p->to.offset = p->cond->pc;
-		}
-	}
-}
-
-#define	LOG	5
-void
-mkfwd(void)
-{
-	Prog *p;
-	int32_t dwn[LOG], cnt[LOG], i;
-	Prog *lst[LOG];
-
-	for(i=0; i<LOG; i++) {
-		if(i == 0)
-			cnt[i] = 1; else
-			cnt[i] = LOG * cnt[i-1];
-		dwn[i] = 1;
-		lst[i] = P;
-	}
-	i = 0;
-	for(p = firstp; p != P; p = p->link) {
-		if(p->as == ATEXT)
-			curtext = p;
-		i--;
-		if(i < 0)
-			i = LOG-1;
-		p->forwd = P;
-		dwn[i]--;
-		if(dwn[i] <= 0) {
-			dwn[i] = cnt[i];
-			if(lst[i] != P)
-				lst[i]->forwd = p;
-			lst[i] = p;
-		}
-	}
-}
-
-Prog*
-brloop(Prog *p)
-{
-	Prog *q;
-	int c;
-
-	for(c=0; p!=P;) {
-		if(p->as != AB)
-			return p;
-		q = p->cond;
-		if(q <= p) {
-			c++;
-			if(q == p || c > 5000)
-				break;
-		}
-		p = q;
-	}
-	return P;
-}
-
-int32_t
-atolwhex(char *s)
-{
-	int32_t n;
-	int f;
-
-	n = 0;
-	f = 0;
-	while(*s == ' ' || *s == '\t')
-		s++;
-	if(*s == '-' || *s == '+') {
-		if(*s++ == '-')
-			f = 1;
-		while(*s == ' ' || *s == '\t')
-			s++;
-	}
-	if(s[0]=='0' && s[1]){
-		if(s[1]=='x' || s[1]=='X'){
-			s += 2;
-			for(;;){
-				if(*s >= '0' && *s <= '9')
-					n = n*16 + *s++ - '0';
-				else if(*s >= 'a' && *s <= 'f')
-					n = n*16 + *s++ - 'a' + 10;
-				else if(*s >= 'A' && *s <= 'F')
-					n = n*16 + *s++ - 'A' + 10;
-				else
-					break;
-			}
-		} else
-			while(*s >= '0' && *s <= '7')
-				n = n*8 + *s++ - '0';
-	} else
-		while(*s >= '0' && *s <= '9')
-			n = n*10 + *s++ - '0';
-	if(f)
-		n = -n;
-	return n;
-}
-
-int32_t
-rnd(int32_t v, int32_t r)
-{
-	int32_t c;
-
-	if(r <= 0)
-		return v;
-	v += r - 1;
-	c = v % r;
-	if(c < 0)
-		c += r;
-	v -= c;
-	return v;
-}
-
-void
-import(void)
-{
-	int i;
-	Sym *s;
-
-	for(i = 0; i < NHASH; i++)
-		for(s = hash[i]; s != S; s = s->link)
-			if(s->sig != 0 && s->type == SXREF && (nimports == 0 || s->subtype == SIMPORT)){
-				undefsym(s);
-				Bprint(&bso, "IMPORT: %s sig=%lux v=%ld\n", s->name, s->sig, s->value);
-			}
-}
-
-void
-ckoff(Sym *s, int32_t v)
-{
-	if(v < 0 || v >= 1<<Roffset)
-		diag("relocation offset %ld for %s out of range", v, s->name);
-}
-
-static Prog*
-newdata(Sym *s, int o, int w, int t)
-{
-	Prog *p;
-
-	p = prg();
-	p->link = datap;
-	datap = p;
-	p->as = ADATA;
-	p->reg = w;
-	p->from.type = D_OREG;
-	p->from.name = t;
-	p->from.sym = s;
-	p->from.offset = o;
-	p->to.type = D_CONST;
-	p->to.name = D_NONE;
-	return p;
-}
-
-void
-export(void)
-{
-	int i, j, n, off, nb, sv, ne;
-	Sym *s, *et, *str, **esyms;
-	Prog *p;
-	char buf[NSNAME], *t;
-
-	n = 0;
-	for(i = 0; i < NHASH; i++)
-		for(s = hash[i]; s != S; s = s->link)
-			if(s->sig != 0 && s->type != SXREF && s->type != SUNDEF && (nexports == 0 || s->subtype == SEXPORT))
-				n++;
-	esyms = malloc(n*sizeof(Sym*));
-	ne = n;
-	n = 0;
-	for(i = 0; i < NHASH; i++)
-		for(s = hash[i]; s != S; s = s->link)
-			if(s->sig != 0 && s->type != SXREF && s->type != SUNDEF && (nexports == 0 || s->subtype == SEXPORT))
-				esyms[n++] = s;
-	for(i = 0; i < ne-1; i++)
-		for(j = i+1; j < ne; j++)
-			if(strcmp(esyms[i]->name, esyms[j]->name) > 0){
-				s = esyms[i];
-				esyms[i] = esyms[j];
-				esyms[j] = s;
-			}
-
-	nb = 0;
-	off = 0;
-	et = lookup(EXPTAB, 0);
-	if(et->type != 0 && et->type != SXREF)
-		diag("%s already defined", EXPTAB);
-	et->type = SDATA;
-	str = lookup(".string", 0);
-	if(str->type == 0)
-		str->type = SDATA;
-	sv = str->value;
-	for(i = 0; i < ne; i++){
-		s = esyms[i];
-		Bprint(&bso, "EXPORT: %s sig=%lux t=%d\n", s->name, s->sig, s->type);
-
-		/* signature */
-		p = newdata(et, off, sizeof(int32_t), D_EXTERN);
-		off += sizeof(int32_t);
-		p->to.offset = s->sig;
-
-		/* address */
-		p = newdata(et, off, sizeof(int32_t), D_EXTERN);
-		off += sizeof(int32_t);
-		p->to.name = D_EXTERN;
-		p->to.sym = s;
-
-		/* string */
-		t = s->name;
-		n = strlen(t)+1;
-		for(;;){
-			buf[nb++] = *t;
-			sv++;
-			if(nb >= NSNAME){
-				p = newdata(str, sv-NSNAME, NSNAME, D_STATIC);
-				p->to.type = D_SCONST;
-				p->to.sval = malloc(NSNAME);
-				memmove(p->to.sval, buf, NSNAME);
-				nb = 0;
-			}
-			if(*t++ == 0)
-				break;
-		}
-
-		/* name */
-		p = newdata(et, off, sizeof(int32_t), D_EXTERN);
-		off += sizeof(int32_t);
-		p->to.name = D_STATIC;
-		p->to.sym = str;
-		p->to.offset = sv-n;
-	}
-
-	if(nb > 0){
-		p = newdata(str, sv-nb, nb, D_STATIC);
-		p->to.type = D_SCONST;
-		p->to.sval = malloc(NSNAME);
-		memmove(p->to.sval, buf, nb);
-	}
-
-	for(i = 0; i < 3; i++){
-		newdata(et, off, sizeof(int32_t), D_EXTERN);
-		off += sizeof(int32_t);
-	}
-	et->value = off;
-	if(sv == 0)
-		sv = 1;
-	str->value = sv;
-	exports = ne;
-	free(esyms);
-}

+ 0 - 996
sys/src/cmd/5l/span.c

@@ -1,996 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include	"l.h"
-
-static struct {
-	uint32_t	start;
-	uint32_t	size;
-} pool;
-
-void	checkpool(Prog*);
-void 	flushpool(Prog*, int);
-
-void
-span(void)
-{
-	Prog *p;
-	Sym *setext, *s;
-	Optab *o;
-	int m, bflag, i;
-	int32_t c, otxt, v;
-
-	if(debug['v'])
-		Bprint(&bso, "%5.2f span\n", cputime());
-	Bflush(&bso);
-
-	bflag = 0;
-	c = INITTEXT;
-	otxt = c;
-	for(p = firstp; p != P; p = p->link) {
-		p->pc = c;
-		o = oplook(p);
-		m = o->size;
-		if(m == 0) {
-			if(p->as == ATEXT) {
-				curtext = p;
-				autosize = p->to.offset + 4;
-				if(p->from.sym != S)
-					p->from.sym->value = c;
-				/* need passes to resolve branches */
-				if(c-otxt >= 1L<<17)
-					bflag = 1;
-				otxt = c;
-				continue;
-			}
-			diag("zero-width instruction\n%P", p);
-			continue;
-		}
-		switch(o->flag & (LFROM|LTO|LPOOL)) {
-		case LFROM:
-			addpool(p, &p->from);
-			break;
-		case LTO:
-			addpool(p, &p->to);
-			break;
-		case LPOOL:
-			if ((p->scond&C_SCOND) == 14)
-				flushpool(p, 0);
-			break;
-		}
-		if(p->as==AMOVW && p->to.type==D_REG && p->to.reg==REGPC && (p->scond&C_SCOND) == 14)
-			flushpool(p, 0);
-		c += m;
-		if(blitrl)
-			checkpool(p);
-	}
-
-	/*
-	 * if any procedure is large enough to
-	 * generate a large SBRA branch, then
-	 * generate extra passes putting branches
-	 * around jmps to fix. this is rare.
-	 */
-	while(bflag) {
-		if(debug['v'])
-			Bprint(&bso, "%5.2f span1\n", cputime());
-		bflag = 0;
-		c = INITTEXT;
-		for(p = firstp; p != P; p = p->link) {
-			p->pc = c;
-			o = oplook(p);
-/* very larg branches
-			if(o->type == 6 && p->cond) {
-				otxt = p->cond->pc - c;
-				if(otxt < 0)
-					otxt = -otxt;
-				if(otxt >= (1L<<17) - 10) {
-					q = prg();
-					q->link = p->link;
-					p->link = q;
-					q->as = AB;
-					q->to.type = D_BRANCH;
-					q->cond = p->cond;
-					p->cond = q;
-					q = prg();
-					q->link = p->link;
-					p->link = q;
-					q->as = AB;
-					q->to.type = D_BRANCH;
-					q->cond = q->link->link;
-					bflag = 1;
-				}
-			}
- */
-			m = o->size;
-			if(m == 0) {
-				if(p->as == ATEXT) {
-					curtext = p;
-					autosize = p->to.offset + 4;
-					if(p->from.sym != S)
-						p->from.sym->value = c;
-					continue;
-				}
-				diag("zero-width instruction\n%P", p);
-				continue;
-			}
-			c += m;
-		}
-	}
-
-	if(debug['t']) {
-		/* 
-		 * add strings to text segment
-		 */
-		c = rnd(c, 8);
-		for(i=0; i<NHASH; i++)
-		for(s = hash[i]; s != S; s = s->link) {
-			if(s->type != SSTRING)
-				continue;
-			v = s->value;
-			while(v & 3)
-				v++;
-			s->value = c;
-			c += v;
-		}
-	}
-
-	c = rnd(c, 8);
-
-	setext = lookup("etext", 0);
-	if(setext != S) {
-		setext->value = c;
-		textsize = c - INITTEXT;
-	}
-	if(INITRND)
-		INITDAT = rnd(c, INITRND);
-	if(debug['v'])
-		Bprint(&bso, "tsize = %lux\n", textsize);
-	Bflush(&bso);
-}
-
-/*
- * when the first reference to the literal pool threatens
- * to go out of range of a 12-bit PC-relative offset,
- * drop the pool now, and branch round it.
- * this happens only in extended basic blocks that exceed 4k.
- */
-void
-checkpool(Prog *p)
-{
-	if(pool.size >= 0xffc || immaddr((p->pc+4)+4+pool.size - pool.start+8) == 0)
-		flushpool(p, 1);
-	else if(p->link == P)
-		flushpool(p, 2);
-}
-
-void
-flushpool(Prog *p, int skip)
-{
-	Prog *q;
-
-	if(blitrl) {
-		if(skip){
-			if(debug['v'] && skip == 1)
-				print("note: flush literal pool at %lux: len=%lud ref=%lux\n", p->pc+4, pool.size, pool.start);
-			q = prg();
-			q->as = AB;
-			q->to.type = D_BRANCH;
-			q->cond = p->link;
-			q->link = blitrl;
-			blitrl = q;
-		}
-		else if(p->pc+pool.size-pool.start < 2048)
-			return;
-		elitrl->link = p->link;
-		p->link = blitrl;
-		blitrl = 0;	/* BUG: should refer back to values until out-of-range */
-		elitrl = 0;
-		pool.size = 0;
-		pool.start = 0;
-	}
-}
-
-void
-addpool(Prog *p, Adr *a)
-{
-	Prog *q, t;
-	int c;
-
-	c = aclass(a);
-
-	t = zprg;
-	t.as = AWORD;
-
-	switch(c) {
-	default:
-		t.to = *a;
-		break;
-
-	case C_SROREG:
-	case C_LOREG:
-	case C_ROREG:
-	case C_FOREG:
-	case C_SOREG:
-	case C_FAUTO:
-	case C_SAUTO:
-	case C_LAUTO:
-	case C_LACON:
-		t.to.type = D_CONST;
-		t.to.offset = instoffset;
-		break;
-	}
-
-	for(q = blitrl; q != P; q = q->link)	/* could hash on t.t0.offset */
-		if(memcmp(&q->to, &t.to, sizeof(t.to)) == 0) {
-			p->cond = q;
-			return;
-		}
-
-	q = prg();
-	*q = t;
-	q->pc = pool.size;
-
-	if(blitrl == P) {
-		blitrl = q;
-		pool.start = p->pc;
-	} else
-		elitrl->link = q;
-	elitrl = q;
-	pool.size += 4;
-
-	p->cond = q;
-}
-
-void
-xdefine(char *p, int t, int32_t v)
-{
-	Sym *s;
-
-	s = lookup(p, 0);
-	if(s->type == 0 || s->type == SXREF) {
-		s->type = t;
-		s->value = v;
-	}
-}
-
-int32_t
-regoff(Adr *a)
-{
-
-	instoffset = 0;
-	aclass(a);
-	return instoffset;
-}
-
-int32_t
-immrot(uint32_t v)
-{
-	int i;
-
-	for(i=0; i<16; i++) {
-		if((v & ~0xff) == 0)
-			return (i<<8) | v | (1<<25);
-		v = (v<<2) | (v>>30);
-	}
-	return 0;
-}
-
-int32_t
-immaddr(int32_t v)
-{
-	if(v >= 0 && v <= 0xfff)
-		return (v & 0xfff) |
-			(1<<24) |	/* pre indexing */
-			(1<<23);	/* pre indexing, up */
-	if(v >= -0xfff && v < 0)
-		return (-v & 0xfff) |
-			(1<<24);	/* pre indexing */
-	return 0;
-}
-
-int
-immfloat(int32_t v)
-{
-	return (v & 0xC03) == 0;	/* offset will fit in floating-point load/store */
-}
-
-int
-immhalf(int32_t v)
-{
-	if(v >= 0 && v <= 0xff)
-		return v|
-			(1<<24)|	/* pre indexing */
-			(1<<23);	/* pre indexing, up */
-	if(v >= -0xff && v < 0)
-		return (-v & 0xff)|
-			(1<<24);	/* pre indexing */
-	return 0;
-}
-
-int
-aclass(Adr *a)
-{
-	Sym *s;
-	int t;
-
-	switch(a->type) {
-	case D_NONE:
-		return C_NONE;
-
-	case D_REG:
-		return C_REG;
-
-	case D_REGREG:
-		return C_REGREG;
-
-	case D_SHIFT:
-		return C_SHIFT;
-
-	case D_FREG:
-		return C_FREG;
-
-	case D_FPCR:
-		return C_FCR;
-
-	case D_OREG:
-		switch(a->name) {
-		case D_EXTERN:
-		case D_STATIC:
-			if(a->sym == 0 || a->sym->name == 0) {
-				print("null sym external\n");
-				print("%D\n", a);
-				return C_GOK;
-			}
-			s = a->sym;
-			t = s->type;
-			if(t == 0 || t == SXREF) {
-				diag("undefined external: %s in %s",
-					s->name, TNAME);
-				s->type = SDATA;
-			}
-			if(dlm) {
-				switch(t) {
-				default:
-					instoffset = s->value + a->offset + INITDAT;
-					break;
-				case SUNDEF:
-				case STEXT:
-				case SCONST:
-				case SLEAF:
-				case SSTRING:
-					instoffset = s->value + a->offset;
-					break;
-				}
-				return C_ADDR;
-			}
-			instoffset = s->value + a->offset - BIG;
-			t = immaddr(instoffset);
-			if(t) {
-				if(immhalf(instoffset))
-					return immfloat(t) ? C_HFEXT : C_HEXT;
-				if(immfloat(t))
-					return C_FEXT;
-				return C_SEXT;
-			}
-			return C_LEXT;
-		case D_AUTO:
-			instoffset = autosize + a->offset;
-			t = immaddr(instoffset);
-			if(t){
-				if(immhalf(instoffset))
-					return immfloat(t) ? C_HFAUTO : C_HAUTO;
-				if(immfloat(t))
-					return C_FAUTO;
-				return C_SAUTO;
-			}
-			return C_LAUTO;
-
-		case D_PARAM:
-			instoffset = autosize + a->offset + 4L;
-			t = immaddr(instoffset);
-			if(t){
-				if(immhalf(instoffset))
-					return immfloat(t) ? C_HFAUTO : C_HAUTO;
-				if(immfloat(t))
-					return C_FAUTO;
-				return C_SAUTO;
-			}
-			return C_LAUTO;
-		case D_NONE:
-			instoffset = a->offset;
-			t = immaddr(instoffset);
-			if(t) {
-				if(immhalf(instoffset))		 /* n.b. that it will also satisfy immrot */
-					return immfloat(t) ? C_HFOREG : C_HOREG;
-				if(immfloat(t))
-					return C_FOREG; /* n.b. that it will also satisfy immrot */
-				t = immrot(instoffset);
-				if(t)
-					return C_SROREG;
-				if(immhalf(instoffset))
-					return C_HOREG;
-				return C_SOREG;
-			}
-			t = immrot(instoffset);
-			if(t)
-				return C_ROREG;
-			return C_LOREG;
-		}
-		return C_GOK;
-
-	case D_PSR:
-		return C_PSR;
-
-	case D_OCONST:
-		switch(a->name) {
-		case D_EXTERN:
-		case D_STATIC:
-			s = a->sym;
-			t = s->type;
-			if(t == 0 || t == SXREF) {
-				diag("undefined external: %s in %s",
-					s->name, TNAME);
-				s->type = SDATA;
-			}
-			instoffset = s->value + a->offset + INITDAT;
-			if(s->type == STEXT || s->type == SLEAF || s->type == SUNDEF)
-				instoffset = s->value + a->offset;
-			return C_LCON;
-		}
-		return C_GOK;
-
-	case D_FCONST:
-		return C_FCON;
-
-	case D_CONST:
-		switch(a->name) {
-
-		case D_NONE:
-			instoffset = a->offset;
-			if(a->reg != NREG)
-				goto aconsize;
-
-			t = immrot(instoffset);
-			if(t)
-				return C_RCON;
-			t = immrot(~instoffset);
-			if(t)
-				return C_NCON;
-			return C_LCON;
-
-		case D_EXTERN:
-		case D_STATIC:
-			s = a->sym;
-			if(s == S)
-				break;
-			t = s->type;
-			switch(t) {
-			case 0:
-			case SXREF:
-				diag("undefined external: %s in %s",
-					s->name, TNAME);
-				s->type = SDATA;
-				break;
-			case SUNDEF:
-			case STEXT:
-			case SSTRING:
-			case SCONST:
-			case SLEAF:
-				instoffset = s->value + a->offset;
-				return C_LCON;
-			}
-			if(!dlm) {
-				instoffset = s->value + a->offset - BIG;
-				t = immrot(instoffset);
-				if(t && instoffset != 0)
-					return C_RECON;
-			}
-			instoffset = s->value + a->offset + INITDAT;
-			return C_LCON;
-
-		case D_AUTO:
-			instoffset = autosize + a->offset;
-			goto aconsize;
-
-		case D_PARAM:
-			instoffset = autosize + a->offset + 4L;
-		aconsize:
-			t = immrot(instoffset);
-			if(t)
-				return C_RACON;
-			return C_LACON;
-		}
-		return C_GOK;
-
-	case D_BRANCH:
-		return C_SBRA;
-	}
-	return C_GOK;
-}
-
-Optab*
-oplook(Prog *p)
-{
-	int a1, a2, a3, r;
-	char *c1, *c3;
-	Optab *o, *e;
-
-	a1 = p->optab;
-	if(a1)
-		return optab+(a1-1);
-	a1 = p->from.class;
-	if(a1 == 0) {
-		a1 = aclass(&p->from) + 1;
-		p->from.class = a1;
-	}
-	a1--;
-	a3 = p->to.class;
-	if(a3 == 0) {
-		a3 = aclass(&p->to) + 1;
-		p->to.class = a3;
-	}
-	a3--;
-	a2 = C_NONE;
-	if(p->reg != NREG)
-		a2 = C_REG;
-	r = p->as;
-	o = oprange[r].start;
-	if(o == 0) {
-		a1 = opcross[repop[r]][a1][a2][a3];
-		if(a1) {
-			p->optab = a1+1;
-			return optab+a1;
-		}
-		o = oprange[r].stop; /* just generate an error */
-	}
-	if(0) {
-		print("oplook %A %d %d %d\n",
-			(int)p->as, a1, a2, a3);
-		print("		%d %d\n", p->from.type, p->to.type);
-	}
-	e = oprange[r].stop;
-	c1 = xcmp[a1];
-	c3 = xcmp[a3];
-	for(; o<e; o++)
-		if(o->a2 == a2)
-		if(c1[o->a1])
-		if(c3[o->a3]) {
-			p->optab = (o-optab)+1;
-			return o;
-		}
-	diag("illegal combination %A %d %d %d",
-		p->as, a1, a2, a3);
-	prasm(p);
-	if(o == 0)
-		o = optab;
-	return o;
-}
-
-int
-cmp(int a, int b)
-{
-
-	if(a == b)
-		return 1;
-	switch(a) {
-	case C_LCON:
-		if(b == C_RCON || b == C_NCON)
-			return 1;
-		break;
-	case C_LACON:
-		if(b == C_RACON)
-			return 1;
-		break;
-	case C_LECON:
-		if(b == C_RECON)
-			return 1;
-		break;
-
-	case C_HFEXT:
-		return b == C_HEXT || b == C_FEXT;
-	case C_FEXT:
-	case C_HEXT:
-		return b == C_HFEXT;
-	case C_SEXT:
-		return cmp(C_HFEXT, b);
-	case C_LEXT:
-		return cmp(C_SEXT, b);
-
-	case C_HFAUTO:
-		return b == C_HAUTO || b == C_FAUTO;
-	case C_FAUTO:
-	case C_HAUTO:
-		return b == C_HFAUTO;
-	case C_SAUTO:
-		return cmp(C_HFAUTO, b);
-	case C_LAUTO:
-		return cmp(C_SAUTO, b);
-
-	case C_HFOREG:
-		return b == C_HOREG || b == C_FOREG;
-	case C_FOREG:
-	case C_HOREG:
-		return b == C_HFOREG;
-	case C_SROREG:
-		return cmp(C_SOREG, b) || cmp(C_ROREG, b);
-	case C_SOREG:
-	case C_ROREG:
-		return b == C_SROREG || cmp(C_HFOREG, b);
-	case C_LOREG:
-		return cmp(C_SROREG, b);
-
-	case C_LBRA:
-		if(b == C_SBRA)
-			return 1;
-		break;
-	}
-	return 0;
-}
-
-int
-ocmp(const void *a1, const void *a2)
-{
-	Optab *p1, *p2;
-	int n;
-
-	p1 = (Optab*)a1;
-	p2 = (Optab*)a2;
-	n = p1->as - p2->as;
-	if(n)
-		return n;
-	n = (p2->flag&V4) - (p1->flag&V4);	/* architecture version */
-	if(n)
-		return n;
-	n = (p2->flag&VFP) - (p1->flag&VFP);	/* floating point arch */
-	if(n)
-		return n;
-	n = p1->a1 - p2->a1;
-	if(n)
-		return n;
-	n = p1->a2 - p2->a2;
-	if(n)
-		return n;
-	n = p1->a3 - p2->a3;
-	if(n)
-		return n;
-	return 0;
-}
-
-void
-buildop(void)
-{
-	int i, n, r;
-
-	armv4 = !debug['h'];
-	vfp = debug['f'];
-	for(i=0; i<C_GOK; i++)
-		for(n=0; n<C_GOK; n++)
-			xcmp[i][n] = cmp(n, i);
-	for(n=0; optab[n].as != AXXX; n++) {
-		if((optab[n].flag & VFP) && !vfp)
-			optab[n].as = AXXX;
-		if((optab[n].flag & V4) && !armv4) {
-			optab[n].as = AXXX;
-			break;
-		}
-	}
-	qsort(optab, n, sizeof(optab[0]), ocmp);
-	for(i=0; i<n; i++) {
-		r = optab[i].as;
-		oprange[r].start = optab+i;
-		while(optab[i].as == r)
-			i++;
-		oprange[r].stop = optab+i;
-		i--;
-
-		switch(r)
-		{
-		default:
-			diag("unknown op in build: %A", r);
-			errorexit();
-		case AXXX:
-			break;
-		case AADD:
-			oprange[AAND] = oprange[r];
-			oprange[AEOR] = oprange[r];
-			oprange[ASUB] = oprange[r];
-			oprange[ARSB] = oprange[r];
-			oprange[AADC] = oprange[r];
-			oprange[ASBC] = oprange[r];
-			oprange[ARSC] = oprange[r];
-			oprange[AORR] = oprange[r];
-			oprange[ABIC] = oprange[r];
-			break;
-		case ACMP:
-			oprange[ATST] = oprange[r];
-			oprange[ATEQ] = oprange[r];
-			oprange[ACMN] = oprange[r];
-			break;
-		case AMVN:
-			break;
-		case ABEQ:
-			oprange[ABNE] = oprange[r];
-			oprange[ABCS] = oprange[r];
-			oprange[ABHS] = oprange[r];
-			oprange[ABCC] = oprange[r];
-			oprange[ABLO] = oprange[r];
-			oprange[ABMI] = oprange[r];
-			oprange[ABPL] = oprange[r];
-			oprange[ABVS] = oprange[r];
-			oprange[ABVC] = oprange[r];
-			oprange[ABHI] = oprange[r];
-			oprange[ABLS] = oprange[r];
-			oprange[ABGE] = oprange[r];
-			oprange[ABLT] = oprange[r];
-			oprange[ABGT] = oprange[r];
-			oprange[ABLE] = oprange[r];
-			break;
-		case ASLL:
-			oprange[ASRL] = oprange[r];
-			oprange[ASRA] = oprange[r];
-			break;
-		case AMUL:
-			oprange[AMULU] = oprange[r];
-			break;
-		case ADIV:
-			oprange[AMOD] = oprange[r];
-			oprange[AMODU] = oprange[r];
-			oprange[ADIVU] = oprange[r];
-			break;
-		case AMOVW:
-		case AMOVB:
-		case AMOVBU:
-		case AMOVH:
-		case AMOVHU:
-			break;
-		case ASWPW:
-			oprange[ASWPBU] = oprange[r];
-			break;
-		case AB:
-		case ABL:
-		case ABX:
-		case ABXRET:
-		case ASWI:
-		case AWORD:
-		case AMOVM:
-		case ARFE:
-		case ATEXT:
-		case ACASE:
-		case ABCASE:
-			break;
-		case AADDF:
-			oprange[AADDD] = oprange[r];
-			oprange[ASUBF] = oprange[r];
-			oprange[ASUBD] = oprange[r];
-			oprange[AMULF] = oprange[r];
-			oprange[AMULD] = oprange[r];
-			oprange[ADIVF] = oprange[r];
-			oprange[ADIVD] = oprange[r];
-			oprange[AMOVFD] = oprange[r];
-			oprange[AMOVDF] = oprange[r];
-			break;
-			
-		case ACMPF:
-			oprange[ACMPD] = oprange[r];
-			break;
-
-		case AMOVF:
-			oprange[AMOVD] = oprange[r];
-			break;
-
-		case AMOVFW:
-			oprange[AMOVWF] = oprange[r];
-			oprange[AMOVWD] = oprange[r];
-			oprange[AMOVDW] = oprange[r];
-			break;
-
-		case AMULL:
-			oprange[AMULA] = oprange[r];
-			oprange[AMULAL] = oprange[r];
-			oprange[AMULLU] = oprange[r];
-			oprange[AMULALU] = oprange[r];
-			break;
-		}
-	}
-}
-
-/*
-void
-buildrep(int x, int as)
-{
-	Opcross *p;
-	Optab *e, *s, *o;
-	int a1, a2, a3, n;
-
-	if(C_NONE != 0 || C_REG != 1 || C_GOK >= 32 || x >= nelem(opcross)) {
-		diag("assumptions fail in buildrep");
-		errorexit();
-	}
-	repop[as] = x;
-	p = (opcross + x);
-	s = oprange[as].start;
-	e = oprange[as].stop;
-	for(o=e-1; o>=s; o--) {
-		n = o-optab;
-		for(a2=0; a2<2; a2++) {
-			if(a2) {
-				if(o->a2 == C_NONE)
-					continue;
-			} else
-				if(o->a2 != C_NONE)
-					continue;
-			for(a1=0; a1<32; a1++) {
-				if(!xcmp[a1][o->a1])
-					continue;
-				for(a3=0; a3<32; a3++)
-					if(xcmp[a3][o->a3])
-						(*p)[a1][a2][a3] = n;
-			}
-		}
-	}
-	oprange[as].start = 0;
-}
-*/
-
-enum{
-	ABSD = 0,
-	ABSU = 1,
-	RELD = 2,
-	RELU = 3,
-};
-
-int modemap[4] = { 0, 1, -1, 2, };
-
-typedef struct Reloc Reloc;
-
-struct Reloc
-{
-	int n;
-	int t;
-	uint8_t *m;
-	uint32_t *a;
-};
-
-Reloc rels;
-
-static void
-grow(Reloc *r)
-{
-	int t;
-	uint8_t *m, *nm;
-	uint32_t *a, *na;
-
-	t = r->t;
-	r->t += 64;
-	m = r->m;
-	a = r->a;
-	r->m = nm = malloc(r->t*sizeof(uint8_t));
-	r->a = na = malloc(r->t*sizeof(uint32_t));
-	memmove(nm, m, t*sizeof(uint8_t));
-	memmove(na, a, t*sizeof(uint32_t));
-	free(m);
-	free(a);
-}
-
-void
-dynreloc(Sym *s, int32_t v, int abs)
-{
-	int i, k, n;
-	uint8_t *m;
-	uint32_t *a;
-	Reloc *r;
-
-	if(v&3)
-		diag("bad relocation address");
-	v >>= 2;
-	if(s != S && s->type == SUNDEF)
-		k = abs ? ABSU : RELU;
-	else
-		k = abs ? ABSD : RELD;
-	/* Bprint(&bso, "R %s a=%ld(%lx) %d\n", s->name, a, a, k); */
-	k = modemap[k];
-	r = &rels;
-	n = r->n;
-	if(n >= r->t)
-		grow(r);
-	m = r->m;
-	a = r->a;
-	for(i = n; i > 0; i--){
-		if(v < a[i-1]){	/* happens occasionally for data */
-			m[i] = m[i-1];
-			a[i] = a[i-1];
-		}
-		else
-			break;
-	}
-	m[i] = k;
-	a[i] = v;
-	r->n++;
-}
-
-static int
-sput(char *s)
-{
-	char *p;
-
-	p = s;
-	while(*s)
-		cput(*s++);
-	cput(0);
-	return  s-p+1;
-}
-
-void
-asmdyn()
-{
-	int i, n, t, c;
-	Sym *s;
-	uint32_t la, ra, *a;
-	int64_t off;
-	uint8_t *m;
-	Reloc *r;
-
-	cflush();
-	off = seek(cout, 0, 1);
-	lput(0);
-	t = 0;
-	lput(imports);
-	t += 4;
-	for(i = 0; i < NHASH; i++)
-		for(s = hash[i]; s != S; s = s->link)
-			if(s->type == SUNDEF){
-				lput(s->sig);
-				t += 4;
-				t += sput(s->name);
-			}
-	
-	la = 0;
-	r = &rels;
-	n = r->n;
-	m = r->m;
-	a = r->a;
-	lput(n);
-	t += 4;
-	for(i = 0; i < n; i++){
-		ra = *a-la;
-		if(*a < la)
-			diag("bad relocation order");
-		if(ra < 256)
-			c = 0;
-		else if(ra < 65536)
-			c = 1;
-		else
-			c = 2;
-		cput((c<<6)|*m++);
-		t++;
-		if(c == 0){
-			cput(ra);
-			t++;
-		}
-		else if(c == 1){
-			wput(ra);
-			t += 2;
-		}
-		else{
-			lput(ra);
-			t += 4;
-		}
-		la = *a++;
-	}
-
-	cflush();
-	seek(cout, off, 0);
-	lput(t);
-
-	if(debug['v']){
-		Bprint(&bso, "import table entries = %d\n", imports);
-		Bprint(&bso, "export table entries = %d\n", exports);
-	}
-}

+ 0 - 204
sys/src/cmd/6a/a.h

@@ -1,204 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <bio.h>
-#include "../6c/6.out.h"
-
-
-#ifndef	EXTERN
-#define	EXTERN	extern
-#endif
-
-typedef	struct	Sym	Sym;
-typedef	struct	Ref	Ref;
-typedef	struct	Gen	Gen;
-typedef	struct	Io	Io;
-typedef	struct	Hist	Hist;
-typedef	struct	Gen2 	Gen2;
-
-#define	MAXALIGN	7
-#define	FPCHIP		1
-#define	NSYMB		500
-#define	BUFSIZ		8192
-#define	HISTSZ		20
-#define	NINCLUDE	10
-#define	NHUNK		10000
-#define	EOF		(-1)
-#define	IGN		(-2)
-#define	GETC()		((--fi.c < 0)? filbuf(): *fi.p++ & 0xff)
-#define	NHASH		503
-#define	STRINGSZ	200
-#define	NMACRO		10
-
-struct	Sym
-{
-	Sym*	link;
-	Ref*	ref;
-	char*	macro;
-	vlong	value;
-	ushort	type;
-	char	*name;
-	char	sym;
-};
-#define	S	((Sym*)0)
-
-struct	Ref
-{
-	int	class;
-};
-
-EXTERN struct
-{
-	char*	p;
-	int	c;
-} fi;
-
-struct	Io
-{
-	Io*	link;
-	char	b[BUFSIZ];
-	char*	p;
-	short	c;
-	short	f;
-};
-#define	I	((Io*)0)
-
-EXTERN struct
-{
-	Sym*	sym;
-	short	type;
-} h[NSYM];
-
-struct	Gen
-{
-	double	dval;
-	char	sval[8];
-	vlong	offset;
-	Sym*	sym;
-	short	type;
-	short	index;
-	short	scale;
-};
-struct	Gen2
-{
-	Gen	from;
-	Gen	to;
-};
-
-struct	Hist
-{
-	Hist*	link;
-	char*	name;
-	long	line;
-	vlong	offset;
-};
-#define	H	((Hist*)0)
-
-enum
-{
-	CLAST,
-	CMACARG,
-	CMACRO,
-	CPREPROC,
-};
-
-
-EXTERN	char	debug[256];
-EXTERN	Sym*	hash[NHASH];
-EXTERN	char*	Dlist[30];
-EXTERN	int	nDlist;
-EXTERN	Hist*	ehist;
-EXTERN	int	newflag;
-EXTERN	Hist*	hist;
-EXTERN	char*	hunk;
-EXTERN	char*	include[NINCLUDE];
-EXTERN	Io*	iofree;
-EXTERN	Io*	ionext;
-EXTERN	Io*	iostack;
-EXTERN	long	lineno;
-EXTERN	int	nerrors;
-EXTERN	long	nhunk;
-EXTERN	int	ninclude;
-EXTERN	Gen	nullgen;
-EXTERN	char*	outfile;
-EXTERN	int	pass;
-EXTERN	char*	pathname;
-EXTERN	long	pc;
-EXTERN	int	peekc;
-EXTERN	int	sym;
-EXTERN	char	symb[NSYMB];
-EXTERN	int	thechar;
-EXTERN	char*	thestring;
-EXTERN	long	thunk;
-EXTERN	Biobuf	obuf;
-
-void*	allocn(void*, long, long);
-void	errorexit(void);
-void	pushio(void);
-void	newio(void);
-void	newfile(char*, int);
-Sym*	slookup(char*);
-Sym*	lookup(void);
-void	syminit(Sym*);
-long	yylex(void);
-int	getc(void);
-int	getnsc(void);
-void	unget(int);
-int	escchar(int);
-void	cinit(void);
-void	checkscale(int);
-void	pinit(char*);
-void	cclean(void);
-int	isreg(Gen*);
-void	outcode(int, Gen2*);
-void	outhist(void);
-void	zaddr(Gen*, int);
-void	zname(char*, int, int);
-void	ieeedtod(Ieee*, double);
-int	filbuf(void);
-Sym*	getsym(void);
-void	domacro(void);
-void	macund(void);
-void	macdef(void);
-void	macexpand(Sym*, char*);
-void	macinc(void);
-void	macprag(void);
-void	maclin(void);
-void	macif(int);
-void	macend(void);
-void	dodefine(char*);
-void	prfile(long);
-void	linehist(char*, int);
-void	gethunk(void);
-void	yyerror(char*, ...);
-int	yyparse(void);
-void	setinclude(char*);
-int	assemble(char*);
-
-/*
- *	Posix.c/Inferno.c/Nt.c
- */
-enum	/* keep in synch with ../cc/cc.h */
-{
-	Plan9	= 1<<0,
-	Unix	= 1<<1,
-	Windows	= 1<<2
-};
-int	mywait(int*);
-int	mycreat(char*, int);
-int	systemtype(int);
-int	pathchar(void);
-char*	mygetwd(char*, int);
-int	myexec(char*, char*[]);
-int	mydup(int, int);
-int	myfork(void);
-int	mypipe(int*);
-void*	mysbrk(ulong);

+ 0 - 562
sys/src/cmd/6a/a.y

@@ -1,562 +0,0 @@
-%{
-#include "a.h"
-%}
-%union	{
-	Sym	*sym;
-	vlong	lval;
-	double	dval;
-	char	sval[8];
-	Gen	gen;
-	Gen2	gen2;
-}
-%left	'|'
-%left	'^'
-%left	'&'
-%left	'<' '>'
-%left	'+' '-'
-%left	'*' '/' '%'
-%token	<lval>	LTYPE0 LTYPE1 LTYPE2 LTYPE3 LTYPE4
-%token	<lval>	LTYPEC LTYPED LTYPEN LTYPER LTYPET LTYPES LTYPEM LTYPEI LTYPEXC LTYPEX LTYPERT
-%token	<lval>	LCONST LFP LPC LSB
-%token	<lval>	LBREG LLREG LSREG LFREG LMREG LXREG
-%token	<dval>	LFCONST
-%token	<sval>	LSCONST LSP
-%token	<sym>	LNAME LLAB LVAR
-%type	<lval>	con expr pointer offset
-%type	<gen>	mem imm reg nam rel rem rim rom omem nmem
-%type	<gen2>	nonnon nonrel nonrem rimnon rimrem remrim spec10
-%type	<gen2>	spec1 spec2 spec3 spec4 spec5 spec6 spec7 spec8 spec9
-%%
-prog:
-|	prog line
-
-line:
-	LLAB ':'
-	{
-		if($1->value != pc)
-			yyerror("redeclaration of %s", $1->name);
-		$1->value = pc;
-	}
-	line
-|	LNAME ':'
-	{
-		$1->type = LLAB;
-		$1->value = pc;
-	}
-	line
-|	';'
-|	inst ';'
-|	error ';'
-
-inst:
-	LNAME '=' expr
-	{
-		$1->type = LVAR;
-		$1->value = $3;
-	}
-|	LVAR '=' expr
-	{
-		if($1->value != $3)
-			yyerror("redeclaration of %s", $1->name);
-		$1->value = $3;
-	}
-|	LTYPE0 nonnon	{ outcode($1, &$2); }
-|	LTYPE1 nonrem	{ outcode($1, &$2); }
-|	LTYPE2 rimnon	{ outcode($1, &$2); }
-|	LTYPE3 rimrem	{ outcode($1, &$2); }
-|	LTYPE4 remrim	{ outcode($1, &$2); }
-|	LTYPER nonrel	{ outcode($1, &$2); }
-|	LTYPED spec1	{ outcode($1, &$2); }
-|	LTYPET spec2	{ outcode($1, &$2); }
-|	LTYPEC spec3	{ outcode($1, &$2); }
-|	LTYPEN spec4	{ outcode($1, &$2); }
-|	LTYPES spec5	{ outcode($1, &$2); }
-|	LTYPEM spec6	{ outcode($1, &$2); }
-|	LTYPEI spec7	{ outcode($1, &$2); }
-|	LTYPEXC spec8	{ outcode($1, &$2); }
-|	LTYPEX spec9	{ outcode($1, &$2); }
-|	LTYPERT spec10	{ outcode($1, &$2); }
-
-nonnon:
-	{
-		$$.from = nullgen;
-		$$.to = nullgen;
-	}
-|	','
-	{
-		$$.from = nullgen;
-		$$.to = nullgen;
-	}
-
-rimrem:
-	rim ',' rem
-	{
-		$$.from = $1;
-		$$.to = $3;
-	}
-
-remrim:
-	rem ',' rim
-	{
-		$$.from = $1;
-		$$.to = $3;
-	}
-
-rimnon:
-	rim ','
-	{
-		$$.from = $1;
-		$$.to = nullgen;
-	}
-|	rim
-	{
-		$$.from = $1;
-		$$.to = nullgen;
-	}
-
-nonrem:
-	',' rem
-	{
-		$$.from = nullgen;
-		$$.to = $2;
-	}
-|	rem
-	{
-		$$.from = nullgen;
-		$$.to = $1;
-	}
-
-nonrel:
-	',' rel
-	{
-		$$.from = nullgen;
-		$$.to = $2;
-	}
-|	rel
-	{
-		$$.from = nullgen;
-		$$.to = $1;
-	}
-
-spec1:	/* DATA */
-	nam '/' con ',' imm
-	{
-		$$.from = $1;
-		$$.from.scale = $3;
-		$$.to = $5;
-	}
-
-spec2:	/* TEXT */
-	mem ',' imm
-	{
-		$$.from = $1;
-		$$.to = $3;
-	}
-|	mem ',' con ',' imm
-	{
-		$$.from = $1;
-		$$.from.scale = $3;
-		$$.to = $5;
-	}
-
-spec3:	/* JMP/CALL */
-	',' rom
-	{
-		$$.from = nullgen;
-		$$.to = $2;
-	}
-|	rom
-	{
-		$$.from = nullgen;
-		$$.to = $1;
-	}
-
-spec4:	/* NOP */
-	nonnon
-|	nonrem
-
-spec5:	/* SHL/SHR */
-	rim ',' rem
-	{
-		$$.from = $1;
-		$$.to = $3;
-	}
-|	rim ',' rem ':' LLREG
-	{
-		$$.from = $1;
-		$$.to = $3;
-		if($$.from.index != D_NONE)
-			yyerror("dp shift with lhs index");
-		$$.from.index = $5;
-	}
-
-spec6:	/* MOVW/MOVL */
-	rim ',' rem
-	{
-		$$.from = $1;
-		$$.to = $3;
-	}
-|	rim ',' rem ':' LSREG
-	{
-		$$.from = $1;
-		$$.to = $3;
-		if($$.to.index != D_NONE)
-			yyerror("dp move with lhs index");
-		$$.to.index = $5;
-	}
-
-spec7:
-	rim ','
-	{
-		$$.from = $1;
-		$$.to = nullgen;
-	}
-|	rim
-	{
-		$$.from = $1;
-		$$.to = nullgen;
-	}
-|	rim ',' rem
-	{
-		$$.from = $1;
-		$$.to = $3;
-	}
-
-spec8:	/* CMPPS/CMPPD */
-	reg ',' rem ',' con
-	{
-		$$.from = $1;
-		$$.to = $3;
-		$$.from.offset = $5;
-	}
-
-spec9:	/* shufl */
-	imm ',' rem ',' reg
-	{
-		$$.from = $3;
-		$$.to = $5;
-		if($1.type != D_CONST)
-			yyerror("illegal constant");
-		$$.to.offset = $1.offset;
-	}
-
-spec10:	/* RET/RETF */
-	{
-		$$.from = nullgen;
-		$$.to = nullgen;
-	}
-|	imm
-	{
-		$$.from = $1;
-		$$.to = nullgen;
-	}
-
-rem:
-	reg
-|	mem
-
-rom:
-	rel
-|	nmem
-|	'*' reg
-	{
-		$$ = $2;
-	}
-|	'*' omem
-	{
-		$$ = $2;
-	}
-|	reg
-|	omem
-
-rim:
-	rem
-|	imm
-
-rel:
-	con '(' LPC ')'
-	{
-		$$ = nullgen;
-		$$.type = D_BRANCH;
-		$$.offset = $1 + pc;
-	}
-|	LNAME offset
-	{
-		$$ = nullgen;
-		if(pass == 2)
-			yyerror("undefined label: %s", $1->name);
-		$$.type = D_BRANCH;
-		$$.sym = $1;
-		$$.offset = $2;
-	}
-|	LLAB offset
-	{
-		$$ = nullgen;
-		$$.type = D_BRANCH;
-		$$.sym = $1;
-		$$.offset = $1->value + $2;
-	}
-
-reg:
-	LBREG
-	{
-		$$ = nullgen;
-		$$.type = $1;
-	}
-|	LFREG
-	{
-		$$ = nullgen;
-		$$.type = $1;
-	}
-|	LLREG
-	{
-		$$ = nullgen;
-		$$.type = $1;
-	}
-|	LMREG
-	{
-		$$ = nullgen;
-		$$.type = $1;
-	}
-|	LSP
-	{
-		$$ = nullgen;
-		$$.type = D_SP;
-	}
-|	LSREG
-	{
-		$$ = nullgen;
-		$$.type = $1;
-	}
-|	LXREG
-	{
-		$$ = nullgen;
-		$$.type = $1;
-	}
-
-imm:
-	'$' con
-	{
-		$$ = nullgen;
-		$$.type = D_CONST;
-		$$.offset = $2;
-	}
-|	'$' nam
-	{
-		$$ = $2;
-		$$.index = $2.type;
-		$$.type = D_ADDR;
-		/*
-		if($2.type == D_AUTO || $2.type == D_PARAM)
-			yyerror("constant cannot be automatic: %s",
-				$2.sym->name);
-		 */
-	}
-|	'$' LSCONST
-	{
-		$$ = nullgen;
-		$$.type = D_SCONST;
-		memcpy($$.sval, $2, sizeof($$.sval));
-	}
-|	'$' LFCONST
-	{
-		$$ = nullgen;
-		$$.type = D_FCONST;
-		$$.dval = $2;
-	}
-|	'$' '(' LFCONST ')'
-	{
-		$$ = nullgen;
-		$$.type = D_FCONST;
-		$$.dval = $3;
-	}
-|	'$' '-' LFCONST
-	{
-		$$ = nullgen;
-		$$.type = D_FCONST;
-		$$.dval = -$3;
-	}
-
-mem:
-	omem
-|	nmem
-
-omem:
-	con
-	{
-		$$ = nullgen;
-		$$.type = D_INDIR+D_NONE;
-		$$.offset = $1;
-	}
-|	con '(' LLREG ')'
-	{
-		$$ = nullgen;
-		$$.type = D_INDIR+$3;
-		$$.offset = $1;
-	}
-|	con '(' LSP ')'
-	{
-		$$ = nullgen;
-		$$.type = D_INDIR+D_SP;
-		$$.offset = $1;
-	}
-|	con '(' LLREG '*' con ')'
-	{
-		$$ = nullgen;
-		$$.type = D_INDIR+D_NONE;
-		$$.offset = $1;
-		$$.index = $3;
-		$$.scale = $5;
-		checkscale($$.scale);
-	}
-|	con '(' LLREG ')' '(' LLREG '*' con ')'
-	{
-		$$ = nullgen;
-		$$.type = D_INDIR+$3;
-		$$.offset = $1;
-		$$.index = $6;
-		$$.scale = $8;
-		checkscale($$.scale);
-	}
-|	'(' LLREG ')'
-	{
-		$$ = nullgen;
-		$$.type = D_INDIR+$2;
-	}
-|	'(' LSP ')'
-	{
-		$$ = nullgen;
-		$$.type = D_INDIR+D_SP;
-	}
-|	'(' LLREG '*' con ')'
-	{
-		$$ = nullgen;
-		$$.type = D_INDIR+D_NONE;
-		$$.index = $2;
-		$$.scale = $4;
-		checkscale($$.scale);
-	}
-|	'(' LLREG ')' '(' LLREG '*' con ')'
-	{
-		$$ = nullgen;
-		$$.type = D_INDIR+$2;
-		$$.index = $5;
-		$$.scale = $7;
-		checkscale($$.scale);
-	}
-
-nmem:
-	nam
-	{
-		$$ = $1;
-	}
-|	nam '(' LLREG '*' con ')'
-	{
-		$$ = $1;
-		$$.index = $3;
-		$$.scale = $5;
-		checkscale($$.scale);
-	}
-
-nam:
-	LNAME offset '(' pointer ')'
-	{
-		$$ = nullgen;
-		$$.type = $4;
-		$$.sym = $1;
-		$$.offset = $2;
-	}
-|	LNAME '<' '>' offset '(' LSB ')'
-	{
-		$$ = nullgen;
-		$$.type = D_STATIC;
-		$$.sym = $1;
-		$$.offset = $4;
-	}
-
-offset:
-	{
-		$$ = 0;
-	}
-|	'+' con
-	{
-		$$ = $2;
-	}
-|	'-' con
-	{
-		$$ = -$2;
-	}
-
-pointer:
-	LSB
-|	LSP
-	{
-		$$ = D_AUTO;
-	}
-|	LFP
-
-con:
-	LCONST
-|	LVAR
-	{
-		$$ = $1->value;
-	}
-|	'-' con
-	{
-		$$ = -$2;
-	}
-|	'+' con
-	{
-		$$ = $2;
-	}
-|	'~' con
-	{
-		$$ = ~$2;
-	}
-|	'(' expr ')'
-	{
-		$$ = $2;
-	}
-
-expr:
-	con
-|	expr '+' expr
-	{
-		$$ = $1 + $3;
-	}
-|	expr '-' expr
-	{
-		$$ = $1 - $3;
-	}
-|	expr '*' expr
-	{
-		$$ = $1 * $3;
-	}
-|	expr '/' expr
-	{
-		$$ = $1 / $3;
-	}
-|	expr '%' expr
-	{
-		$$ = $1 % $3;
-	}
-|	expr '<' '<' expr
-	{
-		$$ = $1 << $4;
-	}
-|	expr '>' '>' expr
-	{
-		$$ = $1 >> $4;
-	}
-|	expr '&' expr
-	{
-		$$ = $1 & $3;
-	}
-|	expr '^' expr
-	{
-		$$ = $1 ^ $3;
-	}
-|	expr '|' expr
-	{
-		$$ = $1 | $3;
-	}

+ 0 - 1298
sys/src/cmd/6a/lex.c

@@ -1,1298 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#define	EXTERN
-#include "a.h"
-#include "y.tab.h"
-#include <ctype.h>
-
-void
-main(int argc, char *argv[])
-{
-	char *p;
-	int nout, nproc, status, i, c;
-
-	thechar = '6';
-	thestring = "amd64";
-	memset(debug, 0, sizeof(debug));
-	cinit();
-	outfile = 0;
-	include[ninclude++] = ".";
-	ARGBEGIN {
-	default:
-		c = ARGC();
-		if(c >= 0 || c < sizeof(debug))
-			debug[c] = 1;
-		break;
-
-	case 'o':
-		outfile = ARGF();
-		break;
-
-	case 'D':
-		p = ARGF();
-		if(p)
-			Dlist[nDlist++] = p;
-		break;
-
-	case 'I':
-		p = ARGF();
-		setinclude(p);
-		break;
-	} ARGEND
-	if(*argv == 0) {
-		print("usage: %ca [-options] file.s\n", thechar);
-		errorexit();
-	}
-	if(argc > 1 && systemtype(Windows)){
-		print("can't assemble multiple files on windows\n");
-		errorexit();
-	}
-	if(argc > 1 && !systemtype(Windows)) {
-		nproc = 1;
-		if(p = getenv("NPROC"))
-			nproc = atol(p);	/* */
-		c = 0;
-		nout = 0;
-		for(;;) {
-			while(nout < nproc && argc > 0) {
-				i = myfork();
-				if(i < 0) {
-					i = mywait(&status);
-					if(i < 0)
-						errorexit();
-					if(status)
-						c++;
-					nout--;
-					continue;
-				}
-				if(i == 0) {
-					print("%s:\n", *argv);
-					if(assemble(*argv))
-						errorexit();
-					exits(0);
-				}
-				nout++;
-				argc--;
-				argv++;
-			}
-			i = mywait(&status);
-			if(i < 0) {
-				if(c)
-					errorexit();
-				exits(0);
-			}
-			if(status)
-				c++;
-			nout--;
-		}
-	}
-	if(assemble(argv[0]))
-		errorexit();
-	exits(0);
-}
-
-int
-assemble(char *file)
-{
-	char ofile[100], incfile[20], *p;
-	int i, of;
-
-	strcpy(ofile, file);
-	p = utfrrune(ofile, pathchar());
-	if(p) {
-		include[0] = ofile;
-		*p++ = 0;
-	} else
-		p = ofile;
-	if(outfile == 0) {
-		outfile = p;
-		if(outfile){
-			p = utfrrune(outfile, '.');
-			if(p)
-				if(p[1] == 's' && p[2] == 0)
-					p[0] = 0;
-			p = utfrune(outfile, 0);
-			p[0] = '.';
-			p[1] = thechar;
-			p[2] = 0;
-		} else
-			outfile = "/dev/null";
-	}
-	p = getenv("INCLUDE");
-	if(p) {
-		setinclude(p);
-	} else {
-		if(systemtype(Plan9)) {
-			sprint(incfile,"/%s/include", thestring);
-			setinclude(strdup(incfile));
-		}
-	}
-
-	of = mycreat(outfile, 0664);
-	if(of < 0) {
-		yyerror("%ca: cannot create %s", thechar, outfile);
-		errorexit();
-	}
-	Binit(&obuf, of, OWRITE);
-
-	pass = 1;
-	pinit(file);
-	for(i=0; i<nDlist; i++)
-		dodefine(Dlist[i]);
-	yyparse();
-	if(nerrors) {
-		cclean();
-		return nerrors;
-	}
-
-	pass = 2;
-	outhist();
-	pinit(file);
-	for(i=0; i<nDlist; i++)
-		dodefine(Dlist[i]);
-	yyparse();
-	cclean();
-	return nerrors;
-}
-
-struct
-{
-	char	*name;
-	uint16_t	type;
-	uint16_t	value;
-} itab[] =
-{
-	"SP",		LSP,	D_AUTO,
-	"SB",		LSB,	D_EXTERN,
-	"FP",		LFP,	D_PARAM,
-	"PC",		LPC,	D_BRANCH,
-
-	"AL",		LBREG,	D_AL,
-	"CL",		LBREG,	D_CL,
-	"DL",		LBREG,	D_DL,
-	"BL",		LBREG,	D_BL,
-/*	"SPB",		LBREG,	D_SPB,	*/
-	"SIB",		LBREG,	D_SIB,
-	"DIB",		LBREG,	D_DIB,
-	"BPB",		LBREG,	D_BPB,
-	"R8B",		LBREG,	D_R8B,
-	"R9B",		LBREG,	D_R9B,
-	"R10B",		LBREG,	D_R10B,
-	"R11B",		LBREG,	D_R11B,
-	"R12B",		LBREG,	D_R12B,
-	"R13B",		LBREG,	D_R13B,
-	"R14B",		LBREG,	D_R14B,
-	"R15B",		LBREG,	D_R15B,
-
-	"AH",		LBREG,	D_AH,
-	"CH",		LBREG,	D_CH,
-	"DH",		LBREG,	D_DH,
-	"BH",		LBREG,	D_BH,
-
-	"AX",		LLREG,	D_AX,
-	"CX",		LLREG,	D_CX,
-	"DX",		LLREG,	D_DX,
-	"BX",		LLREG,	D_BX,
-/*	"SP",		LLREG,	D_SP,	*/
-	"BP",		LLREG,	D_BP,
-	"SI",		LLREG,	D_SI,
-	"DI",		LLREG,	D_DI,
-	"R8",		LLREG,	D_R8,
-	"R9",		LLREG,	D_R9,
-	"R10",		LLREG,	D_R10,
-	"R11",		LLREG,	D_R11,
-	"R12",		LLREG,	D_R12,
-	"R13",		LLREG,	D_R13,
-	"R14",		LLREG,	D_R14,
-	"R15",		LLREG,	D_R15,
-
-	"RARG",		LLREG,	REGARG,
-
-	"F0",		LFREG,	D_F0+0,
-	"F1",		LFREG,	D_F0+1,
-	"F2",		LFREG,	D_F0+2,
-	"F3",		LFREG,	D_F0+3,
-	"F4",		LFREG,	D_F0+4,
-	"F5",		LFREG,	D_F0+5,
-	"F6",		LFREG,	D_F0+6,
-	"F7",		LFREG,	D_F0+7,
-
-	"M0",		LMREG,	D_M0+0,
-	"M1",		LMREG,	D_M0+1,
-	"M2",		LMREG,	D_M0+2,
-	"M3",		LMREG,	D_M0+3,
-	"M4",		LMREG,	D_M0+4,
-	"M5",		LMREG,	D_M0+5,
-	"M6",		LMREG,	D_M0+6,
-	"M7",		LMREG,	D_M0+7,
-
-	"X0",		LXREG,	D_X0+0,
-	"X1",		LXREG,	D_X0+1,
-	"X2",		LXREG,	D_X0+2,
-	"X3",		LXREG,	D_X0+3,
-	"X4",		LXREG,	D_X0+4,
-	"X5",		LXREG,	D_X0+5,
-	"X6",		LXREG,	D_X0+6,
-	"X7",		LXREG,	D_X0+7,
-	"X8",		LXREG,	D_X0+8,
-	"X9",		LXREG,	D_X0+9,
-	"X10",		LXREG,	D_X0+10,
-	"X11",		LXREG,	D_X0+11,
-	"X12",		LXREG,	D_X0+12,
-	"X13",		LXREG,	D_X0+13,
-	"X14",		LXREG,	D_X0+14,
-	"X15",		LXREG,	D_X0+15,
-
-	"CS",		LSREG,	D_CS,
-	"SS",		LSREG,	D_SS,
-	"DS",		LSREG,	D_DS,
-	"ES",		LSREG,	D_ES,
-	"FS",		LSREG,	D_FS,
-	"GS",		LSREG,	D_GS,
-
-	"GDTR",		LBREG,	D_GDTR,
-	"IDTR",		LBREG,	D_IDTR,
-	"LDTR",		LBREG,	D_LDTR,
-	"MSW",		LBREG,	D_MSW,
-	"TASK",		LBREG,	D_TASK,
-
-	"CR0",		LBREG,	D_CR+0,
-	"CR1",		LBREG,	D_CR+1,
-	"CR2",		LBREG,	D_CR+2,
-	"CR3",		LBREG,	D_CR+3,
-	"CR4",		LBREG,	D_CR+4,
-	"CR5",		LBREG,	D_CR+5,
-	"CR6",		LBREG,	D_CR+6,
-	"CR7",		LBREG,	D_CR+7,
-	"CR8",		LBREG,	D_CR+8,
-	"CR9",		LBREG,	D_CR+9,
-	"CR10",		LBREG,	D_CR+10,
-	"CR11",		LBREG,	D_CR+11,
-	"CR12",		LBREG,	D_CR+12,
-	"CR13",		LBREG,	D_CR+13,
-	"CR14",		LBREG,	D_CR+14,
-	"CR15",		LBREG,	D_CR+15,
-
-	"DR0",		LBREG,	D_DR+0,
-	"DR1",		LBREG,	D_DR+1,
-	"DR2",		LBREG,	D_DR+2,
-	"DR3",		LBREG,	D_DR+3,
-	"DR4",		LBREG,	D_DR+4,
-	"DR5",		LBREG,	D_DR+5,
-	"DR6",		LBREG,	D_DR+6,
-	"DR7",		LBREG,	D_DR+7,
-
-	"TR0",		LBREG,	D_TR+0,
-	"TR1",		LBREG,	D_TR+1,
-	"TR2",		LBREG,	D_TR+2,
-	"TR3",		LBREG,	D_TR+3,
-	"TR4",		LBREG,	D_TR+4,
-	"TR5",		LBREG,	D_TR+5,
-	"TR6",		LBREG,	D_TR+6,
-	"TR7",		LBREG,	D_TR+7,
-
-	"AAA",		LTYPE0,	AAAA,
-	"AAD",		LTYPE0,	AAAD,
-	"AAM",		LTYPE0,	AAAM,
-	"AAS",		LTYPE0,	AAAS,
-	"ADCB",		LTYPE3,	AADCB,
-	"ADCL",		LTYPE3,	AADCL,
-	"ADCQ",		LTYPE3,	AADCQ,
-	"ADCW",		LTYPE3,	AADCW,
-	"ADDB",		LTYPE3,	AADDB,
-	"ADDL",		LTYPE3,	AADDL,
-	"ADDQ",		LTYPE3,	AADDQ,
-	"ADDW",		LTYPE3,	AADDW,
-	"ADJSP",	LTYPE2,	AADJSP,
-	"ANDB",		LTYPE3,	AANDB,
-	"ANDL",		LTYPE3,	AANDL,
-	"ANDQ",		LTYPE3,	AANDQ,
-	"ANDW",		LTYPE3,	AANDW,
-	"ARPL",		LTYPE3,	AARPL,
-	"BOUNDL",	LTYPE3,	ABOUNDL,
-	"BOUNDW",	LTYPE3,	ABOUNDW,
-	"BSFL",		LTYPE3,	ABSFL,
-	"BSFQ",		LTYPE3,	ABSFQ,
-	"BSFW",		LTYPE3,	ABSFW,
-	"BSRL",		LTYPE3,	ABSRL,
-	"BSRQ",		LTYPE3,	ABSRQ,
-	"BSRW",		LTYPE3,	ABSRW,
-	"BTCL",		LTYPE3,	ABTCL,
-	"BTCQ",		LTYPE3,	ABTCQ,
-	"BTCW",		LTYPE3,	ABTCW,
-	"BTL",		LTYPE3,	ABTL,
-	"BTQ",		LTYPE3,	ABTQ,
-	"BTRL",		LTYPE3,	ABTRL,
-	"BTRQ",		LTYPE3,	ABTRQ,
-	"BTRW",		LTYPE3,	ABTRW,
-	"BTSL",		LTYPE3,	ABTSL,
-	"BTSQ",		LTYPE3,	ABTSQ,
-	"BTSW",		LTYPE3,	ABTSW,
-	"BTW",		LTYPE3,	ABTW,
-	"BYTE",		LTYPE2,	ABYTE,
-	"CALL",		LTYPEC,	ACALL,
-	"CLC",		LTYPE0,	ACLC,
-	"CLD",		LTYPE0,	ACLD,
-	"CLI",		LTYPE0,	ACLI,
-	"CLTS",		LTYPE0,	ACLTS,
-	"CMC",		LTYPE0,	ACMC,
-	"CMPB",		LTYPE4,	ACMPB,
-	"CMPL",		LTYPE4,	ACMPL,
-	"CMPQ",		LTYPE4,	ACMPQ,
-	"CMPW",		LTYPE4,	ACMPW,
-	"CMPSB",	LTYPE0,	ACMPSB,
-	"CMPSL",	LTYPE0,	ACMPSL,
-	"CMPSQ",	LTYPE0,	ACMPSQ,
-	"CMPSW",	LTYPE0,	ACMPSW,
-	"CMPXCHG8B",	LTYPE1,	ACMPXCHG8B,
-	"CMPXCHGB",	LTYPE3,	ACMPXCHGB,	/* LTYPE3? */
-	"CMPXCHGL",	LTYPE3,	ACMPXCHGL,
-	"CMPXCHGQ",	LTYPE3,	ACMPXCHGQ,
-	"CMPXCHGW",	LTYPE3,	ACMPXCHGW,
-	"CPUID",	LTYPE0,	ACPUID,
-	"DAA",		LTYPE0,	ADAA,
-	"DAS",		LTYPE0,	ADAS,
-	"DATA",		LTYPED,	ADATA,
-	"DECB",		LTYPE1,	ADECB,
-	"DECL",		LTYPE1,	ADECL,
-	"DECQ",		LTYPE1,	ADECQ,
-	"DECW",		LTYPE1,	ADECW,
-	"DIVB",		LTYPE2,	ADIVB,
-	"DIVL",		LTYPE2,	ADIVL,
-	"DIVQ",		LTYPE2,	ADIVQ,
-	"DIVW",		LTYPE2,	ADIVW,
-	"EMMS",		LTYPE0,	AEMMS,
-	"END",		LTYPE0,	AEND,
-	"ENTER",	LTYPE2,	AENTER,
-	"GLOBL",	LTYPET,	AGLOBL,
-	"HLT",		LTYPE0,	AHLT,
-	"IDIVB",	LTYPE2,	AIDIVB,
-	"IDIVL",	LTYPE2,	AIDIVL,
-	"IDIVQ",	LTYPE2,	AIDIVQ,
-	"IDIVW",	LTYPE2,	AIDIVW,
-	"IMULB",	LTYPEI,	AIMULB,
-	"IMULL",	LTYPEI,	AIMULL,
-	"IMULQ",	LTYPEI,	AIMULQ,
-	"IMULW",	LTYPEI,	AIMULW,
-	"INB",		LTYPE0,	AINB,
-	"INL",		LTYPE0,	AINL,
-	"INW",		LTYPE0,	AINW,
-	"INCB",		LTYPE1,	AINCB,
-	"INCL",		LTYPE1,	AINCL,
-	"INCQ",		LTYPE1,	AINCQ,
-	"INCW",		LTYPE1,	AINCW,
-	"INSB",		LTYPE0,	AINSB,
-	"INSL",		LTYPE0,	AINSL,
-	"INSW",		LTYPE0,	AINSW,
-	"INT",		LTYPE2,	AINT,
-	"INTO",		LTYPE0,	AINTO,
-	"INVD",		LTYPE0,	AINVD,
-	"INVLPG",	LTYPE2,	AINVLPG,
-	"IRETL",	LTYPE0,	AIRETL,
-	"IRETQ",	LTYPE0,	AIRETQ,
-	"IRETW",	LTYPE0,	AIRETW,
-
-	"JOS",		LTYPER,	AJOS,
-	"JO",		LTYPER,	AJOS,	/* alternate */
-	"JOC",		LTYPER,	AJOC,
-	"JNO",		LTYPER,	AJOC,	/* alternate */
-	"JCS",		LTYPER,	AJCS,
-	"JB",		LTYPER,	AJCS,	/* alternate */
-	"JC",		LTYPER,	AJCS,	/* alternate */
-	"JNAE",		LTYPER,	AJCS,	/* alternate */
-	"JLO",		LTYPER,	AJCS,	/* alternate */
-	"JCC",		LTYPER,	AJCC,
-	"JAE",		LTYPER,	AJCC,	/* alternate */
-	"JNB",		LTYPER,	AJCC,	/* alternate */
-	"JNC",		LTYPER,	AJCC,	/* alternate */
-	"JHS",		LTYPER,	AJCC,	/* alternate */
-	"JEQ",		LTYPER,	AJEQ,
-	"JE",		LTYPER,	AJEQ,	/* alternate */
-	"JZ",		LTYPER,	AJEQ,	/* alternate */
-	"JNE",		LTYPER,	AJNE,
-	"JNZ",		LTYPER,	AJNE,	/* alternate */
-	"JLS",		LTYPER,	AJLS,
-	"JBE",		LTYPER,	AJLS,	/* alternate */
-	"JNA",		LTYPER,	AJLS,	/* alternate */
-	"JHI",		LTYPER,	AJHI,
-	"JA",		LTYPER,	AJHI,	/* alternate */
-	"JNBE",		LTYPER,	AJHI,	/* alternate */
-	"JMI",		LTYPER,	AJMI,
-	"JS",		LTYPER,	AJMI,	/* alternate */
-	"JPL",		LTYPER,	AJPL,
-	"JNS",		LTYPER,	AJPL,	/* alternate */
-	"JPS",		LTYPER,	AJPS,
-	"JP",		LTYPER,	AJPS,	/* alternate */
-	"JPE",		LTYPER,	AJPS,	/* alternate */
-	"JPC",		LTYPER,	AJPC,
-	"JNP",		LTYPER,	AJPC,	/* alternate */
-	"JPO",		LTYPER,	AJPC,	/* alternate */
-	"JLT",		LTYPER,	AJLT,
-	"JL",		LTYPER,	AJLT,	/* alternate */
-	"JNGE",		LTYPER,	AJLT,	/* alternate */
-	"JGE",		LTYPER,	AJGE,
-	"JNL",		LTYPER,	AJGE,	/* alternate */
-	"JLE",		LTYPER,	AJLE,
-	"JNG",		LTYPER,	AJLE,	/* alternate */
-	"JGT",		LTYPER,	AJGT,
-	"JG",		LTYPER,	AJGT,	/* alternate */
-	"JNLE",		LTYPER,	AJGT,	/* alternate */
-
-	"JCXZ",		LTYPER,	AJCXZ,
-	"JMP",		LTYPEC,	AJMP,
-	"LAHF",		LTYPE0,	ALAHF,
-	"LARL",		LTYPE3,	ALARL,
-	"LARW",		LTYPE3,	ALARW,
-	"LEAL",		LTYPE3,	ALEAL,
-	"LEAQ",		LTYPE3,	ALEAQ,
-	"LEAW",		LTYPE3,	ALEAW,
-	"LEAVEL",	LTYPE0,	ALEAVEL,
-	"LEAVEQ",	LTYPE0,	ALEAVEQ,
-	"LEAVEW",	LTYPE0,	ALEAVEW,
-	"LFENCE",	LTYPE0,	ALFENCE,
-	"LOCK",		LTYPE0,	ALOCK,
-	"LODSB",	LTYPE0,	ALODSB,
-	"LODSL",	LTYPE0,	ALODSL,
-	"LODSQ",	LTYPE0,	ALODSQ,
-	"LODSW",	LTYPE0,	ALODSW,
-	"LONG",		LTYPE2,	ALONG,
-	"LOOP",		LTYPER,	ALOOP,
-	"LOOPEQ",	LTYPER,	ALOOPEQ,
-	"LOOPNE",	LTYPER,	ALOOPNE,
-	"LSLL",		LTYPE3,	ALSLL,
-	"LSLW",		LTYPE3,	ALSLW,
-	"MFENCE",	LTYPE0,	AMFENCE,
-	"MODE",		LTYPE2,	AMODE,
-	"MOVB",		LTYPE3,	AMOVB,
-	"MOVL",		LTYPEM,	AMOVL,
-	"MOVQ",		LTYPEM,	AMOVQ,
-	"MOVW",		LTYPEM,	AMOVW,
-	"MOVBLSX",	LTYPE3, AMOVBLSX,
-	"MOVBLZX",	LTYPE3, AMOVBLZX,
-	"MOVBQSX",	LTYPE3,	AMOVBQSX,
-	"MOVBQZX",	LTYPE3,	AMOVBQZX,
-	"MOVBWSX",	LTYPE3, AMOVBWSX,
-	"MOVBWZX",	LTYPE3, AMOVBWZX,
-	"MOVLQSX",	LTYPE3, AMOVLQSX,
-	"MOVLQZX",	LTYPE3, AMOVLQZX,
-	"MOVNTIL",	LTYPE3,	AMOVNTIL,
-	"MOVNTIQ",	LTYPE3,	AMOVNTIQ,
-	"MOVWLSX",	LTYPE3, AMOVWLSX,
-	"MOVWLZX",	LTYPE3, AMOVWLZX,
-	"MOVWQSX",	LTYPE3,	AMOVWQSX,
-	"MOVWQZX",	LTYPE3,	AMOVWQZX,
-	"MOVSB",	LTYPE0,	AMOVSB,
-	"MOVSL",	LTYPE0,	AMOVSL,
-	"MOVSQ",	LTYPE0,	AMOVSQ,
-	"MOVSW",	LTYPE0,	AMOVSW,
-	"MULB",		LTYPE2,	AMULB,
-	"MULL",		LTYPE2,	AMULL,
-	"MULQ",		LTYPE2,	AMULQ,
-	"MULW",		LTYPE2,	AMULW,
-	"NEGB",		LTYPE1,	ANEGB,
-	"NEGL",		LTYPE1,	ANEGL,
-	"NEGQ",		LTYPE1,	ANEGQ,
-	"NEGW",		LTYPE1,	ANEGW,
-	"NOP",		LTYPEN,	ANOP,
-	"NOTB",		LTYPE1,	ANOTB,
-	"NOTL",		LTYPE1,	ANOTL,
-	"NOTQ",		LTYPE1,	ANOTQ,
-	"NOTW",		LTYPE1,	ANOTW,
-	"ORB",		LTYPE3,	AORB,
-	"ORL",		LTYPE3,	AORL,
-	"ORQ",		LTYPE3,	AORQ,
-	"ORW",		LTYPE3,	AORW,
-	"OUTB",		LTYPE0,	AOUTB,
-	"OUTL",		LTYPE0,	AOUTL,
-	"OUTW",		LTYPE0,	AOUTW,
-	"OUTSB",	LTYPE0,	AOUTSB,
-	"OUTSL",	LTYPE0,	AOUTSL,
-	"OUTSW",	LTYPE0,	AOUTSW,
-	"POPAL",	LTYPE0,	APOPAL,
-	"POPAW",	LTYPE0,	APOPAW,
-	"POPFL",	LTYPE0,	APOPFL,
-	"POPFQ",	LTYPE0,	APOPFQ,
-	"POPFW",	LTYPE0,	APOPFW,
-	"POPL",		LTYPE1,	APOPL,
-	"POPQ",		LTYPE1,	APOPQ,
-	"POPW",		LTYPE1,	APOPW,
-	"PUSHAL",	LTYPE0,	APUSHAL,
-	"PUSHAW",	LTYPE0,	APUSHAW,
-	"PUSHFL",	LTYPE0,	APUSHFL,
-	"PUSHFQ",	LTYPE0,	APUSHFQ,
-	"PUSHFW",	LTYPE0,	APUSHFW,
-	"PUSHL",	LTYPE2,	APUSHL,
-	"PUSHQ",	LTYPE2,	APUSHQ,
-	"PUSHW",	LTYPE2,	APUSHW,
-	"RCLB",		LTYPE3,	ARCLB,
-	"RCLL",		LTYPE3,	ARCLL,
-	"RCLQ",		LTYPE3,	ARCLQ,
-	"RCLW",		LTYPE3,	ARCLW,
-	"RCRB",		LTYPE3,	ARCRB,
-	"RCRL",		LTYPE3,	ARCRL,
-	"RCRQ",		LTYPE3,	ARCRQ,
-	"RCRW",		LTYPE3,	ARCRW,
-	"RDMSR",	LTYPE0,	ARDMSR,
-	"RDPMC",	LTYPE0,	ARDPMC,
-	"RDTSC",	LTYPE0,	ARDTSC,
-	"REP",		LTYPE0,	AREP,
-	"REPN",		LTYPE0,	AREPN,
-	"RET",		LTYPE0,	ARET,
-	"RETFL",	LTYPERT,ARETFL,
-	"RETFW",	LTYPERT,ARETFW,
-	"RETFQ",	LTYPERT,ARETFQ,
-	"ROLB",		LTYPE3,	AROLB,
-	"ROLL",		LTYPE3,	AROLL,
-	"ROLQ",		LTYPE3,	AROLQ,
-	"ROLW",		LTYPE3,	AROLW,
-	"RORB",		LTYPE3,	ARORB,
-	"RORL",		LTYPE3,	ARORL,
-	"RORQ",		LTYPE3,	ARORQ,
-	"RORW",		LTYPE3,	ARORW,
-	"RSM",		LTYPE0,	ARSM,
-	"SAHF",		LTYPE0,	ASAHF,
-	"SALB",		LTYPE3,	ASALB,
-	"SALL",		LTYPE3,	ASALL,
-	"SALQ",		LTYPE3,	ASALQ,
-	"SALW",		LTYPE3,	ASALW,
-	"SARB",		LTYPE3,	ASARB,
-	"SARL",		LTYPE3,	ASARL,
-	"SARQ",		LTYPE3,	ASARQ,
-	"SARW",		LTYPE3,	ASARW,
-	"SBBB",		LTYPE3,	ASBBB,
-	"SBBL",		LTYPE3,	ASBBL,
-	"SBBQ",		LTYPE3,	ASBBQ,
-	"SBBW",		LTYPE3,	ASBBW,
-	"SCASB",	LTYPE0,	ASCASB,
-	"SCASL",	LTYPE0,	ASCASL,
-	"SCASQ",	LTYPE0,	ASCASQ,
-	"SCASW",	LTYPE0,	ASCASW,
-	"SETCC",	LTYPE1,	ASETCC,
-	"SETCS",	LTYPE1,	ASETCS,
-	"SETEQ",	LTYPE1,	ASETEQ,
-	"SETGE",	LTYPE1,	ASETGE,
-	"SETGT",	LTYPE1,	ASETGT,
-	"SETHI",	LTYPE1,	ASETHI,
-	"SETLE",	LTYPE1,	ASETLE,
-	"SETLS",	LTYPE1,	ASETLS,
-	"SETLT",	LTYPE1,	ASETLT,
-	"SETMI",	LTYPE1,	ASETMI,
-	"SETNE",	LTYPE1,	ASETNE,
-	"SETOC",	LTYPE1,	ASETOC,
-	"SETOS",	LTYPE1,	ASETOS,
-	"SETPC",	LTYPE1,	ASETPC,
-	"SETPL",	LTYPE1,	ASETPL,
-	"SETPS",	LTYPE1,	ASETPS,
-	"SFENCE",	LTYPE0,	ASFENCE,
-	"CDQ",		LTYPE0,	ACDQ,
-	"CWD",		LTYPE0,	ACWD,
-	"CQO",		LTYPE0,	ACQO,
-	"SHLB",		LTYPE3,	ASHLB,
-	"SHLL",		LTYPES,	ASHLL,
-	"SHLQ",		LTYPES,	ASHLQ,
-	"SHLW",		LTYPES,	ASHLW,
-	"SHRB",		LTYPE3,	ASHRB,
-	"SHRL",		LTYPES,	ASHRL,
-	"SHRQ",		LTYPES,	ASHRQ,
-	"SHRW",		LTYPES,	ASHRW,
-	"STC",		LTYPE0,	ASTC,
-	"STD",		LTYPE0,	ASTD,
-	"STI",		LTYPE0,	ASTI,
-	"STOSB",	LTYPE0,	ASTOSB,
-	"STOSL",	LTYPE0,	ASTOSL,
-	"STOSQ",	LTYPE0,	ASTOSQ,
-	"STOSW",	LTYPE0,	ASTOSW,
-	"SUBB",		LTYPE3,	ASUBB,
-	"SUBL",		LTYPE3,	ASUBL,
-	"SUBQ",		LTYPE3,	ASUBQ,
-	"SUBW",		LTYPE3,	ASUBW,
-	"SYSCALL",	LTYPE0,	ASYSCALL,
-	"SYSRET",	LTYPE0,	ASYSRET,
-	"SWAPGS",	LTYPE0,	ASWAPGS,
-	"TESTB",	LTYPE3,	ATESTB,
-	"TESTL",	LTYPE3,	ATESTL,
-	"TESTQ",	LTYPE3,	ATESTQ,
-	"TESTW",	LTYPE3,	ATESTW,
-	"TEXT",		LTYPET,	ATEXT,
-	"VERR",		LTYPE2,	AVERR,
-	"VERW",		LTYPE2,	AVERW,
-	"QUAD",		LTYPE2,	AQUAD,
-	"WAIT",		LTYPE0,	AWAIT,
-	"WBINVD",	LTYPE0,	AWBINVD,
-	"WRMSR",	LTYPE0,	AWRMSR,
-	"WORD",		LTYPE2,	AWORD,
-	"XADDB",	LTYPE3,	AXADDB,
-	"XADDL",	LTYPE3,	AXADDL,
-	"XADDQ",	LTYPE3,	AXADDQ,
-	"XADDW",	LTYPE3,	AXADDW,
-	"XCHGB",	LTYPE3,	AXCHGB,
-	"XCHGL",	LTYPE3,	AXCHGL,
-	"XCHGQ",	LTYPE3,	AXCHGQ,
-	"XCHGW",	LTYPE3,	AXCHGW,
-	"XLAT",		LTYPE2,	AXLAT,
-	"XORB",		LTYPE3,	AXORB,
-	"XORL",		LTYPE3,	AXORL,
-	"XORQ",		LTYPE3,	AXORQ,
-	"XORW",		LTYPE3,	AXORW,
-
-	"CMOVLCC",	LTYPE3,	ACMOVLCC,
-	"CMOVLCS",	LTYPE3,	ACMOVLCS,
-	"CMOVLEQ",	LTYPE3,	ACMOVLEQ,
-	"CMOVLGE",	LTYPE3,	ACMOVLGE,
-	"CMOVLGT",	LTYPE3,	ACMOVLGT,
-	"CMOVLHI",	LTYPE3,	ACMOVLHI,
-	"CMOVLLE",	LTYPE3,	ACMOVLLE,
-	"CMOVLLS",	LTYPE3,	ACMOVLLS,
-	"CMOVLLT",	LTYPE3,	ACMOVLLT,
-	"CMOVLMI",	LTYPE3,	ACMOVLMI,
-	"CMOVLNE",	LTYPE3,	ACMOVLNE,
-	"CMOVLOC",	LTYPE3,	ACMOVLOC,
-	"CMOVLOS",	LTYPE3,	ACMOVLOS,
-	"CMOVLPC",	LTYPE3,	ACMOVLPC,
-	"CMOVLPL",	LTYPE3,	ACMOVLPL,
-	"CMOVLPS",	LTYPE3,	ACMOVLPS,
-	"CMOVQCC",	LTYPE3,	ACMOVQCC,
-	"CMOVQCS",	LTYPE3,	ACMOVQCS,
-	"CMOVQEQ",	LTYPE3,	ACMOVQEQ,
-	"CMOVQGE",	LTYPE3,	ACMOVQGE,
-	"CMOVQGT",	LTYPE3,	ACMOVQGT,
-	"CMOVQHI",	LTYPE3,	ACMOVQHI,
-	"CMOVQLE",	LTYPE3,	ACMOVQLE,
-	"CMOVQLS",	LTYPE3,	ACMOVQLS,
-	"CMOVQLT",	LTYPE3,	ACMOVQLT,
-	"CMOVQMI",	LTYPE3,	ACMOVQMI,
-	"CMOVQNE",	LTYPE3,	ACMOVQNE,
-	"CMOVQOC",	LTYPE3,	ACMOVQOC,
-	"CMOVQOS",	LTYPE3,	ACMOVQOS,
-	"CMOVQPC",	LTYPE3,	ACMOVQPC,
-	"CMOVQPL",	LTYPE3,	ACMOVQPL,
-	"CMOVQPS",	LTYPE3,	ACMOVQPS,
-	"CMOVWCC",	LTYPE3,	ACMOVWCC,
-	"CMOVWCS",	LTYPE3,	ACMOVWCS,
-	"CMOVWEQ",	LTYPE3,	ACMOVWEQ,
-	"CMOVWGE",	LTYPE3,	ACMOVWGE,
-	"CMOVWGT",	LTYPE3,	ACMOVWGT,
-	"CMOVWHI",	LTYPE3,	ACMOVWHI,
-	"CMOVWLE",	LTYPE3,	ACMOVWLE,
-	"CMOVWLS",	LTYPE3,	ACMOVWLS,
-	"CMOVWLT",	LTYPE3,	ACMOVWLT,
-	"CMOVWMI",	LTYPE3,	ACMOVWMI,
-	"CMOVWNE",	LTYPE3,	ACMOVWNE,
-	"CMOVWOC",	LTYPE3,	ACMOVWOC,
-	"CMOVWOS",	LTYPE3,	ACMOVWOS,
-	"CMOVWPC",	LTYPE3,	ACMOVWPC,
-	"CMOVWPL",	LTYPE3,	ACMOVWPL,
-	"CMOVWPS",	LTYPE3,	ACMOVWPS,
-
-	"FMOVB",	LTYPE3, AFMOVB,
-	"FMOVBP",	LTYPE3, AFMOVBP,
-	"FMOVD",	LTYPE3, AFMOVD,
-	"FMOVDP",	LTYPE3, AFMOVDP,
-	"FMOVF",	LTYPE3, AFMOVF,
-	"FMOVFP",	LTYPE3, AFMOVFP,
-	"FMOVL",	LTYPE3, AFMOVL,
-	"FMOVLP",	LTYPE3, AFMOVLP,
-	"FMOVV",	LTYPE3, AFMOVV,
-	"FMOVVP",	LTYPE3, AFMOVVP,
-	"FMOVW",	LTYPE3, AFMOVW,
-	"FMOVWP",	LTYPE3, AFMOVWP,
-	"FMOVX",	LTYPE3, AFMOVX,
-	"FMOVXP",	LTYPE3, AFMOVXP,
-	"FCOMB",	LTYPE3, AFCOMB,
-	"FCOMBP",	LTYPE3, AFCOMBP,
-	"FCOMD",	LTYPE3, AFCOMD,
-	"FCOMDP",	LTYPE3, AFCOMDP,
-	"FCOMDPP",	LTYPE3, AFCOMDPP,
-	"FCOMF",	LTYPE3, AFCOMF,
-	"FCOMFP",	LTYPE3, AFCOMFP,
-	"FCOML",	LTYPE3, AFCOML,
-	"FCOMLP",	LTYPE3, AFCOMLP,
-	"FCOMW",	LTYPE3, AFCOMW,
-	"FCOMWP",	LTYPE3, AFCOMWP,
-	"FUCOM",	LTYPE3, AFUCOM,
-	"FUCOMP",	LTYPE3, AFUCOMP,
-	"FUCOMPP",	LTYPE3, AFUCOMPP,
-	"FADDW",	LTYPE3, AFADDW,
-	"FADDL",	LTYPE3, AFADDL,
-	"FADDF",	LTYPE3, AFADDF,
-	"FADDD",	LTYPE3, AFADDD,
-	"FADDDP",	LTYPE3, AFADDDP,
-	"FSUBDP",	LTYPE3, AFSUBDP,
-	"FSUBW",	LTYPE3, AFSUBW,
-	"FSUBL",	LTYPE3, AFSUBL,
-	"FSUBF",	LTYPE3, AFSUBF,
-	"FSUBD",	LTYPE3, AFSUBD,
-	"FSUBRDP",	LTYPE3, AFSUBRDP,
-	"FSUBRW",	LTYPE3, AFSUBRW,
-	"FSUBRL",	LTYPE3, AFSUBRL,
-	"FSUBRF",	LTYPE3, AFSUBRF,
-	"FSUBRD",	LTYPE3, AFSUBRD,
-	"FMULDP",	LTYPE3, AFMULDP,
-	"FMULW",	LTYPE3, AFMULW,
-	"FMULL",	LTYPE3, AFMULL,
-	"FMULF",	LTYPE3, AFMULF,
-	"FMULD",	LTYPE3, AFMULD,
-	"FDIVDP",	LTYPE3, AFDIVDP,
-	"FDIVW",	LTYPE3, AFDIVW,
-	"FDIVL",	LTYPE3, AFDIVL,
-	"FDIVF",	LTYPE3, AFDIVF,
-	"FDIVD",	LTYPE3, AFDIVD,
-	"FDIVRDP",	LTYPE3, AFDIVRDP,
-	"FDIVRW",	LTYPE3, AFDIVRW,
-	"FDIVRL",	LTYPE3, AFDIVRL,
-	"FDIVRF",	LTYPE3, AFDIVRF,
-	"FDIVRD",	LTYPE3, AFDIVRD,
-	"FXCHD",	LTYPE3, AFXCHD,
-	"FFREE",	LTYPE1, AFFREE,
-	"FLDCW",	LTYPE2, AFLDCW,
-	"FLDENV",	LTYPE1, AFLDENV,
-	"FRSTOR",	LTYPE2, AFRSTOR,
-	"FSAVE",	LTYPE1, AFSAVE,
-	"FSTCW",	LTYPE1, AFSTCW,
-	"FSTENV",	LTYPE1, AFSTENV,
-	"FSTSW",	LTYPE1, AFSTSW,
-	"F2XM1",	LTYPE0, AF2XM1,
-	"FABS",		LTYPE0, AFABS,
-	"FCHS",		LTYPE0, AFCHS,
-	"FCLEX",	LTYPE0, AFCLEX,
-	"FCOS",		LTYPE0, AFCOS,
-	"FDECSTP",	LTYPE0, AFDECSTP,
-	"FINCSTP",	LTYPE0, AFINCSTP,
-	"FINIT",	LTYPE0, AFINIT,
-	"FLD1",		LTYPE0, AFLD1,
-	"FLDL2E",	LTYPE0, AFLDL2E,
-	"FLDL2T",	LTYPE0, AFLDL2T,
-	"FLDLG2",	LTYPE0, AFLDLG2,
-	"FLDLN2",	LTYPE0, AFLDLN2,
-	"FLDPI",	LTYPE0, AFLDPI,
-	"FLDZ",		LTYPE0, AFLDZ,
-	"FNOP",		LTYPE0, AFNOP,
-	"FPATAN",	LTYPE0, AFPATAN,
-	"FPREM",	LTYPE0, AFPREM,
-	"FPREM1",	LTYPE0, AFPREM1,
-	"FPTAN",	LTYPE0, AFPTAN,
-	"FRNDINT",	LTYPE0, AFRNDINT,
-	"FSCALE",	LTYPE0, AFSCALE,
-	"FSIN",		LTYPE0, AFSIN,
-	"FSINCOS",	LTYPE0, AFSINCOS,
-	"FSQRT",	LTYPE0, AFSQRT,
-	"FTST",		LTYPE0, AFTST,
-	"FXAM",		LTYPE0, AFXAM,
-	"FXTRACT",	LTYPE0, AFXTRACT,
-	"FYL2X",	LTYPE0, AFYL2X,
-	"FYL2XP1",	LTYPE0, AFYL2XP1,
-
-	"ADDPD",	LTYPE3,	AADDPD,
-	"ADDPS",	LTYPE3,	AADDPS,
-	"ADDSD",	LTYPE3,	AADDSD,
-	"ADDSS",	LTYPE3,	AADDSS,
-	"ANDNPD",	LTYPE3,	AANDNPD,
-	"ANDNPS",	LTYPE3,	AANDNPS,
-	"ANDPD",	LTYPE3,	AANDPD,
-	"ANDPS",	LTYPE3,	AANDPS,
-	"CMPPD",	LTYPEXC,ACMPPD,
-	"CMPPS",	LTYPEXC,ACMPPS,
-	"CMPSD",	LTYPEXC,ACMPSD,
-	"CMPSS",	LTYPEXC,ACMPSS,
-	"COMISD",	LTYPE3,	ACOMISD,
-	"COMISS",	LTYPE3,	ACOMISS,
-	"CVTPL2PD",	LTYPE3,	ACVTPL2PD,
-	"CVTPL2PS",	LTYPE3,	ACVTPL2PS,
-	"CVTPD2PL",	LTYPE3,	ACVTPD2PL,
-	"CVTPD2PS",	LTYPE3,	ACVTPD2PS,
-	"CVTPS2PL",	LTYPE3,	ACVTPS2PL,
-	"PF2IW",	LTYPE3,	APF2IW,
-	"PF2IL",	LTYPE3,	APF2IL,
-	"PF2ID",	LTYPE3,	APF2IL,	/* syn */
-	"PI2FL",	LTYPE3,	API2FL,
-	"PI2FD",	LTYPE3,	API2FL,	/* syn */
-	"PI2FW",	LTYPE3,	API2FW,
-	"CVTPS2PD",	LTYPE3,	ACVTPS2PD,
-	"CVTSD2SL",	LTYPE3,	ACVTSD2SL,
-	"CVTSD2SQ",	LTYPE3,	ACVTSD2SQ,
-	"CVTSD2SS",	LTYPE3,	ACVTSD2SS,
-	"CVTSL2SD",	LTYPE3,	ACVTSL2SD,
-	"CVTSQ2SD",	LTYPE3,	ACVTSQ2SD,
-	"CVTSL2SS",	LTYPE3,	ACVTSL2SS,
-	"CVTSQ2SS",	LTYPE3,	ACVTSQ2SS,
-	"CVTSS2SD",	LTYPE3,	ACVTSS2SD,
-	"CVTSS2SL",	LTYPE3,	ACVTSS2SL,
-	"CVTSS2SQ",	LTYPE3,	ACVTSS2SQ,
-	"CVTTPD2PL",	LTYPE3,	ACVTTPD2PL,
-	"CVTTPS2PL",	LTYPE3,	ACVTTPS2PL,
-	"CVTTSD2SL",	LTYPE3,	ACVTTSD2SL,
-	"CVTTSD2SQ",	LTYPE3,	ACVTTSD2SQ,
-	"CVTTSS2SL",	LTYPE3,	ACVTTSS2SL,
-	"CVTTSS2SQ",	LTYPE3,	ACVTTSS2SQ,
-	"DIVPD",	LTYPE3,	ADIVPD,
-	"DIVPS",	LTYPE3,	ADIVPS,
-	"DIVSD",	LTYPE3,	ADIVSD,
-	"DIVSS",	LTYPE3,	ADIVSS,
-	"FXRSTOR",	LTYPE2,	AFXRSTOR,
-	"FXRSTOR64",	LTYPE2,	AFXRSTOR64,
-	"FXSAVE",	LTYPE1,	AFXSAVE,
-	"FXSAVE64",	LTYPE1,	AFXSAVE64,
-	"LDMXCSR",	LTYPE2,	ALDMXCSR,
-	"MASKMOVOU",	LTYPE3,	AMASKMOVOU,
-	"MASKMOVDQU",	LTYPE3,	AMASKMOVOU,	/* syn */
-	"MASKMOVQ",	LTYPE3,	AMASKMOVQ,
-	"MAXPD",	LTYPE3,	AMAXPD,
-	"MAXPS",	LTYPE3,	AMAXPS,
-	"MAXSD",	LTYPE3,	AMAXSD,
-	"MAXSS",	LTYPE3,	AMAXSS,
-	"MINPD",	LTYPE3,	AMINPD,
-	"MINPS",	LTYPE3,	AMINPS,
-	"MINSD",	LTYPE3,	AMINSD,
-	"MINSS",	LTYPE3,	AMINSS,
-	"MOVAPD",	LTYPE3,	AMOVAPD,
-	"MOVAPS",	LTYPE3,	AMOVAPS,
-	"MOVD",		LTYPE3,	AMOVQ,	/* syn */
-	"MOVDQ2Q",	LTYPE3,	AMOVQ,	/* syn */
-	"MOVO",		LTYPE3,	AMOVO,
-	"MOVOA",	LTYPE3,	AMOVO,	/* syn */
-	"MOVOU",	LTYPE3,	AMOVOU,
-	"MOVHLPS",	LTYPE3,	AMOVHLPS,
-	"MOVHPD",	LTYPE3,	AMOVHPD,
-	"MOVHPS",	LTYPE3,	AMOVHPS,
-	"MOVLHPS",	LTYPE3,	AMOVLHPS,
-	"MOVLPD",	LTYPE3,	AMOVLPD,
-	"MOVLPS",	LTYPE3,	AMOVLPS,
-	"MOVMSKPD",	LTYPE3,	AMOVMSKPD,
-	"MOVMSKPS",	LTYPE3,	AMOVMSKPS,
-	"MOVNTO",	LTYPE3,	AMOVNTO,
-	"MOVNTDQ",	LTYPE3,	AMOVNTO,	/* syn */
-	"MOVNTPD",	LTYPE3,	AMOVNTPD,
-	"MOVNTPS",	LTYPE3,	AMOVNTPS,
-	"MOVNTQ",	LTYPE3,	AMOVNTQ,
-	"MOVQOZX",	LTYPE3,	AMOVQOZX,
-	"MOVSD",	LTYPE3,	AMOVSD,
-	"MOVSS",	LTYPE3,	AMOVSS,
-	"MOVUPD",	LTYPE3,	AMOVUPD,
-	"MOVUPS",	LTYPE3,	AMOVUPS,
-	"MULPD",	LTYPE3,	AMULPD,
-	"MULPS",	LTYPE3,	AMULPS,
-	"MULSD",	LTYPE3,	AMULSD,
-	"MULSS",	LTYPE3,	AMULSS,
-	"ORPD",		LTYPE3,	AORPD,
-	"ORPS",		LTYPE3,	AORPS,
-	"PACKSSLW",	LTYPE3,	APACKSSLW,
-	"PACKSSWB",	LTYPE3,	APACKSSWB,
-	"PACKUSWB",	LTYPE3,	APACKUSWB,
-	"PADDB",	LTYPE3,	APADDB,
-	"PADDL",	LTYPE3,	APADDL,
-	"PADDQ",	LTYPE3,	APADDQ,
-	"PADDSB",	LTYPE3,	APADDSB,
-	"PADDSW",	LTYPE3,	APADDSW,
-	"PADDUSB",	LTYPE3,	APADDUSB,
-	"PADDUSW",	LTYPE3,	APADDUSW,
-	"PADDW",	LTYPE3,	APADDW,
-	"PAND",		LTYPE3, APAND,
-	"PANDB",	LTYPE3,	APANDB,
-	"PANDL",	LTYPE3,	APANDL,
-	"PANDSB",	LTYPE3,	APANDSB,
-	"PANDSW",	LTYPE3,	APANDSW,
-	"PANDUSB",	LTYPE3,	APANDUSB,
-	"PANDUSW",	LTYPE3,	APANDUSW,
-	"PANDW",	LTYPE3,	APANDW,
-	"PANDN",	LTYPE3, APANDN,
-	"PAVGB",	LTYPE3,	APAVGB,
-	"PAVGW",	LTYPE3,	APAVGW,
-	"PCMPEQB",	LTYPE3,	APCMPEQB,
-	"PCMPEQL",	LTYPE3,	APCMPEQL,
-	"PCMPEQW",	LTYPE3,	APCMPEQW,
-	"PCMPGTB",	LTYPE3,	APCMPGTB,
-	"PCMPGTL",	LTYPE3,	APCMPGTL,	
-	"PCMPGTW",	LTYPE3,	APCMPGTW,
-	"PEXTRW",	LTYPEX,	APEXTRW,
-	"PINSRW",	LTYPEX,	APINSRW,
-	"PMADDWL",	LTYPE3,	APMADDWL,
-	"PMAXSW",	LTYPE3,	APMAXSW,
-	"PMAXUB",	LTYPE3,	APMAXUB,
-	"PMINSW",	LTYPE3,	APMINSW,
-	"PMINUB",	LTYPE3,	APMINUB,
-	"PMOVMSKB",	LTYPE3,	APMOVMSKB,
-	"PMULHRW",	LTYPE3,	APMULHRW,
-	"PMULHUW",	LTYPE3,	APMULHUW,
-	"PMULHW",	LTYPE3,	APMULHW,
-	"PMULLW",	LTYPE3,	APMULLW,
-	"PMULULQ",	LTYPE3,	APMULULQ,
-	"POR",		LTYPE3,	APOR,
-	"PSADBW",	LTYPE3,	APSADBW,
-	"PSHUFHW",	LTYPEX,	APSHUFHW,
-	"PSHUFL",	LTYPEX,	APSHUFL,
-	"PSHUFLW",	LTYPEX,	APSHUFLW,
-	"PSHUFW",	LTYPEX, APSHUFW,
-	"PSLLO",	LTYPE3,	APSLLO,
-	"PSLLDQ",	LTYPE3,	APSLLO,	/* syn */
-	"PSLLL",	LTYPE3,	APSLLL,
-	"PSLLQ",	LTYPE3,	APSLLQ,
-	"PSLLW",	LTYPE3,	APSLLW,
-	"PSRAL",	LTYPE3,	APSRAL,
-	"PSRAW",	LTYPE3,	APSRAW,
-	"PSRLO",	LTYPE3,	APSRLO,
-	"PSRLDQ",	LTYPE3,	APSRLO,	/* syn */
-	"PSRLL",	LTYPE3,	APSRLL,
-	"PSRLQ",	LTYPE3,	APSRLQ,
-	"PSRLW",	LTYPE3,	APSRLW,
-	"PSUBB",	LTYPE3,	APSUBB,
-	"PSUBL",	LTYPE3,	APSUBL,
-	"PSUBQ",	LTYPE3,	APSUBQ,
-	"PSUBSB",	LTYPE3,	APSUBSB,
-	"PSUBSW",	LTYPE3,	APSUBSW,
-	"PSUBUSB",	LTYPE3,	APSUBUSB,
-	"PSUBUSW",	LTYPE3,	APSUBUSW,
-	"PSUBW",	LTYPE3,	APSUBW,
-	"PUNPCKHBW",	LTYPE3,	APUNPCKHBW,
-	"PUNPCKHLQ",	LTYPE3,	APUNPCKHLQ,
-	"PUNPCKHQDQ",	LTYPE3,	APUNPCKHQDQ,
-	"PUNPCKHWL",	LTYPE3,	APUNPCKHWL,
-	"PUNPCKLBW",	LTYPE3,	APUNPCKLBW,
-	"PUNPCKLLQ",	LTYPE3,	APUNPCKLLQ,
-	"PUNPCKLQDQ",	LTYPE3,	APUNPCKLQDQ,
-	"PUNPCKLWL",	LTYPE3,	APUNPCKLWL,
-	"PXOR",		LTYPE3,	APXOR,
-	"RCPPS",	LTYPE3,	ARCPPS,
-	"RCPSS",	LTYPE3,	ARCPSS,
-	"RSQRTPS",	LTYPE3,	ARSQRTPS,
-	"RSQRTSS",	LTYPE3,	ARSQRTSS,
-	"SHUFPD",	LTYPEX,	ASHUFPD,
-	"SHUFPS",	LTYPEX,	ASHUFPS,
-	"SQRTPD",	LTYPE3,	ASQRTPD,
-	"SQRTPS",	LTYPE3,	ASQRTPS,
-	"SQRTSD",	LTYPE3,	ASQRTSD,
-	"SQRTSS",	LTYPE3,	ASQRTSS,
-	"STMXCSR",	LTYPE1,	ASTMXCSR,
-	"SUBPD",	LTYPE3,	ASUBPD,
-	"SUBPS",	LTYPE3,	ASUBPS,
-	"SUBSD",	LTYPE3,	ASUBSD,
-	"SUBSS",	LTYPE3,	ASUBSS,
-	"UCOMISD",	LTYPE3,	AUCOMISD,
-	"UCOMISS",	LTYPE3,	AUCOMISS,
-	"UNPCKHPD",	LTYPE3,	AUNPCKHPD,
-	"UNPCKHPS",	LTYPE3,	AUNPCKHPS,
-	"UNPCKLPD",	LTYPE3,	AUNPCKLPD,
-	"UNPCKLPS",	LTYPE3,	AUNPCKLPS,
-	"XORPD",	LTYPE3,	AXORPD,
-	"XORPS",	LTYPE3,	AXORPS,
-
-	0
-};
-
-void
-cinit(void)
-{
-	Sym *s;
-	int i;
-
-	nullgen.sym = S;
-	nullgen.offset = 0;
-	if(FPCHIP)
-		nullgen.dval = 0;
-	for(i=0; i<sizeof(nullgen.sval); i++)
-		nullgen.sval[i] = 0;
-	nullgen.type = D_NONE;
-	nullgen.index = D_NONE;
-	nullgen.scale = 0;
-
-	nerrors = 0;
-	iostack = I;
-	iofree = I;
-	peekc = IGN;
-	nhunk = 0;
-	for(i=0; i<NHASH; i++)
-		hash[i] = S;
-	for(i=0; itab[i].name; i++) {
-		s = slookup(itab[i].name);
-		if(s->type != LNAME)
-			yyerror("double initialization %s", itab[i].name);
-		s->type = itab[i].type;
-		s->value = itab[i].value;
-	}
-
-	pathname = allocn(pathname, 0, 100);
-	if(mygetwd(pathname, 99) == 0) {
-		pathname = allocn(pathname, 100, 900);
-		if(mygetwd(pathname, 999) == 0)
-			strcpy(pathname, "/???");
-	}
-}
-
-void
-checkscale(int scale)
-{
-
-	switch(scale) {
-	case 1:
-	case 2:
-	case 4:
-	case 8:
-		return;
-	}
-	yyerror("scale must be 1248: %d", scale);
-}
-
-void
-syminit(Sym *s)
-{
-
-	s->type = LNAME;
-	s->value = 0;
-}
-
-void
-cclean(void)
-{
-	Gen2 g2;
-
-	g2.from = nullgen;
-	g2.to = nullgen;
-	outcode(AEND, &g2);
-	Bflush(&obuf);
-}
-
-void
-zname(char *n, int t, int s)
-{
-
-	Bputc(&obuf, ANAME);		/* as(2) */
-	Bputc(&obuf, ANAME>>8);
-	Bputc(&obuf, t);		/* type */
-	Bputc(&obuf, s);		/* sym */
-	while(*n) {
-		Bputc(&obuf, *n);
-		n++;
-	}
-	Bputc(&obuf, 0);
-}
-
-void
-zaddr(Gen *a, int s)
-{
-	int32_t l;
-	int i, t;
-	char *n;
-	Ieee e;
-
-	t = 0;
-	if(a->index != D_NONE || a->scale != 0)
-		t |= T_INDEX;
-	if(a->offset != 0) {
-		t |= T_OFFSET;
-		l = a->offset;
-		if((int64_t)l != a->offset)
-			t |= T_64;
-	}
-	if(s != 0)
-		t |= T_SYM;
-
-	switch(a->type) {
-	default:
-		t |= T_TYPE;
-		break;
-	case D_FCONST:
-		t |= T_FCONST;
-		break;
-	case D_SCONST:
-		t |= T_SCONST;
-		break;
-	case D_NONE:
-		break;
-	}
-	Bputc(&obuf, t);
-
-	if(t & T_INDEX) {	/* implies index, scale */
-		Bputc(&obuf, a->index);
-		Bputc(&obuf, a->scale);
-	}
-	if(t & T_OFFSET) {	/* implies offset */
-		l = a->offset;
-		Bputc(&obuf, l);
-		Bputc(&obuf, l>>8);
-		Bputc(&obuf, l>>16);
-		Bputc(&obuf, l>>24);
-		if(t & T_64) {
-			l = a->offset>>32;
-			Bputc(&obuf, l);
-			Bputc(&obuf, l>>8);
-			Bputc(&obuf, l>>16);
-			Bputc(&obuf, l>>24);
-		}
-	}
-	if(t & T_SYM)		/* implies sym */
-		Bputc(&obuf, s);
-	if(t & T_FCONST) {
-		ieeedtod(&e, a->dval);
-		l = e.l;
-		Bputc(&obuf, l);
-		Bputc(&obuf, l>>8);
-		Bputc(&obuf, l>>16);
-		Bputc(&obuf, l>>24);
-		l = e.h;
-		Bputc(&obuf, l);
-		Bputc(&obuf, l>>8);
-		Bputc(&obuf, l>>16);
-		Bputc(&obuf, l>>24);
-		return;
-	}
-	if(t & T_SCONST) {
-		n = a->sval;
-		for(i=0; i<NSNAME; i++) {
-			Bputc(&obuf, *n);
-			n++;
-		}
-		return;
-	}
-	if(t & T_TYPE)
-		Bputc(&obuf, a->type);
-}
-
-void
-outcode(int a, Gen2 *g2)
-{
-	int sf, st, t;
-	Sym *s;
-
-	if(pass == 1)
-		goto out;
-
-jackpot:
-	sf = 0;
-	s = g2->from.sym;
-	while(s != S) {
-		sf = s->sym;
-		if(sf < 0 || sf >= NSYM)
-			sf = 0;
-		t = g2->from.type;
-		if(t == D_ADDR)
-			t = g2->from.index;
-		if(h[sf].type == t)
-		if(h[sf].sym == s)
-			break;
-		zname(s->name, t, sym);
-		s->sym = sym;
-		h[sym].sym = s;
-		h[sym].type = t;
-		sf = sym;
-		sym++;
-		if(sym >= NSYM)
-			sym = 1;
-		break;
-	}
-	st = 0;
-	s = g2->to.sym;
-	while(s != S) {
-		st = s->sym;
-		if(st < 0 || st >= NSYM)
-			st = 0;
-		t = g2->to.type;
-		if(t == D_ADDR)
-			t = g2->to.index;
-		if(h[st].type == t)
-		if(h[st].sym == s)
-			break;
-		zname(s->name, t, sym);
-		s->sym = sym;
-		h[sym].sym = s;
-		h[sym].type = t;
-		st = sym;
-		sym++;
-		if(sym >= NSYM)
-			sym = 1;
-		if(st == sf)
-			goto jackpot;
-		break;
-	}
-	Bputc(&obuf, a);
-	Bputc(&obuf, a>>8);
-	Bputc(&obuf, lineno);
-	Bputc(&obuf, lineno>>8);
-	Bputc(&obuf, lineno>>16);
-	Bputc(&obuf, lineno>>24);
-	zaddr(&g2->from, sf);
-	zaddr(&g2->to, st);
-
-out:
-	if(a != AGLOBL && a != ADATA && a != AMODE)
-		pc++;
-}
-
-void
-outhist(void)
-{
-	Gen g;
-	Hist *h;
-	char *p, *q, *op, c;
-	int n;
-
-	g = nullgen;
-	c = pathchar();
-	for(h = hist; h != H; h = h->link) {
-		p = h->name;
-		op = 0;
-		/* on windows skip drive specifier in pathname */
-		if(systemtype(Windows) && p && p[1] == ':'){
-			p += 2;
-			c = *p;
-		}
-		if(p && p[0] != c && h->offset == 0 && pathname){
-			/* on windows skip drive specifier in pathname */
-			if(systemtype(Windows) && pathname[1] == ':') {
-				op = p;
-				p = pathname+2;
-				c = *p;
-			} else if(pathname[0] == c){
-				op = p;
-				p = pathname;
-			}
-		}
-		while(p) {
-			q = strchr(p, c);
-			if(q) {
-				n = q-p;
-				if(n == 0){
-					n = 1;	/* leading "/" */
-					*p = '/';	/* don't emit "\" on windows */
-				}
-				q++;
-			} else {
-				n = strlen(p);
-				q = 0;
-			}
-			if(n) {
-				Bputc(&obuf, ANAME);
-				Bputc(&obuf, ANAME>>8);
-				Bputc(&obuf, D_FILE);	/* type */
-				Bputc(&obuf, 1);	/* sym */
-				Bputc(&obuf, '<');
-				Bwrite(&obuf, p, n);
-				Bputc(&obuf, 0);
-			}
-			p = q;
-			if(p == 0 && op) {
-				p = op;
-				op = 0;
-			}
-		}
-		g.offset = h->offset;
-
-		Bputc(&obuf, AHISTORY);
-		Bputc(&obuf, AHISTORY>>8);
-		Bputc(&obuf, h->line);
-		Bputc(&obuf, h->line>>8);
-		Bputc(&obuf, h->line>>16);
-		Bputc(&obuf, h->line>>24);
-		zaddr(&nullgen, 0);
-		zaddr(&g, 0);
-	}
-}
-
-#include "../cc/lexbody"
-#include "../cc/macbody"
-#include "../cc/compat"

+ 0 - 26
sys/src/cmd/6a/mkfile

@@ -1,26 +0,0 @@
-</$objtype/mkfile
-
-TARG=6a
-OFILES=\
-	y.tab.$O\
-	lex.$O\
-
-HFILES=\
-	../6c/6.out.h\
-	y.tab.h\
-	a.h\
-
-YFILES=a.y\
-
-BIN=/$objtype/bin
-UPDATE=\
-	mkfile\
-	a.y\
-	lex.c\
-	a.h\
-	${TARG:%=/386/bin/%}\
-
-< /sys/src/cmd/mkone
-YFLAGS=-D1 -d
-
-lex.$O:	../cc/macbody ../cc/lexbody ../cc/compat

+ 0 - 829
sys/src/cmd/6c/6.out.h

@@ -1,829 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#define	NSYM	50
-#define	NSNAME	8
-#define NOPROF	(1<<0)
-#define DUPOK	(1<<1)
-
-/*
- *	amd64
- */
-
-enum	as
-{
-	AXXX,
-	AAAA,
-	AAAD,
-	AAAM,
-	AAAS,
-	AADCB,
-	AADCL,
-	AADCW,
-	AADDB,
-	AADDL,
-	AADDW,
-	AADJSP,
-	AANDB,
-	AANDL,
-	AANDW,
-	AARPL,
-	ABOUNDL,
-	ABOUNDW,
-	ABSFL,
-	ABSFW,
-	ABSRL,
-	ABSRW,
-	ABTL,
-	ABTW,
-	ABTCL,
-	ABTCW,
-	ABTRL,
-	ABTRW,
-	ABTSL,
-	ABTSW,
-	ABYTE,
-	ACALL,
-	ACLC,
-	ACLD,
-	ACLI,
-	ACLTS,
-	ACMC,
-	ACMPB,
-	ACMPL,
-	ACMPW,
-	ACMPSB,
-	ACMPSL,
-	ACMPSW,
-	ADAA,
-	ADAS,
-	ADATA,
-	ADECB,
-	ADECL,
-	ADECQ,
-	ADECW,
-	ADIVB,
-	ADIVL,
-	ADIVW,
-	AENTER,
-	AGLOBL,
-	AGOK,
-	AHISTORY,
-	AHLT,
-	AIDIVB,
-	AIDIVL,
-	AIDIVW,
-	AIMULB,
-	AIMULL,
-	AIMULW,
-	AINB,
-	AINL,
-	AINW,
-	AINCB,
-	AINCL,
-	AINCQ,
-	AINCW,
-	AINSB,
-	AINSL,
-	AINSW,
-	AINT,
-	AINTO,
-	AIRETL,
-	AIRETW,
-	AJCC,
-	AJCS,
-	AJCXZ,
-	AJEQ,
-	AJGE,
-	AJGT,
-	AJHI,
-	AJLE,
-	AJLS,
-	AJLT,
-	AJMI,
-	AJMP,
-	AJNE,
-	AJOC,
-	AJOS,
-	AJPC,
-	AJPL,
-	AJPS,
-	ALAHF,
-	ALARL,
-	ALARW,
-	ALEAL,
-	ALEAW,
-	ALEAVEL,
-	ALEAVEW,
-	ALOCK,
-	ALODSB,
-	ALODSL,
-	ALODSW,
-	ALONG,
-	ALOOP,
-	ALOOPEQ,
-	ALOOPNE,
-	ALSLL,
-	ALSLW,
-	AMOVB,
-	AMOVL,
-	AMOVW,
-	AMOVBLSX,
-	AMOVBLZX,
-	AMOVBQSX,
-	AMOVBQZX,
-	AMOVBWSX,
-	AMOVBWZX,
-	AMOVWLSX,
-	AMOVWLZX,
-	AMOVWQSX,
-	AMOVWQZX,
-	AMOVSB,
-	AMOVSL,
-	AMOVSW,
-	AMULB,
-	AMULL,
-	AMULW,
-	ANAME,
-	ANEGB,
-	ANEGL,
-	ANEGW,
-	ANOP,
-	ANOTB,
-	ANOTL,
-	ANOTW,
-	AORB,
-	AORL,
-	AORW,
-	AOUTB,
-	AOUTL,
-	AOUTW,
-	AOUTSB,
-	AOUTSL,
-	AOUTSW,
-	APOPAL,
-	APOPAW,
-	APOPFL,
-	APOPFW,
-	APOPL,
-	APOPW,
-	APUSHAL,
-	APUSHAW,
-	APUSHFL,
-	APUSHFW,
-	APUSHL,
-	APUSHW,
-	ARCLB,
-	ARCLL,
-	ARCLW,
-	ARCRB,
-	ARCRL,
-	ARCRW,
-	AREP,
-	AREPN,
-	ARET,
-	AROLB,
-	AROLL,
-	AROLW,
-	ARORB,
-	ARORL,
-	ARORW,
-	ASAHF,
-	ASALB,
-	ASALL,
-	ASALW,
-	ASARB,
-	ASARL,
-	ASARW,
-	ASBBB,
-	ASBBL,
-	ASBBW,
-	ASCASB,
-	ASCASL,
-	ASCASW,
-	ASETCC,
-	ASETCS,
-	ASETEQ,
-	ASETGE,
-	ASETGT,
-	ASETHI,
-	ASETLE,
-	ASETLS,
-	ASETLT,
-	ASETMI,
-	ASETNE,
-	ASETOC,
-	ASETOS,
-	ASETPC,
-	ASETPL,
-	ASETPS,
-	ACDQ,
-	ACWD,
-	ASHLB,
-	ASHLL,
-	ASHLW,
-	ASHRB,
-	ASHRL,
-	ASHRW,
-	ASTC,
-	ASTD,
-	ASTI,
-	ASTOSB,
-	ASTOSL,
-	ASTOSW,
-	ASUBB,
-	ASUBL,
-	ASUBW,
-	ASYSCALL,
-	ATESTB,
-	ATESTL,
-	ATESTW,
-	ATEXT,
-	AVERR,
-	AVERW,
-	AWAIT,
-	AWORD,
-	AXCHGB,
-	AXCHGL,
-	AXCHGW,
-	AXLAT,
-	AXORB,
-	AXORL,
-	AXORW,
-
-	AFMOVB,
-	AFMOVBP,
-	AFMOVD,
-	AFMOVDP,
-	AFMOVF,
-	AFMOVFP,
-	AFMOVL,
-	AFMOVLP,
-	AFMOVV,
-	AFMOVVP,
-	AFMOVW,
-	AFMOVWP,
-	AFMOVX,
-	AFMOVXP,
-
-	AFCOMB,
-	AFCOMBP,
-	AFCOMD,
-	AFCOMDP,
-	AFCOMDPP,
-	AFCOMF,
-	AFCOMFP,
-	AFCOML,
-	AFCOMLP,
-	AFCOMW,
-	AFCOMWP,
-	AFUCOM,
-	AFUCOMP,
-	AFUCOMPP,
-
-	AFADDDP,
-	AFADDW,
-	AFADDL,
-	AFADDF,
-	AFADDD,
-
-	AFMULDP,
-	AFMULW,
-	AFMULL,
-	AFMULF,
-	AFMULD,
-
-	AFSUBDP,
-	AFSUBW,
-	AFSUBL,
-	AFSUBF,
-	AFSUBD,
-
-	AFSUBRDP,
-	AFSUBRW,
-	AFSUBRL,
-	AFSUBRF,
-	AFSUBRD,
-
-	AFDIVDP,
-	AFDIVW,
-	AFDIVL,
-	AFDIVF,
-	AFDIVD,
-
-	AFDIVRDP,
-	AFDIVRW,
-	AFDIVRL,
-	AFDIVRF,
-	AFDIVRD,
-
-	AFXCHD,
-	AFFREE,
-
-	AFLDCW,
-	AFLDENV,
-	AFRSTOR,
-	AFSAVE,
-	AFSTCW,
-	AFSTENV,
-	AFSTSW,
-
-	AF2XM1,
-	AFABS,
-	AFCHS,
-	AFCLEX,
-	AFCOS,
-	AFDECSTP,
-	AFINCSTP,
-	AFINIT,
-	AFLD1,
-	AFLDL2E,
-	AFLDL2T,
-	AFLDLG2,
-	AFLDLN2,
-	AFLDPI,
-	AFLDZ,
-	AFNOP,
-	AFPATAN,
-	AFPREM,
-	AFPREM1,
-	AFPTAN,
-	AFRNDINT,
-	AFSCALE,
-	AFSIN,
-	AFSINCOS,
-	AFSQRT,
-	AFTST,
-	AFXAM,
-	AFXTRACT,
-	AFYL2X,
-	AFYL2XP1,
-
-	AEND,
-
-	ADYNT,
-	AINIT,
-
-	ASIGNAME,
-
-	/* extra 32-bit operations */
-	ACMPXCHGB,
-	ACMPXCHGL,
-	ACMPXCHGW,
-	ACMPXCHG8B,
-	ACPUID,
-	AINVD,
-	AINVLPG,
-	ALFENCE,
-	AMFENCE,
-	AMOVNTIL,
-	ARDMSR,
-	ARDPMC,
-	ARDTSC,
-	ARSM,
-	ASFENCE,
-	ASYSRET,
-	AWBINVD,
-	AWRMSR,
-	AXADDB,
-	AXADDL,
-	AXADDW,
-
-	/* conditional move */
-	ACMOVLCC,
-	ACMOVLCS,
-	ACMOVLEQ,
-	ACMOVLGE,
-	ACMOVLGT,
-	ACMOVLHI,
-	ACMOVLLE,
-	ACMOVLLS,
-	ACMOVLLT,
-	ACMOVLMI,
-	ACMOVLNE,
-	ACMOVLOC,
-	ACMOVLOS,
-	ACMOVLPC,
-	ACMOVLPL,
-	ACMOVLPS,
-	ACMOVQCC,
-	ACMOVQCS,
-	ACMOVQEQ,
-	ACMOVQGE,
-	ACMOVQGT,
-	ACMOVQHI,
-	ACMOVQLE,
-	ACMOVQLS,
-	ACMOVQLT,
-	ACMOVQMI,
-	ACMOVQNE,
-	ACMOVQOC,
-	ACMOVQOS,
-	ACMOVQPC,
-	ACMOVQPL,
-	ACMOVQPS,
-	ACMOVWCC,
-	ACMOVWCS,
-	ACMOVWEQ,
-	ACMOVWGE,
-	ACMOVWGT,
-	ACMOVWHI,
-	ACMOVWLE,
-	ACMOVWLS,
-	ACMOVWLT,
-	ACMOVWMI,
-	ACMOVWNE,
-	ACMOVWOC,
-	ACMOVWOS,
-	ACMOVWPC,
-	ACMOVWPL,
-	ACMOVWPS,
-
-	/* 64-bit */
-	AADCQ,
-	AADDQ,
-	AANDQ,
-	ABSFQ,
-	ABSRQ,
-	ABTCQ,
-	ABTQ,
-	ABTRQ,
-	ABTSQ,
-	ACMPQ,
-	ACMPSQ,
-	ACMPXCHGQ,
-	ACQO,
-	ADIVQ,
-	AIDIVQ,
-	AIMULQ,
-	AIRETQ,
-	ALEAQ,
-	ALEAVEQ,
-	ALODSQ,
-	AMOVQ,
-	AMOVLQSX,
-	AMOVLQZX,
-	AMOVNTIQ,
-	AMOVSQ,
-	AMULQ,
-	ANEGQ,
-	ANOTQ,
-	AORQ,
-	APOPFQ,
-	APOPQ,
-	APUSHFQ,
-	APUSHQ,
-	ARCLQ,
-	ARCRQ,
-	AROLQ,
-	ARORQ,
-	AQUAD,
-	ASALQ,
-	ASARQ,
-	ASBBQ,
-	ASCASQ,
-	ASHLQ,
-	ASHRQ,
-	ASTOSQ,
-	ASUBQ,
-	ATESTQ,
-	AXADDQ,
-	AXCHGQ,
-	AXORQ,
-
-	/* media */
-	AADDPD,
-	AADDPS,
-	AADDSD,
-	AADDSS,
-	AANDNPD,
-	AANDNPS,
-	AANDPD,
-	AANDPS,
-	ACMPPD,
-	ACMPPS,
-	ACMPSD,
-	ACMPSS,
-	ACOMISD,
-	ACOMISS,
-	ACVTPD2PL,
-	ACVTPD2PS,
-	ACVTPL2PD,
-	ACVTPL2PS,
-	ACVTPS2PD,
-	ACVTPS2PL,
-	ACVTSD2SL,
-	ACVTSD2SQ,
-	ACVTSD2SS,
-	ACVTSL2SD,
-	ACVTSL2SS,
-	ACVTSQ2SD,
-	ACVTSQ2SS,
-	ACVTSS2SD,
-	ACVTSS2SL,
-	ACVTSS2SQ,
-	ACVTTPD2PL,
-	ACVTTPS2PL,
-	ACVTTSD2SL,
-	ACVTTSD2SQ,
-	ACVTTSS2SL,
-	ACVTTSS2SQ,
-	ADIVPD,
-	ADIVPS,
-	ADIVSD,
-	ADIVSS,
-	AEMMS,
-	AFXRSTOR,
-	AFXRSTOR64,
-	AFXSAVE,
-	AFXSAVE64,
-	ALDMXCSR,
-	AMASKMOVOU,
-	AMASKMOVQ,
-	AMAXPD,
-	AMAXPS,
-	AMAXSD,
-	AMAXSS,
-	AMINPD,
-	AMINPS,
-	AMINSD,
-	AMINSS,
-	AMOVAPD,
-	AMOVAPS,
-	AMOVOU,
-	AMOVHLPS,
-	AMOVHPD,
-	AMOVHPS,
-	AMOVLHPS,
-	AMOVLPD,
-	AMOVLPS,
-	AMOVMSKPD,
-	AMOVMSKPS,
-	AMOVNTO,
-	AMOVNTPD,
-	AMOVNTPS,
-	AMOVNTQ,
-	AMOVO,
-	AMOVQOZX,
-	AMOVSD,
-	AMOVSS,
-	AMOVUPD,
-	AMOVUPS,
-	AMULPD,
-	AMULPS,
-	AMULSD,
-	AMULSS,
-	AORPD,
-	AORPS,
-	APACKSSLW,
-	APACKSSWB,
-	APACKUSWB,
-	APADDB,
-	APADDL,
-	APADDQ,
-	APADDSB,
-	APADDSW,
-	APADDUSB,
-	APADDUSW,
-	APADDW,
-	APANDB,
-	APANDL,
-	APANDSB,
-	APANDSW,
-	APANDUSB,
-	APANDUSW,
-	APANDW,
-	APAND,
-	APANDN,
-	APAVGB,
-	APAVGW,
-	APCMPEQB,
-	APCMPEQL,
-	APCMPEQW,
-	APCMPGTB,
-	APCMPGTL,
-	APCMPGTW,
-	APEXTRW,
-	APFACC,
-	APFADD,
-	APFCMPEQ,
-	APFCMPGE,
-	APFCMPGT,
-	APFMAX,
-	APFMIN,
-	APFMUL,
-	APFNACC,
-	APFPNACC,
-	APFRCP,
-	APFRCPIT1,
-	APFRCPI2T,
-	APFRSQIT1,
-	APFRSQRT,
-	APFSUB,
-	APFSUBR,
-	APINSRW,
-	APMADDWL,
-	APMAXSW,
-	APMAXUB,
-	APMINSW,
-	APMINUB,
-	APMOVMSKB,
-	APMULHRW,
-	APMULHUW,
-	APMULHW,
-	APMULLW,
-	APMULULQ,
-	APOR,
-	APSADBW,
-	APSHUFHW,
-	APSHUFL,
-	APSHUFLW,
-	APSHUFW,
-	APSLLO,
-	APSLLL,
-	APSLLQ,
-	APSLLW,
-	APSRAL,
-	APSRAW,
-	APSRLO,
-	APSRLL,
-	APSRLQ,
-	APSRLW,
-	APSUBB,
-	APSUBL,
-	APSUBQ,
-	APSUBSB,
-	APSUBSW,
-	APSUBUSB,
-	APSUBUSW,
-	APSUBW,
-	APSWAPL,
-	APUNPCKHBW,
-	APUNPCKHLQ,
-	APUNPCKHQDQ,
-	APUNPCKHWL,
-	APUNPCKLBW,
-	APUNPCKLLQ,
-	APUNPCKLQDQ,
-	APUNPCKLWL,
-	APXOR,
-	ARCPPS,
-	ARCPSS,
-	ARSQRTPS,
-	ARSQRTSS,
-	ASHUFPD,
-	ASHUFPS,
-	ASQRTPD,
-	ASQRTPS,
-	ASQRTSD,
-	ASQRTSS,
-	ASTMXCSR,
-	ASUBPD,
-	ASUBPS,
-	ASUBSD,
-	ASUBSS,
-	AUCOMISD,
-	AUCOMISS,
-	AUNPCKHPD,
-	AUNPCKHPS,
-	AUNPCKLPD,
-	AUNPCKLPS,
-	AXORPD,
-	AXORPS,
-
-	APF2IW,
-	APF2IL,
-	API2FW,
-	API2FL,
-	ARETFW,
-	ARETFL,
-	ARETFQ,
-	ASWAPGS,
-
-	AMODE,
-
-	ALAST
-};
-
-enum
-{
-
-	D_AL		= 0,
-	D_CL,
-	D_DL,
-	D_BL,
-	D_SPB,
-	D_BPB,
-	D_SIB,
-	D_DIB,
-	D_R8B,
-	D_R9B,
-	D_R10B,
-	D_R11B,
-	D_R12B,
-	D_R13B,
-	D_R14B,
-	D_R15B,
-
-	D_AX		= 16,
-	D_CX,
-	D_DX,
-	D_BX,
-	D_SP,
-	D_BP,
-	D_SI,
-	D_DI,
-	D_R8,
-	D_R9,
-	D_R10,
-	D_R11,
-	D_R12,
-	D_R13,
-	D_R14,
-	D_R15,
-
-	D_AH		= 32,
-	D_CH,
-	D_DH,
-	D_BH,
-
-	D_F0		= 36,
-
-	D_M0		= 44,
-
-	D_X0		= 52,
-
-	D_CS		= 68,
-	D_SS,
-	D_DS,
-	D_ES,
-	D_FS,
-	D_GS,
-
-	D_GDTR,		/* global descriptor table register */
-	D_IDTR,		/* interrupt descriptor table register */
-	D_LDTR,		/* local descriptor table register */
-	D_MSW,		/* machine status word */
-	D_TASK,		/* task register */
-
-	D_CR		= 79,
-	D_DR		= 95,
-	D_TR		= 103,
-
-	D_NONE		= 111,
-
-	D_BRANCH	= 112,
-	D_EXTERN	= 113,
-	D_STATIC		= 114,
-	D_AUTO		= 115,
-	D_PARAM		= 116,
-	D_CONST		= 117,
-	D_FCONST	= 118,
-	D_SCONST	= 119,
-	D_ADDR		= 120,
-
-	D_FILE,
-	D_FILE1,
-
-	D_INDIR,	/* additive */
-
-	T_TYPE		= 1<<0,
-	T_INDEX		= 1<<1,
-	T_OFFSET	= 1<<2,
-	T_FCONST	= 1<<3,
-	T_SYM		= 1<<4,
-	T_SCONST	= 1<<5,
-	T_64	= 1<<6,
-
-	REGARG		= D_BP,	/* MIGHT CHANGE */
-	REGRET		= D_AX,
-	FREGRET		= D_X0,
-	REGSP		= D_SP,
-	REGTMP		= D_DI,
-	REGEXT		= D_R15,	/* compiler allocates external registers R15 down */
-	FREGMIN		= D_X0+5,	/* first register variable */
-	FREGEXT		= D_X0+7	/* first external register */
-};
-
-/*
- * this is the ranlib header
- */
-#define	SYMDEF	"__.SYMDEF"
-
-/*
- * this is the simulated IEEE floating point
- */
-typedef	struct	ieee	Ieee;
-struct	ieee
-{
-	long	l;	/* contains ls-man	0xffffffff */
-	long	h;	/* contains sign	0x80000000
-				    exp		0x7ff00000
-				    ms-man	0x000fffff */
-};

+ 0 - 1972
sys/src/cmd/6c/cgen.c

@@ -1,1972 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "gc.h"
-
-/* ,x/^(print|prtree)\(/i/\/\/ */
-int castup(Type*, Type*);
-void checkmask(Node*, Node*);
-
-void
-cgen(Node *n, Node *nn)
-{
-	Node *l, *r, *t;
-	Prog *p1;
-	Node nod, nod1, nod2, nod3, nod4;
-	int o, hardleft;
-	int32_t v, curs;
-	int64_t c;
-
-	if(debug['g']) {
-		prtree(nn, "cgen lhs");
-		prtree(n, "cgen");
-	}
-	if(n == Z || n->type == T)
-		return;
-	if(typesu[n->type->etype]) {
-		sugen(n, nn, n->type->width);
-		return;
-	}
-	l = n->left;
-	r = n->right;
-	o = n->op;
-	if(n->addable >= INDEXED) {
-		if(nn == Z) {
-			switch(o) {
-			default:
-				nullwarn(Z, Z);
-				break;
-			case OINDEX:
-				nullwarn(l, r);
-				break;
-			}
-			return;
-		}
-		gmove(n, nn);
-		return;
-	}
-	curs = cursafe;
-
-	if(l->complex >= FNX)
-	if(r != Z && r->complex >= FNX)
-	switch(o) {
-	default:
-		if(cond(o) && typesu[l->type->etype])
-			break;
-
-		regret(&nod, r);
-		cgen(r, &nod);
-
-		regsalloc(&nod1, r);
-		gmove(&nod, &nod1);
-
-		regfree(&nod);
-		nod = *n;
-		nod.right = &nod1;
-
-		cgen(&nod, nn);
-		return;
-
-	case OFUNC:
-	case OCOMMA:
-	case OANDAND:
-	case OOROR:
-	case OCOND:
-	case ODOT:
-		break;
-	}
-
-	hardleft = l->addable < INDEXED || l->complex >= FNX;
-	switch(o) {
-	default:
-		diag(n, "unknown op in cgen: %O", o);
-		break;
-
-	case ONEG:
-	case OCOM:
-		if(nn == Z) {
-			nullwarn(l, Z);
-			break;
-		}
-		regalloc(&nod, l, nn);
-		cgen(l, &nod);
-		gopcode(o, n->type, Z, &nod);
-		gmove(&nod, nn);
-		regfree(&nod);
-		break;
-
-	case OAS:
-		if(l->op == OBIT)
-			goto bitas;
-		if(!hardleft) {
-			if(nn != Z || r->addable < INDEXED || hardconst(r)) {
-				if(r->complex >= FNX && nn == Z)
-					regret(&nod, r);
-				else
-					regalloc(&nod, r, nn);
-				cgen(r, &nod);
-				gmove(&nod, l);
-				if(nn != Z)
-					gmove(&nod, nn);
-				regfree(&nod);
-			} else
-				gmove(r, l);
-			break;
-		}
-		if(l->complex >= r->complex) {
-			if(l->op == OINDEX && immconst(r)) {
-				gmove(r, l);
-				break;
-			}
-			reglcgen(&nod1, l, Z);
-			if(r->addable >= INDEXED && !hardconst(r)) {
-				gmove(r, &nod1);
-				if(nn != Z)
-					gmove(r, nn);
-				regfree(&nod1);
-				break;
-			}
-			regalloc(&nod, r, nn);
-			cgen(r, &nod);
-		} else {
-			regalloc(&nod, r, nn);
-			cgen(r, &nod);
-			reglcgen(&nod1, l, Z);
-		}
-		gmove(&nod, &nod1);
-		regfree(&nod);
-		regfree(&nod1);
-		break;
-
-	bitas:
-		n = l->left;
-		regalloc(&nod, r, nn);
-		if(l->complex >= r->complex) {
-			reglcgen(&nod1, n, Z);
-			cgen(r, &nod);
-		} else {
-			cgen(r, &nod);
-			reglcgen(&nod1, n, Z);
-		}
-		regalloc(&nod2, n, Z);
-		gmove(&nod1, &nod2);
-		bitstore(l, &nod, &nod1, &nod2, nn);
-		break;
-
-	case OBIT:
-		if(nn == Z) {
-			nullwarn(l, Z);
-			break;
-		}
-		bitload(n, &nod, Z, Z, nn);
-		gmove(&nod, nn);
-		regfree(&nod);
-		break;
-
-	case OLSHR:
-	case OASHL:
-	case OASHR:
-		if(nn == Z) {
-			nullwarn(l, r);
-			break;
-		}
-		if(r->op == OCONST) {
-			if(r->vconst == 0) {
-				cgen(l, nn);
-				break;
-			}
-			regalloc(&nod, l, nn);
-			cgen(l, &nod);
-			if(o == OASHL && r->vconst == 1)
-				gopcode(OADD, n->type, &nod, &nod);
-			else
-				gopcode(o, n->type, r, &nod);
-			gmove(&nod, nn);
-			regfree(&nod);
-			break;
-		}
-
-		/*
-		 * get nod to be D_CX
-		 */
-		if(nodreg(&nod, nn, D_CX)) {
-			regsalloc(&nod1, n);
-			gmove(&nod, &nod1);
-			cgen(n, &nod);		/* probably a bug */
-			gmove(&nod, nn);
-			gmove(&nod1, &nod);
-			break;
-		}
-		reg[D_CX]++;
-		if(nn->op == OREGISTER && nn->reg == D_CX)
-			regalloc(&nod1, l, Z);
-		else
-			regalloc(&nod1, l, nn);
-		if(r->complex >= l->complex) {
-			cgen(r, &nod);
-			cgen(l, &nod1);
-		} else {
-			cgen(l, &nod1);
-			cgen(r, &nod);
-		}
-		gopcode(o, n->type, &nod, &nod1);
-		gmove(&nod1, nn);
-		regfree(&nod);
-		regfree(&nod1);
-		break;
-
-	case OADD:
-	case OSUB:
-	case OOR:
-	case OXOR:
-	case OAND:
-		if(nn == Z) {
-			nullwarn(l, r);
-			break;
-		}
-		if(typefd[n->type->etype])
-			goto fop;
-		if(r->op == OCONST) {
-			if(r->vconst == 0 && o != OAND) {
-				cgen(l, nn);
-				break;
-			}
-		}
-		if(n->op == OADD && l->op == OASHL && l->right->op == OCONST
-		&& (r->op != OCONST || r->vconst < -128 || r->vconst > 127)) {
-			c = l->right->vconst;
-			if(c > 0 && c <= 3) {
-				if(l->left->complex >= r->complex) {
-					regalloc(&nod, l->left, nn);
-					cgen(l->left, &nod);
-					if(r->addable < INDEXED) {
-						regalloc(&nod1, r, Z);
-						cgen(r, &nod1);
-						genmuladd(&nod, &nod, 1 << c, &nod1);
-						regfree(&nod1);
-					}
-					else
-						genmuladd(&nod, &nod, 1 << c, r);
-				}
-				else {
-					regalloc(&nod, r, nn);
-					cgen(r, &nod);
-					regalloc(&nod1, l->left, Z);
-					cgen(l->left, &nod1);
-					genmuladd(&nod, &nod1, 1 << c, &nod);
-					regfree(&nod1);
-				}
-				gmove(&nod, nn);
-				regfree(&nod);
-				break;
-			}
-		}
-		if(n->op == OAND)
-			checkmask(n, r);
-		if(r->addable >= INDEXED && !hardconst(r)) {
-			regalloc(&nod, l, nn);
-			cgen(l, &nod);
-			gopcode(o, n->type, r, &nod);
-			gmove(&nod, nn);
-			regfree(&nod);
-			break;
-		}
-		if(l->complex >= r->complex) {
-			regalloc(&nod, l, nn);
-			cgen(l, &nod);
-			regalloc(&nod1, r, Z);
-			cgen(r, &nod1);
-			gopcode(o, n->type, &nod1, &nod);
-		} else {
-			regalloc(&nod1, r, nn);
-			cgen(r, &nod1);
-			regalloc(&nod, l, Z);
-			cgen(l, &nod);
-			gopcode(o, n->type, &nod1, &nod);
-		}
-		gmove(&nod, nn);
-		regfree(&nod);
-		regfree(&nod1);
-		break;
-
-	case OLMOD:
-	case OMOD:
-	case OLMUL:
-	case OLDIV:
-	case OMUL:
-	case ODIV:
-		if(nn == Z) {
-			nullwarn(l, r);
-			break;
-		}
-		if(typefd[n->type->etype])
-			goto fop;
-		if(r->op == OCONST && typechl[n->type->etype]) {	/* TO DO */
-			SET(v);
-			switch(o) {
-			case ODIV:
-			case OMOD:
-				c = r->vconst;
-				if(c < 0)
-					c = -c;
-				v = log2(c);
-				if(v < 0)
-					break;
-				/* fall thru */
-			case OMUL:
-			case OLMUL:
-				regalloc(&nod, l, nn);
-				cgen(l, &nod);
-				switch(o) {
-				case OMUL:
-				case OLMUL:
-					mulgen(n->type, r, &nod);
-					break;
-				case ODIV:
-					sdiv2(r->vconst, v, l, &nod);
-					break;
-				case OMOD:
-					smod2(r->vconst, v, l, &nod);
-					break;
-				}
-				gmove(&nod, nn);
-				regfree(&nod);
-				goto done;
-			case OLDIV:
-				c = r->vconst;
-				if((c & 0x80000000) == 0)
-					break;
-				regalloc(&nod1, l, Z);
-				cgen(l, &nod1);
-				regalloc(&nod, l, nn);
-				zeroregm(&nod);
-				gins(ACMPL, &nod1, nodconst(c));
-				gins(ASBBL, nodconst(-1), &nod);
-				regfree(&nod1);
-				gmove(&nod, nn);
-				regfree(&nod);
-				goto done;
-			}
-		}
-
-		if(o == OMUL) {
-			if(l->addable >= INDEXED) {
-				t = l;
-				l = r;
-				r = t;
-			}
-			/* should favour AX */
-			regalloc(&nod, l, nn);
-			cgen(l, &nod);
-			if(r->addable < INDEXED || hardconst(r)) {
-				regalloc(&nod1, r, Z);
-				cgen(r, &nod1);
-				gopcode(OMUL, n->type, &nod1, &nod);
-				regfree(&nod1);
-			}else
-				gopcode(OMUL, n->type, r, &nod);	/* addressible */
-			gmove(&nod, nn);
-			regfree(&nod);
-			break;
-		}
-
-		/*
-		 * get nod to be D_AX
-		 * get nod1 to be D_DX
-		 */
-		if(nodreg(&nod, nn, D_AX)) {
-			regsalloc(&nod2, n);
-			gmove(&nod, &nod2);
-			v = reg[D_AX];
-			reg[D_AX] = 0;
-
-			if(isreg(l, D_AX)) {
-				nod3 = *n;
-				nod3.left = &nod2;
-				cgen(&nod3, nn);
-			} else
-			if(isreg(r, D_AX)) {
-				nod3 = *n;
-				nod3.right = &nod2;
-				cgen(&nod3, nn);
-			} else
-				cgen(n, nn);
-
-			gmove(&nod2, &nod);
-			reg[D_AX] = v;
-			break;
-		}
-		if(nodreg(&nod1, nn, D_DX)) {
-			regsalloc(&nod2, n);
-			gmove(&nod1, &nod2);
-			v = reg[D_DX];
-			reg[D_DX] = 0;
-
-			if(isreg(l, D_DX)) {
-				nod3 = *n;
-				nod3.left = &nod2;
-				cgen(&nod3, nn);
-			} else
-			if(isreg(r, D_DX)) {
-				nod3 = *n;
-				nod3.right = &nod2;
-				cgen(&nod3, nn);
-			} else
-				cgen(n, nn);
-
-			gmove(&nod2, &nod1);
-			reg[D_DX] = v;
-			break;
-		}
-		reg[D_AX]++;
-
-		if(r->op == OCONST && (o == ODIV || o == OLDIV) && immconst(r) && typechl[r->type->etype]) {
-			reg[D_DX]++;
-			if(l->addable < INDEXED) {
-				regalloc(&nod2, l, Z);
-				cgen(l, &nod2);
-				l = &nod2;
-			}
-			if(o == ODIV)
-				sdivgen(l, r, &nod, &nod1);
-			else
-				udivgen(l, r, &nod, &nod1);
-			gmove(&nod1, nn);
-			if(l == &nod2)
-				regfree(l);
-			goto freeaxdx;
-		}
-
-		if(l->complex >= r->complex) {
-			cgen(l, &nod);
-			reg[D_DX]++;
-			if(o == ODIV || o == OMOD)
-				gins(typechl[l->type->etype]? ACDQ: ACQO, Z, Z);
-			if(o == OLDIV || o == OLMOD)
-				zeroregm(&nod1);
-			if(r->addable < INDEXED || r->op == OCONST) {
-				regalloc(&nod3, r, Z);
-				cgen(r, &nod3);
-				gopcode(o, n->type, &nod3, Z);
-				regfree(&nod3);
-			} else
-				gopcode(o, n->type, r, Z);
-		} else {
-			regsalloc(&nod3, r);
-			cgen(r, &nod3);
-			cgen(l, &nod);
-			reg[D_DX]++;
-			if(o == ODIV || o == OMOD)
-				gins(typechl[l->type->etype]? ACDQ: ACQO, Z, Z);
-			if(o == OLDIV || o == OLMOD)
-				zeroregm(&nod1);
-			gopcode(o, n->type, &nod3, Z);
-		}
-		if(o == OMOD || o == OLMOD)
-			gmove(&nod1, nn);
-		else
-			gmove(&nod, nn);
-	freeaxdx:
-		regfree(&nod);
-		regfree(&nod1);
-		break;
-
-	case OASLSHR:
-	case OASASHL:
-	case OASASHR:
-		if(r->op == OCONST)
-			goto asand;
-		if(l->op == OBIT)
-			goto asbitop;
-		if(typefd[n->type->etype])
-			goto asand;	/* can this happen? */
-
-		/*
-		 * get nod to be D_CX
-		 */
-		if(nodreg(&nod, nn, D_CX)) {
-			regsalloc(&nod1, n);
-			gmove(&nod, &nod1);
-			cgen(n, &nod);
-			if(nn != Z)
-				gmove(&nod, nn);
-			gmove(&nod1, &nod);
-			break;
-		}
-		reg[D_CX]++;
-
-		if(r->complex >= l->complex) {
-			cgen(r, &nod);
-			if(hardleft)
-				reglcgen(&nod1, l, Z);
-			else
-				nod1 = *l;
-		} else {
-			if(hardleft)
-				reglcgen(&nod1, l, Z);
-			else
-				nod1 = *l;
-			cgen(r, &nod);
-		}
-
-		gopcode(o, l->type, &nod, &nod1);
-		regfree(&nod);
-		if(nn != Z)
-			gmove(&nod1, nn);
-		if(hardleft)
-			regfree(&nod1);
-		break;
-
-	case OASAND:
-	case OASADD:
-	case OASSUB:
-	case OASXOR:
-	case OASOR:
-	asand:
-		if(l->op == OBIT)
-			goto asbitop;
-		if(typefd[l->type->etype] || typefd[r->type->etype])
-			goto asfop;
-		if(o == OASAND)
-			checkmask(n, r);
-		if(l->complex >= r->complex) {
-			if(hardleft)
-				reglcgen(&nod, l, Z);
-			else
-				nod = *l;
-			if(!immconst(r)) {
-				regalloc(&nod1, r, nn);
-				cgen(r, &nod1);
-				gopcode(o, l->type, &nod1, &nod);
-				regfree(&nod1);
-			} else
-				gopcode(o, l->type, r, &nod);
-		} else {
-			regalloc(&nod1, r, nn);
-			cgen(r, &nod1);
-			if(hardleft)
-				reglcgen(&nod, l, Z);
-			else
-				nod = *l;
-			gopcode(o, l->type, &nod1, &nod);
-			regfree(&nod1);
-		}
-		if(nn != Z)
-			gmove(&nod, nn);
-		if(hardleft)
-			regfree(&nod);
-		break;
-
-	asfop:
-		if(l->complex >= r->complex) {
-			if(hardleft)
-				reglcgen(&nod, l, Z);
-			else
-				nod = *l;
-			if(r->addable < INDEXED){
-				regalloc(&nod1, r, nn);
-				cgen(r, &nod1);
-			}else
-				nod1 = *r;
-			regalloc(&nod2, r, Z);
-			gmove(&nod, &nod2);
-			gopcode(o, r->type, &nod1, &nod2);
-			gmove(&nod2, &nod);
-			regfree(&nod2);
-			if(r->addable < INDEXED)
-				regfree(&nod1);
-		} else {
-			regalloc(&nod1, r, nn);
-			cgen(r, &nod1);
-			if(hardleft)
-				reglcgen(&nod, l, Z);
-			else
-				nod = *l;
-			if(o != OASMUL && o != OASADD || !typefd[l->type->etype]) {
-				regalloc(&nod2, r, Z);
-				gmove(&nod, &nod2);
-				gopcode(o, r->type, &nod1, &nod2);
-				regfree(&nod1);
-				gmove(&nod2, &nod);
-				regfree(&nod2);
-			} else {
-				gopcode(o, r->type, &nod, &nod1);
-				gmove(&nod1, &nod);
-				regfree(&nod1);
-			}
-		}
-		if(nn != Z)
-			gmove(&nod, nn);
-		if(hardleft)
-			regfree(&nod);
-		break;
-
-	case OASLMUL:
-	case OASLDIV:
-	case OASLMOD:
-	case OASMUL:
-	case OASDIV:
-	case OASMOD:
-		if(l->op == OBIT)
-			goto asbitop;
-		if(typefd[n->type->etype] || typefd[r->type->etype])
-			goto asfop;
-		if(r->op == OCONST && typechl[n->type->etype]) {
-			SET(v);
-			switch(o) {
-			case OASDIV:
-			case OASMOD:
-				c = r->vconst;
-				if(c < 0)
-					c = -c;
-				v = log2(c);
-				if(v < 0)
-					break;
-				/* fall thru */
-			case OASMUL:
-			case OASLMUL:
-				if(hardleft)
-					reglcgen(&nod2, l, Z);
-				else
-					nod2 = *l;
-				regalloc(&nod, l, nn);
-				cgen(&nod2, &nod);
-				switch(o) {
-				case OASMUL:
-				case OASLMUL:
-					mulgen(n->type, r, &nod);
-					break;
-				case OASDIV:
-					sdiv2(r->vconst, v, l, &nod);
-					break;
-				case OASMOD:
-					smod2(r->vconst, v, l, &nod);
-					break;
-				}
-			havev:
-				gmove(&nod, &nod2);
-				if(nn != Z)
-					gmove(&nod, nn);
-				if(hardleft)
-					regfree(&nod2);
-				regfree(&nod);
-				goto done;
-			case OASLDIV:
-				c = r->vconst;
-				if((c & 0x80000000) == 0)
-					break;
-				if(hardleft)
-					reglcgen(&nod2, l, Z);
-				else
-					nod2 = *l;
-				regalloc(&nod1, l, nn);
-				cgen(&nod2, &nod1);
-				regalloc(&nod, l, nn);
-				zeroregm(&nod);
-				gins(ACMPL, &nod1, nodconst(c));
-				gins(ASBBL, nodconst(-1), &nod);
-				regfree(&nod1);
-				goto havev;
-			}
-		}
-
-		if(o == OASMUL) {
-			/* should favour AX */
-			regalloc(&nod, l, nn);
-			if(r->complex >= FNX) {
-				regalloc(&nod1, r, Z);
-				cgen(r, &nod1);
-				r = &nod1;
-			}
-			if(hardleft)
-				reglcgen(&nod2, l, Z);
-			else
-				nod2 = *l;
-			cgen(&nod2, &nod);
-			if(r->addable < INDEXED || hardconst(r)) {
-				if(r->complex < FNX) {
-					regalloc(&nod1, r, Z);
-					cgen(r, &nod1);
-				}
-				gopcode(OASMUL, n->type, &nod1, &nod);
-				regfree(&nod1);
-			}
-			else
-				gopcode(OASMUL, n->type, r, &nod);
-			if(r == &nod1)
-				regfree(r);
-			gmove(&nod, &nod2);
-			if(nn != Z)
-				gmove(&nod, nn);
-			regfree(&nod);
-			if(hardleft)
-				regfree(&nod2);
-			break;
-		}
-
-		/*
-		 * get nod to be D_AX
-		 * get nod1 to be D_DX
-		 */
-		if(nodreg(&nod, nn, D_AX)) {
-			regsalloc(&nod2, n);
-			gmove(&nod, &nod2);
-			v = reg[D_AX];
-			reg[D_AX] = 0;
-
-			if(isreg(l, D_AX)) {
-				nod3 = *n;
-				nod3.left = &nod2;
-				cgen(&nod3, nn);
-			} else
-			if(isreg(r, D_AX)) {
-				nod3 = *n;
-				nod3.right = &nod2;
-				cgen(&nod3, nn);
-			} else
-				cgen(n, nn);
-
-			gmove(&nod2, &nod);
-			reg[D_AX] = v;
-			break;
-		}
-		if(nodreg(&nod1, nn, D_DX)) {
-			regsalloc(&nod2, n);
-			gmove(&nod1, &nod2);
-			v = reg[D_DX];
-			reg[D_DX] = 0;
-
-			if(isreg(l, D_DX)) {
-				nod3 = *n;
-				nod3.left = &nod2;
-				cgen(&nod3, nn);
-			} else
-			if(isreg(r, D_DX)) {
-				nod3 = *n;
-				nod3.right = &nod2;
-				cgen(&nod3, nn);
-			} else
-				cgen(n, nn);
-
-			gmove(&nod2, &nod1);
-			reg[D_DX] = v;
-			break;
-		}
-		reg[D_AX]++;
-		reg[D_DX]++;
-
-		if(l->complex >= r->complex) {
-			if(hardleft)
-				reglcgen(&nod2, l, Z);
-			else
-				nod2 = *l;
-			cgen(&nod2, &nod);
-			if(r->op == OCONST && typechl[r->type->etype]) {
-				switch(o) {
-				case OASDIV:
-					sdivgen(&nod2, r, &nod, &nod1);
-					goto divdone;
-				case OASLDIV:
-					udivgen(&nod2, r, &nod, &nod1);
-				divdone:
-					gmove(&nod1, &nod2);
-					if(nn != Z)
-						gmove(&nod1, nn);
-					goto freelxaxdx;
-				}
-			}
-			if(o == OASDIV || o == OASMOD)
-				gins(typechl[l->type->etype]? ACDQ: ACQO, Z, Z);
-			if(o == OASLDIV || o == OASLMOD)
-				zeroregm(&nod1);
-			if(r->addable < INDEXED || r->op == OCONST ||
-			   !typeil[r->type->etype]) {
-				regalloc(&nod3, r, Z);
-				cgen(r, &nod3);
-				gopcode(o, l->type, &nod3, Z);
-				regfree(&nod3);
-			} else
-				gopcode(o, n->type, r, Z);
-		} else {
-			regalloc(&nod3, r, Z);
-			cgen(r, &nod3);
-			if(hardleft)
-				reglcgen(&nod2, l, Z);
-			else
-				nod2 = *l;
-			cgen(&nod2, &nod);
-			if(o == OASDIV || o == OASMOD)
-				gins(typechl[l->type->etype]? ACDQ: ACQO, Z, Z);
-			if(o == OASLDIV || o == OASLMOD)
-				zeroregm(&nod1);
-			gopcode(o, l->type, &nod3, Z);
-			regfree(&nod3);
-		}
-		if(o == OASMOD || o == OASLMOD) {
-			gmove(&nod1, &nod2);
-			if(nn != Z)
-				gmove(&nod1, nn);
-		} else {
-			gmove(&nod, &nod2);
-			if(nn != Z)
-				gmove(&nod, nn);
-		}
-	freelxaxdx:
-		if(hardleft)
-			regfree(&nod2);
-		regfree(&nod);
-		regfree(&nod1);
-		break;
-
-	fop:
-		if(l->complex >= r->complex) {
-			regalloc(&nod, l, nn);
-			cgen(l, &nod);
-			if(r->addable < INDEXED) {
-				regalloc(&nod1, r, Z);
-				cgen(r, &nod1);
-				gopcode(o, n->type, &nod1, &nod);
-				regfree(&nod1);
-			} else
-				gopcode(o, n->type, r, &nod);
-		} else {
-			/* TO DO: could do better with r->addable >= INDEXED */
-			regalloc(&nod1, r, Z);
-			cgen(r, &nod1);
-			regalloc(&nod, l, nn);
-			cgen(l, &nod);
-			gopcode(o, n->type, &nod1, &nod);
-			regfree(&nod1);
-		}
-		gmove(&nod, nn);
-		regfree(&nod);
-		break;
-
-	asbitop:
-		regalloc(&nod4, n, nn);
-		if(l->complex >= r->complex) {
-			bitload(l, &nod, &nod1, &nod2, &nod4);
-			regalloc(&nod3, r, Z);
-			cgen(r, &nod3);
-		} else {
-			regalloc(&nod3, r, Z);
-			cgen(r, &nod3);
-			bitload(l, &nod, &nod1, &nod2, &nod4);
-		}
-		gmove(&nod, &nod4);
-
-		{	/* TO DO: check floating point source */
-			Node onod;
-
-			/* incredible grot ... */
-			onod = nod3;
-			onod.op = o;
-			onod.complex = 2;
-			onod.addable = 0;
-			onod.type = tfield;
-			onod.left = &nod4;
-			onod.right = &nod3;
-			cgen(&onod, Z);
-		}
-		regfree(&nod3);
-		gmove(&nod4, &nod);
-		regfree(&nod4);
-		bitstore(l, &nod, &nod1, &nod2, nn);
-		break;
-
-	case OADDR:
-		if(nn == Z) {
-			nullwarn(l, Z);
-			break;
-		}
-		lcgen(l, nn);
-		break;
-
-	case OFUNC:
-		if(l->complex >= FNX) {
-			if(l->op != OIND)
-				diag(n, "bad function call");
-
-			regret(&nod, l->left);
-			cgen(l->left, &nod);
-			regsalloc(&nod1, l->left);
-			gmove(&nod, &nod1);
-			regfree(&nod);
-
-			nod = *n;
-			nod.left = &nod2;
-			nod2 = *l;
-			nod2.left = &nod1;
-			nod2.complex = 1;
-			cgen(&nod, nn);
-
-			return;
-		}
-		o = reg[REGARG];
-		gargs(r, &nod, &nod1);
-		if(l->addable < INDEXED) {
-			reglcgen(&nod, l, nn);
-			nod.op = OREGISTER;
-			gopcode(OFUNC, n->type, Z, &nod);
-			regfree(&nod);
-		} else
-			gopcode(OFUNC, n->type, Z, l);
-		if(REGARG)
-			if(o != reg[REGARG])
-				reg[REGARG]--;
-		if(nn != Z) {
-			regret(&nod, n);
-			gmove(&nod, nn);
-			regfree(&nod);
-		}
-		break;
-
-	case OIND:
-		if(nn == Z) {
-			nullwarn(l, Z);
-			break;
-		}
-		regialloc(&nod, n, nn);
-		r = l;
-		while(r->op == OADD)
-			r = r->right;
-		if(sconst(r)) {
-			v = r->vconst;
-			r->vconst = 0;
-			cgen(l, &nod);
-			nod.xoffset += v;
-			r->vconst = v;
-		} else
-			cgen(l, &nod);
-		regind(&nod, n);
-		gmove(&nod, nn);
-		regfree(&nod);
-		break;
-
-	case OEQ:
-	case ONE:
-	case OLE:
-	case OLT:
-	case OGE:
-	case OGT:
-	case OLO:
-	case OLS:
-	case OHI:
-	case OHS:
-		if(nn == Z) {
-			nullwarn(l, r);
-			break;
-		}
-		boolgen(n, 1, nn);
-		break;
-
-	case OANDAND:
-	case OOROR:
-		boolgen(n, 1, nn);
-		if(nn == Z)
-			patch(p, pc);
-		break;
-
-	case ONOT:
-		if(nn == Z) {
-			nullwarn(l, Z);
-			break;
-		}
-		boolgen(n, 1, nn);
-		break;
-
-	case OCOMMA:
-		cgen(l, Z);
-		cgen(r, nn);
-		break;
-
-	case OCAST:
-		if(nn == Z) {
-			nullwarn(l, Z);
-			break;
-		}
-		/*
-		 * convert from types l->n->nn
-		 */
-		if(nocast(l->type, n->type) && nocast(n->type, nn->type)) {
-			/* both null, gen l->nn */
-			cgen(l, nn);
-			break;
-		}
-		if(ewidth[n->type->etype] < ewidth[l->type->etype]){
-			if(l->type->etype == TIND && typechlp[n->type->etype])
-				warn(n, "conversion of pointer to shorter integer");
-		}else if(0){
-			if(nocast(n->type, nn->type) || castup(n->type, nn->type)){
-				if(typefd[l->type->etype] != typefd[nn->type->etype])
-					regalloc(&nod, l, nn);
-				else
-					regalloc(&nod, nn, nn);
-				cgen(l, &nod);
-				gmove(&nod, nn);
-				regfree(&nod);
-				break;
-			}
-		}
-		regalloc(&nod, l, nn);
-		cgen(l, &nod);
-		regalloc(&nod1, n, &nod);
-		gmove(&nod, &nod1);
-		gmove(&nod1, nn);
-		regfree(&nod1);
-		regfree(&nod);
-		break;
-
-	case ODOT:
-		sugen(l, nodrat, l->type->width);
-		if(nn == Z)
-			break;
-		warn(n, "non-interruptable temporary");
-		nod = *nodrat;
-		if(!r || r->op != OCONST) {
-			diag(n, "DOT and no offset");
-			break;
-		}
-		nod.xoffset += (int32_t)r->vconst;
-		nod.type = n->type;
-		cgen(&nod, nn);
-		break;
-
-	case OCOND:
-		bcgen(l, 1);
-		p1 = p;
-		cgen(r->left, nn);
-		gbranch(OGOTO);
-		patch(p1, pc);
-		p1 = p;
-		cgen(r->right, nn);
-		patch(p1, pc);
-		break;
-
-	case OPOSTINC:
-	case OPOSTDEC:
-		v = 1;
-		if(l->type->etype == TIND)
-			v = l->type->link->width;
-		if(o == OPOSTDEC)
-			v = -v;
-		if(l->op == OBIT)
-			goto bitinc;
-		if(nn == Z)
-			goto pre;
-
-		if(hardleft)
-			reglcgen(&nod, l, Z);
-		else
-			nod = *l;
-
-		gmove(&nod, nn);
-		if(typefd[n->type->etype]) {
-			regalloc(&nod1, l, Z);
-			gmove(&nod, &nod1);
-			if(v < 0)
-				gopcode(OSUB, n->type, nodfconst(-v), &nod1);
-			else
-				gopcode(OADD, n->type, nodfconst(v), &nod1);
-			gmove(&nod1, &nod);
-			regfree(&nod1);
-		} else
-			gopcode(OADD, n->type, nodconst(v), &nod);
-		if(hardleft)
-			regfree(&nod);
-		break;
-
-	case OPREINC:
-	case OPREDEC:
-		v = 1;
-		if(l->type->etype == TIND)
-			v = l->type->link->width;
-		if(o == OPREDEC)
-			v = -v;
-		if(l->op == OBIT)
-			goto bitinc;
-
-	pre:
-		if(hardleft)
-			reglcgen(&nod, l, Z);
-		else
-			nod = *l;
-		if(typefd[n->type->etype]) {
-			regalloc(&nod1, l, Z);
-			gmove(&nod, &nod1);
-			if(v < 0)
-				gopcode(OSUB, n->type, nodfconst(-v), &nod1);
-			else
-				gopcode(OADD, n->type, nodfconst(v), &nod1);
-			gmove(&nod1, &nod);
-			regfree(&nod1);
-		} else
-			gopcode(OADD, n->type, nodconst(v), &nod);
-		if(nn != Z)
-			gmove(&nod, nn);
-		if(hardleft)
-			regfree(&nod);
-		break;
-
-	bitinc:
-		if(nn != Z && (o == OPOSTINC || o == OPOSTDEC)) {
-			bitload(l, &nod, &nod1, &nod2, Z);
-			gmove(&nod, nn);
-			gopcode(OADD, tfield, nodconst(v), &nod);
-			bitstore(l, &nod, &nod1, &nod2, Z);
-			break;
-		}
-		bitload(l, &nod, &nod1, &nod2, nn);
-		gopcode(OADD, tfield, nodconst(v), &nod);
-		bitstore(l, &nod, &nod1, &nod2, nn);
-		break;
-	}
-done:
-	cursafe = curs;
-}
-
-void
-reglcgen(Node *t, Node *n, Node *nn)
-{
-	Node *r;
-	int32_t v;
-
-	regialloc(t, n, nn);
-	if(n->op == OIND) {
-		r = n->left;
-		while(r->op == OADD)
-			r = r->right;
-		if(sconst(r)) {
-			v = r->vconst;
-			r->vconst = 0;
-			lcgen(n, t);
-			t->xoffset += v;
-			r->vconst = v;
-			regind(t, n);
-			return;
-		}
-	}
-	lcgen(n, t);
-	regind(t, n);
-}
-
-void
-lcgen(Node *n, Node *nn)
-{
-	Prog *p1;
-	Node nod;
-
-	if(debug['g']) {
-		prtree(nn, "lcgen lhs");
-		prtree(n, "lcgen");
-	}
-	if(n == Z || n->type == T)
-		return;
-	if(nn == Z) {
-		nn = &nod;
-		regalloc(&nod, n, Z);
-	}
-	switch(n->op) {
-	default:
-		if(n->addable < INDEXED) {
-			diag(n, "unknown op in lcgen: %O", n->op);
-			break;
-		}
-		gopcode(OADDR, n->type, n, nn);
-		break;
-
-	case OCOMMA:
-		cgen(n->left, n->left);
-		lcgen(n->right, nn);
-		break;
-
-	case OIND:
-		cgen(n->left, nn);
-		break;
-
-	case OCOND:
-		bcgen(n->left, 1);
-		p1 = p;
-		lcgen(n->right->left, nn);
-		gbranch(OGOTO);
-		patch(p1, pc);
-		p1 = p;
-		lcgen(n->right->right, nn);
-		patch(p1, pc);
-		break;
-	}
-}
-
-void
-bcgen(Node *n, int true)
-{
-
-	if(n->type == T)
-		gbranch(OGOTO);
-	else
-		boolgen(n, true, Z);
-}
-
-void
-boolgen(Node *n, int true, Node *nn)
-{
-	int o;
-	Prog *p1, *p2;
-	Node *l, *r, nod, nod1;
-	int32_t curs;
-
-	if(debug['g']) {
-		prtree(nn, "boolgen lhs");
-		prtree(n, "boolgen");
-	}
-	curs = cursafe;
-	l = n->left;
-	r = n->right;
-	switch(n->op) {
-
-	default:
-		o = ONE;
-		if(true)
-			o = OEQ;
-		/* bad, 13 is address of external that becomes constant */
-		if(n->addable >= INDEXED && n->addable != 13) {
-			if(typefd[n->type->etype]) {
-				regalloc(&nod1, n, Z);
-				gmove(nodfconst(0.0), &nod1);	/* TO DO: FREGZERO */
-				gopcode(o, n->type, n, &nod1);
-				regfree(&nod1);
-			} else
-				gopcode(o, n->type, n, nodconst(0));
-			goto com;
-		}
-		regalloc(&nod, n, nn);
-		cgen(n, &nod);
-		if(typefd[n->type->etype]) {
-			regalloc(&nod1, n, Z);
-			gmove(nodfconst(0.0), &nod1);	/* TO DO: FREGZERO */
-			gopcode(o, n->type, &nod, &nod1);
-			regfree(&nod1);
-		} else
-			gopcode(o, n->type, &nod, nodconst(0));
-		regfree(&nod);
-		goto com;
-
-	case OCONST:
-		o = vconst(n);
-		if(!true)
-			o = !o;
-		gbranch(OGOTO);
-		if(o) {
-			p1 = p;
-			gbranch(OGOTO);
-			patch(p1, pc);
-		}
-		goto com;
-
-	case OCOMMA:
-		cgen(l, Z);
-		boolgen(r, true, nn);
-		break;
-
-	case ONOT:
-		boolgen(l, !true, nn);
-		break;
-
-	case OCOND:
-		bcgen(l, 1);
-		p1 = p;
-		bcgen(r->left, true);
-		p2 = p;
-		gbranch(OGOTO);
-		patch(p1, pc);
-		p1 = p;
-		bcgen(r->right, !true);
-		patch(p2, pc);
-		p2 = p;
-		gbranch(OGOTO);
-		patch(p1, pc);
-		patch(p2, pc);
-		goto com;
-
-	case OANDAND:
-		if(!true)
-			goto caseor;
-
-	caseand:
-		bcgen(l, true);
-		p1 = p;
-		bcgen(r, !true);
-		p2 = p;
-		patch(p1, pc);
-		gbranch(OGOTO);
-		patch(p2, pc);
-		goto com;
-
-	case OOROR:
-		if(!true)
-			goto caseand;
-
-	caseor:
-		bcgen(l, !true);
-		p1 = p;
-		bcgen(r, !true);
-		p2 = p;
-		gbranch(OGOTO);
-		patch(p1, pc);
-		patch(p2, pc);
-		goto com;
-
-	case OEQ:
-	case ONE:
-	case OLE:
-	case OLT:
-	case OGE:
-	case OGT:
-	case OHI:
-	case OHS:
-	case OLO:
-	case OLS:
-		o = n->op;
-		if(true)
-			o = comrel[relindex(o)];
-		if(l->complex >= FNX && r->complex >= FNX) {
-			regret(&nod, r);
-			cgen(r, &nod);
-			regsalloc(&nod1, r);
-			gmove(&nod, &nod1);
-			regfree(&nod);
-			nod = *n;
-			nod.right = &nod1;
-			boolgen(&nod, true, nn);
-			break;
-		}
-		if(immconst(l)) {
-			o = invrel[relindex(o)];
-			/* bad, 13 is address of external that becomes constant */
-			if(r->addable < INDEXED || r->addable == 13) {
-				regalloc(&nod, r, nn);
-				cgen(r, &nod);
-				gopcode(o, l->type, &nod, l);
-				regfree(&nod);
-			} else
-				gopcode(o, l->type, r, l);
-			goto com;
-		}
-		if(typefd[l->type->etype])
-			o = invrel[relindex(logrel[relindex(o)])];
-		if(l->complex >= r->complex) {
-			regalloc(&nod, l, nn);
-			cgen(l, &nod);
-			if(r->addable < INDEXED || hardconst(r) || typefd[l->type->etype]) {
-				regalloc(&nod1, r, Z);
-				cgen(r, &nod1);
-				gopcode(o, l->type, &nod, &nod1);
-				regfree(&nod1);
-			} else
-				gopcode(o, l->type, &nod, r);
-			regfree(&nod);
-			goto com;
-		}
-		regalloc(&nod, r, nn);
-		cgen(r, &nod);
-		if(l->addable < INDEXED || l->addable == 13 || hardconst(l)) {
-			regalloc(&nod1, l, Z);
-			cgen(l, &nod1);
-			if(typechl[l->type->etype] && ewidth[l->type->etype] <= ewidth[TINT])
-				gopcode(o, types[TINT], &nod1, &nod);
-			else
-				gopcode(o, l->type, &nod1, &nod);
-			regfree(&nod1);
-		} else
-			gopcode(o, l->type, l, &nod);
-		regfree(&nod);
-
-	com:
-		if(nn != Z) {
-			p1 = p;
-			gmove(nodconst(1L), nn);
-			gbranch(OGOTO);
-			p2 = p;
-			patch(p1, pc);
-			gmove(nodconst(0L), nn);
-			patch(p2, pc);
-		}
-		break;
-	}
-	cursafe = curs;
-}
-
-void
-sugen(Node *n, Node *nn, int32_t w)
-{
-	Prog *p1;
-	Node nod0, nod1, nod2, nod3, nod4, *l, *r;
-	Type *t;
-	int c, mt, mo;
-	int64_t o0, o1;
-
-	if(n == Z || n->type == T)
-		return;
-	if(debug['g']) {
-		prtree(nn, "sugen lhs");
-		prtree(n, "sugen");
-	}
-	if(nn == nodrat)
-		if(w > nrathole)
-			nrathole = w;
-	switch(n->op) {
-	case OIND:
-		if(nn == Z) {
-			nullwarn(n->left, Z);
-			break;
-		}
-
-	default:
-		goto copy;
-
-	case OCONST:
-		goto copy;
-
-	case ODOT:
-		l = n->left;
-		sugen(l, nodrat, l->type->width);
-		if(nn == Z)
-			break;
-		warn(n, "non-interruptable temporary");
-		nod1 = *nodrat;
-		r = n->right;
-		if(!r || r->op != OCONST) {
-			diag(n, "DOT and no offset");
-			break;
-		}
-		nod1.xoffset += (int32_t)r->vconst;
-		nod1.type = n->type;
-		sugen(&nod1, nn, w);
-		break;
-
-	case OSTRUCT:
-		/*
-		 * rewrite so lhs has no fn call
-		 */
-		if(nn != Z && side(nn)) {
-			nod1 = *n;
-			nod1.type = typ(TIND, n->type);
-			regret(&nod2, &nod1);
-			lcgen(nn, &nod2);
-			regsalloc(&nod0, &nod1);
-			cgen(&nod2, &nod0);
-			regfree(&nod2);
-
-			nod1 = *n;
-			nod1.op = OIND;
-			nod1.left = &nod0;
-			nod1.right = Z;
-			nod1.complex = 1;
-
-			sugen(n, &nod1, w);
-			return;
-		}
-
-		r = n->left;
-		for(t = n->type->link; t != T; t = t->down) {
-			l = r;
-			if(r->op == OLIST) {
-				l = r->left;
-				r = r->right;
-			}
-			if(nn == Z) {
-				cgen(l, nn);
-				continue;
-			}
-			/*
-			 * hand craft *(&nn + o) = l
-			 */
-			nod0 = znode;
-			nod0.op = OAS;
-			nod0.type = t;
-			nod0.left = &nod1;
-			nod0.right = nil;
-
-			nod1 = znode;
-			nod1.op = OIND;
-			nod1.type = t;
-			nod1.left = &nod2;
-
-			nod2 = znode;
-			nod2.op = OADD;
-			nod2.type = typ(TIND, t);
-			nod2.left = &nod3;
-			nod2.right = &nod4;
-
-			nod3 = znode;
-			nod3.op = OADDR;
-			nod3.type = nod2.type;
-			nod3.left = nn;
-
-			nod4 = znode;
-			nod4.op = OCONST;
-			nod4.type = nod2.type;
-			nod4.vconst = t->offset;
-
-			ccom(&nod0);
-			acom(&nod0);
-			xcom(&nod0);
-			nod0.addable = 0;
-			nod0.right = l;
-
-			/* prtree(&nod0, "hand craft"); /* */
-			cgen(&nod0, Z);
-		}
-		break;
-
-	case OAS:
-		if(nn == Z) {
-			if(n->addable < INDEXED)
-				sugen(n->right, n->left, w);
-			break;
-		}
-
-		sugen(n->right, nodrat, w);
-		warn(n, "non-interruptable temporary");
-		sugen(nodrat, n->left, w);
-		sugen(nodrat, nn, w);
-		break;
-
-	case OFUNC:
-		if(nn == Z) {
-			sugen(n, nodrat, w);
-			break;
-		}
-		if(nn->op != OIND) {
-			nn = new1(OADDR, nn, Z);
-			nn->type = types[TIND];
-			nn->addable = 0;
-		} else
-			nn = nn->left;
-		n = new(OFUNC, n->left, new(OLIST, nn, n->right));
-		n->type = types[TVOID];
-		n->left->type = types[TVOID];
-		cgen(n, Z);
-		break;
-
-	case OCOND:
-		bcgen(n->left, 1);
-		p1 = p;
-		sugen(n->right->left, nn, w);
-		gbranch(OGOTO);
-		patch(p1, pc);
-		p1 = p;
-		sugen(n->right->right, nn, w);
-		patch(p1, pc);
-		break;
-
-	case OCOMMA:
-		cgen(n->left, Z);
-		sugen(n->right, nn, w);
-		break;
-	}
-	return;
-
-copy:
-	if(nn == Z) {
-		switch(n->op) {
-		case OASADD:
-		case OASSUB:
-		case OASAND:
-		case OASOR:
-		case OASXOR:
-
-		case OASMUL:
-		case OASLMUL:
-
-
-		case OASASHL:
-		case OASASHR:
-		case OASLSHR:
-			break;
-
-		case OPOSTINC:
-		case OPOSTDEC:
-		case OPREINC:
-		case OPREDEC:
-			break;
-
-		default:
-			return;
-		}
-	}
-
-	if(n->complex >= FNX && nn != nil && nn->complex >= FNX) {
-		t = nn->type;
-		nn->type = types[TLONG];
-		regialloc(&nod1, nn, Z);
-		lcgen(nn, &nod1);
-		regsalloc(&nod2, nn);
-		nn->type = t;
-
-		gins(AMOVQ, &nod1, &nod2);
-		regfree(&nod1);
-
-		nod2.type = typ(TIND, t);
-
-		nod1 = nod2;
-		nod1.op = OIND;
-		nod1.left = &nod2;
-		nod1.right = Z;
-		nod1.complex = 1;
-		nod1.type = t;
-
-		sugen(n, &nod1, w);
-		return;
-	}
-
-	if(w <= 32) {
-		c = cursafe;
-		if(n->left != Z && n->left->complex >= FNX
-		&& n->right != Z && n->right->complex >= FNX) {
-			regsalloc(&nod1, n->right);
-			cgen(n->right, &nod1);
-			nod2 = *n;
-			nod2.right = &nod1;
-			cgen(&nod2, nn);
-			cursafe = c;
-			return;
-		}
-		if(w & 7) {
-			mt = TLONG;
-			mo = AMOVL;
-		} else {
-			mt = TVLONG;
-			mo = AMOVQ;
-		}
-		if(n->complex > nn->complex) {
-			t = n->type;
-			n->type = types[mt];
-			regalloc(&nod0, n, Z);
-			if(!vaddr(n, 0)) {
-				reglcgen(&nod1, n, Z);
-				n->type = t;
-				n = &nod1;
-			}
-			else
-				n->type = t;
-
-			t = nn->type;
-			nn->type = types[mt];
-			if(!vaddr(nn, 0)) {
-				reglcgen(&nod2, nn, Z);
-				nn->type = t;
-				nn = &nod2;
-			}
-			else
-				nn->type = t;
-		} else {
-			t = nn->type;
-			nn->type = types[mt];
-			regalloc(&nod0, nn, Z);
-			if(!vaddr(nn, 0)) {
-				reglcgen(&nod2, nn, Z);
-				nn->type = t;
-				nn = &nod2;
-			}
-			else
-				nn->type = t;
-
-			t = n->type;
-			n->type = types[mt];
-			if(!vaddr(n, 0)) {
-				reglcgen(&nod1, n, Z);
-				n->type = t;
-				n = &nod1;
-			}
-			else
-				n->type = t;
-		}
-		o0 = n->xoffset;
-		o1 = nn->xoffset;
-		w /= ewidth[mt];
-		while(--w >= 0) {
-			gins(mo, n, &nod0);
-			gins(mo, &nod0, nn);
-			n->xoffset += ewidth[mt];
-			nn->xoffset += ewidth[mt];
-		}
-		n->xoffset = o0;
-		nn->xoffset = o1;
-		if(nn == &nod2)
-			regfree(&nod2);
-		if(n == &nod1)
-			regfree(&nod1);
-		regfree(&nod0);
-		return;
-	}
-
-	/* botch, need to save in .safe */
-	c = 0;
-	if(n->complex > nn->complex) {
-		t = n->type;
-		n->type = types[TIND];
-		nodreg(&nod1, n, D_SI);
-		if(reg[D_SI]) {
-			gins(APUSHQ, &nod1, Z);
-			c |= 1;
-			reg[D_SI]++;
-		}
-		lcgen(n, &nod1);
-		n->type = t;
-
-		t = nn->type;
-		nn->type = types[TIND];
-		nodreg(&nod2, nn, D_DI);
-		if(reg[D_DI]) {
-warn(Z, "DI botch");
-			gins(APUSHQ, &nod2, Z);
-			c |= 2;
-			reg[D_DI]++;
-		}
-		lcgen(nn, &nod2);
-		nn->type = t;
-	} else {
-		t = nn->type;
-		nn->type = types[TIND];
-		nodreg(&nod2, nn, D_DI);
-		if(reg[D_DI]) {
-warn(Z, "DI botch");
-			gins(APUSHQ, &nod2, Z);
-			c |= 2;
-			reg[D_DI]++;
-		}
-		lcgen(nn, &nod2);
-		nn->type = t;
-
-		t = n->type;
-		n->type = types[TIND];
-		nodreg(&nod1, n, D_SI);
-		if(reg[D_SI]) {
-			gins(APUSHQ, &nod1, Z);
-			c |= 1;
-			reg[D_SI]++;
-		}
-		lcgen(n, &nod1);
-		n->type = t;
-	}
-	nodreg(&nod3, n, D_CX);
-	if(reg[D_CX]) {
-		gins(APUSHQ, &nod3, Z);
-		c |= 4;
-		reg[D_CX]++;
-	}
-	gins(AMOVL, nodconst(w/SZ_INT), &nod3);
-	gins(ACLD, Z, Z);
-	gins(AREP, Z, Z);
-	gins(AMOVSL, Z, Z);
-	if(c & 4) {
-		gins(APOPQ, Z, &nod3);
-		reg[D_CX]--;
-	}
-	if(c & 2) {
-		gins(APOPQ, Z, &nod2);
-		reg[nod2.reg]--;
-	}
-	if(c & 1) {
-		gins(APOPQ, Z, &nod1);
-		reg[nod1.reg]--;
-	}
-}
-
-/*
- * TO DO
- */
-void
-layout(Node *f, Node *t, int c, int cv, Node *cn)
-{
-	Node t1, t2;
-
-	while(c > 3) {
-		layout(f, t, 2, 0, Z);
-		c -= 2;
-	}
-
-	regalloc(&t1, &lregnode, Z);
-	regalloc(&t2, &lregnode, Z);
-	if(c > 0) {
-		gmove(f, &t1);
-		f->xoffset += SZ_INT;
-	}
-	if(cn != Z)
-		gmove(nodconst(cv), cn);
-	if(c > 1) {
-		gmove(f, &t2);
-		f->xoffset += SZ_INT;
-	}
-	if(c > 0) {
-		gmove(&t1, t);
-		t->xoffset += SZ_INT;
-	}
-	if(c > 2) {
-		gmove(f, &t1);
-		f->xoffset += SZ_INT;
-	}
-	if(c > 1) {
-		gmove(&t2, t);
-		t->xoffset += SZ_INT;
-	}
-	if(c > 2) {
-		gmove(&t1, t);
-		t->xoffset += SZ_INT;
-	}
-	regfree(&t1);
-	regfree(&t2);
-}
-
-/*
- * constant is not vlong or fits as 32-bit signed immediate
- */
-int
-immconst(Node *n)
-{
-	int32_t v;
-
-	if(n->op != OCONST || !typechlpv[n->type->etype])
-		return 0;
-	if(typechl[n->type->etype])
-		return 1;
-	v = n->vconst;
-	return n->vconst == (int64_t)v;
-}
-
-/*
- * if a constant and vlong, doesn't fit as 32-bit signed immediate
- */
-int
-hardconst(Node *n)
-{
-	return n->op == OCONST && !immconst(n);
-}
-
-/*
- * casting up to t2 covers an intermediate cast to t1
- */
-int
-castup(Type *t1, Type *t2)
-{
-	int ft;
-
-	if(!nilcast(t1, t2))
-		return 0;
-	/* known to be small to large */
-	ft = t1->etype;
-	switch(t2->etype){
-	case TINT:
-	case TLONG:
-		return ft == TLONG || ft == TINT || ft == TSHORT || ft == TCHAR;
-	case TUINT:
-	case TULONG:
-		return ft == TULONG || ft == TUINT || ft == TUSHORT || ft == TUCHAR;
-	case TVLONG:
-		return ft == TLONG || ft == TINT || ft == TSHORT;
-	case TUVLONG:
-		return ft == TULONG || ft == TUINT || ft == TUSHORT;
-	}
-	return 0;
-}
-
-/*
- * vl &= ~ul or vl & ~ul
- * create a ul mask with top bits zero, which is usually wrong
- */
-void
-checkmask(Node *n, Node *r)
-{
-	Node *rl;
-
-	if((n->op == OAND || n->op == OASAND) &&
-	   r->op == OCAST &&
-	   (rl = r->left)->op == OCOM &&
-	   typesuv[n->type->etype] && typeu[rl->type->etype] && typechl[rl->type->etype])
-		warn(n, "32-bit mask zero-extended to 64 bits");
-}
-
-void
-zeroregm(Node *n)
-{
-	gins(AMOVL, nodconst(0), n);
-}
-
-/* do we need to load the address of a vlong? */
-int
-vaddr(Node *n, int a)
-{
-	switch(n->op) {
-	case ONAME:
-		if(a)
-			return 1;
-		return !(n->class == CEXTERN || n->class == CGLOBL || n->class == CSTATIC);
-
-	case OCONST:
-	case OREGISTER:
-	case OINDREG:
-		return 1;
-	}
-	return 0;
-}
-
-int32_t
-hi64v(Node *n)
-{
-	if(align(0, types[TCHAR], Aarg1))	/* isbigendian */
-		return (int32_t)(n->vconst) & ~0L;
-	else
-		return (int32_t)((uint64_t)n->vconst>>32) & ~0L;
-}
-
-int32_t
-lo64v(Node *n)
-{
-	if(align(0, types[TCHAR], Aarg1))	/* isbigendian */
-		return (int32_t)((uint64_t)n->vconst>>32) & ~0L;
-	else
-		return (int32_t)(n->vconst) & ~0L;
-}
-
-Node *
-hi64(Node *n)
-{
-	return nodconst(hi64v(n));
-}
-
-Node *
-lo64(Node *n)
-{
-	return nodconst(lo64v(n));
-}
-
-int
-cond(int op)
-{
-	switch(op) {
-	case OANDAND:
-	case OOROR:
-	case ONOT:
-		return 1;
-
-	case OEQ:
-	case ONE:
-	case OLE:
-	case OLT:
-	case OGE:
-	case OGT:
-	case OHI:
-	case OHS:
-	case OLO:
-	case OLS:
-		return 1;
-	}
-	return 0;
-}

+ 0 - 215
sys/src/cmd/6c/div.c

@@ -1,215 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "gc.h"
-
-/*
- * Based on: Granlund, T.; Montgomery, P.L.
- * "Division by Invariant Integers using Multiplication".
- * SIGPLAN Notices, Vol. 29, June 1994, page 61.
- */
-
-#define	TN(n)	((uint64_t)1 << (n))
-#define	T31	TN(31)
-#define	T32	TN(32)
-
-int
-multiplier(uint32_t d, int p, uint64_t *mp)
-{
-	int l;
-	uint64_t mlo, mhi, tlo, thi;
-
-	l = topbit(d - 1) + 1;
-	mlo = (((TN(l) - d) << 32) / d) + T32;
-	if(l + p == 64)
-		mhi = (((TN(l) + 1 - d) << 32) / d) + T32;
-	else
-		mhi = (TN(32 + l) + TN(32 + l - p)) / d;
-	/*assert(mlo < mhi);*/
-	while(l > 0) {
-		tlo = mlo >> 1;
-		thi = mhi >> 1;
-		if(tlo == thi)
-			break;
-		mlo = tlo;
-		mhi = thi;
-		l--;
-	}
-	*mp = mhi;
-	return l;
-}
-
-int
-sdiv(uint32_t d, uint32_t *mp, int *sp)
-{
-	int s;
-	uint64_t m;
-
-	s = multiplier(d, 32 - 1, &m);
-	*mp = m;
-	*sp = s;
-	if(m >= T31)
-		return 1;
-	else
-		return 0;
-}
-
-int
-udiv(uint32_t d, uint32_t *mp, int *sp, int *pp)
-{
-	int p, s;
-	uint64_t m;
-
-	s = multiplier(d, 32, &m);
-	p = 0;
-	if(m >= T32) {
-		while((d & 1) == 0) {
-			d >>= 1;
-			p++;
-		}
-		s = multiplier(d, 32 - p, &m);
-	}
-	*mp = m;
-	*pp = p;
-	if(m >= T32) {
-		/*assert(p == 0);*/
-		*sp = s - 1;
-		return 1;
-	}
-	else {
-		*sp = s;
-		return 0;
-	}
-}
-
-void
-sdivgen(Node *l, Node *r, Node *ax, Node *dx)
-{
-	int a, s;
-	uint32_t m;
-	int64_t c;
-
-	c = r->vconst;
-	if(c < 0)
-		c = -c;
-	a = sdiv(c, &m, &s);
-//print("a=%d i=%ld s=%d m=%lux\n", a, (long)r->vconst, s, m);
-	gins(AMOVL, nodconst(m), ax);
-	gins(AIMULL, l, Z);
-	gins(AMOVL, l, ax);
-	if(a)
-		gins(AADDL, ax, dx);
-	gins(ASHRL, nodconst(31), ax);
-	gins(ASARL, nodconst(s), dx);
-	gins(AADDL, ax, dx);
-	if(r->vconst < 0)
-		gins(ANEGL, Z, dx);
-}
-
-void
-udivgen(Node *l, Node *r, Node *ax, Node *dx)
-{
-	int a, s, t;
-	uint32_t m;
-	Node nod;
-
-	a = udiv(r->vconst, &m, &s, &t);
-//print("a=%ud i=%ld p=%d s=%d m=%lux\n", a, (long)r->vconst, t, s, m);
-	if(t != 0) {
-		gins(AMOVL, l, ax);
-		gins(ASHRL, nodconst(t), ax);
-		gins(AMOVL, nodconst(m), dx);
-		gins(AMULL, dx, Z);
-	}
-	else if(a) {
-		if(l->op != OREGISTER) {
-			regalloc(&nod, l, Z);
-			gins(AMOVL, l, &nod);
-			l = &nod;
-		}
-		gins(AMOVL, nodconst(m), ax);
-		gins(AMULL, l, Z);
-		gins(AADDL, l, dx);
-		gins(ARCRL, nodconst(1), dx);
-		if(l == &nod)
-			regfree(l);
-	}
-	else {
-		gins(AMOVL, nodconst(m), ax);
-		gins(AMULL, l, Z);
-	}
-	if(s != 0)
-		gins(ASHRL, nodconst(s), dx);
-}
-
-void
-sext(Node *d, Node *s, Node *l)
-{
-	if(s->reg == D_AX && !nodreg(d, Z, D_DX)) {
-		reg[D_DX]++;
-		gins(ACDQ, Z, Z);
-	}
-	else {
-		regalloc(d, l, Z);
-		gins(AMOVL, s, d);
-		gins(ASARL, nodconst(31), d);
-	}
-}
-
-void
-sdiv2(int32_t c, int v, Node *l, Node *n)
-{
-	Node nod;
-
-	if(v > 0) {
-		if(v > 1) {
-			sext(&nod, n, l);
-			gins(AANDL, nodconst((1 << v) - 1), &nod);
-			gins(AADDL, &nod, n);
-			regfree(&nod);
-		}
-		else {
-			gins(ACMPL, n, nodconst(0x80000000));
-			gins(ASBBL, nodconst(-1), n);
-		}
-		gins(ASARL, nodconst(v), n);
-	}
-	if(c < 0)
-		gins(ANEGL, Z, n);
-}
-
-void
-smod2(int32_t c, int v, Node *l, Node *n)
-{
-	Node nod;
-
-	if(c == 1) {
-		zeroregm(n);
-		return;
-	}
-
-	sext(&nod, n, l);
-	if(v == 0) {
-		zeroregm(n);
-		gins(AXORL, &nod, n);
-		gins(ASUBL, &nod, n);
-	}
-	else if(v > 1) {
-		gins(AANDL, nodconst((1 << v) - 1), &nod);
-		gins(AADDL, &nod, n);
-		gins(AANDL, nodconst((1 << v) - 1), n);
-		gins(ASUBL, &nod, n);
-	}
-	else {
-		gins(AANDL, nodconst(1), n);
-		gins(AXORL, &nod, n);
-		gins(ASUBL, &nod, n);
-	}
-	regfree(&nod);
-}

+ 0 - 678
sys/src/cmd/6c/enam.c

@@ -1,678 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-char*	anames[] =
-{
-	"XXX",
-	"AAA",
-	"AAD",
-	"AAM",
-	"AAS",
-	"ADCB",
-	"ADCL",
-	"ADCW",
-	"ADDB",
-	"ADDL",
-	"ADDW",
-	"ADJSP",
-	"ANDB",
-	"ANDL",
-	"ANDW",
-	"ARPL",
-	"BOUNDL",
-	"BOUNDW",
-	"BSFL",
-	"BSFW",
-	"BSRL",
-	"BSRW",
-	"BTL",
-	"BTW",
-	"BTCL",
-	"BTCW",
-	"BTRL",
-	"BTRW",
-	"BTSL",
-	"BTSW",
-	"BYTE",
-	"CALL",
-	"CLC",
-	"CLD",
-	"CLI",
-	"CLTS",
-	"CMC",
-	"CMPB",
-	"CMPL",
-	"CMPW",
-	"CMPSB",
-	"CMPSL",
-	"CMPSW",
-	"DAA",
-	"DAS",
-	"DATA",
-	"DECB",
-	"DECL",
-	"DECQ",
-	"DECW",
-	"DIVB",
-	"DIVL",
-	"DIVW",
-	"ENTER",
-	"GLOBL",
-	"GOK",
-	"HISTORY",
-	"HLT",
-	"IDIVB",
-	"IDIVL",
-	"IDIVW",
-	"IMULB",
-	"IMULL",
-	"IMULW",
-	"INB",
-	"INL",
-	"INW",
-	"INCB",
-	"INCL",
-	"INCQ",
-	"INCW",
-	"INSB",
-	"INSL",
-	"INSW",
-	"INT",
-	"INTO",
-	"IRETL",
-	"IRETW",
-	"JCC",
-	"JCS",
-	"JCXZ",
-	"JEQ",
-	"JGE",
-	"JGT",
-	"JHI",
-	"JLE",
-	"JLS",
-	"JLT",
-	"JMI",
-	"JMP",
-	"JNE",
-	"JOC",
-	"JOS",
-	"JPC",
-	"JPL",
-	"JPS",
-	"LAHF",
-	"LARL",
-	"LARW",
-	"LEAL",
-	"LEAW",
-	"LEAVEL",
-	"LEAVEW",
-	"LOCK",
-	"LODSB",
-	"LODSL",
-	"LODSW",
-	"LONG",
-	"LOOP",
-	"LOOPEQ",
-	"LOOPNE",
-	"LSLL",
-	"LSLW",
-	"MOVB",
-	"MOVL",
-	"MOVW",
-	"MOVBLSX",
-	"MOVBLZX",
-	"MOVBQSX",
-	"MOVBQZX",
-	"MOVBWSX",
-	"MOVBWZX",
-	"MOVWLSX",
-	"MOVWLZX",
-	"MOVWQSX",
-	"MOVWQZX",
-	"MOVSB",
-	"MOVSL",
-	"MOVSW",
-	"MULB",
-	"MULL",
-	"MULW",
-	"NAME",
-	"NEGB",
-	"NEGL",
-	"NEGW",
-	"NOP",
-	"NOTB",
-	"NOTL",
-	"NOTW",
-	"ORB",
-	"ORL",
-	"ORW",
-	"OUTB",
-	"OUTL",
-	"OUTW",
-	"OUTSB",
-	"OUTSL",
-	"OUTSW",
-	"POPAL",
-	"POPAW",
-	"POPFL",
-	"POPFW",
-	"POPL",
-	"POPW",
-	"PUSHAL",
-	"PUSHAW",
-	"PUSHFL",
-	"PUSHFW",
-	"PUSHL",
-	"PUSHW",
-	"RCLB",
-	"RCLL",
-	"RCLW",
-	"RCRB",
-	"RCRL",
-	"RCRW",
-	"REP",
-	"REPN",
-	"RET",
-	"ROLB",
-	"ROLL",
-	"ROLW",
-	"RORB",
-	"RORL",
-	"RORW",
-	"SAHF",
-	"SALB",
-	"SALL",
-	"SALW",
-	"SARB",
-	"SARL",
-	"SARW",
-	"SBBB",
-	"SBBL",
-	"SBBW",
-	"SCASB",
-	"SCASL",
-	"SCASW",
-	"SETCC",
-	"SETCS",
-	"SETEQ",
-	"SETGE",
-	"SETGT",
-	"SETHI",
-	"SETLE",
-	"SETLS",
-	"SETLT",
-	"SETMI",
-	"SETNE",
-	"SETOC",
-	"SETOS",
-	"SETPC",
-	"SETPL",
-	"SETPS",
-	"CDQ",
-	"CWD",
-	"SHLB",
-	"SHLL",
-	"SHLW",
-	"SHRB",
-	"SHRL",
-	"SHRW",
-	"STC",
-	"STD",
-	"STI",
-	"STOSB",
-	"STOSL",
-	"STOSW",
-	"SUBB",
-	"SUBL",
-	"SUBW",
-	"SYSCALL",
-	"TESTB",
-	"TESTL",
-	"TESTW",
-	"TEXT",
-	"VERR",
-	"VERW",
-	"WAIT",
-	"WORD",
-	"XCHGB",
-	"XCHGL",
-	"XCHGW",
-	"XLAT",
-	"XORB",
-	"XORL",
-	"XORW",
-	"FMOVB",
-	"FMOVBP",
-	"FMOVD",
-	"FMOVDP",
-	"FMOVF",
-	"FMOVFP",
-	"FMOVL",
-	"FMOVLP",
-	"FMOVV",
-	"FMOVVP",
-	"FMOVW",
-	"FMOVWP",
-	"FMOVX",
-	"FMOVXP",
-	"FCOMB",
-	"FCOMBP",
-	"FCOMD",
-	"FCOMDP",
-	"FCOMDPP",
-	"FCOMF",
-	"FCOMFP",
-	"FCOML",
-	"FCOMLP",
-	"FCOMW",
-	"FCOMWP",
-	"FUCOM",
-	"FUCOMP",
-	"FUCOMPP",
-	"FADDDP",
-	"FADDW",
-	"FADDL",
-	"FADDF",
-	"FADDD",
-	"FMULDP",
-	"FMULW",
-	"FMULL",
-	"FMULF",
-	"FMULD",
-	"FSUBDP",
-	"FSUBW",
-	"FSUBL",
-	"FSUBF",
-	"FSUBD",
-	"FSUBRDP",
-	"FSUBRW",
-	"FSUBRL",
-	"FSUBRF",
-	"FSUBRD",
-	"FDIVDP",
-	"FDIVW",
-	"FDIVL",
-	"FDIVF",
-	"FDIVD",
-	"FDIVRDP",
-	"FDIVRW",
-	"FDIVRL",
-	"FDIVRF",
-	"FDIVRD",
-	"FXCHD",
-	"FFREE",
-	"FLDCW",
-	"FLDENV",
-	"FRSTOR",
-	"FSAVE",
-	"FSTCW",
-	"FSTENV",
-	"FSTSW",
-	"F2XM1",
-	"FABS",
-	"FCHS",
-	"FCLEX",
-	"FCOS",
-	"FDECSTP",
-	"FINCSTP",
-	"FINIT",
-	"FLD1",
-	"FLDL2E",
-	"FLDL2T",
-	"FLDLG2",
-	"FLDLN2",
-	"FLDPI",
-	"FLDZ",
-	"FNOP",
-	"FPATAN",
-	"FPREM",
-	"FPREM1",
-	"FPTAN",
-	"FRNDINT",
-	"FSCALE",
-	"FSIN",
-	"FSINCOS",
-	"FSQRT",
-	"FTST",
-	"FXAM",
-	"FXTRACT",
-	"FYL2X",
-	"FYL2XP1",
-	"END",
-	"DYNT",
-	"INIT",
-	"SIGNAME",
-	"CMPXCHGB",
-	"CMPXCHGL",
-	"CMPXCHGW",
-	"CMPXCHG8B",
-	"CPUID",
-	"INVD",
-	"INVLPG",
-	"LFENCE",
-	"MFENCE",
-	"MOVNTIL",
-	"RDMSR",
-	"RDPMC",
-	"RDTSC",
-	"RSM",
-	"SFENCE",
-	"SYSRET",
-	"WBINVD",
-	"WRMSR",
-	"XADDB",
-	"XADDL",
-	"XADDW",
-	"CMOVLCC",
-	"CMOVLCS",
-	"CMOVLEQ",
-	"CMOVLGE",
-	"CMOVLGT",
-	"CMOVLHI",
-	"CMOVLLE",
-	"CMOVLLS",
-	"CMOVLLT",
-	"CMOVLMI",
-	"CMOVLNE",
-	"CMOVLOC",
-	"CMOVLOS",
-	"CMOVLPC",
-	"CMOVLPL",
-	"CMOVLPS",
-	"CMOVQCC",
-	"CMOVQCS",
-	"CMOVQEQ",
-	"CMOVQGE",
-	"CMOVQGT",
-	"CMOVQHI",
-	"CMOVQLE",
-	"CMOVQLS",
-	"CMOVQLT",
-	"CMOVQMI",
-	"CMOVQNE",
-	"CMOVQOC",
-	"CMOVQOS",
-	"CMOVQPC",
-	"CMOVQPL",
-	"CMOVQPS",
-	"CMOVWCC",
-	"CMOVWCS",
-	"CMOVWEQ",
-	"CMOVWGE",
-	"CMOVWGT",
-	"CMOVWHI",
-	"CMOVWLE",
-	"CMOVWLS",
-	"CMOVWLT",
-	"CMOVWMI",
-	"CMOVWNE",
-	"CMOVWOC",
-	"CMOVWOS",
-	"CMOVWPC",
-	"CMOVWPL",
-	"CMOVWPS",
-	"ADCQ",
-	"ADDQ",
-	"ANDQ",
-	"BSFQ",
-	"BSRQ",
-	"BTCQ",
-	"BTQ",
-	"BTRQ",
-	"BTSQ",
-	"CMPQ",
-	"CMPSQ",
-	"CMPXCHGQ",
-	"CQO",
-	"DIVQ",
-	"IDIVQ",
-	"IMULQ",
-	"IRETQ",
-	"LEAQ",
-	"LEAVEQ",
-	"LODSQ",
-	"MOVQ",
-	"MOVLQSX",
-	"MOVLQZX",
-	"MOVNTIQ",
-	"MOVSQ",
-	"MULQ",
-	"NEGQ",
-	"NOTQ",
-	"ORQ",
-	"POPFQ",
-	"POPQ",
-	"PUSHFQ",
-	"PUSHQ",
-	"RCLQ",
-	"RCRQ",
-	"ROLQ",
-	"RORQ",
-	"QUAD",
-	"SALQ",
-	"SARQ",
-	"SBBQ",
-	"SCASQ",
-	"SHLQ",
-	"SHRQ",
-	"STOSQ",
-	"SUBQ",
-	"TESTQ",
-	"XADDQ",
-	"XCHGQ",
-	"XORQ",
-	"ADDPD",
-	"ADDPS",
-	"ADDSD",
-	"ADDSS",
-	"ANDNPD",
-	"ANDNPS",
-	"ANDPD",
-	"ANDPS",
-	"CMPPD",
-	"CMPPS",
-	"CMPSD",
-	"CMPSS",
-	"COMISD",
-	"COMISS",
-	"CVTPD2PL",
-	"CVTPD2PS",
-	"CVTPL2PD",
-	"CVTPL2PS",
-	"CVTPS2PD",
-	"CVTPS2PL",
-	"CVTSD2SL",
-	"CVTSD2SQ",
-	"CVTSD2SS",
-	"CVTSL2SD",
-	"CVTSL2SS",
-	"CVTSQ2SD",
-	"CVTSQ2SS",
-	"CVTSS2SD",
-	"CVTSS2SL",
-	"CVTSS2SQ",
-	"CVTTPD2PL",
-	"CVTTPS2PL",
-	"CVTTSD2SL",
-	"CVTTSD2SQ",
-	"CVTTSS2SL",
-	"CVTTSS2SQ",
-	"DIVPD",
-	"DIVPS",
-	"DIVSD",
-	"DIVSS",
-	"EMMS",
-	"FXRSTOR",
-	"FXRSTOR64",
-	"FXSAVE",
-	"FXSAVE64",
-	"LDMXCSR",
-	"MASKMOVOU",
-	"MASKMOVQ",
-	"MAXPD",
-	"MAXPS",
-	"MAXSD",
-	"MAXSS",
-	"MINPD",
-	"MINPS",
-	"MINSD",
-	"MINSS",
-	"MOVAPD",
-	"MOVAPS",
-	"MOVOU",
-	"MOVHLPS",
-	"MOVHPD",
-	"MOVHPS",
-	"MOVLHPS",
-	"MOVLPD",
-	"MOVLPS",
-	"MOVMSKPD",
-	"MOVMSKPS",
-	"MOVNTO",
-	"MOVNTPD",
-	"MOVNTPS",
-	"MOVNTQ",
-	"MOVO",
-	"MOVQOZX",
-	"MOVSD",
-	"MOVSS",
-	"MOVUPD",
-	"MOVUPS",
-	"MULPD",
-	"MULPS",
-	"MULSD",
-	"MULSS",
-	"ORPD",
-	"ORPS",
-	"PACKSSLW",
-	"PACKSSWB",
-	"PACKUSWB",
-	"PADDB",
-	"PADDL",
-	"PADDQ",
-	"PADDSB",
-	"PADDSW",
-	"PADDUSB",
-	"PADDUSW",
-	"PADDW",
-	"PANDB",
-	"PANDL",
-	"PANDSB",
-	"PANDSW",
-	"PANDUSB",
-	"PANDUSW",
-	"PANDW",
-	"PAND",
-	"PANDN",
-	"PAVGB",
-	"PAVGW",
-	"PCMPEQB",
-	"PCMPEQL",
-	"PCMPEQW",
-	"PCMPGTB",
-	"PCMPGTL",
-	"PCMPGTW",
-	"PEXTRW",
-	"PFACC",
-	"PFADD",
-	"PFCMPEQ",
-	"PFCMPGE",
-	"PFCMPGT",
-	"PFMAX",
-	"PFMIN",
-	"PFMUL",
-	"PFNACC",
-	"PFPNACC",
-	"PFRCP",
-	"PFRCPIT1",
-	"PFRCPI2T",
-	"PFRSQIT1",
-	"PFRSQRT",
-	"PFSUB",
-	"PFSUBR",
-	"PINSRW",
-	"PMADDWL",
-	"PMAXSW",
-	"PMAXUB",
-	"PMINSW",
-	"PMINUB",
-	"PMOVMSKB",
-	"PMULHRW",
-	"PMULHUW",
-	"PMULHW",
-	"PMULLW",
-	"PMULULQ",
-	"POR",
-	"PSADBW",
-	"PSHUFHW",
-	"PSHUFL",
-	"PSHUFLW",
-	"PSHUFW",
-	"PSLLO",
-	"PSLLL",
-	"PSLLQ",
-	"PSLLW",
-	"PSRAL",
-	"PSRAW",
-	"PSRLO",
-	"PSRLL",
-	"PSRLQ",
-	"PSRLW",
-	"PSUBB",
-	"PSUBL",
-	"PSUBQ",
-	"PSUBSB",
-	"PSUBSW",
-	"PSUBUSB",
-	"PSUBUSW",
-	"PSUBW",
-	"PSWAPL",
-	"PUNPCKHBW",
-	"PUNPCKHLQ",
-	"PUNPCKHQDQ",
-	"PUNPCKHWL",
-	"PUNPCKLBW",
-	"PUNPCKLLQ",
-	"PUNPCKLQDQ",
-	"PUNPCKLWL",
-	"PXOR",
-	"RCPPS",
-	"RCPSS",
-	"RSQRTPS",
-	"RSQRTSS",
-	"SHUFPD",
-	"SHUFPS",
-	"SQRTPD",
-	"SQRTPS",
-	"SQRTSD",
-	"SQRTSS",
-	"STMXCSR",
-	"SUBPD",
-	"SUBPS",
-	"SUBSD",
-	"SUBSS",
-	"UCOMISD",
-	"UCOMISS",
-	"UNPCKHPD",
-	"UNPCKHPS",
-	"UNPCKLPD",
-	"UNPCKLPS",
-	"XORPD",
-	"XORPS",
-	"PF2IW",
-	"PF2IL",
-	"PI2FW",
-	"PI2FL",
-	"RETFW",
-	"RETFL",
-	"RETFQ",
-	"SWAPGS",
-	"MODE",
-	"LAST",
-};

+ 0 - 389
sys/src/cmd/6c/gc.h

@@ -1,389 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include	"../cc/cc.h"
-#include	"../6c/6.out.h"
-
-/*
- * 6c/amd64
- * Intel 386 with AMD64 extensions
- */
-#define	SZ_CHAR		1
-#define	SZ_SHORT	2
-#define	SZ_INT		4
-#define	SZ_LONG		4
-#define	SZ_IND		8
-#define	SZ_FLOAT	4
-#define	SZ_VLONG	8
-#define	SZ_DOUBLE	8
-#define	FNX		100
-
-typedef	struct	Adr	Adr;
-typedef	struct	Prog	Prog;
-typedef	struct	Case	Case;
-typedef	struct	C1	C1;
-typedef	struct	Var	Var;
-typedef	struct	Reg	Reg;
-typedef	struct	Rgn	Rgn;
-typedef	struct	Renv	Renv;
-
-EXTERN	struct
-{
-	Node*	regtree;
-	Node*	basetree;
-	short	scale;
-	short	reg;
-	short	ptr;
-} idx;
-
-struct	Adr
-{
-	vlong	offset;
-	double	dval;
-	char	sval[NSNAME];
-
-	Sym*	sym;
-	uchar	type;
-	uchar	index;
-	uchar	etype;
-	uchar	scale;	/* doubles as width in DATA op */
-};
-#define	A	((Adr*)0)
-
-#define	INDEXED	9
-struct	Prog
-{
-	Adr	from;
-	Adr	to;
-	Prog*	link;
-	long	lineno;
-	short	as;
-};
-#define	P	((Prog*)0)
-
-struct	Case
-{
-	Case*	link;
-	vlong	val;
-	long	label;
-	char	def;
-	char	isv;
-};
-#define	C	((Case*)0)
-
-struct	C1
-{
-	vlong	val;
-	long	label;
-};
-
-struct	Var
-{
-	vlong	offset;
-	Sym*	sym;
-	char	name;
-	char	etype;
-};
-
-struct	Reg
-{
-	long	pc;
-	long	rpo;		/* reverse post ordering */
-
-	Bits	set;
-	Bits	use1;
-	Bits	use2;
-
-	Bits	refbehind;
-	Bits	refahead;
-	Bits	calbehind;
-	Bits	calahead;
-	Bits	regdiff;
-	Bits	act;
-
-	long	regu;
-	long	loop;		/* could be shorter */
-
-	Reg*	log5;
-	long	active;
-
-	Reg*	p1;
-	Reg*	p2;
-	Reg*	p2link;
-	Reg*	s1;
-	Reg*	s2;
-	Reg*	link;
-	Prog*	prog;
-};
-#define	R	((Reg*)0)
-
-struct	Renv
-{
-	int	safe;
-	Node	base;
-	Node*	saved;
-	Node*	scope;
-};
-
-#define	NRGN	600
-struct	Rgn
-{
-	Reg*	enter;
-	short	cost;
-	short	varno;
-	short	regno;
-};
-
-EXTERN	long	breakpc;
-EXTERN	long	nbreak;
-EXTERN	Case*	cases;
-EXTERN	Node	constnode;
-EXTERN	Node	fconstnode;
-EXTERN	Node	vconstnode;
-EXTERN	long	continpc;
-EXTERN	long	curarg;
-EXTERN	long	cursafe;
-EXTERN	Prog*	firstp;
-EXTERN	Prog*	lastp;
-EXTERN	long	maxargsafe;
-EXTERN	int	mnstring;
-EXTERN	Node*	nodrat;
-EXTERN	Node*	nodret;
-EXTERN	Node*	nodsafe;
-EXTERN	long	nrathole;
-EXTERN	long	nstring;
-EXTERN	Prog*	p;
-EXTERN	long	pc;
-EXTERN	Node	lregnode;
-EXTERN	Node	qregnode;
-EXTERN	char	string[NSNAME];
-EXTERN	Sym*	symrathole;
-EXTERN	Node	znode;
-EXTERN	Prog	zprog;
-EXTERN	int	reg[D_NONE];
-EXTERN	long	exregoffset;
-EXTERN	long	exfregoffset;
-EXTERN	uchar	typechlpv[NTYPE];
-
-#define	BLOAD(r)	band(bnot(r->refbehind), r->refahead)
-#define	BSTORE(r)	band(bnot(r->calbehind), r->calahead)
-#define	LOAD(r)		(~r->refbehind.b[z] & r->refahead.b[z])
-#define	STORE(r)	(~r->calbehind.b[z] & r->calahead.b[z])
-
-#define	bset(a,n)	((a).b[(n)/32]&(1L<<(n)%32))
-
-#define	CLOAD	5
-#define	CREF	5
-#define	CINF	1000
-#define	LOOP	3
-
-EXTERN	Rgn	region[NRGN];
-EXTERN	Rgn*	rgp;
-EXTERN	int	nregion;
-EXTERN	int	nvar;
-
-EXTERN	Bits	externs;
-EXTERN	Bits	params;
-EXTERN	Bits	consts;
-EXTERN	Bits	addrs;
-
-EXTERN	long	regbits;
-EXTERN	long	exregbits;
-
-EXTERN	int	change;
-EXTERN	int	suppress;
-
-EXTERN	Reg*	firstr;
-EXTERN	Reg*	lastr;
-EXTERN	Reg	zreg;
-EXTERN	Reg*	freer;
-EXTERN	Var	var[NVAR];
-EXTERN	long*	idom;
-EXTERN	Reg**	rpo2r;
-EXTERN	long	maxnr;
-
-extern	char*	anames[];
-
-/*
- * sgen.c
- */
-void	codgen(Node*, Node*);
-void	gen(Node*);
-void	noretval(int);
-void	usedset(Node*, int);
-void	xcom(Node*);
-void	indx(Node*);
-int	bcomplex(Node*, Node*);
-
-/*
- * cgen.c
- */
-void	zeroregm(Node*);
-void	cgen(Node*, Node*);
-void	reglcgen(Node*, Node*, Node*);
-void	lcgen(Node*, Node*);
-void	bcgen(Node*, int);
-void	boolgen(Node*, int, Node*);
-void	sugen(Node*, Node*, long);
-int	needreg(Node*, int);
-int	hardconst(Node*);
-int	immconst(Node*);
-
-/*
- * cgen64.c
- */
-int	vaddr(Node*, int);
-void	loadpair(Node*, Node*);
-int	cgen64(Node*, Node*);
-void	testv(Node*, int);
-
-/*
- * txt.c
- */
-void	ginit(void);
-void	gclean(void);
-void	nextpc(void);
-void	gargs(Node*, Node*, Node*);
-void	garg1(Node*, Node*, Node*, int, Node**);
-Node*	nodconst(long);
-Node*	nodfconst(double);
-Node*	nodgconst(vlong, Type*);
-int	nodreg(Node*, Node*, int);
-int	isreg(Node*, int);
-void	regret(Node*, Node*);
-void	regalloc(Node*, Node*, Node*);
-void	regfree(Node*);
-void	regialloc(Node*, Node*, Node*);
-void	regsalloc(Node*, Node*);
-void	regaalloc1(Node*, Node*);
-void	regaalloc(Node*, Node*);
-void	regind(Node*, Node*);
-void	gprep(Node*, Node*);
-void	naddr(Node*, Adr*);
-void	gcmp(int, Node*, vlong);
-void	gmove(Node*, Node*);
-void	gins(int a, Node*, Node*);
-void	gopcode(int, Type*, Node*, Node*);
-int	samaddr(Node*, Node*);
-void	gbranch(int);
-void	patch(Prog*, long);
-int	sconst(Node*);
-void	gpseudo(int, Sym*, Node*);
-
-/*
- * swt.c
- */
-int	swcmp(const void*, const void*);
-void	doswit(Node*);
-void	swit1(C1*, int, long, Node*);
-void	casf(void);
-void	bitload(Node*, Node*, Node*, Node*, Node*);
-void	bitstore(Node*, Node*, Node*, Node*, Node*);
-long	outstring(char*, long);
-void	nullwarn(Node*, Node*);
-void	gextern(Sym*, Node*, long, long);
-void	outcode(void);
-void	ieeedtod(Ieee*, double);
-
-/*
- * list
- */
-void	listinit(void);
-int	Pconv(Fmt*);
-int	Aconv(Fmt*);
-int	Dconv(Fmt*);
-int	Sconv(Fmt*);
-int	Rconv(Fmt*);
-int	Xconv(Fmt*);
-int	Bconv(Fmt*);
-
-/*
- * reg.c
- */
-Reg*	rega(void);
-int	rcmp(const void*, const void*);
-void	regopt(Prog*);
-void	addmove(Reg*, int, int, int);
-Bits	mkvar(Reg*, Adr*);
-void	prop(Reg*, Bits, Bits);
-void	loopit(Reg*, long);
-void	synch(Reg*, Bits);
-uint32_t	allreg(uint32_t, Rgn*);
-void	paint1(Reg*, int);
-uint32_t	paint2(Reg*, int);
-void	paint3(Reg*, int, long, int);
-void	addreg(Adr*, int);
-
-/*
- * peep.c
- */
-void	peep(void);
-void	excise(Reg*);
-Reg*	uniqp(Reg*);
-Reg*	uniqs(Reg*);
-int	regtyp(Adr*);
-int	anyvar(Adr*);
-int	subprop(Reg*);
-int	copyprop(Reg*);
-int	copy1(Adr*, Adr*, Reg*, int);
-int	copyu(Prog*, Adr*, Adr*);
-
-int	copyas(Adr*, Adr*);
-int	copyau(Adr*, Adr*);
-int	copysub(Adr*, Adr*, Adr*, int);
-int	copysub1(Prog*, Adr*, Adr*, int);
-
-long	RtoB(int);
-long	FtoB(int);
-int	BtoR(long);
-int	BtoF(long);
-
-#define	D_HI	D_NONE
-#define	D_LO	D_NONE
-
-#define	isregtype(t)	((t)>= D_AX && (t)<=D_R15)
-
-/*
- * bound
- */
-void	comtarg(void);
-
-/*
- * com64
- */
-int	cond(int);
-int	com64(Node*);
-void	com64init(void);
-void	bool64(Node*);
-long	lo64v(Node*);
-long	hi64v(Node*);
-Node*	lo64(Node*);
-Node*	hi64(Node*);
-
-/*
- * div/mul
- */
-void	sdivgen(Node*, Node*, Node*, Node*);
-void	udivgen(Node*, Node*, Node*, Node*);
-void	sdiv2(long, int, Node*, Node*);
-void	smod2(long, int, Node*, Node*);
-void	mulgen(Type*, Node*, Node*);
-void	genmuladd(Node*, Node*, int, Node*);
-void	shiftit(Type*, Node*, Node*);
-
-#pragma	varargck	type	"A"	int
-#pragma	varargck	type	"B"	Bits
-#pragma	varargck	type	"D"	Adr*
-#pragma	varargck	type	"P"	Prog*
-#pragma	varargck	type	"R"	int
-#pragma	varargck	type	"S"	char*
-
-#define	D_X7	(D_X0+7)
-
-void	fgopcode(int, Node*, Node*, int, int);

+ 0 - 346
sys/src/cmd/6c/list.c

@@ -1,346 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#define EXTERN
-#include "gc.h"
-
-void
-listinit(void)
-{
-
-	fmtinstall('A', Aconv);
-	fmtinstall('B', Bconv);
-	fmtinstall('P', Pconv);
-	fmtinstall('S', Sconv);
-	fmtinstall('D', Dconv);
-	fmtinstall('R', Rconv);
-}
-
-int
-Bconv(Fmt *fp)
-{
-	char str[STRINGSZ], ss[STRINGSZ], *s;
-	Bits bits;
-	int i;
-
-	str[0] = 0;
-	bits = va_arg(fp->args, Bits);
-	while(bany(&bits)) {
-		i = bnum(bits);
-		if(str[0])
-			strcat(str, " ");
-		if(var[i].sym == S) {
-			sprint(ss, "$%lld", var[i].offset);
-			s = ss;
-		} else
-			s = var[i].sym->name;
-		if(strlen(str) + strlen(s) + 1 >= STRINGSZ)
-			break;
-		strcat(str, s);
-		bits.b[i/32] &= ~(1L << (i%32));
-	}
-	return fmtstrcpy(fp, str);
-}
-
-int
-Pconv(Fmt *fp)
-{
-	char str[STRINGSZ];
-	Prog *p;
-
-	p = va_arg(fp->args, Prog*);
-	if(p->as == ADATA)
-		sprint(str, "	%A	%D/%d,%D",
-			p->as, &p->from, p->from.scale, &p->to);
-	else if(p->as == ATEXT)
-		sprint(str, "	%A	%D,%d,%D",
-			p->as, &p->from, p->from.scale, &p->to);
-	else
-		sprint(str, "	%A	%D,%D",
-			p->as, &p->from, &p->to);
-	return fmtstrcpy(fp, str);
-}
-
-int
-Aconv(Fmt *fp)
-{
-	int i;
-
-	i = va_arg(fp->args, int);
-	return fmtstrcpy(fp, anames[i]);
-}
-
-int
-Dconv(Fmt *fp)
-{
-	char str[40], s[20];
-	Adr *a;
-	int i;
-
-	a = va_arg(fp->args, Adr*);
-	i = a->type;
-	if(i >= D_INDIR) {
-		if(a->offset)
-			sprint(str, "%lld(%R)", a->offset, i-D_INDIR);
-		else
-			sprint(str, "(%R)", i-D_INDIR);
-		goto brk;
-	}
-	switch(i) {
-
-	default:
-		if(a->offset)
-			sprint(str, "$%lld,%R", a->offset, i);
-		else
-			sprint(str, "%R", i);
-		break;
-
-	case D_NONE:
-		str[0] = 0;
-		break;
-
-	case D_BRANCH:
-		sprint(str, "%lld(PC)", a->offset-pc);
-		break;
-
-	case D_EXTERN:
-		sprint(str, "%s+%lld(SB)", a->sym->name, a->offset);
-		break;
-
-	case D_STATIC:
-		sprint(str, "%s<>+%lld(SB)", a->sym->name,
-			a->offset);
-		break;
-
-	case D_AUTO:
-		sprint(str, "%s+%lld(SP)", a->sym->name, a->offset);
-		break;
-
-	case D_PARAM:
-		if(a->sym)
-			sprint(str, "%s+%lld(FP)", a->sym->name, a->offset);
-		else
-			sprint(str, "%lld(FP)", a->offset);
-		break;
-
-	case D_CONST:
-		sprint(str, "$%lld", a->offset);
-		break;
-
-	case D_FCONST:
-		sprint(str, "$(%.17e)", a->dval);
-		break;
-
-	case D_SCONST:
-		sprint(str, "$\"%S\"", a->sval);
-		break;
-
-	case D_ADDR:
-		a->type = a->index;
-		a->index = D_NONE;
-		sprint(str, "$%D", a);
-		a->index = a->type;
-		a->type = D_ADDR;
-		goto conv;
-	}
-brk:
-	if(a->index != D_NONE) {
-		sprint(s, "(%R*%d)", (int)a->index, (int)a->scale);
-		strcat(str, s);
-	}
-conv:
-	return fmtstrcpy(fp, str);
-}
-
-char*	regstr[] =
-{
-	"AL",		/* [D_AL] */
-	"CL",
-	"DL",
-	"BL",
-	"SPB",
-	"BPB",
-	"SIB",
-	"DIB",
-	"R8B",
-	"R9B",
-	"R10B",
-	"R11B",
-	"R12B",
-	"R13B",
-	"R14B",
-	"R15B",
-
-	"AX",		/* [D_AX] */
-	"CX",
-	"DX",
-	"BX",
-	"SP",
-	"BP",
-	"SI",
-	"DI",
-	"R8",
-	"R9",
-	"R10",
-	"R11",
-	"R12",
-	"R13",
-	"R14",
-	"R15",
-
-	"AH",
-	"CH",
-	"DH",
-	"BH",
-
-	"F0",		/* [D_F0] */
-	"F1",
-	"F2",
-	"F3",
-	"F4",
-	"F5",
-	"F6",
-	"F7",
-
-	"M0",
-	"M1",
-	"M2",
-	"M3",
-	"M4",
-	"M5",
-	"M6",
-	"M7",
-
-	"X0",
-	"X1",
-	"X2",
-	"X3",
-	"X4",
-	"X5",
-	"X6",
-	"X7",
-	"X8",
-	"X9",
-	"X10",
-	"X11",
-	"X12",
-	"X13",
-	"X14",
-	"X15",
-
-	"CS",		/* [D_CS] */
-	"SS",
-	"DS",
-	"ES",
-	"FS",
-	"GS",
-
-	"GDTR",		/* [D_GDTR] */
-	"IDTR",		/* [D_IDTR] */
-	"LDTR",		/* [D_LDTR] */
-	"MSW",		/* [D_MSW] */
-	"TASK",		/* [D_TASK] */
-
-	"CR0",		/* [D_CR] */
-	"CR1",
-	"CR2",
-	"CR3",
-	"CR4",
-	"CR5",
-	"CR6",
-	"CR7",
-	"CR8",
-	"CR9",
-	"CR10",
-	"CR11",
-	"CR12",
-	"CR13",
-	"CR14",
-	"CR15",
-
-	"DR0",		/* [D_DR] */
-	"DR1",
-	"DR2",
-	"DR3",
-	"DR4",
-	"DR5",
-	"DR6",
-	"DR7",
-
-	"TR0",		/* [D_TR] */
-	"TR1",
-	"TR2",
-	"TR3",
-	"TR4",
-	"TR5",
-	"TR6",
-	"TR7",
-
-	"NONE",		/* [D_NONE] */
-};
-
-int
-Rconv(Fmt *fp)
-{
-	char str[20];
-	int r;
-
-	r = va_arg(fp->args, int);
-	if(r >= D_AL && r <= D_NONE)
-		sprint(str, "%s", regstr[r-D_AL]);
-	else
-		sprint(str, "gok(%d)", r);
-
-	return fmtstrcpy(fp, str);
-}
-
-int
-Sconv(Fmt *fp)
-{
-	int i, c;
-	char str[30], *p, *a;
-
-	a = va_arg(fp->args, char*);
-	p = str;
-	for(i=0; i<sizeof(double); i++) {
-		c = a[i] & 0xff;
-		if(c >= 'a' && c <= 'z' ||
-		   c >= 'A' && c <= 'Z' ||
-		   c >= '0' && c <= '9') {
-			*p++ = c;
-			continue;
-		}
-		*p++ = '\\';
-		switch(c) {
-		default:
-			if(c < 040 || c >= 0177)
-				break;	/* not portable */
-			p[-1] = c;
-			continue;
-		case 0:
-			*p++ = 'z';
-			continue;
-		case '\\':
-		case '"':
-			*p++ = c;
-			continue;
-		case '\n':
-			*p++ = 'n';
-			continue;
-		case '\t':
-			*p++ = 't';
-			continue;
-		}
-		*p++ = (c>>6) + '0';
-		*p++ = ((c>>3) & 7) + '0';
-		*p++ = (c & 7) + '0';
-	}
-	*p = 0;
-	return fmtstrcpy(fp, str);
-}

+ 0 - 87
sys/src/cmd/6c/machcap.c

@@ -1,87 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "gc.h"
-
-int
-machcap(Node *n)
-{
-
-	if(n == Z)
-		return 1;	/* test */
-
-	switch(n->op) {
-	case OMUL:
-	case OLMUL:
-	case OASMUL:
-	case OASLMUL:
-		if(typechl[n->type->etype])
-			return 1;
-		if(typev[n->type->etype]) {
-				return 1;
-		}
-		break;
-
-	case OCOM:
-	case ONEG:
-	case OADD:
-	case OAND:
-	case OOR:
-	case OSUB:
-	case OXOR:
-	case OASHL:
-	case OLSHR:
-	case OASHR:
-		if(typechlv[n->left->type->etype])
-			return 1;
-		break;
-
-	case OCAST:
-		return 1;
-
-	case OCOND:
-	case OCOMMA:
-	case OLIST:
-	case OANDAND:
-	case OOROR:
-	case ONOT:
-		return 1;
-
-	case OASADD:
-	case OASSUB:
-	case OASAND:
-	case OASOR:
-	case OASXOR:
-		return 1;
-
-	case OASASHL:
-	case OASASHR:
-	case OASLSHR:
-		return 1;
-
-	case OPOSTINC:
-	case OPOSTDEC:
-	case OPREINC:
-	case OPREDEC:
-		return 1;
-
-	case OEQ:
-	case ONE:
-	case OLE:
-	case OGT:
-	case OLT:
-	case OGE:
-	case OHI:
-	case OHS:
-	case OLO:
-	case OLS:
-		return 1;
-	}
-	return 0;
-}

+ 0 - 15
sys/src/cmd/6c/mkenam

@@ -1,15 +0,0 @@
-ed - ../6c/6.out.h <<'!'
-v/^	A/d
-,s/^	A/	"/
-g/ .*$/s///
-,s/,*$/",/
-1i
-char*	anames[] =
-{
-.
-$a
-};
-.
-w enam.c
-Q
-!

+ 0 - 38
sys/src/cmd/6c/mkfile

@@ -1,38 +0,0 @@
-</$objtype/mkfile
-
-TARG=6c
-OFILES=\
-	cgen.$O\
-	enam.$O\
-	list.$O\
-	sgen.$O\
-	swt.$O\
-	txt.$O\
-	reg.$O\
-	peep.$O\
-	pgen.$O\
-	pswt.$O\
-	machcap.$O\
-	div.$O\
-	mul.$O\
-
-HFILES=\
-	gc.h\
-	6.out.h\
-	../cc/cc.h\
-
-LIB=../cc/cc.a$O
-
-BIN=/$objtype/bin
-</sys/src/cmd/mkone
-
-$LIB:
-	cd ../cc
-	mk install
-	mk clean
-
-%.$O: ../cc/%.c
-	$CC $CFLAGS ../cc/$stem.c
-
-bound.$O:	bound.h
-

+ 0 - 437
sys/src/cmd/6c/mul.c

@@ -1,437 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "gc.h"
-
-typedef struct	Malg	Malg;
-typedef struct	Mparam	Mparam;
-
-struct	Malg
-{
-	char	vals[10];
-};
-
-struct	Mparam
-{
-	uint32_t	value;
-	char	alg;
-	char	neg;
-	char	shift;
-	char	arg;
-	char	off;
-};
-
-static	Mparam	multab[32];
-static	int	mulptr;
-
-static	Malg	malgs[]	=
-{
-	{0, 100},
-	{-1, 1, 100},
-	{-9, -5, -3, 3, 5, 9, 100},
-	{6, 10, 12, 18, 20, 24, 36, 40, 72, 100},
-	{-8, -4, -2, 2, 4, 8, 100},
-};
-
-/*
- * return position of lowest 1
- */
-int
-lowbit(uint32_t v)
-{
-	int s, i;
-	uint32_t m;
-
-	s = 0;
-	m = 0xFFFFFFFFUL;
-	for(i = 16; i > 0; i >>= 1) {
-		m >>= i;
-		if((v & m) == 0) {
-			v >>= i;
-			s += i;
-		}
-	}
-	return s;
-}
-
-void
-genmuladd(Node *d, Node *s, int m, Node *a)
-{
-	Node nod;
-
-	nod.op = OINDEX;
-	nod.left = a;
-	nod.right = s;
-	nod.scale = m;
-	nod.type = types[TIND];
-	nod.xoffset = 0;
-	xcom(&nod);
-	gopcode(OADDR, d->type, &nod, d);
-}
-
-void
-mulparam(uint32_t m, Mparam *mp)
-{
-	int c, i, j, n, o, q, s;
-	int bc, bi, bn, bo, bq, bs, bt;
-	char *p;
-	int32_t u;
-	uint32_t t;
-
-	bc = bq = 10;
-	bi = bn = bo = bs = bt = 0;
-	for(i = 0; i < nelem(malgs); i++) {
-		for(p = malgs[i].vals, j = 0; (o = p[j]) < 100; j++)
-		for(s = 0; s < 2; s++) {
-			c = 10;
-			q = 10;
-			u = m - o;
-			if(u == 0)
-				continue;
-			if(s) {
-				o = -o;
-				if(o > 0)
-					continue;
-				u = -u;
-			}
-			n = lowbit(u);
-			t = (uint32_t)u >> n;
-			switch(i) {
-			case 0:
-				if(t == 1) {
-					c = s + 1;
-					q = 0;
-					break;
-				}
-				switch(t) {
-				case 3:
-				case 5:
-				case 9:
-					c = s + 1;
-					if(n)
-						c++;
-					q = 0;
-					break;
-				}
-				if(s)
-					break;
-				switch(t) {
-				case 15:
-				case 25:
-				case 27:
-				case 45:
-				case 81:
-					c = 2;
-					if(n)
-						c++;
-					q = 1;
-					break;
-				}
-				break;
-			case 1:
-				if(t == 1) {
-					c = 3;
-					q = 3;
-					break;
-				}
-				switch(t) {
-				case 3:
-				case 5:
-				case 9:
-					c = 3;
-					q = 2;
-					break;
-				}
-				break;
-			case 2:
-				if(t == 1) {
-					c = 3;
-					q = 2;
-					break;
-				}
-				break;
-			case 3:
-				if(s)
-					break;
-				if(t == 1) {
-					c = 3;
-					q = 1;
-					break;
-				}
-				break;
-			case 4:
-				if(t == 1) {
-					c = 3;
-					q = 0;
-					break;
-				}
-				break;
-			}
-			if(c < bc || (c == bc && q > bq)) {
-				bc = c;
-				bi = i;
-				bn = n;
-				bo = o;
-				bq = q;
-				bs = s;
-				bt = t;
-			}
-		}
-	}
-	mp->value = m;
-	if(bc <= 3) {
-		mp->alg = bi;
-		mp->shift = bn;
-		mp->off = bo;
-		mp->neg = bs;
-		mp->arg = bt;
-	}
-	else
-		mp->alg = -1;
-}
-
-int
-m0(int a)
-{
-	switch(a) {
-	case -2:
-	case 2:
-		return 2;
-	case -3:
-	case 3:
-		return 2;
-	case -4:
-	case 4:
-		return 4;
-	case -5:
-	case 5:
-		return 4;
-	case 6:
-		return 2;
-	case -8:
-	case 8:
-		return 8;
-	case -9:
-	case 9:
-		return 8;
-	case 10:
-		return 4;
-	case 12:
-		return 2;
-	case 15:
-		return 2;
-	case 18:
-		return 8;
-	case 20:
-		return 4;
-	case 24:
-		return 2;
-	case 25:
-		return 4;
-	case 27:
-		return 2;
-	case 36:
-		return 8;
-	case 40:
-		return 4;
-	case 45:
-		return 4;
-	case 72:
-		return 8;
-	case 81:
-		return 8;
-	}
-	diag(Z, "bad m0");
-	return 0;
-}
-
-int
-m1(int a)
-{
-	switch(a) {
-	case 15:
-		return 4;
-	case 25:
-		return 4;
-	case 27:
-		return 8;
-	case 45:
-		return 8;
-	case 81:
-		return 8;
-	}
-	diag(Z, "bad m1");
-	return 0;
-}
-
-int
-m2(int a)
-{
-	switch(a) {
-	case 6:
-		return 2;
-	case 10:
-		return 2;
-	case 12:
-		return 4;
-	case 18:
-		return 2;
-	case 20:
-		return 4;
-	case 24:
-		return 8;
-	case 36:
-		return 4;
-	case 40:
-		return 8;
-	case 72:
-		return 8;
-	}
-	diag(Z, "bad m2");
-	return 0;
-}
-
-void
-shiftit(Type *t, Node *s, Node *d)
-{
-	int32_t c;
-
-	c = (int32_t)s->vconst & 31;
-	switch(c) {
-	case 0:
-		break;
-	case 1:
-		gopcode(OADD, t, d, d);
-		break;
-	default:
-		gopcode(OASHL, t, s, d);
-	}
-}
-
-static int
-mulgen1(uint32_t v, Node *n)
-{
-	int i, o;
-	Mparam *p;
-	Node nod, nods;
-
-	for(i = 0; i < nelem(multab); i++) {
-		p = &multab[i];
-		if(p->value == v)
-			goto found;
-	}
-
-	p = &multab[mulptr];
-	if(++mulptr == nelem(multab))
-		mulptr = 0;
-
-	mulparam(v, p);
-
-found:
-//	print("v=%.lx a=%d n=%d s=%d g=%d o=%d \n", p->value, p->alg, p->neg, p->shift, p->arg, p->off);
-	if(p->alg < 0)
-		return 0;
-
-	nods = *nodconst(p->shift);
-
-	o = OADD;
-	if(p->alg > 0) {
-		regalloc(&nod, n, Z);
-		if(p->off < 0)
-			o = OSUB;
-	}
-
-	switch(p->alg) {
-	case 0:
-		switch(p->arg) {
-		case 1:
-			shiftit(n->type, &nods, n);
-			break;
-		case 15:
-		case 25:
-		case 27:
-		case 45:
-		case 81:
-			genmuladd(n, n, m1(p->arg), n);
-			/* fall thru */
-		case 3:
-		case 5:
-		case 9:
-			genmuladd(n, n, m0(p->arg), n);
-			shiftit(n->type, &nods, n);
-			break;
-		default:
-			goto bad;
-		}
-		if(p->neg == 1)
-			gins(ANEGL, Z, n);
-		break;
-	case 1:
-		switch(p->arg) {
-		case 1:
-			gmove(n, &nod);
-			shiftit(n->type, &nods, &nod);
-			break;
-		case 3:
-		case 5:
-		case 9:
-			genmuladd(&nod, n, m0(p->arg), n);
-			shiftit(n->type, &nods, &nod);
-			break;
-		default:
-			goto bad;
-		}
-		if(p->neg)
-			gopcode(o, n->type, &nod, n);
-		else {
-			gopcode(o, n->type, n, &nod);
-			gmove(&nod, n);
-		}
-		break;
-	case 2:
-		genmuladd(&nod, n, m0(p->off), n);
-		shiftit(n->type, &nods, n);
-		goto comop;
-	case 3:
-		genmuladd(&nod, n, m0(p->off), n);
-		shiftit(n->type, &nods, n);
-		genmuladd(n, &nod, m2(p->off), n);
-		break;
-	case 4:
-		genmuladd(&nod, n, m0(p->off), nodconst(0));
-		shiftit(n->type, &nods, n);
-		goto comop;
-	default:
-		diag(Z, "bad mul alg");
-		break;
-	comop:
-		if(p->neg) {
-			gopcode(o, n->type, n, &nod);
-			gmove(&nod, n);
-		}
-		else
-			gopcode(o, n->type, &nod, n);
-	}
-
-	if(p->alg > 0)
-		regfree(&nod);
-
-	return 1;
-
-bad:
-	diag(Z, "mulgen botch");
-	return 1;
-}
-
-void
-mulgen(Type *t, Node *r, Node *n)
-{
-	if(!mulgen1(r->vconst, n))
-		gopcode(OMUL, t, r, n);
-}

+ 0 - 855
sys/src/cmd/6c/peep.c

@@ -1,855 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "gc.h"
-
-static int
-needc(Prog *p)
-{
-	while(p != P) {
-		switch(p->as) {
-		case AADCL:
-		case AADCQ:
-		case ASBBL:
-		case ASBBQ:
-		case ARCRL:
-		case ARCRQ:
-			return 1;
-		case AADDL:
-		case AADDQ:
-		case ASUBL:
-		case ASUBQ:
-		case AJMP:
-		case ARET:
-		case ACALL:
-			return 0;
-		default:
-			if(p->to.type == D_BRANCH)
-				return 0;
-		}
-		p = p->link;
-	}
-	return 0;
-}
-
-static Reg*
-rnops(Reg *r)
-{
-	Prog *p;
-	Reg *r1;
-
-	if(r != R)
-	for(;;){
-		p = r->prog;
-		if(p->as != ANOP || p->from.type != D_NONE || p->to.type != D_NONE)
-			break;
-		r1 = uniqs(r);
-		if(r1 == R)
-			break;
-		r = r1;
-	}
-	return r;
-}
-
-void
-peep(void)
-{
-	Reg *r, *r1, *r2;
-	Prog *p, *p1;
-	int t;
-
-	/*
-	 * complete R structure
-	 */
-	t = 0;
-	for(r=firstr; r!=R; r=r1) {
-		r1 = r->link;
-		if(r1 == R)
-			break;
-		p = r->prog->link;
-		while(p != r1->prog)
-		switch(p->as) {
-		default:
-			r2 = rega();
-			r->link = r2;
-			r2->link = r1;
-
-			r2->prog = p;
-			r2->p1 = r;
-			r->s1 = r2;
-			r2->s1 = r1;
-			r1->p1 = r2;
-
-			r = r2;
-			t++;
-
-		case ADATA:
-		case AGLOBL:
-		case ANAME:
-		case ASIGNAME:
-			p = p->link;
-		}
-	}
-
-	pc = 0;	/* speculating it won't kill */
-
-loop1:
-
-	t = 0;
-	for(r=firstr; r!=R; r=r->link) {
-		p = r->prog;
-		switch(p->as) {
-		case AMOVL:
-		case AMOVQ:
-		case AMOVSS:
-		case AMOVSD:
-			if(regtyp(&p->to))
-			if(regtyp(&p->from)) {
-				if(copyprop(r)) {
-					excise(r);
-					t++;
-				} else
-				if(subprop(r) && copyprop(r)) {
-					excise(r);
-					t++;
-				}
-			}
-			break;
-
-		case AMOVBLZX:
-		case AMOVWLZX:
-		case AMOVBLSX:
-		case AMOVWLSX:
-			if(regtyp(&p->to)) {
-				r1 = rnops(uniqs(r));
-				if(r1 != R) {
-					p1 = r1->prog;
-					if(p->as == p1->as && p->to.type == p1->from.type){
-						p1->as = AMOVL;
-						t++;
-					}
-				}
-			}
-			break;
-
-		case AMOVBQSX:
-		case AMOVBQZX:
-		case AMOVWQSX:
-		case AMOVWQZX:
-		case AMOVLQSX:
-		case AMOVLQZX:
-			if(regtyp(&p->to)) {
-				r1 = rnops(uniqs(r));
-				if(r1 != R) {
-					p1 = r1->prog;
-					if(p->as == p1->as && p->to.type == p1->from.type){
-						p1->as = AMOVQ;
-						t++;
-					}
-				}
-			}
-			break;
-
-		case AADDL:
-		case AADDQ:
-		case AADDW:
-			if(p->from.type != D_CONST || needc(p->link))
-				break;
-			if(p->from.offset == -1){
-				if(p->as == AADDQ)
-					p->as = ADECQ;
-				else if(p->as == AADDL)
-					p->as = ADECL;
-				else
-					p->as = ADECW;
-				p->from = zprog.from;
-			}
-			else if(p->from.offset == 1){
-				if(p->as == AADDQ)
-					p->as = AINCQ;
-				else if(p->as == AADDL)
-					p->as = AINCL;
-				else
-					p->as = AINCW;
-				p->from = zprog.from;
-			}
-			break;
-
-		case ASUBL:
-		case ASUBQ:
-		case ASUBW:
-			if(p->from.type != D_CONST || needc(p->link))
-				break;
-			if(p->from.offset == -1) {
-				if(p->as == ASUBQ)
-					p->as = AINCQ;
-				else if(p->as == ASUBL)
-					p->as = AINCL;
-				else
-					p->as = AINCW;
-				p->from = zprog.from;
-			}
-			else if(p->from.offset == 1){
-				if(p->as == ASUBQ)
-					p->as = ADECQ;
-				else if(p->as == ASUBL)
-					p->as = ADECL;
-				else
-					p->as = ADECW;
-				p->from = zprog.from;
-			}
-			break;
-		}
-	}
-	if(t)
-		goto loop1;
-}
-
-void
-excise(Reg *r)
-{
-	Prog *p;
-
-	p = r->prog;
-	p->as = ANOP;
-	p->from = zprog.from;
-	p->to = zprog.to;
-}
-
-Reg*
-uniqp(Reg *r)
-{
-	Reg *r1;
-
-	r1 = r->p1;
-	if(r1 == R) {
-		r1 = r->p2;
-		if(r1 == R || r1->p2link != R)
-			return R;
-	} else
-		if(r->p2 != R)
-			return R;
-	return r1;
-}
-
-Reg*
-uniqs(Reg *r)
-{
-	Reg *r1;
-
-	r1 = r->s1;
-	if(r1 == R) {
-		r1 = r->s2;
-		if(r1 == R)
-			return R;
-	} else
-		if(r->s2 != R)
-			return R;
-	return r1;
-}
-
-int
-regtyp(Adr *a)
-{
-	int t;
-
-	t = a->type;
-	if(t >= D_AX && t <= D_R15)
-		return 1;
-	if(t >= D_X0 && t <= D_X0+15)
-		return 1;
-	return 0;
-}
-
-/*
- * the idea is to substitute
- * one register for another
- * from one MOV to another
- *	MOV	a, R0
- *	ADD	b, R0	/ no use of R1
- *	MOV	R0, R1
- * would be converted to
- *	MOV	a, R1
- *	ADD	b, R1
- *	MOV	R1, R0
- * hopefully, then the former or latter MOV
- * will be eliminated by copy propagation.
- */
-int
-subprop(Reg *r0)
-{
-	Prog *p;
-	Adr *v1, *v2;
-	Reg *r;
-	int t;
-
-	p = r0->prog;
-	v1 = &p->from;
-	if(!regtyp(v1))
-		return 0;
-	v2 = &p->to;
-	if(!regtyp(v2))
-		return 0;
-	for(r=uniqp(r0); r!=R; r=uniqp(r)) {
-		if(uniqs(r) == R)
-			break;
-		p = r->prog;
-		switch(p->as) {
-		case ACALL:
-			return 0;
-
-		case AIMULL:
-		case AIMULQ:
-		case AIMULW:
-			if(p->to.type != D_NONE)
-				break;
-
-		case ADIVB:
-		case ADIVL:
-		case ADIVQ:
-		case ADIVW:
-		case AIDIVB:
-		case AIDIVL:
-		case AIDIVQ:
-		case AIDIVW:
-		case AIMULB:
-		case AMULB:
-		case AMULL:
-		case AMULQ:
-		case AMULW:
-
-		case AROLB:
-		case AROLL:
-		case AROLQ:
-		case AROLW:
-		case ARORB:
-		case ARORL:
-		case ARORQ:
-		case ARORW:
-		case ASALB:
-		case ASALL:
-		case ASALQ:
-		case ASALW:
-		case ASARB:
-		case ASARL:
-		case ASARQ:
-		case ASARW:
-		case ASHLB:
-		case ASHLL:
-		case ASHLQ:
-		case ASHLW:
-		case ASHRB:
-		case ASHRL:
-		case ASHRQ:
-		case ASHRW:
-
-		case AREP:
-		case AREPN:
-
-		case ACWD:
-		case ACDQ:
-		case ACQO:
-
-		case AMOVSL:
-		case AMOVSQ:
-			return 0;
-
-		case AMOVL:
-		case AMOVQ:
-			if(p->to.type == v1->type)
-				goto gotit;
-			break;
-		}
-		if(copyau(&p->from, v2) ||
-		   copyau(&p->to, v2))
-			break;
-		if(copysub(&p->from, v1, v2, 0) ||
-		   copysub(&p->to, v1, v2, 0))
-			break;
-	}
-	return 0;
-
-gotit:
-	copysub(&p->to, v1, v2, 1);
-	if(debug['P']) {
-		print("gotit: %D->%D\n%P", v1, v2, r->prog);
-		if(p->from.type == v2->type)
-			print(" excise");
-		print("\n");
-	}
-	for(r=uniqs(r); r!=r0; r=uniqs(r)) {
-		p = r->prog;
-		copysub(&p->from, v1, v2, 1);
-		copysub(&p->to, v1, v2, 1);
-		if(debug['P'])
-			print("%P\n", r->prog);
-	}
-	t = v1->type;
-	v1->type = v2->type;
-	v2->type = t;
-	if(debug['P'])
-		print("%P last\n", r->prog);
-	return 1;
-}
-
-/*
- * The idea is to remove redundant copies.
- *	v1->v2	F=0
- *	(use v2	s/v2/v1/)*
- *	set v1	F=1
- *	use v2	return fail
- *	-----------------
- *	v1->v2	F=0
- *	(use v2	s/v2/v1/)*
- *	set v1	F=1
- *	set v2	return success
- */
-int
-copyprop(Reg *r0)
-{
-	Prog *p;
-	Adr *v1, *v2;
-	Reg *r;
-
-	p = r0->prog;
-	v1 = &p->from;
-	v2 = &p->to;
-	if(copyas(v1, v2))
-		return 1;
-	for(r=firstr; r!=R; r=r->link)
-		r->active = 0;
-	return copy1(v1, v2, r0->s1, 0);
-}
-
-int
-copy1(Adr *v1, Adr *v2, Reg *r, int f)
-{
-	int t;
-	Prog *p;
-
-	if(r->active) {
-		if(debug['P'])
-			print("act set; return 1\n");
-		return 1;
-	}
-	r->active = 1;
-	if(debug['P'])
-		print("copy %D->%D f=%d\n", v1, v2, f);
-	for(; r != R; r = r->s1) {
-		p = r->prog;
-		if(debug['P'])
-			print("%P", p);
-		if(!f && uniqp(r) == R) {
-			f = 1;
-			if(debug['P'])
-				print("; merge; f=%d", f);
-		}
-		t = copyu(p, v2, A);
-		switch(t) {
-		case 2:	/* rar, cant split */
-			if(debug['P'])
-				print("; %D rar; return 0\n", v2);
-			return 0;
-
-		case 3:	/* set */
-			if(debug['P'])
-				print("; %D set; return 1\n", v2);
-			return 1;
-
-		case 1:	/* used, substitute */
-		case 4:	/* use and set */
-			if(f) {
-				if(!debug['P'])
-					return 0;
-				if(t == 4)
-					print("; %D used+set and f=%d; return 0\n", v2, f);
-				else
-					print("; %D used and f=%d; return 0\n", v2, f);
-				return 0;
-			}
-			if(copyu(p, v2, v1)) {
-				if(debug['P'])
-					print("; sub fail; return 0\n");
-				return 0;
-			}
-			if(debug['P'])
-				print("; sub %D/%D", v2, v1);
-			if(t == 4) {
-				if(debug['P'])
-					print("; %D used+set; return 1\n", v2);
-				return 1;
-			}
-			break;
-		}
-		if(!f) {
-			t = copyu(p, v1, A);
-			if(!f && (t == 2 || t == 3 || t == 4)) {
-				f = 1;
-				if(debug['P'])
-					print("; %D set and !f; f=%d", v1, f);
-			}
-		}
-		if(debug['P'])
-			print("\n");
-		if(r->s2)
-			if(!copy1(v1, v2, r->s2, f))
-				return 0;
-	}
-	return 1;
-}
-
-/*
- * return
- * 1 if v only used (and substitute),
- * 2 if read-alter-rewrite
- * 3 if set
- * 4 if set and used
- * 0 otherwise (not touched)
- */
-int
-copyu(Prog *p, Adr *v, Adr *s)
-{
-
-	switch(p->as) {
-
-	default:
-		if(debug['P'])
-			print("unknown op %A\n", p->as);
-		/* SBBL; ADCL; FLD1; SAHF */
-		return 2;
-
-
-	case ANEGB:
-	case ANEGW:
-	case ANEGL:
-	case ANEGQ:
-	case ANOTB:
-	case ANOTW:
-	case ANOTL:
-	case ANOTQ:
-		if(copyas(&p->to, v))
-			return 2;
-		break;
-
-	case ALEAL:	/* lhs addr, rhs store */
-	case ALEAQ:
-		if(copyas(&p->from, v))
-			return 2;
-
-
-	case ANOP:	/* rhs store */
-	case AMOVL:
-	case AMOVQ:
-	case AMOVBLSX:
-	case AMOVBLZX:
-	case AMOVBQSX:
-	case AMOVBQZX:
-	case AMOVLQSX:
-	case AMOVLQZX:
-	case AMOVWLSX:
-	case AMOVWLZX:
-	case AMOVWQSX:
-	case AMOVWQZX:
-
-	case AMOVSS:
-	case AMOVSD:
-	case ACVTSD2SL:
-	case ACVTSD2SQ:
-	case ACVTSD2SS:
-	case ACVTSL2SD:
-	case ACVTSL2SS:
-	case ACVTSQ2SD:
-	case ACVTSQ2SS:
-	case ACVTSS2SD:
-	case ACVTSS2SL:
-	case ACVTSS2SQ:
-	case ACVTTSD2SL:
-	case ACVTTSD2SQ:
-	case ACVTTSS2SL:
-	case ACVTTSS2SQ:
-		if(copyas(&p->to, v)) {
-			if(s != A)
-				return copysub(&p->from, v, s, 1);
-			if(copyau(&p->from, v))
-				return 4;
-			return 3;
-		}
-		goto caseread;
-
-	case AROLB:
-	case AROLL:
-	case AROLQ:
-	case AROLW:
-	case ARORB:
-	case ARORL:
-	case ARORQ:
-	case ARORW:
-	case ASALB:
-	case ASALL:
-	case ASALQ:
-	case ASALW:
-	case ASARB:
-	case ASARL:
-	case ASARQ:
-	case ASARW:
-	case ASHLB:
-	case ASHLL:
-	case ASHLQ:
-	case ASHLW:
-	case ASHRB:
-	case ASHRL:
-	case ASHRQ:
-	case ASHRW:
-		if(copyas(&p->to, v))
-			return 2;
-		if(copyas(&p->from, v))
-			if(p->from.type == D_CX)
-				return 2;
-		goto caseread;
-
-	case AADDB:	/* rhs rar */
-	case AADDL:
-	case AADDQ:
-	case AADDW:
-	case AANDB:
-	case AANDL:
-	case AANDQ:
-	case AANDW:
-	case ADECL:
-	case ADECQ:
-	case ADECW:
-	case AINCL:
-	case AINCQ:
-	case AINCW:
-	case ASUBB:
-	case ASUBL:
-	case ASUBQ:
-	case ASUBW:
-	case AORB:
-	case AORL:
-	case AORQ:
-	case AORW:
-	case AXORB:
-	case AXORL:
-	case AXORQ:
-	case AXORW:
-	case AMOVB:
-	case AMOVW:
-
-	case AADDSD:
-	case AADDSS:
-	case ACMPSD:
-	case ACMPSS:
-	case ADIVSD:
-	case ADIVSS:
-	case AMAXSD:
-	case AMAXSS:
-	case AMINSD:
-	case AMINSS:
-	case AMULSD:
-	case AMULSS:
-	case ARCPSS:
-	case ARSQRTSS:
-	case ASQRTSD:
-	case ASQRTSS:
-	case ASUBSD:
-	case ASUBSS:
-	case AXORPD:
-		if(copyas(&p->to, v))
-			return 2;
-		goto caseread;
-
-	case ACMPL:	/* read only */
-	case ACMPW:
-	case ACMPB:
-	case ACMPQ:
-
-	case ACOMISD:
-	case ACOMISS:
-	case AUCOMISD:
-	case AUCOMISS:
-	caseread:
-		if(s != A) {
-			if(copysub(&p->from, v, s, 1))
-				return 1;
-			return copysub(&p->to, v, s, 1);
-		}
-		if(copyau(&p->from, v))
-			return 1;
-		if(copyau(&p->to, v))
-			return 1;
-		break;
-
-	case AJGE:	/* no reference */
-	case AJNE:
-	case AJLE:
-	case AJEQ:
-	case AJHI:
-	case AJLS:
-	case AJMI:
-	case AJPL:
-	case AJGT:
-	case AJLT:
-	case AJCC:
-	case AJCS:
-
-	case AADJSP:
-	case AWAIT:
-	case ACLD:
-		break;
-
-	case AIMULL:
-	case AIMULQ:
-	case AIMULW:
-		if(p->to.type != D_NONE) {
-			if(copyas(&p->to, v))
-				return 2;
-			goto caseread;
-		}
-
-	case ADIVB:
-	case ADIVL:
-	case ADIVQ:
-	case ADIVW:
-	case AIDIVB:
-	case AIDIVL:
-	case AIDIVQ:
-	case AIDIVW:
-	case AIMULB:
-	case AMULB:
-	case AMULL:
-	case AMULQ:
-	case AMULW:
-
-	case ACWD:
-	case ACDQ:
-	case ACQO:
-		if(v->type == D_AX || v->type == D_DX)
-			return 2;
-		goto caseread;
-
-	case AMOVSL:
-	case AMOVSQ:
-	case AREP:
-	case AREPN:
-		if(v->type == D_CX || v->type == D_DI || v->type == D_SI)
-			return 2;
-		goto caseread;
-
-	case AJMP:	/* funny */
-		if(s != A) {
-			if(copysub(&p->to, v, s, 1))
-				return 1;
-			return 0;
-		}
-		if(copyau(&p->to, v))
-			return 1;
-		return 0;
-
-	case ARET:	/* funny */
-		if(v->type == REGRET || v->type == FREGRET)
-			return 2;
-		if(s != A)
-			return 1;
-		return 3;
-
-	case ACALL:	/* funny */
-		if(REGEXT && v->type <= REGEXT && v->type > exregoffset)
-			return 2;
-		if(REGARG && v->type == REGARG)
-			return 2;
-
-		if(s != A) {
-			if(copysub(&p->to, v, s, 1))
-				return 1;
-			return 0;
-		}
-		if(copyau(&p->to, v))
-			return 4;
-		return 3;
-
-	case ATEXT:	/* funny */
-		if(REGARG && v->type == REGARG)
-			return 3;
-		return 0;
-	}
-	return 0;
-}
-
-/*
- * direct reference,
- * could be set/use depending on
- * semantics
- */
-int
-copyas(Adr *a, Adr *v)
-{
-	if(a->type != v->type)
-		return 0;
-	if(regtyp(v))
-		return 1;
-	if(v->type == D_AUTO || v->type == D_PARAM)
-		if(v->offset == a->offset)
-			return 1;
-	return 0;
-}
-
-/*
- * either direct or indirect
- */
-int
-copyau(Adr *a, Adr *v)
-{
-
-	if(copyas(a, v))
-		return 1;
-	if(regtyp(v)) {
-		if(a->type-D_INDIR == v->type)
-			return 1;
-		if(a->index == v->type)
-			return 1;
-	}
-	return 0;
-}
-
-/*
- * substitute s for v in a
- * return failure to substitute
- */
-int
-copysub(Adr *a, Adr *v, Adr *s, int f)
-{
-	int t;
-
-	if(copyas(a, v)) {
-		t = s->type;
-		if(t >= D_AX && t <= D_R15 || t >= D_X0 && t <= D_X0+15) {
-			if(f)
-				a->type = t;
-		}
-		return 0;
-	}
-	if(regtyp(v)) {
-		t = v->type;
-		if(a->type == t+D_INDIR) {
-			if((s->type == D_BP || s->type == D_R13) && a->index != D_NONE)
-				return 1;	/* can't use BP-base with index */
-			if(f)
-				a->type = s->type+D_INDIR;
-//			return 0;
-		}
-		if(a->index == t) {
-			if(f)
-				a->index = s->type;
-			return 0;
-		}
-		return 0;
-	}
-	return 0;
-}

+ 0 - 1367
sys/src/cmd/6c/reg.c

@@ -1,1367 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "gc.h"
-
-Reg*
-rega(void)
-{
-	Reg *r;
-
-	r = freer;
-	if(r == R) {
-		r = alloc(sizeof(*r));
-	} else
-		freer = r->link;
-
-	*r = zreg;
-	return r;
-}
-
-int
-rcmp(const void *a1, const void *a2)
-{
-	Rgn *p1, *p2;
-	int c1, c2;
-
-	p1 = (Rgn*)a1;
-	p2 = (Rgn*)a2;
-	c1 = p2->cost;
-	c2 = p1->cost;
-	if(c1 -= c2)
-		return c1;
-	return p2->varno - p1->varno;
-}
-
-void
-regopt(Prog *p)
-{
-	Reg *r, *r1, *r2;
-	Prog *p1;
-	int i, z;
-	int32_t initpc, val, npc;
-	uint32_t vreg;
-	Bits bit;
-	struct
-	{
-		int32_t	m;
-		int32_t	c;
-		Reg*	p;
-	} log5[6], *lp;
-
-	firstr = R;
-	lastr = R;
-	nvar = 0;
-	regbits = RtoB(D_SP) | RtoB(D_AX) | RtoB(D_X0);
-	if(REGEXT)
-		regbits |= RtoB(REGEXT) | RtoB(REGEXT-1);
-	for(z=0; z<BITS; z++) {
-		externs.b[z] = 0;
-		params.b[z] = 0;
-		consts.b[z] = 0;
-		addrs.b[z] = 0;
-	}
-
-	/*
-	 * pass 1
-	 * build aux data structure
-	 * allocate pcs
-	 * find use and set of variables
-	 */
-	val = 5L * 5L * 5L * 5L * 5L;
-	lp = log5;
-	for(i=0; i<5; i++) {
-		lp->m = val;
-		lp->c = 0;
-		lp->p = R;
-		val /= 5L;
-		lp++;
-	}
-	val = 0;
-	for(; p != P; p = p->link) {
-		switch(p->as) {
-		case ADATA:
-		case AGLOBL:
-		case ANAME:
-		case ASIGNAME:
-			continue;
-		}
-		r = rega();
-		if(firstr == R) {
-			firstr = r;
-			lastr = r;
-		} else {
-			lastr->link = r;
-			r->p1 = lastr;
-			lastr->s1 = r;
-			lastr = r;
-		}
-		r->prog = p;
-		r->pc = val;
-		val++;
-
-		lp = log5;
-		for(i=0; i<5; i++) {
-			lp->c--;
-			if(lp->c <= 0) {
-				lp->c = lp->m;
-				if(lp->p != R)
-					lp->p->log5 = r;
-				lp->p = r;
-				(lp+1)->c = 0;
-				break;
-			}
-			lp++;
-		}
-
-		r1 = r->p1;
-		if(r1 != R)
-		switch(r1->prog->as) {
-		case ARET:
-		case AJMP:
-		case AIRETL:
-		case AIRETQ:
-			r->p1 = R;
-			r1->s1 = R;
-		}
-
-		bit = mkvar(r, &p->from);
-		if(bany(&bit))
-		switch(p->as) {
-		/*
-		 * funny
-		 */
-		case ALEAL:
-		case ALEAQ:
-			for(z=0; z<BITS; z++)
-				addrs.b[z] |= bit.b[z];
-			break;
-
-		/*
-		 * left side read
-		 */
-		default:
-			for(z=0; z<BITS; z++)
-				r->use1.b[z] |= bit.b[z];
-			break;
-		}
-
-		bit = mkvar(r, &p->to);
-		if(bany(&bit))
-		switch(p->as) {
-		default:
-			diag(Z, "reg: unknown op: %A", p->as);
-			break;
-
-		/*
-		 * right side read
-		 */
-		case ACMPB:
-		case ACMPL:
-		case ACMPQ:
-		case ACMPW:
-		case ACOMISS:
-		case ACOMISD:
-		case AUCOMISS:
-		case AUCOMISD:
-			for(z=0; z<BITS; z++)
-				r->use2.b[z] |= bit.b[z];
-			break;
-
-		/*
-		 * right side write
-		 */
-		case ANOP:
-		case AMOVL:
-		case AMOVQ:
-		case AMOVB:
-		case AMOVW:
-		case AMOVBLSX:
-		case AMOVBLZX:
-		case AMOVBQSX:
-		case AMOVBQZX:
-		case AMOVLQSX:
-		case AMOVLQZX:
-		case AMOVWLSX:
-		case AMOVWLZX:
-		case AMOVWQSX:
-		case AMOVWQZX:
-
-		case AMOVSS:
-		case AMOVSD:
-		case ACVTSD2SL:
-		case ACVTSD2SQ:
-		case ACVTSD2SS:
-		case ACVTSL2SD:
-		case ACVTSL2SS:
-		case ACVTSQ2SD:
-		case ACVTSQ2SS:
-		case ACVTSS2SD:
-		case ACVTSS2SL:
-		case ACVTSS2SQ:
-		case ACVTTSD2SL:
-		case ACVTTSD2SQ:
-		case ACVTTSS2SL:
-		case ACVTTSS2SQ:
-			for(z=0; z<BITS; z++)
-				r->set.b[z] |= bit.b[z];
-			break;
-
-		/*
-		 * right side read+write
-		 */
-		case AADDB:
-		case AADDL:
-		case AADDQ:
-		case AADDW:
-		case AANDB:
-		case AANDL:
-		case AANDQ:
-		case AANDW:
-		case ASUBB:
-		case ASUBL:
-		case ASUBQ:
-		case ASUBW:
-		case AORB:
-		case AORL:
-		case AORQ:
-		case AORW:
-		case AXORB:
-		case AXORL:
-		case AXORQ:
-		case AXORW:
-		case ASALB:
-		case ASALL:
-		case ASALQ:
-		case ASALW:
-		case ASARB:
-		case ASARL:
-		case ASARQ:
-		case ASARW:
-		case AROLB:
-		case AROLL:
-		case AROLQ:
-		case AROLW:
-		case ARORB:
-		case ARORL:
-		case ARORQ:
-		case ARORW:
-		case ASHLB:
-		case ASHLL:
-		case ASHLQ:
-		case ASHLW:
-		case ASHRB:
-		case ASHRL:
-		case ASHRQ:
-		case ASHRW:
-		case AIMULL:
-		case AIMULQ:
-		case AIMULW:
-		case ANEGL:
-		case ANEGQ:
-		case ANOTL:
-		case ANOTQ:
-		case AADCL:
-		case AADCQ:
-		case ASBBL:
-		case ASBBQ:
-
-		case AADDSD:
-		case AADDSS:
-		case ACMPSD:
-		case ACMPSS:
-		case ADIVSD:
-		case ADIVSS:
-		case AMAXSD:
-		case AMAXSS:
-		case AMINSD:
-		case AMINSS:
-		case AMULSD:
-		case AMULSS:
-		case ARCPSS:
-		case ARSQRTSS:
-		case ASQRTSD:
-		case ASQRTSS:
-		case ASUBSD:
-		case ASUBSS:
-		case AXORPD:
-			for(z=0; z<BITS; z++) {
-				r->set.b[z] |= bit.b[z];
-				r->use2.b[z] |= bit.b[z];
-			}
-			break;
-
-		/*
-		 * funny
-		 */
-		case ACALL:
-			for(z=0; z<BITS; z++)
-				addrs.b[z] |= bit.b[z];
-			break;
-		}
-
-		switch(p->as) {
-		case AIMULL:
-		case AIMULQ:
-		case AIMULW:
-			if(p->to.type != D_NONE)
-				break;
-
-		case AIDIVB:
-		case AIDIVL:
-		case AIDIVQ:
-		case AIDIVW:
-		case AIMULB:
-		case ADIVB:
-		case ADIVL:
-		case ADIVQ:
-		case ADIVW:
-		case AMULB:
-		case AMULL:
-		case AMULQ:
-		case AMULW:
-
-		case ACWD:
-		case ACDQ:
-		case ACQO:
-			r->regu |= RtoB(D_AX) | RtoB(D_DX);
-			break;
-
-		case AREP:
-		case AREPN:
-		case ALOOP:
-		case ALOOPEQ:
-		case ALOOPNE:
-			r->regu |= RtoB(D_CX);
-			break;
-
-		case AMOVSB:
-		case AMOVSL:
-		case AMOVSQ:
-		case AMOVSW:
-		case ACMPSB:
-		case ACMPSL:
-		case ACMPSQ:
-		case ACMPSW:
-			r->regu |= RtoB(D_SI) | RtoB(D_DI);
-			break;
-
-		case ASTOSB:
-		case ASTOSL:
-		case ASTOSQ:
-		case ASTOSW:
-		case ASCASB:
-		case ASCASL:
-		case ASCASQ:
-		case ASCASW:
-			r->regu |= RtoB(D_AX) | RtoB(D_DI);
-			break;
-
-		case AINSB:
-		case AINSL:
-		case AINSW:
-		case AOUTSB:
-		case AOUTSL:
-		case AOUTSW:
-			r->regu |= RtoB(D_DI) | RtoB(D_DX);
-			break;
-		}
-	}
-	if(firstr == R)
-		return;
-	initpc = pc - val;
-	npc = val;
-
-	/*
-	 * pass 2
-	 * turn branch references to pointers
-	 * build back pointers
-	 */
-	for(r = firstr; r != R; r = r->link) {
-		p = r->prog;
-		if(p->to.type == D_BRANCH) {
-			val = p->to.offset - initpc;
-			r1 = firstr;
-			while(r1 != R) {
-				r2 = r1->log5;
-				if(r2 != R && val >= r2->pc) {
-					r1 = r2;
-					continue;
-				}
-				if(r1->pc == val)
-					break;
-				r1 = r1->link;
-			}
-			if(r1 == R) {
-				nearln = p->lineno;
-				diag(Z, "ref not found\n%P", p);
-				continue;
-			}
-			if(r1 == r) {
-				nearln = p->lineno;
-				diag(Z, "ref to self\n%P", p);
-				continue;
-			}
-			r->s2 = r1;
-			r->p2link = r1->p2;
-			r1->p2 = r;
-		}
-	}
-	if(debug['R']) {
-		p = firstr->prog;
-		print("\n%L %D\n", p->lineno, &p->from);
-	}
-
-	/*
-	 * pass 2.5
-	 * find looping structure
-	 */
-	for(r = firstr; r != R; r = r->link)
-		r->active = 0;
-	change = 0;
-	loopit(firstr, npc);
-	if(debug['R'] && debug['v']) {
-		print("\nlooping structure:\n");
-		for(r = firstr; r != R; r = r->link) {
-			print("%ld:%P", r->loop, r->prog);
-			for(z=0; z<BITS; z++)
-				bit.b[z] = r->use1.b[z] |
-					   r->use2.b[z] |
-					   r->set.b[z];
-			if(bany(&bit)) {
-				print("\t");
-				if(bany(&r->use1))
-					print(" u1=%B", r->use1);
-				if(bany(&r->use2))
-					print(" u2=%B", r->use2);
-				if(bany(&r->set))
-					print(" st=%B", r->set);
-			}
-			print("\n");
-		}
-	}
-
-	/*
-	 * pass 3
-	 * iterate propagating usage
-	 * 	back until flow graph is complete
-	 */
-loop1:
-	change = 0;
-	for(r = firstr; r != R; r = r->link)
-		r->active = 0;
-	for(r = firstr; r != R; r = r->link)
-		if(r->prog->as == ARET)
-			prop(r, zbits, zbits);
-loop11:
-	/* pick up unreachable code */
-	i = 0;
-	for(r = firstr; r != R; r = r1) {
-		r1 = r->link;
-		if(r1 && r1->active && !r->active) {
-			prop(r, zbits, zbits);
-			i = 1;
-		}
-	}
-	if(i)
-		goto loop11;
-	if(change)
-		goto loop1;
-
-
-	/*
-	 * pass 4
-	 * iterate propagating register/variable synchrony
-	 * 	forward until graph is complete
-	 */
-loop2:
-	change = 0;
-	for(r = firstr; r != R; r = r->link)
-		r->active = 0;
-	synch(firstr, zbits);
-	if(change)
-		goto loop2;
-
-
-	/*
-	 * pass 5
-	 * isolate regions
-	 * calculate costs (paint1)
-	 */
-	r = firstr;
-	if(r) {
-		for(z=0; z<BITS; z++)
-			bit.b[z] = (r->refahead.b[z] | r->calahead.b[z]) &
-			  ~(externs.b[z] | params.b[z] | addrs.b[z] | consts.b[z]);
-		if(bany(&bit)) {
-			nearln = r->prog->lineno;
-			warn(Z, "used and not set: %B", bit);
-			if(debug['R'] && !debug['w'])
-				print("used and not set: %B\n", bit);
-		}
-	}
-	if(debug['R'] && debug['v'])
-		print("\nprop structure:\n");
-	for(r = firstr; r != R; r = r->link)
-		r->act = zbits;
-	rgp = region;
-	nregion = 0;
-	for(r = firstr; r != R; r = r->link) {
-		if(debug['R'] && debug['v']) {
-			print("%P\t", r->prog);
-			if(bany(&r->set))
-				print("s:%B ", r->set);
-			if(bany(&r->refahead))
-				print("ra:%B ", r->refahead);
-			if(bany(&r->calahead))
-				print("ca:%B ", r->calahead);
-			print("\n");
-		}
-		for(z=0; z<BITS; z++)
-			bit.b[z] = r->set.b[z] &
-			  ~(r->refahead.b[z] | r->calahead.b[z] | addrs.b[z]);
-		if(bany(&bit)) {
-			nearln = r->prog->lineno;
-			warn(Z, "set and not used: %B", bit);
-			if(debug['R'])
-				print("set and not used: %B\n", bit);
-			excise(r);
-		}
-		for(z=0; z<BITS; z++)
-			bit.b[z] = LOAD(r) & ~(r->act.b[z] | addrs.b[z]);
-		while(bany(&bit)) {
-			i = bnum(bit);
-			rgp->enter = r;
-			rgp->varno = i;
-			change = 0;
-			if(debug['R'] && debug['v'])
-				print("\n");
-			paint1(r, i);
-			bit.b[i/32] &= ~(1L<<(i%32));
-			if(change <= 0) {
-				if(debug['R'])
-					print("%L$%d: %B\n",
-						r->prog->lineno, change, blsh(i));
-				continue;
-			}
-			rgp->cost = change;
-			nregion++;
-			if(nregion >= NRGN) {
-				warn(Z, "too many regions");
-				goto brk;
-			}
-			rgp++;
-		}
-	}
-brk:
-	qsort(region, nregion, sizeof(region[0]), rcmp);
-
-	/*
-	 * pass 6
-	 * determine used registers (paint2)
-	 * replace code (paint3)
-	 */
-	rgp = region;
-	for(i=0; i<nregion; i++) {
-		bit = blsh(rgp->varno);
-		vreg = paint2(rgp->enter, rgp->varno);
-		vreg = allreg(vreg, rgp);
-		if(debug['R']) {
-			print("%L$%d %R: %B\n",
-				rgp->enter->prog->lineno,
-				rgp->cost,
-				rgp->regno,
-				bit);
-		}
-		if(rgp->regno != 0)
-			paint3(rgp->enter, rgp->varno, vreg, rgp->regno);
-		rgp++;
-	}
-	/*
-	 * pass 7
-	 * peep-hole on basic block
-	 */
-	if(!debug['R'] || debug['P'])
-		peep();
-
-	/*
-	 * pass 8
-	 * recalculate pc
-	 */
-	val = initpc;
-	for(r = firstr; r != R; r = r1) {
-		r->pc = val;
-		p = r->prog;
-		p1 = P;
-		r1 = r->link;
-		if(r1 != R)
-			p1 = r1->prog;
-		for(; p != p1; p = p->link) {
-			switch(p->as) {
-			default:
-				val++;
-				break;
-
-			case ANOP:
-			case ADATA:
-			case AGLOBL:
-			case ANAME:
-			case ASIGNAME:
-				break;
-			}
-		}
-	}
-	pc = val;
-
-	/*
-	 * fix up branches
-	 */
-	if(debug['R'])
-		if(bany(&addrs))
-			print("addrs: %B\n", addrs);
-
-	r1 = 0; /* set */
-	for(r = firstr; r != R; r = r->link) {
-		p = r->prog;
-		if(p->to.type == D_BRANCH)
-			p->to.offset = r->s2->pc;
-		r1 = r;
-	}
-
-	/*
-	 * last pass
-	 * eliminate nops
-	 * free aux structures
-	 */
-	for(p = firstr->prog; p != P; p = p->link){
-		while(p->link && p->link->as == ANOP)
-			p->link = p->link->link;
-	}
-	if(r1 != R) {
-		r1->link = freer;
-		freer = firstr;
-	}
-}
-
-/*
- * add mov b,rn
- * just after r
- */
-void
-addmove(Reg *r, int bn, int rn, int f)
-{
-	Prog *p, *p1;
-	Adr *a;
-	Var *v;
-
-	p1 = alloc(sizeof(*p1));
-	*p1 = zprog;
-	p = r->prog;
-
-	p1->link = p->link;
-	p->link = p1;
-	p1->lineno = p->lineno;
-
-	v = var + bn;
-
-	a = &p1->to;
-	a->sym = v->sym;
-	a->offset = v->offset;
-	a->etype = v->etype;
-	a->type = v->name;
-
-	p1->as = AMOVL;
-	if(v->etype == TCHAR || v->etype == TUCHAR)
-		p1->as = AMOVB;
-	if(v->etype == TSHORT || v->etype == TUSHORT)
-		p1->as = AMOVW;
-	if(v->etype == TVLONG || v->etype == TUVLONG || v->etype == TIND)
-		p1->as = AMOVQ;
-	if(v->etype == TFLOAT)
-		p1->as = AMOVSS;
-	if(v->etype == TDOUBLE)
-		p1->as = AMOVSD;
-
-	p1->from.type = rn;
-	if(!f) {
-		p1->from = *a;
-		*a = zprog.from;
-		a->type = rn;
-		if(v->etype == TUCHAR)
-			p1->as = AMOVB;
-		if(v->etype == TUSHORT)
-			p1->as = AMOVW;
-	}
-	if(debug['R'])
-		print("%P\t.a%P\n", p, p1);
-}
-
-uint32_t
-doregbits(int r)
-{
-	uint32_t b;
-
-	b = 0;
-	if(r >= D_INDIR)
-		r -= D_INDIR;
-	if(r >= D_AX && r <= D_R15)
-		b |= RtoB(r);
-	else
-	if(r >= D_AL && r <= D_R15B)
-		b |= RtoB(r-D_AL+D_AX);
-	else
-	if(r >= D_AH && r <= D_BH)
-		b |= RtoB(r-D_AH+D_AX);
-	else
-	if(r >= D_X0 && r <= D_X0+15)
-		b |= FtoB(r);
-	return b;
-}
-
-Bits
-mkvar(Reg *r, Adr *a)
-{
-	Var *v;
-	int i, t, n, et, z;
-	int32_t o;
-	Bits bit;
-	Sym *s;
-
-	/*
-	 * mark registers used
-	 */
-	t = a->type;
-	r->regu |= doregbits(t);
-	r->regu |= doregbits(a->index);
-
-	switch(t) {
-	default:
-		goto none;
-	case D_ADDR:
-		a->type = a->index;
-		bit = mkvar(r, a);
-		for(z=0; z<BITS; z++)
-			addrs.b[z] |= bit.b[z];
-		a->type = t;
-		goto none;
-	case D_EXTERN:
-	case D_STATIC:
-	case D_PARAM:
-	case D_AUTO:
-		n = t;
-		break;
-	}
-	s = a->sym;
-	if(s == S)
-		goto none;
-	if(s->name[0] == '.')
-		goto none;
-	et = a->etype;
-	o = a->offset;
-	v = var;
-	for(i=0; i<nvar; i++) {
-		if(s == v->sym)
-		if(n == v->name)
-		if(o == v->offset)
-			goto out;
-		v++;
-	}
-	if(nvar >= NVAR) {
-		if(debug['w'] > 1 && s)
-			warn(Z, "variable not optimized: %s", s->name);
-		goto none;
-	}
-	i = nvar;
-	nvar++;
-	v = &var[i];
-	v->sym = s;
-	v->offset = o;
-	v->name = n;
-	v->etype = et;
-	if(debug['R'])
-		print("bit=%2d et=%2d %D\n", i, et, a);
-
-out:
-	bit = blsh(i);
-	if(n == D_EXTERN || n == D_STATIC)
-		for(z=0; z<BITS; z++)
-			externs.b[z] |= bit.b[z];
-	if(n == D_PARAM)
-		for(z=0; z<BITS; z++)
-			params.b[z] |= bit.b[z];
-	if(v->etype != et || !(typechlpfd[et] || typev[et]))	/* funny punning */
-		for(z=0; z<BITS; z++)
-			addrs.b[z] |= bit.b[z];
-	return bit;
-
-none:
-	return zbits;
-}
-
-void
-prop(Reg *r, Bits ref, Bits cal)
-{
-	Reg *r1, *r2;
-	int z;
-
-	for(r1 = r; r1 != R; r1 = r1->p1) {
-		for(z=0; z<BITS; z++) {
-			ref.b[z] |= r1->refahead.b[z];
-			if(ref.b[z] != r1->refahead.b[z]) {
-				r1->refahead.b[z] = ref.b[z];
-				change++;
-			}
-			cal.b[z] |= r1->calahead.b[z];
-			if(cal.b[z] != r1->calahead.b[z]) {
-				r1->calahead.b[z] = cal.b[z];
-				change++;
-			}
-		}
-		switch(r1->prog->as) {
-		case ACALL:
-			for(z=0; z<BITS; z++) {
-				cal.b[z] |= ref.b[z] | externs.b[z];
-				ref.b[z] = 0;
-			}
-			break;
-
-		case ATEXT:
-			for(z=0; z<BITS; z++) {
-				cal.b[z] = 0;
-				ref.b[z] = 0;
-			}
-			break;
-
-		case ARET:
-			for(z=0; z<BITS; z++) {
-				cal.b[z] = externs.b[z];
-				ref.b[z] = 0;
-			}
-		}
-		for(z=0; z<BITS; z++) {
-			ref.b[z] = (ref.b[z] & ~r1->set.b[z]) |
-				r1->use1.b[z] | r1->use2.b[z];
-			cal.b[z] &= ~(r1->set.b[z] | r1->use1.b[z] | r1->use2.b[z]);
-			r1->refbehind.b[z] = ref.b[z];
-			r1->calbehind.b[z] = cal.b[z];
-		}
-		if(r1->active)
-			break;
-		r1->active = 1;
-	}
-	for(; r != r1; r = r->p1)
-		for(r2 = r->p2; r2 != R; r2 = r2->p2link)
-			prop(r2, r->refbehind, r->calbehind);
-}
-
-/*
- * find looping structure
- *
- * 1) find reverse postordering
- * 2) find approximate dominators,
- *	the actual dominators if the flow graph is reducible
- *	otherwise, dominators plus some other non-dominators.
- *	See Matthew S. Hecht and Jeffrey D. Ullman,
- *	"Analysis of a Simple Algorithm for Global Data Flow Problems",
- *	Conf.  Record of ACM Symp. on Principles of Prog. Langs, Boston, Massachusetts,
- *	Oct. 1-3, 1973, pp.  207-217.
- * 3) find all nodes with a predecessor dominated by the current node.
- *	such a node is a loop head.
- *	recursively, all preds with a greater rpo number are in the loop
- */
-int32_t
-postorder(Reg *r, Reg **rpo2r, int32_t n)
-{
-	Reg *r1;
-
-	r->rpo = 1;
-	r1 = r->s1;
-	if(r1 && !r1->rpo)
-		n = postorder(r1, rpo2r, n);
-	r1 = r->s2;
-	if(r1 && !r1->rpo)
-		n = postorder(r1, rpo2r, n);
-	rpo2r[n] = r;
-	n++;
-	return n;
-}
-
-int32_t
-rpolca(int32_t *idom, int32_t rpo1, int32_t rpo2)
-{
-	int32_t t;
-
-	if(rpo1 == -1)
-		return rpo2;
-	while(rpo1 != rpo2){
-		if(rpo1 > rpo2){
-			t = rpo2;
-			rpo2 = rpo1;
-			rpo1 = t;
-		}
-		while(rpo1 < rpo2){
-			t = idom[rpo2];
-			if(t >= rpo2)
-				fatal(Z, "bad idom");
-			rpo2 = t;
-		}
-	}
-	return rpo1;
-}
-
-int
-doms(int32_t *idom, int32_t r, int32_t s)
-{
-	while(s > r)
-		s = idom[s];
-	return s == r;
-}
-
-int
-loophead(int32_t *idom, Reg *r)
-{
-	int32_t src;
-
-	src = r->rpo;
-	if(r->p1 != R && doms(idom, src, r->p1->rpo))
-		return 1;
-	for(r = r->p2; r != R; r = r->p2link)
-		if(doms(idom, src, r->rpo))
-			return 1;
-	return 0;
-}
-
-void
-loopmark(Reg **rpo2r, int32_t head, Reg *r)
-{
-	if(r->rpo < head || r->active == head)
-		return;
-	r->active = head;
-	r->loop += LOOP;
-	if(r->p1 != R)
-		loopmark(rpo2r, head, r->p1);
-	for(r = r->p2; r != R; r = r->p2link)
-		loopmark(rpo2r, head, r);
-}
-
-void
-loopit(Reg *r, int32_t nr)
-{
-	Reg *r1;
-	int32_t i, d, me;
-
-	if(nr > maxnr) {
-		rpo2r = alloc(nr * sizeof(Reg*));
-		idom = alloc(nr * sizeof(int32_t));
-		maxnr = nr;
-	}
-
-	d = postorder(r, rpo2r, 0);
-	if(d > nr)
-		fatal(Z, "too many reg nodes");
-	nr = d;
-	for(i = 0; i < nr / 2; i++){
-		r1 = rpo2r[i];
-		rpo2r[i] = rpo2r[nr - 1 - i];
-		rpo2r[nr - 1 - i] = r1;
-	}
-	for(i = 0; i < nr; i++)
-		rpo2r[i]->rpo = i;
-
-	idom[0] = 0;
-	for(i = 0; i < nr; i++){
-		r1 = rpo2r[i];
-		me = r1->rpo;
-		d = -1;
-		if(r1->p1 != R && r1->p1->rpo < me)
-			d = r1->p1->rpo;
-		for(r1 = r1->p2; r1 != nil; r1 = r1->p2link)
-			if(r1->rpo < me)
-				d = rpolca(idom, d, r1->rpo);
-		idom[i] = d;
-	}
-
-	for(i = 0; i < nr; i++){
-		r1 = rpo2r[i];
-		r1->loop++;
-		if(r1->p2 != R && loophead(idom, r1))
-			loopmark(rpo2r, i, r1);
-	}
-}
-
-void
-synch(Reg *r, Bits dif)
-{
-	Reg *r1;
-	int z;
-
-	for(r1 = r; r1 != R; r1 = r1->s1) {
-		for(z=0; z<BITS; z++) {
-			dif.b[z] = (dif.b[z] &
-				~(~r1->refbehind.b[z] & r1->refahead.b[z])) |
-					r1->set.b[z] | r1->regdiff.b[z];
-			if(dif.b[z] != r1->regdiff.b[z]) {
-				r1->regdiff.b[z] = dif.b[z];
-				change++;
-			}
-		}
-		if(r1->active)
-			break;
-		r1->active = 1;
-		for(z=0; z<BITS; z++)
-			dif.b[z] &= ~(~r1->calbehind.b[z] & r1->calahead.b[z]);
-		if(r1->s2 != R)
-			synch(r1->s2, dif);
-	}
-}
-
-uint32_t
-allreg(uint32_t b, Rgn *r)
-{
-	Var *v;
-	int i;
-
-	v = var + r->varno;
-	r->regno = 0;
-	switch(v->etype) {
-
-	default:
-		diag(Z, "unknown etype %d/%d", bitno(b), v->etype);
-		break;
-
-	case TCHAR:
-	case TUCHAR:
-	case TSHORT:
-	case TUSHORT:
-	case TINT:
-	case TUINT:
-	case TLONG:
-	case TULONG:
-	case TVLONG:
-	case TUVLONG:
-	case TIND:
-	case TARRAY:
-		i = BtoR(~b);
-		if(i && r->cost > 0) {
-			r->regno = i;
-			return RtoB(i);
-		}
-		break;
-
-	case TDOUBLE:
-	case TFLOAT:
-		i = BtoF(~b);
-		if(i && r->cost > 0) {
-			r->regno = i;
-			return FtoB(i);
-		}
-		break;
-	}
-	return 0;
-}
-
-void
-paint1(Reg *r, int bn)
-{
-	Reg *r1;
-	Prog *p;
-	int z;
-	uint32_t bb;
-
-	z = bn/32;
-	bb = 1L<<(bn%32);
-	if(r->act.b[z] & bb)
-		return;
-	for(;;) {
-		if(!(r->refbehind.b[z] & bb))
-			break;
-		r1 = r->p1;
-		if(r1 == R)
-			break;
-		if(!(r1->refahead.b[z] & bb))
-			break;
-		if(r1->act.b[z] & bb)
-			break;
-		r = r1;
-	}
-
-	if(LOAD(r) & ~(r->set.b[z]&~(r->use1.b[z]|r->use2.b[z])) & bb) {
-		change -= CLOAD * r->loop;
-		if(debug['R'] && debug['v'])
-			print("%ld%P\tld %B $%d\n", r->loop,
-				r->prog, blsh(bn), change);
-	}
-	for(;;) {
-		r->act.b[z] |= bb;
-		p = r->prog;
-
-		if(r->use1.b[z] & bb) {
-			change += CREF * r->loop;
-			if(debug['R'] && debug['v'])
-				print("%ld%P\tu1 %B $%d\n", r->loop,
-					p, blsh(bn), change);
-		}
-
-		if((r->use2.b[z]|r->set.b[z]) & bb) {
-			change += CREF * r->loop;
-			if(debug['R'] && debug['v'])
-				print("%ld%P\tu2 %B $%d\n", r->loop,
-					p, blsh(bn), change);
-		}
-
-		if(STORE(r) & r->regdiff.b[z] & bb) {
-			change -= CLOAD * r->loop;
-			if(debug['R'] && debug['v'])
-				print("%ld%P\tst %B $%d\n", r->loop,
-					p, blsh(bn), change);
-		}
-
-		if(r->refbehind.b[z] & bb)
-			for(r1 = r->p2; r1 != R; r1 = r1->p2link)
-				if(r1->refahead.b[z] & bb)
-					paint1(r1, bn);
-
-		if(!(r->refahead.b[z] & bb))
-			break;
-		r1 = r->s2;
-		if(r1 != R)
-			if(r1->refbehind.b[z] & bb)
-				paint1(r1, bn);
-		r = r->s1;
-		if(r == R)
-			break;
-		if(r->act.b[z] & bb)
-			break;
-		if(!(r->refbehind.b[z] & bb))
-			break;
-	}
-}
-
-uint32_t
-regset(Reg *r, uint32_t bb)
-{
-	uint32_t b, set;
-	Adr v;
-	int c;
-
-	set = 0;
-	v = zprog.from;
-	while(b = bb & ~(bb-1)) {
-		v.type = b & 0xFFFF? BtoR(b): BtoF(b);
-		if(v.type == 0)
-			diag(Z, "zero v.type for %#lux", b);
-		c = copyu(r->prog, &v, A);
-		if(c == 3)
-			set |= b;
-		bb &= ~b;
-	}
-	return set;
-}
-
-uint32_t
-reguse(Reg *r, uint32_t bb)
-{
-	uint32_t b, set;
-	Adr v;
-	int c;
-
-	set = 0;
-	v = zprog.from;
-	while(b = bb & ~(bb-1)) {
-		v.type = b & 0xFFFF? BtoR(b): BtoF(b);
-		c = copyu(r->prog, &v, A);
-		if(c == 1 || c == 2 || c == 4)
-			set |= b;
-		bb &= ~b;
-	}
-	return set;
-}
-
-uint32_t
-paint2(Reg *r, int bn)
-{
-	Reg *r1;
-	int z;
-	uint32_t bb, vreg, x;
-
-	z = bn/32;
-	bb = 1L << (bn%32);
-	vreg = regbits;
-	if(!(r->act.b[z] & bb))
-		return vreg;
-	for(;;) {
-		if(!(r->refbehind.b[z] & bb))
-			break;
-		r1 = r->p1;
-		if(r1 == R)
-			break;
-		if(!(r1->refahead.b[z] & bb))
-			break;
-		if(!(r1->act.b[z] & bb))
-			break;
-		r = r1;
-	}
-	for(;;) {
-		r->act.b[z] &= ~bb;
-
-		vreg |= r->regu;
-
-		if(r->refbehind.b[z] & bb)
-			for(r1 = r->p2; r1 != R; r1 = r1->p2link)
-				if(r1->refahead.b[z] & bb)
-					vreg |= paint2(r1, bn);
-
-		if(!(r->refahead.b[z] & bb))
-			break;
-		r1 = r->s2;
-		if(r1 != R)
-			if(r1->refbehind.b[z] & bb)
-				vreg |= paint2(r1, bn);
-		r = r->s1;
-		if(r == R)
-			break;
-		if(!(r->act.b[z] & bb))
-			break;
-		if(!(r->refbehind.b[z] & bb))
-			break;
-	}
-
-	bb = vreg;
-	for(; r; r=r->s1) {
-		x = r->regu & ~bb;
-		if(x) {
-			vreg |= reguse(r, x);
-			bb |= regset(r, x);
-		}
-	}
-	return vreg;
-}
-
-void
-paint3(Reg *r, int bn, int32_t rb, int rn)
-{
-	Reg *r1;
-	Prog *p;
-	int z;
-	uint32_t bb;
-
-	z = bn/32;
-	bb = 1L << (bn%32);
-	if(r->act.b[z] & bb)
-		return;
-	for(;;) {
-		if(!(r->refbehind.b[z] & bb))
-			break;
-		r1 = r->p1;
-		if(r1 == R)
-			break;
-		if(!(r1->refahead.b[z] & bb))
-			break;
-		if(r1->act.b[z] & bb)
-			break;
-		r = r1;
-	}
-
-	if(LOAD(r) & ~(r->set.b[z] & ~(r->use1.b[z]|r->use2.b[z])) & bb)
-		addmove(r, bn, rn, 0);
-	for(;;) {
-		r->act.b[z] |= bb;
-		p = r->prog;
-
-		if(r->use1.b[z] & bb) {
-			if(debug['R'])
-				print("%P", p);
-			addreg(&p->from, rn);
-			if(debug['R'])
-				print("\t.c%P\n", p);
-		}
-		if((r->use2.b[z]|r->set.b[z]) & bb) {
-			if(debug['R'])
-				print("%P", p);
-			addreg(&p->to, rn);
-			if(debug['R'])
-				print("\t.c%P\n", p);
-		}
-
-		if(STORE(r) & r->regdiff.b[z] & bb)
-			addmove(r, bn, rn, 1);
-		r->regu |= rb;
-
-		if(r->refbehind.b[z] & bb)
-			for(r1 = r->p2; r1 != R; r1 = r1->p2link)
-				if(r1->refahead.b[z] & bb)
-					paint3(r1, bn, rb, rn);
-
-		if(!(r->refahead.b[z] & bb))
-			break;
-		r1 = r->s2;
-		if(r1 != R)
-			if(r1->refbehind.b[z] & bb)
-				paint3(r1, bn, rb, rn);
-		r = r->s1;
-		if(r == R)
-			break;
-		if(r->act.b[z] & bb)
-			break;
-		if(!(r->refbehind.b[z] & bb))
-			break;
-	}
-}
-
-void
-addreg(Adr *a, int rn)
-{
-
-	a->sym = 0;
-	a->offset = 0;
-	a->type = rn;
-}
-
-int32_t
-RtoB(int r)
-{
-
-	if(r < D_AX || r > D_R15)
-		return 0;
-	return 1L << (r-D_AX);
-}
-
-int
-BtoR(int32_t b)
-{
-
-	b &= 0xffffL;
-	if(b == 0)
-		return 0;
-	return bitno(b) + D_AX;
-}
-
-/*
- *	bit	reg
- *	16	X5
- *	17	X6
- *	18	X7
- */
-int32_t
-FtoB(int f)
-{
-	if(f < FREGMIN || f > FREGEXT)
-		return 0;
-	return 1L << (f - FREGMIN + 16);
-}
-
-int
-BtoF(int32_t b)
-{
-
-	b &= 0x70000L;
-	if(b == 0)
-		return 0;
-	return bitno(b) - 16 + FREGMIN;
-}

+ 0 - 444
sys/src/cmd/6c/sgen.c

@@ -1,444 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "gc.h"
-
-void
-noretval(int n)
-{
-
-	if(n & 1) {
-		gins(ANOP, Z, Z);
-		p->to.type = REGRET;
-	}
-	if(n & 2) {
-		gins(ANOP, Z, Z);
-		p->to.type = FREGRET;
-	}
-}
-
-/* welcome to commute */
-static void
-commute(Node *n)
-{
-	Node *l, *r;
-
-	l = n->left;
-	r = n->right;
-	if(r->complex > l->complex) {
-		n->left = r;
-		n->right = l;
-	}
-}
-
-void
-indexshift(Node *n)
-{
-	int g;
-
-	if(!typechlpv[n->type->etype])
-		return;
-	simplifyshift(n);
-	if(n->op == OASHL && n->right->op == OCONST){
-		g = vconst(n->right);
-		if(g >= 0 && g <= 3)
-			n->addable = 7;
-	}
-}
-
-/*
- *	calculate addressability as follows
- *		NAME ==> 10/11		name+value(SB/SP)
- *		REGISTER ==> 12		register
- *		CONST ==> 20		$value
- *		*(20) ==> 21		value
- *		&(10) ==> 13		$name+value(SB)
- *		&(11) ==> 1		$name+value(SP)
- *		(13) + (20) ==> 13	fold constants
- *		(1) + (20) ==> 1	fold constants
- *		*(13) ==> 10		back to name
- *		*(1) ==> 11		back to name
- *
- *		(20) * (X) ==> 7	multiplier in indexing
- *		(X,7) + (13,1) ==> 8	adder in indexing (addresses)
- *		(8) ==> &9(OINDEX)	index, almost addressable
- *
- *	calculate complexity (number of registers)
- */
-void
-xcom(Node *n)
-{
-	Node *l, *r;
-	int g;
-
-	if(n == Z)
-		return;
-	l = n->left;
-	r = n->right;
-	n->complex = 0;
-	n->addable = 0;
-	switch(n->op) {
-	case OCONST:
-		n->addable = 20;
-		break;
-
-	case ONAME:
-		n->addable = 10;
-		if(n->class == CPARAM || n->class == CAUTO)
-			n->addable = 11;
-		break;
-
-	case OREGISTER:
-		n->addable = 12;
-		break;
-
-	case OINDREG:
-		n->addable = 12;
-		break;
-
-	case OADDR:
-		xcom(l);
-		if(l->addable == 10)
-			n->addable = 13;
-		else
-		if(l->addable == 11)
-			n->addable = 1;
-		break;
-
-	case OADD:
-		xcom(l);
-		xcom(r);
-		if(n->type->etype != TIND)
-			break;
-
-		switch(r->addable) {
-		case 20:
-			switch(l->addable) {
-			case 1:
-			case 13:
-			commadd:
-				l->type = n->type;
-				*n = *l;
-				l = new(0, Z, Z);
-				*l = *(n->left);
-				l->xoffset += r->vconst;
-				n->left = l;
-				r = n->right;
-				goto brk;
-			}
-			break;
-
-		case 1:
-		case 13:
-		case 10:
-		case 11:
-			/* l is the base, r is the index */
-			if(l->addable != 20)
-				n->addable = 8;
-			break;
-		}
-		switch(l->addable) {
-		case 20:
-			switch(r->addable) {
-			case 13:
-			case 1:
-				r = n->left;
-				l = n->right;
-				n->left = l;
-				n->right = r;
-				goto commadd;
-			}
-			break;
-
-		case 13:
-		case 1:
-		case 10:
-		case 11:
-			/* r is the base, l is the index */
-			if(r->addable != 20)
-				n->addable = 8;
-			break;
-		}
-		if(n->addable == 8 && !side(n)) {
-			indx(n);
-			l = new1(OINDEX, idx.basetree, idx.regtree);
-			l->scale = idx.scale;
-			l->addable = 9;
-			l->complex = l->right->complex;
-			l->type = l->left->type;
-			n->op = OADDR;
-			n->left = l;
-			n->right = Z;
-			n->addable = 8;
-			break;
-		}
-		break;
-
-	case OINDEX:
-		xcom(l);
-		xcom(r);
-		n->addable = 9;
-		break;
-
-	case OIND:
-		xcom(l);
-		if(l->op == OADDR) {
-			l = l->left;
-			l->type = n->type;
-			*n = *l;
-			return;
-		}
-		switch(l->addable) {
-		case 20:
-			n->addable = 21;
-			break;
-		case 1:
-			n->addable = 11;
-			break;
-		case 13:
-			n->addable = 10;
-			break;
-		}
-		break;
-
-	case OASHL:
-		xcom(l);
-		xcom(r);
-		indexshift(n);
-		break;
-
-	case OMUL:
-	case OLMUL:
-		xcom(l);
-		xcom(r);
-		g = vlog(l);
-		if(g >= 0) {
-			n->left = r;
-			n->right = l;
-			l = r;
-			r = n->right;
-		}
-		g = vlog(r);
-		if(g >= 0) {
-			n->op = OASHL;
-			r->vconst = g;
-			r->type = types[TINT];
-			indexshift(n);
-			break;
-		}
-		commute(n);
-		break;
-
-	case OASLDIV:
-		xcom(l);
-		xcom(r);
-		g = vlog(r);
-		if(g >= 0) {
-			n->op = OASLSHR;
-			r->vconst = g;
-			r->type = types[TINT];
-		}
-		break;
-
-	case OLDIV:
-		xcom(l);
-		xcom(r);
-		g = vlog(r);
-		if(g >= 0) {
-			n->op = OLSHR;
-			r->vconst = g;
-			r->type = types[TINT];
-			indexshift(n);
-			break;
-		}
-		break;
-
-	case OASLMOD:
-		xcom(l);
-		xcom(r);
-		g = vlog(r);
-		if(g >= 0) {
-			n->op = OASAND;
-			r->vconst--;
-		}
-		break;
-
-	case OLMOD:
-		xcom(l);
-		xcom(r);
-		g = vlog(r);
-		if(g >= 0) {
-			n->op = OAND;
-			r->vconst--;
-		}
-		break;
-
-	case OASMUL:
-	case OASLMUL:
-		xcom(l);
-		xcom(r);
-		g = vlog(r);
-		if(g >= 0) {
-			n->op = OASASHL;
-			r->vconst = g;
-		}
-		break;
-
-	case OLSHR:
-	case OASHR:
-		xcom(l);
-		xcom(r);
-		indexshift(n);
-		break;
-
-	default:
-		if(l != Z)
-			xcom(l);
-		if(r != Z)
-			xcom(r);
-		break;
-	}
-brk:
-	if(n->addable >= 10)
-		return;
-	if(l != Z)
-		n->complex = l->complex;
-	if(r != Z) {
-		if(r->complex == n->complex)
-			n->complex = r->complex+1;
-		else
-		if(r->complex > n->complex)
-			n->complex = r->complex;
-	}
-	if(n->complex == 0)
-		n->complex++;
-
-	switch(n->op) {
-
-	case OFUNC:
-		n->complex = FNX;
-		break;
-
-	case OCAST:
-		if(l->type->etype == TUVLONG && typefd[n->type->etype])
-			n->complex += 2;
-		break;
-
-	case OLMOD:
-	case OMOD:
-	case OLMUL:
-	case OLDIV:
-	case OMUL:
-	case ODIV:
-	case OASLMUL:
-	case OASLDIV:
-	case OASLMOD:
-	case OASMUL:
-	case OASDIV:
-	case OASMOD:
-		if(r->complex >= l->complex) {
-			n->complex = l->complex + 3;
-			if(r->complex > n->complex)
-				n->complex = r->complex;
-		} else {
-			n->complex = r->complex + 3;
-			if(l->complex > n->complex)
-				n->complex = l->complex;
-		}
-		break;
-
-	case OLSHR:
-	case OASHL:
-	case OASHR:
-	case OASLSHR:
-	case OASASHL:
-	case OASASHR:
-		if(r->complex >= l->complex) {
-			n->complex = l->complex + 2;
-			if(r->complex > n->complex)
-				n->complex = r->complex;
-		} else {
-			n->complex = r->complex + 2;
-			if(l->complex > n->complex)
-				n->complex = l->complex;
-		}
-		break;
-
-	case OADD:
-	case OXOR:
-	case OAND:
-	case OOR:
-		/*
-		 * immediate operators, make const on right
-		 */
-		if(l->op == OCONST) {
-			n->left = r;
-			n->right = l;
-		}
-		break;
-
-	case OEQ:
-	case ONE:
-	case OLE:
-	case OLT:
-	case OGE:
-	case OGT:
-	case OHI:
-	case OHS:
-	case OLO:
-	case OLS:
-		/*
-		 * compare operators, make const on left
-		 */
-		if(r->op == OCONST) {
-			n->left = r;
-			n->right = l;
-			n->op = invrel[relindex(n->op)];
-		}
-		break;
-	}
-}
-
-void
-indx(Node *n)
-{
-	Node *l, *r;
-
-	if(debug['x'])
-		prtree(n, "indx");
-
-	l = n->left;
-	r = n->right;
-	if(l->addable == 1 || l->addable == 13 || r->complex > l->complex) {
-		n->right = l;
-		n->left = r;
-		l = r;
-		r = n->right;
-	}
-	if(l->addable != 7) {
-		idx.regtree = l;
-		idx.scale = 1;
-	} else
-	if(l->right->addable == 20) {
-		idx.regtree = l->left;
-		idx.scale = 1 << l->right->vconst;
-	} else
-	if(l->left->addable == 20) {
-		idx.regtree = l->right;
-		idx.scale = 1 << l->left->vconst;
-	} else
-		diag(n, "bad index");
-
-	idx.basetree = r;
-	if(debug['x']) {
-		print("scale = %d\n", idx.scale);
-		prtree(idx.regtree, "index");
-		prtree(idx.basetree, "base");
-	}
-}

+ 0 - 522
sys/src/cmd/6c/swt.c

@@ -1,522 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "gc.h"
-
-void
-swit1(C1 *q, int nc, int32_t def, Node *n)
-{
-	C1 *r;
-	int i;
-	Prog *sp;
-
-	if(nc < 5) {
-		for(i=0; i<nc; i++) {
-			if(debug['K'])
-				print("case = %.8llux\n", q->val);
-			gcmp(OEQ, n, q->val);
-			patch(p, q->label);
-			q++;
-		}
-		gbranch(OGOTO);
-		patch(p, def);
-		return;
-	}
-	i = nc / 2;
-	r = q+i;
-	if(debug['K'])
-		print("case > %.8llux\n", r->val);
-	gcmp(OGT, n, r->val);
-	sp = p;
-	gbranch(OGOTO);
-	p->as = AJEQ;
-	patch(p, r->label);
-	swit1(q, i, def, n);
-
-	if(debug['K'])
-		print("case < %.8llux\n", r->val);
-	patch(sp, pc);
-	swit1(r+1, nc-i-1, def, n);
-}
-
-void
-bitload(Node *b, Node *n1, Node *n2, Node *n3, Node *nn)
-{
-	int sh;
-	int32_t v;
-	Node *l;
-
-	/*
-	 * n1 gets adjusted/masked value
-	 * n2 gets address of cell
-	 * n3 gets contents of cell
-	 */
-	l = b->left;
-	if(n2 != Z) {
-		regalloc(n1, l, nn);
-		reglcgen(n2, l, Z);
-		regalloc(n3, l, Z);
-		gmove(n2, n3);
-		gmove(n3, n1);
-	} else {
-		regalloc(n1, l, nn);
-		cgen(l, n1);
-	}
-	if(b->type->shift == 0 && typeu[b->type->etype]) {
-		v = ~0 + (1L << b->type->nbits);
-		gopcode(OAND, tfield, nodconst(v), n1);
-	} else {
-		sh = 32 - b->type->shift - b->type->nbits;
-		if(sh > 0)
-			gopcode(OASHL, tfield, nodconst(sh), n1);
-		sh += b->type->shift;
-		if(sh > 0)
-			if(typeu[b->type->etype])
-				gopcode(OLSHR, tfield, nodconst(sh), n1);
-			else
-				gopcode(OASHR, tfield, nodconst(sh), n1);
-	}
-}
-
-void
-bitstore(Node *b, Node *n1, Node *n2, Node *n3, Node *nn)
-{
-	int32_t v;
-	Node nod;
-	int sh;
-
-	regalloc(&nod, b->left, Z);
-	v = ~0 + (1L << b->type->nbits);
-	gopcode(OAND, types[TLONG], nodconst(v), n1);
-	gmove(n1, &nod);
-	if(nn != Z)
-		gmove(n1, nn);
-	sh = b->type->shift;
-	if(sh > 0)
-		gopcode(OASHL, types[TLONG], nodconst(sh), &nod);
-	v <<= sh;
-	gopcode(OAND, types[TLONG], nodconst(~v), n3);
-	gopcode(OOR, types[TLONG], n3, &nod);
-	gmove(&nod, n2);
-
-	regfree(&nod);
-	regfree(n1);
-	regfree(n2);
-	regfree(n3);
-}
-
-int32_t
-outstring(char *s, int32_t n)
-{
-	int32_t r;
-
-	if(suppress)
-		return nstring;
-	r = nstring;
-	while(n) {
-		string[mnstring] = *s++;
-		mnstring++;
-		nstring++;
-		if(mnstring >= NSNAME) {
-			gpseudo(ADATA, symstring, nodconst(0L));
-			p->from.offset += nstring - NSNAME;
-			p->from.scale = NSNAME;
-			p->to.type = D_SCONST;
-			memmove(p->to.sval, string, NSNAME);
-			mnstring = 0;
-		}
-		n--;
-	}
-	return r;
-}
-
-void
-gextern(Sym *s, Node *a, int32_t o, int32_t w)
-{
-	if(0 && a->op == OCONST && typev[a->type->etype]) {
-		gpseudo(ADATA, s, lo64(a));
-		p->from.offset += o;
-		p->from.scale = 4;
-		gpseudo(ADATA, s, hi64(a));
-		p->from.offset += o + 4;
-		p->from.scale = 4;
-		return;
-	}
-	gpseudo(ADATA, s, a);
-	p->from.offset += o;
-	p->from.scale = w;
-	switch(p->to.type) {
-	default:
-		p->to.index = p->to.type;
-		p->to.type = D_ADDR;
-	case D_CONST:
-	case D_FCONST:
-	case D_ADDR:
-		break;
-	}
-}
-
-void	zname(Biobuf*, Sym*, int);
-void	zaddr(Biobuf*, Adr*, int);
-void	outhist(Biobuf*);
-
-void
-outcode(void)
-{
-	struct { Sym *sym; int16_t type; } h[NSYM];
-	Prog *p;
-	Sym *s;
-	int f, sf, st, t, sym;
-	Biobuf b;
-
-	if(debug['S']) {
-		for(p = firstp; p != P; p = p->link)
-			if(p->as != ADATA && p->as != AGLOBL)
-				pc--;
-		for(p = firstp; p != P; p = p->link) {
-			print("%P\n", p);
-			if(p->as != ADATA && p->as != AGLOBL)
-				pc++;
-		}
-	}
-	f = open(outfile, OWRITE);
-	if(f < 0) {
-		diag(Z, "cannot open %s", outfile);
-		return;
-	}
-	Binit(&b, f, OWRITE);
-	Bseek(&b, 0L, 2);
-	outhist(&b);
-	for(sym=0; sym<NSYM; sym++) {
-		h[sym].sym = S;
-		h[sym].type = 0;
-	}
-	sym = 1;
-	for(p = firstp; p != P; p = p->link) {
-	jackpot:
-		sf = 0;
-		s = p->from.sym;
-		while(s != S) {
-			sf = s->sym;
-			if(sf < 0 || sf >= NSYM)
-				sf = 0;
-			t = p->from.type;
-			if(t == D_ADDR)
-				t = p->from.index;
-			if(h[sf].type == t)
-			if(h[sf].sym == s)
-				break;
-			s->sym = sym;
-			zname(&b, s, t);
-			h[sym].sym = s;
-			h[sym].type = t;
-			sf = sym;
-			sym++;
-			if(sym >= NSYM)
-				sym = 1;
-			break;
-		}
-		st = 0;
-		s = p->to.sym;
-		while(s != S) {
-			st = s->sym;
-			if(st < 0 || st >= NSYM)
-				st = 0;
-			t = p->to.type;
-			if(t == D_ADDR)
-				t = p->to.index;
-			if(h[st].type == t)
-			if(h[st].sym == s)
-				break;
-			s->sym = sym;
-			zname(&b, s, t);
-			h[sym].sym = s;
-			h[sym].type = t;
-			st = sym;
-			sym++;
-			if(sym >= NSYM)
-				sym = 1;
-			if(st == sf)
-				goto jackpot;
-			break;
-		}
-		Bputc(&b, p->as);
-		Bputc(&b, p->as>>8);
-		Bputc(&b, p->lineno);
-		Bputc(&b, p->lineno>>8);
-		Bputc(&b, p->lineno>>16);
-		Bputc(&b, p->lineno>>24);
-		zaddr(&b, &p->from, sf);
-		zaddr(&b, &p->to, st);
-	}
-	Bflush(&b);
-	close(f);
-	firstp = P;
-	lastp = P;
-}
-
-void
-outhist(Biobuf *b)
-{
-	Hist *h;
-	char *p, *q, *op, c;
-	Prog pg;
-	int n;
-
-	pg = zprog;
-	pg.as = AHISTORY;
-	c = pathchar();
-	for(h = hist; h != H; h = h->link) {
-		p = h->name;
-		op = 0;
-		/* on windows skip drive specifier in pathname */
-		if(systemtype(Windows) && p && p[1] == ':'){
-			p += 2;
-			c = *p;
-		}
-		if(p && p[0] != c && h->offset == 0 && pathname){
-			/* on windows skip drive specifier in pathname */
-			if(systemtype(Windows) && pathname[1] == ':') {
-				op = p;
-				p = pathname+2;
-				c = *p;
-			} else if(pathname[0] == c){
-				op = p;
-				p = pathname;
-			}
-		}
-		while(p) {
-			q = utfrune(p, c);
-			if(q) {
-				n = q-p;
-				if(n == 0){
-					n = 1;	/* leading "/" */
-					*p = '/';	/* don't emit "\" on windows */
-				}
-				q++;
-			} else {
-				n = strlen(p);
-				q = 0;
-			}
-			if(n) {
-				Bputc(b, ANAME);
-				Bputc(b, ANAME>>8);
-				Bputc(b, D_FILE);
-				Bputc(b, 1);
-				Bputc(b, '<');
-				Bwrite(b, p, n);
-				Bputc(b, 0);
-			}
-			p = q;
-			if(p == 0 && op) {
-				p = op;
-				op = 0;
-			}
-		}
-		pg.lineno = h->line;
-		pg.to.type = zprog.to.type;
-		pg.to.offset = h->offset;
-		if(h->offset)
-			pg.to.type = D_CONST;
-
-		Bputc(b, pg.as);
-		Bputc(b, pg.as>>8);
-		Bputc(b, pg.lineno);
-		Bputc(b, pg.lineno>>8);
-		Bputc(b, pg.lineno>>16);
-		Bputc(b, pg.lineno>>24);
-		zaddr(b, &pg.from, 0);
-		zaddr(b, &pg.to, 0);
-	}
-}
-
-void
-zname(Biobuf *b, Sym *s, int t)
-{
-	char *n;
-	uint32_t sig;
-
-	if(debug['T'] && t == D_EXTERN && s->sig != SIGDONE && s->type != types[TENUM] && s != symrathole){
-		sig = sign(s);
-		Bputc(b, ASIGNAME);
-		Bputc(b, ASIGNAME>>8);
-		Bputc(b, sig);
-		Bputc(b, sig>>8);
-		Bputc(b, sig>>16);
-		Bputc(b, sig>>24);
-		s->sig = SIGDONE;
-	}
-	else{
-		Bputc(b, ANAME);	/* as */
-		Bputc(b, ANAME>>8);	/* as */
-	}
-	Bputc(b, t);			/* type */
-	Bputc(b, s->sym);		/* sym */
-	n = s->name;
-	while(*n) {
-		Bputc(b, *n);
-		n++;
-	}
-	Bputc(b, 0);
-}
-
-void
-zaddr(Biobuf *b, Adr *a, int s)
-{
-	int32_t l;
-	int i, t;
-	char *n;
-	Ieee e;
-
-	t = 0;
-	if(a->index != D_NONE || a->scale != 0)
-		t |= T_INDEX;
-	if(s != 0)
-		t |= T_SYM;
-
-	switch(a->type) {
-	default:
-		t |= T_TYPE;
-	case D_NONE:
-		if(a->offset != 0) {
-			t |= T_OFFSET;
-			l = a->offset;
-			if((int64_t)l != a->offset)
-				t |= T_64;
-		}
-		break;
-	case D_FCONST:
-		t |= T_FCONST;
-		break;
-	case D_SCONST:
-		t |= T_SCONST;
-		break;
-	}
-	Bputc(b, t);
-
-	if(t & T_INDEX) {	/* implies index, scale */
-		Bputc(b, a->index);
-		Bputc(b, a->scale);
-	}
-	if(t & T_OFFSET) {	/* implies offset */
-		l = a->offset;
-		Bputc(b, l);
-		Bputc(b, l>>8);
-		Bputc(b, l>>16);
-		Bputc(b, l>>24);
-		if(t & T_64) {
-			l = a->offset>>32;
-			Bputc(b, l);
-			Bputc(b, l>>8);
-			Bputc(b, l>>16);
-			Bputc(b, l>>24);
-		}
-	}
-	if(t & T_SYM)		/* implies sym */
-		Bputc(b, s);
-	if(t & T_FCONST) {
-		ieeedtod(&e, a->dval);
-		l = e.l;
-		Bputc(b, l);
-		Bputc(b, l>>8);
-		Bputc(b, l>>16);
-		Bputc(b, l>>24);
-		l = e.h;
-		Bputc(b, l);
-		Bputc(b, l>>8);
-		Bputc(b, l>>16);
-		Bputc(b, l>>24);
-		return;
-	}
-	if(t & T_SCONST) {
-		n = a->sval;
-		for(i=0; i<NSNAME; i++) {
-			Bputc(b, *n);
-			n++;
-		}
-		return;
-	}
-	if(t & T_TYPE)
-		Bputc(b, a->type);
-}
-
-int32_t
-align(int32_t i, Type *t, int op)
-{
-	int32_t o;
-	Type *v;
-	int w;
-
-	o = i;
-	w = 1;
-	switch(op) {
-	default:
-		diag(Z, "unknown align opcode %d", op);
-		break;
-
-	case Asu2:	/* padding at end of a struct */
-		w = SZ_VLONG;
-		if(packflg)
-			w = packflg;
-		break;
-
-	case Ael1:	/* initial align of struct element */
-		for(v=t; v->etype==TARRAY; v=v->link)
-			;
-		w = ewidth[v->etype];
-		if(w <= 0 || w >= SZ_VLONG)
-			w = SZ_VLONG;
-		if(packflg)
-			w = packflg;
-		break;
-
-	case Ael2:	/* width of a struct element */
-		o += t->width;
-		break;
-
-	case Aarg0:	/* initial passbyptr argument in arg list */
-		if(typesu[t->etype]) {
-			o = align(o, types[TIND], Aarg1);
-			o = align(o, types[TIND], Aarg2);
-		}
-		break;
-
-	case Aarg1:	/* initial align of parameter */
-		w = ewidth[t->etype];
-		if(w <= 0 || w >= SZ_VLONG) {
-			w = SZ_VLONG;
-			break;
-		}
-		w = 1;		/* little endian no adjustment */
-		break;
-
-	case Aarg2:	/* width of a parameter */
-		o += t->width;
-		w = SZ_VLONG;
-		break;
-
-	case Aaut3:	/* total allign of automatic */
-		o = align(o, t, Ael1);
-		o = align(o, t, Ael2);
-		break;
-	}
-	o = round(o, w);
-	if(debug['A'])
-		print("align %s %ld %T = %ld\n", bnames[op], i, t, o);
-	return o;
-}
-
-int32_t
-maxround(int32_t max, int32_t v)
-{
-	v = round(v, SZ_VLONG);
-	if(v > max)
-		return v;
-	return max;
-}

+ 0 - 115
sys/src/cmd/6c/sys.c

@@ -1,115 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include "/sys/src/libc/9syscall/sys.h"
-
-int64_t	_sysargs[6*4];
-int64_t _callsys(void);
-
-/*
- * syscalls
- */
-
-int
-getpid(void)
-{
-	_sysargs[0] = -1;
-	return _callsys();
-}
-
-int32_t
-pread(int fd, void *a, int32_t n, int64_t)
-{
-	_sysargs[0] = PREAD;
-	_sysargs[1] = fd;
-	_sysargs[2] = (int64_t)a;
-	_sysargs[3] = n;
-	return _callsys();
-}
-
-int32_t
-pwrite(int fd, void *a, int32_t n, int64_t)
-{
-	_sysargs[0] = PWRITE;
-	_sysargs[1] = fd;
-	_sysargs[2] = (int64_t)a;
-	_sysargs[3] = n;
-	return _callsys();
-}
-
-int
-close(int fd)
-{
-	_sysargs[0] = CLOSE;
-	_sysargs[1] = fd;
-	return _callsys();
-}
-
-int
-open(char *name, int mode)
-{
-	_sysargs[0] = OPEN;
-	_sysargs[1] = (int64_t)name;
-	_sysargs[2] = mode;
-	return _callsys();
-}
-
-int
-create(char *f, int mode, uint32_t perm)
-{
-	_sysargs[0] = CREATE;
-	_sysargs[1] = (int64_t)f;
-	_sysargs[2] = mode;
-	_sysargs[3] = perm;
-	return _callsys();
-}
-
-void
-_exits(char *s)
-{
-	_sysargs[0] = EXITS;
-	_sysargs[1] = s!=nil? strlen(s): 0;
-	_callsys();
-}
-
-int
-dup(int f, int t)
-{
-	_sysargs[0] = DUP;
-	_sysargs[1] = f;
-	_sysargs[2] = t;
-	return _callsys();
-}
-
-int
-errstr(char *buf, uint n)
-{
-	_sysargs[0] = ERRSTR;
-	_sysargs[1] = (int64_t)buf;
-	_sysargs[2] = n;
-	return _callsys();
-}
-
-int
-brk_(void *a)
-{
-	_sysargs[0] = BRK_;
-	_sysargs[1] = (int64_t)a;
-	return _callsys();
-}
-
-void*
-sbrk(uint32_t n)
-{
-	_sysargs[0] = -2;
-	_sysargs[1] = n;
-	return (void*)_callsys();
-}

+ 0 - 1531
sys/src/cmd/6c/txt.c

@@ -1,1531 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "gc.h"
-
-static	int	resvreg[nelem(reg)];
-
-void
-ginit(void)
-{
-	int i;
-	Type *t;
-
-	thechar = '6';
-	thestring = "amd64";
-	exregoffset = REGEXT;
-	exfregoffset = FREGEXT;
-	listinit();
-	nstring = 0;
-	mnstring = 0;
-	nrathole = 0;
-	pc = 0;
-	breakpc = -1;
-	continpc = -1;
-	cases = C;
-	firstp = P;
-	lastp = P;
-	tfield = types[TINT];
-
-	typeword = typechlvp;
-	typeswitch = typechlv;
-	typecmplx = typesu;
-
-	/* TO DO */
-	memmove(typechlpv, typechlp, sizeof(typechlpv));
-	typechlpv[TVLONG] = 1;
-	typechlpv[TUVLONG] = 1;
-
-	zprog.link = P;
-	zprog.as = AGOK;
-	zprog.from.type = D_NONE;
-	zprog.from.index = D_NONE;
-	zprog.from.scale = 0;
-	zprog.to = zprog.from;
-
-	lregnode.op = OREGISTER;
-	lregnode.class = CEXREG;
-	lregnode.reg = REGTMP;
-	lregnode.complex = 0;
-	lregnode.addable = 11;
-	lregnode.type = types[TLONG];
-
-	qregnode = lregnode;
-	qregnode.type = types[TVLONG];
-
-	constnode.op = OCONST;
-	constnode.class = CXXX;
-	constnode.complex = 0;
-	constnode.addable = 20;
-	constnode.type = types[TLONG];
-
-	vconstnode = constnode;
-	vconstnode.type = types[TVLONG];
-
-	fconstnode.op = OCONST;
-	fconstnode.class = CXXX;
-	fconstnode.complex = 0;
-	fconstnode.addable = 20;
-	fconstnode.type = types[TDOUBLE];
-
-	nodsafe = new(ONAME, Z, Z);
-	nodsafe->sym = slookup(".safe");
-	nodsafe->type = types[TINT];
-	nodsafe->etype = types[TINT]->etype;
-	nodsafe->class = CAUTO;
-	complex(nodsafe);
-
-	t = typ(TARRAY, types[TCHAR]);
-	symrathole = slookup(".rathole");
-	symrathole->class = CGLOBL;
-	symrathole->type = t;
-
-	nodrat = new(ONAME, Z, Z);
-	nodrat->sym = symrathole;
-	nodrat->type = types[TIND];
-	nodrat->etype = TVOID;
-	nodrat->class = CGLOBL;
-	complex(nodrat);
-	nodrat->type = t;
-
-	nodret = new(ONAME, Z, Z);
-	nodret->sym = slookup(".ret");
-	nodret->type = types[TIND];
-	nodret->etype = TIND;
-	nodret->class = CPARAM;
-	nodret = new(OIND, nodret, Z);
-	complex(nodret);
-
-	if(0)
-		com64init();
-
-	memset(reg, 0, sizeof(reg));
-	for(i=0; i<nelem(reg); i++) {
-		reg[i] = 1;
-		if(i >= D_AX && i <= D_R15 && i != D_SP)
-			reg[i] = 0;
-		if(i >= D_X0 && i <= D_X7)
-			reg[i] = 0;
-	}
-	/* keep two external registers */
-	reg[REGEXT] = 1;
-	reg[REGEXT-1] = 1;
-	memmove(resvreg, reg, sizeof(resvreg));
-}
-
-void
-gclean(void)
-{
-	int i;
-	Sym *s;
-
-	reg[D_SP]--;
-	for(i=D_AX; i<=D_R15; i++)
-		if(reg[i] && !resvreg[i])
-			diag(Z, "reg %R left allocated", i);
-	for(i=D_X0; i<=D_X7; i++)
-		if(reg[i] && !resvreg[i])
-			diag(Z, "reg %R left allocated", i);
-	while(mnstring)
-		outstring("", 1L);
-	symstring->type->width = nstring;
-	symrathole->type->width = nrathole;
-	for(i=0; i<NHASH; i++)
-	for(s = hash[i]; s != S; s = s->link) {
-		if(s->type == T)
-			continue;
-		if(s->type->width == 0)
-			continue;
-		if(s->class != CGLOBL && s->class != CSTATIC)
-			continue;
-		if(s->type == types[TENUM])
-			continue;
-		gpseudo(AGLOBL, s, nodconst(s->type->width));
-	}
-	nextpc();
-	p->as = AEND;
-	outcode();
-}
-
-void
-nextpc(void)
-{
-
-	p = alloc(sizeof(*p));
-	*p = zprog;
-	p->lineno = nearln;
-	pc++;
-	if(firstp == P) {
-		firstp = p;
-		lastp = p;
-		return;
-	}
-	lastp->link = p;
-	lastp = p;
-}
-
-void
-gargs(Node *n, Node *tn1, Node *tn2)
-{
-	int32_t regs;
-	Node fnxargs[20], *fnxp;
-
-	regs = cursafe;
-
-	fnxp = fnxargs;
-	garg1(n, tn1, tn2, 0, &fnxp);	/* compile fns to temps */
-
-	curarg = 0;
-	fnxp = fnxargs;
-	garg1(n, tn1, tn2, 1, &fnxp);	/* compile normal args and temps */
-
-	cursafe = regs;
-}
-
-int
-nareg(void)
-{
-	int i, n;
-
-	n = 0;
-	for(i=D_AX; i<=D_R15; i++)
-		if(reg[i] == 0 && !resvreg[i])
-			n++;
-	return n;
-}
-
-void
-garg1(Node *n, Node *tn1, Node *tn2, int f, Node **fnxp)
-{
-	Node nod;
-
-	if(n == Z)
-		return;
-	if(n->op == OLIST) {
-		garg1(n->left, tn1, tn2, f, fnxp);
-		garg1(n->right, tn1, tn2, f, fnxp);
-		return;
-	}
-	if(f == 0) {
-		if(n->complex >= FNX) {
-			regsalloc(*fnxp, n);
-			nod = znode;
-			nod.op = OAS;
-			nod.left = *fnxp;
-			nod.right = n;
-			nod.type = n->type;
-			cgen(&nod, Z);
-			(*fnxp)++;
-		}
-		return;
-	}
-	if(typesu[n->type->etype]) {
-		regaalloc(tn2, n);
-		if(n->complex >= FNX) {
-			sugen(*fnxp, tn2, n->type->width);
-			(*fnxp)++;
-		} else
-			sugen(n, tn2, n->type->width);
-		return;
-	}
-	if(REGARG && curarg == 0 && typechlpv[n->type->etype]) {
-		regaalloc1(tn1, n);
-		if(n->complex >= FNX) {
-			cgen(*fnxp, tn1);
-			(*fnxp)++;
-		} else
-			cgen(n, tn1);
-		return;
-	}
-	if(vconst(n) == 0) {
-		regaalloc(tn2, n);
-		gmove(n, tn2);
-		return;
-	}
-	regalloc(tn1, n, Z);
-	if(n->complex >= FNX) {
-		cgen(*fnxp, tn1);
-		(*fnxp)++;
-	} else
-		cgen(n, tn1);
-	regaalloc(tn2, n);
-	gmove(tn1, tn2);
-	regfree(tn1);
-}
-
-Node*
-nodgconst(int64_t v, Type *t)
-{
-	if(!typev[t->etype])
-		return nodconst((int32_t)v);
-	vconstnode.vconst = v;
-	return &vconstnode;
-}
-
-Node*
-nodconst(int32_t v)
-{
-	constnode.vconst = v;
-	return &constnode;
-}
-
-Node*
-nodfconst(double d)
-{
-	fconstnode.fconst = d;
-	return &fconstnode;
-}
-
-int
-isreg(Node *n, int r)
-{
-
-	if(n->op == OREGISTER)
-		if(n->reg == r)
-			return 1;
-	return 0;
-}
-
-int
-nodreg(Node *n, Node *nn, int r)
-{
-	int et;
-
-	*n = qregnode;
-	n->reg = r;
-	if(nn != Z){
-		et = nn->type->etype;
-		if(!typefd[et] && nn->type->width <= SZ_LONG && 0)
-			n->type = typeu[et]? types[TUINT]: types[TINT];
-		else
-			n->type = nn->type;
-//print("nodreg %s [%s]\n", tnames[et], tnames[n->type->etype]);
-		n->lineno = nn->lineno;
-	}
-	if(reg[r] == 0)
-		return 0;
-	if(nn != Z) {
-		if(nn->op == OREGISTER)
-		if(nn->reg == r)
-			return 0;
-	}
-	return 1;
-}
-
-void
-regret(Node *n, Node *nn)
-{
-	int r;
-
-	r = REGRET;
-	if(typefd[nn->type->etype])
-		r = FREGRET;
-	nodreg(n, nn, r);
-	reg[r]++;
-}
-
-void
-regalloc(Node *n, Node *tn, Node *o)
-{
-	int i;
-
-	switch(tn->type->etype) {
-	case TCHAR:
-	case TUCHAR:
-	case TSHORT:
-	case TUSHORT:
-	case TINT:
-	case TUINT:
-	case TLONG:
-	case TULONG:
-	case TVLONG:
-	case TUVLONG:
-	case TIND:
-		if(o != Z && o->op == OREGISTER) {
-			i = o->reg;
-			if(i >= D_AX && i <= D_R15)
-				goto out;
-		}
-		for(i=D_AX; i<=D_R15; i++)
-			if(reg[i] == 0 && !resvreg[i])
-				goto out;
-		diag(tn, "out of fixed registers");
-		goto err;
-
-	case TFLOAT:
-	case TDOUBLE:
-		if(o != Z && o->op == OREGISTER) {
-			i = o->reg;
-			if(i >= D_X0 && i <= D_X7)
-				goto out;
-		}
-		for(i=D_X0; i<=D_X7; i++)
-			if(reg[i] == 0 && !resvreg[i])
-				goto out;
-		diag(tn, "out of float registers");
-		goto out;
-	}
-	diag(tn, "unknown type in regalloc: %T", tn->type);
-err:
-	i = 0;
-out:
-	if(i)
-		reg[i]++;
-	nodreg(n, tn, i);
-}
-
-void
-regialloc(Node *n, Node *tn, Node *o)
-{
-	Node nod;
-
-	nod = *tn;
-	nod.type = types[TIND];
-	regalloc(n, &nod, o);
-}
-
-void
-regfree(Node *n)
-{
-	int i;
-
-	i = 0;
-	if(n->op != OREGISTER && n->op != OINDREG)
-		goto err;
-	i = n->reg;
-	if(i < 0 || i >= sizeof(reg))
-		goto err;
-	if(reg[i] <= 0)
-		goto err;
-	reg[i]--;
-	return;
-err:
-	diag(n, "error in regfree: %R", i);
-}
-
-void
-regsalloc(Node *n, Node *nn)
-{
-	cursafe = align(cursafe, nn->type, Aaut3);
-	maxargsafe = maxround(maxargsafe, cursafe+curarg);
-	*n = *nodsafe;
-	n->xoffset = -(stkoff + cursafe);
-	n->type = nn->type;
-	n->etype = nn->type->etype;
-	n->lineno = nn->lineno;
-}
-
-void
-regaalloc1(Node *n, Node *nn)
-{
-	nodreg(n, nn, REGARG);
-	reg[REGARG]++;
-	curarg = align(curarg, nn->type, Aarg1);
-	curarg = align(curarg, nn->type, Aarg2);
-	maxargsafe = maxround(maxargsafe, cursafe+curarg);
-}
-
-void
-regaalloc(Node *n, Node *nn)
-{
-	curarg = align(curarg, nn->type, Aarg1);
-	*n = *nn;
-	n->op = OINDREG;
-	n->reg = REGSP;
-	n->xoffset = curarg;
-	n->complex = 0;
-	n->addable = 20;
-	curarg = align(curarg, nn->type, Aarg2);
-	maxargsafe = maxround(maxargsafe, cursafe+curarg);
-}
-
-void
-regind(Node *n, Node *nn)
-{
-
-	if(n->op != OREGISTER) {
-		diag(n, "regind not OREGISTER");
-		return;
-	}
-	n->op = OINDREG;
-	n->type = nn->type;
-}
-
-void
-naddr(Node *n, Adr *a)
-{
-	int32_t v;
-
-	a->type = D_NONE;
-	if(n == Z)
-		return;
-	switch(n->op) {
-	default:
-	bad:
-		diag(n, "bad in naddr: %O %D", n->op, a);
-		break;
-
-	case OREGISTER:
-		a->type = n->reg;
-		a->sym = S;
-		break;
-
-
-	case OIND:
-		naddr(n->left, a);
-		if(a->type >= D_AX && a->type <= D_R15)
-			a->type += D_INDIR;
-		else
-		if(a->type == D_CONST)
-			a->type = D_NONE+D_INDIR;
-		else
-		if(a->type == D_ADDR) {
-			a->type = a->index;
-			a->index = D_NONE;
-		} else
-			goto bad;
-		break;
-
-	case OINDEX:
-		a->type = idx.ptr;
-		if(n->left->op == OADDR || n->left->op == OCONST)
-			naddr(n->left, a);
-		if(a->type >= D_AX && a->type <= D_R15)
-			a->type += D_INDIR;
-		else
-		if(a->type == D_CONST)
-			a->type = D_NONE+D_INDIR;
-		else
-		if(a->type == D_ADDR) {
-			a->type = a->index;
-			a->index = D_NONE;
-		} else
-			goto bad;
-		a->index = idx.reg;
-		a->scale = n->scale;
-		a->offset += n->xoffset;
-		break;
-
-	case OINDREG:
-		a->type = n->reg+D_INDIR;
-		a->sym = S;
-		a->offset = n->xoffset;
-		break;
-
-	case ONAME:
-		a->etype = n->etype;
-		a->type = D_STATIC;
-		a->sym = n->sym;
-		a->offset = n->xoffset;
-		if(n->class == CSTATIC)
-			break;
-		if(n->class == CEXTERN || n->class == CGLOBL) {
-			a->type = D_EXTERN;
-			break;
-		}
-		if(n->class == CAUTO) {
-			a->type = D_AUTO;
-			break;
-		}
-		if(n->class == CPARAM) {
-			a->type = D_PARAM;
-			break;
-		}
-		goto bad;
-
-	case OCONST:
-		if(typefd[n->type->etype]) {
-			a->type = D_FCONST;
-			a->dval = n->fconst;
-			break;
-		}
-		a->sym = S;
-		a->type = D_CONST;
-		if(typev[n->type->etype] || n->type->etype == TIND)
-			a->offset = n->vconst;
-		else
-			a->offset = convvtox(n->vconst, typeu[n->type->etype]? TULONG: TLONG);
-		break;
-
-	case OADDR:
-		naddr(n->left, a);
-		if(a->type >= D_INDIR) {
-			a->type -= D_INDIR;
-			break;
-		}
-		if(a->type == D_EXTERN || a->type == D_STATIC ||
-		   a->type == D_AUTO || a->type == D_PARAM)
-			if(a->index == D_NONE) {
-				a->index = a->type;
-				a->type = D_ADDR;
-				break;
-			}
-		goto bad;
-
-	case OADD:
-		if(n->right->op == OCONST) {
-			v = n->right->vconst;
-			naddr(n->left, a);
-		} else
-		if(n->left->op == OCONST) {
-			v = n->left->vconst;
-			naddr(n->right, a);
-		} else
-			goto bad;
-		a->offset += v;
-		break;
-
-	}
-}
-
-void
-gcmp(int op, Node *n, int64_t val)
-{
-	Node *cn, nod;
-
-	cn = nodgconst(val, n->type);
-	if(!immconst(cn)){
-		regalloc(&nod, n, Z);
-		gmove(cn, &nod);
-		gopcode(op, n->type, n, &nod);
-		regfree(&nod);
-	}else
-		gopcode(op, n->type, n, cn);
-}
-
-#define	CASE(a,b)	((a<<8)|(b<<0))
-
-void
-gmove(Node *f, Node *t)
-{
-	int ft, tt, t64, a;
-	Node nod, nod1, nod2, nod3;
-	Prog *p1, *p2;
-
-	ft = f->type->etype;
-	tt = t->type->etype;
-	t64 = tt == TVLONG || tt == TUVLONG || tt == TIND;
-	if(debug['M'])
-		print("gop: %O %O[%s],%O[%s]\n", OAS,
-			f->op, tnames[ft], t->op, tnames[tt]);
-	if(typefd[ft] && f->op == OCONST) {
-		/* TO DO: pick up special constants, possibly preloaded */
-		if(f->fconst == 0.0){
-			regalloc(&nod, t, t);
-			gins(AXORPD, &nod, &nod);
-			gmove(&nod, t);
-			regfree(&nod);
-			return;
-		}
-	}
-/*
- * load
- */
-	if(f->op == ONAME || f->op == OINDREG ||
-	   f->op == OIND || f->op == OINDEX)
-	switch(ft) {
-	case TCHAR:
-		a = AMOVBLSX;
-		if(t64)
-			a = AMOVBQSX;
-		goto ld;
-	case TUCHAR:
-		a = AMOVBLZX;
-		if(t64)
-			a = AMOVBQZX;
-		goto ld;
-	case TSHORT:
-		a = AMOVWLSX;
-		if(t64)
-			a = AMOVWQSX;
-		goto ld;
-	case TUSHORT:
-		a = AMOVWLZX;
-		if(t64)
-			a = AMOVWQZX;
-		goto ld;
-	case TINT:
-	case TLONG:
-		if(typefd[tt]) {
-			regalloc(&nod, t, t);
-			if(tt == TDOUBLE)
-				a = ACVTSL2SD;
-			else
-				a = ACVTSL2SS;
-			gins(a, f, &nod);
-			gmove(&nod, t);
-			regfree(&nod);
-			return;
-		}
-		a = AMOVL;
-		if(t64)
-			a = AMOVLQSX;
-		goto ld;
-	case TUINT:
-	case TULONG:
-		a = AMOVL;
-		if(t64)
-			a = AMOVLQZX;	/* could probably use plain MOVL */
-		goto ld;
-	case TVLONG:
-		if(typefd[tt]) {
-			regalloc(&nod, t, t);
-			if(tt == TDOUBLE)
-				a = ACVTSQ2SD;
-			else
-				a = ACVTSQ2SS;
-			gins(a, f, &nod);
-			gmove(&nod, t);
-			regfree(&nod);
-			return;
-		}
-	case TUVLONG:
-		a = AMOVQ;
-		goto ld;
-	case TIND:
-		a = AMOVQ;
-
-	ld:
-		regalloc(&nod, f, t);
-		nod.type = t64? types[TVLONG]: types[TINT];
-		gins(a, f, &nod);
-		gmove(&nod, t);
-		regfree(&nod);
-		return;
-
-	case TFLOAT:
-		a = AMOVSS;
-		goto fld;
-	case TDOUBLE:
-		a = AMOVSD;
-	fld:
-		regalloc(&nod, f, t);
-		if(tt != TDOUBLE && tt != TFLOAT){	/* TO DO: why is this here */
-			prtree(f, "odd tree");
-			nod.type = t64? types[TVLONG]: types[TINT];
-		}
-		gins(a, f, &nod);
-		gmove(&nod, t);
-		regfree(&nod);
-		return;
-	}
-
-/*
- * store
- */
-	if(t->op == ONAME || t->op == OINDREG ||
-	   t->op == OIND || t->op == OINDEX)
-	switch(tt) {
-	case TCHAR:
-	case TUCHAR:
-		a = AMOVB;	goto st;
-	case TSHORT:
-	case TUSHORT:
-		a = AMOVW;	goto st;
-	case TINT:
-	case TUINT:
-	case TLONG:
-	case TULONG:
-		a = AMOVL;	goto st;
-	case TVLONG:
-	case TUVLONG:
-	case TIND:
-		a = AMOVQ;	goto st;
-
-	st:
-		if(f->op == OCONST) {
-			gins(a, f, t);
-			return;
-		}
-	fst:
-		regalloc(&nod, t, f);
-		gmove(f, &nod);
-		gins(a, &nod, t);
-		regfree(&nod);
-		return;
-
-	case TFLOAT:
-		a = AMOVSS;
-		goto fst;
-	case TDOUBLE:
-		a = AMOVSD;
-		goto fst;
-	}
-
-/*
- * convert
- */
-	switch(CASE(ft,tt)) {
-	default:
-/*
- * integer to integer
- ********
-		a = AGOK;	break;
-
-	case CASE(	TCHAR,	TCHAR):
-	case CASE(	TUCHAR,	TCHAR):
-	case CASE(	TSHORT,	TCHAR):
-	case CASE(	TUSHORT,TCHAR):
-	case CASE(	TINT,	TCHAR):
-	case CASE(	TUINT,	TCHAR):
-	case CASE(	TLONG,	TCHAR):
-	case CASE(	TULONG,	TCHAR):
-	case CASE(	TIND,	TCHAR):
-
-	case CASE(	TCHAR,	TUCHAR):
-	case CASE(	TUCHAR,	TUCHAR):
-	case CASE(	TSHORT,	TUCHAR):
-	case CASE(	TUSHORT,TUCHAR):
-	case CASE(	TINT,	TUCHAR):
-	case CASE(	TUINT,	TUCHAR):
-	case CASE(	TLONG,	TUCHAR):
-	case CASE(	TULONG,	TUCHAR):
-	case CASE(	TIND,	TUCHAR):
-
-	case CASE(	TSHORT,	TSHORT):
-	case CASE(	TUSHORT,TSHORT):
-	case CASE(	TINT,	TSHORT):
-	case CASE(	TUINT,	TSHORT):
-	case CASE(	TLONG,	TSHORT):
-	case CASE(	TULONG,	TSHORT):
-	case CASE(	TIND,	TSHORT):
-
-	case CASE(	TSHORT,	TUSHORT):
-	case CASE(	TUSHORT,TUSHORT):
-	case CASE(	TINT,	TUSHORT):
-	case CASE(	TUINT,	TUSHORT):
-	case CASE(	TLONG,	TUSHORT):
-	case CASE(	TULONG,	TUSHORT):
-	case CASE(	TIND,	TUSHORT):
-
-	case CASE(	TINT,	TINT):
-	case CASE(	TUINT,	TINT):
-	case CASE(	TLONG,	TINT):
-	case CASE(	TULONG,	TINT):
-	case CASE(	TIND,	TINT):
-
-	case CASE(	TINT,	TUINT):
-	case CASE(	TUINT,	TUINT):
-	case CASE(	TLONG,	TUINT):
-	case CASE(	TULONG,	TUINT):
-	case CASE(	TIND,	TUINT):
-
-	case CASE(	TUINT,	TIND):
-	case CASE(	TVLONG,	TUINT):
-	case CASE(	TVLONG,	TULONG):
-	case CASE(	TUVLONG, TUINT):
-	case CASE(	TUVLONG, TULONG):
- *****/
-		a = AMOVL;
-		break;
-
-	case CASE(	TVLONG,	TCHAR):
-	case	CASE(	TVLONG,	TSHORT):
-	case CASE(	TVLONG,	TINT):
-	case CASE(	TVLONG,	TLONG):
-	case CASE(	TUVLONG, TCHAR):
-	case	CASE(	TUVLONG, TSHORT):
-	case CASE(	TUVLONG, TINT):
-	case CASE(	TUVLONG, TLONG):
-	case CASE(	TINT,	TVLONG):
-	case CASE(	TINT,	TUVLONG):
-	case CASE(	TLONG,	TVLONG):
-	case CASE(	TINT,	TIND):
-	case CASE(	TLONG,	TIND):
-		a = AMOVLQSX;
-		if(f->op == OCONST) {
-			f->vconst &= (uint64_t)0xffffffffU;
-			if(f->vconst & 0x80000000)
-				f->vconst |= (int64_t)0xffffffff << 32;
-			a = AMOVQ;
-		}
-		break;
-
-	case CASE(	TUINT,	TIND):
-	case CASE(	TUINT,	TVLONG):
-	case CASE(	TUINT,	TUVLONG):
-	case CASE(	TULONG,	TVLONG):
-	case CASE(	TULONG,	TUVLONG):
-	case CASE(	TULONG,	TIND):
-		a = AMOVL;	/* same effect as AMOVLQZX */
-		if(f->op == OCONST) {
-			f->vconst &= (uint64_t)0xffffffffU;
-			a = AMOVQ;
-		}
-		break;
-
-	case CASE(	TIND,	TVLONG):
-	case CASE(	TVLONG,	TVLONG):
-	case CASE(	TUVLONG,	TVLONG):
-	case CASE(	TVLONG,	TUVLONG):
-	case CASE(	TUVLONG,	TUVLONG):
-	case CASE(	TIND,	TUVLONG):
-	case CASE(	TVLONG,	TIND):
-	case CASE(	TUVLONG,	TIND):
-	case CASE(	TIND,	TIND):
-		a = AMOVQ;
-		break;
-
-	case CASE(	TSHORT,	TINT):
-	case CASE(	TSHORT,	TUINT):
-	case CASE(	TSHORT,	TLONG):
-	case CASE(	TSHORT,	TULONG):
-		a = AMOVWLSX;
-		if(f->op == OCONST) {
-			f->vconst &= 0xffff;
-			if(f->vconst & 0x8000)
-				f->vconst |= 0xffff0000;
-			a = AMOVL;
-		}
-		break;
-
-	case CASE(	TSHORT,	TVLONG):
-	case CASE(	TSHORT,	TUVLONG):
-	case CASE(	TSHORT,	TIND):
-		a = AMOVWQSX;
-		if(f->op == OCONST) {
-			f->vconst &= 0xffff;
-			if(f->vconst & 0x8000){
-				f->vconst |= 0xffff0000;
-				f->vconst |= (int64_t)~0 << 32;
-			}
-			a = AMOVL;
-		}
-		break;
-
-	case CASE(	TUSHORT,TINT):
-	case CASE(	TUSHORT,TUINT):
-	case CASE(	TUSHORT,TLONG):
-	case CASE(	TUSHORT,TULONG):
-		a = AMOVWLZX;
-		if(f->op == OCONST) {
-			f->vconst &= 0xffff;
-			a = AMOVL;
-		}
-		break;
-
-	case CASE(	TUSHORT,TVLONG):
-	case CASE(	TUSHORT,TUVLONG):
-	case CASE(	TUSHORT,TIND):
-		a = AMOVWQZX;
-		if(f->op == OCONST) {
-			f->vconst &= 0xffff;
-			a = AMOVL;	/* MOVL also zero-extends to 64 bits */
-		}
-		break;
-
-	case CASE(	TCHAR,	TSHORT):
-	case CASE(	TCHAR,	TUSHORT):
-	case CASE(	TCHAR,	TINT):
-	case CASE(	TCHAR,	TUINT):
-	case CASE(	TCHAR,	TLONG):
-	case CASE(	TCHAR,	TULONG):
-		a = AMOVBLSX;
-		if(f->op == OCONST) {
-			f->vconst &= 0xff;
-			if(f->vconst & 0x80)
-				f->vconst |= 0xffffff00;
-			a = AMOVL;
-		}
-		break;
-
-	case CASE(	TCHAR,	TVLONG):
-	case CASE(	TCHAR,	TUVLONG):
-	case CASE(	TCHAR,	TIND):
-		a = AMOVBQSX;
-		if(f->op == OCONST) {
-			f->vconst &= 0xff;
-			if(f->vconst & 0x80){
-				f->vconst |= 0xffffff00;
-				f->vconst |= (int64_t)~0 << 32;
-			}
-			a = AMOVQ;
-		}
-		break;
-
-	case CASE(	TUCHAR,	TSHORT):
-	case CASE(	TUCHAR,	TUSHORT):
-	case CASE(	TUCHAR,	TINT):
-	case CASE(	TUCHAR,	TUINT):
-	case CASE(	TUCHAR,	TLONG):
-	case CASE(	TUCHAR,	TULONG):
-		a = AMOVBLZX;
-		if(f->op == OCONST) {
-			f->vconst &= 0xff;
-			a = AMOVL;
-		}
-		break;
-
-	case CASE(	TUCHAR,	TVLONG):
-	case CASE(	TUCHAR,	TUVLONG):
-	case CASE(	TUCHAR,	TIND):
-		a = AMOVBQZX;
-		if(f->op == OCONST) {
-			f->vconst &= 0xff;
-			a = AMOVL;	/* zero-extends to 64-bits */
-		}
-		break;
-
-/*
- * float to fix
- */
-	case CASE(	TFLOAT,	TCHAR):
-	case CASE(	TFLOAT,	TUCHAR):
-	case CASE(	TFLOAT,	TSHORT):
-	case CASE(	TFLOAT,	TUSHORT):
-	case CASE(	TFLOAT,	TINT):
-	case CASE(	TFLOAT,	TUINT):
-	case CASE(	TFLOAT,	TLONG):
-	case CASE(	TFLOAT,	TULONG):
-	case CASE(	TFLOAT,	TVLONG):
-	case CASE(	TFLOAT,	TUVLONG):
-	case CASE(	TFLOAT,	TIND):
-
-	case CASE(	TDOUBLE,TCHAR):
-	case CASE(	TDOUBLE,TUCHAR):
-	case CASE(	TDOUBLE,TSHORT):
-	case CASE(	TDOUBLE,TUSHORT):
-	case CASE(	TDOUBLE,TINT):
-	case CASE(	TDOUBLE,TUINT):
-	case CASE(	TDOUBLE,TLONG):
-	case CASE(	TDOUBLE,TULONG):
-	case CASE(	TDOUBLE,TVLONG):
-	case CASE(	TDOUBLE,TUVLONG):
-	case CASE(	TDOUBLE,TIND):
-		regalloc(&nod, t, Z);
-		if(ewidth[tt] == SZ_VLONG || typeu[tt] && ewidth[tt] == SZ_INT){
-			if(ft == TFLOAT)
-				a = ACVTTSS2SQ;
-			else
-				a = ACVTTSD2SQ;
-		}else{
-			if(ft == TFLOAT)
-				a = ACVTTSS2SL;
-			else
-				a = ACVTTSD2SL;
-		}
-		gins(a, f, &nod);
-		gmove(&nod, t);
-		regfree(&nod);
-		return;
-
-/*
- * ulong to float
- */
-	case CASE(	TUVLONG,	TDOUBLE):
-	case CASE(	TUVLONG,	TFLOAT):
-		a = ACVTSQ2SS;
-		if(tt == TDOUBLE)
-			a = ACVTSQ2SD;
-		regalloc(&nod, f, f);
-		gmove(f, &nod);
-		regalloc(&nod1, t, t);
-		gins(ACMPQ, &nod, nodconst(0));
-		gins(AJLT, Z, Z);
-		p1 = p;
-		gins(a, &nod, &nod1);
-		gins(AJMP, Z, Z);
-		p2 = p;
-		patch(p1, pc);
-		regalloc(&nod2, f, Z);
-		regalloc(&nod3, f, Z);
-		gmove(&nod, &nod2);
-		gins(ASHRQ, nodconst(1), &nod2);
-		gmove(&nod, &nod3);
-		gins(AANDL, nodconst(1), &nod3);
-		gins(AORQ, &nod3, &nod2);
-		gins(a, &nod2, &nod1);
-		gins(tt == TDOUBLE? AADDSD: AADDSS, &nod1, &nod1);
-		regfree(&nod2);
-		regfree(&nod3);
-		patch(p2, pc);
-		regfree(&nod);
-		regfree(&nod1);
-		return;
-
-	case CASE(	TULONG,	TDOUBLE):
-	case CASE(	TUINT,	TDOUBLE):
-	case CASE(	TULONG,	TFLOAT):
-	case CASE(	TUINT,	TFLOAT):
-		a = ACVTSQ2SS;
-		if(tt == TDOUBLE)
-			a = ACVTSQ2SD;
-		regalloc(&nod, f, f);
-		gins(AMOVLQZX, f, &nod);
-		regalloc(&nod1, t, t);
-		gins(a, &nod, &nod1);
-		gmove(&nod1, t);
-		regfree(&nod);
-		regfree(&nod1);
-		return;
-
-/*
- * fix to float
- */
-	case CASE(	TCHAR,	TFLOAT):
-	case CASE(	TUCHAR,	TFLOAT):
-	case CASE(	TSHORT,	TFLOAT):
-	case CASE(	TUSHORT,TFLOAT):
-	case CASE(	TINT,	TFLOAT):
-	case CASE(	TLONG,	TFLOAT):
-	case	CASE(	TVLONG,	TFLOAT):
-	case CASE(	TIND,	TFLOAT):
-
-	case CASE(	TCHAR,	TDOUBLE):
-	case CASE(	TUCHAR,	TDOUBLE):
-	case CASE(	TSHORT,	TDOUBLE):
-	case CASE(	TUSHORT,TDOUBLE):
-	case CASE(	TINT,	TDOUBLE):
-	case CASE(	TLONG,	TDOUBLE):
-	case CASE(	TVLONG,	TDOUBLE):
-	case CASE(	TIND,	TDOUBLE):
-		regalloc(&nod, t, t);
-		if(ewidth[ft] == SZ_VLONG){
-			if(tt == TFLOAT)
-				a = ACVTSQ2SS;
-			else
-				a = ACVTSQ2SD;
-		}else{
-			if(tt == TFLOAT)
-				a = ACVTSL2SS;
-			else
-				a = ACVTSL2SD;
-		}
-		gins(a, f, &nod);
-		gmove(&nod, t);
-		regfree(&nod);
-		return;
-
-/*
- * float to float
- */
-	case CASE(	TFLOAT,	TFLOAT):
-		a = AMOVSS;
-		break;
-	case CASE(	TDOUBLE,TFLOAT):
-		a = ACVTSD2SS;
-		break;
-	case CASE(	TFLOAT,	TDOUBLE):
-		a = ACVTSS2SD;
-		break;
-	case CASE(	TDOUBLE,TDOUBLE):
-		a = AMOVSD;
-		break;
-	}
-	if(a == AMOVQ || a == AMOVSD || a == AMOVSS || a == AMOVL && ewidth[ft] == ewidth[tt])	/* TO DO: check AMOVL */
-	if(samaddr(f, t))
-		return;
-	gins(a, f, t);
-}
-
-void
-doindex(Node *n)
-{
-	Node nod, nod1;
-	int32_t v;
-
-if(debug['Y'])
-prtree(n, "index");
-
-if(n->left->complex >= FNX)
-print("botch in doindex\n");
-
-	regalloc(&nod, &qregnode, Z);
-	v = constnode.vconst;
-	cgen(n->right, &nod);
-	idx.ptr = D_NONE;
-	if(n->left->op == OCONST)
-		idx.ptr = D_CONST;
-	else if(n->left->op == OREGISTER)
-		idx.ptr = n->left->reg;
-	else if(n->left->op != OADDR) {
-		reg[D_BP]++;	// cant be used as a base
-		regalloc(&nod1, &qregnode, Z);
-		cgen(n->left, &nod1);
-		idx.ptr = nod1.reg;
-		regfree(&nod1);
-		reg[D_BP]--;
-	}
-	idx.reg = nod.reg;
-	regfree(&nod);
-	constnode.vconst = v;
-}
-
-void
-gins(int a, Node *f, Node *t)
-{
-
-	if(f != Z && f->op == OINDEX)
-		doindex(f);
-	if(t != Z && t->op == OINDEX)
-		doindex(t);
-	nextpc();
-	p->as = a;
-	if(f != Z)
-		naddr(f, &p->from);
-	if(t != Z)
-		naddr(t, &p->to);
-	if(debug['g'])
-		print("%P\n", p);
-}
-
-void
-gopcode(int o, Type *ty, Node *f, Node *t)
-{
-	int a, et;
-
-	et = TLONG;
-	if(ty != T)
-		et = ty->etype;
-	if(debug['M']) {
-		if(f != Z && f->type != T)
-			print("gop: %O %O[%s],", o, f->op, tnames[et]);
-		else
-			print("gop: %O Z,", o);
-		if(t != Z && t->type != T)
-			print("%O[%s]\n", t->op, tnames[t->type->etype]);
-		else
-			print("Z\n");
-	}
-	a = AGOK;
-	switch(o) {
-	case OCOM:
-		a = ANOTL;
-		if(et == TCHAR || et == TUCHAR)
-			a = ANOTB;
-		if(et == TSHORT || et == TUSHORT)
-			a = ANOTW;
-		if(et == TVLONG || et == TUVLONG || et == TIND)
-			a = ANOTQ;
-		break;
-
-	case ONEG:
-		a = ANEGL;
-		if(et == TCHAR || et == TUCHAR)
-			a = ANEGB;
-		if(et == TSHORT || et == TUSHORT)
-			a = ANEGW;
-		if(et == TVLONG || et == TUVLONG || et == TIND)
-			a = ANEGQ;
-		break;
-
-	case OADDR:
-		a = ALEAQ;
-		break;
-
-	case OASADD:
-	case OADD:
-		a = AADDL;
-		if(et == TCHAR || et == TUCHAR)
-			a = AADDB;
-		if(et == TSHORT || et == TUSHORT)
-			a = AADDW;
-		if(et == TVLONG || et == TUVLONG || et == TIND)
-			a = AADDQ;
-		if(et == TFLOAT)
-			a = AADDSS;
-		if(et == TDOUBLE)
-			a = AADDSD;
-		break;
-
-	case OASSUB:
-	case OSUB:
-		a = ASUBL;
-		if(et == TCHAR || et == TUCHAR)
-			a = ASUBB;
-		if(et == TSHORT || et == TUSHORT)
-			a = ASUBW;
-		if(et == TVLONG || et == TUVLONG || et == TIND)
-			a = ASUBQ;
-		if(et == TFLOAT)
-			a = ASUBSS;
-		if(et == TDOUBLE)
-			a = ASUBSD;
-		break;
-
-	case OASOR:
-	case OOR:
-		a = AORL;
-		if(et == TCHAR || et == TUCHAR)
-			a = AORB;
-		if(et == TSHORT || et == TUSHORT)
-			a = AORW;
-		if(et == TVLONG || et == TUVLONG || et == TIND)
-			a = AORQ;
-		break;
-
-	case OASAND:
-	case OAND:
-		a = AANDL;
-		if(et == TCHAR || et == TUCHAR)
-			a = AANDB;
-		if(et == TSHORT || et == TUSHORT)
-			a = AANDW;
-		if(et == TVLONG || et == TUVLONG || et == TIND)
-			a = AANDQ;
-		break;
-
-	case OASXOR:
-	case OXOR:
-		a = AXORL;
-		if(et == TCHAR || et == TUCHAR)
-			a = AXORB;
-		if(et == TSHORT || et == TUSHORT)
-			a = AXORW;
-		if(et == TVLONG || et == TUVLONG || et == TIND)
-			a = AXORQ;
-		break;
-
-	case OASLSHR:
-	case OLSHR:
-		a = ASHRL;
-		if(et == TCHAR || et == TUCHAR)
-			a = ASHRB;
-		if(et == TSHORT || et == TUSHORT)
-			a = ASHRW;
-		if(et == TVLONG || et == TUVLONG || et == TIND)
-			a = ASHRQ;
-		break;
-
-	case OASASHR:
-	case OASHR:
-		a = ASARL;
-		if(et == TCHAR || et == TUCHAR)
-			a = ASARB;
-		if(et == TSHORT || et == TUSHORT)
-			a = ASARW;
-		if(et == TVLONG || et == TUVLONG || et == TIND)
-			a = ASARQ;
-		break;
-
-	case OASASHL:
-	case OASHL:
-		a = ASALL;
-		if(et == TCHAR || et == TUCHAR)
-			a = ASALB;
-		if(et == TSHORT || et == TUSHORT)
-			a = ASALW;
-		if(et == TVLONG || et == TUVLONG || et == TIND)
-			a = ASALQ;
-		break;
-
-	case OFUNC:
-		a = ACALL;
-		break;
-
-	case OASMUL:
-	case OMUL:
-		if(f->op == OREGISTER && t != Z && isreg(t, D_AX) && reg[D_DX] == 0)
-			t = Z;
-		a = AIMULL;
-		if(et == TVLONG || et == TUVLONG || et == TIND)
-			a = AIMULQ;
-		if(et == TFLOAT)
-			a = AMULSS;
-		if(et == TDOUBLE)
-			a = AMULSD;
-		break;
-
-	case OASMOD:
-	case OMOD:
-	case OASDIV:
-	case ODIV:
-		a = AIDIVL;
-		if(et == TVLONG || et == TUVLONG || et == TIND)
-			a = AIDIVQ;
-		if(et == TFLOAT)
-			a = ADIVSS;
-		if(et == TDOUBLE)
-			a = ADIVSD;
-		break;
-
-	case OASLMUL:
-	case OLMUL:
-		a = AMULL;
-		if(et == TVLONG || et == TUVLONG || et == TIND)
-			a = AMULQ;
-		break;
-
-	case OASLMOD:
-	case OLMOD:
-	case OASLDIV:
-	case OLDIV:
-		a = ADIVL;
-		if(et == TVLONG || et == TUVLONG || et == TIND)
-			a = ADIVQ;
-		break;
-
-	case OEQ:
-	case ONE:
-	case OLT:
-	case OLE:
-	case OGE:
-	case OGT:
-	case OLO:
-	case OLS:
-	case OHS:
-	case OHI:
-		a = ACMPL;
-		if(et == TCHAR || et == TUCHAR)
-			a = ACMPB;
-		if(et == TSHORT || et == TUSHORT)
-			a = ACMPW;
-		if(et == TVLONG || et == TUVLONG || et == TIND)
-			a = ACMPQ;
-		if(et == TFLOAT)
-			a = AUCOMISS;
-		if(et == TDOUBLE)
-			a = AUCOMISD;
-		gins(a, f, t);
-		switch(o) {
-		case OEQ:	a = AJEQ; break;
-		case ONE:	a = AJNE; break;
-		case OLT:	a = AJLT; break;
-		case OLE:	a = AJLE; break;
-		case OGE:	a = AJGE; break;
-		case OGT:	a = AJGT; break;
-		case OLO:	a = AJCS; break;
-		case OLS:	a = AJLS; break;
-		case OHS:	a = AJCC; break;
-		case OHI:	a = AJHI; break;
-		}
-		gins(a, Z, Z);
-		return;
-	}
-	if(a == AGOK)
-		diag(Z, "bad in gopcode %O", o);
-	gins(a, f, t);
-}
-
-int
-samaddr(Node *f, Node *t)
-{
-	return f->op == OREGISTER && t->op == OREGISTER && f->reg == t->reg;
-}
-
-void
-gbranch(int o)
-{
-	int a;
-
-	a = AGOK;
-	switch(o) {
-	case ORETURN:
-		a = ARET;
-		break;
-	case OGOTO:
-		a = AJMP;
-		break;
-	}
-	nextpc();
-	if(a == AGOK) {
-		diag(Z, "bad in gbranch %O",  o);
-		nextpc();
-	}
-	p->as = a;
-}
-
-void
-patch(Prog *op, int32_t pc)
-{
-
-	op->to.offset = pc;
-	op->to.type = D_BRANCH;
-}
-
-void
-gpseudo(int a, Sym *s, Node *n)
-{
-
-	nextpc();
-	p->as = a;
-	p->from.type = D_EXTERN;
-	p->from.sym = s;
-	p->from.scale = (profileflg ? 0 : NOPROF);
-	if(s->class == CSTATIC)
-		p->from.type = D_STATIC;
-	naddr(n, &p->to);
-	if(a == ADATA || a == AGLOBL)
-		pc--;
-}
-
-int
-sconst(Node *n)
-{
-	int32_t v;
-
-	if(n->op == OCONST && !typefd[n->type->etype]) {
-		v = n->vconst;
-		if(v >= -32766L && v < 32766L)
-			return 1;
-	}
-	return 0;
-}
-
-int32_t
-exreg(Type *t)
-{
-	int32_t o;
-
-	if(typechlpv[t->etype]) {
-		if(exregoffset <= REGEXT-4)
-			return 0;
-		o = exregoffset;
-		exregoffset--;
-		return o;
-	}
-	return 0;
-}
-
-schar	ewidth[NTYPE] =
-{
-	-1,		/*[TXXX]*/	
-	SZ_CHAR,	/*[TCHAR]*/	
-	SZ_CHAR,	/*[TUCHAR]*/
-	SZ_SHORT,	/*[TSHORT]*/
-	SZ_SHORT,	/*[TUSHORT]*/
-	SZ_INT,		/*[TINT]*/
-	SZ_INT,		/*[TUINT]*/
-	SZ_LONG,	/*[TLONG]*/
-	SZ_LONG,	/*[TULONG]*/
-	SZ_VLONG,	/*[TVLONG]*/
-	SZ_VLONG,	/*[TUVLONG]*/
-	SZ_FLOAT,	/*[TFLOAT]*/
-	SZ_DOUBLE,	/*[TDOUBLE]*/
-	SZ_IND,		/*[TIND]*/
-	0,		/*[TFUNC]*/
-	-1,		/*[TARRAY]*/
-	0,		/*[TVOID]*/
-	-1,		/*[TSTRUCT]*/
-	-1,		/*[TUNION]*/
-	SZ_INT,		/*[TENUM]*/
-};
-int32_t	ncast[NTYPE] =
-{
-	0,				/*[TXXX]*/
-	BCHAR|BUCHAR,			/*[TCHAR]*/
-	BCHAR|BUCHAR,			/*[TUCHAR]*/	
-	BSHORT|BUSHORT,			/*[TSHORT]*/
-	BSHORT|BUSHORT,			/*[TUSHORT]*/
-	BINT|BUINT|BLONG|BULONG,	/*[TINT]*/		
-	BINT|BUINT|BLONG|BULONG,	/*[TUINT]*/
-	BINT|BUINT|BLONG|BULONG,	/*[TLONG]*/
-	BINT|BUINT|BLONG|BULONG,	/*[TULONG]*/
-	BVLONG|BUVLONG|BIND,			/*[TVLONG]*/
-	BVLONG|BUVLONG|BIND,			/*[TUVLONG]*/
-	BFLOAT,				/*[TFLOAT]*/
-	BDOUBLE,			/*[TDOUBLE]*/
-	BVLONG|BUVLONG|BIND,		/*[TIND]*/
-	0,				/*[TFUNC]*/
-	0,				/*[TARRAY]*/
-	0,				/*[TVOID]*/
-	BSTRUCT,			/*[TSTRUCT]*/
-	BUNION,				/*[TUNION]*/
-	0,				/*[TENUM]*/
-};

+ 0 - 422
sys/src/cmd/6l/asm.c

@@ -1,422 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include	"l.h"
-
-#define	Dbufslop	100
-
-#define PADDR(a)	((a) & ~0xfffffffff0000000ull)
-
-int64_t
-entryvalue(void)
-{
-	char *a;
-	Sym *s;
-
-	a = INITENTRY;
-	if(*a >= '0' && *a <= '9')
-		return atolwhex(a);
-	s = lookup(a, 0);
-	if(s->type == 0)
-		return INITTEXT;
-	switch(s->type) {
-	case STEXT:
-		break;
-	case SDATA:
-		if(dlm)
-			return s->value+INITDAT;
-	default:
-		diag("entry not text: %s", s->name);
-	}
-	return s->value;
-}
-
-/* these need to take long arguments to be compatible with elf.c */void
-wputl(int32_t w)
-{
-	cput(w);
-	cput(w>>8);
-}
-
-void
-wput(int32_t w)
-{
-	cput(w>>8);
-	cput(w);
-}
-
-void
-lput(int32_t l)
-{
-	cput(l>>24);
-	cput(l>>16);
-	cput(l>>8);
-	cput(l);
-}
-
-void
-llput(int64_t v)
-{
-	lput(v>>32);
-	lput(v);
-}
-
-void
-lputl(int32_t l)
-{
-	cput(l);
-	cput(l>>8);
-	cput(l>>16);
-	cput(l>>24);
-}
-
-void
-llputl(int64_t v)
-{
-	lputl(v);
-	lputl(v>>32);
-}
-
-void
-strnput(char *s, int n)
-{
-	for(; *s && n > 0; s++){
-		cput(*s);
-		n--;
-	}
-	while(n > 0){
-		cput(0);
-		n--;
-	}
-}
-
-void
-asmb(void)
-{
-	Prog *p;
-	int32_t v, magic;
-	int a;
-	uint8_t *op1;
-	int64_t vl;
-
-	if(debug['v'])
-		Bprint(&bso, "%5.2f asmb\n", cputime());
-	Bflush(&bso);
-
-	seek(cout, HEADR, 0);
-	pc = INITTEXT;
-	curp = firstp;
-	for(p = firstp; p != P; p = p->link) {
-		if(p->as == ATEXT)
-			curtext = p;
-		if(p->pc != pc) {
-			if(!debug['a'])
-				print("%P\n", curp);
-			diag("phase error %llux sb %llux in %s", p->pc, pc, TNAME);
-			pc = p->pc;
-		}
-		curp = p;
-		asmins(p);
-		a = (andptr - and);
-		if(cbc < a)
-			cflush();
-		if(debug['a']) {
-			Bprint(&bso, pcstr, pc);
-			for(op1 = and; op1 < andptr; op1++)
-				Bprint(&bso, "%.2ux", *op1 & 0xff);
-			Bprint(&bso, "\t%P\n", curp);
-		}
-		if(dlm) {
-			if(p->as == ATEXT)
-				reloca = nil;
-			else if(reloca != nil)
-				diag("reloc failure: %P", curp);
-		}
-		memmove(cbp, and, a);
-		cbp += a;
-		pc += a;
-		cbc -= a;
-	}
-	cflush();
-	switch(HEADTYPE) {
-	default:
-		diag("unknown header type %ld", HEADTYPE);
-	case 2:
-	case 5:
-	case 6:
-		seek(cout, HEADR+textsize, 0);
-		break;
-	}
-
-	if(debug['v'])
-		Bprint(&bso, "%5.2f datblk\n", cputime());
-	Bflush(&bso);
-
-	if(dlm){
-		char buf[8];
-
-		write(cout, buf, INITDAT-textsize);
-		textsize = INITDAT;
-	}
-
-	for(v = 0; v < datsize; v += sizeof(buf)-Dbufslop) {
-		if(datsize-v > sizeof(buf)-Dbufslop)
-			datblk(v, sizeof(buf)-Dbufslop);
-		else
-			datblk(v, datsize-v);
-	}
-
-	symsize = 0;
-	spsize = 0;
-	lcsize = 0;
-	if(!debug['s']) {
-		if(debug['v'])
-			Bprint(&bso, "%5.2f sym\n", cputime());
-		Bflush(&bso);
-		switch(HEADTYPE) {
-		default:
-		case 2:
-		case 5:
-		case 6:
-			seek(cout, HEADR+textsize+datsize, 0);
-			break;
-		}
-		if(!debug['s'])
-			asmsym();
-		if(debug['v'])
-			Bprint(&bso, "%5.2f sp\n", cputime());
-		Bflush(&bso);
-		if(debug['v'])
-			Bprint(&bso, "%5.2f pc\n", cputime());
-		Bflush(&bso);
-		if(!debug['s'])
-			asmlc();
-		if(dlm)
-			asmdyn();
-		cflush();
-	}
-	else if(dlm){
-		seek(cout, HEADR+textsize+datsize, 0);
-		asmdyn();
-		cflush();
-	}
-	if(debug['v'])
-		Bprint(&bso, "%5.2f headr\n", cputime());
-	Bflush(&bso);
-	seek(cout, 0L, 0);
-	switch(HEADTYPE) {
-	default:
-	case 2:	/* plan9 */
-		magic = 4*26*26+7;
-		magic |= 0x00008000;		/* fat header */
-		if(dlm)
-			magic |= 0x80000000;	/* dlm */
-		lput(magic);			/* magic */
-		lput(textsize);			/* sizes */
-		lput(datsize);
-		lput(bsssize);
-		lput(symsize);			/* nsyms */
-		vl = entryvalue();
-		lput(PADDR(vl));		/* va of entry */
-		lput(spsize);			/* sp offsets */
-		lput(lcsize);			/* line offsets */
-		llput(vl);			/* va of entry */
-		break;
-	case 5:
-		elf32(debug['8']? I386: AMD64, ELFDATA2LSB, 0, nil);
-		break;
-	case 6:
-		elf64(AMD64, ELFDATA2LSB, 0, nil);
-		break;
-	}
-	cflush();
-}
-
-void
-cflush(void)
-{
-	int n;
-
-	n = sizeof(buf.cbuf) - cbc;
-	if(n)
-		write(cout, buf.cbuf, n);
-	cbp = buf.cbuf;
-	cbc = sizeof(buf.cbuf);
-}
-
-void
-datblk(int32_t s, int32_t n)
-{
-	Prog *p;
-	uint8_t *cast;
-	int32_t l, fl, j;
-	int64_t o;
-	int i, c;
-
-	memset(buf.dbuf, 0, n+Dbufslop);
-	for(p = datap; p != P; p = p->link) {
-		curp = p;
-		l = p->from.sym->value + p->from.offset - s;
-		c = p->from.scale;
-		i = 0;
-		if(l < 0) {
-			if(l+c <= 0)
-				continue;
-			while(l < 0) {
-				l++;
-				i++;
-			}
-		}
-		if(l >= n)
-			continue;
-		if(p->as != AINIT && p->as != ADYNT) {
-			for(j=l+(c-i)-1; j>=l; j--)
-				if(buf.dbuf[j]) {
-					print("%P\n", p);
-					diag("multiple initialization");
-					break;
-				}
-		}
-		switch(p->to.type) {
-		case D_FCONST:
-			switch(c) {
-			default:
-			case 4:
-				fl = ieeedtof(&p->to.ieee);
-				cast = (uint8_t*)&fl;
-				if(debug['a'] && i == 0) {
-					Bprint(&bso, pcstr, l+s+INITDAT);
-					for(j=0; j<c; j++)
-						Bprint(&bso, "%.2ux", cast[fnuxi4[j]]);
-					Bprint(&bso, "\t%P\n", curp);
-				}
-				for(; i<c; i++) {
-					buf.dbuf[l] = cast[fnuxi4[i]];
-					l++;
-				}
-				break;
-			case 8:
-				cast = (uint8_t*)&p->to.ieee;
-				if(debug['a'] && i == 0) {
-					Bprint(&bso, pcstr, l+s+INITDAT);
-					for(j=0; j<c; j++)
-						Bprint(&bso, "%.2ux", cast[fnuxi8[j]]);
-					Bprint(&bso, "\t%P\n", curp);
-				}
-				for(; i<c; i++) {
-					buf.dbuf[l] = cast[fnuxi8[i]];
-					l++;
-				}
-				break;
-			}
-			break;
-
-		case D_SCONST:
-			if(debug['a'] && i == 0) {
-				Bprint(&bso, pcstr, l+s+INITDAT);
-				for(j=0; j<c; j++)
-					Bprint(&bso, "%.2ux", p->to.scon[j] & 0xff);
-				Bprint(&bso, "\t%P\n", curp);
-			}
-			for(; i<c; i++) {
-				buf.dbuf[l] = p->to.scon[i];
-				l++;
-			}
-			break;
-		default:
-			o = p->to.offset;
-			if(p->to.type == D_ADDR) {
-				if(p->to.index != D_STATIC && p->to.index != D_EXTERN)
-					diag("DADDR type%P", p);
-				if(p->to.sym) {
-					if(p->to.sym->type == SUNDEF)
-						ckoff(p->to.sym, o);
-					o += p->to.sym->value;
-					if(p->to.sym->type != STEXT && p->to.sym->type != SUNDEF)
-						o += INITDAT;
-					if(dlm)
-						dynreloc(p->to.sym, l+s+INITDAT, 1);
-				}
-			}
-			fl = o;
-			cast = (uint8_t*)&fl;
-			switch(c) {
-			default:
-				diag("bad nuxi %d %d\n%P", c, i, curp);
-				break;
-			case 1:
-				if(debug['a'] && i == 0) {
-					Bprint(&bso, pcstr, l+s+INITDAT);
-					for(j=0; j<c; j++)
-						Bprint(&bso, "%.2ux", cast[inuxi1[j]]);
-					Bprint(&bso, "\t%P\n", curp);
-				}
-				for(; i<c; i++) {
-					buf.dbuf[l] = cast[inuxi1[i]];
-					l++;
-				}
-				break;
-			case 2:
-				if(debug['a'] && i == 0) {
-					Bprint(&bso, pcstr, l+s+INITDAT);
-					for(j=0; j<c; j++)
-						Bprint(&bso, "%.2ux", cast[inuxi2[j]]);
-					Bprint(&bso, "\t%P\n", curp);
-				}
-				for(; i<c; i++) {
-					buf.dbuf[l] = cast[inuxi2[i]];
-					l++;
-				}
-				break;
-			case 4:
-				if(debug['a'] && i == 0) {
-					Bprint(&bso, pcstr, l+s+INITDAT);
-					for(j=0; j<c; j++)
-						Bprint(&bso, "%.2ux", cast[inuxi4[j]]);
-					Bprint(&bso, "\t%P\n", curp);
-				}
-				for(; i<c; i++) {
-					buf.dbuf[l] = cast[inuxi4[i]];
-					l++;
-				}
-				break;
-			case 8:
-				cast = (uint8_t*)&o;
-				if(debug['a'] && i == 0) {
-					Bprint(&bso, pcstr, l+s+INITDAT);
-					for(j=0; j<c; j++)
-						Bprint(&bso, "%.2ux", cast[inuxi8[j]]);
-					Bprint(&bso, "\t%P\n", curp);
-				}
-				for(; i<c; i++) {
-					buf.dbuf[l] = cast[inuxi8[i]];
-					l++;
-				}
-				break;
-			}
-			break;
-		}
-	}
-	write(cout, buf.dbuf, n);
-}
-
-int64_t
-rnd(int64_t v, int64_t r)
-{
-	int64_t c;
-
-	if(r <= 0)
-		return v;
-	v += r - 1;
-	c = v % r;
-	if(c < 0)
-		c += r;
-	v -= c;
-	return v;
-}

+ 0 - 73
sys/src/cmd/6l/compat.c

@@ -1,73 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include	"l.h"
-
-/*
- * fake malloc
- */
-void*
-malloc(uint32_t n)
-{
-	void *p;
-
-	while(n & 7)
-		n++;
-	while(nhunk < n)
-		gethunk();
-	p = hunk;
-	nhunk -= n;
-	hunk += n;
-	return p;
-}
-
-void
-free(void *p)
-{
-	USED(p);
-}
-
-void*
-calloc(uint32_t m, uint32_t n)
-{
-	void *p;
-
-	n *= m;
-	p = malloc(n);
-	memset(p, 0, n);
-	return p;
-}
-
-void*
-realloc(void*, uint32_t)
-{
-	fprint(2, "realloc called\n");
-	abort();
-	return 0;
-}
-
-void*
-mysbrk(uint32_t size)
-{
-	return sbrk(size);
-}
-
-void
-setmalloctag(void*, uint32_t)
-{
-}
-
-int
-fileexists(char *s)
-{
-	uint8_t dirbuf[400];
-
-	/* it's fine if stat result doesn't fit in dirbuf, since even then the file exists */
-	return stat(s, dirbuf, sizeof(dirbuf)) >= 0;
-}

+ 0 - 410
sys/src/cmd/6l/l.h

@@ -1,410 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include	<u.h>
-#include	<libc.h>
-#include	<bio.h>
-#include	"../6c/6.out.h"
-#include	"../8l/elf.h"
-
-#ifndef	EXTERN
-#define	EXTERN	extern
-#endif
-
-#define	P		((Prog*)0)
-#define	S		((Sym*)0)
-#define	TNAME		(curtext?curtext->from.sym->name:noname)
-#define	cput(c)\
-	{ *cbp++ = c;\
-	if(--cbc <= 0)\
-		cflush(); }
-
-#define	LIBNAMELEN	300
-
-typedef	struct	Adr	Adr;
-typedef	struct	Prog	Prog;
-typedef	struct	Sym	Sym;
-typedef	struct	Auto	Auto;
-typedef	struct	Optab	Optab;
-typedef	struct	Movtab	Movtab;
-
-struct	Adr
-{
-	union
-	{
-		vlong	u0offset;
-		char	u0scon[8];
-		Prog	*u0cond;	/* not used, but should be D_BRANCH */
-		Ieee	u0ieee;
-	} u0;
-	union
-	{
-		Auto*	u1autom;
-		Sym*	u1sym;
-	} u1;
-	short	type;
-	char	index;
-	char	scale;
-};
-
-#define	offset	u0.u0offset
-#define	scon	u0.u0scon
-#define	cond	u0.u0cond
-#define	ieee	u0.u0ieee
-
-#define	autom	u1.u1autom
-#define	sym	u1.u1sym
-
-struct	Prog
-{
-	Adr	from;
-	Adr	to;
-	Prog	*forwd;
-	Prog*	link;
-	Prog*	pcond;	/* work on this */
-	vlong	pc;
-	long	line;
-	uchar	mark;	/* work on these */
-	uchar	back;
-
-	short	as;
-	char	width;		/* fake for DATA */
-	char	mode;	/* 16, 32, or 64 */
-};
-struct	Auto
-{
-	Sym*	asym;
-	Auto*	link;
-	long	aoffset;
-	short	type;
-};
-struct	Sym
-{
-	char	*name;
-	short	type;
-	short	version;
-	short	become;
-	short	frame;
-	uchar	subtype;
-	ushort	file;
-	vlong	value;
-	long	sig;
-	Sym*	link;
-};
-struct	Optab
-{
-	short	as;
-	uchar*	ytab;
-	uchar	prefix;
-	uchar	op[20];
-};
-struct	Movtab
-{
-	short	as;
-	uchar	ft;
-	uchar	tt;
-	uchar	code;
-	uchar	op[4];
-};
-
-enum
-{
-	STEXT		= 1,
-	SDATA,
-	SBSS,
-	SDATA1,
-	SXREF,
-	SFILE,
-	SCONST,
-	SUNDEF,
-
-	SIMPORT,
-	SEXPORT,
-
-	NHASH		= 10007,
-	NHUNK		= 100000,
-	MINSIZ		= 8,
-	STRINGSZ	= 200,
-	MINLC		= 1,
-	MAXIO		= 8192,
-	MAXHIST		= 20,				/* limit of path elements for history symbols */
-
-	Yxxx		= 0,
-	Ynone,
-	Yi0,
-	Yi1,
-	Yi8,
-	Ys32,
-	Yi32,
-	Yi64,
-	Yiauto,
-	Yal,
-	Ycl,
-	Yax,
-	Ycx,
-	Yrb,
-	Yrl,
-	Yrf,
-	Yf0,
-	Yrx,
-	Ymb,
-	Yml,
-	Ym,
-	Ybr,
-	Ycol,
-
-	Ycs,	Yss,	Yds,	Yes,	Yfs,	Ygs,
-	Ygdtr,	Yidtr,	Yldtr,	Ymsw,	Ytask,
-	Ycr0,	Ycr1,	Ycr2,	Ycr3,	Ycr4,	Ycr5,	Ycr6,	Ycr7,	Ycr8,
-	Ydr0,	Ydr1,	Ydr2,	Ydr3,	Ydr4,	Ydr5,	Ydr6,	Ydr7,
-	Ytr0,	Ytr1,	Ytr2,	Ytr3,	Ytr4,	Ytr5,	Ytr6,	Ytr7,	Yrl32,	Yrl64,
-	Ymr, Ymm,
-	Yxr, Yxm,
-	Ymax,
-
-	Zxxx		= 0,
-
-	Zlit,
-	Z_rp,
-	Zbr,
-	Zcall,
-	Zib_,
-	Zib_rp,
-	Zibo_m,
-	Zibo_m_xm,
-	Zil_,
-	Zil_rp,
-	Ziq_rp,
-	Zilo_m,
-	Ziqo_m,
-	Zjmp,
-	Zloop,
-	Zo_iw,
-	Zm_o,
-	Zm_r,
-	Zm_r_xm,
-	Zm_r_i_xm,
-	Zm_r_3d,
-	Zm_r_xm_nr,
-	Zr_m_xm_nr,
-	Zibm_r,	/* mmx1,mmx2/mem64,imm8 */
-	Zmb_r,
-	Zaut_r,
-	Zo_m,
-	Zo_m64,
-	Zpseudo,
-	Zr_m,
-	Zr_m_xm,
-	Zr_m_i_xm,
-	Zrp_,
-	Z_ib,
-	Z_il,
-	Zm_ibo,
-	Zm_ilo,
-	Zib_rr,
-	Zil_rr,
-	Zclr,
-	Zbyte,
-	Zmax,
-
-	Px		= 0,
-	P32		= 0x32,	/* 32-bit only */
-	Pe		= 0x66,	/* operand escape */
-	Pm		= 0x0f,	/* 2byte opcode escape */
-	Pq		= 0xff,	/* both escape */
-	Pb		= 0xfe,	/* byte operands */
-	Pf2		= 0xf2,	/* xmm escape 1 */
-	Pf3		= 0xf3,	/* xmm escape 2 */
-	Pw		= 0x48,	/* Rex.w */
-	Py		= 0x80,	/* defaults to 64-bit mode */
-
-	Rxf		= 1<<9,	/* internal flag for Rxr on from */
-	Rxt		= 1<<8,	/* internal flag for Rxr on to */
-	Rxw		= 1<<3,	/* =1, 64-bit operand size */
-	Rxr		= 1<<2,	/* extend modrm reg */
-	Rxx		= 1<<1,	/* extend sib index */
-	Rxb		= 1<<0,	/* extend modrm r/m, sib base, or opcode reg */
-
-	Roffset	= 22,		/* no. bits for offset in relocation address */
-	Rindex	= 10,		/* no. bits for index in relocation address */
-};
-
-EXTERN union
-{
-	struct
-	{
-		char	obuf[MAXIO];			/* output buffer */
-		uchar	ibuf[MAXIO];			/* input buffer */
-	} u;
-	char	dbuf[1];
-} buf;
-
-#define	cbuf	u.obuf
-#define	xbuf	u.ibuf
-
-#pragma	varargck	type	"A"	int
-#pragma	varargck	type	"A"	uint
-#pragma	varargck	type	"D"	Adr*
-#pragma	varargck	type	"P"	Prog*
-#pragma	varargck	type	"R"	int
-#pragma	varargck	type	"S"	char*
-
-#pragma	varargck	argpos	diag 1
-
-EXTERN	long	HEADR;
-EXTERN	long	HEADTYPE;
-EXTERN	vlong	INITDAT;
-EXTERN	long	INITRND;
-EXTERN	vlong	INITTEXT;
-EXTERN	vlong	INITTEXTP;
-EXTERN	char*	INITENTRY;		/* entry point */
-EXTERN	Biobuf	bso;
-EXTERN	long	bsssize;
-EXTERN	int	cbc;
-EXTERN	char*	cbp;
-EXTERN	char*	pcstr;
-EXTERN	int	cout;
-EXTERN	Auto*	curauto;
-EXTERN	Auto*	curhist;
-EXTERN	Prog*	curp;
-EXTERN	Prog*	curtext;
-EXTERN	Prog*	datap;
-EXTERN	Prog*	edatap;
-EXTERN	vlong	datsize;
-EXTERN	char	debug[128];
-EXTERN	char	literal[32];
-EXTERN	Prog*	etextp;
-EXTERN	Prog*	firstp;
-EXTERN	uchar	fnuxi8[8];
-EXTERN	uchar	fnuxi4[4];
-EXTERN	Sym*	hash[NHASH];
-EXTERN	Sym*	histfrog[MAXHIST];
-EXTERN	int	histfrogp;
-EXTERN	int	histgen;
-EXTERN	char*	library[50];
-EXTERN	char*	libraryobj[50];
-EXTERN	int	libraryp;
-EXTERN	int	xrefresolv;
-EXTERN	char*	hunk;
-EXTERN	uchar	inuxi1[1];
-EXTERN	uchar	inuxi2[2];
-EXTERN	uchar	inuxi4[4];
-EXTERN	uchar	inuxi8[8];
-EXTERN	char	ycover[Ymax*Ymax];
-EXTERN	uchar*	andptr;
-EXTERN	uchar*	rexptr;
-EXTERN	uchar	and[30];
-EXTERN	int	reg[D_NONE];
-EXTERN	int	regrex[D_NONE+1];
-EXTERN	Prog*	lastp;
-EXTERN	long	lcsize;
-EXTERN	int	nerrors;
-EXTERN	long	nhunk;
-EXTERN	long	nsymbol;
-EXTERN	char*	noname;
-EXTERN	char*	outfile;
-EXTERN	vlong	pc;
-EXTERN	long	spsize;
-EXTERN	Sym*	symlist;
-EXTERN	long	symsize;
-EXTERN	Prog*	textp;
-EXTERN	vlong	textsize;
-EXTERN	long	thunk;
-EXTERN	int	version;
-EXTERN	Prog	zprg;
-EXTERN	int	dtype;
-EXTERN	char*	paramspace;
-
-EXTERN	Adr*	reloca;
-EXTERN	int	doexp, dlm;
-EXTERN	int	imports, nimports;
-EXTERN	int	exports, nexports;
-EXTERN	char*	EXPTAB;
-EXTERN	Prog	undefp;
-
-#define	UP	(&undefp)
-
-extern	Optab	optab[];
-extern	Optab*	opindex[];
-extern	char*	anames[];
-
-int	Aconv(Fmt*);
-int	Dconv(Fmt*);
-int	Pconv(Fmt*);
-int	Rconv(Fmt*);
-int	Sconv(Fmt*);
-void	addhist(long, int);
-void	addlibpath(char*);
-Prog*	appendp(Prog*);
-void	asmb(void);
-void	asmdyn(void);
-void	asmins(Prog*);
-void	asmlc(void);
-void	asmsp(void);
-void	asmsym(void);
-vlong	atolwhex(char*);
-Prog*	brchain(Prog*);
-Prog*	brloop(Prog*);
-void	buildop(void);
-void	cflush(void);
-void	ckoff(Sym*, long);
-Prog*	copyp(Prog*);
-double	cputime(void);
-void	datblk(long, long);
-void	diag(char*, ...);
-void	dodata(void);
-void	doinit(void);
-void	doprof1(void);
-void	doprof2(void);
-void	dostkoff(void);
-void	dynreloc(Sym*, uint32_t, int);
-vlong	entryvalue(void);
-void	errorexit(void);
-void	export(void);
-int	fileexists(char*);
-int	find1(long, int);
-int	find2(long, int);
-char*	findlib(char*);
-void	follow(void);
-void	gethunk(void);
-void	histtoauto(void);
-double	ieeedtod(Ieee*);
-long	ieeedtof(Ieee*);
-void	import(void);
-void	ldobj(int, long, char*);
-void	loadlib(void);
-void	listinit(void);
-Sym*	lookup(char*, int);
-void	llput(vlong v);
-void	llputl(vlong v);
-void	lput(long);
-void	lputl(long);
-void	main(int, char*[]);
-void	mkfwd(void);
-void*	mysbrk(uint32_t);
-void	nuxiinit(void);
-void	objfile(char*);
-int	opsize(Prog*);
-void	patch(void);
-Prog*	prg(void);
-void	readundefs(char*, int);
-int	relinv(int);
-long	reuse(Prog*, Sym*);
-vlong	rnd(vlong, vlong);
-void	span(void);
-void	strnput(char*, int);
-void	undef(void);
-void	undefsym(Sym*);
-vlong	vaddr(Adr*);
-void	wput(long);
-void	wputl(long);
-void	xdefine(char*, int, vlong);
-void	xfol(Prog*);
-int	zaddr(uchar*, Adr*, Sym*[]);
-void	zerosig(char*);

+ 0 - 359
sys/src/cmd/6l/list.c

@@ -1,359 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include	"l.h"
-
-void
-listinit(void)
-{
-
-	fmtinstall('R', Rconv);
-	fmtinstall('A', Aconv);
-	fmtinstall('D', Dconv);
-	fmtinstall('S', Sconv);
-	fmtinstall('P', Pconv);
-}
-
-static	Prog	*bigP;
-
-int
-Pconv(Fmt *fp)
-{
-	char str[STRINGSZ];
-	Prog *p;
-
-	p = va_arg(fp->args, Prog*);
-	bigP = p;
-	switch(p->as) {
-	case ATEXT:
-		if(p->from.scale) {
-			sprint(str, "(%ld)	%A	%D,%d,%D",
-				p->line, p->as, &p->from, p->from.scale, &p->to);
-			break;
-		}
-	default:
-		sprint(str, "(%ld)	%A	%D,%D",
-			p->line, p->as, &p->from, &p->to);
-		break;
-	case ADATA:
-	case AINIT:
-	case ADYNT:
-		sprint(str, "(%ld)	%A	%D/%d,%D",
-			p->line, p->as, &p->from, p->from.scale, &p->to);
-		break;
-	}
-	bigP = P;
-	return fmtstrcpy(fp, str);
-}
-
-int
-Aconv(Fmt *fp)
-{
-	int i;
-
-	i = va_arg(fp->args, int);
-	return fmtstrcpy(fp, anames[i]);
-}
-
-int
-Dconv(Fmt *fp)
-{
-	char str[40], s[20];
-	Adr *a;
-	int i;
-
-	a = va_arg(fp->args, Adr*);
-	i = a->type;
-	if(i >= D_INDIR) {
-		if(a->offset)
-			sprint(str, "%lld(%R)", a->offset, i-D_INDIR);
-		else
-			sprint(str, "(%R)", i-D_INDIR);
-		goto brk;
-	}
-	switch(i) {
-
-	default:
-		if(a->offset)
-			sprint(str, "$%lld,%R", a->offset, i);
-		else
-			sprint(str, "%R", i);
-		break;
-
-	case D_NONE:
-		str[0] = 0;
-		break;
-
-	case D_BRANCH:
-		if(bigP != P && bigP->pcond != P)
-			if(a->sym != S)
-				sprint(str, "%llux+%s", bigP->pcond->pc,
-					a->sym->name);
-			else
-				sprint(str, "%llux", bigP->pcond->pc);
-		else
-			sprint(str, "%lld(PC)", a->offset);
-		break;
-
-	case D_EXTERN:
-		sprint(str, "%s+%lld(SB)", a->sym->name, a->offset);
-		break;
-
-	case D_STATIC:
-		sprint(str, "%s<%d>+%lld(SB)", a->sym->name,
-			a->sym->version, a->offset);
-		break;
-
-	case D_AUTO:
-		sprint(str, "%s+%lld(SP)", a->sym->name, a->offset);
-		break;
-
-	case D_PARAM:
-		if(a->sym)
-			sprint(str, "%s+%lld(%s)", a->sym->name, a->offset, paramspace);
-		else
-			sprint(str, "%lld(%s)", a->offset, paramspace);
-		break;
-
-	case D_CONST:
-		sprint(str, "$%lld", a->offset);
-		break;
-
-	case D_FCONST:
-		sprint(str, "$(%.8lux,%.8lux)", a->ieee.h, a->ieee.l);
-		break;
-
-	case D_SCONST:
-		sprint(str, "$\"%S\"", a->scon);
-		break;
-
-	case D_ADDR:
-		a->type = a->index;
-		a->index = D_NONE;
-		sprint(str, "$%D", a);
-		a->index = a->type;
-		a->type = D_ADDR;
-		goto conv;
-	}
-brk:
-	if(a->index != D_NONE) {
-		sprint(s, "(%R*%d)", a->index, a->scale);
-		strcat(str, s);
-	}
-conv:
-	return fmtstrcpy(fp, str);
-}
-
-char*	regstr[] =
-{
-	"AL",		/* [D_AL] */
-	"CL",
-	"DL",
-	"BL",
-	"SPB",
-	"BPB",
-	"SIB",
-	"DIB",
-	"R8B",
-	"R9B",
-	"R10B",
-	"R11B",
-	"R12B",
-	"R13B",
-	"R14B",
-	"R15B",
-
-	"AX",		/* [D_AX] */
-	"CX",
-	"DX",
-	"BX",
-	"SP",
-	"BP",
-	"SI",
-	"DI",
-	"R8",
-	"R9",
-	"R10",
-	"R11",
-	"R12",
-	"R13",
-	"R14",
-	"R15",
-
-	"AH",
-	"CH",
-	"DH",
-	"BH",
-
-	"F0",		/* [D_F0] */
-	"F1",
-	"F2",
-	"F3",
-	"F4",
-	"F5",
-	"F6",
-	"F7",
-
-	"M0",
-	"M1",
-	"M2",
-	"M3",
-	"M4",
-	"M5",
-	"M6",
-	"M7",
-
-	"X0",
-	"X1",
-	"X2",
-	"X3",
-	"X4",
-	"X5",
-	"X6",
-	"X7",
-	"X8",
-	"X9",
-	"X10",
-	"X11",
-	"X12",
-	"X13",
-	"X14",
-	"X15",
-
-	"CS",		/* [D_CS] */
-	"SS",
-	"DS",
-	"ES",
-	"FS",
-	"GS",
-
-	"GDTR",		/* [D_GDTR] */
-	"IDTR",		/* [D_IDTR] */
-	"LDTR",		/* [D_LDTR] */
-	"MSW",		/* [D_MSW] */
-	"TASK",		/* [D_TASK] */
-
-	"CR0",		/* [D_CR] */
-	"CR1",
-	"CR2",
-	"CR3",
-	"CR4",
-	"CR5",
-	"CR6",
-	"CR7",
-	"CR8",
-	"CR9",
-	"CR10",
-	"CR11",
-	"CR12",
-	"CR13",
-	"CR14",
-	"CR15",
-
-	"DR0",		/* [D_DR] */
-	"DR1",
-	"DR2",
-	"DR3",
-	"DR4",
-	"DR5",
-	"DR6",
-	"DR7",
-
-	"TR0",		/* [D_TR] */
-	"TR1",
-	"TR2",
-	"TR3",
-	"TR4",
-	"TR5",
-	"TR6",
-	"TR7",
-
-	"NONE",		/* [D_NONE] */
-};
-
-int
-Rconv(Fmt *fp)
-{
-	char str[20];
-	int r;
-
-	r = va_arg(fp->args, int);
-	if(r >= D_AL && r <= D_NONE)
-		sprint(str, "%s", regstr[r-D_AL]);
-	else
-		sprint(str, "gok(%d)", r);
-
-	return fmtstrcpy(fp, str);
-}
-
-int
-Sconv(Fmt *fp)
-{
-	int i, c;
-	char str[30], *p, *a;
-
-	a = va_arg(fp->args, char*);
-	p = str;
-	for(i=0; i<sizeof(double); i++) {
-		c = a[i] & 0xff;
-		if(c >= 'a' && c <= 'z' ||
-		   c >= 'A' && c <= 'Z' ||
-		   c >= '0' && c <= '9') {
-			*p++ = c;
-			continue;
-		}
-		*p++ = '\\';
-		switch(c) {
-		default:
-			if(c < 040 || c >= 0177)
-				break;	/* not portable */
-			p[-1] = c;
-			continue;
-		case 0:
-			*p++ = 'z';
-			continue;
-		case '\\':
-		case '"':
-			*p++ = c;
-			continue;
-		case '\n':
-			*p++ = 'n';
-			continue;
-		case '\t':
-			*p++ = 't';
-			continue;
-		}
-		*p++ = (c>>6) + '0';
-		*p++ = ((c>>3) & 7) + '0';
-		*p++ = (c & 7) + '0';
-	}
-	*p = 0;
-	return fmtstrcpy(fp, str);
-}
-
-void
-diag(char *fmt, ...)
-{
-	char buf[STRINGSZ], *tn;
-	va_list arg;
-
-	tn = "??none??";
-	if(curtext != P && curtext->from.sym != S)
-		tn = curtext->from.sym->name;
-	va_start(arg, fmt);
-	vseprint(buf, buf+sizeof(buf), fmt, arg);
-	va_end(arg);
-	print("%s: %s\n", tn, buf);
-
-	nerrors++;
-	if(nerrors > 20) {
-		print("too many errors\n");
-		errorexit();
-	}
-}

+ 0 - 35
sys/src/cmd/6l/mkfile

@@ -1,35 +0,0 @@
-</$objtype/mkfile
-
-TARG=6l
-OFILES=\
-	asm.$O\
-	obj.$O\
-	optab.$O\
-	pass.$O\
-	span.$O\
-	list.$O\
-	enam.$O\
-	compat.$O\
-	elf.$O\
-
-HFILES=\
-	l.h\
-	../6c/6.out.h\
-	../8l/elf.h\
-
-BIN=/$objtype/bin
-CFLAGS=$CFLAGS -. -I.
-CFILES=${OFILES:%.$O=%.c}
-CFILES=${CFILES:enam.c=../6c/enam.c}
-UPDATE=\
-	mkfile\
-	$HFILES\
-	$CFILES\
-	${TARG:%=/386/bin/%}\
-
-</sys/src/cmd/mkone
-
-enam.$O:	../6c/enam.c
-	$CC $CFLAGS ../6c/enam.c
-elf.$O:	../8l/elf.c
-	$CC $CFLAGS ../8l/elf.c

+ 0 - 1683
sys/src/cmd/6l/obj.c

@@ -1,1683 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#define	EXTERN
-#include	"l.h"
-#include	<ar.h>
-
-#ifndef	DEFAULT
-#define	DEFAULT	'9'
-#endif
-
-char	*noname		= "<none>";
-char	symname[]	= SYMDEF;
-char	thechar		= '6';
-char	*thestring 	= "amd64";
-char	*paramspace	= "FP";
-
-char**	libdir;
-int	nlibdir	= 0;
-static	int	maxlibdir = 0;
-
-/*
- *	-H2 -T0x200028 -R0x200000	is plan9 format (was -T4136 -R4096)
- *	-H5 -T0x80110000 -R4096		is ELF32
- *	-H6 -T0x2000e8 -R0x200000	is ELF64
- *
- *	options used: 189BLPQSVWabcjlnpsvz
- */
-
-void
-usage(void)
-{
-	diag("usage: %s [-options] objects", argv0);
-	errorexit();
-}
-
-static int
-isobjfile(char *f)
-{
-	int n, v;
-	Biobuf *b;
-	char buf1[5], buf2[SARMAG];
-
-	b = Bopen(f, OREAD);
-	if(b == nil)
-		return 0;
-	n = Bread(b, buf1, 5);
-	if(n == 5 && (buf1[2] == 1 && buf1[3] == '<' || buf1[3] == 1 && buf1[4] == '<'))
-		v = 1;	/* good enough for our purposes */
-	else{
-		Bseek(b, 0, 0);
-		n = Bread(b, buf2, SARMAG);
-		v = n == SARMAG && strncmp(buf2, ARMAG, SARMAG) == 0;
-	}
-	Bterm(b);
-	return v;
-}
-
-void
-main(int argc, char *argv[])
-{
-	int i, c;
-	char *a;
-	char name[LIBNAMELEN];
-
-	Binit(&bso, 1, OWRITE);
-	cout = -1;
-	listinit();
-	memset(debug, 0, sizeof(debug));
-	nerrors = 0;
-	outfile = "6.out";
-	HEADTYPE = -1;
-	INITTEXT = -1;
-	INITTEXTP = -1;
-	INITDAT = -1;
-	INITRND = -1;
-	INITENTRY = 0;
-	ARGBEGIN {
-	default:
-		c = ARGC();
-		if(c >= 0 && c < sizeof(debug))
-			debug[c]++;
-		break;
-	case 'o': /* output to (next arg) */
-		outfile = ARGF();
-		break;
-	case 'E':
-		a = ARGF();
-		if(a)
-			INITENTRY = a;
-		break;
-	case 'H':
-		a = ARGF();
-		if(a)
-			HEADTYPE = atolwhex(a);
-		break;
-	case 'L':
-		addlibpath(EARGF(usage()));
-		break;
-	case 'T':
-		a = ARGF();
-		if(a)
-			INITTEXT = atolwhex(a);
-		break;
-	case 'P':
-		a = ARGF();
-		if(a)
-			INITTEXTP = atolwhex(a);
-		break;
-	case 'D':
-		a = ARGF();
-		if(a)
-			INITDAT = atolwhex(a);
-		break;
-	case 'R':
-		a = ARGF();
-		if(a)
-			INITRND = atolwhex(a);
-		break;
-	case 'x':	/* produce export table */
-		doexp = 1;
-		if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1]))
-			readundefs(ARGF(), SEXPORT);
-		break;
-	case 'u':	/* produce dynamically loadable module */
-		dlm = 1;
-		debug['l']++;
-		if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1]))
-			readundefs(ARGF(), SIMPORT);
-		break;
-	} ARGEND
-	USED(argc);
-	if(*argv == 0)
-		usage();
-	if(!debug['9'] && !debug['U'] && !debug['B'])
-		debug[DEFAULT] = 1;
-	a = getenv("ccroot");
-	if(a != nil && *a != '\0') {
-		if(!fileexists(a)) {
-			diag("nonexistent $ccroot: %s", a);
-			errorexit();
-		}
-	}else
-		a = "";
-	snprint(name, sizeof(name), "%s/%s/lib", a, thestring);
-	addlibpath(name);
-	if(HEADTYPE == -1) {
-		if(debug['B'])
-			HEADTYPE = 2;
-		if(debug['9'])
-			HEADTYPE = 2;
-	}
-	switch(HEADTYPE) {
-	default:
-		diag("unknown -H option");
-		errorexit();
-	case 2:	/* plan 9 */
-		HEADR = 32L+8L;
-		if(INITTEXT == -1)
-			INITTEXT = 0x200000+HEADR;
-		if(INITDAT == -1)
-			INITDAT = 0;
-		if(INITRND == -1)
-			INITRND = 0x200000;
-		break;
-	case 5:	/* elf32 executable */
-		HEADR = rnd(Ehdr32sz+3*Phdr32sz, 16);
-		if(INITTEXT == -1)
-			INITTEXT = 0xf0110000L;
-		if(INITDAT == -1)
-			INITDAT = 0;
-		if(INITRND == -1)
-			INITRND = 4096;
-		break;
-	case 6:	/* ELF64 executable */
-		HEADR = rnd(Ehdr64sz+3*Phdr64sz, 16);
-		if(INITTEXT == -1)
-			INITTEXT = 0x200000+HEADR;
-		if(INITDAT == -1)
-			INITDAT = 0;
-		if(INITRND == -1)
-			INITRND = 0x200000;
-		break;
-	}
-	if (INITTEXTP == -1)
-		INITTEXTP = INITTEXT;
-	if(INITDAT != 0 && INITRND != 0)
-		print("warning: -D0x%llux is ignored because of -R0x%lux\n",
-			INITDAT, INITRND);
-	if(debug['v'])
-		Bprint(&bso, "HEADER = -H%ld -T0x%llux -D0x%llux -R0x%lux\n",
-			HEADTYPE, INITTEXT, INITDAT, INITRND);
-	Bflush(&bso);
-	for(i=1; optab[i].as; i++) {
-		c = optab[i].as;
-		if(opindex[c] != nil) {
-			diag("phase error in optab: %d (%A)", i, c);
-			errorexit();
-		}
-		opindex[c] = &optab[i];
-	}
-
-	for(i=0; i<Ymax; i++)
-		ycover[i*Ymax + i] = 1;
-
-	ycover[Yi0*Ymax + Yi8] = 1;
-	ycover[Yi1*Ymax + Yi8] = 1;
-
-	ycover[Yi0*Ymax + Ys32] = 1;
-	ycover[Yi1*Ymax + Ys32] = 1;
-	ycover[Yi8*Ymax + Ys32] = 1;
-
-	ycover[Yi0*Ymax + Yi32] = 1;
-	ycover[Yi1*Ymax + Yi32] = 1;
-	ycover[Yi8*Ymax + Yi32] = 1;
-	ycover[Ys32*Ymax + Yi32] = 1;
-
-	ycover[Yi0*Ymax + Yi64] = 1;
-	ycover[Yi1*Ymax + Yi64] = 1;
-	ycover[Yi8*Ymax + Yi64] = 1;
-	ycover[Ys32*Ymax + Yi64] = 1;
-	ycover[Yi32*Ymax + Yi64] = 1;
-
-	ycover[Yal*Ymax + Yrb] = 1;
-	ycover[Ycl*Ymax + Yrb] = 1;
-	ycover[Yax*Ymax + Yrb] = 1;
-	ycover[Ycx*Ymax + Yrb] = 1;
-	ycover[Yrx*Ymax + Yrb] = 1;
-	ycover[Yrl*Ymax + Yrb] = 1;
-
-	ycover[Ycl*Ymax + Ycx] = 1;
-
-	ycover[Yax*Ymax + Yrx] = 1;
-	ycover[Ycx*Ymax + Yrx] = 1;
-
-	ycover[Yax*Ymax + Yrl] = 1;
-	ycover[Ycx*Ymax + Yrl] = 1;
-	ycover[Yrx*Ymax + Yrl] = 1;
-
-	ycover[Yf0*Ymax + Yrf] = 1;
-
-	ycover[Yal*Ymax + Ymb] = 1;
-	ycover[Ycl*Ymax + Ymb] = 1;
-	ycover[Yax*Ymax + Ymb] = 1;
-	ycover[Ycx*Ymax + Ymb] = 1;
-	ycover[Yrx*Ymax + Ymb] = 1;
-	ycover[Yrb*Ymax + Ymb] = 1;
-	ycover[Yrl*Ymax + Ymb] = 1;
-	ycover[Ym*Ymax + Ymb] = 1;
-
-	ycover[Yax*Ymax + Yml] = 1;
-	ycover[Ycx*Ymax + Yml] = 1;
-	ycover[Yrx*Ymax + Yml] = 1;
-	ycover[Yrl*Ymax + Yml] = 1;
-	ycover[Ym*Ymax + Yml] = 1;
-
-	ycover[Yax*Ymax + Ymm] = 1;
-	ycover[Ycx*Ymax + Ymm] = 1;
-	ycover[Yrx*Ymax + Ymm] = 1;
-	ycover[Yrl*Ymax + Ymm] = 1;
-	ycover[Ym*Ymax + Ymm] = 1;
-	ycover[Ymr*Ymax + Ymm] = 1;
-
-	ycover[Yax*Ymax + Yxm] = 1;
-	ycover[Ycx*Ymax + Yxm] = 1;
-	ycover[Yrx*Ymax + Yxm] = 1;
-	ycover[Yrl*Ymax + Yxm] = 1;
-	ycover[Ym*Ymax + Yxm] = 1;
-	ycover[Yxr*Ymax + Yxm] = 1;
-
-	for(i=0; i<D_NONE; i++) {
-		reg[i] = -1;
-		if(i >= D_AL && i <= D_R15B) {
-			reg[i] = (i-D_AL) & 7;
-			if(i >= D_SPB && i <= D_DIB)
-				regrex[i] = 0x40;
-			if(i >= D_R8B && i <= D_R15B)
-				regrex[i] = Rxr | Rxx | Rxb;
-		}
-		if(i >= D_AH && i<= D_BH)
-			reg[i] = 4 + ((i-D_AH) & 7);
-		if(i >= D_AX && i <= D_R15) {
-			reg[i] = (i-D_AX) & 7;
-			if(i >= D_R8)
-				regrex[i] = Rxr | Rxx | Rxb;
-		}
-		if(i >= D_F0 && i <= D_F0+7)
-			reg[i] = (i-D_F0) & 7;
-		if(i >= D_M0 && i <= D_M0+7)
-			reg[i] = (i-D_M0) & 7;
-		if(i >= D_X0 && i <= D_X0+15) {
-			reg[i] = (i-D_X0) & 7;
-			if(i >= D_X0+8)
-				regrex[i] = Rxr | Rxx | Rxb;
-		}
-		if(i >= D_CR+8 && i <= D_CR+15) 
-			regrex[i] = Rxr;
-	}
-
-	zprg.link = P;
-	zprg.pcond = P;
-	zprg.back = 2;
-	zprg.as = AGOK;
-	zprg.from.type = D_NONE;
-	zprg.from.index = D_NONE;
-	zprg.from.scale = 1;
-	zprg.to = zprg.from;
-	zprg.mode = 64;
-
-	pcstr = "%.6llux ";
-	nuxiinit();
-	histgen = 0;
-	textp = P;
-	datap = P;
-	edatap = P;
-	pc = 0;
-	dtype = 4;
-	cout = create(outfile, 1, 0775);
-	if(cout < 0) {
-		diag("cannot create %s: %r", outfile);
-		errorexit();
-	}
-	version = 0;
-	cbp = buf.cbuf;
-	cbc = sizeof(buf.cbuf);
-	firstp = prg();
-	lastp = firstp;
-
-	if(INITENTRY == 0) {
-		INITENTRY = "_main";
-		if(debug['p'])
-			INITENTRY = "_mainp";
-		if(!debug['l'])
-			lookup(INITENTRY, 0)->type = SXREF;
-	} else if(!(*INITENTRY >= '0' && *INITENTRY <= '9'))
-		lookup(INITENTRY, 0)->type = SXREF;
-
-	while(*argv)
-		objfile(*argv++);
-	if(!debug['l'])
-		loadlib();
-	firstp = firstp->link;
-	if(firstp == P)
-		errorexit();
-	if(doexp || dlm){
-		EXPTAB = "_exporttab";
-		zerosig(EXPTAB);
-		zerosig("etext");
-		zerosig("edata");
-		zerosig("end");
-		if(dlm){
-			import();
-			HEADTYPE = 2;
-			INITTEXT = 0;
-			INITDAT = 0;
-			INITRND = 8;
-			INITENTRY = EXPTAB;
-		}
-		export();
-	}
-	patch();
-	follow();
-	dodata();
-	dostkoff();
-	paramspace = "SP";	/* (FP) now (SP) on output */
-	if(debug['p'])
-		if(debug['1'])
-			doprof1();
-		else
-			doprof2();
-	span();
-	doinit();
-	asmb();
-	undef();
-	if(debug['v']) {
-		Bprint(&bso, "%5.2f cpu time\n", cputime());
-		Bprint(&bso, "%ld symbols\n", nsymbol);
-		Bprint(&bso, "%ld memory used\n", thunk);
-		Bprint(&bso, "%d sizeof adr\n", sizeof(Adr));
-		Bprint(&bso, "%d sizeof prog\n", sizeof(Prog));
-	}
-	Bflush(&bso);
-
-	errorexit();
-}
-
-void
-addlibpath(char *arg)
-{
-	char **p;
-
-	if(nlibdir >= maxlibdir) {
-		if(maxlibdir == 0)
-			maxlibdir = 8;
-		else
-			maxlibdir *= 2;
-		p = malloc(maxlibdir*sizeof(*p));
-		if(p == nil) {
-			diag("out of memory");
-			errorexit();
-		}
-		memmove(p, libdir, nlibdir*sizeof(*p));
-		free(libdir);
-		libdir = p;
-	}
-	libdir[nlibdir++] = strdup(arg);
-}
-
-char*
-findlib(char *file)
-{
-	int i;
-	char name[LIBNAMELEN];
-
-	for(i = 0; i < nlibdir; i++) {
-		snprint(name, sizeof(name), "%s/%s", libdir[i], file);
-		if(fileexists(name))
-			return libdir[i];
-	}
-	return nil;
-}
-
-void
-loadlib(void)
-{
-	int i;
-	int32_t h;
-	Sym *s;
-
-loop:
-	xrefresolv = 0;
-	for(i=0; i<libraryp; i++) {
-		if(debug['v'])
-			Bprint(&bso, "%5.2f autolib: %s (from %s)\n", cputime(), library[i], libraryobj[i]);
-		objfile(library[i]);
-	}
-	if(xrefresolv)
-	for(h=0; h<nelem(hash); h++)
-	for(s = hash[h]; s != S; s = s->link)
-		if(s->type == SXREF)
-			goto loop;
-}
-
-void
-errorexit(void)
-{
-
-	if(nerrors) {
-		if(cout >= 0)
-			remove(outfile);
-		exits("error");
-	}
-	exits(0);
-}
-
-void
-objfile(char *file)
-{
-	int32_t off, esym, cnt, l;
-	int f, work;
-	Sym *s;
-	char magbuf[SARMAG];
-	char name[LIBNAMELEN], pname[LIBNAMELEN];
-	struct ar_hdr arhdr;
-	char *e, *start, *stop;
-
-	if(debug['v'])
-		Bprint(&bso, "%5.2f ldobj: %s\n", cputime(), file);
-	Bflush(&bso);
-	if(file[0] == '-' && file[1] == 'l') {
-		snprint(pname, sizeof(pname), "lib%s.a", file+2);
-		e = findlib(pname);
-		if(e == nil) {
-			diag("cannot find library: %s", file);
-			errorexit();
-		}
-		snprint(name, sizeof(name), "%s/%s", e, pname);
-		file = name;
-	}
-	f = open(file, 0);
-	if(f < 0) {
-		diag("cannot open %s: %r", file);
-		errorexit();
-	}
-	l = read(f, magbuf, SARMAG);
-	if(l != SARMAG || strncmp(magbuf, ARMAG, SARMAG)){
-		/* load it as a regular file */
-		l = seek(f, 0L, 2);
-		seek(f, 0L, 0);
-		ldobj(f, l, file);
-		close(f);
-		return;
-	}
-
-	l = read(f, &arhdr, SAR_HDR);
-	if(l != SAR_HDR) {
-		diag("%s: short read on archive file symbol header", file);
-		goto out;
-	}
-	if(strncmp(arhdr.name, symname, strlen(symname))) {
-		diag("%s: first entry not symbol header", file);
-		goto out;
-	}
-
-	esym = SARMAG + SAR_HDR + atolwhex(arhdr.size);
-	off = SARMAG + SAR_HDR;
-
-	/*
-	 * just bang the whole symbol file into memory
-	 */
-	seek(f, off, 0);
-	cnt = esym - off;
-	start = malloc(cnt + 10);
-	cnt = read(f, start, cnt);
-	if(cnt <= 0){
-		close(f);
-		return;
-	}
-	stop = &start[cnt];
-	memset(stop, 0, 10);
-
-	work = 1;
-	while(work) {
-		if(debug['v'])
-			Bprint(&bso, "%5.2f library pass: %s\n", cputime(), file);
-		Bflush(&bso);
-		work = 0;
-		for(e = start; e < stop; e = strchr(e+5, 0) + 1) {
-			s = lookup(e+5, 0);
-			if(s->type != SXREF)
-				continue;
-			sprint(pname, "%s(%s)", file, s->name);
-			if(debug['v'])
-				Bprint(&bso, "%5.2f library: %s\n", cputime(), pname);
-			Bflush(&bso);
-			l = e[1] & 0xff;
-			l |= (e[2] & 0xff) << 8;
-			l |= (e[3] & 0xff) << 16;
-			l |= (e[4] & 0xff) << 24;
-			seek(f, l, 0);
-			/* need readn to read the dumps (at least) */
-			l = readn(f, &arhdr, SAR_HDR);
-			if(l != SAR_HDR)
-				goto bad;
-			if(strncmp(arhdr.fmag, ARFMAG, sizeof(arhdr.fmag)))
-				goto bad;
-			l = atolwhex(arhdr.size);
-			ldobj(f, l, pname);
-			if(s->type == SXREF) {
-				diag("%s: failed to load: %s", file, s->name);
-				errorexit();
-			}
-			work = 1;
-			xrefresolv = 1;
-		}
-	}
-	return;
-
-bad:
-	diag("%s: bad or out of date archive", file);
-out:
-	close(f);
-}
-
-int
-zaddr(uint8_t *p, Adr *a, Sym *h[])
-{
-	int c, t, i;
-	int l;
-	Sym *s;
-	Auto *u;
-
-	t = p[0];
-	c = 1;
-	if(t & T_INDEX) {
-		a->index = p[c];
-		a->scale = p[c+1];
-		c += 2;
-	} else {
-		a->index = D_NONE;
-		a->scale = 0;
-	}
-	a->offset = 0;
-	if(t & T_OFFSET) {
-		/*
-		 * Hack until Charles fixes the compiler.
-		a->offset = (long)(p[c] | (p[c+1]<<8) | (p[c+2]<<16) | (p[c+3]<<24));
-		 */
-		l = p[c] | (p[c+1]<<8) | (p[c+2]<<16) | (p[c+3]<<24);
-		a->offset = l;
-		c += 4;
-		if(t & T_64) {
-			l = p[c] | (p[c+1]<<8) | (p[c+2]<<16) | (p[c+3]<<24);
-			a->offset = ((int64_t)l<<32) | (a->offset & 0xFFFFFFFFUL);
-			c += 4;
-		}
-	}
-	a->sym = S;
-	if(t & T_SYM) {
-		a->sym = h[p[c]];
-		c++;
-	}
-	a->type = D_NONE;
-	if(t & T_FCONST) {
-		a->ieee.l = p[c] | (p[c+1]<<8) | (p[c+2]<<16) | (p[c+3]<<24);
-		a->ieee.h = p[c+4] | (p[c+5]<<8) | (p[c+6]<<16) | (p[c+7]<<24);
-		c += 8;
-		a->type = D_FCONST;
-	} else
-	if(t & T_SCONST) {
-		for(i=0; i<NSNAME; i++)
-			a->scon[i] = p[c+i];
-		c += NSNAME;
-		a->type = D_SCONST;
-	}
-	if(t & T_TYPE) {
-		a->type = p[c];
-		c++;
-	}
-	s = a->sym;
-	if(s == S)
-		return c;
-
-	t = a->type;
-	if(t != D_AUTO && t != D_PARAM)
-		return c;
-	l = a->offset;
-	for(u=curauto; u; u=u->link) {
-		if(u->asym == s)
-		if(u->type == t) {
-			if(u->aoffset > l)
-				u->aoffset = l;
-			return c;
-		}
-	}
-
-	while(nhunk < sizeof(Auto))
-		gethunk();
-	u = (Auto*)hunk;
-	nhunk -= sizeof(Auto);
-	hunk += sizeof(Auto);
-
-	u->link = curauto;
-	curauto = u;
-	u->asym = s;
-	u->aoffset = l;
-	u->type = t;
-	return c;
-}
-
-void
-addlib(char *obj)
-{
-	char fn1[LIBNAMELEN], fn2[LIBNAMELEN], comp[LIBNAMELEN], *p, *name;
-	int i, search;
-
-	if(histfrogp <= 0)
-		return;
-
-	name = fn1;
-	search = 0;
-	if(histfrog[0]->name[1] == '/') {
-		sprint(name, "");
-		i = 1;
-	} else if(histfrog[0]->name[1] == '.') {
-		sprint(name, ".");
-		i = 0;
-	} else {
-		sprint(name, "");
-		i = 0;
-		search = 1;
-	}
-
-	for(; i<histfrogp; i++) {
-		snprint(comp, sizeof comp, histfrog[i]->name+1);
-		for(;;) {
-			p = strstr(comp, "$O");
-			if(p == 0)
-				break;
-			memmove(p+1, p+2, strlen(p+2)+1);
-			p[0] = thechar;
-		}
-		for(;;) {
-			p = strstr(comp, "$M");
-			if(p == 0)
-				break;
-			if(strlen(comp)+strlen(thestring)-2+1 >= sizeof comp) {
-				diag("library component too long");
-				return;
-			}
-			memmove(p+strlen(thestring), p+2, strlen(p+2)+1);
-			memmove(p, thestring, strlen(thestring));
-		}
-		if(strlen(fn1) + strlen(comp) + 3 >= sizeof(fn1)) {
-			diag("library component too long");
-			return;
-		}
-		if(i > 0 || !search)
-			strcat(fn1, "/");
-		strcat(fn1, comp);
-	}
-
-	cleanname(name);
-
-	if(search){
-		p = findlib(name);
-		if(p != nil){
-			snprint(fn2, sizeof(fn2), "%s/%s", p, name);
-			name = fn2;
-		}
-	}
-
-	for(i=0; i<libraryp; i++)
-		if(strcmp(name, library[i]) == 0)
-			return;
-	if(libraryp == nelem(library)){
-		diag("too many autolibs; skipping %s", name);
-		return;
-	}
-
-	p = malloc(strlen(name) + 1);
-	strcpy(p, name);
-	library[libraryp] = p;
-	p = malloc(strlen(obj) + 1);
-	strcpy(p, obj);
-	libraryobj[libraryp] = p;
-	libraryp++;
-}
-
-void
-addhist(int32_t line, int type)
-{
-	Auto *u;
-	Sym *s;
-	int i, j, k;
-
-	u = malloc(sizeof(Auto));
-	s = malloc(sizeof(Sym));
-	s->name = malloc(2*(histfrogp+1) + 1);
-
-	u->asym = s;
-	u->type = type;
-	u->aoffset = line;
-	u->link = curhist;
-	curhist = u;
-
-	j = 1;
-	for(i=0; i<histfrogp; i++) {
-		k = histfrog[i]->value;
-		s->name[j+0] = k>>8;
-		s->name[j+1] = k;
-		j += 2;
-	}
-}
-
-void
-histtoauto(void)
-{
-	Auto *l;
-
-	while(l = curhist) {
-		curhist = l->link;
-		l->link = curauto;
-		curauto = l;
-	}
-}
-
-void
-collapsefrog(Sym *s)
-{
-	int i;
-
-	/*
-	 * bad encoding of path components only allows
-	 * MAXHIST components. if there is an overflow,
-	 * first try to collapse xxx/..
-	 */
-	for(i=1; i<histfrogp; i++)
-		if(strcmp(histfrog[i]->name+1, "..") == 0) {
-			memmove(histfrog+i-1, histfrog+i+1,
-				(histfrogp-i-1)*sizeof(histfrog[0]));
-			histfrogp--;
-			goto out;
-		}
-
-	/*
-	 * next try to collapse .
-	 */
-	for(i=0; i<histfrogp; i++)
-		if(strcmp(histfrog[i]->name+1, ".") == 0) {
-			memmove(histfrog+i, histfrog+i+1,
-				(histfrogp-i-1)*sizeof(histfrog[0]));
-			goto out;
-		}
-
-	/*
-	 * last chance, just truncate from front
-	 */
-	memmove(histfrog+0, histfrog+1,
-		(histfrogp-1)*sizeof(histfrog[0]));
-
-out:
-	histfrog[histfrogp-1] = s;
-}
-
-void
-nopout(Prog *p)
-{
-	p->as = ANOP;
-	p->from.type = D_NONE;
-	p->to.type = D_NONE;
-}
-
-uint8_t*
-readsome(int f, uint8_t *buf, uint8_t *good, uint8_t *stop, int max)
-{
-	int n;
-
-	n = stop - good;
-	memmove(buf, good, stop - good);
-	stop = buf + n;
-	n = MAXIO - n;
-	if(n > max)
-		n = max;
-	n = read(f, stop, n);
-	if(n <= 0)
-		return 0;
-	return stop + n;
-}
-
-void
-ldobj(int f, int32_t c, char *pn)
-{
-	int64_t ipc;
-	Prog *p, *t;
-	uint8_t *bloc, *bsize, *stop;
-	int v, o, r, skip, mode;
-	Sym *h[NSYM], *s, *di;
-	uint32_t sig;
-	static int files;
-	static char **filen;
-	char **nfilen;
-
-	if((files&15) == 0){
-		nfilen = malloc((files+16)*sizeof(char*));
-		memmove(nfilen, filen, files*sizeof(char*));
-		free(filen);
-		filen = nfilen;
-	}
-	filen[files++] = strdup(pn);
-
-	bsize = buf.xbuf;
-	bloc = buf.xbuf;
-	di = S;
-
-newloop:
-	memset(h, 0, sizeof(h));
-	version++;
-	histfrogp = 0;
-	ipc = pc;
-	skip = 0;
-	mode = 64;
-
-loop:
-	if(c <= 0)
-		goto eof;
-	r = bsize - bloc;
-	if(r < 100 && r < c) {		/* enough for largest prog */
-		bsize = readsome(f, buf.xbuf, bloc, bsize, c);
-		if(bsize == 0)
-			goto eof;
-		bloc = buf.xbuf;
-		goto loop;
-	}
-	o = bloc[0] | (bloc[1] << 8);
-	if(o <= AXXX || o >= ALAST) {
-		if(o < 0)
-			goto eof;
-		diag("%s: opcode out of range %d", pn, o);
-		print("	probably not a .6 file\n");
-		errorexit();
-	}
-
-	if(o == ANAME || o == ASIGNAME) {
-		sig = 0;
-		if(o == ASIGNAME) {
-			sig = bloc[2] | (bloc[3]<<8) | (bloc[4]<<16) | (bloc[5]<<24);
-			bloc += 4;
-			c -= 4;
-		}
-		stop = memchr(&bloc[4], 0, bsize-&bloc[4]);
-		if(stop == 0){
-			bsize = readsome(f, buf.xbuf, bloc, bsize, c);
-			if(bsize == 0)
-				goto eof;
-			bloc = buf.xbuf;
-			stop = memchr(&bloc[4], 0, bsize-&bloc[4]);
-			if(stop == 0){
-				fprint(2, "%s: name too long\n", pn);
-				errorexit();
-			}
-		}
-		v = bloc[2];	/* type */
-		o = bloc[3];	/* sym */
-		bloc += 4;
-		c -= 4;
-
-		r = 0;
-		if(v == D_STATIC)
-			r = version;
-		s = lookup((char*)bloc, r);
-		c -= &stop[1] - bloc;
-		bloc = stop + 1;
-
-		if(debug['S'] && r == 0)
-			sig = 1729;
-		if(sig != 0){
-			if(s->sig != 0 && s->sig != sig)
-				diag("incompatible type signatures %lux(%s) and %lux(%s) for %s", s->sig, filen[s->file], sig, pn, s->name);
-			s->sig = sig;
-			s->file = files-1;
-		}
-
-		if(debug['W'])
-			print("	ANAME	%s\n", s->name);
-		h[o] = s;
-		if((v == D_EXTERN || v == D_STATIC) && s->type == 0)
-			s->type = SXREF;
-		if(v == D_FILE) {
-			if(s->type != SFILE) {
-				histgen++;
-				s->type = SFILE;
-				s->value = histgen;
-			}
-			if(histfrogp < MAXHIST) {
-				histfrog[histfrogp] = s;
-				histfrogp++;
-			} else
-				collapsefrog(s);
-		}
-		goto loop;
-	}
-
-	while(nhunk < sizeof(Prog))
-		gethunk();
-	p = (Prog*)hunk;
-	nhunk -= sizeof(Prog);
-	hunk += sizeof(Prog);
-
-	p->as = o;
-	p->line = bloc[2] | (bloc[3] << 8) | (bloc[4] << 16) | (bloc[5] << 24);
-	p->back = 2;
-	p->mode = mode;
-	r = zaddr(bloc+6, &p->from, h) + 6;
-	r += zaddr(bloc+r, &p->to, h);
-	bloc += r;
-	c -= r;
-
-	if(debug['W'])
-		print("%P\n", p);
-
-	switch(p->as) {
-	case AHISTORY:
-		if(p->to.offset == -1) {
-			addlib(pn);
-			histfrogp = 0;
-			goto loop;
-		}
-		addhist(p->line, D_FILE);		/* 'z' */
-		if(p->to.offset)
-			addhist(p->to.offset, D_FILE1);	/* 'Z' */
-		histfrogp = 0;
-		goto loop;
-
-	case AEND:
-		histtoauto();
-		if(curtext != P)
-			curtext->to.autom = curauto;
-		curauto = 0;
-		curtext = P;
-		if(c)
-			goto newloop;
-		return;
-
-	case AGLOBL:
-		s = p->from.sym;
-		if(s->type == 0 || s->type == SXREF) {
-			s->type = SBSS;
-			s->value = 0;
-		}
-		if(s->type != SBSS) {
-			diag("%s: redefinition: %s in %s",
-				pn, s->name, TNAME);
-			s->type = SBSS;
-			s->value = 0;
-		}
-		if(p->to.offset > s->value)
-			s->value = p->to.offset;
-		goto loop;
-
-	case ADYNT:
-		if(p->to.sym == S) {
-			diag("DYNT without a sym\n%P", p);
-			break;
-		}
-		di = p->to.sym;
-		p->from.scale = 4;
-		if(di->type == SXREF) {
-			if(debug['z'])
-				Bprint(&bso, "%P set to %d\n", p, dtype);
-			di->type = SCONST;
-			di->value = dtype;
-			dtype += 4;
-		}
-		if(p->from.sym == S)
-			break;
-
-		p->from.offset = di->value;
-		p->from.sym->type = SDATA;
-		if(curtext == P) {
-			diag("DYNT not in text: %P", p);
-			break;
-		}
-		p->to.sym = curtext->from.sym;
-		p->to.type = D_ADDR;
-		p->to.index = D_EXTERN;
-		goto data;
-
-	case AINIT:
-		if(p->from.sym == S) {
-			diag("INIT without a sym\n%P", p);
-			break;
-		}
-		if(di == S) {
-			diag("INIT without previous DYNT\n%P", p);
-			break;
-		}
-		p->from.offset = di->value;
-		p->from.sym->type = SDATA;
-		goto data;
-
-	case ADATA:
-	data:
-		if(edatap == P)
-			datap = p;
-		else
-			edatap->link = p;
-		edatap = p;
-		p->link = P;
-		goto loop;
-
-	case AGOK:
-		diag("%s: GOK opcode in %s", pn, TNAME);
-		pc++;
-		goto loop;
-
-	case ATEXT:
-		if(curtext != P) {
-			histtoauto();
-			curtext->to.autom = curauto;
-			curauto = 0;
-		}
-		skip = 0;
-		curtext = p;
-		s = p->from.sym;
-		if(s == S) {
-			diag("%s: no TEXT symbol: %P", pn, p);
-			errorexit();
-		}
-		if(s->type != 0 && s->type != SXREF) {
-			if(p->from.scale & DUPOK) {
-				skip = 1;
-				goto casdef;
-			}
-			diag("%s: redefinition: %s\n%P", pn, s->name, p);
-		}
-		s->type = STEXT;
-		s->value = pc;
-		lastp->link = p;
-		lastp = p;
-		p->pc = pc;
-		pc++;
-		if(textp == P) {
-			textp = p;
-			etextp = p;
-			goto loop;
-		}
-		etextp->pcond = p;
-		etextp = p;
-		goto loop;
-
-	case AMODE:
-		if(p->from.type == D_CONST || p->from.type == D_INDIR+D_NONE){
-			switch((int)p->from.offset){
-			case 16: case 32: case 64:
-				mode = p->from.offset;
-				break;
-			}
-		}
-		goto loop;
-
-	case AFMOVF:
-	case AFADDF:
-	case AFSUBF:
-	case AFSUBRF:
-	case AFMULF:
-	case AFDIVF:
-	case AFDIVRF:
-	case AFCOMF:
-	case AFCOMFP:
-	case AMOVSS:
-	case AADDSS:
-	case ASUBSS:
-	case AMULSS:
-	case ADIVSS:
-	case ACOMISS:
-	case AUCOMISS:
-		if(skip)
-			goto casdef;
-		if(p->from.type == D_FCONST) {
-			/* size sb 9 max */
-			sprint(literal, "$%lux", ieeedtof(&p->from.ieee));
-			s = lookup(literal, 0);
-			if(s->type == 0) {
-				s->type = SBSS;
-				s->value = 4;
-				t = prg();
-				t->as = ADATA;
-				t->line = p->line;
-				t->from.type = D_EXTERN;
-				t->from.sym = s;
-				t->from.scale = 4;
-				t->to = p->from;
-				if(edatap == P)
-					datap = t;
-				else
-					edatap->link = t;
-				edatap = t;
-				t->link = P;
-			}
-			p->from.type = D_EXTERN;
-			p->from.sym = s;
-			p->from.offset = 0;
-		}
-		goto casdef;
-
-	case AFMOVD:
-	case AFADDD:
-	case AFSUBD:
-	case AFSUBRD:
-	case AFMULD:
-	case AFDIVD:
-	case AFDIVRD:
-	case AFCOMD:
-	case AFCOMDP:
-	case AMOVSD:
-	case AADDSD:
-	case ASUBSD:
-	case AMULSD:
-	case ADIVSD:
-	case ACOMISD:
-	case AUCOMISD:
-		if(skip)
-			goto casdef;
-		if(p->from.type == D_FCONST) {
-			/* size sb 18 max */
-			sprint(literal, "$%lux.%lux",
-				p->from.ieee.l, p->from.ieee.h);
-			s = lookup(literal, 0);
-			if(s->type == 0) {
-				s->type = SBSS;
-				s->value = 8;
-				t = prg();
-				t->as = ADATA;
-				t->line = p->line;
-				t->from.type = D_EXTERN;
-				t->from.sym = s;
-				t->from.scale = 8;
-				t->to = p->from;
-				if(edatap == P)
-					datap = t;
-				else
-					edatap->link = t;
-				edatap = t;
-				t->link = P;
-			}
-			p->from.type = D_EXTERN;
-			p->from.sym = s;
-			p->from.offset = 0;
-		}
-		goto casdef;
-
-	casdef:
-	default:
-		if(skip)
-			nopout(p);
-
-		if(p->to.type == D_BRANCH)
-			p->to.offset += ipc;
-		lastp->link = p;
-		lastp = p;
-		p->pc = pc;
-		pc++;
-		goto loop;
-	}
-	goto loop;
-
-eof:
-	diag("truncated object file: %s", pn);
-}
-
-Sym*
-lookup(char *symb, int v)
-{
-	Sym *s;
-	char *p;
-	int32_t h;
-	int l, c;
-
-	h = v;
-	for(p=symb; c = *p; p++)
-		h = h+h+h + c;
-	l = (p - symb) + 1;
-	h &= 0xffffff;
-	h %= NHASH;
-	for(s = hash[h]; s != S; s = s->link)
-		if(s->version == v)
-		if(memcmp(s->name, symb, l) == 0)
-			return s;
-
-	while(nhunk < sizeof(Sym))
-		gethunk();
-	s = (Sym*)hunk;
-	nhunk -= sizeof(Sym);
-	hunk += sizeof(Sym);
-
-	s->name = malloc(l + 1);
-	memmove(s->name, symb, l);
-
-	s->link = hash[h];
-	s->type = 0;
-	s->version = v;
-	s->value = 0;
-	s->sig = 0;
-	hash[h] = s;
-	nsymbol++;
-	return s;
-}
-
-Prog*
-prg(void)
-{
-	Prog *p;
-
-	while(nhunk < sizeof(Prog))
-		gethunk();
-	p = (Prog*)hunk;
-	nhunk -= sizeof(Prog);
-	hunk += sizeof(Prog);
-
-	*p = zprg;
-	return p;
-}
-
-Prog*
-copyp(Prog *q)
-{
-	Prog *p;
-
-	p = prg();
-	*p = *q;
-	return p;
-}
-
-Prog*
-appendp(Prog *q)
-{
-	Prog *p;
-
-	p = prg();
-	p->link = q->link;
-	q->link = p;
-	p->line = q->line;
-	p->mode = q->mode;
-	return p;
-}
-
-void
-gethunk(void)
-{
-	char *h;
-	int32_t nh;
-
-	nh = NHUNK;
-	if(thunk >= 5L*NHUNK) {
-		nh = 5L*NHUNK;
-		if(thunk >= 25L*NHUNK)
-			nh = 25L*NHUNK;
-	}
-	h = mysbrk(nh);
-	if(h == (char*)-1) {
-		diag("out of memory");
-		errorexit();
-	}
-	hunk = h;
-	nhunk = nh;
-	thunk += nh;
-}
-
-void
-doprof1(void)
-{
-	Sym *s;
-	int32_t n;
-	Prog *p, *q;
-
-	if(debug['v'])
-		Bprint(&bso, "%5.2f profile 1\n", cputime());
-	Bflush(&bso);
-	s = lookup("__mcount", 0);
-	n = 1;
-	for(p = firstp->link; p != P; p = p->link) {
-		if(p->as == ATEXT) {
-			q = prg();
-			q->line = p->line;
-			q->link = datap;
-			datap = q;
-			q->as = ADATA;
-			q->from.type = D_EXTERN;
-			q->from.offset = n*4;
-			q->from.sym = s;
-			q->from.scale = 4;
-			q->to = p->from;
-			q->to.type = D_CONST;
-
-			q = prg();
-			q->line = p->line;
-			q->pc = p->pc;
-			q->link = p->link;
-			p->link = q;
-			p = q;
-			p->as = AADDL;
-			p->from.type = D_CONST;
-			p->from.offset = 1;
-			p->to.type = D_EXTERN;
-			p->to.sym = s;
-			p->to.offset = n*4 + 4;
-
-			n += 2;
-			continue;
-		}
-	}
-	q = prg();
-	q->line = 0;
-	q->link = datap;
-	datap = q;
-
-	q->as = ADATA;
-	q->from.type = D_EXTERN;
-	q->from.sym = s;
-	q->from.scale = 4;
-	q->to.type = D_CONST;
-	q->to.offset = n;
-
-	s->type = SBSS;
-	s->value = n*4;
-}
-
-void
-doprof2(void)
-{
-	Sym *s2, *s4;
-	Prog *p, *q, *q2, *ps2, *ps4;
-
-	if(debug['v'])
-		Bprint(&bso, "%5.2f profile 2\n", cputime());
-	Bflush(&bso);
-
-	if(debug['e']){
-		s2 = lookup("_tracein", 0);
-		s4 = lookup("_traceout", 0);
-	}else{
-		s2 = lookup("_profin", 0);
-		s4 = lookup("_profout", 0);
-	}
-	if(s2->type != STEXT || s4->type != STEXT) {
-		if(debug['e'])
-			diag("_tracein/_traceout not defined %d %d", s2->type, s4->type);
-		else
-			diag("_profin/_profout not defined");
-		return;
-	}
-
-	ps2 = P;
-	ps4 = P;
-	for(p = firstp; p != P; p = p->link) {
-		if(p->as == ATEXT) {
-			if(p->from.sym == s2) {
-				p->from.scale = 1;
-				ps2 = p;
-			}
-			if(p->from.sym == s4) {
-				p->from.scale = 1;
-				ps4 = p;
-			}
-		}
-	}
-	for(p = firstp; p != P; p = p->link) {
-		if(p->as == ATEXT) {
-			curtext = p;
-
-			if(p->from.scale & NOPROF) {	/* dont profile */
-				for(;;) {
-					q = p->link;
-					if(q == P)
-						break;
-					if(q->as == ATEXT)
-						break;
-					p = q;
-				}
-				continue;
-			}
-
-			/*
-			 * JMPL	profin
-			 */
-			q = prg();
-			q->line = p->line;
-			q->pc = p->pc;
-			q->link = p->link;
-			if(debug['e']){		/* embedded tracing */
-				q2 = prg();
-				p->link = q2;
-				q2->link = q;
-
-				q2->line = p->line;
-				q2->pc = p->pc;
-
-				q2->as = AJMP;
-				q2->to.type = D_BRANCH;
-				q2->to.sym = p->to.sym;
-				q2->pcond = q->link;
-			}else
-				p->link = q;
-			p = q;
-			p->as = ACALL;
-			p->to.type = D_BRANCH;
-			p->pcond = ps2;
-			p->to.sym = s2;
-
-			continue;
-		}
-		if(p->as == ARET) {
-			/*
-			 * RET (default)
-			 */
-			if(debug['e']){		/* embedded tracing */
-				q = prg();
-				q->line = p->line;
-				q->pc = p->pc;
-				q->link = p->link;
-				p->link = q;
-				p = q;
-			}
-			/*
-			 * RET
-			 */
-			q = prg();
-			q->as = ARET;
-			q->from = p->from;
-			q->to = p->to;
-			q->link = p->link;
-			p->link = q;
-
-			/*
-			 * JAL	profout
-			 */
-			p->as = ACALL;
-			p->from = zprg.from;
-			p->to = zprg.to;
-			p->to.type = D_BRANCH;
-			p->pcond = ps4;
-			p->to.sym = s4;
-
-			p = q;
-
-			continue;
-		}
-	}
-}
-
-void
-nuxiinit(void)
-{
-	int i, c;
-
-	for(i=0; i<4; i++) {
-		c = find1(0x04030201L, i+1);
-		if(i < 2)
-			inuxi2[i] = c;
-		if(i < 1)
-			inuxi1[i] = c;
-		inuxi4[i] = c;
-		inuxi8[i] = c;
-		inuxi8[i+4] = c+4;
-		fnuxi4[i] = c;
-		fnuxi8[i] = c;
-		fnuxi8[i+4] = c+4;
-	}
-	if(debug['v']) {
-		Bprint(&bso, "inuxi = ");
-		for(i=0; i<1; i++)
-			Bprint(&bso, "%d", inuxi1[i]);
-		Bprint(&bso, " ");
-		for(i=0; i<2; i++)
-			Bprint(&bso, "%d", inuxi2[i]);
-		Bprint(&bso, " ");
-		for(i=0; i<4; i++)
-			Bprint(&bso, "%d", inuxi4[i]);
-		Bprint(&bso, " ");
-		for(i=0; i<8; i++)
-			Bprint(&bso, "%d", inuxi8[i]);
-		Bprint(&bso, "\nfnuxi = ");
-		for(i=0; i<4; i++)
-			Bprint(&bso, "%d", fnuxi4[i]);
-		Bprint(&bso, " ");
-		for(i=0; i<8; i++)
-			Bprint(&bso, "%d", fnuxi8[i]);
-		Bprint(&bso, "\n");
-	}
-	Bflush(&bso);
-}
-
-int
-find1(int32_t l, int c)
-{
-	char *p;
-	int i;
-
-	p = (char*)&l;
-	for(i=0; i<4; i++)
-		if(*p++ == c)
-			return i;
-	return 0;
-}
-
-int
-find2(int32_t l, int c)
-{
-	int16_t *p;
-	int i;
-
-	p = (int16_t*)&l;
-	for(i=0; i<4; i+=2) {
-		if(((*p >> 8) & 0xff) == c)
-			return i;
-		if((*p++ & 0xff) == c)
-			return i+1;
-	}
-	return 0;
-}
-
-int32_t
-ieeedtof(Ieee *e)
-{
-	int exp;
-	int32_t v;
-
-	if(e->h == 0)
-		return 0;
-	exp = (e->h>>20) & ((1L<<11)-1L);
-	exp -= (1L<<10) - 2L;
-	v = (e->h & 0xfffffL) << 3;
-	v |= (e->l >> 29) & 0x7L;
-	if((e->l >> 28) & 1) {
-		v++;
-		if(v & 0x800000L) {
-			v = (v & 0x7fffffL) >> 1;
-			exp++;
-		}
-	}
-	if(exp <= -126 || exp >= 130)
-		diag("double fp to single fp overflow");
-	v |= ((exp + 126) & 0xffL) << 23;
-	v |= e->h & 0x80000000L;
-	return v;
-}
-
-double
-ieeedtod(Ieee *ieeep)
-{
-	Ieee e;
-	double fr;
-	int exp;
-
-	if(ieeep->h & (1L<<31)) {
-		e.h = ieeep->h & ~(1L<<31);
-		e.l = ieeep->l;
-		return -ieeedtod(&e);
-	}
-	if(ieeep->l == 0 && ieeep->h == 0)
-		return 0;
-	fr = ieeep->l & ((1L<<16)-1L);
-	fr /= 1L<<16;
-	fr += (ieeep->l>>16) & ((1L<<16)-1L);
-	fr /= 1L<<16;
-	fr += (ieeep->h & (1L<<20)-1L) | (1L<<20);
-	fr /= 1L<<21;
-	exp = (ieeep->h>>20) & ((1L<<11)-1L);
-	exp -= (1L<<10) - 2L;
-	return ldexp(fr, exp);
-}
-
-void
-undefsym(Sym *s)
-{
-	int n;
-
-	n = imports;
-	if(s->value != 0)
-		diag("value != 0 on SXREF");
-	if(n >= 1<<Rindex)
-		diag("import index %d out of range", n);
-	s->value = n<<Roffset;
-	s->type = SUNDEF;
-	imports++;
-}
-
-void
-zerosig(char *sp)
-{
-	Sym *s;
-
-	s = lookup(sp, 0);
-	s->sig = 0;
-}
-
-void
-readundefs(char *f, int t)
-{
-	int i, n;
-	Sym *s;
-	Biobuf *b;
-	char *l, buf[256], *fields[64];
-
-	if(f == nil)
-		return;
-	b = Bopen(f, OREAD);
-	if(b == nil){
-		diag("could not open %s: %r", f);
-		errorexit();
-	}
-	while((l = Brdline(b, '\n')) != nil){
-		n = Blinelen(b);
-		if(n >= sizeof(buf)){
-			diag("%s: line too long", f);
-			errorexit();
-		}
-		memmove(buf, l, n);
-		buf[n-1] = '\0';
-		n = getfields(buf, fields, nelem(fields), 1, " \t\r\n");
-		if(n == nelem(fields)){
-			diag("%s: bad format", f);
-			errorexit();
-		}
-		for(i = 0; i < n; i++){
-			s = lookup(fields[i], 0);
-			s->type = SXREF;
-			s->subtype = t;
-			if(t == SIMPORT)
-				nimports++;
-			else
-				nexports++;
-		}
-	}
-	Bterm(b);
-}

+ 0 - 1194
sys/src/cmd/6l/optab.c

@@ -1,1194 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include	"l.h"
-
-uint8_t	ynone[] =
-{
-	Ynone,	Ynone,	Zlit,	1,
-	0
-};
-uint8_t	ytext[] =
-{
-	Ymb,	Yi32,	Zpseudo,1,
-	0
-};
-uint8_t	ynop[] =
-{
-	Ynone,	Ynone,	Zpseudo,1,
-	Ynone,	Yml,	Zpseudo,1,
-	Ynone,	Yrf,	Zpseudo,1,
-	Ynone,	Yxr,	Zpseudo,1,
-	Yml,	Ynone,	Zpseudo,1,
-	Yrf,	Ynone,	Zpseudo,1,
-	Yxr,	Ynone,	Zpseudo,1,
-	0
-};
-uint8_t	yxorb[] =
-{
-	Yi32,	Yal,	Zib_,	1,
-	Yi32,	Ymb,	Zibo_m,	2,
-	Yrb,	Ymb,	Zr_m,	1,
-	Ymb,	Yrb,	Zm_r,	1,
-	0
-};
-uint8_t	yxorl[] =
-{
-	Yi8,	Yml,	Zibo_m,	2,
-	Yi32,	Yax,	Zil_,	1,
-	Yi32,	Yml,	Zilo_m,	2,
-	Yrl,	Yml,	Zr_m,	1,
-	Yml,	Yrl,	Zm_r,	1,
-	0
-};
-uint8_t	yaddl[] =
-{
-	Yi8,	Yml,	Zibo_m,	2,
-	Yi32,	Yax,	Zil_,	1,
-	Yi32,	Yml,	Zilo_m,	2,
-	Yrl,	Yml,	Zr_m,	1,
-	Yml,	Yrl,	Zm_r,	1,
-	0
-};
-uint8_t	yincb[] =
-{
-	Ynone,	Ymb,	Zo_m,	2,
-	0
-};
-uint8_t	yincw[] =
-{
-	Ynone,	Yml,	Zo_m,	2,
-	0
-};
-uint8_t	yincl[] =
-{
-	Ynone,	Yml,	Zo_m,	2,
-	0
-};
-uint8_t	ycmpb[] =
-{
-	Yal,	Yi32,	Z_ib,	1,
-	Ymb,	Yi32,	Zm_ibo,	2,
-	Ymb,	Yrb,	Zm_r,	1,
-	Yrb,	Ymb,	Zr_m,	1,
-	0
-};
-uint8_t	ycmpl[] =
-{
-	Yml,	Yi8,	Zm_ibo,	2,
-	Yax,	Yi32,	Z_il,	1,
-	Yml,	Yi32,	Zm_ilo,	2,
-	Yml,	Yrl,	Zm_r,	1,
-	Yrl,	Yml,	Zr_m,	1,
-	0
-};
-uint8_t	yshb[] =
-{
-	Yi1,	Ymb,	Zo_m,	2,
-	Yi32,	Ymb,	Zibo_m,	2,
-	Ycx,	Ymb,	Zo_m,	2,
-	0
-};
-uint8_t	yshl[] =
-{
-	Yi1,	Yml,	Zo_m,	2,
-	Yi32,	Yml,	Zibo_m,	2,
-	Ycl,	Yml,	Zo_m,	2,
-	Ycx,	Yml,	Zo_m,	2,
-	0
-};
-uint8_t	ytestb[] =
-{
-	Yi32,	Yal,	Zib_,	1,
-	Yi32,	Ymb,	Zibo_m,	2,
-	Yrb,	Ymb,	Zr_m,	1,
-	Ymb,	Yrb,	Zm_r,	1,
-	0
-};
-uint8_t	ytestl[] =
-{
-	Yi32,	Yax,	Zil_,	1,
-	Yi32,	Yml,	Zilo_m,	2,
-	Yrl,	Yml,	Zr_m,	1,
-	Yml,	Yrl,	Zm_r,	1,
-	0
-};
-uint8_t	ymovb[] =
-{
-	Yrb,	Ymb,	Zr_m,	1,
-	Ymb,	Yrb,	Zm_r,	1,
-	Yi32,	Yrb,	Zib_rp,	1,
-	Yi32,	Ymb,	Zibo_m,	2,
-	0
-};
-uint8_t	ymbs[] =
-{
-	Ymb,	Ynone,	Zm_o,	2,
-	0
-};
-uint8_t	ybtl[] =
-{
-	Yi8,	Yml,	Zibo_m,	2,
-	Yrl,	Yml,	Zr_m,	1,
-	0
-};
-uint8_t	ymovw[] =
-{
-	Yrl,	Yml,	Zr_m,	1,
-	Yml,	Yrl,	Zm_r,	1,
-	Yi0,	Yrl,	Zclr,	1,
-	Yi32,	Yrl,	Zil_rp,	1,
-	Yi32,	Yml,	Zilo_m,	2,
-	Yiauto,	Yrl,	Zaut_r,	2,
-	0
-};
-uint8_t	ymovl[] =
-{
-	Yrl,	Yml,	Zr_m,	1,
-	Yml,	Yrl,	Zm_r,	1,
-	Yi0,	Yrl,	Zclr,	1,
-	Yi32,	Yrl,	Zil_rp,	1,
-	Yi32,	Yml,	Zilo_m,	2,
-	Yml,	Ymr,	Zm_r_xm,	1,	// MMX MOVD
-	Ymr,	Yml,	Zr_m_xm,	1,	// MMX MOVD
-	Yml,	Yxr,	Zm_r_xm,	2,	// XMM MOVD (32 bit)
-	Yxr,	Yml,	Zr_m_xm,	2,	// XMM MOVD (32 bit)
-	Yiauto,	Yrl,	Zaut_r,	2,
-	0
-};
-uint8_t	yret[] =
-{
-	Ynone,	Ynone,	Zo_iw,	1,
-	Yi32,	Ynone,	Zo_iw,	1,
-	0
-};
-uint8_t	ymovq[] =
-{
-	Yrl,	Yml,	Zr_m,	1,	// 0x89
-	Yml,	Yrl,	Zm_r,	1,	// 0x8b
-	Yi0,	Yrl,	Zclr,	1,	// 0x31
-	Ys32,	Yrl,	Zilo_m,	2,	// 32 bit signed 0xc7,(0)
-	Yi64,	Yrl,	Ziq_rp,	1,	// 0xb8 -- 32/64 bit immediate
-	Yi32,	Yml,	Zilo_m,	2,	// 0xc7,(0)
-	Ym,	Ymr,	Zm_r_xm_nr,	1,	// MMX MOVQ (shorter encoding)
-	Ymr,	Ym,	Zr_m_xm_nr,	1,	// MMX MOVQ
-	Ymm,	Ymr,	Zm_r_xm,	1,	// MMX MOVD
-	Ymr,	Ymm,	Zr_m_xm,	1,	// MMX MOVD
-	Yxr,	Ymr,	Zm_r_xm_nr,	2,	// MOVDQ2Q
-	Yxr,	Ym,	Zr_m_xm_nr,	2,	// MOVQ xmm store
-	Yml,	Yxr,	Zm_r_xm,	2,	// MOVD xmm load
-	Yxr,	Yml,	Zr_m_xm,	2,	// MOVD xmm store
-	Yiauto,	Yrl,	Zaut_r,	2,	// built-in LEAQ
-	0
-};
-uint8_t	ym_rl[] =
-{
-	Ym,	Yrl,	Zm_r,	1,
-	0
-};
-uint8_t	yrl_m[] =
-{
-	Yrl,	Ym,	Zr_m,	1,
-	0
-};
-uint8_t	ymb_rl[] =
-{
-	Ymb,	Yrl,	Zmb_r,	1,
-	0
-};
-uint8_t	yml_rl[] =
-{
-	Yml,	Yrl,	Zm_r,	1,
-	0
-};
-uint8_t	yrl_ml[] =
-{
-	Yrl,	Yml,	Zr_m,	1,
-	0
-};
-uint8_t	yml_mb[] =
-{
-	Yrb,	Ymb,	Zr_m,	1,
-	Ymb,	Yrb,	Zm_r,	1,
-	0
-};
-uint8_t	yrb_mb[] =
-{
-	Yrb,	Ymb,	Zr_m,	1,
-	0
-};
-uint8_t	yml_ml[] =
-{
-	Yrl,	Yml,	Zr_m,	1,
-	Yml,	Yrl,	Zm_r,	1,
-	0
-};
-uint8_t	ydivl[] =
-{
-	Yml,	Ynone,	Zm_o,	2,
-	0
-};
-uint8_t	ydivb[] =
-{
-	Ymb,	Ynone,	Zm_o,	2,
-	0
-};
-uint8_t	yimul[] =
-{
-	Yml,	Ynone,	Zm_o,	2,
-	Yi8,	Yrl,	Zib_rr,	1,
-	Yi32,	Yrl,	Zil_rr,	1,
-	Yml,	Yrl,	Zm_r,	2,
-	0
-};
-uint8_t	ybyte[] =
-{
-	Yi64,	Ynone,	Zbyte,	1,
-	0
-};
-uint8_t	yin[] =
-{
-	Yi32,	Ynone,	Zib_,	1,
-	Ynone,	Ynone,	Zlit,	1,
-	0
-};
-uint8_t	yint[] =
-{
-	Yi32,	Ynone,	Zib_,	1,
-	0
-};
-uint8_t	ypushl[] =
-{
-	Yrl,	Ynone,	Zrp_,	1,
-	Ym,	Ynone,	Zm_o,	2,
-	Yi8,	Ynone,	Zib_,	1,
-	Yi32,	Ynone,	Zil_,	1,
-	0
-};
-uint8_t	ypopl[] =
-{
-	Ynone,	Yrl,	Z_rp,	1,
-	Ynone,	Ym,	Zo_m,	2,
-	0
-};
-uint8_t	yscond[] =
-{
-	Ynone,	Ymb,	Zo_m,	2,
-	0
-};
-uint8_t	yjcond[] =
-{
-	Ynone,	Ybr,	Zbr,	1,
-	0
-};
-uint8_t	yloop[] =
-{
-	Ynone,	Ybr,	Zloop,	1,
-	0
-};
-uint8_t	ycall[] =
-{
-	Ynone,	Yml,	Zo_m64,	2,
-	Ynone,	Ybr,	Zcall,	1,
-	0
-};
-uint8_t	yjmp[] =
-{
-	Ynone,	Yml,	Zo_m64,	2,
-	Ynone,	Ybr,	Zjmp,	1,
-	0
-};
-
-uint8_t	yfmvd[] =
-{
-	Ym,	Yf0,	Zm_o,	2,
-	Yf0,	Ym,	Zo_m,	2,
-	Yrf,	Yf0,	Zm_o,	2,
-	Yf0,	Yrf,	Zo_m,	2,
-	0
-};
-uint8_t	yfmvdp[] =
-{
-	Yf0,	Ym,	Zo_m,	2,
-	Yf0,	Yrf,	Zo_m,	2,
-	0
-};
-uint8_t	yfmvf[] =
-{
-	Ym,	Yf0,	Zm_o,	2,
-	Yf0,	Ym,	Zo_m,	2,
-	0
-};
-uint8_t	yfmvx[] =
-{
-	Ym,	Yf0,	Zm_o,	2,
-	0
-};
-uint8_t	yfmvp[] =
-{
-	Yf0,	Ym,	Zo_m,	2,
-	0
-};
-uint8_t	yfadd[] =
-{
-	Ym,	Yf0,	Zm_o,	2,
-	Yrf,	Yf0,	Zm_o,	2,
-	Yf0,	Yrf,	Zo_m,	2,
-	0
-};
-uint8_t	yfaddp[] =
-{
-	Yf0,	Yrf,	Zo_m,	2,
-	0
-};
-uint8_t	yfxch[] =
-{
-	Yf0,	Yrf,	Zo_m,	2,
-	Yrf,	Yf0,	Zm_o,	2,
-	0
-};
-uint8_t	ycompp[] =
-{
-	Yf0,	Yrf,	Zo_m,	2,	/* botch is really f0,f1 */
-	0
-};
-uint8_t	ystsw[] =
-{
-	Ynone,	Ym,	Zo_m,	2,
-	Ynone,	Yax,	Zlit,	1,
-	0
-};
-uint8_t	ystcw[] =
-{
-	Ynone,	Ym,	Zo_m,	2,
-	Ym,	Ynone,	Zm_o,	2,
-	0
-};
-uint8_t	ysvrs[] =
-{
-	Ynone,	Ym,	Zo_m,	2,
-	Ym,	Ynone,	Zm_o,	2,
-	0
-};
-uint8_t	ymm[] = 
-{
-	Ymm,	Ymr,	Zm_r_xm,	1,
-	Yxm,	Yxr,	Zm_r_xm,	2,
-	0
-};
-uint8_t	yxm[] = 
-{
-	Yxm,	Yxr,	Zm_r_xm,	1,
-	0
-};
-uint8_t	yxcvm1[] = 
-{
-	Yxm,	Yxr,	Zm_r_xm,	2,
-	Yxm,	Ymr,	Zm_r_xm,	2,
-	0
-};
-uint8_t	yxcvm2[] =
-{
-	Yxm,	Yxr,	Zm_r_xm,	2,
-	Ymm,	Yxr,	Zm_r_xm,	2,
-	0
-};
-uint8_t	yxmq[] = 
-{
-	Yxm,	Yxr,	Zm_r_xm,	2,
-	0
-};
-uint8_t	yxr[] = 
-{
-	Yxr,	Yxr,	Zm_r_xm,	1,
-	0
-};
-uint8_t	yxr_ml[] =
-{
-	Yxr,	Yml,	Zr_m_xm,	1,
-	0
-};
-uint8_t	ymr[] =
-{
-	Ymr,	Ymr,	Zm_r,	1,
-	0
-};
-uint8_t	ymr_ml[] =
-{
-	Ymr,	Yml,	Zr_m_xm,	1,
-	0
-};
-uint8_t	yxcmp[] =
-{
-	Yxm,	Yxr, Zm_r_xm,	1,
-	0
-};
-uint8_t	yxcmpi[] =
-{
-	Yxm,	Yxr, Zm_r_i_xm,	2,
-	0
-};
-uint8_t	yxmov[] =
-{
-	Yxm,	Yxr,	Zm_r_xm,	1,
-	Yxr,	Yxm,	Zr_m_xm,	1,
-	0
-};
-uint8_t	yxcvfl[] = 
-{
-	Yxm,	Yrl,	Zm_r_xm,	1,
-	0
-};
-uint8_t	yxcvlf[] =
-{
-	Yml,	Yxr,	Zm_r_xm,	1,
-	0
-};
-uint8_t	yxcvfq[] = 
-{
-	Yxm,	Yrl,	Zm_r_xm,	2,
-	0
-};
-uint8_t	yxcvqf[] =
-{
-	Yml,	Yxr,	Zm_r_xm,	2,
-	0
-};
-uint8_t	yps[] = 
-{
-	Ymm,	Ymr,	Zm_r_xm,	1,
-	Yi8,	Ymr,	Zibo_m_xm,	2,
-	Yxm,	Yxr,	Zm_r_xm,	2,
-	Yi8,	Yxr,	Zibo_m_xm,	3,
-	0
-};
-uint8_t	yxrrl[] =
-{
-	Yxr,	Yrl,	Zm_r,	1,
-	0
-};
-uint8_t	ymfp[] =
-{
-	Ymm,	Ymr,	Zm_r_3d,	1,
-	0,
-};
-uint8_t	ymrxr[] =
-{
-	Ymr,	Yxr,	Zm_r,	1,
-	Yxm,	Yxr,	Zm_r_xm,	1,
-	0
-};
-uint8_t	ymshuf[] =
-{
-	Ymm,	Ymr,	Zibm_r,	1,
-	0
-};
-uint8_t	yxshuf[] =
-{
-	Yxm,	Yxr,	Zibm_r,	1,
-	0
-};
-uint8_t	yextrw[] =
-{
-	Yxr,	Yrl,	Zibm_r,	1,
-	0
-};
-uint8_t	ypsdq[] =
-{
-	Yi8,	Yxr,	Zibo_m,	2,
-	0
-};
-uint8_t	ymskb[] =
-{
-	Yxr,	Yrl,	Zm_r_xm,	2,
-	Ymr,	Yrl,	Zm_r_xm,	1,
-	0
-};
-
-Optab optab[] =
-/*	as, ytab, andproto, opcode */
-{
-	{ AXXX },
-	{ AAAA,		ynone,	P32, 0x37 },
-	{ AAAD,		ynone,	P32, 0xd5,0x0a },
-	{ AAAM,		ynone,	P32, 0xd4,0x0a },
-	{ AAAS,		ynone,	P32, 0x3f },
-	{ AADCB,	yxorb,	Pb, 0x14,0x80,(02),0x10,0x10 },
-	{ AADCL,	yxorl,	Px, 0x83,(02),0x15,0x81,(02),0x11,0x13 },
-	{ AADCQ,	yxorl,	Pw, 0x83,(02),0x15,0x81,(02),0x11,0x13 },
-	{ AADCW,	yxorl,	Pe, 0x83,(02),0x15,0x81,(02),0x11,0x13 },
-	{ AADDB,	yxorb,	Pb, 0x04,0x80,(00),0x00,0x02 },
-	{ AADDL,	yaddl,	Px, 0x83,(00),0x05,0x81,(00),0x01,0x03 },
-	{ AADDPD,	yxm,	Pq, 0x58 },
-	{ AADDPS,	yxm,	Pm, 0x58 },
-	{ AADDQ,	yaddl,	Pw, 0x83,(00),0x05,0x81,(00),0x01,0x03 },
-	{ AADDSD,	yxm,	Pf2, 0x58 },
-	{ AADDSS,	yxm,	Pf3, 0x58 },
-	{ AADDW,	yaddl,	Pe, 0x83,(00),0x05,0x81,(00),0x01,0x03 },
-	{ AADJSP },
-	{ AANDB,	yxorb,	Pb, 0x24,0x80,(04),0x20,0x22 },
-	{ AANDL,	yxorl,	Px, 0x83,(04),0x25,0x81,(04),0x21,0x23 },
-	{ AANDNPD,	yxm,	Pq, 0x55 },
-	{ AANDNPS,	yxm,	Pm, 0x55 },
-	{ AANDPD,	yxm,	Pq, 0x54 },
-	{ AANDPS,	yxm,	Pq, 0x54 },
-	{ AANDQ,	yxorl,	Pw, 0x83,(04),0x25,0x81,(04),0x21,0x23 },
-	{ AANDW,	yxorl,	Pe, 0x83,(04),0x25,0x81,(04),0x21,0x23 },
-	{ AARPL,	yrl_ml,	P32, 0x63 },
-	{ ABOUNDL,	yrl_m,	P32, 0x62 },
-	{ ABOUNDW,	yrl_m,	Pe, 0x62 },
-	{ ABSFL,	yml_rl,	Pm, 0xbc },
-	{ ABSFQ,	yml_rl,	Pw, 0x0f,0xbc },
-	{ ABSFW,	yml_rl,	Pq, 0xbc },
-	{ ABSRL,	yml_rl,	Pm, 0xbd },
-	{ ABSRQ,	yml_rl,	Pw, 0x0f,0xbd },
-	{ ABSRW,	yml_rl,	Pq, 0xbd },
-	{ ABTCL,	ybtl,	Pm, 0xba,(07),0xbb },
-	{ ABTCQ,	ybtl,	Pw, 0x0f,0xba,(07),0x0f,0xbb },
-	{ ABTCW,	ybtl,	Pq, 0xba,(07),0xbb },
-	{ ABTL,		ybtl,	Pm, 0xba,(04),0xa3 },
-	{ ABTQ,		ybtl,	Pw, 0x0f,0xba,(04),0x0f,0xa3},
-	{ ABTRL,	ybtl,	Pm, 0xba,(06),0xb3 },
-	{ ABTRQ,	ybtl,	Pw, 0x0f,0xba,(06),0x0f,0xb3 },
-	{ ABTRW,	ybtl,	Pq, 0xba,(06),0xb3 },
-	{ ABTSL,	ybtl,	Pm, 0xba,(05),0xab  },
-	{ ABTSQ,	ybtl,	Pw, 0x0f,0xba,(05),0x0f,0xab },
-	{ ABTSW,	ybtl,	Pq, 0xba,(05),0xab  },
-	{ ABTW,		ybtl,	Pq, 0xba,(04),0xa3 },
-	{ ABYTE,	ybyte,	Px, 1 },
-	{ ACALL,	ycall,	Px, 0xff,(02),0xe8 },
-	{ ACDQ,		ynone,	Px, 0x99 },
-	{ ACLC,		ynone,	Px, 0xf8 },
-	{ ACLD,		ynone,	Px, 0xfc },
-	{ ACLI,		ynone,	Px, 0xfa },
-	{ ACLTS,	ynone,	Pm, 0x06 },
-	{ ACMC,		ynone,	Px, 0xf5 },
-	{ ACMOVLCC,	yml_rl,	Pm, 0x43 },
-	{ ACMOVLCS,	yml_rl,	Pm, 0x42 },
-	{ ACMOVLEQ,	yml_rl,	Pm, 0x44 },
-	{ ACMOVLGE,	yml_rl,	Pm, 0x4d },
-	{ ACMOVLGT,	yml_rl,	Pm, 0x4f },
-	{ ACMOVLHI,	yml_rl,	Pm, 0x47 },
-	{ ACMOVLLE,	yml_rl,	Pm, 0x4e },
-	{ ACMOVLLS,	yml_rl,	Pm, 0x46 },
-	{ ACMOVLLT,	yml_rl,	Pm, 0x4c },
-	{ ACMOVLMI,	yml_rl,	Pm, 0x48 },
-	{ ACMOVLNE,	yml_rl,	Pm, 0x45 },
-	{ ACMOVLOC,	yml_rl,	Pm, 0x41 },
-	{ ACMOVLOS,	yml_rl,	Pm, 0x40 },
-	{ ACMOVLPC,	yml_rl,	Pm, 0x4b },
-	{ ACMOVLPL,	yml_rl,	Pm, 0x49 },
-	{ ACMOVLPS,	yml_rl,	Pm, 0x4a },
-	{ ACMOVQCC,	yml_rl,	Pw, 0x0f,0x43 },
-	{ ACMOVQCS,	yml_rl,	Pw, 0x0f,0x42 },
-	{ ACMOVQEQ,	yml_rl,	Pw, 0x0f,0x44 },
-	{ ACMOVQGE,	yml_rl,	Pw, 0x0f,0x4d },
-	{ ACMOVQGT,	yml_rl,	Pw, 0x0f,0x4f },
-	{ ACMOVQHI,	yml_rl,	Pw, 0x0f,0x47 },
-	{ ACMOVQLE,	yml_rl,	Pw, 0x0f,0x4e },
-	{ ACMOVQLS,	yml_rl,	Pw, 0x0f,0x46 },
-	{ ACMOVQLT,	yml_rl,	Pw, 0x0f,0x4c },
-	{ ACMOVQMI,	yml_rl,	Pw, 0x0f,0x48 },
-	{ ACMOVQNE,	yml_rl,	Pw, 0x0f,0x45 },
-	{ ACMOVQOC,	yml_rl,	Pw, 0x0f,0x41 },
-	{ ACMOVQOS,	yml_rl,	Pw, 0x0f,0x40 },
-	{ ACMOVQPC,	yml_rl,	Pw, 0x0f,0x4b },
-	{ ACMOVQPL,	yml_rl,	Pw, 0x0f,0x49 },
-	{ ACMOVQPS,	yml_rl,	Pw, 0x0f,0x4a },
-	{ ACMOVWCC,	yml_rl,	Pq, 0x43 },
-	{ ACMOVWCS,	yml_rl,	Pq, 0x42 },
-	{ ACMOVWEQ,	yml_rl,	Pq, 0x44 },
-	{ ACMOVWGE,	yml_rl,	Pq, 0x4d },
-	{ ACMOVWGT,	yml_rl,	Pq, 0x4f },
-	{ ACMOVWHI,	yml_rl,	Pq, 0x47 },
-	{ ACMOVWLE,	yml_rl,	Pq, 0x4e },
-	{ ACMOVWLS,	yml_rl,	Pq, 0x46 },
-	{ ACMOVWLT,	yml_rl,	Pq, 0x4c },
-	{ ACMOVWMI,	yml_rl,	Pq, 0x48 },
-	{ ACMOVWNE,	yml_rl,	Pq, 0x45 },
-	{ ACMOVWOC,	yml_rl,	Pq, 0x41 },
-	{ ACMOVWOS,	yml_rl,	Pq, 0x40 },
-	{ ACMOVWPC,	yml_rl,	Pq, 0x4b },
-	{ ACMOVWPL,	yml_rl,	Pq, 0x49 },
-	{ ACMOVWPS,	yml_rl,	Pq, 0x4a },
-	{ ACMPB,	ycmpb,	Pb, 0x3c,0x80,(07),0x38,0x3a },
-	{ ACMPL,	ycmpl,	Px, 0x83,(07),0x3d,0x81,(07),0x39,0x3b },
-	{ ACMPPD,	yxcmpi,	Px, Pe,0xc2 },
-	{ ACMPPS,	yxcmpi,	Pm, 0xc2,0 },
-	{ ACMPQ,	ycmpl,	Pw, 0x83,(07),0x3d,0x81,(07),0x39,0x3b },
-	{ ACMPSB,	ynone,	Pb, 0xa6 },
-	{ ACMPSD,	yxcmpi,	Px, Pf2,0xc2 },
-	{ ACMPSL,	ynone,	Px, 0xa7 },
-	{ ACMPSQ,	ynone,	Pw, 0xa7 },
-	{ ACMPSS,	yxcmpi,	Px, Pf3,0xc2 },
-	{ ACMPSW,	ynone,	Pe, 0xa7 },
-	{ ACMPW,	ycmpl,	Pe, 0x83,(07),0x3d,0x81,(07),0x39,0x3b },
-	{ ACOMISD,	yxcmp,	Pe, 0x2f },
-	{ ACOMISS,	yxcmp,	Pm, 0x2f },
-	{ ACPUID,	ynone,	Pm, 0xa2 },
-	{ ACVTPL2PD,	yxcvm2,	Px, Pf3,0xe6,Pe,0x2a },
-	{ ACVTPL2PS,	yxcvm2,	Pm, 0x5b,0,0x2a,0, },
-	{ ACVTPD2PL,	yxcvm1,	Px, Pf2,0xe6,Pe,0x2d },
-	{ ACVTPD2PS,	yxm,	Pe, 0x5a },
-	{ ACVTPS2PL,	yxcvm1, Px, Pe,0x5b,Pm,0x2d },
-	{ ACVTPS2PD,	yxm,	Pm, 0x5a },
-	{ API2FW,	ymfp,	Px, 0x0c },
-	{ ACVTSD2SL,	yxcvfl, Pf2, 0x2d },
-	{ ACVTSD2SQ,	yxcvfq, Pw, Pf2,0x2d },
-	{ ACVTSD2SS,	yxm,	Pf2, 0x5a },
-	{ ACVTSL2SD,	yxcvlf, Pf2, 0x2a },
-	{ ACVTSQ2SD,	yxcvqf, Pw, Pf2,0x2a },
-	{ ACVTSL2SS,	yxcvlf, Pf3, 0x2a },
-	{ ACVTSQ2SS,	yxcvqf, Pw, Pf3,0x2a },
-	{ ACVTSS2SD,	yxm,	Pf3, 0x5a },
-	{ ACVTSS2SL,	yxcvfl, Pf3, 0x2d },
-	{ ACVTSS2SQ,	yxcvfq, Pw, Pf3,0x2d },
-	{ ACVTTPD2PL,	yxcvm1,	Px, Pe,0xe6,Pe,0x2c },
-	{ ACVTTPS2PL,	yxcvm1,	Px, Pf3,0x5b,Pm,0x2c },
-	{ ACVTTSD2SL,	yxcvfl, Pf2, 0x2c },
-	{ ACVTTSD2SQ,	yxcvfq, Pw, Pf2,0x2c },
-	{ ACVTTSS2SL,	yxcvfl,	Pf3, 0x2c },
-	{ ACVTTSS2SQ,	yxcvfq, Pw, Pf3,0x2c },
-	{ ACWD,		ynone,	Pe, 0x99 },
-	{ ACQO,		ynone,	Pw, 0x99 },
-	{ ADAA,		ynone,	P32, 0x27 },
-	{ ADAS,		ynone,	P32, 0x2f },
-	{ ADATA },
-	{ ADECB,	yincb,	Pb, 0xfe,(01) },
-	{ ADECL,	yincl,	Px, 0xff,(01) },
-	{ ADECQ,	yincl,	Pw, 0xff,(01) },
-	{ ADECW,	yincw,	Pe, 0xff,(01) },
-	{ ADIVB,	ydivb,	Pb, 0xf6,(06) },
-	{ ADIVL,	ydivl,	Px, 0xf7,(06) },
-	{ ADIVPD,	yxm,	Pe, 0x5e },
-	{ ADIVPS,	yxm,	Pm, 0x5e },
-	{ ADIVQ,	ydivl,	Pw, 0xf7,(06) },
-	{ ADIVSD,	yxm,	Pf2, 0x5e },
-	{ ADIVSS,	yxm,	Pf3, 0x5e },
-	{ ADIVW,	ydivl,	Pe, 0xf7,(06) },
-	{ AEMMS,	ynone,	Pm, 0x77 },
-	{ AENTER },				/* botch */
-	{ AFXRSTOR,	ysvrs,	Pm, 0xae,(01),0xae,(01) },
-	{ AFXSAVE,	ysvrs,	Pm, 0xae,(00),0xae,(00) },
-	{ AFXRSTOR64,	ysvrs,	Pw, 0x0f,0xae,(01),0x0f,0xae,(01) },
-	{ AFXSAVE64,	ysvrs,	Pw, 0x0f,0xae,(00),0x0f,0xae,(00) },
-	{ AGLOBL },
-	{ AGOK },
-	{ AHISTORY },
-	{ AHLT,		ynone,	Px, 0xf4 },
-	{ AIDIVB,	ydivb,	Pb, 0xf6,(07) },
-	{ AIDIVL,	ydivl,	Px, 0xf7,(07) },
-	{ AIDIVQ,	ydivl,	Pw, 0xf7,(07) },
-	{ AIDIVW,	ydivl,	Pe, 0xf7,(07) },
-	{ AIMULB,	ydivb,	Pb, 0xf6,(05) },
-	{ AIMULL,	yimul,	Px, 0xf7,(05),0x6b,0x69,Pm,0xaf },
-	{ AIMULQ,	yimul,	Pw, 0xf7,(05),0x6b,0x69,Pm,0xaf },
-	{ AIMULW,	yimul,	Pe, 0xf7,(05),0x6b,0x69,Pm,0xaf },
-	{ AINB,		yin,	Pb, 0xe4,0xec },
-	{ AINCB,	yincb,	Pb, 0xfe,(00) },
-	{ AINCL,	yincl,	Px, 0xff,(00) },
-	{ AINCQ,	yincl,	Pw, 0xff,(00) },
-	{ AINCW,	yincw,	Pe, 0xff,(00) },
-	{ AINL,		yin,	Px, 0xe5,0xed },
-	{ AINSB,	ynone,	Pb, 0x6c },
-	{ AINSL,	ynone,	Px, 0x6d },
-	{ AINSW,	ynone,	Pe, 0x6d },
-	{ AINT,		yint,	Px, 0xcd },
-	{ AINTO,	ynone,	P32, 0xce },
-	{ AINW,		yin,	Pe, 0xe5,0xed },
-	{ AIRETL,	ynone,	Px, 0xcf },
-	{ AIRETQ,	ynone,	Pw, 0xcf },
-	{ AIRETW,	ynone,	Pe, 0xcf },
-	{ AJCC,		yjcond,	Px, 0x73,0x83,(00) },
-	{ AJCS,		yjcond,	Px, 0x72,0x82 },
-	{ AJCXZ,	yloop,	Px, 0xe3 },
-	{ AJEQ,		yjcond,	Px, 0x74,0x84 },
-	{ AJGE,		yjcond,	Px, 0x7d,0x8d },
-	{ AJGT,		yjcond,	Px, 0x7f,0x8f },
-	{ AJHI,		yjcond,	Px, 0x77,0x87 },
-	{ AJLE,		yjcond,	Px, 0x7e,0x8e },
-	{ AJLS,		yjcond,	Px, 0x76,0x86 },
-	{ AJLT,		yjcond,	Px, 0x7c,0x8c },
-	{ AJMI,		yjcond,	Px, 0x78,0x88 },
-	{ AJMP,		yjmp,	Px, 0xff,(04),0xeb,0xe9 },
-	{ AJNE,		yjcond,	Px, 0x75,0x85 },
-	{ AJOC,		yjcond,	Px, 0x71,0x81,(00) },
-	{ AJOS,		yjcond,	Px, 0x70,0x80,(00) },
-	{ AJPC,		yjcond,	Px, 0x7b,0x8b },
-	{ AJPL,		yjcond,	Px, 0x79,0x89 },
-	{ AJPS,		yjcond,	Px, 0x7a,0x8a },
-	{ ALAHF,	ynone,	Px, 0x9f },
-	{ ALARL,	yml_rl,	Pm, 0x02 },
-	{ ALARW,	yml_rl,	Pq, 0x02 },
-	{ ALDMXCSR,	ysvrs,	Pm, 0xae,(02),0xae,(02) },
-	{ ALEAL,	ym_rl,	Px, 0x8d },
-	{ ALEAQ,	ym_rl,	Pw, 0x8d },
-	{ ALEAVEL,	ynone,	P32, 0xc9 },
-	{ ALEAVEQ,	ynone,	Py, 0xc9 },
-	{ ALEAVEW,	ynone,	Pe, 0xc9 },
-	{ ALEAW,	ym_rl,	Pe, 0x8d },
-	{ ALOCK,	ynone,	Px, 0xf0 },
-	{ ALODSB,	ynone,	Pb, 0xac },
-	{ ALODSL,	ynone,	Px, 0xad },
-	{ ALODSQ,	ynone,	Pw, 0xad },
-	{ ALODSW,	ynone,	Pe, 0xad },
-	{ ALONG,	ybyte,	Px, 4 },
-	{ ALOOP,	yloop,	Px, 0xe2 },
-	{ ALOOPEQ,	yloop,	Px, 0xe1 },
-	{ ALOOPNE,	yloop,	Px, 0xe0 },
-	{ ALSLL,	yml_rl,	Pm, 0x03  },
-	{ ALSLW,	yml_rl,	Pq, 0x03  },
-	{ AMASKMOVOU,	yxr,	Pe, 0xf7 },
-	{ AMASKMOVQ,	ymr,	Pm, 0xf7 },
-	{ AMAXPD,	yxm,	Pe, 0x5f },
-	{ AMAXPS,	yxm,	Pm, 0x5f },
-	{ AMAXSD,	yxm,	Pf2, 0x5f },
-	{ AMAXSS,	yxm,	Pf3, 0x5f },
-	{ AMINPD,	yxm,	Pe, 0x5d },
-	{ AMINPS,	yxm,	Pm, 0x5d },
-	{ AMINSD,	yxm,	Pf2, 0x5d },
-	{ AMINSS,	yxm,	Pf3, 0x5d },
-	{ AMOVAPD,	yxmov,	Pe, 0x28,0x29 },
-	{ AMOVAPS,	yxmov,	Pm, 0x28,0x29 },
-	{ AMOVB,	ymovb,	Pb, 0x88,0x8a,0xb0,0xc6,(00) },
-	{ AMOVBLSX,	ymb_rl,	Pm, 0xbe },
-	{ AMOVBLZX,	ymb_rl,	Pm, 0xb6 },
-	{ AMOVBQSX,	ymb_rl,	Pw, 0x0f,0xbe },
-	{ AMOVBQZX,	ymb_rl,	Pw, 0x0f,0xb6 },
-	{ AMOVBWSX,	ymb_rl,	Pq, 0xbe },
-	{ AMOVBWZX,	ymb_rl,	Pq, 0xb6 },
-	{ AMOVO,	yxmov,	Pe, 0x6f,0x7f },
-	{ AMOVOU,	yxmov,	Pf3, 0x6f,0x7f },
-	{ AMOVHLPS,	yxr,	Pm, 0x12 },
-	{ AMOVHPD,	yxmov,	Pe, 0x16,0x17 },
-	{ AMOVHPS,	yxmov,	Pm, 0x16,0x17 },
-	{ AMOVL,	ymovl,	Px, 0x89,0x8b,0x31,0xb8,0xc7,(00),0x6e,0x7e,Pe,0x6e,Pe,0x7e },
-	{ AMOVLHPS,	yxr,	Pm, 0x16 },
-	{ AMOVLPD,	yxmov,	Pe, 0x12,0x13 },
-	{ AMOVLPS,	yxmov,	Pm, 0x12,0x13 },
-	{ AMOVLQSX,	yml_rl,	Pw, 0x63 },
-	{ AMOVLQZX,	yml_rl,	Px, 0x8b },
-	{ AMOVMSKPD,	yxrrl,	Pq, 0x50 },
-	{ AMOVMSKPS,	yxrrl,	Pm, 0x50 },
-	{ AMOVNTO,	yxr_ml,	Pe, 0xe7 },
-	{ AMOVNTPD,	yxr_ml,	Pe, 0x2b },
-	{ AMOVNTPS,	yxr_ml,	Pm, 0x2b },
-	{ AMOVNTQ,	ymr_ml,	Pm, 0xe7 },
-	{ AMOVQ,	ymovq,	Pw, 0x89,0x8b,0x31,0xc7,(00),0xb8,0xc7,(00),0x6f,0x7f,0x6e,0x7e,Pf2,0xd6,Pe,0xd6,Pe,0x6e,Pe,0x7e },
-	{ AMOVQOZX,	ymrxr,	Pf3, 0xd6,0x7e },
-	{ AMOVSB,	ynone,	Pb, 0xa4 },
-	{ AMOVSD,	yxmov,	Pf2, 0x10,0x11 },
-	{ AMOVSL,	ynone,	Px, 0xa5 },
-	{ AMOVSQ,	ynone,	Pw, 0xa5 },
-	{ AMOVSS,	yxmov,	Pf3, 0x10,0x11 },
-	{ AMOVSW,	ynone,	Pe, 0xa5 },
-	{ AMOVUPD,	yxmov,	Pe, 0x10,0x11 },
-	{ AMOVUPS,	yxmov,	Pm, 0x10,0x11 },
-	{ AMOVW,	ymovw,	Pe, 0x89,0x8b,0x31,0xb8,0xc7,(00) },
-	{ AMOVWLSX,	yml_rl,	Pm, 0xbf },
-	{ AMOVWLZX,	yml_rl,	Pm, 0xb7 },
-	{ AMOVWQSX,	yml_rl,	Pw, 0x0f,0xbf },
-	{ AMOVWQZX,	yml_rl,	Pw, 0x0f,0xb7 },
-	{ AMULB,	ydivb,	Pb, 0xf6,(04) },
-	{ AMULL,	ydivl,	Px, 0xf7,(04) },
-	{ AMULPD,	yxm,	Pe, 0x59 },
-	{ AMULPS,	yxm,	Ym, 0x59 },
-	{ AMULQ,	ydivl,	Pw, 0xf7,(04) },
-	{ AMULSD,	yxm,	Pf2, 0x59 },
-	{ AMULSS,	yxm,	Pf3, 0x59 },
-	{ AMULW,	ydivl,	Pe, 0xf7,(04) },
-	{ ANAME },
-	{ ANEGB,	yscond,	Pb, 0xf6,(03) },
-	{ ANEGL,	yscond,	Px, 0xf7,(03) },
-	{ ANEGQ,	yscond,	Pw, 0xf7,(03) },
-	{ ANEGW,	yscond,	Pe, 0xf7,(03) },
-	{ ANOP,		ynop,	Px, 0,0 },
-	{ ANOTB,	yscond,	Pb, 0xf6,(02) },
-	{ ANOTL,	yscond,	Px, 0xf7,(02) },
-	{ ANOTQ,	yscond,	Pw, 0xf7,(02) },
-	{ ANOTW,	yscond,	Pe, 0xf7,(02) },
-	{ AORB,		yxorb,	Pb, 0x0c,0x80,(01),0x08,0x0a },
-	{ AORL,		yxorl,	Px, 0x83,(01),0x0d,0x81,(01),0x09,0x0b },
-	{ AORPD,	yxm,	Pq, 0x56 },
-	{ AORPS,	yxm,	Pm, 0x56 },
-	{ AORQ,		yxorl,	Pw, 0x83,(01),0x0d,0x81,(01),0x09,0x0b },
-	{ AORW,		yxorl,	Pe, 0x83,(01),0x0d,0x81,(01),0x09,0x0b },
-	{ AOUTB,	yin,	Pb, 0xe6,0xee },
-	{ AOUTL,	yin,	Px, 0xe7,0xef },
-	{ AOUTSB,	ynone,	Pb, 0x6e },
-	{ AOUTSL,	ynone,	Px, 0x6f },
-	{ AOUTSW,	ynone,	Pe, 0x6f },
-	{ AOUTW,	yin,	Pe, 0xe7,0xef },
-	{ APACKSSLW,	ymm,	Py, 0x6b,Pe,0x6b },
-	{ APACKSSWB,	ymm,	Py, 0x63,Pe,0x63 },
-	{ APACKUSWB,	ymm,	Py, 0x67,Pe,0x67 },
-	{ APADDB,	ymm,	Py, 0xfc,Pe,0xfc },
-	{ APADDL,	ymm,	Py, 0xfe,Pe,0xfe },
-	{ APADDQ,	yxm,	Pe, 0xd4 },
-	{ APADDSB,	ymm,	Py, 0xec,Pe,0xec },
-	{ APADDSW,	ymm,	Py, 0xed,Pe,0xed },
-	{ APADDUSB,	ymm,	Py, 0xdc,Pe,0xdc },
-	{ APADDUSW,	ymm,	Py, 0xdd,Pe,0xdd },
-	{ APADDW,	ymm,	Py, 0xfd,Pe,0xfd },
-	{ APAND,	ymm,	Py, 0xdb,Pe,0xdb },
-	{ APANDN,	ymm,	Py, 0xdf,Pe,0xdf },
-	{ APAVGB,	ymm,	Py, 0xe0,Pe,0xe0 },
-	{ APAVGW,	ymm,	Py, 0xe3,Pe,0xe3 },
-	{ APCMPEQB,	ymm,	Py, 0x74,Pe,0x74 },
-	{ APCMPEQL,	ymm,	Py, 0x76,Pe,0x76 },
-	{ APCMPEQW,	ymm,	Py, 0x75,Pe,0x75 },
-	{ APCMPGTB,	ymm,	Py, 0x64,Pe,0x64 },
-	{ APCMPGTL,	ymm,	Py, 0x66,Pe,0x66 },
-	{ APCMPGTW,	ymm,	Py, 0x65,Pe,0x65 },
-	{ APEXTRW,	yextrw,	Pq, 0xc5 },
-	{ APF2IL,	ymfp,	Px, 0x1d },
-	{ APF2IW,	ymfp,	Px, 0x1c },
-	{ API2FL,	ymfp,	Px, 0x0d },
-	{ APFACC,	ymfp,	Px, 0xae },
-	{ APFADD,	ymfp,	Px, 0x9e },
-	{ APFCMPEQ,	ymfp,	Px, 0xb0 },
-	{ APFCMPGE,	ymfp,	Px, 0x90 },
-	{ APFCMPGT,	ymfp,	Px, 0xa0 },
-	{ APFMAX,	ymfp,	Px, 0xa4 },
-	{ APFMIN,	ymfp,	Px, 0x94 },
-	{ APFMUL,	ymfp,	Px, 0xb4 },
-	{ APFNACC,	ymfp,	Px, 0x8a },
-	{ APFPNACC,	ymfp,	Px, 0x8e },
-	{ APFRCP,	ymfp,	Px, 0x96 },
-	{ APFRCPIT1,	ymfp,	Px, 0xa6 },
-	{ APFRCPI2T,	ymfp,	Px, 0xb6 },
-	{ APFRSQIT1,	ymfp,	Px, 0xa7 },
-	{ APFRSQRT,	ymfp,	Px, 0x97 },
-	{ APFSUB,	ymfp,	Px, 0x9a },
-	{ APFSUBR,	ymfp,	Px, 0xaa },
-	{ APINSRW,	yextrw,	Pq, 0xc4 },
-	{ APMADDWL,	ymm,	Py, 0xf5,Pe,0xf5 },
-	{ APMAXSW,	yxm,	Pe, 0xee },
-	{ APMAXUB,	yxm,	Pe, 0xde },
-	{ APMINSW,	yxm,	Pe, 0xea },
-	{ APMINUB,	yxm,	Pe, 0xda },
-	{ APMOVMSKB,	ymskb,	Px, Pe,0xd7,0xd7 },
-	{ APMULHRW,	ymfp,	Px, 0xb7 },
-	{ APMULHUW,	ymm,	Py, 0xe4,Pe,0xe4 },
-	{ APMULHW,	ymm,	Py, 0xe5,Pe,0xe5 },
-	{ APMULLW,	ymm,	Py, 0xd5,Pe,0xd5 },
-	{ APMULULQ,	ymm,	Py, 0xf4,Pe,0xf4 },
-	{ APOPAL,	ynone,	P32, 0x61 },
-	{ APOPAW,	ynone,	Pe, 0x61 },
-	{ APOPFL,	ynone,	P32, 0x9d },
-	{ APOPFQ,	ynone,	Py, 0x9d },
-	{ APOPFW,	ynone,	Pe, 0x9d },
-	{ APOPL,	ypopl,	P32, 0x58,0x8f,(00) },
-	{ APOPQ,	ypopl,	Py, 0x58,0x8f,(00) },
-	{ APOPW,	ypopl,	Pe, 0x58,0x8f,(00) },
-	{ APOR,		ymm,	Py, 0xeb,Pe,0xeb },
-	{ APSADBW,	yxm,	Pq, 0xf6 },
-	{ APSHUFHW,	yxshuf,	Pf3, 0x70 },
-	{ APSHUFL,	yxshuf,	Pq, 0x70 },
-	{ APSHUFLW,	yxshuf,	Pf2, 0x70 },
-	{ APSHUFW,	ymshuf,	Pm, 0x70 },
-	{ APSLLO,	ypsdq,	Pq, 0x73,(07) },
-	{ APSLLL,	yps,	Py, 0xf2, 0x72,(06), Pe,0xf2, Pe,0x72,(06) },
-	{ APSLLQ,	yps,	Py, 0xf3, 0x73,(06), Pe,0xf3, Pe,0x7e,(06) },
-	{ APSLLW,	yps,	Py, 0xf1, 0x71,(06), Pe,0xf1, Pe,0x71,(06) },
-	{ APSRAL,	yps,	Py, 0xe2, 0x72,(04), Pe,0xe2, Pe,0x72,(04) },
-	{ APSRAW,	yps,	Py, 0xe1, 0x71,(04), Pe,0xe1, Pe,0x71,(04) },
-	{ APSRLO,	ypsdq,	Pq, 0x73,(03) },
-	{ APSRLL,	yps,	Py, 0xd2, 0x72,(02), Pe,0xd2, Pe,0x72,(02) },
-	{ APSRLQ,	yps,	Py, 0xd3, 0x73,(02), Pe,0xd3, Pe,0x73,(02) },
-	{ APSRLW,	yps,	Py, 0xd1, 0x71,(02), Pe,0xe1, Pe,0x71,(02) },
-	{ APSUBB,	yxm,	Pe, 0xf8 },
-	{ APSUBL,	yxm,	Pe, 0xfa },
-	{ APSUBQ,	yxm,	Pe, 0xfb },
-	{ APSUBSB,	yxm,	Pe, 0xe8 },
-	{ APSUBSW,	yxm,	Pe, 0xe9 },
-	{ APSUBUSB,	yxm,	Pe, 0xd8 },
-	{ APSUBUSW,	yxm,	Pe, 0xd9 },
-	{ APSUBW,	yxm,	Pe, 0xf9 },
-	{ APSWAPL,	ymfp,	Px, 0xbb },
-	{ APUNPCKHBW,	ymm,	Py, 0x68,Pe,0x68 },
-	{ APUNPCKHLQ,	ymm,	Py, 0x6a,Pe,0x6a },
-	{ APUNPCKHQDQ,	yxm,	Pe, 0x6d },
-	{ APUNPCKHWL,	ymm,	Py, 0x69,Pe,0x69 },
-	{ APUNPCKLBW,	ymm,	Py, 0x60,Pe,0x60 },
-	{ APUNPCKLLQ,	ymm,	Py, 0x62,Pe,0x62 },
-	{ APUNPCKLQDQ,	yxm,	Pe, 0x6c },
-	{ APUNPCKLWL,	ymm,	Py, 0x61,Pe,0x61 },
-	{ APUSHAL,	ynone,	P32, 0x60 },
-	{ APUSHAW,	ynone,	Pe, 0x60 },
-	{ APUSHFL,	ynone,	P32, 0x9c },
-	{ APUSHFQ,	ynone,	Py, 0x9c },
-	{ APUSHFW,	ynone,	Pe, 0x9c },
-	{ APUSHL,	ypushl,	P32, 0x50,0xff,(06),0x6a,0x68 },
-	{ APUSHQ,	ypushl,	Py, 0x50,0xff,(06),0x6a,0x68 },
-	{ APUSHW,	ypushl,	Pe, 0x50,0xff,(06),0x6a,0x68 },
-	{ APXOR,	ymm,	Py, 0xef,Pe,0xef },
-	{ AQUAD,	ybyte,	Px, 8 },
-	{ ARCLB,	yshb,	Pb, 0xd0,(02),0xc0,(02),0xd2,(02) },
-	{ ARCLL,	yshl,	Px, 0xd1,(02),0xc1,(02),0xd3,(02),0xd3,(02) },
-	{ ARCLQ,	yshl,	Pw, 0xd1,(02),0xc1,(02),0xd3,(02),0xd3,(02) },
-	{ ARCLW,	yshl,	Pe, 0xd1,(02),0xc1,(02),0xd3,(02),0xd3,(02) },
-	{ ARCPPS,	yxm,	Pm, 0x53 },
-	{ ARCPSS,	yxm,	Pf3, 0x53 },
-	{ ARCRB,	yshb,	Pb, 0xd0,(03),0xc0,(03),0xd2,(03) },
-	{ ARCRL,	yshl,	Px, 0xd1,(03),0xc1,(03),0xd3,(03),0xd3,(03) },
-	{ ARCRQ,	yshl,	Pw, 0xd1,(03),0xc1,(03),0xd3,(03),0xd3,(03) },
-	{ ARCRW,	yshl,	Pe, 0xd1,(03),0xc1,(03),0xd3,(03),0xd3,(03) },
-	{ AREP,		ynone,	Px, 0xf3 },
-	{ AREPN,	ynone,	Px, 0xf2 },
-	{ ARET,		ynone,	Px, 0xc3 },
-	{ ARETFW,	yret,	Pe, 0xcb,0xca },
-	{ ARETFL,	yret,	Px, 0xcb,0xca },
-	{ ARETFQ,	yret,	Pw, 0xcb,0xca },
-	{ AROLB,	yshb,	Pb, 0xd0,(00),0xc0,(00),0xd2,(00) },
-	{ AROLL,	yshl,	Px, 0xd1,(00),0xc1,(00),0xd3,(00),0xd3,(00) },
-	{ AROLQ,	yshl,	Pw, 0xd1,(00),0xc1,(00),0xd3,(00),0xd3,(00) },
-	{ AROLW,	yshl,	Pe, 0xd1,(00),0xc1,(00),0xd3,(00),0xd3,(00) },
-	{ ARORB,	yshb,	Pb, 0xd0,(01),0xc0,(01),0xd2,(01) },
-	{ ARORL,	yshl,	Px, 0xd1,(01),0xc1,(01),0xd3,(01),0xd3,(01) },
-	{ ARORQ,	yshl,	Pw, 0xd1,(01),0xc1,(01),0xd3,(01),0xd3,(01) },
-	{ ARORW,	yshl,	Pe, 0xd1,(01),0xc1,(01),0xd3,(01),0xd3,(01) },
-	{ ARSQRTPS,	yxm,	Pm, 0x52 },
-	{ ARSQRTSS,	yxm,	Pf3, 0x52 },
-	{ ASAHF,	ynone,	Px, 0x86,0xe0,0x50,0x9d },	/* XCHGB AH,AL; PUSH AX; POPFL */
-	{ ASALB,	yshb,	Pb, 0xd0,(04),0xc0,(04),0xd2,(04) },
-	{ ASALL,	yshl,	Px, 0xd1,(04),0xc1,(04),0xd3,(04),0xd3,(04) },
-	{ ASALQ,	yshl,	Pw, 0xd1,(04),0xc1,(04),0xd3,(04),0xd3,(04) },
-	{ ASALW,	yshl,	Pe, 0xd1,(04),0xc1,(04),0xd3,(04),0xd3,(04) },
-	{ ASARB,	yshb,	Pb, 0xd0,(07),0xc0,(07),0xd2,(07) },
-	{ ASARL,	yshl,	Px, 0xd1,(07),0xc1,(07),0xd3,(07),0xd3,(07) },
-	{ ASARQ,	yshl,	Pw, 0xd1,(07),0xc1,(07),0xd3,(07),0xd3,(07) },
-	{ ASARW,	yshl,	Pe, 0xd1,(07),0xc1,(07),0xd3,(07),0xd3,(07) },
-	{ ASBBB,	yxorb,	Pb, 0x1c,0x80,(03),0x18,0x1a },
-	{ ASBBL,	yxorl,	Px, 0x83,(03),0x1d,0x81,(03),0x19,0x1b },
-	{ ASBBQ,	yxorl,	Pw, 0x83,(03),0x1d,0x81,(03),0x19,0x1b },
-	{ ASBBW,	yxorl,	Pe, 0x83,(03),0x1d,0x81,(03),0x19,0x1b },
-	{ ASCASB,	ynone,	Pb, 0xae },
-	{ ASCASL,	ynone,	Px, 0xaf },
-	{ ASCASQ,	ynone,	Pw, 0xaf },
-	{ ASCASW,	ynone,	Pe, 0xaf },
-	{ ASETCC,	yscond,	Pm, 0x93,(00) },
-	{ ASETCS,	yscond,	Pm, 0x92,(00) },
-	{ ASETEQ,	yscond,	Pm, 0x94,(00) },
-	{ ASETGE,	yscond,	Pm, 0x9d,(00) },
-	{ ASETGT,	yscond,	Pm, 0x9f,(00) },
-	{ ASETHI,	yscond,	Pm, 0x97,(00) },
-	{ ASETLE,	yscond,	Pm, 0x9e,(00) },
-	{ ASETLS,	yscond,	Pm, 0x96,(00) },
-	{ ASETLT,	yscond,	Pm, 0x9c,(00) },
-	{ ASETMI,	yscond,	Pm, 0x98,(00) },
-	{ ASETNE,	yscond,	Pm, 0x95,(00) },
-	{ ASETOC,	yscond,	Pm, 0x91,(00) },
-	{ ASETOS,	yscond,	Pm, 0x90,(00) },
-	{ ASETPC,	yscond,	Pm, 0x96,(00) },
-	{ ASETPL,	yscond,	Pm, 0x99,(00) },
-	{ ASETPS,	yscond,	Pm, 0x9a,(00) },
-	{ ASHLB,	yshb,	Pb, 0xd0,(04),0xc0,(04),0xd2,(04) },
-	{ ASHLL,	yshl,	Px, 0xd1,(04),0xc1,(04),0xd3,(04),0xd3,(04) },
-	{ ASHLQ,	yshl,	Pw, 0xd1,(04),0xc1,(04),0xd3,(04),0xd3,(04) },
-	{ ASHLW,	yshl,	Pe, 0xd1,(04),0xc1,(04),0xd3,(04),0xd3,(04) },
-	{ ASHRB,	yshb,	Pb, 0xd0,(05),0xc0,(05),0xd2,(05) },
-	{ ASHRL,	yshl,	Px, 0xd1,(05),0xc1,(05),0xd3,(05),0xd3,(05) },
-	{ ASHRQ,	yshl,	Pw, 0xd1,(05),0xc1,(05),0xd3,(05),0xd3,(05) },
-	{ ASHRW,	yshl,	Pe, 0xd1,(05),0xc1,(05),0xd3,(05),0xd3,(05) },
-	{ ASHUFPD,	yxshuf,	Pq, 0xc6 },
-	{ ASHUFPS,	yxshuf,	Pm, 0xc6 },
-	{ ASQRTPD,	yxm,	Pe, 0x51 },
-	{ ASQRTPS,	yxm,	Pm, 0x51 },
-	{ ASQRTSD,	yxm,	Pf2, 0x51 },
-	{ ASQRTSS,	yxm,	Pf3, 0x51 },
-	{ ASTC,		ynone,	Px, 0xf9 },
-	{ ASTD,		ynone,	Px, 0xfd },
-	{ ASTI,		ynone,	Px, 0xfb },
-	{ ASTMXCSR,	ysvrs,	Pm, 0xae,(03),0xae,(03) },
-	{ ASTOSB,	ynone,	Pb, 0xaa },
-	{ ASTOSL,	ynone,	Px, 0xab },
-	{ ASTOSQ,	ynone,	Pw, 0xab },
-	{ ASTOSW,	ynone,	Pe, 0xab },
-	{ ASUBB,	yxorb,	Pb, 0x2c,0x80,(05),0x28,0x2a },
-	{ ASUBL,	yaddl,	Px, 0x83,(05),0x2d,0x81,(05),0x29,0x2b },
-	{ ASUBPD,	yxm,	Pe, 0x5c },
-	{ ASUBPS,	yxm,	Pm, 0x5c },
-	{ ASUBQ,	yaddl,	Pw, 0x83,(05),0x2d,0x81,(05),0x29,0x2b },
-	{ ASUBSD,	yxm,	Pf2, 0x5c },
-	{ ASUBSS,	yxm,	Pf3, 0x5c },
-	{ ASUBW,	yaddl,	Pe, 0x83,(05),0x2d,0x81,(05),0x29,0x2b },
-	{ ASWAPGS,	ynone,	Pm, 0x01,0xf8 },
-	{ ASYSCALL,	ynone,	Px, 0x0f,0x05 },	/* fast syscall */
-	{ ATESTB,	ytestb,	Pb, 0xa8,0xf6,(00),0x84,0x84 },
-	{ ATESTL,	ytestl,	Px, 0xa9,0xf7,(00),0x85,0x85 },
-	{ ATESTQ,	ytestl,	Pw, 0xa9,0xf7,(00),0x85,0x85 },
-	{ ATESTW,	ytestl,	Pe, 0xa9,0xf7,(00),0x85,0x85 },
-	{ ATEXT,	ytext,	Px },
-	{ AUCOMISD,	yxcmp,	Pe, 0x2e },
-	{ AUCOMISS,	yxcmp,	Pm, 0x2e },
-	{ AUNPCKHPD,	yxm,	Pe, 0x15 },
-	{ AUNPCKHPS,	yxm,	Pm, 0x15 },
-	{ AUNPCKLPD,	yxm,	Pe, 0x14 },
-	{ AUNPCKLPS,	yxm,	Pm, 0x14 },
-	{ AVERR,	ydivl,	Pm, 0x00,(04) },
-	{ AVERW,	ydivl,	Pm, 0x00,(05) },
-	{ AWAIT,	ynone,	Px, 0x9b },
-	{ AWORD,	ybyte,	Px, 2 },
-	{ AXCHGB,	yml_mb,	Pb, 0x86,0x86 },
-	{ AXCHGL,	yml_ml,	Px, 0x87,0x87 },
-	{ AXCHGQ,	yml_ml,	Pw, 0x87,0x87 },
-	{ AXCHGW,	yml_ml,	Pe, 0x87,0x87 },
-	{ AXLAT,	ynone,	Px, 0xd7 },
-	{ AXORB,	yxorb,	Pb, 0x34,0x80,(06),0x30,0x32 },
-	{ AXORL,	yxorl,	Px, 0x83,(06),0x35,0x81,(06),0x31,0x33 },
-	{ AXORPD,	yxm,	Pe, 0x57 },
-	{ AXORPS,	yxm,	Pm, 0x57 },
-	{ AXORQ,	yxorl,	Pw, 0x83,(06),0x35,0x81,(06),0x31,0x33 },
-	{ AXORW,	yxorl,	Pe, 0x83,(06),0x35,0x81,(06),0x31,0x33 },
-
-	{ AFMOVB,	yfmvx,	Px, 0xdf,(04) },
-	{ AFMOVBP,	yfmvp,	Px, 0xdf,(06) },
-	{ AFMOVD,	yfmvd,	Px, 0xdd,(00),0xdd,(02),0xd9,(00),0xdd,(02) },
-	{ AFMOVDP,	yfmvdp,	Px, 0xdd,(03),0xdd,(03) },
-	{ AFMOVF,	yfmvf,	Px, 0xd9,(00),0xd9,(02) },
-	{ AFMOVFP,	yfmvp,	Px, 0xd9,(03) },
-	{ AFMOVL,	yfmvf,	Px, 0xdb,(00),0xdb,(02) },
-	{ AFMOVLP,	yfmvp,	Px, 0xdb,(03) },
-	{ AFMOVV,	yfmvx,	Px, 0xdf,(05) },
-	{ AFMOVVP,	yfmvp,	Px, 0xdf,(07) },
-	{ AFMOVW,	yfmvf,	Px, 0xdf,(00),0xdf,(02) },
-	{ AFMOVWP,	yfmvp,	Px, 0xdf,(03) },
-	{ AFMOVX,	yfmvx,	Px, 0xdb,(05) },
-	{ AFMOVXP,	yfmvp,	Px, 0xdb,(07) },
-
-	{ AFCOMB },
-	{ AFCOMBP },
-	{ AFCOMD,	yfadd,	Px, 0xdc,(02),0xd8,(02),0xdc,(02) },	/* botch */
-	{ AFCOMDP,	yfadd,	Px, 0xdc,(03),0xd8,(03),0xdc,(03) },	/* botch */
-	{ AFCOMDPP,	ycompp,	Px, 0xde,(03) },
-	{ AFCOMF,	yfmvx,	Px, 0xd8,(02) },
-	{ AFCOMFP,	yfmvx,	Px, 0xd8,(03) },
-	{ AFCOML,	yfmvx,	Px, 0xda,(02) },
-	{ AFCOMLP,	yfmvx,	Px, 0xda,(03) },
-	{ AFCOMW,	yfmvx,	Px, 0xde,(02) },
-	{ AFCOMWP,	yfmvx,	Px, 0xde,(03) },
-
-	{ AFUCOM,	ycompp,	Px, 0xdd,(04) },
-	{ AFUCOMP,	ycompp, Px, 0xdd,(05) },
-	{ AFUCOMPP,	ycompp,	Px, 0xda,(13) },
-
-	{ AFADDDP,	yfaddp,	Px, 0xde,(00) },
-	{ AFADDW,	yfmvx,	Px, 0xde,(00) },
-	{ AFADDL,	yfmvx,	Px, 0xda,(00) },
-	{ AFADDF,	yfmvx,	Px, 0xd8,(00) },
-	{ AFADDD,	yfadd,	Px, 0xdc,(00),0xd8,(00),0xdc,(00) },
-
-	{ AFMULDP,	yfaddp,	Px, 0xde,(01) },
-	{ AFMULW,	yfmvx,	Px, 0xde,(01) },
-	{ AFMULL,	yfmvx,	Px, 0xda,(01) },
-	{ AFMULF,	yfmvx,	Px, 0xd8,(01) },
-	{ AFMULD,	yfadd,	Px, 0xdc,(01),0xd8,(01),0xdc,(01) },
-
-	{ AFSUBDP,	yfaddp,	Px, 0xde,(05) },
-	{ AFSUBW,	yfmvx,	Px, 0xde,(04) },
-	{ AFSUBL,	yfmvx,	Px, 0xda,(04) },
-	{ AFSUBF,	yfmvx,	Px, 0xd8,(04) },
-	{ AFSUBD,	yfadd,	Px, 0xdc,(04),0xd8,(04),0xdc,(05) },
-
-	{ AFSUBRDP,	yfaddp,	Px, 0xde,(04) },
-	{ AFSUBRW,	yfmvx,	Px, 0xde,(05) },
-	{ AFSUBRL,	yfmvx,	Px, 0xda,(05) },
-	{ AFSUBRF,	yfmvx,	Px, 0xd8,(05) },
-	{ AFSUBRD,	yfadd,	Px, 0xdc,(05),0xd8,(05),0xdc,(04) },
-
-	{ AFDIVDP,	yfaddp,	Px, 0xde,(07) },
-	{ AFDIVW,	yfmvx,	Px, 0xde,(06) },
-	{ AFDIVL,	yfmvx,	Px, 0xda,(06) },
-	{ AFDIVF,	yfmvx,	Px, 0xd8,(06) },
-	{ AFDIVD,	yfadd,	Px, 0xdc,(06),0xd8,(06),0xdc,(07) },
-
-	{ AFDIVRDP,	yfaddp,	Px, 0xde,(06) },
-	{ AFDIVRW,	yfmvx,	Px, 0xde,(07) },
-	{ AFDIVRL,	yfmvx,	Px, 0xda,(07) },
-	{ AFDIVRF,	yfmvx,	Px, 0xd8,(07) },
-	{ AFDIVRD,	yfadd,	Px, 0xdc,(07),0xd8,(07),0xdc,(06) },
-
-	{ AFXCHD,	yfxch,	Px, 0xd9,(01),0xd9,(01) },
-	{ AFFREE },
-	{ AFLDCW,	ystcw,	Px, 0xd9,(05),0xd9,(05) },
-	{ AFLDENV,	ystcw,	Px, 0xd9,(04),0xd9,(04) },
-	{ AFRSTOR,	ysvrs,	Px, 0xdd,(04),0xdd,(04) },
-	{ AFSAVE,	ysvrs,	Px, 0xdd,(06),0xdd,(06) },
-	{ AFSTCW,	ystcw,	Px, 0xd9,(07),0xd9,(07) },
-	{ AFSTENV,	ystcw,	Px, 0xd9,(06),0xd9,(06) },
-	{ AFSTSW,	ystsw,	Px, 0xdd,(07),0xdf,0xe0 },
-	{ AF2XM1,	ynone,	Px, 0xd9, 0xf0 },
-	{ AFABS,	ynone,	Px, 0xd9, 0xe1 },
-	{ AFCHS,	ynone,	Px, 0xd9, 0xe0 },
-	{ AFCLEX,	ynone,	Px, 0xdb, 0xe2 },
-	{ AFCOS,	ynone,	Px, 0xd9, 0xff },
-	{ AFDECSTP,	ynone,	Px, 0xd9, 0xf6 },
-	{ AFINCSTP,	ynone,	Px, 0xd9, 0xf7 },
-	{ AFINIT,	ynone,	Px, 0xdb, 0xe3 },
-	{ AFLD1,	ynone,	Px, 0xd9, 0xe8 },
-	{ AFLDL2E,	ynone,	Px, 0xd9, 0xea },
-	{ AFLDL2T,	ynone,	Px, 0xd9, 0xe9 },
-	{ AFLDLG2,	ynone,	Px, 0xd9, 0xec },
-	{ AFLDLN2,	ynone,	Px, 0xd9, 0xed },
-	{ AFLDPI,	ynone,	Px, 0xd9, 0xeb },
-	{ AFLDZ,	ynone,	Px, 0xd9, 0xee },
-	{ AFNOP,	ynone,	Px, 0xd9, 0xd0 },
-	{ AFPATAN,	ynone,	Px, 0xd9, 0xf3 },
-	{ AFPREM,	ynone,	Px, 0xd9, 0xf8 },
-	{ AFPREM1,	ynone,	Px, 0xd9, 0xf5 },
-	{ AFPTAN,	ynone,	Px, 0xd9, 0xf2 },
-	{ AFRNDINT,	ynone,	Px, 0xd9, 0xfc },
-	{ AFSCALE,	ynone,	Px, 0xd9, 0xfd },
-	{ AFSIN,	ynone,	Px, 0xd9, 0xfe },
-	{ AFSINCOS,	ynone,	Px, 0xd9, 0xfb },
-	{ AFSQRT,	ynone,	Px, 0xd9, 0xfa },
-	{ AFTST,	ynone,	Px, 0xd9, 0xe4 },
-	{ AFXAM,	ynone,	Px, 0xd9, 0xe5 },
-	{ AFXTRACT,	ynone,	Px, 0xd9, 0xf4 },
-	{ AFYL2X,	ynone,	Px, 0xd9, 0xf1 },
-	{ AFYL2XP1,	ynone,	Px, 0xd9, 0xf9 },
-
-	{ ACMPXCHGB,	yrb_mb,	Pb, 0x0f,0xb0 },
-	{ ACMPXCHGL,	yrl_ml,	Px, 0x0f,0xb1 },
-	{ ACMPXCHGW,	yrl_ml,	Pe, 0x0f,0xb1 },
-	{ ACMPXCHGQ,	yrl_ml,	Pw, 0x0f,0xb1 },
-	{ ACMPXCHG8B,	yscond,	Pm, 0xc7,(01) },
-	{ AINVD,	ynone,	Pm, 0x08 },
-	{ AINVLPG,	ymbs,	Pm, 0x01,(07) },
-	{ ALFENCE,	ynone,	Pm, 0xae,0xe8 },
-	{ AMFENCE,	ynone,	Pm, 0xae,0xf0 },
-	{ AMOVNTIL,	yrl_ml,	Pm, 0xc3 },
-	{ AMOVNTIQ,	yrl_ml, Pw, 0x0f,0xc3 },
-	{ ARDMSR,	ynone,	Pm, 0x32 },
-	{ ARDPMC,	ynone,	Pm, 0x33 },
-	{ ARDTSC,	ynone,	Pm, 0x31 },
-	{ ARSM,		ynone,	Pm, 0xaa },
-	{ ASFENCE,	ynone,	Pm, 0xae,0xf8 },
-	{ ASYSRET,	ynone,	Pm, 0x07 },
-	{ AWBINVD,	ynone,	Pm, 0x09 },
-	{ AWRMSR,	ynone,	Pm, 0x30 },
-
-	{ AXADDB,	yrb_mb,	Pb, 0x0f,0xc0 },
-	{ AXADDL,	yrl_ml,	Px, 0x0f,0xc1 },
-	{ AXADDQ,	yrl_ml,	Pw, 0x0f,0xc1 },
-	{ AXADDW,	yrl_ml,	Pe, 0x0f,0xc1 },
-
-	{ AEND },
-	0
-};
-
-Optab*	opindex[ALAST+1];
-
-/*
-AMOVD	0f 6e/r	mmx,reg/mem32[mem64-rex?]
-AMOVD	0f 7e/r	reg/mem32[64],mmx	STORE
-AMOVQ	0f 6f/r	mmx1,mmx2/mem64
-AMOVQ	0f 7f/r	mmx1/mem64,mmx2
-*/

+ 0 - 799
sys/src/cmd/6l/pass.c

@@ -1,799 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include	"l.h"
-
-void
-dodata(void)
-{
-	int i;
-	Sym *s;
-	Prog *p;
-	int32_t t, u;
-
-	if(debug['v'])
-		Bprint(&bso, "%5.2f dodata\n", cputime());
-	Bflush(&bso);
-	for(p = datap; p != P; p = p->link) {
-		s = p->from.sym;
-		if(p->as == ADYNT || p->as == AINIT)
-			s->value = dtype;
-		if(s->type == SBSS)
-			s->type = SDATA;
-		if(s->type != SDATA)
-			diag("initialize non-data (%d): %s\n%P",
-				s->type, s->name, p);
-		t = p->from.offset + p->width;
-		if(t > s->value)
-			diag("initialize bounds (%lld): %s\n%P",
-				s->value, s->name, p);
-	}
-	/* allocate small guys */
-	datsize = 0;
-	for(i=0; i<NHASH; i++)
-	for(s = hash[i]; s != S; s = s->link) {
-		if(s->type != SDATA)
-		if(s->type != SBSS)
-			continue;
-		t = s->value;
-		if(t == 0) {
-			diag("%s: no size", s->name);
-			t = 1;
-		}
-		t = rnd(t, 4);
-		s->value = t;
-		if(t > MINSIZ)
-			continue;
-		if(t >= 8)
-			datsize = rnd(datsize, 8);
-		s->value = datsize;
-		datsize += t;
-		s->type = SDATA1;
-	}
-
-	/* allocate the rest of the data */
-	for(i=0; i<NHASH; i++)
-	for(s = hash[i]; s != S; s = s->link) {
-		if(s->type != SDATA) {
-			if(s->type == SDATA1)
-				s->type = SDATA;
-			continue;
-		}
-		t = s->value;
-		if(t >= 8)
-			datsize = rnd(datsize, 8);
-		s->value = datsize;
-		datsize += t;
-	}
-	if(datsize)
-		datsize = rnd(datsize, 8);
-
-	if(debug['j']) {
-		/*
-		 * pad data with bss that fits up to next
-		 * 8k boundary, then push data to 8k
-		 */
-		u = rnd(datsize, 8192);
-		u -= datsize;
-		for(i=0; i<NHASH; i++)
-		for(s = hash[i]; s != S; s = s->link) {
-			if(s->type != SBSS)
-				continue;
-			t = s->value;
-			if(t > u)
-				continue;
-			u -= t;
-			s->value = datsize;
-			s->type = SDATA;
-			datsize += t;
-		}
-		datsize += u;
-	}
-
-	/* now the bss */
-	bsssize = 0;
-	for(i=0; i<NHASH; i++)
-	for(s = hash[i]; s != S; s = s->link) {
-		if(s->type != SBSS)
-			continue;
-		t = s->value;
-		if(t >= 8)
-			bsssize = rnd(bsssize, 8);
-		s->value = bsssize + datsize;
-		bsssize += t;
-	}
-	xdefine("edata", SBSS, datsize);
-	xdefine("end", SBSS, bsssize + datsize);
-}
-
-Prog*
-brchain(Prog *p)
-{
-	int i;
-
-	for(i=0; i<20; i++) {
-		if(p == P || p->as != AJMP)
-			return p;
-		p = p->pcond;
-	}
-	return P;
-}
-
-void
-follow(void)
-{
-
-	if(debug['v'])
-		Bprint(&bso, "%5.2f follow\n", cputime());
-	Bflush(&bso);
-	firstp = prg();
-	lastp = firstp;
-	xfol(textp);
-	lastp->link = P;
-	firstp = firstp->link;
-}
-
-void
-xfol(Prog *p)
-{
-	Prog *q;
-	int i;
-	enum as a;
-
-loop:
-	if(p == P)
-		return;
-	if(p->as == ATEXT)
-		curtext = p;
-	if(p->as == AJMP)
-	if((q = p->pcond) != P) {
-		p->mark = 1;
-		p = q;
-		if(p->mark == 0)
-			goto loop;
-	}
-	if(p->mark) {
-		/* copy up to 4 instructions to avoid branch */
-		for(i=0,q=p; i<4; i++,q=q->link) {
-			if(q == P)
-				break;
-			if(q == lastp)
-				break;
-			a = q->as;
-			if(a == ANOP) {
-				i--;
-				continue;
-			}
-			switch(a) {
-			case AJMP:
-			case ARET:
-			case AIRETL:
-			case AIRETQ:
-			case AIRETW:
-			case ARETFL:
-			case ARETFQ:
-			case ARETFW:
-
-			case APUSHL:
-			case APUSHFL:
-			case APUSHQ:
-			case APUSHFQ:
-			case APUSHW:
-			case APUSHFW:
-			case APOPL:
-			case APOPFL:
-			case APOPQ:
-			case APOPFQ:
-			case APOPW:
-			case APOPFW:
-				goto brk;
-			}
-			if(q->pcond == P || q->pcond->mark)
-				continue;
-			if(a == ACALL || a == ALOOP)
-				continue;
-			for(;;) {
-				if(p->as == ANOP) {
-					p = p->link;
-					continue;
-				}
-				q = copyp(p);
-				p = p->link;
-				q->mark = 1;
-				lastp->link = q;
-				lastp = q;
-				if(q->as != a || q->pcond == P || q->pcond->mark)
-					continue;
-
-				q->as = relinv(q->as);
-				p = q->pcond;
-				q->pcond = q->link;
-				q->link = p;
-				xfol(q->link);
-				p = q->link;
-				if(p->mark)
-					return;
-				goto loop;
-			}
-		} /* */
-	brk:;
-		q = prg();
-		q->as = AJMP;
-		q->line = p->line;
-		q->to.type = D_BRANCH;
-		q->to.offset = p->pc;
-		q->pcond = p;
-		p = q;
-	}
-	p->mark = 1;
-	lastp->link = p;
-	lastp = p;
-	a = p->as;
-	if(a == AJMP || a == ARET || a == AIRETL || a == AIRETQ || a == AIRETW ||
-	   a == ARETFL || a == ARETFQ || a == ARETFW)
-		return;
-	if(p->pcond != P)
-	if(a != ACALL) {
-		q = brchain(p->link);
-		if(q != P && q->mark)
-		if(a != ALOOP) {
-			p->as = relinv(a);
-			p->link = p->pcond;
-			p->pcond = q;
-		}
-		xfol(p->link);
-		q = brchain(p->pcond);
-		if(q->mark) {
-			p->pcond = q;
-			return;
-		}
-		p = q;
-		goto loop;
-	}
-	p = p->link;
-	goto loop;
-}
-
-int
-relinv(int a)
-{
-
-	switch(a) {
-	case AJEQ:	return AJNE;
-	case AJNE:	return AJEQ;
-	case AJLE:	return AJGT;
-	case AJLS:	return AJHI;
-	case AJLT:	return AJGE;
-	case AJMI:	return AJPL;
-	case AJGE:	return AJLT;
-	case AJPL:	return AJMI;
-	case AJGT:	return AJLE;
-	case AJHI:	return AJLS;
-	case AJCS:	return AJCC;
-	case AJCC:	return AJCS;
-	case AJPS:	return AJPC;
-	case AJPC:	return AJPS;
-	case AJOS:	return AJOC;
-	case AJOC:	return AJOS;
-	}
-	diag("unknown relation: %s in %s", anames[a], TNAME);
-	return a;
-}
-
-void
-doinit(void)
-{
-	Sym *s;
-	Prog *p;
-	int x;
-
-	for(p = datap; p != P; p = p->link) {
-		x = p->to.type;
-		if(x != D_EXTERN && x != D_STATIC)
-			continue;
-		s = p->to.sym;
-		if(s->type == 0 || s->type == SXREF)
-			diag("undefined %s initializer of %s",
-				s->name, p->from.sym->name);
-		p->to.offset += s->value;
-		p->to.type = D_CONST;
-		if(s->type == SDATA || s->type == SBSS)
-			p->to.offset += INITDAT;
-	}
-}
-
-void
-patch(void)
-{
-	int32_t c;
-	Prog *p, *q;
-	Sym *s;
-	int32_t vexit;
-
-	if(debug['v'])
-		Bprint(&bso, "%5.2f mkfwd\n", cputime());
-	Bflush(&bso);
-	mkfwd();
-	if(debug['v'])
-		Bprint(&bso, "%5.2f patch\n", cputime());
-	Bflush(&bso);
-	s = lookup("exit", 0);
-	vexit = s->value;
-	for(p = firstp; p != P; p = p->link) {
-		if(p->as == ATEXT)
-			curtext = p;
-		if(p->as == ACALL || p->as == ARET) {
-			s = p->to.sym;
-			if(s) {
-				if(debug['c'])
-					Bprint(&bso, "%s calls %s\n", TNAME, s->name);
-				switch(s->type) {
-				default:
-					diag("undefined: %s in %s", s->name, TNAME);
-					s->type = STEXT;
-					s->value = vexit;
-					break;	/* or fall through to set offset? */
-				case STEXT:
-					p->to.offset = s->value;
-					break;
-				case SUNDEF:
-					p->pcond = UP;
-					p->to.offset = 0;
-					break;
-				}
-				p->to.type = D_BRANCH;
-			}
-		}
-		if(p->to.type != D_BRANCH || p->pcond == UP)
-			continue;
-		c = p->to.offset;
-		for(q = firstp; q != P;) {
-			if(q->forwd != P)
-			if(c >= q->forwd->pc) {
-				q = q->forwd;
-				continue;
-			}
-			if(c == q->pc)
-				break;
-			q = q->link;
-		}
-		if(q == P) {
-			diag("branch out of range in %s\n%P", TNAME, p);
-			p->to.type = D_NONE;
-		}
-		p->pcond = q;
-	}
-
-	for(p = firstp; p != P; p = p->link) {
-		if(p->as == ATEXT)
-			curtext = p;
-		p->mark = 0;	/* initialization for follow */
-		if(p->pcond != P && p->pcond != UP) {
-			p->pcond = brloop(p->pcond);
-			if(p->pcond != P)
-			if(p->to.type == D_BRANCH)
-				p->to.offset = p->pcond->pc;
-		}
-	}
-}
-
-#define	LOG	5
-void
-mkfwd(void)
-{
-	Prog *p;
-	int i;
-	int32_t dwn[LOG], cnt[LOG];
-	Prog *lst[LOG];
-
-	for(i=0; i<LOG; i++) {
-		if(i == 0)
-			cnt[i] = 1; else
-			cnt[i] = LOG * cnt[i-1];
-		dwn[i] = 1;
-		lst[i] = P;
-	}
-	i = 0;
-	for(p = firstp; p != P; p = p->link) {
-		if(p->as == ATEXT)
-			curtext = p;
-		i--;
-		if(i < 0)
-			i = LOG-1;
-		p->forwd = P;
-		dwn[i]--;
-		if(dwn[i] <= 0) {
-			dwn[i] = cnt[i];
-			if(lst[i] != P)
-				lst[i]->forwd = p;
-			lst[i] = p;
-		}
-	}
-}
-
-Prog*
-brloop(Prog *p)
-{
-	int c;
-	Prog *q;
-
-	c = 0;
-	for(q = p; q != P; q = q->pcond) {
-		if(q->as != AJMP)
-			break;
-		c++;
-		if(c >= 5000)
-			return P;
-	}
-	return q;
-}
-
-void
-dostkoff(void)
-{
-	Prog *p, *q;
-	int32_t autoffset, deltasp;
-	int a, f, curframe, curbecome, maxbecome, pcsize;
-
-	curframe = 0;
-	curbecome = 0;
-	maxbecome = 0;
-	curtext = 0;
-	for(p = firstp; p != P; p = p->link) {
-
-		/* find out how much arg space is used in this TEXT */
-		if(p->to.type == (D_INDIR+D_SP))
-			if(p->to.offset > curframe)
-				curframe = p->to.offset;
-
-		switch(p->as) {
-		case ATEXT:
-			if(curtext && curtext->from.sym) {
-				curtext->from.sym->frame = curframe;
-				curtext->from.sym->become = curbecome;
-				if(curbecome > maxbecome)
-					maxbecome = curbecome;
-			}
-			curframe = 0;
-			curbecome = 0;
-
-			curtext = p;
-			break;
-
-		case ARET:
-			/* special form of RET is BECOME */
-			if(p->from.type == D_CONST)
-				if(p->from.offset > curbecome)
-					curbecome = p->from.offset;
-			break;
-		}
-	}
-	if(curtext && curtext->from.sym) {
-		curtext->from.sym->frame = curframe;
-		curtext->from.sym->become = curbecome;
-		if(curbecome > maxbecome)
-			maxbecome = curbecome;
-	}
-
-	if(debug['b'])
-		print("max become = %d\n", maxbecome);
-	xdefine("ALEFbecome", STEXT, maxbecome);
-
-	curtext = 0;
-	for(p = firstp; p != P; p = p->link) {
-		switch(p->as) {
-		case ATEXT:
-			curtext = p;
-			break;
-		case ACALL:
-			if(curtext != P && curtext->from.sym != S && curtext->to.offset >= 0) {
-				f = maxbecome - curtext->from.sym->frame;
-				if(f <= 0)
-					break;
-				/* calling a become or calling a variable */
-				if(p->to.sym == S || p->to.sym->become) {
-					curtext->to.offset += f;
-					if(debug['b']) {
-						curp = p;
-						print("%D calling %D increase %d\n",
-							&curtext->from, &p->to, f);
-					}
-				}
-			}
-			break;
-		}
-	}
-
-	autoffset = 0;
-	deltasp = 0;
-	for(p = firstp; p != P; p = p->link) {
-		if(p->as == ATEXT) {
-			curtext = p;
-			autoffset = p->to.offset;
-			if(autoffset < 0)
-				autoffset = 0;
-			if(autoffset) {
-				p = appendp(p);
-				p->as = AADJSP;
-				p->from.type = D_CONST;
-				p->from.offset = autoffset;
-			}
-			deltasp = autoffset;
-		}
-		pcsize = p->mode/8;
-		a = p->from.type;
-		if(a == D_AUTO)
-			p->from.offset += deltasp;
-		if(a == D_PARAM)
-			p->from.offset += deltasp + pcsize;
-		a = p->to.type;
-		if(a == D_AUTO)
-			p->to.offset += deltasp;
-		if(a == D_PARAM)
-			p->to.offset += deltasp + pcsize;
-
-		switch(p->as) {
-		default:
-			continue;
-		case APUSHL:
-		case APUSHFL:
-			deltasp += 4;
-			continue;
-		case APUSHQ:
-		case APUSHFQ:
-			deltasp += 8;
-			continue;
-		case APUSHW:
-		case APUSHFW:
-			deltasp += 2;
-			continue;
-		case APOPL:
-		case APOPFL:
-			deltasp -= 4;
-			continue;
-		case APOPQ:
-		case APOPFQ:
-			deltasp -= 8;
-			continue;
-		case APOPW:
-		case APOPFW:
-			deltasp -= 2;
-			continue;
-		case ARET:
-			break;
-		}
-
-		if(autoffset != deltasp)
-			diag("unbalanced PUSH/POP");
-		if(p->from.type == D_CONST)
-			goto become;
-
-		if(autoffset) {
-			q = p;
-			p = appendp(p);
-			p->as = ARET;
-
-			q->as = AADJSP;
-			q->from.type = D_CONST;
-			q->from.offset = -autoffset;
-		}
-		continue;
-
-	become:
-		q = p;
-		p = appendp(p);
-		p->as = AJMP;
-		p->to = q->to;
-		p->pcond = q->pcond;
-
-		q->as = AADJSP;
-		q->from = zprg.from;
-		q->from.type = D_CONST;
-		q->from.offset = -autoffset;
-		q->to = zprg.to;
-		continue;
-	}
-}
-
-int64_t
-atolwhex(char *s)
-{
-	int64_t n;
-	int f;
-
-	n = 0;
-	f = 0;
-	while(*s == ' ' || *s == '\t')
-		s++;
-	if(*s == '-' || *s == '+') {
-		if(*s++ == '-')
-			f = 1;
-		while(*s == ' ' || *s == '\t')
-			s++;
-	}
-	if(s[0]=='0' && s[1]){
-		if(s[1]=='x' || s[1]=='X'){
-			s += 2;
-			for(;;){
-				if(*s >= '0' && *s <= '9')
-					n = n*16 + *s++ - '0';
-				else if(*s >= 'a' && *s <= 'f')
-					n = n*16 + *s++ - 'a' + 10;
-				else if(*s >= 'A' && *s <= 'F')
-					n = n*16 + *s++ - 'A' + 10;
-				else
-					break;
-			}
-		} else
-			while(*s >= '0' && *s <= '7')
-				n = n*8 + *s++ - '0';
-	} else
-		while(*s >= '0' && *s <= '9')
-			n = n*10 + *s++ - '0';
-	if(f)
-		n = -n;
-	return n;
-}
-
-void
-undef(void)
-{
-	int i;
-	Sym *s;
-
-	for(i=0; i<NHASH; i++)
-	for(s = hash[i]; s != S; s = s->link)
-		if(s->type == SXREF)
-			diag("%s: not defined", s->name);
-}
-
-void
-import(void)
-{
-	int i;
-	Sym *s;
-
-	for(i = 0; i < NHASH; i++)
-		for(s = hash[i]; s != S; s = s->link)
-			if(s->sig != 0 && s->type == SXREF && (nimports == 0 || s->subtype == SIMPORT)){
-				if(s->value != 0)
-					diag("value != 0 on SXREF");
-				undefsym(s);
-				Bprint(&bso, "IMPORT: %s sig=%lux v=%lld\n", s->name, s->sig, s->value);
-				if(debug['S'])
-					s->sig = 0;
-			}
-}
-
-void
-ckoff(Sym *s, int32_t v)
-{
-	if(v < 0 || v >= 1<<Roffset)
-		diag("relocation offset %ld for %s out of range", v, s->name);
-}
-
-static Prog*
-newdata(Sym *s, int o, int w, int t)
-{
-	Prog *p;
-
-	p = prg();
-	if(edatap == P)
-		datap = p;
-	else
-		edatap->link = p;
-	edatap = p;
-	p->as = ADATA;
-	p->width = w;
-	p->from.scale = w;
-	p->from.type = t;
-	p->from.sym = s;
-	p->from.offset = o;
-	p->to.type = D_CONST;
-	return p;
-}
-
-void
-export(void)
-{
-	int i, j, n, off, nb, sv, ne;
-	Sym *s, *et, *str, **esyms;
-	Prog *p;
-	char buf[NSNAME], *t;
-
-	n = 0;
-	for(i = 0; i < NHASH; i++)
-		for(s = hash[i]; s != S; s = s->link)
-			if(s->sig != 0 && s->type != SXREF && s->type != SUNDEF && (nexports == 0 || s->subtype == SEXPORT))
-				n++;
-	esyms = malloc(n*sizeof(Sym*));
-	ne = n;
-	n = 0;
-	for(i = 0; i < NHASH; i++)
-		for(s = hash[i]; s != S; s = s->link)
-			if(s->sig != 0 && s->type != SXREF && s->type != SUNDEF && (nexports == 0 || s->subtype == SEXPORT))
-				esyms[n++] = s;
-	for(i = 0; i < ne-1; i++)
-		for(j = i+1; j < ne; j++)
-			if(strcmp(esyms[i]->name, esyms[j]->name) > 0){
-				s = esyms[i];
-				esyms[i] = esyms[j];
-				esyms[j] = s;
-			}
-
-	nb = 0;
-	off = 0;
-	et = lookup(EXPTAB, 0);
-	if(et->type != 0 && et->type != SXREF)
-		diag("%s already defined", EXPTAB);
-	et->type = SDATA;
-	str = lookup(".string", 0);
-	if(str->type == 0)
-		str->type = SDATA;
-	sv = str->value;
-	for(i = 0; i < ne; i++){
-		s = esyms[i];
-		if(debug['S'])
-			s->sig = 0;
-		/* Bprint(&bso, "EXPORT: %s sig=%lux t=%d\n", s->name, s->sig, s->type); */
-
-		/* signature */
-		p = newdata(et, off, sizeof(int32_t), D_EXTERN);
-		off += sizeof(int32_t);
-		p->to.offset = s->sig;
-
-		/* address */
-		p = newdata(et, off, sizeof(int32_t), D_EXTERN);
-		off += sizeof(int32_t);
-		p->to.type = D_ADDR;
-		p->to.index = D_EXTERN;
-		p->to.sym = s;
-
-		/* string */
-		t = s->name;
-		n = strlen(t)+1;
-		for(;;){
-			buf[nb++] = *t;
-			sv++;
-			if(nb >= NSNAME){
-				p = newdata(str, sv-NSNAME, NSNAME, D_STATIC);
-				p->to.type = D_SCONST;
-				memmove(p->to.scon, buf, NSNAME);
-				nb = 0;
-			}
-			if(*t++ == 0)
-				break;
-		}
-
-		/* name */
-		p = newdata(et, off, sizeof(int32_t), D_EXTERN);
-		off += sizeof(int32_t);
-		p->to.type = D_ADDR;
-		p->to.index = D_STATIC;
-		p->to.sym = str;
-		p->to.offset = sv-n;
-	}
-
-	if(nb > 0){
-		p = newdata(str, sv-nb, nb, D_STATIC);
-		p->to.type = D_SCONST;
-		memmove(p->to.scon, buf, nb);
-	}
-
-	for(i = 0; i < 3; i++){
-		newdata(et, off, sizeof(int32_t), D_EXTERN);
-		off += sizeof(int32_t);
-	}
-	et->value = off;
-	if(sv == 0)
-		sv = 1;
-	str->value = sv;
-	exports = ne;
-	free(esyms);
-}

+ 0 - 1763
sys/src/cmd/6l/span.c

@@ -1,1763 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include	"l.h"
-
-static int	rexflag;
-static int	asmode;
-
-void
-span(void)
-{
-	Prog *p, *q;
-	int32_t v;
-	int64_t c, idat;
-	int m, n, again;
-
-	xdefine("etext", STEXT, 0L);
-	idat = INITDAT;
-	for(p = firstp; p != P; p = p->link) {
-		if(p->as == ATEXT)
-			curtext = p;
-		n = 0;
-		if(p->to.type == D_BRANCH)
-			if(p->pcond == P)
-				p->pcond = p;
-		if((q = p->pcond) != P)
-			if(q->back != 2)
-				n = 1;
-		p->back = n;
-		if(p->as == AADJSP) {
-			p->to.type = D_SP;
-			v = -p->from.offset;
-			p->from.offset = v;
-			p->as = p->mode != 64? AADDL: AADDQ;
-			if(v < 0) {
-				p->as = p->mode != 64? ASUBL: ASUBQ;
-				v = -v;
-				p->from.offset = v;
-			}
-			if(v == 0)
-				p->as = ANOP;
-		}
-	}
-	n = 0;
-
-start:
-	if(debug['v'])
-		Bprint(&bso, "%5.2f span\n", cputime());
-	Bflush(&bso);
-	c = INITTEXT;
-	for(p = firstp; p != P; p = p->link) {
-		if(p->as == ATEXT)
-			curtext = p;
-		if(p->to.type == D_BRANCH)
-			if(p->back)
-				p->pc = c;
-		asmins(p);
-		p->pc = c;
-		m = andptr-and;
-		p->mark = m;
-		c += m;
-	}
-
-loop:
-	n++;
-	if(debug['v'])
-		Bprint(&bso, "%5.2f span %d\n", cputime(), n);
-	Bflush(&bso);
-	if(n > 50) {
-		print("span must be looping\n");
-		errorexit();
-	}
-	again = 0;
-	c = INITTEXT;
-	for(p = firstp; p != P; p = p->link) {
-		if(p->as == ATEXT)
-			curtext = p;
-		if(p->to.type == D_BRANCH || p->back & 0100) {
-			if(p->back)
-				p->pc = c;
-			asmins(p);
-			m = andptr-and;
-			if(m != p->mark) {
-				p->mark = m;
-				again++;
-			}
-		}
-		p->pc = c;
-		c += p->mark;
-	}
-	if(again) {
-		textsize = c;
-		goto loop;
-	}
-	if(INITRND) {
-		INITDAT = rnd(c, INITRND);
-		if(INITDAT != idat) {
-			idat = INITDAT;
-			goto start;
-		}
-	}
-	xdefine("etext", STEXT, c);
-	if(debug['v'])
-		Bprint(&bso, "etext = %llux\n", c);
-	Bflush(&bso);
-	for(p = textp; p != P; p = p->pcond)
-		p->from.sym->value = p->pc;
-	textsize = c - INITTEXT;
-}
-
-void
-xdefine(char *p, int t, int64_t v)
-{
-	Sym *s;
-
-	s = lookup(p, 0);
-	if(s->type == 0 || s->type == SXREF) {
-		s->type = t;
-		s->value = v;
-	}
-	if(s->type == STEXT && s->value == 0)
-		s->value = v;
-}
-
-void
-putsymb(char *s, int t, int64_t v, int ver)
-{
-	int i, f, l;
-
-	if(t == 'f')
-		s++;
-	l = 4;
-	switch(HEADTYPE){
-	default:
-		break;
-	case 5:
-		if(debug['8'])
-			break;
-	case 2:
-	case 6:
-		lput(v>>32);
-		l = 8;
-		break;
-	}
-	lput(v);
-	if(ver)
-		t += 'a' - 'A';
-	cput(t+0x80);			/* 0x80 is variable length */
-
-	if(t == 'Z' || t == 'z') {
-		cput(s[0]);
-		for(i=1; s[i] != 0 || s[i+1] != 0; i += 2) {
-			cput(s[i]);
-			cput(s[i+1]);
-		}
-		cput(0);
-		cput(0);
-		i++;
-	}
-	else {
-		for(i=0; s[i]; i++)
-			cput(s[i]);
-		cput(0);
-	}
-	symsize += l + 1 + i + 1;
-
-	if(debug['n']) {
-		if(t == 'z' || t == 'Z') {
-			Bprint(&bso, "%c %.8llux ", t, v);
-			for(i=1; s[i] != 0 || s[i+1] != 0; i+=2) {
-				f = ((s[i]&0xff) << 8) | (s[i+1]&0xff);
-				Bprint(&bso, "/%x", f);
-			}
-			Bprint(&bso, "\n");
-			return;
-		}
-		if(ver)
-			Bprint(&bso, "%c %.8llux %s<%d>\n", t, v, s, ver);
-		else
-			Bprint(&bso, "%c %.8llux %s\n", t, v, s);
-	}
-}
-
-void
-asmsym(void)
-{
-	Prog *p;
-	Auto *a;
-	Sym *s;
-	int h;
-
-	s = lookup("etext", 0);
-	if(s->type == STEXT)
-		putsymb(s->name, 'T', s->value, s->version);
-
-	for(h=0; h<NHASH; h++)
-		for(s=hash[h]; s!=S; s=s->link)
-			switch(s->type) {
-			case SCONST:
-				putsymb(s->name, 'D', s->value, s->version);
-				continue;
-
-			case SDATA:
-				putsymb(s->name, 'D', s->value+INITDAT, s->version);
-				continue;
-
-			case SBSS:
-				putsymb(s->name, 'B', s->value+INITDAT, s->version);
-				continue;
-
-			case SFILE:
-				putsymb(s->name, 'f', s->value, s->version);
-				continue;
-			}
-
-	for(p=textp; p!=P; p=p->pcond) {
-		s = p->from.sym;
-		if(s->type != STEXT)
-			continue;
-
-		/* filenames first */
-		for(a=p->to.autom; a; a=a->link)
-			if(a->type == D_FILE)
-				putsymb(a->asym->name, 'z', a->aoffset, 0);
-			else
-			if(a->type == D_FILE1)
-				putsymb(a->asym->name, 'Z', a->aoffset, 0);
-
-		putsymb(s->name, 'T', s->value, s->version);
-
-		/* frame, auto and param after */
-		putsymb(".frame", 'm', p->to.offset+8, 0);
-
-		for(a=p->to.autom; a; a=a->link)
-			if(a->type == D_AUTO)
-				putsymb(a->asym->name, 'a', -a->aoffset, 0);
-			else
-			if(a->type == D_PARAM)
-				putsymb(a->asym->name, 'p', a->aoffset, 0);
-	}
-	if(debug['v'] || debug['n'])
-		Bprint(&bso, "symsize = %lud\n", symsize);
-	Bflush(&bso);
-}
-
-void
-asmlc(void)
-{
-	int64_t oldpc;
-	Prog *p;
-	int32_t oldlc, v, s;
-
-	oldpc = INITTEXT;
-	oldlc = 0;
-	for(p = firstp; p != P; p = p->link) {
-		if(p->line == oldlc || p->as == ATEXT || p->as == ANOP) {
-			if(p->as == ATEXT)
-				curtext = p;
-			if(debug['V'])
-				Bprint(&bso, "%6llux %P\n",
-					p->pc, p);
-			continue;
-		}
-		if(debug['V'])
-			Bprint(&bso, "\t\t%6ld", lcsize);
-		v = (p->pc - oldpc) / MINLC;
-		while(v) {
-			s = 127;
-			if(v < 127)
-				s = v;
-			cput(s+128);	/* 129-255 +pc */
-			if(debug['V'])
-				Bprint(&bso, " pc+%ld*%d(%ld)", s, MINLC, s+128);
-			v -= s;
-			lcsize++;
-		}
-		s = p->line - oldlc;
-		oldlc = p->line;
-		oldpc = p->pc + MINLC;
-		if(s > 64 || s < -64) {
-			cput(0);	/* 0 vv +lc */
-			cput(s>>24);
-			cput(s>>16);
-			cput(s>>8);
-			cput(s);
-			if(debug['V']) {
-				if(s > 0)
-					Bprint(&bso, " lc+%ld(%d,%ld)\n",
-						s, 0, s);
-				else
-					Bprint(&bso, " lc%ld(%d,%ld)\n",
-						s, 0, s);
-				Bprint(&bso, "%6llux %P\n",
-					p->pc, p);
-			}
-			lcsize += 5;
-			continue;
-		}
-		if(s > 0) {
-			cput(0+s);	/* 1-64 +lc */
-			if(debug['V']) {
-				Bprint(&bso, " lc+%ld(%ld)\n", s, 0+s);
-				Bprint(&bso, "%6llux %P\n",
-					p->pc, p);
-			}
-		} else {
-			cput(64-s);	/* 65-128 -lc */
-			if(debug['V']) {
-				Bprint(&bso, " lc%ld(%ld)\n", s, 64-s);
-				Bprint(&bso, "%6llux %P\n",
-					p->pc, p);
-			}
-		}
-		lcsize++;
-	}
-	while(lcsize & 1) {
-		s = 129;
-		cput(s);
-		lcsize++;
-	}
-	if(debug['v'] || debug['V'])
-		Bprint(&bso, "lcsize = %ld\n", lcsize);
-	Bflush(&bso);
-}
-
-int
-oclass(Adr *a)
-{
-	int64_t v;
-	int32_t l;
-
-	if(a->type >= D_INDIR || a->index != D_NONE) {
-		if(a->index != D_NONE && a->scale == 0) {
-			if(a->type == D_ADDR) {
-				switch(a->index) {
-				case D_EXTERN:
-				case D_STATIC:
-					return Yi32;	/* TO DO: Yi64 */
-				case D_AUTO:
-				case D_PARAM:
-					return Yiauto;
-				}
-				return Yxxx;
-			}
-			return Ycol;
-		}
-		return Ym;
-	}
-	switch(a->type)
-	{
-	case D_AL:
-		return Yal;
-
-	case D_AX:
-		return Yax;
-
-/*
-	case D_SPB:
-*/
-	case D_BPB:
-	case D_SIB:
-	case D_DIB:
-	case D_R8B:
-	case D_R9B:
-	case D_R10B:
-	case D_R11B:
-	case D_R12B:
-	case D_R13B:
-	case D_R14B:
-	case D_R15B:
-		if(asmode != 64)
-			return Yxxx;
-	case D_DL:
-	case D_BL:
-	case D_AH:
-	case D_CH:
-	case D_DH:
-	case D_BH:
-		return Yrb;
-
-	case D_CL:
-		return Ycl;
-
-	case D_CX:
-		return Ycx;
-
-	case D_DX:
-	case D_BX:
-		return Yrx;
-
-	case D_R8:	/* not really Yrl */
-	case D_R9:
-	case D_R10:
-	case D_R11:
-	case D_R12:
-	case D_R13:
-	case D_R14:
-	case D_R15:
-		if(asmode != 64)
-			return Yxxx;
-	case D_SP:
-	case D_BP:
-	case D_SI:
-	case D_DI:
-		return Yrl;
-
-	case D_F0+0:
-		return	Yf0;
-
-	case D_F0+1:
-	case D_F0+2:
-	case D_F0+3:
-	case D_F0+4:
-	case D_F0+5:
-	case D_F0+6:
-	case D_F0+7:
-		return	Yrf;
-
-	case D_M0+0:
-	case D_M0+1:
-	case D_M0+2:
-	case D_M0+3:
-	case D_M0+4:
-	case D_M0+5:
-	case D_M0+6:
-	case D_M0+7:
-		return	Ymr;
-
-	case D_X0+0:
-	case D_X0+1:
-	case D_X0+2:
-	case D_X0+3:
-	case D_X0+4:
-	case D_X0+5:
-	case D_X0+6:
-	case D_X0+7:
-	case D_X0+8:
-	case D_X0+9:
-	case D_X0+10:
-	case D_X0+11:
-	case D_X0+12:
-	case D_X0+13:
-	case D_X0+14:
-	case D_X0+15:
-		return	Yxr;
-
-	case D_NONE:
-		return Ynone;
-
-	case D_CS:	return	Ycs;
-	case D_SS:	return	Yss;
-	case D_DS:	return	Yds;
-	case D_ES:	return	Yes;
-	case D_FS:	return	Yfs;
-	case D_GS:	return	Ygs;
-
-	case D_GDTR:	return	Ygdtr;
-	case D_IDTR:	return	Yidtr;
-	case D_LDTR:	return	Yldtr;
-	case D_MSW:	return	Ymsw;
-	case D_TASK:	return	Ytask;
-
-	case D_CR+0:	return	Ycr0;
-	case D_CR+1:	return	Ycr1;
-	case D_CR+2:	return	Ycr2;
-	case D_CR+3:	return	Ycr3;
-	case D_CR+4:	return	Ycr4;
-	case D_CR+5:	return	Ycr5;
-	case D_CR+6:	return	Ycr6;
-	case D_CR+7:	return	Ycr7;
-	case D_CR+8:	return	Ycr8;
-
-	case D_DR+0:	return	Ydr0;
-	case D_DR+1:	return	Ydr1;
-	case D_DR+2:	return	Ydr2;
-	case D_DR+3:	return	Ydr3;
-	case D_DR+4:	return	Ydr4;
-	case D_DR+5:	return	Ydr5;
-	case D_DR+6:	return	Ydr6;
-	case D_DR+7:	return	Ydr7;
-
-	case D_TR+0:	return	Ytr0;
-	case D_TR+1:	return	Ytr1;
-	case D_TR+2:	return	Ytr2;
-	case D_TR+3:	return	Ytr3;
-	case D_TR+4:	return	Ytr4;
-	case D_TR+5:	return	Ytr5;
-	case D_TR+6:	return	Ytr6;
-	case D_TR+7:	return	Ytr7;
-
-	case D_EXTERN:
-	case D_STATIC:
-	case D_AUTO:
-	case D_PARAM:
-		return Ym;
-
-	case D_CONST:
-	case D_ADDR:
-		if(a->sym == S) {
-			v = a->offset;
-			if(v == 0)
-				return Yi0;
-			if(v == 1)
-				return Yi1;
-			if(v >= -128 && v <= 127)
-				return Yi8;
-			l = v;
-			if((int64_t)l == v)
-				return Ys32;	/* can sign extend */
-			if((v>>32) == 0)
-				return Yi32;	/* unsigned */
-			return Yi64;
-		}
-		return Yi32;	/* TO DO: D_ADDR as Yi64 */
-
-	case D_BRANCH:
-		return Ybr;
-	}
-	return Yxxx;
-}
-
-void
-asmidx(Adr *a, int base)
-{
-	int i;
-
-	switch(a->index) {
-	default:
-		goto bad;
-
-	case D_NONE:
-		i = 4 << 3;
-		goto bas;
-
-	case D_R8:
-	case D_R9:
-	case D_R10:
-	case D_R11:
-	case D_R12:
-	case D_R13:
-	case D_R14:
-	case D_R15:
-		if(asmode != 64)
-			goto bad;
-	case D_AX:
-	case D_CX:
-	case D_DX:
-	case D_BX:
-	case D_BP:
-	case D_SI:
-	case D_DI:
-		i = reg[a->index] << 3;
-		break;
-	}
-	switch(a->scale) {
-	default:
-		goto bad;
-	case 1:
-		break;
-	case 2:
-		i |= (1<<6);
-		break;
-	case 4:
-		i |= (2<<6);
-		break;
-	case 8:
-		i |= (3<<6);
-		break;
-	}
-bas:
-	switch(base) {
-	default:
-		goto bad;
-	case D_NONE:	/* must be mod=00 */
-		i |= 5;
-		break;
-	case D_R8:
-	case D_R9:
-	case D_R10:
-	case D_R11:
-	case D_R12:
-	case D_R13:
-	case D_R14:
-	case D_R15:
-		if(asmode != 64)
-			goto bad;
-	case D_AX:
-	case D_CX:
-	case D_DX:
-	case D_BX:
-	case D_SP:
-	case D_BP:
-	case D_SI:
-	case D_DI:
-		i |= reg[base];
-		break;
-	}
-	*andptr++ = i;
-	return;
-bad:
-	diag("asmidx: bad address %D", a);
-	*andptr++ = 0;
-	return;
-}
-
-static void
-put4(int32_t v)
-{
-	if(dlm && curp != P && reloca != nil){
-		dynreloc(reloca->sym, curp->pc + andptr - &and[0], 1);
-		reloca = nil;
-	}
-	andptr[0] = v;
-	andptr[1] = v>>8;
-	andptr[2] = v>>16;
-	andptr[3] = v>>24;
-	andptr += 4;
-}
-
-static void
-put8(int64_t v)
-{
-	if(dlm && curp != P && reloca != nil){
-		dynreloc(reloca->sym, curp->pc + andptr - &and[0], 1);	/* TO DO */
-		reloca = nil;
-	}
-	andptr[0] = v;
-	andptr[1] = v>>8;
-	andptr[2] = v>>16;
-	andptr[3] = v>>24;
-	andptr[4] = v>>32;
-	andptr[5] = v>>40;
-	andptr[6] = v>>48;
-	andptr[7] = v>>56;
-	andptr += 8;
-}
-
-int64_t
-vaddr(Adr *a)
-{
-	int t;
-	int64_t v;
-	Sym *s;
-
-	t = a->type;
-	v = a->offset;
-	if(t == D_ADDR)
-		t = a->index;
-	switch(t) {
-	case D_STATIC:
-	case D_EXTERN:
-		s = a->sym;
-		if(s != nil) {
-			if(dlm && curp != P)
-				reloca = a;
-			switch(s->type) {
-			case SUNDEF:
-				ckoff(s, v);
-			case STEXT:
-			case SCONST:
-				if((uint64_t)s->value < (uint64_t)INITTEXT)
-					v += INITTEXT;	/* TO DO */
-				v += s->value;
-				break;
-			default:
-				v += INITDAT + s->value;
-			}
-		}
-	}
-	return v;
-}
-
-static void
-asmandsz(Adr *a, int r, int rex, int m64)
-{
-	int32_t v;
-	int t;
-	Adr aa;
-
-	rex &= (0x40 | Rxr);
-	v = a->offset;
-	t = a->type;
-	if(a->index != D_NONE) {
-		if(t >= D_INDIR) {
-			t -= D_INDIR;
-			rexflag |= (regrex[a->index] & Rxx) | (regrex[t] & Rxb) | rex;
-			if(t == D_NONE) {
-				*andptr++ = (0 << 6) | (4 << 0) | (r << 3);
-				asmidx(a, t);
-				put4(v);
-				return;
-			}
-			if(v == 0 && t != D_BP && t != D_R13) {
-				*andptr++ = (0 << 6) | (4 << 0) | (r << 3);
-				asmidx(a, t);
-				return;
-			}
-			if(v >= -128 && v < 128) {
-				*andptr++ = (1 << 6) | (4 << 0) | (r << 3);
-				asmidx(a, t);
-				*andptr++ = v;
-				return;
-			}
-			*andptr++ = (2 << 6) | (4 << 0) | (r << 3);
-			asmidx(a, t);
-			put4(v);
-			return;
-		}
-		switch(t) {
-		default:
-			goto bad;
-		case D_STATIC:
-		case D_EXTERN:
-			aa.type = D_NONE+D_INDIR;
-			break;
-		case D_AUTO:
-		case D_PARAM:
-			aa.type = D_SP+D_INDIR;
-			break;
-		}
-		aa.offset = vaddr(a);
-		aa.index = a->index;
-		aa.scale = a->scale;
-		asmandsz(&aa, r, rex, m64);
-		return;
-	}
-	if(t >= D_AL && t <= D_X0+15) {
-		if(v)
-			goto bad;
-		*andptr++ = (3 << 6) | (reg[t] << 0) | (r << 3);
-		rexflag |= (regrex[t] & (0x40 | Rxb)) | rex;
-		return;
-	}
-	if(t >= D_INDIR) {
-		t -= D_INDIR;
-		rexflag |= (regrex[t] & Rxb) | rex;
-		if(t == D_NONE) {
-			if(asmode != 64){
-				*andptr++ = (0 << 6) | (5 << 0) | (r << 3);
-				put4(v);
-				return;
-			}
-			/* temporary */
-			*andptr++ = (0 <<  6) | (4 << 0) | (r << 3);	/* sib present */
-			*andptr++ = (0 << 6) | (4 << 3) | (5 << 0);	/* DS:d32 */
-			put4(v);
-			return;
-		}
-		if(t == D_SP || t == D_R12) {
-			if(v == 0) {
-				*andptr++ = (0 << 6) | (reg[t] << 0) | (r << 3);
-				asmidx(a, t);
-				return;
-			}
-			if(v >= -128 && v < 128) {
-				*andptr++ = (1 << 6) | (reg[t] << 0) | (r << 3);
-				asmidx(a, t);
-				*andptr++ = v;
-				return;
-			}
-			*andptr++ = (2 << 6) | (reg[t] << 0) | (r << 3);
-			asmidx(a, t);
-			put4(v);
-			return;
-		}
-		if(t >= D_AX && t <= D_R15) {
-			if(v == 0 && t != D_BP && t != D_R13) {
-				*andptr++ = (0 << 6) | (reg[t] << 0) | (r << 3);
-				return;
-			}
-			if(v >= -128 && v < 128) {
-				andptr[0] = (1 << 6) | (reg[t] << 0) | (r << 3);
-				andptr[1] = v;
-				andptr += 2;
-				return;
-			}
-			*andptr++ = (2 << 6) | (reg[t] << 0) | (r << 3);
-			put4(v);
-			return;
-		}
-		goto bad;
-	}
-	switch(a->type) {
-	default:
-		goto bad;
-	case D_STATIC:
-	case D_EXTERN:
-		aa.type = D_NONE+D_INDIR;
-		break;
-	case D_AUTO:
-	case D_PARAM:
-		aa.type = D_SP+D_INDIR;
-		break;
-	}
-	aa.index = D_NONE;
-	aa.scale = 1;
-	aa.offset = vaddr(a);
-	asmandsz(&aa, r, rex, m64);
-	return;
-bad:
-	diag("asmand: bad address %D", a);
-	return;
-}
-
-void
-asmand(Adr *a, Adr *ra)
-{
-	asmandsz(a, reg[ra->type], regrex[ra->type], 0);
-}
-
-void
-asmando(Adr *a, int o)
-{
-	asmandsz(a, o, 0, 0);
-}
-
-static void
-bytereg(Adr *a)
-{
-	if(a->index == D_NONE && (a->type >= D_AX && a->type <= D_R15))
-		a->type = D_AL + (a->type-D_AX);
-}
-
-#define	E	0xff
-Movtab	ymovtab[] =
-{
-/* push */
-	{APUSHL,	Ycs,	Ynone,	0,	0x0e,E,0,0},
-	{APUSHL,	Yss,	Ynone,	0,	0x16,E,0,0},
-	{APUSHL,	Yds,	Ynone,	0,	0x1e,E,0,0},
-	{APUSHL,	Yes,	Ynone,	0,	0x06,E,0,0},
-	{APUSHL,	Yfs,	Ynone,	0,	0x0f,0xa0,E,0},
-	{APUSHL,	Ygs,	Ynone,	0,	0x0f,0xa8,E,0},
-	{APUSHQ,	Yfs,	Ynone,	0,	0x0f,0xa0,E,0},
-	{APUSHQ,	Ygs,	Ynone,	0,	0x0f,0xa8,E,0},
-
-	{APUSHW,	Ycs,	Ynone,	0,	Pe,0x0e,E,0},
-	{APUSHW,	Yss,	Ynone,	0,	Pe,0x16,E,0},
-	{APUSHW,	Yds,	Ynone,	0,	Pe,0x1e,E,0},
-	{APUSHW,	Yes,	Ynone,	0,	Pe,0x06,E,0},
-	{APUSHW,	Yfs,	Ynone,	0,	Pe,0x0f,0xa0,E},
-	{APUSHW,	Ygs,	Ynone,	0,	Pe,0x0f,0xa8,E},
-
-/* pop */
-	{APOPL,	Ynone,	Yds,	0,	0x1f,E,0,0},
-	{APOPL,	Ynone,	Yes,	0,	0x07,E,0,0},
-	{APOPL,	Ynone,	Yss,	0,	0x17,E,0,0},
-	{APOPL,	Ynone,	Yfs,	0,	0x0f,0xa1,E,0},
-	{APOPL,	Ynone,	Ygs,	0,	0x0f,0xa9,E,0},
-	{APOPQ,	Ynone,	Yfs,	0,	0x0f,0xa1,E,0},
-	{APOPQ,	Ynone,	Ygs,	0,	0x0f,0xa9,E,0},
-
-	{APOPW,	Ynone,	Yds,	0,	Pe,0x1f,E,0},
-	{APOPW,	Ynone,	Yes,	0,	Pe,0x07,E,0},
-	{APOPW,	Ynone,	Yss,	0,	Pe,0x17,E,0},
-	{APOPW,	Ynone,	Yfs,	0,	Pe,0x0f,0xa1,E},
-	{APOPW,	Ynone,	Ygs,	0,	Pe,0x0f,0xa9,E},
-
-/* mov seg */
-	{AMOVW,	Yes,	Yml,	1,	0x8c,0,0,0},
-	{AMOVW,	Ycs,	Yml,	1,	0x8c,1,0,0},
-	{AMOVW,	Yss,	Yml,	1,	0x8c,2,0,0},
-	{AMOVW,	Yds,	Yml,	1,	0x8c,3,0,0},
-	{AMOVW,	Yfs,	Yml,	1,	0x8c,4,0,0},
-	{AMOVW,	Ygs,	Yml,	1,	0x8c,5,0,0},
-
-	{AMOVW,	Yml,	Yes,	2,	0x8e,0,0,0},
-	{AMOVW,	Yml,	Ycs,	2,	0x8e,1,0,0},
-	{AMOVW,	Yml,	Yss,	2,	0x8e,2,0,0},
-	{AMOVW,	Yml,	Yds,	2,	0x8e,3,0,0},
-	{AMOVW,	Yml,	Yfs,	2,	0x8e,4,0,0},
-	{AMOVW,	Yml,	Ygs,	2,	0x8e,5,0,0},
-
-/* mov cr */
-	{AMOVL,	Ycr0,	Yml,	3,	0x0f,0x20,0,0},
-	{AMOVL,	Ycr2,	Yml,	3,	0x0f,0x20,2,0},
-	{AMOVL,	Ycr3,	Yml,	3,	0x0f,0x20,3,0},
-	{AMOVL,	Ycr4,	Yml,	3,	0x0f,0x20,4,0},
-	{AMOVL,	Ycr8,	Yml,	3,	0x0f,0x20,8,0},
-	{AMOVQ,	Ycr0,	Yml,	3,	0x0f,0x20,0,0},
-	{AMOVQ,	Ycr2,	Yml,	3,	0x0f,0x20,2,0},
-	{AMOVQ,	Ycr3,	Yml,	3,	0x0f,0x20,3,0},
-	{AMOVQ,	Ycr4,	Yml,	3,	0x0f,0x20,4,0},
-	{AMOVQ,	Ycr8,	Yml,	3,	0x0f,0x20,8,0},
-
-	{AMOVL,	Yml,	Ycr0,	4,	0x0f,0x22,0,0},
-	{AMOVL,	Yml,	Ycr2,	4,	0x0f,0x22,2,0},
-	{AMOVL,	Yml,	Ycr3,	4,	0x0f,0x22,3,0},
-	{AMOVL,	Yml,	Ycr4,	4,	0x0f,0x22,4,0},
-	{AMOVL,	Yml,	Ycr8,	4,	0x0f,0x22,8,0},
-	{AMOVQ,	Yml,	Ycr0,	4,	0x0f,0x22,0,0},
-	{AMOVQ,	Yml,	Ycr2,	4,	0x0f,0x22,2,0},
-	{AMOVQ,	Yml,	Ycr3,	4,	0x0f,0x22,3,0},
-	{AMOVQ,	Yml,	Ycr4,	4,	0x0f,0x22,4,0},
-	{AMOVQ,	Yml,	Ycr8,	4,	0x0f,0x22,8,0},
-
-/* mov dr */
-	{AMOVL,	Ydr0,	Yml,	3,	0x0f,0x21,0,0},
-	{AMOVL,	Ydr6,	Yml,	3,	0x0f,0x21,6,0},
-	{AMOVL,	Ydr7,	Yml,	3,	0x0f,0x21,7,0},
-	{AMOVQ,	Ydr0,	Yml,	3,	0x0f,0x21,0,0},
-	{AMOVQ,	Ydr6,	Yml,	3,	0x0f,0x21,6,0},
-	{AMOVQ,	Ydr7,	Yml,	3,	0x0f,0x21,7,0},
-
-	{AMOVL,	Yml,	Ydr0,	4,	0x0f,0x23,0,0},
-	{AMOVL,	Yml,	Ydr6,	4,	0x0f,0x23,6,0},
-	{AMOVL,	Yml,	Ydr7,	4,	0x0f,0x23,7,0},
-	{AMOVQ,	Yml,	Ydr0,	4,	0x0f,0x23,0,0},
-	{AMOVQ,	Yml,	Ydr6,	4,	0x0f,0x23,6,0},
-	{AMOVQ,	Yml,	Ydr7,	4,	0x0f,0x23,7,0},
-
-/* mov tr */
-	{AMOVL,	Ytr6,	Yml,	3,	0x0f,0x24,6,0},
-	{AMOVL,	Ytr7,	Yml,	3,	0x0f,0x24,7,0},
-
-	{AMOVL,	Yml,	Ytr6,	4,	0x0f,0x26,6,E},
-	{AMOVL,	Yml,	Ytr7,	4,	0x0f,0x26,7,E},
-
-/* lgdt, sgdt, lidt, sidt */
-	{AMOVL,	Ym,	Ygdtr,	4,	0x0f,0x01,2,0},
-	{AMOVL,	Ygdtr,	Ym,	3,	0x0f,0x01,0,0},
-	{AMOVL,	Ym,	Yidtr,	4,	0x0f,0x01,3,0},
-	{AMOVL,	Yidtr,	Ym,	3,	0x0f,0x01,1,0},
-	{AMOVQ,	Ym,	Ygdtr,	4,	0x0f,0x01,2,0},
-	{AMOVQ,	Ygdtr,	Ym,	3,	0x0f,0x01,0,0},
-	{AMOVQ,	Ym,	Yidtr,	4,	0x0f,0x01,3,0},
-	{AMOVQ,	Yidtr,	Ym,	3,	0x0f,0x01,1,0},
-
-/* lldt, sldt */
-	{AMOVW,	Yml,	Yldtr,	4,	0x0f,0x00,2,0},
-	{AMOVW,	Yldtr,	Yml,	3,	0x0f,0x00,0,0},
-
-/* lmsw, smsw */
-	{AMOVW,	Yml,	Ymsw,	4,	0x0f,0x01,6,0},
-	{AMOVW,	Ymsw,	Yml,	3,	0x0f,0x01,4,0},
-
-/* ltr, str */
-	{AMOVW,	Yml,	Ytask,	4,	0x0f,0x00,3,0},
-	{AMOVW,	Ytask,	Yml,	3,	0x0f,0x00,1,0},
-
-/* load full pointer */
-	{AMOVL,	Yml,	Ycol,	5,	0,0,0,0},
-	{AMOVW,	Yml,	Ycol,	5,	Pe,0,0,0},
-
-/* double shift */
-	{ASHLL,	Ycol,	Yml,	6,	0xa4,0xa5,0,0},
-	{ASHRL,	Ycol,	Yml,	6,	0xac,0xad,0,0},
-	{ASHLQ,	Ycol,	Yml,	6,	Pw,0xa4,0xa5,0},
-	{ASHRQ,	Ycol,	Yml,	6,	Pw,0xac,0xad,0},
-	{ASHLW,	Ycol,	Yml,	6,	Pe,0xa4,0xa5,0},
-	{ASHRW,	Ycol,	Yml,	6,	Pe,0xac,0xad,0},
-	0
-};
-
-int
-isax(Adr *a)
-{
-
-	switch(a->type) {
-	case D_AX:
-	case D_AL:
-	case D_AH:
-	case D_INDIR+D_AX:
-		return 1;
-	}
-	if(a->index == D_AX)
-		return 1;
-	return 0;
-}
-
-void
-subreg(Prog *p, int from, int to)
-{
-
-	if(debug['Q'])
-		print("\n%P	s/%R/%R/\n", p, from, to);
-
-	if(p->from.type == from)
-		p->from.type = to;
-	if(p->to.type == from)
-		p->to.type = to;
-
-	if(p->from.index == from)
-		p->from.index = to;
-	if(p->to.index == from)
-		p->to.index = to;
-
-	from += D_INDIR;
-	if(p->from.type == from)
-		p->from.type = to+D_INDIR;
-	if(p->to.type == from)
-		p->to.type = to+D_INDIR;
-
-	if(debug['Q'])
-		print("%P\n", p);
-}
-
-static int
-mediaop(Optab *o, int op, int osize, int z)
-{
-	switch(op){
-	case Pm:
-	case Pe:
-	case Pf2:
-	case Pf3:
-		if(osize != 1){
-			if(op != Pm)
-				*andptr++ = op;
-			*andptr++ = Pm;
-			op = o->op[++z];
-			break;
-		}
-	default:
-		if(andptr == and || andptr[-1] != Pm)
-			*andptr++ = Pm;
-		break;
-	}
-	*andptr++ = op;
-	return z;
-}
-
-void
-doasm(Prog *p)
-{
-	Optab *o;
-	Prog *q, pp;
-	uint8_t *t;
-	Movtab *mo;
-	int z, op, ft, tt, xo, l;
-	int64_t v;
-
-	o = opindex[p->as];
-	if(o == nil) {
-		diag("asmins: missing op %P", p);
-		return;
-	}
-	ft = oclass(&p->from) * Ymax;
-	tt = oclass(&p->to) * Ymax;
-	t = o->ytab;
-	if(t == 0) {
-		diag("asmins: noproto %P", p);
-		return;
-	}
-	xo = o->op[0] == 0x0f;
-	for(z=0; *t; z+=t[3]+xo,t+=4)
-		if(ycover[ft+t[0]])
-		if(ycover[tt+t[1]])
-			goto found;
-	goto domov;
-
-found:
-	switch(o->prefix) {
-	case Pq:	/* 16 bit escape and opcode escape */
-		*andptr++ = Pe;
-		*andptr++ = Pm;
-		break;
-
-	case Pf2:	/* xmm opcode escape */
-	case Pf3:
-		*andptr++ = o->prefix;
-		*andptr++ = Pm;
-		break;
-
-	case Pm:	/* opcode escape */
-		*andptr++ = Pm;
-		break;
-
-	case Pe:	/* 16 bit escape */
-		*andptr++ = Pe;
-		break;
-
-	case Pw:	/* 64-bit escape */
-		if(p->mode != 64)
-			diag("asmins: illegal 64: %P", p);
-		rexflag |= Pw;
-		break;
-
-	case Pb:	/* botch */
-		bytereg(&p->from);
-		bytereg(&p->to);
-		break;
-
-	case P32:	/* 32 bit but illegal if 64-bit mode */
-		if(p->mode == 64)
-			diag("asmins: illegal in 64-bit mode: %P", p);
-		break;
-
-	case Py:	/* 64-bit only, no prefix */
-		if(p->mode != 64)
-			diag("asmins: illegal in %d-bit mode: %P", p->mode, p);
-		break;
-	}
-	v = vaddr(&p->from);
-	op = o->op[z];
-	if(op == 0x0f) {
-		*andptr++ = op;
-		op = o->op[++z];
-	}
-	switch(t[2]) {
-	default:
-		diag("asmins: unknown z %d %P", t[2], p);
-		return;
-
-	case Zpseudo:
-		break;
-
-	case Zlit:
-		for(; op = o->op[z]; z++)
-			*andptr++ = op;
-		break;
-
-	case Zmb_r:
-		bytereg(&p->from);
-		/* fall through */
-	case Zm_r:
-		*andptr++ = op;
-		asmand(&p->from, &p->to);
-		break;
-
-	case Zm_r_xm:
-		mediaop(o, op, t[3], z);
-		asmand(&p->from, &p->to);
-		break;
-
-	case Zm_r_xm_nr:
-		rexflag = 0;
-		mediaop(o, op, t[3], z);
-		asmand(&p->from, &p->to);
-		break;
-
-	case Zm_r_i_xm:
-		mediaop(o, op, t[3], z);
-		asmand(&p->from, &p->to);
-		*andptr++ = p->to.offset;
-		break;
-
-	case Zm_r_3d:
-		*andptr++ = 0x0f;
-		*andptr++ = 0x0f;
-		asmand(&p->from, &p->to);
-		*andptr++ = op;
-		break;
-
-	case Zibm_r:
-		*andptr++ = op;
-		asmand(&p->from, &p->to);
-		*andptr++ = p->to.offset;
-		break;
-
-	case Zaut_r:
-		*andptr++ = 0x8d;	/* leal */
-		if(p->from.type != D_ADDR)
-			diag("asmins: Zaut sb type ADDR");
-		p->from.type = p->from.index;
-		p->from.index = D_NONE;
-		asmand(&p->from, &p->to);
-		p->from.index = p->from.type;
-		p->from.type = D_ADDR;
-		break;
-
-	case Zm_o:
-		*andptr++ = op;
-		asmando(&p->from, o->op[z+1]);
-		break;
-
-	case Zr_m:
-		*andptr++ = op;
-		asmand(&p->to, &p->from);
-		break;
-
-	case Zr_m_xm:
-		mediaop(o, op, t[3], z);
-		asmand(&p->to, &p->from);
-		break;
-
-	case Zr_m_xm_nr:
-		rexflag = 0;
-		mediaop(o, op, t[3], z);
-		asmand(&p->to, &p->from);
-		break;
-
-	case Zr_m_i_xm:
-		mediaop(o, op, t[3], z);
-		asmand(&p->to, &p->from);
-		*andptr++ = p->from.offset;
-		break;
-
-	case Zo_m:
-		*andptr++ = op;
-		asmando(&p->to, o->op[z+1]);
-		break;
-
-	case Zo_m64:
-		*andptr++ = op;
-		asmandsz(&p->to, o->op[z+1], 0, 1);
-		break;
-
-	case Zm_ibo:
-		v = vaddr(&p->to);
-		*andptr++ = op;
-		asmando(&p->from, o->op[z+1]);
-		*andptr++ = v;
-		break;
-
-	case Zibo_m:
-		*andptr++ = op;
-		asmando(&p->to, o->op[z+1]);
-		*andptr++ = v;
-		break;
-
-	case Zibo_m_xm:
-		z = mediaop(o, op, t[3], z);
-		asmando(&p->to, o->op[z+1]);
-		*andptr++ = v;
-		break;
-
-	case Z_ib:
-		v = vaddr(&p->to);
-	case Zib_:
-		*andptr++ = op;
-		*andptr++ = v;
-		break;
-
-	case Zib_rp:
-		rexflag |= regrex[p->to.type] & (Rxb|0x40);
-		*andptr++ = op + reg[p->to.type];
-		*andptr++ = v;
-		break;
-
-	case Zil_rp:
-		rexflag |= regrex[p->to.type] & Rxb;
-		*andptr++ = op + reg[p->to.type];
-		if(o->prefix == Pe) {
-			*andptr++ = v;
-			*andptr++ = v>>8;
-		}
-		else
-			put4(v);
-		break;
-
-	case Zo_iw:
-		*andptr++ = op;
-		if(p->from.type != D_NONE){
-			*andptr++ = v;
-			*andptr++ = v>>8;
-		}
-		break;
-
-	case Ziq_rp:
-		l = v>>32;
-		if(l == 0){
-			//p->mark |= 0100;
-			//print("zero: %llux %P\n", v, p);
-			rexflag &= ~(0x40|Rxw);
-			rexflag |= regrex[p->to.type] & Rxb;
-			*andptr++ = 0xb8 + reg[p->to.type];
-			put4(v);
-		}else if(l == -1 && (v&((uint64_t)1<<31))!=0){	/* sign extend */
-			//p->mark |= 0100;
-			//print("sign: %llux %P\n", v, p);
-			*andptr ++ = 0xc7;
-			asmando(&p->to, 0);
-			put4(v);
-		}else{	/* need all 8 */
-			//print("all: %llux %P\n", v, p);
-			rexflag |= regrex[p->to.type] & Rxb;
-			*andptr++ = op + reg[p->to.type];
-			put8(v);
-		}
-		break;
-
-	case Zib_rr:
-		*andptr++ = op;
-		asmand(&p->to, &p->to);
-		*andptr++ = v;
-		break;
-
-	case Z_il:
-		v = vaddr(&p->to);
-	case Zil_:
-		*andptr++ = op;
-		if(o->prefix == Pe) {
-			*andptr++ = v;
-			*andptr++ = v>>8;
-		}
-		else
-			put4(v);
-		break;
-
-	case Zm_ilo:
-		v = vaddr(&p->to);
-		*andptr++ = op;
-		asmando(&p->from, o->op[z+1]);
-		if(o->prefix == Pe) {
-			*andptr++ = v;
-			*andptr++ = v>>8;
-		}
-		else
-			put4(v);
-		break;
-
-	case Zilo_m:
-		*andptr++ = op;
-		asmando(&p->to, o->op[z+1]);
-		if(o->prefix == Pe) {
-			*andptr++ = v;
-			*andptr++ = v>>8;
-		}
-		else
-			put4(v);
-		break;
-
-	case Zil_rr:
-		*andptr++ = op;
-		asmand(&p->to, &p->to);
-		if(o->prefix == Pe) {
-			*andptr++ = v;
-			*andptr++ = v>>8;
-		}
-		else
-			put4(v);
-		break;
-
-	case Z_rp:
-		rexflag |= regrex[p->to.type] & (Rxb|0x40);
-		*andptr++ = op + reg[p->to.type];
-		break;
-
-	case Zrp_:
-		rexflag |= regrex[p->from.type] & (Rxb|0x40);
-		*andptr++ = op + reg[p->from.type];
-		break;
-
-	case Zclr:
-		*andptr++ = op;
-		asmand(&p->to, &p->to);
-		break;
-
-	case Zbr:
-		q = p->pcond;
-		if(q) {
-			v = q->pc - p->pc - 2;
-			if(v >= -128 && v <= 127) {
-				*andptr++ = op;
-				*andptr++ = v;
-			} else {
-				v -= 6-2;
-				*andptr++ = 0x0f;
-				*andptr++ = o->op[z+1];
-				*andptr++ = v;
-				*andptr++ = v>>8;
-				*andptr++ = v>>16;
-				*andptr++ = v>>24;
-			}
-		}
-		break;
-
-	case Zcall:
-		q = p->pcond;
-		if(q) {
-			v = q->pc - p->pc - 5;
-			if(dlm && curp != P && p->to.sym->type == SUNDEF){
-				/* v = 0 - p->pc - 5; */
-				v = 0;
-				ckoff(p->to.sym, v);
-				v += p->to.sym->value;
-				dynreloc(p->to.sym, p->pc+1, 0);
-			}
-			*andptr++ = op;
-			*andptr++ = v;
-			*andptr++ = v>>8;
-			*andptr++ = v>>16;
-			*andptr++ = v>>24;
-		}
-		break;
-
-	case Zjmp:
-		q = p->pcond;
-		if(q) {
-			v = q->pc - p->pc - 2;
-			if(v >= -128 && v <= 127) {
-				*andptr++ = op;
-				*andptr++ = v;
-			} else {
-				v -= 5-2;
-				*andptr++ = o->op[z+1];
-				*andptr++ = v;
-				*andptr++ = v>>8;
-				*andptr++ = v>>16;
-				*andptr++ = v>>24;
-			}
-		}
-		break;
-
-	case Zloop:
-		q = p->pcond;
-		if(q) {
-			v = q->pc - p->pc - 2;
-			if(v < -128 || v > 127)
-				diag("loop too far: %P", p);
-			*andptr++ = op;
-			*andptr++ = v;
-		}
-		break;
-
-	case Zbyte:
-		*andptr++ = v;
-		if(op > 1) {
-			*andptr++ = v>>8;
-			if(op > 2) {
-				*andptr++ = v>>16;
-				*andptr++ = v>>24;
-				if(op > 4) {
-					*andptr++ = v>>32;
-					*andptr++ = v>>40;
-					*andptr++ = v>>48;
-					*andptr++ = v>>56;
-				}
-			}
-		}
-		break;
-	}
-	return;
-
-domov:
-	for(mo=ymovtab; mo->as; mo++)
-		if(p->as == mo->as)
-		if(ycover[ft+mo->ft])
-		if(ycover[tt+mo->tt]){
-			t = mo->op;
-			goto mfound;
-		}
-bad:
-	if(p->mode != 64){
-		/*
-		 * here, the assembly has failed.
-		 * if its a byte instruction that has
-		 * unaddressable registers, try to
-		 * exchange registers and reissue the
-		 * instruction with the operands renamed.
-		 */
-		pp = *p;
-		z = p->from.type;
-		if(z >= D_BP && z <= D_DI) {
-			if(isax(&p->to)) {
-				*andptr++ = 0x87;			/* xchg lhs,bx */
-				asmando(&p->from, reg[D_BX]);
-				subreg(&pp, z, D_BX);
-				doasm(&pp);
-				*andptr++ = 0x87;			/* xchg lhs,bx */
-				asmando(&p->from, reg[D_BX]);
-			} else {
-				*andptr++ = 0x90 + reg[z];		/* xchg lsh,ax */
-				subreg(&pp, z, D_AX);
-				doasm(&pp);
-				*andptr++ = 0x90 + reg[z];		/* xchg lsh,ax */
-			}
-			return;
-		}
-		z = p->to.type;
-		if(z >= D_BP && z <= D_DI) {
-			if(isax(&p->from)) {
-				*andptr++ = 0x87;			/* xchg rhs,bx */
-				asmando(&p->to, reg[D_BX]);
-				subreg(&pp, z, D_BX);
-				doasm(&pp);
-				*andptr++ = 0x87;			/* xchg rhs,bx */
-				asmando(&p->to, reg[D_BX]);
-			} else {
-				*andptr++ = 0x90 + reg[z];		/* xchg rsh,ax */
-				subreg(&pp, z, D_AX);
-				doasm(&pp);
-				*andptr++ = 0x90 + reg[z];		/* xchg rsh,ax */
-			}
-			return;
-		}
-	}
-	diag("doasm: notfound from=%ux to=%ux %P", p->from.type, p->to.type, p);
-	return;
-
-mfound:
-	switch(mo->code) {
-	default:
-		diag("asmins: unknown mov %d %P", mo->code, p);
-		break;
-
-	case 0:	/* lit */
-		for(z=0; t[z]!=E; z++)
-			*andptr++ = t[z];
-		break;
-
-	case 1:	/* r,m */
-		*andptr++ = t[0];
-		asmando(&p->to, t[1]);
-		break;
-
-	case 2:	/* m,r */
-		*andptr++ = t[0];
-		asmando(&p->from, t[1]);
-		break;
-
-	case 3:	/* r,m - 2op */
-		*andptr++ = t[0];
-		*andptr++ = t[1];
-		asmando(&p->to, t[2]);
-		rexflag |= regrex[p->from.type] & (Rxr|0x40);
-		break;
-
-	case 4:	/* m,r - 2op */
-		*andptr++ = t[0];
-		*andptr++ = t[1];
-		asmando(&p->from, t[2]);
-		rexflag |= regrex[p->to.type] & (Rxr|0x40);
-		break;
-
-	case 5:	/* load full pointer, trash heap */
-		if(t[0])
-			*andptr++ = t[0];
-		switch(p->to.index) {
-		default:
-			goto bad;
-		case D_DS:
-			*andptr++ = 0xc5;
-			break;
-		case D_SS:
-			*andptr++ = 0x0f;
-			*andptr++ = 0xb2;
-			break;
-		case D_ES:
-			*andptr++ = 0xc4;
-			break;
-		case D_FS:
-			*andptr++ = 0x0f;
-			*andptr++ = 0xb4;
-			break;
-		case D_GS:
-			*andptr++ = 0x0f;
-			*andptr++ = 0xb5;
-			break;
-		}
-		asmand(&p->from, &p->to);
-		break;
-
-	case 6:	/* double shift */
-		if(t[0] == Pw){
-			if(p->mode != 64)
-				diag("asmins: illegal 64: %P", p);
-			rexflag |= Pw;
-			t++;
-		}else if(t[0] == Pe){
-			*andptr++ = Pe;
-			t++;
-		}
-		z = p->from.type;
-		switch(z) {
-		default:
-			goto bad;
-		case D_CONST:
-			*andptr++ = 0x0f;
-			*andptr++ = t[0];
-			asmandsz(&p->to, reg[p->from.index], regrex[p->from.index], 0);
-			*andptr++ = p->from.offset;
-			break;
-		case D_CL:
-		case D_CX:
-			*andptr++ = 0x0f;
-			*andptr++ = t[1];
-			asmandsz(&p->to, reg[p->from.index], regrex[p->from.index], 0);
-			break;
-		}
-		break;
-	}
-}
-
-void
-asmins(Prog *p)
-{
-	int n, np, c;
-
-	rexflag = 0;
-	andptr = and;
-	asmode = p->mode;
-	doasm(p);
-	if(rexflag){
-		/*
-		 * as befits the whole approach of the architecture,
-		 * the rex prefix must appear before the first opcode byte
-		 * (and thus after any 66/67/f2/f3/26/2e/3e prefix bytes, but
-		 * before the 0f opcode escape!), or it might be ignored.
-		 * note that the handbook often misleadingly shows 66/f2/f3 in `opcode'.
-		 */
-		if(p->mode != 64)
-			diag("asmins: illegal in mode %d: %P", p->mode, p);
-		n = andptr - and;
-		for(np = 0; np < n; np++) {
-			c = and[np];
-			if(c != 0xf2 && c != 0xf3 && (c < 0x64 || c > 0x67) && c != 0x2e && c != 0x3e && c != 0x26)
-				break;
-		}
-		memmove(and+np+1, and+np, n-np);
-		and[np] = 0x40 | rexflag;
-		andptr++;
-	}
-}
-
-enum{
-	ABSD = 0,
-	ABSU = 1,
-	RELD = 2,
-	RELU = 3,
-};
-
-int modemap[4] = { 0, 1, -1, 2, };
-
-typedef struct Reloc Reloc;
-
-struct Reloc
-{
-	int n;
-	int t;
-	uint8_t *m;
-	uint32_t *a;
-};
-
-Reloc rels;
-
-static void
-grow(Reloc *r)
-{
-	int t;
-	uint8_t *m, *nm;
-	uint32_t *a, *na;
-
-	t = r->t;
-	r->t += 64;
-	m = r->m;
-	a = r->a;
-	r->m = nm = malloc(r->t*sizeof(uint8_t));
-	r->a = na = malloc(r->t*sizeof(uint32_t));
-	memmove(nm, m, t*sizeof(uint8_t));
-	memmove(na, a, t*sizeof(uint32_t));
-	free(m);
-	free(a);
-}
-
-void
-dynreloc(Sym *s, uint32_t v, int abs)
-{
-	int i, k, n;
-	uint8_t *m;
-	uint32_t *a;
-	Reloc *r;
-
-	if(s->type == SUNDEF)
-		k = abs ? ABSU : RELU;
-	else
-		k = abs ? ABSD : RELD;
-	/* Bprint(&bso, "R %s a=%ld(%lx) %d\n", s->name, v, v, k); */
-	k = modemap[k];
-	r = &rels;
-	n = r->n;
-	if(n >= r->t)
-		grow(r);
-	m = r->m;
-	a = r->a;
-	for(i = n; i > 0; i--){
-		if(v < a[i-1]){	/* happens occasionally for data */
-			m[i] = m[i-1];
-			a[i] = a[i-1];
-		}
-		else
-			break;
-	}
-	m[i] = k;
-	a[i] = v;
-	r->n++;
-}
-
-static int
-sput(char *s)
-{
-	char *p;
-
-	p = s;
-	while(*s)
-		cput(*s++);
-	cput(0);
-	return s-p+1;
-}
-
-void
-asmdyn()
-{
-	int i, n, t, c;
-	Sym *s;
-	uint32_t la, ra, *a;
-	int64_t off;
-	uint8_t *m;
-	Reloc *r;
-
-	cflush();
-	off = seek(cout, 0, 1);
-	lput(0);
-	t = 0;
-	lput(imports);
-	t += 4;
-	for(i = 0; i < NHASH; i++)
-		for(s = hash[i]; s != S; s = s->link)
-			if(s->type == SUNDEF){
-				lput(s->sig);
-				t += 4;
-				t += sput(s->name);
-			}
-
-	la = 0;
-	r = &rels;
-	n = r->n;
-	m = r->m;
-	a = r->a;
-	lput(n);
-	t += 4;
-	for(i = 0; i < n; i++){
-		ra = *a-la;
-		if(*a < la)
-			diag("bad relocation order");
-		if(ra < 256)
-			c = 0;
-		else if(ra < 65536)
-			c = 1;
-		else
-			c = 2;
-		cput((c<<6)|*m++);
-		t++;
-		if(c == 0){
-			cput(ra);
-			t++;
-		}
-		else if(c == 1){
-			wput(ra);
-			t += 2;
-		}
-		else{
-			lput(ra);
-			t += 4;
-		}
-		la = *a++;
-	}
-
-	cflush();
-	seek(cout, off, 0);
-	lput(t);
-
-	if(debug['v']){
-		Bprint(&bso, "import table entries = %d\n", imports);
-		Bprint(&bso, "export table entries = %d\n", exports);
-	}
-}

+ 0 - 204
sys/src/cmd/8a/a.h

@@ -1,204 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <bio.h>
-#include "../8c/8.out.h"
-
-#ifndef	EXTERN
-#define	EXTERN	extern
-#endif
-
-typedef	struct	Sym	Sym;
-typedef	struct	Ref	Ref;
-typedef	struct	Gen	Gen;
-typedef	struct	Io	Io;
-typedef	struct	Hist	Hist;
-typedef	struct	Gen2 	Gen2;
-
-#define	MAXALIGN	7
-#define	FPCHIP		1
-#define	NSYMB		500
-#define	BUFSIZ		8192
-#define	HISTSZ		20
-#define	NINCLUDE	10
-#define	NHUNK		10000
-#define	EOF		(-1)
-#define	IGN		(-2)
-#define	GETC()		((--fi.c < 0)? filbuf(): *fi.p++ & 0xff)
-#define	NHASH		503
-#define	STRINGSZ	200
-#define	NMACRO		10
-
-struct	Sym
-{
-	Sym*	link;
-	Ref*	ref;
-	char*	macro;
-	long	value;
-	ushort	type;
-	char	*name;
-	char	sym;
-};
-#define	S	((Sym*)0)
-
-struct	Ref
-{
-	int	class;
-};
-
-EXTERN struct
-{
-	char*	p;
-	int	c;
-} fi;
-
-struct	Io
-{
-	Io*	link;
-	char	b[BUFSIZ];
-	char*	p;
-	short	c;
-	short	f;
-};
-#define	I	((Io*)0)
-
-EXTERN struct
-{
-	Sym*	sym;
-	short	type;
-} h[NSYM];
-
-struct	Gen
-{
-	double	dval;
-	char	sval[8];
-	long	offset;
-	long	offset2;
-	Sym*	sym;
-	short	type;
-	short	index;
-	short	scale;
-};
-struct	Gen2
-{
-	Gen	from;
-	Gen	to;
-};
-
-struct	Hist
-{
-	Hist*	link;
-	char*	name;
-	long	line;
-	long	offset;
-};
-#define	H	((Hist*)0)
-
-enum
-{
-	CLAST,
-	CMACARG,
-	CMACRO,
-	CPREPROC,
-};
-
-
-EXTERN	char	debug[256];
-EXTERN	Sym*	hash[NHASH];
-EXTERN	char*	Dlist[30];
-EXTERN	int	nDlist;
-EXTERN	Hist*	ehist;
-EXTERN	int	newflag;
-EXTERN	Hist*	hist;
-EXTERN	char*	hunk;
-EXTERN	char*	include[NINCLUDE];
-EXTERN	Io*	iofree;
-EXTERN	Io*	ionext;
-EXTERN	Io*	iostack;
-EXTERN	long	lineno;
-EXTERN	int	nerrors;
-EXTERN	long	nhunk;
-EXTERN	int	ninclude;
-EXTERN	Gen	nullgen;
-EXTERN	char*	outfile;
-EXTERN	int	pass;
-EXTERN	char*	pathname;
-EXTERN	long	pc;
-EXTERN	int	peekc;
-EXTERN	int	sym;
-EXTERN	char	symb[NSYMB];
-EXTERN	int	thechar;
-EXTERN	char*	thestring;
-EXTERN	long	thunk;
-EXTERN	Biobuf	obuf;
-
-void*	allocn(void*, long, long);
-void	errorexit(void);
-void	pushio(void);
-void	newio(void);
-void	newfile(char*, int);
-Sym*	slookup(char*);
-Sym*	lookup(void);
-void	syminit(Sym*);
-long	yylex(void);
-int	getc(void);
-int	getnsc(void);
-void	unget(int);
-int	escchar(int);
-void	cinit(void);
-void	checkscale(int);
-void	pinit(char*);
-void	cclean(void);
-int	isreg(Gen*);
-void	outcode(int, Gen2*);
-void	outhist(void);
-void	zaddr(Gen*, int);
-void	zname(char*, int, int);
-void	ieeedtod(Ieee*, double);
-int	filbuf(void);
-Sym*	getsym(void);
-void	domacro(void);
-void	macund(void);
-void	macdef(void);
-void	macexpand(Sym*, char*);
-void	macinc(void);
-void	macprag(void);
-void	maclin(void);
-void	macif(int);
-void	macend(void);
-void	dodefine(char*);
-void	prfile(long);
-void	linehist(char*, int);
-void	gethunk(void);
-void	yyerror(char*, ...);
-int	yyparse(void);
-void	setinclude(char*);
-int	assemble(char*);
-
-/*
- *	system-dependent stuff from ../cc/compat.c
- */
-enum	/* keep in synch with ../cc/cc.h */
-{
-	Plan9	= 1<<0,
-	Unix	= 1<<1,
-	Windows	= 1<<2
-};
-int	mywait(int*);
-int	mycreat(char*, int);
-int	systemtype(int);
-int	pathchar(void);
-char*	mygetwd(char*, int);
-int	myexec(char*, char*[]);
-int	mydup(int, int);
-int	myfork(void);
-int	mypipe(int*);
-void*	mysbrk(ulong);

+ 0 - 577
sys/src/cmd/8a/a.y

@@ -1,577 +0,0 @@
-%{
-#include "a.h"
-%}
-%union	{
-	Sym	*sym;
-	long	lval;
-	struct {
-		long v1;
-		long v2;
-	} con2;
-	double	dval;
-	char	sval[8];
-	Gen	gen;
-	Gen2	gen2;
-}
-%left	'|'
-%left	'^'
-%left	'&'
-%left	'<' '>'
-%left	'+' '-'
-%left	'*' '/' '%'
-%token	<lval>	LTYPE0 LTYPE1 LTYPE2 LTYPE3 LTYPE4
-%token	<lval>	LTYPEC LTYPED LTYPEN LTYPER LTYPET LTYPES LTYPEM LTYPEI LTYPEG
-%token	<lval>	LCONST LFP LPC LSB
-%token	<lval>	LBREG LLREG LSREG LFREG
-%token	<dval>	LFCONST
-%token	<sval>	LSCONST LSP
-%token	<sym>	LNAME LLAB LVAR
-%type	<lval>	con expr pointer offset
-%type	<con2>	con2
-%type	<gen>	mem imm imm2 reg nam rel rem rim rom omem nmem
-%type	<gen2>	nonnon nonrel nonrem rimnon rimrem remrim
-%type	<gen2>	spec1 spec2 spec3 spec4 spec5 spec6 spec7 spec8
-%%
-prog:
-|	prog line
-
-line:
-	LLAB ':'
-	{
-		if($1->value != pc)
-			yyerror("redeclaration of %s", $1->name);
-		$1->value = pc;
-	}
-	line
-|	LNAME ':'
-	{
-		$1->type = LLAB;
-		$1->value = pc;
-	}
-	line
-|	';'
-|	inst ';'
-|	error ';'
-
-inst:
-	LNAME '=' expr
-	{
-		$1->type = LVAR;
-		$1->value = $3;
-	}
-|	LVAR '=' expr
-	{
-		if($1->value != $3)
-			yyerror("redeclaration of %s", $1->name);
-		$1->value = $3;
-	}
-|	LTYPE0 nonnon	{ outcode($1, &$2); }
-|	LTYPE1 nonrem	{ outcode($1, &$2); }
-|	LTYPE2 rimnon	{ outcode($1, &$2); }
-|	LTYPE3 rimrem	{ outcode($1, &$2); }
-|	LTYPE4 remrim	{ outcode($1, &$2); }
-|	LTYPER nonrel	{ outcode($1, &$2); }
-|	LTYPED spec1	{ outcode($1, &$2); }
-|	LTYPET spec2	{ outcode($1, &$2); }
-|	LTYPEC spec3	{ outcode($1, &$2); }
-|	LTYPEN spec4	{ outcode($1, &$2); }
-|	LTYPES spec5	{ outcode($1, &$2); }
-|	LTYPEM spec6	{ outcode($1, &$2); }
-|	LTYPEI spec7	{ outcode($1, &$2); }
-|	LTYPEG spec8	{ outcode($1, &$2); }
-
-nonnon:
-	{
-		$$.from = nullgen;
-		$$.to = nullgen;
-	}
-|	','
-	{
-		$$.from = nullgen;
-		$$.to = nullgen;
-	}
-
-rimrem:
-	rim ',' rem
-	{
-		$$.from = $1;
-		$$.to = $3;
-	}
-
-remrim:
-	rem ',' rim
-	{
-		$$.from = $1;
-		$$.to = $3;
-	}
-
-rimnon:
-	rim ','
-	{
-		$$.from = $1;
-		$$.to = nullgen;
-	}
-|	rim
-	{
-		$$.from = $1;
-		$$.to = nullgen;
-	}
-
-nonrem:
-	',' rem
-	{
-		$$.from = nullgen;
-		$$.to = $2;
-	}
-|	rem
-	{
-		$$.from = nullgen;
-		$$.to = $1;
-	}
-
-nonrel:
-	',' rel
-	{
-		$$.from = nullgen;
-		$$.to = $2;
-	}
-|	rel
-	{
-		$$.from = nullgen;
-		$$.to = $1;
-	}
-
-spec1:	/* DATA */
-	nam '/' con ',' imm
-	{
-		$$.from = $1;
-		$$.from.scale = $3;
-		$$.to = $5;
-	}
-
-spec2:	/* TEXT */
-	mem ',' imm
-	{
-		$$.from = $1;
-		$$.to = $3;
-	}
-|	mem ',' con ',' imm
-	{
-		$$.from = $1;
-		$$.from.scale = $3;
-		$$.to = $5;
-	}
-
-spec3:	/* JMP/CALL */
-	',' rom
-	{
-		$$.from = nullgen;
-		$$.to = $2;
-	}
-|	rom
-	{
-		$$.from = nullgen;
-		$$.to = $1;
-	}
-
-spec4:	/* NOP */
-	nonnon
-|	nonrem
-
-spec5:	/* SHL/SHR */
-	rim ',' rem
-	{
-		$$.from = $1;
-		$$.to = $3;
-	}
-|	rim ',' rem ':' LLREG
-	{
-		$$.from = $1;
-		$$.to = $3;
-		if($$.from.index != D_NONE)
-			yyerror("dp shift with lhs index");
-		$$.from.index = $5;
-	}
-
-spec6:	/* MOVW/MOVL */
-	rim ',' rem
-	{
-		$$.from = $1;
-		$$.to = $3;
-	}
-|	rim ',' rem ':' LSREG
-	{
-		$$.from = $1;
-		$$.to = $3;
-		if($$.to.index != D_NONE)
-			yyerror("dp move with lhs index");
-		$$.to.index = $5;
-	}
-
-spec7:
-	rim ','
-	{
-		$$.from = $1;
-		$$.to = nullgen;
-	}
-|	rim
-	{
-		$$.from = $1;
-		$$.to = nullgen;
-	}
-|	rim ',' rem
-	{
-		$$.from = $1;
-		$$.to = $3;
-	}
-
-spec8:	/* GLOBL */
-	mem ',' imm
-	{
-		$$.from = $1;
-		$$.to = $3;
-	}
-|	mem ',' con ',' imm
-	{
-		$$.from = $1;
-		$$.from.scale = $3;
-		$$.to = $5;
-	}
-
-rem:
-	reg
-|	mem
-
-rom:
-	rel
-|	nmem
-|	'*' reg
-	{
-		$$ = $2;
-	}
-|	'*' omem
-	{
-		$$ = $2;
-	}
-|	reg
-|	omem
-|	imm
-
-rim:
-	rem
-|	imm
-
-rel:
-	con '(' LPC ')'
-	{
-		$$ = nullgen;
-		$$.type = D_BRANCH;
-		$$.offset = $1 + pc;
-	}
-|	LNAME offset
-	{
-		$$ = nullgen;
-		if(pass == 2)
-			yyerror("undefined label: %s", $1->name);
-		$$.type = D_BRANCH;
-		$$.sym = $1;
-		$$.offset = $2;
-	}
-|	LLAB offset
-	{
-		$$ = nullgen;
-		$$.type = D_BRANCH;
-		$$.sym = $1;
-		$$.offset = $1->value + $2;
-	}
-
-reg:
-	LBREG
-	{
-		$$ = nullgen;
-		$$.type = $1;
-	}
-|	LFREG
-	{
-		$$ = nullgen;
-		$$.type = $1;
-	}
-|	LLREG
-	{
-		$$ = nullgen;
-		$$.type = $1;
-	}
-|	LSP
-	{
-		$$ = nullgen;
-		$$.type = D_SP;
-	}
-|	LSREG
-	{
-		$$ = nullgen;
-		$$.type = $1;
-	}
-
-imm:
-	'$' con
-	{
-		$$ = nullgen;
-		$$.type = D_CONST;
-		$$.offset = $2;
-	}
-|	'$' nam
-	{
-		$$ = $2;
-		$$.index = $2.type;
-		$$.type = D_ADDR;
-		/*
-		if($2.type == D_AUTO || $2.type == D_PARAM)
-			yyerror("constant cannot be automatic: %s",
-				$2.sym->name);
-		 */
-	}
-|	'$' LSCONST
-	{
-		$$ = nullgen;
-		$$.type = D_SCONST;
-		memcpy($$.sval, $2, sizeof($$.sval));
-	}
-|	'$' LFCONST
-	{
-		$$ = nullgen;
-		$$.type = D_FCONST;
-		$$.dval = $2;
-	}
-|	'$' '(' LFCONST ')'
-	{
-		$$ = nullgen;
-		$$.type = D_FCONST;
-		$$.dval = $3;
-	}
-|	'$' '-' LFCONST
-	{
-		$$ = nullgen;
-		$$.type = D_FCONST;
-		$$.dval = -$3;
-	}
-
-imm2:
-	'$' con2
-	{
-		$$ = nullgen;
-		$$.type = D_CONST2;
-		$$.offset = $2.v1;
-		$$.offset2 = $2.v2;
-	}
-
-con2:
-	LCONST
-	{
-		$$.v1 = $1;
-		$$.v2 = 0;
-	}
-|	'-' LCONST
-	{
-		$$.v1 = -$2;
-		$$.v2 = 0;
-	}
-|	LCONST '-' LCONST
-	{
-		$$.v1 = $1;
-		$$.v2 = $3;
-	}
-|	'-' LCONST '-' LCONST
-	{
-		$$.v1 = -$2;
-		$$.v2 = $4;
-	}
-
-mem:
-	omem
-|	nmem
-
-omem:
-	con
-	{
-		$$ = nullgen;
-		$$.type = D_INDIR+D_NONE;
-		$$.offset = $1;
-	}
-|	con '(' LLREG ')'
-	{
-		$$ = nullgen;
-		$$.type = D_INDIR+$3;
-		$$.offset = $1;
-	}
-|	con '(' LSP ')'
-	{
-		$$ = nullgen;
-		$$.type = D_INDIR+D_SP;
-		$$.offset = $1;
-	}
-|	con '(' LLREG '*' con ')'
-	{
-		$$ = nullgen;
-		$$.type = D_INDIR+D_NONE;
-		$$.offset = $1;
-		$$.index = $3;
-		$$.scale = $5;
-		checkscale($$.scale);
-	}
-|	con '(' LLREG ')' '(' LLREG '*' con ')'
-	{
-		$$ = nullgen;
-		$$.type = D_INDIR+$3;
-		$$.offset = $1;
-		$$.index = $6;
-		$$.scale = $8;
-		checkscale($$.scale);
-	}
-|	'(' LLREG ')'
-	{
-		$$ = nullgen;
-		$$.type = D_INDIR+$2;
-	}
-|	'(' LSP ')'
-	{
-		$$ = nullgen;
-		$$.type = D_INDIR+D_SP;
-	}
-|	con '(' LSREG ')'
-	{
-		$$ = nullgen;
-		$$.type = D_INDIR+$3;
-		$$.offset = $1;
-	}
-|	'(' LLREG '*' con ')'
-	{
-		$$ = nullgen;
-		$$.type = D_INDIR+D_NONE;
-		$$.index = $2;
-		$$.scale = $4;
-		checkscale($$.scale);
-	}
-|	'(' LLREG ')' '(' LLREG '*' con ')'
-	{
-		$$ = nullgen;
-		$$.type = D_INDIR+$2;
-		$$.index = $5;
-		$$.scale = $7;
-		checkscale($$.scale);
-	}
-
-nmem:
-	nam
-	{
-		$$ = $1;
-	}
-|	nam '(' LLREG '*' con ')'
-	{
-		$$ = $1;
-		$$.index = $3;
-		$$.scale = $5;
-		checkscale($$.scale);
-	}
-
-nam:
-	LNAME offset '(' pointer ')'
-	{
-		$$ = nullgen;
-		$$.type = $4;
-		$$.sym = $1;
-		$$.offset = $2;
-	}
-|	LNAME '<' '>' offset '(' LSB ')'
-	{
-		$$ = nullgen;
-		$$.type = D_STATIC;
-		$$.sym = $1;
-		$$.offset = $4;
-	}
-
-offset:
-	{
-		$$ = 0;
-	}
-|	'+' con
-	{
-		$$ = $2;
-	}
-|	'-' con
-	{
-		$$ = -$2;
-	}
-
-pointer:
-	LSB
-|	LSP
-	{
-		$$ = D_AUTO;
-	}
-|	LFP
-
-con:
-	LCONST
-|	LVAR
-	{
-		$$ = $1->value;
-	}
-|	'-' con
-	{
-		$$ = -$2;
-	}
-|	'+' con
-	{
-		$$ = $2;
-	}
-|	'~' con
-	{
-		$$ = ~$2;
-	}
-|	'(' expr ')'
-	{
-		$$ = $2;
-	}
-
-expr:
-	con
-|	expr '+' expr
-	{
-		$$ = $1 + $3;
-	}
-|	expr '-' expr
-	{
-		$$ = $1 - $3;
-	}
-|	expr '*' expr
-	{
-		$$ = $1 * $3;
-	}
-|	expr '/' expr
-	{
-		$$ = $1 / $3;
-	}
-|	expr '%' expr
-	{
-		$$ = $1 % $3;
-	}
-|	expr '<' '<' expr
-	{
-		$$ = $1 << $4;
-	}
-|	expr '>' '>' expr
-	{
-		$$ = $1 >> $4;
-	}
-|	expr '&' expr
-	{
-		$$ = $1 & $3;
-	}
-|	expr '^' expr
-	{
-		$$ = $1 ^ $3;
-	}
-|	expr '|' expr
-	{
-		$$ = $1 | $3;
-	}

+ 0 - 704
sys/src/cmd/8a/l.s

@@ -1,704 +0,0 @@
-/*
- * Memory and machine-specific definitions.  Used in C and assembler.
- */
-
-/*
- * Sizes
- */
-#define	BI2BY		8			/* bits per byte */
-#define BI2WD		32			/* bits per word */
-#define	BY2WD		4			/* bytes per word */
-#define	BY2PG		4096			/* bytes per page */
-#define	WD2PG		(BY2PG/BY2WD)		/* words per page */
-#define	PGSHIFT		12			/* log(BY2PG) */
-#define PGROUND(s)	(((s)+(BY2PG-1))&~(BY2PG-1))
-
-#define	MAXMACH		1			/* max # cpus system can run */
-
-/*
- * Time
- */
-#define	HZ		(20)			/* clock frequency */
-#define	MS2HZ		(1000/HZ)		/* millisec per clock tick */
-#define	TK2SEC(t)	((t)/HZ)		/* ticks to seconds */
-#define	TK2MS(t)	((((ulong)(t))*1000)/HZ)	/* ticks to milliseconds */
-#define	MS2TK(t)	((((ulong)(t))*HZ)/1000)	/* milliseconds to ticks */
-
-/*
- * Fundamental addresses
- */
-
-/*
- *  Address spaces
- *
- *  User is at 0-2GB
- *  Kernel is at 2GB-4GB
- *
- *  To avoid an extra page map, both the user stack (USTKTOP) and
- *  the temporary user stack (TSTKTOP) should be in the the same
- *  4 meg.
- */
-#define	UZERO		0			/* base of user address space */
-#define	UTZERO		(UZERO+BY2PG)		/* first address in user text */
-#define	KZERO		0x80000000		/* base of kernel address space */
-#define	KTZERO		KZERO			/* first address in kernel text */
-#define	USERADDR	0xC0000000		/* struct User */
-#define	UREGADDR	(USERADDR+BY2PG-4*19)	
-#define	TSTKTOP		USERADDR		/* end of new stack in sysexec */
-#define TSTKSIZ 10
-#define	USTKTOP		(TSTKTOP-TSTKSIZ*BY2PG)	/* byte just beyond user stack */
-#define	USTKSIZE	(16*1024*1024 - TSTKSIZ*BY2PG)	/* size of user stack */
-#define ROMBIOS		(KZERO|0xF0000)
-
-#define	MACHSIZE	4096
-
-#define isphys(x) (((ulong)x)&KZERO)
-
-/*
- *  known 80386 segments (in GDT) and their selectors
- */
-#define	NULLSEG	0	/* null segment */
-#define	KDSEG	1	/* kernel data/stack */
-#define	KESEG	2	/* kernel executable */	
-#define	UDSEG	3	/* user data/stack */
-#define	UESEG	4	/* user executable */
-#define TSSSEG	5	/* task segment */
-
-#define SELGDT	(0<<3)	/* selector is in gdt */
-#define	SELLDT	(1<<3)	/* selector is in ldt */
-
-#define SELECTOR(i, t, p)	(((i)<<3) | (t) | (p))
-
-#define NULLSEL	SELECTOR(NULLSEG, SELGDT, 0)
-#define KESEL	SELECTOR(KESEG, SELGDT, 0)
-#define KDSEL	SELECTOR(KDSEG, SELGDT, 0)
-#define UESEL	SELECTOR(UESEG, SELGDT, 3)
-#define UDSEL	SELECTOR(UDSEG, SELGDT, 3)
-#define TSSSEL	SELECTOR(TSSSEG, SELGDT, 0)
-
-/*
- *  fields in segment descriptors
- */
-#define SEGDATA	(0x10<<8)	/* data/stack segment */
-#define SEGEXEC	(0x18<<8)	/* executable segment */
-#define	SEGTSS	(0x9<<8)	/* TSS segment */
-#define SEGCG	(0x0C<<8)	/* call gate */
-#define	SEGIG	(0x0E<<8)	/* interrupt gate */
-#define SEGTG	(0x0F<<8)	/* task gate */
-#define SEGTYPE	(0x1F<<8)
-
-#define SEGP	(1<<15)		/* segment present */
-#define SEGPL(x) ((x)<<13)	/* priority level */
-#define SEGB	(1<<22)		/* granularity 1==4k (for expand-down) */
-#define SEGG	(1<<23)		/* granularity 1==4k (for other) */
-#define SEGE	(1<<10)		/* expand down */
-#define SEGW	(1<<9)		/* writable (for data/stack) */
-#define	SEGR	(1<<9)		/* readable (for code) */
-#define SEGD	(1<<22)		/* default 1==32bit (for code) */
-
-/*
- *  virtual MMU
- */
-#define PTEMAPMEM	(1024*1024)	/* ??? */	
-#define SEGMAPSIZE	16		/* ??? */
-#define	PTEPERTAB	(PTEMAPMEM/BY2PG)	/* ??? */
-#define PPN(x)		((x)&~(BY2PG-1))
-
-/*
- *  physical MMU
- */
-#define	PTEVALID	(1<<0)
-#define	PTEUNCACHED	0		/* everything is uncached */
-#define PTEWRITE	(1<<1)
-#define	PTERONLY	(0<<1)
-#define	PTEKERNEL	(0<<2)
-#define	PTEUSER		(1<<2)
-
-/*
- *  flag register bits that we care about
- */
-#define IFLAG	0x200
-
-#define OP16	BYTE	$0x66
-
-/*
- *	about to walk all over ms/dos - turn off interrupts
- */
-TEXT	origin(SB),$0
-
-	CLI
-
-#ifdef BOOT
-/*
- *	This part of l.s is used only in the boot kernel.
- *	It assumes that we are in real address mode, i.e.,
- *	that we look like an 8086.
- */
-/*
- *	relocate everything to a half meg and jump there
- *	- looks wierd because it is being assembled by a 32 bit
- *	  assembler for a 16 bit world
- */
-	MOVL	$0,BX
-	INCL	BX
-	SHLL	$15,BX
-	MOVL	BX,CX
-	MOVW	BX,ES
-	MOVL	$0,SI
-	MOVL	SI,DI
-	CLD; REP; MOVSL
-/*	JMPFAR	0X8000:$lowcore(SB) /**/
-	 BYTE	$0xEA
-	 WORD	$lowcore(SB)
-	 WORD	$0X8000
-
-TEXT	lowcore(SB),$0
-
-/*
- *	now that we're in low core, update the DS
- */
-
-	MOVW	BX,DS
-
-/*
- * 	goto protected mode
- */
-/*	MOVL	tgdtptr(SB),GDTR /**/
-	 BYTE	$0x0f
-	 BYTE	$0x01
-	 BYTE	$0x16
-	 WORD	$tgdtptr(SB)
-	MOVL	CR0,AX
-	ORL	$1,AX
-	MOVL	AX,CR0
-
-/*
- *	clear prefetch queue (wierd code to avoid optimizations)
- */
-	CLC
-	JCC	flush
-	MOVL	AX,AX
-flush:
-
-/*
- *	set all segs
- */
-/*	MOVW	$SELECTOR(1, SELGDT, 0),AX	/**/
-	 BYTE	$0xc7
-	 BYTE	$0xc0
-	 WORD	$SELECTOR(1, SELGDT, 0)
-	MOVW	AX,DS
-	MOVW	AX,SS
-	MOVW	AX,ES
-	MOVW	AX,FS
-	MOVW	AX,GS
-
-/*	JMPFAR	SELECTOR(2, SELGDT, 0):$mode32bit(SB) /**/
-	 BYTE	$0x66
-	 BYTE	$0xEA
-	 LONG	$mode32bit-KZERO(SB)
-	 WORD	$SELECTOR(2, SELGDT, 0)
-
-TEXT	mode32bit(SB),$0
-
-#endif BOOT
-
-	/*
-	 * Clear BSS
-	 */
-	LEAL	edata-KZERO(SB),SI
-	MOVL	SI,DI
-	ADDL	$4,DI
-	MOVL	$0,AX
-	MOVL	AX,(SI)
-	LEAL	end-KZERO(SB),CX
-	SUBL	DI,CX
-	SHRL	$2,CX
-	CLD; REP; MOVSL
-
-	/*
-	 *  make a bottom level page table page that maps the first
-	 *  16 meg of physical memory
-	 */
-	LEAL	tpt-KZERO(SB),AX	/* get phys addr of temporary page table */
-	ADDL	$(BY2PG-1),AX		/* must be page aligned */
-	ANDL	$(~(BY2PG-1)),AX	/* ... */
-	MOVL	$(4*1024),CX		/* pte's per page */
-	MOVL	$((((4*1024)-1)<<PGSHIFT)|PTEVALID|PTEKERNEL|PTEWRITE),BX
-setpte:
-	MOVL	BX,-4(AX)(CX*4)
-	SUBL	$(1<<PGSHIFT),BX
-	LOOP	setpte
-
-	/*
-	 *  make a top level page table page that maps the first
-	 *  16 meg of memory to 0 thru 16meg and to KZERO thru KZERO+16meg
-	 */
-	MOVL	AX,BX
-	ADDL	$(4*BY2PG),AX
-	ADDL	$(PTEVALID|PTEKERNEL|PTEWRITE),BX
-	MOVL	BX,0(AX)
-	MOVL	BX,((((KZERO>>1)&0x7FFFFFFF)>>(2*PGSHIFT-1-4))+0)(AX)
-	ADDL	$BY2PG,BX
-	MOVL	BX,4(AX)
-	MOVL	BX,((((KZERO>>1)&0x7FFFFFFF)>>(2*PGSHIFT-1-4))+4)(AX)
-	ADDL	$BY2PG,BX
-	MOVL	BX,8(AX)
-	MOVL	BX,((((KZERO>>1)&0x7FFFFFFF)>>(2*PGSHIFT-1-4))+8)(AX)
-	ADDL	$BY2PG,BX
-	MOVL	BX,12(AX)
-	MOVL	BX,((((KZERO>>1)&0x7FFFFFFF)>>(2*PGSHIFT-1-4))+12)(AX)
-
-	/*
-	 *  point processor to top level page & turn on paging
-	 */
-	MOVL	AX,CR3
-	MOVL	CR0,AX
-	ORL	$0X80000000,AX
-	ANDL	$~(0x8|0x2),AX	/* TS=0, MP=0 */
-	MOVL	AX,CR0
-
-	/*
-	 *  use a jump to an absolute location to get the PC into
-	 *  KZERO.
-	 */
-	LEAL	tokzero(SB),AX
-	JMP*	AX
-
-TEXT	tokzero(SB),$0
-
-	/*
-	 *  stack and mach
-	 */
-	MOVL	$mach0(SB),SP
-	MOVL	SP,m(SB)
-	MOVL	$0,0(SP)
-	ADDL	$(MACHSIZE-4),SP	/* start stack under machine struct */
-	MOVL	$0, u(SB)
-
-	/*
-	 *  clear flags
-	 */
-	MOVL	$0,AX
-	PUSHL	AX
-	POPFL
-
-	CALL	main(SB)
-
-loop:
-	JMP	loop
-
-GLOBL	mach0+0(SB), $MACHSIZE
-GLOBL	u(SB), $4
-GLOBL	m(SB), $4
-GLOBL	tpt(SB), $(BY2PG*6)
-
-/*
- *  gdt to get us to 32-bit/segmented/unpaged mode
- */
-TEXT	tgdt(SB),$0
-
-	/* null descriptor */
-	LONG	$0
-	LONG	$0
-
-	/* data segment descriptor for 4 gigabytes (PL 0) */
-	LONG	$(0xFFFF)
-	LONG	$(SEGG|SEGB|(0xF<<16)|SEGP|SEGPL(0)|SEGDATA|SEGW)
-
-	/* exec segment descriptor for 4 gigabytes (PL 0) */
-	LONG	$(0xFFFF)
-	LONG	$(SEGG|SEGD|(0xF<<16)|SEGP|SEGPL(0)|SEGEXEC|SEGR)
-
-/*
- *  pointer to initial gdt
- */
-TEXT	tgdtptr(SB),$0
-
-	WORD	$(3*8)
-	LONG	$tgdt-KZERO(SB)
-
-/*
- *  input a byte
- */
-TEXT	inb(SB),$0
-
-	MOVL	p+0(FP),DX
-	XORL	AX,AX
-	INB
-	RET
-
-/*
- *  output a byte
- */
-TEXT	outb(SB),$0
-
-	MOVL	p+0(FP),DX
-	MOVL	b+4(FP),AX
-	OUTB
-	RET
-
-/*
- *  input a string of shorts from a port
- */
-TEXT	inss(SB),$0
-	MOVL	p+0(FP),DX
-	MOVL	a+4(FP),DI
-	MOVL	c+8(FP),CX
-	CLD; REP; OP16; INSL
-	RET
-
-/*
- *  output a string of shorts to a port
- */
-TEXT	outss(SB),$0
-	MOVL	p+0(FP),DX
-	MOVL	a+4(FP),SI
-	MOVL	c+8(FP),CX
-	CLD; REP; OP16; OUTSL
-	RET
-
-/*
- *  test and set
- */
-TEXT	tas(SB),$0
-	MOVL	$0xdeadead,AX
-	MOVL	l+0(FP),BX
-	XCHGL	AX,(BX)
-	RET
-
-/*
- *  routines to load/read various system registers
- */
-GLOBL	idtptr(SB),$6
-TEXT	putidt(SB),$0		/* interrupt descriptor table */
-	MOVL	t+0(FP),AX
-	MOVL	AX,idtptr+2(SB)
-	MOVL	l+4(FP),AX
-	MOVW	AX,idtptr(SB)
-	MOVL	idtptr(SB),IDTR
-	RET
-
-GLOBL	gdtptr(SB),$6
-TEXT	putgdt(SB),$0		/* global descriptor table */
-	MOVL	t+0(FP),AX
-	MOVL	AX,gdtptr+2(SB)
-	MOVL	l+4(FP),AX
-	MOVW	AX,gdtptr(SB)
-	MOVL	gdtptr(SB),GDTR
-	RET
-
-TEXT	putcr3(SB),$0		/* top level page table pointer */
-	MOVL	t+0(FP),AX
-	MOVL	AX,CR3
-	RET
-
-TEXT	puttr(SB),$0		/* task register */
-	MOVL	t+0(FP),AX
-	MOVW	AX,TASK
-	RET
-
-TEXT	getcr0(SB),$0		/* coprocessor bits */
-	MOVL	CR0,AX
-	RET
-
-TEXT	getcr2(SB),$0		/* fault address */
-	MOVL	CR2,AX
-	RET
-
-#define	FPOFF\
-	WAIT;\
-	MOVL	CR0,AX;\
-	ORL	$0x4,AX		/* EM=1 */;\
-	MOVL	AX,CR0
-
-#define	FPON\
-	MOVL	CR0,AX;\
-	ANDL	$~0x4,AX	/* EM=0 */;\
-	MOVL	AX,CR0
-	
-TEXT	fpoff(SB),$0		/* turn off floating point */
-	FPOFF
-	RET
-
-TEXT	fpinit(SB),$0		/* turn on & init the floating point */
-	FPON
-	FINIT
-	WAIT
-	PUSHW	$0x0330
-	FLDCW	0(SP)		/* ignore underflow/precision, signal others */
-	POPW	AX
-	WAIT
-	RET
-
-TEXT	fpsave(SB),$0		/* save floating point state and turn off */
-	MOVL	p+0(FP),AX
-	WAIT
-	FSAVE	0(AX)
-	FPOFF
-	RET
-
-TEXT	fprestore(SB),$0	/* turn on floating point and restore regs */
-	FPON
-	MOVL	p+0(FP),AX
-	FRSTOR	0(AX)
-	WAIT
-	RET
-
-TEXT	fpstatus(SB),$0		/* get floating point status */
-	FSTSW	AX
-	RET
-
-/*
- *  special traps
- */
-TEXT	intr0(SB),$0
-	PUSHL	$0
-	PUSHL	$0
-	JMP	intrcommon
-TEXT	intr1(SB),$0
-	PUSHL	$0
-	PUSHL	$1
-	JMP	intrcommon
-TEXT	intr2(SB),$0
-	PUSHL	$0
-	PUSHL	$2
-	JMP	intrcommon
-TEXT	intr3(SB),$0
-	PUSHL	$0
-	PUSHL	$3
-	JMP	intrcommon
-TEXT	intr4(SB),$0
-	PUSHL	$0
-	PUSHL	$4
-	JMP	intrcommon
-TEXT	intr5(SB),$0
-	PUSHL	$0
-	PUSHL	$5
-	JMP	intrcommon
-TEXT	intr6(SB),$0
-	PUSHL	$0
-	PUSHL	$6
-	JMP	intrcommon
-TEXT	intr7(SB),$0
-	PUSHL	$0
-	PUSHL	$7
-	JMP	intrcommon
-TEXT	intr8(SB),$0
-	PUSHL	$8
-	JMP	intrscommon
-TEXT	intr9(SB),$0
-	PUSHL	$0
-	PUSHL	$9
-	JMP	intrcommon
-TEXT	intr10(SB),$0
-	PUSHL	$10
-	JMP	intrscommon
-TEXT	intr11(SB),$0
-	PUSHL	$11
-	JMP	intrscommon
-TEXT	intr12(SB),$0
-	PUSHL	$12
-	JMP	intrscommon
-TEXT	intr13(SB),$0
-	PUSHL	$13
-	JMP	intrscommon
-TEXT	intr14(SB),$0
-	PUSHL	$14
-	JMP	intrscommon
-TEXT	intr15(SB),$0
-	PUSHL	$0
-	PUSHL	$15
-	JMP	intrcommon
-TEXT	intr16(SB),$0
-	PUSHL	$0
-	PUSHL	$16
-	JMP	intrcommon
-TEXT	intr24(SB),$0
-	PUSHL	$0
-	PUSHL	$24
-	JMP	intrcommon
-TEXT	intr25(SB),$0
-	PUSHL	$0
-	PUSHL	$25
-	JMP	intrcommon
-TEXT	intr26(SB),$0
-	PUSHL	$0
-	PUSHL	$26
-	JMP	intrcommon
-TEXT	intr27(SB),$0
-	PUSHL	$0
-	PUSHL	$27
-	JMP	intrcommon
-TEXT	intr28(SB),$0
-	PUSHL	$0
-	PUSHL	$28
-	JMP	intrcommon
-TEXT	intr29(SB),$0
-	PUSHL	$0
-	PUSHL	$29
-	JMP	intrcommon
-TEXT	intr30(SB),$0
-	PUSHL	$0
-	PUSHL	$30
-	JMP	intrcommon
-TEXT	intr31(SB),$0
-	PUSHL	$0
-	PUSHL	$31
-	JMP	intrcommon
-TEXT	intr32(SB),$0
-	PUSHL	$0
-	PUSHL	$16
-	JMP	intrcommon
-TEXT	intr33(SB),$0
-	PUSHL	$0
-	PUSHL	$33
-	JMP	intrcommon
-TEXT	intr34(SB),$0
-	PUSHL	$0
-	PUSHL	$34
-	JMP	intrcommon
-TEXT	intr35(SB),$0
-	PUSHL	$0
-	PUSHL	$35
-	JMP	intrcommon
-TEXT	intr36(SB),$0
-	PUSHL	$0
-	PUSHL	$36
-	JMP	intrcommon
-TEXT	intr37(SB),$0
-	PUSHL	$0
-	PUSHL	$37
-	JMP	intrcommon
-TEXT	intr38(SB),$0
-	PUSHL	$0
-	PUSHL	$38
-	JMP	intrcommon
-TEXT	intr39(SB),$0
-	PUSHL	$0
-	PUSHL	$39
-	JMP	intrcommon
-TEXT	intr64(SB),$0
-	PUSHL	$0
-	PUSHL	$64
-	JMP	intrcommon
-TEXT	intrbad(SB),$0
-	PUSHL	$0
-	PUSHL	$0x1ff
-	JMP	intrcommon
-
-intrcommon:
-	PUSHL	DS
-	PUSHL	ES
-	PUSHL	FS
-	PUSHL	GS
-	PUSHAL
-	MOVL	$(KDSEL),AX
-	MOVW	AX,DS
-	MOVW	AX,ES
-	LEAL	0(SP),AX
-	PUSHL	AX
-	CALL	trap(SB)
-	POPL	AX
-	POPAL
-	POPL	GS
-	POPL	FS
-	POPL	ES
-	POPL	DS
-	ADDL	$8,SP	/* error code and trap type */
-	IRETL
-
-intrscommon:
-	PUSHL	DS
-	PUSHL	ES
-	PUSHL	FS
-	PUSHL	GS
-	PUSHAL
-	MOVL	$(KDSEL),AX
-	MOVW	AX,DS
-	MOVW	AX,ES
-	LEAL	0(SP),AX
-	PUSHL	AX
-	CALL	trap(SB)
-	POPL	AX
-	POPAL
-	POPL	GS
-	POPL	FS
-	POPL	ES
-	POPL	DS
-	ADDL	$8,SP	/* error code and trap type */
-	IRETL
-
-/*
- *  interrupt level is interrupts on or off
- */
-TEXT	spllo(SB),$0
-	PUSHFL
-	POPL	AX
-	STI
-	RET
-
-TEXT	splhi(SB),$0
-	PUSHFL
-	POPL	AX
-	CLI
-	RET
-
-TEXT	splx(SB),$0
-	MOVL	s+0(FP),AX
-	PUSHL	AX
-	POPFL
-	RET
-
-/*
- *  do nothing whatsoever till interrupt happens
- */
-TEXT	idle(SB),$0
-	HLT
-	RET
-
-/*
- *  label consists of a stack pointer and a PC
- */
-TEXT	gotolabel(SB),$0
-	MOVL	l+0(FP),AX
-	MOVL	0(AX),SP	/* restore sp */
-	MOVL	4(AX),AX	/* put return pc on the stack */
-	MOVL	AX,0(SP)
-	MOVL	$1,AX		/* return 1 */
-	RET
-
-TEXT	setlabel(SB),$0
-	MOVL	l+0(FP),AX
-	MOVL	SP,0(AX)	/* store sp */
-	MOVL	0(SP),BX	/* store return pc */
-	MOVL	BX,4(AX)
-	MOVL	$0,AX		/* return 0 */
-	RET
-
-/*
- *  Used to get to the first process.
- *  Set up an interrupt return frame and IRET to user level.
- */
-TEXT	touser(SB),$0
-	PUSHL	$(UDSEL)		/* old ss */
-	PUSHL	$(USTKTOP)		/* old sp */
-	PUSHFL				/* old flags */
-	PUSHL	$(UESEL)		/* old cs */
-	PUSHL	$(UTZERO+32)		/* old pc */
-	MOVL	$(UDSEL),AX
-	MOVW	AX,DS
-	MOVW	AX,ES
-	MOVW	AX,GS
-	MOVW	AX,FS
-	IRETL
-
-/*
- *  set configuration register
- */
-TEXT	config(SB),$0
-	MOVL	l+0(FP),AX
-	MOVL	$0x3F3,DX
-	OUTB
-	OUTB
-	RET

+ 0 - 963
sys/src/cmd/8a/lex.c

@@ -1,963 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <ctype.h>
-#define	EXTERN
-#include "a.h"
-#include "y.tab.h"
-
-void
-main(int argc, char *argv[])
-{
-	char *p;
-	int nout, nproc, status, i, c;
-
-	thechar = '8';
-	thestring = "386";
-	memset(debug, 0, sizeof(debug));
-	cinit();
-	outfile = 0;
-	include[ninclude++] = ".";
-	ARGBEGIN {
-	default:
-		c = ARGC();
-		if(c >= 0 || c < sizeof(debug))
-			debug[c] = 1;
-		break;
-
-	case 'o':
-		outfile = ARGF();
-		break;
-
-	case 'D':
-		p = ARGF();
-		if(p)
-			Dlist[nDlist++] = p;
-		break;
-
-	case 'I':
-		p = ARGF();
-		setinclude(p);
-		break;
-	} ARGEND
-	if(*argv == 0) {
-		print("usage: %ca [-options] file.s\n", thechar);
-		errorexit();
-	}
-	if(argc > 1 && systemtype(Windows)){
-		print("can't assemble multiple files on windows\n");
-		errorexit();
-	}
-	if(argc > 1 && !systemtype(Windows)) {
-		nproc = 1;
-		if(p = getenv("NPROC"))
-			nproc = atol(p);	/* */
-		c = 0;
-		nout = 0;
-		for(;;) {
-			while(nout < nproc && argc > 0) {
-				i = myfork();
-				if(i < 0) {
-					i = mywait(&status);
-					if(i < 0)
-						errorexit();
-					if(status)
-						c++;
-					nout--;
-					continue;
-				}
-				if(i == 0) {
-					print("%s:\n", *argv);
-					if(assemble(*argv))
-						errorexit();
-					exits(0);
-				}
-				nout++;
-				argc--;
-				argv++;
-			}
-			i = mywait(&status);
-			if(i < 0) {
-				if(c)
-					errorexit();
-				exits(0);
-			}
-			if(status)
-				c++;
-			nout--;
-		}
-	}
-	if(assemble(argv[0]))
-		errorexit();
-	exits(0);
-}
-
-int
-assemble(char *file)
-{
-	char ofile[100], incfile[20], *p;
-	int i, of;
-
-	strcpy(ofile, file);
-	p = utfrrune(ofile, pathchar());
-	if(p) {
-		include[0] = ofile;
-		*p++ = 0;
-	} else
-		p = ofile;
-	if(outfile == 0) {
-		outfile = p;
-		if(outfile){
-			p = utfrrune(outfile, '.');
-			if(p)
-				if(p[1] == 's' && p[2] == 0)
-					p[0] = 0;
-			p = utfrune(outfile, 0);
-			p[0] = '.';
-			p[1] = thechar;
-			p[2] = 0;
-		} else
-			outfile = "/dev/null";
-	}
-	p = getenv("INCLUDE");
-	if(p) {
-		setinclude(p);
-	} else {
-		if(systemtype(Plan9)) {
-			sprint(incfile,"/%s/include", thestring);
-			setinclude(strdup(incfile));
-		}
-	}
-
-	of = mycreat(outfile, 0664);
-	if(of < 0) {
-		yyerror("%ca: cannot create %s", thechar, outfile);
-		errorexit();
-	}
-	Binit(&obuf, of, OWRITE);
-
-	pass = 1;
-	pinit(file);
-	for(i=0; i<nDlist; i++)
-		dodefine(Dlist[i]);
-	yyparse();
-	if(nerrors) {
-		cclean();
-		return nerrors;
-	}
-
-	pass = 2;
-	outhist();
-	pinit(file);
-	for(i=0; i<nDlist; i++)
-		dodefine(Dlist[i]);
-	yyparse();
-	cclean();
-	return nerrors;
-}
-
-struct
-{
-	char	*name;
-	uint16_t	type;
-	uint16_t	value;
-} itab[] =
-{
-	"SP",		LSP,	D_AUTO,
-	"SB",		LSB,	D_EXTERN,
-	"FP",		LFP,	D_PARAM,
-	"PC",		LPC,	D_BRANCH,
-
-	"AL",		LBREG,	D_AL,
-	"CL",		LBREG,	D_CL,
-	"DL",		LBREG,	D_DL,
-	"BL",		LBREG,	D_BL,
-	"AH",		LBREG,	D_AH,
-	"CH",		LBREG,	D_CH,
-	"DH",		LBREG,	D_DH,
-	"BH",		LBREG,	D_BH,
-
-	"AX",		LLREG,	D_AX,
-	"CX",		LLREG,	D_CX,
-	"DX",		LLREG,	D_DX,
-	"BX",		LLREG,	D_BX,
-/*	"SP",		LLREG,	D_SP,	*/
-	"BP",		LLREG,	D_BP,
-	"SI",		LLREG,	D_SI,
-	"DI",		LLREG,	D_DI,
-
-	"F0",		LFREG,	D_F0+0,
-	"F1",		LFREG,	D_F0+1,
-	"F2",		LFREG,	D_F0+2,
-	"F3",		LFREG,	D_F0+3,
-	"F4",		LFREG,	D_F0+4,
-	"F5",		LFREG,	D_F0+5,
-	"F6",		LFREG,	D_F0+6,
-	"F7",		LFREG,	D_F0+7,
-
-	"CS",		LSREG,	D_CS,
-	"SS",		LSREG,	D_SS,
-	"DS",		LSREG,	D_DS,
-	"ES",		LSREG,	D_ES,
-	"FS",		LSREG,	D_FS,
-	"GS",		LSREG,	D_GS,
-
-	"GDTR",		LBREG,	D_GDTR,
-	"IDTR",		LBREG,	D_IDTR,
-	"LDTR",		LBREG,	D_LDTR,
-	"MSW",		LBREG,	D_MSW,
-	"TASK",		LBREG,	D_TASK,
-
-	"CR0",		LBREG,	D_CR+0,
-	"CR1",		LBREG,	D_CR+1,
-	"CR2",		LBREG,	D_CR+2,
-	"CR3",		LBREG,	D_CR+3,
-	"CR4",		LBREG,	D_CR+4,
-	"CR5",		LBREG,	D_CR+5,
-	"CR6",		LBREG,	D_CR+6,
-	"CR7",		LBREG,	D_CR+7,
-
-	"DR0",		LBREG,	D_DR+0,
-	"DR1",		LBREG,	D_DR+1,
-	"DR2",		LBREG,	D_DR+2,
-	"DR3",		LBREG,	D_DR+3,
-	"DR4",		LBREG,	D_DR+4,
-	"DR5",		LBREG,	D_DR+5,
-	"DR6",		LBREG,	D_DR+6,
-	"DR7",		LBREG,	D_DR+7,
-
-	"TR0",		LBREG,	D_TR+0,
-	"TR1",		LBREG,	D_TR+1,
-	"TR2",		LBREG,	D_TR+2,
-	"TR3",		LBREG,	D_TR+3,
-	"TR4",		LBREG,	D_TR+4,
-	"TR5",		LBREG,	D_TR+5,
-	"TR6",		LBREG,	D_TR+6,
-	"TR7",		LBREG,	D_TR+7,
-
-	"AAA",		LTYPE0,	AAAA,
-	"AAD",		LTYPE0,	AAAD,
-	"AAM",		LTYPE0,	AAAM,
-	"AAS",		LTYPE0,	AAAS,
-	"ADCB",		LTYPE3,	AADCB,
-	"ADCL",		LTYPE3,	AADCL,
-	"ADCW",		LTYPE3,	AADCW,
-	"ADDB",		LTYPE3,	AADDB,
-	"ADDL",		LTYPE3,	AADDL,
-	"ADDW",		LTYPE3,	AADDW,
-	"ADJSP",	LTYPE2,	AADJSP,
-	"ANDB",		LTYPE3,	AANDB,
-	"ANDL",		LTYPE3,	AANDL,
-	"ANDW",		LTYPE3,	AANDW,
-	"ARPL",		LTYPE3,	AARPL,
-	"BOUNDL",	LTYPE3,	ABOUNDL,
-	"BOUNDW",	LTYPE3,	ABOUNDW,
-	"BSFL",		LTYPE3,	ABSFL,
-	"BSFW",		LTYPE3,	ABSFW,
-	"BSRL",		LTYPE3,	ABSRL,
-	"BSRW",		LTYPE3,	ABSRW,
-	"BTCL",		LTYPE3,	ABTCL,
-	"BTCW",		LTYPE3,	ABTCW,
-	"BTL",		LTYPE3,	ABTL,
-	"BTRL",		LTYPE3,	ABTRL,
-	"BTRW",		LTYPE3,	ABTRW,
-	"BTSL",		LTYPE3,	ABTSL,
-	"BTSW",		LTYPE3,	ABTSW,
-	"BTW",		LTYPE3,	ABTW,
-	"BYTE",		LTYPE2,	ABYTE,
-	"CALL",		LTYPEC,	ACALL,
-	"CLC",		LTYPE0,	ACLC,
-	"CLD",		LTYPE0,	ACLD,
-	"CLI",		LTYPE0,	ACLI,
-	"CLTS",		LTYPE0,	ACLTS,
-	"CMC",		LTYPE0,	ACMC,
-	"CMPB",		LTYPE4,	ACMPB,
-	"CMPL",		LTYPE4,	ACMPL,
-	"CMPW",		LTYPE4,	ACMPW,
-	"CMPSB",	LTYPE0,	ACMPSB,
-	"CMPSL",	LTYPE0,	ACMPSL,
-	"CMPSW",	LTYPE0,	ACMPSW,
-	"CMPXCHGB",	LTYPE3,	ACMPXCHGB,
-	"CMPXCHGL",	LTYPE3,	ACMPXCHGL,
-	"CMPXCHGW",	LTYPE3,	ACMPXCHGW,
-	"DAA",		LTYPE0,	ADAA,
-	"DAS",		LTYPE0,	ADAS,
-	"DATA",		LTYPED,	ADATA,
-	"DECB",		LTYPE1,	ADECB,
-	"DECL",		LTYPE1,	ADECL,
-	"DECW",		LTYPE1,	ADECW,
-	"DIVB",		LTYPE2,	ADIVB,
-	"DIVL",		LTYPE2,	ADIVL,
-	"DIVW",		LTYPE2,	ADIVW,
-	"END",		LTYPE0,	AEND,
-	"ENTER",	LTYPE2,	AENTER,
-	"GLOBL",	LTYPEG,	AGLOBL,
-	"HLT",		LTYPE0,	AHLT,
-	"IDIVB",	LTYPE2,	AIDIVB,
-	"IDIVL",	LTYPE2,	AIDIVL,
-	"IDIVW",	LTYPE2,	AIDIVW,
-	"IMULB",	LTYPEI,	AIMULB,
-	"IMULL",	LTYPEI,	AIMULL,
-	"IMULW",	LTYPEI,	AIMULW,
-	"INB",		LTYPE0,	AINB,
-	"INL",		LTYPE0,	AINL,
-	"INW",		LTYPE0,	AINW,
-	"INCB",		LTYPE1,	AINCB,
-	"INCL",		LTYPE1,	AINCL,
-	"INCW",		LTYPE1,	AINCW,
-	"INSB",		LTYPE0,	AINSB,
-	"INSL",		LTYPE0,	AINSL,
-	"INSW",		LTYPE0,	AINSW,
-	"INT",		LTYPE2,	AINT,
-	"INTO",		LTYPE0,	AINTO,
-	"IRETL",	LTYPE0,	AIRETL,
-	"IRETW",	LTYPE0,	AIRETW,
-
-	"JOS",		LTYPER,	AJOS,
-	"JO",		LTYPER,	AJOS,	/* alternate */
-	"JOC",		LTYPER,	AJOC,
-	"JNO",		LTYPER,	AJOC,	/* alternate */
-	"JCS",		LTYPER,	AJCS,
-	"JB",		LTYPER,	AJCS,	/* alternate */
-	"JC",		LTYPER,	AJCS,	/* alternate */
-	"JNAE",		LTYPER,	AJCS,	/* alternate */
-	"JLO",		LTYPER,	AJCS,	/* alternate */
-	"JCC",		LTYPER,	AJCC,
-	"JAE",		LTYPER,	AJCC,	/* alternate */
-	"JNB",		LTYPER,	AJCC,	/* alternate */
-	"JNC",		LTYPER,	AJCC,	/* alternate */
-	"JHS",		LTYPER,	AJCC,	/* alternate */
-	"JEQ",		LTYPER,	AJEQ,
-	"JE",		LTYPER,	AJEQ,	/* alternate */
-	"JZ",		LTYPER,	AJEQ,	/* alternate */
-	"JNE",		LTYPER,	AJNE,
-	"JNZ",		LTYPER,	AJNE,	/* alternate */
-	"JLS",		LTYPER,	AJLS,
-	"JBE",		LTYPER,	AJLS,	/* alternate */
-	"JNA",		LTYPER,	AJLS,	/* alternate */
-	"JHI",		LTYPER,	AJHI,
-	"JA",		LTYPER,	AJHI,	/* alternate */
-	"JNBE",		LTYPER,	AJHI,	/* alternate */
-	"JMI",		LTYPER,	AJMI,
-	"JS",		LTYPER,	AJMI,	/* alternate */
-	"JPL",		LTYPER,	AJPL,
-	"JNS",		LTYPER,	AJPL,	/* alternate */
-	"JPS",		LTYPER,	AJPS,
-	"JP",		LTYPER,	AJPS,	/* alternate */
-	"JPE",		LTYPER,	AJPS,	/* alternate */
-	"JPC",		LTYPER,	AJPC,
-	"JNP",		LTYPER,	AJPC,	/* alternate */
-	"JPO",		LTYPER,	AJPC,	/* alternate */
-	"JLT",		LTYPER,	AJLT,
-	"JL",		LTYPER,	AJLT,	/* alternate */
-	"JNGE",		LTYPER,	AJLT,	/* alternate */
-	"JGE",		LTYPER,	AJGE,
-	"JNL",		LTYPER,	AJGE,	/* alternate */
-	"JLE",		LTYPER,	AJLE,
-	"JNG",		LTYPER,	AJLE,	/* alternate */
-	"JGT",		LTYPER,	AJGT,
-	"JG",		LTYPER,	AJGT,	/* alternate */
-	"JNLE",		LTYPER,	AJGT,	/* alternate */
-
-	"JCXZ",		LTYPER,	AJCXZ,
-	"JMP",		LTYPEC,	AJMP,
-	"LAHF",		LTYPE0,	ALAHF,
-	"LARL",		LTYPE3,	ALARL,
-	"LARW",		LTYPE3,	ALARW,
-	"LEAL",		LTYPE3,	ALEAL,
-	"LEAW",		LTYPE3,	ALEAW,
-	"LEAVEL",	LTYPE0,	ALEAVEL,
-	"LEAVEW",	LTYPE0,	ALEAVEW,
-	"LOCK",		LTYPE0,	ALOCK,
-	"LODSB",	LTYPE0,	ALODSB,
-	"LODSL",	LTYPE0,	ALODSL,
-	"LODSW",	LTYPE0,	ALODSW,
-	"LONG",		LTYPE2,	ALONG,
-	"LOOP",		LTYPER,	ALOOP,
-	"LOOPEQ",	LTYPER,	ALOOPEQ,
-	"LOOPNE",	LTYPER,	ALOOPNE,
-	"LSLL",		LTYPE3,	ALSLL,
-	"LSLW",		LTYPE3,	ALSLW,
-	"MOVB",		LTYPE3,	AMOVB,
-	"MOVL",		LTYPEM,	AMOVL,
-	"MOVW",		LTYPEM,	AMOVW,
-	"MOVBLSX",	LTYPE3, AMOVBLSX,
-	"MOVBLZX",	LTYPE3, AMOVBLZX,
-	"MOVBWSX",	LTYPE3, AMOVBWSX,
-	"MOVBWZX",	LTYPE3, AMOVBWZX,
-	"MOVWLSX",	LTYPE3, AMOVWLSX,
-	"MOVWLZX",	LTYPE3, AMOVWLZX,
-	"MOVSB",	LTYPE0,	AMOVSB,
-	"MOVSL",	LTYPE0,	AMOVSL,
-	"MOVSW",	LTYPE0,	AMOVSW,
-	"MULB",		LTYPE2,	AMULB,
-	"MULL",		LTYPE2,	AMULL,
-	"MULW",		LTYPE2,	AMULW,
-	"NEGB",		LTYPE1,	ANEGB,
-	"NEGL",		LTYPE1,	ANEGL,
-	"NEGW",		LTYPE1,	ANEGW,
-	"NOP",		LTYPEN,	ANOP,
-	"NOTB",		LTYPE1,	ANOTB,
-	"NOTL",		LTYPE1,	ANOTL,
-	"NOTW",		LTYPE1,	ANOTW,
-	"ORB",		LTYPE3,	AORB,
-	"ORL",		LTYPE3,	AORL,
-	"ORW",		LTYPE3,	AORW,
-	"OUTB",		LTYPE0,	AOUTB,
-	"OUTL",		LTYPE0,	AOUTL,
-	"OUTW",		LTYPE0,	AOUTW,
-	"OUTSB",	LTYPE0,	AOUTSB,
-	"OUTSL",	LTYPE0,	AOUTSL,
-	"OUTSW",	LTYPE0,	AOUTSW,
-	"POPAL",	LTYPE0,	APOPAL,
-	"POPAW",	LTYPE0,	APOPAW,
-	"POPFL",	LTYPE0,	APOPFL,
-	"POPFW",	LTYPE0,	APOPFW,
-	"POPL",		LTYPE1,	APOPL,
-	"POPW",		LTYPE1,	APOPW,
-	"PUSHAL",	LTYPE0,	APUSHAL,
-	"PUSHAW",	LTYPE0,	APUSHAW,
-	"PUSHFL",	LTYPE0,	APUSHFL,
-	"PUSHFW",	LTYPE0,	APUSHFW,
-	"PUSHL",	LTYPE2,	APUSHL,
-	"PUSHW",	LTYPE2,	APUSHW,
-	"RCLB",		LTYPE3,	ARCLB,
-	"RCLL",		LTYPE3,	ARCLL,
-	"RCLW",		LTYPE3,	ARCLW,
-	"RCRB",		LTYPE3,	ARCRB,
-	"RCRL",		LTYPE3,	ARCRL,
-	"RCRW",		LTYPE3,	ARCRW,
-	"REP",		LTYPE0,	AREP,
-	"REPN",		LTYPE0,	AREPN,
-	"RET",		LTYPE0,	ARET,
-	"ROLB",		LTYPE3,	AROLB,
-	"ROLL",		LTYPE3,	AROLL,
-	"ROLW",		LTYPE3,	AROLW,
-	"RORB",		LTYPE3,	ARORB,
-	"RORL",		LTYPE3,	ARORL,
-	"RORW",		LTYPE3,	ARORW,
-	"SAHF",		LTYPE0,	ASAHF,
-	"SALB",		LTYPE3,	ASALB,
-	"SALL",		LTYPE3,	ASALL,
-	"SALW",		LTYPE3,	ASALW,
-	"SARB",		LTYPE3,	ASARB,
-	"SARL",		LTYPE3,	ASARL,
-	"SARW",		LTYPE3,	ASARW,
-	"SBBB",		LTYPE3,	ASBBB,
-	"SBBL",		LTYPE3,	ASBBL,
-	"SBBW",		LTYPE3,	ASBBW,
-	"SCASB",	LTYPE0,	ASCASB,
-	"SCASL",	LTYPE0,	ASCASL,
-	"SCASW",	LTYPE0,	ASCASW,
-	"SETCC",	LTYPE1,	ASETCC,
-	"SETCS",	LTYPE1,	ASETCS,
-	"SETEQ",	LTYPE1,	ASETEQ,
-	"SETGE",	LTYPE1,	ASETGE,
-	"SETGT",	LTYPE1,	ASETGT,
-	"SETHI",	LTYPE1,	ASETHI,
-	"SETLE",	LTYPE1,	ASETLE,
-	"SETLS",	LTYPE1,	ASETLS,
-	"SETLT",	LTYPE1,	ASETLT,
-	"SETMI",	LTYPE1,	ASETMI,
-	"SETNE",	LTYPE1,	ASETNE,
-	"SETOC",	LTYPE1,	ASETOC,
-	"SETOS",	LTYPE1,	ASETOS,
-	"SETPC",	LTYPE1,	ASETPC,
-	"SETPL",	LTYPE1,	ASETPL,
-	"SETPS",	LTYPE1,	ASETPS,
-	"CDQ",		LTYPE0,	ACDQ,
-	"CWD",		LTYPE0,	ACWD,
-	"SHLB",		LTYPE3,	ASHLB,
-	"SHLL",		LTYPES,	ASHLL,
-	"SHLW",		LTYPES,	ASHLW,
-	"SHRB",		LTYPE3,	ASHRB,
-	"SHRL",		LTYPES,	ASHRL,
-	"SHRW",		LTYPES,	ASHRW,
-	"STC",		LTYPE0,	ASTC,
-	"STD",		LTYPE0,	ASTD,
-	"STI",		LTYPE0,	ASTI,
-	"STOSB",	LTYPE0,	ASTOSB,
-	"STOSL",	LTYPE0,	ASTOSL,
-	"STOSW",	LTYPE0,	ASTOSW,
-	"SUBB",		LTYPE3,	ASUBB,
-	"SUBL",		LTYPE3,	ASUBL,
-	"SUBW",		LTYPE3,	ASUBW,
-	"SYSCALL",	LTYPE0,	ASYSCALL,
-	"TESTB",	LTYPE3,	ATESTB,
-	"TESTL",	LTYPE3,	ATESTL,
-	"TESTW",	LTYPE3,	ATESTW,
-	"TEXT",		LTYPET,	ATEXT,
-	"VERR",		LTYPE2,	AVERR,
-	"VERW",		LTYPE2,	AVERW,
-	"WAIT",		LTYPE0,	AWAIT,
-	"WORD",		LTYPE2,	AWORD,
-	"XCHGB",	LTYPE3,	AXCHGB,
-	"XCHGL",	LTYPE3,	AXCHGL,
-	"XCHGW",	LTYPE3,	AXCHGW,
-	"XLAT",		LTYPE2,	AXLAT,
-	"XORB",		LTYPE3,	AXORB,
-	"XORL",		LTYPE3,	AXORL,
-	"XORW",		LTYPE3,	AXORW,
-
-	"CMOVLCC",	LTYPE3,	ACMOVLCC,
-	"CMOVLCS",	LTYPE3,	ACMOVLCS,
-	"CMOVLEQ",	LTYPE3,	ACMOVLEQ,
-	"CMOVLGE",	LTYPE3,	ACMOVLGE,
-	"CMOVLGT",	LTYPE3,	ACMOVLGT,
-	"CMOVLHI",	LTYPE3,	ACMOVLHI,
-	"CMOVLLE",	LTYPE3,	ACMOVLLE,
-	"CMOVLLS",	LTYPE3,	ACMOVLLS,
-	"CMOVLLT",	LTYPE3,	ACMOVLLT,
-	"CMOVLMI",	LTYPE3,	ACMOVLMI,
-	"CMOVLNE",	LTYPE3,	ACMOVLNE,
-	"CMOVLOC",	LTYPE3,	ACMOVLOC,
-	"CMOVLOS",	LTYPE3,	ACMOVLOS,
-	"CMOVLPC",	LTYPE3,	ACMOVLPC,
-	"CMOVLPL",	LTYPE3,	ACMOVLPL,
-	"CMOVLPS",	LTYPE3,	ACMOVLPS,
-	"CMOVWCC",	LTYPE3,	ACMOVWCC,
-	"CMOVWCS",	LTYPE3,	ACMOVWCS,
-	"CMOVWEQ",	LTYPE3,	ACMOVWEQ,
-	"CMOVWGE",	LTYPE3,	ACMOVWGE,
-	"CMOVWGT",	LTYPE3,	ACMOVWGT,
-	"CMOVWHI",	LTYPE3,	ACMOVWHI,
-	"CMOVWLE",	LTYPE3,	ACMOVWLE,
-	"CMOVWLS",	LTYPE3,	ACMOVWLS,
-	"CMOVWLT",	LTYPE3,	ACMOVWLT,
-	"CMOVWMI",	LTYPE3,	ACMOVWMI,
-	"CMOVWNE",	LTYPE3,	ACMOVWNE,
-	"CMOVWOC",	LTYPE3,	ACMOVWOC,
-	"CMOVWOS",	LTYPE3,	ACMOVWOS,
-	"CMOVWPC",	LTYPE3,	ACMOVWPC,
-	"CMOVWPL",	LTYPE3,	ACMOVWPL,
-	"CMOVWPS",	LTYPE3,	ACMOVWPS,
-
-	"FMOVB",	LTYPE3, AFMOVB,
-	"FMOVBP",	LTYPE3, AFMOVBP,
-	"FMOVD",	LTYPE3, AFMOVD,
-	"FMOVDP",	LTYPE3, AFMOVDP,
-	"FMOVF",	LTYPE3, AFMOVF,
-	"FMOVFP",	LTYPE3, AFMOVFP,
-	"FMOVL",	LTYPE3, AFMOVL,
-	"FMOVLP",	LTYPE3, AFMOVLP,
-	"FMOVV",	LTYPE3, AFMOVV,
-	"FMOVVP",	LTYPE3, AFMOVVP,
-	"FMOVW",	LTYPE3, AFMOVW,
-	"FMOVWP",	LTYPE3, AFMOVWP,
-	"FMOVX",	LTYPE3, AFMOVX,
-	"FMOVXP",	LTYPE3, AFMOVXP,
-	"FCMOVCC",	LTYPE3, AFCMOVCC,
-	"FCMOVCS",	LTYPE3, AFCMOVCS,
-	"FCMOVEQ",	LTYPE3, AFCMOVEQ,
-	"FCMOVHI",	LTYPE3, AFCMOVHI,
-	"FCMOVLS",	LTYPE3, AFCMOVLS,
-	"FCMOVNE",	LTYPE3, AFCMOVNE,
-	"FCMOVNU",	LTYPE3, AFCMOVNU,
-	"FCMOVUN",	LTYPE3, AFCMOVUN,
-	"FCOMB",	LTYPE3, AFCOMB,
-	"FCOMBP",	LTYPE3, AFCOMBP,
-	"FCOMD",	LTYPE3, AFCOMD,
-	"FCOMDP",	LTYPE3, AFCOMDP,
-	"FCOMDPP",	LTYPE3, AFCOMDPP,
-	"FCOMF",	LTYPE3, AFCOMF,
-	"FCOMFP",	LTYPE3, AFCOMFP,
-	"FCOMI",	LTYPE3, AFCOMI,
-	"FCOMIP",	LTYPE3, AFCOMIP,
-	"FCOML",	LTYPE3, AFCOML,
-	"FCOMLP",	LTYPE3, AFCOMLP,
-	"FCOMW",	LTYPE3, AFCOMW,
-	"FCOMWP",	LTYPE3, AFCOMWP,
-	"FUCOM",	LTYPE3, AFUCOM,
-	"FUCOMI",	LTYPE3, AFUCOMI,
-	"FUCOMIP",	LTYPE3, AFUCOMIP,
-	"FUCOMP",	LTYPE3, AFUCOMP,
-	"FUCOMPP",	LTYPE3, AFUCOMPP,
-	"FADDW",	LTYPE3, AFADDW,
-	"FADDL",	LTYPE3, AFADDL,
-	"FADDF",	LTYPE3, AFADDF,
-	"FADDD",	LTYPE3, AFADDD,
-	"FADDDP",	LTYPE3, AFADDDP,
-	"FSUBDP",	LTYPE3, AFSUBDP,
-	"FSUBW",	LTYPE3, AFSUBW,
-	"FSUBL",	LTYPE3, AFSUBL,
-	"FSUBF",	LTYPE3, AFSUBF,
-	"FSUBD",	LTYPE3, AFSUBD,
-	"FSUBRDP",	LTYPE3, AFSUBRDP,
-	"FSUBRW",	LTYPE3, AFSUBRW,
-	"FSUBRL",	LTYPE3, AFSUBRL,
-	"FSUBRF",	LTYPE3, AFSUBRF,
-	"FSUBRD",	LTYPE3, AFSUBRD,
-	"FMULDP",	LTYPE3, AFMULDP,
-	"FMULW",	LTYPE3, AFMULW,
-	"FMULL",	LTYPE3, AFMULL,
-	"FMULF",	LTYPE3, AFMULF,
-	"FMULD",	LTYPE3, AFMULD,
-	"FDIVDP",	LTYPE3, AFDIVDP,
-	"FDIVW",	LTYPE3, AFDIVW,
-	"FDIVL",	LTYPE3, AFDIVL,
-	"FDIVF",	LTYPE3, AFDIVF,
-	"FDIVD",	LTYPE3, AFDIVD,
-	"FDIVRDP",	LTYPE3, AFDIVRDP,
-	"FDIVRW",	LTYPE3, AFDIVRW,
-	"FDIVRL",	LTYPE3, AFDIVRL,
-	"FDIVRF",	LTYPE3, AFDIVRF,
-	"FDIVRD",	LTYPE3, AFDIVRD,
-	"FXCHD",	LTYPE3, AFXCHD,
-	"FFREE",	LTYPE1, AFFREE,
-	"FLDCW",	LTYPE2, AFLDCW,
-	"FLDENV",	LTYPE1, AFLDENV,
-	"FRSTOR",	LTYPE2, AFRSTOR,
-	"FSAVE",	LTYPE1, AFSAVE,
-	"FSTCW",	LTYPE1, AFSTCW,
-	"FSTENV",	LTYPE1, AFSTENV,
-	"FSTSW",	LTYPE1, AFSTSW,
-	"F2XM1",	LTYPE0, AF2XM1,
-	"FABS",		LTYPE0, AFABS,
-	"FCHS",		LTYPE0, AFCHS,
-	"FCLEX",	LTYPE0, AFCLEX,
-	"FCOS",		LTYPE0, AFCOS,
-	"FDECSTP",	LTYPE0, AFDECSTP,
-	"FINCSTP",	LTYPE0, AFINCSTP,
-	"FINIT",	LTYPE0, AFINIT,
-	"FLD1",		LTYPE0, AFLD1,
-	"FLDL2E",	LTYPE0, AFLDL2E,
-	"FLDL2T",	LTYPE0, AFLDL2T,
-	"FLDLG2",	LTYPE0, AFLDLG2,
-	"FLDLN2",	LTYPE0, AFLDLN2,
-	"FLDPI",	LTYPE0, AFLDPI,
-	"FLDZ",		LTYPE0, AFLDZ,
-	"FNOP",		LTYPE0, AFNOP,
-	"FPATAN",	LTYPE0, AFPATAN,
-	"FPREM",	LTYPE0, AFPREM,
-	"FPREM1",	LTYPE0, AFPREM1,
-	"FPTAN",	LTYPE0, AFPTAN,
-	"FRNDINT",	LTYPE0, AFRNDINT,
-	"FSCALE",	LTYPE0, AFSCALE,
-	"FSIN",		LTYPE0, AFSIN,
-	"FSINCOS",	LTYPE0, AFSINCOS,
-	"FSQRT",	LTYPE0, AFSQRT,
-	"FTST",		LTYPE0, AFTST,
-	"FXAM",		LTYPE0, AFXAM,
-	"FXTRACT",	LTYPE0, AFXTRACT,
-	"FYL2X",	LTYPE0, AFYL2X,
-	"FYL2XP1",	LTYPE0, AFYL2XP1,
-
-	0
-};
-
-void
-cinit(void)
-{
-	Sym *s;
-	int i;
-
-	nullgen.sym = S;
-	nullgen.offset = 0;
-	if(FPCHIP)
-		nullgen.dval = 0;
-	for(i=0; i<sizeof(nullgen.sval); i++)
-		nullgen.sval[i] = 0;
-	nullgen.type = D_NONE;
-	nullgen.index = D_NONE;
-	nullgen.scale = 0;
-
-	nerrors = 0;
-	iostack = I;
-	iofree = I;
-	peekc = IGN;
-	nhunk = 0;
-	for(i=0; i<NHASH; i++)
-		hash[i] = S;
-	for(i=0; itab[i].name; i++) {
-		s = slookup(itab[i].name);
-		if(s->type != LNAME)
-			yyerror("double initialization %s", itab[i].name);
-		s->type = itab[i].type;
-		s->value = itab[i].value;
-	}
-
-	pathname = allocn(pathname, 0, 100);
-	if(mygetwd(pathname, 99) == 0) {
-		pathname = allocn(pathname, 100, 900);
-		if(mygetwd(pathname, 999) == 0)
-			strcpy(pathname, "/???");
-	}
-}
-
-void
-checkscale(int scale)
-{
-
-	switch(scale) {
-	case 1:
-	case 2:
-	case 4:
-	case 8:
-		return;
-	}
-	yyerror("scale must be 1248: %d", scale);
-}
-
-void
-syminit(Sym *s)
-{
-
-	s->type = LNAME;
-	s->value = 0;
-}
-
-void
-cclean(void)
-{
-	Gen2 g2;
-
-	g2.from = nullgen;
-	g2.to = nullgen;
-	outcode(AEND, &g2);
-	Bflush(&obuf);
-}
-
-void
-zname(char *n, int t, int s)
-{
-
-	Bputc(&obuf, ANAME);		/* as(2) */
-	Bputc(&obuf, ANAME>>8);
-	Bputc(&obuf, t);		/* type */
-	Bputc(&obuf, s);		/* sym */
-	while(*n) {
-		Bputc(&obuf, *n);
-		n++;
-	}
-	Bputc(&obuf, 0);
-}
-
-void
-zaddr(Gen *a, int s)
-{
-	int32_t l;
-	int i, t;
-	char *n;
-	Ieee e;
-
-	t = 0;
-	if(a->index != D_NONE || a->scale != 0)
-		t |= T_INDEX;
-	if(a->offset != 0)
-		t |= T_OFFSET;
-	if(s != 0)
-		t |= T_SYM;
-
-	switch(a->type) {
-	default:
-		t |= T_TYPE;
-		break;
-	case D_FCONST:
-		t |= T_FCONST;
-		break;
-	case D_CONST2:
-		t |= T_OFFSET|T_OFFSET2;
-		break;
-	case D_SCONST:
-		t |= T_SCONST;
-		break;
-	case D_NONE:
-		break;
-	}
-	Bputc(&obuf, t);
-
-	if(t & T_INDEX) {	/* implies index, scale */
-		Bputc(&obuf, a->index);
-		Bputc(&obuf, a->scale);
-	}
-	if(t & T_OFFSET) {	/* implies offset */
-		l = a->offset;
-		Bputc(&obuf, l);
-		Bputc(&obuf, l>>8);
-		Bputc(&obuf, l>>16);
-		Bputc(&obuf, l>>24);
-	}
-	if(t & T_OFFSET2) {
-		l = a->offset2;
-		Bputc(&obuf, l);
-		Bputc(&obuf, l>>8);
-		Bputc(&obuf, l>>16);
-		Bputc(&obuf, l>>24);
-	}
-	if(t & T_SYM)		/* implies sym */
-		Bputc(&obuf, s);
-	if(t & T_FCONST) {
-		ieeedtod(&e, a->dval);
-		l = e.l;
-		Bputc(&obuf, l);
-		Bputc(&obuf, l>>8);
-		Bputc(&obuf, l>>16);
-		Bputc(&obuf, l>>24);
-		l = e.h;
-		Bputc(&obuf, l);
-		Bputc(&obuf, l>>8);
-		Bputc(&obuf, l>>16);
-		Bputc(&obuf, l>>24);
-		return;
-	}
-	if(t & T_SCONST) {
-		n = a->sval;
-		for(i=0; i<NSNAME; i++) {
-			Bputc(&obuf, *n);
-			n++;
-		}
-		return;
-	}
-	if(t & T_TYPE)
-		Bputc(&obuf, a->type);
-}
-
-void
-outcode(int a, Gen2 *g2)
-{
-	int sf, st, t;
-	Sym *s;
-
-	if(pass == 1)
-		goto out;
-
-jackpot:
-	sf = 0;
-	s = g2->from.sym;
-	while(s != S) {
-		sf = s->sym;
-		if(sf < 0 || sf >= NSYM)
-			sf = 0;
-		t = g2->from.type;
-		if(t == D_ADDR)
-			t = g2->from.index;
-		if(h[sf].type == t)
-		if(h[sf].sym == s)
-			break;
-		zname(s->name, t, sym);
-		s->sym = sym;
-		h[sym].sym = s;
-		h[sym].type = t;
-		sf = sym;
-		sym++;
-		if(sym >= NSYM)
-			sym = 1;
-		break;
-	}
-	st = 0;
-	s = g2->to.sym;
-	while(s != S) {
-		st = s->sym;
-		if(st < 0 || st >= NSYM)
-			st = 0;
-		t = g2->to.type;
-		if(t == D_ADDR)
-			t = g2->to.index;
-		if(h[st].type == t)
-		if(h[st].sym == s)
-			break;
-		zname(s->name, t, sym);
-		s->sym = sym;
-		h[sym].sym = s;
-		h[sym].type = t;
-		st = sym;
-		sym++;
-		if(sym >= NSYM)
-			sym = 1;
-		if(st == sf)
-			goto jackpot;
-		break;
-	}
-	Bputc(&obuf, a);
-	Bputc(&obuf, a>>8);
-	Bputc(&obuf, lineno);
-	Bputc(&obuf, lineno>>8);
-	Bputc(&obuf, lineno>>16);
-	Bputc(&obuf, lineno>>24);
-	zaddr(&g2->from, sf);
-	zaddr(&g2->to, st);
-
-out:
-	if(a != AGLOBL && a != ADATA)
-		pc++;
-}
-
-void
-outhist(void)
-{
-	Gen g;
-	Hist *h;
-	char *p, *q, *op, c;
-	int n;
-
-	g = nullgen;
-	c = pathchar();
-	for(h = hist; h != H; h = h->link) {
-		p = h->name;
-		op = 0;
-		/* on windows skip drive specifier in pathname */
-		if(systemtype(Windows) && p && p[1] == ':'){
-			p += 2;
-			c = *p;
-		}
-		if(p && p[0] != c && h->offset == 0 && pathname){
-			/* on windows skip drive specifier in pathname */
-			if(systemtype(Windows) && pathname[1] == ':') {
-				op = p;
-				p = pathname+2;
-				c = *p;
-			} else if(pathname[0] == c){
-				op = p;
-				p = pathname;
-			}
-		}
-		while(p) {
-			q = strchr(p, c);
-			if(q) {
-				n = q-p;
-				if(n == 0){
-					n = 1;	/* leading "/" */
-					*p = '/';	/* don't emit "\" on windows */
-				}
-				q++;
-			} else {
-				n = strlen(p);
-				q = 0;
-			}
-			if(n) {
-				Bputc(&obuf, ANAME);
-				Bputc(&obuf, ANAME>>8);
-				Bputc(&obuf, D_FILE);	/* type */
-				Bputc(&obuf, 1);	/* sym */
-				Bputc(&obuf, '<');
-				Bwrite(&obuf, p, n);
-				Bputc(&obuf, 0);
-			}
-			p = q;
-			if(p == 0 && op) {
-				p = op;
-				op = 0;
-			}
-		}
-		g.offset = h->offset;
-
-		Bputc(&obuf, AHISTORY);
-		Bputc(&obuf, AHISTORY>>8);
-		Bputc(&obuf, h->line);
-		Bputc(&obuf, h->line>>8);
-		Bputc(&obuf, h->line>>16);
-		Bputc(&obuf, h->line>>24);
-		zaddr(&nullgen, 0);
-		zaddr(&g, 0);
-	}
-}
-
-#include "../cc/lexbody"
-#include "../cc/macbody"
-#include "../cc/compat"

+ 0 - 26
sys/src/cmd/8a/mkfile

@@ -1,26 +0,0 @@
-</$objtype/mkfile
-
-TARG=8a
-OFILES=\
-	y.tab.$O\
-	lex.$O\
-
-HFILES=\
-	../8c/8.out.h\
-	y.tab.h\
-	a.h\
-
-YFILES=a.y\
-
-BIN=/$objtype/bin
-UPDATE=\
-	mkfile\
-	a.y\
-	lex.c\
-	a.h\
-	${TARG:%=/386/bin/%}\
-
-< /sys/src/cmd/mkone
-YFLAGS=-D1 -d
-
-lex.$O:	../cc/macbody ../cc/lexbody ../cc/compat

+ 0 - 514
sys/src/cmd/8c/8.out.h

@@ -1,514 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#define	NSYM	50
-#define	NSNAME	8
-#define NOPROF	(1<<0)
-#define DUPOK	(1<<1)
-#define NOSPLIT	(1<<2)
-
-enum	as
-{
-	AXXX,
-	AAAA,
-	AAAD,
-	AAAM,
-	AAAS,
-	AADCB,
-	AADCL,
-	AADCW,
-	AADDB,
-	AADDL,
-	AADDW,
-	AADJSP,
-	AANDB,
-	AANDL,
-	AANDW,
-	AARPL,
-	ABOUNDL,
-	ABOUNDW,
-	ABSFL,
-	ABSFW,
-	ABSRL,
-	ABSRW,
-	ABTL,
-	ABTW,
-	ABTCL,
-	ABTCW,
-	ABTRL,
-	ABTRW,
-	ABTSL,
-	ABTSW,
-	ABYTE,
-	ACALL,
-	ACLC,
-	ACLD,
-	ACLI,
-	ACLTS,
-	ACMC,
-	ACMPB,
-	ACMPL,
-	ACMPW,
-	ACMPSB,
-	ACMPSL,
-	ACMPSW,
-	ADAA,
-	ADAS,
-	ADATA,
-	ADECB,
-	ADECL,
-	ADECW,
-	ADIVB,
-	ADIVL,
-	ADIVW,
-	AENTER,
-	AGLOBL,
-	AGOK,
-	AHISTORY,
-	AHLT,
-	AIDIVB,
-	AIDIVL,
-	AIDIVW,
-	AIMULB,
-	AIMULL,
-	AIMULW,
-	AINB,
-	AINL,
-	AINW,
-	AINCB,
-	AINCL,
-	AINCW,
-	AINSB,
-	AINSL,
-	AINSW,
-	AINT,
-	AINTO,
-	AIRETL,
-	AIRETW,
-	AJCC,
-	AJCS,
-	AJCXZ,
-	AJEQ,
-	AJGE,
-	AJGT,
-	AJHI,
-	AJLE,
-	AJLS,
-	AJLT,
-	AJMI,
-	AJMP,
-	AJNE,
-	AJOC,
-	AJOS,
-	AJPC,
-	AJPL,
-	AJPS,
-	ALAHF,
-	ALARL,
-	ALARW,
-	ALEAL,
-	ALEAW,
-	ALEAVEL,
-	ALEAVEW,
-	ALOCK,
-	ALODSB,
-	ALODSL,
-	ALODSW,
-	ALONG,
-	ALOOP,
-	ALOOPEQ,
-	ALOOPNE,
-	ALSLL,
-	ALSLW,
-	AMOVB,
-	AMOVL,
-	AMOVW,
-	AMOVBLSX,
-	AMOVBLZX,
-	AMOVBWSX,
-	AMOVBWZX,
-	AMOVWLSX,
-	AMOVWLZX,
-	AMOVSB,
-	AMOVSL,
-	AMOVSW,
-	AMULB,
-	AMULL,
-	AMULW,
-	ANAME,
-	ANEGB,
-	ANEGL,
-	ANEGW,
-	ANOP,
-	ANOTB,
-	ANOTL,
-	ANOTW,
-	AORB,
-	AORL,
-	AORW,
-	AOUTB,
-	AOUTL,
-	AOUTW,
-	AOUTSB,
-	AOUTSL,
-	AOUTSW,
-	APOPAL,
-	APOPAW,
-	APOPFL,
-	APOPFW,
-	APOPL,
-	APOPW,
-	APUSHAL,
-	APUSHAW,
-	APUSHFL,
-	APUSHFW,
-	APUSHL,
-	APUSHW,
-	ARCLB,
-	ARCLL,
-	ARCLW,
-	ARCRB,
-	ARCRL,
-	ARCRW,
-	AREP,
-	AREPN,
-	ARET,
-	AROLB,
-	AROLL,
-	AROLW,
-	ARORB,
-	ARORL,
-	ARORW,
-	ASAHF,
-	ASALB,
-	ASALL,
-	ASALW,
-	ASARB,
-	ASARL,
-	ASARW,
-	ASBBB,
-	ASBBL,
-	ASBBW,
-	ASCASB,
-	ASCASL,
-	ASCASW,
-	ASETCC,
-	ASETCS,
-	ASETEQ,
-	ASETGE,
-	ASETGT,
-	ASETHI,
-	ASETLE,
-	ASETLS,
-	ASETLT,
-	ASETMI,
-	ASETNE,
-	ASETOC,
-	ASETOS,
-	ASETPC,
-	ASETPL,
-	ASETPS,
-	ACDQ,
-	ACWD,
-	ASHLB,
-	ASHLL,
-	ASHLW,
-	ASHRB,
-	ASHRL,
-	ASHRW,
-	ASTC,
-	ASTD,
-	ASTI,
-	ASTOSB,
-	ASTOSL,
-	ASTOSW,
-	ASUBB,
-	ASUBL,
-	ASUBW,
-	ASYSCALL,
-	ATESTB,
-	ATESTL,
-	ATESTW,
-	ATEXT,
-	AVERR,
-	AVERW,
-	AWAIT,
-	AWORD,
-	AXCHGB,
-	AXCHGL,
-	AXCHGW,
-	AXLAT,
-	AXORB,
-	AXORL,
-	AXORW,
-
-	AFMOVB,
-	AFMOVBP,
-	AFMOVD,
-	AFMOVDP,
-	AFMOVF,
-	AFMOVFP,
-	AFMOVL,
-	AFMOVLP,
-	AFMOVV,
-	AFMOVVP,
-	AFMOVW,
-	AFMOVWP,
-	AFMOVX,
-	AFMOVXP,
-
-	AFCOMB,
-	AFCOMBP,
-	AFCOMD,
-	AFCOMDP,
-	AFCOMDPP,
-	AFCOMF,
-	AFCOMFP,
-	AFCOML,
-	AFCOMLP,
-	AFCOMW,
-	AFCOMWP,
-	AFUCOM,
-	AFUCOMP,
-	AFUCOMPP,
-
-	AFADDDP,
-	AFADDW,
-	AFADDL,
-	AFADDF,
-	AFADDD,
-
-	AFMULDP,
-	AFMULW,
-	AFMULL,
-	AFMULF,
-	AFMULD,
-
-	AFSUBDP,
-	AFSUBW,
-	AFSUBL,
-	AFSUBF,
-	AFSUBD,
-
-	AFSUBRDP,
-	AFSUBRW,
-	AFSUBRL,
-	AFSUBRF,
-	AFSUBRD,
-
-	AFDIVDP,
-	AFDIVW,
-	AFDIVL,
-	AFDIVF,
-	AFDIVD,
-
-	AFDIVRDP,
-	AFDIVRW,
-	AFDIVRL,
-	AFDIVRF,
-	AFDIVRD,
-
-	AFXCHD,
-	AFFREE,
-
-	AFLDCW,
-	AFLDENV,
-	AFRSTOR,
-	AFSAVE,
-	AFSTCW,
-	AFSTENV,
-	AFSTSW,
-
-	AF2XM1,
-	AFABS,
-	AFCHS,
-	AFCLEX,
-	AFCOS,
-	AFDECSTP,
-	AFINCSTP,
-	AFINIT,
-	AFLD1,
-	AFLDL2E,
-	AFLDL2T,
-	AFLDLG2,
-	AFLDLN2,
-	AFLDPI,
-	AFLDZ,
-	AFNOP,
-	AFPATAN,
-	AFPREM,
-	AFPREM1,
-	AFPTAN,
-	AFRNDINT,
-	AFSCALE,
-	AFSIN,
-	AFSINCOS,
-	AFSQRT,
-	AFTST,
-	AFXAM,
-	AFXTRACT,
-	AFYL2X,
-	AFYL2XP1,
-
-	AEND,
-
-	ADYNT,
-	AINIT,
-
-	ASIGNAME,
-
-	AFCOMI,
-	AFCOMIP,
-	AFUCOMI,
-	AFUCOMIP,
-	ACMPXCHGB,
-	ACMPXCHGL,
-	ACMPXCHGW,
-
-	/* conditional move */
-	ACMOVLCC,
-	ACMOVLCS,
-	ACMOVLEQ,
-	ACMOVLGE,
-	ACMOVLGT,
-	ACMOVLHI,
-	ACMOVLLE,
-	ACMOVLLS,
-	ACMOVLLT,
-	ACMOVLMI,
-	ACMOVLNE,
-	ACMOVLOC,
-	ACMOVLOS,
-	ACMOVLPC,
-	ACMOVLPL,
-	ACMOVLPS,
-	ACMOVWCC,
-	ACMOVWCS,
-	ACMOVWEQ,
-	ACMOVWGE,
-	ACMOVWGT,
-	ACMOVWHI,
-	ACMOVWLE,
-	ACMOVWLS,
-	ACMOVWLT,
-	ACMOVWMI,
-	ACMOVWNE,
-	ACMOVWOC,
-	ACMOVWOS,
-	ACMOVWPC,
-	ACMOVWPL,
-	ACMOVWPS,
-
-	AFCMOVCC,
-	AFCMOVCS,
-	AFCMOVEQ,
-	AFCMOVHI,
-	AFCMOVLS,
-	AFCMOVNE,
-	AFCMOVNU,
-	AFCMOVUN,
-
-	/* add new operations here. nowhere else. here. */
-	ALAST
-};
-
-enum
-{
-	D_AL		= 0,
-	D_CL,
-	D_DL,
-	D_BL,
-
-	D_AH		= 4,
-	D_CH,
-	D_DH,
-	D_BH,
-
-	D_AX		= 8,
-	D_CX,
-	D_DX,
-	D_BX,
-	D_SP,
-	D_BP,
-	D_SI,
-	D_DI,
-
-	D_F0		= 16,
-	D_F7		= D_F0 + 7,
-
-	D_CS		= 24,
-	D_SS,
-	D_DS,
-	D_ES,
-	D_FS,
-	D_GS,
-
-	D_GDTR,		/* global descriptor table register */
-	D_IDTR,		/* interrupt descriptor table register */
-	D_LDTR,		/* local descriptor table register */
-	D_MSW,		/* machine status word */
-	D_TASK,		/* task register */
-
-	D_CR		= 35,
-	D_DR		= 43,
-	D_TR		= 51,
-
-	D_NONE		= 59,
-
-	D_BRANCH	= 60,
-	D_EXTERN	= 61,
-	D_STATIC	= 62,
-	D_AUTO		= 63,
-	D_PARAM		= 64,
-	D_CONST		= 65,
-	D_FCONST	= 66,
-	D_SCONST	= 67,
-	D_ADDR		= 68,
-
-	D_FILE,
-	D_FILE1,
-
-	D_INDIR,	/* additive */
-
-	D_CONST2 = D_INDIR+D_INDIR,
-
-	D_SIZE,	/* 8l internal */
-
-	T_TYPE		= 1<<0,
-	T_INDEX		= 1<<1,
-	T_OFFSET	= 1<<2,
-	T_FCONST	= 1<<3,
-	T_SYM		= 1<<4,
-	T_SCONST	= 1<<5,
-	T_OFFSET2	= 1<<6,
-	T_GOTYPE	= 1<<7,
-
-	REGARG		= -1,
-	REGRET		= D_AX,
-	FREGRET		= D_F0,
-	REGSP		= D_SP,
-	REGTMP		= D_DI,
-};
-
-/*
- * this is the ranlib header
- */
-#define	SYMDEF	"__.SYMDEF"
-
-/*
- * this is the simulated IEEE floating point
- */
-typedef	struct	ieee	Ieee;
-struct	ieee
-{
-	long	l;	/* contains ls-man	0xffffffff */
-	long	h;	/* contains sign	0x80000000
-				    exp		0x7ff00000
-				    ms-man	0x000fffff */
-};

+ 0 - 1861
sys/src/cmd/8c/cgen.c

@@ -1,1861 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "gc.h"
-
-/* ,x/^(print|prtree)\(/i/\/\/ */
-
-void
-cgen(Node *n, Node *nn)
-{
-	Node *l, *r, *t;
-	Prog *p1;
-	Node nod, nod1, nod2, nod3, nod4;
-	int o, hardleft;
-	int32_t v, curs;
-	int64_t c;
-
-	if(debug['g']) {
-		prtree(nn, "cgen lhs");
-		prtree(n, "cgen");
-	}
-	if(n == Z || n->type == T)
-		return;
-	if(typesuv[n->type->etype]) {
-		sugen(n, nn, n->type->width);
-		return;
-	}
-	l = n->left;
-	r = n->right;
-	o = n->op;
-// Go's version does the following, but it's the wrong place: doesn't allow assignment
-//	if(o == OEXREG || nn != Z && nn->op == OEXREG) {
-//		gmove(n, nn);
-//		return;
-//	}
-
-	if(n->addable >= INDEXED) {
-		if(nn == Z) {
-			switch(o) {
-			default:
-				nullwarn(Z, Z);
-				break;
-			case OINDEX:
-				nullwarn(l, r);
-				break;
-			}
-			return;
-		}
-		gmove(n, nn);
-		return;
-	}
-	curs = cursafe;
-
-	if(l->complex >= FNX)
-	if(r != Z && r->complex >= FNX)
-	switch(o) {
-	default:
-		if(cond(o) && typesuv[l->type->etype])
-			break;
-
-		regret(&nod, r);
-		cgen(r, &nod);
-
-		regsalloc(&nod1, r);
-		gmove(&nod, &nod1);
-
-		regfree(&nod);
-		nod = *n;
-		nod.right = &nod1;
-
-		cgen(&nod, nn);
-		return;
-
-	case OFUNC:
-	case OCOMMA:
-	case OANDAND:
-	case OOROR:
-	case OCOND:
-	case ODOT:
-		break;
-	}
-
-	hardleft = l->addable < INDEXED || l->complex >= FNX;
-	switch(o) {
-	default:
-		diag(n, "unknown op in cgen: %O", o);
-		break;
-
-	case ONEG:
-	case OCOM:
-		if(nn == Z) {
-			nullwarn(l, Z);
-			break;
-		}
-		regalloc(&nod, l, nn);
-		cgen(l, &nod);
-		gopcode(o, n->type, Z, &nod);
-		gmove(&nod, nn);
-		regfree(&nod);
-		break;
-
-	case OAS:
-		if(typefd[n->type->etype]) {
-			cgen(r, &fregnode0);
-			if(nn != Z)
-				gins(AFMOVD, &fregnode0, &fregnode0);
-			if(l->addable < INDEXED) {
-				reglcgen(&nod, l, Z);
-				gmove(&fregnode0, &nod);
-				regfree(&nod);
-			} else
-				gmove(&fregnode0, l);
-			if(nn != Z)
-				gmove(&fregnode0, nn);
-			return;
-		}
-		if(l->op == OBIT)
-			goto bitas;
-		if(!hardleft) {
-			if(nn != Z || r->addable < INDEXED) {
-				if(r->complex >= FNX && nn == Z)
-					regret(&nod, r);
-				else
-					regalloc(&nod, r, nn);
-				cgen(r, &nod);
-				gmove(&nod, l);
-				if(nn != Z)
-					gmove(&nod, nn);
-				regfree(&nod);
-			} else
-				gmove(r, l);
-			break;
-		}
-		if(l->complex >= r->complex) {
-			if(l->op == OINDEX && r->op == OCONST) {
-				gmove(r, l);
-				break;
-			}
-			reglcgen(&nod1, l, Z);
-			if(r->addable >= INDEXED) {
-				gmove(r, &nod1);
-				if(nn != Z)
-					gmove(r, nn);
-				regfree(&nod1);
-				break;
-			}
-			regalloc(&nod, r, nn);
-			cgen(r, &nod);
-		} else {
-			regalloc(&nod, r, nn);
-			cgen(r, &nod);
-			reglcgen(&nod1, l, Z);
-		}
-		gmove(&nod, &nod1);
-		regfree(&nod);
-		regfree(&nod1);
-		break;
-
-	bitas:
-		n = l->left;
-		regalloc(&nod, r, nn);
-		if(l->complex >= r->complex) {
-			reglcgen(&nod1, n, Z);
-			cgen(r, &nod);
-		} else {
-			cgen(r, &nod);
-			reglcgen(&nod1, n, Z);
-		}
-		regalloc(&nod2, n, Z);
-		gmove(&nod1, &nod2);
-		bitstore(l, &nod, &nod1, &nod2, nn);
-		break;
-
-	case OBIT:
-		if(nn == Z) {
-			nullwarn(l, Z);
-			break;
-		}
-		bitload(n, &nod, Z, Z, nn);
-		gmove(&nod, nn);
-		regfree(&nod);
-		break;
-
-	case OLSHR:
-	case OASHL:
-	case OASHR:
-		if(nn == Z) {
-			nullwarn(l, r);
-			break;
-		}
-		if(r->op == OCONST) {
-			if(r->vconst == 0) {
-				cgen(l, nn);
-				break;
-			}
-			regalloc(&nod, l, nn);
-			cgen(l, &nod);
-			if(o == OASHL && r->vconst == 1)
-				gopcode(OADD, n->type, &nod, &nod);
-			else
-				gopcode(o, n->type, r, &nod);
-			gmove(&nod, nn);
-			regfree(&nod);
-			break;
-		}
-
-		/*
-		 * get nod to be D_CX
-		 */
-		if(nodreg(&nod, nn, D_CX)) {
-			regsalloc(&nod1, n);
-			gmove(&nod, &nod1);
-			cgen(n, &nod);		/* probably a bug */
-			gmove(&nod, nn);
-			gmove(&nod1, &nod);
-			break;
-		}
-		reg[D_CX]++;
-		if(nn->op == OREGISTER && nn->reg == D_CX)
-			regalloc(&nod1, l, Z);
-		else
-			regalloc(&nod1, l, nn);
-		if(r->complex >= l->complex) {
-			cgen(r, &nod);
-			cgen(l, &nod1);
-		} else {
-			cgen(l, &nod1);
-			cgen(r, &nod);
-		}
-		gopcode(o, n->type, &nod, &nod1);
-		gmove(&nod1, nn);
-		regfree(&nod);
-		regfree(&nod1);
-		break;
-
-	case OADD:
-	case OSUB:
-	case OOR:
-	case OXOR:
-	case OAND:
-		if(nn == Z) {
-			nullwarn(l, r);
-			break;
-		}
-		if(typefd[n->type->etype])
-			goto fop;
-		if(r->op == OCONST) {
-			if(r->vconst == 0 && o != OAND) {
-				cgen(l, nn);
-				break;
-			}
-		}
-		if(n->op == OADD && l->op == OASHL && l->right->op == OCONST
-		&& (r->op != OCONST || r->vconst < -128 || r->vconst > 127)) {
-			c = l->right->vconst;
-			if(c > 0 && c <= 3 && nareg(1) >= 4) {
-				if(l->left->complex >= r->complex) {
-					regalloc(&nod, l->left, nn);
-					cgen(l->left, &nod);
-					if(r->addable < INDEXED) {
-						regalloc(&nod1, r, Z);
-						cgen(r, &nod1);
-						genmuladd(&nod, &nod, 1 << c, &nod1);
-						regfree(&nod1);
-					}
-					else
-						genmuladd(&nod, &nod, 1 << c, r);
-				}
-				else {
-					regalloc(&nod, r, nn);
-					cgen(r, &nod);
-					regalloc(&nod1, l->left, Z);
-					cgen(l->left, &nod1);
-					genmuladd(&nod, &nod1, 1 << c, &nod);
-					regfree(&nod1);
-				}
-				gmove(&nod, nn);
-				regfree(&nod);
-				break;
-			}
-		}
-		if(r->addable >= INDEXED) {
-			regalloc(&nod, l, nn);
-			cgen(l, &nod);
-			gopcode(o, n->type, r, &nod);
-			gmove(&nod, nn);
-			regfree(&nod);
-			break;
-		}
-		if(l->complex >= r->complex) {
-			regalloc(&nod, l, nn);
-			cgen(l, &nod);
-			regalloc(&nod1, r, Z);
-			cgen(r, &nod1);
-			gopcode(o, n->type, &nod1, &nod);
-		} else {
-			regalloc(&nod1, r, nn);
-			cgen(r, &nod1);
-			regalloc(&nod, l, Z);
-			cgen(l, &nod);
-			gopcode(o, n->type, &nod1, &nod);
-		}
-		gmove(&nod, nn);
-		regfree(&nod);
-		regfree(&nod1);
-		break;
-
-	case OLMOD:
-	case OMOD:
-	case OLMUL:
-	case OLDIV:
-	case OMUL:
-	case ODIV:
-		if(nn == Z) {
-			nullwarn(l, r);
-			break;
-		}
-		if(typefd[n->type->etype])
-			goto fop;
-		if(r->op == OCONST) {
-			SET(v);
-			switch(o) {
-			case ODIV:
-			case OMOD:
-				c = r->vconst;
-				if(c < 0)
-					c = -c;
-				v = log2(c);
-				if(v < 0)
-					break;
-				/* fall thru */
-			case OMUL:
-			case OLMUL:
-				regalloc(&nod, l, nn);
-				cgen(l, &nod);
-				switch(o) {
-				case OMUL:
-				case OLMUL:
-					mulgen(n->type, r, &nod);
-					break;
-				case ODIV:
-					sdiv2(r->vconst, v, l, &nod);
-					break;
-				case OMOD:
-					smod2(r->vconst, v, l, &nod);
-					break;
-				}
-				gmove(&nod, nn);
-				regfree(&nod);
-				goto done;
-			case OLDIV:
-				c = r->vconst;
-				if((c & 0x80000000) == 0)
-					break;
-				regalloc(&nod1, l, Z);
-				cgen(l, &nod1);
-				regalloc(&nod, l, nn);
-				zeroregm(&nod);
-				gins(ACMPL, &nod1, nodconst(c));
-				gins(ASBBL, nodconst(-1), &nod);
-				regfree(&nod1);
-				gmove(&nod, nn);
-				regfree(&nod);
-				goto done;
-			}
-		}
-
-		if(o == OMUL) {
-			if(l->addable >= INDEXED) {
-				t = l;
-				l = r;
-				r = t;
-				goto imula;
-			}
-			else if(r->addable >= INDEXED) {
-			imula:
-/* should favour AX */
-				regalloc(&nod, l, nn);
-				cgen(l, &nod);
-				gopcode(OMUL, n->type, r, &nod);
-			}
-			else {
-/* should favour AX */
-				regalloc(&nod, l, nn);
-				cgen(l, &nod);
-				regalloc(&nod1, r, Z);
-				cgen(r, &nod1);
-				gopcode(OMUL, n->type, &nod1, &nod);
-				regfree(&nod1);
-			}
-			gmove(&nod, nn);
-			regfree(&nod);
-			goto done;
-		}
-
-		/*
-		 * get nod to be D_AX
-		 * get nod1 to be D_DX
-		 */
-		if(nodreg(&nod, nn, D_AX)) {
-			regsalloc(&nod2, n);
-			gmove(&nod, &nod2);
-			v = reg[D_AX];
-			reg[D_AX] = 0;
-
-			if(isreg(l, D_AX)) {
-				nod3 = *n;
-				nod3.left = &nod2;
-				cgen(&nod3, nn);
-			} else
-			if(isreg(r, D_AX)) {
-				nod3 = *n;
-				nod3.right = &nod2;
-				cgen(&nod3, nn);
-			} else
-				cgen(n, nn);
-
-			gmove(&nod2, &nod);
-			reg[D_AX] = v;
-			break;
-		}
-		if(nodreg(&nod1, nn, D_DX)) {
-			regsalloc(&nod2, n);
-			gmove(&nod1, &nod2);
-			v = reg[D_DX];
-			reg[D_DX] = 0;
-
-			if(isreg(l, D_DX)) {
-				nod3 = *n;
-				nod3.left = &nod2;
-				cgen(&nod3, nn);
-			} else
-			if(isreg(r, D_DX)) {
-				nod3 = *n;
-				nod3.right = &nod2;
-				cgen(&nod3, nn);
-			} else
-				cgen(n, nn);
-
-			gmove(&nod2, &nod1);
-			reg[D_DX] = v;
-			break;
-		}
-		reg[D_AX]++;
-
-		if(r->op == OCONST) {
-			switch(o) {
-			case ODIV:
-				reg[D_DX]++;
-				if(l->addable < INDEXED) {
-					regalloc(&nod2, l, Z);
-					cgen(l, &nod2);
-					l = &nod2;
-				}
-				sdivgen(l, r, &nod, &nod1);
-				gmove(&nod1, nn);
-				if(l == &nod2)
-					regfree(l);
-				goto freeaxdx;
-			case OLDIV:
-				reg[D_DX]++;
-				if(l->addable < INDEXED) {
-					regalloc(&nod2, l, Z);
-					cgen(l, &nod2);
-					l = &nod2;
-				}
-				udivgen(l, r, &nod, &nod1);
-				gmove(&nod1, nn);
-				if(l == &nod2)
-					regfree(l);
-				goto freeaxdx;
-			}
-		}
-
-		if(l->complex >= r->complex) {
-			cgen(l, &nod);
-			reg[D_DX]++;
-			if(o == ODIV || o == OMOD)
-				gins(ACDQ, Z, Z);
-			if(o == OLDIV || o == OLMOD)
-				zeroregm(&nod1);
-			if(r->addable < INDEXED || r->op == OCONST) {
-				regsalloc(&nod3, r);
-				cgen(r, &nod3);
-				gopcode(o, n->type, &nod3, Z);
-			} else
-				gopcode(o, n->type, r, Z);
-		} else {
-			regsalloc(&nod3, r);
-			cgen(r, &nod3);
-			cgen(l, &nod);
-			reg[D_DX]++;
-			if(o == ODIV || o == OMOD)
-				gins(ACDQ, Z, Z);
-			if(o == OLDIV || o == OLMOD)
-				zeroregm(&nod1);
-			gopcode(o, n->type, &nod3, Z);
-		}
-		if(o == OMOD || o == OLMOD)
-			gmove(&nod1, nn);
-		else
-			gmove(&nod, nn);
-	freeaxdx:
-		regfree(&nod);
-		regfree(&nod1);
-		break;
-
-	case OASLSHR:
-	case OASASHL:
-	case OASASHR:
-		if(r->op == OCONST)
-			goto asand;
-		if(l->op == OBIT)
-			goto asbitop;
-		if(typefd[n->type->etype])
-			goto asfop;
-
-		/*
-		 * get nod to be D_CX
-		 */
-		if(nodreg(&nod, nn, D_CX)) {
-			regsalloc(&nod1, n);
-			gmove(&nod, &nod1);
-			cgen(n, &nod);
-			if(nn != Z)
-				gmove(&nod, nn);
-			gmove(&nod1, &nod);
-			break;
-		}
-		reg[D_CX]++;
-
-		if(r->complex >= l->complex) {
-			cgen(r, &nod);
-			if(hardleft)
-				reglcgen(&nod1, l, Z);
-			else
-				nod1 = *l;
-		} else {
-			if(hardleft)
-				reglcgen(&nod1, l, Z);
-			else
-				nod1 = *l;
-			cgen(r, &nod);
-		}
-
-		gopcode(o, l->type, &nod, &nod1);
-		regfree(&nod);
-		if(nn != Z)
-			gmove(&nod1, nn);
-		if(hardleft)
-			regfree(&nod1);
-		break;
-
-	case OASAND:
-	case OASADD:
-	case OASSUB:
-	case OASXOR:
-	case OASOR:
-	asand:
-		if(l->op == OBIT)
-			goto asbitop;
-		if(typefd[n->type->etype]||typefd[r->type->etype])
-			goto asfop;
-		if(l->complex >= r->complex) {
-			if(hardleft)
-				reglcgen(&nod, l, Z);
-			else
-				nod = *l;
-			if(r->op != OCONST) {
-				regalloc(&nod1, r, nn);
-				cgen(r, &nod1);
-				gopcode(o, l->type, &nod1, &nod);
-				regfree(&nod1);
-			} else
-				gopcode(o, l->type, r, &nod);
-		} else {
-			regalloc(&nod1, r, nn);
-			cgen(r, &nod1);
-			if(hardleft)
-				reglcgen(&nod, l, Z);
-			else
-				nod = *l;
-			gopcode(o, l->type, &nod1, &nod);
-			regfree(&nod1);
-		}
-		if(nn != Z)
-			gmove(&nod, nn);
-		if(hardleft)
-			regfree(&nod);
-		break;
-
-	case OASLMUL:
-	case OASLDIV:
-	case OASLMOD:
-	case OASMUL:
-	case OASDIV:
-	case OASMOD:
-		if(l->op == OBIT)
-			goto asbitop;
-		if(typefd[n->type->etype]||typefd[r->type->etype])
-			goto asfop;
-		if(r->op == OCONST) {
-			SET(v);
-			switch(o) {
-			case OASDIV:
-			case OASMOD:
-				c = r->vconst;
-				if(c < 0)
-					c = -c;
-				v = log2(c);
-				if(v < 0)
-					break;
-				/* fall thru */
-			case OASMUL:
-			case OASLMUL:
-				if(hardleft)
-					reglcgen(&nod2, l, Z);
-				else
-					nod2 = *l;
-				regalloc(&nod, l, nn);
-				cgen(&nod2, &nod);
-				switch(o) {
-				case OASMUL:
-				case OASLMUL:
-					mulgen(n->type, r, &nod);
-					break;
-				case OASDIV:
-					sdiv2(r->vconst, v, l, &nod);
-					break;
-				case OASMOD:
-					smod2(r->vconst, v, l, &nod);
-					break;
-				}
-			havev:
-				gmove(&nod, &nod2);
-				if(nn != Z)
-					gmove(&nod, nn);
-				if(hardleft)
-					regfree(&nod2);
-				regfree(&nod);
-				goto done;
-			case OASLDIV:
-				c = r->vconst;
-				if((c & 0x80000000) == 0)
-					break;
-				if(hardleft)
-					reglcgen(&nod2, l, Z);
-				else
-					nod2 = *l;
-				regalloc(&nod1, l, nn);
-				cgen(&nod2, &nod1);
-				regalloc(&nod, l, nn);
-				zeroregm(&nod);
-				gins(ACMPL, &nod1, nodconst(c));
-				gins(ASBBL, nodconst(-1), &nod);
-				regfree(&nod1);
-				goto havev;
-			}
-		}
-
-		if(o == OASMUL) {
-/* should favour AX */
-			regalloc(&nod, l, nn);
-			if(r->complex >= FNX) {
-				regalloc(&nod1, r, Z);
-				cgen(r, &nod1);
-				r = &nod1;
-			}
-			if(hardleft)
-				reglcgen(&nod2, l, Z);
-			else
-				nod2 = *l;
-			cgen(&nod2, &nod);
-			if(r->addable < INDEXED) {
-				if(r->complex < FNX) {
-					regalloc(&nod1, r, Z);
-					cgen(r, &nod1);
-				}
-				gopcode(OASMUL, n->type, &nod1, &nod);
-				regfree(&nod1);
-			}
-			else
-				gopcode(OASMUL, n->type, r, &nod);
-			if(r == &nod1)
-				regfree(r);
-			gmove(&nod, &nod2);
-			if(nn != Z)
-				gmove(&nod, nn);
-			regfree(&nod);
-			if(hardleft)
-				regfree(&nod2);
-			goto done;
-		}
-
-		/*
-		 * get nod to be D_AX
-		 * get nod1 to be D_DX
-		 */
-		if(nodreg(&nod, nn, D_AX)) {
-			regsalloc(&nod2, n);
-			gmove(&nod, &nod2);
-			v = reg[D_AX];
-			reg[D_AX] = 0;
-
-			if(isreg(l, D_AX)) {
-				nod3 = *n;
-				nod3.left = &nod2;
-				cgen(&nod3, nn);
-			} else
-			if(isreg(r, D_AX)) {
-				nod3 = *n;
-				nod3.right = &nod2;
-				cgen(&nod3, nn);
-			} else
-				cgen(n, nn);
-
-			gmove(&nod2, &nod);
-			reg[D_AX] = v;
-			break;
-		}
-		if(nodreg(&nod1, nn, D_DX)) {
-			regsalloc(&nod2, n);
-			gmove(&nod1, &nod2);
-			v = reg[D_DX];
-			reg[D_DX] = 0;
-
-			if(isreg(l, D_DX)) {
-				nod3 = *n;
-				nod3.left = &nod2;
-				cgen(&nod3, nn);
-			} else
-			if(isreg(r, D_DX)) {
-				nod3 = *n;
-				nod3.right = &nod2;
-				cgen(&nod3, nn);
-			} else
-				cgen(n, nn);
-
-			gmove(&nod2, &nod1);
-			reg[D_DX] = v;
-			break;
-		}
-		reg[D_AX]++;
-		reg[D_DX]++;
-
-		if(l->complex >= r->complex) {
-			if(hardleft)
-				reglcgen(&nod2, l, Z);
-			else
-				nod2 = *l;
-			cgen(&nod2, &nod);
-			if(r->op == OCONST) {
-				switch(o) {
-				case OASDIV:
-					sdivgen(&nod2, r, &nod, &nod1);
-					goto divdone;
-				case OASLDIV:
-					udivgen(&nod2, r, &nod, &nod1);
-				divdone:
-					gmove(&nod1, &nod2);
-					if(nn != Z)
-						gmove(&nod1, nn);
-					goto freelxaxdx;
-				}
-			}
-			if(o == OASDIV || o == OASMOD)
-				gins(ACDQ, Z, Z);
-			if(o == OASLDIV || o == OASLMOD)
-				zeroregm(&nod1);
-			if(r->addable < INDEXED || r->op == OCONST ||
-			   !typeil[r->type->etype]) {
-				regalloc(&nod3, r, Z);
-				cgen(r, &nod3);
-				gopcode(o, l->type, &nod3, Z);
-				regfree(&nod3);
-			} else
-				gopcode(o, n->type, r, Z);
-		} else {
-			regalloc(&nod3, r, Z);
-			cgen(r, &nod3);
-			if(hardleft)
-				reglcgen(&nod2, l, Z);
-			else
-				nod2 = *l;
-			cgen(&nod2, &nod);
-			if(o == OASDIV || o == OASMOD)
-				gins(ACDQ, Z, Z);
-			if(o == OASLDIV || o == OASLMOD)
-				zeroregm(&nod1);
-			gopcode(o, l->type, &nod3, Z);
-			regfree(&nod3);
-		}
-		if(o == OASMOD || o == OASLMOD) {
-			gmove(&nod1, &nod2);
-			if(nn != Z)
-				gmove(&nod1, nn);
-		} else {
-			gmove(&nod, &nod2);
-			if(nn != Z)
-				gmove(&nod, nn);
-		}
-	freelxaxdx:
-		if(hardleft)
-			regfree(&nod2);
-		regfree(&nod);
-		regfree(&nod1);
-		break;
-
-	fop:
-		if(l->complex >= r->complex) {
-			cgen(l, &fregnode0);
-			if(r->addable < INDEXED) {
-				cgen(r, &fregnode0);
-				fgopcode(o, &fregnode0, &fregnode1, 1, 0);
-			} else
-				fgopcode(o, r, &fregnode0, 0, 0);
-		} else {
-			cgen(r, &fregnode0);
-			if(l->addable < INDEXED) {
-				cgen(l, &fregnode0);
-				fgopcode(o, &fregnode0, &fregnode1, 1, 1);
-			} else
-				fgopcode(o, l, &fregnode0, 0, 1);
-		}
-		gmove(&fregnode0, nn);
-		break;
-
-	asfop:
-		if(l->complex >= r->complex) {
-			if(hardleft)
-				reglcgen(&nod, l, Z);
-			else
-				nod = *l;
-			cgen(r, &fregnode0);
-		} else {
-			cgen(r, &fregnode0);
-			if(hardleft)
-				reglcgen(&nod, l, Z);
-			else
-				nod = *l;
-		}
-		if(!typefd[l->type->etype]) {
-			gmove(&nod, &fregnode0);
-			fgopcode(o, &fregnode0, &fregnode1, 1, 1);
-		} else
-			fgopcode(o, &nod, &fregnode0, 0, 1);
-		if(nn != Z)
-			gins(AFMOVD, &fregnode0, &fregnode0);
-		gmove(&fregnode0, &nod);
-		if(nn != Z)
-			gmove(&fregnode0, nn);
-		if(hardleft)
-			regfree(&nod);
-		break;
-
-	asbitop:
-		regalloc(&nod4, n, nn);
-		if(l->complex >= r->complex) {
-			bitload(l, &nod, &nod1, &nod2, &nod4);
-			regalloc(&nod3, r, Z);
-			cgen(r, &nod3);
-		} else {
-			regalloc(&nod3, r, Z);
-			cgen(r, &nod3);
-			bitload(l, &nod, &nod1, &nod2, &nod4);
-		}
-		gmove(&nod, &nod4);
-
-		if(typefd[nod3.type->etype])
-			fgopcode(o, &fregnode0, &fregnode1, 1, 1);
-		else {
-			Node onod;
-
-			/* incredible grot ... */
-			onod = nod3;
-			onod.op = o;
-			onod.complex = 2;
-			onod.addable = 0;
-			onod.type = tfield;
-			onod.left = &nod4;
-			onod.right = &nod3;
-			cgen(&onod, Z);
-		}
-		regfree(&nod3);
-		gmove(&nod4, &nod);
-		regfree(&nod4);
-		bitstore(l, &nod, &nod1, &nod2, nn);
-		break;
-
-	case OADDR:
-		if(nn == Z) {
-			nullwarn(l, Z);
-			break;
-		}
-		lcgen(l, nn);
-		break;
-
-	case OFUNC:
-		l = uncomma(l);
-		if(l->complex >= FNX) {
-			if(l->op != OIND)
-				diag(n, "bad function call");
-
-			regret(&nod, l->left);
-			cgen(l->left, &nod);
-			regsalloc(&nod1, l->left);
-			gmove(&nod, &nod1);
-			regfree(&nod);
-
-			nod = *n;
-			nod.left = &nod2;
-			nod2 = *l;
-			nod2.left = &nod1;
-			nod2.complex = 1;
-			cgen(&nod, nn);
-
-			return;
-		}
-		gargs(r, &nod, &nod1);
-		if(l->addable < INDEXED) {
-			reglcgen(&nod, l, nn);
-			nod.op = OREGISTER;
-			gopcode(OFUNC, n->type, Z, &nod);
-			regfree(&nod);
-		} else
-			gopcode(OFUNC, n->type, Z, l);
-		if(REGARG>=0 && reg[REGARG])
-			reg[REGARG]--;
-		if(nn != Z) {
-			regret(&nod, n);
-			gmove(&nod, nn);
-			regfree(&nod);
-		} else
-		if(typefd[n->type->etype])
-			gins(AFMOVDP, &fregnode0, &fregnode0);
-		break;
-
-	case OIND:
-		if(nn == Z) {
-			nullwarn(l, Z);
-			break;
-		}
-		regialloc(&nod, n, nn);
-		r = l;
-		while(r->op == OADD)
-			r = r->right;
-		if(sconst(r)) {
-			v = r->vconst;
-			r->vconst = 0;
-			cgen(l, &nod);
-			nod.xoffset += v;
-			r->vconst = v;
-		} else
-			cgen(l, &nod);
-		regind(&nod, n);
-		gmove(&nod, nn);
-		regfree(&nod);
-		break;
-
-	case OEQ:
-	case ONE:
-	case OLE:
-	case OLT:
-	case OGE:
-	case OGT:
-	case OLO:
-	case OLS:
-	case OHI:
-	case OHS:
-		if(nn == Z) {
-			nullwarn(l, r);
-			break;
-		}
-		boolgen(n, 1, nn);
-		break;
-
-	case OANDAND:
-	case OOROR:
-		boolgen(n, 1, nn);
-		if(nn == Z)
-			patch(p, pc);
-		break;
-
-	case ONOT:
-		if(nn == Z) {
-			nullwarn(l, Z);
-			break;
-		}
-		boolgen(n, 1, nn);
-		break;
-
-	case OCOMMA:
-		cgen(l, Z);
-		cgen(r, nn);
-		break;
-
-	case OCAST:
-		if(nn == Z) {
-			nullwarn(l, Z);
-			break;
-		}
-		/*
-		 * convert from types l->n->nn
-		 */
-		if(nocast(l->type, n->type) && nocast(n->type, nn->type)) {
-			/* both null, gen l->nn */
-			cgen(l, nn);
-			break;
-		}
-		if(typev[l->type->etype]) {
-			cgen64(n, nn);
-			break;
-		}
-		regalloc(&nod, l, nn);
-		cgen(l, &nod);
-		regalloc(&nod1, n, &nod);
-		gmove(&nod, &nod1);
-		gmove(&nod1, nn);
-		regfree(&nod1);
-		regfree(&nod);
-		break;
-
-	case ODOT:
-		sugen(l, nodrat, l->type->width);
-		if(nn == Z)
-			break;
-		warn(n, "non-interruptable temporary");
-		nod = *nodrat;
-		if(!r || r->op != OCONST) {
-			diag(n, "DOT and no offset");
-			break;
-		}
-		nod.xoffset += (int32_t)r->vconst;
-		nod.type = n->type;
-		cgen(&nod, nn);
-		break;
-
-	case OCOND:
-		bcgen(l, 1);
-		p1 = p;
-		cgen(r->left, nn);
-		gbranch(OGOTO);
-		patch(p1, pc);
-		p1 = p;
-		cgen(r->right, nn);
-		patch(p1, pc);
-		break;
-
-	case OPOSTINC:
-	case OPOSTDEC:
-		v = 1;
-		if(l->type->etype == TIND)
-			v = l->type->link->width;
-		if(o == OPOSTDEC)
-			v = -v;
-		if(l->op == OBIT)
-			goto bitinc;
-		if(nn == Z)
-			goto pre;
-
-		if(hardleft)
-			reglcgen(&nod, l, Z);
-		else
-			nod = *l;
-
-		if(typefd[n->type->etype])
-			goto fltinc;
-		gmove(&nod, nn);
-		gopcode(OADD, n->type, nodconst(v), &nod);
-		if(hardleft)
-			regfree(&nod);
-		break;
-
-	case OPREINC:
-	case OPREDEC:
-		v = 1;
-		if(l->type->etype == TIND)
-			v = l->type->link->width;
-		if(o == OPREDEC)
-			v = -v;
-		if(l->op == OBIT)
-			goto bitinc;
-
-	pre:
-		if(hardleft)
-			reglcgen(&nod, l, Z);
-		else
-			nod = *l;
-		if(typefd[n->type->etype])
-			goto fltinc;
-		gopcode(OADD, n->type, nodconst(v), &nod);
-		if(nn != Z)
-			gmove(&nod, nn);
-		if(hardleft)
-			regfree(&nod);
-		break;
-
-	fltinc:
-		gmove(&nod, &fregnode0);
-		if(nn != Z && (o == OPOSTINC || o == OPOSTDEC))
-			gins(AFMOVD, &fregnode0, &fregnode0);
-		gins(AFLD1, Z, Z);
-		if(v < 0)
-			fgopcode(OSUB, &fregnode0, &fregnode1, 1, 0);
-		else
-			fgopcode(OADD, &fregnode0, &fregnode1, 1, 0);
-		if(nn != Z && (o == OPREINC || o == OPREDEC))
-			gins(AFMOVD, &fregnode0, &fregnode0);
-		gmove(&fregnode0, &nod);
-		if(hardleft)
-			regfree(&nod);
-		break;
-
-	bitinc:
-		if(nn != Z && (o == OPOSTINC || o == OPOSTDEC)) {
-			bitload(l, &nod, &nod1, &nod2, Z);
-			gmove(&nod, nn);
-			gopcode(OADD, tfield, nodconst(v), &nod);
-			bitstore(l, &nod, &nod1, &nod2, Z);
-			break;
-		}
-		bitload(l, &nod, &nod1, &nod2, nn);
-		gopcode(OADD, tfield, nodconst(v), &nod);
-		bitstore(l, &nod, &nod1, &nod2, nn);
-		break;
-	}
-done:
-	cursafe = curs;
-}
-
-void
-reglcgen(Node *t, Node *n, Node *nn)
-{
-	Node *r;
-	int32_t v;
-
-	regialloc(t, n, nn);
-	if(n->op == OIND) {
-		r = n->left;
-		while(r->op == OADD)
-			r = r->right;
-		if(sconst(r)) {
-			v = r->vconst;
-			r->vconst = 0;
-			lcgen(n, t);
-			t->xoffset += v;
-			r->vconst = v;
-			regind(t, n);
-			return;
-		}
-	}
-	lcgen(n, t);
-	regind(t, n);
-}
-
-void
-lcgen(Node *n, Node *nn)
-{
-	Prog *p1;
-	Node nod;
-
-	if(debug['g']) {
-		prtree(nn, "lcgen lhs");
-		prtree(n, "lcgen");
-	}
-	if(n == Z || n->type == T)
-		return;
-	if(nn == Z) {
-		nn = &nod;
-		regalloc(&nod, n, Z);
-	}
-	switch(n->op) {
-	default:
-		if(n->addable < INDEXED) {
-			diag(n, "unknown op in lcgen: %O", n->op);
-			break;
-		}
-		gopcode(OADDR, n->type, n, nn);
-		break;
-
-	case OCOMMA:
-		cgen(n->left, n->left);
-		lcgen(n->right, nn);
-		break;
-
-	case OIND:
-		cgen(n->left, nn);
-		break;
-
-	case OCOND:
-		bcgen(n->left, 1);
-		p1 = p;
-		lcgen(n->right->left, nn);
-		gbranch(OGOTO);
-		patch(p1, pc);
-		p1 = p;
-		lcgen(n->right->right, nn);
-		patch(p1, pc);
-		break;
-	}
-}
-
-void
-bcgen(Node *n, int true)
-{
-
-	if(n->type == T)
-		gbranch(OGOTO);
-	else
-		boolgen(n, true, Z);
-}
-
-void
-boolgen(Node *n, int true, Node *nn)
-{
-	int o;
-	Prog *p1, *p2;
-	Node *l, *r, nod, nod1;
-	int32_t curs;
-
-	if(debug['g']) {
-		prtree(nn, "boolgen lhs");
-		prtree(n, "boolgen");
-	}
-	curs = cursafe;
-	l = n->left;
-	r = n->right;
-	switch(n->op) {
-
-	default:
-		if(typev[n->type->etype]) {
-			testv(n, true);
-			goto com;
-		}
-		o = ONE;
-		if(true)
-			o = OEQ;
-		if(typefd[n->type->etype]) {
-			if(n->addable < INDEXED) {
-				cgen(n, &fregnode0);
-				gins(AFLDZ, Z, Z);
-				fgopcode(o, &fregnode0, &fregnode1, 1, 1);
-			} else {
-				gins(AFLDZ, Z, Z);
-				fgopcode(o, n, &fregnode0, 0, 1);
-			}
-			goto com;
-		}
-		/* bad, 13 is address of external that becomes constant */
-		if(n->addable >= INDEXED && n->addable != 13) {
-			gopcode(o, n->type, n, nodconst(0));
-			goto com;
-		}
-		regalloc(&nod, n, nn);
-		cgen(n, &nod);
-		gopcode(o, n->type, &nod, nodconst(0));
-		regfree(&nod);
-		goto com;
-
-	case OCONST:
-		o = vconst(n);
-		if(!true)
-			o = !o;
-		gbranch(OGOTO);
-		if(o) {
-			p1 = p;
-			gbranch(OGOTO);
-			patch(p1, pc);
-		}
-		goto com;
-
-	case OCOMMA:
-		cgen(l, Z);
-		boolgen(r, true, nn);
-		break;
-
-	case ONOT:
-		boolgen(l, !true, nn);
-		break;
-
-	case OCOND:
-		bcgen(l, 1);
-		p1 = p;
-		bcgen(r->left, true);
-		p2 = p;
-		gbranch(OGOTO);
-		patch(p1, pc);
-		p1 = p;
-		bcgen(r->right, !true);
-		patch(p2, pc);
-		p2 = p;
-		gbranch(OGOTO);
-		patch(p1, pc);
-		patch(p2, pc);
-		goto com;
-
-	case OANDAND:
-		if(!true)
-			goto caseor;
-
-	caseand:
-		bcgen(l, true);
-		p1 = p;
-		bcgen(r, !true);
-		p2 = p;
-		patch(p1, pc);
-		gbranch(OGOTO);
-		patch(p2, pc);
-		goto com;
-
-	case OOROR:
-		if(!true)
-			goto caseand;
-
-	caseor:
-		bcgen(l, !true);
-		p1 = p;
-		bcgen(r, !true);
-		p2 = p;
-		gbranch(OGOTO);
-		patch(p1, pc);
-		patch(p2, pc);
-		goto com;
-
-	case OEQ:
-	case ONE:
-	case OLE:
-	case OLT:
-	case OGE:
-	case OGT:
-	case OHI:
-	case OHS:
-	case OLO:
-	case OLS:
-		o = n->op;
-		if(typev[l->type->etype]) {
-			if(!true)
-				n->op = comrel[relindex(o)];
-			cgen64(n, Z);
-			goto com;
-		}
-		if(true)
-			o = comrel[relindex(o)];
-		if(l->complex >= FNX && r->complex >= FNX) {
-			regret(&nod, r);
-			cgen(r, &nod);
-			regsalloc(&nod1, r);
-			gmove(&nod, &nod1);
-			regfree(&nod);
-			nod = *n;
-			nod.right = &nod1;
-			boolgen(&nod, true, nn);
-			break;
-		}
-		if(typefd[l->type->etype]) {
-			if(l->complex >= r->complex) {
-				cgen(l, &fregnode0);
-				if(r->addable < INDEXED) {
-					cgen(r, &fregnode0);
-					o = invrel[relindex(o)];
-					fgopcode(o, &fregnode0, &fregnode1, 1, 1);
-				} else
-					fgopcode(o, r, &fregnode0, 0, 1);
-			} else {
-				o = invrel[relindex(o)];
-				cgen(r, &fregnode0);
-				if(l->addable < INDEXED) {
-					cgen(l, &fregnode0);
-					o = invrel[relindex(o)];
-					fgopcode(o, &fregnode0, &fregnode1, 1, 1);
-				} else
-					fgopcode(o, l, &fregnode0, 0, 1);
-			}
-			goto com;
-		}
-		if(l->op == OCONST) {
-			o = invrel[relindex(o)];
-			/* bad, 13 is address of external that becomes constant */
-			if(r->addable < INDEXED || r->addable == 13) {
-				regalloc(&nod, r, nn);
-				cgen(r, &nod);
-				gopcode(o, l->type, &nod, l);
-				regfree(&nod);
-			} else
-				gopcode(o, l->type, r, l);
-			goto com;
-		}
-		if(l->complex >= r->complex) {
-			regalloc(&nod, l, nn);
-			cgen(l, &nod);
-			if(r->addable < INDEXED) {
-				regalloc(&nod1, r, Z);
-				cgen(r, &nod1);
-				gopcode(o, l->type, &nod, &nod1);
-				regfree(&nod1);
-			} else
-				gopcode(o, l->type, &nod, r);
-			regfree(&nod);
-			goto com;
-		}
-		regalloc(&nod, r, nn);
-		cgen(r, &nod);
-		if(l->addable < INDEXED || l->addable == 13) {
-			regalloc(&nod1, l, Z);
-			cgen(l, &nod1);
-			if(typechlp[l->type->etype])
-				gopcode(o, types[TINT], &nod1, &nod);
-			else
-				gopcode(o, l->type, &nod1, &nod);
-			regfree(&nod1);
-		} else
-			gopcode(o, l->type, l, &nod);
-		regfree(&nod);
-
-	com:
-		if(nn != Z) {
-			p1 = p;
-			gmove(nodconst(1L), nn);
-			gbranch(OGOTO);
-			p2 = p;
-			patch(p1, pc);
-			gmove(nodconst(0L), nn);
-			patch(p2, pc);
-		}
-		break;
-	}
-	cursafe = curs;
-}
-
-void
-sugen(Node *n, Node *nn, int32_t w)
-{
-	Prog *p1;
-	Node nod0, nod1, nod2, nod3, nod4, *h, *l, *r;
-	Type *t;
-	int c, v, x;
-
-	if(n == Z || n->type == T)
-		return;
-	if(debug['g']) {
-		prtree(nn, "sugen lhs");
-		prtree(n, "sugen");
-	}
-	if(nn == nodrat)
-		if(w > nrathole)
-			nrathole = w;
-	switch(n->op) {
-	case OIND:
-		if(nn == Z) {
-			nullwarn(n->left, Z);
-			break;
-		}
-
-	default:
-		goto copy;
-
-	case OCONST:
-		if(n->type && typev[n->type->etype]) {
-			if(nn == Z) {
-				nullwarn(n->left, Z);
-				break;
-			}
-
-			if(nn->op == OREGPAIR) {
-				loadpair(n, nn);
-				break;
-			}
-			else if(!vaddr(nn, 0)) {
-				t = nn->type;
-				nn->type = types[TLONG];
-				reglcgen(&nod1, nn, Z);
-				nn->type = t;
-
-				gmove(lo64(n), &nod1);
-				nod1.xoffset += SZ_LONG;
-				gmove(hi64(n), &nod1);
-				regfree(&nod1);
-			}
-			else {
-				gins(AMOVL, lo64(n), nn);
-				nn->xoffset += SZ_LONG;
-				gins(AMOVL, hi64(n), nn);
-				nn->xoffset -= SZ_LONG;
-				break;
-			}
-			break;
-		}
-		goto copy;
-
-	case ODOT:
-		l = n->left;
-		sugen(l, nodrat, l->type->width);
-		if(nn == Z)
-			break;
-		warn(n, "non-interruptable temporary");
-		nod1 = *nodrat;
-		r = n->right;
-		if(!r || r->op != OCONST) {
-			diag(n, "DOT and no offset");
-			break;
-		}
-		nod1.xoffset += (int32_t)r->vconst;
-		nod1.type = n->type;
-		sugen(&nod1, nn, w);
-		break;
-
-	case OSTRUCT:
-		/*
-		 * rewrite so lhs has no fn call
-		 */
-		if(nn != Z && side(nn)) {
-			nod1 = *n;
-			nod1.type = typ(TIND, n->type);
-			regret(&nod2, &nod1);
-			lcgen(nn, &nod2);
-			regsalloc(&nod0, &nod1);
-			cgen(&nod2, &nod0);
-			regfree(&nod2);
-
-			nod1 = *n;
-			nod1.op = OIND;
-			nod1.left = &nod0;
-			nod1.right = Z;
-			nod1.complex = 1;
-
-			sugen(n, &nod1, w);
-			return;
-		}
-
-		r = n->left;
-		for(t = n->type->link; t != T; t = t->down) {
-			l = r;
-			if(r->op == OLIST) {
-				l = r->left;
-				r = r->right;
-			}
-			if(nn == Z) {
-				cgen(l, nn);
-				continue;
-			}
-			/*
-			 * hand craft *(&nn + o) = l
-			 */
-			nod0 = znode;
-			nod0.op = OAS;
-			nod0.type = t;
-			nod0.left = &nod1;
-			nod0.right = nil;
-
-			nod1 = znode;
-			nod1.op = OIND;
-			nod1.type = t;
-			nod1.left = &nod2;
-
-			nod2 = znode;
-			nod2.op = OADD;
-			nod2.type = typ(TIND, t);
-			nod2.left = &nod3;
-			nod2.right = &nod4;
-
-			nod3 = znode;
-			nod3.op = OADDR;
-			nod3.type = nod2.type;
-			nod3.left = nn;
-
-			nod4 = znode;
-			nod4.op = OCONST;
-			nod4.type = nod2.type;
-			nod4.vconst = t->offset;
-
-			ccom(&nod0);
-			acom(&nod0);
-			xcom(&nod0);
-			nod0.addable = 0;
-			nod0.right = l;
-
-			/* prtree(&nod0, "hand craft"); /* */
-			cgen(&nod0, Z);
-		}
-		break;
-
-	case OAS:
-		if(nn == Z) {
-			if(n->addable < INDEXED)
-				sugen(n->right, n->left, w);
-			break;
-		}
-
-		sugen(n->right, nodrat, w);
-		warn(n, "non-interruptable temporary");
-		sugen(nodrat, n->left, w);
-		sugen(nodrat, nn, w);
-		break;
-
-	case OFUNC:
-		if(nn == Z) {
-			sugen(n, nodrat, w);
-			break;
-		}
-		h = nn;
-		if(nn->op == OREGPAIR) {
-			regsalloc(&nod1, nn);
-			nn = &nod1;
-		}
-		if(nn->op != OIND) {
-			nn = new1(OADDR, nn, Z);
-			nn->type = types[TIND];
-			nn->addable = 0;
-		} else
-			nn = nn->left;
-		n = new(OFUNC, n->left, new(OLIST, nn, n->right));
-		n->type = types[TVOID];
-		n->left->type = types[TVOID];
-		cgen(n, Z);
-		if(h->op == OREGPAIR)
-			loadpair(nn->left, h);
-		break;
-
-	case OCOND:
-		bcgen(n->left, 1);
-		p1 = p;
-		sugen(n->right->left, nn, w);
-		gbranch(OGOTO);
-		patch(p1, pc);
-		p1 = p;
-		sugen(n->right->right, nn, w);
-		patch(p1, pc);
-		break;
-
-	case OCOMMA:
-		cgen(n->left, Z);
-		sugen(n->right, nn, w);
-		break;
-	}
-	return;
-
-copy:
-	if(nn == Z) {
-		switch(n->op) {
-		case OASADD:
-		case OASSUB:
-		case OASAND:
-		case OASOR:
-		case OASXOR:
-
-		case OASMUL:
-		case OASLMUL:
-
-		case OASASHL:
-		case OASASHR:
-		case OASLSHR:
-			break;
-
-		case OPOSTINC:
-		case OPOSTDEC:
-		case OPREINC:
-		case OPREDEC:
-			break;
-
-		default:
-			return;
-		}
-	}
-
-	if(n->complex >= FNX && nn != nil && nn->complex >= FNX) {
-		t = nn->type;
-		nn->type = types[TLONG];
-		regialloc(&nod1, nn, Z);
-		lcgen(nn, &nod1);
-		regsalloc(&nod2, nn);
-		nn->type = t;
-
-		gins(AMOVL, &nod1, &nod2);
-		regfree(&nod1);
-
-		nod2.type = typ(TIND, t);
-
-		nod1 = nod2;
-		nod1.op = OIND;
-		nod1.left = &nod2;
-		nod1.right = Z;
-		nod1.complex = 1;
-		nod1.type = t;
-
-		sugen(n, &nod1, w);
-		return;
-	}
-
-	x = 0;
-	v = w == 8;
-	if(v) {
-		c = cursafe;
-		if(n->left != Z && n->left->complex >= FNX
-		&& n->right != Z && n->right->complex >= FNX) {
-//			warn(n, "toughie");
-			regsalloc(&nod1, n->right);
-			cgen(n->right, &nod1);
-			nod2 = *n;
-			nod2.right = &nod1;
-			cgen(&nod2, nn);
-			cursafe = c;
-			return;
-		}
-		if(cgen64(n, nn)) {
-			cursafe = c;
-			return;
-		}
-		if(n->op == OCOM) {
-			n = n->left;
-			x = 1;
-		}
-	}
-
-	/* botch, need to save in .safe */
-	c = 0;
-	if(n->complex > nn->complex) {
-		t = n->type;
-		n->type = types[TLONG];
-		if(v) {
-			regalloc(&nod0, n, Z);
-			if(!vaddr(n, 0)) {
-				reglcgen(&nod1, n, Z);
-				n->type = t;
-				n = &nod1;
-			}
-			else
-				n->type = t;
-		}
-		else {
-			nodreg(&nod1, n, D_SI);
-			if(reg[D_SI]) {
-				gins(APUSHL, &nod1, Z);
-				c |= 1;
-				reg[D_SI]++;
-			}
-			lcgen(n, &nod1);
-			n->type = t;
-		}
-
-		t = nn->type;
-		nn->type = types[TLONG];
-		if(v) {
-			if(!vaddr(nn, 0)) {
-				reglcgen(&nod2, nn, Z);
-				nn->type = t;
-				nn = &nod2;
-			}
-			else
-				nn->type = t;
-		}
-		else {
-			nodreg(&nod2, nn, D_DI);
-			if(reg[D_DI]) {
-				gins(APUSHL, &nod2, Z);
-				c |= 2;
-				reg[D_DI]++;
-			}
-			lcgen(nn, &nod2);
-			nn->type = t;
-		}
-	} else {
-		t = nn->type;
-		nn->type = types[TLONG];
-		if(v) {
-			regalloc(&nod0, nn, Z);
-			if(!vaddr(nn, 0)) {
-				reglcgen(&nod2, nn, Z);
-				nn->type = t;
-				nn = &nod2;
-			}
-			else
-				nn->type = t;
-		}
-		else {
-			nodreg(&nod2, nn, D_DI);
-			if(reg[D_DI]) {
-				gins(APUSHL, &nod2, Z);
-				c |= 2;
-				reg[D_DI]++;
-			}
-			lcgen(nn, &nod2);
-			nn->type = t;
-		}
-
-		t = n->type;
-		n->type = types[TLONG];
-		if(v) {
-			if(!vaddr(n, 0)) {
-				reglcgen(&nod1, n, Z);
-				n->type = t;
-				n = &nod1;
-			}
-			else
-				n->type = t;
-		}
-		else {
-			nodreg(&nod1, n, D_SI);
-			if(reg[D_SI]) {
-				gins(APUSHL, &nod1, Z);
-				c |= 1;
-				reg[D_SI]++;
-			}
-			lcgen(n, &nod1);
-			n->type = t;
-		}
-	}
-	if(v) {
-		gins(AMOVL, n, &nod0);
-		if(x)
-			gins(ANOTL, Z, &nod0);
-		gins(AMOVL, &nod0, nn);
-		n->xoffset += SZ_LONG;
-		nn->xoffset += SZ_LONG;
-		gins(AMOVL, n, &nod0);
-		if(x)
-			gins(ANOTL, Z, &nod0);
-		gins(AMOVL, &nod0, nn);
-		n->xoffset -= SZ_LONG;
-		nn->xoffset -= SZ_LONG;
-		if(nn == &nod2)
-			regfree(&nod2);
-		if(n == &nod1)
-			regfree(&nod1);
-		regfree(&nod0);
-		return;
-	}
-	nodreg(&nod3, n, D_CX);
-	if(reg[D_CX]) {
-		gins(APUSHL, &nod3, Z);
-		c |= 4;
-		reg[D_CX]++;
-	}
-	gins(AMOVL, nodconst(w/SZ_LONG), &nod3);
-	gins(ACLD, Z, Z);
-	gins(AREP, Z, Z);
-	gins(AMOVSL, Z, Z);
-	if(w & (SZ_LONG-1)) {
-		/* odd length of packed structure */
-		gins(AMOVL, nodconst(w & (SZ_LONG-1)), &nod3);
-		gins(AREP, Z, Z);
-		gins(AMOVSB, Z, Z);
-	}
-	if(c & 4) {
-		gins(APOPL, Z, &nod3);
-		reg[D_CX]--;
-	}
-	if(c & 2) {
-		gins(APOPL, Z, &nod2);
-		reg[nod2.reg]--;
-	}
-	if(c & 1) {
-		gins(APOPL, Z, &nod1);
-		reg[nod1.reg]--;
-	}
-}

+ 0 - 2663
sys/src/cmd/8c/cgen64.c

@@ -1,2663 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "gc.h"
-
-void
-zeroregm(Node *n)
-{
-	gins(AMOVL, nodconst(0), n);
-}
-
-/* do we need to load the address of a vlong? */
-int
-vaddr(Node *n, int a)
-{
-	switch(n->op) {
-	case ONAME:
-		if(a)
-			return 1;
-		return !(n->class == CEXTERN || n->class == CGLOBL || n->class == CSTATIC);
-
-	case OCONST:
-	case OREGISTER:
-	case OINDREG:
-		return 1;
-	}
-	return 0;
-}
-
-long
-hi64v(Node *n)
-{
-	if(align(0, types[TCHAR], Aarg1))	/* isbigendian */
-		return (long)(n->vconst) & ~0L;
-	else
-		return (long)((uvlong)n->vconst>>32) & ~0L;
-}
-
-long
-lo64v(Node *n)
-{
-	if(align(0, types[TCHAR], Aarg1))	/* isbigendian */
-		return (long)((uvlong)n->vconst>>32) & ~0L;
-	else
-		return (long)(n->vconst) & ~0L;
-}
-
-Node *
-hi64(Node *n)
-{
-	return nodconst(hi64v(n));
-}
-
-Node *
-lo64(Node *n)
-{
-	return nodconst(lo64v(n));
-}
-
-static Node *
-anonreg(void)
-{
-	Node *n;
-
-	n = new(OREGISTER, Z, Z);
-	n->reg = D_NONE;
-	n->type = types[TLONG];
-	return n;
-}
-
-static Node *
-regpair(Node *n, Node *t)
-{
-	Node *r;
-
-	if(n != Z && n->op == OREGPAIR)
-		return n;
-	r = new(OREGPAIR, anonreg(), anonreg());
-	if(n != Z)
-		r->type = n->type;
-	else
-		r->type = t->type;
-	return r;
-}
-
-static void
-evacaxdx(Node *r)
-{
-	Node nod1, nod2;
-
-	if(r->reg == D_AX || r->reg == D_DX) {
-		reg[D_AX]++;
-		reg[D_DX]++;
-		/*
-		 * this is just an optim that should
-		 * check for spill
-		 */
-		r->type = types[TULONG];
-		regalloc(&nod1, r, Z);
-		nodreg(&nod2, Z, r->reg);
-		gins(AMOVL, &nod2, &nod1);
-		regfree(r);
-		r->reg = nod1.reg;
-		reg[D_AX]--;
-		reg[D_DX]--;
-	}
-}
-
-/* lazy instantiation of register pair */
-static int
-instpair(Node *n, Node *l)
-{
-	int r;
-
-	r = 0;
-	if(n->left->reg == D_NONE) {
-		if(l != Z) {
-			n->left->reg = l->reg;
-			r = 1;
-		}
-		else
-			regalloc(n->left, n->left, Z);
-	}
-	if(n->right->reg == D_NONE)
-		regalloc(n->right, n->right, Z);
-	return r;
-}
-
-static void
-zapreg(Node *n)
-{
-	if(n->reg != D_NONE) {
-		//prtree(n, "zapreg");
-		regfree(n);
-		n->reg = D_NONE;
-	}
-}
-
-static void
-freepair(Node *n)
-{
-	regfree(n->left);
-	regfree(n->right);
-}
-
-/* n is not OREGPAIR, nn is */
-void
-loadpair(Node *n, Node *nn)
-{
-	Node nod;
-
-	instpair(nn, Z);
-	if(n->op == OCONST) {
-		gins(AMOVL, lo64(n), nn->left);
-		n->xoffset += SZ_LONG;
-		gins(AMOVL, hi64(n), nn->right);
-		n->xoffset -= SZ_LONG;
-		return;
-	}
-	if(!vaddr(n, 0)) {
-		/* steal the right register for the laddr */
-		nod = regnode;
-		nod.reg = nn->right->reg;
-		lcgen(n, &nod);
-		n = &nod;
-		regind(n, n);
-		n->xoffset = 0;
-	}
-	gins(AMOVL, n, nn->left);
-	n->xoffset += SZ_LONG;
-	gins(AMOVL, n, nn->right);
-	n->xoffset -= SZ_LONG;
-}
-
-/* n is OREGPAIR, nn is not */
-static void
-storepair(Node *n, Node *nn, int f)
-{
-	Node nod;
-
-	if(!vaddr(nn, 0)) {
-		reglcgen(&nod, nn, Z);
-		nn = &nod;
-	}
-	gins(AMOVL, n->left, nn);
-	nn->xoffset += SZ_LONG;
-	gins(AMOVL, n->right, nn);
-	nn->xoffset -= SZ_LONG;
-	if(nn == &nod)
-		regfree(&nod);
-	if(f)
-		freepair(n);
-}
-
-enum
-{
-/* 4 only, see WW */
-	WNONE	= 0,
-	WCONST,
-	WADDR,
-	WHARD,
-};
-
-static int
-whatof(Node *n, int a)
-{
-	if(n->op == OCONST)
-		return WCONST;
-	return !vaddr(n, a) ? WHARD : WADDR;
-}
-
-/* can upgrade an extern to addr for AND */
-static int
-reduxv(Node *n)
-{
-	return lo64v(n) == 0 || hi64v(n) == 0;
-}
-
-int
-cond(int op)
-{
-	switch(op) {
-	case OANDAND:
-	case OOROR:
-	case ONOT:
-		return 1;
-
-	case OEQ:
-	case ONE:
-	case OLE:
-	case OLT:
-	case OGE:
-	case OGT:
-	case OHI:
-	case OHS:
-	case OLO:
-	case OLS:
-		return 1;
-	}
-	return 0;
-}
-
-/*
- * for a func operand call it and then return
- * the safe node
- */
-static Node *
-vfunc(Node *n, Node *nn)
-{
-	Node *t;
-
-	if(n->op != OFUNC)
-		return n;
-	t = new(0, Z, Z);
-	if(nn == Z || nn == nodret)
-		nn = n;
-	regsalloc(t, nn);
-	sugen(n, t, 8);
-	return t;
-}
-
-/* try to steal a reg */
-static int
-getreg(Node **np, Node *t, int r)
-{
-	Node *n, *p;
-
-	n = *np;
-	if(n->reg == r) {
-		p = new(0, Z, Z);
-		regalloc(p, n, Z);
-		gins(AMOVL, n, p);
-		*t = *n;
-		*np = p;
-		return 1;
-	}
-	return 0;
-}
-
-static Node *
-snarfreg(Node *n, Node *t, int r, Node *d, Node *c)
-{
-	if(n == Z || n->op != OREGPAIR || (!getreg(&n->left, t, r) && !getreg(&n->right, t, r))) {
-		if(nodreg(t, Z, r)) {
-			regalloc(c, d, Z);
-			gins(AMOVL, t, c);
-			reg[r]++;
-			return c;
-		}
-		reg[r]++;
-	}
-	return Z;
-}
-
-enum
-{
-	Vstart	= OEND,
-
-	Vgo,
-	Vamv,
-	Vmv,
-	Vzero,
-	Vop,
-	Vopx,
-	Vins,
-	Vins0,
-	Vinsl,
-	Vinsr,
-	Vinsla,
-	Vinsra,
-	Vinsx,
-	Vmul,
-	Vshll,
-	VT,
-	VF,
-	V_l_lo_f,
-	V_l_hi_f,
-	V_l_lo_t,
-	V_l_hi_t,
-	V_l_lo_u,
-	V_l_hi_u,
-	V_r_lo_f,
-	V_r_hi_f,
-	V_r_lo_t,
-	V_r_hi_t,
-	V_r_lo_u,
-	V_r_hi_u,
-	Vspazz,
-	Vend,
-
-	V_T0,
-	V_T1,
-	V_F0,
-	V_F1,
-
-	V_a0,
-	V_a1,
-	V_f0,
-	V_f1,
-
-	V_p0,
-	V_p1,
-	V_p2,
-	V_p3,
-	V_p4,
-
-	V_s0,
-	V_s1,
-	V_s2,
-	V_s3,
-	V_s4,
-
-	C00,
-	C01,
-	C31,
-	C32,
-
-	O_l_lo,
-	O_l_hi,
-	O_r_lo,
-	O_r_hi,
-	O_t_lo,
-	O_t_hi,
-	O_l,
-	O_r,
-	O_l_rp,
-	O_r_rp,
-	O_t_rp,
-	O_r0,
-	O_r1,
-	O_Zop,
-
-	O_a0,
-	O_a1,
-
-	V_C0,
-	V_C1,
-
-	V_S0,
-	V_S1,
-
-	VOPS	= 5,
-	VLEN	= 5,
-	VARGS	= 2,
-
-	S00	= 0,
-	Sc0,
-	Sc1,
-	Sc2,
-	Sac3,
-	Sac4,
-	S10,
-
-	SAgen	= 0,
-	SAclo,
-	SAc32,
-	SAchi,
-	SAdgen,
-	SAdclo,
-	SAdc32,
-	SAdchi,
-
-	B0c	= 0,
-	Bca,
-	Bac,
-
-	T0i	= 0,
-	Tii,
-
-	Bop0	= 0,
-	Bop1,
-};
-
-/*
- * _testv:
- * 	CMPL	lo,$0
- * 	JNE	true
- * 	CMPL	hi,$0
- * 	JNE	true
- * 	GOTO	false
- * false:
- * 	GOTO	code
- * true:
- * 	GOTO	patchme
- * code:
- */
-
-static uchar	testi[][VLEN] =
-{
-	{Vop, ONE, O_l_lo, C00},
-	{V_s0, Vop, ONE, O_l_hi, C00},
-	{V_s1, Vgo, V_s2, Vgo, V_s3},
-	{VF, V_p0, V_p1, VT, V_p2},
-	{Vgo, V_p3},
-	{VT, V_p0, V_p1, VF, V_p2},
-	{Vend},
-};
-
-/* shift left general case */
-static uchar	shll00[][VLEN] =
-{
-	{Vop, OGE, O_r, C32},
-	{V_s0, Vinsl, ASHLL, O_r, O_l_rp},
-	{Vins, ASHLL, O_r, O_l_lo, Vgo},
-	{V_p0, V_s0},
-	{Vins, ASHLL, O_r, O_l_lo},
-	{Vins, AMOVL, O_l_lo, O_l_hi},
-	{Vzero, O_l_lo, V_p0, Vend},
-};
-
-/* shift left rp, const < 32 */
-static uchar	shllc0[][VLEN] =
-{
-	{Vinsl, ASHLL, O_r, O_l_rp},
-	{Vshll, O_r, O_l_lo, Vend},
-};
-
-/* shift left rp, const == 32 */
-static uchar	shllc1[][VLEN] =
-{
-	{Vins, AMOVL, O_l_lo, O_l_hi},
-	{Vzero, O_l_lo, Vend},
-};
-
-/* shift left rp, const > 32 */
-static uchar	shllc2[][VLEN] =
-{
-	{Vshll, O_r, O_l_lo},
-	{Vins, AMOVL, O_l_lo, O_l_hi},
-	{Vzero, O_l_lo, Vend},
-};
-
-/* shift left addr, const == 32 */
-static uchar	shllac3[][VLEN] =
-{
-	{Vins, AMOVL, O_l_lo, O_t_hi},
-	{Vzero, O_t_lo, Vend},
-};
-
-/* shift left addr, const > 32 */
-static uchar	shllac4[][VLEN] =
-{
-	{Vins, AMOVL, O_l_lo, O_t_hi},
-	{Vshll, O_r, O_t_hi},
-	{Vzero, O_t_lo, Vend},
-};
-
-/* shift left of constant */
-static uchar	shll10[][VLEN] =
-{
-	{Vop, OGE, O_r, C32},
-	{V_s0, Vins, AMOVL, O_l_lo, O_t_lo},
-	{Vins, AMOVL, O_l_hi, O_t_hi},
-	{Vinsl, ASHLL, O_r, O_t_rp},
-	{Vins, ASHLL, O_r, O_t_lo, Vgo},
-	{V_p0, V_s0},
-	{Vins, AMOVL, O_l_lo, O_t_hi},
-	{V_l_lo_t, Vins, ASHLL, O_r, O_t_hi},
-	{Vzero, O_t_lo, V_p0, Vend},
-};
-
-static uchar	(*shlltab[])[VLEN] =
-{
-	shll00,
-	shllc0,
-	shllc1,
-	shllc2,
-	shllac3,
-	shllac4,
-	shll10,
-};
-
-/* shift right general case */
-static uchar	shrl00[][VLEN] =
-{
-	{Vop, OGE, O_r, C32},
-	{V_s0, Vinsr, ASHRL, O_r, O_l_rp},
-	{Vins, O_a0, O_r, O_l_hi, Vgo},
-	{V_p0, V_s0},
-	{Vins, O_a0, O_r, O_l_hi},
-	{Vins, AMOVL, O_l_hi, O_l_lo},
-	{V_T1, Vzero, O_l_hi},
-	{V_F1, Vins, ASARL, C31, O_l_hi},
-	{V_p0, Vend},
-};
-
-/* shift right rp, const < 32 */
-static uchar	shrlc0[][VLEN] =
-{
-	{Vinsr, ASHRL, O_r, O_l_rp},
-	{Vins, O_a0, O_r, O_l_hi, Vend},
-};
-
-/* shift right rp, const == 32 */
-static uchar	shrlc1[][VLEN] =
-{
-	{Vins, AMOVL, O_l_hi, O_l_lo},
-	{V_T1, Vzero, O_l_hi},
-	{V_F1, Vins, ASARL, C31, O_l_hi},
-	{Vend},
-};
-
-/* shift right rp, const > 32 */
-static uchar	shrlc2[][VLEN] =
-{
-	{Vins, O_a0, O_r, O_l_hi},
-	{Vins, AMOVL, O_l_hi, O_l_lo},
-	{V_T1, Vzero, O_l_hi},
-	{V_F1, Vins, ASARL, C31, O_l_hi},
-	{Vend},
-};
-
-/* shift right addr, const == 32 */
-static uchar	shrlac3[][VLEN] =
-{
-	{Vins, AMOVL, O_l_hi, O_t_lo},
-	{V_T1, Vzero, O_t_hi},
-	{V_F1, Vins, AMOVL, O_t_lo, O_t_hi},
-	{V_F1, Vins, ASARL, C31, O_t_hi},
-	{Vend},
-};
-
-/* shift right addr, const > 32 */
-static uchar	shrlac4[][VLEN] =
-{
-	{Vins, AMOVL, O_l_hi, O_t_lo},
-	{Vins, O_a0, O_r, O_t_lo},
-	{V_T1, Vzero, O_t_hi},
-	{V_F1, Vins, AMOVL, O_t_lo, O_t_hi},
-	{V_F1, Vins, ASARL, C31, O_t_hi},
-	{Vend},
-};
-
-/* shift right of constant */
-static uchar	shrl10[][VLEN] =
-{
-	{Vop, OGE, O_r, C32},
-	{V_s0, Vins, AMOVL, O_l_lo, O_t_lo},
-	{Vins, AMOVL, O_l_hi, O_t_hi},
-	{Vinsr, ASHRL, O_r, O_t_rp},
-	{Vins, O_a0, O_r, O_t_hi, Vgo},
-	{V_p0, V_s0},
-	{Vins, AMOVL, O_l_hi, O_t_lo},
-	{V_l_hi_t, Vins, O_a0, O_r, O_t_lo},
-	{V_l_hi_u, V_S1},
-	{V_T1, Vzero, O_t_hi, V_p0},
-	{V_F1, Vins, AMOVL, O_t_lo, O_t_hi},
-	{V_F1, Vins, ASARL, C31, O_t_hi},
-	{Vend},
-};
-
-static uchar	(*shrltab[])[VLEN] =
-{
-	shrl00,
-	shrlc0,
-	shrlc1,
-	shrlc2,
-	shrlac3,
-	shrlac4,
-	shrl10,
-};
-
-/* shift asop left general case */
-static uchar	asshllgen[][VLEN] =
-{
-	{V_a0, V_a1},
-	{Vop, OGE, O_r, C32},
-	{V_s0, Vins, AMOVL, O_l_lo, O_r0},
-	{Vins, AMOVL, O_l_hi, O_r1},
-	{Vinsla, ASHLL, O_r, O_r0},
-	{Vins, ASHLL, O_r, O_r0},
-	{Vins, AMOVL, O_r1, O_l_hi},
-	{Vins, AMOVL, O_r0, O_l_lo, Vgo},
-	{V_p0, V_s0},
-	{Vins, AMOVL, O_l_lo, O_r0},
-	{Vzero, O_l_lo},
-	{Vins, ASHLL, O_r, O_r0},
-	{Vins, AMOVL, O_r0, O_l_hi, V_p0},
-	{V_f0, V_f1, Vend},
-};
-
-/* shift asop left, const < 32 */
-static uchar	asshllclo[][VLEN] =
-{
-	{V_a0, V_a1},
-	{Vins, AMOVL, O_l_lo, O_r0},
-	{Vins, AMOVL, O_l_hi, O_r1},
-	{Vinsla, ASHLL, O_r, O_r0},
-	{Vshll, O_r, O_r0},
-	{Vins, AMOVL, O_r1, O_l_hi},
-	{Vins, AMOVL, O_r0, O_l_lo},
-	{V_f0, V_f1, Vend},
-};
-
-/* shift asop left, const == 32 */
-static uchar	asshllc32[][VLEN] =
-{
-	{V_a0},
-	{Vins, AMOVL, O_l_lo, O_r0},
-	{Vzero, O_l_lo},
-	{Vins, AMOVL, O_r0, O_l_hi},
-	{V_f0, Vend},
-};
-
-/* shift asop left, const > 32 */
-static uchar	asshllchi[][VLEN] =
-{
-	{V_a0},
-	{Vins, AMOVL, O_l_lo, O_r0},
-	{Vzero, O_l_lo},
-	{Vshll, O_r, O_r0},
-	{Vins, AMOVL, O_r0, O_l_hi},
-	{V_f0, Vend},
-};
-
-/* shift asop dest left general case */
-static uchar	asdshllgen[][VLEN] =
-{
-	{Vop, OGE, O_r, C32},
-	{V_s0, Vins, AMOVL, O_l_lo, O_t_lo},
-	{Vins, AMOVL, O_l_hi, O_t_hi},
-	{Vinsl, ASHLL, O_r, O_t_rp},
-	{Vins, ASHLL, O_r, O_t_lo},
-	{Vins, AMOVL, O_t_hi, O_l_hi},
-	{Vins, AMOVL, O_t_lo, O_l_lo, Vgo},
-	{V_p0, V_s0},
-	{Vins, AMOVL, O_l_lo, O_t_hi},
-	{Vzero, O_l_lo},
-	{Vins, ASHLL, O_r, O_t_hi},
-	{Vzero, O_t_lo},
-	{Vins, AMOVL, O_t_hi, O_l_hi, V_p0},
-	{Vend},
-};
-
-/* shift asop dest left, const < 32 */
-static uchar	asdshllclo[][VLEN] =
-{
-	{Vins, AMOVL, O_l_lo, O_t_lo},
-	{Vins, AMOVL, O_l_hi, O_t_hi},
-	{Vinsl, ASHLL, O_r, O_t_rp},
-	{Vshll, O_r, O_t_lo},
-	{Vins, AMOVL, O_t_hi, O_l_hi},
-	{Vins, AMOVL, O_t_lo, O_l_lo},
-	{Vend},
-};
-
-/* shift asop dest left, const == 32 */
-static uchar	asdshllc32[][VLEN] =
-{
-	{Vins, AMOVL, O_l_lo, O_t_hi},
-	{Vzero, O_t_lo},
-	{Vins, AMOVL, O_t_hi, O_l_hi},
-	{Vins, AMOVL, O_t_lo, O_l_lo},
-	{Vend},
-};
-
-/* shift asop dest, const > 32 */
-static uchar	asdshllchi[][VLEN] =
-{
-	{Vins, AMOVL, O_l_lo, O_t_hi},
-	{Vzero, O_t_lo},
-	{Vshll, O_r, O_t_hi},
-	{Vins, AMOVL, O_t_lo, O_l_lo},
-	{Vins, AMOVL, O_t_hi, O_l_hi},
-	{Vend},
-};
-
-static uchar	(*asshlltab[])[VLEN] =
-{
-	asshllgen,
-	asshllclo,
-	asshllc32,
-	asshllchi,
-	asdshllgen,
-	asdshllclo,
-	asdshllc32,
-	asdshllchi,
-};
-
-/* shift asop right general case */
-static uchar	asshrlgen[][VLEN] =
-{
-	{V_a0, V_a1},
-	{Vop, OGE, O_r, C32},
-	{V_s0, Vins, AMOVL, O_l_lo, O_r0},
-	{Vins, AMOVL, O_l_hi, O_r1},
-	{Vinsra, ASHRL, O_r, O_r0},
-	{Vinsx, Bop0, O_r, O_r1},
-	{Vins, AMOVL, O_r0, O_l_lo},
-	{Vins, AMOVL, O_r1, O_l_hi, Vgo},
-	{V_p0, V_s0},
-	{Vins, AMOVL, O_l_hi, O_r0},
-	{Vinsx, Bop0, O_r, O_r0},
-	{V_T1, Vzero, O_l_hi},
-	{Vins, AMOVL, O_r0, O_l_lo},
-	{V_F1, Vins, ASARL, C31, O_r0},
-	{V_F1, Vins, AMOVL, O_r0, O_l_hi},
-	{V_p0, V_f0, V_f1, Vend},
-};
-
-/* shift asop right, const < 32 */
-static uchar	asshrlclo[][VLEN] =
-{
-	{V_a0, V_a1},
-	{Vins, AMOVL, O_l_lo, O_r0},
-	{Vins, AMOVL, O_l_hi, O_r1},
-	{Vinsra, ASHRL, O_r, O_r0},
-	{Vinsx, Bop0, O_r, O_r1},
-	{Vins, AMOVL, O_r0, O_l_lo},
-	{Vins, AMOVL, O_r1, O_l_hi},
-	{V_f0, V_f1, Vend},
-};
-
-/* shift asop right, const == 32 */
-static uchar	asshrlc32[][VLEN] =
-{
-	{V_a0},
-	{Vins, AMOVL, O_l_hi, O_r0},
-	{V_T1, Vzero, O_l_hi},
-	{Vins, AMOVL, O_r0, O_l_lo},
-	{V_F1, Vins, ASARL, C31, O_r0},
-	{V_F1, Vins, AMOVL, O_r0, O_l_hi},
-	{V_f0, Vend},
-};
-
-/* shift asop right, const > 32 */
-static uchar	asshrlchi[][VLEN] =
-{
-	{V_a0},
-	{Vins, AMOVL, O_l_hi, O_r0},
-	{V_T1, Vzero, O_l_hi},
-	{Vinsx, Bop0, O_r, O_r0},
-	{Vins, AMOVL, O_r0, O_l_lo},
-	{V_F1, Vins, ASARL, C31, O_r0},
-	{V_F1, Vins, AMOVL, O_r0, O_l_hi},
-	{V_f0, Vend},
-};
-
-/* shift asop dest right general case */
-static uchar	asdshrlgen[][VLEN] =
-{
-	{Vop, OGE, O_r, C32},
-	{V_s0, Vins, AMOVL, O_l_lo, O_t_lo},
-	{Vins, AMOVL, O_l_hi, O_t_hi},
-	{Vinsr, ASHRL, O_r, O_t_rp},
-	{Vinsx, Bop0, O_r, O_t_hi},
-	{Vins, AMOVL, O_t_lo, O_l_lo},
-	{Vins, AMOVL, O_t_hi, O_l_hi, Vgo},
-	{V_p0, V_s0},
-	{Vins, AMOVL, O_l_hi, O_t_lo},
-	{V_T1, Vzero, O_t_hi},
-	{Vinsx, Bop0, O_r, O_t_lo},
-	{V_F1, Vins, AMOVL, O_t_lo, O_t_hi},
-	{V_F1, Vins, ASARL, C31, O_t_hi},
-	{Vins, AMOVL, O_t_hi, O_l_hi, V_p0},
-	{Vend},
-};
-
-/* shift asop dest right, const < 32 */
-static uchar	asdshrlclo[][VLEN] =
-{
-	{Vins, AMOVL, O_l_lo, O_t_lo},
-	{Vins, AMOVL, O_l_hi, O_t_hi},
-	{Vinsr, ASHRL, O_r, O_t_rp},
-	{Vinsx, Bop0, O_r, O_t_hi},
-	{Vins, AMOVL, O_t_lo, O_l_lo},
-	{Vins, AMOVL, O_t_hi, O_l_hi},
-	{Vend},
-};
-
-/* shift asop dest right, const == 32 */
-static uchar	asdshrlc32[][VLEN] =
-{
-	{Vins, AMOVL, O_l_hi, O_t_lo},
-	{V_T1, Vzero, O_t_hi},
-	{V_F1, Vins, AMOVL, O_t_lo, O_t_hi},
-	{V_F1, Vins, ASARL, C31, O_t_hi},
-	{Vins, AMOVL, O_t_lo, O_l_lo},
-	{Vins, AMOVL, O_t_hi, O_l_hi},
-	{Vend},
-};
-
-/* shift asop dest, const > 32 */
-static uchar	asdshrlchi[][VLEN] =
-{
-	{Vins, AMOVL, O_l_hi, O_t_lo},
-	{V_T1, Vzero, O_t_hi},
-	{Vinsx, Bop0, O_r, O_t_lo},
-	{V_T1, Vins, AMOVL, O_t_hi, O_l_hi},
-	{V_T1, Vins, AMOVL, O_t_lo, O_l_lo},
-	{V_F1, Vins, AMOVL, O_t_lo, O_t_hi},
-	{V_F1, Vins, ASARL, C31, O_t_hi},
-	{V_F1, Vins, AMOVL, O_t_lo, O_l_lo},
-	{V_F1, Vins, AMOVL, O_t_hi, O_l_hi},
-	{Vend},
-};
-
-static uchar	(*asshrltab[])[VLEN] =
-{
-	asshrlgen,
-	asshrlclo,
-	asshrlc32,
-	asshrlchi,
-	asdshrlgen,
-	asdshrlclo,
-	asdshrlc32,
-	asdshrlchi,
-};
-
-static uchar	shrlargs[]	= { ASHRL, 1 };
-static uchar	sarlargs[]	= { ASARL, 0 };
-
-/* ++ -- */
-static uchar	incdec[][VLEN] =
-{
-	{Vinsx, Bop0, C01, O_l_lo},
-	{Vinsx, Bop1, C00, O_l_hi, Vend},
-};
-
-/* ++ -- *p */
-static uchar	incdecpre[][VLEN] =
-{
-	{Vins, AMOVL, O_l_lo, O_t_lo},
-	{Vins, AMOVL, O_l_hi, O_t_hi},
-	{Vinsx, Bop0, C01, O_t_lo},
-	{Vinsx, Bop1, C00, O_t_hi},
-	{Vins, AMOVL, O_t_lo, O_l_lo},
-	{Vins, AMOVL, O_t_hi, O_l_hi, Vend},
-};
-
-/* *p ++ -- */
-static uchar	incdecpost[][VLEN] =
-{
-	{Vins, AMOVL, O_l_lo, O_t_lo},
-	{Vins, AMOVL, O_l_hi, O_t_hi},
-	{Vinsx, Bop0, C01, O_l_lo},
-	{Vinsx, Bop1, C00, O_l_hi, Vend},
-};
-
-/* binop rp, rp */
-static uchar	binop00[][VLEN] =
-{
-	{Vinsx, Bop0, O_r_lo, O_l_lo},
-	{Vinsx, Bop1, O_r_hi, O_l_hi, Vend},
-	{Vend},
-};
-
-/* binop rp, addr */
-static uchar	binoptmp[][VLEN] =
-{
-	{V_a0, Vins, AMOVL, O_r_lo, O_r0},
-	{Vinsx, Bop0, O_r0, O_l_lo},
-	{Vins, AMOVL, O_r_hi, O_r0},
-	{Vinsx, Bop1, O_r0, O_l_hi},
-	{V_f0, Vend},
-};
-
-/* binop t = *a op *b */
-static uchar	binop11[][VLEN] =
-{
-	{Vins, AMOVL, O_l_lo, O_t_lo},
-	{Vinsx, Bop0, O_r_lo, O_t_lo},
-	{Vins, AMOVL, O_l_hi, O_t_hi},
-	{Vinsx, Bop1, O_r_hi, O_t_hi, Vend},
-};
-
-/* binop t = rp +- c */
-static uchar	add0c[][VLEN] =
-{
-	{V_r_lo_t, Vinsx, Bop0, O_r_lo, O_l_lo},
-	{V_r_lo_f, Vamv, Bop0, Bop1},
-	{Vinsx, Bop1, O_r_hi, O_l_hi},
-	{Vend},
-};
-
-/* binop t = rp & c */
-static uchar	and0c[][VLEN] =
-{
-	{V_r_lo_t, Vinsx, Bop0, O_r_lo, O_l_lo},
-	{V_r_lo_f, Vins, AMOVL, C00, O_l_lo},
-	{V_r_hi_t, Vinsx, Bop1, O_r_hi, O_l_hi},
-	{V_r_hi_f, Vins, AMOVL, C00, O_l_hi},
-	{Vend},
-};
-
-/* binop t = rp | c */
-static uchar	or0c[][VLEN] =
-{
-	{V_r_lo_t, Vinsx, Bop0, O_r_lo, O_l_lo},
-	{V_r_hi_t, Vinsx, Bop1, O_r_hi, O_l_hi},
-	{Vend},
-};
-
-/* binop t = c - rp */
-static uchar	sub10[][VLEN] =
-{
-	{V_a0, Vins, AMOVL, O_l_lo, O_r0},
-	{Vinsx, Bop0, O_r_lo, O_r0},
-	{Vins, AMOVL, O_l_hi, O_r_lo},
-	{Vinsx, Bop1, O_r_hi, O_r_lo},
-	{Vspazz, V_f0, Vend},
-};
-
-/* binop t = c + *b */
-static uchar	addca[][VLEN] =
-{
-	{Vins, AMOVL, O_r_lo, O_t_lo},
-	{V_l_lo_t, Vinsx, Bop0, O_l_lo, O_t_lo},
-	{V_l_lo_f, Vamv, Bop0, Bop1},
-	{Vins, AMOVL, O_r_hi, O_t_hi},
-	{Vinsx, Bop1, O_l_hi, O_t_hi},
-	{Vend},
-};
-
-/* binop t = c & *b */
-static uchar	andca[][VLEN] =
-{
-	{V_l_lo_t, Vins, AMOVL, O_r_lo, O_t_lo},
-	{V_l_lo_t, Vinsx, Bop0, O_l_lo, O_t_lo},
-	{V_l_lo_f, Vzero, O_t_lo},
-	{V_l_hi_t, Vins, AMOVL, O_r_hi, O_t_hi},
-	{V_l_hi_t, Vinsx, Bop1, O_l_hi, O_t_hi},
-	{V_l_hi_f, Vzero, O_t_hi},
-	{Vend},
-};
-
-/* binop t = c | *b */
-static uchar	orca[][VLEN] =
-{
-	{Vins, AMOVL, O_r_lo, O_t_lo},
-	{V_l_lo_t, Vinsx, Bop0, O_l_lo, O_t_lo},
-	{Vins, AMOVL, O_r_hi, O_t_hi},
-	{V_l_hi_t, Vinsx, Bop1, O_l_hi, O_t_hi},
-	{Vend},
-};
-
-/* binop t = c - *b */
-static uchar	subca[][VLEN] =
-{
-	{Vins, AMOVL, O_l_lo, O_t_lo},
-	{Vins, AMOVL, O_l_hi, O_t_hi},
-	{Vinsx, Bop0, O_r_lo, O_t_lo},
-	{Vinsx, Bop1, O_r_hi, O_t_hi},
-	{Vend},
-};
-
-/* binop t = *a +- c */
-static uchar	addac[][VLEN] =
-{
-	{Vins, AMOVL, O_l_lo, O_t_lo},
-	{V_r_lo_t, Vinsx, Bop0, O_r_lo, O_t_lo},
-	{V_r_lo_f, Vamv, Bop0, Bop1},
-	{Vins, AMOVL, O_l_hi, O_t_hi},
-	{Vinsx, Bop1, O_r_hi, O_t_hi},
-	{Vend},
-};
-
-/* binop t = *a | c */
-static uchar	orac[][VLEN] =
-{
-	{Vins, AMOVL, O_l_lo, O_t_lo},
-	{V_r_lo_t, Vinsx, Bop0, O_r_lo, O_t_lo},
-	{Vins, AMOVL, O_l_hi, O_t_hi},
-	{V_r_hi_t, Vinsx, Bop1, O_r_hi, O_t_hi},
-	{Vend},
-};
-
-/* binop t = *a & c */
-static uchar	andac[][VLEN] =
-{
-	{V_r_lo_t, Vins, AMOVL, O_l_lo, O_t_lo},
-	{V_r_lo_t, Vinsx, Bop0, O_r_lo, O_t_lo},
-	{V_r_lo_f, Vzero, O_t_lo},
-	{V_r_hi_t, Vins, AMOVL, O_l_hi, O_t_hi},
-	{V_r_hi_t, Vinsx, Bop0, O_r_hi, O_t_hi},
-	{V_r_hi_f, Vzero, O_t_hi},
-	{Vend},
-};
-
-static uchar	ADDargs[]	= { AADDL, AADCL };
-static uchar	ANDargs[]	= { AANDL, AANDL };
-static uchar	ORargs[]	= { AORL, AORL };
-static uchar	SUBargs[]	= { ASUBL, ASBBL };
-static uchar	XORargs[]	= { AXORL, AXORL };
-
-static uchar	(*ADDtab[])[VLEN] =
-{
-	add0c, addca, addac,
-};
-
-static uchar	(*ANDtab[])[VLEN] =
-{
-	and0c, andca, andac,
-};
-
-static uchar	(*ORtab[])[VLEN] =
-{
-	or0c, orca, orac,
-};
-
-static uchar	(*SUBtab[])[VLEN] =
-{
-	add0c, subca, addac,
-};
-
-/* mul of const32 */
-static uchar	mulc32[][VLEN] =
-{
-	{V_a0, Vop, ONE, O_l_hi, C00},
-	{V_s0, Vins, AMOVL, O_r_lo, O_r0},
-	{Vins, AMULL, O_r0, O_Zop},
-	{Vgo, V_p0, V_s0},
-	{Vins, AMOVL, O_l_hi, O_r0},
-	{Vmul, O_r_lo, O_r0},
-	{Vins, AMOVL, O_r_lo, O_l_hi},
-	{Vins, AMULL, O_l_hi, O_Zop},
-	{Vins, AADDL, O_r0, O_l_hi},
-	{V_f0, V_p0, Vend},
-};
-
-/* mul of const64 */
-static uchar	mulc64[][VLEN] =
-{
-	{V_a0, Vins, AMOVL, O_r_hi, O_r0},
-	{Vop, OOR, O_l_hi, O_r0},
-	{Vop, ONE, O_r0, C00},
-	{V_s0, Vins, AMOVL, O_r_lo, O_r0},
-	{Vins, AMULL, O_r0, O_Zop},
-	{Vgo, V_p0, V_s0},
-	{Vmul, O_r_lo, O_l_hi},
-	{Vins, AMOVL, O_l_lo, O_r0},
-	{Vmul, O_r_hi, O_r0},
-	{Vins, AADDL, O_l_hi, O_r0},
-	{Vins, AMOVL, O_r_lo, O_l_hi},
-	{Vins, AMULL, O_l_hi, O_Zop},
-	{Vins, AADDL, O_r0, O_l_hi},
-	{V_f0, V_p0, Vend},
-};
-
-/* mul general */
-static uchar	mull[][VLEN] =
-{
-	{V_a0, Vins, AMOVL, O_r_hi, O_r0},
-	{Vop, OOR, O_l_hi, O_r0},
-	{Vop, ONE, O_r0, C00},
-	{V_s0, Vins, AMOVL, O_r_lo, O_r0},
-	{Vins, AMULL, O_r0, O_Zop},
-	{Vgo, V_p0, V_s0},
-	{Vins, AIMULL, O_r_lo, O_l_hi},
-	{Vins, AMOVL, O_l_lo, O_r0},
-	{Vins, AIMULL, O_r_hi, O_r0},
-	{Vins, AADDL, O_l_hi, O_r0},
-	{Vins, AMOVL, O_r_lo, O_l_hi},
-	{Vins, AMULL, O_l_hi, O_Zop},
-	{Vins, AADDL, O_r0, O_l_hi},
-	{V_f0, V_p0, Vend},
-};
-
-/* cast rp l to rp t */
-static uchar	castrp[][VLEN] =
-{
-	{Vmv, O_l, O_t_lo},
-	{VT, Vins, AMOVL, O_t_lo, O_t_hi},
-	{VT, Vins, ASARL, C31, O_t_hi},
-	{VF, Vzero, O_t_hi},
-	{Vend},
-};
-
-/* cast rp l to addr t */
-static uchar	castrpa[][VLEN] =
-{
-	{VT, V_a0, Vmv, O_l, O_r0},
-	{VT, Vins, AMOVL, O_r0, O_t_lo},
-	{VT, Vins, ASARL, C31, O_r0},
-	{VT, Vins, AMOVL, O_r0, O_t_hi},
-	{VT, V_f0},
-	{VF, Vmv, O_l, O_t_lo},
-	{VF, Vzero, O_t_hi},
-	{Vend},
-};
-
-static uchar	netab0i[][VLEN] =
-{
-	{Vop, ONE, O_l_lo, O_r_lo},
-	{V_s0, Vop, ONE, O_l_hi, O_r_hi},
-	{V_s1, Vgo, V_s2, Vgo, V_s3},
-	{VF, V_p0, V_p1, VT, V_p2},
-	{Vgo, V_p3},
-	{VT, V_p0, V_p1, VF, V_p2},
-	{Vend},
-};
-
-static uchar	netabii[][VLEN] =
-{
-	{V_a0, Vins, AMOVL, O_l_lo, O_r0},
-	{Vop, ONE, O_r0, O_r_lo},
-	{V_s0, Vins, AMOVL, O_l_hi, O_r0},
-	{Vop, ONE, O_r0, O_r_hi},
-	{V_s1, Vgo, V_s2, Vgo, V_s3},
-	{VF, V_p0, V_p1, VT, V_p2},
-	{Vgo, V_p3},
-	{VT, V_p0, V_p1, VF, V_p2},
-	{V_f0, Vend},
-};
-
-static uchar	cmptab0i[][VLEN] =
-{
-	{Vopx, Bop0, O_l_hi, O_r_hi},
-	{V_s0, Vins0, AJNE},
-	{V_s1, Vopx, Bop1, O_l_lo, O_r_lo},
-	{V_s2, Vgo, V_s3, Vgo, V_s4},
-	{VT, V_p1, V_p3},
-	{VF, V_p0, V_p2},
-	{Vgo, V_p4},
-	{VT, V_p0, V_p2},
-	{VF, V_p1, V_p3},
-	{Vend},
-};
-
-static uchar	cmptabii[][VLEN] =
-{
-	{V_a0, Vins, AMOVL, O_l_hi, O_r0},
-	{Vopx, Bop0, O_r0, O_r_hi},
-	{V_s0, Vins0, AJNE},
-	{V_s1, Vins, AMOVL, O_l_lo, O_r0},
-	{Vopx, Bop1, O_r0, O_r_lo},
-	{V_s2, Vgo, V_s3, Vgo, V_s4},
-	{VT, V_p1, V_p3},
-	{VF, V_p0, V_p2},
-	{Vgo, V_p4},
-	{VT, V_p0, V_p2},
-	{VF, V_p1, V_p3},
-	{V_f0, Vend},
-};
-
-static uchar	(*NEtab[])[VLEN] =
-{
-	netab0i, netabii,
-};
-
-static uchar	(*cmptab[])[VLEN] =
-{
-	cmptab0i, cmptabii,
-};
-
-static uchar	GEargs[]	= { OGT, OHS };
-static uchar	GTargs[]	= { OGT, OHI };
-static uchar	HIargs[]	= { OHI, OHI };
-static uchar	HSargs[]	= { OHI, OHS };
-
-/* Big Generator */
-static void
-biggen(Node *l, Node *r, Node *t, int true, uchar code[][VLEN], uchar *a)
-{
-	int i, j, g, oc, op, lo, ro, to, xo, *xp;
-	Type *lt;
-	Prog *pr[VOPS];
-	Node *ot, *tl, *tr, tmps[2];
-	uchar *c, (*cp)[VLEN], args[VARGS];
-
-	if(a != nil)
-		memmove(args, a, VARGS);
-//print("biggen %d %d %d\n", args[0], args[1], args[2]);
-//if(l) prtree(l, "l");
-//if(r) prtree(r, "r");
-//if(t) prtree(t, "t");
-	lo = ro = to = 0;
-	cp = code;
-
-	for (;;) {
-		c = *cp++;
-		g = 1;
-		i = 0;
-//print("code %d %d %d %d %d\n", c[0], c[1], c[2], c[3], c[4]);
-		for(;;) {
-			switch(op = c[i]) {
-			case Vgo:
-				if(g)
-					gbranch(OGOTO);
-				i++;
-				break;
-
-			case Vamv:
-				i += 3;
-				if(i > VLEN) {
-					diag(l, "bad Vop");
-					return;
-				}
-				if(g)
-					args[c[i - 1]] = args[c[i - 2]];
-				break;
-
-			case Vzero:
-				i += 2;
-				if(i > VLEN) {
-					diag(l, "bad Vop");
-					return;
-				}
-				j = i - 1;
-				goto op;
-
-			case Vspazz:	// nasty hack to save a reg in SUB
-//print("spazz\n");
-				if(g) {
-//print("hi %R lo %R t %R\n", r->right->reg, r->left->reg, tmps[0].reg);
-					ot = r->right;
-					r->right = r->left;
-					tl = new(0, Z, Z);
-					*tl = tmps[0];
-					r->left = tl;
-					tmps[0] = *ot;
-//print("hi %R lo %R t %R\n", r->right->reg, r->left->reg, tmps[0].reg);
-				}
-				i++;
-				break;
-
-			case Vmv:
-			case Vmul:
-			case Vshll:
-				i += 3;
-				if(i > VLEN) {
-					diag(l, "bad Vop");
-					return;
-				}
-				j = i - 2;
-				goto op;
-
-			case Vins0:
-				i += 2;
-				if(i > VLEN) {
-					diag(l, "bad Vop");
-					return;
-				}
-				gins(c[i - 1], Z, Z);
-				break;
-
-			case Vop:
-			case Vopx:
-			case Vins:
-			case Vinsl:
-			case Vinsr:
-			case Vinsla:
-			case Vinsra:
-			case Vinsx:
-				i += 4;
-				if(i > VLEN) {
-					diag(l, "bad Vop");
-					return;
-				}
-				j = i - 2;
-				goto op;
-
-			op:
-				if(!g)
-					break;
-				tl = Z;
-				tr = Z;
-				for(; j < i; j++) {
-					switch(c[j]) {
-					case C00:
-						ot = nodconst(0);
-						break;
-					case C01:
-						ot = nodconst(1);
-						break;
-					case C31:
-						ot = nodconst(31);
-						break;
-					case C32:
-						ot = nodconst(32);
-						break;
-
-					case O_l:
-					case O_l_lo:
-						ot = l; xp = &lo; xo = 0;
-						goto op0;
-					case O_l_hi:
-						ot = l; xp = &lo; xo = SZ_LONG;
-						goto op0;
-					case O_r:
-					case O_r_lo:
-						ot = r; xp = &ro; xo = 0;
-						goto op0;
-					case O_r_hi:
-						ot = r; xp = &ro; xo = SZ_LONG;
-						goto op0;
-					case O_t_lo:
-						ot = t; xp = &to; xo = 0;
-						goto op0;
-					case O_t_hi:
-						ot = t; xp = &to; xo = SZ_LONG;
-						goto op0;
-					case O_l_rp:
-						ot = l;
-						break;
-					case O_r_rp:
-						ot = r;
-						break;
-					case O_t_rp:
-						ot = t;
-						break;
-					case O_r0:
-					case O_r1:
-						ot = &tmps[c[j] - O_r0];
-						break;
-					case O_Zop:
-						ot = Z;
-						break;
-
-					op0:
-						switch(ot->op) {
-						case OCONST:
-							if(xo)
-								ot = hi64(ot);
-							else
-								ot = lo64(ot);
-							break;
-						case OREGPAIR:
-							if(xo)
-								ot = ot->right;
-							else
-								ot = ot->left;
-							break;
-						case OREGISTER:
-							break;
-						default:
-							if(xo != *xp) {
-								ot->xoffset += xo - *xp;
-								*xp = xo;
-							}
-						}
-						break;
-					
-					default:
-						diag(l, "bad V_lop");
-						return;
-					}
-					if(tl == nil)
-						tl = ot;
-					else
-						tr = ot;
-				}
-				if(op == Vzero) {
-					zeroregm(tl);
-					break;
-				}
-				oc = c[i - 3];
-				if(op == Vinsx || op == Vopx) {
-//print("%d -> %d\n", oc, args[oc]);
-					oc = args[oc];
-				}
-				else {
-					switch(oc) {
-					case O_a0:
-					case O_a1:
-						oc = args[oc - O_a0];
-						break;
-					}
-				}
-				switch(op) {
-				case Vmul:
-					mulgen(tr->type, tl, tr);
-					break;
-				case Vmv:
-					gmove(tl, tr);
-					break;
-				case Vshll:
-					shiftit(tr->type, tl, tr);
-					break;
-				case Vop:
-				case Vopx:
-					gopcode(oc, types[TULONG], tl, tr);
-					break;
-				case Vins:
-				case Vinsx:
-					gins(oc, tl, tr);
-					break;
-				case Vinsl:
-					gins(oc, tl, tr->right);
-					p->from.index = tr->left->reg;
-					break;
-				case Vinsr:
-					gins(oc, tl, tr->left);
-					p->from.index = tr->right->reg;
-					break;
-				case Vinsla:
-					gins(oc, tl, tr + 1);
-					p->from.index = tr->reg;
-					break;
-				case Vinsra:
-					gins(oc, tl, tr);
-					p->from.index = (tr + 1)->reg;
-					break;
-				}
-				break;
-
-			case VT:
-				g = true;
-				i++;
-				break;
-			case VF:
-				g = !true;
-				i++;
-				break;
-
-			case V_T0: case V_T1:
-				g = args[op - V_T0];
-				i++;
-				break;
-
-			case V_F0: case V_F1:
-				g = !args[op - V_F0];
-				i++;
-				break;
-
-			case V_C0: case V_C1:
-				if(g)
-					args[op - V_C0] = 0;
-				i++;
-				break;
-
-			case V_S0: case V_S1:
-				if(g)
-					args[op - V_S0] = 1;
-				i++;
-				break;
-
-			case V_l_lo_f:
-				g = lo64v(l) == 0;
-				i++;
-				break;
-			case V_l_hi_f:
-				g = hi64v(l) == 0;
-				i++;
-				break;
-			case V_l_lo_t:
-				g = lo64v(l) != 0;
-				i++;
-				break;
-			case V_l_hi_t:
-				g = hi64v(l) != 0;
-				i++;
-				break;
-			case V_l_lo_u:
-				g = lo64v(l) >= 0;
-				i++;
-				break;
-			case V_l_hi_u:
-				g = hi64v(l) >= 0;
-				i++;
-				break;
-			case V_r_lo_f:
-				g = lo64v(r) == 0;
-				i++;
-				break;
-			case V_r_hi_f:
-				g = hi64v(r) == 0;
-				i++;
-				break;
-			case V_r_lo_t:
-				g = lo64v(r) != 0;
-				i++;
-				break;
-			case V_r_hi_t:
-				g = hi64v(r) != 0;
-				i++;
-				break;
-			case V_r_lo_u:
-				g = lo64v(r) >= 0;
-				i++;
-				break;
-			case V_r_hi_u:
-				g = hi64v(r) >= 0;
-				i++;
-				break;
-
-			case Vend:
-				goto out;
-
-			case V_a0: case V_a1:
-				if(g) {
-					lt = l->type;
-					l->type = types[TULONG];
-					regalloc(&tmps[op - V_a0], l, Z);
-					l->type = lt;
-				}
-				i++;
-				break;
-
-			case V_f0: case V_f1:
-				if(g)
-					regfree(&tmps[op - V_f0]);
-				i++;
-				break;
-
-			case V_p0: case V_p1: case V_p2: case V_p3: case V_p4:
-				if(g)
-					patch(pr[op - V_p0], pc);
-				i++;
-				break;
-
-			case V_s0: case V_s1: case V_s2: case V_s3: case V_s4:
-				if(g)
-					pr[op - V_s0] = p;
-				i++;
-				break;
-
-			default:
-				diag(l, "bad biggen: %d", op);
-				return;
-			}
-			if(i == VLEN || c[i] == 0)
-				break;
-		}
-	}
-out:
-	if(lo)
-		l->xoffset -= lo;
-	if(ro)
-		r->xoffset -= ro;
-	if(to)
-		t->xoffset -= to;
-}
-
-int
-cgen64(Node *n, Node *nn)
-{
-	Type *dt;
-	uchar *args, (*cp)[VLEN], (**optab)[VLEN];
-	int li, ri, lri, dr, si, m, op, sh, cmp, true;
-	Node *c, *d, *l, *r, *t, *s, nod1, nod2, nod3, nod4, nod5;
-
-	if(debug['g']) {
-		prtree(nn, "cgen64 lhs");
-		prtree(n, "cgen64");
-		print("AX = %d\n", reg[D_AX]);
-	}
-	cmp = 0;
-	sh = 0;
-
-	switch(n->op) {
-	case ONEG:
-		d = regpair(nn, n);
-		sugen(n->left, d, 8);
-		gins(ANOTL, Z, d->right);
-		gins(ANEGL, Z, d->left);
-		gins(ASBBL, nodconst(-1), d->right);
-		break;
-
-	case OCOM:
-		if(!vaddr(n->left, 0) || !vaddr(nn, 0))
-			d = regpair(nn, n);
-		else
-			return 0;
-		sugen(n->left, d, 8);
-		gins(ANOTL, Z, d->left);
-		gins(ANOTL, Z, d->right);
-		break;
-
-	case OADD:
-		optab = ADDtab;
-		args = ADDargs;
-		goto twoop;
-	case OAND:
-		optab = ANDtab;
-		args = ANDargs;
-		goto twoop;
-	case OOR:
-		optab = ORtab;
-		args = ORargs;
-		goto twoop;
-	case OSUB:
-		optab = SUBtab;
-		args = SUBargs;
-		goto twoop;
-	case OXOR:
-		optab = ORtab;
-		args = XORargs;
-		goto twoop;
-	case OASHL:
-		sh = 1;
-		args = nil;
-		optab = shlltab;
-		goto twoop;
-	case OLSHR:
-		sh = 1;
-		args = shrlargs;
-		optab = shrltab;
-		goto twoop;
-	case OASHR:
-		sh = 1;
-		args = sarlargs;
-		optab = shrltab;
-		goto twoop;
-	case OEQ:
-		cmp = 1;
-		args = nil;
-		optab = nil;
-		goto twoop;
-	case ONE:
-		cmp = 1;
-		args = nil;
-		optab = nil;
-		goto twoop;
-	case OLE:
-		cmp = 1;
-		args = nil;
-		optab = nil;
-		goto twoop;
-	case OLT:
-		cmp = 1;
-		args = nil;
-		optab = nil;
-		goto twoop;
-	case OGE:
-		cmp = 1;
-		args = nil;
-		optab = nil;
-		goto twoop;
-	case OGT:
-		cmp = 1;
-		args = nil;
-		optab = nil;
-		goto twoop;
-	case OHI:
-		cmp = 1;
-		args = nil;
-		optab = nil;
-		goto twoop;
-	case OHS:
-		cmp = 1;
-		args = nil;
-		optab = nil;
-		goto twoop;
-	case OLO:
-		cmp = 1;
-		args = nil;
-		optab = nil;
-		goto twoop;
-	case OLS:
-		cmp = 1;
-		args = nil;
-		optab = nil;
-		goto twoop;
-
-twoop:
-		dr = nn != Z && nn->op == OREGPAIR;
-		l = vfunc(n->left, nn);
-		if(sh)
-			r = n->right;
-		else
-			r = vfunc(n->right, nn);
-
-		li = l->op == ONAME || l->op == OINDREG || l->op == OCONST;
-		ri = r->op == ONAME || r->op == OINDREG || r->op == OCONST;
-
-#define	IMM(l, r)	((l) | ((r) << 1))
-
-		lri = IMM(li, ri);
-
-		/* find out what is so easy about some operands */
-		if(li)
-			li = whatof(l, sh | cmp);
-		if(ri)
-			ri = whatof(r, cmp);
-
-		if(sh)
-			goto shift;
-
-		if(cmp)
-			goto cmp;
-
-		/* evaluate hard subexps, stealing nn if possible. */
-		switch(lri) {
-		case IMM(0, 0):
-		bin00:
-			if(l->complex > r->complex) {
-				if(dr)
-					t = nn;
-				else
-					t = regpair(Z, n);
-				sugen(l, t, 8);
-				l = t;
-				t = regpair(Z, n);
-				sugen(r, t, 8);
-				r = t;
-			}
-			else {
-				t = regpair(Z, n);
-				sugen(r, t, 8);
-				r = t;
-				if(dr)
-					t = nn;
-				else
-					t = regpair(Z, n);
-				sugen(l, t, 8);
-				l = t;
-			}
-			break;
-		case IMM(0, 1):
-			if(dr)
-				t = nn;
-			else
-				t = regpair(Z, n);
-			sugen(l, t, 8);
-			l = t;
-			break;
-		case IMM(1, 0):
-			if(n->op == OSUB && l->op == OCONST && hi64v(l) == 0) {
-				lri = IMM(0, 0);
-				goto bin00;
-			}
-			if(dr)
-				t = nn;
-			else
-				t = regpair(Z, n);
-			sugen(r, t, 8);
-			r = t;
-			break;
-		case IMM(1, 1):
-			break;
-		}
-
-#define	WW(l, r)	((l) | ((r) << 2))
-		d = Z;
-		dt = nn->type;
-		nn->type = types[TLONG];
-
-		switch(lri) {
-		case IMM(0, 0):
-			biggen(l, r, Z, 0, binop00, args);
-			break;
-		case IMM(0, 1):
-			switch(ri) {
-			case WNONE:
-				diag(r, "bad whatof\n");
-				break;
-			case WCONST:
-				biggen(l, r, Z, 0, optab[B0c], args);
-				break;
-			case WHARD:
-				reglcgen(&nod2, r, Z);
-				r = &nod2;
-				/* fall thru */
-			case WADDR:
-				biggen(l, r, Z, 0, binoptmp, args);
-				if(ri == WHARD)
-					regfree(r);
-				break;
-			}
-			break;
-		case IMM(1, 0):
-			if(n->op == OSUB) {
-				switch(li) {
-				case WNONE:
-					diag(l, "bad whatof\n");
-					break;
-				case WHARD:
-					reglcgen(&nod2, l, Z);
-					l = &nod2;
-					/* fall thru */
-				case WADDR:
-				case WCONST:
-					biggen(l, r, Z, 0, sub10, args);
-					break;
-				}
-				if(li == WHARD)
-					regfree(l);
-			}
-			else {
-				switch(li) {
-				case WNONE:
-					diag(l, "bad whatof\n");
-					break;
-				case WCONST:
-					biggen(r, l, Z, 0, optab[B0c], args);
-					break;
-				case WHARD:
-					reglcgen(&nod2, l, Z);
-					l = &nod2;
-					/* fall thru */
-				case WADDR:
-					biggen(r, l, Z, 0, binoptmp, args);
-					if(li == WHARD)
-						regfree(l);
-					break;
-				}
-			}
-			break;
-		case IMM(1, 1):
-			switch(WW(li, ri)) {
-			case WW(WCONST, WHARD):
-				if(r->op == ONAME && n->op == OAND && reduxv(l))
-					ri = WADDR;
-				break;
-			case WW(WHARD, WCONST):
-				if(l->op == ONAME && n->op == OAND && reduxv(r))
-					li = WADDR;
-				break;
-			}
-			if(li == WHARD) {
-				reglcgen(&nod3, l, Z);
-				l = &nod3;
-			}
-			if(ri == WHARD) {
-				reglcgen(&nod2, r, Z);
-				r = &nod2;
-			}
-			d = regpair(nn, n);
-			instpair(d, Z);
-			switch(WW(li, ri)) {
-			case WW(WCONST, WADDR):
-			case WW(WCONST, WHARD):
-				biggen(l, r, d, 0, optab[Bca], args);
-				break;
-
-			case WW(WADDR, WCONST):
-			case WW(WHARD, WCONST):
-				biggen(l, r, d, 0, optab[Bac], args);
-				break;
-
-			case WW(WADDR, WADDR):
-			case WW(WADDR, WHARD):
-			case WW(WHARD, WADDR):
-			case WW(WHARD, WHARD):
-				biggen(l, r, d, 0, binop11, args);
-				break;
-
-			default:
-				diag(r, "bad whatof pair %d %d\n", li, ri);
-				break;
-			}
-			if(li == WHARD)
-				regfree(l);
-			if(ri == WHARD)
-				regfree(r);
-			break;
-		}
-
-		nn->type = dt;
-
-		if(d != Z)
-			goto finished;
-
-		switch(lri) {
-		case IMM(0, 0):
-			freepair(r);
-			/* fall thru */;
-		case IMM(0, 1):
-			if(!dr)
-				storepair(l, nn, 1);
-			break;
-		case IMM(1, 0):
-			if(!dr)
-				storepair(r, nn, 1);
-			break;
-		case IMM(1, 1):
-			break;
-		}
-		return 1;
-
-	shift:
-		c = Z;
-
-		/* evaluate hard subexps, stealing nn if possible. */
-		/* must also secure CX.  not as many optims as binop. */
-		switch(lri) {
-		case IMM(0, 0):
-		imm00:
-			if(l->complex + 1 > r->complex) {
-				if(dr)
-					t = nn;
-				else
-					t = regpair(Z, l);
-				sugen(l, t, 8);
-				l = t;
-				t = &nod1;
-				c = snarfreg(l, t, D_CX, r, &nod2);
-				cgen(r, t);
-				r = t;
-			}
-			else {
-				t = &nod1;
-				c = snarfreg(nn, t, D_CX, r, &nod2);
-				cgen(r, t);
-				r = t;
-				if(dr)
-					t = nn;
-				else
-					t = regpair(Z, l);
-				sugen(l, t, 8);
-				l = t;
-			}
-			break;
-		case IMM(0, 1):
-		imm01:
-			if(ri != WCONST) {
-				lri = IMM(0, 0);
-				goto imm00;
-			}
-			if(dr)
-				t = nn;
-			else
-				t = regpair(Z, n);
-			sugen(l, t, 8);
-			l = t;
-			break;
-		case IMM(1, 0):
-		imm10:
-			if(li != WCONST) {
-				lri = IMM(0, 0);
-				goto imm00;
-			}
-			t = &nod1;
-			c = snarfreg(nn, t, D_CX, r, &nod2);
-			cgen(r, t);
-			r = t;
-			break;
-		case IMM(1, 1):
-			if(ri != WCONST) {
-				lri = IMM(1, 0);
-				goto imm10;
-			}
-			if(li == WHARD) {
-				lri = IMM(0, 1);
-				goto imm01;
-			}
-			break;
-		}
-
-		d = Z;
-
-		switch(lri) {
-		case IMM(0, 0):
-			biggen(l, r, Z, 0, optab[S00], args);
-			break;
-		case IMM(0, 1):
-			switch(ri) {
-			case WNONE:
-			case WADDR:
-			case WHARD:
-				diag(r, "bad whatof\n");
-				break;
-			case WCONST:
-				m = r->vconst & 63;
-				s = nodconst(m);
-				if(m < 32)
-					cp = optab[Sc0];
-				else if(m == 32)
-					cp = optab[Sc1];
-				else
-					cp = optab[Sc2];
-				biggen(l, s, Z, 0, cp, args);
-				break;
-			}
-			break;
-		case IMM(1, 0):
-			/* left is const */
-			d = regpair(nn, n);
-			instpair(d, Z);
-			biggen(l, r, d, 0, optab[S10], args);
-			regfree(r);
-			break;
-		case IMM(1, 1):
-			d = regpair(nn, n);
-			instpair(d, Z);
-			switch(WW(li, ri)) {
-			case WW(WADDR, WCONST):
-				m = r->vconst & 63;
-				s = nodconst(m);
-				if(m < 32) {
-					loadpair(l, d);
-					l = d;
-					cp = optab[Sc0];
-				}
-				else if(m == 32)
-					cp = optab[Sac3];
-				else
-					cp = optab[Sac4];
-				biggen(l, s, d, 0, cp, args);
-				break;
-
-			default:
-				diag(r, "bad whatof pair %d %d\n", li, ri);
-				break;
-			}
-			break;
-		}
-
-		if(c != Z) {
-			gins(AMOVL, c, r);
-			regfree(c);
-		}
-
-		if(d != Z)
-			goto finished;
-
-		switch(lri) {
-		case IMM(0, 0):
-			regfree(r);
-			/* fall thru */
-		case IMM(0, 1):
-			if(!dr)
-				storepair(l, nn, 1);
-			break;
-		case IMM(1, 0):
-			regfree(r);
-			break;
-		case IMM(1, 1):
-			break;
-		}
-		return 1;
-
-	cmp:
-		op = n->op;
-		/* evaluate hard subexps */
-		switch(lri) {
-		case IMM(0, 0):
-			if(l->complex > r->complex) {
-				t = regpair(Z, l);
-				sugen(l, t, 8);
-				l = t;
-				t = regpair(Z, r);
-				sugen(r, t, 8);
-				r = t;
-			}
-			else {
-				t = regpair(Z, r);
-				sugen(r, t, 8);
-				r = t;
-				t = regpair(Z, l);
-				sugen(l, t, 8);
-				l = t;
-			}
-			break;
-		case IMM(1, 0):
-			t = r;
-			r = l;
-			l = t;
-			ri = li;
-			op = invrel[relindex(op)];
-			/* fall thru */
-		case IMM(0, 1):
-			t = regpair(Z, l);
-			sugen(l, t, 8);
-			l = t;
-			break;
-		case IMM(1, 1):
-			break;
-		}
-
-		true = 1;
-		optab = cmptab;
-		switch(op) {
-		case OEQ:
-			optab = NEtab;
-			true = 0;
-			break;
-		case ONE:
-			optab = NEtab;
-			break;
-		case OLE:
-			args = GTargs;
-			true = 0;
-			break;
-		case OGT:
-			args = GTargs;
-			break;
-		case OLS:
-			args = HIargs;
-			true = 0;
-			break;
-		case OHI:
-			args = HIargs;
-			break;
-		case OLT:
-			args = GEargs;
-			true = 0;
-			break;
-		case OGE:
-			args = GEargs;
-			break;
-		case OLO:
-			args = HSargs;
-			true = 0;
-			break;
-		case OHS:
-			args = HSargs;
-			break;
-		default:
-			diag(n, "bad cmp\n");
-			SET(optab);
-		}
-
-		switch(lri) {
-		case IMM(0, 0):
-			biggen(l, r, Z, true, optab[T0i], args);
-			break;
-		case IMM(0, 1):
-		case IMM(1, 0):
-			switch(ri) {
-			case WNONE:
-				diag(l, "bad whatof\n");
-				break;
-			case WCONST:
-				biggen(l, r, Z, true, optab[T0i], args);
-				break;
-			case WHARD:
-				reglcgen(&nod2, r, Z);
-				r = &nod2;
-				/* fall thru */
-			case WADDR:
-				biggen(l, r, Z, true, optab[T0i], args);
-				if(ri == WHARD)
-					regfree(r);
-				break;
-			}
-			break;
-		case IMM(1, 1):
-			if(li == WHARD) {
-				reglcgen(&nod3, l, Z);
-				l = &nod3;
-			}
-			if(ri == WHARD) {
-				reglcgen(&nod2, r, Z);
-				r = &nod2;
-			}
-			biggen(l, r, Z, true, optab[Tii], args);
-			if(li == WHARD)
-				regfree(l);
-			if(ri == WHARD)
-				regfree(r);
-			break;
-		}
-
-		switch(lri) {
-		case IMM(0, 0):
-			freepair(r);
-			/* fall thru */;
-		case IMM(0, 1):
-		case IMM(1, 0):
-			freepair(l);
-			break;
-		case IMM(1, 1):
-			break;
-		}
-		return 1;
-
-	case OASMUL:
-	case OASLMUL:
-		m = 0;
-		goto mulop;
-
-	case OMUL:
-	case OLMUL:
-		m = 1;
-		goto mulop;
-
-	mulop:
-		dr = nn != Z && nn->op == OREGPAIR;
-		l = vfunc(n->left, nn);
-		r = vfunc(n->right, nn);
-		if(r->op != OCONST) {
-			if(l->complex > r->complex) {
-				if(m) {
-					t = l;
-					l = r;
-					r = t;
-				}
-				else if(!vaddr(l, 1)) {
-					reglcgen(&nod5, l, Z);
-					l = &nod5;
-					evacaxdx(l);
-				}
-			}
-			t = regpair(Z, n);
-			sugen(r, t, 8);
-			r = t;
-			evacaxdx(r->left);
-			evacaxdx(r->right);
-			if(l->complex <= r->complex && !m && !vaddr(l, 1)) {
-				reglcgen(&nod5, l, Z);
-				l = &nod5;
-				evacaxdx(l);
-			}
-		}
-		if(dr)
-			t = nn;
-		else
-			t = regpair(Z, n);
-		//print("dr=%d ", dr); prtree(t, "t");
-		c = Z;
-		d = Z;
-		if(!nodreg(&nod1, t->left, D_AX)) {
-			if(t->left->reg != D_AX){
-				t->left->reg = D_AX;
-				reg[D_AX]++;
-			}else if(reg[D_AX] == 0)
-				fatal(Z, "vlong mul AX botch");
-		}
-		if(!nodreg(&nod2, t->right, D_DX)) {
-			if(t->right->reg != D_DX){
-				t->right->reg = D_DX;
-				reg[D_DX]++;
-			}else if(reg[D_DX] == 0)
-				fatal(Z, "vlong mul DX botch");
-		}
-		//prtree(t, "t1"); print("reg/ax = %d reg/dx = %d\n", reg[D_AX], reg[D_DX]);
-		if(m)
-			sugen(l, t, 8);
-		else
-			loadpair(l, t);
-		//prtree(t, "t2"); print("reg/ax = %d reg/dx = %d\n", reg[D_AX], reg[D_DX]);
-		if(t->left->reg != D_AX) {
-			c = &nod3;
-			regsalloc(c, t->left);
-			gmove(&nod1, c);
-			gmove(t->left, &nod1);
-			zapreg(t->left);
-		}
-		//print("reg/ax = %d reg/dx = %d\n", reg[D_AX], reg[D_DX]);
-		if(t->right->reg != D_DX) {
-			d = &nod4;
-			regsalloc(d, t->right);
-			gmove(&nod2, d);
-			if(t->right->reg == D_AX && c != nil){
-				/* need previous value of AX in DX */
-				gmove(c, &nod2);
-			}else
-				gmove(t->right, &nod2);
-			zapreg(t->right);
-		}
-		if(c != Z || d != Z) {
-			s = regpair(Z, n);
-			s->left = &nod1;
-			s->right = &nod2;
-		}
-		else
-			s = t;
-		reg[D_AX]++;	/* don't allow biggen to allocate AX or DX (smashed by MUL) as temp */
-		reg[D_DX]++;
-		if(r->op == OCONST) {
-			if(hi64v(r) == 0)
-				biggen(s, r, Z, 0, mulc32, nil);
-			else
-				biggen(s, r, Z, 0, mulc64, nil);
-		}
-		else
-			biggen(s, r, Z, 0, mull, nil);
-		instpair(t, Z);
-		reg[D_AX]--;
-		reg[D_DX]--;
-		if(c != Z) {
-			gmove(&nod1, t->left);
-			gmove(&nod3, &nod1);
-		}
-		if(d != Z) {
-			gmove(&nod2, t->right);
-			gmove(&nod4, &nod2);
-		}
-
-		if(r->op == OREGPAIR)
-			freepair(r);
-		if(!m)
-			storepair(t, l, 0);
-		if(l == &nod5)
-			regfree(l);
-
-		if(!dr) {
-			if(nn != Z)
-				storepair(t, nn, 1);
-			else
-				freepair(t);
-		}
-		return 1;
-
-	case OASADD:
-		args = ADDargs;
-		goto vasop;
-	case OASAND:
-		args = ANDargs;
-		goto vasop;
-	case OASOR:
-		args = ORargs;
-		goto vasop;
-	case OASSUB:
-		args = SUBargs;
-		goto vasop;
-	case OASXOR:
-		args = XORargs;
-		goto vasop;
-
-	vasop:
-		l = n->left;
-		r = n->right;
-		dr = nn != Z && nn->op == OREGPAIR;
-		m = 0;
-		if(l->complex > r->complex) {
-			if(!vaddr(l, 1)) {
-				reglcgen(&nod1, l, Z);
-				l = &nod1;
-			}
-			if(!vaddr(r, 1) || nn != Z || r->op == OCONST) {
-				if(dr)
-					t = nn;
-				else
-					t = regpair(Z, r);
-				sugen(r, t, 8);
-				r = t;
-				m = 1;
-			}
-		}
-		else {
-			if(!vaddr(r, 1) || nn != Z || r->op == OCONST) {
-				if(dr)
-					t = nn;
-				else
-					t = regpair(Z, r);
-				sugen(r, t, 8);
-				r = t;
-				m = 1;
-			}
-			if(!vaddr(l, 1)) {
-				reglcgen(&nod1, l, Z);
-				l = &nod1;
-			}
-		}
-		if(nn != Z) {
-			if(n->op == OASSUB)
-				biggen(l, r, Z, 0, sub10, args);
-			else
-				biggen(r, l, Z, 0, binoptmp, args);
-			storepair(r, l, 0);
-		}
-		else {
-			if(m)
-				biggen(l, r, Z, 0, binop00, args);
-			else
-				biggen(l, r, Z, 0, binoptmp, args);
-		}
-		if(l == &nod1)
-			regfree(&nod1);
-		if(m) {
-			if(nn == Z)
-				freepair(r);
-			else if(!dr)
-				storepair(r, nn, 1);
-		}
-		return 1;
-
-	case OASASHL:
-		args = nil;
-		optab = asshlltab;
-		goto assh;
-	case OASLSHR:
-		args = shrlargs;
-		optab = asshrltab;
-		goto assh;
-	case OASASHR:
-		args = sarlargs;
-		optab = asshrltab;
-		goto assh;
-
-	assh:
-		c = Z;
-		l = n->left;
-		r = n->right;
-		if(r->op == OCONST) {
-			m = r->vconst & 63;
-			if(m < 32)
-				m = SAclo;
-			else if(m == 32)
-				m = SAc32;
-			else
-				m = SAchi;
-		}
-		else
-			m = SAgen;
-		if(l->complex > r->complex) {
-			if(!vaddr(l, 0)) {
-				reglcgen(&nod1, l, Z);
-				l = &nod1;
-			}
-			if(m == SAgen) {
-				t = &nod2;
-				if(l->reg == D_CX) {
-					regalloc(t, r, Z);
-					gmove(l, t);
-					l->reg = t->reg;
-					t->reg = D_CX;
-				}
-				else
-					c = snarfreg(nn, t, D_CX, r, &nod3);
-				cgen(r, t);
-				r = t;
-			}
-		}
-		else {
-			if(m == SAgen) {
-				t = &nod2;
-				c = snarfreg(nn, t, D_CX, r, &nod3);
-				cgen(r, t);
-				r = t;
-			}
-			if(!vaddr(l, 0)) {
-				reglcgen(&nod1, l, Z);
-				l = &nod1;
-			}
-		}
-
-		if(nn != Z) {
-			m += SAdgen - SAgen;
-			d = regpair(nn, n);
-			instpair(d, Z);
-			biggen(l, r, d, 0, optab[m], args);
-			if(l == &nod1) {
-				regfree(&nod1);
-				l = Z;
-			}
-			if(r == &nod2 && c == Z) {
-				regfree(&nod2);
-				r = Z;
-			}
-			if(d != nn)
-				storepair(d, nn, 1);
-		}
-		else
-			biggen(l, r, Z, 0, optab[m], args);
-
-		if(c != Z) {
-			gins(AMOVL, c, r);
-			regfree(c);
-		}
-		if(l == &nod1)
-			regfree(&nod1);
-		if(r == &nod2)
-			regfree(&nod2);
-		return 1;
-
-	case OPOSTINC:
-		args = ADDargs;
-		cp = incdecpost;
-		goto vinc;
-	case OPOSTDEC:
-		args = SUBargs;
-		cp = incdecpost;
-		goto vinc;
-	case OPREINC:
-		args = ADDargs;
-		cp = incdecpre;
-		goto vinc;
-	case OPREDEC:
-		args = SUBargs;
-		cp = incdecpre;
-		goto vinc;
-
-	vinc:
-		l = n->left;
-		if(!vaddr(l, 1)) {
-			reglcgen(&nod1, l, Z);
-			l = &nod1;
-		}
-		
-		if(nn != Z) {
-			d = regpair(nn, n);
-			instpair(d, Z);
-			biggen(l, Z, d, 0, cp, args);
-			if(l == &nod1) {
-				regfree(&nod1);
-				l = Z;
-			}
-			if(d != nn)
-				storepair(d, nn, 1);
-		}
-		else
-			biggen(l, Z, Z, 0, incdec, args);
-
-		if(l == &nod1)
-			regfree(&nod1);
-		return 1;
-
-	case OCAST:
-		l = n->left;
-		if(typev[l->type->etype]) {
-			if(!vaddr(l, 1)) {
-				if(l->complex + 1 > nn->complex) {
-					d = regpair(Z, l);
-					sugen(l, d, 8);
-					if(!vaddr(nn, 1)) {
-						reglcgen(&nod1, nn, Z);
-						r = &nod1;
-					}
-					else
-						r = nn;
-				}
-				else {
-					if(!vaddr(nn, 1)) {
-						reglcgen(&nod1, nn, Z);
-						r = &nod1;
-					}
-					else
-						r = nn;
-					d = regpair(Z, l);
-					sugen(l, d, 8);
-				}
-//				d->left->type = r->type;
-				d->left->type = types[TLONG];
-				gmove(d->left, r);
-				freepair(d);
-			}
-			else {
-				if(nn->op != OREGISTER && !vaddr(nn, 1)) {
-					reglcgen(&nod1, nn, Z);
-					r = &nod1;
-				}
-				else
-					r = nn;
-//				l->type = r->type;
-				l->type = types[TLONG];
-				gmove(l, r);
-			}
-			if(r != nn)
-				regfree(r);
-		}
-		else {
-			if(typeu[l->type->etype] || cond(l->op))
-				si = TUNSIGNED;
-			else
-				si = TSIGNED;
-			regalloc(&nod1, l, Z);
-			cgen(l, &nod1);
-			if(nn->op == OREGPAIR) {
-				m = instpair(nn, &nod1);
-				biggen(&nod1, Z, nn, si == TSIGNED, castrp, nil);
-			}
-			else {
-				m = 0;
-				if(!vaddr(nn, si != TSIGNED)) {
-					dt = nn->type;
-					nn->type = types[TLONG];
-					reglcgen(&nod2, nn, Z);
-					nn->type = dt;
-					nn = &nod2;
-				}
-				dt = nn->type;
-				nn->type = types[TLONG];
-				biggen(&nod1, Z, nn, si == TSIGNED, castrpa, nil);
-				nn->type = dt;
-				if(nn == &nod2)
-					regfree(&nod2);
-			}
-			if(!m)
-				regfree(&nod1);
-		}
-		return 1;
-
-	default:
-		if(n->op == OREGPAIR) {
-			storepair(n, nn, 1);
-			return 1;
-		}
-		if(nn->op == OREGPAIR) {
-			loadpair(n, nn);
-			return 1;
-		}
-		return 0;
-	}
-finished:
-	if(d != nn)
-		storepair(d, nn, 1);
-	return 1;
-}
-
-void
-testv(Node *n, int true)
-{
-	Type *t;
-	Node *nn, nod, *b;
-
-	if(machcap(Z)) {
-		b = &nod;
-		b->op = true ? ONE : OEQ;
-		b->left = n;
-		b->right = new(0, Z, Z);
-		*b->right = *nodconst(0);
-		b->right->type = n->type;
-		b->type = types[TLONG];
-		cgen64(b, Z);
-		return;
-	}
-
-	switch(n->op) {
-	case OINDREG:
-	case ONAME:
-		biggen(n, Z, Z, true, testi, nil);
-		break;
-
-	default:
-		n = vfunc(n, n);
-		if(n->addable >= INDEXED) {
-			t = n->type;
-			n->type = types[TLONG];
-			reglcgen(&nod, n, Z);
-			n->type = t;
-			n = &nod;
-			biggen(n, Z, Z, true, testi, nil);
-			if(n == &nod)
-				regfree(n);
-		}
-		else {
-			nn = regpair(Z, n);
-			sugen(n, nn, 8);
-			biggen(nn, Z, Z, true, testi, nil);
-			freepair(nn);
-		}
-	}
-}

+ 0 - 215
sys/src/cmd/8c/div.c

@@ -1,215 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "gc.h"
-
-/*
- * Based on: Granlund, T.; Montgomery, P.L.
- * "Division by Invariant Integers using Multiplication".
- * SIGPLAN Notices, Vol. 29, June 1994, page 61.
- */
-
-#define	TN(n)	((uint64_t)1 << (n))
-#define	T31	TN(31)
-#define	T32	TN(32)
-
-int
-multiplier(uint32_t d, int p, uint64_t *mp)
-{
-	int l;
-	uint64_t mlo, mhi, tlo, thi;
-
-	l = topbit(d - 1) + 1;
-	mlo = (((TN(l) - d) << 32) / d) + T32;
-	if(l + p == 64)
-		mhi = (((TN(l) + 1 - d) << 32) / d) + T32;
-	else
-		mhi = (TN(32 + l) + TN(32 + l - p)) / d;
-	assert(mlo < mhi);
-	while(l > 0) {
-		tlo = mlo >> 1;
-		thi = mhi >> 1;
-		if(tlo == thi)
-			break;
-		mlo = tlo;
-		mhi = thi;
-		l--;
-	}
-	*mp = mhi;
-	return l;
-}
-
-int
-sdiv(uint32_t d, uint32_t *mp, int *sp)
-{
-	int s;
-	uint64_t m;
-
-	s = multiplier(d, 32 - 1, &m);
-	*mp = m;
-	*sp = s;
-	if(m >= T31)
-		return 1;
-	else
-		return 0;
-}
-
-int
-udiv(uint32_t d, uint32_t *mp, int *sp, int *pp)
-{
-	int p, s;
-	uint64_t m;
-
-	s = multiplier(d, 32, &m);
-	p = 0;
-	if(m >= T32) {
-		while((d & 1) == 0) {
-			d >>= 1;
-			p++;
-		}
-		s = multiplier(d, 32 - p, &m);
-	}
-	*mp = m;
-	*pp = p;
-	if(m >= T32) {
-		assert(p == 0);
-		*sp = s - 1;
-		return 1;
-	}
-	else {
-		*sp = s;
-		return 0;
-	}
-}
-
-void
-sdivgen(Node *l, Node *r, Node *ax, Node *dx)
-{
-	int a, s;
-	uint32_t m;
-	int64_t c;
-
-	c = r->vconst;
-	if(c < 0)
-		c = -c;
-	a = sdiv(c, &m, &s);
-//print("a=%d i=%ld s=%d m=%lux\n", a, (long)r->vconst, s, m);
-	gins(AMOVL, nodconst(m), ax);
-	gins(AIMULL, l, Z);
-	gins(AMOVL, l, ax);
-	if(a)
-		gins(AADDL, ax, dx);
-	gins(ASHRL, nodconst(31), ax);
-	gins(ASARL, nodconst(s), dx);
-	gins(AADDL, ax, dx);
-	if(r->vconst < 0)
-		gins(ANEGL, Z, dx);
-}
-
-void
-udivgen(Node *l, Node *r, Node *ax, Node *dx)
-{
-	int a, s, t;
-	uint32_t m;
-	Node nod;
-
-	a = udiv(r->vconst, &m, &s, &t);
-//print("a=%ud i=%ld p=%d s=%d m=%lux\n", a, (long)r->vconst, t, s, m);
-	if(t != 0) {
-		gins(AMOVL, l, ax);
-		gins(ASHRL, nodconst(t), ax);
-		gins(AMOVL, nodconst(m), dx);
-		gins(AMULL, dx, Z);
-	}
-	else if(a) {
-		if(l->op != OREGISTER) {
-			regalloc(&nod, l, Z);
-			gins(AMOVL, l, &nod);
-			l = &nod;
-		}
-		gins(AMOVL, nodconst(m), ax);
-		gins(AMULL, l, Z);
-		gins(AADDL, l, dx);
-		gins(ARCRL, nodconst(1), dx);
-		if(l == &nod)
-			regfree(l);
-	}
-	else {
-		gins(AMOVL, nodconst(m), ax);
-		gins(AMULL, l, Z);
-	}
-	if(s != 0)
-		gins(ASHRL, nodconst(s), dx);
-}
-
-void
-sext(Node *d, Node *s, Node *l)
-{
-	if(s->reg == D_AX && !nodreg(d, Z, D_DX)) {
-		reg[D_DX]++;
-		gins(ACDQ, Z, Z);
-	}
-	else {
-		regalloc(d, l, Z);
-		gins(AMOVL, s, d);
-		gins(ASARL, nodconst(31), d);
-	}
-}
-
-void
-sdiv2(int32_t c, int v, Node *l, Node *n)
-{
-	Node nod;
-
-	if(v > 0) {
-		if(v > 1) {
-			sext(&nod, n, l);
-			gins(AANDL, nodconst((1 << v) - 1), &nod);
-			gins(AADDL, &nod, n);
-			regfree(&nod);
-		}
-		else {
-			gins(ACMPL, n, nodconst(0x80000000));
-			gins(ASBBL, nodconst(-1), n);
-		}
-		gins(ASARL, nodconst(v), n);
-	}
-	if(c < 0)
-		gins(ANEGL, Z, n);
-}
-
-void
-smod2(int32_t c, int v, Node *l, Node *n)
-{
-	Node nod;
-
-	if(c == 1) {
-		zeroregm(n);
-		return;
-	}
-
-	sext(&nod, n, l);
-	if(v == 0) {
-		zeroregm(n);
-		gins(AXORL, &nod, n);
-		gins(ASUBL, &nod, n);
-	}
-	else if(v > 1) {
-		gins(AANDL, nodconst((1 << v) - 1), &nod);
-		gins(AADDL, &nod, n);
-		gins(AANDL, nodconst((1 << v) - 1), n);
-		gins(ASUBL, &nod, n);
-	}
-	else {
-		gins(AANDL, nodconst(1), n);
-		gins(AXORL, &nod, n);
-		gins(ASUBL, &nod, n);
-	}
-	regfree(&nod);
-}

+ 0 - 393
sys/src/cmd/8c/enam.c

@@ -1,393 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-char*	anames[] =
-{
-	"XXX",
-	"AAA",
-	"AAD",
-	"AAM",
-	"AAS",
-	"ADCB",
-	"ADCL",
-	"ADCW",
-	"ADDB",
-	"ADDL",
-	"ADDW",
-	"ADJSP",
-	"ANDB",
-	"ANDL",
-	"ANDW",
-	"ARPL",
-	"BOUNDL",
-	"BOUNDW",
-	"BSFL",
-	"BSFW",
-	"BSRL",
-	"BSRW",
-	"BTL",
-	"BTW",
-	"BTCL",
-	"BTCW",
-	"BTRL",
-	"BTRW",
-	"BTSL",
-	"BTSW",
-	"BYTE",
-	"CALL",
-	"CLC",
-	"CLD",
-	"CLI",
-	"CLTS",
-	"CMC",
-	"CMPB",
-	"CMPL",
-	"CMPW",
-	"CMPSB",
-	"CMPSL",
-	"CMPSW",
-	"DAA",
-	"DAS",
-	"DATA",
-	"DECB",
-	"DECL",
-	"DECW",
-	"DIVB",
-	"DIVL",
-	"DIVW",
-	"ENTER",
-	"GLOBL",
-	"GOK",
-	"HISTORY",
-	"HLT",
-	"IDIVB",
-	"IDIVL",
-	"IDIVW",
-	"IMULB",
-	"IMULL",
-	"IMULW",
-	"INB",
-	"INL",
-	"INW",
-	"INCB",
-	"INCL",
-	"INCW",
-	"INSB",
-	"INSL",
-	"INSW",
-	"INT",
-	"INTO",
-	"IRETL",
-	"IRETW",
-	"JCC",
-	"JCS",
-	"JCXZ",
-	"JEQ",
-	"JGE",
-	"JGT",
-	"JHI",
-	"JLE",
-	"JLS",
-	"JLT",
-	"JMI",
-	"JMP",
-	"JNE",
-	"JOC",
-	"JOS",
-	"JPC",
-	"JPL",
-	"JPS",
-	"LAHF",
-	"LARL",
-	"LARW",
-	"LEAL",
-	"LEAW",
-	"LEAVEL",
-	"LEAVEW",
-	"LOCK",
-	"LODSB",
-	"LODSL",
-	"LODSW",
-	"LONG",
-	"LOOP",
-	"LOOPEQ",
-	"LOOPNE",
-	"LSLL",
-	"LSLW",
-	"MOVB",
-	"MOVL",
-	"MOVW",
-	"MOVBLSX",
-	"MOVBLZX",
-	"MOVBWSX",
-	"MOVBWZX",
-	"MOVWLSX",
-	"MOVWLZX",
-	"MOVSB",
-	"MOVSL",
-	"MOVSW",
-	"MULB",
-	"MULL",
-	"MULW",
-	"NAME",
-	"NEGB",
-	"NEGL",
-	"NEGW",
-	"NOP",
-	"NOTB",
-	"NOTL",
-	"NOTW",
-	"ORB",
-	"ORL",
-	"ORW",
-	"OUTB",
-	"OUTL",
-	"OUTW",
-	"OUTSB",
-	"OUTSL",
-	"OUTSW",
-	"POPAL",
-	"POPAW",
-	"POPFL",
-	"POPFW",
-	"POPL",
-	"POPW",
-	"PUSHAL",
-	"PUSHAW",
-	"PUSHFL",
-	"PUSHFW",
-	"PUSHL",
-	"PUSHW",
-	"RCLB",
-	"RCLL",
-	"RCLW",
-	"RCRB",
-	"RCRL",
-	"RCRW",
-	"REP",
-	"REPN",
-	"RET",
-	"ROLB",
-	"ROLL",
-	"ROLW",
-	"RORB",
-	"RORL",
-	"RORW",
-	"SAHF",
-	"SALB",
-	"SALL",
-	"SALW",
-	"SARB",
-	"SARL",
-	"SARW",
-	"SBBB",
-	"SBBL",
-	"SBBW",
-	"SCASB",
-	"SCASL",
-	"SCASW",
-	"SETCC",
-	"SETCS",
-	"SETEQ",
-	"SETGE",
-	"SETGT",
-	"SETHI",
-	"SETLE",
-	"SETLS",
-	"SETLT",
-	"SETMI",
-	"SETNE",
-	"SETOC",
-	"SETOS",
-	"SETPC",
-	"SETPL",
-	"SETPS",
-	"CDQ",
-	"CWD",
-	"SHLB",
-	"SHLL",
-	"SHLW",
-	"SHRB",
-	"SHRL",
-	"SHRW",
-	"STC",
-	"STD",
-	"STI",
-	"STOSB",
-	"STOSL",
-	"STOSW",
-	"SUBB",
-	"SUBL",
-	"SUBW",
-	"SYSCALL",
-	"TESTB",
-	"TESTL",
-	"TESTW",
-	"TEXT",
-	"VERR",
-	"VERW",
-	"WAIT",
-	"WORD",
-	"XCHGB",
-	"XCHGL",
-	"XCHGW",
-	"XLAT",
-	"XORB",
-	"XORL",
-	"XORW",
-	"FMOVB",
-	"FMOVBP",
-	"FMOVD",
-	"FMOVDP",
-	"FMOVF",
-	"FMOVFP",
-	"FMOVL",
-	"FMOVLP",
-	"FMOVV",
-	"FMOVVP",
-	"FMOVW",
-	"FMOVWP",
-	"FMOVX",
-	"FMOVXP",
-	"FCOMB",
-	"FCOMBP",
-	"FCOMD",
-	"FCOMDP",
-	"FCOMDPP",
-	"FCOMF",
-	"FCOMFP",
-	"FCOML",
-	"FCOMLP",
-	"FCOMW",
-	"FCOMWP",
-	"FUCOM",
-	"FUCOMP",
-	"FUCOMPP",
-	"FADDDP",
-	"FADDW",
-	"FADDL",
-	"FADDF",
-	"FADDD",
-	"FMULDP",
-	"FMULW",
-	"FMULL",
-	"FMULF",
-	"FMULD",
-	"FSUBDP",
-	"FSUBW",
-	"FSUBL",
-	"FSUBF",
-	"FSUBD",
-	"FSUBRDP",
-	"FSUBRW",
-	"FSUBRL",
-	"FSUBRF",
-	"FSUBRD",
-	"FDIVDP",
-	"FDIVW",
-	"FDIVL",
-	"FDIVF",
-	"FDIVD",
-	"FDIVRDP",
-	"FDIVRW",
-	"FDIVRL",
-	"FDIVRF",
-	"FDIVRD",
-	"FXCHD",
-	"FFREE",
-	"FLDCW",
-	"FLDENV",
-	"FRSTOR",
-	"FSAVE",
-	"FSTCW",
-	"FSTENV",
-	"FSTSW",
-	"F2XM1",
-	"FABS",
-	"FCHS",
-	"FCLEX",
-	"FCOS",
-	"FDECSTP",
-	"FINCSTP",
-	"FINIT",
-	"FLD1",
-	"FLDL2E",
-	"FLDL2T",
-	"FLDLG2",
-	"FLDLN2",
-	"FLDPI",
-	"FLDZ",
-	"FNOP",
-	"FPATAN",
-	"FPREM",
-	"FPREM1",
-	"FPTAN",
-	"FRNDINT",
-	"FSCALE",
-	"FSIN",
-	"FSINCOS",
-	"FSQRT",
-	"FTST",
-	"FXAM",
-	"FXTRACT",
-	"FYL2X",
-	"FYL2XP1",
-	"END",
-	"DYNT",
-	"INIT",
-	"SIGNAME",
-	"FCOMI",
-	"FCOMIP",
-	"FUCOMI",
-	"FUCOMIP",
-	"CMPXCHGB",
-	"CMPXCHGL",
-	"CMPXCHGW",
-	"CMOVLCC",
-	"CMOVLCS",
-	"CMOVLEQ",
-	"CMOVLGE",
-	"CMOVLGT",
-	"CMOVLHI",
-	"CMOVLLE",
-	"CMOVLLS",
-	"CMOVLLT",
-	"CMOVLMI",
-	"CMOVLNE",
-	"CMOVLOC",
-	"CMOVLOS",
-	"CMOVLPC",
-	"CMOVLPL",
-	"CMOVLPS",
-	"CMOVWCC",
-	"CMOVWCS",
-	"CMOVWEQ",
-	"CMOVWGE",
-	"CMOVWGT",
-	"CMOVWHI",
-	"CMOVWLE",
-	"CMOVWLS",
-	"CMOVWLT",
-	"CMOVWMI",
-	"CMOVWNE",
-	"CMOVWOC",
-	"CMOVWOS",
-	"CMOVWPC",
-	"CMOVWPL",
-	"CMOVWPS",
-	"FCMOVCC",
-	"FCMOVCS",
-	"FCMOVEQ",
-	"FCMOVHI",
-	"FCMOVLS",
-	"FCMOVNE",
-	"FCMOVNU",
-	"FCMOVUN",
-	"LAST",
-};

+ 0 - 379
sys/src/cmd/8c/gc.h

@@ -1,379 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include	"../cc/cc.h"
-#include	"../8c/8.out.h"
-
-/*
- * 8c/386
- * Intel 386
- */
-#define	SZ_CHAR		1
-#define	SZ_SHORT	2
-#define	SZ_INT		4
-#define	SZ_LONG		4
-#define	SZ_IND		4
-#define	SZ_FLOAT	4
-#define	SZ_VLONG	8
-#define	SZ_DOUBLE	8
-#define	FNX		100
-
-typedef	struct	Adr	Adr;
-typedef	struct	Prog	Prog;
-typedef	struct	Case	Case;
-typedef	struct	C1	C1;
-typedef	struct	Var	Var;
-typedef	struct	Reg	Reg;
-typedef	struct	Rgn	Rgn;
-typedef	struct	Renv	Renv;
-
-EXTERN	struct
-{
-	Node*	regtree;
-	Node*	basetree;
-	short	scale;
-	short	reg;
-	short	ptr;
-} idx;
-
-struct	Adr
-{
-	long	offset;
-	double	dval;
-	char	sval[NSNAME];
-
-	Sym*	sym;
-	uchar	type;
-	uchar	index;
-	uchar	etype;
-	uchar	scale;	/* doubles as width in DATA op */
-};
-#define	A	((Adr*)0)
-
-#define	INDEXED	9
-struct	Prog
-{
-	Adr	from;
-	Adr	to;
-	Prog*	link;
-	long	lineno;
-	short	as;
-};
-#define	P	((Prog*)0)
-
-struct	Case
-{
-	Case*	link;
-	vlong	val;
-	long	label;
-	char	def;
-	char isv;
-};
-#define	C	((Case*)0)
-
-struct	C1
-{
-	vlong	val;
-	long	label;
-};
-
-struct	Var
-{
-	long	offset;
-	Sym*	sym;
-	char	name;
-	char	etype;
-};
-
-struct	Reg
-{
-	long	pc;
-	long	rpo;		/* reverse post ordering */
-
-	Bits	set;
-	Bits	use1;
-	Bits	use2;
-
-	Bits	refbehind;
-	Bits	refahead;
-	Bits	calbehind;
-	Bits	calahead;
-	Bits	regdiff;
-	Bits	act;
-
-	long	regu;
-	long	loop;		/* could be shorter */
-
-	Reg*	log5;
-	long	active;
-
-	Reg*	p1;
-	Reg*	p2;
-	Reg*	p2link;
-	Reg*	s1;
-	Reg*	s2;
-	Reg*	link;
-	Prog*	prog;
-};
-#define	R	((Reg*)0)
-
-struct	Renv
-{
-	int	safe;
-	Node	base;
-	Node*	saved;
-	Node*	scope;
-};
-
-#define	NRGN	600
-struct	Rgn
-{
-	Reg*	enter;
-	short	cost;
-	short	varno;
-	short	regno;
-};
-
-EXTERN	long	breakpc;
-EXTERN	long	nbreak;
-EXTERN	Case*	cases;
-EXTERN	Node	constnode;
-EXTERN	Node	fconstnode;
-EXTERN	long	continpc;
-EXTERN	long	curarg;
-EXTERN	long	cursafe;
-EXTERN	Prog*	firstp;
-EXTERN	Prog*	lastp;
-EXTERN	long	maxargsafe;
-EXTERN	int	mnstring;
-EXTERN	Node*	nodrat;
-EXTERN	Node*	nodret;
-EXTERN	Node*	nodsafe;
-EXTERN	long	nrathole;
-EXTERN	long	nstring;
-EXTERN	Prog*	p;
-EXTERN	long	pc;
-EXTERN	Node	regnode;
-EXTERN	Node	fregnode0;
-EXTERN	Node	fregnode1;
-EXTERN	char	string[NSNAME];
-EXTERN	Sym*	symrathole;
-EXTERN	Node	znode;
-EXTERN	Prog	zprog;
-EXTERN	int	reg[D_NONE];
-EXTERN	long	exregoffset;
-EXTERN	long	exfregoffset;
-
-#define	BLOAD(r)	band(bnot(r->refbehind), r->refahead)
-#define	BSTORE(r)	band(bnot(r->calbehind), r->calahead)
-#define	LOAD(r)		(~r->refbehind.b[z] & r->refahead.b[z])
-#define	STORE(r)	(~r->calbehind.b[z] & r->calahead.b[z])
-
-#define	bset(a,n)	((a).b[(n)/32]&(1L<<(n)%32))
-
-#define	CLOAD	5
-#define	CREF	5
-#define	CINF	1000
-#define	LOOP	3
-
-EXTERN	Rgn	region[NRGN];
-EXTERN	Rgn*	rgp;
-EXTERN	int	nregion;
-EXTERN	int	nvar;
-
-EXTERN	Bits	externs;
-EXTERN	Bits	params;
-EXTERN	Bits	consts;
-EXTERN	Bits	addrs;
-
-EXTERN	long	regbits;
-EXTERN	long	exregbits;
-
-EXTERN	int	change;
-EXTERN	int	suppress;
-
-EXTERN	Reg*	firstr;
-EXTERN	Reg*	lastr;
-EXTERN	Reg	zreg;
-EXTERN	Reg*	freer;
-EXTERN	Var	var[NVAR];
-EXTERN	long*	idom;
-EXTERN	Reg**	rpo2r;
-EXTERN	long	maxnr;
-
-extern	char*	anames[];
-
-/*
- * sgen.c
- */
-void	codgen(Node*, Node*);
-void	gen(Node*);
-void	noretval(int);
-void	usedset(Node*, int);
-void	xcom(Node*);
-void	indx(Node*);
-int	bcomplex(Node*, Node*);
-
-/*
- * cgen.c
- */
-void	zeroregm(Node*);
-void	cgen(Node*, Node*);
-void	reglcgen(Node*, Node*, Node*);
-void	lcgen(Node*, Node*);
-void	bcgen(Node*, int);
-void	boolgen(Node*, int, Node*);
-void	sugen(Node*, Node*, long);
-int	needreg(Node*, int);
-
-/*
- * cgen64.c
- */
-int	vaddr(Node*, int);
-void	loadpair(Node*, Node*);
-int	cgen64(Node*, Node*);
-void	testv(Node*, int);
-
-/*
- * txt.c
- */
-void	ginit(void);
-void	gclean(void);
-void	nextpc(void);
-void	gargs(Node*, Node*, Node*);
-void	garg1(Node*, Node*, Node*, int, Node**);
-Node*	nodconst(long);
-int	nareg(int);
-Node*	nodfconst(double);
-int	nodreg(Node*, Node*, int);
-int	isreg(Node*, int);
-void	regret(Node*, Node*);
-void	regalloc(Node*, Node*, Node*);
-void	regfree(Node*);
-void	regialloc(Node*, Node*, Node*);
-void	regsalloc(Node*, Node*);
-void	regaalloc1(Node*, Node*);
-void	regaalloc(Node*, Node*);
-void	regind(Node*, Node*);
-void	gprep(Node*, Node*);
-void	naddr(Node*, Adr*);
-void	gmove(Node*, Node*);
-void	gins(int a, Node*, Node*);
-void	fgopcode(int, Node*, Node*, int, int);
-void	gopcode(int, Type*, Node*, Node*);
-int	samaddr(Node*, Node*);
-void	gbranch(int);
-void	patch(Prog*, long);
-int	sconst(Node*);
-void	gpseudo(int, Sym*, Node*);
-
-/*
- * swt.c
- */
-int	swcmp(const void*, const void*);
-void	doswit(Node*);
-void	swit1(C1*, int, long, Node*);
-void	casf(void);
-void	bitload(Node*, Node*, Node*, Node*, Node*);
-void	bitstore(Node*, Node*, Node*, Node*, Node*);
-long	outstring(char*, long);
-void	nullwarn(Node*, Node*);
-void	gextern(Sym*, Node*, long, long);
-void	outcode(void);
-void	ieeedtod(Ieee*, double);
-
-/*
- * list
- */
-void	listinit(void);
-int	Pconv(Fmt*);
-int	Aconv(Fmt*);
-int	Dconv(Fmt*);
-int	Sconv(Fmt*);
-int	Rconv(Fmt*);
-int	Xconv(Fmt*);
-int	Bconv(Fmt*);
-
-/*
- * reg.c
- */
-Reg*	rega(void);
-int	rcmp(const void*, const void*);
-void	regopt(Prog*);
-void	addmove(Reg*, int, int, int);
-Bits	mkvar(Reg*, Adr*, int);
-void	prop(Reg*, Bits, Bits);
-void	loopit(Reg*, long);
-void	synch(Reg*, Bits);
-uint32_t	allreg(uint32_t, Rgn*);
-void	paint1(Reg*, int);
-uint32_t	paint2(Reg*, int);
-void	paint3(Reg*, int, long, int);
-void	addreg(Adr*, int);
-
-/*
- * peep.c
- */
-void	peep(void);
-void	excise(Reg*);
-Reg*	uniqp(Reg*);
-Reg*	uniqs(Reg*);
-int	regtyp(Adr*);
-int	anyvar(Adr*);
-int	subprop(Reg*);
-int	copyprop(Reg*);
-int	copy1(Adr*, Adr*, Reg*, int);
-int	copyu(Prog*, Adr*, Adr*);
-
-int	copyas(Adr*, Adr*);
-int	copyau(Adr*, Adr*);
-int	copysub(Adr*, Adr*, Adr*, int);
-int	copysub1(Prog*, Adr*, Adr*, int);
-
-long	RtoB(int);
-long	FtoB(int);
-int	BtoR(long);
-int	BtoF(long);
-
-#define	D_HI	D_NONE
-#define	D_LO	D_NONE
-
-/*
- * com64
- */
-int	cond(int);
-int	com64(Node*);
-void	com64init(void);
-void	bool64(Node*);
-long	lo64v(Node*);
-long	hi64v(Node*);
-Node*	lo64(Node*);
-Node*	hi64(Node*);
-
-/*
- * div/mul
- */
-void	sdivgen(Node*, Node*, Node*, Node*);
-void	udivgen(Node*, Node*, Node*, Node*);
-void	sdiv2(long, int, Node*, Node*);
-void	smod2(long, int, Node*, Node*);
-void	mulgen(Type*, Node*, Node*);
-void	genmuladd(Node*, Node*, int, Node*);
-void	shiftit(Type*, Node*, Node*);
-
-#pragma	varargck	type	"A"	int
-#pragma	varargck	type	"B"	Bits
-#pragma	varargck	type	"D"	Adr*
-#pragma	varargck	type	"P"	Prog*
-#pragma	varargck	type	"R"	int
-#pragma	varargck	type	"S"	char*
-
-/* wrecklessly steal a field */
-
-#define	rplink	label

+ 0 - 292
sys/src/cmd/8c/list.c

@@ -1,292 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#define EXTERN
-#include "gc.h"
-
-void
-listinit(void)
-{
-
-	fmtinstall('A', Aconv);
-	fmtinstall('B', Bconv);
-	fmtinstall('P', Pconv);
-	fmtinstall('S', Sconv);
-	fmtinstall('D', Dconv);
-	fmtinstall('R', Rconv);
-}
-
-int
-Bconv(Fmt *fp)
-{
-	char str[STRINGSZ], ss[STRINGSZ], *s;
-	Bits bits;
-	int i;
-
-	str[0] = 0;
-	bits = va_arg(fp->args, Bits);
-	while(bany(&bits)) {
-		i = bnum(bits);
-		if(str[0])
-			strcat(str, " ");
-		if(var[i].sym == S) {
-			snprint(ss, sizeof(ss), "$%ld", var[i].offset);
-			s = ss;
-		} else
-			s = var[i].sym->name;
-		if(strlen(str) + strlen(s) + 1 >= STRINGSZ)
-			break;
-		strcat(str, s);
-		bits.b[i/32] &= ~(1L << (i%32));
-	}
-	return fmtstrcpy(fp, str);
-}
-
-int
-Pconv(Fmt *fp)
-{
-	char str[STRINGSZ];
-	Prog *p;
-
-	p = va_arg(fp->args, Prog*);
-	if(p->as == ADATA)
-		snprint(str, sizeof(str), "	%A	%D/%d,%D",
-			p->as, &p->from, p->from.scale, &p->to);
-	else if(p->as == ATEXT)
-		snprint(str, sizeof(str), "	%A	%D,%d,%D",
-			p->as, &p->from, p->from.scale, &p->to);
-	else
-		snprint(str, sizeof(str), "	%A	%D,%D",
-			p->as, &p->from, &p->to);
-	return fmtstrcpy(fp, str);
-}
-
-int
-Aconv(Fmt *fp)
-{
-	int i;
-
-	i = va_arg(fp->args, int);
-	return fmtstrcpy(fp, anames[i]);
-}
-
-int
-Dconv(Fmt *fp)
-{
-	char str[40], s[20];
-	Adr *a;
-	int i;
-
-	a = va_arg(fp->args, Adr*);
-	i = a->type;
-	if(i >= D_INDIR) {
-		if(a->offset)
-			snprint(str, sizeof(str), "%ld(%R)", a->offset, i-D_INDIR);
-		else
-			snprint(str, sizeof(str), "(%R)", i-D_INDIR);
-		goto brk;
-	}
-	switch(i) {
-
-	default:
-		if(a->offset)
-			snprint(str, sizeof(str), "$%ld,%R", a->offset, i);
-		else
-			snprint(str, sizeof(str), "%R", i);
-		break;
-
-	case D_NONE:
-		str[0] = 0;
-		break;
-
-	case D_BRANCH:
-		snprint(str, sizeof(str), "%ld(PC)", a->offset-pc);
-		break;
-
-	case D_EXTERN:
-		snprint(str, sizeof(str), "%s+%ld(SB)", a->sym->name, a->offset);
-		break;
-
-	case D_STATIC:
-		snprint(str, sizeof(str), "%s<>+%ld(SB)", a->sym->name,
-			a->offset);
-		break;
-
-	case D_AUTO:
-		snprint(str, sizeof(str), "%s+%ld(SP)", a->sym->name, a->offset);
-		break;
-
-	case D_PARAM:
-		if(a->sym)
-			snprint(str, sizeof(str), "%s+%ld(FP)", a->sym->name, a->offset);
-		else
-			snprint(str, sizeof(str), "%ld(FP)", a->offset);
-		break;
-
-	case D_CONST:
-		snprint(str, sizeof(str), "$%ld", a->offset);
-		break;
-
-	case D_FCONST:
-		snprint(str, sizeof(str), "$(%.17e)", a->dval);
-		break;
-
-	case D_SCONST:
-		snprint(str, sizeof(str), "$\"%S\"", a->sval);
-		break;
-
-	case D_ADDR:
-		a->type = a->index;
-		a->index = D_NONE;
-		snprint(str, sizeof(str), "$%D", a);
-		a->index = a->type;
-		a->type = D_ADDR;
-		goto conv;
-	}
-brk:
-	if(a->index != D_NONE) {
-		fmtstrcpy(fp, str);
-		snprint(s, sizeof(s), "(%R*%d)", (int)a->index, (int)a->scale);
-		return fmtstrcpy(fp, s);
-	}
-conv:
-	return fmtstrcpy(fp, str);
-}
-
-char*	regstr[] =
-{
-	"AL",	/*[D_AL]*/	
-	"CL",
-	"DL",
-	"BL",
-	"AH",
-	"CH",
-	"DH",
-	"BH",
-
-	"AX",	/*[D_AX]*/
-	"CX",
-	"DX",
-	"BX",
-	"SP",
-	"BP",
-	"SI",
-	"DI",
-
-	"F0",	/*[D_F0]*/
-	"F1",
-	"F2",
-	"F3",
-	"F4",
-	"F5",
-	"F6",
-	"F7",
-
-	"CS",	/*[D_CS]*/
-	"SS",
-	"DS",
-	"ES",
-	"FS",
-	"GS",
-
-	"GDTR",	/*[D_GDTR]*/
-	"IDTR",	/*[D_IDTR]*/
-	"LDTR",	/*[D_LDTR]*/
-	"MSW",	/*[D_MSW] */
-	"TASK",	/*[D_TASK]*/
-
-	"CR0",	/*[D_CR]*/
-	"CR1",
-	"CR2",
-	"CR3",
-	"CR4",
-	"CR5",
-	"CR6",
-	"CR7",
-
-	"DR0",	/*[D_DR]*/
-	"DR1",
-	"DR2",
-	"DR3",
-	"DR4",
-	"DR5",
-	"DR6",
-	"DR7",
-
-	"TR0",	/*[D_TR]*/
-	"TR1",
-	"TR2",
-	"TR3",
-	"TR4",
-	"TR5",
-	"TR6",
-	"TR7",
-
-	"NONE",	/*[D_NONE]*/
-};
-
-int
-Rconv(Fmt *fp)
-{
-	char str[20];
-	int r;
-
-	r = va_arg(fp->args, int);
-	if(r >= D_AL && r <= D_NONE)
-		snprint(str, sizeof(str), "%s", regstr[r-D_AL]);
-	else
-		snprint(str, sizeof(str), "gok(%d)", r);
-
-	return fmtstrcpy(fp, str);
-}
-
-int
-Sconv(Fmt *fp)
-{
-	int i, c;
-	char str[30], *p, *a;
-
-	a = va_arg(fp->args, char*);
-	p = str;
-	for(i=0; i<sizeof(double); i++) {
-		c = a[i] & 0xff;
-		if(c >= 'a' && c <= 'z' ||
-		   c >= 'A' && c <= 'Z' ||
-		   c >= '0' && c <= '9') {
-			*p++ = c;
-			continue;
-		}
-		*p++ = '\\';
-		switch(c) {
-		default:
-			if(c < 040 || c >= 0177)
-				break;	/* not portable */
-			p[-1] = c;
-			continue;
-		case 0:
-			*p++ = 'z';
-			continue;
-		case '\\':
-		case '"':
-			*p++ = c;
-			continue;
-		case '\n':
-			*p++ = 'n';
-			continue;
-		case '\t':
-			*p++ = 't';
-			continue;
-		}
-		*p++ = (c>>6) + '0';
-		*p++ = ((c>>3) & 7) + '0';
-		*p++ = (c & 7) + '0';
-	}
-	*p = 0;
-	return fmtstrcpy(fp, str);
-}

+ 0 - 100
sys/src/cmd/8c/machcap.c

@@ -1,100 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "gc.h"
-
-int
-machcap(Node *n)
-{
-//	return 0;
-
-	if(n == Z)
-		return 1;	/* test */
-
-	switch(n->op) {
-	case OMUL:
-	case OLMUL:
-	case OASMUL:
-	case OASLMUL:
-		if(typechl[n->type->etype])
-			return 1;
-		if(typev[n->type->etype]) {
-//		if(typev[n->type->etype] && n->right->op == OCONST) {
-//			if(hi64v(n->right) == 0)
-				return 1;
-		}
-		break;
-
-	case OCOM:
-	case ONEG:
-	case OADD:
-	case OAND:
-	case OOR:
-	case OSUB:
-	case OXOR:
-	case OASHL:
-	case OLSHR:
-	case OASHR:
-		if(typechlv[n->left->type->etype])
-			return 1;
-		break;
-
-	case OCAST:
-		if(typev[n->type->etype]) {
-			if(typechlp[n->left->type->etype])
-				return 1;
-		}
-		else if(!typefd[n->type->etype]) {
-			if(typev[n->left->type->etype])
-				return 1;
-		}
-		break;
-
-	case OCOND:
-	case OCOMMA:
-	case OLIST:
-	case OANDAND:
-	case OOROR:
-	case ONOT:
-	case ODOT:
-		return 1;
-
-	case OASADD:
-	case OASSUB:
-	case OASAND:
-	case OASOR:
-	case OASXOR:
-		return 1;
-
-	case OASASHL:
-	case OASASHR:
-	case OASLSHR:
-		return 1;
-
-	case OPOSTINC:
-	case OPOSTDEC:
-	case OPREINC:
-	case OPREDEC:
-		return 1;
-
-	case OEQ:
-	case ONE:
-	case OLE:
-	case OGT:
-	case OLT:
-	case OGE:
-	case OHI:
-	case OHS:
-	case OLO:
-	case OLS:
-//print("%O\n", n->op);
-		return 1;
-	}
-	return 0;
-}

+ 0 - 15
sys/src/cmd/8c/mkenam

@@ -1,15 +0,0 @@
-ed - ../8c/8.out.h <<'!'
-v/^	A/d
-,s/^	A/	"/
-g/ .*$/s///
-,s/,*$/",/
-1i
-char*	anames[] =
-{
-.
-$a
-};
-.
-w enam.c
-Q
-!

+ 0 - 39
sys/src/cmd/8c/mkfile

@@ -1,39 +0,0 @@
-</$objtype/mkfile
-
-TARG=8c
-OFILES=\
-	cgen.$O\
-	cgen64.$O\
-	div.$O\
-	enam.$O\
-	list.$O\
-	machcap.$O\
-	mul.$O\
-	peep.$O\
-	pgen.$O\
-	pswt.$O\
-	reg.$O\
-	sgen.$O\
-	swt.$O\
-	txt.$O\
-
-HFILES=\
-	gc.h\
-	8.out.h\
-	../cc/cc.h\
-
-LIB=../cc/cc.a$O
-
-BIN=/$objtype/bin
-</sys/src/cmd/mkone
-
-$LIB:
-	cd ../cc
-	mk install
-	mk clean
-
-
-%.$O: ../cc/%.c
-	$CC $CFLAGS ../cc/$stem.c
-
-

+ 0 - 437
sys/src/cmd/8c/mul.c

@@ -1,437 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "gc.h"
-
-typedef struct	Malg	Malg;
-typedef struct	Mparam	Mparam;
-
-struct	Malg
-{
-	char	vals[10];
-};
-
-struct	Mparam
-{
-	uint32_t	value;
-	char	alg;
-	char	neg;
-	char	shift;
-	char	arg;
-	char	off;
-};
-
-static	Mparam	multab[32];
-static	int	mulptr;
-
-static	Malg	malgs[]	=
-{
-	{0, 100},
-	{-1, 1, 100},
-	{-9, -5, -3, 3, 5, 9, 100},
-	{6, 10, 12, 18, 20, 24, 36, 40, 72, 100},
-	{-8, -4, -2, 2, 4, 8, 100},
-};
-
-/*
- * return position of lowest 1
- */
-int
-lowbit(uint32_t v)
-{
-	int s, i;
-	uint32_t m;
-
-	s = 0;
-	m = 0xFFFFFFFFUL;
-	for(i = 16; i > 0; i >>= 1) {
-		m >>= i;
-		if((v & m) == 0) {
-			v >>= i;
-			s += i;
-		}
-	}
-	return s;
-}
-
-void
-genmuladd(Node *d, Node *s, int m, Node *a)
-{
-	Node nod;
-
-	nod.op = OINDEX;
-	nod.left = a;
-	nod.right = s;
-	nod.scale = m;
-	nod.type = types[TIND];
-	nod.xoffset = 0;
-	xcom(&nod);
-	gopcode(OADDR, d->type, &nod, d);
-}
-
-void
-mulparam(uint32_t m, Mparam *mp)
-{
-	int c, i, j, n, o, q, s;
-	int bc, bi, bn, bo, bq, bs, bt;
-	char *p;
-	int32_t u;
-	uint32_t t;
-
-	bc = bq = 10;
-	bi = bn = bo = bs = bt = 0;
-	for(i = 0; i < nelem(malgs); i++) {
-		for(p = malgs[i].vals, j = 0; (o = p[j]) < 100; j++)
-		for(s = 0; s < 2; s++) {
-			c = 10;
-			q = 10;
-			u = m - o;
-			if(u == 0)
-				continue;
-			if(s) {
-				o = -o;
-				if(o > 0)
-					continue;
-				u = -u;
-			}
-			n = lowbit(u);
-			t = (uint32_t)u >> n;
-			switch(i) {
-			case 0:
-				if(t == 1) {
-					c = s + 1;
-					q = 0;
-					break;
-				}
-				switch(t) {
-				case 3:
-				case 5:
-				case 9:
-					c = s + 1;
-					if(n)
-						c++;
-					q = 0;
-					break;
-				}
-				if(s)
-					break;
-				switch(t) {
-				case 15:
-				case 25:
-				case 27:
-				case 45:
-				case 81:
-					c = 2;
-					if(n)
-						c++;
-					q = 1;
-					break;
-				}
-				break;
-			case 1:
-				if(t == 1) {
-					c = 3;
-					q = 3;
-					break;
-				}
-				switch(t) {
-				case 3:
-				case 5:
-				case 9:
-					c = 3;
-					q = 2;
-					break;
-				}
-				break;
-			case 2:
-				if(t == 1) {
-					c = 3;
-					q = 2;
-					break;
-				}
-				break;
-			case 3:
-				if(s)
-					break;
-				if(t == 1) {
-					c = 3;
-					q = 1;
-					break;
-				}
-				break;
-			case 4:
-				if(t == 1) {
-					c = 3;
-					q = 0;
-					break;
-				}
-				break;
-			}
-			if(c < bc || (c == bc && q > bq)) {
-				bc = c;
-				bi = i;
-				bn = n;
-				bo = o;
-				bq = q;
-				bs = s;
-				bt = t;
-			}
-		}
-	}
-	mp->value = m;
-	if(bc <= 3) {
-		mp->alg = bi;
-		mp->shift = bn;
-		mp->off = bo;
-		mp->neg = bs;
-		mp->arg = bt;
-	}
-	else
-		mp->alg = -1;
-}
-
-int
-m0(int a)
-{
-	switch(a) {
-	case -2:
-	case 2:
-		return 2;
-	case -3:
-	case 3:
-		return 2;
-	case -4:
-	case 4:
-		return 4;
-	case -5:
-	case 5:
-		return 4;
-	case 6:
-		return 2;
-	case -8:
-	case 8:
-		return 8;
-	case -9:
-	case 9:
-		return 8;
-	case 10:
-		return 4;
-	case 12:
-		return 2;
-	case 15:
-		return 2;
-	case 18:
-		return 8;
-	case 20:
-		return 4;
-	case 24:
-		return 2;
-	case 25:
-		return 4;
-	case 27:
-		return 2;
-	case 36:
-		return 8;
-	case 40:
-		return 4;
-	case 45:
-		return 4;
-	case 72:
-		return 8;
-	case 81:
-		return 8;
-	}
-	diag(Z, "bad m0");
-	return 0;
-}
-
-int
-m1(int a)
-{
-	switch(a) {
-	case 15:
-		return 4;
-	case 25:
-		return 4;
-	case 27:
-		return 8;
-	case 45:
-		return 8;
-	case 81:
-		return 8;
-	}
-	diag(Z, "bad m1");
-	return 0;
-}
-
-int
-m2(int a)
-{
-	switch(a) {
-	case 6:
-		return 2;
-	case 10:
-		return 2;
-	case 12:
-		return 4;
-	case 18:
-		return 2;
-	case 20:
-		return 4;
-	case 24:
-		return 8;
-	case 36:
-		return 4;
-	case 40:
-		return 8;
-	case 72:
-		return 8;
-	}
-	diag(Z, "bad m2");
-	return 0;
-}
-
-void
-shiftit(Type *t, Node *s, Node *d)
-{
-	int32_t c;
-
-	c = (int32_t)s->vconst & 31;
-	switch(c) {
-	case 0:
-		break;
-	case 1:
-		gopcode(OADD, t, d, d);
-		break;
-	default:
-		gopcode(OASHL, t, s, d);
-	}
-}
-
-static int
-mulgen1(uint32_t v, Node *n)
-{
-	int i, o;
-	Mparam *p;
-	Node nod, nods;
-
-	for(i = 0; i < nelem(multab); i++) {
-		p = &multab[i];
-		if(p->value == v)
-			goto found;
-	}
-
-	p = &multab[mulptr];
-	if(++mulptr == nelem(multab))
-		mulptr = 0;
-
-	mulparam(v, p);
-
-found:
-//	print("v=%.lx a=%d n=%d s=%d g=%d o=%d \n", p->value, p->alg, p->neg, p->shift, p->arg, p->off);
-	if(p->alg < 0)
-		return 0;
-
-	nods = *nodconst(p->shift);
-
-	o = OADD;
-	if(p->alg > 0) {
-		regalloc(&nod, n, Z);
-		if(p->off < 0)
-			o = OSUB;
-	}
-
-	switch(p->alg) {
-	case 0:
-		switch(p->arg) {
-		case 1:
-			shiftit(n->type, &nods, n);
-			break;
-		case 15:
-		case 25:
-		case 27:
-		case 45:
-		case 81:
-			genmuladd(n, n, m1(p->arg), n);
-			/* fall thru */
-		case 3:
-		case 5:
-		case 9:
-			genmuladd(n, n, m0(p->arg), n);
-			shiftit(n->type, &nods, n);
-			break;
-		default:
-			goto bad;
-		}
-		if(p->neg == 1)
-			gins(ANEGL, Z, n);
-		break;
-	case 1:
-		switch(p->arg) {
-		case 1:
-			gmove(n, &nod);
-			shiftit(n->type, &nods, &nod);
-			break;
-		case 3:
-		case 5:
-		case 9:
-			genmuladd(&nod, n, m0(p->arg), n);
-			shiftit(n->type, &nods, &nod);
-			break;
-		default:
-			goto bad;
-		}
-		if(p->neg)
-			gopcode(o, n->type, &nod, n);
-		else {
-			gopcode(o, n->type, n, &nod);
-			gmove(&nod, n);
-		}
-		break;
-	case 2:
-		genmuladd(&nod, n, m0(p->off), n);
-		shiftit(n->type, &nods, n);
-		goto comop;
-	case 3:
-		genmuladd(&nod, n, m0(p->off), n);
-		shiftit(n->type, &nods, n);
-		genmuladd(n, &nod, m2(p->off), n);
-		break;
-	case 4:
-		genmuladd(&nod, n, m0(p->off), nodconst(0));
-		shiftit(n->type, &nods, n);
-		goto comop;
-	default:
-		diag(Z, "bad mul alg");
-		break;
-	comop:
-		if(p->neg) {
-			gopcode(o, n->type, n, &nod);
-			gmove(&nod, n);
-		}
-		else
-			gopcode(o, n->type, &nod, n);
-	}
-
-	if(p->alg > 0)
-		regfree(&nod);
-
-	return 1;
-
-bad:
-	diag(Z, "mulgen botch");
-	return 1;
-}
-
-void
-mulgen(Type *t, Node *r, Node *n)
-{
-	if(!mulgen1(r->vconst, n))
-		gopcode(OMUL, t, r, n);
-}

+ 0 - 780
sys/src/cmd/8c/peep.c

@@ -1,780 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "gc.h"
-
-static int
-needc(Prog *p)
-{
-	while(p != P) {
-		switch(p->as) {
-		case AADCL:
-		case ASBBL:
-		case ARCRL:
-			return 1;
-		case AADDL:
-		case ASUBL:
-		case AJMP:
-		case ARET:
-		case ACALL:
-			return 0;
-		default:
-			if(p->to.type == D_BRANCH)
-				return 0;
-		}
-		p = p->link;
-	}
-	return 0;
-}
-
-void
-peep(void)
-{
-	Reg *r, *r1, *r2;
-	Prog *p, *p1;
-	int t;
-
-	/*
-	 * complete R structure
-	 */
-	t = 0;
-	for(r=firstr; r!=R; r=r1) {
-		r1 = r->link;
-		if(r1 == R)
-			break;
-		p = r->prog->link;
-		while(p != r1->prog)
-		switch(p->as) {
-		default:
-			r2 = rega();
-			r->link = r2;
-			r2->link = r1;
-
-			r2->prog = p;
-			r2->p1 = r;
-			r->s1 = r2;
-			r2->s1 = r1;
-			r1->p1 = r2;
-
-			r = r2;
-			t++;
-
-		case ADATA:
-		case AGLOBL:
-		case ANAME:
-		case ASIGNAME:
-			p = p->link;
-		}
-	}
-
-	pc = 0;	/* speculating it won't kill */
-
-loop1:
-
-	t = 0;
-	for(r=firstr; r!=R; r=r->link) {
-		p = r->prog;
-		switch(p->as) {
-		case AMOVL:
-			if(regtyp(&p->to))
-			if(regtyp(&p->from)) {
-				if(copyprop(r)) {
-					excise(r);
-					t++;
-				}
-				if(subprop(r) && copyprop(r)) {
-					excise(r);
-					t++;
-				}
-			}
-			break;
-
-		case AMOVBLSX:
-		case AMOVBLZX:
-		case AMOVWLSX:
-		case AMOVWLZX:
-			if(regtyp(&p->to)) {
-				r1 = uniqs(r);
-				if(r1 != R) {
-					p1 = r1->prog;
-					if(p->as == p1->as && p->to.type == p1->from.type)
-						p1->as = AMOVL;
-				}
-			}
-			break;
-		case AADDL:
-		case AADDW:
-			if(p->from.type != D_CONST || needc(p->link))
-				break;
-			if(p->from.offset == -1){
-				if(p->as == AADDL)
-					p->as = ADECL;
-				else
-					p->as = ADECW;
-				p->from = zprog.from;
-			}
-			else if(p->from.offset == 1){
-				if(p->as == AADDL)
-					p->as = AINCL;
-				else
-					p->as = AINCW;
-				p->from = zprog.from;
-			}
-			break;
-		case ASUBL:
-		case ASUBW:
-			if(p->from.type != D_CONST || needc(p->link))
-				break;
-			if(p->from.offset == -1) {
-				if(p->as == ASUBL)
-					p->as = AINCL;
-				else
-					p->as = AINCW;
-				p->from = zprog.from;
-			}
-			else if(p->from.offset == 1){
-				if(p->as == ASUBL)
-					p->as = ADECL;
-				else
-					p->as = ADECW;
-				p->from = zprog.from;
-			}
-			break;
-		}
-	}
-	if(t)
-		goto loop1;
-}
-
-void
-excise(Reg *r)
-{
-	Prog *p;
-
-	p = r->prog;
-	p->as = ANOP;
-	p->from = zprog.from;
-	p->to = zprog.to;
-}
-
-Reg*
-uniqp(Reg *r)
-{
-	Reg *r1;
-
-	r1 = r->p1;
-	if(r1 == R) {
-		r1 = r->p2;
-		if(r1 == R || r1->p2link != R)
-			return R;
-	} else
-		if(r->p2 != R)
-			return R;
-	return r1;
-}
-
-Reg*
-uniqs(Reg *r)
-{
-	Reg *r1;
-
-	r1 = r->s1;
-	if(r1 == R) {
-		r1 = r->s2;
-		if(r1 == R)
-			return R;
-	} else
-		if(r->s2 != R)
-			return R;
-	return r1;
-}
-
-int
-regtyp(Adr *a)
-{
-	int t;
-
-	t = a->type;
-	if(t >= D_AX && t <= D_DI)
-		return 1;
-	return 0;
-}
-
-/*
- * the idea is to substitute
- * one register for another
- * from one MOV to another
- *	MOV	a, R0
- *	ADD	b, R0	/ no use of R1
- *	MOV	R0, R1
- * would be converted to
- *	MOV	a, R1
- *	ADD	b, R1
- *	MOV	R1, R0
- * hopefully, then the former or latter MOV
- * will be eliminated by copy propagation.
- */
-int
-subprop(Reg *r0)
-{
-	Prog *p;
-	Adr *v1, *v2;
-	Reg *r;
-	int t;
-
-	p = r0->prog;
-	v1 = &p->from;
-	if(!regtyp(v1))
-		return 0;
-	v2 = &p->to;
-	if(!regtyp(v2))
-		return 0;
-	for(r=uniqp(r0); r!=R; r=uniqp(r)) {
-		if(uniqs(r) == R)
-			break;
-		p = r->prog;
-		switch(p->as) {
-		case ACALL:
-			return 0;
-
-		case AIMULL:
-		case AIMULW:
-			if(p->to.type != D_NONE)
-				break;
-
-		case ADIVB:
-		case ADIVL:
-		case ADIVW:
-		case AIDIVB:
-		case AIDIVL:
-		case AIDIVW:
-		case AIMULB:
-		case AMULB:
-		case AMULL:
-		case AMULW:
-
-		case AROLB:
-		case AROLL:
-		case AROLW:
-		case ARORB:
-		case ARORL:
-		case ARORW:
-		case ASALB:
-		case ASALL:
-		case ASALW:
-		case ASARB:
-		case ASARL:
-		case ASARW:
-		case ASHLB:
-		case ASHLL:
-		case ASHLW:
-		case ASHRB:
-		case ASHRL:
-		case ASHRW:
-
-		case AREP:
-		case AREPN:
-
-		case ACWD:
-		case ACDQ:
-
-		case ASTOSB:
-		case ASTOSL:
-		case AMOVSB:
-		case AMOVSL:
-		case AFSTSW:
-			return 0;
-
-		case AMOVL:
-			if(p->to.type == v1->type)
-				goto gotit;
-			break;
-		}
-		if(copyau(&p->from, v2) ||
-		   copyau(&p->to, v2))
-			break;
-		if(copysub(&p->from, v1, v2, 0) ||
-		   copysub(&p->to, v1, v2, 0))
-			break;
-	}
-	return 0;
-
-gotit:
-	copysub(&p->to, v1, v2, 1);
-	if(debug['P']) {
-		print("gotit: %D->%D\n%P", v1, v2, r->prog);
-		if(p->from.type == v2->type)
-			print(" excise");
-		print("\n");
-	}
-	for(r=uniqs(r); r!=r0; r=uniqs(r)) {
-		p = r->prog;
-		copysub(&p->from, v1, v2, 1);
-		copysub(&p->to, v1, v2, 1);
-		if(debug['P'])
-			print("%P\n", r->prog);
-	}
-	t = v1->type;
-	v1->type = v2->type;
-	v2->type = t;
-	if(debug['P'])
-		print("%P last\n", r->prog);
-	return 1;
-}
-
-/*
- * The idea is to remove redundant copies.
- *	v1->v2	F=0
- *	(use v2	s/v2/v1/)*
- *	set v1	F=1
- *	use v2	return fail
- *	-----------------
- *	v1->v2	F=0
- *	(use v2	s/v2/v1/)*
- *	set v1	F=1
- *	set v2	return success
- */
-int
-copyprop(Reg *r0)
-{
-	Prog *p;
-	Adr *v1, *v2;
-	Reg *r;
-
-	p = r0->prog;
-	v1 = &p->from;
-	v2 = &p->to;
-	if(copyas(v1, v2))
-		return 1;
-	for(r=firstr; r!=R; r=r->link)
-		r->active = 0;
-	return copy1(v1, v2, r0->s1, 0);
-}
-
-int
-copy1(Adr *v1, Adr *v2, Reg *r, int f)
-{
-	int t;
-	Prog *p;
-
-	if(r->active) {
-		if(debug['P'])
-			print("act set; return 1\n");
-		return 1;
-	}
-	r->active = 1;
-	if(debug['P'])
-		print("copy %D->%D f=%d\n", v1, v2, f);
-	for(; r != R; r = r->s1) {
-		p = r->prog;
-		if(debug['P'])
-			print("%P", p);
-		if(!f && uniqp(r) == R) {
-			f = 1;
-			if(debug['P'])
-				print("; merge; f=%d", f);
-		}
-		t = copyu(p, v2, A);
-		switch(t) {
-		case 2:	/* rar, cant split */
-			if(debug['P'])
-				print("; %D rar; return 0\n", v2);
-			return 0;
-
-		case 3:	/* set */
-			if(debug['P'])
-				print("; %D set; return 1\n", v2);
-			return 1;
-
-		case 1:	/* used, substitute */
-		case 4:	/* use and set */
-			if(f) {
-				if(!debug['P'])
-					return 0;
-				if(t == 4)
-					print("; %D used+set and f=%d; return 0\n", v2, f);
-				else
-					print("; %D used and f=%d; return 0\n", v2, f);
-				return 0;
-			}
-			if(copyu(p, v2, v1)) {
-				if(debug['P'])
-					print("; sub fail; return 0\n");
-				return 0;
-			}
-			if(debug['P'])
-				print("; sub %D/%D", v2, v1);
-			if(t == 4) {
-				if(debug['P'])
-					print("; %D used+set; return 1\n", v2);
-				return 1;
-			}
-			break;
-		}
-		if(!f) {
-			t = copyu(p, v1, A);
-			if(!f && (t == 2 || t == 3 || t == 4)) {
-				f = 1;
-				if(debug['P'])
-					print("; %D set and !f; f=%d", v1, f);
-			}
-		}
-		if(debug['P'])
-			print("\n");
-		if(r->s2)
-			if(!copy1(v1, v2, r->s2, f))
-				return 0;
-	}
-	return 1;
-}
-
-/*
- * return
- * 1 if v only used (and substitute),
- * 2 if read-alter-rewrite
- * 3 if set
- * 4 if set and used
- * 0 otherwise (not touched)
- */
-int
-copyu(Prog *p, Adr *v, Adr *s)
-{
-
-	switch(p->as) {
-
-	default:
-		if(debug['P'])
-			print("unknown op %A\n", p->as);
-		return 2;
-
-	case ANEGB:
-	case ANEGW:
-	case ANEGL:
-	case ANOTB:
-	case ANOTW:
-	case ANOTL:
-		if(copyas(&p->to, v))
-			return 2;
-		break;
-
-	case ALEAL:	/* lhs addr, rhs store */
-		if(copyas(&p->from, v))
-			return 2;
-
-
-	case ANOP:	/* rhs store */
-	case AMOVL:
-	case AMOVBLSX:
-	case AMOVBLZX:
-	case AMOVWLSX:
-	case AMOVWLZX:
-		if(copyas(&p->to, v)) {
-			if(s != A)
-				return copysub(&p->from, v, s, 1);
-			if(copyau(&p->from, v))
-				return 4;
-			return 3;
-		}
-		goto caseread;
-
-	case AROLB:
-	case AROLL:
-	case AROLW:
-	case ARORB:
-	case ARORL:
-	case ARORW:
-	case ASALB:
-	case ASALL:
-	case ASALW:
-	case ASARB:
-	case ASARL:
-	case ASARW:
-	case ASHLB:
-	case ASHLL:
-	case ASHLW:
-	case ASHRB:
-	case ASHRL:
-	case ASHRW:
-		if(copyas(&p->to, v))
-			return 2;
-		if(copyas(&p->from, v))
-			if(p->from.type == D_CX)
-				return 2;
-		goto caseread;
-
-	case AADDB:	/* rhs rar */
-	case AADDL:
-	case AADDW:
-	case AANDB:
-	case AANDL:
-	case AANDW:
-	case ADECL:
-	case ADECW:
-	case AINCL:
-	case AINCW:
-	case ASUBB:
-	case ASUBL:
-	case ASUBW:
-	case AORB:
-	case AORL:
-	case AORW:
-	case AXORB:
-	case AXORL:
-	case AXORW:
-	case AMOVB:
-	case AMOVW:
-
-	case AFMOVB:
-	case AFMOVBP:
-	case AFMOVD:
-	case AFMOVDP:
-	case AFMOVF:
-	case AFMOVFP:
-	case AFMOVL:
-	case AFMOVLP:
-	case AFMOVV:
-	case AFMOVVP:
-	case AFMOVW:
-	case AFMOVWP:
-	case AFMOVX:
-	case AFMOVXP:
-	case AFADDDP:
-	case AFADDW:
-	case AFADDL:
-	case AFADDF:
-	case AFADDD:
-	case AFMULDP:
-	case AFMULW:
-	case AFMULL:
-	case AFMULF:
-	case AFMULD:
-	case AFSUBDP:
-	case AFSUBW:
-	case AFSUBL:
-	case AFSUBF:
-	case AFSUBD:
-	case AFSUBRDP:
-	case AFSUBRW:
-	case AFSUBRL:
-	case AFSUBRF:
-	case AFSUBRD:
-	case AFDIVDP:
-	case AFDIVW:
-	case AFDIVL:
-	case AFDIVF:
-	case AFDIVD:
-	case AFDIVRDP:
-	case AFDIVRW:
-	case AFDIVRL:
-	case AFDIVRF:
-	case AFDIVRD:
-		if(copyas(&p->to, v))
-			return 2;
-		goto caseread;
-
-	case ACMPL:	/* read only */
-	case ACMPW:
-	case ACMPB:
-
-	case AFCOMB:
-	case AFCOMBP:
-	case AFCOMD:
-	case AFCOMDP:
-	case AFCOMDPP:
-	case AFCOMF:
-	case AFCOMFP:
-	case AFCOML:
-	case AFCOMLP:
-	case AFCOMW:
-	case AFCOMWP:
-	case AFUCOM:
-	case AFUCOMP:
-	case AFUCOMPP:
-	caseread:
-		if(s != A) {
-			if(copysub(&p->from, v, s, 1))
-				return 1;
-			return copysub(&p->to, v, s, 1);
-		}
-		if(copyau(&p->from, v))
-			return 1;
-		if(copyau(&p->to, v))
-			return 1;
-		break;
-
-	case AJGE:	/* no reference */
-	case AJNE:
-	case AJLE:
-	case AJEQ:
-	case AJHI:
-	case AJLS:
-	case AJMI:
-	case AJPL:
-	case AJGT:
-	case AJLT:
-	case AJCC:
-	case AJCS:
-
-	case AADJSP:
-	case AFLDZ:
-	case AWAIT:
-		break;
-
-	case AIMULL:
-	case AIMULW:
-		if(p->to.type != D_NONE) {
-			if(copyas(&p->to, v))
-				return 2;
-			goto caseread;
-		}
-
-	case ADIVB:
-	case ADIVL:
-	case ADIVW:
-	case AIDIVB:
-	case AIDIVL:
-	case AIDIVW:
-	case AIMULB:
-	case AMULB:
-	case AMULL:
-	case AMULW:
-
-	case ACWD:
-	case ACDQ:
-		if(v->type == D_AX || v->type == D_DX)
-			return 2;
-		goto caseread;
-
-	case AREP:
-	case AREPN:
-		if(v->type == D_CX)
-			return 2;
-		goto caseread;
-
-	case AMOVSB:
-	case AMOVSL:
-		if(v->type == D_DI || v->type == D_SI)
-			return 2;
-		goto caseread;
-
-	case ASTOSB:
-	case ASTOSL:
-		if(v->type == D_AX || v->type == D_DI)
-			return 2;
-		goto caseread;
-
-	case AFSTSW:
-		if(v->type == D_AX)
-			return 2;
-		goto caseread;
-
-	case AJMP:	/* funny */
-		if(s != A) {
-			if(copysub(&p->to, v, s, 1))
-				return 1;
-			return 0;
-		}
-		if(copyau(&p->to, v))
-			return 1;
-		return 0;
-
-	case ARET:	/* funny */
-		if(v->type == REGRET)
-			return 2;
-		if(s != A)
-			return 1;
-		return 3;
-
-	case ACALL:	/* funny */
-		if(REGARG>=0 && v->type == REGARG)
-			return 2;
-
-		if(s != A) {
-			if(copysub(&p->to, v, s, 1))
-				return 1;
-			return 0;
-		}
-		if(copyau(&p->to, v))
-			return 4;
-		return 3;
-	}
-	return 0;
-}
-
-/*
- * direct reference,
- * could be set/use depending on
- * semantics
- */
-int
-copyas(Adr *a, Adr *v)
-{
-	if(a->type != v->type)
-		return 0;
-	if(regtyp(v))
-		return 1;
-	if(v->type == D_AUTO || v->type == D_PARAM)
-		if(v->offset == a->offset)
-			return 1;
-	return 0;
-}
-
-/*
- * either direct or indirect
- */
-int
-copyau(Adr *a, Adr *v)
-{
-
-	if(copyas(a, v))
-		return 1;
-	if(regtyp(v)) {
-		if(a->type-D_INDIR == v->type)
-			return 1;
-		if(a->index == v->type)
-			return 1;
-	}
-	return 0;
-}
-
-/*
- * substitute s for v in a
- * return failure to substitute
- */
-int
-copysub(Adr *a, Adr *v, Adr *s, int f)
-{
-	int t;
-
-	if(copyas(a, v)) {
-		t = s->type;
-		if(t >= D_AX && t <= D_DI) {
-			if(f)
-				a->type = t;
-		}
-		return 0;
-	}
-	if(regtyp(v)) {
-		t = v->type;
-		if(a->type == t+D_INDIR) {
-			if(s->type == D_BP && a->index != D_NONE)
-				return 1;	/* can't use BP-base with index */
-			if(f)
-				a->type = s->type+D_INDIR;
-//			return 0;
-		}
-		if(a->index == t) {
-			if(f)
-				a->index = s->type;
-			return 0;
-		}
-		return 0;
-	}
-	return 0;
-}

+ 0 - 1273
sys/src/cmd/8c/reg.c

@@ -1,1273 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "gc.h"
-
-Reg*
-rega(void)
-{
-	Reg *r;
-
-	r = freer;
-	if(r == R) {
-		r = alloc(sizeof(*r));
-	} else
-		freer = r->link;
-
-	*r = zreg;
-	return r;
-}
-
-int
-rcmp(const void *a1, const void *a2)
-{
-	Rgn *p1, *p2;
-	int c1, c2;
-
-	p1 = (Rgn*)a1;
-	p2 = (Rgn*)a2;
-	c1 = p2->cost;
-	c2 = p1->cost;
-	if(c1 -= c2)
-		return c1;
-	return p2->varno - p1->varno;
-}
-
-void
-regopt(Prog *p)
-{
-	Reg *r, *r1, *r2;
-	Prog *p1;
-	int i, z;
-	int32_t initpc, val, npc;
-	uint32_t vreg;
-	Bits bit;
-	struct
-	{
-		int32_t	m;
-		int32_t	c;
-		Reg*	p;
-	} log5[6], *lp;
-
-	firstr = R;
-	lastr = R;
-	nvar = 0;
-	regbits = RtoB(D_SP) | RtoB(D_AX);
-	for(z=0; z<BITS; z++) {
-		externs.b[z] = 0;
-		params.b[z] = 0;
-		consts.b[z] = 0;
-		addrs.b[z] = 0;
-	}
-
-	/*
-	 * pass 1
-	 * build aux data structure
-	 * allocate pcs
-	 * find use and set of variables
-	 */
-	val = 5L * 5L * 5L * 5L * 5L;
-	lp = log5;
-	for(i=0; i<5; i++) {
-		lp->m = val;
-		lp->c = 0;
-		lp->p = R;
-		val /= 5L;
-		lp++;
-	}
-	val = 0;
-	for(; p != P; p = p->link) {
-		switch(p->as) {
-		case ADATA:
-		case AGLOBL:
-		case ANAME:
-		case ASIGNAME:
-			continue;
-		}
-		r = rega();
-		if(firstr == R) {
-			firstr = r;
-			lastr = r;
-		} else {
-			lastr->link = r;
-			r->p1 = lastr;
-			lastr->s1 = r;
-			lastr = r;
-		}
-		r->prog = p;
-		r->pc = val;
-		val++;
-
-		lp = log5;
-		for(i=0; i<5; i++) {
-			lp->c--;
-			if(lp->c <= 0) {
-				lp->c = lp->m;
-				if(lp->p != R)
-					lp->p->log5 = r;
-				lp->p = r;
-				(lp+1)->c = 0;
-				break;
-			}
-			lp++;
-		}
-
-		r1 = r->p1;
-		if(r1 != R)
-		switch(r1->prog->as) {
-		case ARET:
-		case AJMP:
-		case AIRETL:
-			r->p1 = R;
-			r1->s1 = R;
-		}
-
-		bit = mkvar(r, &p->from, p->as==AMOVL);
-		if(bany(&bit))
-		switch(p->as) {
-		/*
-		 * funny
-		 */
-		case ALEAL:
-			for(z=0; z<BITS; z++)
-				addrs.b[z] |= bit.b[z];
-			break;
-
-		/*
-		 * left side read
-		 */
-		default:
-			for(z=0; z<BITS; z++)
-				r->use1.b[z] |= bit.b[z];
-			break;
-		}
-
-		bit = mkvar(r, &p->to, 0);
-		if(bany(&bit))
-		switch(p->as) {
-		default:
-			diag(Z, "reg: unknown op: %A", p->as);
-			break;
-
-		/*
-		 * right side read
-		 */
-		case ACMPB:
-		case ACMPL:
-		case ACMPW:
-			for(z=0; z<BITS; z++)
-				r->use2.b[z] |= bit.b[z];
-			break;
-
-		/*
-		 * right side write
-		 */
-		case ANOP:
-		case AMOVL:
-		case AMOVB:
-		case AMOVW:
-		case AMOVBLSX:
-		case AMOVBLZX:
-		case AMOVWLSX:
-		case AMOVWLZX:
-			for(z=0; z<BITS; z++)
-				r->set.b[z] |= bit.b[z];
-			break;
-
-		/*
-		 * right side read+write
-		 */
-		case AADDB:
-		case AADDL:
-		case AADDW:
-		case AANDB:
-		case AANDL:
-		case AANDW:
-		case ASUBB:
-		case ASUBL:
-		case ASUBW:
-		case AORB:
-		case AORL:
-		case AORW:
-		case AXORB:
-		case AXORL:
-		case AXORW:
-		case ASALB:
-		case ASALL:
-		case ASALW:
-		case ASARB:
-		case ASARL:
-		case ASARW:
-		case AROLB:
-		case AROLL:
-		case AROLW:
-		case ARORB:
-		case ARORL:
-		case ARORW:
-		case ASHLB:
-		case ASHLL:
-		case ASHLW:
-		case ASHRB:
-		case ASHRL:
-		case ASHRW:
-		case AIMULL:
-		case AIMULW:
-		case ANEGL:
-		case ANOTL:
-		case AADCL:
-		case ASBBL:
-			for(z=0; z<BITS; z++) {
-				r->set.b[z] |= bit.b[z];
-				r->use2.b[z] |= bit.b[z];
-			}
-			break;
-
-		/*
-		 * funny
-		 */
-		case AFMOVDP:
-		case AFMOVFP:
-		case AFMOVLP:
-		case AFMOVVP:
-		case AFMOVWP:
-		case ACALL:
-			for(z=0; z<BITS; z++)
-				addrs.b[z] |= bit.b[z];
-			break;
-		}
-
-		switch(p->as) {
-		case AIMULL:
-		case AIMULW:
-			if(p->to.type != D_NONE)
-				break;
-
-		case AIDIVB:
-		case AIDIVL:
-		case AIDIVW:
-		case AIMULB:
-		case ADIVB:
-		case ADIVL:
-		case ADIVW:
-		case AMULB:
-		case AMULL:
-		case AMULW:
-
-		case ACWD:
-		case ACDQ:
-			r->regu |= RtoB(D_AX) | RtoB(D_DX);
-			break;
-
-		case AREP:
-		case AREPN:
-		case ALOOP:
-		case ALOOPEQ:
-		case ALOOPNE:
-			r->regu |= RtoB(D_CX);
-			break;
-
-		case AMOVSB:
-		case AMOVSL:
-		case AMOVSW:
-		case ACMPSB:
-		case ACMPSL:
-		case ACMPSW:
-			r->regu |= RtoB(D_SI) | RtoB(D_DI);
-			break;
-
-		case ASTOSB:
-		case ASTOSL:
-		case ASTOSW:
-		case ASCASB:
-		case ASCASL:
-		case ASCASW:
-			r->regu |= RtoB(D_AX) | RtoB(D_DI);
-			break;
-
-		case AINSB:
-		case AINSL:
-		case AINSW:
-		case AOUTSB:
-		case AOUTSL:
-		case AOUTSW:
-			r->regu |= RtoB(D_DI) | RtoB(D_DX);
-			break;
-
-		case AFSTSW:
-		case ASAHF:
-			r->regu |= RtoB(D_AX);
-			break;
-		}
-	}
-	if(firstr == R)
-		return;
-	initpc = pc - val;
-	npc = val;
-
-	/*
-	 * pass 2
-	 * turn branch references to pointers
-	 * build back pointers
-	 */
-	for(r = firstr; r != R; r = r->link) {
-		p = r->prog;
-		if(p->to.type == D_BRANCH) {
-			val = p->to.offset - initpc;
-			r1 = firstr;
-			while(r1 != R) {
-				r2 = r1->log5;
-				if(r2 != R && val >= r2->pc) {
-					r1 = r2;
-					continue;
-				}
-				if(r1->pc == val)
-					break;
-				r1 = r1->link;
-			}
-			if(r1 == R) {
-				nearln = p->lineno;
-				diag(Z, "ref not found\n%P", p);
-				continue;
-			}
-			if(r1 == r) {
-				nearln = p->lineno;
-				diag(Z, "ref to self\n%P", p);
-				continue;
-			}
-			r->s2 = r1;
-			r->p2link = r1->p2;
-			r1->p2 = r;
-		}
-	}
-	if(debug['R']) {
-		p = firstr->prog;
-		print("\n%L %D\n", p->lineno, &p->from);
-	}
-
-	/*
-	 * pass 2.5
-	 * find looping structure
-	 */
-	for(r = firstr; r != R; r = r->link)
-		r->active = 0;
-	change = 0;
-	loopit(firstr, npc);
-	if(debug['R'] && debug['v']) {
-		print("\nlooping structure:\n");
-		for(r = firstr; r != R; r = r->link) {
-			print("%ld:%P", r->loop, r->prog);
-			for(z=0; z<BITS; z++)
-				bit.b[z] = r->use1.b[z] |
-					   r->use2.b[z] |
-					   r->set.b[z];
-			if(bany(&bit)) {
-				print("\t");
-				if(bany(&r->use1))
-					print(" u1=%B", r->use1);
-				if(bany(&r->use2))
-					print(" u2=%B", r->use2);
-				if(bany(&r->set))
-					print(" st=%B", r->set);
-			}
-			print("\n");
-		}
-	}
-
-	/*
-	 * pass 3
-	 * iterate propagating usage
-	 * 	back until flow graph is complete
-	 */
-loop1:
-	change = 0;
-	for(r = firstr; r != R; r = r->link)
-		r->active = 0;
-	for(r = firstr; r != R; r = r->link)
-		if(r->prog->as == ARET)
-			prop(r, zbits, zbits);
-loop11:
-	/* pick up unreachable code */
-	i = 0;
-	for(r = firstr; r != R; r = r1) {
-		r1 = r->link;
-		if(r1 && r1->active && !r->active) {
-			prop(r, zbits, zbits);
-			i = 1;
-		}
-	}
-	if(i)
-		goto loop11;
-	if(change)
-		goto loop1;
-
-
-	/*
-	 * pass 4
-	 * iterate propagating register/variable synchrony
-	 * 	forward until graph is complete
-	 */
-loop2:
-	change = 0;
-	for(r = firstr; r != R; r = r->link)
-		r->active = 0;
-	synch(firstr, zbits);
-	if(change)
-		goto loop2;
-
-
-	/*
-	 * pass 5
-	 * isolate regions
-	 * calculate costs (paint1)
-	 */
-	r = firstr;
-	if(r) {
-		for(z=0; z<BITS; z++)
-			bit.b[z] = (r->refahead.b[z] | r->calahead.b[z]) &
-			  ~(externs.b[z] | params.b[z] | addrs.b[z] | consts.b[z]);
-		if(bany(&bit)) {
-			nearln = r->prog->lineno;
-			warn(Z, "used and not set: %B", bit);
-			if(debug['R'] && !debug['w'])
-				print("used and not set: %B\n", bit);
-		}
-	}
-	if(debug['R'] && debug['v'])
-		print("\nprop structure:\n");
-	for(r = firstr; r != R; r = r->link)
-		r->act = zbits;
-	rgp = region;
-	nregion = 0;
-	for(r = firstr; r != R; r = r->link) {
-		if(debug['R'] && debug['v']) {
-			print("%P\t", r->prog);
-			if(bany(&r->set))
-				print("s:%B ", r->set);
-			if(bany(&r->refahead))
-				print("ra:%B ", r->refahead);
-			if(bany(&r->calahead))
-				print("ca:%B ", r->calahead);
-			print("\n");
-		}
-		for(z=0; z<BITS; z++)
-			bit.b[z] = r->set.b[z] &
-			  ~(r->refahead.b[z] | r->calahead.b[z] | addrs.b[z]);
-		if(bany(&bit)) {
-			nearln = r->prog->lineno;
-			warn(Z, "set and not used: %B", bit);
-			if(debug['R'])
-				print("set and not used: %B\n", bit);
-			excise(r);
-		}
-		for(z=0; z<BITS; z++)
-			bit.b[z] = LOAD(r) & ~(r->act.b[z] | addrs.b[z]);
-		while(bany(&bit)) {
-			i = bnum(bit);
-			rgp->enter = r;
-			rgp->varno = i;
-			change = 0;
-			if(debug['R'] && debug['v'])
-				print("\n");
-			paint1(r, i);
-			bit.b[i/32] &= ~(1L<<(i%32));
-			if(change <= 0) {
-				if(debug['R'])
-					print("%L$%d: %B\n",
-						r->prog->lineno, change, blsh(i));
-				continue;
-			}
-			rgp->cost = change;
-			nregion++;
-			if(nregion >= NRGN) {
-				warn(Z, "too many regions");
-				goto brk;
-			}
-			rgp++;
-		}
-	}
-brk:
-	qsort(region, nregion, sizeof(region[0]), rcmp);
-
-	/*
-	 * pass 6
-	 * determine used registers (paint2)
-	 * replace code (paint3)
-	 */
-	rgp = region;
-	for(i=0; i<nregion; i++) {
-		bit = blsh(rgp->varno);
-		vreg = paint2(rgp->enter, rgp->varno);
-		vreg = allreg(vreg, rgp);
-		if(debug['R']) {
-			print("%L$%d %R: %B\n",
-				rgp->enter->prog->lineno,
-				rgp->cost,
-				rgp->regno,
-				bit);
-		}
-		if(rgp->regno != 0)
-			paint3(rgp->enter, rgp->varno, vreg, rgp->regno);
-		rgp++;
-	}
-	/*
-	 * pass 7
-	 * peep-hole on basic block
-	 */
-	if(!debug['R'] || debug['P'])
-		peep();
-
-	/*
-	 * pass 8
-	 * recalculate pc
-	 */
-	val = initpc;
-	for(r = firstr; r != R; r = r1) {
-		r->pc = val;
-		p = r->prog;
-		p1 = P;
-		r1 = r->link;
-		if(r1 != R)
-			p1 = r1->prog;
-		for(; p != p1; p = p->link) {
-			switch(p->as) {
-			default:
-				val++;
-				break;
-
-			case ANOP:
-			case ADATA:
-			case AGLOBL:
-			case ANAME:
-			case ASIGNAME:
-				break;
-			}
-		}
-	}
-	pc = val;
-
-	/*
-	 * fix up branches
-	 */
-	if(debug['R'])
-		if(bany(&addrs))
-			print("addrs: %B\n", addrs);
-
-	r1 = 0; /* set */
-	for(r = firstr; r != R; r = r->link) {
-		p = r->prog;
-		if(p->to.type == D_BRANCH)
-			p->to.offset = r->s2->pc;
-		r1 = r;
-	}
-
-	/*
-	 * last pass
-	 * eliminate nops
-	 * free aux structures
-	 */
-	for(p = firstr->prog; p != P; p = p->link){
-		while(p->link && p->link->as == ANOP)
-			p->link = p->link->link;
-	}
-	if(r1 != R) {
-		r1->link = freer;
-		freer = firstr;
-	}
-}
-
-/*
- * add mov b,rn
- * just after r
- */
-void
-addmove(Reg *r, int bn, int rn, int f)
-{
-	Prog *p, *p1;
-	Adr *a;
-	Var *v;
-
-	p1 = alloc(sizeof(*p1));
-	*p1 = zprog;
-	p = r->prog;
-
-	p1->link = p->link;
-	p->link = p1;
-	p1->lineno = p->lineno;
-
-	v = var + bn;
-
-	a = &p1->to;
-	a->sym = v->sym;
-	a->offset = v->offset;
-	a->etype = v->etype;
-	a->type = v->name;
-
-	p1->as = AMOVL;
-	if(v->etype == TCHAR || v->etype == TUCHAR)
-		p1->as = AMOVB;
-	if(v->etype == TSHORT || v->etype == TUSHORT)
-		p1->as = AMOVW;
-
-	p1->from.type = rn;
-	if(!f) {
-		p1->from = *a;
-		*a = zprog.from;
-		a->type = rn;
-		if(v->etype == TUCHAR)
-			p1->as = AMOVB;
-		if(v->etype == TUSHORT)
-			p1->as = AMOVW;
-	}
-	if(debug['R'])
-		print("%P\t.a%P\n", p, p1);
-}
-
-uint32_t
-doregbits(int r)
-{
-	uint32_t b;
-
-	b = 0;
-	if(r >= D_INDIR)
-		r -= D_INDIR;
-	if(r >= D_AX && r <= D_DI)
-		b |= RtoB(r);
-	else
-	if(r >= D_AL && r <= D_BL)
-		b |= RtoB(r-D_AL+D_AX);
-	else
-	if(r >= D_AH && r <= D_BH)
-		b |= RtoB(r-D_AH+D_AX);
-	return b;
-}
-
-Bits
-mkvar(Reg *r, Adr *a, int isro)
-{
-	Var *v;
-	int i, t, n, et, z;
-	int32_t o;
-	Bits bit;
-	Sym *s;
-
-	/*
-	 * mark registers used
-	 */
-	t = a->type;
-	r->regu |= doregbits(t);
-	r->regu |= doregbits(a->index);
-	et = a->etype;
-
-	switch(t) {
-	default:
-		goto none;
-	case D_INDIR+D_GS:
-		if(!isro || 1)
-			goto none;
-		n = t;
-		{static Sym er; a->sym = &er;}
-		a->sym->name = "$extreg";
-		break;
-	case D_ADDR:
-		a->type = a->index;
-		bit = mkvar(r, a, 0);
-		for(z=0; z<BITS; z++)
-			addrs.b[z] |= bit.b[z];
-		a->type = t;
-		goto none;
-	case D_EXTERN:
-	case D_STATIC:
-	case D_PARAM:
-	case D_AUTO:
-		n = t;
-		break;
-	}
-	s = a->sym;
-	if(s == S)
-		goto none;
-	if(s->name[0] == '.')
-		goto none;
-	o = a->offset;
-	v = var;
-	for(i=0; i<nvar; i++) {
-		if(s == v->sym)
-		if(n == v->name)
-		if(o == v->offset)
-			goto out;
-		v++;
-	}
-	if(nvar >= NVAR) {
-		if(debug['w'] > 1 && s)
-			warn(Z, "variable not optimized: %s", s->name);
-		goto none;
-	}
-	i = nvar;
-	nvar++;
-	v = &var[i];
-	v->sym = s;
-	v->offset = o;
-	v->name = n;
-	v->etype = et;
-	if(debug['R'])
-		print("bit=%2d et=%2d %D\n", i, et, a);
-
-out:
-	bit = blsh(i);
-	if(n == D_EXTERN || n == D_STATIC)
-		for(z=0; z<BITS; z++)
-			externs.b[z] |= bit.b[z];
-	if(n == D_PARAM)
-		for(z=0; z<BITS; z++)
-			params.b[z] |= bit.b[z];
-	if(v->etype != et || !typechlpfd[et])	/* funny punning */
-		for(z=0; z<BITS; z++)
-			addrs.b[z] |= bit.b[z];
-	return bit;
-
-none:
-	return zbits;
-}
-
-void
-prop(Reg *r, Bits ref, Bits cal)
-{
-	Reg *r1, *r2;
-	int z;
-
-	for(r1 = r; r1 != R; r1 = r1->p1) {
-		for(z=0; z<BITS; z++) {
-			ref.b[z] |= r1->refahead.b[z];
-			if(ref.b[z] != r1->refahead.b[z]) {
-				r1->refahead.b[z] = ref.b[z];
-				change++;
-			}
-			cal.b[z] |= r1->calahead.b[z];
-			if(cal.b[z] != r1->calahead.b[z]) {
-				r1->calahead.b[z] = cal.b[z];
-				change++;
-			}
-		}
-		switch(r1->prog->as) {
-		case ACALL:
-			for(z=0; z<BITS; z++) {
-				cal.b[z] |= ref.b[z] | externs.b[z];
-				ref.b[z] = 0;
-			}
-			break;
-
-		case ATEXT:
-			for(z=0; z<BITS; z++) {
-				cal.b[z] = 0;
-				ref.b[z] = 0;
-			}
-			break;
-
-		case ARET:
-			for(z=0; z<BITS; z++) {
-				cal.b[z] = externs.b[z];
-				ref.b[z] = 0;
-			}
-		}
-		for(z=0; z<BITS; z++) {
-			ref.b[z] = (ref.b[z] & ~r1->set.b[z]) |
-				r1->use1.b[z] | r1->use2.b[z];
-			cal.b[z] &= ~(r1->set.b[z] | r1->use1.b[z] | r1->use2.b[z]);
-			r1->refbehind.b[z] = ref.b[z];
-			r1->calbehind.b[z] = cal.b[z];
-		}
-		if(r1->active)
-			break;
-		r1->active = 1;
-	}
-	for(; r != r1; r = r->p1)
-		for(r2 = r->p2; r2 != R; r2 = r2->p2link)
-			prop(r2, r->refbehind, r->calbehind);
-}
-
-/*
- * find looping structure
- *
- * 1) find reverse postordering
- * 2) find approximate dominators,
- *	the actual dominators if the flow graph is reducible
- *	otherwise, dominators plus some other non-dominators.
- *	See Matthew S. Hecht and Jeffrey D. Ullman,
- *	"Analysis of a Simple Algorithm for Global Data Flow Problems",
- *	Conf.  Record of ACM Symp. on Principles of Prog. Langs, Boston, Massachusetts,
- *	Oct. 1-3, 1973, pp.  207-217.
- * 3) find all nodes with a predecessor dominated by the current node.
- *	such a node is a loop head.
- *	recursively, all preds with a greater rpo number are in the loop
- */
-int32_t
-postorder(Reg *r, Reg **rpo2r, int32_t n)
-{
-	Reg *r1;
-
-	r->rpo = 1;
-	r1 = r->s1;
-	if(r1 && !r1->rpo)
-		n = postorder(r1, rpo2r, n);
-	r1 = r->s2;
-	if(r1 && !r1->rpo)
-		n = postorder(r1, rpo2r, n);
-	rpo2r[n] = r;
-	n++;
-	return n;
-}
-
-int32_t
-rpolca(int32_t *idom, int32_t rpo1, int32_t rpo2)
-{
-	int32_t t;
-
-	if(rpo1 == -1)
-		return rpo2;
-	while(rpo1 != rpo2){
-		if(rpo1 > rpo2){
-			t = rpo2;
-			rpo2 = rpo1;
-			rpo1 = t;
-		}
-		while(rpo1 < rpo2){
-			t = idom[rpo2];
-			if(t >= rpo2)
-				fatal(Z, "bad idom");
-			rpo2 = t;
-		}
-	}
-	return rpo1;
-}
-
-int
-doms(int32_t *idom, int32_t r, int32_t s)
-{
-	while(s > r)
-		s = idom[s];
-	return s == r;
-}
-
-int
-loophead(int32_t *idom, Reg *r)
-{
-	int32_t src;
-
-	src = r->rpo;
-	if(r->p1 != R && doms(idom, src, r->p1->rpo))
-		return 1;
-	for(r = r->p2; r != R; r = r->p2link)
-		if(doms(idom, src, r->rpo))
-			return 1;
-	return 0;
-}
-
-void
-loopmark(Reg **rpo2r, int32_t head, Reg *r)
-{
-	if(r->rpo < head || r->active == head)
-		return;
-	r->active = head;
-	r->loop += LOOP;
-	if(r->p1 != R)
-		loopmark(rpo2r, head, r->p1);
-	for(r = r->p2; r != R; r = r->p2link)
-		loopmark(rpo2r, head, r);
-}
-
-void
-loopit(Reg *r, int32_t nr)
-{
-	Reg *r1;
-	int32_t i, d, me;
-
-	if(nr > maxnr) {
-		rpo2r = alloc(nr * sizeof(Reg*));
-		idom = alloc(nr * sizeof(int32_t));
-		maxnr = nr;
-	}
-
-	d = postorder(r, rpo2r, 0);
-	if(d > nr)
-		fatal(Z, "too many reg nodes");
-	nr = d;
-	for(i = 0; i < nr / 2; i++){
-		r1 = rpo2r[i];
-		rpo2r[i] = rpo2r[nr - 1 - i];
-		rpo2r[nr - 1 - i] = r1;
-	}
-	for(i = 0; i < nr; i++)
-		rpo2r[i]->rpo = i;
-
-	idom[0] = 0;
-	for(i = 0; i < nr; i++){
-		r1 = rpo2r[i];
-		me = r1->rpo;
-		d = -1;
-		if(r1->p1 != R && r1->p1->rpo < me)
-			d = r1->p1->rpo;
-		for(r1 = r1->p2; r1 != nil; r1 = r1->p2link)
-			if(r1->rpo < me)
-				d = rpolca(idom, d, r1->rpo);
-		idom[i] = d;
-	}
-
-	for(i = 0; i < nr; i++){
-		r1 = rpo2r[i];
-		r1->loop++;
-		if(r1->p2 != R && loophead(idom, r1))
-			loopmark(rpo2r, i, r1);
-	}
-}
-
-void
-synch(Reg *r, Bits dif)
-{
-	Reg *r1;
-	int z;
-
-	for(r1 = r; r1 != R; r1 = r1->s1) {
-		for(z=0; z<BITS; z++) {
-			dif.b[z] = (dif.b[z] &
-				~(~r1->refbehind.b[z] & r1->refahead.b[z])) |
-					r1->set.b[z] | r1->regdiff.b[z];
-			if(dif.b[z] != r1->regdiff.b[z]) {
-				r1->regdiff.b[z] = dif.b[z];
-				change++;
-			}
-		}
-		if(r1->active)
-			break;
-		r1->active = 1;
-		for(z=0; z<BITS; z++)
-			dif.b[z] &= ~(~r1->calbehind.b[z] & r1->calahead.b[z]);
-		if(r1->s2 != R)
-			synch(r1->s2, dif);
-	}
-}
-
-uint32_t
-allreg(uint32_t b, Rgn *r)
-{
-	Var *v;
-	int i;
-
-	v = var + r->varno;
-	r->regno = 0;
-	switch(v->etype) {
-
-	default:
-		diag(Z, "unknown etype %d/%d", bitno(b), v->etype);
-		break;
-
-	case TCHAR:
-	case TUCHAR:
-	case TSHORT:
-	case TUSHORT:
-	case TINT:
-	case TUINT:
-	case TLONG:
-	case TULONG:
-	case TIND:
-	case TARRAY:
-		i = BtoR(~b);
-		if(i && r->cost > 0) {
-			r->regno = i;
-			return RtoB(i);
-		}
-		break;
-
-	case TDOUBLE:
-	case TFLOAT:
-		break;
-	}
-	return 0;
-}
-
-void
-paint1(Reg *r, int bn)
-{
-	Reg *r1;
-	Prog *p;
-	int z;
-	uint32_t bb;
-
-	z = bn/32;
-	bb = 1L<<(bn%32);
-	if(r->act.b[z] & bb)
-		return;
-	for(;;) {
-		if(!(r->refbehind.b[z] & bb))
-			break;
-		r1 = r->p1;
-		if(r1 == R)
-			break;
-		if(!(r1->refahead.b[z] & bb))
-			break;
-		if(r1->act.b[z] & bb)
-			break;
-		r = r1;
-	}
-
-	if(LOAD(r) & ~(r->set.b[z]&~(r->use1.b[z]|r->use2.b[z])) & bb) {
-		change -= CLOAD * r->loop;
-		if(debug['R'] && debug['v'])
-			print("%ld%P\tld %B $%d\n", r->loop,
-				r->prog, blsh(bn), change);
-	}
-	for(;;) {
-		r->act.b[z] |= bb;
-		p = r->prog;
-
-		if(r->use1.b[z] & bb) {
-			change += CREF * r->loop;
-			if(p->as == AFMOVL || p->as == AFMOVW)
-				if(BtoR(bb) != D_F0)
-					change = -CINF;
-			if(debug['R'] && debug['v'])
-				print("%ld%P\tu1 %B $%d\n", r->loop,
-					p, blsh(bn), change);
-		}
-
-		if((r->use2.b[z]|r->set.b[z]) & bb) {
-			change += CREF * r->loop;
-			if(p->as == AFMOVL || p->as == AFMOVW)
-				if(BtoR(bb) != D_F0)
-					change = -CINF;
-			if(debug['R'] && debug['v'])
-				print("%ld%P\tu2 %B $%d\n", r->loop,
-					p, blsh(bn), change);
-		}
-
-		if(STORE(r) & r->regdiff.b[z] & bb) {
-			change -= CLOAD * r->loop;
-			if(p->as == AFMOVL || p->as == AFMOVW)
-				if(BtoR(bb) != D_F0)
-					change = -CINF;
-			if(debug['R'] && debug['v'])
-				print("%ld%P\tst %B $%d\n", r->loop,
-					p, blsh(bn), change);
-		}
-
-		if(r->refbehind.b[z] & bb)
-			for(r1 = r->p2; r1 != R; r1 = r1->p2link)
-				if(r1->refahead.b[z] & bb)
-					paint1(r1, bn);
-
-		if(!(r->refahead.b[z] & bb))
-			break;
-		r1 = r->s2;
-		if(r1 != R)
-			if(r1->refbehind.b[z] & bb)
-				paint1(r1, bn);
-		r = r->s1;
-		if(r == R)
-			break;
-		if(r->act.b[z] & bb)
-			break;
-		if(!(r->refbehind.b[z] & bb))
-			break;
-	}
-}
-
-uint32_t
-regset(Reg *r, uint32_t bb)
-{
-	uint32_t b, set;
-	Adr v;
-	int c;
-
-	set = 0;
-	v = zprog.from;
-	while(b = bb & ~(bb-1)) {
-		v.type = BtoR(b);
-		c = copyu(r->prog, &v, A);
-		if(c == 3)
-			set |= b;
-		bb &= ~b;
-	}
-	return set;
-}
-
-uint32_t
-reguse(Reg *r, uint32_t bb)
-{
-	uint32_t b, set;
-	Adr v;
-	int c;
-
-	set = 0;
-	v = zprog.from;
-	while(b = bb & ~(bb-1)) {
-		v.type = BtoR(b);
-		c = copyu(r->prog, &v, A);
-		if(c == 1 || c == 2 || c == 4)
-			set |= b;
-		bb &= ~b;
-	}
-	return set;
-}
-
-uint32_t
-paint2(Reg *r, int bn)
-{
-	Reg *r1;
-	int z;
-	uint32_t bb, vreg, x;
-
-	z = bn/32;
-	bb = 1L << (bn%32);
-	vreg = regbits;
-	if(!(r->act.b[z] & bb))
-		return vreg;
-	for(;;) {
-		if(!(r->refbehind.b[z] & bb))
-			break;
-		r1 = r->p1;
-		if(r1 == R)
-			break;
-		if(!(r1->refahead.b[z] & bb))
-			break;
-		if(!(r1->act.b[z] & bb))
-			break;
-		r = r1;
-	}
-	for(;;) {
-		r->act.b[z] &= ~bb;
-
-		vreg |= r->regu;
-
-		if(r->refbehind.b[z] & bb)
-			for(r1 = r->p2; r1 != R; r1 = r1->p2link)
-				if(r1->refahead.b[z] & bb)
-					vreg |= paint2(r1, bn);
-
-		if(!(r->refahead.b[z] & bb))
-			break;
-		r1 = r->s2;
-		if(r1 != R)
-			if(r1->refbehind.b[z] & bb)
-				vreg |= paint2(r1, bn);
-		r = r->s1;
-		if(r == R)
-			break;
-		if(!(r->act.b[z] & bb))
-			break;
-		if(!(r->refbehind.b[z] & bb))
-			break;
-	}
-
-	bb = vreg;
-	for(; r; r=r->s1) {
-		x = r->regu & ~bb;
-		if(x) {
-			vreg |= reguse(r, x);
-			bb |= regset(r, x);
-		}
-	}
-	return vreg;
-}
-
-void
-paint3(Reg *r, int bn, int32_t rb, int rn)
-{
-	Reg *r1;
-	Prog *p;
-	int z;
-	uint32_t bb;
-
-	z = bn/32;
-	bb = 1L << (bn%32);
-	if(r->act.b[z] & bb)
-		return;
-	for(;;) {
-		if(!(r->refbehind.b[z] & bb))
-			break;
-		r1 = r->p1;
-		if(r1 == R)
-			break;
-		if(!(r1->refahead.b[z] & bb))
-			break;
-		if(r1->act.b[z] & bb)
-			break;
-		r = r1;
-	}
-
-	if(LOAD(r) & ~(r->set.b[z] & ~(r->use1.b[z]|r->use2.b[z])) & bb)
-		addmove(r, bn, rn, 0);
-	for(;;) {
-		r->act.b[z] |= bb;
-		p = r->prog;
-
-		if(r->use1.b[z] & bb) {
-			if(debug['R'])
-				print("%P", p);
-			addreg(&p->from, rn);
-			if(debug['R'])
-				print("\t.c%P\n", p);
-		}
-		if((r->use2.b[z]|r->set.b[z]) & bb) {
-			if(debug['R'])
-				print("%P", p);
-			addreg(&p->to, rn);
-			if(debug['R'])
-				print("\t.c%P\n", p);
-		}
-
-		if(STORE(r) & r->regdiff.b[z] & bb)
-			addmove(r, bn, rn, 1);
-		r->regu |= rb;
-
-		if(r->refbehind.b[z] & bb)
-			for(r1 = r->p2; r1 != R; r1 = r1->p2link)
-				if(r1->refahead.b[z] & bb)
-					paint3(r1, bn, rb, rn);
-
-		if(!(r->refahead.b[z] & bb))
-			break;
-		r1 = r->s2;
-		if(r1 != R)
-			if(r1->refbehind.b[z] & bb)
-				paint3(r1, bn, rb, rn);
-		r = r->s1;
-		if(r == R)
-			break;
-		if(r->act.b[z] & bb)
-			break;
-		if(!(r->refbehind.b[z] & bb))
-			break;
-	}
-}
-
-void
-addreg(Adr *a, int rn)
-{
-
-	a->sym = 0;
-	a->offset = 0;
-	a->type = rn;
-}
-
-int32_t
-RtoB(int r)
-{
-
-	if(r < D_AX || r > D_DI)
-		return 0;
-	return 1L << (r-D_AX);
-}
-
-int
-BtoR(int32_t b)
-{
-
-	b &= 0xffL;
-	if(b == 0)
-		return 0;
-	return bitno(b) + D_AX;
-}

+ 0 - 449
sys/src/cmd/8c/sgen.c

@@ -1,449 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "gc.h"
-
-void
-noretval(int n)
-{
-
-	if(n & 1) {
-		gins(ANOP, Z, Z);
-		p->to.type = REGRET;
-	}
-	if(n & 2) {
-		gins(ANOP, Z, Z);
-		p->to.type = FREGRET;
-	}
-	if((n&3) == 3)
-	if(thisfn && thisfn->link && typefd[thisfn->link->etype])
-		gins(AFLDZ, Z, Z);
-}
-
-/* welcome to commute */
-static void
-commute(Node *n)
-{
-	Node *l, *r;
-
-	l = n->left;
-	r = n->right;
-	if(r->complex > l->complex) {
-		n->left = r;
-		n->right = l;
-	}
-}
-
-void
-indexshift(Node *n)
-{
-	int g;
-
-	if(!typechlp[n->type->etype])
-		return;
-	simplifyshift(n);
-	if(n->op == OASHL && n->right->op == OCONST){
-		g = vconst(n->right);
-		if(g >= 0 && g < 4)
-			n->addable = 7;
-	}
-}
-
-/*
- *	calculate addressability as follows
- *		NAME ==> 10/11		name+value(SB/SP)
- *		REGISTER ==> 12		register
- *		CONST ==> 20		$value
- *		*(20) ==> 21		value
- *		&(10) ==> 13		$name+value(SB)
- *		&(11) ==> 1		$name+value(SP)
- *		(13) + (20) ==> 13	fold constants
- *		(1) + (20) ==> 1	fold constants
- *		*(13) ==> 10		back to name
- *		*(1) ==> 11		back to name
- *
- *		(20) * (X) ==> 7	multiplier in indexing
- *		(X,7) + (13,1) ==> 8	adder in indexing (addresses)
- *		(8) ==> &9(OINDEX)	index, almost addressable
- *
- *	calculate complexity (number of registers)
- */
-void
-xcom(Node *n)
-{
-	Node *l, *r;
-	int g;
-
-	if(n == Z)
-		return;
-	l = n->left;
-	r = n->right;
-	n->complex = 0;
-	n->addable = 0;
-	switch(n->op) {
-	case OCONST:
-		n->addable = 20;
-		break;
-
-	case ONAME:
-		n->addable = 10;
-		if(n->class == CPARAM || n->class == CAUTO)
-			n->addable = 11;
-		break;
-
-	case OEXREG:
-		n->addable = 12;
-		break;
-
-	case OREGISTER:
-		n->addable = 12;
-		break;
-
-	case OINDREG:
-		n->addable = 12;
-		break;
-
-	case OADDR:
-		xcom(l);
-		if(l->addable == 10)
-			n->addable = 13;
-		else
-		if(l->addable == 11)
-			n->addable = 1;
-		break;
-
-	case OADD:
-		xcom(l);
-		xcom(r);
-		if(n->type->etype != TIND)
-			break;
-
-		switch(r->addable) {
-		case 20:
-			switch(l->addable) {
-			case 1:
-			case 13:
-			commadd:
-				l->type = n->type;
-				*n = *l;
-				l = new(0, Z, Z);
-				*l = *(n->left);
-				l->xoffset += r->vconst;
-				n->left = l;
-				r = n->right;
-				goto brk;
-			}
-			break;
-
-		case 1:
-		case 13:
-		case 10:
-		case 11:
-			/* l is the base, r is the index */
-			if(l->addable != 20)
-				n->addable = 8;
-			break;
-		}
-		switch(l->addable) {
-		case 20:
-			switch(r->addable) {
-			case 13:
-			case 1:
-				r = n->left;
-				l = n->right;
-				n->left = l;
-				n->right = r;
-				goto commadd;
-			}
-			break;
-
-		case 13:
-		case 1:
-		case 10:
-		case 11:
-			/* r is the base, l is the index */
-			if(r->addable != 20)
-				n->addable = 8;
-			break;
-		}
-		if(n->addable == 8 && !side(n)) {
-			indx(n);
-			l = new1(OINDEX, idx.basetree, idx.regtree);
-			l->scale = idx.scale;
-			l->addable = 9;
-			l->complex = l->right->complex;
-			l->type = l->left->type;
-			n->op = OADDR;
-			n->left = l;
-			n->right = Z;
-			n->addable = 8;
-			break;
-		}
-		break;
-
-	case OINDEX:
-		xcom(l);
-		xcom(r);
-		n->addable = 9;
-		break;
-
-	case OIND:
-		xcom(l);
-		if(l->op == OADDR) {
-			l = l->left;
-			l->type = n->type;
-			*n = *l;
-			return;
-		}
-		switch(l->addable) {
-		case 20:
-			n->addable = 21;
-			break;
-		case 1:
-			n->addable = 11;
-			break;
-		case 13:
-			n->addable = 10;
-			break;
-		}
-		break;
-
-	case OASHL:
-		xcom(l);
-		xcom(r);
-		indexshift(n);
-		break;
-
-	case OMUL:
-	case OLMUL:
-		xcom(l);
-		xcom(r);
-		g = vlog(l);
-		if(g >= 0) {
-			n->left = r;
-			n->right = l;
-			l = r;
-			r = n->right;
-		}
-		g = vlog(r);
-		if(g >= 0) {
-			n->op = OASHL;
-			r->vconst = g;
-			r->type = types[TINT];
-			indexshift(n);
-			break;
-		}
-commute(n);
-		break;
-
-	case OASLDIV:
-		xcom(l);
-		xcom(r);
-		g = vlog(r);
-		if(g >= 0) {
-			n->op = OASLSHR;
-			r->vconst = g;
-			r->type = types[TINT];
-		}
-		break;
-
-	case OLDIV:
-		xcom(l);
-		xcom(r);
-		g = vlog(r);
-		if(g >= 0) {
-			n->op = OLSHR;
-			r->vconst = g;
-			r->type = types[TINT];
-			indexshift(n);
-			break;
-		}
-		break;
-
-	case OASLMOD:
-		xcom(l);
-		xcom(r);
-		g = vlog(r);
-		if(g >= 0) {
-			n->op = OASAND;
-			r->vconst--;
-		}
-		break;
-
-	case OLMOD:
-		xcom(l);
-		xcom(r);
-		g = vlog(r);
-		if(g >= 0) {
-			n->op = OAND;
-			r->vconst--;
-		}
-		break;
-
-	case OASMUL:
-	case OASLMUL:
-		xcom(l);
-		xcom(r);
-		g = vlog(r);
-		if(g >= 0) {
-			n->op = OASASHL;
-			r->vconst = g;
-		}
-		break;
-
-	case OLSHR:
-	case OASHR:
-		xcom(l);
-		xcom(r);
-		indexshift(n);
-		break;
-
-	default:
-		if(l != Z)
-			xcom(l);
-		if(r != Z)
-			xcom(r);
-		break;
-	}
-brk:
-	if(n->addable >= 10)
-		return;
-	if(l != Z)
-		n->complex = l->complex;
-	if(r != Z) {
-		if(r->complex == n->complex)
-			n->complex = r->complex+1;
-		else
-		if(r->complex > n->complex)
-			n->complex = r->complex;
-	}
-	if(n->complex == 0)
-		n->complex++;
-
-	if(com64(n))
-		return;
-
-	switch(n->op) {
-
-	case OFUNC:
-		n->complex = FNX;
-		break;
-
-	case OLMOD:
-	case OMOD:
-	case OLMUL:
-	case OLDIV:
-	case OMUL:
-	case ODIV:
-	case OASLMUL:
-	case OASLDIV:
-	case OASLMOD:
-	case OASMUL:
-	case OASDIV:
-	case OASMOD:
-		if(r->complex >= l->complex) {
-			n->complex = l->complex + 3;
-			if(r->complex > n->complex)
-				n->complex = r->complex;
-		} else {
-			n->complex = r->complex + 3;
-			if(l->complex > n->complex)
-				n->complex = l->complex;
-		}
-		break;
-
-	case OLSHR:
-	case OASHL:
-	case OASHR:
-	case OASLSHR:
-	case OASASHL:
-	case OASASHR:
-		if(r->complex >= l->complex) {
-			n->complex = l->complex + 2;
-			if(r->complex > n->complex)
-				n->complex = r->complex;
-		} else {
-			n->complex = r->complex + 2;
-			if(l->complex > n->complex)
-				n->complex = l->complex;
-		}
-		break;
-
-	case OADD:
-	case OXOR:
-	case OAND:
-	case OOR:
-		/*
-		 * immediate operators, make const on right
-		 */
-		if(l->op == OCONST) {
-			n->left = r;
-			n->right = l;
-		}
-		break;
-
-	case OEQ:
-	case ONE:
-	case OLE:
-	case OLT:
-	case OGE:
-	case OGT:
-	case OHI:
-	case OHS:
-	case OLO:
-	case OLS:
-		/*
-		 * compare operators, make const on left
-		 */
-		if(r->op == OCONST) {
-			n->left = r;
-			n->right = l;
-			n->op = invrel[relindex(n->op)];
-		}
-		break;
-	}
-}
-
-void
-indx(Node *n)
-{
-	Node *l, *r;
-
-	if(debug['x'])
-		prtree(n, "indx");
-
-	l = n->left;
-	r = n->right;
-	if(l->addable == 1 || l->addable == 13 || r->complex > l->complex) {
-		n->right = l;
-		n->left = r;
-		l = r;
-		r = n->right;
-	}
-	if(l->addable != 7) {
-		idx.regtree = l;
-		idx.scale = 1;
-	} else
-	if(l->right->addable == 20) {
-		idx.regtree = l->left;
-		idx.scale = 1 << l->right->vconst;
-	} else
-	if(l->left->addable == 20) {
-		idx.regtree = l->right;
-		idx.scale = 1 << l->left->vconst;
-	} else
-		diag(n, "bad index");
-
-	idx.basetree = r;
-	if(debug['x']) {
-		print("scale = %d\n", idx.scale);
-		prtree(idx.regtree, "index");
-		prtree(idx.basetree, "base");
-	}
-}

+ 0 - 511
sys/src/cmd/8c/swt.c

@@ -1,511 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "gc.h"
-
-void
-swit1(C1 *q, int nc, int32_t def, Node *n)
-{
-	C1 *r;
-	int i;
-	Prog *sp;
-
-	if(nc < 5) {
-		for(i=0; i<nc; i++) {
-			if(debug['K'])
-				print("case = %.8llux\n", q->val);
-			gopcode(OEQ, n->type, n, nodconst(q->val));
-			patch(p, q->label);
-			q++;
-		}
-		gbranch(OGOTO);
-		patch(p, def);
-		return;
-	}
-	i = nc / 2;
-	r = q+i;
-	if(debug['K'])
-		print("case > %.8llux\n", r->val);
-	gopcode(OGT, n->type, n, nodconst(r->val));
-	sp = p;
-	gbranch(OGOTO);
-	p->as = AJEQ;
-	patch(p, r->label);
-	swit1(q, i, def, n);
-
-	if(debug['K'])
-		print("case < %.8llux\n", r->val);
-	patch(sp, pc);
-	swit1(r+1, nc-i-1, def, n);
-}
-
-void
-bitload(Node *b, Node *n1, Node *n2, Node *n3, Node *nn)
-{
-	int sh;
-	int32_t v;
-	Node *l;
-
-	/*
-	 * n1 gets adjusted/masked value
-	 * n2 gets address of cell
-	 * n3 gets contents of cell
-	 */
-	l = b->left;
-	if(n2 != Z) {
-		regalloc(n1, l, nn);
-		reglcgen(n2, l, Z);
-		regalloc(n3, l, Z);
-		gmove(n2, n3);
-		gmove(n3, n1);
-	} else {
-		regalloc(n1, l, nn);
-		cgen(l, n1);
-	}
-	if(b->type->shift == 0 && typeu[b->type->etype]) {
-		v = ~0 + (1L << b->type->nbits);
-		gopcode(OAND, types[TLONG], nodconst(v), n1);
-	} else {
-		sh = 32 - b->type->shift - b->type->nbits;
-		if(sh > 0)
-			gopcode(OASHL, types[TLONG], nodconst(sh), n1);
-		sh += b->type->shift;
-		if(sh > 0)
-			if(typeu[b->type->etype])
-				gopcode(OLSHR, types[TLONG], nodconst(sh), n1);
-			else
-				gopcode(OASHR, types[TLONG], nodconst(sh), n1);
-	}
-}
-
-void
-bitstore(Node *b, Node *n1, Node *n2, Node *n3, Node *nn)
-{
-	int32_t v;
-	Node nod;
-	int sh;
-
-	regalloc(&nod, b->left, Z);
-	v = ~0 + (1L << b->type->nbits);
-	gopcode(OAND, types[TLONG], nodconst(v), n1);
-	gmove(n1, &nod);
-	if(nn != Z)
-		gmove(n1, nn);
-	sh = b->type->shift;
-	if(sh > 0)
-		gopcode(OASHL, types[TLONG], nodconst(sh), &nod);
-	v <<= sh;
-	gopcode(OAND, types[TLONG], nodconst(~v), n3);
-	gopcode(OOR, types[TLONG], n3, &nod);
-	gmove(&nod, n2);
-
-	regfree(&nod);
-	regfree(n1);
-	regfree(n2);
-	regfree(n3);
-}
-
-int32_t
-outstring(char *s, int32_t n)
-{
-	int32_t r;
-
-	if(suppress)
-		return nstring;
-	r = nstring;
-	while(n) {
-		string[mnstring] = *s++;
-		mnstring++;
-		nstring++;
-		if(mnstring >= NSNAME) {
-			gpseudo(ADATA, symstring, nodconst(0L));
-			p->from.offset += nstring - NSNAME;
-			p->from.scale = NSNAME;
-			p->to.type = D_SCONST;
-			memmove(p->to.sval, string, NSNAME);
-			mnstring = 0;
-		}
-		n--;
-	}
-	return r;
-}
-
-void
-gextern(Sym *s, Node *a, int32_t o, int32_t w)
-{
-	if(a->op == OCONST && typev[a->type->etype]) {
-		gpseudo(ADATA, s, lo64(a));
-		p->from.offset += o;
-		p->from.scale = 4;
-		gpseudo(ADATA, s, hi64(a));
-		p->from.offset += o + 4;
-		p->from.scale = 4;
-		return;
-	}
-	gpseudo(ADATA, s, a);
-	p->from.offset += o;
-	p->from.scale = w;
-	switch(p->to.type) {
-	default:
-		p->to.index = p->to.type;
-		p->to.type = D_ADDR;
-	case D_CONST:
-	case D_FCONST:
-	case D_ADDR:
-		break;
-	}
-}
-
-void	zname(Biobuf*, Sym*, int);
-void	zaddr(Biobuf*, Adr*, int);
-void	outhist(Biobuf*);
-
-void
-outcode(void)
-{
-	struct { Sym *sym; int16_t type; } h[NSYM];
-	Prog *p;
-	Sym *s;
-	int f, sf, st, t, sym;
-	Biobuf b;
-
-	if(debug['S']) {
-		for(p = firstp; p != P; p = p->link)
-			if(p->as != ADATA && p->as != AGLOBL)
-				pc--;
-		for(p = firstp; p != P; p = p->link) {
-			print("%P\n", p);
-			if(p->as != ADATA && p->as != AGLOBL)
-				pc++;
-		}
-	}
-	f = open(outfile, OWRITE);
-	if(f < 0) {
-		diag(Z, "cannot open %s", outfile);
-		return;
-	}
-	Binit(&b, f, OWRITE);
-	Bseek(&b, 0L, 2);
-	outhist(&b);
-	for(sym=0; sym<NSYM; sym++) {
-		h[sym].sym = S;
-		h[sym].type = 0;
-	}
-	sym = 1;
-	for(p = firstp; p != P; p = p->link) {
-	jackpot:
-		sf = 0;
-		s = p->from.sym;
-		while(s != S) {
-			sf = s->sym;
-			if(sf < 0 || sf >= NSYM)
-				sf = 0;
-			t = p->from.type;
-			if(t == D_ADDR)
-				t = p->from.index;
-			if(h[sf].type == t)
-			if(h[sf].sym == s)
-				break;
-			s->sym = sym;
-			zname(&b, s, t);
-			h[sym].sym = s;
-			h[sym].type = t;
-			sf = sym;
-			sym++;
-			if(sym >= NSYM)
-				sym = 1;
-			break;
-		}
-		st = 0;
-		s = p->to.sym;
-		while(s != S) {
-			st = s->sym;
-			if(st < 0 || st >= NSYM)
-				st = 0;
-			t = p->to.type;
-			if(t == D_ADDR)
-				t = p->to.index;
-			if(h[st].type == t)
-			if(h[st].sym == s)
-				break;
-			s->sym = sym;
-			zname(&b, s, t);
-			h[sym].sym = s;
-			h[sym].type = t;
-			st = sym;
-			sym++;
-			if(sym >= NSYM)
-				sym = 1;
-			if(st == sf)
-				goto jackpot;
-			break;
-		}
-		Bputc(&b, p->as);
-		Bputc(&b, p->as>>8);
-		Bputc(&b, p->lineno);
-		Bputc(&b, p->lineno>>8);
-		Bputc(&b, p->lineno>>16);
-		Bputc(&b, p->lineno>>24);
-		zaddr(&b, &p->from, sf);
-		zaddr(&b, &p->to, st);
-	}
-	Bflush(&b);
-	close(f);
-	firstp = P;
-	lastp = P;
-}
-
-void
-outhist(Biobuf *b)
-{
-	Hist *h;
-	char *p, *q, *op, c;
-	Prog pg;
-	int n;
-
-	pg = zprog;
-	pg.as = AHISTORY;
-	c = pathchar();
-	for(h = hist; h != H; h = h->link) {
-		p = h->name;
-		op = 0;
-		/* on windows skip drive specifier in pathname */
-		if(systemtype(Windows) && p && p[1] == ':'){
-			p += 2;
-			c = *p;
-		}
-		if(p && p[0] != c && h->offset == 0 && pathname){
-			/* on windows skip drive specifier in pathname */
-			if(systemtype(Windows) && pathname[1] == ':') {
-				op = p;
-				p = pathname+2;
-				c = *p;
-			} else if(pathname[0] == c){
-				op = p;
-				p = pathname;
-			}
-		}
-		while(p) {
-			q = utfrune(p, c);
-			if(q) {
-				n = q-p;
-				if(n == 0){
-					n = 1;	/* leading "/" */
-					*p = '/';	/* don't emit "\" on windows */
-				}
-				q++;
-			} else {
-				n = strlen(p);
-				q = 0;
-			}
-			if(n) {
-				Bputc(b, ANAME);
-				Bputc(b, ANAME>>8);
-				Bputc(b, D_FILE);
-				Bputc(b, 1);
-				Bputc(b, '<');
-				Bwrite(b, p, n);
-				Bputc(b, 0);
-			}
-			p = q;
-			if(p == 0 && op) {
-				p = op;
-				op = 0;
-			}
-		}
-		pg.lineno = h->line;
-		pg.to.type = zprog.to.type;
-		pg.to.offset = h->offset;
-		if(h->offset)
-			pg.to.type = D_CONST;
-
-		Bputc(b, pg.as);
-		Bputc(b, pg.as>>8);
-		Bputc(b, pg.lineno);
-		Bputc(b, pg.lineno>>8);
-		Bputc(b, pg.lineno>>16);
-		Bputc(b, pg.lineno>>24);
-		zaddr(b, &pg.from, 0);
-		zaddr(b, &pg.to, 0);
-	}
-}
-
-void
-zname(Biobuf *b, Sym *s, int t)
-{
-	char *n;
-	uint32_t sig;
-
-	if(debug['T'] && t == D_EXTERN && s->sig != SIGDONE && s->type != types[TENUM] && s != symrathole){
-		sig = sign(s);
-		Bputc(b, ASIGNAME);
-		Bputc(b, ASIGNAME>>8);
-		Bputc(b, sig);
-		Bputc(b, sig>>8);
-		Bputc(b, sig>>16);
-		Bputc(b, sig>>24);
-		s->sig = SIGDONE;
-	}
-	else{
-		Bputc(b, ANAME);	/* as */
-		Bputc(b, ANAME>>8);	/* as */
-	}
-	Bputc(b, t);			/* type */
-	Bputc(b, s->sym);		/* sym */
-	n = s->name;
-	while(*n) {
-		Bputc(b, *n);
-		n++;
-	}
-	Bputc(b, 0);
-}
-
-void
-zaddr(Biobuf *b, Adr *a, int s)
-{
-	int32_t l;
-	int i, t;
-	char *n;
-	Ieee e;
-
-	t = 0;
-	if(a->index != D_NONE || a->scale != 0)
-		t |= T_INDEX;
-	if(s != 0)
-		t |= T_SYM;
-
-	switch(a->type) {
-	default:
-		t |= T_TYPE;
-	case D_NONE:
-		if(a->offset != 0)
-			t |= T_OFFSET;
-		break;
-	case D_FCONST:
-		t |= T_FCONST;
-		break;
-	case D_SCONST:
-		t |= T_SCONST;
-		break;
-	}
-	Bputc(b, t);
-
-	if(t & T_INDEX) {	/* implies index, scale */
-		Bputc(b, a->index);
-		Bputc(b, a->scale);
-	}
-	if(t & T_OFFSET) {	/* implies offset */
-		l = a->offset;
-		Bputc(b, l);
-		Bputc(b, l>>8);
-		Bputc(b, l>>16);
-		Bputc(b, l>>24);
-	}
-	if(t & T_SYM)		/* implies sym */
-		Bputc(b, s);
-	if(t & T_FCONST) {
-		ieeedtod(&e, a->dval);
-		l = e.l;
-		Bputc(b, l);
-		Bputc(b, l>>8);
-		Bputc(b, l>>16);
-		Bputc(b, l>>24);
-		l = e.h;
-		Bputc(b, l);
-		Bputc(b, l>>8);
-		Bputc(b, l>>16);
-		Bputc(b, l>>24);
-		return;
-	}
-	if(t & T_SCONST) {
-		n = a->sval;
-		for(i=0; i<NSNAME; i++) {
-			Bputc(b, *n);
-			n++;
-		}
-		return;
-	}
-	if(t & T_TYPE)
-		Bputc(b, a->type);
-}
-
-int32_t
-align(int32_t i, Type *t, int op)
-{
-	int32_t o;
-	Type *v;
-	int w;
-
-	o = i;
-	w = 1;
-	switch(op) {
-	default:
-		diag(Z, "unknown align opcode %d", op);
-		break;
-
-	case Asu2:	/* padding at end of a struct */
-		w = SZ_LONG;
-		if(packflg)
-			w = packflg;
-		break;
-
-	case Ael1:	/* initial allign of struct element */
-		for(v=t; v->etype==TARRAY; v=v->link)
-			;
-		w = ewidth[v->etype];
-		if(w <= 0 || w >= SZ_LONG)
-			w = SZ_LONG;
-		if(packflg)
-			w = packflg;
-		break;
-
-	case Ael2:	/* width of a struct element */
-		o += t->width;
-		break;
-
-	case Aarg0:	/* initial passbyptr argument in arg list */
-		if(typesuv[t->etype]) {
-			o = align(o, types[TIND], Aarg1);
-			o = align(o, types[TIND], Aarg2);
-		}
-		break;
-
-	case Aarg1:	/* initial allign of parameter */
-		w = ewidth[t->etype];
-		if(w <= 0 || w >= SZ_LONG) {
-			w = SZ_LONG;
-			break;
-		}
-		w = 1;		/* little endian no adjustment */
-		break;
-
-	case Aarg2:	/* width of a parameter */
-		o += t->width;
-		w = SZ_LONG;
-		break;
-
-	case Aaut3:	/* total allign of automatic */
-		o = align(o, t, Ael1);
-		o = align(o, t, Ael2);
-		break;
-	}
-	o = round(o, w);
-	if(debug['A'])
-		print("align %s %ld %T = %ld\n", bnames[op], i, t, o);
-	return o;
-}
-
-int32_t
-maxround(int32_t max, int32_t v)
-{
-	v = round(v, SZ_LONG);
-	if(v > max)
-		return v;
-	return max;
-}

+ 0 - 1455
sys/src/cmd/8c/txt.c

@@ -1,1455 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include "gc.h"
-
-void
-ginit(void)
-{
-	int i;
-	Type *t;
-
-	thechar = '8';
-	thestring = "386";
-	exregoffset = 0;
-	exfregoffset = 0;
-	listinit();
-	nstring = 0;
-	mnstring = 0;
-	nrathole = 0;
-	pc = 0;
-	breakpc = -1;
-	continpc = -1;
-	cases = C;
-	firstp = P;
-	lastp = P;
-	tfield = types[TLONG];
-
-	typeswitch = typechlv;
-
-	zprog.link = P;
-	zprog.as = AGOK;
-	zprog.from.type = D_NONE;
-	zprog.from.index = D_NONE;
-	zprog.from.scale = 0;
-	zprog.to = zprog.from;
-
-	regnode.op = OREGISTER;
-	regnode.class = CEXREG;
-	regnode.reg = REGTMP;
-	regnode.complex = 0;
-	regnode.addable = 11;
-	regnode.type = types[TLONG];
-
-	fregnode0 = regnode;
-	fregnode0.reg = D_F0;
-	fregnode0.type = types[TDOUBLE];
-
-	fregnode1 = fregnode0;
-	fregnode1.reg = D_F0+1;
-
-	constnode.op = OCONST;
-	constnode.class = CXXX;
-	constnode.complex = 0;
-	constnode.addable = 20;
-	constnode.type = types[TLONG];
-
-	fconstnode.op = OCONST;
-	fconstnode.class = CXXX;
-	fconstnode.complex = 0;
-	fconstnode.addable = 20;
-	fconstnode.type = types[TDOUBLE];
-
-	nodsafe = new(ONAME, Z, Z);
-	nodsafe->sym = slookup(".safe");
-	nodsafe->type = types[TINT];
-	nodsafe->etype = types[TINT]->etype;
-	nodsafe->class = CAUTO;
-	complex(nodsafe);
-
-	t = typ(TARRAY, types[TCHAR]);
-	symrathole = slookup(".rathole");
-	symrathole->class = CGLOBL;
-	symrathole->type = t;
-
-	nodrat = new(ONAME, Z, Z);
-	nodrat->sym = symrathole;
-	nodrat->type = types[TIND];
-	nodrat->etype = TVOID;
-	nodrat->class = CGLOBL;
-	complex(nodrat);
-	nodrat->type = t;
-
-	nodret = new(ONAME, Z, Z);
-	nodret->sym = slookup(".ret");
-	nodret->type = types[TIND];
-	nodret->etype = TIND;
-	nodret->class = CPARAM;
-	nodret = new(OIND, nodret, Z);
-	complex(nodret);
-
-	com64init();
-
-	for(i=0; i<nelem(reg); i++) {
-		reg[i] = 1;
-		if(i >= D_AX && i <= D_DI && i != D_SP)
-			reg[i] = 0;
-	}
-}
-
-void
-gclean(void)
-{
-	int i;
-	Sym *s;
-
-	reg[D_SP]--;
-	for(i=D_AX; i<=D_DI; i++)
-		if(reg[i])
-			diag(Z, "reg %R left allocated", i);
-	while(mnstring)
-		outstring("", 1L);
-	symstring->type->width = nstring;
-	symrathole->type->width = nrathole;
-	for(i=0; i<NHASH; i++)
-	for(s = hash[i]; s != S; s = s->link) {
-		if(s->type == T)
-			continue;
-		if(s->type->width == 0)
-			continue;
-		if(s->class != CGLOBL && s->class != CSTATIC)
-			continue;
-		if(s->type == types[TENUM])
-			continue;
-		gpseudo(AGLOBL, s, nodconst(s->type->width));
-	}
-	nextpc();
-	p->as = AEND;
-	outcode();
-}
-
-void
-nextpc(void)
-{
-
-	p = alloc(sizeof(*p));
-	*p = zprog;
-	p->lineno = nearln;
-	pc++;
-	if(firstp == P) {
-		firstp = p;
-		lastp = p;
-		return;
-	}
-	lastp->link = p;
-	lastp = p;
-}
-
-void
-gargs(Node *n, Node *tn1, Node *tn2)
-{
-	int32_t regs;
-	Node fnxargs[20], *fnxp;
-
-	regs = cursafe;
-
-	fnxp = fnxargs;
-	garg1(n, tn1, tn2, 0, &fnxp);	/* compile fns to temps */
-
-	curarg = 0;
-	fnxp = fnxargs;
-	garg1(n, tn1, tn2, 1, &fnxp);	/* compile normal args and temps */
-
-	cursafe = regs;
-}
-
-int
-nareg(int notbp)
-{
-	int i, n;
-
-	n = 0;
-	for(i=D_AX; i<=D_DI; i++)
-		if(reg[i] == 0)
-			n++;
-	if(notbp && reg[D_BP] == 0)
-		n--;
-	return n;
-}
-
-void
-garg1(Node *n, Node *tn1, Node *tn2, int f, Node **fnxp)
-{
-	Node nod;
-
-	if(n == Z)
-		return;
-	if(n->op == OLIST) {
-		garg1(n->left, tn1, tn2, f, fnxp);
-		garg1(n->right, tn1, tn2, f, fnxp);
-		return;
-	}
-	if(f == 0) {
-		if(n->complex >= FNX) {
-			regsalloc(*fnxp, n);
-			nod = znode;
-			nod.op = OAS;
-			nod.left = *fnxp;
-			nod.right = n;
-			nod.type = n->type;
-			cgen(&nod, Z);
-			(*fnxp)++;
-		}
-		return;
-	}
-	if(typesu[n->type->etype] || typev[n->type->etype]) {
-		regaalloc(tn2, n);
-		if(n->complex >= FNX) {
-			sugen(*fnxp, tn2, n->type->width);
-			(*fnxp)++;
-		} else
-			sugen(n, tn2, n->type->width);
-		return;
-	}
-	if(REGARG>=0 && curarg == 0 && typeilp[n->type->etype]) {
-		regaalloc1(tn1, n);
-		if(n->complex >= FNX) {
-			cgen(*fnxp, tn1);
-			(*fnxp)++;
-		} else
-			cgen(n, tn1);
-		return;
-	}
-	if(vconst(n) == 0) {
-		regaalloc(tn2, n);
-		gmove(n, tn2);
-		return;
-	}
-	regalloc(tn1, n, Z);
-	if(n->complex >= FNX) {
-		cgen(*fnxp, tn1);
-		(*fnxp)++;
-	} else
-		cgen(n, tn1);
-	regaalloc(tn2, n);
-	gmove(tn1, tn2);
-	regfree(tn1);
-}
-
-Node*
-nodconst(int32_t v)
-{
-	constnode.vconst = v;
-	return &constnode;
-}
-
-Node*
-nodfconst(double d)
-{
-	fconstnode.fconst = d;
-	return &fconstnode;
-}
-
-int
-isreg(Node *n, int r)
-{
-
-	if(n->op == OREGISTER)
-		if(n->reg == r)
-			return 1;
-	return 0;
-}
-
-int
-nodreg(Node *n, Node *nn, int r)
-{
-
-	*n = regnode;
-	n->reg = r;
-	if(reg[r] == 0)
-		return 0;
-	if(nn != Z) {
-		n->type = nn->type;
-		n->lineno = nn->lineno;
-		if(nn->op == OREGISTER)
-		if(nn->reg == r)
-			return 0;
-	}
-	return 1;
-}
-
-void
-regret(Node *n, Node *nn)
-{
-	int r;
-
-	r = REGRET;
-	if(typefd[nn->type->etype])
-		r = FREGRET;
-	nodreg(n, nn, r);
-	reg[r]++;
-}
-
-void
-regalloc(Node *n, Node *tn, Node *o)
-{
-	int i;
-
-	switch(tn->type->etype) {
-	case TCHAR:
-	case TUCHAR:
-	case TSHORT:
-	case TUSHORT:
-	case TINT:
-	case TUINT:
-	case TLONG:
-	case TULONG:
-	case TIND:
-		if(o != Z && o->op == OREGISTER) {
-			i = o->reg;
-			if(i >= D_AX && i <= D_DI)
-				goto out;
-		}
-		for(i=D_AX; i<=D_DI; i++)
-			if(reg[i] == 0)
-				goto out;
-		diag(tn, "out of fixed registers");
-abort();
-		goto err;
-
-	case TFLOAT:
-	case TDOUBLE:
-		i = D_F0;
-		goto out;
-
-	case TVLONG:
-	case TUVLONG:
-		n->op = OREGPAIR;
-		n->complex = 0; /* already in registers */
-		n->addable = 11;
-		n->type = tn->type;
-		n->lineno = nearln;
-		n->left = alloc(sizeof(Node));
-		n->right = alloc(sizeof(Node));
-		if(o != Z && o->op == OREGPAIR) {
-			regalloc(n->left, &regnode, o->left);
-			regalloc(n->right, &regnode, o->right);
-		} else {
-			regalloc(n->left, &regnode, Z);
-			regalloc(n->right, &regnode, Z);
-		}
-		n->right->type = types[TULONG];
-		if(tn->type->etype == TUVLONG)
-			n->left->type = types[TULONG];
-		return;
-	}
-	diag(tn, "unknown type in regalloc: %T", tn->type);
-err:
-	i = 0;
-out:
-	if(i)
-		reg[i]++;
-	nodreg(n, tn, i);
-//print("+ %R %d\n", i, reg[i]);
-}
-
-void
-regialloc(Node *n, Node *tn, Node *o)
-{
-	Node nod;
-
-	nod = *tn;
-	nod.type = types[TIND];
-	regalloc(n, &nod, o);
-}
-
-void
-regfree(Node *n)
-{
-	int i;
-
-	if(n->op == OREGPAIR) {
-		regfree(n->left);
-		regfree(n->right);
-		return;
-	}
-
-	i = 0;
-	if(n->op != OREGISTER && n->op != OINDREG)
-		goto err;
-	i = n->reg;
-	if(i < 0 || i >= sizeof(reg))
-		goto err;
-	if(reg[i] <= 0)
-		goto err;
-	reg[i]--;
-//print("- %R %d\n", i, reg[i]);
-	return;
-err:
-	diag(n, "error in regfree: %R", i);
-}
-
-void
-regsalloc(Node *n, Node *nn)
-{
-	cursafe = align(cursafe, nn->type, Aaut3);
-	maxargsafe = maxround(maxargsafe, cursafe+curarg);
-	*n = *nodsafe;
-	n->xoffset = -(stkoff + cursafe);
-	n->type = nn->type;
-	n->etype = nn->type->etype;
-	n->lineno = nn->lineno;
-}
-
-void
-regaalloc1(Node *n, Node *nn)
-{
-	USED(nn);
-
-	if(REGARG < 0) {
-		diag(n, "regaalloc1");
-		return;
-	}
-/* not reached 
-	nodreg(n, nn, REGARG);
-	reg[REGARG]++;
-	curarg = align(curarg, nn->type, Aarg1);
-	curarg = align(curarg, nn->type, Aarg2);
-	maxargsafe = maxround(maxargsafe, cursafe+curarg);
-*/
-}
-
-void
-regaalloc(Node *n, Node *nn)
-{
-	curarg = align(curarg, nn->type, Aarg1);
-	*n = *nn;
-	n->op = OINDREG;
-	n->reg = REGSP;
-	n->xoffset = curarg;
-	n->complex = 0;
-	n->addable = 20;
-	curarg = align(curarg, nn->type, Aarg2);
-	maxargsafe = maxround(maxargsafe, cursafe+curarg);
-}
-
-void
-regind(Node *n, Node *nn)
-{
-
-	if(n->op != OREGISTER) {
-		diag(n, "regind not OREGISTER");
-		return;
-	}
-	n->op = OINDREG;
-	n->type = nn->type;
-}
-
-void
-naddr(Node *n, Adr *a)
-{
-	int32_t v;
-
-	a->type = D_NONE;
-	if(n == Z)
-		return;
-	switch(n->op) {
-	default:
-	bad:
-		diag(n, "bad in naddr: %O %D", n->op, a);
-//prtree(n, "naddr");
-		break;
-
-	case OREGISTER:
-		a->type = n->reg;
-		a->sym = S;
-		break;
-
-	case OEXREG:
-		a->type = D_INDIR + D_GS;
-		a->offset = n->reg - 1;
-		a->etype = n->etype;
-		break;
-
-	case OIND:
-		naddr(n->left, a);
-		if(a->type >= D_AX && a->type <= D_DI)
-			a->type += D_INDIR;
-		else
-		if(a->type == D_CONST)
-			a->type = D_NONE+D_INDIR;
-		else
-		if(a->type == D_ADDR) {
-			a->type = a->index;
-			a->index = D_NONE;
-		} else
-			goto bad;
-		break;
-
-	case OINDEX:
-		a->type = idx.ptr;
-		if(n->left->op == OADDR || n->left->op == OCONST)
-			naddr(n->left, a);
-		if(a->type >= D_AX && a->type <= D_DI)
-			a->type += D_INDIR;
-		else
-		if(a->type == D_CONST)
-			a->type = D_NONE+D_INDIR;
-		else
-		if(a->type == D_ADDR) {
-			a->type = a->index;
-			a->index = D_NONE;
-		} else
-			goto bad;
-		a->index = idx.reg;
-		a->scale = n->scale;
-		a->offset += n->xoffset;
-		break;
-
-	case OINDREG:
-		a->type = n->reg+D_INDIR;
-		a->sym = S;
-		a->offset = n->xoffset;
-		break;
-
-	case ONAME:
-		a->etype = n->etype;
-		a->type = D_STATIC;
-		a->sym = n->sym;
-		a->offset = n->xoffset;
-		if(n->class == CSTATIC)
-			break;
-		if(n->class == CEXTERN || n->class == CGLOBL) {
-			a->type = D_EXTERN;
-			break;
-		}
-		if(n->class == CAUTO) {
-			a->type = D_AUTO;
-			break;
-		}
-		if(n->class == CPARAM) {
-			a->type = D_PARAM;
-			break;
-		}
-		goto bad;
-
-	case OCONST:
-		if(typefd[n->type->etype]) {
-			a->type = D_FCONST;
-			a->dval = n->fconst;
-			break;
-		}
-		a->sym = S;
-		a->type = D_CONST;
-		a->offset = n->vconst;
-		break;
-
-	case OADDR:
-		naddr(n->left, a);
-		if(a->type >= D_INDIR) {
-			a->type -= D_INDIR;
-			break;
-		}
-		if(a->type == D_EXTERN || a->type == D_STATIC ||
-		   a->type == D_AUTO || a->type == D_PARAM)
-			if(a->index == D_NONE) {
-				a->index = a->type;
-				a->type = D_ADDR;
-				break;
-			}
-		goto bad;
-
-	case OADD:
-		if(n->right->op == OCONST) {
-			v = n->right->vconst;
-			naddr(n->left, a);
-		} else
-		if(n->left->op == OCONST) {
-			v = n->left->vconst;
-			naddr(n->right, a);
-		} else
-			goto bad;
-		a->offset += v;
-		break;
-
-	}
-}
-
-#define	CASE(a,b)	((a<<8)|(b<<0))
-
-void
-gmove(Node *f, Node *t)
-{
-	int ft, tt, a;
-	Node nod, nod1;
-	Prog *p1;
-
-	ft = f->type->etype;
-	tt = t->type->etype;
-	if(debug['M'])
-		print("gop: %O %O[%s],%O[%s]\n", OAS,
-			f->op, tnames[ft], t->op, tnames[tt]);
-	if(typefd[ft] && f->op == OCONST) {
-		if(f->fconst == 0)
-			gins(AFLDZ, Z, Z);
-		else
-		if(f->fconst == 1)
-			gins(AFLD1, Z, Z);
-		else
-			gins(AFMOVD, f, &fregnode0);
-		gmove(&fregnode0, t);
-		return;
-	}
-/*
- * load
- */
-	if(f->op == ONAME || f->op == OINDREG ||
-	   f->op == OIND || f->op == OINDEX)
-	switch(ft) {
-	case TCHAR:
-		a = AMOVBLSX;
-		goto ld;
-	case TUCHAR:
-		a = AMOVBLZX;
-		goto ld;
-	case TSHORT:
-		if(typefd[tt]) {
-			gins(AFMOVW, f, &fregnode0);
-			gmove(&fregnode0, t);
-			return;
-		}
-		a = AMOVWLSX;
-		goto ld;
-	case TUSHORT:
-		a = AMOVWLZX;
-		goto ld;
-	case TINT:
-	case TUINT:
-	case TLONG:
-	case TULONG:
-	case TIND:
-		if(typefd[tt]) {
-			gins(AFMOVL, f, &fregnode0);
-			gmove(&fregnode0, t);
-			return;
-		}
-		a = AMOVL;
-
-	ld:
-		regalloc(&nod, f, t);
-		nod.type = types[TLONG];
-		gins(a, f, &nod);
-		gmove(&nod, t);
-		regfree(&nod);
-		return;
-
-	case TFLOAT:
-		gins(AFMOVF, f, t);
-		return;
-	case TDOUBLE:
-		gins(AFMOVD, f, t);
-		return;
-	}
-
-/*
- * store
- */
-	if(t->op == ONAME || t->op == OINDREG ||
-	   t->op == OIND || t->op == OINDEX)
-	switch(tt) {
-	case TCHAR:
-	case TUCHAR:
-		a = AMOVB;	goto st;
-	case TSHORT:
-	case TUSHORT:
-		a = AMOVW;	goto st;
-	case TINT:
-	case TUINT:
-	case TLONG:
-	case TULONG:
-	case TIND:
-		a = AMOVL;	goto st;
-
-	st:
-		if(f->op == OCONST) {
-			gins(a, f, t);
-			return;
-		}
-		regalloc(&nod, t, f);
-		gmove(f, &nod);
-		gins(a, &nod, t);
-		regfree(&nod);
-		return;
-
-	case TFLOAT:
-		gins(AFMOVFP, f, t);
-		return;
-	case TDOUBLE:
-		gins(AFMOVDP, f, t);
-		return;
-	}
-
-/*
- * convert
- */
-	switch(CASE(ft,tt)) {
-	default:
-/*
- * integer to integer
- ********
-		a = AGOK;	break;
-
-	case CASE(	TCHAR,	TCHAR):
-	case CASE(	TUCHAR,	TCHAR):
-	case CASE(	TSHORT,	TCHAR):
-	case CASE(	TUSHORT,TCHAR):
-	case CASE(	TINT,	TCHAR):
-	case CASE(	TUINT,	TCHAR):
-	case CASE(	TLONG,	TCHAR):
-	case CASE(	TULONG,	TCHAR):
-	case CASE(	TIND,	TCHAR):
-
-	case CASE(	TCHAR,	TUCHAR):
-	case CASE(	TUCHAR,	TUCHAR):
-	case CASE(	TSHORT,	TUCHAR):
-	case CASE(	TUSHORT,TUCHAR):
-	case CASE(	TINT,	TUCHAR):
-	case CASE(	TUINT,	TUCHAR):
-	case CASE(	TLONG,	TUCHAR):
-	case CASE(	TULONG,	TUCHAR):
-	case CASE(	TIND,	TUCHAR):
-
-	case CASE(	TSHORT,	TSHORT):
-	case CASE(	TUSHORT,TSHORT):
-	case CASE(	TINT,	TSHORT):
-	case CASE(	TUINT,	TSHORT):
-	case CASE(	TLONG,	TSHORT):
-	case CASE(	TULONG,	TSHORT):
-	case CASE(	TIND,	TSHORT):
-
-	case CASE(	TSHORT,	TUSHORT):
-	case CASE(	TUSHORT,TUSHORT):
-	case CASE(	TINT,	TUSHORT):
-	case CASE(	TUINT,	TUSHORT):
-	case CASE(	TLONG,	TUSHORT):
-	case CASE(	TULONG,	TUSHORT):
-	case CASE(	TIND,	TUSHORT):
-
-	case CASE(	TINT,	TINT):
-	case CASE(	TUINT,	TINT):
-	case CASE(	TLONG,	TINT):
-	case CASE(	TULONG,	TINT):
-	case CASE(	TIND,	TINT):
-
-	case CASE(	TINT,	TUINT):
-	case CASE(	TUINT,	TUINT):
-	case CASE(	TLONG,	TUINT):
-	case CASE(	TULONG,	TUINT):
-	case CASE(	TIND,	TUINT):
-
-	case CASE(	TINT,	TLONG):
-	case CASE(	TUINT,	TLONG):
-	case CASE(	TLONG,	TLONG):
-	case CASE(	TULONG,	TLONG):
-	case CASE(	TIND,	TLONG):
-
-	case CASE(	TINT,	TULONG):
-	case CASE(	TUINT,	TULONG):
-	case CASE(	TLONG,	TULONG):
-	case CASE(	TULONG,	TULONG):
-	case CASE(	TIND,	TULONG):
-
-	case CASE(	TINT,	TIND):
-	case CASE(	TUINT,	TIND):
-	case CASE(	TLONG,	TIND):
-	case CASE(	TULONG,	TIND):
-	case CASE(	TIND,	TIND):
- *****/
-		a = AMOVL;
-		break;
-
-	case CASE(	TSHORT,	TINT):
-	case CASE(	TSHORT,	TUINT):
-	case CASE(	TSHORT,	TLONG):
-	case CASE(	TSHORT,	TULONG):
-	case CASE(	TSHORT,	TIND):
-		a = AMOVWLSX;
-		if(f->op == OCONST) {
-			f->vconst &= 0xffff;
-			if(f->vconst & 0x8000)
-				f->vconst |= 0xffff0000;
-			a = AMOVL;
-		}
-		break;
-
-	case CASE(	TUSHORT,TINT):
-	case CASE(	TUSHORT,TUINT):
-	case CASE(	TUSHORT,TLONG):
-	case CASE(	TUSHORT,TULONG):
-	case CASE(	TUSHORT,TIND):
-		a = AMOVWLZX;
-		if(f->op == OCONST) {
-			f->vconst &= 0xffff;
-			a = AMOVL;
-		}
-		break;
-
-	case CASE(	TCHAR,	TSHORT):
-	case CASE(	TCHAR,	TUSHORT):
-	case CASE(	TCHAR,	TINT):
-	case CASE(	TCHAR,	TUINT):
-	case CASE(	TCHAR,	TLONG):
-	case CASE(	TCHAR,	TULONG):
-	case CASE(	TCHAR,	TIND):
-		a = AMOVBLSX;
-		if(f->op == OCONST) {
-			f->vconst &= 0xff;
-			if(f->vconst & 0x80)
-				f->vconst |= 0xffffff00;
-			a = AMOVL;
-		}
-		break;
-
-	case CASE(	TUCHAR,	TSHORT):
-	case CASE(	TUCHAR,	TUSHORT):
-	case CASE(	TUCHAR,	TINT):
-	case CASE(	TUCHAR,	TUINT):
-	case CASE(	TUCHAR,	TLONG):
-	case CASE(	TUCHAR,	TULONG):
-	case CASE(	TUCHAR,	TIND):
-		a = AMOVBLZX;
-		if(f->op == OCONST) {
-			f->vconst &= 0xff;
-			a = AMOVL;
-		}
-		break;
-
-/*
- * float to fix
- */
-	case CASE(	TFLOAT,	TCHAR):
-	case CASE(	TFLOAT,	TUCHAR):
-	case CASE(	TFLOAT,	TSHORT):
-	case CASE(	TFLOAT,	TUSHORT):
-	case CASE(	TFLOAT,	TINT):
-	case CASE(	TFLOAT,	TLONG):
-	case CASE(	TFLOAT,	TIND):
-
-	case CASE(	TDOUBLE,TCHAR):
-	case CASE(	TDOUBLE,TUCHAR):
-	case CASE(	TDOUBLE,TSHORT):
-	case CASE(	TDOUBLE,TUSHORT):
-	case CASE(	TDOUBLE,TINT):
-	case CASE(	TDOUBLE,TLONG):
-	case CASE(	TDOUBLE,TIND):
-		if(fproundflg) {
-			regsalloc(&nod, &regnode);
-			gins(AFMOVLP, f, &nod);
-			gmove(&nod, t);
-			return;
-		}
-		regsalloc(&nod, &regnode);
-		regsalloc(&nod1, &regnode);
-		gins(AFSTCW, Z, &nod1);
-		nod1.xoffset += 2;
-		gins(AMOVW, nodconst(0xf7f), &nod1);
-		gins(AFLDCW, &nod1, Z);
-		gins(AFMOVLP, f, &nod);
-		nod1.xoffset -= 2;
-		gins(AFLDCW, &nod1, Z);
-		gmove(&nod, t);
-		return;
-
-/*
- * float to ulong
- */
-	case CASE(	TDOUBLE,	TULONG):
-	case CASE(	TFLOAT,	TULONG):
-	case CASE(	TDOUBLE,	TUINT):
-	case CASE(	TFLOAT,	TUINT):
-		regsalloc(&nod, &regnode);
-		gmove(f, &fregnode0);
-		gins(AFADDD, nodfconst(-2147483648.), &fregnode0);
-		gins(AFMOVLP, f, &nod);
-		gins(ASUBL, nodconst(-2147483648), &nod);
-		gmove(&nod, t);
-		return;
-
-/*
- * ulong to float
- */
-	case CASE(	TULONG,	TDOUBLE):
-	case CASE(	TULONG,	TFLOAT):
-	case CASE(	TUINT,	TDOUBLE):
-	case CASE(	TUINT,	TFLOAT):
-		regalloc(&nod, f, f);
-		gmove(f, &nod);
-		regsalloc(&nod1, &regnode);
-		gmove(&nod, &nod1);
-		gins(AFMOVL, &nod1, &fregnode0);
-		gins(ACMPL, &nod, nodconst(0));
-		gins(AJGE, Z, Z);
-		p1 = p;
-		gins(AFADDD, nodfconst(4294967296.), &fregnode0);
-		patch(p1, pc);
-		regfree(&nod);
-		return;
-
-/*
- * fix to float
- */
-	case CASE(	TCHAR,	TFLOAT):
-	case CASE(	TUCHAR,	TFLOAT):
-	case CASE(	TSHORT,	TFLOAT):
-	case CASE(	TUSHORT,TFLOAT):
-	case CASE(	TINT,	TFLOAT):
-	case CASE(	TLONG,	TFLOAT):
-	case CASE(	TIND,	TFLOAT):
-
-	case CASE(	TCHAR,	TDOUBLE):
-	case CASE(	TUCHAR,	TDOUBLE):
-	case CASE(	TSHORT,	TDOUBLE):
-	case CASE(	TUSHORT,TDOUBLE):
-	case CASE(	TINT,	TDOUBLE):
-	case CASE(	TLONG,	TDOUBLE):
-	case CASE(	TIND,	TDOUBLE):
-		regsalloc(&nod, &regnode);
-		gmove(f, &nod);
-		gins(AFMOVL, &nod, &fregnode0);
-		return;
-
-/*
- * float to float
- */
-	case CASE(	TFLOAT,	TFLOAT):
-	case CASE(	TDOUBLE,TFLOAT):
-
-	case CASE(	TFLOAT,	TDOUBLE):
-	case CASE(	TDOUBLE,TDOUBLE):
-		a = AFMOVD;	break;
-	}
-	if(a == AMOVL || a == AFMOVD)
-	if(samaddr(f, t))
-		return;
-	gins(a, f, t);
-}
-
-void
-doindex(Node *n)
-{
-	Node nod, nod1;
-	int32_t v;
-
-if(debug['Y'])
-prtree(n, "index");
-
-if(n->left->complex >= FNX)
-print("botch in doindex\n");
-
-	regalloc(&nod, &regnode, Z);
-	v = constnode.vconst;
-	cgen(n->right, &nod);
-	idx.ptr = D_NONE;
-	if(n->left->op == OCONST)
-		idx.ptr = D_CONST;
-	else if(n->left->op == OREGISTER)
-//	else if(n->left->op == OREGISTER && typeil[n->left->type->etype])
-		idx.ptr = n->left->reg;
-	else if(n->left->op != OADDR) {
-		reg[D_BP]++;	// cant be used as a base
-		regalloc(&nod1, &regnode, Z);
-		cgen(n->left, &nod1);
-		idx.ptr = nod1.reg;
-		regfree(&nod1);
-		reg[D_BP]--;
-	}
-	idx.reg = nod.reg;
-	regfree(&nod);
-	constnode.vconst = v;
-}
-
-void
-gins(int a, Node *f, Node *t)
-{
-
-	if(f != Z && f->op == OINDEX)
-		doindex(f);
-	if(t != Z && t->op == OINDEX)
-		doindex(t);
-	nextpc();
-	p->as = a;
-	if(f != Z)
-		naddr(f, &p->from);
-	if(t != Z)
-		naddr(t, &p->to);
-	if(debug['g'])
-		print("%P\n", p);
-}
-
-void
-fgopcode(int o, Node *f, Node *t, int pop, int rev)
-{
-	int a, et;
-	Node nod;
-
-	et = TLONG;
-	if(f != Z && f->type != T)
-		et = f->type->etype;
-	if(!typefd[et]) {
-		diag(f, "fop: integer %O", o);
-		return;
-	}
-	if(debug['M']) {
-		if(t != Z && t->type != T)
-			print("gop: %O %O-%s Z\n", o, f->op, tnames[et]);
-		else
-			print("gop: %O %O-%s %O-%s\n", o,
-				f->op, tnames[et], t->op, tnames[t->type->etype]);
-	}
-	a = AGOK;
-	switch(o) {
-
-	case OASADD:
-	case OADD:
-		if(et == TFLOAT)
-			a = AFADDF;
-		else
-		if(et == TDOUBLE) {
-			a = AFADDD;
-			if(pop)
-				a = AFADDDP;
-		}
-		break;
-
-	case OASSUB:
-	case OSUB:
-		if(et == TFLOAT) {
-			a = AFSUBF;
-			if(rev)
-				a = AFSUBRF;
-		} else
-		if(et == TDOUBLE) {
-			a = AFSUBD;
-			if(pop)
-				a = AFSUBDP;
-			if(rev) {
-				a = AFSUBRD;
-				if(pop)
-					a = AFSUBRDP;
-			}
-		}
-		break;
-
-	case OASMUL:
-	case OMUL:
-		if(et == TFLOAT)
-			a = AFMULF;
-		else
-		if(et == TDOUBLE) {
-			a = AFMULD;
-			if(pop)
-				a = AFMULDP;
-		}
-		break;
-
-	case OASMOD:
-	case OMOD:
-	case OASDIV:
-	case ODIV:
-		if(et == TFLOAT) {
-			a = AFDIVF;
-			if(rev)
-				a = AFDIVRF;
-		} else
-		if(et == TDOUBLE) {
-			a = AFDIVD;
-			if(pop)
-				a = AFDIVDP;
-			if(rev) {
-				a = AFDIVRD;
-				if(pop)
-					a = AFDIVRDP;
-			}
-		}
-		break;
-
-	case OEQ:
-	case ONE:
-	case OLT:
-	case OLE:
-	case OGE:
-	case OGT:
-		pop += rev;
-		if(et == TFLOAT) {
-			a = AFCOMF;
-			if(pop) {
-				a = AFCOMFP;
-				if(pop > 1)
-					a = AGOK;
-			}
-		} else
-		if(et == TDOUBLE) {
-			a = AFCOMF;
-			if(pop) {
-				a = AFCOMDP;
-				if(pop > 1)
-					a = AFCOMDPP;
-			}
-		}
-		gins(a, f, t);
-		regalloc(&nod, &regnode, Z);
-		if(nod.reg != D_AX) {
-			regfree(&nod);
-			nod.reg = D_AX;
-			gins(APUSHL, &nod, Z);
-			gins(AWAIT, Z, Z);
-			gins(AFSTSW, Z, &nod);
-			gins(ASAHF, Z, Z);
-			gins(APOPL, Z, &nod);
-		} else {
-			gins(AWAIT, Z, Z);
-			gins(AFSTSW, Z, &nod);
-			gins(ASAHF, Z, Z);
-			regfree(&nod);
-		}
-		switch(o) {
-		case OEQ:	a = AJEQ; break;
-		case ONE:	a = AJNE; break;
-		case OLT:	a = AJCS; break;
-		case OLE:	a = AJLS; break;
-		case OGE:	a = AJCC; break;
-		case OGT:	a = AJHI; break;
-		}
-		gins(a, Z, Z);
-		return;
-	}
-	if(a == AGOK)
-		diag(Z, "bad in gopcode %O", o);
-	gins(a, f, t);
-}
-
-void
-gopcode(int o, Type *ty, Node *f, Node *t)
-{
-	int a, et;
-
-	et = TLONG;
-	if(ty != T)
-		et = ty->etype;
-	if(typefd[et] && o != OADDR && o != OFUNC) {
-		diag(f, "gop: float %O", o);
-		return;
-	}
-	if(debug['M']) {
-		if(f != Z && f->type != T)
-			print("gop: %O %O[%s],", o, f->op, tnames[et]);
-		else
-			print("gop: %O Z,", o);
-		if(t != Z && t->type != T)
-			print("%O[%s]\n", t->op, tnames[t->type->etype]);
-		else
-			print("Z\n");
-	}
-	a = AGOK;
-	switch(o) {
-	case OCOM:
-		a = ANOTL;
-		if(et == TCHAR || et == TUCHAR)
-			a = ANOTB;
-		if(et == TSHORT || et == TUSHORT)
-			a = ANOTW;
-		break;
-
-	case ONEG:
-		a = ANEGL;
-		if(et == TCHAR || et == TUCHAR)
-			a = ANEGB;
-		if(et == TSHORT || et == TUSHORT)
-			a = ANEGW;
-		break;
-
-	case OADDR:
-		a = ALEAL;
-		break;
-
-	case OASADD:
-	case OADD:
-		a = AADDL;
-		if(et == TCHAR || et == TUCHAR)
-			a = AADDB;
-		if(et == TSHORT || et == TUSHORT)
-			a = AADDW;
-		break;
-
-	case OASSUB:
-	case OSUB:
-		a = ASUBL;
-		if(et == TCHAR || et == TUCHAR)
-			a = ASUBB;
-		if(et == TSHORT || et == TUSHORT)
-			a = ASUBW;
-		break;
-
-	case OASOR:
-	case OOR:
-		a = AORL;
-		if(et == TCHAR || et == TUCHAR)
-			a = AORB;
-		if(et == TSHORT || et == TUSHORT)
-			a = AORW;
-		break;
-
-	case OASAND:
-	case OAND:
-		a = AANDL;
-		if(et == TCHAR || et == TUCHAR)
-			a = AANDB;
-		if(et == TSHORT || et == TUSHORT)
-			a = AANDW;
-		break;
-
-	case OASXOR:
-	case OXOR:
-		a = AXORL;
-		if(et == TCHAR || et == TUCHAR)
-			a = AXORB;
-		if(et == TSHORT || et == TUSHORT)
-			a = AXORW;
-		break;
-
-	case OASLSHR:
-	case OLSHR:
-		a = ASHRL;
-		if(et == TCHAR || et == TUCHAR)
-			a = ASHRB;
-		if(et == TSHORT || et == TUSHORT)
-			a = ASHRW;
-		break;
-
-	case OASASHR:
-	case OASHR:
-		a = ASARL;
-		if(et == TCHAR || et == TUCHAR)
-			a = ASARB;
-		if(et == TSHORT || et == TUSHORT)
-			a = ASARW;
-		break;
-
-	case OASASHL:
-	case OASHL:
-		a = ASALL;
-		if(et == TCHAR || et == TUCHAR)
-			a = ASALB;
-		if(et == TSHORT || et == TUSHORT)
-			a = ASALW;
-		break;
-
-	case OFUNC:
-		a = ACALL;
-		break;
-
-	case OASMUL:
-	case OMUL:
-		if(f->op == OREGISTER && t != Z && isreg(t, D_AX) && reg[D_DX] == 0)
-			t = Z;
-		a = AIMULL;
-		break;
-
-	case OASMOD:
-	case OMOD:
-	case OASDIV:
-	case ODIV:
-		a = AIDIVL;
-		break;
-
-	case OASLMUL:
-	case OLMUL:
-		a = AMULL;
-		break;
-
-	case OASLMOD:
-	case OLMOD:
-	case OASLDIV:
-	case OLDIV:
-		a = ADIVL;
-		break;
-
-	case OEQ:
-	case ONE:
-	case OLT:
-	case OLE:
-	case OGE:
-	case OGT:
-	case OLO:
-	case OLS:
-	case OHS:
-	case OHI:
-		a = ACMPL;
-		if(et == TCHAR || et == TUCHAR)
-			a = ACMPB;
-		if(et == TSHORT || et == TUSHORT)
-			a = ACMPW;
-		gins(a, f, t);
-		switch(o) {
-		case OEQ:	a = AJEQ; break;
-		case ONE:	a = AJNE; break;
-		case OLT:	a = AJLT; break;
-		case OLE:	a = AJLE; break;
-		case OGE:	a = AJGE; break;
-		case OGT:	a = AJGT; break;
-		case OLO:	a = AJCS; break;
-		case OLS:	a = AJLS; break;
-		case OHS:	a = AJCC; break;
-		case OHI:	a = AJHI; break;
-		}
-		gins(a, Z, Z);
-		return;
-	}
-	if(a == AGOK)
-		diag(Z, "bad in gopcode %O", o);
-	gins(a, f, t);
-}
-
-int
-samaddr(Node *f, Node *t)
-{
-
-	if(f->op != t->op)
-		return 0;
-	switch(f->op) {
-
-	case OREGISTER:
-		if(f->reg != t->reg)
-			break;
-		return 1;
-	}
-	return 0;
-}
-
-void
-gbranch(int o)
-{
-	int a;
-
-	a = AGOK;
-	switch(o) {
-	case ORETURN:
-		a = ARET;
-		break;
-	case OGOTO:
-		a = AJMP;
-		break;
-	}
-	nextpc();
-	if(a == AGOK) {
-		diag(Z, "bad in gbranch %O",  o);
-		nextpc();
-	}
-	p->as = a;
-}
-
-void
-patch(Prog *op, int32_t pc)
-{
-
-	op->to.offset = pc;
-	op->to.type = D_BRANCH;
-}
-
-void
-gpseudo(int a, Sym *s, Node *n)
-{
-
-	nextpc();
-	p->as = a;
-	p->from.type = D_EXTERN;
-	p->from.sym = s;
-	p->from.scale = (profileflg ? 0 : NOPROF);
-	if(s->class == CSTATIC)
-		p->from.type = D_STATIC;
-	naddr(n, &p->to);
-	if(a == ADATA || a == AGLOBL)
-		pc--;
-}
-
-int
-sconst(Node *n)
-{
-	int32_t v;
-
-	if(n->op == OCONST && !typefd[n->type->etype]) {
-		v = n->vconst;
-		if(v >= -32766L && v < 32766L)
-			return 1;
-	}
-	return 0;
-}
-
-int32_t
-exreg(Type *t)
-{
-
-	int o;
-
-	if(typechlp[t->etype]){
-		if(exregoffset >= 32)
-			return 0;
-		o = exregoffset;
-		exregoffset += 4;
-		return o+1;	/* +1 to avoid 0 == failure; naddr case OEXREG will -1. */
-	}
-	return 0;
-}
-
-schar	ewidth[NTYPE] =
-{
-	-1,		/*[TXXX]*/	
-	SZ_CHAR,	/*[TCHAR]*/	
-	SZ_CHAR,	/*[TUCHAR]*/
-	SZ_SHORT,	/*[TSHORT]*/
-	SZ_SHORT,	/*[TUSHORT]*/
-	SZ_INT,		/*[TINT]*/
-	SZ_INT,		/*[TUINT]*/
-	SZ_LONG,	/*[TLONG]*/
-	SZ_LONG,	/*[TULONG]*/
-	SZ_VLONG,	/*[TVLONG]*/
-	SZ_VLONG,	/*[TUVLONG]*/
-	SZ_FLOAT,	/*[TFLOAT]*/
-	SZ_DOUBLE,	/*[TDOUBLE]*/
-	SZ_IND,		/*[TIND]*/
-	0,		/*[TFUNC]*/
-	-1,		/*[TARRAY]*/
-	0,		/*[TVOID]*/
-	-1,		/*[TSTRUCT]*/
-	-1,		/*[TUNION]*/
-	SZ_INT,		/*[TENUM]*/
-};
-int32_t	ncast[NTYPE] =
-{
-	0,				/*[TXXX]*/
-	BCHAR|BUCHAR,			/*[TCHAR]*/
-	BCHAR|BUCHAR,			/*[TUCHAR]*/	
-	BSHORT|BUSHORT,			/*[TSHORT]*/
-	BSHORT|BUSHORT,			/*[TUSHORT]*/
-	BINT|BUINT|BLONG|BULONG|BIND,	/*[TINT]*/		
-	BINT|BUINT|BLONG|BULONG|BIND,	/*[TUINT]*/
-	BINT|BUINT|BLONG|BULONG|BIND,	/*[TLONG]*/
-	BINT|BUINT|BLONG|BULONG|BIND,	/*[TULONG]*/
-	BVLONG|BUVLONG,			/*[TVLONG]*/
-	BVLONG|BUVLONG,			/*[TUVLONG]*/
-	BFLOAT,				/*[TFLOAT]*/
-	BDOUBLE,			/*[TDOUBLE]*/
-	BLONG|BULONG|BIND,		/*[TIND]*/
-	0,				/*[TFUNC]*/
-	0,				/*[TARRAY]*/
-	0,				/*[TVOID]*/
-	BSTRUCT,			/*[TSTRUCT]*/
-	BUNION,				/*[TUNION]*/
-	0,				/*[TENUM]*/
-};

+ 0 - 532
sys/src/cmd/8l/asm.c

@@ -1,532 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include	"l.h"
-
-#define	Dbufslop	100
-
-int32_t
-entryvalue(void)
-{
-	char *a;
-	Sym *s;
-
-	a = INITENTRY;
-	if(*a >= '0' && *a <= '9')
-		return atolwhex(a);
-	s = lookup(a, 0);
-	if(s->type == 0)
-		return INITTEXT;
-	switch(s->type) {
-	case STEXT:
-		break;
-	case SDATA:
-		if(dlm)
-			return s->value+INITDAT;
-	default:
-		diag("entry not text: %s", s->name);
-	}
-	return s->value;
-}
-
-/* these need to take long arguments to be compatible with elf.c */
-void
-wputl(int32_t w)
-{
-	cput(w);
-	cput(w>>8);
-}
-
-void
-wput(int32_t w)
-{
-	cput(w>>8);
-	cput(w);
-}
-
-void
-lput(int32_t l)
-{
-	cput(l>>24);
-	cput(l>>16);
-	cput(l>>8);
-	cput(l);
-}
-
-void
-lputl(int32_t l)
-{
-	cput(l);
-	cput(l>>8);
-	cput(l>>16);
-	cput(l>>24);
-}
-
-void
-llput(int64_t v)
-{
-	lput(v>>32);
-	lput(v);
-}
-
-void
-llputl(int64_t v)
-{
-	lputl(v);
-	lputl(v>>32);
-}
-
-void
-strnput(char *s, int n)
-{
-	for(; *s && n > 0; s++){
-		cput(*s);
-		n--;
-	}
-	while(n > 0){
-		cput(0);
-		n--;
-	}
-}
-
-void
-asmb(void)
-{
-	Prog *p;
-	int32_t v, magic;
-	int a;
-	uint8_t *op1;
-
-	if(debug['v'])
-		Bprint(&bso, "%5.2f asmb\n", cputime());
-	Bflush(&bso);
-
-	seek(cout, HEADR, 0);
-	pc = INITTEXT;
-	curp = firstp;
-	for(p = firstp; p != P; p = p->link) {
-		if(p->as == ATEXT)
-			curtext = p;
-		if(p->pc != pc) {
-			if(!debug['a'])
-				print("%P\n", curp);
-			diag("phase error %lux sb %lux in %s", p->pc, pc, TNAME);
-			pc = p->pc;
-		}
-		curp = p;
-		asmins(p);
-		if(cbc < sizeof(and))
-			cflush();
-		a = (andptr - and);
-		if(debug['a']) {
-			Bprint(&bso, pcstr, pc);
-			for(op1 = and; op1 < andptr; op1++)
-				Bprint(&bso, "%.2ux", *op1 & 0xff);
-			Bprint(&bso, "\t%P\n", curp);
-		}
-		if(dlm) {
-			if(p->as == ATEXT)
-				reloca = nil;
-			else if(reloca != nil)
-				diag("reloc failure: %P", curp);
-		}
-		memmove(cbp, and, a);
-		cbp += a;
-		pc += a;
-		cbc -= a;
-	}
-	cflush();
-	switch(HEADTYPE) {
-	default:
-		diag("unknown header type %ld", HEADTYPE);
-	case 0:
-		seek(cout, rnd(HEADR+textsize, 8192), 0);
-		break;
-	case 1:
-		textsize = rnd(HEADR+textsize, 4096)-HEADR;
-		seek(cout, textsize+HEADR, 0);
-		break;
-	case 2:
-	case 5:
-		seek(cout, HEADR+textsize, 0);
-		break;
-	case 3:
-	case 4:
-		seek(cout, HEADR+rnd(textsize, INITRND), 0);
-		break;
-	}
-
-	if(debug['v'])
-		Bprint(&bso, "%5.2f datblk\n", cputime());
-	Bflush(&bso);
-
-	if(dlm){
-		char buf[8];
-
-		write(cout, buf, INITDAT-textsize);
-		textsize = INITDAT;
-	}
-
-	for(v = 0; v < datsize; v += sizeof(buf)-Dbufslop) {
-		if(datsize-v > sizeof(buf)-Dbufslop)
-			datblk(v, sizeof(buf)-Dbufslop);
-		else
-			datblk(v, datsize-v);
-	}
-
-	symsize = 0;
-	spsize = 0;
-	lcsize = 0;
-	if(!debug['s']) {
-		if(debug['v'])
-			Bprint(&bso, "%5.2f sym\n", cputime());
-		Bflush(&bso);
-		switch(HEADTYPE) {
-		default:
-		case 0:
-			seek(cout, rnd(HEADR+textsize, 8192)+datsize, 0);
-			break;
-		case 1:
-			seek(cout, rnd(HEADR+textsize, INITRND)+datsize, 0);
-			break;
-		case 2:
-		case 5:
-			seek(cout, HEADR+textsize+datsize, 0);
-			break;
-		case 3:
-		case 4:
-			debug['s'] = 1;
-			break;
-		}
-		if(!debug['s'])
-			asmsym();
-		if(debug['v'])
-			Bprint(&bso, "%5.2f sp\n", cputime());
-		Bflush(&bso);
-		if(debug['v'])
-			Bprint(&bso, "%5.2f pc\n", cputime());
-		Bflush(&bso);
-		if(!debug['s'])
-			asmlc();
-		if(dlm)
-			asmdyn();
-		cflush();
-	}
-	else if(dlm){
-		seek(cout, HEADR+textsize+datsize, 0);
-		asmdyn();
-		cflush();
-	}
-	if(debug['v'])
-		Bprint(&bso, "%5.2f headr\n", cputime());
-	Bflush(&bso);
-	seek(cout, 0L, 0);
-	switch(HEADTYPE) {
-	default:
-	case 0:	/* garbage */
-		lput(0x160L<<16);		/* magic and sections */
-		lput(0L);			/* time and date */
-		lput(rnd(HEADR+textsize, 4096)+datsize);
-		lput(symsize);			/* nsyms */
-		lput((0x38L<<16)|7L);		/* size of optional hdr and flags */
-		lput((0413<<16)|0437L);		/* magic and version */
-		lput(rnd(HEADR+textsize, 4096));/* sizes */
-		lput(datsize);
-		lput(bsssize);
-		lput(entryvalue());		/* va of entry */
-		lput(INITTEXT-HEADR);		/* va of base of text */
-		lput(INITDAT);			/* va of base of data */
-		lput(INITDAT+datsize);		/* va of base of bss */
-		lput(~0L);			/* gp reg mask */
-		lput(0L);
-		lput(0L);
-		lput(0L);
-		lput(0L);
-		lput(~0L);			/* gp value ?? */
-		break;
-	case 1:	/* unix coff */
-		/*
-		 * file header
-		 */
-		lputl(0x0004014c);		/* 4 sections, magic */
-		lputl(0);			/* unix time stamp */
-		lputl(0);			/* symbol table */
-		lputl(0);			/* nsyms */
-		lputl(0x0003001c);		/* flags, sizeof a.out header */
-		/*
-		 * a.out header
-		 */
-		lputl(0x10b);			/* magic, version stamp */
-		lputl(rnd(textsize, INITRND));	/* text sizes */
-		lputl(datsize);			/* data sizes */
-		lputl(bsssize);			/* bss sizes */
-		lput(entryvalue());		/* va of entry */
-		lputl(INITTEXT);		/* text start */
-		lputl(INITDAT);			/* data start */
-		/*
-		 * text section header
-		 */
-		strnput(".text", 8);
-		lputl(HEADR);			/* pa */
-		lputl(HEADR);			/* va */
-		lputl(textsize);		/* text size */
-		lputl(HEADR);			/* file offset */
-		lputl(0);			/* relocation */
-		lputl(0);			/* line numbers */
-		lputl(0);			/* relocation, line numbers */
-		lputl(0x20);			/* flags text only */
-		/*
-		 * data section header
-		 */
-		strnput(".data", 8);
-		lputl(INITDAT);			/* pa */
-		lputl(INITDAT);			/* va */
-		lputl(datsize);			/* data size */
-		lputl(HEADR+textsize);		/* file offset */
-		lputl(0);			/* relocation */
-		lputl(0);			/* line numbers */
-		lputl(0);			/* relocation, line numbers */
-		lputl(0x40);			/* flags data only */
-		/*
-		 * bss section header
-		 */
-		strnput(".bss", 8);
-		lputl(INITDAT+datsize);		/* pa */
-		lputl(INITDAT+datsize);		/* va */
-		lputl(bsssize);			/* bss size */
-		lputl(0);			/* file offset */
-		lputl(0);			/* relocation */
-		lputl(0);			/* line numbers */
-		lputl(0);			/* relocation, line numbers */
-		lputl(0x80);			/* flags bss only */
-		/*
-		 * comment section header
-		 */
-		strnput(".comment", 8);
-		lputl(0);			/* pa */
-		lputl(0);			/* va */
-		lputl(symsize+lcsize);		/* comment size */
-		lputl(HEADR+textsize+datsize);	/* file offset */
-		lputl(HEADR+textsize+datsize);	/* offset of syms */
-		lputl(HEADR+textsize+datsize+symsize);/* offset of line numbers */
-		lputl(0);			/* relocation, line numbers */
-		lputl(0x200);			/* flags comment only */
-		break;
-	case 2:	/* plan9 */
-		magic = 4*11*11+7;
-		if(dlm)
-			magic |= 0x80000000;
-		lput(magic);			/* magic */
-		lput(textsize);			/* sizes */
-		lput(datsize);
-		lput(bsssize);
-		lput(symsize);			/* nsyms */
-		lput(entryvalue());		/* va of entry */
-		lput(spsize);			/* sp offsets */
-		lput(lcsize);			/* line offsets */
-		break;
-	case 3:
-		/* MS-DOS .COM */
-		break;
-	case 4:
-		/* fake MS-DOS .EXE */
-		v = rnd(HEADR+textsize, INITRND)+datsize;
-		wputl(0x5A4D);			/* 'MZ' */
-		wputl(v % 512);			/* bytes in last page */
-		wputl(rnd(v, 512)/512);		/* total number of pages */
-		wputl(0x0000);			/* number of reloc items */
-		v = rnd(HEADR-(INITTEXT & 0xFFFF), 16);
-		wputl(v/16);			/* size of header */
-		wputl(0x0000);			/* minimum allocation */
-		wputl(0xFFFF);			/* maximum allocation */
-		wputl(0x0000);			/* initial ss value */
-		wputl(0x0100);			/* initial sp value */
-		wputl(0x0000);			/* complemented checksum */
-		v = entryvalue();
-		wputl(v);			/* initial ip value (!) */
-		wputl(0x0000);			/* initial cs value */
-		wputl(0x0000);
-		wputl(0x0000);
-		wputl(0x003E);			/* reloc table offset */
-		wputl(0x0000);			/* overlay number */
-		break;
-	case 5:
-		elf32(I386, ELFDATA2LSB, 0, nil);
-		break;
-	}
-	cflush();
-}
-
-void
-cflush(void)
-{
-	int n;
-
-	n = sizeof(buf.cbuf) - cbc;
-	if(n)
-		write(cout, buf.cbuf, n);
-	cbp = buf.cbuf;
-	cbc = sizeof(buf.cbuf);
-}
-
-void
-datblk(int32_t s, int32_t n)
-{
-	Prog *p;
-	char *cast;
-	int32_t l, fl, j;
-	int i, c;
-
-	memset(buf.dbuf, 0, n+Dbufslop);
-	for(p = datap; p != P; p = p->link) {
-		curp = p;
-		l = p->from.sym->value + p->from.offset - s;
-		c = p->from.scale;
-		i = 0;
-		if(l < 0) {
-			if(l+c <= 0)
-				continue;
-			while(l < 0) {
-				l++;
-				i++;
-			}
-		}
-		if(l >= n)
-			continue;
-		if(p->as != AINIT && p->as != ADYNT) {
-			for(j=l+(c-i)-1; j>=l; j--)
-				if(buf.dbuf[j]) {
-					print("%P\n", p);
-					diag("multiple initialization");
-					break;
-				}
-		}
-		switch(p->to.type) {
-		case D_FCONST:
-			switch(c) {
-			default:
-			case 4:
-				fl = ieeedtof(&p->to.ieee);
-				cast = (char*)&fl;
-				if(debug['a'] && i == 0) {
-					Bprint(&bso, pcstr, l+s+INITDAT);
-					for(j=0; j<c; j++)
-						Bprint(&bso, "%.2ux", cast[fnuxi4[j]] & 0xff);
-					Bprint(&bso, "\t%P\n", curp);
-				}
-				for(; i<c; i++) {
-					buf.dbuf[l] = cast[fnuxi4[i]];
-					l++;
-				}
-				break;
-			case 8:
-				cast = (char*)&p->to.ieee;
-				if(debug['a'] && i == 0) {
-					Bprint(&bso, pcstr, l+s+INITDAT);
-					for(j=0; j<c; j++)
-						Bprint(&bso, "%.2ux", cast[fnuxi8[j]] & 0xff);
-					Bprint(&bso, "\t%P\n", curp);
-				}
-				for(; i<c; i++) {
-					buf.dbuf[l] = cast[fnuxi8[i]];
-					l++;
-				}
-				break;
-			}
-			break;
-
-		case D_SCONST:
-			if(debug['a'] && i == 0) {
-				Bprint(&bso, pcstr, l+s+INITDAT);
-				for(j=0; j<c; j++)
-					Bprint(&bso, "%.2ux", p->to.scon[j] & 0xff);
-				Bprint(&bso, "\t%P\n", curp);
-			}
-			for(; i<c; i++) {
-				buf.dbuf[l] = p->to.scon[i];
-				l++;
-			}
-			break;
-		default:
-			fl = p->to.offset;
-			if(p->to.type == D_ADDR) {
-				if(p->to.index != D_STATIC && p->to.index != D_EXTERN)
-					diag("DADDR type%P", p);
-				if(p->to.sym) {
-					if(p->to.sym->type == SUNDEF)
-						ckoff(p->to.sym, fl);
-					fl += p->to.sym->value;
-					if(p->to.sym->type != STEXT && p->to.sym->type != SUNDEF)
-						fl += INITDAT;
-					if(dlm)
-						dynreloc(p->to.sym, l+s+INITDAT, 1);
-				}
-			}
-			cast = (char*)&fl;
-			switch(c) {
-			default:
-				diag("bad nuxi %d %d\n%P", c, i, curp);
-				break;
-			case 1:
-				if(debug['a'] && i == 0) {
-					Bprint(&bso, pcstr, l+s+INITDAT);
-					for(j=0; j<c; j++)
-						Bprint(&bso, "%.2ux", cast[inuxi1[j]] & 0xff);
-					Bprint(&bso, "\t%P\n", curp);
-				}
-				for(; i<c; i++) {
-					buf.dbuf[l] = cast[inuxi1[i]];
-					l++;
-				}
-				break;
-			case 2:
-				if(debug['a'] && i == 0) {
-					Bprint(&bso, pcstr, l+s+INITDAT);
-					for(j=0; j<c; j++)
-						Bprint(&bso, "%.2ux", cast[inuxi2[j]] & 0xff);
-					Bprint(&bso, "\t%P\n", curp);
-				}
-				for(; i<c; i++) {
-					buf.dbuf[l] = cast[inuxi2[i]];
-					l++;
-				}
-				break;
-			case 4:
-				if(debug['a'] && i == 0) {
-					Bprint(&bso, pcstr, l+s+INITDAT);
-					for(j=0; j<c; j++)
-						Bprint(&bso, "%.2ux", cast[inuxi4[j]] & 0xff);
-					Bprint(&bso, "\t%P\n", curp);
-				}
-				for(; i<c; i++) {
-					buf.dbuf[l] = cast[inuxi4[i]];
-					l++;
-				}
-				break;
-			}
-			break;
-		}
-	}
-	write(cout, buf.dbuf, n);
-}
-
-int32_t
-rnd(int32_t v, int32_t r)
-{
-	int32_t c;
-
-	if(r <= 0)
-		return v;
-	v += r - 1;
-	c = v % r;
-	if(c < 0)
-		c += r;
-	v -= c;
-	return v;
-}

+ 0 - 74
sys/src/cmd/8l/compat.c

@@ -1,74 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include	"l.h"
-
-/*
- * fake malloc
- */
-void*
-malloc(uint32_t n)
-{
-	void *p;
-
-	while(n & 7)
-		n++;
-	while(nhunk < n)
-		gethunk();
-	p = hunk;
-	nhunk -= n;
-	hunk += n;
-	return p;
-}
-
-void
-free(void *p)
-{
-	USED(p);
-}
-
-void*
-calloc(uint32_t m, uint32_t n)
-{
-	void *p;
-
-	n *= m;
-	p = malloc(n);
-	memset(p, 0, n);
-	return p;
-}
-
-void*
-realloc(void*, uint32_t)
-{
-	fprint(2, "realloc called\n");
-	abort();
-	return 0;
-}
-
-void*
-mysbrk(uint32_t size)
-{
-	return sbrk(size);
-}
-
-void
-setmalloctag(void *v, uint32_t pc)
-{
-	USED(v, pc);
-}
-
-int
-fileexists(char *s)
-{
-	uint8_t dirbuf[400];
-
-	/* it's fine if stat result doesn't fit in dirbuf, since even then the file exists */
-	return stat(s, dirbuf, sizeof(dirbuf)) >= 0;
-}

+ 0 - 275
sys/src/cmd/8l/elf.c

@@ -1,275 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-/*
- * emit 32- or 64-bit elf headers for any architecture.
- * this is a component of ?l.
- */
-#include "l.h"
-
-enum {
-	/* offsets into string table */
-	Stitext		= 1,
-	Stidata		= 7,
-	Stistrtab	= 13,
-};
-
-void
-elfident(int bo, int class)
-{
-	strnput("\177ELF", 4);		/* e_ident */
-	cput(class);
-	cput(bo);			/* byte order */
-	cput(1);			/* version = CURRENT */
-	if(debug['k']){			/* boot/embedded/standalone */
-		cput(255);
-		cput(0);
-	}
-	else{
-		cput(0);		/* osabi = SYSV */
-		cput(0);		/* abiversion = 3 */
-	}
-	strnput("", 7);
-}
-
-void
-elfstrtab(void)
-{
-	/* string table */
-	cput(0);
-	strnput(".text", 5);		/* +1 */
-	cput(0);
-	strnput(".data", 5);		/* +7 */
-	cput(0);
-	strnput(".strtab", 7);		/* +13 */
-	cput(0);
-	cput(0);
-}
-
-void
-elf32phdr(void (*putl)(long), ulong type, ulong off, ulong vaddr, ulong paddr,
-	ulong filesz, ulong memsz, ulong prots, ulong align)
-{
-	putl(type);
-	putl(off);
-	putl(vaddr);
-	putl(paddr);
-	putl(filesz);
-	putl(memsz);
-	putl(prots);
-	putl(align);
-}
-
-void
-elf32shdr(void (*putl)(long), ulong name, ulong type, ulong flags, ulong vaddr,
-	ulong off, ulong sectsz, ulong link, ulong addnl, ulong align,
-	ulong entsz)
-{
-	putl(name);
-	putl(type);
-	putl(flags);
-	putl(vaddr);
-	putl(off);
-	putl(sectsz);
-	putl(link);
-	putl(addnl);
-	putl(align);
-	putl(entsz);
-}
-
-static void
-elf32sectab(void (*putl)(long))
-{
-	seek(cout, HEADR+textsize+datsize+symsize, 0);
-	elf32shdr(putl, Stitext, Progbits, Salloc|Sexec, INITTEXT,
-		HEADR, textsize, 0, 0, 0x10000, 0);
-	elf32shdr(putl, Stidata, Progbits, Salloc|Swrite, INITDAT,
-		HEADR+textsize, datsize, 0, 0, 0x10000, 0);
-	elf32shdr(putl, Stistrtab, Strtab, 1 << 5, 0,
-		HEADR+textsize+datsize+symsize+3*Shdr32sz, 14, 0, 0, 1, 0);
-	elfstrtab();
-}
-
-/* if addpsects > 0, putpsects must emit exactly that many psects. */
-void
-elf32(int mach, int bo, int addpsects, void (*putpsects)(Putl))
-{
-	ulong phydata;
-	void (*putw)(long), (*putl)(long);
-
-	if(bo == ELFDATA2MSB){
-		putw = wput;
-		putl = lput;
-	}else if(bo == ELFDATA2LSB){
-		putw = wputl;
-		putl = lputl;
-	}else{
-		print("elf32 byte order is mixed-endian\n");
-		errorexit();
-		return;
-	}
-
-	elfident(bo, ELFCLASS32);
-	putw(EXEC);
-	putw(mach);
-	putl(1L);			/* version = CURRENT */
-	putl(entryvalue());		/* entry vaddr */
-	putl(Ehdr32sz);			/* offset to first phdr */
-	if(debug['S'])
-		putl(HEADR+textsize+datsize+symsize); /* offset to first shdr */
-	else
-		putl(0);
-	putl(0L);			/* flags */
-	putw(Ehdr32sz);
-	putw(Phdr32sz);
-	putw(3 + addpsects);		/* # of Phdrs */
-	putw(Shdr32sz);
-	if(debug['S']){
-		putw(3);		/* # of Shdrs */
-		putw(2);		/* Shdr table index */
-	}else{
-		putw(0);
-		putw(0);
-	}
-
-	/*
-	 * could include ELF headers in text -- 8l doesn't,
-	 * but in theory it aids demand loading.
-	 */
-	elf32phdr(putl, PT_LOAD, HEADR, INITTEXT, INITTEXTP,
-		textsize, textsize, R|X, INITRND);	/* text */
-	/*
-	 * we need INITDATP, but it has to be computed.
-	 * assume distance between INITTEXT & INITTEXTP is also
-	 * correct for INITDAT and INITDATP.
-	 */
-	phydata = INITDAT - (INITTEXT - INITTEXTP);
-	elf32phdr(putl, PT_LOAD, HEADR+textsize, INITDAT, phydata,
-		datsize, datsize+bsssize, R|W|X, INITRND); /* data */
-	elf32phdr(putl, NOPTYPE, HEADR+textsize+datsize, 0, 0,
-		symsize, lcsize, R, 4);			/* symbol table */
-	if (addpsects > 0)
-		putpsects(putl);
-	cflush();
-
-	if(debug['S'])
-		elf32sectab(putl);
-}
-
-/*
- * elf64
- */
-
-void
-elf64phdr(void (*putl)(long), void (*putll)(vlong), ulong type, uvlong off,
-	uvlong vaddr, uvlong paddr, uvlong filesz, uvlong memsz, ulong prots,
-	uvlong align)
-{
-	putl(type);		
-	putl(prots);		
-	putll(off);		
-	putll(vaddr);	
-	putll(paddr);	
-	putll(filesz);	
-	putll(memsz);	
-	putll(align);		
-}
-
-void
-elf64shdr(void (*putl)(long), void (*putll)(vlong), ulong name, ulong type,
-	uvlong flags, uvlong vaddr, uvlong off, uvlong sectsz, ulong link,
-	ulong addnl, uvlong align, uvlong entsz)
-{
-	putl(name);
-	putl(type);
-	putll(flags);
-	putll(vaddr);
-	putll(off);
-	putll(sectsz);
-	putl(link);
-	putl(addnl);
-	putll(align);
-	putll(entsz);
-}
-
-static void
-elf64sectab(void (*putl)(long), void (*putll)(vlong))
-{
-	seek(cout, HEADR+textsize+datsize+symsize, 0);
-	elf64shdr(putl, putll, Stitext, Progbits, Salloc|Sexec, INITTEXT,
-		HEADR, textsize, 0, 0, 0x10000, 0);
-	elf64shdr(putl, putll, Stidata, Progbits, Salloc|Swrite, INITDAT,
-		HEADR+textsize, datsize, 0, 0, 0x10000, 0);
-	elf64shdr(putl, putll, Stistrtab, Strtab, 1 << 5, 0,
-		HEADR+textsize+datsize+symsize+3*Shdr64sz, 14, 0, 0, 1, 0);
-	elfstrtab();
-}
-
-/* if addpsects > 0, putpsects must emit exactly that many psects. */
-void
-elf64(int mach, int bo, int addpsects, void (*putpsects)(Putl))
-{
-	uvlong phydata;
-	void (*putw)(long), (*putl)(long);
-	void (*putll)(vlong);
-
-	if(bo == ELFDATA2MSB){
-		putw = wput;
-		putl = lput;
-		putll = llput;
-	}else if(bo == ELFDATA2LSB){
-		putw = wputl;
-		putl = lputl;
-		putll = llputl;
-	}else{
-		print("elf64 byte order is mixed-endian\n");
-		errorexit();
-		return;
-	}
-
-	elfident(bo, ELFCLASS64);
-	putw(EXEC);
-	putw(mach);
-	putl(1L);			/* version = CURRENT */
-	putll(entryvalue());		/* entry vaddr */
-	putll(Ehdr64sz);		/* offset to first phdr */
-	if(debug['S'])
-		putll(HEADR+textsize+datsize+symsize); /* offset to 1st shdr */
-	else
-		putll(0);
-	putl(0L);			/* flags */
-	putw(Ehdr64sz);
-	putw(Phdr64sz);
-	putw(3 + addpsects);		/* # of Phdrs */
-	putw(Shdr64sz);
-	if(debug['S']){
-		putw(3);		/* # of Shdrs */
-		putw(2);		/* Shdr table index */
-	}else{
-		putw(0);
-		putw(0);
-	}
-
-	elf64phdr(putl, putll, PT_LOAD, HEADR, INITTEXT, INITTEXTP,
-		textsize, textsize, R|X, INITRND);	/* text */
-	/*
-	 * see 32-bit ELF case for physical data address computation.
-	 */
-	phydata = INITDAT - (INITTEXT - INITTEXTP);
-	elf64phdr(putl, putll, PT_LOAD, HEADR+textsize, INITDAT, phydata,
-		datsize, datsize+bsssize, R|W, INITRND); /* data */
-	elf64phdr(putl, putll, NOPTYPE, HEADR+textsize+datsize, 0, 0,
-		symsize, lcsize, R, 4);			/* symbol table */
-	if (addpsects > 0)
-		putpsects(putl);
-	cflush();
-
-	if(debug['S'])
-		elf64sectab(putl, putll);
-}

+ 0 - 111
sys/src/cmd/8l/elf.h

@@ -1,111 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-enum {
-	Ehdr32sz	= 52,
-	Phdr32sz	= 32,
-	Shdr32sz	= 40,
-
-	Ehdr64sz	= 64,
-	Phdr64sz	= 56,
-	Shdr64sz	= 64,
-};
-
-/* from /sys/src/libmach/elf.h */
-enum {
-	/* Ehdr codes */
-	MAG0 = 0,		/* ident[] indexes */
-	MAG1 = 1,
-	MAG2 = 2,
-	MAG3 = 3,
-	CLASS = 4,
-	DATA = 5,
-	VERSION = 6,
-
-	ELFCLASSNONE = 0,	/* ident[CLASS] */
-	ELFCLASS32 = 1,
-	ELFCLASS64 = 2,
-	ELFCLASSNUM = 3,
-
-	ELFDATANONE = 0,	/* ident[DATA] */
-	ELFDATA2LSB = 1,
-	ELFDATA2MSB = 2,
-	ELFDATANUM = 3,
-
-	NOETYPE = 0,		/* type */
-	REL = 1,
-	EXEC = 2,
-	DYN = 3,
-	CORE = 4,
-
-	NONE = 0,		/* machine */
-	M32 = 1,		/* AT&T WE 32100 */
-	SPARC = 2,		/* Sun SPARC */
-	I386 = 3,		/* Intel 80386 */
-	M68K = 4,		/* Motorola 68000 */
-	M88K = 5,		/* Motorola 88000 */
-	I486 = 6,		/* Intel 80486 */
-	I860 = 7,		/* Intel i860 */
-	MIPS = 8,		/* Mips R2000 */
-	S370 = 9,		/* Amdhal	*/
-	MIPSR4K = 10,		/* Mips R4000 */
-	SPARC64 = 18,		/* Sun SPARC v9 */
-	POWER = 20,		/* PowerPC */
-	POWER64 = 21,		/* PowerPC64 */
-	ARM = 40,		/* ARM */
-	AMD64 = 62,		/* Amd64 */
-	ARM64 = 183,		/* ARM64 */
-
-	NO_VERSION = 0,		/* version, ident[VERSION] */
-	CURRENT = 1,
-
-	/* Phdr Codes */
-	NOPTYPE = 0,		/* type */
-	PT_LOAD = 1,
-	DYNAMIC = 2,
-	INTERP = 3,
-	NOTE = 4,
-	SHLIB = 5,
-	PHDR = 6,
-
-	R = 0x4,		/* flags */
-	W = 0x2,
-	X = 0x1,
-
-	/* Shdr Codes */
-	Progbits = 1,	/* section types */
-	Strtab = 3,
-	Nobits = 8,
-
-	Swrite = 1,	/* section attributes (flags) */
-	Salloc = 2,
-	Sexec = 4,
-};
-
-typedef void (*Putl)(long);
-
-void	elf32(int mach, int bo, int addpsects, void (*putpsects)(Putl));
-void	elf32phdr(void (*putl)(long), uint32_t type, uint32_t off,
-		      uint32_t vaddr,
-	uint32_t paddr, uint32_t filesz, uint32_t memsz, uint32_t prots,
-		      uint32_t align);
-void	elf32shdr(void (*putl)(long), uint32_t name, uint32_t type,
-		      uint32_t flags,
-	uint32_t vaddr, uint32_t off, uint32_t sectsz, uint32_t link,
-		      uint32_t addnl,
-	uint32_t align, uint32_t entsz);
-
-void	elf64(int mach, int bo, int addpsects, void (*putpsects)(Putl));
-void	elf64phdr(void (*putl)(long), void (*putll)(vlong), uint32_t type,
-	uvlong off, uvlong vaddr, uvlong paddr, uvlong filesz, uvlong memsz,
-	uint32_t prots, uvlong align);
-void	elf64shdr(void (*putl)(long), void (*putll)(vlong), uint32_t name,
-	uint32_t type, uvlong flags, uvlong vaddr, uvlong off,
-		      uvlong sectsz,
-	uint32_t link, uint32_t addnl, uvlong align, uvlong entsz);

+ 0 - 374
sys/src/cmd/8l/l.h

@@ -1,374 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include	<u.h>
-#include	<libc.h>
-#include	<bio.h>
-#include	"../8c/8.out.h"
-#include	"../8l/elf.h"
-
-#ifndef	EXTERN
-#define	EXTERN	extern
-#endif
-
-#define	P		((Prog*)0)
-#define	S		((Sym*)0)
-#define	TNAME		(curtext?curtext->from.sym->name:noname)
-
-#define	cput(c)\
-	{ *cbp++ = c;\
-	if(--cbc <= 0)\
-		cflush(); }
-
-#define	LIBNAMELEN	300
-
-typedef	struct	Adr	Adr;
-typedef	struct	Prog	Prog;
-typedef	struct	Sym	Sym;
-typedef	struct	Auto	Auto;
-typedef	struct	Optab	Optab;
-
-struct	Adr
-{
-	union
-	{
-		long	u0offset;
-		char	u0scon[8];
-		Prog	*u0cond;	/* not used, but should be D_BRANCH */
-		Ieee	u0ieee;
-	} u0;
-	union
-	{
-		Auto*	u1autom;
-		Sym*	u1sym;
-	} u1;
-	short	type;
-	uchar	index;
-	char	scale;
-};
-
-#define	offset	u0.u0offset
-#define	scon	u0.u0scon
-#define	cond	u0.u0cond
-#define	ieee	u0.u0ieee
-
-#define	autom	u1.u1autom
-#define	sym	u1.u1sym
-
-struct	Prog
-{
-	Adr	from;
-	Adr	to;
-	Prog	*forwd;
-	Prog*	link;
-	Prog*	pcond;	/* work on this */
-	long	pc;
-	long	line;
-	short	as;
-	char	width;		/* fake for DATA */
-	char	ft;		/* oclass cache */
-	char	tt;
-	uchar	mark;	/* work on these */
-	uchar	back;
-};
-struct	Auto
-{
-	Sym*	asym;
-	Auto*	link;
-	long	aoffset;
-	short	type;
-};
-struct	Sym
-{
-	char	*name;
-	short	type;
-	short	version;
-	short	become;
-	short	frame;
-	uchar	subtype;
-	ushort	file;
-	long	value;
-	long	sig;
-	Sym*	link;
-};
-struct	Optab
-{
-	short	as;
-	uchar*	ytab;
-	uchar	prefix;
-	uchar	op[10];
-};
-
-enum
-{
-	STEXT		= 1,
-	SDATA,
-	SBSS,
-	SDATA1,
-	SXREF,
-	SFILE,
-	SCONST,
-	SUNDEF,
-
-	SIMPORT,
-	SEXPORT,
-
-	NHASH		= 10007,
-	NHUNK		= 100000,
-	MINSIZ		= 4,
-	STRINGSZ	= 200,
-	MINLC		= 1,
-	MAXIO		= 8192,
-	MAXHIST		= 20,				/* limit of path elements for history symbols */
-
-	Yxxx		= 0,
-	Ynone,
-	Yi0,
-	Yi1,
-	Yi8,
-	Yi32,
-	Yiauto,
-	Yal,
-	Ycl,
-	Yax,
-	Ycx,
-	Yrb,
-	Yrl,
-	Yrf,
-	Yf0,
-	Yrx,
-	Ymb,
-	Yml,
-	Ym,
-	Ybr,
-	Ycol,
-
-	Ycs,	Yss,	Yds,	Yes,	Yfs,	Ygs,
-	Ygdtr,	Yidtr,	Yldtr,	Ymsw,	Ytask,
-	Ycr0,	Ycr1,	Ycr2,	Ycr3,	Ycr4,	Ycr5,	Ycr6,	Ycr7,
-	Ydr0,	Ydr1,	Ydr2,	Ydr3,	Ydr4,	Ydr5,	Ydr6,	Ydr7,
-	Ytr0,	Ytr1,	Ytr2,	Ytr3,	Ytr4,	Ytr5,	Ytr6,	Ytr7,
-	Ymax,
-
-	Zxxx		= 0,
-
-	Zlit,
-	Z_rp,
-	Zbr,
-	Zcall,
-	Zib_,
-	Zib_rp,
-	Zibo_m,
-	Zil_,
-	Zil_rp,
-	Zilo_m,
-	Zjmp,
-	Zloop,
-	Zm_o,
-	Zm_r,
-	Zaut_r,
-	Zo_m,
-	Zpseudo,
-	Zr_m,
-	Zrp_,
-	Z_ib,
-	Z_il,
-	Zm_ibo,
-	Zm_ilo,
-	Zib_rr,
-	Zil_rr,
-	Zclr,
-	Zbyte,
-	Zmov,
-	Zmax,
-
-	Px		= 0,
-	Pe		= 0x66,	/* operand escape */
-	Pm		= 0x0f,	/* 2byte opcode escape */
-	Pq		= 0xff,	/* both escape */
-	Pb		= 0xfe,	/* byte operands */
-
-	Roffset	= 22,		/* no. bits for offset in relocation address */
-	Rindex	= 10,		/* no. bits for index in relocation address */
-};
-
-EXTERN union
-{
-	struct
-	{
-		char	obuf[MAXIO];			/* output buffer */
-		uchar	ibuf[MAXIO];			/* input buffer */
-	} u;
-	char	dbuf[1];
-} buf;
-
-#define	cbuf	u.obuf
-#define	xbuf	u.ibuf
-
-#pragma	varargck	type	"A"	int
-#pragma	varargck	type	"A"	uint
-#pragma	varargck	type	"D"	Adr*
-#pragma	varargck	type	"P"	Prog*
-#pragma	varargck	type	"R"	int
-#pragma	varargck	type	"R"	uint
-#pragma	varargck	type	"S"	char*
-
-#pragma	varargck	argpos	diag 1
-
-EXTERN	long	HEADR;
-EXTERN	long	HEADTYPE;
-EXTERN	long	INITDAT;
-EXTERN	long	INITRND;
-EXTERN	long	INITTEXT;
-EXTERN	long	INITTEXTP;
-EXTERN	char*	INITENTRY;		/* entry point */
-EXTERN	Biobuf	bso;
-EXTERN	long	bsssize;
-EXTERN	long	casepc;
-EXTERN	int	cbc;
-EXTERN	char*	cbp;
-EXTERN	char*	pcstr;
-EXTERN	int	cout;
-EXTERN	Auto*	curauto;
-EXTERN	Auto*	curhist;
-EXTERN	Prog*	curp;
-EXTERN	Prog*	curtext;
-EXTERN	Prog*	datap;
-EXTERN	Prog*	edatap;
-EXTERN	long	datsize;
-EXTERN	char	debug[128];
-EXTERN	char	literal[32];
-EXTERN	Prog*	etextp;
-EXTERN	Prog*	firstp;
-EXTERN	char	fnuxi8[8];
-EXTERN	char	fnuxi4[4];
-EXTERN	Sym*	hash[NHASH];
-EXTERN	Sym*	histfrog[MAXHIST];
-EXTERN	int	histfrogp;
-EXTERN	int	histgen;
-EXTERN	char*	library[50];
-EXTERN	char*	libraryobj[50];
-EXTERN	int	libraryp;
-EXTERN	int	xrefresolv;
-EXTERN	char*	hunk;
-EXTERN	char	inuxi1[1];
-EXTERN	char	inuxi2[2];
-EXTERN	char	inuxi4[4];
-EXTERN	char	ycover[Ymax*Ymax];
-EXTERN	uchar*	andptr;
-EXTERN	uchar	and[30];
-EXTERN	char	reg[D_NONE];
-EXTERN	Prog*	lastp;
-EXTERN	long	lcsize;
-EXTERN	int	nerrors;
-EXTERN	long	nhunk;
-EXTERN	long	nsymbol;
-EXTERN	char*	noname;
-EXTERN	char*	outfile;
-EXTERN	long	pc;
-EXTERN	long	spsize;
-EXTERN	Sym*	symlist;
-EXTERN	long	symsize;
-EXTERN	Prog*	textp;
-EXTERN	long	textsize;
-EXTERN	long	thunk;
-EXTERN	int	version;
-EXTERN	Prog	zprg;
-EXTERN	int	dtype;
-
-EXTERN	Adr*	reloca;
-EXTERN	int	doexp, dlm;
-EXTERN	int	imports, nimports;
-EXTERN	int	exports, nexports, allexport;
-EXTERN	char*	EXPTAB;
-EXTERN	Prog	undefp;
-
-#define	UP	(&undefp)
-
-extern	Optab	optab[];
-extern	char*	anames[];
-
-int	Aconv(Fmt*);
-int	Dconv(Fmt*);
-int	Pconv(Fmt*);
-int	Rconv(Fmt*);
-int	Sconv(Fmt*);
-void	addhist(long, int);
-void	addlibpath(char*);
-Prog*	appendp(Prog*);
-void	asmb(void);
-void	asmdyn(void);
-void	asmins(Prog*);
-void	asmlc(void);
-void	asmsp(void);
-void	asmsym(void);
-long	atolwhex(char*);
-Prog*	brchain(Prog*);
-Prog*	brloop(Prog*);
-void	cflush(void);
-void	ckoff(Sym*, long);
-Prog*	copyp(Prog*);
-double	cputime(void);
-void	datblk(long, long);
-void	diag(char*, ...);
-void	dodata(void);
-void	doinit(void);
-void	doprof1(void);
-void	doprof2(void);
-void	dostkoff(void);
-void	dynreloc(Sym*, uint32_t, int);
-long	entryvalue(void);
-void	errorexit(void);
-void	export(void);
-int	fileexists(char*);
-int	find1(long, int);
-int	find2(long, int);
-char*	findlib(char*);
-void	follow(void);
-void	gethunk(void);
-void	histtoauto(void);
-double	ieeedtod(Ieee*);
-long	ieeedtof(Ieee*);
-void	import(void);
-void	ldobj(int, long, char*);
-void	loadlib(void);
-void	listinit(void);
-Sym*	lookup(char*, int);
-void	lput(long);
-void	lputl(long);
-void	llput(vlong v);
-void	llputl(vlong v);
-void	main(int, char*[]);
-void	mkfwd(void);
-void*	mysbrk(uint32_t);
-void	nuxiinit(void);
-void	objfile(char*);
-int	opsize(Prog*);
-void	patch(void);
-Prog*	prg(void);
-void	readundefs(char*, int);
-int	relinv(int);
-long	reuse(Prog*, Sym*);
-long	rnd(long, long);
-void	span(void);
-void	strnput(char*, int);
-void	undef(void);
-void	undefsym(Sym*);
-long	vaddr(Adr*);
-void	wput(long);
-void	wputl(long);
-void	xdefine(char*, int, long);
-void	xfol(Prog*);
-int	zaddr(uchar*, Adr*, Sym*[]);
-void	zerosig(char*);
-
-#pragma	varargck	type	"D"	Adr*
-#pragma	varargck	type	"P"	Prog*
-#pragma	varargck	type	"R"	int
-#pragma	varargck	type	"A"	int

+ 0 - 301
sys/src/cmd/8l/list.c

@@ -1,301 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include	"l.h"
-
-void
-listinit(void)
-{
-
-	fmtinstall('R', Rconv);
-	fmtinstall('A', Aconv);
-	fmtinstall('D', Dconv);
-	fmtinstall('S', Sconv);
-	fmtinstall('P', Pconv);
-}
-
-static	Prog	*bigP;
-
-int
-Pconv(Fmt *fp)
-{
-	char str[STRINGSZ];
-	Prog *p;
-
-	p = va_arg(fp->args, Prog*);
-	bigP = p;
-	switch(p->as) {
-	case ATEXT:
-		if(p->from.scale) {
-			snprint(str, sizeof(str), "(%ld)	%A	%D,%d,%D",
-				p->line, p->as, &p->from, p->from.scale, &p->to);
-			break;
-		}
-	default:
-		snprint(str, sizeof(str), "(%ld)	%A	%D,%D",
-			p->line, p->as, &p->from, &p->to);
-		break;
-	case ADATA:
-	case AINIT:
-	case ADYNT:
-		snprint(str, sizeof(str), "(%ld)	%A	%D/%d,%D",
-			p->line, p->as, &p->from, p->from.scale, &p->to);
-		break;
-	}
-	bigP = P;
-	return fmtstrcpy(fp, str);
-}
-
-int
-Aconv(Fmt *fp)
-{
-	int i;
-
-	i = va_arg(fp->args, int);
-	return fmtstrcpy(fp, anames[i]);
-}
-
-int
-Dconv(Fmt *fp)
-{
-	char str[STRINGSZ+40], s[20];
-	Adr *a;
-	int i;
-
-	a = va_arg(fp->args, Adr*);
-	i = a->type;
-	if(i >= D_INDIR) {
-		if(a->offset)
-			snprint(str, sizeof(str), "%ld(%R)", a->offset, i-D_INDIR);
-		else
-			snprint(str, sizeof(str), "(%R)", i-D_INDIR);
-		goto brk;
-	}
-	switch(i) {
-
-	default:
-		snprint(str, sizeof(str), "%R", i);
-		break;
-
-	case D_NONE:
-		str[0] = 0;
-		break;
-
-	case D_BRANCH:
-		if(bigP != P && bigP->pcond != P)
-			if(a->sym != S)
-				snprint(str, sizeof(str), "%lux+%s", bigP->pcond->pc,
-					a->sym->name);
-			else
-				snprint(str, sizeof(str), "%lux", bigP->pcond->pc);
-		else
-			snprint(str, sizeof(str), "%ld(PC)", a->offset);
-		break;
-
-	case D_EXTERN:
-		snprint(str, sizeof(str), "%s+%ld(SB)", a->sym->name, a->offset);
-		break;
-
-	case D_STATIC:
-		snprint(str, sizeof(str), "%s<%d>+%ld(SB)", a->sym->name,
-			a->sym->version, a->offset);
-		break;
-
-	case D_AUTO:
-		snprint(str, sizeof(str), "%s+%ld(SP)", a->sym->name, a->offset);
-		break;
-
-	case D_PARAM:
-		if(a->sym)
-			snprint(str, sizeof(str), "%s+%ld(FP)", a->sym->name, a->offset);
-		else
-			snprint(str, sizeof(str), "%ld(FP)", a->offset);
-		break;
-
-	case D_CONST:
-		snprint(str, sizeof(str), "$%ld", a->offset);
-		break;
-
-	case D_FCONST:
-		snprint(str, sizeof(str), "$(%.8lux,%.8lux)", a->ieee.h, a->ieee.l);
-		break;
-
-	case D_SCONST:
-		snprint(str, sizeof(str), "$\"%S\"", a->scon);
-		break;
-
-	case D_ADDR:
-		a->type = a->index;
-		a->index = D_NONE;
-		snprint(str, sizeof(str), "$%D", a);
-		a->index = a->type;
-		a->type = D_ADDR;
-		goto conv;
-	}
-brk:
-	if(a->index != D_NONE) {
-		snprint(s, sizeof(s), "(%R*%d)", a->index, a->scale);
-		strcat(str, s);
-	}
-conv:
-	return fmtstrcpy(fp, str);
-}
-
-char*	regstr[] =
-{
-	"AL",		/* [D_AL] */
-	"CL",
-	"DL",
-	"BL",
-	"AH",
-	"CH",
-	"DH",
-	"BH",
-
-	"AX",		/* [D_AX] */
-	"CX",
-	"DX",
-	"BX",
-	"SP",
-	"BP",
-	"SI",
-	"DI",
-
-	"F0",		/* [D_F0] */
-	"F1",
-	"F2",
-	"F3",
-	"F4",
-	"F5",
-	"F6",
-	"F7",
-
-	"CS",		/* [D_CS] */
-	"SS",
-	"DS",
-	"ES",
-	"FS",
-	"GS",
-
-	"GDTR",		/* [D_GDTR] */
-	"IDTR",		/* [D_IDTR] */
-	"LDTR",		/* [D_LDTR] */
-	"MSW",		/* [D_MSW] */
-	"TASK",		/* [D_TASK] */
-
-	"CR0",		/* [D_CR] */
-	"CR1",
-	"CR2",
-	"CR3",
-	"CR4",
-	"CR5",
-	"CR6",
-	"CR7",
-
-	"DR0",		/* [D_DR] */
-	"DR1",
-	"DR2",
-	"DR3",
-	"DR4",
-	"DR5",
-	"DR6",
-	"DR7",
-
-	"TR0",		/* [D_TR] */
-	"TR1",
-	"TR2",
-	"TR3",
-	"TR4",
-	"TR5",
-	"TR6",
-	"TR7",
-
-	"NONE",		/* [D_NONE] */
-};
-
-int
-Rconv(Fmt *fp)
-{
-	char str[20];
-	int r;
-
-	r = va_arg(fp->args, int);
-	if(r >= D_AL && r <= D_NONE)
-		snprint(str, sizeof(str), "%s", regstr[r-D_AL]);
-	else
-		snprint(str, sizeof(str), "gok(%d)", r);
-
-	return fmtstrcpy(fp, str);
-}
-
-int
-Sconv(Fmt *fp)
-{
-	int i, c;
-	char str[30], *p, *a;
-
-	a = va_arg(fp->args, char*);
-	p = str;
-	for(i=0; i<sizeof(double); i++) {
-		c = a[i] & 0xff;
-		if(c >= 'a' && c <= 'z' ||
-		   c >= 'A' && c <= 'Z' ||
-		   c >= '0' && c <= '9') {
-			*p++ = c;
-			continue;
-		}
-		*p++ = '\\';
-		switch(c) {
-		default:
-			if(c < 040 || c >= 0177)
-				break;	/* not portable */
-			p[-1] = c;
-			continue;
-		case 0:
-			*p++ = 'z';
-			continue;
-		case '\\':
-		case '"':
-			*p++ = c;
-			continue;
-		case '\n':
-			*p++ = 'n';
-			continue;
-		case '\t':
-			*p++ = 't';
-			continue;
-		}
-		*p++ = (c>>6) + '0';
-		*p++ = ((c>>3) & 7) + '0';
-		*p++ = (c & 7) + '0';
-	}
-	*p = 0;
-	return fmtstrcpy(fp, str);
-}
-
-void
-diag(char *fmt, ...)
-{
-	char buf[STRINGSZ], *tn;
-	va_list arg;
-
-	tn = "??none??";
-	if(curtext != P && curtext->from.sym != S)
-		tn = curtext->from.sym->name;
-	va_start(arg, fmt);
-	vseprint(buf, buf+sizeof(buf), fmt, arg);
-	va_end(arg);
-	print("%s: %s\n", tn, buf);
-
-	nerrors++;
-	if(nerrors > 20 && !debug['A']) {
-		print("too many errors\n");
-		errorexit();
-	}
-}

+ 0 - 35
sys/src/cmd/8l/mkfile

@@ -1,35 +0,0 @@
-</$objtype/mkfile
-
-TARG=8l
-OFILES=\
-	asm.$O\
-	obj.$O\
-	optab.$O\
-	pass.$O\
-	span.$O\
-	list.$O\
-	enam.$O\
-	compat.$O\
-	elf.$O\
-
-HFILES=\
-	l.h\
-	../8c/8.out.h\
-	../8l/elf.h\
-
-BIN=/$objtype/bin
-CFLAGS=$CFLAGS -. -I.
-CFILES=${OFILES:%.$O=%.c}
-CFILES=${CFILES:enam.c=../8c/enam.c}
-UPDATE=\
-	mkfile\
-	$HFILES\
-	$CFILES\
-	${TARG:%=/386/bin/%}\
-
-</sys/src/cmd/mkone
-
-enam.$O:	../8c/enam.c
-	$CC $CFLAGS ../8c/enam.c
-elf.$O:	../8l/elf.c
-	$CC $CFLAGS ../8l/elf.c

+ 0 - 1626
sys/src/cmd/8l/obj.c

@@ -1,1626 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#define	EXTERN
-#include	"l.h"
-#include	<ar.h>
-
-#ifndef	DEFAULT
-#define	DEFAULT	'9'
-#endif
-
-char	*noname		= "<none>";
-char	symname[]	= SYMDEF;
-char	thechar		= '8';
-char	*thestring 	= "386";
-
-char**	libdir;
-int	nlibdir	= 0;
-static	int	maxlibdir = 0;
-
-/*
- *	-H0 -T0x40004C -D0x10000000	is garbage unix
- *	-H1 -T0xd0 -R4			is unix coff
- *	-H2 -T4128 -R4096		is plan9 format
- *	-H3 -Tx -Rx			is MS-DOS .COM
- *	-H4 -Tx -Rx			is fake MS-DOS .EXE
- *	-H5 -T0x80100020 -R4096		is ELF
- */
-
-void
-usage(void)
-{
-	diag("usage: %s [-options] objects", argv0);
-	errorexit();
-}
-
-static int
-isobjfile(char *f)
-{
-	int n, v;
-	Biobuf *b;
-	char buf1[5], buf2[SARMAG];
-
-	b = Bopen(f, OREAD);
-	if(b == nil)
-		return 0;
-	n = Bread(b, buf1, 5);
-	if(n == 5 && (buf1[2] == 1 && buf1[3] == '<' || buf1[3] == 1 && buf1[4] == '<'))
-		v = 1;	/* good enough for our purposes */
-	else{
-		Bseek(b, 0, 0);
-		n = Bread(b, buf2, SARMAG);
-		v = n == SARMAG && strncmp(buf2, ARMAG, SARMAG) == 0;
-	}
-	Bterm(b);
-	return v;
-}
-
-void
-main(int argc, char *argv[])
-{
-	int i, c;
-	char *a;
-	char name[LIBNAMELEN];
-
-	Binit(&bso, 1, OWRITE);
-	cout = -1;
-	listinit();
-	memset(debug, 0, sizeof(debug));
-	nerrors = 0;
-	outfile = "8.out";
-	HEADTYPE = -1;
-	INITTEXT = -1;
-	INITTEXTP = -1;
-	INITDAT = -1;
-	INITRND = -1;
-	INITENTRY = 0;
-	ARGBEGIN {
-	default:
-		c = ARGC();
-		if(c >= 0 && c < sizeof(debug))
-			debug[c]++;
-		break;
-	case 'o': /* output to (next arg) */
-		outfile = ARGF();
-		break;
-	case 'E':
-		a = ARGF();
-		if(a)
-			INITENTRY = a;
-		break;
-	case 'H':
-		a = ARGF();
-		if(a)
-			HEADTYPE = atolwhex(a);
-		break;
-	case 'L':
-		addlibpath(EARGF(usage()));
-		break;
-	case 'T':
-		a = ARGF();
-		if(a)
-			INITTEXT = atolwhex(a);
-		break;
-	case 'P':
-		a = ARGF();
-		if(a)
-			INITTEXTP = atolwhex(a);
-		break;
-	case 'D':
-		a = ARGF();
-		if(a)
-			INITDAT = atolwhex(a);
-		break;
-	case 'R':
-		a = ARGF();
-		if(a)
-			INITRND = atolwhex(a);
-		break;
-	case 'x':	/* produce export table */
-		doexp = 1;
-		if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1])){
-			a = ARGF();
-			if(strcmp(a, "*") == 0)
-				allexport = 1;
-			else
-				readundefs(a, SEXPORT);
-		}
-		break;
-	case 'u':	/* produce dynamically loadable module */
-		dlm = 1;
-		debug['l']++;
-		if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1]))
-			readundefs(ARGF(), SIMPORT);
-		break;
-	} ARGEND
-	USED(argc);
-	if(*argv == 0)
-		usage();
-	if(!debug['9'] && !debug['U'] && !debug['B'])
-		debug[DEFAULT] = 1;
-	a = getenv("ccroot");
-	if(a != nil && *a != '\0') {
-		if(!fileexists(a)) {
-			diag("nonexistent $ccroot: %s", a);
-			errorexit();
-		}
-	}else
-		a = "";
-	snprint(name, sizeof(name), "%s/%s/lib", a, thestring);
-	addlibpath(name);
-	if(HEADTYPE == -1) {
-		if(debug['U'])
-			HEADTYPE = 1;
-		if(debug['B'])
-			HEADTYPE = 2;
-		if(debug['9'])
-			HEADTYPE = 2;
-	}
-	switch(HEADTYPE) {
-	default:
-		diag("unknown -H option");
-		errorexit();
-
-	case 0:	/* this is garbage */
-		HEADR = 20L+56L;
-		if(INITTEXT == -1)
-			INITTEXT = 0x40004CL;
-		if(INITDAT == -1)
-			INITDAT = 0x10000000L;
-		if(INITRND == -1)
-			INITRND = 0;
-		break;
-	case 1:	/* is unix coff */
-		HEADR = 0xd0L;
-		if(INITTEXT == -1)
-			INITTEXT = 0xd0;
-		if(INITDAT == -1)
-			INITDAT = 0x400000;
-		if(INITRND == -1)
-			INITRND = 0;
-		break;
-	case 2:	/* plan 9 */
-		HEADR = 32L;
-		if(INITTEXT == -1)
-			INITTEXT = 4096+32;
-		if(INITDAT == -1)
-			INITDAT = 0;
-		if(INITRND == -1)
-			INITRND = 4096;
-		break;
-	case 3:	/* MS-DOS .COM */
-		HEADR = 0;
-		if(INITTEXT == -1)
-			INITTEXT = 0x0100;
-		if(INITDAT == -1)
-			INITDAT = 0;
-		if(INITRND == -1)
-			INITRND = 4;
-		break;
-	case 4:	/* fake MS-DOS .EXE */
-		HEADR = 0x200;
-		if(INITTEXT == -1)
-			INITTEXT = 0x0100;
-		if(INITDAT == -1)
-			INITDAT = 0;
-		if(INITRND == -1)
-			INITRND = 4;
-		HEADR += (INITTEXT & 0xFFFF);
-		if(debug['v'])
-			Bprint(&bso, "HEADR = 0x%ld\n", HEADR);
-		break;
-	case 5:	/* elf executable */
-		HEADR = rnd(Ehdr32sz+3*Phdr32sz, 16);
-		if(INITTEXT == -1)
-			INITTEXT = 0x80100020L;
-		if(INITDAT == -1)
-			INITDAT = 0;
-		if(INITRND == -1)
-			INITRND = 4096;
-		break;
-	}
-	if (INITTEXTP == -1)
-		INITTEXTP = INITTEXT;
-	if(INITDAT != 0 && INITRND != 0)
-		print("warning: -D0x%lux is ignored because of -R0x%lux\n",
-			INITDAT, INITRND);
-	if(debug['v'])
-		Bprint(&bso, "HEADER = -H0x%ld -T0x%lux -D0x%lux -R0x%lux\n",
-			HEADTYPE, INITTEXT, INITDAT, INITRND);
-	Bflush(&bso);
-	for(i=1; optab[i].as; i++)
-		if(i != optab[i].as) {
-			diag("phase error in optab: %d", i);
-			errorexit();
-		}
-
-	for(i=0; i<Ymax; i++)
-		ycover[i*Ymax + i] = 1;
-
-	ycover[Yi0*Ymax + Yi8] = 1;
-	ycover[Yi1*Ymax + Yi8] = 1;
-
-	ycover[Yi0*Ymax + Yi32] = 1;
-	ycover[Yi1*Ymax + Yi32] = 1;
-	ycover[Yi8*Ymax + Yi32] = 1;
-
-	ycover[Yal*Ymax + Yrb] = 1;
-	ycover[Ycl*Ymax + Yrb] = 1;
-	ycover[Yax*Ymax + Yrb] = 1;
-	ycover[Ycx*Ymax + Yrb] = 1;
-	ycover[Yrx*Ymax + Yrb] = 1;
-
-	ycover[Yax*Ymax + Yrx] = 1;
-	ycover[Ycx*Ymax + Yrx] = 1;
-
-	ycover[Yax*Ymax + Yrl] = 1;
-	ycover[Ycx*Ymax + Yrl] = 1;
-	ycover[Yrx*Ymax + Yrl] = 1;
-
-	ycover[Yf0*Ymax + Yrf] = 1;
-
-	ycover[Yal*Ymax + Ymb] = 1;
-	ycover[Ycl*Ymax + Ymb] = 1;
-	ycover[Yax*Ymax + Ymb] = 1;
-	ycover[Ycx*Ymax + Ymb] = 1;
-	ycover[Yrx*Ymax + Ymb] = 1;
-	ycover[Yrb*Ymax + Ymb] = 1;
-	ycover[Ym*Ymax + Ymb] = 1;
-
-	ycover[Yax*Ymax + Yml] = 1;
-	ycover[Ycx*Ymax + Yml] = 1;
-	ycover[Yrx*Ymax + Yml] = 1;
-	ycover[Yrl*Ymax + Yml] = 1;
-	ycover[Ym*Ymax + Yml] = 1;
-
-	for(i=0; i<D_NONE; i++) {
-		reg[i] = -1;
-		if(i >= D_AL && i <= D_BH)
-			reg[i] = (i-D_AL) & 7;
-		if(i >= D_AX && i <= D_DI)
-			reg[i] = (i-D_AX) & 7;
-		if(i >= D_F0 && i <= D_F0+7)
-			reg[i] = (i-D_F0) & 7;
-	}
-
-	zprg.link = P;
-	zprg.pcond = P;
-	zprg.back = 2;
-	zprg.as = AGOK;
-	zprg.from.type = D_NONE;
-	zprg.from.index = D_NONE;
-	zprg.from.scale = 1;
-	zprg.to = zprg.from;
-
-	pcstr = "%.6lux ";
-	nuxiinit();
-	histgen = 0;
-	textp = P;
-	datap = P;
-	edatap = P;
-	pc = 0;
-	dtype = 4;
-	cout = create(outfile, 1, 0775);
-	if(cout < 0) {
-		diag("cannot create %s: %r", outfile);
-		errorexit();
-	}
-	version = 0;
-	cbp = buf.cbuf;
-	cbc = sizeof(buf.cbuf);
-	firstp = prg();
-	lastp = firstp;
-
-	if(INITENTRY == 0) {
-		INITENTRY = "_main";
-		if(debug['p'])
-			INITENTRY = "_mainp";
-		if(!debug['l'])
-			lookup(INITENTRY, 0)->type = SXREF;
-	} else if(!(*INITENTRY >= '0' && *INITENTRY <= '9'))
-		lookup(INITENTRY, 0)->type = SXREF;
-
-	while(*argv)
-		objfile(*argv++);
-	if(!debug['l'])
-		loadlib();
-	firstp = firstp->link;
-	if(firstp == P)
-		errorexit();
-	if(doexp || dlm){
-		EXPTAB = "_exporttab";
-		zerosig(EXPTAB);
-		zerosig("etext");
-		zerosig("edata");
-		zerosig("end");
-		if(dlm){
-			import();
-			HEADTYPE = 2;
-			INITTEXT = INITDAT = 0;
-			INITRND = 8;
-			INITENTRY = EXPTAB;
-		}
-		export();
-	}
-	patch();
-	follow();
-	dodata();
-	dostkoff();
-	if(debug['p'])
-		if(debug['1'])
-			doprof1();
-		else
-			doprof2();
-	span();
-	doinit();
-	asmb();
-	undef();
-	if(debug['v']) {
-		Bprint(&bso, "%5.2f cpu time\n", cputime());
-		Bprint(&bso, "%ld symbols\n", nsymbol);
-		Bprint(&bso, "%ld memory used\n", thunk);
-		Bprint(&bso, "%d sizeof adr\n", sizeof(Adr));
-		Bprint(&bso, "%d sizeof prog\n", sizeof(Prog));
-	}
-	Bflush(&bso);
-
-	errorexit();
-}
-
-void
-addlibpath(char *arg)
-{
-	char **p;
-
-	if(nlibdir >= maxlibdir) {
-		if(maxlibdir == 0)
-			maxlibdir = 8;
-		else
-			maxlibdir *= 2;
-		p = malloc(maxlibdir*sizeof(*p));
-		if(p == nil) {
-			diag("out of memory");
-			errorexit();
-		}
-		memmove(p, libdir, nlibdir*sizeof(*p));
-		free(libdir);
-		libdir = p;
-	}
-	libdir[nlibdir++] = strdup(arg);
-}
-
-char*
-findlib(char *file)
-{
-	int i;
-	char name[LIBNAMELEN];
-
-	for(i = 0; i < nlibdir; i++) {
-		snprint(name, sizeof(name), "%s/%s", libdir[i], file);
-		if(fileexists(name))
-			return libdir[i];
-	}
-	return nil;
-}
-
-void
-loadlib(void)
-{
-	int i;
-	int32_t h;
-	Sym *s;
-
-loop:
-	xrefresolv = 0;
-	for(i=0; i<libraryp; i++) {
-		if(debug['v'])
-			Bprint(&bso, "%5.2f autolib: %s (from %s)\n", cputime(), library[i], libraryobj[i]);
-		objfile(library[i]);
-	}
-	if(xrefresolv)
-	for(h=0; h<nelem(hash); h++)
-	for(s = hash[h]; s != S; s = s->link)
-		if(s->type == SXREF)
-			goto loop;
-}
-
-void
-errorexit(void)
-{
-
-	if(nerrors) {
-		if(cout >= 0)
-			remove(outfile);
-		exits("error");
-	}
-	exits(0);
-}
-
-void
-objfile(char *file)
-{
-	int32_t off, esym, cnt, l;
-	int f, work;
-	Sym *s;
-	char magbuf[SARMAG];
-	char name[LIBNAMELEN], pname[LIBNAMELEN];
-	struct ar_hdr arhdr;
-	char *e, *start, *stop;
-
-	if(debug['v'])
-		Bprint(&bso, "%5.2f ldobj: %s\n", cputime(), file);
-	Bflush(&bso);
-	if(file[0] == '-' && file[1] == 'l') {
-		snprint(pname, sizeof(pname), "lib%s.a", file+2);
-		e = findlib(pname);
-		if(e == nil) {
-			diag("cannot find library: %s", file);
-			errorexit();
-		}
-		snprint(name, sizeof(name), "%s/%s", e, pname);
-		file = name;
-	}
-	f = open(file, 0);
-	if(f < 0) {
-		diag("cannot open %s: %r", file);
-		errorexit();
-	}
-	l = read(f, magbuf, SARMAG);
-	if(l != SARMAG || strncmp(magbuf, ARMAG, SARMAG)){
-		/* load it as a regular file */
-		l = seek(f, 0L, 2);
-		seek(f, 0L, 0);
-		ldobj(f, l, file);
-		close(f);
-		return;
-	}
-
-	l = read(f, &arhdr, SAR_HDR);
-	if(l != SAR_HDR) {
-		diag("%s: short read on archive file symbol header", file);
-		goto out;
-	}
-	if(strncmp(arhdr.name, symname, strlen(symname))) {
-		diag("%s: first entry not symbol header", file);
-		goto out;
-	}
-
-	esym = SARMAG + SAR_HDR + atolwhex(arhdr.size);
-	off = SARMAG + SAR_HDR;
-
-	/*
-	 * just bang the whole symbol file into memory
-	 */
-	seek(f, off, 0);
-	cnt = esym - off;
-	start = malloc(cnt + 10);
-	cnt = read(f, start, cnt);
-	if(cnt <= 0){
-		close(f);
-		return;
-	}
-	stop = &start[cnt];
-	memset(stop, 0, 10);
-
-	work = 1;
-	while(work) {
-		if(debug['v'])
-			Bprint(&bso, "%5.2f library pass: %s\n", cputime(), file);
-		Bflush(&bso);
-		work = 0;
-		for(e = start; e < stop; e = strchr(e+5, 0) + 1) {
-			s = lookup(e+5, 0);
-			if(s->type != SXREF)
-				continue;
-			sprint(pname, "%s(%s)", file, s->name);
-			if(debug['v'])
-				Bprint(&bso, "%5.2f library: %s\n", cputime(), pname);
-			Bflush(&bso);
-			l = e[1] & 0xff;
-			l |= (e[2] & 0xff) << 8;
-			l |= (e[3] & 0xff) << 16;
-			l |= (e[4] & 0xff) << 24;
-			seek(f, l, 0);
-			/* need readn to read the dumps (at least) */
-			l = readn(f, &arhdr, SAR_HDR);
-			if(l != SAR_HDR)
-				goto bad;
-			if(strncmp(arhdr.fmag, ARFMAG, sizeof(arhdr.fmag)))
-				goto bad;
-			l = atolwhex(arhdr.size);
-			ldobj(f, l, pname);
-			if(s->type == SXREF) {
-				diag("%s: failed to load: %s", file, s->name);
-				errorexit();
-			}
-			work = 1;
-			xrefresolv = 1;
-		}
-	}
-	return;
-
-bad:
-	diag("%s: bad or out of date archive", file);
-out:
-	close(f);
-}
-
-int
-zaddr(uint8_t *p, Adr *a, Sym *h[])
-{
-	int c, t, i;
-	int l;
-	Sym *s;
-	Auto *u;
-
-	t = p[0];
-
-	c = 1;
-	if(t & T_INDEX) {
-		a->index = p[c];
-		a->scale = p[c+1];
-		c += 2;
-	} else {
-		a->index = D_NONE;
-		a->scale = 0;
-	}
-	a->offset = 0;
-	if(t & T_OFFSET) {
-		a->offset = p[c] | (p[c+1]<<8) | (p[c+2]<<16) | (p[c+3]<<24);
-		c += 4;
-	}
-	a->sym = S;
-	if(t & T_SYM) {
-		a->sym = h[p[c]];
-		c++;
-	}
-	a->type = D_NONE;
-	if(t & T_FCONST) {
-		a->ieee.l = p[c] | (p[c+1]<<8) | (p[c+2]<<16) | (p[c+3]<<24);
-		a->ieee.h = p[c+4] | (p[c+5]<<8) | (p[c+6]<<16) | (p[c+7]<<24);
-		c += 8;
-		a->type = D_FCONST;
-	} else
-	if(t & T_SCONST) {
-		for(i=0; i<NSNAME; i++)
-			a->scon[i] = p[c+i];
-		c += NSNAME;
-		a->type = D_SCONST;
-	}
-	if(t & T_TYPE) {
-		a->type = p[c];
-		c++;
-	}
-	s = a->sym;
-	if(s == S)
-		return c;
-
-	t = a->type;
-	if(t != D_AUTO && t != D_PARAM)
-		return c;
-	l = a->offset;
-	for(u=curauto; u; u=u->link) {
-		if(u->asym == s)
-		if(u->type == t) {
-			if(u->aoffset > l)
-				u->aoffset = l;
-			return c;
-		}
-	}
-
-	while(nhunk < sizeof(Auto))
-		gethunk();
-	u = (Auto*)hunk;
-	nhunk -= sizeof(Auto);
-	hunk += sizeof(Auto);
-
-	u->link = curauto;
-	curauto = u;
-	u->asym = s;
-	u->aoffset = l;
-	u->type = t;
-	return c;
-}
-
-void
-addlib(char *obj)
-{
-	char fn1[LIBNAMELEN], fn2[LIBNAMELEN], comp[LIBNAMELEN], *p, *name;
-	int i, search;
-
-	if(histfrogp <= 0)
-		return;
-
-	name = fn1;
-	search = 0;
-	if(histfrog[0]->name[1] == '/') {
-		sprint(name, "");
-		i = 1;
-	} else if(histfrog[0]->name[1] == '.') {
-		sprint(name, ".");
-		i = 0;
-	} else {
-		sprint(name, "");
-		i = 0;
-		search = 1;
-	}
-
-	for(; i<histfrogp; i++) {
-		snprint(comp, sizeof comp, histfrog[i]->name+1);
-		for(;;) {
-			p = strstr(comp, "$O");
-			if(p == 0)
-				break;
-			memmove(p+1, p+2, strlen(p+2)+1);
-			p[0] = thechar;
-		}
-		for(;;) {
-			p = strstr(comp, "$M");
-			if(p == 0)
-				break;
-			if(strlen(comp)+strlen(thestring)-2+1 >= sizeof comp) {
-				diag("library component too long");
-				return;
-			}
-			memmove(p+strlen(thestring), p+2, strlen(p+2)+1);
-			memmove(p, thestring, strlen(thestring));
-		}
-		if(strlen(fn1) + strlen(comp) + 3 >= sizeof(fn1)) {
-			diag("library component too long");
-			return;
-		}
-		if(i > 0 || !search)
-			strcat(fn1, "/");
-		strcat(fn1, comp);
-	}
-
-	cleanname(name);
-
-	if(search){
-		p = findlib(name);
-		if(p != nil){
-			snprint(fn2, sizeof(fn2), "%s/%s", p, name);
-			name = fn2;
-		}
-	}
-
-	for(i=0; i<libraryp; i++)
-		if(strcmp(name, library[i]) == 0)
-			return;
-	if(libraryp == nelem(library)){
-		diag("too many autolibs; skipping %s", name);
-		return;
-	}
-
-	p = malloc(strlen(name) + 1);
-	strcpy(p, name);
-	library[libraryp] = p;
-	p = malloc(strlen(obj) + 1);
-	strcpy(p, obj);
-	libraryobj[libraryp] = p;
-	libraryp++;
-}
-
-void
-addhist(int32_t line, int type)
-{
-	Auto *u;
-	Sym *s;
-	int i, j, k;
-
-	u = malloc(sizeof(Auto));
-	s = malloc(sizeof(Sym));
-	s->name = malloc(2*(histfrogp+1) + 1);
-
-	u->asym = s;
-	u->type = type;
-	u->aoffset = line;
-	u->link = curhist;
-	curhist = u;
-
-	j = 1;
-	for(i=0; i<histfrogp; i++) {
-		k = histfrog[i]->value;
-		s->name[j+0] = k>>8;
-		s->name[j+1] = k;
-		j += 2;
-	}
-}
-
-void
-histtoauto(void)
-{
-	Auto *l;
-
-	while(l = curhist) {
-		curhist = l->link;
-		l->link = curauto;
-		curauto = l;
-	}
-}
-
-void
-collapsefrog(Sym *s)
-{
-	int i;
-
-	/*
-	 * bad encoding of path components only allows
-	 * MAXHIST components. if there is an overflow,
-	 * first try to collapse xxx/..
-	 */
-	for(i=1; i<histfrogp; i++)
-		if(strcmp(histfrog[i]->name+1, "..") == 0) {
-			memmove(histfrog+i-1, histfrog+i+1,
-				(histfrogp-i-1)*sizeof(histfrog[0]));
-			histfrogp--;
-			goto out;
-		}
-
-	/*
-	 * next try to collapse .
-	 */
-	for(i=0; i<histfrogp; i++)
-		if(strcmp(histfrog[i]->name+1, ".") == 0) {
-			memmove(histfrog+i, histfrog+i+1,
-				(histfrogp-i-1)*sizeof(histfrog[0]));
-			goto out;
-		}
-
-	/*
-	 * last chance, just truncate from front
-	 */
-	memmove(histfrog+0, histfrog+1,
-		(histfrogp-1)*sizeof(histfrog[0]));
-
-out:
-	histfrog[histfrogp-1] = s;
-}
-
-void
-nopout(Prog *p)
-{
-	p->as = ANOP;
-	p->from.type = D_NONE;
-	p->to.type = D_NONE;
-}
-
-uint8_t*
-readsome(int f, uint8_t *buf, uint8_t *good, uint8_t *stop, int max)
-{
-	int n;
-
-	n = stop - good;
-	memmove(buf, good, stop - good);
-	stop = buf + n;
-	n = MAXIO - n;
-	if(n > max)
-		n = max;
-	n = read(f, stop, n);
-	if(n <= 0)
-		return 0;
-	return stop + n;
-}
-
-void
-ldobj(int f, int32_t c, char *pn)
-{
-	int32_t ipc;
-	Prog *p, *t;
-	uint8_t *bloc, *bsize, *stop;
-	int v, o, r, skip;
-	Sym *h[NSYM], *s, *di;
-	uint32_t sig;
-	static int files;
-	static char **filen;
-	char **nfilen;
-
-	if((files&15) == 0){
-		nfilen = malloc((files+16)*sizeof(char*));
-		memmove(nfilen, filen, files*sizeof(char*));
-		free(filen);
-		filen = nfilen;
-	}
-	filen[files++] = strdup(pn);
-
-	bsize = buf.xbuf;
-	bloc = buf.xbuf;
-	di = S;
-
-newloop:
-	memset(h, 0, sizeof(h));
-	version++;
-	histfrogp = 0;
-	ipc = pc;
-	skip = 0;
-
-loop:
-	if(c <= 0)
-		goto eof;
-	r = bsize - bloc;
-	if(r < 100 && r < c) {		/* enough for largest prog */
-		bsize = readsome(f, buf.xbuf, bloc, bsize, c);
-		if(bsize == 0)
-			goto eof;
-		bloc = buf.xbuf;
-		goto loop;
-	}
-	o = bloc[0] | (bloc[1] << 8);
-	if(o <= AXXX || o >= ALAST) {
-		if(o < 0)
-			goto eof;
-		diag("%s: opcode out of range %d", pn, o);
-		print("	probably not a .8 file\n");
-		errorexit();
-	}
-
-	if(o == ANAME || o == ASIGNAME) {
-		sig = 0;
-		if(o == ASIGNAME) {
-			sig = bloc[2] | (bloc[3]<<8) | (bloc[4]<<16) | (bloc[5]<<24);
-			bloc += 4;
-			c -= 4;
-		}
-		stop = memchr(&bloc[4], 0, bsize-&bloc[4]);
-		if(stop == 0){
-			bsize = readsome(f, buf.xbuf, bloc, bsize, c);
-			if(bsize == 0)
-				goto eof;
-			bloc = buf.xbuf;
-			stop = memchr(&bloc[4], 0, bsize-&bloc[4]);
-			if(stop == 0){
-				fprint(2, "%s: name too long\n", pn);
-				errorexit();
-			}
-		}
-		v = bloc[2];	/* type */
-		o = bloc[3];	/* sym */
-		bloc += 4;
-		c -= 4;
-
-		r = 0;
-		if(v == D_STATIC)
-			r = version;
-		s = lookup((char*)bloc, r);
-		c -= &stop[1] - bloc;
-		bloc = stop + 1;
-
-		if(debug['S'] && r == 0)
-			sig = 1729;
-		if(sig != 0){
-			if(s->sig != 0 && s->sig != sig)
-				diag("incompatible type signatures %lux(%s) and %lux(%s) for %s", s->sig, filen[s->file], sig, pn, s->name);
-			s->sig = sig;
-			s->file = files-1;
-		}
-
-		if(debug['W'])
-			print("	ANAME	%s\n", s->name);
-		h[o] = s;
-		if((v == D_EXTERN || v == D_STATIC) && s->type == 0)
-			s->type = SXREF;
-		if(v == D_FILE) {
-			if(s->type != SFILE) {
-				histgen++;
-				s->type = SFILE;
-				s->value = histgen;
-			}
-			if(histfrogp < MAXHIST) {
-				histfrog[histfrogp] = s;
-				histfrogp++;
-			} else
-				collapsefrog(s);
-		}
-		goto loop;
-	}
-
-	while(nhunk < sizeof(Prog))
-		gethunk();
-	p = (Prog*)hunk;
-	nhunk -= sizeof(Prog);
-	hunk += sizeof(Prog);
-
-	p->as = o;
-	p->line = bloc[2] | (bloc[3] << 8) | (bloc[4] << 16) | (bloc[5] << 24);
-	p->back = 2;
-	r = zaddr(bloc+6, &p->from, h) + 6;
-	r += zaddr(bloc+r, &p->to, h);
-	bloc += r;
-	c -= r;
-
-	if(debug['W'])
-		print("%P\n", p);
-
-	switch(p->as) {
-	case AHISTORY:
-		if(p->to.offset == -1) {
-			addlib(pn);
-			histfrogp = 0;
-			goto loop;
-		}
-		addhist(p->line, D_FILE);		/* 'z' */
-		if(p->to.offset)
-			addhist(p->to.offset, D_FILE1);	/* 'Z' */
-		histfrogp = 0;
-		goto loop;
-
-	case AEND:
-		histtoauto();
-		if(curtext != P)
-			curtext->to.autom = curauto;
-		curauto = 0;
-		curtext = P;
-		if(c)
-			goto newloop;
-		return;
-
-	case AGLOBL:
-		s = p->from.sym;
-		if(s->type == 0 || s->type == SXREF) {
-			s->type = SBSS;
-			s->value = 0;
-		}
-		if(s->type != SBSS) {
-			diag("%s: redefinition: %s in %s",
-				pn, s->name, TNAME);
-			s->type = SBSS;
-			s->value = 0;
-		}
-		if(p->to.offset > s->value)
-			s->value = p->to.offset;
-		goto loop;
-
-	case ADYNT:
-		if(p->to.sym == S) {
-			diag("DYNT without a sym\n%P", p);
-			break;
-		}
-		di = p->to.sym;
-		p->from.scale = 4;
-		if(di->type == SXREF) {
-			if(debug['z'])
-				Bprint(&bso, "%P set to %d\n", p, dtype);
-			di->type = SCONST;
-			di->value = dtype;
-			dtype += 4;
-		}
-		if(p->from.sym == S)
-			break;
-
-		p->from.offset = di->value;
-		p->from.sym->type = SDATA;
-		if(curtext == P) {
-			diag("DYNT not in text: %P", p);
-			break;
-		}
-		p->to.sym = curtext->from.sym;
-		p->to.type = D_ADDR;
-		p->to.index = D_EXTERN;
-		goto data;
-
-	case AINIT:
-		if(p->from.sym == S) {
-			diag("INIT without a sym\n%P", p);
-			break;
-		}
-		if(di == S) {
-			diag("INIT without previous DYNT\n%P", p);
-			break;
-		}
-		p->from.offset = di->value;
-		p->from.sym->type = SDATA;
-		goto data;
-
-	case ADATA:
-	data:
-		if(edatap == P)
-			datap = p;
-		else
-			edatap->link = p;
-		edatap = p;
-		p->link = P;
-		goto loop;
-
-	case AGOK:
-		diag("%s: GOK opcode in %s", pn, TNAME);
-		pc++;
-		goto loop;
-
-	case ATEXT:
-		if(curtext != P) {
-			histtoauto();
-			curtext->to.autom = curauto;
-			curauto = 0;
-		}
-		skip = 0;
-		curtext = p;
-		s = p->from.sym;
-		if(s == S) {
-			diag("%s: no TEXT symbol: %P", pn, p);
-			errorexit();
-		}
-		if(s->type != 0 && s->type != SXREF) {
-			if(p->from.scale & DUPOK) {
-				skip = 1;
-				goto casdef;
-			}
-			diag("%s: redefinition: %s\n%P", pn, s->name, p);
-		}
-		s->type = STEXT;
-		s->value = pc;
-		lastp->link = p;
-		lastp = p;
-		p->pc = pc;
-		pc++;
-		if(textp == P) {
-			textp = p;
-			etextp = p;
-			goto loop;
-		}
-		etextp->pcond = p;
-		etextp = p;
-		goto loop;
-
-	case AFMOVF:
-	case AFADDF:
-	case AFSUBF:
-	case AFSUBRF:
-	case AFMULF:
-	case AFDIVF:
-	case AFDIVRF:
-	case AFCOMF:
-	case AFCOMFP:
-		if(skip)
-			goto casdef;
-		if(p->from.type == D_FCONST) {
-			/* size sb 9 max */
-			sprint(literal, "$%lux", ieeedtof(&p->from.ieee));
-			s = lookup(literal, 0);
-			if(s->type == 0) {
-				s->type = SBSS;
-				s->value = 4;
-				t = prg();
-				t->as = ADATA;
-				t->line = p->line;
-				t->from.type = D_EXTERN;
-				t->from.sym = s;
-				t->from.scale = 4;
-				t->to = p->from;
-				if(edatap == P)
-					datap = t;
-				else
-					edatap->link = t;
-				edatap = t;
-				t->link = P;
-			}
-			p->from.type = D_EXTERN;
-			p->from.sym = s;
-			p->from.offset = 0;
-		}
-		goto casdef;
-
-	case AFMOVD:
-	case AFADDD:
-	case AFSUBD:
-	case AFSUBRD:
-	case AFMULD:
-	case AFDIVD:
-	case AFDIVRD:
-	case AFCOMD:
-	case AFCOMDP:
-		if(skip)
-			goto casdef;
-		if(p->from.type == D_FCONST) {
-			/* size sb 18 max */
-			sprint(literal, "$%lux.%lux",
-				p->from.ieee.l, p->from.ieee.h);
-			s = lookup(literal, 0);
-			if(s->type == 0) {
-				s->type = SBSS;
-				s->value = 8;
-				t = prg();
-				t->as = ADATA;
-				t->line = p->line;
-				t->from.type = D_EXTERN;
-				t->from.sym = s;
-				t->from.scale = 8;
-				t->to = p->from;
-				if(edatap == P)
-					datap = t;
-				else
-					edatap->link = t;
-				edatap = t;
-				t->link = P;
-			}
-			p->from.type = D_EXTERN;
-			p->from.sym = s;
-			p->from.offset = 0;
-		}
-		goto casdef;
-
-	casdef:
-	default:
-		if(skip)
-			nopout(p);
-
-		if(p->to.type == D_BRANCH)
-			p->to.offset += ipc;
-		lastp->link = p;
-		lastp = p;
-		p->pc = pc;
-		pc++;
-		goto loop;
-	}
-	goto loop;
-
-eof:
-	diag("truncated object file: %s", pn);
-}
-
-Sym*
-lookup(char *symb, int v)
-{
-	Sym *s;
-	char *p;
-	int32_t h;
-	int l, c;
-
-	h = v;
-	for(p=symb; c = *p; p++)
-		h = h+h+h + c;
-	l = (p - symb) + 1;
-	h &= 0xffffff;
-	h %= NHASH;
-	for(s = hash[h]; s != S; s = s->link)
-		if(s->version == v)
-		if(memcmp(s->name, symb, l) == 0)
-			return s;
-
-	while(nhunk < sizeof(Sym))
-		gethunk();
-	s = (Sym*)hunk;
-	nhunk -= sizeof(Sym);
-	hunk += sizeof(Sym);
-
-	s->name = malloc(l + 1);
-	memmove(s->name, symb, l);
-
-	s->link = hash[h];
-	s->type = 0;
-	s->version = v;
-	s->value = 0;
-	s->sig = 0;
-	hash[h] = s;
-	nsymbol++;
-	return s;
-}
-
-Prog*
-prg(void)
-{
-	Prog *p;
-
-	while(nhunk < sizeof(Prog))
-		gethunk();
-	p = (Prog*)hunk;
-	nhunk -= sizeof(Prog);
-	hunk += sizeof(Prog);
-
-	*p = zprg;
-	return p;
-}
-
-Prog*
-copyp(Prog *q)
-{
-	Prog *p;
-
-	p = prg();
-	*p = *q;
-	return p;
-}
-
-Prog*
-appendp(Prog *q)
-{
-	Prog *p;
-
-	p = prg();
-	p->link = q->link;
-	q->link = p;
-	p->line = q->line;
-	return p;
-}
-
-void
-gethunk(void)
-{
-	char *h;
-	int32_t nh;
-
-	nh = NHUNK;
-	if(thunk >= 5L*NHUNK) {
-		nh = 5L*NHUNK;
-		if(thunk >= 25L*NHUNK)
-			nh = 25L*NHUNK;
-	}
-	h = mysbrk(nh);
-	if(h == (char*)-1) {
-		diag("out of memory");
-		errorexit();
-	}
-	hunk = h;
-	nhunk = nh;
-	thunk += nh;
-}
-
-void
-doprof1(void)
-{
-	Sym *s;
-	int32_t n;
-	Prog *p, *q;
-
-	if(debug['v'])
-		Bprint(&bso, "%5.2f profile 1\n", cputime());
-	Bflush(&bso);
-	s = lookup("__mcount", 0);
-	n = 1;
-	for(p = firstp->link; p != P; p = p->link) {
-		if(p->as == ATEXT) {
-			q = prg();
-			q->line = p->line;
-			q->link = datap;
-			datap = q;
-			q->as = ADATA;
-			q->from.type = D_EXTERN;
-			q->from.offset = n*4;
-			q->from.sym = s;
-			q->from.scale = 4;
-			q->to = p->from;
-			q->to.type = D_CONST;
-
-			q = prg();
-			q->line = p->line;
-			q->pc = p->pc;
-			q->link = p->link;
-			p->link = q;
-			p = q;
-			p->as = AADDL;
-			p->from.type = D_CONST;
-			p->from.offset = 1;
-			p->to.type = D_EXTERN;
-			p->to.sym = s;
-			p->to.offset = n*4 + 4;
-
-			n += 2;
-			continue;
-		}
-	}
-	q = prg();
-	q->line = 0;
-	q->link = datap;
-	datap = q;
-
-	q->as = ADATA;
-	q->from.type = D_EXTERN;
-	q->from.sym = s;
-	q->from.scale = 4;
-	q->to.type = D_CONST;
-	q->to.offset = n;
-
-	s->type = SBSS;
-	s->value = n*4;
-}
-
-void
-doprof2(void)
-{
-	Sym *s2, *s4;
-	Prog *p, *q, *q2, *ps2, *ps4;
-
-	if(debug['v'])
-		Bprint(&bso, "%5.2f profile 2\n", cputime());
-	Bflush(&bso);
-
-	if(debug['e']){
-		s2 = lookup("_tracein", 0);
-		s4 = lookup("_traceout", 0);
-	}else{
-		s2 = lookup("_profin", 0);
-		s4 = lookup("_profout", 0);
-	}
-	if(s2->type != STEXT || s4->type != STEXT) {
-		if(debug['e'])
-			diag("_tracein/_traceout not defined %d %d", s2->type, s4->type);
-		else
-			diag("_profin/_profout not defined");
-		return;
-	}
-
-	ps2 = P;
-	ps4 = P;
-	for(p = firstp; p != P; p = p->link) {
-		if(p->as == ATEXT) {
-			if(p->from.sym == s2) {
-				p->from.scale = 1;
-				ps2 = p;
-			}
-			if(p->from.sym == s4) {
-				p->from.scale = 1;
-				ps4 = p;
-			}
-		}
-	}
-	for(p = firstp; p != P; p = p->link) {
-		if(p->as == ATEXT) {
-			curtext = p;
-
-			if(p->from.scale & NOPROF) {	/* dont profile */
-				for(;;) {
-					q = p->link;
-					if(q == P)
-						break;
-					if(q->as == ATEXT)
-						break;
-					p = q;
-				}
-				continue;
-			}
-
-			/*
-			 * JMPL	profin
-			 */
-			q = prg();
-			q->line = p->line;
-			q->pc = p->pc;
-			q->link = p->link;
-			if(debug['e']){		/* embedded tracing */
-				q2 = prg();
-				p->link = q2;
-				q2->link = q;
-
-				q2->line = p->line;
-				q2->pc = p->pc;
-
-				q2->as = AJMP;
-				q2->to.type = D_BRANCH;
-				q2->to.sym = p->to.sym;
-				q2->pcond = q->link;
-			}else
-				p->link = q;
-			p = q;
-			p->as = ACALL;
-			p->to.type = D_BRANCH;
-			p->pcond = ps2;
-			p->to.sym = s2;
-
-			continue;
-		}
-		if(p->as == ARET) {
-			/*
-			 * RET (default)
-			 */
-			if(debug['e']){		/* embedded tracing */
-				q = prg();
-				q->line = p->line;
-				q->pc = p->pc;
-				q->link = p->link;
-				p->link = q;
-				p = q;
-			}
-			/*
-			 * RET
-			 */
-			q = prg();
-			q->as = ARET;
-			q->from = p->from;
-			q->to = p->to;
-			q->link = p->link;
-			p->link = q;
-
-			/*
-			 * JAL	profout
-			 */
-			p->as = ACALL;
-			p->from = zprg.from;
-			p->to = zprg.to;
-			p->to.type = D_BRANCH;
-			p->pcond = ps4;
-			p->to.sym = s4;
-
-			p = q;
-
-			continue;
-		}
-	}
-}
-
-void
-nuxiinit(void)
-{
-	int i, c;
-
-	for(i=0; i<4; i++) {
-		c = find1(0x04030201L, i+1);
-		if(i < 2)
-			inuxi2[i] = c;
-		if(i < 1)
-			inuxi1[i] = c;
-		inuxi4[i] = c;
-		fnuxi4[i] = c;
-		fnuxi8[i] = c;
-		fnuxi8[i+4] = c+4;
-	}
-	if(debug['v']) {
-		Bprint(&bso, "inuxi = ");
-		for(i=0; i<1; i++)
-			Bprint(&bso, "%d", inuxi1[i]);
-		Bprint(&bso, " ");
-		for(i=0; i<2; i++)
-			Bprint(&bso, "%d", inuxi2[i]);
-		Bprint(&bso, " ");
-		for(i=0; i<4; i++)
-			Bprint(&bso, "%d", inuxi4[i]);
-		Bprint(&bso, "\nfnuxi = ");
-		for(i=0; i<4; i++)
-			Bprint(&bso, "%d", fnuxi4[i]);
-		Bprint(&bso, " ");
-		for(i=0; i<8; i++)
-			Bprint(&bso, "%d", fnuxi8[i]);
-		Bprint(&bso, "\n");
-	}
-	Bflush(&bso);
-}
-
-int
-find1(int32_t l, int c)
-{
-	char *p;
-	int i;
-
-	p = (char*)&l;
-	for(i=0; i<4; i++)
-		if(*p++ == c)
-			return i;
-	return 0;
-}
-
-int
-find2(int32_t l, int c)
-{
-	int16_t *p;
-	int i;
-
-	p = (int16_t*)&l;
-	for(i=0; i<4; i+=2) {
-		if(((*p >> 8) & 0xff) == c)
-			return i;
-		if((*p++ & 0xff) == c)
-			return i+1;
-	}
-	return 0;
-}
-
-int32_t
-ieeedtof(Ieee *e)
-{
-	int exp;
-	int32_t v;
-
-	if(e->h == 0)
-		return 0;
-	exp = (e->h>>20) & ((1L<<11)-1L);
-	exp -= (1L<<10) - 2L;
-	v = (e->h & 0xfffffL) << 3;
-	v |= (e->l >> 29) & 0x7L;
-	if((e->l >> 28) & 1) {
-		v++;
-		if(v & 0x800000L) {
-			v = (v & 0x7fffffL) >> 1;
-			exp++;
-		}
-	}
-	if(exp <= -126 || exp >= 130)
-		diag("double fp to single fp overflow");
-	v |= ((exp + 126) & 0xffL) << 23;
-	v |= e->h & 0x80000000L;
-	return v;
-}
-
-double
-ieeedtod(Ieee *ieeep)
-{
-	Ieee e;
-	double fr;
-	int exp;
-
-	if(ieeep->h & (1L<<31)) {
-		e.h = ieeep->h & ~(1L<<31);
-		e.l = ieeep->l;
-		return -ieeedtod(&e);
-	}
-	if(ieeep->l == 0 && ieeep->h == 0)
-		return 0;
-	fr = ieeep->l & ((1L<<16)-1L);
-	fr /= 1L<<16;
-	fr += (ieeep->l>>16) & ((1L<<16)-1L);
-	fr /= 1L<<16;
-	fr += (ieeep->h & (1L<<20)-1L) | (1L<<20);
-	fr /= 1L<<21;
-	exp = (ieeep->h>>20) & ((1L<<11)-1L);
-	exp -= (1L<<10) - 2L;
-	return ldexp(fr, exp);
-}
-
-void
-undefsym(Sym *s)
-{
-	int n;
-
-	n = imports;
-	if(s->value != 0)
-		diag("value != 0 on SXREF");
-	if(n >= 1<<Rindex)
-		diag("import index %d out of range", n);
-	s->value = n<<Roffset;
-	s->type = SUNDEF;
-	imports++;
-}
-
-void
-zerosig(char *sp)
-{
-	Sym *s;
-
-	s = lookup(sp, 0);
-	s->sig = 0;
-}
-
-void
-readundefs(char *f, int t)
-{
-	int i, n;
-	Sym *s;
-	Biobuf *b;
-	char *l, buf[256], *fields[64];
-
-	if(f == nil)
-		return;
-	b = Bopen(f, OREAD);
-	if(b == nil){
-		diag("could not open %s: %r", f);
-		errorexit();
-	}
-	while((l = Brdline(b, '\n')) != nil){
-		n = Blinelen(b);
-		if(n >= sizeof(buf)){
-			diag("%s: line too long", f);
-			errorexit();
-		}
-		memmove(buf, l, n);
-		buf[n-1] = '\0';
-		n = getfields(buf, fields, nelem(fields), 1, " \t\r\n");
-		if(n == nelem(fields)){
-			diag("%s: bad format", f);
-			errorexit();
-		}
-		for(i = 0; i < n; i++){
-			s = lookup(fields[i], 0);
-			s->type = SXREF;
-			s->subtype = t;
-			if(t == SIMPORT)
-				nimports++;
-			else
-				nexports++;
-		}
-	}
-	Bterm(b);
-}

Some files were not shown because too many files changed in this diff