Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


stable compliation version with some running problems in kernel thread
Lei Xia [Mon, 6 Oct 2008 16:53:17 +0000 (11:53 -0500)]
18 files changed:
palacios/build/Makefile
palacios/include/geekos/int.h
palacios/include/geekos/ne2k.h
palacios/include/geekos/socket.h
palacios/include/geekos/timer.h
palacios/include/libc/string.h
palacios/include/lwip/arch/cc.h
palacios/include/lwip/ipv4/lwip/ip_addr.h
palacios/include/lwip/lwip/opt.h
palacios/include/uip/uip-conf.h
palacios/src/geekos/ne2k.c
palacios/src/geekos/net.c
palacios/src/geekos/socket.c
palacios/src/geekos/synch.c
palacios/src/geekos/timer.c
palacios/src/lwip/api/tcpip.c
palacios/src/lwip/build/Makefile
palacios/src/lwip/core/init.c

index 8fa36ef..1f20a2d 100644 (file)
@@ -181,7 +181,7 @@ endif
 #
 #TCPSTACK, uIP is used currently
 #
-UIP=ON
+UIP=OFF
 
 #
 #LWIP, ON -- used, OFF -- not used
@@ -321,8 +321,10 @@ endif
 
 ifeq ($(LWIP),ON)
        LWIP_OBJS := lwip/*.o
+       CC_LWIP_OPTS := -I$(PROJECT_ROOT)/include/lwip  -I$(PROJECT_ROOT)/include/lwip/ipv4 -I$(PROJECT_ROOT)/include/libc -DLWIP_DEBUG
 else
        LWIP_OBJS := 
+       CC_LWIP_OPTS :=
 endif
 
 TCPSTACK_OBJS := $(UIP_C_OBJS) $(LWIP_OBJS)
@@ -425,7 +427,7 @@ OBJCOPY_FLAGS := -R .dynamic -R .note -R .comment
 # Compilation of kernel C source files
 
 geekos/%.o : geekos/%.c
-       $(TARGET_CC) -c $(CC_GENERAL_OPTS) $(CC_KERNEL_OPTS) $< -o geekos/$*.o
+       $(TARGET_CC) -c $(CC_GENERAL_OPTS) $(CC_KERNEL_OPTS) $(CC_LWIP_OPTS) $< -o geekos/$*.o
 
 
 # Compilation of kernel assembly source files
index a80d142..0097777 100644 (file)
 #include <geekos/ktypes.h>
 #include <geekos/defs.h>
 
+
+// to stop the compilation warnings
+extern void Print(const char* fmt, ...); 
+extern void Set_Current_Attr(uchar_t attrib);
+
 /*
  * This struct reflects the contents of the stack when
  * a C interrupt handler function is called.
index 10c2175..7f7395c 100644 (file)
 
 #define NE2K_IRQ       11              /* Interrupt channel */
 
+
+/* Physical Address of Network Card */
+#define PHY_ADDR1 0x52
+#define PHY_ADDR2 0x54
+#define PHY_ADDR3 0x00
+#define PHY_ADDR4 0x12
+#define PHY_ADDR5 0x34
+#define PHY_ADDR6 0x58
+
+
 struct NE2K_REGS {
        uchar_t cr;
        uchar_t isr;
index 1b839d6..fbc47ed 100644 (file)
@@ -5,9 +5,11 @@
 #define GEEKOS_SOCKET_H
 
 #include <geekos/ring_buffer.h>
-#include <uip/uip.h>
 #include <geekos/kthread.h>
 
+#ifdef UIP
+#include <uip/uip.h>
+
 
 typedef enum {WAITING, CLOSED, LISTEN, ESTABLISHED} sock_state_t;
 
@@ -32,5 +34,7 @@ int send(int sockfd, void * buf, uint_t len);
 
 void set_ip_addr(uchar_t addr[4]);
 
+#endif /* UIP */
+
 
 #endif
index da31415..b967fef 100644 (file)
@@ -14,7 +14,7 @@
 
 #define TIMER_IRQ 0
 
-extern volatile ulong_t g_numTicks;
+extern volatile unsigned long g_numTicks;
 
 typedef void (*timerCallback)(int, void*);
 
@@ -43,6 +43,6 @@ int Cancel_Timer(int id);
 
 void Micro_Delay(int us);
 
-ulong_t clock_time(void);  //return elipsed millisecs
+unsigned long clock_time(void);  //return elipsed millisecs
 
 #endif  /* GEEKOS_TIMER_H */
index 5a81cb8..5bf42df 100644 (file)
@@ -44,7 +44,8 @@ char *strrchr(const char *s, int c);
 char *strpbrk(const char *s, const char *accept);
 char *strncat(char *s1, const char *s2, size_t limit);
 int fprintf(FILE *file, char *fmt, ...);
-//int fflush(FILE *file);
+int fflush(FILE *file);
+int printf(char *fmt, ...);
 
 
 
index 73eb7d3..75b51bd 100644 (file)
 /* Include some files for defining library routines */
 
 #include <string.h>
-
-extern int fflush(FILE *file);
-extern int printf(char *fmt, ...);
-extern void abort (void);
-
+#include <geekos/debug.h>
 
 /* Define platform endianness */
 #ifndef BYTE_ORDER
@@ -74,7 +70,7 @@ typedef u32_t mem_ptr_t;
 //#include <stdio.h>
 //#include <stdlib.h>
 /* Plaform specific diagnostic output */
-#define LWIP_PLATFORM_DIAG(x)  //do {printf x;} while(0)
+#define LWIP_PLATFORM_DIAG(x)  do {PrintBoth x;} while(0)//do {printf x;} while(0)
 
 #define LWIP_PLATFORM_ASSERT(x)   do {printf("Assertion \"%s\" failed at line %d in %s\n", \
                                    x, __LINE__, __FILE__); fflush(NULL); abort();} while(0) 
