From 4e6a3aa00d7dec5d58b14848048c2292171e049a Mon Sep 17 00:00:00 2001 From: Tomas 'ZeXx86' Jedrzejek Date: Thu, 2 Apr 2009 16:45:09 +0200 Subject: [PATCH] Fixed bug in sh app - memory corruption when you delete more characters then you wrote; Added new function to libzde - zgui_puts () and zgui_resize (); Added EXIT state to appsrv/appcl for succefull exit when you click on the window's cross; Improved MOVE state of window; Added some comments to ZDE sources; Dialogs are translucent; ztest app was improved; Real Time Clock was updated + realtime variable was deleted; Fixed sys_time () system call; System call sys_system () was improved and fixed - you are able to start new user process in user apps; ICMPv6 code was updated; Added support for NDP's Router Advertisement - IPv6 address is automaticaly configured with site packets of e.g. radvd software; Added support for public IPv6 address communication into NDP protocol; Small correction in function net_proto_ipv6_print (); Added function net_proto_ipv6_cmp_prefix () to compare IPv6 prefix with any next IPv6 address; Added GMM - initial Graphic Memory Manager implementation - something like graphics renderer accelerator - graphics rendering is faster then before (cca 60% performance boost); Updated libc functions time () and localtime_r (); Added ZDE app zclock - digital clock --- apps/sh/main.c | 14 ++-- apps/zde/appcl.c | 37 ++++++++-- apps/zde/appcl.h | 5 ++ apps/zde/appsrv.c | 16 +++++ apps/zde/appsrv.h | 1 + apps/zde/dialog.c | 16 +++++ apps/zde/handler.c | 9 +-- apps/zde/icon.c | 5 +- apps/zde/window.c | 34 ++++++--- apps/zde/window.h | 2 + apps/zde/{ztest => zclock}/Makefile | 14 ++-- apps/zde/zclock/README | 8 +++ apps/zde/zclock/link.ld | 48 +++++++++++++ apps/zde/{ztest => zclock}/main.c | 36 ++++++---- apps/zde/zclock/make_img.sh | 29 ++++++++ apps/zde/zclock/start.asm | 55 +++++++++++++++ apps/zde/ztest/Makefile | 6 +- apps/zde/ztest/main.c | 24 +++---- kernel/arch/i386/rtc.c | 81 ++++++++++++---------- kernel/arch/i386/syscall.c | 22 +++++- kernel/core/commands.c | 6 +- kernel/core/mm/kmem.c | 3 +- kernel/core/mm/kzmem.c | 3 +- kernel/core/net/icmp6.c | 23 ++++-- kernel/core/net/ipv6.c | 16 ++++- kernel/core/net/ndp.c | 135 +++++++++++++++++++++++++++++++++--- kernel/core/net/tcp6.c | 3 +- kernel/core/net/udp6.c | 3 +- kernel/defconfig | 3 +- kernel/drivers/Kconfig | 6 ++ kernel/drivers/char/video/video.c | 47 +++++++++---- kernel/include/net/ndp.h | 7 +- kernel/include/system.h | 6 +- libc/include/time.h | 2 + libc/time/localtime.c | 14 ++-- libc/time/time.c | 11 +-- 36 files changed, 597 insertions(+), 153 deletions(-) copy apps/zde/{ztest => zclock}/Makefile (73%) create mode 100644 apps/zde/zclock/README create mode 100644 apps/zde/zclock/link.ld copy apps/zde/{ztest => zclock}/main.c (68%) create mode 100755 apps/zde/zclock/make_img.sh create mode 100644 apps/zde/zclock/start.asm diff --git a/apps/sh/main.c b/apps/sh/main.c index 47873f0..8d9cb6f 100644 --- a/apps/sh/main.c +++ b/apps/sh/main.c @@ -26,7 +26,7 @@ #define SHELL_VERSION "0.0.2" char *cmdline; -unsigned cmdline_len; +int cmdline_len; unsigned key_pressed (int keycode) { @@ -97,12 +97,14 @@ int loop () ret = check_cmd (); cmdline_len = 0; } else { - if (c == '\b') - cmdline_len --; - else + if (c == '\b') { + if (cmdline_len > 0) + cmdline_len --; + } else cmdline_len ++; - - putch (c); + + if (cmdline_len >= 0) + putch (c); } } diff --git a/apps/zde/appcl.c b/apps/zde/appcl.c index e30983d..652cb54 100755 --- a/apps/zde/appcl.c +++ b/apps/zde/appcl.c @@ -31,19 +31,41 @@ #include "appcl.h" -char zstr[128]; +static char zstr[128]; int zappcl_fd; -appcl_t *zappcl; +static appcl_t *zappcl; +static unsigned short zsizex; +static unsigned short zsizey; +static unsigned zstate; appcl_t *zgui_window () { return zappcl; } +void zgui_puts (unsigned short x, unsigned short y, char *str, unsigned color) +{ + if (zappcl) + xtext_puts (zappcl->x+4+x, zappcl->y+21+y, color, str); +} + +int zgui_resize (unsigned short x, unsigned short y) +{ + if (!zappcl) + return -1; + + zsizex = x; + zsizey = y; + + zstate |= APPCL_STATE_RESIZE; + + return 0; +} + unsigned zgui_event () { - if (zappcl->state == APPCL_STATE_REDRAW) { + if (zappcl->state & APPCL_STATE_REDRAW) { zappcl->state &= ~APPCL_STATE_REDRAW; zappcl->state |= APPCL_STATE_RECVOK; @@ -52,8 +74,15 @@ unsigned zgui_event () int ret = ipc_recv (zappcl_fd, zstr, 128); - if (ret > 0) + if (ret > 0) { + if (zstate & APPCL_STATE_RESIZE) { + zappcl->sizex = zsizex; + zappcl->sizey = zsizey; + zappcl->state |= APPCL_STATE_RESIZE; + } + return zappcl->state; + } schedule (); diff --git a/apps/zde/appcl.h b/apps/zde/appcl.h index 94eef82..bb3ab47 100755 --- a/apps/zde/appcl.h +++ b/apps/zde/appcl.h @@ -22,6 +22,8 @@ #define APPCL_STATE_REDRAW 0x1 #define APPCL_STATE_RECVOK 0x2 +#define APPCL_STATE_EXIT 0x4 +#define APPCL_STATE_RESIZE 0x8 typedef struct { unsigned state; @@ -31,7 +33,10 @@ typedef struct { unsigned short sizey; } __attribute__ ((__packed__)) appcl_t; + extern appcl_t *zgui_window (); +extern void zgui_puts (unsigned short x, unsigned short y, char *str, unsigned color); +extern int zgui_resize (unsigned short x, unsigned short y); extern unsigned zgui_event (); extern int zgui_init (); extern int zgui_exit (); diff --git a/apps/zde/appsrv.c b/apps/zde/appsrv.c index ce672eb..c17c466 100755 --- a/apps/zde/appsrv.c +++ b/apps/zde/appsrv.c @@ -79,6 +79,22 @@ int appsrv_redraw (zde_dobj_appcl_t *appcl) return -1; } +int appsrv_exit (zde_dobj_appcl_t *appcl) +{ + if (!appcl) + return -1; + + /* new window (client) ? */ + if (appcl->fd == -1) + return -1; + + appcl->state |= APPCL_STATE_EXIT; + + ipc_send (appcl->fd, (char *) appcl, sizeof (appcl_t)); + + return 0; +} + void *handler_appsrv (void *p) { while (1) { diff --git a/apps/zde/appsrv.h b/apps/zde/appsrv.h index 02fcf48..f25573c 100755 --- a/apps/zde/appsrv.h +++ b/apps/zde/appsrv.h @@ -23,6 +23,7 @@ #include "dialog.h" extern int appsrv_redraw (zde_dobj_appcl_t *appcl); +extern int appsrv_exit (zde_dobj_appcl_t *appcl); extern int init_appsrv (); #endif diff --git a/apps/zde/dialog.c b/apps/zde/dialog.c index ba3ca3b..2679251 100755 --- a/apps/zde/dialog.c +++ b/apps/zde/dialog.c @@ -28,6 +28,7 @@ #include #include +#include "appcl.h" #include "dialog.h" #include "cursor.h" #include "window.h" @@ -98,6 +99,10 @@ unsigned destroy_dialog_object (zde_win_t *window) dobj->next->prev = dobj->prev; dobj->prev->next = dobj->next; + /* send exit state to client's app */ + if (dobj->type == ZDE_DOBJ_TYPE_APPCL) + appsrv_exit (dobj->arg); + free (dobj); i = 1; @@ -203,13 +208,24 @@ int draw_dialog_object (zde_win_t *window) if (!dobj_appcl) break; + /* setup windows properties*/ dobj_appcl->x = window->x; dobj_appcl->y = window->y; dobj_appcl->sizex = window->sizex; dobj_appcl->sizey = window->sizey; + /* redraw client's window */ appsrv_redraw (dobj_appcl); + if (dobj_appcl->state & APPCL_STATE_RESIZE) { + dobj_appcl->state &= ~APPCL_STATE_RESIZE; + + window->x = dobj_appcl->x; + window->y = dobj_appcl->y; + window->sizex = dobj_appcl->sizex; + window->sizey = dobj_appcl->sizey; + } + break; } /*if (dobj->bitmap) diff --git a/apps/zde/handler.c b/apps/zde/handler.c index dcc4507..8fe532b 100755 --- a/apps/zde/handler.c +++ b/apps/zde/handler.c @@ -214,7 +214,7 @@ void *handler_icon_exec (void *r) unsigned l = strlen (r); unsigned i; - char *str = (char *) r; + char *str = (char *) strdup (r); for (i = l; i > 1; i --) { if (str[i] == '/') { @@ -227,16 +227,17 @@ void *handler_icon_exec (void *r) chdir ((char *) str); - str += (i+1); + sprintf (desc, "exec %s", str+i+1); - sprintf (desc, "exec %s", str); + free (str); system (desc); + schedule (); + while (!(window->state & WINDOW_STATE_CLOSE)) { schedule (); - if (window != zde_win_last) continue; diff --git a/apps/zde/icon.c b/apps/zde/icon.c index e09ecb7..9e88594 100755 --- a/apps/zde/icon.c +++ b/apps/zde/icon.c @@ -265,6 +265,9 @@ int draw_icon_window (zde_win_t *window) if (!(zde_cursor->flags & CURSOR_FLAG_MOVE)) if (zde_cursor->x >= icon->x && zde_cursor->x <= icon->x+32) if (zde_cursor->y >= icon->y && zde_cursor->y <= icon->y+32) { + if (isactive_window () != window) + continue; + zde_cursor->state = 0; zde_cursor->flags |= CURSOR_FLAG_LBCLICK; @@ -337,7 +340,7 @@ int init_icon () create_icon ("Filesystem", 0, handler_icon_filesystem, ""); /* create test icon */ - create_icon ("Terminal", 0, handler_icon_terminal, ""); + //create_icon ("Terminal", 0, handler_icon_terminal, ""); return 0; } diff --git a/apps/zde/window.c b/apps/zde/window.c index f8acf49..a9a1219 100755 --- a/apps/zde/window.c +++ b/apps/zde/window.c @@ -63,6 +63,7 @@ zde_win_t *create_window (char *name, unsigned char type) zde_win_newy = 0; window->name = strdup (name); + window->name_len = strlen (name); window->state = 0; window->objectid = 0; @@ -111,6 +112,11 @@ unsigned active_window (zde_win_t *window) return 1; } +zde_win_t *isactive_window () +{ + return zde_win_last; +} + static void draw_bitmap (unsigned short x, unsigned short y) { unsigned i = 0; @@ -185,8 +191,10 @@ int draw_window () } + /* we cant move with any window */ if (!(zde_cursor->flags & CURSOR_FLAG_MOVE)) if (curr) { + /* exit window */ if (zde_cursor->x >= (curr->x+curr->sizex-18) && zde_cursor->x <= (curr->x+curr->sizex-6)) if (zde_cursor->y >= curr->y+3 && zde_cursor->y <= curr->y+17) { zde_cursor->state = 0; @@ -197,12 +205,14 @@ int draw_window () break; } + /* window header */ if (zde_cursor->x >= curr->x && zde_cursor->x <= (curr->x+curr->sizex)) if (zde_cursor->y >= curr->y && zde_cursor->y <= (int) (curr->y+22)) { curr->state |= WINDOW_STATE_MOVE; zde_cursor->flags |= CURSOR_FLAG_MOVE; } + /* make active window (front of screen) */ if (curr != zde_win_last) { active_window (curr); break; @@ -213,27 +223,31 @@ int draw_window () zde_cursor->flags &= ~CURSOR_FLAG_MOVE; } + /* when some window is moving, we need update postitions of it */ if (window->state & WINDOW_STATE_MOVE) { window->x = zde_cursor->x; window->y = zde_cursor->y; } - /* jedna se o okno */ + /* it's classical window */ if (window->type == 0) { unsigned x = window->x+window->sizex-4; unsigned y = window->y+window->sizey-3; - /* bila plocha okna */ + /* window background */ draw_rectfill (window->x+4, window->y+21, x, y, ~0); - + //xrectfill (window->x+4, window->y+21, window->x+window->sizex-4, window->y+window->sizey-3, ~0-0xf); /* vykreslime vsechny ikony naseho okna */ draw_icon_window (window); - /* jedna se o dialog */ + /* it's dialog window */ } else if (window->type == 1) { - /* seda plocha okna */ - xrectfill (window->x+4, window->y+21, window->x+window->sizex-4, window->y+window->sizey-3, ~0-0xf); + unsigned x = window->x+window->sizex-4; + unsigned y = window->y+window->sizey-3; - /* vykreslime vsechny objekty naseho okna */ + /* window background */ + draw_rectfill (window->x+4, window->y+21, x, y, ~0-0x1); + + /* let's draw all objects of this window */ draw_dialog_object (window); } @@ -306,8 +320,10 @@ int draw_window () for (l = 0; l < window->sizex-11; l ++) draw_bitmap (window->x+5+l, window->y+window->sizey-2); - if (window->name) - xtext_puts (window->x+8, window->y+5, 0, window->name); + if (window->name) { + if (window->sizex > (window->name_len * 6)) + xtext_puts (window->x+8, window->y+5, 0, window->name); + } } return 0; diff --git a/apps/zde/window.h b/apps/zde/window.h index 342fc43..eed1d6c 100755 --- a/apps/zde/window.h +++ b/apps/zde/window.h @@ -42,11 +42,13 @@ typedef struct zde_win_context { unsigned short sizex; unsigned short sizey; char *name; + unsigned char name_len; unsigned char state; unsigned char objectid; unsigned char type; } zde_win_t; +extern zde_win_t *isactive_window (); extern zde_win_t *create_window (char *name, unsigned char type); extern int draw_window (); extern int init_window (); diff --git a/apps/zde/ztest/Makefile b/apps/zde/zclock/Makefile similarity index 73% copy from apps/zde/ztest/Makefile copy to apps/zde/zclock/Makefile index eb0732d..35b018e 100644 --- a/apps/zde/ztest/Makefile +++ b/apps/zde/zclock/Makefile @@ -21,17 +21,21 @@ LIBZ =$(LIBZDIR)/libzde.a OBJS =start.o main.o # targets -all: ztest +all: prepare zclock -install: ztest +prepare: + make -C ../ + + +install: zclock mkdir mnt mount /dev/fd0 mnt - cp -f ztest ./mnt/ztest + cp -f zclock ./mnt/zclock umount mnt rmdir mnt clean: - rm -f *.o ztest ztest.img $(OBJS) + rm -f *.o zclock zclock.img $(OBJS) # implicit rules .asm.o: $(NASM) -o$@ $< @@ -46,5 +50,5 @@ start.o: start.asm $(MAKEDEP) main.o: main.c $(MAKEDEP) # explicit rules -ztest: $(OBJS) $(LIBI) $(LIBX) $(LIBZ) $(LIBC) $(MAKEDEP) +zclock: $(OBJS) $(LIBI) $(LIBX) $(LIBZ) $(LIBC) $(MAKEDEP) $(LD) $(LFLAGS) -o$@ $(OBJS) $(LIBZ) $(LIBI) $(LIBX) $(LIBC) \ No newline at end of file diff --git a/apps/zde/zclock/README b/apps/zde/zclock/README new file mode 100644 index 0000000..c33b597 --- /dev/null +++ b/apps/zde/zclock/README @@ -0,0 +1,8 @@ +Description: Clone of netcat for TCP over IPs comunication +Info: For *.img use ./make_img.sh (Usefully for developers in virtualization) + +License: GNU/GPL3 +Author: ZeXx86 + +Syntax: +exec nc
\ No newline at end of file diff --git a/apps/zde/zclock/link.ld b/apps/zde/zclock/link.ld new file mode 100644 index 0000000..b9f9cb1 --- /dev/null +++ b/apps/zde/zclock/link.ld @@ -0,0 +1,48 @@ +OUTPUT_FORMAT("elf32-i386") +ENTRY(entry) +phys = 0x400000; + +SECTIONS +{ + .text phys + 0x1000 : AT (phys) + { + code = .; _code = .; __code = .; + *(.text) + . = ALIGN(1024); + } + .data : AT(phys + (data - code)) + { + data = .; _data = .; __data = .; + *(.data) + . = ALIGN(1024); + } + .rodata : AT(phys + (rodata - code)) + { + rodata = .; _rodata = .; __rodata = .; + *(.rodata) + *(.rodata.*) + . = ALIGN(1024); + } + .bss : AT(phys + (bss - code)) + { + bss = .; _bss = .; __bss = .; + *(.bss) + *(COMMON) + . = ALIGN(1024); + } + .comment : AT(phys + (comment - code)) + { + comment = .; _comment = .; __comment = .; + *(.comment) + *(.comment.*) + . = ALIGN(1024); + } + .shstrtab : AT(phys + (shstrtab - code)) + { + shstrtab = .; _shstrtab = .; __shstrtab = .; + *(.shstrtab) + *(.shstrtab.*) + . = ALIGN(1024); + } + end = .; _end = .; +} diff --git a/apps/zde/ztest/main.c b/apps/zde/zclock/main.c similarity index 68% copy from apps/zde/ztest/main.c copy to apps/zde/zclock/main.c index 14203b2..07d2cea 100644 --- a/apps/zde/ztest/main.c +++ b/apps/zde/zclock/main.c @@ -17,31 +17,43 @@ */ -#include #include #include +#include +#include + +char str[128]; void ztest_draw () { - appcl_t *cl = zgui_window (); + time_t t = time (0); + + struct tm time; + localtime_r (&t, &time); + + sprintf (str, "%d:%d:%d", time.tm_hour, time.tm_min, time.tm_sec+1); - if (cl) - xtext_puts (cl->x+5, cl->y+22, 0, "Hello World from Client APP"); + zgui_puts (28, 15, "CLOCK", 0); + zgui_puts (20, 30, str, 0); } int main (int argc, char **argv) { + int exit = 0; + if (zgui_init () == -1) return -1; - while (1) { - switch (zgui_event ()) { - case 0: - break; - case APPCL_STATE_REDRAW: - ztest_draw (); - break; - } + zgui_resize (100, 70); + + while (!exit) { + unsigned state = zgui_event (); + + if (state & APPCL_STATE_REDRAW) + ztest_draw (); + + if (state & APPCL_STATE_EXIT) + exit = 1; } return zgui_exit (); diff --git a/apps/zde/zclock/make_img.sh b/apps/zde/zclock/make_img.sh new file mode 100755 index 0000000..d009f09 --- /dev/null +++ b/apps/zde/zclock/make_img.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +if [ "$USER" = "root" ] ; then + +# Folder name of your application +APPNAME="zclock" + +# Compile source +make + +# Optimized for 1,4MB floppy +dd if=/dev/zero of=$APPNAME.img bs=1440k count=1 +mkfs.vfat $APPNAME.img + +mkdir floppy +mount -oloop $APPNAME.img floppy +cp ../zde floppy +cp ../folder floppy +cp ../border floppy +cp ../file floppy +cp $APPNAME floppy +umount floppy +rmdir floppy + +else + +echo "Please start this script as root - it is needed for mount program" + +fi \ No newline at end of file diff --git a/apps/zde/zclock/start.asm b/apps/zde/zclock/start.asm new file mode 100644 index 0000000..bd9cc05 --- /dev/null +++ b/apps/zde/zclock/start.asm @@ -0,0 +1,55 @@ +; ZeX/OS +; Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) +; Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) +; +; This program is free software: you can redistribute it and/or modify +; it under the terms of the GNU General Public License as published by +; the Free Software Foundation, either version 3 of the License, or +; (at your option) any later version. +; +; This program is distributed in the hope that it will be useful, +; but WITHOUT ANY WARRANTY; without even the implied warranty of +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +; GNU General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this program. If not, see . + + +; This is the kernel's entry point. We could either call main here, +; or we can use this to setup the stack or other nice stuff, like +; perhaps setting up the GDT and segments. Please note that interrupts +; are disabled at this point: More on interrupts later! + +[SECTION .text] +[BITS 32] + +extern main +global entry + +entry: + ; first we get arguments + mov eax, 26 + mov ecx, 0 + int 0x80 + + push eax ; argv + + ; lets get count of arguments + mov eax, 26 + mov ecx, 1 + int 0x80 + + mov ebx, eax + push ebx ; argc + + call main ; call our program + + pop ebx + pop eax + + ; proc exit + mov eax, 1 + int 0x80 + + ret \ No newline at end of file diff --git a/apps/zde/ztest/Makefile b/apps/zde/ztest/Makefile index eb0732d..3c1efa9 100644 --- a/apps/zde/ztest/Makefile +++ b/apps/zde/ztest/Makefile @@ -21,7 +21,11 @@ LIBZ =$(LIBZDIR)/libzde.a OBJS =start.o main.o # targets -all: ztest +all: prepare ztest + +prepare: + make -C ../ + install: ztest mkdir mnt diff --git a/apps/zde/ztest/main.c b/apps/zde/ztest/main.c index 14203b2..e0d75c4 100644 --- a/apps/zde/ztest/main.c +++ b/apps/zde/ztest/main.c @@ -17,31 +17,29 @@ */ -#include #include #include void ztest_draw () { - appcl_t *cl = zgui_window (); - - if (cl) - xtext_puts (cl->x+5, cl->y+22, 0, "Hello World from Client APP"); + zgui_puts (80, 80, "Hello World from ZTEST APP !", 0); } int main (int argc, char **argv) { + int exit = 0; + if (zgui_init () == -1) return -1; - while (1) { - switch (zgui_event ()) { - case 0: - break; - case APPCL_STATE_REDRAW: - ztest_draw (); - break; - } + while (!exit) { + unsigned state = zgui_event (); + + if (state & APPCL_STATE_REDRAW) + ztest_draw (); + + if (state & APPCL_STATE_EXIT) + exit = 1; } return zgui_exit (); diff --git a/kernel/arch/i386/rtc.c b/kernel/arch/i386/rtc.c index 5163212..d3bc641 100644 --- a/kernel/arch/i386/rtc.c +++ b/kernel/arch/i386/rtc.c @@ -2,6 +2,7 @@ * ZeX/OS * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) + * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,18 +23,22 @@ #include #include +static tm rtime; + /* use BCD mode, since binary mode seems to be buggy */ static unsigned read_register (unsigned reg) { unsigned high_digit, low_digit; outb (0x70, reg); + high_digit = low_digit = inb (0x71); /* convert from BCD to binary */ high_digit >>= 4; high_digit &= 0x0F; low_digit &= 0x0F; + return 10 * high_digit + low_digit; } @@ -63,7 +68,7 @@ code shown here: IMHO, it's easier to see how the algorithm for this code works, versus the code at the URL above. *****************************************************************************/ -static long days_between_dates(unsigned start_year, unsigned start_day, +static long days_between_dates (unsigned start_year, unsigned start_day, int end_year, unsigned end_day) { int fourcents, centuries, fouryears, years; @@ -91,33 +96,33 @@ static long days_between_dates(unsigned start_year, unsigned start_day, /* 0 leap days for residual years */ days += (365L * 1) * years; /* residual days (need the cast!) */ - days += ((long)end_day - start_day); + days += ((long) end_day - start_day); /* account for terminal leap year */ - if(end_year % 4 == 0 && end_day >= 60) - { - days++; - if(end_year % 100 == 0) - days--; - if(end_year % 400 == 0) - days++; + if(end_year % 4 == 0 && end_day >= 60) { + days ++; + + if (end_year % 100 == 0) + days --; + if (end_year % 400 == 0) + days ++; } /* xxx - what have I wrought? I don't know what's going on here, but the code won't work properly without it */ - if(end_year >= 0) - { - days++; - if(end_year % 4 == 0) - days--; - if(end_year % 100 == 0) - days++; - if(end_year % 400 == 0) - days--; + if (end_year >= 0) { + days ++; + + if (end_year % 4 == 0) + days --; + if (end_year % 100 == 0) + days ++; + if (end_year % 400 == 0) + days --; } - if(start_year > 0) - days--; + if (start_year > 0) + days --; return days; } @@ -126,7 +131,7 @@ static long days_between_dates(unsigned start_year, unsigned start_day, month and date start with 1, not with 0 *****************************************************************************/ #define EPOCH_YEAR 1970 -#define EPOCH_DAY 0 /* Jan 1 */ +#define EPOCH_DAY 0 /* Jan 1 */ unsigned long date_time_to_time_t(unsigned year, unsigned month, unsigned date, unsigned hour, unsigned min, @@ -153,15 +158,16 @@ unsigned long date_time_to_time_t(unsigned year, unsigned month, unsigned day; /* convert month and year to day-in-year */ - if(month < 1 || month > 12 || date < 1 || date > 31) + if (month < 1 || month > 12 || date < 1 || date > 31) return 0; - month--; - date--; + month --; + date --; + day = date + days_to_date[month]; /* convert to Unix JDN (UJDN) */ - ret_val = days_between_dates(EPOCH_YEAR, EPOCH_DAY, year, day); + ret_val = days_between_dates (EPOCH_YEAR, EPOCH_DAY, year, day); /* convert from days to seconds, adding time as you go */ ret_val *= 24; @@ -184,16 +190,16 @@ tm *rtc_getcurrtime () unsigned date, month, hour, minute, second; int year; - if (!init) - { + if (!init) { /* b2=0 BCD mode, vs. binary (binary mode seems to be buggy) b1=1 24-hour mode, vs. 12-hour mode */ outb (0x70, 11); outb (0x71, (inb (0x71) & ~6) | 2); init = 1; } + /* wait for stored time value to stop changing */ - outb(0x70, 10); + outb (0x70, 10); while (inb (0x71) & 128); @@ -212,19 +218,18 @@ tm *rtc_getcurrtime () month = read_register (8); /* 1-12 */ date = read_register (7); /* 1-31 */ - /* get time */ hour = read_register (4); /* 0-23 */ minute = read_register (2); /* 0-59 */ second = read_register (0); /* 0-59 */ - realtime->tm_sec = second; - realtime->tm_min = minute; - realtime->tm_hour = hour; - realtime->tm_mday = date; - realtime->tm_mon = month; - realtime->tm_year = year; - realtime->tm_isdst = 0; - realtime->__tm_gmtoff = date_time_to_time_t (year, month, date, hour, minute, second); + rtime.tm_sec = second; + rtime.tm_min = minute; + rtime.tm_hour = hour; + rtime.tm_mday = date; + rtime.tm_mon = month; + rtime.tm_year = year; + rtime.tm_isdst = 0; + rtime.__tm_gmtoff = date_time_to_time_t (year, month, date, hour, minute, second); - return realtime; + return &rtime; } diff --git a/kernel/arch/i386/syscall.c b/kernel/arch/i386/syscall.c index 4389534..301c354 100644 --- a/kernel/arch/i386/syscall.c +++ b/kernel/arch/i386/syscall.c @@ -399,7 +399,12 @@ void sys_read (struct regs *r) void sys_time (struct regs *r) { - r->eax = (unsigned) rtc_getcurrtime (); + time_t *memptr = (time_t *) 0x9005; + + tm *t = rtc_getcurrtime (); + + if (t) + *memptr = (time_t) t->__tm_gmtoff; } void sys_system (struct regs *r) @@ -409,13 +414,26 @@ void sys_system (struct regs *r) if (!task) return; + proc_t *proc = proc_find (_curr_task); + + if (!proc) + return; + + task_t *oldtask = _curr_task; + page_dir_switch (task->page_cover->page_dir); unsigned char *cmd = (unsigned char *) r->ebx; command_parser ((char *) cmd, strlen (cmd)); - page_dir_switch (_curr_task->page_cover->page_dir); + page_dir_switch (oldtask->page_cover->page_dir); + + /* needed for correct scheduling (when you execute new process, _curr_task is tasj of current tty) */ + _curr_task = oldtask; + + schedule (); + } void sys_chdir (struct regs *r) diff --git a/kernel/core/commands.c b/kernel/core/commands.c index 1bfc7fc..77dcb1a 100644 --- a/kernel/core/commands.c +++ b/kernel/core/commands.c @@ -612,10 +612,10 @@ unsigned command_free (char *command, unsigned len) unsigned command_date (char *command, unsigned len) { - rtc_getcurrtime (); + tm *t = rtc_getcurrtime (); - printf ("%02u:%02u:%02u, %u.%u.%u\n", realtime->tm_hour, realtime->tm_min, realtime->tm_sec, - realtime->tm_mday, realtime->tm_mon, realtime->tm_year); + printf ("%02u:%02u:%02u, %u.%u.%u\n", + t->tm_hour, t->tm_min, t->tm_sec, t->tm_mday, t->tm_mon, t->tm_year); return 1; } diff --git a/kernel/core/mm/kmem.c b/kernel/core/mm/kmem.c index 6b7fe9e..eedc6fb 100644 --- a/kernel/core/mm/kmem.c +++ b/kernel/core/mm/kmem.c @@ -2,6 +2,7 @@ * ZeX/OS * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) + * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -489,8 +490,6 @@ unsigned int init_mm () kdump_heap (); - tm *realtime = (tm *) malloc (sizeof (tm)); - pmem_init (); swmem_init (); diff --git a/kernel/core/mm/kzmem.c b/kernel/core/mm/kzmem.c index 3b94057..59bfb53 100644 --- a/kernel/core/mm/kzmem.c +++ b/kernel/core/mm/kzmem.c @@ -2,6 +2,7 @@ * ZeX/OS * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) + * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -296,8 +297,6 @@ unsigned int init_mm () //mem_ext = kmem_get (); // get extended memory (in Mb) - tm *realtime = (tm *) malloc (sizeof (tm)); - pmem_init (); return 1; diff --git a/kernel/core/net/icmp6.c b/kernel/core/net/icmp6.c index 9da523c..6b7502a 100644 --- a/kernel/core/net/icmp6.c +++ b/kernel/core/net/icmp6.c @@ -1,6 +1,7 @@ /* * ZeX/OS * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) + * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -83,9 +84,9 @@ unsigned net_proto_icmp6_handler (packet_t *packet, proto_ipv6_t *ip, char *buf, net_icmp6_ping = 1; return 1; } - //printf ("icmpv6->type: 0x%x\n", icmp->type); + /* ICMPv6 - NDP protocol handler */ - if (icmp->type == NET_NDP_TYPE_ADVERT) { + if (icmp->type == NET_NDP_TYPE_NBADVERT) { netif_t *netif = netif_findbyname ("eth0"); proto_ndp_adv_t *ndp = (proto_ndp_adv_t *) buf; @@ -96,18 +97,28 @@ unsigned net_proto_icmp6_handler (packet_t *packet, proto_ipv6_t *ip, char *buf, return 0; } - if (icmp->type == NET_NDP_TYPE_SOL) { + if (icmp->type == NET_NDP_TYPE_NBSOL) { netif_t *netif = netif_findbyname ("eth0"); proto_ndp_adv_t *ndp = (proto_ndp_adv_t *) buf; - /* send ARP reply */ + /* send NDP reply */ if (net_proto_ipv6_cmp (ndp->target, netif->ipv6)) { ndp_cache_add (ndp->ll_mac, ip->ip_source); - return ndp_send_reply (netif, ndp->ll_mac, ip->ip_source); + return ndp_send_nbreply (netif, ndp->ll_mac, ip->ip_source); } } + if (icmp->type == NET_NDP_TYPE_RADVERT) { + netif_t *netif = netif_findbyname ("eth0"); + + proto_icmp_ndp2_t *ndp = (proto_icmp_ndp2_t *) buf; + + /* send NDP reply */ + return ndp_send_rreply (netif, ndp, ip->ip_source, ip->ip_dest); + + } + return 0; } @@ -119,7 +130,7 @@ unsigned net_proto_icmp6_request (netif_t *netif, net_ipv6 dest) unsigned get = ndp_cache_get (dest, &mac_dest); if (!get) { - ndp_send_request (netif, dest); + ndp_send_nbrequest (netif, dest); unsigned i = 0; /* 200ms for waiting on NDP reply */ diff --git a/kernel/core/net/ipv6.c b/kernel/core/net/ipv6.c index 1f18fd8..8462640 100644 --- a/kernel/core/net/ipv6.c +++ b/kernel/core/net/ipv6.c @@ -59,7 +59,7 @@ void net_proto_ipv6_print (net_ipv6 ip) if (ip[7]) printf ("%x", swap16 (ip[7])); else - printf ("0:"); + printf ("0"); } unsigned net_proto_ipv6_cmp (net_ipv6 ip, net_ipv6 ip2) @@ -72,6 +72,20 @@ unsigned net_proto_ipv6_cmp (net_ipv6 ip, net_ipv6 ip2) return 1; } +unsigned net_proto_ipv6_cmp_prefix (net_ipv6 ip, net_ipv6 ip2, unsigned char prefix) +{ + unsigned i; + for (i = 0; i < 8; i ++) { + if (i >= prefix/16) + break; + + if (ip[i] != ip2[i]) + return 0; + } + + return 1; +} + unsigned net_proto_ipv6_convert (net_ipv6 ipv6, char *ip) { unsigned short a; diff --git a/kernel/core/net/ndp.c b/kernel/core/net/ndp.c index 7b91bc5..6020c2e 100644 --- a/kernel/core/net/ndp.c +++ b/kernel/core/net/ndp.c @@ -32,13 +32,14 @@ #include ndp_cache_t ndp_cache_list; +mac_addr_t ndp_macgw; extern unsigned long timer_ticks; /* prototype */ -unsigned ndp_send_request (netif_t *netif, net_ipv6 dest) +unsigned ndp_send_nbrequest (netif_t *netif, net_ipv6 dest) { /* packet header */ packet_t *packet = (packet_t *) kmalloc (sizeof (packet_t)); @@ -90,7 +91,7 @@ unsigned ndp_send_request (netif_t *netif, net_ipv6 dest) memset ((char *) ndp, 0, sizeof (proto_ndp_sol_t)); - ndp->type = NET_NDP_TYPE_SOL; + ndp->type = NET_NDP_TYPE_NBSOL; ndp->code = 0; memcpy (ndp->target, (void *) dest, sizeof (net_ipv6)); @@ -110,7 +111,7 @@ unsigned ndp_send_request (netif_t *netif, net_ipv6 dest) } -int ndp_send_reply (netif_t *i, mac_addr_t target_mac, net_ipv6 target_ipaddr) +int ndp_send_nbreply (netif_t *i, mac_addr_t target_mac, net_ipv6 target_ipaddr) { /* packet header */ packet_t *packet = (packet_t *) kmalloc (sizeof (packet_t)); @@ -150,7 +151,7 @@ int ndp_send_reply (netif_t *i, mac_addr_t target_mac, net_ipv6 target_ipaddr) memset ((char *) ndp, 0, sizeof (proto_ndp_sol_t)); - ndp->type = NET_NDP_TYPE_ADVERT; + ndp->type = NET_NDP_TYPE_NBADVERT; ndp->code = 0; ndp->flags = swap32 (0x60000000); memcpy (ndp->target, (void *) i->ipv6, sizeof (net_ipv6)); @@ -170,6 +171,116 @@ int ndp_send_reply (netif_t *i, mac_addr_t target_mac, net_ipv6 target_ipaddr) return 1; } +int ndp_send_rreply (netif_t *i, proto_icmp_ndp2_t *ndp, net_ipv6 source, net_ipv6 dest) +{ + /*printf ("IP adresa je: "); + net_proto_ipv6_print (source); + printf ("\n");*/ + + net_ipv6 bcast_ip; + + NET_IPV6_TO_ADDR (bcast_ip, 0xfe80, 0, 0, 0, 0, 0, 0, 0); + + if (!net_proto_ipv6_cmp_prefix (source, bcast_ip, 64)) { + return 0; + } + + /* local IPv6 address - we can change it to public IPv6 */ + if (!net_proto_ipv6_network (i->ipv6)) { + if (ndp->prefix_len != 64) + return 0; + + net_ipv6 ipv6; + +/* +eth3 Zapouzdření:Ethernet HWadr 00:E0:4D:7A:D3:48 + inet6-adr: 2001:15c0:661d:0:2e0:4dff:fe7a:d348/64 Rozsah:Globál + inet6-adr: fe80::2e0:4dff:fe7a:d348/64 Rozsah:Linka +*/ + + unsigned l = ndp->prefix_len/8; + + memcpy (&ipv6, (void *) ndp->prefix, l); + + //memcpy ((char *) &ipv6+ndp->prefix_len/8, ndp->prefix, ndp->prefix_len); + /*unsigned i; + for (i = l/8; i < 8; i ++) { + ipv6[i] = + }*/ + ipv6[4] = 0x2 | i->dev->dev_addr[1] << 8; + ipv6[5] = 0xff << 8 | i->dev->dev_addr[2]; + ipv6[6] = 0xfe | i->dev->dev_addr[3] << 8; + ipv6[7] = i->dev->dev_addr[4] | i->dev->dev_addr[5] << 8; + + netif_ipv6_addr (i, ipv6); + + //NET_IPV6_TO_ADDR (ipv6, 0xfc00, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1); + + + netif_gwv6_addr (i, ndp->prefix); + memcpy (&ndp_macgw, &ndp->ll_mac, sizeof (mac_addr_t)); + } + + return 1; +#ifdef TEST + /* packet header */ + packet_t *packet = (packet_t *) kmalloc (sizeof (packet_t)); + + if (!packet) + return 0; + + memcpy (&packet->mac_source, i->dev->dev_addr, 6); + memcpy (&packet->mac_dest, target_mac, 6); + packet->type = NET_PACKET_TYPE_IPV6; + + /* ip layer */ + proto_ipv6_t *ip = (proto_ipv6_t *) kmalloc (sizeof (proto_ipv6_t)); + + if (!ip) + return 0; + + /* there are some fixed values - yeah it is horrible */ + ip->ver = 0x60; + ip->tclass = 0x0; + ip->flabel = 0x0; + ip->pl_len = swap16 (32); + ip->nhead = NET_PROTO_IP_TYPE_ICMP6; + ip->hop = 0xff; + + memcpy (ip->ip_source, (void *) i->ipv6, sizeof (net_ipv6)); + +// if (dest[0] == swap16 (0xff02)) + + memcpy (ip->ip_dest, (void *) source, sizeof (net_ipv6)); + + /* icmp layer */ + proto_ndp_adv_t *ndp = (proto_ndp_adv_t *) kmalloc (sizeof (proto_ndp_adv_t)); + + if (!ndp) + return 0; + + memset ((char *) ndp, 0, sizeof (proto_ndp_sol_t)); + + ndp->type = NET_NDP_TYPE_RSOL; + ndp->code = 0; + ndp->flags = swap32 (0x60000000); + memcpy (ndp->target, (void *) i->ipv6, sizeof (net_ipv6)); + + ndp->ll_type = 2; + ndp->ll_length = 1; + memcpy (&ndp->ll_mac, i->dev->dev_addr, 6); + + ndp->checksum = checksum16_ipv6 (ip->ip_source, ip->ip_dest, ndp, sizeof (proto_ndp_adv_t), NET_PROTO_IP_TYPE_ICMP6); + + unsigned ret = net_proto_ipv6_send (i, packet, ip, (char *) ndp, sizeof (proto_ndp_sol_t)); + + kfree (ndp); + kfree (ip); + kfree (packet); +#endif + return 1; +} + /* NDP Cache */ unsigned ndp_cache_add (mac_addr_t mac, net_ipv6 ip) { @@ -207,26 +318,30 @@ unsigned ndp_cache_get (net_ipv6 ip, mac_addr_t *mac) { ndp_cache_t *cache; - /*if (net_proto_ip_network (ip)) { - netif_t *eth = netif_findbyname ("eth0"); + if (net_proto_ipv6_network (ip)) { + /*netif_t *eth = netif_findbyname ("eth0"); if (!eth) return 0; for (cache = ndp_cache_list.next; cache != &ndp_cache_list; cache = cache->next) { - if (net_proto_ipv6_cmp (cache->ip, eth->gw)) { + if (net_proto_ipv6_cmp (cache->ip, eth->gwv6)) { memcpy (mac, cache->mac, 6); return 1; } - } - } else {*/ + }*/ + + memcpy (mac, &ndp_macgw, 6); + + return 1; + } else { for (cache = ndp_cache_list.next; cache != &ndp_cache_list; cache = cache->next) { if (net_proto_ipv6_cmp (cache->ip, ip)) { memcpy (mac, cache->mac, 6); return 1; } } - //} + } return 0; } diff --git a/kernel/core/net/tcp6.c b/kernel/core/net/tcp6.c index 6ca3e00..32475b8 100644 --- a/kernel/core/net/tcp6.c +++ b/kernel/core/net/tcp6.c @@ -1,6 +1,7 @@ /* * ZeX/OS * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) + * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -547,7 +548,7 @@ int net_proto_tcp6_write (netif_t *eth, net_ipv6 dest, proto_tcp_t *tcp, char *d unsigned get = ndp_cache_get (dest, &mac_dest); if (!get) { - ndp_send_request (eth, dest); + ndp_send_nbrequest (eth, dest); unsigned i = 0; /* 200ms for waiting on NDP reply */ diff --git a/kernel/core/net/udp6.c b/kernel/core/net/udp6.c index 10794f6..90daa86 100644 --- a/kernel/core/net/udp6.c +++ b/kernel/core/net/udp6.c @@ -1,6 +1,7 @@ /* * ZeX/OS * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) + * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -343,7 +344,7 @@ int net_proto_udp6_write (proto_udp6_conn_t *conn, char *data, unsigned len) unsigned get = ndp_cache_get (conn->ip_dest, &mac_dest); if (!get) { - ndp_send_request (conn->netif, conn->ip_dest); + ndp_send_nbrequest (conn->netif, conn->ip_dest); unsigned i = 0; /* 100ms for waiting on ARP reply */ diff --git a/kernel/defconfig b/kernel/defconfig index 7d97e42..e3f8f19 100644 --- a/kernel/defconfig +++ b/kernel/defconfig @@ -1,7 +1,7 @@ # # Automatically generated make config: don't edit # ZeX/OS version: .. -# Tue Mar 24 20:06:33 2009 +# Wed Apr 1 17:12:57 2009 # # @@ -50,6 +50,7 @@ CONFIG_DRV_RTL8169=y CONFIG_DRV_VGA=y CONFIG_DRV_VGA_RES="320x200" CONFIG_DRV_VESA=y +CONFIG_DRV_GMM=y CONFIG_DRV_ATA=y CONFIG_DRV_FAT12=y # CONFIG_DRV_FAT16 is not set diff --git a/kernel/drivers/Kconfig b/kernel/drivers/Kconfig index 8057c28..6f9de4c 100644 --- a/kernel/drivers/Kconfig +++ b/kernel/drivers/Kconfig @@ -107,6 +107,12 @@ config DRV_VESA help Enable the VESA graphics driver +config DRV_GMM + bool "Graphical Memory Management (EXPERIMENTAL)" + default n + help + Enable the GMM extension + config DRV_ATA bool "ATA disk driver" default y diff --git a/kernel/drivers/char/video/video.c b/kernel/drivers/char/video/video.c index 37387b7..56bc5aa 100644 --- a/kernel/drivers/char/video/video.c +++ b/kernel/drivers/char/video/video.c @@ -261,8 +261,9 @@ unsigned int init_video (void) */ extern unsigned short *vesafb; -char *vgafb; -char *vgadb; +char *vgafb; /* frame buffer */ +char *vgadb; /* double buffer */ + unsigned vgafb_res_x, vgafb_res_y; char *init_vgafb () @@ -311,7 +312,7 @@ char *init_vgafb () vgafb_res_y = 200; vgafb = (char *) 0xA0000; - vgadb = (char *) kmalloc (sizeof (char) * vgafb_res_x * vgafb_res_y); + vgadb = 0;//(char *) kmalloc (sizeof (char) * vgafb_res_x * vgafb_res_y); } #endif @@ -323,6 +324,7 @@ char *init_vgafb () vgafb = (char *) vesafb; vgadb = (char *) PAGE_MEM_LOW+0x100000;//kmalloc (sizeof (short) * vgafb_res_x * vgafb_res_y); + //vgatb = (char *) PAGE_MEM_LOW+0x200000;//kmalloc (sizeof (char) * vgafb_res_x * vgafb_res_y); } if (!vgadb) @@ -391,17 +393,16 @@ void gpixel (unsigned x, unsigned y, unsigned color) unsigned i = y * vgafb_res_x + x; - if (vgagui == 1) { - vgadb[i] = color; + if (vgagui == 2) { + unsigned short *db = (unsigned short *) vgadb; + + db[i] = color; + return; } - unsigned short *vesadb = 0; - - if (vgagui == 2) { - vesadb = (unsigned short *) vgadb; - - vesadb[i] = color; + if (vgagui == 1) { + vgadb[i] = color; return; } @@ -412,14 +413,26 @@ void gfbswap () { paging_disable (); +#ifdef CONFIG_DRV_GMM + unsigned l = (vgafb_res_x * vgafb_res_y) / 2; + unsigned i = 0; + unsigned *fb = (unsigned *) vgafb; + unsigned *db = (unsigned *) vgadb; + + for (; i < l; i ++) { + fb[i] = db[i]; + db[i] = 0; + } +#else if (vgadb != vgafb) { - unsigned l = vgafb_res_x*vgafb_res_y*vgagui; + unsigned l = vgafb_res_x * vgafb_res_y * vgagui; unsigned i = 0; for (i = 0; i < l; i ++) { vgafb[i] = vgadb[i]; vgadb[i] = 0; } } +#endif paging_enable (); } @@ -427,9 +440,13 @@ void gfbswap () /* Clear screen with specified color*/ void gcls (unsigned color) { - unsigned x = 0; - for (x = 0; x < vgafb_res_x * vgafb_res_y * vgagui; x ++) - vgadb[x] = color; + unsigned short *db = (unsigned short *) vgadb; + + unsigned x; + unsigned l = vgafb_res_x * vgafb_res_y * vgagui; + + for (x = 0; x < l; x ++) + db[x] = color; } #endif diff --git a/kernel/include/net/ndp.h b/kernel/include/net/ndp.h index 3798264..9d3e0d3 100644 --- a/kernel/include/net/ndp.h +++ b/kernel/include/net/ndp.h @@ -1,6 +1,7 @@ /* * ZeX/OS * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) + * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,8 +22,10 @@ #include -#define NET_NDP_TYPE_SOL 0x87 -#define NET_NDP_TYPE_ADVERT 0x88 +#define NET_NDP_TYPE_RSOL 0x85 +#define NET_NDP_TYPE_RADVERT 0x86 +#define NET_NDP_TYPE_NBSOL 0x87 +#define NET_NDP_TYPE_NBADVERT 0x88 typedef struct ndp_cache_context { struct ndp_cache_context *next, *prev; diff --git a/kernel/include/system.h b/kernel/include/system.h index d8f724e..9ad73d4 100644 --- a/kernel/include/system.h +++ b/kernel/include/system.h @@ -2,6 +2,7 @@ * ZeX/OS * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) + * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -49,7 +50,6 @@ unsigned kernel_attr; #define KERNEL_NOETH 0x40 #define KERNEL_NOVESA 0x80 -//#define swap8(x) ({unsigned _x:4 = (x); (((_x)>>4)&0xf) | (((_x)<<4)&0xf0); }) #define swap16(x) ({unsigned _x = (x); (((_x)>>8)&0xff) | (((_x)<<8)&0xff00); }) @@ -66,7 +66,7 @@ unsigned kernel_attr; #define swap64(_v) (((unsigned long)swap32((unsigned)(_v))<<32)|(unsigned long)swap32((unsigned)((_v)>>32))) -unsigned debug; // developer mode +unsigned debug; // developer mode unsigned long long ctps; // cpu ticks per second @@ -76,8 +76,6 @@ partition_t *curr_part; unsigned int fd_count; -tm *realtime; - page_dir_t *page_cover_curr; unsigned char *kbd_layout[2]; diff --git a/libc/include/time.h b/libc/include/time.h index 35575a0..fbd09be 100644 --- a/libc/include/time.h +++ b/libc/include/time.h @@ -1,6 +1,7 @@ /* * ZeX/OS * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) + * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -40,5 +41,6 @@ struct tm { }; extern time_t time (time_t *t); +extern struct tm *localtime_r (const time_t *time, struct tm *resultp); #endif diff --git a/libc/time/localtime.c b/libc/time/localtime.c index adbdb9a..4fe2265 100644 --- a/libc/time/localtime.c +++ b/libc/time/localtime.c @@ -1,6 +1,7 @@ /* * ZeX/OS * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) + * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,10 +20,10 @@ #include -#define MINUTE 60 -#define HOUR (60*MINUTE) -#define DAY (24*HOUR) -#define YEAR (365*DAY) +#define MINUTE 60 +#define HOUR (60 * MINUTE) +#define DAY (24 * HOUR) +#define YEAR (365 * DAY) struct tm tmbuf; @@ -36,7 +37,9 @@ struct tm tmbuf; struct tm *localtime_r (const time_t *time, struct tm *resultp) { - /* this seems buggy, but works :-) */ + if (!resultp || !time) + return 0; + time_t c = *time; resultp->tm_year = c/YEAR; @@ -57,6 +60,7 @@ struct tm *localtime_r (const time_t *time, struct tm *resultp) resultp->tm_mday -= 8; // FIXME: hack resultp->tm_wday = resultp->tm_mday; + while (resultp->tm_wday > 6) resultp->tm_wday -= 7; diff --git a/libc/time/time.c b/libc/time/time.c index 31a423f..cc13888 100644 --- a/libc/time/time.c +++ b/libc/time/time.c @@ -1,6 +1,7 @@ /* * ZeX/OS * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) + * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,14 +22,14 @@ time_t time (time_t *t) { - time_t *p = 0; - asm volatile ( "movl $22, %%eax;" - "int $0x80;" - "movl %%eax, %0;": "=g" (p) :: "%eax"); + "int $0x80;" ::: "%eax"); + + time_t *p = (time_t *) 0x9005; - *t = *p; + if (t) + *t = *p; return (time_t) *p; } -- 2.11.4.GIT