VirtualBox

Changeset 82191 in vbox for trunk/src/VBox/Devices/Input


Ignore:
Timestamp:
Nov 25, 2019 5:48:55 PM (5 years ago)
Author:
vboxsync
Message:

DevPS2: Moved XlateAT2PC to the DevPS2.cpp file. bugref:9218

Location:
trunk/src/VBox/Devices/Input
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Input/DevPS2.cpp

    r82190 r82191  
    5454#include "DevPS2.h"
    5555
     56
     57/*********************************************************************************************************************************
     58*   Defined Constants And Macros                                                                                                 *
     59*********************************************************************************************************************************/
    5660/* Do not remove this (unless eliminating the corresponding ifdefs), it will
    5761 * cause instant triple faults when booting Windows VMs. */
     
    5963
    6064#define PCKBD_SAVED_STATE_VERSION 8
    61 
    62 #ifndef VBOX_DEVICE_STRUCT_TESTCASE
    63 
    64 
    65 /*********************************************************************************************************************************
    66 *   Internal Functions                                                                                                           *
    67 *********************************************************************************************************************************/
    68 RT_C_DECLS_BEGIN
    69 PDMBOTHCBDECL(int) kbdIOPortDataRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb);
    70 PDMBOTHCBDECL(int) kbdIOPortDataWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
    71 PDMBOTHCBDECL(int) kbdIOPortStatusRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb);
    72 PDMBOTHCBDECL(int) kbdIOPortCommandWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
    73 RT_C_DECLS_END
    74 #endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
    7565
    7666/* debug PC keyboard */
     
    125115
    126116
     117/*********************************************************************************************************************************
     118*   Structures and Typedefs                                                                                                      *
     119*********************************************************************************************************************************/
     120/** AT to PC scancode translator state.  */
     121typedef enum
     122{
     123    XS_IDLE,    /**< Starting state. */
     124    XS_BREAK,   /**< F0 break byte was received. */
     125    XS_HIBIT    /**< Break code still active. */
     126} xlat_state_t;
     127
     128
     129/*********************************************************************************************************************************
     130*   Global Variables                                                                                                             *
     131*********************************************************************************************************************************/
     132/* Table used by the keyboard controller to optionally translate the incoming
     133 * keyboard data. Note that the translation is designed for essentially taking
     134 * Scan Set 2 input and producing Scan Set 1 output, but can be turned on and
     135 * off regardless of what the keyboard is sending.
     136 */
     137static uint8_t const g_aAT2PC[128] =
     138{
     139    0xff,0x43,0x41,0x3f,0x3d,0x3b,0x3c,0x58,0x64,0x44,0x42,0x40,0x3e,0x0f,0x29,0x59,
     140    0x65,0x38,0x2a,0x70,0x1d,0x10,0x02,0x5a,0x66,0x71,0x2c,0x1f,0x1e,0x11,0x03,0x5b,
     141    0x67,0x2e,0x2d,0x20,0x12,0x05,0x04,0x5c,0x68,0x39,0x2f,0x21,0x14,0x13,0x06,0x5d,
     142    0x69,0x31,0x30,0x23,0x22,0x15,0x07,0x5e,0x6a,0x72,0x32,0x24,0x16,0x08,0x09,0x5f,
     143    0x6b,0x33,0x25,0x17,0x18,0x0b,0x0a,0x60,0x6c,0x34,0x35,0x26,0x27,0x19,0x0c,0x61,
     144    0x6d,0x73,0x28,0x74,0x1a,0x0d,0x62,0x6e,0x3a,0x36,0x1c,0x1b,0x75,0x2b,0x63,0x76,
     145    0x55,0x56,0x77,0x78,0x79,0x7a,0x0e,0x7b,0x7c,0x4f,0x7d,0x4b,0x47,0x7e,0x7f,0x6f,
     146    0x52,0x53,0x50,0x4c,0x4d,0x48,0x01,0x45,0x57,0x4e,0x51,0x4a,0x37,0x49,0x46,0x54
     147};
     148
     149
     150
     151/*********************************************************************************************************************************
     152*   Internal Functions                                                                                                           *
     153*********************************************************************************************************************************/
     154RT_C_DECLS_BEGIN
     155PDMBOTHCBDECL(int) kbdIOPortDataRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb);
     156PDMBOTHCBDECL(int) kbdIOPortDataWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
     157PDMBOTHCBDECL(int) kbdIOPortStatusRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb);
     158PDMBOTHCBDECL(int) kbdIOPortCommandWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
     159RT_C_DECLS_END
     160
     161
     162/**
     163 * Convert an AT (Scan Set 2) scancode to PC (Scan Set 1).
     164 *
     165 * @param state         Current state of the translator
     166 *                      (xlat_state_t).
     167 * @param scanIn        Incoming scan code.
     168 * @param pScanOut      Pointer to outgoing scan code. The
     169 *                      contents are only valid if returned
     170 *                      state is not XS_BREAK.
     171 *
     172 * @return xlat_state_t New state of the translator.
     173 */
     174static int32_t kbcXlateAT2PC(int32_t state, uint8_t scanIn, uint8_t *pScanOut)
     175{
     176    uint8_t     scan_in;
     177    uint8_t     scan_out;
     178
     179    Assert(pScanOut);
     180    Assert(state == XS_IDLE || state == XS_BREAK || state == XS_HIBIT);
     181
     182    /* Preprocess the scan code for a 128-entry translation table. */
     183    if (scanIn == 0x83)         /* Check for F7 key. */
     184        scan_in = 0x02;
     185    else if (scanIn == 0x84)    /* Check for SysRq key. */
     186        scan_in = 0x7f;
     187    else
     188        scan_in = scanIn;
     189
     190    /* Values 0x80 and above are passed through, except for 0xF0
     191     * which indicates a key release.
     192     */
     193    if (scan_in < 0x80)
     194    {
     195        scan_out = g_aAT2PC[scan_in];
     196        /* Turn into break code if required. */
     197        if (state == XS_BREAK || state == XS_HIBIT)
     198            scan_out |= 0x80;
     199
     200        state = XS_IDLE;
     201    }
     202    else
     203    {
     204        /* NB: F0 E0 10 will be translated to E0 E5 (high bit set on last byte)! */
     205        if (scan_in == 0xF0)        /* Check for break code. */
     206            state = XS_BREAK;
     207        else if (state == XS_BREAK)
     208            state = XS_HIBIT;       /* Remember the break bit. */
     209        scan_out = scan_in;
     210    }
     211    LogFlowFunc(("scan code %02X translated to %02X; new state is %d\n",
     212                 scanIn, scan_out, state));
     213
     214    *pScanOut = scan_out;
     215    return state;
     216}
     217
    127218
    128219/* update irq and KBD_STAT_[MOUSE_]OBF */
     
    151242                uint8_t     xlated_val;
    152243
    153                 s->xlat_state = XlateAT2PC(s->xlat_state, val, &xlated_val);
     244                s->xlat_state = kbcXlateAT2PC(s->xlat_state, val, &xlated_val);
    154245                val = xlated_val;
    155246
     
    159250                while (s->xlat_state == XS_BREAK && PS2KByteFromKbd(&s->Kbd, &val) == VINF_SUCCESS)
    160251                {
    161                     s->xlat_state = XlateAT2PC(s->xlat_state, val, &xlated_val);
     252                    s->xlat_state = kbcXlateAT2PC(s->xlat_state, val, &xlated_val);
    162253                    val = xlated_val;
    163254                }
  • trunk/src/VBox/Devices/Input/DevPS2.h

    r82190 r82191  
    376376void KBCUpdateInterrupts(void *pKbc);
    377377
    378 
    379 ///@todo: This should live with the KBC implementation.
    380 /** AT to PC scancode translator state.  */
    381 typedef enum
    382 {
    383     XS_IDLE,    /**< Starting state. */
    384     XS_BREAK,   /**< F0 break byte was received. */
    385     XS_HIBIT    /**< Break code still active. */
    386 } xlat_state_t;
    387 
    388 int32_t XlateAT2PC(int32_t state, uint8_t scanIn, uint8_t *pScanOut);
    389 
    390378/** @}  */
    391379
  • trunk/src/VBox/Devices/Input/DevPS2K.cpp

    r82190 r82191  
    108108*   Structures and Typedefs                                                                                                      *
    109109*********************************************************************************************************************************/
    110 #ifndef VBOX_DEVICE_STRUCT_TESTCASE
    111 
    112110/* Key type flags. */
    113111#define KF_E0        0x01    /* E0 prefix. */
     
    14331431#endif /* IN _RING3 */
    14341432
    1435 /// @todo The following should live with the KBC implementation.
    1436 
    1437 /* Table used by the keyboard controller to optionally translate the incoming
    1438  * keyboard data. Note that the translation is designed for essentially taking
    1439  * Scan Set 2 input and producing Scan Set 1 output, but can be turned on and
    1440  * off regardless of what the keyboard is sending.
    1441  */
    1442 static uint8_t aAT2PC[128] = {
    1443     0xff,0x43,0x41,0x3f,0x3d,0x3b,0x3c,0x58,0x64,0x44,0x42,0x40,0x3e,0x0f,0x29,0x59,
    1444     0x65,0x38,0x2a,0x70,0x1d,0x10,0x02,0x5a,0x66,0x71,0x2c,0x1f,0x1e,0x11,0x03,0x5b,
    1445     0x67,0x2e,0x2d,0x20,0x12,0x05,0x04,0x5c,0x68,0x39,0x2f,0x21,0x14,0x13,0x06,0x5d,
    1446     0x69,0x31,0x30,0x23,0x22,0x15,0x07,0x5e,0x6a,0x72,0x32,0x24,0x16,0x08,0x09,0x5f,
    1447     0x6b,0x33,0x25,0x17,0x18,0x0b,0x0a,0x60,0x6c,0x34,0x35,0x26,0x27,0x19,0x0c,0x61,
    1448     0x6d,0x73,0x28,0x74,0x1a,0x0d,0x62,0x6e,0x3a,0x36,0x1c,0x1b,0x75,0x2b,0x63,0x76,
    1449     0x55,0x56,0x77,0x78,0x79,0x7a,0x0e,0x7b,0x7c,0x4f,0x7d,0x4b,0x47,0x7e,0x7f,0x6f,
    1450     0x52,0x53,0x50,0x4c,0x4d,0x48,0x01,0x45,0x57,0x4e,0x51,0x4a,0x37,0x49,0x46,0x54
    1451 };
    1452 
    1453 /**
    1454  * Convert an AT (Scan Set 2) scancode to PC (Scan Set 1).
    1455  *
    1456  * @param state         Current state of the translator
    1457  *                      (xlat_state_t).
    1458  * @param scanIn        Incoming scan code.
    1459  * @param pScanOut      Pointer to outgoing scan code. The
    1460  *                      contents are only valid if returned
    1461  *                      state is not XS_BREAK.
    1462  *
    1463  * @return xlat_state_t New state of the translator.
    1464  */
    1465 int32_t XlateAT2PC(int32_t state, uint8_t scanIn, uint8_t *pScanOut)
    1466 {
    1467     uint8_t     scan_in;
    1468     uint8_t     scan_out;
    1469 
    1470     Assert(pScanOut);
    1471     Assert(state == XS_IDLE || state == XS_BREAK || state == XS_HIBIT);
    1472 
    1473     /* Preprocess the scan code for a 128-entry translation table. */
    1474     if (scanIn == 0x83)         /* Check for F7 key. */
    1475         scan_in = 0x02;
    1476     else if (scanIn == 0x84)    /* Check for SysRq key. */
    1477         scan_in = 0x7f;
    1478     else
    1479         scan_in = scanIn;
    1480 
    1481     /* Values 0x80 and above are passed through, except for 0xF0
    1482      * which indicates a key release.
    1483      */
    1484     if (scan_in < 0x80)
    1485     {
    1486         scan_out = aAT2PC[scan_in];
    1487         /* Turn into break code if required. */
    1488         if (state == XS_BREAK || state == XS_HIBIT)
    1489             scan_out |= 0x80;
    1490 
    1491         state = XS_IDLE;
    1492     }
    1493     else
    1494     {
    1495         /* NB: F0 E0 10 will be translated to E0 E5 (high bit set on last byte)! */
    1496         if (scan_in == 0xF0)        /* Check for break code. */
    1497             state = XS_BREAK;
    1498         else if (state == XS_BREAK)
    1499             state = XS_HIBIT;       /* Remember the break bit. */
    1500         scan_out = scan_in;
    1501     }
    1502     LogFlowFunc(("scan code %02X translated to %02X; new state is %d\n",
    1503                  scanIn, scan_out, state));
    1504 
    1505     *pScanOut = scan_out;
    1506     return state;
    1507 }
    1508 
    1509 #endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
  • trunk/src/VBox/Devices/Input/DevPS2M.cpp

    r82190 r82191  
    196196#define ARSP_RESEND         0xFE    /* Requesting resend. */
    197197/** @} */
    198 
    199 
    200 #ifndef VBOX_DEVICE_STRUCT_TESTCASE
    201198
    202199
     
    668665
    669666/** Is there any state change to send as events to the guest? */
    670 static uint32_t ps2mHaveEvents(PPS2M pThis)
     667static uint32_t ps2mR3HaveEvents(PPS2M pThis)
    671668{
    672669    return   pThis->iAccumX || pThis->iAccumY || pThis->iAccumZ || pThis->iAccumW
     
    689686
    690687    /* If more movement is accumulated, report it and restart the timer. */
    691     uHaveEvents = ps2mHaveEvents(pThis);
     688    uHaveEvents = ps2mR3HaveEvents(pThis);
    692689    LogFlowFunc(("Have%s events\n", uHaveEvents ? "" : " no"));
    693690
     
    814811
    815812    /* Report the event (if any) and start the throttle timer unless it's already running. */
    816     if (!pThis->fThrottleActive && ps2mHaveEvents(pThis))
     813    if (!pThis->fThrottleActive && ps2mR3HaveEvents(pThis))
    817814    {
    818815        ps2mReportAccumulatedEvents(pThis, (GeneriQ *)&pThis->evtQ, true);
     
    11001097     * this to check that it is handled right. */
    11011098    ps2mR3PutEventWorker(&This, 0, 0, 0, 0, 1);
    1102     if (ps2mHaveEvents(&This))
     1099    if (ps2mR3HaveEvents(&This))
    11031100        ps2mReportAccumulatedEvents(&This, (GeneriQ *)&This.evtQ, true);
    11041101    ps2mR3PutEventWorker(&This, 0, 0, 0, 0, 0);
    1105     if (ps2mHaveEvents(&This))
     1102    if (ps2mR3HaveEvents(&This))
    11061103        ps2mReportAccumulatedEvents(&This, (GeneriQ *)&This.evtQ, true);
    11071104    ps2mR3PutEventWorker(&This, 0, 0, 0, 0, 1);
    11081105    ps2mR3PutEventWorker(&This, 0, 0, 0, 0, 0);
    1109     if (ps2mHaveEvents(&This))
     1106    if (ps2mR3HaveEvents(&This))
    11101107        ps2mReportAccumulatedEvents(&This, (GeneriQ *)&This.evtQ, true);
    1111     if (ps2mHaveEvents(&This))
     1108    if (ps2mR3HaveEvents(&This))
    11121109        ps2mReportAccumulatedEvents(&This, (GeneriQ *)&This.evtQ, true);
    11131110    for (i = 0; i < 12; ++i)
     
    11241121     * testing fixes for the previous issue.  Test that that works. */
    11251122    ps2mR3PutEventWorker(&This, 0, 0, 0, 0, 1);
    1126     if (ps2mHaveEvents(&This))
     1123    if (ps2mR3HaveEvents(&This))
    11271124        ps2mReportAccumulatedEvents(&This, (GeneriQ *)&This.evtQ, true);
    1128     if (ps2mHaveEvents(&This))
     1125    if (ps2mR3HaveEvents(&This))
    11291126        ps2mReportAccumulatedEvents(&This, (GeneriQ *)&This.evtQ, true);
    11301127    for (i = 0; i < 3; ++i)
     
    11411138#endif /* RT_STRICT && IN_RING3 */
    11421139
    1143 #endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette