Fixed a bug in apic.c for irq's > 7. Rewrote/organized nic driver to use kalloc
[akaros.git] / kern / src / syscall.c
index 4e51b99..cb852f6 100644 (file)
@@ -72,6 +72,7 @@ static ssize_t sys_serial_read(env_t* e, char *DANGEROUS buf, size_t len)
        #endif
 }
 
+// This is probably not a syscall we want. Its hacky. Here just for syscall stuff until get a stack.
 static ssize_t sys_eth_write(env_t* e, const char *DANGEROUS buf, size_t len) 
 { 
        extern int eth_up;
@@ -84,11 +85,15 @@ static ssize_t sys_eth_write(env_t* e, const char *DANGEROUS buf, size_t len)
                int cur_packet_len = 0;
                while (total_sent != len) {
                        cur_packet_len = ((len - total_sent) > MAX_PACKET_DATA) ? MAX_PACKET_DATA : (len - total_sent);
-                       
-                       just_sent = send_packet(packet_wrap(buf + total_sent, cur_packet_len), cur_packet_len + PACKET_HEADER_SIZE);
+                       char* wrap_buffer = packet_wrap(buf + total_sent, cur_packet_len);
+                       just_sent = send_frame(wrap_buffer, cur_packet_len + PACKET_HEADER_SIZE);
                        
                        if (just_sent < 0)
-                               return -1; // This should be an error code of its own
+                               return 0; // This should be an error code of its own
+                               
+                       if (wrap_buffer)
+                               kfree(wrap_buffer);
+                               
                        total_sent += cur_packet_len;
                }
                
@@ -98,22 +103,52 @@ static ssize_t sys_eth_write(env_t* e, const char *DANGEROUS buf, size_t len)
        else
                return -E_INVAL;
 }
+/*
+static ssize_t sys_eth_write(env_t* e, const char *DANGEROUS buf, size_t len) 
+{ 
+       extern int eth_up;
+       
+       if (eth_up) {
+               
+               char *COUNT(len) _buf = user_mem_assert(e, buf, len, PTE_U);
+               
+               return(send_frame(buf, len));
+       }
+       return -E_INVAL;
+}
+*/
 
+
+// This is probably not a syscall we want. Its hacky. Here just for syscall stuff until get a stack.
 static ssize_t sys_eth_read(env_t* e, char *DANGEROUS buf, size_t len) 
-{/*
-       #ifdef SERIAL_IO
-           char *COUNT(len) _buf = user_mem_assert(e, buf, len, PTE_U);
-               size_t bytes_read = 0;
-               int c;
-               while((c = serial_read_byte()) != -1) {
-                       buf[bytes_read++] = (uint8_t)c;
-                       if(bytes_read == len) break;
+{
+       extern int eth_up;
+       
+       if (eth_up) {
+               extern int packet_waiting;
+               extern int packet_buffer_size;
+               extern char* packet_buffer;
+               extern char* packet_buffer_orig;
+               extern int packet_buffer_pos;
+                       
+               if (packet_waiting == 0)
+                       return 0;
+                       
+               int read_len = ((packet_buffer_pos + len) > packet_buffer_size) ? packet_buffer_size - packet_buffer_pos : len;
+
+               memcpy(buf, packet_buffer + packet_buffer_pos, read_len);
+       
+               packet_buffer_pos = packet_buffer_pos + read_len;
+       
+               if (packet_buffer_pos == packet_buffer_size) {
+                       kfree(packet_buffer_orig);
+                       packet_waiting = 0;
                }
-               return (ssize_t)bytes_read;
-       #else
+       
+               return read_len;
+       }
+       else
                return -E_INVAL;
-       #endif*/
-               return 0;
 }
 
 // Invalidate the cache of this core