NVIDIA BIOS Modification Program

Script Syntax and Command Line Parameters

Script Syntax

A BIOS Modification Script consists of definitions. Definition specify things such as where to find certain structures, what data to place into a BIOS image, where to place checksums, and what values to prompt the BIOSMOD operator for.

BIOSMOD interprets the script in a single pass, so symbols need to be defined in definitions before they are referenced in other definitions.

Comments preceded by a double slash (//) and extending to the end of the line are allowed. Also, white space including spaces, tabs, and new-lines can be included between tokens.

All identifiers and reserved words are NOT case sensitive.

Definitions

Struct/EndStruct

The Struct keyword is used to define a structure. There are two forms of the Struct construct. The first form specifies its starting address (as an offset into the BIOS segment) and its contents. The bytes at the specified starting address are replaced with the data specified in the structure. This structure has the following syntax:

	Struct <id> at <expression>
	    <line>
	    <line>
	    ...
	EndStruct

<id> is the name of the structure. <expression> is the address of the structure. Besides specifying where the bytes of the structure will be stored, the value of the expression is bound to the structure identifier so that it can be used in expressions in the remainder of the script.

Alternatively, the expression can be specified as "?", and the script can be resolved with a map file. The map file must contain a symbol with the same name as the structure identifier. The value of the symbol in the map file will be used as the structure address.

A script with unresolved structure addresses (specified as question marks) can either be used with a map file to modify a BIOS image, or it can be used with a map file to create a new script file that has all resolved addresses. The new script file can then be used to modify a BIOS image without a map file.

The second form of the Struct construct is used to search for a sequence of bytes. The name of the structure can then be used in expressions for specifying the locations of other structures. This allows searching for structures with a certain pattern without the need for a map file. The syntax to search for a structure is shown below:

	Struct <Structure Identifier> find
	    <line>
	    <line>
	    ...
	EndStruct

The format of <line> in either type of structure definition is one of the following:

An expression list can be one of the following forms:

<expression>
<expression> , <expression-list>

An expression in a byte, word, or dword struct line can be a "?" to signify that a byte, word, or dword respectively should be skipped and left unchanged in the BIOS image. Alternately, the skip line can be used to skip a number of bytes. The number of bytes skipped is specified in the expression present in the skip statement.

In the case of a byte line, an expression can be a string expression surrounded by tick marks ('). Standard C escape sequences can also be used inside the string. Each character of the string will be stored as a byte.

The string expression given to the date statement should be in the format used in the WIN32 API GetDateFormat.

The byterange, wordrange, and dwordrange statements are used to specify a range of valid values for use with a find structure. For a match to occur, the value at that position in the BIOS image must be equal to or greater than the first expression, and equal to or less than the second expression.

Checksum

The checksum definition can be used to generate a single byte checksum of a range of bytes and store the checksum at a specified location. The syntax is:

checksum <start>, <end>, <checksum>
 
<start> - Expression that specifies the address to start the checksum calculation at
<end> - Expression that specifies the address to end the checksum calculation at
<checksum> - Expression that specifies the address to store the checksum byte at

Include

The include definition can be used to include another script within this script. The script acts as if the lines of the included script file where inserted at the point of the include definition. When a script file is resolved with a map file to produce a new script file, the new script file will have the include statements replaced with the lines of the included file. The syntax for the include definition is:

Include <filename>
 
<filename> - String expression specifying the filename of the script to include.

StringPrompt

The StringPrompt statement is used to prompt the BIOSMOD operator for a string of characters. The dialog box that is presented actually brings up a hex editor, so the string can be entered as either text characters or hex numbers. The format for the StringPrompt statement is:

stringprompt <id>, <label>, <address>, <size>
 
<id> - ID of this prompt. Currently unused.
<label> - String expression specifying the label to display on the dialog box next to this prompt.
<address> - Expression specifying the start address of the area of memory to edit.
<size> - Expression specifying the number of bytes to expose to the user in the prompt.

ValuePrompt

The ValuePrompt statement is used to prompt the BIOSMOD operator for a value. The value can be any number of bits in length and the bits that make up the value can be scattered among different bytes in the BIOS image. The user can enter the value in decimal or hex by preceding the value with a "0x". If the value consists of a single bit, a check box is displayed instead of an edit box. The format for the ValuePrompt statement is:

valueprompt <id>, <label>, <base>, <address>:<bit>:<bitsize> [, <address>:<bit>:<bitsize>]*
 
<id> - ID of this prompt. Currently unused.
<label> - String expression specifying the label to display on the dialog box next to this prompt.
<base> - Decimal integer specifying number base to use for displaying the current value in the edit box. Usually 10 or 16.
<address> - Expression specifying the address of this sequence of bits.
<bit> - Expression specifying the bit number for the least significant source bit of this sequence of bits.
<bitsize> - Expression specifying the number of bits to use at this location.

Note that more than one address, bit, bitsize sequence can be specified if the value comes from multiple bit fields. The value is assembled in order with the first sequence specifying the most significant bits and the last sequence specifying the least significant bits. For example, to prompt for an eight bit value that is stored in two separate 4-bit fields at the following locations:

the following statement would be used:

valueprompt example, 'Example Value: ', 16, a1:0:4, a2:2:4

EnumDef/EndEnumDef

The EnumDef definition defines the valid values for an EnumPrompt. Each possible value has a string and an integer associated with it. The format of an EnumDef definition is:

EnumDef <id>
<string>, <value>
[ <string>, <value> ]*
EndEnumDef
 
<id> - ID of this EnumDef. Used to uniquely identify this EnumDef in an EnumPrompt.
<string> - String expression specifying the string to include in the combo box.
<value> - Decimal or hex integer that will be stored when the corresponding string is selected in the combo box.

EnumPrompt

The EnumPrompt is similar to a ValuePrompt except that instead of presenting an edit box to the user, a combo box is presented instead. The combo box is populated with the strings listed in the specified EnumDef. The combo box will initially have the string selected that corresponds to the value currently present in the BIOS image. The value associated with the selected string will be stored into the BIOS image when the user presses "OK". The format for the EnumPrompt is:

enumprompt <id>, <label>, <enumdef-id>, <address>:<bit>:<bitsize> [, <address>:<bit>:<bitsize>]*
 
<id> - ID of this prompt. Currently unused.
<label> - String expression specifying the label to display on the dialog box next to this prompt.
<enumdef-id> - ID of the enumdef to reference to determine what to populate the combo box with.
<address> - Expression specifying the address of this sequence of bits.
<bit> - Expression specifying the bit number for the least significant source bit of this sequence of bits.
<bitsize> - Expression specifying the number of bits to use at this location.

Note that more than one address, bit, bitsize sequence can be specified if the value comes from multiple bit fields. The value is assembled in order with the first sequence specifying the most significant bits and the last sequence specifying the least significant bits. For example, to prompt for an eight bit value that is stored in two separate 4-bit fields at the following locations:

The following statement would be used:

enumprompt example, 'Example Value: ', exampleEnum, a1:0:4, a2:2:4

MapReg

The MapReg statement is used to specify to BIOSMOD where the value that will be written to a NVIDIA register is stored in the BIOS image. This information is used by BIOSMOD to check to see that rules listed in the NVIDIA hardware manuals are not violated by the BIOS image.

The bits that make up the value can be scattered among different bytes in the BIOS image. The format for the MapReg statement is:

mapreg <reg>, <set>, <address>:<bit>:<bitsize> [, <address>:<bit>:<bitsize>]*
 
<reg> - Name of the NVIDA register to map into the BIOS image.
<set> - Set to add this mapping to.
<address> - Expression specifying the address of this sequence of bits.
<bit> - Expression specifying the bit number for the least significant source bit of this sequence of bits.
<bitsize> - Expression specifying the number of bits to use at this location.

Each register mapping is stored in a set. When rules are checked, values within each set are used to see if all the conditions pass. This allows for cases where there is more than one value that can be written to a register. There is a special set called GLOBAL. Mappings in the GLOBAL set act as through they are included in all sets. For normal cases where there is only one value that will be written to a register, the set should be specified as GLOBAL.

Note that more than one address, bit, bitsize sequence can be specified if the value comes from multiple bit fields. The value is assembled in order with the first sequence specifying the most significant bits and the last sequence specifying the least significant bits. For example, to prompt for an eight bit value that is stored in two separate 4-bit fields at the following locations:

the following statement would be used:

mapreg NV_PFB_PIN, GLOBAL, a1:0:16, a2:2:16

MapField

The MapField statement is used to specify to BIOSMOD where the value that will be written to an individual NVIDIA register field is stored in the BIOS image. This information is used by BIOSMOD to check to see that rules listed in the NVIDIA hardware manuals are not violated by the BIOS image.

The bits that make up the value can be scattered among different bytes in the BIOS image. The format for the MapField statement is:

mapfield <field>, <set>, <address>:<bit>:<bitsize> [, <address>:<bit>:<bitsize>]*
 
<field> - Name of the NVIDA field to map into the BIOS image.
<set> - Set to add this mapping to.
<address> - Expression specifying the address of this sequence of bits.
<bit> - Expression specifying the bit number for the least significant source bit of this sequence of bits.
<bitsize> - Expression specifying the number of bits to use at this location.

Each field mapping is stored in a set. When rules are checked, values within each set are used to see if all the conditions pass. This allows for cases where there is more than one value that can be written to a field. There is a special set called GLOBAL. Mappings in the GLOBAL set act as through they are included in all sets. For normal cases where there is only one value that will be written to a field, the set should be specified as GLOBAL.

Note that more than one address, bit, bitsize sequence can be specified if the value comes from multiple bit fields. The value is assembled in order with the first sequence specifying the most significant bits and the last sequence specifying the least significant bits. For example, to prompt for an eight bit value that is stored in two separate 4-bit fields at the following locations:

the following statement would be used:

mapfield NV_PFB_PIN, GLOBAL, a1:0:4, a2:2:4

Expressions

An expression can include the following operands:

An expression can include the following operators:

Standard rules of precedence are used, but they can be overridden with parentheses. The indirection operator (@) evaluates the value at the address given by the expression following the "@" symbol.

Constants are decimal by default, but can be specified in hexadecimal if preceded with a "0x", octal if preceded with a leading 0, and binary if followed by a b.

String expressions are a sequence of characters surrounded by tick marks ('). Standard C escape sequences can also be used inside the string.

Example

An example script can be found here: example.html

Command Line Parameters

The BIOS Modification Program is started with the following command line:

biosmod [<options>] [<filename>]

<filename> Specified file is loaded.  Required for any of the other options to work.  If any of the other options are present, then the file is saved after the changes are made, and the program is terminated.

<options> can be any of the options listed in the following table:

/script:script.srp Specifies script file to use to modify the BIOS image
/mapfile:rombios.map Specifies map file to use to resolve structure addresses in the script file

Alternatively, the BIOS Modification Program can be run to take a script file and a map file and produce a new script file with no unresolved structure addresses. The new file can then be used to modify a BIOS image without a map file. The syntax to resolve a script with a map file and create a new script file is shown below:

biosmod /script:<script file> /mapfile:<map file> /outscript:<new script file>