Ignore:
Timestamp:
Sep 27, 2001, 5:08:35 AM (24 years ago)
Author:
bird
Message:

Win32k/kKrnlLib splittup: done the major stuff.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/splittup/src/win32k/dev16/d16init.c

    r6431 r6841  
    1 /* $Id: d16init.c,v 1.12 2001-07-31 21:36:37 bird Exp $
     1/* $Id: d16init.c,v 1.12.2.1 2001-09-27 03:08:10 bird Exp $
    22 *
    33 * d16init - init routines for both drivers.
     
    66 *            completed. CodeEnd and DataEnd should not be set here.?
    77 *
    8  * Copyright (c) 1999-2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
     8 * Copyright (c) 1999-2001 knut st. osmundsen (kosmunds@csc.com)
    99 *
    1010 * Project Odin Software License can be found in LICENSE.TXT
     
    3737
    3838#include "devSegDf.h"
    39 #undef  DATA16_INIT
     39/*#undef  DATA16_INIT
    4040#define DATA16_INIT
    4141#undef  CODE16_INIT
    42 #define CODE16_INIT
    43 #include "probkrnl.h"
     42#define CODE16_INIT*/
    4443#include "dev1632.h"
    4544#include "dev16.h"
    4645#include "vprntf16.h"
    47 #include "log.h"
    4846#include "options.h"
    49 #include "errors.h"
    5047
    51 
    52 /**
    53  * init function - device 0.
    54  * Does nothing else than setting the device_help variable and
    55  * fill the request packet.
    56  * @returns   Status word.
    57  * @param     pRpIn   Pointer to input request packet.  Actually the same memory as pRpOut but another struct.
    58  * @param     pRpOut  Pointer to output request packet. Actually the same memory as pRpIn  but another struct.
    59  * @remark    pRpIn and pRpOut points to the same memory.
    60  */
    61 USHORT NEAR dev0Init(PRPINITIN pRpIn, PRPINITOUT pRpOut)
    62 {
    63     APIRET  rc;
    64     Device_Help = pRpIn->DevHlpEP;
    65 
    66     /*
    67      * Does this work at Ring-3 (inittime)?
    68      * If this work we could be saved from throuble!
    69      */
    70     rc = initGetDosTableData();
    71     if (rc != NO_ERROR)
    72         printf16("win32k - elf$: initGetDosTableData failed with rc=%d\n", rc);
    73 
    74     pRpOut->BPBArray = NULL;
    75     pRpOut->CodeEnd = (USHORT)&CODE16_INITSTART;
    76     pRpOut->DataEnd = (USHORT)&DATA16_INITSTART;
    77     pRpOut->Unit     = 0;
    78     pRpOut->rph.Status = STATUS_DONE;
    79     return STATUS_DONE;
    80 }
     48#include "kKLInitHlp.h"
    8149
    8250
     
    9058 * @remark    pRpIn and pRpOut points to the same memory.
    9159 */
    92 USHORT NEAR dev1Init(PRPINITIN pRpIn, PRPINITOUT pRpOut)
     60USHORT NEAR devInit(PRPINITIN pRpIn, PRPINITOUT pRpOut)
    9361{
    94     APIRET          rc;
    95     D16R0INITPARAM  param;
    96     D16R0INITDATA   data = {0};
    97     HFILE           hDev0 = 0;
     62    ULONG           rc;
     63    KKLR0INITPARAM  param;
     64    KKLR0INITDATA   data = {0UL};
     65    HFILE           hKrnlLib = 0;
    9866    USHORT          usAction = 0;
    9967    NPSZ            npszErrMsg = NULL;
    100     const char *    npszErrMsg2 = NULL;
    10168
    10269    /*
    103      * Probe kernel data.
     70     * Open and send a Ring-0 init packet to kKrnlHlp.
     71     * If this succeeds win32k$ init succeeds.
    10472     */
    105     rc = ProbeKernel(pRpIn);
     73    rc = DosOpen(KKL_DEVICE_NAME, &hKrnlLib, &usAction, 0UL, FILE_NORMAL,
     74                 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
     75                 OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY,
     76                 0UL);
    10677    if (rc == NO_ERROR)
    10778    {
    10879        /*
    109          * Open and send a Ring-0 init packet to elf$.
    110          * If this succeeds win32k$ init succeeds.
     80         * Create new 32-bit init packet - Parameter pointer is thunked.
    11181         */
    112         rc = DosOpen("\\dev\\elf$", &hDev0, &usAction, 0UL, FILE_NORMAL,
    113                      OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
    114                      OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY,
    115                      0UL);
    116         if (rc == NO_ERROR)
    117         {
    118             param.pRpInitIn = pRpIn;
    119             rc = DosDevIOCtl(&data, &param, D16_IOCTL_RING0INIT, D16_IOCTL_CAT, hDev0);
     82        RP32INIT        rp32init;
     83        RP32INIT FAR *  fprp32init = &rp32init;
     84
     85        _fmemcpy(fprp32init, pRpIn, sizeof(RPINITIN));
     86        if ((   pRpIn->InitArgs == NULL
     87             || !(rc = DevHelp_VirtToLin(SELECTOROF(rp32init.InitArgs), OFFSETOF(rp32init.InitArgs), (PLIN)&rp32init.InitArgs))
     88             )
     89            &&  !(rc = DevHelp_VirtToLin(SELECTOROF(fprp32init), OFFSETOF(fprp32init), (PLIN)&param.ulParam))
     90           )
     91        {   /* call 32-bit init routine and set 32 bit rc. */
     92            param.pfn = GetR0InitPtr();
     93            rc = DosDevIOCtl(&data, &param, KKL_IOCTL_RING0INIT, KKL_IOCTL_CAT, hKrnlLib);
    12094            if (rc == NO_ERROR)
    12195            {
    122                 if (data.usRcInit32 == NO_ERROR)
     96                if (data.ulRc == NO_ERROR)
    12397                {
    12498                    if (!options.fQuiet)
     
    129103                {
    130104                    /* set correct error message and rc */
    131                     rc = data.usRcInit32;
    132                     npszErrMsg = "Ring-0 initiation failed. rc=%x\n";
    133                     if (rc >= ERROR_D32_FIRST && rc <= ERROR_D32_LAST)
    134                         npszErrMsg2 =
    135                         GetErrorMsg(
    136                         data.usRcInit32
    137                         + ERROR_PROB_SYM_D32_FIRST
    138                         - ERROR_D32_FIRST
    139                         );
     105                    rc = data.ulRc;
     106                    npszErrMsg = "Ring-0 initiation failed. rc=%ld\n";
    140107                }
    141108            }
    142109            else
    143                 npszErrMsg = "Ring-0 init: DosDevIOCtl failed. rc=%d\n";
    144             DosClose(hDev0);
     110                npszErrMsg = "Ring-0 init: DosDevIOCtl failed. rc=%ld\n";
    145111        }
    146112        else
    147             npszErrMsg = "Ring-0 init: DosOpen failed. rc=%d\n";
     113            npszErrMsg = "Ring-0 init: Argument thunking failed. rc=%ld\n";
     114
     115        DosClose(hKrnlLib);
    148116    }
    149117    else
    150         npszErrMsg = ""; /* ProbeKrnl do its own complaining, but we need something here to indicate failure. */
     118        npszErrMsg = "Ring-0 init: DosOpen failed. rc=%ld\n";
     119
    151120
    152121    /*
     
    164133    {
    165134        printf16(npszErrMsg, rc);
    166         if (npszErrMsg2)
    167             printf16("%s\n", npszErrMsg2);
    168135        pRpOut->Status = pRpOut->rph.Status = STATUS_DONE | STERR | ERROR_I24_GEN_FAILURE;
    169136    }
     
    177144}
    178145
    179 
    180 
    181 /**
    182  * R0 16-bit initiation.
    183  * This gets TKSSBase, thunks parameters and calls R0 32-bit initiation function.
    184  * @returns     Status word. We don't fail on R0Init32 but forwards the result
    185  *              using the usRcInit32.
    186  * @param       pRp     Generic IO Control request packet.
    187  */
    188 USHORT NEAR  R0Init16(PRP_GENIOCTL pRp)
    189 {
    190     USHORT usRc = STATUS_DONE;
    191     APIRET rc;
    192 
    193     /* First we're to get the DosTable2 stuff. */
    194     rc = initGetDosTableData();
    195     if (rc == NO_ERROR)
    196     {
    197         ULONG cPages;
    198         char  hLockParm[12] = {0};
    199         ULONG ulLinParm;
    200         char  hLockData[12] = {0};
    201         ULONG ulLinData;
    202 
    203         /*
    204          * Thunk the request packet and lock userdata.
    205          */
    206         if (!DevHelp_VirtToLin(SELECTOROF(pRp->ParmPacket), OFFSETOF(pRp->ParmPacket), &ulLinParm)
    207             &&
    208             !DevHelp_VirtToLin(SELECTOROF(pRp->DataPacket), OFFSETOF(pRp->DataPacket), &ulLinData)
    209             )
    210         {
    211             if (!(rc = DevHelp_VMLock(VMDHL_LONG | VMDHL_WRITE,
    212                                 ulLinParm, sizeof(D16R0INITPARAM),
    213                                 (LIN)~0UL, SSToDS_16(&hLockParm[0]), &cPages))
    214                 &&
    215                 !DevHelp_VMLock(VMDHL_LONG | VMDHL_WRITE,
    216                                 ulLinData, sizeof(D16R0INITDATA),
    217                                 (LIN)~0UL, SSToDS_16(&hLockData[0]), &cPages)
    218                 )
    219             {
    220                 /*
    221                  * -data and param is locked (do we need to lock the request packet too ?).-
    222                  * Create new 32-bit init packet - Parameter pointer is thunked.
    223                  */
    224                 RP32INIT rp32init;
    225 
    226                 _fmemcpy(&rp32init, ((PD16R0INITPARAM)pRp->ParmPacket)->pRpInitIn, sizeof(RPINITIN));
    227                 if (((PD16R0INITPARAM)pRp->ParmPacket)->pRpInitIn->InitArgs == NULL ||
    228                     !DevHelp_VirtToLin(SELECTOROF(rp32init.InitArgs), OFFSETOF(rp32init.InitArgs), (PLIN)&rp32init.InitArgs)
    229                    )
    230                 {   /* call 32-bit init routine and set 32 bit rc. */
    231                     usRc = CallR0Init32(SSToDS_16(&rp32init));
    232                     ((PD16R0INITDATA)pRp->DataPacket)->usRcInit32 = usRc;
    233 
    234                     /* set status to done (success).  (R0Init32 RC is return as usRcInit32.)  */
    235                     usRc = STATUS_DONE;
    236                 }
    237                 else
    238                     usRc |= STERR | ERROR_I24_INVALID_PARAMETER;
    239 
    240 
    241                 /*
    242                  * finished - unlock data and parm;
    243                  */
    244                 DevHelp_VMUnLock((LIN)SSToDS_16(&hLockParm[0]));
    245                 DevHelp_VMUnLock((LIN)SSToDS_16(&hLockData[0]));
    246             }
    247             else
    248                 usRc |= STERR | ERROR_I24_INVALID_PARAMETER;
    249         }
    250         else
    251             usRc |= STERR | ERROR_I24_INVALID_PARAMETER;
    252     }
    253     else
    254         usRc |= STERR | ERROR_I24_GEN_FAILURE;
    255 
    256     return usRc;
    257 }
    258 
    259 
    260 
    261 /**
    262  * Gets the data we need from the DosTables.
    263  * This data is TKSSBase16, R0FlatCS16 and R0FlatDS16.
    264  * @returns   Same as DevHelp_GetDosVar.
    265  * @status    completely implemented.
    266  * @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
    267  * @remark    If you are not sure if TKSSBase16 is set or not, call this.
    268  *            After R0Init16 is called TKSSBase16 _is_ set.
    269  *            IMPORTANT! This function must _not_ be called after the initiation of the second device driver!!!
    270  *                       (Since this is init code not present after init...)
    271  */
    272 USHORT NEAR  initGetDosTableData(void)
    273 {
    274     APIRET     rc;
    275     PDOSTABLE  pDT;
    276     PDOSTABLE2 pDT2;
    277 
    278     if (TKSSBase16 != 0)
    279         return NO_ERROR;
    280     /*
    281     _asm {
    282         int 3;
    283     }
    284     */
    285 
    286     /* First we're to get the DosTable2 stuff. */
    287     rc = DevHelp_GetDOSVar(9, 0, &pDT);
    288     if (rc == NO_ERROR)
    289     {
    290         pDT2 = (PDOSTABLE2)((char FAR *)pDT + pDT->cul*4 + 1);
    291         TKSSBase16 = (ULONG)pDT2->pTKSSBase;
    292         R0FlatCS16 = (USHORT)pDT2->R0FlatCS;
    293         R0FlatDS16 = (USHORT)pDT2->R0FlatDS;
    294     }
    295     return rc;
    296 }
    297 
Note: See TracChangeset for help on using the changeset viewer.