Просмотр исходного кода

Add basic RTL8029AS network support

Johannes Zellner 1 месяц назад
Родитель
Сommit
0b8534c747
6 измененных файлов с 655 добавлено и 2 удалено
  1. 11 2
      Makefile
  2. 60 0
      lspci.c
  3. 362 0
      ne2000.c
  4. 26 0
      ne2000.h
  5. 113 0
      netcmd.c
  6. 83 0
      terminal.c

+ 11 - 2
Makefile

@@ -125,6 +125,15 @@ usb.o: usb.c usb.h io.h timer.h uhci.h
 lsusb.o: lsusb.c io.h usb.h
 lsusb.o: lsusb.c io.h usb.h
 	$(CC) $(CFLAGS) -o $@ $<
 	$(CC) $(CFLAGS) -o $@ $<
 
 
+lspci.o: lspci.c io.h pci.h
+	$(CC) $(CFLAGS) -o $@ $<
+
+ne2000.o: ne2000.c ne2000.h pci.h timer.h io.h
+	$(CC) $(CFLAGS) -o $@ $<
+
+netcmd.o: netcmd.c io.h timer.h ne2000.h
+	$(CC) $(CFLAGS) -o $@ $<
+
 blkdev.o: blkdev.c blkdev.h ata.h disk.h
 blkdev.o: blkdev.c blkdev.h ata.h disk.h
 	$(CC) $(CFLAGS) -o $@ $<
 	$(CC) $(CFLAGS) -o $@ $<
 
 
@@ -188,7 +197,7 @@ switch.o: switch.S
 process.o: process.c process.h io.h
 process.o: process.c process.h io.h
 	$(CC) $(CFLAGS) -o $@ $<
 	$(CC) $(CFLAGS) -o $@ $<
 
 
-kernel.elf: vesa_stage.o kernel.o timer.o switch.o process.o screen.o io.o rtc.o terminal.o wm.o hello.o reboot.o poweroff.o disk.o fat.o ls.o cat.o run.o serial.o serial_ring_buf.o serial_loop.o serial_recv.o bin_recv.o vga.o vga_copy.o gpu.o ati.o cirrus.o nvidia.o font_8x8.o fbtext.o clock.o colors.o display.o cpuinfo.o mouse.o mousecmd.o uhci.o usb.o lsusb.o blkdev.o ata.o fatdetect.o storage.o fatformat.o format.o vfs.o idle.o kexec.o kexec_tramp.o dbg.o save.o rm.o mkdir.o rmdir.o
+kernel.elf: vesa_stage.o kernel.o timer.o switch.o process.o screen.o io.o rtc.o terminal.o wm.o hello.o reboot.o poweroff.o disk.o fat.o ls.o cat.o run.o serial.o serial_ring_buf.o serial_loop.o serial_recv.o bin_recv.o vga.o vga_copy.o gpu.o ati.o cirrus.o nvidia.o font_8x8.o fbtext.o clock.o colors.o display.o cpuinfo.o mouse.o mousecmd.o uhci.o usb.o lsusb.o blkdev.o ata.o fatdetect.o storage.o fatformat.o format.o vfs.o idle.o kexec.o kexec_tramp.o dbg.o save.o rm.o mkdir.o rmdir.o lspci.o ne2000.o netcmd.o
 	$(LD) $(KERNEL_LDFLAGS) -o $@ $^
 	$(LD) $(KERNEL_LDFLAGS) -o $@ $^
 
 
 MBR_LDFLAGS = -T mbr.ld -nostdlib -m elf_i386
 MBR_LDFLAGS = -T mbr.ld -nostdlib -m elf_i386
@@ -337,4 +346,4 @@ dev: kernel.bin kexec_send
 	./kexec_send $(SERIAL_DEV) $(SERIAL_BAUD) $$entry kernel.bin
 	./kexec_send $(SERIAL_DEV) $(SERIAL_BAUD) $$entry kernel.bin
 
 
 clean:
 clean:
