root/src/dps8/dps8_fnp2_iomcmd.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. fnp_core_read_n
  2. l_putbits36_1
  3. dmpmbx
  4. wcd
  5. tun_write
  6. fnp_wtx_output
  7. wtx
  8. fnp_rtx_input_accepted
  9. interruptL66_CS_to_FNP
  10. interruptL66_FNP_to_CS
  11. interruptL66_CS_done
  12. interruptL66
  13. fnpcmdBootload
  14. getl6core
  15. processMBX
  16. fnpCmd
  17. fnp_iom_cmd

   1 /*
   2  * vim: filetype=c:tabstop=4:ai:expandtab
   3  * SPDX-License-Identifier: ICU
   4  * SPDX-License-Identifier: Multics
   5  * scspell-id: 55ddc42f-f62e-11ec-ad7c-80ee73e9b8e7
   6  *
   7  * ---------------------------------------------------------------------------
   8  *
   9  * Copyright (c) 2007-2013 Michael Mondy
  10  * Copyright (c) 2012-2016 Harry Reed
  11  * Copyright (c) 2013-2016 Charles Anthony
  12  * Copyright (c) 2021-2026 The DPS8M Development Team
  13  *
  14  * This software is made available under the terms of the ICU License.
  15  * See the LICENSE.md file at the top-level directory of this distribution.
  16  *
  17  * ---------------------------------------------------------------------------
  18  *
  19  * This source file may contain code comments that adapt, include, and/or
  20  * incorporate Multics program code and/or documentation distributed under
  21  * the Multics License.  In the event of any discrepancy between code
  22  * comments herein and the original Multics materials, the original Multics
  23  * materials should be considered authoritative unless otherwise noted.
  24  * For more details and historical background, see the LICENSE.md file at
  25  * the top-level directory of this distribution.
  26  *
  27  * ---------------------------------------------------------------------------
  28  */
  29 
  30 //
  31 // This module contains the code that runs under the IOM channel thread
  32 //
  33 
  34 #define ASSUME0 0
  35 
  36 #include <stdio.h>
  37 #include <ctype.h>
  38 
  39 #include "dps8.h"
  40 #include "dps8_sys.h"
  41 #include "dps8_iom.h"
  42 #include "dps8_cable.h"
  43 #include "dps8_cpu.h"
  44 #include "dps8_scu.h"
  45 #include "dps8_fnp2.h"
  46 #include "dps8_fnp2_iomcmd.h"
  47 #include "dps8_utils.h"
  48 #include "fnpuv.h"
  49 
  50 #define DBG_CTR 1
  51 
  52 #if defined(THREADZ) || defined(LOCKLESS)
  53 # include "threadz.h"
  54 #endif
  55 
  56 #if defined(TESTING)
  57 static inline void fnp_core_read_n (word24 addr, word36 *data, uint n, UNUSED const char * ctx)
     /* [previous][next][first][last][top][bottom][index][help] */
  58   {
  59 # if defined(THREADZ)
  60     lock_mem_rd ();
  61 # endif /* if defined(THREADZ) */
  62     for (uint i = 0; i < n; i ++)
  63       data [i] = M [addr + i] & DMASK;
  64 # if defined(THREADZ)
  65     unlock_mem ();
  66 # endif /* if defined(THREADZ) */
  67   }
  68 #endif /* if defined(TESTING) */
  69 
  70 #if defined(THREADZ)
  71 static inline void l_putbits36_1 (vol word36 * x, uint p, word1 val)
     /* [previous][next][first][last][top][bottom][index][help] */
  72 {
  73     const int n = 1;
  74     int shift = 36 - (int) p - (int) n;
  75     if (shift < 0 || shift > 35) {
  76         sim_printf ("l_putbits36_1: bad args (%012"PRIo64",pos=%d)\r\n", *x, p);
  77         return;
  78     }
  79     word36 mask = ~ (~0U<<n);  // n low bits on
  80     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
  81     // caller may provide val that is too big, e.g., a word with all bits
  82     // set to one, so we mask val
  83     lock_mem_wr ();
  84     * x = (* x & ~ smask) | (((word36) val & mask) << shift);
  85     unlock_mem ();
  86 }
  87 #else
  88 # define l_putbits36_1 putbits36_1
  89 #endif /* if defined(THREADZ) */
  90 
  91 //
  92 // As mailbox messages are processed, decoded data is stashed here
  93 ///
  94 
  95 struct decoded_t
  96   {
  97     uint devUnitIdx;
  98     uint op_code;
  99     uint slot_no;
 100     uint iom_unit;
 101     uint chan_num;
 102     word24 smbx;
 103     word24 fsmbx;
 104     struct fnpUnitData_s * fudp;
 105     uint cell;
 106   };
 107 
 108 //
 109 // Debugging...
 110 //
 111 
 112 #if defined(TESTING)
 113 static void dmpmbx (uint mailboxAddress)
     /* [previous][next][first][last][top][bottom][index][help] */
 114   {
 115     struct mailbox mbx;
 116     fnp_core_read_n (mailboxAddress, (word36 *) & mbx, MAILBOX_WORDS, "dmpmbx");
 117     sim_printf ("dia_pcw            %012llo\r\n", (long long unsigned int) mbx.dia_pcw);
 118     sim_printf ("mailbox_requests   %012llo\r\n", (long long unsigned int) mbx.mailbox_requests);
 119     sim_printf ("term_inpt_mpx_wd   %012llo\r\n", (long long unsigned int) mbx.term_inpt_mpx_wd);
 120     sim_printf ("last_mbx_req_count %012llo\r\n", (long long unsigned int) mbx.last_mbx_req_count);
 121     sim_printf ("num_in_use         %012llo\r\n", (long long unsigned int) mbx.num_in_use);
 122     sim_printf ("mbx_used_flags     %012llo\r\n", (long long unsigned int) mbx.mbx_used_flags);
 123     for (uint i = 0; i < 8; i ++)
 124       {
 125         sim_printf ("CS  mbx %d\r\n", i);
 126         sim_printf ("    word1        %012llo\r\n",
 127                     (long long unsigned int) mbx.dn355_sub_mbxes[i].word1);
 128         sim_printf ("    word2        %012llo\r\n",
 129                     (long long unsigned int) mbx.dn355_sub_mbxes[i].word2);
 130         sim_printf ("    command_data %012llo\r\n",
 131                     (long long unsigned int) mbx.dn355_sub_mbxes[i].command_data [0]);
 132         sim_printf ("                 %012llo\r\n",
 133                     (long long unsigned int) mbx.dn355_sub_mbxes[i].command_data [1]);
 134         sim_printf ("                 %012llo\r\n",
 135                     (long long unsigned int) mbx.dn355_sub_mbxes[i].command_data [2]);
 136         sim_printf ("    word6        %012llo\r\n",
 137                     (long long unsigned int) mbx.dn355_sub_mbxes[i].word6);
 138       }
 139     for (uint i = 0; i < 4; i ++)
 140       {
 141         sim_printf ("FNP mbx %d\r\n", i);
 142         sim_printf ("    word1        %012llo\r\n",
 143                     (unsigned long long int)mbx.fnp_sub_mbxes[i].word1);
 144         sim_printf ("    word2        %012llo\r\n",
 145                     (unsigned long long int)mbx.fnp_sub_mbxes[i].word2);
 146         sim_printf ("    mystery      %012llo\r\n",
 147                     (unsigned long long int)mbx.fnp_sub_mbxes[i].mystery [0]);
 148         sim_printf ("                 %012llo\r\n",
 149                     (unsigned long long int)mbx.fnp_sub_mbxes[i].mystery [1]);
 150         sim_printf ("                 %012llo\r\n",
 151                     (unsigned long long int)mbx.fnp_sub_mbxes[i].mystery [2]);
 152       }
 153 
 154   }
 155 #endif
 156 
 157 //
 158 // wcd; Multics has sent a Write Control Data command to the FNP
 159 //
 160 
 161 static int wcd (struct decoded_t *decoded_p)
     /* [previous][next][first][last][top][bottom][index][help] */
 162   {
 163 #if defined(TESTING)
 164     cpu_state_t * cpup = _cpup;
 165 #endif
 166     struct t_line * linep = & decoded_p->fudp->MState.line[decoded_p->slot_no];
 167     sim_debug (DBG_TRACE, & fnp_dev, "[%u] wcd op_code %u 0%o\r\n",
 168                decoded_p->slot_no, decoded_p->op_code, decoded_p->op_code);
 169 
 170     word36 command_data[3];
 171     for (uint i=0; i < 3; i++)
 172       iom_direct_data_service (decoded_p->iom_unit, decoded_p->chan_num,
 173                                decoded_p->smbx+COMMAND_DATA + i, & command_data [i], direct_load);
 174 
 175     switch (decoded_p->op_code)
 176       {
 177         case  1: // disconnect_this_line
 178           {
 179             sim_debug (DBG_TRACE, & fnp_dev, "[%u]    disconnect_this_line\r\n", decoded_p->slot_no);
 180             if (linep->line_client && linep->service == service_login)
 181               fnpuv_start_writestr (linep->line_client, (unsigned char *) "Multics has disconnected you\r\n");
 182 #if defined(DISC_DELAY)
 183             linep -> line_disconnected = DISC_DELAY;
 184 #else
 185             linep -> line_disconnected = true;
 186 #endif
 187             linep -> listen = false;
 188             if (linep->line_client)
 189               {
 190                 close_connection ((uv_stream_t *) linep->line_client);
 191               }
 192 
 193           }
 194           break;
 195 
 196         case  3: // dont_accept_calls
 197           {
 198             sim_debug (DBG_TRACE, & fnp_dev, "[%u]    dont_accept_calls\r\n", decoded_p->slot_no);
 199             decoded_p->fudp->MState.accept_calls = false;
 200           }
 201           break;
 202 
 203         case  4: // accept_calls
 204           {
 205             sim_debug (DBG_TRACE, & fnp_dev, "[%u]    accept_calls\r\n", decoded_p->slot_no);
 206             decoded_p->fudp->MState.accept_calls = true;
 207           }
 208           break;
 209 
 210         case  6: // set_line_type
 211           {
 212             linep->lineType = (word9) getbits36_18 (command_data[0], 0);
 213           }
 214           break;
 215 
 216         case  8: // set_framing_chars
 217           {
 218             sim_debug (DBG_TRACE, & fnp_dev, "[%u]    set_framing_chars\r\n", decoded_p->slot_no);
 219             //sim_printf ("fnp set framing characters\r\n");
 220             uint d1 = getbits36_9 (command_data[0], 0);
 221             uint d2 = getbits36_9 (command_data[0], 9);
 222             linep->frame_begin = d1;
 223             linep->frame_end = d2;
 224           }
 225           break;
 226 
 227         case 12: // dial out
 228           {
 229             sim_debug (DBG_TRACE, & fnp_dev, "[%u]    dial out\r\n", decoded_p->slot_no);
 230             //sim_printf ("XXX dial_out %d %012"PRIo64" %012"PRIo64" %012"PRIo64"",
 231             //            decoded_p->slot_no, command_data0, command_data1, command_data2);
 232             fnpuv_dial_out (decoded_p->devUnitIdx, decoded_p->slot_no,
 233                             command_data[0], command_data[1], command_data[2]);
 234           }
 235           break;
 236 
 237         case 22: // line_control
 238           {
 239             sim_debug (DBG_TRACE, & fnp_dev, "[%u]    line_control\r\n", decoded_p->slot_no);
 240             //word36 command_data2 = decoded_p->smbxp -> command_data [2];
 241             //sim_printf ("XXX line_control %d %012"PRIo64" %012"PRIo64" %012"PRIo64"\r\n",
 242             //            decoded_p->slot_no, command_data0, command_data1, command_data2);
 243 
 244 // bisync_line_data.inc.pl1
 245             word18 op = getbits36_18 (command_data[0], 0);
 246             //word18 val1 = getbits36_18 (command_data[0], 18);
 247             //word18 val2 = getbits36_18 (command_data[1], 0);
 248             //word18 val3 = getbits36_18 (command_data1, 18);
 249 //sim_printf ("line_control %d op %d. %o\r\n", decoded_p->slot_no, op, op);
 250             switch (op)
 251               {
 252                 case 1:
 253                   //if_sim_debug (DBG_TRACE, & fnp_dev) {
 254                   //    word18 val1 = getbits36_18 (command_data[0], 18);
 255                   //    sim_debug (DBG_TRACE, & fnp_dev, "SET_BID_LIMIT\r\n");
 256                   //    sim_debug (DBG_TRACE, & fnp_dev, "    %u\r\n", val1);
 257                   //}
 258                   break;
 259                 case 2:
 260                   sim_debug (DBG_TRACE, & fnp_dev, "ACCEPT_BID\r\n");
 261                   break;
 262                 case 3:
 263                   //if_sim_debug (DBG_TRACE, & fnp_dev) {
 264                   //    word18 val1 = getbits36_18 (command_data[0], 18);
 265                   //    sim_debug (DBG_TRACE, & fnp_dev, "CONFIGURE\r\n");
 266                   //    if (val1 == 0)
 267                   //      sim_debug (DBG_TRACE, & fnp_dev, "    non-transparent ASCII\r\n");
 268                   //    else if (val1 == 1)
 269                   //      sim_debug (DBG_TRACE, & fnp_dev, "    non-transparent EBCDIC\r\n");
 270                   //    else if (val1 == 2)
 271                   //      sim_debug (DBG_TRACE, & fnp_dev, "    transparent ASCII\r\n");
 272                   //    else if (val1 == 3)
 273                   //      sim_debug (DBG_TRACE, & fnp_dev, "    transparent EBCDIC\r\n");
 274                   //    else
 275                   //      sim_debug (DBG_TRACE, & fnp_dev, "    unknown %u. %o\r\n", val1, val1);
 276                   //}
 277                   break;
 278                 case 4:
 279                   //if_sim_debug (DBG_TRACE, & fnp_dev) {
 280                   //    word18 val1 = getbits36_18 (command_data[0], 18);
 281                   //    word18 val2 = getbits36_18 (command_data[1], 0);
 282                   //    sim_debug (DBG_TRACE, & fnp_dev, "SET_TTD_PARAMS\r\n");
 283                   //    sim_debug (DBG_TRACE, & fnp_dev, "    ttd_time  %u\r\n", val1);
 284                   //    sim_debug (DBG_TRACE, & fnp_dev, "    ttd_limit %u\r\n", val2);
 285                   //}
 286                   break;
 287                 case 5:
 288                   sim_debug (DBG_TRACE, & fnp_dev, "REPORT_WRITE_STATUS\r\n");
 289                   break;
 290                 case 6:
 291                   sim_debug (DBG_TRACE, & fnp_dev, "SET_3270_MODE\r\n");
 292                   break;
 293                 case 7:
 294                   {
 295                     sim_debug (DBG_TRACE, & fnp_dev, "SET_POLLING_ADDR\r\n");
 296 //word36 command_data2 = decoded_p->smbxp -> command_data [2];
 297 //sim_printf ("XXX line_control %d %012"PRIo64" %012"PRIo64" %012"PRIo64"\r\n",
 298 //            decoded_p->slot_no, command_data0, command_data1, command_data2);
 299                     //word9 len = getbits36_9 (command_data0, 18);
 300                     word9 c1 = getbits36_9 (command_data[0], 27);
 301                     //word9 c2 = getbits36_9 (command_data1, 0);
 302                     word9 c3 = getbits36_9 (command_data[1], 9);
 303                     //word9 c4 = getbits36_9 (command_data1, 18);
 304                     sim_debug (DBG_TRACE, & fnp_dev, "    char1 %u\r\n", c1);
 305                     sim_debug (DBG_TRACE, & fnp_dev, "    char3 %u\r\n", c3);
 306                     fnpData.ibm3270ctlr[ASSUME0].pollCtlrChar = (unsigned char) (c1 & 0xff);
 307                     fnpData.ibm3270ctlr[ASSUME0].pollDevChar = (unsigned char) (c3 & 0xff);
 308                     fnpData.
 309                       fnpUnitData[decoded_p->devUnitIdx].
 310                         MState.
 311                           line[decoded_p->slot_no].
 312                             line_client = NULL;
 313                   }
 314                   break;
 315                 case 8:
 316                   sim_debug (DBG_TRACE, & fnp_dev, "START_POLL\r\n");
 317                   fnpuv3270Poll (true);
 318                   break;
 319                 case 9:
 320                   {
 321                     sim_debug (DBG_TRACE, & fnp_dev, "SET_SELECT_ADDR\r\n");
 322                     //word9 len = getbits36_9 (command_data0, 18);
 323                     word9 c1 = getbits36_9 (command_data[0], 27);
 324                     //word9 c2 = getbits36_9 (command_data1, 0);
 325                     word9 c3 = getbits36_9 (command_data[1], 9);
 326                     //word9 c4 = getbits36_9 (command_data1, 18);
 327                     sim_debug (DBG_TRACE, & fnp_dev, "    char1 %u\r\n", c1);
 328                     sim_debug (DBG_TRACE, & fnp_dev, "    char3 %u\r\n", c3);
 329                     fnpData.ibm3270ctlr[ASSUME0].selCtlrChar = (unsigned char) (c1 & 0xff);
 330                     fnpData.ibm3270ctlr[ASSUME0].selDevChar = (unsigned char) (c3 & 0xff);
 331 
 332                     // General Poll
 333                     if (fnpData.ibm3270ctlr[ASSUME0].selDevChar == 127)
 334                       {
 335                         fnpData.
 336                           fnpUnitData[decoded_p->devUnitIdx].
 337                             MState.
 338                               line[decoded_p->slot_no].
 339                                 line_client = NULL;
 340                         break;
 341                       }
 342 // Setup line_client to that wtx can locate the connection
 343 
 344                     // Find the client from the device selection call
 345 
 346                     uint stn_no;
 347                     for (stn_no = 0; stn_no < ADDR_MAP_ENTRIES; stn_no ++)
 348                       if (addr_map [stn_no] == fnpData.ibm3270ctlr[ASSUME0].selDevChar)
 349                         break;
 350                     if (stn_no >= ADDR_MAP_ENTRIES)
 351                       {
 352                         sim_warn ("SET_POLLING_ADDR couldn't find selDevChar %02x\r\n",
 353                                   (unsigned int) fnpData.ibm3270ctlr[ASSUME0].selDevChar);
 354                         break;
 355                       }
 356                     fnpData.
 357                       fnpUnitData[decoded_p->devUnitIdx].
 358                         MState.
 359                           line[decoded_p->slot_no].
 360                             line_client =
 361                                            fnpData.
 362                                              ibm3270ctlr[ASSUME0].
 363                                                stations[stn_no].
 364                                                  client;
 365                   }
 366                   break;
 367                 case 10:
 368                   sim_debug (DBG_TRACE, & fnp_dev, "STOP_AUTO_POLL\r\n");
 369                   break;
 370                 case 11:
 371                   //if_sim_debug (DBG_TRACE, & fnp_dev) {
 372                   //    word18 val1 = getbits36_18 (command_data[0], 18);
 373                   //    sim_debug (DBG_TRACE, & fnp_dev, "SET_MASTER_SLAVE_MODE\r\n");
 374                   //    if (val1 == 0)
 375                   //      sim_debug (DBG_TRACE, & fnp_dev, "    slave\r\n");
 376                   //    else if (val1 == 1)
 377                   //      sim_debug (DBG_TRACE, & fnp_dev, "    master\r\n");
 378                   //    else
 379                   //      sim_debug (DBG_TRACE, & fnp_dev, "    unknown %u. %o\r\n", val1, val1);
 380                   //}
 381                   break;
 382                 case 12:
 383                   sim_debug (DBG_TRACE, & fnp_dev, "SET_HASP_MODE\r\n");
 384                   break;
 385                 case 13:
 386                   sim_debug (DBG_TRACE, & fnp_dev, "SET_NAK_LIMIT\r\n");
 387                   break;
 388                 case 14:
 389                   sim_debug (DBG_TRACE, & fnp_dev, "SET_HASP_TIMERS\r\n");
 390                   break;
 391                 default:
 392                   sim_printf ("unknown %u. %o\r\n", op, op);
 393                   break;
 394               }
 395 
 396 
 397 
 398 
 399 
 400 
 401 
 402 
 403 
 404 
 405 
 406 
 407 
 408           }
 409         break;
 410 
 411         case 23: // sync_msg_size
 412           {
 413             linep->sync_msg_size = (uint) getbits36_18 (command_data[0], 0);
 414             //sim_printf ("sync_msg_size %u\r\n", sz);
 415           }
 416           break;
 417 
 418 //
 419 //  1 echo_neg_data          based (echo_neg_datap) aligned,
 420 //    /* Echo negotiation data */
 421 //    2 version                     fixed bin,
 422 //    2 break (0:255)               bit (1) unaligned,                /* Break table, 1 = break */
 423 //    2 pad                         bit (7) unaligned,
 424 //    2 rubout_trigger_chars (2) unaligned,                           /* Characters that cause rubout action */
 425 //      3 char                      char (1) unaligned,
 426 //    2 rubout_sequence_length      fixed bin (4) unsigned unaligned, /* Length of rubout sequence, output */
 427 //    2 rubout_pad_count            fixed bin (4) unsigned unaligned, /* Count of pads needed */
 428 //    2 buffer_rubouts              bit (1) unaligned,                /* 1 = put rubouts and rubbed out in buffer */
 429 //    2 rubout_sequence             char (12) unaligned;              /* Actual rubout sequence */
 430 //
 431 //   0  version
 432 //   1  break(0:35)
 433 //   2  break(36:71)
 434 //   3  break(72:107)
 435 //   4  break(108:143)
 436 //   5  break(144:179)
 437 //   6  break(180:215)
 438 //   7  break(216:251)
 439 //   8
 440 //      0:3 break(252:255)
 441 //      4:10 pad
 442 //      11:17  padding inserted by compiler to align to char boundary
 443 //      18:35 rubout_trigger_chars
 444 //   9  0:3 rubout_sequence_length
 445 //      4:7 rubout_pad_count
 446 //      8: buffer_rubouts
 447 //      9:35 rubout_sequence (1:3)
 448 //  10  rubout_sequence (4:7)
 449 //  12  rubout_sequence (8:11)
 450 //  13  0:8 rubout_sequence (12)
 451 
 452         case 24: // set_echnego_break_table
 453           {
 454             sim_debug (DBG_TRACE, & fnp_dev,
 455                        "[%u]    set_echnego_break_table\r\n", decoded_p->slot_no);
 456 
 457 #if defined(ECHNEGO_DEBUG)
 458             sim_printf ("set_echnego_break_table\r\n");
 459 #endif
 460             // Get the table pointer and length
 461             word36 word6;
 462             iom_direct_data_service (decoded_p->iom_unit, decoded_p->chan_num,
 463                                      decoded_p->smbx+WORD6, & word6,
 464                                      direct_load);
 465             uint data_addr = getbits36_18 (word6, 0);
 466             uint data_len = getbits36_18 (word6, 18);
 467 
 468             //sim_printf ("set_echnego_break_table %d addr %06o len %d\r\n",
 469             //            decoded_p->slot_no, data_addr, data_len);
 470 
 471             // According to the MOWSE documentation, length of 0
 472             // means no break characters and -1 means all break.
 473 
 474 #define echoTableLen 8
 475 
 476             if (data_len != echoTableLen && data_len != 0 &&
 477                 data_len != MASK18)
 478               {
 479                 sim_printf ("set_echnego_break_table data_len !=8 (%d)\r\n", data_len);
 480                 break;
 481               }
 482 
 483             word36 echoTable [echoTableLen];
 484             if (data_len == 0)
 485               {
 486                 (void)memset (linep->echnego_break_table, 0,
 487                               sizeof (linep->echnego_break_table));
 488               }
 489             else if (data_len == MASK18)
 490               {
 491                 (void)memset (linep->echnego_break_table, 1,
 492                               sizeof (linep->echnego_break_table));
 493               }
 494             else
 495               {
 496                 for (uint i = 0; i < echoTableLen; i ++)
 497                   {
 498                     iom_direct_data_service (decoded_p->iom_unit,
 499                       decoded_p->chan_num, data_addr + i, & echoTable [i],
 500                       direct_load);
 501                       //sim_printf ("%012llo\r\n", echoTable[i]);
 502                   }
 503 // Table format is actually
 504 //   16 bits 2 pad 15 bits 2 pad
 505                 uint offset = 0;
 506                 for (uint i = 0; i < 8; i ++)
 507                   {
 508                     word36 w = echoTable [i];
 509                     for (uint j = 0; j < 16; j ++)
 510                       linep->echnego_break_table[offset++] =
 511                         !! getbits36_1 (w, j);
 512                     for (uint j = 0; j < 16; j ++)
 513                       linep->echnego_break_table[offset++] =
 514                         !! getbits36_1 (w, j + 18);
 515                   }
 516               }
 517 
 518 
 519 
 520 
 521 
 522 
 523 
 524 
 525 
 526 
 527 
 528           }
 529           break;
 530 
 531 // MTB418, pg 13:
 532 // "When Ring Zero MCS is called upon to begin negotiated echo (echo negotiate
 533 // get chars, as in the previous paper), and has no characters to deliver
 534 // immediately (already accumulated), it calls upon the inferior multiplexer to
 535 // "start negotiated echo'', via a control order, also specifying the number of
 536 // characters left on the line, as in the protocol of the previous paper. If
 537 // this control order is refused (the multiplexer does not support the new
 538 // protocol (of course, fnp multiplexer in specific, does)), ring zero proceeds
 539 // as today, with interrupt-side negotiated echo. If the multiplexer goes along
 540 // with the order, the channel is marked (in the ring-zero echo data) as having
 541 // a multiplexer knowledgeable about the protocol. In either case, ring zero
 542 // will enter the ''ring zero echo state" (of the previous paper).
 543 
 544         case 25: // start_negotiated_echo
 545           {
 546             sim_debug (DBG_TRACE, & fnp_dev,
 547               "[%u]    start_negotiated_echo\r\n", decoded_p->slot_no);
 548 
 549             linep->echnego_sync_ctr =
 550               getbits36_18 (command_data[0], 0);
 551             linep->echnego_screen_left = getbits36_18 (command_data[0], 18);
 552 
 553 #if defined(ECHNEGO_DEBUG)
 554             sim_printf ("start_negotiated_echo ctr %d screenleft %d "
 555               "unechoed cnt %d\r\n", linep->echnego_sync_ctr,
 556               linep->echnego_screen_left,linep->echnego_unechoed_cnt);
 557 #endif
 558 
 559 // MTB-418 pg 15
 560 // If the counts are not equal, it must be the case that non-echoed characters
 561 // are ''in transit'', and the order must not be honored.
 562 
 563             linep->echnego_on =
 564               linep->echnego_sync_ctr == linep->echnego_unechoed_cnt;
 565 
 566 #if defined(ECHNEGO_DEBUG)
 567             sim_printf ("echnego is %s\r\n",
 568                         linep->echnego_on ? "on" : "off");
 569 #endif
 570 
 571           }
 572           break;
 573 
 574         case 26: // stop_negotiated_echo
 575           {
 576             sim_debug (DBG_TRACE, & fnp_dev,
 577                        "[%u]    stop_negotiated_echo\r\n",
 578                        decoded_p->slot_no);
 579 #if defined(ECHNEGO_DEBUG)
 580             sim_printf ("stop_negotiated_echo\r\n");
 581 #endif
 582             linep->echnego_on = false;
 583             // Post a ack echnego stop to MCS
 584             linep->ack_echnego_stop = true;
 585           }
 586           break;
 587 
 588         case 27: // init_echo_negotiation
 589           {
 590             sim_debug (DBG_TRACE, & fnp_dev,
 591                        "[%u]    init_echo_negotiation\r\n",
 592                        decoded_p->slot_no);
 593 #if defined(ECHNEGO_DEBUG)
 594             sim_printf ("init_echo_negotiation\r\n");
 595 #endif
 596 
 597 // At the time the multiplexer's input processor (which maintains the (
 598 // multiplexer's synchronization counter) receives the init echo negotiation
 599 // control order, it zeroes its synchronization counter, begins counting
 600 // characters (it must be in the non-echoing state) thereafter, and sends a new
 601 // type of interrupt to Ring Zero MCS, ACK ECHNEGO START.
 602 
 603             linep->echnego_unechoed_cnt = 0;
 604 
 605             // Post a ack echnego init to MCS
 606             linep->ack_echnego_init = true;
 607           }
 608           break;
 609 
 610         case 30: // input_fc_chars
 611           {
 612 // dcl 1 input_flow_control_info aligned based,
 613 //     2 suspend_seq unaligned,
 614 //       3 count fixed bin (9) unsigned,
 615 //       3 chars char (3),
 616 //     2 resume_seq unaligned,
 617 //       3 count fixed bin (9) unsigned,
 618 //       3 chars char (3),
 619 //     2 timeout bit (1);
 620 
 621             sim_debug (DBG_TRACE, & fnp_dev, "[%u]    input_fc_chars\r\n",
 622                        decoded_p->slot_no);
 623             word36 suspendStr = command_data[0];
 624             linep->inputSuspendStr[0] = getbits36_8 (suspendStr, 10);
 625             linep->inputSuspendStr[1] = getbits36_8 (suspendStr, 19);
 626             linep->inputSuspendStr[2] = getbits36_8 (suspendStr, 28);
 627             uint suspendLen = getbits36_9 (suspendStr, 0);
 628             if (suspendLen > 3)
 629               {
 630                 //sim_printf ("input_fc_chars truncating suspend %d to 3\r\n",
 631                 //            suspendLen);
 632                 suspendLen = 3;
 633               }
 634             linep->inputSuspendLen = suspendLen;
 635 
 636             word36 resumeStr = command_data[1];
 637             linep->inputResumeStr[0] = getbits36_8 (resumeStr, 10);
 638             linep->inputResumeStr[1] = getbits36_8 (resumeStr, 19);
 639             linep->inputResumeStr[2] = getbits36_8 (resumeStr, 28);
 640             uint resumeLen = getbits36_9 (resumeStr, 0);
 641             if (resumeLen > 3)
 642               {
 643                 //sim_printf ("input_fc_chars truncating suspend %d to 3\r\n",
 644                 //            suspendLen);
 645                 resumeLen = 3;
 646               }
 647             linep->inputResumeLen = resumeLen;
 648 
 649             // XXX timeout ignored
 650           }
 651           break;
 652 
 653         case 31: // output_fc_chars
 654           {
 655             sim_debug (DBG_TRACE, & fnp_dev, "[%u]    output_fc_chars\r\n",
 656                        decoded_p->slot_no);
 657             //sim_printf ("fnp output_fc_chars\r\n");
 658 
 659             word36 suspendStr = command_data[0];
 660             linep->outputSuspendStr[0] = getbits36_8 (suspendStr, 10);
 661             linep->outputSuspendStr[1] = getbits36_8 (suspendStr, 19);
 662             linep->outputSuspendStr[2] = getbits36_8 (suspendStr, 28);
 663             uint suspendLen = getbits36_9 (suspendStr, 0);
 664             if (suspendLen > 3)
 665               {
 666                 //sim_printf ("output_fc_chars truncating suspend %d to 3\r\n",
 667                 //            suspendLen);
 668                 suspendLen = 3;
 669               }
 670             linep->outputSuspendLen = suspendLen;
 671 
 672             word36 resumeStr = command_data[1];
 673             linep->outputResumeStr[0] = getbits36_8 (resumeStr, 10);
 674             linep->outputResumeStr[1] = getbits36_8 (resumeStr, 19);
 675             linep->outputResumeStr[2] = getbits36_8 (resumeStr, 28);
 676             uint resumeLen = getbits36_9 (resumeStr, 0);
 677             if (resumeLen > 3)
 678               {
 679                 //sim_printf ("output_fc_chars truncating suspend %d to 3\r\n",
 680                 //            suspendLen);
 681                 resumeLen = 3;
 682               }
 683             linep->outputResumeLen = resumeLen;
 684           }
 685           break;
 686 
 687         case 34: // alter_parameters
 688           {
 689             sim_debug (DBG_TRACE, & fnp_dev, "[%u]    alter_parameters\r\n",
 690                        decoded_p->slot_no);
 691             //sim_printf ("fnp alter parameters\r\n");
 692             // The docs insist the subtype is in word2, but I think
 693             // it is in command data...
 694             uint subtype = getbits36_9 (command_data[0], 0);
 695             uint flag = getbits36_1 (command_data[0], 17);
 696             //sim_printf ("  subtype %d\r\n", subtype);
 697             switch (subtype)
 698               {
 699                 case  3: // Fullduplex
 700                   {
 701                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        alter_parameters fullduplex %u\r\n",
 702                                decoded_p->slot_no, flag);
 703                     //sim_printf ("fnp full_duplex\r\n");
 704                     linep->fullDuplex = !! flag;
 705                   }
 706                   break;
 707 
 708                 case  8: // Crecho
 709                   {
 710                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        alter_parameters crecho %u\r\n",
 711                                decoded_p->slot_no, flag);
 712                     //sim_printf ("fnp crecho\r\n");
 713                     linep->crecho = !! flag;
 714                   }
 715                   break;
 716 
 717                 case  9: // Lfecho
 718                   {
 719                     //sim_printf ("fnp lfecho\r\n");
 720                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        alter_parameters lfecho %u\r\n",
 721                                decoded_p->slot_no, flag);
 722                     linep->lfecho = !! flag;
 723                   }
 724                   break;
 725 
 726                 case 13: // Dumpoutput
 727                   {
 728                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        alter_parameters dumpoutput\r\n",
 729                                decoded_p->slot_no);
 730                     //sim_printf ("fnp dumpoutput\r\n");
 731                     // XXX ignored
 732                     //linep -> send_output = true;
 733                     linep -> send_output = SEND_OUTPUT_DELAY;
 734                   }
 735                   break;
 736 
 737                 case 14: // Tabecho
 738                   {
 739                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        alter_parameters tabecho %u\r\n",
 740                                decoded_p->slot_no, flag);
 741                     //sim_printf ("fnp tabecho\r\n");
 742                     linep->tabecho = !! flag;
 743                   }
 744                   break;
 745 
 746                 case 16: // Listen
 747                   {
 748                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        alter_parameters listen %u\r\n",
 749                                decoded_p->slot_no, flag);
 750                     //sim_printf ("fnp listen %p %d.%d %d\r\n",
 751                     //            linep->line_client, decoded_p->devUnitIdx,decoded_p->slot_no, flag);
 752                     uint bufsz = getbits36_18 (command_data[0], 18);
 753                     linep->listen = !! flag;
 754                     linep->inputBufferSize = bufsz;
 755 
 756                     if (linep->service == service_undefined)
 757                       linep->service = service_login;
 758 
 759                     if (linep->service == service_login && linep -> line_client)
 760                       {
 761                         fnpuv_start_writestr (linep->line_client,
 762                           linep->listen ?
 763                             (unsigned char *) "Multics is now listening to this line\r\n":
 764                             (unsigned char *) "Multics is no longer listening to this line\r\n");
 765                       }
 766                     if (linep->service == service_slave && ! linep -> line_client)
 767                       fnpuv_open_slave (decoded_p->devUnitIdx, decoded_p->slot_no);
 768                   }
 769                   break;
 770 
 771                 case 17: // Hndlquit
 772                   {
 773                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        alter_parameters handlequit%u \r\n",
 774                                decoded_p->slot_no, flag);
 775                     //sim_printf ("fnp handle_quit %d\r\n", flag);
 776                     linep->handleQuit = !! flag;
 777                   }
 778                   break;
 779 
 780                 case 18: // Chngstring
 781                   {
 782                     //sim_printf ("fnp Change control string\r\n");
 783                     uint idx =  getbits36_9 (command_data[0], 9);
 784                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        alter_parameters chngstring %u\r\n",
 785                                decoded_p->slot_no, flag);
 786                     linep->ctrlStrIdx = idx;
 787                   }
 788                   break;
 789 
 790                 case 19: // Wru
 791                   {
 792                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        alter_parameters wru\r\n",
 793                                decoded_p->slot_no);
 794                     linep -> wru_timeout = true;
 795                   }
 796                   break;
 797 
 798                 case 20: // Echoplex
 799                   {
 800                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        alter_parameters echoplex %u\r\n",
 801                                decoded_p->slot_no, flag);
 802                     //sim_printf ("fnp echoplex\r\n");
 803                     linep->echoPlex = !! flag;
 804                   }
 805                   break;
 806 
 807                 case 22: // Dumpinput
 808                   {
 809                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        alter_parameters dumpinput\r\n",
 810                                decoded_p->slot_no);
 811 // XXX
 812 // dump input should discard whatever input buffers it can
 813 
 814                     //sim_printf ("fnp dump input\r\n");
 815         // dump the input
 816        //int muxLineNo = MState[fnpUnitNum].line [lineno] . muxLineNum;
 817        //sim_printf ("dumping mux line %d\r\n");
 818        //ttys [muxLineNo] . nPos = 0;
 819                   }
 820                   break;
 821 
 822                 case 23: // Replay
 823                   {
 824                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        alter_parameters replay %u\r\n",
 825                                decoded_p->slot_no, flag);
 826                     //sim_printf ("fnp replay\r\n");
 827                     linep->replay = !! flag;
 828                   }
 829                   break;
 830 
 831                 case 24: // Polite
 832                   {
 833                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        alter_parameters polite %u\r\n",
 834                                decoded_p->slot_no, flag);
 835                     //sim_printf ("fnp polite\r\n");
 836                     linep->polite = !! flag;
 837                   }
 838                   break;
 839 
 840                 case 25: // Block_xfer
 841                   {
 842                     uint bufsiz1 = getbits36_18 (command_data[0], 18);
 843                     uint bufsiz2 = getbits36_18 (command_data[1], 0);
 844                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        alter_parameters block_xfer %u %u\r\n",
 845                                decoded_p->slot_no, bufsiz1, bufsiz2);
 846                     linep->block_xfer_out_frame_sz = bufsiz1;
 847                     linep->block_xfer_in_frame_sz = bufsiz2;
 848 //sim_printf ("in frame sz %u out frame sz %u\r\n", linep->block_xfer_in_frame_sz, linep->block_xfer_out_frame_sz);
 849                     //sim_printf ("fnp block_xfer %d %d\r\n", bufsiz1, bufsiz2);
 850                   }
 851                   break;
 852 
 853                 case 26: // Set_buffer_size
 854                   {
 855                     // Word 2: Bit 17 is "1"b.
 856                     //uint mb1 = getbits36_1  (decoded_p->smbxp -> command_data [0], 17);
 857                     // Bits 18...35 contain the size, in characters,
 858                     // of input buffers to be allocated for the
 859                     // channel.
 860                     uint sz =  getbits36_18 (command_data[0], 18);
 861                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        alter_parameters set_buffer_size %u\r\n",
 862                                decoded_p->slot_no, flag);
 863                     linep->inputBufferSize = sz;
 864 //sim_printf ("Set_buffer_size %u\r\n", sz);
 865                   }
 866                   break;
 867 
 868                 case 27: // Breakall
 869                   {
 870                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        alter_parameters breakall %u\r\n",
 871                                decoded_p->slot_no, flag);
 872                     //sim_printf ("fnp break_all\r\n");
 873                     linep->breakAll = !! flag;
 874                   }
 875                   break;
 876 
 877                 case 28: // Prefixnl
 878                   {
 879                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        alter_parameters prefixnl %u\r\n",
 880                                decoded_p->slot_no, flag);
 881                     //sim_printf ("fnp prefixnl\r\n");
 882                     linep->prefixnl = !! flag;
 883                   }
 884                   break;
 885 
 886                 case 29: // Input_flow_control
 887                   {
 888                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        alter_parameters input_flow_control %u\r\n",
 889                                decoded_p->slot_no, flag);
 890                     //sim_printf ("fnp input_flow_control\r\n");
 891                     linep->input_flow_control = !! flag;
 892                   }
 893                   break;
 894 
 895                 case 30: // Output_flow_control
 896                   {
 897                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        alter_parameters output_flow_control %u\r\n",
 898                                decoded_p->slot_no, flag);
 899                     //sim_printf ("fnp output_flow_control\r\n");
 900                     linep->output_flow_control = !! flag;
 901                   }
 902                   break;
 903 
 904                 case 31: // Odd_parity
 905                   {
 906                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        alter_parameters odd_parity %u\r\n",
 907                                decoded_p->slot_no, flag);
 908                     //sim_printf ("fnp odd_parity\r\n");
 909                     linep->odd_parity = !! flag;
 910                   }
 911                   break;
 912 
 913                 case 32: // Eight_bit_in
 914                   {
 915                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        alter_parameters eight_bit_in %u\r\n",
 916                                decoded_p->slot_no, flag);
 917                     //sim_printf ("fnp eight_bit_in\r\n");
 918                     linep->eight_bit_in = !! flag;
 919                   }
 920                   break;
 921 
 922                 case 33: // Eight_bit_out
 923                   {
 924                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        alter_parameters eight_bit_out %u\r\n",
 925                                decoded_p->slot_no, flag);
 926                     //sim_printf ("fnp eight_bit_out\r\n");
 927                     linep->eight_bit_out = !! flag;
 928                   }
 929                   break;
 930 
 931                 case  1: // Breakchar
 932                 case  2: // Nocontrol
 933                 case  4: // Break
 934                 case  5: // Errormsg
 935                 case  6: // Meter
 936                 case  7: // Sensepos
 937                 case 10: // Lock
 938                 case 11: // Msg
 939                 case 12: // Upstate
 940                 case 15: // Setbusy
 941                 case 21: // Xmit_hold
 942                   {
 943                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        alter_parameters unimplemented\r\n",
 944                                decoded_p->slot_no);
 945                     sim_printf ("fnp unimplemented subtype %d (%o)\r\n", subtype, subtype);
 946                     // doFNPfault (...) // XXX
 947                     return -1;
 948                   }
 949 
 950                 default:
 951                   {
 952                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        alter_parameters illegal\r\n",
 953                                decoded_p->slot_no);
 954                     sim_printf ("fnp illegal subtype %d (%o)\r\n", subtype, subtype);
 955                     // doFNPfault (...) // XXX
 956                     return -1;
 957                   }
 958               } // switch (subtype)
 959           }
 960           break; // alter_parameters
 961 
 962         case 37: // set_delay_table
 963           {
 964             sim_debug (DBG_TRACE, & fnp_dev, "[%u]    set_delay_table\r\n", decoded_p->slot_no);
 965             //sim_printf ("fnp set delay table\r\n");
 966             uint d1 = getbits36_18 (command_data[0], 0);
 967             uint d2 = getbits36_18 (command_data[0], 18);
 968 
 969             uint d3 = getbits36_18 (command_data[1], 0);
 970             uint d4 = getbits36_18 (command_data[1], 18);
 971 
 972             uint d5 = getbits36_18 (command_data[2], 0);
 973             uint d6 = getbits36_18 (command_data[2], 18);
 974 
 975             linep->delay_table[0] = d1;
 976             linep->delay_table[1] = d2;
 977             linep->delay_table[2] = d3;
 978             linep->delay_table[3] = d4;
 979             linep->delay_table[4] = d5;
 980             linep->delay_table[5] = d6;
 981           }
 982           break;
 983 
 984 //  dcl  fnp_chan_meterp pointer;
 985 //  dcl  FNP_CHANNEL_METERS_VERSION_1 fixed bin int static options (constant) init (1);
 986 //
 987 //  dcl 1 fnp_chan_meter_struc based (fnp_chan_meterp) aligned,
 988 //      2 version fixed bin,
 989 //      2 flags,
 990 //        3 synchronous bit (1) unaligned,
 991 //        3 reserved bit (35) unaligned,
 992 //      2 current_meters like fnp_channel_meters,
 993 //      2 saved_meters like fnp_channel_meters;
 994 //
 995 
 996 /*NOTREACHED*/ /* unreachable */
 997 
 998 //  dcl 1 fnp_channel_meters based aligned,
 999 struct fnp_channel_meters //-V779
