]> Joshua Wise's Git repositories - netwatch.git/blob - net/net.c
7312fdec89426630cff34b898f5b1a764a915d05
[netwatch.git] / net / net.c
1 #include <pci.h>
2 #include <io.h>
3 #include <video_defines.h>
4 #include <smram.h>
5 #include <pci-bother.h>
6 #include <output.h>
7 #include "net.h"
8
9 static struct nic *_nic = 0x0;
10
11 extern struct pci_driver a3c90x_driver;
12
13 static char test[1024] = {0};
14
15 static char packet[4096] = {0};
16
17 typedef struct packet_t {
18         char from[6];
19         char to[6];
20         unsigned short ethertype;
21         char data[];
22 } packet_t;
23
24 static unsigned char vga_read(unsigned char idx)
25 {
26         outb(CRTC_IDX_REG, idx);
27         return inb(CRTC_DATA_REG);
28 }
29
30 static unsigned int vga_base()
31 {
32         return (((unsigned int) vga_read(CRTC_START_ADDR_MSB_IDX)) << 9)
33              + (((unsigned int) vga_read(CRTC_START_ADDR_LSB_IDX)) << 1);
34 }
35
36 void eth_poll()
37 {
38         int i;
39 //      static int c;
40         static short pos = 0x0;
41         unsigned short base = vga_base();
42         unsigned char *p = (unsigned char *)0xB8000;
43         smram_state_t old_state;
44         
45         if (!_nic)
46                 return;
47
48         if (_nic->poll(_nic, 0)) {
49                 _nic->packet = packet;
50                 _nic->poll(_nic, 1);
51
52                 packet_t * p = (packet_t *) packet;
53
54                 outputf("NIC: Packet: %d 0x%x", _nic->packetlen, p->ethertype);
55                 if (p->ethertype == 0x3813) {
56                         outputf("NIC: Command: 0x%x", *((uint16_t *)p->data));
57                 }
58         }
59         smram_tseg_set_state(SMRAM_TSEG_OPEN);
60         old_state = smram_save_state();
61         
62 //      if ((c++) % 2)
63 //              return;
64         
65         test[0] = pos >> 8;
66         test[1] = pos & 0xFF;
67         test[2] = base >> 8;
68         test[3] = base & 0xFF;
69
70         smram_aseg_set_state(SMRAM_ASEG_SMMCODE);
71         
72         for (i = 4; i < 1024; i++)
73         {
74                 test[i] = p[pos++];
75                 pos %= 0x8000;
76         }
77         smram_restore_state(old_state);
78         _nic->transmit("\x00\x03\x93\x87\x84\x8C", 0x1337, 1024, test);
79 }
80
81 int eth_register(struct nic *nic)
82 {
83         if (_nic)
84                 return -1;
85         _nic = nic;
86         return 0;
87 }
88
89 void eth_init()
90 {
91         /* Required for DMA to work. :( */
92         smram_tseg_set_state(SMRAM_TSEG_OPEN);
93         pci_probe_driver(a3c90x_driver);
94 }
This page took 0.024139 seconds and 2 git commands to generate.