-	rm -f boot.o vesa_stage.o kernel.o timer.o switch.o process.o screen.o io.o rtc.o terminal.o wm.o hello.o reboot.o poweroff.o fat.o ls.o cat.o run.o disk.o serial.o serial_ring_buf.o serial_loop.o serial_recv.o bin_recv.o vga.o vga_copy.o gpu.o ati.o cirrus.o nvidia.o font_8x8.o fbtext.o clock.o colors.o display.o cpuinfo.o mouse.o mousecmd.o uhci.o usb.o lsusb.o blkdev.o ata.o fatdetect.o storage.o fatformat.o format.o vfs.o idle.o kexec.o kexec_tramp.o dbg.o save.o rm.o mkdir.o rmdir.o mbr.o boot.elf kernel.elf mbr.elf boot.bin mbr.bin kernel.bin boot.bin.tmp boot.bin.patched image.bin floppy.img usb.img final.bin root.img prog.o prog.elf prog.bin space.o space.elf space.bin bootstrap.o bootstrap.elf bootstrap.bin send_serial kexec_send
+	rm -f boot.o vesa_stage.o kernel.o timer.o switch.o process.o screen.o io.o rtc.o terminal.o wm.o hello.o reboot.o poweroff.o fat.o ls.o cat.o run.o disk.o serial.o serial_ring_buf.o serial_loop.o serial_recv.o bin_recv.o vga.o vga_copy.o gpu.o ati.o cirrus.o nvidia.o font_8x8.o fbtext.o clock.o colors.o display.o cpuinfo.o mouse.o mousecmd.o uhci.o usb.o lsusb.o blkdev.o ata.o fatdetect.o storage.o fatformat.o format.o vfs.o idle.o kexec.o kexec_tramp.o dbg.o save.o rm.o mkdir.o rmdir.o lspci.o ne2000.o netcmd.o mbr.o boot.elf kernel.elf mbr.elf boot.bin mbr.bin kernel.bin boot.bin.tmp boot.bin.patched image.bin floppy.img usb.img final.bin root.img prog.o prog.elf prog.bin space.o space.elf space.bin bootstrap.o bootstrap.elf bootstrap.bin send_serial kexec_send

+ 60 - 0
lspci.c

@@ -0,0 +1,60 @@
+/* lspci command: enumerate PCI devices (vendor:device, class, BAR0). */
+
+#include "io.h"
+#include "pci.h"
+
+static void put_hex2(unsigned int v)
+{
+	static const char hex[] = "0123456789ABCDEF";
+	io_putchar(hex[(v >> 4) & 0xF]);
+	io_putchar(hex[v & 0xF]);
+}
+
+static void put_hex4(unsigned int v)
+{
+	put_hex2((v >> 8) & 0xFF);
+	put_hex2(v & 0xFF);
+}
+
+static void put_hex8(unsigned int v)
+{
+	put_hex4((v >> 16) & 0xFFFF);
+	put_hex4(v & 0xFFFF);
+}
+
+void program_lspci_main(void)
+{
+	unsigned int bus, dev;
+
+	for (bus = 0; bus < 256; bus++) {
+		for (dev = 0; dev < 32; dev++) {
+			unsigned int id = pci_cfg_read32(bus, dev, 0, 0x00);
+			unsigned int class_rev, bar0;
+			unsigned int vendor, device, cls, sub;
+
+			if (id == 0xFFFFFFFFu || id == 0)
+				continue;
+
+			vendor = id & 0xFFFFu;
+			device = (id >> 16) & 0xFFFFu;
+			class_rev = pci_cfg_read32(bus, dev, 0, 0x08);
+			cls = (class_rev >> 24) & 0xFFu;
+			sub = (class_rev >> 16) & 0xFFu;
+			bar0 = pci_cfg_read32(bus, dev, 0, 0x10);
+
+			put_hex2(bus);
+			io_putchar(':');
+			put_hex2(dev);
+			io_putstr("  ");
+			put_hex4(vendor);
+			io_putchar(':');
+			put_hex4(device);
+			io_putstr("  class=");
+			put_hex2(cls);
+			put_hex2(sub);
+			io_putstr("  bar0=");
+			put_hex8(bar0);
+			io_putchar('\n');
+		}
+	}
+}