1000   {
1001 //      2 header,
1002 struct header //-V779
1003   { //-V779
1004 //        3 dia_request_q_len fixed bin (35),                             /* cumulative */
1005 word36 dia_request_q_len; //-V779
1006 //        3 dia_rql_updates fixed bin (35),                     /* updates to above */
1007 word36 dia_rql_updates; //-V779
1008 //        3 pending_status fixed bin (35),                      /* cumulative */
1009 word36 pending_status; //-V779
1010 //        3 pending_status_updates fixed bin (35),              /* updates to above */
1011 word36 pending_status_updates; //-V779
1012 //        3 output_overlaps fixed bin (18) unsigned unaligned,  /* output chained to already-existing chain */
1013 //        3 parity_errors fixed bin (18) unsigned unaligned,    /* parity on the channel */
1014 word36 output_overlaps___parity_errors; //-V779
1015 //        3 software_status_overflows fixed bin (18) unsigned unaligned,
1016 //        3 hardware_status_overflows fixed bin (18) unsigned unaligned,
1017 word36 software_status_overflows___hardware_status_overflows; //-V779
1018 //        3 input_alloc_failures fixed bin (18) unsigned unaligned,
1019 //        3 dia_current_q_len fixed bin (18) unsigned unaligned,          /* current length of dia request queue */
1020 word36 input_alloc_failures___dia_current_q_len; //-V779
1021 //        3 exhaust fixed bin (35),
1022 word36 exhaust; //-V779
1023 //        3 software_xte fixed bin (18) unsigned unaligned,
1024 //        3 pad bit (18) unaligned,
1025 word36 software_xte___sync_or_async; //-V779
1026   } header; //-V779
1027 //      2 sync_or_async (17) fixed bin;                         /* placeholder for meters for sync or async channels */
1028 word36 sync_or_async; //-V779
1029   }; //-V779
1030 
1031 //
1032 //  dcl 1 fnp_sync_meters based aligned,
1033 //      2 header like fnp_channel_meters.header,
1034 //      2 input,
1035 //        3 message_count fixed bin (35),                       /* total number of messages */
1036 //        3 cum_length fixed bin (35),                          /* total cumulative length in characters */
1037 //        3 min_length fixed bin (18) unsigned unaligned,       /* length of shortest message */
1038 //        3 max_length fixed bin (18) unsigned unaligned,       /* length of longest message */
1039 //      2 output like fnp_sync_meters.input,
1040 //      2 counters (8) fixed bin (35),
1041 //      2 pad (3) fixed bin;
1042 //
1043 //  dcl 1 fnp_async_meters based aligned,
1044 struct fnp_async_meters //-V779
1045   { //-V779
1046 //      2 header like fnp_channel_meters.header,
1047 //      2 pre_exhaust fixed bin (35),
1048 word36 pre_exhaust; //-V779
1049 //      2 echo_buf_overflow fixed bin (35),                     /* number of times echo buffer has overflowed */
1050 word36 echo_buf_overflow; //-V779
1051 //      2 bell_quits fixed bin (18) unsigned unaligned,
1052 //      2 padb bit (18) unaligned,
1053 word36 bell_quits___pad; //-V779
1054 //      2 pad (14) fixed bin;
1055 word36 pad; //-V779
1056   }; //-V779
1057 //
1058         case 36: // report_meters
1059           {
1060             sim_debug (DBG_TRACE, & fnp_dev, "[%u]    report_meters\r\n", decoded_p->slot_no);
1061             //sim_printf ("fnp report_meters\r\n");
1062 // XXX Do nothing, the request will timeout...
1063           }
1064           break;
1065 
1066         case  0: // terminal_accepted
1067         case  2: // disconnect_all_lines
1068         case  5: // input_accepted
1069         case  7: // enter_receive
1070         case  9: // blast
1071         case 10: // accept_direct_output
1072         case 11: // accept_last_output
1073       //case 13: // ???
1074         case 14: // reject_request_temp
1075       //case 15: // ???
1076         case 16: // terminal_rejected
1077         case 17: // disconnect_accepted
1078         case 18: // init_complete
1079         case 19: // dump_mem
1080         case 20: // patch_mem
1081         case 21: // fnp_break
1082       //case 24: // set_echnego_break_table
1083       //case 25: // start_negotiated_echo
1084       //case 26: // stop_negotiated_echo
1085       //case 27: // init_echo_negotiation
1086       //case 28: // ???
1087         case 29: // break_acknowledged
1088       //case 32: // ???
1089       //case 33: // ???
1090         case 35: // checksum_error
1091           {
1092             sim_debug (DBG_TRACE, & fnp_dev, "[%u]    unimplemented opcode\r\n", decoded_p->slot_no);
1093             sim_warn ("fnp unimplemented opcode %d (%o)\r\n", decoded_p->op_code, decoded_p->op_code);
1094             //sim_debug (DBG_ERR, & fnp_dev, "fnp unimplemented opcode %d (%o)\r\n", decoded_p->op_code, decoded_p->op_code);
1095             //sim_printf ("fnp unimplemented opcode %d (%o)\r\n", decoded_p->op_code, decoded_p->op_code);
1096             // doFNPfault (...) // XXX
1097             //return -1;
1098           }
1099         break;
1100 
1101         default:
1102           {
1103             sim_debug (DBG_TRACE, & fnp_dev, "[%u]fnp illegal opcode %d (%o)\r\n",
1104                        decoded_p->slot_no, decoded_p->op_code, decoded_p->op_code);
1105             // doFNPfault (...) // XXX
1106             return -1;
1107           }
1108       } // switch decoded_p->op_code
1109 
1110     setTIMW (decoded_p->iom_unit, decoded_p->chan_num, decoded_p->fudp->mailboxAddress, (int) decoded_p->cell);
1111 
1112     send_general_interrupt (decoded_p->iom_unit, decoded_p->chan_num, imwTerminatePic);
1113 
1114     return 0;
1115   }
1116 
1117 #if defined(TUN)
1118 static void tun_write (struct t_line * linep, uint16_t * data, uint tally)
     /* [previous][next][first][last][top][bottom][index][help] */
1119   {
1120 
1121 
1122 
1123 
1124 
1125 // XXX this code is buggy; if a buffer is received with an embedded frame start, the embedded frame
1126 // XXX will be lost
1127 
1128     for (uint i = 0; i < tally; i ++)
1129       {
1130         // Check for start of frame...
1131         if (data [i] == 0x100)
1132           {
1133             linep->in_frame = true;
1134             linep->frameLen = 0;
1135             continue;
1136           }
1137 
1138         if (! linep->in_frame)
1139           continue;
1140 
1141         if (linep->frameLen >= 2+1500)
1142           {
1143             sim_printf ("inFrame overrun\r\n");
1144             break;
1145           }
1146         linep->frame[linep->frameLen ++] = (uint8_t) (data [i] & 0xff);
1147       }
1148 
1149 // Is frame complete?
1150 
1151       if (linep->frameLen >= 2)
1152         {
1153           uint16_t target = (uint16_t) ((linep->frame[0] & 0xff) << 8) | (linep->frame[1]);
1154           if (target + 2 >= linep->frameLen)
1155             {
1156               sim_printf ("frame received\r\n");
1157               fnpuv_tun_write (linep);
1158               linep->in_frame = false;
1159             }
1160         }
1161   }
1162 #endif
1163 
1164 static void fnp_wtx_output (struct decoded_t *decoded_p, uint tally, uint dataAddr)
     /* [previous][next][first][last][top][bottom][index][help] */
