mirror of
				https://github.com/FDOS/kernel.git
				synced 2025-11-04 05:05:11 +01:00 
			
		
		
		
	memdisk rework to not require fd=, better handling of memdisk options inbetween config commands
This commit is contained in:
		
							parent
							
								
									9c7e161526
								
							
						
					
					
						commit
						69f76c377e
					
				
							
								
								
									
										205
									
								
								kernel/config.c
									
									
									
									
									
								
							
							
						
						
									
										205
									
								
								kernel/config.c
									
									
									
									
									
								
							@ -202,6 +202,7 @@ STATIC VOID CfgMenuEsc(BYTE * pLine);
 | 
				
			|||||||
STATIC VOID DoMenu(void);
 | 
					STATIC VOID DoMenu(void);
 | 
				
			||||||
STATIC VOID CfgMenuDefault(BYTE * pLine);
 | 
					STATIC VOID CfgMenuDefault(BYTE * pLine);
 | 
				
			||||||
STATIC BYTE * skipwh(BYTE * s);
 | 
					STATIC BYTE * skipwh(BYTE * s);
 | 
				
			||||||
 | 
					STATIC int iswh(unsigned char c);
 | 
				
			||||||
STATIC BYTE * scan(BYTE * s, BYTE * d);
 | 
					STATIC BYTE * scan(BYTE * s, BYTE * d);
 | 
				
			||||||
STATIC BOOL isnum(char ch);
 | 
					STATIC BOOL isnum(char ch);
 | 
				
			||||||
#if 0
 | 
					#if 0
 | 
				
			||||||