+ 362 - 0
ne2000.c

@@ -0,0 +1,362 @@
+/* NE2000-compatible (Realtek RTL8029AS) Ethernet driver.
+   PCI discovery, byte-mode remote DMA, on-card SRAM ring, polling (no IRQ).
+
+   Register map (byte offsets from the I/O base; page selected by CR bits
+   PS0/PS1). Page 0: 0x00 CR, 0x01 PSTART, 0x02 PSTOP, 0x03 BNRY, 0x04
+   TPSR(TSR), 0x05/0x06 TBCR, 0x07 ISR, 0x08/0x09 RSAR, 0x0A/0x0B RBCR,
+   0x0C RCR, 0x0D TCR, 0x0E DCR, 0x0F IMR. Page 1: 0x01-0x06 PAR0-5,
+   0x07 CURR. Data port 0x10, reset port 0x1F. */
+
+#include "io.h"
+#include "pci.h"
+#include "timer.h"
+#include "ne2000.h"
+
+/* Register offsets. */
+#define NE_CR      0x00
+#define NE_PSTART  0x01
+#define NE_PSTOP   0x02
+#define NE_BNRY    0x03
+#define NE_TSR     0x04   /* read: transmit status */
+#define NE_TPSR    0x04   /* write: transmit page start */
+#define NE_TBCR0   0x05
+#define NE_TBCR1   0x06
+#define NE_ISR     0x07
+#define NE_RSAR0   0x08
+#define NE_RSAR1   0x09
+#define NE_RBCR0   0x0A
+#define NE_RBCR1   0x0B
+#define NE_RCR     0x0C
+#define NE_TCR     0x0D
+#define NE_DCR     0x0E
+#define NE_IMR     0x0F
+#define NE_DATA    0x10
+#define NE_RESET   0x1F
+
+/* CR bits. */
+#define CR_STP     0x01
+#define CR_START   0x02
+#define CR_TXP     0x04
+#define CR_RREAD   0x08
+#define CR_RWRITE  0x10
+#define CR_NODMA   0x20
+#define CR_PAGE1   0x40
+
+/* ISR bits. */
+#define ISR_PTX    0x02
+#define ISR_TXE    0x08
+#define ISR_RST    0x80
+
+/* RCR bits. */
+#define RCR_AB     0x04
+#define RCR_PRO    0x10
+
+/* TSR bits. */
+#define TSR_PTX    0x01
+
+/* On-card SRAM layout (16 KB at 0x4000): TX buffer 0x4000-0x45FF,
+   RX ring 0x4600-0x7FFF. Pages are 256 bytes. */
+#define TX_PAGE    0x40
+#define RX_START   0x46
+#define RX_STOP    0x80
+
+/* PCI IDs. */
+#define RTL8029_VENDOR 0x10ECu
+#define RTL8029_DEVICE 0x8029u
+
+static unsigned short iobase;
+static unsigned char mac[6];
+static int present;
+static int inited;
+
+static unsigned char nread(unsigned char reg)
+{
+	return port_inb((unsigned short)(iobase + reg));
+}
+
+static void nwrite(unsigned char reg, unsigned char val)
+{
+	port_outb((unsigned short)(iobase + reg), val);
+}
+
+static void delay_ms(unsigned int ms)
+{
+	unsigned int t0 = get_ticks_ms();
+	while (get_ticks_ms() - t0 < ms)
+		;
+}
+
+static void remote_read(unsigned short addr, unsigned char *dst, unsigned short len)
+{
+	unsigned short i;
+
+	nwrite(NE_CR, CR_NODMA | CR_START);      /* page 0, keep NIC running */
+	nwrite(NE_RBCR0, 0);
+	nwrite(NE_RBCR1, 0);
+	nwrite(NE_RSAR0, addr & 0xFF);
+	nwrite(NE_RSAR1, addr >> 8);
+	nwrite(NE_RBCR0, len & 0xFF);
+	nwrite(NE_RBCR1, len >> 8);
+	nwrite(NE_CR, CR_RREAD | CR_START);      /* remote read, page 0 */
+	for (i = 0; i + 1 < len; i += 2) {
+		unsigned short w = port_inw((unsigned short)(iobase + NE_DATA));
+		dst[i] = (unsigned char)(w & 0xFF);
+		dst[i + 1] = (unsigned char)(w >> 8);
+	}
+	if (len & 1)
+		dst[len - 1] = port_inb((unsigned short)(iobase + NE_DATA));
+}
+
+static void remote_write(unsigned short addr, const unsigned char *src, unsigned short len)
+{
+	unsigned short i;
+
+	nwrite(NE_CR, CR_NODMA | CR_START);
+	nwrite(NE_RBCR0, 0);
+	nwrite(NE_RBCR1, 0);
+	nwrite(NE_RSAR0, addr & 0xFF);
+	nwrite(NE_RSAR1, addr >> 8);
+	nwrite(NE_RBCR0, len & 0xFF);
+	nwrite(NE_RBCR1, len >> 8);
+	nwrite(NE_CR, CR_RWRITE | CR_START);     /* remote write, page 0 */
+	for (i = 0; i + 1 < len; i += 2)
+		port_outw((unsigned short)(iobase + NE_DATA),
+			  (unsigned short)(src[i] | (src[i + 1] << 8)));
+	if (len & 1)
+		port_outb((unsigned short)(iobase + NE_DATA), src[len - 1]);
+}
+
+int ne2000_init(void)
+{
+	unsigned int bus, dev;
+
+	if (inited)
+		return present ? 0 : -1;
+	inited = 1;
+
+	present = 0;
+	iobase = 0;
+
+	/* PCI scan for Realtek RTL8029. */
+	for (bus = 0; bus < 256 && !present; bus++) {
+		for (dev = 0; dev < 32; dev++) {
+			unsigned int id = pci_cfg_read32(bus, dev, 0, 0x00);
+			unsigned int cmd, bar;
+
+			if (id == 0xFFFFFFFFu || id == 0)
+				continue;
+			if ((id & 0xFFFFu) != RTL8029_VENDOR)
+				continue;
+			if (((id >> 16) & 0xFFFFu) != RTL8029_DEVICE)
+				continue;
+
+			/* Enable I/O space + bus master. */
+			cmd = pci_cfg_read32(bus, dev, 0, 0x04);
+			pci_cfg_write32(bus, dev, 0, 0x04, cmd | 0x0005u);
+
+			bar = pci_cfg_read32(bus, dev, 0, 0x10);
+			if (!(bar & 0x1u))
+				continue;   /* not an I/O-space BAR */
+
+			iobase = (unsigned short)(bar & 0xFFFCu);
+			present = 1;
+		}
+	}
+
+	if (!present)
+		return -1;
+
+	/* Reset (read then write the reset port). */
+	nwrite(NE_RESET, nread(NE_RESET));
+	delay_ms(20);
+
+	/* Wait for reset completion (ISR RST bit), then clear ISR. */
+	{
+		unsigned int t0 = get_ticks_ms();
+		while (!(nread(NE_ISR) & ISR_RST)) {
+			if (get_ticks_ms() - t0 > 500)
+				break;
+		}
+		nwrite(NE_ISR, 0xFF);
+	}
+
+	/* Stop, page 0. */
+	nwrite(NE_CR, CR_NODMA | CR_STP);
+
+	/* DCR: word-wide remote DMA (16-bit), normal (non-loopback), 8-byte FIFO. */
+	nwrite(NE_DCR, 0x49);
+
+	nwrite(NE_RBCR0, 0);
+	nwrite(NE_RBCR1, 0);
+
+	/* Read the station address PROM. The NE2000/RTL8029 maps the MAC into
+	   the first 32 bytes of remote-DMA-addressable memory, at even offsets. */
+	{
+		unsigned char prom[32];
+		unsigned int i;
+		remote_read(0x0000, prom, 32);
+		for (i = 0; i < 6; i++)
+			mac[i] = prom[2 * i];
+	}
+
+	/* RX: promiscuous + broadcast (easiest to observe traffic). */
+	nwrite(NE_RCR, RCR_PRO | RCR_AB);
+
+	/* TX: normal, append CRC. */
+	nwrite(NE_TCR, 0x00);
+
+	/* Ring buffer. */
+	nwrite(NE_PSTART, RX_START);
+	nwrite(NE_PSTOP, RX_STOP);
+	nwrite(NE_BNRY, RX_START);
+
+	/* Clear ISR; mask all interrupts (polling). */
+	nwrite(NE_ISR, 0xFF);
+	nwrite(NE_IMR, 0x00);
+
+	/* Page 1: set CURR to the first free page. */
+	nwrite(NE_CR, CR_NODMA | CR_START | CR_PAGE1);
+	nwrite(0x07, RX_START + 1);
+
+	/* Page 0, start the NIC. */
+	nwrite(NE_CR, CR_NODMA | CR_START);
+
+	return 0;
+}
+
+int ne2000_present(void)
+{
+	return present;
+}
+
+void ne2000_get_mac(unsigned char out[6])
+{
+	unsigned int i;
+	for (i = 0; i < 6; i++)
+		out[i] = mac[i];
+}
+
+int ne2000_rx(unsigned char *buf, unsigned int maxlen)
+{
+	unsigned char bnry, cur, pkt, next, status;
+	unsigned short addr, len;
+	unsigned int guard = 0;
+
+	if (!present)
+		return -1;
+
+	for (;;) {
+		/* Safety net: a full ring is only ~230 frames, so bail out
+		   rather than spin forever if the card misbehaves. */
+		if (++guard > 1024)
+			return -1;
+
+		/* BNRY (page 0) and CURR (page 1). */
+		nwrite(NE_CR, CR_NODMA | CR_START);
+		bnry = nread(NE_BNRY);
+		nwrite(NE_CR, CR_NODMA | CR_START | CR_PAGE1);
+		cur = nread(0x07);
+		nwrite(NE_CR, CR_NODMA | CR_START);
+
+		/* Next unread frame starts at page bnry+1 (wrapping). */
+		pkt = bnry + 1;
+		if (pkt >= RX_STOP)
+			pkt = RX_START;
+
+		/* No new frames once the next-unread page catches up to CURR. */
+		if (pkt == cur)
+			return -1;
+
+		addr = (unsigned short)pkt << 8;
+
+		/* 4-byte header: status, next page, length lo, length hi. */
+		{
+			unsigned char hdr[4];
+			remote_read(addr, hdr, 4);
+			status = hdr[0];
+			next = hdr[1];
+			len = (unsigned short)hdr[2] | ((unsigned short)hdr[3] << 8);
+		}
+
+		/* Advance boundary past this frame. */
+		if (next == RX_START)
+			nwrite(NE_BNRY, RX_STOP - 1);
+		else
+			nwrite(NE_BNRY, next - 1);
+
+		/* Skip errored or oversized frames. */
+		if (!(status & 0x01))
+			continue;
+		if (len < 4 || (unsigned int)(len - 4) > maxlen)
+			continue;
+
+		remote_read(addr + 4, buf, (unsigned short)(len - 4));
+		return (int)(len - 4);
+	}
+}
+
+int ne2000_tx(const unsigned char *buf, unsigned int len)
+{
+	unsigned int t0;
+	unsigned char isr, tsr;
+
+	if (!present)
+		return -1;
+	if (len < 14 || len > 1514)
+		return -1;
+
+	/* Copy the frame into on-card SRAM. */
+	remote_write((unsigned short)(TX_PAGE << 8), buf, (unsigned short)len);
+
+	/* Program transmit page + byte count. */
+	nwrite(NE_CR, CR_NODMA | CR_START);
+	nwrite(NE_TPSR, TX_PAGE);
+	nwrite(NE_TBCR0, len & 0xFF);
+	nwrite(NE_TBCR1, (len >> 8) & 0xFF);
+
+	/* Clear TX status bits, then fire. */
+	nwrite(NE_ISR, ISR_PTX | ISR_TXE);
+	nwrite(NE_CR, CR_NODMA | CR_START | CR_TXP);
+
+	/* Poll for completion. */
+	t0 = get_ticks_ms();
+	for (;;) {
+		isr = nread(NE_ISR);
+		if (isr & (ISR_PTX | ISR_TXE))
+			break;
+		if (get_ticks_ms() - t0 > 100)
+			return -1;
+	}
+
+	tsr = nread(NE_TSR);
+	if (!(tsr & TSR_PTX))
+		return -1;   /* collision/abort/underrun */
+	return 0;
+}
+
+static void put_hex2(unsigned char v)
+{
+	static const char hex[] = "0123456789ABCDEF";
+	io_putchar(hex[(v >> 4) & 0xF]);
+	io_putchar(hex[v & 0xF]);
+}
+
+void ne2000_print_info(void)
+{
+	unsigned int i;
+
+	if (!present) {
+		io_putstr("net: no RTL8029AS found\n");
+		return;
+	}
+
+	io_putstr("RTL8029AS iobase=0x");
+	io_puthex(iobase);
+	io_putstr(" mac=");
+	for (i = 0; i < 6; i++) {
+		if (i)
+			io_putchar(':');
+		put_hex2(mac[i]);
+	}
+	io_putchar('\n');
+}