1165   {
1166 #if defined(TESTING)
1167     cpu_state_t * cpup = _cpup;
1168     sim_debug (DBG_TRACE, & fnp_dev, "[%u]rcd wtx_output\r\n", decoded_p->slot_no);
1169 #endif
1170     struct t_line * linep = & decoded_p->fudp->MState.line[decoded_p->slot_no];
1171 
1172     uint wordOff     = 0;
1173     word36 word      = 0;
1174     uint lastWordOff = (uint) -1;
1175 #if defined(TUN)
1176     uint16_t data9 [tally];
1177 #endif
1178     unsigned char data [tally];
1179 
1180     for (uint i = 0; i < tally; i ++)
1181        {
1182          uint byteOff = i % 4;
1183          uint byte = 0;
1184 
1185          wordOff = i / 4;
1186 
1187          if (wordOff != lastWordOff)
1188            {
1189              lastWordOff = wordOff;
1190              iom_direct_data_service (decoded_p->iom_unit, decoded_p->chan_num, dataAddr + wordOff, & word, direct_load);
1191            }
1192          byte = getbits36_9 (word, byteOff * 9);
1193          data [i] = byte & 0377;
1194 #if defined(TUN)
1195          data9 [i] = (uint16_t) byte;
1196 #endif
1197 
1198 //sim_printf ("   %03o %c\r\n", data [i], isgraph (data [i]) ? data [i] : '.');
1199        }
1200 
1201 
1202 
1203 
1204 
1205 
1206 
1207 
1208 
1209 
1210 
1211 
1212 
1213 
1214 #if defined(TUN)
1215     if (linep->is_tun && tally > 0)
1216       {
1217         tun_write (linep, data9, tally);
1218         return;
1219      }
1220 #endif
1221     if (tally > 0 && linep->line_client)
1222       {
1223         if (! linep->line_client || ! linep->line_client->data) //-V560
1224           {
1225             sim_warn ("fnp_wtx_output bad client data\r\n");
1226             return;
1227           }
1228         uvClientData * p = linep->line_client->data;
1229         (* p->write_cb) (linep->line_client, data, tally);
1230       }
1231   }
1232 
1233 static int wtx (struct decoded_t *decoded_p)
     /* [previous][next][first][last][top][bottom][index][help] */
1234   {
1235 #if defined(TESTING)
1236     cpu_state_t * cpup = _cpup;
1237     sim_debug (DBG_TRACE, & fnp_dev, "[%u]wtx op_code %u 0%o\r\n", decoded_p->slot_no, decoded_p->op_code, decoded_p->op_code);
1238 #endif
1239 //sim_printf ("wtx op_code %o (%d.) %c.h%03d\r\n",
1240 //            decoded_p->op_code, decoded_p->op_code,
1241 //            decoded_p->devUnitIdx+'a', decoded_p->slot_no);
1242     if (decoded_p->op_code != 012 && decoded_p->op_code != 014) //-V536
1243       {
1244         sim_debug (DBG_TRACE, & fnp_dev, "[%u]     unimplemented opcode\r\n", decoded_p->slot_no);
1245         sim_debug (DBG_ERR, & fnp_dev, "[%u]fnp wtx unimplemented opcode %d (%o)\r\n",
1246                    decoded_p->slot_no, decoded_p->op_code, decoded_p->op_code);
1247          sim_printf ("fnp wtx unimplemented opcode %d (%o)\r\n", decoded_p->op_code, decoded_p->op_code);
1248         // doFNPfault (...) // XXX
1249         return -1;
1250       }
1251 // op_code is 012
1252     word36 data;
1253     iom_direct_data_service (decoded_p->iom_unit, decoded_p->chan_num, decoded_p->smbx+WORD6, & data, direct_load);
1254     uint dcwAddr = getbits36_18 (data, 0);
1255     uint dcwCnt = getbits36_9 (data, 27);
1256     //uint sent = 0;
1257 
1258     // For each dcw
1259     for (uint i = 0; i < dcwCnt; i ++)
1260       {
1261         // The address of the dcw in the dcw list
1262         // The dcw
1263         word36 dcw;
1264         iom_direct_data_service (decoded_p->iom_unit, decoded_p->chan_num, dcwAddr + i, & dcw, direct_load);
1265 
1266         // Get the address and the tally from the dcw
1267         uint dataAddr = getbits36_18 (dcw, 0);
1268         uint tally = getbits36_9 (dcw, 27);
1269         //sim_printf ("%6d %012o\r\n", tally, dataAddr);
1270         if (! tally)
1271           continue;
1272         fnp_wtx_output (decoded_p, tally, dataAddr);
1273         //sent += tally;
1274       } // for each dcw
1275 
1276     setTIMW (decoded_p->iom_unit, decoded_p->chan_num, decoded_p->fudp->mailboxAddress, (int) decoded_p->cell);
1277 
1278     send_general_interrupt (decoded_p->iom_unit, decoded_p->chan_num, imwTerminatePic);
1279 
1280 
1281 
1282 
1283 
1284 
1285 
1286 
1287 
1288 
1289 
1290     decoded_p->fudp->MState.line[decoded_p->slot_no].send_output = SEND_OUTPUT_DELAY;
1291 
1292     return 0;
1293   }
1294 
1295 static void fnp_rtx_input_accepted (struct decoded_t *decoded_p)
     /* [previous][next][first][last][top][bottom][index][help] */
