📄 rinit.c
字号:
//*************************Compiling Information*************************************
// Here is an example of batch file to build the utility with Microsoft C and MASM
// compilers. The project includes 2 files : RINIT.C and ASM.ASM. The files are also
// compilable by BCC and TASM.
// The code is a proprietary of ATI Technologies. Redistribution is prohibited.
/*
ECHO OFF
set C_PATH=c:\msvc15
set ASM_PATH=c:\masm611
set LINKER_PATH=c:\msvc15
set MAP_FILE=rinit.map
set EXE_FILE=rinit.exe
set OLDPATH=%Path%
set Path=%Path%;%C_PATH%\bin;%LINKER_PATH%\bin;%ASM_PATH%\bin;
del %MAP_FILE%
del %EXE_FILE%
del rinit.obj
del asm.obj
%C_PATH%\bin\cl /c /AL /I%C_PATH%\include rinit.c
%ASM_PATH%\bin\ml /c asm.asm
%LINKER_PATH%\bin\link /MAP rinit asm ,%EXE_FILE%,%MAP_FILE%,%LINKER_PATH%\lib\,,
set Path=%OLDPATH%
set OLDPATH=
set C_PATH=
set LINKER_PATH=
set MAP_FILE=
set EXE_FILE=
*///************************************************************************************
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <io.h>
#include <fcntl.h>
#include <malloc.h>
/**********************************************************************************************/
/*Commands structure: describes a command line command */
struct cmd_struc
{
const char index;
const char * cmd_str;
const char * cmd_expl;
};
/* This structure describes PCI device*/
struct cdevice
{
unsigned short busdevfnc; // bus, device, function
unsigned long memory_base; //memory base, offset 0x10
unsigned short io_base; //io base, offset 0x14
unsigned short revision; //revision, offset 0x8
unsigned short ID; //device ID, offset 0x2
unsigned short config; //config word, offset 0x4
};
/*This structure containes pointers to initialization tables and pointers to some
routines to parse the binary in order to find the tables*/
struct tables_info
{
unsigned char** pointer; // pointer of the table pointer
unsigned short offset; // ofset of the table in the binary
void (*validate) (struct tables_info*); // pointer to function to validate table pointer we have got
char* description;
unsigned char* (*look_for) (unsigned char**); // pointer to function to look for table relaying on another(parent) table
unsigned char** parent_table;
};
/*Binary parsing functions*/
void general_validate(struct tables_info*); //checks if pointer is valid
unsigned char* look_for_add_init_table (unsigned char**); // looks for ASIC init tables 3 and 4
unsigned char* look_for_mem_res_table(unsigned char**); // looks for memory reset table
unsigned char* look_for_short_mem_res_table(unsigned char**);// looks for short memory reset table
/*External IO, PCI and Memory access functions*/
extern void io_outbyte(unsigned short port, unsigned char data);
extern void io_outword(unsigned short port, unsigned short data);
extern void io_outdword(unsigned short port, unsigned long data);
extern unsigned char io_inbyte(unsigned short port);
extern unsigned long io_indword(unsigned short port);
extern unsigned short pci_inword(unsigned short busdevfnc,unsigned short offs);
extern void pci_outword(unsigned short busdevfnc,unsigned short offs,unsigned short data);
extern void pci_outdword(unsigned short busdevfnc,unsigned short offs,unsigned long data);
extern unsigned long pci_indword(unsigned short busdevfnc,unsigned short offs);
extern unsigned long readxmsdword(unsigned long addr);
extern void readxmsbuffer(char* buffer,unsigned long bar, unsigned short binary_size);
extern int check_for_v86(void);
extern void _scprintf(char* , unsigned short,unsigned short);
/**********************************************************************************************/
unsigned char * buffer; // BIOS binary buffer
struct cdevice device[8]; // list of PCI/AGP devices
struct cdevice* defaultdev; // device we chose to initialite or get info
/**********************************************************************************************/
/*In new modifications of BIOS only one table is used (ASIC init table 1)*/
unsigned char* rage_regs_1_table; // ASIC init table 1
unsigned char* rage_regs_2_table; // ASIC init table 2
unsigned char* rage_regs_3_table; // ASIC init table 3
unsigned char* rage_regs_4_table; // ASIC init table 4
unsigned char* dyn_clock_table; // Dynamic clock enable table
unsigned char* pll_init_table; // PLL init table
unsigned char* mem_conf_table; // Memory config table
unsigned char* mem_reset_table; // memory reset table
unsigned char* short_mem_reset_table;
unsigned char* rom_hdr_rev_pointer; //pointer to ATI ROM header
/**********************************************************************************************/
/*Definitions for displaying of test pattern*/
#define MAX_X_RESOLUTION 640
#define MAX_Y_RESOLUTION 480
#define TEXT_COLOR1 0x07ff
#define BORDER_COLOR 0xffff
#define BLUE_COLOR 0x001f
#define GREEN_COLOR 0x07E0
#define RED_COLOR 0xf800
#define TEXT_COLOR2 0xffe0
/*Init tables offsets*/
#define INIT_TABLES_NUMBER 9
#define RAGE_REGS1_TABLE_OFFS 0x0c
#define RAGE_REGS2_TABLE_OFFS 0x4e
#define DYN_CLOCK_TABLE_OFFS 0x52
#define PLL_INIT_TABLE_OFFS 0x46
#define MEM_CONFIG_TABLE_OFFS 0x48
/*Masks definitions*/
#define pllWR_EN 0x00000080
#define pllWR_DIS 0xffffff7f
#define pllINDEX_MASK 0xffffff60
#define pllMASK_BYTE 0xffffff00
#define pllWAIT_MC_BUSY_MASK 0x00010000 // byte 16 = 1
#define pllWAIT_DLL_READY_MASK 0x00080000 // byte 19 = 0
#define MEM_PWRUP_COMPLETE_A 0x01
#define MEM_PWRUP_COMPLETE_B 0x02
#define mask_SDRAM_MODE 0xffff0000
#define mask_b3MEM_RESET 0x6fffffff
#define SET_ALL_SOURCES_TO_PCI 0x00001111
#define CLK_PWRMGT_CNTL24 0x01000000
#define VIPH_ENABLE ((unsigned long) 1 << 21)
#define LINEAR_APERTURE 0x80000000;
/*Registers definitions*/
#define pllCLK_PWRMGT_CNTL 0x0014
#define pllMCLK_CNTL 0x0012
#define MC_STATUS 0x0150
#define MEM_SDRAM_MODE_REG 0x0158
#define CLOCK_CNTL_INDEX 0x0008
#define CLOCK_CNTL_DATA 0x000C
#define ioMM_INDEX 0x0000
#define ioMM_DATA 0x0004
#define PALETTE_INDEX 0x00B0
#define PALETTE_DATA 0x00B4
#define VIPH_CONTROL 0x0C40
#define SEPROM_CONTROL1 0x01C0
/*Tables commands definitions*/
#define PLL_WAIT 0x80
#define PLL_PROGRAM_DWORD 0x00
#define PLL_MASK_BYTE 0x40
#define PLL_FLAG_BITS 0xc0
#define PLL_INDEX_BITS 0x3f
#define PLL_DELAY_150MKS 1
#define PLL_DELAY_5MS 2
#define WAIT_MC_BUSY_MASK 3
#define WAIT_DLL_READY_MASK 4
#define CHECK_SET_CLK_PWRMGT_CNTL24 5
/*ASIC init table records sizes*/
#define INIT_TABLE_COMMAND_SIZE 2
#define INIT_TABLE_DATA_SIZE 4
#define INIT_TABLE_DELAY_SIZE 2
#define INIT_TABLE_SCOMMAND_SIZE 2
/*Command line commands*/
#define cmdBIOS 0x0001
#define cmdINFO 0x0008
#define cmdINIT 0x0010
#define cmdFILE 0x0040
#define CMD_NUMBER 4
/*System timer registers*/
#define TIMER_CHANNEL_MODE 0x43
#define TIMER_CHANNEL_COUNTER 0x40
#define BLOCK_SIZE 512
#define ATI_VENDOR_ID 0x1002
#define OFF_ROM_HEAD 0x48 //ATI ROM header offset
/*PCI configuration space offsets*/
#define PCI_VENDOR_ID 0x00
#define PCI_DEVICE_ID 0x02
#define PCI_REVISION 0x08
#define PCI_MEM_BASE 0x10
#define PCI_IO_BASE 0x14
#define PCI_IO_REVISION 0x08
#define PCI_CONFIG 0x04
#define PCI_BAR 0x30
#define MEM_IO_ENABLE 0x07 /*01-IO enable | 02-MEM enable | 04 - BUS master*/
// We need bus mestering to read binary from expansion ROM if needed
#define TRUE 1
#define FALSE 0
/*Constants to validate table pointer*/
#define MAX_REVISION 0x10
#define MIN_TABLE_POINTER_ALLOWED 0x60
#define SINGLE_TABLE_REVISION 0x09
/**********************************************************************************************/
char* status_str[2] = {"primary ","secondary"}; // string to show if device is primary
/* Device IDs of supported adapters*/
static unsigned short ati_device_ids [] =
{
// RV100
0x5159, 0x515A, 0x4C59, 0x4C5A,
// R200
0x5148, 0x5149, 0x514A, 0x514B, 0x514C, 0x514D, 0x514E, 0x514F,
// R200 AiW board with Bridget
0x4242, 0x4243,
// RV200
0x5157, 0x5158, 0x5159, 0x515A,
// RV250
0x4964,0x4965,0x4966,0x4967,0x4968,
0x4969,0x496A,0x496B,0x496C,0x496D,0x496E,0x496F,
// R300
0x4164,0x4165,0x4166,0x4167,0x4168,
0x4169,0x416A,0x416B,0x416C,0x416D,0x416E,0x416F,
0
};
/*Tables parsing information
table's pointer, table's offset, validation func, description to generate messages,
func to look for table if we don't have table offset, and pointer we should start at*/
struct tables_info tables[INIT_TABLES_NUMBER] =
{
{&rage_regs_1_table,RAGE_REGS1_TABLE_OFFS,general_validate,"1st init block",NULL,NULL},
{&rage_regs_2_table,RAGE_REGS2_TABLE_OFFS,general_validate,"2nd init block",NULL,NULL},
{&dyn_clock_table,DYN_CLOCK_TABLE_OFFS,general_validate,"dynamic clock init block",NULL,NULL},
{&pll_init_table,PLL_INIT_TABLE_OFFS,general_validate,"pll init block",NULL,NULL},
{&mem_conf_table,MEM_CONFIG_TABLE_OFFS, general_validate,"memory config block",NULL,NULL},
{&mem_reset_table,0,NULL,"memory reset table",look_for_mem_res_table,&mem_conf_table},
{&short_mem_reset_table,0,NULL,"short memory reset table",look_for_short_mem_res_table,&mem_conf_table},
{&rage_regs_3_table,0,NULL,"3rd init block",look_for_add_init_table,&rage_regs_2_table},
{&rage_regs_4_table,0,NULL,"4th init block",look_for_add_init_table,&rage_regs_3_table}
};
/**********************************************************************************************/
/*Font EGA 8x16*/
char font_ega8x16[] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x7c,0x82,0x82,0xaa,0x82,0x82,0xc6,0xba,0x82,0x7c,0x00,0x00,0x00,0x00,
0x00,0x00,0x7c,0xfe,0xfe,0xd6,0xfe,0xfe,0xba,0xc6,0xfe,0x7c,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x6c,0xee,0xfe,0xfe,0xfe,0xfe,0x7c,0x38,0x10,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x10,0x38,0x7c,0xfe,0x7c,0x38,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x10,0x38,0x38,0x10,0x6c,0xee,0x6c,0x10,0x38,0x00,0x00,0x00,0x00,
0x00,0x00,0x10,0x38,0x7c,0x7c,0xfe,0xfe,0xfe,0x6c,0x10,0x38,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x18,0x3c,0x3c,0x3c,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xe7,0xc3,0xc3,0xc3,0xe7,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0x00,0x00,0x18,0x3c,0x66,0x66,0x66,0x3c,0x18,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xe7,0xc3,0x99,0x99,0x99,0xc3,0xe7,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0x1e,0x0e,0x1e,0x36,0x78,0xcc,0xcc,0xcc,0xcc,0x78,0x00,0x00,0x00,0x00,
0x00,0x00,0x3c,0x66,0x66,0x66,0x3c,0x18,0x7e,0x18,0x18,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0x1e,0x1a,0x1e,0x18,0x18,0x18,0x18,0x78,0xf8,0x70,0x00,0x00,0x00,0x00,
0x00,0x00,0x3e,0x36,0x3e,0x36,0x36,0x76,0xf6,0x66,0x0e,0x1e,0x0c,0x00,0x00,0x00,
0x00,0x00,0x18,0xdb,0x7e,0x3c,0x66,0x66,0x3c,0x7e,0xdb,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x80,0xe0,0xf0,0xfc,0xfe,0xfc,0xf0,0xe0,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x02,0x0e,0x3e,0x7e,0xfe,0x7e,0x3e,0x0e,0x02,0x00,0x00,0x00,0x00,
0x00,0x00,0x18,0x3c,0x7e,0x18,0x18,0x18,0x18,0x7e,0x3c,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x00,0x66,0x66,0x00,0x00,0x00,0x00,
0x00,0x00,0x7f,0xdb,0xdb,0xdb,0xdb,0x7b,0x1b,0x1b,0x1b,0x1b,0x00,0x00,0x00,0x00,
0x00,0x00,0x7c,0xc6,0xc6,0x60,0x7c,0xf6,0xde,0x7c,0x0c,0xc6,0xc6,0x7c,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfe,0xfe,0xfe,0xfe,0x00,0x00,0x00,0x00,
0x00,0x00,0x18,0x3c,0x7e,0x18,0x18,0x18,0x7e,0x3c,0x18,0x7e,0x00,0x00,0x00,0x00,
0x00,0x00,0x18,0x3c,0x7e,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x7e,0x3c,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x0c,0x0e,0xff,0x0e,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x30,0x70,0xfe,0x70,0x30,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xc0,0xc0,0xc0,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x24,0x66,0xff,0x66,0x24,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x10,0x38,0x38,0x38,0x7c,0x7c,0xfe,0xfe,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xfe,0xfe,0x7c,0x7c,0x7c,0x38,0x38,0x10,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x18,0x3c,0x3c,0x3c,0x3c,0x18,0x18,0x00,0x18,0x18,0x00,0x00,0x00,0x00,
0x00,0x36,0x36,0x36,0x36,0x14,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x6c,0x6c,0x6c,0xfe,0x6c,0x6c,0xfe,0x6c,0x6c,0x6c,0x00,0x00,0x00,0x00,
0x00,0x00,0x18,0x18,0x7c,0xc6,0xc0,0x78,0x3c,0x06,0xc6,0x7c,0x18,0x18,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x62,0x66,0x0c,0x18,0x30,0x66,0xc6,0x00,0x00,0x00,0x00,
0x00,0x00,0x38,0x6c,0x38,0x30,0x76,0x7e,0xcc,0xcc,0xcc,0x76,0x00,0x00,0x00,0x00,
0x00,0x0c,0x0c,0x0c,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x0c,0x18,0x30,0x30,0x30,0x30,0x30,0x30,0x18,0x0c,0x00,0x00,0x00,0x00,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -