summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/buffer/ringbuffer.c76
-rw-r--r--lib/buffer/ringbuffer.h3
-rw-r--r--lib/logger/log.c94
-rw-r--r--lib/logger/log.h14
-rw-r--r--lib/printf/printf.c250
-rw-r--r--lib/printf/printf.h125
-rw-r--r--lib/string/string.c37
-rw-r--r--lib/string/string.h3
8 files changed, 0 insertions, 602 deletions
diff --git a/lib/buffer/ringbuffer.c b/lib/buffer/ringbuffer.c
deleted file mode 100644
index a121df1..0000000
--- a/lib/buffer/ringbuffer.c
+++ /dev/null
@@ -1,76 +0,0 @@
-// can handle one buffer for a start.
-// later make it reentrant and manage multiple buffers!
-// todo: syncing access to buffer.
-
-#define FOOLOS_MODULE_NAME "ringbuffer"
-
-#include "ringbuffer.h"
-#include "kernel/x86.h"
-#include "lib/logger/log.h"
-#include "kernel/spinlock.h"
-
-#define RINGBUFFER_SIZE 10
-static int size=RINGBUFFER_SIZE;
-static volatile int front=RINGBUFFER_SIZE-1;
-static volatile int back=RINGBUFFER_SIZE-1;
-static volatile char buf[RINGBUFFER_SIZE];
-
-static spinlock sl=9;
-
-bool ringbuffer_put(char c)
-{
-
- x86_int_disable();
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"put wants lock");
- lock_spin(sl);
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"locked by put");
-
- if((back-1+size)%size==front)
- {
- lock_release(sl);
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by put");
- x86_int_enable();
- return false;
- }
-
- buf[back]=c;
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"put %d %d (%c)", back, front,c);
- back--;
- back+=size;
- back%=size;
-
- lock_release(sl);
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by put");
- x86_int_enable();
-
- return true;
-}
-
-bool ringbuffer_get(char *c)
-{
- x86_int_disable();
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"get wants lock");
- lock_spin(sl);
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"locked by get");
- if(front==back)
- {
- lock_release(sl);
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by get");
- x86_int_enable();
- *c='_';
- return false;
- }
-
- *c=buf[front];
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"get %d %d (%c)", back, front,*c);
-
- front--;
- front+=size;
- front%=size;
-
- lock_release(sl);
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by get");
- x86_int_enable();
-
- return true;
-}
diff --git a/lib/buffer/ringbuffer.h b/lib/buffer/ringbuffer.h
deleted file mode 100644
index 038e33a..0000000
--- a/lib/buffer/ringbuffer.h
+++ /dev/null
@@ -1,3 +0,0 @@
-#include <stdbool.h>
-bool ringbuffer_put(char c);
-bool ringbuffer_get(char *c);
diff --git a/lib/logger/log.c b/lib/logger/log.c
deleted file mode 100644
index 430f982..0000000
--- a/lib/logger/log.c
+++ /dev/null
@@ -1,94 +0,0 @@
-#define FOOLOS_MODULE_NAME "log"
-
-#include <stdarg.h>
-#include <stdbool.h>
-
-#include "log.h"
-#include "kernel/config.h"
-#include "terminal/vt52.h"
-#include "lib/printf/printf.h"
-#include "kernel/timer.h"
-
-
-static char buffer[LOG_BUF_SIZE];
-static int first=0;
-static int last=0;
-static bool init=true;//
-
-static void init_log()
-{
-}
-
-void log(char *module_name, int log_level, char *format_string, ...)
-{
-
- #ifdef FOOLOS_LOG_OFF
- return;
- #endif
-
- if(log_level<FOOLOS_LOG_INFO)return;
-
- char buf_info[256];
- char buf_log[256];
- char buf_time[20];
-
- uint32_t t=timer_get_ticks();
- uint32_t s=t/25;
- uint32_t ms=t*1000/25-1000*s;
-
- tfp_sprintf(buf_time,"[%3d.%05d]",s,ms);
-
- va_list va;
- va_start(va,format_string);
- tfp_vsprintf(buf_info,format_string,va);
- va_end(va);
-
- tfp_sprintf(buf_log,"%s %s: %s\n",buf_time,module_name,buf_info);
-
- if(init)console_put_str_gray(buf_log);
-
- for(int i=0;buf_log[i]!=0;i++)
- {
- buffer[last]=buf_log[i];
- last=(last+1)%LOG_BUF_SIZE;
- if(first<last)if(last-first>=LOG_BUF_SIZE)first=(first+1)%LOG_BUF_SIZE;
- if(last>first)if(LOG_BUF_SIZE-last+first>=LOG_BUF_SIZE)first=(first+1)%LOG_BUF_SIZE;
- }
-
-
-}
-
-void panic(char *module_name, char *message)
-{
- char buf_log[256];
- tfp_sprintf(buf_log,"KERNEL PANIC !! %s: %s\n",module_name,message);
- //console_put_str_red(buf_log);
-
- while(1)
- {
- asm volatile("cli");
- asm volatile("hlt");
- }
-
-}
-
-// unused shit!
-/*
-static void log_log()
-{
- #ifdef FOOLOS_LOG_OFF
- return;
- #endif
-
- char buf_log[256];
- tfp_sprintf(buf_log,"[ 0.00000] log: buffer state: first=%d, last=%d, buf_size=%d\n",first,last,LOG_BUF_SIZE);
- console_put_str_gray(buf_log);
- for(int i=first;i!=last;i++)
- {
- console_put_char_gray(buffer[i]);
-
- }
-
- init=true;
-}
-*/
diff --git a/lib/logger/log.h b/lib/logger/log.h
deleted file mode 100644
index da27340..0000000
--- a/lib/logger/log.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifndef FOOLOS_LOG_H
-#define FOOLOS_LOG_H
-
-#define FOOLOS_LOG_ERROR 5
-#define FOOLOS_LOG_WARNING 4
-#define FOOLOS_LOG_INFO 3
-#define FOOLOS_LOG_DEBUG 2
-#define FOOLOS_LOG_FINE 1
-
-void log(char *module_name, int prio, char *format_string, ...);
-void panic(char *module_name, char *format_string);
-void log_log();
-
-#endif
diff --git a/lib/printf/printf.c b/lib/printf/printf.c
deleted file mode 100644
index 23d3d46..0000000
--- a/lib/printf/printf.c
+++ /dev/null
@@ -1,250 +0,0 @@
-/*
- * Copyright (c) 2004,2012 Kustaa Nyholm / SpareTimeLabs
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list
- * of conditions and the following disclaimer.
- *
- * 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.
- *
- * Neither the name of the Kustaa Nyholm or SpareTimeLabs 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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 "printf.h"
-
-typedef void (*putcf) (void*,char);
-static putcf stdout_putf;
-static void* stdout_putp;
-
-
-#ifdef PRINTF_LONG_SUPPORT
-
-static void uli2a(unsigned long int num, unsigned int base, int uc,char * bf)
- {
- int n=0;
- unsigned int d=1;
- while (num/d >= base)
- d*=base;
- while (d!=0) {
- int dgt = num / d;
- num%=d;
- d/=base;
- if (n || dgt>0|| d==0) {
- *bf++ = dgt+(dgt<10 ? '0' : (uc ? 'A' : 'a')-10);
- ++n;
- }
- }
- *bf=0;
- }
-
-static void li2a (long num, char * bf)
- {
- if (num<0) {
- num=-num;
- *bf++ = '-';
- }
- uli2a(num,10,0,bf);
- }
-
-#endif
-
-static void ui2a(unsigned int num, unsigned int base, int uc,char * bf)
- {
- int n=0;
- unsigned int d=1;
- while (num/d >= base)
- d*=base;
- while (d!=0) {
- int dgt = num / d;
- num%= d;
- d/=base;
- if (n || dgt>0 || d==0) {
- *bf++ = dgt+(dgt<10 ? '0' : (uc ? 'A' : 'a')-10);
- ++n;
- }
- }
- *bf=0;
- }
-
-static void i2a (int num, char * bf)
- {
- if (num<0) {
- num=-num;
- *bf++ = '-';
- }
- ui2a(num,10,0,bf);
- }
-
-static int a2d(char ch)
- {
- if (ch>='0' && ch<='9')
- return ch-'0';
- else if (ch>='a' && ch<='f')
- return ch-'a'+10;
- else if (ch>='A' && ch<='F')
- return ch-'A'+10;
- else return -1;
- }
-
-static char a2i(char ch, char** src,int base,int* nump)
- {
- char* p= *src;
- int num=0;
- int digit;
- while ((digit=a2d(ch))>=0) {
- if (digit>base) break;
- num=num*base+digit;
- ch=*p++;
- }
- *src=p;
- *nump=num;
- return ch;
- }
-
-static void putchw(void* putp,putcf putf,int n, char z, char* bf)
- {
- char fc=z? '0' : ' ';
- char ch;
- char* p=bf;
- while (*p++ && n > 0)
- n--;
- while (n-- > 0)
- putf(putp,fc);
- while ((ch= *bf++))
- putf(putp,ch);
- }
-
-void tfp_format(void* putp,putcf putf,char *fmt, va_list va)
- {
- char bf[12];
-
- char ch;
-
-
- while ((ch=*(fmt++))) {
- if (ch!='%')
- putf(putp,ch);
- else {
- char lz=0;
-#ifdef PRINTF_LONG_SUPPORT
- char lng=0;
-#endif
- int w=0;
- ch=*(fmt++);
- if (ch=='0') {
- ch=*(fmt++);
- lz=1;
- }
- if (ch>='0' && ch<='9') {
- ch=a2i(ch,&fmt,10,&w);
- }
-#ifdef PRINTF_LONG_SUPPORT
- if (ch=='l') {
- ch=*(fmt++);
- lng=1;
- }
-#endif
- switch (ch) {
- case 0:
- goto abort;
- case 'u' : {
-#ifdef PRINTF_LONG_SUPPORT
- if (lng)
- uli2a(va_arg(va, unsigned long int),10,0,bf);
- else
-#endif
- ui2a(va_arg(va, unsigned int),10,0,bf);
- putchw(putp,putf,w,lz,bf);
- break;
- }
- case 'd' : {
-#ifdef PRINTF_LONG_SUPPORT
- if (lng)
- li2a(va_arg(va, unsigned long int),bf);
- else
-#endif
- i2a(va_arg(va, int),bf);
- putchw(putp,putf,w,lz,bf);
- break;
- }
- case 'x': case 'X' :
-#ifdef PRINTF_LONG_SUPPORT
- if (lng)
- uli2a(va_arg(va, unsigned long int),16,(ch=='X'),bf);
- else
-#endif
- ui2a(va_arg(va, unsigned int),16,(ch=='X'),bf);
- putchw(putp,putf,w,lz,bf);
- break;
- case 'c' :
- putf(putp,(char)(va_arg(va, int)));
- break;
- case 's' :
- putchw(putp,putf,w,0,va_arg(va, char*));
- break;
- case '%' :
- putf(putp,ch);
- default:
- break;
- }
- }
- }
- abort:;
- }
-
-
-void init_printf(void* putp,void (*putf) (void*,char))
- {
- stdout_putf=putf;
- stdout_putp=putp;
- }
-
-void tfp_printf(char *fmt, ...)
- {
- va_list va;
- va_start(va,fmt);
- tfp_format(stdout_putp,stdout_putf,fmt,va);
- va_end(va);
- }
-
-static void putcp(void* p,char c)
- {
- *(*((char**)p))++ = c;
- }
-
-
-
-void tfp_vsprintf(char* s,char *fmt, va_list va)
- {
- tfp_format(&s,putcp,fmt,va);
- putcp(&s,0);
- }
-
-void tfp_sprintf(char* s,char *fmt, ...)
- {
- va_list va;
- va_start(va,fmt);
- tfp_vsprintf(s,fmt,va);
- va_end(va);
- }
-
-
diff --git a/lib/printf/printf.h b/lib/printf/printf.h
deleted file mode 100644
index 0e65915..0000000
--- a/lib/printf/printf.h
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
-File: printf.h
-
-Copyright (c) 2004,2012 Kustaa Nyholm / SpareTimeLabs
-
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without modification,
-are permitted provided that the following conditions are met:
-
-Redistributions of source code must retain the above copyright notice, this list
-of conditions and the following disclaimer.
-
-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.
-
-Neither the name of the Kustaa Nyholm or SpareTimeLabs 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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 library is realy just two files: 'printf.h' and 'printf.c'.
-
-They provide a simple and small (+200 loc) printf functionality to
-be used in embedded systems.
-
-I've found them so usefull in debugging that I do not bother with a
-debugger at all.
-
-They are distributed in source form, so to use them, just compile them
-into your project.
-
-Two printf variants are provided: printf and sprintf.
-
-The formats supported by this implementation are: 'd' 'u' 'c' 's' 'x' 'X'.
-
-Zero padding and field width are also supported.
-
-If the library is compiled with 'PRINTF_SUPPORT_LONG' defined then the
-long specifier is also
-supported. Note that this will pull in some long math routines (pun intended!)
-and thus make your executable noticably longer.
-
-The memory foot print of course depends on the target cpu, compiler and
-compiler options, but a rough guestimate (based on a H8S target) is about
-1.4 kB for code and some twenty 'int's and 'char's, say 60 bytes of stack space.
-Not too bad. Your milage may vary. By hacking the source code you can
-get rid of some hunred bytes, I'm sure, but personally I feel the balance of
-functionality and flexibility versus code size is close to optimal for
-many embedded systems.
-
-To use the printf you need to supply your own character output function,
-something like :
-
-void putc ( void* p, char c)
- {
- while (!SERIAL_PORT_EMPTY) ;
- SERIAL_PORT_TX_REGISTER = c;
- }
-
-Before you can call printf you need to initialize it to use your
-character output function with something like:
-
-init_printf(NULL,putc);
-
-Notice the 'NULL' in 'init_printf' and the parameter 'void* p' in 'putc',
-the NULL (or any pointer) you pass into the 'init_printf' will eventually be
-passed to your 'putc' routine. This allows you to pass some storage space (or
-anything realy) to the character output function, if necessary.
-This is not often needed but it was implemented like that because it made
-implementing the sprintf function so neat (look at the source code).
-
-The code is re-entrant, except for the 'init_printf' function, so it
-is safe to call it from interupts too, although this may result in mixed output.
-If you rely on re-entrancy, take care that your 'putc' function is re-entrant!
-
-The printf and sprintf functions are actually macros that translate to
-'tfp_printf' and 'tfp_sprintf'. This makes it possible
-to use them along with 'stdio.h' printf's in a single source file.
-You just need to undef the names before you include the 'stdio.h'.
-Note that these are not function like macros, so if you have variables
-or struct members with these names, things will explode in your face.
-Without variadic macros this is the best we can do to wrap these
-fucnction. If it is a problem just give up the macros and use the
-functions directly or rename them.
-
-For further details see source code.
-
-regs Kusti, 23.10.2004
-*/
-
-
-#ifndef __TFP_PRINTF__
-#define __TFP_PRINTF__
-
-#include <stdarg.h>
-
-void init_printf(void* putp,void (*putf) (void*,char));
-
-void tfp_printf(char *fmt, ...);
-void tfp_sprintf(char* s,char *fmt, ...);
-void tfp_vsprintf(char* s,char *fmt, va_list va);
-
-void tfp_format(void* putp,void (*putf) (void*,char),char *fmt, va_list va);
-
-#define printf tfp_printf
-#define sprintf tfp_sprintf
-
-#endif
-
-
-
diff --git a/lib/string/string.c b/lib/string/string.c
deleted file mode 100644
index 729c509..0000000
--- a/lib/string/string.c
+++ /dev/null
@@ -1,37 +0,0 @@
-#include <stdbool.h>
-
-//length 0 for null terminated strings;
-bool strcmp(char *str1, char *str2, int length)
-{
- int i=0;
- while(true)
- {
- if(str1[i]!=str2[i])return false;
- i++;
-
- if(i==length) return true;
- if(str1[i]==0||str2[i]==0)
- {
- if(str1[i]==str2[i])return true;
- return false;
- }
- }
-
-}
-
-void* memcpy(void* restrict dstptr, const void* restrict srcptr, int size)
-{
- unsigned char* dst = (unsigned char*) dstptr;
- const unsigned char* src = (const unsigned char*) srcptr;
- for ( int i = 0; i < size; i++ )
- dst[i] = src[i];
- return dstptr;
-}
-
-int strlen(const char* string)
-{
- int result = 0;
- while ( string[result] )
- result++;
- return result;
-}
diff --git a/lib/string/string.h b/lib/string/string.h
deleted file mode 100644
index a804de9..0000000
--- a/lib/string/string.h
+++ /dev/null
@@ -1,3 +0,0 @@
-#include <stdbool.h>
-bool strcmp(char *str1, char *str2, int length);
-void* memcpy(void* restrict dstptr, const void* restrict srcptr, int size);