1296   {
1297 // AN85-01 pg 232 A-6
1298 //
1299 //  Input Accepted (005)
1300 //
1301 //    Purpose:
1302 //      Response to an accept input operation by providing the address
1303 //      (in the circular buffer) to which input is sent.
1304 //
1305 //    Associated Data:
1306 //      Word 5: Bits 0..17 contain the beginning absolute address of the
1307 //      portion of the circular buffer into which the input is to be placed.
1308 //
1309 //      Bits 18...35 contain the number of characters to be placed in the
1310 //      specified location.
1311 //
1312 //      Word 4: If non-zero, contains the address and tally as described
1313 //      above for the remaining data. This word is only used if the input
1314 //      request required a wraparound of the circular buffer.
1315 //
1316 
1317 #if defined(TESTING)
1318     cpu_state_t * cpup = _cpup;
1319 #endif
1320     word36 word2;
1321     iom_direct_data_service (decoded_p->iom_unit, decoded_p->chan_num, decoded_p->fsmbx+WORD2, & word2, direct_load);
1322     uint n_chars = getbits36_18 (word2, 0);
1323 
1324     word36 n_buffers;
1325     iom_direct_data_service (decoded_p->iom_unit, decoded_p->chan_num, decoded_p->fsmbx+N_BUFFERS, & n_buffers, direct_load);
1326 
1327     struct t_line * linep = & decoded_p->fudp->MState.line[decoded_p->slot_no];
1328     unsigned char * data_p = linep -> buffer;
1329 
1330     n_chars = min(n_chars, linep -> nPos);
1331 
1332     // The response lives in a 28-word FNP submailbox.  N_BUFFERS is guest
1333     // supplied and the 24 DCW slots are the only ones we may read.  The
1334     // tallies here count input characters, not packed 36-bit words. Validate
1335     // all of them before writing anything to the guest's input buffers.
1336     if (!linep->input_reply_pending || linep->input_cancelled)
1337       {
1338         if (!linep->input_cancelled)
1339           sim_warn ("FNP input_accepted without pending input on line %u\r\n",
1340                     decoded_p->slot_no);
1341         linep->input_reply_pending = false;
1342         linep->input_cancelled = false;
1343         linep->input_retry_at_ns = 0;
1344         goto finish_input_response;
1345       }
1346 
1347     word36 dcws[N_DCWS];
1348     uint total_tally = 0;
1349     bool valid = n_buffers <= N_DCWS && (n_chars == 0 || n_buffers != 0);
1350     if (valid)
1351       for (uint j = 0; j < (uint)n_buffers; j++)
1352         {
1353           iom_direct_data_service (decoded_p->iom_unit, decoded_p->chan_num,
1354                                    decoded_p->fsmbx+DCWS+j, &dcws[j], direct_load);
1355           total_tally += getbits36_12 (dcws[j], 24);
1356         }
1357     if (!valid || total_tally < n_chars)
1358       {
1359         sim_warn ("FNP input_accepted has invalid DCWs on line %u "
1360                   "(buffers %llu, allocated %u, requested %u); retrying\r\n",
1361                   decoded_p->slot_no, (unsigned long long)n_buffers,
1362                   total_tally, n_chars);
1363         fnpScheduleInputRetry (linep);
1364         goto finish_input_response;
1365       }
1366 
1367     uint off = 0;
1368     for (uint j = 0; j < n_buffers && off < n_chars; j++)
1369       {
1370         word36 data = dcws[j];
1371         word24 addr = getbits36_24 (data, 0);
1372         word12 tally = getbits36_12 (data, 24);
1373 
1374 if_sim_debug (DBG_TRACE, & fnp_dev) {
1375 { sim_printf ("[%u][FNP emulator: nPos %d long IN: '", decoded_p->slot_no, linep->nPos);
1376 for (uint i = 0; i < linep->nPos; i ++)
1377 {
1378 if (isgraph (linep->buffer [i]))
1379 sim_printf ("%c", linep->buffer [i]);
1380 else
1381 sim_printf ("\\%03o", linep->buffer [i]);
1382 }
1383 sim_printf ("']\r\n");
1384 }
1385 }
1386 
1387 //sim_printf ("long  in; line %d tally %d\r\n", decoded_p->slot_no, linep->nPos);
1388         uint n_chars_in_buf = min(n_chars-off, tally);
1389         for (uint i = 0; i < n_chars_in_buf; i += 4)
1390           {
1391             word36 v = 0;
1392             if (i < n_chars_in_buf) //-V547
1393               putbits36_9 (& v, 0, data_p [off++]);
1394             if (i + 1 < n_chars_in_buf)
1395               putbits36_9 (& v, 9, data_p [off++]);
1396             if (i + 2 < n_chars_in_buf)
1397               putbits36_9 (& v, 18, data_p [off++]);
1398             if (i + 3 < n_chars_in_buf)
1399               putbits36_9 (& v, 27, data_p [off++]);
1400             iom_direct_data_service (decoded_p->iom_unit, decoded_p->chan_num, addr, & v, direct_store);
1401             addr ++;
1402           }
1403       }
1404     // XXX temporary until the logic is in place
1405     // This appears to only be used in tty_interrupt.pl1 as
1406     // rtx_info.output_in_fnp as part of echo negotiation:
1407     //    if ^rtx_info.output_in_fnp  /* if there's no output going on */
1408     // So apparently a flag indicating that there is output queued.
1409     word1 output_chain_present = 1;
1410 
1411     word36 v;
1412     iom_direct_data_service (decoded_p->iom_unit, decoded_p->chan_num,  decoded_p->fsmbx+INP_COMMAND_DATA, &v, direct_load);
1413     l_putbits36_1 (& v, 16, output_chain_present);
1414     // A short grant must not claim that a break terminating the *original*
1415     // input batch has already been delivered.
1416     l_putbits36_1 (& v, 17, linep->input_break && n_chars == linep->nPos ? 1 : 0);
1417     iom_direct_data_service (decoded_p->iom_unit, decoded_p->chan_num,  decoded_p->fsmbx+INP_COMMAND_DATA, &v, direct_store);
1418 
1419     // A short grant, including a zero-length grant, leaves input pending.
1420     // Preserve its order, carry the break flag through the final fragment,
1421     // and use the same bounded retry as a temporary buffer rejection.
1422     const bool short_grant = n_chars < linep->nPos;
1423     if (short_grant)
1424       {
1425         if (n_chars)
1426           memmove (linep->buffer, linep->buffer + n_chars,
1427                    linep->nPos - n_chars);
1428         linep->nPos -= n_chars;
1429         fnpScheduleInputRetry (linep);
1430       }
1431     else
1432       {
1433         linep->input_break = false;
1434         linep->nPos = 0;
1435         linep->input_retry_at_ns = 0;
1436       }
1437     linep->input_reply_pending = false;
1438 
1439 finish_input_response:
1440     setTIMW (decoded_p->iom_unit, decoded_p->chan_num, decoded_p->fudp->mailboxAddress, (int) decoded_p->cell);
1441 
1442     send_general_interrupt (decoded_p->iom_unit, decoded_p->chan_num, imwTerminatePic);
1443   }
1444 
1445 static int interruptL66_CS_to_FNP (struct decoded_t *decoded_p)
     /* [previous][next][first][last][top][bottom][index][help] */
1446   {
1447 #if defined(TESTING)
1448     cpu_state_t * cpup = _cpup;
1449 #endif
1450     uint mbx = decoded_p->cell;
1451     //ASSURE(mbx < 8);
1452     if (mbx >= 8)
1453       {
1454         sim_warn ("bad mbx number in interruptL66_CS_to_FNP; dropping\r\n");
1455         return -1;
1456       }
1457     decoded_p->smbx = decoded_p->fudp->mailboxAddress + DN355_SUB_MBXES + mbx*DN355_SUB_MBX_SIZE;
1458 
1459     word36 word2;
1460     iom_direct_data_service (decoded_p->iom_unit, decoded_p->chan_num, decoded_p->smbx+WORD2, & word2, direct_load);
1461     //uint cmd_data_len = getbits36_9 (word2, 9);
1462     decoded_p->op_code = getbits36_9 (word2, 18);
1463     uint io_cmd = getbits36_9 (word2, 27);
1464 
1465     word36 word1;
1466     iom_direct_data_service (decoded_p->iom_unit, decoded_p->chan_num, decoded_p->smbx+WORD1, & word1, direct_load);
1467     decoded_p->slot_no = getbits36_6 (word1, 12);
1468 
1469     sim_debug (DBG_TRACE, & fnp_dev, "io_cmd %u\r\n", io_cmd);
1470     switch (io_cmd)
1471       {
1472 
1473 
1474 
1475 
1476 
1477 
1478 
1479 
1480 
1481         case 3: // wcd (write control data)
1482           {
1483             int ret = wcd (decoded_p);
1484             if (ret)
1485               return ret;
1486           }
1487           break;
1488 
1489         case 4: // wtx (write text)
1490           {
1491             int ret = wtx (decoded_p);
1492             if (ret)
1493               return ret;
1494           }
1495           break;
1496 
1497         case 1: // rcd (read control data)
1498           {
1499             sim_debug (DBG_TRACE, & fnp_dev, "[%u]rcd unimplemented\r\n", decoded_p->slot_no);
1500             sim_debug (DBG_ERR, & fnp_dev, "[%u]fnp unimplemented io_cmd %d\r\n", decoded_p->slot_no, io_cmd);
1501              sim_printf ("fnp unimplemented io_cmd %d\r\n", io_cmd);
1502             // doFNPfault (...) // XXX
1503             return -1;
1504           }
1505         default:
1506           {
1507             sim_debug (DBG_TRACE, & fnp_dev, "[%u]rcd illegal opcode\r\n", decoded_p->slot_no);
1508             sim_debug (DBG_ERR, & fnp_dev, "[%u]fnp illegal io_cmd %d\r\n", decoded_p->slot_no, io_cmd);
1509             sim_printf ("fnp illegal io_cmd %d\r\n", io_cmd);
1510             // doFNPfault (...) // XXX
1511             return -1;
1512           }
1513       } // switch (io_cmd)
1514     return 0;
1515   }
1516 
1517 static int interruptL66_FNP_to_CS (struct decoded_t *decoded_p)
     /* [previous][next][first][last][top][bottom][index][help] */
1518   {
1519     // The CS has updated the FNP sub mailbox; this acknowledges processing
1520     // of the FNP->CS command that was in the submailbox
1521 
1522 #if defined(TESTING)
1523     cpu_state_t * cpup = _cpup;
1524 #endif
1525     uint mbx = decoded_p->cell - 8;
1526     //ASSURE(mbx < 4);
1527     if (mbx >= 4)
1528       {
1529         sim_warn ("bad mbx number in interruptL66_FNP_to_CS; dropping\r\n");
1530         return -1;
1531       }
1532     decoded_p->fsmbx = decoded_p->fudp->mailboxAddress + FNP_SUB_MBXES + mbx*FNP_SUB_MBX_SIZE;
1533 
1534 
1535 
1536 
1537 
1538 
1539 
1540 
1541     word36 word2;
1542     iom_direct_data_service (decoded_p->iom_unit, decoded_p->chan_num, decoded_p->fsmbx+WORD2, & word2, direct_load);
1543     //uint cmd_data_len = getbits36_9 (word2, 9);
1544     uint op_code = getbits36_9 (word2, 18);
1545     uint io_cmd = getbits36_9 (word2, 27);
1546 
1547     word36 word1;
1548     iom_direct_data_service (decoded_p->iom_unit, decoded_p->chan_num, decoded_p->fsmbx+WORD1, & word1, direct_load);
1549     //uint dn355_no = getbits36_3 (word1, 0);
1550     //uint is_hsla = getbits36_1 (word1, 8);
1551     //uint la_no = getbits36_3 (word1, 9);
1552     decoded_p->slot_no = getbits36_6 (word1, 12);
1553     //uint terminal_id = getbits36_18 (word1, 18);
1554 
1555     sim_debug (DBG_TRACE, & fnp_dev, "[%u]fnp interrupt\r\n", decoded_p->slot_no);
1556     switch (io_cmd)
1557       {
1558         case 2: // rtx (read transmission)
1559           {
1560             sim_debug (DBG_TRACE, & fnp_dev, "[%u]    rtx\r\n", decoded_p->slot_no);
1561             switch (op_code)
1562               {
1563                 case  5: // input_accepted
1564                   {
1565                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        input_accepted\r\n", decoded_p->slot_no);
1566                     fnp_rtx_input_accepted (decoded_p);
1567                   }
1568                   break;
1569                 default:
1570                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        illegal rtx ack\r\n", decoded_p->slot_no);
1571                   sim_warn ("rtx %d. %o ack ignored\r\n", op_code, op_code);
1572                   break;
1573               }
1574               break;
1575           }
1576         case 3: // wcd (write control data)
1577           {
1578             sim_debug (DBG_TRACE, & fnp_dev, "[%u]    wcd\r\n", decoded_p->slot_no);
1579             switch (op_code)
1580               {
1581                 case  0: // terminal_accepted
1582                   {
1583                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        terminal accepted\r\n", decoded_p->slot_no);
1584                     // outputBufferThreshold Ignored
1585                     //word36 command_data0 = decoded_p->fsmbxp -> mystery [0];
1586                     //uint outputBufferThreshold = getbits36_18 (command_data0, 0);
1587                     //sim_printf ("  outputBufferThreshold %d\r\n", outputBufferThreshold);
1588 
1589                     // Prime the pump
1590                     //decoded_p->fudp->MState.line[decoded_p->slot_no].send_output = true;
1591                     decoded_p->fudp->MState.line[decoded_p->slot_no].send_output = SEND_OUTPUT_DELAY;
1592                     // The common WCD completion path below releases the
1593                     // matching mailbox's wait state, including this one.
1594                   }
1595                   break;
1596 
1597                 case  1: // disconnect_this_line
1598                   {
1599                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        disconnect_this_line\r\n", decoded_p->slot_no);
1600                     //sim_printf ("disconnect_this_line ack.\r\n");
1601                   }
1602                   break;
1603 
1604                 case 14: // reject_request_temp
1605                   {
1606                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        reject_request_temp\r\n", decoded_p->slot_no);
1607                     struct t_line * linep = &decoded_p->fudp->MState.line[decoded_p->slot_no];
1608                     // Both accept_input and input_in_mailbox can be rejected
1609                     // for lack of Multics buffers.  Retain the same bytes
1610                     // and retry after one second, as the DN355 did.
1611                     if (decoded_p->fudp->lineWaiting[mbx] &&
1612                         decoded_p->fudp->fnpMBXlineno[mbx] == (int)decoded_p->slot_no &&
1613                         (linep->input_reply_pending || linep->input_in_mailbox_pending))
1614                       {
1615                         if (linep->input_cancelled)
1616                           {
1617                             // The connection went away while Multics was
1618                             // deciding.  Do not replay old input to a new
1619                             // connection on the same FNP line.
1620                             linep->input_reply_pending = false;
1621                             linep->input_in_mailbox_pending = false;
1622                             linep->input_cancelled = false;
1623                             linep->accept_input = 0;
1624                             linep->input_retry_at_ns = 0;
1625                           }
1626                         else
1627                           fnpScheduleInputRetry (linep);
1628                       }
1629                     else
1630                       sim_warn ("FNP temporary reject without matching pending input on line %u\r\n",
1631                                 decoded_p->slot_no);
1632                   }
1633                   break;
1634 
1635                 case  2: // disconnect_all_lines
1636                 case  3: // dont_accept_calls
1637                 case  4: // accept_calls
1638                 case  5: // input_accepted
1639                 case  6: // set_line_type
1640                 case  7: // enter_receive
1641                 case  8: // set_framing_chars
1642                 case  9: // blast
1643                 case 10: // accept_direct_output
1644                 case 11: // accept_last_output
1645                 case 12: // dial
1646               //case 13: // ???
1647               //case 15: // ???
1648                 case 16: // terminal_rejected
1649                 case 17: // disconnect_accepted
1650                 case 18: // init_complete
1651                 case 19: // dump_mem
1652                 case 20: // patch_mem
1653                 case 21: // fnp_break
1654                 case 22: // line_control
1655                 case 23: // sync_msg_size
1656                 case 24: // set_echnego_break_table
1657                 case 25: // start_negotiated_echo
1658                 case 26: // stop_negotiated_echo
1659                 case 27: // init_echo_negotiation
1660               //case 28: // ???
1661                 case 29: // break_acknowledged
1662                 case 30: // input_fc_chars
1663                 case 31: // output_fc_chars
1664               //case 32: // ???
1665               //case 33: // ???
1666                 case 34: // alter_parameters
1667                 case 35: // checksum_error
1668                 case 36: // report_meters
1669                 case 37: // set_delay_table
1670                   {
1671                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        unimplemented opcode\r\n", decoded_p->slot_no);
1672                     sim_debug (DBG_ERR, & fnp_dev, "[%u]fnp reply unimplemented opcode %d (%o)\r\n",
1673                                decoded_p->slot_no, op_code, op_code);
1674                     sim_printf ("fnp reply unimplemented opcode %d (%o)\r\n", op_code, op_code);
1675                     // doFNPfault (...) // XXX
1676                     return -1;
1677                   }
1678 
1679                 default:
1680                   {
1681                     sim_debug (DBG_TRACE, & fnp_dev, "[%u]        illegal opcode\r\n", decoded_p->slot_no);
1682                     sim_debug (DBG_ERR, & fnp_dev, "[%u]fnp reply illegal opcode %d (%o)\r\n",
1683                                decoded_p->slot_no, op_code, op_code);
1684                     sim_printf ("fnp reply illegal opcode %d (%o)\r\n", op_code, op_code);
1685                     // doFNPfault (...) // XXX
1686                     return -1;
1687                   }
1688               } // switch op_code
1689 
1690             // Set the TIMW
1691 
1692             // Not sure... XXX
1693             //putbits36_1 (& mbxp -> term_inpt_mpx_wd, cell, 1);
1694             // No; the CS has told us it has updated the mbx, and
1695             // we need to read it; we have done so, so we are finished
1696             // with the mbx, and can mark it so.
1697             if (decoded_p->fudp->fnpMBXinUse[mbx] &&
1698                 decoded_p->fudp->lineWaiting[mbx])
1699               {
1700                 int pending_line = decoded_p->fudp->fnpMBXlineno[mbx];
1701                 if (pending_line >= 0 && pending_line < MAX_LINES)
1702                   decoded_p->fudp->MState.line[pending_line].waitForMbxDone = false;
1703                 else
1704                   sim_warn ("FNP mailbox %u has invalid waiting line %d\r\n", mbx, pending_line);
1705               }
1706             decoded_p->fudp->lineWaiting[mbx] = false;
1707             decoded_p->fudp->fnpMBXinUse[mbx] = false;
1708 
1709           } // case wcd
1710           break;
1711 
1712         default:
1713           {
1714             sim_debug (DBG_TRACE, & fnp_dev, "[%u]        illegal io_cmd\r\n", decoded_p->slot_no);
1715             sim_debug (DBG_ERR, & fnp_dev, "[%u]illegal/unimplemented io_cmd (%d) in fnp submbx\r\n",
1716                        decoded_p->slot_no, io_cmd);
1717             sim_printf ("illegal/unimplemented io_cmd (%d) in fnp submbx\r\n", io_cmd);
1718             // doFNPfault (...) // XXX
1719             return -1;
1720           }
1721       } // switch (io_cmd)
1722     return 0;
1723   }
1724 
1725 static int interruptL66_CS_done (struct decoded_t *decoded_p)
     /* [previous][next][first][last][top][bottom][index][help] */
1726   {
1727 #if defined(TESTING)
1728     cpu_state_t * cpup = _cpup;
1729 #endif
1730     uint mbx = decoded_p->cell - 12;
1731     //ASSURE(mbx < 4);
1732     if (mbx >= 4)
1733       {
1734         sim_warn ("bad mbx number in interruptL66_CS_done; dropping\r\n");
1735         return -1;
1736       }
1737     if (! decoded_p->fudp -> fnpMBXinUse [mbx])
1738       {
1739         sim_debug (DBG_ERR, & fnp_dev, "odd -- Multics marked an unused mbx as unused? cell %d (mbx %d)\r\n",
1740                    decoded_p->cell, mbx);
1741         sim_debug (DBG_ERR, & fnp_dev, "  %d %d %d %d\r\n",
1742                    decoded_p->fudp -> fnpMBXinUse [0], decoded_p->fudp -> fnpMBXinUse [1],
1743                    decoded_p->fudp -> fnpMBXinUse [2], decoded_p->fudp -> fnpMBXinUse [3]);
1744       }
1745     else
1746       {
1747         sim_debug (DBG_TRACE, & fnp_dev, "Multics marked cell %d (mbx %d) as unused; was %o\r\n",
1748                    decoded_p->cell, mbx, decoded_p->fudp -> fnpMBXinUse [mbx]);
1749         decoded_p->fudp -> fnpMBXinUse [mbx] = false;
1750         if (decoded_p->fudp->lineWaiting[mbx])
1751           {
1752             int pending_line = decoded_p->fudp->fnpMBXlineno[mbx];
1753             if (pending_line >= 0 && pending_line < MAX_LINES)
1754               {
1755                 struct t_line * linep = &decoded_p->fudp->MState.line[pending_line];
1756                 // Short input is embedded in the mailbox, so CS_done is its
1757                 // successful acknowledgment.  Do not consume it on send:
1758                 // a WCD reject must be able to retransmit the same bytes.
1759                 if (linep->input_in_mailbox_pending)
1760                   {
1761                     linep->input_in_mailbox_pending = false;
1762                     if (linep->input_cancelled)
1763                       linep->input_cancelled = false;
1764                     else
1765                       {
1766                         linep->nPos = 0;
1767                         linep->input_break = false;
1768                         linep->input_retry_at_ns = 0;
1769                         // A break queued while the mailbox was in flight
1770                         // must follow it without sending an empty duplicate.
1771                         if (linep->line_break && linep->accept_input == 1)
1772                           linep->accept_input = 0;
1773                       }
1774                   }
1775                 sim_debug (DBG_TRACE, &fnp_dev, "clearing wait; was %d\r\n", linep->waitForMbxDone);
1776                 linep->waitForMbxDone = false;
1777               }
1778             else
1779               sim_warn ("FNP mailbox %u has invalid waiting line %d\r\n", mbx, pending_line);
1780           }
1781         decoded_p->fudp->lineWaiting[mbx] = false;
1782           sim_debug (DBG_TRACE, & fnp_dev, "  %d %d %d %d\r\n",
1783                      decoded_p->fudp->fnpMBXinUse [0], decoded_p->fudp->fnpMBXinUse [1],
1784                      decoded_p->fudp->fnpMBXinUse [2], decoded_p->fudp->fnpMBXinUse [3]);
1785       }
1786     return 0;
1787   }
1788 
1789 static int interruptL66 (uint iomUnitIdx, uint chan)
     /* [previous][next][first][last][top][bottom][index][help] */
1790   {
1791 #if defined(TESTING)
1792     cpu_state_t * cpup = _cpup;
1793 #endif
1794     struct decoded_t decoded;
1795     struct decoded_t *decoded_p = &decoded;
1796     decoded_p->iom_unit = iomUnitIdx;
1797     decoded_p->chan_num = chan;
1798     decoded_p->devUnitIdx = get_ctlr_idx (iomUnitIdx, chan);
1799     decoded_p->fudp = & fnpData.fnpUnitData [decoded_p->devUnitIdx];
1800     word36 dia_pcw;
1801     iom_direct_data_service (decoded_p->iom_unit, decoded_p->chan_num,
1802                              decoded_p->fudp->mailboxAddress+DIA_PCW, & dia_pcw, direct_load);
1803 
1804 // AN85, pg 13-5
1805 // When the CS has control information or output data to send
1806 // to the FNP, it fills in a submailbox as described in Section 4
1807 // and sends an interrupt over the DIA. This interrupt is handled
1808 // by dail as described above; when the submailbox is read, the
1809 // transaction control word is set to "submailbox read" so that when
1810 // the I/O completes and dtrans runs, the mailbox decoder (decmbx)
1811 // is called. the I/O command in the submail box is either WCD (for
1812 // control information) or WTX (for output data). If it is WCD,
1813 // decmbx dispatches according to a table of operation codes and
1814 // setting a flag in the IB and calling itest, the "test-state"
1815 // entry of the interpreter. n a few cases, the operation requires
1816 // further DIA I/O, but usually all that remains to be does is to
1817 // "free" the submailbox by turning on the corresponding bit in the
1818 // mailbox terminate interrupt multiplex word (see Section 4) and
1819 // set the transaction control word accordingly. When the I/O to
1820 // update TIMW terminates, the transaction is complete.
1821 //
1822 // If the I/O command is WTX, the submailbox contains the
1823 // address and length of a 'pseudo-DCW" list containing the
1824 // addresses and tallies of data buffers in tty_buf. In this case,
1825 // dia_man connects to a DCW list to read them into a reserved area
1826 // in dia_man. ...
1827 
1828 // interrupt level (in "cell"):
1829 //
1830 // mbxs 0-7 are CS -> FNP
1831 // mbxs 8--11 are FNP -> CS
1832 //
1833 //   0-7 Multics has placed a message for the FNP in mbx 0-7.
1834 //   8-11 Multics has updated mbx 8-11
1835 //   12-15 Multics is done with mbx 8-11  (n - 4).
1836 
1837     decoded_p->cell = getbits36_6 (dia_pcw, 24);
1838     sim_debug (DBG_TRACE, & fnp_dev, "CS interrupt %u\r\n", decoded_p->cell);
1839     if (decoded_p->cell < 8)
1840       {
1841         interruptL66_CS_to_FNP (decoded_p);
1842       }
1843     else if (decoded_p->cell >= 8 && decoded_p->cell <= 11) //-V560
1844       {
1845         interruptL66_FNP_to_CS (decoded_p);
1846       }
1847     else if (decoded_p->cell >= 12 && decoded_p->cell <= 15) //-V560
1848       {
1849         interruptL66_CS_done (decoded_p);
1850       }
1851     else
1852       {
1853         sim_debug (DBG_ERR, & fnp_dev, "fnp illegal cell number %d\r\n", decoded_p->cell);
1854         sim_printf ("fnp illegal cell number %d\r\n", decoded_p->cell);
1855         // doFNPfault (...) // XXX
1856         return -1;
1857       }
1858     return 0;
1859   }
1860 
1861 static void fnpcmdBootload (uint devUnitIdx)
     /* [previous][next][first][last][top][bottom][index][help] */
1862   {
1863 #if defined(TESTING)
1864     cpu_state_t * cpup = _cpup;
1865 #endif
1866     sim_printf("\r[FNP emulation: FNP %c received BOOTLOAD command]\r\n", (int)('a' + (int)devUnitIdx));
1867     fnpData.fnpUnitData[devUnitIdx].MState.accept_calls = false;
1868     bool have3270 = false;
1869     for (uint lineno = 0; lineno < MAX_LINES; lineno ++)
1870       {
1871         fnpData.fnpUnitData[devUnitIdx].MState.line [lineno] . listen = false;
1872         if (fnpData.fnpUnitData[devUnitIdx].MState.line [lineno].line_client)
1873           {
1874             fnpuv_start_writestr (fnpData.fnpUnitData[devUnitIdx].MState.line [lineno].line_client,
1875               (unsigned char *) "\r[FNP emulation: FNP restarted]\r\n");
1876           }
1877         if (fnpData.fnpUnitData[devUnitIdx].MState.line[lineno].service == service_3270)
1878           {
1879               sim_debug (DBG_TRACE, & fnp_dev, "3270 controller found at unit %u line %u\r\n", devUnitIdx, lineno);
1880             // XXX assuming only single controller
1881             if (fnpData.ibm3270ctlr[ASSUME0].configured)
1882               {
1883                 sim_warn ("Too many 3270 controllers configured");
1884               }
1885             else
1886               {
1887                 have3270 = true;
1888                 (void)memset (& fnpData.ibm3270ctlr[ASSUME0], 0, sizeof (struct ibm3270ctlr_s));
1889                 fnpData.ibm3270ctlr[ASSUME0].configured = true;
1890                 fnpData.ibm3270ctlr[ASSUME0].fnpno = devUnitIdx;
1891                 fnpData.ibm3270ctlr[ASSUME0].lineno = lineno;
1892 
1893                 // 3270 controller connects immediately
1894                 // Set from CMF data now.
1895                 //fnpData.fnpUnitData[devUnitIdx].MState.line[lineno].lineType  = 7 /* LINE_BSC */;
1896                 if (fnpData.fnpUnitData[devUnitIdx].MState.line[lineno].lineType == 0) /* LINE_NONE */
1897                   fnpData.fnpUnitData[devUnitIdx].MState.line[lineno].lineType = 7; /* LINE_BSC */
1898                 fnpData.fnpUnitData[devUnitIdx].MState.line[lineno].accept_new_terminal = true;
1899               }
1900           }
1901       }
1902     (void)fnpuvInit (fnpData.telnet_port, fnpData.telnet_address);
1903     if (have3270)
1904       (void)fnpuv3270Init (fnpData.telnet3270_port);
1905   }
1906 
1907 
1908 static word18 getl6core (uint iom_unit_idx, uint chan, word24 l66addr, uint addr)
     /* [previous][next][first][last][top][bottom][index][help] */
1909   {
1910     word24 wos = addr / 2;
1911     word36 word;
1912     iom_direct_data_service (iom_unit_idx, chan, l66addr + wos, & word, direct_load);
1913     if (addr & 1)
1914       return (word18) (word & MASK18);
1915     else
1916       return (word18) ((word >> 18) & MASK18);
1917   }
1918 
1919 
1920 static void processMBX (uint iomUnitIdx, uint chan)
     /* [previous][next][first][last][top][bottom][index][help] */
