diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 35152e8..0000000 --- a/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2014, RetroBSD -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the {organization} nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/Makefile b/Makefile index 6c92d17..3b6b042 100644 --- a/Makefile +++ b/Makefile @@ -11,36 +11,28 @@ # # Supported boards # -MAX32 = sys/pic32/max32/MAX32 -FUBARINO = sys/pic32/fubarino/FUBARINO -FUBARINOBIG = sys/pic32/fubarino/FUBARINO-UART2CONS-UART1-SRAMC -SDXL = sys/pic32/sdxl/SDXL -MAXIMITE = sys/pic32/maximite/MAXIMITE -MAXCOLOR = sys/pic32/maximite-color/MAXCOLOR -DUINOMITE = sys/pic32/duinomite/DUINOMITE -DUINOMITEUART = sys/pic32/duinomite-uart/DUINOMITE-UART -DUINOMITEE = sys/pic32/duinomite-e/DUINOMITE-E -DUINOMITEEUART = sys/pic32/duinomite-e-uart/DUINOMITE-E-UART -MMBMX7 = sys/pic32/mmb-mx7/MMB-MX7 -WF32 = sys/pic32/wf32/WF32 -UBW32 = sys/pic32/ubw32/UBW32 -UBW32UART = sys/pic32/ubw32-uart/UBW32-UART -UBW32UARTSDRAM = sys/pic32/ubw32-uart-sdram/UBW32-UART-SDRAM -EXPLORER16 = sys/pic32/explorer16/EXPLORER16 -STARTERKIT = sys/pic32/starter-kit/STARTER-KIT -BAREMETAL = sys/pic32/baremetal/BAREMETAL -RETROONE = sys/pic32/retroone/RETROONE +MAX32 = pic32/max32 +UBW32 = pic32/ubw32 +UBW32UART = pic32/ubw32-uart +UBW32UARTSDRSW = pic32/ubw32-uart-sdramswap +MAXIMITE = pic32/maximite +EXPLORER16 = pic32/explorer16 +STARTERKIT = pic32/starter-kit +DUINOMITE = pic32/duinomite +PINGUINO = pic32/pinguino-micro +DIP = pic32/dip +BAREMETAL = pic32/baremetal +RETROONE = pic32/retroone # Select target board -TARGET ?= $(MAX32) +TARGET ?= $(UBW32UARTSDRSW) # Filesystem and swap sizes. -FS_MBYTES = 100 -U_MBYTES = 100 -SWAP_MBYTES = 2 +FS_KBYTES = 16384 +SWAP_KBYTES = 2048 # Set this to the device name for your SD card. With this -# enabled you can use "make installfs" to copy the sdcard.img +# enabled you can use "make installfs" to copy the filesys.img # to the SD card. #SDCARD = /dev/sdb @@ -53,71 +45,136 @@ DEFS = FSUTIL = tools/fsutil/fsutil --include Makefile.user +# +# Filesystem contents. +# +BIN_FILES := $(wildcard bin/*) +SBIN_FILES := $(wildcard sbin/*) +GAMES_FILES := $(shell find games -type f ! -path '*/.*') +LIB_FILES := $(wildcard lib/*) +LIBEXEC_FILES := $(wildcard libexec/*) +ETC_FILES = etc/rc etc/rc.local etc/ttys etc/gettytab etc/group \ + etc/passwd etc/shadow etc/fstab etc/motd etc/shells \ + etc/termcap +INC_FILES = include/stdio.h include/syscall.h include/sys/types.h \ + include/sys/select.h +SHARE_FILES = share/re.help share/example/Makefile \ + share/example/ashello.S share/example/chello.c \ + share/example/blkjack.bas share/example/hilow.bas \ + share/example/stars.bas share/example/prime.scm \ + share/example/fact.fth share/example/echo.S +ALLFILES = $(SBIN_FILES) $(ETC_FILES) $(BIN_FILES) $(LIB_FILES) $(LIBEXEC_FILES) \ + $(INC_FILES) $(SHARE_FILES) $(GAMES_FILES) \ + var/log/messages var/log/wtmp .profile +ALLDIRS = sbin/ bin/ dev/ etc/ tmp/ lib/ libexec/ share/ share/example/ \ + share/misc/ var/ var/run/ var/log/ u/ include/ include/sys/ \ + games/ games/lib/ +BDEVS = dev/sd0!b0:0 dev/sd1!b0:1 dev/sw0!b1:0 +CDEVS = dev/console!c0:0 \ + dev/mem!c1:0 dev/kmem!c1:1 dev/null!c1:2 dev/zero!c1:3 \ + dev/tty!c2:0 \ + dev/rsd0!c3:0 dev/rsd1!c3:1 dev/swap!c3:0 \ + dev/klog!c4:0 \ + dev/stdin!c5:0 dev/stdout!c5:1 dev/stderr!c5:2 \ + dev/rsw0!c6:0 \ + dev/porta!c7:0 dev/portb!c7:1 dev/portc!c7:2 \ + dev/portd!c7:3 dev/porte!c7:4 dev/portf!c7:5 dev/portg!c7:6 \ + dev/confa!c7:64 dev/confb!c7:65 dev/confc!c7:66 \ + dev/confd!c7:67 dev/confe!c7:68 dev/conff!c7:69 dev/confg!c7:70 \ + dev/spi1!c9:0 dev/spi2!c9:1 dev/spi3!c9:2 dev/spi4!c9:3 \ + dev/glcd0!c10:0 +FDDEVS = dev/fd/ dev/fd/0!c5:0 dev/fd/1!c5:1 dev/fd/2!c5:2 \ + dev/fd/3!c5:3 dev/fd/4!c5:4 dev/fd/5!c5:5 dev/fd/6!c5:6 \ + dev/fd/7!c5:7 dev/fd/8!c5:8 dev/fd/9!c5:9 dev/fd/10!c5:10 \ + dev/fd/11!c5:11 dev/fd/12!c5:12 dev/fd/13!c5:13 \ + dev/fd/14!c5:14 dev/fd/15!c5:15 dev/fd/16!c5:16 \ + dev/fd/17!c5:17 dev/fd/18!c5:18 dev/fd/19!c5:19 \ + dev/fd/20!c5:20 dev/fd/21!c5:21 dev/fd/22!c5:22 \ + dev/fd/23!c5:23 dev/fd/24!c5:24 dev/fd/25!c5:25 \ + dev/fd/26!c5:26 dev/fd/27!c5:27 dev/fd/28!c5:28 \ + dev/fd/29!c5:29 +ADCDEVS = dev/adc0!c8:0 dev/adc1!c8:1 dev/adc2!c8:2 dev/adc3!c8:3 \ + dev/adc4!c8:4 dev/adc5!c8:5 dev/adc6!c8:6 dev/adc7!c8:7 \ + dev/adc8!c8:8 dev/adc9!c8:9 dev/adc10!c8:10 dev/adc11!c8:11 \ + dev/adc12!c8:12 dev/adc13!c8:13 dev/adc14!c8:14 dev/adc15!c8:15 +OCDEVS = dev/oc0!c11:0 dev/oc1!c11:1 dev/oc2!c11:2 dev/oc3!c11:3 dev/oc4!c11:4 -TARGETDIR = $(shell dirname $(TARGET)) -TARGETNAME = $(shell basename $(TARGET)) -TOPSRC = $(shell pwd) -CONFIG = $(TOPSRC)/tools/configsys/config - -all: .profile - $(MAKE) -C tools - $(MAKE) -C lib - $(MAKE) -C src install - $(MAKE) kernel +all: build kernel $(MAKE) fs -kernel: $(TARGETDIR)/Makefile - $(MAKE) -C $(TARGETDIR) +fs: filesys.img user.img -$(TARGETDIR)/Makefile: $(CONFIG) $(TARGETDIR)/$(TARGETNAME) - cd $(TARGETDIR) && ../../../tools/configsys/config $(TARGETNAME) +kernel: + $(MAKE) -C sys/$(TARGET) -fs: sdcard.img +build: + $(MAKE) -C tools + $(MAKE) -C src install -.PHONY: sdcard.img -sdcard.img: $(FSUTIL) rootfs.manifest userfs.manifest +filesys.img: $(FSUTIL) $(ALLFILES) rm -f $@ - $(FSUTIL) --repartition=fs=$(FS_MBYTES)M:swap=$(SWAP_MBYTES)M:fs=$(U_MBYTES)M $@ - $(FSUTIL) --new --partition=1 --manifest=rootfs.manifest $@ . - $(FSUTIL) --new --partition=3 --manifest=userfs.manifest $@ u + $(FSUTIL) -n$(FS_KBYTES) -s$(SWAP_KBYTES) $@ + $(FSUTIL) -a $@ $(ALLDIRS) $(ALLFILES) + $(FSUTIL) -a $@ $(CDEVS) + $(FSUTIL) -a $@ $(BDEVS) + $(FSUTIL) -a $@ $(ADCDEVS) + $(FSUTIL) -a $@ $(OCDEVS) +# $(FSUTIL) -a $@ $(FDDEVS) + +user.img: $(FSUTIL) + rm -f $@ + $(FSUTIL) -n$(FS_KBYTES) $@ $(FSUTIL): cd tools/fsutil; $(MAKE) -$(CONFIG): - make -C tools/configsys - clean: rm -f *~ - for dir in tools lib src sys/pic32; do $(MAKE) -C $$dir -k clean; done + for dir in tools src sys/pic32; do $(MAKE) -C $$dir -k clean; done cleanall: clean - $(MAKE) -C lib clean - rm -f sys/pic32/*/unix.hex bin/* sbin/* libexec/* - rm -f games/[a-k]* games/[m-z]* share/man/cat*/* - rm -f games/lib/adventure.dat games/lib/cfscores - rm -f share/re.help share/emg.keys share/misc/more.help - rm -f etc/termcap etc/remote etc/phones - rm -f tools/configsys/.depend - rm -f var/log/aculog - rm -rf var/lock share/unixbench + rm -f sys/pic32/*/unix.hex bin/* sbin/* lib/* games/[a-k]* games/[m-z]* libexec/* share/man/cat*/* + rm -f games/lib/adventure.dat + rm -f games/lib/cfscores + rm -f share/re.help + rm -f share/misc/more.help + rm -f etc/termcap -installfs: + +# TODO +buildlib: + @echo installing /usr/include + # cd include; $(MAKE) DESTDIR=$(DESTDIR) install + @echo + @echo compiling libc.a + cd lib/libc; $(MAKE) $(LIBCDEFS) + @echo installing /lib/libc.a + cd lib/libc; $(MAKE) DESTDIR=$(DESTDIR) install + @echo + @echo compiling C compiler + cd lib; $(MAKE) ccom cpp c2 + @echo installing C compiler + cd lib/ccom; $(MAKE) DESTDIR=$(DESTDIR) install + cd lib/cpp; $(MAKE) DESTDIR=$(DESTDIR) install + cd lib/c2; $(MAKE) DESTDIR=$(DESTDIR) install + cd lib; $(MAKE) clean + @echo + @echo re-compiling libc.a + cd lib/libc; $(MAKE) $(LIBCDEFS) + @echo re-installing /lib/libc.a + cd lib/libc; $(MAKE) DESTDIR=$(DESTDIR) install + @echo + @echo re-compiling C compiler + cd lib; $(MAKE) ccom cpp c2 + @echo re-installing C compiler + cd lib/ccom; $(MAKE) DESTDIR=$(DESTDIR) install + cd lib/cpp; $(MAKE) DESTDIR=$(DESTDIR) install + cd lib/c2; $(MAKE) DESTDIR=$(DESTDIR) install + @echo + +installfs: filesys.img ifdef SDCARD - @[ -f sdcard.img ] || $(MAKE) sdcard.img - sudo dd bs=32k if=sdcard.img of=$(SDCARD) + sudo dd bs=16k if=filesys.img of=$(SDCARD) else - @echo "Error: No SDCARD defined." + @echo "Error: No SDCARD defined." endif - -# TODO: make it relative to Target -installflash: - sudo pic32prog sys/pic32/fubarino/unix.hex - -# TODO: make it relative to Target -installboot: - sudo pic32prog sys/pic32/fubarino/bootloader.hex - -.profile: etc/root/dot.profile - cp etc/root/dot.profile .profile diff --git a/README b/README new file mode 100644 index 0000000..0d60590 --- /dev/null +++ b/README @@ -0,0 +1,129 @@ +This is the RetroBSD source directory. + + +Source Roadmap +~~~~~~~~~~~~~~ + bin User commands. + etc Template files for /etc. + include System include files. + lib System libraries. + libexec System binaries. + sbin System administration commands. + share Shared resources. + sys Kernel sources. + tools Build tools and simulators. + + +Supported hardware +~~~~~~~~~~~~~~~~~~ + * chipKIT Max32 board. + * Sparkfun UBW32 board. + * Maximite computer. + * Microchip Explorer 16 board, with PIC32 CAN-USB plug-in module and SD & MMC pictail. + * Microchip PIC32 USB or Ethernet Starter Kit, with I/O Expansion board and SD & MMC pictail. + * Olimex Duinomite, Duinomite-Mini and Duinomite-Mega boards. + * Olimex Pinguino-Micro board with PIC32MX795F512H microcontroller. + * eflightworks DIP board. + + +Build +~~~~~ +By default, the system is configured for the Max32 board. +To select another target board, edit a top-level Makefile +and change a TARGET value under section "Select target board": + + TARGET = $(UBW32) # for the UBW32 board with USB console + TARGET = $(UBW32UART) # for the UBW32 board with UART console + TARGET = $(MAXIMITE) # for the Maximite board + TARGET = $(EXPLORER16) # for the Explorer 16 board + TARGET = $(STARTERKIT) # for the PIC32 USB or Ethernet Starter Kit + TARGET = $(MAX32) # default + TARGET = $(DUINOMITE) # for the Duinomite board + TARGET = $(PINGUINO) # for the Pinguino-Micro board + TARGET = $(DIP) # for the DIP board + +You can also change a desired filesystem size and swap area size, +as required. Default is: + + FS_KBYTES = 16384 + SWAP_KBYTES = 2048 + +To compile the kernel and build a filesystem image, run: + + make + +A resulting root filesystem image is in file `filesys.img`. +A kernel is in file `unix.hex` in your target board subdirectory. + + +Filesystem image +~~~~~~~~~~~~~~~~ +You need to put a filesystem image on a SD card. On Windows, use +Win32DiskImager utility (https://launchpad.net/win32-image-writer/+download). +On Linux, run: + + sudo dd if=filesys.img of=/dev/XYZ + +Here `XYZ` is a device name of SD card, as recognized by Linux (sdb in my case). + + +Install kernel +~~~~~~~~~~~~~~ +Kernel image should be written to PIC32 flash memory. The procedure depends +on a board used. + +Max32 board: + cd sys/pic32/ubw32 + AVRTOOLS=/Applications/Mpide.app/Contents/Resources/Java/hardware/tools + $AVRTOOLS/bin/avrdude -C$AVRTOOLS/etc/avrdude.conf -c stk500v2 -p pic32 \ + -P /dev/tty.usbserial-* -b 115200 -v -U flash:w:unix.hex:i + + Here you need to change AVRTOOLS path and tty name according to your system. + +UBW32 board: + Use a pic32prog utility (http://code.google.com/p/pic32prog/) + and a USB cable to install a kernel: + + pic32prog sys/pic32/ubw32/unix.hex + +Maximite: + Use the bootload program for Windows, available for download by link: + http://geoffg.net/Downloads/Maximite/Maximite_Update_V2.7B.zip + +Explorer 16 board: + There is an auxiliary PIC18 chip on the Explorer 16 board, which can be + used as a built-in programmer device. You will need a PICkit 2 adapter + to install a needed firmware, as described in article: + http://www.paintyourdragon.com/?p=51 + (section "Hack #2: Lose the PICkit 2, Save $35"). + This should be done only once. + + Then, you can use a pic32prog utility (http://code.google.com/p/pic32prog/) + and a USB cable to install a kernel: + + pic32prog sys/pic32/explorer16/unix.hex + +PIC32 Starter Kit: + Use PICkit 2 adapter and software to install a boot loader from + file `sys/pic32/starter-kit/boot.hex`. This should be done only once. + + Then, you can use a pic32prog utility (http://code.google.com/p/pic32prog/) + and a USB cable to install a kernel: + + pic32prog sys/pic32/starter-kit/unix.hex + + +Simulator +~~~~~~~~~ +You can use a MIPS32 simulator to develop a debug a RetroBSD software, +without a need for hardware board. By default, a simulator is configured +to imitate a Max32 board. To build it: + + cd tools/virtualmips + make + +Run it: + + ./pic32 + +Configuration of simulated board is stored in file `pic32_max32.conf`. diff --git a/README.md b/README.md deleted file mode 100644 index adf3356..0000000 --- a/README.md +++ /dev/null @@ -1,161 +0,0 @@ -# This is the RetroBSD source directory. - -## Source Roadmap - - bin User commands. - etc Template files for /etc. - include System include files. - lib System libraries. - libexec System binaries. - sbin System administration commands. - share Shared resources. - sys Kernel sources. - tools Build tools and simulators. - - -## Supported hardware - - * chipKIT Max32 board. - * Sparkfun UBW32 board. - * Maximite and Colour Maximite computers. - * Microchip Explorer 16 board, with PIC32 CAN-USB plug-in module and SD & MMC pictail. - * Microchip PIC32 USB or Ethernet Starter Kit, with I/O Expansion board and SD & MMC pictail. - * Olimex Duinomite, Duinomite-Mini and Duinomite-Mega boards. - * Olimex Pinguino-Micro board with PIC32MX795F512H microcontroller. - * eflightworks DIP board. - - -## Build - -To compile everything from sources, you'll need some packages installed, namely: -Berkeley YACC, GNU bison and flex, ELF library and FUSE library. -Under Ubuntu, for example, you can do it by command: - -```shell -$ sudo apt-get install bison byacc flex libelf-dev libfuse-dev -``` - -By default, the system is configured for the Max32 board. -To select another target board, edit a top-level user-specific Makefile called "Makefile.user" -and set a TARGET value: - -```Makefile -TARGET = $(MAX32) # for the chipKIT Max32 board with SD card shield (default) -TARGET = $(FUBARINO) # Fubarino SD board -TARGET = $(FUBARINOBIG) # Fubarino SD board with 8MB SRAM RAMDISK -TARGET = $(MAXIMITE) # for the Maximite board -TARGET = $(MAXCOLOR) # for the Colour Maximite board -TARGET = $(DUINOMITE) # for the Duinomite board with USB console -TARGET = $(DUINOMITEUART) # for the Duinomite board with UART console -TARGET = $(DUINOMITEE) # for the Duinomite E board with USB console -TARGET = $(DUINOMITEEUART) # for the Duinomite E board with UART console -TARGET = $(MMBMX7) # MMB MX7 board -TARGET = $(UBW32) # for the UBW32 board with USB console -TARGET = $(UBW32UART) # for the UBW32 board with UART console -TARGET = $(UBW32UARTSDRAM) # for the UBW32 boars with UART console and 8MB SRAM ramdisk -TARGET = $(EXPLORER16) # for the Explorer 16 board -TARGET = $(STARTERKIT) # for the PIC32 USB or Ethernet Starter Kit -TARGET = $(BAREMETAL) # Bare PIC32 chip on a breakout board -``` - -You can also change a desired filesystem size and swap area size, -as required. Default is: -```Makefile -FS_KBYTES = 16384 -SWAP_KBYTES = 2048 -``` -To compile the kernel and build a filesystem image, run: - -```shell -$ make -``` - -A resulting root filesystem image is in file `sdcard.img`. -A kernel is in file `unix.hex` in your target board subdirectory. - - -### Filesystem image - -You need to put a filesystem image on a SD card. On Windows, use -Win32DiskImager utility (https://launchpad.net/win32-image-writer/+download). -On Linux, run: - -```shell -$ sudo dd if=sdcard.img of=/dev/XYZ -``` - -Here `XYZ` is a device name of SD card, as recognized by Linux (sdb in my case). - - -### Install kernel - -Kernel image should be written to PIC32 flash memory. The procedure depends -on a board used. - -#### Max32 board: -Use a pic32prog utility (http://code.google.com/p/pic32prog/) -and a USB cable to install a kernel: - -```shell -$ pic32prog -d /dev/ttyUSB0 sys/pic32/max32/unix.hex -``` - -Here you need to change AVRTOOLS path and tty name according to your system. - -#### UBW32 board: -Use a pic32prog utility (http://code.google.com/p/pic32prog/) -and a USB cable to install a kernel: - -```shell -$ pic32prog sys/pic32/ubw32/unix.hex -``` - -#### Maximite: -Use the bootload program for Windows, available for download by link: -http://geoffg.net/Downloads/Maximite/Maximite_Update_V2.7B.zip - -#### Explorer 16 board: -There is an auxiliary PIC18 chip on the Explorer 16 board, which can be -used as a built-in programmer device. You will need a PICkit 2 adapter -to install a needed firmware, as described in article: -http://www.paintyourdragon.com/?p=51 -(section "Hack #2: Lose the PICkit 2, Save $35"). -This should be done only once. - -Then, you can use a pic32prog utility (http://code.google.com/p/pic32prog/) -and a USB cable to install a kernel: - -``` shell -$ pic32prog sys/pic32/explorer16/unix.hex -``` - -#### PIC32 Starter Kit: -Use PICkit 2 adapter and software to install a boot loader from -file `sys/pic32/starter-kit/boot.hex`. This should be done only once. - -Then, you can use a pic32prog utility (http://code.google.com/p/pic32prog/) -and a USB cable to install a kernel: - -```shell -$ pic32prog sys/pic32/starter-kit/unix.hex -``` - - -## Simulator - -You can use a MIPS32 simulator to develop a debug a RetroBSD software, -without a need for hardware board. By default, a simulator is configured -to imitate a Max32 board. To build it: - -```shell -$ cd tools/virtualmips -$ make -``` - -Run it: - -```shell -$ ./pic32 -``` - -Configuration of simulated board is stored in file `pic32_max32.conf`. diff --git a/bin/.gitignore b/bin/.gitignore deleted file mode 100644 index 72e8ffc..0000000 --- a/bin/.gitignore +++ /dev/null @@ -1 +0,0 @@ -* diff --git a/cross.mk b/cross.mk index 89b37ac..f0eb9a2 100644 --- a/cross.mk +++ b/cross.mk @@ -1,7 +1,7 @@ DESTDIR = /usr/local/retrobsd MACHINE = mips -CC = gcc -m32 +CC = gcc AS = $(CC) -x assembler-with-cpp LD = ld @@ -18,14 +18,6 @@ TAGSFILE = tags MANROFF = nroff -man -h ELF2AOUT = cp -CFLAGS = -O -DCROSS +CFLAGS = -O -DCROSS -I/usr/include -I$(TOPSRC)/include LDFLAGS = LIBS = - -# Add system include path -ifeq (,$(wildcard /usr/include/i386-linux-gnu)) - CFLAGS += -I/usr/include -else - CFLAGS += -I/usr/include/i386-linux-gnu -endif -CFLAGS += -I$(TOPSRC)/include diff --git a/etc/.gitignore b/etc/.gitignore deleted file mode 100644 index c602e3a..0000000 --- a/etc/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -phones -remote -termcap -termcap.full diff --git a/etc/MAKEDEV b/etc/MAKEDEV index e6aaae7..1ec9386 100755 --- a/etc/MAKEDEV +++ b/etc/MAKEDEV @@ -52,13 +52,16 @@ do case $i in std) - mknod console c 0 0 - mknod mem c 1 0 ; chmod 640 mem ; chgrp kmem mem + mknod console c 0 0 +# mknod kUmem c 1 3 ; chmod 600 kUmem ;: untested mknod kmem c 1 1 ; chmod 640 kmem ; chgrp kmem kmem + mknod mem c 1 0 ; chmod 640 mem ; chgrp kmem mem mknod null c 1 2 ; chmod 666 null mknod zero c 1 3 ; chmod 444 zero - mknod tty c 2 0 ; chmod 666 tty - mknod klog c 3 0 ; chmod 600 klog + mknod tty c 9 0 ; chmod 666 tty + mknod klog c 22 0 ; chmod 600 klog + mknod errlog c 22 1 ; chmod 600 errlog + mknod acctlog c 22 2 ; chmod 600 acctlog ;; fd) @@ -67,105 +70,304 @@ fd) rm -f stdin stdout stderr mkdir fd chmod 755 fd - mknod stdin c 4 0 - mknod stdout c 4 1 - mknod stderr c 4 2 + mknod stdin c 26 0 + mknod stdout c 26 1 + mknod stderr c 26 2 eval `echo "" | awk '{ for (i = 0; i < 32; i++) - printf("mknod fd/%d c 4 %d; ",i,i); }'` + printf("mknod fd/%d c 26 %d; ",i,i); }'` ;; -rd) +ht*|tm*|ts*|tu*) + umask 0 ; ctlr=`expr $i : '..\(.*\)'` + ctlr=`expr $ctlr '*' 64` + case $i in + ht*) blk=0; chr=6;; + tm*) blk=1; chr=7;; + ts*) blk=2; chr=8;; + tu*) blk=12; chr=23;; + esac +# Maximum of 4 controllers in a system + case $ctlr in + 0|64|128|192) +# Maximum of 4 units per controller +# for unit in 0 1 2 3 + for unit in 0 1 + do + zero=`expr $ctlr + $unit + 0` + four=`expr $zero + 4` ; eight=`expr $zero + 8` + twelve=`expr $zero + 12` + sixteen=`expr $zero + 16` + twenty=`expr $zero + 20` + twentyfour=`expr $zero + 24` + twentyeight=`expr $zero + 28` + mknod mt$zero b $blk $zero + mknod mt$four b $blk $four + mknod mt$eight b $blk $eight + mknod mt$twelve b $blk $twelve + mknod nmt$zero b $blk $four ;: v7 compatibility + mknod nmt$eight b $blk $twelve ;: ditto + mknod nrmt$zero c $chr $four ;: ditto + mknod nrmt$eight c $chr $twelve ;: ditto + mknod rmt$zero c $chr $zero + mknod rmt$four c $chr $four + mknod rmt$eight c $chr $eight + mknod rmt$twelve c $chr $twelve + if [ `expr $i : '\(..\)'` = tu ] + then + mknod mt$sixteen b $blk $sixteen + mknod mt$twenty b $blk $twenty + mknod mt$twentyfour b $blk $twentyfour + mknod mt$twentyeight b $blk $twentyeight + mknod nmt$sixteen b $blk $twenty ;: v7 compatibility + mknod nmt$twentyfour b $blk $twentyeight ;: ditto + mknod nrmt$sixteen c $chr $twenty ;: ditto + mknod nrmt$twentyfour c $chr $twentyeight ;: ditto + mknod rmt$sixteen c $chr $sixteen + mknod rmt$twenty c $chr $twenty + mknod rmt$twentyfour c $chr $twentyfour + mknod rmt$twentyeight c $chr $twentyeight + fi + if [ `expr $i : '\(..\)'` = ut ] + then + mknod mt$twenty b $blk $twenty + mknod rmt$twenty c $chr $twenty + fi + done + ;; + *) + echo bad controller for tape in: $1 + ;; + esac + umask 77 + ;; + +rk*) + # The 2.11BSD rk driver doesn't support partitions. We create + # a single block and charater inode pair for each unit and + # call it rkNh. + umask 2 ; unit=`expr $i : '..\(.*\)'` + case $i in + rk*) name=rk; blk=6; chr=15;; + esac + mknod ${name}${unit}h b ${blk} ${unit} + mknod r${name}${unit}h c ${chr} ${unit} + chgrp operator ${name}${unit}h r${name}${unit}h + chmod 640 ${name}${unit}h r${name}${unit}h + ;; + +rx*) umask 2 - rm -f rd[0123] rd[0123][abcd] - mknod rd0 b 0 0 - mknod rd0a b 0 1 - mknod rd0b b 0 2 - mknod rd0c b 0 2 - mknod rd0d b 0 2 - mknod rd1 b 1 0 - mknod rd1a b 1 1 - mknod rd1b b 1 2 - mknod rd1c b 1 2 - mknod rd1d b 1 2 - mknod rd2 b 2 0 - mknod rd2a b 2 1 - mknod rd2b b 2 2 - mknod rd2c b 2 2 - mknod rd2d b 2 2 - mknod rd3 b 3 0 - mknod rd3a b 3 1 - mknod rd3b b 3 2 - mknod rd3c b 3 2 - mknod rd3d b 3 2 - chgrp operator rd[0123] - chgrp operator rd[0123][abcd] - chmod 640 rd[0123][abcd] - chmod 640 rd[0123] + name=rx; blk=8; chr=17 + mknod ${name}0a b ${blk} 0 + mknod ${name}1a b ${blk} 1 + mknod ${name}0b b ${blk} 2 + mknod ${name}1b b ${blk} 3 + mknod r${name}0a c ${chr} 0 + mknod r${name}1a c ${chr} 1 + mknod r${name}0b c ${chr} 2 + mknod r${name}1b c ${chr} 3 + chgrp operator ${name}[01][ab] r${name}[01][ab] + chmod 640 ${name}[01][ab] r${name}[01][ab] ;; -gpio) - umask 0 - rm -f port[abcdefg] conf[abcdef] - mknod porta c 5 0 - mknod portb c 5 1 - mknod portc c 5 2 - mknod portd c 5 3 - mknod porte c 5 4 - mknod portf c 5 5 - mknod portg c 5 6 - mknod confa c 5 64 - mknod confb c 5 65 - mknod confc c 5 66 - mknod confd c 5 67 - mknod confe c 5 68 - mknod conff c 5 69 - mknod confg c 5 70 +ram*) + # Note, this must come *before* the "ra*". The entry "rram" is for + # auto fscks when ram is mentioned in /etc/fstab. + umask 2 + mknod ram b 3 0 + ln ram rram + chgrp operator ram + chmod 640 ram + umask 77 ;; -adc) - umask 0 - rm -f adc[0123456789] adc1[012345] - mknod adc0 c 6 0 - mknod adc1 c 6 1 - mknod adc2 c 6 2 - mknod adc3 c 6 3 - mknod adc4 c 6 4 - mknod adc5 c 6 5 - mknod adc6 c 6 6 - mknod adc7 c 6 7 - mknod adc8 c 6 8 - mknod adc9 c 6 9 - mknod adc10 c 6 10 - mknod adc11 c 6 11 - mknod adc12 c 6 12 - mknod adc13 c 6 13 - mknod adc14 c 6 14 - mknod adc15 c 6 15 +br*|hk*|ra*|si*|xp*|rl*) + umask 2 ; unit=`expr $i : '..\(.*\)'` + case $i in + br*) name=rp; blk=11; chr=20;; + hk*) name=hk; blk=4; chr=13;; + ra*) name=ra; blk=5; chr=14;; + si*) name=si; blk=9; chr=18;; + xp*) name=xp; blk=10; chr=19;; + rl*) name=rl; blk=7; chr=16;; + esac + case $unit in + 0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|\ + 17|18|19|20|21|22|23|24|25|26|27|28|29|30|31) + mknod ${name}${unit}a b $blk `expr $unit '*' 8 + 0` + mknod ${name}${unit}b b $blk `expr $unit '*' 8 + 1` + mknod ${name}${unit}c b $blk `expr $unit '*' 8 + 2` + mknod ${name}${unit}d b $blk `expr $unit '*' 8 + 3` + mknod ${name}${unit}e b $blk `expr $unit '*' 8 + 4` + mknod ${name}${unit}f b $blk `expr $unit '*' 8 + 5` + mknod ${name}${unit}g b $blk `expr $unit '*' 8 + 6` + mknod ${name}${unit}h b $blk `expr $unit '*' 8 + 7` + mknod r${name}${unit}a c $chr `expr $unit '*' 8 + 0` + mknod r${name}${unit}b c $chr `expr $unit '*' 8 + 1` + mknod r${name}${unit}c c $chr `expr $unit '*' 8 + 2` + mknod r${name}${unit}d c $chr `expr $unit '*' 8 + 3` + mknod r${name}${unit}e c $chr `expr $unit '*' 8 + 4` + mknod r${name}${unit}f c $chr `expr $unit '*' 8 + 5` + mknod r${name}${unit}h c $chr `expr $unit '*' 8 + 7` + mknod r${name}${unit}g c $chr `expr $unit '*' 8 + 6` + chgrp operator ${name}${unit}[a-h] r${name}${unit}[a-h] + chmod 640 ${name}${unit}[a-h] r${name}${unit}[a-h] + ;; + *) + echo bad unit for disk in: $i + ;; + esac + umask 77 ;; -spi) - umask 0 - rm -f spi[1234] - mknod spi1 c 7 0 - mknod spi2 c 7 1 - mknod spi3 c 7 2 - mknod spi4 c 7 3 +dz*) + unit=`expr $i : 'dz\(.*\)'` + case $unit in + 0|1|2|3|4|5|6|7) + eval `echo $unit | awk ' { u = $1 } END { + for (i = 0; i < 8; i++) + printf("mknod tty%02d c 2 %d; ",u*8+i,u*8+i); }'` + ;; + *) + echo bad unit for dz in: $i + ;; + esac ;; -glcd) - umask 0 - rm -f glcd0 - mknod glcd0 c 8 0 +# +# we may want dmz and dmf someday... +# dhu*|dh*|dmf*|dmz*) +dhv*|dhu*|dh*) + case $i in +# dmz*) name=dmz; major=37; count=24; +# unit=`expr $i : "$name\(.*\)"` +# case $unit in +# 0) ch=a ;; 1) ch=b ;; 2) ch=c ;; 3) ch=e ;; +# 4) ch=f ;; 5) ch=g ;; +# *) echo bad unit for $name in: $i ;; +# esac;; +# dmf*) name=dmf; major=22; count=8; +# unit=`expr $i : "$name\(.*\)"` +# case $unit in +# 0) ch=A ;; 1) ch=B ;; 2) ch=C ;; 3) ch=E ;; +# 4) ch=F ;; 5) ch=G ;; 6) ch=H ;; 7) ch=I ;; +# *) echo bad unit for $name in: $i ;; +# esac;; + dhv*) name=dhv; major=24; count=8; + unit=`expr $i : "$name\(.*\)"`; + case $unit in + 0) ch=S ;; 1) ch=T ;; 2) ch=U ;; 3) ch=V ;; + 4) ch=W ;; 5) ch=X ;; 6) ch=Y ;; 7) ch=Z ;; + *) echo bad unit for $name in: $i ;; + esac;; + dhu*) name=dhu; major=4; count=16; + unit=`expr $i : "$name\(.*\)"`; + case $unit in + 0) ch=S ;; 1) ch=T ;; 2) ch=U ;; 3) ch=V ;; + 4) ch=W ;; 5) ch=X ;; 6) ch=Y ;; 7) ch=Z ;; + *) echo bad unit for $name in: $i ;; + esac;; + dh*) name=dh; major=3; count=16; + unit=`expr $i : "$name\(.*\)"` + case $unit in + 0) ch=h ;; 1) ch=i ;; 2) ch=j ;; 3) ch=k ;; + *) echo bad unit for $name in: $i ;; + esac;; + esac + eval `echo $ch $unit $major $count | + awk ' { ch = $1; u = $4 * $2; m = $3; cnt = $4 } END { + for (i = 0; i < cnt; i++) + if (i < 10) + printf("mknod tty%s%x c %d %d; ",ch,i,m,u+i); + else + printf("mknod tty%s%c c %d %d; ",ch,87+i,m,u+i); }'` ;; -oc) - umask 0 - rm -f oc[12345] - mknod oc1 c 9 0 - mknod oc2 c 9 1 - mknod oc3 c 9 2 - mknod oc4 c 9 3 - mknod oc5 c 9 4 +# extra DL-11 units not including the console. unit numbers start at 1 because +# the console is always unit 0. Seven units (1 - 7) are defined for the 11/93 +# and 11/94. Device name is "ttyl?". The DH range was restricted from 'h'-'o' +# to 'h' - 'k' (very unlikely that more than 64 channels of DH-11 will or could +# be put on an 11. + +dl*) + name=dl; major=0; ch=l + unit=`expr $i : "$name\(.*\)"` + case $unit in + 1|2|3|4|5|6|7) + mknod tty${ch}${unit} c $major $unit; + ;; + *) + echo bad unit for $name in: $i + ;; + esac + ;; + +# we may want va and vp someday... +# lp*|va*|vp*) +lp*|dn*) + case $i in + lp*) name=lp; major=5;; + dn*) name=dn; major=21;; +# va*) name=va; major=10;; +# vp*) name=vp; major=6;; + esac + unit=`expr $i : "$name\(.*\)"` + case $unit in + 0|1|2|3|4|5|6|7) + mknod $i c $major $unit; + chmod 666 $i + ;; + *) + echo bad unit for $name in: $i + ;; + esac + ;; + +pty*) + class=`expr $i : 'pty\(.*\)'` + case $class in + 0) offset=0 name=p;; + 1) offset=16 name=q;; + 2) offset=32 name=r;; + 3) offset=48 name=s;; + 4) offset=64 name=t;; + 5) offset=80 name=u;; + *) echo bad unit for pty in: $i;; + esac + case $class in + 0|1|2|3|4|5) + umask 0 + eval `echo $offset $name | awk ' { b=$1; n=$2 } END { + for (i = 0; i < 16; i++) + printf("mknod tty%s%x c 11 %d; \ + mknod pty%s%x c 10 %d; ", \ + n, i, b+i, n, i, b+i); }'` + umask 77 + ;; + esac + ;; + +dr*) + unit=`expr $i : '..\(.*\)'` + case $i in + dr*) name=dr; chr=12;; + esac + case $unit in + 0|1|2|3|4|5|6|7) + umask 0 + mknod ${name}${unit} c ${chr} ${unit} + umask 77 + ;; + *) + echo bad unit for ${name} in: $i + ;; + esac + ;; + +ingreslock) + mknod ingreslock c 25 0 + chown ingres ingreslock + chmod 200 ingreslock ;; local) diff --git a/etc/fstab b/etc/fstab index 38305c1..2c5cf75 100644 --- a/etc/fstab +++ b/etc/fstab @@ -1,2 +1,2 @@ -/dev/rd0a / ufs rw,async 1 1 -#/dev/rd0c /u ufs rw,async 1 2 +/dev/sd0 / ufs rw,async 1 1 +#/dev/sd1 /u ufs rw,async 1 2 diff --git a/etc/gettytab b/etc/gettytab index 5a873c3..e53d8f1 100644 --- a/etc/gettytab +++ b/etc/gettytab @@ -80,8 +80,6 @@ v|std.3500000|3500000-baud:\ :sp#3500000: w|std.4000000|4000000-baud:\ :sp#4000000: -x|std.default|default-baud:\ - :sp#0: # diff --git a/etc/rc b/etc/rc index c72f050..5658298 100755 --- a/etc/rc +++ b/etc/rc @@ -3,8 +3,6 @@ HOME=/; export HOME PATH=/bin:/sbin; export PATH exec >/dev/console 2>&1 -/sbin/devupdate - if test "$1" != "autoboot"; then # # Switch from single-user to multi-user mode. @@ -66,7 +64,6 @@ rm -f /etc/nologin echo -n "Starting daemons:" update && echo -n "update" -cron && echo -n "cron" echo #/etc/rc.local diff --git a/etc/ttys b/etc/ttys index 55106e4..058dd44 100644 --- a/etc/ttys +++ b/etc/ttys @@ -1,16 +1,4 @@ # # name getty type status comments # -console "/libexec/getty std.default" xterm on secure #special - -# Enable some of these for additional logins. Do NOT enable the same one as the -# console port, or strange things will happen. You can turn off the console port -# if you would rather use the getty on the real tty - it's up to you. - -tty0 "/libexec/getty std.default" xterm off secure -tty1 "/libexec/getty std.default" xterm off secure -tty2 "/libexec/getty std.default" xterm off secure -tty3 "/libexec/getty std.default" xterm off secure -tty4 "/libexec/getty std.default" xterm off secure -tty5 "/libexec/getty std.default" xterm off secure -ttyUSB0 "/libexec/getty std.default" xterm off secure +console "/libexec/getty std.115200" vt100 on secure #special diff --git a/games/.gitignore b/games/.gitignore deleted file mode 100644 index 72e8ffc..0000000 --- a/games/.gitignore +++ /dev/null @@ -1 +0,0 @@ -* diff --git a/games/lib/battle_strings b/games/lib/battle_strings deleted file mode 100644 index a11dd99..0000000 Binary files a/games/lib/battle_strings and /dev/null differ diff --git a/include/a.out.h b/include/a.out.h index 4b03a12..383df20 100644 --- a/include/a.out.h +++ b/include/a.out.h @@ -33,36 +33,48 @@ #ifndef _AOUT_H_ #define _AOUT_H_ -#include +#include + +/* Valid magic number check. */ +#define N_BADMAG(x) (((x).a_magic) != RMAGIC && \ + ((x).a_magic) != OMAGIC && \ + ((x).a_magic) != NMAGIC) + +/* Text segment offset. */ +#define N_TXTOFF(x) sizeof(struct exec) + +/* Data segment offset. */ +#define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text) + +/* Text relocation table offset. */ +#define N_TRELOFF(x) (N_DATOFF(x) + (x).a_data) + +/* Data relocation table offset. */ +#define N_DRELOFF(x) (N_TRELOFF(x) + (x).a_reltext) + +/* Symbol table offset. */ +#define N_SYMOFF(x) ((x).a_magic == RMAGIC ? \ + N_DRELOFF(x) + (x).a_reldata : \ + N_DATOFF(x) + (x).a_data) #define _AOUT_INCLUDE_ #include /* Relocations */ -struct reloc { - unsigned flags; #define RSMASK 0x70 /* bitmask for segments */ -#define RABS 0 -#define RTEXT 0x20 -#define RDATA 0x30 -#define RBSS 0x40 -#define RSTRNG 0x60 /* for assembler */ -#define REXT 0x70 /* externals and bitmask */ - -#define RGPREL 0x08 /* gp relative */ +#define RABS 0 +#define RTEXT 0x20 +#define RDATA 0x30 +#define RBSS 0x40 +#define RSTRNG 0x60 /* for assembler */ +#define REXT 0x70 /* externals and bitmask */ #define RFMASK 0x07 /* bitmask for format */ -#define RBYTE16 0x00 /* low part of byte address: bits 15:0 */ -#define RBYTE32 0x01 /* 32-bit byte address */ -#define RHIGH16 0x02 /* upper part of byte address: bits 31:16 */ -#define RHIGH16S 0x03 /* upper part of address with signed offset */ -#define RWORD16 0x04 /* word address: bits 17:2 */ -#define RWORD26 0x05 /* word address: bits 27:2 */ +#define RHIGH16 0x02 /* upper part of byte address: bits 31:16 */ +#define RWORD16 0x03 /* word address: bits 17:2 */ +#define RWORD26 0x04 /* word address: bits 27:2 */ - unsigned index; /* 24-bit index in symbol table, - * for REXT */ - unsigned offset; /* 16-bit offset, - * for RIGH16 and RIGH16S */ -}; +#define RINDEX(h) ((h) >> 8) +#define RSETINDEX(h) ((h) << 8) #endif /* !_AOUT_H_ */ diff --git a/include/alloca.h b/include/alloca.h deleted file mode 100644 index b73c543..0000000 --- a/include/alloca.h +++ /dev/null @@ -1,15 +0,0 @@ -/* alloca.h - Allocate memory on stack */ - -#ifndef ALLOCA_H -#define ALLOCA_H - -#undef alloca - -#ifdef __GNUC__ -#define alloca(size) __builtin_alloca(size) -#else -#include -void *alloca(size_t); -#endif - -#endif diff --git a/include/curses.h b/include/curses.h index 28bf21c..fd66b22 100644 --- a/include/curses.h +++ b/include/curses.h @@ -9,7 +9,7 @@ #include #include -#define bool int +#define bool char #define reg register #define TRUE (1) @@ -149,7 +149,7 @@ int __void__; #define noecho() (_tty.sg_flags &= ~ECHO, _echoit = FALSE, ioctl(_tty_ch, TIOCSETP, &_tty)) #define nl() (_tty.sg_flags |= CRMOD, _pfast = _rawmode,ioctl(_tty_ch, TIOCSETP, &_tty)) #define nonl() (_tty.sg_flags &= ~CRMOD,_pfast = TRUE, ioctl(_tty_ch, TIOCSETP,&_tty)) -#define savetty() ((void) ioctl(_tty_ch, TIOCGETP, &_tty), _res_flg = _tty.sg_flags) +#define savetty() ((void) gtty(_tty_ch, &_tty), _res_flg = _tty.sg_flags) #define resetty() (_tty.sg_flags = _res_flg, (void) ioctl(_tty_ch, TIOCSETP, &_tty)) #define erasechar() (_tty.sg_erase) @@ -167,24 +167,11 @@ int wgetch (WINDOW *); char *wstandout (WINDOW *); char *wstandend (WINDOW *); int touchwin (WINDOW *); -int touchline (WINDOW *, int, int, int); -void box (WINDOW *, char, char); +int touchline (WINDOW *, int, int); +int box (WINDOW *, char, char); void endwin (void); -int printw (char *, ...); -int wprintw (WINDOW *, char *, ...); -int scroll (WINDOW *); -void wclrtoeol (WINDOW *); -void werase (WINDOW *); -int setterm (char *); -int delwin (WINDOW *); -int waddstr (WINDOW *, char *); -int wgetstr (WINDOW *, char *); -int wdeleteln (WINDOW *); -void mvcur(int ly, int lx, int y, int x); -void overwrite(WINDOW *win1, WINDOW *win2); -void wclrtobot(WINDOW *win); -int mvprintw(int y, int x, char *fmt, ...); -int mvwprintw(WINDOW *win, int y, int x, char *fmt, ...); +int printw (char *fmt, ...); +int wprintw (WINDOW *win, char *fmt, ...); /* * Used to be in unctrl.h. diff --git a/include/grp.h b/include/grp.h index b32ebd9..f053f22 100644 --- a/include/grp.h +++ b/include/grp.h @@ -7,9 +7,4 @@ struct group { /* see getgrent(3) */ char **gr_mem; }; -struct group *getgrent(void); -struct group *getgrnam(const char *name); -struct group *getgrgid(gid_t gid); -void setgrent(void); -void endgrent(void); -int setgroups(size_t size, const gid_t *list); +struct group *getgrent(), *getgrgid(), *getgrnam(); diff --git a/include/kmem.h b/include/kmem.h deleted file mode 100644 index bf3e5ea..0000000 --- a/include/kmem.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _KMEM_H -#define _KMEM_H - -extern dev_t kmemdev(); - -#endif diff --git a/include/nlist.h b/include/nlist.h index 8380246..aa27b85 100644 --- a/include/nlist.h +++ b/include/nlist.h @@ -35,7 +35,8 @@ #include /* - * Symbol table entry format. + * Symbol table entry format. The #ifdef's are so that programs including + * nlist.h can initialize nlist structures statically. */ struct nlist { char *n_name; /* In memory address of symbol name, @@ -55,12 +56,13 @@ struct nlist { #define N_BSS 0x04 /* bss segment */ #define N_STRNG 0x05 /* string segment (for assembler) */ #define N_COMM 0x06 /* .comm segment (for assembler) */ +#define N_REG 0x14 /* register symbol */ #define N_FN 0x1f /* file name */ -#define N_TYPE 0x1f /* mask for all the type bits */ #define N_EXT 0x20 /* external (global) bit, OR'ed in */ -#define N_WEAK 0x40 /* weak reference bit, OR'ed in */ -#define N_LOC 0x80 /* local, for assembler */ +#define N_TYPE 0x1f /* mask for all the type bits */ + +#define N_FORMAT "%06o" /* namelist value format; XXX */ /* * Get symbols from a file. diff --git a/include/ranlib.h b/include/ranlib.h index 6cd1da8..80a919a 100644 --- a/include/ranlib.h +++ b/include/ranlib.h @@ -39,7 +39,7 @@ struct ranlib { int ran_len; /* 1 byte - name length in bytes */ - unsigned ran_off; /* 4 bytes - file offset */ + off_t ran_off; /* 4 bytes - file offset */ char *ran_name; /* in memory symbol name */ }; diff --git a/include/setjmp.h b/include/setjmp.h index 14f4327..b209951 100644 --- a/include/setjmp.h +++ b/include/setjmp.h @@ -14,29 +14,9 @@ * 9 - $ra - return address * 10 - $gp - global data pointer * 11 - $sp - stack pointer - * 12 - signal mask saved - * 13 - signal mask */ -typedef int jmp_buf [14]; -typedef jmp_buf sigjmp_buf; +typedef int jmp_buf [12]; -/* - * Save and restore only CPU state. - * Signal mask is not saved. - */ -int _setjmp (jmp_buf env); -void _longjmp (jmp_buf env, int val); - -/* - * Save and restore CPU state and signal mask. - */ int setjmp (jmp_buf env); void longjmp (jmp_buf env, int val); - -/* - * Save and restore CPU state and optionally a signal mask. - * Signal mask is saved only when savesigs is nonzero. - */ -int sigsetjmp (sigjmp_buf env, int savesigs); -void siglongjmp (sigjmp_buf env, int val); #endif diff --git a/include/smallc/curses.h b/include/smallc/curses.h deleted file mode 100644 index f9aa9a1..0000000 --- a/include/smallc/curses.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * SmallC: interface to curses library. - */ -#define WINDOW int - -extern WINDOW *stdscr, *curscr; - -extern int LINES, COLS; - -/* - * pseudo functions for standard screen - */ -#define addch(ch) waddch(stdscr, ch) -#define getch() wgetch(stdscr) -#define addstr(str) waddstr(stdscr, str) -#define getstr(str) wgetstr(stdscr, str) -#define move(y, x) wmove(stdscr, y, x) -#define clear() wclear(stdscr) -#define erase() werase(stdscr) -#define clrtobot() wclrtobot(stdscr) -#define clrtoeol() wclrtoeol(stdscr) -#define insertln() winsertln(stdscr) -#define deleteln() wdeleteln(stdscr) -#define refresh() wrefresh(stdscr) -#define inch() winch(stdscr) -#define insch(c) winsch(stdscr,c) -#define delch() wdelch(stdscr) -#define standout() wstandout(stdscr) -#define standend() wstandend(stdscr) - -/* - * mv functions - */ -#define mvwaddch(win,y,x,ch) wmove(win,y,x) == 0 ? 0 : waddch(win,ch) -#define mvwgetch(win,y,x) wmove(win,y,x) == 0 ? 0 : wgetch(win) -#define mvwaddstr(win,y,x,str) wmove(win,y,x) == 0 ? 0 : waddstr(win,str) -#define mvwgetstr(win,y,x,str) wmove(win,y,x) == 0 ? 0 : wgetstr(win,str) -#define mvwinch(win,y,x) wmove(win,y,x) == 0 ? 0 : winch(win) -#define mvwdelch(win,y,x) wmove(win,y,x) == 0 ? 0 : wdelch(win) -#define mvwinsch(win,y,x,c) wmove(win,y,x) == 0 ? 0 : winsch(win,c) -#define mvaddch(y,x,ch) mvwaddch(stdscr,y,x,ch) -#define mvgetch(y,x) mvwgetch(stdscr,y,x) -#define mvaddstr(y,x,str) mvwaddstr(stdscr,y,x,str) -#define mvgetstr(y,x,str) mvwgetstr(stdscr,y,x,str) -#define mvinch(y,x) mvwinch(stdscr,y,x) -#define mvdelch(y,x) mvwdelch(stdscr,y,x) -#define mvinsch(y,x,c) mvwinsch(stdscr,y,x,c) - -#ifdef TODO - -#define TRUE (1) -#define FALSE (0) -#define ERR (0) -#define OK (1) - -/* - * Capabilities from termcap - */ -extern int AM, BS, CA, DA, DB, EO, HC, HZ, IN, MI, MS, NC, NS, OS, UL, - XB, XN, XT, XS, XX; -extern char *AL, *BC, *BT, *CD, *CE, *CL, *CM, *CR, *CS, *DC, *DL, - *DM, *DO, *ED, *EI, *K0, *K1, *K2, *K3, *K4, *K5, *K6, - *K7, *K8, *K9, *HO, *IC, *IM, *IP, *KD, *KE, *KH, *KL, - *KR, *KS, *KU, *LL, *MA, *ND, *NL, *RC, *SC, *SE, *SF, - *SO, *SR, *TA, *TE, *TI, *UC, *UE, *UP, *US, *VB, *VS, - *VE, *AL_PARM, *DL_PARM, *UP_PARM, *DOWN_PARM, - *LEFT_PARM, *RIGHT_PARM; -extern char PC; - -/* - * From the tty modes... - */ -extern int GT, NONL, UPPERCASE, normtty, _pfast; - -extern int My_term, _echoit, _rawmode, _endwin; - -extern char *Def_term, ttytype[]; - -extern int _tty_ch, _res_flg; - -extern SGTTY _tty; - -/* - * pseudo functions - */ -#define clearok(win,bf) (win->_clear = bf) -#define leaveok(win,bf) (win->_leave = bf) -#define scrollok(win,bf) (win->_scroll = bf) -#define flushok(win,bf) (bf ? (win->_flags |= _FLUSH):(win->_flags &= ~_FLUSH)) -#define getyx(win,y,x) y = win->_cury, x = win->_curx -#define winch(win) (win->_y[win->_cury][win->_curx] & 0177) - -#define raw() (_tty.sg_flags|=RAW, _pfast=_rawmode=TRUE, ioctl(_tty_ch,TIOCSETP,&_tty)) -#define noraw() (_tty.sg_flags&=~RAW,_rawmode=FALSE,_pfast=!(_tty.sg_flags&CRMOD),ioctl(_tty_ch,TIOCSETP,&_tty)) -#define cbreak() (_tty.sg_flags |= CBREAK, _rawmode = TRUE, ioctl(_tty_ch,TIOCSETP,&_tty)) -#define nocbreak() (_tty.sg_flags &= ~CBREAK,_rawmode=FALSE,ioctl(_tty_ch,TIOCSETP,&_tty)) -#define echo() (_tty.sg_flags |= ECHO, _echoit = TRUE, ioctl(_tty_ch, TIOCSETP, &_tty)) -#define noecho() (_tty.sg_flags &= ~ECHO, _echoit = FALSE, ioctl(_tty_ch, TIOCSETP, &_tty)) -#define nl() (_tty.sg_flags |= CRMOD, _pfast = _rawmode,ioctl(_tty_ch, TIOCSETP, &_tty)) -#define nonl() (_tty.sg_flags &= ~CRMOD,_pfast = TRUE, ioctl(_tty_ch, TIOCSETP,&_tty)) -#define savetty() ((void) ioctl(_tty_ch, TIOCGETP, &_tty), _res_flg = _tty.sg_flags) -#define resetty() (_tty.sg_flags = _res_flg, (void) ioctl(_tty_ch, TIOCSETP, &_tty)) - -#define erasechar() (_tty.sg_erase) -#define killchar() (_tty.sg_kill) -#define baudrate() (_tty.sg_ospeed) - -/* - * Used to be in unctrl.h. - */ -#define unctrl(c) _unctrl[(c) & 0177] -extern char *_unctrl[]; - -#endif diff --git a/include/smallc/fcntl.h b/include/smallc/fcntl.h deleted file mode 100644 index f1eb11c..0000000 --- a/include/smallc/fcntl.h +++ /dev/null @@ -1,38 +0,0 @@ - -/* open-only flags */ -#define O_RDONLY 0x0000 /* open for reading only */ -#define O_WRONLY 0x0001 /* open for writing only */ -#define O_RDWR 0x0002 /* open for reading and writing */ -#define O_ACCMODE 0x0003 /* mask for above modes */ - -#define O_NONBLOCK 0x0004 /* no delay */ -#define O_APPEND 0x0008 /* set append mode */ -#define O_SHLOCK 0x0010 /* open with shared file lock */ -#define O_EXLOCK 0x0020 /* open with exclusive file lock */ -#define O_ASYNC 0x0040 /* signal pgrp when data ready */ -#define O_FSYNC 0x0080 /* synchronous writes */ -#define O_CREAT 0x0200 /* create if nonexistant */ -#define O_TRUNC 0x0400 /* truncate to zero length */ -#define O_EXCL 0x0800 /* error if already exists */ - -/* - * Constants used for fcntl(2) - */ - -/* command values */ -#define F_DUPFD 0 /* duplicate file descriptor */ -#define F_GETFD 1 /* get file descriptor flags */ -#define F_SETFD 2 /* set file descriptor flags */ -#define F_GETFL 3 /* get file status flags */ -#define F_SETFL 4 /* set file status flags */ -#define F_GETOWN 5 /* get SIGIO/SIGURG proc/pgrp */ -#define F_SETOWN 6 /* set SIGIO/SIGURG proc/pgrp */ - -/* file descriptor flags (F_GETFD, F_SETFD) */ -#define FD_CLOEXEC 1 /* close-on-exec flag */ - -/* lock operations for flock() */ -#define LOCK_SH 1 /* shared file lock */ -#define LOCK_EX 2 /* exclusive file lock */ -#define LOCK_NB 4 /* don't block when locking */ -#define LOCK_UN 8 /* unlock file */ diff --git a/include/smallc/signal.h b/include/smallc/signal.h deleted file mode 100644 index ae8f7a2..0000000 --- a/include/smallc/signal.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 1986 Regents of the University of California. - * All rights reserved. The Berkeley software License Agreement - * specifies the terms and conditions for redistribution. - */ -#ifndef NSIG - -#define NSIG 32 - -#define SIGHUP 1 /* hangup */ -#define SIGINT 2 /* interrupt */ -#define SIGQUIT 3 /* quit */ -#define SIGILL 4 /* illegal instruction (not reset when caught) */ -#define SIGTRAP 5 /* trace trap (not reset when caught) */ -#define SIGIOT 6 /* IOT instruction */ -#define SIGABRT SIGIOT /* compatibility */ -#define SIGEMT 7 /* EMT instruction */ -#define SIGFPE 8 /* floating point exception */ -#define SIGKILL 9 /* kill (cannot be caught or ignored) */ -#define SIGBUS 10 /* bus error */ -#define SIGSEGV 11 /* segmentation violation */ -#define SIGSYS 12 /* bad argument to system call */ -#define SIGPIPE 13 /* write on a pipe with no one to read it */ -#define SIGALRM 14 /* alarm clock */ -#define SIGTERM 15 /* software termination signal from kill */ -#define SIGURG 16 /* urgent condition on IO channel */ -#define SIGSTOP 17 /* sendable stop signal not from tty */ -#define SIGTSTP 18 /* stop signal from tty */ -#define SIGCONT 19 /* continue a stopped process */ -#define SIGCHLD 20 /* to parent on child stop or exit */ -#define SIGCLD SIGCHLD /* compatibility */ -#define SIGTTIN 21 /* to readers pgrp upon background tty read */ -#define SIGTTOU 22 /* like TTIN for output if (tp->t_local<OSTOP) */ -#define SIGIO 23 /* input/output possible signal */ -#define SIGXCPU 24 /* exceeded CPU time limit */ -#define SIGXFSZ 25 /* exceeded file size limit */ -#define SIGVTALRM 26 /* virtual time alarm */ -#define SIGPROF 27 /* profiling time alarm */ -#define SIGWINCH 28 /* window size changes */ -#define SIGUSR1 30 /* user defined signal 1 */ -#define SIGUSR2 31 /* user defined signal 2 */ - -#define SIG_ERR -1 -#define SIG_DFL 0 -#define SIG_IGN 1 -#define BADSIG SIG_ERR - -#define SA_ONSTACK 0x0001 /* take signal on signal stack */ -#define SA_RESTART 0x0002 /* restart system on signal return */ -#define SA_DISABLE 0x0004 /* disable taking signals on alternate stack */ -#define SA_NOCLDSTOP 0x0008 /* do not generate SIGCHLD on child stop */ - -/* - * Flags for sigprocmask: - */ -#define SIG_BLOCK 1 /* block specified signal set */ -#define SIG_UNBLOCK 2 /* unblock specified signal set */ -#define SIG_SETMASK 3 /* set specified signal set */ - -#define MINSIGSTKSZ 128 /* minimum allowable stack */ -#define SIGSTKSZ (MINSIGSTKSZ + 384) /* recommended stack size */ - -#define SV_ONSTACK SA_ONSTACK /* take signal on signal stack */ -#define SV_INTERRUPT SA_RESTART /* same bit, opposite sense */ - -/* - * Macro for converting signal number to a mask suitable for - * sigblock(). - */ -#define sigmask(m) (1L << ((m)-1)) -#define sigaddset(set, signo) (*(set) |= 1L << ((signo) - 1), 0) -#define sigdelset(set, signo) (*(set) &= ~(1L << ((signo) - 1)), 0) -#define sigemptyset(set) (*(set) = (sigset_t)0, (int)0) -#define sigfillset(set) (*(set) = ~(sigset_t)0, (int)0) -#define sigismember(set, signo) ((*(set) & (1L << ((signo) - 1))) != 0) - -#endif /* NSIG */ diff --git a/include/smallc/stdio.h b/include/smallc/stdio.h deleted file mode 100644 index c0278d0..0000000 --- a/include/smallc/stdio.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * SmallC: interface to stdio library. - */ -#define BUFSIZ 1024 - -#ifndef NULL -#define NULL 0 -#endif - -#define FILE int -#define EOF (-1) - -extern int _iob[]; - -#define stdin (&_iob[0]) -#define stdout (&_iob[5]) -#define stderr (&_iob[10]) - -#define SEEK_SET 0 /* set file offset to offset */ -#define SEEK_CUR 1 /* set file offset to current plus offset */ -#define SEEK_END 2 /* set file offset to EOF plus offset */ - -#define getc fgetc -#define putc fputc diff --git a/include/smallc/sys/gpio.h b/include/smallc/sys/gpio.h deleted file mode 100644 index ff1a68e..0000000 --- a/include/smallc/sys/gpio.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Ioctl definitions for GPIO driver. - */ -#define GPIO_PORT(n) (n) /* port number */ -#define GPIO_PORTA 0 -#define GPIO_PORTB 1 -#define GPIO_PORTC 2 -#define GPIO_PORTD 3 -#define GPIO_PORTE 4 -#define GPIO_PORTF 5 -#define GPIO_PORTG 6 - -#define GPIO_CONFIN 0x20016700 /* configure as input */ -#define GPIO_CONFOUT 0x20026700 /* configure as output */ -#define GPIO_CONFOD 0x20046700 /* configure as open drain */ -#define GPIO_DECONF 0x20086700 /* deconfigure */ -#define GPIO_STORE 0x20106700 /* store all outputs */ -#define GPIO_SET 0x20206700 /* set to 1 by mask */ -#define GPIO_CLEAR 0x20406700 /* set to 0 by mask */ -#define GPIO_INVERT 0x20806700 /* invert by mask */ -#define GPIO_POLL 0x21006700 /* poll */ -#define GPIO_LOL 0x82006700 /* display lol picture */ diff --git a/include/smallc/sys/spi.h b/include/smallc/sys/spi.h deleted file mode 100644 index 6d5b154..0000000 --- a/include/smallc/sys/spi.h +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Ioctl definitions for SPI driver. - */ -#define SPICTL_SETMODE 0x20007000 /* set SPI mode */ -#define SPICTL_SETRATE 0x20007001 /* set clock rate, kHz */ -#define SPICTL_SETSELPIN 0x20007002 /* set select pin */ -#define SPICTL_IO8(n) (0xc0007003 | (n)<<16) /* transfer n*8 bits */ -#define SPICTL_IO16(n) (0xc0007004 | (n)<<16) /* transfer n*16 bits */ -#define SPICTL_IO32(n) (0xc0007005 | (n)<<16) /* transfer n*32 bits */ diff --git a/include/smallc/wiznet.h b/include/smallc/wiznet.h deleted file mode 100644 index 23f2ec7..0000000 --- a/include/smallc/wiznet.h +++ /dev/null @@ -1,12 +0,0 @@ -/* - * SmallC: interface to wiznet library. - */ -#define MAX_SOCK_NUM 4 /* Max number of sockets per chip */ -#define CLIENT_SIZE 3 /* Size of client structure in words */ -#define UDP_SIZE 2 /* Size of UDP structure in words */ - -extern unsigned _socket_port[]; - -extern unsigned _client_srcport; - -extern unsigned _server_port; diff --git a/include/stdarg.h b/include/stdarg.h index 54710a5..d03246e 100644 --- a/include/stdarg.h +++ b/include/stdarg.h @@ -4,49 +4,27 @@ #ifndef _STDARG_H #define _STDARG_H -/* - * Define va_start, va_arg, va_end, va_copy. - */ -#if defined(__GNUC__) /* Gnu C */ -# define va_start(ap, last) __builtin_va_start((ap), last) -# define va_arg(ap, type) __builtin_va_arg((ap), type) -# define va_end(ap) __builtin_va_end((ap)) -# define va_copy(dest, src) __builtin_va_copy((dest), (src)) +/* Define __gnuc_va_list. */ -#elif defined(__PCC__) /* PCC */ -# define va_start(ap, last) __builtin_stdarg_start((ap), last) -# define va_arg(ap, type) __builtin_va_arg((ap), type) -# define va_end(ap) __builtin_va_end((ap)) -# define va_copy(dest, src) __builtin_va_copy((dest), (src)) - -#else /* SmallerC, LCC */ -# define va_start(ap, last) (ap = ((char*)&(last) + \ - (((sizeof(last) + sizeof(int) - 1) / sizeof(int)) * sizeof(int)))) -# define va_arg(ap, type) ((type*)(ap += \ - sizeof(type) == sizeof(int) ? sizeof(type) : \ - (-(int)(ap) & (sizeof(type) - 1)) + sizeof(type)))[-1] -# define va_end(ap) -# define va_copy(dest, src) (dest = (src)) +#ifndef __GNUC_VA_LIST +#define __GNUC_VA_LIST +typedef __builtin_va_list __gnuc_va_list; #endif -/* - * Define va_list. - */ -#ifndef _VA_LIST_T -# define _VA_LIST_T -# if defined(__GNUC__) || defined(__PCC__) - typedef __builtin_va_list va_list; -# else - typedef char *va_list; -# endif +#ifdef __GNUC__ +# define va_start(ap, last) __builtin_va_start((ap), last) #endif +#ifdef __PCC__ +# define va_start(ap, last) __builtin_stdarg_start((ap), last) +#endif +#define va_arg(ap, type) __builtin_va_arg((ap), type) +#define va_end(ap) __builtin_va_end((ap)) +#define va_copy(dest, src) __builtin_va_copy((dest), (src)) -/* - * Define __gnuc_va_list. - */ -#if defined(__GNUC__) && !defined(__GNUC_VA_LIST) -# define __GNUC_VA_LIST - typedef __builtin_va_list __gnuc_va_list; + +#ifndef _VA_LIST +#define _VA_LIST +typedef __gnuc_va_list va_list; #endif #endif /* not _STDARG_H */ diff --git a/include/stddef.h b/include/stddef.h deleted file mode 100644 index 5b6206f..0000000 --- a/include/stddef.h +++ /dev/null @@ -1,8 +0,0 @@ - -/* Offset of member MEMBER in a struct of type TYPE. */ - -#if defined(__GNUC__) && __GNUC__ > 3 -#define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER) -#else -#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE*)0)->MEMBER) -#endif diff --git a/include/stdio.h b/include/stdio.h index bae653e..42a38e3 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -14,7 +14,7 @@ extern struct _iobuf { char *_base; /* ditto */ int _bufsiz; short _flag; - short _file; + char _file; /* should be short */ } _iob[]; #define _IOREAD 01 @@ -73,7 +73,6 @@ FILE *fopen (const char *, const char *); FILE *fdopen (int, const char *); FILE *freopen (const char *, const char *, FILE *); FILE *popen (const char *, const char *); -FILE *tmpfile (void); int fclose (FILE *); long ftell (FILE *); int fflush (FILE *); @@ -94,8 +93,6 @@ int setvbuf (FILE *, char *, int, size_t); int fseek (FILE *, long, int); void rewind (FILE *); int remove (const char *); -int getw(FILE *stream); -int putw(int w, FILE *stream); size_t fread (void *, size_t, size_t, FILE *); size_t fwrite (const void *, size_t, size_t, FILE *); @@ -110,12 +107,7 @@ int scanf (const char *, ...); int sscanf (const char *, const char *, ...); #ifndef _VA_LIST_ -# ifdef __GNUC__ -# define va_list __builtin_va_list /* For Gnu C */ -# endif -# ifdef __SMALLER_C__ -# define va_list char * /* For Smaller C */ -# endif +#define va_list __builtin_va_list /* For GCC */ #endif int vfprintf (FILE *, const char *, va_list); @@ -131,7 +123,7 @@ int _doprnt (const char *, va_list, FILE *); int _doscan (FILE *, const char *, va_list); #ifndef _VA_LIST_ -# undef va_list +#undef va_list #endif void perror (const char *); diff --git a/include/stdlib.h b/include/stdlib.h index eee38c7..b9c0285 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -54,51 +54,48 @@ #define RAND_MAX 0x7fff -void abort (void); +void abort(); int abs (int); int atexit (void (*)(void)); -int atoi (const char *); -long atol (const char *); +double atof(); +int atoi(); +long atol(); void *calloc (size_t, size_t); void exit (int); void free (void *); -char *getenv (const char *); -long labs (long); +char *getenv(); void *malloc (size_t); char *mktemp (char *); int mkstemp (char *); -void qsort (void *, size_t, size_t, int (*)(const void *, const void *)); -int rand (void); +void qsort(); +int rand(); void *realloc (void*, size_t); -void srand (unsigned); -long strtol (const char *, char **, int); -unsigned long strtoul (const char *, char **, int); -int system (const char *); +void srand(); +double strtod(); +long strtol(); +unsigned long strtoul(); +int system(); int putenv (char *string); int setenv (const char *name, const char *value, int overwrite); int unsetenv (const char *name); char *_findenv (const char *name, int *offset); -void *alloca (size_t size); +void *alloca(); -int daemon (int, int); -char *devname (dev_t dev, mode_t type); -int getloadavg (unsigned loadavg[], int nelem); +int daemon(); +char *devname(); +int getloadavg(unsigned loadavg[], int nelem); extern char *suboptarg; /* getsubopt(3) external variable */ -int getsubopt (char **, char **, char **); +int getsubopt(); long random (void); char *setstate (char *); void srandom (unsigned); -#ifndef __SMALLER_C__ -double atof (const char *); -double strtod (const char *, char **); -char *ecvt (double, int, int *, int *); -char *fcvt (double, int, int *, int *); -char *gcvt (double, int, char *); -#endif +char *ecvt (double, int, int *, int *); +char *fcvt (double, int, int *, int *); +char *gcvt (double, int, char *); #endif /* _STDLIB_H_ */ diff --git a/include/string.h b/include/string.h index 088eceb..b1c0b0f 100644 --- a/include/string.h +++ b/include/string.h @@ -39,5 +39,5 @@ char *strtok_r (char *, const char *, char **); size_t strcspn (const char *, const char *); size_t strspn (const char *, const char *); -char *strerror (int); +const char *strerror (int); const char *syserrlst (int); diff --git a/include/strings.h b/include/strings.h index 66c429c..2e0445d 100644 --- a/include/strings.h +++ b/include/strings.h @@ -34,7 +34,7 @@ int bcmp(const void *, const void *, size_t); void bcopy(const void *, void *, size_t); -void bzero(void *, unsigned long); +void bzero(void *, size_t); int ffs(int); char *index(const char *, int); char *rindex(const char *, int); diff --git a/include/syscall.h b/include/syscall.h index 49f8262..8f625ea 100644 --- a/include/syscall.h +++ b/include/syscall.h @@ -59,7 +59,7 @@ #define SYS_getegid 48 #define SYS_setgid 49 #define SYS_setegid 50 -#define SYS_kmemdev 51 + /* 51 is old; acct */ #define SYS_phys 52 #define SYS_lock 53 #define SYS_ioctl 54 @@ -81,7 +81,7 @@ #define SYS_rdglob 70 #define SYS_wrglob 71 /* 71 is unused 4.3: mmap */ -#define SYS_msec 72 /* 72 is unused 4.3: vadvise */ + /* 72 is unused 4.3: vadvise */ /* 73 is unused 4.3: munmap */ /* 74 is unused 4.3: mprotect */ /* 75 is unused 4.3: madvise */ diff --git a/include/term.h b/include/term.h index bc1865e..599affe 100644 --- a/include/term.h +++ b/include/term.h @@ -2,9 +2,13 @@ #define _TERM_H extern int tgetent(char *, char *); +extern int tnchktc(); +extern int tnamatch(char *); +extern char *tskip(register char *); extern int tgetnum(char *); extern int tgetflag(char *); extern char *tgetstr(char *, char **); +extern char *tdecode(register char *, char **); extern char *tgoto(char *, int, int); extern int tputs(register char *, int, int (*)()); diff --git a/include/ttyent.h b/include/ttyent.h index 3e70681..4886710 100644 --- a/include/ttyent.h +++ b/include/ttyent.h @@ -18,5 +18,5 @@ struct ttyent { /* see getttyent(3) */ struct ttyent *getttyent (void); struct ttyent *getttynam (const char *name); -void setttyent (void); -void endttyent (void); +int setttyent (void); +int endttyent (void); diff --git a/include/tzfile.h b/include/tzfile.h index 8b4c60a..3442190 100644 --- a/include/tzfile.h +++ b/include/tzfile.h @@ -97,4 +97,4 @@ struct tzhead { ** that will probably do. */ -#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0) +#define isleap(y) (((y) % 4) == 0 && ((y) % 100) != 0 || ((y) % 400) == 0) diff --git a/include/unistd.h b/include/unistd.h index 0ff1ed1..cd018c5 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -94,7 +94,6 @@ void setusershell(); void sync(); unsigned int ualarm(); void usleep(); -int pause (void); pid_t vfork(); int pipe (int pipefd[2]); @@ -108,18 +107,11 @@ int chown (const char *path, uid_t owner, gid_t group); int nice (int inc); int setuid (uid_t uid); int setgid (gid_t gid); -int seteuid (uid_t euid); -int setegid (gid_t egid); -int setreuid (uid_t ruid, uid_t euid); -int setregid (gid_t rgid, gid_t egid); int isatty (int fd); int chdir (const char *path); int fchdir (int fd); int chflags (const char *path, u_long flags); int fchflags (int fd, u_long flags); -int getgroups (int size, gid_t list[]); -int getdtablesize (void); -int rmdir (const char *pathname); struct stat; int stat (const char *path, struct stat *buf); @@ -143,12 +135,7 @@ extern char *optarg; /* getopt(3) external variables */ extern int opterr, optind, optopt; #ifndef _VA_LIST_ -# ifdef __GNUC__ -# define va_list __builtin_va_list /* For Gnu C */ -# endif -# ifdef __SMALLER_C__ -# define va_list char * /* For Smaller C */ -# endif +#define va_list __builtin_va_list /* For GCC */ #endif void err (int eval, const char *fmt, ...); @@ -161,6 +148,6 @@ void vwarn (const char *fmt, va_list ap); void vwarnx (const char *fmt, va_list ap); #ifndef _VA_LIST_ -# undef va_list +#undef va_list #endif #endif /* !_UNISTD_H_ */ diff --git a/include/wiznet/socket.h b/include/wiznet/socket.h index 67ddd37..ed692d1 100644 --- a/include/wiznet/socket.h +++ b/include/wiznet/socket.h @@ -3,7 +3,7 @@ #include "w5100.h" -extern unsigned _socket_port [MAX_SOCK_NUM]; +extern uint16_t _socket_port [MAX_SOCK_NUM]; /* * Opens a socket(TCP or UDP or IP_RAW mode) diff --git a/include/wiznet/udp.h b/include/wiznet/udp.h index 0988339..b7bff03 100644 --- a/include/wiznet/udp.h +++ b/include/wiznet/udp.h @@ -62,13 +62,13 @@ void udp_stop (udp_t *u); /* * Send a packet to specified peer. */ -unsigned udp_send_packet (udp_t *u, const uint8_t *data, unsigned len, +uint16_t udp_send_packet (udp_t *u, const uint8_t *data, unsigned len, uint8_t *ip, unsigned port); /* * Send a zero-terminated string to specified peer. */ -unsigned udp_send_string (udp_t *u, const char *data, +uint16_t udp_send_string (udp_t *u, const char *data, uint8_t *ip, unsigned port); /* diff --git a/lib/.gitignore b/lib/.gitignore deleted file mode 100644 index f9deb05..0000000 --- a/lib/.gitignore +++ /dev/null @@ -1,14 +0,0 @@ -a.out.h -aout -ar -ar.h -as -ld -nlist.h -nm -ranlib -ranlib.h -retroImage -size -strip -gccdump.s diff --git a/lib/Makefile b/lib/Makefile deleted file mode 100644 index 49e6364..0000000 --- a/lib/Makefile +++ /dev/null @@ -1,66 +0,0 @@ -TOPSRC = $(shell cd ..; pwd) -SUBDIR = startup libc libcurses libtermlib libwiznet -PROG = ar as aout ld nm ranlib size strip - -# Build a list of the host include directories. -CPP = $(shell gcc -print-prog-name=cc1) -HOSTINC = $(addprefix -I,$(shell echo | $(CPP) -v 2>&1 | grep '^ /.*include')) - -# Add system include path -ifeq (,$(wildcard /usr/include/i386-linux-gnu)) - HOSTINC += -I/usr/include -else - HOSTINC += -I/usr/include/i386-linux-gnu -endif - -CFLAGS += -nostdinc -fno-builtin -g -Werror -Wall -DCROSS -I. $(HOSTINC) \ - -I$(TOPSRC)/include -I$(TOPSRC)/src/cmd/ar \ - -I$(TOPSRC)/src/cmd/as -LDFLAGS += -g - -AR_OBJS = ar.o append.o archive.o contents.o delete.o extract.o \ - misc.o move.o print.o replace.o strmode.o -AOUT_OBJS = aout.o mips-dis.o -RANLIB_OBJS = ranlib.o archive.o -HEADERS = a.out.h ar.h nlist.h ranlib.h - -vpath %.c $(TOPSRC)/src/cmd/aout $(TOPSRC)/src/cmd/ar $(TOPSRC)/src/cmd/as \ - $(TOPSRC)/src/cmd/ld $(TOPSRC)/src/cmd/nm $(TOPSRC)/src/cmd/ranlib \ - $(TOPSRC)/src/cmd - -all install depend: $(HEADERS) $(SUBDIR) $(PROG) - -for i in $(SUBDIR); do $(MAKE) -C $$i $(MFLAGS) DESTDIR=$(DESTDIR) $@; done - -clean: - rm -f *~ *.o *.a *.h $(PROG) retroImage gccdump.s - for i in $(SUBDIR); do $(MAKE) -C $$i $(MFLAGS) clean; done - -ar: $(AR_OBJS) - $(CC) $(LDFLAGS) -o $@ $(AR_OBJS) $(LIBS) - -as: as.o - $(CC) $(LDFLAGS) -o $@ $< $(LIBS) - -aout: $(AOUT_OBJS) - $(CC) $(LDFLAGS) -o $@ $(AOUT_OBJS) $(LIBS) - -ld: ld.o - $(CC) $(LDFLAGS) -o $@ $< $(LIBS) - -nm: nm.o - $(CC) $(LDFLAGS) -o $@ $< $(LIBS) - -ranlib: $(RANLIB_OBJS) - $(CC) $(LDFLAGS) -o $@ $(RANLIB_OBJS) $(LIBS) - -size: size.o - $(CC) $(LDFLAGS) -o $@ $< $(LIBS) - -strip: strip.o - $(CC) $(LDFLAGS) -o $@ $< $(LIBS) - -$(HEADERS): - -ln -s -f ../include/a.out.h . - -ln -s -f ../include/ar.h . - -ln -s -f ../include/nlist.h . - -ln -s -f ../include/ranlib.h . diff --git a/lib/libc/Makefile b/lib/libc/Makefile deleted file mode 100644 index d01b709..0000000 --- a/lib/libc/Makefile +++ /dev/null @@ -1,111 +0,0 @@ -TOPSRC = $(shell cd ../..; pwd) -include $(TOPSRC)/target.mk - -LIBCDIR = $(TOPSRC)/src/libc -vpath %.S $(LIBCDIR)/mips/sys $(LIBCDIR)/mips/string $(LIBCDIR)/mips/gen \ - $(LIBCDIR)/runtime -vpath %.c $(LIBCDIR)/mips/sys $(LIBCDIR)/gen $(LIBCDIR)/stdio \ - $(LIBCDIR)/stdlib $(LIBCDIR)/string $(LIBCDIR)/inet \ - $(LIBCDIR)/compat $(LIBCDIR)/runtime - -CFLAGS += -B$(TOPSRC)/lib/ $(DEFS) -Wa,-x -Wall -Werror -ASFLAGS += -B$(TOPSRC)/lib/ $(DEFS) -Wa,-x -I$(LIBCDIR)/mips/sys - -# modules which can not use SYSCALL and must be assembled from sources. The -# rest of the system calls are generated with printf(1) and do not have -# source files associated with them. - -# libc/mips/sys -SYSOBJS = __sysctl.o accept.o access.o adjtime.o bind.o chdir.o \ - chflags.o chmod.o chown.o chroot.o close.o connect.o dup.o \ - dup2.o execve.o fchdir.o fchflags.o fchmod.o fchown.o \ - fcntl.o flock.o fork.o fstat.o fsync.o ftruncate.o \ - getdtablesize.o getgroups.o getitimer.o getsockname.o \ - getpeername.o getpriority.o getrlimit.o getrusage.o \ - getsockopt.o gettimeofday.o ioctl.o kill.o killpg.o link.o \ - listen.o lstat.o mkdir.o mknod.o mount.o open.o pselect.o \ - quota.o read.o readlink.o readv.o reboot.o recv.o \ - recvfrom.o recvmsg.o rename.o rmdir.o select.o send.o \ - sendmsg.o sendto.o setgroups.o setitimer.o setpgrp.o \ - setpriority.o setquota.o setuid.o seteuid.o setgid.o \ - setegid.o setrlimit.o setsockopt.o settimeofday.o \ - shutdown.o sigaltstack.o socket.o socketpair.o stat.o \ - symlink.o sigprocmask.o sigstack.o sigwait.o statfs.o \ - fstatfs.o getfsstat.o truncate.o umount.o unlink.o \ - utimes.o wait4.o write.o writev.o lseek.o sigsuspend.o \ - getgid.o getegid.o getpgrp.o getpid.o getppid.o getuid.o \ - geteuid.o profil.o sigpending.o sync.o ufetch.o ustore.o \ - ucall.o umask.o vfork.o vhangup.o rdglob.o wrglob.o - -OBJS = $(SYSOBJS) sbrk.o execl.o execle.o execv.o \ - _exit.o _brk.o pipe.o ptrace.o sigaction.o - -# libc/mips/string -ASFLAGS += -DLWHI=lwr -DLWLO=lwl -DSWHI=swr -DSWLO=swl -OBJS += bcopy.o bzero.o ffs.o memcpy.o memmove.o memset.o \ - strlen.o bcmp.o index.o rindex.o strcmp.o - -# libc/mips/gen -OBJS += _setjmp.o htonl.o htons.o - -# libc/gen -OBJS += abort.o alarm.o atof.o atoi.o atol.o calloc.o closedir.o crypt.o \ - ctime.o ctype_.o daemon.o devname.o ecvt.o err.o \ - execvp.o fakcu.o frexp.o fstab.o gcvt.o getenv.o getgrent.o \ - getgrgid.o getgrnam.o getlogin.o \ - getgrouplist.o gethostname.o getpagesize.o \ - getpass.o getpwent.o getloadavg.o getmntinfo.o \ - getttyent.o getttynam.o getusershell.o getwd.o \ - initgroups.o isatty.o isinff.o isnanf.o ldexp.o malloc.o mktemp.o \ - modff.o ndbm.o nlist.o knlist.o opendir.o perror.o popen.o \ - psignal.o qsort.o random.o readdir.o regex.o scandir.o \ - seekdir.o setmode.o sethostname.o setenv.o siglist.o \ - signal.o siginterrupt.o sigsetops.o \ - sleep.o strcasecmp.o strftime.o swab.o sysctl.o syslog.o system.o \ - strcat.o strncat.o strcpy.o strncpy.o strncmp.o \ - telldir.o time.o timezone.o ttyname.o ttyslot.o ualarm.o usleep.o \ - strdup.o uname.o wait.o wait3.o waitpid.o - -# libc/stdio -OBJS += fgetc.o fgets.o fputc.o fputs.o gets.o puts.o \ - clrerr.o doscan.o exit.o fdopen.o filbuf.o findiop.o \ - flsbuf.o fopen.o fprintf.o fread.o freopen.o fseek.o \ - ftell.o fwrite.o getchar.o getw.o printf.o putchar.o putw.o \ - rew.o scanf.o setbuf.o setbuffer.o setvbuf.o snprintf.o sprintf.o \ - strout.o ungetc.o vfprintf.o vprintf.o vsprintf.o doprnt.o \ - remove.o feof.o ferror.o fileno.o - -# libc/stdlib -OBJS += getopt.o getsubopt.o strtol.o strtoul.o strtod.o - -# libc/string -OBJS += strcspn.o strpbrk.o strerror.o strsep.o strspn.o \ - strstr.o strtok.o strtok_r.o - -# libc/inet -OBJS += inet_addr.o inet_network.o inet_netof.o \ - inet_ntoa.o inet_lnaof.o inet_maddr.o - -# libc/compat -OBJS += creat.o ftime.o gethostid.o gtty.o memccpy.o memchr.o \ - memcmp.o memcpy.o memset.o nice.o pause.o rand.o \ - sethostid.o setregid.o setreuid.o setrgid.o setruid.o \ - sigcompat.o strchr.o strrchr.o stty.o times.o tmpnam.o \ - utime.o - -# libc/runtime -OBJS += addsf3.o comparesf2.o divsf3.o fixsfsi.o floatsisf.o \ - mulsf3.o negsf2.o subsf3.o sc_case.o - -all: ../libc.a - -../libc.a: ../ar ../ranlib $(OBJS) - ../ar rc $@ $(OBJS) - ../ranlib $@ - -$(SYSOBJS): $(LIBCDIR)/mips/sys/SYS.h - @echo creating $*.o - @printf '#include "SYS.h"\nSYS($*)\n' | $(AS) $(ASFLAGS) - -c -o $*.o - -clean: - rm -f *~ *.o a.out *.a diff --git a/lib/libcurses/Makefile b/lib/libcurses/Makefile deleted file mode 100644 index b2fde22..0000000 --- a/lib/libcurses/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -TOPSRC = $(shell cd ../..; pwd) -include $(TOPSRC)/target.mk - -vpath %.c $(TOPSRC)/src/libcurses - -CFLAGS += -B$(TOPSRC)/lib/ $(DEFS) -Wa,-x -Wall -Werror - -OBJS = addch.o addstr.o box.o clear.o clrtobot.o clrtoeol.o cr_put.o \ - cr_tty.o curses.o delch.o deleteln.o delwin.o endwin.o erase.o \ - fullname.o getch.o getstr.o idlok.o id_subwins.o initscr.o insch.o \ - insertln.o longname.o move.o mvprintw.o mvscanw.o mvwin.o newwin.o \ - overlay.o overwrite.o printw.o putchar.o refresh.o scanw.o scroll.o \ - toucholap.o standout.o touchwin.o tstp.o unctrl.o - -all: ../libcurses.a - -../libcurses.a: ../ar ../ranlib $(OBJS) - ../ar rc $@ $(OBJS) - ../ranlib $@ - -clean: - rm -f *~ *.o a.out *.a diff --git a/lib/libtermlib/Makefile b/lib/libtermlib/Makefile deleted file mode 100644 index 2b3fb1a..0000000 --- a/lib/libtermlib/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -TOPSRC = $(shell cd ../..; pwd) -include $(TOPSRC)/target.mk - -vpath %.c $(TOPSRC)/src/libtermlib - -CFLAGS += -B$(TOPSRC)/lib/ $(DEFS) -Wa,-x -Wall -Werror - -OBJS = termcap.o tgoto.o tputs.o tcattr.o - -all: ../libtermlib.a - -../libtermlib.a: ../ar ../ranlib $(OBJS) - ../ar rc $@ $(OBJS) - ../ranlib $@ - -clean: - rm -f *~ *.o a.out *.a diff --git a/lib/libwiznet/Makefile b/lib/libwiznet/Makefile deleted file mode 100644 index d7883bc..0000000 --- a/lib/libwiznet/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -TOPSRC = $(shell cd ../..; pwd) -include $(TOPSRC)/target.mk - -vpath %.c $(TOPSRC)/src/libwiznet - -CFLAGS += -B$(TOPSRC)/lib/ $(DEFS) -Wa,-x -Wall -Werror - -OBJS = w5100.o socket.o ethernet.o client.o server.o udp.o - -all: ../libwiznet.a - -../libwiznet.a: ../ar ../ranlib $(OBJS) - ../ar rc $@ $(OBJS) - ../ranlib $@ - -clean: - rm -f *~ *.o a.out *.a diff --git a/lib/startup/Makefile b/lib/startup/Makefile deleted file mode 100644 index a4e47a6..0000000 --- a/lib/startup/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -# -# Copyright (c) 1987 Regents of the University of California. -# All rights reserved. The Berkeley software License Agreement -# specifies the terms and conditions for redistribution. -# -# crt0 Normal C run time startoff -# -TOPSRC = $(shell cd ../..; pwd) -include $(TOPSRC)/target.mk -vpath %.c $(TOPSRC)/src/startup-mips - -CFLAGS = -B$(TOPSRC)/lib/ -O -Wa,-x $(DEFS) - -OBJS = ../crt0.o - -all: $(OBJS) - -../crt0.o: crt0.c - $(CC) $(DEFS) $(CFLAGS) -c $< -o $@ - -clean: - rm -f $(OBJS) *~ diff --git a/libexec/.gitignore b/libexec/.gitignore deleted file mode 100644 index 72e8ffc..0000000 --- a/libexec/.gitignore +++ /dev/null @@ -1 +0,0 @@ -* diff --git a/rootfs.manifest b/rootfs.manifest deleted file mode 100644 index f3356d0..0000000 --- a/rootfs.manifest +++ /dev/null @@ -1,862 +0,0 @@ -# -# Manifest file for RetroBSD root filesystem. -# -default -owner 0 -group 0 -dirmode 0775 -filemode 0664 - -# -# Directories. -# -dir /bin -dir /dev -dir /etc -dir /lib -dir /libexec -dir /sbin -dir /tmp -dir /u - -# -# Character devices. -# -cdev /dev/console -major 0 -minor 0 -cdev /dev/mem -major 1 -minor 0 -cdev /dev/kmem -major 1 -minor 1 -cdev /dev/null -major 1 -minor 2 -mode 666 -cdev /dev/zero -major 1 -minor 3 -mode 666 -cdev /dev/tty -major 2 -minor 0 -mode 666 -cdev /dev/stdin -major 3 -minor 0 -cdev /dev/stdout -major 3 -minor 1 -cdev /dev/stderr -major 3 -minor 2 -cdev /dev/temp0 -major 4 -minor 0 -cdev /dev/temp1 -major 4 -minor 1 -cdev /dev/temp2 -major 4 -minor 2 - -# -# Block devices. -# -bdev /dev/rd0 -major 0 -minor 0 -bdev /dev/rd0a -major 0 -minor 1 -bdev /dev/rd0b -major 0 -minor 2 -bdev /dev/rd0c -major 0 -minor 3 -bdev /dev/rd0d -major 0 -minor 4 -bdev /dev/rd1 -major 1 -minor 0 -bdev /dev/rd1a -major 1 -minor 1 -bdev /dev/rd1b -major 1 -minor 2 -bdev /dev/rd1c -major 1 -minor 3 -bdev /dev/rd1d -major 1 -minor 4 -bdev /dev/rd2 -major 2 -minor 0 -bdev /dev/rd2a -major 2 -minor 1 -bdev /dev/rd2b -major 2 -minor 2 -bdev /dev/rd2c -major 2 -minor 3 -bdev /dev/rd2d -major 2 -minor 4 -bdev /dev/rd3 -major 3 -minor 0 -bdev /dev/rd3a -major 3 -minor 1 -bdev /dev/rd3b -major 3 -minor 2 -bdev /dev/rd3c -major 3 -minor 3 -bdev /dev/rd3d -major 3 -minor 4 -bdev /dev/swap -major 4 -minor 64 -bdev /dev/swap0 -major 4 -minor 0 -bdev /dev/swap1 -major 4 -minor 1 -bdev /dev/swap2 -major 4 -minor 2 - -# -# Files: / -# -file /.profile - -# -# Files: /etc -# -file /etc/fstab -file /etc/gettytab -file /etc/group -file /etc/MAKEDEV -mode 0775 -file /etc/motd -file /etc/passwd -file /etc/phones -file /etc/rc -mode 0775 -file /etc/rc.local -mode 0775 -file /etc/remote -file /etc/shadow -file /etc/shells -file /etc/termcap -mode 0444 -file /etc/ttys - -# -# Files: /bin -# -default -filemode 0775 -file /bin/adb -file /bin/adc-demo -file /bin/aout -file /bin/apropos -file /bin/ar -file /bin/as -file /bin/awk -file /bin/basename -file /bin/basic -file /bin/bc -file /bin/cal -file /bin/cat -file /bin/cb -file /bin/cc -file /bin/chat-server -file /bin/chflags -file /bin/chgrp -file /bin/chmod -file /bin/chpass -mode 04755 -file /bin/cmp -file /bin/col -file /bin/comm -file /bin/compress -file /bin/cp -file /bin/cpp -file /bin/crontab -file /bin/date -file /bin/dc -file /bin/dd -file /bin/df -mode 02755 -file /bin/diff -file /bin/diskspeed -file /bin/du -file /bin/echo -file /bin/ed -file /bin/egrep -file /bin/emg -file /bin/env -file /bin/expr -file /bin/false -file /bin/fgrep -file /bin/file -file /bin/find -file /bin/forth -file /bin/fstat -mode 02755 -file /bin/glcdtest -file /bin/globdump -file /bin/globread -file /bin/globwrite -file /bin/grep -file /bin/groups -file /bin/head -file /bin/hostid -file /bin/hostname -file /bin/id -file /bin/iostat -mode 02755 -file /bin/join -file /bin/kill -file /bin/la -file /bin/last -file /bin/lcc -file /bin/lcpp -file /bin/ld -file /bin/ln -file /bin/login -mode 04755 -file /bin/lol -file /bin/ls -file /bin/mail -mode 04755 -file /bin/make -file /bin/man -file /bin/med -file /bin/mesg -file /bin/mkdir -file /bin/more -file /bin/msec -file /bin/mv -file /bin/nice -file /bin/nm -file /bin/nohup -file /bin/ntpdate -file /bin/od -file /bin/pagesize -file /bin/passwd -mode 04755 -file /bin/picoc -file /bin/portio -file /bin/pr -file /bin/printenv -file /bin/printf -file /bin/ps -mode 02755 -file /bin/pwd -file /bin/pwm -file /bin/ranlib -file /bin/re -file /bin/renice -file /bin/renumber -file /bin/retroforth -file /bin/rev -file /bin/rm -file /bin/rmail -file /bin/rmdir -file /bin/rz -file /bin/scc -file /bin/scm -file /bin/sed -file /bin/setty -file /bin/sh -file /bin/size -file /bin/sl -file /bin/sleep -file /bin/smux -file /bin/sort -file /bin/split -file /bin/strip -file /bin/stty -file /bin/su -mode 04755 -file /bin/sum -file /bin/sync -file /bin/sysctl -file /bin/sz -file /bin/tail -file /bin/tar -file /bin/tee -file /bin/telnet -file /bin/test -file /bin/time -file /bin/tip -file /bin/touch -file /bin/tr -file /bin/true -file /bin/tsort -file /bin/tty -file /bin/uname -file /bin/uncompress -file /bin/uniq -file /bin/uucico -file /bin/uuclean -file /bin/uucp -file /bin/uudecode -file /bin/uuencode -file /bin/uulog -file /bin/uuname -file /bin/uupoll -file /bin/uuq -file /bin/uusend -file /bin/uusnap -file /bin/uux -file /bin/uuxqt -file /bin/vi -file /bin/vmstat -mode 02755 -file /bin/w -file /bin/wall -mode 02755 -file /bin/wc -file /bin/web-client -file /bin/web-server -file /bin/whereis -file /bin/who -file /bin/whoami -file /bin/write -mode 02755 -file /bin/xargs -file /bin/zcat - -link /bin/[ -target /bin/test - -link /bin/whatis -target /bin/apropos - -link /bin/chfn -target /bin/chpass -link /bin/chsh -target /bin/chpass - -link /bin/rb -target /bin/rz -link /bin/rx -target /bin/rz - -link /bin/sb -target /bin/sz -link /bin/sx -target /bin/sz - -# -# Files: /sbin -# -file /sbin/chown -file /sbin/chroot -mode 04755 -file /sbin/cron -file /sbin/devupdate -file /sbin/disktool -file /sbin/fdisk -file /sbin/fsck -file /sbin/init -mode 0700 -file /sbin/mkfs -file /sbin/mknod -file /sbin/mkpasswd -file /sbin/mount -file /sbin/pstat -mode 02755 -file /sbin/rdprof -file /sbin/reboot -file /sbin/shutdown -mode 04750 -file /sbin/talloc -file /sbin/umount -file /sbin/update -file /sbin/updatedb -file /sbin/vipw - -link /sbin/bootloader -target /sbin/reboot -link /sbin/fastboot -target /sbin/reboot -link /sbin/halt -target /sbin/reboot -link /sbin/poweroff -target /sbin/reboot - -# -# Files: /games -# -default -filemode 0775 -dir /games -file /games/adventure -file /games/arithmetic -file /games/atc -file /games/backgammon -file /games/banner -file /games/battlestar -file /games/bcd -file /games/boggle -file /games/btlgammon -file /games/canfield -file /games/cfscores -file /games/cribbage -file /games/factor -file /games/fish -file /games/fortune -file /games/hangman -file /games/mille -file /games/monop -file /games/morse -file /games/number -file /games/ppt -file /games/primes -file /games/quiz -file /games/rain -file /games/robots -file /games/rogue -file /games/sail -file /games/snake -file /games/snscore -file /games/teachgammon -file /games/trek -file /games/worm -file /games/worms -file /games/wump - -# -# Files: /games/lib -# -default -filemode 0444 -dir /games/lib -file /games/lib/adventure.dat -file /games/lib/battle_strings -file /games/lib/backrules -file /games/lib/bogdict -file /games/lib/cfscores -file /games/lib/crib.instr -mode 0666 -file /games/lib/fortunes.dat -file /games/lib/cards.pck -file /games/lib/robots_roll -mode 0666 -file /games/lib/snakerawscores -mode 0666 -dir /games/lib/atc -file /games/lib/atc/ATC_scores -file /games/lib/atc/crossover -file /games/lib/atc/default -file /games/lib/atc/easy -file /games/lib/atc/game_2 -file /games/lib/atc/Game_List -file /games/lib/atc/Killer -dir /games/lib/quiz.k -file /games/lib/quiz.k/africa -file /games/lib/quiz.k/america -file /games/lib/quiz.k/areas -file /games/lib/quiz.k/arith -file /games/lib/quiz.k/asia -file /games/lib/quiz.k/babies -file /games/lib/quiz.k/bard -file /games/lib/quiz.k/chinese -file /games/lib/quiz.k/collectives -file /games/lib/quiz.k/ed -file /games/lib/quiz.k/elements -file /games/lib/quiz.k/europe -file /games/lib/quiz.k/greek -file /games/lib/quiz.k/inca -file /games/lib/quiz.k/index -file /games/lib/quiz.k/latin -file /games/lib/quiz.k/locomotive -file /games/lib/quiz.k/midearth -file /games/lib/quiz.k/morse -file /games/lib/quiz.k/murders -file /games/lib/quiz.k/poetry -file /games/lib/quiz.k/posneg -file /games/lib/quiz.k/pres -file /games/lib/quiz.k/province -file /games/lib/quiz.k/seq-easy -file /games/lib/quiz.k/seq-hard -file /games/lib/quiz.k/sexes -file /games/lib/quiz.k/sov -file /games/lib/quiz.k/spell -file /games/lib/quiz.k/state -file /games/lib/quiz.k/trek -file /games/lib/quiz.k/ucc - -# -# Files: /include -# -default -filemode 0664 -dir /include -dir /include/arpa -dir /include/machine -dir /include/smallc -dir /include/smallc/sys -dir /include/sys -file /include/alloca.h -file /include/a.out.h -file /include/ar.h -file /include/arpa/inet.h -file /include/assert.h -file /include/ctype.h -file /include/curses.h -file /include/dbm.h -file /include/fcntl.h -file /include/float.h -file /include/fstab.h -file /include/grp.h -file /include/kmem.h -file /include/lastlog.h -file /include/limits.h -file /include/machine/cpu.h -file /include/machine/elf_machdep.h -file /include/machine/float.h -file /include/machine/io.h -file /include/machine/limits.h -file /include/machine/machparam.h -file /include/machine/pic32mx.h -file /include/machine/rd_sdramp_config.h -file /include/machine/sdram.h -file /include/machine/ssd1926.h -file /include/machine/usb_ch9.h -file /include/machine/usb_device.h -file /include/machine/usb_function_cdc.h -file /include/machine/usb_function_hid.h -file /include/machine/usb_hal_pic32.h -file /include/math.h -file /include/mtab.h -file /include/ndbm.h -file /include/nlist.h -file /include/paths.h -file /include/pcc.h -file /include/psout.h -file /include/pwd.h -file /include/ranlib.h -file /include/regexp.h -file /include/setjmp.h -file /include/sgtty.h -file /include/smallc/curses.h -file /include/smallc/fcntl.h -file /include/smallc/signal.h -file /include/smallc/stdio.h -file /include/smallc/sys/gpio.h -file /include/smallc/sys/spi.h -file /include/smallc/wiznet.h -file /include/stab.h -file /include/stdarg.h -file /include/stddef.h -file /include/stdint.h -file /include/stdio.h -file /include/stdlib.h -file /include/string.h -file /include/strings.h -file /include/struct.h -file /include/sys/adc.h -file /include/sys/buf.h -file /include/syscall.h -file /include/sys/callout.h -file /include/sys/clist.h -file /include/sys/conf.h -file /include/sys/debug.h -file /include/sys/dir.h -file /include/sys/disk.h -file /include/sys/dkbad.h -file /include/sys/dk.h -file /include/sys/errno.h -file /include/sys/exec_aout.h -file /include/sys/exec_elf.h -file /include/sys/exec.h -file /include/sysexits.h -file /include/sys/fcntl.h -file /include/sys/file.h -file /include/sys/fs.h -file /include/sys/glcd.h -file /include/sys/glob.h -file /include/sys/gpio.h -file /include/sys/inode.h -file /include/sys/ioctl.h -file /include/sys/kernel.h -file /include/sys/map.h -file /include/sys/mount.h -file /include/sys/msgbuf.h -file /include/sys/mtio.h -file /include/sys/namei.h -file /include/sys/oc.h -file /include/sys/param.h -file /include/sys/picga.h -file /include/sys/proc.h -file /include/sys/ptrace.h -file /include/sys/pty.h -file /include/sys/rd_flash.h -file /include/sys/rdisk.h -file /include/sys/rd_mrams.h -file /include/sys/rd_sdramp.h -file /include/sys/rd_sramc.h -file /include/sys/reboot.h -file /include/sys/resource.h -file /include/sys/select.h -file /include/sys/signal.h -file /include/sys/signalvar.h -file /include/sys/spi_bus.h -file /include/sys/spi.h -file /include/sys/stat.h -file /include/sys/swap.h -file /include/sys/sysctl.h -file /include/sys/syslog.h -file /include/sys/systm.h -file /include/sys/time.h -file /include/sys/times.h -file /include/sys/trace.h -file /include/sys/ttychars.h -file /include/sys/ttydev.h -file /include/sys/tty.h -file /include/sys/types.h -file /include/sys/uart.h -file /include/sys/uio.h -file /include/sys/usb_uart.h -file /include/sys/user.h -file /include/sys/utsname.h -file /include/sys/vm.h -file /include/sys/vmmac.h -file /include/sys/vmmeter.h -file /include/sys/vmparam.h -file /include/sys/vmsystm.h -file /include/sys/wait.h -file /include/term.h -file /include/termios-todo.h -file /include/time.h -file /include/ttyent.h -file /include/tzfile.h -file /include/unistd.h -file /include/utmp.h -file /include/vmf.h - -symlink /include/errno.h -target sys/errno.h - -symlink /include/signal.h -target sys/signal.h - -symlink /include/syslog.h -target sys/syslog.h - -# -# Files: /lib -# -file /lib/crt0.o -file /lib/libc.a -file /lib/libcurses.a -file /lib/libtermlib.a -file /lib/libwiznet.a -file /lib/retroImage - -# -# Files: /libexec -# -default -filemode 0775 -file /libexec/bigram -file /libexec/code -file /libexec/diffh -file /libexec/getty -file /libexec/smallc -file /libexec/smlrc - -# -# Files: /share -# -default -filemode 0444 -dir /share -dir /share/dict -dir /share/misc -file /share/emg.keys -file /share/re.help -file /share/dict/words -file /share/misc/more.help - -# -# Files: /share/example -# -default -filemode 0664 -dir /share/example -file /share/example/ashello.S -file /share/example/blkjack.bas -file /share/example/chello.c -file /share/example/echo.S -file /share/example/fact.fth -file /share/example/hilow.bas -file /share/example/Makefile -file /share/example/prime.scm -file /share/example/skeleton.c -file /share/example/stars.bas -file /share/example/stdarg.c - -# -# Files: /share/smallc -# -dir /share/smallc -file /share/smallc/adc.c -file /share/smallc/gpio.c -file /share/smallc/hello.c -file /share/smallc/Makefile -file /share/smallc/primelist.c -file /share/smallc/primesum.c -file /share/smallc/q8.c -file /share/smallc/rain.c -file /share/smallc/test1.c -file /share/smallc/test2.c -file /share/smallc/test3.c -file /share/smallc/webserver.c - -# -# Files: /share/smallerc -# -dir /share/smallerc -file /share/smallerc/adc.c -file /share/smallerc/gpio.c -file /share/smallerc/hello.c -file /share/smallerc/Makefile -file /share/smallerc/primelist.c -file /share/smallerc/primesum.c -file /share/smallerc/q8.c -file /share/smallerc/rain.c -file /share/smallerc/test1.c -file /share/smallerc/test2.c -file /share/smallerc/test3.c - -# -# Files: /var -# -dir /var -dir /var/lock -dir /var/log -dir /var/run -file /var/log/messages -file /var/log/wtmp - -# -# Files: /share/man -# -dir /share/man -dir /share/man/cat1 -dir /share/man/cat2 -dir /share/man/cat3 -dir /share/man/cat4 -dir /share/man/cat5 -dir /share/man/cat6 -dir /share/man/cat7 -dir /share/man/cat8 -file /share/man/cat1/ar.0 -file /share/man/cat1/chflags.0 -file /share/man/cat1/chpass.0 -file /share/man/cat1/cpp.0 -file /share/man/cat1/crontab.0 -file /share/man/cat1/emg.0 -file /share/man/cat1/groups.0 -file /share/man/cat1/hostname.0 -file /share/man/cat1/id.0 -file /share/man/cat1/la.0 -file /share/man/cat1/lcc.0 -file /share/man/cat1/ld.0 -file /share/man/cat1/passwd.0 -file /share/man/cat1/printf.0 -file /share/man/cat1/ranlib.0 -file /share/man/cat1/rz.0 -file /share/man/cat1/stty.0 -file /share/man/cat1/sz.0 -file /share/man/cat1/test.0 -file /share/man/cat1/uname.0 -file /share/man/cat1/whoami.0 -file /share/man/cat1/xargs.0 -file /share/man/cat3/vmf.0 -file /share/man/cat5/ar.0 -file /share/man/cat5/crontab.0 -file /share/man/cat5/ranlib.0 -file /share/man/cat6/adventure.0 -file /share/man/cat6/arithmetic.0 -file /share/man/cat6/atc.0 -file /share/man/cat6/backgammon.0 -file /share/man/cat6/banner.0 -file /share/man/cat6/battlestar.0 -file /share/man/cat6/bcd.0 -file /share/man/cat6/canfield.0 -file /share/man/cat6/cribbage.0 -file /share/man/cat6/fish.0 -file /share/man/cat6/fortune.0 -file /share/man/cat6/hangman.0 -file /share/man/cat6/mille.0 -file /share/man/cat6/monop.0 -file /share/man/cat6/number.0 -file /share/man/cat6/quiz.0 -file /share/man/cat6/rain.0 -file /share/man/cat6/robots.0 -file /share/man/cat6/rogue.0 -file /share/man/cat6/sail.0 -file /share/man/cat6/snake.0 -file /share/man/cat6/trek.0 -file /share/man/cat6/worm.0 -file /share/man/cat6/worms.0 -file /share/man/cat6/wump.0 -file /share/man/cat8/chown.0 -file /share/man/cat8/chroot.0 -file /share/man/cat8/cron.0 -file /share/man/cat8/fdisk.0 -file /share/man/cat8/fstat.0 -file /share/man/cat8/init.0 -file /share/man/cat8/mkfs.0 -file /share/man/cat8/mknod.0 -file /share/man/cat8/mkpasswd.0 -file /share/man/cat8/mount.0 -file /share/man/cat8/pstat.0 -file /share/man/cat8/reboot.0 -file /share/man/cat8/renice.0 -file /share/man/cat8/shutdown.0 -file /share/man/cat8/sysctl.0 -#file /share/man/cat8/talloc.0 -file /share/man/cat8/umount.0 -file /share/man/cat8/update.0 -file /share/man/cat8/vipw.0 - -link /share/man/cat1/rb.0 -target /share/man/cat1/rz.0 -link /share/man/cat1/rx.0 -target /share/man/cat1/rz.0 - -link /share/man/cat1/sb.0 -target /share/man/cat1/sz.0 -link /share/man/cat1/sx.0 -target /share/man/cat1/sz.0 - -link /share/man/cat8/fastboot.0 -target /share/man/cat8/reboot.0 -link /share/man/cat8/halt.0 -target /share/man/cat8/reboot.0 - -link /share/man/cat1/chfn.0 -target /share/man/cat1/chpass.0 -link /share/man/cat1/chsh.0 -target /share/man/cat1/chpass.0 diff --git a/sbin/.gitignore b/sbin/.gitignore deleted file mode 100644 index 72e8ffc..0000000 --- a/sbin/.gitignore +++ /dev/null @@ -1 +0,0 @@ -* diff --git a/sdram-fpga.S b/sdram-fpga.S new file mode 100644 index 0000000..2e7ed9f --- /dev/null +++ b/sdram-fpga.S @@ -0,0 +1,755 @@ +/* + * SDRAM Access Routines for PIC32. + * + * Retromaster - 10.05.2010 + * + * This file is in the public domain. You can use, modify, and distribute the source code + * and executable programs based on the source code. This file is provided "as is" and + * without any express or implied warranties whatsoever. Use at your own risk! + * + * Changes by jmcgee for inclusion in the retrobsd project. + */ + +/* SDRAM Used: HY57V281620 + * SDRAM Pin to PIC32 Pin Mapping: + * SDRAM PIC32 + * ------ ------ + * note: the order of An to RBn DOES matter + * At the moment it is a bit of a mess and + * needs to be cleaned up. + * A0 23 RB11 + * A1 24 RB12 + * A2 25 RB13 + * A3 26 RB14 + * A4 29 RB5 + * A5 30 RB4 + * A6 31 RB3 + * A7 32 RB2 + * A8 33 RB6 + * A9 34 RB7 + * A10 22 RB15 + * A11 35 RB9 + * + * BA0 20 RD4 + * BA1 21 RD5 + * + * note: the order of DQn to RAn does not matter + * DQ0 2 RA6 + * DQ1 4 RA1 + * DQ2 5 RA7 + * DQ3 7 RA2 + * DQ4 8 RA3 + * DQ5 10 RA4 + * DQ6 11 RA5 + * DQ7 13 RA0 + + * CLK 38 OC1-RD0 + * CKE 37 A10 + * CS 19 RF12 + * WE 16 RF0 + * CAS 17 RF1 + * RAS 18 RF13 + * + * SDRam 42, 44, 45, 47, 48, 50, 51, 53 - (d8-d15) should be pulled up, but + * on the prototype board these were simply left floating + * + * Power connections not listed. + */ + + +/* + * Retrobsd does not currently contain a good header + * for pulling the pic32 port addresses into an assembly + * file, so define some needed registers here for the moment. + */ + +#define TRISA 0xBF886000 +#define T2CON 0xBF800800 +#define TMR2 0xBF800810 +#define PR2 0xBF800820 +#define T2CONSET 0xBF800808 + +#define OC1CON 0xBF803000 +#define OC4CON 0xBF803600 +#define OCXR_OFFSET 0x10 +#define OCXRS_OFFSET 0x20 + +#define AD1PCFGSET 0xBF809068 + +/* Offsets (from TRISA) for the io ports */ +#define SDR_OFFSET_A 0 +#define SDR_OFFSET_B 0x40 +#define SDR_OFFSET_C 0x80 +#define SDR_OFFSET_D 0xc0 +#define SDR_OFFSET_E 0x100 +#define SDR_OFFSET_F 0x140 +#define SDR_OFFSET_G 0x180 + +/* Offsets (from TRISA) for the various port control registers */ +#define TRIS_OFFSET 0x0 +#define PORT_OFFSET 0x10 +#define LAT_OFFSET 0x20 +#define ODCF_OFFSET 0x30 + +/* Offsets (from TRISA) for the various io port bit manipulator registers */ +#define NOP_OP_OFFSET 0x0 +#define CLR_OP_OFFSET 0x4 +#define SET_OP_OFFSET 0x8 +#define INV_OP_OFFSET 0xc + + +/* + * Specific assignments of ports ports used + * Note: In general, it is not sufficient to + * change the constants below - corresponding + * changes to the code below will likely be + * required if any of the following values + * are changed. + */ + +/* DATA_PORT_TRIS must be assigned to a TRIS of the port + * that has the low 8 bits tied the 8 data bits on the ram. + */ +#define SDR_OCR OC1CON + +#define SDR_DATA_IO SDR_OFFSET_A +#define SDR_DATA_TRIS SDR_OFFSET_A + +#define SDR_ADDRESS_IO SDR_OFFSET_B +#define SDR_ADDRESS_TRIS SDR_OFFSET_B +#define ADDRESS_MASK 0xfafc + +#define SDR_BANK_IO SDR_OFFSET_D +#define SDR_BANK_TRIS SDR_OFFSET_D +#define BANK_0_BIT 4 +#define BANK_1_BIT 5 + +#define SDR_CONTROL_IO SDR_OFFSET_F +#define SDR_CONTROL_TRIS SDR_OFFSET_F +#define CONTROL_WE_BIT 0 +#define CONTROL_CAS_BIT 1 +#define CONTROL_CS_BIT 12 +#define CONTROL_RAS_BIT 13 + +#define SDR_CKE_IO SDR_OFFSET_A +#define SDR_CKE_TRIS SDR_OFFSET_A +#define CKE_BIT 10 +#define DATA_DIR_BIT 15 + +#define CONTROL_ALL_MASK ( (1< chello.dis - ${SIZE} chello.elf - ${ELF2AOUT} chello.elf $@ +hello: hello.o + ${CC} ${LDFLAGS} -o hello.elf hello.o ${LIBS} + ${OBJDUMP} -S hello.elf > hello.dis + ${SIZE} hello.elf + ${ELF2AOUT} hello.elf $@ cplus: cplus.o ${CXX} ${LDFLAGS} -nostdlib -o cplus.elf cplus.o ${LIBS} @@ -24,6 +24,7 @@ echo: echo.o ${OBJDUMP} -S $@.elf > $@.dis ${SIZE} $@.elf ${ELF2AOUT} $@.elf $@ + ./aout $@ > $@.dis clean: - rm -f *.o *.elf ${MAN} chello cplus echo stdarg *.elf *.dis tags *~ + rm -f *.o *.elf ${MAN} hello cplus *.elf *.dis tags *~ diff --git a/share/example/chello.c b/share/example/chello.c index 4634ab5..14d9b7d 100644 --- a/share/example/chello.c +++ b/share/example/chello.c @@ -2,6 +2,6 @@ int main() { - printf ("Hello, C World!\n"); - return 0; + printf ("Hello, C World!\n"); + return 0; } diff --git a/share/example/skeleton.c b/share/example/skeleton.c deleted file mode 100644 index 6c74b3f..0000000 --- a/share/example/skeleton.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Generic skeleton for a C program. - * When you create your own program based on this skeleton, - * you can replace the author's name and copyright with - * whatever your want. When you redistribute this skeleton or - * enhance it, please leave my name and copyright on it. - * - * Copyright (C) 1993-2014 Serge Vakulenko, - * - * Permission to use, copy, modify, and distribute this software - * and its documentation for any purpose and without fee is hereby - * granted, provided that the above copyright notice appear in all - * copies and that both that the copyright notice and this - * permission notice and warranty disclaimer appear in supporting - * documentation, and that the name of the author not be used in - * advertising or publicity pertaining to distribution of the - * software without specific, written prior permission. - * - * The author disclaim all warranties with regard to this - * software, including all implied warranties of merchantability - * and fitness. In no event shall the author be liable for any - * special, indirect or consequential damages or any damages - * whatsoever resulting from loss of use, data or profits, whether - * in an action of contract, negligence or other tortious action, - * arising out of or in connection with the use or performance of - * this software. - */ -#include -#include -#include - -const char version[] = "1.0"; -const char copyright[] = "Copyright (C) 1993-2014 Serge Vakulenko"; - -char *progname; /* Name of the current program (argv[0]) */ -int verbose; /* Option -v */ -int trace; /* Option -t */ -int debug; /* Option -d */ - -void usage () -{ - fprintf (stderr, "Generic C skeleton, Version %s, %s\n", version, copyright); - fprintf (stderr, "Usage:\n\t%s [-vtd] [-r count] file...\n", progname); - fprintf (stderr, "Options:\n"); - fprintf (stderr, "\t-v\tverbose mode\n"); - fprintf (stderr, "\t-t\ttrace mode\n"); - fprintf (stderr, "\t-d\tdebug\n"); - fprintf (stderr, "\t-r #\trepeat count\n"); - exit (-1); -} - -int main (int argc, char **argv) -{ - int count = 1; /* Option -r # */ - - progname = *argv; - for (;;) { - switch (getopt (argc, argv, "vtdr:")) { - case EOF: - break; - case 'v': - ++verbose; - continue; - case 't': - ++trace; - continue; - case 'd': - ++debug; - continue; - case 'r': - count = strtol (optarg, 0, 0); - continue; - default: - usage (); - } - break; - } - argc -= optind; - argv += optind; - - if (argc < 1) - usage (); - - while (count-- > 0) { - int i; - - for (i=0; i -#include - -void print(char *fmt, ...) -{ - va_list ap; - int d; - char c, *s; - - va_start(ap, fmt); - while (*fmt) { - switch (*fmt++) { - case 's': /* string */ - s = va_arg(ap, char*); - printf("string %s\n", s); - break; - case 'd': /* int */ - d = va_arg(ap, int); - printf("int %d\n", d); - break; - case 'c': /* char */ - c = va_arg(ap, int); - printf("char %c\n", c); - break; - } - } - va_end(ap); -} - -int main() -{ - print("sdcsdc", "abracadabra", 12345, 'Z', "foo", 365, '%'); - return 0; -} diff --git a/share/man/.gitignore b/share/man/.gitignore deleted file mode 100644 index 8e1b609..0000000 --- a/share/man/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -makewhatis.sed -man.template -whatis diff --git a/share/man/cat1/.gitignore b/share/man/cat1/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/share/man/cat2/.gitignore b/share/man/cat2/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/share/man/cat3/.gitignore b/share/man/cat3/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/share/man/cat4/.gitignore b/share/man/cat4/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/share/man/cat5/.gitignore b/share/man/cat5/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/share/man/cat6/.gitignore b/share/man/cat6/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/share/man/cat7/.gitignore b/share/man/cat7/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/share/man/cat8/.gitignore b/share/man/cat8/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/share/smallc/Makefile b/share/smallc/Makefile deleted file mode 100644 index 8c17d23..0000000 --- a/share/smallc/Makefile +++ /dev/null @@ -1,41 +0,0 @@ -CC = scc -PROG = hello primelist primesum test1 test2 test3 gpio adc rain \ - webserver q8 - -all: $(PROG) - -hello: hello.c - $(CC) $(CFLAGS) -o $@ $(LDFLAGS) hello.c - -primelist: primelist.c - $(CC) $(CFLAGS) -o $@ $(LDFLAGS) primelist.c - -primesum: primesum.c - $(CC) $(CFLAGS) -o $@ $(LDFLAGS) primesum.c - -webserver: webserver.c - $(CC) $(CFLAGS) -o $@ $(LDFLAGS) webserver.c -lwiznet - -gpio: gpio.c - $(CC) $(CFLAGS) -o $@ $(LDFLAGS) gpio.c - -adc: adc.c - $(CC) $(CFLAGS) -o $@ $(LDFLAGS) adc.c - -rain: rain.c - $(CC) $(CFLAGS) -o $@ $(LDFLAGS) rain.c - -q8: q8.c - $(CC) $(CFLAGS) -o $@ $(LDFLAGS) q8.c - -test1: test1.c - $(CC) $(CFLAGS) -o $@ $(LDFLAGS) test1.c - -test2: test2.c - $(CC) $(CFLAGS) -o $@ $(LDFLAGS) test2.c - -test3: test3.c - $(CC) $(CFLAGS) -o $@ $(LDFLAGS) test3.c - -clean: - rm -f *.o $(PROG) diff --git a/share/smallc/adc.c b/share/smallc/adc.c deleted file mode 100644 index 79a11e0..0000000 --- a/share/smallc/adc.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Example of reading ADC data. - */ -#include - -char buf[100]; - -main() -{ - int i, fd, value; - - for (i=0; i<16; i++) { - sprintf(buf, "/dev/adc%d", i); - fd = open(buf, O_RDWR); - if (fd < 0) { - printf("Error: unable to open %s\n", buf); - } else { - if (read(fd, buf, 20) > 0) { - value = strtol (buf, 0, 0); - printf("adc%-2d = %d\n", i, value); - } - close(fd); - } - } - return 0; -} diff --git a/share/smallc/gpio.c b/share/smallc/gpio.c deleted file mode 100644 index fd667e1..0000000 --- a/share/smallc/gpio.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Example of polling general purpose i/o pins. - */ -#include -#include - -main () -{ - int fd, pnum, value; - - fd = open ("/dev/porta", O_RDWR); - if (fd < 0) { - perror ("/dev/porta"); - return -1; - } - - for (pnum=0; pnum<7; pnum++) { - value = ioctl (fd, GPIO_POLL | GPIO_PORT (pnum), 0); - if (value < 0) - perror ("GPIO_POLL"); - printf ("port%c = 0x%04x\n", pnum + 'A', value); - } - return 0; -} diff --git a/share/smallc/hello.c b/share/smallc/hello.c deleted file mode 100644 index 645e00e..0000000 --- a/share/smallc/hello.c +++ /dev/null @@ -1,4 +0,0 @@ -main() -{ - printf ("Hello, SmallC World!\n"); -} diff --git a/share/smallc/primelist.c b/share/smallc/primelist.c deleted file mode 100644 index 3df189f..0000000 --- a/share/smallc/primelist.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Print the list of prime numbers up to 100. - */ -main() -{ - int n; - - for (n=2; n<100; ++n) { - if (isprime(n)) { - printf("%d ", n); - } - } - printf("\n"); -} - -isprime(n) - int n; -{ - int j; - - if (n == 2) - return 1; - - if (n % 2 == 0) - return 0; - - for (j=3; j*j<=n; j+=2) - if (n % j == 0) - return 0; - return 1; -} diff --git a/share/smallc/primesum.c b/share/smallc/primesum.c deleted file mode 100644 index 81acb3e..0000000 --- a/share/smallc/primesum.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Compute the sum of prime numbers up to 10000. - */ -main() -{ - int sum, n; - - sum = 0; - for (n=2; n<10000; ++n) { - if (isprime(n)) { - sum += n; - } - } - printf("Sum of primes less than 10000: %d\n", sum); -} - -isprime(n) - int n; -{ - int j; - - if (n == 2) - return 1; - - if (n % 2 == 0) - return 0; - - for (j=3; j*j<=n; j+=2) - if (n % j == 0) - return 0; - return 1; -} diff --git a/share/smallc/q8.c b/share/smallc/q8.c deleted file mode 100644 index e4f90e2..0000000 --- a/share/smallc/q8.c +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Eight Queens puzzle - * - * (C) 2010 by Mark Sproul - * Open source as per standard Arduino code - * Modified by Pito 12/2012 for SmallC - */ -#define TRUE 1 -#define FALSE 0 - -unsigned int gChessBoard[8]; -unsigned int gLoopCounter; -int gValidCount; - -CheckCurrentBoard() -{ - int ii; - int jj; - int theRow; - int theLongRow; - int theLongColumns; - int bitCount; - - //* we know we have 1 in each row, - //* Check for 1 in each column - theRow = 0; - for (ii=0; ii<8; ii++) { - theRow |= gChessBoard[ii]; - } - if (theRow != 0x0ff) { - return FALSE; - } - - //* we have 1 in each column, now check the diagonals - theLongColumns = 0; - for (ii=0; ii<8; ii++) { - theLongRow = gChessBoard[ii] & 0x0ff; - theLongRow = theLongRow << ii; - - theLongColumns |= theLongRow; - } - - //* now count the bits - bitCount = 0; - for (ii=0; ii<16; ii++) { - if ((theLongColumns & 0x01) == 0x01) { - bitCount++; - } - theLongColumns = theLongColumns >> 1; - } - - if (bitCount != 8) { - return FALSE; - } - - //* we now have to check the other diagonal - theLongColumns = 0; - for (ii=0; ii<8; ii++) { - theLongRow = gChessBoard[ii] & 0x0ff; - theLongRow = theLongRow << 8; - theLongRow = theLongRow >> ii; - - theLongColumns |= theLongRow; - } - - //* now count the bits - bitCount = 0; - for (ii=0; ii<16; ii++) { - if ((theLongColumns & 0x01) == 0x01) { - bitCount++; - } - theLongColumns = theLongColumns >> 1; - } - - if (bitCount != 8) { - return FALSE; - } - return TRUE; -} - -CheckForDone() -{ - int ii; - int weAreDone; - int theRow; - - weAreDone = FALSE; - - //* we know we have 1 in each row, - //* Check for 1 in each column - theRow = 0; - for (ii=0; ii<8; ii++) { - theRow |= gChessBoard[ii]; - } - - if (theRow == 0x01) { - weAreDone = TRUE; - } - return weAreDone; -} - -RotateQueens() -{ - int ii; - int keepGoing; - int theRow; - - ii = 0; - keepGoing = TRUE; - while (keepGoing && (ii < 8)) { - theRow = gChessBoard[ii] & 0x0ff; - theRow = (theRow >> 1) & 0x0ff; - if (theRow != 0) { - gChessBoard[ii] = theRow; - keepGoing = FALSE; - } else { - gChessBoard[ii] = 0x080; - } - ii++; - } -} - -PrintChessBoard() -{ - int ii; - int jj; - int theRow; - char textString[32]; - - printf("\nLoop= %d\n", gLoopCounter); - printf("Solution count= %d\n", gValidCount); - - printf("+----------------+\n"); - for (ii=0; ii<8; ii++) { - theRow = gChessBoard[ii]; - - printf("|"); - for (jj=0; jj<8; jj++) { - if (theRow & 0x080) { - printf("Q "); - } else { - printf(". "); - } - theRow = theRow << 1; - } - printf("|\n"); - } - printf("+----------------+\n"); -} - -main() -{ - int ii; - - printf("\nEight Queens brute force"); - printf("\n************************\n"); - //* put the 8 queens on the board, 1 in each row - for (ii=0; ii<8; ii++) { - gChessBoard[ii] = 0x080; - } - PrintChessBoard(); - - gLoopCounter = 0; - gValidCount = 0; - - - while (1) { - gLoopCounter++; - - if (CheckCurrentBoard()) { - gValidCount++; - PrintChessBoard(); - } else if ((gLoopCounter % 1000) == 0) { - //PrintChessBoard(); - } - - RotateQueens(); - if (CheckForDone()) { - //int elapsedSeconds; - //int elapsedMinutes; - //int elapsedHours; - - //elapsedSeconds = millis() / 1000; - //elapsedMinutes = elapsedSeconds / 60; - //elapsedHours = elapsedMinutes / 60; - - printf("----------------------------------\n"); - printf("All done\n"); - - PrintChessBoard(); - printf("----------------------------------\n"); - - //Serial.print("total seconds="); - //Serial.println(elapsedSeconds); - - //Serial.print("hours="); - //Serial.println(elapsedHours); - - //Serial.print("minutes="); - //Serial.println(elapsedMinutes % 60); - - //Serial.print("seconds="); - //Serial.println(elapsedSeconds % 60); - - return (1); - } - } -} diff --git a/share/smallc/rain.c b/share/smallc/rain.c deleted file mode 100644 index d0a617d..0000000 --- a/share/smallc/rain.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Example of using termcap library for SmallC. - * 11/3/1980 EPS/CITHEP - * - * Copyright (c) 1980 Regents of the University of California. - * All rights reserved. The Berkeley software License Agreement - * specifies the terms and conditions for redistribution. - */ -#include -#include - -#define CO 80 /* number of columns */ -#define LI 24 /* number of lines */ - -#define CL "\33[H\33[J" /* clear the screen */ -#define CM "\33[%u;%uH" /* move the cursor to row, column */ -#define BC "\b" /* move cursor left */ -#define DN "\33[B" /* move cursor down */ -#define ND " " /* move cursor right */ - -int xpos[5], ypos[5]; -char outbuf[BUFSIZ]; - -moveto(col, row) - int col, row; -{ - printf(CM, row, col); -} - -onsig(n) - int n; -{ - moveto(0, LI - 1); - fflush(stdout); - _exit(0); -} - -main() -{ - int x, y, j; - - setbuf(stdout, outbuf); - for (j = SIGHUP; j <= SIGTERM; j++) - if (signal(j, SIG_IGN) != SIG_IGN) - signal(j, onsig); - - fputs(CL, stdout); - fflush(stdout); - for (j = 5; --j >= 0; ) { - xpos[j] = 2 + rand() % (CO - 4); - ypos[j] = 2 + rand() % (LI - 4); - } - for (j = 0; ; ) { - x = 2 + rand() % (CO - 4); - y = 2 + rand() % (LI - 4); - moveto(x, y); - putchar('.'); - moveto(xpos[j], ypos[j]); - putchar('o'); - if (j == 0) - j = 4; - else - --j; - moveto(xpos[j], ypos[j]); - putchar('O'); - if (j == 0) - j = 4; - else - --j; - moveto(xpos[j], ypos[j]-1); - putchar('-'); - fputs(DN, stdout); - fputs(BC, stdout); - fputs(BC, stdout); - fputs("|.|", stdout); - fputs(DN, stdout); - fputs(BC, stdout); - fputs(BC, stdout); - putchar('-'); - if (j == 0) - j = 4; - else - --j; - moveto(xpos[j], ypos[j]-2); - putchar('-'); - fputs(DN, stdout); - fputs(BC, stdout); - fputs(BC, stdout); - fputs("/ \\", stdout); - moveto(xpos[j]-2, ypos[j]); - fputs("| O |", stdout); - moveto(xpos[j]-1, ypos[j]+1); - fputs("\\ /", stdout); - fputs(DN, stdout); - fputs(BC, stdout); - fputs(BC, stdout); - putchar('-'); - if (j == 0) - j = 4; - else - --j; - moveto(xpos[j], ypos[j]-2); - putchar(' '); - fputs(DN, stdout); - fputs(BC, stdout); - fputs(BC, stdout); - putchar(' '); - fputs(ND, stdout); - putchar(' '); - moveto(xpos[j]-2, ypos[j]); - putchar(' '); - fputs(ND, stdout); - putchar(' '); - fputs(ND, stdout); - putchar(' '); - moveto(xpos[j]-1, ypos[j]+1); - putchar(' '); - fputs(ND, stdout); - putchar(' '); - fputs(DN, stdout); - fputs(BC, stdout); - fputs(BC, stdout); - putchar(' '); - xpos[j] = x; - ypos[j] = y; - fflush(stdout); - usleep(100000); - } -} diff --git a/share/smallc/test1.c b/share/smallc/test1.c deleted file mode 100644 index 182ec29..0000000 --- a/share/smallc/test1.c +++ /dev/null @@ -1,219 +0,0 @@ -int ga[5]; - -main() -{ - int a, b, c, d; - int arr[5]; - int *pi; - char arrc[5]; - char *pic; - int s1, s2; - int z; - int t; - int *pip; - int *picp; - int e1, e2; - - ga[0] = 10; - ga[1] = 20; - ga[2] = 30; - ga[3] = 40; - ga[4] = 50; - - a = 21; - b = 31; - c = 71; - d = 82; - - arr[0] = 10; - arr[1] = 20; - arr[2] = 30; - arr[3] = 40; - arr[4] = 50; - pi = &arr[0]; - - arrc[0] = 13; - arrc[1] = 23; - arrc[2] = 33; - arrc[3] = 43; - arrc[4] = 53; - pic = &arrc[0]; - - printf(" 21 + 31 = %d (52)\n", a + b); - printf(" 21 - 31 = %d (-10)\n", a - b); - printf(" 21 & 71 = %d (5)\n", a & c); - printf(" 21 | 82 = %d (87)\n", a | d); - printf(" 21 ^ 82 = %d (71)\n", a ^ d); - printf(" 21 * 82 = %d (1722)\n", a * d); - printf(" 82 % 21 = %d (19)\n", d % a); - printf(" 82 / 21 = %d (3)\n", d / a); - printf(" *pi = %d (10)\n", *pi); - printf(" *pi + 1 = %d (11)\n", *pi + 1); - printf(" *(pi + 1) = %d (20)\n", *(pi + 1)); - printf("&arr[3] - &arr[0] = %d (3)\n", &arr[3] - &arr[0]); - printf(" arr[3]-arr[0] = %d (30)\n", arr[3] - arr[0]); - printf(" arr[3]+arr[0] = %d (50)\n", arr[3] + arr[0]); - printf(" &ga[3] - &ga[0] = %d (3)\n", &ga[3] - &ga[0]); - printf(" ga[3]-ga[0] = %d (30)\n", ga[3] - ga[0]); - printf(" ga[3]+ga[0] = %d (50)\n", ga[3] + ga[0]); - printf("\n"); - - printf(" *pic = %d (13)\n", *pic); - printf(" *pic + 1 = %d (14)\n", *pic+1); - printf(" *(pic + 1) = %d (23)\n", *(pic+1)); - printf("&arrc[3] - &arrc[0] = %d (3)\n", &arrc[3]-&arrc[0]); - printf("\n"); - - s1 = 3; - s2 = -200; - printf(" 82 << 3 = %d (656)\n", d << s1); - printf(" 82 >> 3 = %d (10)\n", d >> s1); - printf("-200 >> 3 = %d (-25)\n", s2 >> s1); - printf("-200 << 3 = %d (-1600)\n", s2 << s1); - printf("\n"); - - printf("-s1 = %d (-3)\n", -s1); - printf("-s2 = %d (200)\n", -s2); - printf("\n"); - - printf("~82 = %d (-83)\n", ~d); - printf("\n"); - - z = 0; - printf("!82 = %d (0)\n", !d); - printf(" !0 = %d (1)\n", !z); - printf("\n"); - - printf(" 0 && 0 = %d (0)\n", z && z); - printf(" 0 && 21 = %d (0)\n", z && a); - printf(" 3 && 21 = %d (1)\n", s1 && a); - printf("21 && 3 = %d (1)\n", a && s1); - printf("\n"); - - printf(" 0 || 0 = %d (0)\n", z || z); - printf(" 0 || 21 = %d (1)\n", z || a); - printf(" 3 || 21 = %d (1)\n", s1 || a); - printf("21 || 3 = %d (1)\n", a || s1); - printf("\n"); - - pi = 4; - printf("pi++ = %d (4)\n", pi++); - printf(" pi = %d (8)\n", pi); - printf("++pi = %d (12)\n", ++pi); - printf("pi-- = %d (12)\n", pi--); - printf(" pi = %d (8)\n", pi); - printf("--pi = %d (4)\n", --pi); - printf("\n"); - - pic = 4; - printf("pic++ = %d (4)\n", pic++); - printf(" pic = %d (5)\n", pic); - printf("++pic = %d (6)\n", ++pic); - printf("pic-- = %d (6)\n", pic--); - printf(" pic = %d (5)\n", pic); - printf("--pic = %d (4)\n", --pic); - printf("\n"); - - t = 4; - printf("t++ = %d (4)\n", t++); - printf(" t = %d (5)\n", t); - printf("++t = %d (6)\n", ++t); - printf("t-- = %d (6)\n", t--); - printf(" t = %d (5)\n", t); - printf("--t = %d (4)\n", --t); - printf("\n"); - - t = 4; - printf(" t==4 = %d (1)\n", t == 4); - printf(" t==3 = %d (0)\n", t == 3); - printf(" t==5 = %d (0)\n", t == 5); - t = -4; - printf("t==-4 = %d (1)\n", t == -4); - printf("t==-3 = %d (0)\n", t == -3); - printf("t==-5 = %d (0)\n", t == -5); - printf(" t==4 = %d (0)\n", t == 4); - printf(" t==3 = %d (0)\n", t == 3); - printf(" t==5 = %d (0)\n", t == 5); - printf("\n"); - - t = 4; - printf(" t!=4 = %d (0)\n", t != 4); - printf(" t!=3 = %d (1)\n", t != 3); - printf(" t!=5 = %d (1)\n", t != 5); - t = -4; - printf("t!=-4 = %d (0)\n", t != -4); - printf("t!=-3 = %d (1)\n", t != -3); - printf("t!=-5 = %d (1)\n", t != -5); - printf(" t!=4 = %d (1)\n", t != 4); - printf(" t!=3 = %d (1)\n", t != 3); - printf(" t!=5 = %d (1)\n", t != 5); - printf("\n"); - - t = 4; - printf(" t<4 = %d (0)\n", t < 4); - printf(" t<3 = %d (0)\n", t < 3); - printf(" t<5 = %d (1)\n", t < 5); - printf("t<-1 = %d (0)\n", t < -1); - printf("\n"); - - printf(" t<=4 = %d (1)\n", t <= 4); - printf(" t<=3 = %d (0)\n", t <= 3); - printf(" t<=5 = %d (1)\n", t <= 5); - printf("t<=-1 = %d (0)\n", t <= -1); - printf("\n"); - - t = 4; - printf(" t>4 = %d (0)\n", t > 4); - printf(" t>3 = %d (1)\n", t > 3); - printf(" t>5 = %d (0)\n", t > 5); - printf("t>-1 = %d (1)\n", t > -1); - printf("\n"); - - printf(" t>=4 = %d (1)\n", t >= 4); - printf(" t>=3 = %d (1)\n", t >= 3); - printf(" t>=5 = %d (0)\n", t >= 5); - printf("t>=-1 = %d (1)\n", t >= -1); - printf("\n"); - - pi = -100; - printf(" pi<4 = %d (0)\n", pi < 4); - printf(" pi<3 = %d (0)\n", pi < 3); - printf("pi<-100 = %d (0)\n", pi < -100); - printf(" pi<-1 = %d (1)\n", pi < -1); - printf("\n"); - - printf(" pi<=4 = %d (0)\n", pi <= 4); - printf(" pi<=3 = %d (0)\n", pi <= 3); - printf("pi<=-100 = %d (1)\n", pi <= -100); - printf(" pi<=-1 = %d (1)\n", pi <= -1); - printf("\n"); - - pi = -100; - printf(" pi>4 = %d (1)\n", pi > 4); - printf(" pi>3 = %d (1)\n", pi > 3); - printf("pi>-100 = %d (0)\n", pi > -100); - printf(" pi>-1 = %d (0)\n", pi > -1); - printf("\n"); - - printf(" pi>=4 = %d (1)\n", pi >= 4); - printf(" pi>=3 = %d (1)\n", pi >= 3); - printf("pi>=-100 = %d (1)\n", pi >= -100); - printf(" pi>=-1 = %d (0)\n", pi >= -1); - printf("\n"); - - pi = &arr[0]; - pip = &arr[3]; - printf(" *pip - *pi: %d 30\n", *pip - *pi); - printf(" pip - pi: %d 3\n", pip - pi); - printf(" *pip: %d 40\n", *pip); - printf(" *(pip - 3): %d 10\n", *(pip - 3)); - printf(" *&arr[3]: %d 40\n", *&arr[3]); - printf("*(&arr[3] - 3): %d 10\n", *(&arr[3]-3)); -} - -printt (t, str) - int t; - char *str; -{ - printf("bool test on value %d %s\n", t, str); -} diff --git a/share/smallc/test2.c b/share/smallc/test2.c deleted file mode 100644 index 64f8cca..0000000 --- a/share/smallc/test2.c +++ /dev/null @@ -1,127 +0,0 @@ -#include - -int aaa; -int bbb; -int ccc; -char gc; -char gbuffer[3]; -int gibuffer[4]; - -extern errno; - -main() -{ - char b; - int la; - unsigned int u1, u2; - int s1, s2; - unsigned char uc1, uc2; - char sc1, sc2; - int fd; - char buffer[6]; - int ibuffer[7]; - - printf(" sizeof(uc1): %d 1\n", sizeof(uc1)); - printf(" sizeof(sc1): %d 1\n", sizeof(sc1)); - printf(" sizeof(u1): %d 4\n", sizeof(u1)); - printf(" sizeof(s1): %d 4\n", sizeof(s1)); - printf(" sizeof(aaa): %d 4\n", sizeof(aaa)); - printf(" sizeof(bbb): %d 4\n", sizeof(bbb)); - printf(" sizeof(gc): %d 1\n", sizeof(gc)); - printf(" sizeof(buffer): %d 6\n", sizeof(buffer)); - printf(" sizeof(ibuffer): %d 28\n", sizeof(ibuffer)); - printf(" sizeof(char): %d 1\n", sizeof(char)); - printf(" sizeof(int): %d 4\n", sizeof(int)); - printf(" sizeof(gbuffer): %d 3\n", sizeof(gbuffer)); - printf(" sizeof(gibuffer): %d 16\n", sizeof(gibuffer)); - // sizeof(ibuffer[0]) is not supported, so the following can be used... - printf("sizeof(ibuffer)/sizeof(int): %d 7\n", sizeof(ibuffer)/sizeof(int)); - - aaa = 1; - bbb = 2; - la = 4; - printf("%d 1\n", aaa); - printf("%d 2\n", bbb); - printf("%d 4\n", la); - - uc1 = 0x80; - sc1 = 0x80; - s1 = uc1; - s2 = sc1; - printf("unsigned char (0x80) -> int: %d 128\n", s1); - printf(" signed char (0x80) -> int: %d -128\n", s2); - - u1 = uc1; - u2 = sc1; - printf("unsigned char (0x80) -> unsigned: %d 128\n", u1); - printf(" signed char (0x80) -> unsigned: %d -128\n", u2); - - la = errno; - printf("errno: %d 0\n", la); - - write(1, "abcd ", 5); - la = errno; - printf("errno after good write call: %d 0\n", la); - - write(10, "abcde", 5); - la = errno; - printf("errno after bad write call: %d 9\n", la); - - write(1, "abcd ", 5); - la = errno; - printf("good write after failed should not overwrite errno: %d 9\n", la); - - errno = 0; - write(1, "abcd ", 5); - la = errno; - printf("good write after errno set to zero: %d 0\n", la); - - la = write(1, "abcd ", 5); - printf("write() return: %d 5\n", la); - - la = write(10, "abcd ", 5); - printf("write(bad fd) return: %d -1\n", la); - - fd = open("/a.txt", O_WRONLY | O_CREAT, 0666); - if (fd != -1) { - printf("open success\n"); - la = write(fd, "abcd\n", 5); - if (la == 5) printf("write success\n"); else printf("write failed\n"); - la = close(fd); - if (la != -1) printf("close success\n"); else printf("close failed\n"); - } else { - printf("open failed\n"); - } - - buffer[0] = 0; - buffer[1] = 0; - buffer[2] = 0; - buffer[3] = 0; - buffer[4] = 0; - buffer[5] = 0; - - fd = open("/a.txt", O_RDONLY, 0666); - if (fd != -1) { - printf("open success\n"); - la = read(fd, buffer, 5); - printf(buffer); - if (la == 5) printf("read success\n"); else printf("read failed\n"); - la = close(fd); - if (la != -1) printf("close success\n"); else printf("close failed\n"); - } else { - printf("open failed\n"); - } - - if (buffer[0] != 'a') printf("data0 readback from file MISMATCH\n"); - if (buffer[1] != 'b') printf("data1 readback from file MISMATCH\n"); - if (buffer[2] != 'c') printf("data2 readback from file MISMATCH\n"); - if (buffer[3] != 'd') printf("data3 readback from file MISMATCH\n"); - if (buffer[4] != '\n') printf("data4 readback from file MISMATCH\n"); - - if (buffer[0] != 'a' || buffer[1] != 'b' || buffer[2] != 'c' || - buffer[3] != 'd' || buffer[4] != '\n') { - printf("data readback from file MISMATCH\n"); - } else { - printf("data readback from file OK\n"); - } -} diff --git a/share/smallc/test3.c b/share/smallc/test3.c deleted file mode 100644 index edb0ab0..0000000 --- a/share/smallc/test3.c +++ /dev/null @@ -1,49 +0,0 @@ -main() -{ - int t; - - t = 0; - if (t) printt(t, "failure"); else printt(t, "success"); - t = 1; - if (t) printt(t, "success"); else printt(t, "failure"); - t = 8; - if (t) printt(t, "success"); else printt(t, "failure"); - t = -2; - if (t) printt(t, "success"); else printt(t, "failure"); - printf("\n"); - - t = 4; - printf("switch test: "); - switch (t) { - case 3: - printf("failure"); - break; - case 4: - printf("success"); - break; - case 5: - printf("failure"); - break; - } - printf("\n"); - - printf("switch fallthrough test: "); - switch (t) { - case 3: - printf("failure"); - break; - case 4: - printf("OKSOFAR: "); - case 5: - printf("success if oksofar printed before this in caps"); - break; - } - printf("\n"); -} - -printt (t, str) - int t; - char *str; -{ - printf("bool test on value %d %s\n", t, str); -} diff --git a/share/smallc/webserver.c b/share/smallc/webserver.c deleted file mode 100644 index 4f6a81d..0000000 --- a/share/smallc/webserver.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Web server, written in SmallC. - * - * A simple web server that shows the value of the analog input pins. - * using an Arduino Wiznet Ethernet shield. - * - * 18 Dec 2009 created by David A. Mellis - * 4 Sep 2010 modified by Tom Igoe - * 16 Apr 2012 ported to RetroBSD by Serge Vakulenko - */ -#include -#include -#include -#include - -int client [CLIENT_SIZE]; - -char buf [80]; - -main() -{ - /* Initialize the Ethernet server library - * with the IP address and port you want to use - * (port 80 is default for HTTP). */ - ethernet_init (); - server_init (80); - - for (;;) { - /* Listen for incoming clients. */ - if (server_available (client)) { - process_request(); - } - } -} - -process_request() -{ - int current_line_is_blank; - int c, fd, pnum, value; - - /* An http request ends with a blank line. */ - current_line_is_blank = 1; - - /* Parse the http request. */ - while (client_connected (client)) { - if (client_available (client)) { - c = client_getc (client); - - /* If you've gotten to the end of the line (received - * a newline character) and the line is blank, the http - * request has ended, so you can send a reply. */ - if (c == '\n' && current_line_is_blank) - break; - - if (c == '\n') { - /* You're starting a new line. */ - current_line_is_blank = 1; - } - else if (c != '\r') { - /* You've gotten a character on the current line. */ - current_line_is_blank = 0; - } - } - } - - /* Send a standard http response header. */ - client_puts (client, "HTTP/1.1 200 OK\n"); - client_puts (client, "Content-Type: text/html\n\n"); - - /* Output the value of each digital pin. */ - fd = open ("/dev/porta", O_RDONLY); - if (fd < 0) { - client_puts (client, "Failed to open /dev/porta\n"); - } else { - for (pnum = 0; pnum < 6; pnum++) { - value = ioctl (fd, GPIO_POLL | GPIO_PORT (pnum), 0); - sprintf (buf, "PORT%c = 0x%04x
\n", pnum+'A', value); - client_puts (client, buf); - } - close (fd); - } - - /* Give the web browser time to receive the data. */ - usleep (1000); - - /* Close the connection. */ - client_stop (client); -} diff --git a/share/smallerc/Makefile b/share/smallerc/Makefile deleted file mode 100644 index 977a786..0000000 --- a/share/smallerc/Makefile +++ /dev/null @@ -1,38 +0,0 @@ -CC = cc -PROG = hello primelist primesum test1 test2 test3 gpio adc rain \ - q8 - -all: $(PROG) - -hello: hello.c - $(CC) $(CFLAGS) -o $@ $(LDFLAGS) hello.c - -primelist: primelist.c - $(CC) $(CFLAGS) -o $@ $(LDFLAGS) primelist.c - -primesum: primesum.c - $(CC) $(CFLAGS) -o $@ $(LDFLAGS) primesum.c - -gpio: gpio.c - $(CC) $(CFLAGS) -o $@ $(LDFLAGS) gpio.c - -adc: adc.c - $(CC) $(CFLAGS) -o $@ $(LDFLAGS) adc.c - -rain: rain.c - $(CC) $(CFLAGS) -o $@ $(LDFLAGS) rain.c - -q8: q8.c - $(CC) $(CFLAGS) -o $@ $(LDFLAGS) q8.c - -test1: test1.c - $(CC) $(CFLAGS) -o $@ $(LDFLAGS) test1.c - -test2: test2.c - $(CC) $(CFLAGS) -o $@ $(LDFLAGS) test2.c - -test3: test3.c - $(CC) $(CFLAGS) -o $@ $(LDFLAGS) test3.c - -clean: - rm -f *.o $(PROG) diff --git a/share/smallerc/adc.c b/share/smallerc/adc.c deleted file mode 100644 index af0efe3..0000000 --- a/share/smallerc/adc.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Example of reading ADC data. - */ -#include -#include -#include -#include - -char buf[100]; - -int main(void) -{ - int i, fd, value; - - for (i=0; i<16; i++) { - sprintf(buf, "/dev/adc%d", i); - fd = open(buf, O_RDWR); - if (fd < 0) { - printf("Error: unable to open %s\n", buf); - } else { - if (read(fd, buf, 20) > 0) { - value = strtol (buf, 0, 0); - printf("adc%-2d = %d\n", i, value); - } - close(fd); - } - } - return 0; -} diff --git a/share/smallerc/gpio.c b/share/smallerc/gpio.c deleted file mode 100644 index f6b6ba2..0000000 --- a/share/smallerc/gpio.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Example of polling general purpose i/o pins. - */ -#include -#include -#include -#include - -int main(void) -{ - int fd, pnum, value; - - fd = open ("/dev/porta", O_RDWR); - if (fd < 0) { - perror ("/dev/porta"); - return -1; - } - - for (pnum=0; pnum<7; pnum++) { - value = ioctl (fd, GPIO_POLL | GPIO_PORT (pnum), 0); - if (value < 0) - perror ("GPIO_POLL"); - printf ("port%c = 0x%04x\n", pnum + 'A', value); - } - return 0; -} diff --git a/share/smallerc/hello.c b/share/smallerc/hello.c deleted file mode 100644 index c72c91b..0000000 --- a/share/smallerc/hello.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main(void) -{ - printf("Hello, Smaller C World!\n"); -} diff --git a/share/smallerc/primelist.c b/share/smallerc/primelist.c deleted file mode 100644 index 036b02f..0000000 --- a/share/smallerc/primelist.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Print the list of prime numbers up to 100. - */ -#include - -int isprime(int); - -int main(void) -{ - int n; - - for (n=2; n<100; ++n) { - if (isprime(n)) { - printf("%d ", n); - } - } - printf("\n"); -} - -int isprime(int n) -{ - int j; - - if (n == 2) - return 1; - - if (n % 2 == 0) - return 0; - - for (j=3; j*j<=n; j+=2) - if (n % j == 0) - return 0; - return 1; -} - diff --git a/share/smallerc/primesum.c b/share/smallerc/primesum.c deleted file mode 100644 index 7f37a59..0000000 --- a/share/smallerc/primesum.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Compute the sum of prime numbers up to 10000. - */ -#include - -int isprime(int); - -int main(void) -{ - int sum, n; - - sum = 0; - for (n=2; n<10000; ++n) { - if (isprime(n)) { - sum += n; - } - } - printf("Sum of primes less than 10000: %d\n", sum); -} - -int isprime(int n) -{ - int j; - - if (n == 2) - return 1; - - if (n % 2 == 0) - return 0; - - for (j=3; j*j<=n; j+=2) - if (n % j == 0) - return 0; - return 1; -} diff --git a/share/smallerc/q8.c b/share/smallerc/q8.c deleted file mode 100644 index 9cc3b12..0000000 --- a/share/smallerc/q8.c +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Eight Queens puzzle - * - * (C) 2010 by Mark Sproul - * Open source as per standard Arduino code - * Modified by Pito 12/2012 for SmallC and then by Alexey Frunze for Smaller C - */ -#include -#define TRUE 1 -#define FALSE 0 - -unsigned int gChessBoard[8]; -unsigned int gLoopCounter; -int gValidCount; - -int CheckCurrentBoard(void) -{ - int ii; - int jj; - int theRow; - int theLongRow; - int theLongColumns; - int bitCount; - - //* we know we have 1 in each row, - //* Check for 1 in each column - theRow = 0; - for (ii=0; ii<8; ii++) { - theRow |= gChessBoard[ii]; - } - if (theRow != 0x0ff) { - return FALSE; - } - - //* we have 1 in each column, now check the diagonals - theLongColumns = 0; - for (ii=0; ii<8; ii++) { - theLongRow = gChessBoard[ii] & 0x0ff; - theLongRow = theLongRow << ii; - - theLongColumns |= theLongRow; - } - - //* now count the bits - bitCount = 0; - for (ii=0; ii<16; ii++) { - if ((theLongColumns & 0x01) == 0x01) { - bitCount++; - } - theLongColumns = theLongColumns >> 1; - } - - if (bitCount != 8) { - return FALSE; - } - - //* we now have to check the other diagonal - theLongColumns = 0; - for (ii=0; ii<8; ii++) { - theLongRow = gChessBoard[ii] & 0x0ff; - theLongRow = theLongRow << 8; - theLongRow = theLongRow >> ii; - - theLongColumns |= theLongRow; - } - - //* now count the bits - bitCount = 0; - for (ii=0; ii<16; ii++) { - if ((theLongColumns & 0x01) == 0x01) { - bitCount++; - } - theLongColumns = theLongColumns >> 1; - } - - if (bitCount != 8) { - return FALSE; - } - return TRUE; -} - -int CheckForDone(void) -{ - int ii; - int weAreDone; - int theRow; - - weAreDone = FALSE; - - //* we know we have 1 in each row, - //* Check for 1 in each column - theRow = 0; - for (ii=0; ii<8; ii++) { - theRow |= gChessBoard[ii]; - } - - if (theRow == 0x01) { - weAreDone = TRUE; - } - return weAreDone; -} - -void RotateQueens(void) -{ - int ii; - int keepGoing; - int theRow; - - ii = 0; - keepGoing = TRUE; - while (keepGoing && (ii < 8)) { - theRow = gChessBoard[ii] & 0x0ff; - theRow = (theRow >> 1) & 0x0ff; - if (theRow != 0) { - gChessBoard[ii] = theRow; - keepGoing = FALSE; - } else { - gChessBoard[ii] = 0x080; - } - ii++; - } -} - -void PrintChessBoard(void) -{ - int ii; - int jj; - int theRow; - char textString[32]; - - printf("\nLoop= %d\n", gLoopCounter); - printf("Solution count= %d\n", gValidCount); - - printf("+----------------+\n"); - for (ii=0; ii<8; ii++) { - theRow = gChessBoard[ii]; - - printf("|"); - for (jj=0; jj<8; jj++) { - if (theRow & 0x080) { - printf("Q "); - } else { - printf(". "); - } - theRow = theRow << 1; - } - printf("|\n"); - } - printf("+----------------+\n"); -} - -int main(void) -{ - int ii; - - printf("\nEight Queens brute force"); - printf("\n************************\n"); - //* put the 8 queens on the board, 1 in each row - for (ii=0; ii<8; ii++) { - gChessBoard[ii] = 0x080; - } - PrintChessBoard(); - - gLoopCounter = 0; - gValidCount = 0; - - - while (1) { - gLoopCounter++; - - if (CheckCurrentBoard()) { - gValidCount++; - PrintChessBoard(); - } else if ((gLoopCounter % 1000) == 0) { - //PrintChessBoard(); - } - - RotateQueens(); - if (CheckForDone()) { - //int elapsedSeconds; - //int elapsedMinutes; - //int elapsedHours; - - //elapsedSeconds = millis() / 1000; - //elapsedMinutes = elapsedSeconds / 60; - //elapsedHours = elapsedMinutes / 60; - - printf("----------------------------------\n"); - printf("All done\n"); - - PrintChessBoard(); - printf("----------------------------------\n"); - - //Serial.print("total seconds="); - //Serial.println(elapsedSeconds); - - //Serial.print("hours="); - //Serial.println(elapsedHours); - - //Serial.print("minutes="); - //Serial.println(elapsedMinutes % 60); - - //Serial.print("seconds="); - //Serial.println(elapsedSeconds % 60); - - return (1); - } - } -} diff --git a/share/smallerc/rain.c b/share/smallerc/rain.c deleted file mode 100644 index fc385ed..0000000 --- a/share/smallerc/rain.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Example of using termcap library for SmallC. - * 11/3/1980 EPS/CITHEP - * - * Copyright (c) 1980 Regents of the University of California. - * All rights reserved. The Berkeley software License Agreement - * specifies the terms and conditions for redistribution. - */ -#include -#include -#include -#include - -#define CO 80 /* number of columns */ -#define LI 24 /* number of lines */ - -#define CL "\33[H\33[J" /* clear the screen */ -#define CM "\33[%u;%uH" /* move the cursor to row, column */ -#define BC "\b" /* move cursor left */ -#define DN "\33[B" /* move cursor down */ -#define ND " " /* move cursor right */ - -int xpos[5], ypos[5]; -char outbuf[BUFSIZ]; - -void moveto(int col, int row) -{ - printf(CM, row, col); -} - -void onsig(int n) -{ - moveto(0, LI - 1); - fflush(stdout); - _exit(0); -} - -int main(void) -{ - int x, y, j; - - setbuf(stdout, outbuf); - for (j = SIGHUP; j <= SIGTERM; j++) - if (signal(j, SIG_IGN) != SIG_IGN) - signal(j, onsig); - - fputs(CL, stdout); - fflush(stdout); - for (j = 5; --j >= 0; ) { - xpos[j] = 2 + rand() % (CO - 4); - ypos[j] = 2 + rand() % (LI - 4); - } - for (j = 0; ; ) { - x = 2 + rand() % (CO - 4); - y = 2 + rand() % (LI - 4); - moveto(x, y); - putchar('.'); - moveto(xpos[j], ypos[j]); - putchar('o'); - if (j == 0) - j = 4; - else - --j; - moveto(xpos[j], ypos[j]); - putchar('O'); - if (j == 0) - j = 4; - else - --j; - moveto(xpos[j], ypos[j]-1); - putchar('-'); - fputs(DN, stdout); - fputs(BC, stdout); - fputs(BC, stdout); - fputs("|.|", stdout); - fputs(DN, stdout); - fputs(BC, stdout); - fputs(BC, stdout); - putchar('-'); - if (j == 0) - j = 4; - else - --j; - moveto(xpos[j], ypos[j]-2); - putchar('-'); - fputs(DN, stdout); - fputs(BC, stdout); - fputs(BC, stdout); - fputs("/ \\", stdout); - moveto(xpos[j]-2, ypos[j]); - fputs("| O |", stdout); - moveto(xpos[j]-1, ypos[j]+1); - fputs("\\ /", stdout); - fputs(DN, stdout); - fputs(BC, stdout); - fputs(BC, stdout); - putchar('-'); - if (j == 0) - j = 4; - else - --j; - moveto(xpos[j], ypos[j]-2); - putchar(' '); - fputs(DN, stdout); - fputs(BC, stdout); - fputs(BC, stdout); - putchar(' '); - fputs(ND, stdout); - putchar(' '); - moveto(xpos[j]-2, ypos[j]); - putchar(' '); - fputs(ND, stdout); - putchar(' '); - fputs(ND, stdout); - putchar(' '); - moveto(xpos[j]-1, ypos[j]+1); - putchar(' '); - fputs(ND, stdout); - putchar(' '); - fputs(DN, stdout); - fputs(BC, stdout); - fputs(BC, stdout); - putchar(' '); - xpos[j] = x; - ypos[j] = y; - fflush(stdout); - usleep(100000); - } -} diff --git a/share/smallerc/test1.c b/share/smallerc/test1.c deleted file mode 100644 index 6177a9e..0000000 --- a/share/smallerc/test1.c +++ /dev/null @@ -1,214 +0,0 @@ -#include - -int ga[5]; - -int main(void) -{ - int a, b, c, d; - int arr[5]; - int *pi; - char arrc[5]; - char *pic; - int s1, s2; - int z; - int t; - int *pip; - int *picp; - int e1, e2; - - ga[0] = 10; - ga[1] = 20; - ga[2] = 30; - ga[3] = 40; - ga[4] = 50; - - a = 21; - b = 31; - c = 71; - d = 82; - - arr[0] = 10; - arr[1] = 20; - arr[2] = 30; - arr[3] = 40; - arr[4] = 50; - pi = &arr[0]; - - arrc[0] = 13; - arrc[1] = 23; - arrc[2] = 33; - arrc[3] = 43; - arrc[4] = 53; - pic = &arrc[0]; - - printf(" 21 + 31 = %d (52)\n", a + b); - printf(" 21 - 31 = %d (-10)\n", a - b); - printf(" 21 & 71 = %d (5)\n", a & c); - printf(" 21 | 82 = %d (87)\n", a | d); - printf(" 21 ^ 82 = %d (71)\n", a ^ d); - printf(" 21 * 82 = %d (1722)\n", a * d); - printf(" 82 %% 21 = %d (19)\n", d % a); - printf(" 82 / 21 = %d (3)\n", d / a); - printf(" *pi = %d (10)\n", *pi); - printf(" *pi + 1 = %d (11)\n", *pi + 1); - printf(" *(pi + 1) = %d (20)\n", *(pi + 1)); - printf("&arr[3] - &arr[0] = %d (3)\n", &arr[3] - &arr[0]); - printf(" arr[3]-arr[0] = %d (30)\n", arr[3] - arr[0]); - printf(" arr[3]+arr[0] = %d (50)\n", arr[3] + arr[0]); - printf(" &ga[3] - &ga[0] = %d (3)\n", &ga[3] - &ga[0]); - printf(" ga[3]-ga[0] = %d (30)\n", ga[3] - ga[0]); - printf(" ga[3]+ga[0] = %d (50)\n", ga[3] + ga[0]); - printf("\n"); - - printf(" *pic = %d (13)\n", *pic); - printf(" *pic + 1 = %d (14)\n", *pic+1); - printf(" *(pic + 1) = %d (23)\n", *(pic+1)); - printf("&arrc[3] - &arrc[0] = %d (3)\n", &arrc[3]-&arrc[0]); - printf("\n"); - - s1 = 3; - s2 = -200; - printf(" 82 << 3 = %d (656)\n", d << s1); - printf(" 82 >> 3 = %d (10)\n", d >> s1); - printf("-200 >> 3 = %d (-25)\n", s2 >> s1); - printf("-200 << 3 = %d (-1600)\n", s2 << s1); - printf("\n"); - - printf("-s1 = %d (-3)\n", -s1); - printf("-s2 = %d (200)\n", -s2); - printf("\n"); - - printf("~82 = %d (-83)\n", ~d); - printf("\n"); - - z = 0; - printf("!82 = %d (0)\n", !d); - printf(" !0 = %d (1)\n", !z); - printf("\n"); - - printf(" 0 && 0 = %d (0)\n", z && z); - printf(" 0 && 21 = %d (0)\n", z && a); - printf(" 3 && 21 = %d (1)\n", s1 && a); - printf("21 && 3 = %d (1)\n", a && s1); - printf("\n"); - - printf(" 0 || 0 = %d (0)\n", z || z); - printf(" 0 || 21 = %d (1)\n", z || a); - printf(" 3 || 21 = %d (1)\n", s1 || a); - printf("21 || 3 = %d (1)\n", a || s1); - printf("\n"); - - pi = 4; - printf("pi++ = %d (4)\n", pi++); - printf(" pi = %d (8)\n", pi); - printf("++pi = %d (12)\n", ++pi); - printf("pi-- = %d (12)\n", pi--); - printf(" pi = %d (8)\n", pi); - printf("--pi = %d (4)\n", --pi); - printf("\n"); - - pic = 4; - printf("pic++ = %d (4)\n", pic++); - printf(" pic = %d (5)\n", pic); - printf("++pic = %d (6)\n", ++pic); - printf("pic-- = %d (6)\n", pic--); - printf(" pic = %d (5)\n", pic); - printf("--pic = %d (4)\n", --pic); - printf("\n"); - - t = 4; - printf("t++ = %d (4)\n", t++); - printf(" t = %d (5)\n", t); - printf("++t = %d (6)\n", ++t); - printf("t-- = %d (6)\n", t--); - printf(" t = %d (5)\n", t); - printf("--t = %d (4)\n", --t); - printf("\n"); - - t = 4; - printf(" t==4 = %d (1)\n", t == 4); - printf(" t==3 = %d (0)\n", t == 3); - printf(" t==5 = %d (0)\n", t == 5); - t = -4; - printf("t==-4 = %d (1)\n", t == -4); - printf("t==-3 = %d (0)\n", t == -3); - printf("t==-5 = %d (0)\n", t == -5); - printf(" t==4 = %d (0)\n", t == 4); - printf(" t==3 = %d (0)\n", t == 3); - printf(" t==5 = %d (0)\n", t == 5); - printf("\n"); - - t = 4; - printf(" t!=4 = %d (0)\n", t != 4); - printf(" t!=3 = %d (1)\n", t != 3); - printf(" t!=5 = %d (1)\n", t != 5); - t = -4; - printf("t!=-4 = %d (0)\n", t != -4); - printf("t!=-3 = %d (1)\n", t != -3); - printf("t!=-5 = %d (1)\n", t != -5); - printf(" t!=4 = %d (1)\n", t != 4); - printf(" t!=3 = %d (1)\n", t != 3); - printf(" t!=5 = %d (1)\n", t != 5); - printf("\n"); - - t = 4; - printf(" t<4 = %d (0)\n", t < 4); - printf(" t<3 = %d (0)\n", t < 3); - printf(" t<5 = %d (1)\n", t < 5); - printf("t<-1 = %d (0)\n", t < -1); - printf("\n"); - - printf(" t<=4 = %d (1)\n", t <= 4); - printf(" t<=3 = %d (0)\n", t <= 3); - printf(" t<=5 = %d (1)\n", t <= 5); - printf("t<=-1 = %d (0)\n", t <= -1); - printf("\n"); - - t = 4; - printf(" t>4 = %d (0)\n", t > 4); - printf(" t>3 = %d (1)\n", t > 3); - printf(" t>5 = %d (0)\n", t > 5); - printf("t>-1 = %d (1)\n", t > -1); - printf("\n"); - - printf(" t>=4 = %d (1)\n", t >= 4); - printf(" t>=3 = %d (1)\n", t >= 3); - printf(" t>=5 = %d (0)\n", t >= 5); - printf("t>=-1 = %d (1)\n", t >= -1); - printf("\n"); - - pi = -100; - printf(" pi<4 = %d (0)\n", pi < (int*)4); - printf(" pi<3 = %d (0)\n", pi < (int*)3); - printf("pi<-100 = %d (0)\n", pi < (int*)-100); - printf(" pi<-1 = %d (1)\n", pi < (int*)-1); - printf("\n"); - - printf(" pi<=4 = %d (0)\n", pi <= (int*)4); - printf(" pi<=3 = %d (0)\n", pi <= (int*)3); - printf("pi<=-100 = %d (1)\n", pi <= (int*)-100); - printf(" pi<=-1 = %d (1)\n", pi <= (int*)-1); - printf("\n"); - - pi = -100; - printf(" pi>4 = %d (1)\n", pi > (int*)4); - printf(" pi>3 = %d (1)\n", pi > (int*)3); - printf("pi>-100 = %d (0)\n", pi > (int*)-100); - printf(" pi>-1 = %d (0)\n", pi > (int*)-1); - printf("\n"); - - printf(" pi>=4 = %d (1)\n", pi >= (int*)4); - printf(" pi>=3 = %d (1)\n", pi >= (int*)3); - printf("pi>=-100 = %d (1)\n", pi >= (int*)-100); - printf(" pi>=-1 = %d (0)\n", pi >= (int*)-1); - printf("\n"); - - pi = &arr[0]; - pip = &arr[3]; - printf(" *pip - *pi: %d (30)\n", *pip - *pi); - printf(" pip - pi: %d (3)\n", pip - pi); - printf(" *pip: %d (40)\n", *pip); - printf(" *(pip - 3): %d (10)\n", *(pip - 3)); - printf(" *&arr[3]: %d (40)\n", *&arr[3]); - printf("*(&arr[3] - 3): %d (10)\n", *(&arr[3]-3)); -} diff --git a/share/smallerc/test2.c b/share/smallerc/test2.c deleted file mode 100644 index e15b3f9..0000000 --- a/share/smallerc/test2.c +++ /dev/null @@ -1,128 +0,0 @@ -#include -#include -#include -#include - -int aaa; -int bbb; -int ccc; -char gc; -char gbuffer[3]; -int gibuffer[4]; - -int main(void) -{ - char b; - int la; - unsigned int u1, u2; - int s1, s2; - unsigned char uc1, uc2; - char sc1, sc2; - int fd; - char buffer[6]; - int ibuffer[7]; - - printf(" sizeof(uc1): %d 1\n", sizeof(uc1)); - printf(" sizeof(sc1): %d 1\n", sizeof(sc1)); - printf(" sizeof(u1): %d 4\n", sizeof(u1)); - printf(" sizeof(s1): %d 4\n", sizeof(s1)); - printf(" sizeof(aaa): %d 4\n", sizeof(aaa)); - printf(" sizeof(bbb): %d 4\n", sizeof(bbb)); - printf(" sizeof(gc): %d 1\n", sizeof(gc)); - printf(" sizeof(buffer): %d 6\n", sizeof(buffer)); - printf(" sizeof(ibuffer): %d 28\n", sizeof(ibuffer)); - printf(" sizeof(char): %d 1\n", sizeof(char)); - printf(" sizeof(int): %d 4\n", sizeof(int)); - printf(" sizeof(gbuffer): %d 3\n", sizeof(gbuffer)); - printf(" sizeof(gibuffer): %d 16\n", sizeof(gibuffer)); - // sizeof(ibuffer[0]) is not supported, so the following can be used... - printf("sizeof(ibuffer)/sizeof(int): %d 7\n", sizeof(ibuffer)/sizeof(int)); - - aaa = 1; - bbb = 2; - la = 4; - printf("%d 1\n", aaa); - printf("%d 2\n", bbb); - printf("%d 4\n", la); - - uc1 = 0x80; - sc1 = 0x80; - s1 = uc1; - s2 = sc1; - printf("unsigned char (0x80) -> int: %d 128\n", s1); - printf(" signed char (0x80) -> int: %d -128\n", s2); - - u1 = uc1; - u2 = sc1; - printf("unsigned char (0x80) -> unsigned: %d 128\n", u1); - printf(" signed char (0x80) -> unsigned: %d -128\n", u2); - - la = errno; - printf("errno: %d 0\n", la); - - write(1, "abcd ", 5); - la = errno; - printf("errno after good write call: %d 0\n", la); - - write(10, "abcde", 5); - la = errno; - printf("errno after bad write call: %d 9\n", la); - - write(1, "abcd ", 5); - la = errno; - printf("good write after failed should not overwrite errno: %d 9\n", la); - - errno = 0; - write(1, "abcd ", 5); - la = errno; - printf("good write after errno set to zero: %d 0\n", la); - - la = write(1, "abcd ", 5); - printf("write() return: %d 5\n", la); - - la = write(10, "abcd ", 5); - printf("write(bad fd) return: %d -1\n", la); - - fd = open("/a.txt", O_WRONLY | O_CREAT, 0666); - if (fd != -1) { - printf("open success\n"); - la = write(fd, "abcd\n", 5); - if (la == 5) printf("write success\n"); else printf("write failed\n"); - la = close(fd); - if (la != -1) printf("close success\n"); else printf("close failed\n"); - } else { - printf("open failed\n"); - } - - buffer[0] = 0; - buffer[1] = 0; - buffer[2] = 0; - buffer[3] = 0; - buffer[4] = 0; - buffer[5] = 0; - - fd = open("/a.txt", O_RDONLY, 0666); - if (fd != -1) { - printf("open success\n"); - la = read(fd, buffer, 5); - printf(buffer); - if (la == 5) printf("read success\n"); else printf("read failed\n"); - la = close(fd); - if (la != -1) printf("close success\n"); else printf("close failed\n"); - } else { - printf("open failed\n"); - } - - if (buffer[0] != 'a') printf("data0 readback from file MISMATCH\n"); - if (buffer[1] != 'b') printf("data1 readback from file MISMATCH\n"); - if (buffer[2] != 'c') printf("data2 readback from file MISMATCH\n"); - if (buffer[3] != 'd') printf("data3 readback from file MISMATCH\n"); - if (buffer[4] != '\n') printf("data4 readback from file MISMATCH\n"); - - if (buffer[0] != 'a' || buffer[1] != 'b' || buffer[2] != 'c' || - buffer[3] != 'd' || buffer[4] != '\n') { - printf("data readback from file MISMATCH\n"); - } else { - printf("data readback from file OK\n"); - } -} diff --git a/share/smallerc/test3.c b/share/smallerc/test3.c deleted file mode 100644 index 0155783..0000000 --- a/share/smallerc/test3.c +++ /dev/null @@ -1,51 +0,0 @@ -#include - -void printt(int t, char* str); - -int main(void) -{ - int t; - - t = 0; - if (t) printt(t, "failure"); else printt(t, "success"); - t = 1; - if (t) printt(t, "success"); else printt(t, "failure"); - t = 8; - if (t) printt(t, "success"); else printt(t, "failure"); - t = -2; - if (t) printt(t, "success"); else printt(t, "failure"); - printf("\n"); - - t = 4; - printf("switch test: "); - switch (t) { - case 3: - printf("failure"); - break; - case 4: - printf("success"); - break; - case 5: - printf("failure"); - break; - } - printf("\n"); - - printf("switch fallthrough test: "); - switch (t) { - case 3: - printf("failure"); - break; - case 4: - printf("OKSOFAR: "); - case 5: - printf("success if oksofar printed before this in caps"); - break; - } - printf("\n"); -} - -void printt(int t, char* str) -{ - printf("bool test on value %d %s\n", t, str); -} diff --git a/src/Makefile b/src/Makefile index cf43117..8dc58f5 100644 --- a/src/Makefile +++ b/src/Makefile @@ -9,7 +9,7 @@ include $(TOPSRC)/target.mk # Programs that live in subdirectories, and have makefiles of their own. # SUBDIR = startup-$(MACHINE) libc libm libutil libtermlib libcurses \ - libvmf libwiznet share cmd games man + libvmf libwiznet share cmd games all: $(SUBDIR) @@ -21,7 +21,7 @@ FRC: install: elf32-mips.ld -for i in $(SUBDIR); do \ $(MAKE) -C $$i DESTDIR=$(DESTDIR) all install; done -# cp -p elf32-mips.ld $(DESTDIR)/lib/elf32-mips.ld + cp -p elf32-mips.ld $(DESTDIR)/lib/elf32-mips.ld clean: rm -f a.out core *.s *.o *.a *~ diff --git a/src/cmd/.gitignore b/src/cmd/.gitignore deleted file mode 100644 index 0253bbf..0000000 --- a/src/cmd/.gitignore +++ /dev/null @@ -1,72 +0,0 @@ -basename -bc -cal -cat -cb -chgrp -chmod -cmp -col -comm -cp -dd -df -diskspeed -du -echo -ed -egrep -expr -expr.c -false -fgrep -file -grep -head -hostid -iostat -join -kill -last -ln -mail -mesg -mkdir -mv -nice -nohup -od -pagesize -pr -printenv -ps -pwd -rev -rm -rmail -rmdir -size -sleep -sort -split -strip -su -sum -sync -tail -tar -tee -time -touch -tr -true -tsort -tty -uniq -vmstat -w -wall -wc -whereis -who -write diff --git a/src/cmd/Makefile b/src/cmd/Makefile index ccb63fe..e080fc7 100644 --- a/src/cmd/Makefile +++ b/src/cmd/Makefile @@ -10,14 +10,13 @@ CFLAGS += -Werror # Programs that live in subdirectories, and have makefiles of their own. # /bin -SUBDIR = adb adc-demo aout ar as awk basic cc chflags chpass \ - cpp dc diff emg env fdisk find forth fstat glcdtest \ - hostname id la lcc lcpp ld ls login make man med \ +SUBDIR = adb adc-demo ar as awk basic cc chflags chpass \ + cpp dc diff env find forth fstat glcdtest hostname \ + id la lcc lcpp ld ls login make man med \ more nm passwd picoc portio printf pwm \ - rdprof ranlib re renice retroforth scm setty sl \ - sed sh smallc smlrc stty sysctl test uname wiznet xargs \ - zmodem gtest msec unixbench cron compress date2 tip \ - talloc devupdate uucp smux + ranlib re renice retroforth scm setty sl \ + sed sh smallc stty sysctl test uname wiznet xargs \ + zmodem gtest # /sbin SUBDIR += chown chroot disktool fsck getty init \ @@ -33,11 +32,11 @@ SCRIPT = false nohup true #lorder mkdep # C programs that live in the current directory and do not need # explicit make lines. # -STD = basename cal cat cb chgrp chmod cmp col comm cp dd \ - diskspeed du echo ed fgrep file grep head hostid join \ - kill last ln mesg mkdir mv nice od pagesize pr printenv \ - pwd rev rm rmail rmdir size sleep sort split sum sync \ - tail tar tee time touch tr tsort tty uniq w wc whereis who +STD = basename cal cat cb chgrp chmod cmp col comm cp date dd du \ + echo ed fgrep file grep head hostid join kill last ln \ + mesg mkdir mv nice od pagesize pr printenv pwd rev rm rmail rmdir \ + size sleep sort split sum sync tail tar tee time touch tr \ + tsort tty uniq w wc whereis who # C programs that live in the current directory and need explicit make lines. # diff --git a/src/cmd/adb/.gitignore b/src/cmd/adb/.gitignore deleted file mode 100644 index 06e7af1..0000000 --- a/src/cmd/adb/.gitignore +++ /dev/null @@ -1 +0,0 @@ -adb diff --git a/src/cmd/adb/Makefile b/src/cmd/adb/Makefile index baaff88..7e8bbe3 100644 --- a/src/cmd/adb/Makefile +++ b/src/cmd/adb/Makefile @@ -1,7 +1,6 @@ TOPSRC = $(shell cd ../../..; pwd) include $(TOPSRC)/target.mk #include $(TOPSRC)/cross.mk -#CFLAGS = -DCROSS -I$(TOPSRC)/include -I/usr/include -D__mips__ -ggdb3 OBJS = message.o access.o command.o expr.o findfn.o format.o input.o \ main.o opset.o output.o pcs.o print.o \ diff --git a/src/cmd/adb/access.c b/src/cmd/adb/access.c index 3b0b804..05d022e 100644 --- a/src/cmd/adb/access.c +++ b/src/cmd/adb/access.c @@ -2,7 +2,6 @@ * File handling and access routines */ #include "defs.h" -#include static int within(adr, lbd, ubd) @@ -60,7 +59,7 @@ acces(mode, adr, space, value) long adr; { int w, w1, pmode, rd, file; - BKPTR bkptr; + BKPTR bkptr, scanbkpt(); if (space == NSP) return 0; @@ -90,7 +89,7 @@ acces(mode, adr, space, value) return w; } w = 0; - if (mode==WT && wtflag==O_RDONLY) { + if (mode==WT && wtflag==0) { error("not in write mode"); } if (! chkmap(&adr, space)) diff --git a/src/cmd/adb/command.c b/src/cmd/adb/command.c index 41495d3..4f8b601 100644 --- a/src/cmd/adb/command.c +++ b/src/cmd/adb/command.c @@ -190,8 +190,7 @@ trypr: regptr = getreg(savc); if (regptr != NOREG) { uframe[regptr] = shorten(dot); - ptrace(PT_WRITE_U, pid, (char*) (KERNEL_DATA_END - USIZE) + - ((char*)&uframe[regptr] - (char*)&corhdr), + ptrace(PT_WRITE_U, pid, &uframe[regptr] - (int)&corhdr, uframe[regptr]); } else if ((modifier = varchk(savc)) != -1) { var[modifier] = dot; diff --git a/src/cmd/adb/cross/Makefile b/src/cmd/adb/cross/Makefile deleted file mode 100644 index ec6b072..0000000 --- a/src/cmd/adb/cross/Makefile +++ /dev/null @@ -1,55 +0,0 @@ -TOPSRC = $(shell cd ../../../..; pwd) -include $(TOPSRC)/cross.mk - -vpath %.c .. - -# Build a list of the host include directories. -CPP = $(shell gcc -print-prog-name=cc1) -HOSTINC = $(addprefix -I,$(shell echo | $(CPP) -v 2>&1 | grep '^ /.*include')) -HOSTINC += -I/usr/include/i386-linux-gnu - -CFLAGS = -m32 -g -DCROSS -nostdinc -I. $(HOSTINC) -I.. -D__mips__ -CFLAGS += -Wall -Werror -DNUM_SYMS_CACHE=50 -fno-builtin -LDFLAGS += -m32 -g - -OBJS = message.o access.o command.o expr.o findfn.o format.o input.o \ - main.o opset.o output.o pcs.o print.o \ - runpcs.o setup.o sym.o -HEADERS = a.out.h nlist.h time.h signal.h stdlib.h \ - sys/exec.h sys/types.h sys/param.h sys/user.h \ - sys/time.h sys/dir.h sys/resource.h sys/select.h \ - sys/signal.h sys/wait.h \ - machine/io.h machine/machparam.h - -all: $(HEADERS) adb - -adb: $(OBJS) - $(CC) $(LDFLAGS) $(OBJS) -o $@ - -clean: - rm -f *~ *.o adb *.h */*.h gccdump.s - -$(HEADERS): - ln -s -f ../../../../include/a.out.h . - ln -s -f ../../../../include/nlist.h . - ln -s -f ../../../../include/time.h . - ln -s -f ../../../../include/stdlib.h . - ln -s -f sys/signal.h . - ln -s -f ../../../../../include/sys/exec.h sys/ - ln -s -f ../../../../../include/sys/param.h sys/ - ln -s -f ../../../../../include/sys/user.h sys/ - ln -s -f ../../../../../include/sys/types.h sys/ - ln -s -f ../../../../../include/sys/time.h sys/ - ln -s -f ../../../../../include/sys/dir.h sys/ - ln -s -f ../../../../../include/sys/resource.h sys/ - ln -s -f ../../../../../include/sys/select.h sys/ - ln -s -f ../../../../../include/sys/wait.h sys/ - ln -s -f ../../../../../include/sys/signal.h sys/ - ln -s -f ../../../../../include/machine/io.h machine/ - ln -s -f ../../../../../include/machine/machparam.h machine/ - -test: - echo '$$q' | ./adb fsck fsck.core - @printf '\n----------------------------\n' - echo '$$m' | ./adb fsck fsck.core - @printf '\n----------------------------\n' diff --git a/src/cmd/adb/defs.h b/src/cmd/adb/defs.h index 2b6f244..f30af3d 100644 --- a/src/cmd/adb/defs.h +++ b/src/cmd/adb/defs.h @@ -8,22 +8,16 @@ * This has changed over time - see a.out.h, sys/exec.h and nlist.h * for the current a.out definition and format. */ -#include #include #include #include +#include #include #include #include #include #include #include -#ifdef CROSS -# include -# define sgttyb termios -#else -# include -#endif #define MAXSYMLEN 32 #define MAXCOM 64 @@ -55,6 +49,7 @@ typedef struct map MAP; typedef MAP *MAPPTR; typedef struct bkpt BKPT; typedef BKPT *BKPTR; +typedef struct user U; /* file address maps */ struct map { @@ -134,9 +129,7 @@ typedef struct reglist REGLIST; #define MAXPOS 80 #define MAXLIN 128 -#ifndef TRUE - #define TRUE (-1) -#endif +#define TRUE (-1) #define FALSE 0 #define LOBYTE 0377 #define HIBYTE 0177400 @@ -150,7 +143,7 @@ typedef struct reglist REGLIST; /* long to ints and back (puns) */ #define leng(a) ((long)((unsigned)(a))) -#define shorten(a) ((long)a) +#define shorten(a) ((int)a) struct sgttyb adbtty, usrtty; jmp_buf erradb; diff --git a/src/cmd/adb/doc/adb-figures.ms b/src/cmd/adb/doc/adb-figures.ms deleted file mode 100644 index 8366473..0000000 --- a/src/cmd/adb/doc/adb-figures.ms +++ /dev/null @@ -1,961 +0,0 @@ -.sp 100 -.nr PS 9 -.nr VS 11 -. \" START OF Figures -.de P1 -.nf -.in +.5i -.ta .5i 1i 1.5i 2i 2.5i 3i 3.5i 4i 4.5i 5i -.sp -.ps 9 -.vs 11p -.. -.de P2 -.sp -.fi -.ps \\n(PS -.vs \\n(VS -.in -.5i -.. -.SH -Figure 1: C program with pointer bug -.LP -.P1 -struct buf { - int fildes; - int nleft; - char *nextp; - char buff[512]; - }bb; -struct buf *obuf; - -char *charp "this is a sentence."; - -main(argc,argv) -int argc; -char **argv; -{ - char cc; - - if(argc < 2) { - printf("Input file missing\\n"); - exit(8); - } - - if((fcreat(argv[1],obuf)) < 0){ - printf("%s : not found\\n", argv[1]); - exit(8); - } - charp = \'T\'; -printf("debug 1 %s\\n",charp); - while(cc= *charp++) - putc(cc,obuf); - fflush(obuf); -} -.P2 -.sp 100 -.SH -Figure 2: ADB output for C program of Figure 1 -.LP -.P1 -.ft B -adb a.out core -$c -.ft R -~main(02,0177762) -.ft B -$C -.ft R -~main(02,0177762) - argc: 02 - argv: 0177762 - cc: 02124 -.ft B -$r -.ft R -ps 0170010 -pc 0204 ~main+0152 -sp 0177740 -r5 0177752 -r4 01 -r3 0 -r2 0 -r1 0 -r0 0124 -~main+0152: mov _obuf,(sp) -.ft B -$e -.ft R -savr5: 0 -_obuf: 0 -_charp: 0124 -_errno: 0 -_fout: 0 -.ft B -$m -.ft R -text map \`ex1\' -b1 = 0 e1 = 02360 f1 = 020 -b2 = 0 e2 = 02360 f2 = 020 -data map \`core1\' -b1 = 0 e1 = 03500 f1 = 02000 -b2 = 0175400 e2 = 0200000 f2 = 05500 -.ft B -*charp/s -.ft R -0124: TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTLx Nh@x&_ -~ -.ft B -charp/s -.ft R -_charp: T - -_charp+02: this is a sentence. - -_charp+026: Input file missing -.ft B -main.argc/d -.ft R -0177756: 2 -.ft B -*main.argv/3o -.ft R -0177762: 0177770 0177776 0177777 -.ft B -0177770/s -.ft R -0177770: a.out -.ft B -*main.argv/3o -.ft R -0177762: 0177770 0177776 0177777 -.ft B -*"/s -.ft R -0177770: a.out -.ft B - .=o -.ft R - 0177770 -.ft B - .\(mi10/d -.ft R -0177756: 2 -.ft B -$q -.P2 -.sp 100 -.SH -Figure 3: Multiple function C program for stack trace illustration -.LP -.P1 -int fcnt,gcnt,hcnt; -h(x,y) -{ - int hi; register int hr; - hi = x+1; - hr = x\(miy+1; - hcnt++ ; - hj: - f(hr,hi); -} - -g(p,q) -{ - int gi; register int gr; - gi = q\(mip; - gr = q\(mip+1; - gcnt++ ; - gj: - h(gr,gi); -} - -f(a,b) -{ - int fi; register int fr; - fi = a+2*b; - fr = a+b; - fcnt++ ; - fj: - g(fr,fi); -} - -main() -{ - f(1,1); -} -.P2 -.sp 100 -.SH -Figure 4: ADB output for C program of Figure 3 -.LP -.P1 -.ft B -adb -$c -.ft R -~h(04452,04451) -~g(04453,011124) -~f(02,04451) -~h(04450,04447) -~g(04451,011120) -~f(02,04447) -~h(04446,04445) -~g(04447,011114) -~f(02,04445) -~h(04444,04443) -.ft B -HIT DEL KEY -.ft R -adb -.ft B -,5$C -.ft R -~h(04452,04451) - x: 04452 - y: 04451 - hi: ? -~g(04453,011124) - p: 04453 - q: 011124 - gi: 04451 - gr: ? -~f(02,04451) - a: 02 - b: 04451 - fi: 011124 - fr: 04453 -~h(04450,04447) - x: 04450 - y: 04447 - hi: 04451 - hr: 02 -~g(04451,011120) - p: 04451 - q: 011120 - gi: 04447 - gr: 04450 -.ft B -fcnt/d -.ft R -_fcnt: 1173 -.ft B -gcnt/d -.ft R -_gcnt: 1173 -.ft B -hcnt/d -.ft R -_hcnt: 1172 -.ft B -h.x/d -.ft R -022004: 2346 -.ft B -$q -.P2 -.sp 100 -.SH -Figure 5: C program to decode tabs -.LP -.P1 -#define MAXLINE 80 -#define YES 1 -#define NO 0 -#define TABSP 8 -.sp .5 -char input[] "data"; -char ibuf[518]; -int tabs[MAXLINE]; -.sp .5 -main() -{ - int col, *ptab; - char c; -.sp .5 - ptab = tabs; - settab(ptab); /*Set initial tab stops */ - col = 1; - if(fopen(input,ibuf) < 0) { - printf("%s : not found\\n",input); - exit(8); - } - while((c = getc(ibuf)) != \(mi1) { - switch(c) { - case \(fm\\t\(fm: /* TAB */ - while(tabpos(col) != YES) { - putchar(\(fm \(fm); /* put BLANK */ - col++ ; - } - break; - case \(fm\\n\(fm: /*NEWLINE */ - putchar(\(fm\\n\(fm); - col = 1; - break; - default: - putchar(c); - col++ ; - } - } -} -.sp .5 -/* Tabpos return YES if col is a tab stop */ -tabpos(col) -int col; -{ - if(col > MAXLINE) - return(YES); - else - return(tabs[col]); -} -.sp .5 -/* Settab - Set initial tab stops */ -settab(tabp) -int *tabp; -{ - int i; -.sp .5 - for(i = 0; i<= MAXLINE; i++) - (i%TABSP) ? (tabs[i] = NO) : (tabs[i] = YES); -} -.P2 -.sp 100 -.SH -Figure 6a: ADB output for C program of Figure 5 -.LP -.P1 -.ft B -adb a.out \(mi -settab+4:b -fopen+4:b -getc+4:b -tabpos+4:b -$b -.ft R -breakpoints -count bkpt command -1 ~tabpos+04 -1 _getc+04 -1 _fopen+04 -1 ~settab+04 -.ft B -settab,5?ia -.ft R -~settab: jsr r5,csv -~settab+04: tst \(mi(sp) -~settab+06: clr 0177770(r5) -~settab+012: cmp $0120,0177770(r5) -~settab+020: blt ~settab+076 -~settab+022: -.ft B -settab,5?i -.ft R -~settab: jsr r5,csv - tst \(mi(sp) - clr 0177770(r5) - cmp $0120,0177770(r5) - blt ~settab+076 -.ft B -:r -.ft R -a.out: running -breakpoint ~settab+04: tst \(mi(sp) -.ft B -settab+4:d -:c -.ft R -a.out: running -breakpoint _fopen+04: mov 04(r5),nulstr+012 -.ft B -$C -.ft R -_fopen(02302,02472) -~main(01,0177770) - col: 01 - c: 0 - ptab: 03500 -.ft B -tabs,3/8o -.ft R -03500: 01 0 0 0 0 0 0 0 - 01 0 0 0 0 0 0 0 - 01 0 0 0 0 0 0 0 -.P2 -.sp 100 -.SH -Figure 6b: ADB output for C program of Figure 5 -.LP -.P1 -.ft B -:c -.ft R -a.out: running -breakpoint _getc+04: mov 04(r5),r1 -.ft B -ibuf+6/20c -.ft R -__cleanu+0202: This is a test of -.ft B -:c -.ft R -a.out: running -breakpoint ~tabpos+04: cmp $0120,04(r5) -.ft B -tabpos+4:d -settab+4:b settab,5?ia -settab+4:b settab,5?ia; 0 -getc+4,3:b main.c?C; 0 -settab+4:b settab,5?ia; ptab/o; 0 -$b -.ft R -breakpoints -count bkpt command -1 ~tabpos+04 -3 _getc+04 main.c?C;0 -1 _fopen+04 -1 ~settab+04 settab,5?ia;ptab?o;0 -~settab: jsr r5,csv -~settab+04: bpt -~settab+06: clr 0177770(r5) -~settab+012: cmp $0120,0177770(r5) -~settab+020: blt ~settab+076 -~settab+022: -0177766: 0177770 -0177744: @\` -T0177744: T -h0177744: h -i0177744: i -s0177744: s -.P2 -.sp 100 -.SH -Figure 7: ADB output for C program with breakpoints -.LP -.in +.5i -.nf -.ps 8 -.vs 9 -.ft B -adb ex3 \(mi -h+4:b hcnt/d; h.hi/; h.hr/ -g+4:b gcnt/d; g.gi/; g.gr/ -f+4:b fcnt/d; f.fi/; f.fr/ -:r -.ft R -ex3: running -_fcnt: 0 -0177732: 214 -symbol not found -.ft B -f+4:b fcnt/d; f.a/; f.b/; f.fi/ -g+4:b gcnt/d; g.p/; g.q/; g.gi/ -h+4:b hcnt/d; h.x/; h.y/; h.hi/ -:c -.ft R -ex3: running -_fcnt: 0 -0177746: 1 -0177750: 1 -0177732: 214 -_gcnt: 0 -0177726: 2 -0177730: 3 -0177712: 214 -_hcnt: 0 -0177706: 2 -0177710: 1 -0177672: 214 -_fcnt: 1 -0177666: 2 -0177670: 3 -0177652: 214 -_gcnt: 1 -0177646: 5 -0177650: 8 -0177632: 214 -.ft B -HIT DEL -f+4:b fcnt/d; f.a/"a = "d; f.b/"b = "d; f.fi/"fi = "d -g+4:b gcnt/d; g.p/"p = "d; g.q/"q = "d; g.gi/"gi = "d -h+4:b hcnt/d; h.x/"x = "d; h.y/"h = "d; h.hi/"hi = "d -:r -.ft R -ex3: running -_fcnt: 0 -0177746: a = 1 -0177750: b = 1 -0177732: fi = 214 -_gcnt: 0 -0177726: p = 2 -0177730: q = 3 -0177712: gi = 214 -_hcnt: 0 -0177706: x = 2 -0177710: y = 1 -0177672: hi = 214 -_fcnt: 1 -0177666: a = 2 -0177670: b = 3 -0177652: fi = 214 -.ft B -HIT DEL -$q -.in -.5i -.sp 100 -.SH -Figure 8: ADB address maps -.LP -.de l1 -.tc -.ta 1.20i +1.6i +2.5i -.. -.de l3 -.tc -.ta 1.6i +2.80i +.2i +1.55i -.. -.de l2 -.tc -.ti 1.0i -.ta +0.5i +3.0i +1.75i -.tc _ -.. -.de l5 -.tc -.ti 1.0i -.ta +0.75i +3.0i +1.5i -.tc _ -.. -.de l6 -.tc -.ti 1.0i -.ta +.8i +2.85i +0.4i +1.1i -.. -.de l8 -.tc -.ti 1.0i -.ta +0.5i +3.0i +1.75i -.tc _ -.. -.de la -.tc -.ta 1.20i +1.25i +1.7i -.. -.de lc -.tc -.ti 1.0i -.ta +.85i +1.6i +.35i +1.1i -.. -.de lb -.tc -.ti 1.0i -.ta +0.75i +1.75i +1.5i -.tc _ -.. -.ul -407 files -.sp -.l1 -a.out hdr text+data -.l2 -| | | -.l3 - 0 D -.sp -.l1 -core hdr text+data stack -.l5 -| | ......| | -.l6 - 0 D S E -.sp 2 -.ul -410 files (shared text) -.sp -.l1 -a.out hdr text data -.l2 -| | | | -.l3 - 0 T B D -.sp -.la -core hdr data stack -.lb -| | ......| | -.lc - B D S E -.sp 2 -.ul -411 files (separated I and D space) -.sp -.l1 -a.out hdr text data -.l2 -| | | | -.l3 - 0 T 0 D -.sp -.la -core hdr data stack -.lb -| | ......| | -.lc - 0 D S E -.sp 2 -The following -.ul -adb -variables are set. -.nf -.ta .75i 1.5i 3.5i 4.5i 5.5i -.sp - 407 410 411 -.sp - b base of data 0 B 0 - d length of data D D\(miB D - s length of stack S S S - t length of text 0 T T -.sp 100 -.SH -Figure 9: ADB output for maps -.LP -.nf -.in +.5i -.ft B -adb map407 core407 -$m -.ft R -text map \`map407\' -b1 = 0 e1 = 0256 f1 = 020 -b2 = 0 e2 = 0256 f2 = 020 -data map \`core407\' -b1 = 0 e1 = 0300 f1 = 02000 -b2 = 0175400 e2 = 0200000 f2 = 02300 -.ft B -$v -.ft R -variables -d = 0300 -m = 0407 -s = 02400 -.ft B -$q -.sp 2 -adb map410 core410 -$m -.ft R -text map \`map410\' -b1 = 0 e1 = 0200 f1 = 020 -b2 = 020000 e2 = 020116 f2 = 0220 -data map \`core410\' -b1 = 020000 e1 = 020200 f1 = 02000 -b2 = 0175400 e2 = 0200000 f2 = 02200 -.ft B -$v -.ft R -variables -b = 020000 -d = 0200 -m = 0410 -s = 02400 -t = 0200 -.ft B -$q -.sp 2 -adb map411 core411 -$m -.ft R -text map \`map411\' -b1 = 0 e1 = 0200 f1 = 020 -b2 = 0 e2 = 0116 f2 = 0220 -data map \`core411\' -b1 = 0 e1 = 0200 f1 = 02000 -b2 = 0175400 e2 = 0200000 f2 = 02200 -.ft B -$v -.ft R -variables -d = 0200 -m = 0411 -s = 02400 -t = 0200 -.ft B -$q -.in -.5i -.sp 100 -.SH -Figure 10: Simple C program for illustrating formatting and patching -.LP -.P1 -char str1[] "This is a character string"; -int one 1; -int number 456; -long lnum 1234; -float fpt 1.25; -char str2[] "This is the second character string"; -main() -{ - one = 2; -} -.P2 -.sp 100 -.SH -Figure 11: ADB output illustrating fancy formats -.LP -.nf -.ps 9 -.vs 11p -.ft B -adb map410 core410 -b -?m\fIname\fR assign dot to variable or register \fIname\fR -.sp 100 -.SH -Format Summary -.LP -.ta .7i -.nf -\fBa \fRthe value of dot -\fBb \fRone byte in octal -\fBc \fRone byte as a character -\fBd \fRone word in decimal -\fBf \fRtwo words in floating point -\fBi \fRPDP 11 instruction -\fBo \fRone word in octal -\fBn \fRprint a newline -\fBr \fRprint a blank space -\fBs \fRa null terminated character string -\fIn\fBt \fRmove to next \fIn\fR space tab -\fBu \fRone word as unsigned integer -\fBx \fRhexadecimal -\fBY \fRdate -\fB^ \fRbackup dot -\fB"..."\fR print string -.LP -.ta .7i -.SH -Expression Summary -.LP -.ta .7i -a) expression components -.LP -.ta .1.1i -.nf -\fBdecimal integer \fRe.g. 256 -\fBoctal integer \fRe.g. 0277 -\fBhexadecimal \fRe.g. #ff -\fBsymbols \fRe.g. flag _main main.argc -\fBvariables \fRe.g. - struct buf { - int fildes; - int nleft; - char *nextp; - char buff[512]; - }bb; - struct buf *obuf; - - char *charp "this is a sentence."; - - main(argc,argv) - int argc; - char **argv; - { - char cc; - - if(argc < 2) { - printf("Input file missing\n"); - exit(8); - } - - if((fcreat(argv[1],obuf)) < 0){ - printf("%s : not found\n", argv[1]); - exit(8); - } - charp = 'T'; - printf("debug 1 %s\n",charp); - while(cc= *charp++) - putc(cc,obuf); - fflush(obuf); - } - - -=== Figure 2: ADB output for C program of Figure 1 === - **adb a.out core** - **$c** - ~main(02,0177762) - **$C** - ~main(02,0177762) - argc: 02 - argv: 0177762 - cc: 02124 - **$r** - ps 0170010 - pc 0204 ~main+0152 - sp 0177740 - r5 0177752 - r4 01 - r3 0 - r2 0 - r1 0 - r0 0124 - ~main+0152: mov _obuf,(sp) - **$e** - savr5: 0 - _obuf: 0 - _charp: 0124 - _errno: 0 - _fout: 0 - **$m** - text map `ex1' - b1 = 0 e1 = 02360 f1 = 020 - b2 = 0 e2 = 02360 f2 = 020 - data map `core1' - b1 = 0 e1 = 03500 f1 = 02000 - b2 = 0175400 e2 = 0200000 f2 = 05500 - ***charp/s** - 0124: TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTLxNh@x&_ - ~ - **charp/s** - _charp: T - - _charp+02: this is a sentence. - - _charp+026: Input file missing - **main.argc/d** - 0177756: 2 - ***main.argv/3o** - 0177762: 0177770 0177776 0177777 - **0177770/s** - 0177770: a.out - ***main.argv/3o** - 0177762: 0177770 0177776 0177777 - ***"/s** - 0177770: a.out - **.=o** - 0177770 - **.-10/d** - 0177756: 2 - **$q** - -=== Figure 3: Multiple function C program for stack trace === - - int fcnt,gcnt,hcnt; - h(x,y) - { - int hi; register int hr; - hi = x+1; - hr = x-y+1; - hcnt++ ; - hj: - f(hr,hi); - } - - g(p,q) - { - int gi; register int gr; - gi = q-p; - gr = q-p+1; - gcnt++ ; - gj: - h(gr,gi); - } - - f(a,b) - { - int fi; register int fr; - fi = a+2*b; - fr = a+b; - fcnt++ ; - fj: - g(fr,fi); - } - - main() - { - f(1,1); - } - - -=== Figure 4: ADB output for C program of Figure 3 === - **adb** - **$c** - ~h(04452,04451) - ~g(04453,011124) - ~f(02,04451) - ~h(04450,04447) - ~g(04451,011120) - ~f(02,04447) - ~h(04446,04445) - ~g(04447,011114) - ~f(02,04445) - ~h(04444,04443) - **HIT DEL KEY** - adb - **,5$C** - ~h(04452,04451) - x: 04452 - y: 04451 - hi: ? - ~g(04453,011124) - p: 04453 - q: 011124 - gi: 04451 - gr: ? - ~f(02,04451) - a: 02 - b: 04451 - fi: 011124 - fr: 04453 - ~h(04450,04447) - x: 04450 - y: 04447 - hi: 04451 - hr: 02 - ~g(04451,011120) - p: 04451 - q: 011120 - gi: 04447 - gr: 04450 - **fcnt/d** - _fcnt: 1173 - **gcnt/d** - _gcnt: 1173 - **hcnt/d** - _hcnt: 1172 - **h.x/d** - 022004: 2346 - **$q** - -=== Figure 5: C program to decode tabs === - - #define MAXLINE 80 - #define YES 1 - #define NO 0 - #define TABSP 8 - char input[] "data"; - char ibuf[518]; - int tabs[MAXLINE]; - main() - { - int col, *ptab; - char c; - ptab = tabs; - settab(ptab); /*Set initial tab stops */ - col = 1; - if(fopen(input,ibuf) < 0) { - printf("%s : not found\n",input); - exit(8); - } - while((c = getc(ibuf)) != -1) { - switch(c) { - case '\t': /* TAB */ - while(tabpos(col) != YES) { - putchar(' '); /* put BLANK */ - col++ ; - } - break; - case '\n': /*NEWLINE */ - putchar('\n'); - col = 1; - break; - default: - putchar(c); - col++ ; - } - } - } - /* Tabpos return YES if col is a tab stop */ - tabpos(col) - int col; - { - if(col > MAXLINE) - return(YES); - else - return(tabs[col]); - } - /* Settab - Set initial tab stops */ - settab(tabp) - int *tabp; - { - int i; - for(i = 0; i<= MAXLINE; i++) - (i%TABSP) ? (tabs[i] = NO) : (tabs[i] = YES); - } - - -=== Figure 6a: ADB output for C program of Figure 5 === - **adb a.out -** - **settab+4:b** - **fopen+4:b** - **getc+4:b** - **tabpos+4:b** - **$b** - breakpoints - count bkpt command - 1 ~tabpos+04 - 1 _getc+04 - 1 _fopen+04 - 1 ~settab+04 - **settab,5?ia** - ~settab: jsr r5,csv - ~settab+04: tst -(sp) - ~settab+06: clr 0177770(r5) - ~settab+012: cmp $0120,0177770(r5) - ~settab+020: blt ~settab+076 - ~settab+022: - **settab,5?i** - ~settab: jsr r5,csv - tst -(sp) - clr 0177770(r5) - cmp $0120,0177770(r5) - blt ~settab+076 - **:r** - a.out: running - breakpoint ~settab+04: tst -(sp) - **settab+4:d** - **:c** - a.out: running - breakpoint _fopen+04: mov 04(r5),nulstr+012 - **$C** - _fopen(02302,02472) - ~main(01,0177770) - col: 01 - c: 0 - ptab: 03500 - **tabs,3/8o** - 03500: 01 0 0 0 0 0 0 0 - 01 0 0 0 0 0 0 0 - 01 0 0 0 0 0 0 0 - - -=== Figure 6b: ADB output for C program of Figure 5 === - **:c** - a.out: running - breakpoint _getc+04: mov 04(r5),r1 - **ibuf+6/20c** - __cleanu+0202: This is a test of - **:c** - a.out: running - breakpoint ~tabpos+04: cmp $0120,04(r5) - **tabpos+4:d** - **settab+4:b settab,5?ia** - **settab+4:b settab,5?ia; 0** - **getc+4,3:b main.c?C; 0** - **settab+4:b settab,5?ia; ptab/o; 0** - **$b** - breakpoints - count bkpt command - 1 ~tabpos+04 - 3 _getc+04 main.c?C;0 - 1 _fopen+04 - 1 ~settab+04 settab,5?ia;ptab?o;0 - ~settab: jsr r5,csv - ~settab+04: bpt - ~settab+06: clr 0177770(r5) - ~settab+012: cmp $0120,0177770(r5) - ~settab+020: blt ~settab+076 - ~settab+022: - 0177766: 0177770 - 0177744: @` - T0177744: T - h0177744: h - i0177744: i - s0177744: s - -=== Figure 7: ADB output for C program with breakpoints === - **adb ex3 -** - **h+4:b hcnt/d; h.hi/; h.hr/** - **g+4:b gcnt/d; g.gi/; g.gr/** - **f+4:b fcnt/d; f.fi/; f.fr/** - **:r** - ex3: running - _fcnt: 0 - 0177732: 214 - symbol not found - **f+4:b fcnt/d; f.a/; f.b/; f.fi/** - **g+4:b gcnt/d; g.p/; g.q/; g.gi/** - **h+4:b hcnt/d; h.x/; h.y/; h.hi/** - **:c** - ex3: running - _fcnt: 0 - 0177746: 1 - 0177750: 1 - 0177732: 214 - _gcnt: 0 - 0177726: 2 - 0177730: 3 - 0177712: 214 - _hcnt: 0 - 0177706: 2 - 0177710: 1 - 0177672: 214 - _fcnt: 1 - 0177666: 2 - 0177670: 3 - 0177652: 214 - _gcnt: 1 - 0177646: 5 - 0177650: 8 - 0177632: 214 - **HIT DEL** - **f+4:b fcnt/d; f.a/"a = "d; f.b/"b = "d; f.fi/"fi = "d** - **g+4:b gcnt/d; g.p/"p = "d; g.q/"q = "d; g.gi/"gi = "d** - **h+4:b hcnt/d; h.x/"x = "d; h.y/"h = "d; h.hi/"hi = "d** - **:r** - ex3: running - _fcnt: 0 - 0177746: a = 1 - 0177750: b = 1 - 0177732: fi = 214 - _gcnt: 0 - 0177726: p = 2 - 0177730: q = 3 - 0177712: gi = 214 - _hcnt: 0 - 0177706: x = 2 - 0177710: y = 1 - 0177672: hi = 214 - _fcnt: 1 - 0177666: a = 2 - 0177670: b = 3 - 0177652: fi = 214 - **HIT DEL** - **$q** - - -=== Figure 8: ADB address maps === - -a.out hdr text+data - |____|_____________________________| - 0 D - -core hdr text+data stack - |______|_____________________________......|________| - 0 D S E - - -The following ''adb'' variables are set. - -|| b || base of data || 0 || -|| d || length of data || D || -|| s || length of stack || S || -|| t || length of text || 0 || - - -=== Figure 9: ADB output for maps === - **adb map core** - **$m** - text map `map' - b1 = 0 e1 = 0256 f1 = 020 - b2 = 0 e2 = 0256 f2 = 020 - data map `core' - b1 = 0 e1 = 0300 f1 = 02000 - b2 = 0175400 e2 = 0200000 f2 = 02300 - **$v** - variables - d = 0300 - m = 0407 - s = 02400 - **$q** - -=== Figure 10: Simple C program for illustrating formatting and patching === - - char str1[] "This is a character string"; - int one 1; - int number 456; - long lnum 1234; - float fpt 1.25; - char str2[] "This is the second character string"; - main() - { - one = 2; - } - - -=== Figure 11: ADB output illustrating fancy formats === - -**adb map410 core410** -** - - -=== Figure 12: Directory and inode dumps === - -**adb dir -** -**=nt"Inode"t"Name"** -**0,-1?ut14cn** - - Inode Name -0: 652 . - 82 .. - 5971 cap.c - 5323 cap - 0 pp - - - - -**adb /dev/src -** -**02000>b** -**?m diff --git a/src/cmd/adb/doc/adb-summary.txt b/src/cmd/adb/doc/adb-summary.txt deleted file mode 100644 index 336aabe..0000000 --- a/src/cmd/adb/doc/adb-summary.txt +++ /dev/null @@ -1,91 +0,0 @@ -=== ADB Summary === - -== Command Summary == - -a) formatted printing - -|| ? format || print from ''a.out'' file according to format || -|| / format || print from ''core'' file according to format || -|| = format || print the value of dot || -|| ?w expr || write expression into ''a.out'' file || -|| /w expr || write expression into ''core'' file || -|| ?l expr || locate expression in ''a.out'' file || - -b) breakpoint and program control - -|| :b || set breakpoint at dot || -|| :c || continue running program || -|| :d || delete breakpoint || -|| :k || kill the program being debugged || -|| :r || run ''a.out'' file under ADB control || -|| :s || single step || - -c) miscellaneous printing - -|| $b || print current breakpoints || -|| $c || C stack trace || -|| $e || external variables || -|| $f || floating registers || -|| $m || print ADB segment maps || -|| $q || exit from ADB || -|| $r || general registers || -|| $s || set offset for symbol match || -|| $v || print ADB variables || -|| $w || set output line width || - -d) calling the shell - -|| ! || call shell to read rest of line || - -e) assignment to variables - -|| >name || assign dot to variable or register name || - - -== Format Summary == - -|| a || the value of dot || -|| b || one byte in octal || -|| c || one byte as a character || -|| d || one word in decimal || -|| f || two words in floating point || -|| i || PDP 11 instruction || -|| o || one word in octal || -|| n || print a newline || -|| r || print a blank space || -|| s || a null terminated character string || -|| nt || move to next n space tab || -|| u || one word as unsigned integer || -|| x || hexadecimal || -|| Y || date || -|| ^ || backup dot || -|| "..." || print string || - - -== Expression Summary == - -a) expression components - -|| decimal integer || e.g. 256 || -|| octal integer || e.g. 0277 || -|| hexadecimal || e.g. #ff || -|| symbols || e.g. flag _main main.argc || -|| variables || e.g. 0 .ta \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 -.if \\n(.$=0 .ta 1i 1.7i 2.5i -.ft 3 -.nf -.. -.de P2 -.sp .5 -.ft 1 -.fi -.. -.RP -.....TM "77-8234-11 77-1273-10" "49170-220 39199" "40952-1 39199-11" -.ND May 5, 1977 -.TL -A Tutorial Introduction to ADB -.AU "MH2F-207" "3816" -J. F. Maranzano -.AU "MH2C-512" 7419 -S. R. Bourne -.AI -.MH -.OK -UNIX -Debugging -C Programming -.AB -.PP -Debugging tools generally provide a wealth of information -about the inner workings of programs. -These tools have been available on -.UX -to allow users to -examine ``core'' files -that result from aborted programs. -A new debugging program, ADB, provides enhanced capabilities -to examine "core" and other program files in a -variety of formats, run programs with embedded breakpoints and patch files. -.PP -ADB is an indispensable but complex tool for debugging crashed systems and/or -programs. -This document provides an introduction to ADB with examples of its use. -It explains the various formatting options, -techniques for debugging C programs, examples of printing -file system information and patching. -.AE -.CS 12 15 27 13 0 5 -.NH -Introduction -.PP -ADB is a new debugging program that is -available on UNIX. -It provides capabilities to look at -``core'' files resulting from aborted programs, print output in a -variety of formats, patch files, and run programs -with embedded breakpoints. -This document provides examples of -the more useful features of ADB. -The reader is expected to be -familiar with the basic commands on -.UX -with the C -language, and with References 1, 2 and 3. -.NH -A Quick Survey -.NH 2 -Invocation -.PP -ADB is invoked as: -.P1 - adb objfile corefile -.P2 -where -.ul -objfile -is an executable UNIX file and -.ul -corefile -is a core image file. -Many times this will look like: -.P1 - adb a.out core -.P2 -or more simply: -.P1 - adb -.P2 -where the defaults are -.ul -a.out -and -.ul -core -respectively. -The filename minus (\-) means ignore this argument as in: -.P1 - adb \- core -.P2 -.PP -ADB has requests for examining locations in either file. -The -\fB?\fP -request examines the contents of -.ul -objfile, -the -\fB/\fP -request examines the -.ul -corefile. -The general form of these requests is: -.P1 - address ? format -.P2 -or -.P1 - address / format -.P2 -.NH 2 -Current Address -.PP -ADB maintains a current address, called dot, -similar in function to the current pointer in the UNIX editor. -When an address is entered, the current address is set to that location, -so that: -.P1 - 0126?i -.P2 -sets dot to octal 126 and prints the instruction -at that address. -The request: -.P1 - .,10/d -.P2 -prints 10 decimal numbers starting at dot. -Dot ends up referring to the address of the last item printed. -When used with the \fB?\fP or \fB/\fP requests, -the current address can be advanced by typing newline; it can be decremented -by typing \fB^\fP. -.PP -Addresses are represented by -expressions. -Expressions are made up from decimal, octal, and hexadecimal integers, -and symbols from the program under test. -These may be combined with the operators +, \-, *, % (integer division), -& (bitwise and), | (bitwise inclusive or), # (round up -to the next multiple), and ~ (not). -(All arithmetic within ADB is 32 bits.) -When typing a symbolic address for a C program, -the user can type -.ul -name -or -.ul -_name; -ADB will recognize both forms. -.NH 2 -Formats -.PP -To print data, a user specifies a collection of letters and characters -that describe the format of the printout. -Formats are "remembered" in the sense that typing a request without one -will cause the new printout to appear in the previous format. -The following are the most commonly used format letters. -.P1 -\fB b \fPone byte in octal -\fB c \fPone byte as a character -\fB o \fPone word in octal -\fB d \fPone word in decimal -\fB f \fPtwo words in floating point -\fB i \fPPDP 11 instruction -\fB s \fPa null terminated character string -\fB a \fPthe value of dot -\fB u \fPone word as unsigned integer -\fB n \fPprint a newline -\fB r \fPprint a blank space -\fB ^ \fPbackup dot -.P2 -(Format letters are also available for "long" values, -for example, `\fBD\fR' for long decimal, and `\fBF\fP' for double floating point.) -For other formats see the ADB manual. -.NH 2 -General Request Meanings -.PP -The general form of a request is: -.P1 - address,count command modifier -.P2 -which sets `dot' to \fIaddress\fP -and executes the command -\fIcount\fR times. -.PP -The following table illustrates some general ADB command meanings: -.P1 - Command Meaning -\fB ? \fPPrint contents from \fIa.out\fP file -\fB / \fPPrint contents from \fIcore\fP file -\fB = \fPPrint value of "dot" -\fB : \fPBreakpoint control -\fB $ \fPMiscellaneous requests -\fB ; \fPRequest separator -\fB ! \fPEscape to shell -.P2 -.PP -ADB catches signals, so a user cannot use a quit signal to exit from ADB. -The request $q or $Q (or cntl-D) must be used -to exit from ADB. -.NH -Debugging C Programs -.NH 2 -Debugging A Core Image -.PP -Consider the C program in Figure 1. -The program is used to illustrate a common error made by -C programmers. -The object of the program is to change the -lower case "t" to upper case in the string pointed to by -.ul -charp -and then write the character string to the file indicated by -argument 1. -The bug shown is that the character "T" -is stored in the pointer -.ul -charp -instead of the string pointed to by -.ul -charp. -Executing the program produces a core file because of an out of bounds memory reference. -.PP -ADB is invoked by: -.P1 - adb a.out core -.P2 -The first debugging request: -.P1 - $c -.P2 -is used to give a C backtrace through the -subroutines called. -As shown in Figure 2 -only one function (\fImain\fR) was called and the -arguments -.ul -argc -and -.ul -argv -have octal values 02 and -0177762 respectively. -Both of these values look -reasonable; 02 = two arguments, 0177762 = address on stack -of parameter vector. -.br -The next request: -.P1 - $C -.P2 -is used to give a C backtrace plus an interpretation -of all the local variables in each function and their -values in octal. -The value of the variable -.ul -cc -looks incorrect -since -.ul -cc -was declared as a character. -.PP -The next request: -.P1 - $r -.P2 -prints out the registers including the program -counter and an interpretation of the instruction at that -location. -.PP -The request: -.P1 - $e -.P2 -prints out the values of all external variables. -.PP -A map exists for each file -handled by -ADB. -The map for the -.ul -a.out -file is referenced by \fB?\fP whereas the map for -.ul -core -file is referenced by \fB/\fP. -Furthermore, a good rule of thumb is to use \fB?\fP for -instructions and \fB/\fP for data when looking at programs. -To print out information about the maps type: -.P1 - $m -.P2 -This produces a report of the contents of the maps. -More about these maps later. -.PP -In our example, it is useful to see the -contents of the string pointed to by -.ul -charp. -This is done by: -.P1 - *charp/s -.P2 -which says use -.ul -charp -as a pointer in the -.ul -core -file -and print the information as a character string. -This printout clearly shows that the character buffer -was incorrectly overwritten and helps identify the error. -Printing the locations around -.ul -charp -shows that the buffer is unchanged -but that the pointer is destroyed. -Using ADB similarly, we could print information about the -arguments to a function. -The request: -.P1 - main.argc/d -.P2 -prints the decimal -.ul -core -image value of the argument -.ul -argc -in the function -.ul -main. -.br -The request: -.P1 - *main.argv,3/o -.P2 -prints the octal values of the three consecutive -cells pointed to by -.ul -argv -in the function -.ul -main. -Note that these values are the addresses of the arguments -to main. -Therefore: -.P1 - 0177770/s -.P2 -prints the ASCII value of the first argument. -Another way to print this value would have been -.P1 - *"/s -.P2 -The " means ditto which remembers the last address -typed, in this case \fImain.argc\fP ; the \fB*\fP instructs ADB to use the address field of the -.ul -core -file as a pointer. -.PP -The request: -.P1 - .=o -.P2 -prints the current address (not its contents) in octal which has been set to the address of the first argument. -The current address, dot, is used by ADB to -"remember" its current location. -It allows the user -to reference locations relative to the current -address, for example: -.P1 - .\-10/d -.P2 -.NH 2 -Multiple Functions -.PP -Consider the C program illustrated in -Figure 3. -This program calls functions -.ul -f, g, -and -.ul -h -until the stack is exhausted and a core image is produced. -.PP -Again you can enter the debugger via: -.P1 - adb -.P2 -which assumes the names -.ul -a.out -and -.ul -core -for the executable -file and core image file respectively. -The request: -.P1 - $c -.P2 -will fill a page of backtrace references to -.ul -f, g, -and -.ul -h. -Figure 4 shows an abbreviated list (typing -.ul -DEL -will terminate the output and bring you back to ADB request level). -.PP -The request: -.P1 - ,5$C -.P2 -prints the five most recent activations. -.PP -Notice that each function -(\fIf,g,h\fP) has a counter -of the number of times it was called. -.PP -The request: -.P1 - fcnt/d -.P2 -prints the decimal value of the counter for the function -.ul -f. -Similarly -.ul -gcnt -and -.ul -hcnt -could be printed. -To print the value of an automatic variable, -for example the decimal value of -.ul -x -in the last call of the function -.ul -h, -type: -.P1 - h.x/d -.P2 -It is currently not possible in the exported version to print stack frames other than the most recent activation of a function. -Therefore, a user can print everything with -\fB$C\fR or the occurrence of a variable in the most recent call of a function. -It is possible with the \fB$C\fR request, however, to print the stack frame -starting at some address as \fBaddress$C.\fR -.NH 2 -Setting Breakpoints -.PP -Consider the C program in Figure 5. -This program, which changes tabs into blanks, is adapted from -.ul -Software Tools -by Kernighan and Plauger, pp. 18-27. -.PP -We will run this program under the control of ADB (see Figure 6a) by: -.P1 - adb a.out \- -.P2 -Breakpoints are set in the program as: -.ul -.P1 - address:b [request] -.P2 -The requests: -.P1 - settab+4:b - fopen+4:b - getc+4:b - tabpos+4:b -.P2 -set breakpoints at the start of these functions. -C does not generate statement labels. -Therefore it is currently not possible to plant breakpoints at locations -other than function entry points without a knowledge of the code -generated by the C compiler. -The above addresses are entered as -.ft B -symbol+4 -.ft R -so that they will appear in any -C backtrace since the first instruction of each function is a call -to the C save routine -(\fIcsv\fR). -Note that some of the functions are from the C library. -.PP -To print the location of breakpoints one types: -.P1 - $b -.P2 -The display indicates a -.ul -count -field. -A breakpoint is bypassed -.ul -count \-1 -times before causing a stop. -The -.ul -command -field indicates the ADB requests to be executed each time the breakpoint is encountered. -In our example no -.ul -command -fields are present. -.PP -By displaying the original instructions at the function -.ul -settab -we see that -the breakpoint is set after the jsr to the C save routine. -We can display the instructions using the ADB request: -.P1 - settab,5?ia -.P2 -This request displays five instructions starting at -.ul -settab -with the addresses of each location displayed. -Another variation is: -.P1 - settab,5?i -.P2 -which displays the instructions with only the starting address. -.PP -Notice that we accessed the addresses from the -.ul -a.out -file with the \fB?\fP command. -In general when asking for a printout of multiple items, -ADB will advance the current address the number of -bytes necessary to satisfy the request; in the above -example five instructions were displayed and the current address was -advanced 18 (decimal) bytes. -.PP -To run the program one simply types: -.P1 - :r -.P2 -To delete a breakpoint, for instance the entry to the function -.ul -settab, -one types: -.P1 - settab+4:d -.P2 -To continue execution of the program from the breakpoint type: -.P1 - :c -.PP -Once the program has stopped (in this case at the breakpoint for -.ul -fopen), -ADB requests can be used to display the contents of memory. -For example: -.P1 - $C -.P2 -to display a stack trace, or: -.P1 - tabs,3/8o -.P2 -to print three lines of 8 locations each from the array called -.ul -tabs. -By this time (at location -.ul -fopen) -in the C program, -.ul -settab -has been called and should have set a one in every eighth location of -.ul -tabs. -.NH 2 -Advanced Breakpoint Usage -.PP -We continue execution of the program with: -.P1 - :c -.P2 -See Figure 6b. -.ul -Getc -is called three times and the contents of the variable -.ul -c -in the function -.ul -main -are displayed -each time. -The single character on the left hand edge is the output from the C program. -On the third occurrence of -.ul -getc -the program stops. -We can look at the full buffer of characters by typing: -.P1 - ibuf+6/20c -.P2 -When we continue the program with: -.P1 - :c -.P2 -we hit our first breakpoint at -.ul -tabpos -since there is a tab following the -"This" word of the data. -.PP -Several breakpoints of -.ul -tabpos -will occur until the program has changed the tab into equivalent blanks. -Since we feel that -.ul -tabpos -is working, -we can remove the breakpoint at that location by: -.P1 - tabpos+4:d -.P2 -If the program is continued with: -.P1 - :c -.P2 -it resumes normal execution after ADB prints -the message -.P1 - a.out:running -.P2 -.PP -The UNIX quit and interrupt signals -act on ADB itself rather than on the program being debugged. -If such a signal occurs then the program being debugged is stopped and control is returned to ADB. -The signal is saved by ADB and is passed on to the test program if: -.P1 - :c -.P2 -is typed. -This can be useful when testing interrupt -handling routines. -The signal is not passed on to the test program if: -.P1 - :c 0 -.P2 -is typed. -.PP -Now let us reset the breakpoint at -.ul -settab -and display the instructions located there when we reach the breakpoint. -This is accomplished by: -.P1 - settab+4:b settab,5?ia \fR* -.P2 -.FS -* Owing to a bug in early versions of ADB (including the -version distributed in Generic 3 UNIX) these statements -must be written as: -.br -.in 1i -\fBsettab+4:b settab,5?ia;0\fR -.ft B -.br -getc+4,3:b main.c?C;0 -.br -settab+4:b settab,5?ia; ptab/o;0 -.br -.ft R -.in -1i -Note that \fB;0\fR will set dot to zero and stop at the breakpoint. -.FE -It is also possible to execute the ADB requests for each occurrence of the breakpoint but -only stop after the third occurrence by typing: -.P1 - getc+4,3:b main.c?C \fR* -.P2 -This request will print the local variable -.ul -c -in the function -.ul -main -at each occurrence of the breakpoint. -The semicolon is used to separate multiple ADB requests on a single line. -.PP -Warning: -setting a breakpoint causes the value of dot to be changed; -executing the program under ADB does not change dot. -Therefore: -.P1 - settab+4:b .,5?ia - fopen+4:b -.P2 -will print the last thing dot was set to -(in the example \fIfopen+4\fP) -.ul -not -the current location (\fIsettab+4\fP) -at which the program is executing. -.PP -A breakpoint can be overwritten without first deleting the old breakpoint. -For example: -.P1 - settab+4:b settab,5?ia; ptab/o \fR* -.P2 -could be entered after typing the above requests. -.PP -Now the display of breakpoints: -.P1 - $b -.P2 -shows the above request for the -.ul -settab -breakpoint. -When the breakpoint at -.ul -settab -is encountered the ADB requests are executed. -Note that the location at -.ul -settab+4 -has been changed to plant the breakpoint; -all the other locations match their original value. -.PP -Using the functions, -.ul -f, g -and -.ul -h -shown in Figure 3, -we can follow the execution of each function by planting non-stopping -breakpoints. -We call ADB with the executable program of Figure 3 as follows: -.P1 - adb ex3 \- -.P2 -Suppose we enter the following breakpoints: -.P1 - h+4:b hcnt/d; h.hi/; h.hr/ - g+4:b gcnt/d; g.gi/; g.gr/ - f+4:b fcnt/d; f.fi/; f.fr/ - :r -.P2 -Each request line indicates that the variables are printed in decimal -(by the specification \fBd\fR). -Since the format is not changed, the \fBd\fR can be left off all but -the first request. -.PP -The output in Figure 7 illustrates two points. -First, the ADB requests in the breakpoint line are not -examined until the program under -test is run. -That means any errors in those ADB requests is not detected until run time. -At the location of the error ADB stops running the program. -.PP -The second point is the way ADB handles register variables. -ADB uses the symbol table to address variables. -Register variables, like \fIf.fr\fR above, have pointers to uninitialized -places on the stack. -Therefore the message "symbol not found". -.PP -Another way of getting at the data in this example is to print -the variables used in the call as: -.P1 - f+4:b fcnt/d; f.a/; f.b/; f.fi/ - g+4:b gcnt/d; g.p/; g.q/; g.gi/ - :c -.P2 -The operator / was used instead of ? -to read values from the \fIcore\fP file. -The output for each function, as shown in Figure 7, has the same format. -For the function \fIf\fP, for example, it shows the name and value of the -.ul -external -variable -.ul -fcnt. -It also shows the address on the stack and value of the -variables -.ul -a, b -and -.ul -fi. -.PP -Notice that the addresses on the stack will continue to decrease -until no address space is left for program execution -at which time (after many pages of output) -the program under test aborts. -A display with names would be produced by requests like the following: -.P1 - f+4:b fcnt/d; f.a/"a="d; f.b/"b="d; f.fi/"fi="d -.P2 -In this format the quoted string is printed literally and the \fBd\fP -produces a decimal display of the variables. -The results are shown in Figure 7. -.NH 2 -Other Breakpoint Facilities -.LP -.IP \(bu 4 -Arguments and change of standard input and output are passed to a program as: -.P1 - :r arg1 arg2 ... outfile -.P2 -This request -kills any existing program under test and -starts the -.ul -a.out -afresh. -.IP \(bu -The program being debugged can be single stepped -by: -.P1 - :s -.P2 -If necessary, this request will start up the program being -debugged and stop after executing -the first instruction. -.IP \(bu -ADB allows a program to be entered at a specific address -by typing: -.P1 - address:r -.P2 -.IP \(bu -The count field can be used to skip the first \fIn\fR breakpoints as: -.P1 - ,n:r -.P2 -The request: -.P1 - ,n:c -.P2 -may also be used for skipping the first \fIn\fR breakpoints -when continuing a program. -.sp -.IP \(bu -A program can be continued at an address different from the breakpoint by: -.P1 - address:c -.P2 -.IP \(bu -The program being debugged runs as a separate process and can be killed by: -.P1 - :k -.P2 -.LP -.NH -Maps -.PP -UNIX supports several executable file formats. These are used to tell -the loader how to load the program file. File type 407 -is the most common and is generated by a C compiler invocation such as -\fBcc pgm.c\fP. -A 410 file is produced by a C compiler command of the form \fBcc -n pgm.c\fP, -whereas a 411 file is produced by \fBcc -i pgm.c\fP. -ADB interprets these different file formats and -provides access to the different segments through a set of maps (see Figure 8). -To print the maps type: -.P1 - $m -.P2 -.PP -In 407 files, both text (instructions) and data are intermixed. -This makes it impossible for ADB to differentiate data from -instructions and some of the printed symbolic addresses look incorrect; -for example, printing data addresses as offsets from routines. -.PP -In 410 files (shared text), the instructions are separated from data and -\fB?*\fR accesses the data part of the \fIa.out\fP file. -The \fB?* \fP request tells ADB to use the second part of the -map in the -.ul -a.out -file. -Accessing data in the \fIcore\fP file shows -the data after it was modified by the execution of the program. -Notice also that the data segment may have grown during -program execution. -.PP -In 411 files (separated I & D space), the -instructions and data are also separated. -However, in this -case, since data is mapped through a separate set of segmentation -registers, the base of the data segment is also relative to address zero. -In this case since the addresses overlap it is necessary to use -the \fB?*\fR operator to access the data space of the \fIa.out\fP file. -In both 410 and 411 files the corresponding -core file does not contain the program text. -.PP -Figure 9 shows the display of three maps -for the same program linked as a 407, 410, 411 respectively. -The b, e, and f fields are used by ADB to map -addresses into file addresses. -The "f1" field is the -length of the header at the beginning of the file (020 bytes -for an \fIa.out\fP file and 02000 bytes for a \fIcore\fP file). -The "f2" field is the displacement from the beginning of the file to the data. -For a 407 file with mixed text and data this is the -same as the length of the header; for 410 and 411 files this -is the length of the header plus the size of the text portion. -.PP -The "b" and "e" fields are the starting and ending locations -for a segment. -Given an address, A, the location in -the file (either \fIa.out\fP or \fIcore\fP) is calculated as: -.P1 - b1\(<=A\(<=e1 =\h'-.5m'> file address = (A\-b1)+f1 - b2\(<=A\(<=e2 =\h'-.5m'> file address = (A\-b2)+f2 -.P2 -A user can access locations by using the ADB defined variables. -The \fB$v\fR request prints the variables initialized by ADB: -.P1 - b base address of data segment - d length of the data segment - s length of the stack - t length of the text - m execution type (407,410,411) -.P2 -.PP -In Figure 9 those variables not present are zero. -Use can be made of these variables by expressions such as: -.P1 - b -.P2 -that sets \fBb\fP to octal 2000. -These variables are useful to know if the file under examination -is an executable or \fIcore\fP image file. -.PP -ADB reads the header of the \fIcore\fP image file to find the -values for these variables. -If the second file specified does not -seem to be a \fIcore\fP file, or if it is missing then the header of -the executable file is used instead. -.NH -Advanced Usage -.PP -It is possible with ADB to combine formatting requests -to provide elaborate displays. -Below are several examples. -.NH 2 -Formatted dump -.PP -The line: -.P1 - b - ?m file address = (A-b1)+f1** - **b2<=A<=e2 => file address = (A-b2)+f2** -A user can access locations by using the ADB defined variables. -The **$v** request prints the variables initialized by -ADB: - -|| b || base address of data segment || -|| d || length of the data segment || -|| s || length of the stack || -|| t || length of the text || -|| m || execution type (407,410,411) || - -In Figure 9 those variables not present are zero. Use -can be made of these variables by expressions such as: - **b** -that sets **b** to octal 2000. These variables are useful to -know if the file under examination is an executable or //core// -image file. - -ADB reads the header of the ''core'' image file to find the -values for these variables. If the second file specified -does not seem to be a ''core'' file, or if it is missing then -the header of the executable file is used instead. - - -===== 5. Advanced Usage ===== - -It is possible with ADB to combine formatting requests -to provide elaborate displays. Below are several examples. - -==== 5.1. Formatted dump ==== - -The line: - **b** - **?m -#else -# include -#endif +#include static int savlastf; static long savframe; diff --git a/src/cmd/adb/format.c b/src/cmd/adb/format.c index e4710ae..0515c28 100644 --- a/src/cmd/adb/format.c +++ b/src/cmd/adb/format.c @@ -1,10 +1,6 @@ #include "defs.h" +#include #include -#ifdef CROSS -# include -#else -# include -#endif void scanform(icount, ifp, itype, ptype) @@ -87,7 +83,7 @@ exform(fcount, ifp, itype, ptype) u_int w; long savdot, wx; char *fp = 0; - int c, modifier; + int c, modifier, longpr; struct { long sa; int sb, sc; @@ -96,7 +92,7 @@ exform(fcount, ifp, itype, ptype) while (fcount > 0) { fp = ifp; c = *fp; - //int longpr = (c >= 'A' && c <= 'Z') || (c == 'f'); + longpr = (c >= 'A' && c <= 'Z') || (c == 'f'); if (itype == NSP || *fp == 'a') { wx = dot; w = dot; diff --git a/src/cmd/adb/main.c b/src/cmd/adb/main.c index 96fda2a..8dead38 100644 --- a/src/cmd/adb/main.c +++ b/src/cmd/adb/main.c @@ -1,5 +1,4 @@ #include "defs.h" -#include char *Ipath = "/share/adb"; @@ -60,27 +59,22 @@ main(argc, argv) myname = "adb"; mynamelen = strlen(myname); -#ifdef TIOCGETP ioctl(0, TIOCGETP, &adbtty); ioctl(0, TIOCGETP, &usrtty); -#else - tcgetattr(0, &adbtty); - tcgetattr(0, &usrtty); -#endif while (argc > 1) { - if (strcmp("-w", argv[1]) == 0) { - wtflag = O_RDWR; + if (! strcmp("-w", argv[1])) { + wtflag = 2; argc--; argv++; continue; } - if (strcmp("-k", argv[1]) == 0) { + if (! strcmp("-k", argv[1])) { kernel++; argc--; argv++; continue; } - if (strcmp("-I", argv[1]) == 0) { + if (! strcmp("-I", argv[1])) { Ipath = argv[2]; argc -= 2; argv += 2; @@ -127,7 +121,7 @@ main(argc, argv) flushbuf(); if (errflg) { print("%s\n", errflg); - exitflg = (errflg != 0); + exitflg = (int) errflg; errflg = 0; } if (mkfault) { diff --git a/src/cmd/adb/output.c b/src/cmd/adb/output.c index 2796ca7..5b6fe08 100644 --- a/src/cmd/adb/output.c +++ b/src/cmd/adb/output.c @@ -1,5 +1,4 @@ #include "defs.h" -#include int outfile = 1; char *printptr = printbuf; @@ -188,143 +187,153 @@ printdate(tvec) void print(char *fmat, ...) { - va_list args, prev_args; char *fptr, *s; + int *vptr; + long *dptr; + double *rptr; int width, prec; char c, adj; - int decpt, n; + int x, decpt, n; + long lx; char digits[64]; - union { - int int32; - float float32; - } word; - va_start(args, fmat); fptr = fmat; + vptr = 1 + (int*) &fmat; + while ((c = *fptr++)) { if (c != '%') { printc(c); - continue; - } - - if (*fptr == '-') { - adj = 'l'; - fptr++; } else { - adj = 'r'; - } - width = convert(&fptr); - if (*fptr == '*') { - width = va_arg(args, int); - fptr++; - } - if (*fptr == '.') { - fptr++; - prec = convert(&fptr); + if (*fptr == '-') { + adj = 'l'; + fptr++; + } else { + adj = 'r'; + } + width = convert(&fptr); if (*fptr == '*') { - prec = va_arg(args, int); + width = *vptr++; fptr++; } - } else - prec = -1; + if (*fptr == '.') { + fptr++; + prec = convert(&fptr); + if (*fptr == '*') { + prec = *vptr++; + fptr++; + } + } else + prec = -1; - digitptr = digits; - prev_args = args; - word.int32 = va_arg(args, int); - s = 0; - switch (c = *fptr++) { - case 'd': - case 'u': - printnum(word.int32, c, 10); - break; - case 'o': - printoct(word.int32, 0); - break; - case 'q': - case 'x': - printlong(word.int32, 'x', 16); - break; - case 'Y': - printdate(word.int32); - break; - case 'D': - case 'U': - printlong(word.int32, c, 10); - break; - case 'O': - printoct(word.int32, 0); - break; - case 'Q': - case 'X': - printlong(word.int32, 'x', 16); - break; - case 'c': - printc(word.int32); - break; - case 's': - s = (char*) word.int32; - break; - case 'f': - case 'F': - s = ecvt(word.float32, prec, &decpt, &n); - *digitptr++ = n ? '-' : '+'; - *digitptr++ = (decpt <= 0) ? '0' : *s++; - if (decpt > 0) { - decpt--; - } - *digitptr++ = '.'; - while (*s && prec-- ) { - *digitptr++ = *s++; - } - while (*--digitptr=='0'); - digitptr += (digitptr - digits >= 3) ? 1 : 2; - if (decpt) { - *digitptr++ = 'e'; - printnum(decpt, 'd', 10); - } + digitptr = digits; + rptr = (double*) vptr; + dptr = (long*) vptr; + lx = *dptr; + x = *vptr++; s = 0; - prec = -1; - break; - case 'm': - args = prev_args; - break; - case 'M': - width = word.int32; - break; - case 'T': - case 't': - if (c == 'T') { - width = word.int32; - } else { - args = prev_args; + switch (c = *fptr++) { + case 'd': + case 'u': + printnum(x, c, 10); + break; + case 'o': + printoct((long) (unsigned) x, 0); + break; + case 'q': + printlong((long) (unsigned) x, 'x', 16); + break; + case 'x': + printlong((long) (unsigned) x, c, 16); + break; + case 'Y': + printdate(lx); + //vptr++; + break; + case 'D': + case 'U': + printlong(lx, c, 10); + //vptr++; + break; + case 'O': + printoct(lx, 0); + //vptr++; + break; + case 'Q': + printlong(lx, 'x', 16); + //vptr++; + break; + case 'X': + printlong(lx, 'x', 16); + //vptr++; + break; + case 'c': + printc(x); + break; + case 's': + s = (char*) x; + break; + case 'f': + case 'F': + //vptr += 7; + s = ecvt(*rptr, prec, &decpt, &n); + *digitptr++ = (n?'-':'+'); + *digitptr++ = (decpt <= 0) ? '0' : *s++; + if (decpt > 0) { + decpt--; + } + *digitptr++ = '.'; + while (*s && prec-- ) { + *digitptr++ = *s++; + } + while (*--digitptr=='0'); + digitptr += (digitptr - digits >= 3) ? 1 : 2; + if (decpt) { + *digitptr++ = 'e'; + printnum(decpt, 'd', 10); + } + s = 0; + prec = -1; + break; + case 'm': + vptr--; + break; + case 'M': + width = x; + break; + case 'T': + case 't': + if (c == 'T') { + width = x; + } else { + vptr--; + } + if (width) { + width -= (printptr - printbuf) % width; + } + break; + default: + printc(c); + vptr--; } - if (width) { - width -= (printptr - printbuf) % width; - } - break; - default: - printc(c); - args = prev_args; - } - if (s == 0) { - *digitptr = 0; - s = digits; - } - n = strlen(s); - n = (prec < n && prec >= 0) ? prec : n; - width -= n; - if (adj == 'r') { + if (s == 0) { + *digitptr = 0; + s = digits; + } + n = strlen(s); + n = (prec < n && prec >= 0) ? prec : n; + width -= n; + if (adj == 'r') { + while (width-- > 0) + printc(SP); + } + while (n--) + printc(*s++); while (width-- > 0) printc(SP); + digitptr = digits; } - while (n--) - printc(*s++); - while (width-- > 0) - printc(SP); - digitptr = digits; } - va_end(args); } #define MAXIFD 5 diff --git a/src/cmd/adb/print.c b/src/cmd/adb/print.c index 5dc91f4..c127940 100644 --- a/src/cmd/adb/print.c +++ b/src/cmd/adb/print.c @@ -74,7 +74,6 @@ printregs() int v; if (kernel) { - // TODO for (p=kregs; p<&kregs[7]; p++) { v = corhdr[p->roffs]; print("%s%8t%x%8t", p->rname, v); @@ -82,30 +81,12 @@ printregs() printc(EOR); } } else { - print (" t0 = %9x s0 = %9x t8 = %9x lo = %9x\n", - uframe [FRAME_R8], uframe [FRAME_R16], - uframe [FRAME_R24], uframe [FRAME_LO]); - print ("at = %9x t1 = %9x s1 = %9x t9 = %9x hi = %9x\n", - uframe [FRAME_R1], uframe [FRAME_R9], uframe [FRAME_R17], - uframe [FRAME_R25], uframe [FRAME_HI]); - print ("v0 = %9x t2 = %9x s2 = %9x status = %9x\n", - uframe [FRAME_R2], uframe [FRAME_R10], - uframe [FRAME_R18], uframe [FRAME_STATUS]); - print ("v1 = %9x t3 = %9x s3 = %9x pc = %9x\n", - uframe [FRAME_R3], uframe [FRAME_R11], - uframe [FRAME_R19], uframe [FRAME_PC]); - print ("a0 = %9x t4 = %9x s4 = %9x gp = %9x\n", - uframe [FRAME_R4], uframe [FRAME_R12], - uframe [FRAME_R20], uframe [FRAME_GP]); - print ("a1 = %9x t5 = %9x s5 = %9x sp = %9x\n", - uframe [FRAME_R5], uframe [FRAME_R13], - uframe [FRAME_R21], uframe [FRAME_SP]); - print ("a2 = %9x t6 = %9x s6 = %9x fp = %9x\n", - uframe [FRAME_R6], uframe [FRAME_R14], - uframe [FRAME_R22], uframe [FRAME_FP]); - print ("a3 = %9x t7 = %9x s7 = %9x ra = %9x\n", - uframe [FRAME_R7], uframe [FRAME_R15], - uframe [FRAME_R23], uframe [FRAME_RA]); + for (p=reglist; p < ®list[NREG]; p++) { + v = uframe[p->roffs]; + print("%s%8t%x%8t", p->rname, v); + valpr(v, (p->roffs == FRAME_PC) ? ISYM : DSYM); + printc(EOR); + } printpc(); } } @@ -304,7 +285,7 @@ printtrace(modif) } break; - case 'e': case 'E': /* print externals */ + case 'e': case 'E': /* print externals*/ symset(); while ((symp = symget())) { chkerr(); @@ -417,10 +398,8 @@ printpc() void sigprint() { -#ifndef CROSS if (signo >= 0 && signo < NSIG) print("%s", sys_siglist[signo]); else -#endif print("unknown signal %d", signo); } diff --git a/src/cmd/adb/runpcs.c b/src/cmd/adb/runpcs.c index 3cb8a5f..9bdf783 100644 --- a/src/cmd/adb/runpcs.c +++ b/src/cmd/adb/runpcs.c @@ -23,14 +23,8 @@ bpwait() while ((w = wait(&stat)) != pid && w != -1) ; signal(SIGINT, sigint); - -#ifdef TIOCGETP ioctl(0, TIOCGETP, &usrtty); ioctl(0, TIOCSETP, &adbtty); -#else - tcgetattr(0, &usrtty); - tcsetattr(0, TCSANOW, &adbtty); -#endif if (w == -1) { pid = 0; errflg = BADWAIT; @@ -69,7 +63,7 @@ readregs() for (i=0; icount); #endif bkptloc = bkptr->loc; ptrace(PT_WRITE_I, pid, (void*) bkptloc, bkptr->ins); - -#ifdef TIOCGETP ioctl(0, TIOCSETP, &usrtty); -#else - tcsetattr(0, TCSANOW, &usrtty); -#endif ptrace(PT_STEP, pid, (void*) bkptloc, 0); bpwait(); chkerr(); @@ -112,11 +100,7 @@ runpcs(runmode, execsig) #ifdef DEBUG print("\ncontinue %d %d\n", userpc, execsig); #endif -#ifdef TIOCGETP ioctl(0, TIOCSETP, &usrtty); -#else - tcsetattr(0, TCSANOW, &usrtty); -#endif ptrace (runmode, pid, (void*) userpc, execsig); bpwait(); chkerr(); diff --git a/src/cmd/adb/setup.c b/src/cmd/adb/setup.c index dc1b9db..ddb48bb 100644 --- a/src/cmd/adb/setup.c +++ b/src/cmd/adb/setup.c @@ -1,6 +1,5 @@ #include "defs.h" #include -#include u_int *uframe = UFRAME; char *symfil = "a.out"; @@ -15,15 +14,16 @@ getfile(filnam, cnt) { register int f; - if (strcmp("-", filnam) == 0) - return -1; - - f = open(filnam, wtflag); - if (f < 0 && argcount > cnt) { - if (wtflag) - f = open(filnam, O_CREAT | O_TRUNC | wtflag, 644); - if (f < 0) - print("cannot open `%s'\n", filnam); + if (strcmp("-", filnam)) { + f = open(filnam, wtflag); + if (f < 0 && argcount > cnt) { + if (wtflag) + f = open(filnam, O_CREAT | O_TRUNC | wtflag, 644); + if (f < 0) + print("cannot open `%s'\n", filnam); + } + } else { + f = -1; } return f; } @@ -77,9 +77,9 @@ setcor() datmap.ufd = fcor; if (read(fcor, corhdr, sizeof corhdr) == sizeof corhdr) { if (! kernel) { - txtsiz = ((struct user*)corhdr)->u_tsize; - datsiz = ((struct user*)corhdr)->u_dsize; - stksiz = ((struct user*)corhdr)->u_ssize; + txtsiz = ((U*)corhdr)->u_tsize; + datsiz = ((U*)corhdr)->u_dsize; + stksiz = ((U*)corhdr)->u_ssize; datmap.f1 = USIZE; datmap.b2 = USER_DATA_END - stksiz; datmap.e2 = USER_DATA_END; @@ -112,14 +112,13 @@ setcor() } datbas = datmap.b1; if (! kernel && magic) { - /* User's frame pointer in user's address space. */ - register u_int frame; - frame = (long) ((struct user*)corhdr)->u_frame; - frame -= KERNEL_DATA_END - USIZE; - if (frame > 0 && frame < USIZE && ! (frame & 3)) { - /* User's frame pointer in adb address space. */ - uframe = (u_int*) &corhdr[frame >> 2]; - } + register u_int *frame; + frame = (u_int*) ((U*)corhdr)->u_frame; + if (frame > (u_int*) (KERNEL_DATA_END - USIZE) && + frame < (u_int*) KERNEL_DATA_END && + ! ((unsigned)frame & 3)) + uframe = (u_int*) &corhdr[frame - + (u_int*) (KERNEL_DATA_END - USIZE)]; } } else { datmap.e1 = maxfile; diff --git a/src/cmd/adb/sym.c b/src/cmd/adb/sym.c index 650fd1a..a5bad14 100644 --- a/src/cmd/adb/sym.c +++ b/src/cmd/adb/sym.c @@ -1,13 +1,9 @@ /* * Symbol table and file handling service routines */ +#include #include "defs.h" #include -#ifdef CROSS -# include -#else -# include -#endif struct SYMcache { char *name; @@ -207,6 +203,8 @@ symINI(ex) if (nbytes <= 0) break; symnum -= nbytes; + if (type == N_REG) + continue; nused++; } @@ -222,7 +220,7 @@ symINI(ex) if (nbytes <= 0) break; symnum -= nbytes; - if (! (type & N_EXT)) + if (type == N_REG || ! (type & N_EXT)) continue; nused++; } @@ -244,6 +242,8 @@ symINI(ex) if (nbytes <= 0) break; symnum -= nbytes; + if (type == N_REG) + continue; if (globals_only && ! (type & N_EXT)) continue; sp->value = value; @@ -254,10 +254,7 @@ symINI(ex) } symnum = nused; #if 1 - //printf("file '%s'\n", symfil); - printf("text=%u data=%u bss=%u symoff=%u syms=%u\n", - ex->a_text, ex->a_data, ex->a_bss, (unsigned) symoff, ex->a_syms); - printf("%d symbols loaded\n", nused); + print("%d symbols loaded\n", nused); #endif if (globals_only) print("%s: could only do global symbols\n", myname); diff --git a/src/cmd/adc-demo/.gitignore b/src/cmd/adc-demo/.gitignore deleted file mode 100644 index 2ace794..0000000 --- a/src/cmd/adc-demo/.gitignore +++ /dev/null @@ -1 +0,0 @@ -adc-demo diff --git a/src/cmd/adc-demo/Makefile b/src/cmd/adc-demo/Makefile index 74a1794..2264760 100644 --- a/src/cmd/adc-demo/Makefile +++ b/src/cmd/adc-demo/Makefile @@ -10,7 +10,7 @@ include $(TOPSRC)/target.mk OBJS = adc-demo.o SRCS = adc-demo.c -LIBS += -lcurses -ltermcap -lc +LIBS += -lcurses -ltermcap all: adc-demo diff --git a/src/cmd/adc-demo/adc-demo.c b/src/cmd/adc-demo/adc-demo.c index 812032f..c766bbd 100644 --- a/src/cmd/adc-demo/adc-demo.c +++ b/src/cmd/adc-demo/adc-demo.c @@ -60,7 +60,6 @@ int main(int argc, char **argv) clear(); while(1) { - clear(); for(i=0; i<16; i++) { if(channels[i].enabled == 1) @@ -78,7 +77,7 @@ int main(int argc, char **argv) { mvwaddch(win,i,value+11,'='); } - // clrtoeol(); + clrtoeol(); } } refresh(); diff --git a/src/cmd/aout/.gitignore b/src/cmd/aout/.gitignore deleted file mode 100644 index 347b11f..0000000 --- a/src/cmd/aout/.gitignore +++ /dev/null @@ -1 +0,0 @@ -aout diff --git a/src/cmd/aout/Makefile b/src/cmd/aout/Makefile deleted file mode 100644 index 7ca33a2..0000000 --- a/src/cmd/aout/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -# -# aout - Display information from a.out files -# -TOPSRC = $(shell cd ../../..; pwd) -include $(TOPSRC)/target.mk -#include $(TOPSRC)/cross.mk - -CFLAGS += -Werror -Wall -Os -LDFLAGS += - -AOUTOBJS = aout.o mips-dis.o - -all: aout - -aout: $(AOUTOBJS) - ${CC} ${LDFLAGS} -o aout.elf $(AOUTOBJS) ${LIBS} - ${OBJDUMP} -S aout.elf > aout.dis - ${SIZE} aout.elf - ${ELF2AOUT} aout.elf $@ && rm aout.elf - -clean: - rm -f *.o *.0 *.elf aout tags *~ *.dis - -install: all - install aout $(DESTDIR)/bin/ diff --git a/src/cmd/ar/.gitignore b/src/cmd/ar/.gitignore deleted file mode 100644 index 13beaee..0000000 --- a/src/cmd/ar/.gitignore +++ /dev/null @@ -1 +0,0 @@ -ar diff --git a/src/cmd/ar/append.c b/src/cmd/ar/append.c index 7f098ee..c2cd51b 100644 --- a/src/cmd/ar/append.c +++ b/src/cmd/ar/append.c @@ -34,27 +34,19 @@ * SUCH DAMAGE. */ #ifdef CROSS -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include +# include +# include #else -# include -# include -# include -# include # include -# include -# include # include -# include #endif +#include +#include +#include +#include +#include +#include +#include #include "archive.h" #include "extern.h" diff --git a/src/cmd/ar/ar.c b/src/cmd/ar/ar.c index 74d05d3..d4b4d2f 100644 --- a/src/cmd/ar/ar.c +++ b/src/cmd/ar/ar.c @@ -34,71 +34,27 @@ * SUCH DAMAGE. */ #ifdef CROSS -# include -# include -# include -# include -# include -# include +# include +# include #else -# include -# include # include -# include -# include -# include # include #endif +#include +#include +#include +#include #include +#include #include "archive.h" #include "extern.h" extern int errno; CHDR chdr; -unsigned options; +u_int options; char *archive, *envtmp, *posarg, *posname; - -static void -usage() -{ - (void)fprintf(stderr, "Usage:\n"); - (void)fprintf(stderr, " ar -d [-Tv] archive file ...\n"); - (void)fprintf(stderr, " ar -m [-Tv] archive file ...\n"); - (void)fprintf(stderr, " ar -m [-abiTv] position archive file ...\n"); - (void)fprintf(stderr, " ar -p [-Tv] archive [file ...]\n"); - (void)fprintf(stderr, " ar -q [-cTv] archive file ...\n"); - (void)fprintf(stderr, " ar -r [-cuTv] archive file ...\n"); - (void)fprintf(stderr, " ar -r [-abciuTv] position archive file ...\n"); - (void)fprintf(stderr, " ar -t [-Tv] archive [file ...]\n"); - (void)fprintf(stderr, " ar -x [-ouTv] archive [file ...]\n"); - (void)fprintf(stderr, "Commands:\n"); - (void)fprintf(stderr, " -d Delete file(s) from the archive\n"); - (void)fprintf(stderr, " -m Move file(s) in the archive\n"); - (void)fprintf(stderr, " -p Print file(s) found in the archive\n"); - (void)fprintf(stderr, " -q Quick append file(s) to the archive\n"); - (void)fprintf(stderr, " -r Replace existing or insert new file(s) into the archive\n"); - (void)fprintf(stderr, " -t Display contents of archive\n"); - (void)fprintf(stderr, " -x Extract file(s) from the archive\n"); - (void)fprintf(stderr, "Modifiers:\n"); - (void)fprintf(stderr, " -a Put file(s) after [member-name]\n"); - (void)fprintf(stderr, " -b, -i Put file(s) before [member-name]\n"); - (void)fprintf(stderr, " -c Do not warn if the library had to be created\n"); - (void)fprintf(stderr, " -u Only replace files that are newer than current archive contents\n"); - (void)fprintf(stderr, " -o Preserve original dates\n"); - (void)fprintf(stderr, " -T Make a thin archive\n"); - (void)fprintf(stderr, " -v Be verbose\n"); - exit(1); -} - -static void -badoptions(arg) - char *arg; -{ - (void)fprintf(stderr, - "ar: illegal option combination for %s.\n", arg); - usage(); -} +static void badoptions(), usage(); /* * main -- @@ -114,7 +70,8 @@ main(argc, argv) extern int optind; int c; char *p; - int (*fcall)() = 0; + int (*fcall)() = 0, append(), contents(), delete(), extract(), + move(), print(), replace(); if (argc < 3) usage(); @@ -124,7 +81,7 @@ main(argc, argv) * Fix it, if necessary. */ if (*argv[1] != '-') { - if (!(p = malloc((unsigned)(strlen(argv[1]) + 2)))) { + if (!(p = malloc((u_int)(strlen(argv[1]) + 2)))) { (void)fprintf(stderr, "ar: %s.\n", strerror(errno)); exit(1); } @@ -253,3 +210,44 @@ main(argc, argv) exit(1); exit((*fcall)(argv)); } + +static void +badoptions(arg) + char *arg; +{ + (void)fprintf(stderr, + "ar: illegal option combination for %s.\n", arg); + usage(); +} + +static void +usage() +{ + (void)fprintf(stderr, "Usage:\n"); + (void)fprintf(stderr, " ar -d [-Tv] archive file ...\n"); + (void)fprintf(stderr, " ar -m [-Tv] archive file ...\n"); + (void)fprintf(stderr, " ar -m [-abiTv] position archive file ...\n"); + (void)fprintf(stderr, " ar -p [-Tv] archive [file ...]\n"); + (void)fprintf(stderr, " ar -q [-cTv] archive file ...\n"); + (void)fprintf(stderr, " ar -r [-cuTv] archive file ...\n"); + (void)fprintf(stderr, " ar -r [-abciuTv] position archive file ...\n"); + (void)fprintf(stderr, " ar -t [-Tv] archive [file ...]\n"); + (void)fprintf(stderr, " ar -x [-ouTv] archive [file ...]\n"); + (void)fprintf(stderr, "Commands:\n"); + (void)fprintf(stderr, " -d Delete file(s) from the archive\n"); + (void)fprintf(stderr, " -m Move file(s) in the archive\n"); + (void)fprintf(stderr, " -p Print file(s) found in the archive\n"); + (void)fprintf(stderr, " -q Quick append file(s) to the archive\n"); + (void)fprintf(stderr, " -r Replace existing or insert new file(s) into the archive\n"); + (void)fprintf(stderr, " -t Display contents of archive\n"); + (void)fprintf(stderr, " -x Extract file(s) from the archive\n"); + (void)fprintf(stderr, "Modifiers:\n"); + (void)fprintf(stderr, " -a Put file(s) after [member-name]\n"); + (void)fprintf(stderr, " -b, -i Put file(s) before [member-name]\n"); + (void)fprintf(stderr, " -c Do not warn if the library had to be created\n"); + (void)fprintf(stderr, " -u Only replace files that are newer than current archive contents\n"); + (void)fprintf(stderr, " -o Preserve original dates\n"); + (void)fprintf(stderr, " -T Make a thin archive\n"); + (void)fprintf(stderr, " -v Be verbose\n"); + exit(1); +} diff --git a/src/cmd/ar/archive.c b/src/cmd/ar/archive.c index 6747fb5..9087ef9 100644 --- a/src/cmd/ar/archive.c +++ b/src/cmd/ar/archive.c @@ -34,31 +34,22 @@ * SUCH DAMAGE. */ #ifdef CROSS -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include +# include +# include #else -# include -# include -# include -# include # include -# include -# include -# include -# include # include -# include #endif +#include +#include +#include +#include #include +#include +#include +#include +#include +#include #include "archive.h" #include "extern.h" @@ -79,8 +70,7 @@ open_archive(mode) created = 0; if (mode & O_CREAT) { mode |= O_EXCL; - fd = open(archive, mode, 0666); - if (fd >= 0) { + if ((fd = open(archive, mode, 0666)) >= 0) { /* POSIX.2 puts create message on stderr. */ if (!(options & AR_C)) (void)fprintf(stderr, @@ -92,9 +82,7 @@ open_archive(mode) error(archive); mode &= ~O_EXCL; } - - fd = open(archive, mode, 0666); - if (fd < 0) + if ((fd = open(archive, mode, 0666)) < 0) error(archive); /* @@ -238,10 +226,7 @@ copy_ar(cfp, size) from = cfp->rfd; to = cfp->wfd; - while (sz) { - nr = read(from, buf, sz < sizeof(buf) ? sz : sizeof(buf)); - if (nr <= 0) - break; + while (sz && (nr = read(from, buf, (size_t)(MIN(sz, sizeof(buf))))) > 0) { sz -= nr; for (off = 0; off < nr; nr -= off, off += nw) if ((nw = write(to, buf + off, (size_t)nr)) < 0) @@ -341,6 +326,6 @@ skip_arobj(fd) off_t len; len = chdr.size + (chdr.lname & 1); - if (lseek(fd, len, SEEK_CUR) == (off_t)-1) + if (lseek(fd, len, L_INCR) == (off_t)-1) error(archive); } diff --git a/src/cmd/ar/archive.h b/src/cmd/ar/archive.h index aaeffa7..39f85e8 100644 --- a/src/cmd/ar/archive.h +++ b/src/cmd/ar/archive.h @@ -33,27 +33,6 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -#ifdef CROSS -# ifdef __linux__ -# undef O_CREAT -# define O_CREAT 00000100 -# undef O_EXCL -# define O_EXCL 00000200 -# undef O_NOCTTY -# define O_NOCTTY 00000400 -# undef O_TRUNC -# define O_TRUNC 00001000 -# endif -# ifndef MAXNAMLEN -# define MAXNAMLEN 63 -# endif -# ifndef MAXPATHLEN -# define MAXPATHLEN 256 -# endif -# ifndef _PATH_ARTMP -# define _PATH_ARTMP "/tmp/ar.XXXXXX" -# endif -#endif /* Ar(1) options. */ #define AR_A 0x0001 @@ -71,7 +50,7 @@ #define AR_V 0x1000 #define AR_X 0x2000 -extern unsigned options; +extern u_int options; /* Set up file copy. */ #define SETCF(from, fromname, to, toname, pad) { \ @@ -91,7 +70,7 @@ typedef struct { #define NOPAD 0x00 /* don't pad */ #define RPAD 0x01 /* pad on reads */ #define WPAD 0x02 /* pad on writes */ - unsigned flags; /* pad flags */ + u_int flags; /* pad flags */ } CF; /* Header structure internal format. */ @@ -101,7 +80,7 @@ typedef struct { int lname; /* size of the long name in bytes */ int gid; /* group */ int uid; /* owner */ - unsigned short mode; /* permissions */ + u_short mode; /* permissions */ char name[MAXNAMLEN + 1]; /* name */ } CHDR; @@ -118,11 +97,3 @@ void copy_ar(); int get_arobj(); int open_archive(); void put_arobj(); - -int delete (register char **argv); -int move (register char **argv); -int print (register char **argv); -int append (register char **argv); -int replace (register char **argv); -int contents (register char **argv); -int extract (register char **argv); diff --git a/src/cmd/ar/contents.c b/src/cmd/ar/contents.c index 836a7ec..0ce99f3 100644 --- a/src/cmd/ar/contents.c +++ b/src/cmd/ar/contents.c @@ -34,23 +34,18 @@ * SUCH DAMAGE. */ #ifdef CROSS -# include -# include -# include -# include -# include -# include +# include #else -# include -# include -# include -# include # include -# include -# include -# include #endif +#include +#include +#include +#include +#include +#include #include +#include #include "archive.h" #include "extern.h" diff --git a/src/cmd/ar/delete.c b/src/cmd/ar/delete.c index 73d6f90..de67687 100644 --- a/src/cmd/ar/delete.c +++ b/src/cmd/ar/delete.c @@ -34,21 +34,16 @@ * SUCH DAMAGE. */ #ifdef CROSS -# include -# include -# include -# include -# include -# include +# include #else -# include -# include -# include -# include # include -# include -# include #endif +#include +#include +#include +#include +#include +#include #include #include "archive.h" #include "extern.h" @@ -85,9 +80,9 @@ delete(argv) put_arobj(&cf, (struct stat *)NULL); } - size = lseek(tfd, (off_t)0, SEEK_CUR); - (void)lseek(tfd, (off_t)0, SEEK_SET); - (void)lseek(afd, (off_t)SARMAG, SEEK_SET); + size = lseek(tfd, (off_t)0, L_INCR); + (void)lseek(tfd, (off_t)0, L_SET); + (void)lseek(afd, (off_t)SARMAG, L_SET); SETCF(tfd, tname, afd, archive, NOPAD); copy_ar(&cf, size); (void)close(tfd); diff --git a/src/cmd/ar/extern.h b/src/cmd/ar/extern.h index 43bafdf..44e81f8 100644 --- a/src/cmd/ar/extern.h +++ b/src/cmd/ar/extern.h @@ -39,3 +39,6 @@ int tmp(); char *files(); char *rname(); void strmode(); +extern long strtol(); +extern off_t lseek(); +extern char *getenv(); diff --git a/src/cmd/ar/extract.c b/src/cmd/ar/extract.c index 1e429cb..8247767 100644 --- a/src/cmd/ar/extract.c +++ b/src/cmd/ar/extract.c @@ -34,26 +34,18 @@ * SUCH DAMAGE. */ #ifdef CROSS -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include +# include +# include #else -# include -# include -# include -# include # include -# include # include -# include #endif +#include +#include +#include +#include +#include +#include #include #include "archive.h" #include "extern.h" diff --git a/src/cmd/ar/misc.c b/src/cmd/ar/misc.c index 00c5ac0..c4a9a38 100644 --- a/src/cmd/ar/misc.c +++ b/src/cmd/ar/misc.c @@ -34,26 +34,19 @@ * SUCH DAMAGE. */ #ifdef CROSS -# include -# include -# include -# include -# include -# include -# include -# include -# include +# include +# include #else -# include -# include # include -# include -# include -# include # include -# include -# include #endif +#include +#include +#include +#include +#include +#include +#include #include "archive.h" #include "extern.h" @@ -65,9 +58,7 @@ int tmp() { extern char *envtmp; -#ifndef CROSS sigset_t set, oset; -#endif static int first; static const char *artmp = _PATH_ARTMP; int fd; @@ -84,17 +75,13 @@ tmp() } else { strcpy(path, artmp); } -#ifndef CROSS sigfillset(&set); (void)sigprocmask(SIG_BLOCK, &set, &oset); -#endif fd = mkstemp(path); if (fd == -1) error(tname); (void)unlink(path); -#ifndef CROSS (void)sigprocmask(SIG_SETMASK, &oset, NULL); -#endif return(fd); } diff --git a/src/cmd/ar/move.c b/src/cmd/ar/move.c index a44ef3b..10ba384 100644 --- a/src/cmd/ar/move.c +++ b/src/cmd/ar/move.c @@ -34,21 +34,16 @@ * SUCH DAMAGE. */ #ifdef CROSS -# include -# include -# include -# include -# include -# include +# include #else -# include -# include -# include -# include # include -# include -# include #endif +#include +#include +#include +#include +#include +#include #include #include "archive.h" #include "extern.h" @@ -119,20 +114,20 @@ move(argv) close_archive(afd); return(1); } - (void)lseek(afd, (off_t)SARMAG, SEEK_SET); + (void)lseek(afd, (off_t)SARMAG, L_SET); SETCF(tfd1, tname, afd, archive, NOPAD); - tsize = size = lseek(tfd1, (off_t)0, SEEK_CUR); - (void)lseek(tfd1, (off_t)0, SEEK_SET); + tsize = size = lseek(tfd1, (off_t)0, L_INCR); + (void)lseek(tfd1, (off_t)0, L_SET); copy_ar(&cf, size); - tsize += size = lseek(tfd2, (off_t)0, SEEK_CUR); - (void)lseek(tfd2, (off_t)0, SEEK_SET); + tsize += size = lseek(tfd2, (off_t)0, L_INCR); + (void)lseek(tfd2, (off_t)0, L_SET); cf.rfd = tfd2; copy_ar(&cf, size); - tsize += size = lseek(tfd3, (off_t)0, SEEK_CUR); - (void)lseek(tfd3, (off_t)0, SEEK_SET); + tsize += size = lseek(tfd3, (off_t)0, L_INCR); + (void)lseek(tfd3, (off_t)0, L_SET); cf.rfd = tfd3; copy_ar(&cf, size); diff --git a/src/cmd/ar/print.c b/src/cmd/ar/print.c index 06d2d9c..f11082a 100644 --- a/src/cmd/ar/print.c +++ b/src/cmd/ar/print.c @@ -34,17 +34,13 @@ * SUCH DAMAGE. */ #ifdef CROSS -# include -# include -# include -# include -# include +# include #else -# include -# include # include -# include #endif +#include +#include +#include #include "archive.h" #include "extern.h" diff --git a/src/cmd/ar/replace.c b/src/cmd/ar/replace.c index 51d4702..f9d87bc 100644 --- a/src/cmd/ar/replace.c +++ b/src/cmd/ar/replace.c @@ -34,28 +34,20 @@ * SUCH DAMAGE. */ #ifdef CROSS -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include +# include +# include #else -# include -# include -# include -# include # include -# include -# include # include -# include #endif +#include +#include +#include +#include +#include #include +#include +#include #include "archive.h" #include "extern.h" @@ -160,8 +152,7 @@ useold: SETCF(afd, archive, curfd, tname, RPAD|WPAD); append: while ((file = *argv++) != 0) { if (options & AR_V) (void)printf("a - %s\n", file); - sfd = open(file, O_RDONLY); - if (sfd < 0) { + if ((sfd = open(file, O_RDONLY)) < 0) { err = 1; (void)fprintf(stderr, "ar: %s: %s.\n", file, strerror(errno)); @@ -175,18 +166,18 @@ append: while ((file = *argv++) != 0) { (void)close(sfd); } - (void)lseek(afd, (off_t)SARMAG, SEEK_SET); + (void)lseek(afd, (off_t)SARMAG, L_SET); SETCF(tfd1, tname, afd, archive, NOPAD); if (tfd1 != -1) { - tsize = size = lseek(tfd1, (off_t)0, SEEK_CUR); - (void)lseek(tfd1, (off_t)0, SEEK_SET); + tsize = size = lseek(tfd1, (off_t)0, L_INCR); + (void)lseek(tfd1, (off_t)0, L_SET); copy_ar(&cf, size); } else tsize = 0; - tsize += size = lseek(tfd2, (off_t)0, SEEK_CUR); - (void)lseek(tfd2, (off_t)0, SEEK_SET); + tsize += size = lseek(tfd2, (off_t)0, L_INCR); + (void)lseek(tfd2, (off_t)0, L_SET); cf.rfd = tfd2; copy_ar(&cf, size); diff --git a/src/cmd/ar/strmode.c b/src/cmd/ar/strmode.c index 8889b5f..91ea47c 100644 --- a/src/cmd/ar/strmode.c +++ b/src/cmd/ar/strmode.c @@ -30,13 +30,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -#ifdef CROSS -# include -# include -#else -# include -# include -#endif +#include +#include void strmode(mode, p) diff --git a/src/cmd/as/.gitignore b/src/cmd/as/.gitignore deleted file mode 100644 index 11b3e7d..0000000 --- a/src/cmd/as/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -aout -as diff --git a/src/cmd/as/Makefile b/src/cmd/as/Makefile index 06a3019..8091e93 100644 --- a/src/cmd/as/Makefile +++ b/src/cmd/as/Makefile @@ -1,14 +1,17 @@ # # as - Assembler +# aout - Display information from a.out files # TOPSRC = $(shell cd ../../..; pwd) include $(TOPSRC)/target.mk #include $(TOPSRC)/cross.mk CFLAGS += -Werror -Wall -Os -LDFLAGS += +LDFLAGS += -g -all: as +AOUTOBJS = aout.o mips-dis.o + +all: as aout as: as.o ${CC} ${LDFLAGS} -o as.elf as.o ${LIBS} @@ -16,8 +19,26 @@ as: as.o ${SIZE} as.elf ${ELF2AOUT} as.elf $@ && rm as.elf +aout: $(AOUTOBJS) + ${CC} ${LDFLAGS} -o aout.elf $(AOUTOBJS) ${LIBS} + ${OBJDUMP} -S aout.elf > aout.dis + ${SIZE} aout.elf + ${ELF2AOUT} aout.elf $@ && rm aout.elf + clean: - rm -f *.o *.0 *.elf as tags *~ *.dis tests/*.dis tests/*.gcc-dis tests/*.o + rm -f *.o *.0 *.elf as aout *.elf tags *~ *.dis + +test: + /usr/local/pic32-tools/bin/pic32-as -al example.s install: all install as $(DESTDIR)/bin/ + install aout $(DESTDIR)/bin/ + +test.dis-gcc: test.s + $(AS) $< -o test.o + ${OBJDUMP} -D test.o > $@ + +test.dis: test.s as aout + ./as $< -o test.o + ./aout test.o > $@ diff --git a/src/cmd/aout/aout.c b/src/cmd/as/aout.c similarity index 81% rename from src/cmd/aout/aout.c rename to src/cmd/as/aout.c index f22f82e..79a8656 100644 --- a/src/cmd/aout/aout.c +++ b/src/cmd/as/aout.c @@ -22,7 +22,7 @@ * this software. */ #ifdef CROSS -# include +# include #else # include #endif @@ -55,7 +55,7 @@ int fgethdr (text, h) register FILE *text; register struct exec *h; { - h->a_midmag = fgetword (text); + h->a_magic = fgetword (text); h->a_text = fgetword (text); h->a_data = fgetword (text); h->a_bss = fgetword (text); @@ -67,24 +67,20 @@ int fgethdr (text, h) } /* - * Read a relocation record: 1 to 6 bytes. + * Read a relocation record: 1 or 4 bytes. */ -void fgetrel (f, r) +unsigned int fgetrel (f) register FILE *f; - register struct reloc *r; { - r->flags = getc (f); - if ((r->flags & RSMASK) == REXT) { - r->index = getc (f); - r->index |= getc (f) << 8; - r->index |= getc (f) << 16; - } - if ((r->flags & RFMASK) == RHIGH16 || - (r->flags & RFMASK) == RHIGH16S) - { - r->offset = getc (f); - r->offset |= getc (f) << 8; + register unsigned int r; + + r = getc (f); + if ((r & RSMASK) == REXT) { + r |= getc (f) << 8; + r |= getc (f) << 16; + r |= getc (f) << 24; } + return r; } /* @@ -118,28 +114,27 @@ int fgetsym (text, name, value, type) } void prrel (r) - register struct reloc *r; + register unsigned r; { + int indx; + printf ("<"); - switch (r->flags & RSMASK) { + indx = RINDEX (r); + switch (r & RSMASK) { default: putchar ('?'); break; case RTEXT: putchar ('t'); break; case RDATA: putchar ('d'); break; case RBSS: putchar ('b'); break; - case REXT: printf ("%d", r->index); break; + case REXT: printf ("%d", indx); case RABS: break; } - switch (r->flags & RFMASK) { + switch (r & RFMASK) { default: putchar ('?'); break; - case RBYTE32: putchar ('b'); break; case RWORD26: putchar ('j'); break; case RWORD16: putchar ('w'); break; - case RHIGH16: printf ("u.%x", r->offset); break; - case RHIGH16S: printf ("h.%x", r->offset); break; - case RBYTE16: break; + case RHIGH16: putchar ('h'); break; + case 0: break; } - if (r->flags & RGPREL) - putchar ('g'); printf (">"); } @@ -147,7 +142,6 @@ void prtext (n) register int n; { unsigned opcode; - struct reloc relinfo; while (n--) { printf (" %8x:", addr); @@ -155,8 +149,7 @@ void prtext (n) printf ("\t%08x", opcode); if (rflag) { putchar (' '); - fgetrel (rel, &relinfo); - prrel (&relinfo); + prrel (fgetrel (rel)); } if (! dflag) { putchar ('\t'); @@ -172,14 +165,11 @@ void prtext (n) void prdata (n) register int n; { - struct reloc relinfo; - while (n--) { printf (" %8x:\t%08x", addr, fgetword (text)); if (rflag) { putchar (' '); - fgetrel (rel, &relinfo); - prrel (&relinfo); + prrel (fgetrel (rel)); } putchar ('\n'); @@ -235,7 +225,7 @@ void disasm (fname) return; } if (rflag) { - if (N_GETMAGIC(hdr) != RMAGIC) { + if (hdr.a_magic != RMAGIC) { fprintf (stderr, "aout: %s is not relocatable\n", fname); rflag = 0; @@ -250,9 +240,9 @@ void disasm (fname) } printf ("File %s:\n", fname); printf (" a_magic = %08x (%s)\n", hdr.a_magic, - N_GETMAGIC(hdr) == RMAGIC ? "relocatable" : - N_GETMAGIC(hdr) == OMAGIC ? "OMAGIC" : - N_GETMAGIC(hdr) == NMAGIC ? "NMAGIC" : "unknown"); + hdr.a_magic == RMAGIC ? "relocatable" : + hdr.a_magic == OMAGIC ? "OMAGIC" : + hdr.a_magic == NMAGIC ? "NMAGIC" : "unknown"); printf (" a_text = %08x (%u bytes)\n", hdr.a_text, hdr.a_text); printf (" a_data = %08x (%u bytes)\n", hdr.a_data, hdr.a_data); printf (" a_bss = %08x (%u bytes)\n", hdr.a_bss, hdr.a_bss); @@ -261,7 +251,7 @@ void disasm (fname) printf (" a_syms = %08x (%u bytes)\n", hdr.a_syms, hdr.a_syms); printf (" a_entry = %08x\n", hdr.a_entry); - addr = ((hdr.a_magic) == RMAGIC) ? 0 : USER_CODE_START; + addr = (hdr.a_magic == RMAGIC) ? 0 : USER_CODE_START; if (hdr.a_text > 0) { printf ("\nSection .text:\n"); @@ -295,11 +285,7 @@ int main (argc, argv) dflag++; break; default: -usage: fprintf (stderr, "Usage:\n"); - fprintf (stderr, " aout [-rd] file...\n"); - fprintf (stderr, "Options:\n"); - fprintf (stderr, " -r Print relocation info\n"); - fprintf (stderr, " -d Do not disassemble\n"); +usage: fprintf (stderr, "Usage: aout [-rd] file...\n"); return (1); } argc -= optind; diff --git a/src/cmd/as/as.c b/src/cmd/as/as.c index 931486a..fe33b96 100644 --- a/src/cmd/as/as.c +++ b/src/cmd/as/as.c @@ -1,8 +1,7 @@ /* - * Assembler for MIPS32. - * The syntax is compatible with GCC output. + * Assembler for MIPS. * - * Copyright (C) 2011-2012 Serge Vakulenko, + * Copyright (C) 2011 Serge Vakulenko, * * Permission to use, copy, modify, and distribute this software * and its documentation for any purpose and without fee is hereby @@ -23,8 +22,7 @@ * this software. */ #ifdef CROSS -# include -# include +# include #else # include #endif @@ -36,9 +34,6 @@ #define WORDSZ 4 /* word size in bytes */ -/* - * Locals beginning with L or dot are stripped off by -X flag. - */ #define IS_LOCAL(s) ((s)->n_name[0] == 'L' || (s)->n_name[0] == '.') /* @@ -48,6 +43,7 @@ enum { LEOF = 1, /* end of file */ LEOL, /* end of line */ LNAME, /* identifier */ + LCMD, /* machine instruction */ LREG, /* machine register */ LNUM, /* integer number */ LLSHIFT, /* << */ @@ -57,33 +53,11 @@ enum { LCOMM, /* .comm */ LDATA, /* .data */ LGLOBL, /* .globl */ - LHALF, /* .half */ + LSHORT, /* .short */ LSTRNG, /* .strng */ - LRDATA, /* .rdata */ LTEXT, /* .text */ LEQU, /* .equ */ LWORD, /* .word */ - LBYTE, /* .byte */ - LSPACE, /* .space */ - LFILE, /* .file */ - LSECTION, /* .section */ - LSYMTYPE, /* @type of symbol */ - LSECTYPE, /* @type of section */ - LPREVIOUS, /* .previous */ - LGNUATTR, /* .gnu_attribute */ - LALIGN, /* .align */ - LSET, /* .set */ - LENT, /* .ent */ - LTYPE, /* .type */ - LFRAME, /* .frame */ - LMASK, /* .mask */ - LFMASK, /* .fmask */ - LEND, /* .end */ - LSIZE, /* .size */ - LIDENT, /* .ident */ - LWEAK, /* .weak */ - LLOCAL, /* .local */ - LNAN, /* .nan */ }; /* @@ -98,6 +72,31 @@ enum { SABS, /* special case for getexpr() */ }; +/* + * Flags of instruction formats. + */ +#define FRD1 (1 << 0) /* rd, ... */ +#define FRD2 (1 << 1) /* .., rd, ... */ +#define FRT1 (1 << 2) /* rt, ... */ +#define FRT2 (1 << 3) /* .., rt, ... */ +#define FRT3 (1 << 4) /* .., .., rt */ +#define FRS1 (1 << 5) /* rs, ... */ +#define FRS2 (1 << 6) /* .., rs, ... */ +#define FRS3 (1 << 7) /* .., .., rs */ +#define FRSB (1 << 8) /* ... (rs) */ +#define FCODE (1 << 9) /* immediate shifted <<6 */ +#define FOFF16 (1 << 11) /* 16-bit relocatable offset */ +#define FHIGH16 (1 << 12) /* high 16-bit relocatable offset */ +#define FOFF18 (1 << 13) /* 18-bit PC-relative relocatable offset shifted >>2 */ +#define FAOFF18 (1 << 14) /* 18-bit PC-relative relocatable offset shifted >>2 */ +#define FAOFF28 (1 << 15) /* 28-bit absolute relocatable offset shifted >>2 */ +#define FSA (1 << 16) /* 5-bit shift amount */ +#define FSEL (1 << 17) /* optional 3-bit COP0 register select */ +#define FSIZE (1 << 18) /* bit field size */ +#define FMSB (1 << 19) /* bit field msb */ +#define FRTD (1 << 20) /* set rt to rd number */ +#define FCODE16 (1 << 21) /* immediate shifted <<16 */ + /* * Sizes of tables. * Hash sizes should be powers of 2! @@ -105,7 +104,6 @@ enum { #define HASHSZ 1024 /* symbol name hash table size */ #define HCMDSZ 256 /* instruction hash table size */ #define STSIZE (HASHSZ*9/10) /* symbol name table size */ -#define MAXRLAB 200 /* max relative (digit) labels */ /* * On second pass, hashtab[] is not needed. @@ -150,184 +148,138 @@ const int typesegm [] = { SSTRNG, /* N_STRNG */ }; -/* - * Table of local (numeric) labels. - */ -struct labeltab { - int num; - int value; -}; - -#define RLAB_OFFSET (1 << 23) /* index offset of relative label */ -#define RLAB_MAXVAL 1000000 /* max value of relative label */ - -/* - * Main opcode table. - */ struct optable { - unsigned opcode; /* instruction code */ - const char *name; /* instruction name */ - unsigned type; /* flags */ - void (*func) (unsigned, struct reloc*); /* handler for pseudo-instructions */ + unsigned opcode; + const char *name; + unsigned type; + void (*func) (unsigned, unsigned); }; -/* - * Flags of instruction formats. - */ -#define FRD1 (1 << 0) /* rd, ... */ -#define FRD2 (1 << 1) /* .., rd, ... */ -#define FRT1 (1 << 2) /* rt, ... */ -#define FRT2 (1 << 3) /* .., rt, ... */ -#define FRT3 (1 << 4) /* .., .., rt */ -#define FRS1 (1 << 5) /* rs, ... */ -#define FRS2 (1 << 6) /* .., rs, ... */ -#define FRS3 (1 << 7) /* .., .., rs */ -#define FRSB (1 << 8) /* ... (rs) */ -#define FCODE (1 << 9) /* immediate shifted <<6 */ -#define FDSLOT (1 << 10) /* have delay slot */ -#define FOFF16 (1 << 11) /* 16-bit relocatable offset */ -#define FHIGH16 (1 << 12) /* high 16-bit relocatable offset */ -#define FOFF18 (1 << 13) /* 18-bit PC-relative relocatable offset shifted >>2 */ -#define FAOFF18 (1 << 14) /* 18-bit PC-relative relocatable offset shifted >>2 */ -#define FAOFF28 (1 << 15) /* 28-bit absolute relocatable offset shifted >>2 */ -#define FSA (1 << 16) /* 5-bit shift amount */ -#define FSEL (1 << 17) /* optional 3-bit COP0 register select */ -#define FSIZE (1 << 18) /* bit field size */ -#define FMSB (1 << 19) /* bit field msb */ -#define FRTD (1 << 20) /* set rt to rd number */ -#define FCODE16 (1 << 21) /* immediate shifted <<16 */ -#define FMOD (1 << 22) /* modifies the first register */ - /* * Implement pseudo-instructions. - * TODO: bge, bgeu, bgt, bgtu, ble, bleu, blt, bltu */ -void emit_li (unsigned, struct reloc*); -void emit_la (unsigned, struct reloc*); +void emit_li (unsigned, unsigned); +void emit_la (unsigned, unsigned); const struct optable optable [] = { - { 0x00000020, "add", FRD1 | FRS2 | FRT3 | FMOD }, - { 0x20000000, "addi", FRT1 | FRS2 | FOFF16 | FMOD }, - { 0x24000000, "addiu", FRT1 | FRS2 | FOFF16 | FMOD }, - { 0x00000021, "addu", FRD1 | FRS2 | FRT3 | FMOD }, - { 0x00000024, "and", FRD1 | FRS2 | FRT3 | FMOD }, - { 0x30000000, "andi", FRT1 | FRS2 | FOFF16 | FMOD }, - { 0x10000000, "b", FAOFF18 | FDSLOT }, - { 0x04110000, "bal", FAOFF18 | FDSLOT }, - { 0x10000000, "beq", FRS1 | FRT2 | FOFF18 | FDSLOT }, - { 0x50000000, "beql", FRS1 | FRT2 | FOFF18 | FDSLOT }, - { 0x10000000, "beqz", FRS1 | FOFF18 | FDSLOT }, - { 0x50000000, "beqzl", FRS1 | FOFF18 | FDSLOT }, - { 0x04010000, "bgez", FRS1 | FOFF18 | FDSLOT }, - { 0x04110000, "bgezal", FRS1 | FOFF18 | FDSLOT }, - { 0x04130000, "bgezall", FRS1 | FOFF18 | FDSLOT }, - { 0x04030000, "bgezl", FRS1 | FOFF18 | FDSLOT }, - { 0x1c000000, "bgtz", FRS1 | FOFF18 | FDSLOT }, - { 0x5c000000, "bgtzl", FRS1 | FOFF18 | FDSLOT }, - { 0x18000000, "blez", FRS1 | FOFF18 | FDSLOT }, - { 0x58000000, "blezl", FRS1 | FOFF18 | FDSLOT }, - { 0x04000000, "bltz", FRS1 | FOFF18 | FDSLOT }, - { 0x04100000, "bltzal", FRS1 | FOFF18 | FDSLOT }, - { 0x04120000, "bltzall", FRS1 | FOFF18 | FDSLOT }, - { 0x04020000, "bltzl", FRS1 | FOFF18 | FDSLOT }, - { 0x14000000, "bne", FRS1 | FRT2 | FOFF18 | FDSLOT }, - { 0x54000000, "bnel", FRS1 | FRT2 | FOFF18 | FDSLOT }, - { 0x14000000, "bnez", FRS1 | FOFF18 | FDSLOT }, - { 0x54000000, "bnezl", FRS1 | FOFF18 | FDSLOT }, + { 0x00000020, "add", FRD1 | FRS2 | FRT3 }, + { 0x20000000, "addi", FRT1 | FRS2 | FOFF16 }, + { 0x24000000, "addiu", FRT1 | FRS2 | FOFF16 }, + { 0x00000021, "addu", FRD1 | FRS2 | FRT3 }, + { 0x00000024, "and", FRD1 | FRS2 | FRT3 }, + { 0x30000000, "andi", FRT1 | FRS2 | FOFF16 }, + { 0x10000000, "b", FAOFF18 }, + { 0x04110000, "bal", FAOFF18 }, + { 0x10000000, "beq", FRS1 | FRT2 | FOFF18 }, + { 0x50000000, "beql", FRS1 | FRT2 | FOFF18 }, + { 0x04010000, "bgez", FRS1 | FOFF18 }, + { 0x04110000, "bgezal", FRS1 | FOFF18 }, + { 0x04130000, "bgezall", FRS1 | FOFF18 }, + { 0x04030000, "bgezl", FRS1 | FOFF18 }, + { 0x1c000000, "bgtz", FRS1 | FOFF18 }, + { 0x5c000000, "bgtzl", FRS1 | FOFF18 }, + { 0x18000000, "blez", FRS1 | FOFF18 }, + { 0x58000000, "blezl", FRS1 | FOFF18 }, + { 0x04000000, "bltz", FRS1 | FOFF18 }, + { 0x04100000, "bltzal", FRS1 | FOFF18 }, + { 0x04120000, "bltzall", FRS1 | FOFF18 }, + { 0x04020000, "bltzl", FRS1 | FOFF18 }, + { 0x14000000, "bne", FRS1 | FRT2 | FOFF18 }, + { 0x54000000, "bnel", FRS1 | FRT2 | FOFF18 }, { 0x0000000d, "break", FCODE16 }, - { 0x70000021, "clo", FRD1 | FRS2 | FRTD | FMOD }, - { 0x70000020, "clz", FRD1 | FRS2 | FRTD | FMOD }, + { 0x70000021, "clo", FRD1 | FRS2 | FRTD }, + { 0x70000020, "clz", FRD1 | FRS2 | FRTD }, { 0x4200001f, "deret", 0 }, - { 0x41606000, "di", FRT1 | FMOD }, + { 0x41606000, "di", FRT1 }, { 0x0000001a, "div", FRS1 | FRT2 }, { 0x0000001b, "divu", FRS1 | FRT2 }, { 0x000000c0, "ehb", 0 }, - { 0x41606020, "ei", FRT1 | FMOD }, + { 0x41606020, "ei", FRT1 }, { 0x42000018, "eret", 0 }, - { 0x7c000000, "ext", FRT1 | FRS2 | FSA | FSIZE | FMOD }, - { 0x7c000004, "ins", FRT1 | FRS2 | FSA | FMSB | FMOD }, - { 0x08000000, "j", FAOFF28 | FDSLOT }, - { 0x0c000000, "jal", FAOFF28 | FDSLOT }, - { 0x00000009, "jalr", FRD1 | FRS2 | FDSLOT }, - { 0x00000409, "jalr.hb", FRD1 | FRS2 | FDSLOT }, - { 0x00000008, "jr", FRS1 | FDSLOT }, - { 0x00000408, "jr.hb", FRS1 | FDSLOT }, - { 0, "la", FRT1 | FMOD, emit_la }, - { 0x80000000, "lb", FRT1 | FOFF16 | FRSB | FMOD }, - { 0x90000000, "lbu", FRT1 | FOFF16 | FRSB | FMOD }, - { 0x84000000, "lh", FRT1 | FOFF16 | FRSB | FMOD }, - { 0x94000000, "lhu", FRT1 | FOFF16 | FRSB | FMOD }, - { 0, "li", FRT1 | FMOD, emit_li }, - { 0xc0000000, "ll", FRT1 | FOFF16 | FRSB | FMOD }, - { 0x3c000000, "lui", FRT1 | FHIGH16 | FMOD }, - { 0x8c000000, "lw", FRT1 | FOFF16 | FRSB | FMOD }, - { 0x88000000, "lwl", FRT1 | FOFF16 | FRSB | FMOD }, - { 0x98000000, "lwr", FRT1 | FOFF16 | FRSB | FMOD }, - { 0x70000000, "madd", FRS1 | FRT2 | FMOD }, - { 0x70000001, "maddu", FRS1 | FRT2 | FMOD }, - { 0x40000000, "mfc0", FRT1 | FRD2 | FSEL | FMOD }, - { 0x00000010, "mfhi", FRD1 | FMOD }, - { 0x00000012, "mflo", FRD1 | FMOD }, - { 0x00000021, "move", FRD1 | FRS2 | FMOD }, // addu - { 0x0000000b, "movn", FRD1 | FRS2 | FRT3 | FMOD }, - { 0x0000000a, "movz", FRD1 | FRS2 | FRT3 | FMOD }, - { 0x70000004, "msub", FRS1 | FRT2 | FMOD }, - { 0x70000005, "msubu", FRS1 | FRT2 | FMOD }, + { 0x7c000000, "ext", FRT1 | FRS2 | FSA | FSIZE }, + { 0x7c000004, "ins", FRT1 | FRS2 | FSA | FMSB }, + { 0x08000000, "j", FAOFF28 }, + { 0x0c000000, "jal", FAOFF28 }, + { 0x00000009, "jalr", FRD1 | FRS2 }, + { 0x00000409, "jalr.hb", FRD1 | FRS2 }, + { 0x00000008, "jr", FRS1 }, + { 0x00000408, "jr.hb", FRS1 }, + { 0, "la", FRT1, emit_la }, + { 0x80000000, "lb", FRT1 | FOFF16 | FRSB }, + { 0x90000000, "lbu", FRT1 | FOFF16 | FRSB }, + { 0x84000000, "lh", FRT1 | FOFF16 | FRSB }, + { 0x94000000, "lhu", FRT1 | FOFF16 | FRSB }, + { 0, "li", FRT1, emit_li }, + { 0xc0000000, "ll", FRT1 | FOFF16 | FRSB }, + { 0x3c000000, "lui", FRT1 | FHIGH16 }, + { 0x8c000000, "lw", FRT1 | FOFF16 | FRSB }, + { 0x88000000, "lwl", FRT1 | FOFF16 | FRSB }, + { 0x98000000, "lwr", FRT1 | FOFF16 | FRSB }, + { 0x70000000, "madd", FRS1 | FRT2 }, + { 0x70000001, "maddu", FRS1 | FRT2 }, + { 0x40000000, "mfc0", FRT1 | FRD2 | FSEL }, + { 0x00000010, "mfhi", FRD1 }, + { 0x00000012, "mflo", FRD1 }, + { 0x00000021, "move", FRD1 | FRS2 }, // addu + { 0x0000000b, "movn", FRD1 | FRS2 | FRT3 }, + { 0x0000000a, "movz", FRD1 | FRS2 | FRT3 }, + { 0x70000004, "msub", FRS1 | FRT2 }, + { 0x70000005, "msubu", FRS1 | FRT2 }, { 0x40800000, "mtc0", FRT1 | FRD2 | FSEL }, { 0x00000011, "mthi", FRS1 }, { 0x00000013, "mtlo", FRS1 }, - { 0x70000002, "mul", FRD1 | FRS2 | FRT3 | FMOD }, + { 0x70000002, "mul", FRD1 | FRS2 | FRT3 }, { 0x00000018, "mult", FRS1 | FRT2 }, { 0x00000019, "multu", FRS1 | FRT2 }, { 0x00000000, "nop", 0 }, - { 0x00000027, "nor", FRD1 | FRS2 | FRT3 | FMOD }, - { 0x00000025, "or", FRD1 | FRS2 | FRT3 | FMOD }, - { 0x34000000, "ori", FRT1 | FRS2 | FOFF16 | FMOD }, - { 0x7c00003b, "rdhwr", FRT1 | FRD2 | FMOD }, - { 0x41400000, "rdpgpr", FRD1 | FRT2 | FMOD }, - { 0x00200002, "ror", FRD1 | FRT2 | FSA | FMOD }, - { 0x00000046, "rorv", FRD1 | FRT2 | FRS3 | FMOD }, + { 0x00000027, "nor", FRD1 | FRS2 | FRT3 }, + { 0x00000025, "or", FRD1 | FRS2 | FRT3 }, + { 0x34000000, "ori", FRT1 | FRS2 | FOFF16 }, + { 0x7c00003b, "rdhwr", FRT1 | FRD2 }, + { 0x41400000, "rdpgpr", FRD1 | FRT2 }, + { 0x00200002, "ror", FRD1 | FRT2 | FSA }, + { 0x00000046, "rorv", FRD1 | FRT2 | FRS3 }, { 0xa0000000, "sb", FRT1 | FOFF16 | FRSB }, { 0xe0000000, "sc", FRT1 | FOFF16 | FRSB }, { 0x7000003f, "sdbbp", FCODE }, { 0x7c000420, "seb", FRD1 | FRT2 }, { 0x7c000620, "seh", FRD1 | FRT2 }, { 0xa4000000, "sh", FRT1 | FOFF16 | FRSB }, - { 0x00000000, "sll", FRD1 | FRT2 | FSA | FMOD }, - { 0x00000004, "sllv", FRD1 | FRT2 | FRS3 | FMOD }, - { 0x0000002a, "slt", FRD1 | FRS2 | FRT3 | FMOD }, - { 0x28000000, "slti", FRT1 | FRS2 | FOFF16 | FMOD }, - { 0x2c000000, "sltiu", FRT1 | FRS2 | FOFF16 | FMOD }, - { 0x0000002b, "sltu", FRD1 | FRS2 | FRT3 | FMOD }, - { 0x00000003, "sra", FRD1 | FRT2 | FSA | FMOD }, - { 0x00000007, "srav", FRD1 | FRT2 | FRS3 | FMOD }, - { 0x00000002, "srl", FRD1 | FRT2 | FSA | FMOD }, - { 0x00000006, "srlv", FRD1 | FRT2 | FRS3 | FMOD }, + { 0x00000000, "sll", FRD1 | FRT2 | FSA }, + { 0x00000004, "sllv", FRD1 | FRT2 | FRS3 }, + { 0x0000002a, "slt", FRD1 | FRS2 | FRT3 }, + { 0x28000000, "slti", FRT1 | FRS2 | FOFF16 }, + { 0x2c000000, "sltiu", FRT1 | FRS2 | FOFF16 }, + { 0x0000002b, "sltu", FRD1 | FRS2 | FRT3 }, + { 0x00000003, "sra", FRD1 | FRT2 | FSA }, + { 0x00000007, "srav", FRD1 | FRT2 | FRS3 }, + { 0x00000002, "srl", FRD1 | FRT2 | FSA }, + { 0x00000006, "srlv", FRD1 | FRT2 | FRS3 }, { 0x00000040, "ssnop", 0 }, - { 0x00000022, "sub", FRD1 | FRS2 | FRT3 | FMOD }, - { 0x00000023, "subu", FRD1 | FRS2 | FRT3 | FMOD }, + { 0x00000022, "sub", FRD1 | FRS2 | FRT3 }, + { 0x00000023, "subu", FRD1 | FRS2 | FRT3 }, { 0xac000000, "sw", FRT1 | FOFF16 | FRSB }, { 0xa8000000, "swl", FRT1 | FOFF16 | FRSB }, { 0xb8000000, "swr", FRT1 | FOFF16 | FRSB }, { 0x0000000f, "sync", FCODE }, { 0x0000000c, "syscall", FCODE }, - { 0x00000034, "teq", FRS1 | FRT2 | FCODE }, + { 0x00000034, "teq", FRS1 | FRT2 }, { 0x040c0000, "teqi", FRS1 | FOFF16 }, - { 0x00000030, "tge", FRS1 | FRT2 | FCODE }, + { 0x00000030, "tge", FRS1 | FRT2 }, { 0x04080000, "tgei", FRS1 | FOFF16 }, { 0x04090000, "tgeiu", FRS1 | FOFF16 }, - { 0x00000031, "tgeu", FRS1 | FRT2 | FCODE }, - { 0x00000032, "tlt", FRS1 | FRT2 | FCODE }, + { 0x00000031, "tgeu", FRS1 | FRT2 }, + { 0x00000032, "tlt", FRS1 | FRT2 }, { 0x040a0000, "tlti", FRS1 | FOFF16 }, { 0x040b0000, "tltiu", FRS1 | FOFF16 }, - { 0x00000033, "tltu", FRS1 | FRT2 | FCODE }, - { 0x00000036, "tne", FRS1 | FRT2 | FCODE }, + { 0x00000033, "tltu", FRS1 | FRT2 }, + { 0x00000036, "tne", FRS1 | FRT2 }, { 0x040e0000, "tnei", FRS1 | FOFF16 }, { 0x42000020, "wait", FCODE }, { 0x41c00000, "wrpgpr", FRD1 | FRT2 }, - { 0x7c0000a0, "wsbh", FRD1 | FRT2 | FMOD }, - { 0x00000026, "xor", FRD1 | FRS2 | FRT3 | FMOD }, - { 0x38000000, "xori", FRT1 | FRS2 | FOFF16 | FMOD }, + { 0x7c0000a0, "wsbh", FRD1 | FRT2 }, + { 0x00000026, "xor", FRD1 | FRS2 | FRT3 }, + { 0x38000000, "xori", FRT1 | FRS2 | FOFF16 }, { 0, 0, 0 }, }; @@ -342,7 +294,7 @@ const struct optable optable [] = { const char ctype [256] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,8,0,0,0,0,0,0,0,0,0,8,0,7,7,7,7,7,7,7,7,5,5,0,0,0,0,0,0, - 8,9,9,9,9,9,9,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,0,0,0,0,8, + 0,9,9,9,9,9,9,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,0,0,0,0,8, 0,9,9,9,9,9,9,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, @@ -369,30 +321,10 @@ unsigned intval; int extref; int blexflag, backlex, blextype; short hashtab [HASHSZ], hashctab [HCMDSZ]; -struct labeltab labeltab [MAXRLAB]; /* relative labels */ -int nlabels; -int mode_reorder = 1; /* .set reorder option (default) */ -int mode_macro; /* .set macro option */ -int mode_mips16; /* .set mips16 option */ -int mode_micromips; /* .set micromips option */ -int mode_at = 1; /* .set at option */ -int reorder_full; /* instruction buffered for reorder */ -unsigned reorder_word; /* buffered instruction... */ -unsigned reorder_clobber; /* ...modified this register */ -struct reloc reorder_rel; /* buffered relocation */ -struct reloc relabs = { RABS }; /* absolute relocation */ -int expr_flags; /* flags set by getexpr */ -#define EXPR_GPREL 1 /* gp relative relocation */ -#define EXPR_HI 2 /* %hi function */ -#define EXPR_LO 4 /* %lo function */ - -/* Forward declarations. */ +void getbitmask (void); unsigned getexpr (int *s); -/* - * Fatal error message. - */ void uerror (char *fmt, ...) { va_list ap; @@ -401,18 +333,13 @@ void uerror (char *fmt, ...) fprintf (stderr, "as: "); if (infile) fprintf (stderr, "%s, ", infile); - if (line) - fprintf (stderr, "%d: ", line); + fprintf (stderr, "%d: ", line); vfprintf (stderr, fmt, ap); va_end (ap); fprintf (stderr, "\n"); exit (1); } -/* - * Read a 4-byte word from the file. - * Little-endian. - */ unsigned fgetword (f) FILE *f; { @@ -423,10 +350,6 @@ unsigned fgetword (f) return w; } -/* - * Write a 4-byte word to the file. - * Little-endian. - */ void fputword (w, f) unsigned int w; FILE *f; @@ -435,57 +358,40 @@ void fputword (w, f) } /* -* Read a relocation record: 1 to 6 bytes. -*/ -void fgetrel (f, r) - register FILE *f; - register struct reloc *r; -{ - r->flags = getc (f); - if ((r->flags & RSMASK) == REXT) { - r->index = getc (f); - r->index |= getc (f) << 8; - r->index |= getc (f) << 16; - } - if ((r->flags & RFMASK) == RHIGH16 || - (r->flags & RFMASK) == RHIGH16S) - { - r->offset = getc (f); - r->offset |= getc (f) << 8; - } -} - -/* -* Emit a relocation record: 1 to 6 bytes. -* Return a written length. -*/ -unsigned fputrel (r, f) - register struct reloc *r; - register FILE *f; -{ - register unsigned nbytes = 1; - - putc (r->flags, f); - if ((r->flags & RSMASK) == REXT) { - putc (r->index, f); - putc (r->index >> 8, f); - putc (r->index >> 16, f); - nbytes += 3; - } - if ((r->flags & RFMASK) == RHIGH16 || - (r->flags & RFMASK) == RHIGH16S) - { - putc (r->offset, f); - putc (r->offset >> 8, f); - nbytes += 2; - } - return nbytes; -} - -/* - * Write the a.out header to the file. - * Little-endian. + * Read a relocation record: 1 or 4 bytes. */ +unsigned int fgetrel (f) + register FILE *f; +{ + register unsigned int r; + + r = getc (f); + if ((r & RSMASK) == REXT) { + r |= getc (f) << 8; + r |= getc (f) << 16; + r |= getc (f) << 24; + } + return r; +} + +/* + * Emit a relocation record: 1 or 4 bytes. + * Return a written length. + */ +unsigned int fputrel (r, f) + register unsigned int r; + register FILE *f; +{ + putc (r, f); + if ((r & RSMASK) != REXT) { + return 1; + } + putc (r >> 8, f); + putc (r >> 16, f); + putc (r >> 24, f); + return 4; +} + void fputhdr (filhdr, coutb) register struct exec *filhdr; register FILE *coutb; @@ -500,9 +406,6 @@ void fputhdr (filhdr, coutb) fputword (filhdr->a_entry, coutb); } -/* - * Emit the nlist record for the symbol. - */ void fputsym (s, file) register struct nlist *s; register FILE *file; @@ -510,25 +413,17 @@ void fputsym (s, file) register int i; putc (s->n_len, file); - putc (s->n_type & ~N_LOC, file); + putc (s->n_type, file); fputword (s->n_value, file); for (i=0; in_len; i++) putc (s->n_name[i], file); } -/* - * Create temporary files for STEXT, SDATA and SSTRNG segments. - */ void startup () { register int i; - int fd = mkstemp (tfilename); - if (fd == -1) { - uerror ("cannot create temporary file %s", tfilename); - } else { - close(fd); - } + mktemp (tfilename); for (i=STEXT; i=0; c-=4, ++p) { + if (p >= cp) + return; + intval |= *p << c; + } +} + /* * Get hexadecimal number 0xZZZ */ @@ -610,8 +526,9 @@ void gethnum () /* * Get a number. - * 1234 - decimal - * 01234 - octal + * 1234 1234d 1234D - decimal + * 01234 1234. 1234o 1234O - octal + * 1234' 1234h 1234H - hexadecimal */ void getnum (c) register int c; @@ -620,12 +537,11 @@ void getnum (c) int leadingzero; leadingzero = (c=='0'); - for (cp=name; ISDIGIT(c); c=getchar()) + for (cp=name; ISHEX(c); c=getchar()) *cp++ = hexdig (c); - ungetc (c, stdin); intval = 0; - if (leadingzero) { - /* Octal. */ + if (c=='.' || c=='o' || c=='O') { +octal: for (c=0; c<=27; c+=3) { if (--cp < name) return; @@ -635,8 +551,18 @@ void getnum (c) return; intval |= *cp << 30; return; + } else if (c=='h' || c=='H' || c=='\'') { + for (c=0; c<32; c+=4) { + if (--cp < name) + return; + intval |= *cp << c; + } + return; + } else if (c!='d' && c!='D') { + ungetc (c, stdin); + if (leadingzero) + goto octal; } - /* Decimal. */ for (c=1; ; c*=10) { if (--cp < name) return; @@ -655,52 +581,14 @@ void getname (c) ungetc (c, stdin); } -int looktype () -{ - switch (name [1]) { - case 'c': - if (! strcmp ("@common", name)) return (LSYMTYPE); - break; - case 'f': - if (! strcmp ("@fini_array", name)) return (LSECTYPE); - if (! strcmp ("@function", name)) return (LSYMTYPE); - break; - case 'g': - if (! strcmp ("@gnu_indirect_function", name)) return (LSYMTYPE); - if (! strcmp ("@gnu_unique_object", name)) return (LSYMTYPE); - break; - case 'i': - if (! strcmp ("@init_array", name)) return (LSECTYPE); - break; - case 'n': - if (! strcmp ("@nobits", name)) return (LSECTYPE); - if (! strcmp ("@note", name)) return (LSECTYPE); - if (! strcmp ("@notype", name)) return (LSYMTYPE); - break; - case 'o': - if (! strcmp ("@object", name)) return (LSYMTYPE); - break; - case 'p': - if (! strcmp ("@progbits", name)) return (LSECTYPE); - if (! strcmp ("@preinit_array", name)) return (LSECTYPE); - break; - case 't': - if (! strcmp ("@tls_object", name)) return (LSYMTYPE); - break; - } - return (-1); -} - int lookacmd () { switch (name [1]) { case 'a': if (! strcmp (".ascii", name)) return (LASCII); - if (! strcmp (".align", name)) return (LALIGN); break; case 'b': if (! strcmp (".bss", name)) return (LBSS); - if (! strcmp (".byte", name)) return (LBYTE); break; case 'c': if (! strcmp (".comm", name)) return (LCOMM); @@ -710,90 +598,24 @@ int lookacmd () break; case 'e': if (! strcmp (".equ", name)) return (LEQU); - if (! strcmp (".end", name)) return (LEND); - if (! strcmp (".ent", name)) return (LENT); - break; - case 'f': - if (! strcmp (".file", name)) return (LFILE); - if (! strcmp (".fmask", name)) return (LFMASK); - if (! strcmp (".frame", name)) return (LFRAME); break; case 'g': if (! strcmp (".globl", name)) return (LGLOBL); - if (! strcmp (".gnu_attribute", name)) return (LGNUATTR); - break; - case 'h': - if (! strcmp (".half", name)) return (LHALF); - break; - case 'i': - if (! strcmp (".ident", name)) return (LIDENT); - break; - case 'l': - if (! strcmp (".local", name)) return (LLOCAL); - break; - case 'm': - if (! strcmp (".mask", name)) return (LMASK); - break; - case 'n': - if (! strcmp (".nan", name)) return (LNAN); - break; - case 'p': - if (! strcmp (".previous", name)) return (LPREVIOUS); - break; - case 'r': - if (! strcmp (".rdata", name)) return (LRDATA); break; case 's': - if (! strcmp (".section", name)) return (LSECTION); - if (! strcmp (".set", name)) return (LSET); - if (! strcmp (".size", name)) return (LSIZE); - if (! strcmp (".space", name)) return (LSPACE); + if (! strcmp (".short", name)) return (LSHORT); if (! strcmp (".strng", name)) return (LSTRNG); break; case 't': if (! strcmp (".text", name)) return (LTEXT); - if (! strcmp (".type", name)) return (LTYPE); break; case 'w': if (! strcmp (".word", name)) return (LWORD); - if (! strcmp (".weak", name)) return (LWEAK); break; } return (-1); } -/* - * Change a segment based on a section name. - */ -void setsection () -{ - struct { - const char *name; - int len; - int segm; - } const *p, map[] = { - { ".text", 5, STEXT }, - { ".data", 5, SDATA }, - { ".sdata", 6, SDATA }, - { ".rodata", 7, SSTRNG }, - { ".bss", 4, SBSS }, - { ".sbss", 5, SBSS }, - { ".mdebug", 7, SSTRNG }, - { 0 }, - }; - - for (p=map; p->name; p++) { - if (strncmp (name, p->name, p->len) == 0 && - (p->name [p->len] == 0 || - p->name [p->len] == '.')) - { - segm = p->segm; - return; - } - } - uerror ("bad .section name"); -} - int lookreg () { int val; @@ -810,6 +632,7 @@ int lookreg () if (*cp != 0) break; return val; + break; case 'a': if (name[3] == 0) { switch (name[2]) { @@ -886,7 +709,8 @@ int lookreg () return 0; /* $zero */ break; } - return -1; + uerror ("bad register name '%s'", name); + return 0; } int lookcmd () @@ -934,7 +758,7 @@ int lookname () stab[i].n_name = alloc (1 + stab[i].n_len); strcpy (stab[i].n_name, name); stab[i].n_value = 0; - stab[i].n_type = N_UNDF; + stab[i].n_type = 0; hashtab[h] = i; return (i); } @@ -945,7 +769,8 @@ int lookname () * LEOL - End of line. Value is a line number. * LEOF - End of file. * LNUM - Integer value (into intval), *val undefined. - * LNAME - Identifier. String value is in name[] array. + * LCMD - Machine opcode. Value is optable[] index. + * LNAME - Identifier. Value is stab[] index. * LREG - Machine register. Value is a register number. * LLSHIFT - << operator. * LRSHIFT - >> operator. @@ -954,13 +779,11 @@ int lookname () * LCOMM - .comm assembler instruction. * LDATA - .data assembler instruction. * LGLOBL - .globl assembler instruction. - * LHALF - .half assembler instruction. + * LSHORT - .short assembler instruction. * LSTRNG - .strng assembler instruction. * LTEXT - .text assembler instruction. * LEQU - .equ assembler instruction. * LWORD - .word assembler instruction. - * LFILE - .file assembler instruction. - * LSECTION - .section assembler instruction. */ int getlex (pval) register int *pval; @@ -984,7 +807,6 @@ skiptoeol: while ((c = getchar()) != '\n') if (c == '#') goto skiptoeol; ungetc (c, stdin); - case ';': *pval = line; return (LEOL); case ' ': @@ -1000,13 +822,16 @@ skiptoeol: while ((c = getchar()) != '\n') return (LRSHIFT); ungetc (c, stdin); return ('\\'); - case '\'': case '%': + case '+': case '-': case '^': case '&': case '|': case '~': - case '+': case '-': case '*': case '/': + case ';': case '*': case '/': case '%': case '"': case ',': case '[': case ']': case '(': case ')': case '{': case '}': case '<': case '>': case '=': case ':': return (c); + case '\'': + getlhex (c); + return (LNUM); case '0': if ((c = getchar ()) == 'x' || c=='X') { gethnum (); @@ -1022,6 +847,22 @@ skiptoeol: while ((c = getchar()) != '\n') default: if (! ISLETTER (c)) uerror ("bad character: \\%o", c & 0377); + if (c == '.') { + c = getchar(); + if (c == '[') { + getbitmask (); + return (LNUM); + } else if (ISOCTAL (c)) { + getnum (c); + c = intval; + if (c < 0 || c >= 32) + uerror ("bit number out of range 0..31"); + intval = 1 << c; + return (LNUM); + } + ungetc (c, stdin); + c = '.'; + } getname (c); if (name[0] == '.') { if (name[1] == 0) @@ -1035,11 +876,10 @@ skiptoeol: while ((c = getchar()) != '\n') if (*pval != -1) return (LREG); } - if (name[0] == '@') { - *pval = looktype(); - if (*pval != -1) - return (*pval); - } + *pval = lookcmd(); + if (*pval != -1) + return (LCMD); + *pval = lookname (); return (LNAME); } } @@ -1061,24 +901,9 @@ int getterm () default: uerror ("operand missed"); case LNUM: - cval = getchar (); - if (cval == 'b' || cval == 'B') - extref = RLAB_OFFSET - intval; - else if (cval == 'f' || cval == 'F') - extref = RLAB_OFFSET + intval; - else { - /* Integer literal. */ - ungetc (cval, stdin); - return (SABS); - } - /* Local label. */ - if (intval >= RLAB_MAXVAL) - uerror ("too large relative label"); - intval = 0; - return (SEXT); + return (SABS); case LNAME: intval = 0; - cval = lookname(); ty = stab[cval].n_type & N_TYPE; if (ty==N_UNDF || ty==N_COMM) { extref = cval; @@ -1089,21 +914,6 @@ int getterm () case '.': intval = count[segm]; return (segm); - case '%': - if (getlex (&cval) != LNAME) - uerror ("bad %function name"); - if (strcmp (name, "gp_rel") == 0) { - /* GP relative reverence. */ - expr_flags |= EXPR_GPREL; - } else if (strcmp (name, "hi") == 0) { - expr_flags |= EXPR_HI; - } else if (strcmp (name, "lo") == 0) { - expr_flags |= EXPR_LO; - } else - uerror ("unknown function %s", name); - if (getlex (&cval) != '(') - uerror ("bad %s syntax", name); - /* fall through */ case '(': getexpr (&s); if (getlex (&cval) != ')') @@ -1112,6 +922,34 @@ int getterm () } } +/* + * Get a number .[a:b], where a, b are bit numbers 0..31 + */ +void getbitmask () +{ + register int c, a, b; + int v; + + a = getexpr (&v) - 1; + if (v != SABS) + uerror ("illegal expression in bit mask"); + c = getlex (&v); + if (c != ':') + uerror ("illegal bit mask delimiter"); + b = getexpr (&v) - 1; + if (v != SABS) + uerror ("illegal expression in bit mask"); + c = getlex (&v); + if (c != ']') + uerror ("illegal bit mask delimiter"); + if (a<0 || a>=32 || b<0 || b>=32) + uerror ("bit number out of range 0..31"); + if (a < b) + c = a, a = b, b = c; + /* a greater than or equal to b */ + intval = (unsigned) ~0 >> (31 - a + b) << b; +} + /* * Get an expression. * Return a value, put a base segment id to *s. @@ -1119,7 +957,7 @@ int getterm () * * expression = [term] {op term}... * term = LNAME | LNUM | "." | "(" expression ")" - * op = "+" | "-" | "&" | "|" | "^" | "~" | "<<" | ">>" | "/" | "*" + * op = "+" | "-" | "&" | "|" | "^" | "~" | "<<" | ">>" | "/" | "*" | "%" */ unsigned getexpr (s) register int *s; @@ -1139,7 +977,6 @@ unsigned getexpr (s) case LNAME: case '.': case '(': - case '%': ungetlex (clex, cval); *s = getterm (); rez = intval; @@ -1157,9 +994,7 @@ unsigned getexpr (s) break; case '-': s2 = getterm (); - if (s2 == *s && s2 != SEXT) - *s = SABS; - else if (s2 != SABS) + if (s2 != SABS) uerror ("too complex expression"); rez -= intval; break; @@ -1213,6 +1048,14 @@ unsigned getexpr (s) uerror ("division by zero"); rez /= intval; break; + case '%': + s2 = getterm (); + if (*s != SABS || s2 != SABS) + uerror ("too complex expression"); + if (intval == 0) + uerror ("division (%%) by zero"); + rez %= intval; + break; default: ungetlex (clex, cval); intval = rez; @@ -1222,42 +1065,12 @@ unsigned getexpr (s) /* NOTREACHED */ } -void reorder_flush () -{ - if (reorder_full) { - fputword (reorder_word, sfile[segm]); - fputrel (&reorder_rel, rfile[segm]); - reorder_full = 0; - } -} - -/* - * Default emit function. - */ -void emitword (w, r, clobber_reg) - register unsigned w; - register struct reloc *r; - int clobber_reg; -{ - if (mode_reorder && segm == STEXT) { - reorder_flush(); - reorder_word = w; - reorder_rel = *r; - reorder_full = 1; - reorder_clobber = clobber_reg & 15; - } else { - fputword (w, sfile[segm]); - fputrel (r, rfile[segm]); - } - count[segm] += WORDSZ; -} - /* * LI pseudo instruction. */ void emit_li (opcode, relinfo) register unsigned opcode; - register struct reloc *relinfo; + register unsigned relinfo; { register unsigned value; int cval, segment; @@ -1267,22 +1080,23 @@ void emit_li (opcode, relinfo) value = getexpr (&segment); if (segment != SABS) uerror ("absolute value required"); - if (value <= 0xffff) { + if (value >= 0 && value <= 0xffff) { /* ori d, $zero, value */ opcode |= 0x34000000 | value; } else if (value >= -0x8000) { /* addiu d, $zero, value */ - opcode |= 0x24000000 | (value & 0xffff); - } else if ((value & 0xffff) == 0) { - /* lui d, value[31:16] */ - opcode |= 0x3c000000 | (value >> 16); + opcode |= 0x24000000 | value; } else { - /* lui d, value[31:16] - * ori d, d, value[15:0]) */ - emitword (opcode | 0x3c000000 | (value >> 16), &relabs, value >> 16); + /* lui d, %hi(value) + * ori d, d, %lo(value) */ + fputword (opcode | 0x3c000000 | (value >> 16), sfile[segm]); + fputrel (RABS, rfile[segm]); + count[segm] += WORDSZ; opcode |= 0x34000000 | (opcode & 0x1f0000) << 5 | (value & 0xffff); } - emitword (opcode, relinfo, value >> 16); + fputword (opcode, sfile[segm]); + fputrel (relinfo, rfile[segm]); + count[segm] += WORDSZ; } /* @@ -1290,33 +1104,42 @@ void emit_li (opcode, relinfo) */ void emit_la (opcode, relinfo) register unsigned opcode; - register struct reloc *relinfo; + register unsigned relinfo; { - register unsigned value, hi; + register unsigned value; int cval, segment; if (getlex (&cval) != ',') uerror ("comma expected"); - expr_flags = 0; value = getexpr (&segment); if (segment == SABS) - uerror ("relocatable value required"); - relinfo->flags = segmrel [segment]; - if (relinfo->flags == REXT) - relinfo->index = extref; - if (expr_flags & EXPR_GPREL) - relinfo->flags |= RGPREL; + uerror ("relocatable value required"); + relinfo = segmrel [segment]; + if (relinfo == REXT) + relinfo |= RSETINDEX (extref); /* lui d, %hi(value) - * addiu d, d, %lo(value) */ - relinfo->flags |= RHIGH16S; - relinfo->offset = value & 0xffff; - hi = (value + 0x8000) >> 16; - emitword (opcode | 0x3c000000 | hi, relinfo, hi); + * ori d, d, %lo(value) */ + fputword (opcode | 0x3c000000 | (value >> 16), sfile[segm]); + fputrel (relinfo | RHIGH16, rfile[segm]); + count[segm] += WORDSZ; - relinfo->flags &= ~RHIGH16S; - opcode |= 0x24000000 | (opcode & 0x1f0000) << 5 | (value & 0xffff); - emitword (opcode, relinfo, value >> 16); + opcode |= 0x34000000 | (opcode & 0x1f0000) << 5 | (value & 0xffff); + fputword (opcode, sfile[segm]); + fputrel (relinfo, rfile[segm]); + count[segm] += WORDSZ; +} + +/* + * Default emit function. + */ +void emitword (w, r) + register unsigned w; + register unsigned r; +{ + fputword (w, sfile[segm]); + fputrel (r, rfile[segm]); + count[segm] += WORDSZ; } /* @@ -1324,40 +1147,18 @@ void emit_la (opcode, relinfo) */ void makecmd (opcode, type, emitfunc) unsigned opcode; - void (*emitfunc) (unsigned, struct reloc*); + void (*emitfunc) (unsigned, unsigned); { - unsigned offset, orig_opcode = 0; - struct reloc relinfo; - int clex, cval, segment, clobber_reg, negate_literal; + register int clex; + register unsigned offset, relinfo; + int cval, segment; offset = 0; - relinfo.flags = RABS; - negate_literal = 0; - - /* - * GCC can generate "j" instead of "jr". - * Need to detect it early. - */ - if (type == (FAOFF28 | FDSLOT)) { - clex = getlex (&cval); - ungetlex (clex, cval); - if (clex == LREG) { - if (opcode == 0x08000000) { /* j - replace by jr */ - opcode = 0x00000008; - type = FRS1 | FDSLOT; - } - if (opcode == 0x0c000000) { /* jal - replace by jalr */ - opcode = 0x00000009; - type = FRD1 | FRS2 | FDSLOT; - } - } - } + relinfo = RABS; /* * First register. */ - cval = 0; - clobber_reg = 0; if (type & FRD1) { clex = getlex (&cval); if (clex != LREG) @@ -1371,24 +1172,14 @@ void makecmd (opcode, type, emitfunc) opcode |= cval << 16; /* rt, ... */ } if (type & FRS1) { -frs1: clex = getlex (&cval); + clex = getlex (&cval); if (clex != LREG) uerror ("bad rs register"); - if (cval == 0 && (opcode == 0x0000001a || /* div */ - opcode == 0x0000001b)) { /* divu */ - /* Div instruction with three args. - * Treat it as a 2-arg variant. */ - if (getlex (&cval) != ',') - uerror ("comma expected"); - goto frs1; - } opcode |= cval << 21; /* rs, ... */ } if (type & FRTD) { opcode |= cval << 16; /* rt equals rd */ } - if ((type & FMOD) && (type & (FRD1 | FRT1 | FRS1))) - clobber_reg = cval; /* * Second register. @@ -1405,45 +1196,16 @@ frs1: clex = getlex (&cval); if (getlex (&cval) != ',') uerror ("comma expected"); clex = getlex (&cval); - if (clex != LREG) { - if ((type & FRD1) && (type & FSA)) { - /* Second register operand omitted. - * Need to restore the missing operand. */ - ungetlex (clex, cval); - cval = (opcode >> 11) & 31; /* get 1-st register */ - opcode |= cval << 16; /* use 1-st reg as 2-nd */ - goto fsa; - } + if (clex != LREG) uerror ("bad rt register"); - } opcode |= cval << 16; /* .., rt, ... */ } if (type & FRS2) { + if (getlex (&cval) != ',') + uerror ("comma expected"); clex = getlex (&cval); - if (clex != ',') { - if ((opcode & 0xfc00003f) != 0x00000009) - uerror ("comma expected"); - /* Jalr with one argument. - * Treat as if the first argument is $31. */ - ungetlex (clex, cval); - cval = (opcode >> 11) & 31; /* get 1-st register */ - opcode |= cval << 21; /* use 1-st reg as 2-nd */ - opcode |= 31 << 11; /* set 1-st reg to 31 */ - clobber_reg = 31; - goto done3; - } - clex = getlex (&cval); - if (clex != LREG) { - if ((type & FRT1) && (type & FOFF16)) { - /* Second register operand omitted. - * Need to restore the missing operand. */ - ungetlex (clex, cval); - cval = (opcode >> 16) & 31; /* get 1-st register */ - opcode |= cval << 21; /* use 1-st reg as 2-nd */ - goto foff16; - } + if (clex != LREG) uerror ("bad rs register"); - } opcode |= cval << 21; /* .., rs, ... */ } @@ -1451,70 +1213,21 @@ frs1: clex = getlex (&cval); * Third register. */ if (type & FRT3) { + if (getlex (&cval) != ',') + uerror ("comma expected"); clex = getlex (&cval); - if (clex != ',') { - /* Three-operand instruction used with two operands. - * Need to restore the missing operand. */ - ungetlex (clex, cval); - cval = (opcode >> 21) & 31; - opcode &= ~(31 << 21); /* clear 2-nd register */ - opcode |= ((opcode >> 11) & 31) << 21; /* use 1-st reg as 2-nd */ - opcode |= cval << 16; /* add 3-rd register */ - goto done3; - } - clex = getlex (&cval); - if (clex != LREG) { - if ((type & FRD1) && (type & FRS2)) { - /* Three-operand instruction used with literal operand. - * Convert it to immediate type. */ - unsigned newop; - switch (opcode & 0xfc0007ff) { - case 0x00000020: newop = 0x20000000; break; // add -> addi - case 0x00000021: newop = 0x24000000; break; // addu -> addiu - case 0x00000024: newop = 0x30000000; break; // and -> andi - case 0x00000025: newop = 0x34000000; break; // or -> ori - case 0x0000002a: newop = 0x28000000; break; // slt -> slti - case 0x0000002b: newop = 0x2c000000; break; // sltu -> sltiu - case 0x00000022: newop = 0x20000000; // sub -> addi, negate - negate_literal = 1; break; - case 0x00000023: newop = 0x24000000; // subu -> addiu, negate - negate_literal = 1; break; - case 0x00000026: newop = 0x38000000; break; // xor -> xori - default: - uerror ("bad rt register"); - return; - } - ungetlex (clex, cval); - cval = (opcode >> 11) & 31; /* get 1-st register */ - newop |= cval << 16; /* set 1-st register */ - newop |= opcode & (31 << 21); /* set 2-nd register */ - orig_opcode = opcode; - opcode = newop; - type = FRT1 | FRS2 | FOFF16 | FMOD; - goto foff16; - } + if (clex != LREG) uerror ("bad rt register"); - } opcode |= cval << 16; /* .., .., rt */ } if (type & FRS3) { - clex = getlex (&cval); - if (clex != ',') { - /* Three-operand instruction used with two operands. - * Need to restore the missing operand. */ - ungetlex (clex, cval); - cval = (opcode >> 16) & 31; - opcode &= ~(31 << 16); /* clear 2-nd register */ - opcode |= ((opcode >> 11) & 31) << 16; /* use 1-st reg as 2-nd */ - opcode |= cval << 21; /* add 3-rd register */ - goto done3; - } + if (getlex (&cval) != ',') + uerror ("comma expected"); clex = getlex (&cval); if (clex != LREG) uerror ("bad rs register"); opcode |= cval << 21; /* .., .., rs */ } -done3: /* * Immediate argument. @@ -1532,40 +1245,9 @@ done3: } else if (type & (FCODE | FCODE16 | FSA)) { /* Non-relocatable offset */ - if (type & FSA) { - if (getlex (&cval) != ',') - uerror ("comma expected"); - clex = getlex (&cval); - if (clex == LREG && type == (FRD1 | FRT2 | FSA | FMOD)) { - /* Literal-operand shift instruction used with register operand. - * Convert it to 3-register type. */ - unsigned newop; - switch (opcode & 0xffe0003f) { - case 0x00200002: newop = 0x00000046; break; // ror -> rorv - case 0x00000000: newop = 0x00000004; break; // sll -> sllv - case 0x00000003: newop = 0x00000007; break; // sra -> srav - case 0x00000002: newop = 0x00000006; break; // srl -> srlv - default: - uerror ("bad shift amount"); - return; - } - newop |= opcode & (0x3ff << 11); /* set 1-st and 2-nd regs */ - newop |= cval << 21; /* set 3-rd register */ - opcode = newop; - type = FRD1 | FRT2 | FRS3 | FMOD; - goto done3; - } - ungetlex (clex, cval); - } - if ((type & FCODE) && (type & FRT2)) { - /* Optional code for trap instruction. */ - clex = getlex (&cval); - if (clex != ',') { - ungetlex (clex, cval); - goto done; - } - } -fsa: offset = getexpr (&segment); + if ((type & FSA) && getlex (&cval) != ',') + uerror ("comma expected"); + offset = getexpr (&segment); if (segment != SABS) uerror ("absolute value required"); switch (type & (FCODE | FCODE16 | FSA)) { @@ -1581,94 +1263,39 @@ fsa: offset = getexpr (&segment); } } else if (type & (FOFF16 | FOFF18 | FAOFF18 | FAOFF28 | FHIGH16)) { /* Relocatable offset */ - int valid_range; - if ((type & (FOFF16 | FOFF18 | FHIGH16)) && getlex (&cval) != ',') uerror ("comma expected"); -foff16: expr_flags = 0; offset = getexpr (&segment); - relinfo.flags = segmrel [segment]; - if (relinfo.flags == REXT) - relinfo.index = extref; - if (expr_flags & EXPR_GPREL) - relinfo.flags |= RGPREL; + relinfo = segmrel [segment]; + if (relinfo == REXT) + relinfo |= RSETINDEX (extref); switch (type & (FOFF16 | FOFF18 | FAOFF18 | FAOFF28 | FHIGH16)) { case FOFF16: /* low 16-bit byte address */ - /* Test whether the immediate is in valid range - * for the opcode. */ - if (negate_literal) { - // Negate literal arg for sub and subu - offset = -offset; - if (relinfo.flags != RABS) - uerror ("cannot negate relocatable literal"); - } - switch (opcode & 0xfc000000) { - default: /* addi, addiu, slti, sltiu, lw, sw */ - /* 16-bit signed value. */ - valid_range = (offset >= -0x8000) || (offset <= 0x7fff); - break; - case 0x30000000: /* andi */ - case 0x34000000: /* ori */ - case 0x38000000: /* xori */ - /* 16-bit unsigned value. */ - valid_range = (offset <= 0xffff); - break; - } - if (valid_range) { - opcode |= offset & 0xffff; - } else if (orig_opcode == 0 || ! mode_at) { - uerror ("value out of range"); - } else { - /* Convert back to 3-reg opcode. - * Insert an extra LI instruction. */ - if (segment != SABS) - uerror ("absolute value required"); - if (negate_literal) - offset = -offset; - - if (offset <= 0xffff) { - /* ori $1, $zero, value */ - emitword (0x34010000 | offset, &relabs, 1); - } else if (offset >= -0x8000) { - /* addiu $1, $zero, value */ - emitword (0x24010000 | (offset & 0xffff), &relabs, 1); - } else if ((offset & 0xffff) == 0) { - /* lui $1, value[31:16] */ - emitword (0x3c010000 | (offset >> 16), &relabs, 1); - } else { - /* lui $1, value[31:16] - * ori $1, $1, value[15:0]) */ - emitword (0x3c010000 | (offset >> 16), &relabs, 1); - emitword (0x34210000 | (offset & 0xffff), &relabs, 1); - } - opcode = orig_opcode | 0x10000; - } + opcode |= offset & 0xffff; break; case FHIGH16: /* high 16-bit byte address */ - if (expr_flags & EXPR_HI) { - /* %hi function - assume signed offset */ - relinfo.flags |= RHIGH16S; - relinfo.offset = offset & 0xffff; - offset += 0x8000; - opcode |= offset >> 16; - } else { + if (relinfo == RABS) opcode |= offset & 0xffff; + else { + opcode |= (offset >> 16) & 0xffff; + relinfo |= RHIGH16; } + /* TODO: keep full offset in relinfo value */ break; case FOFF18: /* 18-bit PC-relative word address */ case FAOFF18: if (segment == segm) { offset -= count[segm] + 4; - relinfo.flags = RABS; + relinfo = RABS; } else if (segment == SEXT) { - relinfo.flags |= RWORD16; + relinfo |= RWORD16; } else - uerror ("invalid segment %d", segment); + uerror ("invalid segment"); opcode |= (offset >> 2) & 0xffff; break; case FAOFF28: /* 28-bit word address */ opcode |= (offset >> 2) & 0x3ffffff; - relinfo.flags |= RWORD26; + relinfo |= RWORD26; break; } } @@ -1704,66 +1331,16 @@ foff16: expr_flags = 0; offset = 32; opcode |= ((offset - 1) & 0x1f) << 11; /* msb */ } -done: /* Output resulting values. */ - if (emitfunc) { - emitfunc (opcode, &relinfo); - } else if (mode_reorder && (type & FDSLOT) && segm == STEXT) { - /* Need a delay slot. */ - if (reorder_full && reorder_clobber != 0) { - /* Analyse register dependency. - * Flush the instruction if needed. */ - int rt = (opcode >> 16) & 31; - int rs = (opcode >> 21) & 31; - if (((type & (FRS1 | FRS2)) && rs == reorder_clobber) || - ((type & FRT2) && rt == reorder_clobber)) - reorder_flush(); - } - fputword (opcode, sfile[segm]); - fputrel (&relinfo, rfile[segm]); - if (reorder_full) { - /* Delay slot: insert a previous instruction. */ - reorder_flush(); - } else { - /* Insert NOP in delay slot. */ - fputword (0, sfile[segm]); - fputrel (&relabs, rfile[segm]); - count[segm] += WORDSZ; - } - count[segm] += WORDSZ; - } else { - emitword (opcode, &relinfo, clobber_reg); - } -} - -/* - * Increment the current segment by nbytes. - * Emit a needed amount of zeroes to sfile and rfile. - * Part of data have already been sent to rfile; - * length specified by 'done' argument. - */ -void add_space (nbytes, fill_data) - unsigned nbytes, fill_data; -{ - unsigned c; - - if (segm < SBSS) { - /* Emit data and relocation. */ - for (c=0; c='0' && c<='7') { - c = getchar (); - if (c>='0' && c<='7') { - } else - ungetc (c, stdin); - } else - ungetc (c, stdin); - break; - } - default: - continue; - } - break; - } -} - -/* - * Set assembler option. - */ -void setoption () -{ - const char *option = name; - int enable = 1; - - if (option[0] == 'n' && option[1] == 'o') { - enable = 0; - option += 2; - } - if (! strcmp ("reorder", option)) { - /* reorder mode */ - mode_reorder = enable; - if (! mode_reorder) - reorder_flush(); - return; - } - if (! strcmp ("macro", option)) { - /* macro mode */ - mode_macro = enable; - return; - } - if (! strcmp ("mips16", option)) { - /* mips16 mode */ - mode_mips16 = enable; - return; - } - if (! strcmp ("micromips", option)) { - /* micromips mode */ - mode_micromips = enable; - return; - } - if (! strcmp ("at", option)) { - /* at mode */ - mode_at = enable; - return; - } - uerror ("unknown option %s", option); -} - -/* - * Align the current segment. - */ -void align (align_bits) -{ - unsigned nbytes, align_mask, c; - - align_mask = (1 << align_bits) - 1; - nbytes = count[segm] & align_mask; - if (nbytes == 0) - return; - nbytes = align_mask + 1 - nbytes; - if (segm < SBSS) { - /* Emit data and relocation. */ - for (c=0; c= MAXRLAB) - uerror ("too many digital labels"); - reorder_flush(); - labeltab[nlabels].num = intval; - labeltab[nlabels].value = count[segm]; - ++nlabels; - clex = getlex (&tval); - if (clex != ':') - uerror ("bad digital label"); - continue; + uerror ("bad instruction"); case LTEXT: segm = STEXT; - reorder_flush(); break; case LDATA: segm = SDATA; break; case LSTRNG: - case LRDATA: segm = SSTRNG; break; case LBSS: segm = SBSS; break; - case LWORD: - reorder_flush(); - align (2); + case LSHORT: for (;;) { - struct reloc relinfo; - expr_flags = 0; getexpr (&cval); - relinfo.flags = RBYTE32 | segmrel [cval]; + addr = segmrel [cval]; if (cval == SEXT) - relinfo.index = extref; - if (expr_flags & EXPR_GPREL) - relinfo.flags |= RGPREL; - emitword (intval, &relinfo, 0); + addr |= RSETINDEX (extref); + emitword (intval, addr); clex = getlex (&cval); if (clex != ',') { ungetlex (clex, cval); @@ -2067,64 +1498,30 @@ void pass1 () } } break; - case LBYTE: - reorder_flush(); - nbytes = 0; + case LWORD: for (;;) { getexpr (&cval); - fputc (intval, sfile[segm]); - nbytes++; + addr = segmrel [cval]; + if (cval == SEXT) + addr |= RSETINDEX (extref); + fputword (intval, sfile[segm]); + fputrel (addr, rfile[segm]); + count[segm] += 2; clex = getlex (&cval); if (clex != ',') { ungetlex (clex, cval); break; } } - add_space (nbytes, 0); - break; - case LHALF: - reorder_flush(); - align (1); - nbytes = 0; - for (;;) { - getexpr (&cval); - fputc (intval, sfile[segm]); - fputc (intval >> 8, sfile[segm]); - nbytes += 2; - clex = getlex (&cval); - if (clex != ',') { - ungetlex (clex, cval); - break; - } - } - add_space (nbytes, 0); - break; - case LSPACE: - /* .space num */ - getexpr (&cval); - reorder_flush(); - add_space (intval, 1); - break; - case LALIGN: - /* .align num */ - if (getlex (&cval) != LNUM) - uerror ("bad parameter of .align"); - reorder_flush(); - align (intval); break; case LASCII: - reorder_flush(); makeascii (); break; case LGLOBL: - /* .globl name, ... */ for (;;) { clex = getlex (&cval); if (clex != LNAME) - uerror ("bad parameter of .globl"); - cval = lookname(); - if (stab[cval].n_type & N_LOC) - uerror ("local name redefined as global"); + uerror ("bad parameter .globl"); stab[cval].n_type |= N_EXT; clex = getlex (&cval); if (clex != ',') { @@ -2133,206 +1530,24 @@ void pass1 () } } break; - case LLOCAL: - /* .local name, ... */ - for (;;) { - clex = getlex (&cval); - if (clex != LNAME) - uerror ("bad parameter of .local"); - cval = lookname(); - if (stab[cval].n_type & N_EXT) - uerror ("global name redefined as local"); - stab[cval].n_type |= N_LOC; - clex = getlex (&cval); - if (clex != ',') { - ungetlex (clex, cval); - break; - } - } - break; - case LWEAK: - /* .weak name */ - for (;;) { - clex = getlex (&cval); - if (clex != LNAME) - uerror ("bad parameter of .weak"); - cval = lookname(); - stab[cval].n_type |= N_WEAK; - clex = getlex (&cval); - if (clex != ',') { - ungetlex (clex, cval); - break; - } - } - break; case LCOMM: - /* .comm name,len[,alignment] */ + /* .comm name,len */ if (getlex (&cval) != LNAME) - uerror ("bad parameter of .comm"); - cval = lookname(); + uerror ("bad parameter .comm"); if (stab[cval].n_type != N_UNDF && - stab[cval].n_type != N_LOC && - (stab[cval].n_type & N_TYPE) != N_COMM) + stab[cval].n_type != (N_EXT|N_COMM)) uerror ("name already defined"); - if (stab[cval].n_type & N_LOC) - stab[cval].n_type = N_COMM; - else - stab[cval].n_type = N_EXT | N_COMM; + stab[cval].n_type = N_EXT | N_COMM; clex = getlex (&tval); if (clex == ',') { getexpr (&tval); if (tval != SABS) - uerror ("bad length of .comm"); + uerror ("bad length .comm"); } else { ungetlex (clex, cval); intval = 1; } stab[cval].n_value = intval; - clex = getlex (&cval); - if (clex != ',') { - ungetlex (clex, cval); - break; - } - getexpr (&tval); - if (tval != SABS) - uerror ("bad .comm alignment"); - break; - case LFILE: - /* .file line filename */ - if (getlex (&cval) != LNUM) - uerror ("bad parameter of .file"); - skipstring(); - break; - case LIDENT: - /* .ident string */ - skipstring(); - break; - case LSECTION: - /* .section name[,"flags"[,type[,entsize]]] */ - clex = getlex (&cval); - if (clex != LNAME && clex != LBSS && clex != LTEXT && clex != LDATA) - uerror ("bad name of .section"); - setsection(); - clex = getlex (&cval); - if (clex != ',') { - ungetlex (clex, cval); - break; - } - clex = getlex (&cval); - if (clex == '"') { - ungetlex (clex, cval); - skipstring(); - } else if (clex != LNAME) - uerror ("bad type of .section"); - clex = getlex (&cval); - if (clex != ',') { - ungetlex (clex, cval); - break; - } - if (getlex (&cval) != LSECTYPE) - uerror ("bad type of .section"); - clex = getlex (&cval); - if (clex != ',') { - ungetlex (clex, cval); - break; - } - if (getlex (&cval) != LNUM) - uerror ("bad entry size of .section"); - break; - case LPREVIOUS: - /* .previous - ignore */ - break; - case LGNUATTR: - /* .gnu_attribute num[,num] */ - if (getlex (&cval) != LNUM) - uerror ("bad parameter of .gnu_attribute"); - clex = getlex (&cval); - if (clex != ',' || getlex (&cval) != LNUM) - uerror ("bad parameter of .gnu_attribute"); - break; - case LSET: - /* .set option */ - if (getlex (&cval) != LNAME) - uerror ("bad parameter of .set"); - setoption(); - break; - case LENT: - /* .ent name */ - clex = getlex (&cval); - if (clex != LNAME) - uerror ("bad parameter of .ent"); - cval = lookname(); - break; - case LEND: - /* .end name */ - clex = getlex (&cval); - if (clex != LNAME) - uerror ("bad parameter of .end"); - cval = lookname(); - break; - case LNAN: - /* .nan name */ - clex = getlex (&cval); - if (clex != LNAME) - uerror ("bad parameter of .nan"); - break; - case LTYPE: - /* .type name,type */ - if (getlex (&cval) != LNAME) - uerror ("bad name of .type"); - clex = getlex (&cval); - if (clex != ',') { - ungetlex (clex, cval); - break; - } - if (getlex (&cval) != LSYMTYPE) - uerror ("bad type of .type"); - break; - case LFRAME: - /* .frame reg,num,reg */ - if (getlex (&cval) != LREG) - uerror ("bad register of .frame"); - clex = getlex (&cval); - if (clex != ',' || getlex (&cval) != LNUM) - uerror ("bad parameter of .frame"); - clex = getlex (&cval); - if (clex != ',' || getlex (&cval) != LREG) - uerror ("bad register of .frame"); - break; - case LMASK: - /* .mask mask,expr */ - if (getlex (&cval) != LNUM) - uerror ("bad mask of .mask"); - clex = getlex (&cval); - if (clex != ',') - uerror ("bad parameter of .mask"); - getexpr (&cval); - if (cval != SABS) - uerror ("bad expression of .mask"); - break; - case LFMASK: - /* .fmask mask,expr */ - if (getlex (&cval) != LNUM) - uerror ("bad mask of .fmask"); - clex = getlex (&cval); - if (clex != ',') - uerror ("bad parameter of .fmask"); - getexpr (&cval); - if (cval != SABS) - uerror ("bad expression of .fmask"); - break; - case LSIZE: - /* .size name,expr */ - if (getlex (&cval) != LNAME) - uerror ("bad name of .size"); - clex = getlex (&cval); - if (clex != ',') { - ungetlex (clex, cval); - break; - } - nbytes = getexpr (&csegm); - if (csegm != SABS) - uerror ("bad value of .size"); break; default: uerror ("bad syntax"); @@ -2346,59 +1561,20 @@ void pass1 () } } -/* - * Find the relative label address, - * by the reference address and the label number. - * Backward references have negative label numbers. - */ -int findlabel (int addr, int sym) -{ - struct labeltab *p; - - if (sym < 0) { - /* Backward reference. */ - for (p=labeltab+nlabels-1; p>=labeltab; --p) { - if (p->value <= addr && p->num == -sym) { - return p->value; - } - } - uerror ("undefined label %db at address %d", -sym, addr); - } else { - /* Forward reference. */ - for (p=labeltab; pvalue > addr && p->num == sym) { - return p->value; - } - } - uerror ("undefined label %df at address %d", sym, addr); - } - return 0; -} - void middle () { - register int i, snum, nbytes; + register int i, snum; stlength = 0; for (snum=0, i=0; iflags & RFMASK) { - case RBYTE32: /* 32 bits of byte address */ - opcode += offset; - break; - case RBYTE16: /* low 16 bits of byte address */ + switch (relinfo & RFMASK) { + case 0: /* low 16 bits of byte address */ offset += opcode & 0xffff; opcode &= ~0xffff; opcode |= offset & 0xffff; break; case RHIGH16: /* high 16 bits of byte address */ + /* TODO: keep full 32-offset in relinfo */ offset += (opcode & 0xffff) << 16; - offset += relinfo->offset; opcode &= ~0xffff; opcode |= (offset >> 16) & 0xffff; - relinfo->offset = offset & 0xffff; - break; - case RHIGH16S: /* high 16 bits of byte address */ - offset += (opcode & 0xffff) << 16; - offset += (signed short) relinfo->offset; - opcode &= ~0xffff; - opcode |= ((offset + 0x8000) >> 16) & 0xffff; - relinfo->offset = offset & 0xffff; break; case RWORD16: /* 16 bits of relative word address */ - uerror ("bad relative relocation: opcode %08x, relinfo %02x", opcode, relinfo->flags); + uerror ("bad relative relocation: opcode %08x, relinfo %08x", opcode, relinfo); break; case RWORD26: /* 26 bits of word address */ offset += (opcode & 0x3ffffff) << 2; @@ -2467,51 +1631,35 @@ unsigned relocate (opcode, offset, relinfo) } unsigned makeword (opcode, relinfo, offset) - register unsigned opcode, offset; - register struct reloc *relinfo; + register unsigned opcode, *relinfo, offset; { - struct nlist *sym; - unsigned value; + register int i; - switch (relinfo->flags & RSMASK) { + switch ((int) *relinfo & REXT) { case RABS: break; case RTEXT: - opcode = relocate (opcode, tbase, relinfo); + opcode = relocate (opcode, tbase, (int) *relinfo); break; case RDATA: - opcode = relocate (opcode, dbase, relinfo); + opcode = relocate (opcode, dbase, (int) *relinfo); break; case RSTRNG: - opcode = relocate (opcode, adbase, relinfo); + opcode = relocate (opcode, adbase, (int) *relinfo); break; case RBSS: - opcode = relocate (opcode, bbase, relinfo); + opcode = relocate (opcode, bbase, (int) *relinfo); break; case REXT: - if (relinfo->index >= RLAB_OFFSET - RLAB_MAXVAL) { - /* Relative label. - * Change relocation to segment type. */ - sym = 0; - value = findlabel (offset, relinfo->index - RLAB_OFFSET); - relinfo->flags &= RGPREL | RFMASK; - relinfo->flags |= segmrel[segm]; - } else { - /* Symbol name. */ - sym = &stab[relinfo->index]; - if (sym->n_type == N_EXT+N_UNDF || sym->n_type == N_EXT+N_COMM) - return opcode; - value = sym->n_value; - } - - switch (relinfo->flags & RFMASK) { - case RWORD16: - /* Relative word address. - * Change relocation to absolute. */ - if (sym && (sym->n_type & N_TYPE) != segmtype[segm]) - uerror ("%s: bad segment for relative relocation, offset %u", - sym->n_name, offset); - offset = value - offset - 4; + i = RINDEX (*relinfo); + if (stab[i].n_type == N_EXT+N_UNDF || + stab[i].n_type == N_EXT+N_COMM) + break; + if ((*relinfo & RFMASK) == RWORD16) { + /* Relative word address */ + if ((stab[i].n_type & N_TYPE) != segmtype[segm]) + uerror ("%s: bad segment for relative relocation", stab[i].n_name); + offset = stab[i].n_value - offset - 4; if (segm == SDATA) offset -= dbase; else if (segm == SSTRNG) @@ -2519,16 +1667,12 @@ unsigned makeword (opcode, relinfo, offset) offset += (opcode & 0xffff) << 2; opcode &= ~0xffff; opcode |= (offset >> 2) & 0xffff; - relinfo->flags = RABS; - return opcode; - case RHIGH16: - value += relinfo->offset; - break; - case RHIGH16S: - value += (signed short) relinfo->offset; + + /* Change relocation to absolute. */ + *relinfo = RABS; break; } - opcode = relocate (opcode, value, relinfo); + opcode = relocate (opcode, stab[i].n_value, (int) *relinfo); break; } return opcode; @@ -2546,24 +1690,26 @@ void pass2 () /* Adjust indexes in symbol name */ for (i=0; iflags & REXT) { + switch ((int) relinfo & REXT) { case RSTRNG: - relinfo->flags &= ~RSMASK; - relinfo->flags |= RDATA; + relinfo = RDATA | (relinfo & RFMASK); break; case REXT: - type = stab[relinfo->index].n_type; - if (type == N_EXT+N_UNDF || type == N_EXT+N_COMM) + i = RINDEX (relinfo); + if (stab[i].n_type == N_EXT+N_UNDF || + stab[i].n_type == N_EXT+N_COMM) { /* Reindexing */ if (xflags) - relinfo->index = newindex [relinfo->index]; - } else { - relinfo->flags &= ~RSMASK; - relinfo->flags |= typerel (type); - } + relinfo = (relinfo & (RFMASK | REXT)) | RSETINDEX (newindex [i]); + } else + relinfo = (relinfo & RFMASK) | typerel (stab[i].n_type); break; } + return (relinfo); } /* @@ -2645,16 +1789,16 @@ unsigned makereloc (s) register int s; { register unsigned i, nbytes; - struct reloc relinfo; + unsigned r, n; if (count [s] <= 0) return 0; rewind (rfile [s]); nbytes = 0; for (i=0; i +# include #else # include #endif diff --git a/src/cmd/as/mips-instruction-set.txt b/src/cmd/as/mips-instruction-set.txt index 6cd4c80..669dd78 100644 --- a/src/cmd/as/mips-instruction-set.txt +++ b/src/cmd/as/mips-instruction-set.txt @@ -226,7 +226,7 @@ RDHWR Read Hardware Register Allows unprivileged acce RDPGPR Read GPR from Previous Shadow Set Rt = SGPR[SRSCtl.PSS, Rd] RESTORE Restore registers and deallocate stack See Architecture Reference Manual - frame (MIPS16e only) + frame (MIPS16eª only) ROTR Rotate Word Right Rd = Rt[sa-1..0] || Rt[31..sa] diff --git a/src/cmd/aout/mips-opc.c b/src/cmd/as/mips-opc.c similarity index 100% rename from src/cmd/aout/mips-opc.c rename to src/cmd/as/mips-opc.c diff --git a/src/cmd/aout/mips-opcode.h b/src/cmd/as/mips-opcode.h similarity index 100% rename from src/cmd/aout/mips-opcode.h rename to src/cmd/as/mips-opcode.h diff --git a/src/cmd/aout/mips16-opc.c b/src/cmd/as/mips16-opc.c similarity index 100% rename from src/cmd/aout/mips16-opc.c rename to src/cmd/as/mips16-opc.c diff --git a/src/cmd/as/tests/test1.s b/src/cmd/as/test.s similarity index 100% rename from src/cmd/as/tests/test1.s rename to src/cmd/as/test.s diff --git a/src/cmd/as/tests/Makefile b/src/cmd/as/tests/Makefile deleted file mode 100644 index 2a7d529..0000000 --- a/src/cmd/as/tests/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -TOPSRC = $(shell cd ../../../..; pwd) -include $(TOPSRC)/target.mk - -CFLAGS += -Wall -Os -TESTS = test1 test2 test3 test4 - -all: ../as ../aout - for i in $(TESTS); do \ - $(AS) $$i.s -o $$i.o; \ - $(OBJDUMP) -D $$i.o > $$i.gcc-dis; \ - ../as $$i.s -o $$i.o; \ - ../aout -r $$i.o > $$i.dis; \ - done - -clean: - rm -f *.o *.dis *.gcc-dis - -hello.s: hello.c - $(CC) $(CFLAGS) -S $< diff --git a/src/cmd/as/tests/hello.c b/src/cmd/as/tests/hello.c deleted file mode 100644 index d7a3e34..0000000 --- a/src/cmd/as/tests/hello.c +++ /dev/null @@ -1,4 +0,0 @@ -void hello() -{ - puts ("Hello, World!\n"); -} diff --git a/src/cmd/as/tests/test2.s b/src/cmd/as/tests/test2.s deleted file mode 100644 index da43fb1..0000000 --- a/src/cmd/as/tests/test2.s +++ /dev/null @@ -1,37 +0,0 @@ - .file 1 "hello.c" - .section .mdebug.abi32 - .previous - .gnu_attribute 4, 3 - .section .rodata.str1.4,"aMS",@progbits,1 - .align 2 -.LC0: - .ascii "Hello, World!\012\000" - .section .text.hello,"ax",@progbits - .align 2 - .globl hello - .set nomips16 - .set nomicromips - .ent hello - .type hello, @function -hello: - .frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, gp= 0 - .mask 0x00000000,0 - .fmask 0x00000000,0 - .set noreorder - .set nomacro -# Begin mchp_output_function_prologue -# End mchp_output_function_prologue - lui $4,%hi(.LC0) - j puts - addiu $4,$4,%lo(.LC0) - - .set macro - .set reorder -# Begin mchp_output_function_epilogue -# End mchp_output_function_epilogue - .end hello - .size hello, .-hello - .ident "GCC: (chipKIT) 4.5.1 chipKIT Compiler for PIC32 MCUs v1.30-20110506" -# Begin MCHP vector dispatch table -# End MCHP vector dispatch table -# MCHP configuration words diff --git a/src/cmd/as/tests/test3.s b/src/cmd/as/tests/test3.s deleted file mode 100644 index 687d9bb..0000000 --- a/src/cmd/as/tests/test3.s +++ /dev/null @@ -1,49 +0,0 @@ - .file 1 "hello.c" - .section .mdebug.abi32 - .previous - .gnu_attribute 4, 3 - .rdata - .align 2 -.LC0: - .ascii "Hello, World!\012\000" - .section .text.hello,"ax",@progbits - .align 2 - .globl hello - .set nomips16 - .set nomicromips - .ent hello - .type hello, @function -hello: - .frame $fp,24,$31 # vars= 0, regs= 2/0, args= 16, gp= 0 - .mask 0xc0000000,-4 - .fmask 0x00000000,0 - .set noreorder - .set nomacro -# Begin mchp_output_function_prologue -# End mchp_output_function_prologue - addiu $sp,$sp,-24 - sw $31,20($sp) - sw $fp,16($sp) - move $fp,$sp - lui $2,%hi(.LC0) - addiu $4,$2,%lo(.LC0) - jal puts - nop - - move $sp,$fp - lw $31,20($sp) - lw $fp,16($sp) - addiu $sp,$sp,24 - j $31 - nop - - .set macro - .set reorder -# Begin mchp_output_function_epilogue -# End mchp_output_function_epilogue - .end hello - .size hello, .-hello - .ident "GCC: (chipKIT) 4.5.1 chipKIT Compiler for PIC32 MCUs v1.30-20110506" -# Begin MCHP vector dispatch table -# End MCHP vector dispatch table -# MCHP configuration words diff --git a/src/cmd/as/tests/test4.s b/src/cmd/as/tests/test4.s deleted file mode 100644 index e958928..0000000 --- a/src/cmd/as/tests/test4.s +++ /dev/null @@ -1,90 +0,0 @@ - .file 1 "crt0.c" - .section .mdebug.abi32 - .previous - .gnu_attribute 4, 3 - .section .text._start,"ax",@progbits - .align 2 - .globl _start - .set nomips16 - .set nomicromips - .ent _start - .type _start, @function -_start: - .frame $sp,24,$31 # vars= 0, regs= 1/0, args= 16, gp= 0 - .mask 0x80000000,-4 - .fmask 0x00000000,0 -# Begin mchp_output_function_prologue -# End mchp_output_function_prologue - addiu $sp,$sp,-24 - sw $31,20($sp) - #APP - # 69 "crt0.c" 1 - la $gp, _gp - # 0 "" 2 - #NO_APP - .set noreorder - .set nomacro - blez $4,.L2 - sw $6,%gp_rel(environ)($28) - .set macro - .set reorder - - lw $2,0($5) - beq $2,$0,.L2 - sw $2,%gp_rel(__progname)($28) - lb $3,0($2) - .set noreorder - .set nomacro - beq $3,$0,.L2 - addiu $2,$2,1 - .set macro - .set reorder - - li $7,47 # 0x2f -.L4: - .set noreorder - .set nomacro - beql $3,$7,.L3 - sw $2,%gp_rel(__progname)($28) - .set macro - .set reorder - -.L3: - lb $3,0($2) - .set noreorder - .set nomacro - bne $3,$0,.L4 - addiu $2,$2,1 - .set macro - .set reorder - -.L2: - jal main - .set noreorder - .set nomacro - jal exit - move $4,$2 - .set macro - .set reorder - -# Begin mchp_output_function_epilogue -# End mchp_output_function_epilogue - .end _start - .size _start, .-_start - .globl __progname - .section .rodata.str1.4,"aMS",@progbits,1 - .align 2 -.LC0: - .ascii "\000" - .section .sdata.__progname,"aw",@progbits - .align 2 - .type __progname, @object - .size __progname, 4 -__progname: - .word .LC0 - - .comm environ,4,4 - .ident "GCC: (chipKIT) 4.5.1 chipKIT Compiler for PIC32 MCUs v1.30-20110506" -# Begin MCHP vector dispatch table -# End MCHP vector dispatch table -# MCHP configuration words diff --git a/src/cmd/awk/.gitignore b/src/cmd/awk/.gitignore deleted file mode 100644 index a000d74..0000000 --- a/src/cmd/awk/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -awk -awk.h -proc -proctab.c -token.h -y.tab.h diff --git a/src/cmd/awk/Makefile b/src/cmd/awk/Makefile index 2bcfc2e..3821c54 100644 --- a/src/cmd/awk/Makefile +++ b/src/cmd/awk/Makefile @@ -5,7 +5,7 @@ CFLAGS += -Werror -Os YACC = bison -y YFLAGS = -d -LIBS = -lm -lc +LIBS = -lm FILES = awk.lx.o b.o main.o tran.o lib.o run.o parse.o proctab.o freeze.o SOURCE = awk.def.h awk.g.y awk.lx.l b.c lib.c main.c parse.c \ proc.c freeze.c run.c tran.c diff --git a/src/cmd/basename.c b/src/cmd/basename.c index 79957a6..ab913ec 100644 --- a/src/cmd/basename.c +++ b/src/cmd/basename.c @@ -4,27 +4,27 @@ main(argc, argv) char **argv; { - register char *p1, *p2, *p3; + register char *p1, *p2, *p3; - if (argc < 2) { - putchar('\n'); - exit(1); - } - p1 = argv[1]; - p2 = p1; - while (*p1) { - if (*p1++ == '/') - p2 = p1; - } - if (argc>2) { - for(p3=argv[2]; *p3; p3++) - ; - while(p1>p2 && p3>argv[2]) - if(*--p3 != *--p1) - goto output; - *p1 = '\0'; - } + if (argc < 2) { + putchar('\n'); + exit(1); + } + p1 = argv[1]; + p2 = p1; + while (*p1) { + if (*p1++ == '/') + p2 = p1; + } + if (argc>2) { + for(p3=argv[2]; *p3; p3++) + ; + while(p1>p2 && p3>argv[2]) + if(*--p3 != *--p1) + goto output; + *p1 = '\0'; + } output: - puts(p2); - exit(0); + puts(p2); + exit(0); } diff --git a/src/cmd/basic/.gitignore b/src/cmd/basic/.gitignore deleted file mode 100644 index 2d4d795..0000000 --- a/src/cmd/basic/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -basic -renumber diff --git a/src/cmd/basic/Makefile b/src/cmd/basic/Makefile index 4c3fafa..8a5c2bc 100644 --- a/src/cmd/basic/Makefile +++ b/src/cmd/basic/Makefile @@ -6,7 +6,7 @@ CFLAGS += -Wall -Werror OBJS = basic.o -LIBS = -lcurses -ltermcap -lm -lc +LIBS = -lcurses -ltermcap all: basic renumber diff --git a/src/cmd/basic/basic.c b/src/cmd/basic/basic.c index 4131760..6cd4dba 100644 --- a/src/cmd/basic/basic.c +++ b/src/cmd/basic/basic.c @@ -7,91 +7,81 @@ * quite instructive, as a simple but fairly complete interpreter. * * Variables: - * 260 Numeric variables : A0-A9 ... Z0-Z9 - * 260 Character variables : A0$-A9$ ... Z0$-Z9$ - * 260 Numeric arrays : A0()-A9() ... Z0()-Z9() + * 260 Numeric variables : A0-A9 ... Z0-Z9 + * 260 Character variables : A0$-A9$ ... Z0$-Z9$ + * 260 Numeric arrays : A0()-A9() ... Z0()-Z9() * - * For convenience the '0' variables can be referenced by letter - * only. IE: A is equivalent to A0 ... Z$ is equivalent to Z0$ + * For convenience the '0' variables can be referenced by letter + * only. IE: A is equivalent to A0 ... Z$ is equivalent to Z0$ * * Statements: - * BEEP freq,ms - Generate a BEEP on the PC speaker - * CLEAR - Erase variables only - * CLOSE#n - Close file (0-9) opened with OPEN - * DATA - Enter "inline" data statements - * DELAY ms - Stops for the indicated time - * DIM var(size)[, ... ] - Dimension an array - * DOS "command" - Execute a DOS program - * END - Terminate program with no message - * EXIT - Terminate MICRO-BASIC - * FOR v=init TO limit [STEP increment] - Perform a counted loop - * GOSUB line - Call a subroutine - * GOTO line - Jump to line - * IF test THEN line - Conditional goto - * IF test THEN statement - Conditional statement (next statement only) - * INPUT var - Get value for variable - * INPUT "prompt",var - Get value of variable with prompt - * prompt must be a constant string, however you can use a char variable - * in prompt by concatinating it to such a string: INPUT ""+a$,b$ - * INPUT#n,var - Get value for variable from file (0-9) - * LET (default) - variable = expression - * LIF test THEN statements- LONG IF (all statements to end of line) - * LIST [start,[end]] - List program lines - * LIST#n ... - List program to file (0-9) - * LOAD "name" - Load program from disk file - * When LOAD is used within a program, execution continues with the - * first line of the newly loaded program. In this case, the user - * variables are NOT cleared. This provides a means of chaining - * to a new program, and passing information to it. - * Also note that LOAD must be the LAST statement on a line. - * NEW - Erase program and variables - * NEXT [v] - End counted loop - * OPEN#n,"name","opts" - Open file (0-9), opts are same as "fopen()" - * ORDER line - Position data read pointer - * OUT port,expr - Write to I/O port - * PRINT expr[,expr ...] - Print to console - * PRINT#n,... - Print to file (0-9) - * READ var[,var ...] - Read data from program statements - * You MUST issue an "ORDER" statement targeting a line - * containing a valid DATA statement before using READ - * RETURN - Return from subroutine - * REM - Comment... reminder of line is ignored - * RUN [line] - Run program - * SAVE ["name"] - Save program to disk file - * STOP - Terminate program & issue message - * SRND seed - Seeds random() + * BEEP freq,ms - Generate a BEEP on the PC speaker + * CLEAR - Erase variables only + * CLOSE#n - Close file (0-9) opened with OPEN + * DATA - Enter "inline" data statements + * DELAY ms - Stops for the indicated time + * DIM var(size)[, ... ] - Dimension an array + * DOS "comand" - Execute a DOS program + * END - Terminate program with no message + * EXIT - Terminate MICRO-BASIC + * FOR v=init TO limit [STEP increment] - Perform a counted loop + * GOSUB line - Call a subroutine + * GOTO line - Jump to line + * IF test THEN line - Conditional goto + * IF test THEN statement - Conditional statement (next statement only) + * INPUT var - Get value for variable + * INPUT "prompt",var - Get value of variable with prompt + * prompt must be a constant string, however you can use a char variable + * in prompt by concatinating it to such a string: INPUT ""+a$,b$ + * INPUT#n,var - Get value for variable from file (0-9) + * LET (default) - variable = expression + * LIF test THEN statements- LONG IF (all statements to end of line) + * LIST [start,[end]] - List program lines + * LIST#n ... - List program to file (0-9) + * LOAD "name" - Load program from disk file + * When LOAD is used within a program, execution continues with the + * first line of the newly loaded program. In this case, the user + * variables are NOT cleared. This provides a means of chaining + * to a new program, and passing information to it. + * Also note that LOAD must be the LAST statement on a line. + * NEW - Erase program and variables + * NEXT [v] - End counted loop + * OPEN#n,"name","opts" - Open file (0-9), opts are same as "fopen()" + * ORDER line - Position data read pointer + * OUT port,expr - Write to I/O port + * PRINT expr[,expr ...] - Print to console + * PRINT#n,... - Print to file (0-9) + * READ var[,var ...] - Read data from program statements + * You MUST issue an "ORDER" statement targeting a line + * containing a valid DATA statement before using READ + * RETURN - Return from subroutine + * REM - Comment... reminder of line is ignored + * RUN [line] - Run program + * SAVE ["name"] - Save program to disk file + * STOP - Terminate program & issue message * * Operators: - * + - Addition, string concatination - * - - Unary minus, subtraction - * *, /, %, - multiplication, division, modulus - * &, |, ^ - AND, OR, Exclusive OR - * =, <> - Assign/test equal, test NOTequal (num or string) - * <, <=, >, >= - LT, LE, GT, GE (numbers only) - * ! - Unary NOT - * The "test" operators (=, <>, <, <=, >, >=) can be used in any - * expression, and evaluate to 1 of the test is TRUE, and 0 if it - * is FALSE. The IF and LIF commands accept any non-zero value to - * indicate a TRUE condition. + * + - Addition, string concatination + * - - Unary minus, subtraction + * *, /, %, - multiplication, division, modulus + * &, |, ^ - AND, OR, Exclusive OR + * =, <> - Assign/test equal, test NOTequal (num or string) + * <, <=, >, >= - LT, LE, GT, GE (numbers only) + * ! - Unary NOT + * The "test" operators (=, <>, <, <=, >, >=) can be used in any + * expression, and evaluate to 1 of the test is TRUE, and 0 if it + * is FALSE. The IF and LIF commands accept any non-zero value to + * indicate a TRUE condition. * * Functions: - * CHR$(value) - Returns character of passed value - * STR$(value) - Returns ASCII string of value's digits - * ASC(char) - Returns value of passed character - * NUM(string) - Convert string to number - * ABS(value) - Returns absolute value of argument - * RND(value) - Returns random number from 0 to (value-1) - * KEY() - Test for key from keyboard - * INP(port) - Read an I/O port - * SIN(value*10^6) - 10^6*SIN(x) - * COS(value*10^6) - 10^6*COS(x) - * TAN(value*10^6) - 10^6*TAN(x) - * ASIN(value*10^6) - 10^6*SIN(x) - * ACOS(value*10^6) - 10^6*COS(x) - * ATAN(value*10^6) - 10^6*TAN(x) - * LOG(value*10^6) - 10^6*LOG(x) - * LOG10(value*10^6) - 10^6*LOG10(x) - * EXP(value*10^6) - 10^6*EXP(x) + * CHR$(value) - Returns character of passed value + * STR$(value) - Returns ASCII string of value's digits + * ASC(char) - Returns value of passed character + * NUM(string) - Convert string to number + * ABS(value) - Returns absolute value of argument + * RND(value) - Returns random number from 0 to (value-1) + * KEY() - Test for key from keyboard + * INP(port) - Read an I/O port * * Copyright 1982-2000 Dave Dunfield * All rights reserved. @@ -116,104 +106,90 @@ #include #include #include -#include /* Fixed parameters */ -#define BUFFER_SIZE 100 /* input buffer size */ -#define NUM_VAR 260 /* number of variables */ -#define SA_SIZE 200 /* string accumulator size */ +#define BUFFER_SIZE 100 /* input buffer size */ +#define NUM_VAR 260 /* number of variables */ +#define SA_SIZE 100 /* string accumulator size */ /* Control stack constant identifiers */ -#define _FOR 1000 /* indicate FOR statement */ -#define _GOSUB _FOR+1 /* indicate GOSUB statement */ +#define _FOR 1000 /* indicate FOR statement */ +#define _GOSUB _FOR+1 /* indicate GOSUB statement */ /* Primary keywords */ -#define LET 1 -#define EXIT 2 -#define LIST 3 -#define NEW 4 -#define RUN 5 -#define CLEAR 6 -#define GOSUB 7 -#define GOTO 8 -#define RETURN 9 -#define PRINT 10 -#define FOR 11 -#define NEXT 12 -#define IF 13 -#define LIF 14 -#define REM 15 -#define STOP 16 -#define END 17 -#define INPUT 18 -#define OPEN 19 -#define CLOSE 20 -#define DIM 21 -#define ORDER 22 -#define READ 23 -#define DATA 24 -#define SAVE 25 -#define LOAD 26 -#define DELAY 27 -#define BEEP 28 -#define DOS 29 -#define OUT 30 +#define LET 1 +#define EXIT 2 +#define LIST 3 +#define NEW 4 +#define RUN 5 +#define CLEAR 6 +#define GOSUB 7 +#define GOTO 8 +#define RETURN 9 +#define PRINT 10 +#define FOR 11 +#define NEXT 12 +#define IF 13 +#define LIF 14 +#define REM 15 +#define STOP 16 +#define END 17 +#define INPUT 18 +#define OPEN 19 +#define CLOSE 20 +#define DIM 21 +#define ORDER 22 +#define READ 23 +#define DATA 24 +#define SAVE 25 +#define LOAD 26 +#define DELAY 27 +#define BEEP 28 +#define DOS 29 +#define OUT 30 /* Secondary keywords */ -#define TO 31 /* Also used as marker */ -#define STEP 32 -#define THEN 33 +#define TO 31 /* Also used as marker */ +#define STEP 32 +#define THEN 33 /* Operators and functions */ -#define ADD 34 /* Also used as marker */ -#define SUB 35 -#define MUL 36 -#define DIV 37 -#define MOD 38 -#define AND 39 -#define OR 40 -#define XOR 41 -#define EQ 42 -#define NE 43 -#define LE 44 -#define LT 45 -#define GE 46 -#define GT 47 -#define CHR 48 -#define STR 49 -#define ASC 50 -#define ABS 51 -#define NUM 52 -#define RND 53 -#define KEY 54 -#define INP 55 -#define DATE 56 -#define SRND 57 -#define SIN 58 -#define COS 59 -#define TAN 60 -#define ASIN 61 -#define ACOS 62 -#define ATAN 63 -#define LOG 64 -#define LOG10 65 -#define EXP 66 +#define ADD 34 /* Also used as marker */ +#define SUB 35 +#define MUL 36 +#define DIV 37 +#define MOD 38 +#define AND 39 +#define OR 40 +#define XOR 41 +#define EQ 42 +#define NE 43 +#define LE 44 +#define LT 45 +#define GE 46 +#define GT 47 +#define CHR 48 +#define STR 49 +#define ASC 50 +#define ABS 51 +#define NUM 52 +#define RND 53 +#define KEY 54 +#define INP 55 -#define RUN1 99 +#define RUN1 99 /* Make sure this token table matches the above definitions */ static char *reserved_words[] = { - "LET", "EXIT", "LIST", "NEW", "RUN", "CLEAR", "GOSUB", "GOTO", - "RETURN", "PRINT", "FOR", "NEXT", "IF", "LIF", "REM", "STOP", - "END", "INPUT", "OPEN", "CLOSE", "DIM", "ORDER", "READ", "DATA", - "SAVE", "LOAD", "DELAY", "BEEP", "DOS", "OUT", - "TO", "STEP", "THEN", - "+", "-", "*", "/", "%", "&", "|", "^", - "=", "<>", "<=", "<", ">=", ">", - "CHR$(", "STR$(", "ASC(", "ABS(", "NUM(", "RND(", "KEY(", "INP(", - "DATE$(", "SRND", "SIN(", "COS(", "TAN(", "ASIN(", "ACOS(", "ATAN(", - "LOG(", "LOG10(", "EXP(", - 0 + "LET", "EXIT", "LIST", "NEW", "RUN", "CLEAR", "GOSUB", "GOTO", + "RETURN", "PRINT", "FOR", "NEXT", "IF", "LIF", "REM", "STOP", + "END", "INPUT", "OPEN", "CLOSE", "DIM", "ORDER", "READ", "DATA", + "SAVE", "LOAD", "DELAY", "BEEP", "DOS", "OUT", + "TO", "STEP", "THEN", + "+", "-", "*", "/", "%", "&", "|", "^", + "=", "<>", "<=", "<", ">=", ">", + "CHR$(", "STR$(", "ASC(", "ABS(", "NUM(", "RND(", "KEY(", "INP(", + 0 }; /* Table of operator priorities */ @@ -221,59 +197,59 @@ static char priority[] = { 0, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1, 1, 1, 1 }; /* Table of error messages */ static char *error_messages[] = { - "Syntax", - "Illegal program", - "Illegal direct", - "Line number", - "Wrong type", - "Divide by zero", - "Nesting", - "File not open", - "File already open", - "Input", - "Dimension", - "Data", - "Out of memory" - }; + "Syntax", + "Illegal program", + "Illegal direct", + "Line number", + "Wrong type", + "Divide by zero", + "Nesting", + "File not open", + "File already open", + "Input", + "Dimension", + "Data", + "Out of memory" + }; struct line_record { - unsigned Lnumber; - struct line_record *Llink; - char Ltext[1]; + unsigned Lnumber; + struct line_record *Llink; + char Ltext[1]; }; -char sa1[SA_SIZE], sa2[SA_SIZE]; /* String accumulators */ -struct line_record *pgm_start, /* Indicates start of program */ - *runptr, /* Line we are RUNnning */ - *readptr; /* Line we are READing */ +char sa1[SA_SIZE], sa2[SA_SIZE]; /* String accumulators */ +struct line_record *pgm_start, /* Indicates start of program */ + *runptr, /* Line we are RUNnning */ + *readptr; /* Line we are READing */ -unsigned dim_check[NUM_VAR]; /* Check dim sizes for arrays */ +unsigned dim_check[NUM_VAR]; /* Check dim sizes for arrays */ -FILE *filein, *fileout; /* File I/O active pointers */ +FILE *filein, *fileout; /* File I/O active pointers */ -jmp_buf savjmp; /* Save area for set/longjmp */ +jmp_buf savjmp; /* Save area for set/longjmp */ /* Misc. global variables */ -char *cmdptr, /* Command line parse pointer */ - *dataptr, /* Read data pointer */ - buffer[BUFFER_SIZE]; /* General input buffer */ -unsigned mode = 0, /* 0=Stopped, !0=Running */ - expr_type, /* Type of last expression */ - nest; /* Nest level of expr. parser */ -unsigned line, /* Current line number */ - ctl_ptr = 0, /* Control stack pointer */ - ctl_stk[50]; /* Control stack */ +char *cmdptr, /* Command line parse pointer */ + *dataptr, /* Read data pointer */ + buffer[BUFFER_SIZE]; /* General input buffer */ +unsigned mode = 0, /* 0=Stopped, !0=Running */ + expr_type, /* Type of last expression */ + nest; /* Nest level of expr. parser */ +unsigned line, /* Current line number */ + ctl_ptr = 0, /* Control stack pointer */ + ctl_stk[50]; /* Control stack */ /* * The following variables must be iniitialized to zero. If your * compiler does not automatically zero uninitialized global * variables, modify these declarations to initialize them. */ -char filename[65]; /* Name of program file */ -FILE *files[10]; /* File unit numbers */ -int num_vars[NUM_VAR]; /* Numeric variables */ -int *dim_vars[NUM_VAR]; /* Dimensioned arrays */ -char *char_vars[NUM_VAR]; /* Character variables */ +char filename[65]; /* Name of program file */ +FILE *files[10]; /* File unit numbers */ +int num_vars[NUM_VAR]; /* Numeric variables */ +int *dim_vars[NUM_VAR]; /* Dimensioned arrays */ +char *char_vars[NUM_VAR]; /* Character variables */ int eval_sub(void); @@ -281,135 +257,91 @@ WINDOW *win; void beep (int i, int t) { - printf("BEEP not implemented yet, at line %u\n", line); + printf("BEEP not implemented yet, at line %u\n", line); } void delay (int msec) { - usleep (msec * 1000); + usleep (msec * 1000); } + int sigint(int sn) { - nocbreak(); - echo(); - endwin(); - exit(0); + nocbreak(); + echo(); + endwin(); + exit(0); } unsigned kbtst () { - unsigned int chr; + unsigned int chr; - signal(SIGINT,(sig_t)sigint); - win = initscr(); - cbreak(); - noecho(); - chr = getch(); - nocbreak(); - echo(); - endwin(); - signal(SIGINT,SIG_DFL); - return chr; + signal(SIGINT,(sig_t)sigint); + win = initscr(); + cbreak(); + noecho(); + chr = getch(); + nocbreak(); + echo(); + endwin(); + signal(SIGINT,SIG_DFL); + return chr; } void out (int addr, int value) { - /* 2BSD system call extension. */ - ustore (addr, value); + /* 2BSD system call extension. */ + ustore (addr, value); } unsigned in (int addr) { - /* 2BSD system call extension. */ - return ufetch (addr); -} - -int _sin (int value) -{ - return (int)(1.0e6 * sin(value * 1.0e-6)); -} - -int _cos (int value) -{ - return (int)(1.0e6 * cos(value * 1.0e-6)); -} - -int _tan (int value) -{ - return (int)(1.0e6 * tan(value * 1.0e-6)); -} - -int _asin (int value) -{ - return (int)(1.0e6 * asin(value * 1.0e-6)); -} - -int _acos (int value) -{ - return (int)(1.0e6 * acos(value * 1.0e-6)); -} - -int _atan (int value) -{ - return (int)(1.0e6 * atan(value * 1.0e-6)); -} - -int _log (int value) -{ - return (int)(1.0e6 * log(value * 1.0e-6)); -} - -int _log10 (int value) -{ - return (int)(1.0e6 * log10(value * 1.0e-6)); -} - -int _exp (int value) -{ - return (int)(1.0e6 * exp(value * 1.0e-6)); + /* 2BSD system call extension. */ + return ufetch (addr); } int isalnum(int c) { - c = (unsigned char) c; - if (c >= 'a' && c <= 'z') - return 1; - if (c >= '0' && c <= '9') - return 1; - if (c >= 'A' && c <= 'Z') - return 1; - return 0; + c = (unsigned char) c; + if (c >= 'a' && c <= 'z') + return 1; + if (c >= '0' && c <= '9') + return 1; + if (c >= 'A' && c <= 'Z') + return 1; + return 0; } int isalpha(int c) { - c = (unsigned char) c; - if (c >= 'a' && c <= 'z') - return 1; - if (c >= 'A' && c <= 'Z') - return 1; - return 0; + c = (unsigned char) c; + if (c >= 'a' && c <= 'z') + return 1; + if (c >= 'A' && c <= 'Z') + return 1; + return 0; } int isdigit(int c) { - c = (unsigned char) c; - return c >= '0' && c <= '9'; + c = (unsigned char) c; + return c >= '0' && c <= '9'; } int toupper(int c) { - c = (unsigned char) c; - if (c >= 'a' && c <= 'z') - c += 'A' - 'a'; - return c; + c = (unsigned char) c; + if (c >= 'a' && c <= 'z') + c += 'A' - 'a'; + return c; } void concat (char *ab, char *a, char *b) { - strcpy (ab, a); - strcat (ab, b); + strcpy (ab, a); + strcat (ab, b); } /* @@ -417,9 +349,9 @@ void concat (char *ab, char *a, char *b) */ int is_e_end(char c) { - if ((c >= (-128+TO)) && (c < (-128+ADD))) - return(1); - return (c == '\0') || (c == ':') || (c == ')') || (c == ','); + if((c >= (-128+TO)) && (c < (-128+ADD))) + return(1); + return (c == '\0') || (c == ':') || (c == ')') || (c == ','); } /* @@ -427,7 +359,7 @@ int is_e_end(char c) */ int is_l_end(char c) { - return (c == '\0') || (c == ':'); + return (c == '\0') || (c == ':'); } /* @@ -435,7 +367,7 @@ int is_l_end(char c) */ int isterm(char c) { - return (c == ' ') || (c == '\t'); + return (c == ' ') || (c == '\t'); } /* @@ -443,9 +375,9 @@ int isterm(char c) */ char skip_blank() { - while (isterm(*cmdptr)) - ++cmdptr; - return *cmdptr; + while(isterm(*cmdptr)) + ++cmdptr; + return *cmdptr; } /* @@ -453,13 +385,13 @@ char skip_blank() */ char get_next() { - char c; + char c; - while (isterm(c = *cmdptr)) - ++cmdptr; - if (c) - ++cmdptr; - return c; + while(isterm(c = *cmdptr)) + ++cmdptr; + if(c) + ++cmdptr; + return c; } /* @@ -467,11 +399,11 @@ char get_next() */ int test_next(int token) { - if (skip_blank() == token) { - ++cmdptr; - return -1; - } - return 0; + if(skip_blank() == token) { + ++cmdptr; + return -1; + } + return 0; } /* @@ -479,11 +411,11 @@ int test_next(int token) */ void error(unsigned en) { - printf("%s error", error_messages[en]); - if (mode) - printf(" in line %u", line); - putc('\n',stdout); - longjmp(savjmp, 1); + printf("%s error", error_messages[en]); + if(mode) + printf(" in line %u", line); + putc('\n',stdout); + longjmp(savjmp, 1); } /* @@ -491,8 +423,8 @@ void error(unsigned en) */ void expect(int token) { - if (get_next() != token) - error(0); + if(get_next() != token) + error(0); } /* @@ -500,24 +432,24 @@ void expect(int token) */ unsigned lookup(char *table[]) { - unsigned i; - char *cptr, *optr; + unsigned i; + char *cptr, *optr; - optr = cmdptr; - for (i=0; (cptr = table[i]); ++i) { - while ((*cptr) && (*cptr == toupper(*cmdptr))) { - ++cptr; - ++cmdptr; - } - if (! *cptr) { - if (! (isalnum(*(cptr-1)) && isalnum(*cmdptr)) ) { - skip_blank(); - return i+1; - } - } - cmdptr = optr; - } - return 0; + optr = cmdptr; + for(i=0; (cptr = table[i]); ++i) { + while((*cptr) && (*cptr == toupper(*cmdptr))) { + ++cptr; + ++cmdptr; + } + if(! *cptr) { + if(! (isalnum(*(cptr-1)) && isalnum(*cmdptr)) ) { + skip_blank(); + return i+1; + } + } + cmdptr = optr; + } + return 0; } /* @@ -525,15 +457,15 @@ unsigned lookup(char *table[]) */ unsigned get_num() { - unsigned value; - char c; + unsigned value; + char c; - value = 0; - while (isdigit(c = *cmdptr)) { - ++cmdptr; - value = (value * 10) + (c - '0'); - } - return value; + value = 0; + while(isdigit(c = *cmdptr)) { + ++cmdptr; + value = (value * 10) + (c - '0'); + } + return value; } /* @@ -541,13 +473,13 @@ unsigned get_num() */ char *allocate(unsigned size) { - char *ptr; + char *ptr; - ptr = malloc(size); - if (! ptr) - error(12); - memset(ptr, 0, size); - return ptr; + ptr = malloc(size); + if(! ptr) + error(12); + memset(ptr, 0, size); + return ptr; } /* @@ -555,23 +487,23 @@ char *allocate(unsigned size) */ void delete_line(unsigned lino) { - struct line_record *cptr, *bptr = 0; + struct line_record *cptr, *bptr = 0; - if (! pgm_start) /* no lines in pgm */ - return; - cptr = pgm_start; - do { - if (lino == cptr->Lnumber) { /* we have line to delete */ - if (cptr == pgm_start) { /* first line in pgm */ - pgm_start = cptr->Llink; - return; - } - if (bptr) /* skip it in linked list */ - bptr->Llink = cptr->Llink; - free(cptr); /* let it go */ - } - bptr = cptr; - } while ((cptr = cptr->Llink)); + if(! pgm_start) /* no lines in pgm */ + return; + cptr = pgm_start; + do { + if(lino == cptr->Lnumber) { /* we have line to delete */ + if(cptr == pgm_start) { /* first line in pgm */ + pgm_start = cptr->Llink; + return; + } + if (bptr) /* skip it in linked list */ + bptr->Llink = cptr->Llink; + free(cptr); /* let it go */ + } + bptr = cptr; + } while((cptr = cptr->Llink)); } /* @@ -579,29 +511,29 @@ void delete_line(unsigned lino) */ void insert_line(unsigned lino) { - struct line_record *cptr, *bptr, *optr; + struct line_record *cptr, *bptr, *optr; - bptr = (struct line_record*) - allocate(sizeof (struct line_record) + strlen (cmdptr)); - bptr->Lnumber = lino; - strcpy (bptr->Ltext, cmdptr); - if (! pgm_start || lino < pgm_start->Lnumber) { - /* at start */ - bptr->Llink = pgm_start; - pgm_start = bptr; - return; - } - /* inserting into main part of pgm */ - cptr = pgm_start; - for (;;) { - optr = cptr; - cptr = cptr->Llink; - if (! cptr || lino < cptr->Lnumber) { - bptr->Llink = optr->Llink; - optr->Llink = bptr; - break; - } - } + bptr = (struct line_record*) + allocate(sizeof (struct line_record) + strlen (cmdptr)); + bptr->Lnumber = lino; + strcpy (bptr->Ltext, cmdptr); + if(! pgm_start || lino < pgm_start->Lnumber) { + /* at start */ + bptr->Llink = pgm_start; + pgm_start = bptr; + return; + } + /* inserting into main part of pgm */ + cptr = pgm_start; + for(;;) { + optr = cptr; + cptr = cptr->Llink; + if(! cptr || lino < cptr->Lnumber) { + bptr->Llink = optr->Llink; + optr->Llink = bptr; + break; + } + } } /* @@ -609,42 +541,42 @@ void insert_line(unsigned lino) */ int edit_program() { - unsigned value; - char *ptr, c; + unsigned value; + char *ptr, c; - cmdptr = ptr = buffer; - /* Translate special tokens into codes */ - while ((c = *cmdptr)) { - if (c == '\n' || c == '\r') { - ++cmdptr; - continue; - } - value = lookup(reserved_words); - if (value) - *ptr++ = value | 0x80; - else { - *ptr++ = c; - ++cmdptr; - if (c == '"') { /* double quote */ - while ((c = *cmdptr) && (c != '"')) { - ++cmdptr; - *ptr++ = c; - } - *ptr++ = *cmdptr++; - } - } - } - *ptr = 0; - cmdptr = buffer; + cmdptr = ptr = buffer; + /* Translate special tokens into codes */ + while((c = *cmdptr)) { + if (c == '\n' || c == '\r') { + ++cmdptr; + continue; + } + value = lookup(reserved_words); + if(value) + *ptr++ = value | 0x80; + else { + *ptr++ = c; + ++cmdptr; + if(c == '"') { /* double quote */ + while((c = *cmdptr) && (c != '"')) { + ++cmdptr; + *ptr++ = c; + } + *ptr++ = *cmdptr++; + } + } + } + *ptr = 0; + cmdptr = buffer; - if (isdigit(skip_blank())) { /* Valid source line */ - value = get_num(); /* Get line number */ - delete_line(value); /* Delete the old */ - if (skip_blank()) - insert_line(value); - return -1; /* Insert the new */ - } - return 0; + if(isdigit(skip_blank())) { /* Valid source line */ + value = get_num(); /* Get line number */ + delete_line(value); /* Delete the old */ + if(skip_blank()) + insert_line(value); + return -1; /* Insert the new */ + } + return 0; } /* @@ -652,13 +584,13 @@ int edit_program() */ struct line_record *find_line(unsigned line) { - struct line_record *cptr; + struct line_record *cptr; - for (cptr = pgm_start; cptr; cptr = cptr->Llink) - if (cptr->Lnumber == line) - return cptr; - error(3); - return 0; + for(cptr = pgm_start; cptr; cptr = cptr->Llink) + if(cptr->Lnumber == line) + return cptr; + error(3); + return 0; } /* @@ -666,23 +598,23 @@ struct line_record *find_line(unsigned line) */ int get_var() { - unsigned index; - char c; + unsigned index; + char c; - if (! isalpha(c = get_next())) - error(0); - index = ((c - 'A') & 0x1F) * 10; - if (isdigit(c = *cmdptr)) { - index += (c - '0'); - c = *++cmdptr; - } - if (c == '$') { - ++cmdptr; - expr_type = 1; - } else - expr_type = 0; + if(! isalpha(c = get_next())) + error(0); + index = ((c - 'A') & 0x1F) * 10; + if(isdigit(c = *cmdptr)) { + index += (c - '0'); + c = *++cmdptr; + } + if(c == '$') { + ++cmdptr; + expr_type = 1; + } else + expr_type = 0; - return index; + return index; } /* @@ -690,13 +622,12 @@ int get_var() */ int eval() { - unsigned value; + unsigned value; - nest = 0; - value = eval_sub(); - if (nest != 1) - error(0); - return value; + nest = 0; + value = eval_sub(); + if(nest != 1) error(0); + return value; } /* @@ -704,12 +635,12 @@ int eval() */ int eval_num() { - unsigned value; + unsigned value; - value = eval(); - if (expr_type) - error(4); - return value; + value = eval(); + if(expr_type) + error(4); + return value; } /* @@ -717,9 +648,9 @@ int eval_num() */ void eval_char() { - eval(); - if (! expr_type) - error(4); + eval(); + if(!expr_type) + error(4); } /* @@ -727,26 +658,26 @@ void eval_char() */ unsigned *address() { - unsigned i, j, *dptr; + unsigned i, j, *dptr; - i = get_var(); - if (expr_type) - return (unsigned*) &char_vars[i]; + i = get_var(); + if(expr_type) + return (unsigned*) &char_vars[i]; - if (! test_next('(')) - return (unsigned*) &num_vars[i]; + if(! test_next('(')) + return (unsigned*) &num_vars[i]; - /* Array */ - if (expr_type) - error(0); - dptr = (unsigned*) dim_vars[i]; - if (! dptr) - error(10); - nest = 0; - j = eval_sub(); - if (j >= dim_check[i]) - error(10); - return &dptr[j]; + /* Array */ + if(expr_type) + error(0); + dptr = (unsigned*) dim_vars[i]; + if(! dptr) + error(10); + nest = 0; + j = eval_sub(); + if(j >= dim_check[i]) + error(10); + return &dptr[j]; } /* @@ -754,21 +685,20 @@ unsigned *address() */ int chk_file(char flag) { - unsigned i; + unsigned i; - i = -1; - if (test_next('#')) { - if (9 < (i = eval_num())) - error(7); - test_next(','); - filein = fileout = files[i]; - if (flag && (!filein)) - error(7); - } else { - filein = stdin; - fileout = stdout; - } - return i; + i = -1; + if(test_next('#')) { + if(9 < (i = eval_num())) error(7); + test_next(','); + filein = fileout = files[i]; + if(flag && (!filein)) + error(7); + } else { + filein = stdin; + fileout = stdout; + } + return i; } /* @@ -776,25 +706,25 @@ int chk_file(char flag) */ void disp_pgm(FILE *fp, unsigned i, unsigned j) { - unsigned k; - struct line_record *cptr; - char c; + unsigned k; + struct line_record *cptr; + char c; - for (cptr = pgm_start; cptr; cptr = cptr->Llink) { - k = cptr->Lnumber; - if ((k >= i) && (k <= j)) { - fprintf(fp,"%u ",k); - for (k=0; (c = cptr->Ltext[k]); ++k) - if (c < 0) { - c = c & 127; - fputs(reserved_words[c - 1], fp); - if (c < ADD) - putc(' ',fp); - } else - putc(c,fp); - putc('\n', fp); - } - } + for(cptr = pgm_start; cptr; cptr = cptr->Llink) { + k = cptr->Lnumber; + if((k >= i) && (k <= j)) { + fprintf(fp,"%u ",k); + for(k=0; (c = cptr->Ltext[k]); ++k) + if(c < 0) { + c = c & 127; + fputs(reserved_words[c - 1], fp); + if(c < ADD) + putc(' ',fp); + } else + putc(c,fp); + putc('\n', fp); + } + } } /* @@ -802,22 +732,22 @@ void disp_pgm(FILE *fp, unsigned i, unsigned j) */ void clear_vars() { - unsigned i; - char *ptr; + unsigned i; + char *ptr; - for (i=0; i < NUM_VAR; ++i) { - num_vars[i] = 0; - ptr = char_vars[i]; /* Character variables */ - if (ptr) { - free(ptr); - char_vars[i] = 0; - } - ptr = (char*) dim_vars[i]; /* Dimensioned arrays */ - if (ptr) { - free(ptr); - dim_vars[i] = 0; - } - } + for(i=0; i < NUM_VAR; ++i) { + num_vars[i] = 0; + ptr = char_vars[i]; /* Character variables */ + if(ptr) { + free(ptr); + char_vars[i] = 0; + } + ptr = (char*) dim_vars[i]; /* Dimensioned arrays */ + if(ptr) { + free(ptr); + dim_vars[i] = 0; + } + } } /* @@ -825,9 +755,9 @@ void clear_vars() */ void clear_pgm() { - for (runptr = pgm_start; runptr; runptr = runptr->Llink) - free(runptr); - pgm_start = 0; + for(runptr = pgm_start; runptr; runptr = runptr->Llink) + free(runptr); + pgm_start = 0; } /* @@ -835,8 +765,8 @@ void clear_pgm() */ void pgm_only() { - if (! mode) - error(2); + if(! mode) + error(2); } /* @@ -844,8 +774,8 @@ void pgm_only() */ void direct_only() { - if (mode) - error(1); + if(mode) + error(1); } /* @@ -853,181 +783,17 @@ void direct_only() */ void skip_stmt() { - char c; + char c; - while ((c = *cmdptr) && (c != ':')) { - ++cmdptr; - if (c == '"') { - while ((c = *cmdptr) && (c != '"')) - ++cmdptr; - if (c) - ++cmdptr; - } - } -} - -const char *wday_s[] = { - "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", 0 -}; -const char *wday_l[] = { - "Sunday", "Monday", "Tuesday", "Wednesday", - "Thursday", "Friday", "Saturday", 0 -}; -const char *month_l[] = { - "January", "February", "March", "April", "May", "June", - "July", "August", "September", "October", "November", "December", - 0 -}; -const char *month_s[] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", - 0 -}; - -void date_string(char *format, char *ptr) -{ - char *f; - time_t t = time(NULL); - struct tm *tm = localtime(&t); - char *fmt = strdup(format); - - for (f=fmt; *f; f++) { - if (*f == '%') { - f++; - switch (*f) { - case 'd': // Day of the month, 2 digits, leading 0 - 01-31 - sprintf(ptr,"%02d",tm->tm_mday); - break; - case 'D': - sprintf(ptr,"%s",wday_s[tm->tm_wday]); - break; - case 'j': - sprintf(ptr,"%d",tm->tm_mday); - break; - case 'l': - sprintf(ptr,"%s",wday_l[tm->tm_wday]); - break; - case 'N': - sprintf(ptr,"%d",tm->tm_wday == 0 ? 7 : tm->tm_wday); - break; - case 'S': - switch (tm->tm_mday) { - case 1: - case 21: - case 31: - sprintf(ptr,"st"); - break; - case 2: - case 22: - sprintf(ptr,"nd"); - break; - case 3: - case 23: - sprintf(ptr,"rd"); - break; - default: - sprintf(ptr,"th"); - break; - } - break; - case 'w': - sprintf(ptr,"%d",tm->tm_wday); - break; - case 'z': - sprintf(ptr,"%d",tm->tm_yday); - break; - case 'F': - sprintf(ptr,"%s",month_l[tm->tm_mon]); - break; - case 'm': - sprintf(ptr,"%02d",tm->tm_mon+1); - break; - case 'M': - sprintf(ptr,"%s",month_s[tm->tm_mon]); - break; - case 'n': - sprintf(ptr,"%d",tm->tm_mon+1); - break; - case 't': - switch (tm->tm_mon) { - case 0: sprintf(ptr,"%d",31); break; // Jan - case 1: sprintf(ptr,"%d",((tm->tm_year+1900) % 4 == 0) ? 29 : 28); break; // Feb - case 2: sprintf(ptr,"%d",31); break; // Mar - case 3: sprintf(ptr,"%d",30); break; // Apr - case 4: sprintf(ptr,"%d",31); break; // May - case 5: sprintf(ptr,"%d",30); break; // Jun - case 6: sprintf(ptr,"%d",31); break; // Jul - case 7: sprintf(ptr,"%d",31); break; // Aug - case 8: sprintf(ptr,"%d",30); break; // Sep - case 9: sprintf(ptr,"%d",31); break; // Oct - case 10: sprintf(ptr,"%d",30); break; // Nov - case 11: sprintf(ptr,"%d",31); break; // Dec - } - break; - case 'L': - sprintf(ptr,"%d",((tm->tm_year+1900) % 4 == 0) ? 1 : 0); - break; - case 'o': - case 'Y': - sprintf(ptr,"%04d",tm->tm_year+1900); - break; - case 'y': - sprintf(ptr,"%02d",(tm->tm_year+1900) % 100); - break; - case 'a': - sprintf(ptr,"%s",(tm->tm_hour<12) ? "am" : "pm"); - break; - case 'A': - sprintf(ptr,"%s",(tm->tm_hour<12) ? "AM" : "PM"); - break; - case 'g': - sprintf(ptr,"%d",tm->tm_hour % 12); - break; - case 'G': - sprintf(ptr,"%d",tm->tm_hour); - break; - case 'h': - sprintf(ptr,"%02d",tm->tm_hour % 12); - break; - case 'H': - sprintf(ptr,"%02d",tm->tm_hour); - break; - case 'i': - sprintf(ptr,"%02d",tm->tm_min); - break; - case 's': - sprintf(ptr,"%02d",tm->tm_sec); - break; - case 'u': - sprintf(ptr,"000000"); - break; - case 'e': - sprintf(ptr,"%s",tm->tm_zone); - break; - case 'I': - sprintf(ptr,"%d",tm->tm_isdst); - break; - case 'O': - sprintf(ptr,"%02d%02d",(int)tm->tm_gmtoff/60,(int)tm->tm_gmtoff%60); - break; - case 'P': - sprintf(ptr,"%02d:%02d",(int)tm->tm_gmtoff/60,(int)tm->tm_gmtoff%60); - break; - case 'T': - sprintf(ptr,"%s",tm->tm_zone); - break; - default: - *ptr++ = *f; - *ptr = 0; - } - } else { - *ptr++ = *f; - *ptr = 0; - } - while (*ptr) - ptr++; - } - free(fmt); + while((c = *cmdptr) && (c != ':')) { + ++cmdptr; + if(c == '"') { + while((c = *cmdptr) && (c != '"')) + ++cmdptr; + if(c) + ++cmdptr; + } + } } /* @@ -1035,21 +801,21 @@ void date_string(char *format, char *ptr) */ void num_string(unsigned value, char *ptr) { - char cstack[12]; - int i; + char cstack[12]; + int i; - if (value > INT_MAX) { - *ptr++ = '-'; - value = -value; - } - i = 0; - do { - cstack[i++] = (value % 10) + '0'; - } while (value /= 10); + if(value > INT_MAX) { + *ptr++ = '-'; + value = -value; + } + i = 0; + do { + cstack[i++] = (value % 10) + '0'; + } while(value /= 10); - while (i) - *ptr++ = cstack[--i]; - *ptr = 0; + while(i) + *ptr++ = cstack[--i]; + *ptr = 0; } /* @@ -1057,367 +823,353 @@ void num_string(unsigned value, char *ptr) */ struct line_record *execute(char cmd) { - unsigned i, j, k, *dptr; - int ii, jj; - struct line_record *cptr; - char c; + unsigned i, j, k, *dptr; + int ii, jj; + struct line_record *cptr; + char c; - switch (cmd & 0x7F) { - case LET: - dptr = address(); - j = expr_type; + switch(cmd & 0x7F) { + case LET: + dptr = address(); + j = expr_type; - expect(-128+EQ); + expect(-128+EQ); - k = eval(); + k = eval(); - if (j != expr_type) - error(0); - if (! expr_type) /* numeric assignment */ - *dptr = k; - else { /* character assignment */ - if (*dptr) - free((void*) *dptr); - if (*sa1) { - *dptr = (unsigned) allocate(strlen(sa1)+1); - strcpy((char*) *dptr, sa1); - } else - *dptr = 0; - } - break; - case EXIT: - exit(0); - case LIST: - chk_file(1); - if (! isdigit(skip_blank())) { - i=0; j=-1; - } else { - i = get_num(); - if (get_next() == ',') { - if (isdigit(skip_blank())) - j=get_num(); - else - j = -1; - } else - j=i; - } - disp_pgm(fileout,i,j); - break; - case NEW: - clear_vars(); - clear_pgm(); - longjmp(savjmp, 1); - case RUN: - direct_only(); - clear_vars(); - case RUN1: /* No clearing */ - if (is_e_end(skip_blank())) - runptr = pgm_start; - else - runptr = find_line(eval_num()); - --mode; /* indicate running */ + if(j != expr_type) + error(0); + if(! expr_type) /* numeric assignment */ + *dptr = k; + else { /* character assignment */ + if(*dptr) + free((void*) *dptr); + if(*sa1) { + *dptr = (unsigned) allocate(strlen(sa1)+1); + strcpy((char*) *dptr, sa1); + } else + *dptr = 0; + } + break; + case EXIT: + exit(0); + case LIST: + chk_file(1); + if(!isdigit(skip_blank())) { + i=0; j=-1; + } else { + i = get_num(); + if(get_next() == ',') { + if(isdigit(skip_blank())) + j=get_num(); + else + j = -1; + } else + j=i; + } + disp_pgm(fileout,i,j); + break; + case NEW: + clear_vars(); + clear_pgm(); + longjmp(savjmp, 1); + case RUN: + direct_only(); + clear_vars(); + case RUN1: /* No clearing */ + if(is_e_end(skip_blank())) + runptr = pgm_start; + else + runptr = find_line(eval_num()); + --mode; /* indicate running */ newline: - while (runptr) { - cmdptr = runptr->Ltext; - line = runptr->Lnumber; - do { - if ((cmd = skip_blank()) < 0) { - ++cmdptr; - dptr = (unsigned*) execute(cmd); - if (dptr) { - runptr = (struct line_record*) dptr; - goto newline; - } - } else - execute(1); - } while ((c = get_next()) == ':'); - if (c) - error(0); - runptr = runptr->Llink; - } - mode = 0; - break; - case CLEAR: - clear_vars(); - break; - case GOSUB: - ctl_stk[ctl_ptr++] = (unsigned) runptr; - ctl_stk[ctl_ptr++] = (unsigned) cmdptr; - ctl_stk[ctl_ptr++] = _GOSUB; - case GOTO: - pgm_only(); - return find_line(eval_num()); - case RETURN: - pgm_only(); - if (ctl_stk[--ctl_ptr] != _GOSUB) - error(6); - cmdptr = (char*) ctl_stk[--ctl_ptr]; - runptr = (struct line_record*) ctl_stk[--ctl_ptr]; - line = runptr->Lnumber; - skip_stmt(); - break; - case PRINT: - chk_file(1); - j = 0; - do { - if (is_l_end(skip_blank())) - --j; - else { - i = eval(); - if (! expr_type) { - num_string(i, sa1); - putc(' ',fileout); - } - fputs(sa1, fileout); - } - } while (test_next(',')); - if (! j) - putc('\n', fileout); - break; - case FOR: - pgm_only(); - ii = 1; /* default step value */ - i = get_var(); - if (expr_type) - error(0); - expect(-128+EQ); - num_vars[i] = eval(); - if (expr_type) - error(0); - expect(-128+TO); - jj = eval(); - if (test_next(-128+STEP)) - ii = eval(); - skip_stmt(); - ctl_stk[ctl_ptr++] = (unsigned) runptr; /* line */ - ctl_stk[ctl_ptr++] = (unsigned) cmdptr; /* command pointer */ - ctl_stk[ctl_ptr++] = ii; /* step value */ - ctl_stk[ctl_ptr++] = jj; /* limit value */ - ctl_stk[ctl_ptr++] = i; /* variable number */ - ctl_stk[ctl_ptr++] = _FOR; - break; - case NEXT: - pgm_only(); - if (ctl_stk[ctl_ptr-1] != _FOR) - error(6); - i = ctl_stk[ctl_ptr-2]; - if (!is_l_end(skip_blank())) - if (get_var() != i) - error(6); - jj = ctl_stk[ctl_ptr-3]; /* get limit */ - ii = ctl_stk[ctl_ptr-4]; /* get step */ - num_vars[i] += ii; - if ((ii < 0) ? num_vars[i] >= jj : num_vars[i] <= jj) { - cmdptr = (char*) ctl_stk[ctl_ptr-5]; - runptr = (struct line_record*) ctl_stk[ctl_ptr-6]; - line = runptr->Lnumber; - } else - ctl_ptr -= 6; - break; - case IF: - i = eval_num(); - expect(-128+THEN); - if (i) { - if (isdigit(cmd = skip_blank())) - return find_line(eval_num()); - else if (cmd < 0) { - ++cmdptr; - return execute(cmd); - } else - execute(1); - } else - skip_stmt(); - break; - case LIF: - i = eval_num(); - expect(-128+THEN); - if (i) { - if ((cmd = skip_blank()) < 0) { - ++cmdptr; - return execute(cmd); - } else - execute(1); - break; - } - case DATA: - pgm_only(); - case REM: - if (mode) { - if ((cptr = runptr->Llink)) - return cptr; - longjmp(savjmp, 1); - } - break; - case STOP: - pgm_only(); - printf("STOP in line %u\n",line); - case END: - pgm_only(); - longjmp(savjmp, 1); - case INPUT: - ii = chk_file(1); - if (skip_blank() == '"') { /* special prompt */ - eval(); - expect(','); - } else - strcpy(sa1, "? "); - dptr = address(); - cptr = (struct line_record*) cmdptr; -input: if (ii == -1) - fputs(sa1, stdout); - if (! fgets(buffer, sizeof(buffer)-1, filein)) - exit (0); - /* Remove trailing eols. */ - cmdptr = buffer + strlen(buffer); - while (cmdptr > buffer && - (cmdptr[-1] == '\n' || cmdptr[-1] == '\r')) - *--cmdptr = 0; - cmdptr = buffer; - if (expr_type) { - if (*dptr) - free((void*) *dptr); - *dptr = (unsigned) allocate(strlen(buffer)+1); - strcpy((char*) *dptr, buffer); - } else { - k = 0; - if (test_next('-')) - --k; - if (! isdigit(*cmdptr)) { - if (ii != -1) - error(9); - fputs("Input error\n", stdout); - goto input; - } - j = get_num(); - *dptr = (k) ? 0-j: j; - } - cmdptr = (char*) cptr; - break; - case OPEN: - if (skip_blank() != '#') - error(0); - if (files[i = chk_file(0)]) - error(8); - eval_char(); - strcpy(buffer, sa1); - expect(','); - eval_char(); - files[i] = fopen(buffer,sa1); - break; - case CLOSE: - if ((i = chk_file(1)) == -1) - error(0); - if (! filein) - error(8); - fclose(files[i]); - files[i] = 0; - break; - case DIM: - do { - i = get_var(); - dptr = (unsigned*) dim_vars[i]; - if (dptr) - free(dptr); - dim_check[i] = eval_num() + 1; - dim_vars[i] = (int*) allocate(dim_check[i] * sizeof(int)); - } while (test_next(',')); - break; - case ORDER: - readptr = find_line(eval_num()); - dptr = (unsigned*) cmdptr; - cmdptr = readptr->Ltext; - if (get_next() != -128+DATA) - error(11); - dataptr = cmdptr; - cmdptr = (char*) dptr; - break; - case READ: - do { - dptr = address(); - j = expr_type; - cptr = (struct line_record*) cmdptr; - cmdptr = dataptr; - ii = line; - if (! skip_blank()) { /* End of line */ - readptr = readptr->Llink; - cmdptr = readptr->Ltext; - if (get_next() != -128+DATA) - error(11); - } - line = readptr->Lnumber; - k = eval(); - test_next(','); - dataptr = cmdptr; - cmdptr = (char*) cptr; - line = ii; - if (j != expr_type) - error(11); - if (! expr_type) /* numeric assignment */ - *dptr = k; - else { /* character assignment */ - if (*dptr) - free((void*) *dptr); - if (*sa1) { - *dptr = (unsigned) allocate(strlen(sa1)+1); - strcpy((char*) *dptr, sa1); - } else - *dptr = 0; - } - } while (test_next(',')); - break; - case DELAY: - delay(eval_num()); - break; - case SRND: - srandom(eval_num()); - break; - case BEEP: - i = eval_num(); - expect(','); - beep(i, eval_num()); - break; - case DOS: - eval_char(); - fflush(stdout); - system(sa1); - break; - case OUT: - i = eval_num(); - expect(','); - out(i, eval_num()); - break; - case SAVE: - direct_only(); - if (skip_blank()) { - eval_char(); - concat(filename, sa1, ""); - } - fileout = fopen(filename, "wv"); - if (fileout) { - disp_pgm(fileout, 0, -1); - fclose(fileout); - } else - perror (filename); - break; - case LOAD: - eval_char(); - concat(filename, sa1, ""); - filein = fopen(filename, "rv"); - if (filein) { - if (! mode) - clear_vars(); - clear_pgm(); - while (fgets(buffer, sizeof(buffer)-1, filein)) - edit_program(); - fclose(filein); - return pgm_start; - } else - perror (filename); - longjmp(savjmp, 1); - default: /* unknown */ - error(0); - } - return 0; + while(runptr) { + cmdptr = runptr->Ltext; + line = runptr->Lnumber; + do { + if((cmd = skip_blank()) < 0) { + ++cmdptr; + dptr = (unsigned*) execute(cmd); + if(dptr) { + runptr = (struct line_record*) dptr; + goto newline; + } + } else + execute(1); + } while((c = get_next()) == ':'); + if(c) + error(0); + runptr = runptr->Llink; + } + mode = 0; + break; + case CLEAR: + clear_vars(); + break; + case GOSUB: + ctl_stk[ctl_ptr++] = (unsigned) runptr; + ctl_stk[ctl_ptr++] = (unsigned) cmdptr; + ctl_stk[ctl_ptr++] = _GOSUB; + case GOTO: + pgm_only(); + return find_line(eval_num()); + case RETURN: + pgm_only(); + if(ctl_stk[--ctl_ptr] != _GOSUB) + error(6); + cmdptr = (char*) ctl_stk[--ctl_ptr]; + runptr = (struct line_record*) ctl_stk[--ctl_ptr]; + line = runptr->Lnumber; + skip_stmt(); + break; + case PRINT: + chk_file(1); + j = 0; + do { + if(is_l_end(skip_blank())) + --j; + else { + i = eval(); + if(! expr_type) { + num_string(i, sa1); + putc(' ',fileout); + } + fputs(sa1, fileout); + } + } while(test_next(',')); + if(!j) + putc('\n', fileout); + break; + case FOR: + pgm_only(); + ii = 1; /* default step value */ + i = get_var(); + if(expr_type) error(0); + expect(-128+EQ); + num_vars[i] = eval(); + if(expr_type) error(0); + expect(-128+TO); + jj = eval(); + if(test_next(-128+STEP)) + ii = eval(); + skip_stmt(); + ctl_stk[ctl_ptr++] = (unsigned) runptr; /* line */ + ctl_stk[ctl_ptr++] = (unsigned) cmdptr; /* command pointer */ + ctl_stk[ctl_ptr++] = ii; /* step value */ + ctl_stk[ctl_ptr++] = jj; /* limit value */ + ctl_stk[ctl_ptr++] = i; /* variable number */ + ctl_stk[ctl_ptr++] = _FOR; + break; + case NEXT: + pgm_only(); + if(ctl_stk[ctl_ptr-1] != _FOR) + error(6); + i = ctl_stk[ctl_ptr-2]; + if(!is_l_end(skip_blank())) + if(get_var() != i) error(6); + jj = ctl_stk[ctl_ptr-3]; /* get limit */ + ii = ctl_stk[ctl_ptr-4]; /* get step */ + num_vars[i] += ii; + if((ii < 0) ? num_vars[i] >= jj : num_vars[i] <= jj) { + cmdptr = (char*) ctl_stk[ctl_ptr-5]; + runptr = (struct line_record*) ctl_stk[ctl_ptr-6]; + line = runptr->Lnumber; + } else + ctl_ptr -= 6; + break; + case IF: + i = eval_num(); + expect(-128+THEN); + if(i) { + if(isdigit(cmd = skip_blank())) + return find_line(eval_num()); + else if(cmd < 0) { + ++cmdptr; + return execute(cmd); + } else + execute(1); + } else + skip_stmt(); + break; + case LIF: + i = eval_num(); + expect(-128+THEN); + if(i) { + if((cmd = skip_blank()) < 0) { + ++cmdptr; + return execute(cmd); + } else + execute(1); + break; + } + case DATA: + pgm_only(); + case REM: + if(mode) { + if((cptr = runptr->Llink)) + return cptr; + longjmp(savjmp, 1); + } + break; + case STOP: + pgm_only(); + printf("STOP in line %u\n",line); + case END: + pgm_only(); + longjmp(savjmp, 1); + case INPUT: + ii = chk_file(1); + if(skip_blank() == '"') { /* special prompt */ + eval(); + expect(','); + } else + strcpy(sa1, "? "); + dptr = address(); + cptr = (struct line_record*) cmdptr; +input: if(ii == -1) + fputs(sa1, stdout); + if (! fgets(buffer, sizeof(buffer)-1, filein)) + exit (0); + /* Remove trailing eols. */ + cmdptr = buffer + strlen(buffer); + while (cmdptr > buffer && + (cmdptr[-1] == '\n' || cmdptr[-1] == '\r')) + *--cmdptr = 0; + cmdptr = buffer; + if(expr_type) { + if(*dptr) free((void*) *dptr); + *dptr = (unsigned) allocate(strlen(buffer)+1); + strcpy((char*) *dptr, buffer); + } else { + k = 0; + if(test_next('-')) + --k; + if(!isdigit(*cmdptr)) { + if(ii != -1) error(9); + fputs("Input error\n",stdout); + goto input; + } + j = get_num(); + *dptr = (k) ? 0-j: j; + } + cmdptr = (char*) cptr; + break; + case OPEN: + if(skip_blank() != '#') error(0); + if(files[i = chk_file(0)]) error(8); + eval_char(); + strcpy(buffer, sa1); + expect(','); + eval_char(); + files[i] = fopen(buffer,sa1); + break; + case CLOSE: + if((i = chk_file(1)) == -1) error(0); + if(!filein) error(8); + fclose(files[i]); + files[i] = 0; + break; + case DIM: + do { + i = get_var(); + dptr = (unsigned*) dim_vars[i]; + if(dptr) + free(dptr); + dim_check[i] = eval_num() + 1; + dim_vars[i] = (int*) allocate(dim_check[i] * sizeof(int)); + } while(test_next(',')); + break; + case ORDER: + readptr = find_line(eval_num()); + dptr = (unsigned*) cmdptr; + cmdptr = readptr->Ltext; + if(get_next() != -128+DATA) + error(11); + dataptr = cmdptr; + cmdptr = (char*) dptr; + break; + case READ: + do { + dptr = address(); + j = expr_type; + cptr = (struct line_record*) cmdptr; + cmdptr = dataptr; + ii = line; + if(!skip_blank()) { /* End of line */ + readptr = readptr->Llink; + cmdptr = readptr->Ltext; + if(get_next() != -128+DATA) + error(11); + } + line = readptr->Lnumber; + k = eval(); + test_next(','); + dataptr = cmdptr; + cmdptr = (char*) cptr; + line = ii; + if(j != expr_type) + error(11); + if(!expr_type) /* numeric assignment */ + *dptr = k; + else { /* character assignment */ + if(*dptr) + free((void*) *dptr); + if(*sa1) { + *dptr = (unsigned) allocate(strlen(sa1)+1); + strcpy((char*) *dptr, sa1); + } else + *dptr = 0; + } + } while(test_next(',')); + break; + case DELAY: + delay(eval_num()); + break; + case BEEP: + i = eval_num(); + expect(','); + beep(i, eval_num()); + break; + case DOS: + eval_char(); + system(sa1); + break; + case OUT: + i = eval_num(); + expect(','); + out(i, eval_num()); + break; + case SAVE: + direct_only(); + if(skip_blank()) { + eval_char(); + concat(filename, sa1, ""); + } + fileout = fopen(filename, "wv"); + if(fileout) { + disp_pgm(fileout, 0, -1); + fclose(fileout); + } else + perror (filename); + break; + case LOAD: + eval_char(); + concat(filename, sa1, ""); + filein = fopen(filename, "rv"); + if(filein) { + if(!mode) clear_vars(); + clear_pgm(); + while(fgets(buffer, sizeof(buffer)-1, filein)) + edit_program(); + fclose(filein); + return pgm_start; + } else + perror (filename); + longjmp(savjmp, 1); + default: /* unknown */ + error(0); + } + return 0; } /* @@ -1425,56 +1177,56 @@ input: if (ii == -1) */ int do_arith(char opr, unsigned op1, unsigned op2) { - unsigned value; + unsigned value; - switch (opr) { - case ADD-(ADD-1): /* addition */ - value = op1 + op2; - break; - case SUB-(ADD-1): /* subtraction */ - value = op1 - op2; - break; - case MUL-(ADD-1): /* multiplication */ - value = op1 * op2; - break; - case DIV-(ADD-1): /* division */ - value = op1 / op2; - break; - case MOD-(ADD-1): /* modulus */ - value = op1 % op2; - break; - case AND-(ADD-1): /* logical and */ - value = op1 & op2; - break; - case OR-(ADD-1): /* logical or */ - value = op1 | op2; - break; - case XOR-(ADD-1): /* exclusive or */ - value = op1 ^ op2; - break; - case EQ-(ADD-1): /* equals */ - value = op1 == op2; - break; - case NE-(ADD-1): /* not-equals */ - value = op1 != op2; - break; - case LE-(ADD-1): /* less than or equal to */ - value = op1 <= op2; - break; - case LT-(ADD-1): /* less than */ - value = op1 < op2; - break; - case GE-(ADD-1): /* greater than or equal to */ - value = op1 >= op2; - break; - case GT-(ADD-1): /* greater than */ - value = op1 > op2; - break; - default: - error(0); - value = 0; - } - return value; + switch(opr) { + case ADD-(ADD-1): /* addition */ + value = op1 + op2; + break; + case SUB-(ADD-1): /* subtraction */ + value = op1 - op2; + break; + case MUL-(ADD-1): /* multiplication */ + value = op1 * op2; + break; + case DIV-(ADD-1): /* division */ + value = op1 / op2; + break; + case MOD-(ADD-1): /* modulus */ + value = op1 % op2; + break; + case AND-(ADD-1): /* logical and */ + value = op1 & op2; + break; + case OR-(ADD-1): /* logical or */ + value = op1 | op2; + break; + case XOR-(ADD-1): /* exclusive or */ + value = op1 ^ op2; + break; + case EQ-(ADD-1): /* equals */ + value = op1 == op2; + break; + case NE-(ADD-1): /* not-equals */ + value = op1 != op2; + break; + case LE-(ADD-1): /* less than or equal to */ + value = op1 <= op2; + break; + case LT-(ADD-1): /* less than */ + value = op1 < op2; + break; + case GE-(ADD-1): /* greater than or equal to */ + value = op1 >= op2; + break; + case GT-(ADD-1): /* greater than */ + value = op1 > op2; + break; + default: + error(0); + value = 0; + } + return value; } /* @@ -1482,43 +1234,37 @@ int do_arith(char opr, unsigned op1, unsigned op2) */ void get_char_value(char *ptr) { - unsigned i; - char c, *st; + unsigned i; + char c, *st; - if ((c = get_next()) == '"') { /* character value */ - while ((c = *cmdptr++) != '"') { - if (! c) - error(0); - *ptr++ = c; - } - *ptr = 0; - } else if (isalpha(c)) { /* variable */ - --cmdptr; - i = get_var(); - if (! expr_type) - error(0); - st = char_vars[i]; - if (st) - strcpy(ptr,st); - else - strcpy(ptr,""); - } else if (c == -128+CHR) { /* Convert number to character */ - *ptr++ = eval_sub(); - if (expr_type) - error(4); - *ptr = 0; - } else if (c == -128+STR) { /* Convert number to string */ - num_string(eval_sub(), ptr); - if (expr_type) - error(4); - } else if (c == -128+DATE) { /* Format a date */ - eval_sub(); - if (! expr_type) - error(4); - date_string(sa1,ptr); - } else - error(0); - expr_type = 1; + if((c = get_next()) == '"') { /* character value */ + while((c = *cmdptr++) != '"') { + if(!c) error(0); + *ptr++ = c; + } + *ptr = 0; + } else if(isalpha(c)) { /* variable */ + --cmdptr; + i = get_var(); + if(! expr_type) + error(0); + st = char_vars[i]; + if(st) + strcpy(ptr,st); + else + strcpy(ptr,""); + } else if(c == -128+CHR) { /* Convert number to character */ + *ptr++ = eval_sub(); + if(expr_type) + error(4); + *ptr = 0; + } else if(c == -128+STR) { /* Convert number to string */ + num_string(eval_sub(), ptr); + if(expr_type) + error(4); + } else + error(0); + expr_type = 1; } /* @@ -1526,111 +1272,81 @@ void get_char_value(char *ptr) */ int get_value() { - unsigned value, v, *dptr; - char c, *ptr; + unsigned value, v, *dptr; + char c, *ptr; - expr_type = 0; - if (isdigit(c = skip_blank())) - value = get_num(); - else { - ++cmdptr; - switch ((int)c) { - case '(': /* nesting */ - value = eval_sub(); - break; - case '!': /* not */ - value = ~get_value(); - break; - case -128+SUB: /* negate */ - value = -get_value(); - break; - case -128+ASC: /* Convert character to number */ - eval_sub(); - if (! expr_type) - error(4); - value = *sa1 & 255; - expr_type = 0; - break; - case -128+NUM: /* Convert string to number */ - eval_sub(); - if (! expr_type) - error(4); - value = atoi(sa1); - expr_type = 0; - break; - case -128+ABS: /* Absolute value */ - if ((value = eval_sub()) > INT_MAX) - value = -value; - goto number_only; - case -128+RND: /* Random number */ - value = random() % eval_sub(); - goto number_only; - case -128+SIN: /* SIN */ - value = _sin(eval_sub()); - goto number_only; - case -128+COS: /* COS */ - value = _cos(eval_sub()); - goto number_only; - case -128+TAN: /* TAN */ - value = _tan(eval_sub()); - goto number_only; - case -128+ASIN: /* ASIN */ - value = _asin(eval_sub()); - goto number_only; - case -128+ACOS: /* ACOS */ - value = _acos(eval_sub()); - goto number_only; - case -128+ATAN: /* ATAN */ - value = _atan(eval_sub()); - goto number_only; - case -128+LOG: /* LN */ - value = _log(eval_sub()); - goto number_only; - case -128+LOG10: /* LOG */ - value = _log10(eval_sub()); - goto number_only; - case -128+EXP: /* EXP */ - value = _exp(eval_sub()); - goto number_only; - case -128+KEY: /* Keyboard test */ - /* eval_sub(); */ - expect(')'); - value = kbtst(); - break; - case -128+INP: /* Read from port */ - value = in(eval_sub()); + expr_type = 0; + if(isdigit(c = skip_blank())) + value = get_num(); + else { + ++cmdptr; + switch(c) { + case '(': /* nesting */ + value = eval_sub(); + break; + case '!': /* not */ + value = ~get_value(); + break; + case -128+SUB: /* negate */ + value = -get_value(); + break; + case -128+ASC: /* Convert character to number */ + eval_sub(); + if(! expr_type) error(4); + value = *sa1 & 255; + expr_type = 0; + break; + case -128+NUM: /* Convert string to number */ + eval_sub(); + if(! expr_type) error(4); + value = atoi(sa1); + expr_type = 0; + break; + case -128+ABS: /* Absolute value */ + if((value = eval_sub()) > INT_MAX) + value = -value; + goto number_only; + case -128+RND: /* Random number */ + value = random() % eval_sub(); + goto number_only; + case -128+KEY: /* Keyboard test */ + /* eval_sub(); */ + expect(')'); + value = kbtst(); + break; + case -128+INP: /* Read from port */ + value = in(eval_sub()); number_only: - if (expr_type) - error(4); - break; - default: /* test for character expression */ - --cmdptr; - if (isalpha(c)) { /* variable */ - value = get_var(); - if (expr_type) { /* char */ - ptr = char_vars[value]; - if (ptr) - strcpy(sa1, ptr); - else - strcpy(sa1, ""); - } else { - if (test_next('(')) { /* Array */ - dptr = (unsigned*) dim_vars[value]; - if (! dptr) - error(10); - if ((v = eval_sub()) >= dim_check[value]) - error(10); - value = dptr[v]; - } else /* Std variable */ - value = num_vars[value]; - } - } else { - get_char_value(sa1); - value = 0; - } - } - } - return value; + if(expr_type) error(4); + break; + default: /* test for character expression */ + --cmdptr; + if(isalpha(c)) { /* variable */ + value = get_var(); + if(expr_type) { /* char */ + ptr = char_vars[value]; + if(ptr) + strcpy(sa1, ptr); + else + strcpy(sa1, ""); + } else { + if(test_next('(')) { /* Array */ + dptr = (unsigned*) dim_vars[value]; + if(! dptr) + error(10); + if((v = eval_sub()) >= dim_check[value]) + error(10); + value = dptr[v]; + } else /* Std variable */ + value = num_vars[value]; + } + } else { + get_char_value(sa1); + value = 0; + } + } + } + return value; } /* @@ -1638,63 +1354,61 @@ number_only: */ int eval_sub() { - unsigned value, nstack[10], nptr, optr; - int ostack[10], c; + unsigned value, nstack[10], nptr, optr; + int ostack[10], c; - ++nest; /* indicate we went down */ + ++nest; /* indicate we went down */ - /* establish first entry on number and operator stacks */ - ostack[optr = nptr = 0] = 0; /* add zero to init */ +/* establish first entry on number and operator stacks */ + ostack[optr = nptr = 0] = 0; /* add zero to init */ - nstack[++nptr] = get_value(); /* get next value */ + nstack[++nptr] = get_value(); /* get next value */ +/* string operations */ + if(expr_type) { /* string operations */ + while(!is_e_end(c = skip_blank())) { + ++cmdptr; + c &= 0x7F; + get_char_value(sa2); + if(c == ADD) /* String concatination */ + strcat(sa1, sa2); + else { + if(c == EQ) /* String EQUALS */ + value = !strcmp(sa1, sa2); + else if(c == NE) /* String NOT EQUALS */ + value = strcmp(sa1, sa2) != 0; + else { + error(0); + value = 0; + } + nstack[nptr] = value; + expr_type = 0; + } + } - /* string operations */ - if (expr_type) { /* string operations */ - while (! is_e_end(c = skip_blank())) { - ++cmdptr; - c &= 0x7F; - get_char_value(sa2); - if (c == ADD) /* String concatination */ - strcat(sa1, sa2); - else { - if (c == EQ) /* String EQUALS */ - value = !strcmp(sa1, sa2); - else if (c == NE) /* String NOT EQUALS */ - value = strcmp(sa1, sa2) != 0; - else { - error(0); - value = 0; - } - nstack[nptr] = value; - expr_type = 0; - } - } - - /* numeric operations */ - } else { - while (! is_e_end(c = skip_blank())) { - ++cmdptr; - c = (c & 0x7F) - (ADD-1); /* 0 based priority table */ - if (priority[c] <= priority[ostack[optr]]) { - /* execute operand */ - value = nstack[nptr--]; - nstack[nptr] = do_arith(ostack[optr--], nstack[nptr], value); - } - nstack[++nptr] = get_value(); /* stack next operand */ - if (expr_type) - error(0); - ostack[++optr] = c; - } - while (optr) { /* clean up all pending operations */ - value = nstack[nptr--]; - nstack[nptr] = do_arith(ostack[optr--], nstack[nptr], value); - } - } - if (c == ')') { - --nest; - ++cmdptr; - } - return nstack[nptr]; +/* numeric operations */ + } else { + while(!is_e_end(c = skip_blank())) { + ++cmdptr; + c = (c & 0x7F) - (ADD-1); /* 0 based priority table */ + if(priority[c] <= priority[ostack[optr]]) { + /* execute operand */ + value = nstack[nptr--]; + nstack[nptr] = do_arith(ostack[optr--], nstack[nptr], value); + } + nstack[++nptr] = get_value(); /* stack next operand */ + if(expr_type) error(0); + ostack[++optr] = c; + } + while(optr) { /* clean up all pending operations */ + value = nstack[nptr--]; + nstack[nptr] = do_arith(ostack[optr--], nstack[nptr], value); + } + } + if(c == ')') { + --nest; + ++cmdptr; + } + return nstack[nptr]; } /* @@ -1702,58 +1416,56 @@ int eval_sub() */ int main(int argc, char *argv[]) { - int i, j; + int i, j; - pgm_start = 0; - srandom (time (0)); + pgm_start = 0; + srandom (time (0)); - /* - * If arguments are given, copy them into the A0$, A1$, A2$ ... variables - */ - j = 0; - for (i=1; i < argc; ++i) - char_vars[j++] = strdup (argv[i]); + /* + * If arguments are given, copy them into the A0$, A1$, A2$ ... variables + */ + j = 0; + for(i=1; i < argc; ++i) + char_vars[j++] = strdup (argv[i]); - /* - * If a name is given on the command line, load it as a program and - * run immediately. If the program does not explicitly EXIT, we will - * then proceed to an interactive session - */ - if (j) { - concat(filename, char_vars[0], ""); - filein = fopen(filename, "rv"); - if (filein) { - while (fgets(buffer, sizeof(buffer)-1, filein)) - edit_program(); - fclose(filein); - cmdptr = ""; - if (! setjmp(savjmp)) - execute(RUN1); - } else - perror (filename); - } + /* + * If a name is given on the command line, load it as a program and + * run immediately. If the program does not explicitly EXIT, we will + * then proceed to an interactive session + */ + if(j) { + concat(filename, char_vars[0], ""); + filein = fopen(filename, "rv"); + if(filein) { + while(fgets(buffer, sizeof(buffer)-1, filein)) + edit_program(); + fclose(filein); + cmdptr = ""; + if(! setjmp(savjmp)) + execute(RUN1); + } else + perror (filename); + } - /* - * Display header AFTER running command line, so that programs run as - * "batch" commands terminating with EXIT do not get "noise" output. - */ - printf("MICRO-BASIC 2.1 - Copyright 1982-2000 Dave Dunfield.\n"); + /* + * Display header AFTER running command line, so that programs run as + * "batch" commands terminating with EXIT do not get "noise" output. + */ + printf("MICRO-BASIC 2.1 - Copyright 1982-2000 Dave Dunfield.\n"); - setjmp(savjmp); - for (;;) { /* Main interactive loop */ - fputs("Ready\n", stdout); -noprompt: - mode = 0; - ctl_ptr = 0; - if (! fgets(buffer, sizeof(buffer)-1, stdin)) - exit (0); - if (edit_program()) /* Tokenize & edit if OK */ - goto noprompt; - i = *cmdptr; - if (i < 0) { /* Keyword, execute command */ - ++cmdptr; - execute(i); - } else if (i) /* Unknown, assume LET */ - execute(LET); - } + setjmp(savjmp); + for(;;) { /* Main interactive loop */ + fputs("Ready\n", stdout); +noprompt: mode = ctl_ptr = 0; + if (! fgets(buffer, sizeof(buffer)-1, stdin)) + exit (0); + if(edit_program()) /* Tokenize & edit if OK */ + goto noprompt; + i = *cmdptr; + if(i < 0) { /* Keyword, execute command */ + ++cmdptr; + execute(i); + } else if(i) /* Unknown, assume LET */ + execute(LET); + } } diff --git a/src/cmd/bc.y b/src/cmd/bc.y index 982c86f..24a2305 100644 --- a/src/cmd/bc.y +++ b/src/cmd/bc.y @@ -1,5 +1,5 @@ %{ - int *getout(); + int *getout(); %} %right '=' %left '+' '-' @@ -37,296 +37,296 @@ char *numb[15] = { int *pre, *post; %} %% -start : - | start stat tail - = output( $2 ); - | start def dargs ')' '{' dlist slist '}' - ={ bundle( 6,pre, $7, post ,"0",numb[lev],"Q"); - conout( $$, $2 ); - rcrs = crs; - output( "" ); - lev = bindx = 0; - } - ; +start : + | start stat tail + = output( $2 ); + | start def dargs ')' '{' dlist slist '}' + ={ bundle( 6,pre, $7, post ,"0",numb[lev],"Q"); + conout( $$, $2 ); + rcrs = crs; + output( "" ); + lev = bindx = 0; + } + ; -dlist : tail - | dlist _AUTO dlets tail - ; +dlist : tail + | dlist _AUTO dlets tail + ; -stat : e - ={ bundle(2, $1, "ps." ); } - | - ={ bundle(1, "" ); } - | QSTR - ={ bundle(3,"[",$1,"]P");} - | LETTER '=' e - ={ bundle(3, $3, "s", $1 ); } - | LETTER '[' e ']' '=' e - ={ bundle(4, $6, $3, ":", geta($1)); } - | LETTER EQOP e - ={ bundle(6, "l", $1, $3, $2, "s", $1 ); } - | LETTER '[' e ']' EQOP e - ={ bundle(8,$3, ";", geta($1), $6, $5, $3, ":", geta($1));} - | _BREAK - ={ bundle(2, numb[lev-bstack[bindx-1]], "Q" ); } - | _RETURN '(' e ')' - = bundle(4, $3, post, numb[lev], "Q" ); - | _RETURN '(' ')' - = bundle(4, "0", post, numb[lev], "Q" ); - | _RETURN - = bundle(4,"0",post,numb[lev],"Q"); - | SCALE '=' e - = bundle(2, $3, "k"); - | SCALE EQOP e - = bundle(4,"K",$3,$2,"k"); - | BASE '=' e - = bundle(2,$3, "i"); - | BASE EQOP e - = bundle(4,"I",$3,$2,"i"); - | OBASE '=' e - = bundle(2,$3,"o"); - | OBASE EQOP e - = bundle(4,"O",$3,$2,"o"); - | '{' slist '}' - ={ $$ = $2; } - | FFF - ={ bundle(1,"fY"); } - | error - ={ bundle(1,"c"); } - | _IF CRS BLEV '(' re ')' stat - ={ conout( $7, $2 ); - bundle(3, $5, $2, " " ); - } - | _WHILE CRS '(' re ')' stat BLEV - ={ bundle(3, $6, $4, $2 ); - conout( $$, $2 ); - bundle(3, $4, $2, " " ); - } - | fprefix CRS re ';' e ')' stat BLEV - ={ bundle(5, $7, $5, "s.", $3, $2 ); - conout( $$, $2 ); - bundle(5, $1, "s.", $3, $2, " " ); - } - | '~' LETTER '=' e - ={ bundle(3,$4,"S",$2); } - ; +stat : e + ={ bundle(2, $1, "ps." ); } + | + ={ bundle(1, "" ); } + | QSTR + ={ bundle(3,"[",$1,"]P");} + | LETTER '=' e + ={ bundle(3, $3, "s", $1 ); } + | LETTER '[' e ']' '=' e + ={ bundle(4, $6, $3, ":", geta($1)); } + | LETTER EQOP e + ={ bundle(6, "l", $1, $3, $2, "s", $1 ); } + | LETTER '[' e ']' EQOP e + ={ bundle(8,$3, ";", geta($1), $6, $5, $3, ":", geta($1));} + | _BREAK + ={ bundle(2, numb[lev-bstack[bindx-1]], "Q" ); } + | _RETURN '(' e ')' + = bundle(4, $3, post, numb[lev], "Q" ); + | _RETURN '(' ')' + = bundle(4, "0", post, numb[lev], "Q" ); + | _RETURN + = bundle(4,"0",post,numb[lev],"Q"); + | SCALE '=' e + = bundle(2, $3, "k"); + | SCALE EQOP e + = bundle(4,"K",$3,$2,"k"); + | BASE '=' e + = bundle(2,$3, "i"); + | BASE EQOP e + = bundle(4,"I",$3,$2,"i"); + | OBASE '=' e + = bundle(2,$3,"o"); + | OBASE EQOP e + = bundle(4,"O",$3,$2,"o"); + | '{' slist '}' + ={ $$ = $2; } + | FFF + ={ bundle(1,"fY"); } + | error + ={ bundle(1,"c"); } + | _IF CRS BLEV '(' re ')' stat + ={ conout( $7, $2 ); + bundle(3, $5, $2, " " ); + } + | _WHILE CRS '(' re ')' stat BLEV + ={ bundle(3, $6, $4, $2 ); + conout( $$, $2 ); + bundle(3, $4, $2, " " ); + } + | fprefix CRS re ';' e ')' stat BLEV + ={ bundle(5, $7, $5, "s.", $3, $2 ); + conout( $$, $2 ); + bundle(5, $1, "s.", $3, $2, " " ); + } + | '~' LETTER '=' e + ={ bundle(3,$4,"S",$2); } + ; -EQOP : EQPL - ={ $$ = (int) "+"; } - | EQMI - ={ $$ = (int) "-"; } - | EQMUL - ={ $$ = (int) "*"; } - | EQDIV - ={ $$ = (int) "/"; } - | EQREM - ={ $$ = (int) "%%"; } - | EQEXP - ={ $$ = (int) "^"; } - ; +EQOP : EQPL + ={ $$ = (int) "+"; } + | EQMI + ={ $$ = (int) "-"; } + | EQMUL + ={ $$ = (int) "*"; } + | EQDIV + ={ $$ = (int) "/"; } + | EQREM + ={ $$ = (int) "%%"; } + | EQEXP + ={ $$ = (int) "^"; } + ; -fprefix : _FOR '(' e ';' - ={ $$ = $3; } - ; +fprefix : _FOR '(' e ';' + ={ $$ = $3; } + ; -BLEV : - ={ --bindx; } - ; +BLEV : + ={ --bindx; } + ; -slist : stat - | slist tail stat - ={ bundle(2, $1, $3 ); } - ; +slist : stat + | slist tail stat + ={ bundle(2, $1, $3 ); } + ; -tail : '\n' - ={ln++;} - | ';' - ; +tail : '\n' + ={ln++;} + | ';' + ; -re : e EQ e - = bundle(3, $1, $3, "=" ); - | e '<' e - = bundle(3, $1, $3, ">" ); - | e '>' e - = bundle(3, $1, $3, "<" ); - | e NE e - = bundle(3, $1, $3, "!=" ); - | e GE e - = bundle(3, $1, $3, "!>" ); - | e LE e - = bundle(3, $1, $3, "!<" ); - | e - = bundle(2, $1, " 0!=" ); - ; +re : e EQ e + = bundle(3, $1, $3, "=" ); + | e '<' e + = bundle(3, $1, $3, ">" ); + | e '>' e + = bundle(3, $1, $3, "<" ); + | e NE e + = bundle(3, $1, $3, "!=" ); + | e GE e + = bundle(3, $1, $3, "!>" ); + | e LE e + = bundle(3, $1, $3, "!<" ); + | e + = bundle(2, $1, " 0!=" ); + ; -e : e '+' e - = bundle(3, $1, $3, "+" ); - | e '-' e - = bundle(3, $1, $3, "-" ); - | '-' e %prec UMINUS - = bundle(3, " 0", $2, "-" ); - | e '*' e - = bundle(3, $1, $3, "*" ); - | e '/' e - = bundle(3, $1, $3, "/" ); - | e '%' e - = bundle(3, $1, $3, "%%" ); - | e '^' e - = bundle(3, $1, $3, "^" ); - | LETTER '[' e ']' - ={ bundle(3,$3, ";", geta($1)); } - | LETTER INCR - = bundle(4, "l", $1, "d1+s", $1 ); - | INCR LETTER - = bundle(4, "l", $2, "1+ds", $2 ); - | DECR LETTER - = bundle(4, "l", $2, "1-ds", $2 ); - | LETTER DECR - = bundle(4, "l", $1, "d1-s", $1 ); - | LETTER '[' e ']' INCR - = bundle(7,$3,";",geta($1),"d1+",$3,":",geta($1)); - | INCR LETTER '[' e ']' - = bundle(7,$4,";",geta($2),"1+d",$4,":",geta($2)); - | LETTER '[' e ']' DECR - = bundle(7,$3,";",geta($1),"d1-",$3,":",geta($1)); - | DECR LETTER '[' e ']' - = bundle(7,$4,";",geta($2),"1-d",$4,":",geta($2)); - | SCALE INCR - = bundle(1,"Kd1+k"); - | INCR SCALE - = bundle(1,"K1+dk"); - | SCALE DECR - = bundle(1,"Kd1-k"); - | DECR SCALE - = bundle(1,"K1-dk"); - | BASE INCR - = bundle(1,"Id1+i"); - | INCR BASE - = bundle(1,"I1+di"); - | BASE DECR - = bundle(1,"Id1-i"); - | DECR BASE - = bundle(1,"I1-di"); - | OBASE INCR - = bundle(1,"Od1+o"); - | INCR OBASE - = bundle(1,"O1+do"); - | OBASE DECR - = bundle(1,"Od1-o"); - | DECR OBASE - = bundle(1,"O1-do"); - | LETTER '(' cargs ')' - = bundle(4, $3, "l", getf($1), "x" ); - | LETTER '(' ')' - = bundle(3, "l", getf($1), "x" ); - | cons - ={ bundle(2, " ", $1 ); } - | DOT cons - ={ bundle(2, " .", $2 ); } - | cons DOT cons - ={ bundle(4, " ", $1, ".", $3 ); } - | cons DOT - ={ bundle(3, " ", $1, "." ); } - | DOT - ={ $$ = (int) "l."; } - | LETTER - = { bundle(2, "l", $1 ); } - | LETTER '=' e - ={ bundle(3, $3, "ds", $1 ); } - | LETTER EQOP e %prec '=' - ={ bundle(6, "l", $1, $3, $2, "ds", $1 ); } - | LETTER '[' e ']' '=' e - = { bundle(5,$6,"d",$3,":",geta($1)); } - | LETTER '[' e ']' EQOP e - = { bundle(9,$3,";",geta($1),$6,$5,"d",$3,":",geta($1)); } - | LENGTH '(' e ')' - = bundle(2,$3,"Z"); - | SCALE '(' e ')' - = bundle(2,$3,"X"); /* must be before '(' e ')' */ - | '(' e ')' - = { $$ = $2; } - | '?' - ={ bundle(1, "?" ); } - | SQRT '(' e ')' - ={ bundle(2, $3, "v" ); } - | '~' LETTER - ={ bundle(2,"L",$2); } - | SCALE '=' e - = bundle(2,$3,"dk"); - | SCALE EQOP e %prec '=' - = bundle(4,"K",$3,$2,"dk"); - | BASE '=' e - = bundle(2,$3,"di"); - | BASE EQOP e %prec '=' - = bundle(4,"I",$3,$2,"di"); - | OBASE '=' e - = bundle(2,$3,"do"); - | OBASE EQOP e %prec '=' - = bundle(4,"O",$3,$2,"do"); - | SCALE - = bundle(1,"K"); - | BASE - = bundle(1,"I"); - | OBASE - = bundle(1,"O"); - ; +e : e '+' e + = bundle(3, $1, $3, "+" ); + | e '-' e + = bundle(3, $1, $3, "-" ); + | '-' e %prec UMINUS + = bundle(3, " 0", $2, "-" ); + | e '*' e + = bundle(3, $1, $3, "*" ); + | e '/' e + = bundle(3, $1, $3, "/" ); + | e '%' e + = bundle(3, $1, $3, "%%" ); + | e '^' e + = bundle(3, $1, $3, "^" ); + | LETTER '[' e ']' + ={ bundle(3,$3, ";", geta($1)); } + | LETTER INCR + = bundle(4, "l", $1, "d1+s", $1 ); + | INCR LETTER + = bundle(4, "l", $2, "1+ds", $2 ); + | DECR LETTER + = bundle(4, "l", $2, "1-ds", $2 ); + | LETTER DECR + = bundle(4, "l", $1, "d1-s", $1 ); + | LETTER '[' e ']' INCR + = bundle(7,$3,";",geta($1),"d1+",$3,":",geta($1)); + | INCR LETTER '[' e ']' + = bundle(7,$4,";",geta($2),"1+d",$4,":",geta($2)); + | LETTER '[' e ']' DECR + = bundle(7,$3,";",geta($1),"d1-",$3,":",geta($1)); + | DECR LETTER '[' e ']' + = bundle(7,$4,";",geta($2),"1-d",$4,":",geta($2)); + | SCALE INCR + = bundle(1,"Kd1+k"); + | INCR SCALE + = bundle(1,"K1+dk"); + | SCALE DECR + = bundle(1,"Kd1-k"); + | DECR SCALE + = bundle(1,"K1-dk"); + | BASE INCR + = bundle(1,"Id1+i"); + | INCR BASE + = bundle(1,"I1+di"); + | BASE DECR + = bundle(1,"Id1-i"); + | DECR BASE + = bundle(1,"I1-di"); + | OBASE INCR + = bundle(1,"Od1+o"); + | INCR OBASE + = bundle(1,"O1+do"); + | OBASE DECR + = bundle(1,"Od1-o"); + | DECR OBASE + = bundle(1,"O1-do"); + | LETTER '(' cargs ')' + = bundle(4, $3, "l", getf($1), "x" ); + | LETTER '(' ')' + = bundle(3, "l", getf($1), "x" ); + | cons + ={ bundle(2, " ", $1 ); } + | DOT cons + ={ bundle(2, " .", $2 ); } + | cons DOT cons + ={ bundle(4, " ", $1, ".", $3 ); } + | cons DOT + ={ bundle(3, " ", $1, "." ); } + | DOT + ={ $$ = (int) "l."; } + | LETTER + = { bundle(2, "l", $1 ); } + | LETTER '=' e + ={ bundle(3, $3, "ds", $1 ); } + | LETTER EQOP e %prec '=' + ={ bundle(6, "l", $1, $3, $2, "ds", $1 ); } + | LETTER '[' e ']' '=' e + = { bundle(5,$6,"d",$3,":",geta($1)); } + | LETTER '[' e ']' EQOP e + = { bundle(9,$3,";",geta($1),$6,$5,"d",$3,":",geta($1)); } + | LENGTH '(' e ')' + = bundle(2,$3,"Z"); + | SCALE '(' e ')' + = bundle(2,$3,"X"); /* must be before '(' e ')' */ + | '(' e ')' + = { $$ = $2; } + | '?' + ={ bundle(1, "?" ); } + | SQRT '(' e ')' + ={ bundle(2, $3, "v" ); } + | '~' LETTER + ={ bundle(2,"L",$2); } + | SCALE '=' e + = bundle(2,$3,"dk"); + | SCALE EQOP e %prec '=' + = bundle(4,"K",$3,$2,"dk"); + | BASE '=' e + = bundle(2,$3,"di"); + | BASE EQOP e %prec '=' + = bundle(4,"I",$3,$2,"di"); + | OBASE '=' e + = bundle(2,$3,"do"); + | OBASE EQOP e %prec '=' + = bundle(4,"O",$3,$2,"do"); + | SCALE + = bundle(1,"K"); + | BASE + = bundle(1,"I"); + | OBASE + = bundle(1,"O"); + ; -cargs : eora - | cargs ',' eora - = bundle(2, $1, $3 ); - ; -eora: e - | LETTER '[' ']' - =bundle(2,"l",geta($1)); - ; +cargs : eora + | cargs ',' eora + = bundle(2, $1, $3 ); + ; +eora: e + | LETTER '[' ']' + =bundle(2,"l",geta($1)); + ; -cons : constant - ={ *cp++ = '\0'; } +cons : constant + ={ *cp++ = '\0'; } constant: - '_' - ={ $$ = (int) cp; *cp++ = '_'; } - | DIGIT - ={ $$ = (int) cp; *cp++ = $1; } - | constant DIGIT - ={ *cp++ = $2; } - ; + '_' + ={ $$ = (int) cp; *cp++ = '_'; } + | DIGIT + ={ $$ = (int) cp; *cp++ = $1; } + | constant DIGIT + ={ *cp++ = $2; } + ; -CRS : - ={ $$ = (int) cp; *cp++ = crs++; *cp++ = '\0'; - if(crs == '[')crs+=3; - if(crs == 'a')crs='{'; - if(crs >= 0241){yyerror("program too big"); - getout(); - } - bstack[bindx++] = lev++; } - ; +CRS : + ={ $$ = (int) cp; *cp++ = crs++; *cp++ = '\0'; + if(crs == '[')crs+=3; + if(crs == 'a')crs='{'; + if(crs >= 0241){yyerror("program too big"); + getout(); + } + bstack[bindx++] = lev++; } + ; -def : _DEFINE LETTER '(' - ={ $$ = (int) getf($2); - pre = (int*) ""; - post = (int*) ""; - lev = 1; - bstack[bindx=0] = 0; - } - ; +def : _DEFINE LETTER '(' + ={ $$ = (int) getf($2); + pre = (int*) ""; + post = (int*) ""; + lev = 1; + bstack[bindx=0] = 0; + } + ; -dargs : - | lora - ={ pp( $1 ); } - | dargs ',' lora - ={ pp( $3 ); } - ; +dargs : + | lora + ={ pp( $1 ); } + | dargs ',' lora + ={ pp( $3 ); } + ; -dlets : lora - ={ tp($1); } - | dlets ',' lora - ={ tp($3); } - ; -lora : LETTER - | LETTER '[' ']' - ={ $$ = (int) geta($1); } - ; +dlets : lora + ={ tp($1); } + | dlets ',' lora + ={ tp($3); } + ; +lora : LETTER + | LETTER '[' ']' + ={ $$ = (int) geta($1); } + ; %% # define error 256 @@ -337,141 +337,141 @@ int ifile; char **sargv; char funtab[52] = { - 01,0,02,0,03,0,04,0,05,0,06,0,07,0,010,0,011,0,012,0,013,0,014,0,015,0,016,0,017,0, - 020,0,021,0,022,0,023,0,024,0,025,0,026,0,027,0,030,0,031,0,032,0 }; + 01,0,02,0,03,0,04,0,05,0,06,0,07,0,010,0,011,0,012,0,013,0,014,0,015,0,016,0,017,0, + 020,0,021,0,022,0,023,0,024,0,025,0,026,0,027,0,030,0,031,0,032,0 }; char atab[52] = { - 0241,0,0242,0,0243,0,0244,0,0245,0,0246,0,0247,0,0250,0,0251,0,0252,0,0253,0, - 0254,0,0255,0,0256,0,0257,0,0260,0,0261,0,0262,0,0263,0,0264,0,0265,0,0266,0, - 0267,0,0270,0,0271,0,0272,0}; + 0241,0,0242,0,0243,0,0244,0,0245,0,0246,0,0247,0,0250,0,0251,0,0252,0,0253,0, + 0254,0,0255,0,0256,0,0257,0,0260,0,0261,0,0262,0,0263,0,0264,0,0265,0,0266,0, + 0267,0,0270,0,0271,0,0272,0}; char *letr[26] = { "a","b","c","d","e","f","g","h","i","j", "k","l","m","n","o","p","q","r","s","t", "u","v","w","x","y","z" } ; char *dot = { "." }; yylex(){ - int c, ch; + int c, ch; restart: - c = getch(); - peekc = -1; - while( c == ' ' || c == '\t' ) c = getch(); - if(c == '\\'){ - getch(); - goto restart; - } - if( c<= 'z' && c >= 'a' ) { - /* look ahead to look for reserved words */ - peekc = getch(); - if( peekc >= 'a' && peekc <= 'z' ){ /* must be reserved word */ - if( c=='i' && peekc=='f' ){ c=_IF; goto skip; } - if( c=='w' && peekc=='h' ){ c=_WHILE; goto skip; } - if( c=='f' && peekc=='o' ){ c=_FOR; goto skip; } - if( c=='s' && peekc=='q' ){ c=SQRT; goto skip; } - if( c=='r' && peekc=='e' ){ c=_RETURN; goto skip; } - if( c=='b' && peekc=='r' ){ c=_BREAK; goto skip; } - if( c=='d' && peekc=='e' ){ c=_DEFINE; goto skip; } - if( c=='s' && peekc=='c' ){ c= SCALE; goto skip; } - if( c=='b' && peekc=='a' ){ c=BASE; goto skip; } - if( c=='i' && peekc == 'b'){ c=BASE; goto skip; } - if( c=='o' && peekc=='b' ){ c=OBASE; goto skip; } - if( c=='d' && peekc=='i' ){ c=FFF; goto skip; } - if( c=='a' && peekc=='u' ){ c=_AUTO; goto skip; } - if( c == 'l' && peekc=='e'){ c=LENGTH; goto skip; } - if( c == 'q' && peekc == 'u'){getout();} - /* could not be found */ - return( error ); - skip: /* skip over rest of word */ - peekc = -1; - while( (ch = getch()) >= 'a' && ch <= 'z' ); - peekc = ch; - return( c ); - } + c = getch(); + peekc = -1; + while( c == ' ' || c == '\t' ) c = getch(); + if(c == '\\'){ + getch(); + goto restart; + } + if( c<= 'z' && c >= 'a' ) { + /* look ahead to look for reserved words */ + peekc = getch(); + if( peekc >= 'a' && peekc <= 'z' ){ /* must be reserved word */ + if( c=='i' && peekc=='f' ){ c=_IF; goto skip; } + if( c=='w' && peekc=='h' ){ c=_WHILE; goto skip; } + if( c=='f' && peekc=='o' ){ c=_FOR; goto skip; } + if( c=='s' && peekc=='q' ){ c=SQRT; goto skip; } + if( c=='r' && peekc=='e' ){ c=_RETURN; goto skip; } + if( c=='b' && peekc=='r' ){ c=_BREAK; goto skip; } + if( c=='d' && peekc=='e' ){ c=_DEFINE; goto skip; } + if( c=='s' && peekc=='c' ){ c= SCALE; goto skip; } + if( c=='b' && peekc=='a' ){ c=BASE; goto skip; } + if( c=='i' && peekc == 'b'){ c=BASE; goto skip; } + if( c=='o' && peekc=='b' ){ c=OBASE; goto skip; } + if( c=='d' && peekc=='i' ){ c=FFF; goto skip; } + if( c=='a' && peekc=='u' ){ c=_AUTO; goto skip; } + if( c == 'l' && peekc=='e'){ c=LENGTH; goto skip; } + if( c == 'q' && peekc == 'u'){getout();} + /* could not be found */ + return( error ); + skip: /* skip over rest of word */ + peekc = -1; + while( (ch = getch()) >= 'a' && ch <= 'z' ); + peekc = ch; + return( c ); + } - /* usual case; just one single letter */ + /* usual case; just one single letter */ - yylval = (int) letr[c-'a']; - return( LETTER ); - } - if( c>= '0' && c <= '9' || c>= 'A' && c<= 'F' ){ - yylval = c; - return( DIGIT ); - } - switch( c ){ - case '.': return( DOT ); - case '=': - switch( peekc = getch() ){ - case '=': c=EQ; goto gotit; - case '+': c=EQPL; goto gotit; - case '-': c=EQMI; goto gotit; - case '*': c=EQMUL; goto gotit; - case '/': c=EQDIV; goto gotit; - case '%': c=EQREM; goto gotit; - case '^': c=EQEXP; goto gotit; - default: return( '=' ); - gotit: peekc = -1; return(c); - } - case '+': return( cpeek( '+', INCR, cpeek( '=', EQPL, '+') ) ); - case '-': return( cpeek( '-', DECR, cpeek( '=', EQMI, '-') ) ); - case '<': return( cpeek( '=', LE, '<' ) ); - case '>': return( cpeek( '=', GE, '>' ) ); - case '!': return( cpeek( '=', NE, '!' ) ); - case '/': - if((peekc = getch()) == '*'){ - peekc = -1; - while((getch() != '*') || ((peekc = getch()) != '/')); - peekc = -1; - goto restart; - } - else if (peekc == '=') { - c=EQDIV; - goto gotit; - } - else return(c); - case '*': - return( cpeek( '=', EQMUL, '*' ) ); - case '%': - return( cpeek( '=', EQREM, '%' ) ); - case '^': - return( cpeek( '=', EQEXP, '^' ) ); - case '"': - yylval = (int) str; - while((c=getch()) != '"'){*str++ = c; - if(str >= &string[999]){yyerror("string space exceeded"); - getout(); - } - } - *str++ = '\0'; - return(QSTR); - default: return( c ); - } + yylval = (int) letr[c-'a']; + return( LETTER ); + } + if( c>= '0' && c <= '9' || c>= 'A' && c<= 'F' ){ + yylval = c; + return( DIGIT ); + } + switch( c ){ + case '.': return( DOT ); + case '=': + switch( peekc = getch() ){ + case '=': c=EQ; goto gotit; + case '+': c=EQPL; goto gotit; + case '-': c=EQMI; goto gotit; + case '*': c=EQMUL; goto gotit; + case '/': c=EQDIV; goto gotit; + case '%': c=EQREM; goto gotit; + case '^': c=EQEXP; goto gotit; + default: return( '=' ); + gotit: peekc = -1; return(c); + } + case '+': return( cpeek( '+', INCR, cpeek( '=', EQPL, '+') ) ); + case '-': return( cpeek( '-', DECR, cpeek( '=', EQMI, '-') ) ); + case '<': return( cpeek( '=', LE, '<' ) ); + case '>': return( cpeek( '=', GE, '>' ) ); + case '!': return( cpeek( '=', NE, '!' ) ); + case '/': + if((peekc = getch()) == '*'){ + peekc = -1; + while((getch() != '*') || ((peekc = getch()) != '/')); + peekc = -1; + goto restart; + } + else if (peekc == '=') { + c=EQDIV; + goto gotit; + } + else return(c); + case '*': + return( cpeek( '=', EQMUL, '*' ) ); + case '%': + return( cpeek( '=', EQREM, '%' ) ); + case '^': + return( cpeek( '=', EQEXP, '^' ) ); + case '"': + yylval = (int) str; + while((c=getch()) != '"'){*str++ = c; + if(str >= &string[999]){yyerror("string space exceeded"); + getout(); + } + } + *str++ = '\0'; + return(QSTR); + default: return( c ); + } } cpeek( c, yes, no ){ - if( (peekc=getch()) != c ) return( no ); - else { - peekc = -1; - return( yes ); - } + if( (peekc=getch()) != c ) return( no ); + else { + peekc = -1; + return( yes ); + } } getch(){ - int ch; + int ch; loop: - ch = (peekc < 0) ? getc(in) : peekc; - peekc = -1; - if(ch != EOF)return(ch); - if(++ifile > sargc){ - if(ifile >= sargc+2)getout(); - in = stdin; - ln = 0; - goto loop; - } - fclose(in); - if((in = fopen(sargv[ifile],"r")) != NULL){ - ln = 0; - ss = sargv[ifile]; - goto loop; - } - yyerror("cannot open input file"); + ch = (peekc < 0) ? getc(in) : peekc; + peekc = -1; + if(ch != EOF)return(ch); + if(++ifile > sargc){ + if(ifile >= sargc+2)getout(); + in = stdin; + ln = 0; + goto loop; + } + fclose(in); + if((in = fopen(sargv[ifile],"r")) != NULL){ + ln = 0; + ss = sargv[ifile]; + goto loop; + } + yyerror("cannot open input file"); } # define b_sp_max 3000 int b_space [ b_sp_max ]; @@ -479,135 +479,135 @@ int * b_sp_nxt = { b_space }; int bdebug = 0; bundle(a){ - int i, *p, *q; + int i, *p, *q; - p = &a; - i = *p++; - q = b_sp_nxt; - if (bdebug) printf("bundle %d elements at %p\n", i, q); - while(i-- > 0){ - if( b_sp_nxt >= & b_space[b_sp_max] ) yyerror( "bundling space exceeded" ); - * b_sp_nxt++ = *p++; - } - * b_sp_nxt++ = 0; - yyval = (int) q; - return( (int) q ); + p = &a; + i = *p++; + q = b_sp_nxt; + if (bdebug) printf("bundle %d elements at %p\n", i, q); + while(i-- > 0){ + if( b_sp_nxt >= & b_space[b_sp_max] ) yyerror( "bundling space exceeded" ); + * b_sp_nxt++ = *p++; + } + * b_sp_nxt++ = 0; + yyval = (int) q; + return( (int) q ); } routput(p) int *p; { - if( bdebug ) printf("routput(%p)\n", p ); - if( p >= &b_space[0] && p < &b_space[b_sp_max]){ - /* part of a bundle */ - while( *p != 0 ) routput( *p++ ); - } - else printf( "%s", (char*) p ); /* character string */ + if( bdebug ) printf("routput(%p)\n", p ); + if( p >= &b_space[0] && p < &b_space[b_sp_max]){ + /* part of a bundle */ + while( *p != 0 ) routput( *p++ ); + } + else printf( "%s", (char*) p ); /* character string */ } output( p ) int *p; { - routput( p ); - b_sp_nxt = & b_space[0]; - printf( "\n" ); - fflush(stdout); - cp = cary; - crs = rcrs; + routput( p ); + b_sp_nxt = & b_space[0]; + printf( "\n" ); + fflush(stdout); + cp = cary; + crs = rcrs; } conout( p, s ) int *p; char *s; { - printf("["); - routput( p ); - printf("]s%s\n", s ); - fflush(stdout); - lev--; + printf("["); + routput( p ); + printf("]s%s\n", s ); + fflush(stdout); + lev--; } yyerror( s ) char *s; { - if(ifile > sargc)ss="teletype"; - printf("c[%s on line %d, %s]pc\n", s ,ln+1,ss); - fflush(stdout); - cp = cary; - crs = rcrs; - bindx = 0; - lev = 0; - b_sp_nxt = &b_space[0]; + if(ifile > sargc)ss="teletype"; + printf("c[%s on line %d, %s]pc\n", s ,ln+1,ss); + fflush(stdout); + cp = cary; + crs = rcrs; + bindx = 0; + lev = 0; + b_sp_nxt = &b_space[0]; } pp( s ) char *s; { - /* puts the relevant stuff on pre and post for the letter s */ + /* puts the relevant stuff on pre and post for the letter s */ - bundle(3, "S", s, pre ); - pre = (int*) yyval; - bundle(4, post, "L", s, "s." ); - post = (int*) yyval; + bundle(3, "S", s, pre ); + pre = (int*) yyval; + bundle(4, post, "L", s, "s." ); + post = (int*) yyval; } tp( s ) char *s; { /* same as pp, but for temps */ - bundle(3, "0S", s, pre ); - pre = (int*) yyval; - bundle(4, post, "L", s, "s." ); - post = (int*) yyval; + bundle(3, "0S", s, pre ); + pre = (int*) yyval; + bundle(4, post, "L", s, "s." ); + post = (int*) yyval; } yyinit(argc,argv) int argc; char *argv[];{ - signal( 2, SIG_IGN ); /* ignore all interrupts */ - sargv=argv; - sargc= -- argc; - if(sargc == 0)in=stdin; - else if((in = fopen(sargv[1],"r")) == NULL) { - yyerror("cannot open input file"); - in = stdin; - } - ifile = 1; - ln = 0; - ss = sargv[1]; + signal( 2, SIG_IGN ); /* ignore all interrupts */ + sargv=argv; + sargc= -- argc; + if(sargc == 0)in=stdin; + else if((in = fopen(sargv[1],"r")) == NULL) { + yyerror("cannot open input file"); + in = stdin; + } + ifile = 1; + ln = 0; + ss = sargv[1]; } int *getout(){ - printf("q"); - fflush(stdout); - exit(0); + printf("q"); + fflush(stdout); + exit(0); } int * getf(p) char *p;{ - return (int*) &funtab[2 * (*p - 0141)]; + return (int*) &funtab[2 * (*p - 0141)]; } int * geta(p) char *p;{ - return (int*) &atab[2 * (*p - 0141)]; + return (int*) &atab[2 * (*p - 0141)]; } main(argc, argv) char **argv; { - int p[2]; + int p[2]; - if (argc > 1 && *argv[1] == '-') { - if((argv[1][1] == 'd')||(argv[1][1] == 'c')){ - yyinit(--argc, ++argv); - yyparse(); - exit(0); - } - if(argv[1][1] != 'l'){ - printf("unrecognizable argument\n"); - fflush(stdout); - exit(0); - } - argv[1] = "/usr/share/misc/lib.b"; - } - pipe(p); - if (fork()==0) { - close(1); - dup(p[1]); - close(p[0]); - close(p[1]); - yyinit(argc, argv); - yyparse(); - exit(0); - } - close(0); - dup(p[0]); - close(p[0]); - close(p[1]); - execl("/bin/dc", "dc", "-", (char*) 0); - execl("/usr/bin/dc", "dc", "-", (char*) 0); + if (argc > 1 && *argv[1] == '-') { + if((argv[1][1] == 'd')||(argv[1][1] == 'c')){ + yyinit(--argc, ++argv); + yyparse(); + exit(0); + } + if(argv[1][1] != 'l'){ + printf("unrecognizable argument\n"); + fflush(stdout); + exit(0); + } + argv[1] = "/usr/share/misc/lib.b"; + } + pipe(p); + if (fork()==0) { + close(1); + dup(p[1]); + close(p[0]); + close(p[1]); + yyinit(argc, argv); + yyparse(); + exit(0); + } + close(0); + dup(p[0]); + close(p[0]); + close(p[1]); + execl("/bin/dc", "dc", "-", (char*) 0); + execl("/usr/bin/dc", "dc", "-", (char*) 0); } diff --git a/src/cmd/cal.c b/src/cmd/cal.c index 0c8a96d..a4bc95b 100644 --- a/src/cmd/cal.c +++ b/src/cmd/cal.c @@ -1,208 +1,208 @@ #include #include -char dayw[] = { - " S M Tu W Th F S" +char dayw[] = { + " S M Tu W Th F S" }; -char *smon[]= { - "January", "February", "March", "April", - "May", "June", "July", "August", - "September", "October", "November", "December", +char *smon[]= { + "January", "February", "March", "April", + "May", "June", "July", "August", + "September", "October", "November", "December", }; -char string[432]; +char string[432]; main(argc, argv) char *argv[]; { - register y, i, j; - int m; + register y, i, j; + int m; - if(argc < 2) { - printf("usage: cal [month] year\n"); - exit(0); - } - if(argc == 2) - goto xlong; + if(argc < 2) { + printf("usage: cal [month] year\n"); + exit(0); + } + if(argc == 2) + goto xlong; /* - * print out just month + * print out just month */ - m = number(argv[1]); - if(m<1 || m>12) - goto badarg; - y = number(argv[2]); - if(y<1 || y>9999) - goto badarg; - printf(" %s %u\n", smon[m-1], y); - printf("%s\n", dayw); - cal(m, y, string, 24); - for(i=0; i<6*24; i+=24) - pstr(string+i, 24); - exit(0); + m = number(argv[1]); + if(m<1 || m>12) + goto badarg; + y = number(argv[2]); + if(y<1 || y>9999) + goto badarg; + printf(" %s %u\n", smon[m-1], y); + printf("%s\n", dayw); + cal(m, y, string, 24); + for(i=0; i<6*24; i+=24) + pstr(string+i, 24); + exit(0); /* - * print out complete year + * print out complete year */ xlong: - y = number(argv[1]); - if(y<1 || y>9999) - goto badarg; - printf("\n\n\n"); - printf(" %u\n", y); - printf("\n"); - for(i=0; i<12; i+=3) { - for(j=0; j<6*72; j++) - string[j] = '\0'; - printf(" %.3s", smon[i]); - printf(" %.3s", smon[i+1]); - printf(" %.3s\n", smon[i+2]); - printf("%s %s %s\n", dayw, dayw, dayw); - cal(i+1, y, string, 72); - cal(i+2, y, string+23, 72); - cal(i+3, y, string+46, 72); - for(j=0; j<6*72; j+=72) - pstr(string+j, 72); - } - printf("\n\n\n"); - exit(0); + y = number(argv[1]); + if(y<1 || y>9999) + goto badarg; + printf("\n\n\n"); + printf(" %u\n", y); + printf("\n"); + for(i=0; i<12; i+=3) { + for(j=0; j<6*72; j++) + string[j] = '\0'; + printf(" %.3s", smon[i]); + printf(" %.3s", smon[i+1]); + printf(" %.3s\n", smon[i+2]); + printf("%s %s %s\n", dayw, dayw, dayw); + cal(i+1, y, string, 72); + cal(i+2, y, string+23, 72); + cal(i+3, y, string+46, 72); + for(j=0; j<6*72; j+=72) + pstr(string+j, 72); + } + printf("\n\n\n"); + exit(0); badarg: - printf("Bad argument\n"); + printf("Bad argument\n"); } number(str) char *str; { - register n, c; - register char *s; + register n, c; + register char *s; - n = 0; - s = str; - while(c = *s++) { - if(c<'0' || c>'9') - return(0); - n = n*10 + c-'0'; - } - return(n); + n = 0; + s = str; + while(c = *s++) { + if(c<'0' || c>'9') + return(0); + n = n*10 + c-'0'; + } + return(n); } pstr(str, n) char *str; { - register i; - register char *s; + register i; + register char *s; - s = str; - i = n; - while(i--) - if(*s++ == '\0') - s[-1] = ' '; - i = n+1; - while(i--) - if(*--s != ' ') - break; - s[1] = '\0'; - printf("%s\n", str); + s = str; + i = n; + while(i--) + if(*s++ == '\0') + s[-1] = ' '; + i = n+1; + while(i--) + if(*--s != ' ') + break; + s[1] = '\0'; + printf("%s\n", str); } -char mon[] = { - 0, - 31, 29, 31, 30, - 31, 30, 31, 31, - 30, 31, 30, 31, +char mon[] = { + 0, + 31, 29, 31, 30, + 31, 30, 31, 31, + 30, 31, 30, 31, }; cal(m, y, p, w) char *p; { - register d, i; - register char *s; + register d, i; + register char *s; - s = p; - d = jan1(y); - mon[2] = 29; - mon[9] = 30; + s = p; + d = jan1(y); + mon[2] = 29; + mon[9] = 30; - switch((jan1(y+1)+7-d)%7) { + switch((jan1(y+1)+7-d)%7) { - /* - * non-leap year - */ - case 1: - mon[2] = 28; - break; + /* + * non-leap year + */ + case 1: + mon[2] = 28; + break; - /* - * 1752 - */ - default: - mon[9] = 19; - break; + /* + * 1752 + */ + default: + mon[9] = 19; + break; - /* - * leap year - */ - case 2: - ; - } - for(i=1; i 9) - *s = i/10+'0'; - s++; - *s++ = i%10+'0'; - s++; - if(++d == 7) { - d = 0; - s = p+w; - p = s; - } - } + /* + * leap year + */ + case 2: + ; + } + for(i=1; i 9) + *s = i/10+'0'; + s++; + *s++ = i%10+'0'; + s++; + if(++d == 7) { + d = 0; + s = p+w; + p = s; + } + } } /* - * return day of the week - * of jan 1 of given year + * return day of the week + * of jan 1 of given year */ jan1(yr) { - register y, d; + register y, d; /* - * normal gregorian calendar - * one extra day per four years + * normal gregorian calendar + * one extra day per four years */ - y = yr; - d = 4+y+(y+3)/4; + y = yr; + d = 4+y+(y+3)/4; /* - * julian calendar - * regular gregorian - * less three days per 400 + * julian calendar + * regular gregorian + * less three days per 400 */ - if(y > 1800) { - d -= (y-1701)/100; - d += (y-1601)/400; - } + if(y > 1800) { + d -= (y-1701)/100; + d += (y-1601)/400; + } /* - * great calendar changeover instant + * great calendar changeover instant */ - if(y > 1752) - d += 3; + if(y > 1752) + d += 3; - return(d%7); + return(d%7); } diff --git a/src/cmd/cat.c b/src/cmd/cat.c index 70e30bf..361e3b9 100644 --- a/src/cmd/cat.c +++ b/src/cmd/cat.c @@ -12,206 +12,206 @@ #include #include -/* #define OPTSIZE BUFSIZ /* define this only if not 4.2 BSD or beyond */ +/* #define OPTSIZE BUFSIZ /* define this only if not 4.2 BSD or beyond */ -int bflg, eflg, nflg, sflg, tflg, uflg, vflg; -int spaced, col, lno, inlin, ibsize, obsize; +int bflg, eflg, nflg, sflg, tflg, uflg, vflg; +int spaced, col, lno, inlin, ibsize, obsize; main(argc, argv) char **argv; { - int fflg = 0; - register FILE *fi; - register c; - int dev, ino = -1; - struct stat statb; - int retval = 0; + int fflg = 0; + register FILE *fi; + register c; + int dev, ino = -1; + struct stat statb; + int retval = 0; - lno = 1; - for( ; argc>1 && argv[1][0]=='-'; argc--,argv++) { - switch(argv[1][1]) { - case 0: - break; - case 'u': - setbuf(stdout, (char *)NULL); - uflg++; - continue; - case 'n': - nflg++; - continue; - case 'b': - bflg++; - nflg++; - continue; - case 'v': - vflg++; - continue; - case 's': - sflg++; - continue; - case 'e': - eflg++; - vflg++; - continue; - case 't': - tflg++; - vflg++; - continue; - } - break; - } - if (fstat(fileno(stdout), &statb) == 0) { - statb.st_mode &= S_IFMT; - if (statb.st_mode!=S_IFCHR && statb.st_mode!=S_IFBLK) { - dev = statb.st_dev; - ino = statb.st_ino; - } -#ifndef OPTSIZE - obsize = statb.st_blksize; + lno = 1; + for( ; argc>1 && argv[1][0]=='-'; argc--,argv++) { + switch(argv[1][1]) { + case 0: + break; + case 'u': + setbuf(stdout, (char *)NULL); + uflg++; + continue; + case 'n': + nflg++; + continue; + case 'b': + bflg++; + nflg++; + continue; + case 'v': + vflg++; + continue; + case 's': + sflg++; + continue; + case 'e': + eflg++; + vflg++; + continue; + case 't': + tflg++; + vflg++; + continue; + } + break; + } + if (fstat(fileno(stdout), &statb) == 0) { + statb.st_mode &= S_IFMT; + if (statb.st_mode!=S_IFCHR && statb.st_mode!=S_IFBLK) { + dev = statb.st_dev; + ino = statb.st_ino; + } +#ifndef OPTSIZE + obsize = statb.st_blksize; #endif - } - else - obsize = 0; - if (argc < 2) { - argc = 2; - fflg++; - } - while (--argc > 0) { - if (fflg || (*++argv)[0]=='-' && (*argv)[1]=='\0') - fi = stdin; - else { - if ((fi = fopen(*argv, "r")) == NULL) { - perror(*argv); - retval = 1; - continue; - } - } - if (fstat(fileno(fi), &statb) == 0) { - if ((statb.st_mode & S_IFMT) == S_IFREG && - statb.st_dev==dev && statb.st_ino==ino) { - fprintf(stderr, "cat: input %s is output\n", - fflg?"-": *argv); - fclose(fi); - retval = 1; - continue; - } -#ifndef OPTSIZE - ibsize = statb.st_blksize; + } + else + obsize = 0; + if (argc < 2) { + argc = 2; + fflg++; + } + while (--argc > 0) { + if (fflg || (*++argv)[0]=='-' && (*argv)[1]=='\0') + fi = stdin; + else { + if ((fi = fopen(*argv, "r")) == NULL) { + perror(*argv); + retval = 1; + continue; + } + } + if (fstat(fileno(fi), &statb) == 0) { + if ((statb.st_mode & S_IFMT) == S_IFREG && + statb.st_dev==dev && statb.st_ino==ino) { + fprintf(stderr, "cat: input %s is output\n", + fflg?"-": *argv); + fclose(fi); + retval = 1; + continue; + } +#ifndef OPTSIZE + ibsize = statb.st_blksize; #endif - } - else - ibsize = 0; - if (nflg||sflg||vflg) - copyopt(fi); - else if (uflg) { - while ((c = getc(fi)) != EOF) - putchar(c); - } else - retval |= fastcat(fileno(fi)); /* no flags specified */ - if (fi!=stdin) - fclose(fi); - else - clearerr(fi); /* reset sticky eof */ - if (ferror(stdout)) { - fprintf(stderr, "cat: output write error\n"); - retval = 1; - break; - } - } - exit(retval); + } + else + ibsize = 0; + if (nflg||sflg||vflg) + copyopt(fi); + else if (uflg) { + while ((c = getc(fi)) != EOF) + putchar(c); + } else + retval |= fastcat(fileno(fi)); /* no flags specified */ + if (fi!=stdin) + fclose(fi); + else + clearerr(fi); /* reset sticky eof */ + if (ferror(stdout)) { + fprintf(stderr, "cat: output write error\n"); + retval = 1; + break; + } + } + exit(retval); } copyopt(f) - register FILE *f; + register FILE *f; { - register int c; + register int c; top: - c = getc(f); - if (c == EOF) - return; - if (c == '\n') { - if (inlin == 0) { - if (sflg && spaced) - goto top; - spaced = 1; - } - if (nflg && bflg==0 && inlin==0) - printf("%6d\t", lno++); - if (eflg) - putchar('$'); - putchar('\n'); - inlin = 0; - goto top; - } - if (nflg && inlin == 0) - printf("%6d\t", lno++); - inlin = 1; - if (vflg) { - if (tflg==0 && c == '\t') - putchar(c); - else { - if (c > 0177) { - printf("M-"); - c &= 0177; - } - if (c < ' ') - printf("^%c", c+'@'); - else if (c == 0177) - printf("^?"); - else - putchar(c); - } - } else - putchar(c); - spaced = 0; - goto top; + c = getc(f); + if (c == EOF) + return; + if (c == '\n') { + if (inlin == 0) { + if (sflg && spaced) + goto top; + spaced = 1; + } + if (nflg && bflg==0 && inlin==0) + printf("%6d\t", lno++); + if (eflg) + putchar('$'); + putchar('\n'); + inlin = 0; + goto top; + } + if (nflg && inlin == 0) + printf("%6d\t", lno++); + inlin = 1; + if (vflg) { + if (tflg==0 && c == '\t') + putchar(c); + else { + if (c > 0177) { + printf("M-"); + c &= 0177; + } + if (c < ' ') + printf("^%c", c+'@'); + else if (c == 0177) + printf("^?"); + else + putchar(c); + } + } else + putchar(c); + spaced = 0; + goto top; } fastcat(fd) register int fd; { - register int buffsize, n, nwritten, offset; - register char *buff; - struct stat statbuff; + register int buffsize, n, nwritten, offset; + register char *buff; + struct stat statbuff; -#ifndef OPTSIZE - if (obsize) - buffsize = obsize; /* common case, use output blksize */ - else if (ibsize) - buffsize = ibsize; - else - buffsize = BUFSIZ; +#ifndef OPTSIZE + if (obsize) + buffsize = obsize; /* common case, use output blksize */ + else if (ibsize) + buffsize = ibsize; + else + buffsize = BUFSIZ; #else - buffsize = OPTSIZE; + buffsize = OPTSIZE; #endif - if ((buff = malloc(buffsize)) == NULL) { - perror("cat: no memory"); - return (1); - } + if ((buff = malloc(buffsize)) == NULL) { + perror("cat: no memory"); + return (1); + } - /* - * Note that on some systems (V7), very large writes to a pipe - * return less than the requested size of the write. - * In this case, multiple writes are required. - */ - while ((n = read(fd, buff, buffsize)) > 0) { - offset = 0; - do { - nwritten = write(fileno(stdout), &buff[offset], n); - if (nwritten <= 0) { - perror("cat: write error"); - exit(2); - } - offset += nwritten; - } while ((n -= nwritten) > 0); - } + /* + * Note that on some systems (V7), very large writes to a pipe + * return less than the requested size of the write. + * In this case, multiple writes are required. + */ + while ((n = read(fd, buff, buffsize)) > 0) { + offset = 0; + do { + nwritten = write(fileno(stdout), &buff[offset], n); + if (nwritten <= 0) { + perror("cat: write error"); + exit(2); + } + offset += nwritten; + } while ((n -= nwritten) > 0); + } - free(buff); - if (n < 0) { - perror("cat: read error"); - return (1); - } - return (0); + free(buff); + if (n < 0) { + perror("cat: read error"); + return (1); + } + return (0); } diff --git a/src/cmd/cb.c b/src/cmd/cb.c index a11944e..6d84fd0 100644 --- a/src/cmd/cb.c +++ b/src/cmd/cb.c @@ -1,380 +1,380 @@ #include -int slevel[10]; -int clevel = 0; -int spflg[20][10]; -int sind[20][10]; -int siflev[10]; -int sifflg[10]; -int iflev = 0; -int ifflg = -1; -int level = 0; -int ind[10] = { - 0,0,0,0,0,0,0,0,0,0 }; -int eflg = 0; -int paren = 0; -int pflg[10] = { - 0,0,0,0,0,0,0,0,0,0 }; -char lchar; -char pchar; -int aflg = 0; -int ct; -int stabs[20][10]; -int qflg = 0; -char *wif[] = { - "if",0}; -char *welse[] = { - "else",0}; -char *wfor[] = { - "for",0}; -char *wds[] = { - "case","default",0}; -int j = 0; -char string[200]; -char cc; -int sflg = 1; -int peek = -1; -int tabs = 0; -int lastchar; -int c; -int getstr(); +int slevel[10]; +int clevel = 0; +int spflg[20][10]; +int sind[20][10]; +int siflev[10]; +int sifflg[10]; +int iflev = 0; +int ifflg = -1; +int level = 0; +int ind[10] = { + 0,0,0,0,0,0,0,0,0,0 }; +int eflg = 0; +int paren = 0; +int pflg[10] = { + 0,0,0,0,0,0,0,0,0,0 }; +char lchar; +char pchar; +int aflg = 0; +int ct; +int stabs[20][10]; +int qflg = 0; +char *wif[] = { + "if",0}; +char *welse[] = { + "else",0}; +char *wfor[] = { + "for",0}; +char *wds[] = { + "case","default",0}; +int j = 0; +char string[200]; +char cc; +int sflg = 1; +int peek = -1; +int tabs = 0; +int lastchar; +int c; +int getstr(); putstr() { - if(j > 0){ - if(sflg != 0){ - ptabs(); - sflg = 0; - if(aflg == 1){ - aflg = 0; - if(tabs > 0)printf(" "); - } - } - string[j] = '\0'; - printf("%s",string); - j = 0; - } - else{ - if(sflg != 0){ - sflg = 0; - aflg = 0; - } - } + if(j > 0){ + if(sflg != 0){ + ptabs(); + sflg = 0; + if(aflg == 1){ + aflg = 0; + if(tabs > 0)printf(" "); + } + } + string[j] = '\0'; + printf("%s",string); + j = 0; + } + else{ + if(sflg != 0){ + sflg = 0; + aflg = 0; + } + } } main(argc, argv) int argc; char argv[]; { - while((c = getch()) != EOF){ - switch(c){ - case ' ': - case '\t': - if(lookup(welse) == 1){ - gotelse(); - if(sflg == 0 || j > 0)string[j++] = c; - putstr(); - sflg = 0; - continue; - } - if(sflg == 0 || j > 0)string[j++] = c; - continue; - case '\n': - if((eflg = lookup(welse)) == 1)gotelse(); - putstr(); - printf("\n"); - sflg = 1; - if(eflg == 1){ - pflg[level]++; - tabs++; - } - else - if(pchar == lchar) - aflg = 1; - continue; - case '{': - if(lookup(welse) == 1)gotelse(); - siflev[clevel] = iflev; - sifflg[clevel] = ifflg; - iflev = ifflg = 0; - clevel++; - if(sflg == 1 && pflg[level] != 0){ - pflg[level]--; - tabs--; - } - string[j++] = c; - putstr(); - getnl(); - putstr(); - printf("\n"); - tabs++; - sflg = 1; - if(pflg[level] > 0){ - ind[level] = 1; - level++; - slevel[level] = clevel; - } - continue; - case '}': - clevel--; - if((iflev = siflev[clevel]-1) < 0)iflev = 0; - ifflg = sifflg[clevel]; - if(pflg[level] >0 && ind[level] == 0){ - tabs -= pflg[level]; - pflg[level] = 0; - } - putstr(); - tabs--; - ptabs(); - if((peek = getch()) == ';'){ - printf("%c;",c); - peek = -1; - } - else printf("%c",c); - getnl(); - putstr(); - printf("\n"); - sflg = 1; - if(clevel < slevel[level])if(level > 0)level--; - if(ind[level] != 0){ - tabs -= pflg[level]; - pflg[level] = 0; - ind[level] = 0; - } - continue; - case '"': - case '\'': - string[j++] = c; - while((cc = getch()) != c){ - string[j++] = cc; - if(cc == '\\'){ - string[j++] = getch(); - } - if(cc == '\n'){ - putstr(); - sflg = 1; - } - } - string[j++] = cc; - if(getnl() == 1){ - lchar = cc; - peek = '\n'; - } - continue; - case ';': - string[j++] = c; - putstr(); - if(pflg[level] > 0 && ind[level] == 0){ - tabs -= pflg[level]; - pflg[level] = 0; - } - getnl(); - putstr(); - printf("\n"); - sflg = 1; - if(iflev > 0) - if(ifflg == 1){iflev--; - ifflg = 0; - } - else iflev = 0; - continue; - case '\\': - string[j++] = c; - string[j++] = getch(); - continue; - case '?': - qflg = 1; - string[j++] = c; - continue; - case ':': - string[j++] = c; - if(qflg == 1){ - qflg = 0; - continue; - } - if(lookup(wds) == 0){ - sflg = 0; - putstr(); - } - else{ - tabs--; - putstr(); - tabs++; - } - if((peek = getch()) == ';'){ - printf(";"); - peek = -1; - } - getnl(); - putstr(); - printf("\n"); - sflg = 1; - continue; - case '/': - string[j++] = c; - if((peek = getch()) != '*')continue; - string[j++] = peek; - peek = -1; - comment(); - continue; - case ')': - paren--; - string[j++] = c; - putstr(); - if(getnl() == 1){ - peek = '\n'; - if(paren != 0)aflg = 1; - else if(tabs > 0){ - pflg[level]++; - tabs++; - ind[level] = 0; - } - } - continue; - case '#': - string[j++] = c; - while((cc = getch()) != '\n')string[j++] = cc; - string[j++] = cc; - sflg = 0; - putstr(); - sflg = 1; - continue; - case '(': - string[j++] = c; - paren++; - if(lookup(wfor) == 1){ - while((c = getstr()) != ';'); - ct=0; + while((c = getch()) != EOF){ + switch(c){ + case ' ': + case '\t': + if(lookup(welse) == 1){ + gotelse(); + if(sflg == 0 || j > 0)string[j++] = c; + putstr(); + sflg = 0; + continue; + } + if(sflg == 0 || j > 0)string[j++] = c; + continue; + case '\n': + if((eflg = lookup(welse)) == 1)gotelse(); + putstr(); + printf("\n"); + sflg = 1; + if(eflg == 1){ + pflg[level]++; + tabs++; + } + else + if(pchar == lchar) + aflg = 1; + continue; + case '{': + if(lookup(welse) == 1)gotelse(); + siflev[clevel] = iflev; + sifflg[clevel] = ifflg; + iflev = ifflg = 0; + clevel++; + if(sflg == 1 && pflg[level] != 0){ + pflg[level]--; + tabs--; + } + string[j++] = c; + putstr(); + getnl(); + putstr(); + printf("\n"); + tabs++; + sflg = 1; + if(pflg[level] > 0){ + ind[level] = 1; + level++; + slevel[level] = clevel; + } + continue; + case '}': + clevel--; + if((iflev = siflev[clevel]-1) < 0)iflev = 0; + ifflg = sifflg[clevel]; + if(pflg[level] >0 && ind[level] == 0){ + tabs -= pflg[level]; + pflg[level] = 0; + } + putstr(); + tabs--; + ptabs(); + if((peek = getch()) == ';'){ + printf("%c;",c); + peek = -1; + } + else printf("%c",c); + getnl(); + putstr(); + printf("\n"); + sflg = 1; + if(clevel < slevel[level])if(level > 0)level--; + if(ind[level] != 0){ + tabs -= pflg[level]; + pflg[level] = 0; + ind[level] = 0; + } + continue; + case '"': + case '\'': + string[j++] = c; + while((cc = getch()) != c){ + string[j++] = cc; + if(cc == '\\'){ + string[j++] = getch(); + } + if(cc == '\n'){ + putstr(); + sflg = 1; + } + } + string[j++] = cc; + if(getnl() == 1){ + lchar = cc; + peek = '\n'; + } + continue; + case ';': + string[j++] = c; + putstr(); + if(pflg[level] > 0 && ind[level] == 0){ + tabs -= pflg[level]; + pflg[level] = 0; + } + getnl(); + putstr(); + printf("\n"); + sflg = 1; + if(iflev > 0) + if(ifflg == 1){iflev--; + ifflg = 0; + } + else iflev = 0; + continue; + case '\\': + string[j++] = c; + string[j++] = getch(); + continue; + case '?': + qflg = 1; + string[j++] = c; + continue; + case ':': + string[j++] = c; + if(qflg == 1){ + qflg = 0; + continue; + } + if(lookup(wds) == 0){ + sflg = 0; + putstr(); + } + else{ + tabs--; + putstr(); + tabs++; + } + if((peek = getch()) == ';'){ + printf(";"); + peek = -1; + } + getnl(); + putstr(); + printf("\n"); + sflg = 1; + continue; + case '/': + string[j++] = c; + if((peek = getch()) != '*')continue; + string[j++] = peek; + peek = -1; + comment(); + continue; + case ')': + paren--; + string[j++] = c; + putstr(); + if(getnl() == 1){ + peek = '\n'; + if(paren != 0)aflg = 1; + else if(tabs > 0){ + pflg[level]++; + tabs++; + ind[level] = 0; + } + } + continue; + case '#': + string[j++] = c; + while((cc = getch()) != '\n')string[j++] = cc; + string[j++] = cc; + sflg = 0; + putstr(); + sflg = 1; + continue; + case '(': + string[j++] = c; + paren++; + if(lookup(wfor) == 1){ + while((c = getstr()) != ';'); + ct=0; cont: - while((c = getstr()) != ')'){ - if(c == '(') ct++; - } - if(ct != 0){ - ct--; - goto cont; - } - paren--; - putstr(); - if(getnl() == 1){ - peek = '\n'; - pflg[level]++; - tabs++; - ind[level] = 0; - } - continue; - } - if(lookup(wif) == 1){ - putstr(); - stabs[clevel][iflev] = tabs; - spflg[clevel][iflev] = pflg[level]; - sind[clevel][iflev] = ind[level]; - iflev++; - ifflg = 1; - } - continue; - default: - string[j++] = c; - if(c != ',')lchar = c; - } - } + while((c = getstr()) != ')'){ + if(c == '(') ct++; + } + if(ct != 0){ + ct--; + goto cont; + } + paren--; + putstr(); + if(getnl() == 1){ + peek = '\n'; + pflg[level]++; + tabs++; + ind[level] = 0; + } + continue; + } + if(lookup(wif) == 1){ + putstr(); + stabs[clevel][iflev] = tabs; + spflg[clevel][iflev] = pflg[level]; + sind[clevel][iflev] = ind[level]; + iflev++; + ifflg = 1; + } + continue; + default: + string[j++] = c; + if(c != ',')lchar = c; + } + } } ptabs() { - int i; - for(i=0; i < tabs; i++)printf("\t"); + int i; + for(i=0; i < tabs; i++)printf("\t"); } getch() { - if(peek < 0 && lastchar != ' ' && lastchar != '\t')pchar = lastchar; - lastchar = (peek<0) ? getc(stdin):peek; - peek = -1; - return(lastchar); + if(peek < 0 && lastchar != ' ' && lastchar != '\t')pchar = lastchar; + lastchar = (peek<0) ? getc(stdin):peek; + peek = -1; + return(lastchar); } lookup(tab) char *tab[]; { - char r; - int l,kk,k,i; - if(j < 1)return(0); - kk=0; - while(string[kk] == ' ')kk++; - for(i=0; tab[i] != 0; i++){ - l=0; - for(k=kk;(r = tab[i][l++]) == string[k] && r != '\0';k++); - if(r == '\0' && (string[k] < 'a' || string[k] > 'z' || k >= j))return(1); - } - return(0); + char r; + int l,kk,k,i; + if(j < 1)return(0); + kk=0; + while(string[kk] == ' ')kk++; + for(i=0; tab[i] != 0; i++){ + l=0; + for(k=kk;(r = tab[i][l++]) == string[k] && r != '\0';k++); + if(r == '\0' && (string[k] < 'a' || string[k] > 'z' || k >= j))return(1); + } + return(0); } getstr() { - char ch; + char ch; beg: - if((ch = string[j++] = getch()) == '\\'){ - string[j++] = getch(); - goto beg; - } - if(ch == '\'' || ch == '"'){ - while((cc = string[j++] = getch()) != ch)if(cc == '\\')string[j++] = getch(); - goto beg; - } - if(ch == '\n'){ - putstr(); - aflg = 1; - goto beg; - } - else return(ch); + if((ch = string[j++] = getch()) == '\\'){ + string[j++] = getch(); + goto beg; + } + if(ch == '\'' || ch == '"'){ + while((cc = string[j++] = getch()) != ch)if(cc == '\\')string[j++] = getch(); + goto beg; + } + if(ch == '\n'){ + putstr(); + aflg = 1; + goto beg; + } + else return(ch); } gotelse() { - tabs = stabs[clevel][iflev]; - pflg[level] = spflg[clevel][iflev]; - ind[level] = sind[clevel][iflev]; - ifflg = 1; + tabs = stabs[clevel][iflev]; + pflg[level] = spflg[clevel][iflev]; + ind[level] = sind[clevel][iflev]; + ifflg = 1; } getnl() { - while((peek = getch()) == '\t' || peek == ' '){ - string[j++] = peek; - peek = -1; - } - if((peek = getch()) == '/'){ - peek = -1; - if((peek = getch()) == '*'){ - string[j++] = '/'; - string[j++] = '*'; - peek = -1; - comment(); - } - else string[j++] = '/'; - } - if((peek = getch()) == '\n'){ - peek = -1; - return(1); - } - return(0); + while((peek = getch()) == '\t' || peek == ' '){ + string[j++] = peek; + peek = -1; + } + if((peek = getch()) == '/'){ + peek = -1; + if((peek = getch()) == '*'){ + string[j++] = '/'; + string[j++] = '*'; + peek = -1; + comment(); + } + else string[j++] = '/'; + } + if((peek = getch()) == '\n'){ + peek = -1; + return(1); + } + return(0); } comment() { - int i = j; + int i = j; - while ((c = getch()) != EOF) { - string[j++] = c; - switch(c) { - case '/': - if (j > i + 1 && string[j-2] == '*') - return; - break; - case '\n': - putstr(); - sflg = 1; - break; - } - } + while ((c = getch()) != EOF) { + string[j++] = c; + switch(c) { + case '/': + if (j > i + 1 && string[j-2] == '*') + return; + break; + case '\n': + putstr(); + sflg = 1; + break; + } + } } diff --git a/src/cmd/cc/.gitignore b/src/cmd/cc/.gitignore deleted file mode 100644 index 46c1d61..0000000 --- a/src/cmd/cc/.gitignore +++ /dev/null @@ -1 +0,0 @@ -cc diff --git a/src/cmd/cc/Makefile b/src/cmd/cc/Makefile index b54ffcf..297ae74 100644 --- a/src/cmd/cc/Makefile +++ b/src/cmd/cc/Makefile @@ -4,13 +4,13 @@ include $(TOPSRC)/target.mk OBJS = cc.o -CFLAGS += -Werror -Wall +CFLAGS += -Werror -Wall -DGCC_COMPAT CFLAGS += -DVERSSTR=\"1.0\" \ -DSTDINC=\"/include\" \ -DLIBDIR=\"/lib\" \ - -DLIBEXECDIR=\"/libexec\" \ + -DLIBEXECDIR=\"/libexec\" -DCRT0FILE=\"/lib/crt0.o\" \ - -DCRT0FILE_PROFILE=\"/lib/mcrt0.o\" + -DCRT0FILE_PROFILE=\"/lib/gcrt0.o\" all: cc @@ -25,5 +25,3 @@ clean: install: all install cc $(DESTDIR)/bin/ - install cc $(DESTDIR)/bin/scc - install cc $(DESTDIR)/bin/lcc diff --git a/src/cmd/cc/cc.c b/src/cmd/cc/cc.c index 1c30ede..b0ee85d 100644 --- a/src/cmd/cc/cc.c +++ b/src/cmd/cc/cc.c @@ -63,6 +63,12 @@ # include #endif +#ifdef WIN32 +#include +#include +#include +#endif + #define MKS(x) _MKS(x) #define _MKS(x) #x @@ -102,8 +108,8 @@ #define MAXLIB 1000 #define MAXAV 1000 #define MAXOPT 100 -char *tmp_as; -char *tmp_cpp; +char *tmp3; +char *tmp4; char *outfile, *ermfile; char *Bprefix(char *); char *copy(char *, int); @@ -118,6 +124,10 @@ void dexit(int); void idexit(int); char *gettmp(void); void *ccmalloc(int size); +#ifdef WIN32 +char *win32pathsubst(char *); +char *win32commandline(char *, char *[]); +#endif char *av[MAXAV]; char *clist[MAXFIL]; char *olist[MAXFIL]; @@ -131,7 +141,6 @@ char *mlist[100]; char *flist[100]; char *wlist[100]; char *idirafter; -char *progname; int nm; int nf; int nw; @@ -169,15 +178,8 @@ char *as = ASSEMBLER; char *ld = LINKER; char *Bflag; -enum { - MODE_LCC, - MODE_PCC, - MODE_SMALLC, - MODE_SMALLERC, -} mode; - /* common cpp predefines */ -char *cppadd[] = { "-D__LCC__", "-D__unix__", "-D__BSD__", "-D__RETROBSD__", NULL }; +char *cppadd[] = { "-D__unix__", "-D__BSD__", "-D__RETROBSD__", NULL }; #ifdef __mips__ # define CPPMDADD { "-D__mips__", NULL, } @@ -229,7 +231,7 @@ char *libclibs_profile[] = LIBCLIBS_PROFILE; char *libclibs_profile[] = { "-lc_p", NULL }; #endif #ifndef STARTLABEL -#define STARTLABEL "_start" +#define STARTLABEL "__start" #endif char *incdir = STDINC; char *libdir = LIBDIR; @@ -358,7 +360,7 @@ strlcat(char *dst, const char *src, size_t siz) void usage() { - printf("Usage: %s [options] file...\n", progname); + printf("Usage: cc [options] file...\n"); printf("Options:\n"); printf(" -h Display this information\n"); printf(" --version Display compiler version information\n"); @@ -369,29 +371,24 @@ usage() printf(" -o Place the output into \n"); printf(" -O, -O0 Enable, disable optimization\n"); printf(" -g Create debug output\n"); - printf(" -v Display the programs invoked by the compiler\n"); - if (mode == MODE_LCC || mode == MODE_PCC) { printf(" -k Generate position-independent code\n"); + printf(" -v Display the programs invoked by the compiler\n"); printf(" -Wall Enable gcc-compatible warnings\n"); printf(" -WW Enable all warnings\n"); printf(" -p, -pg Generate profiled code\n"); printf(" -r Generate relocatable code\n"); - } printf(" -t Use traditional preprocessor syntax\n"); printf(" -C