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

📄 nvbuild.c

📁 详细介绍了一篇关于pci开发的接口芯片
💻 C
📖 第 1 页 / 共 5 页
字号:
			0, H_LOAD_PCI);
		wmenuitem(3, 8, "File",       'F', FILE_SELECT,       0, NULL,
			0, H_LOAD_FILE);
		wmenuitem(5, 8, "Exit Menu",  'x', LD_EXIT_SELECT,    0, NULL,
			0, H_EXIT_MENU);
		wmenuend(subscr, M_VERT, 0, 6, menu_border_color, menu_qsel_color,
			0, menu_selection_color);
		if ((subscr = wmenuget()) == -1 && _winfo.errno > W_ESCPRESS)
			error_exit(1);
		wclose();
		whelpopc();
	} else
		subscr = FILE_SELECT;

	switch (subscr) {
	case FILE_SELECT:
		whelpcat(H_SELECT_FILE);
		fname = wpickfile_criteria(7, 10, 22, 70, 1, menu_border_color,
			menu_window_color, menu_selection_color, 1, "*.*",
				add_shadow, select_nvram_file);

		if (fname == NULL)
			break;

		strcpy(savename, fname);
		tmp_nvram = cur_nvram;
		ftype = load_hex_file(fname, nvram_buf, nvram_bsize, &loaded, TRUE);

		if (ftype != ERROR_TYPE) {
			memcpy(&cur_nvram, nvram_buf + CONF_SPACE_OFFSET, CONF_SPACE_SIZE);
			nvram_loaded = loaded;
		{
			char buf[80];
			if (ftype == INTEL_HEX_TYPE)
			{
				sprintf(buf, "%d bytes of Intel Hex File Loaded", nvram_loaded);
				wdisp_message(buf);
			} else if (ftype == BINARY_TYPE) {
				sprintf(buf, "%d bytes of Binary File Loaded", nvram_loaded);
				wdisp_message(buf);
			}
		}
		} else {
			nvram_loaded = CONF_SPACE_END;
			cur_nvram = tmp_nvram;
		}

		whelpopc();
		break;

	case PCI_DEVICE_SELECT:
	if (select_pci_device() == OK) {
		nvram_loaded = CONF_SPACE_END;
		if (load_nvram_from_device(1) == OK)
		{
			char buf[80];

			sprintf(buf, "%d bytes of nvRAM data loaded", nvram_loaded);
			wdisp_message(buf);
		} else {
			wdisp_message("nvRAM load failed");
			cur_nvram = default_nvram;
		}
	}
	break;

	default: /* If ESC was pressed, revert back to previous */
		subscr = prev_subscr;
		break;
	}
	wunhide(nvbuild_menu_window);
}

/*
** Display a menu to edit which portion of the NVRAM image.
*/
STATIC void
edit(void)
{
	int row;

	row = 1;
	wactiv(nvbuild_menu_window);
	whide();

	/* define and process the edit menu */
	wmenubeg(9, 20, 19, 60, 0, menu_border_color, menu_window_color,
		pre_edit_menu);

	wmenuitem(row, 3, "Edit Base Addresses",                'B', 1, 0,
		edit_base,   0, H_EDIT_BASE);
	row += 2;

	wmenuitem(row, 3, "Edit Other Configuration Registers", 'O', 2, 0,
		edit_other,  0, H_EDIT_MISC);
	row += 2;

	wmenuitem(row, 3, "Edit Location 45 Configuration Bits",'L', 2, 0,
		edit_loc_45_config_bits,0, H_EDIT_LOC_45);
	row += 2;

	wmenuitem(row, 3, "Exit Menu"     ,                     'x', 3, 0,
		NULL,        0, H_EXIT_MENU);
	row += 2;

	wmenuend(1, M_VERT, 0, 6, menu_border_color, menu_qsel_color,
					0, menu_selection_color);
 	if (wmenuget() == -1 && _winfo.errno > W_ESCPRESS)
		error_exit(1);
	wunhide(nvbuild_menu_window);
}

/*
** Called during the setup of the main menu.  It is called by
** wmenuget() right after the main menu's window is opened.
*/
STATIC void
pre_edit_menu(void)
{
	hidecur();
	add_shadow();
	wtitle("[ Edit Menu ]", TCENTER, menu_border_color);
	edit_menu_window = whandle();
}