1921   {
1922 #if defined(TESTING)
1923     cpu_state_t * cpup = _cpup;
1924 #endif
1925     uint fnp_unit_idx = get_ctlr_idx (iomUnitIdx, chan);
1926     struct fnpUnitData_s * fudp = & fnpData.fnpUnitData [fnp_unit_idx];
1927 
1928 // 60132445 FEP Coupler EPS
1929 // 2.2.1 Control Intercommunication
1930 //
1931 // "In Level 66 memory, at a location known to the coupler and
1932 // to Level 6 software is a mailbox area consisting to an Overhead
1933 // mailbox and 7 Channel mailboxes."
1934 
1935     bool ok = true;
1936 
1937     word36 dia_pcw;
1938     iom_direct_data_service (iomUnitIdx, chan, fudp->mailboxAddress+DIA_PCW, & dia_pcw, direct_load);
1939     sim_debug (DBG_TRACE, & fnp_dev,
1940                "%s: chan %d dia_pcw %012"PRIo64"\r\n", __func__, chan, dia_pcw);
1941 
1942 // Mailbox word 0:
1943 //
1944 //   0-17 A
1945 //     18 I
1946 //  19-20 MBZ
1947 //  21-22 RFU
1948 //     23 0
1949 //  24-26 B
1950 //  27-29 D Channel #
1951 //  30-35 C Command
1952 //
1953 //                          A6-A23    A0-A2     A3-A5
1954 // Operation          C         A        B        D
1955 // Interrupt L6      071       ---      Int.     Level
1956 // Bootload L6       072    L66 Addr  L66 Addr  L66 Addr
1957 //                           A6-A23    A0-A2     A3-A5
1958 // Interrupt L66     073      ---      ---     Intr Cell
1959 // Data Xfer to L66  075    L66 Addr  L66 Addr  L66 Addr
1960 //                           A6-A23    A0-A2     A3-A5
1961 // Data Xfer to L6   076    L66 Addr  L66 Addr  L66 Addr
1962 //                           A6-A23    A0-A2     A3-A5
1963 
1964 //
1965 // fnp_util.pl1:
1966 //    075 tandd read
1967 //    076 tandd write
1968 
1969 // mbx word 1: mailbox_requests fixed bin
1970 //          2: term_inpt_mpx_wd bit (36) aligned
1971 //          3: last_mbx_req_count fixed bin
1972 //          4: num_in_use fixed bin
1973 //          5: mbx_used_flags
1974 //                used (0:7) bit (1) unaligned
1975 //                pad2 bit (28) unaligned
1976 //          6,7: crash_data
1977 //                fault_code fixed bin (18) unal unsigned
1978 //                ic fixed bin (18) unal unsigned
1979 //                iom_fault_status fixed bin (18) unal unsigned
1980 //                fault_word fixed bin (18) unal unsigned
1981 //
1982 //    crash_data according to dn355_boot_interrupt.pl1:
1983 //
1984 //   dcl  1 fnp_boot_status aligned based (stat_ptr),            /* structure of bootload status */
1985 //          2 real_status bit (1) unaligned,                     /* must be "1"b in valid status */
1986 //          2 pad1 bit (2) unaligned,
1987 //          2 major_status bit (3) unaligned,
1988 //          2 pad2 bit (3) unaligned,
1989 //          2 substatus fixed bin (8) unal,                      /* code set by 355, only interesting if major_status is 4 */
1990 //          2 channel_no fixed bin (17) unaligned;               /* channel no. of LSLA in case of config error */
1991 //    only 34 bits???
1992 // major_status:
1993 //  dcl  BOOTLOAD_OK fixed bin int static options (constant) init (0);
1994 //  dcl  CHECKSUM_ERROR fixed bin int static options (constant) init (1);
1995 //  dcl  READ_ERROR fixed bin int static options (constant) init (2);
1996 //  dcl  GICB_ERROR fixed bin int static options (constant) init (3);
1997 //  dcl  INIT_ERROR fixed bin int static options (constant) init (4);
1998 //  dcl  UNWIRE_STATUS fixed bin int static options (constant) init (5);
1999 //  dcl  MAX_STATUS fixed bin int static options (constant) init (5);
2000 
2001 // 3.5.1 Commands Issued by Central System
2002 //
2003 // In the issuing of an order by the Central System to the Coupler, the
2004 // sequence occurs:
2005 //
2006 // 1. The L66 program creates a LPW and Pcw for the Central System Connect
2007 // channel. It also generates and stores a control word containing a command
2008 // int he L66 mailbox. A Connect is then issued to the L66 IOM.
2009 //
2010 // 2. The Connect Channel accesses the PCW to get the channel number of
2011 // the Direct Channel that the coupler is attached to. the direct Channel
2012 // sends a signal to the Coupler that a Connect has been issued.
2013 //
2014 // 3. The Coupler now reads the content of the L66 mailbox, obtaining the
2015 // control word. If the control word is legal, the Coupler will write a
2016 // word of all zeros into the mailbox.
2017 //
2018 
2019 // 4.1.1.2 Transfer Control Word.
2020 // The transfer control word, which is pointed to by the
2021 // mailbox word in l66 memory on Op Codes 72, 7, 76 contains
2022 // a starting address which applies to L6 memory an a Tally
2023 // of the number of 36 bit words to be transferred. The l66
2024 // memory locations to/from which the transfers occur are
2025 // those immediately following the location where this word
2026 // was obtained.
2027 //
2028 //    00-02  001
2029 //    03-17 L6 Address
2030 //       18 P
2031 //    19-23 MBZ
2032 //    24-25 Tally
2033 //
2034 //     if P = 0 the l6 address:
2035 //        00-07 00000000
2036 //        08-22 L6 address (bits 3-17)
2037 //           23 0
2038 //     if P = 1
2039 //        00-14 L6 address (bits 3-17)
2040 //        15-23 0
2041 //
2042 
2043     uint command = getbits36_6 (dia_pcw, 30);
2044     word36 bootloadStatus = 0;
2045 
2046     if (command == 000) // reset
2047       {
2048         sim_debug (DBG_TRACE, & fnp_dev,
2049                    "%s: chan %d reset command\r\n", __func__, chan);
2050         send_general_interrupt (iomUnitIdx, chan, imwTerminatePic);
2051       }
2052     else if (command == 072) // bootload
2053       {
2054 
2055         word24 l66addr = (((word24) getbits36_6 (dia_pcw, 24)) << 18) |
2056                            (word24) getbits36_18 (dia_pcw, 0);
2057 
2058 // AN85-01 15-2
2059 //   0 boot dcw
2060 //   1  gicb
2061 //      ....
2062 //      padding to next multiple of 64
2063 //   n  core image
2064 //
2065 // where n is (in 36 bit words) (gicb len + 1) + 63 / 64
2066 
2067 //sim_printf ("l66addr %08o\r\n", l66addr);
2068         word36 dcw;
2069         iom_direct_data_service (iomUnitIdx, chan, l66addr, & dcw, direct_load);
2070         word12 tally = getbits36_12 (dcw, 24);
2071         // sim_printf ("%o %d.\r\n", tally, tally);
2072 //sim_printf ("dcw %012llo\r\n", dcw);
2073 
2074         // Calculate start of core image
2075         word24 image_off = (tally + 64) & 077777700;
2076         // sim_printf ("image_off %o %d.\r\n", image_off, image_off);
2077 
2078 
2079 
2080 
2081 
2082 
2083 
2084 
2085 
2086 
2087 
2088 
2089 
2090 
2091 
2092 
2093 
2094 
2095 
2096 
2097 
2098 
2099 
2100 
2101 
2102 
2103 
2104 
2105 
2106 
2107 // comm_ref
2108 //   0640   crldt  72
2109 //   0644   crbdt  72
2110 //   0650   crbuf  18
2111 //   0651   crmem  18
2112 //   0652   crnbf  18
2113 //   0653   criom  18
2114 
2115 //     2 comm_reg unal,                   /* software communications region */
2116 // 0640  3 crldt fixed bin (71) aligned,  /* date and time binder */
2117 // 0644  3 crbdt fixed bin (71) aligned,  /* date and time image booted */
2118 // 0650  3 crbuf fixed bin (17) unal,     /* base of free buffer pool */
2119 // 0651  3 crmem fixed bin (18) unsigned unal, /* last loc of mem configured */
2120 // 0652  3 crnbf fixed bin (17) unal,     /* free buffers in pool now */
2121 // 0653  3 criom fixed bin (17) unal,     /* pointer to iom table */
2122 // 0654  3 crnhs fixed bin (17) unal,     /* number of HSLAs */
2123 // 0655  3 crnls fixed bin (17) unal,     /* number of LSLAs */
2124 // 0656  3 crcon bit (18) unal,           /* console enable switch */
2125 // 0657  3 crmod fixed bin (17) unal,     /* base of module chain */
2126 //       3 crnxa fixed bin (17) unal,     /* ptr to head of free space chain */
2127 //       3 crtra bit (18) unal,           /* trace entry enable mask */
2128 //       3 crtrb fixed bin (18) unsigned unal, /* base of trace table */
2129 //       3 crtrc fixed bin (18) unsigned unal, /* next trace table entry ptr */
2130 //       3 crreg fixed bin (17) unal,    /* ptr to fault reg storage area */
2131 //       3 crttb fixed bin (17) unal,    /* ptr to tib table base */
2132 //       3 crtte fixed bin (17) unal,    /* last addr in tib table */
2133 //       3 crdly fixed bin (17) unal,    /* pointer to delay table chain */
2134 //       3 crver char (4) unal, /* mcs version number */
2135 //       3 crbrk fixed bin (17) unal,    /* pointer to breakpoint control table */
2136 //       3 crtsw bit (18) unal, /* trace switch (zero=trace on) */
2137 //       3 crnxs fixed bin (17) unal,    /* pointer to next free small block */
2138 //       3 crnbs fixed bin (17) unal,    /* number of buffers devoted to small space */
2139 //       3 crcct fixed bin (17) unal,    /* pointer to first cct descriptor */
2140 //       3 crskd fixed bin (17) unal,    /* pointer to scheduler data block */
2141 //       3 cretb fixed bin (17) unal,    /* pointer to list of echo-negotiation bit tables */
2142 //       3 crcpt fixed bin (17) unal,    /* pointer to cpu page table */
2143 //       3 crpte fixed bin (17) unal,    /* pointer to variable cpu page table entry */
2144 //       3 crtsz fixed bin (17) unal,    /* size of trace data buffer */
2145 //       3 crmet bit (18) unal,          /* metering enabled */
2146 //       3 crtdt bit (18) unal,          /* 0 if no COLTS channel; set to TIB address if it exists */
2147 //       3 crbtm bit (18) unal,          /* address of time meters for buffer allocation/freeing */
2148 //       3 crnxe fixed bin (18) unsigned unal, /* next available space in extended memory */
2149 //       3 crbpe fixed bin (17) unal,    /* buffer paging window table entry */
2150 //       3 pad (39) bit (18) unal,
2151 //       3 crcpr char (28) unal,         /* image copyright notice */
2152 //       3 crash_location bit (18) unal, /* offset used for unresolved REF's */
2153 //       3 crash_opcode bit (18) unal,   /* crash instruction */
2154 
2155 
2156 
2157 
2158 
2159 
2160 
2161 
2162 
2163 
2164 
2165 
2166 
2167 
2168 
2169 
2170 
2171 
2172 
2173 
2174 
2175 
2176 
2177 
2178 
2179 
2180 
2181 
2182 
2183 
2184 
2185 
2186 
2187 
2188 
2189 
2190 
2191 
2192 
2193 
2194 
2195 
2196 
2197 
2198 
2199 
2200 
2201 
2202 
2203 
2204 
2205 
2206 
2207         // Number of LSLAs
2208 # if defined(VERBOSE_BOOT)
2209         word18 crnls = getl6core (iomUnitIdx, chan, l66addr + image_off, 0655);
2210         sim_printf ("Number of LSLAs (crnls) %d\r\n", crnls);
2211 # endif /* if defined(VERBOSE_BOOT) */
2212 
2213         // Address of IOM table
2214         word18 criom = getl6core (iomUnitIdx, chan, l66addr + image_off, 0653);
2215 
2216         // Walk the LSLAs in the IOM table
2217         //  2 words/slot (flags, taddr)
2218         //  6 LSLA slots
2219         //  first slot at first_lsla_ch 9
2220 
2221         bool hdr = false;
2222 # if defined(VERBOSE_BOOT)
2223         uint nfound = 0;
2224 # endif /* if defined(VERBOSE_BOOT) */
2225         for (uint lsla = 0; lsla < 6; lsla ++)
2226           {
2227             uint slot = lsla + 9;
2228             uint os = slot * 2;
2229             // get flags word
2230             word18 flags = getl6core (iomUnitIdx, chan, l66addr + image_off, criom + os);
2231             uint device_type_code = (flags >> 4) & 037;
2232             if (device_type_code == 4)
2233               {
2234 # if defined (VERBOSE_BOOT)
2235                 nfound ++;
2236 # endif /* if defined(VERBOSE_BOOT) */
2237                 // get addr word
2238                 word18 tblp = getl6core (iomUnitIdx, chan, l66addr + image_off, criom + os + 1);
2239                 for (uint slot = 0; slot < 52; slot ++)
2240                   {
2241                     // 2 word18s per entry
2242                     //   pad bit(11)
2243                     //   ibm_code bit(1)   // if 6-bit odd parity
2244                     //   pad2 bit(3)
2245                     //   slot_id bit(3)
2246                     //
2247                     //   ptr bit(18)
2248                     word3 slot_id = getl6core (iomUnitIdx, chan, l66addr + image_off, tblp + 2 * slot) & MASK3;
2249                     if (slot_id != 7)
2250                       {
2251 # if defined(VERBOSE_BOOT)
2252                         char * slot_ids [8] =
2253                           {
2254                             "10 cps",
2255                             "30 cps, slot 1",
2256                             "30 cps, slot 2",
2257                             "30 cps, slot 3",
2258                             "invalid",
2259                             "15 cps, slot 1",
2260                             "15 cps, slot 2",
2261                             "unused"
2262                           };
2263                         char * id = slot_ids[slot_id];
2264 # endif /* if defined(VERBOSE_BOOT) */
2265                         if (! hdr)
2266                           {
2267                             hdr = true;
2268 # if defined(VERBOSE_BOOT)
2269                             sim_printf ("LSLA table: card number, slot, slot_id, slot_id string\r\n");
2270 # endif /* if defined(VERBOSE_BOOT) */
2271                           }
2272 # if defined(VERBOSE_BOOT)
2273                         sim_printf ("%d %2d %d %s\r\n", lsla, slot, slot_id, id);
2274 # endif /* if defined(VERBOSE_BOOT) */
2275                       }
2276                   } // for slot
2277               } // if dev type 4 (LSLA)
2278           } // iom table entry
2279 # if defined(VERBOSE_BOOT)
2280         if (nfound != crnls)
2281           sim_printf ("LSLAs configured %d found %d\r\n", crnls, nfound);
2282 # endif /* if defined(VERBOSE_BOOT) */
2283 
2284         // Number of HSLAs
2285 # if defined(VERBOSE_BOOT)
2286         word18 crnhs = getl6core (iomUnitIdx, chan, l66addr + image_off, 0654);
2287         sim_printf ("Number of HSLAs (crnhs) %d\r\n", crnhs);
2288 # endif /* if defined(VERBOSE_BOOT) */
2289 
2290         // Walk the HSLAs in the IOM table
2291         //  2 words/slot (flags, taddr)
2292         //  3 LSLA slots
2293         //  first slot at first_hsla_ch 6
2294 
2295         hdr = false;
2296 # if defined(VERBOSE_BOOT)
2297         nfound = 0;
2298 # endif /* if defined(VERBOSE_BOOT) */
2299         for (uint hsla = 0; hsla < 3; hsla ++)
2300           {
2301             uint slot = hsla + 6;
2302             uint os = slot * 2;
2303             // get flags word
2304             word18 flags = getl6core (iomUnitIdx, chan, l66addr + image_off, criom + os);
2305             uint device_type_code = (flags >> 4) & 037;
2306             if (device_type_code == 3)
2307               {
2308 # if defined(VERBOSE_BOOT)
2309                 nfound ++;
2310 # endif /* if defined(VERBOSE_BOOT) */
2311                 // get addr word
2312                 word18 tblp = getl6core (iomUnitIdx, chan, l66addr + image_off, criom + os + 1);
2313                 for (uint slot = 0; slot < 32; slot ++)
2314                   {
2315                     // 2 word18s per entry
2316                     //   conc_chan bit(1)
2317                     //   private_line bit(1)
2318                     //   async bit(1)
2319                     //   option1 bit(1)
2320                     //   option2 bit(1)
2321                     //   modem_type bit(4)
2322                     //   line_type bit(5)
2323                     //   dev_speed bit(4)
2324                     //
2325                     //   ptr bit(18)
2326 
2327 # if defined(VERBOSE_BOOT)
2328                     char * line_types[23] =
2329                       {
2330                         "none      ",
2331                         "ASCII     ",
2332                         "1050      ",
2333                         "2741      ",
2334                         "ARDS      ",
2335                         "Sync      ",
2336                         "G115      ",
2337                         "BSC       ",
2338                         "202ETX    ",
2339                         "VIP       ",
2340                         "ASYNC1    ",
2341                         "ASYNC2    ",
2342                         "ASYNC3    ",
2343                         "SYNC1     ",
2344                         "SYNC2     ",
2345                         "SYNC3     ",
2346                         "POLLED_VIP",
2347                         "X25LAP    ",
2348                         "HDLC      ",
2349                         "COLTS     ",
2350                         "DSA       ",
2351                         "HASP_OPR  ",
2352                         "invalid   "
2353                       };
2354 # endif
2355 
2356 # if defined(VERBOSE_BOOT)
2357                     char * modem_types[8] =
2358                       {
2359                         "invalid      ",
2360                         "Bell 103A/113",
2361                         "Bell 201C    ",
2362                         "Bell 202C5   ",
2363                         "Bell 202C6   ",
2364                         "Bell 208A    ",
2365                         "Bell 208B    ",
2366                         "Bell 209A    "
2367                       };
2368 # endif
2369 
2370 
2371 
2372 
2373 
2374 
2375 
2376 
2377 
2378 
2379 
2380 
2381 
2382 
2383 
2384 
2385 
2386 
2387 
2388 
2389 
2390 
2391 
2392 
2393 
2394 
2395 
2396 
2397 
2398 
2399 
2400 
2401 # if defined(VERBOSE_BOOT)
2402                     char * async_speeds[16] =
2403                       {
2404                         "invalid",
2405                         "110    ",
2406                         "133    ",
2407                         "150    ",
2408                         "300    ",
2409                         "600    ",
2410                         "1200   ",
2411                         "1800   ",
2412                         "2400   ",
2413                         "4800   ",
2414                         "7200   ",
2415                         "9600   ",
2416                         "19200  ",
2417                         "40800  ",
2418                         "50000  ",
2419                         "72000  "
2420                       };
2421 
2422                     char * sync_speeds[16] =
2423                       {
2424                         "invalid",
2425                         "2000   ",
2426                         "2400   ",
2427                         "3600   ",
2428                         "4800   ",
2429                         "5400   ",
2430                         "7200   ",
2431                         "9600   ",
2432                         "19200  ",
2433                         "40800  ",
2434                         "50000  ",
2435                         "invalid",
2436                         "invalid",
2437                         "invalid",
2438                         "invalid",
2439                         "invalid"
2440                       };
2441 # endif
2442                     word18 subch_data = getl6core (iomUnitIdx, chan, l66addr + image_off, tblp + 2 * slot);
2443 # if defined(VERBOSE_BOOT)
2444                     word1 async = (subch_data >> 15) & 1;
2445                     word1 option1 = (subch_data >> 14) & 1;
2446 # endif
2447                     word5 line_type = (subch_data >> 4)  & MASK5;
2448                     if (line_type > 22)
2449                       line_type = 22;
2450                     word4 modem_type = (subch_data >> 9)  & MASK4;
2451                     if (modem_type > 7)
2452                       modem_type = 0;
2453 # if defined(VERBOSE_BOOT)
2454                     word4 dev_speed = subch_data  & MASK4;
2455                     //if (dev_speed > 10)
2456                       //dev_speed = 0;
2457                     char * speed = async ? async_speeds[dev_speed] : sync_speeds[dev_speed];
2458                     if (async && dev_speed == 4 && option1)
2459                       speed = "auto   ";
2460 # endif
2461                     if (! hdr)
2462                       {
2463                         hdr = true;
2464 # if defined(VERBOSE_BOOT)
2465                         sim_printf ("HSLA table: card number, slot, "
2466                                     "sync/async, line type, modem_type, "
2467                                     "speed\r\n");
2468 # endif
2469                       }
2470 # if defined(VERBOSE_BOOT)
2471                     sim_printf ("%d %2d %s %s %s %s\r\n",
2472                                  hsla, slot, async ? "async" :"sync ",
2473                                  line_types[line_type],
2474                                  modem_types[modem_type],
2475                                  speed);
2476 # endif
2477                      uint lineno = hsla * 32u + slot;
2478                      struct t_line * linep = & fudp->MState.line[lineno];
2479 
2480 
2481 
2482 
2483 
2484 
2485 
2486                      //linep->lineType = line_type ? line_type : 1; // Map none to ASCII
2487                      linep->lineType = line_type;
2488                   } // for slot
2489               } // if dev type 4 (LSLA)
2490           } // iom table entry
2491 # if defined(VERBOSE_BOOT)
2492         if (nfound != crnls)
2493           sim_printf ("LSLAs configured %d found %d\r\n", crnls, nfound);
2494 # endif /* if defined(VERBOSE_BOOT) */
2495 
2496 
2497 #if defined(THREADZ) || defined(LOCKLESS)
2498         lock_libuv ();
2499 #endif
2500         fnpcmdBootload (fnp_unit_idx);
2501 #if defined(THREADZ) || defined(LOCKLESS)
2502         unlock_libuv ();
2503 #endif
2504         send_general_interrupt (iomUnitIdx, chan, imwTerminatePic);
2505         fudp -> fnpIsRunning = true;
2506       }
2507     else if (command == 071) // interrupt L6
2508       {
2509 #if defined(THREADZ) || defined(LOCKLESS)
2510         lock_libuv ();
2511 #endif
2512         ok = interruptL66 (iomUnitIdx, chan) == 0;
2513 #if defined(THREADZ) || defined(LOCKLESS)
2514         unlock_libuv ();
2515 #endif
2516       }
2517     else if (command == 075) // data xfer from L6 to L66
2518       {
2519         // Build the L66 address from the PCW
2520         //   0-17 A
2521         //  24-26 B
2522         //  27-29 D Channel #
2523         // Operation          C         A        B        D
2524         // Data Xfer to L66  075    L66 Addr  L66 Addr  L66 Addr
2525         //                           A6-A23    A0-A2     A3-A5
2526         // These don't seem to be right; M[L66Add] is always 0.
2527         //word24 A = (word24) getbits36_18 (dia_pcw,  0);
2528         //word24 B = (word24) getbits36_3  (dia_pcw, 24);
2529         //word24 D = (word24) getbits36_3  (dia_pcw, 29);
2530         //word24 L66Addr = (B << (24 - 3)) | (D << (24 - 3 - 3)) | A;
2531 
2532         // According to fnp_util:
2533         //                      /* better declaration than the one used when MCS is running */
2534         //  dcl  1 a_dia_pcw aligned based (mbxp),
2535         //         2 address fixed bin (18) unsigned unaligned,
2536         //         2 error bit (1) unaligned,
2537         //         2 pad1 bit (3) unaligned,
2538         //         2 parity bit (1) unaligned,
2539         //         2 pad2 bit (1) unaligned,
2540         //                            /* if we used address extension this would be important */
2541         //         2 pad3 bit (3) unaligned,
2542         //         2 interrupt_level fixed bin (3) unsigned unaligned,
2543         //         2 command bit (6) unaligned;
2544         //
2545         //   a_dia_pcw.address = address;
2546         //
2547 
2548         //word24 L66Addr = (word24) getbits36_18 (dia_pcw, 0);
2549         //sim_printf ("L66 xfer\r\n");
2550         //sim_printf ("PCW  %012"PRIo64"\r\n", dia_pcw);
2551         //sim_printf ("L66Addr %08o\r\n", L66Addr);
2552         //sim_printf ("M[] %012"PRIo64"\r\n", M[L66Addr]);
2553 
2554         // 'dump_mpx d'
2555         //L66 xfer
2556         //PCW  022002000075
2557         //L66Addr 00022002
2558         //M[] 000000401775
2559         //L66 xfer
2560         //PCW  022002000075
2561         //L66Addr 00022002
2562         //M[] 003772401775
2563         //L66 xfer
2564         //PCW  022002000075
2565         //L66Addr 00022002
2566         //M[] 007764401775
2567         //
2568         // The contents of M seem much more reasonable, bit still don't match
2569         // fnp_util$setup_dump_ctl_word. The left octet should be '1', not '0';
2570         // bit 18 should be 0 not 1. But the offsets and tallies match exactly.
2571         // Huh... Looking at 'dump_6670_control' control instead, it matches
2572         // correctly. Apparently fnp_util thinks the FNP is a 6670, not a 335.
2573         // I can't decipher the call path, so I don't know why; but looking at
2574         // multiplexer_types.incl.pl1, I would guess that by MR12.x, all FNPs
2575         // were 6670s.
2576         //
2577         // So:
2578         //          /* word used to supply DN6670 address and tally for fdump */
2579         //   dcl  1 dump_6670_control aligned based (data_ptr),
2580         //          2 fnp_address fixed bin (18) unsigned unaligned,
2581         //          2 unpaged bit (1) unaligned,
2582         //          2 mbz bit (5) unaligned,
2583         //          2 tally fixed bin (12) unsigned unaligned;
2584 
2585         // Since the data is marked 'paged', and I don't understand the
2586         // the paging mechanism or parameters, I'm going to punt here and
2587         // not actually transfer any data.
2588 
2589       }
2590     else
2591       {
2592         sim_warn ("bogus fnp command %d (%o)\r\n", command, command);
2593         ok = false;
2594       }
2595 
2596     if (ok)
2597       {
2598 #if defined(TESTING)
2599         if_sim_debug (DBG_TRACE, & fnp_dev) dmpmbx (fudp->mailboxAddress);
2600 #endif
2601         //iom_chan_data [iomUnitIdx] [chan] . in_use = false;
2602         dia_pcw = 0;
2603         iom_direct_data_service (iomUnitIdx, chan, fudp -> mailboxAddress+DIA_PCW, & dia_pcw, direct_store);
2604         putbits36_1 (& bootloadStatus, 0, 1); // real_status = 1
2605         putbits36_3 (& bootloadStatus, 3, 0); // major_status = BOOTLOAD_OK;
2606         putbits36_8 (& bootloadStatus, 9, 0); // substatus = BOOTLOAD_OK;
2607         putbits36_17 (& bootloadStatus, 17, 0); // channel_no = 0;
2608         iom_direct_data_service (iomUnitIdx, chan, fudp -> mailboxAddress+CRASH_DATA, & bootloadStatus, direct_store);
2609       }
2610     else
2611       {
2612 #if defined(TESTING)
2613         if_sim_debug (DBG_TRACE, & fnp_dev) dmpmbx (fudp->mailboxAddress);
2614 #endif
2615         // 3 error bit (1) unaligned, /* set to "1"b if error on connect */
2616         //iom_chan_data [iomUnitIdx] [chan] . in_use = false;
2617         putbits36_1 (& dia_pcw, 18, 1); // set bit 18
2618         iom_direct_data_service (iomUnitIdx, chan, fudp -> mailboxAddress+DIA_PCW, & dia_pcw, direct_store);
2619       }
2620   }
2621 
2622 static int fnpCmd (uint iomUnitIdx, uint chan) {
     /* [previous][next][first][last][top][bottom][index][help] */
2623   iom_chan_data_t * p = & iom_chan_data [iomUnitIdx] [chan];
2624 
2625   switch (p->IDCW_DEV_CMD) {
2626     case 000: { // CMD 00 Request status
2627         p->stati = 04000;
2628         processMBX (iomUnitIdx, chan);
2629         // no status_service and no additional terminate interrupt
2630         // ???
2631       }
2632       return IOM_CMD_DISCONNECT;
2633 
2634     default: {
2635       p->stati = 04501; // cmd reject, invalid opcode
2636       p->chanStatus = chanStatIncorrectDCW;
2637       // ignore the bootload console probe (051) and, in T&D mode, the
2638       // executive's survey of every channel with reset status (040); the
2639       // FNP rejects it, as here
2640       if (p->IDCW_DEV_CMD != 051 && ! (tandd_io_mode () && p->IDCW_DEV_CMD == 040))
2641         sim_warn ("%s: FNP unrecognized device command  %02o\r\n", __func__, p->IDCW_DEV_CMD);
2642       }
2643       return IOM_CMD_ERROR;
2644   }
2645 }
2646 
2647 /*
2648  * fnp_iom_cmd()
2649  *
2650  */
2651 
2652 iom_cmd_rc_t fnp_iom_cmd (uint iomUnitIdx, uint chan) {
     /* [previous][next][first][last][top][bottom][index][help] */
2653   iom_chan_data_t * p = & iom_chan_data [iomUnitIdx] [chan];
2654 // Is it an IDCW?
2655 
2656   if (IS_IDCW (p)) {
2657     return fnpCmd (iomUnitIdx, chan);
2658   }
2659   // else // DDCW/TDCW
2660   sim_warn ("%s expected IDCW\r\n", __func__);
2661   return IOM_CMD_ERROR;
2662 }

/* [previous][next][first][last][top][bottom][index][help] */