RTL8139 MAC Address (using QEMU)

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
jasonc122
Member
Member
Posts: 27
Joined: Fri Jan 01, 2010 7:51 am

RTL8139 MAC Address (using QEMU)

Post by jasonc122 »

Hi,

I've an easy question for those that have got networking working using the RTL8139 on QEMU...

I'm trying to correctly read the MAC address for the RTL8139 network device using QEMU. I set the MAC using:

qemu ... -net nic, model=rtl8139, macaddr=52:54:00:12:34:56

However, I'm getting 0xFFFFFFFFFFFF as the MAC from my OS. What's going wrong here? I'm reading BAR0 from the PCI config to get the IO base address and then I'm reading the MAC i.e. inl(io_base + 0x00) and inw(io_base + 0x40).

I'm reading 0x3040 as the IO base from BAR0 which has value 0xc101.

Code: Select all

pci_device_t *pci_dev;
		u8int cmd;
		u8int interrupt_line;
		u32int MAC0;
		u16int MAC4;
		u32int work;

		pci_dev = _ki_load_pci_device(0x10ec,0x8139);
		if( pci_dev == 0)
		{
			ki_printf("couldn't load network pci device\n");
			return;
		}

		ki_printf_klog("BAR0 for RTL8139 device is 0x%x\n",pci_dev->config.reg4.bar0);

		io_base = (u16int)_ki_get_pci_io_bar(pci_dev->config.reg4.bar0);
		ki_printf_klog("IO base for RTL8139 device is 0x%x\n",io_base);

		interrupt_line = pci_dev->config.reg15.interrupt_line;
		ki_printf_klog("RTL8139 interrupt line nr is %d\n", interrupt_line);
	
		MAC0 = ki_inl(io_base + 0x00);
		MAC4 = ki_inw(io_base + 0x04);
		ki_printf_klog("RTL8139 MAC: 0x%x%x\n",MAC0,MAC4);
TIA
H Technology Solutions - Business Operating System Specialists
jasonc122
Member
Member
Posts: 27
Joined: Fri Jan 01, 2010 7:51 am

Re: RTL8139 MAC Address (using QEMU)

Post by jasonc122 »

thanks to froggey and hindplayr this problems been solved.

The error was in my "_ki_get_pci_io_bar" routine which should have returned 0xc100 instead 0x3040.
H Technology Solutions - Business Operating System Specialists
User avatar
IanSeyler
Member
Member
Posts: 326
Joined: Mon Jul 28, 2008 9:46 am
Location: Ontario, Canada
Contact:

Re: RTL8139 MAC Address (using QEMU)

Post by IanSeyler »

I made the same mistake. You clear the 2 lowest bits from the value in BAR0 to get the Base IO... not shifting right by 2.

Code: Select all

os_net_rtl8139_probe_found:            ; Supported device was found. Get the Base IO
    mov cl, 0x04                ; BAR0
    call os_pci_read_reg
    and eax, 0xFFFFFFFC            ; EAX now holds the Base IO Address (clear the low 2 bits)
    mov word [os_NetIOAddress], ax
BareMetal OS - http://www.returninfinity.com/
Mono-tasking 64-bit OS for x86-64 based computers, written entirely in Assembly
Post Reply