From: Lei Xia Date: Mon, 6 Oct 2008 16:53:17 +0000 (-0500) Subject: stable compliation version with some running problems in kernel thread X-Git-Tag: 1.0~3^2~11^2 X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=3fb8af7e2069d7517b5d6c4fb7dc04b22ddf8396 stable compliation version with some running problems in kernel thread --- diff --git a/palacios/build/Makefile b/palacios/build/Makefile index 8fa36ef..1f20a2d 100644 --- a/palacios/build/Makefile +++ b/palacios/build/Makefile @@ -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 diff --git a/palacios/include/geekos/int.h b/palacios/include/geekos/int.h index a80d142..0097777 100644 --- a/palacios/include/geekos/int.h +++ b/palacios/include/geekos/int.h @@ -20,6 +20,11 @@ #include #include + +// 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. diff --git a/palacios/include/geekos/ne2k.h b/palacios/include/geekos/ne2k.h index 10c2175..7f7395c 100644 --- a/palacios/include/geekos/ne2k.h +++ b/palacios/include/geekos/ne2k.h @@ -60,6 +60,16 @@ #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; diff --git a/palacios/include/geekos/socket.h b/palacios/include/geekos/socket.h index 1b839d6..fbc47ed 100644 --- a/palacios/include/geekos/socket.h +++ b/palacios/include/geekos/socket.h @@ -5,9 +5,11 @@ #define GEEKOS_SOCKET_H #include -#include #include +#ifdef UIP +#include + 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 diff --git a/palacios/include/geekos/timer.h b/palacios/include/geekos/timer.h index da31415..b967fef 100644 --- a/palacios/include/geekos/timer.h +++ b/palacios/include/geekos/timer.h @@ -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 */ diff --git a/palacios/include/libc/string.h b/palacios/include/libc/string.h index 5a81cb8..5bf42df 100644 --- a/palacios/include/libc/string.h +++ b/palacios/include/libc/string.h @@ -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, ...); diff --git a/palacios/include/lwip/arch/cc.h b/palacios/include/lwip/arch/cc.h index 73eb7d3..75b51bd 100644 --- a/palacios/include/lwip/arch/cc.h +++ b/palacios/include/lwip/arch/cc.h @@ -35,11 +35,7 @@ /* Include some files for defining library routines */ #include - -extern int fflush(FILE *file); -extern int printf(char *fmt, ...); -extern void abort (void); - +#include /* Define platform endianness */ #ifndef BYTE_ORDER @@ -74,7 +70,7 @@ typedef u32_t mem_ptr_t; //#include //#include /* 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) diff --git a/palacios/include/lwip/ipv4/lwip/ip_addr.h b/palacios/include/lwip/ipv4/lwip/ip_addr.h index 7f24336..9c184af 100644 --- a/palacios/include/lwip/ipv4/lwip/ip_addr.h +++ b/palacios/include/lwip/ipv4/lwip/ip_addr.h @@ -32,7 +32,7 @@ #ifndef __LWIP_IP_ADDR_H__ #define __LWIP_IP_ADDR_H__ -#include "lwip/opt.h" +#include #ifdef __cplusplus extern "C" { diff --git a/palacios/include/lwip/lwip/opt.h b/palacios/include/lwip/lwip/opt.h index c980e44..8128d34 100644 --- a/palacios/include/lwip/lwip/opt.h +++ b/palacios/include/lwip/lwip/opt.h @@ -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 #include "lwip/debug.h" /* @@ -640,7 +640,7 @@ * TCP_WND: The size of a TCP window. */ #ifndef TCP_WND -#define TCP_WND 2048 +#define TCP_WND 1024 //2048 #endif /** @@ -785,7 +785,7 @@ * 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 /** diff --git a/palacios/include/uip/uip-conf.h b/palacios/include/uip/uip-conf.h index 17a5d5e..6f23e05 100644 --- a/palacios/include/uip/uip-conf.h +++ b/palacios/include/uip/uip-conf.h @@ -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 diff --git a/palacios/src/geekos/ne2k.c b/palacios/src/geekos/ne2k.c index bebca55..a139f36 100644 --- a/palacios/src/geekos/ne2k.c +++ b/palacios/src/geekos/ne2k.c @@ -4,8 +4,11 @@ #include #include #include + +#ifdef UIP #include #include +#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); diff --git a/palacios/src/geekos/net.c b/palacios/src/geekos/net.c index dedb156..7067a38 100644 --- a/palacios/src/geekos/net.c +++ b/palacios/src/geekos/net.c @@ -5,14 +5,70 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include -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 diff --git a/palacios/src/geekos/socket.c b/palacios/src/geekos/socket.c index 661970e..4ef4907 100644 --- a/palacios/src/geekos/socket.c +++ b/palacios/src/geekos/socket.c @@ -5,13 +5,16 @@ #include #include #include + +#ifdef UIP + #include #include + #include #include #include - #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 */ diff --git a/palacios/src/geekos/synch.c b/palacios/src/geekos/synch.c index c7a826c..5c5a75b 100644 --- a/palacios/src/geekos/synch.c +++ b/palacios/src/geekos/synch.c @@ -14,6 +14,8 @@ #include #include +#include + /* * NOTES: * - The GeekOS mutex and condition variable APIs are based on those diff --git a/palacios/src/geekos/timer.c b/palacios/src/geekos/timer.c index ec47b0b..0e3804f 100644 --- a/palacios/src/geekos/timer.c +++ b/palacios/src/geekos/timer.c @@ -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 { diff --git a/palacios/src/lwip/api/tcpip.c b/palacios/src/lwip/api/tcpip.c index 97ae41d..2dae2e5 100644 --- a/palacios/src/lwip/api/tcpip.c +++ b/palacios/src/lwip/api/tcpip.c @@ -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: diff --git a/palacios/src/lwip/build/Makefile b/palacios/src/lwip/build/Makefile index af7ceb3..db76718 100644 --- a/palacios/src/lwip/build/Makefile +++ b/palacios/src/lwip/build/Makefile @@ -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)) diff --git a/palacios/src/lwip/core/init.c b/palacios/src/lwip/core/init.c index 5e0b522..5a29538 100644 --- a/palacios/src/lwip/core/init.c +++ b/palacios/src/lwip/core/init.c @@ -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 */