Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDP-8 socket tty looses data #85

Closed
dgesswein opened this issue Oct 11, 2013 · 6 comments
Closed

PDP-8 socket tty looses data #85

dgesswein opened this issue Oct 11, 2013 · 6 comments

Comments

@dgesswein
Copy link
Contributor

@dgesswein dgesswein commented Oct 11, 2013

If you run the following program

        *200
        CLA
        TAD (101
        JMS SEND
        TAD (102
        JMS SEND
        TAD (103
        JMS SEND
        TAD (104
        JMS SEND
        JMP 200
SEND,   0
        6416
        6411
        JMP .-1
        CLA
        JMP I SEND
        $

with these simh commands
att ttix 2222;notelnet
set ttox 8b

The first few characters get lost
$ nc localhost 2222 | od -to1
0000000 103 104 101 102 103 104 101 102 103 104 101 102 103 104 101 102
*
0167040 103 104 101 102 103
0167045

This part of the patch for issue 75 was to fix this problem. With more knowledge of the code there is probably a better solution.

*** ../simh-master/PDP8/pdp8_cpu.c  2013-10-02 13:23:34.000000000 -0400
--- PDP8/pdp8_cpu.c 2013-10-11 15:22:44.000000000 -0400
***************
*** 321,326 ****
--- 321,327 ----
  uint32 PC, MA;
  int32 device, pulse, temp, iot_data;
  t_stat reason;
+ static int first_time = 1;

  /* Restore register state */

***************
*** 338,346 ****

  while (reason == 0) {                                   /* loop until halted */

!     if (sim_interval <= 0) {                            /* check clock queue */
          if ((reason = sim_process_event ()))
              break;
          }

      if (int_req > INT_PENDING) {                        /* interrupt? */
--- 339,348 ----

  while (reason == 0) {                                   /* loop until halted */

!     if (sim_interval <= 0 || first_time) {                            /* check clock queue */
+         first_time = 0;
          if ((reason = sim_process_event ()))
              break;

          }

      if (int_req > INT_PENDING) {                        /* interrupt? */
***************
@markpizz
Copy link
Member

@markpizz markpizz commented Oct 11, 2013

I don't see when you actually start the program:

with these simh commands
att ttix 2222;notelnet
set ttox 8b

The first few characters get lost
$ nc localhost 2222 | od -to1
0000000 103 104 101 102 103 104 101 102 103 104 101 102 103 104 101 102
*

The tcp session has to be established before you can expect the output can be delivered.
Meanwhile, on real hardware, you can't just blast bytes out a serial port. You've got to wait until the prior character has been delivered out before you can send another. I don't know enough about the PDP8 instructions to determine if you are actually doing this.

Does "dep ttox time 1" get you better behavior without the lost bytes?

@markpizz
Copy link
Member

@markpizz markpizz commented Oct 11, 2013

After some more thought, I realize what is probably happening. Your program is pushing bytes out before the system notices that someone has established a connection to the serial port. One would argue that this race condition is a consequence of the program which immediately starts writing output and the fact that from the simulator's point of view, a wire hasn't been plugged into the serial port yet, and the program doesn't have a way to determine this. One could hack the ttox device to not generate output complete interrupts when a tcp connection isn't established, but this wouldn't reflect how real hardware behaves. Most output to real serial ports just falls on the floor if a wire isn't plugged into the port.

@dgesswein
Copy link
Contributor Author

@dgesswein dgesswein commented Oct 11, 2013

The socket receiving program was started before I started the PDP-8 running. This was for testing my program for dumping and restoring images. The PDP-8 program sends a character when started telling the other end of the serial line to send the next block. With SIMH that first character gets lost without the change above. Works fine on a real PDP-8.

The order was
sim> att ttix 2222;notelnet
Listening on port 2222
sim> set ttox 8b
sim> load char.bin
sim>
(other window) nc localhost 2222 | od -to1
sim> run 200

6416 sends the character
6411 skips next instruction if sending character finished
JMP .-1 repeats skip until character sending finished

@markpizz
Copy link
Member

@markpizz markpizz commented Oct 12, 2013

My analysis above is correct. The 'wire' hasn't been connected to the serial port yet and hence the initial output drops on the floor in the back of the computer.

As you initially suggested, I have fixed this issue by explicitly scheduling the TTIX device immediately when the "attach ttix nnn" is done. Now, when the TTIX device is attached, an initial check will be done the first time simulation is started. This is sort of equivalent to your "first_time" flag, but specific to the issue it was created for.

markpizz added a commit that referenced this issue Oct 12, 2013
@markpizz markpizz closed this Oct 12, 2013
@markpizz markpizz reopened this Oct 19, 2013
@markpizz
Copy link
Member

@markpizz markpizz commented Oct 23, 2013

I reopened this issue since the problem was reported to still be happening; And testing confirmed that using the above recipe:

The order was
sim> att ttix 2222;notelnet
Listening on port 2222
sim> set ttox 8b
sim> load char.bin
sim>
(other window) nc localhost 2222 | od -to1
sim> run 200

.

@markpizz
Copy link
Member

@markpizz markpizz commented Oct 23, 2013

Much digging revealed that the problem persisted due to the use of "RUN 200" to start simulator execution rather than "GO 200".

The difference between the simh RUN and GO commands is that the RUN command resets all devices before starting execution. The GO command merely starts execution at the indicated start address (or the current PC value of no start address is supplied).

The additional reset operation cancels the immediate pending poll for connection operation which is scheduled when the "attach ttix" command was issued. The first poll operation will now not happen until the first clock tick. The program therefore drops output characters until the connection is established.

If there is some benefit to having devices reset, then the best way to achieve this would be:

 sim> set ttox 8b
 sim> load char.bin
 sim> reset -p
 sim> att ttix 2222;notelnet
 sim> go 200
@markpizz markpizz closed this Oct 23, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants