diff --git a/.gitignore b/.gitignore index 2b5e79dd..56762699 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,8 @@ newlib/examples/hello newlib/examples/echo newlib/examples/tests newlib/examples/jacobi +newlib/examples/server +newlib/examples/client newlib/tmp/* newlib/x86/* metalsvm.elf diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h index 91f30387..da3b3556 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -42,9 +42,9 @@ extern "C" { // feature list 1 #define CPU_FEATURE_FPU (1 << 0) #define CPU_FEATURE_MMX (1 << 23) -#define CPU_FEATURE_FXSR (1 << 24) +#define CPU_FEATURE_FXSR (1 << 24) #define CPU_FEATURE_SSE (1 << 25) -#define CPU_FEATURE_SSE2 (1 << 26) +#define CPU_FEATURE_SSE2 (1 << 26) // feature list 2 #define CPU_FEATURE_AVX (1 << 28) diff --git a/arch/x86/include/asm/syscall.h b/arch/x86/include/asm/syscall.h index 13285ed2..17aa1abf 100644 --- a/arch/x86/include/asm/syscall.h +++ b/arch/x86/include/asm/syscall.h @@ -1,20 +1,36 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * This file is part of MetalSVM. + * This file is part of MetalSVM. */ /** diff --git a/arch/x86/include/asm/tasks.h b/arch/x86/include/asm/tasks.h index c12f946a..d2cf6731 100644 --- a/arch/x86/include/asm/tasks.h +++ b/arch/x86/include/asm/tasks.h @@ -36,6 +36,11 @@ extern "C" { #endif +/** + * @brief Dump some scheduling statistics + */ +int dump_scheduling_statistics(void); + /** @brief Fork a task from current task * * @param task Pointer to the task structure to fork to diff --git a/arch/x86/kernel/apic.c b/arch/x86/kernel/apic.c index a916222c..379a181b 100644 --- a/arch/x86/kernel/apic.c +++ b/arch/x86/kernel/apic.c @@ -301,9 +301,6 @@ void smp_start(uint32_t id) // install IDT idt_install(); - // enable additional cpu features - cpu_detection(); - /* enable paging */ write_cr3((uint32_t)get_boot_pgd()); i = read_cr0(); @@ -320,6 +317,9 @@ void smp_start(uint32_t id) */ register_task(per_core(current_task)); + // enable additional cpu features + cpu_detection(); + smp_main(); // idle loop @@ -327,15 +327,18 @@ void smp_start(uint32_t id) } #endif -#ifndef CONFIG_MULTIBOOT +#if 1 static apic_mp_t* search_apic(size_t base, size_t limit) { size_t ptr; + apic_mp_t* tmp; for (ptr=base; ptr<=limit-sizeof(uint32_t); ptr++) { - if (*((uint32_t*) ptr) == MP_FLT_SIGNATURE) { - if (!(((apic_mp_t*)ptr)->version > 4) && ((apic_mp_t*)ptr)->features[0]) - return (apic_mp_t*) ptr; - } + tmp = (apic_mp_t*) ptr; + + if (tmp->signature == MP_FLT_SIGNATURE) { + if (!((tmp->version > 4) || tmp->features[0])) + return tmp; + } } return NULL; @@ -561,7 +564,7 @@ static int apic_probe(void) uint32_t i, count; int isa_bus = -1; -#ifndef CONFIG_MULTIBOOT +#if 1 apic_mp = search_apic(0xF0000, 0x100000); if (apic_mp) goto found_mp; @@ -590,7 +593,7 @@ static int apic_probe(void) for(i=0; (ilen-sizeof(uint32_t)) && (addr < 0x0FFFFF); i++, addr++) { if (*((uint32_t*) addr) == MP_FLT_SIGNATURE) { apic_mp = (apic_mp_t*) addr; - if (!(apic_mp->version > 4) && apic_mp->features[0]) + if (!((apic_mp->version > 4) || apic_mp->features[0])) goto found_mp; } } diff --git a/arch/x86/kernel/gdt.c b/arch/x86/kernel/gdt.c index 9441410a..f6667c60 100644 --- a/arch/x86/kernel/gdt.c +++ b/arch/x86/kernel/gdt.c @@ -116,9 +116,8 @@ int arch_fork(task_t* task) asm volatile ("pop %0" : "=r"(task_state_segments[id].ecx)); asm volatile ("pop %0" : "=r"(task_state_segments[id].eax)); - // store current EFLAGS and set IF flag - // => the parent task will enable the interrupt handling - asm volatile ("pushf; pop %%eax; or $2,%%ah" : "=a"(task_state_segments[id].eflags)); + // store the current EFLAGS + asm volatile ("pushf; pop %%eax" : "=a"(task_state_segments[id].eflags)); // This will be the entry point for the new task. asm volatile ("call read_eip" : "=a"(task_state_segments[id].eip)); @@ -146,7 +145,7 @@ int create_default_frame(task_t* task, internal_entry_point_t ep, void* arg) task_state_segments[id].fs = ds; task_state_segments[id].gs = ds; task_state_segments[id].es = ds; - task_state_segments[id].eflags = 0x1202; + task_state_segments[id].eflags = 0x1002; // 0x1202; task_state_segments[id].cr3 = (uint32_t) (virt_to_phys((size_t)task->pgd)); task_state_segments[id].eip = (uint32_t) ep; task_state_segments[id].esp = (uint32_t) kstacks[id] + KERNEL_STACK_SIZE - sizeof(size_t); diff --git a/arch/x86/kernel/timer.c b/arch/x86/kernel/timer.c index 251f71f8..8a806eb6 100644 --- a/arch/x86/kernel/timer.c +++ b/arch/x86/kernel/timer.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -33,7 +34,7 @@ * This will keep track of how many ticks the system * has been running for */ -static volatile uint64_t timer_ticks __attribute__ ((aligned (CACHE_LINE))) = 0; +static volatile uint64_t timer_ticks = 0; uint64_t get_clock_tick(void) { @@ -60,40 +61,60 @@ int sys_times(struct tms* buffer, clock_t* clock) */ static void timer_handler(struct state *s) { + uint32_t i; + /* Increment our 'tick counter' */ #if MAX_CORES > 1 if (smp_id() == 0) - timer_ticks++; -#else - timer_ticks++; #endif + { + timer_ticks++; - /* - * Every TIMER_FREQ clocks (approximately 1 second), we will - * display a message on the screen - */ - /*if (timer_ticks % TIMER_FREQ == 0) { - vga_puts("One second has passed\n"); - }*/ + /* + * Every TIMER_FREQ clocks (approximately 1 second), we will + * display a message on the screen + */ + /*if (timer_ticks % TIMER_FREQ == 0) { + vga_puts("One second has passed\n"); + }*/ + } } -/* - * This will continuously loop until the given time has - * been reached - */ -void timer_wait(unsigned int ticks) +int timer_wait(unsigned int ticks) { uint64_t eticks = timer_ticks + ticks; + task_t* curr_task = per_core(current_task); - while (timer_ticks < eticks) { + if (curr_task->status == TASK_IDLE) + { + /* + * This will continuously loop until the given time has + * been reached + */ + while (timer_ticks < eticks) { + check_workqueues(); + + // recheck break condition + if (timer_ticks >= eticks) + break; + + HALT; + } + } else if (timer_ticks < eticks) { check_workqueues(); - // recheck break condition - if (timer_ticks >= eticks) - break; + if (timer_ticks < eticks) { + uint32_t flags = irq_nested_disable(); + curr_task->timeout = eticks; + curr_task->flags |= TASK_TIMER_USED; + curr_task->status = TASK_BLOCKED; + irq_nested_enable(flags); - reschedule(); + reschedule(); + } } + + return 0; } #define LATCH(f) ((CLOCK_TICK_RATE + f/2) / f) diff --git a/arch/x86/mm/page.c b/arch/x86/mm/page.c index aa952edf..6eadd3d1 100644 --- a/arch/x86/mm/page.c +++ b/arch/x86/mm/page.c @@ -730,12 +730,6 @@ int arch_paging_init(void) // map SCC's bootinfo map_region(SCC_BOOTINFO, SCC_BOOTINFO, 1, MAP_KERNEL_SPACE); - // map the initial ramdisk - npages = bootinfo->size >> PAGE_SHIFT; - if (bootinfo->size & (PAGE_SIZE-1)) - npages++; - map_region(bootinfo->addr, bootinfo->addr, npages, MAP_KERNEL_SPACE); - // map SCC's configuration registers viraddr = map_region(CRB_X0_Y0, CRB_X0_Y0, (CRB_OWN-CRB_X0_Y0+16*1024*1024) >> PAGE_SHIFT, MAP_KERNEL_SPACE|MAP_NO_CACHE); kprintf("Map configuration registers at 0x%x\n", viraddr); @@ -756,6 +750,15 @@ int arch_paging_init(void) write_cr0(i); paging_enabled = 1; +#ifdef CONFIG_ROCKCREEK + // map the initial ramdisk + npages = bootinfo->size >> PAGE_SHIFT; + if (bootinfo->size & (PAGE_SIZE-1)) + npages++; + bootinfo->addr = map_region(0, bootinfo->addr, npages, MAP_KERNEL_SPACE); + kprintf("Map initrd at 0x%x (size %u bytes)\n", bootinfo->addr, bootinfo->size); +#endif + /* * we turned on paging * => now, we are able to register our task for Task State Switching diff --git a/drivers/net/mmnif.c b/drivers/net/mmnif.c index d2dbdece..6d805772 100644 --- a/drivers/net/mmnif.c +++ b/drivers/net/mmnif.c @@ -1,72 +1,52 @@ -/* - * Copyright 2011 Carl-Benedikt Krueger, Chair for Operating Systems, - * RWTH Aachen University - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * This file is part of MetalSVM. - */ - /* * mmnif.c --- memmory mapped interface * * Virutal IP Interface for the concept processor SCC * - * Carl-Benedikt Krueger 2011 + * virutally tested under Windows 7 * + * Carl-Benedikt Krüger 2011 + * + * + * EXPERIMENTAL VERSION */ + #include "mmnif.h" /* definitions */ -#ifdef WIN32 -#include "mailbox.h" /* mailbox_ptr_t */ -#else -#include /* mailbox_ptr_t */ -#endif - -#if defined(CONFIG_LWIP) && defined(CONFIG_ROCKCREEK) - #include /* lwip netif */ #include /* inteface stats */ #include /* ethernet arp packets */ #include /* struct iphdr*/ #include /* tcpip_input()*/ - -//#define DEBUG_MMNIF - -#ifdef DEBUG_MMNIF -#include "util.h" /* hex dump */ -#endif +#if defined(CONFIG_LWIP) && defined(CONFIG_ROCKCREEK) #ifdef WIN32 + +#define kmalloc malloc +#define kfree(x,y) free(x) +#define RCCE_shfree(x) VirtualFree(x,NULL,NULL); +#define RCCE_shmalloc(x) VirtualAlloc((char*)0x41000000,x,MEM_COMMIT|MEM_RESERVE,PAGE_READWRITE); +#include "mailbox.h" /* mailbox_ptr_t */ #define WIN32_LEAN_AND_MEAN #include #include - typedef bthread_sem_t sem_t; typedef bthread_t tid_t; - /* "interrupt" of the other virutal network card*/ extern HANDLE remote_process_event; +extern HANDLE remote_process_mutex; +extern HANDLE own_process_mutex; /* HANDLE to the other Process (for WPM and RPM)*/ extern HANDLE hProc; - - #define DEBUGPRINTF(x,...) printf(x,__VA_ARGS__) + #else -#define DEBUGPRINTF(x,...) kprintf(x,##__VA_ARGS__) + +#include /* mailbox_ptr_t */ #include +#include #include #include @@ -77,18 +57,39 @@ extern HANDLE hProc; #include +#define DEBUGPRINTF(x,...) kprintf(x,##__VA_ARGS__) #endif -#define MMNIF_TX_QUEUELEN 4 -#define MMNIF_RX_QUEUELEN 8 -#define MMNIF_RX_BUFFERLEN 1792 + +#define DEBUG_MMNIF +//#define DEBUG_MMNIF_PACKET + +#ifdef DEBUG_MMNIF +#include "util.h" /* hex dump */ +#endif + +/* define constants + * regarding the driver & its configuration + */ + #define MMNIF_TX_BUFFERLEN 1792 +#define MMNIF_TX_QUEUELEN 4 -#define MMNIF_CORES 2 +#define MMNIF_RX_BUFFERLEN 8192 +#define MMNIF_MAX_DESCRIPTORS 32 + +#define MMNIF_CORES 48 + +#define MMNIF_POLL_BUDGET 0x100000 + +#define MMNIF_STATUS_FREE 0x00 +#define MMNIF_STATUS_PENDING 0x01 +#define MMNIF_STATUS_RDY 0x02 +#define MMNIF_STATUS_INPROC 0x03 +#define MMNIF_STATUS_PROC 0x04 -#define MMNIF_WORKER_BUDGET 5 /* decide whether it's polling mode or not */ @@ -102,6 +103,10 @@ static int active = 0; */ static int disable_locking = 0; +/* decide whether deliver work to a worker thread or instantly process all packets + */ +static int instant_process = 1; + /* IP address of the local core and the router core to get packets forwarded */ static unsigned int own_ip_address = 0xC0A80000; /* 192.168.0.0 */ @@ -112,29 +117,9 @@ static unsigned int router_ip_address = 0xC0A80001; /* 192.168.0.1 */ * - start address * - size */ -char* mpb_start_address = NULL; +char* mpb_start_address = NULL; unsigned int mpb_size = NULL; - -/* Register offset for the CONFIG and LOCK registers */ -#define RCK_GLCFG0 0x10 -#define RCK_GLCFG1 0x18 -#define RCK_TILEID 0x100 - -#define RCK_TILE_SIZE 0x01000000 - -/* Start address of the local register bank */ -static int local_crb = 0xF8000000; - -/* just set and reset the irq */ -static int pulse_irq = 0; - -/* Mask of the interrupt bits */ -#define RCK_INTR_MASK 0x00000002 -#define RCK_NMI_MASK 0x00000001 - - - /* * the memory mapped network device */ @@ -149,8 +134,10 @@ typedef struct mmnif_device_stats /* device stats (granularity in packets): * - recieve errors * - recieve successes + * - recieved bytes * - transmit errors * - transmit successes + * - transmitted bytes */ unsigned int rx_err; unsigned int rx; @@ -163,7 +150,10 @@ typedef struct mmnif_device_stats unsigned int tx_bytes; /* Heuristics : - * + * - how many times an budget overflow occured + * - how many times the polling thread polled without recieving a new message + * - how many messages are recieved via interrupt + * - how many messages are recieved via the polling thread */ unsigned int bdg_overflow; unsigned int pll_empty; @@ -172,275 +162,119 @@ typedef struct mmnif_device_stats } mmnif_device_stats_t; +/* receive descror structure */ +typedef struct rx_desc +{ + uint8_t stat; + uint16_t len; + uint32_t addr; + +} rx_desc_t; + +/* receive ring buffer structure */ typedef struct mm_rx_buffer { - /* memory rx buffer build - * - queued : how many packets are in the queue - * - pos : which is the next packet to be worked on - * - pending : how many packets are pending - * - iv_intr : inform via interrupt or not - * - lock: semaphore to lock the local variables to be multi access save - * - * Note: this section will soon be complexer. - * I won't use a single buffer the whole time. I think i will use an descripor table - * and a table which descriptor is in use and use the buffer space dynamically with - * descriptors - * - * And this buffer needs a lock as soon as more as cores are availible =/ + /* iv_intr: inform via interrupt + * states whether the interface wants to recieve an interrupt for + * incoming packet + */ + uint16_t iv_intr; + /* memory "pseudo-ring/heap" + * packets are always in one single chunk of memory + * head : head of allocated memory region + * tail : tail of allocated memory region */ - uint8_t queued; - uint8_t pos; - uint8_t pending; - - uint8_t iv_intr; - - sem_t lock; - -// void* rx_desc[MMNIF_CORES * MMNIF_RX_QUEUELEN]; -// uint8_t rx_inuse[MMNIF_CORES * MMNIF_RX_QUEUELEN]; /* bits 1: pending 2: finished 3: free ...*/ -// uint8_t fin; -// uint8_t* data[MMNIF_RX_QUEUELEN]; + uint16_t head; + uint16_t tail; + spinlock_t rlock; + /* descritpor queue + * desc_table : descriptor table + * dcount : descriptor's free in queue + * dread : next descriptor to read + * dwrite : next descriptor to write + * dlock : lock to protect these members + */ + rx_desc_t desc_table[MMNIF_MAX_DESCRIPTORS]; + uint8_t dcount; + uint8_t dread; + uint8_t dwrite; + spinlock_t dlock; } mm_rx_buffer_t; typedef struct mmnif { - struct mmnif_device_stats stats; + struct mmnif_device_stats stats; /* Interface constants: * - ehternet address - * - local ip address + * - local ip address */ - struct eth_addr* ethaddr; - uint32_t ipaddr; + struct eth_addr* ethaddr; + uint32_t ipaddr; /* memory interaction variables: * - transmit queue * - pointer to transmit buffer * - pointer to recive buffer */ - uint8_t tx_queue; - uint8_t* tx_buff[MMNIF_TX_QUEUELEN]; - mm_rx_buffer_t* rx_buff; + uint8_t tx_queue; + uint8_t* tx_buff[MMNIF_TX_QUEUELEN]; + mm_rx_buffer_t* rx_buff; - sem_t com_poll; + /* lock to protect members + */ + spinlock_t lock; + + /* + */ + sem_t com_poll; - /* comunication mailbox - */ - mailbox_ptr_t mbox; }mmnif_t; #ifdef WIN32 - -__inline int RCCE_ue(void) -{ +__inline int RCCE_ue(void){ #ifndef RECV - return 1; + return 1; #else - return 0; + return 0; #endif } - #endif /* * memory maped interface helper functions */ +#ifdef WIN32 +#define __MEMCPY(x,y,z) memcpy(x,y,z) +#else +#define __MEMCPY(x,y,z) memcpy(x,y,z) +#endif -/* read the queue value from the remote buffer - * and return it. +/* mmnif_device_schedule() : + * if there is no interupt used to indicate new packets + * this creates a polling thread which looks for data + * itself */ -__inline uint8_t mmnif_read_rx_queue(uint32_t dest_ip) +__inline int mmnif_device_schedule() { #ifdef WIN32 - /* Read the value of the forgein process - * form rx_buff->queued - */ - mm_rx_buffer_t hdr; - while(!ReadProcessMemory(hProc,(char*)mpb_start_address + ( dest_ip -1 ) * mpb_size,&hdr,sizeof(hdr),NULL)); - return hdr.queued; + bthread_create(&polling_thread,NULL,mmnif_poll,NULL); + return NULL; #else - mm_rx_buffer_t hdr; - memcpy(&hdr,(char*)mpb_start_address + ( dest_ip -1 ) * mpb_size,sizeof(hdr)); - return hdr.queued; + create_kernel_task(&polling_thread,mmnif_poll,NULL); + return NULL; #endif -}; - -/* read the pos value from the remote buffer - * and return it. - */ -__inline uint8_t mmnif_read_rx_pos(uint32_t dest_ip) -{ -#ifdef WIN32 - /* Read the value of the forgein process - * form rx_buff->pos - */ - mm_rx_buffer_t hdr; - while(!ReadProcessMemory(hProc,(char*)mpb_start_address + ( dest_ip -1 ) * mpb_size,&hdr,sizeof(hdr),NULL)); - return hdr.pos; -#else - mm_rx_buffer_t hdr; - memcpy(&hdr,(char*)mpb_start_address + ( dest_ip -1 ) * mpb_size,sizeof(hdr)); - return hdr.pos; -#endif -}; - -/* read the inv_intr from the remote buffer - * and return it. - */ -__inline uint8_t mmnif_read_rx_inv_intr(uint32_t dest_ip) -{ -#ifdef WIN32 - /* Read the value of the forgein process - * form rx_buff->inv_intr - */ - mm_rx_buffer_t hdr; - while(!ReadProcessMemory(hProc,(char*)mpb_start_address + ( dest_ip -1 ) * mpb_size,&hdr,sizeof(hdr),NULL)); - return hdr.iv_intr; -#else - mm_rx_buffer_t hdr; - memcpy(&hdr,(char*)mpb_start_address + ( dest_ip -1 ) * mpb_size,sizeof(hdr)); - return hdr.iv_intr; -#endif -}; - -/* read the pending value from the remote buffer - * and return it. - */ -__inline uint8_t mmnif_read_rx_pending(uint32_t dest_ip) -{ -#ifdef WIN32 - /* Read the value of the forgein process - * form rx_buff->pending - */ - mm_rx_buffer_t hdr; - while(!ReadProcessMemory(hProc,(char*)mpb_start_address + ( dest_ip -1 ) * mpb_size,&hdr,sizeof(hdr),NULL)); - return hdr.pending; -#else - mm_rx_buffer_t hdr; - memcpy(&hdr,(char*)mpb_start_address + ( dest_ip -1 ) * mpb_size,sizeof(hdr)); - return hdr.pending; -#endif -}; - -/* write data to the remote buffer - * - */ -__inline int mmnif_write_rx_buff(uint32_t dest_ip, uint32_t pos,void* data) -{ -#ifdef WIN32 - /* we assume this is a correct buffer - * therefore here is no further error checking - */ - uint32_t nr_of_bytes_written = 0; - uint16_t length = *((uint16_t*)data); - while(!WriteProcessMemory(hProc,(char*)mpb_start_address +(dest_ip -1 ) * mpb_size + sizeof(mm_rx_buffer_t)+ pos * MMNIF_RX_BUFFERLEN,data,length+2,&nr_of_bytes_written)); - return nr_of_bytes_written; -#else - uint16_t length = *((uint16_t*)data); - memcpy((char*)mpb_start_address +(dest_ip -1 ) * mpb_size + sizeof(mm_rx_buffer_t)+ pos * MMNIF_RX_BUFFERLEN,data,length+2); - return 1; -#endif -}; - -__inline int mmnif_write_rx_buffl(uint32_t dest_ip, uint32_t pos,void* data,uint16_t length) -{ -#ifdef WIN32 - /* we assume this is a correct buffer - * therefore here is no further error checking - */ - uint32_t nr_of_bytes_written = 0; - while(!WriteProcessMemory(hProc,(char*)mpb_start_address +(dest_ip -1 ) * mpb_size + sizeof(mm_rx_buffer_t)+ pos * MMNIF_RX_BUFFERLEN,&length,2,&nr_of_bytes_written)); - while(!WriteProcessMemory(hProc,(char*)mpb_start_address +(dest_ip -1 ) * mpb_size + sizeof(mm_rx_buffer_t)+ pos * MMNIF_RX_BUFFERLEN + 2,data,length,&nr_of_bytes_written)); - return nr_of_bytes_written+2; -#else -// uint16_t length = *((uint16_t*)data); - memcpy((char*)mpb_start_address +(dest_ip -1 ) * mpb_size + sizeof(mm_rx_buffer_t)+ pos * MMNIF_RX_BUFFERLEN,&length,2); - memcpy((char*)mpb_start_address +(dest_ip -1 ) * mpb_size + sizeof(mm_rx_buffer_t)+ pos * MMNIF_RX_BUFFERLEN + 2,data,length); - return 1; -#endif -}; - -/* write the new queue value to the remote buffer - * - */ -__inline int mmnif_write_rx_queue(uint32_t dest_ip,uint8_t queue) -{ - /* tell the remote buffer/process - * that there is another packet in the queue - */ -#ifdef WIN32 - uint32_t nr_of_bytes_written = 0; - while(!WriteProcessMemory(hProc,(char*)mpb_start_address + ( dest_ip -1 ) * mpb_size ,&queue,1,&nr_of_bytes_written)); - return nr_of_bytes_written; -#else - - memcpy((char*)mpb_start_address + ( dest_ip -1 ) * mpb_size ,&queue,1); - - return 1; -#endif -}; - -/* write the new queue value to the remote buffer - * - */ -__inline int mmnif_write_rx_pending(uint32_t dest_ip,uint8_t pending) -{ - /* tell the remote buffer/process - * that there is another packet in the queue - */ -#ifdef WIN32 - uint32_t nr_of_bytes_written = 0; - while(!WriteProcessMemory(hProc,(char*)mpb_start_address + ( dest_ip -1 ) * mpb_size + 2 ,&pending,1,&nr_of_bytes_written)); - return nr_of_bytes_written; -#else - - memcpy((char*)mpb_start_address + ( dest_ip -1 ) * mpb_size + 2 , &pending,1); - - return 1; -#endif -}; +} /* trigger an interrupt on the remote processor - * + * so he knows there is a packet to read */ __inline int mmnif_trigger_irq(dest_ip) { #ifdef WIN32 - return PulseEvent(remote_process_event); + return SetEvent(remote_process_event); #else -#if 0 - /* NOTE: have to check how the remote interrupt managment works - * on the SCC - */ - mmnif_t* mmnif = mmnif_dev->state; - int core = (dest_ip - 1) % 2; - int irq_address = mmnif->crb[dest_ip-1]; - unsigned int value; - - if (core == 0) irq_address += RCK_GLCFG0; - else irq_address += RCK_GLCFG1; - - /**/ - value = ReadConfigReg((void*)irq_address); - - if ((!pulse_irq) && (value & RCK_INTR_MASK)) - { - value &= (~(RCK_INTR_MASK|RCK_NMI_MASK)); - SetConfigReg((void*)irq_address,value); - } - - value |= RCK_INTR_MASK; - SetConfigReg((void*) irq_address,value); - - /**/ - if (pulse_irq) - { - value &= (~(RCK_INTR_MASK|RCK_NMI_MASK)); - SetConfigReg((void*)irq_address,value); - } -#endif - int tmp, x, y, z, addr; int ue = dest_ip -1; @@ -460,123 +294,12 @@ __inline int mmnif_trigger_irq(dest_ip) return 0; #endif -}; - -/* mmnif_device_schedule() : - * if there is no interupt used to indicate new packets - * this creates a polling thread which looks for data - * itself - */ -__inline int mmnif_device_schedule() -{ -#ifdef WIN32 - bthread_create(&polling_thread,NULL,mmnif_poll,NULL); - return NULL; -#else - create_kernel_task(&polling_thread,mmnif_poll,NULL); - return NULL; -#endif } -/* mmnif_worker_schedule() : - * if there is no interupt used to indicate new packets - * this creates a polling thread which looks for data - * itself - */ -__inline int mmnif_worker_schedule() -{ -#ifdef WIN32 - bthread_create(&worker_thread,NULL,mmnif_worker,NULL); - return NULL; -#else - create_kernel_task(&worker_thread,mmnif_worker,NULL); - return NULL; -#endif -} -/* Allocate Shared Memory for communication this could be: - * - in Message Passing Buffer - * - Shared Memory Address Space (0x8000000 + ) - * - * Note: under windows this is kernel space so we take arbitrary 0x41000000 here - */ -__inline void* mmnif_shmalloc() -{ - /* Right now every core has the same buffer for every incoming packet - * this will be removed and a buffer for each Core will be implemented - * - * but i'm first testing with two cores/processes. - */ -#ifdef WIN32 - mpb_size = sizeof(mm_rx_buffer_t) + MMNIF_RX_QUEUELEN* MMNIF_RX_BUFFERLEN; - mpb_start_address = VirtualAlloc((char*)0x41000000 /*+ - (mpb_size) * (own_ip_address - router_ip_address)*/, - mpb_size *MMNIF_CORES,MEM_COMMIT|MEM_RESERVE,PAGE_READWRITE); - - return (char*)0x41000000 + (mpb_size) * (own_ip_address - router_ip_address); -#else - mpb_size = (sizeof(mm_rx_buffer_t) + MMNIF_RX_QUEUELEN* MMNIF_RX_BUFFERLEN); - /* We choose a arbitrary address first - * until i know how to properly allocate shared memory - */ -// RCCE_shmalloc_init(0x80000000,48*8192); - mpb_start_address = RCCE_shmalloc(mpb_size*MMNIF_CORES); - //mpb_start_address = 0x8000000+ mpb_size * (own_ip_address - router_ip_address); - //SHMalloc(&mpb_start_address); - //mpb_start_address = kmalloc(mpb_size*MMNIF_CORES); -// mpb_start_address = 0xC0000000; - return mpb_start_address + (mpb_size) * (own_ip_address - router_ip_address); -#endif -} - -/* mmnif_lock_rx_hdr(): lock the header of mm_rx_buffer - * so there is no race condition on the variables - */ -__inline void mmnif_lock_rx_hdr(int dest_ip) -{ -#ifdef WIN32 - mm_rx_buffer_t hdr; - if(disable_locking) return; - while(!ReadProcessMemory(hProc,(char*)mpb_start_address + ( dest_ip -1 ) * mpb_size,&hdr,sizeof(hdr),NULL)); - sem_wait(&hdr.lock); -#else - if(disable_locking) return; - mm_rx_buffer_t* hdr = (char*)mpb_start_address + ( dest_ip -1 ) * mpb_size; - sem_wait(&hdr->lock); -#endif -} -/* mmnif_unlock_rx_hdr(): unlock the header - * again - */ -__inline void mmnif_unlock_rx_hdr(int dest_ip) -{ -#ifdef WIN32 - mm_rx_buffer_t hdr; - if(disable_locking) return; - while(!ReadProcessMemory(hProc,(char*)mpb_start_address + ( dest_ip -1 ) * mpb_size,&hdr,sizeof(hdr),NULL)); - sem_post(&hdr.lock); -#else - if(disable_locking) return; - mm_rx_buffer_t* hdr = (char*)mpb_start_address + ( dest_ip -1 ) * mpb_size; - sem_post(&hdr->lock); -#endif -} - -/* mmnif_timestamp(): genereate a timestamp for the - * packets - */ -__inline int mmnif_timestamp() -{ -#ifdef WIN32 - return GetTickCount(); -#else - return get_clock_tick(); -#endif -} - /* mmnif_get_device_stats(): Returns a copy of the * current device */ -mmnif_device_stats_t mmnif_get_device_stats() +mmnif_device_stats_t mmnif_get_device_stats(void) { mmnif_device_stats_t stats = {0}; @@ -588,11 +311,10 @@ mmnif_device_stats_t mmnif_get_device_stats() return stats; } - /* mmnif_print_stats(): Print the devices stats of the * current device */ -void mmnif_print_stats() +void mmnif_print_stats(void) { mmnif_t* mmnif; @@ -634,7 +356,6 @@ uint8_t mmnif_get_destination(struct netif* netif, struct pbuf* p) uint8_t addr[4]; uint32_t netmask = 0xFFFFFF00; - /* grab the destination ip address out of the ip header * for internal routing the last ocet is interpreted as core ID. */ @@ -655,8 +376,6 @@ uint8_t mmnif_get_destination(struct netif* netif, struct pbuf* p) if (!((netmask & *(uint32_t*)addr) == (netmask & own_ip_address) )) return 1; - - core = addr[0]; /* check if the address is legitimata else return router core again */ @@ -664,47 +383,217 @@ uint8_t mmnif_get_destination(struct netif* netif, struct pbuf* p) core = 1; return core; - } +/* mmnif_rxbuff_alloc(): + * this function allocates a continues chunk of memory + * right inside of the buffer which is used for communication + * with the remote end + */ +uint32_t mmnif_rxbuff_alloc(uint8_t dest,uint16_t len) +{ + mm_rx_buffer_t* rb = (mm_rx_buffer_t*)((char*)mpb_start_address + ( dest -1 ) * mpb_size); + char* memblock = (char*)rb + sizeof(mm_rx_buffer_t); + + uint32_t ret; + + spinlock_lock(&rb->dlock); + + if (rb->dcount) + { + if (rb->tail > rb->head) + { + if (MMNIF_RX_BUFFERLEN - rb->tail > len) + { + rb->desc_table[rb->dwrite].stat = MMNIF_STATUS_PENDING; + ret = memblock + rb->tail; + rb->desc_table[rb->dwrite].addr = ret; + rb->desc_table[rb->dwrite].len = len; + rb->dcount--; + rb->dwrite = (++rb->dwrite)%MMNIF_MAX_DESCRIPTORS; + + rb->tail = (rb->tail + len); + spinlock_unlock(&rb->dlock); + return ret; + } + else if (rb->head > len) + { + rb->desc_table[rb->dwrite].stat = MMNIF_STATUS_PENDING; + ret = memblock; + rb->desc_table[rb->dwrite].addr = ret; + rb->desc_table[rb->dwrite].len = len; + rb->dcount--; + rb->dwrite = (++rb->dwrite)%MMNIF_MAX_DESCRIPTORS; + + rb->tail = len; + spinlock_unlock(&rb->dlock); + return ret; + } + else + { + spinlock_unlock(&rb->dlock); + return NULL; + } + } + else + { + if (rb->head - rb->tail > len) + { + rb->desc_table[rb->dwrite].stat = MMNIF_STATUS_PENDING; + ret = memblock + rb->tail; + rb->desc_table[rb->dwrite].addr = ret; + rb->desc_table[rb->dwrite].len = len; + rb->dcount--; + rb->dwrite = (++rb->dwrite)%MMNIF_MAX_DESCRIPTORS; + + rb->tail = (rb->tail + len); + spinlock_unlock(&rb->dlock); + return ret; + } + else if (rb->tail == rb->head) + { + if (MMNIF_RX_BUFFERLEN - rb->tail < len) + { + rb->tail = 0; + if (rb->dread == rb->dwrite) + rb->head = 0; + } + + rb->desc_table[rb->dwrite].stat = MMNIF_STATUS_PENDING; + ret = memblock + rb->tail; + rb->desc_table[rb->dwrite].addr = ret; + rb->desc_table[rb->dwrite].len = len; + rb->dcount--; + rb->dwrite = (++rb->dwrite)%MMNIF_MAX_DESCRIPTORS; + + rb->tail = (rb->tail + len); + spinlock_unlock(&rb->dlock); + return ret; + } + else + { + spinlock_unlock(&rb->dlock); + return NULL; + } + } + } + else + { + spinlock_unlock(&rb->dlock); + return NULL; + } +} + +/* mmnif_commit_packet: this function set the state of the (in advance) + * allocated packet to RDY so the recieve queue knows that it can be + * processed further + */ +int mmnif_commit_packet(uint8_t dest,uint32_t addr) +{ + mm_rx_buffer_t* rb = (mm_rx_buffer_t*)((char*)mpb_start_address + ( dest -1 ) * mpb_size); + uint32_t i; + + for (i = 0; i < MMNIF_MAX_DESCRIPTORS; i++) + { + if (rb->desc_table[i].addr == addr && rb->desc_table[i].stat == MMNIF_STATUS_PENDING) + { + rb->desc_table[i].stat = MMNIF_STATUS_RDY; + return 0; + } + } + return -1; +} + +/* mmnif_rxbuff_free() : the opposite to mmnif_rxbuff_alloc() a from the receiver + * already processed chunk of memory is freed so that it can be allocated again + */ +void mmnif_rxbuff_free(void) +{ + mmnif_t* mmnif = mmnif_dev->state; + mm_rx_buffer_t* b = mmnif->rx_buff; + uint32_t i,j; + uint32_t rpos; + + spinlock_lock(&b->dlock); + + rpos = b->dread; + + for (i = 0, j = rpos; i < MMNIF_MAX_DESCRIPTORS; i++) + { + j = (j+i)%MMNIF_MAX_DESCRIPTORS; + + if (b->desc_table[j].stat == MMNIF_STATUS_PROC) + { + b->dcount++; + b->dread = (b->dread +1)%MMNIF_MAX_DESCRIPTORS; + b->desc_table[j].stat = MMNIF_STATUS_FREE; + + if (b->tail > b->head) + { + b->head += b->desc_table[j].len; + } + else + { + if ( (b->desc_table[(j+1)%MMNIF_MAX_DESCRIPTORS].stat != MMNIF_STATUS_FREE ) + && ( b->desc_table[j].addr > b->desc_table[(j+1)%MMNIF_MAX_DESCRIPTORS].addr)) + { + b->head = 0; + + } + else + { + b->head += b->desc_table[j].len; + } + } + } + else + break; + } + + spinlock_unlock(&b->dlock); +} /* * Transmid a packet (called by the lwip) */ err_t mmnif_tx(struct netif* netif, struct pbuf* p) { - mmnif_t* mmnif = netif->state; - uint8_t slot = mmnif->tx_queue; - uint8_t queued; - uint8_t pos; - uint8_t pending; - uint32_t i; - struct pbuf* q; /* interator */ - uint8_t build_buff = TRUE; - uint8_t dest_intr = FALSE; - uint32_t dest_ip = mmnif_get_destination(netif,p); + mmnif_t* mmnif = netif->state; + uint8_t slot = mmnif->tx_queue; - /* take a place in the tx_queue */ + uint32_t write_address; + uint32_t i; + struct pbuf* q; /* interator */ + + uint8_t build_buff = TRUE; + uint32_t dest_ip = mmnif_get_destination(netif,p); + + mm_rx_buffer_t* rb = (mm_rx_buffer_t*)((char*)mpb_start_address + ( dest_ip -1 ) * mpb_size); + +#ifdef WIN32 + ReadProcessMemory(hProc, (char*)mpb_start_address + ( dest_ip -1 ) * mpb_size, (char*)mpb_start_address + ( dest_ip -1 ) * mpb_size,mpb_size,NULL); + WaitForSingleObject(remote_process_mutex,INFINITE); +#endif + + spinlock_lock(&mmnif->lock); mmnif->tx_queue++; + spinlock_unlock(&mmnif->lock); + /* Perform serveral sanity checks on the packet and the buffers: * - is the queue full? * - is the output packet to big? - * - * - * HINT: MMNIF_TX_QUEUELEN should be 1 as long there is no mutex availible to ensure - * just one thread is writing to pos and queue of the mm_rx_buff */ - if (mmnif->tx_queue >= MMNIF_TX_QUEUELEN) + if (mmnif->tx_queue > MMNIF_TX_QUEUELEN) { - DEBUGPRINTF("mmnif_tx(): too many packets at once for tx_queue\n"); - goto drop_packet; + DEBUGPRINTF("mmnif_tx(): too many packets at once for tx_queue\n"); + goto drop_packet; } if (p->tot_len > MMNIF_TX_BUFFERLEN) { - DEBUGPRINTF("mmnif_tx(): packet is longer than 1792 bytes\n"); - goto drop_packet; + DEBUGPRINTF("mmnif_tx(): packet is longer than %d bytes\n",MMNIF_TX_BUFFERLEN); + goto drop_packet; } /* check if the pbuf consists only of one element @@ -714,114 +603,82 @@ err_t mmnif_tx(struct netif* netif, struct pbuf* p) if (!p->next) build_buff = FALSE; - if (build_buff) { - /* write packet length to start transmit buffer */ - *((unsigned short*)mmnif->tx_buff[slot]) = p->tot_len; - /* build the payload out of the p's * ensure that the packet is in one memory chunk stored in the transmid buffer */ - for (q = p, i = 2; q != 0; q = q->next) + for (q = p, i = 0; q != 0; q = q->next) { memcpy(mmnif->tx_buff[slot] + i, q->payload, q->len); i += q->len; } } - else - { - /* because there is no copy operation to the tx_slots - * we don't need a place in the queue anymore - */ - mmnif->tx_queue--; - } - /* get the palce the router core is looking for the packet */ - /* lock the dest_ip mm_rx_buffer_hdr */ - mmnif_lock_rx_hdr(dest_ip); + /* allocate memory for the packet in the remote buffer */ - /* read and edit needed values */ - queued = mmnif_read_rx_queue(dest_ip); - pos = mmnif_read_rx_pos(dest_ip); + write_address = mmnif_rxbuff_alloc(dest_ip,p->tot_len); - pending = mmnif_read_rx_pending(dest_ip); - - pending++; - mmnif_write_rx_pending(dest_ip,pending); - - /* and unlock the dest_ip mm_rx_buffer_hdr */ - mmnif_unlock_rx_hdr(dest_ip); - - /* check if there is a space in the queue without overwriting another packet */ - if ((queued + pending) > MMNIF_RX_QUEUELEN) - { - DEBUGPRINTF("mmnif_tx(): too many packet's at once for the remote queue : q:%d p:%d\n",queued , pending); + if (!write_address) goto drop_packet; - } - - pos = (pos + queued + pending -1) % MMNIF_RX_QUEUELEN; /* write buffer to buffer & increment the queued packet count * this can be safely done without locking because this place is * reserved for us because it has the status "pending" */ if (build_buff) - mmnif_write_rx_buff(dest_ip, pos, mmnif->tx_buff[slot]); + memcpy(write_address,mmnif->tx_buff[slot],p->tot_len); else - mmnif_write_rx_buffl(dest_ip, pos, p->payload,p->tot_len); + memcpy(write_address,p->payload,p->tot_len); -// udelay(50000); - /* like above ensure we are the only ones editing the hdr */ - mmnif_lock_rx_hdr(dest_ip); - - queued = mmnif_read_rx_queue(dest_ip); - pending = mmnif_read_rx_pending(dest_ip); - queued++; - pending--; - - dest_intr = mmnif_read_rx_inv_intr(dest_ip); - -#ifdef DEBUG_MMNIF + if (mmnif_commit_packet(dest_ip,write_address)) + { + DEBUGPRINTF("mmnif_tx(): packet somehow lost during commit\n"); + } + +#ifdef DEBUG_MMNIF_PACKET DEBUGPRINTF("\n SEND 0x%.8X with length: %d\n",(char*)mpb_start_address + (dest_ip -1)*mpb_size + pos * 1792,p->tot_len +2); hex_dump(p->tot_len, p->payload); #endif - mmnif_write_rx_queue(dest_ip, queued); - mmnif_write_rx_pending(dest_ip, pending); + /* release the tx_queue because it's finished */ + spinlock_lock(&mmnif->lock); + mmnif->tx_queue--; + spinlock_unlock(&mmnif->lock); - mmnif_unlock_rx_hdr(dest_ip); - - /* if driver is not in polling mode inform core that a message has arrived */ - if (dest_intr) - mmnif_trigger_irq(dest_ip); - - /* free the transmid queue*/ - if(build_buff) - mmnif->tx_queue--; - - /* gather stats: - * - firstly for lwip - * - secondly for us - */ - + /* just gather some stats */ LINK_STATS_INC(link.xmit); mmnif->stats.tx++; mmnif->stats.tx_bytes += p->tot_len; +#ifdef WIN32 + WriteProcessMemory(hProc, (char*)mpb_start_address + ( dest_ip -1 ) * mpb_size, (char*)mpb_start_address + ( dest_ip -1 ) * mpb_size,mpb_size,NULL); + SetEvent(remote_process_event); + ReleaseMutex(remote_process_mutex); +#endif + + if (rb->iv_intr) + mmnif_trigger_irq(dest_ip); + return ERR_OK; -drop_packet: /* packet is lost. clean up and gather stats */ - +drop_packet: + /* drop packet for one or another reason + */ + spinlock_lock(&mmnif->lock); mmnif->tx_queue--; - + spinlock_unlock(&mmnif->lock); + LINK_STATS_INC(link.drop); - mmnif->stats.tx_err++; - return ERR_IF; +#ifdef WIN32 + WriteProcessMemory(hProc, (char*)mpb_start_address + ( dest_ip -1 ) * mpb_size,(char*)mpb_start_address + ( dest_ip -1 ) * mpb_size,mpb_size,NULL); +#endif + + return ERR_IF; } /* mmnif_link_layer(): wrapper function called by ip_output() @@ -834,7 +691,6 @@ static void mmnif_link_layer(struct netif *netif, struct pbuf *q, ip_addr_t *ipa netif->linkoutput(netif,q); } - /* * Init the device (called from lwip) * It's invoked in netif_add @@ -843,17 +699,12 @@ err_t mmnif_init(struct netif* netif) { mmnif_t* mmnif; uint32_t i; - static int num = 0; - uint16_t speed = 4000; - + int num = 0; /* Alloc and clear memory for the device struct */ -#ifdef WIN32 - mmnif = malloc(sizeof(mmnif_t)); -#else mmnif = kmalloc(sizeof(mmnif_t)); -#endif + if (!mmnif) { DEBUGPRINTF("mmnif init():out of memory\n"); @@ -863,23 +714,36 @@ err_t mmnif_init(struct netif* netif) /* Alloc and clear shared memory for rx_buff */ - mmnif->rx_buff = mmnif_shmalloc(); - if (!(mmnif->rx_buff)) + mpb_size = (sizeof(mm_rx_buffer_t) + MMNIF_RX_BUFFERLEN); + mpb_start_address = RCCE_shmalloc(mpb_size*MMNIF_CORES); + + mmnif->rx_buff = mpb_start_address + (mpb_size) * (own_ip_address - router_ip_address); + if (!(mpb_start_address)) { DEBUGPRINTF("mmnif init(): allocating shared memory failed\n"); return ERR_MEM; } memset(mmnif->rx_buff, 0, mpb_size); - /* init the lock for the hdr + /* set initial values + */ + mmnif->rx_buff->dcount = MMNIF_MAX_DESCRIPTORS; + + /* init the lock's for the hdr */ - sem_init(&mmnif->rx_buff->lock,1); + + spinlock_init(&mmnif->rx_buff->rlock); + spinlock_init(&mmnif->rx_buff->dlock); + + spinlock_init(&mmnif->lock); /* init the sems for communication art */ - sem_init(&mmnif->com_poll,1); - sem_wait(&mmnif->com_poll); + + /* since there is no possibilty to create a full semaphore we just block it manually + */ + sem_wait(&mmnif->com_poll,0); /* inform via interrupt should be the dafault */ @@ -888,21 +752,11 @@ err_t mmnif_init(struct netif* netif) /* Alloc and clear internal memory for tx_buff */ -#ifdef WIN32 - mmnif->tx_buff[0] = malloc(MMNIF_TX_QUEUELEN * MMNIF_TX_BUFFERLEN); -#else mmnif->tx_buff[0] = kmalloc(MMNIF_TX_QUEUELEN * MMNIF_TX_BUFFERLEN); -#endif + if (!(mmnif->tx_buff[0])) { DEBUGPRINTF("mmnif init: out of memory tx\n"); -#ifdef WIN32 - free(mmnif->rx_buff); - free(mmnif); -#else -// kfree(mmnif->rx_buff); -// kfree(mmnif); -#endif return ERR_MEM; } mmnif->tx_queue = 0; @@ -911,26 +765,12 @@ err_t mmnif_init(struct netif* netif) for (i = 0; i < MMNIF_TX_QUEUELEN -1 ; i++) mmnif->tx_buff[i+1] = mmnif->tx_buff[i] + MMNIF_TX_BUFFERLEN; - /* initialize the mailbox system */ - mailbox_ptr_init(&mmnif->mbox); - /* pass the device state to lwip */ netif->state = mmnif; mmnif_dev = netif; - /* Generate MAC address */ - mmnif_dev->hwaddr[0] = 0x11;mmnif_dev->hwaddr[1] = 0x22;mmnif_dev->hwaddr[2] = 0x33; - mmnif_dev->hwaddr[3] = 0x44;mmnif_dev->hwaddr[4] = 0x55;mmnif_dev->hwaddr[5] = RCCE_ue()*0x11 +0x66; - - /* - * Initialize the snmp variables and counters inside the struct netif. - * The last argument should be replaced with your link speed, in units - * of bits per second. - */ - NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, speed); - /* administrative details */ - netif->name[0] = 'm'; + netif->name[0] = 'e'; netif->name[1] = 'n'; netif->num = num; num++; @@ -941,12 +781,10 @@ err_t mmnif_init(struct netif* netif) /* maximum transfer unit */ netif->mtu = 1500; /* broadcast capability, keep all default flags*/ - netif->flags |= NETIF_FLAG_BROADCAST /*| NETIF_FLAG_ETHARP*/ | NETIF_FLAG_LINK_UP; + netif->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_LINK_UP; /* hardware address length */ netif->hwaddr_len = 6; - mmnif->ethaddr = (struct eth_addr *)netif->hwaddr; - active = TRUE; #ifdef MMNIF_DEBUG @@ -961,30 +799,68 @@ err_t mmnif_init(struct netif* netif) */ static void mmnif_rx(struct netif* netif) { - mmnif_t* mmnif = netif->state; - uint16_t length,i; + mmnif_t* mmnif = netif->state; + mm_rx_buffer_t* b = mmnif->rx_buff; + + uint16_t length; struct pbuf* p = NULL; struct pbuf* q; - char* data; - uint32_t pos; - uint8_t queued; + char* packet; - /* retrieve pointer to actual data array */ - data = (char*) mmnif->rx_buff + sizeof(mm_rx_buffer_t); - /* retrice position wich is needed to be worked on */ - pos = (mmnif->rx_buff->pos % MMNIF_RX_QUEUELEN) * MMNIF_RX_BUFFERLEN; + uint32_t i,j; + uint8_t rdesc = 0xFF; - /* The packet length is stored in the first 2 bytes but does not include - * the header. Check for reasonable sizes before processing the data to - * prevent nasty memory overflow errors. - */ - length = *((uint16_t*) (data + pos)); + err_t err = NULL; - /* If length is zero return silently */ +#ifdef WIN32 + ReadProcessMemory(hProc, (char*)mpb_start_address + ( !((own_ip_address && 0xFF)-1) ) * mpb_size, (char*)mpb_start_address + ( !((own_ip_address && 0xFF)-1) ) * mpb_size,mpb_size,NULL); + WaitForSingleObject(own_process_mutex,INFINITE); +#endif + + spinlock_lock(&b->rlock); + + /* check if this call to mmnif_rx makes any sense + */ + if (b->desc_table[b->dread].stat == MMNIF_STATUS_FREE) + { + spinlock_unlock(&b->rlock); +#ifdef WIN32 + WriteProcessMemory(hProc, (char*)mpb_start_address + ( !((own_ip_address && 0xFF)-1) ) * mpb_size, (char*)mpb_start_address + ( !((own_ip_address && 0xFF)-1) ) * mpb_size,mpb_size,NULL); +#endif + return; + } + + /* search the packet whose transmission is finished + */ + for (i = 0,j = b->dread; i < MMNIF_MAX_DESCRIPTORS; i++) + { + if (b->desc_table[(j + i)% MMNIF_MAX_DESCRIPTORS].stat == MMNIF_STATUS_RDY) + { + rdesc = (j + i)% MMNIF_MAX_DESCRIPTORS; + b->desc_table[rdesc].stat = MMNIF_STATUS_INPROC; + packet = (char*)b->desc_table[rdesc].addr; + length = b->desc_table[rdesc].len; + break; + } + } + + spinlock_unlock(&b->rlock); + + /* if there is no packet finished we encountered a random error + */ + if (rdesc == 0xFF) + { +#ifdef WIN32 + WriteProcessMemory(hProc, (char*)mpb_start_address + ( !((own_ip_address && 0xFF)-1) ) * mpb_size, (char*)mpb_start_address + ( !((own_ip_address && 0xFF)-1) ) * mpb_size,mpb_size,NULL); +#endif + return; + } + + /* If length is zero return silently + */ if (length == 0) { -// mmnif->rx_buff->pos++; -// mmnif->rx_buff->queued--; + DEBUGPRINTF("mmnif_rx(): empty packet error\n"); return; } if (length < sizeof(struct ip_hdr) ||length > netif->mtu) @@ -997,16 +873,11 @@ static void mmnif_rx(struct netif* netif) * has to be worked on */ + #ifdef DEBUG_MMNIF_PACKET + DEBUGPRINTF("\n RECIEVED - 0x%.8X with legth: %d\n",packet,length); + hex_dump(length,packet); + #endif -#ifdef DEBUG_MMNIF - DEBUGPRINTF("\n RECIEVED - 0x%.8X with legth: %d\n",data + pos,length+2); - hex_dump(length+2,data + pos); -#endif - - /* drop the length word of the packet data since it's no longer needed*/ - pos += 2; - - /* Build the pbuf for the packet so the lwip * and other higher layer can handle it */ @@ -1016,29 +887,31 @@ static void mmnif_rx(struct netif* netif) DEBUGPRINTF("mmnif_rx(): low on mem - packet dropped\n"); goto drop_packet; } - + /* copy packet to pbuf structure going through linked list */ for (q=p, i = 0; q!=NULL; q=q->next) { - memcpy((uint8_t*)q->payload + i,&data[pos+i],q->len); + memcpy((uint8_t*)q->payload,&packet[i],q->len); i +=q->len; } + /* indicate that the copy process is done and the packet can be freed + * note that we did not lock here because we are the only one editing this value + */ + mmnif->rx_buff->desc_table[rdesc].stat = MMNIF_STATUS_PROC; + /* everything is copied to a new buffer so it's save to release * the old one for new incoming packets */ - mmnif_lock_rx_hdr(own_ip_address & 0xFF); + mmnif_rxbuff_free(); - mmnif->rx_buff->pos++; - mmnif->rx_buff->queued--; - - mmnif_unlock_rx_hdr(own_ip_address & 0xFF); - - /* using the mailbox to hand the buffer to the incoming packet thread - * so the "interrupt" itself is not taking to long - */ - mailbox_ptr_post(&mmnif->mbox, (void*)p); + /* full packet send to tcpip_thread to process */ + if ((err = mmnif_dev->input(p, mmnif_dev)) != ERR_OK) + { + DEBUGPRINTF("mmnif_rx: IP input error\n"); + pbuf_free(p); + } /* gather some stats and leave the rx handler */ LINK_STATS_INC(link.xmit); @@ -1051,170 +924,34 @@ static void mmnif_rx(struct netif* netif) else mmnif->stats.rx_poll++; +#ifdef WIN32 + WriteProcessMemory(hProc, (char*)mpb_start_address + ( !((own_ip_address && 0xFF)-1) ) * mpb_size, (char*)mpb_start_address + ( !((own_ip_address && 0xFF)-1) ) * mpb_size,mpb_size,NULL); + ReleaseMutex(own_process_mutex); +#endif + return; drop_packet: - /* packet is lost so gather stats and leave the rx handler*/ - mmnif->rx_buff->pos++; - mmnif->rx_buff->queued--; - LINK_STATS_INC(link.drop); + + spinlock_lock(&mmnif->rx_buff->rlock); + /*error handling*/ + spinlock_unlock(&mmnif->rx_buff->rlock); + + LINK_STATS_INC(link.drop); mmnif->stats.rx_err++; + +#ifdef WIN32 + WriteProcessMemory(hProc, (char*)mpb_start_address + ( !((own_ip_address && 0xFF)-1) ) * mpb_size, (char*)mpb_start_address + ( !((own_ip_address && 0xFF)-1) ) * mpb_size,mpb_size,NULL); +#endif return; } - -/* - * The wait implementation which is processing all incoming packets - */ -static int mmnif_wait(struct netif* netif, uint32_t poll, int budget) -{ - mmnif_t* mmnif = netif->state; - struct eth_hdr * ethhdr; - struct pbuf* p = NULL; - int err = ERR_OK; - unsigned int npackets = 0; - unsigned int quota = 0; - - if (budget > mmnif->rx_buff->queued) - { - quota = mmnif->rx_buff->queued; - } - else - { - quota = budget; - - mmnif->stats.bdg_overflow++; - if (mmnif->stats.bdg_overflow >= 0x10) - { - /* enable polling and disable interrupts - * - - */ - mmnif_lock_rx_hdr(own_ip_address && 0xff); - mmnif->rx_buff->iv_intr = FALSE; - mmnif_unlock_rx_hdr(own_ip_address && 0xff); -#ifdef DEBUG_MMNIF - DEBUGPRINTF("mmnif_wait(): heuristical polling enables\n"); -#endif - sem_post(&mmnif->com_poll); - mmnif->stats.bdg_overflow = 0; - } - - } - - /* process up to quota packets from the receive queue */ - while (npackets <= quota) - { - /* fetch new data from mmnif_rx() if there is any */ - if (poll) - { - /* if there is no data return immeadieatly*/ - if (mailbox_ptr_tryfetch(&(mmnif->mbox), (void**) &p)) - return err; - } - else - { - mailbox_ptr_fetch(&(mmnif->mbox), (void**) &p); - } - - /* if there is data, pass it up to the lwip - * so he can handle it properly - */ - - /* full packet send to tcpip_thread to process */ - if ((err = mmnif_dev->input(p, mmnif_dev)) != ERR_OK) - { - DEBUGPRINTF("mmnif_poll: IP input error\n"); - pbuf_free(p); - } - - npackets++; - } - - /* Note : i will add an return error wich indicates that - * there is no budget left but messages in the queue - */ - return err; - -} - -/* - * worker thread - */ -int mmnif_worker(void* e) -{ -#ifdef DEBUG_MMNIF - DEBUGPRINTF("Waiting for work to do!!!\n"); -#endif - while (active) - mmnif_wait(mmnif_dev,0,MMNIF_WORKER_BUDGET); - - return NULL; -} - -/* - * the poll function wich is used if no interrupt wake up our mmnif_rx functions - */ -int mmnif_poll(void* e) -{ - mmnif_t* mmnif; - unsigned int diff = mmnif_timestamp(); - unsigned int tmp32 = 0; - - if (!mmnif_dev) - { - DEBUGPRINTF("mmnif_poll(): the driver is not initialized yet\n"); - return -1; - } - - mmnif = (mmnif_t*) mmnif_dev->state; - -#ifdef DEBUG_MMNIF - DEBUGPRINTF("Polling for work to do!!!! ONBBBB 0x%.8X BBBB\n\n",mmnif->rx_buff); -#endif - - if (!no_irq) - { - sem_wait(&mmnif->com_poll); - } - - /*run while driver is up*/ - while (active) - { - while (!mmnif->rx_buff->queued) - { - tmp32 = mmnif_timestamp(); - diff = diff - tmp32 > 0 ? diff - tmp32 : tmp32 - diff; - mmnif->stats.pll_empty++; - if (mmnif->stats.pll_empty >= 0x100000) - { - /* enable interrupts and suspend polling - * - */ - mmnif_lock_rx_hdr(own_ip_address && 0xff); - mmnif->rx_buff->iv_intr = TRUE; - mmnif_unlock_rx_hdr(own_ip_address && 0xff); -#ifdef DEBUG_MMNIF - DEBUGPRINTF("mmnif_poll(): heuristical interrupts enabled\n"); -#endif - sem_wait(&mmnif->com_poll); - mmnif->stats.pll_empty = 1; - } - } - mmnif->stats.pll_empty--; -// udelay(30000); - mmnif_rx(mmnif_dev); -// mmnif_wait(mmnif_dev,0,MMNIF_WORKER_BUDGET); - } - - return NULL; -} - -/* mmnif_irqhandler(): handles incoming interrupts - * its just a local wrapper for mmnif_rx() +/* mmnif_irqhandler(): + * handles the incomint interrupts */ void mmnif_irqhandler(void) { mmnif_t* mmnif; + /* return if mmnif_dev is not yet initialized*/ if (!mmnif_dev) { @@ -1224,10 +961,68 @@ void mmnif_irqhandler(void) mmnif = (mmnif_t*) mmnif_dev->state; - while (mmnif->rx_buff->queued) + while (mmnif->rx_buff->dcount < MMNIF_MAX_DESCRIPTORS) + { mmnif_rx(mmnif_dev); -} +// if (instant_process) +// mmnif_wait(mmnif_dev,1,MMNIF_WORKER_BUDGET); + } +} +/* + * the poll function wich is used if no interrupt wake up our mmnif_rx functions + */ +int mmnif_poll(void* e) +{ + mmnif_t* mmnif; + + if (!mmnif_dev) + { + DEBUGPRINTF("mmnif_poll(): the driver is not initialized yet\n"); + return -1; + } + + mmnif = (mmnif_t*) mmnif_dev->state; + +#ifdef DEBUG_MMNIF + DEBUGPRINTF("mmnif_poll(): polling thread launched",mmnif->rx_buff); +#endif + + if (!no_irq) + { + sem_wait(&mmnif->com_poll,0); + } + + /*run while driver is up*/ + while (active) + { + while (!mmnif->rx_buff->dcount == MMNIF_MAX_DESCRIPTORS) + { + mmnif->stats.pll_empty++; + if (mmnif->stats.pll_empty >= MMNIF_POLL_BUDGET) + { + /* enable interrupts and suspend polling + * + */ + mmnif->rx_buff->iv_intr = TRUE; + mmnif->stats.pll_empty = 0; +#ifdef DEBUG_MMNIF + DEBUGPRINTF("mmnif_poll(): heuristical interrupts enabled\n"); +#endif + sem_wait(&mmnif->com_poll,0); + } + /* uncomment this to test only polling + */ + // mmnif->stats.pll_empty = 0; + } + + mmnif->stats.pll_empty=0; + mmnif_rx(mmnif_dev); + + } + + return NULL; +} /* * Open the interface should be called by kernel to use this network interface */ @@ -1240,17 +1035,14 @@ int mmnif_open(void) /* calculate my own ip address from core number * Note: core 1 is the router core */ - IP4_ADDR(&gw, 0,0,0,0); - IP4_ADDR(&ipaddr, 192,168,0,RCCE_ue()+1); + IP4_ADDR(&gw, 0,0,0,0); + IP4_ADDR(&ipaddr, 192,168,0,RCCE_ue() +1); IP4_ADDR(&netmask, 255,255,255,0); - own_ip_address += RCCE_ue()+1; + own_ip_address+= RCCE_ue() +1; -#ifdef WIN32 - mmnif_dev = malloc(sizeof(struct netif)); -#else mmnif_dev = kmalloc(sizeof(struct netif)); -#endif + /* register our Memory Mapped Virtual IP interface in the lwip stack * and tell him how to use the interface: * - mmnif_dev : the device data storage @@ -1262,14 +1054,14 @@ int mmnif_open(void) * Note: Ethernet Input will be removed because its NOT needed and will * be replaced with ip_input */ - if (!netif_add(mmnif_dev, &ipaddr, &netmask, &gw, NULL,(netif_init_fn)mmnif_init, tcpip_input/*ethernet_input*/)) + if (!netif_add(mmnif_dev, &ipaddr, &netmask, &gw, NULL,(netif_init_fn)mmnif_init, tcpip_input)) { DEBUGPRINTF("mmnif_open() : unable to add network interface\n"); return -1; } /* set our network interface to the default interface for lwip*/ - //netif_set_default(mmnif_dev); + //netif_set_default(mmnif_dev); /* tell lwip all initialization is done and we want to set it ab*/ netif_set_up(mmnif_dev); @@ -1284,15 +1076,18 @@ int mmnif_open(void) active = TRUE; /* If interrupts are not used we immediately add the polling function - * to the queue which would otherwise be done through the IRQ handler. - */ -// if (no_irq) - mmnif_device_schedule(); + * to the queue which would otherwise be done through the IRQ handler. + */ + mmnif_device_schedule(); /* Start the device worker thread wich actually processes the incoming * packet's this is not done in the "interrupt handler" to shorten them up */ - mmnif_worker_schedule(); +// if (!instant_process) +// mmnif_worker_schedule(); + + + // mmnif_retrigger_schedule(); #ifdef DEBUG_MMNIF DEBUGPRINTF("mmnif_dev is open\n"); @@ -1320,18 +1115,12 @@ int mmnif_close(void) * - this will stop the polling thread i.e. */ - /* resources has to be freed here - * will be added soon ;) - */ - active = FALSE; -#ifdef WIN32 - free(mmnif->tx_buff); - free(mmnif_dev); -#else -// kfree(mmnif->tx_buff); -// kfree(mmnif_dev); -#endif + + kfree(mmnif->tx_buff[0],MMNIF_TX_QUEUELEN * MMNIF_TX_BUFFERLEN); + kfree(mmnif_dev,sizeof(mmnif_t)); + RCCE_shfree(mpb_start_address); + return NULL; } diff --git a/drivers/net/rckemac.c b/drivers/net/rckemac.c index cd3409e9..1c8ae09d 100644 --- a/drivers/net/rckemac.c +++ b/drivers/net/rckemac.c @@ -276,7 +276,7 @@ static void rckemacif_input(struct netif* netif, struct pbuf* p) #endif /* PPPOE_SUPPORT */ /* full packet send to tcpip_thread to process */ if (mynetif->input(p, mynetif) != ERR_OK) { - LWIP_DEBUGF(NETIF_DEBUG, ("rtl8139if_input: IP input error\n")); + LWIP_DEBUGF(NETIF_DEBUG, ("rckemacif_input: IP input error\n")); pbuf_free(p); } break; diff --git a/drivers/net/rtl8139.c b/drivers/net/rtl8139.c index 1afc6a10..c7978fdf 100644 --- a/drivers/net/rtl8139.c +++ b/drivers/net/rtl8139.c @@ -113,7 +113,8 @@ static err_t rtl8139if_output(struct netif* netif, struct pbuf* p) static void rtl8139if_input(struct netif* netif, struct pbuf* p) { struct eth_hdr *ethhdr; - + err_t err; + /* points to packet payload, which starts with an Ethernet header */ ethhdr = p->payload; @@ -127,8 +128,9 @@ static void rtl8139if_input(struct netif* netif, struct pbuf* p) case ETHTYPE_PPPOE: #endif /* PPPOE_SUPPORT */ /* full packet send to tcpip_thread to process */ - if (mynetif->input(p, mynetif) != ERR_OK) { - LWIP_DEBUGF(NETIF_DEBUG, ("rtl8139if_input: IP input error\n")); + err = mynetif->input(p, mynetif); + if (err != ERR_OK) { + LWIP_DEBUGF(NETIF_DEBUG, ("rtl8139if_input: IP input error %d\n", (int32_t) err)); pbuf_free(p); } break; diff --git a/include/metalsvm/init.h b/include/metalsvm/init.h index fddf3409..02f97091 100644 --- a/include/metalsvm/init.h +++ b/include/metalsvm/init.h @@ -42,6 +42,9 @@ int network_init(void); /** @brief Shutdown the networking subsystem. */ int network_shutdown(void); +/** @brief Entry point of the init task */ +int initd(void* arg); + #ifdef __cplusplus } #endif diff --git a/include/metalsvm/mailbox.h b/include/metalsvm/mailbox.h index 3ffb1d87..8d86492c 100644 --- a/include/metalsvm/mailbox.h +++ b/include/metalsvm/mailbox.h @@ -24,6 +24,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -32,7 +33,7 @@ extern "C" { #define MAILBOX(name, type) \ inline static int mailbox_##name##_init(mailbox_##name##_t* m) { \ if (BUILTIN_EXPECT(!m, 0)) \ - return -1; \ + return -EINVAL; \ \ memset(m->buffer, 0x00, sizeof(type)*MAILBOX_SIZE); \ m->wpos = m->rpos = 0; \ @@ -46,7 +47,7 @@ extern "C" { \ inline static int mailbox_##name##_destroy(mailbox_##name##_t* m) { \ if (BUILTIN_EXPECT(!m, 0)) \ - return -1; \ + return -EINVAL; \ \ sem_destroy(&m->mails); \ sem_destroy(&m->boxes); \ @@ -58,9 +59,9 @@ extern "C" { \ inline static int mailbox_##name##_post(mailbox_##name##_t* m, type mail) { \ if (BUILTIN_EXPECT(!m, 0)) \ - return -1; \ + return -EINVAL; \ \ - sem_wait(&m->boxes); \ + sem_wait(&m->boxes, 0); \ spinlock_lock(&m->wlock); \ m->buffer[m->wpos] = mail; \ m->wpos = (m->wpos+1) % MAILBOX_SIZE; \ @@ -70,11 +71,29 @@ extern "C" { return 0; \ } \ \ - inline static int mailbox_##name##_fetch(mailbox_##name##_t* m, type* mail) { \ - if (BUILTIN_EXPECT(!m || !mail, 0)) \ - return -1; \ + inline static int mailbox_##name##_trypost(mailbox_##name##_t* m, type mail) { \ + if (BUILTIN_EXPECT(!m, 0)) \ + return -EINVAL; \ \ - sem_wait(&m->mails); \ + if (sem_trywait(&m->boxes)) \ + return -EBUSY; \ + spinlock_lock(&m->wlock); \ + m->buffer[m->wpos] = mail; \ + m->wpos = (m->wpos+1) % MAILBOX_SIZE; \ + spinlock_unlock(&m->wlock); \ + sem_post(&m->mails); \ + \ + return 0; \ + } \ + \ + inline static int mailbox_##name##_fetch(mailbox_##name##_t* m, type* mail, uint32_t ms) { \ + int err; \ + \ + if (BUILTIN_EXPECT(!m || !mail, 0)) \ + return -EINVAL; \ + \ + err = sem_wait(&m->mails, ms); \ + if (err) return err; \ spinlock_lock(&m->rlock); \ *mail = m->buffer[m->rpos]; \ m->rpos = (m->rpos+1) % MAILBOX_SIZE; \ @@ -86,10 +105,10 @@ extern "C" { \ inline static int mailbox_##name##_tryfetch(mailbox_##name##_t* m, type* mail) { \ if (BUILTIN_EXPECT(!m || !mail, 0)) \ - return -1; \ + return -EINVAL; \ \ if (sem_trywait(&m->mails) != 0) \ - return -1; \ + return -EINVAL; \ spinlock_lock(&m->rlock); \ *mail = m->buffer[m->rpos]; \ m->rpos = (m->rpos+1) % MAILBOX_SIZE; \ diff --git a/include/metalsvm/semaphore.h b/include/metalsvm/semaphore.h index 735c0e78..19ad8e38 100644 --- a/include/metalsvm/semaphore.h +++ b/include/metalsvm/semaphore.h @@ -29,6 +29,8 @@ #include #include #include +#include +#include #ifdef __cplusplus extern "C" { @@ -43,19 +45,19 @@ extern "C" { * * @return * - 0 on success - * - -1 on failure + * - -EINVAL on invalid argument */ inline static int sem_init(sem_t* s, unsigned int v) { unsigned int i; if (BUILTIN_EXPECT(!s, 0)) - return -1; + return -EINVAL; s->value = v; s->pos = 0; for(i=0; iqueue[i] = MAX_TASKS; - spinlock_init(&s->lock); + spinlock_irqsave_init(&s->lock); return 0; } @@ -63,42 +65,13 @@ inline static int sem_init(sem_t* s, unsigned int v) { /** @brief Destroy semaphore * @return * - 0 on success - * - -1 on failure + * - -EINVAL on invalid argument */ inline static int sem_destroy(sem_t* s) { if (BUILTIN_EXPECT(!s, 0)) - return -1; + return -EINVAL; - spinlock_destroy(&s->lock); - - return 0; -} - -/** @brief Blocking wait for semaphore - * - * This will put your task to sleep - * - * @return - * - 0 on success - * - -1 on failure - */ -inline static int sem_wait(sem_t* s) { - if (BUILTIN_EXPECT(!s, 0)) - return -1; - -next_try: - spinlock_lock(&s->lock); - if (s->value > 0) { - s->value--; - spinlock_unlock(&s->lock); - } else { - s->queue[s->pos] = per_core(current_task)->id; - s->pos = (s->pos + 1) % MAX_TASKS; - block_task(per_core(current_task)->id); - spinlock_unlock(&s->lock); - reschedule(); - goto next_try; - } + spinlock_irqsave_destroy(&s->lock); return 0; } @@ -109,37 +82,111 @@ next_try: * * @return * - 0 on success (You got the semaphore) - * - -1 on failure (You still have to wait) + * - -EINVAL on invalid argument + * - -ECANCELED on failure (You still have to wait) */ inline static int sem_trywait(sem_t* s) { - int ret = -1; + int ret = -ECANCELED; if (BUILTIN_EXPECT(!s, 0)) - return -1; + return -EINVAL; - spinlock_lock(&s->lock); + spinlock_irqsave_lock(&s->lock); if (s->value > 0) { s->value--; ret = 0; } - spinlock_unlock(&s->lock); + spinlock_irqsave_unlock(&s->lock); return ret; } +/** @brief Blocking wait for semaphore + * + * @param ms Timeout in milliseconds + * @return + * - 0 on success + * - -EINVAL on invalid argument + * - -ETIME on timer expired + */ +inline static int sem_wait(sem_t* s, uint32_t ms) { + task_t* curr_task = per_core(current_task); + + if (BUILTIN_EXPECT(!s, 0)) + return -EINVAL; + + if (!ms) { +next_try1: + spinlock_irqsave_lock(&s->lock); + if (s->value > 0) { + s->value--; + spinlock_irqsave_unlock(&s->lock); + } else { + s->queue[s->pos] = curr_task->id; + s->pos = (s->pos + 1) % MAX_TASKS; + curr_task->status = TASK_BLOCKED; + spinlock_irqsave_unlock(&s->lock); + reschedule(); + NOP2; + goto next_try1; + } + + return 0; + } else { + uint32_t ticks = (ms * TIMER_FREQ) / 1000; + uint32_t remain = (ms * TIMER_FREQ) % 1000; + + if (ticks) { + uint64_t deadline = get_clock_tick() + ticks; + +next_try2: + spinlock_irqsave_lock(&s->lock); + if (s->value > 0) { + s->value--; + spinlock_irqsave_unlock(&s->lock); + return 0; + } else { + if (get_clock_tick() >= deadline) { + spinlock_irqsave_unlock(&s->lock); + goto timeout; + } + s->queue[s->pos] = curr_task->id; + s->pos = (s->pos + 1) % MAX_TASKS; + curr_task->timeout = deadline; + curr_task->flags |= TASK_TIMER_USED; + curr_task->status = TASK_BLOCKED; + spinlock_irqsave_unlock(&s->lock); + reschedule(); + goto next_try2; + } + } + +timeout: + while (remain) { + udelay(1000); + remain--; + + if (!sem_trywait(s)) + return 0; + } + + return -ETIME; + } +} + /** @brief Give back resource * @return * - 0 on success - * - -1 on failure + * - -EINVAL on invalid argument */ inline static int sem_post(sem_t* s) { if (BUILTIN_EXPECT(!s, 0)) - return -1; + return -EINVAL; - spinlock_lock(&s->lock); + spinlock_irqsave_lock(&s->lock); if (s->value > 0) { s->value++; - spinlock_unlock(&s->lock); + spinlock_irqsave_unlock(&s->lock); } else { unsigned int k, i; @@ -153,7 +200,7 @@ inline static int sem_post(sem_t* s) { } i = (i + 1) % MAX_TASKS; } - spinlock_unlock(&s->lock); + spinlock_irqsave_unlock(&s->lock); } return 0; diff --git a/include/metalsvm/semaphore_types.h b/include/metalsvm/semaphore_types.h index a80dbc5e..5812d51a 100644 --- a/include/metalsvm/semaphore_types.h +++ b/include/metalsvm/semaphore_types.h @@ -41,11 +41,11 @@ typedef struct { /// Position in queue unsigned int pos; /// Access lock - spinlock_t lock; + spinlock_irqsave_t lock; } sem_t; /// Macro for initialization of semaphore -#define SEM_INIT(v) {v, {[0 ... MAX_TASKS-1] = MAX_TASKS}, 0, SPINLOCK_INIT} +#define SEM_INIT(v) {v, {[0 ... MAX_TASKS-1] = MAX_TASKS}, 0, SPINLOCK_IRQSAVE_INIT} #ifdef __cplusplus } diff --git a/include/metalsvm/syscall.h b/include/metalsvm/syscall.h index b47fc284..70c6ff4c 100644 --- a/include/metalsvm/syscall.h +++ b/include/metalsvm/syscall.h @@ -1,20 +1,36 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * This file is part of MetalSVM. + * This file is part of MetalSVM. */ /** @@ -50,6 +66,14 @@ extern "C" { #define __NR_wait 13 #define __NR_execve 14 #define __NR_times 15 +#define __NR_accept 16 +#define __NR_bind 17 +#define __NR_closesocket 18 +#define __NR_connect 19 +#define __NR_listen 20 +#define __NR_recv 21 +#define __NR_send 22 +#define __NR_socket 23 #ifdef __cplusplus } diff --git a/include/metalsvm/tasks.h b/include/metalsvm/tasks.h index c4e68991..0b0bcdac 100644 --- a/include/metalsvm/tasks.h +++ b/include/metalsvm/tasks.h @@ -100,13 +100,6 @@ void scheduler(void); */ int wakeup_task(tid_t); -/** @brief Change a task's status to TASK_BLOCKED - * @return - * - 0 on success - * - -EINVAL (-22) on failure - */ -int block_task(tid_t); - /** @brief Abort current task */ void NORETURN abort(void); diff --git a/include/metalsvm/tasks_types.h b/include/metalsvm/tasks_types.h index 9725454b..3379fccb 100644 --- a/include/metalsvm/tasks_types.h +++ b/include/metalsvm/tasks_types.h @@ -41,15 +41,17 @@ extern "C" { #endif #define TASK_INVALID 0 -#define TASK_READY 1 +#define TASK_READY 1 #define TASK_RUNNING 2 #define TASK_BLOCKED 3 #define TASK_FINISHED 4 -#define TASK_IDLE 5 +#define TASK_IDLE 5 #define TASK_DEFAULT_FLAGS 0 #define TASK_FPU_INIT (1 << 0) #define TASK_FPU_USED (1 << 1) +#define TASK_TIMER_USED (1 << 2) +#define TASK_SWITCH_IN_PROGRESS (1 << 3) typedef int (*entry_point_t)(void*); typedef int (STDCALL *internal_entry_point_t)(void*); @@ -61,8 +63,14 @@ typedef struct task { tid_t id; /// Task status (INVALID, READY, RUNNING, ...) uint32_t status; + /// Additional status flags. For instance, to signalize the using of the FPU + uint32_t flags; + /// Number of used time slices + uint32_t time_slices; + /// timeout for a blocked task + uint64_t timeout; /// Usage in number of pages - atomic_int32_t user_usage; + atomic_int32_t user_usage; /// Avoids concurrent access to the page directory spinlock_t pgd_lock; /// pointer to the page directory @@ -71,21 +79,23 @@ typedef struct task { spinlock_t vma_lock; /// List of VMAs vma_t* vma_list; - /// Additional status flags. For instance, to signalize the using of the FPU - uint32_t flags; /// starting time/tick of the task uint64_t start_tick; /// Start address of the heap uint32_t start_heap; /// End address of the heap uint32_t end_heap; +#ifdef CONFIG_LWIP + /// LwIP error code + int lwip_err; +#endif /// Mail inbox mailbox_wait_msg_t inbox; /// Mail outbox array mailbox_wait_msg_t* outbox[MAX_TASKS]; /// FPU state union fpu_state fpu; -} __attribute__((packed)) task_t; +} task_t; #ifdef __cplusplus } diff --git a/include/metalsvm/time.h b/include/metalsvm/time.h index aa47e47a..c20d059c 100644 --- a/include/metalsvm/time.h +++ b/include/metalsvm/time.h @@ -56,13 +56,13 @@ int sys_times(struct tms*, clock_t* clock); */ int timer_init(void); -/** @brief Blocking wait function - * - * This function does no busy-wait. +/** @brief Initialized a timer * * @param ticks Amount of ticks to wait + * @return + * - 0 on success */ -void timer_wait(unsigned int ticks); +int timer_wait(unsigned int ticks); /** @brief Returns the current number of ticks. * @return Current number of ticks diff --git a/kernel/Makefile b/kernel/Makefile index fdddee71..9f1eb11f 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -1,4 +1,4 @@ -C_source := main.c tasks.c syscall.c tests.c echo.c ping.c init.c +C_source := main.c tasks.c syscall.c tests.c echo.c ping.c netio.c init.c server.c client.c shell.c MODULE := kernel include $(TOPDIR)/Makefile.inc diff --git a/kernel/client.c b/kernel/client.c new file mode 100644 index 00000000..386e69a7 --- /dev/null +++ b/kernel/client.c @@ -0,0 +1,120 @@ +#include "client.h" + +#include "../drivers/net/util.h" + +#define SOCKET_ERROR -1 + +int cli_sendBuffer(Client* cli,void* pBuffer, unsigned int bufferlen) +{ + int iResult; + ClientEventArgs e; + //abfragen ob client existiert!! wichtig + if (cli->sSocket != SOCKET_ERROR) + { + iResult= send(cli->sSocket,(char*)pBuffer,bufferlen,0); + if (cli->_OnWrite != 0) + { + e.dwLen = iResult; + e.pBuffer = pBuffer; + cli->_OnWrite(&e); + } + return iResult; + } + else + return -3; +} + +int cli_ConnectTo(Client* cli,char * pAdresse,unsigned short Port,int webAdresse) +{ + ClientEventArgs e; + cli->sSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); // Einen Socket erstellen + cli->wPort=Port; + cli->adAddr.sin_port = htons(cli->wPort); + + if (cli->sSocket == SOCKET_ERROR) + return -2; + + if (webAdresse) //Fall es sich um eine Internet Adresse Handelt + return -1; + else //Fall es sich um eine LAN Adresse im 127.0.0.1 Stil handelt + cli->adAddr.sin_addr.s_addr = inet_addr(pAdresse); + + if (connect(cli->sSocket,(const struct sockaddr*)&cli->adAddr, sizeof(cli->adAddr))==0) + { + + create_kernel_task(&cli->bThread,cli_WaitForPacket,cli); + + if (cli->_OnConnect != 0) + { + e.dwLen = 0; + e.pBuffer = 0; + cli->_OnConnect(&e); + } + return 0; + } + else + return -1; +}; + +int cli_DisconnectFrom(Client* cli) +{ + shutdown(cli->sSocket,2); + closesocket(cli->sSocket); + cli->sSocket = SOCKET_ERROR; + return 0; +} + +void cli_WaitForPacket(Client* cli) +{ + int iResult=1; + char pTmpBuffer[DEF_BUFFERSIZE+1]; + ClientEventArgs e; + + while (iResult > 0) + { + iResult = recv(cli->sSocket ,pTmpBuffer, DEF_BUFFERSIZE, 0); + if (iResult > 0) + { + pTmpBuffer[iResult]='\0'; + if (cli->_OnRead != 0) + { + e.dwLen = iResult; + e.pBuffer = pTmpBuffer; + cli->_OnRead( &e); + } + } + else //Verbindung geschlossen + { + cli->sSocket=SOCKET_ERROR; + if (cli->_OnDisconnect != 0) + { + e.dwLen = 0; + e.pBuffer = 0; + cli->_OnDisconnect( &e); + } + } + + } +}; + + +int cli_init(Client* cli) +{ + + cli->_OnConnect = 0; + cli->_OnWrite = 0; + cli->_OnRead = 0; + cli->_OnDisconnect = 0; + + cli->adAddr.sin_addr.s_addr = INADDR_ANY; // IP'S die der Client annehmen soll + cli->adAddr.sin_family = AF_INET; // AdressFamilie (TCP/IP) +// adAddr.sin_port = htons(iPort); // Port auf dem der Client erreichbar seien soll + + return NULL; +} + +int cli_destroy(Client* cli) +{ + closesocket(cli->sSocket);; + return NULL; +} diff --git a/kernel/client.h b/kernel/client.h new file mode 100644 index 00000000..1c686c4d --- /dev/null +++ b/kernel/client.h @@ -0,0 +1,56 @@ +#ifndef __CLIENT__ +#define __CLIENT__ + +#define DEF_BUFFERSIZE 2048 // Buffergröße für ein Packet + +#ifndef LWIP_SOCKET +#include +#endif + +#ifndef SOCKET +#define SOCKET int +#endif + + +#include + + +typedef struct _ClientEventArgs +{ + unsigned int dwLen; + void* pBuffer; +} ClientEventArgs; + + +typedef void (*ClientEventHandler)(ClientEventArgs*); + + +typedef struct _Client +{ +//Connection Handling +SOCKET sSocket; + +struct sockaddr_in adAddr; + +//Output Interfacte +unsigned short wPort; + +tid_t bThread; + +// Eventhandling +ClientEventHandler _OnConnect; +ClientEventHandler _OnDisconnect; +ClientEventHandler _OnRead; +ClientEventHandler _OnWrite; +} Client; + +int cli_sendBuffer(Client* cli,void* pBuffer, unsigned int bufferlen); +int cli_ConnectTo(Client* cli,char * pAdresse,unsigned short Port,int webAdresse); +int cli_DisconnectFrom(Client* cli); +void cli_WaitForPacket(Client* cli); + +cli_init(Client* cli); +cli_destroy(Client* cli); + + +#endif diff --git a/kernel/init.c b/kernel/init.c index b63c5c43..a29807ac 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -25,6 +25,7 @@ #include #include #include +#include #ifdef CONFIG_LWIP #include #include @@ -47,6 +48,8 @@ void echo_init(void); void ping_init(void); +void netio_init(void); +int test_init(void); /* * Note that linker symbols are not variables, they have no memory allocated for @@ -150,12 +153,13 @@ int network_init(void) } } #else - //mmnif_open(); + mmnif_open(); #endif // start echo and ping server echo_init(); - ping_init(); + //ping_init(); + netio_init(); #endif return 0; @@ -165,7 +169,7 @@ int network_shutdown(void) { #ifdef CONFIG_LWIP #ifdef CONFIG_ROCKCREEK - //mmnif_close(); + mmnif_close(); #elif defined(CONFIG_PCI) dhcp_release(default_netif); dhcp_stop(default_netif); @@ -178,4 +182,45 @@ int network_shutdown(void) return 0; } +static void list_fs(vfs_node_t* node, uint32_t depth) +{ + int j, i = 0; + dirent_t* dirent = NULL; + + while ((dirent = readdir_fs(node, i)) != 0) { + for(j=0; jname); + + if (strcmp(dirent->name, ".") && strcmp(dirent->name, "..")) { + vfs_node_t *new_node = finddir_fs(node, dirent->name); + if (new_node) { + if (new_node->type == FS_FILE) { + char buff[16] = {[0 ... 15] = 0x00}; + + read_fs(new_node, (uint8_t*)buff, 8, 0); + for(j=0; j #include #include -#include #include #include +#include #include #include #include @@ -34,8 +34,6 @@ #include #endif -extern int test_init(void); - /* * Note that linker symbols are not variables, they have no memory allocated for * maintaining a value, rather their address is their value. @@ -45,39 +43,6 @@ extern const void kernel_end; extern char __BUILD_DATE; extern char __BUILD_TIME; -static void list_fs(vfs_node_t* node, uint32_t depth) -{ - int j, i = 0; - dirent_t* dirent = NULL; - - while ((dirent = readdir_fs(node, i)) != 0) { - for(j=0; jname); - - if (strcmp(dirent->name, ".") && strcmp(dirent->name, "..")) { - vfs_node_t *new_node = finddir_fs(node, dirent->name); - if (new_node) { - if (new_node->type == FS_FILE) { - char buff[16] = {[0 ... 15] = 0x00}; - - read_fs(new_node, (uint8_t*)buff, 8, 0); - for(j=0; j 1 // idle loop of the application processors int smp_main(void) @@ -117,7 +82,6 @@ int main(void) kprintf("Kernel starts at %p and ends at %p\n", &kernel_start, &kernel_end); system_calibration(); - network_init(); kprintf("Processor frequency: %u MHz\n", get_cpu_frequency()); kprintf("Total memory: %u MBytes\n", atomic_int32_read(&total_pages)/((1024*1024)/PAGE_SIZE)); @@ -125,9 +89,8 @@ int main(void) kprintf("Current available memory: %u MBytes\n", atomic_int32_read(&total_available_pages)/((1024*1024)/PAGE_SIZE)); sleep(5); - list_root(); - test_init(); - per_core(current_task)->status = TASK_IDLE; + create_kernel_task(NULL, initd, NULL); + per_core(current_task)->time_slices = 0; // reset the number of time slices reschedule(); while(1) { diff --git a/kernel/netio.c b/kernel/netio.c new file mode 100644 index 00000000..166bbc18 --- /dev/null +++ b/kernel/netio.c @@ -0,0 +1,62 @@ +/* + * this example is derived from the netio example of the contrib-1.4.0 + * + * see http://download.savannah.gnu.org/releases/lwip/ + */ + +#include +#include + +#if defined(CONFIG_LWIP) + +#include +#include + +/* See http://www.nwlab.net/art/netio/netio.html to get the netio tool */ + +#if LWIP_TCP +static err_t netio_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) +{ + + LWIP_UNUSED_ARG(arg); + + if (err == ERR_OK && p != NULL) { + tcp_recved(pcb, p->tot_len); + pbuf_free(p); + } else { + pbuf_free(p); + } + + if (err == ERR_OK && p == NULL) { + tcp_arg(pcb, NULL); + tcp_sent(pcb, NULL); + tcp_recv(pcb, NULL); + tcp_close(pcb); + } + + return ERR_OK; +} + +static err_t netio_accept(void *arg, struct tcp_pcb *pcb, err_t err) +{ + LWIP_UNUSED_ARG(arg); + LWIP_UNUSED_ARG(err); + + tcp_arg(pcb, NULL); + tcp_sent(pcb, NULL); + tcp_recv(pcb, netio_recv); + return ERR_OK; +} + +void netio_init(void) +{ + struct tcp_pcb *pcb; + + pcb = tcp_new(); + tcp_bind(pcb, IP_ADDR_ANY, 18767); + pcb = tcp_listen(pcb); + tcp_accept(pcb, netio_accept); +} +#endif /* LWIP_TCP */ + +#endif diff --git a/kernel/server.c b/kernel/server.c new file mode 100644 index 00000000..bd5c441a --- /dev/null +++ b/kernel/server.c @@ -0,0 +1,199 @@ +#include "server.h" + +typedef int UINT_PTR; +#define SOCKET_ERROR -1 + + +int srv_sendBuffer(Server* srv, unsigned int cli,void* pBuffer, unsigned int dwLen) +{ + int result; + ServerEventArgs e; + //abfragen ob client existiert!! wichtig + if (srv->sConnections[cli] != SOCKET_ERROR) + { + result= send(srv->sConnections[cli],(char*)pBuffer,dwLen,0); + if (srv->_OnWrite!=0) + { + e.ClientID = cli; + e.dwLen = dwLen; + e.pBuffer = pBuffer; + srv->_OnWrite(&e); + } + + return result; + } + else + return -1; +} + +void srv_DisconnectClient(Server* srv, unsigned int cli) +{ + ServerEventArgs e; + closesocket(srv->sConnections[cli]); + srv->sConnections[cli]=SOCKET_ERROR; + srv->dwConnections--; + if (srv->_OnDisconnect!=0) + { + e.ClientID = cli; + e.dwLen = 0; + e.pBuffer = 0; + srv->_OnDisconnect(&e); + } + + memset(&srv->ConnectionsAddr[cli],0,sizeof(struct sockaddr_in)); +} +void* srv_WaitForConnection(Server* srv) +{ + SOCKET tmpClient; + struct sockaddr_in tmpAddr; + int tmpAddrLen; + ServerEventArgs e; + ServerThreadArgs* t; + unsigned int i; + + + do + { + if (srv->dwConnections < srv->dwMaximumConnections) + { + tmpAddrLen = sizeof(struct sockaddr); + if ((tmpClient=accept(srv->sSocket,(struct sockaddr*)&tmpAddr,&tmpAddrLen)) != SOCKET_ERROR) + { + for(i=0;idwMaximumConnections;i++) + { + if (srv->sConnections[i] == SOCKET_ERROR) + { + srv->sConnections[i] = tmpClient; + srv->ConnectionsAddr[i] = tmpAddr; + srv->dwConnections++; + + if(srv->_OnConnect!=0) + { + e.ClientID = i; + e.dwLen = 0; + e.pBuffer =0; + srv->_OnConnect(&e); + } + + t = (ServerThreadArgs*) kmalloc(sizeof(ServerThreadArgs)); + t->ID = i; + t->srv = srv; + create_kernel_task(&srv->bThreads[i],srv_WaitForPacket,t); + + break; + } + } + } + } + else + { + } + }while(1); + + return NULL; + +} +void* srv_WaitForPacket(ServerThreadArgs* t) +{ + int iResult=1; + char pTmpBuffer[DEF_BUFFERSIZE+1]; + ServerEventArgs e; + Server* srv = t->srv; + int cli = t->ID; + + while (iResult > 0) + { + iResult = recv(srv->sConnections[cli] ,pTmpBuffer, DEF_BUFFERSIZE, 0); + if (iResult > 0) + { + pTmpBuffer[iResult]='\0'; + if(srv->_OnRead!=0) + { + e.ClientID = cli; + e.dwLen = iResult; + e.pBuffer = pTmpBuffer; + srv->_OnRead(&e); + } + } + else //Verbindung geschlossen + { + closesocket(srv->sConnections[cli]); + srv->sConnections[cli]=SOCKET_ERROR; + if(srv->_OnDisconnect!=0) + { + e.ClientID = cli; + e.dwLen = 0; + e.pBuffer = 0; + srv->_OnDisconnect(&e); + } + memset(&srv->ConnectionsAddr[cli],0,sizeof(struct sockaddr_in)); + srv->dwConnections--; + iResult=-1; + } + } + return NULL; +} + +int server_init(Server* srv, unsigned short Port, unsigned int dwMaxConnections) +{ + struct sockaddr_in tmpAddr; + int tmpAddrLen; + ServerThreadArgs t; + tmpAddrLen = sizeof(struct sockaddr); + + // Unregister Events + srv->_OnConnect=0; + srv->_OnRead=0; + srv->_OnDisconnect=0; + srv->_OnWrite=0; + + // Allocate needed Memory + srv->sConnections=(SOCKET*)kmalloc(sizeof(SOCKET)*dwMaxConnections); + srv->ConnectionsAddr =(struct sockaddr_in*) kmalloc(sizeof(struct sockaddr_in)*dwMaxConnections); + srv->bThreads = (tid_t*)kmalloc(sizeof(tid_t)*dwMaxConnections); + + if (!srv->sConnections || !srv->ConnectionsAddr || !srv->bThreads) + { + kprintf("low on mem -%d- -%d- -%d-",srv->sConnections ,srv->ConnectionsAddr,srv->bThreads); + return -1; + } + + srv->dwMaximumConnections=dwMaxConnections; + + memset(srv->sConnections,0xFF,sizeof(SOCKET)*dwMaxConnections); + memset(srv->ConnectionsAddr,0x00,sizeof(struct sockaddr_in)*dwMaxConnections); + + srv->dwConnections=0; + srv->wPort = Port; + + srv->adAddr.sin_addr.s_addr = INADDR_ANY; // IP'S die der Server annehmen soll + srv->adAddr.sin_family = AF_INET; // AdressFamilie (TCP/IP) + srv->adAddr.sin_port = htons(srv->wPort); // Port auf dem der server erreichbar seien soll + + srv->sSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); // Einen Socket erstellen + + bind( srv->sSocket,(const struct sockaddr *) &srv->adAddr, sizeof(srv->adAddr)); // Der Server an die Adresse binden; + listen(srv->sSocket,srv->dwMaximumConnections); // Den Server in listenig State versetzen + + create_kernel_task(&srv->bThread_listen,srv_WaitForConnection,srv); +// sConnections[0] = accept(sSocket,(struct sockaddr*)&tmpAddr,&tmpAddrLen); +// t.ID = 0; +// bthread_create(&bThreads[0],NULL,(start_routine) srv_WaitForPacket,&t); +} + +int server_destroy(Server* srv) +{ + unsigned int i; + for (i=0;idwMaximumConnections;i++) + { + if (srv->sConnections[i] != SOCKET_ERROR)closesocket(srv->sConnections[i]); + //bthread_terminate(&srv->bThreads[i],0x00); + } + closesocket(srv->sSocket); + //bthread_terminate(&srv->bThread_listen,0x00); + +// free(srv->sConnections); +// free(srv->ConnectionsAddr); +// free(srv->bThreads); + +} diff --git a/kernel/server.h b/kernel/server.h new file mode 100644 index 00000000..c0ad344e --- /dev/null +++ b/kernel/server.h @@ -0,0 +1,67 @@ +#ifndef __SERVER__ +#define __SERVER__ + + +#ifdef WIN32 +#include +#else +#include +#endif + +#ifndef LWIP_SOCKET +#include +#endif + + +typedef struct _ServerEventArgs +{ + unsigned int ClientID; + unsigned int dwLen; + void* pBuffer; +} ServerEventArgs; + +#define DEF_BUFFERSIZE 2048 + +typedef void (*ServerEventHandler)(ServerEventArgs*); + +#ifndef SOCKET +#define SOCKET int +#endif + + +typedef struct _Server +{ + SOCKET sSocket; + unsigned int* sConnections; + struct sockaddr_in adAddr; + unsigned short wPort; + unsigned int dwConnections; + unsigned int dwMaximumConnections; + + struct sockaddr_in* ConnectionsAddr; + + tid_t bThread_listen; + tid_t* bThreads; + + ServerEventHandler _OnConnect; + ServerEventHandler _OnDisconnect; + ServerEventHandler _OnRead; + ServerEventHandler _OnWrite; +} Server; + +typedef struct _ServerThreadArgs +{ + Server* srv; + unsigned int ID; +} ServerThreadArgs; + + +int srv_sendBuffer(Server* srv,unsigned int cli,void* pBuffer, unsigned int dwLen); +void srv_DisconnectClient(Server* srv,unsigned int cli); +void* srv_WaitForConnection(Server* srv); +void* srv_WaitForPacket(ServerThreadArgs* t); + +int server_init(Server* srv,unsigned short Port, unsigned int dwMaxConnections); +int server_destroy(Server* srv); + +#endif diff --git a/kernel/shell.c b/kernel/shell.c new file mode 100644 index 00000000..b7df2362 --- /dev/null +++ b/kernel/shell.c @@ -0,0 +1,76 @@ +#include "shell.h" + +#include "server.h" +#include "client.h" + +#include + +static Server srv; +static int emac_id = -1; + +static Client cli; + +static int iamsrv = 0; + +char shellbuffer[512]; + + +void shelldebugprint(char* x) +{ + kprintf("debugprinting : %s",x); + if (iamsrv) + srv_sendBuffer(&srv,emac_id,x,strlen(x)); + else + cli_sendBuffer(&cli,x,strlen(x)); +} + +void shell_on_connect(ServerEventArgs* e) +{ + kprintf("connection from %s:%d",inet_ntoa(srv.ConnectionsAddr[e->ClientID].sin_addr),ntohs(srv.ConnectionsAddr[e->ClientID].sin_port)); + kprintf("connehx: 0x%.8X",srv.ConnectionsAddr[e->ClientID].sin_addr); + // if (srv.ConnectionsAddr[e->ClientID].sin_addr.s_addr > 0xC0A80031 || srv.ConnectionsAddr[e->ClientID].sin_addr.s_addr < 0xC0A80001) + if (srv.ConnectionsAddr[e->ClientID].sin_addr.s_addr == 0xFE04A8C0) + { + emac_id = e->ClientID; + kprintf("bmc connected"); + } + else + kprintf("link engaged\n"); +} + +void shell_on_disconnect(ServerEventArgs* e) +{ + kprintf("connection lost from %s:%d",inet_ntoa(srv.ConnectionsAddr[e->ClientID].sin_addr),ntohs(srv.ConnectionsAddr[e->ClientID].sin_port)); +} + +void shell_on_read(ServerEventArgs* e) +{ + if (emac_id != -1 && e->ClientID != emac_id) + srv_sendBuffer(&srv,emac_id,e->pBuffer,e->dwLen); + else + // else commandos oder so + srv_sendBuffer(&srv,emac_id,e->pBuffer,e->dwLen); +} + +void shell_init(int srv_or_cli) +{ + if (!srv_or_cli) + { + iamsrv = 1; + kprintf("server init"); + server_init(&srv,23,49); + srv._OnConnect = shell_on_connect; + srv._OnDisconnect = shell_on_disconnect; + srv._OnRead = shell_on_read; + } + else + { + sleep(3); + kprintf("client init"); + cli_init(&cli); + while (cli_ConnectTo(&cli,"192.168.0.1",23,0)); + sleep(1); + + } + +} diff --git a/kernel/shell.h b/kernel/shell.h new file mode 100644 index 00000000..6924c567 --- /dev/null +++ b/kernel/shell.h @@ -0,0 +1,14 @@ +#ifndef SHELL_H +#define SHELL_H + +#include + +void shelldebugprint(char* x); + +void shell_init(int srv_or_cli); + +extern char shellbuffer[512]; + +#define SHELLDEBUGPRINTF(x,...) ksnprintf(shellbuffer,sizeof(shellbuffer),x,##__VA_ARGS__);shelldebugprint(shellbuffer); + +#endif // SHELL_H diff --git a/kernel/syscall.c b/kernel/syscall.c index d3eba333..6eaecd28 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -24,6 +24,27 @@ #include #include #include +#include + +#if defined(CONFIG_LWIP) && LWIP_SOCKET +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * We set the a bit LWIP_FD_BIT to determine, + * if the descriptor belongs to LwIP or MetalSVM. + */ +#define LWIP_FD_BIT (1 << 28) +#endif static int sys_write(int fildes, const char *buf, size_t len) { @@ -85,15 +106,33 @@ int syscall_handler(uint32_t sys_nr, ...) const char* buf = va_arg(vl, const char*); size_t len = va_arg(vl, size_t); +#if defined(CONFIG_LWIP) && LWIP_SOCKET + if (fildes & LWIP_FD_BIT) { + ret = lwip_write(fildes & ~LWIP_FD_BIT, buf, len); + if (ret < 0) + ret = -errno; + } else ret = sys_write(fildes, buf, len); +#else ret = sys_write(fildes, buf, len); +#endif break; } case __NR_open: ret = 1; break; - case __NR_close: + case __NR_close: { +#if defined(CONFIG_LWIP) && LWIP_SOCKET + int s = va_arg(vl, int); + if (s & LWIP_FD_BIT) { + ret = lwip_close(s & ~LWIP_FD_BIT); + if (ret < 0) + ret = -errno; + } else ret = 0; +#else ret = 0; +#endif break; + } case __NR_sbrk: { int incr = va_arg(vl, int); @@ -127,6 +166,109 @@ int syscall_handler(uint32_t sys_nr, ...) ret = sys_times(buffer, clock); break; } +#if defined(CONFIG_LWIP) && LWIP_SOCKET + case __NR_read: { + int s = va_arg(vl, int); + void* mem = va_arg(vl, void*); + size_t len = va_arg(vl, size_t); + + if (!(s & LWIP_FD_BIT)) { + ret = -ENOTSOCK; + break; + } + + ret = lwip_read(s & ~LWIP_FD_BIT, mem, len); + if (ret < 0) + ret = -errno; + break; + } + case __NR_closesocket: { + int s = va_arg(vl, int); + + if (BUILTIN_EXPECT(!(s & LWIP_FD_BIT), 0)) { + ret = -ENOTSOCK; + break; + } + + ret = lwip_close(s & ~LWIP_FD_BIT); + if (ret < 0) + ret = -errno; + break; + } + case __NR_socket: { + int domain = va_arg(vl, int); + int type = va_arg(vl, int); + int protocol = va_arg(vl, int); + + ret = lwip_socket(domain, type, protocol); + if (ret >= 0) + ret |= LWIP_FD_BIT; + else + ret = -errno; + break; + } + case __NR_connect: { + int s = va_arg(vl, int); + const struct sockaddr* name = va_arg(vl, const struct sockaddr*); + socklen_t namelen = va_arg(vl, socklen_t); + + if (BUILTIN_EXPECT(!(s & LWIP_FD_BIT), 0)) { + ret = -ENOTSOCK; + break; + } + + ret = lwip_connect(s & ~LWIP_FD_BIT, name, namelen); + if (ret < 0) + ret = -errno; + break; + } + case __NR_bind: { + int s = va_arg(vl, int); + const struct sockaddr* name = va_arg(vl, const struct sockaddr*); + socklen_t namelen = va_arg(vl, socklen_t); + + if (BUILTIN_EXPECT(!(s & LWIP_FD_BIT), 0)) { + ret = -ENOTSOCK; + break; + } + + ret = lwip_bind(s & ~LWIP_FD_BIT, name, namelen); + if (ret < 0) + ret = -errno; + break; + } + case __NR_listen:{ + int s = va_arg(vl, int); + int backlog = va_arg(vl, int); + + if (BUILTIN_EXPECT(!(s & LWIP_FD_BIT), 0)) { + ret = -ENOTSOCK; + break; + } + + ret = lwip_listen(s & ~LWIP_FD_BIT, backlog); + if (ret < 0) + ret = -errno; + break; + } + case __NR_accept: { + int s = va_arg(vl, int); + struct sockaddr* addr = va_arg(vl, struct sockaddr*); + socklen_t* addrlen = va_arg(vl, socklen_t*); + + if (BUILTIN_EXPECT(!(s & LWIP_FD_BIT), 0)) { + ret = -ENOTSOCK; + break; + } + + ret = lwip_accept(s & ~LWIP_FD_BIT, addr, addrlen); + if (ret >= 0) + ret |= LWIP_FD_BIT; + else + ret = -errno; + break; + } +#endif default: kputs("invalid system call\n"); ret = -ENOSYS; diff --git a/kernel/tasks.c b/kernel/tasks.c index 6800e662..413ce994 100644 --- a/kernel/tasks.c +++ b/kernel/tasks.c @@ -47,8 +47,8 @@ * A task's id will be its position in this array. */ static task_t task_table[MAX_TASKS] = { \ - [0] = {0, TASK_RUNNING, ATOMIC_INIT(0), SPINLOCK_INIT, NULL, SPINLOCK_INIT, NULL, 0, 0, 0, 0}, \ - [1 ... MAX_TASKS-1] = {0, TASK_INVALID, ATOMIC_INIT(0), SPINLOCK_INIT, NULL, SPINLOCK_INIT, NULL, 0, 0, 0, 0}}; + [0] = {0, TASK_IDLE, 0, 0, 0, ATOMIC_INIT(0), SPINLOCK_INIT, NULL, SPINLOCK_INIT, NULL, 0, 0, 0, 0}, \ + [1 ... MAX_TASKS-1] = {0, TASK_INVALID, 0, 0, 0, ATOMIC_INIT(0), SPINLOCK_INIT, NULL, SPINLOCK_INIT, NULL, 0, 0, 0, 0}}; static spinlock_irqsave_t table_lock = SPINLOCK_IRQSAVE_INIT; DEFINE_PER_CORE(task_t*, current_task, task_table+0); @@ -63,16 +63,36 @@ task_t* get_current_task(void) { return per_core(current_task); } -int multitasking_init(void) { - if (BUILTIN_EXPECT(task_table[0].status == TASK_RUNNING, 1)) { - mailbox_wait_msg_init(&task_table[0].inbox); - memset(task_table[0].outbox, 0x00, sizeof(mailbox_wait_msg_t*)*MAX_TASKS); - task_table[0].pgd = get_boot_pgd(); - task_table[0].flags = TASK_DEFAULT_FLAGS; - return 0; +int dump_scheduling_statistics(void) +{ + uint32_t i; + uint32_t id = 0; + + kprintf("Scheduling statistics:\n"); + kprintf("======================\n"); + kprintf("total ticks:\t%llu\n", get_clock_tick()); + for(i=0; i 1 - spinlock_irqsave_unlock(&table_lock); -#endif -} - /** @brief Create a task with a specific entry point * * @param id Pointer to a tid_t struct were the id shall be set @@ -217,6 +227,9 @@ static int create_task(tid_t* id, internal_entry_point_t ep, void* arg) } task_table[i].id = i; + task_table[i].status = TASK_READY; + task_table[i].flags = TASK_DEFAULT_FLAGS; + task_table[i].time_slices = 0; spinlock_init(&task_table[i].vma_lock); task_table[i].vma_list = NULL; mailbox_wait_msg_init(&task_table[i].inbox); @@ -228,11 +241,12 @@ static int create_task(tid_t* id, internal_entry_point_t ep, void* arg) ret = create_default_frame(task_table+i, ep, arg); - task_table[i].flags = TASK_DEFAULT_FLAGS; task_table[i].start_heap = 0; task_table[i].end_heap = 0; +#ifdef CONFIG_LWIP + task_table[i].lwip_err = 0; +#endif task_table[i].start_tick = get_clock_tick(); - task_table[i].status = TASK_READY; break; } } @@ -292,11 +306,14 @@ int sys_fork(void) mailbox_wait_msg_init(&task_table[i].inbox); memset(task_table[i].outbox, 0x00, sizeof(mailbox_wait_msg_t*)*MAX_TASKS); task_table[i].outbox[parent_task->id] = &parent_task->inbox; - task_table[i].flags = parent_task->flags; + task_table[i].flags = parent_task->flags & ~TASK_SWITCH_IN_PROGRESS; memcpy(&(task_table[i].fpu), &(parent_task->fpu), sizeof(union fpu_state)); task_table[i].start_tick = get_clock_tick(); task_table[i].start_heap = 0; task_table[i].end_heap = 0; +#ifdef CONFIG_LWIP + task_table[i].lwip_err = 0; +#endif ret = arch_fork(task_table+i); @@ -305,7 +322,13 @@ int sys_fork(void) // Leave the function without releasing the locks // because the locks are already released // by the parent task! - start_first_time_slice(); +#if MAX_CORES > 1 + task_t* old = per_core(old_task); + + if (old) + old->flags &= ~TASK_SWITCH_IN_PROGRESS; +#endif + irq_enable(); return 0; } @@ -339,8 +362,13 @@ static int STDCALL kernel_entry(void* args) { int ret; kernel_args_t* kernel_args = (kernel_args_t*) args; +#if MAX_CORES > 1 + task_t* old = per_core(old_task); - start_first_time_slice(); + if (old) + old->flags &= ~TASK_SWITCH_IN_PROGRESS; +#endif + irq_enable(); if (BUILTIN_EXPECT(!kernel_args, 0)) return -EINVAL; @@ -395,6 +423,7 @@ static int load_task(load_args_t* largs) //elf_section_header_t sec_header; vfs_node_t* node; task_t* curr_task = per_core(current_task); + int err; if (!largs) return -EINVAL; @@ -403,7 +432,12 @@ static int load_task(load_args_t* largs) if (!node) return -EINVAL; - read_fs(node, (uint8_t*)&header, sizeof(elf_header_t), 0); + err = read_fs(node, (uint8_t*)&header, sizeof(elf_header_t), 0); + if (err < 0) { + kprintf("read_fs failed: %d\n", err); + return err; + } + if (BUILTIN_EXPECT(header.ident.magic != ELF_MAGIC, 0)) goto invalid; @@ -571,6 +605,12 @@ static int load_task(load_args_t* largs) invalid: kprintf("Invalid executable!\n"); + kprintf("magic number 0x%x\n", (uint32_t) header.ident.magic); + kprintf("header type 0x%x\n", (uint32_t) header.type); + kprintf("machine type 0x%x\n", (uint32_t) header.machine); + kprintf("elf ident class 0x%x\n", (uint32_t) header.ident._class); + kprintf("elf identdata !0x%x\n", header.ident.data); + kprintf("program entry point 0x%x\n", (size_t) header.entry); return -EINVAL; } @@ -580,8 +620,13 @@ invalid: static int STDCALL user_entry(void* arg) { int ret; +#if MAX_CORES > 1 + task_t* old = per_core(old_task); - start_first_time_slice(); + if (old) + old->flags &= ~TASK_SWITCH_IN_PROGRESS; +#endif + irq_enable(); if (BUILTIN_EXPECT(!arg, 0)) return -EINVAL; @@ -734,7 +779,7 @@ tid_t wait(int32_t* result) if (BUILTIN_EXPECT(curr_task->status == TASK_IDLE, 0)) return -EINVAL; - mailbox_wait_msg_fetch(&curr_task->inbox, &tmp); + mailbox_wait_msg_fetch(&curr_task->inbox, &tmp, 0); if (result) *result = tmp.result; @@ -752,12 +797,9 @@ int wakeup_task(tid_t id) { int ret = -EINVAL; - /* avoid nested locking */ spinlock_irqsave_lock(&table_lock); - if (task_table[id].status != TASK_BLOCKED) { - kprintf("Task %d is not blocked!\n", id); - } else { + if (task_table[id].status == TASK_BLOCKED) { task_table[id].status = TASK_READY; ret = 0; } @@ -767,27 +809,14 @@ int wakeup_task(tid_t id) return ret; } -/** @brief Block a running or ready task. - * @param id The task's tid_t structure - * @return - * - 0 on success - * - -EINVAL (-22) on failure +/* + * we use this struct to guarantee that the id + * has its own cache line */ -int block_task(tid_t id) -{ - int ret = -EINVAL; - - spinlock_irqsave_lock(&table_lock); - - if ((task_table[id].status == TASK_RUNNING) || (task_table[id].status == TASK_READY)) { - task_table[id].status = TASK_BLOCKED; - ret = 0; - } else kprintf("Unable to block task %d!\n", id); - - spinlock_irqsave_unlock(&table_lock); - - return ret; -} +typedef struct { + uint32_t id __attribute__ ((aligned (CACHE_LINE))); + uint8_t gap[CACHE_LINE-sizeof(uint32_t)]; +} last_id_t; /** @brief _The_ scheduler procedure * @@ -797,15 +826,20 @@ void scheduler(void) { task_t* orig_task; task_t* curr_task; - unsigned int i; - unsigned int new_id; + uint32_t i; + uint32_t new_id; + uint64_t current_tick; + static last_id_t last_id = { 0 }; #if MAX_CORES > 1 spinlock_irqsave_lock(&table_lock); #endif - + current_tick = get_clock_tick(); orig_task = curr_task = per_core(current_task); + /* increase the number of used time slices */ + curr_task->time_slices++; + /* signalizes that this task could be reused */ if (curr_task->status == TASK_FINISHED) curr_task->status = TASK_INVALID; @@ -816,19 +850,41 @@ void scheduler(void) curr_task->flags &= ~TASK_FPU_USED; } - for(i=1, new_id=(curr_task->id + 1) % MAX_TASKS; + for(i=0, new_id=(last_id.id + 1) % MAX_TASKS; istatus == TASK_RUNNING) + if (task_table[new_id].flags & TASK_TIMER_USED) { + if (task_table[new_id].status != TASK_BLOCKED) + task_table[new_id].flags &= ~TASK_TIMER_USED; + if ((task_table[new_id].status == TASK_BLOCKED) && (current_tick >= task_table[new_id].timeout)) { + task_table[new_id].flags &= ~TASK_TIMER_USED; + task_table[new_id].status = TASK_READY; + } + } + + if ((task_table[new_id].status == TASK_READY) && !(task_table[new_id].flags & TASK_SWITCH_IN_PROGRESS)) { + if (curr_task->status == TASK_RUNNING) { curr_task->status = TASK_READY; +#if MAX_CORES > 1 + curr_task->flags |= TASK_SWITCH_IN_PROGRESS; + per_core(old_task) = curr_task; +#endif + } +#if MAX_CORES > 1 + else per_core(old_task) = NULL; +#endif task_table[new_id].status = TASK_RUNNING; curr_task = per_core(current_task) = task_table+new_id; + last_id.id = new_id; goto get_task_out; } } +#if MAX_CORES > 1 + per_core(old_task) = NULL; +#endif + if ((curr_task->status == TASK_RUNNING) || (curr_task->status == TASK_IDLE)) goto get_task_out; @@ -840,14 +896,19 @@ void scheduler(void) curr_task = per_core(current_task) = task_table+CORE_ID; get_task_out: - //kprintf("schedule %d on core %d\n", per_core(current_task)->id, smp_id()); - - if (curr_task != orig_task) - switch_task(new_id); - #if MAX_CORES > 1 spinlock_irqsave_unlock(&table_lock); #endif + + if (curr_task != orig_task) { + //kprintf("schedule from %d to %d on core %d\n", orig_task->id, curr_task->id, smp_id()); + switch_task(new_id); +#if MAX_CORES > 1 + orig_task= per_core(old_task); + if (orig_task) + orig_task->flags &= ~TASK_SWITCH_IN_PROGRESS; +#endif + } } void reschedule(void) diff --git a/kernel/tests.c b/kernel/tests.c index ecef70c2..5b67a06d 100644 --- a/kernel/tests.c +++ b/kernel/tests.c @@ -33,6 +33,12 @@ #include #include + +#include "client.h" +#include "server.h" + +#include "shell.h" + #endif static sem_t consuming, producing; @@ -44,14 +50,14 @@ static int consumer(void* arg) int i, m = 0; for(i=0; i<5; i++) { - sem_wait(&consuming); + sem_wait(&consuming, 0); kprintf("Consumer got %d\n", val); val = 0; sem_post(&producing); } for(i=0; i<5; i++) { - mailbox_int32_fetch(&mbox, &m); + mailbox_int32_fetch(&mbox, &m, 0); kprintf("Got mail %d\n", m); } @@ -64,7 +70,7 @@ static int producer(void* arg) int mail[5] = {1, 2, 3, 4, 5}; for(i=0; i<5; i++) { - sem_wait(&producing); + sem_wait(&producing, 0); kprintf("Produce value: current val %d\n", val); val = 42; sem_post(&consuming); @@ -125,136 +131,146 @@ static int join_test(void* arg) } #if defined(CONFIG_LWIP) && defined(CONFIG_ROCKCREEK) -static int server_task(void* e) + +#define SHELLDEBUGPRINTF(x,...) kprintf(x,##__VA_ARGS__); + +static int srv_cnt = 0; +static Server srv; +void srv_on_read(ServerEventArgs* e) { - int sockfd, newsockfd, portno, clilen; - char buffer[256]; - struct sockaddr_in serv_addr, cli_addr; - int n; - - /* First call to socket() function */ - sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - if (sockfd < 0) - { - kprintf("ERROR opening socket"); - return -1; - } - /* Initialize socket structure */ - memset((char *) &serv_addr,0, sizeof(serv_addr)); - portno = 5001; - serv_addr.sin_family = AF_INET; - serv_addr.sin_addr.s_addr = INADDR_ANY; - serv_addr.sin_port = htons(portno); - - kprintf("binding"); - /* Now bind the host address using bind() call.*/ - if (bind(sockfd, (struct sockaddr *) &serv_addr, - sizeof(serv_addr)) < 0) - { - kprintf("ERROR on binding"); - return -1; - } - - /* Now start listening for the clients, here process will - * go in sleep mode and will wait for the incoming connection - */ - kprintf("listening"); - listen(sockfd,5); - clilen = sizeof(cli_addr); - - /* Accept actual connection from the client */ - kprintf("accepting"); - newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen); - if (newsockfd < 0) - { - kprintf("ERROR on accept"); - return -1; - } - /* If connection is established then start communicating */ - memset(buffer,0,256); - kprintf("recieving"); - n = read( newsockfd,buffer, 255); - if (n < 0) - { - kprintf("ERROR reading from socket"); - return -1; - } - kprintf("Here is the message: %s\n",buffer); - - /* Write a response to the client */ - kprintf("writing"); - n = write(newsockfd,"I got your message",18); - if (n < 0) - { - kprintf("ERROR writing to socket"); - return -1; - } - - return 0; + // kprintf("%i:",srv_cnt); + // hex_dump(e->dwLen,e->pBuffer); + // srv_cnt++; +/* printf("%i:",cnt); + puts(e->pBuffer); + puts("\n"); + cnt++; + */ } -static int client_task(void* e) +void srv_on_disc(ServerEventArgs*e ) { - char dir[256]; - int sd; - struct sockaddr_in pin; + kprintf("connection lost!!!\n"); +} - sleep(1); +void srv_on_conn(ServerEventArgs* e) +{ + int i = 0, err = 0; + int tmp1,tmp2; + char buff[1024]; - /* fill in the socket structure with host information */ - memset(&pin, 0, sizeof(pin)); - pin.sin_family = AF_INET; - pin.sin_addr.s_addr = inet_addr("192.168.0.1"); - pin.sin_port = htons(5001); + SHELLDEBUGPRINTF("someone finally connected\n"); - /* grab an Internet domain socket */ - if ((sd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) { - kprintf("socketfail"); - return -1; - } + tmp1 = get_clock_tick(); + for (i = 0; i < 1024*4; i++) + { + err = srv_sendBuffer(&srv,e->ClientID,buff,sizeof(buff)); + if ( err < 0) + { + SHELLDEBUGPRINTF("err: %d", err); + } - kprintf("connecting with socket nr : %d",sd); - /* connect to PORT on HOST */ + if (!(i%10)) + { + SHELLDEBUGPRINTF("\r-%d-",i); + } - if (connect(sd,(struct sockaddr *) &pin, sizeof(pin)) == -1) { - kprintf("connectfail"); - return -1; - } - kprintf("sending"); - /* send a message to the server PORT on machine HOST */ - if (send(sd, "HELLO THERE", strlen("HELLO THERE"), 0) == -1) { - kprintf("sendfail"); - return -1; - } - kprintf("recieving"); - /* wait for a message to come back from the server */ - if (recv(sd, dir, 256, 0) == -1) { - kprintf("recvfail"); - return -1; - } + } + tmp2 = get_clock_tick(); - /* spew-out the results and bail out of here! */ - kprintf("%s\n", dir); +// SHELLDEBUGPRINTF("send with %f kb/s",((float)i*sizeof(buff))/(tmp2-tmp1)); + SHELLDEBUGPRINTF("send %d bytes in %d ticks",i*sizeof(buff),(tmp2-tmp1)); +} - close(sd); +void* server_task(void* e) +{ + SHELLDEBUGPRINTF("created server\n"); - return 0; + server_init(&srv,5555,2); + + srv._OnRead = srv_on_read; + srv._OnDisconnect = srv_on_disc; + srv._OnConnect = srv_on_conn; + + while(1) + sleep(2); + + return NULL; +} + +static int cli_cnt = 0; +void cli_on_read(ClientEventArgs* e) +{ + kprintf("\r-%d-",cli_cnt); + cli_cnt++; +// printf("%i:",cnt); +// hex_dump(e->dwLen,e->pBuffer); +// cnt++; +/* puts(e->pBuffer); + puts("\n"); + cnt++; +*/ +} + +void cli_on_disc(ClientEventArgs*e ) +{ + kprintf("connection lost!!!\n"); +} + + +void* client_task(void* e) +{ + int err = -2; + Client cli; + char netbuffer[256]; + kprintf("created client"); + cli_init(&cli); + cli._OnRead = cli_on_read; + cli._OnDisconnect = cli_on_disc; + sleep(2); + + SHELLDEBUGPRINTF("Client is ready...\n"); + while (err) + { + sleep(1); + err = cli_ConnectTo(&cli,"192.168.0.1",5555,0); + SHELLDEBUGPRINTF("retry connect err = %d socket: %d\n",err,cli.sSocket); + } + SHELLDEBUGPRINTF("connected\n"); + + sleep(1); + err = cli_sendBuffer(&cli,"Hallo Welt",sizeof("Hallo Welt")); + SHELLDEBUGPRINTF("send message err = %d\n",err); + + + while(1) + sleep(2); + + return NULL; } #endif int test_init(void) { char* argv[] = {"/bin/tests", NULL}; + char* server_argv[] = {"/bin/server", "6789", NULL}; + char* client_argv[] = {"/bin/client", "127.0.0.1", "6789", NULL}; sem_init(&producing, 1); sem_init(&consuming, 0); mailbox_int32_init(&mbox); -#if 0 //defined(CONFIG_LWIP) && defined(CONFIG_ROCKCREEK) - if (!RCCE_ue()) - create_kernel_task(NULL,server_task,NULL); - else - create_kernel_task(NULL,client_task,NULL); +#if defined(CONFIG_LWIP) && defined(CONFIG_ROCKCREEK) + +// shell_init(RCCE_ue()); +// +// sleep(10); +// SHELLDEBUGPRINTF("hello World! I AM CORE NO. %d =) \n",RCCE_ue()); + +// if (!RCCE_ue()) +// create_kernel_task(NULL,server_task,NULL); +// else +// create_kernel_task(NULL,client_task,NULL); #endif create_kernel_task(NULL, foo, "Hello from foo1"); @@ -266,6 +282,9 @@ int test_init(void) create_user_task(NULL, "/bin/tests", argv); //create_user_task(NULL, "/bin/jacobi", argv); //create_user_task(NULL, "/bin/jacobi", argv); + create_user_task(NULL, "/bin/server", server_argv); + //sleep(5); + //create_user_task(NULL, "/bin/client", client_argv); return 0; } diff --git a/lwip/src/arch/sys_arch.c b/lwip/src/arch/sys_arch.c index 47c6e6ec..b46f0fd7 100644 --- a/lwip/src/arch/sys_arch.c +++ b/lwip/src/arch/sys_arch.c @@ -32,18 +32,22 @@ #define FALSE 0 #endif +#if SYS_LIGHTWEIGHT_PROT +#if MAX_CORES > 1 +static spinlock_irqsave_t lwprot_lock; +#endif +#endif + /** Returns the current time in milliseconds, * may be the same as sys_jiffies or at least based on it. */ -u32_t -sys_now(void) +u32_t sys_now(void) { - return (get_clock_tick() / TIMER_FREQ) * 1000; + return (get_clock_tick() / TIMER_FREQ) * 1000; } -u32_t -sys_jiffies(void) +u32_t sys_jiffies(void) { - return (get_clock_tick() / TIMER_FREQ) * 1000; + return (get_clock_tick() / TIMER_FREQ) * 1000; } #if !NO_SYS @@ -51,9 +55,13 @@ sys_jiffies(void) /* sys_init(): init needed system resources * Note: At the moment there are none */ -void -sys_init(void) +void sys_init(void) { +#if SYS_LIGHTWEIGHT_PROT +#if MAX_CORES > 1 + spinlock_irqsave_init(&lwprot_lock); +#endif +#endif } /** @@ -61,28 +69,24 @@ sys_init(void) * * @param ms number of milliseconds to sleep */ -void -sys_msleep(u32_t ms) +void sys_msleep(u32_t ms) { - if (ms > 0) { - sys_sem_t delaysem; - err_t err = sys_sem_new(&delaysem, 0); - if (err == ERR_OK) { - sys_arch_sem_wait(&delaysem, ms); - sys_sem_free(&delaysem); - } - } + if (ms * TIMER_FREQ / 1000 > 0) + timer_wait(ms * TIMER_FREQ / 1000); + else if (ms > 0) + udelay(ms * 1000); } /* sys_thread_new(): Spawns a new thread with given attributes as supported * Note: In MetalSVM this is realized as kernel tasks */ -sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio) +sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, + int stacksize, int prio) { - tid_t tmp; + sys_thread_t tmp; - kprintf("Create LWIP task %s\n", name); - create_kernel_task(&tmp,thread,arg); + create_kernel_task(&tmp, thread, arg); + kprintf("Created LWIP task %s with id %u\n", name, tmp); return tmp; } @@ -108,10 +112,10 @@ int sys_sem_valid(sys_sem_t* sem) /* sys_sem_new(): creates a new semaphre with given count. * This semaphore becomes valid */ -err_t sys_sem_new(sys_sem_t* sem,u8_t count) +err_t sys_sem_new(sys_sem_t* sem, u8_t count) { sem->valid = TRUE; - return sem_init(&sem->sem,count); + return sem_init(&sem->sem, count); } /* sys_sem_set_invalid(): this semapohore becomes invalid @@ -137,16 +141,11 @@ void sys_sem_signal(sys_sem_t* sem) u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout) { int err; - if (!timeout) - return sem_wait(&sem->sem); - while (timeout) - { - err = sem_trywait(&sem->sem); - if (err != -1) - return err; - udelay(1000); - timeout--; - } + + err = sem_wait(&sem->sem, timeout); + if (!err) + return 0; + return SYS_ARCH_TIMEOUT; } @@ -164,16 +163,11 @@ int sys_mbox_valid(sys_mbox_t * mbox) */ u32_t sys_arch_mbox_fetch(sys_mbox_t * mbox, void **msg, u32_t timeout) { - if (!timeout) - return mailbox_ptr_fetch(&mbox->mailbox,msg); + int err; - while(timeout) - { - if (!mailbox_ptr_tryfetch(&mbox->mailbox,msg)) - return 0; - udelay(1000); - timeout--; - } + err = mailbox_ptr_fetch(&mbox->mailbox, msg, timeout); + if (!err) + return 0; return SYS_ARCH_TIMEOUT; } @@ -192,13 +186,13 @@ void sys_mbox_free(sys_mbox_t* mbox) */ u32_t sys_arch_mbox_tryfetch(sys_mbox_t* mbox, void** msg) { - return mailbox_ptr_tryfetch(&mbox->mailbox,msg); + mailbox_ptr_tryfetch(&mbox->mailbox, msg); } /* sys_mbox_new(): create a new mailbox with a minimum size of "size" * */ -err_t sys_mbox_new(sys_mbox_t* mbox,int size) +err_t sys_mbox_new(sys_mbox_t* mbox, int size) { mbox->valid = TRUE; return mailbox_ptr_init(&mbox->mailbox); @@ -218,15 +212,19 @@ void sys_mbox_set_invalid(sys_mbox_t* mbox) */ err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg) { - return mailbox_ptr_post(&mbox->mailbox,msg); + int err; + + err = mailbox_ptr_trypost(&mbox->mailbox, msg); + + return err; } /* sys_mbox_post(): post new data to the mailbox * */ -void sys_mbox_post(sys_mbox_t* mbox,void* msg) +void sys_mbox_post(sys_mbox_t* mbox, void* msg) { - mailbox_ptr_post(&mbox->mailbox,msg); + mailbox_ptr_post(&mbox->mailbox, msg); } /* sys_mutex_lock(): lock the given mutex @@ -235,7 +233,7 @@ void sys_mbox_post(sys_mbox_t* mbox,void* msg) */ void sys_mutex_lock(sys_mutex_t* mutex) { - sem_wait(mutex); + sem_wait(mutex, 0); } /* sys_mutex_unlock(): unlock the given mutex @@ -251,23 +249,22 @@ void sys_mutex_unlock(sys_mutex_t* mutex) */ err_t sys_mutex_new(sys_mutex_t * mutex) { - sem_init(mutex,1); + sem_init(mutex, 1); return 0; } #if SYS_LIGHTWEIGHT_PROT #if MAX_CORES > 1 -static spinlock_irqsave_t lwprot_lock = SPINLOCK_IRQSAVE_INIT; - sys_prot_t sys_arch_protect(void) { - spinlock_irqsave_lock(&lwprot_lock); - return 0; + spinlock_irqsave_lock(&lwprot_lock); + return 0; } void sys_arch_unprotect(sys_prot_t pval) { - spinlock_irqsave_unlock(&lwprot_lock); + LWIP_UNUSED_ARG(pval); + spinlock_irqsave_unlock(&lwprot_lock); } #endif #endif diff --git a/lwip/src/include/arch/cc.h b/lwip/src/include/arch/cc.h index 94fb22ee..3474f573 100644 --- a/lwip/src/include/arch/cc.h +++ b/lwip/src/include/arch/cc.h @@ -81,5 +81,5 @@ typedef size_t mem_ptr_t; #define LWIP_PLATFORM_ASSERT(x) do {kprintf("Assertion \"%s\" failed at line %d in %s\n", \ x, __LINE__, __FILE__); abort();} while(0) - + #endif /* __ARCH_CC_H__ */ diff --git a/lwip/src/include/arch/sys_arch.h b/lwip/src/include/arch/sys_arch.h index eab88cb5..e71a6d36 100644 --- a/lwip/src/include/arch/sys_arch.h +++ b/lwip/src/include/arch/sys_arch.h @@ -21,7 +21,7 @@ typedef struct int valid; } sys_mbox_t; -typedef tid_t* sys_thread_t; +typedef tid_t sys_thread_t; #if SYS_LIGHTWEIGHT_PROT #if MAX_CORES > 1 @@ -43,4 +43,10 @@ static inline void sys_arch_unprotect(sys_prot_t pval) #endif #endif +/* define errno to determine error code */ +#ifdef CONFIG_LWIP +#define ERRNO +#define errno per_core(current_task)->lwip_err +#endif + #endif /* __ARCH_SYS_ARCH_H__ */ diff --git a/lwip/src/include/lwipopts.h b/lwip/src/include/lwipopts.h index 4be7eb4c..fb9ebf6e 100644 --- a/lwip/src/include/lwipopts.h +++ b/lwip/src/include/lwipopts.h @@ -117,5 +117,10 @@ #define NETIF_DEBUG LWIP_DBG_ON #define TIMERS_DEBUG LWIP_DBG_OFF #define SOCKETS_DEBUG LWIP_DBG_OFF +#define PBUF_DEBUG LWIP_DBG_OFF +// we need this feature to avoid memcpy operation between user- and kernel space +#define LWIP_TCPIP_CORE_LOCKING 1 + +//#define LWIP_TCPIP_THREAD_ALIVE() kputs("TCPIP thread is alive!\n") #endif diff --git a/newlib/Makefile b/newlib/Makefile index 07751473..be63ebef 100644 --- a/newlib/Makefile +++ b/newlib/Makefile @@ -16,13 +16,17 @@ TMP = $(TOPDIR)/tmp OPT = --disable-shared --disable-multilib --enable-newlib-hw-fp default: $(ARCH) - $(MAKE) -C examples depend + $(MAKE) CFLAGS+="-nostdinc -Wall -fno-builtin -I$(NEWLIB)/include -I../../include -I../../arch/$(ARCH)/include" LDFLAGS+="-nostdlib -L$(NEWLIB)/lib" -C net depend + $(MAKE) CFLAGS+="-nostdinc -Wall -fno-builtin -I$(NEWLIB)/include -I../../include -I../../arch/$(ARCH)/include" LDFLAGS+="-nostdlib -L$(NEWLIB)/lib" -C net + $(MAKE) CFLAGS+="-nostdinc -Wall -fno-builtin -I$(NEWLIB)/include -I../../include -I../../arch/$(ARCH)/include" LDFLAGS+="-nostdlib -L$(NEWLIB)/lib" -C examples depend $(MAKE) CFLAGS+="-nostdinc -Wall -fno-builtin -I$(NEWLIB)/include -I../../include -I../../arch/$(ARCH)/include" LDFLAGS+="-nostdlib -L$(NEWLIB)/lib" -C examples $(ARCH): $(RM) $(TMP) $(MKDIR) $(TMP) $(CD) $(TMP); $(TOPDIR)/src/configure --target=$(TARGET) --prefix=$(TOPDIR)/$(ARCH) $(OPT) && make && make install + $(MKDIR) $(NEWLIB)/include/netinet + $(MKDIR) $(NEWLIB)/include/arpa clean: $(MAKE) -C examples clean diff --git a/newlib/examples/Makefile b/newlib/examples/Makefile index e1a373f9..4e2a747f 100644 --- a/newlib/examples/Makefile +++ b/newlib/examples/Makefile @@ -11,7 +11,7 @@ LDFLAGS = default: all -all: hello tests jacobi +all: hello tests jacobi server client jacobi: jacobi.o $(CC_FOR_TARGET) -T link.ld -o $@ $(LDFLAGS) $< -lm @@ -31,8 +31,20 @@ hello: hello.o $(OBJCOPY_FOR_TARGET) $(STRIP_DEBUG) $@ chmod a-x $@.sym +server: server.o + $(CC_FOR_TARGET) -T link.ld -o $@ $(LDFLAGS) $< -lsocket + $(OBJCOPY_FOR_TARGET) $(KEEP_DEBUG) $@ $@.sym + $(OBJCOPY_FOR_TARGET) $(STRIP_DEBUG) $@ + chmod a-x $@.sym + +client: client.o + $(CC_FOR_TARGET) -T link.ld -o $@ $(LDFLAGS) $< -lsocket + $(OBJCOPY_FOR_TARGET) $(KEEP_DEBUG) $@ $@.sym + $(OBJCOPY_FOR_TARGET) $(STRIP_DEBUG) $@ + chmod a-x $@.sym + clean: - $(RM) hello tests *.sym *.o *~ + $(RM) hello tests server client *.sym *.o *~ depend: $(CC_FOR_TARGET) -MM $(CFLAGS) *.c > Makefile.dep diff --git a/newlib/examples/client.c b/newlib/examples/client.c new file mode 100644 index 00000000..ae1f0a0a --- /dev/null +++ b/newlib/examples/client.c @@ -0,0 +1,57 @@ +/* derived form http://www.cs.put.poznan.pl/csobaniec/examples/sockets/client-tcp-simple.c */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#undef errno +extern int errno; + +#define MAX_BUF 100 + +int main(int argc, char* argv[]) +{ + int sockd; + int count; + struct sockaddr_in serv_name; + char buf[MAX_BUF]; + int status; + + if (argc < 3) + { + fprintf(stderr, "Usage: %s ip_address port_number\n", argv[0]); + exit(1); + } + /* create a socket */ + sockd = socket(AF_INET, SOCK_STREAM, 0); + if (sockd == -1) + { + perror("Socket creation"); + exit(1); + } + + /* server address */ + serv_name.sin_family = AF_INET; + inet_aton(argv[1], &serv_name.sin_addr); + serv_name.sin_port = htons(atoi(argv[2])); + + /* connect to the server */ + status = connect(sockd, (struct sockaddr*)&serv_name, sizeof(serv_name)); + if (status == -1) + { + perror("Connection error"); + exit(1); + } + + count = read(sockd, buf, MAX_BUF); + write(1, buf, count); + + close(sockd); + + return 0; +} diff --git a/newlib/examples/server.c b/newlib/examples/server.c new file mode 100644 index 00000000..35e09e43 --- /dev/null +++ b/newlib/examples/server.c @@ -0,0 +1,72 @@ +/* derived from http://www.cs.put.poznan.pl/csobaniec/examples/sockets/server-tcp-simple.c */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#undef errno +extern int errno; + +static char msg[] =" Hello from server!\n"; + +int main(int argc, char* argv[]) +{ + int sockd, sockd2; + unsigned int addrlen; + struct sockaddr_in my_name, peer_name; + int status; + + /* create a socket */ + sockd = socket(AF_INET, SOCK_STREAM, 0); + if (sockd == -1) + { + perror("Socket creation error"); + exit(1); + } + + if (argc < 2) + { + fprintf(stderr, "Usage: %s port_number\n", argv[0]); + exit(1); + } + + /* server address */ + my_name.sin_family = AF_INET; + my_name.sin_addr.s_addr = INADDR_ANY; + my_name.sin_port = htons(atoi(argv[1])); + + status = bind(sockd, (struct sockaddr*)&my_name, sizeof(my_name)); + if (status == -1) + { + perror("Binding error"); + exit(1); + } + + status = listen(sockd, 5); + if (status == -1) + { + perror("Listening error"); + exit(1); + } + + while(1) + { + /* wait for a connection */ + addrlen = sizeof(peer_name); + sockd2 = accept(sockd, (struct sockaddr*)&peer_name, &addrlen); + if (sockd2 == -1) + { + perror("Wrong connection"); + exit(1); + } + write(sockd2, msg, strlen(msg)+1); + close(sockd2); + } + + return 0; +} diff --git a/newlib/net/Makefile b/newlib/net/Makefile new file mode 100644 index 00000000..4d8e4bce --- /dev/null +++ b/newlib/net/Makefile @@ -0,0 +1,34 @@ +ARCH = x86 +NEWLIB = ../x86/i586-metalsvm-elf32 +MAKE = make +STRIP_DEBUG = --strip-debug +KEEP_DEBUG = --only-keep-debug +LDFLAGS = +LIBNAME = libsocket.a +ARFLAGS = ruv +CP = cp +OBJS = accept.o bind.o closesocket.o connect.o listen.o recv.o send.o socket.o ip_addr.o + +# other implicit rules +%.o : %.c + $(CC_FOR_TARGET) -c $(CFLAGS) -o $@ $< + +default: all + +all: $(LIBNAME) + +$(LIBNAME): $(OBJS) socket.h + $(AR_FOR_TARGET) $(ARFLAGS) $@ $(OBJS) + $(CP) $@ $(NEWLIB)/lib + $(CP) socket.h $(NEWLIB)/include/sys + $(CP) in.h $(NEWLIB)/include/netinet + $(CP) inet.h $(NEWLIB)/include/arpa + +clean: + $(RM) $(LIBNAME) *.o *~ + +depend: + $(CC_FOR_TARGET) -MM $(CFLAGS) *.c > Makefile.dep + +-include Makefile.dep +# DO NOT DELETE diff --git a/newlib/net/accept.c b/newlib/net/accept.c new file mode 100644 index 00000000..e188200f --- /dev/null +++ b/newlib/net/accept.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2011, Carl-Benedikt Krueger, Chair for Operating Systems, + * RWTH Aachen University + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include <_ansi.h> +#include <_syslist.h> +#include +#undef errno +extern int errno; +#include "warning.h" +#include "syscall.h" + + +int +_DEFUN (accept, (s, addr, addrlen), + int s _AND void *addr _AND void *addrlen) +{ + int ret; + + ret = SYSCALL3(__NR_accept, s, addr, addrlen); + if (ret < 0) { + errno = -ret; + ret = -1; + } + + return ret; +} diff --git a/newlib/net/bind.c b/newlib/net/bind.c new file mode 100644 index 00000000..9adecc22 --- /dev/null +++ b/newlib/net/bind.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2011, Carl-Benedikt Krueger, Chair for Operating Systems, + * RWTH Aachen University + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include <_ansi.h> +#include <_syslist.h> +#include +#undef errno +extern int errno; +#include "warning.h" +#include "syscall.h" + + +int +_DEFUN (bind, (s, name, namelen), + int s _AND void *name _AND int namelen) +{ + int ret; + + ret = SYSCALL3(__NR_bind, s, name, namelen); + if (ret < 0) { + errno = -ret; + ret = -1; + } + + return ret; +} diff --git a/newlib/net/closesocket.c b/newlib/net/closesocket.c new file mode 100644 index 00000000..edcf03b6 --- /dev/null +++ b/newlib/net/closesocket.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2011, Carl-Benedikt Krueger, Chair for Operating Systems, + * RWTH Aachen University + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include <_ansi.h> +#include <_syslist.h> +#include +#undef errno +extern int errno; +#include "warning.h" +#include "syscall.h" + + +int +_DEFUN (closesocket, (s), + int s) +{ + int ret; + + ret = SYSCALL1(__NR_closesocket, s); + if (ret < 0) { + errno = -ret; + ret = -1; + } + + return ret; +} diff --git a/newlib/net/config.h b/newlib/net/config.h new file mode 100644 index 00000000..962b38e3 --- /dev/null +++ b/newlib/net/config.h @@ -0,0 +1,26 @@ +/* Name of package. */ +#define PACKAGE libsocket + +/* Version of package. */ +#define VERSION 0.1 + +/* Missing syscall names */ +#define MISSING_SYSCALL_NAMES 1 + +/* Using ELF format */ +#define HAVE_ELF 1 + +/* Using GNU LD */ +#define HAVE_GNU_LD 1 + +/* .previous directive allowed */ +#define HAVE_ASM_PREVIOUS_DIRECTIVE 1 + +/* .pushsection/.popsection directives allowed */ +#define HAVE_ASM_POPSECTION_DIRECTIVE 1 + +/* support for section attributes */ +#define HAVE_SECTION_ATTRIBUTES 1 + +/* symbol prefix */ +#define __SYMBOL_PREFIX "" diff --git a/newlib/net/connect.c b/newlib/net/connect.c new file mode 100644 index 00000000..f737d44f --- /dev/null +++ b/newlib/net/connect.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2011, Carl-Benedikt Krueger, Chair for Operating Systems, + * RWTH Aachen University + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include <_ansi.h> +#include <_syslist.h> +#include +#undef errno +extern int errno; +#include "warning.h" +#include "syscall.h" + + +int +_DEFUN (connect, (s, name, namelen), + int s _AND void *name _AND int namelen) +{ + int ret; + + ret = SYSCALL3(__NR_connect, s, name, namelen); + if (ret < 0) { + errno = -ret; + ret = -1; + } + + return ret; +} diff --git a/newlib/net/in.h b/newlib/net/in.h new file mode 100644 index 00000000..cd676dbe --- /dev/null +++ b/newlib/net/in.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * The kernel of MetalSVM uses LwIP as lightweight TCP/IP stack. + * This header defines only a small wrapper to use LwIP functions + * from user space. + */ + +#ifndef __NETINET_IN_H__ +#define __NETINET_IN_H__ + +#include +#include + +#ifdef __cplusplus +{ +#endif + +struct in_addr { + uint32_t s_addr; +}; + +/** 255.255.255.255 */ +#define IPADDR_NONE ((uint32_t)0xffffffffUL) +/** 127.0.0.1 */ +#define IPADDR_LOOPBACK ((uint32_t)0x7f000001UL) +/** 0.0.0.0 */ +#define IPADDR_ANY ((uint32_t)0x00000000UL) +/** 255.255.255.255 */ +#define IPADDR_BROADCAST ((uint32_t)0xffffffffUL) + +/** 255.255.255.255 */ +#define INADDR_NONE IPADDR_NONE +/** 127.0.0.1 */ +#define INADDR_LOOPBACK IPADDR_LOOPBACK +/** 0.0.0.0 */ +#define INADDR_ANY IPADDR_ANY +/** 255.255.255.255 */ +#define INADDR_BROADCAST IPADDR_BROADCAST + +#ifdef __cplusplus +} +#endif + +#endif /* __NETINET_IN_H__ */ diff --git a/newlib/net/inet.h b/newlib/net/inet.h new file mode 100644 index 00000000..39bbc745 --- /dev/null +++ b/newlib/net/inet.h @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * The kernel of MetalSVM uses LwIP as lightweight TCP/IP stack. + * This header defines only a small wrapper to use LwIP functions + * from user space. + */ + +#ifndef __ARPA_INET_H__ +#define __ARPA_INET_H__ + +#include +#include + +#ifdef __cplusplus +{ +#endif + +/* + * This is the aligned version of ip_addr_t, + * used as local variable, on the stack, etc. + */ +struct ip_addr { + uint32_t addr; +}; + +#ifndef LITTLE_ENDIAN +// Convert an uint16_t from host- to network byte order. +static inline uint16_t htons(uint16_t n) +{ + return ((n & 0xff) << 8) | ((n & 0xff00) >> 8); +} + +// Convert an uint16_t from network- to host byte order. +static inline uint16_t ntohs(uint16_t n) +{ + return htons(n); +} + +// Convert an uint32_t from host- to network byte order. +static inline uint32_t htonl(uint32_t n) +{ + return ((n & 0xff) << 24) | ((n & 0xff00) << 8) | ((n & 0xff0000UL) >> 8) | + ((n & 0xff000000UL) >> 24); +} + +// Convert an uint32_t from network- to host byte order. +static inline uint32_t ntohl(uint32_t n) +{ + return htonl(n); +} +#else +#error currently not supported!!! +#endif + + +/** ip_addr_t uses a struct for convenience only, so that the same defines can + * operate both on ip_addr_t as well as on ip_addr_p_t. */ +typedef struct ip_addr ip_addr_t; +//typedef struct ip_addr_packed ip_addr_p_t; + +uint32_t ipaddr_addr(const char *cp); +int ipaddr_aton(const char *cp, ip_addr_t *addr); +/** returns ptr to static buffer; not reentrant! */ +char *ipaddr_ntoa(const ip_addr_t *addr); +char *ipaddr_ntoa_r(const ip_addr_t *addr, char *buf, int buflen); + +/* directly map this to the lwip internal functions */ +#define inet_addr(cp) ipaddr_addr(cp) +#define inet_aton(cp, addr) ipaddr_aton(cp, (ip_addr_t*)addr) +#define inet_ntoa(addr) ipaddr_ntoa((ip_addr_t*)&(addr)) +#define inet_ntoa_r(addr, buf, buflen) ipaddr_ntoa_r((ip_addr_t*)&(addr), buf, buflen) + +#ifdef __cplusplus +} +#endif + +#endif /* __NETINET_IN_H__ */ diff --git a/newlib/net/ip_addr.c b/newlib/net/ip_addr.c new file mode 100644 index 00000000..53e19db1 --- /dev/null +++ b/newlib/net/ip_addr.c @@ -0,0 +1,336 @@ +/** + * @file + * This is the IPv4 address tools implementation. + * + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ + +/* + * LwIP backports of helper function for user-space applications + */ +#include "inet.h" +#include + +/* Define generic types used in lwIP */ +typedef uint8_t u8_t; +typedef int8_t s8_t; +typedef uint16_t u16_t; +typedef int16_t s16_t; +typedef uint32_t u32_t; +typedef int32_t s32_t; + +#define LWIP_ASSERT(message, assertion) do { if(!(assertion)) \ + fprintf(stderr, message); } while(0) + +/** IPv4 only: set the IP address given as an u32_t */ +#define ip4_addr_set_u32(dest_ipaddr, src_u32) ((dest_ipaddr)->addr = (src_u32)) +/** IPv4 only: get the IP address as an u32_t */ +#define ip4_addr_get_u32(src_ipaddr) ((src_ipaddr)->addr) + +#if 0 +#include "lwip/opt.h" +#include "lwip/ip_addr.h" +#include "lwip/netif.h" + +/* used by IP_ADDR_ANY and IP_ADDR_BROADCAST in ip_addr.h */ +const ip_addr_t ip_addr_any = { IPADDR_ANY }; +const ip_addr_t ip_addr_broadcast = { IPADDR_BROADCAST }; + +/** + * Determine if an address is a broadcast address on a network interface + * + * @param addr address to be checked + * @param netif the network interface against which the address is checked + * @return returns non-zero if the address is a broadcast address + */ +u8_t +ip4_addr_isbroadcast(u32_t addr, const struct netif *netif) +{ + ip_addr_t ipaddr; + ip4_addr_set_u32(&ipaddr, addr); + + /* all ones (broadcast) or all zeroes (old skool broadcast) */ + if ((~addr == IPADDR_ANY) || + (addr == IPADDR_ANY)) { + return 1; + /* no broadcast support on this network interface? */ + } else if ((netif->flags & NETIF_FLAG_BROADCAST) == 0) { + /* the given address cannot be a broadcast address + * nor can we check against any broadcast addresses */ + return 0; + /* address matches network interface address exactly? => no broadcast */ + } else if (addr == ip4_addr_get_u32(&netif->ip_addr)) { + return 0; + /* on the same (sub) network... */ + } else if (ip_addr_netcmp(&ipaddr, &(netif->ip_addr), &(netif->netmask)) + /* ...and host identifier bits are all ones? =>... */ + && ((addr & ~ip4_addr_get_u32(&netif->netmask)) == + (IPADDR_BROADCAST & ~ip4_addr_get_u32(&netif->netmask)))) { + /* => network broadcast address */ + return 1; + } else { + return 0; + } +} + +/** Checks if a netmask is valid (starting with ones, then only zeros) + * + * @param netmask the IPv4 netmask to check (in network byte order!) + * @return 1 if the netmask is valid, 0 if it is not + */ +u8_t +ip4_addr_netmask_valid(u32_t netmask) +{ + u32_t mask; + u32_t nm_hostorder = lwip_htonl(netmask); + + /* first, check for the first zero */ + for (mask = 1UL << 31 ; mask != 0; mask >>= 1) { + if ((nm_hostorder & mask) == 0) { + break; + } + } + /* then check that there is no one */ + for (; mask != 0; mask >>= 1) { + if ((nm_hostorder & mask) != 0) { + /* there is a one after the first zero -> invalid */ + return 0; + } + } + /* no one after the first zero -> valid */ + return 1; +} + +/* Here for now until needed in other places in lwIP */ +#ifndef isprint +#define in_range(c, lo, up) ((u8_t)c >= lo && (u8_t)c <= up) +#define isprint(c) in_range(c, 0x20, 0x7f) +#define isdigit(c) in_range(c, '0', '9') +#define isxdigit(c) (isdigit(c) || in_range(c, 'a', 'f') || in_range(c, 'A', 'F')) +#define islower(c) in_range(c, 'a', 'z') +#define isspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v') +#endif + +/** + * Ascii internet address interpretation routine. + * The value returned is in network order. + * + * @param cp IP address in ascii represenation (e.g. "127.0.0.1") + * @return ip address in network order + */ +u32_t +ipaddr_addr(const char *cp) +{ + ip_addr_t val; + + if (ipaddr_aton(cp, &val)) { + return ip4_addr_get_u32(&val); + } + return (IPADDR_NONE); +} +#endif + +/** + * Check whether "cp" is a valid ascii representation + * of an Internet address and convert to a binary address. + * Returns 1 if the address is valid, 0 if not. + * This replaces inet_addr, the return value from which + * cannot distinguish between failure and a local broadcast address. + * + * @param cp IP address in ascii represenation (e.g. "127.0.0.1") + * @param addr pointer to which to save the ip address in network order + * @return 1 if cp could be converted to addr, 0 on failure + */ +int +ipaddr_aton(const char *cp, ip_addr_t *addr) +{ + u32_t val; + u8_t base; + char c; + u32_t parts[4]; + u32_t *pp = parts; + + c = *cp; + for (;;) { + /* + * Collect number up to ``.''. + * Values are specified as for C: + * 0x=hex, 0=octal, 1-9=decimal. + */ + if (!isdigit(c)) + return (0); + val = 0; + base = 10; + if (c == '0') { + c = *++cp; + if (c == 'x' || c == 'X') { + base = 16; + c = *++cp; + } else + base = 8; + } + for (;;) { + if (isdigit(c)) { + val = (val * base) + (int)(c - '0'); + c = *++cp; + } else if (base == 16 && isxdigit(c)) { + val = (val << 4) | (int)(c + 10 - (islower(c) ? 'a' : 'A')); + c = *++cp; + } else + break; + } + if (c == '.') { + /* + * Internet format: + * a.b.c.d + * a.b.c (with c treated as 16 bits) + * a.b (with b treated as 24 bits) + */ + if (pp >= parts + 3) { + return (0); + } + *pp++ = val; + c = *++cp; + } else + break; + } + /* + * Check for trailing characters. + */ + if (c != '\0' && !isspace(c)) { + return (0); + } + /* + * Concoct the address according to + * the number of parts specified. + */ + switch (pp - parts + 1) { + + case 0: + return (0); /* initial nondigit */ + + case 1: /* a -- 32 bits */ + break; + + case 2: /* a.b -- 8.24 bits */ + if (val > 0xffffffUL) { + return (0); + } + val |= parts[0] << 24; + break; + + case 3: /* a.b.c -- 8.8.16 bits */ + if (val > 0xffff) { + return (0); + } + val |= (parts[0] << 24) | (parts[1] << 16); + break; + + case 4: /* a.b.c.d -- 8.8.8.8 bits */ + if (val > 0xff) { + return (0); + } + val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); + break; + default: + LWIP_ASSERT("unhandled", 0); + break; + } + if (addr) { + ip4_addr_set_u32(addr, htonl(val)); + } + return (1); +} + +/** + * Convert numeric IP address into decimal dotted ASCII representation. + * returns ptr to static buffer; not reentrant! + * + * @param addr ip address in network order to convert + * @return pointer to a global static (!) buffer that holds the ASCII + * represenation of addr + */ +char * +ipaddr_ntoa(const ip_addr_t *addr) +{ + static char str[16]; + return ipaddr_ntoa_r(addr, str, 16); +} + +/** + * Same as ipaddr_ntoa, but reentrant since a user-supplied buffer is used. + * + * @param addr ip address in network order to convert + * @param buf target buffer where the string is stored + * @param buflen length of buf + * @return either pointer to buf which now holds the ASCII + * representation of addr or NULL if buf was too small + */ +char *ipaddr_ntoa_r(const ip_addr_t *addr, char *buf, int buflen) +{ + u32_t s_addr; + char inv[3]; + char *rp; + u8_t *ap; + u8_t rem; + u8_t n; + u8_t i; + int len = 0; + + s_addr = ip4_addr_get_u32(addr); + + rp = buf; + ap = (u8_t *)&s_addr; + for(n = 0; n < 4; n++) { + i = 0; + do { + rem = *ap % (u8_t)10; + *ap /= (u8_t)10; + inv[i++] = '0' + rem; + } while(*ap); + while(i--) { + if (len++ >= buflen) { + return NULL; + } + *rp++ = inv[i]; + } + if (len++ >= buflen) { + return NULL; + } + *rp++ = '.'; + ap++; + } + *--rp = 0; + return buf; +} diff --git a/newlib/net/listen.c b/newlib/net/listen.c new file mode 100644 index 00000000..699bfcd1 --- /dev/null +++ b/newlib/net/listen.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2011, Carl-Benedikt Krueger, Chair for Operating Systems, + * RWTH Aachen University + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include <_ansi.h> +#include <_syslist.h> +#include +#undef errno +extern int errno; +#include "warning.h" +#include "syscall.h" + + +int +_DEFUN (listen, (s, backlog), + int s _AND int backlog) +{ + int ret; + + ret = SYSCALL2(__NR_listen, s, backlog); + if (ret < 0) { + errno = -ret; + ret = -1; + } + + return ret; +} diff --git a/newlib/net/recv.c b/newlib/net/recv.c new file mode 100644 index 00000000..cd7a39e1 --- /dev/null +++ b/newlib/net/recv.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2011, Carl-Benedikt Krueger, Chair for Operating Systems, + * RWTH Aachen University + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include <_ansi.h> +#include <_syslist.h> +#include +#undef errno +extern int errno; +#include "warning.h" +#include "syscall.h" + + +int +_DEFUN (recv, (s, data, size,flags), + int s _AND void *data _AND int size _AND int flags) +{ + int ret; + + ret = SYSCALL4(__NR_recv, s, data, size, flags); + if (ret < 0) { + errno = -ret; + ret = -1; + } + + return ret; +} diff --git a/newlib/net/send.c b/newlib/net/send.c new file mode 100644 index 00000000..939a5262 --- /dev/null +++ b/newlib/net/send.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2011, Carl-Benedikt Krueger, Chair for Operating Systems, + * RWTH Aachen University + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include <_ansi.h> +#include <_syslist.h> +#include +#undef errno +extern int errno; +#include "warning.h" +#include "syscall.h" + + +int +_DEFUN (send, (s, data, size,flags), + int s _AND void *data _AND int size _AND int flags) +{ + int ret; + + ret = SYSCALL4(__NR_send, s, data, size, flags); + if (ret < 0) { + errno = -ret; + ret = -1; + } + + return ret; +} diff --git a/newlib/net/socket.c b/newlib/net/socket.c new file mode 100644 index 00000000..0e7d850b --- /dev/null +++ b/newlib/net/socket.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2011, Carl-Benedikt Krueger, Chair for Operating Systems, + * RWTH Aachen University + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include <_ansi.h> +#include <_syslist.h> +#include +#undef errno +extern int errno; +#include "warning.h" +#include "syscall.h" + + +int +_DEFUN (socket, (domain, type, protocol), + int domain _AND int type _AND int protocol) +{ + int ret; + + ret = SYSCALL3(__NR_socket, domain, type, protocol); + if (ret < 0) { + errno = -ret; + ret = -1; + } + + return ret; +} diff --git a/newlib/net/socket.h b/newlib/net/socket.h new file mode 100644 index 00000000..92d9ad0f --- /dev/null +++ b/newlib/net/socket.h @@ -0,0 +1,323 @@ +/* + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * The kernel of MetalSVM uses LwIP as lightweight TCP/IP stack. + * This header defines only a small wrapper to use LwIP functions + * from user space. + */ + +#ifndef __SOCKET_H__ +#define __SOCKET_H__ + +#include +#include +#include +#include + +#ifdef __cplusplus +{ +#endif + +struct sockaddr_in { + uint8_t sin_len; + uint8_t sin_family; + uint16_t sin_port; + struct in_addr sin_addr; + char sin_zero[8]; +}; + +struct sockaddr { + uint8_t sa_len; + uint8_t sa_family; + char sa_data[14]; +}; + +#ifndef socklen_t +# define socklen_t uint32_t +#endif + +/* Socket protocol types (TCP/UDP/RAW) */ +#define SOCK_STREAM 1 +#define SOCK_DGRAM 2 +#define SOCK_RAW 3 + +/* + * Option flags per-socket. These must match the SOF_ flags in ip.h (checked in init.c) + */ +#define SO_DEBUG 0x0001 /* Unimplemented: turn on debugging info recording */ +#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */ +#define SO_REUSEADDR 0x0004 /* Allow local address reuse */ +#define SO_KEEPALIVE 0x0008 /* keep connections alive */ +#define SO_DONTROUTE 0x0010 /* Unimplemented: just use interface addresses */ +#define SO_BROADCAST 0x0020 /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */ +#define SO_USELOOPBACK 0x0040 /* Unimplemented: bypass hardware when possible */ +#define SO_LINGER 0x0080 /* linger on close if data present */ +#define SO_OOBINLINE 0x0100 /* Unimplemented: leave received OOB data in line */ +#define SO_REUSEPORT 0x0200 /* Unimplemented: allow local address & port reuse */ + +#define SO_DONTLINGER ((int)(~SO_LINGER)) + +/* + * Additional options, not kept in so_options. + */ +#define SO_SNDBUF 0x1001 /* Unimplemented: send buffer size */ +#define SO_RCVBUF 0x1002 /* receive buffer size */ +#define SO_SNDLOWAT 0x1003 /* Unimplemented: send low-water mark */ +#define SO_RCVLOWAT 0x1004 /* Unimplemented: receive low-water mark */ +#define SO_SNDTIMEO 0x1005 /* Unimplemented: send timeout */ +#define SO_RCVTIMEO 0x1006 /* receive timeout */ +#define SO_ERROR 0x1007 /* get error status and clear */ +#define SO_TYPE 0x1008 /* get socket type */ +#define SO_CONTIMEO 0x1009 /* Unimplemented: connect timeout */ +#define SO_NO_CHECK 0x100a /* don't create UDP checksum */ + + +/* + * Structure used for manipulating linger option. + */ +struct linger { + int l_onoff; /* option on/off */ + int l_linger; /* linger time */ +}; + +/* + * Level number for (get/set)sockopt() to apply to socket itself. + */ +#define SOL_SOCKET 0xfff /* options for socket level */ + + +#define AF_UNSPEC 0 +#define AF_INET 2 +#define PF_INET AF_INET +#define PF_UNSPEC AF_UNSPEC + +#define IPPROTO_IP 0 +#define IPPROTO_TCP 6 +#define IPPROTO_UDP 17 +#define IPPROTO_UDPLITE 136 + +/* Flags we can use with send and recv. */ +#define MSG_PEEK 0x01 /* Peeks at an incoming message */ +#define MSG_WAITALL 0x02 /* Unimplemented: Requests that the function block until the full amount of data requested can be returned */ +#define MSG_OOB 0x04 /* Unimplemented: Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific */ +#define MSG_DONTWAIT 0x08 /* Nonblocking i/o for this operation only */ +#define MSG_MORE 0x10 /* Sender will send more */ + + +/* + * Options for level IPPROTO_IP + */ +#define IP_TOS 1 +#define IP_TTL 2 + +/* + * Options for level IPPROTO_TCP + */ +#define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */ +#define TCP_KEEPALIVE 0x02 /* send KEEPALIVE probes when idle for pcb->keep_idle milliseconds */ +#define TCP_KEEPIDLE 0x03 /* set pcb->keep_idle - Same as TCP_KEEPALIVE, but use seconds for get/setsockopt */ +#define TCP_KEEPINTVL 0x04 /* set pcb->keep_intvl - Use seconds for get/setsockopt */ +#define TCP_KEEPCNT 0x05 /* set pcb->keep_cnt - Use number of probes sent for get/setsockopt */ + +/* + * Options for level IPPROTO_UDPLITE + */ +#define UDPLITE_SEND_CSCOV 0x01 /* sender checksum coverage */ +#define UDPLITE_RECV_CSCOV 0x02 /* minimal receiver checksum coverage */ + + +/* + * Options and types for UDP multicast traffic handling + */ +#define IP_ADD_MEMBERSHIP 3 +#define IP_DROP_MEMBERSHIP 4 +#define IP_MULTICAST_TTL 5 +#define IP_MULTICAST_IF 6 +#define IP_MULTICAST_LOOP 7 + +typedef struct ip_mreq { + struct in_addr imr_multiaddr; /* IP multicast address of group */ + struct in_addr imr_interface; /* local IP address of interface */ +} ip_mreq; + +/* + * The Type of Service provides an indication of the abstract + * parameters of the quality of service desired. These parameters are + * to be used to guide the selection of the actual service parameters + * when transmitting a datagram through a particular network. Several + * networks offer service precedence, which somehow treats high + * precedence traffic as more important than other traffic (generally + * by accepting only traffic above a certain precedence at time of high + * load). The major choice is a three way tradeoff between low-delay, + * high-reliability, and high-throughput. + * The use of the Delay, Throughput, and Reliability indications may + * increase the cost (in some sense) of the service. In many networks + * better performance for one of these parameters is coupled with worse + * performance on another. Except for very unusual cases at most two + * of these three indications should be set. + */ +#define IPTOS_TOS_MASK 0x1E +#define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK) +#define IPTOS_LOWDELAY 0x10 +#define IPTOS_THROUGHPUT 0x08 +#define IPTOS_RELIABILITY 0x04 +#define IPTOS_LOWCOST 0x02 +#define IPTOS_MINCOST IPTOS_LOWCOST + +/* + * The Network Control precedence designation is intended to be used + * within a network only. The actual use and control of that + * designation is up to each network. The Internetwork Control + * designation is intended for use by gateway control originators only. + * If the actual use of these precedence designations is of concern to + * a particular network, it is the responsibility of that network to + * control the access to, and use of, those precedence designations. + */ +#define IPTOS_PREC_MASK 0xe0 +#define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK) +#define IPTOS_PREC_NETCONTROL 0xe0 +#define IPTOS_PREC_INTERNETCONTROL 0xc0 +#define IPTOS_PREC_CRITIC_ECP 0xa0 +#define IPTOS_PREC_FLASHOVERRIDE 0x80 +#define IPTOS_PREC_FLASH 0x60 +#define IPTOS_PREC_IMMEDIATE 0x40 +#define IPTOS_PREC_PRIORITY 0x20 +#define IPTOS_PREC_ROUTINE 0x00 + + +/* + * Commands for ioctlsocket(), taken from the BSD file fcntl.h. + * lwip_ioctl only supports FIONREAD and FIONBIO, for now + * + * Ioctl's have the command encoded in the lower word, + * and the size of any in or out parameters in the upper + * word. The high 2 bits of the upper word are used + * to encode the in/out status of the parameter; for now + * we restrict parameters to at most 128 bytes. + */ +#if !defined(FIONREAD) || !defined(FIONBIO) +#define IOCPARM_MASK 0x7fU /* parameters must be < 128 bytes */ +#define IOC_VOID 0x20000000UL /* no parameters */ +#define IOC_OUT 0x40000000UL /* copy out parameters */ +#define IOC_IN 0x80000000UL /* copy in parameters */ +#define IOC_INOUT (IOC_IN|IOC_OUT) + /* 0x20000000 distinguishes new & + old ioctl's */ +#define _IO(x,y) (IOC_VOID|((x)<<8)|(y)) + +#define _IOR(x,y,t) (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y)) + +#define _IOW(x,y,t) (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y)) +#endif /* !defined(FIONREAD) || !defined(FIONBIO) */ + +#ifndef FIONREAD +#define FIONREAD _IOR('f', 127, unsigned long) /* get # bytes to read */ +#endif +#ifndef FIONBIO +#define FIONBIO _IOW('f', 126, unsigned long) /* set/clear non-blocking i/o */ +#endif + +/* Socket I/O Controls: unimplemented */ +#ifndef SIOCSHIWAT +#define SIOCSHIWAT _IOW('s', 0, unsigned long) /* set high watermark */ +#define SIOCGHIWAT _IOR('s', 1, unsigned long) /* get high watermark */ +#define SIOCSLOWAT _IOW('s', 2, unsigned long) /* set low watermark */ +#define SIOCGLOWAT _IOR('s', 3, unsigned long) /* get low watermark */ +#define SIOCATMARK _IOR('s', 7, unsigned long) /* at oob mark? */ +#endif + +/* commands for fnctl */ +#ifndef F_GETFL +#define F_GETFL 3 +#endif +#ifndef F_SETFL +#define F_SETFL 4 +#endif + +/* File status flags and file access modes for fnctl, + these are bits in an int. */ +#ifndef O_NONBLOCK +#define O_NONBLOCK 1 /* nonblocking I/O */ +#endif +#ifndef O_NDELAY +#define O_NDELAY 1 /* same as O_NONBLOCK, for compatibility */ +#endif + +#ifndef SHUT_RD + #define SHUT_RD 0 + #define SHUT_WR 1 + #define SHUT_RDWR 2 +#endif + +/* FD_SET used for lwip_select */ +#ifndef FD_SET + #undef FD_SETSIZE + /* Make FD_SETSIZE match NUM_SOCKETS in socket.c */ + #define FD_SETSIZE MEMP_NUM_NETCONN + #define FD_SET(n, p) ((p)->fd_bits[(n)/8] |= (1 << ((n) & 7))) + #define FD_CLR(n, p) ((p)->fd_bits[(n)/8] &= ~(1 << ((n) & 7))) + #define FD_ISSET(n,p) ((p)->fd_bits[(n)/8] & (1 << ((n) & 7))) + #define FD_ZERO(p) memset((void*)(p),0,sizeof(*(p))) + + typedef struct fd_set { + unsigned char fd_bits [(FD_SETSIZE+7)/8]; + } fd_set; + +#endif /* FD_SET */ + +int accept(int s, struct sockaddr *addr, socklen_t *addrlen); +int bind(int s, const struct sockaddr *name, socklen_t namelen); +int getpeername (int s, struct sockaddr *name, socklen_t *namelen); +int getsockname (int s, struct sockaddr *name, socklen_t *namelen); +int getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen); +int setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen); +int connect(int s, const struct sockaddr *name, socklen_t namelen); +int listen(int s, int backlog); +int recv(int s, void *mem, size_t len, int flags); +int recvfrom(int s, void *mem, size_t len, int flags, + struct sockaddr *from, socklen_t *fromlen); +int send(int s, const void *dataptr, size_t size, int flags); +int sendto(int s, const void *dataptr, size_t size, int flags, + const struct sockaddr *to, socklen_t tolen); +int socket(int domain, int type, int protocol); +//int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, +// struct timeval *timeout); +//int ioctl(int s, long cmd, void *argp); +//int fcntl(int s, int cmd, int val); + +#ifdef __cplusplus +} +#endif + +#endif /* __SOCKET_H__ */ diff --git a/newlib/net/syscall.h b/newlib/net/syscall.h new file mode 100644 index 00000000..5bd58118 --- /dev/null +++ b/newlib/net/syscall.h @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of MetalSVM. + */ + +#ifndef __SYSCALL_H__ +#define __SYSCALL_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#define __NR_exit 0 +#define __NR_write 1 +#define __NR_open 2 +#define __NR_close 3 +#define __NR_read 4 +#define __NR_lseek 6 +#define __NR_unlink 7 +#define __NR_getpid 8 +#define __NR_kill 9 +#define __NR_fstat 10 +#define __NR_sbrk 11 +#define __NR_fork 12 +#define __NR_wait 13 +#define __NR_execve 14 +#define __NR_times 15 +#define __NR_accept 16 +#define __NR_bind 17 +#define __NR_closesocket 18 +#define __NR_connect 19 +#define __NR_listen 20 +#define __NR_recv 21 +#define __NR_send 22 +#define __NR_socket 23 + +#define _STR(token) #token +#define _SYSCALLSTR(x) "int $" _STR(x) " " +#define INT_SYSCALL 0x80 + +inline static long +syscall(int nr, unsigned long arg0, unsigned long arg1, unsigned long arg2, + unsigned long arg3, unsigned long arg4) +{ + long res; + + asm volatile (_SYSCALLSTR(INT_SYSCALL) + : "=a" (res) + : "0" (nr), "b" (arg0), "c" (arg1), "d" (arg2), "S" (arg3), "D" (arg4) + : "memory", "cc"); + + return res; +} + +#define SYSCALL0(NR) \ + syscall(NR, 0, 0, 0, 0, 0) +#define SYSCALL1(NR, ARG1) \ + syscall(NR, (unsigned long)ARG1, 0, 0, 0, 0) +#define SYSCALL2(NR, ARG1, ARG2) \ + syscall(NR, (unsigned long)ARG1, (unsigned long)ARG2, 0, 0, 0) +#define SYSCALL3(NR, ARG1, ARG2, ARG3) \ + syscall(NR, (unsigned long)ARG1, (unsigned long)ARG2, (unsigned long)ARG3, 0, 0) +#define SYSCALL4(NR, ARG1, ARG2, ARG3, ARG4) \ + syscall(NR, (unsigned long)ARG1, (unsigned long)ARG2, (unsigned long)ARG3, (unsigned long) ARG4, 0) +#define SYSCALL5(NR, ARG1, ARG2, ARG3, ARG4) \ + syscall(NR, (unsigned long)ARG1, (unsigned long)ARG2, (unsigned long)ARG3, (unsigned long) ARG4, (unsigned long) ARG5) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/newlib/net/warning.h b/newlib/net/warning.h new file mode 100644 index 00000000..9232a924 --- /dev/null +++ b/newlib/net/warning.h @@ -0,0 +1,44 @@ +#ifndef __WARNING_H__ +#define __WARNING_H__ + +#ifdef HAVE_GNU_LD +# ifdef HAVE_ELF + +/* We want the .gnu.warning.SYMBOL section to be unallocated. */ +# ifdef HAVE_ASM_PREVIOUS_DIRECTIVE +# define __make_section_unallocated(section_string) \ + asm(".section " section_string "\n .previous"); +# elif defined (HAVE_ASM_POPSECTION_DIRECTIVE) +# define __make_section_unallocated(section_string) \ + asm(".pushsection " section_string "\n .popsection"); +# else +# define __make_section_unallocated(section_string) +# endif + +# ifdef HAVE_SECTION_ATTRIBUTES +# define link_warning(symbol, msg) \ + static const char __evoke_link_warning_##symbol[] \ + __attribute__ ((section (".gnu.warning." __SYMBOL_PREFIX #symbol), \ + __used__)) = msg; +# else +# define link_warning(symbol, msg) +# endif + +#else /* !ELF */ + +# define link_warning(symbol, msg) \ + asm(".stabs \"" msg "\",30,0,0,0\n" \ + ".stabs \"" __SYMBOL_PREFIX #symbol "\",1,0,0,0\n"); +# endif +#else /* !GNULD */ +/* We will never be heard; they will all die horribly. */ +# define link_warning(symbol, msg) +#endif + +/* A canned warning for sysdeps/stub functions. + The GNU linker prepends a "warning: " string. */ +#define stub_warning(name) \ + link_warning (name, \ + #name " is not implemented and will always fail") + +#endif /* __WARNING_H__ */ diff --git a/newlib/src/libgloss/metalsvm/_exit.c b/newlib/src/libgloss/metalsvm/_exit.c index 78499875..ab8fb363 100644 --- a/newlib/src/libgloss/metalsvm/_exit.c +++ b/newlib/src/libgloss/metalsvm/_exit.c @@ -1,20 +1,36 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * This file is part of MetalSVM. + * This file is part of MetalSVM. */ #include "config.h" diff --git a/newlib/src/libgloss/metalsvm/chown.c b/newlib/src/libgloss/metalsvm/chown.c index 323538d4..028e904a 100644 --- a/newlib/src/libgloss/metalsvm/chown.c +++ b/newlib/src/libgloss/metalsvm/chown.c @@ -1,18 +1,34 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of MetalSVM. */ diff --git a/newlib/src/libgloss/metalsvm/close.c b/newlib/src/libgloss/metalsvm/close.c index 5bcf18e6..e5e64d22 100644 --- a/newlib/src/libgloss/metalsvm/close.c +++ b/newlib/src/libgloss/metalsvm/close.c @@ -1,18 +1,34 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of MetalSVM. */ diff --git a/newlib/src/libgloss/metalsvm/crt0.asm b/newlib/src/libgloss/metalsvm/crt0.asm index a1130587..5cca9cee 100644 --- a/newlib/src/libgloss/metalsvm/crt0.asm +++ b/newlib/src/libgloss/metalsvm/crt0.asm @@ -1,20 +1,35 @@ -; -; Copyright 2010 Stefan Lankes, Chair for Operating Systems, -; RWTH Aachen University -; -; Licensed under the Apache License, Version 2.0 (the "License"); -; you may not use this file except in compliance with the License. -; You may obtain a copy of the License at -; -; http://www.apache.org/licenses/LICENSE-2.0 -; -; Unless required by applicable law or agreed to in writing, software -; distributed under the License is distributed on an "AS IS" BASIS, -; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -; See the License for the specific language governing permissions and -; limitations under the License. -; -; This file is part of MetalSVM. + ; Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + ; RWTH Aachen University + ; + ; All rights reserved. + ; + ; Redistribution and use in source and binary forms, with or without + ; modification, are permitted provided that the following conditions are met: + ; 1. Redistributions of source code must retain the above copyright + ; notice, this list of conditions and the following disclaimer. + ; 2. Redistributions in binary form must reproduce the above copyright + ; notice, this list of conditions and the following disclaimer in the + ; documentation and/or other materials provided with the distribution. + ; 3. All advertising materials mentioning features or use of this software + ; must display the following acknowledgement: + ; This product includes software developed by the Chair for Operating Systems, + ; RWTH Aachen University. + ; 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + ; nor the names of its contributors may be used to endorse or promote products + ; derived from this software without specific prior written permission. + ; + ; THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + ; EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + ; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + ; DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + ; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + ; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + ; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + ; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + ; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ; + ; This file is part of MetalSVM. [BITS 32] SECTION .text diff --git a/newlib/src/libgloss/metalsvm/environ.c b/newlib/src/libgloss/metalsvm/environ.c index 2274cfb9..6bf7f583 100644 --- a/newlib/src/libgloss/metalsvm/environ.c +++ b/newlib/src/libgloss/metalsvm/environ.c @@ -1,18 +1,34 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of MetalSVM. */ diff --git a/newlib/src/libgloss/metalsvm/errno.c b/newlib/src/libgloss/metalsvm/errno.c index c6289903..c61abbb3 100644 --- a/newlib/src/libgloss/metalsvm/errno.c +++ b/newlib/src/libgloss/metalsvm/errno.c @@ -1,18 +1,34 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of MetalSVM. */ diff --git a/newlib/src/libgloss/metalsvm/execve.c b/newlib/src/libgloss/metalsvm/execve.c index 285b8248..45fa7614 100644 --- a/newlib/src/libgloss/metalsvm/execve.c +++ b/newlib/src/libgloss/metalsvm/execve.c @@ -1,18 +1,34 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of MetalSVM. */ diff --git a/newlib/src/libgloss/metalsvm/fork.c b/newlib/src/libgloss/metalsvm/fork.c index 91864ee9..606c388c 100644 --- a/newlib/src/libgloss/metalsvm/fork.c +++ b/newlib/src/libgloss/metalsvm/fork.c @@ -1,18 +1,34 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of MetalSVM. */ diff --git a/newlib/src/libgloss/metalsvm/fstat.c b/newlib/src/libgloss/metalsvm/fstat.c index 51e1dbf5..54fbc09a 100644 --- a/newlib/src/libgloss/metalsvm/fstat.c +++ b/newlib/src/libgloss/metalsvm/fstat.c @@ -1,18 +1,34 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of MetalSVM. */ diff --git a/newlib/src/libgloss/metalsvm/getpid.c b/newlib/src/libgloss/metalsvm/getpid.c index 9c386e00..ca3f23f0 100644 --- a/newlib/src/libgloss/metalsvm/getpid.c +++ b/newlib/src/libgloss/metalsvm/getpid.c @@ -1,18 +1,34 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of MetalSVM. */ diff --git a/newlib/src/libgloss/metalsvm/gettod.c b/newlib/src/libgloss/metalsvm/gettod.c index 6fdea902..0d2a9307 100644 --- a/newlib/src/libgloss/metalsvm/gettod.c +++ b/newlib/src/libgloss/metalsvm/gettod.c @@ -1,18 +1,34 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of MetalSVM. */ diff --git a/newlib/src/libgloss/metalsvm/init.c b/newlib/src/libgloss/metalsvm/init.c index 74b2a283..be79d519 100644 --- a/newlib/src/libgloss/metalsvm/init.c +++ b/newlib/src/libgloss/metalsvm/init.c @@ -1,18 +1,34 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of MetalSVM. */ diff --git a/newlib/src/libgloss/metalsvm/isatty.c b/newlib/src/libgloss/metalsvm/isatty.c index 714b40f1..38952ee1 100644 --- a/newlib/src/libgloss/metalsvm/isatty.c +++ b/newlib/src/libgloss/metalsvm/isatty.c @@ -1,18 +1,34 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of MetalSVM. */ diff --git a/newlib/src/libgloss/metalsvm/kill.c b/newlib/src/libgloss/metalsvm/kill.c index 07315752..a883f9cc 100644 --- a/newlib/src/libgloss/metalsvm/kill.c +++ b/newlib/src/libgloss/metalsvm/kill.c @@ -1,18 +1,34 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of MetalSVM. */ diff --git a/newlib/src/libgloss/metalsvm/link.c b/newlib/src/libgloss/metalsvm/link.c index 2e030e5a..d2e0d793 100644 --- a/newlib/src/libgloss/metalsvm/link.c +++ b/newlib/src/libgloss/metalsvm/link.c @@ -1,18 +1,34 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of MetalSVM. */ diff --git a/newlib/src/libgloss/metalsvm/lseek.c b/newlib/src/libgloss/metalsvm/lseek.c index 82328753..f263ad72 100644 --- a/newlib/src/libgloss/metalsvm/lseek.c +++ b/newlib/src/libgloss/metalsvm/lseek.c @@ -1,18 +1,34 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of MetalSVM. */ diff --git a/newlib/src/libgloss/metalsvm/open.c b/newlib/src/libgloss/metalsvm/open.c index c7f40c14..918d2dc9 100644 --- a/newlib/src/libgloss/metalsvm/open.c +++ b/newlib/src/libgloss/metalsvm/open.c @@ -1,18 +1,34 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of MetalSVM. */ diff --git a/newlib/src/libgloss/metalsvm/read.c b/newlib/src/libgloss/metalsvm/read.c index a240d838..057f725c 100644 --- a/newlib/src/libgloss/metalsvm/read.c +++ b/newlib/src/libgloss/metalsvm/read.c @@ -1,18 +1,34 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of MetalSVM. */ diff --git a/newlib/src/libgloss/metalsvm/readlink.c b/newlib/src/libgloss/metalsvm/readlink.c index db23173e..004872f4 100644 --- a/newlib/src/libgloss/metalsvm/readlink.c +++ b/newlib/src/libgloss/metalsvm/readlink.c @@ -1,18 +1,34 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of MetalSVM. */ diff --git a/newlib/src/libgloss/metalsvm/sbrk.c b/newlib/src/libgloss/metalsvm/sbrk.c index 78002469..25948a43 100644 --- a/newlib/src/libgloss/metalsvm/sbrk.c +++ b/newlib/src/libgloss/metalsvm/sbrk.c @@ -1,18 +1,34 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of MetalSVM. */ diff --git a/newlib/src/libgloss/metalsvm/stat.c b/newlib/src/libgloss/metalsvm/stat.c index 4d008a9f..4ab81546 100644 --- a/newlib/src/libgloss/metalsvm/stat.c +++ b/newlib/src/libgloss/metalsvm/stat.c @@ -1,18 +1,34 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of MetalSVM. */ diff --git a/newlib/src/libgloss/metalsvm/symlink.c b/newlib/src/libgloss/metalsvm/symlink.c index a4ddef46..c2ccc403 100644 --- a/newlib/src/libgloss/metalsvm/symlink.c +++ b/newlib/src/libgloss/metalsvm/symlink.c @@ -1,18 +1,34 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of MetalSVM. */ diff --git a/newlib/src/libgloss/metalsvm/syscall.h b/newlib/src/libgloss/metalsvm/syscall.h index 6d137508..5bd58118 100644 --- a/newlib/src/libgloss/metalsvm/syscall.h +++ b/newlib/src/libgloss/metalsvm/syscall.h @@ -1,20 +1,36 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * Standard x86 syscalls for user programs running under MetalSVM + * This file is part of MetalSVM. */ #ifndef __SYSCALL_H__ @@ -39,6 +55,14 @@ extern "C" { #define __NR_wait 13 #define __NR_execve 14 #define __NR_times 15 +#define __NR_accept 16 +#define __NR_bind 17 +#define __NR_closesocket 18 +#define __NR_connect 19 +#define __NR_listen 20 +#define __NR_recv 21 +#define __NR_send 22 +#define __NR_socket 23 #define _STR(token) #token #define _SYSCALLSTR(x) "int $" _STR(x) " " diff --git a/newlib/src/libgloss/metalsvm/times.c b/newlib/src/libgloss/metalsvm/times.c index 5c4ebcd7..9f294ef7 100644 --- a/newlib/src/libgloss/metalsvm/times.c +++ b/newlib/src/libgloss/metalsvm/times.c @@ -1,18 +1,34 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of MetalSVM. */ diff --git a/newlib/src/libgloss/metalsvm/unlink.c b/newlib/src/libgloss/metalsvm/unlink.c index 23f2b763..5e26561c 100644 --- a/newlib/src/libgloss/metalsvm/unlink.c +++ b/newlib/src/libgloss/metalsvm/unlink.c @@ -1,18 +1,34 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of MetalSVM. */ diff --git a/newlib/src/libgloss/metalsvm/wait.c b/newlib/src/libgloss/metalsvm/wait.c index 166bef02..f4392ec9 100644 --- a/newlib/src/libgloss/metalsvm/wait.c +++ b/newlib/src/libgloss/metalsvm/wait.c @@ -1,18 +1,34 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of MetalSVM. */ diff --git a/newlib/src/libgloss/metalsvm/write.c b/newlib/src/libgloss/metalsvm/write.c index 8c0fd3c0..b1f1d17a 100644 --- a/newlib/src/libgloss/metalsvm/write.c +++ b/newlib/src/libgloss/metalsvm/write.c @@ -1,18 +1,34 @@ /* - * Copyright 2010 Stefan Lankes, Chair for Operating Systems, - * RWTH Aachen University + * Copyright (c) 2011, Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen University + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of MetalSVM. */ diff --git a/tools/prepare.sh b/tools/prepare.sh index c94b5104..961cb45e 100755 --- a/tools/prepare.sh +++ b/tools/prepare.sh @@ -9,3 +9,13 @@ if [ $SIZE -ne 0 ]; then else echo not patching $NAME fi; + +NAME=initrd.img +SIZE=`ls -ld "$NAME" | awk '{print $5 % 64}'` +if [ $SIZE -ne 0 ]; then + echo "$NAME: patching $SIZE Zero-Bytes" + dd if=/dev/zero of=zero.bin bs=1 count=$SIZE + cat zero.bin >> $NAME +else + echo not patching $NAME +fi;