/** Read from IO space Argv[0] - "ioread"[.#] # is optional width 1, 2, or 4. Default 1 Argv[1] - Hex IO address ior.4 0x3f8 ;Do a 32-bit IO Read from 0x3f8 ior 0x3f8 ;Do a 8-bit IO Read from 0x3f8 @param Argc Number of command arguments in Argv @param Argv Array of strings that represent the parsed command line. Argv[0] is the command name @return EFI_SUCCESS **/ EFI_STATUS EblIoReadCmd ( IN UINTN Argc, IN CHAR8 **Argv ) { UINTN Width; UINTN Port; UINTN Data; if (Argc < 2) { return EFI_INVALID_PARAMETER; } Port = AsciiStrHexToUintn (Argv[1]); Width = WidthFromCommandName (Argv[0], 1); if (Width == 1) { Data = IoRead8 (Port); } else if (Width == 2) { Data = IoRead16 (Port); } else if (Width == 4) { Data = IoRead32 (Port); } else { return EFI_INVALID_PARAMETER; } AsciiPrint ("0x%04x = 0x%x", Port, Data); return EFI_SUCCESS; }
/** Write to IO space Argv[0] - "iowrite"[.#] # is optional width 1, 2, or 4. Default 1 Argv[1] - Hex IO address Argv[2] - Hex data to write iow.4 0x3f8 af ;Do a 32-bit IO write of af to 0x3f8 iow 0x3f8 af ;Do an 8-bit IO write of af to 0x3f8 @param Argc Number of command arguments in Argv @param Argv Array of strings that represent the parsed command line. Argv[0] is the command name @return EFI_SUCCESS **/ EFI_STATUS EblIoWriteCmd ( IN UINTN Argc, IN CHAR8 **Argv ) { UINTN Width; UINTN Port; UINTN Data; if (Argc < 3) { return EFI_INVALID_PARAMETER; } Port = AsciiStrHexToUintn (Argv[1]); Data = AsciiStrHexToUintn (Argv[2]); Width = WidthFromCommandName (Argv[0], 1); if (Width == 1) { IoWrite8 (Port, (UINT8)Data); } else if (Width == 2) { IoWrite16 (Port, (UINT16)Data); } else if (Width == 4) { IoWrite32 (Port, (UINT32)Data); } else { return EFI_INVALID_PARAMETER; } return EFI_SUCCESS; }
/** Toggle page break global. This turns on and off prompting to Quit or hit any key to continue when a command is about to scroll the screen with its output Argv[0] - "hexdump"[.#] # is optional 1,2, or 4 for width Argv[1] - Device or File to dump. Argv[2] - Optional offset to start dumping Argv[3] - Optional number of bytes to dump @param Argc Number of command arguments in Argv @param Argv Array of strings that represent the parsed command line. Argv[0] is the command name @return EFI_SUCCESS **/ EFI_STATUS EFIAPI EblHexdumpCmd ( IN UINTN Argc, IN CHAR8 **Argv ) { EFI_OPEN_FILE *File; VOID *Location; UINTN Size; UINTN Width; UINTN Offset = 0; EFI_STATUS Status; UINTN Chunk = HEXDUMP_CHUNK; if ((Argc < 2) || (Argc > 4)) { return EFI_INVALID_PARAMETER; } Width = WidthFromCommandName (Argv[0], 1); if ((Width != 1) && (Width != 2) && (Width != 4)) { return EFI_INVALID_PARAMETER; } File = EfiOpen (Argv[1], EFI_FILE_MODE_READ, 0); if (File == NULL) { return EFI_NOT_FOUND; } Location = AllocatePool (Chunk); Size = (Argc > 3) ? AsciiStrHexToUintn (Argv[3]) : EfiTell (File, NULL); Offset = 0; if (Argc > 2) { Offset = AsciiStrHexToUintn (Argv[2]); if (Offset > 0) { // Make sure size includes the part of the file we have skipped Size += Offset; } } Status = EfiSeek (File, Offset, EfiSeekStart); if (EFI_ERROR (Status)) { goto Exit; } for (; Offset + HEXDUMP_CHUNK <= Size; Offset += Chunk) { Chunk = HEXDUMP_CHUNK; Status = EfiRead (File, Location, &Chunk); if (EFI_ERROR(Status)) { AsciiPrint ("Error reading file content\n"); goto Exit; } Status = OutputData (Location, Chunk, Width, File->BaseOffset + Offset); if (EFI_ERROR(Status)) { if (Status == EFI_END_OF_FILE) { Status = EFI_SUCCESS; } goto Exit; } } // Any left over? if (Offset < Size) { Chunk = Size - Offset; Status = EfiRead (File, Location, &Chunk); if (EFI_ERROR(Status)) { AsciiPrint ("Error reading file content\n"); goto Exit; } Status = OutputData (Location, Chunk, Width, File->BaseOffset + Offset); if (EFI_ERROR(Status)) { if (Status == EFI_END_OF_FILE) { Status = EFI_SUCCESS; } goto Exit; } } Exit: EfiClose (File); FreePool (Location); return EFI_SUCCESS; }