/*
** Display a menu to choose which base address to edit.
*/
STATIC void
edit_base(void)
{
	wactiv(edit_menu_window);
	whide();

	/* define and process the edit menu */
	if (!wopen(8, 2, 22, 77, 0, menu_border_color, menu_window_color))
		error_exit(1);
	hidecur();
	add_shadow();
	wtitle("[ Base Address Menu ]", TCENTER, menu_border_color);
	edit_base_menu_window = whandle();

	wmenubegc();
	wmenuitem( 2, 3, "Base Address 0", '0', 1, 0, edit_base_addr,
		0, H_SELECT_BASE);
	wmenuitem( 4, 3, "Base Address 1", '1', 2, 0, edit_base_addr,
		0, H_SELECT_BASE);
	wmenuitem( 6, 3, "Base Address 2", '2', 3, 0, edit_base_addr,
		0, H_SELECT_BASE);
	wmenuitem( 8, 3, "Base Address 3", '3', 4, 0, edit_base_addr,
		0, H_SELECT_BASE);
	wmenuitem(10, 3, "Base Address 4", '4', 5, 0, edit_base_addr,
		0, H_SELECT_BASE);
	wmenuitem(12, 3, "Exit Menu",      'x', 6, 0, NULL, 0, H_EXIT_MENU);
	update_base_addr();
	wmenuend(1, M_VERT, 0, 6, menu_border_color, menu_qsel_color,
		0, menu_selection_color);
 	if (wmenuget() == -1 && _winfo.errno > W_ESCPRESS)
		error_exit(1);
	wclose();
	wunhide(edit_menu_window);
}

enum base_type {MEMORY_SELECT, IO_SELECT, DISABLE_SELECT};

STATIC int base_reg;
STATIC dword cur_addr;
STATIC byte passthru_width_index;

#define NUMBER_PASS_THROUGHS  4

STATIC char passthru_width[10];
STATIC char *passthru[] = {
	"32-bits",
	"16-bits",
	"8-bits ",
	"Disable",
	NULL
};

char passthru_values[] = { 0x3, 0x2, 0x1, 0x0 };
byte memory_loc_index;
char memory_loc[2];

#define NUMBER_MEMORY_LOCS 2

char *memory_locs[] = {
	"Locate Anywhere in Memory",
	"Locate Below 1MB",
	NULL
};

#define NUMBER_MEM_BASE_ADDR 27

char *membase_addr[NUMBER_MEM_BASE_ADDR+1] = {
	"16 bytes  ",
	"32 bytes  ",
	"64 bytes  ",
	"128 bytes ",
	"256 bytes ",
	"512 bytes ",
	"1 Kbytes  ",
	"2 Kbytes  ",
	"4 Kbytes  ",
	"8 Kbytes  ",
	"16 Kbytes ",
	"32 Kbytes ",
	"64 Kbytes ",
	"128 Kbytes",
	"256 Kbytes",
	"512 Kbytes",
	"1 Mbytes  ",
	"2 Mbytes  ",
	"4 Mbytes  ",
	"8 Mbytes  ",
	"16 Mbytes ",
	"32 Mbytes ",
	"64 Mbytes ",
	"128 Mbytes",
	"256 Mbytes",
	"512 Mbytes",
	"1 Gbytes  ",
	NULL
};

dword membase_val[] = {
	0x3FFFFFF0L,
	0x3FFFFFE0L,
	0x3FFFFFC0L,
	0x3FFFFF80L,
	0x3FFFFF00L,
	0x3FFFFE00L,
	0x3FFFFC00L,
	0x3FFFF800L,
	0x3FFFF000L,
	0x3FFFE000L,
	0x3FFFC000L,
	0x3FFF8000L,
	0x3FFF0000L,
	0x3FFE0000L,
	0x3FFC0000L,
	0x3FF80000L,
	0x3FF00000L,
	0x3FE00000L,
	0x3FC00000L,
	0x3F800000L,
	0x3F000000L,
	0x3E000000L,
	0x3C000000L,
	0x38000000L,
	0x30000000L,
	0x20000000L,
	0x00000000L
};

int membase_addr_subscr;

#define NUMBER_CLASS_CODES  14

char *class_code_messages[] = {
	"Early, pre-2.0 PCI Specification Device",
	"Mass Storage Controller",
	"Network Controller",
	"Display Controller",
	"Multimedia Device",
	"Memory Controller",
	"Bridge Device",
	"Simple Communication Controller",
	"Base System Peripheral",
	"Input Device",
	"Docking Station",
	"Processor",
	"Serial Bus Controller",
	"Device does not fit defined class codes",
	NULL
};

byte class_codes[] = {
	0x00, 0x01, 0x02, 0x03, 0x04,
	0x05, 0x06, 0x07, 0x08, 0x09,
	0x0a, 0x0b, 0x0c, 0xff
};

/* Max number suclass codes in a single class */
#define NUMBER_SUBCLASS_CODES 9

char *subclass_code_messages[NUMBER_CLASS_CODES][NUMBER_SUBCLASS_CODES + 1] = {
  // "Early, pre-2.0 PCI Specification Device"
  {
    "All Devices other than VGA    ",
    "VGA-compatible Device         ",
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL
  },

  // "Mass Storage Controller"
  {
    "SCSI Controller              ",
    "IDE Controller               ",
    "Floppy Disk Controller       ",
    "IPI Controller               ",
    "RAID Controller              ",
    "Other Mass Storage Controller",
    NULL,
    NULL,
    NULL,
    NULL
  },

  // "Network Controller"
  {
    "Ethernet Controller          ",
    "Token Ring Controller        ",
    "FDDI Controller              ",
    "ATM Controller               ",
    "Other Network Controller     ",
    NULL,
    NULL,
    NULL,
    NULL,
    NULL
  },

  // "Display Controller"
  {
    "VGA/8514 Compatible Controller",
    "XGA Controller                ",
    "Other Display Controller      ",
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL
  },

  // "Multimedia Device"
  {
    "Video Device                 ",
    "Audio Device                 ",
    "Other Multimedia Device      ",
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL
  },

  // "Memory Controller"
  {
    "RAM Memory Controller        ",
    "Flash Memory Controller      ",
    "Other Memory Controller      ",
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL
  },

  // "Bridge Device"
  {
    "HOST/PCI Bridge              ",
    "PCI/ISA Bridge               ",
    "PCI/EISA Bridge              ",
    "PCI/Micro Channel Bridge     ",
    "PCI/PCI Bridge               ",
    "PCI/PCMCIA Bridge            ",
    "NuBus Bridge                 ",
    "CardBus Bridge               ",
    "Other Bridge Type            ",
    NULL
  },

  // "Simple Communication Controller"
  {
    "Serial Controller             ",
    "Parallel Controller           ",
    "Other Communications Device   ",
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL
  },

  // "Base System Peripheral"
  {
    "Programmable Interrupt Controller",
    "DMA Controller                   ",
    "System Timer                     ",
    "Real-time Clock Controller       ",
    "Other System Controller          ",
    NULL,
    NULL,
    NULL,
    NULL
  },
  // "Input Device"
  {
    "Keyboard Controller           ",
    "Digitizer (Pen)               ",
    "Mouse Controller              ",
    "Other Input Controller        ",
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL
  },
  // "Docking Station"
  {
    "Generic Docking Station       ",
    "Other Type of Docking Station ",
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL
  },
  // "Processor"
  {
    "386                           ",
    "486                           ",
    "Pentium (TM)                  ",
    "Alpha (TM)                    ",
    "Co-processor                  ",
    NULL,
    NULL,
    NULL,
    NULL,
    NULL
  },
  // "Serial Bus Controller"
  {
    "Firewire (IEEE 1394)          ",
    "ACCESS.bus                    ",
    "SSA                           ",
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL
  },

  // "Device does not fit defined class codes"
  {
    "Not Applicable                ",
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL
  }
};

STATIC void
pre_class_code(void)
{
	field_edit_menu = TRUE;
	field_edit_menu_process = pick_class_code;
	disp_menu_pick();
}

STATIC void
post_class_code(void)
{
	field_edit_menu = FALSE;
	field_edit_menu_process = NULL;
	del_menu_pick();
}

STATIC void
pre_cc_menu(void)
{
	add_shadow();
	wtitle("[ Choose Base Class Code ]", TCENTER, submenu_border_color);
	hidecur();
}

/*
** Let the user pick a valid class code.
*/
STATIC void
pick_class_code(void)
{
	char *tmp_class_codes[NUMBER_CLASS_CODES], str[20];
	int subscr, row, col, i;

	del_menu_pick();
	whelpush();

	determine_row_col(&row, &col, TRUE);
	row += 2;
	wmenubeg(row, 29, row + NUMBER_CLASS_CODES + 1, 76, 0,
		submenu_border_color, submenu_window_color, pre_cc_menu);
	for (i = 0; i < NUMBER_CLASS_CODES; i++) {
		tmp_class_codes[i] = malloc(strlen(class_code_messages[i]) + 7);
		if (tmp_class_codes[i] == NULL)
			error_exit(1);
		sprintf(tmp_class_codes[i], "%2.2Xh - %s", class_codes[i],
			class_code_messages[i]);
		wmenuitem(i, 1, tmp_class_codes[i], i, i, 0, NULL, 0, 0);
	}
	wmenuend(0, M_VERT, 0, 1, submenu_border_color, submenu_qsel_color,
		0, submenu_selection_color);

	if ((subscr = wmenuget()) == -1 && _winfo.errno > W_ESCPRESS)
		error_exit(1);

	for (i = 0; i < NUMBER_CLASS_CODES; i++) {
		if (tmp_class_codes[i])
			free(tmp_class_codes[i]);
		tmp_class_codes[i] = NULL;
	}

	kbput(0x4700);  /* [Home] */
	if (subscr == -1)
		subscr = class_code_subscr;
	sprintf(str, "%2.2X", class_codes[subscr]);
	kbputs(str);
	whelpop();
}

byte subclass_codes[NUMBER_CLASS_CODES][NUMBER_SUBCLASS_CODES] = {
  // "Early, pre-2.0 PCI Specification Device"
  {
    0x00,
    0x01,
    0x00,

⌨️ 快捷键说明

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