Monday, April 29, 2013

How to disassemble raw x86 code

Source: http://stackoverflow.com/questions/1737095/how-do-i-disassemble-raw-x86-code


objdump -D -b binary -mi386 -Maddr16,data16 mbr


--target instead of -b-D is "disassemble the contents of all sections"; -b bfdname or --target=bfdname will force reading as specified object-code format (not elf but raw binary in our case); -m machine will specify the architecture to use (in our file there is no header with arch info). -M options are options of disassembler; addr16,data16 are used to "specify the default address size and operand size" (treat code as i8086 one in the universal x86 disasm engine) 

Tuesday, April 23, 2013

List of Intel NICs

List of Intel Network Controller

http://www.intel.com/content/www/us/en/ethernet-controllers/ethernet-controllers.html

Intel® 82574 Gigabit Ethernet Controller

Intel® 82541 Gigabit Ethernet Controller

Intel® 82540 Gigabit Ethernet Controller

Thursday, April 18, 2013

Super IO configuration

Similar to PCI controller, the super IO controller also has its own configuration space. The size of the Super IO configuration space is same as PCI configuration space, which is 0xFF (256) bytes.

Regards to how to access this configuration space, please read my previous article:
http://fengweizhang.blogspot.com/2013/04/how-to-access-super-io-registers.html

The seventh byte of the configuration specifies the logical device. I am still looking for the configuration space MAP.

Friday, April 5, 2013

How does BIOS work


From: http://www.biosren.com/thread-3075-1-1.html
这个过程.....虽然我大体知道但是也说不清楚。还是帮你看了哈总结出来的贴给你看哈:
1.        当机器被打开时,等电源稳定之后,电源会发送一个“加电成功信号”给芯片,以启动时钟生成器(8284);
2.        然后,CPU重新自设定为初试状态,开始准备运行。当CPU最初被启动的时候,系统RAM中是空的,没有任何内容可供执行。当然CPU设计者也知道这一点,所以他们对CPU进行了预先编程,以让CPU在这个阶段总是去查找系统BIOSROM中的一个固定的位置,以启动BIOS BootProgram,这个位置为FFFF0h,这个位置是UMA临近结尾的位置。之所以选择这个位置是因为,这样就不会引起由于ROM的大小改变而造成的兼容性问题。既然FFFF0h到UMA结束的位置之后16个字节,所以这里只放置着一个Jump指令,以进一步跳转到真正的BIOSstartup program的位置。(不同的BIOS厂商可以将其放在不同的位置,只需要通过Jump指定就可以了)。
3.        然后BIOS开始实施Power-OnSelf Test(POST),在这个过程中,如果遇到任何错误,Booting处理就会结束,机器会被挂起。
4.        然后BIOS开始查找显示卡。精确的说,是查找被内建在BIOS内部的显示卡程序,并执行它,它通常被放在C0000h的内存位置,它的作用是初始化显示卡。绝大多数的现代显示卡都能够在显示器上显示它的相关信息。这就是为什么当我们开机的时候,首先会在显示器的顶端会出现关于显示卡的信息。
5.        然后BIOS会查看其它设备的ROM,看一看这些设备之中哪些存在着BIOS,通常能够在C8000h的位置找到IDE/ATA硬盘的BIOS,并执行它们。如果找到任何其它设备的BIOSes,它们也会被执行。
6.        然后BIOS显示它的启动屏幕。
7.        然后BIOS开始做进一步的检测,包括我们可以看到的内存容量检测。在这个阶段,如果BIOS遇到任何错误,BIOS将会在屏幕上显示它的错误信息。
8.        然后BIOS会根据自己的"系统资源列表“,来对系统资源进行进一步的检测以确定究竟那些系统资源(设备)被安装在机器上。有些计算机会逐步显示这些被检测到的设备。
9.        如果BIOS支持Plug&
play标准,它将会检测和配置Plug&play设备,并显示这些它找到的设备。
10.        等着一些检测结束之后,BIOS会在系统屏幕上列出一个检测总结。
11.        然后BIOS开始寻找一个启动设备,你可以通过配置BIOS来决定其搜索的顺序,这些设备包括FloppyDisk(A),或者Hard Disk(C),甚至还可以包括CD-ROM Driver或者其它设备。
12.        当找到响应的启动设备之后,BIOS将会查找Boot信息以开始OS的启动过程。如果它找到了一个HardDisk,它将会查找一个位于Cylinder 0, Head 0, Sector 1的Master BootRecord(硬盘的第一个扇区),如果它找到的是Floppy Disk,它也会读区软盘的第一个扇区。
13.        如果找不到任何启动设备,系统将会显示一条错误信息,然后冻结系统。如果找到了响应的启动设备,BIOS会将读到的扇区放在内存7C00h的位置,并跳转到那里执行它。从此以后,就有硬件启动阶段进入了OS启动阶段。
总之,这个阶段有大量的事情要做,比如自检,初始化各种芯片,控制器,与端口;包括显示器,内存,键盘,软驱,串口等等;在这个过程中BIOS将检测到的数据放置于1K到2K的RAM,这个区域因此也被称为BIOS Data Area;同时还将中断向量以及BIOS程序运行所需要的Stack设置置于0到1K的RAM。最终,POST执行INT 19h中断,找到可以启动的磁盘,并将boot程序装入内存7C00h,并将控制权交给OS的boot程序。
也不知是否正确。

Wednesday, April 3, 2013

How to access the Super IO registers

Method: use normal I/O Index/Data Access

SIO Index: 0x0E
SIO DATA: 0x0F

Super I/O controller is connected to Southbridge, and it supports low speed devices including serial port, PS/2 keyboard/mouse, and parallel port.

All of the devices on Super I/O controller is identified by Logical Device Number (LDN). For example, Keyboard can be assigned as LDN 5, and Serial port COM1 has LDN 2.

In order to access Super I/O registers, please follow steps as below:

1. Use key config to open the access right.

2. Select LDN

3. Read/Write using normal outb/inb instruction.

Below is a sample code working on my machine. It is just a user program. We can use Tool rweverything to verify the result.


#define SIO_INDEX 0x2E
#define SIO_DATA SIO_INDEX+1
u8 byte;

// What the heck is this?
// some secret config key to open the access right
outb(0x87, SIO_INDEX);
outb(0x01, SIO_INDEX);
outb(0x55, SIO_INDEX);
outb(0x55, SIO_INDEX);

// set the Logical Device to keyboard
 // 7th bit of the configuration
outb(0x07, SIO_INDEX);
outb(0x05, SIO_DATA);

printk(BIOS_DEBUG, "\n\nKeybard Super IO configration:");
// print Super IO configuration
for(i=0; i<0x100; i++)
{
   outb(i, SIO_INDEX);
   byte = inb(SIO_DATA);
   if(i%16==0)
printk(BIOS_DEBUG, "\n");
   printk(BIOS_DEBUG, "%x ", byte);
}

// set the Logical Device to mouse
 // 7th bit of the config
outb(0x07, SIO_INDEX);
outb(0x06, SIO_DATA);

printk(BIOS_DEBUG, "\n\nMouse Super IO configration:");
// print Super IO configuration
for(i=0; i<0x100; i++)
{
   outb(i, SIO_INDEX);
   byte = inb(SIO_DATA);
   if(i%16==0)
printk(BIOS_DEBUG, "\n");
   printk(BIOS_DEBUG, "%x ", byte);
}

More info:
http://coreboot.blogspot.com/2009/01/coreboot-superio.html

Read Write Everything website

http://rweverything.com/download/