+ 26 - 0
ne2000.h

@@ -0,0 +1,26 @@
+/* NE2000-compatible (Realtek RTL8029AS) Ethernet driver.
+   Polling based (no IRQ), byte-mode remote DMA, on-card 16 KB SRAM ring. */
+#ifndef NE2000_H
+#define NE2000_H
+
+/* Probe + reset + configure the NIC. Idempotent; 0 on success, -1 if absent. */
+int ne2000_init(void);
+
+/* 1 if a supported NIC was found. */
+int ne2000_present(void);
+
+/* Copy the NIC's 6-byte MAC address into out[]. */
+void ne2000_get_mac(unsigned char out[6]);
+
+/* Print NIC info (base, MAC) to the console. */
+void ne2000_print_info(void);
+
+/* Poll one received frame. Returns length (>= 14) or -1 if none pending.
+   buf must hold at least maxlen bytes; frames longer than maxlen are skipped. */
+int ne2000_rx(unsigned char *buf, unsigned int maxlen);
+
+/* Transmit a raw Ethernet frame (must include the 14-byte header).
+   Returns 0 on success, -1 on error. */
+int ne2000_tx(const unsigned char *buf, unsigned int len);
+
+#endif

+ 113 - 0
netcmd.c

@@ -0,0 +1,113 @@
+/* Network test commands: netinfo, netrecv, netsend. */
+
+#include "io.h"
+#include "timer.h"
+#include "ne2000.h"
+
+static void put_hex2(unsigned char v)
+{
+	static const char hex[] = "0123456789ABCDEF";
+	io_putchar(hex[(v >> 4) & 0xF]);
+	io_putchar(hex[v & 0xF]);
+}
+
+static void put_dec(unsigned int v)
+{
+	char b[12];
+	int i = 0;
+
+	if (v == 0) {
+		io_putchar('0');
+		return;
+	}
+	while (v) {
+		b[i++] = (char)('0' + (v % 10));
+		v /= 10;
+	}
+	while (i)
+		io_putchar(b[--i]);
+}
+
+void program_netinfo_main(void)
+{
+	ne2000_init();
+	ne2000_print_info();
+}
+
+void program_netrecv_main(void)
+{
+	unsigned char buf[2048];
+	unsigned int deadline, count = 0;
+
+	ne2000_init();
+	if (!ne2000_present()) {
+		io_putstr("netrecv: no NIC found\n");
+		return;
+	}
+
+	io_putstr("netrecv: listening (8s)...\n");
+	deadline = get_ticks_ms() + 8000;
+
+	while (get_ticks_ms() < deadline) {
+		int len = ne2000_rx(buf, sizeof(buf));
+		unsigned int i;
+
+		if (len < 0)
+			continue;
+
+		io_putstr("rx ");
+		put_dec((unsigned int)len);
+		io_putstr(" bytes:\n");
+		for (i = 0; i < (unsigned int)len; i++) {
+			put_hex2(buf[i]);
+			io_putchar(' ');
+			if ((i & 15) == 15)
+				io_putchar('\n');
+		}
+		if (((unsigned int)len & 15) != 0)
+			io_putchar('\n');
+
+		if (++count >= 32)
+			break;
+	}
+
+	io_putstr("netrecv: ");
+	put_dec(count);
+	io_putstr(" frame(s)\n");
+}
+
+void program_netsend_main(void)
+{
+	unsigned char frame[64];
+	unsigned char mac[6];
+	unsigned int i;
+
+	ne2000_init();
+	if (!ne2000_present()) {
+		io_putstr("netsend: no NIC found\n");
+		return;
+	}
+
+	ne2000_get_mac(mac);
+
+	/* Broadcast test frame: dst=ff:ff:ff:ff:ff:ff, src=our MAC,
+	   ethertype 0x88B5 (local experimental), payload "NEBS". */
+	for (i = 0; i < 6; i++)
+		frame[i] = 0xFF;
+	for (i = 0; i < 6; i++)
+		frame[6 + i] = mac[i];
+	frame[12] = 0x88;
+	frame[13] = 0xB5;
+	frame[14] = 'N';
+	frame[15] = 'E';
+	frame[16] = 'B';
+	frame[17] = 'S';
+	for (i = 18; i < 64; i++)
+		frame[i] = 0x00;
+
+	if (ne2000_tx(frame, sizeof(frame)) != 0) {
+		io_putstr("netsend: transmit failed\n");
+		return;
+	}
+	io_putstr("netsend: sent 64-byte broadcast frame\n");
+}

