1 /* i7094_binloader.c: IBM 7094 simulator interface
3 Copyright (c) 2006, David G. Pitts
5 Permission is hereby granted, free of charge, to any person obtaining a
6 copy of this software and associated documentation files (the "Software"),
7 to deal in the Software without restriction, including without limitation
8 the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 and/or sell copies of the Software, and to permit persons to whom the
10 Software is furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of the author shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from the author.
26 /***********************************************************************
28 * binloader.h - IBM 7090 emulator binary loader header.
31 * 10/20/03 DGP Original.
32 * 12/28/04 DGP Changed for new object formats.
34 ***********************************************************************/
36 #define IBSYSSYM '$' /* Marks end of object file */
37 #define WORDPERREC 5 /* Object words per record */
38 #define LOADADDR 0200 /* Default load address */
39 #define OBJRECLEN 80 /* Object record length */
40 #define CHARWORD 12 /* Characters per word */
46 #define IDT_TAG '0' /* 0SSSSSS0LLLLL */
47 #define ABSENTRY_TAG '1' /* 10000000AAAAA */
48 #define RELENTRY_TAG '2' /* 20000000RRRRR */
49 #define ABSEXTRN_TAG '3' /* 3SSSSSS0AAAAA */
50 #define RELEXTRN_TAG '4' /* 4SSSSSS0RRRRR */
51 #define ABSGLOBAL_TAG '5' /* 5SSSSSS0AAAAA */
52 #define RELGLOBAL_TAG '6' /* 6SSSSSS0RRRRR */
53 #define ABSORG_TAG '7' /* 70000000AAAAA */
54 #define RELORG_TAG '8' /* 80000000RRRRR */
55 #define ABSDATA_TAG '9' /* 9AAAAAAAAAAAA */
56 #define RELADDR_TAG 'A' /* AAAAAAAARRRRR */
57 #define RELDECR_TAG 'B' /* BARRRRRAAAAAA */
58 #define RELBOTH_TAG 'C' /* CARRRRRARRRRR */
59 #define BSS_TAG 'D' /* D0000000PPPPP */
60 #define ABSXFER_TAG 'E' /* E0000000RRRRR */
61 #define RELXFER_TAG 'F' /* F0000000RRRRR */
62 #define EVEN_TAG 'G' /* G0000000RRRRR */
63 #define FAPCOMMON_TAG 'H' /* H0000000AAAAA */
67 * LLLLLL - Length of module
68 * AAAAAA - Absolute field
69 * RRRRRR - Relocatable field
70 * PPPPPP - PC offset field
73 /***********************************************************************
75 * binloader.c - IBM 7090 emulator binary loader routines for ASM7090
76 * and LNK7090 object files.
79 * 10/20/03 DGP Original.
80 * 12/28/04 DGP Changed for new object formats.
81 * 02/14/05 DGP Detect IBSYSSYM for EOF.
82 * 06/09/06 DGP Make simh callable.
84 ***********************************************************************/
86 #include "i7094_defs.h"
92 binloader (FILE *fd
, char *file
, int loadpt
)
98 int loadaddr
= LOADADDR
;
99 int curraddr
= LOADADDR
;
100 char inbuf
[OBJRECLEN
+2];
103 lfd
= fopen ("load.log", "w");
104 fprintf (lfd
, "binloader: file = '%s', loadpt = %d\n", file
, loadpt
);
113 while (fgets (inbuf
, sizeof(inbuf
), fd
))
118 if (*op
== IBSYSSYM
) /* End of object marker */
121 for (i
= 0; i
< WORDPERREC
; i
++)
128 if (otag
== ' ') break;
129 strncpy (item
, op
, CHARWORD
);
130 item
[CHARWORD
] = '\0';
132 sscanf (item
, "%I64o", &ldata
);
134 sscanf (item
, "%llo", &ldata
);
138 fprintf (lfd
, "loadaddr = %05o, curraddr = %05o\n",
140 fprintf (lfd
, " otag = %c, item = %s\n", otag
, item
);
141 fprintf (lfd
, " ldata = %12.12o\n", ldata
);
150 curraddr
= loadaddr
= (int32
) ldata
& AMASK
;
154 curraddr
= (int32
) (ldata
+ loadaddr
) & AMASK
;
158 curraddr
= (int32
) (curraddr
+ ldata
) & AMASK
;
162 ldata
= ldata
+ loadaddr
+ (loadaddr
<< INST_V_DEC
);
166 ldata
= ldata
+ (loadaddr
<< INST_V_DEC
);
170 ldata
= ldata
+ loadaddr
;
175 fprintf (lfd
, " M[%05o] = %12.12o\n", curraddr
, ldata
);
177 M
[curraddr
] = ldata
& DMASK
;
184 PC
= (uint32
) ldata
& AMASK
;
186 fprintf (lfd
, " PC = %05o\n", PC
);
188 if (transfer
) goto GOSTART
;
194 ldata
= (ldata
+ loadaddr
) & AMASK
;
195 PC
= (uint32
) ldata
& AMASK
;
197 fprintf (lfd
, " PC = %05o\n", PC
);
199 if (transfer
) goto GOSTART
;