Browse Source

Plan 9 from Bell Labs 2012-09-27

David du Colombier 11 years ago
parent
commit
1dba61b0a5
70 changed files with 4450 additions and 19658 deletions
  1. 1 0
      rc/bin/fshalt
  2. 3 10
      sys/doc/asm.ms
  3. 867 884
      sys/doc/asm.ps
  4. 25 29
      sys/doc/comp.ms
  5. 878 876
      sys/doc/comp.ps
  6. 5 6
      sys/doc/compiler.ms
  7. 700 643
      sys/doc/compiler.ps
  8. 1 61
      sys/doc/port.ms
  9. 969 915
      sys/doc/port.ps
  10. 74 76
      sys/lib/man/lookman/index
  11. 9 9
      sys/man/1/2a
  12. 10 15
      sys/man/1/2c
  13. 11 11
      sys/man/1/2l
  14. 60 0
      sys/man/1/8a
  15. 485 0
      sys/man/1/8c
  16. 220 0
      sys/man/1/8l
  17. 24 6
      sys/man/1/INDEX
  18. 15 3
      sys/man/1/INDEX.html
  19. 5 5
      sys/man/1/acid
  20. 2 2
      sys/man/1/ar
  21. 2 2
      sys/man/1/cpp
  22. 3 3
      sys/man/1/mk
  23. 1 1
      sys/man/1/nm
  24. 7 7
      sys/man/1/pcc
  25. 2 2
      sys/man/1/prof
  26. 2 2
      sys/man/2/0intro
  27. 1 0
      sys/man/2/INDEX
  28. 1 1
      sys/man/2/INDEX.html
  29. 1 1
      sys/man/2/fmtinstall
  30. 2 2
      sys/man/2/mach
  31. 1 0
      sys/man/3/INDEX
  32. 4 0
      sys/man/3/INDEX.html
  33. 0 1
      sys/man/4/INDEX
  34. 0 4
      sys/man/4/INDEX.html
  35. 2 2
      sys/man/4/namespace
  36. 2 2
      sys/man/6/a.out
  37. 2 2
      sys/man/6/ar
  38. 1 7
      sys/man/8/INDEX
  39. 5 9
      sys/man/8/INDEX.html
  40. 0 0
      sys/man/searchindex
  41. 6 1
      sys/src/9/pc/x86watchdog.c
  42. 41 1
      sys/src/9/port/devwd.c
  43. 0 201
      sys/src/cmd/2a/a.h
  44. 0 540
      sys/src/cmd/2a/a.y
  45. 0 479
      sys/src/cmd/2a/l.s
  46. 0 936
      sys/src/cmd/2a/lex.c
  47. 0 19
      sys/src/cmd/2a/mkfile
  48. 0 523
      sys/src/cmd/2c/2.out.h
  49. 0 127
      sys/src/cmd/2c/bits.c
  50. 0 1404
      sys/src/cmd/2c/cgen.c
  51. 0 425
      sys/src/cmd/2c/enam.c
  52. 0 358
      sys/src/cmd/2c/gc.h
  53. 0 384
      sys/src/cmd/2c/list.c
  54. 0 32
      sys/src/cmd/2c/mkfile
  55. 0 174
      sys/src/cmd/2c/mul.c
  56. 0 1073
      sys/src/cmd/2c/peep.c
  57. 0 1275
      sys/src/cmd/2c/reg.c
  58. 0 839
      sys/src/cmd/2c/sgen.c
  59. 0 1046
      sys/src/cmd/2c/swt.c
  60. 0 940
      sys/src/cmd/2c/txt.c
  61. 0 1569
      sys/src/cmd/2l/asm.c
  62. 0 50
      sys/src/cmd/2l/compat.c
  63. 0 12
      sys/src/cmd/2l/cputime.c
  64. 0 266
      sys/src/cmd/2l/l.h
  65. 0 395
      sys/src/cmd/2l/list.c
  66. 0 22
      sys/src/cmd/2l/mkfile
  67. 0 1435
      sys/src/cmd/2l/obj.c
  68. 0 444
      sys/src/cmd/2l/optab.c
  69. 0 538
      sys/src/cmd/2l/pass.c
  70. 0 551
      sys/src/cmd/2l/span.c

+ 1 - 0
rc/bin/fshalt

@@ -61,6 +61,7 @@ venti/sync  >[2]/dev/null &
 
 unmount /mnt/consoles >[2]/dev/null
 kill consolefs | rc			# don't compete with /mnt/consoles
+kill cron | rc				# unlock /cron/lock
 sleep 1
 
 f=`{ls /srv/fscons*>[2]/dev/null}

+ 3 - 10
sys/doc/asm.ms

@@ -10,11 +10,11 @@ rob@plan9.bell-labs.com
 .SH
 Machines
 .PP
-There is an assembler for each of the MIPS, SPARC, Intel 386,
-Intel 960, Motorola 68020 and 68000, Power PC,
-AMD64, and ARM.
+There is an assembler for each of the MIPS, SPARC, Intel 386, AMD64,
+Power PC, and ARM.
 The 68020 assembler,
 .CW 2a ,
+(no longer distributed)
 is the oldest and in many ways the prototype.
 The assemblers are really just variations of a single program:
 they share many properties such as left-to-right assignment order for
@@ -476,13 +476,6 @@ notation, not Motorola's) see the file
 Despite its name, this file contains an enumeration of the
 instructions that appear in the intermediate files generated
 by the compiler, which correspond exactly to lines of assembly language.
-.PP
-The MC68000 assembler,
-.CW 1a ,
-is essentially the same, honoring the appropriate subset of the instructions
-and addressing modes.
-The definitions of these are, nonetheless, part of
-.CW 2.out.h .
 .SH
 Laying down instructions
 .PP

File diff suppressed because it is too large
+ 867 - 884
sys/doc/asm.ps


+ 25 - 29
sys/doc/comp.ms

@@ -15,7 +15,7 @@ a number of differences in both the language the Plan 9 compiler
 accepts and in how the compiler is used.
 .PP
 The compiler is really a set of compilers, one for each
-architecture \(em MIPS, SPARC, Motorola 68020, Intel 386, etc. \(em
+architecture \(em MIPS, SPARC, Intel 386, Power PC, ARM, etc. \(em
 that accept a dialect of ANSI C and efficiently produce
 fairly good code for the target machine.
 There is a packaging of the compiler that accepts strict ANSI C for
@@ -114,7 +114,7 @@ abbreviations for
 and so on.
 .PP
 Here is an excerpt from
-.CW /68020/include/u.h :
+.CW /386/include/u.h :
 .P1
 #define nil		((void*)0)
 typedef	unsigned short	ushort;
@@ -286,12 +286,8 @@ for 32-bit Power PC,
 for MIPS,
 .CW 0
 for little-endian MIPS,
-.CW 1
-for Motorola 68000,
-.CW 2
-for Motorola 68020 and 68040,
 .CW 5
-for ARM v5 and later architectures,
+for ARM v5 and later 32-bit architectures,
 .CW 6
 for AMD64,
 .CW 8
@@ -299,39 +295,39 @@ for Intel 386, and
 .CW 9
 for 64-bit Power PC.
 The character labels the support tools and files for that architecture.
-For instance, for the 68020 the compiler is
-.CW 2c ,
+For instance, for the 386 the compiler is
+.CW 8c ,
 the assembler is
-.CW 2a ,
+.CW 8a ,
 the link editor/loader is
-.CW 2l ,
+.CW 8l ,
 the object files are suffixed
-.CW \&.2 ,
+.CW \&.8 ,
 and the default name for an executable file is
-.CW 2.out .
+.CW 8.out .
 Before we can use the compiler we therefore need to know which
 machine we are compiling for.
 The next section explains how this decision is made; for the moment
-assume we are building 68020 binaries and make the mental substitution for
-.CW 2
+assume we are building 386 binaries and make the mental substitution for
+.CW 8
 appropriate to the machine you are actually using.
 .PP
 To convert source to an executable binary is a two-step process.
 First run the compiler,
-.CW 2c ,
+.CW 8c ,
 on the source, say
 .CW file.c ,
 to generate an object file
-.CW file.2 .
+.CW file.8 .
 Then run the loader,
-.CW 2l ,
+.CW 8l ,
 to generate an executable
-.CW 2.out
-that may be run (on a 680X0 machine):
+.CW 8.out
+that may be run (on a 386 machine):
 .P1
-2c file.c
-2l file.2
-2.out
+8c file.c
+8l file.8
+8.out
 .P2
 The loader automatically links with whatever libraries the program
 needs, usually including the standard C library as defined by
@@ -355,7 +351,7 @@ and writes the final executable.
 There is no separate C preprocessor and no assembler in the usual pipeline.
 Instead the intermediate object file
 (here a
-.CW \&.2
+.CW \&.8
 file) is a type of binary assembly language.
 The instructions in the intermediate format are not exactly those in
 the machine.  For example, on the 68020 the object file may specify
@@ -364,7 +360,7 @@ the MOVE instruction \(em MOVE immediate, MOVE quick, MOVE address,
 etc. \(em is most efficient.
 .PP
 The assembler,
-.CW 2a ,
+.CW 8a ,
 is just a translator between the textual and binary
 representations of the object file format.
 It is not an assembler in the traditional sense.  It has limited
@@ -428,8 +424,8 @@ The configuration process is controlled by an environment variable,
 .CW $cputype ,
 with value such as
 .CW mips ,
-.CW 68020 ,
 .CW 386 ,
+.CW arm ,
 or
 .CW sparc .
 For each architecture there is a directory in the root,
@@ -461,7 +457,7 @@ There is a version of
 .CW vc
 compiled for each architecture:
 .CW /mips/bin/vc ,
-.CW /68020/bin/vc ,
+.CW /arm/bin/vc ,
 .CW /sparc/bin/vc ,
 and so on,
 each capable of producing MIPS object files regardless of the native
@@ -1298,7 +1294,7 @@ not for example
 and
 .CW vacid .
 They also support cross-architecture debugging comfortably:
-one may debug a 68020 binary on a MIPS.
+one may debug a 386 binary on a MIPS.
 .PP
 Imagine a program has crashed mysteriously:
 .P1
@@ -1391,7 +1387,7 @@ acid: include("sourcedirectory/syms")
 to read in the relevant definitions.
 (For multi-file source, you need to be a little fancier;
 see
-.I 2c (1)).
+.I 8c (1)).
 This text includes, for each defined compound
 type, a function with that name that may be called with the address of a structure
 of that type to display its contents.

File diff suppressed because it is too large
+ 878 - 876
sys/doc/comp.ps


+ 5 - 6
sys/doc/compiler.ms

@@ -25,12 +25,13 @@ There are many compilers in the series.
 Five of the compilers (Intel 386, AMD64, PowerPC, PowerPC 64-bit, ARM)
 are considered active and are used to compile
 current versions of Plan 9.
-Three of the compilers (MIPS 3000, SPARC, and Motorola 68020)
+Two of the compilers (MIPS 3000, SPARC)
 are maintained but are for older machines
 for which we have no current ports of Plan 9;
-other than the MIPS, we are unlikely to port to any such machines.
-The DEC Alpha compiler has been retired.
-Several others (Motorola 68000, Intel 960, AMD 29000) have had only limited use, such as
+we are unlikely to port to any SPARC machines.
+The DEC Alpha and Motorola 68020 compilers have been retired.
+Several others (Motorola 68000, Intel 960, AMD 29000)
+have had only limited use, such as
 to program peripherals or experimental devices.
 Any of the disused compilers could be restored if needed.
 .NH
@@ -63,8 +64,6 @@ are as follows:
 .Ta PowerPC qc ql qa
 .Ta MIPS vc vl va
 .Ta MIPS\ little-endian 0c 0l 0a
-.Ta Motorola\ 68000 1c 1l 1a
-.Ta Motorola\ 68020 2c 2l 2a
 .Ta ARM 5c 5l 5a
 .Ta AMD64 6c 6l 6a
 .Ta Intel\ 386 8c 8l 8a

File diff suppressed because it is too large
+ 700 - 643
sys/doc/compiler.ps


+ 1 - 61
sys/doc/port.ms

@@ -17,50 +17,7 @@ The first section discusses the compiler/assembler/loader suite for each machine
 The second talks about
 the operating system implemented on each of the various
 machines.
-.SH
-The Motorola MC68020 compiler
-.PP
-This is the oldest compiler of the bunch.  Relative to its
-competitors\(emcommercial compilers for the same machine\(emit generates
-quite good code.
-It assumes at least a 68020 architecture: some of the addressing
-modes it generates are not on the 68000 or 68010.
-.PP
-We also use this compiler for the 68040.  Except for a few
-instructions and registers available only from assembly language,
-the only user-visible difference between these machines is in
-floating point.  Our 68020s all have 68881 or 68882 floating
-point units attached, so to execute floating point programs we
-depend on there being appropriate hardware.
-Unfortunately, the 68040 is not quite so thorough in its implementation
-of the IEEE 754 standard or in its provision of built-in instructions
-for the
-transcendental functions.  The latter was easy to get around: we
-don't use them on the 68020 either, but we do have a library,
-.CW -l68881 ,
-that you can use if you need the performance (which can be
-substantial:
-.CW astro
-runs twice as fast).
-We don't use this library by default because we want to run the same
-binaries on both machines and don't want to emulate
-.CW FCOSH
-in the operating system.
-.PP
-The problem with IEEE is nastier.  We didn't really want to deal
-with gradual underflow and all that, especially since we had
-half a dozen machines we'd need to do it on, so on the 68040
-we implement non-trapping underflow as truncation to zero and
-do nothing about denormalized numbers and not-a-numbers.
-This means the 68020
-and the 68040 are not precisely compatible.
-.SH
-The Motorola MC68000 compiler
-.PP
-This compiler is a stripped-down version of the MC68020 compiler
-built for an abortive port to the Dragonball processor on the Palm Pilot.
-It generates position-independent code whose overall quality is much
-poorer than the code for the MC68020.
+.
 .SH
 The MIPS compiler
 .PP
@@ -123,16 +80,6 @@ transcendentals.
 If you want them,
 build the code in
 .CW /sys/src/libc/386/387 .
-.SH
-The Intel i960 compiler
-.PP
-This compiler was built as a weekend hack to let us get the Cyclone
-boards running.  It has only been used to run one program\(emthe on-board
-code in the Cyclone\(emand is therefore likely to be buggy.
-There are a number of obvious optimizations to the code that have
-never been attempted.
-For example, the compiler does not support pipelining.
-The code runs in little-endian mode.
 .
 .SH
 The PowerPC compiler
@@ -165,13 +112,6 @@ but probably should instead generate VFP 3+ instructions
 for coprocessors 10 and 11.
 .
 .SH
-The Carrera operating system
-.PP
-We used to have a number of MIPS R4400 PC-like devices called Carreras,
-with custom-built frame buffers, that we used as terminals.
-They're almost all decommissioned now, but we're including the source as a reference
-in case someone wants to get another MIPS-based system running.
-.SH
 The IBM PC operating system
 .PP
 The PC version of Plan 9 can boot either from MS-DOS

File diff suppressed because it is too large
+ 969 - 915
sys/doc/port.ps


File diff suppressed because it is too large
+ 74 - 76
sys/lib/man/lookman/index


+ 9 - 9
sys/man/1/2a

@@ -1,8 +1,8 @@
-.TH 2A 1 
+.TH 8A 1 
 .SH NAME
-0a, 2a, 5a, 6a, 8a, 9a, ka, qa, va \- assemblers
+0a, 5a, 6a, 8a, 9a, ka, qa, va \- assemblers
 .SH SYNOPSIS
-.B 2a
+.B 8a
 [
 .I option ...
 ]
@@ -15,10 +15,10 @@ etc.
 These programs
 assemble the named files into object files
 for the corresponding architectures; see
-.IR 2c (1)
+.IR 8c (1)
 for the correspondence between an architecture and the character
-.RB ( 1 ,
-.RB 2 ,
+.RB ( 6 ,
+.RB 8 ,
 etc.) that specifies it.
 The assemblers handle the most common C preprocessor directives and the associated
 command-line options
@@ -46,11 +46,11 @@ is searched for include files after
 machine-dependent files in
 .BR /$objtype/include .
 .SH SOURCE
-.BR /sys/src/cmd/2a ,
+.BR /sys/src/cmd/8a ,
 etc.
 .SH SEE ALSO
-.IR 2c (1),
-.IR 2l (1).
+.IR 8c (1),
+.IR 8l (1).
 .PP
 Rob Pike, ``A manual for the Plan 9 assembler''
 .SH BUGS

+ 10 - 15
sys/man/1/2c

@@ -1,8 +1,8 @@
-.TH 2C 1
+.TH 8C 1
 .SH NAME
-0c, 2c, 5c, 6c, 8c, 9c, kc, qc, vc \- C compilers
+0c, 5c, 6c, 8c, 9c, kc, qc, vc \- C compilers
 .SH SYNOPSIS
-.B 2c
+.B 8c
 [
 .I option ...
 ]
@@ -29,9 +29,6 @@ for example
 .B "0c spim
 little-endian MIPS 3000 family
 .TP
-.B "2c 68020
-Motorola MC68020
-.TP
 .B "5c arm
 little-endian ARM
 .TP
@@ -61,8 +58,6 @@ which must be run separately.
 Let the first letter of the compiler name be
 .IR O =
 .BR 0 ,
-.BR 1 ,
-.BR 2 ,
 .BR 5 ,
 .BR 6 ,
 .BR 8 ,
@@ -409,7 +404,7 @@ as is done for shorter
 .I unsigned
 expressions).
 .SH EXAMPLE
-For the 68020, produce a program
+For the 386, produce a program
 .B prog
 from C files
 .BR main.c
@@ -417,8 +412,8 @@ and
 .BR sub.c :
 .IP
 .EX
-2c -FVw main.c sub.c
-2l -o prog main.2 sub.2
+8c -FVw main.c sub.c
+8l -o prog main.8 sub.8
 .EE
 .SH FILES
 .TF /$objtype/include
@@ -433,16 +428,16 @@ system area for machine-dependent
 .B #include
 directives.
 .SH SOURCE
-.TF /sys/src/cmd/2c,\ etc.
+.TF /sys/src/cmd/8c,\ etc.
 .TP
 .B /sys/src/cmd/cc
 machine-independent part
 .TP
-.BR /sys/src/cmd/2c ,\ etc.
+.BR /sys/src/cmd/8c ,\ etc.
 machine-dependent part
 .SH "SEE ALSO"
-.IR 2a (1),
-.IR 2l (1),
+.IR 8a (1),
+.IR 8l (1),
 .IR cpp (1),
 .IR mk (1),
 .IR nm (1),

+ 11 - 11
sys/man/1/2l

@@ -1,8 +1,8 @@
-.TH 2L 1 
+.TH 8L 1 
 .SH NAME
-0l, 2l, 5l, 6l, 8l, 9l, kl, ql, vl \- loaders
+0l, 5l, 6l, 8l, 9l, kl, ql, vl \- loaders
 .SH SYNOPSIS
-.B 2l
+.B 8l
 [
 .I option ...
 ]
@@ -16,10 +16,10 @@ These commands
 load the named
 .I files
 into executable files for the corresponding architectures; see
-.IR 2c (1)
+.IR 8c (1)
 for the correspondence between an architecture and the character
-.RB ( 1 ,
-.RB 2 ,
+.RB ( 6 ,
+.RB 8 ,
 etc.) that specifies it.
 The files should be object files or libraries (archives of object files)
 for the appropriate architecture.
@@ -34,7 +34,7 @@ where
 is one of
 .BR 386 ,
 etc. as listed in
-.IR 2c (1).
+.IR 8c (1).
 The libraries must have tables of contents
 (see
 .IR ar (1)).
@@ -44,7 +44,7 @@ In practice,
 options are rarely necessary as the header files for
 the libraries cause their archives to be included automatically in the load
 (see
-.IR 2c (1)).
+.IR 8c (1)).
 For example, any program that includes header file
 .B libc.h
 causes the loader
@@ -201,11 +201,11 @@ for
 .BI -l lib
 arguments.
 .SH SOURCE
-.B /sys/src/cmd/2l
+.B /sys/src/cmd/8l
 etc.
 .SH "SEE ALSO"
-.IR 2c (1),
-.IR 2a (1),
+.IR 8c (1),
+.IR 8a (1),
 .IR ar (1),
 .IR nm (1),
 .IR db (1),

+ 60 - 0
sys/man/1/8a

@@ -0,0 +1,60 @@
+.TH 8A 1 
+.SH NAME
+0a, 5a, 6a, 8a, 9a, ka, qa, va \- assemblers
+.SH SYNOPSIS
+.B 8a
+[
+.I option ...
+]
+[
+.I name ...
+]
+.br
+etc.
+.SH DESCRIPTION
+These programs
+assemble the named files into object files
+for the corresponding architectures; see
+.IR 8c (1)
+for the correspondence between an architecture and the character
+.RB ( 6 ,
+.RB 8 ,
+etc.) that specifies it.
+The assemblers handle the most common C preprocessor directives and the associated
+command-line options
+.BR -D
+and
+.BR -I .
+Other options are:
+.TP
+.BI -o " obj"
+Place output in file
+.I obj
+(allowed only if there is just one input file).
+Default is to take the last element of the input path name,
+strip any trailing
+.BR .s ,
+and append
+.RI . O ,
+where
+.I O
+is first letter of the assembler's name.
+.SH FILES
+The directory
+.B /sys/include
+is searched for include files after
+machine-dependent files in
+.BR /$objtype/include .
+.SH SOURCE
+.BR /sys/src/cmd/8a ,
+etc.
+.SH SEE ALSO
+.IR 8c (1),
+.IR 8l (1).
+.PP
+Rob Pike, ``A manual for the Plan 9 assembler''
+.SH BUGS
+The list of assemblers given above is only partial,
+not all architectures are supported on all systems,
+some have been retired and some
+are provided by third parties.

+ 485 - 0
sys/man/1/8c

@@ -0,0 +1,485 @@
+.TH 8C 1
+.SH NAME
+0c, 5c, 6c, 8c, 9c, kc, qc, vc \- C compilers
+.SH SYNOPSIS
+.B 8c
+[
+.I option ...
+]
+[
+.I file ...
+]
+.br
+etc.
+.SH DESCRIPTION
+These commands compile the named C
+.I files
+into object files for the corresponding architecture.
+If there are multiple C
+.IR files ,
+the compilers will attempt to keep
+.B $NPROC
+compilations running concurrently.
+Associated with each compiler is a string
+.IR objtype ,
+for example
+.TF "6c amd64 "
+.PD
+.TP
+.B "0c spim
+little-endian MIPS 3000 family
+.TP
+.B "5c arm
+little-endian ARM
+.TP
+.B "6c amd64
+AMD64 and compatibles (e.g., Intel64)
+.TP
+.B "8c 386
+Intel i386, i486, Pentium, etc.
+.TP
+.B "9c power64
+64-bit PowerPC
+.TP
+.B "kc sparc
+Sun (now Oracle) SPARC
+.TP
+.B "qc power
+PowerPC
+.TP
+.B "vc mips
+big-endian MIPS 3000 family
+.PP
+The compilers handle most preprocessing directives themselves; a complete
+preprocessor is available in
+.IR cpp (1),
+which must be run separately.
+.PP
+Let the first letter of the compiler name be
+.IR O =
+.BR 0 ,
+.BR 5 ,
+.BR 6 ,
+.BR 8 ,
+.BR 9 ,
+.BR k ,
+.BR q ,
+or
+.BR v .
+The output object files end in
+.RI . O .
+The letter is also the prefix of related programs:
+.IB O a
+is the assembler,
+.IB O l
+is the loader.
+Plan 9 conventionally sets the
+.B $objtype
+environment variable to the
+.I objtype
+string appropriate to the current machine's type.
+Plan 9 also conventionally has
+.RI / objtype
+directories, which contain among other things:
+.BR include ,
+for machine-dependent include files;
+.BR lib ,
+for public object code libraries;
+.BR bin ,
+for public programs;
+and
+.BR mkfile ,
+for preconditioning
+.IR mk (1).
+.PP
+The compiler options are:
+.TF Dname
+.PD
+.TP
+.BI -o " obj"
+Place output in file
+.I obj
+(allowed only if there is just one input file).
+Default is to take the last element of the input file name,
+strip any trailing
+.BR .c ,
+and append
+.RI . O .
+.TP
+.B -w
+Print warning messages about unused variables, etc.
+.TP
+.B -B
+Accept functions without a new-style
+ANSI C function prototype.
+By default, the compilers reject functions
+used without a defined prototype,
+although ANSI C permits them.
+.TP
+.BI -D\*S name=def
+.br
+.ns
+.TP
+.BI -D \*Sname
+Define the
+.I name
+to the preprocessor,
+as if by
+.LR #define .
+If no definition is given, the name is defined as
+.LR 1 .
+.TP
+.BI -F
+Enable type-checking of calls to
+.IR print (2)
+and other formatted print routines.  See the discussion
+of extensions, below.
+.TP
+.BI -I \*Sdir
+An
+.L #include
+file whose name does not begin with
+slash
+or is enclosed in double quotes
+is always
+sought first in the directory
+of the
+.I file
+argument.  If this fails,
+the
+.I -.
+flag is given or the name is enclosed in
+.BR <> ,
+it is then sought
+in directories named in
+.B -I
+options,
+then in
+.BR /sys/include ,
+and finally in
+.BR /$objtype/include .
+.TP
+.B -.
+Suppress the automatic searching for include files in
+the directory of the file argument.
+.TP
+.B -N
+Suppress automatic registerization and optimization.
+.TP
+.B -S
+Print an assembly language version of the object code
+on standard output as well as generating the
+.RI . O
+file.
+.TP
+.B -T
+Pass type signatures on all external and global entities.
+The signature is based on the C
+.B signof
+operator.
+See
+.IR dynld (2).
+.TP
+.B -V
+By default, the compilers are non-standardly lax about type equality between
+.B void*
+values and other pointers; this flag requires ANSI C conformance.
+.TP
+.B -p
+Invoke a standard ANSI C preprocessor before compiling.
+.TP
+.B -a
+Instead of compiling, print on standard output acid functions (see
+.IR acid (1))
+for examining structures declared in the source files.
+.TP
+.B -aa
+Like
+.B -a
+except suppress information about structures
+declared in included header files.
+.TP
+.B -n
+When used with
+.B -a
+or
+.BR -aa ,
+places acid functions in
+.IB file .acid
+for input
+.IB file .c ,
+and not on standard output.
+.PP
+The compilers support several extensions to 1989 ANSI C,
+some of which were adopted in later ANSI C standards:
+.TF \|
+.PD
+.TP
+\-
+A structure or union may contain unnamed substructures and subunions.
+The fields of the substructures or
+subunions can then be used as if they were members of the parent
+structure or union (the resolution of a name conflict is unspecified).
+When a pointer to the outer structure or union is used in a context
+that is only legal for the unnamed substructure, the compiler promotes
+the type and adjusts the pointer value to point at the substructure.
+If the unnamed structure or union is of a type with a tag name specified by a
+.B typedef
+statement,
+the unnamed structure or union can be explicitly referenced
+by <struct variable>.<tagname>.
+.TP
+\-
+A structure value can be formed with an expression such as
+.EX
+    (struct S){v1, v2, v3}
+.EE
+where the list elements are values for the fields of struct
+.BR S .
+.TP
+\-
+Array initializers can specify the indices of the array in square
+brackets, as
+.EX
+    int a[] = { [3] 1, [10] 5 };
+.EE
+which initializes the third and tenth elements of the eleven-element array
+.BR a .
+.TP
+\-
+Structure initializers can specify the structure element by using the name
+following a period, as
+.EX
+    struct { int x; int y; } s = { .y 1, .x 5 };
+.EE
+which initializes elements
+.B y
+and then
+.B x
+of the structure
+.BR s .
+These forms also accept the new ANSI C notation, which includes an equal sign:
+.EX
+    int a[] = { [3] = 1, [10] = 5 };
+    struct { int x; int y; } s = { .y = 1, .x = 5 };
+.EE
+.TP
+\-
+A global variable can be dedicated to a register
+by declaring it
+.B "extern register"
+in
+.I all
+modules and libraries.
+.TP
+\-
+A
+.B #pragma
+of the form
+.EX
+    #pragma lib "libbio.a"
+.EE
+records that the program needs to be loaded with file
+.BR /$objtype/lib/libbio.a ;
+such lines, typically placed in library header files, obviate the
+.B -l
+option of the loaders.  To help identify files in non-standard directories,
+within the file names in the
+.B #pragmas
+the string
+.B $M
+represents the name of the architecture
+(e.g.,
+.BR mips )
+and
+.B $O
+represents its identifying character
+(e.g.,
+.BR v ).
+.TP
+\-
+A
+.B #pragma
+of the form
+.EX
+    #pragma varargck argpos error 2
+.EE
+tells the compiler that the second argument to
+.B error
+is a
+.BR print -like
+format string (see
+.IR print (2))
+that identifies the handling of subsequent arguments.
+The
+.B #pragma
+.EX
+    #pragma varargck type "s" char*
+.EE
+says that the format verb
+.B s
+processes an argument of type
+.BR char *.
+The
+.B #pragma
+.EX
+    #pragma varargck flag 'c'
+.EE
+says that
+.B c
+is a flag character.
+These
+.B #pragmas
+are used, if the
+.B -F
+option is enabled, to type-check calls to
+.B print
+and other such routines.
+.TP
+\-
+A
+.B #pragma
+with any of the following forms:
+.EX
+    #pragma incomplete \fItype\fP
+    #pragma incomplete struct \fItag\fP
+    #pragma incomplete union \fItag\fP
+.EE
+where
+.I type
+is a
+.BR typedef 'd
+name for a structure or union type, and
+.I tag
+is a structure or union tag,
+tells the compiler that
+the corresponding type
+should have its signature calculated as an incomplete type
+even if it is subsequently fully defined.
+This allows the type signature mechanism to work in the presence
+of opaque types declared in header files, with their full definitions
+visible only to the code which manipulates them.
+With some imported software it might be necessary to turn off the
+signature generation completely for a large body of code (typically
+at the start and end of a particular include file).
+If
+.I type
+is the word
+.BR _off_ ,
+signature generation is turned off; if
+.I type
+is the word
+.BR _on_ ,
+the compiler will generate signatures.
+.TP
+\-
+The C++ comment
+.RB ( //
+to end of line)
+is accepted as well as the normal
+convention of
+.B /*
+.BR */ .
+.TP
+\-
+The compilers accept
+.B long
+.B long
+variables as a 64-bit type.
+The standard header typedefs this to
+.BR vlong .
+Arithmetic on
+.B  vlong
+values is usually emulated by a run-time library,
+though in at least
+.IR 8c ,
+only division and modulus use the run-time library
+and the other operators generate in-line code
+(and
+.I uvlong-expression
+.I divison-or-modulus
+.BI "(1<<" constant )
+will turn into in-line bit operations,
+as is done for shorter
+.I unsigned
+expressions).
+.SH EXAMPLE
+For the 386, produce a program
+.B prog
+from C files
+.BR main.c
+and
+.BR sub.c :
+.IP
+.EX
+8c -FVw main.c sub.c
+8l -o prog main.8 sub.8
+.EE
+.SH FILES
+.TF /$objtype/include
+.TP
+.B /sys/include
+system area for machine-independent
+.B #include
+directives.
+.TP
+.B /$objtype/include
+system area for machine-dependent
+.B #include
+directives.
+.SH SOURCE
+.TF /sys/src/cmd/8c,\ etc.
+.TP
+.B /sys/src/cmd/cc
+machine-independent part
+.TP
+.BR /sys/src/cmd/8c ,\ etc.
+machine-dependent part
+.SH "SEE ALSO"
+.IR 8a (1),
+.IR 8l (1),
+.IR cpp (1),
+.IR mk (1),
+.IR nm (1),
+.IR pcc (1),
+.IR db (1),
+.IR acid (1)
+.\" .IR ansitize (1)
+.PP
+Rob Pike,
+``How to Use the Plan 9 C Compiler''
+.SH BUGS
+The list of compilers given above is only partial,
+not all architectures are supported on all systems,
+some have been retired and some
+are provided by third parties.
+.PP
+The default preprocessor only handles
+.LR #define ,
+.LR #include ,
+.LR #undef ,
+.LR #ifdef ,
+.LR #line ,
+and
+.LR #ifndef .
+For a full ANSI preprocessor, use
+the
+.B p
+option.
+.PP
+The default search order for include files
+differs to that of
+.IR cpp (1).
+.PP
+Some new features of C99, the 1999 ANSI C standard,
+are implemented.
+No new features of C11, the 2011 ANSI C standard,
+are implemented.
+.PP
+The implementation of
+.B vlong
+assignment can use a static location
+and this can be disturbed by interrupts
+(e.g., notes)
+.RI ( 8c
+at least).

+ 220 - 0
sys/man/1/8l

@@ -0,0 +1,220 @@
+.TH 8L 1 
+.SH NAME
+0l, 5l, 6l, 8l, 9l, kl, ql, vl \- loaders
+.SH SYNOPSIS
+.B 8l
+[
+.I option ...
+]
+[
+.I file ...
+]
+.br
+etc.
+.SH DESCRIPTION
+These commands
+load the named
+.I files
+into executable files for the corresponding architectures; see
+.IR 8c (1)
+for the correspondence between an architecture and the character
+.RB ( 6 ,
+.RB 8 ,
+etc.) that specifies it.
+The files should be object files or libraries (archives of object files)
+for the appropriate architecture.
+Also, a name like
+.BI -l ext
+represents the library
+.BI lib ext .a
+in
+.BR /$objtype/lib ,
+where
+.I objtype
+is one of
+.BR 386 ,
+etc. as listed in
+.IR 8c (1).
+The libraries must have tables of contents
+(see
+.IR ar (1)).
+.PP
+In practice, 
+.B -l
+options are rarely necessary as the header files for
+the libraries cause their archives to be included automatically in the load
+(see
+.IR 8c (1)).
+For example, any program that includes header file
+.B libc.h
+causes the loader
+to search the C library
+.BR /$objtype/lib/libc.a .
+Also, the loader creates an undefined symbol
+.B _main
+(or
+.B _mainp
+if profiling is enabled) to force loading of the
+startup linkage from the C library.
+.PP
+The order of search to resolve undefined symbols is to load all files and libraries
+mentioned explicitly on the command line, and then to resolve remaining symbols
+by searching in topological order
+libraries mentioned in header files included by files already loaded.
+When scanning such libraries, the algorithm is to scan each library repeatedly until
+no new undefined symbols are picked up, then to start on the next library.  Thus if library
+.I A
+needs
+.I B
+which needs
+.I A
+again, it may be necessary to mention
+.I A
+explicitly so it will be read a second time.
+.PP
+The loader options are:
+.TP 0.75i
+.B -l
+(As a bare option.)
+Suppress the default loading of the startup linkage and libraries
+specified by header files.
+.TP
+.BI -o " out"
+Place output in file
+.IR out .
+Default is
+.IB O .out\f1,
+where
+.I O
+is the first letter of the loader name.
+.TP
+.B -p
+Insert profiling code into the executable output; no special action is needed
+during compilation or assembly.
+.TP
+.B -e
+Insert (\fLe\fPmbedded) tracing code into the executable output; no special action is needed
+during compilation or assembly.
+The added code calls
+.L _tracein
+at function entries
+and
+.L _traceout
+at function exits.
+.TP
+.B -s
+Strip the symbol tables from the output file.
+.TP
+.B -a
+Print the object code in assembly language, with addresses.
+.TP
+.B -v
+Print debugging output that annotates the activities of the load.
+.TP
+.BI -M
+.RI ( Kl
+only) Generate instructions rather than calls to emulation routines
+for multiply and divide.
+.TP
+.BI -E symbol
+The entry point for the binary is
+.I symbol
+(default
+.BR _main ;
+.B _mainp
+under
+.BR -p ).
+.TP
+.BI -x " [ file ]"
+Produce an export table in the executable.
+The optional
+.I file
+restricts the exported symbols to those listed in the file.
+See
+.IR dynld (2).
+.TP
+.BI -u " [ file ]"
+Produce an export table, import table
+and a dynamic load section in the executable.
+The optional
+.I file
+restricts the imported symbols to those listed in the file.
+See
+.IR dynld (2).
+.TP
+.B -t
+(\c
+.I 5l
+and
+.I vl
+only)
+Move strings into the text segment.
+.TP
+.BI -H n
+Executable header is type
+.IR n .
+The meaning of the types is architecture-dependent; typically
+type 1 is Plan 9 boot format and type 2 is the
+regular Plan 9 format, the default.  These are reversed on the MIPS.
+The Next boot format is 3.  Type 4 in
+.I vl
+creates a MIPS executable for an SGI Unix system.
+.TP
+.BI -T t
+The text segment starts at address
+.IR t .
+.TP
+.BI -D d
+The data segment starts at address
+.IR d .
+.TP
+.BI -R r
+The text segment is rounded to a multiple of
+.I r
+(if
+.I r
+is nonzero).
+.PP
+The numbers in the above options can begin with
+.L 0x
+or
+.L 0
+to change the default base from decimal to hexadecimal or octal.
+The defaults for the values depend on the compiler and the
+header type.
+.PP
+The loaded image has several symbols inserted by the loader:
+.B etext
+is the address of the end of the text segment;
+.B bdata
+is the address of the beginning of the data segment;
+.B edata
+is the address of the end of the data segment;
+and
+.B end
+is the address of the end of the bss segment, and of the program.
+.SH FILES
+.TF /$objtype/lib
+.TP
+.B /$objtype/lib
+for
+.BI -l lib
+arguments.
+.SH SOURCE
+.B /sys/src/cmd/8l
+etc.
+.SH "SEE ALSO"
+.IR 8c (1),
+.IR 8a (1),
+.IR ar (1),
+.IR nm (1),
+.IR db (1),
+.IR prof (1)
+.PP
+Rob Pike,
+``How to Use the Plan 9 C Compiler''
+.SH BUGS
+The list of loaders given above is only partial,
+not all architectures are supported on all systems,
+some have been retired and some
+are provided by third parties.

+ 24 - 6
sys/man/1/INDEX

@@ -1,38 +1,56 @@
 0intro 0intro
 intro 0intro
 0a 2a
-1a 2a
 2a 2a
 5a 2a
 6a 2a
-7a 2a
 8a 2a
 9a 2a
 ka 2a
 qa 2a
 va 2a
 0c 2c
-1c 2c
 2c 2c
 5c 2c
 6c 2c
-7c 2c
 8c 2c
 9c 2c
 kc 2c
 qc 2c
 vc 2c
 0l 2l
-1l 2l
 2l 2l
 5l 2l
 6l 2l
-7l 2l
 8l 2l
 9l 2l
 kl 2l
 ql 2l
 vl 2l
+0a 8a
+5a 8a
+6a 8a
+8a 8a
+9a 8a
+ka 8a
+qa 8a
+va 8a
+0c 8c
+5c 8c
+6c 8c
+8c 8c
+9c 8c
+kc 8c
+qc 8c
+vc 8c
+0l 8l
+5l 8l
+6l 8l
+8l 8l
+9l 8l
+kl 8l
+ql 8l
+vl 8l
 abaco abaco
 readweb abaco
 acid acid

+ 15 - 3
sys/man/1/INDEX.html

@@ -12,15 +12,27 @@
 </DT>
 <DT><A HREF="/magic/man2html/1/2a">2a</A>
 -  assemblers
-<DD><TT> 0a, 1a, 2a, 5a, 6a, 7a, 8a, 9a, ka, qa, va</TT>
+<DD><TT> 0a, 5a, 6a, 8a, 9a, ka, qa, va</TT>
 </DT>
 <DT><A HREF="/magic/man2html/1/2c">2c</A>
 -  C compilers
-<DD><TT> 0c, 1c, 2c, 5c, 6c, 7c, 8c, 9c, kc, qc, vc</TT>
+<DD><TT> 0c, 5c, 6c, 8c, 9c, kc, qc, vc</TT>
 </DT>
 <DT><A HREF="/magic/man2html/1/2l">2l</A>
 -  loaders
-<DD><TT> 0l, 1l, 2l, 5l, 6l, 7l, 8l, 9l, kl, ql, vl</TT>
+<DD><TT> 0l, 5l, 6l, 8l, 9l, kl, ql, vl</TT>
+</DT>
+<DT><A HREF="/magic/man2html/1/8a">8a</A>
+-  assemblers
+<DD><TT> 0a, 5a, 6a, 8a, 9a, ka, qa, va</TT>
+</DT>
+<DT><A HREF="/magic/man2html/1/8c">8c</A>
+-  C compilers
+<DD><TT> 0c, 5c, 6c, 8c, 9c, kc, qc, vc</TT>
+</DT>
+<DT><A HREF="/magic/man2html/1/8l">8l</A>
+-  loaders
+<DD><TT> 0l, 5l, 6l, 8l, 9l, kl, ql, vl</TT>
 </DT>
 <DT><A HREF="/magic/man2html/1/abaco">abaco</A>
 -  browse the World-Wide Web

+ 5 - 5
sys/man/1/acid

@@ -63,7 +63,7 @@ Assume instructions are for the given CPU type
 .BR amd64 ,
 .BR 386 ,
 etc., as listed in
-.IR 2c (1),
+.IR 8c (1),
 or
 .B sunsparc
 or
@@ -91,7 +91,7 @@ If the function
 .IR acidinit ()
 is defined, it will be invoked after all libraries have been loaded.
 See
-.IR 2c (1)
+.IR 8c (1)
 for information about creating
 .I acid
 functions for examining data structures.
@@ -470,9 +470,9 @@ acid: cont()
 .SH SOURCE
 .B /sys/src/cmd/acid
 .SH "SEE ALSO"
-.IR 2a (1),
-.IR 2c (1),
-.IR 2l (1),
+.IR 8a (1),
+.IR 8c (1),
+.IR 8l (1),
 .IR mk (1),
 .IR db (1)
 .br

+ 2 - 2
sys/man/1/ar

@@ -19,7 +19,7 @@ combined into a single archive file,
 The main use of
 .I ar
 is to create and update library files for the loaders
-.IR 2l (1),
+.IR 8l (1),
 etc.
 It can be used, though, for any similar purpose.
 .PP
@@ -172,7 +172,7 @@ temporaries
 .SH SOURCE
 .B /sys/src/cmd/ar.c
 .SH "SEE ALSO"
-.IR 2l (1), 
+.IR 8l (1), 
 .IR ar (6)
 .SH BUGS
 If the same file is mentioned twice in an argument list,

+ 2 - 2
sys/man/1/cpp

@@ -31,7 +31,7 @@ The options are:
 .TP
 .BI -I dir\^
 Same as in
-.IR 2c "(1): add
+.IR 8c "(1): add
 .I dir
 to the search for
 .CW search
@@ -116,4 +116,4 @@ directory for machine-dependent include files
 .SH SOURCE
 .B /sys/src/cmd/cpp
 .SH SEE ALSO
-.IR 2c (1)
+.IR 8c (1)

+ 3 - 3
sys/man/1/mk

@@ -168,13 +168,13 @@ In the recipe of a meta-rule, the environment variable
 contains the string matched by the
 .BR % .
 For example, a meta-rule to compile a C program using
-.IR 2c (1)
+.IR 8c (1)
 might be:
 .IP
 .EX
 %:    %.c
-        2c $stem.c
-        2l -o $stem $stem.2
+        8c $stem.c
+        8l -o $stem $stem.2
 .EE
 .PP
 Meta-rules may contain an ampersand

+ 1 - 1
sys/man/1/nm

@@ -100,7 +100,7 @@ Print only undefined symbols.
 .B /sys/src/cmd/nm.c
 .SH SEE ALSO
 .IR ar (1),
-.IR 2l (1), 
+.IR 8l (1), 
 .IR db (1),
 .IR acid (1),
 .IR a.out (6)

+ 7 - 7
sys/man/1/pcc

@@ -18,11 +18,11 @@ Named files ending with
 are preprocessed with
 .IR cpp (1),
 then compiled with one of the compilers described in
-.IR 2c (1),
+.IR 8c (1),
 as specified by the environment variable
 .BR $objtype .
 The object files are then loaded using one of the loaders described in
-.IR 2l (1).
+.IR 8l (1).
 The options are:
 .TP \w'\fL-D\ \fIname=def\ 'u
 .B "-+
@@ -72,7 +72,7 @@ ANSI function prototypes.
 Enable
 .B void*
 conversion warnings, as in
-.IR 2c (1).
+.IR 8c (1).
 .TP
 .B -v
 Echo the preprocessing, compiling, and loading commands
@@ -133,7 +133,7 @@ are omitted.
 .TP
 .B -F
 Enable vararg type checking as described in 
-.IR 2c (1).
+.IR 8c (1).
 This is of limited use without the appropriate 
 .B #pragma 
 definitions.
@@ -162,9 +162,9 @@ files.
 ANSI C/POSIX library.
 .SH "SEE ALSO"
 .IR cpp (1),
-.IR 2c (1),
-.IR 2a (1),
-.IR 2l (1),
+.IR 8c (1),
+.IR 8a (1),
+.IR 8l (1),
 .IR mk (1),
 .IR nm (1),
 .IR acid (1),

+ 2 - 2
sys/man/1/prof

@@ -24,7 +24,7 @@ prof, tprof, kprof \- display profiling data
 interprets files produced automatically by programs loaded using the
 .B -p
 option of
-.IR 2l (1)
+.IR 8l (1)
 or other loader.
 The symbol table in the
 named program file
@@ -162,6 +162,6 @@ has no options and cannot present dynamic data.
 .br
 .B /sys/src/cmd/kprof.c
 .SH SEE ALSO
-.IR 2l (1),
+.IR 8l (1),
 .IR exec (2),
 .IR kprof (3)

+ 2 - 2
sys/man/2/0intro

@@ -431,8 +431,8 @@ or
 .IR mouse (2).
 .SH SEE ALSO
 .IR nm (1), 
-.IR 2l (1), 
-.IR 2c (1)
+.IR 8l (1), 
+.IR 8c (1)
 .SH DIAGNOSTICS
 Math functions in
 .I libc

+ 1 - 0
sys/man/2/INDEX

@@ -1192,6 +1192,7 @@ segbrk segbrk
 segflush segflush
 semacquire semacquire
 semrelease semacquire
+tsemacquire semacquire
 longjmp setjmp
 notejmp setjmp
 setjmp setjmp

+ 1 - 1
sys/man/2/INDEX.html

@@ -520,7 +520,7 @@
 </DT>
 <DT><A HREF="/magic/man2html/2/semacquire">semacquire</A>
 -  user level semaphores
-<DD><TT> semacquire, semrelease</TT>
+<DD><TT> semacquire, tsemacquire, semrelease</TT>
 </DT>
 <DT><A HREF="/magic/man2html/2/setjmp">setjmp</A>
 -  non-local goto

+ 1 - 1
sys/man/2/fmtinstall

@@ -298,7 +298,7 @@ All these routines return zero for successful execution.
 Conversion routines that call these functions will work properly
 regardless of whether the output is bytes or runes.
 .PP
-.IR 2c (1)
+.IR 8c (1)
 describes the C directive
 .B #pragma
 .B varargck

+ 2 - 2
sys/man/2/mach

@@ -167,7 +167,7 @@ data structure.
 .I Machbyname
 performs the same selection based
 on the name of a processor class; see
-.IR 2c (1)
+.IR 8c (1)
 for a list of valid names.
 Both functions point global variables
 .I mach
@@ -388,7 +388,7 @@ contained in
 .SH SOURCE
 .B /sys/src/libmach
 .SH "SEE ALSO"
-.IR 2c (1),
+.IR 8c (1),
 .IR symbol (2),
 .IR object (2),
 .IR errstr (2),

+ 1 - 0
sys/man/3/INDEX

@@ -49,3 +49,4 @@ eia uart
 uart uart
 usb usb
 vga vga
+wd wd

+ 4 - 0
sys/man/3/INDEX.html

@@ -166,4 +166,8 @@
 -  VGA controller device
 <DD><TT> vga</TT>
 </DT>
+<DT><A HREF="/magic/man2html/3/wd">wd</A>
+-  hardware watchdog timer
+<DD><TT> wd</TT>
+</DT>
 </DL>

+ 0 - 1
sys/man/4/INDEX

@@ -48,7 +48,6 @@ ramfs ramfs
 ratfs ratfs
 rdbfs rdbfs
 rio rio
-sacfs sacfs
 snap snap
 snapfs snap
 9fs srv

+ 0 - 4
sys/man/4/INDEX.html

@@ -138,10 +138,6 @@
 -  window system files
 <DD><TT> rio</TT>
 </DT>
-<DT><A HREF="/magic/man2html/4/sacfs">sacfs</A>
--  compressed file system
-<DD><TT> sacfs</TT>
-</DT>
 <DT><A HREF="/magic/man2html/4/snap">snap</A>
 -  create and mount process snapshots
 <DD><TT> snap, snapfs</TT>

+ 2 - 2
sys/man/4/namespace

@@ -87,7 +87,7 @@ architecture-specific files, to be selected according to
 or
 .B $cputype
 (see
-.IR 2c (1)
+.IR 8c (1)
 and
 .IR init (8)).
 Here we list only those for
@@ -113,7 +113,7 @@ containing auxiliary tools and collecting related programs.
 Directory of object code libraries as used by
 .B 8l
 (see
-.IR 2l (1)).
+.IR 8l (1)).
 .TP
 .B /386/include
 Directory of x86-specific C include files.

+ 2 - 2
sys/man/6/a.out

@@ -239,8 +239,8 @@ symbol in the symbol table.
 .SH "SEE ALSO"
 .IR db (1), 
 .IR acid (1), 
-.IR 2a (1), 
-.IR 2l (1), 
+.IR 8a (1), 
+.IR 8l (1), 
 .IR nm (1), 
 .IR strip (1),
 .IR mach (2),

+ 2 - 2
sys/man/6/ar

@@ -10,7 +10,7 @@ is used to combine several files into
 one.
 Archives are used mainly as libraries to be searched
 by the loaders
-.IR 2l (1)
+.IR 8l (1)
 .I et al.
 .PP
 A file produced by
@@ -85,7 +85,7 @@ There is no provision for empty areas in an archive
 file.
 .SH "SEE ALSO"
 .IR ar (1), 
-.IR 2l (1), 
+.IR 8l (1), 
 .IR nm (1),
 .IR stat (2)
 .SH BUGS

+ 1 - 7
sys/man/8/INDEX

@@ -114,7 +114,6 @@ mkflashfs mkflashfs
 mkext mkfs
 mkfs mkfs
 mkpaqfs mkpaqfs
-mksacfs mksacfs
 mkusbboot mkusbboot
 aux/accupoint mouse
 aux/mouse mouse
@@ -137,12 +136,6 @@ newuser newuser
 nfsserver nfsserver
 pcnfsd nfsserver
 portmapper nfsserver
-9loadask old9load
-9loadusb old9load
-9pxeload old9load
-ld old9load
-old9load old9load
-old9load: 9load old9load
 partfs partfs
 pci pci
 pcmcia pcmcia
@@ -226,4 +219,5 @@ fmtisect venti-fmt
 syncindex venti-fmt
 venti-fmt venti-fmt
 vga vga
+watchdog watchdog
 wol wol

+ 5 - 9
sys/man/8/INDEX.html

@@ -11,7 +11,7 @@
 <DD><TT> intro</TT>
 </DT>
 <DT><A HREF="/magic/man2html/8/6in4">6in4</A>
--  configure and run automatic or manual 6to4 tunnel of IPv6 through IPv4
+-  6to4 tunnel of IPv6 through IPv4
 <DD><TT> 6in4</TT>
 </DT>
 <DT><A HREF="/magic/man2html/8/9boot">9boot</A>
@@ -162,10 +162,6 @@
 -  make a compressed read-only file system
 <DD><TT> mkpaqfs</TT>
 </DT>
-<DT><A HREF="/magic/man2html/8/mksacfs">mksacfs</A>
--  make a compressed file system
-<DD><TT> mksacfs</TT>
-</DT>
 <DT><A HREF="/magic/man2html/8/mkusbboot">mkusbboot</A>
 -  generate bootable USB or other disk image for PC
 <DD><TT> mkusbboot</TT>
@@ -190,10 +186,6 @@
 -  NFS service
 <DD><TT> nfsserver, portmapper, pcnfsd</TT>
 </DT>
-<DT><A HREF="/magic/man2html/8/old9load">old9load</A>
--  old PC bootstrap program
-<DD><TT> old9load: 9load, 9pxeload, 9loadusb, 9loadask, ld</TT>
-</DT>
 <DT><A HREF="/magic/man2html/8/partfs">partfs</A>
 -  serve file, with partitions
 <DD><TT> partfs</TT>
@@ -330,6 +322,10 @@
 -  configure a VGA card
 <DD><TT> vga</TT>
 </DT>
+<DT><A HREF="/magic/man2html/8/watchdog">watchdog</A>
+-  reset the system if it gets stuck
+<DD><TT> watchdog</TT>
+</DT>
 <DT><A HREF="/magic/man2html/8/wol">wol</A>
 -  send wake-on-lan Ethernet packet
 <DD><TT> wol</TT>

File diff suppressed because it is too large
+ 0 - 0
sys/man/searchindex


+ 6 - 1
sys/src/9/pc/x86watchdog.c

@@ -48,9 +48,14 @@ interval(void)
 static void
 runoncpu(int cpu)
 {
-	while (m->machno != cpu) {
+	if (m->machno != cpu) {
+		if (up == nil)
+			panic("x86watchdog: nil up");
 		procwired(up, cpu);
 		sched();
+		if (m->machno != cpu)
+			panic("x86watchdog: runoncpu: can't switch to cpu%d",
+				cpu);
 	}
 }
 

+ 41 - 1
sys/src/9/port/devwd.c

@@ -15,6 +15,7 @@ enum {
 };
 
 static Watchdog *wd;
+static int wdautopet;
 static Ref refs;
 static Dirtab wddir[] = {
 	".",		{ Qdir, 0, QTDIR },	0,		0555,
@@ -34,6 +35,44 @@ addwatchdog(Watchdog *watchdog)
 		wd->disable();
 }
 
+static void
+wdpet(void)
+{
+	if (wdautopet)
+		wd->restart();
+}
+
+/*
+ * reassure the watchdog from the clock interrupt
+ * until the user takes control of it.
+ */
+static void
+wdautostart(void)
+{
+	if (wdautopet || !wd)
+		return;
+	iprint("watchdog: on with clock strokes\n");
+	wd->enable();
+	wdautopet = 1;
+	addclock0link(wdpet, 200);
+}
+
+static void
+wdautostop(void)
+{
+	if (!wdautopet)
+		return;
+	wdautopet = 0;
+	wd->disable();
+	iprint("watchdog: off\n");
+}
+
+static void
+wdreset(void)
+{
+	wdautostart();
+}
+
 static Chan*
 wdattach(char *spec)
 {
@@ -55,6 +94,7 @@ wdstat(Chan *c, uchar *dp, int n)
 static Chan*
 wdopen(Chan* c, int omode)
 {
+	wdautostop();
 	c = devopen(c, omode, wddir, nelem(wddir), devgen);
 	if (c->qid.path == Qwdctl)
 		incref(&refs);
@@ -152,7 +192,7 @@ Dev wddevtab = {
 	'w',
 	"watchdog",
 
-	devreset,
+	wdreset,
 	devinit,
 	wdshutdown,
 	wdattach,

+ 0 - 201
sys/src/cmd/2a/a.h

@@ -1,201 +0,0 @@
-#include <u.h>
-#include <libc.h>
-#include <bio.h>
-#include "../2c/2.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	Addr 	Addr;
-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	Addr
-{
-	Sym*	sym;
-	long	offset;
-	short	type;
-};
-struct	Gen
-{
-	Addr;
-	double	dval;
-	char	sval[8];
-	long	displace;
-	short	type;
-	short	index;
-	short	scale;
-	short	field;
-};
-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	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*);
-
-enum				/* keep in synch with ../cc/cc.h */
-{
-	Plan9	= 1<<0,
-	Unix	= 1<<1,
-	Windows	= 1<<2
-};
-
-/*
- *	system-dependent stuff from ../cc/compat.c
- */
-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 - 540
sys/src/cmd/2a/a.y

@@ -1,540 +0,0 @@
-%{
-#include "a.h"
-%}
-%union	{
-	Sym	*sym;
-	long	lval;
-	double	dval;
-	char	sval[8];
-	Addr	addr;
-	Gen	gen;
-	Gen2	gen2;
-}
-%left	'|'
-%left	'^'
-%left	'&'
-%left	'<' '>'
-%left	'+' '-'
-%left	'*' '/' '%'
-%token	<lval>	LTYPE1 LTYPE2 LTYPE3 LTYPE4 LTYPE5
-%token	<lval>	LTYPE6 LTYPE7 LTYPE8 LTYPE9 LTYPEA LTYPEB
-%token	<lval>	LCONST LSP LSB LFP LPC LTOS LAREG LDREG LFREG LWID
-%token	<dval>	LFCONST
-%token	<sval>	LSCONST
-%token	<sym>	LNAME LLAB LVAR
-%type	<lval>	con expr scale type pointer reg offset
-%type	<addr>	name areg xreg
-%type	<gen>	gen rel
-%type	<gen2>	noaddr gengen dstgen spec1 spec2 spec3 srcgen dstrel genrel
-%%
-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;
-	}
-|	LTYPE1 gengen	{ outcode($1, &$2); }
-|	LTYPE2 noaddr	{ outcode($1, &$2); }
-|	LTYPE3 dstgen	{ outcode($1, &$2); }
-|	LTYPE4 spec1	{ outcode($1, &$2); }
-|	LTYPE5 srcgen	{ outcode($1, &$2); }
-|	LTYPE6 dstrel	{ outcode($1, &$2); }
-|	LTYPE7 genrel	{ outcode($1, &$2); }
-|	LTYPE8 dstgen	{ outcode($1, &$2); }
-|	LTYPE8 gengen	{ outcode($1, &$2); }
-|	LTYPE9 noaddr	{ outcode($1, &$2); }
-|	LTYPE9 dstgen	{ outcode($1, &$2); }
-|	LTYPEA spec2	{ outcode($1, &$2); }
-|	LTYPEB spec3	{ outcode($1, &$2); }
-
-noaddr:
-	{
-		$$.from = nullgen;
-		$$.to = nullgen;
-	}
-|	','
-	{
-		$$.from = nullgen;
-		$$.to = nullgen;
-	}
-
-srcgen:
-	gen
-	{
-		$$.from = $1;
-		$$.to = nullgen;
-	}
-|	gen ','
-	{
-		$$.from = $1;
-		$$.to = nullgen;
-	}
-
-dstgen:
-	gen
-	{
-		$$.from = nullgen;
-		$$.to = $1;
-	}
-|	',' gen
-	{
-		$$.from = nullgen;
-		$$.to = $2;
-	}
-
-gengen:
-	gen ',' gen
-	{
-		$$.from = $1;
-		$$.to = $3;
-	}
-
-dstrel:
-	rel
-	{
-		$$.from = nullgen;
-		$$.to = $1;
-	}
-|	',' rel
-	{
-		$$.from = nullgen;
-		$$.to = $2;
-	}
-
-genrel:
-	gen ',' rel
-	{
-		$$.from = $1;
-		$$.to = $3;
-	}
-
-spec1:	/* DATA opcode */
-	gen '/' con ',' gen
-	{
-		$1.displace = $3;
-		$$.from = $1;
-		$$.to = $5;
-	}
-
-spec2:	/* bit field opcodes */
-	gen ',' gen ',' con ',' con
-	{
-		$1.field = $7;
-		$3.field = $5;
-		$$.from = $1;
-		$$.to = $3;
-	}
-
-spec3:	/* TEXT opcode */
-	gengen
-|	gen ',' con ',' gen
-	{
-		$1.displace = $3;
-		$$.from = $1;
-		$$.to = $5;
-	}
-
-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;
-	}
-
-gen:
-	type
-	{
-		$$ = nullgen;
-		$$.type = $1;
-	}
-|	'$' con
-	{
-		$$ = nullgen;
-		$$.type = D_CONST;
-		$$.offset = $2;
-	}
-|	'$' name
-	{
-		$$ = nullgen;
-		{
-			Addr *a;
-			a = &$$;
-			*a = $2;
-		}
-		if($2.type == D_AUTO || $2.type == D_PARAM)
-			yyerror("constant cannot be automatic: %s",
-				$2.sym->name);
-		$$.type = $2.type | I_ADDR;
-	}
-|	'$' LSCONST
-	{
-		$$ = nullgen;
-		$$.type = D_SCONST;
-		memcpy($$.sval, $2, sizeof($$.sval));
-	}
-|	'$' LFCONST
-	{
-		$$ = nullgen;
-		$$.type = D_FCONST;
-		$$.dval = $2;
-	}
-|	'$' '-' LFCONST
-	{
-		$$ = nullgen;
-		$$.type = D_FCONST;
-		$$.dval = -$3;
-	}
-|	LTOS '+' con
-	{
-		$$ = nullgen;
-		$$.type = D_STACK;
-		$$.offset = $3;
-	}
-|	LTOS '-' con
-	{
-		$$ = nullgen;
-		$$.type = D_STACK;
-		$$.offset = -$3;
-	}
-|	con
-	{
-		$$ = nullgen;
-		$$.type = D_CONST | I_INDIR;
-		$$.offset = $1;
-	}
-|	'-' '(' LAREG ')'
-	{
-		$$ = nullgen;
-		$$.type = $3 | I_INDDEC;
-	}
-|	'(' LAREG ')' '+'
-	{
-		$$ = nullgen;
-		$$.type = $2 | I_INDINC;
-	}
-|	areg
-	{
-		$$ = nullgen;
-		$$.type = $1.type;
-		{
-			Addr *a;
-			a = &$$;
-			*a = $1;
-		}
-		if(($$.type & D_MASK) == D_NONE) {
-			$$.index = D_NONE | I_INDEX1;
-			$$.scale = 0;
-			$$.displace = 0;
-		}
-	}
-|	areg xreg
-	{
-		$$ = nullgen;
-		$$.type = $1.type;
-		{
-			Addr *a;
-			a = &$$;
-			*a = $1;
-		}
-		$$.index = $2.type | I_INDEX1;
-		$$.scale = $2.offset;
-	}
-|	'(' areg ')' xreg
-	{
-		$$ = nullgen;
-		$$.type = $2.type;
-		{
-			Addr *a;
-			a = &$$;
-			*a = $2;
-		}
-		$$.index = $4.type | I_INDEX2;
-		$$.scale = $4.offset;
-		$$.displace = 0;
-	}
-|	con '(' areg ')' xreg
-	{
-		$$ = nullgen;
-		$$.type = $3.type;
-		{
-			Addr *a;
-			a = &$$;
-			*a = $3;
-		}
-		$$.index = $5.type | I_INDEX2;
-		$$.scale = $5.offset;
-		$$.displace = $1;
-	}
-|	'(' areg ')'
-	{
-		$$ = nullgen;
-		$$.type = $2.type;
-		{
-			Addr *a;
-			a = &$$;
-			*a = $2;
-		}
-		$$.index = D_NONE | I_INDEX3;
-		$$.scale = 0;
-		$$.displace = 0;
-	}
-|	con '(' areg ')'
-	{
-		$$ = nullgen;
-		$$.type = $3.type;
-		{
-			Addr *a;
-			a = &$$;
-			*a = $3;
-		}
-		$$.index = D_NONE | I_INDEX3;
-		$$.scale = 0;
-		$$.displace = $1;
-	}
-|	'(' areg xreg ')'
-	{
-		$$ = nullgen;
-		$$.type = $2.type;
-		{
-			Addr *a;
-			a = &$$;
-			*a = $2;
-		}
-		$$.index = $3.type | I_INDEX3;
-		$$.scale = $3.offset;
-		$$.displace = 0;
-	}
-|	con '(' areg xreg ')'
-	{
-		$$ = nullgen;
-		$$.type = $3.type;
-		{
-			Addr *a;
-			a = &$$;
-			*a = $3;
-		}
-		$$.index = $4.type | I_INDEX3;
-		$$.scale = $4.offset;
-		$$.displace = $1;
-	}
-
-type:
-	reg
-|	LFREG
-
-xreg:
-	/*
-	 *	.W*1	0
-	 *	.W*2	1
-	 *	.W*4	2
-	 *	.W*8	3
-	 *	.L*1	4
-	 *	.L*2	5
-	 *	.L*4	6
-	 *	.L*8	7
-	 */
-	'(' reg LWID scale ')'
-	{
-		$$.type = $2;
-		$$.offset = $3+$4;
-		$$.sym = S;
-	}
-
-reg:
-	LAREG
-|	LDREG
-|	LTOS
-
-scale:
-	'*' con
-	{
-		switch($2) {
-		case 1:
-			$$ = 0;
-			break;
-
-		case 2:
-			$$ = 1;
-			break;
-
-		default:
-			yyerror("bad scale: %ld", $2);
-
-		case 4:
-			$$ = 2;
-			break;
-
-		case 8:
-			$$ = 3;
-			break;
-		}
-	}
-
-areg:
-	'(' LAREG ')'
-	{
-		$$.type = $2 | I_INDIR;
-		$$.sym = S;
-		$$.offset = 0;
-	}
-|	con '(' LAREG ')'
-	{
-		$$.type = $3 | I_INDIR;
-		$$.sym = S;
-		$$.offset = $1;
-	}
-|	'(' ')'
-	{
-		$$.type = D_NONE | I_INDIR;
-		$$.sym = S;
-		$$.offset = 0;
-	}
-|	con '(' ')'
-	{
-		$$.type = D_NONE | I_INDIR;
-		$$.sym = S;
-		$$.offset = $1;
-	}
-|	name
-
-name:
-	LNAME offset '(' pointer ')'
-	{
-		$$.type = $4;
-		$$.sym = $1;
-		$$.offset = $2;
-	}
-|	LNAME '<' '>' offset '(' LSB ')'
-	{
-		$$.type = 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;
-	}
-
-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 - 479
sys/src/cmd/2a/l.s

@@ -1,479 +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		8192			/* bytes per page */
-#define	WD2PG		(BY2PG/BY2WD)		/* words per page */
-#define	PGSHIFT		13			/* log(BY2PG) */
-#define PGROUND(s)	(((s)+(BY2PG-1))&~(BY2PG-1))
-#define ICACHESIZE	0
-#define MB4		(4*1024*1024)		/* Lots of things are 4Mb in size */
-
-#define	MAXMACH		1			/* max # cpus system can run */
-
-/*
- * Time
- */
-#define	HZ		(60)			/* 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 */
-
-/*
- * SR bits
- */
-#define SUPER		0x2000
-#define SPL(n)		(n<<8)
-
-/*
- * CACR
- */
-#define	CCLEAR		0x08
-#define	CENABLE		0x01
-
-/*
- * Magic registers (unused in current system)
- */
-
-#define	MACH		A5		/* A5 is m-> */
-#define	USER		A4		/* A4 is u-> */
-
-/*
- * Fundamental addresses
- */
-
-#define	USERADDR	0x80000000
-/* assuming we're in a syscall, this is the address of the Ureg structure */
-#define	UREGVARSZ	(23*BY2WD)	/* size of variable part of Ureg */
-#define	UREGADDR	(USERADDR+BY2PG-(UREGVARSZ+2+4+2+(8+8+1+1)*BY2WD))
-
-/*
- * Devices poked during bootstrap
- */
-#define	TACADDR		0x40600000
-#define	MOUSE		0x40200000
-
-/*
- * MMU
- */
-
-#define	VAMASK	0xCFFFFFFF	/* clear balu bits in address */
-#define	KUSEG	0x00000000
-#define KSEG	0x80000000
-
-/*
- * MMU entries
- */
-#define	PTEVALID	(1<<13)
-#define PTEWRITE	0
-#define	PTERONLY	(1<<14)
-#define	PTEKERNEL	(1<<15)
-#define PTEUNCACHED	0
-#define	INVALIDPTE	0
-#define PTEMAPMEM	(1024*1024)	
-#define	PTEPERTAB	(PTEMAPMEM/BY2PG)
-#define SEGMAPSIZE	16
-
-#define	PPN(pa)		((pa>>13)&0x1FFF)
-
-#define	KMAP	((unsigned long *)0xD0000000)
-#define	UMAP	((unsigned long *)0x50000000)
-
-/*
- * Virtual addresses
- */
-#define	VTAG(va)	((va>>22)&0x03F)
-#define	VPN(va)		((va>>13)&0x1FF)
-
-#define	PARAM		((char*)0x40500000)
-#define	TLBFLUSH_	0x01
-
-/*
- * Address spaces
- */
-
-#define	UZERO	KUSEG			/* base of user address space */
-#define	UTZERO	(UZERO+BY2PG)		/* first address in user text */
-#define	TSTKTOP	0x10000000		/* end of new stack in sysexec */
-#define TSTKSIZ 100
-#define	USTKTOP	(TSTKTOP-TSTKSIZ*BY2PG) /* byte just beyond user stack */
-#define	KZERO	KSEG			/* base of kernel address space */
-#define	KTZERO	(KZERO+BY2PG)		/* first address in kernel text */
-#define	USTKSIZE	(4*1024*1024)	/* size of user stack */
-
-#define	MACHSIZE	4096
-
-
-#define isphys(p) ((((ulong)(p))&0xF0000000) == KSEG)
-#define	DBMAGIC		0xBADC0C0A
-
-/*
- * Boot first processor
- */
-TEXT	start(SB), $-4
-
-	MOVW	$(SUPER|SPL(7)), SR
-	MOVL	$a6base(SB), A6
-	MOVL	$0, R0
-	MOVL	R0, CACR
-	MOVL	R0, TACADDR		/* zero tac counter (cause an intr?) */
-
-	MOVL	$mach0(SB), A0
-	MOVL	A0, m(SB)
-	MOVL	$0, 0(A0)
-	MOVL	A0, A7
-	ADDL	$(MACHSIZE-4), A7	/* start stack under machine struct */
-	MOVL	$0, u(SB)
-
-	MOVL	$vectors(SB), A0
-	MOVL	A0, VBR
-
-	BSR	main(SB)
-	/* never returns */
-dead:
-	BRA	dead
-
-/*
- * Take first processor into user mode.  Leave enough room on the stack
- * for a full-sized Ureg (including long bus error format) to fit
- */
-
-TEXT	touser(SB), $-4
-
-	MOVL	$(USERADDR+BY2PG-UREGVARSZ), A7
-	MOVW	$0, -(A7)
-	MOVL	$(UTZERO+32), -(A7)	/* header is in text */
-	MOVW	$0, -(A7)
-	MOVL	$(USTKTOP-6*BY2WD), A0	/* MAXSYSARG=6 */
-	MOVL	A0, USP
-	MOVW	$(SUPER|SPL(0)), SR
-	MOVL	$8, R0
-	MOVL	R0, CACR
-	RTE
-
-TEXT	firmware(SB), $0
-
-	MOVL	$0x40000090, A0
-	JMP	(A0)
-
-TEXT	splhi(SB), $0
-
-	MOVL	m(SB), A0
-	MOVL	(A7), 4(A0)
-	MOVL	$0, R0
-	MOVW	SR, R0
-	MOVW	$(SUPER|SPL(7)), SR
-	RTS
-
-TEXT	splduart(SB), $0
-
-	MOVL	$0, R0
-	MOVW	SR, R0
-	MOVW	$(SUPER|SPL(5)), SR
-	RTS
-
-TEXT	spllo(SB), $0
-
-	MOVL	$0, R0
-	MOVW	SR, R0
-	MOVW	$(SUPER|SPL(0)), SR
-	RTS
-
-TEXT	splx(SB), $0
-
-	MOVL	sr+0(FP), R0
-	MOVW	R0, SR
-	RTS
-
-TEXT	spldone(SB), $0
-
-	RTS
-
-TEXT	spl1(SB), $0
-
-	MOVL	$0, R0
-	MOVW	SR, R0
-	MOVW	$(SUPER|SPL(1)), SR
-	RTS
-
-TEXT	flushcpucache(SB), $0
-
-	MOVL	$(CCLEAR|CENABLE), R0
-	MOVL	R0, CACR
-	RTS
-
-TEXT	cacrtrap(SB), $0	/* user entry point to control cache, e.g. flush */
-
-	MOVL	R0, CACR
-	RTE
-
-TEXT	setlabel(SB), $0
-
-	MOVL	sr+0(FP), A0
-	MOVL	A7, (A0)+		/* stack pointer */
-	MOVL	(A7), (A0)+		/* pc of caller */
-	MOVW	SR, (A0)+		/* status register */
-	CLRL	R0			/* ret 0 => not returning */
-	RTS
-
-TEXT	gotolabel(SB), $0
-
-	MOVL	p+0(FP), A0
-	MOVW	$(SUPER|SPL(7)), SR
-	MOVL	(A0)+, A7		/* stack pointer */
-	MOVL	(A0)+, (A7)		/* pc; stuff into stack frame */
-	MOVW	(A0)+, R0		/* status register */
-	MOVW	R0, SR
-	MOVL	$1, R0			/* ret 1 => returning */
-	RTS
-
-/*
- * Test and set, as a subroutine
- */
-
-TEXT	tas(SB), $0
-
-	MOVL	$0, R0
-	MOVL	a+0(FP), A0
-	TAS	(A0)
-	BEQ	tas_1
-	MOVL	$1, R0
-tas_1:
-	RTS
-
-/*
- * Floating point
- */
-
-TEXT	fpsave(SB), $0
-
-	FSAVE	(fp+0(FP))
-	RTS
-
-TEXT	fprestore(SB), $0
-
-	FRESTORE	(fp+0(FP))
-	RTS
-
-TEXT	fpregsave(SB), $0
-
-	FMOVEM	$0xFF, (3*4)(fr+0(FP))
-	FMOVEMC	$0x7, (fr+0(FP))
-	RTS
-
-TEXT	fpregrestore(SB), $0
-
-	FMOVEMC	(fr+0(FP)), $0x7
-	FMOVEM	(3*4)(fr+0(FP)), $0xFF
-	RTS
-
-TEXT	fpcr(SB), $0
-
-	MOVL	new+0(FP), R1
-	MOVL	FPCR, R0
-	MOVL	R1, FPCR
-	RTS
-
-
-TEXT	rfnote(SB), $0
-
-	MOVL	uregp+0(FP), A7
-	MOVL	((8+8)*BY2WD)(A7), A0
-	MOVL	A0, USP
-	MOVEM	(A7), $0x7FFF
-	ADDL	$((8+8+1+1)*BY2WD), A7
-	RTE
-
-TEXT	illegal(SB), $0
-
-	MOVL	$DBMAGIC, -(A7)
-	SUBL	$((8+8+1)*BY2WD), A7
-	MOVEM	$0x7FFF, (A7)
-	MOVL	$a6base(SB), A6
-	MOVL	USP, A0
-	MOVL	A0, ((8+8)*BY2WD)(A7)
-	MOVL	A7, -(A7)
-	BSR	trap(SB)
-	ADDL	$4, A7
-	MOVL	((8+8)*BY2WD)(A7), A0
-	MOVL	A0, USP
-	MOVEM	(A7), $0x7FFF
-	ADDL	$((8+8+1)*BY2WD+BY2WD), A7
-	RTE
-
-TEXT	systrap(SB), $0
-
-	MOVL	$DBMAGIC, -(A7)
-	SUBL	$((8+8+1)*BY2WD), A7
-	MOVL	A6, ((8+6)*BY2WD)(A7)
-	MOVL	R0, (A7)
-	MOVL	$a6base(SB), A6
-	MOVL	USP, A0
-	MOVL	A0, ((8+8)*BY2WD)(A7)
-	MOVL	A7, -(A7)
-	BSR	syscall(SB)
-	MOVL	((1+8+8)*BY2WD)(A7), A0
-	MOVL	A0, USP
-	MOVL	((1+8+6)*BY2WD)(A7), A6
-	ADDL	$((1+8+8+1)*BY2WD+BY2WD), A7
-	RTE
-
-TEXT	buserror(SB), $0
-
-	MOVL	$DBMAGIC, -(A7)
-	SUBL	$((8+8+1)*BY2WD), A7
-	MOVEM	$0x7FFF, (A7)
-	MOVL	$a6base(SB), A6
-	MOVL	USP, A0
-	MOVL	A0, ((8+8)*BY2WD)(A7)
-	PEA	((8+8+1+3)*BY2WD)(A7)
-	PEA	4(A7)
-	BSR	fault68020(SB)
-	ADDL	$8, A7
-	MOVL	((8+8)*BY2WD)(A7), A0
-	MOVL	A0, USP
-	MOVEM	(A7), $0x7FFF
-	ADDL	$((8+8+1)*BY2WD+BY2WD), A7
-	RTE
-
-TEXT	tacintr(SB), $0			/* level 1 */
-
-	MOVL	R0, -(A7)
-	MOVL	TACADDR, R0
-	MOVL	(A7)+, R0
-	RTE
-
-TEXT	portintr(SB), $0		/* level 2 */
-
-	MOVL	$DBMAGIC, -(A7)
-	SUBL	$((8+8+1)*BY2WD), A7
-	MOVEM	$0x7FFF, (A7)
-	MOVL	$a6base(SB), A6
-	MOVL	USP, A0
-	MOVL	A0, ((8+8)*BY2WD)(A7)
-	MOVL	A7, -(A7)
-	BSR	devportintr(SB)
-	BRA	retintr
-
-TEXT	dkintr(SB), $0			/* level 3 */
-
-	MOVL	$DBMAGIC, -(A7)
-	SUBL	$((8+8+1)*BY2WD), A7
-	MOVEM	$0x7FFF, (A7)
-	MOVL	$a6base(SB), A6
-	MOVL	USP, A0
-	MOVL	A0, ((8+8)*BY2WD)(A7)
-	MOVL	A7, -(A7)
-	BSR	inconintr(SB)
-	BRA	retintr
-
-TEXT	mouseintr(SB), $0		/* level 4 */
-
-	MOVEM	$0x80C2, -(A7)		/* D0, A0, A1, A6 */
-	MOVL	$a6base(SB), A6
-	MOVL	$15, R0			/* mask off hex switch */
-	ANDB	MOUSE,R0		/* clears quadrature interrupt */
-	LEA	mousetab(SB)(R0.W*8), A0
-	LEA	mouse(SB), A1
-	MOVL	(A0)+, R0
-	ADDL	R0, (A1)+		/* dx */
-	MOVL	(A0), R0
-	ADDL	R0, (A1)+		/* dy */
-	ADDL	$1, (A1)		/* track */
-	MOVEM	(A7)+, $0x4301
-	RTE
-
-TEXT	uartintr(SB), $0		/* level 5 */
-
-	MOVL	$DBMAGIC, -(A7)
-	SUBL	$((8+8+1)*BY2WD), A7
-	MOVEM	$0x7FFF, (A7)
-	MOVL	$a6base(SB), A6
-	MOVL	USP, A0
-	MOVL	A0, ((8+8)*BY2WD)(A7)
-	MOVL	A7, -(A7)
-	BSR	duartintr(SB)
-	BRA	retintr
-
-TEXT	syncintr(SB), $0		/* level 6 */
-
-	MOVL	$DBMAGIC, -(A7)
-	SUBL	$((8+8+1)*BY2WD), A7
-	MOVEM	$0x7FFF, (A7)
-	MOVL	$a6base(SB), A6
-	MOVL	USP, A0
-	MOVL	A0, ((8+8)*BY2WD)(A7)
-	MOVL	A7, -(A7)
-	BSR	clock(SB)
-	/* fall through */
-retintr:
-	BSR	mousetry(SB)
-	ADDL	$4, A7
-	MOVL	((8+8)*BY2WD)(A7), A0
-	MOVL	A0, USP
-	MOVEM	(A7), $0x7FFF
-	ADDL	$((8+8+1)*BY2WD+BY2WD), A7
-	RTE
-
-GLOBL	duarttimer+0(SB),$4
-
-TEXT	duartreadtimer+0(SB), $0
-	MOVW	SR, R1		/* spl7() */
-	MOVW	$0x2700, SR
-	MOVL	$0x40100000, A0
-	CLRL	R0
-	TSTB	15(A0)		/* stop timer */
-	MOVW	6(A0), R0	/* read hi,lo */
-	TSTB	14(A0)		/* restart timer */
-	NOTW	R0		/* timer counts down from 0xffff */
-	ADDL	duarttimer(SB), R0
-	MOVL	R0, duarttimer(SB)
-	MOVW	R1, SR
-	RTS
-
-GLOBL	mousetab(SB), $128
-DATA	mousetab+  0(SB)/4, -1		/* x down,        */
-DATA	mousetab+  4(SB)/4,  1		/*         y up   */
-DATA	mousetab+  8(SB)/4,  0		/* x -            */
-DATA	mousetab+ 12(SB)/4,  1		/*         y up   */
-DATA	mousetab+ 16(SB)/4,  1		/* x up           */
-DATA	mousetab+ 20(SB)/4,  1		/*         y up   */
-DATA	mousetab+ 24(SB)/4,  0		/* x  -           */
-DATA	mousetab+ 28(SB)/4,  1		/*         y up   */
-DATA	mousetab+ 32(SB)/4, -1		/* x down         */
-DATA	mousetab+ 36(SB)/4,  0		/*         y -    */
-DATA	mousetab+ 40(SB)/4,  0		/* x -            */
-DATA	mousetab+ 44(SB)/4,  0		/*         y -    */
-DATA	mousetab+ 48(SB)/4,  1		/* x up,          */
-DATA	mousetab+ 52(SB)/4,  0		/*         y -    */
-DATA	mousetab+ 56(SB)/4,  0		/* x -            */
-DATA	mousetab+ 60(SB)/4,  0		/*         y -    */
-DATA	mousetab+ 64(SB)/4, -1		/* x down         */
-DATA	mousetab+ 68(SB)/4, -1		/*         y down */
-DATA	mousetab+ 72(SB)/4,  0		/* x -            */
-DATA	mousetab+ 76(SB)/4, -1		/*         y down */
-DATA	mousetab+ 80(SB)/4,  1		/* x up           */
-DATA	mousetab+ 84(SB)/4, -1		/*         y down */
-DATA	mousetab+ 88(SB)/4,  0		/* x -            */
-DATA	mousetab+ 92(SB)/4, -1		/*         y down */
-DATA	mousetab+ 96(SB)/4, -1		/* x down         */
-DATA	mousetab+100(SB)/4,  0		/*         y -    */
-DATA	mousetab+104(SB)/4,  0		/* x -            */
-DATA	mousetab+108(SB)/4,  0		/*         y -    */
-DATA	mousetab+112(SB)/4,  1		/* x up           */
-DATA	mousetab+116(SB)/4,  0		/*         y -    */
-DATA	mousetab+120(SB)/4,  0		/* x -            */
-DATA	mousetab+124(SB)/4,  0		/*         y -    */
-
-GLOBL	mach0+0(SB), $MACHSIZE
-GLOBL	u(SB), $4
-GLOBL	m(SB), $4

+ 0 - 936
sys/src/cmd/2a/lex.c

@@ -1,936 +0,0 @@
-#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 = '2';
-	thestring = "68020";
-	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;
-	ushort	type;
-	ushort	value;
-} itab[] =
-{
-	"SP",		LSP,	D_AUTO,
-	"SB",		LSB,	D_EXTERN,
-	"FP",		LFP,	D_PARAM,
-	"PC",		LPC,	D_BRANCH,
-	"TOS",		LTOS,	D_TOS,
-	"CCR",		LTOS,	D_CCR,
-	"SR",		LTOS,	D_SR,
-	"SFC",		LTOS,	D_SFC,
-	"DFC",		LTOS,	D_DFC,
-	"CACR",		LTOS,	D_CACR,
-	"USP",		LTOS,	D_USP,
-	"VBR",		LTOS,	D_VBR,
-	"CAAR",		LTOS,	D_CAAR,
-	"MSP",		LTOS,	D_MSP,
-	"ISP",		LTOS,	D_ISP,
-	"FPCR",		LTOS,	D_FPCR,
-	"FPSR",		LTOS,	D_FPSR,
-	"FPIAR",	LTOS,	D_FPIAR,
-	"TC",		LTOS,	D_TC,
-	"ITT0",		LTOS,	D_ITT0,
-	"ITT1",		LTOS,	D_ITT1,
-	"DTT0",		LTOS,	D_DTT0,
-	"DTT1",		LTOS,	D_DTT1,
-	"MMUSR",	LTOS,	D_MMUSR,
-	"URP",		LTOS,	D_URP,
-	"SRP",		LTOS,	D_SRP,
-
-	"R0",		LDREG,	D_R0+0,
-	"R1",		LDREG,	D_R0+1,
-	"R2",		LDREG,	D_R0+2,
-	"R3",		LDREG,	D_R0+3,
-	"R4",		LDREG,	D_R0+4,
-	"R5",		LDREG,	D_R0+5,
-	"R6",		LDREG,	D_R0+6,
-	"R7",		LDREG,	D_R0+7,
-
-	".W",		LWID,	0,
-	".L",		LWID,	4,
-
-	"A0",		LAREG,	D_A0+0,
-	"A1",		LAREG,	D_A0+1,
-	"A2",		LAREG,	D_A0+2,
-	"A3",		LAREG,	D_A0+3,
-	"A4",		LAREG,	D_A0+4,
-	"A5",		LAREG,	D_A0+5,
-	"A6",		LAREG,	D_A0+6,
-	"A7",		LAREG,	D_A0+7,
-
-	"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,
-
-	"ABCD",		LTYPE1, AABCD,
-	"ADDB",		LTYPE1, AADDB,
-	"ADDL",		LTYPE1, AADDL,
-	"ADDW",		LTYPE1, AADDW,
-	"ADDXB",	LTYPE1, AADDXB,
-	"ADDXL",	LTYPE1, AADDXL,
-	"ADDXW",	LTYPE1, AADDXW,
-	"ADJSP",	LTYPE5, AADJSP,
-	"ANDB",		LTYPE1, AANDB,
-	"ANDL",		LTYPE1, AANDL,
-	"ANDW",		LTYPE1, AANDW,
-	"ASLB",		LTYPE1, AASLB,
-	"ASLL",		LTYPE1, AASLL,
-	"ASLW",		LTYPE1, AASLW,
-	"ASRB",		LTYPE1, AASRB,
-	"ASRL",		LTYPE1, AASRL,
-	"ASRW",		LTYPE1, AASRW,
-	"BCASE",	LTYPE7, ABCASE,
-	"BCC",		LTYPE6, ABCC,
-	"BCHG",		LTYPE1, ABCHG,
-	"BCLR",		LTYPE1, ABCLR,
-	"BCS",		LTYPE6, ABCS,
-	"BEQ",		LTYPE6, ABEQ,
-	"BFCHG",	LTYPEA, ABFCHG,
-	"BFCLR",	LTYPEA, ABFCLR,
-	"BFEXTS",	LTYPEA, ABFEXTS,
-	"BFEXTU",	LTYPEA, ABFEXTU,
-	"BFFFO",	LTYPEA, ABFFFO,
-	"BFINS",	LTYPEA, ABFINS,
-	"BFSET",	LTYPEA, ABFSET,
-	"BFTST",	LTYPEA, ABFTST,
-	"BGE",		LTYPE6, ABGE,
-	"BGT",		LTYPE6, ABGT,
-	"BHI",		LTYPE6, ABHI,
-	"BKPT",		LTYPE1, ABKPT,
-	"BLE",		LTYPE6, ABLE,
-	"BLS",		LTYPE6, ABLS,
-	"BLT",		LTYPE6, ABLT,
-	"BMI",		LTYPE6, ABMI,
-	"BNE",		LTYPE6, ABNE,
-	"BPL",		LTYPE6, ABPL,
-	"BRA",		LTYPE6, ABRA,
-	"BSET",		LTYPE1, ABSET,
-	"BSR",		LTYPE3, ABSR,
-	"BTST",		LTYPE1, ABTST,
-	"BVC",		LTYPE6, ABVC,
-	"BVS",		LTYPE6, ABVS,
-	"CALLM",	LTYPE1, ACALLM,
-	"CAS2B",	LTYPE1, ACAS2B,
-	"CAS2L",	LTYPE1, ACAS2L,
-	"CAS2W",	LTYPE1, ACAS2W,
-	"CASB",		LTYPE1, ACASB,
-	"CASEW",	LTYPE2, ACASEW,
-	"CASL",		LTYPE1, ACASL,
-	"CASW",		LTYPE1, ACASW,
-	"CHK2B",	LTYPE1, ACHK2B,
-	"CHK2L",	LTYPE1, ACHK2L,
-	"CHK2W",	LTYPE1, ACHK2W,
-	"CHKL",		LTYPE1, ACHKL,
-	"CHKW",		LTYPE1, ACHKW,
-	"CLRB",		LTYPE3, ACLRB,
-	"CLRL",		LTYPE3, ACLRL,
-	"CLRW",		LTYPE3, ACLRW,
-	"CMP2B",	LTYPE1, ACMP2B,
-	"CMP2L",	LTYPE1, ACMP2L,
-	"CMP2W",	LTYPE1, ACMP2W,
-	"CMPB",		LTYPE1, ACMPB,
-	"CMPL",		LTYPE1, ACMPL,
-	"CMPW",		LTYPE1, ACMPW,
-	"DATA",		LTYPE4, ADATA,
-	"DBCC",		LTYPE7, ADBCC,
-	"DBCS",		LTYPE7, ADBCS,
-	"DBEQ",		LTYPE7, ADBEQ,
-	"DBF",		LTYPE7, ADBF,
-	"DBGE",		LTYPE7, ADBGE,
-	"DBGT",		LTYPE7, ADBGT,
-	"DBHI",		LTYPE7, ADBHI,
-	"DBLE",		LTYPE7, ADBLE,
-	"DBLS",		LTYPE7, ADBLS,
-	"DBLT",		LTYPE7, ADBLT,
-	"DBMI",		LTYPE7, ADBMI,
-	"DBNE",		LTYPE7, ADBNE,
-	"DBPL",		LTYPE7, ADBPL,
-	"DBT",		LTYPE7, ADBT,
-	"DBVC",		LTYPE7, ADBVC,
-	"DBVS",		LTYPE7, ADBVS,
-	"DIVSL",	LTYPE1, ADIVSL,
-	"DIVSW",	LTYPE1, ADIVSW,
-	"DIVUL",	LTYPE1, ADIVUL,
-	"DIVUW",	LTYPE1, ADIVUW,
-	"END",		LTYPE2, AEND,
-	"EORB",		LTYPE1, AEORB,
-	"EORL",		LTYPE1, AEORL,
-	"EORW",		LTYPE1, AEORW,
-	"EXG",		LTYPE1, AEXG,
-	"EXTBL",	LTYPE3, AEXTBL,
-	"EXTBW",	LTYPE3, AEXTBW,
-	"EXTWL",	LTYPE3, AEXTWL,
-	"FABSB",	LTYPE1, AFABSB,
-	"FABSD",	LTYPE1, AFABSD,
-	"FABSF",	LTYPE1, AFABSF,
-	"FABSL",	LTYPE1, AFABSL,
-	"FABSW",	LTYPE1, AFABSW,
-	"FACOSB",	LTYPE1, AFACOSB,
-	"FACOSD",	LTYPE1, AFACOSD,
-	"FACOSF",	LTYPE1, AFACOSF,
-	"FACOSL",	LTYPE1, AFACOSL,
-	"FACOSW",	LTYPE1, AFACOSW,
-	"FADDB",	LTYPE1, AFADDB,
-	"FADDD",	LTYPE1, AFADDD,
-	"FADDF",	LTYPE1, AFADDF,
-	"FADDL",	LTYPE1, AFADDL,
-	"FADDW",	LTYPE1, AFADDW,
-	"FASINB",	LTYPE1, AFASINB,
-	"FASIND",	LTYPE1, AFASIND,
-	"FASINF",	LTYPE1, AFASINF,
-	"FASINL",	LTYPE1, AFASINL,
-	"FASINW",	LTYPE1, AFASINW,
-	"FATANB",	LTYPE1, AFATANB,
-	"FATAND",	LTYPE1, AFATAND,
-	"FATANF",	LTYPE1, AFATANF,
-	"FATANHB",	LTYPE1, AFATANHB,
-	"FATANHD",	LTYPE1, AFATANHD,
-	"FATANHF",	LTYPE1, AFATANHF,
-	"FATANHL",	LTYPE1, AFATANHL,
-	"FATANHW",	LTYPE1, AFATANHW,
-	"FATANL",	LTYPE1, AFATANL,
-	"FATANW",	LTYPE1, AFATANW,
-	"FBEQ",		LTYPE6, AFBEQ,
-	"FBF",		LTYPE6, AFBF,
-	"FBGE",		LTYPE6, AFBGE,
-	"FBGT",		LTYPE6, AFBGT,
-	"FBLE",		LTYPE6, AFBLE,
-	"FBLT",		LTYPE6, AFBLT,
-	"FBNE",		LTYPE6, AFBNE,
-	"FBT",		LTYPE6, AFBT,
-	"FCMPB",	LTYPE1, AFCMPB,
-	"FCMPD",	LTYPE1, AFCMPD,
-	"FCMPF",	LTYPE1, AFCMPF,
-	"FCMPL",	LTYPE1, AFCMPL,
-	"FCMPW",	LTYPE1, AFCMPW,
-	"FCOSB",	LTYPE1, AFCOSB,
-	"FCOSD",	LTYPE1, AFCOSD,
-	"FCOSF",	LTYPE1, AFCOSF,
-	"FCOSHB",	LTYPE1, AFCOSHB,
-	"FCOSHD",	LTYPE1, AFCOSHD,
-	"FCOSHF",	LTYPE1, AFCOSHF,
-	"FCOSHL",	LTYPE1, AFCOSHL,
-	"FCOSHW",	LTYPE1, AFCOSHW,
-	"FCOSL",	LTYPE1, AFCOSL,
-	"FCOSW",	LTYPE1, AFCOSW,
-	"FDBEQ",	LTYPE7, AFDBEQ,
-	"FDBF",		LTYPE7, AFDBF,
-	"FDBGE",	LTYPE7, AFDBGE,
-	"FDBGT",	LTYPE7, AFDBGT,
-	"FDBLE",	LTYPE7, AFDBLE,
-	"FDBLT",	LTYPE7, AFDBLT,
-	"FDBNE",	LTYPE7, AFDBNE,
-	"FDBT",		LTYPE7, AFDBT,
-	"FDIVB",	LTYPE1, AFDIVB,
-	"FDIVD",	LTYPE1, AFDIVD,
-	"FDIVF",	LTYPE1, AFDIVF,
-	"FDIVL",	LTYPE1, AFDIVL,
-	"FDIVW",	LTYPE1, AFDIVW,
-	"FETOXB",	LTYPE1, AFETOXB,
-	"FETOXD",	LTYPE1, AFETOXD,
-	"FETOXF",	LTYPE1, AFETOXF,
-	"FETOXL",	LTYPE1, AFETOXL,
-	"FETOXM1B",	LTYPE1, AFETOXM1B,
-	"FETOXM1D",	LTYPE1, AFETOXM1D,
-	"FETOXM1F",	LTYPE1, AFETOXM1F,
-	"FETOXM1L",	LTYPE1, AFETOXM1L,
-	"FETOXM1W",	LTYPE1, AFETOXM1W,
-	"FETOXW",	LTYPE1, AFETOXW,
-	"FGETEXPB",	LTYPE1, AFGETEXPB,
-	"FGETEXPD",	LTYPE1, AFGETEXPD,
-	"FGETEXPF",	LTYPE1, AFGETEXPF,
-	"FGETEXPL",	LTYPE1, AFGETEXPL,
-	"FGETEXPW",	LTYPE1, AFGETEXPW,
-	"FGETMANB",	LTYPE1, AFGETMANB,
-	"FGETMAND",	LTYPE1, AFGETMAND,
-	"FGETMANF",	LTYPE1, AFGETMANF,
-	"FGETMANL",	LTYPE1, AFGETMANL,
-	"FGETMANW",	LTYPE1, AFGETMANW,
-	"FINTB",	LTYPE1, AFINTB,
-	"FINTD",	LTYPE1, AFINTD,
-	"FINTF",	LTYPE1, AFINTF,
-	"FINTL",	LTYPE1, AFINTL,
-	"FINTRZB",	LTYPE1, AFINTRZB,
-	"FINTRZD",	LTYPE1, AFINTRZD,
-	"FINTRZF",	LTYPE1, AFINTRZF,
-	"FINTRZL",	LTYPE1, AFINTRZL,
-	"FINTRZW",	LTYPE1, AFINTRZW,
-	"FINTW",	LTYPE1, AFINTW,
-	"FLOG10B",	LTYPE1, AFLOG10B,
-	"FLOG10D",	LTYPE1, AFLOG10D,
-	"FLOG10F",	LTYPE1, AFLOG10F,
-	"FLOG10L",	LTYPE1, AFLOG10L,
-	"FLOG10W",	LTYPE1, AFLOG10W,
-	"FLOG2B",	LTYPE1, AFLOG2B,
-	"FLOG2D",	LTYPE1, AFLOG2D,
-	"FLOG2F",	LTYPE1, AFLOG2F,
-	"FLOG2L",	LTYPE1, AFLOG2L,
-	"FLOG2W",	LTYPE1, AFLOG2W,
-	"FLOGNB",	LTYPE1, AFLOGNB,
-	"FLOGND",	LTYPE1, AFLOGND,
-	"FLOGNF",	LTYPE1, AFLOGNF,
-	"FLOGNL",	LTYPE1, AFLOGNL,
-	"FLOGNP1B",	LTYPE1, AFLOGNP1B,
-	"FLOGNP1D",	LTYPE1, AFLOGNP1D,
-	"FLOGNP1F",	LTYPE1, AFLOGNP1F,
-	"FLOGNP1L",	LTYPE1, AFLOGNP1L,
-	"FLOGNP1W",	LTYPE1, AFLOGNP1W,
-	"FLOGNW",	LTYPE1, AFLOGNW,
-	"FMODB",	LTYPE1, AFMODB,
-	"FMODD",	LTYPE1, AFMODD,
-	"FMODF",	LTYPE1, AFMODF,
-	"FMODL",	LTYPE1, AFMODL,
-	"FMODW",	LTYPE1, AFMODW,
-	"FMOVEB",	LTYPE1, AFMOVEB,
-	"FMOVED",	LTYPE1, AFMOVED,
-	"FMOVEF",	LTYPE1, AFMOVEF,
-	"FMOVEL",	LTYPE1, AFMOVEL,
-	"FMOVEW",	LTYPE1, AFMOVEW,
-	"FMULB",	LTYPE1, AFMULB,
-	"FMULD",	LTYPE1, AFMULD,
-	"FMULF",	LTYPE1, AFMULF,
-	"FMULL",	LTYPE1, AFMULL,
-	"FMULW",	LTYPE1, AFMULW,
-	"FNEGB",	LTYPE8, AFNEGB,
-	"FNEGD",	LTYPE8, AFNEGD,
-	"FNEGF",	LTYPE8, AFNEGF,
-	"FNEGL",	LTYPE8, AFNEGL,
-	"FNEGW",	LTYPE8, AFNEGW,
-	"FREMB",	LTYPE1, AFREMB,
-	"FREMD",	LTYPE1, AFREMD,
-	"FREMF",	LTYPE1, AFREMF,
-	"FREML",	LTYPE1, AFREML,
-	"FREMW",	LTYPE1, AFREMW,
-	"FSCALEB",	LTYPE1, AFSCALEB,
-	"FSCALED",	LTYPE1, AFSCALED,
-	"FSCALEF",	LTYPE1, AFSCALEF,
-	"FSCALEL",	LTYPE1, AFSCALEL,
-	"FSCALEW",	LTYPE1, AFSCALEW,
-	"FSEQ",		LTYPE1, AFSEQ,
-	"FSF",		LTYPE1, AFSF,
-	"FSGE",		LTYPE1, AFSGE,
-	"FSGT",		LTYPE1, AFSGT,
-	"FSINB",	LTYPE1, AFSINB,
-	"FSIND",	LTYPE1, AFSIND,
-	"FSINF",	LTYPE1, AFSINF,
-	"FSINHB",	LTYPE1, AFSINHB,
-	"FSINHD",	LTYPE1, AFSINHD,
-	"FSINHF",	LTYPE1, AFSINHF,
-	"FSINHL",	LTYPE1, AFSINHL,
-	"FSINHW",	LTYPE1, AFSINHW,
-	"FSINL",	LTYPE1, AFSINL,
-	"FSINW",	LTYPE1, AFSINW,
-	"FSLE",		LTYPE1, AFSLE,
-	"FSLT",		LTYPE1, AFSLT,
-	"FSNE",		LTYPE1, AFSNE,
-	"FSQRTB",	LTYPE1, AFSQRTB,
-	"FSQRTD",	LTYPE1, AFSQRTD,
-	"FSQRTF",	LTYPE1, AFSQRTF,
-	"FSQRTL",	LTYPE1, AFSQRTL,
-	"FSQRTW",	LTYPE1, AFSQRTW,
-	"FST",		LTYPE1, AFST,
-	"FSUBB",	LTYPE1, AFSUBB,
-	"FSUBD",	LTYPE1, AFSUBD,
-	"FSUBF",	LTYPE1, AFSUBF,
-	"FSUBL",	LTYPE1, AFSUBL,
-	"FSUBW",	LTYPE1, AFSUBW,
-	"FTANB",	LTYPE1, AFTANB,
-	"FTAND",	LTYPE1, AFTAND,
-	"FTANF",	LTYPE1, AFTANF,
-	"FTANHB",	LTYPE1, AFTANHB,
-	"FTANHD",	LTYPE1, AFTANHD,
-	"FTANHF",	LTYPE1, AFTANHF,
-	"FTANHL",	LTYPE1, AFTANHL,
-	"FTANHW",	LTYPE1, AFTANHW,
-	"FTANL",	LTYPE1, AFTANL,
-	"FTANW",	LTYPE1, AFTANW,
-	"FTENTOXB",	LTYPE1, AFTENTOXB,
-	"FTENTOXD",	LTYPE1, AFTENTOXD,
-	"FTENTOXF",	LTYPE1, AFTENTOXF,
-	"FTENTOXL",	LTYPE1, AFTENTOXL,
-	"FTENTOXW",	LTYPE1, AFTENTOXW,
-	"FTSTB",	LTYPE1, AFTSTB,
-	"FTSTD",	LTYPE1, AFTSTD,
-	"FTSTF",	LTYPE1, AFTSTF,
-	"FTSTL",	LTYPE1, AFTSTL,
-	"FTSTW",	LTYPE1, AFTSTW,
-	"FTWOTOXB",	LTYPE1, AFTWOTOXB,
-	"FTWOTOXD",	LTYPE1, AFTWOTOXD,
-	"FTWOTOXF",	LTYPE1, AFTWOTOXF,
-	"FTWOTOXL",	LTYPE1, AFTWOTOXL,
-	"FTWOTOXW",	LTYPE1, AFTWOTOXW,
-	"FMOVEM",	LTYPE1, AFMOVEM,
-	"FMOVEMC",	LTYPE1, AFMOVEMC,
-	"FRESTORE",	LTYPE3, AFRESTORE,
-	"FSAVE",	LTYPE3, AFSAVE,
-	"GLOBL",	LTYPE1, AGLOBL,
-	"GOK",		LTYPE2, AGOK,
-	"HISTORY",	LTYPE2, AHISTORY,
-	"ILLEG",	LTYPE2, AILLEG,
-	"INSTR",	LTYPE3, AINSTR,
-	"JMP",		LTYPE3, AJMP,
-	"JSR",		LTYPE3, AJSR,
-	"LEA",		LTYPE1, ALEA,
-	"LINKL",	LTYPE1, ALINKL,
-	"LINKW",	LTYPE1, ALINKW,
-	"LOCATE",	LTYPE1, ALOCATE,
-	"LONG",		LTYPE3, ALONG,
-	"LSLB",		LTYPE1, ALSLB,
-	"LSLL",		LTYPE1, ALSLL,
-	"LSLW",		LTYPE1, ALSLW,
-	"LSRB",		LTYPE1, ALSRB,
-	"LSRL",		LTYPE1, ALSRL,
-	"LSRW",		LTYPE1, ALSRW,
-	"MOVB",		LTYPE1, AMOVB,
-	"MOVEM",	LTYPE1, AMOVEM,
-	"MOVEPL",	LTYPE1, AMOVEPL,
-	"MOVEPW",	LTYPE1, AMOVEPW,
-	"MOVESB",	LTYPE1, AMOVESB,
-	"MOVESL",	LTYPE1, AMOVESL,
-	"MOVESW",	LTYPE1, AMOVESW,
-	"MOVL",		LTYPE1, AMOVL,
-	"MOVW",		LTYPE1, AMOVW,
-	"MULSL",	LTYPE1, AMULSL,
-	"MULSW",	LTYPE1, AMULSW,
-	"MULUL",	LTYPE1, AMULUL,
-	"MULUW",	LTYPE1, AMULUW,
-	"NAME",		LTYPE1, ANAME,
-	"NBCD",		LTYPE3, ANBCD,
-	"NEGB",		LTYPE3, ANEGB,
-	"NEGL",		LTYPE3, ANEGL,
-	"NEGW",		LTYPE3, ANEGW,
-	"NEGXB",	LTYPE3, ANEGXB,
-	"NEGXL",	LTYPE3, ANEGXL,
-	"NEGXW",	LTYPE3, ANEGXW,
-	"NOP",		LTYPE9, ANOP,
-	"NOTB",		LTYPE3, ANOTB,
-	"NOTL",		LTYPE3, ANOTL,
-	"NOTW",		LTYPE3, ANOTW,
-	"ORB",		LTYPE1, AORB,
-	"ORL",		LTYPE1, AORL,
-	"ORW",		LTYPE1, AORW,
-	"PACK",		LTYPE1, APACK,
-	"PEA",		LTYPE3, APEA,
-	"RESET",	LTYPE2, ARESET,
-	"ROTLB",	LTYPE1, AROTLB,
-	"ROTLL",	LTYPE1, AROTLL,
-	"ROTLW",	LTYPE1, AROTLW,
-	"ROTRB",	LTYPE1, AROTRB,
-	"ROTRL",	LTYPE1, AROTRL,
-	"ROTRW",	LTYPE1, AROTRW,
-	"ROXLB",	LTYPE1, AROXLB,
-	"ROXLL",	LTYPE1, AROXLL,
-	"ROXLW",	LTYPE1, AROXLW,
-	"ROXRB",	LTYPE1, AROXRB,
-	"ROXRL",	LTYPE1, AROXRL,
-	"ROXRW",	LTYPE1, AROXRW,
-	"RTD",		LTYPE3, ARTD,
-	"RTE",		LTYPE2, ARTE,
-	"RTM",		LTYPE3, ARTM,
-	"RTR",		LTYPE2, ARTR,
-	"RTS",		LTYPE2, ARTS,
-	"SBCD",		LTYPE1, ASBCD,
-	"SCC",		LTYPE3, ASCC,
-	"SCS",		LTYPE3, ASCS,
-	"SEQ",		LTYPE3, ASEQ,
-	"SF",		LTYPE3, ASF,
-	"SGE",		LTYPE3, ASGE,
-	"SGT",		LTYPE3, ASGT,
-	"SHI",		LTYPE3, ASHI,
-	"SLE",		LTYPE3, ASLE,
-	"SLS",		LTYPE3, ASLS,
-	"SLT",		LTYPE3, ASLT,
-	"SMI",		LTYPE3, ASMI,
-	"SNE",		LTYPE3, ASNE,
-	"SPL",		LTYPE3, ASPL,
-	"ST",		LTYPE3, AST,
-	"STOP",		LTYPE3, ASTOP,
-	"SUBB",		LTYPE1, ASUBB,
-	"SUBL",		LTYPE1, ASUBL,
-	"SUBW",		LTYPE1, ASUBW,
-	"SUBXB",	LTYPE1, ASUBXB,
-	"SUBXL",	LTYPE1, ASUBXL,
-	"SUBXW",	LTYPE1, ASUBXW,
-	"SVC",		LTYPE2, ASVC,
-	"SVS",		LTYPE2, ASVS,
-	"SWAP",		LTYPE3, ASWAP,
-	"SYS",		LTYPE2, ASYS,
-	"TAS",		LTYPE3, ATAS,
-	"TEXT",		LTYPEB, ATEXT,
-	"TRAP",		LTYPE3, ATRAP,
-	"TRAPCC",	LTYPE2, ATRAPCC,
-	"TRAPCS",	LTYPE2, ATRAPCS,
-	"TRAPEQ",	LTYPE2, ATRAPEQ,
-	"TRAPF",	LTYPE2, ATRAPF,
-	"TRAPGE",	LTYPE2, ATRAPGE,
-	"TRAPGT",	LTYPE2, ATRAPGT,
-	"TRAPHI",	LTYPE2, ATRAPHI,
-	"TRAPLE",	LTYPE2, ATRAPLE,
-	"TRAPLS",	LTYPE2, ATRAPLS,
-	"TRAPLT",	LTYPE2, ATRAPLT,
-	"TRAPMI",	LTYPE2, ATRAPMI,
-	"TRAPNE",	LTYPE2, ATRAPNE,
-	"TRAPPL",	LTYPE2, ATRAPPL,
-	"TRAPT",	LTYPE2, ATRAPT,
-	"TRAPV",	LTYPE2, ATRAPV,
-	"TRAPVC",	LTYPE2, ATRAPVC,
-	"TRAPVS",	LTYPE2, ATRAPVS,
-	"TSTB",		LTYPE3, ATSTB,
-	"TSTL",		LTYPE3, ATSTL,
-	"TSTW",		LTYPE3, ATSTW,
-	"UNLK",		LTYPE3, AUNLK,
-	"UNPK",		LTYPE1, AUNPK,
-	"WORD",		LTYPE3, AWORD,
-
-	0
-};
-
-void
-cinit(void)
-{
-	Sym *s;
-	int i;
-
-	nullgen.sym = S;
-	nullgen.offset = 0;
-	nullgen.type = D_NONE;
-	if(FPCHIP)
-		nullgen.dval = 0;
-	for(i=0; i<sizeof(nullgen.sval); i++)
-		nullgen.sval[i] = 0;
-	nullgen.displace = 0;
-	nullgen.type = D_NONE;
-	nullgen.index = D_NONE;
-	nullgen.scale = 0;
-	nullgen.field = 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(mygetwd(pathname, 99) == 0) {
-		pathname = allocn(pathname, 100, 900);
-		if(mygetwd(pathname, 999) == 0)
-			strcpy(pathname, "/???");
-	}
-}
-
-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 */
-	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)
-{
-	long l;
-	int i, t;
-	char *n;
-	Ieee e;
-
-	t = 0;
-	if(a->field)
-		t |= T_FIELD;
-	if(a->index != D_NONE || a->displace != 0)
-		t |= T_INDEX;
-	if(a->offset != 0)
-		t |= T_OFFSET;
-	if(s != 0)
-		t |= T_SYM;
-
-	if(a->type == D_FCONST)
-		t |= T_FCONST;
-	else
-	if(a->type == D_SCONST)
-		t |= T_SCONST;
-	else
-	if(a->type & ~0xff)
-		t |= T_TYPE;
-	Bputc(&obuf, t);
-
-	if(t & T_FIELD) {	/* implies field */
-		i = a->field;
-		Bputc(&obuf, i);
-		Bputc(&obuf, i>>8);
-	}
-	if(t & T_INDEX) {	/* implies index, scale, displace */
-		i = a->index;
-		Bputc(&obuf, i);
-		Bputc(&obuf, i>>8);
-		Bputc(&obuf, a->scale);
-		l = a->displace;
-		Bputc(&obuf, l);
-		Bputc(&obuf, l>>8);
-		Bputc(&obuf, l>>16);
-		Bputc(&obuf, l>>24);
-	}
-	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_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;
-	}
-	i = a->type;
-	Bputc(&obuf, i);
-	if(t & T_TYPE)
-		Bputc(&obuf, i>>8);
-}
-
-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 & D_MASK;
-		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 & D_MASK;
-		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 - 19
sys/src/cmd/2a/mkfile

@@ -1,19 +0,0 @@
-</$objtype/mkfile
-
-TARG=2a
-OFILES=\
-	y.tab.$O\
-	lex.$O\
-
-HFILES=\
-	../2c/2.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 ../cc/compat

+ 0 - 523
sys/src/cmd/2c/2.out.h

@@ -1,523 +0,0 @@
-#define	NSYM	50
-#define	NSNAME	8
-
-/* R0 is return */
-#define	REGEXT	7
-/* A7 is sp A6 is sb */
-#define	AREGEXT	5
-/* F0 is ret */
-#define	FREGEXT	7
-
-enum	as
-{
-	AXXX = 0,
-	AABCD,
-	AADDB,
-	AADDL,
-	AADDW,
-	AADDXB,
-	AADDXL,
-	AADDXW,
-	AADJSP,
-	AANDB,
-	AANDL,
-	AANDW,
-	AASLB,
-	AASLL,
-	AASLW,
-	AASRB,
-	AASRL,
-	AASRW,
-	ABCASE,
-	ABCC,
-	ABCHG,
-	ABCLR,
-	ABCS,
-	ABEQ,
-	ABFCHG,
-	ABFCLR,
-	ABFEXTS,
-	ABFEXTU,
-	ABFFFO,
-	ABFINS,
-	ABFSET,
-	ABFTST,
-	ABGE,
-	ABGT,
-	ABHI,
-	ABKPT,
-	ABLE,
-	ABLS,
-	ABLT,
-	ABMI,
-	ABNE,
-	ABPL,
-	ABRA,
-	ABSET,
-	ABSR,
-	ABTST,
-	ABVC,
-	ABVS,
-	ACALLM,
-	ACAS2B,
-	ACAS2L,
-	ACAS2W,
-	ACASB,
-	ACASEW,
-	ACASL,
-	ACASW,
-	ACHK2B,
-	ACHK2L,
-	ACHK2W,
-	ACHKL,
-	ACHKW,
-	ACLRB,
-	ACLRL,
-	ACLRW,
-	ACMP2B,
-	ACMP2L,
-	ACMP2W,
-	ACMPB,
-	ACMPL,
-	ACMPW,
-	ADATA,
-	ADBCC,
-	ADBCS,
-	ADBEQ,
-	ADBF,
-	ADBGE,
-	ADBGT,
-	ADBHI,
-	ADBLE,
-	ADBLS,
-	ADBLT,
-	ADBMI,
-	ADBNE,
-	ADBPL,
-	ADBT,
-	ADBVC,
-	ADBVS,
-	ADIVSL,
-	ADIVSW,
-	ADIVUL,
-	ADIVUW,
-	AEND,
-	AEORB,
-	AEORL,
-	AEORW,
-	AEXG,
-	AEXTBL,
-	AEXTBW,
-	AEXTWL,
-	AFABSB,
-	AFABSD,
-	AFABSF,
-	AFABSL,
-	AFABSW,
-	AFACOSB,
-	AFACOSD,
-	AFACOSF,
-	AFACOSL,
-	AFACOSW,
-	AFADDB,
-	AFADDD,
-	AFADDF,
-	AFADDL,
-	AFADDW,
-	AFASINB,
-	AFASIND,
-	AFASINF,
-	AFASINL,
-	AFASINW,
-	AFATANB,
-	AFATAND,
-	AFATANF,
-	AFATANHB,
-	AFATANHD,
-	AFATANHF,
-	AFATANHL,
-	AFATANHW,
-	AFATANL,
-	AFATANW,
-	AFBEQ,
-	AFBF,
-	AFBGE,
-	AFBGT,
-	AFBLE,
-	AFBLT,
-	AFBNE,
-	AFBT,
-	AFCMPB,
-	AFCMPD,
-	AFCMPF,
-	AFCMPL,
-	AFCMPW,
-	AFCOSB,
-	AFCOSD,
-	AFCOSF,
-	AFCOSHB,
-	AFCOSHD,
-	AFCOSHF,
-	AFCOSHL,
-	AFCOSHW,
-	AFCOSL,
-	AFCOSW,
-	AFDBEQ,
-	AFDBF,
-	AFDBGE,
-	AFDBGT,
-	AFDBLE,
-	AFDBLT,
-	AFDBNE,
-	AFDBT,
-	AFDIVB,
-	AFDIVD,
-	AFDIVF,
-	AFDIVL,
-	AFDIVW,
-	AFETOXB,
-	AFETOXD,
-	AFETOXF,
-	AFETOXL,
-	AFETOXM1B,
-	AFETOXM1D,
-	AFETOXM1F,
-	AFETOXM1L,
-	AFETOXM1W,
-	AFETOXW,
-	AFGETEXPB,
-	AFGETEXPD,
-	AFGETEXPF,
-	AFGETEXPL,
-	AFGETEXPW,
-	AFGETMANB,
-	AFGETMAND,
-	AFGETMANF,
-	AFGETMANL,
-	AFGETMANW,
-	AFINTB,
-	AFINTD,
-	AFINTF,
-	AFINTL,
-	AFINTRZB,
-	AFINTRZD,
-	AFINTRZF,
-	AFINTRZL,
-	AFINTRZW,
-	AFINTW,
-	AFLOG10B,
-	AFLOG10D,
-	AFLOG10F,
-	AFLOG10L,
-	AFLOG10W,
-	AFLOG2B,
-	AFLOG2D,
-	AFLOG2F,
-	AFLOG2L,
-	AFLOG2W,
-	AFLOGNB,
-	AFLOGND,
-	AFLOGNF,
-	AFLOGNL,
-	AFLOGNP1B,
-	AFLOGNP1D,
-	AFLOGNP1F,
-	AFLOGNP1L,
-	AFLOGNP1W,
-	AFLOGNW,
-	AFMODB,
-	AFMODD,
-	AFMODF,
-	AFMODL,
-	AFMODW,
-	AFMOVEB,
-	AFMOVED,
-	AFMOVEF,
-	AFMOVEL,
-	AFMOVEM,
-	AFMOVEMC,
-	AFMOVEW,
-	AFMULB,
-	AFMULD,
-	AFMULF,
-	AFMULL,
-	AFMULW,
-	AFNEGB,
-	AFNEGD,
-	AFNEGF,
-	AFNEGL,
-	AFNEGW,
-	AFREMB,
-	AFREMD,
-	AFREMF,
-	AFREML,
-	AFREMW,
-	AFRESTORE,
-	AFSAVE,
-	AFSCALEB,
-	AFSCALED,
-	AFSCALEF,
-	AFSCALEL,
-	AFSCALEW,
-	AFSEQ,
-	AFSF,
-	AFSGE,
-	AFSGT,
-	AFSINB,
-	AFSIND,
-	AFSINF,
-	AFSINHB,
-	AFSINHD,
-	AFSINHF,
-	AFSINHL,
-	AFSINHW,
-	AFSINL,
-	AFSINW,
-	AFSLE,
-	AFSLT,
-	AFSNE,
-	AFSQRTB,
-	AFSQRTD,
-	AFSQRTF,
-	AFSQRTL,
-	AFSQRTW,
-	AFST,
-	AFSUBB,
-	AFSUBD,
-	AFSUBF,
-	AFSUBL,
-	AFSUBW,
-	AFTANB,
-	AFTAND,
-	AFTANF,
-	AFTANHB,
-	AFTANHD,
-	AFTANHF,
-	AFTANHL,
-	AFTANHW,
-	AFTANL,
-	AFTANW,
-	AFTENTOXB,
-	AFTENTOXD,
-	AFTENTOXF,
-	AFTENTOXL,
-	AFTENTOXW,
-	AFTSTB,
-	AFTSTD,
-	AFTSTF,
-	AFTSTL,
-	AFTSTW,
-	AFTWOTOXB,
-	AFTWOTOXD,
-	AFTWOTOXF,
-	AFTWOTOXL,
-	AFTWOTOXW,
-	AGLOBL,
-	AGOK,
-	AHISTORY,
-	AILLEG,
-	AINSTR,
-	AJMP,
-	AJSR,
-	ALEA,
-	ALINKL,
-	ALINKW,
-	ALOCATE,
-	ALONG,
-	ALSLB,
-	ALSLL,
-	ALSLW,
-	ALSRB,
-	ALSRL,
-	ALSRW,
-	AMOVB,
-	AMOVEM,
-	AMOVEPL,
-	AMOVEPW,
-	AMOVESB,
-	AMOVESL,
-	AMOVESW,
-	AMOVL,
-	AMOVW,
-	AMULSL,
-	AMULSW,
-	AMULUL,
-	AMULUW,
-	ANAME,
-	ANBCD,
-	ANEGB,
-	ANEGL,
-	ANEGW,
-	ANEGXB,
-	ANEGXL,
-	ANEGXW,
-	ANOP,
-	ANOTB,
-	ANOTL,
-	ANOTW,
-	AORB,
-	AORL,
-	AORW,
-	APACK,
-	APEA,
-	ARESET,
-	AROTLB,
-	AROTLL,
-	AROTLW,
-	AROTRB,
-	AROTRL,
-	AROTRW,
-	AROXLB,
-	AROXLL,
-	AROXLW,
-	AROXRB,
-	AROXRL,
-	AROXRW,
-	ARTD,
-	ARTE,
-	ARTM,
-	ARTR,
-	ARTS,
-	ASBCD,
-	ASCC,
-	ASCS,
-	ASEQ,
-	ASF,
-	ASGE,
-	ASGT,
-	ASHI,
-	ASLE,
-	ASLS,
-	ASLT,
-	ASMI,
-	ASNE,
-	ASPL,
-	AST,
-	ASTOP,
-	ASUBB,
-	ASUBL,
-	ASUBW,
-	ASUBXB,
-	ASUBXL,
-	ASUBXW,
-	ASVC,
-	ASVS,
-	ASWAP,
-	ASYS,
-	ATAS,
-	ATEXT,
-	ATRAP,
-	ATRAPCC,
-	ATRAPCS,
-	ATRAPEQ,
-	ATRAPF,
-	ATRAPGE,
-	ATRAPGT,
-	ATRAPHI,
-	ATRAPLE,
-	ATRAPLS,
-	ATRAPLT,
-	ATRAPMI,
-	ATRAPNE,
-	ATRAPPL,
-	ATRAPT,
-	ATRAPV,
-	ATRAPVC,
-	ATRAPVS,
-	ATSTB,
-	ATSTL,
-	ATSTW,
-	AUNLK,
-	AUNPK,
-	AWORD,
-	ASIGNAME,
-
-	ALAST
-};
-
-enum
-{
-	NREG		= 8,
-
-	D_R0		= 0,
-	D_A0		= NREG,
-	D_F0		= D_A0+NREG,
-	D_NONE		= D_F0+NREG,
-	D_TOS,
-	D_BRANCH,
-	D_STACK,
-	D_TREE,
-	D_EXTERN,
-	D_STATIC,
-	D_AUTO,
-	D_PARAM,
-	D_CONST,
-	D_FCONST,
-	D_QUICK,
-
-	D_CCR,
-	D_SR,
-	D_SFC,
-	D_CACR,
-	D_USP,
-	D_VBR,
-	D_CAAR,
-	D_MSP,
-	D_ISP,
-	D_DFC,
-	D_FPCR,
-	D_FPSR,
-	D_FPIAR,
-	D_SCONST,
-	D_FILE,
-
-	D_TC,		/* new for 68040 */
-	D_ITT0,
-	D_ITT1,
-	D_DTT0,
-	D_DTT1,
-	D_MMUSR,
-	D_URP,
-	D_SRP,
-
-	D_FILE1,
-
-	D_MASK		= 63/(D_SRP>=63?0:1),
-
-	I_DIR		= (D_MASK+1)*0,
-	I_INDINC	= (D_MASK+1)*1,
-	I_INDDEC	= (D_MASK+1)*2,
-	I_INDIR		= (D_MASK+1)*3,
-	I_ADDR		= (D_MASK+1)*4,
-
-	I_INDEX1	= (D_MASK+1)*1,
-	I_INDEX2	= (D_MASK+1)*2,
-	I_INDEX3	= (D_MASK+1)*3,
-
-	I_MASK		= (D_MASK+1)*7,
-
-	T_FIELD		= 1<<0,
-	T_INDEX		= 1<<1,
-	T_TYPE		= 1<<2,
-	T_OFFSET	= 1<<3,
-	T_FCONST	= 1<<4,
-	T_SYM		= 1<<5,
-	T_SCONST	= 1<<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 - 127
sys/src/cmd/2c/bits.c

@@ -1,127 +0,0 @@
-#define	EXTERN
-#include "gc.h"
-
-/*
-Bits
-bor(Bits a, Bits b)
-{
-	Bits c;
-	int i;
-
-	for(i=0; i<BITS; i++)
-		c.b[i] = a.b[i] | b.b[i];
-	return c;
-}
-*/
-
-/*
-Bits
-band(Bits a, Bits b)
-{
-	Bits c;
-	int i;
-
-	for(i=0; i<BITS; i++)
-		c.b[i] = a.b[i] & b.b[i];
-	return c;
-}
-*/
-
-/*
-Bits
-bnot(Bits a)
-{
-	Bits c;
-	int i;
-
-	for(i=0; i<BITS; i++)
-		c.b[i] = ~a.b[i];
-	return c;
-}
-*/
-
-int
-bany(Bits *a)
-{
-	int i;
-
-	for(i=0; i<BITS; i++)
-		if(a->b[i])
-			return 1;
-	return 0;
-}
-
-/*
-int
-beq(Bits a, Bits b)
-{
-	int i;
-
-	for(i=0; i<BITS; i++)
-		if(a.b[i] != b.b[i])
-			return 0;
-	return 1;
-}
-*/
-
-int
-bnum(Bits a)
-{
-	int i;
-	long b;
-
-	for(i=0; i<BITS; i++)
-		if(b = a.b[i])
-			return 32*i + bitno(b);
-	diag(Z, "bad in bnum");
-	return 0;
-}
-
-Bits
-blsh(unsigned n)
-{
-	Bits c;
-
-	c = zbits;
-	c.b[n/32] = 1L << (n%32);
-	return c;
-}
-
-/*
-int
-bset(Bits a, unsigned n)
-{
-	int i;
-
-	if(a.b[n/32] & (1L << (n%32)))
-		return 1;
-	return 0;
-}
-*/
-
-int
-Bconv(va_list *arg, Fconv *fp)
-{
-	char str[STRINGSZ], ss[STRINGSZ], *s;
-	Bits bits;
-	int i;
-
-	str[0] = 0;
-	bits = va_arg(*arg, Bits);
-	while(bany(&bits)) {
-		i = bnum(bits);
-		if(str[0])
-			strcat(str, " ");
-		if(var[i].sym == S) {
-			sprint(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));
-	}
-	strconv(str, fp);
-	return 0;
-}

+ 0 - 1404
sys/src/cmd/2c/cgen.c

@@ -1,1404 +0,0 @@
-#include "gc.h"
-
-void
-cgen(Node *n, int result, Node *nn)
-{
-	Node *l, *r, nod;
-	int lg, rg, xg, yg, g, o;
-	long v;
-	Prog *p1;
-
-	if(n == Z || n->type == T)
-		return;
-	if(typesuv[n->type->etype]) {
-		sugen(n, result, nn, n->type->width);
-		return;
-	}
-	if(debug['g']) {
-		if(result == D_TREE)
-			prtree(nn, "result");
-		else
-			print("result = %R\n", result);
-		prtree(n, "cgen");
-	}
-	l = n->left;
-	r = n->right;
-	o = n->op;
-	if(n->addable >= INDEXED) {
-		if(result == D_NONE) {
-			if(nn == Z)
-				switch(o) {
-				default:
-					nullwarn(Z, Z);
-					break;
-				case OINDEX:
-					nullwarn(l, r);
-					break;
-				}
-			return;
-		}
-		gmove(n->type, nn->type, D_TREE, n, result, nn);
-		return;
-	}
-
-	v = 0; /* set */
-	switch(o) {
-	default:
-		diag(n, "unknown op in cgen: %O", o);
-		break;
-
-	case OAS:
-		if(l->op == OBIT)
-			goto bitas;
-		/*
-		 * recursive use of result
-		 */
-		if(result == D_NONE)
-		if(l->addable > INDEXED)
-		if(l->complex < FNX) {
-			cgen(r, D_TREE, l);
-			break;
-		}
-
-		/*
-		 * function calls on both sides
-		 */
-		if(l->complex >= FNX && r->complex >= FNX) {
-			cgen(r, D_TOS, r);
-			v = argoff;
-			lg = regaddr(result);
-			lcgen(l, lg, Z);
-			lg |= I_INDIR;
-			adjsp(v - argoff);
-			gmove(r->type, l->type, D_TOS, r, lg, l);
-			if(result != D_NONE)
-				gmove(l->type, nn->type, lg, l, result, nn);
-			regfree(lg);
-			break;
-		}
-
-		rg = D_TREE;
-		lg = D_TREE;
-		if(r->complex >= l->complex) {
-			/*
-			 * right side before left
-			 */
-			if(result != D_NONE) {
-				rg = regalloc(n->type, result);
-				cgen(r, rg, n);
-			} else
-			if(r->complex >= FNX || r->addable < INDEXED) {
-				rg = regalloc(r->type, result);
-				cgen(r, rg, r);
-			}
-			if(l->addable < INDEXED) {
-				lg = regaddr(lg);
-				lcgen(l, lg, Z);
-				lg |= I_INDIR;
-			}
-		} else {
-			/*
-			 * left before right
-			 */
-			if(l->complex >= FNX || l->addable < INDEXED) {
-				lg = regaddr(lg);
-				lcgen(l, lg, Z);
-				lg |= I_INDIR;
-			}
-			if(result != D_NONE) {
-				rg = regalloc(n->type, result);
-				cgen(r, rg, n);
-			} else
-			if(r->addable < INDEXED) {
-				rg = regalloc(r->type, result);
-				cgen(r, rg, r);
-			}
-		}
-		if(result != D_NONE) {
-			gmove(n->type, l->type, rg, r, lg, l);
-			gmove(n->type, nn->type, rg, r, result, nn);
-		} else
-			gmove(r->type, l->type, rg, r, lg, l);
-		regfree(lg);
-		regfree(rg);
-		break;
-
-	bitas:
-		n = l->left;
-		rg = regalloc(tfield, result);
-		if(l->complex >= r->complex) {
-			lg = regaddr(D_NONE);
-			lcgen(n, lg, Z);
-			lg |= I_INDIR;
-			cgen(r, rg, r);
-		} else {
-			cgen(r, rg, r);
-			lg = regaddr(D_NONE);
-			lcgen(n, lg, Z);
-			lg |= I_INDIR;
-		}
-		g = regalloc(n->type, D_NONE);
-		gmove(l->type, l->type, lg, l, g, l);
-		bitstore(l, rg, lg, g, result, nn);
-		break;
-
-	case OBIT:
-		if(result == D_NONE) {
-			nullwarn(l, Z);
-			break;
-		}
-		g = bitload(n, D_NONE, D_NONE, result, nn);
-		gopcode(OAS, nn->type, g, n, result, nn);
-		regfree(g);
-		break;
-
-	case ODOT:
-		sugen(l, D_TREE, nodrat, l->type->width);
-		if(result != D_NONE) {
-			warn(n, "non-interruptable temporary");
-			nod = *nodrat;
-			if(!r || r->op != OCONST) {
-				diag(n, "DOT and no offset");
-				break;
-			}
-			nod.xoffset += r->vconst;
-			nod.type = n->type;
-			cgen(&nod, result, nn);
-		}
-		break;
-
-	case OASLDIV:
-	case OASLMOD:
-	case OASDIV:
-	case OASMOD:
-		if(l->op == OBIT)
-			goto asbitop;
-		if(typefd[n->type->etype])
-			goto asbinop;
-		rg = D_TREE;
-		if(l->complex >= FNX || r->complex >= FNX) {
-			rg = D_TOS;
-			cgen(r, rg, r);
-			v = argoff;
-		} else
-		if(r->addable < INDEXED) {
-			rg = regalloc(n->type, D_NONE);
-			cgen(r, rg, r);
-		}
-		lg = D_TREE;
-		if(!simplv(l)) {
-			lg = regaddr(D_NONE);
-			lcgen(l, lg, Z);	/* destroys register optimization */
-			lg |= I_INDIR;
-		}
-		g = regpair(result);
-		gmove(l->type, n->type, lg, l, g, n);
-		if(rg == D_TOS)
-			adjsp(v - argoff);
-		gopcode(o, n->type, rg, r, g, n);
-		if(o == OASLMOD || o == OASMOD)
-			gmove(n->type, l->type, g+1, n, lg, l);
-		else
-			gmove(n->type, l->type, g, n, lg, l);
-		if(result != D_NONE)
-		if(o == OASLMOD || o == OASMOD)
-			gmove(n->type, nn->type, g+1, n, result, nn);
-		else
-			gmove(n->type, nn->type, g, n, result, nn);
-		regfree(g);
-		regfree(g+1);
-		regfree(lg);
-		regfree(rg);
-		break;
-
-	case OASXOR:
-	case OASAND:
-	case OASOR:
-		if(l->op == OBIT)
-			goto asbitop;
-		if(l->complex >= FNX ||
-		   l->addable < INDEXED ||
-		   result != D_NONE ||
-		   typefd[n->type->etype])
-			goto asbinop;
-		rg = D_TREE;
-		if(r->op != OCONST) {
-			rg = regalloc(n->type, D_NONE);
-			cgen(r, rg, r);
-		}
-		gopcode(o, l->type, rg, r, D_TREE, l);
-		regfree(rg);
-		break;
-
-	case OASADD:
-	case OASSUB:
-		if(l->op == OBIT ||
-		   l->complex >= FNX ||
-		   l->addable < INDEXED ||
-		   result != D_NONE ||
-		   typefd[n->type->etype])
-			goto asbinop;
-		v = vconst(r);
-		if(v > 0 && v <= 8) {
-			gopcode(o, n->type, D_TREE, r, D_TREE, l);
-			break;
-		}
-		rg = regalloc(n->type, D_NONE);
-		cgen(r, rg, r);
-		gopcode(o, n->type, rg, r, D_TREE, l);
-		regfree(rg);
-		break;
-
-	case OASLSHR:
-	case OASASHR:
-	case OASASHL:
-		if(l->op == OBIT ||
-		   l->complex >= FNX ||
-		   l->addable < INDEXED ||
-		   result != D_NONE ||
-		   typefd[n->type->etype])
-			goto asbinop;
-		rg = D_TREE;
-		v = vconst(r);
-		if(v <= 0 || v > 8) {
-			rg = regalloc(n->type, D_NONE);
-			cgen(r, rg, r);
-		}
-		lg = regalloc(n->type, D_NONE);
-		cgen(l, lg, l);
-		gopcode(o, n->type, rg, r, lg, l);
-		gmove(n->type, n->type, lg, l, D_TREE, l);
-		regfree(lg);
-		regfree(rg);
-		break;
-
-	case OASLMUL:
-	case OASMUL:
-	asbinop:
-		if(l->op == OBIT)
-			goto asbitop;
-		rg = D_TREE;
-		if(l->complex >= FNX || r->complex >= FNX) {
-			rg = D_TOS;
-			cgen(r, rg, r);
-			v = argoff;
-		} else
-		if(r->addable < INDEXED) {
-			rg = regalloc(n->type, D_NONE);
-			cgen(r, rg, r);
-		} else {
-			if(o == OASLSHR || o == OASASHR || o == OASASHL) {
-				v = vconst(r);
-				if(v <= 0 || v > 8) {
-					rg = regalloc(n->type, D_NONE);
-					cgen(r, rg, r);
-				}
-			}
-		}
-		lg = D_TREE;
-		if(!simplv(l)) {
-			lg = regaddr(D_NONE);
-			lcgen(l, lg, Z);	/* destroys register optimization */
-			lg |= I_INDIR;
-		}
-		g = regalloc(n->type, result);
-		gmove(l->type, n->type, lg, l, g, n);
-		if(rg == D_TOS)
-			adjsp(v - argoff);
-		if(o == OASXOR)
-			if(rg == D_TREE) {
-				rg = regalloc(n->type, D_NONE);
-				cgen(r, rg, r);
-			}
-		if(o == OASXOR || o == OASLSHR || o == OASASHR || o == OASASHL)
-			if(rg == D_TOS) {
-				rg = regalloc(n->type, D_NONE);
-				gmove(n->type, n->type, D_TOS, n, rg, n);
-			}
-		gopcode(o, n->type, rg, r, g, n);
-		gmove(n->type, l->type, g, n, lg, l);
-		if(result != D_NONE)
-			gmove(n->type, nn->type, g, n, result, nn);
-		regfree(g);
-		regfree(lg);
-		regfree(rg);
-		break;
-
-	asbitop:
-		rg = regaddr(D_NONE);
-		lg = regalloc(tfield, D_NONE);
-		if(l->complex >= r->complex) {
-			g = bitload(l, lg, rg, result, nn);
-			xg = regalloc(r->type, D_NONE);
-			cgen(r, xg, nn);
-		} else {
-			xg = regalloc(r->type, D_NONE);
-			cgen(r, xg, nn);
-			g = bitload(l, lg, rg, result, nn);
-		}
-
-		if(!typefd[n->type->etype]) {
-			if(o == OASLDIV || o == OASDIV) {
-				yg = regpair(result);
-				gmove(tfield, n->type, g, l, yg, n);
-				gopcode(o, n->type, xg, r, yg, n);
-				gmove(n->type, tfield, yg, n, g, l);
-				regfree(yg);
-				regfree(yg+1);
-
-				regfree(xg);
-				bitstore(l, g, rg, lg, D_NONE, nn);
-				break;
-			}
-			if(o == OASLMOD || o == OASMOD) {
-				yg = regpair(result);
-				gmove(tfield, n->type, g, l, yg, n);
-				gopcode(o, n->type, xg, r, yg, n);
-				gmove(n->type, tfield, yg+1, n, g, l);
-				regfree(yg);
-				regfree(yg+1);
-
-				regfree(xg);
-				bitstore(l, g, rg, lg, D_NONE, nn);
-				break;
-			}
-		}
-
-		yg = regalloc(n->type, result);
-		gmove(tfield, n->type, g, l, yg, n);
-		gopcode(o, n->type, xg, r, yg, n);
-		gmove(n->type, tfield, yg, n, g, l);
-		regfree(yg);
-
-		regfree(xg);
-		bitstore(l, g, rg, lg, D_NONE, nn);
-		break;
-
-	case OCAST:
-		if(result == D_NONE) {
-			nullwarn(l, Z);
-			break;
-		}
-		lg = result;
-		if(l->complex >= FNX)
-			lg = regret(l->type);
-		lg = eval(l, lg);
-		if(nocast(l->type, n->type)) {
-			gmove(n->type, nn->type, lg, l, result, nn);
-			regfree(lg);
-			break;
-		}
-		if(nocast(n->type, nn->type)) {
-			gmove(l->type, n->type, lg, l, result, nn);
-			regfree(lg);
-			break;
-		}
-		rg = regalloc(n->type, result);
-		gmove(l->type, n->type, lg, l, rg, n);
-		gmove(n->type, nn->type, rg, n, result, nn);
-		regfree(rg);
-		regfree(lg);
-		break;
-
-	case OCOND:
-		doinc(l, PRE);
-		boolgen(l, 1, D_NONE, Z, l);
-		p1 = p;
-
-		inargs++;
-		doinc(r->left, PRE);
-		cgen(r->left, result, nn);
-		doinc(r->left, POST);
-		gbranch(OGOTO);
-		patch(p1, pc);
-		p1 = p;
-
-		doinc(r->right, PRE);
-		cgen(r->right, result, nn);
-		doinc(r->right, POST);
-		patch(p1, pc);
-		inargs--;
-		break;
-
-	case OIND:
-		if(result == D_NONE) {
-			nullwarn(l, Z);
-			break;
-		}
-		lg = nodalloc(types[TIND], result, &nod);
-		nod.lineno = n->lineno;
-		if(l->op == OADD) {
-			if(l->left->op == OCONST) {
-				nod.xoffset += l->left->vconst;
-				l = l->right;
-			} else
-			if(l->right->op == OCONST) {
-				nod.xoffset += l->right->vconst;
-				l = l->left;
-			}
-		}
-		cgen(l, lg, l);
-		gmove(n->type, nn->type, D_TREE, &nod, result, nn);
-		regfree(lg);
-		break;
-
-	case OFUNC:
-		v = argoff;
-		inargs++;
-		gargs(r);
-		lg = D_TREE;
-		if(l->addable < INDEXED) {
-			lg = regaddr(result);
-			lcgen(l, lg, Z);
-			lg |= I_INDIR;
-		}
-		inargs--;
-		doinc(r, POST);
-		doinc(l, POST);
-		gopcode(OFUNC, types[TCHAR], D_NONE, Z, lg, l);
-		regfree(lg);
-		if(inargs)
-			adjsp(v - argoff);
-		if(result != D_NONE) {
-			lg = regret(n->type);
-			gmove(n->type, nn->type, lg, n, result, nn);
-		}
-		break;
-
-	case OLDIV:
-	case OLMOD:
-	case ODIV:
-	case OMOD:
-		if(result == D_NONE) {
-			nullwarn(l, r);
-			break;
-		}
-		if(typefd[n->type->etype])
-			goto binop;
-		if(r->addable >= INDEXED && r->complex < FNX) {
-			lg = regpair(result);
-			cgen(l, lg, l);
-			rg = D_TREE;
-		} else {
-			cgen(r, D_TOS, r);
-			v = argoff;
-			lg = regpair(result);
-			cgen(l, lg, l);
-			adjsp(v - argoff);
-			rg = D_TOS;
-		}
-		gopcode(o, n->type, rg, r, lg, l);
-		if(o == OMOD || o == OLMOD)
-			gmove(l->type, nn->type, lg+1, l, result, nn);
-		else
-			gmove(l->type, nn->type, lg, l, result, nn);
-		regfree(lg);
-		regfree(lg+1);
-		break;
-
-	case OMUL:
-	case OLMUL:
-		if(l->op == OCONST)
-			if(mulcon(r, l, result, nn))
-				break;
-		if(r->op == OCONST)
-			if(mulcon(l, r, result, nn))
-				break;
-		if(debug['M'])
-			print("%L multiply\n", n->lineno);
-		goto binop;
-
-	case OAND:
-		if(r->op == OCONST)
-		if(typeil[n->type->etype])
-		if(l->op == OCAST) {
-			if(typec[l->left->type->etype])
-			if(!(r->vconst & ~0xff)) {
-				l = l->left;
-				goto binop;
-			}
-			if(typeh[l->left->type->etype])
-			if(!(r->vconst & ~0xffff)) {
-				l = l->left;
-				goto binop;
-			}
-		}
-		goto binop;
-
-	case OADD:
-		if(result == D_TOS)
-		if(r->addable >= INDEXED)
-		if(l->op == OCONST)
-		if(typeil[l->type->etype]) {
-			v = l->vconst;
-			if(v > -32768 && v < 32768) {
-				rg = regaddr(D_NONE);
-				gmove(r->type, r->type, D_TREE, r, rg, r);
-				gopcode(OADDR, types[TSHORT], D_NONE, Z, rg, r);
-				p->to.offset = v;
-				p->to.type |= I_INDIR;
-				regfree(rg);
-				break;
-			}
-		}
-
-	case OSUB:
-		if(result == D_TOS)
-		if(l->addable >= INDEXED)
-		if(r->op == OCONST)
-		if(typeil[r->type->etype]) {
-			v = r->vconst;
-			if(v > -32768 && v < 32768) {
-				if(n->op == OSUB)
-					v = -v;
-				lg = regaddr(D_NONE);
-				gmove(l->type, l->type, D_TREE, l, lg, l);
-				gopcode(OADDR, types[TSHORT], D_NONE, Z, lg, l);
-				p->to.offset = v;
-				p->to.type |= I_INDIR;
-				regfree(lg);
-				break;
-			}
-		}
-		goto binop;
-
-	case OOR:
-	case OXOR:
-	binop:
-		if(result == D_NONE) {
-			nullwarn(l, r);
-			break;
-		}
-		if(l->complex >= FNX && r->complex >= FNX) {
-			cgen(r, D_TOS, r);
-			v = argoff;
-			lg = regalloc(l->type, result);
-			cgen(l, lg, l);
-			adjsp(v - argoff);
-			if(o == OXOR) {
-				rg = regalloc(r->type, D_NONE);
-				gmove(r->type, r->type, D_TOS, r, rg, r);
-				gopcode(o, n->type, rg, r, lg, l);
-				regfree(rg);
-			} else
-				gopcode(o, n->type, D_TOS, r, lg, l);
-			gmove(n->type, nn->type, lg, l, result, nn);
-			regfree(lg);
-			break;
-		}
-		if(l->complex >= r->complex) {
-			if(l->op == OADDR && (o == OADD || o == OSUB))
-				lg = regaddr(result);
-			else
-				lg = regalloc(l->type, result);
-			cgen(l, lg, l);
-			rg = eval(r, D_NONE);
-		} else {
-			rg = regalloc(r->type, D_NONE);
-			cgen(r, rg, r);
-			lg = regalloc(l->type, result);
-			cgen(l, lg, l);
-		}
-		if(o == OXOR) {
-			if(rg == D_TREE) {
-				rg = regalloc(r->type, D_NONE);
-				cgen(r, rg, r);
-			}
-			if(rg == D_TOS) {
-				rg = regalloc(r->type, D_NONE);
-				gmove(r->type, r->type, D_TOS, r, rg, r);
-			}
-		}
-		gopcode(o, n->type, rg, r, lg, l);
-		gmove(n->type, nn->type, lg, l, result, nn);
-		regfree(lg);
-		regfree(rg);
-		break;
-
-	case OASHL:
-		if(r->op == OCONST)
-			if(shlcon(l, r, result, nn))
-				break;
-	case OLSHR:
-	case OASHR:
-		if(result == D_NONE) {
-			nullwarn(l, r);
-			break;
-		}
-
-		if(l->complex >= FNX && r->complex >= FNX) {
-			cgen(r, D_TOS, r);
-			v = argoff;
-			lg = regalloc(l->type, result);
-			cgen(l, lg, l);
-			adjsp(v - argoff);
-			rg = regalloc(r->type, D_NONE);
-			gopcode(OAS, r->type, D_TOS, r, rg, r);
-			gopcode(n->op, n->type, rg, r, lg, l);
-			gmove(n->type, nn->type, lg, l, result, nn);
-			regfree(lg);
-			regfree(rg);
-			break;
-		}
-		if(l->complex >= r->complex) {
-			lg = regalloc(l->type, result);
-			cgen(l, lg, l);
-			v = vconst(r);
-			if(v <= 0 || v > 8) {
-				rg = regalloc(r->type, D_NONE);
-				cgen(r, rg, r);
-			} else
-				rg = eval(r, D_NONE);
-		} else {
-			rg = regalloc(r->type, D_NONE);
-			cgen(r, rg, r);
-			lg = regalloc(l->type, result);
-			cgen(l, lg, l);
-		}
-		gopcode(o, n->type, rg, r, lg, l);
-		gmove(n->type, nn->type, lg, l, result, nn);
-		regfree(lg);
-		regfree(rg);
-		break;
-
-	case ONEG:
-	case OCOM:
-		if(result == D_NONE) {
-			nullwarn(l, Z);
-			break;
-		}
-		lg = regalloc(l->type, result);
-		cgen(l, lg, l);
-		gopcode(o, l->type, D_NONE, Z, lg, l);
-		gmove(n->type, nn->type, lg, l, result, nn);
-		regfree(lg);
-		break;
-
-	case OADDR:
-		if(result == D_NONE) {
-			nullwarn(l, Z);
-			break;
-		}
-		if(l->op == OINDEX && l->scale == 4 && result != D_TOS) {
-			/* index scaled by 1, add is better */
-			nod = *l;
-			nod.op = OADD;
-			nod.addable = 0;
-			cgen(&nod, result, nn);
-			break;
-		}
-		lcgen(l, result, nn);
-		break;
-
-	case OEQ:
-	case ONE:
-	case OLE:
-	case OLT:
-	case OGE:
-	case OGT:
-	case OLO:
-	case OLS:
-	case OHI:
-	case OHS:
-		if(result == D_NONE) {
-			nullwarn(l, r);
-			break;
-		}
-		boolgen(n, 1, result, nn, Z);
-		break;
-
-	case OANDAND:
-	case OOROR:
-		boolgen(n, 1, result, nn, Z);
-		if(result == D_NONE)
-			patch(p, pc);
-		break;
-
-	case OCOMMA:
-		cgen(l, D_NONE, l);
-		doinc(l, POST);
-		doinc(r, PRE);
-		cgen(r, result, nn);
-		break;
-
-	case ONOT:
-		if(result == D_NONE) {
-			nullwarn(l, Z);
-			break;
-		}
-		boolgen(n, 1, result, nn, Z);
-		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;
-
-		lg = D_TREE;
-		if(l->addable < INDEXED) {
-			lg = regaddr(D_NONE);
-			lcgen(l, lg, Z);
-			lg |= I_INDIR;
-		}
-		if(result != D_NONE)
-			gmove(l->type, nn->type, lg, l, result, nn);
-		if(typefd[n->type->etype]) {
-			rg = regalloc(n->type, D_NONE);
-			gmove(l->type, l->type, lg, l, rg, l);
-			gopcode(o, n->type, D_CONST, nodconst(1), rg, l);
-			gmove(l->type, l->type, rg, l, lg, l);
-			regfree(rg);
-		} else {
-			if(v < 0)
-				gopcode(o, n->type, D_CONST, nodconst(-v), lg, l);
-			else
-				gopcode(o, n->type, D_CONST, nodconst(v), lg, l);
-		}
-		regfree(lg);
-		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:
-		lg = D_TREE;
-		if(l->addable < INDEXED) {
-			lg = regaddr(D_NONE);
-			lcgen(l, lg, Z);
-			lg |= I_INDIR;
-		}
-		if(typefd[n->type->etype]) {
-			rg = regalloc(n->type, D_NONE);
-			gmove(l->type, l->type, lg, l, rg, l);
-			gopcode(o, n->type, D_CONST, nodconst(1), rg, l);
-			gmove(l->type, l->type, rg, l, lg, l);
-			regfree(rg);
-		} else {
-			if(v < 0)
-				gopcode(o, n->type, D_CONST, nodconst(-v), lg, l);
-			else
-				gopcode(o, n->type, D_CONST, nodconst(v), lg, l);
-		}
-		if(result != D_NONE)
-			gmove(l->type, nn->type, lg, l, result, nn);
-		regfree(lg);
-		break;
-
-	bitinc:
-		rg = regaddr(D_NONE);
-		lg = regalloc(tfield, D_NONE);
-		if(result != D_NONE && (o == OPOSTINC || o == OPOSTDEC)) {
-			g = bitload(l, lg, rg, D_NONE, nn);
-			if(nn != Z)
-				gmove(l->type, nn->type, g, l, result, nn);
-			if(v < 0)
-				gopcode(o, n->type, D_CONST, nodconst(-v), g, n);
-			else
-				gopcode(o, n->type, D_CONST, nodconst(v), g, n);
-			bitstore(l, g, rg, lg, D_NONE, nn);
-			break;
-		}
-		g = bitload(l, lg, rg, result, nn);
-		if(v < 0)
-			gopcode(o, n->type, D_CONST, nodconst(-v), g, n);
-		else
-			gopcode(o, n->type, D_CONST, nodconst(v), g, n);
-		if(result != D_NONE)
-			gmove(l->type, nn->type, g, l, result, nn);
-		bitstore(l, g, rg, lg, D_NONE, nn);
-		break;
-	}
-}
-
-void
-lcgen(Node *n, int result, Node *nn)
-{
-	Node rn;
-	Prog *p1;
-	int lg;
-
-	if(n == Z || n->type == T)
-		return;
-	if(debug['g']) {
-		if(result == D_TREE)
-			prtree(nn, "result");
-		else
-			print("result = %R\n", result);
-		prtree(n, "lcgen");
-	}
-	if(nn == Z) {
-		nn = &rn;
-		nn->type = types[TIND];
-	}
-	switch(n->op) {
-	case OCOMMA:
-		cgen(n->left, D_NONE, n->left);
-		doinc(n->left, POST);
-		doinc(n->right, PRE);
-		lcgen(n->right, result, nn);
-		break;
-
-	case OCOND:
-		doinc(n->left, PRE);
-		boolgen(n->left, 1, D_NONE, Z, n->left);
-		p1 = p;
-
-		inargs++;
-		doinc(n->right->left, PRE);
-		lcgen(n->right->left, result, nn);
-		doinc(n->right->left, POST);
-		gbranch(OGOTO);
-		patch(p1, pc);
-		p1 = p;
-
-		doinc(n->right->right, PRE);
-		lcgen(n->right->right, result, nn);
-		doinc(n->right->right, POST);
-		patch(p1, pc);
-		inargs--;
-		break;
-
-	case OIND:
-		if(n->addable >= INDEXED) {
-			if(result >= D_A0 && result < D_A0+NREG) {
-				gopcode(OADDR, types[TLONG], D_TREE, n, result, nn);
-				break;
-			}
-			if(result == D_TOS) {
-				gopcode(OADDR, types[TSHORT], D_NONE, nn, D_TREE, n);
-				break;
-			}
-		}
-		cgen(n->left, result, nn);
-		break;
-
-	default:
-		if(n->addable < INDEXED) {
-			diag(n, "unknown op in lcgen: %O", n->op);
-			break;
-		}
-		if(result >= D_A0 && result < D_A0+NREG) {
-			gopcode(OADDR, types[TLONG], D_TREE, n, result, nn);
-			break;
-		}
-		if(result == D_TOS) {
-			gopcode(OADDR, types[TSHORT], D_NONE, nn, D_TREE, n);
-			break;
-		}
-		lg = regaddr(result);
-		gopcode(OADDR, types[TLONG], D_TREE, n, lg, nn);
-		gopcode(OAS, nn->type, lg, nn, result, nn);
-		regfree(lg);
-		break;
-	}
-}
-
-void
-bcgen(Node *n, int true)
-{
-
-	boolgen(n, true, D_NONE, Z, Z);
-}
-
-void
-boolgen(Node *n, int true, int result, Node *nn, Node *post)
-{
-	Prog *p1, *p2;
-	Node *l, *r;
-	int lg, rg, fp, o;
-	long v;
-
-	if(debug['g']) {
-		if(result == D_TREE)
-			prtree(nn, "result");
-		else
-			print("result = %R\n", result);
-		prtree(n, "boolgen");
-	}
-	l = n->left;
-	r = n->right;
-	switch(n->op) {
-
-	default:
-		lg = eval(n, result);
-		if(lg >= D_A0 && lg < D_A0+NREG) {
-			rg = regalloc(types[TLONG], D_NONE);
-			gopcode(OAS, types[TLONG], lg, n, rg, Z);
-			regfree(rg);
-		} else
-			gopcode(OTST, n->type, D_NONE, Z, lg, n);
-		regfree(lg);
-		o = ONE;
-		fp = typefd[n->type->etype];
-		goto genbool;
-
-	case OCONST:
-		fp = vconst(n);
-		if(!true)
-			fp = !fp;
-		gbranch(OGOTO);
-		if(fp) {
-			p1 = p;
-			gbranch(OGOTO);
-			patch(p1, pc);
-		}
-		goto com;
-
-	case ONOT:
-		boolgen(l, !true, result, nn, post);
-		break;
-
-	case OCOND:
-		doinc(l, PRE);
-		boolgen(l, 1, D_NONE, Z, l);
-		p1 = p;
-
-		inargs++;
-		doinc(r->left, PRE);
-		boolgen(r->left, true, result, nn, r->left);
-		if(result != D_NONE) {
-			doinc(r->left, POST);
-			gbranch(OGOTO);
-			patch(p1, pc);
-			p1 = p;
-
-			doinc(r->right, PRE);
-			boolgen(r->right, !true, result, nn, r->right);
-			doinc(r->right, POST);
-			patch(p1, pc);
-			inargs--;
-			break;
-		}
-		p2 = p;
-		gbranch(OGOTO);
-		patch(p1, pc);
-		p1 = p;
-
-		doinc(r->right, PRE);
-		boolgen(r->right, !true, result, nn, r->right);
-		patch(p2, pc);
-		p2 = p;
-		if(doinc(post, POST|TEST)) {
-			lg = regalloc(types[TSHORT], D_NONE);
-			gopcode(OAS, types[TSHORT], D_CCR, Z, lg, Z);
-			doinc(post, POST);
-			gopcode(OAS, types[TSHORT], lg, Z, D_CCR, Z);
-			regfree(lg);
-		}
-		gbranch(OGOTO);
-		patch(p1, pc);
-		patch(p2, pc);
-		inargs--;
-		goto com;
-
-	case OANDAND:
-		if(!true)
-			goto caseor;
-
-	caseand:
-		doinc(l, PRE);
-		boolgen(l, true, D_NONE, Z, l);
-		p1 = p;
-		inargs++;
-		doinc(r, PRE);
-		boolgen(r, !true, D_NONE, Z, r);
-		p2 = p;
-		patch(p1, pc);
-		gbranch(OGOTO);
-		patch(p2, pc);
-		inargs--;
-		goto com;
-
-	case OOROR:
-		if(!true)
-			goto caseand;
-
-	caseor:
-		doinc(l, PRE);
-		boolgen(l, !true, D_NONE, Z, l);
-		p1 = p;
-		inargs++;
-		doinc(r, PRE);
-		boolgen(r, !true, D_NONE, Z, r);
-		p2 = p;
-		gbranch(OGOTO);
-		patch(p1, pc);
-		patch(p2, pc);
-		inargs--;
-		goto com;
-
-	case OEQ:
-	case ONE:
-		if(vconst(l) == 0) {
-			if(n->op == ONE) {
-				boolgen(r, true, result, nn, post);
-				break;
-			}
-			boolgen(r, !true, result, nn, post);
-			break;
-		}
-
-	case OLE:
-	case OLT:
-	case OGE:
-	case OGT:
-	case OHI:
-	case OHS:
-	case OLO:
-	case OLS:
-		fp = typefd[r->type->etype];
-		if(l->op == OCONST) {
-			v = vconst(l);
-			if(v == 0) {	/* tst instruction */
-				o = invrel[relindex(n->op)];
-				rg = eval(r, result);
-				gopcode(OTST, r->type, D_NONE, Z, rg, r);
-				regfree(rg);
-				goto genbool;
-			}
-			if(!fp) {	/* cmpi and movq, saves about .5% both time and space */
-				if(v < 128 && v >= -128 &&
-				   ewidth[r->type->etype] == SZ_LONG) {
-					rg = eval(r, result);
-					lg = regalloc(l->type, D_NONE);
-					cgen(l, lg, l);
-					o = n->op;
-					gopcode(o, l->type, lg, l, rg, r);
-					regfree(lg);
-					regfree(rg);
-					goto genbool;
-				}
-				o = invrel[relindex(n->op)];
-				rg = eval(r, result);
-				gopcode(o, r->type, rg, r, D_TREE, l);
-				regfree(rg);
-				goto genbool;
-			}
-		}
-		lg = D_TOS;
-		if(r->complex < FNX)
-			lg = regalloc(l->type, lg);
-		cgen(l, lg, l);
-		v = argoff;
-		rg = eval(r, result);
-		if(lg == D_TOS) {
-			adjsp(v - argoff);
-			lg = regalloc(l->type, lg);
-			gopcode(OAS, l->type, D_TOS, l, lg, l);
-		}
-		o = n->op;
-		gopcode(o, l->type, lg, l, rg, r);
-		regfree(lg);
-		regfree(rg);
-
-	genbool:
-		if(true)
-			o = comrel[relindex(o)];
-		if(doinc(post, POST|TEST)) {
-			lg = regalloc(types[TSHORT], D_NONE);
-			gopcode(OAS, types[TSHORT], D_CCR, Z, lg, Z);
-			doinc(post, POST);
-			gopcode(OAS, types[TSHORT], lg, Z, D_CCR, Z);
-			regfree(lg);
-		}
-		gbranch(o);
-		if(fp)
-			fpbranch();
-
-	com:
-		if(result == D_NONE)
-			break;
-		p1 = p;
-		gopcode(OAS, nn->type, D_CONST, nodconst(1), result, nn);
-		gbranch(OGOTO);
-		p2 = p;
-		patch(p1, pc);
-		gopcode(OAS, nn->type, D_CONST, nodconst(0), result, nn);
-		patch(p2, pc);
-		break;
-	}
-}
-
-void
-sugen(Node *n, int result, Node *nn, long w)
-{
-	long s, v, o;
-	int lg, rg, ng;
-	Prog *p1;
-	Node *l, *r, nod;
-	Type *t;
-
-	if(n == Z || n->type == T)
-		return;
-	if(debug['g']) {
-		if(result == D_TREE)
-			prtree(nn, "result");
-		else
-			print("result = %R width = %ld\n", result, w);
-		prtree(n, "sugen");
-	}
-	s = argoff;
-	if(result == D_TREE) {
-		if(nn == nodrat)
-			if(w > nrathole)
-				nrathole = w;
-	}
-
-	if(n->addable >= INDEXED && n->op != OCONST)
-		goto copy;
-	switch(n->op) {
-	default:
-		diag(n, "unknown op in sugen: %O", n->op);
-		break;
-
-	case OCONST:
-		if(n->type && typev[n->type->etype]) {
-			if(result == D_NONE) {
-				nullwarn(n->left, Z);
-				break;
-			}
-
-			lg = regaddr(D_NONE);
-			if(result == D_TOS) {
-				adjsp(s - argoff + w);
-				gopcode(OADDR, types[TIND], result, nn, lg, n);
-			} else
-			if(result == D_TREE) {
-				lcgen(nn, lg, Z);
-			} else
-				diag(n, "unknown su result: %R", result);
-
-			gopcode(OAS, types[TLONG], D_CONST, nodconst((long)(n->vconst>>32)),
-				lg|I_INDINC, n);
-			gopcode(OAS, types[TLONG], D_CONST, nodconst((long)(n->vconst)),
-				lg|I_INDINC, n);
-			regfree(lg);
-			break;
-		}
-		goto copy;
-
-	case ODOT:
-		l = n->left;
-		sugen(l, D_TREE, nodrat, l->type->width);
-		if(result != D_NONE) {
-			warn(n, "non-interruptable temporary");
-			nod = *nodrat;
-			r = n->right;
-			if(!r || r->op != OCONST) {
-				diag(n, "DOT and no offset");
-				break;
-			}
-			nod.xoffset += r->vconst;
-			nod.type = n->type;
-			sugen(&nod, result, nn, w);
-		}
-		break;
-
-	case OIND:
-		if(result == D_NONE) {
-			nullwarn(n->left, Z);
-			break;
-		}
-		goto copy;
-
-	case OSTRUCT:
-		lg = nodalloc(types[TIND], result, &nod);
-		nod.lineno = n->lineno;
-		if(result == D_TREE)
-			lcgen(nn, lg, Z);
-		else
-		if(result == D_TOS) {
-			adjsp(s - argoff + w);
-			gopcode(OADDR, types[TIND], result, nn, lg, n);
-		} else
-			diag(n, "unknown su result: %R", result);
-		o = 0;
-		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;
-			}
-			nod.type = t;
-			if(l->complex < FNX) {
-				nod.xoffset = 0;
-				if(o != t->offset) {
-					gopcode(OADD, types[TIND], D_CONST,
-						nodconst(t->offset-o), lg, Z);
-					o = t->offset;
-				}
-				cgen(l, D_TREE, &nod);
-				continue;
-			}
-			nod.xoffset = t->offset - o;
-			gopcode(OAS, types[TIND], lg, Z, D_TOS, Z);
-			s = argoff;
-			if(typesuv[t->etype]) {
-				sugen(l, D_TREE, nodrat, t->width);
-				adjsp(s - argoff);
-				gopcode(OAS, types[TIND], D_TOS, Z, lg, Z);
-				warn(n, "non-interruptable temporary");
-				sugen(nodrat, D_TREE, &nod, t->width);
-				continue;
-			}
-			rg = regalloc(t, D_NONE);
-			cgen(l, rg, l);
-			adjsp(s - argoff);
-			gopcode(OAS, types[TIND], D_TOS, Z, lg, Z);
-			gopcode(OAS, t, rg, Z, D_TREE, &nod);
-			regfree(rg);
-		}
-		regfree(lg);
-		break;
-
-	case OAS:
-		if(result == D_NONE) {
-			sugen(n->right, D_TREE, n->left, w);
-			break;
-		}
-		sugen(n->right, D_TREE, nodrat, w);	/* could do better */
-		warn(n, "non-interruptable temporary");
-		sugen(nodrat, D_TREE, n->left, w);
-		sugen(nodrat, result, nn, w);
-		break;
-
-	case OFUNC:
-		if(result == D_NONE) {
-			sugen(n, D_TREE, nodrat, w);
-			break;
-		}
-		inargs++;
-		/* prepare zero-th arg: address of result */
-		if(result == D_TOS) {
-			adjsp(s - argoff + w);
-			v = argoff;
-			gargs(n->right);
-			gopcode(OADDR, types[TSHORT], D_NONE, nn, result, nn);
-			p->to.type = D_STACK;
-			p->to.offset = argoff - v;
-		} else
-		if(result == D_TREE) {
-			v = argoff;
-			gargs(n->right);
-			if(nn->complex >= FNX) {
-				rg = regalloc(types[TIND], regret(types[TIND]));
-				lcgen(nn, rg, Z);
-				gopcode(OAS, types[TIND], rg, Z, D_TOS, Z);
-				regfree(rg);
-			} else
-				lcgen(nn, D_TOS, Z);
-		} else {
-			diag(n, "unknown result in FUNC sugen");
-			break;
-		}
-		argoff += types[TIND]->width;
-		l = n->left;
-		lg = D_TREE;
-		if(l->addable < INDEXED) {
-			lg = regaddr(result);
-			lcgen(l, lg, Z);
-			lg |= I_INDIR;
-		}
-		inargs--;
-		doinc(n->right, POST);
-		doinc(n->left, POST);
-		gopcode(OFUNC, types[TCHAR], D_NONE, Z, lg, l);
-		regfree(lg);
-		if(inargs)
-			adjsp(v - argoff);
-		break;
-
-	case OCOND:
-		doinc(n->left, PRE);
-		boolgen(n->left, 1, D_NONE, Z, n->left);
-		p1 = p;
-
-		inargs++;
-		doinc(n->right->left, PRE);
-		sugen(n->right->left, result, nn, w);
-		doinc(n->right->left, POST);
-		gbranch(OGOTO);
-		patch(p1, pc);
-		p1 = p;
-
-		doinc(n->right->right, PRE);
-		sugen(n->right->right, result, nn, w);
-		doinc(n->right->right, POST);
-		patch(p1, pc);
-		inargs--;
-		break;
-
-	case OCOMMA:
-		cgen(n->left, D_NONE, n->left);
-		doinc(n->left, POST);
-		doinc(n->right, PRE);
-		sugen(n->right, result, nn, w);
-		break;
-	}
-	return;
-
-copy:
-	if(result == D_NONE)
-		return;
-	rg = regaddr(D_NONE);
-	lcgen(n, rg, Z);
-
-	lg = regaddr(D_NONE);
-	if(result == D_TOS) {
-		adjsp(s - argoff + w);
-		gopcode(OADDR, types[TIND], result, nn, lg, n);
-	} else
-	if(result == D_TREE) {
-		if(nn->complex >= FNX) {
-			gopcode(OAS, types[TIND], rg, n, D_TOS, n);
-			s = argoff;
-			lcgen(nn, lg, Z);
-			adjsp(s - argoff);
-			gopcode(OAS, types[TIND], D_TOS, n, rg, n);
-		} else
-			lcgen(nn, lg, Z);
-	} else
-		diag(n, "unknown su result: %R", result);
-
-	if(w % SZ_LONG)
-		diag(Z, "sucopy width not 0%%%d", SZ_LONG);
-	v = w / SZ_LONG;
-	if(v & 1) {
-		gopcode(OAS, types[TLONG], rg|I_INDINC, n, lg|I_INDINC, n);
-		v--;
-	}
-	if(v > 6) {
-		ng = regalloc(types[TLONG], D_NONE);
-		gopcode(OAS, types[TLONG], D_CONST, nodconst(v/2-1), ng, n);
-		v = pc;
-		gopcode(OAS, types[TLONG], rg|I_INDINC, n, lg|I_INDINC, n);
-		gopcode(OAS, types[TLONG], rg|I_INDINC, n, lg|I_INDINC, n);
-		gbranch(OGT);
-		patch(p, v);
-		p->from.type = ng;
-		p->as = ADBF;
-		regfree(ng);
-	} else
-		while(v > 0) {
-			gopcode(OAS, types[TLONG], rg|I_INDINC, n, lg|I_INDINC, n);
-			v--;
-		}
-
-	regfree(lg);
-	regfree(rg);
-}

+ 0 - 425
sys/src/cmd/2c/enam.c

@@ -1,425 +0,0 @@
-char	*anames[] =
-{
-	"XXX",
-	"ABCD",
-	"ADDB",
-	"ADDL",
-	"ADDW",
-	"ADDXB",
-	"ADDXL",
-	"ADDXW",
-	"ADJSP",
-	"ANDB",
-	"ANDL",
-	"ANDW",
-	"ASLB",
-	"ASLL",
-	"ASLW",
-	"ASRB",
-	"ASRL",
-	"ASRW",
-	"BCASE",
-	"BCC",
-	"BCHG",
-	"BCLR",
-	"BCS",
-	"BEQ",
-	"BFCHG",
-	"BFCLR",
-	"BFEXTS",
-	"BFEXTU",
-	"BFFFO",
-	"BFINS",
-	"BFSET",
-	"BFTST",
-	"BGE",
-	"BGT",
-	"BHI",
-	"BKPT",
-	"BLE",
-	"BLS",
-	"BLT",
-	"BMI",
-	"BNE",
-	"BPL",
-	"BRA",
-	"BSET",
-	"BSR",
-	"BTST",
-	"BVC",
-	"BVS",
-	"CALLM",
-	"CAS2B",
-	"CAS2L",
-	"CAS2W",
-	"CASB",
-	"CASEW",
-	"CASL",
-	"CASW",
-	"CHK2B",
-	"CHK2L",
-	"CHK2W",
-	"CHKL",
-	"CHKW",
-	"CLRB",
-	"CLRL",
-	"CLRW",
-	"CMP2B",
-	"CMP2L",
-	"CMP2W",
-	"CMPB",
-	"CMPL",
-	"CMPW",
-	"DATA",
-	"DBCC",
-	"DBCS",
-	"DBEQ",
-	"DBF",
-	"DBGE",
-	"DBGT",
-	"DBHI",
-	"DBLE",
-	"DBLS",
-	"DBLT",
-	"DBMI",
-	"DBNE",
-	"DBPL",
-	"DBT",
-	"DBVC",
-	"DBVS",
-	"DIVSL",
-	"DIVSW",
-	"DIVUL",
-	"DIVUW",
-	"END",
-	"EORB",
-	"EORL",
-	"EORW",
-	"EXG",
-	"EXTBL",
-	"EXTBW",
-	"EXTWL",
-	"FABSB",
-	"FABSD",
-	"FABSF",
-	"FABSL",
-	"FABSW",
-	"FACOSB",
-	"FACOSD",
-	"FACOSF",
-	"FACOSL",
-	"FACOSW",
-	"FADDB",
-	"FADDD",
-	"FADDF",
-	"FADDL",
-	"FADDW",
-	"FASINB",
-	"FASIND",
-	"FASINF",
-	"FASINL",
-	"FASINW",
-	"FATANB",
-	"FATAND",
-	"FATANF",
-	"FATANHB",
-	"FATANHD",
-	"FATANHF",
-	"FATANHL",
-	"FATANHW",
-	"FATANL",
-	"FATANW",
-	"FBEQ",
-	"FBF",
-	"FBGE",
-	"FBGT",
-	"FBLE",
-	"FBLT",
-	"FBNE",
-	"FBT",
-	"FCMPB",
-	"FCMPD",
-	"FCMPF",
-	"FCMPL",
-	"FCMPW",
-	"FCOSB",
-	"FCOSD",
-	"FCOSF",
-	"FCOSHB",
-	"FCOSHD",
-	"FCOSHF",
-	"FCOSHL",
-	"FCOSHW",
-	"FCOSL",
-	"FCOSW",
-	"FDBEQ",
-	"FDBF",
-	"FDBGE",
-	"FDBGT",
-	"FDBLE",
-	"FDBLT",
-	"FDBNE",
-	"FDBT",
-	"FDIVB",
-	"FDIVD",
-	"FDIVF",
-	"FDIVL",
-	"FDIVW",
-	"FETOXB",
-	"FETOXD",
-	"FETOXF",
-	"FETOXL",
-	"FETOXM1B",
-	"FETOXM1D",
-	"FETOXM1F",
-	"FETOXM1L",
-	"FETOXM1W",
-	"FETOXW",
-	"FGETEXPB",
-	"FGETEXPD",
-	"FGETEXPF",
-	"FGETEXPL",
-	"FGETEXPW",
-	"FGETMANB",
-	"FGETMAND",
-	"FGETMANF",
-	"FGETMANL",
-	"FGETMANW",
-	"FINTB",
-	"FINTD",
-	"FINTF",
-	"FINTL",
-	"FINTRZB",
-	"FINTRZD",
-	"FINTRZF",
-	"FINTRZL",
-	"FINTRZW",
-	"FINTW",
-	"FLOG10B",
-	"FLOG10D",
-	"FLOG10F",
-	"FLOG10L",
-	"FLOG10W",
-	"FLOG2B",
-	"FLOG2D",
-	"FLOG2F",
-	"FLOG2L",
-	"FLOG2W",
-	"FLOGNB",
-	"FLOGND",
-	"FLOGNF",
-	"FLOGNL",
-	"FLOGNP1B",
-	"FLOGNP1D",
-	"FLOGNP1F",
-	"FLOGNP1L",
-	"FLOGNP1W",
-	"FLOGNW",
-	"FMODB",
-	"FMODD",
-	"FMODF",
-	"FMODL",
-	"FMODW",
-	"FMOVEB",
-	"FMOVED",
-	"FMOVEF",
-	"FMOVEL",
-	"FMOVEM",
-	"FMOVEMC",
-	"FMOVEW",
-	"FMULB",
-	"FMULD",
-	"FMULF",
-	"FMULL",
-	"FMULW",
-	"FNEGB",
-	"FNEGD",
-	"FNEGF",
-	"FNEGL",
-	"FNEGW",
-	"FREMB",
-	"FREMD",
-	"FREMF",
-	"FREML",
-	"FREMW",
-	"FRESTORE",
-	"FSAVE",
-	"FSCALEB",
-	"FSCALED",
-	"FSCALEF",
-	"FSCALEL",
-	"FSCALEW",
-	"FSEQ",
-	"FSF",
-	"FSGE",
-	"FSGT",
-	"FSINB",
-	"FSIND",
-	"FSINF",
-	"FSINHB",
-	"FSINHD",
-	"FSINHF",
-	"FSINHL",
-	"FSINHW",
-	"FSINL",
-	"FSINW",
-	"FSLE",
-	"FSLT",
-	"FSNE",
-	"FSQRTB",
-	"FSQRTD",
-	"FSQRTF",
-	"FSQRTL",
-	"FSQRTW",
-	"FST",
-	"FSUBB",
-	"FSUBD",
-	"FSUBF",
-	"FSUBL",
-	"FSUBW",
-	"FTANB",
-	"FTAND",
-	"FTANF",
-	"FTANHB",
-	"FTANHD",
-	"FTANHF",
-	"FTANHL",
-	"FTANHW",
-	"FTANL",
-	"FTANW",
-	"FTENTOXB",
-	"FTENTOXD",
-	"FTENTOXF",
-	"FTENTOXL",
-	"FTENTOXW",
-	"FTSTB",
-	"FTSTD",
-	"FTSTF",
-	"FTSTL",
-	"FTSTW",
-	"FTWOTOXB",
-	"FTWOTOXD",
-	"FTWOTOXF",
-	"FTWOTOXL",
-	"FTWOTOXW",
-	"GLOBL",
-	"GOK",
-	"HISTORY",
-	"ILLEG",
-	"INSTR",
-	"JMP",
-	"JSR",
-	"LEA",
-	"LINKL",
-	"LINKW",
-	"LOCATE",
-	"LONG",
-	"LSLB",
-	"LSLL",
-	"LSLW",
-	"LSRB",
-	"LSRL",
-	"LSRW",
-	"MOVB",
-	"MOVEM",
-	"MOVEPL",
-	"MOVEPW",
-	"MOVESB",
-	"MOVESL",
-	"MOVESW",
-	"MOVL",
-	"MOVW",
-	"MULSL",
-	"MULSW",
-	"MULUL",
-	"MULUW",
-	"NAME",
-	"NBCD",
-	"NEGB",
-	"NEGL",
-	"NEGW",
-	"NEGXB",
-	"NEGXL",
-	"NEGXW",
-	"NOP",
-	"NOTB",
-	"NOTL",
-	"NOTW",
-	"ORB",
-	"ORL",
-	"ORW",
-	"PACK",
-	"PEA",
-	"RESET",
-	"ROTLB",
-	"ROTLL",
-	"ROTLW",
-	"ROTRB",
-	"ROTRL",
-	"ROTRW",
-	"ROXLB",
-	"ROXLL",
-	"ROXLW",
-	"ROXRB",
-	"ROXRL",
-	"ROXRW",
-	"RTD",
-	"RTE",
-	"RTM",
-	"RTR",
-	"RTS",
-	"SBCD",
-	"SCC",
-	"SCS",
-	"SEQ",
-	"SF",
-	"SGE",
-	"SGT",
-	"SHI",
-	"SLE",
-	"SLS",
-	"SLT",
-	"SMI",
-	"SNE",
-	"SPL",
-	"ST",
-	"STOP",
-	"SUBB",
-	"SUBL",
-	"SUBW",
-	"SUBXB",
-	"SUBXL",
-	"SUBXW",
-	"SVC",
-	"SVS",
-	"SWAP",
-	"SYS",
-	"TAS",
-	"TEXT",
-	"TRAP",
-	"TRAPCC",
-	"TRAPCS",
-	"TRAPEQ",
-	"TRAPF",
-	"TRAPGE",
-	"TRAPGT",
-	"TRAPHI",
-	"TRAPLE",
-	"TRAPLS",
-	"TRAPLT",
-	"TRAPMI",
-	"TRAPNE",
-	"TRAPPL",
-	"TRAPT",
-	"TRAPV",
-	"TRAPVC",
-	"TRAPVS",
-	"TSTB",
-	"TSTL",
-	"TSTW",
-	"UNLK",
-	"UNPK",
-	"WORD",
-	"SIGNAME",
-	"LAST",
-};

+ 0 - 358
sys/src/cmd/2c/gc.h

@@ -1,358 +0,0 @@
-#include	"../cc/cc.h"
-#include	"../2c/2.out.h"
-/*
- * 2c/68020
- * Motorola 68020
- */
-
-#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	ALLOP	OEND
-#define	NRGN	300
-#define	FNX	100
-#define	INDEXED	9
-
-#define	PRE	1
-#define	POST	2
-#define	TEST	4
-
-typedef	struct	Adr	Adr;
-typedef	struct	Prog	Prog;
-typedef	struct	Txt	Txt;
-typedef	struct	Cases	Case;
-typedef	struct	Reg	Reg;
-typedef	struct	Rgn	Rgn;
-typedef	struct	Var	Var;
-typedef	struct	Multab	Multab;
-typedef	struct	C1	C1;
-typedef	struct	Index	Index;
-
-struct Index
-{
-	int	o0;
-	int	o1;
-};
-
-EXTERN	struct
-{
-	Node*	regtree;
-	Node*	basetree;
-	short	scale;
-} idx;
-
-struct	Adr
-{
-	long	displace;
-	long	offset;
-
-	char	sval[NSNAME];
-	double	dval;
-
-	Sym*	sym;
-	short	type;
-	short	index;
-	short	scale;
-	short	field;
-	short	etype;
-};
-#define	A	((Adr*)0)
-
-struct	Prog
-{
-	Adr	from;
-	Adr	to;
-	Prog*	link;
-	long	lineno;
-	short	as;
-};
-#define	P	((Prog*)0)
-
-struct	Txt
-{
-	short	movas;
-	short	postext;
-	char	preclr;
-};
-
-struct	Cases
-{
-	vlong	val;
-	long	label;
-	uchar	def;
-	Case*	link;
-};
-#define	C	((Case*)0)
-
-struct	Var
-{
-	long	offset;
-	Sym*	sym;
-	char	type;
-	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;
-
-	ulong	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	Rgn
-{
-	Reg*	enter;
-	short	costr;
-	short	costa;
-	short	varno;
-	short	regno;
-};
-
-struct	Multab
-{
-	short	val;
-	char	code[6];
-};
-
-struct	C1
-{
-	vlong	val;
-	long	label;
-};
-
-#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	8
-#define	CREF	5
-#define	CTEST	2
-#define	CXREF	3
-#define	CINF	1000
-#define	LOOP	3
-
-EXTERN	Bits	externs;
-EXTERN	Bits	params;
-EXTERN	Bits	addrs;
-EXTERN	ulong	regbits;
-
-#define	B_INDIR	(1<<0)
-#define	B_ADDR	(1<<1)
-EXTERN	int	mvbits;
-EXTERN	int	changer;
-EXTERN	int	changea;
-
-EXTERN	Txt	txt[NTYPE][NTYPE];
-EXTERN	short	opxt[ALLOP][NTYPE];
-EXTERN	Txt*	txtp;
-EXTERN	int	multabsize;
-
-EXTERN	Reg*	firstr;
-EXTERN	Reg*	lastr;
-EXTERN	Reg	zreg;
-EXTERN	Reg*	freer;
-
-EXTERN	long	argoff;
-EXTERN	long	breakpc;
-EXTERN	long	nbreak;
-EXTERN	Case*	cases;
-EXTERN	long	continpc;
-EXTERN	Prog*	firstp;
-EXTERN	Reg*	firstr;
-EXTERN	int	inargs;
-EXTERN	Prog*	lastp;
-EXTERN	int	retok;
-EXTERN	long	mnstring;
-EXTERN	Node*	nodrat;
-EXTERN	Node*	nodret;
-EXTERN	long	nrathole;
-EXTERN	long	nstatic;
-EXTERN	int	nregion;
-EXTERN	long	nstring;
-EXTERN	int	nvar;
-EXTERN	Prog*	p;
-EXTERN	long	pc;
-EXTERN	Rgn	region[NRGN];
-EXTERN	Rgn*	rgp;
-EXTERN	char	string[NSNAME];
-EXTERN	Sym*	symrathole;
-EXTERN	Sym*	symstatic;
-EXTERN	Var	var[NVAR];
-EXTERN	long*	idom;
-EXTERN	Reg**	rpo2r;
-EXTERN	long	maxnr;
-EXTERN	Prog	zprog;
-
-EXTERN	uchar	regused[NREG];
-EXTERN	uchar	aregused[NREG];
-EXTERN	uchar	fregused[NREG];
-EXTERN	uchar	regbase[I_MASK];
-EXTERN	long	exregoffset;
-EXTERN	long	exaregoffset;
-EXTERN	long	exfregoffset;
-
-extern	char*	anames[];
-extern	Multab	multab[];
-
-void	cgen(Node*, int, Node*);
-void	lcgen(Node*, int, Node*);
-void	bcgen(Node*, int);
-void	boolgen(Node*, int, int, Node*, Node*);
-void	sugen(Node*, int, Node*, long);
-
-
-void	listinit(void);
-int	Bconv(Fmt*);
-int	Pconv(Fmt*);
-int	Aconv(Fmt*);
-int	Xconv(Fmt*);
-int	Dconv(Fmt*);
-int	Rconv(Fmt*);
-int	Sconv(Fmt*);
-
-void	peep(void);
-void	excise(Reg*);
-Reg*	uniqp(Reg*);
-Reg*	uniqs(Reg*);
-int	findtst(Reg*, Prog*, int);
-int	setcc(Prog*, Prog*);
-int	compat(Adr*, Adr*);
-int	aregind(Adr*);
-int	asize(int);
-int	usedin(int, Adr*);
-Reg*	findccr(Reg*);
-int	setccr(Prog*);
-Reg*	findop(Reg*, int, int, int);
-int	regtyp(int);
-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	tasas(Adr*, Adr*);
-int	copyau(Adr*, Adr*);
-int	copysub(Adr*, Adr*, Adr*, Prog*, int);
-
-ulong	RtoB(int);
-ulong	AtoB(int);
-ulong	FtoB(int);
-int	BtoR(ulong);
-int	BtoA(ulong);
-int	BtoF(ulong);
-
-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);
-ulong	allreg(ulong, Rgn*);
-void	paint1(Reg*, int);
-ulong	paint2(Reg*, int);
-void	paint3(Reg*, int, ulong, int);
-void	addreg(Adr*, int);
-
-void	codgen(Node*, Node*);
-void	gen(Node*);
-void	usedset(Node*, int);
-void	noretval(int);
-Node*	nodconst(long);
-
-int	swcmp(const void*, const void*);
-void	doswit(int, Node*);
-void	swit1(C1*, int, long, int, Node*);
-void	casf(void);
-int	bitload(Node*, int, int, int, Node*);
-void	bitstore(Node*, int, int, int, int, Node*);
-long	outstring(char*, long);
-int	doinc(Node*, int);
-void	setsp(void);
-void	adjsp(long);
-int	simplv(Node*);
-int	eval(Node*, int);
-void	outcode(void);
-void	ieeedtod(Ieee*, double);
-int	nodalloc(Type*, int, Node*);
-int	mulcon(Node*, Node*, int, Node*);
-int	shlcon(Node*, Node*, int, Node*);
-int	mulcon1(Node*, long, int, Node*);
-void	nullwarn(Node*, Node*);
-
-void	tindex(Type*, Type*);
-void	ginit(void);
-void	gclean(void);
-void	oinit(int, int, int, int, int, int);
-Prog*	prg(void);
-void	nextpc(void);
-void	gargs(Node*);
-void	naddr(Node*, Adr*, int);
-int	regalloc(Type*, int);
-int	regaddr(int);
-int	regpair(int);
-int	regret(Type*);
-void	regfree(int);
-void	gmove(Type*, Type*, int, Node*, int, Node*);
-void	gopcode(int, Type*, int, Node*, int, Node*);
-void	asopt(void);
-int	relindex(int);
-void	gbranch(int);
-void	fpbranch(void);
-void	patch(Prog*, long);
-void	gpseudo(int, Sym*, int, long);
-void	gpseudotree(int, Sym*, Node*);
-
-void	indx(Node*);
-void	bcomplex(Node*);
-
-/*
- * com64
- */
-int	com64(Node*);
-void	com64init(void);
-void	bool64(Node*);
-
-#pragma	varargck	type	"A"	int
-#pragma	varargck	type	"B"	Bits
-#pragma	varargck	type	"D"	Adr*
-#pragma	varargck	type	"N"	Adr*
-#pragma	varargck	type	"P"	Prog*
-#pragma	varargck	type	"S"	char*
-#pragma	varargck	type	"R"	int
-#pragma	varargck	type	"X"	Index

+ 0 - 384
sys/src/cmd/2c/list.c

@@ -1,384 +0,0 @@
-#define EXTERN
-#include "gc.h"
-
-void
-listinit(void)
-{
-
-	fmtinstall('R', Rconv);
-	fmtinstall('A', Aconv);
-	fmtinstall('D', Dconv);
-	fmtinstall('P', Pconv);
-	fmtinstall('S', Sconv);
-	fmtinstall('X', Xconv);
-	fmtinstall('B', Bconv);
-}
-
-static Index
-indexv(int i, int j)
-{
-	Index x;
-
-	x.o0 = i;
-	x.o1 = j;
-	return x;
-}
-
-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, "$%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], s[20];
-	Prog *p;
-
-	p = va_arg(fp->args, Prog*);
-	sprint(str, "	%A	%D,%D", p->as, &p->from, &p->to);
-	if(p->from.field) {
-		sprint(s, ",%d,%d", p->to.field, p->from.field);
-		strcat(str, s);
-	}
-	return fmtstrcpy(fp, str);
-}
-
-int
-Aconv(Fmt *fp)
-{
-	int r;
-
-	r = va_arg(fp->args, int);
-	return fmtstrcpy(fp, anames[r]);
-}
-
-int
-Xconv(Fmt *fp)
-{
-	char str[20], s[10];
-	Index x;
-	int i;
-
-	x = va_arg(fp->args, Index);
-	str[0] = 0;
-	i = x.o0 & D_MASK;
-	if(i != D_NONE) {
-		sprint(str, "(%R.", i);
-		i = x.o1;
-		sprint(s, "%c*%c)",
-			"WWWWLLLL"[i],
-			"12481248"[i]);
-		strcat(str, s);
-	}
-	return fmtstrcpy(fp, str);
-}
-
-int
-Dconv(Fmt *fp)
-{
-	char str[40], s[20];
-	Adr *a;
-	int i, j;
-	long d;
-
-	a = va_arg(fp->args, Adr*);
-	i = a->index;
-	if(i != D_NONE) {
-		a->index = D_NONE;
-		d = a->displace;
-		j = a->scale;
-		a->displace = 0;
-		switch(i & I_MASK) {
-		default:
-			sprint(str, "???%ld(%D%X)", d, a, indexv(i, j));
-			break;
-
-		case I_INDEX1:
-			sprint(str, "%D%X", a, indexv(i, a->scale));
-			break;
-
-		case I_INDEX2:
-			if(d)
-				sprint(str, "%ld(%D)%X", d, a, indexv(i, j));
-			else
-				sprint(str, "(%D)%X", a, indexv(i, j));
-			break;
-
-		case I_INDEX3:
-			if(d)
-				sprint(str, "%ld(%D%X)", d, a, indexv(i, j));
-			else
-				sprint(str, "(%D%X)", a, indexv(i, j));
-			break;
-		}
-		a->displace = d;
-		a->index = i;
-		goto out;
-	}
-	i = a->type;
-	j = i & I_MASK;
-	if(j) {
-		a->type = i & D_MASK;
-		d = a->offset;
-		a->offset = 0;
-		switch(j) {
-		case I_INDINC:
-			sprint(str, "(%D)+", a);
-			break;
-
-		case I_INDDEC:
-			sprint(str, "-(%D)", a);
-			break;
-
-		case I_INDIR:
-			if(a->type == D_CONST)
-				sprint(str, "%ld", d);
-			else
-			if(d)
-				sprint(str, "%ld(%D)", d, a);
-			else
-				sprint(str, "(%D)", a);
-			break;
-
-		case I_ADDR:
-			a->offset = d;
-			sprint(str, "$%D", a);
-			break;
-		}
-		a->type = i;
-		a->offset = d;
-		goto out;
-	}
-	switch(i) {
-
-	default:
-		sprint(str, "%R", i);
-		break;
-
-	case D_NONE:
-		str[0] = 0;
-		break;
-
-	case D_BRANCH:
-		sprint(str, "%ld(PC)", a->offset-pc);
-		break;
-
-	case D_EXTERN:
-		sprint(str, "%s+%ld(SB)", a->sym->name, a->offset);
-		break;
-
-	case D_STATIC:
-		sprint(str, "%s<>+%ld(SB)", a->sym->name, a->offset);
-		break;
-
-	case D_AUTO:
-		sprint(str, "%s-%ld(SP)", a->sym->name, -a->offset);
-		break;
-
-	case D_PARAM:
-		sprint(str, "%s+%ld(FP)", a->sym->name, a->offset);
-		break;
-
-	case D_CONST:
-		sprint(str, "$%ld", a->offset);
-		break;
-
-	case D_STACK:
-		sprint(str, "TOS+%ld", a->offset);
-		break;
-
-	case D_FCONST:
-		sprint(str, "$%.17e", a->dval);
-		goto out;
-
-	case D_SCONST:
-		sprint(str, "$\"%S\"", a->sval);
-		goto out;
-	}
-	if(a->displace) {
-		sprint(s, "/%ld", a->displace);
-		strcat(str, s);
-	}
-out:
-	return fmtstrcpy(fp, str);
-}
-
-int
-Rconv(Fmt *fp)
-{
-	char str[20];
-	int r;
-
-	r = va_arg(fp->args, int);
-	if(r >= D_R0 && r < D_R0+NREG)
-		sprint(str, "R%d", r-D_R0);
-	else
-	if(r >= D_A0 && r < D_A0+NREG)
-		sprint(str, "A%d", r-D_A0);
-	else
-	if(r >= D_F0 && r < D_F0+NREG)
-		sprint(str, "F%d", r-D_F0);
-	else
-	switch(r) {
-
-	default:
-		sprint(str, "gok(%d)", r);
-		break;
-
-	case D_NONE:
-		sprint(str, "NONE");
-		break;
-
-	case D_TOS:
-		sprint(str, "TOS");
-		break;
-
-	case D_CCR:
-		sprint(str, "CCR");
-		break;
-
-	case D_SR:
-		sprint(str, "SR");
-		break;
-
-	case D_SFC:
-		sprint(str, "SFC");
-		break;
-
-	case D_DFC:
-		sprint(str, "DFC");
-		break;
-
-	case D_CACR:
-		sprint(str, "CACR");
-		break;
-
-	case D_USP:
-		sprint(str, "USP");
-		break;
-
-	case D_VBR:
-		sprint(str, "VBR");
-		break;
-
-	case D_CAAR:
-		sprint(str, "CAAR");
-		break;
-
-	case D_MSP:
-		sprint(str, "MSP");
-		break;
-
-	case D_ISP:
-		sprint(str, "ISP");
-		break;
-
-	case D_TREE:
-		sprint(str, "TREE");
-		break;
-
-	case D_FPCR:
-		sprint(str, "FPCR");
-		break;
-
-	case D_FPSR:
-		sprint(str, "FPSR");
-		break;
-
-	case D_FPIAR:
-		sprint(str, "FPIAR");
-		break;
-
-	case D_TC:
-		sprint(str, "TC");
-		break;
-
-	case D_ITT0:
-		sprint(str, "ITT0");
-		break;
-
-	case D_ITT1:
-		sprint(str, "ITT1");
-		break;
-
-	case D_DTT0:
-		sprint(str, "DTT0");
-		break;
-
-	case D_DTT1:
-		sprint(str, "DTT1");
-		break;
-
-	case D_MMUSR:
-		sprint(str, "MMUSR");
-		break;
-	case D_URP:
-		sprint(str, "URP");
-		break;
-
-	case D_SRP:
-		sprint(str, "SRP");
-		break;
-	}
-	return fmtstrcpy(fp, str);
-}
-
-int
-Sconv(Fmt *fp)
-{
-	int i, c;
-	char str[30], *p, *s;
-
-	s = va_arg(fp->args, char*);
-	p = str;
-	for(i=0; i<sizeof(double); i++) {
-		c = s[i] & 0xff;
-		if(c != '\\' && c != '"' && isprint(c)) {
-			*p++ = c;
-			continue;
-		}
-		*p++ = '\\';
-		switch(c) {
-		case 0:
-			*p++ = '0';
-			continue;
-		case '\\':
-		case '"':
-			*p++ = c;
-			continue;
-		case '\n':
-			*p++ = 'n';
-			continue;
-		case '\t':
-			*p++ = 't';
-			continue;
-		}
-		*p++ = ((c>>6) & 7) + '0';
-		*p++ = ((c>>3) & 7) + '0';
-		*p++ = ((c>>0) & 7) + '0';
-	}
-	*p = 0;
-	return fmtstrcpy(fp, str);
-}

+ 0 - 32
sys/src/cmd/2c/mkfile

@@ -1,32 +0,0 @@
-</$objtype/mkfile
-
-TARG=2c
-OFILES=\
-	cgen.$O\
-	reg.$O\
-	txt.$O\
-	peep.$O\
-	swt.$O\
-	sgen.$O\
-	list.$O\
-	enam.$O\
-	mul.$O\
-
-HFILES=\
-	gc.h\
-	2.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 - 174
sys/src/cmd/2c/mul.c

@@ -1,174 +0,0 @@
-#include "gc.h"
-
-/*
- * code sequences for multiply by constant
- * all sequences start with leading '0'.
- * if sequence starts with 'i', then the
- *	leading '0' is suppressed.
- * '0'	mov r0,r1
- * '1'  sub r0,r1
- * '2'	sub r1,r0
- * '3'	add r0,r1
- * '4'	add r1,r0
- * '5'	add r0,r0
- * '6'	add r1,r1
- * 'b'	lsh $2,r0
- * 'c'	lsh $3,r0
- * 'd'-'h' ...
- * 'j'	lsh $2,r1
- * 'k'-'p' ...
- */
-Multab multab[] =
-{
-	2, "i5",
-	3, "64",
-	4, "i55",
-	5, "664",
-	6, "645",
-	7, "c2",
-	9, "k4",
-	10, "6645",
-	11, "66364",
-	12, "6455",
-	13, "66464",
-	14, "6d2",
-	15, "d2",
-	17, "l4",
-	18, "6d4",
-	19, "64k4",
-	20, "66455",
-	21, "664664",
-	22, "64c2",
-	23, "44c2",
-	24, "64c",
-	25, "63k4",
-	26, "64c4",
-	27, "663e2",
-	28, "66e2",
-	29, "63e2",
-	30, "6e2",
-	31, "e2",
-	33, "m4",
-	34, "6e4",
-	35, "64l4",
-	36, "66e4",
-	37, "664k4",
-	38, "64k45",
-	39, "454c2",
-	40, "664c",
-	41, "663k4",
-	42, "644c4",
-	43, "643k4",
-	44, "664c4",
-	45, "640d2",
-	46, "64d2",
-	47, "44d2",
-	48, "64d",
-	49, "63l4",
-	50, "64d4",
-	51, "640l4",
-	52, "646d4",
-	53, "643d4",
-	54, "6636f2",
-	55, "k3f2",
-	56, "kf2",
-	57, "k2k4",
-	58, "636f2",
-	59, "663f2",
-	60, "66f2",
-	61, "63f2",
-	62, "6f2",
-	63, "f2",
-	65, "n4",
-	66, "6f4",
-	67, "64m4",
-	68, "66f4",
-	69, "664l4",
-	70, "64l45",
-	71, "k1f4",
-	72, "k4c",
-	73, "k4k4",
-	74, "664k45",
-	75, "6640d2",
-	76, "664d2",
-	77, "434d2",
-	78, "644d2",
-	79, "454d2",
-	80, "664d",
-	81, "663l4",
-	82, "644d4",
-	83, "643l4",
-	84, "664d4",
-	85, "6640l4",
-	86, "6634l4",
-	87, "6443d4",
-	88, "6646d4",
-	89, "6643d4",
-	90, "6406e2",
-	91, "643e2",
-	92, "646e2",
-	93, "640e2",
-	94, "64e2",
-	95, "44e2",
-	96, "64e",
-	97, "63m4",
-	98, "64e4",
-	99, "640m4",
-	100, "646e4",
-	200, "66f364",
-	300, "j40jf2",
-	400, "64kg4",
-	500, "66h212",
-	600, "64m4c4",
-	700, "j4c4d2",
-	800, "64lh4",
-	900, "6464g4",
-	1000, "63g2c",
-	1100, "j4d2p4",
-	1200, "64k4f2",
-	1300, "j4n4b4",
-	1400, "64j4g2",
-	1600, "64d4e",
-	1800, "p4c2",
-	2000, "63g2d",
-	2100, "l4b2o4",
-	2200, "k4d4p4",
-	2300, "6644h2",
-	2400, "j4k4f4",
-	2500, "j4e2d4",
-	2600, "j40n4c",
-	3100, "jd12p2",
-	3200, "64d4f",
-	3600, "6d1p2",
-	3800, "e3k3g2",
-	3900, "jf20n4",
-	4000, "o4e2",
-	4100, "66p455",
-	4200, "l4c3e2",
-	4300, "l4b1f4",
-	4400, "64o4d4",
-	4600, "k45h2",
-	4700, "k3j4g2",
-	4800, "j40d2f",
-	5000, "l4c3m4",
-	5100, "j40h2b",
-	5200, "j40n4d",
-	6000, "d1o3h2",
-	6100, "o1l4b2",
-	6200, "ke12p2",
-	6400, "64d4g",
-	7200, "66e1p2",
-	7400, "m3m4c2",
-	7600, "l4f3c2",
-	7800, "kg20n4",
-	8000, "63g2f",
-	8100, "m2b4p4",
-	8200, "66p4c",
-	8700, "66f4g2",
-	8900, "l3j4g4",
-	9200, "k45h25",
-	9600, "j40d2g",
-	9800, "k4f3d4",
-};
-
-int	multabsize = sizeof(multab) / sizeof(multab[0]);

+ 0 - 1073
sys/src/cmd/2c/peep.c

@@ -1,1073 +0,0 @@
-#include "gc.h"
-
-void
-peep(void)
-{
-	Reg *r, *r1, *r2;
-	Prog *p, *p1;
-	int t, s;
-/*
- * 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:
-	/*
-	 * propigate move's by renaming
-	 */
-	t = 0;
-	for(r=firstr; r!=R; r=r->link) {
-		p = r->prog;
-		if(p->as == AMOVL || p->as == AFMOVEF || p->as == AFMOVED)
-		if(regtyp(p->from.type))
-		if(anyvar(&p->to)) {
-			if(copyprop(r)) {
-				excise(r);
-				t++;
-			} else
-			if(subprop(r) && copyprop(r)) {
-				excise(r);
-				t++;
-			}
-		}
-	}
-	if(t)
-		goto loop1;
-	for(r=firstr; r!=R; r=r->link) {
-		p = r->prog;
-		/*
-		 * convert (A) ... A++ into (A)++
-		 * and     A-- ... (A) into --(A)
-		 */
-		t = aregind(&p->from);
-		if(t == D_NONE)
-			goto out1;
-		s = asize(p->as);
-		if(s == 0)
-			goto out1;
-		r1 = findop(r, t, AADDL, s);
-		if(r1 != R) {
-			if(usedin(t, &p->to))
-				goto out1;
-			p->from.type += I_INDINC - I_INDIR;
-			excise(r1);
-			goto out1;
-		}
-		r1 = findop(r, t, ASUBL, s);
-		if(r1 != R) {
-			p->from.type += I_INDDEC - I_INDIR;
-			excise(r1);
-		}
-	out1:
-		t = aregind(&p->to);
-		if(t == D_NONE)
-			goto out2;
-		s = asize(p->as);
-		if(s == 0)
-			goto out2;
-		r1 = findop(r, t, AADDL, s);
-		if(r1 != R) {
-			p->to.type += I_INDINC - I_INDIR;
-			excise(r1);
-			goto out2;
-		}
-		r1 = findop(r, t, ASUBL, s);
-		if(r1 != R) {
-			if(usedin(t, &p->from))
-				goto out2;
-			p->to.type += I_INDDEC - I_INDIR;
-			excise(r1);
-		}
-	out2:
-		/*
-		 * get rid of unneeded save/restore CCR
-		 */
-		if(p->from.type == D_CCR) {
-			r1 = findccr(r);
-			if(r1 != R) {
-				excise(r);
-				excise(r1);
-			}
-		}
-		switch(p->as) {
-		case ATSTB:
-		case ATSTW:
-		case ATSTL:
-			if(findtst(r, r->prog, 0))
-				excise(r);
-		}
-		/*
-		 * turn TSTB (A); BLT; ORB $128,(A) into TAS (A); BLT; NOP
-		 */
-		if(p->as == ATSTB && (r1 = r->s1)) {
-			if((r1->prog->as == ABLT && (r2 = r1->s1)) ||
-			   (r1->prog->as == ABGE && (r2 = r1->s2))) {
-				p1 = r2->prog;
-				if(p1->as == AORB)
-				if(p1->from.type == D_CONST)
-				if(p1->from.offset == 128)
-				if(r1 == uniqp(r2))
-				if(tasas(&p->to, &p1->to)) {
-					p->as = ATAS;
-					excise(r2);
-				}
-			}
-		}
-	}
-}
-
-void
-excise(Reg *r)
-{
-
-	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;
-}
-
-/*
- * chase backward all cc setting.
- * returns 1 if all set same.
- */
-int
-findtst(Reg *r0, Prog *rp, int n)
-{
-	Reg *r;
-	int c;
-
-loop:
-	n++;
-	if(n >= 10)
-		return 0;
-	for(r=r0->p2; r!=R; r=r->p2link) {
-		c = setcc(r->prog, rp);
-		if(c > 0)
-			continue;
-		if(c == 0)
-			return 0;
-		if(findtst(r, rp, n) == 0)
-			return 0;
-	}
-	r = r0->p1;
-	if(r == R)
-		return 1;
-	c = setcc(r->prog, rp);
-	if(c > 0)
-		return 1;
-	if(c == 0)
-		return 0;
-	r0 = r;
-	goto loop;
-}
-
-/*
- * tests cc
- * returns -1 if no change
- * returns 1 if set the same
- * returns 0 if set different
- */
-int
-setcc(Prog *p, Prog *rp)
-{
-	int s;
-
-	s = asize(rp->as);
-	switch(p->as) {
-	default:
-		if(debug['P'])
-			print("unknown setcc %A\n", p->as);
-		break;
-
-	case ACMPB:
-	case ACMPW:
-	case ACMPL:
-	case ABSR:
-		return 0;
-
-	case ABRA:
-	case ABGE:
-	case ABNE:
-	case ABLE:
-	case ABEQ:
-	case ABHI:
-	case ABLS:
-	case ABMI:
-	case ABPL:
-	case ABGT:
-	case ABLT:
-	case ABCC:
-	case ABCS:
-	case APEA:
-	case ALEA:
-	case ANOP:
-
-	case AFADDD:
-	case AFMULD:
-	case AFDIVD:
-	case AFSUBD:
-	case AFADDF:
-	case AFMULF:
-	case AFDIVF:
-	case AFSUBF:
-	case AADJSP:
-		return -1;
-
-	case AADDW:
-	case AADDL:
-	case ASUBW:
-	case ASUBL:
-	case ACLRL:
-	case ACLRW:
-		if(p->to.type >= D_A0 && p->to.type < D_A0+8)
-			goto areg;
-
-	case AADDB:
-	case ASUBB:
-	case AANDB:
-	case AANDW:
-	case AANDL:
-	case AORB:
-	case AORW:
-	case AORL:
-	case AEORB:
-	case AEORW:
-	case AEORL:
-	case ALSLB:
-	case ALSLW:
-	case ALSLL:
-	case ALSRB:
-	case ALSRW:
-	case ALSRL:
-	case AASLB:
-	case AASLW:
-	case AASLL:
-	case AASRB:
-	case AASRW:
-	case AASRL:
-	case ATSTB:
-	case ATSTW:
-	case ATSTL:
-	case ANEGB:
-	case ANEGW:
-	case ANEGL:
-	case ACLRB:
-		if(asize(p->as) != s)
-			break;
-		if(compat(&rp->to, &p->to))
-			return 1;
-		break;
-
-	case AMOVW:
-	case AMOVL:
-		if(p->to.type >= D_A0 && p->to.type < D_A0+8)
-			goto areg;
-	case AMOVB:
-		if(asize(p->as) != s)
-			break;
-		if(compat(&rp->to, &p->to))
-			return 1;
-		if(compat(&rp->to, &p->from))
-			return 1;
-	}
-	return 0;
-
-areg:
-	if((rp->to.type&D_MASK) == p->to.type)
-		return 0;
-	return -1;
-}
-
-int
-compat(Adr *a, Adr *b)
-{
-	int o;
-
-	if(a->index != D_NONE)
-		return 0;
-	if(b->index != D_NONE)
-		return 0;
-	o = a->type;
-	if((o >= D_R0 && o < D_R0+NREG) ||
-	   (o >= D_A0 && o < D_A0+NREG))
-		return o == b->type;
-	o &= D_MASK;
-	if(o >= D_A0 && o < D_A0+NREG) {
-		if(o != (b->type&D_MASK))
-			return 0;
-		if(a->offset != b->offset)
-			return 0;
-		o = a->type & I_MASK;
-		if(o == I_INDIR) {
-			o = b->type & I_MASK;
-			if(o == I_INDIR || o == I_INDDEC)
-				return 1;
-			return 0;
-		}
-		if(o == I_INDINC) {
-			o = b->type & I_MASK;
-			if(o == I_INDIR) {
-				b->type += I_INDINC-I_INDIR;
-				return 1;
-			}
-			if(o == I_INDDEC) {
-				b->type += I_INDIR-I_INDDEC;
-				return 1;
-			}
-			return 0;
-		}
-	}
-	return 0;
-}
-
-int
-aregind(Adr *a)
-{
-	int t;
-
-	t = a->type;
-	if(t >= (D_A0|I_INDIR) && t < ((D_A0+NREG)|I_INDIR))
-	while(a->offset == 0 && a->index == D_NONE)
-		return t & D_MASK;
-	return D_NONE;
-}
-
-int
-asize(int a)
-{
-
-	switch(a) {
-	case AFTSTD:
-	case AFMOVED:
-	case AFADDD:
-	case AFSUBD:
-	case AFMULD:
-	case AFDIVD:
-	case AFCMPD:
-	case AFNEGD:
-		return 8;
-
-	case AFTSTF:
-	case AFMOVEF:
-	case AFADDF:
-	case AFSUBF:
-	case AFMULF:
-	case AFDIVF:
-	case AFCMPF:
-	case AFNEGF:
-
-	case ACLRL:
-	case ATSTL:
-	case AMOVL:
-	case AADDL:
-	case ASUBL:
-	case ACMPL:
-	case AANDL:
-	case AORL:
-	case AEORL:
-	case ALSLL:
-	case ALSRL:
-	case AASLL:
-	case AASRL:
-	case ANEGL:
-		return 4;
-
-	case ACLRW:
-	case ATSTW:
-	case AMOVW:
-	case AADDW:
-	case ASUBW:
-	case ACMPW:
-	case AANDW:
-	case AORW:
-	case AEORW:
-	case ALSLW:
-	case ALSRW:
-	case AASLW:
-	case AASRW:
-	case ANEGW:
-		return 2;
-
-	case ACLRB:
-	case ATSTB:
-	case AMOVB:
-	case AADDB:
-	case ASUBB:
-	case ACMPB:
-	case AANDB:
-	case AORB:
-	case AEORB:
-	case ALSLB:
-	case ALSRB:
-	case AASLB:
-	case AASRB:
-	case ANEGB:
-		return 1;
-	}
-	if(debug['P'])
-		print("unknown asize %A\n", p->as);
-	return 0;
-}
-
-int
-usedin(int t, Adr *a)
-{
-
-	if((a->type&D_MASK) == t)
-		return 1;
-	if((a->index&D_MASK) == t)
-		return 1;
-	return 0;
-}
-
-Reg*
-findccr(Reg *r)
-{
-	Prog *p;
-
-	for(;;) {
-		r = uniqs(r);
-		if(r == R)
-			break;
-		p = r->prog;
-		if(p->to.type == D_CCR)
-			return r;
-		if(setccr(p))
-			break;
-	}
-	return R;
-}
-
-int
-setccr(Prog *p)
-{
-
-	switch(p->as) {
-	case ANOP:
-		return 0;
-
-	case AADDL:
-	case AMOVL:
-	case ACLRL:
-		if(p->to.type >= D_A0 && p->to.type < D_A0+8)
-			return 0;
-	}
-	return 1;
-}
-
-Reg*
-findop(Reg *r, int t, int o, int s)
-{
-	Prog *p;
-	Reg *r1;
-
-	for(;;) {
-		if(o == AADDL) {
-			r1 = uniqs(r);
-			if(r1 == R)
-				break;
-			if(uniqp(r1) != r)
-				break;
-		} else {
-			r1 = uniqp(r);
-			if(r1 == R)
-				break;
-			if(uniqs(r1) != r)
-				break;
-		}
-		r = r1;
-		p = r->prog;
-		if(usedin(t, &p->from))
-			break;
-		if(usedin(t, &p->to)) {
-			if(p->as == o)
-			if(p->to.type == t)
-			if(p->to.index == D_NONE)
-			if(p->from.type == D_CONST)
-			if(p->from.offset == s)
-				return r;
-			break;
-		}
-	}
-	return R;
-}
-
-int
-regtyp(int t)
-{
-
-	if(t >= D_R0 && t < D_R0+8)
-		return 1;
-	if(t >= D_A0 && t < D_A0+8)
-		return 1;
-	if(t >= D_F0 && t < D_F0+8)
-		return 1;
-	return 0;
-}
-
-int
-anyvar(Adr *a)
-{
-
-	if(regtyp(a->type))
-		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 MOVL
- * 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->type))
-		return 0;
-	v2 = &p->to;
-	if(!regtyp(v2->type))
-		return 0;
-	for(r=uniqp(r0); r!=R; r=uniqp(r)) {
-		if(uniqs(r) == R)
-			break;
-		p = r->prog;
-		switch(p->as) {
-		case ADIVUW:	/* these set Rn and Rn+1 */
-		case ADIVUL:
-		case ADIVSW:
-		case ADIVSL:
-		case ABSR:
-			return 0;
-
-		case AFMOVED:
-		case AFMOVEF:
-		case AMOVL:
-			if(p->to.type == v1->type)
-				goto gotit;
-		}
-		if(copyau(&p->from, v2) || copyau(&p->to, v2))
-			break;
-		if(copysub(&p->from, v1, v2, p, 0) || copysub(&p->to, v1, v2, p, 0))
-			break;
-	}
-	return 0;
-
-gotit:
-	copysub(&p->to, v1, v2, p, 1);
-	if(debug['P']) {
-		print("gotit: %D->%D\n%P", v1, v2, r->prog);
-		if(p->from.type == v2->type)
-			print(" excise");
-		print("\n");
-	}
-	if(p->from.type == v2->type)
-		excise(r);
-	for(r=uniqs(r); r!=r0; r=uniqs(r)) {
-		p = r->prog;
-		copysub(&p->from, v1, v2, p, 1);
-		copysub(&p->to, v1, v2, p, 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;
-
-	if(r->active) {
-		if(debug['P'])
-			print("copyret 1\n");
-		return 1;
-	}
-	r->active = 1;
-	if(debug['P'])
-		print("copy %D->%D\n", v1, v2);
-	for(; r != R; r = r->s1) {
-		if(debug['P'])
-			print("%P", r->prog);
-		if(!f && uniqp(r) == R) {
-			f = 1;
-			if(debug['P'])
-				print("; merge; f=%d", f);
-		}
-		t = copyu(r->prog, v2, A);
-		switch(t) {
-		case 2:	/* rar, cant split */
-			if(debug['P'])
-				print("; rar return 0\n");
-			return 0;
-		case 3:	/* set */
-			if(debug['P'])
-				print("; set; return 1\n");
-			return 1;
-		case 1:	/* used, substitute */
-		case 4:	/* use and set */
-			if(f) {
-				if(debug['P'])
-					print("; used and f; return 0\n");
-				return 0;
-			}
-			if(copyu(r->prog, v2, v1)) {
-				if(debug['P'])
-					print("; sub fail; return 0\n");
-				return 0;
-			}
-			if(debug['P'])
-				print("; substitute");
-			if(t == 4) {
-				if(debug['P'])
-					print("; used and set; return 1\n");
-				return 1;
-			}
-			break;
-		}
-		if(!f) {
-			t = copyu(r->prog, v1, A);
-			if(!f && (t == 2 || t == 3 || t == 4)) {
-				if(debug['P'])
-					print("; f set used");
-				f = 1;
-			}
-		}
-		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)
-{
-	int t;
-
-	switch(p->as) {
-
-	default:
-		if(debug['P'])
-			print("unknown op %A\n", p->as);
-		return 2;
-
-	case APEA:	/* rhs addr */
-		if(copyas(&p->to, v))
-			return 2;
-		goto caseread;
-
-	case ALEA:	/* lhs addr, rhs store */
-		if(copyas(&p->from, v))
-			return 2;
-
-	case AMOVL:	/* rhs store */
-	case ACLRL:
-	case AFMOVEF:
-	case AFMOVED:
-	case AFMOVEB:
-	case AFMOVEW:
-	case AFMOVEL:
-	case ANOP:
-		if(copyas(&p->to, v)) {
-			if(s != A)
-				return copysub(&p->from, v, s, p, 1);
-			if(copyau(&p->from, v))
-				return 4;
-			return 3;
-		}
-		goto caseread;
-			
-	case AADDL:	/* rhs rar */
-	case AADDW:
-	case AADDB:
-	case ASUBL:
-	case ASUBW:
-	case ASUBB:
-	case AANDL:
-	case AANDW:
-	case AANDB:
-	case AORL:
-	case AORW:
-	case AORB:
-	case AEORL:
-	case AEORW:
-	case AEORB:
-	case AASRL:
-	case AASRW:
-	case AASRB:
-	case AASLL:
-	case AASLW:
-	case AASLB:
-	case ALSRL:
-	case ALSRW:
-	case ALSRB:
-	case ANOTL:
-	case ANOTW:
-	case ANOTB:
-	case ANEGL:
-	case ANEGW:
-	case ANEGB:
-	case AEXTBL:
-	case AEXTWL:
-	case AEXTBW:
-
-	case AMULSL:
-	case AMULUL:
-
-	case AMOVW:	/* only sets part of register */
-	case AMOVB:
-	case ACLRW:
-	case ACLRB:
-
-	case AFADDD:
-	case AFMULD:
-	case AFDIVD:
-	case AFSUBD:
-	case AFNEGD:
-	case AFADDF:
-	case AFMULF:
-	case AFDIVF:
-	case AFSUBF:
-	case AFNEGF:
-		if(copyas(&p->to, v))
-			return 2;
-		goto caseread;
-
-	case ADBF:	/* lhs rar */
-		if(copyas(&p->from, v))
-			return 2;
-		goto caseread;
-
-	case ACMPL:	/* read only */
-	case ACMPW:
-	case ACMPB:
-	case AFCMPF:
-	case AFCMPD:
-	case ATSTL:
-	case ATSTW:
-	case ATSTB:
-	case AFTSTF:
-	case AFTSTD:
-	caseread:
-		if(s != A) {
-			if(copysub(&p->from, v, s, p, 1))
-				return 1;
-			return copysub(&p->to, v, s, p, 1);
-		}
-		if(copyau(&p->from, v))
-			return 1;
-		if(copyau(&p->to, v))
-			return 1;
-		break;
-
-	case ABRA:	/* no reference */
-	case ABGE:
-	case ABNE:
-	case ABLE:
-	case ABEQ:
-	case ABHI:
-	case ABLS:
-	case ABMI:
-	case ABPL:
-	case ABGT:
-	case ABLT:
-	case ABCC:
-	case ABCS:
-
-	case AFBEQ:
-	case AFBNE:
-	case AFBGT:
-	case AFBGE:
-	case AFBLE:
-	case AFBLT:
-
-	case AADJSP:
-	case ACASEW:
-		break;
-
-	case ADIVUW:	/* these set Rn and Rn+1 */
-	case ADIVUL:
-	case ADIVSW:
-	case ADIVSL:
-		t = v->type;
-		if(t == p->to.type || t == p->to.type+1)
-			return 2;
-		goto caseread;
-
-	case ARTS:	/* funny */
-		t = v->type;
-		if(t == D_R0 || t == D_F0)
-			return 2;
-		if(t >= D_R0 && t < D_R0+NREG)
-		if(t-D_R0 > exregoffset)
-			return 2;
-		if(t >= D_A0 && t < D_A0+NREG)
-		if(t-D_A0 > exaregoffset)
-			return 2;
-		if(t >= D_F0 && t < D_F0+NREG)
-		if(t-D_F0 > exfregoffset)
-			return 2;
-		return 3;
-
-	case ABSR:	/* funny */
-		t = v->type;
-		if(t >= D_R0 && t < D_R0+NREG)
-		if(t-D_R0 > exregoffset)
-			return 2;
-		if(t >= D_A0 && t < D_A0+NREG)
-		if(t-D_A0 > exaregoffset)
-			return 2;
-		if(t >= D_F0 && t < D_F0+NREG)
-		if(t-D_F0 > exfregoffset)
-			return 2;
-		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->type))
-		return 1;
-	if(v->type == D_AUTO || v->type == D_PARAM) {
-		if(v->offset == a->offset)
-			return 1;
-		return 0;
-	}
-	return 0;
-}
-
-/*
- * indirect
- */
-int
-tasas(Adr *a, Adr *v)
-{
-	int t;
-
-	if(a->index != D_NONE)
-		return 0;
-	if(v->index != D_NONE)
-		return 0;
-	t = a->type;
-	if(t < I_INDIR+D_A0 && t >= I_INDIR+D_A0+8)
-		return 0;
-	if(v->type != t)
-		return 0;
-	if(a->displace != v->displace)
-		return 0;
-	return 1;
-}
-
-/*
- * either direct or indirect
- */
-int
-copyau(Adr *a, Adr *v)
-{
-	int t;
-
-	if(copyas(a, v))
-		return 1;
-	t = v->type;
-	if(regtyp(t)) {
-		if((a->type & D_MASK) == t)
-			return 1;
-		if((a->index & D_MASK) == t)
-			return 1;
-	}
-	return 0;
-}
-
-/*
- * substitute s for v in a
- * return failure to substitute
- */
-int
-copysub(Adr *a, Adr *v, Adr *s, Prog *p, int f)
-{
-	int t;
-
-	if(copyas(a, v)) {
-		t = s->type;
-		if(t >= D_F0 && t < D_F0+8) {
-			if(f)
-				a->type = t;
-			return 0;
-		}
-		if(t >= D_R0 && t < D_R0+8) {
-			if(f)
-				a->type = t;
-			return 0;
-		}
-		if(!(t >= D_A0 && t < D_A0+8))
-			return 1;
-		switch(p->as) {
-		default:
-			return 1;
-
-		case AMOVL:
-		case AMOVW:
-		case ACMPL:
-		case ACMPW:
-			break;
-
-		case AADDL:
-		case AADDW:
-		case ASUBL:
-		case ASUBW:
-			if(a == &p->from && !regtyp(p->to.type))
-				return 1;
-			break;
-		}
-		if(f)
-			a->type = t;
-		return 0;
-	}
-	t = v->type;
-	if(regtyp(t)) {
-		if((a->type & D_MASK) == t) {
-			if((s->type ^ t) & ~(NREG-1))
-				return 1;
-			if(f)
-				a->type = (a->type & ~D_MASK) | s->type;
-			return 0;
-		}
-		if((a->index & D_MASK) == t) {
-			if(f)
-				a->index = (a->index & ~D_MASK) | s->type;
-			return 0;
-		}
-		return 0;
-	}
-	return 0;
-}

+ 0 - 1275
sys/src/cmd/2c/reg.c

@@ -1,1275 +0,0 @@
-#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->costr;
-	if(p2->costa > c1)
-		c1 = p2->costa;
-	c2 = p1->costr;
-	if(p1->costa > c2)
-		c2 = p1->costa;
-	if(c1 -= c2)
-		return c1;
-	return p2->varno - p1->varno;
-}
-
-void
-regopt(Prog *p)
-{
-	Reg *r, *r1, *r2;
-	Prog *p1;
-	int i, z;
-	long val, initpc, npc;
-	ulong vreg;
-	Bits bit;
-	Var *v;
-	struct {
-		long	m;
-		long	c;
-		Reg*	p;
-	} log5[6], *lp;
-
-	firstr = R;
-	lastr = R;
-	nvar = 0;
-	for(z=0; z<BITS; z++) {
-		externs.b[z] = 0;
-		params.b[z] = 0;
-		addrs.b[z] = 0;
-	}
-	regbits = RtoB(0) |		/* return reg */
-		AtoB(6) | AtoB(7) |	/* sp and sb */
-		FtoB(0) | FtoB(1);	/* floating return reg */
-	for(i=0; i<NREG; i++) {
-		if(regused[i])
-			regbits |= RtoB(i);
-		if(fregused[i])
-			regbits |= FtoB(i);
-		if(aregused[i])
-			regbits |= AtoB(i);
-	}
-
-	/*
-	 * 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 ABRA:
-		case ARTS:
-		case ARTE:
-			r->p1 = R;
-			r1->s1 = R;
-		}
-
-		bit = mkvar(&p->from, AGOK);
-		if(bany(&bit))
-		switch(p->as) {
-		case ALEA:
-			if(!(mvbits & B_INDIR))
-			for(z=0; z<BITS; z++)
-				addrs.b[z] |= bit.b[z];
-
-		default:
-			if(mvbits & B_ADDR)
-			for(z=0; z<BITS; z++)
-				addrs.b[z] |= bit.b[z];
-			for(z=0; z<BITS; z++)
-				r->use1.b[z] |= bit.b[z];
-		}
-
-		bit = mkvar(&p->to, p->as);
-		if(bany(&bit))
-		switch(p->as) {
-		case ABSR:	/* funny */
-			for(z=0; z<BITS; z++)
-				addrs.b[z] |= bit.b[z];
-			goto def;
-
-		case APEA:
-			if(!(mvbits & B_INDIR))
-			for(z=0; z<BITS; z++)
-				addrs.b[z] |= bit.b[z];
-
-		def:
-		case ACMPB: case ACMPW: case ACMPL:
-		case AFCMPF: case AFCMPD:
-		case ATSTB: case ATSTW: case ATSTL:
-		case AFTSTF: case AFTSTD:
-		case ABFEXTU: case ABFEXTS:
-			if(mvbits & B_ADDR)
-			for(z=0; z<BITS; z++)
-				addrs.b[z] |= bit.b[z];
-			for(z=0; z<BITS; z++)
-				r->use2.b[z] |= bit.b[z];
-			break;
-
-		default:
-			diag(Z, "reg: unknown asop: %A", p->as);
-
-		case AADDB: case AADDW: case AADDL:
-		case ASUBB: case ASUBW: case ASUBL:
-		case AANDB: case AANDW: case AANDL:
-		case AORB: case AORW: case AORL:
-		case AEORB: case AEORW: case AEORL:
-		case ABFINS:
-			for(z=0; z<BITS; z++)
-				r->use2.b[z] |= bit.b[z];
-
-		case ANOP:
-		case AMOVB: case AMOVW: case AMOVL:
-		case AFMOVEB: case AFMOVEW: case AFMOVEL:
-		case ACLRB: case ACLRW: case ACLRL:
-		case AFMOVEF: case AFMOVED:
-			if(mvbits & B_INDIR)
-			for(z=0; z<BITS; z++)
-				r->use2.b[z] |= bit.b[z];
-			else
-			for(z=0; z<BITS; z++)
-				r->set.b[z] |= bit.b[z];
-			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) {
-				diag(Z, "ref not found\n%L:%P", p->lineno, p);
-				continue;
-			}
-			if(r1 == r) {
-				diag(Z, "ref to self");
-				continue;
-			}
-			r->s2 = r1;
-			r->p2link = r1->p2;
-			r1->p2 = r;
-		}
-	}
-	if(debug['R'])
-		print("\n%L %D\n", firstr->prog->lineno, &firstr->prog->from);
-
-	/*
-	 * pass 2.5
-	 * find looping structure
-	 */
-	for(r = firstr; r != R; r = r->link)
-		r->active = 0;
-	changer = 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:
-	changer = 0;
-	for(r = firstr; r != R; r = r->link)
-		r->active = 0;
-	for(r = firstr; r != R; r = r->link)
-		if(r->prog->as == ARTS)
-			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(changer)
-		goto loop1;
-
-	/*
-	 * pass 4
-	 * iterate propagating register/variable synchrony
-	 * 	forward until graph is complete
-	 */
-loop2:
-	changer = 0;
-	for(r = firstr; r != R; r = r->link)
-		r->active = 0;
-	synch(firstr, zbits);
-	if(changer)
-		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]);
-		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);
-
-			/*
-			 * 68040 'feature':
-			 *	load of a denormalized fp will trap
-			 */
-			while(bany(&bit)) {
-				i = bnum(bit);
-				bit.b[i/32] &= ~(1L << (i%32));
-				v = var + i;
-				if(v->type == D_AUTO) {
-					r->set.b[i/32] |= (1L << (i%32));
-					if(typefd[v->etype])
-						addmove(r, i, NREG+NREG, 1);
-				}
-			}
-		}
-	}
-	if(debug['R'] && debug['v'])
-		print("\nprop structure:\n");
-	for(r = firstr; r != R; r = r->link) {
-		if(debug['R'] && debug['v'])
-			print("%P\n	set = %B; rah = %B; cal = %B\n",
-				r->prog, r->set, r->refahead, r->calahead);
-		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 an 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;
-			changer = 0;
-			changea = 0;
-			if(debug['R'] && debug['v'])
-				print("\n");
-			paint1(r, i);
-			bit.b[i/32] &= ~(1L<<(i%32));
-			if(changer <= 0 && changea <= 0) {
-				if(debug['R'])
-					print("%L$%d.%d: %B\n",
-						r->prog->lineno,
-						changer, changea, blsh(i));
-				continue;
-			}
-			rgp->costr = changer;
-			rgp->costa = changea;
-			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.%d %R: %B\n",
-				rgp->enter->prog->lineno,
-				rgp->costr, rgp->costa,
-				rgp->regno,
-				bit);
-		if(rgp->regno != D_NONE)
-			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;
-	Var *v;
-	int badccr;
-
-	badccr = 0;
-	p = r->prog;
-	p1 = p->link;
-	if(p1)
-	switch(p1->as) {
-	case AMOVW:
-		if(p1->from.type == D_CCR)
-			p = p1;
-		break;
-
-	case ABEQ:
-	case ABNE:
-	case ABLE:
-	case ABLS:
-	case ABLT:
-	case ABMI:
-	case ABGE:
-	case ABPL:
-	case ABGT:
-	case ABHI:
-	case ABCC:
-	case ABCS:
-		p1 = prg();
-		p1->link = p->link;
-		p->link = p1;
-		p1->lineno = p->lineno;
-
-		p1->from.type = D_CCR;
-		p1->to.type = D_TOS;
-		p1->as = AMOVW;
-		p = p1;
-		badccr = 1;
-	}
-	p1 = prg();
-	p1->link = p->link;
-	p->link = p1;
-	p1->lineno = p->lineno;
-
-	v = var + bn;
-	p1->from.sym = v->sym;
-	p1->from.type = v->type;
-	p1->from.offset = v->offset;
-	p1->from.etype = v->etype;
-	p1->to.type = rn;
-	if(f) {
-		p1->to = p1->from;
-		p1->from = zprog.from;
-		p1->from.type = rn;
-	}
-	p1->as = opxt[OAS][v->etype];
-	if(badccr) {
-		p = p1;
-		p1 = prg();
-		p1->link = p->link;
-		p->link = p1;
-		p1->lineno = p->lineno;
-
-		p1->from.type = D_TOS;
-		p1->to.type = D_CCR;
-		p1->as = AMOVW;
-	}
-	if(debug['R'])
-		print("%P\t.a%P\n", p, p1);
-}
-
-Bits
-mkvar(Adr *a, int as)
-{
-	Var *v;
-	int i, t, z;
-	long o;
-	Bits bit;
-	Sym *s;
-
-	mvbits = 0;
-	t = a->type & D_MASK;
-	switch(t) {
-
-	default:
-		if(t >= D_R0 && t < D_R0+NREG) {
-			regbits |= RtoB(t-D_R0);
-			if(as == ADIVUL || as == ADIVSL)
-				regbits |= RtoB(t-D_R0+1);
-		}
-		if(t >= D_A0 && t < D_A0+NREG)
-			regbits |= AtoB(t-D_A0);
-		if(t >= D_F0 && t < D_F0+NREG)
-			regbits |= FtoB(t-D_F0);
-		goto none;
-
-	case D_EXTERN:
-	case D_STATIC:
-	case D_AUTO:
-	case D_PARAM:
-		break;
-	}
-	s = a->sym;
-	if(s == S)
-		goto none;
-
-	if((a->type & I_MASK) == I_ADDR)
-		mvbits |= B_ADDR;
-
-	switch(a->index & I_MASK) {
-	case I_INDEX1:
-		mvbits |= B_ADDR;
-		break;
-
-	case I_INDEX2:
-	case I_INDEX3:
-		mvbits |= B_INDIR;
-		break;
-	}
-
-	o = a->offset;
-	v = var;
-	for(i=0; i<nvar; i++) {
-		if(s == v->sym)
-		if(t == v->type)
-		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 = a->etype;
-	v->type = t;
-	if(debug['R'])
-		print("bit=%2d et=%2d %s (%p,%d,%ld)\n",
-			i, a->etype, s->name,
-			v->sym, v->type, v->offset);
-
-out:
-	bit = blsh(i);
-	if(t == D_EXTERN || t == D_STATIC)
-		for(z=0; z<BITS; z++)
-			externs.b[z] |= bit.b[z];
-	if(t == D_PARAM)
-		for(z=0; z<BITS; z++)
-			params.b[z] |= bit.b[z];
-	if(a->etype != v->etype || !typechlpfd[a->etype])
-		for(z=0; z<BITS; z++)
-			addrs.b[z] |= bit.b[z];	/* funny punning */
-	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];
-				changer++;
-			}
-			cal.b[z] |= r1->calahead.b[z];
-			if(cal.b[z] != r1->calahead.b[z]) {
-				r1->calahead.b[z] = cal.b[z];
-				changer++;
-			}
-		}
-		switch(r1->prog->as) {
-		case ABSR:
-			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 ARTS:
-			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
- */
-long
-postorder(Reg *r, Reg **rpo2r, long 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;
-}
-
-long
-rpolca(long *idom, long rpo1, long rpo2)
-{
-	long 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(long *idom, long r, long s)
-{
-	while(s > r)
-		s = idom[s];
-	return s == r;
-}
-
-int
-loophead(long *idom, Reg *r)
-{
-	long 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, long 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, long nr)
-{
-	Reg *r1;
-	long i, d, me;
-
-	if(nr > maxnr) {
-		rpo2r = alloc(nr * sizeof(Reg*));
-		idom = alloc(nr * sizeof(long));
-		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];
-				changer++;
-			}
-		}
-		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);
-	}
-}
-
-ulong
-allreg(ulong b, Rgn *r)
-{
-	Var *v;
-	int i, j;
-
-	v = var + r->varno;
-	r->regno = D_NONE;
-	switch(v->etype) {
-
-	default:
-		diag(Z, "unknown etype");
-		break;
-
-	case TCHAR:
-	case TUCHAR:
-	case TSHORT:
-	case TUSHORT:
-	case TINT:
-	case TUINT:
-	case TLONG:
-	case TULONG:
-	case TIND:
-		i = BtoR(~b);
-		j = BtoA(~b);
-		if(r->costa == r->costr)
-			if(i > j)
-				i = NREG;
-		if(j < NREG && r->costa > 0)
-		if(r->costa > r->costr || i >= NREG) {
-			r->regno = D_A0 + j;
-			return AtoB(j);
-		}
-		if(i < NREG && r->costr > 0) {
-			r->regno = D_R0 + i;
-			return RtoB(i);
-		}
-		break;
-
-	case TDOUBLE:
-	case TFLOAT:
-		i = BtoF(~b);
-		if(i < NREG) {
-			r->regno = D_F0 + i;
-			return FtoB(i);
-		}
-		break;
-	}
-	return 0;
-}
-
-void
-paint1(Reg *r, int bn)
-{
-	Reg *r1;
-	Prog *p;
-	int z;
-	ulong bb;
-	int x;
-
-	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) {
-		changer -= CLOAD * r->loop;
-		changea -= CLOAD * r->loop;
-		if(debug['R'] && debug['v'])
-			print("%ld%P\tld %B $%d.%d\n", r->loop,
-				r->prog, blsh(bn), changer, changea);
-	}
-	for(;;) {
-		r->act.b[z] |= bb;
-		p = r->prog;
-
-		if(r->use1.b[z] & bb) {
-			changer += CREF * r->loop;
-			changea += CREF * r->loop;
-			x = p->from.index;
-			if(x == D_NONE) {
-				switch(p->as) {
-				default:
-					changea = -CINF;
-				case AADDL:
-				case ASUBL:
-				case AMOVL:
-				case ACMPL:
-					break;
-				}
-			} else {
-				changer += (CXREF-CREF) * r->loop;
-				if(x != (I_INDEX3|D_NONE))
-					changer = -CINF;
-				if((x&I_MASK) == I_INDEX1)
-					changea = -CINF;
-			}
-			if(p->as == AMOVL) {
-				x = p->to.type;
-				if(x >= D_R0 && x < D_R0+NREG)
-					changer += r->loop;
-				if(x >= D_A0 && x < D_A0+NREG)
-					changea += r->loop;
-			}
-			if(debug['R'] && debug['v'])
-				print("%ld%P\tu1 %B $%d.%d\n", r->loop,
-					p, blsh(bn), changer, changea);
-		}
-		if((r->use2.b[z]|r->set.b[z]) & bb) {
-			changer += CREF * r->loop;
-			changea += CREF * r->loop;
-			x = p->to.index;
-			if(x == D_NONE)
-				switch(p->as) {
-				default:
-					changea = -CINF;
-					break;
-				case AMOVL:
-				case AADDL:
-				case ACMPL:
-				case ASUBL:
-				case ACLRL:	/* can be faked */
-				case ATSTL:	/* can be faked */
-					break;
-				}
-			else {
-				changer += (CXREF-CREF) * r->loop;
-				if(x != (I_INDEX3|D_NONE))
-					changer = -CINF;
-				if((x&I_MASK) == I_INDEX1)
-					changea = -CINF;
-			}
-			if(p->as == AMOVL) {
-				x = p->from.type;
-				if(x >= D_R0 && x < D_R0+NREG)
-					changer += r->loop;
-				if(x >= D_A0 && x < D_A0+NREG)
-					changea += r->loop;
-			}
-			if(debug['R'] && debug['v'])
-				print("%ld%P\tu2 %B $%d.%d\n", r->loop,
-					p, blsh(bn), changer, changea);
-		}
-		if(STORE(r) & r->regdiff.b[z] & bb) {
-			changer -= CLOAD * r->loop;
-			changea -= CLOAD * r->loop;
-			if(debug['R'] && debug['v'])
-				print("%ld%P\tst %B $%d.%d\n", r->loop,
-					p, blsh(bn), changer, changea);
-		}
-
-		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;
-	}
-}
-
-ulong
-paint2(Reg *r, int bn)
-{
-	Reg *r1;
-	int z;
-	ulong 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, ulong rb, int rn)
-{
-	Reg *r1;
-	Prog *p;
-	int z;
-	ulong 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)
-{
-	int x;
-
-	a->sym = 0;
-	x = a->index;
-	if(rn >= D_R0 && rn < D_R0+NREG)
-		goto addr;
-	if(x == (I_INDEX3|D_NONE)) {
-		a->type = rn | I_INDIR;
-		a->index = D_NONE;
-		a->offset = a->displace;
-		a->displace = 0;
-		return;
-	}
-	if(x != D_NONE) {
-		a->type = rn | I_INDIR;
-		a->index += I_INDEX1 - I_INDEX2;
-		a->offset = a->displace;
-		a->displace = 0;
-		return;
-	}
-	a->type = rn | (a->type & I_INDIR);
-	return;
-
-addr:
-	if(x == (I_INDEX3|D_NONE)) {
-		a->type = D_NONE|I_INDIR;
-		a->index += I_INDEX1 + rn - D_NONE - I_INDEX3;
-		a->scale = 4;	/* .L*1 */
-		a->offset = a->displace;
-		a->displace = 0;
-		return;
-	}
-	a->type = rn | (a->type & I_INDIR);
-}
-
-/*
- *	bit	reg
- *	0-7	R0-R7
- *	8-15	A0-A7
- *	16-23	F0-F7
- */
-ulong
-RtoB(int r)
-{
-
-	if(r < 0 || r >= NREG)
-		return 0;
-	return 1L << (r + 0);
-}
-
-int
-BtoR(ulong b)
-{
-
-	b &= 0x0000ffL;
-	if(b == 0)
-		return NREG;
-	return bitno(b) - 0;
-}
-
-ulong
-AtoB(int a)
-{
-
-	if(a < 0 || a >= NREG)
-		return 0;
-	return 1L << (a + NREG);
-}
-
-int
-BtoA(ulong b)
-{
-
-	b &= 0x00ff00L;
-	if(b == 0)
-		return NREG;
-	return bitno(b) - NREG;
-}
-
-ulong
-FtoB(int f)
-{
-
-	if(f < 0 || f >= NREG)
-		return 0;
-	return 1L << (f + NREG+NREG);
-}
-
-int
-BtoF(ulong b)
-{
-
-	b &= 0xff0000L;
-	if(b == 0)
-		return NREG;
-	return bitno(b) - NREG-NREG;
-}

+ 0 - 839
sys/src/cmd/2c/sgen.c

@@ -1,839 +0,0 @@
-#include "gc.h"
-
-void
-codgen(Node *n, Node *nn)
-{
-	Prog *sp;
-
-	argoff = 0;
-	inargs = 0;
-	for(;; nn = nn->left) {
-		if(nn == Z) {
-			diag(Z, "cant find function name");
-			return;
-		}
-		if(nn->op == ONAME)
-			break;
-	}
-	nearln = nn->lineno;
-	gpseudo(ATEXT, nn->sym, D_CONST, stkoff);
-	sp = p;
-
-	retok = 0;
-	gen(n);
-	if(!retok)
-		if(thisfn->link->etype != TVOID)
-			warn(Z, "no return at end of function: %s", nn->sym->name);
-
-	noretval(3);
-	gbranch(ORETURN);
-	if(!debug['N'] || debug['R'] || debug['P'])
-		regopt(sp);
-}
-
-void
-gen(Node *n)
-{
-	Node *l;
-	Prog *sp, *spc, *spb;
-	Case *cn;
-	long sbc, scc;
-	int snbreak;
-	int g, o;
-
-loop:
-	if(n == Z)
-		return;
-	nearln = n->lineno;
-	o = n->op;
-	if(debug['G'])
-		if(o != OLIST)
-			print("%L %O\n", nearln, o);
-
-	retok = 0;
-	switch(o) {
-
-	default:
-		complex(n);
-		doinc(n, PRE);
-		cgen(n, D_NONE, n);
-		doinc(n, POST);
-		break;
-
-	case OLIST:
-		gen(n->left);
-
-	rloop:
-		n = n->right;
-		goto loop;
-
-	case ORETURN:
-		retok = 1;
-		complex(n);
-		if(n->type == T)
-			break;
-		l = n->left;
-		if(l == Z) {
-			noretval(3);
-			gbranch(ORETURN);
-			break;
-		}
-		doinc(l, PRE);
-		if(typesuv[n->type->etype]) {
-			sugen(l, D_TREE, nodret, n->type->width);
-			doinc(l, POST);
-			noretval(3);
-			gbranch(ORETURN);
-			break;
-		}
-		g = regalloc(n->type, regret(n->type));
-		cgen(l, g, n);
-		doinc(l, POST);
-		if(typefd[n->type->etype])
-			noretval(1);
-		else
-			noretval(2);
-		gbranch(ORETURN);
-		regfree(g);
-		break;
-
-	case OLABEL:
-		l = n->left;
-		if(l) {
-			l->xoffset = pc;
-			if(l->label)
-				patch(l->label, pc);
-		}
-		gbranch(OGOTO);	/* prevent self reference in reg */
-		patch(p, pc);
-		goto rloop;
-
-	case OGOTO:
-		retok = 1;
-		n = n->left;
-		if(n == Z)
-			return;
-		if(n->complex == 0) {
-			diag(Z, "label undefined: %s", n->sym->name);
-			return;
-		}
-		gbranch(OGOTO);
-		if(n->xoffset) {
-			patch(p, n->xoffset);
-			return;
-		}
-		if(n->label)
-			patch(n->label, pc-1);
-		n->label = p;
-		return;
-
-	case OCASE:
-		l = n->left;
-		if(cases == C)
-			diag(n, "case/default outside a switch");
-		if(l == Z) {
-			casf();
-			cases->val = 0;
-			cases->def = 1;
-			cases->label = pc;
-			setsp();;
-			goto rloop;
-		}
-		complex(l);
-		if(l->type == T)
-			goto rloop;
-		if(l->op == OCONST)
-		if(typechl[l->type->etype]) {
-			casf();
-			cases->val = l->vconst;
-			cases->def = 0;
-			cases->label = pc;
-			setsp();
-			goto rloop;
-		}
-		diag(n, "case expression must be integer constant");
-		goto rloop;
-
-	case OSWITCH:
-		l = n->left;
-		complex(l);
-		doinc(l, PRE);
-		if(l->type == T)
-			break;
-		if(!typechl[l->type->etype]) {
-			diag(n, "switch expression must be integer");
-			break;
-		}
-		g = regalloc(types[TLONG], D_NONE);
-		n->type = types[TLONG];
-		cgen(l, g, n);
-		regfree(g);
-		doinc(l, POST);
-		setsp();
-		gbranch(OGOTO);		/* entry */
-		sp = p;
-
-		cn = cases;
-		cases = C;
-		casf();
-
-		sbc = breakpc;
-		breakpc = pc;
-		snbreak = nbreak;
-		nbreak = 0;
-		gbranch(OGOTO);
-		spb = p;
-
-		gen(n->right);
-		gbranch(OGOTO);
-		patch(p, breakpc);
-		nbreak++;
-
-		patch(sp, pc);
-		doswit(g, l);
-
-		patch(spb, pc);
-		cases = cn;
-		breakpc = sbc;
-		nbreak = snbreak;
-		setsp();
-		break;
-
-	case OWHILE:
-	case ODWHILE:
-		l = n->left;
-		gbranch(OGOTO);		/* entry */
-		sp = p;
-
-		scc = continpc;
-		continpc = pc;
-		gbranch(OGOTO);
-		spc = p;
-
-		sbc = breakpc;
-		breakpc = pc;
-		snbreak = nbreak;
-		nbreak = 0;
-		gbranch(OGOTO);
-		spb = p;
-
-		patch(spc, pc);
-		if(n->op == OWHILE)
-			patch(sp, pc);
-		bcomplex(l);	/* test */
-		patch(p, breakpc);
-		if(l->op != OCONST || vconst(l) == 0)
-			nbreak++;
-
-		if(n->op == ODWHILE)
-			patch(sp, pc);
-		gen(n->right);		/* body */
-		gbranch(OGOTO);
-		patch(p, continpc);
-
-		patch(spb, pc);
-		continpc = scc;
-		breakpc = sbc;
-		if(nbreak == 0)
-			retok = 1;
-		nbreak = snbreak;
-		break;
-
-	case OFOR:
-		l = n->left;
-		gen(l->right->left);	/* init */
-		gbranch(OGOTO);			/* entry */
-		sp = p;
-
-		scc = continpc;
-		continpc = pc;
-		gbranch(OGOTO);
-		spc = p;
-
-		sbc = breakpc;
-		breakpc = pc;
-		snbreak = nbreak;
-		nbreak = 0;
-		gbranch(OGOTO);
-		spb = p;
-
-		patch(spc, pc);
-		gen(l->right->right);	/* inc */
-		patch(sp, pc);	
-		if(l->left != Z) {	/* test */
-			bcomplex(l->left);
-			patch(p, breakpc);
-			if(l->left->op != OCONST || vconst(l->left) == 0)
-				nbreak++;
-		}
-		gen(n->right);		/* body */
-		gbranch(OGOTO);
-		patch(p, continpc);
-
-		patch(spb, pc);
-		continpc = scc;
-		breakpc = sbc;
-		if(nbreak == 0)
-			retok = 1;
-		nbreak = snbreak;
-		break;
-
-	case OCONTINUE:
-		if(continpc < 0) {
-			diag(n, "continue not in a loop");
-			break;
-		}
-		gbranch(OGOTO);
-		patch(p, continpc);
-		break;
-
-	case OBREAK:
-		if(breakpc < 0) {
-			diag(n, "break not in a loop");
-			break;
-		}
-		gbranch(OGOTO);
-		patch(p, breakpc);
-		nbreak++;
-		break;
-
-	case OIF:
-		l = n->left;
-		bcomplex(l);
-		sp = p;
-		if(n->right->left != Z)
-			gen(n->right->left);
-		if(n->right->right != Z) {
-			gbranch(OGOTO);
-			patch(sp, pc);
-			sp = p;
-			gen(n->right->right);
-		}
-		patch(sp, pc);
-		break;
-
-	case OSET:
-	case OUSED:
-		usedset(n->left, o);
-		break;
-	}
-}
-
-void
-usedset(Node *n, int o)
-{
-	if(n->op == OLIST) {
-		usedset(n->left, o);
-		usedset(n->right, o);
-		return;
-	}
-	complex(n);
-	switch(n->op) {
-	case OADDR:	/* volatile */
-		gopcode(OTST, types[TINT], D_TREE, n, D_NONE, Z);
-		p->as = ANOP;
-		break;
-	case ONAME:
-		if(o == OSET)
-			gopcode(OTST, types[TINT], D_NONE, Z, D_TREE, n);
-		else
-			gopcode(OTST, types[TINT], D_TREE, n, D_NONE, Z);
-		p->as = ANOP;
-		break;
-	}
-}
-
-void
-noretval(int n)
-{
-
-	if(n & 1) {
-		gopcode(OTST, types[TINT], D_NONE, Z, regret(types[TLONG]), Z);
-		p->as = ANOP;
-	}
-	if(n & 2) {
-		gopcode(OTST, types[TINT], D_NONE, Z, regret(types[TDOUBLE]), Z);
-		p->as = ANOP;
-	}
-}
-
-/*
- *	calculate addressability as follows
- *		REGISTER ==> 12		register
- *		NAME ==> 10/11		name+value(SB/SP)
- *		CONST ==> 20		$value
- *		*(20) ==> 21		value
- *		&(10) ==> 12		$name+value(SB)
- *		&(11) ==> 1		$name+value(SP)
- *		(12) + (20) ==> 12	fold constants
- *		(1) + (20) ==> 1	fold constants
- *		*(12) ==> 10		back to name
- *		*(1) ==> 11		back to name
- *
- *		(2,10,11) + (20) ==> 2	indirect w offset
- *		(2) ==> &13
- *		*(10,11) ==> 13		indirect, no index
- *
- *		(20) * (X) ==> 7	multiplier in indexing
- *		(X,7) + (12,1) ==> 8	adder in indexing (addresses)
- *		(X,7) + (10,11,2) ==> 8	adder in indexing (names)
- *		(8) ==> &9		index, almost addressable
- *
- *		(X)++ ==> X		fake addressability
- *
- *	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 OADDR:
-		xcom(l);
-		if(l->addable == 10)
-			n->addable = 12;
-		else
-		if(l->addable == 11)
-			n->addable = 1;
-		break;
-
-	case OADD:
-		xcom(l);
-		xcom(r);
-		if(n->type->etype != TIND)
-			break;
-
-		if(l->addable == 20)
-		switch(r->addable) {
-		case 12:
-		case 1:
-			n->addable = r->addable;
-			goto brk;
-		case 10:
-		case 11:
-		case 2:
-			goto addr13;
-		}
-		if(r->addable == 20)
-		switch(l->addable) {
-		case 12:
-		case 1:
-			n->addable = l->addable;
-			goto brk;
-		case 10:
-		case 11:
-		case 2:
-		addr13:
-			n->addable = 2;
-			l = new1(OXXX, Z, Z);
-			*l = *n;
-			n->op = OIND;
-			n->left = l;
-			n->right = Z;
-			n->addable = 13;
-			l = new1(OXXX, Z, Z);
-			*l = *n;
-			n->op = OADDR;
-			n->left = l;
-			n->right = Z;
-			n->addable = 2;
-			goto brk;
-		}
-
-		switch(r->addable) {
-		case 10:
-		case 11:
-		case 12:
-		case 1:
-			n->addable = 8;
-		}
-		switch(l->addable) {
-		case 10:
-		case 11:
-		case 12:
-		case 1:
-			n->addable = 8;
-		}
-		if(n->addable == 8) {
-			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 = 0;
-			break;
-		}
-		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 12:
-			n->addable = 10;
-			break;
-		case 10:
-		case 11:
-		case 2:
-			n->addable = 13;
-			break;
-		}
-		break;
-
-	case OASHL:
-		xcom(l);
-		xcom(r);
-		if(typev[n->type->etype])
-			break;
-		g = vconst(r);
-		if(g >= 0 && g < 4)
-			n->addable = 7;
-		break;
-
-	case OMUL:
-	case OLMUL:
-		xcom(l);
-		xcom(r);
-		if(typev[n->type->etype])
-			break;
-		g = vlog(r);
-		if(g >= 0) {
-			n->op = OASHL;
-			r->vconst = g;
-			if(g < 4)
-				n->addable = 7;
-			break;
-		}
-		g = vlog(l);
-		if(g >= 0) {
-			n->left = r;
-			n->right = l;
-			l = r;
-			r = n->right;
-			n->op = OASHL;
-			r->vconst = g;
-			if(g < 4)
-				n->addable = 7;
-			break;
-		}
-		break;
-
-	case ODIV:
-	case OLDIV:
-		xcom(l);
-		xcom(r);
-		if(typev[n->type->etype])
-			break;
-		g = vlog(r);
-		if(g >= 0) {
-			if(n->op == ODIV)
-				n->op = OASHR;
-			else
-				n->op = OLSHR;
-			r->vconst = g;
-		}
-		break;
-
-	case OSUB:
-		xcom(l);
-		xcom(r);
-		if(typev[n->type->etype])
-			break;
-		if(vconst(l) == 0) {
-			n->op = ONEG;
-			n->left = r;
-			n->right = Z;
-		}
-		break;
-
-	case OXOR:
-		xcom(l);
-		xcom(r);
-		if(typev[n->type->etype])
-			break;
-		if(vconst(l) == -1) {
-			n->op = OCOM;
-			n->left = r;
-			n->right = Z;
-		}
-		break;
-
-	case OASMUL:
-	case OASLMUL:
-		xcom(l);
-		xcom(r);
-		if(typev[n->type->etype])
-			break;
-		g = vlog(r);
-		if(g >= 0) {
-			n->op = OASASHL;
-			r->vconst = g;
-		}
-		goto aseae;
-
-	case OASDIV:
-	case OASLDIV:
-		xcom(l);
-		xcom(r);
-		if(typev[n->type->etype])
-			break;
-		g = vlog(r);
-		if(g >= 0) {
-			if(n->op == OASDIV)
-				n->op = OASASHR;
-			else
-				n->op = OASLSHR;
-			r->vconst = g;
-		}
-		goto aseae;
-
-	case OASLMOD:
-	case OASMOD:
-		xcom(l);
-		xcom(r);
-		if(typev[n->type->etype])
-			break;
-
-	aseae:		/* hack that there are no byte/short mul/div operators */
-		if(n->type->etype == TCHAR || n->type->etype == TSHORT) {
-			n->right = new1(OCAST, n->right, Z);
-			n->right->type = types[TLONG];
-			n->type = types[TLONG];
-		}
-		if(n->type->etype == TUCHAR || n->type->etype == TUSHORT) {
-			n->right = new1(OCAST, n->right, Z);
-			n->right->type = types[TULONG];
-			n->type = types[TULONG];
-		}
-		goto asop;
-
-	case OASXOR:
-	case OASOR:
-	case OASADD:
-	case OASSUB:
-	case OASLSHR:
-	case OASASHR:
-	case OASASHL:
-	case OASAND:
-	case OAS:
-		xcom(l);
-		xcom(r);
-		if(typev[n->type->etype])
-			break;
-
-	asop:
-		if(l->addable > INDEXED &&
-		   l->complex < FNX &&
-		   r && r->complex < FNX)
-			n->addable = l->addable;
-		break;
-
-	case OPOSTINC:
-	case OPREINC:
-	case OPOSTDEC:
-	case OPREDEC:
-		xcom(l);
-		if(typev[n->type->etype])
-			break;
-		if(l->addable > INDEXED &&
-		   l->complex < FNX)
-			n->addable = l->addable;
-		break;
-
-	default:
-		if(l != Z)
-			xcom(l);
-		if(r != Z)
-			xcom(r);
-		break;
-	}
-
-brk:
-	n->complex = 0;
-	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 OMUL:
-	case OLMUL:
-	case OXOR:
-	case OAND:
-	case OOR:
-		/*
-		 * symmetric operators, make right side simple
-		 * if same, put constant on left to get movq
-		 */
-		if(r->complex > l->complex ||
-		  (r->complex == l->complex && r->addable == 20)) {
-			n->left = r;
-			n->right = l;
-		}
-		break;
-
-	case OLE:
-	case OLT:
-	case OGE:
-	case OGT:
-	case OEQ:
-	case ONE:
-		/*
-		 * relational operators, make right side simple
-		 * if same, put constant on left to get movq
-		 */
-		if(r->complex > l->complex || r->addable == 20) {
-			n->left = r;
-			n->right = l;
-			n->op = invrel[relindex(n->op)];
-		}
-		break;
-	}
-}
-
-void
-indx(Node *n)
-{
-	Node *l, *r;
-	int t;
-
-	if(debug['x'])
-		prtree(n, "indx");
-	t = 0;
-
-loop:
-	l = n->left;
-	r = n->right;
-	switch(r->addable) {
-	default:
-		if(t) {
-			diag(n, "bad indx");
-			break;
-		}
-		n->right = l;
-		n->left = r;
-		t++;
-		goto loop;
-
-	case 10:
-	case 11:
-		if(l->op == ONAME && r->op == ONAME)
-		if(l->etype == TIND)
-		if(r->etype != TIND) {
-			n->right = l;
-			n->left = r;
-			goto loop;
-		}
-		if(l->addable == 1 || l->addable == 12) {
-			n->right = l;
-			n->left = r;
-			goto loop;
-		}
-
-	case 1:
-	case 12:
-		break;
-	}
-	if(l->addable != 7) {
-		idx.regtree = l;
-		idx.scale = 0;
-	} else
-	if(l->right->addable == 20) {
-		idx.regtree = l->left;
-		idx.scale = l->right->vconst;
-	} else {
-		idx.regtree = l->right;
-		idx.scale = l->left->vconst;
-	}
-	t = ewidth[idx.regtree->type->etype];
-	if(t == SZ_LONG)
-		idx.scale += 4;
-	else
-	if(t != SZ_SHORT)
-		diag(n, "index not W or L");
-
-	idx.basetree = r;
-	if(debug['x']) {
-		print("scale = %d\n", idx.scale);
-		prtree(idx.regtree, "index");
-		prtree(idx.basetree, "base");
-	}
-}
-
-void
-bcomplex(Node *n)
-{
-
-	complex(n);
-	if(n->type != T)
-	if(tcompat(n, T, n->type, tnot))
-		n->type = T;
-	if(n->type != T) {
-		bool64(n);
-		doinc(n, PRE);
-		boolgen(n, 1, D_NONE, Z, n);
-	} else
-		gbranch(OGOTO);
-}
-
-Node*
-nodconst(long v)
-{
-
-	return (Node*)v;
-}

+ 0 - 1046
sys/src/cmd/2c/swt.c

@@ -1,1046 +0,0 @@
-#include "gc.h"
-
-int
-swcmp(const void *a1, const void *a2)
-{
-	C1 *p1, *p2;
-
-	p1 = (C1*)a1;
-	p2 = (C1*)a2;
-	if(p1->val < p2->val)
-		return -1;
-	return p1->val > p2->val;
-}
-
-void
-doswit(int g, Node *n)
-{
-	Case *c;
-	C1 *q, *iq;
-	long def, nc, i;
-
-	def = 0;
-	nc = 0;
-	for(c = cases; c->link != C; c = c->link) {
-		if(c->def) {
-			if(def)
-				diag(n, "more than one default in switch");
-			def = c->label;
-			continue;
-		}
-		nc++;
-	}
-
-	iq = alloc(nc*sizeof(C1));
-	q = iq;
-	for(c = cases; c->link != C; c = c->link) {
-		if(c->def)
-			continue;
-		q->label = c->label;
-		q->val = c->val;
-		q++;
-	}
-	qsort(iq, nc, sizeof(C1), swcmp);
-	if(def == 0)
-		def = breakpc;
-	for(i=0; i<nc-1; i++)
-		if(iq[i].val == iq[i+1].val)
-			diag(n, "duplicate cases in switch %lld", iq[i].val);
-	swit1(iq, nc, def, g, n);
-}
-
-#define	N1	4	/* ncase: always linear */
-#define	N2	5	/* min ncase: direct */
-#define	N3	4	/* range/ncase: direct */
-			/* else binary */
-void
-swit1(C1 *q, int nc, long def, int g, Node *n)
-{
-	C1 *r, *s;
-	int i, l, m, y;
-	long v, range;
-	Prog *sp1, *sp2;
-
-	/* note that g and g+1 are not allocated */
-	if(nc <= N1)
-		goto linear;
-	y = 23*nc/100 + 5;	/* number of cases needed to make */
-	if(y < N2)		/* direct switch worthwile */
-		y = N2;				/* try to do better than n**2 here */
-	for(m=nc; m>=y; m--) {			/* m is number of cases */
-		s = q+nc;
-		r = s-m;
-		for(l=nc-m; l>=0; l--) {	/* l is base of contig cases */
-			s--;
-			range = s->val - r->val;
-			if(range > 0 && range <= N3*m)
-				goto direct;
-			r--;
-		}
-	}
-
-	/*
-	 * divide and conquer
-	 */
-	i = nc / 2;
-	r = q+i;
-	v = r->val;
-	/* compare median */
-	if(v >= -128 && v < 128) {
-		gopcode(OAS, n->type, D_CONST, nodconst(v), g+1, n);
-		gopcode(OEQ, n->type, g, n, g+1, n);
-	} else
-		gopcode(OEQ, n->type, g, n, D_CONST, nodconst(v));
-	gbranch(OLT);
-	sp1 = p;
-	gbranch(OGT);
-	sp2 = p;
-	gbranch(OGOTO);
-	patch(p, r->label);
-
-	patch(sp1, pc);
-	swit1(q, i, def, g, n);
-
-	patch(sp2, pc);
-	swit1(r+1, nc-i-1, def, g, n);
-	return;
-
-direct:
-	/* compare low bound */
-	v = r->val;
-	if(v >= -128 && v < 128) {
-		gopcode(OAS, n->type, D_CONST, nodconst(v), g+1, n);
-		gopcode(OEQ, n->type, g, n, g+1, n);
-	} else
-		gopcode(OEQ, n->type, g, n, D_CONST, nodconst(v));
-	gbranch(OLT);
-	sp1 = p;
-
-	/* compare high bound */
-	v = s->val;
-	if(v >= -128 && v < 128) {
-		gopcode(OAS, n->type, D_CONST, nodconst(v), g+1, n);
-		gopcode(OEQ, n->type, g, n, g+1, n);
-	} else
-		gopcode(OEQ, n->type, g, n, D_CONST, nodconst(v));
-	gbranch(OGT);
-	sp2 = p;
-
-	/* switch */
-	v = r->val;
-	gpseudo(AMOVW, symstatic, D_R0, 0L);
-	p->from.offset = nstatic - v*2;
-	p->from.index = g|I_INDEX1;
-	p->from.scale = 5;
-	nextpc();
-	p->as = ACASEW;
-
-	/* table */
-	for(i=0; i<=range; i++) {
-		gbranch(OCASE);
-		if(v == r->val) {
-			patch(p, r->label);
-			r++;
-		} else
-			patch(p, def);
-		p->from.type = D_STATIC;
-		p->from.sym = symstatic;
-		p->from.offset = nstatic;
-		nstatic += types[TSHORT]->width;
-		v++;
-	}
-	gbranch(OGOTO);
-	patch(p, def);
-	if(r != s+1)
-		print("smelly direct switch\n");
-
-	if(l > 0) {
-		patch(sp1, pc);
-		swit1(q, l, def, g, n);
-	} else
-		patch(sp1, def);
-
-	m += l;
-	if(m < nc) {
-		patch(sp2, pc);
-		swit1(q+m, nc-m, def, g, n);
-	} else
-		patch(sp2, def);
-	return;
-
-
-linear:
-	for(i=0; i<nc; i++) {
-		v = q->val;
-		if(v >= -128 && v < 128) {
-			gopcode(OAS, n->type, D_CONST, nodconst(v), g+1, n);
-			gopcode(OEQ, n->type, g+1, n, g, n);
-		} else
-			gopcode(OEQ, n->type, g, n, D_CONST, nodconst(v));
-		gbranch(OEQ);
-		patch(p, q->label);
-		q++;
-	}
-	gbranch(OGOTO);
-	patch(p, def);
-}
-
-void
-casf(void)
-{
-	Case *c;
-
-	c = alloc(sizeof(*c));
-	c->link = cases;
-	cases = c;
-}
-
-
-int
-bitload(Node *b, int n1, int n2, int n3, Node *nn)
-{
-	int sh, g, gs;
-	long v;
-	Node *l;
-	Type *t;
-
-	/*
-	 * n1 gets adjusted/masked value
-	 * n2 gets address of cell
-	 * n3 gets contents of cell
-	 */
-	gs = 0;
-	t = tfield;
-
-	l = b->left;
-	g = regalloc(t, n3);
-	if(n2 != D_NONE) {
-		lcgen(l, n2, Z);
-		n2 |= I_INDIR;
-		gmove(t, t, n2, l, g, l);
-		gmove(t, t, g, l, n1, l);
-	} else
-		cgen(l, g, nn);
-	if(b->type->shift == 0 && typeu[b->type->etype]) {
-		v = ~0 + (1L << b->type->nbits);
-		gopcode(OAND, t, D_CONST, nodconst(v), g, l);
-	} else {
-		sh = 32 - b->type->shift - b->type->nbits;
-		if(sh > 0)
-			if(sh >= 8) {
-				gs = regalloc(t, D_NONE);
-				gmove(t, t, D_CONST, nodconst(sh), gs, l);
-				gopcode(OASHL, t, gs, l, g, l);
-				if(b->type->shift)
-					regfree(gs);
-			} else
-				gopcode(OASHL, t, D_CONST, nodconst(sh), g, l);
-		sh += b->type->shift;
-		if(sh > 0) {
-			if(sh >= 8) {
-				if(b->type->shift) {
-					gs = regalloc(t, D_NONE);
-					gmove(t, t, D_CONST, nodconst(sh), gs, l);
-				}
-				if(typeu[b->type->etype])
-					gopcode(OLSHR, t, gs, l, g, l);
-				else
-					gopcode(OASHR, t, gs, l, g, l);
-				regfree(gs);
-			} else {
-				if(typeu[b->type->etype])
-					gopcode(OLSHR, t, D_CONST, nodconst(sh), g, l);
-				else
-					gopcode(OASHR, t, D_CONST, nodconst(sh), g, l);
-			}
-		}
-	}
-	return g;
-}
-
-void
-bitstore(Node *b, int n1, int n2, int n3, int result, Node *nn)
-{
-	long v;
-	Node *l;
-	Type *t;
-	int sh, g, gs;
-
-	/*
-	 * n1 has adjusted/masked value
-	 * n2 has address of cell
-	 * n3 has contents of cell
-	 */
-	t = tfield;
-
-	l = b->left;
-	g = regalloc(t, D_NONE);
-	v = ~0 + (1L << b->type->nbits);
-	gopcode(OAND, t, D_CONST, nodconst(v), n1, l);
-	gmove(t, t, n1, l, g, l);
-	if(result != D_NONE)
-		gmove(t, nn->type, n1, l, result, nn);
-	sh = b->type->shift;
-	if(sh > 0) {
-		if(sh >= 8) {
-			gs = regalloc(t, D_NONE);
-			gmove(t, t, D_CONST, nodconst(sh), gs, l);
-			gopcode(OASHL, t, gs, l, g, l);
-			regfree(gs);
-		} else
-			gopcode(OASHL, t, D_CONST, nodconst(sh), g, l);
-	}
-	v <<= sh;
-	gopcode(OAND, t, D_CONST, nodconst(~v), n3, l);
-	gopcode(OOR, t, n3, l, g, l);
-	gmove(t, t, g, l, n2|I_INDIR, l);
-
-	regfree(g);
-	regfree(n1);
-	regfree(n2);
-	regfree(n3);
-}
-
-long
-outstring(char *s, long n)
-{
-	long r;
-
-	r = nstring;
-	while(n) {
-		string[mnstring] = *s++;
-		mnstring++;
-		nstring++;
-		if(mnstring >= NSNAME) {
-			gpseudo(ADATA, symstring, D_SCONST, 0L);
-			memmove(p->to.sval, string, NSNAME);
-			p->from.offset = nstring - NSNAME;
-			p->from.displace = NSNAME;
-			mnstring = 0;
-		}
-		n--;
-	}
-	return r;
-}
-
-long
-outlstring(ushort *s, long n)
-{
-	char buf[2];
-	int c;
-	long r;
-
-	while(nstring & 1)
-		outstring("", 1);
-	r = nstring;
-	while(n > 0) {
-		c = *s++;
-		if(align(0, types[TCHAR], Aarg1)) {
-			buf[0] = c>>8;
-			buf[1] = c;
-		} else {
-			buf[0] = c;
-			buf[1] = c>>8;
-		}
-		outstring(buf, 2);
-		n -= sizeof(ushort);
-	}
-	return r;
-}
-
-int
-doinc(Node *n, int f)
-{
-	Node *l;
-	int a;
-
-loop:
-	if(n == Z)
-		return 0;
-	l = n->left;
-	switch(n->op) {
-
-	case OPOSTINC:
-	case OPOSTDEC:
-		if(f & POST) {
-			a = n->addable;
-			if(a >= INDEXED) {
-				if(f & TEST)
-					return 1;
-				n->addable = 0;
-				cgen(n, D_NONE, n);
-				n->addable = a;
-			}
-		}
-		break;
-
-	case OAS:
-	case OASLMUL:
-	case OASLDIV:
-	case OASLMOD:
-	case OASMUL:
-	case OASDIV:
-	case OASMOD:
-	case OASXOR:
-	case OASOR:
-	case OASADD:
-	case OASSUB:
-	case OASLSHR:
-	case OASASHR:
-	case OASASHL:
-	case OASAND:
-
-	case OPREINC:
-	case OPREDEC:
-		if(f & PRE) {
-			a = n->addable;
-			if(a >= INDEXED) {
-				if(f & TEST)
-					return 1;
-				n->addable = 0;
-				doinc(n, PRE);
-				cgen(n, D_NONE, n);
-				n->addable = a;
-				return 0;
-			}
-		}
-		break;
-
-	case OFUNC:
-		if(f & PRE)
-			break;
-		return 0;
-
-	case ONAME:
-	case OREGISTER:
-	case OSTRING:
-	case OCONST:
-
-	case OANDAND:
-	case OOROR:
-		return 0;
-
-	case OCOND:
-		return 0;
-
-	case OCOMMA:
-		n = n->right;
-		if(f & PRE)
-			n = l;
-		goto loop;
-	}
-	if(l != Z)
-		if(doinc(l, f))
-			return 1;
-	n = n->right;
-	goto loop;
-}
-
-void
-setsp(void)
-{
-
-	nextpc();
-	p->as = AADJSP;
-	p->from.type = D_CONST;
-	p->from.offset = 0;
-}
-
-void
-adjsp(long o)
-{
-
-	if(o != 0) {
-		nextpc();
-		p->as = AADJSP;
-		p->from.type = D_CONST;
-		p->from.offset = o;
-		argoff += o;
-	}
-}
-
-int
-simplv(Node *n)
-{
-
-	if(n->addable <= INDEXED)
-		return 0;
-	while(n->op == OIND)
-		n = n->left;
-	if(n->op == ONAME)
-		return 1;
-	return 0;
-}
-
-int
-eval(Node *n, int g)
-{
-
-	if(n->addable >= INDEXED)
-		return D_TREE;
-	g = regalloc(n->type, g);
-	cgen(n, g, n);
-	return g;
-}
-
-void	outhist(Biobuf*);
-void	zname(Biobuf*, Sym*, int);
-void	zaddr(Biobuf*, Adr*, int);
-void	zwrite(Biobuf*, Prog*, int, int);
-
-void
-outcode(void)
-{
-	struct { Sym *sym; short 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, "cant open %s", outfile);
-		errorexit();
-	}
-	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 & D_MASK;
-			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 & D_MASK;
-			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;
-		}
-		zwrite(&b, p, sf, st);
-	}
-	Bflush(&b);
-	close(f);
-	firstp = P;
-	lastp = P;
-}
-
-void
-zwrite(Biobuf *b, Prog *p, int sf, int st)
-{
-	long l;
-
-	l = p->as;
-	Bputc(b, l);
-	Bputc(b, l>>8);
-	l = p->lineno;
-	Bputc(b, l);
-	Bputc(b, l>>8);
-	Bputc(b, l>>16);
-	Bputc(b, l>>24);
-	zaddr(b, &p->from, sf);
-	zaddr(b, &p->to, st);
-}
-
-void
-zname(Biobuf *b, Sym *s, int t)
-{
-	char *n;
-	ulong 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)
-{
-	long l;
-	int i, t;
-	char *n;
-	Ieee e;
-
-	t = 0;
-	if(a->field)
-		t |= T_FIELD;
-	if(a->index != D_NONE)
-		t |= T_INDEX;
-	if(s)
-		t |= T_SYM;
-
-	switch(a->type) {
-	default:
-		if(a->offset)
-			t |= T_OFFSET;
-		if(a->displace)
-			t |= T_INDEX;
-		if(a->type & ~0xff)
-			t |= T_TYPE;
-		break;
-	case D_FCONST:
-		t |= T_FCONST;
-		break;
-	case D_SCONST:
-		t |= T_SCONST;
-		break;
-	}
-	Bputc(b, t);
-
-	if(t & T_FIELD) {	/* implies field */
-		i = a->field;
-		Bputc(b, i);
-		Bputc(b, i>>8);
-	}
-	if(t & T_INDEX) {	/* implies index, scale, displace */
-		i = a->index;
-		Bputc(b, i);
-		Bputc(b, i>>8);
-		Bputc(b, a->scale);
-		l = a->displace;
-		Bputc(b, l);
-		Bputc(b, l>>8);
-		Bputc(b, l>>16);
-		Bputc(b, l>>24);
-	}
-	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;
-	}
-	i = a->type;
-	Bputc(b, i);
-	if(t & T_TYPE)
-		Bputc(b, i>>8);
-}
-
-
-
-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;
-
-		zwrite(b, &pg, 0, 0);
-	}
-}
-
-void
-ieeedtod(Ieee *ieee, double native)
-{
-	double fr, ho, f;
-	int exp;
-
-	if(native < 0) {
-		ieeedtod(ieee, -native);
-		ieee->h |= 0x80000000L;
-		return;
-	}
-	if(native == 0) {
-		ieee->l = 0;
-		ieee->h = 0;
-		return;
-	}
-	fr = frexp(native, &exp);
-	f = 2097152L;		/* shouldnt use fp constants here */
-	fr = modf(fr*f, &ho);
-	ieee->h = ho;
-	ieee->h &= 0xfffffL;
-	ieee->h |= (exp+1022L) << 20;
-	f = 65536L;
-	fr = modf(fr*f, &ho);
-	ieee->l = ho;
-	ieee->l <<= 16;
-	ieee->l |= (long)(fr*f);
-}
-
-int
-nodalloc(Type *t, int g, Node *n)
-{
-
-	n->type = t;
-	n->op = OREGISTER;
-	n->addable = 12;
-	n->complex = 0;
-	g = regaddr(g);
-	n->reg = g | I_INDIR;
-	n->xoffset = 0;
-	return g;
-}
-
-int
-mulcon(Node *n, Node *c, int result, Node *nn)
-{
-	long v;
-
-	if(typefd[n->type->etype])
-		return 0;
-	v = c->vconst;
-	if(mulcon1(n, v, result, nn))
-		return 1;
-	return 0;
-}
-
-int
-shlcon(Node *n, Node *c, int result, Node *nn)
-{
-	long v;
-
-	v = 1L << c->vconst;
-	return mulcon1(n, v, result, nn);
-}
-
-int
-mulcon1(Node *n, long v, int result, Node *nn)
-{
-	int g, g1, a1, a2, neg;
-	int o;
-	char code[10], *p;
-
-	if(result == D_NONE)
-		return 0;
-	neg = 0;
-	if(v < 0) {
-		v = -v;
-		neg++;
-	}
-	a1 = 0;
-	a2 = multabsize;
-	for(;;) {
-		if(a1 >= a2)
-			return 0;
-		g1 = (a2 + a1)/2;
-		if(v < multab[g1].val) {
-			a2 = g1;
-			continue;
-		}
-		if(v > multab[g1].val) {
-			a1 = g1+1;
-			continue;
-		}
-		break;
-	}
-	strcpy(code, "0");
-	strncat(code, multab[g1].code, sizeof(multab[0].code));
-	p = code;
-	if(p[1] == 'i')
-		p += 2;
-	g = regalloc(n->type, result);
-	cgen(n, g, n);
-	if(neg)
-		gopcode(ONEG, n->type, D_NONE, n, g, n);
-	g1 = regalloc(n->type, D_NONE);
-loop:
-	switch(*p) {
-	case 0:
-		regfree(g1);
-		gmove(n->type, nn->type, g, n, result, nn);
-		regfree(g);
-		return 1;
-	case '0':
-		o = OAS;
-		*p -= '0';
-		goto com;
-	case '1':
-	case '2':
-		o = OSUB;
-		*p -= '1';
-		goto com;
-	case '3':
-	case '4':
-	case '5':
-	case '6':
-		o = OADD;
-		*p -= '3';
-	com:
-		a1 = g;
-		if(*p == 1 || *p == 3)
-			a1 = g1;
-		a2 = g;
-		if(*p == 0 || *p == 3)
-			a2 = g1;
-		gopcode(o, n->type, a1, n, a2, n);
-		p++;
-		break;
-	default:
-		a1 = *p++ - 'a' + 1;
-		a2 = g;
-		if(a1 > 8) {
-			a2 = g1;
-			a1 -= 8;
-		}
-		gopcode(OASHL, n->type, D_CONST, nodconst(a1), a2, n);
-		break;
-	}
-	goto loop;
-}
-
-void
-nullwarn(Node *l, Node *r)
-{
-	warn(Z, "result of operation not used");
-	if(l != Z)
-		cgen(l, D_NONE, Z);
-	if(r != Z)
-		cgen(r, D_NONE, Z);
-}
-
-void
-sextern(Sym *s, Node *a, long o, long w)
-{
-	long e, lw;
-
-	for(e=0; e<w; e+=NSNAME) {
-		lw = NSNAME;
-		if(w-e < lw)
-			lw = w-e;
-		gpseudo(ADATA, s, D_SCONST, 0L);
-		p->from.offset += o+e;
-		p->from.displace = lw;
-		memmove(p->to.sval, a->cstring+e, lw);
-	}
-}
-
-void
-gextern(Sym *s, Node *a, long o, long w)
-{
-	if(a->op == OCONST && typev[a->type->etype]) {
-		gpseudo(ADATA, s, D_CONST, (long)(a->vconst>>32));
-		p->from.offset += o;
-		p->from.displace = 4;
-		gpseudo(ADATA, s, D_CONST, (long)(a->vconst));
-		p->from.offset += o + 4;
-		p->from.displace = 4;
-		return;
-	}
-	gpseudotree(ADATA, s, a);
-	p->from.offset += o;
-	p->from.displace = w;
-}
-
-long
-align(long i, Type *t, int op)
-{
-	long 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_SHORT)
-			w = SZ_SHORT;
-		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;
-		}
-		o += SZ_LONG - w;	/* big endian adjustment */
-		w = 1;
-		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;
-}
-
-long
-maxround(long max, long v)
-{
-	v += SZ_LONG-1;
-	if(v > max)
-		max = round(v, SZ_LONG);
-	return max;
-}

+ 0 - 940
sys/src/cmd/2c/txt.c

@@ -1,940 +0,0 @@
-#include "gc.h"
-
-void
-tindex(Type *tf, Type *tt)
-{
-	int i, j;
-
-	j = 0;
-	if(tt != T) {
-		j = tt->etype;
-		if(j >= NTYPE)
-			j = 0;
-	}
-	i = 0;
-	if(tf != T) {
-		i = tf->etype;
-		if(i >= NTYPE)
-			if(typesu[i])
-				i = j;
-			else
-				i = 0;
-	}
-	txtp = &txt[i][j];
-}
-
-void
-ginit(void)
-{
-	int i, j, si, sj;
-
-	thestring = "68020";
-	thechar = '2';
-	exregoffset = 7;
-	exaregoffset = 5;
-	exfregoffset = 7;
-	listinit();
-	for(i=0; i<NREG; i++) {
-		regused[i] = 0;
-		fregused[i] = 0;
-		aregused[i] = 0;
-	}
-	regaddr(D_A0+6);
-	regaddr(D_A0+7);
-	for(i=0; i<sizeof(regbase); i++)
-		regbase[i] = D_NONE;
-	for(i=0; i<NREG; i++) {
-		regbase[D_R0+i] = D_R0+i;
-		regbase[D_A0+i] = D_A0+i;
-		regbase[D_F0+i] = D_F0+i;
-	}
-	regbase[D_TOS] = D_TOS;
-
-	for(i=0; i<NTYPE; i++)
-	for(j=0; j<NTYPE; j++) {
-		txtp = &txt[i][j];
-		txtp->movas = AGOK;
-		txtp->preclr = 0;
-		txtp->postext = AGOK;
-		if(!(typechlp[i] && typechlp[j]))
-			continue;
-		si = types[i]->width;
-		sj = types[j]->width;
-		if(sj < si)
-			txtp->preclr = -1;
-		if(sj > si) {
-			if(typeu[i]) {
-				txtp->preclr = 1;
-			} else {
-				if(sj == 2)
-					txtp->postext = AEXTBW;
-				if(sj == 4)
-					if(si == 1)
-						txtp->postext = AEXTBL;
-					else
-						txtp->postext = AEXTWL;
-			}
-			sj = si;
-		}
-		if(sj == 1)
-			txtp->movas = AMOVB;
-		if(sj == 2)
-			txtp->movas = AMOVW;
-		if(sj == 4)
-			txtp->movas = AMOVL;
-	}
-
-	for(i=0; i<ALLOP; i++)
-		for(j=0; j<NTYPE; j++)
-			opxt[i][j] = AGOK;
-	oinit(OFUNC, ABSR, ATRAP, AGOK, AGOK, AGOK);
-
-	oinit(OAS, AMOVB, AMOVW, AMOVL, AFMOVEF, AFMOVED);
-	oinit(OFAS, AFMOVEB, AFMOVEW, AFMOVEL, AFMOVEF, AFMOVED);
-	oinit(OADDR, AGOK, APEA, ALEA, AGOK, AGOK);
-	oinit(OPREINC, AADDB, AADDW, AADDL, AFADDF, AFADDD);
-	oinit(OPOSTINC, AADDB, AADDW, AADDL, AFADDF, AFADDD);
-	oinit(OPREDEC, ASUBB, ASUBW, ASUBL, AFSUBF, AFSUBD);
-	oinit(OPOSTDEC, ASUBB, ASUBW, ASUBL, AFSUBF, AFSUBD);
-	oinit(OADD, AADDB, AADDW, AADDL, AFADDF, AFADDD);
-	oinit(OASADD, AADDB, AADDW, AADDL, AFADDF, AFADDD);
-	oinit(OSUB, ASUBB, ASUBW, ASUBL, AFSUBF, AFSUBD);
-	oinit(OASSUB, ASUBB, ASUBW, ASUBL, AFSUBF, AFSUBD);
-	oinit(OMUL, AGOK, AMULSW, AMULSL, AFMULF, AFMULD);
-	oinit(OLMUL, AGOK, AMULSW, AMULSL, AFMULF, AFMULD);
-	oinit(OASMUL, AGOK, AMULSW, AMULSL, AFMULF, AFMULD);
-	oinit(OASLMUL, AGOK, AMULSW, AMULSL, AFMULF, AFMULD);
-	oinit(ODIV, AGOK, ADIVSW, ADIVSL, AFDIVF, AFDIVD);
-	oinit(OLDIV, AGOK, ADIVUW, ADIVUL, AFDIVF, AFDIVD);
-	oinit(OASDIV, AGOK, ADIVSW, ADIVSL, AFDIVF, AFDIVD);
-	oinit(OASLDIV, AGOK, ADIVUW, ADIVUL, AFDIVF, AFDIVD);
-	oinit(OMOD, AGOK, ADIVSW, ADIVSL, AFMODF, AFMODD);
-	oinit(OASMOD, AGOK, ADIVSW, ADIVSL, AGOK, AGOK);
-	oinit(OLMOD, AGOK, ADIVUW, ADIVUL, AGOK, AGOK);
-	oinit(OASLMOD, AGOK, ADIVUW, ADIVUL, AGOK, AGOK);
-	oinit(OAND, AANDB, AANDW, AANDL, AGOK, AGOK);
-	oinit(OASAND, AANDB, AANDW, AANDL, AGOK, AGOK);
-	oinit(OOR, AORB, AORW, AORL, AGOK, AGOK);
-	oinit(OASOR, AORB, AORW, AORL, AGOK, AGOK);
-	oinit(OXOR, AEORB, AEORW, AEORL, AGOK, AGOK);
-	oinit(OASXOR, AEORB, AEORW, AEORL, AGOK, AGOK);
-	oinit(ONEG, ANEGB, ANEGW, ANEGL, AFNEGF, AFNEGD);
-	oinit(OCOM, ANOTB, ANOTW, ANOTL, AGOK, AGOK);
-	oinit(OTST, ATSTB, ATSTW, ATSTL, AFTSTF, AFTSTD);
-	oinit(OEQ, ACMPB, ACMPW, ACMPL, AFCMPF, AFCMPD);
-	oinit(ONE, ACMPB, ACMPW, ACMPL, AFCMPF, AFCMPD);
-	oinit(OGE, ACMPB, ACMPW, ACMPL, AFCMPF, AFCMPD);
-	oinit(OGT, ACMPB, ACMPW, ACMPL, AFCMPF, AFCMPD);
-	oinit(OLT, ACMPB, ACMPW, ACMPL, AFCMPF, AFCMPD);
-	oinit(OLE, ACMPB, ACMPW, ACMPL, AFCMPF, AFCMPD);
-	oinit(OLS, ACMPB, ACMPW, ACMPL, AFCMPF, AFCMPD);
-	oinit(OLO, ACMPB, ACMPW, ACMPL, AFCMPF, AFCMPD);
-	oinit(OHS, ACMPB, ACMPW, ACMPL, AFCMPF, AFCMPD);
-	oinit(OHI, ACMPB, ACMPW, ACMPL, AFCMPF, AFCMPD);
-	oinit(OASHR, AASRB, AASRW, AASRL, AGOK, AGOK);
-	oinit(OASASHR, AASRB, AASRW, AASRL, AGOK, AGOK);
-	oinit(OLSHR, ALSRB, ALSRW, ALSRL, AGOK, AGOK);
-	oinit(OASLSHR, ALSRB, ALSRW, ALSRL, AGOK, AGOK);
-	oinit(OASHL, AASLB, AASLW, AASLL, AGOK, AGOK);
-	oinit(OASASHL, AASLB, AASLW, AASLL, AGOK, AGOK);
-	oinit(OBIT, ABFEXTU, AGOK, AGOK, AGOK, AGOK);
-
-	nstring = 0;
-	mnstring = 0;
-	nrathole = 0;
-	nstatic = 0;
-	pc = 0;
-	breakpc = -1;
-	continpc = -1;
-	cases = C;
-	firstp = P;
-	lastp = P;
-	tfield = types[TLONG];
-
-	zprog.link = P;
-	zprog.as = AGOK;
-	zprog.from.type = D_NONE;
-	zprog.from.index = D_NONE;
-	zprog.to = zprog.from;
-
-	nodret = new(ONAME, Z, Z);
-	nodret->sym = slookup(".ret");
-	nodret->type = types[TIND];
-	nodret->etype = types[TIND]->etype;
-	nodret->class = CPARAM;
-	nodret = new(OIND, nodret, Z);
-	complex(nodret);
-
-	symrathole = slookup(".rathole");
-	symrathole->class = CGLOBL;
-	symrathole->type = typ(TARRAY, types[TCHAR]);
-	nodrat = new(ONAME, Z, Z);
-	nodrat->sym = symrathole;
-	nodrat->type = types[TIND];
-	nodrat->etype = TVOID;
-	nodrat->class = CGLOBL;
-	complex(nodrat);
-	nodrat->type = symrathole->type;
-
-	com64init();
-
-	symstatic = slookup(".static");
-	symstatic->class = CSTATIC;
-	symstatic->type = typ(TARRAY, types[TLONG]);
-}
-
-void
-gclean(void)
-{
-	int i;
-	Sym *s;
-
-	regfree(D_A0+6);
-	regfree(D_A0+7);
-	for(i=0; i<NREG; i++) {
-		if(regused[i])
-			diag(Z, "missing R%d", i);
-		if(aregused[i])
-			diag(Z, "missing A%d", i);
-		if(fregused[i])
-			diag(Z, "missing F%d", i);
-	}
-
-	while(mnstring)
-		outstring("", 1L);
-	symstring->type->width = nstring;
-	symstatic->type->width = nstatic;
-	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, D_CONST, s->type->width);
-		pc--;
-	}
-	nextpc();
-	p->as = AEND;
-	outcode();
-}
-
-void
-oinit(int o, int ab, int aw, int al, int af, int ad)
-{
-	int i;
-
-	i = o;
-	if(i >= ALLOP) {
-		diag(Z, "op(%d) >= ALLOP(%d)", i, ALLOP);
-		errorexit();
-	}
-	opxt[i][TCHAR] = ab;
-	opxt[i][TUCHAR] = ab;
-	opxt[i][TSHORT] = aw;
-	opxt[i][TUSHORT] = aw;
-	opxt[i][TINT] = al;
-	opxt[i][TUINT] = al;
-	opxt[i][TLONG] = al;
-	opxt[i][TULONG] = al;
-	opxt[i][TIND] = al;
-	opxt[i][TFLOAT] = af;
-	opxt[i][TDOUBLE] = ad;
-}
-
-Prog*
-prg(void)
-{
-	Prog *p;
-
-	p = alloc(sizeof(*p));
-	*p = zprog;
-	return p;
-}
-
-void
-nextpc(void)
-{
-
-	p = prg();
-	pc++;
-	p->lineno = nearln;
-	if(firstp == P) {
-		firstp = p;
-		lastp = p;
-		return;
-	}
-	lastp->link = p;
-	lastp = p;
-}
-
-void
-gargs(Node *n)
-{
-	long s;
-
-loop:
-	if(n == Z)
-		return;
-	if(n->op == OLIST) {
-		gargs(n->right);
-		n = n->left;
-		goto loop;
-	}
-	s = argoff;
-	cgen(n, D_TOS, n);
-	argoff = s + n->type->width;
-}
-
-void
-naddr(Node *n, Adr *a, int x)
-{
-	Node *l;
-	long v;
-
-	switch(n->op) {
-	default:
-	bad:
-		diag(n, "bad in naddr: %O", n->op);
-		break;
-
-	case OADDR:
-	case OIND:
-		naddr(n->left, a, x);
-		goto noadd;
-
-	case OREGISTER:
-		a->sym = S;
-		a->type = n->reg;
-		a->offset = n->xoffset;
-		a->displace = 0;
-		break;
-
-	case ONAME:
-		a->etype = n->etype;
-		a->displace = 0;
-		a->sym = n->sym;
-		a->offset = n->xoffset;
-		a->type = D_STATIC;
-		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 OINDEX:
-		naddr(n->left, a, x);
-		switch(n->left->addable) {
-		default:
-			goto bad;
-		case 1:
-		case 12:
-			a->index = x | I_INDEX1;
-			a->type &= D_MASK;
-			break;
-		case 2:
-		case 10:
-		case 11:
-			a->index = x | I_INDEX2;
-			break;
-		}
-		a->scale = n->scale;
-		break;
-
-	case OCONST:
-		a->displace = 0;
-		if(typefd[n->type->etype]) {
-			a->type = D_FCONST;
-			a->dval = n->fconst;
-			break;
-		}
-		a->type = D_CONST;
-		a->offset = n->vconst;
-		break;
-
-	case OADD:
-		l = n->left;
-		if(l->addable == 20) {
-			v = l->vconst;
-			naddr(n->right, a, x);
-			goto add;
-		}
-		l = n->right;
-		if(l->addable == 20) {
-			v = l->vconst;
-			naddr(n->left, a, x);
-			goto add;
-		}
-		goto bad;
-	noadd:
-		v = 0;
-	add:
-		switch(n->addable) {
-		default:
-			goto bad;
-		case 2:
-			a->displace += v;
-			break;
-		case 21:
-			a->type &= D_MASK;
-			a->type |= I_INDIR;
-			break;
-		case 1:
-		case 12:
-			a->offset += v;
-			a->type &= D_MASK;
-			a->type |= I_ADDR;
-			break;
-		case 13:
-			a->index = D_NONE|I_INDEX3;
-		case 10:
-		case 11:
-		case 20:
-			a->type &= D_MASK;
-			a->type |= I_DIR;
-			break;
-		}
-		break;
-
-	case OPREINC:
-	case OPREDEC:
-	case OPOSTINC:
-	case OPOSTDEC:
-
-	case OAS:
-	case OASLMUL:
-	case OASLDIV:
-	case OASLMOD:
-	case OASMUL:
-	case OASDIV:
-	case OASMOD:
-	case OASXOR:
-	case OASOR:
-	case OASADD:
-	case OASSUB:
-	case OASLSHR:
-	case OASASHR:
-	case OASASHL:
-	case OASAND:
-		naddr(n->left, a, x);
-		break;
-	}
-}
-
-int
-regalloc(Type *t, int g)
-{
-
-	if(t == T)
-		return D_NONE;
-	g &= D_MASK;
-	if(typefd[t->etype]) {
-		if(g >= D_F0 && g < D_F0+NREG) {
-			fregused[g-D_F0]++;
-			return g;
-		}
-		for(g=0; g<NREG; g++)
-			if(fregused[g] == 0) {
-				fregused[g]++;
-				return g + D_F0;
-			}
-	} else {
-		if(g >= D_R0 && g < D_R0+NREG) {
-			regused[g-D_R0]++;
-			return g;
-		}
-		for(g=0; g<NREG; g++)
-			if(regused[g] == 0) {
-				regused[g]++;
-				return g + D_R0;
-			}
-	}
-	diag(Z, "out of registers");
-	return D_TOS;
-}
-
-int
-regaddr(int g)
-{
-
-	if(g >= D_A0 && g < D_A0+NREG) {
-		aregused[g-D_A0]++;
-		return g;
-	}
-	for(g=0; g<NREG; g++)
-		if(aregused[g] == 0) {
-			aregused[g]++;
-			return g + D_A0;
-		}
-	diag(Z, "out of addr registers");
-	return D_TOS;
-}
-
-int
-regpair(int g)
-{
-
-	if(g >= D_R0+1 && g < D_R0+NREG)
-		if(!regused[g-D_R0-1]) {
-			regused[g-D_R0-1]++;
-			regused[g-D_R0]++;
-			return g-1;
-		}
-	if(g >= D_R0 && g < D_R0+NREG-1)
-		if(!regused[g-D_R0+1]) {
-			regused[g-D_R0+1]++;
-			regused[g-D_R0]++;
-			return g;
-		}
-	for(g = 0; g < NREG-1; g++)
-		if(!regused[g])
-		if(!regused[g+1]) {
-			regused[g]++;
-			regused[g+1]++;
-			return g + D_R0;
-		}
-	diag(Z, "out of register pairs");
-	return D_TOS;
-}
-
-int
-regret(Type *t)
-{
-
-	if(t == T)
-		return D_NONE;
-	if(typefd[t->etype])
-		return D_F0;
-	return D_R0;
-}
-
-void
-regfree(int g)
-{
-
-	g &= D_MASK;
-	if(g == D_TOS || g == D_TREE || g == D_NONE)
-		return;
-	if(g >= D_R0 && g < D_R0+NREG) {
-		regused[g-D_R0]--;
-		return;
-	}
-	if(g >= D_A0 && g < D_A0+NREG) {
-		aregused[g-D_A0]--;
-		return;
-	}
-	if(g >= D_F0 && g < D_F0+NREG) {
-		fregused[g-D_F0]--;
-		return;
-	}
-	diag(Z, "bad in regfree: %d", g);
-}
-
-void
-gmove(Type *tf, Type *tt, int gf, Node *f, int gt, Node *t)
-{
-	int g, a, b;
-	Prog *p1;
-
-	tindex(tf, tt);
-	if(txtp->preclr) {
-		if(gf >= D_R0 && gf < D_R0+NREG)
-		if(txtp->preclr < 0) {
-			gmove(tt, tt, gf, f, gt, t);
-			return;
-		}
-		g = regalloc(types[TLONG], gt);
-		if(g == gf) {
-			g = regalloc(types[TLONG], D_NONE);
-			regfree(gf);
-		}
-		if(txtp->preclr > 0)
-			gopcode(OAS, types[TLONG], D_CONST, nodconst(0), g, Z);
-		gopcode(OAS, tf, gf, f, g, Z);
-		if(g != gt)
-			gopcode(OAS, tt, g, Z, gt, t);
-		regfree(g);
-		return;
-	}
-	a = txtp->postext;
-	if(a != AGOK) {
-		if(gf >= D_R0 && gf < D_R0+NREG)
-			g = regalloc(types[TLONG], gf);
-		else
-			g = regalloc(types[TLONG], gt);
-		if(g != gf)
-			gopcode(OAS, tf, gf, f, g, Z);
-		nextpc();
-		p->as = a;
-		p->to.type = g;
-		if(debug['g'])
-			print("%P\n", p);
-		if(g != gt)
-			gopcode(OAS, tt, g, Z, gt, t);
-		regfree(g);
-		return;
-	}
-	if((regbase[gf] != D_NONE && regbase[gf] == regbase[gt]) ||
-	   (gf == D_TREE && gt == D_TREE && f == t))
-		return;
-	if(typefd[tf->etype] || typefd[tt->etype]) {
-		if(typeu[tf->etype] && typefd[tt->etype]) {	/* unsign->float */
-			a = regalloc(types[TLONG], D_NONE);
-			gmove(tf, types[TLONG], gf, f, a, t);
-			if(tf->etype == TULONG) {
-				b = regalloc(types[TDOUBLE], D_NONE);
-				gmove(types[TLONG], tt, a, t, b, t);
-				gopcode(OTST, types[TLONG], D_NONE, Z, a, t);
-				gbranch(OGE);
-				p1 = p;
-				gopcode(OASADD, types[TDOUBLE],
-					D_CONST, nodconst(100), b, t);
-				p->from.dval = 4294967296.;
-				patch(p1, pc);
-				gmove(types[TDOUBLE], tt, b, t, gt, t);
-				regfree(b);
-			} else
-				gmove(types[TLONG], tt, a, t, gt, t);
-			regfree(a);
-			return;
-		}
-		if(typefd[tf->etype] && !typefd[tt->etype]) {	/* float->fix */
-			a = regalloc(types[TLONG], D_NONE);
-			gopcode(OAS, types[TLONG], D_FPCR, t, a, t);
-			gopcode(OAS, types[TLONG], D_CONST, nodconst(16), D_FPCR, t);
-		}
-		if(gf < D_F0 || gf >= D_F0+NREG) {
-			g = regalloc(types[TDOUBLE], gt);
-			gopcode(OFAS, tf, gf, f, g, t);
-			if(g != gt)
-				gopcode(OFAS, tt, g, t, gt, t);
-			regfree(g);
-		} else
-			gopcode(OFAS, tt, gf, f, gt, t);
-		if(typefd[tf->etype] && !typefd[tt->etype]) {	/* float->fix */
-			gopcode(OAS, types[TLONG], a, t, D_FPCR, t);
-			regfree(a);
-		}
-		return;
-	}
-	gopcode(OAS, tt, gf, f, gt, t);
-}
-
-void
-gopcode(int o, Type *ty, int gf, Node *f, int gt, Node *t)
-{
-	int i, fidx, tidx;
-	long v;
-
-	if(o == OAS)
-		if(gf == gt)
-			if(gf != D_TREE || f == t)
-				return;
-
-	fidx = D_NONE;
-	if(gf == D_TREE) {
-		if(f->op == OINDEX) {
-			fidx = regalloc(types[TIND], fidx);
-			cgen(f->right, fidx, f->right);
-		}
-	}
-	tidx = D_NONE;
-	if(gt == D_TREE) {
-		if(t->op == OINDEX) {
-			v = argoff;
-			tidx = regalloc(types[TIND], tidx);
-			cgen(t->right, tidx, t->right);
-			if(gf == D_TOS)
-				adjsp(v - argoff);
-		}
-	}
-	i = 0;
-	if(ty != T) {
-		i = ty->etype;
-		if(i >= NTYPE)
-			i = 0;
-	}
-	nextpc();
-	if(gf == D_TREE) {
-		naddr(f, &p->from, fidx);
-	} else {
-		p->from.type = gf;
-		if(gf == D_CONST) {
-			p->from.offset = (long)(uintptr)f;
-			if(typefd[i]) {
-				p->from.type = D_FCONST;
-				p->from.dval = (long)(uintptr)f;
-			}
-		}
-	}
-	p->as = opxt[o][i];
-	if(gt == D_TREE) {
-		naddr(t, &p->to, tidx);
-	} else {
-		p->to.type = gt;
-		if(gt == D_CONST)
-			p->to.offset = (long)(uintptr)t;
-	}
-	if(o == OBIT) {
-		p->from.field = f->type->nbits;
-		p->to.field = f->type->shift;
-		if(p->from.field == 0)
-			diag(Z, "BIT zero width bit field");
-	}
-	if(p->as == AMOVL || p->as == AMOVW || p->as == AMOVB)
-		asopt();
-	if(debug['g'])
-		print("%P\n", p);
-	if(p->as == AGOK)
-		diag(Z, "GOK in gopcode: %s", onames[o]);
-	if(fidx != D_NONE)
-		regfree(fidx);
-	if(tidx != D_NONE)
-		regfree(tidx);
-}
-
-void
-asopt(void)
-{
-	long v;
-	int g;
-	Prog *q;
-
-	/*
-	 * mov $0, ...
-	 * ==>
-	 * clr , ...
-	 */
-	v = 0;
-	if(p->from.type == D_CONST) {
-		v = p->from.offset;
-		if(v == 0) {
-			p->from.type = D_NONE;
-			if(p->as == AMOVL)
-				p->as = ACLRL;
-			if(p->as == AMOVW)
-				p->as = ACLRW;
-			if(p->as == AMOVB)
-				p->as = ACLRB;
-			return;
-		}
-	}
-	/*
-	 * mov ..., TOS
-	 * ==>
-	 * pea (...)
-	 */
-	if(p->as == AMOVL && p->to.type == D_TOS && p->from.index == D_NONE)
-	switch(p->from.type) {
-	case D_CONST:
-		p->from.type |= I_INDIR;
-		p->to = p->from;
-		p->from = zprog.from;
-		p->as = APEA;
-		return;
-
-	case I_ADDR|D_EXTERN:
-	case I_ADDR|D_STATIC:
-		p->from.type &= ~I_ADDR;
-		p->to = p->from;
-		p->from = zprog.from;
-		p->as = APEA;
-		return;
-	}
-	/*
-	 * movL $Qx, ...
-	 * ==>
-	 * movL $Qx,R
-	 * movL R, ...
-	 */
-	if(p->as == AMOVL && p->from.type == D_CONST)
-	if(v >= -128 && v < 128)
-	if(p->to.type < D_R0 || p->to.type >= D_R0+NREG) {
-		g = regalloc(types[TLONG], D_NONE);
-		q = p;
-		nextpc();
-		p->as = AMOVL;
-		p->from.type = g;
-		p->to = q->to;
-		q->to = p->from;
-		regfree(g);
-		if(debug['g'])
-			print("%P\n", q);
-		return;
-	}
-}
-
-void
-gbranch(int o)
-{
-	int a;
-
-	a = ABNE;
-	switch(o) {
-	case ORETURN: a = ARTS; break;
-	case OGOTO: a = ABRA; break;
-	case OEQ: a = ABEQ; break;
-	case ONE: a = ABNE; break;
-	case OLE: a = ABLE; break;
-	case OLS: a = ABLS; break;
-	case OLT: a = ABLT; break;
-	case OLO: a = ABCS; break;
-	case OGE: a = ABGE; break;
-	case OHS: a = ABCC; break;
-	case OGT: a = ABGT; break;
-	case OHI: a = ABHI; break;
-	case OBIT: a = ABCS; break;
-	case OCASE: a = ABCASE; break;
-	}
-	nextpc();
-	p->from.type = D_NONE;
-	p->to.type = D_NONE;
-	p->as = a;
-}
-
-void
-fpbranch(void)
-{
-	int a;
-
-	a = p->as;
-	switch(a) {
-	case ABEQ: a = AFBEQ; break;
-	case ABNE: a = AFBNE; break;
-	case ABLE: a = AFBLE; break;
-	case ABLT: a = AFBLT; break;
-	case ABGE: a = AFBGE; break;
-	case ABGT: a = AFBGT; break;
-	}
-	p->as = a;
-}
-
-void
-patch(Prog *op, long pc)
-{
-
-	op->to.offset = pc;
-	op->to.type = D_BRANCH;
-}
-
-void
-gpseudo(int a, Sym *s, int g, long v)
-{
-
-	nextpc();
-	if(a == ADATA)
-		pc--;
-	p->as = a;
-	if(g == D_TREE)
-		abort();	/* obsolete */
-	p->to.type = g;
-	p->to.offset = v;
-	p->from.sym = s;
-	p->from.type = D_EXTERN;
-	if(s->class == CSTATIC)
-		p->from.type = D_STATIC;
-}
-
-void
-gpseudotree(int a, Sym *s, Node *n)
-{
-	nextpc();
-	if(a == ADATA)
-		pc--;
-	p->as = a;
-	naddr(n, &p->to, D_NONE);
-	p->from.sym = s;
-	p->from.type = D_EXTERN;
-	if(s->class == CSTATIC)
-		p->from.type = D_STATIC;
-}
-
-long
-exreg(Type *t)
-{
-	long o;
-
-	if(typechl[t->etype]) {
-		if(exregoffset <= 5)
-			return 0;
-		o = exregoffset + D_R0;
-		exregoffset--;
-		return o;
-	}
-	if(t->etype == TIND) {
-		if(exaregoffset <= 3)
-			return 0;
-		o = exaregoffset + D_A0;
-		exaregoffset--;
-		return o;
-	}
-	if(typefd[t->etype]) {
-		if(exfregoffset <= 5)
-			return 0;
-		o = exfregoffset + D_F0;
-		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] */
-};
-long	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 - 1569
sys/src/cmd/2l/asm.c

@@ -1,1569 +0,0 @@
-#include	"l.h"
-
-short	opa[20];
-short	*op;
-
-long
-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;
-	if(s->type != STEXT)
-		diag("entry not text: %s", s->name);
-	return s->value;
-}
-
-void
-asmb(void)
-{
-	Prog *p;
-	long v;
-	int a;
-	short *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;
-		if(debug['a'])
-			Bprint(&bso, "%lux:%P\n", pc, curp);
-		asmins(p);
-		if(cbc < sizeof(opa))
-			cflush();
-		for(op1 = opa; op1 < op; op1++) {
-			a = *op1;
-			*cbp++ = a >> 8;
-			*cbp++ = a;
-		}
-		a = 2*(op - opa);
-		pc += a;
-		cbc -= a;
-		if(debug['a']) {
-			for(op1 = opa; op1 < op; op1++)
-				if(op1 == opa)
-					Bprint(&bso, "\t\t%4ux", *op1 & 0xffff);
-				else
-					Bprint(&bso, " %4ux", *op1 & 0xffff);
-			if(op != opa)
-				Bprint(&bso, "\n");
-		}
-	}
-	cflush();
-	switch(HEADTYPE) {
-	case 0:	/* this is garbage */
-		seek(cout, rnd(HEADR+textsize, 8192), 0);
-		break;
-	case 1:	/* plan9 boot data goes into text */
-		seek(cout, rnd(HEADR+textsize, INITRND), 0);
-		break;
-	case 2:	/* plan 9 */
-		seek(cout, HEADR+textsize, 0);
-		break;
-	case 3:	/* next boot */
-		seek(cout, HEADR+rnd(textsize, INITRND), 0);
-		break;
-	case 4:	/* preprocess pilot */
-		seek(cout, HEADR+textsize, 0);
-		break;
-	}
-
-	if(debug['v'])
-		Bprint(&bso, "%5.2f datblk\n", cputime());
-	Bflush(&bso);
-
-	for(v = 0; v < datsize; v += sizeof(buf)-100) {
-		if(datsize-v > sizeof(buf)-100)
-			datblk(v, sizeof(buf)-100);
-		else
-			datblk(v, datsize-v);
-	}
-
-	symsize = 0;
-	spsize = 0;
-	lcsize = 0;
-
-	Bflush(&bso);
-
-	switch(HEADTYPE) {
-	default:
-		seek(cout, rnd(HEADR+textsize, 8192)+datsize, 0);
-		break;
-	case 1:	/* plan9 boot data goes into text */
-		seek(cout, rnd(HEADR+textsize, INITRND)+datsize, 0);
-		break;
-	case 2:	/* plan 9 */
-		seek(cout, HEADR+textsize+datsize, 0);
-		break;
-	case 3:	/* next boot */
-		seek(cout, HEADR+rnd(textsize, INITRND)+datsize, 0);
-		break;
-	}
-	if(!debug['s']) {
-		if(debug['v'])
-			Bprint(&bso, "%5.2f sym\n", cputime());
-		asmsym();
-	}
-	Bflush(&bso);
-	if(!debug['s']) {
-		if(debug['v'])
-			Bprint(&bso, "%5.2f sp\n", cputime());
-		asmsp();
-	}
-	Bflush(&bso);
-	if(!debug['s']) {
-		if(debug['v'])
-			Bprint(&bso, "%5.2f pc\n", cputime());
-		asmlc();
-	}
-	cflush();
-
-	if(debug['v'])
-		Bprint(&bso, "%5.2f headr\n", cputime());
-	Bflush(&bso);
-	seek(cout, 0L, 0);
-	switch(HEADTYPE) {
-	default:
-		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:	/* plan9 boot data goes into text */
-		lput(0407);			/* magic */
-		lput(rnd(HEADR+textsize, INITRND)-HEADR+datsize);		/* sizes */
-		lput(0);
-		lput(bsssize);
-		lput(symsize);			/* nsyms */
-		lput(entryvalue());		/* va of entry */
-		lput(spsize);			/* sp offsets */
-		lput(lcsize);			/* line offsets */
-		break;
-	case 2:	/* plan 9 */
-		lput(0407);			/* 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:	/* next boot */
-		/* header */
-		lput(0xfeedfaceL);			/* magic */
-		lput(6);				/* 68040 */
-		lput(1);				/* more 68040 */
-		lput(5);				/* file type 'boot' */
-		lput(HEADTYPE);				/* number commands */
-		lput(HEADR-7*4);			/* sizeof commands */
-		lput(1);				/* no undefineds */
-		/* command 1 text */
-		lput(1);				/* command = 'segment' */
-		lput(124);				/* command size */
-		s16put("__TEXT");
-			/* botch?? entryvalue() */
-		lput(INITTEXT);				/* va of start */
-		lput(rnd(textsize, 8192));		/* va size */
-		lput(HEADR);				/* file offset */
-		lput(rnd(textsize, 8192));		/* file size */
-		lput(7);				/* max prot */
-		lput(7);				/* init prot */
-		lput(1);				/* number of sections */
-		lput(0);				/* flags */
-		/* text section */
-		s16put("__text");
-		s16put("__TEXT");
-			/* botch?? entryvalue() */
-		lput(INITTEXT);				/* va of start */
-		lput(textsize);				/* va size */
-		lput(HEADR);				/* file offset */
-		lput(2);				/* align */
-		lput(0);				/* reloff */
-		lput(0);				/* nreloc */
-		lput(0);				/* flags */
-		lput(0);				/* reserved1 */
-		lput(0);				/* reserved2 */
-		/* command 1 data */
-		lput(1);				/* command = 'segment' */
-		lput(192);				/* command size */
-		s16put("__DATA");
-		lput(INITDAT);				/* va of start */
-		lput(rnd(datsize, 8192));		/* va size */
-		lput(HEADR+rnd(textsize, 8192));	/* file offset */
-		lput(rnd(datsize, 8192));		/* file size */
-		lput(7);				/* max prot */
-		lput(7);				/* init prot */
-		lput(2);				/* number of sections */
-		lput(0);				/* flags */
-		/* data section */
-		s16put("__data");
-		s16put("__DATA");
-		lput(INITDAT);				/* va of start */
-		lput(datsize);				/* va size */
-		lput(HEADR+rnd(textsize, 8192));	/* file offset */
-		lput(2);				/* align */
-		lput(0);				/* reloff */
-		lput(0);				/* nreloc */
-		lput(0);				/* flags */
-		lput(0);				/* reserved1 */
-		lput(0);				/* reserved2 */
-		/* bss section */
-		s16put("__bss");
-		s16put("__DATA");
-		lput(INITDAT+datsize);			/* va of start */
-		lput(bsssize);				/* va size */
-		lput(0);				/* file offset */
-		lput(2);				/* align */
-		lput(0);				/* reloff */
-		lput(0);				/* nreloc */
-		lput(1);				/* flags = zero fill */
-		lput(0);				/* reserved1 */
-		lput(0);				/* reserved2 */
-		/* command 2 symbol */
-		lput(2);				/* command = 'symbol' */
-		lput(24);				/* command size */
-		lput(HEADR+rnd(textsize, INITRND)
-			+datsize);			/* symoff */
-		lput(symsize);				/* nsyms */
-		lput(spsize);				/* sp offsets */
-		lput(lcsize);				/* line offsets */
-		break;
-	}
-	cflush();
-}
-
-void
-asmins(Prog *p)
-{
-	Optab *o;
-	int t, a, b;
-	long v;
-	Prog *q;
-
-	op = opa + 1;
-	if(special[p->from.type])
-	switch(p->from.type) {
-
-	case D_CCR:
-		if(p->as != AMOVW)
-			goto bad;
-		a = asmea(p, &p->to);
-		if((a & 0170) == 010)
-			goto bad;
-		opa[0] = 0x42c0 | a;		/* mov from ccr */
-		return;
-
-	case D_SR:
-		if(p->as != AMOVW)
-			goto bad;
-		a = asmea(p, &p->to);
-		if((a & 0170) == 010)
-			goto bad;
-		opa[0] = 0x40c0 | a;		/* mov from sr */
-		return;
-
-	case D_USP:
-		if(p->as != AMOVL)
-			goto bad;
-		a = asmea(p, &p->to);
-		if((a & 0170) == 010) {
-			opa[0] = 0x4e68|(a&7);	/* mov usp An */
-			return;
-		}
-		t = 0x800;
-		goto movec1;
-
-	case D_SFC:
-		t = 0x000;
-		goto movec1;
-
-	case D_DFC:
-		t = 0x001;
-		goto movec1;
-
-	case D_CACR:
-		t = 0x002;
-		goto movec1;
-
-	case D_TC:
-		t = 0x003;
-		goto movec1;
-
-	case D_ITT0:
-		t = 0x004;
-		goto movec1;
-
-	case D_ITT1:
-		t = 0x005;
-		goto movec1;
-
-	case D_DTT0:
-		t = 0x006;
-		goto movec1;
-
-	case D_DTT1:
-		t = 0x007;
-		goto movec1;
-
-	case D_VBR:
-		t = 0x801;
-		goto movec1;
-
-	case D_CAAR:
-		t = 0x802;
-		goto movec1;
-
-	case D_MSP:
-		t = 0x803;
-		goto movec1;
-
-	case D_ISP:
-		t = 0x804;
-		goto movec1;
-
-	case D_MMUSR:
-		t = 0x805;
-		goto movec1;
-
-	case D_URP:
-		t = 0x806;
-		goto movec1;
-
-	case D_SRP:
-		t = 0x807;
-		goto movec1;
-
-	movec1:
-		if(p->as != AMOVL)
-			goto bad;
-		opa[0] = 0x4e7a;			/* mov spc Dn */
-		a = asmea(p, &p->to);
-		b = a & 0170;
-		if(b == 0 || b == 010) {
-			*op++ = (a<<12) | t;
-			return;
-		}
-		goto bad;
-
-	case D_FPCR:
-		t = 0xb000;
-		goto movec3;
-
-	case D_FPSR:
-		t = 0xa800;
-		goto movec3;
-
-	case D_FPIAR:
-		t = 0xa400;
-
-	movec3:
-		if(p->as != AMOVL)
-			goto bad;
-		op++;
-		a = asmea(p, &p->to);
-		opa[0] = optab[AFMOVEL].opcode0 | a;
-		opa[1] = t;
-		return;
-	}
-	if(special[p->to.type])
-	switch(p->to.type) {
-
-	case D_CCR:
-		if(p->as != AMOVW)		/* botch, needs and, eor etc. */
-			goto bad;
-		a = asmea(p, &p->from);
-		if((a & 0170) == 010)
-			goto bad;
-		opa[0] = 0x44c0 | a;		/* mov to ccr */
-		return;
-
-	case D_SR:
-		if(p->as != AMOVW)		/* botch, needs and, eor etc. */
-			goto bad;
-		a = asmea(p, &p->from);
-		if((a & 0170) == 010)
-			goto bad;
-		opa[0] = 0x46c0 | a;		/* mov to sr */
-		return;
-
-	case D_USP:
-		if(p->as != AMOVL)
-			goto bad;
-		a = asmea(p, &p->from);
-		if((a & 0170) == 010) {
-			opa[0] = 0x4e60|(a&7);	/* mov An usp */
-			return;
-		}
-		t = 0x800;
-		goto movec2;
-
-	case D_SFC:
-		t = 0x000;
-		goto movec2;
-
-	case D_DFC:
-		t = 0x001;
-		goto movec2;
-
-	case D_CACR:
-		t = 0x002;
-		goto movec2;
-
-	case D_TC:
-		t = 0x003;
-		goto movec2;
-
-	case D_ITT0:
-		t = 0x004;
-		goto movec2;
-
-	case D_ITT1:
-		t = 0x005;
-		goto movec2;
-
-	case D_DTT0:
-		t = 0x006;
-		goto movec2;
-
-	case D_DTT1:
-		t = 0x007;
-		goto movec2;
-
-	case D_VBR:
-		t = 0x801;
-		goto movec2;
-
-	case D_CAAR:
-		t = 0x802;
-		goto movec2;
-
-	case D_MSP:
-		t = 0x803;
-		goto movec2;
-
-	case D_ISP:
-		t = 0x804;
-		goto movec2;
-
-	case D_MMUSR:
-		t = 0x805;
-		goto movec2;
-
-	case D_URP:
-		t = 0x806;
-		goto movec2;
-
-	case D_SRP:
-		t = 0x807;
-		goto movec2;
-
-	movec2:
-		if(p->as != AMOVL)
-			goto bad;
-		opa[0] = 0x4e7b;			/* mov Dn spc */
-		a = asmea(p, &p->from);
-		b = a & 0170;
-		if(b == 0 || b == 010) {
-			*op++ = (a<<12) | t;
-			return;
-		}
-		goto bad;
-
-	case D_FPCR:
-		t = 0x9000;
-		goto movec4;
-
-	case D_FPSR:
-		t = 0x8800;
-		goto movec4;
-
-	case D_FPIAR:
-		t = 0x8400;
-
-	movec4:
-		if(p->as != AMOVL)
-			goto bad;
-		op++;
-		a = asmea(p, &p->from);
-		opa[0] = optab[AFMOVEL].opcode0 | a;
-		opa[1] = t;
-		return;
-	}
-
-	o = &optab[p->as];
-	t = o->opcode0;
-	switch(o->optype) {
-	case 0:		/* pseudo ops */
-		if(p->as != ATEXT && p->as != ANOP) {
-			if(!debug['a'])
-				print("%P\n", p);
-			diag("unimplemented instruction in %s", TNAME);
-			return;
-		}
-		op = opa;
-		return;
-
-	case 1:		/* branches */
-		if(p->to.type != D_BRANCH)
-			goto bad;
-		a = asmea(p, &p->to);
-		/* hack to turn 3-word bsr into 2-word jsr */
-		if(a == 0xff && p->as == ABSR &&
-		   p->pcond->pc < 32768L && p->pcond->pc >= 0) {
-			op = opa + 1;
-			t = o->opcode1;
-			*op++ = p->pcond->pc;
-			break;
-		}
-		t |= a;
-		break;
-
-	case 2:		/* move */
-		a = asmea(p, &p->from);
-		b = asmea(p, &p->to);
-		if((a & 0170) == 0110) { /* src quick */
-			t = o->opcode1;
-			if((b & 0170) != 0)
-				goto bad;
-			t |= a >> 7;
-			t |= b << 9;
-			break;
-		}
-		t |= a;
-		t |= (b&7) << 9;
-		t |= (b&070) << 3;
-		break;
-
-	case 3:		/* add */
-		a = asmea(p, &p->from);
-		b = asmea(p, &p->to);
-		if((a & 0170) == 0110) { /* src quick */
-			t = o->opcode1;
-			t |= (a&01600) << 2;
-			t |= b;
-			break;
-		}
-		if((b & 0170) == 0) { /* dst Dn */
-			t |= a;
-			t |= (b & 7) << 9;
-			break;
-		}
-		if((b & 0170) == 010) { /* dst An */
-			if((t & 0xc0) == 0)
-				goto bad;
-			t = o->opcode2;
-			t |= a;						
-			t |= (b & 7) << 9;
-			break;
-		}
-		if((a & 0170) == 0) { /* src Dn */
-			t |= 0x100;
-			t |= (a & 7) << 9;
-			t |= b;
-			break;
-		}
-		if((a & 0177) == 074) { /* src immed */
-			t = o->opcode3;
-			t |= b;
-			break;
-		}
-		goto bad;
-
-	case 4:		/* no operands */
-		break;
-
-	case 5:		/* tst */
-		t |= asmea(p, &p->to);
-		if((t&0170) == 010)
-			goto bad;
-		break;
-
-	case 6:		/* lea */
-		a = asmea(p, &p->from);
-		b = asmea(p, &p->to);
-		if((b & 0170) != 010)
-			goto bad;
-		t |= a;
-		t |= (b & 7) << 9;
-		break;
-
-	case 7:		/* cmp */
-		b = asmea(p, &p->to);
-		a = asmea(p, &p->from);
-		if((a & 0170) == 010) {	/* dst An */
-			t = o->opcode1;
-			if(t == 0)	/* cmpb illegal */
-				goto bad;
-			t |= 0xc0;
-			t |= b;						
-			t |= (a & 7) << 9;
-			break;
-		}
-		if((b & 0177) == 074) { /* src immed */
-			t = o->opcode2;
-			t |= a;
-			break;
-		}
-		if((a & 0170) == 0) {	/* dst Dn */
-			t |= b;
-			t |= (a&7) << 9;
-			break;
-		}
-		if((b&0170) == 030 && (a&0170) == 030) { /* (A)+,(A)+ */
-			t = o->opcode3;
-			t |= b & 7;
-			t |= (a & 7) << 9;
-			break;
-		}
-		goto bad;
-
-	case 8:		/* svc */
-		*op++ = optab[ARTS].opcode0;
-		break;
-
-	case 9:		/* and */
-		a = asmea(p, &p->from);
-		b = asmea(p, &p->to);
-		if((a & 0170) == 010)
-			goto bad;
-		if((b & 0170) == 0) { /* dst Dn */
-			t |= a;
-			t |= (b&7) << 9;
-			break;
-		}
-		if((a & 0170) == 0) { /* src Dn */
-			t = o->opcode1;
-			t |= b;
-			t |= (a&7) << 9;
-			break;
-		}
-		if((a & 0177) == 074) { /* src immed */
-			t = o->opcode2;
-			t |= b;
-			break;
-		}
-		goto bad;
-
-	case 10:	/* eor */
-		a = asmea(p, &p->from);
-		b = asmea(p, &p->to);
-		if((a & 0170) == 010)
-			goto bad;
-		if((a & 0170) == 0) { /* src Dn */
-			t |= b;
-			t |= (a&7) << 9;
-			break;
-		}
-		if((a & 0177) == 074) { /* src immed */
-			t = o->opcode1;
-			t |= b;
-			break;
-		}
-		goto bad;
-
-	case 11:	/* ext */
-		b = asmea(p, &p->to);
-		if((b & 0170) == 0) { /* dst Dn */
-			t |= b;
-			break;
-		}
-		goto bad;
-
-	case 12:	/* shift */
-		a = asmea(p, &p->from);
-		b = asmea(p, &p->to);
-		if((b & 0170) == 0) { /* dst Dn */
-			if((a & 0177) == 0110) { /* src quick */
-				t |= (a & 01600) << 2;
-				t |= b;
-				break;
-			}
-			if((a & 0170) == 0) { /* src Dn */
-				t |= 0x20;
-				t |= a << 9;
-				t |= b;
-				break;
-			}
-			goto bad;
-		}
-		goto bad;
-
-	case 13:	/* mul, div short */
-		a = asmea(p, &p->from);
-		b = asmea(p, &p->to);
-		if((b & 0170) == 0) { /* dst Dn */
-			if((a & 0170) == 010)
-				goto bad;	
-			t |= a;
-			t |= b << 9;
-			break;
-		}
-		goto bad;
-
-	case 14:	/* mul, div long */
-		*op++ = o->opcode1;
-		a = asmea(p, &p->from);
-		b = asmea(p, &p->to);
-		if((b & 0170) == 0) { /* dst Dn */
-			if((a & 0170) == 010)
-				goto bad;	
-			t |= a;
-			opa[1] |= b << 12;
-			opa[1] |= b+1;
-			break;
-		}
-		goto bad;
-
-	case 15:	/* dec and branch */
-		if(p->to.type != D_BRANCH)
-			goto bad;
-		v = p->pcond->pc - p->pc - 2;
-		if(v < -32768L || v >= 32768L)
-			goto bad;
-		*op++ = v;
-		a = asmea(p, &p->from);
-		if((a & 0170) != 0)
-			goto bad;
-		t |= a;
-		break;
-
-	case 16:	/* fmove */
-		*op++ = o->opcode1;
-		a = asmea(p, &p->from);
-		b = asmea(p, &p->to);
-		if((a & 0170) == 0100) { /* src Fn */
-			if((b & 0170) == 0100) { /* both Fn */
-				opa[1] |= (a&7) << 10;
-				opa[1] |= (b&7) << 7;
-				break;
-			}
-			t |= b;
-			opa[1] = o->opcode2;
-			opa[1] |= (a&7) << 7;
-			break;
-		}
-		if((b & 0170) != 0100) /* dst Fn */
-			goto bad;
-		t |= a;
-		opa[1] = o->opcode3;
-		opa[1] |= (b&7) << 7;
-		break;
-
-	case 17:	/* floating ea,Fn */
-		*op++ = o->opcode1;
-		a = asmea(p, &p->from);
-		b = asmea(p, &p->to);
-		if((b & 0170) != 0100) /* dst Fn */
-			goto bad;
-		if((a & 0170) == 0100) { /* both Fn */
-			opa[1] |= (a&7) << 10;
-			opa[1] |= (b&7) << 7;
-			break;
-		}
-		t |= a;
-		opa[1] = o->opcode2;
-		opa[1] |= (b&7) << 7;
-		break;
-
-	case 18:	/* floating branchs */
-		if(p->to.type != D_BRANCH)
-			goto bad;
-		v = p->pcond->pc - p->pc - 2;
-		if(v < -32768L || v >= 32768L)
-			goto bad;
-		*op++ = v;
-		break;
-
-	case 19:	/* floating dec and branch */
-		if(p->to.type != D_BRANCH)
-			goto bad;
-		*op++ = o->opcode1;
-		v = p->pcond->pc - p->pc - 2;
-		if(v < -32768L || v >= 32768L)
-			goto bad;
-		*op++ = v;
-		a = asmea(p, &p->from);
-		if((a & 0170) != 0)
-			goto bad;
-		t |= a;
-		break;
-
-	case 20:	/* ftst ea */
-		*op++ = o->opcode1;
-		if(p->from.type != D_NONE)
-			goto bad;
-		a = asmea(p, &p->to);
-		if((a & 0170) == 0100) { /* Fn */
-			opa[1] |= (a&7) << 10;
-			break;
-		}
-		t |= a;
-		opa[1] = o->opcode2;
-		break;
-
-	case 21:	/* fneg */
-		*op++ = o->opcode1;
-		if(p->from.type == D_NONE) {
-			b = asmea(p, &p->to);
-			a = b;
-		} else {
-			a = asmea(p, &p->from);
-			b = asmea(p, &p->to);
-		}
-		if((b & 0170) != 0100) /* dst Fn */
-			goto bad;
-		if((a & 0170) == 0100) { /* both Fn */
-			opa[1] |= (a&7) << 10;
-			opa[1] |= (b&7) << 7;
-			break;
-		}
-		t |= a;
-		opa[1] = o->opcode2;
-		opa[1] |= (b&7) << 7;
-		break;
-
-	case 22:	/* floating cmp Fn,ea */
-		*op++ = o->opcode1;
-		a = asmea(p, &p->from);
-		b = asmea(p, &p->to);
-		if((a & 0170) != 0100) /* dst Fn */
-			goto bad;
-		if((b & 0170) == 0100) { /* both Fn */
-			opa[1] |= (b&7) << 10;
-			opa[1] |= (a&7) << 7;
-			break;
-		}
-		t |= b;
-		opa[1] = o->opcode2;
-		opa[1] |= (a&7) << 7;
-		break;
-
-	case 23:	/* word, long */
-		op = opa;
-		a = asmea(p, &p->to);
-		if(a == ((7<<3)|4))
-			return;
-		if(a == ((7<<3)|1)) {
-			if(p->as == AWORD) {
-				op = opa;
-				*op++ = opa[1];
-			}
-			return;
-		}
-		if(a == ((7<<3)|0)) {
-			if(p->as == ALONG) {
-				*op++ = opa[0];
-				opa[0] = 0;
-			}
-			return;
-		}
-		goto bad;
-
-	case 24:	/* bit field */
-		a = ((p->to.field&31)<<6) | (p->from.field&31);
-		if(p->as == ABFINS) {
-			b = asmea(p, &p->from);
-			if((b&0170) != 0)
-				goto bad;
-			a |= b<<12;
-			*op++ = a;
-			a = asmea(p, &p->to);
-		} else {
-			if(p->to.type != D_NONE) {
-				b = asmea(p, &p->to);
-				if((b&0170) != 0)
-					goto bad;
-				a |= b<<12;
-			}
-			*op++ = a;
-			a = asmea(p, &p->from);
-		}
-		t |= a;
-		a &= 0170;
-		if(a == 010 || a == 030 || a == 040 || a == 074)
-			goto bad;
-		break;
-
-	case 25:	/* movem */
-		if(p->from.type == D_CONST) { /* registers -> memory */
-			asmea(p, &p->from);
-			a = asmea(p, &p->to);
-			if(a == 074)
-				goto bad;
-			b = a & 0170;
-			if(b == 000 || b == 010 || b == 030)
-				goto bad;
-			t |= a;
-			break;
-		}
-		if(p->to.type == D_CONST) { /* memory -> registers */
-			t |= 0x400;
-			asmea(p, &p->to);
-			a = asmea(p, &p->from);
-			if(a == 074)
-				goto bad;
-			b = a & 0170;
-			if(b == 000 || b == 010 || b == 040)
-				goto bad;
-			t |= a;
-			break;
-		}
-		goto bad;
-
-	case 26:	/* chk */
-		a = asmea(p, &p->from);
-		if((a&0170) == 010)
-			goto bad;
-		b = asmea(p, &p->to);
-		if((b&0170) != 0)
-			goto bad;
-		t |= a;
-		t |= b<<9;
-		break;
-
-	case 27:	/* btst */
-		a = asmea(p, &p->from);
-		if(a == 074) {
-			t = o->opcode1;
-		} else
-		if((a&0170) != 0)
-			goto bad;
-		b = asmea(p, &p->to);
-		if(b == 074 || (b&0170) == 010)
-			goto bad;
-		t |= b;
-		break;
-
-	case 28:	/* fmovem */
-		if(p->from.type == D_CONST) { /* registers -> memory */
-			b = p->from.offset & 0xff;
-			b |= 0xf000;		/* control or postinc */
-			*op++ = b;
-			a = asmea(p, &p->to);
-			if(a == 074)
-				goto bad;
-			b = a & 0170;
-			if(b == 000 || b == 010 || b == 030)
-				goto bad;
-			if(b == 040)
-				op[-1] &= ~0x1000;	/* predec */
-			t |= a;
-			break;
-		}
-		if(p->to.type == D_CONST) { /* memory -> registers */
-			b = p->to.offset & 0xff;
-			b |= 0xd000;		/* control or postinc */
-			*op++ = b;
-			a = asmea(p, &p->from);
-			if(a == 074)
-				goto bad;
-			b = a & 0170;
-			if(b == 000 || b == 010 || b == 040)
-				goto bad;
-			t |= a;
-			break;
-		}
-		goto bad;
-
-	case 29:	/* fmovemc */
-		if(p->from.type == D_CONST) { /* registers -> memory */
-			b = (p->from.offset & 0x7) << 10;
-			b |= 0xa000;
-			*op++ = b;
-			a = asmea(p, &p->to);
-			if(a == 074)
-				goto bad;
-			b = a & 0170;
-			if(b == 000 || b == 010 || b == 030)
-				goto bad;
-			t |= a;
-			break;
-		}
-		if(p->to.type == D_CONST) { /* memory -> registers */
-			b = (p->to.offset & 0x7) << 10;
-			b |= 0x8000;
-			*op++ = b;
-			a = asmea(p, &p->from);
-			if(a == 074)
-				goto bad;
-			b = a & 0170;
-			if(b == 000 || b == 010 || b == 040)
-				goto bad;
-			t |= a;
-			break;
-		}
-		goto bad;
-
-	case 30:	/* trap */
-		if(p->to.type == D_CONST) {
-			t |= p->to.offset & 0xf;
-			break;
-		}
-		goto bad;
-
-	case 31:	/* chk2, cmp2 */
-		b = asmea(p, &p->to);
-		a = b & 0170;
-		if(a == 000 || a == 010) {
-			*op++ = o->opcode1 | (b << 12);
-			t |= asmea(p, &p->from);
-			break;
-		}
-		goto bad;
-
-	case 32:	/* casew */
-		/* jmp (0,pc,r0.w*1) */
-		casepc = p->pc;
-		*op++ = o->opcode1;
-		break;
-
-	case 33:	/* bcase */
-		q = copyp(p);
-		q->as = ADATA;
-		q->to.type = D_CONST;
-		q->to.offset = p->pcond->pc - casepc - 2;
-		q->from.displace = 2;
-		q->link = datap;
-		datap = q;
-		if(debug['a'])
-			Bprint(&bso, "%P\n", q);
-		op = opa;
-		return;
-
-	case 34:	/* moves */
-		op++;
-		a = asmea(p, &p->from);
-		b = a & 0170;
-		if(b == 0 || b == 010) {
-			opa[1] = (a << 12) | 0x800;
-			b = asmea(p, &p->to);
-			a = b & 0170;
-			if(a == 0 || a == 010)
-				goto bad;
-			t |= b;
-			break;
-		}
-		t |= a;
-		b = asmea(p, &p->to);
-		a = b & 0170;
-		if(a != 0 && a != 010)
-			goto bad;
-		opa[1] = (b << 12);
-		break;
-
-	case 35:	/* swap */
-		a = asmea(p, &p->to);
-		if((a & 0170) == 0) {
-			t |= a;
-			break;
-		}
-		goto bad;
-	}
-	opa[0] = t;
-	return;
-
-bad:
-	if(!debug['a'])
-		print("%P\n", p);
-	diag("bad combination of addressing in %s", TNAME);
-	opa[0] = 0;
-}
-
-int
-asmea(Prog *p, Adr *a)
-{
-	Optab *o;
-	int f, t, r, i;
-	short *top;
-	long v;
-
-	if(a->index != D_NONE)
-		goto index;
-	t = a->type;
-	r = simple[t];
-	v = a->offset;
-	if(r != 0177) {
-		if(v == 0)
-			return r;
-		if((r & 070) != 020)
-			return r;
-		if(v >= -32768L && v < 32768L) {
-			*op++ = v;
-			return t-D_A0-I_INDIR+050;	/* d(Ax) */
-		}
-		*op++ = 0x170;			/* is, no indirect */
-		*op++ = v>>16;
-		*op++ = v;
-		return t-D_A0-I_INDIR+060;	/* (d,Ax) */
-	}
-	f = 0;
-	if(a == &p->from)
-		f++;
-	o = &optab[p->as];
-	switch(t) {
-	case D_TOS:
-		if(f) {
-			if(o->srcsp)
-				return (3<<3) | 7;	/* (A7)+ */
-		} else
-			if(o->dstsp)
-				return (4<<3) | 7;	/* -(A7) */
-		return (2<<3) | 7;			/* (A7) */
-		
-	case D_BRANCH:
-		v = p->pcond->pc - p->pc - 2;
-		if(v < -32768L || v >= 32768L) {
-			*op++ = v>>16;
-			*op++ = v;
-			return 0xff;
-		}
-		if(v < -128 || v >= 128 || p->mark == 4) {
-			*op++ = v;
-			return 0;
-		}
-		return v & 0xff;
-
-	case I_ADDR|D_STATIC:
-	case I_ADDR|D_EXTERN:
-		t = a->sym->type;
-		if(t == 0 || t == SXREF) {
-			diag("undefined external: %s in %s",
-				a->sym->name, TNAME);
-			a->sym->type = SDATA;
-		}
-		v = a->sym->value + a->offset;
-		if(t != STEXT)
-			v += INITDAT;
-
-	case D_CONST:
-		switch(f? o->srcsp: o->dstsp) {
-		case 4:
-			*op++ = v>>16;
-
-		case 2:
-			*op++ = v;
-			break;
-
-		default:
-			diag("unknown srcsp asmea in %s", TNAME);
-		}
-		return (7<<3) | 4;
-
-	case D_FCONST:
-		r = f? o->srcsp: o->dstsp;
-		for(i=0; i<r; i++)
-			((char*)op)[i] = gnuxi(&a->ieee, i, r);
-		op += r/2;
-		return (7<<3) | 4;
-
-	case D_QUICK:
-		v = a->offset & 0xff;
-		return 0110 | (v<<7);
-			
-	case D_STACK:
-	case D_AUTO:
-	case D_PARAM:
-		if(v == 0)
-			return (2<<3) | 7;	/* (A7) */
-		if(v >= -32768L && v < 32768L) {
-			*op++ = v;
-			return (5<<3) | 7;	/* d(A7) */
-		}
-		*op++ = 0x170;			/* is, no indirect */
-		*op++ = v>>16;
-		*op++ = v;
-		return (6<<3) | 7;		/* (d,A7) */
-
-	case I_INDIR|D_CONST:
-		goto adr;
-
-	case D_STATIC:
-	case D_EXTERN:
-		t = a->sym->type;
-		if(t == 0 || t == SXREF) {
-			diag("undefined external: %s in %s",
-				a->sym->name, TNAME);
-			a->sym->type = SDATA;
-		}
-		if(t == STEXT) {
-			v = a->sym->value + a->offset;
-			*op++ = v>>16;
-			*op++ = v;
-			return (7<<3) | 1;
-		}
-		v = a->sym->value + a->offset - A6OFFSET;
-		if(debug['6']) {
-			v += INITDAT + A6OFFSET;
-			goto adr;
-		}
-		if(v == 0)
-			return (2<<3) | 6;
-		if(v >= -32768L && v < 32768L) {
-			*op++ = v;
-			return (5<<3) | 6;
-		}
-		v += INITDAT + A6OFFSET;
-
-	adr:
-		if(v >= -32768L && v < 32768L) {
-			*op++ = v;
-			return (7<<3) | 0;
-		}
-		*op++ = v>>16;
-		*op++ = v;
-		return (7<<3) | 1;
-	}
-	if(!debug['a'])
-		print("%P\n", p);
-	diag("unknown addressing mode: %d in %s", t, TNAME);
-	return 0;
-
-index:
-	top = op++;
-	t = a->index & D_MASK;
-	f = (a->scale & 7) << 9;	/* w/l scale */
-	f |= (t & 7) << 12;		/* register */
-	if(t < D_R0 || t >= D_R0+8) {
-		if(t >= D_A0 && t < D_A0+8) {
-			f |= 0x8000;	/* d/a */
-		} else
-		if(t == D_NONE)
-			f = 0x40;	/* is */
-		else
-			goto bad;
-	}
-
-	t = a->type;
-	r = t & 7;
-	v = a->offset;
-	if(t < (I_INDIR|D_A0) || t >= (I_INDIR|(D_A0+8)))
-	switch(t) {
-	default:
-		goto bad;
-
-	case I_INDIR|D_NONE:
-		f |= 0x80;		/* bs */
-		r = 0;
-		break;
-
-	case D_AUTO:
-	case D_PARAM:
-	case D_STACK:
-		r = 7;
-		break;
-
-	case D_STATIC:
-	case D_EXTERN:
-		t = a->sym->type;
-		if(t == 0 || t == SXREF) {
-			diag("undefined external: %s in %s",
-				a->sym->name, TNAME);
-			a->sym->type = SDATA;
-		}
-		r = 6;
-		v += a->sym->value - A6OFFSET;
-		if(t == STEXT) {
-			f |= 0x80;	/* bs */
-			r = 0;
-			v += A6OFFSET;
-			goto bdlong;
-		}
-		if(debug['6']) {
-			f |= 0x80;	/* bs */
-			r = 0;
-			v += INITDAT + A6OFFSET;
-		}
-	}
-	if(v == 0)
-		f |= 0x10;		/* bd size = null */
-	else
-	if(v >= -32768L && v < 32768L) {
-		f |= 0x20;		/* bd size = word */
-		*op++ = v;
-	} else {
-	bdlong:
-		f |= 0x30;		/* bd size = long */
-		*op++ = v>>16;
-		*op++ = v;
-	}
-	v = a->displace;
-	t = a->index & I_MASK;
-	if(t != I_INDEX1) {		/* non-memory index */
-		if(t == I_INDEX2)
-			f |= 5;		/* post indexing */
-		else
-		if(t == I_INDEX3)
-			f |= 1;		/* pre indexing */
-		else
-			goto bad;
-	}
-	if(v != 0) {
-		if(v >= -32768L && v < 32768L) {
-			f++;		/* is size = word */
-			*op++ = v;
-		} else {
-			f += 2;		/* is size = long */
-			*op++ = v>>16;
-			*op++ = v;
-		}
-	}
-	*top = f | 0x100;
-	return (6<<3) | r;
-
-bad:
-	if(!debug['a'])
-		print("%P\n", p);
-	diag("bad operand in %s", TNAME);
-	return 0;
-}
-
-void
-lput(long l)
-{
-
-	CPUT(l>>24)
-	CPUT(l>>16)
-	CPUT(l>>8)
-	CPUT(l)
-}
-
-void
-s16put(char *n)
-{
-	char name[16];
-	int i;
-
-	strncpy(name, n, sizeof(name));
-	for(i=0; i<sizeof(name); i++)
-		CPUT(name[i])
-}
-
-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(long s, long n)
-{
-	Prog *p;
-	char *cast;
-	long l, fl, j;
-	int i, c;
-
-	memset(buf.dbuf, 0, n+100);
-	for(p = datap; p != P; p = p->link) {
-		curp = p;
-		l = p->from.sym->value + p->from.offset - s;
-		c = p->from.displace;
-		i = 0;
-		if(l < 0) {
-			if(l+c <= 0)
-				continue;
-			while(l < 0) {
-				l++;
-				i++;
-			}
-		}
-		if(l >= n)
-			continue;
-		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, "%lux:%P\n\t\t", l+s+INITDAT, curp);
-					for(j=0; j<c; j++)
-						Bprint(&bso, "%.2ux", cast[fnuxi8[j+4]] & 0xff);
-					Bprint(&bso, "\n");
-				}
-				for(; i<c; i++) {
-					buf.dbuf[l] = cast[fnuxi8[i+4]];
-					l++;
-				}
-				break;
-			case 8:
-				cast = (char*)&p->to.ieee;
-				if(debug['a'] && i == 0) {
-					Bprint(&bso, "%lux:%P\n\t\t", l+s+INITDAT, curp);
-					for(j=0; j<c; j++)
-						Bprint(&bso, "%.2ux", cast[fnuxi8[j]] & 0xff);
-					Bprint(&bso, "\n");
-				}
-				for(; i<c; i++) {
-					buf.dbuf[l] = cast[fnuxi8[i]];
-					l++;
-				}
-				break;
-			}
-			break;
-
-		case D_SCONST:
-			if(debug['a'] && i == 0) {
-				Bprint(&bso, "%lux:%P\n\t\t", l+s+INITDAT, curp);
-				for(j=0; j<c; j++)
-					Bprint(&bso, "%.2ux", p->to.scon[j] & 0xff);
-				Bprint(&bso, "\n");
-			}
-			for(; i<c; i++) {
-				buf.dbuf[l] = p->to.scon[i];
-				l++;
-			}
-			break;
-		default:
-			fl = p->to.offset;
-			if(p->to.sym) {
-				if(p->to.sym->type == STEXT)
-					fl += p->to.sym->value;
-				if(p->to.sym->type == SDATA)
-					fl += p->to.sym->value + INITDAT;
-				if(p->to.sym->type == SBSS)
-					fl += p->to.sym->value + INITDAT;
-			}
-
-			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, "%lux:%P\n\t\t", l+s+INITDAT, curp);
-					for(j=0; j<c; j++)
-						Bprint(&bso, "%.2ux",cast[inuxi1[j]] & 0xff);
-					Bprint(&bso, "\n");
-				}
-				for(; i<c; i++) {
-					buf.dbuf[l] = cast[inuxi1[i]];
-					l++;
-				}
-				break;
-			case 2:
-				if(debug['a'] && i == 0) {
-					Bprint(&bso, "%lux:%P\n\t\t", l+s+INITDAT, curp);
-					for(j=0; j<c; j++)
-						Bprint(&bso, "%.2ux",cast[inuxi2[j]] & 0xff);
-					Bprint(&bso, "\n");
-				}
-				for(; i<c; i++) {
-					buf.dbuf[l] = cast[inuxi2[i]];
-					l++;
-				}
-				break;
-			case 4:
-				if(debug['a'] && i == 0) {
-					Bprint(&bso, "%lux:%P\n\t\t", l+s+INITDAT, curp);
-					for(j=0; j<c; j++)
-						Bprint(&bso, "%.2ux",cast[inuxi4[j]] & 0xff);
-					Bprint(&bso, "\n");
-				}
-				for(; i<c; i++) {
-					buf.dbuf[l] = cast[inuxi4[i]];
-					l++;
-				}
-				break;
-			}
-			break;
-		}
-	}
-	write(cout, buf.dbuf, n);
-}
-
-int
-gnuxi(Ieee *d, int i, int c)
-{
-	char *p;
-	long l;
-
-	switch(c) {
-	default:
-		diag("bad nuxi %d %d\n%P", c, i, curp);
-		return 0;
-	
-		/*
-		 * 2301 vax
-		 * 0123 68k
-		 */
-	case 4:
-		l = ieeedtof(d);
-		p = (char*)&l;
-		i = gnuxi8[i+4];
-		break;
-
-		/*
-		 * 67452301 vax
-		 * 45670123 68k
-		 */
-	case 8:
-		p = (char*)d;
-		i = gnuxi8[i];
-		break;
-	}
-	return p[i];
-}
-
-long
-rnd(long v, long r)
-{
-	long c;
-
-	if(r <= 0)
-		return v;
-	v += r - 1;
-	c = v % r;
-	if(c < 0)
-		c += r;
-	v -= c;
-	return v;
-}

+ 0 - 50
sys/src/cmd/2l/compat.c

@@ -1,50 +0,0 @@
-#include	"l.h"
-
-/*
- * fake malloc
- */
-void*
-malloc(ulong 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(ulong m, ulong n)
-{
-	void *p;
-
-	n *= m;
-	p = malloc(n);
-	memset(p, 0, n);
-	return p;
-}
-
-void*
-realloc(void *p, ulong n)
-{
-	fprint(2, "realloc(0x%p %ld) called\n", p, n);
-	abort();
-	return 0;
-}
-
-void*
-mysbrk(ulong size)
-{
-	return sbrk(size);
-}

+ 0 - 12
sys/src/cmd/2l/cputime.c

@@ -1,12 +0,0 @@
-double
-cputime(void)
-{
-	long t[4];
-	long times(long*);
-	int i;
-
-	times(t);
-	for(i=1; i<4; i++)
-		t[0] += t[i];
-	return t[0] / 100.;
-}

+ 0 - 266
sys/src/cmd/2l/l.h

@@ -1,266 +0,0 @@
-#include	<u.h>
-#include	<libc.h>
-#include	<bio.h>
-#include	"../2c/2.out.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(); }
-
-typedef	struct	Adr	Adr;
-typedef	struct	Prog	Prog;
-typedef	struct	Sym	Sym;
-typedef	struct	Auto	Auto;
-typedef	struct	Optab	Optab;
-
-struct	Adr
-{
-	short	type;
-	short	index;
-	union
-	{
-		struct
-		{
-			long	u0displace;
-			long	u0offset;
-		} s0;
-		char	u0scon[8];
-		Prog	*u0cond;	/* not used, but should be D_BRANCH */
-		Ieee	u0ieee;
-	} u0;
-	union
-	{
-		Auto*	u1autom;
-		Sym*	u1sym;
-	} u1;
-	uchar	field;
-	uchar	scale;
-};
-
-#define	displace u0.s0.u0displace
-#define	offset	u0.s0.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;
-	union
-	{
-		long	u0stkoff;
-		Prog	*u0forwd;
-	} u0;
-	Prog*	link;
-	Prog*	pcond;	/* work on this */
-	long	pc;
-	long	line;
-	short	as;
-	uchar	mark;	/* work on these */
-	uchar	back;
-};
-
-#define	stkoff	u0.u0stkoff
-#define	forwd	u0.u0forwd
-
-struct	Auto
-{
-	Sym*	asym;
-	Auto*	link;
-	long	aoffset;
-	short	type;
-};
-struct	Sym
-{
-	char	*name;
-	short	type;
-	short	version;
-	short	become;
-	short	frame;
-	long	value;
-	Sym*	link;
-};
-struct	Optab
-{
-	short	as;
-	short	fas;
-	short	srcsp;
-	short	dstsp;
-	ushort	optype;
-	ushort	opcode0;
-	ushort	opcode1;
-	ushort	opcode2;
-	ushort	opcode3;
-};
-
-enum
-{
-	STEXT		= 1,
-	SDATA,
-	SBSS,
-	SDATA1,
-	SXREF,
-	SAUTO,
-	SPARAM,
-	SFILE,
-	NHASH		= 10007,
-	NHUNK		= 100000,
-	MINSIZ		= 4,
-	STRINGSZ	= 200,
-	MAXIO		= 8192,
-	MAXHIST		= 20,				/* limit of path elements for history symbols */
-	A6OFFSET 	= 32766
-};
-
-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
-
-EXTERN	long	HEADR;
-EXTERN	long	HEADTYPE;
-EXTERN	long	INITDAT;
-EXTERN	long	INITRND;
-EXTERN	long	INITTEXT;
-EXTERN	char*	INITENTRY;		/* entry point */
-EXTERN	Biobuf	bso;
-EXTERN	long	bsssize;
-EXTERN	long	casepc;
-EXTERN	int	cbc;
-EXTERN	char*	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	fnuxi8[8];
-EXTERN	char	gnuxi8[8];
-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	long	ncase;
-EXTERN	long	ndata;
-EXTERN	int	nerrors;
-EXTERN	long	nhunk;
-EXTERN	long	nsymbol;
-EXTERN	char*	noname;
-EXTERN	short*	op;
-EXTERN	char*	outfile;
-EXTERN	long	pc;
-EXTERN	char	simple[I_MASK];
-EXTERN	char	special[I_MASK];
-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	Optab	optab[];
-extern	char	mmsize[];
-extern	char*	anames[];
-
-#pragma	varargck	type	"A"	int
-#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
-
-int	Aconv(Fmt*);
-int	Dconv(Fmt*);
-int	Pconv(Fmt*);
-int	Rconv(Fmt*);
-int	Sconv(Fmt*);
-int	Xconv(Fmt*);
-void	addhist(long, int);
-int	andsize(Prog*, Adr*);
-Prog*	appendp(Prog*);
-void	asmb(void);
-int	asmea(Prog*, Adr*);
-void	asmins(Prog*);
-void	asmlc(void);
-void	asmsp(void);
-void	asmsym(void);
-long	atolwhex(char*);
-Prog*	brchain(Prog*);
-Prog*	brloop(Prog*);
-void	cflush(void);
-Prog*	copyp(Prog*);
-double	cputime(void);
-void	datblk(long, long);
-void	diag(char*, ...);
-void	dodata(void);
-void	doprof1(void);
-void	doprof2(void);
-void	dostkoff(void);
-long	entryvalue(void);
-void	errorexit(void);
-int	find1(long, int);
-int	find2(long, int);
-void	follow(void);
-void	gethunk(void);
-int	gnuxi(Ieee*, int, int);
-void	histtoauto(void);
-double	ieeedtod(Ieee*);
-long	ieeedtof(Ieee*);
-void	ldobj(int, long, char*);
-void	loadlib(void);
-void	listinit(void);
-Sym*	lookup(char*, int);
-void	lput(long);
-void	main(int, char*[]);
-void	mkfwd(void);
-void*	mysbrk(ulong);
-void	nuxiinit(void);
-void	objfile(char*);
-void	patch(void);
-Prog*	prg(void);
-int	relinv(int);
-long	reuse(Prog*, Sym*);
-long	rnd(long, long);
-void	s16put(char*);
-void	span(void);
-void	undef(void);
-void	xdefine(char*, int, long);
-void	xfol(Prog*);
-int	zaddr(uchar*, Adr*, Sym*[]);

+ 0 - 395
sys/src/cmd/2l/list.c

@@ -1,395 +0,0 @@
-#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], s[20];
-	Prog *p;
-
-	p = va_arg(fp->args, Prog*);
-	bigP = p;
-	sprint(str, "(%ld)	%A	%D,%D",
-		p->line, p->as, &p->from, &p->to);
-	if(p->from.field) {
-		sprint(s, ",%d,%d", p->to.field, p->from.field);
-		strcat(str, s);
-	}
-	bigP = P;
-	return fmtstrcpy(fp, str);
-}
-
-int
-Aconv(Fmt *fp)
-{
-
-	return fmtstrcpy(fp, anames[va_arg(fp->args, int)]);
-}
-
-int
-Xconv(Fmt *fp)
-{
-	char str[20], s[10];
-	int i0, i1;
-
-	str[0] = 0;
-	i0 = va_arg(fp->args, int) & D_MASK;
-	i1 = va_arg(fp->args, int);
-	if(i0 != D_NONE) {
-		sprint(str, "(%R.", i0);
-		sprint(s, "%c*%c)",
-			"WWWWLLLL"[i1],
-			"12481248"[i1]);
-		strcat(str, s);
-	}
-	return fmtstrcpy(fp, str);
-}
-
-int
-Dconv(Fmt *fp)
-{
-	char str[40], s[20];
-	Adr *a;
-	int i, j;
-	long d;
-
-	a = va_arg(fp->args, Adr*);
-	i = a->index;
-	if(i != D_NONE) {
-		a->index = D_NONE;
-		d = a->displace;
-		a->displace = 0;
-		switch(i & I_MASK) {
-		default:
-			sprint(str, "???%ld(%D)", d, a);
-			break;
-
-		case I_INDEX1:
-			sprint(str, "%D", a);
-			break;
-
-		case I_INDEX2:
-			if(d)
-				sprint(str, "%ld(%D)", d, a);
-			else
-				sprint(str, "(%D)", a);
-			break;
-
-		case I_INDEX3:
-			if(d)
-				sprint(str, "%ld(%D", d, a);
-			else
-				sprint(str, "(%D", a);
-			break;
-		}
-
-		if(i != D_NONE) {
-			j = a->scale & 7;
-			sprint(strchr(str,0), "(%R.", i);
-			sprint(strchr(str,0), "%c*%c)",
-				"WWWWLLLL"[j],
-				"12481248"[j]);
-		}
-		if((i & I_MASK) == I_INDEX3)
-			strcat(str, ")");
-		a->displace = d;
-		a->index = i;
-		goto out;
-	}
-	i = a->type;
-	j = i & I_MASK;
-	if(j) {
-		a->type = i & D_MASK;
-		d = a->offset;
-		a->offset = 0;
-		switch(j) {
-		case I_INDINC:
-			sprint(str, "(%D)+", a);
-			break;
-
-		case I_INDDEC:
-			sprint(str, "-(%D)", a);
-			break;
-
-		case I_INDIR:
-			if(d)
-				sprint(str, "%ld(%D)", d, a);
-			else
-				sprint(str, "(%D)", a);
-			break;
-
-		case I_ADDR:
-			a->offset = d;
-			sprint(str, "$%D", a);
-			break;
-		}
-		a->type = i;
-		a->offset = d;
-		goto out;
-	}
-	switch(i) {
-
-	default:
-		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, "%lux+%s", bigP->pcond->pc,
-					a->sym->name);
-			else
-				sprint(str, "%lux", bigP->pcond->pc);
-		else
-			sprint(str, "%ld(PC)", a->offset);
-		break;
-
-	case D_EXTERN:
-		sprint(str, "%s+%ld(SB)", a->sym->name, a->offset);
-		break;
-
-	case D_STATIC:
-		sprint(str, "%s<%d>+%ld(SB)", a->sym->name,
-			a->sym->version, a->offset);
-		break;
-
-	case D_AUTO:
-		sprint(str, "%s+%ld(SP)", a->sym->name, a->offset);
-		break;
-
-	case D_PARAM:
-		if(a->sym)
-			sprint(str, "%s+%ld(FP)", a->sym->name, a->offset);
-		else
-			sprint(str, "%ld(FP)", a->offset);
-		break;
-
-	case D_CONST:
-		sprint(str, "$%ld", a->offset);
-		break;
-
-	case D_STACK:
-		sprint(str, "TOS+%ld", a->offset);
-		break;
-
-	case D_QUICK:
-		sprint(str, "$Q%ld", a->offset);
-		break;
-
-	case D_FCONST:
-		sprint(str, "$(%.8lux,%.8lux)", a->ieee.h, a->ieee.l);
-		goto out;
-
-	case D_SCONST:
-		sprint(str, "$\"%S\"", a->scon);
-		goto out;
-	}
-	if(a->displace) {
-		sprint(s, "/%ld", a->displace);
-		strcat(str, s);
-	}
-out:
-	return fmtstrcpy(fp, str);
-}
-
-int
-Rconv(Fmt *fp)
-{
-	char str[20];
-	int r;
-
-	r = va_arg(fp->args, int);
-	if(r >= D_R0 && r < D_R0+NREG)
-		sprint(str, "R%d", r-D_R0);
-	else
-	if(r >= D_A0 && r < D_A0+NREG)
-		sprint(str, "A%d", r-D_A0);
-	else
-	if(r >= D_F0 && r < D_F0+NREG)
-		sprint(str, "F%d", r-D_F0);
-	else
-	switch(r) {
-
-	default:
-		sprint(str, "gok(%d)", r);
-		break;
-
-	case D_NONE:
-		sprint(str, "NONE");
-		break;
-
-	case D_TOS:
-		sprint(str, "TOS");
-		break;
-
-	case D_CCR:
-		sprint(str, "CCR");
-		break;
-
-	case D_SR:
-		sprint(str, "SR");
-		break;
-
-	case D_SFC:
-		sprint(str, "SFC");
-		break;
-
-	case D_DFC:
-		sprint(str, "DFC");
-		break;
-
-	case D_CACR:
-		sprint(str, "CACR");
-		break;
-
-	case D_USP:
-		sprint(str, "USP");
-		break;
-
-	case D_VBR:
-		sprint(str, "VBR");
-		break;
-
-	case D_CAAR:
-		sprint(str, "CAAR");
-		break;
-
-	case D_MSP:
-		sprint(str, "MSP");
-		break;
-
-	case D_ISP:
-		sprint(str, "ISP");
-		break;
-
-	case D_FPCR:
-		sprint(str, "FPCR");
-		break;
-
-	case D_FPSR:
-		sprint(str, "FPSR");
-		break;
-
-	case D_FPIAR:
-		sprint(str, "FPIAR");
-		break;
-
-	case D_TREE:
-		sprint(str, "TREE");
-		break;
-
-	case D_TC:
-		sprint(str, "TC");
-		break;
-
-	case D_ITT0:
-		sprint(str, "ITT0");
-		break;
-
-	case D_ITT1:
-		sprint(str, "ITT1");
-		break;
-
-	case D_DTT0:
-		sprint(str, "DTT0");
-		break;
-
-	case D_DTT1:
-		sprint(str, "DTT1");
-		break;
-
-	case D_MMUSR:
-		sprint(str, "MMUSR");
-		break;
-	case D_URP:
-		sprint(str, "URP");
-		break;
-
-	case D_SRP:
-		sprint(str, "SRP");
-		break;
-	}
-	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 > 10) {
-		print("too many errors\n");
-		errorexit();
-	}
-}

+ 0 - 22
sys/src/cmd/2l/mkfile

@@ -1,22 +0,0 @@
-</$objtype/mkfile
-
-TARG=2l
-OFILES=\
-	asm.$O\
-	obj.$O\
-	optab.$O\
-	pass.$O\
-	span.$O\
-	list.$O\
-	enam.$O\
-	compat.$O\
-
-HFILES=\
-	l.h\
-	../2c/2.out.h\
-
-BIN=/$objtype/bin
-</sys/src/cmd/mkone
-
-enam.$O:	../2c/enam.c
-	$CC $CFLAGS ../2c/enam.c

+ 0 - 1435
sys/src/cmd/2l/obj.c

@@ -1,1435 +0,0 @@
-#define	EXTERN
-#include	"l.h"
-#include	<ar.h>
-
-#ifndef	DEFAULT
-#define	DEFAULT	'9'
-#endif
-
-char	*noname		= "<none>";
-char	symname[]	= SYMDEF;
-char	thechar		= '2';
-char	*thestring 	= "68020";
-
-/*
- *	-H0 -T0x40004C -D0x10000000	is garbage unix
- *	-H1 -T0x80020000 -R4		is garbage format
- *	-H2 -T8224 -R8192		is plan9 format
- *	-H3 -Tx -Rx			is next boot
- */
-
-void
-main(int argc, char *argv[])
-{
-	int i, c;
-	char *a;
-
-	Binit(&bso, 1, OWRITE);
-	cout = -1;
-	listinit();
-	memset(debug, 0, sizeof(debug));
-	nerrors = 0;
-	outfile = "2.out";
-	HEADTYPE = -1;
-	INITTEXT = -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 'T':
-		a = ARGF();
-		if(a)
-			INITTEXT = atolwhex(a);
-		break;
-	case 'D':
-		a = ARGF();
-		if(a)
-			INITDAT = atolwhex(a);
-		break;
-	case 'R':
-		a = ARGF();
-		if(a)
-			INITRND = atolwhex(a);
-		break;
-	} ARGEND
-
-	USED(argc);
-
-	if(*argv == 0) {
-		diag("usage: 2l [-options] objects");
-		errorexit();
-	}
-	if(!debug['9'] && !debug['U'] && !debug['B'])
-		debug[DEFAULT] = 1;
-	if(HEADTYPE == -1) {
-		if(debug['U'])
-			HEADTYPE = 2;
-		if(debug['B'])
-			HEADTYPE = 2;
-		if(debug['9'])
-			HEADTYPE = 2;
-	}
-	if(INITDAT != -1 && INITRND == -1)
-		INITRND = 0;
-	switch(HEADTYPE) {
-	default:
-		diag("unknown -H option %ld", HEADTYPE);
-		errorexit();
-
-	case 0:	/* this is garbage */
-		HEADR = 20L+56L;
-		if(INITTEXT == -1)
-			INITTEXT = 0x40004CL;
-		if(INITDAT == -1)
-			INITDAT = 0x10000000L;
-		if(INITDAT != 0 && INITRND == -1)
-			INITRND = 0;
-		if(INITRND == -1)
-			INITRND = 0;
-		break;
-	case 1:	/* plan9 boot data goes into text */
-		HEADR = 32L;
-		if(INITTEXT == -1)
-			INITTEXT = 8224;
-		if(INITDAT == -1)
-			INITDAT = 0;
-		if(INITDAT != 0 && INITRND == -1)
-			INITRND = 0;
-		if(INITRND == -1)
-			INITRND = 8192;
-		break;
-	case 2:	/* plan 9 */
-		HEADR = 32L;
-		if(INITTEXT == -1)
-			INITTEXT = 8224;
-		if(INITDAT == -1)
-			INITDAT = 0;
-		if(INITDAT != 0 && INITRND == -1)
-			INITRND = 0;
-		if(INITRND == -1)
-			INITRND = 8192;
-		break;
-	case 3:	/* next boot */
-		HEADR = 28+124+192+24;
-		if(INITTEXT == -1)
-			INITTEXT = 0x04002000;
-		if(INITDAT == -1)
-			INITDAT = 0;
-		if(INITDAT != 0 && INITRND == -1)
-			INITRND = 0;
-		if(INITRND == -1)
-			INITRND = 8192L;
-		break;
-	case 4:	/* preprocess pilot */
-		HEADR = 32L;
-		if(INITTEXT == -1)
-			INITTEXT = 0;
-		if(INITDAT == -1)
-			INITDAT = 0;
-		if(INITDAT != 0 && INITRND == -1)
-			INITRND = 0;
-		if(INITRND == -1)
-			INITRND = 32;
-		break;
-	}
-	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();
-		}
-
-	zprg.link = P;
-	zprg.pcond = P;
-	zprg.back = 2;
-	zprg.as = AGOK;
-	zprg.from.type = D_NONE;
-	zprg.from.index = D_NONE;
-	zprg.to = zprg.from;
-
-	memset(special, 0, sizeof(special));
-	special[D_CCR] = 1;
-	special[D_SR] = 1;
-	special[D_SFC] = 1;
-	special[D_CACR] = 1;
-	special[D_USP] = 1;
-	special[D_VBR] = 1;
-	special[D_CAAR] = 1;
-	special[D_MSP] = 1;
-	special[D_ISP] = 1;
-	special[D_DFC] = 1;
-	special[D_FPCR] = 1;
-	special[D_FPSR] = 1;
-	special[D_FPIAR] = 1;
- 	special[D_TC] = 1;
-	special[D_ITT0] = 1;
-	special[D_ITT1] = 1;
-	special[D_DTT0] = 1;
-	special[D_DTT1] = 1;
-	special[D_MMUSR] = 1;
-	special[D_URP] = 1;
-	special[D_SRP] = 1;
-	memset(simple, 0177, sizeof(simple));
-	for(i=0; i<8; i++) {
-		simple[D_R0+i] = i;
-		simple[D_F0+i] = i+0100;
-		simple[D_A0+i] = i+010;
-		simple[D_A0+I_INDIR+i] = i+020;
-		simple[D_A0+I_INDINC+i] = i+030;
-		simple[D_A0+I_INDDEC+i] = i+040;
-	}
-	nuxiinit();
-	histgen = 0;
-	textp = P;
-	datap = P;
-	pc = 0;
-	cout = create(outfile, 1, 0775);
-	if(cout < 0) {
-		diag("cannot create %s", 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
-		lookup(INITENTRY, 0)->type = SXREF;
-
-	while(*argv)
-		objfile(*argv++);
-	if(!debug['l'])
-		loadlib();
-	firstp = firstp->link;
-	if(firstp == P)
-		errorexit();
-	patch();
-	if(debug['p'])
-		if(debug['1'])
-			doprof1();
-		else
-			doprof2();
-	follow();
-	dodata();
-	dostkoff();
-	span();
-	asmb();
-	undef();
-	if(debug['v']) {
-		Bprint(&bso, "%5.2f cpu time\n", cputime());
-		Bprint(&bso, "%ld+%ld = %ld data statements\n",
-			ndata, ncase, ndata+ncase);
-		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
-loadlib(void)
-{
-	int i;
-	long 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)
-{
-
-	Bflush(&bso);
-	if(nerrors) {
-		if(cout >= 0)
-			remove(outfile);
-		exits("error");
-	}
-	exits(0);
-}
-
-void
-objfile(char *file)
-{
-	long off, esym, cnt, l;
-	int f, work;
-	Sym *s;
-	char magbuf[SARMAG];
-	char name[100], pname[150];
-	struct ar_hdr arhdr;
-	char *e, *start, *stop;
-
-	if(file[0] == '-' && file[1] == 'l') {
-		if(debug['9'])
-			sprint(name, "/%s/lib/lib", thestring);
-		else
-			sprint(name, "/usr/%clib/lib", thechar);
-		strcat(name, file+2);
-		strcat(name, ".a");
-		file = name;
-	}
-	if(debug['v'])
-		Bprint(&bso, "%5.2f ldobj: %s\n", cputime(), file);
-	Bflush(&bso);
-	f = open(file, 0);
-	if(f < 0) {
-		diag("cannot open file: %s", 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);
-			l = read(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(uchar *p, Adr *a, Sym *h[])
-{
-	int c, t, i;
-	long l;
-	Sym *s;
-	Auto *u;
-
-	t = p[0];
-
-	/*
-	 * first try the high-time formats
-	 */
-	if(t == 0) {
-		a->index = D_NONE;
-		a->type = p[1];
-		return 2;
-	}
-	if(t == T_OFFSET) {
-		a->index = D_NONE;
-		a->offset = p[1] | (p[2]<<8) | (p[3]<<16) | (p[4]<<24);
-		a->type = p[5];
-		return 6;
-	}
-	if(t == (T_OFFSET|T_SYM)) {
-		a->index = D_NONE;
-		a->offset = p[1] | (p[2]<<8) | (p[3]<<16) | (p[4]<<24);
-		s = h[p[5]];
-		a->sym = s;
-		a->type = p[6];
-		c = 7;
-		goto dosym;
-	}
-	if(t == T_SYM) {
-		a->index = D_NONE;
-		s = h[p[1]];
-		a->sym = s;
-		a->type = p[2];
-		c = 3;
-		goto dosym;
-	}
-	if(t == (T_INDEX|T_OFFSET|T_SYM)) {
-		a->index = p[1] | (p[2]<<8);
-		a->scale = p[3];
-		a->displace = p[4] | (p[5]<<8) | (p[6]<<16) | (p[7]<<24);
-		a->offset = p[8] | (p[9]<<8) | (p[10]<<16) | (p[11]<<24);
-		s = h[p[12]];
-		a->sym = s;
-		a->type = p[13];
-		c = 14;
-		goto dosym;
-	}
-
-	/*
-	 * now do it the hard way
-	 */
-	c = 1;
-	a->index = D_NONE;
-	if(t & T_FIELD) {
-		a->field = p[c] | (p[c+1]<<8);
-		c += 2;
-	}
-	if(t & T_INDEX) {
-		a->index = p[c] | (p[c+1]<<8);
-		a->scale = p[c+2];
-		a->displace = p[c+3] | (p[c+4]<<8) | (p[c+5]<<16) | (p[c+6]<<24);
-		c += 7;
-	}
-	if(t & T_OFFSET) {
-		a->offset = p[c] | (p[c+1]<<8) | (p[c+2]<<16) | (p[c+3]<<24);
-		c += 4;
-	}
-	if(t & T_SYM) {
-		a->sym = h[p[c]];
-		c += 1;
-	}
-	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;
-	} else
-	if(t & T_TYPE) {
-		a->type = p[c] | (p[c+1]<<8);
-		c += 2;
-	} else {
-		a->type = p[c];
-		c++;
-	}
-	s = a->sym;
-	if(s == S)
-		return c;
-
-dosym:
-	t = a->type & D_MASK;
-	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 name[1024], comp[256], *p;
-	int i;
-
-	if(histfrogp <= 0)
-		return;
-
-	if(histfrog[0]->name[1] == '/') {
-		sprint(name, "");
-		i = 1;
-	} else
-	if(histfrog[0]->name[1] == '.') {
-		sprint(name, ".");
-		i = 0;
-	} else {
-		if(debug['9'])
-			sprint(name, "/%s/lib", thestring);
-		else
-			sprint(name, "/usr/%clib", thechar);
-		i = 0;
-	}
-
-	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(name) + strlen(comp) + 3 >= sizeof(name)) {
-			diag("library component too long");
-			return;
-		}
-		strcat(name, "/");
-		strcat(name, comp);
-	}
-	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(long 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;
-}
-
-uchar*
-readsome(int f, uchar *buf, uchar *good, uchar *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, long c, char *pn)
-{
-	Prog *p;
-	Sym *h[NSYM], *s;
-	int v, o, r;
-	long ipc, lv;
-	double dv;
-	uchar *bloc, *bsize, *stop;
-
-	bsize = buf.xbuf;
-	bloc = buf.xbuf;
-
-newloop:
-	memset(h, 0, sizeof(h));
-	version++;
-	histfrogp = 0;
-	ipc = pc;
-
-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 .2 file\n");
-		errorexit();
-	}
-
-	if(o == ANAME || o == ASIGNAME) {
-		if(o == ASIGNAME) {
-			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['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 ABCASE:
-		ncase++;
-		goto casdef;
-
-	case ADATA:
-		p->link = datap;
-		datap = p;
-		ndata++;
-		goto loop;
-
-	case AGOK:
-		diag("%s: unknown opcode in %s", pn, TNAME);
-		pc++;
-		goto loop;
-
-	case ATEXT:
-		if(curtext != P) {
-			histtoauto();
-			curtext->to.autom = curauto;
-			curauto = 0;
-		}
-		curtext = p;
-		lastp->link = p;
-		lastp = p;
-		p->pc = pc;
-		s = p->from.sym;
-		if(s->type != 0 && s->type != SXREF)
-			diag("%s: redefinition: %s", pn, s->name);
-		s->type = STEXT;
-		s->value = p->pc;
-		pc++;
-		p->pcond = P;
-		if(textp == P) {
-			textp = p;
-			etextp = p;
-			goto loop;
-		}
-		etextp->pcond = p;
-		etextp = p;
-		goto loop;
-
-	case AJSR:
-		p->as = ABSR;
-
-	case ABSR:
-		if(p->to.index != D_NONE)
-			p->as = AJSR;
-		if(p->to.type != D_EXTERN && p->to.type != D_STATIC)
-			p->as = AJSR;
-		goto casdef;
-
-	case AMOVL:
-	case AMOVB:
-	case AMOVW:
-		if(p->from.type != D_CONST)
-			goto casdef;
-		lv = p->from.offset;
-		if(lv >= -128 && lv < 128)
-		if(p->to.type >= D_R0 && p->to.type < D_R0+8)
-		if(p->to.index == D_NONE) {
-			p->from.type = D_QUICK;
-			goto casdef;
-		}
-
-		if(lv >= -0x7fff && lv <= 0x7fff)
-		if(p->to.type >= D_A0 && p->to.type < D_A0+8)
-		if(p->to.index == D_NONE)
-		if(p->as == AMOVL)
-			p->as = AMOVW;
-		goto casdef;
-
-	case AADDB:
-	case AADDL:
-	case AADDW:
-		if(p->from.type != D_CONST)
-			goto casdef;
-		lv = p->from.offset;
-		if(lv < 0) {
-			lv = -lv;
-			p->from.offset = lv;
-			if(p->as == AADDB)
-				p->as = ASUBB;
-			else
-			if(p->as == AADDW)
-				p->as = ASUBW;
-			else
-			if(p->as == AADDL)
-				p->as = ASUBL;
-		}
-		if(lv > 0)
-		if(lv <= 8)
-			p->from.type = D_QUICK;
-		goto casdef;
-
-	case ASUBB:
-	case ASUBL:
-	case ASUBW:
-		if(p->from.type != D_CONST)
-			goto casdef;
-		lv = p->from.offset;
-		if(lv < 0) {
-			lv = -lv;
-			p->from.offset = lv;
-			if(p->as == ASUBB)
-				p->as = AADDB;
-			else
-			if(p->as == ASUBW)
-				p->as = AADDW;
-			else
-			if(p->as == ASUBL)
-				p->as = AADDL;
-		}
-		if(lv > 0)
-		if(lv <= 8)
-			p->from.type = D_QUICK;
-		goto casdef;
-
-	case AROTRB:
-	case AROTRL:
-	case AROTRW:
-	case AROTLB:
-	case AROTLL:
-	case AROTLW:
-
-	case AASLB:
-	case AASLL:
-	case AASLW:
-	case AASRB:
-	case AASRL:
-	case AASRW:
-	case ALSLB:
-	case ALSLL:
-	case ALSLW:
-	case ALSRB:
-	case ALSRL:
-	case ALSRW:
-		if(p->from.type == D_CONST)
-		if(p->from.offset > 0)
-		if(p->from.offset <= 8)
-			p->from.type = D_QUICK;
-		goto casdef;
-
-	case ATSTL:
-		if(p->to.type >= D_A0 && p->to.type < D_A0+8) {
-			p->as = ACMPW;
-			p->from = p->to;
-			p->to.type = D_CONST;
-			p->to.offset = 0;
-		}
-		goto casdef;
-
-	case ACMPL:
-		if(p->to.type != D_CONST)
-			goto casdef;
-		lv = p->to.offset;
-		if(lv >= -0x7fff && lv <= 0x7fff)
-		if(p->from.type >= D_A0 && p->from.type < D_A0+8)
-		if(p->from.index == D_NONE)
-			p->as = ACMPW;
-		goto casdef;
-
-	case ACLRL:
-		if(p->to.type >= D_A0 && p->to.type < D_A0+8) {
-			p->as = AMOVW;
-			p->from.type = D_CONST;
-			p->from.offset = 0;
-		}
-		goto casdef;
-
-	casdef:
-	default:
-		if(p->from.type == D_FCONST)
-		if(optab[p->as].fas != AXXX) {
-			dv = ieeedtod(&p->from.ieee);
-			if(dv >= -(1L<<30) && dv <= (1L<<30)) {
-				lv = dv;
-				if(lv == dv) {
-					p->as = optab[p->as].fas;
-					p->from.type = D_CONST;
-					p->from.offset = lv;
-					p->from.displace = 0;
-				}
-			}
-		}
-		if(p->to.type == D_BRANCH)
-			p->to.offset += ipc;
-		lastp->link = p;
-		lastp = p;
-		p->pc = pc;
-		pc++;
-		goto loop;
-	}
-	/* not reached */
-
-eof:
-	diag("%s: truncated object file in %s", pn, TNAME);
-}
-
-Sym*
-lookup(char *symb, int v)
-{
-	Sym *s;
-	char *p;
-	long h;
-	int l, c;
-
-	h = v;
-	for(p=symb; c = *p; p++)
-		h = h+h+h + c;
-	l = (p - symb) + 1;
-	if(h < 0)
-		h = ~h;
-	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;
-	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;
-	long 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;
-	long 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->as = AADDL;
-			q->line = p->line;
-			q->pc = p->pc;
-			q->link = p->link;
-			p->link = q;
-			q->from.type = D_CONST;
-			q->from.offset = 1;
-			q->to.type = D_EXTERN;
-			q->to.sym = s;
-			q->to.offset = n*4 + 4;
-
-			q = prg();
-			q->as = ADATA;
-			q->line = p->line;
-			q->link = datap;
-			datap = q;
-			q->from.type = D_EXTERN;
-			q->from.sym = s;
-			q->from.offset = n*4;
-			q->from.displace = 4;
-			q->to.type = D_EXTERN;
-			q->to.sym = p->from.sym;
-			n += 2;
-			continue;
-		}
-	}
-	q = prg();
-	q->line = 0;
-	q->as = ADATA;
-	q->link = datap;
-	datap = q;
-	q->from.type = D_EXTERN;
-	q->from.sym = s;
-	q->from.displace = 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) {
-				ps2 = p;
-				p->from.displace = 1;
-			}
-			if(p->from.sym == s4) {
-				ps4 = p;
-				p->from.displace = 1;
-			}
-		}
-	}
-	for(p = firstp; p != P; p = p->link) {
-		if(p->as == ATEXT) {
-			if(p->from.displace != 0) {
-				for(;;) {
-					q = p->link;
-					if(q == P)
-						break;
-					if(q->as == ATEXT)
-						break;
-					p = q;
-				}
-				continue;
-			}
-
-			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 = ABSR;
-			p->to.type = D_BRANCH;
-			p->pcond = ps2;
-			p->to.sym = s2;
-
-			continue;
-		}
-		if(p->as == ARTS) {
-			/*
-			 * RTS (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;
-			}
-			/*
-			 * RTS
-			 */
-			q = prg();
-			q->as = ARTS;
-			q->from = p->from;
-			q->to = p->to;
-			q->link = p->link;
-			p->link = q;
-
-			/*
-			 * BSR	profout
-			 */
-			p->as = ABSR;
-			p->from = zprg.from;
-			p->to = zprg.to;
-			p->to.type = D_BRANCH;
-			p->pcond = ps4;
-			p->to.sym = s4;
-
-			p = q;
-
-			continue;
-		}
-	}
-}
-
-long
-reuse(Prog *r, Sym *s)
-{
-	Prog *p;
-
-
-	if(r == P)
-		return 0;
-	for(p = datap; p != r; p = p->link)
-		if(p->to.sym == s)
-			return p->from.offset;
-	return 0;
-}
-
-void
-nuxiinit(void)
-{
-	int i, c;
-
-	for(i=0; i<4; i++) {
-		c = find1(0x01020304L, i+1);
-		if(i >= 2)
-			inuxi2[i-2] = c;
-		if(i >= 3)
-			inuxi1[i-3] = c;
-		inuxi4[i] = c;
-		fnuxi8[i] = c+4;
-		fnuxi8[i+4] = c;
-		c = find2(0x01020304L, i+1);
-		gnuxi8[i] = c+4;
-		gnuxi8[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, "\n[fg]nuxi = ");
-		for(i=0; i<8; i++)
-			Bprint(&bso, "%d", fnuxi8[i]);
-		Bprint(&bso, " ");
-		for(i=0; i<8; i++)
-			Bprint(&bso, "%d", gnuxi8[i]);
-		Bprint(&bso, "\n");
-	}
-	Bflush(&bso);
-}
-
-int
-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;
-}
-
-int
-find2(long l, int c)
-{
-	short *p;
-	int i;
-
-	p = (short*)&l;
-	for(i=0; i<4; i+=2) {
-		if(((*p >> 8) & 0xff) == c)
-			return i;
-		if((*p++ & 0xff) == c)
-			return i+1;
-	}
-	return 0;
-}
-
-long
-ieeedtof(Ieee *e)
-{
-	int exp;
-	long 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);
-}

+ 0 - 444
sys/src/cmd/2l/optab.c

@@ -1,444 +0,0 @@
-#include	"l.h"
-
-#define	X1	0
-#define	X2	0
-#define	X3	0
-#define	C	0xf200
-
-Optab optab[] =
-/*	as, fas, srcsp, dstsp, optype, opcode */
-{
-	{ AXXX },
-	{ AABCD, AXXX, X1, X2, X3, 0x4e71 },
-	{ AADDB, AXXX, 2, 0, 3, 0xd000, 0x5000,      0, 0x0600 },
-	{ AADDL, AXXX, 4, 0, 3, 0xd080, 0x5080, 0xd1c0, 0x0680 },
-	{ AADDW, AXXX, 2, 0, 3, 0xd040, 0x5040, 0xd0c0, 0x0640 },
-	{ AADDXB },
-	{ AADDXL },
-	{ AADDXW },
-	{ AADJSP },
-	{ AANDB, AXXX, 2, 0, 9, 0xc000, 0xc100, 0x0200 },
-	{ AANDL, AXXX, 4, 0, 9, 0xc080, 0xc180, 0x0280 },
-	{ AANDW, AXXX, 2, 0, 9, 0xc040, 0xc140, 0x0240 },
-	{ AASLB, AXXX, 0, 2, 12, 0xe100 },
-	{ AASLL, AXXX, 0, 4, 12, 0xe180 },
-	{ AASLW, AXXX, 0, 2, 12, 0xe140 },
-	{ AASRB, AXXX, 0, 2, 12, 0xe000 },
-	{ AASRL, AXXX, 0, 4, 12, 0xe080 },
-	{ AASRW, AXXX, 0, 2, 12, 0xe040 },
-	{ ABCASE, AXXX, 0, 0, 33 },
-	{ ABCC, AXXX, 0, 0, 1, 0x6400 },
-	{ ABCHG, AXXX, 2, 2, 27, 0x0140, 0x0840 },
-	{ ABCLR, AXXX, 2, 2, 27, 0x0180, 0x0880 },
-	{ ABCS, AXXX, 0, 0, 1, 0x6500 },
-	{ ABEQ, AXXX, 0, 0, 1, 0x6700 },
-	{ ABFCHG, AXXX, 0, 0, 24, 0xeac0 },
-	{ ABFCLR, AXXX, 0, 0, 24, 0xecc0 },
-	{ ABFEXTS, AXXX, 0, 0, 24, 0xebc0 },
-	{ ABFEXTU, AXXX, 0, 0, 24, 0xe9c0 },
-	{ ABFFFO, AXXX, 0, 0, 24, 0xedc0 },
-	{ ABFINS, AXXX, 0, 0, 24, 0xefc0 },
-	{ ABFSET, AXXX, 0, 0, 24, 0xeec0 },
-	{ ABFTST, AXXX, 0, 0, 24, 0xe8c0 },
-	{ ABGE, AXXX, 0, 0, 1, 0x6c00 },
-	{ ABGT, AXXX, 0, 0, 1, 0x6e00 },
-	{ ABHI, AXXX, 0, 0, 1, 0x6200 },
-	{ ABKPT },
-	{ ABLE, AXXX, 0, 0, 1, 0x6f00 },
-	{ ABLS, AXXX, 0, 0, 1, 0x6300 },
-	{ ABLT, AXXX, 0, 0, 1, 0x6d00 },
-	{ ABMI, AXXX, 0, 0, 1, 0x6b00 },
-	{ ABNE, AXXX, 0, 0, 1, 0x6600 },
-	{ ABPL, AXXX, 0, 0, 1, 0x6a00 },
-	{ ABRA, AXXX, 0, 0, 1, 0x6000 },
-	{ ABSET, AXXX, 2, 2, 27, 0x01c0, 0x08c0 },
-	{ ABSR, AXXX, 0, 0, 1, 0x6100, 0x4eb8 },
-	{ ABTST, AXXX, 2, 2, 27, 0x0100, 0x0800 },
-	{ ABVC, AXXX, 0, 0, 1, 0x6800 },
-	{ ABVS, AXXX, 0, 0, 1, 0x6900 },
-	{ ACALLM },
-	{ ACAS2B },
-	{ ACAS2L },
-	{ ACAS2W },
-	{ ACASB },
-	{ ACASEW, AXXX, 0, 0, 32, 0x4efb, 0 },
-	{ ACASL },
-	{ ACASW },
-	{ ACHK2B, AXXX, 2, 0, 31, 0x00c0, 0x0800 },
-	{ ACHK2L, AXXX, 4, 0, 31, 0x04c0, 0x0800 },
-	{ ACHK2W, AXXX, 2, 0, 31, 0x02c0, 0x0800 },
-	{ ACHKL, AXXX, 4, 4, 26, 0x4100 },
-	{ ACHKW, AXXX, 2, 2, 26, 0x4180 },
-	{ ACLRB, AXXX, 0, -2, 5, 0x4200 },
-	{ ACLRL, AXXX, 0, -4, 5, 0x4280 },
-	{ ACLRW, AXXX, 0, -2, 5, 0x4240 },
-	{ ACMP2B, AXXX, 2, 0, 31, 0x00c0, 0x0000 },
-	{ ACMP2L, AXXX, 4, 0, 31, 0x04c0, 0x0000 },
-	{ ACMP2W, AXXX, 2, 0, 31, 0x02c0, 0x0000 },
-	{ ACMPB, AXXX, 2, 2, 7, 0xb000,      0, 0x0c00, 0xb108 },
-	{ ACMPL, AXXX, 4, 4, 7, 0xb080, 0xb100, 0x0c80, 0xb188 },
-	{ ACMPW, AXXX, 2, 2, 7, 0xb040, 0xb080, 0x0c40, 0xb148 },
-	{ ADATA },
-	{ ADBCC, AXXX, 0, 0, 15, 0x54c8 },
-	{ ADBCS, AXXX, 0, 0, 15, 0x55c8 },
-	{ ADBEQ, AXXX, 0, 0, 15, 0x57c8 },
-	{ ADBF, AXXX, 0, 0, 15, 0x51c8 },
-	{ ADBGE, AXXX, 0, 0, 15, 0x5cc8 },
-	{ ADBGT, AXXX, 0, 0, 15, 0x5ec8 },
-	{ ADBHI, AXXX, 0, 0, 15, 0x52c8 },
-	{ ADBLE, AXXX, 0, 0, 15, 0x5fc8 },
-	{ ADBLS, AXXX, 0, 0, 15, 0x53c8 },
-	{ ADBLT, AXXX, 0, 0, 15, 0x5dc8 },
-	{ ADBMI, AXXX, 0, 0, 15, 0x5bc8 },
-	{ ADBNE, AXXX, 0, 0, 15, 0x56c8 },
-	{ ADBPL, AXXX, 0, 0, 15, 0x5ac8 },
-	{ ADBT, AXXX, 0, 0, 15, 0x50c8 },
-	{ ADBVC, AXXX, 0, 0, 15, 0x58c8 },
-	{ ADBVS, AXXX, 0, 0, 15, 0x59c8 },
-	{ ADIVSL, AXXX, 4, 0, 14, 0x4c40, 0x0800 },
-	{ ADIVSW, AXXX, 2, 0, 13, 0x81c0 },
-	{ ADIVUL, AXXX, 4, 0, 14, 0x4c40, 0x0000 },
-	{ ADIVUW, AXXX, 2, 0, 13, 0x80c0 },
-	{ AEND },
-	{ AEORB, AXXX, 2, 0, 10, 0xb100, 0x0a00 },
-	{ AEORL, AXXX, 4, 0, 10, 0xb180, 0x0a80 },
-	{ AEORW, AXXX, 2, 0, 10, 0xb140, 0x0a40 },
-	{ AEXG },
-	{ AEXTBL, AXXX, 0, 0, 11, 0x49c0 },
-	{ AEXTBW, AXXX, 0, 0, 11, 0x4880 },
-	{ AEXTWL, AXXX, 0, 0, 11, 0x48c0 },
-	{ AFABSB, AXXX, 2, 0, 17, C, 0x0018, 0x5818 },
-	{ AFABSD, AFABSL, 8, 0, 17, C, 0x0018, 0x5418 },
-	{ AFABSF, AFABSL, 4, 0, 17, C, 0x0018, 0x4418 },
-	{ AFABSL, AXXX, 4, 0, 17, C, 0x0018, 0x4018 },
-	{ AFABSW, AXXX, 2, 0, 17, C, 0x0018, 0x5018 },
-	{ AFACOSB, AXXX, 2, 0, 17, C, 0x001c, 0x581c },
-	{ AFACOSD, AFACOSL, 8, 0, 17, C, 0x001c, 0x541c },
-	{ AFACOSF, AFACOSL, 4, 0, 17, C, 0x001c, 0x441c },
-	{ AFACOSL, AXXX, 4, 0, 17, C, 0x001c, 0x401c },
-	{ AFACOSW, AXXX, 2, 0, 17, C, 0x001c, 0x501c },
-	{ AFADDB, AXXX, 2, 0, 17, C, 0x0022, 0x5822 },
-	{ AFADDD, AFADDL, 8, 0, 17, C, 0x0022, 0x5422 },
-	{ AFADDF, AFADDL, 4, 0, 17, C, 0x0022, 0x4422 },
-	{ AFADDL, AXXX, 4, 0, 17, C, 0x0022, 0x4022 },
-	{ AFADDW, AXXX, 2, 0, 17, C, 0x0022, 0x5022 },
-	{ AFASINB, AXXX, 2, 0, 17, C, 0x000c, 0x580c },
-	{ AFASIND, AFASINL, 8, 0, 17, C, 0x000c, 0x540c },
-	{ AFASINF, AFASINL, 4, 0, 17, C, 0x000c, 0x440c },
-	{ AFASINL, AXXX, 4, 0, 17, C, 0x000c, 0x400c },
-	{ AFASINW, AXXX, 2, 0, 17, C, 0x000c, 0x500c },
-	{ AFATANB, AXXX, 2, 0, 17, C, 0x000a, 0x580a },
-	{ AFATAND, AFATANL, 8, 0, 17, C, 0x000a, 0x540a },
-	{ AFATANF, AFATANL, 4, 0, 17, C, 0x000a, 0x440a },
-	{ AFATANHB, AXXX, 2, 0, 17, C, 0x000d, 0x580d },
-	{ AFATANHD, AFATANHL, 8, 0, 17, C, 0x000d, 0x540d },
-	{ AFATANHF, AFATANHL, 4, 0, 17, C, 0x000d, 0x440d },
-	{ AFATANHL, AXXX, 4, 0, 17, C, 0x000d, 0x400d },
-	{ AFATANHW, AXXX, 2, 0, 17, C, 0x000d, 0x500d },
-	{ AFATANL, AXXX, 4, 0, 17, C, 0x000a, 0x400a },
-	{ AFATANW, AXXX, 2, 0, 17, C, 0x000a, 0x500a },
-	{ AFBEQ, AXXX, 0, 0, 18, C+0x81 },
-	{ AFBF, AXXX, 0, 0, 18, C+0x8f },
-	{ AFBGE, AXXX, 0, 0, 18, C+0x93 },
-	{ AFBGT, AXXX, 0, 0, 18, C+0x92 },
-	{ AFBLE, AXXX, 0, 0, 18, C+0x95 },
-	{ AFBLT, AXXX, 0, 0, 18, C+0x94 },
-	{ AFBNE, AXXX, 0, 0, 18, C+0x8e },
-	{ AFBT, AXXX, 0, 0, 18, C+0x80 },
-	{ AFCMPB, AXXX, 0, 2, 22, C, 0x0038, 0x5838 },
-	{ AFCMPD, AFCMPL, 0, 8, 22, C, 0x0038, 0x5438 },
-	{ AFCMPF, AFCMPL, 0, 4, 22, C, 0x0038, 0x4438 },
-	{ AFCMPL, AXXX, 0, 4, 22, C, 0x0038, 0x4038 },
-	{ AFCMPW, AXXX, 0, 2, 22, C, 0x0038, 0x5038 },
-	{ AFCOSB, AXXX, 2, 0, 17, C, 0x001d, 0x581d },
-	{ AFCOSD, AFCOSL, 8, 0, 17, C, 0x001d, 0x541d },
-	{ AFCOSF, AFCOSL, 4, 0, 17, C, 0x001d, 0x441d },
-	{ AFCOSHB, AXXX, 2, 0, 17, C, 0x0019, 0x5819 },
-	{ AFCOSHD, AFCOSHL, 8, 0, 17, C, 0x0019, 0x5419 },
-	{ AFCOSHF, AFCOSHL, 4, 0, 17, C, 0x0019, 0x4419 },
-	{ AFCOSHL, AXXX, 4, 0, 17, C, 0x0019, 0x4019 },
-	{ AFCOSHW, AXXX, 2, 0, 17, C, 0x0019, 0x5019 },
-	{ AFCOSL, AXXX, 4, 0, 17, C, 0x001d, 0x401d },
-	{ AFCOSW, AXXX, 2, 0, 17, C, 0x001d, 0x501d },
-	{ AFDBEQ, AXXX, 0, 0, 19, C+0x48, 0x01 },
-	{ AFDBF, AXXX, 0, 0, 19, C+0x48, 0x0f },
-	{ AFDBGE, AXXX, 0, 0, 19, C+0x48, 0x13 },
-	{ AFDBGT, AXXX, 0, 0, 19, C+0x48, 0x12 },
-	{ AFDBLE, AXXX, 0, 0, 19, C+0x48, 0x15 },
-	{ AFDBLT, AXXX, 0, 0, 19, C+0x48, 0x14 },
-	{ AFDBNE, AXXX, 0, 0, 19, C+0x48, 0x0e },
-	{ AFDBT, AXXX, 0, 0, 19, C+0x48, 0x00 },
-	{ AFDIVB, AXXX, 2, 0, 17, C, 0x0020, 0x5820 },
-	{ AFDIVD, AFDIVL, 8, 0, 17, C, 0x0020, 0x5420 },
-	{ AFDIVF, AFDIVL, 4, 0, 17, C, 0x0020, 0x4420 },
-	{ AFDIVL, AXXX, 4, 0, 17, C, 0x0020, 0x4020 },
-	{ AFDIVW, AXXX, 2, 0, 17, C, 0x0020, 0x5020 },
-	{ AFETOXB, AXXX, 2, 0, 17, C, 0x0010, 0x5810 },
-	{ AFETOXD, AFETOXL, 8, 0, 17, C, 0x0010, 0x5410 },
-	{ AFETOXF, AFETOXL, 4, 0, 17, C, 0x0010, 0x4410 },
-	{ AFETOXL, AXXX, 4, 0, 17, C, 0x0010, 0x4010 },
-	{ AFETOXM1B, AXXX, 2, 0, 17, C, 0x0008, 0x5808 },
-	{ AFETOXM1D, AFETOXM1L, 8, 0, 17, C, 0x0008, 0x5408 },
-	{ AFETOXM1F, AFETOXM1L, 4, 0, 17, C, 0x0008, 0x4408 },
-	{ AFETOXM1L, AXXX, 4, 0, 17, C, 0x0008, 0x4008 },
-	{ AFETOXM1W, AXXX, 2, 0, 17, C, 0x0008, 0x5008 },
-	{ AFETOXW, AXXX, 2, 0, 17, C, 0x0010, 0x5010 },
-	{ AFGETEXPB, AXXX, 2, 0, 17, C, 0x001e, 0x581e },
-	{ AFGETEXPD, AFGETEXPL, 8, 0, 17, C, 0x001e, 0x541e },
-	{ AFGETEXPF, AFGETEXPL, 4, 0, 17, C, 0x001e, 0x441e },
-	{ AFGETEXPL, AXXX, 4, 0, 17, C, 0x001e, 0x401e },
-	{ AFGETEXPW, AXXX, 2, 0, 17, C, 0x001e, 0x501e },
-	{ AFGETMANB, AXXX, 2, 0, 17, C, 0x001f, 0x581f },
-	{ AFGETMAND, AFGETMANL, 8, 0, 17, C, 0x001f, 0x541f },
-	{ AFGETMANF, AFGETMANL, 4, 0, 17, C, 0x001f, 0x441f },
-	{ AFGETMANL, AXXX, 4, 0, 17, C, 0x001f, 0x401f },
-	{ AFGETMANW, AXXX, 2, 0, 17, C, 0x001f, 0x501f },
-	{ AFINTB, AXXX, 2, 0, 17, C, 0x0001, 0x5801 },
-	{ AFINTD, AFINTL, 8, 0, 17, C, 0x0001, 0x5401 },
-	{ AFINTF, AFINTL, 4, 0, 17, C, 0x0001, 0x4401 },
-	{ AFINTL, AXXX, 4, 0, 17, C, 0x0001, 0x4001 },
-	{ AFINTRZB, AXXX, 2, 0, 17, C, 0x0003, 0x5803 },
-	{ AFINTRZD, AFINTRZL, 8, 0, 17, C, 0x0003, 0x5403 },
-	{ AFINTRZF, AFINTRZL, 4, 0, 17, C, 0x0003, 0x4403 },
-	{ AFINTRZL, AXXX, 4, 0, 17, C, 0x0003, 0x4003 },
-	{ AFINTRZW, AXXX, 2, 0, 17, C, 0x0003, 0x5003 },
-	{ AFINTW, AXXX, 2, 0, 17, C, 0x0001, 0x5001 },
-	{ AFLOG10B, AXXX, 2, 0, 17, C, 0x0015, 0x5815 },
-	{ AFLOG10D, AFLOG10L, 8, 0, 17, C, 0x0015, 0x5415 },
-	{ AFLOG10F, AFLOG10L, 4, 0, 17, C, 0x0015, 0x4415 },
-	{ AFLOG10L, AXXX, 4, 0, 17, C, 0x0015, 0x4015 },
-	{ AFLOG10W, AXXX, 2, 0, 17, C, 0x0015, 0x5015 },
-	{ AFLOG2B, AXXX, 2, 0, 17, C, 0x0016, 0x5816 },
-	{ AFLOG2D, AFLOG2L, 8, 0, 17, C, 0x0016, 0x5416 },
-	{ AFLOG2F, AFLOG2L, 4, 0, 17, C, 0x0016, 0x4416 },
-	{ AFLOG2L, AXXX, 4, 0, 17, C, 0x0016, 0x4016 },
-	{ AFLOG2W, AXXX, 2, 0, 17, C, 0x0016, 0x5016 },
-	{ AFLOGNB, AXXX, 2, 0, 17, C, 0x0014, 0x5814 },
-	{ AFLOGND, AFLOGNL, 8, 0, 17, C, 0x0014, 0x5414 },
-	{ AFLOGNF, AFLOGNL, 4, 0, 17, C, 0x0014, 0x4414 },
-	{ AFLOGNL, AXXX, 4, 0, 17, C, 0x0014, 0x4014 },
-	{ AFLOGNP1B, AXXX, 2, 0, 17, C, 0x0006, 0x5806 },
-	{ AFLOGNP1D, AFLOGNP1L, 8, 0, 17, C, 0x0006, 0x5406 },
-	{ AFLOGNP1F, AFLOGNP1L, 4, 0, 17, C, 0x0006, 0x4406 },
-	{ AFLOGNP1L, AXXX, 4, 0, 17, C, 0x0006, 0x4006 },
-	{ AFLOGNP1W, AXXX, 2, 0, 17, C, 0x0006, 0x5006 },
-	{ AFLOGNW, AXXX, 2, 0, 17, C, 0x0014, 0x5014 },
-	{ AFMODB, AXXX, 2, 0, 17, C, 0x0021, 0x5821 },
-	{ AFMODD, AFMODL, 8, 0, 17, C, 0x0021, 0x5421 },
-	{ AFMODF, AFMODL, 4, 0, 17, C, 0x0021, 0x4421 },
-	{ AFMODL, AXXX, 4, 0, 17, C, 0x0021, 0x4021 },
-	{ AFMODW, AXXX, 2, 0, 17, C, 0x0021, 0x5021 },
-	{ AFMOVEB, AXXX, 2, -2, 16, C, 0x0000, 0x7800, 0x5800 },
-	{ AFMOVED, AFMOVEL, 8, -8, 16, C, 0x0000, 0x7400, 0x5400 },
-	{ AFMOVEF, AFMOVEL, 4, -4, 16, C, 0x0000, 0x6400, 0x4400 },
-	{ AFMOVEL, AXXX, 4, -4, 16, C, 0x0000, 0x6000, 0x4000 },
-	{ AFMOVEM, AXXX, 2, 2, 28, C },
-	{ AFMOVEMC, AXXX, 2, 2, 29, C },
-	{ AFMOVEW, AXXX, 2, -2, 16, C, 0x0000, 0x7000, 0x5000 },
-	{ AFMULB, AXXX, 2, 0, 17, C, 0x0023, 0x5823 },
-	{ AFMULD, AFMULL, 8, 0, 17, C, 0x0023, 0x5423 },
-	{ AFMULF, AFMULL, 4, 0, 17, C, 0x0023, 0x4423 },
-	{ AFMULL, AXXX, 4, 0, 17, C, 0x0023, 0x4023 },
-	{ AFMULW, AXXX, 2, 0, 17, C, 0x0023, 0x5023 },
-	{ AFNEGB, AXXX, 2, 0, 21, C, 0x001a, 0x581a },
-	{ AFNEGD, AFNEGL, 8, 0, 21, C, 0x001a, 0x541a },
-	{ AFNEGF, AFNEGL, 4, 0, 21, C, 0x001a, 0x441a },
-	{ AFNEGL, AXXX, 4, 0, 21, C, 0x001a, 0x401a },
-	{ AFNEGW, AXXX, 2, 0, 21, C, 0x001a, 0x501a },
-	{ AFREMB, AXXX, 2, 0, 17, C, 0x0025, 0x5825 },
-	{ AFREMD, AFREML, 8, 0, 17, C, 0x0025, 0x5425 },
-	{ AFREMF, AFREML, 4, 0, 17, C, 0x0025, 0x4425 },
-	{ AFREML, AXXX, 4, 0, 17, C, 0x0025, 0x4025 },
-	{ AFREMW, AXXX, 2, 0, 17, C, 0x0025, 0x5025 },
-	{ AFRESTORE, AXXX, 0, 2, 5, C+0x0140 },
-	{ AFSAVE, AXXX, 0, 2, 5, C+0x0100 },
-	{ AFSCALEB, AXXX, 2, 0, 17, C, 0x0026, 0x5826 },
-	{ AFSCALED, AFSCALEL, 8, 0, 17, C, 0x0026, 0x5426 },
-	{ AFSCALEF, AFSCALEL, 4, 0, 17, C, 0x0026, 0x4426 },
-	{ AFSCALEL, AXXX, 4, 0, 17, C, 0x0026, 0x4026 },
-	{ AFSCALEW, AXXX, 2, 0, 17, C, 0x0026, 0x5026 },
-	{ AFSEQ, AXXX, X1, X2, X3, 0xffff },
-	{ AFSF, AXXX, 4, X2, X3, 0xffff },
-	{ AFSGE, AXXX, X1, X2, X3, 0xffff },
-	{ AFSGT, AXXX, X1, X2, X3, 0xffff },
-	{ AFSINB, AXXX, 2, 0, 17, C, 0x000e, 0x580e },
-	{ AFSIND, AFSINL, 8, 0, 17, C, 0x000e, 0x540e },
-	{ AFSINF, AFSINL, 4, 0, 17, C, 0x000e, 0x440e },
-	{ AFSINHB, AXXX, 2, 0, 17, C, 0x0002, 0x5802 },
-	{ AFSINHD, AFSINHL, 8, 0, 17, C, 0x0002, 0x5402 },
-	{ AFSINHF, AFSINHL, 4, 0, 17, C, 0x0002, 0x4402 },
-	{ AFSINHL, AXXX, 4, 0, 17, C, 0x0002, 0x4002 },
-	{ AFSINHW, AXXX, 2, 0, 17, C, 0x0002, 0x5002 },
-	{ AFSINL, AXXX, 4, 0, 17, C, 0x000e, 0x400e },
-	{ AFSINW, AXXX, 2, 0, 17, C, 0x000e, 0x500e },
-	{ AFSLE, AXXX, X1, X2, X3, 0xffff },
-	{ AFSLT, AXXX, X1, X2, X3, 0xffff },
-	{ AFSNE, AXXX, X1, X2, X3, 0xffff },
-	{ AFSQRTB, AXXX, 2, 0, 17, C, 0x0004, 0x5804 },
-	{ AFSQRTD, AFSQRTL, 8, 0, 17, C, 0x0004, 0x5404 },
-	{ AFSQRTF, AFSQRTL, 4, 0, 17, C, 0x0004, 0x4404 },
-	{ AFSQRTL, AXXX, 4, 0, 17, C, 0x0004, 0x4004 },
-	{ AFSQRTW, AXXX, 2, 0, 17, C, 0x0004, 0x5004 },
-	{ AFST, AXXX, X1, X2, X3, 0xffff },
-	{ AFSUBB, AXXX, 2, 0, 17, C, 0x0028, 0x5828 },
-	{ AFSUBD, AFSUBL, 8, 0, 17, C, 0x0028, 0x5428 },
-	{ AFSUBF, AFSUBL, 4, 0, 17, C, 0x0028, 0x4428 },
-	{ AFSUBL, AXXX, 4, 0, 17, C, 0x0028, 0x4028 },
-	{ AFSUBW, AXXX, 2, 0, 17, C, 0x0028, 0x5028 },
-	{ AFTANB, AXXX, 2, 0, 17, C, 0x000f, 0x580f },
-	{ AFTAND, AFTANL, 8, 0, 17, C, 0x000f, 0x540f },
-	{ AFTANF, AFTANL, 4, 0, 17, C, 0x000f, 0x440f },
-	{ AFTANHB, AXXX, 2, 0, 17, C, 0x0009, 0x5809 },
-	{ AFTANHD, AFTANHL, 8, 0, 17, C, 0x0009, 0x5409 },
-	{ AFTANHF, AFTANHL, 4, 0, 17, C, 0x0009, 0x4409 },
-	{ AFTANHL, AXXX, 4, 0, 17, C, 0x0009, 0x4009 },
-	{ AFTANHW, AXXX, 2, 0, 17, C, 0x0009, 0x5009 },
-	{ AFTANL, AXXX, 4, 0, 17, C, 0x000f, 0x400f },
-	{ AFTANW, AXXX, 2, 0, 17, C, 0x000f, 0x500f },
-	{ AFTENTOXB, AXXX, 2, 0, 17, C, 0x0012, 0x5812 },
-	{ AFTENTOXD, AFTENTOXL, 8, 0, 17, C, 0x0012, 0x5412 },
-	{ AFTENTOXF, AFTENTOXL, 4, 0, 17, C, 0x0012, 0x4412 },
-	{ AFTENTOXL, AXXX, 4, 0, 17, C, 0x0012, 0x4012 },
-	{ AFTENTOXW, AXXX, 2, 0, 17, C, 0x0012, 0x5012 },
-	{ AFTSTB, AXXX, 0, 2, 20, C, 0x003a, 0x583a },
-	{ AFTSTD, AFTSTL, 0, 8, 20, C, 0x003a, 0x543a },
-	{ AFTSTF, AFTSTL, 0, 4, 20, C, 0x003a, 0x443a },
-	{ AFTSTL, AXXX, 0, 4, 20, C, 0x003a, 0x403a },
-	{ AFTSTW, AXXX, 0, 2, 20, C, 0x003a, 0x503a },
-	{ AFTWOTOXB, AXXX, 2, 0, 17, C, 0x0011, 0x5811 },
-	{ AFTWOTOXD, AFTWOTOXL, 8, 0, 17, C, 0x0011, 0x5411 },
-	{ AFTWOTOXF, AFTWOTOXL, 4, 0, 17, C, 0x0011, 0x4411 },
-	{ AFTWOTOXL, AXXX, 4, 0, 17, C, 0x0011, 0x4011 },
-	{ AFTWOTOXW, AXXX, 2, 0, 17, C, 0x0011, 0x5011 },
-	{ AGLOBL },
-	{ AGOK },
-	{ AHISTORY },
-	{ AILLEG, AXXX, 0, 0, 4, 0x4efc },
-	{ AINSTR },
-	{ AJMP, AXXX, 0, 0, 5, 0x4ec0 },
-	{ AJSR, AXXX, 0, 0, 5, 0x4e80 },
-	{ ALEA, AXXX, 0, 0, 6, 0x41c0 },
-	{ ALINKL },
-	{ ALINKW },
-	{ ALOCATE },
-	{ ALONG, AXXX, 0, 4, 23 },
-	{ ALSLB, AXXX, 0, 2, 12, 0xe108 },
-	{ ALSLL, AXXX, 0, 4, 12, 0xe188 },
-	{ ALSLW, AXXX, 0, 2, 12, 0xe148 },
-	{ ALSRB, AXXX, 0, 2, 12, 0xe008 },
-	{ ALSRL, AXXX, 0, 4, 12, 0xe088 },
-	{ ALSRW, AXXX, 0, 2, 12, 0xe048 },
-	{ AMOVB, AXXX, 2, -2, 2, 0x1000, 0x7000 },
-	{ AMOVEM, AXXX, 2, 2, 25, 0x48c0 },
-	{ AMOVEPL },
-	{ AMOVEPW },
-	{ AMOVESB, AXXX, 2, -2, 34, 0xe00 },
-	{ AMOVESL, AXXX, 4, -4, 34, 0xe80 },
-	{ AMOVESW, AXXX, 2, -2, 34, 0xe40 },
-	{ AMOVL, AXXX, 4, -4, 2, 0x2000, 0x7000 },
-	{ AMOVW, AXXX, 2, -2, 2, 0x3000, 0x7000 },
-	{ AMULSL, AXXX, 4, 0, 14, 0x4c00, 0x0800 },
-	{ AMULSW, AXXX, 2, 0, 13, 0xc1c0 },
-	{ AMULUL, AXXX, 4, 0, 14, 0x4c00, 0x0000 },
-	{ AMULUW, AXXX, 2, 0, 13, 0xc0c0 },
-	{ ANAME },
-	{ ANBCD },
-	{ ANEGB, AXXX, 0, 0, 5, 0x4400 },
-	{ ANEGL, AXXX, 0, 0, 5, 0x4480 },
-	{ ANEGW, AXXX, 0, 0, 5, 0x4440 },
-	{ ANEGXB },
-	{ ANEGXL },
-	{ ANEGXW },
-	{ ANOP },
-	{ ANOTB, AXXX, 0, 0, 5, 0x4600 },
-	{ ANOTL, AXXX, 0, 0, 5, 0x4680 },
-	{ ANOTW, AXXX, 0, 0, 5, 0x4640 },
-	{ AORB, AXXX, 2, 0, 9, 0x8000, 0x8100, 0x0000 },
-	{ AORL, AXXX, 4, 0, 9, 0x8080, 0x8180, 0x0080 },
-	{ AORW, AXXX, 2, 0, 9, 0x8040, 0x8140, 0x0040 },
-	{ APACK },
-	{ APEA, AXXX, 0, 0, 5, 0x4840 },
-	{ ARESET },
-	{ AROTLB, AXXX, 0, 2, 12, 0xe118 },
-	{ AROTLL, AXXX, 0, 4, 12, 0xe198 },
-	{ AROTLW, AXXX, 0, 2, 12, 0xe158 },
-	{ AROTRB, AXXX, 0, 2, 12, 0xe018 },
-	{ AROTRL, AXXX, 0, 4, 12, 0xe098 },
-	{ AROTRW, AXXX, 0, 2, 12, 0xe058 },
-	{ AROXLB },
-	{ AROXLL },
-	{ AROXLW },
-	{ AROXRB },
-	{ AROXRL },
-	{ AROXRW },
-	{ ARTD },
-	{ ARTE, AXXX, 0, 0, 4, 0x4e73 },
-	{ ARTM },
-	{ ARTR },
-	{ ARTS, AXXX, 0, 0, 4, 0x4e75 },
-	{ ASBCD },
-	{ ASCC },
-	{ ASCS },
-	{ ASEQ },
-	{ ASF },
-	{ ASGE },
-	{ ASGT },
-	{ ASHI },
-	{ ASLE },
-	{ ASLS },
-	{ ASLT },
-	{ ASMI },
-	{ ASNE },
-	{ ASPL },
-	{ AST },
-	{ ASTOP },
-	{ ASUBB, AXXX, 2, 0, 3, 0x9000, 0x5100,      0, 0x0400 },
-	{ ASUBL, AXXX, 4, 0, 3, 0x9080, 0x5180, 0x91c0, 0x0480 },
-	{ ASUBW, AXXX, 2, 0, 3, 0x9040, 0x5140, 0x90c0, 0x0440 },
-	{ ASUBXB },
-	{ ASUBXL },
-	{ ASUBXW },
-	{ ASVC },
-	{ ASVS },
-	{ ASWAP, AXXX, 0, 0, 35, 0x4840 },
-	{ ASYS, AXXX, 0, 2, 8, 0x4e40 },
-	{ ATAS, AXXX, 0, 2, 5, 0x4ac0 },
-	{ ATEXT },
-	{ ATRAP, AXXX, 0, 0, 30, 0x4e40 },
-	{ ATRAPCC, AXXX, 0, 0, 4, 0x54fc },
-	{ ATRAPCS, AXXX, 0, 0, 4, 0x55fc },
-	{ ATRAPEQ, AXXX, 0, 0, 4, 0x57fc },
-	{ ATRAPF, AXXX, 0, 0, 4, 0x51fc },
-	{ ATRAPGE, AXXX, 0, 0, 4, 0x5cfc },
-	{ ATRAPGT, AXXX, 0, 0, 4, 0x5efc },
-	{ ATRAPHI, AXXX, 0, 0, 4, 0x52fc },
-	{ ATRAPLE, AXXX, 0, 0, 4, 0x5ffc },
-	{ ATRAPLS, AXXX, 0, 0, 4, 0x53fc },
-	{ ATRAPLT, AXXX, 0, 0, 4, 0x5dfc },
-	{ ATRAPMI, AXXX, 0, 0, 4, 0x5bfc },
-	{ ATRAPNE, AXXX, 0, 0, 4, 0x56fc },
-	{ ATRAPPL, AXXX, 0, 0, 4, 0x5afc },
-	{ ATRAPT, AXXX, 0, 0, 4, 0x50fc },
-	{ ATRAPV, AXXX, 0, 0, 4, 0x4e76 },
-	{ ATRAPVC, AXXX, 0, 0, 4, 0x58fc },
-	{ ATRAPVS, AXXX, 0, 0, 4, 0x59fc },
-	{ ATSTB, AXXX, 0, 2, 5, 0x4a00 },
-	{ ATSTL, AXXX, 0, 4, 5, 0x4a80 },
-	{ ATSTW, AXXX, 0, 2, 5, 0x4a40 },
-	{ AUNLK },
-	{ AUNPK },
-	{ AWORD, AXXX, 0, 2, 23 },
-	{ AXXX }
-};
-
-char	mmsize[] =
-{
-	/*  0 */	0, 2, 2, 2, 2,
-	/*  5 */	2, 2, 2, 4, 2,
-	/* 10 */	2, 2, 2, 2, 4,
-	/* 15 */	4, 4, 4, 4, 6,
-	/* 20 */	4, 4, 4, 0, 4,
-	/* 25 */	2, 2, 2, 2, 2,
-	/* 30 */	2, 4, 4, 0, 4,
-	/* 35 */	2, 0, 0, 0, 0,
-};

+ 0 - 538
sys/src/cmd/2l/pass.c

@@ -1,538 +0,0 @@
-#include	"l.h"
-
-void
-dodata(void)
-{
-	int i;
-	Sym *s;
-	Prog *p;
-	long 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(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->from.displace;
-		if(t > s->value)
-			diag("initialize bounds (%ld): %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;
-		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;
-		s->value = datsize;
-		datsize += t;
-	}
-
-	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;
-		s->value = bsssize + datsize;
-		bsssize += t;
-	}
-	xdefine("bdata", SDATA, 0L);
-	xdefine("edata", SDATA, datsize);
-	xdefine("end", SBSS, datsize+bsssize);
-}
-
-Prog*
-brchain(Prog *p)
-{
-	int i;
-
-	for(i=0; i<20; i++) {
-		if(p == P || p->as != ABRA)
-			return p;
-		p = p->pcond;
-	}
-	return P;
-}
-
-void
-follow(void)
-{
-	Prog *p;
-	long o;
-	Sym *s;
-
-	if(debug['v'])
-		Bprint(&bso, "%5.2f follow\n", cputime());
-	Bflush(&bso);
-	firstp = prg();
-	lastp = firstp;
-	xfol(textp);
-	lastp->link = P;
-	firstp = firstp->link;
-	o = 0; /* set */
-	for(p = firstp; p != P; p = p->link) {
-		if(p->as == ATEXT)
-			curtext = p;
-		if(p->as == ABCASE) {	/* initialization for dodata */
-			s = p->from.sym;
-			if(s->type == SBSS)
-				s->type = SDATA;
-			if(s->type != SDATA)
-				diag("BCASE of non-data: %s in %s\n%P",
-					s->name, TNAME, p);
-		}
-
-		p->stkoff = -1;	/* initialization for stkoff */
-		if(p->as == ATEXT) {
-			p->stkoff = 0;
-			o = p->to.offset;
-			continue;
-		}
-		if(p->as == AADJSP && p->from.offset == 0) {
-			p->stkoff = o;
-			continue;
-		}
-	}
-}
-
-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 == ABRA)
-	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;
-			}
-			if(a == ABRA || a == ARTS || a == ARTE)
-				break;
-			if(q->pcond == P || q->pcond->mark)
-				continue;
-			if(a == ABSR || a == ABCASE || a == ADBF)
-				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;
-			}
-		} /* */
-		q = prg();
-		q->as = ABRA;
-		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 == ARTS || a == ABRA || a == ARTE)
-		return;
-	if(p->pcond != P)
-	if(a != ABSR) {
-		q = brchain(p->link);
-		if(q != P && q->mark)
-		if(a != ABCASE && a != ADBF) {
-			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 ABEQ:	return ABNE;
-	case ABNE:	return ABEQ;
-	case ABLE:	return ABGT;
-	case ABLS:	return ABHI;
-	case ABLT:	return ABGE;
-	case ABMI:	return ABPL;
-	case ABGE:	return ABLT;
-	case ABPL:	return ABMI;
-	case ABGT:	return ABLE;
-	case ABHI:	return ABLS;
-	case ABCS:	return ABCC;
-	case ABCC:	return ABCS;
-	case AFBEQ:	return AFBNE;
-	case AFBF:	return AFBT;
-	case AFBGE:	return AFBLT;
-	case AFBGT:	return AFBLE;
-	case AFBLE:	return AFBGT;
-	case AFBLT:	return AFBGE;
-	case AFBNE:	return AFBEQ;
-	case AFBT:	return AFBF;
-	}
-	diag("unknown relation: %s in %s", anames[a], TNAME);
-	return a;
-}
-
-void
-patch(void)
-{
-	long c;
-	Prog *p, *q;
-	Sym *s;
-	long 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 == ABSR || p->as == ARTS) && p->to.sym != S) {
-			s = p->to.sym;
-			if(s->type != STEXT) {
-				diag("undefined: %s in %s", s->name, TNAME);
-				s->type = STEXT;
-				s->value = vexit;
-			}
-			p->to.offset = s->value;
-			p->to.type = D_BRANCH;
-		}
-		if(p->to.type != D_BRANCH)
-			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 = 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;
-	long 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 != ABRA)
-			break;
-		c++;
-		if(c >= 5000)
-			return P;
-	}
-	return q;
-}
-
-void
-dostkoff(void)
-{
-	Prog *p, *q;
-	long s, t;
-	int a;
-	Optab *o;
-
-	if(debug['v'])
-		Bprint(&bso, "%5.2f stkoff\n", cputime());
-	Bflush(&bso);
-	s = 0;
-	for(p = firstp; p != P; p = p->link) {
-		if(p->as == ATEXT) {
-			curtext = p;
-			s = p->to.offset;
-			if(s == 0)
-				continue;
-			p = appendp(p);
-			p->as = AADJSP;
-			p->from.type = D_CONST;
-			p->from.offset = s;
-			p->stkoff = 0;
-			continue;
-		}
-		for(q = p; q != P; q = q->pcond) {
-			if(q->as == ATEXT)
-				break;
-			if(q->stkoff >= 0)
-				if(q->stkoff != s)
-					diag("stack offset %ld is %ld sb %ld in %s\n%P",
-						q->pc, q->stkoff, s, TNAME, p);
-			q->stkoff = s;
-		}
-		o = &optab[p->as];
-		if(p->to.type == D_TOS)
-			s -= o->dstsp;
-		if(p->from.type == D_TOS)
-			s -= o->srcsp;
-		if(p->as == AADJSP)
-			s += p->from.offset;
-		if(p->as == APEA)
-			s += 4;
-		for(q = p->link; q != P; q = q->pcond) {
-			if(q->as == ATEXT) {
-				q = P;
-				break;
-			}
-			if(q->stkoff >= 0)
-				break;
-		}
-		if(q == P || q->stkoff == s)
-			continue;
-		if(p->as == ABRA || p->as == ARTS || p->as == ARTE) {
-			s = q->stkoff;
-			continue;
-		}
-		if(p->link->as == ABCASE)
-			diag("BCASE with stack offset in %s", TNAME);
-		t = q->stkoff - s;
-		s = q->stkoff;
-		p = appendp(p);
-		p->as = AADJSP;
-		p->stkoff = s - t;
-		p->from.type = D_CONST;
-		p->from.offset = t;
-	}
-
-	for(p = firstp; p != P; p = p->link) {
-		if(p->as == ATEXT)
-			curtext = p;
-		a = p->from.type & D_MASK;
-		if(a == D_AUTO)
-			p->from.offset += p->stkoff;
-		if(a == D_PARAM)
-			p->from.offset += p->stkoff + 4;
-		a = p->to.type & D_MASK;
-		if(a == D_AUTO)
-			p->to.offset += p->stkoff;
-		if(a == D_PARAM)
-			p->to.offset += p->stkoff + 4;
-		if(p->as != ARTS)
-			continue;
-		if(p->stkoff == 0)
-			continue;
-		q = p;
-		p = appendp(p);
-		p->as = ARTS;
-		p->stkoff = 0;
-
-		q->as = AADJSP;
-		q->from.type = D_CONST;
-		q->from.offset = -q->stkoff;
-	}
-}
-
-long
-atolwhex(char *s)
-{
-	long 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);
-}

+ 0 - 551
sys/src/cmd/2l/span.c

@@ -1,551 +0,0 @@
-#include	"l.h"
-
-void
-span(void)
-{
-	Prog *p, *q;
-	long v, c, idat;
-	Optab *o;
-	int m, n;
-
-	xdefine("etext", STEXT, 0L);
-	xdefine("a6base", STEXT, 0L);
-	idat = INITDAT;
-	for(p = firstp; p != P; p = p->link) {
-		if(p->as == ATEXT)
-			curtext = p;
-		n = 0;
-		if((q = p->pcond) != P)
-			if(q->back != 2)
-				n = 1;
-		p->back = n;
-		if(p->as == AADJSP) {
-			p->to.type = D_A0+7;
-			v = -p->from.offset;
-			p->from.offset = v;
-			if((v < -8 && v >= -32768L) || (v > 8 && v < 32768L)) {
-				p->as = ALEA;
-				p->from.type = I_INDIR | (D_A0+7);
-				continue;
-			}
-			p->as = AADDL;
-			if(v < 0) {
-				p->as = ASUBL;
-				v = -v;
-				p->from.offset = v;
-			}
-			if(v >= 0 && v <= 8)
-				p->from.type = D_QUICK;
-			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;
-		o = &optab[p->as];
-		p->pc = c;
-		m = mmsize[o->optype];
-		if(m == 0) {
-			if(p->as == AWORD)
-				m = 2;
-			if(p->as == ALONG)
-				m = 4;
-			p->mark = m;
-			c += m;
-			continue;
-		}
-		if(p->from.type != D_NONE)
-			m += andsize(p, &p->from);
-		if(p->to.type == D_BRANCH) {
-			if(p->pcond == P)
-				p->pcond = p;
-			c += m;
-			if(m == 2)
-				m |= 0100;
-			p->mark = m;
-			continue;
-		}
-		if(p->to.type != D_NONE)
-			m += andsize(p, &p->to);
-		p->mark = m;
-		c += m;
-	}
-
-loop:
-	n++;
-	if(debug['v'])
-		Bprint(&bso, "%5.2f span %d\n", cputime(), n);
-	Bflush(&bso);
-	if(n > 60) {
-		diag("span must be looping");
-		errorexit();
-	}
-	c = INITTEXT;
-	for(p = firstp; p != P; p = p->link) {
-		if(p->as == ATEXT)
-			curtext = p;
-		if((m = p->mark) & 0100) {
-			q = p->pcond;
-			v = q->pc - 2;
-			if(p->back)
-				v -= c;
-			else
-				v -= p->pc;
-			p->pc = c;
-			if(v < -32768L || v >= 32768L) {
-				if(p->as == ABSR && q->pc < 32768L && q->pc >= 0) 
-					c += 4;
-				else
-					c += 6;
-			} else
-			if(v < -128 || v >= 128)
-				c += 4;
-			else
-			if(v == 0) {
-				c += 4;
-				p->mark = 4;
-			} else
-				c += 2;
-			continue;
-		}
-		p->pc = c;
-		c += m;
-	}
-	if(c != textsize) {
-		textsize = c;
-		goto loop;
-	}
-	if(INITRND)
-		INITDAT = rnd(c, INITRND);
-	if(INITDAT != idat) {
-		idat = INITDAT;
-		goto start;
-	}
-	xdefine("etext", STEXT, c);
-	xdefine("a6base", STEXT, INITDAT+A6OFFSET);
-	if(debug['v'])
-		Bprint(&bso, "etext = %lux\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, long 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;
-}
-
-int
-andsize(Prog *p, Adr *ap)
-{
-	int t, n;
-	long v;
-	Optab *o;
-
-	t = ap->type;
-	if(ap->index != D_NONE) {
-		n = 2;
-		v = ap->displace;
-		if(v != 0) {
-			n += 2;
-			if(v < -32768L || v >= 32768L)
-				n += 2;
-		}
-		switch(t) {
-		default:
-			v = ap->offset;
-			break;
-
-		case D_STATIC:
-		case D_EXTERN:
-			if(ap->sym->type == STEXT)
-				return n+4;	/* see below */
-			v = ap->sym->value + ap->offset - A6OFFSET;
-			if(debug['6'])
-				v += INITDAT + A6OFFSET;
-		}
-		if(v != 0) {
-			n += 2;
-			if(v < -32768L || v >= 32768L)
-				n += 2;
-		}
-		return n;
-	}
-	n = simple[t];
-	if(n != 0177) {
-		v = ap->offset;
-		if(v == 0)
-			return 0;
-		if((n&070) != 020)	/* D_INDIR */
-			return 0;
-		if(v == 0)
-			return 0;
-		if(v < -32768L || v >= 32768L)
-			return 6;	/* switch to index1 mode */
-		return 2;
-	}
-	if((t&I_MASK) == I_ADDR)
-		t = D_CONST;
-	switch(t) {
-
-	default:
-		return 0;
-
-	case D_STACK:
-	case D_AUTO:
-	case D_PARAM:
-		v = ap->offset;
-		if(v == 0)
-			return 0;
-		if(v < -32768L || v >= 32768L)
-			return 6;	/* switch to index1 mode */
-		return 2;
-
-	case I_INDIR|D_CONST:
-		v = ap->offset;
-		goto adr;
-
-	case D_STATIC:
-	case D_EXTERN:
-		if(ap->sym->type == STEXT)
-			return 4;	/* too slow to get back into namelist */
-		v = ap->sym->value + ap->offset - A6OFFSET;
-		if(debug['6']) {
-			v += INITDAT + A6OFFSET;
-			goto adr;
-		}
-		if(v == 0)
-			return 0;
-
-	adr:
-		if(v < -32768L || v >= 32768L)
-			return 4;
-		return 2;
-
-	case D_CONST:
-	case D_FCONST:
-		o = &optab[p->as];
-		if(ap == &(p->from))
-			return o->srcsp;
-		return o->dstsp;
-
-	case D_CCR:
-	case D_SR:
-		if(p->as == AMOVW)
-			return 0;
-		return 2;
-
-	case D_USP:
-		t = p->from.type;
-		if(t >= D_A0 && t <= D_A0+8)
-			return 0;
-		t = p->to.type;
-		if(t >= D_A0 && t <= D_A0+8)
-			return 0;
-
-	case D_SFC:
-	case D_DFC:
-	case D_CACR:
-	case D_VBR:
-	case D_CAAR:
-	case D_MSP:
-	case D_ISP:
-	case D_FPCR:
-	case D_FPSR:
-	case D_FPIAR:
- 	case D_TC:
-	case D_ITT0:
-	case D_ITT1:
-	case D_DTT0:
-	case D_DTT1:
-	case D_MMUSR:
-	case D_URP:
-	case D_SRP:
-		return 2;
-	}
-}
-
-void
-putsymb(Sym *s, int t, long v)
-{
-	int i, f;
-	char *n;
-
-	n = s->name;
-	if(t == 'f')
-		n++;
-	lput(v);
-	if(s->version)
-		t += 'a' - 'A';
-	CPUT(t+0x80);			/* 0x80 is variable length */
-
-	if(t == 'Z' || t == 'z') {
-		CPUT(n[0]);
-		for(i=1; n[i] != 0 || n[i+1] != 0; i += 2) {
-			CPUT(n[i]);
-			CPUT(n[i+1]);
-		}
-		CPUT(0);
-		CPUT(0);
-		i++;
-	}
-	else {
-		for(i=0; n[i]; i++)
-			CPUT(n[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; n[i] != 0 || n[i+1] != 0; i+=2) {
-				f = ((n[i]&0xff) << 8) | (n[i+1]&0xff);
-				Bprint(&bso, "/%x", f);
-			}
-			Bprint(&bso, "\n");
-			return;
-		}
-		if(s->version)
-			Bprint(&bso, "%c %.8lux %s<%d>\n", t, v, n, s->version);
-		else
-			Bprint(&bso, "%c %.8lux %s\n", t, v, n);
-	}
-}
-
-void
-asmsym(void)
-{
-	Prog *p;
-	Auto *a;
-	Sym *s;
-	int h;
-
-	s = lookup("etext", 0);
-	if(s->type == STEXT)
-		putsymb(s, 'T', s->value);
-	s = lookup("a6base", 0);
-	if(s->type == STEXT)
-		putsymb(s, 'D', s->value);
-
-	for(h=0; h<NHASH; h++)
-		for(s=hash[h]; s!=S; s=s->link)
-			switch(s->type) {
-			case SDATA:
-				putsymb(s, 'D', s->value+INITDAT);
-				continue;
-
-			case SBSS:
-				putsymb(s, 'B', s->value+INITDAT);
-				continue;
-
-			case SFILE:
-				putsymb(s, 'f', s->value);
-				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, 'z', a->aoffset);
-			else
-			if(a->type == D_FILE1)
-				putsymb(a->asym, 'Z', a->aoffset);
-
-		putsymb(s, 'T', s->value);
-
-		/* auto and param after */
-		for(a=p->to.autom; a; a=a->link)
-			if(a->type == D_AUTO)
-				putsymb(a->asym, 'a', -a->aoffset);
-			else
-			if(a->type == D_PARAM)
-				putsymb(a->asym, 'p', a->aoffset);
-	}
-	if(debug['v'] || debug['n'])
-		Bprint(&bso, "symsize = %lud\n", symsize);
-	Bflush(&bso);
-}
-
-#define	MINLC	2
-void
-asmsp(void)
-{
-	long oldpc, oldsp;
-	Prog *p;
-	int s;
-	long v;
-
-	oldpc = INITTEXT;
-	oldsp = 0;
-	for(p = firstp; p != P; p = p->link) {
-		if(p->stkoff == oldsp || p->as == ATEXT || p->as == ANOP) {
-			if(p->as == ATEXT)
-				curtext = p;
-			if(debug['G'])
-				Bprint(&bso, "%6lux %4ld%P\n",
-					p->pc, p->stkoff, p);
-			continue;
-		}
-		if(debug['G'])
-			Bprint(&bso, "\t\t%6ld", spsize);
-		v = (p->pc - oldpc) / MINLC;
-		while(v) {
-			s = 127;
-			if(v < 127)
-				s = v;
-			CPUT(s+128);	/* 129-255 +pc */
-			if(debug['G'])
-				Bprint(&bso, " pc+%d*2(%d)", s, s+128);
-			v -= s;
-			spsize++;
-		}
-		v = p->stkoff - oldsp;
-		oldsp = p->stkoff;
-		oldpc = p->pc + MINLC;
-		if(v & 3 || v > 64L*4L || v < -64L*4L) {
-			CPUT(0);	/* 0 vvvv +sp */
-			lput(v);
-			if(debug['G']) {
-				if(v > 0)
-					Bprint(&bso, " sp+%ld*1(%d,%ld)\n",
-						v, 0, v);
-				else
-					Bprint(&bso, " sp%ld*1(%d,%ld)\n",
-						v, 0, v);
-				Bprint(&bso, "%6lux %4ld%P\n",
-					p->pc, p->stkoff, p);
-			}
-			spsize += 5;
-			continue;
-		}
-		s = v/4;
-		if(s > 0) {
-			CPUT(0+s);	/* 1-64 +sp */
-			if(debug['G']) {
-				Bprint(&bso, " sp+%d*4(%d)\n", s, 0+s);
-				Bprint(&bso, "%6lux %4ld%P\n",
-					p->pc, p->stkoff, p);
-			}
-		} else {
-			CPUT(64-s);	/* 65-128 -sp */
-			if(debug['G']) {
-				Bprint(&bso, " sp%d*4(%d)\n", s, 64-s);
-				Bprint(&bso, "%6lux %4ld%P\n",
-					p->pc, p->stkoff, p);
-			}
-		}
-		spsize++;
-	}
-	while(spsize & 1) {
-		s = 129;
-		CPUT(s);
-		spsize++;
-	}
-	if(debug['v'] || debug['G'])
-		Bprint(&bso, "stsize = %ld\n", spsize);
-	Bflush(&bso);
-}
-
-void
-asmlc(void)
-{
-	long oldpc, oldlc;
-	Prog *p;
-	long 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['L'])
-				Bprint(&bso, "%6lux %P\n",
-					p->pc, p);
-			continue;
-		}
-		if(debug['L'])
-			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['L'])
-				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['L']) {
-				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['L']) {
-				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['L']) {
-				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['L'])
-		Bprint(&bso, "lcsize = %ld\n", lcsize);
-	Bflush(&bso);
-}

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