⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 builtins.c

📁 grub4dos-0.4.4-2008- 08-src.zip
💻 C
📖 第 1 页 / 共 5 页
字号:
		chain_load_segment = (unsigned short)chainloader_load_segment;		chain_load_offset = (unsigned short)chainloader_load_offset;		chain_boot_CS = (unsigned short)chainloader_boot_CS;		chain_boot_IP = (unsigned short)chainloader_boot_IP;		chain_load_length = chainloader_load_length;		if (! chainloader_ebx_set)		{			chainloader_ebx_set = 1;			chainloader_ebx = boot_drive;		}		chain_ebx = chainloader_ebx;		chain_ebx_set = chainloader_ebx_set;		chain_edx = chainloader_edx;		chain_edx_set = chainloader_edx_set;		chain_enable_gateA20 = ! chainloader_disable_A20;				/* Check if we should set the int13 handler.  */		if (unset_int13_handler (1) && ! drive_map_slot_empty (bios_drive_map[0]))		{		  /* Set the handler. This is somewhat dangerous.  */		  set_int13_handler (bios_drive_map);		  buf_drive = -1;		  buf_track = -1;		}		/* move the code to a safe place at 0x2B0000 */		grub_memmove((char *)HMA_ADDR, HMA_start, 0x200/*0xfff0*/);		//typedef void (*HMA_FUNC)(void);		//((HMA_FUNC)0x100000)();	/* no return */		/* Jump to high memory area. This will move boot code at		 * 0x110000 to the destination load-segment:load-offset;		 * setup edx and ebx registers; switch to real mode;		 * and jump to boot-cs:boot-ip.		 */		((void (*)(void))HMA_ADDR)();	/* no return */		break;	}#endif      if (chainloader_disable_A20)      {	if (gateA20 (0))		grub_printf("\nGate A20 is turned off successfully.\n");	else {		/* to asure A20 is on when we return to grub. */		gateA20 (1);	/* turn on A20 in case it is off */		errnum = ERR_DISABLE_A20;		break;	}      }      /* Check if we should set the int13 handler.  */      if (unset_int13_handler (1) && ! drive_map_slot_empty (bios_drive_map[0]))	{	  /* Set the handler. This is somewhat dangerous.  */	  set_int13_handler (bios_drive_map);	  buf_drive = -1;	  buf_track = -1;	}      	if ((boot_drive & 0x80) == 0)	{	  /* clear number of hidden sectors for floppy */	  if (! probe_bpb((struct master_and_dos_boot_sector *)0x7C00))	    if (*((unsigned long *) (0x7C00 + 0x1C)))	        *((unsigned long *) (0x7C00 + 0x1C)) = 0;	} else {	  if (! probe_bpb((struct master_and_dos_boot_sector *)0x7C00))	    if (*((unsigned long *) (0x7C00 + 0x1C)) == 0)	    {	      if (probe_mbr ((struct master_and_dos_boot_sector *)0x7C00, 0, 1, 0))	      {		errnum = ERR_HD_VOL_START_0;	  	break;	      }	    }	}#ifdef FSYS_PXE      pxe_unload();#endif      chain_stage1 (0, 0x7C00, boot_part_addr); /* no return */      break;    case KERNEL_TYPE_MULTIBOOT:      /* Multiboot */            /* Set the boot loader name.  */      mbi.boot_loader_name = (unsigned long) "GNU GRUB " VERSION;      /* Get the ROM configuration table by INT 15, AH=C0h.  */      mbi.config_table = get_rom_config_table ();#if 0      /* Get the APM BIOS table.  */      get_apm_info ();      if (apm_bios_info.version)      {	mbi.apm_table = (unsigned long) &apm_bios_info;	mbi.flags |= MB_INFO_APM_TABLE;      }#endif      multi_boot ((int) entry_addr, (int) &mbi);      break;    default:      errnum = ERR_BOOT_COMMAND;      //return 0;    }  old_errnum = errnum;  /* if we get back here, we should go back to what our term was before */  setcursor (old_cursor);  current_term = prev_term;  if (current_term->startup)      /* if our terminal fails to initialize, fall back to console since       * it should always work */      if ((*current_term->startup)() == 0)          current_term = term_table; /* we know that console is first */  errnum = old_errnum;  return ! errnum;}static struct builtin builtin_boot ={  "boot",  boot_func,  BUILTIN_MENU | BUILTIN_CMDLINE | BUILTIN_HELP_LIST,  "boot",  "Boot the OS/chain-loader which has been loaded."};#endif /* ! GRUB_UTIL */#ifdef SUPPORT_NETBOOT#ifndef GRUB_UTIL/* bootp */static intbootp_func (char *arg, int flags){  int with_configfile = 0;  if (grub_memcmp (arg, "--with-configfile", sizeof ("--with-configfile") - 1)      == 0)    {      with_configfile = 1;      arg = skip_to (0, arg);    }    if (! bootp ())    {      if (errnum == ERR_NONE)	errnum = ERR_DEV_VALUES;      return 0;    }  /* Notify the configuration.  */  print_network_configuration ();  /* XXX: this can cause an endless loop, but there is no easy way to     detect such a loop unfortunately.  */  if (with_configfile)    configfile_func (config_file, flags);    return 1;}static struct builtin builtin_bootp ={  "bootp",  bootp_func,  BUILTIN_CMDLINE | BUILTIN_MENU | BUILTIN_HELP_LIST,  "bootp [--with-configfile]",  "Initialize a network device via BOOTP. If the option `--with-configfile'"  " is given, try to load a configuration file specified by the 150 vendor"  " tag."};#endif /* ! GRUB_UTIL */#endif /* SUPPORT_NETBOOT */void hexdump(unsigned long ofs,char* buf,int len){  quit_print=0;  while (len>0)    {      int cnt,k;      grub_printf ("%08X: ", ofs);      cnt=16;      if (cnt>len)        cnt=len;      for (k=0;k<cnt;k++)        {	            printf("%02X ", (unsigned char)(buf[k]));          if ((k!=15) && ((k & 3)==3))            printf(" ");        }      for (;k<16;k++)        {          printf("   ");          if ((k!=15) && ((k & 3)==3))            printf(" ");        }      printf("; ");      for (k=0;k<cnt;k++)        printf("%c",((buf[k]>=32) && (buf[k]<127))?buf[k]:'.');      printf("\n");      if (quit_print)        break;      ofs+=16;      len-=cnt;    }}/* cat */static intcat_func (char *arg, int flags){  unsigned char c;  unsigned char s[] = "0123456789abcdef";  int Hex = 0;  unsigned long len, j;  char *p;  unsigned long skip = 0;  unsigned long length = 0xffffffff;  char *locate = 0;  unsigned long len1;  quit_print = 0;  for (;;)  {    if (grub_memcmp (arg, "--hex", 5) == 0)      {	Hex = 1;      }    else if (grub_memcmp (arg, "--skip=", 7) == 0)      {	p = arg + 7;	if (! safe_parse_maxint (&p, (int *)(void *)&skip))		return 0;      }    else if (grub_memcmp (arg, "--length=", 9) == 0)      {	p = arg + 9;	if (! safe_parse_maxint (&p, (int *)(void *)(&length)))		return 0;      }    else if (grub_memcmp (arg, "--locate=", 9) == 0)      {	p = locate = arg + 9;	if (*p == '\"')	{	  while (*(++p) != '\"');	  arg = ++p; // or: arg = p;	}      }    else	break;    arg = skip_to (0, arg);  }    if (! grub_open (arg))    return 0;   filepos = skip;  if (locate)  {    if (*locate == '\"')    {      for (i = 0; i < 16 && (s[i] = *(++locate)) != '\"'; i++);      len1 = i;      s[i] = 0;    }else{      for (i = 0; i < 16 && (s[i] = *(locate++)) != ' ' && s[i] != '\t'; i++);      len1 = i;      s[i] = 0;    }    //j = skip;    for (j = skip; j - skip < length && (len = grub_read ((char *)(SCRATCHADDR + 16), 16)); j += 16)    {      if (j != skip)      for (i = 0; i < 16; i++)	if (! grub_memcmp ((char *)&s, (char *)(SCRATCHADDR + i), len1))	{	  /* print the address */	  grub_printf ("%X ", j - 16 + i);	  //break;	}      grub_memmove ((char *)SCRATCHADDR, (char *)(SCRATCHADDR + 16), 16);      //i = len;    }      for (i = 0; i < 16; i++)	if (! grub_memcmp ((char *)&s, (char *)(SCRATCHADDR + i), len1))	{	  /* print the address */	  grub_printf ("%X ", j - 16 + i);	  //break;	}  }else if (Hex == 1)  {    for (j = skip; j - skip < length && (len = grub_read ((char *)&s, 16)); j += 16)    {      hexdump(j,(char*)&s,(len>length+skip-j)?(length+skip-j):len);      if (quit_print)        break;    }  }else    for (j = 0; j < length && grub_read ((char *)&c, 1); j++)    {#if 1	grub_putchar (c);#else      /* Because running "cat" with a binary file can confuse the terminal,	 print only some characters as they are.  */      if (grub_isspace (c) || (c >= ' ' && c <= '~'))	grub_putchar (c);      else	grub_putchar ('?');#endif      if (quit_print)	break;    }    grub_close ();  return 1;}static struct builtin builtin_cat ={  "cat",  cat_func,  BUILTIN_MENU | BUILTIN_CMDLINE | BUILTIN_HELP_LIST,  "cat [--hex] [--skip=S] [--length=L] [--locate=STRING] FILE",  "Print the contents of the file FILE, or print the locations "  "of the string STRING in FILE."};#if ! defined(GRUB_UTIL) && ! defined (STAGE1_5)/* cdrom */static intcdrom_func (char *arg, int flags){  char *p;  unsigned long tmp;    for (;;)  {    if (grub_memcmp (arg, "--add-io-ports=", 15) == 0)      {	p = arg + 15;	if (! safe_parse_maxint (&p, (int *)(void *)&tmp))		return 0;	*reg_base_addr_append = tmp;	return 1;      }    else if (grub_memcmp (arg, "--init", 6) == 0)      {	init_atapi();	if (atapi_dev_count)	{	  if (debug > 0)	    printf("\nFound %d CD-ROM%s. (Note: Further read could fail if the hardware does not\nfully support ATAPI).\n", atapi_dev_count, atapi_dev_count > 1 ? "s" : "");	} else {	  if (debug > 0)	    printf("\nNo CD-ROMs found. Perhaps the hardware does not fully support ATAPI. If your\nCD-ROM uses unusual I/O ports, please specify them with \"--add-io-ports=P\".\n");	}	return atapi_dev_count;      }    else if (grub_memcmp (arg, "--stop", 6) == 0)      {	atapi_dev_count = 0;	return 1;      }    else      return ! (errnum = ERR_BAD_ARGUMENT);    arg = skip_to (0, arg);  }    return 1;}static struct builtin builtin_cdrom ={  "cdrom",  cdrom_func,  BUILTIN_MENU | BUILTIN_CMDLINE | BUILTIN_HELP_LIST,  "cdrom --add-io-ports=P | --init | --stop",  "Initialise/stop atapi cdroms or set additional I/O ports for a possible atapi cdrom device."  " The high word of P specifies the base register of the control block registers, and"  " the low word of P specifies the base register of the command block registers."};#endif /* ! defined(GRUB_UTIL) && ! defined (STAGE1_5) *//* chainloader */static intchainloader_func (char *arg, int flags){  char *p;  int force = 0;  char *filename;//  unsigned long hidden_sectors;  chainloader_load_segment_orig = chainloader_load_segment;  chainloader_load_offset_orig = chainloader_load_offset;  chainloader_load_length_orig = chainloader_load_length;  chainloader_skip_length_orig = chainloader_skip_length;  chainloader_boot_CS_orig = chainloader_boot_CS;  chainloader_boot_IP_orig = chainloader_boot_IP;  chainloader_ebx_orig = chainloader_ebx;  chainloader_ebx_set_orig = chainloader_ebx_set;  chainloader_edx_orig = chainloader_edx;  chainloader_edx_set_orig = chainloader_edx_set;  chainloader_disable_A20_orig = chainloader_disable_A20;  is_sdi_orig = is_sdi;  is_raw_orig = is_raw;  is_isolinux_orig = is_isolinux;  kernel_type_orig = kernel_type;  grub_memmove ((char *)chainloader_file_orig, (char *)chainloader_file, sizeof(chainloader_file));  chainloader_load_segment = -1;//0x0000;  chainloader_load_offset = -1;//0x7c00;  chainloader_load_length = -1;//0x200;  chainloader_skip_length = 0;  chainloader_boot_CS = -1;//0x0000;  chainloader_boot_IP = -1;//0x7c00;  chainloader_ebx = 0;  chainloader_ebx_set = 0;  chainloader_edx = 0;  chainloader_edx_set = 0;  chainloader_disable_A20 = 0;  is_sdi = is_raw = 0;  is_isolinux = 0;  kernel_type = KERNEL_TYPE_CHAINLOADER;  for (;;)  {    if (grub_memcmp (arg, "--force", 7) == 0)      {	force = 1;      }    else if (grub_memcmp (arg, "--load-segment=", 15) == 0)      {	p = arg + 15;	if (! safe_parse_maxint (&p, &chainloader_load_segment))		goto failure;	if (chainloader_load_segment < 0 || chainloader_load_segment >= 0xa000)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -