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

📄 disk.c

📁 MIPS YAMON, a famous monitor inc. source, make file and PDF manuals.
💻 C
📖 第 1 页 / 共 2 页
字号:
      case IDE_CMD_IDENTIFY :	*flush   = FALSE;	*dev_all = !dev_valid;	if( int_count != 0 ) 	    return SHELL_ERROR_SYNTAX;	break;      case IDE_CMD_WRITE : 	*flush   = FALSE;	/* Fallthrough !!! */      case IDE_CMD_READ :	*dev_all = FALSE;	if( (int_count != 3) || !dev_valid ) 	    return SHELL_ERROR_SYNTAX;	else            return sys_validate_range(	                (UINT32)(*addr),			(*count) * IDE_BYTES_PER_SECTOR,			sizeof(UINT8),			(*command == IDE_CMD_WRITE) );    }    return OK;}/************************************************************************ *                          do_access ************************************************************************/static UINT32do_access(    t_ide_ctrl_descriptor *ide_ctrl,    UINT8		  *addr,    UINT32		  device,    UINT32		  count ){    UINT32		      rc;    char		      *s;    char		      msg[100];    UINT32		      len;    UINT32		      size_mb;    t_FLASH_write_descriptor  flash_write;    UINT8		      buffer_tmp[IDE_BYTES_PER_SECTOR];    UINT32		      count_dot_freq = 0;    UINT32		      dot_count = 0;    bool		      print_dot;    if( ide_ctrl->command == IDE_CMD_IDENTIFY )    {        rc = IO_ctrl( SYS_MAJOR_IDE, device, ide_ctrl );        if( rc != OK )	    return rc;	/* Logical name */        switch( device )	{          case IDE_MINOR_PRIMARY_MASTER   : s = "hda"; break;          case IDE_MINOR_PRIMARY_SLAVE    : s = "hdb"; break;          case IDE_MINOR_SECONDARY_MASTER : s = "hdc"; break;	  case IDE_MINOR_SECONDARY_SLAVE  : s = "hdd"; break;	}	strcpy( msg, s ); 	strcat( msg, ": " );	/* Model name */	len = strlen( msg );	strncpy( &msg[len],		 ide_ctrl->u.identify.model_name, 		 IDE_MODEL_NAME_LEN );	/* Remove spaces */	len += IDE_MODEL_NAME_LEN - 1;	while( msg[len] == ' ' )	    len--;	msg[len+1] = '\0';		/* LBA sector count */	len = strlen( msg );        sprintf( &msg[len], 		 ", LBA sectors = 0x%08x ",                  ide_ctrl->u.identify.lba_sector_count );	/*  Size in MByte ("decimal" MB/GB)	 *	 *  Number of MByte = sector count / 10^6 * bytes per sector	 *	 *  We divide by 10^6 first in order to avoid overflow. This	 *  however causes rounding down error, so we adjust for the	 *  remainder from the division.	 */        size_mb =  ide_ctrl->u.identify.lba_sector_count / 1000000 *		   IDE_BYTES_PER_SECTOR;		size_mb += ide_ctrl->u.identify.lba_sector_count % 1000000 *		   IDE_BYTES_PER_SECTOR /		   1000000;	len = strlen( msg );        if( size_mb < 1000 )            sprintf( &msg[len], "(%d MB)", (UINT32)size_mb );        else            sprintf( &msg[len], "(%d GB)", (UINT32)(size_mb / 1000) );	/* Print string */	strcat( msg, "\n" );	if( SHELL_PUTS( msg ) ) return SHELL_ERROR_CONTROL_C_DETECTED;    }    else    {        /* Read/write */	if( ide_ctrl->command == IDE_CMD_READ )	{	    /* Read (one sector at a time) */            ide_ctrl->u.sector.buffer = buffer_tmp;	    ide_ctrl->u.sector.count  = 1;	    flash_write.adr	      = (UINT32)addr;            flash_write.length	      = IDE_BYTES_PER_SECTOR;            flash_write.buffer	      = buffer_tmp;	}	else	{	    /* Write (multiple sectors at a time) */            ide_ctrl->u.sector.buffer = addr;	    ide_ctrl->u.sector.count  = MIN(count, SECTORS_PER_DOT);	    print_dot		      = (count > SECTORS_PER_DOT);	}	do	{            rc = IO_ctrl( SYS_MAJOR_IDE, device, ide_ctrl );	    if( rc == OK )	    {	        count		          -= ide_ctrl->u.sector.count;	        ide_ctrl->u.sector.sector += ide_ctrl->u.sector.count;	        if( ide_ctrl->command == IDE_CMD_READ )		{		    /* This flash copy function can also handle RAM */		    rc = IO_write( SYS_MAJOR_FLASH_STRATA, 0, &flash_write );		    flash_write.adr += IDE_BYTES_PER_SECTOR;		    print_dot = (++count_dot_freq % SECTORS_PER_DOT == 0);		}		else		{	            ide_ctrl->u.sector.buffer += ide_ctrl->u.sector.count *					         IDE_BYTES_PER_SECTOR;	            ide_ctrl->u.sector.count   = MIN(count, SECTORS_PER_DOT);		    if( count == 0 ) 		        print_dot = FALSE;		}                if( (rc == OK) && print_dot && shell_print_dot(&dot_count) )		{                    rc = SHELL_ERROR_CONTROL_C_DETECTED;		}	    }        }	while( count && (rc == OK) );    }    if( dot_count )        printf( "\n" );    return rc;}/* Command definition for disk */static t_cmd cmd_def ={    "disk",    disk,    "disk [-f] (id [hda|hdb|hdc|hdd]                          ) |\n"    "          (read  hda|hdb|hdc|hdd <sector> <count> <addr> ) |\n"    "          (write hda|hdb|hdc|hdd <sector> <count> <addr> )",    "Command for copying data to/from IDE harddisk or compact flash module.\n"    "\n"    "The disks are named the following way :\n"    "\n"    "Primary master   : hda\n"    "Primary slave    : hdb\n"    "Secondary master : hdc\n"    "Secondary slave  : hdd\n"    "\n"    "When a single device is attached to an interface, it is recommended\n"    "to set it as master. Otherwise, the device may not be detected\n"    "immediately following a reset. For example, a 'disk id' command may\n"    "not detect the device if executed directly following a reset, but\n"    "will detect the device after a few seconds.\n"    "\n"    "Depending on the configuration, a command executed directly following\n"    "a reset may take up to 30 seconds to complete (not including the time\n"    "required for reading/writing data).\n"    "\n"    "Only LBA addressing is supported.\n"    "\n"    "Description :\n"    "\n"    "'disk id'    Lists disk parameters (ID, size) for all disks available\n"    "             or the particular one (hda/hdb/hdc/hdd) requested.\n"    "\n"    "'disk read'  Reads <count> sectors starting at <sector>.\n"    "             Data is written to <addr>.\n"    "\n"    "'disk write' Writes <count> sectors starting at <sector>.\n"    "             Data is read from <addr>.\n"    "\n"    "If a read operation is performed, and <addr> is flash, the destination\n"    "area must be cleared using the 'erase' command prior to the disk\n"    "operation.\n"    "\n"    "Unless the -f option is applied, caches are flushed before and after\n"    "a read operation (D-cache writeback and invalidate, I-cache invalidate).\n",    options,    OPTION_COUNT,    FALSE};/************************************************************************ *  Implementation : Public functions ************************************************************************//************************************************************************ * *                          shell_disk_init *  Description : *  ------------- * *  Initialise command * *  Return values : *  --------------- * *  void * ************************************************************************/t_cmd *shell_disk_init( void ){    return &cmd_def;}/************************************************************************ * *                          shell_ide_display *  Description : *  ------------- * *  Display IDE configuration * *  Return values : *  --------------- * *  None * ************************************************************************/UINT32shell_ide_display(void){    t_ide_ctrl_descriptor ide_ctrl;    UINT32		  rc;    ide_ctrl.command = IDE_CMD_IDENTIFY;      /* Ignore error codes (except ctrl-c) */    rc = do_access( &ide_ctrl, NULL, IDE_MINOR_PRIMARY_MASTER,   0 );    if( rc == SHELL_ERROR_CONTROL_C_DETECTED ) return rc;    rc = do_access( &ide_ctrl, NULL, IDE_MINOR_PRIMARY_SLAVE,    0 );    if( rc == SHELL_ERROR_CONTROL_C_DETECTED ) return rc;    rc = do_access( &ide_ctrl, NULL, IDE_MINOR_SECONDARY_MASTER, 0 );    if( rc == SHELL_ERROR_CONTROL_C_DETECTED ) return rc;    rc = do_access( &ide_ctrl, NULL, IDE_MINOR_SECONDARY_SLAVE,  0 );    if( rc == SHELL_ERROR_CONTROL_C_DETECTED ) return rc;    return OK;}

⌨️ 快捷键说明

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