├── .gitignore ├── .gitlab-ci.yml ├── .indent.pro ├── .travis.yml ├── CHANGES ├── LICENSE ├── Makefile ├── README ├── TODO ├── assemble.c ├── assemble.h ├── assemble_aux.c ├── assemble_aux.h ├── assemble_globals.c ├── assemble_globals.h ├── dumpobj.c ├── dumpobj.dsp ├── extree.c ├── extree.h ├── listing.c ├── listing.h ├── macro11.c ├── macro11.dsp ├── macro11.dsw ├── macro11.h ├── macro11.supp ├── macros.c ├── macros.h ├── make-git-info ├── mlb-rsx.c ├── mlb-rt11.c ├── mlb.h ├── mlb2.c ├── obj2bin ├── .gitignore ├── README.md └── obj2bin.pl ├── object.c ├── object.h ├── parse.c ├── parse.h ├── rad50.c ├── rad50.h ├── rept_irpc.c ├── rept_irpc.h ├── stream2.c ├── stream2.h ├── symbols.c ├── symbols.h ├── tests ├── 2.11BSD-m11-code.lst.ok ├── 2.11BSD-m11-debug.lst.ok ├── 2.11BSD-m11-errs.lst.ok ├── 2.11BSD-m11-exec.lst.ok ├── 2.11BSD-m11-expr.lst.ok ├── 2.11BSD-m11-fltg.lst.ok ├── 2.11BSD-m11-getl.lst.ok ├── 2.11BSD-m11-lout.lst.ok ├── 2.11BSD-m11-mac.lst.ok ├── 2.11BSD-m11-macro.lst.ok ├── 2.11BSD-m11-misc.lst.ok ├── 2.11BSD-m11-often.lst.ok ├── 2.11BSD-m11-pst.lst.ok ├── 2.11BSD-m11-srch.lst.ok ├── 2.11BSD-m11-syscalls.lst.ok ├── 2.11BSD-m11-xlat.lst.ok ├── 2.11BSD-m11-xpcor.lst.ok ├── 2.11BSD │ ├── 00SOURCE │ └── m11 │ │ ├── Document │ │ ├── Makefile │ │ ├── READme │ │ ├── at.sml │ │ ├── code.m11 │ │ ├── debug.m11 │ │ ├── errs.m11 │ │ ├── exec.m11 │ │ ├── expr.m11 │ │ ├── fltg.m11 │ │ ├── getl.m11 │ │ ├── l11.x │ │ ├── lout.m11 │ │ ├── m11.1 │ │ ├── m11.x │ │ ├── mac.m11 │ │ ├── macro.m11 │ │ ├── macxrf.c │ │ ├── misc.m11 │ │ ├── often.m11 │ │ ├── pst.m11 │ │ ├── srch.m11 │ │ ├── syscalls.m11 │ │ ├── xlat.m11 │ │ └── xpcor.m11 ├── RunTests ├── SetTestOk ├── float.c ├── incl.mac ├── mafile.mac ├── test-asciz.lst.ok ├── test-asciz.mac ├── test-backpatch.lst.ok ├── test-backpatch.mac ├── test-blkb.lst.ok ├── test-blkb.mac ├── test-bsl-mac-arg.lst.ok ├── test-bsl-mac-arg.mac ├── test-cis.lst.ok ├── test-cis.mac ├── test-complex-reloc.lst.ok ├── test-complex-reloc.mac ├── test-complex-reloc.objd.ok ├── test-enabl-ama.lst.ok ├── test-enabl-ama.mac ├── test-enabl-lcm.lst.ok ├── test-enabl-lcm.mac ├── test-endm.lst.ok ├── test-endm.mac ├── test-float.lst.ok ├── test-float.mac ├── test-gbl.lst.ok ├── test-gbl.mac ├── test-if.lst.ok ├── test-if.mac ├── test-impword.lst.ok ├── test-impword.mac ├── test-include.lst.ok ├── test-include.mac ├── test-jmp.lst.ok ├── test-jmp.mac ├── test-listing.lst.ok ├── test-listing.mac ├── test-locals.lst.ok ├── test-locals.mac ├── test-macro-comma.lst.ok ├── test-macro-comma.mac ├── test-mcall-file.lst.ok ├── test-mcall-file.mac ├── test-opcodes.lst.ok ├── test-opcodes.mac ├── test-operands.lst.ok ├── test-operands.mac ├── test-prec.lst.ok ├── test-prec.mac ├── test-psect.lst.ok ├── test-psect.mac ├── test-rad50.lst.ok ├── test-rad50.mac ├── test-radix.lst.ok ├── test-radix.mac ├── test-reg.mac ├── test-reloc.lst.ok ├── test-reloc.mac ├── test-reloc.objd.ok ├── test-rept.lst.ok ├── test-rept.mac ├── test-syntax.lst.ok ├── test-syntax.mac ├── test-ua-pl.lst.ok ├── test-ua-pl.mac ├── test-ua-pl.objd.ok ├── test-undef.lst.ok ├── test-undef.mac ├── test-word-comma.lst.ok └── test-word-comma.mac ├── tools ├── checker.pl └── varrec.c ├── util.c └── util.h /.gitignore: -------------------------------------------------------------------------------- 1 | git-info.h 2 | *.d 3 | *.o 4 | dumpobj 5 | macro11 6 | tests/*.lst 7 | tests/*.obj 8 | tests/*.objd 9 | x/* 10 | tests/2.11BSD/l11 11 | tests/2.11BSD-*.mac 12 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | # Minimized from https://about.gitlab.com/2016/10/12/automated-debian-package-build-with-gitlab-ci/ 2 | # https://github.com/gitlabhq/gitlabhq/blob/master/vendor/gitlab-ci-yml/C%2B%2B.gitlab-ci.yml 3 | 4 | # use the official gcc image, based on debian 5 | # can use verions as well, like gcc:5.2 6 | # see https://hub.docker.com/_/gcc/ 7 | #image: gcc 8 | 9 | before_script: 10 | - apt-get update 11 | 12 | # Defines stages which are to be executed 13 | stages: 14 | - build-gcc 15 | - build-clang 16 | 17 | # Stage "build" 18 | run-build-gcc: 19 | stage: build-gcc 20 | script: 21 | - apt-get install -y gcc 22 | - make 23 | - cd tests && ./RunTests 24 | 25 | # Stage "build-clang" 26 | run-build-clang: 27 | stage: build-clang 28 | script: 29 | - apt-get install -y clang 30 | - CC=clang make 31 | - cd tests && ./RunTests 32 | 33 | -------------------------------------------------------------------------------- /.indent.pro: -------------------------------------------------------------------------------- 1 | --blank-lines-after-commas 2 | --blank-lines-after-declarations 3 | --blank-lines-after-procedures 4 | --braces-on-if-line 5 | --braces-on-struct-decl-line 6 | --break-before-boolean-operator 7 | --break-function-decl-args 8 | --break-function-decl-args-end 9 | --case-indentation0 10 | --comment-indentation40 11 | --continuation-indentation8 12 | --continue-at-parentheses 13 | --cuddle-do-while 14 | --cuddle-else 15 | --declaration-indentation16 16 | --dont-break-procedure-type 17 | --dont-format-comments 18 | --indent-level4 19 | --honour-newlines 20 | --leave-optional-blank-lines 21 | --line-comments-indentation0 22 | --line-length112 23 | --no-blank-lines-before-block-comments 24 | --no-space-after-function-call-names 25 | --no-tabs 26 | --paren-indentation4 27 | --space-special-semicolon 28 | --tab-size8 29 | -T ADDR_MODE 30 | -T ARG 31 | -T BUFFER 32 | -T EX_TREE 33 | -T FILE 34 | -T MACRO 35 | -T MACRO_STREAM 36 | -T MLB 37 | -T MLBENT 38 | -T STACK 39 | -T STREAM 40 | -T SECTION 41 | -T SYMBOL 42 | -T SYMBOL_ITER 43 | -T SYMBOL_TABLE 44 | -T TEXT_COMPLEX 45 | -T TEXT_RLD 46 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | dist: bionic 3 | os: 4 | - linux 5 | - osx 6 | compiler: 7 | - gcc 8 | - clang 9 | script: 10 | - make 11 | - cd tests 12 | - ./RunTests 13 | -------------------------------------------------------------------------------- /CHANGES: -------------------------------------------------------------------------------- 1 | 07.07.2022: Rhialto 2 | version 0.8: 3 | - Improve parsing of symbols, e.g. `4..` is not a symbol. 4 | - More careful file format checking of .MLB files, so that you can 5 | use either RSX or RT format .MLB files, and autodetection works. 6 | - Replace the floating point parser by a version which is based on 7 | integer math only, because the Apple M1 doesn't have the required 8 | long double support in its compiler. 9 | 13 changes from Paul Koning that add some features which help to 10 | assemble RSTS/E sources: 11 | - Add default extensions to .include, .library 12 | - Fix .psect without argument, add (ignored) pseudo ops .mdelete, 13 | .cross, .nocross 14 | - Allow TRAP without argument, or with non-literal argument 15 | - Fix .library pseudo 16 | - Always list lines that have an error 17 | - Fix macro calls with omitted argument that has a default value, 18 | followed by additional (not omitted) arguments. 19 | - Implement .ENABLE MCL 20 | - Treat unexpected .IF argument as true, not false. This appears to 21 | be what the reference assembler does, at least it is necessary for 22 | certain RSTS source files to assemble without error. 23 | - Allow formal name of .IRP and .IRPC to be enclosed in < >. 24 | - Just like .RAD50, .IDENT accepts an argument that can contain not 25 | just delimited string characters but also values in < >. 26 | - Allow expression (with constant value) in .RADIX 27 | - Bugfixes in macro expansion, incl duplicate named arguments 28 | - Fix references to blank section: Its name is empty, not ". BLK." 29 | 30 | 05.01.2022: Rhialto 31 | version 0.7.2: 32 | - Improved error messages for bad addressing modes 33 | (due to gitlab issue #10) 34 | - Undefined symbols are now listed in the symbol table. 35 | - The weird way the unary "operator" % works in expressions is 36 | now implemented. 37 | The docs on page 3-8/9 aren't very precise but testing showed 38 | that any expression with a register in it can be used as a 39 | register, and (if used to define a symbol) is listed in the 40 | symbol table as such. %3+1 is <%3>+1 is R4. 41 | - Fixed registers being used in .word or immediate operands: 42 | no longer generated as being relocatable expressions. 43 | - 'make tests' works more portably. 44 | 45 | 16.05.2021: Rhialto 46 | version 0.7.1: 47 | - Fixed immediate source operand of LDEXP, LD[IL][FD] 48 | which is an integer, unlike several other FPP instructions. 49 | (gitlab issue #7) 50 | - Start each pass with .DSABL LSB (gitlab issue #8) 51 | 52 | 19.03.2021: Rhialto 53 | version 0.7: 54 | - Fixed the end-of-line check for MARK, EMT, TRAP. 55 | - Left/right shift operator _; disabled when the -yus option is used. 56 | Contributed by Stephen Casner. 57 | - Added some missing instructions: LDCFD, CSM, TSTSET, WRTLCK. 58 | 59 | 13.02.2021: Rhialto 60 | version 0.6: 61 | - Fixed rounding issues with floating point literals. 62 | - Fixed FPP instructions which take fp immediate operands. 63 | - Fixed bounds check on FPP AC0-3 operands. 64 | - Fix listing to show a % before values that represent a register 65 | number. 66 | - Added checks for junk text following correct code. This revealed 67 | some small other issues, now fixed. 68 | - Added CIS instructions; as an extension, for the Inline variants 69 | you can specify the descriptor addresses etc as arguments to 70 | the instruction (much like an implied .word). 71 | 72 | 25.04.2020: Rhialto 73 | version 0.5: 74 | - Fixed bug with checking addressing mode for JSR and bugs 75 | with .REPT 0, unneeded relocation on pc-relative mode. 76 | - Very simple .LIST and .NLIST implementation. 77 | - Add ^pl and ^ph expressions from 2.11BSD's m11. 78 | - Object-ified macro libraries with an eye to support the .sml 79 | files from 2.11BSD's m11. But since the given file does not 80 | just contain .MACROs (it even contains conditionals) I'm not 81 | sure how it is supposed to work. 82 | - Added 2.11BSD/m11 as test files. To make this reasonable, a 83 | few small features they use have been recognized and ignored. 84 | - Add -rsx and -rt11 to switch object file format (from Kevin Handy) 85 | - Add obj2bin from https://github.com/AK6DN/obj2bin.git 86 | 87 | 09.11.2015: Rhialto 88 | version 0.4: 89 | - Fixed various bugs. The most notable was extensive use- 90 | after-free in the expression tree, which crashed on NetBSD but 91 | apparently not on other systems. 92 | - Lots of changes to make this MACRO11 more like the MACRO11 of 93 | RSX-11M+ 4.6. I used Kermit-11 source files for comparison. 94 | "The Manual" I'm refering to is 95 | AA-KX10A-TC_PDP-11_MACRO-11_Reference_Manual_May88.pdf at 96 | www.bitsavers.org/pdf/dec/pdp11/rsx11/RSX11Mplus_V4.x/4a/ and 97 | I use an installed system to double-check. 98 | 99 | ----------- Joerg Hoppe's entries ------------------ 100 | 101 | 19.4.2009: JH 102 | version 0.3 103 | - bugfix: Illegal labels and illegal opcodes are processed as 104 | "implied .WORD" directives. 105 | Expression errors in "do_word()" did not process any input character, 106 | so parser did go into an endless loop. 107 | - Switchable syntax extensions with -yxx options: 108 | symbol len can be adjusted with "-ysl" command line option. 109 | "-yus" option allows underscore "_" char in symbols. 110 | This was needed to process code generated by my favorite disassembler. 111 | - command line help added (-h option) 112 | 113 | 17.4.2009: JH 114 | version 0.3 115 | - ".INCLUDE" re-enabled 116 | - refactoring: big 6000+ lines "macro11.c" split into 10 modules. 117 | 118 | 15.4.2009: JH 119 | Begin rework by Joerg Hoppe (j_hoppe@t-online.de) 120 | All my changes are marked with "/*JH: .. */" comments 121 | 122 | 123 | ----------- Richard Krebiehls entries ------------------ 124 | 125 | 126 | 15-July-2001 127 | version 0.2 128 | removed references to snprintf from dumpobj.c and 129 | mlb.c for portability 130 | fixed a type cast warning in dumpobj.c compare_gsdlines 131 | Removed strcasecmp from macro11.c for portability 132 | Removed references to wnewmem.c from makefile (isn't needed) 133 | makefile more compatible with non-gnu make and compiler 134 | main prints version 0.2 135 | 136 | 14-July-2001 137 | First release, version 0.1. 138 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2001, Richard Krehbiel 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | o Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | o Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | o Neither the name of the copyright holder nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 24 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 26 | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 28 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 29 | USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 30 | DAMAGE. 31 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ##### 2 | # 3 | # Makefile for macro11 and dumpobj 4 | # 5 | 6 | WARNS ?= -Wall -Wshadow -Wextra -pedantic -Woverflow -Wstrict-overflow 7 | OBJFORMAT ?= -DDEFAULT_OBJECTFORMAT_RT11=0 8 | #SANITIZE ?= -fsanitize=address -fsanitize=undefined -fsanitize-recover=all -fno-omit-frame-pointer 9 | DEBUG ?= -ggdb $(SANITIZE) 10 | OPT ?= -O3 11 | CFLAGS ?= -std=gnu99 $(WARNS) $(DEBUG) $(OPT) $(OBJFORMAT) 12 | 13 | MACRO11_SRCS = macro11.c \ 14 | assemble.c assemble_globals.c assemble_aux.c \ 15 | extree.c listing.c macros.c parse.c rept_irpc.c symbols.c \ 16 | mlb2.c mlb-rsx.c mlb-rt11.c object.c stream2.c util.c rad50.c 17 | 18 | MACRO11_OBJS = $(MACRO11_SRCS:.c=.o) 19 | 20 | DUMPOBJ_SRCS = dumpobj.c rad50.c 21 | 22 | DUMPOBJ_OBJS = $(DUMPOBJ_SRCS:.c=.o) 23 | 24 | ALL_SRCS = $(MACRO11_SRCS) $(DUMPOBJ_SRCS) 25 | 26 | all: macro11 dumpobj 27 | 28 | tags: macro11 dumpobj 29 | ctags *.c *.h 30 | 31 | macro11: git-info.h $(MACRO11_OBJS) Makefile 32 | $(CC) $(CFLAGS) -o macro11 $(MACRO11_OBJS) -lm 33 | 34 | dumpobj: $(DUMPOBJ_OBJS) Makefile 35 | $(CC) $(CFLAGS) -o dumpobj $(DUMPOBJ_OBJS) 36 | 37 | $(MACRO11_OBJS): Makefile 38 | $(DUMPOBJ_OBJS): Makefile 39 | 40 | git-info.h: 41 | ./make-git-info 42 | 43 | # Bootstrap dependency on the git header file, which otherwise 44 | # gets generated too late. 45 | macro11.o: git-info.h 46 | macro11.c: git-info.h 47 | 48 | clean: 49 | -rm -f $(MACRO11_OBJS) $(DUMPOBJ_OBJS) macro11 dumpobj 50 | -rm -f *.d 51 | -rm -f git-info.h 52 | 53 | # Since the only tests we have so far are for crashes, 54 | # just try to assemble. Later, we will need expected/actual tests. 55 | 56 | # Test that all options requiring a value bail out if it's not present. 57 | argtests: macro11 58 | @ for OPT in -e -d -m -p -o -l -ysl ; do \ 59 | ./macro11 foo.mac $$OPT 2> /dev/null; \ 60 | if [ $$? = 1 ]; then echo PASS; else echo FAIL; fi; \ 61 | echo " $$OPT missing value"; \ 62 | ./macro11 foo.mac $$OPT -v 2> /dev/null; \ 63 | if [ $$? = 1 ]; then echo PASS; else echo FAIL; fi; \ 64 | echo " $$OPT fol. by option"; \ 65 | done 66 | @ ./macro11 foo.mac $$OPT -x -v 2> /dev/null; \ 67 | if [ $$? = 1 ]; then echo PASS; else echo FAIL; fi; \ 68 | echo " -x must be the last option" 69 | 70 | LSAN_OPTIONS=suppressions=../macro11.supp 71 | 72 | tests: macro11 argtests 73 | cd tests && env LSAN_OPTIONS="${LSAN_OPTIONS}" ./RunTests 74 | 75 | # Automatic dependency generation 76 | 77 | ifneq ($(MAKECMDGOALS),clean) 78 | -include $(ALL_SRCS:.c=.d) 79 | endif 80 | 81 | # Make .d files as side effect of compiling .c to .o 82 | %.d %.o: %.c 83 | $(CC) $(CFLAGS) -c -o $*.o $< 84 | @set -e; rm -f $*.d; \ 85 | $(CC) -MM $(CPPFLAGS) $< > $@.$$$$; \ 86 | sed 's,\($*\)\.o[ :]*,\1.o \1.d : ,g' < $@.$$$$ > $*.d; \ 87 | rm -f $@.$$$$ 88 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | .packed pdf page 80 2 | 3 | listing format errors: ignore whitespace of input 4 | 5 | documentation: print supported directives 6 | 7 | --------------------------------------- 8 | I was not able to locate a Macro-11 language reference manual any more 9 | recent than for RT11 version *3*, so I used that plus my recollection 10 | of more modern features. It was enough to get the RT11 V5.4 kernel 11 | built, plus a significant chunk of our own code. 12 | 13 | The biggest missing feature is full featured listings. The .LIST and 14 | .NLIST directives are ignored, as is .SBTTL. No table of contents is 15 | accumulated or printed. No symbol cross referencing is done (most 16 | likely I'll just write a CTAGS file, not a cross reference listing). 17 | 18 | Many errors still go unchecked. Off the top of my head, I recall that 19 | object and listing file output errors are ignored. 20 | 21 | .FLT4 format may be inaccurate in the low bits. This is because IEEE 22 | 64 bit format has two fewer mantissa bits than 64 bit PDP-11 format. 23 | Without writing soft-float routines, there's not much I can do abbout 24 | it. 25 | 26 | Expression math is done in native width, almost certainly 32 bits. 27 | Truncation to 16 bits is done only for listing and output. This may 28 | make some output differ in the presence of 16-bit overflows and 29 | underflows. I don't think this needs fixing. 30 | 31 | .REM blocks containing code can screw up .MACRO, .REPT, .IRP, .IRPC. 32 | read_body in macro11.c would need to be able to parse and ignore .REM 33 | blocks. 34 | 35 | Need to search a path for the .INCLUDE directive. Right now it only 36 | takes a complete file name. And most likely, existing code will have 37 | RT-11 style file names; I don't know what to do about that, except put 38 | in a device name parser. 39 | 40 | Possible enhancements: 41 | 42 | It would be very simple to make macro11 resolve internal symbols with 43 | more that 6 significant characters. Even so, only the first 6 would 44 | be used for external symbols, and you have to be wary of existing code 45 | that used (for example) .LOOKU rather than .LOOKUP, since these two 46 | would become distinct. 47 | 48 | SYM = 0 49 | MOV SYM(R0),R0 ; macro11 could optimize SYM(R0) into just (R0) 50 | 51 | I dream of automatically fixing branches out of range. Easy when the 52 | destination is backwards, difficult when it's forwards. I have this 53 | idea: during the first assembly pass, all branches generate a long 54 | branch if the target symbol is undefined, otherwise an "optimized" 55 | branch (short or long) if the target is defined. Then keep a 56 | 128-instruction FIFO of generated instructions. Each FIFO entry is 57 | tagged with context and symbol definition as they are pushed to the 58 | FIFO. When an instruction gets pulled from the FIFO because it's more 59 | than 128 words away, the FIFO is searched for long branches that point 60 | to this location; any such are shortened, and any symbols defined 61 | following their location in the stream are adjusted. In the second 62 | assembly pass, the FIFOs aren't used because all jump distances are 63 | known, and the right sized branch (JMP or Bcc) can be generated. 64 | 65 | -------------------------------------------------------------------------------- /assemble.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef ASSEMBLE__H 3 | #define ASSEMBLE__H 4 | 5 | 6 | #include "stream2.h" 7 | #include "object.h" 8 | 9 | 10 | 11 | #define DOT (current_pc->value) /* Handy reference to the current location */ 12 | 13 | int assemble_stack( 14 | STACK *stack, 15 | TEXT_RLD *tr); 16 | int get_next_lsb( 17 | void); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /assemble_aux.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef ASSEMBLE_AUX__H 3 | #define ASSEMBLE_AUX__H 4 | 5 | #include "stream2.h" 6 | #include "object.h" 7 | #include "extree.h" 8 | 9 | #define NO_REG 0777 10 | 11 | 12 | typedef struct addr_mode { 13 | unsigned type; /* The bits that represent the addressing mode */ 14 | /* bits 0:2 are register number */ 15 | /* bit 3 is indirect */ 16 | /* bits 4:6 are mode, where 0=Rn, 1=(Rn)+, 17 | 2=-(Rn), 3=offset(Rn) */ 18 | int pcrel; /* the addressing mode is PC-relative */ 19 | EX_TREE *offset; /* Expression giving the offset */ 20 | } ADDR_MODE; 21 | 22 | #define MODE_INDIRECT 010 /* (R0), @(R0)+, @-(R0), @42(R0) */ 23 | #define MODE_REG 000 /* R0 */ 24 | #define MODE_AUTO_INCR 020 /* (R0)+ */ 25 | #define MODE_AUTO_DECR 040 /* -(R0) */ 26 | #define MODE_OFFSET 060 /* 42(R0) */ 27 | #define MODE_PC 007 28 | 29 | void push_cond( 30 | int ok, 31 | STREAM *str); 32 | void pop_cond( 33 | int to); 34 | 35 | int express_sym_offset( 36 | EX_TREE *value, 37 | SYMBOL **sym, 38 | unsigned *offset); 39 | 40 | void change_dot( 41 | TEXT_RLD *tr, 42 | int size); 43 | 44 | int store_word( 45 | STREAM *str, 46 | TEXT_RLD *tr, 47 | int size, 48 | unsigned word); 49 | int store_limits( 50 | STREAM *str, 51 | TEXT_RLD *tr); 52 | void store_value( 53 | STACK *stack, 54 | TEXT_RLD *tr, 55 | int size, 56 | EX_TREE *value); 57 | 58 | int do_word( 59 | STACK *stack, 60 | TEXT_RLD *tr, 61 | char *cp, 62 | int size); 63 | 64 | SECTION *new_section( 65 | void); 66 | void go_section( 67 | TEXT_RLD *tr, 68 | SECTION *sect); 69 | 70 | void free_addr_mode( 71 | ADDR_MODE *mode); 72 | 73 | int eval_defined( 74 | EX_TREE *value); 75 | int eval_undefined( 76 | EX_TREE *value); 77 | 78 | 79 | void mode_extension( 80 | TEXT_RLD *tr, 81 | ADDR_MODE *mode, 82 | STREAM *str); 83 | int check_branch( 84 | STACK *stack, 85 | unsigned offset, 86 | int min, 87 | int max); 88 | unsigned get_register( 89 | EX_TREE *expr); 90 | 91 | void write_globals( 92 | FILE *obj); 93 | void migrate_implicit( 94 | void); 95 | void migrate_undefined( 96 | void); 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /assemble_globals.c: -------------------------------------------------------------------------------- 1 | 2 | #define ASSEMBLE_GLOBALS__C 3 | 4 | 5 | #include "assemble_globals.h" /* own definitions */ 6 | 7 | #include "object.h" 8 | 9 | 10 | /* GLOBAL VARIABLES */ 11 | int pass = 0; /* The current assembly pass. 0 = first pass */ 12 | int stmtno = 0; /* The current source line number */ 13 | int radix = 8; /* The current input conversion radix */ 14 | 15 | 16 | int lsb = 0; /* The current local symbol section identifier */ 17 | int lsb_used = 0; /* Whether there was a local symbol using this lsb */ 18 | int next_lsb = 0; /* The number of the next local symbol block */ 19 | int last_macro_lsb = 0; /* The last block in which a macro 20 | automatic label was created */ 21 | 22 | int last_locsym = 32768; /* The last local symbol number generated */ 23 | 24 | 25 | int enabl_debug = 0; /* Whether assembler debugging is enabled */ 26 | 27 | int opt_enabl_ama = 0; /* May be changed by command line */ 28 | int enabl_ama; /* When set, chooses absolute (037) versus 29 | PC-relative */ 30 | /* (067) addressing mode */ 31 | int enabl_lsb = 0; /* When set, stops non-local symbol 32 | definitions from delimiting local 33 | symbol sections. */ 34 | 35 | int enabl_gbl = 1; /* Implicit definition of global symbols */ 36 | 37 | int enabl_lc = 1; /* If lowercase disabled, convert assembler 38 | source to upper case. */ 39 | 40 | int enabl_lcm = 0; /* If lowercase disabled, .IF IDN/DIF are 41 | case-sensitive. */ 42 | 43 | int enabl_mcl = 0; /* When set, unknown symbols are looked up 44 | as if .MCALL had been done. */ 45 | 46 | int suppressed = 0; /* Assembly suppressed by failed conditional */ 47 | 48 | 49 | MLB *mlbs[MAX_MLBS]; /* macro libraries specified on the 50 | command line */ 51 | int nr_mlbs = 0; /* Number of macro libraries */ 52 | 53 | COND conds[MAX_CONDS]; /* Stack of recent conditions */ 54 | int last_cond; /* 0 means no stacked cond. */ 55 | 56 | SECTION *sect_stack[SECT_STACK_SIZE]; /* 32 saved sections */ 57 | int dot_stack[SECT_STACK_SIZE]; /* 32 saved sections */ 58 | int sect_sp; /* Stack pointer */ 59 | 60 | char *module_name = NULL; /* The module name (taken from the 'TITLE'); */ 61 | 62 | unsigned *ident = NULL; /* Encoded .IDENT name */ 63 | 64 | EX_TREE *xfer_address = NULL; /* The transfer address */ 65 | 66 | SYMBOL *current_pc; /* The current program counter */ 67 | 68 | unsigned last_dot_addr; /* Last coded PC... */ 69 | SECTION *last_dot_section; /* ...and its program section */ 70 | 71 | /* The following are dummy psects for symbols which have meaning to 72 | the assembler: */ 73 | 74 | SECTION register_section = { 75 | "*REGISTERS*", SECTION_REGISTER, 0, 0, 0, 0 76 | }; /* the section containing the registers */ 77 | 78 | SECTION pseudo_section = { 79 | "*PSEUDO*", SECTION_PSEUDO, 0, 0, 0, 0 80 | }; /* the section containing the 81 | pseudo-operations */ 82 | 83 | SECTION instruction_section = { 84 | "*INSTR*", SECTION_INSTRUCTION, 0, 0, 0, 0 85 | }; /* the section containing instructions */ 86 | 87 | SECTION macro_section = { 88 | "*MACRO*", SECTION_SYSTEM, 0, 0, 0, 0 89 | }; /* Section for macros */ 90 | 91 | /* These are real psects that get written out to the object file */ 92 | 93 | SECTION absolute_section = { 94 | ". ABS.", SECTION_SYSTEM, PSECT_GBL | PSECT_COM, 0, 0, 0 95 | }; /* The default 96 | absolute section */ 97 | 98 | SECTION blank_section = { 99 | "", SECTION_SYSTEM, PSECT_REL, 0, 0, 1 100 | }; /* The default relocatable section */ 101 | 102 | SECTION *sections[256] = { 103 | /* Array of sections in the order they were 104 | defined */ 105 | &absolute_section, &blank_section, 106 | }; 107 | 108 | int sector = 2; /* number of such sections */ 109 | -------------------------------------------------------------------------------- /assemble_globals.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef ASSEMBLE_GLOBALS__H 3 | #define ASSEMBLE_GLOBALS__H 4 | 5 | 6 | #include "mlb.h" 7 | #include "symbols.h" 8 | #include "extree.h" 9 | 10 | 11 | 12 | #define MAX_MLBS 32 /* number of macro libraries */ 13 | 14 | #define MAX_CONDS 256 15 | typedef struct cond { 16 | int ok; /* What the condition evaluated to */ 17 | char *file; /* What file and line it occurred */ 18 | int line; 19 | } COND; 20 | 21 | #define SECT_STACK_SIZE 32 22 | 23 | #ifndef ASSEMBLE_GLOBALS__C 24 | /* GLOBAL VARIABLES */ 25 | extern int pass; /* The current assembly pass. 0 = first pass */ 26 | extern int stmtno; /* The current source line number */ 27 | extern int radix; /* The current input conversion radix */ 28 | extern int lsb; /* The current local symbol section identifier */ 29 | extern int lsb_used; /* Whether there was a local symbol using this lsb */ 30 | extern int next_lsb; /* The number of the next local symbol block */ 31 | extern int last_macro_lsb; /* The last block in which a macro 32 | automatic label was created */ 33 | 34 | extern int last_locsym; /* The last local symbol number generated */ 35 | 36 | extern int enabl_debug; /* Whether assembler debugging is enabled */ 37 | 38 | extern int opt_enabl_ama; /* May be changed by command line */ 39 | 40 | extern int enabl_ama; /* When set, chooses absolute (037) versus 41 | PC-relative */ 42 | /* (067) addressing mode */ 43 | extern int enabl_lsb; /* When set, stops non-local symbol 44 | definitions from delimiting local 45 | symbol sections. */ 46 | 47 | extern int enabl_gbl; /* Implicit definition of global symbols */ 48 | 49 | extern int enabl_lc; /* If lowercase disabled, convert assembler 50 | source to upper case. */ 51 | extern int enabl_lcm; /* If lowercase disabled, .IF IDN/DIF are 52 | case-sensitive. */ 53 | extern int suppressed; /* Assembly suppressed by failed conditional */ 54 | 55 | extern MLB *mlbs[MAX_MLBS]; /* macro libraries specified on the command line */ 56 | extern int nr_mlbs; /* Number of macro libraries */ 57 | 58 | extern int enabl_mcl; /* If MCALL of unknown symbols is enabled. */ 59 | 60 | extern COND conds[MAX_CONDS]; /* Stack of recent conditions */ 61 | extern int last_cond; /* 0 means no stacked cond. */ 62 | 63 | extern SECTION *sect_stack[SECT_STACK_SIZE]; /* 32 saved sections */ 64 | extern int dot_stack[SECT_STACK_SIZE]; /* 32 saved sections */ 65 | extern int sect_sp; /* Stack pointer */ 66 | 67 | extern char *module_name; /* The module name (taken from the 'TITLE'); */ 68 | 69 | extern unsigned *ident; /* .IDENT name (encoded RAD50 value) */ 70 | 71 | extern EX_TREE *xfer_address; /* The transfer address */ 72 | 73 | extern SYMBOL *current_pc; /* The current program counter */ 74 | 75 | extern unsigned last_dot_addr; /* Last coded PC... */ 76 | extern SECTION *last_dot_section; /* ...and its program section */ 77 | 78 | /* The following are dummy psects for symbols which have meaning to 79 | the assembler: */ 80 | extern SECTION register_section; 81 | extern SECTION pseudo_section; /* the section containing the pseudo-operations */ 82 | extern SECTION instruction_section; /* the section containing instructions */ 83 | extern SECTION macro_section; /* Section for macros */ 84 | 85 | /* These are real psects that get written out to the object file */ 86 | extern SECTION absolute_section; /* The default absolute section */ 87 | extern SECTION blank_section; 88 | extern SECTION *sections[256]; /* Array of sections in the order they were defined */ 89 | extern int sector; /* number of such sections */ 90 | 91 | #endif 92 | 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /dumpobj.dsp: -------------------------------------------------------------------------------- 1 | # Microsoft Developer Studio Project File - Name="dumpobj" - Package Owner=<4> 2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00 3 | # ** DO NOT EDIT ** 4 | 5 | # TARGTYPE "Win32 (x86) Console Application" 0x0103 6 | 7 | CFG=dumpobj - Win32 Debug 8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE, 9 | !MESSAGE use the Export Makefile command and run 10 | !MESSAGE 11 | !MESSAGE NMAKE /f "dumpobj.mak". 12 | !MESSAGE 13 | !MESSAGE You can specify a configuration when running NMAKE 14 | !MESSAGE by defining the macro CFG on the command line. For example: 15 | !MESSAGE 16 | !MESSAGE NMAKE /f "dumpobj.mak" CFG="dumpobj - Win32 Debug" 17 | !MESSAGE 18 | !MESSAGE Possible choices for configuration are: 19 | !MESSAGE 20 | !MESSAGE "dumpobj - Win32 Release" (based on "Win32 (x86) Console Application") 21 | !MESSAGE "dumpobj - Win32 Debug" (based on "Win32 (x86) Console Application") 22 | !MESSAGE 23 | 24 | # Begin Project 25 | # PROP AllowPerConfigDependencies 0 26 | # PROP Scc_ProjName ""$/macro11", BAAAAAAA" 27 | # PROP Scc_LocalPath "." 28 | CPP=cl.exe 29 | RSC=rc.exe 30 | 31 | !IF "$(CFG)" == "dumpobj - Win32 Release" 32 | 33 | # PROP BASE Use_MFC 0 34 | # PROP BASE Use_Debug_Libraries 0 35 | # PROP BASE Output_Dir "Release" 36 | # PROP BASE Intermediate_Dir "Release" 37 | # PROP BASE Target_Dir "" 38 | # PROP Use_MFC 0 39 | # PROP Use_Debug_Libraries 0 40 | # PROP Output_Dir "dumpobj___Release" 41 | # PROP Intermediate_Dir "dumpobj___Release" 42 | # PROP Ignore_Export_Lib 0 43 | # PROP Target_Dir "" 44 | # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c 45 | # ADD CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c 46 | # ADD BASE RSC /l 0x409 /d "NDEBUG" 47 | # ADD RSC /l 0x409 /d "NDEBUG" 48 | BSC32=bscmake.exe 49 | # ADD BASE BSC32 /nologo 50 | # ADD BSC32 /nologo 51 | LINK32=link.exe 52 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 53 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 54 | 55 | !ELSEIF "$(CFG)" == "dumpobj - Win32 Debug" 56 | 57 | # PROP BASE Use_MFC 0 58 | # PROP BASE Use_Debug_Libraries 1 59 | # PROP BASE Output_Dir "Debug" 60 | # PROP BASE Intermediate_Dir "Debug" 61 | # PROP BASE Target_Dir "" 62 | # PROP Use_MFC 0 63 | # PROP Use_Debug_Libraries 1 64 | # PROP Output_Dir "dumpobj___Debug" 65 | # PROP Intermediate_Dir "dumpobj___Debug" 66 | # PROP Ignore_Export_Lib 0 67 | # PROP Target_Dir "" 68 | # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c 69 | # ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c 70 | # ADD BASE RSC /l 0x409 /d "_DEBUG" 71 | # ADD RSC /l 0x409 /d "_DEBUG" 72 | BSC32=bscmake.exe 73 | # ADD BASE BSC32 /nologo 74 | # ADD BSC32 /nologo 75 | LINK32=link.exe 76 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept 77 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept 78 | 79 | !ENDIF 80 | 81 | # Begin Target 82 | 83 | # Name "dumpobj - Win32 Release" 84 | # Name "dumpobj - Win32 Debug" 85 | # Begin Group "Source Files" 86 | 87 | # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" 88 | # Begin Source File 89 | 90 | SOURCE=.\dumpobj.c 91 | # End Source File 92 | # Begin Source File 93 | 94 | SOURCE=.\Rad50.c 95 | # End Source File 96 | # End Group 97 | # Begin Group "Header Files" 98 | 99 | # PROP Default_Filter "h;hpp;hxx;hm;inl" 100 | # Begin Source File 101 | 102 | SOURCE=.\Rad50.h 103 | # End Source File 104 | # Begin Source File 105 | 106 | SOURCE=.\util.h 107 | # End Source File 108 | # End Group 109 | # Begin Group "Resource Files" 110 | 111 | # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" 112 | # End Group 113 | # End Target 114 | # End Project 115 | -------------------------------------------------------------------------------- /extree.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef EXTREE__H 3 | #define EXTREE__H 4 | 5 | #include "symbols.h" 6 | 7 | typedef struct ex_tree { 8 | enum ex_type { 9 | EX_LIT = 1, 10 | /* Expression is a literal value */ 11 | EX_SYM = 2, 12 | /* Expression has a symbol reference 13 | * (symbol from symbol table, so not freed) */ 14 | EX_UNDEFINED_SYM = 3, 15 | /* Expression is undefined sym reference */ 16 | EX_TEMP_SYM = 4, 17 | /* Expression is temp sym reference */ 18 | 19 | EX_COM = 5, 20 | /* One's complement */ 21 | EX_NEG = 6, 22 | /* Negate */ 23 | EX_REG = 7, 24 | /* register value (%) */ 25 | EX_ERR = 8, 26 | /* Expression with an error */ 27 | 28 | EX_ADD = 9, 29 | /* Add */ 30 | EX_SUB = 10, 31 | /* Subtract */ 32 | EX_MUL = 11, 33 | /* Multiply */ 34 | EX_DIV = 12, 35 | /* Divide */ 36 | EX_AND = 13, 37 | /* bitwise and */ 38 | EX_OR = 14, 39 | /* bitwise or */ 40 | EX_LSH = 15, 41 | /* left shift */ 42 | } type; 43 | 44 | char *cp; /* points to end of parsed expression */ 45 | 46 | union { 47 | struct { 48 | struct ex_tree *left, 49 | *right; /* Left, right children */ 50 | } child; 51 | unsigned lit; /* Literal value */ 52 | SYMBOL *symbol; /* Symbol reference */ 53 | } data; 54 | } EX_TREE; 55 | 56 | 57 | EX_TREE *new_ex_tree( 58 | int type); 59 | void free_tree( 60 | EX_TREE *tp); 61 | 62 | EX_TREE *new_ex_lit( 63 | unsigned value); 64 | EX_TREE *ex_err( 65 | EX_TREE *tp, 66 | char *cp); 67 | EX_TREE *new_ex_bin( 68 | int type, 69 | EX_TREE *left, 70 | EX_TREE *right); 71 | EX_TREE *new_ex_una( 72 | int type, 73 | EX_TREE *left); 74 | int num_subtrees( 75 | EX_TREE *tp); 76 | EX_TREE *evaluate( 77 | EX_TREE *tp, 78 | int flags); 79 | 80 | #define EVALUATE_DEFINEDNESS 1 81 | 82 | #define EVALUATE_OUT_IS_REGISTER 1 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /listing.c: -------------------------------------------------------------------------------- 1 | #define LISTING__C 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "listing.h" /* my own definitions */ 9 | 10 | #include "util.h" 11 | #include "assemble_globals.h" 12 | 13 | 14 | /* GLOBAL VARIABLES */ 15 | 16 | int list_md = 1; /* option to list macro/rept definition = yes */ 17 | 18 | int list_me = 1; /* option to list macro/rept expansion = yes */ 19 | 20 | int list_bex = 1; /* option to show binary */ 21 | 22 | int list_level = 1; /* Listing control level. .LIST 23 | increments; .NLIST decrements */ 24 | 25 | static char *listline; /* Source lines */ 26 | 27 | static char *binline; /* for octal expansion */ 28 | 29 | FILE *lstfile = NULL; 30 | 31 | int list_pass_0 = 0;/* Also list what happens during the first pass */ 32 | 33 | static int errline = 0; /* Set if current line has an error */ 34 | 35 | /* maybe_list returns TRUE if listing may happen for this line. */ 36 | 37 | static int can_list( 38 | void) 39 | { 40 | int ok = lstfile != NULL && 41 | (pass > 0 || list_pass_0); 42 | 43 | return ok; 44 | } 45 | 46 | /* do_list returns TRUE if listing is enabled. */ 47 | 48 | static int dolist( 49 | void) 50 | { 51 | int ok = can_list () && 52 | (list_level > 0 || errline); 53 | 54 | return ok; 55 | } 56 | 57 | /* list_source saves a text line for later listing by list_flush */ 58 | 59 | void list_source( 60 | STREAM *str, 61 | char *cp) 62 | { 63 | if (can_list()) { 64 | int len = strcspn(cp, "\n"); 65 | 66 | /* Not an error yet */ 67 | errline = 0; 68 | /* Save the line text away for later... */ 69 | if (listline) 70 | free(listline); 71 | listline = memcheck(malloc(len + 1)); 72 | memcpy(listline, cp, len); 73 | listline[len] = 0; 74 | 75 | if (!binline) 76 | binline = memcheck(malloc(sizeof(LSTFORMAT) + 16)); 77 | 78 | sprintf(binline, "%*s%*d", (int)SIZEOF_MEMBER(LSTFORMAT, flag), "", (int)SIZEOF_MEMBER(LSTFORMAT, line_number), 79 | str->line); 80 | } 81 | } 82 | 83 | /* list_flush produces a buffered list line. */ 84 | 85 | void list_flush( 86 | void) 87 | { 88 | if (dolist()) { 89 | padto(binline, offsetof(LSTFORMAT, source)); 90 | fputs(binline, lstfile); 91 | fputs(listline, lstfile); 92 | fputc('\n', lstfile); 93 | listline[0] = 0; 94 | binline[0] = 0; 95 | } 96 | } 97 | 98 | /* list_fit checks to see if a word will fit in the current listing 99 | line. If not, it flushes and prepares another line. */ 100 | 101 | static void list_fit( 102 | STREAM *str, 103 | unsigned addr) 104 | { 105 | size_t col1 = offsetof(LSTFORMAT, source); 106 | size_t col2 = offsetof(LSTFORMAT, pc); 107 | 108 | if (strlen(binline) >= col1) { 109 | list_flush(); 110 | listline[0] = 0; 111 | binline[0] = 0; 112 | sprintf(binline, "%*s %6.6o", (int)offsetof(LSTFORMAT, pc), "", addr); 113 | padto(binline, offsetof(LSTFORMAT, words)); 114 | } else if (strlen(binline) <= col2) { 115 | sprintf(binline, "%*s%*d %6.6o", (int)SIZEOF_MEMBER(LSTFORMAT, flag), "", 116 | (int)SIZEOF_MEMBER(LSTFORMAT, line_number), str->line, addr); 117 | padto(binline, offsetof(LSTFORMAT, words)); 118 | } 119 | } 120 | 121 | /* list_value is used to show a computed value */ 122 | 123 | void list_value( 124 | STREAM *str, 125 | unsigned word) 126 | { 127 | if (dolist()) { 128 | /* Print the value and go */ 129 | binline[0] = 0; 130 | sprintf(binline, "%*s%*d %6.6o", (int)SIZEOF_MEMBER(LSTFORMAT, flag), "", 131 | (int)SIZEOF_MEMBER(LSTFORMAT, line_number), str->line, word & 0177777); 132 | } 133 | } 134 | 135 | /* Print a word to the listing file */ 136 | 137 | void list_word( 138 | STREAM *str, 139 | unsigned addr, 140 | unsigned value, 141 | int size, 142 | char *flags) 143 | { 144 | if (dolist()) { 145 | list_fit(str, addr); 146 | if (size == 1) 147 | sprintf(binline + strlen(binline), " %3.3o%1.1s ", value & 0377, flags); 148 | else 149 | sprintf(binline + strlen(binline), "%6.6o%1.1s ", value & 0177777, flags); 150 | } 151 | } 152 | 153 | 154 | /* Print just a line with the address to the listing file */ 155 | 156 | void list_location( 157 | STREAM *str, 158 | unsigned addr) 159 | { 160 | if (dolist()) { 161 | list_fit(str, addr); 162 | } 163 | } 164 | 165 | 166 | 167 | /* reports errors */ 168 | void report( 169 | STREAM *str, 170 | char *fmt, 171 | ...) 172 | { 173 | va_list ap; 174 | char *name = "**"; 175 | int line = 0; 176 | 177 | if (!pass && list_pass_0 < 2) 178 | return; /* Don't report now. */ 179 | 180 | errline = 1; 181 | 182 | if (str) { 183 | name = str->name; 184 | line = str->line; 185 | } 186 | 187 | fprintf(stderr, "%s:%d: ***ERROR ", name, line); 188 | va_start(ap, fmt); 189 | vfprintf(stderr, fmt, ap); 190 | va_end(ap); 191 | 192 | if (lstfile) { 193 | fprintf(lstfile, "%s:%d: ***ERROR ", name, line); 194 | va_start(ap, fmt); 195 | vfprintf(lstfile, fmt, ap); 196 | va_end(ap); 197 | } 198 | } 199 | -------------------------------------------------------------------------------- /listing.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef LISTING__H 3 | #define LISTING__H 4 | 5 | #include "stream2.h" 6 | 7 | /* 8 | format of a listing line 9 | Interestingly, no instances of this struct are ever created. 10 | It lives to be a way to layout the format of a list line. 11 | I wonder if I should have bothered. 12 | */ 13 | 14 | typedef struct lstformat { 15 | char flag[2]; /* Error flags */ 16 | char line_number[6]; /* Line number */ 17 | char pc[8]; /* Location */ 18 | char words[8][3]; /* three instruction words */ 19 | char source[1]; /* source line */ 20 | } LSTFORMAT; 21 | 22 | 23 | /* GLOBAL VARIABLES */ 24 | #ifndef LISTING__C 25 | extern int list_md; /* option to list macro/rept definition = yes */ 26 | 27 | extern int list_me; /* option to list macro/rept expansion = yes */ 28 | 29 | extern int list_bex; /* option to show binary */ 30 | 31 | extern int list_level; /* Listing control level. .LIST 32 | increments; .NLIST decrements */ 33 | 34 | extern FILE *lstfile; 35 | 36 | extern int list_pass_0; /* Also list what happens during the first pass */ 37 | 38 | #endif 39 | 40 | 41 | void list_word( 42 | STREAM *str, 43 | unsigned addr, 44 | unsigned value, 45 | int size, 46 | char *flags); 47 | 48 | void list_value( 49 | STREAM *str, 50 | unsigned word); 51 | 52 | void list_location( 53 | STREAM *str, 54 | unsigned word); 55 | 56 | void list_source( 57 | STREAM *str, 58 | char *cp); 59 | 60 | void list_flush( 61 | void); 62 | 63 | void report( 64 | STREAM *str, 65 | char *fmt, 66 | ...); 67 | 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /macro11.dsp: -------------------------------------------------------------------------------- 1 | # Microsoft Developer Studio Project File - Name="macro11" - Package Owner=<4> 2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00 3 | # ** DO NOT EDIT ** 4 | 5 | # TARGTYPE "Win32 (x86) Console Application" 0x0103 6 | 7 | CFG=macro11 - Win32 Debug 8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE, 9 | !MESSAGE use the Export Makefile command and run 10 | !MESSAGE 11 | !MESSAGE NMAKE /f "macro11.mak". 12 | !MESSAGE 13 | !MESSAGE You can specify a configuration when running NMAKE 14 | !MESSAGE by defining the macro CFG on the command line. For example: 15 | !MESSAGE 16 | !MESSAGE NMAKE /f "macro11.mak" CFG="macro11 - Win32 Debug" 17 | !MESSAGE 18 | !MESSAGE Possible choices for configuration are: 19 | !MESSAGE 20 | !MESSAGE "macro11 - Win32 Release" (based on "Win32 (x86) Console Application") 21 | !MESSAGE "macro11 - Win32 Debug" (based on "Win32 (x86) Console Application") 22 | !MESSAGE 23 | 24 | # Begin Project 25 | # PROP AllowPerConfigDependencies 0 26 | # PROP Scc_ProjName ""$/macro11", BAAAAAAA" 27 | # PROP Scc_LocalPath "." 28 | CPP=cl.exe 29 | RSC=rc.exe 30 | 31 | !IF "$(CFG)" == "macro11 - Win32 Release" 32 | 33 | # PROP BASE Use_MFC 0 34 | # PROP BASE Use_Debug_Libraries 0 35 | # PROP BASE Output_Dir "Release" 36 | # PROP BASE Intermediate_Dir "Release" 37 | # PROP BASE Target_Dir "" 38 | # PROP Use_MFC 0 39 | # PROP Use_Debug_Libraries 0 40 | # PROP Output_Dir "Release" 41 | # PROP Intermediate_Dir "Release" 42 | # PROP Ignore_Export_Lib 0 43 | # PROP Target_Dir "" 44 | # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c 45 | # ADD CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c 46 | # SUBTRACT CPP /YX 47 | # ADD BASE RSC /l 0x409 /d "NDEBUG" 48 | # ADD RSC /l 0x409 /d "NDEBUG" 49 | BSC32=bscmake.exe 50 | # ADD BASE BSC32 /nologo 51 | # ADD BSC32 /nologo 52 | LINK32=link.exe 53 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 54 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 55 | # SUBTRACT LINK32 /profile 56 | # Begin Special Build Tool 57 | TargetPath=.\Release\macro11.exe 58 | SOURCE="$(InputPath)" 59 | PostBuild_Cmds=copy $(TargetPath) c:\bin 60 | # End Special Build Tool 61 | 62 | !ELSEIF "$(CFG)" == "macro11 - Win32 Debug" 63 | 64 | # PROP BASE Use_MFC 0 65 | # PROP BASE Use_Debug_Libraries 1 66 | # PROP BASE Output_Dir "Debug" 67 | # PROP BASE Intermediate_Dir "Debug" 68 | # PROP BASE Target_Dir "" 69 | # PROP Use_MFC 0 70 | # PROP Use_Debug_Libraries 1 71 | # PROP Output_Dir "Debug" 72 | # PROP Intermediate_Dir "Debug" 73 | # PROP Ignore_Export_Lib 0 74 | # PROP Target_Dir "" 75 | # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c 76 | # ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "MEM_DEBUG" /FR /FD /GZ /c 77 | # SUBTRACT CPP /YX 78 | # ADD BASE RSC /l 0x409 /d "_DEBUG" 79 | # ADD RSC /l 0x409 /d "_DEBUG" 80 | BSC32=bscmake.exe 81 | # ADD BASE BSC32 /nologo 82 | # ADD BSC32 /nologo 83 | LINK32=link.exe 84 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept 85 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept 86 | # SUBTRACT LINK32 /profile 87 | # Begin Special Build Tool 88 | TargetPath=.\Debug\macro11.exe 89 | SOURCE="$(InputPath)" 90 | PostBuild_Cmds=copy $(TargetPath) c:\bin 91 | # End Special Build Tool 92 | 93 | !ENDIF 94 | 95 | # Begin Target 96 | 97 | # Name "macro11 - Win32 Release" 98 | # Name "macro11 - Win32 Debug" 99 | # Begin Group "Source Files" 100 | 101 | # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" 102 | # Begin Source File 103 | 104 | SOURCE=.\macro11.c 105 | # End Source File 106 | # Begin Source File 107 | 108 | SOURCE=.\mlb.c 109 | # End Source File 110 | # Begin Source File 111 | 112 | SOURCE=.\object.c 113 | # End Source File 114 | # Begin Source File 115 | 116 | SOURCE=.\rad50.c 117 | # End Source File 118 | # Begin Source File 119 | 120 | SOURCE=.\stream2.c 121 | # End Source File 122 | # Begin Source File 123 | 124 | SOURCE=.\util.c 125 | # End Source File 126 | # End Group 127 | # Begin Group "Header Files" 128 | 129 | # PROP Default_Filter "h;hpp;hxx;hm;inl" 130 | # Begin Source File 131 | 132 | SOURCE=.\macro11.h 133 | # End Source File 134 | # Begin Source File 135 | 136 | SOURCE=.\mlb.h 137 | # End Source File 138 | # Begin Source File 139 | 140 | SOURCE=.\object.h 141 | # End Source File 142 | # Begin Source File 143 | 144 | SOURCE=.\Rad50.h 145 | # End Source File 146 | # Begin Source File 147 | 148 | SOURCE=.\stream2.h 149 | # End Source File 150 | # Begin Source File 151 | 152 | SOURCE=.\util.h 153 | # End Source File 154 | # End Group 155 | # Begin Group "Resource Files" 156 | 157 | # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" 158 | # End Group 159 | # Begin Source File 160 | 161 | SOURCE=.\Changes 162 | # End Source File 163 | # Begin Source File 164 | 165 | SOURCE=.\License 166 | # End Source File 167 | # Begin Source File 168 | 169 | SOURCE=.\Makefile 170 | # End Source File 171 | # Begin Source File 172 | 173 | SOURCE=.\Readme 174 | # End Source File 175 | # Begin Source File 176 | 177 | SOURCE=.\Todo 178 | # End Source File 179 | # End Target 180 | # End Project 181 | -------------------------------------------------------------------------------- /macro11.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "dumpobj"=.\dumpobj.dsp - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | begin source code control 11 | "$/macro11", BAAAAAAA 12 | . 13 | end source code control 14 | }}} 15 | 16 | Package=<4> 17 | {{{ 18 | }}} 19 | 20 | ############################################################################### 21 | 22 | Project: "macro11"=.\macro11.dsp - Package Owner=<4> 23 | 24 | Package=<5> 25 | {{{ 26 | begin source code control 27 | "$/macro11", BAAAAAAA 28 | . 29 | end source code control 30 | }}} 31 | 32 | Package=<4> 33 | {{{ 34 | }}} 35 | 36 | ############################################################################### 37 | 38 | Global: 39 | 40 | Package=<5> 41 | {{{ 42 | begin source code control 43 | "$/macro11", BAAAAAAA 44 | . 45 | end source code control 46 | }}} 47 | 48 | Package=<3> 49 | {{{ 50 | }}} 51 | 52 | ############################################################################### 53 | 54 | -------------------------------------------------------------------------------- /macro11.h: -------------------------------------------------------------------------------- 1 | #ifndef MACRO11_H 2 | #define MACRO11_H 3 | 4 | #include "git-info.h" 5 | 6 | #define BASE_VERSION "0.8" 7 | 8 | #if defined(GIT_VERSION) 9 | #define VERSIONSTR BASE_VERSION" ("GIT_VERSION"\n\t"GIT_AUTHOR_DATE")" 10 | #else 11 | #define VERSIONSTR BASE_VERSION" (07 Jul 2022)" 12 | /*#define VERSIONSTR "0.3 (April 21, 2009)" */ 13 | /*#define VERSIONSTR "0.2 July 15, 2001" */ 14 | #endif 15 | 16 | 17 | /* 18 | Copyright (c) 2001, Richard Krehbiel 19 | All rights reserved. 20 | 21 | Redistribution and use in source and binary forms, with or without 22 | modification, are permitted provided that the following conditions are 23 | met: 24 | 25 | o Redistributions of source code must retain the above copyright 26 | notice, this list of conditions and the following disclaimer. 27 | 28 | o Redistributions in binary form must reproduce the above copyright 29 | notice, this list of conditions and the following disclaimer in the 30 | documentation and/or other materials provided with the distribution. 31 | 32 | o Neither the name of the copyright holder nor the names of its 33 | contributors may be used to endorse or promote products derived from 34 | this software without specific prior written permission. 35 | 36 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 37 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 38 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 39 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 40 | HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 41 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 42 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 43 | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 44 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 45 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 46 | USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 47 | DAMAGE. 48 | */ 49 | 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /macro11.supp: -------------------------------------------------------------------------------- 1 | leak:atexit_handler_alloc 2 | -------------------------------------------------------------------------------- /macros.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef MACROS__H 3 | #define MACROS__H 4 | 5 | /* Arguments given to macros or .IRP/.IRPC blocks */ 6 | 7 | #include "symbols.h" 8 | #include "stream2.h" 9 | 10 | 11 | typedef struct arg { 12 | struct arg *next; /* Pointer in arg list */ 13 | int locsym; /* Whether arg represents an optional 14 | local symbol */ 15 | char *label; /* Argument name */ 16 | char *value; /* Default or active substitution */ 17 | } ARG; 18 | 19 | /* A MACRO is a superstructure surrounding a SYMBOL. */ 20 | 21 | typedef struct macro { 22 | SYMBOL sym; /* Surrounds a symbol, contains the macro 23 | name */ 24 | ARG *args; /* The argument list */ 25 | BUFFER *text; /* The macro text */ 26 | } MACRO; 27 | 28 | typedef struct macro_stream { 29 | BUFFER_STREAM bstr; /* Base class: buffer stream */ 30 | int nargs; /* Add number-of-macro-arguments */ 31 | int cond; /* Add saved conditional stack */ 32 | } MACRO_STREAM; 33 | 34 | 35 | #ifndef MACROS__C 36 | extern STREAM_VTBL macro_stream_vtbl; 37 | #endif 38 | 39 | MACRO *new_macro( 40 | char *label); 41 | void free_macro( 42 | MACRO *mac); 43 | 44 | MACRO *defmacro( 45 | char *cp, 46 | STACK *stack, 47 | int called); 48 | 49 | #define CALLED_NORMAL 0 50 | #define CALLED_NOLIST 1 51 | #define CALLED_NODEFINE 2 52 | 53 | STREAM *expandmacro( 54 | STREAM *refstr, 55 | MACRO *mac, 56 | char *cp); 57 | 58 | ARG *new_arg( 59 | void); 60 | 61 | void read_body( 62 | STACK *stack, 63 | BUFFER *gb, 64 | char *name, 65 | int called); 66 | char *getstring_macarg( 67 | STREAM *refstr, 68 | char *cp, 69 | char **endp); 70 | BUFFER *subst_args( 71 | BUFFER *text, 72 | ARG *args); 73 | 74 | int do_mcall ( 75 | char *label, 76 | STACK *stack); 77 | 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /make-git-info: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | desc=$(git describe --tags) 4 | 5 | if [ "$desc" = "" ] 6 | then 7 | echo "#undef GIT_VERSION" > new-git-info.h 8 | else 9 | auth=$(git log -n 1 "--pretty=format:%an <%ae> %aD") 10 | 11 | echo "#define GIT_VERSION "'"'"$desc"'"' >new-git-info.h 12 | echo "#define GIT_AUTHOR_DATE "'"'"$auth"'"' >>new-git-info.h 13 | fi 14 | 15 | # move-if-different 16 | if diff new-git-info.h git-info.h >/dev/null 2>&1 17 | then 18 | rm new-git-info.h 19 | else 20 | mv new-git-info.h git-info.h 21 | fi 22 | -------------------------------------------------------------------------------- /mlb.h: -------------------------------------------------------------------------------- 1 | #ifndef MLB_H 2 | #define MLB_H 3 | 4 | /* 5 | 6 | Copyright (c) 2001, Richard Krehbiel 7 | All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions are 11 | met: 12 | 13 | o Redistributions of source code must retain the above copyright 14 | notice, this list of conditions and the following disclaimer. 15 | 16 | o Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | 20 | o Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 29 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 30 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 31 | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 32 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 33 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 34 | USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 35 | DAMAGE. 36 | 37 | */ 38 | 39 | #include "stream2.h" 40 | 41 | /* Routines to open and read entries from a macro library */ 42 | 43 | typedef struct mlbent { 44 | char *label; 45 | unsigned long position; 46 | int length; 47 | } MLBENT; 48 | 49 | struct mlb_vtbl; 50 | 51 | typedef struct mlb { 52 | struct mlb_vtbl *vtbl; 53 | char *name; 54 | FILE *fp; 55 | MLBENT *directory; 56 | int nentries; 57 | int is_objlib; /* is really an object library */ 58 | } MLB; 59 | 60 | typedef struct mlb_vtbl { 61 | MLB *(*mlb_open)(char *name, int allow_object_library); 62 | BUFFER *(*mlb_entry)(MLB *mlb, char *name); 63 | void (*mlb_extract)(MLB *mlb); 64 | void (*mlb_close)(MLB *mlb); 65 | int mlb_is_rt11; 66 | } MLB_VTBL; 67 | 68 | extern MLB *mlb_open( 69 | char *name, 70 | int allow_object_library); 71 | extern BUFFER *mlb_entry( 72 | MLB *mlb, 73 | char *name); 74 | extern void mlb_close( 75 | MLB *mlb); 76 | extern void mlb_extract( 77 | MLB *mlb); 78 | 79 | extern struct mlb_vtbl mlb_rsx_vtbl; 80 | extern struct mlb_vtbl mlb_rt11_vtbl; 81 | 82 | #endif /* MLB_H */ 83 | -------------------------------------------------------------------------------- /mlb2.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017, Olaf Seibert 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | o Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | o Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | o Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 28 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 29 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 30 | USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 31 | DAMAGE. 32 | */ 33 | 34 | #include 35 | #include 36 | #include "util.h" 37 | #include "mlb.h" 38 | #include "object.h" 39 | 40 | MLB_VTBL *mlb_vtbls[] = { 41 | &mlb_rsx_vtbl, 42 | &mlb_rt11_vtbl, 43 | NULL 44 | }; 45 | 46 | static MLB *mlb_open_fmt( 47 | char *name, 48 | int allow_object_library, 49 | int object_format) 50 | { 51 | MLB_VTBL *vtbl; 52 | MLB *mlb = NULL; 53 | int i; 54 | 55 | for (i = 0; (vtbl = mlb_vtbls[i]); i++) { 56 | if (vtbl->mlb_is_rt11 == object_format) { 57 | mlb = vtbl->mlb_open(name, allow_object_library); 58 | if (mlb != NULL) { 59 | mlb->name = memcheck(strdup(name)); 60 | break; 61 | } 62 | } 63 | } 64 | 65 | return mlb; 66 | } 67 | 68 | MLB *mlb_open( 69 | char *name, 70 | int allow_object_library) 71 | { 72 | MLB *mlb = NULL; 73 | 74 | /* 75 | * First try the open function for the currently set object format. 76 | * If that fails, try the other one. 77 | */ 78 | mlb = mlb_open_fmt(name, allow_object_library, rt11); 79 | if (mlb == NULL) { 80 | mlb = mlb_open_fmt(name, allow_object_library, !rt11); 81 | } 82 | 83 | return mlb; 84 | } 85 | 86 | BUFFER *mlb_entry( 87 | MLB *mlb, 88 | char *name) 89 | { 90 | return mlb->vtbl->mlb_entry(mlb, name); 91 | } 92 | 93 | void mlb_close( 94 | MLB *mlb) 95 | { 96 | free(mlb->name); 97 | mlb->vtbl->mlb_close(mlb); 98 | } 99 | 100 | void mlb_extract( 101 | MLB *mlb) 102 | { 103 | mlb->vtbl->mlb_extract(mlb); 104 | } 105 | 106 | 107 | -------------------------------------------------------------------------------- /obj2bin/.gitignore: -------------------------------------------------------------------------------- 1 | # ignore these files: 2 | # ignore these directories: 3 | tests/ 4 | # the end 5 | -------------------------------------------------------------------------------- /obj2bin/README.md: -------------------------------------------------------------------------------- 1 | obj2bin.pl is a PDP-11 object file translator / linker, transforming an .obj file as output from macro11 into an absolute binary load image file (.bin) or other useful formats (.hex). 2 | 3 | If run with no options, it prints a usage screen: 4 | 5 | ``` 6 | obj2bin.pl v2.1 by Don North (perl 5.03) 7 | Usage: ./obj2bin.pl [options...] arguments 8 | --help output manpage and exit 9 | --debug enable debug mode 10 | --verbose verbose status reporting 11 | --boot M9312 boot prom .hex 12 | --console M9312 console/diagnostic prom .hex 13 | --binary binary program load image .bin [default] 14 | --ascii ascii m9312 program load image .txt 15 | --rt11 read .obj files in RT11 format 16 | --rsx11 read .obj files in RSX11 format [default] 17 | --bytes=N bytes per block on output hex format 18 | --nocrc inhibit output of CRC-16 in hex format 19 | --logfile=LOGFILE logging message file 20 | --outfile=OUTFILE output .hex/.txt/.bin file 21 | OBJFILE... macro11 object .obj file(s) 22 | Aborted due to command line errors. 23 | ``` 24 | 25 | If run with the --help option it prints a longer manual page: 26 | 27 | ``` 28 | NAME 29 | obj2bin.pl - Convert a Macro-11 program image to PROM/load format 30 | 31 | SYNOPSIS 32 | obj2bin.pl [--help] [--debug] [--verbose] [--boot] [--console] [--binary] 33 | [--ascii] [--rt11] [--rsx11] [--bytes=N] [--nocrc] [--logfile=LOGFILE] 34 | --outfile=BINFILE OBJFILE 35 | 36 | DESCRIPTION 37 | Converts a Macro-11 object files to various output formats, including 38 | M9312 boot and console PROM, straight binary records, ASCII format for 39 | M9312 console load commands, and loadable absolute binary program images 40 | (.BIN) files. 41 | 42 | Multiple .psect/.asect ops are supported, as well as all local 43 | (non-global) relocation directory entries. 44 | 45 | Supports either RT-11 or RSX-11 format object files. 46 | 47 | OPTIONS 48 | The following options are available: 49 | 50 | --help 51 | Output this manpage and exit the program. 52 | 53 | --debug 54 | Enable debug mode; print input file records as parsed. 55 | 56 | --verbose 57 | Verbose status; output status messages during processing. 58 | 59 | --boot 60 | Generate a hex PROM file image suitable for programming into an M9312 61 | boot prom (512x4 geometry, only low half used). 62 | 63 | --console 64 | Generate a hex PROM file image suitable for programming into an M9312 65 | console/diagnostic prom (1024x4 geometry). 66 | 67 | --ascii 68 | Generate a a sequence of 'L addr' / 'D data' commands for downloading 69 | a program via a terminal emulator thru the M9312 user command 70 | interface. Suitable only for really small test programs. 71 | 72 | --binary 73 | Generate binary format load records of the program image (paper tape 74 | format) for loading into SIMH or compatible simulators. These files 75 | can also be copied onto XXDP filesystems to generate runnable program 76 | images (used to write custom diaqnostics). 77 | 78 | Binary format is the default if no other option is specified. If more 79 | than one option is specified the last one takes effect. 80 | 81 | --rt11 82 | Read input object files in RT-11 format. 83 | 84 | --rsx11 85 | Read input object files in RSX-11 format. 86 | 87 | RSX-11 object file format is the default if no other option is 88 | specified. If more than one option is specified the last one takes 89 | effect. 90 | 91 | --bytes=N 92 | For hex format output files, output N bytes per line (default 16). 93 | 94 | --nocrc 95 | For hex format output files, don't automatically stuff the computed 96 | CRC-16 as the last word in the ROM. 97 | 98 | --logfile=FILENAME 99 | Generate debug output into this file. 100 | 101 | --outfile=FILENAME 102 | Output binary file in format selected by user option. 103 | 104 | OBJFILE... 105 | Input object file(s) in .obj format. 106 | 107 | ERRORS 108 | The following diagnostic error messages can be produced on STDERR. The 109 | meaning should be fairly self explanatory. 110 | 111 | "Aborted due to command line errors" -- bad option or missing file(s) 112 | 113 | "Can't open input file '$file'" -- bad filename or unreadable file 114 | 115 | "Error: Improper object file format (1)" -- valid RT-11 record must start 116 | with 0x01 117 | 118 | "Error: Improper object file format (2)" -- second RT-11 byte must be 0x00 119 | 120 | "Error: Improper object file format (3)" -- third byte is low byte of 121 | record length 122 | 123 | "Error: Improper object file format (4)" -- fourth byte is high byte of 124 | record length 125 | 126 | "Error: Improper object file format (5)" -- bytes five thru end-1 are data 127 | bytes 128 | 129 | "Error: Improper object file format (6)" -- last RT-11 byte is checksum 130 | 131 | "Error: Bad checksum exp=0x%02X rcv=0x%02X" -- compare rcv'ed checksum vs 132 | exp'ed checksum 133 | 134 | EXAMPLES 135 | Some examples of common usage: 136 | 137 | obj2bin.pl --help 138 | 139 | obj2bin.pl --verbose --boot --out 23-751A9.hex 23-751A9.obj 140 | 141 | obj2bin.pl --verbose --binary --rt11 --out memtest.bin memtest.obj 142 | 143 | obj2bin.pl --verbose --binary --rsx11 --out prftst.bin prftst.obj mac/printf.obj 144 | 145 | AUTHOR 146 | Don North - donorth 147 | 148 | HISTORY 149 | Modification history: 150 | 151 | 2005-05-05 v1.0 donorth - Initial version. 152 | 2016-01-15 v1.1 donorth - Added RLD(IR) processing, moved sub's to end. 153 | 2016-01-18 v1.2 donorth - Added GSD processing, improved debug output. 154 | 2016-01-20 v1.3 donorth - Initial support for linking multiple PSECTs. 155 | 2016-01-22 v1.4 donorth - Added objfile/outfile/logfile switches vs stdio. 156 | 2016-01-28 v1.5 donorth - Added RLD processing, especially complex. 157 | 2017-04-01 v1.9 donorth - Renamed from obj2hex.pl to obj2bin.pl 158 | 2017-05-04 v1.95 donorth - Updated capability to read multiple input .obj files. 159 | 2020-03-06 v2.0 donorth - Updated help documentation and README.md file. 160 | 2020-03-10 v2.1 donorth - Broke down and added RSX-11 input format option. 161 | 162 | ``` 163 | -------------------------------------------------------------------------------- /parse.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef PARSE__H 3 | #define PARSE__H 4 | 5 | #include "symbols.h" 6 | #include "assemble_aux.h" /* ADDR_MODE */ 7 | 8 | 9 | // is char 'c' part of a symbol? 10 | #define issym(c) (isalpha(c) || isdigit(c) \ 11 | || (c) == '.' || (c) == '$' \ 12 | || (symbol_allow_underscores && (c) == '_')) 13 | 14 | 15 | char *skipwhite( 16 | char *cp); 17 | char *skipdelim( 18 | char *cp); 19 | char *skipdelim_comma( 20 | char *cp, 21 | int *comma); 22 | 23 | SYMBOL *get_op( 24 | char *cp, 25 | char **endp); 26 | int check_eol( 27 | STACK *stack, 28 | char *cp); 29 | char *getstring( 30 | char *cp, 31 | char **endp); 32 | char *getstring_fn( 33 | char *cp, 34 | char **endp); 35 | char *get_symbol( 36 | char *cp, 37 | char **endp, 38 | int *islocal); 39 | int get_mode( 40 | char *cp, 41 | char **endp, 42 | ADDR_MODE *mode, 43 | char **error); 44 | int get_fp_src_mode( 45 | char *cp, 46 | char **endp, 47 | ADDR_MODE *mode, 48 | char **error); 49 | 50 | EX_TREE *parse_expr( 51 | char *cp, 52 | int flags); 53 | EX_TREE *parse_unary_expr( 54 | char *cp, 55 | int flags); 56 | int expr_ok( 57 | EX_TREE *expr); 58 | int parse_float( 59 | char *cp, 60 | char **endp, 61 | int size, 62 | unsigned *flt); 63 | 64 | int brackrange( 65 | char *cp, 66 | int *start, 67 | int *length, 68 | char **endp); 69 | 70 | 71 | 72 | 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /rad50.c: -------------------------------------------------------------------------------- 1 | /* Functions to convert RAD50 to or from ASCII. */ 2 | 3 | /* 4 | Copyright (c) 2001, Richard Krehbiel 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are 9 | met: 10 | 11 | o Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | o Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | o Neither the name of the copyright holder nor the names of its 19 | contributors may be used to endorse or promote products derived from 20 | this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 29 | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 30 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 31 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 32 | USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 33 | DAMAGE. 34 | 35 | */ 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #include "rad50.h" 43 | 44 | static char radtbl[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ$. 0123456789"; 45 | 46 | /* rad50 converts from 0 to 3 ASCII (or EBCDIC, if your compiler is so 47 | inclined) characters into a RAD50 word. */ 48 | 49 | unsigned rad50( 50 | char *cp, 51 | char **endp) 52 | { 53 | unsigned long acc = 0; 54 | char *rp; 55 | 56 | if (endp) 57 | *endp = cp; 58 | 59 | if (!*cp) /* Got to check for end-of-string manually, because strchr will call it a hit. :-/ */ 60 | return acc; 61 | 62 | rp = strchr(radtbl, toupper((unsigned char)*cp)); 63 | if (rp == NULL) /* Not a RAD50 character */ 64 | return acc; 65 | acc = ((int) (rp - radtbl)) * 03100; /* Convert */ 66 | cp++; 67 | 68 | /* Now, do the same thing two more times... */ 69 | 70 | if (endp) 71 | *endp = cp; 72 | if (!*cp) 73 | return acc; 74 | rp = strchr(radtbl, toupper((unsigned char)*cp)); 75 | if (rp == NULL) 76 | return acc; 77 | acc += ((int) (rp - radtbl)) * 050; 78 | 79 | cp++; 80 | if (endp) 81 | *endp = cp; 82 | if (!*cp) 83 | return acc; 84 | rp = strchr(radtbl, toupper((unsigned char)*cp)); 85 | if (rp == NULL) 86 | return acc; 87 | acc += (int) (rp - radtbl); 88 | 89 | cp++; 90 | if (endp) 91 | *endp = cp; 92 | 93 | return acc; /* Done. */ 94 | } 95 | 96 | /* rad50x2 - converts from 0 to 6 characters into two words of RAD50. */ 97 | 98 | void rad50x2( 99 | char *cp, 100 | unsigned *rp) 101 | { 102 | *rp++ = rad50(cp, &cp); 103 | *rp = 0; 104 | if (*cp) 105 | *rp = rad50(cp, &cp); 106 | } 107 | 108 | /* unrad50 - converts a RAD50 word to three characters of ASCII. */ 109 | 110 | void unrad50( 111 | unsigned word, 112 | char *cp) 113 | { 114 | if (word < 0175000) { /* Is it legal RAD50? */ 115 | cp[0] = radtbl[word / 03100]; 116 | cp[1] = radtbl[(word / 050) % 050]; 117 | cp[2] = radtbl[word % 050]; 118 | } else 119 | cp[0] = cp[1] = cp[2] = ' '; 120 | } 121 | 122 | /* ascii2rad50 - convert a single character to a RAD50 character */ 123 | 124 | int ascii2rad50( 125 | char c) 126 | { 127 | char *rp; 128 | 129 | if (c == '\0') /* Not a RAD50 character */ 130 | return -1; 131 | rp = strchr(radtbl, toupper((unsigned char)c)); 132 | if (rp == NULL) /* Not a RAD50 character */ 133 | return -1; 134 | return (int) (rp - radtbl); /* Convert */ 135 | } 136 | 137 | /* packrad50word - packs up to 3 characters into a RAD50 word. 138 | * 139 | * The characters should be in the range [0, 050), 140 | * such as having been converted by ascii2rad50(). 141 | */ 142 | 143 | unsigned packrad50word( 144 | char *cp, 145 | int len) 146 | { 147 | unsigned long acc = 0; 148 | 149 | if (len >= 1) { 150 | acc += (cp[0] % 050) * 050 * 050; 151 | } 152 | if (len >= 2) { 153 | acc += (cp[1] % 050) * 050; 154 | } 155 | if (len >= 3) { 156 | acc += cp[2] % 050; 157 | } 158 | 159 | return acc; 160 | } 161 | -------------------------------------------------------------------------------- /rad50.h: -------------------------------------------------------------------------------- 1 | #ifndef RAD50_H 2 | #define RAD50_H 3 | 4 | /* 5 | Copyright (c) 2001, Richard Krehbiel 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are 10 | met: 11 | 12 | o Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | 15 | o Redistributions in binary form must reproduce the above copyright 16 | notice, this list of conditions and the following disclaimer in the 17 | documentation and/or other materials provided with the distribution. 18 | 19 | o Neither the name of the copyright holder nor the names of its 20 | contributors may be used to endorse or promote products derived from 21 | this software without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 28 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 29 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 30 | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 31 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 32 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 33 | USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 34 | DAMAGE. 35 | */ 36 | 37 | extern unsigned rad50( 38 | char *cp, 39 | char **endp); 40 | 41 | extern void rad50x2( 42 | char *cp, 43 | unsigned *rp); 44 | 45 | extern void unrad50( 46 | unsigned word, 47 | char *cp); 48 | 49 | int ascii2rad50( 50 | char c); 51 | 52 | unsigned packrad50word( 53 | char *cp, 54 | int len); 55 | 56 | #endif /* RAD50_H */ 57 | -------------------------------------------------------------------------------- /rept_irpc.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef REPT_IRPC__H 3 | #define REPT_IRPC__H 4 | 5 | #include "stream2.h" 6 | 7 | 8 | #ifndef REPT_IRPC__C 9 | extern STREAM_VTBL rept_stream_vtbl; 10 | extern STREAM_VTBL irp_stream_vtbl; 11 | extern STREAM_VTBL irpc_stream_vtbl; 12 | #endif 13 | 14 | STREAM *expand_rept( 15 | STACK *stack, 16 | char *cp); 17 | 18 | STREAM *expand_irp( 19 | STACK *stack, 20 | char *cp); 21 | 22 | STREAM *expand_irpc( 23 | STACK *stack, 24 | char *cp); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /stream2.h: -------------------------------------------------------------------------------- 1 | #ifndef STREAM2_H 2 | #define STREAM2_H 3 | 4 | /* 5 | 6 | Copyright (c) 2001, Richard Krehbiel 7 | All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions are 11 | met: 12 | 13 | o Redistributions of source code must retain the above copyright 14 | notice, this list of conditions and the following disclaimer. 15 | 16 | o Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | 20 | o Neither the name of the copyright holder nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 29 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 30 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 31 | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 32 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 33 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 34 | USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 35 | DAMAGE. 36 | 37 | */ 38 | #include 39 | 40 | struct stream; 41 | 42 | typedef struct stream_vtbl { 43 | void (*delete)( 44 | struct stream *stream); /* Destructor */ 45 | char *(*getline)( 46 | struct stream *stream); /* "getline" function */ 47 | void (*rewind)( 48 | struct stream *stream); /* "rewind" function */ 49 | } STREAM_VTBL; 50 | 51 | typedef struct stream { 52 | STREAM_VTBL *vtbl; /* Pointer to dispatch table */ 53 | char *name; /* Stream name */ 54 | int line; /* Current line number in stream */ 55 | struct stream *next; /* Next stream in stack */ 56 | } STREAM; 57 | 58 | typedef struct file_stream { 59 | STREAM stream; /* Base class */ 60 | FILE *fp; /* File pointer */ 61 | char *buffer; /* Line buffer */ 62 | } FILE_STREAM; 63 | 64 | typedef struct buffer { 65 | char *buffer; /* Pointer to text */ 66 | int size; /* Size of buffer */ 67 | int length; /* Occupied size of buffer */ 68 | int use; /* Number of users of buffer */ 69 | } BUFFER; 70 | 71 | #define GROWBUF_INCR 1024 /* Buffers grow by leaps and bounds */ 72 | 73 | typedef struct buffer_stream { 74 | STREAM stream; /* Base class */ 75 | BUFFER *buffer; /* text buffer */ 76 | int offset; /* Current read offset */ 77 | } BUFFER_STREAM; 78 | 79 | typedef struct stack { 80 | STREAM *top; /* Top of stacked stream pieces */ 81 | } STACK; 82 | 83 | #define STREAM_BUFFER_SIZE 1024 /* This limits the max size of an input line. */ 84 | BUFFER *new_buffer( 85 | void); 86 | BUFFER *buffer_clone( 87 | BUFFER *from); 88 | void buffer_resize( 89 | BUFFER *buff, 90 | int size); 91 | void buffer_free( 92 | BUFFER *buf); 93 | void buffer_appendn( 94 | BUFFER *buf, 95 | char *str, 96 | int len); 97 | void buffer_append_line( 98 | BUFFER *buf, 99 | char *str); 100 | 101 | STREAM *new_buffer_stream( 102 | BUFFER *buf, 103 | char *name); 104 | void buffer_stream_set_buffer( 105 | BUFFER_STREAM * bstr, 106 | BUFFER *buf); 107 | 108 | /* Provide these so that macro11 can derive from a BUFFER_STREAM */ 109 | extern STREAM_VTBL buffer_stream_vtbl; 110 | void buffer_stream_construct( 111 | BUFFER_STREAM * bstr, 112 | BUFFER *buf, 113 | char *name); 114 | char *buffer_stream_getline( 115 | STREAM *str); 116 | void buffer_stream_delete( 117 | STREAM *str); 118 | void buffer_stream_rewind( 119 | STREAM *str); 120 | 121 | STREAM *new_file_stream( 122 | char *filename); 123 | 124 | void stack_init( 125 | STACK *stack); 126 | void stack_push( 127 | STACK *stack, 128 | STREAM *str); 129 | void stack_pop( 130 | STACK *stack); 131 | char *stack_getline( 132 | STACK *stack); 133 | 134 | #endif /* STREAM2_H */ 135 | -------------------------------------------------------------------------------- /tests/2.11BSD/00SOURCE: -------------------------------------------------------------------------------- 1 | 2.11BSD is patch level 431, dated April 2000. 2 | 3 | ftp://minnie.tuhs.org/UnixArchive/PDP-11/Trees/2.11BSD/usr/src/new/ 4 | or 5 | http://minnie.tuhs.org/Archive/PDP-11/Trees/2.11BSD/usr/src/new/ 6 | or 7 | http://minnie.tuhs.org/cgi-bin/utree.pl?file=2.11BSD/src/new 8 | -------------------------------------------------------------------------------- /tests/2.11BSD/m11/Document: -------------------------------------------------------------------------------- 1 | .RP 2 | .TL 3 | New UCB 4 | .UX 5 | Edition of 6 | .I m11 7 | Assembler 8 | .AU 9 | Jim Reeds 10 | .AI 11 | Statistics Department 12 | Univerity of California 13 | Berkeley 14 | .AB 15 | A new edition of the old Harvard 16 | .UX 17 | implementation of the 18 | .I Macro-11 19 | assembler for PDP-11 computers is now available. 20 | This document gives, in terse form, a list of features in the new 21 | assembler. 22 | The reader is assumed to have some prior knowledge of Macro-11, 23 | for instance by having previously read the DEC Macro-11 manual. 24 | .AE 25 | .SH 26 | History 27 | .PP 28 | Harvard modified 29 | an old (circa 1974) DEC implementation of Macro-11 30 | to run on 31 | .UX 32 | in the mid 1970's. 33 | They called it 34 | .I macro, 35 | but at Berkeley this program has been known as 36 | .I m11. 37 | I modified it further, borrowing features supported in current DEC 38 | assemblers. 39 | In the course of this work I found many bugs in the original 40 | .I m11 41 | and many cases of disagreement between the DEC Macro-11 manuals and the 42 | .I m11 43 | program. 44 | I have tried to fix as many of these as I could. 45 | .SH 46 | Assembler Directives 47 | .PP 48 | The following is a list of all the directives supported by 49 | .I m11. 50 | Most work as described in the DEC manuals. 51 | One directive implemented in all DEC assemblers but not documented 52 | is the 53 | .I .rem 54 | directive. 55 | Its use is illustrated by the following example: 56 | .DS 57 | call sub1 58 | call sub2 59 | \\.rem & 60 | mov #message,-(sp) 61 | call errpr 62 | tst (sp)+ 63 | & 64 | call sub3 65 | .DE 66 | Here the text following the 67 | .I rem 68 | directive up through the second & sign is a comment. 69 | Any character may play the role of &. 70 | Another undocumented fact about all DEC Macro-11 assemblers 71 | is the fact that the 72 | .I .endm 73 | and 74 | .I .endr 75 | directives are complete synonyms and may be used interchangeably, as in 76 | .DS 77 | \\.macro call1 func, arg 78 | mov arg,-(sp) 79 | call func 80 | tst (sp)+ 81 | \\.endr 82 | .DE 83 | in violation of the rules given in the DEC manuals. 84 | The directives are: 85 | .DS 86 | ascii asciz asect blkb 87 | blkw byte csect dsabl 88 | enabl end endc endm 89 | endr eot error even 90 | flt2 flt4 globl ident 91 | if ifdf ifeq iff 92 | ifg ifge ifgt ifl 93 | ifle iflt ifndf ifne 94 | ifnz ift iftf ifz 95 | iif irp irpc limit 96 | list macr macro mcall 97 | mexit narg nchr nlist 98 | ntype odd page print 99 | psect radix rad50 rem 100 | rept sbttl title word 101 | .DE 102 | .SH 103 | Op Codes 104 | .PP 105 | The following is a list of op codes supported by 106 | .I m11. 107 | Consult the PDP Procssor Handbook for details. 108 | One new feature of recent DEC assemblers and of the new version 109 | of 110 | .I m11 111 | is the use of the short-hand opcodes 112 | .I call 113 | and 114 | .I return, 115 | which are simply the 116 | .I jsr 117 | and 118 | .I rts 119 | opcodes with use of the 120 | .I pc 121 | enforced. 122 | .DS 123 | absd absf adc adcb add addd addf ash 124 | ashc asl aslb asr asrb bcc bcs beq 125 | bge bgt bhi bhis bic bicb bis bisb 126 | bit bitb ble blo blos blt bmi bne 127 | bpl bpt br bvc bvs call ccc cfcc 128 | clc cln clr clrb clrd clrf clv clz 129 | cmp cmpb cmpd cmpf cnz com comb dec 130 | decb div divd divf emt fadd fdiv fmul 131 | fsub halt inc incb iot jmp jsr ldcdf 132 | ldcfd ldcid ldcif ldcld ldclf ldd ldexp ldf 133 | ldfps ldsc ldub mark mfpd mfpi modd modf 134 | mov movb mtpd mtpi mul muld mulf neg 135 | negb negd negf nop reset return rol rolb 136 | ror rorb rti rts rtt sbc sbcb scc 137 | sec sen setd setf seti setl sev sez 138 | sob spl sta0 stb0 stcdf stcdi stcdl stcfd 139 | stcfi stcfl std stexp stf stfps stq0 stst 140 | sub subd subf swab sxt trap tst tstb 141 | tstd tstf wait xor 142 | .DE 143 | .SH 144 | .UX 145 | Command Line Arguments 146 | .PP 147 | .DS 148 | .DE 149 | .PP 150 | The list of valid arguments to the 151 | .I -cr 152 | flag is 153 | .DS 154 | s sy sym 155 | r re reg 156 | m ma mac 157 | p pe per pst 158 | c cs cse sec pse 159 | e er err 160 | .DE 161 | .SH 162 | Psect Attributes 163 | .PP 164 | Psect attributes are coded by bits in a byte. 165 | The various attribute arguments turn selected bits on and selected 166 | bits off. 167 | This attribute byte is interpreted by the loader. 168 | The following three kinds of program sections each have their own 169 | default attributes. 170 | These defaults can be changed by the system manager. 171 | The user can override them by using the 172 | .I -dp, 173 | .I -dc, 174 | and 175 | .I -da 176 | command line flags. 177 | .IP 178 | Blank 179 | .I csects 180 | and all 181 | .I .psects 182 | have the default attribute 183 | .I relocatable. 184 | .IP 185 | Named 186 | .I .csects 187 | have the default attributes 188 | .I overlaid, 189 | .I global, 190 | and 191 | .I relocatable. 192 | .IP 193 | The absolute 194 | .I .asect 195 | has the attributes 196 | .I overlaid 197 | and 198 | .I global. 199 | .PP 200 | The meaning of the bits is (in octal): 201 | .DS 202 | shareable 1 203 | instructions 2 204 | bss 4 205 | defined 10 206 | overlaid 20 207 | relocatable 40 208 | global 100 209 | .DE 210 | .PP 211 | Each of the attribute key words turns some of these bits on 212 | and some off. 213 | The list is: 214 | .DS 215 | Keyword Synonym Turns On Turns Off 216 | 217 | rel 40 218 | abs 40 219 | gbl 100 220 | lcl 100 221 | ovr 20 222 | con 20 223 | shr ro 1 4 224 | prv rw 5 225 | bss b 4 3 226 | ins i 2 4 227 | dat d 6 228 | hgh low 229 | .DE 230 | .PP 231 | The 232 | .I hgh 233 | and 234 | .I low 235 | attribute keywords are for compatability with DEC 236 | assemblers. 237 | They have no UNIX function. 238 | .SH 239 | Listing control arguments 240 | .DS 241 | seq loc bin src com 242 | bex md mc me meb 243 | cnd ld ttm toc sym 244 | .DE 245 | .SH 246 | Arguments to the 247 | .I .enabl 248 | and 249 | .I .dsabl 250 | directives 251 | .PP 252 | These args are: 253 | .DS 254 | pnc crf gbl fpt lc lsb 255 | cdr reg ama pic abs 256 | .DE 257 | .SH 258 | Arguments to Condtional Statements 259 | .PP 260 | The conditional directives 261 | .I .if, 262 | etc, take the following arguments: 263 | .DS 264 | eq ne z nz 265 | gt le g lt 266 | ge l df ndf 267 | b nb idn dif 268 | .DE 269 | .I 270 | .SH 271 | Differences Between Old Harvard Assembler and New Assembler 272 | .PP 273 | The new assembler does not convert macro definition text to upper case. 274 | This feature can be disabled by using the 275 | .I -um 276 | switch. 277 | .SH 278 | Differences Between DEC Macro-11 Assemblers and the New Assembler 279 | .PP 280 | The new assembler does not have keyword arguments to macros, as described in 281 | section 7.3.6 in the DEC Macro 11 manual. 282 | .PP 283 | The new assembler starts out with lower case enabled and it does not convert 284 | macro definition text to upper case. Both of these features can be turned 285 | off by specifying the 286 | .I -uc 287 | switch. 288 | -------------------------------------------------------------------------------- /tests/2.11BSD/m11/Makefile: -------------------------------------------------------------------------------- 1 | # m11 Makefile. Revised 1996/1/28 2 | # 3 | # Note that the pathname for macxrf is wired into exec.m11 ... 4 | 5 | DESTDIR= 6 | 7 | M11= ./m11.x 8 | L11= ./l11.x 9 | 10 | SEPFLAG=-i 11 | MFLAGS= 12 | 13 | .SUFFIXES: .m11 .obj 14 | 15 | .m11.obj: 16 | ${M11} ${MFLAGS} $< 17 | 18 | .SUFFIXES: .1 .0 19 | 20 | .1.0: 21 | /usr/man/manroff $*.1 > $*.0 22 | 23 | SRCS= exec.m11 macro.m11 code.m11 expr.m11 fltg.m11 getl.m11 \ 24 | lout.m11 mac.m11 srch.m11 xlat.m11 misc.m11 pst.m11 \ 25 | errs.m11 debug.m11 often.m11 xpcor.m11 syscalls.m11 at.sml 26 | OBJS= exec.obj macro.obj code.obj expr.obj fltg.obj getl.obj \ 27 | lout.obj mac.obj srch.obj xlat.obj misc.obj pst.obj \ 28 | errs.obj debug.obj often.obj xpcor.obj syscalls.obj 29 | 30 | all: m11 macxrf m11.0 31 | 32 | m11: ${OBJS} 33 | ${L11} -ls ${SEPFLAG} ${OBJS} 34 | mv exec.out m11 35 | 36 | macxrf: macxrf.c 37 | cc ${SEPFLAG} -O -w -o macxrf macxrf.c 38 | 39 | install: all m11.0 40 | install -s m11 ${DESTDIR}/usr/new/m11 41 | install -s macxrf ${DESTDIR}/usr/new/macxrf 42 | install -c -m 444 -o bin -g bin m11.0 ${DESTDIR}/usr/new/man/cat1/m11.0 43 | 44 | cmp: all 45 | cmp m11 ${DESTDIR}/usr/new/m11 46 | cmp macxrf ${DESTDIR}/usr/new/macxrf 47 | 48 | clean: 49 | rm -f *.obj *.lst *.map m11 macxrf *.0 50 | -------------------------------------------------------------------------------- /tests/2.11BSD/m11/READme: -------------------------------------------------------------------------------- 1 | This is the Jim Reeds version of the Harvard m11. 2 | 3 | Here is code for 2 programs: 4 | 5 | m11 the assembler itself many .m11 source files 6 | and the include file 'at.sml' 7 | macxrf crossreference generator macxrf.c 8 | 9 | There are two documentation files: 10 | 11 | m11.1 nroff -man'able version of a manual page 12 | Document nroff -ms'able version of a DRAFT of a windy document 13 | 14 | To install: 15 | 16 | You must put macxrf into /usr/ucb/macxrf. This path name is 17 | buried in the m11 source file exec.m11 if you want to change it. The assembler 18 | itself can live anywhere. /usr/new/m11 and /usr/ucb/m11 are two 19 | likely places to put it. 20 | 21 | You might need a copy of the Jim Reeds souped up l11 to link this 22 | program. Source is in ../l11. The changes involved with l11 are minor. 23 | 24 | Hints about using m11: This version works differently from older 25 | versions. Many of the defaults are changed. The most suprising is that 26 | undefined sysmbols are automatically treated as external. This is the 27 | default .enabl gbl attribute. Users can either do .dsabl gbl or use one of the 28 | retrofit flags. Here are the two retrofit flags: 29 | 30 | m11 -de args 31 | m11 -ha args 32 | 33 | -de stands for DEC, -ha stands for Harvard. Code written for DEC macro-11 34 | should probably be assembled with the -de flag for DEC-like treatment of 35 | case conversion, etc. This includes the Johns Hopkins basic+ interpreter. 36 | Code written for earlier versions of the Harvard Unixification of macro-11 37 | should be assembled with the -ha flag. This includes Harvard's absurd .psect 38 | default attributes. Use it when recreating Harvard lisp. 39 | -------------------------------------------------------------------------------- /tests/2.11BSD/m11/debug.m11: -------------------------------------------------------------------------------- 1 | .mcall (at) always 2 | .globl $write 3 | 4 | .globl ndebug,sdebug, ..z,..zbuf 5 | .globl savreg,dnc 6 | .globl xx.flg 7 | always 8 | 9 | xitsec 10 | sdebug: 11 | call savreg 12 | mov r0,-(sp) 13 | 14 | mov #..s,r2 15 | mov ..z,r3 16 | mov #2,r0 17 | 1$: movb (r3)+,(r2)+ 18 | beq 2$ 19 | inc r0 20 | br 1$ 21 | 2$: 22 | movb #12,(r2) 23 | mov r0,..n 24 | ddd: 25 | tst xx.flg 26 | beq 100$ 27 | mov ..n,-(sp) ;write(2, ..s, ..n) 28 | mov #..s,-(sp) 29 | mov #2,-(sp) 30 | tst -(sp) ;simulate return address stack spacing 31 | $write 32 | add #8.,sp ;toss syscall cruft 33 | 100$: 34 | mov (sp)+,r0 35 | return 36 | ndebug: 37 | call savreg 38 | mov r0,-(sp) 39 | mov #..s,r2 40 | mov ..z,r1 41 | call dnc 42 | movb #12,(r2)+ 43 | mov r2,..n 44 | sub #..s,..n 45 | br ddd 46 | 47 | entsec mixed 48 | ..n: .blkw 49 | ..z: .word 50 | ..s: .blkw 100 51 | ..zbuf: .blkw 100 52 | 53 | .end 54 | -------------------------------------------------------------------------------- /tests/2.11BSD/m11/errs.m11: -------------------------------------------------------------------------------- 1 | ; 2 | ; m11 error messages 3 | ; jim reeds 4 july 1981 4 | ; 5 | .mcall (at)always 6 | always 7 | 8 | .data 9 | .dsabl lc 10 | .list md,me,mc 11 | 12 | .macro errgen num,code,text 13 | ern'num:: .asciz \text\ 14 | .endm 15 | errgen 1,r, 16 | errgen 2,a, 17 | errgen 3,a, 18 | errgen 4,u, 19 | errgen 5,m, 20 | errgen 6,n, 21 | errgen 7,t, 22 | errgen 8,u, 23 | errgen 9,a, 24 | errgen 10,n, 25 | errgen 11,t, 26 | errgen 12,l, 27 | errgen 13,i, 28 | errgen 14,e,<.end not found> 29 | errgen 140,e, 30 | errgen 15,o, 31 | errgen 16,o, 32 | errgen 17,a, 33 | errgen 18,t, 34 | errgen 19,q, 35 | errgen 20,a, 36 | errgen 0,<>, 37 | errgen 22,a, 38 | errgen 23,a, 39 | errgen 24,o, 40 | errgen 25,o, 41 | errgen 26,a,<.endm name doesn't match .macro name> 42 | errgen 27,a, 43 | errgen 28,a, 44 | errgen 29,o, 45 | errgen 30,a, 46 | errgen 31,a, 47 | errgen 70,a, 48 | errgen 71,a, 49 | errgen 32,p, 50 | errgen 33,q, 51 | errgen 34,m,