3 #include <video_defines.h>
5 #include <pci-bother.h>
10 #include "../aseg/keyboard.h"
12 static struct nic *_nic = 0x0;
14 extern struct pci_driver a3c90x_driver;
16 static char test[1024] = {0};
18 static char packet[4096] = {0};
20 typedef struct packet_t {
23 unsigned short ethertype;
24 unsigned short datalen;
25 unsigned char command;
29 static unsigned char vga_read(unsigned char idx)
31 outb(CRTC_IDX_REG, idx);
32 return inb(CRTC_DATA_REG);
35 static unsigned int vga_base()
37 return (((unsigned int) vga_read(CRTC_START_ADDR_MSB_IDX)) << 9)
38 + (((unsigned int) vga_read(CRTC_START_ADDR_LSB_IDX)) << 1);
41 void handle_command(packet_t * p)
43 uint16_t dl = htons(p->datalen);
46 outputf("NIC: Command: 0x%x, %d bytes", p->command, dl);
50 for (i = 0; i < dl; i++)
51 kbd_inject_key(p->data[i]);
54 outb(0xCF9, 0x4); /* Reboot */
63 static short pos = 0x0;
64 unsigned short base = vga_base();
65 unsigned char *p = (unsigned char *)0xB8000;
66 smram_state_t old_state;
71 if (_nic->poll(_nic, 0)) {
72 _nic->packet = packet;
75 packet_t * p = (packet_t *) packet;
77 outputf("NIC: Packet: %d 0x%x", _nic->packetlen, htons(p->ethertype));
78 if (htons(p->ethertype) == 0x1338) {
79 if (htons(p->datalen) + sizeof(packet_t) > _nic->packetlen) {
80 outputf("NIC: Malformed packet");
86 smram_tseg_set_state(SMRAM_TSEG_OPEN);
87 old_state = smram_save_state();
92 if (((base + 80*25*2)%0x8000) < base)
94 if ((pos > ((base + 80*25*2)%0x8000)) && (pos < base))
96 } else if ((pos > base + 80*25*2) || (pos < base))
100 test[1] = pos & 0xFF;
102 test[3] = base & 0xFF;
104 smram_aseg_set_state(SMRAM_ASEG_SMMCODE);
106 for (i = 4; i < 1024; i++)
111 smram_restore_state(old_state);
112 _nic->transmit("\x00\x03\x93\x87\x84\x8C", 0x1337, 1024, test);
115 int eth_register(struct nic *nic)
125 /* Required for DMA to work. :( */
126 smram_tseg_set_state(SMRAM_TSEG_OPEN);
127 pci_probe_driver(a3c90x_driver);