GithubHelp home page GithubHelp logo

outofmbufs / python-pdp11-emulator Goto Github PK

View Code? Open in Web Editor NEW
5.0 5.0 1.0 535 KB

Yet another PDP-11 emulator, written in Python. Can boot/run V7 Unix!

License: MIT License

Python 100.00%
pdp-11 pdp11

python-pdp11-emulator's People

Contributors

folkertvanheusden avatar outofmbufs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

python-pdp11-emulator's Issues

python & signmask

In RORB (and others):

     cpu.psw_n = val & signmask
    cpu.psw_z = (val == 0)
     cpu.psw_v = cpu.psw_n ^ cpu.psw_c

Now val is 0...255. Signmask is 128. So psw_n can be 128 and 0.
This makes psw_v into 0, 1, 128 or 129.

_brconds (in branches.py) for v-flag is:

    0o102000: lambda n, z, v, c: not v,            # BVC
    0o102400: lambda n, z, v, c: v,                # BVS

I think you shold either make the lambda in: "not (v & 1)" and "(v & 1)" or the asignment of the n-flag into e.g.:
cpu.psw_n = 1 if val & signmask else 0

problem with console i/o: "NoneType" written to it

Hi,

Trying to load XXDP modules into the emulator to do extra testing of its emulation.
For that I implemented a tape image loader which should be able to read e.g. a .BIC file from the XXDP set.
The loading at itself works fine but as soon as the emulated code wants to write a character to the console, an PDPTraps.AddressError is triggered. I dug a bit into it and klregs from KL11 in kl11.py is called with address 017566 and a value of None, yet the following is logged:

pdp11.DEBUG[004933]: Byte write to 0o17566 value=13
pdp11.DEBUG[004933]: TRAP: AddressError(vector=0o4):

BKTCB0.BIC.zip
tapeloader.py.zip

Stack trace:

* Stack trace, innermost first
* 
** byteme at /home/folkert/Projects/PDP-11/json/python-pdp11-emulator/mmio.py:215
*** ioaddr: 8054
*** value: None
*** opsize: 2
*** iofunc: <bound method KL11.klregs of <kl11.KL11 object at 0x75ad6c350d90>>
*** self: <mmio.MMIO object at 0x75ad6c346450>

** wordRW at /home/folkert/Projects/PDP-11/json/python-pdp11-emulator/mmio.py:280
*** self: <mmio.MMIO object at 0x75ad6c346450>
*** ioaddr: 8054
*** value: None        <=------- here value is suddenly None

** byteme at /home/folkert/Projects/PDP-11/json/python-pdp11-emulator/mmio.py:220
*** ioaddr: 8054
*** value: 13
*** opsize: 1
*** iofunc: <bound method KL11.klregs of <kl11.KL11 object at 0x75ad6c350d90>>
*** self: <mmio.MMIO object at 0x75ad6c346450>

** byteRW at /home/folkert/Projects/PDP-11/json/python-pdp11-emulator/mmio.py:290
*** self: <mmio.MMIO object at 0x75ad6c346450>
*** ioaddr: 8054
*** value: 13

** byteRW at /home/folkert/Projects/PDP-11/json/python-pdp11-emulator/mmu.py:559
*** self: <mmu.MemoryMgmt object at 0x75ad6cf24d50>
*** vaddr: 65398
*** value: 13
*** mode: None
*** space: 1
*** pa: 65398
*** odd: 0

** operandx at /home/folkert/Projects/PDP-11/json/python-pdp11-emulator/machine.py:528
*** self: <machine.PDP1170 object at 0x75ad6c5b6010>
*** b6: 55
*** value: 13
*** opsize: 1
*** altmode: None
*** altspace: None
*** rmw: False
*** justEA: False
*** Rn: 7
*** autocrement: 0
*** space: 1
*** extendedb6: None
*** addr: 65398
*** addrmode: 48
*** x: 64786

** op11_movb at /home/folkert/Projects/PDP-11/json/python-pdp11-emulator/op4.py:110
*** cpu: <machine.PDP1170 object at 0x75ad6c5b6010>
*** inst: 37943
*** val: 13
*** dst: 55

** run at /home/folkert/Projects/PDP-11/json/python-pdp11-emulator/machine.py:585
*** self: <machine.PDP1170 object at 0x75ad6c5b6010>
*** pc: 128
*** breakpoint: None
*** interrupt_mgr: <interrupts.InterruptManager object at 0x75ad6c346410>
*** mmu: <mmu.MemoryMgmt object at 0x75ad6cf24d50>
*** abort_trap: None
*** thisPC: 608
*** inst: 37943

** <module> at /home/folkert/Projects/PDP-11/json/python-pdp11-emulator/./tapeloader.py:63
*** __name__: '__main__'
[...]

In mmio.py line 220 a word is read from the i/o to convert the byte-write into a word-write.

For that to work I think you need to do something like this:

diff --git a/kl11.py b/kl11.py
index b8ad643..9db36fc 100644
--- a/kl11.py
+++ b/kl11.py
@@ -125,7 +125,8 @@ class KL11:
                         self.ub.intmgr.simple_irq(pri=4, vector=0o64)
 
             # transmit buffer
-            case 6 if value is not None:              # tbuf
+            case 6:
+                if value is not None:              # tbuf
                     # *** WRITING ***
                     value &= 0o177
                     if (value != 0o177):
@@ -133,6 +134,8 @@ class KL11:
                         self.tq.put(s)
                     if self.t_ienable:
                         self.ub.intmgr.simple_irq(pri=4, vector=0o64)
+                else:
+                    value = 0
             case _:
                 raise PDPTraps.AddressError

SOB?

Hi,

Are you sure about the current SOB implementation?
It is subtle different from other implementations I saw (p11, simh) and behaves a tiny bit different because of that.

I think it should be:

def op077_sob(cpu, inst):
    srcreg = (inst & 0o000700) >> 6
    r = (cpu.r[srcreg] - 1) & 0xffff

    if r != 0:
        # technically if this instruction occurs low enough in memory
        # this PC subtraction could wrap, so be technically correct & mask
        cpu.r[cpu.PC] = (cpu.r[cpu.PC] - 2 * (inst & 0o077)) & cpu.MASK16

    cpu.r[srcreg] = r

See https://github.com/open-simh/simh/blob/master/PDP11/pdp11_cpu.c#L1895

#8

addressing modes

Hi,

I'm not 100% sure but regarding https://github.com/outofmbufs/python-pdp11-emulator/blob/main/machine.py#L454
At line 463 for registers that are not SP/PC, the autoincrement is set to word_size. But I think that should always be 2 unless I mis-interpret https://bitsavers.org/pdf/dec/pdp11/1170/PDP-11_70_Handbook_1977-78.pdf page 33, 3-9.
"Register is first used as a pointer to a word containing the address of the operand, then incremented (always by 2; even for byte instructions)". Same for mode 5 (which currently only for SP decrements by 2).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.