@ -617,6 +618,94 @@ struct memdiskinfo {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/* query_memdisk() based on similar subroutine in Eric Auer's public domain getargs.asm which is based on IFMEMDSK */
 | 
					/* query_memdisk() based on similar subroutine in Eric Auer's public domain getargs.asm which is based on IFMEMDSK */
 | 
				
			||||||
struct memdiskinfo FAR * ASMCFUNC query_memdisk(UBYTE drive);
 | 
					struct memdiskinfo FAR * ASMCFUNC query_memdisk(UBYTE drive);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct memdiskopt {
 | 
				
			||||||
 | 
					  BYTE * name;
 | 
				
			||||||
 | 
					  UWORD size;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Given a pointer to a memdisk command line and buffer will copy the next
 | 
				
			||||||
 | 
					   config.sys equivalent line to pLine and return updated cLine.
 | 
				
			||||||
 | 
					   Call repeatedly until end of string (*cLine == '\0').
 | 
				
			||||||
 | 
					   Each simulated line is indicated be enclosing the line in curly braces {}
 | 
				
			||||||
 | 
					   with the end } optional - the next { will indicate end/beginning and
 | 
				
			||||||
 | 
					   end of line.  MEMDISK options may appear nearly anywhere on line and are
 | 
				
			||||||
 | 
					   ignored - see memdisk_opts for list of recognized options.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					  BYTE FAR * GetNextMemdiskLine(BYTE FAR *cLine, BYTE *pLine)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    int ws = TRUE;
 | 
				
			||||||
 | 
					    BYTE FAR *ptr;
 | 
				
			||||||
 | 
					    STATIC struct memdiskopt memdiskopts[] = {
 | 
				
			||||||
 | 
					      {"initrd", 6}, {"BOOT_IMAGE", 10},
 | 
				
			||||||
 | 
					      {"c", 1}, {"h", 1}, {"s", 1}, 
 | 
				
			||||||
 | 
					      {"floppy", 6}, {"harddisk", 8}, {"iso", 3}, 
 | 
				
			||||||
 | 
					      {"raw", 3}, {"bigraw", 6}, {"int", 3}, {"safeint", 7},
 | 
				
			||||||
 | 
					      {"nopass", 6}, {"nopassany", 9},
 | 
				
			||||||
 | 
					      {"edd", 3}, {"noedd", 5}
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    /* skip everything until end of line or starting { */
 | 
				
			||||||
 | 
					    for (; *cLine && (*cLine != '{'); ++cLine)
 | 
				
			||||||
 | 
					      ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* exit early if end of line reached, else skip past { */
 | 
				
			||||||
 | 
					    if (!*cLine)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      *pLine = 0;
 | 
				
			||||||
 | 
					      return cLine;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    cLine++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* scan for end marker }, start of next line {, or end of line */
 | 
				
			||||||
 | 
					    for (ptr = cLine; *ptr && (*ptr != '}') && (*ptr != '{'); ++ptr)
 | 
				
			||||||
 | 
					      ;
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					    /* copy to pLine buffer, skipping memdisk options */
 | 
				
			||||||
 | 
					    while (*cLine && (cLine < ptr))
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      /* if last character was whitespace (or start of line) check for memdisk option to skip */
 | 
				
			||||||
 | 
					      if (ws)
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        int i;
 | 
				
			||||||
 | 
					        for (i = 0; i < 16; ++i)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          /* compare with option */
 | 
				
			||||||
 | 
					          if (fmemcmp(cLine, memdiskopts[i].name, memdiskopts[i].size) == 0) 
 | 
				
			||||||
 | 
					          {
 | 
				
			||||||
 | 
					            BYTE FAR *tmp = cLine + memdiskopts[i].size;
 | 
				
			||||||
 | 
					            /* ensure character after is end of line, =, or whitespace */
 | 
				
			||||||
 | 
					            if (!*tmp || (*tmp == '=') || iswh(*tmp))
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					              cLine = tmp;
 | 
				
			||||||
 | 
					              if (*cLine == '=')
 | 
				
			||||||
 | 
					              {
 | 
				
			||||||
 | 
					                /* skip past all characters after = */
 | 
				
			||||||
 | 
					                for (; *cLine && (cLine < ptr) && !iswh(*cLine); ++cLine)
 | 
				
			||||||
 | 
					                  ;
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
 | 
					              
 | 
				
			||||||
 | 
					              break;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      if (cLine < ptr)
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        *pLine = *cLine;
 | 
				
			||||||
 | 
					        ws = iswh(*pLine);
 | 
				
			||||||
 | 
					        ++cLine;
 | 
				
			||||||
 | 
					        ++pLine;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    *pLine = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* return location to begin next scan from */    
 | 
				
			||||||
 | 
					    if (*ptr == '}') ptr++;
 | 
				
			||||||
 | 
					    return ptr;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -624,18 +713,18 @@ VOID DoConfig(int nPass)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
  COUNT nFileDesc;
 | 
					  COUNT nFileDesc;
 | 
				
			||||||
  BYTE *pLine;
 | 
					  BYTE *pLine;
 | 
				
			||||||
  BOOL bEof;
 | 
					  BOOL bEof = FALSE;
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef MEMDISK_ARGS
 | 
					#ifdef MEMDISK_ARGS
 | 
				
			||||||
  /* check if MEMDISK used for LoL->BootDrive, if so check for special appended arguments */
 | 
					  /* check if MEMDISK used for LoL->BootDrive, if so check for special appended arguments */
 | 
				
			||||||
  struct memdiskinfo FAR *mdsk;
 | 
					  struct memdiskinfo FAR *mdsk = NULL;
 | 
				
			||||||
  BYTE FAR *mdsk_cfg = NULL;
 | 
					  BYTE FAR *cLine;
 | 
				
			||||||
  /* memdisk check & usage requires 386+, DO NOT invoke if less than 386 */
 | 
					  /* memdisk check & usage requires 386+, DO NOT invoke if less than 386 */
 | 
				
			||||||
  if (LoL->cpu >= 3)
 | 
					  if (LoL->cpu >= 3)
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    UBYTE drv = (LoL->BootDrive < 3)?0x0:0x80; /* 1=A,2=B,3=C */
 | 
					    UBYTE drv = (LoL->BootDrive < 3)?0x0:0x80; /* 1=A,2=B,3=C */
 | 
				
			||||||
    mdsk = query_memdisk(drv);
 | 
					    mdsk = query_memdisk(drv);
 | 
				
			||||||
 | 
					    if (mdsk != NULL) cLine = mdsk->cmdline;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -648,40 +737,14 @@ VOID DoConfig(int nPass)
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
      printf("MEMDISK version %u.%02u  (%lu sectors)\n", mdsk->version, mdsk->version_minor, mdsk->size);
 | 
					      printf("MEMDISK version %u.%02u  (%lu sectors)\n", mdsk->version, mdsk->version_minor, mdsk->size);
 | 
				
			||||||
      DebugPrintf(("MEMDISK args:{%S}\n", mdsk->cmdline));
 | 
					      DebugPrintf(("MEMDISK args:{%S}\n", mdsk->cmdline));
 | 
				
			||||||
 | 
					      printf("MEMDISK args:{%S}\n", mdsk->cmdline);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#endif
 | 
					    else
 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef MEMDISK_ARGS
 | 
					 | 
				
			||||||
  if (mdsk != NULL)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    /* scan for FD= */
 | 
					 | 
				
			||||||
    /* when done mdsk->cmdline points to { character or assume no valid CONFIG options */
 | 
					 | 
				
			||||||
    for (mdsk_cfg=mdsk->cmdline; *mdsk_cfg; ++mdsk_cfg)
 | 
					 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      if ((*mdsk_cfg | 32) != 'f') continue;
 | 
					      DebugPrintf(("MEMDISK not detected!\n"));
 | 
				
			||||||
      ++mdsk_cfg;
 | 
					 | 
				
			||||||
      if ((*mdsk_cfg | 32) != 'd') continue;
 | 
					 | 
				
			||||||
      ++mdsk_cfg;
 | 
					 | 
				
			||||||
      
 | 
					 | 
				
			||||||
      /* skip past any extra spaces between D and = */
 | 
					 | 
				
			||||||
      while (*mdsk_cfg == ' ')
 | 
					 | 
				
			||||||
        ++mdsk_cfg;
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
      if (*mdsk_cfg != '=') continue;
 | 
					 | 
				
			||||||
      ++mdsk_cfg;
 | 
					 | 
				
			||||||
              
 | 
					 | 
				
			||||||
      /* assume found extra config options */
 | 
					 | 
				
			||||||
      break;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    /* if FD= was not found then flag as no extra CONFIG lines */
 | 
					 | 
				
			||||||
    if (!*mdsk_cfg) mdsk_cfg = NULL;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  else
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    DebugPrintf(("MEMDISK not detected! bootdrive=[%0Xh]\n", (unsigned int)drv));
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* Check to see if we have a config.sys file.  If not, just     */
 | 
					  /* Check to see if we have a config.sys file.  If not, just     */
 | 
				
			||||||
@ -697,8 +760,10 @@ VOID DoConfig(int nPass)
 | 
				
			|||||||
    if ((nFileDesc = open("config.sys", 0)) < 0)
 | 
					    if ((nFileDesc = open("config.sys", 0)) < 0)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      DebugPrintf(("CONFIG.SYS not found\n"));
 | 
					      DebugPrintf(("CONFIG.SYS not found\n"));
 | 
				
			||||||
 | 
					      /* at this point no config file was found, may return early */
 | 
				
			||||||
#ifdef MEMDISK_ARGS
 | 
					#ifdef MEMDISK_ARGS
 | 
				
			||||||
      if (mdsk_cfg != NULL)
 | 
					      /* if memdisk in use then only assume end of file reached and proceed, else return early */
 | 
				
			||||||
 | 
					      if (mdsk != NULL)
 | 
				
			||||||
        bEof = TRUE;
 | 
					        bEof = TRUE;
 | 
				
			||||||
      else
 | 
					      else
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
@ -710,26 +775,21 @@ VOID DoConfig(int nPass)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* Have one -- initialize.                                      */
 | 
					  nCfgLine = 0;  /* keep track of which line in file for errors   */
 | 
				
			||||||
  nCfgLine = 0;
 | 
					 | 
				
			||||||
  bEof = 0;
 | 
					 | 
				
			||||||
  pLine = szLine;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* Read each line into the buffer and then parse the line,      */
 | 
					  /* Read each line into the buffer and then parse the line,      */
 | 
				
			||||||
  /* do the table lookup and execute the handler for that         */
 | 
					  /* do the table lookup and execute the handler for that         */
 | 
				
			||||||
  /* function.                                                    */
 | 
					  /* function.                                                    */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef MEMDISK_ARGS
 | 
					#ifdef MEMDISK_ARGS
 | 
				
			||||||
  for (; !bEof || (mdsk_cfg != NULL); nCfgLine++)
 | 
					  for (; !bEof || (mdsk != NULL); nCfgLine++)
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
  for (; !bEof; nCfgLine++)
 | 
					  for (; !bEof; nCfgLine++)
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    struct table *pEntry;
 | 
					    struct table *pEntry;
 | 
				
			||||||
 | 
					 | 
				
			||||||
    pLineStart = szLine;
 | 
					    pLineStart = szLine;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef MEMDISK_ARGS
 | 
					#ifdef MEMDISK_ARGS
 | 
				
			||||||
    if (!bEof)
 | 
					    if (!bEof)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@ -759,67 +819,22 @@ VOID DoConfig(int nPass)
 | 
				
			|||||||
        pLine++;
 | 
					        pLine++;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    *pLine = 0;
 | 
				
			||||||
#ifdef MEMDISK_ARGS
 | 
					#ifdef MEMDISK_ARGS
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if (mdsk_cfg != NULL)
 | 
					    else if (mdsk != NULL)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        pLine = szLine;
 | 
					      cLine = GetNextMemdiskLine(cLine, szLine);
 | 
				
			||||||
 | 
					      /* if end of memdisk command line reached, flag done */
 | 
				
			||||||
        /* skip past any extra spaces before ( */
 | 
					      if (!*cLine)
 | 
				
			||||||
        while (*mdsk_cfg == ' ')
 | 
					        mdsk = NULL;
 | 
				
			||||||
          ++mdsk_cfg;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (*mdsk_cfg != '{') /* if not at start of line */
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            mdsk_cfg = NULL; /* no longer need data, so set to NULL to flag done */
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            /* copy data to near buffer skipping { and } */
 | 
					 | 
				
			||||||
            for (pLine = szLine, mdsk_cfg++; *mdsk_cfg; mdsk_cfg++, pLine++)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
              /* copy character to near buffer */
 | 
					 | 
				
			||||||
              *pLine = *mdsk_cfg;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
              /* ensure we don't copy too much, exceed our buffer size */
 | 
					 | 
				
			||||||
              if (pLine >= szLine + sizeof(szLine) - 3)
 | 
					 | 
				
			||||||
              {
 | 
					 | 
				
			||||||
                CfgFailure(pLine);
 | 
					 | 
				
			||||||
                printf("error - line overflow line %d \n", nCfgLine);
 | 
					 | 
				
			||||||
                break;
 | 
					 | 
				
			||||||
              }
 | 
					 | 
				
			||||||
              
 | 
					 | 
				
			||||||
              /* if initrd=IMAGEFILE or BOOT_IMAGE=memdisk is found, treat same as end of line & end of file */
 | 
					 | 
				
			||||||
              /* we backtrack to enable use of near pointers in memcmp */
 | 
					 | 
				
			||||||
              if ((*pLine == '=') && ((pLine - szLine) >= 7))
 | 
					 | 
				
			||||||
              {
 | 
					 | 
				
			||||||
                if ((memcmp(pLine-6, "initrd=", 7) == 0) || (memcmp(pLine-10, "BOOT_IMAGE=", 11) == 0))
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                  pLine -= 6;  /* backup */
 | 
					 | 
				
			||||||
                  if (*pLine == '_') pLine -= 4;
 | 
					 | 
				
			||||||
                  mdsk_cfg = NULL;
 | 
					 | 
				
			||||||
                  break;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
              }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
              /* if end of this simulated line is found, skip over EOL marker then proceed to process line */
 | 
					 | 
				
			||||||
              if (*pLine == '}')
 | 
					 | 
				
			||||||
              {
 | 
					 | 
				
			||||||
                  mdsk_cfg++;
 | 
					 | 
				
			||||||
                  break;
 | 
					 | 
				
			||||||
              }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    *pLine = 0;
 | 
					    DebugPrintf(("CONFIG=[%s]\n", szLine));
 | 
				
			||||||
    pLine = szLine;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    DebugPrintf(("CONFIG=[%s]\n", pLine));
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Skip leading white space and get verb.               */
 | 
					    /* Skip leading white space and get verb.               */
 | 
				
			||||||
    pLine = scan(pLine, szBuf);
 | 
					    pLine = scan(szLine, szBuf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* If the line was blank, skip it.  Otherwise, look up  */
 | 
					    /* If the line was blank, skip it.  Otherwise, look up  */
 | 
				
			||||||
    /* the verb and execute the appropriate function.       */
 | 
					    /* the verb and execute the appropriate function.       */
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user