From 1b821e2588af9565b71891f67314a991e9173767 Mon Sep 17 00:00:00 2001 From: Jean-Yves Lamoureux Date: Sun, 17 Sep 2006 12:44:18 +0000 Subject: [PATCH] * Updated kernel 'driver', still not working, but most of the work is done --- caca/driver_vga.c | 2 +- common.h | 5 ++++- configure.ac | 5 +++-- cucul/buffer.c | 3 ++- cucul/cucul.c | 14 ++++++------- kernel/kernel.c | 51 +++++++++++++++++++++++++++++++++++++++++++++- kernel/kernel.h | 23 ++++++++++++++------- src/Makefile.am | 1 - src/cacadraw.c | 8 +++++--- src/cacaplay.c | 6 ++++-- src/cacaview.c | 2 ++ src/common-image.c | 12 +++++++---- src/img2irc.c | 4 +++- test/demo.c | 10 ++++----- test/demo0.c | 8 +++++--- test/dithering.c | 6 ++++-- test/event.c | 9 ++++---- test/export.c | 13 ++++++------ test/font.c | 22 +++++++++++--------- test/font2tga.c | 11 +++++----- test/frames.c | 12 +++++------ test/gamma.c | 9 ++++---- test/hsv.c | 11 +++++----- test/import.c | 11 ++++++---- test/input.c | 9 ++++---- test/spritedit.c | 6 +++--- test/text.c | 15 +++++++------- test/transform.c | 12 +++++------ test/truecolor.c | 11 +++++----- test/unicode.c | 11 +++++----- tools/optipal.c | 6 ++++-- 31 files changed, 209 insertions(+), 119 deletions(-) diff --git a/caca/driver_vga.c b/caca/driver_vga.c index ccdbe6f..d4a2d87 100644 --- a/caca/driver_vga.c +++ b/caca/driver_vga.c @@ -133,7 +133,7 @@ static void vga_handle_resize(caca_display_t *dp) dp->resize.h = dp->cv->height; } -static int vga_get_event(caca_display_t *dp, caca_event-t *ev) +static int vga_get_event(caca_display_t *dp, caca_event_t *ev) { /* FIXME */ ev->type = CACA_EVENT_NONE; diff --git a/common.h b/common.h index 997ea4f..b5026d8 100644 --- a/common.h +++ b/common.h @@ -17,7 +17,7 @@ * function prototypes that are sometimes missing. */ -#if defined(HAVE_INTTYPES_H) +#if defined(HAVE_INTTYPES_H) && !defined(__KERNEL__) # include #else typedef signed char int8_t; @@ -69,3 +69,6 @@ static inline uint32_t hton32(uint32_t x) } #endif +#if defined(__KERNEL__) +#undef HAVE_ERRNO_H +#endif diff --git a/configure.ac b/configure.ac index a8fbb20..4ee9f79 100644 --- a/configure.ac +++ b/configure.ac @@ -209,9 +209,9 @@ fi if test "${enable_vga}" = "yes"; then ac_cv_my_have_vga="yes" CPPFLAGS="${CPPFLAGS} -I. -D__KERNEL__ -nostdinc -include kernel/kernel.h" - CFLAGS="${CFLAGS} -fno-builtin -O2 -Wall" + CFLAGS="${CFLAGS} -fno-builtin -O2 -Wall -I../kernel/" CCASFLAGS="${CCASFLAGS} -I." - LDFLAGS="${LDFLAGS} -nostdlib -Wl,-N -Wl,-Ttext -Wl,100000" + LDFLAGS="${LDFLAGS} -nostdlib -Wl,-N -Wl,-Ttext -Wl,100000 " AC_DEFINE(USE_VGA, 1, Define to 1 to activate the VGA backend driver) CACA_DRIVERS="${CACA_DRIVERS} vga" fi @@ -225,6 +225,7 @@ else AC_MSG_RESULT([${CACA_DRIVERS}]) fi + AC_SUBST(MATH_LIBS) AC_SUBST(CACA_LIBS) diff --git a/cucul/buffer.c b/cucul/buffer.c index 0102d25..e5eaa35 100644 --- a/cucul/buffer.c +++ b/cucul/buffer.c @@ -62,6 +62,7 @@ cucul_buffer_t *cucul_load_memory(void *data, unsigned long int size) * \return A \e libcucul buffer containing the file's contents, or NULL * if an error occurred. */ +#if !defined(__KERNEL__) cucul_buffer_t *cucul_load_file(char const *file) { cucul_buffer_t *buf; @@ -98,7 +99,7 @@ cucul_buffer_t *cucul_load_file(char const *file) return buf; } - +#endif /** \brief Get the buffer size. * * This function returns the length (in bytes) of the memory area stored diff --git a/cucul/cucul.c b/cucul/cucul.c index dfe85f9..64e6b55 100644 --- a/cucul/cucul.c +++ b/cucul/cucul.c @@ -98,13 +98,13 @@ cucul_canvas_t * cucul_create_canvas(unsigned int width, unsigned int height) if(ret < 0) { -#if defined(HAVE_ERRNO_H) +#if defined(HAVE_ERRNO_H) && !defined(__KERNEL__) int saved_errno = errno; #endif free(cv->allattr); free(cv->allchars); free(cv); -#if defined(HAVE_ERRNO_H) +#if defined(HAVE_ERRNO_H) && !defined(__KERNEL__) errno = saved_errno; #endif return NULL; @@ -116,7 +116,7 @@ cucul_canvas_t * cucul_create_canvas(unsigned int width, unsigned int height) return cv; nomem: -#if defined(HAVE_ERRNO_H) +#if defined(HAVE_ERRNO_H) && !defined(__KERNEL__) errno = ENOMEM; #endif return NULL; @@ -152,7 +152,7 @@ int cucul_set_canvas_size(cucul_canvas_t *cv, unsigned int width, { if(cv->refcount) { -#if defined(HAVE_ERRNO_H) +#if defined(HAVE_ERRNO_H) && !defined(__KERNEL__) errno = EBUSY; #endif return -1; @@ -246,7 +246,7 @@ int cucul_free_canvas(cucul_canvas_t *cv) if(cv->refcount) { -#if defined(HAVE_ERRNO_H) +#if defined(HAVE_ERRNO_H) && !defined(__KERNEL__) errno = EBUSY; #endif return -1; @@ -316,7 +316,7 @@ int _cucul_set_canvas_size(cucul_canvas_t *cv, unsigned int width, new_size * sizeof(uint32_t)); if(!cv->allchars[f] || !cv->allattr[f]) { -#if defined(HAVE_ERRNO_H) +#if defined(HAVE_ERRNO_H) && !defined(__KERNEL__) errno = ENOMEM; #endif return -1; @@ -405,7 +405,7 @@ int _cucul_set_canvas_size(cucul_canvas_t *cv, unsigned int width, new_size * sizeof(uint32_t)); if(!cv->allchars[f] || !cv->allattr[f]) { -#if defined(HAVE_ERRNO_H) +#if defined(HAVE_ERRNO_H) && !defined(__KERNEL__) errno = ENOMEM; #endif return -1; diff --git a/kernel/kernel.c b/kernel/kernel.c index 17a43a6..e115d35 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -29,6 +29,9 @@ #define UPPER(x) (IS_LOWER(x)?(x+('A'-'a')):x) #define LOWER(x) (IS_UPPER(x)?(x-('a'-'A')):x) +/* Our default seed for random number generator */ +static int seed = 0x68743284; + /* Our memory mapping */ static uint32_t *freemem = (uint32_t*) 0x00200000; @@ -94,9 +97,23 @@ char *getenv(const char *name) return NULL; } +int getpid(void) +{ + return 0x1337; +} + +void srand(unsigned int s) +{ + seed = rand(); +} + +int time(void *dummy) +{ + return rand(); +} + int rand(void) { - static int seed = 0x68743284; seed = (seed * 0x7f32ba17) ^ 0xf893a735; return seed % RAND_MAX; } @@ -157,6 +174,18 @@ int strcasecmp(const char *s1, const char *s2) return (int)UPPER(*s1) - (int)UPPER(*s2); } +int memcmp(const char *s1, const char *s2, size_t n) +{ + while(n) { + if(*s1 != *s2) return *s1-*s2; + *s1++; + *s2++; + n--; + } + return 0; +} + + /* stdarg.h functions */ int vsnprintf(char *str, size_t size, const char *format, va_list ap) { @@ -183,6 +212,11 @@ char *fgets(char *s, int size, FILE *stream) return NULL; } +size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) +{ + return 0; +} + int fclose(FILE *fp) { /* FIXME */ @@ -298,4 +332,19 @@ double sqrt(double x) return ret; } + +/* XXX FIXME Converts only from little endian to big endian (x86) */ +unsigned int htonl(unsigned int hostlong) +{ + return ((hostlong&0xFFFF0000)>>16)|((hostlong&0x0000FFFFFF)<<16); +} + +/* XXX FIXME Converts only from little endian to big endian (x86) */ +unsigned short htons(unsigned short hostlong) +{ + return ((hostlong&0xFF00)>>8)|((hostlong&0x00FF)<<8); +} + + + #endif /* __KERNEL__ */ diff --git a/kernel/kernel.h b/kernel/kernel.h index 45466c9..2f79c54 100644 --- a/kernel/kernel.h +++ b/kernel/kernel.h @@ -17,6 +17,8 @@ * that must be used when building libcucul and libcaca into a kernel. */ +#ifndef __KERNEL_H_ +#define __KERNEL_H_ /* Various defines */ #define NULL ((void *)0) #define BUFSIZ 4096 @@ -44,12 +46,6 @@ extern inline unsigned char inb(unsigned short port) /* Various typedefs -- some are x86-specific */ #define CUSTOM_INTTYPES -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -typedef unsigned long int uint32_t; -typedef long int intptr_t; -typedef long unsigned int uintptr_t; - typedef unsigned int size_t; typedef struct file @@ -81,13 +77,17 @@ char *getenv(const char *name); int rand(void); int abs(int j); void exit(int status); +void srand(unsigned int s); +int stdint; +int stdout; +int stderr; /* string.h functions */ void *memset(void *s, int c, size_t n); void *memcpy(void *dest, const void *src, size_t n); size_t strlen(const char *s); int strcasecmp(const char *s1, const char *s2); - +int memcmp(const char *s1, const char *s2, size_t n); /* stdarg.h functions */ typedef void * va_list; #define va_start(v,a) v = (void *)((uintptr_t)(&a) + sizeof(a)) @@ -98,6 +98,7 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap); FILE *fopen(const char *path, const char *mode); int feof(FILE *stream); char *fgets(char *s, int size, FILE *stream); +size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); int fclose(FILE *fp); int printf(const char *format, ...); int sprintf(char *str, const char *format, ...); @@ -105,12 +106,20 @@ int sscanf(const char *str, const char *format, ...); /* unistd.h functions */ void usleep(unsigned long usec); +int getpid(void); + /* time.h functions */ int gettimeofday(struct timeval *tv, struct timezone *tz); +int time(void *); /* math.h functions */ double cos(double x); double sin(double x); double sqrt(double x); +/* arpa/inet.h functions */ +unsigned int htonl(unsigned int hostlong); +unsigned short htons(unsigned short hostlong); + +#endif /* __KERNEL_H_ */ diff --git a/src/Makefile.am b/src/Makefile.am index aef863e..e32b827 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -46,4 +46,3 @@ fcntl_programs = cacaserver else fcntl_programs = endif - diff --git a/src/cacadraw.c b/src/cacadraw.c index 135dbc7..5f36806 100644 --- a/src/cacadraw.c +++ b/src/cacadraw.c @@ -14,9 +14,11 @@ #include "config.h" #include "common.h" -#include -#include -#include +#if !defined(__KERNEL__) +# include +# include +# include +#endif #include "cucul.h" #include "caca.h" diff --git a/src/cacaplay.c b/src/cacaplay.c index 4dbb6e4..37ca012 100644 --- a/src/cacaplay.c +++ b/src/cacaplay.c @@ -14,8 +14,10 @@ #include "config.h" #include "common.h" -#include -#include +#if !defined(__KERNEL__) + #include + #include +#endif #include "cucul.h" #include "caca.h" diff --git a/src/cacaview.c b/src/cacaview.c index 7163776..0fe543d 100644 --- a/src/cacaview.c +++ b/src/cacaview.c @@ -14,9 +14,11 @@ #include "config.h" #include "common.h" +#if !defined(__KERNEL__) #include #include #include +#endif #if defined(HAVE_SLEEP) # include diff --git a/src/common-image.c b/src/common-image.c index 48fab3a..7ccd077 100644 --- a/src/common-image.c +++ b/src/common-image.c @@ -14,14 +14,18 @@ #include "config.h" #include "common.h" -#include -#include -#include +#if !defined(__KERNEL__) +# include +# include +# include +#endif #if defined(HAVE_IMLIB2_H) # include #else -# include +# if !defined(__KERNEL__) +# include +# endif #endif #include "cucul.h" diff --git a/src/img2irc.c b/src/img2irc.c index a7073c4..7135c50 100644 --- a/src/img2irc.c +++ b/src/img2irc.c @@ -14,9 +14,11 @@ #include "config.h" #include "common.h" -#include +#if !defined(__KERNEL__) +# include #include #include +# endif #include "cucul.h" #include "common-image.h" diff --git a/test/demo.c b/test/demo.c index 0a55cc8..d558e9e 100644 --- a/test/demo.c +++ b/test/demo.c @@ -13,11 +13,11 @@ #include "config.h" #include "common.h" - -#include -#include -#include - +#if !defined(__KERNEL__) +# include +# include +# include +#endif #include "caca.h" static void display_menu(void); diff --git a/test/demo0.c b/test/demo0.c index ddc85e8..686615d 100644 --- a/test/demo0.c +++ b/test/demo0.c @@ -23,9 +23,11 @@ #include "config.h" -#include -#include -#include +#if !defined(__KERNEL__) +# include +# include +# include +#endif #include "caca0.h" diff --git a/test/dithering.c b/test/dithering.c index 4c9474d..699cfed 100644 --- a/test/dithering.c +++ b/test/dithering.c @@ -14,7 +14,9 @@ #include "config.h" #include "common.h" -#include +#if !defined(__KERNEL__) +# include +#endif #include "cucul.h" #include "caca.h" @@ -35,7 +37,7 @@ unsigned int points[] = char density[] = " ',+:;o&%w$W@#"; -int main(void) +int main(int argc, char *argv[]) { cucul_canvas_t *cv; caca_display_t *dp; diff --git a/test/event.c b/test/event.c index 8ee6cbc..bcca617 100644 --- a/test/event.c +++ b/test/event.c @@ -13,10 +13,11 @@ #include "config.h" #include "common.h" - -#include -#include -#include +#if !defined(__KERNEL__) +# include +# include +# include +#endif #include "cucul.h" #include "caca.h" diff --git a/test/export.c b/test/export.c index 81d0847..7236e65 100644 --- a/test/export.c +++ b/test/export.c @@ -14,14 +14,15 @@ #include "config.h" #include "common.h" -#if defined(HAVE_INTTYPES_H) -# include +#if !defined(__KERNEL__) +# if defined(HAVE_INTTYPES_H) +# include +# endif +# include +# include +# include #endif -#include -#include -#include - #include "cucul.h" #define WIDTH 80 diff --git a/test/font.c b/test/font.c index 28904c6..8ed2a53 100644 --- a/test/font.c +++ b/test/font.c @@ -14,18 +14,20 @@ #include "config.h" #include "common.h" -#if defined(HAVE_INTTYPES_H) -# include +#if !defined(__KERNEL__) +# if defined(HAVE_INTTYPES_H) +# include +# endif + +# if defined(HAVE_ENDIAN_H) +# include +# endif + +# include +# include +# include #endif -#if defined(HAVE_ENDIAN_H) -# include -#endif - -#include -#include -#include - #include "cucul.h" #include "caca.h" diff --git a/test/font2tga.c b/test/font2tga.c index 2ba3168..ab62521 100644 --- a/test/font2tga.c +++ b/test/font2tga.c @@ -14,13 +14,14 @@ #include "config.h" #include "common.h" -#if defined(HAVE_INTTYPES_H) -# include +#if !defined(__KERNEL__) +# if defined(HAVE_INTTYPES_H) +# include +# endif +# include +# include #endif -#include -#include - #include "cucul.h" #define WIDTH 64 diff --git a/test/frames.c b/test/frames.c index 30d137f..6d8529c 100644 --- a/test/frames.c +++ b/test/frames.c @@ -13,17 +13,17 @@ #include "config.h" #include "common.h" +#if !defined(__KERNEL__) +# if defined(HAVE_INTTYPES_H) +# include +# endif -#if defined(HAVE_INTTYPES_H) -# include +# include #endif - -#include - #include "cucul.h" #include "caca.h" -int main(void) +int main(int argc, char *argv[]) { cucul_canvas_t *cv; caca_display_t *dp; diff --git a/test/gamma.c b/test/gamma.c index aac14c8..3e2804e 100644 --- a/test/gamma.c +++ b/test/gamma.c @@ -14,11 +14,10 @@ #include "config.h" #include "common.h" -#if defined(HAVE_INTTYPES_H) -# include -#endif - #if !defined(__KERNEL__) +# if defined(HAVE_INTTYPES_H) +# include +# endif # include # include #endif @@ -28,7 +27,7 @@ uint32_t buffer[256 * 4]; -int main(void) +int main(int argc, char *argv[]) { caca_event_t ev; cucul_canvas_t *cv, *cw, *mask; diff --git a/test/hsv.c b/test/hsv.c index a0f348d..8f6960d 100644 --- a/test/hsv.c +++ b/test/hsv.c @@ -14,18 +14,19 @@ #include "config.h" #include "common.h" -#if defined(HAVE_INTTYPES_H) -# include +#if !defined(__KERNEL__) +# if defined(HAVE_INTTYPES_H) +# include +# endif +# include #endif -#include - #include "cucul.h" #include "caca.h" uint32_t buffer[256*256]; -int main(void) +int main(int argc, char *argv[]) { cucul_canvas_t *cv; caca_display_t *dp; diff --git a/test/import.c b/test/import.c index 82e3306..87dd8d8 100644 --- a/test/import.c +++ b/test/import.c @@ -14,12 +14,15 @@ #include "config.h" #include "common.h" -#if defined(HAVE_INTTYPES_H) -# include + +#if !defined(__KERNEL__) +# if defined(HAVE_INTTYPES_H) +# include +# endif +# include +# include #endif -#include -#include #include "cucul.h" #include "caca.h" diff --git a/test/input.c b/test/input.c index 0795eae..4380dc3 100644 --- a/test/input.c +++ b/test/input.c @@ -14,12 +14,13 @@ #include "config.h" #include "common.h" -#if defined(HAVE_INTTYPES_H) +#if !defined(__KERNEL__) +# if defined(HAVE_INTTYPES_H) # include +# endif +# include #endif -#include - #include "cucul.h" #include "caca.h" @@ -32,7 +33,7 @@ typedef struct textentry unsigned int size, cursor; } textentry; -int main(void) +int main(int argc, char *argv[]) { textentry entries[TEXT_ENTRIES]; cucul_canvas_t *cv; diff --git a/test/spritedit.c b/test/spritedit.c index 8abe1d2..c5c30ba 100644 --- a/test/spritedit.c +++ b/test/spritedit.c @@ -13,9 +13,9 @@ #include "config.h" #include "common.h" - -#include - +#if !defined(__KERNEL__) +# include +#endif #include "cucul.h" #include "caca.h" diff --git a/test/text.c b/test/text.c index 03c9674..920e620 100644 --- a/test/text.c +++ b/test/text.c @@ -13,14 +13,13 @@ #include "config.h" #include "common.h" - -#if defined(HAVE_INTTYPES_H) -# include +#if !defined(__KERNEL__) +# if defined(HAVE_INTTYPES_H) +# include +# endif +# include +# include #endif - -#include -#include - #include "cucul.h" #define STRING \ @@ -31,7 +30,7 @@ " \\ `--' / \n" \ " `----' \n" -int main(void) +int main(int argc, char *argv[]) { cucul_canvas_t *cv; cucul_buffer_t *buffer; diff --git a/test/transform.c b/test/transform.c index 4585e95..0e36f00 100644 --- a/test/transform.c +++ b/test/transform.c @@ -13,13 +13,13 @@ #include "config.h" #include "common.h" - -#if defined(HAVE_INTTYPES_H) -# include +#if !defined(__KERNEL__) +# if defined(HAVE_INTTYPES_H) +# include +# endif +# include #endif -#include - #include "cucul.h" #include "caca.h" @@ -44,7 +44,7 @@ static char const *duck[] = NULL }; -int main(void) +int main(int argc, char *argv[]) { cucul_canvas_t *cv, *normal, *flip, *flop, *rotate; caca_display_t *dp; diff --git a/test/truecolor.c b/test/truecolor.c index ae2af58..35fccd5 100644 --- a/test/truecolor.c +++ b/test/truecolor.c @@ -14,16 +14,17 @@ #include "config.h" #include "common.h" -#if defined(HAVE_INTTYPES_H) -# include +#if !defined(__KERNEL__) +# if defined(HAVE_INTTYPES_H) +# include +# endif +# include #endif -#include - #include "cucul.h" #include "caca.h" -int main(void) +int main(int argc, char *argv[]) { cucul_canvas_t *cv; caca_display_t *dp; diff --git a/test/unicode.c b/test/unicode.c index 159ea66..02c2818 100644 --- a/test/unicode.c +++ b/test/unicode.c @@ -14,16 +14,17 @@ #include "config.h" #include "common.h" -#if defined(HAVE_INTTYPES_H) -# include +#if !defined(__KERNEL__) +# if defined(HAVE_INTTYPES_H) +# include +# endif +# include #endif -#include - #include "cucul.h" #include "caca.h" -int main(void) +int main(int argc, char *argv[]) { cucul_canvas_t *cv; caca_display_t *dp; diff --git a/tools/optipal.c b/tools/optipal.c index cd33f2d..b5677ab 100644 --- a/tools/optipal.c +++ b/tools/optipal.c @@ -14,7 +14,9 @@ #include "config.h" #include "common.h" -#include +#if !defined(__KERNEL__) +# include +#endif #include "cucul.h" /* Only necessary for CUCUL_* macros */ @@ -44,7 +46,7 @@ static unsigned int const hue_list[] = } \ while(0); -int main(void) +int main(int argc, char *argv[]) { int i;