VirtualBox

source: vbox/trunk/src/VBox/Devices/PC/Etherboot-src/util/swapdevids.pl@ 46355

Last change on this file since 46355 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.3 KB
Line 
1#!/usr/bin/perl -w
2#
3# Program to reverse the device identifier IDs in the PCIR and PnP
4# structures in a ROM for old non-compliant BIOSes
5#
6# GPL, Ken Yap 2001
7#
8
9use bytes;
10
11use IO::Seekable;
12
13sub swaplocs ($$$)
14{
15 my ($dataref, $loc1, $loc2) = @_;
16 my ($t);
17
18 $t = substr($$dataref, $loc1, 1);
19 substr($$dataref, $loc1, 1) = substr($$dataref, $loc2, 1);
20 substr($$dataref, $loc2, 1) = $t;
21}
22
23sub printdevids ($$)
24{
25 my ($dataref, $loc) = @_;
26
27 return (sprintf "%02x %02x %02x", unpack('C3', substr($$dataref, $loc, 3)));
28}
29
30$#ARGV >= 0 or die "Usage: $0 romimage\n";
31$file = $ARGV[0];
32open(F, "+<$file") or die "$file: $!\n";
33binmode(F);
34# Handle up to 64kB ROM images
35$len = read(F, $data, 64*1024);
36defined($len) or die "$file: $!\n";
37substr($data, 0, 2) eq "\x55\xAA" or die "$file: Not a boot ROM image\n";
38($pci, $pnp) = unpack('v2', substr($data, 0x18, 4));
39($pci < $len and $pnp < $len) or die "$file: Not a PCI PnP ROM image\n";
40(substr($data, $pci, 4) eq 'PCIR' and substr($data, $pnp, 4) eq '$PnP')
41 or die "$file: No PCI and PNP structures, not a PCI PNP ROM image\n";
42&swaplocs(\$data, $pci+13, $pci+15);
43&swaplocs(\$data, $pnp+18, $pnp+20);
44seek(F, 0, SEEK_SET) or die "$file: Cannot seek to beginning\n";
45print F $data;
46close(F);
47print "PCI devids now: ", &printdevids(\$data, $pci+13), "\n";
48print "PnP devids now: ", &printdevids(\$data, $pnp+18), "\n";
49exit(0);
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette