as: change section image from a pdp_uint36_t arrary to a pdp10_uint9_t array

This commit is contained in:
Mikael Pettersson 2015-03-03 21:20:29 +00:00
parent a3eda3f0ac
commit ade65971fa
4 changed files with 23 additions and 16 deletions

View File

@ -8,6 +8,7 @@
#include "assemble.h"
#include "hashtab.h"
#include "tunit.h"
#include "pdp10-extint.h"
static int assemble_section(struct hashnode *hashnode, void *data)
{
@ -23,10 +24,10 @@ static int assemble_section(struct hashnode *hashnode, void *data)
section->dot = (section->dot + 3) & ~(unsigned long)3;
section->image_words = malloc((section->dot / 4) * sizeof(pdp10_uint36_t));
if (!section->image_words) {
section->image = malloc(section->dot * sizeof(pdp10_uint9_t));
if (!section->image) {
fprintf(stderr, "%s: %s: failed to allocate %zu bytes for text image: %s\n",
tunit->progname, __FUNCTION__, (section->dot / 4) * sizeof(pdp10_uint36_t), strerror(errno));
tunit->progname, __FUNCTION__, section->dot * sizeof(pdp10_uint9_t), strerror(errno));
return -1;
}
@ -50,16 +51,23 @@ static int assemble_section(struct hashnode *hashnode, void *data)
}
case S_INSN:
{
pdp10_uint36_t word;
struct pdp10_ext_uint36 ext36;
unsigned int i;
if (dot >= section->dot) {
fprintf(stderr, "%s: %s: internal error: text image overflow\n", tunit->progname, __FUNCTION__);
return -1;
}
section->image_words[dot / 4] =
word =
((pdp10_uint36_t)(stmt->u.insn.opcode & 0x1FF) << (36 - 9)
| ((stmt->u.insn.accumulator & 0xF) << (36 - 13))
| ((stmt->u.insn.at & 1) << (36 - 14))
| ((stmt->u.insn.indexreg & 0xF) << (36 - 18))
| (stmt->u.insn.address & PDP10_UINT18_MAX));
pdp10_uint36_to_ext(word, &ext36);
for (i = 0; i < 4; ++i)
section->image[dot + i] = ext36.nonet[i];
dot += 4;
break;
}

View File

@ -104,7 +104,7 @@ struct context {
static int append_section(struct context *context, struct section *section)
{
if (section->dot == 0 || section->image_words == NULL)
if (section->dot == 0 || section->image == NULL)
return 0;
section->st_shndx = context->shnum;
@ -154,15 +154,14 @@ static int output_section(struct hashnode *hashnode, void *data)
struct context *context = data;
unsigned int i;
if (section->dot == 0 || section->image_words == NULL)
if (section->dot == 0 || section->image == NULL)
return 0;
if (output_section_prologue(context, section) < 0)
return -1;
/* XXX: ->image_words[] should be uint9_t[] not uint36_t[] */
for (i = 0; i < section->dot; i += 4)
if (pdp10_elf36_write_uint36(context->pdp10fp, section->image_words[i / 4]) < 0)
for (i = 0; i < section->dot; ++i)
if (pdp10_elf36_write_uint9(context->pdp10fp, section->image[i]) < 0)
return -1;
output_section_epilogue(context, section);
@ -194,7 +193,7 @@ static int output_shdr(struct hashnode *hashnode, void *data)
struct context *context = data;
if (section->dot == 0 || section->image_words == NULL)
if (section->dot == 0 || section->image == NULL)
return 0;
return output_section_header(context, section);
@ -286,7 +285,7 @@ int output(struct tunit *tunit, const char *outfile)
section_strtab.sh_type = SHT_STRTAB;
section_strtab.sh_addralign = 1;
section_strtab.dot = context.symstrtab.nrbytes; /* XXX: fixme */
section_strtab.image_words = (pdp10_uint36_t*)4; /* XXX: fixme */
section_strtab.image = (pdp10_uint9_t*)4; /* XXX: fixme */
if (append_section(&context, &section_strtab) < 0)
return -1;
@ -318,7 +317,7 @@ int output(struct tunit *tunit, const char *outfile)
section_symtab.sh_link = section_strtab.st_shndx;
section_symtab.sh_addralign = 4; /* XXX: PDP10-specific */
section_symtab.dot = context.symnum * ELF36_SYM_SIZEOF; /* XXX: fixme */
section_symtab.image_words = (pdp10_uint36_t*)symtab; /* XXX: fixme */
section_symtab.image = (pdp10_uint9_t*)symtab; /* XXX: fixme */
if (append_section(&context, &section_symtab) < 0)
return -1;
@ -336,7 +335,7 @@ int output(struct tunit *tunit, const char *outfile)
return -1;
section_shstrtab.dot = context.shstrtab.nrbytes; /* XXX: fixme */
section_shstrtab.image_words = (pdp10_uint36_t*)4; /* XXX: fixme */
section_shstrtab.image = (pdp10_uint9_t*)4; /* XXX: fixme */
section_shstrtab.st_shndx = context.shnum;
++context.shnum;
@ -406,7 +405,7 @@ int output(struct tunit *tunit, const char *outfile)
if (output_section_prologue(&context, &section_symtab) < 0)
return -1;
symtab = (Elf36_Sym*)section_symtab.image_words;
symtab = (Elf36_Sym*)section_symtab.image;
for (i = 0; i < context.symnum; ++i)
if (pdp10_elf36_write_sym(context.pdp10fp, &symtab[i]) < 0)

View File

@ -49,7 +49,7 @@ void section_init(struct section *section, const char *name)
section->head = NULL;
section->tailptr = &section->head;
section->dot = 0;
section->image_words = NULL;
section->image = NULL;
section->st_shndx = 0;
section->sh_name = 0;
section->sh_type = SHT_NULL;

View File

@ -50,7 +50,7 @@ struct section {
const char *name;
struct stmt *head, **tailptr;
unsigned long dot;
pdp10_uint36_t *image_words; /* assigned during assembly */
pdp10_uint9_t *image; /* assigned during assembly */
Elf36_Word st_shndx; /* assigned during output */
Elf36_Word sh_name; /* assigned during output */
Elf36_Word sh_type;