summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-08-17 03:57:35 +0200
committerMiguel <m.i@gmx.at>2018-08-17 03:57:35 +0200
commit413f1f19184acd9024b9a97156c467b88ff72484 (patch)
treefcc8ba0a4ea8a1785d5818c7793e946da84e07e6
parentc742be9c738c91703a7be787639cad167de3a6b1 (diff)
math, time, seed and randomness - simple test
-rw-r--r--kernel/syscalls.c16
-rw-r--r--kernel/timer.c8
-rw-r--r--userspace/Makefile8
-rw-r--r--userspace/add.c41
-rw-r--r--userspace/crt0.S3
-rw-r--r--userspace/task1.c1
-rw-r--r--userspace/test-math.c32
7 files changed, 58 insertions, 51 deletions
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index 31579e1..e3db767 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -6,6 +6,7 @@
#include "kernel/kernel.h"
#include "kernel/config.h"
#include <sys/stat.h>
+#include <sys/time.h>
#include <stdbool.h>
#include <stddef.h>
@@ -15,9 +16,20 @@ int syscall_unhandled(int nr)
panic(FOOLOS_MODULE_NAME,"unhandled syscall (generic handler)");
}
-int syscall_gettimeofday(void *timeval, void *tz)
+int syscall_gettimeofday(struct timeval *tv, struct timezone *tz)
{
- return -1;
+ if(tv!=NULL)
+ {
+ uint32_t t=timer_get_ms();
+ tv->tv_sec=t/1000;
+ tv->tv_usec=0;//t-tv->tv_sec*1000;
+ }
+ if(tz!=NULL)
+ {
+ tz->tz_minuteswest=0;
+ tz->tz_dsttime=DST_NONE;
+ }
+ return 0;
}
int syscall_lseek(int file,int ptr,int dir)
diff --git a/kernel/timer.c b/kernel/timer.c
index 5adc986..9ca748c 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -73,3 +73,11 @@ uint64_t timer_get_ticks()
{
return task_system_clock;
}
+
+uint32_t timer_get_ms()
+{
+ uint32_t t=timer_get_ticks();
+ uint32_t s=t/25;
+ uint32_t ms=t*1000/25-1000*s;
+ return s*1000;//+ms;
+}
diff --git a/userspace/Makefile b/userspace/Makefile
index 62bc857..2812edd 100644
--- a/userspace/Makefile
+++ b/userspace/Makefile
@@ -1,4 +1,3 @@
-
CC=i686-foolos-gcc
CC=i686-elf-gcc
@@ -12,9 +11,10 @@ CFLAGS+=-g
#CFLAGS+=-fstack-protector-all
#LDFLAGS=-nostdlib
-LDFLAGS=-L/home/miguel/foolos/usr/i686-foolos/lib/ -lc -lm -lg -lnosys
+LDFLAGS=-L/home/miguel/foolos/usr/i686-foolos/lib/
+LDLIBS=-lc -lm -lg -lnosys
-PROGS=foolshell ls simple brainfuck add checker clear task1 task2 init cat snake
+PROGS=foolshell ls simple brainfuck test-math checker clear task1 task2 init cat snake
include ../Makefile.common
@@ -50,7 +50,7 @@ brainfuck: brainfuck.o
snake: snake.o
foolshell: foolshell.o
simple: simple.o
-add: add.o
+test-math: test-math.o
checker: checker.o
task1: task1.o
task2: task2.o
diff --git a/userspace/add.c b/userspace/add.c
deleted file mode 100644
index 94bb244..0000000
--- a/userspace/add.c
+++ /dev/null
@@ -1,41 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include <stdint.h>
-#include <math.h>
-#include "../fs/fs.h"
-
-int main(int argc, char **argv)
-{
-
- float sum=0;
- float i=0;
-
- char *buf=malloc(256);
- puts("\n*** fools calculator ***");
-
- while(1)
- {
- printf("enter numer (or 'exit' to finish) %i: ",i+1);
- fgets(buf,255,stdin);
-
- if(buf[1]=='x')break;
-
- i++;
- sum+=atoi(buf);
- }
-
- if(i!=0)
- {
- puts("--------");
- printf("sum = %f \n",sum);
- printf("avg = %f \n",sum/i);
-// printf("sin(avg) = %f \n\n",sin(sum/i));
- }
-
- return 0;
-}
-
-
-
-
-
diff --git a/userspace/crt0.S b/userspace/crt0.S
index 4c08f89..23efec5 100644
--- a/userspace/crt0.S
+++ b/userspace/crt0.S
@@ -24,6 +24,3 @@ call _exit2
.wait:
hlt
jmp .wait
-
-.hellostr:
-.ascii "Hello Ass"
diff --git a/userspace/task1.c b/userspace/task1.c
index d9875f4..793b7f8 100644
--- a/userspace/task1.c
+++ b/userspace/task1.c
@@ -27,7 +27,6 @@ ULL fib(ULL i)
}
-
int main(unsigned int argc, char **argv)
{
ULL i=0;
diff --git a/userspace/test-math.c b/userspace/test-math.c
new file mode 100644
index 0000000..acaecad
--- /dev/null
+++ b/userspace/test-math.c
@@ -0,0 +1,32 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <math.h>
+#include <time.h>
+
+int main(int argc, char **argv)
+{
+ time_t ltime;
+ time(&ltime);
+ printf("the time is %s", ctime(&ltime));
+
+ unsigned int seed=time(NULL);
+ printf("seed = %u\n",seed);
+
+ srand(seed);
+
+ for(int i=0;i<10;i++)
+ {
+ int r=rand()%100;
+ printf("sin(%i) = %f \n",r,sin(r));
+ }
+
+
+ return 0;
+}
+
+
+
+
+