home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / kernex32.zip / mwdd_src.zip / 32bits / ext2-os2 / mwdd32 / mwdd32_init_base.c < prev    next >
C/C++ Source or Header  |  1997-03-16  |  7KB  |  215 lines

  1. //
  2. // $Header: d:\\32bits\\ext2-os2\\mwdd32\\rcs\\mwdd32_init_base.c,v 1.3 1997/03/16 12:44:29 Willm Exp $
  3. //
  4.  
  5. // 32 bits OS/2 device driver and IFS support. Provides 32 bits kernel 
  6. // services (DevHelp) and utility functions to 32 bits OS/2 ring 0 code 
  7. // (device drivers and installable file system drivers).
  8. // Copyright (C) 1995, 1996, 1997  Matthieu WILLM (willm@ibm.net)
  9. //
  10. // This program is free software; you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation; either version 2 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program; if not, write to the Free Software
  22. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  
  24. #define INCL_DOSERRORS
  25. #define INCL_NOPMAPI
  26. #include <os2.h>
  27.  
  28. #include <string.h>
  29.  
  30. #include <os2/types.h>
  31. #include <os2/StackToFlat.h>
  32. #include <os2/DevHlp32.h>
  33. #include <reqpkt32.h>
  34.  
  35. #include "mwdd32_entry_points.h"
  36.  
  37.  
  38. extern unsigned short codeend;
  39. extern unsigned short dataend;
  40. extern PTR16          DevHelp2;
  41.  
  42. extern int mwdd32_pre_init_base(PTR16 reqpkt);
  43.  
  44. unsigned long *DosTable;
  45.  
  46. /*
  47.  * Got it from kernel debugger ...
  48.  */
  49. struct DosTable2 {
  50.     unsigned long ErrMap24                     ;
  51.     unsigned long MsgMap24                     ;
  52.     unsigned long Err_Table_24                 ;
  53.     unsigned long CDSAddr                      ;
  54.     unsigned long GDT_RDR1                     ;
  55.     unsigned long InterruptLevel               ;
  56.     unsigned long _cInDos                      ;
  57.     unsigned long zero_1                       ;
  58.     unsigned long zero_2                       ;
  59.     unsigned long FlatCS                       ;
  60.     unsigned long FlatDS                       ;
  61.     unsigned long _TKSSBase                    ;
  62.     unsigned long intSwitchStack               ;
  63.     unsigned long privateStack                 ;
  64.     unsigned long PhysDiskTablePtr             ;
  65.     unsigned long forceEMHandler               ;
  66.     unsigned long ReserveVM                    ;
  67.     unsigned long pgpPageDir                   ;
  68.     unsigned long unknown                      ;
  69. };
  70.  
  71. extern char code32_end;
  72. extern char data32_end;
  73.  
  74. extern void begin_code32(void);
  75. extern int  begin_data32;
  76.  
  77. int _dllentry = 0;
  78.  
  79. int LockSegments(void) {
  80.     APIRET rc;
  81.     ULONG  PgCount;
  82.     char   lock[12];
  83.  
  84.     /*
  85.      * Locks DGROUP into physical memory
  86.      */
  87.     if ((rc = DevHlp32_VMLock(
  88.                         VMDHL_LONG | VMDHL_WRITE | VMDHL_VERIFY,
  89.                         &begin_data32,
  90.                         (ULONG)(&data32_end) - (ULONG)(&begin_data32),
  91.                         (void *)-1,
  92.                         __StackToFlat(lock),
  93.                         __StackToFlat(&PgCount))) == NO_ERROR) {
  94.         /*
  95.          * Locks CODE32 into physical memory
  96.          */
  97.         if ((rc = DevHlp32_VMLock(
  98.                             VMDHL_LONG | VMDHL_VERIFY,
  99.                             (void *)begin_code32,
  100.                             (ULONG)(&code32_end) - (ULONG)begin_code32,
  101.                             (void *)-1,
  102.                             __StackToFlat(lock),
  103.                             __StackToFlat(&PgCount))) == NO_ERROR) {
  104.             /*
  105.              * Nothing else to do ...
  106.              */
  107.         }
  108.     }
  109.     return rc;
  110. }
  111.  
  112.  
  113. extern char banner[];
  114.  
  115. void *TKSSBase;
  116. PTR16 DevHelp2;
  117.  
  118. #pragma pack(1)
  119. struct ddd32_parm_list {
  120.   unsigned short cache_parm_list;        /* addr of InitCache_Parameter List  */
  121.   unsigned short disk_config_table;      /* addr of disk_configuration table  */
  122.   unsigned short init_req_vec_table;     /* addr of IRQ_Vector_Table          */
  123.   unsigned short cmd_line_args;          /* addr of Command Line Args         */
  124.   unsigned short machine_config_table;   /* addr of Machine Config Info       */
  125. };
  126. #pragma pack()
  127.  
  128. int mwdd32_init_base(PTR16 reqpkt) {
  129.     int                 status;
  130.     int                 rc;
  131.     struct reqpkt_init     *request;
  132.     struct ddd32_parm_list *cmd;
  133.     unsigned short      tmpsel;
  134.     char                *szParm;
  135.     char                *tmp;
  136.     char                quiet = 0;
  137.     PTR16               tmpparm;
  138.  
  139.     /*
  140.      * Initialize request status
  141.      */
  142.     status = 0;
  143.  
  144.     /*
  145.      * We first do preliminaty init code so that DevHelp32 functions and
  146.      * __StackToFlat() can be called.
  147.      */
  148.     if ((rc = mwdd32_pre_init_base(reqpkt)) == NO_ERROR) {
  149.         /*
  150.          * Now we convert the 16:16 request packet pointer to FLAT
  151.          */
  152.         if ((rc = DevHlp32_VirtToLin(reqpkt, __StackToFlat(&request))) == NO_ERROR) {
  153.             /*
  154.              * Now we convert the 16:16 command line pointer to FLAT
  155.              */
  156.             if ((rc = DevHlp32_VirtToLin(request->u.input.initarg, __StackToFlat(&cmd))) == NO_ERROR) {
  157.         tmpparm.seg = request->u.input.initarg.seg;
  158.         tmpparm.ofs = cmd->cmd_line_args;
  159.                 if ((rc = DevHlp32_VirtToLin(tmpparm, __StackToFlat(&szParm))) == NO_ERROR) {
  160.                     strupr(szParm);
  161.                     for (tmp = strpbrk(szParm, "-/"); tmp; tmp = strpbrk(tmp, "-/")) {
  162.                 tmp ++;
  163.                         //
  164.                         // Quiet initialization.
  165.                         //
  166.                         if (strncmp(tmp, "Q", sizeof("Q") - 1) == 0) {
  167.                             quiet = 1;
  168.                             continue;
  169.                         }
  170.                     }
  171.  
  172.                     /*
  173.                      * locks the 32 bits segments in memory
  174.                      */
  175.                     if ((rc = LockSegments()) == NO_ERROR) {
  176.                             if (!quiet)
  177.                                 DevHlp32_SaveMessage(banner, strlen(banner) + 1);
  178.                             request->u.output.codeend = codeend;
  179.                             request->u.output.dataend = dataend;
  180.                     } else {
  181.                         /*
  182.                          * couldn't lock 32 bits segments
  183.                          */
  184.                         status |= STERR + ERROR_I24_QUIET_INIT_FAIL;
  185.                     }
  186.        
  187.                 } else {
  188.                     /*
  189.                      * Error while thunking command line pointer
  190.                      */
  191.                     status |= STERR + ERROR_I24_QUIET_INIT_FAIL;
  192.                 }
  193.             } else {
  194.                 /*
  195.                  * Error while thunking command line pointer
  196.                  */
  197.                 status |= STERR + ERROR_I24_QUIET_INIT_FAIL;
  198.             }
  199.         } else {
  200.             /*
  201.              * Error while thunking reqpkt
  202.              */
  203.             status |= STERR + ERROR_I24_QUIET_INIT_FAIL;
  204.         }
  205.     } else {
  206.         status |= STERR + ERROR_I24_QUIET_INIT_FAIL;
  207.         /*
  208.          * error in mwdd32_pre_init
  209.          */
  210.     }
  211.  
  212.     return (status | STDON);
  213. }
  214.  
  215.