index 7f24336..9c184af 100644 (file)
@@ -32,7 +32,7 @@
 #ifndef __LWIP_IP_ADDR_H__
 #define __LWIP_IP_ADDR_H__
 
-#include "lwip/opt.h"
+#include <lwip/lwip/opt.h>
 
 #ifdef __cplusplus
 extern "C" {
index c980e44..8128d34 100644 (file)
@@ -42,7 +42,7 @@
  * Include user defined options first. Anything not defined in these files
  * will be set to standard values. Override anything you dont like!
  */
-#include "lwipopts.h"
+#include <lwip/lwipopts.h>
 #include "lwip/debug.h"
 
 /*
  * TCP_WND: The size of a TCP window.
  */
 #ifndef TCP_WND
-#define TCP_WND                         2048
+#define TCP_WND                         1024 //2048
 #endif 
 
 /**
  * LWIP_NETIF_API==1: Support netif api (in netifapi.c)
  */
 #ifndef LWIP_NETIF_API
-#define LWIP_NETIF_API                  0
+#define LWIP_NETIF_API                  1
 #endif
 
 /**
index 17a5d5e..6f23e05 100644 (file)
@@ -69,7 +69,8 @@ extern int appcall(void);
  *
  * \hideinitializer
  */
-typedef unsigned char u8_t;
+//conflict with lwip
+//typedef unsigned char u8_t;
 
 /**
  * 16 bit datatype
@@ -78,7 +79,8 @@ typedef unsigned char u8_t;
  *
  * \hideinitializer
  */
-typedef unsigned short int u16_t;
+//confict with lwip
+//typedef unsigned short int u16_t;
 
 /**
  * Statistics datatype
index bebca55..a139f36 100644 (file)
@@ -4,8 +4,11 @@
 #include <geekos/irq.h>
 #include <geekos/malloc.h>
 #include <geekos/string.h>
+
+#ifdef UIP
 #include <uip/uip.h>
 #include <uip/uip_arp.h>
+#endif
 
 #define DEBUG 1
 #define TX_START_BUFF  0x40
@@ -127,13 +130,13 @@ int Init_Ne2k(int (*rcvd_fn)(struct NE2K_Packet_Info *info, uchar_t *packet))
   cr->ps = 0x01;  /* Switch to reg page 1 */
   Out_Byte(NE2K_CR, regs->cr);
 
-  /* Set the physical address of the card to 52:54:00:12:34:58 */
-  Out_Byte(NE2K_CR+0x01, 0x52);
-  Out_Byte(NE2K_CR+0x02, 0x54);
-  Out_Byte(NE2K_CR+0x03, 0x00);
-  Out_Byte(NE2K_CR+0x04, 0x12);
-  Out_Byte(NE2K_CR+0x05, 0x34);
-  Out_Byte(NE2K_CR+0x06, 0x58);
+  /* Set the physical address of the card */
+  Out_Byte(NE2K_CR+0x01, PHY_ADDR1);
+  Out_Byte(NE2K_CR+0x02, PHY_ADDR2);
+  Out_Byte(NE2K_CR+0x03, PHY_ADDR3);
+  Out_Byte(NE2K_CR+0x04, PHY_ADDR4);
+  Out_Byte(NE2K_CR+0x05, PHY_ADDR5);
+  Out_Byte(NE2K_CR+0x06, PHY_ADDR6);
 
   /* Set the multicast address register to all 1s; accepts all multicast packets */
   uint_t i;
@@ -207,6 +210,8 @@ int Init_Ne2k(int (*rcvd_fn)(struct NE2K_Packet_Info *info, uchar_t *packet))
  * an ARP packet, which is sent out instead.  The original packet will need to be
  * retransmitted at some point in the future.
  */
+#ifdef UIP
+
 int NE2K_Transmit(uint_t size)
 {
   uip_arp_out();
@@ -236,6 +241,8 @@ int NE2K_Transmit(uint_t size)
   return 0;
 }
 
+#endif
+
 int NE2K_Send_Packet(uchar_t *packet, uint_t size)
 {
   struct _CR * cr = (struct _CR*)&(regs->cr);
index dedb156..7067a38 100644 (file)
@@ -5,14 +5,70 @@
 #include <geekos/net.h>
 #include <geekos/socket.h>
 #include <geekos/ne2k.h>
+#include <lwip/apps/ping.h>
+#include <lwip/lwip/sockets.h>
+#include <lwip/ipv4/lwip/ip_addr.h>
+#include <lwip/netif/ne2kif.h>
+#include <lwip/sys.h>
+#include <lwip/netifapi.h>
+#include <lwip/tcpip.h>
+#include <netif/etharp.h>
+#include <geekos/debug.h>
 
-void Init_Network() {
-  init_socket_layer();
+
+static void
+tcpip_init_done(void *arg)
+{
+  sys_sem_t *sem;
+  sem = arg;
+  sys_sem_signal(*sem);
 }
 
+void Init_Network() {
+
+  //temporay now we are using lwip sockets
+  // init_socket_layer();
+  
+  struct ip_addr ipaddr, netmask, gateway;
+  sys_sem_t sem;
+  err_t err;
+
+  sem = sys_sem_new(0);
+
+#ifdef LWIP_DEBUG
+  PrintBoth("lwIP: before tcpip_init\n");
+#endif
+
+  tcpip_init(tcpip_init_done, &sem);  //initial the whole lwip module
 
+#ifdef LWIP_DEBUG
+  PrintBoth("lwIP: After tcpip_init\n");
+#endif
 
+  sys_sem_wait(sem);
+  sys_sem_free(sem);
+  IP4_ADDR(&gateway, 192,168,1,1);
+  IP4_ADDR(&ipaddr, 192,168,1,2);
+  IP4_ADDR(&netmask, 255,255,255,0);
 
+
+  err = netifapi_netif_add(&ne2kif, &ipaddr, &netmask, &gateway, 
+                                               NULL, ne2kif_init, ethernet_input); 
+  
+  if (err != ERR_OK){
+               PrintBoth("lwip: initial network failed! add netif error %d/n", err);
+               return;
+  }
+  
+  netifapi_netif_set_default(&ne2kif);
+
+  //initial a network application
+  ping_init();
+}
+
+
+#if 0
 void test_network() {
 
     uchar_t local_addr[4];
@@ -23,7 +79,7 @@ void test_network() {
     local_addr[2] = 2;
     local_addr[3] = 21;
 
-    set_ip_addr(local_addr);
+//    set_ip_addr(local_addr);
 
     remote_addr[0] = 10;
     remote_addr[1] = 0;
@@ -31,6 +87,8 @@ void test_network() {
     remote_addr[3] = 20;
 
 
-    connect(remote_addr, 4301);
+   // connect(remote_addr, 4301);
 
 }
+
+#endif
index 661970e..4ef4907 100644 (file)
@@ -5,13 +5,16 @@
 #include <geekos/socket.h>
 #include <geekos/malloc.h>
 #include <geekos/ne2k.h>
+
+#ifdef UIP
+
 #include <uip/uip.h>
 #include <uip/uip_arp.h>
+
 #include <geekos/vmm_stubs.h>
 #include <geekos/debug.h>
 #include <geekos/timer.h>
 
-
 #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
 
 #define MAX_SOCKS 1024
@@ -25,12 +28,11 @@ void socket_appcall(void);
 #endif /* UIP_APPCALL */
 
 
-
-
 static int Packet_Received(struct NE2K_Packet_Info* info, uchar_t *pkt);
 static void periodic_caller(int timer_id, void * arg);
 
 void init_socket_layer() {
+       
    int i = 0;
    bool iflag;
 
@@ -42,31 +44,24 @@ void init_socket_layer() {
       sockets[i].state = CLOSED;
    }
 
-
-
     //initiate uIP
     uip_init();
     uip_arp_init();
        
-    //setup device driver
-    Init_Ne2k(&Packet_Received);
+    //setup device driver 
+    Init_Ne2k(&Packet_Received); 
 
     iflag = Begin_Int_Atomic();
     Start_Timer(2, periodic_caller, NULL);
     End_Int_Atomic(iflag);
-
 }
 
-
-
-
 void set_ip_addr(uchar_t addr[4]) {
   uip_ipaddr_t ipaddr;
   uip_ipaddr(ipaddr, addr[0], addr[1], addr[2], addr[3]);  /* Local IP address */
   uip_sethostaddr(ipaddr);
 }
 
-
 static int allocate_socket_fd() {
   int i = 0;
   
@@ -107,7 +102,6 @@ struct socket * get_socket_from_fd(int fd) {
 }
 
 
-
 static void periodic_caller(int timer_id, void * arg) {
   int i;
   //handle the periodic calls of uIP
@@ -362,3 +356,6 @@ static int Packet_Received(struct NE2K_Packet_Info * info, uchar_t * pkt) {
 
   return 0;
 }
+
+
+#endif  /* UIP */
index c7a826c..5c5a75b 100644 (file)
@@ -14,6 +14,8 @@
 #include <geekos/synch.h>
 #include <geekos/timer.h>
 
+#include <geekos/debug.h>
+
 /*
  * NOTES:
  * - The GeekOS mutex and condition variable APIs are based on those
index ec47b0b..0e3804f 100644 (file)
@@ -356,6 +356,8 @@ int Start_Timer(int ticks, timerCallback cb, void * arg)
 
     KASSERT(!Interrupts_Enabled());
 
+    PrintBoth ("there\n");
+
     if (timeEventCount == MAX_TIMER_EVENTS) {
        return -1;
     } else {
index 97ae41d..2dae2e5 100644 (file)
@@ -261,7 +261,11 @@ tcpip_thread(void *arg)
 
   LOCK_TCPIP_CORE();
   while (1) {                          /* MAIN Loop */
+
+    PrintBoth("In tcp_thread: main loop\n");    
+
     sys_mbox_fetch(mbox, (void *)&msg);
+
     switch (msg->type) {
 #if LWIP_NETCONN
     case TCPIP_MSG_API:
index af7ceb3..db76718 100644 (file)
@@ -56,17 +56,19 @@ CORE4FILES=$(LWIPDIR)/core/ipv4/icmp.c $(LWIPDIR)/core/ipv4/ip.c \
 
 # APIFILES: The files which implement the sequential and socket APIs.
 APIFILES=$(LWIPDIR)/api/api_lib.c $(LWIPDIR)/api/api_msg.c $(LWIPDIR)/api/tcpip.c \
-       $(LWIPDIR)/api/err.c $(LWIPDIR)/api/sockets.c $(LWIPDIR)/api/netbuf.c $(LWIPDIR)/api/netdb.c
+       $(LWIPDIR)/api/err.c $(LWIPDIR)/api/sockets.c $(LWIPDIR)/api/netbuf.c $(LWIPDIR)/api/netdb.c  $(LWIPDIR)/api/netifapi.c
 
 # NETIFFILES: Files implementing various generic network interface functions.'
-NETIFFILES=$(LWIPDIR)/netif/loopif.c \
-       $(LWIPDIR)/netif/etharp.c
+NETIFFILES=$(LWIPDIR)/netif/loopif.c $(LWIPDIR)/netif/ne2kif.c $(LWIPDIR)/netif/etharp.c
 
 # ARCHFILES: Architecture specific files.
 ARCHFILES=$(LWIPDIR)/arch/sys_arch.c
 
+# APPFILES: Application files
+APPFILES=$(LWIPDIR)/apps/ping.c
+
 # LWIPFILES: All the above.
-LWIPFILES=$(COREFILES) $(CORE4FILES) $(APIFILES) $(NETIFFILES) $(ARCHFILES)
+LWIPFILES=$(COREFILES) $(CORE4FILES) $(APIFILES) $(NETIFFILES) $(ARCHFILES) $(APPFILES)
 LWIPFILESW=$(wildcard $(LWIPFILES))
 LWIPOBJS=$(notdir $(LWIPFILESW:.c=.o))
 
index 5e0b522..5a29538 100644 (file)
@@ -200,7 +200,7 @@ lwip_sanity_check(void)
   if (TCP_SNDLOWAT > TCP_SND_BUF)
     LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_SNDLOWAT must be less than or equal to TCP_SND_BUF.\n"));
   if (TCP_WND > (PBUF_POOL_SIZE*PBUF_POOL_BUFSIZE))
-    LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_WND is larger than space provided by PBUF_POOL_SIZE*PBUF_POOL_BUFSIZE\n"));
+    LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_WND is larger than space provided by PBUF_POOL_SIZE*PBUF_POOL_BUFSIZE: %d\n",  (PBUF_POOL_SIZE*PBUF_POOL_BUFSIZE)));
   if (TCP_WND < TCP_MSS)
     LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_WND is smaller than MSS\n"));
 #endif /* LWIP_TCP */