+ 83 - 0
terminal.c

@@ -30,6 +30,10 @@ extern void program_run_serial_main(const char *arg);
 extern void program_lsusb_main(void);
 extern void program_lsusb_main(void);
 extern void program_storage_main(void);
 extern void program_storage_main(void);
 extern void program_format_main(const char *arg);
 extern void program_format_main(const char *arg);
+extern void program_lspci_main(void);
+extern void program_netinfo_main(void);
+extern void program_netrecv_main(void);
+extern void program_netsend_main(void);
 
 
 /* Print the prompt (with the current directory) and set line_start. */
 /* Print the prompt (with the current directory) and set line_start. */
 static void term_print_prompt(struct term *t, int first)
 static void term_print_prompt(struct term *t, int first)
@@ -239,6 +243,73 @@ static int is_cmd_lsusb(const char *line, unsigned int line_len)
 	return (i == line_len);
 	return (i == line_len);
 }
 }
 
 
+static int is_cmd_lspci(const char *line, unsigned int line_len)
+{
+	unsigned int i = 0;
+	while (i < line_len && line[i] == ' ')
+		i++;
+	if (i + 5 > line_len)
+		return 0;
+	if (line[i] != 'l' || line[i+1] != 's' || line[i+2] != 'p' ||
+	    line[i+3] != 'c' || line[i+4] != 'i')
+		return 0;
+	i += 5;
+	while (i < line_len && line[i] == ' ')
+		i++;
+	return (i == line_len);
+}
+
+static int is_cmd_netinfo(const char *line, unsigned int line_len)
+{
+	unsigned int i = 0;
+	while (i < line_len && line[i] == ' ')
+		i++;
+	if (i + 7 > line_len)
+		return 0;
+	if (line[i] != 'n' || line[i+1] != 'e' || line[i+2] != 't' ||
+	    line[i+3] != 'i' || line[i+4] != 'n' || line[i+5] != 'f' ||
+	    line[i+6] != 'o')
+		return 0;
+	i += 7;
+	while (i < line_len && line[i] == ' ')
+		i++;
+	return (i == line_len);
+}
+
+static int is_cmd_netrecv(const char *line, unsigned int line_len)
+{
+	unsigned int i = 0;
+	while (i < line_len && line[i] == ' ')
+		i++;
+	if (i + 7 > line_len)
+		return 0;
+	if (line[i] != 'n' || line[i+1] != 'e' || line[i+2] != 't' ||
+	    line[i+3] != 'r' || line[i+4] != 'e' || line[i+5] != 'c' ||
+	    line[i+6] != 'v')
+		return 0;
+	i += 7;
+	while (i < line_len && line[i] == ' ')
+		i++;
+	return (i == line_len);
+}
+
+static int is_cmd_netsend(const char *line, unsigned int line_len)
+{
+	unsigned int i = 0;
+	while (i < line_len && line[i] == ' ')
+		i++;
+	if (i + 7 > line_len)
+		return 0;
+	if (line[i] != 'n' || line[i+1] != 'e' || line[i+2] != 't' ||
+	    line[i+3] != 's' || line[i+4] != 'e' || line[i+5] != 'n' ||
+	    line[i+6] != 'd')
+		return 0;
+	i += 7;
+	while (i < line_len && line[i] == ' ')
+		i++;
+	return (i == line_len);
+}
+
 static int is_cmd_space(const char *line, unsigned int line_len)
 static int is_cmd_space(const char *line, unsigned int line_len)
 {
 {
 	unsigned int i = 0;
 	unsigned int i = 0;
@@ -824,6 +895,14 @@ void term_run(struct term *t)
 						}
 						}
 					} else if (is_cmd_lsusb(t->line, t->line_len)) {
 					} else if (is_cmd_lsusb(t->line, t->line_len)) {
 						term_spawn("lsusb", program_lsusb_main);
 						term_spawn("lsusb", program_lsusb_main);
+					} else if (is_cmd_lspci(t->line, t->line_len)) {
+						term_spawn("lspci", program_lspci_main);
+					} else if (is_cmd_netinfo(t->line, t->line_len)) {
+						term_spawn("netinfo", program_netinfo_main);
+					} else if (is_cmd_netrecv(t->line, t->line_len)) {
+						term_spawn("netrecv", program_netrecv_main);
+					} else if (is_cmd_netsend(t->line, t->line_len)) {
+						term_spawn("netsend", program_netsend_main);
 					} else if (is_cmd_storage(t->line, t->line_len)) {
 					} else if (is_cmd_storage(t->line, t->line_len)) {
 						term_spawn("storage", program_storage_main);
 						term_spawn("storage", program_storage_main);
 					} else if (is_cmd_clock(t->line, t->line_len)) {
 					} else if (is_cmd_clock(t->line, t->line_len)) {
@@ -917,6 +996,10 @@ void term_run(struct term *t)
 						io_putstr("mouseinfo\n");
 						io_putstr("mouseinfo\n");
 						io_putstr("storage\n");
 						io_putstr("storage\n");
 						io_putstr("format <device>\n");
 						io_putstr("format <device>\n");
+						io_putstr("lspci\n");
+						io_putstr("netinfo\n");
+						io_putstr("netrecv\n");
+						io_putstr("netsend\n");
 						io_putstr("ps\n");
 						io_putstr("ps\n");
 						io_putstr("kill <pid>\n");
 						io_putstr("kill <pid>\n");
 						io_putstr("kexec\n");
 						io_putstr("kexec\n");