pdp10-opcodes: complete rewrite

This commit is contained in:
Mikael Pettersson
2015-04-19 18:22:17 +02:00
parent af1fd536c2
commit b0aaba8f9a
5 changed files with 1052 additions and 1083 deletions

5
TODO
View File

@@ -32,6 +32,9 @@ pdp10-stdio:
- Handle non-seekable output files better (i.e., allow 8to9 to write to stdout)
pdp10-opcodes:
- change insn->fmt to separate flag bits
Tools:
- size: implement it
@@ -39,12 +42,10 @@ Tools:
- ld: implement it
- readelf: add support for relocs
- readelf: add support for program headers
- pdp10-opcodes.{h,c}: rewrite completely
- as:
* add line-comment character, e.g. '#'
+ use it in doc/MUUO.txt
+ use it in as/tests/*.s
+ add license boilerplate to the above files
* support .ident:
+ change strtab to have a finalizer which returns an image array,
+ use standard output_section for strtab

View File

@@ -293,7 +293,7 @@ static int parse_insn_address_after_at(struct scan_state *scan_state, struct stm
}
}
static int parse_insn_address(struct scan_state *scan_state, struct stmt *stmt, const struct pdp10_instruction *insndesc)
static int parse_insn_address(struct scan_state *scan_state, struct stmt *stmt, const struct pdp10_insn *insndesc)
{
enum token token;
union token_attribute token_attr;
@@ -302,7 +302,7 @@ static int parse_insn_address(struct scan_state *scan_state, struct stmt *stmt,
if (token == T_NEWLINE)
return 1;
if (insndesc->type & PDP10_E_UNUSED)
if (insndesc->fmt & PDP10_INSN_E_UNUSED)
return error(scan_state, "<address> not allowed in this instruction", token, &token_attr);
switch (token) {
@@ -322,7 +322,7 @@ static int parse_insn_address(struct scan_state *scan_state, struct stmt *stmt,
}
static int parse_insn_after_symbol_uinteger(
struct scan_state *scan_state, struct stmt *stmt, const struct pdp10_instruction *insndesc, union token_attribute *uinteger_attr)
struct scan_state *scan_state, struct stmt *stmt, const struct pdp10_insn *insndesc, union token_attribute *uinteger_attr)
{
enum token token;
union token_attribute token_attr;
@@ -331,13 +331,14 @@ static int parse_insn_after_symbol_uinteger(
if (token == T_COMMA) { /* the <uinteger> is the <accumulator> */
if (uinteger_attr->uint > 0xF)
return error(scan_state, "invalid <accumulator>", T_UINTEGER, uinteger_attr);
if (insndesc->type & (PDP10_A_OPCODE | PDP10_A_UNUSED))
if ((insndesc->fmt & 3) == PDP10_INSN_A_OPCODE
|| (insndesc->fmt & 3) == PDP10_INSN_A_UNUSED)
return error(scan_state, "<accumulator> not allowed in this instruction", T_UINTEGER, uinteger_attr);
stmt->u.insn.accumulator = uinteger_attr->uint;
return parse_insn_address(scan_state, stmt, insndesc);
}
if (insndesc->type & PDP10_E_UNUSED)
if (insndesc->fmt & PDP10_INSN_E_UNUSED)
return error(scan_state, "<address> not allowed in this instruction", token, &token_attr);
switch (token) {
@@ -360,7 +361,8 @@ static int parse_after_symbol(struct scan_state *scan_state, struct stmt *stmt,
{
enum token token;
union token_attribute token_attr;
const struct pdp10_instruction *insndesc;
const struct pdp10_insn *insndesc;
const pdp10_cpu_models_t models = PDP10_KL10_271up; /* XXX: make it user-selectable */
token = scan_token(scan_state, &token_attr);
if (token == T_COLON) {
@@ -369,7 +371,7 @@ static int parse_after_symbol(struct scan_state *scan_state, struct stmt *stmt,
return 1;
}
insndesc = pdp10_instruction_from_name(symbol_attr->text);
insndesc = pdp10_insn_from_name(models, symbol_attr->text);
if (!insndesc)
return error(scan_state, "invalid instruction name", T_SYMBOL, symbol_attr);
@@ -378,12 +380,13 @@ static int parse_after_symbol(struct scan_state *scan_state, struct stmt *stmt,
stmt->u.insn.address = 0;
stmt->u.insn.indexreg = 0;
if (insndesc->type & PDP10_A_OPCODE) {
/* XXX: this is too intimate with quirky ->opcode representation */
stmt->u.insn.opcode = (insndesc->opcode >> 6) & 0x1FF;
stmt->u.insn.accumulator = (insndesc->opcode >> 2) & 0xF;
/* XXX: this is too intimate with quirky ->high13 representation */
/* XXX: what about IO insns? should we just store high13 as-is? */
if ((insndesc->fmt & 3) == PDP10_INSN_A_OPCODE) {
stmt->u.insn.opcode = (insndesc->high13 >> 4) & 0x1FF;
stmt->u.insn.accumulator = insndesc->high13 & 0xF;
} else {
stmt->u.insn.opcode = insndesc->opcode & 0x1FF;
stmt->u.insn.opcode = (insndesc->high13 >> 4) & 0x1FF;
stmt->u.insn.accumulator = 0;
}
@@ -396,7 +399,7 @@ static int parse_after_symbol(struct scan_state *scan_state, struct stmt *stmt,
break;
}
if (insndesc->type & PDP10_E_UNUSED)
if (insndesc->fmt & PDP10_INSN_E_UNUSED)
return error(scan_state, "<address> not allowed in this instruction", token, &token_attr);
switch (token) {

View File

@@ -1,43 +1,52 @@
/* PDP-10 opcode list.
Copyright (C) 2000 Free Software Foundation, Inc.
This file is part of GDB and GAS.
GDB and GAS are free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
GDB and GAS are distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GDB or GAS; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#ifndef PDP10_OPCODES_H
#define PDP10_OPCODES_H
/*
* PDP-10 notational conventions.
* pdp10-opcodes.h
* Copyright (C) 2013-2015 Mikael Pettersson
*
* A word is 36 bits wide, with bits numbered 0 to 35, left to right
* (most significant to least significant).
* This file is part of pdp10-tools.
*
* A doubleword is two adjacent words treated as a single 72-bit entity,
* where the word with the lower address is on the left. The direction
* from more to less significance is always from lower to higher addresses.
* pdp10-tools is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Bit numbers are always displayed in decimal. Values in bit fields,
* especially opcodes, are always displayed in octal.
* pdp10-tools is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with pdp10-tools. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* PDP-10 instruction types.
* Word Representation
* ===================
*
* Most PDP-10 instructions have this format:
*
* 11111111112222222222333333
* 012345678901234567890123456789012345
* +------------------------------------+
* | |
* +------------------------------------+
*
* The basic storage unit is a 36-bit wide word. Its bits are numbered 0
* to 35, in left-to-right order, with bit 0 being the most significant
* and bit 35 the least significant. (Similar to IBM's bit numbering but
* opposite to most modern processors.)
*
* The architecture supports sub-word storage units via special instructions
* and specially formatted "byte" pointers, where a byte may be from 0 to 36
* bits wide. Incrementing a byte pointer moves it right over a word towards
* its less significant bits, implying a big-endian storage model.
*
* A 72-bit long integer is composed of two adjacent words. It stores the most
* significant bits in first word (lower address) and the least significant bits
* in the second word (higher address), again implying a big-endian storage model.
*
*
* Instruction Representation
* ==========================
*
* Basic instructions are stored in 36-bit words with the following format:
*
* 111 1 1111 112222222222333333
* 012345678 9012 3 4567 890123456789012345
@@ -46,21 +55,22 @@ the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307
* +---------+----+-+----+------------------+
* 9 bits 4 1 4 18 bits
*
* A usually specifies the accumulator.
* I indicates indirect addressing.
* X specifies the index register.
* Y specifies the address.
* A 9-bit opcode is stored in the high 9 bits.
* A is a 4-bit field specifying the accumulator (a register).
* I is a 1-bit field specifying indirect addressing.
* X is a 4-bit field specifying the index register.
* Y is an 18-bit field specifying an address or offset.
*
* I, X, and Y are used together to calculate E, the effective address.
* E, the effective addreess, is computed from I, X, and Y.
*
* PDP10_A_OPCODE means that A is used together with the opcode field
* to specify the operation.
* In some instructions A contains further opcode bits.
*
* PDP10_A_UNUSED means that A is unused and should be set to zero.
* In some instructions A is unused and should be zero.
*
* PDP10_E_UNUSED means that I, X, and Y are unused and should be set to zero.
* Instructions that not compute an effective address E
* should have I, X, and Y set to zero.
*
* PDP10_IO means that the instruction format looks like this:
* IO instructions have a slightly different format:
*
* 111 1 1111 112222222222333333
* 012 3456789 012 3 4567 890123456789012345
@@ -69,69 +79,163 @@ the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307
* +---+-------+---+-+----+------------------+
* 3 7 bits 3 1 4 18 bits
*
* op1 and op2 are used together to specify the operation.
* The op1 field is all-bits-one (7), the device field addresses the selected device,
* and the op2 field specifies the operation. Both devices internal to the processor
* and devices attached via external buses can be accessed.
*
* I, X, and Y as above.
* Some non-IO instructions also have a 7 in their high three bits.
*
* PDP10_EXTEND means that this the first word of a two-word
* instruction. The second word is located at the effective address,
* E, of the first instruction word.
* Extended instructions consist of two separate instruction words:
*
* A:
* 111 1 1111 112222222222333333
* 012345678 9012 3 4567 890123456789012345
* +---------+----+-+----+------------------+
* | 0123 | A |I| X | Y |
* +---------+----+-+----+------------------+
* 9 bits 4 1 4 18 bits
*
* E0:
* 111 1 1111 112222222222333333
* 012345678 9012 3 4567 890123456789012345
* +---------+----+-+----+------------------+
* | xopcode |0000|I| X | Y |
* +---------+----+-+----+------------------+
* 9 bits 4 1 4 18 bits
*
* The first word is stored at address A in the instruction stream in the basic
* format with opcode 0123. The second word is stored at the effective address
* E0 specified by the the first word. Its accumulator field is unused and must
* be zero for compatibility with future extensions.
*/
#define PDP10_BASIC 0x00
#define PDP10_A_OPCODE 0x01
#define PDP10_A_UNUSED 0x02
#define PDP10_E_UNUSED 0x04
#define PDP10_IO 0x08
#define PDP10_EXTEND 0x10
/*
* PDP-10 CPU models.
* Known PDP10 CPU models, each represented by a distinct bit value.
*
* These are combined with bit-wise 'and', 'or', and 'not' operations
* to form sets of CPU models, used to check if a given mnemonic or
* opcode is available for a selected set of CPUs.
*/
#define PDP10_NONE 0x00000000
#define PDP6_166 0x00000001 /* DEC PDP-6 Type 166 Arithmetic Processor */
#define PDP10_KA10 0x00000002 /* DEC PDP-10 KA10 */
#define PDP10_KA10_ITS 0x00000004 /* DEC PDP-10 KA10, modifications for ITS */
#define PDP10_KI10 0x00000008 /* DEC PDP-10 KI10 */
#define PDP10_KL10 0x00000010 /* DEC PDP-10 KL10 */
#define PDP10_KL10_ITS 0x00000020 /* DEC PDP-10 KL10, ITS microcode */
#define PDP10_KL10_271 0x00000040 /* DEC PDP-10 KL10, microcode version >= 271 */
#define PDP10_KS10 0x00000080 /* DEC PDP-10 KS10 */
#define PDP10_KS10_ITS 0x00000100 /* DEC PDP-10 KS10, ITS microcode */
#define PDP10_KC10 0x00000200 /* DEC PDP-10 KC10 */
#define PDP10_XKL1 0x00000400 /* XKL TOAD-1 XKL-1 */
#define PDP10_ALL 0xffffffff
enum {
/*
* DEC processors.
*/
struct pdp10_instruction
{
const char *name;
unsigned int opcode;
unsigned int type;
unsigned int model;
PDP10_NONE = 0,
PDP6_166 = 1 << 0, /* DEC PDP-6 Type 166 Arithmetic Processor */
PDP10_KA10 = 1 << 1, /* DEC PDP-10 KA10 */
PDP10_KA10_ITS = 1 << 2, /* DEC PDP-10 KA10, ITS microcode */
PDP10_KI10 = 1 << 3, /* DEC PDP-10 KI10 */
PDP10_KL10 = 1 << 4, /* DEC PDP-10 KL10 */
PDP10_KL10_ITS = 1 << 5, /* DEC PDP-10 KL10, ITS microcode */
PDP10_KL10_271 = 1 << 6, /* DEC PDP-10 KL10, microcode version >= 271 (many extensions) */
PDP10_KS10 = 1 << 7, /* DEC PDP-10 KS10 */
PDP10_KS10_ITS = 1 << 8, /* DEC PDP-10 KS10, ITS microcode */
PDP10_KC10 = 1 << 9, /* DEC PDP-10 KC10 (Jupiter, full extended addressing) */
PDP10_KD10 = 1 << 10, /* DEC PDP-10 KD10 (Minnow, KS10 extended to match KC10 specs) */
/*
* XKL Processors.
*
* The XKL-2 is believed to have been built, and to contain some instruction set
* extensions, but no details are known about it at this time.
*/
PDP10_XKL1 = 1 << 11, /* XKL TOAD-1 XKL-1, KL10 clone with KC10-like full extended addressing */
/*
* Other clones, not yet supported.
*
* System Concepts SC-20, SC-25, SC-30M, SC-40 (KC10-like)
*
* Foonly F-1, F-2, F-3, F-4 (KI10/KL10-hybrid)
*
* Xerox PARC MAXC (KI10-like?)
*/
/*
* Convenience constants for combinations of CPU models.
*/
PDP10_ALL = PDP10_XKL1 | (PDP10_XKL1 - 1), /* XXX: depends on XKL1 being last above */
PDP10_KL10_271up = PDP10_KL10_271 | PDP10_XKL1,
PDP10_KL10any = PDP10_KL10 | PDP10_KL10_ITS | PDP10_KL10_271up,
PDP10_KL10up = PDP10_KL10any | PDP10_KS10,
PDP10_KI10_to_KL10 = PDP10_KI10 | PDP10_KL10any,
PDP10_KI10up = PDP10_KI10 | PDP10_KL10up,
PDP10_KA10any = PDP10_KA10 | PDP10_KA10_ITS,
PDP10_KA10up = PDP10_KA10any | PDP10_KI10up,
PDP10_KA10_to_KI10 = PDP10_KA10 | PDP10_KI10, /* XXX: should that be KA10_any? */
PDP10_KA10_to_KL10 = PDP10_KA10_to_KI10 | PDP10_KL10any,
PDP10_not_KS10_or_XKL1 = PDP10_ALL & ~(PDP10_KS10 | PDP10_XKL1), /* XXX: should that be KS10_any? */
PDP10_ITS = PDP10_KA10_ITS | PDP10_KL10_ITS | PDP10_KS10_ITS,
PDP6_166_to_PDP10_KI10 = PDP6_166 | PDP10_KA10_to_KI10,
};
struct pdp10_device
{
const char *name;
unsigned number;
unsigned int model;
typedef unsigned short pdp10_cpu_models_t;
/*
* Device names for IO instructions.
*/
struct pdp10_cpu_device {
const char *name;
unsigned char device; /* device field in bits 3-9 of IO instructions */
pdp10_cpu_models_t models;
};
extern const struct pdp10_instruction pdp10_instruction[];
extern const unsigned int pdp10_num_instructions;
const struct pdp10_cpu_device *
pdp10_cpu_device_from_name(pdp10_cpu_models_t models, const char *name);
extern const struct pdp10_device pdp10_device[];
extern const unsigned int pdp10_num_devices;
/*
* Instructions.
*/
extern const struct pdp10_instruction pdp10_alias[];
extern const unsigned int pdp10_num_aliases;
enum {
/* Each instruction belongs to exactly one of these primary categories,
which determine how the high 13 bits are to be interpreted: */
/* XXX: change this to separate mutually exclusive bits to simplify usage */
PDP10_INSN_BASIC = 0,
PDP10_INSN_A_OPCODE = 1,
PDP10_INSN_A_UNUSED = 2,
PDP10_INSN_IO = 3,
extern const struct pdp10_instruction pdp10_extended_instruction[];
extern const unsigned int pdp10_num_extended_instructions;
/* Flag set to indicate that E is unused. */
PDP10_INSN_E_UNUSED = 4,
const struct pdp10_instruction *pdp10_instruction_from_high13(unsigned int high13);
/* Flag set to indicate that this is the second word of an extended instruction. */
PDP10_INSN_EXTENDED = 8,
};
const struct pdp10_instruction *pdp10_instruction_from_name(const char *name);
typedef unsigned char pdp10_insn_fmt_t;
#endif /* PDP10_OPCODES_H */
struct pdp10_insn {
const char *name;
/*
* The high13 field is 13 bits, formatted as:
* <9 bit opcode><0000> BASIC, A_UNUSED
* <9 + 4 bit opcode> A_OPCODE
* <111><0000000><3 bit op> IO
*
* An extended instruction uses the BASIC format with opcode 0123 for
* the first word, and the A_UNUSED | EXTENDED format for the second word.
*/
unsigned short high13;
pdp10_insn_fmt_t fmt;
pdp10_cpu_models_t models;
};
/* for assembly */
const struct pdp10_insn *
pdp10_insn_from_name(pdp10_cpu_models_t models, const char *name);
/* for disassembly */
const struct pdp10_insn *
pdp10_insn_from_high13(pdp10_cpu_models_t models, unsigned int high13, int extended);

File diff suppressed because it is too large Load Diff

View File

@@ -749,7 +749,8 @@ static int disassemble_section(struct params *params, pdp10_uint36_t shndx)
pdp10_uint36_t labelnr;
pdp10_uint36_t i;
pdp10_uint36_t insnword;
const struct pdp10_instruction *insndesc;
const struct pdp10_insn *insndesc;
const pdp10_cpu_models_t models = PDP10_KL10_271up; /* XXX: make it user-selectable */
shdr = &params->shtab[shndx];
if (shdr->sh_type != SHT_PROGBITS)
@@ -789,16 +790,16 @@ static int disassemble_section(struct params *params, pdp10_uint36_t shndx)
}
printf(" 0x%" PDP10_PRIx36 ":\t0%" PDP10_PRIo36 "\t", i * 4, insnword);
insndesc = pdp10_instruction_from_high13(insnword >> (36 - 13));
insndesc = pdp10_insn_from_high13(models, insnword >> (36 - 13), 0);
if (!insndesc) {
printf("(bad)\n");
continue;
}
printf("%s ", insndesc->name);
if (!((insndesc->type & PDP10_A_OPCODE)
if (!(((insndesc->fmt & 3) == PDP10_INSN_A_OPCODE)
|| (((insnword >> 23) & 0xF) == 0
&& (insndesc->type & PDP10_A_UNUSED))))
&& ((insndesc->fmt & 3) == PDP10_INSN_A_UNUSED))))
printf("%u,", (unsigned int)(insnword >> 23) & 0xF);
if (insnword & (1 << 22))