From: Jack Lange Date: Tue, 16 Sep 2008 19:03:48 +0000 (+0000) Subject: fixed a ton of compile errors X-Git-Tag: 1.0~34 X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=eb7dda8d4a92a2e8d0c8f867c65317d756ca6c11 fixed a ton of compile errors --- diff --git a/palacios/build/Makefile b/palacios/build/Makefile index 7a147f4..9f0f862 100644 --- a/palacios/build/Makefile +++ b/palacios/build/Makefile @@ -1,6 +1,6 @@ # Makefile for GeekOS kernel, userspace, and tools # Copyright (c) 2004,2005 David H. Hovemeyer -# $Revision: 1.69 $ +# $Revision: 1.70 $ # This is free software. You are permitted to use, # redistribute, and modify it as specified in the file "COPYING". @@ -141,7 +141,7 @@ endif endif -DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DTEST_NE2K +#DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DTEST_NE2K ifeq ($(DEBUG),1) JRLDEBUG= -DSERIAL_PRINT_DEBUG=1 -DSERIAL_PRINT_DEBUG_LEVEL=10 -DSERIAL_PRINT=1 -DVMM_DEBUG=1 -DVMM_INFO=1 -DVMM_TRACE=1 $(DEBUG_SECTIONS) @@ -230,8 +230,9 @@ KERNEL_C_SRCS := idt.c int.c trap.c irq.c io.c \ serial.c reboot.c \ paging.c \ debug.c vmm_stubs.c vm.c pci.c\ - queue.c socket.c ring_buffer.c \ + queue.c ring_buffer.c \ main.c + #socket.c # Kernel object files built from C source files KERNEL_C_OBJS := $(KERNEL_C_SRCS:%.c=geekos/%.o) diff --git a/palacios/include/geekos/timer.h b/palacios/include/geekos/timer.h index 37dda14..bf09464 100644 --- a/palacios/include/geekos/timer.h +++ b/palacios/include/geekos/timer.h @@ -1,7 +1,7 @@ /* * GeekOS timer interrupt support * Copyright (c) 2001, David H. Hovemeyer - * $Revision: 1.1 $ + * $Revision: 1.2 $ * * This is free software. You are permitted to use, * redistribute, and modify it as specified in the file "COPYING". @@ -14,11 +14,25 @@ extern volatile ulong_t g_numTicks; +typedef void (*timerCallback)(int); + void Init_Timer(void); void Micro_Delay(int us); +typedef struct { + int ticks; /* timer code decrements this */ + int id; /* unqiue id for this timer even */ + timerCallback callBack; /* Queue to wakeup on timer expire */ + int origTicks; +} timerEvent; + +int Start_Timer(int ticks, timerCallback); +int Get_Remaing_Timer_Ticks(int id); +int Cancel_Timer(int id); + + void Micro_Delay(int us); #endif /* GEEKOS_TIMER_H */ diff --git a/palacios/include/palacios/vm_guest.h b/palacios/include/palacios/vm_guest.h index bb1afbb..7d31e6f 100644 --- a/palacios/include/palacios/vm_guest.h +++ b/palacios/include/palacios/vm_guest.h @@ -139,6 +139,10 @@ struct guest_info { vm_operating_mode_t run_state; void * vmm_data; + + /* TEMP */ + //ullong_t exit_tsc; + }; diff --git a/palacios/src/devices/8259a.c b/palacios/src/devices/8259a.c index b636ddc..186aace 100644 --- a/palacios/src/devices/8259a.c +++ b/palacios/src/devices/8259a.c @@ -6,7 +6,7 @@ #ifndef DEBUG_PIC #undef PrintDebug #define PrintDebug(fmt, args...) -#define PrintPicTrace(_f, _a...) PrintTrace("\n8259a.c(%d) "_f, __LINE__, ## _a) +//#define PrintPicTrace(_f, _a...) PrintTrace("\n8259a.c(%d) "_f, __LINE__, ## _a) #endif @@ -190,18 +190,18 @@ static int pic_lower_intr(void *private_data, int irq_no) { struct pic_internal *state = (struct pic_internal*)private_data; - PrintPicTrace("[pic_lower_intr] IRQ line %d now low\n", (unsigned) irq_no); + PrintDebug("[pic_lower_intr] IRQ line %d now low\n", (unsigned) irq_no); if (irq_no <= 7) { state->master_irr &= ~(1 << irq_no); if ((state->master_irr & ~(state->master_imr)) == 0) { - PrintPicTrace("\t\tFIXME: Master maybe should do sth\n"); + PrintDebug("\t\tFIXME: Master maybe should do sth\n"); } } else if ((irq_no > 7) && (irq_no <= 15)) { state->slave_irr &= ~(1 << (irq_no - 8)); if ((state->slave_irr & (~(state->slave_imr))) == 0) { - PrintPicTrace("\t\tFIXME: Slave maybe should do sth\n"); + PrintDebug("\t\tFIXME: Slave maybe should do sth\n"); } } return 0; diff --git a/palacios/src/geekos/main.c b/palacios/src/geekos/main.c index eab0aa0..5e1d714 100644 --- a/palacios/src/geekos/main.c +++ b/palacios/src/geekos/main.c @@ -3,7 +3,7 @@ * Copyright (c) 2001,2003,2004 David H. Hovemeyer * Copyright (c) 2003, Jeffrey K. Hollingsworth * Copyright (c) 2004, Iulian Neamtiu - * $Revision: 1.45 $ + * $Revision: 1.46 $ * * This is free software. You are permitted to use, * redistribute, and modify it as specified in the file "COPYING". @@ -249,8 +249,7 @@ void Main(struct Boot_Info* bootInfo) Init_Stubs(); - -#ifdef TEST_NE2K +#if 0 { init_network(); uchar_t local_addr[4]; @@ -259,14 +258,14 @@ void Main(struct Boot_Info* bootInfo) local_addr[0] = 10; local_addr[1] = 0; local_addr[2] = 2; - local_addr[3] = 20; + local_addr[3] = 21; set_ip_addr(local_addr); remote_addr[0] = 10; remote_addr[1] = 0; remote_addr[2] = 2; - remote_addr[3] = 21; + remote_addr[3] = 20; connect(remote_addr, 4301); @@ -347,11 +346,10 @@ void Main(struct Boot_Info* bootInfo) } #endif -#if !TEST_NE2K + { RunVMM(bootInfo); } -#endif SerialPrint("RunVMM returned, spinning\n"); diff --git a/palacios/src/geekos/ne2k.c b/palacios/src/geekos/ne2k.c index 453781a..bebca55 100644 --- a/palacios/src/geekos/ne2k.c +++ b/palacios/src/geekos/ne2k.c @@ -37,6 +37,7 @@ static void Dump_Registers() static void NE2K_Interrupt_Handler(struct Interrupt_State * state) { + Begin_IRQ(state); PrintBoth("NIC Interrupt Occured!\n"); uchar_t isr_content = In_Byte(NE2K_ISR); diff --git a/palacios/src/geekos/socket.c b/palacios/src/geekos/socket.c index a3966e1..0301b93 100644 --- a/palacios/src/geekos/socket.c +++ b/palacios/src/geekos/socket.c @@ -5,7 +5,7 @@ #include #include #include - +#include #define BUF ((struct uip_eth_hdr *)&uip_buf[0]) @@ -15,12 +15,21 @@ struct socket sockets[MAX_SOCKS]; +void socket_appcall(void); +#ifndef UIP_APPCALL +#define UIP_APPCALL socket_appcall +#endif /* UIP_APPCALL */ + + -int Packet_Received(struct NE2K_Packet_Info* info, uchar_t *pkt); +static int Packet_Received(struct NE2K_Packet_Info* info, uchar_t *pkt); +static void periodic_caller(int timer_id); void init_network() { int i = 0; + bool iflag; + for (i = 0; i < MAX_SOCKS; i++) { sockets[i].in_use = 0; @@ -30,6 +39,7 @@ void init_network() { } + //initiate uIP uip_init(); uip_arp_init(); @@ -37,7 +47,9 @@ void init_network() { //setup device driver Init_Ne2k(&Packet_Received); - + iflag = Begin_Int_Atomic(); + Start_Timer(2, periodic_caller); + End_Int_Atomic(iflag); } @@ -91,20 +103,43 @@ struct socket * get_socket_from_fd(int fd) { } + +static void periodic_caller(int timer_id) { + int i; + //handle the periodic calls of uIP + + //PrintBoth("Timer CALLBACK handler\n"); + + for(i = 0; i < UIP_CONNS; ++i) { + uip_periodic(i); + if(uip_len > 0) { + //devicedriver_send(); + PrintBoth("Sending Packet\n"); + NE2K_Transmit(uip_len); + } + } + for(i = 0; i < UIP_UDP_CONNS; i++) { + uip_udp_periodic(i); + if(uip_len > 0) { + //devicedriver_send(); + NE2K_Transmit(uip_len); + } + } +} + + int connect(const uchar_t ip_addr[4], ushort_t port) { int sockfd = -1; sockfd = allocate_socket_fd(); - uip_ipaddr_t ipaddr; + static uip_ipaddr_t ipaddr; if (sockfd == -1) { return -1; } uip_ipaddr(&ipaddr, ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3]); - - sockets[sockfd].state = WAITING; - sockets[sockfd].con = uip_connect((uip_ipaddr_t *)&ip_addr, htons(port)); + sockets[sockfd].con = uip_connect(&ipaddr, htons(port)); if (sockets[sockfd].con == NULL){ @@ -114,18 +149,12 @@ int connect(const uchar_t ip_addr[4], ushort_t port) { PrintBoth("Connection start\n"); - - while(sockets[sockfd].state == WAITING) { - timer_int_handler(NULL); - } - + Wait(&(sock->recv_wait_queue)); + PrintBoth("Connected\n"); - if (sockets[sockfd].state != ESTABLISHED) { - release_socket_fd(sockfd); - return -1; - } + return sockfd; @@ -149,24 +178,7 @@ buf_read: return recvlen; } -void timer_int_Handler(struct Interrupt_State * state){ - int i; - //handle the periodic calls of uIP - for(i = 0; i < UIP_CONNS; ++i) { - uip_periodic(i); - if(uip_len > 0) { - //devicedriver_send(); - NE2K_Transmit(uip_len); - } - } - for(i = 0; i < UIP_UDP_CONNS; i++) { - uip_udp_periodic(i); - if(uip_len > 0) { - //devicedriver_send(); - NE2K_Transmit(uip_len); - } - } -} + // a series of utilities to handle conncetion states static void connected(int sockfd) { @@ -303,38 +315,46 @@ void socket_appcall(void) { -int Packet_Received(struct NE2K_Packet_Info * info, uchar_t * pkt) { +static int Packet_Received(struct NE2K_Packet_Info * info, uchar_t * pkt) { //int i; - uip_len = info->size; // for (i = 0; i < info->size; i++) { // uip_buf[i] = *(pkt + i); //} + PrintBoth("Packet REceived\n"); + memcpy(uip_buf, pkt, uip_len); Free(pkt); if (BUF->type == htons(UIP_ETHTYPE_ARP)) { + PrintBoth("ARP PACKET\n"); + uip_arp_arpin(); + if (uip_len > 0) { + PrintBoth("Transmitting\n"); NE2K_Transmit(uip_len); - } + } + } else { - + PrintBoth("Data PACKET\n"); uip_arp_ipin(); uip_input(); + if (uip_len > 0) { + PrintBoth("Transmitting\n"); uip_arp_out(); NE2K_Transmit(uip_len); } + } - - return 0; + return 0; } diff --git a/palacios/src/geekos/timer.c b/palacios/src/geekos/timer.c index 01b716d..f9139bc 100644 --- a/palacios/src/geekos/timer.c +++ b/palacios/src/geekos/timer.c @@ -2,7 +2,7 @@ * GeekOS timer interrupt support * Copyright (c) 2001,2003 David H. Hovemeyer * Copyright (c) 2003, Jeffrey K. Hollingsworth - * $Revision: 1.10 $ + * $Revision: 1.11 $ * * This is free software. You are permitted to use, * redistribute, and modify it as specified in the file "COPYING". @@ -18,6 +18,7 @@ #include #include +#include /* PAD this currently is in nvram.c */ extern void deliver_timer_interrupt_to_vmm(uint_t period_us); @@ -26,53 +27,10 @@ extern void deliver_timer_interrupt_to_vmm(uint_t period_us); uint_t cpu_khz_freq; -#define __SLOW_DOWN_IO "\noutb %%al,$0x80" -#ifdef REALLY_SLOW_IO -#define __FULL_SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO -#else -#define __FULL_SLOW_DOWN_IO __SLOW_DOWN_IO -#endif - - - -#define __OUT1(s,x) \ -static inline void out##s(unsigned x value, unsigned short port) { - -#define __OUT2(s,s1,s2) \ -__asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1" - -#define __OUT(s,s1,x) \ -__OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "Nd" (port)); } \ -__OUT1(s##_p,x) __OUT2(s,s1,"w") __FULL_SLOW_DOWN_IO : : "a" (value), "Nd" (port));} \ - - -#define __IN1(s) \ -static inline RETURN_TYPE in##s(unsigned short port) { RETURN_TYPE _v; - -#define __IN2(s,s1,s2) \ -__asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0" - -#define __IN(s,s1,i...) \ -__IN1(s) __IN2(s,s1,"w") : "=a" (_v) : "Nd" (port) ,##i ); return _v; } \ -__IN1(s##_p) __IN2(s,s1,"w") __FULL_SLOW_DOWN_IO : "=a" (_v) : "Nd" (port) ,##i ); return _v; } \ - - -#define RETURN_TYPE unsigned char -__IN(b,"") -#undef RETURN_TYPE -#define RETURN_TYPE unsigned short -__IN(w,"") -#undef RETURN_TYPE -#define RETURN_TYPE unsigned int -__IN(l,"") -#undef RETURN_TYPE -__OUT(b,"b",char) -__OUT(w,"w",short) - @@ -157,6 +115,13 @@ pit_calibrate_tsc(void) +#define MAX_TIMER_EVENTS 100 + +static int timerDebug = 0; +static int timeEventCount; +static int nextEventID; +timerEvent pendingTimerEvents[MAX_TIMER_EVENTS]; + /* @@ -210,39 +175,50 @@ int g_Quantum = DEFAULT_MAX_TICKS; static void Timer_Interrupt_Handler(struct Interrupt_State* state) { - struct Kernel_Thread* current = g_currentThread; - - Begin_IRQ(state); - - + int i; + struct Kernel_Thread* current = g_currentThread; -#if 0 -#define STACK_LEN 256 + Begin_IRQ(state); - SerialPrint("Host Timer Interrupt Handler running\n"); - SerialPrint("Timer====\n"); - Dump_Interrupt_State(state); - // SerialMemDump((unsigned char*)(¤t),STACK_LEN); - SerialPrint("Timer done===\n"); - -#endif - /* Update global and per-thread number of ticks */ - ++g_numTicks; - ++current->numTicks; + /* Update global and per-thread number of ticks */ + ++g_numTicks; + ++current->numTicks; + + /* update timer events */ + for (i=0; i < timeEventCount; i++) { + if (pendingTimerEvents[i].ticks == 0) { + if (timerDebug) Print("timer: event %d expired (%d ticks)\n", + pendingTimerEvents[i].id, pendingTimerEvents[i].origTicks); + (pendingTimerEvents[i].callBack)(pendingTimerEvents[i].id); + pendingTimerEvents[i].ticks = pendingTimerEvents[i].origTicks; + } else { + pendingTimerEvents[i].ticks--; + } + } + + /* + * If thread has been running for an entire quantum, + * inform the interrupt return code that we want + * to choose a new thread. + */ + if (current->numTicks >= g_Quantum) { + g_needReschedule = true; /* - * If thread has been running for an entire quantum, - * inform the interrupt return code that we want - * to choose a new thread. + * The current process is moved to a lower priority queue, + * since it consumed a full quantum. */ - if (current->numTicks >= g_Quantum) { - g_needReschedule = true; - } - - - deliver_timer_interrupt_to_vmm(1000000/HZ); - - End_IRQ(state); + //if (current->currentReadyQueue < (MAX_QUEUE_LEVEL - 1)) { + /*Print("process %d moved to ready queue %d\n", current->pid, current->currentReadyQueue); */ + //current->currentReadyQueue++; + //} + + } + + + deliver_timer_interrupt_to_vmm(1000000/HZ); + + End_IRQ(state); } /* @@ -360,6 +336,57 @@ void Init_Timer(void) } +int Start_Timer(int ticks, timerCallback cb) +{ + int ret; + + KASSERT(!Interrupts_Enabled()); + + if (timeEventCount == MAX_TIMER_EVENTS) { + return -1; + } else { + ret = nextEventID++; + pendingTimerEvents[timeEventCount].id = ret; + pendingTimerEvents[timeEventCount].callBack = cb; + pendingTimerEvents[timeEventCount].ticks = ticks; + pendingTimerEvents[timeEventCount].origTicks = ticks; + timeEventCount++; + + return ret; + } +} + +int Get_Remaing_Timer_Ticks(int id) +{ + int i; + + KASSERT(!Interrupts_Enabled()); + for (i=0; i < timeEventCount; i++) { + if (pendingTimerEvents[i].id == id) { + return pendingTimerEvents[i].ticks; + } + } + + return -1; +} + +int Cancel_Timer(int id) +{ + int i; + KASSERT(!Interrupts_Enabled()); + for (i=0; i < timeEventCount; i++) { + if (pendingTimerEvents[i].id == id) { + pendingTimerEvents[i] = pendingTimerEvents[timeEventCount-1]; + timeEventCount--; + return 0; + } + } + + Print("timer: unable to find timer id %d to cancel it\n", id); + return -1; +} + + #define US_PER_TICK (HZ * 1000000) /* diff --git a/palacios/src/palacios/svm.c b/palacios/src/palacios/svm.c index 9d6fdab..584bf2c 100644 --- a/palacios/src/palacios/svm.c +++ b/palacios/src/palacios/svm.c @@ -269,8 +269,9 @@ static int init_svm_guest(struct guest_info *info) { } + // can we start a kernel thread here... -static int start_svm_guest(struct guest_info *info) { + int start_svm_guest(struct guest_info *info) { vmcb_saved_state_t * guest_state = GET_VMCB_SAVE_STATE_AREA((vmcb_t*)(info->vmm_data)); vmcb_ctrl_t * guest_ctrl = GET_VMCB_CTRL_AREA((vmcb_t*)(info->vmm_data)); uint_t num_exits = 0; @@ -351,6 +352,7 @@ static int start_svm_guest(struct guest_info *info) { + /* Checks machine SVM capability */ /* Implemented from: AMD Arch Manual 3, sect 15.4 */ int is_svm_capable() { diff --git a/palacios/src/palacios/svm_handler.c b/palacios/src/palacios/svm_handler.c index ad4fe4c..ef33407 100644 --- a/palacios/src/palacios/svm_handler.c +++ b/palacios/src/palacios/svm_handler.c @@ -258,6 +258,21 @@ int handle_svm_exit(struct guest_info * info) { return -1; } } else { + /* + ulong_t tsc_spread = 0; + ullong_t exit_tsc = 0; + + ulong_t rax = (ulong_t)info->vm_regs.rbx; + ulong_t rdx = (ulong_t)info->vm_regs.rcx; + + *(ulong_t *)(&exit_tsc) = rax; + *(((ulong_t *)(&exit_tsc)) + 1) = rdx; + + tsc_spread = info->exit_tsc - exit_tsc; + + PrintError("VMMCALL tsc diff = %lu\n",tsc_spread); + info->rip += 3; + */ PrintError("VMMCALL with not emulator...\n"); return -1; } diff --git a/palacios/src/palacios/vmm_config.c b/palacios/src/palacios/vmm_config.c index 5ef7461..03df326 100644 --- a/palacios/src/palacios/vmm_config.c +++ b/palacios/src/palacios/vmm_config.c @@ -33,6 +33,24 @@ static int passthrough_mem_write(addr_t guest_addr, void * src, uint_t length, v } +/*static int IO_Read(ushort_t port, void * dst, uint_t length, void * priv_data) { + + struct guest_info * info = priv_data; + ulong_t tsc_spread = 0; + ullong_t exit_tsc = 0; + + + *(ulong_t *)(&exit_tsc) = info->vm_regs.rbx; + *(ulong_t *)((&exit_tsc) + 4) = info->vm_regs.rcx; + tsc_spread = info->exit_tsc - exit_tsc; + + PrintError("IOREAD tsc diff = %lu\n",tsc_spread); + info->rip += 3; + + + return 1; +} +*/ int config_guest(struct guest_info * info, void * config_ptr) { @@ -295,6 +313,8 @@ int config_guest(struct guest_info * info, void * config_ptr) { #endif + //v3_hook_io_port(info, 1234, &IO_Read, NULL, info); + info->rip = 0xfff0; info->vm_regs.rsp = 0x0; @@ -357,6 +377,8 @@ int config_guest(struct guest_info * info, void * config_ptr) { v3_hook_io_port(&vm_info, 0x61, &IO_Read, &IO_Write, NULL); v3_hook_io_port(&vm_info, 0x05, &IO_Read, &IO_Write_to_Serial, NULL); + + /* vm_info.cr0 = 0; vm_info.cs.base=0xf000; diff --git a/palacios/src/palacios/vmm_intr.c b/palacios/src/palacios/vmm_intr.c index ebe9d12..1029dcc 100644 --- a/palacios/src/palacios/vmm_intr.c +++ b/palacios/src/palacios/vmm_intr.c @@ -6,9 +6,6 @@ #ifndef DEBUG_INTERRUPTS #undef PrintDebug #define PrintDebug(fmt, args...) -#else -#undef PrintDebug -#define PrintDebug(fmt, args...) PrintTrace("\nvmm_intr.c(%d) "_f, __LINE__, ## _a) #endif