ND100 emulator - FreeBSD
ND100 emulator - FreeBSD
back to main nd100em page.
History
2021-11-15: I re-created this page on my self-hosted web server.
2016-10-18: Bitraf - open source night - nd100em v0.2.4 - after fixing the Makefile, I can compile
tingo@kg-core1$ make gcc -Wall -O3 -pg -I/usr/local/include -L/usr/local/lib -c nd100em.c gcc -Wall -O3 -pg -I/usr/local/include -L/usr/local/lib -c nd100lib.c nd100lib.c: In function 'start_threads': nd100lib.c:548: warning: cast from pointer to integer of different size nd100lib.c:552: warning: cast from pointer to integer of different size nd100lib.c:556: warning: cast from pointer to integer of different size nd100lib.c:560: warning: cast from pointer to integer of different size nd100lib.c:564: warning: cast from pointer to integer of different size nd100lib.c:568: warning: cast from pointer to integer of different size nd100lib.c:579: warning: cast from pointer to integer of different size nd100lib.c:583: warning: cast from pointer to integer of different size nd100lib.c: In function 'stop_threads': nd100lib.c:588: warning: cast from pointer to integer of different size nd100lib.c:592: warning: cast from pointer to integer of different size gcc -Wall -O3 -pg -I/usr/local/include -L/usr/local/lib -c cpu.c cpu.c: In function 'cpurun': cpu.c:3648: warning: suggest explicit braces to avoid ambiguous 'else' cpu.c:3637: warning: unused variable 'disasm_str' cpu.c: In function 'mopc_cmd': cpu.c:3110: warning: 'val' may be used uninitialized in this function cpu.c: In function 'New_GetEffectiveAddr': cpu.c:1958: warning: 'eff_addr' may be used uninitialized in this function cpu.c: In function 'GetEffectiveAddr': cpu.c:1916: warning: 'res' may be used uninitialized in this function gcc -Wall -O3 -pg -I/usr/local/include -L/usr/local/lib -c rtc.c gcc -Wall -O3 -pg -I/usr/local/include -L/usr/local/lib -c mon.c gcc -Wall -O3 -pg -I/usr/local/include -L/usr/local/lib -c decode.c gcc -Wall -O3 -pg -I/usr/local/include -L/usr/local/lib -c float.c float.c: In function 'pow2l': float.c:53: warning: 'r' is used uninitialized in this function float.c: In function 'ndmant_to_ld': float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c: In function 'ld_to_ndmant': float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c: In function 'DoDNZ': float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c: In function 'DoNLZ': float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c: In function 'NDFloat_Sub': float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c: In function 'NDFloat_Mul': float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c: In function 'NDFloat_Div': float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here gcc -Wall -O3 -pg -I/usr/local/include -L/usr/local/lib -c floppy.c floppy.c: In function 'imd_sectorread': floppy.c:126: warning: unused variable 'res' floppy.c:241: warning: control reaches end of non-void function floppy.c:127: warning: 'secsize' may be used uninitialized in this function floppy.c:127: warning: 'isecsize' may be used uninitialized in this function floppy.c:127: warning: 'isecs' may be used uninitialized in this function floppy.c:127: warning: 'ihead' may be used uninitialized in this function floppy.c:127: warning: 'icyl' may be used uninitialized in this function floppy.c:127: warning: 'imod' may be used uninitialized in this function gcc -Wall -O3 -pg -I/usr/local/include -L/usr/local/lib -c io.c io.c: In function 'console_socket_in': io.c:850: warning: comparison is always false due to limited range of data type gcc -Wall -O3 -pg -I/usr/local/include -L/usr/local/lib -c trace.c trace.c: In function 'trace_instr': trace.c:123: warning: unused variable 'disasm_str2' trace.c: In function 'disasm_dump': trace.c:304: warning: comparison is always true due to limited range of data type trace.c:304: warning: suggest parentheses around comparison in operand of & trace.c:306: warning: comparison is always true due to limited range of data type trace.c:306: warning: suggest parentheses around comparison in operand of & trace.c:310: warning: comparison is always true due to limited range of data type trace.c:310: warning: suggest parentheses around comparison in operand of & trace.c:312: warning: comparison is always true due to limited range of data type trace.c:312: warning: suggest parentheses around comparison in operand of & trace.c: In function 'trace_instr': trace.c:132: warning: 'opcode' is used uninitialized in this function gcc -Wall -O3 -pg -I/usr/local/include -L/usr/local/lib -pthread nd100em.o nd100lib.o cpu.o rtc.o mon.o decode.o float.o floppy.o io.o trace.o -lconfig -lm -o nd100em
But it core dumps when I run it:
tingo@kg-core1$ ./nd100em Segmentation fault (core dumped)
gdb says
tingo@kg-core1$ gdb ./nd100em ./nd100em.core GNU gdb 6.1.1 [FreeBSD] Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "amd64-marcel-freebsd"...(no debugging symbols found)... Core was generated by `nd100em'. Program terminated with signal 11, Segmentation fault. Reading symbols from /usr/local/lib/libconfig.so.9...(no debugging symbols found)...done. Loaded symbols for /usr/local/lib/libconfig.so.9 Reading symbols from /lib/libm.so.5...(no debugging symbols found)...done. Loaded symbols for /lib/libm.so.5 Reading symbols from /lib/libc.so.7...(no debugging symbols found)...done. Loaded symbols for /lib/libc.so.7 Reading symbols from /libexec/ld-elf.so.1...(no debugging symbols found)...done. Loaded symbols for /libexec/ld-elf.so.1 #0 0x00000000004410a9 in xlocale_retain () [New Thread 801407400 (LWP 101486/nd100em)] (gdb) bt #0 0x00000000004410a9 in xlocale_retain () #1 0x000000000044139c in dupcomponent () #2 0x0000000000441542 in newlocale () #3 0x00000008008908c7 in __config_locale_override () from /usr/local/lib/libconfig.so.9 #4 0x0000000800890995 in __config_read () from /usr/local/lib/libconfig.so.9 #5 0x0000000800890ae0 in config_read_file () from /usr/local/lib/libconfig.so.9 #6 0x0000000000409c44 in nd100emconf () #7 0x0000000000409372 in main () (gdb)
hmmm.
2016-09-10: try compiling nd100em v0.2.4 on FreeBSD: Nice to see that nd100em is still being developed. This evening I tried compiling v0.2.4 on FreeBSD. I understand that libconfig is needed now. My old testmachine doesn't have ports, so I just tried on my workstation instead:
tingo@kg-core1$ uname -a FreeBSD kg-core1.kg4.no 9.3-STABLE FreeBSD 9.3-STABLE #3 r304838: Fri Aug 26 12:11:25 CEST 2016 root@kg-core1.kg4.no:/usr/obj/usr/src/sys/GENERIC amd64
I installed libconfig from ports:
root@kg-core1# pv libconfi* [Reading data from pkg(8) ... - 858 packages found - done] libconfig-1.4.9_1 = up-to-date with port
Next I modified CFLAGS in Makefile:
CFLAGS = -Wall -O3 -pg -I/usr/local/include
the '-I/usr/local/include' is so that it will find libconfig.h. FreeBSD has this version of gcc
tingo@kg-core1$ gcc --version gcc (GCC) 4.2.1 20070831 patched [FreeBSD] Copyright (C) 2007 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
and it doesn't recognize '-fno-aggressive-loop-optimizations'. Anyway, it still fails:
tingo@kg-core1$ make clean rm -f cpu.o mon.o trace.o decode.o float.o floppy.o io.o rtc.o nd100lib.o nd100em.o nd100em core tingo@kg-core1$ make gcc -Wall -O3 -pg -I/usr/local/include -c nd100em.c gcc -Wall -O3 -pg -I/usr/local/include -c nd100lib.c nd100lib.c: In function 'start_threads': nd100lib.c:548: warning: cast from pointer to integer of different size nd100lib.c:552: warning: cast from pointer to integer of different size nd100lib.c:556: warning: cast from pointer to integer of different size nd100lib.c:560: warning: cast from pointer to integer of different size nd100lib.c:564: warning: cast from pointer to integer of different size nd100lib.c:568: warning: cast from pointer to integer of different size nd100lib.c:579: warning: cast from pointer to integer of different size nd100lib.c:583: warning: cast from pointer to integer of different size nd100lib.c: In function 'stop_threads': nd100lib.c:588: warning: cast from pointer to integer of different size nd100lib.c:592: warning: cast from pointer to integer of different size gcc -Wall -O3 -pg -I/usr/local/include -c cpu.c cpu.c: In function 'cpurun': cpu.c:3648: warning: suggest explicit braces to avoid ambiguous 'else' cpu.c:3637: warning: unused variable 'disasm_str' cpu.c: In function 'mopc_cmd': cpu.c:3110: warning: 'val' may be used uninitialized in this function cpu.c: In function 'New_GetEffectiveAddr': cpu.c:1958: warning: 'eff_addr' may be used uninitialized in this function cpu.c: In function 'GetEffectiveAddr': cpu.c:1916: warning: 'res' may be used uninitialized in this function gcc -Wall -O3 -pg -I/usr/local/include -c rtc.c gcc -Wall -O3 -pg -I/usr/local/include -c mon.c gcc -Wall -O3 -pg -I/usr/local/include -c decode.c gcc -Wall -O3 -pg -I/usr/local/include -c float.c float.c: In function 'pow2l': float.c:53: warning: 'r' is used uninitialized in this function float.c: In function 'ndmant_to_ld': float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c: In function 'ld_to_ndmant': float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c: In function 'DoDNZ': float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c: In function 'DoNLZ': float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c: In function 'NDFloat_Sub': float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c: In function 'NDFloat_Mul': float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c: In function 'NDFloat_Div': float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here float.c:53: warning: 'r' is used uninitialized in this function float.c:48: note: 'r' was declared here gcc -Wall -O3 -pg -I/usr/local/include -c floppy.c floppy.c:26:20: error: floppy.h: No such file or directory floppy.c: In function 'imd_sectorread': floppy.c:126: warning: unused variable 'res' floppy.c:241: warning: control reaches end of non-void function *** [floppy.o] Error code 1 Stop in /zs/tingo/work/nd100em/nd100em-0.2.4.
FreeBSD doesn't have floppy.h and I'm not sure how t fix that.
older history:
2011-07-12: testing nd100em v0.2.1: Testing:
tingo@kg-v3$ uname -a FreeBSD kg-v3.kg4.no 8.2-RELEASE FreeBSD 8.2-RELEASE #0: Fri Feb 18 02:24:46 UTC 2011 root@almeida.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC i386 tingo@kg-v3$ ./nd100em PAGING TEST PROGRAM (PAGING) PROGRAM NUMBER: 203098B DATE ISSUED : 15 JANUARY 1982 THE COMMAND HELP GIVES YOU A LIST OF THE COMMANDS >run RUN MODE: INFINITE LOOP; ABORT AFTER 10 ERRORS; PAGING AS MEMORY (ADDRESS & DATA BITS) === END OF TEST === PAGING CONTROL REGISTERS, ALL LEVELS === END OF TEST === PGU/WIP BITS FOR ALL PITS & ALL ENTRIES === END OF TEST === ALTERNATIVE PIT USAGE ON ALL LEVELS === END OF TEST === RING VIOLATION INTERRUPT === END OF TEST === PAGE FAULT INTERRUPT === END OF TEST === READ PROTECT VIOLATION INTERRUPT === END OF TEST === WRITE PROTECT VIOLATION INTERRUPT === END OF TEST === === THE TESTS ARE NOW LOOPING === Number of instructions run: 32145755.000000, time used: 13.177739 usertime: 13.103892 systemtime: 0.073847 Current cpu cycle time is:0.409937 microsecs
and on 64-bit:
tingo@kg-v2$ uname -a FreeBSD kg-v2.kg4.no 8.1-STABLE FreeBSD 8.1-STABLE #3: Thu Sep 16 22:18:48 CEST 2010 root@kg-v2.kg4.no:/usr/obj/usr/src/sys/GENERIC amd64 tingo@kg-v2$ ./nd100em PAGING TEST PROGRAM (PAGING) PROGRAM NUMBER: 203098B DATE ISSUED : 15 JANUARY 1982 THE COMMAND HELP GIVES YOU A LIST OF THE COMMANDS >run RUN MODE: INFINITE LOOP; ABORT AFTER 10 ERRORS; PAGING AS MEMORY (ADDRESS & DATA BITS) === END OF TEST === PAGING CONTROL REGISTERS, ALL LEVELS === END OF TEST === PGU/WIP BITS FOR ALL PITS & ALL ENTRIES === END OF TEST === ALTERNATIVE PIT USAGE ON ALL LEVELS === END OF TEST === RING VIOLATION INTERRUPT === END OF TEST === PAGE FAULT INTERRUPT === END OF TEST === READ PROTECT VIOLATION INTERRUPT === END OF TEST === WRITE PROTECT VIOLATION INTERRUPT === END OF TEST === === THE TESTS ARE NOW LOOPING === Number of instructions run: 29138472.000000, time used: 10.302720 usertime: 10.280210 systemtime: 0.022511 Current cpu cycle time is:0.353578 microsecs
Very well done! Now I also have to sleep.
2011-06-18: more findings / testing of nd100em: I just found out that the emulator uses usleep(3) in a few places:
tingo@kg-v3$ grep usleep *.c cpu.c: usleep(10000); io.c: usleep(10); /* Sleep 10us for IOX timeout time simulation */ io.c: usleep(20000); /* so not to busy loop FIXME:: this routine should be changed to react to event instead */ io.c: usleep(20000); /* so not to busy loop FIXME:: this routine should be changed to react to event instead */ io.c: usleep(20000); /* give time for other threads to react */
In FreeBSD, using usleep(3) in combination with threads is not a good match. From the usleep(3) man page[1]:
"System activity may lengthen the sleep by an indeterminate amount."
and
"Consequently, in this implementation, sleeping has no effect on the state of process timers, and there is no special handling for SIGALRM."
I tried commenting out the usleep in cpu.c and those in io.c, but it didn't change anything, the emulator still core dumps:
tingo@kg-v3$ ./nd100em PAGING TEST PROGRAM (PAGING) PROGRAM NUMBER: 203098B DATE ISSUED : 15 JANUARY 1982 THE COMMAND HELP GIVES YOU A LIST OF THE COMMANDS >Segmentation fault (core dumped)
I fired up gdb (not that I am very familiar with it):
tingo@kg-v3$ gdb ./nd100em ./nd100em.core GNU gdb 6.1.1 [FreeBSD] Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-marcel-freebsd"...(no debugging symbols found)... Core was generated by `nd100em'. Program terminated with signal 11, Segmentation fault. Reading symbols from /lib/libm.so.5...(no debugging symbols found)...done. Loaded symbols for /lib/libm.so.5 Reading symbols from /lib/libthr.so.3...(no debugging symbols found)...done. Loaded symbols for /lib/libthr.so.3 Reading symbols from /lib/libc.so.7...(no debugging symbols found)...done. Loaded symbols for /lib/libc.so.7 Reading symbols from /libexec/ld-elf.so.1...(no debugging symbols found)...done. Loaded symbols for /libexec/ld-elf.so.1 #0 0x28148869 in free () from /lib/libc.so.7 [New Thread 28278140 (LWP 100112)] [New Thread 2823eb00 (LWP 100111)] [New Thread 2823ec40 (LWP 100110)] [New Thread 2823ed80 (LWP 100109)] [New Thread 2823eec0 (LWP 100108)] [New Thread 2823f140 (LWP 100098)] [New Thread 28201140 (LWP 100070)] a bactrace (bt) says this: #0 0x28148869 in free () from /lib/libc.so.7 #1 0x0805c7a9 in RemIdentChain () #2 0x08057ae9 in DoIDENT () #3 0x080523ce in do_op () #4 0x0805c392 in cpurun () #5 0x0805c667 in cpu_thread () #6 0x280c873f in pthread_getprio () from /lib/libthr.so.3 #7 0x00000000 in ?? ()
all for now.
2011-06-05: testing nd100em. Oh, it does that here as well, but I just thought that it was because I have no "test" image to start from (I'm currently running from the default directory, with the default nd100em.conf):
tingo@kg-v2$ uname -a FreeBSD kg-v2.kg4.no 8.1-STABLE FreeBSD 8.1-STABLE #3: Thu Sep 16 22:18:48 CEST 2010 root@kg-v2.kg4.no:/usr/obj/usr/src/sys/GENERIC amd64 tingo@kg-v2$ ./nd100em Segmentation fault (core dumped)
But it also core dumps if I run it on a 32-bit machine:
tingo@kg-v3$ uname -a FreeBSD kg-v3.kg4.no 8.2-RELEASE FreeBSD 8.2-RELEASE #0: Fri Feb 18 02:24:46 UTC 2011 root@almeida.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC i386 tingo@kg-v3$ ./nd100em Segmentation fault (core dumped)
that's it. It also seems to use a hardcoded filename of "test.bpun".
OK, testing on my 64-bit machine /using instruction-b.bpun as test.bpun):
tingo@kg-v2$ ./nd100em --------------------------- -- INSTRUCTION VERIFY -- --------------------------- PROGRAM NUMBER: 204384B PROGRAM NAME : INSTRUCTION-B DATE ISSUED : 83.11.01 Segmentation fault (core dumped)
Well, let's try the 32-bit machine then:
tingo@kg-v3$ uname -a FreeBSD kg-v3.kg4.no 8.2-RELEASE FreeBSD 8.2-RELEASE #0: Fri Feb 18 02:24:46 UTC 2011 root@almeida.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC i386 tingo@kg-v3$ ./nd100em --------------------------- -- INSTRUCTION VERIFY -- --------------------------- PROGRAM NUMBER: 204384B PROGRAM NAME : INSTRUCTION-B DATE ISSUED : 83.11.01 Segmentation fault (core dumped)
Ok, more testing and bug-hunting is needed I see.
2011-05-24: compiling nd100em v0.2.0 under FreeBSD.
tingo@kg-v2$ uname -a FreeBSD kg-v2.kg4.no 8.1-STABLE FreeBSD 8.1-STABLE #3: Thu Sep 16 22:18:48 CEST 2010 root@kg-v2.kg4.no:/usr/obj/usr/src/sys/GENERIC amd64
try
tingo@kg-v2$ gmake gcc -c nd100em.c gcc -c cpu.c gcc -c mon.c gcc -c decode.c gcc -c float.c In file included from float.c:26: nd100.h:196: error: expected specifier-qualifier-list before 'pthread_t' gmake: *** [float.o] Error 1
Hmm, let's try 'gmake clean' and then FreeBSD native make:
tingo@kg-v2$ make gcc -c nd100em.c gcc -c cpu.c gcc -c mon.c gcc -c decode.c gcc -c float.c In file included from float.c:26: nd100.h:196: error: expected specifier-qualifier-list before 'pthread_t' *** Error code 1 Stop in /usr/home/tingo/work/nd100em/nd100em.
Ok, fixed by adding
#include <pthread.h>
to float.c Now it compiles with a warning: with gmake:
tingo@kg-v2$ gmake gcc -c nd100em.c gcc -c cpu.c gcc -c mon.c gcc -c decode.c gcc -c float.c gcc -c floppy.c gcc -c io.c io.c: In function 'console_socket_in': io.c:599: warning: comparison is always false due to limited range of data type gcc -c trace.c gcc -pthread -lm nd100em.o cpu.o rtc.o mon.o decode.o float.o floppy.o io.o trace.o -o nd100em
and with make:
tingo@kg-v2$ make gcc -c nd100em.c gcc -c cpu.c gcc -c mon.c gcc -c decode.c gcc -c float.c gcc -c floppy.c gcc -c io.c io.c: In function 'console_socket_in': io.c:599: warning: comparison is always false due to limited range of data type gcc -c trace.c gcc -pthread -lm nd100em.o cpu.o rtc.o mon.o decode.o float.o floppy.o io.o trace.o -o nd100em
need a few BPUN files for testing.