From 79be93988822d10eb29bd9f402ceb0796f89e121 Mon Sep 17 00:00:00 2001 From: Mathias Gottschlag Date: Thu, 25 Dec 2008 14:16:55 +0100 Subject: [PATCH] - Fixed keGetUnixTime(). - Kernel now compiles with -Werror enabled. - Added ARCH variable for compiling on amd64. --- CMakeLists.txt | 2 ++ system/kernel/CMakeLists.txt | 12 ++++++++++-- system/kernel/ke/debug.c | 2 +- system/kernel/ke/signal.S | 3 ++- system/kernel/ke/spinlock.c | 1 + system/kernel/ke/timer.c | 39 ++++++++++++++++++++++++--------------- system/kernel/lwip/CMakeLists.txt | 1 - system/kernel/lwip/core/ipv4/ip.c | 6 ++++-- system/kernel/lwip/netif/etharp.c | 6 +++--- 9 files changed, 47 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c2c4a9f..6cc5305 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,8 @@ cmake_minimum_required(VERSION 2.6) project(planlOS C ASM-ATT) +set(ARCH "x86" CACHE STRING "Architecture (can be x86 or amd64)") + set(OBJECTS) macro(add_object name) set(OBJECTS ${OBJECTS} ${name} PARENT_SCOPE) diff --git a/system/kernel/CMakeLists.txt b/system/kernel/CMakeLists.txt index 8f977a7..a99f813 100644 --- a/system/kernel/CMakeLists.txt +++ b/system/kernel/CMakeLists.txt @@ -44,8 +44,16 @@ ke/smpstart.o ke/signal.o ) -set(CMAKE_C_FLAGS "-fstrength-reduce -fno-builtin -m32 -Wall -Wextra -Wno-unused-parameter -nostdlib -nostdinc -Wno-long-long") -set(CMAKE_ASM-ATT_FLAGS "--32") +string(COMPARE EQUAL "${ARCH}" "x86" IS_X86) +if(IS_X86) + message(STATUS "Building for x86.") + set(CMAKE_C_FLAGS "-fstrength-reduce -fno-builtin -m32 -Wall -Wextra -Werror -Wno-unused-parameter -nostdlib -nostdinc -Wno-long-long") + set(CMAKE_ASM-ATT_FLAGS "--32") +else(IS_X86) + message(STATUS "Building for amd64.") + set(CMAKE_C_FLAGS "-fstrength-reduce -fno-builtin -m64 -Wall -Wextra -Werror -Wno-unused-parameter -nostdlib -nostdinc -Wno-long-long") + set(CMAKE_ASM-ATT_FLAGS "--64") +endif(IS_X86) include_directories(../include ../include/lwip ../include/lwip/ipv4 ../../shared/include) add_custom_command(OUTPUT ke/smpstart.o COMMAND ${CMAKE_ASM-ATT_COMPILER} --32 -o smpstart2.o ke/smpstart.S && ld -o smpstart.o smpstart2.o -Ttext 0x1000 --oformat binary -m elf_i386 && objcopy -B i386 -I binary -O elf32-i386 smpstart.o ke/smpstart.o && rm smpstart.o smpstart2.o DEPENDS ke/smpstart.S) add_custom_command(OUTPUT ke/signal.o COMMAND ${CMAKE_ASM-ATT_COMPILER} --32 -o signal2.o ke/signal.S && ld -o signal.o signal2.o -Ttext 0xFFFFF000 --oformat binary -m elf_i386 && objcopy -B i386 -I binary -O elf32-i386 signal.o ke/signal.o && rm signal.o signal2.o DEPENDS ke/signal.S) diff --git a/system/kernel/ke/debug.c b/system/kernel/ke/debug.c index b4e11ac..d64872a 100644 --- a/system/kernel/ke/debug.c +++ b/system/kernel/ke/debug.c @@ -40,7 +40,7 @@ static int use_vga = 1; void keTerminalInitialized(void) { - use_vga = 0; + //use_vga = 0; } void kePrintInit(void) diff --git a/system/kernel/ke/signal.S b/system/kernel/ke/signal.S index ee3fda7..a1066d2 100644 --- a/system/kernel/ke/signal.S +++ b/system/kernel/ke/signal.S @@ -1,6 +1,7 @@ .code32 .org 0x0 -start: +.global _start +_start: pushal push -4(%ebp) mov -8(%ebp), %eax diff --git a/system/kernel/ke/spinlock.c b/system/kernel/ke/spinlock.c index 0052a7a..2cf71ee 100644 --- a/system/kernel/ke/spinlock.c +++ b/system/kernel/ke/spinlock.c @@ -21,6 +21,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "ke/spinlock.h" #include "ke/errors.h" +#include "ke/panic.h" int keDestroySpinlock(KeSpinlock *spinlock) { diff --git a/system/kernel/ke/timer.c b/system/kernel/ke/timer.c index 147c8f8..a398daa 100644 --- a/system/kernel/ke/timer.c +++ b/system/kernel/ke/timer.c @@ -249,7 +249,20 @@ static uint8_t keReadCMOS(uint8_t index) return inb(0x71); } -static unsigned int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +static unsigned int days[12] = { +31, +31 + 28, +31 + 28 + 31, +31 + 28 + 31 + 30, +31 + 28 + 31 + 30 + 31, +31 + 28 + 31 + 30 + 31 + 30, +31 + 28 + 31 + 30 + 31 + 30 + 31, +31 + 28 + 31 + 30 + 31 + 30 + 31 + 31, +31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30, +31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31, +31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30, +31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 +}; static int keIsLeapYear(unsigned int year) { @@ -277,21 +290,17 @@ uint32_t keGetUnixTime(void) month = (month & 0xF) + (month >> 4) * 10; year = (year & 0xF) + (year >> 4) * 10; century = (century & 0xF) + (century >> 4) * 10; - //kePrint("%d:%d:%d (%d.%d.%d)\n", hours, minutes, seconds, day, month, year + century * 100); + year += century * 100; + day--; // Add data - // FIXME: Broken. - uint32_t time = seconds + minutes * 60 + hours * 3600 + (day - 1) * 24 * 3600; - uint32_t i; - for (i = 0; i < month - 1; i++) - { - time += days[i] * 24 * 3600; - } - for (i = 1970; i < year + century * 100; i++) - { - time += 3600 * 24 * 365; - if (keIsLeapYear(year + century * 100)) time += 3600 * 24; - } - //kePrint("Time: %d\n", time); + if (month > 1) + day += days[month - 2]; + if ((month > 2) && keIsLeapYear(year)) + day++; + year -= 1900; + int time = seconds + minutes * 60 + hours * 3600 + day * 86400 + + (year - 70) * 31536000 + ((year - 69) / 4) * 86400 + - ((year - 1) / 100) * 86400 + ((year + 299) / 400) * 86400; return time; } diff --git a/system/kernel/lwip/CMakeLists.txt b/system/kernel/lwip/CMakeLists.txt index 585931c..384d25d 100644 --- a/system/kernel/lwip/CMakeLists.txt +++ b/system/kernel/lwip/CMakeLists.txt @@ -53,7 +53,6 @@ netif/ppp/ipcp.c netif/ppp/lcp.c netif/ppp/chpms.c netif/ppp/ppp_oe.c -netif/ethernetif.c ) include_directories(../../include ../../include/lwip ../../include/lwip/ipv4 ../../../shared/include) diff --git a/system/kernel/lwip/core/ipv4/ip.c b/system/kernel/lwip/core/ipv4/ip.c index fbcef5d..936b8cf 100644 --- a/system/kernel/lwip/core/ipv4/ip.c +++ b/system/kernel/lwip/core/ipv4/ip.c @@ -207,13 +207,15 @@ ip_input(struct pbuf *p, struct netif *inp) /* header length exceeds first pbuf length, or ip length exceeds total pbuf length? */ if ((iphdr_hlen > p->len) || (iphdr_len > p->tot_len)) { - if (iphdr_hlen > p->len) + if (iphdr_hlen > p->len) { LWIP_DEBUGF(IP_DEBUG | 2, ("IP header (len %"U16_F") does not fit in first pbuf (len %"U16_F"), IP packet dropped.\n", iphdr_hlen, p->len)); - if (iphdr_len > p->tot_len) + } + if (iphdr_len > p->tot_len) { LWIP_DEBUGF(IP_DEBUG | 2, ("IP (len %"U16_F") is longer than pbuf (len %"U16_F"), " "IP packet dropped.\n", iphdr_len, p->tot_len)); + } /* free (drop) packet pbufs */ pbuf_free(p); IP_STATS_INC(ip.lenerr); diff --git a/system/kernel/lwip/netif/etharp.c b/system/kernel/lwip/netif/etharp.c index 070b913..fe501b8 100644 --- a/system/kernel/lwip/netif/etharp.c +++ b/system/kernel/lwip/netif/etharp.c @@ -467,7 +467,7 @@ etharp_send_ip(struct netif *netif, struct pbuf *p, struct eth_addr *src, struct static err_t update_arp_entry(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr *ethaddr, u8_t flags) { - s8_t i; + s16_t i; u8_t k; LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | 3, ("update_arp_entry()\n")); LWIP_ASSERT("netif->hwaddr_len == ETHARP_HWADDR_LEN", netif->hwaddr_len == ETHARP_HWADDR_LEN); @@ -545,7 +545,7 @@ s8_t etharp_find_addr(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr **eth_ret, struct ip_addr **ip_ret) { - s8_t i; + s16_t i; LWIP_UNUSED_ARG(netif); @@ -876,7 +876,7 @@ etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q) { struct eth_addr * srcaddr = (struct eth_addr *)netif->hwaddr; err_t result = ERR_MEM; - s8_t i; /* ARP entry index */ + s16_t i; /* ARP entry index */ /* non-unicast address? */ if (ip_addr_isbroadcast(ipaddr, netif) || -- 2.11.4.GIT