/* * 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. */ #include #include #include #include #include #include #include #include #include #include #ifdef CONFIG_PCI #include #endif #ifdef CONFIG_LWIP #include #include #include #include #include #include #include //#include #endif static sem_t consuming, producing; static mailbox_t mbox; static int val = 0; extern const void kernel_start; extern const void kernel_end; void* STDCALL consumer(void* arg) { int i; int* m = NULL; for(i=0; i<5; i++) { sem_wait(&consuming); kprintf("Consumer got %d\n", val); val = 0; sem_post(&producing); } for(i=0; i<5; i++) { mailbox_fetch(&mbox, (void**) &m); kprintf("Got mail %d\n", *m); } return NULL; } void* STDCALL producer(void* arg) { int i; int mail[5] = {1, 2, 3, 4, 5}; tid_t id; create_kernel_task(&id, consumer, NULL, 0); for(i=0; i<5; i++) { sem_wait(&producing); kprintf("Produce value: current val %d\n", val); val = 42; sem_post(&consuming); } for(i=0; i<5; i++) { //kprintf("Send mail %d\n", mail[i]); mailbox_post(&mbox, mail+i); } join_kernel_task(id, NULL); return NULL; } void* STDCALL foo(void* arg) { int i; if (!arg) return NULL; for(i=0; i<5; i++) { kputs((char*) arg); sleep(1); } return (void*) 42; } void* STDCALL join_test(void* arg) { int ret; tid_t id; void* result = NULL; ret = create_kernel_task(&id, foo, "Hello from foo2\n", 0); kprintf("Wait for task %u: ret = %d\n", id, ret); ret = join_kernel_task(id, &result); kprintf("Task %u finished: ret = %d, result = %u\n", id, ret, (int)result); return NULL; } #ifdef CONFIG_LWIP void* STDCALL lwip_task(void* arg) { struct netif netif; struct ip_addr ipaddr; struct ip_addr netmask; struct ip_addr gw; err_t err; sleep(10); kputs("LWIP task is started\n"); stats_init(); /* Clears the structure where runtime statistics are gathered */ sys_init(); mem_init(); /* Initializes the dynamic memory heap defined by MEM_SIZE. */ memp_init(); /* Initializes the memory pools defined by MEMP_NUM_x */ pbuf_init(); /* Initializes the pbuf memory pool defined by PBUF_POOL_SIZE. */ etharp_init(); /* Initializes the ARP table and queue. */ ip_init(); udp_init(); /* Clears the UDP PCB list */ tcp_init(); /* Clears the TCP PCB list and clears some internal TCP timers. */ /* Bring up the network interface */ //if (!netif_add(&netif, &ipaddr, &netmask, &gw, NULL, pcnetif_init, ethernet_input)) { // kputs("Unable to add network interface\n"); // return NULL; //} /* This will bring the interface up and set its IP address when it can acquire one. */ //err = dhcp_start(&netif); //if (err != ERR_OK) { // kprintf("Unable to get IP via DHCP: %s\n", lwip_strerr(err)); // return NULL; //} //if (netif_is_up(&netif)) { // kputs("Network interface is not up\n"); // return NULL; //} //while(1) { //} return 0; } #endif int main(void) { tid_t id1, id2, id3; #ifdef CONFIG_LWIP tid_t lwip_id; #endif system_init(); irq_init(); koutput_init(); timer_init(); #ifdef CONFIG_KEYBOARD keyboard_init(); #endif mmu_init(); multitasking_init(); irq_enable(); kprintf("Here is MetalSVM %s\n", METALSVM_VERSION); kprintf("Kernel starts at %p and ends at %p\n", &kernel_start, &kernel_end); detect_cpu_frequency(); kprintf("Processor frequency: %d MHz\n", get_cpu_frequency()/1000000); kprintf("Total memory: %u MBytes\n", atomic_size_read(&total_memory)/(1024*1024)); kprintf("Current allocated memory: %u KBytes\n", atomic_size_read(&total_allocated_memory)/1024); kprintf("Current available memory: %u MBytes\n", atomic_size_read(&total_available_memory)/(1024*1024)); #ifdef CONFIG_PCI print_pci_adapters(); #endif timer_set_frequency(TIMER_FREQ); sem_init(&producing, 1); sem_init(&consuming, 0); mailbox_init(&mbox); sleep(5); #ifdef CONFIG_LWIP //create_kernel_task(&lwip_id, lwip_task, NULL, 0); #endif create_kernel_task(&id1, foo, "Hello from foo1\n", 8192); create_kernel_task(&id2, join_test, NULL, 0); create_kernel_task(&id3, producer, NULL, 0); current_task->status = TASK_IDLE; schedule(); while(1) { NOP8; } return 0; }