summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-09-21 03:14:52 +0200
committerMiguel <m.i@gmx.at>2018-09-21 03:14:52 +0200
commitd4bc2ecdd1d0b3d3f3642a5f02840d1e0cb5e199 (patch)
tree076ecc41b928c057a6c10df6508237961d714958
parentace0646608c393d8952b14536090c302bed2ee85 (diff)
piper works so nice
-rw-r--r--driver/terminal.c2
-rw-r--r--kernel/kernel.h2
-rw-r--r--kernel/scheduler.c4
-rw-r--r--kernel/syscalls.c1
-rw-r--r--userspace/Makefile1
-rw-r--r--userspace/file.txt82
-rw-r--r--userspace/foolshell.c54
-rw-r--r--userspace/grep.c67
-rw-r--r--userspace/number.c22
9 files changed, 222 insertions, 13 deletions
diff --git a/driver/terminal.c b/driver/terminal.c
index 978a7be..c399ca0 100644
--- a/driver/terminal.c
+++ b/driver/terminal.c
@@ -41,7 +41,7 @@ typedef enum {
ecma48_underscore_on, // set def color
ecma48_underscore_off, // set def color
- ecma48_bg_black,
+ ecma48_bg_black, //40
ecma48_bg_red,
ecma48_bg_green,
ecma48_bg_brown,
diff --git a/kernel/kernel.h b/kernel/kernel.h
index 5f21bc6..e52bcf3 100644
--- a/kernel/kernel.h
+++ b/kernel/kernel.h
@@ -34,7 +34,7 @@ REFERENCES
#define FIFO_MAX_RINGBUFFERS 20
#define MAX_FIFOS 20
#define MAX_FD 20
-#define MAX_TASKS 10
+#define MAX_TASKS 100
#define MEM_PRINT_MEMORYMAP
#define KMALLOC_MEM_SIZE 1024*1024*8 // 8MB for in kernel-memory
diff --git a/kernel/scheduler.c b/kernel/scheduler.c
index 56f6bbc..c13fd4e 100644
--- a/kernel/scheduler.c
+++ b/kernel/scheduler.c
@@ -295,7 +295,7 @@ void task_syscall_worker()
{
uint32_t syscall=task_list[cpu][i].eax;
- klog("task pid=%d waiting on syscall %d/%s on cpu %d slot %d.",task_list[cpu][i].pid,syscall,syscall_get_name(syscall),cpu,i);
+// klog("task pid=%d waiting on syscall %d/%s on cpu %d slot %d.",task_list[cpu][i].pid,syscall,syscall_get_name(syscall),cpu,i);
task_list[cpu][0].vmem=task_list[cpu][i].vmem; // switch syscall worker to pagedir of calling userprog
x86_set_page_directory(task_list[cpu][0].vmem);
@@ -318,7 +318,7 @@ void task_syscall_worker()
task_list[cpu][i].ebx,
task_list[cpu][i].pid);
- klog("... returned : %d",ret);
+// klog("... returned : %d",ret);
scheduler_wake_all();
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index ee100e2..edc4751 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -375,7 +375,6 @@ uint32_t syscall_pipe(uint32_t *addr,int none1, int none2, uint32_t pid)
uint32_t syscall_dup2(uint32_t oldfd,int newfd, int none2, uint32_t pid)
{
- fd_close(&fds[pid][newfd]);
fds[pid][newfd]=fd_dupl(&fds[pid][oldfd]);
return newfd;
}
diff --git a/userspace/Makefile b/userspace/Makefile
index b3c962b..f2ca823 100644
--- a/userspace/Makefile
+++ b/userspace/Makefile
@@ -42,6 +42,7 @@ ext2.img: $(PROGS)
@mkdir -p mnt/home/miguel
@mkdir -p mnt/boot
@echo "Welcome to FoolOs\nWe hope you will enjoy your stay." > mnt/home/miguel/hello.txt
+ @cp file.txt mnt/home/miguel/file.txt
@mkdir -p mnt/bin
@mkdir -p mnt/doc/test
@mkdir -p mnt/sys # mountpoint for sysfs
diff --git a/userspace/file.txt b/userspace/file.txt
new file mode 100644
index 0000000..8cdd524
--- /dev/null
+++ b/userspace/file.txt
@@ -0,0 +1,82 @@
+Sometimes someone would speak in a boat. But most
+of the boats were silent except for the dip of the
+oars. They spread apart after they were out of the
+mouth of the harbour and each one headed for the
+part of the ocean where he hoped to find fish. The
+old man knew he was going far out and he left the
+smell of the land behind and rowed out into the
+clean early morning smell of the ocean. He saw the
+phosphorescence of the Gulf weed in the water as
+he rowed over the part of the ocean that the
+fishermen called the great well because there was
+a sudden deep of seven hundred fathoms where all
+sorts of fish congregated because of the swirl the
+current made against the steep walls of the floor
+of the ocean. Here there were concentrations of
+shrimp and bait fish and sometimes schools of
+squid in the deepest holes and these rose close to
+the surface at night where all the wandering fish
+fed on them.
+
+In the dark the old man could feel the morning
+coming and as he rowed he heard the trembling
+sound as flying fish left the water and the
+hissing that their stiff set wings made as they
+soared away in the darkness. He was very fond of
+flying fish as they were his principal friends on
+the ocean. He was sorry for the birds, especially
+the small delicate dark terns that were always
+flying and looking and almost never finding, and
+he thought, "The birds have a harder life than we
+do except for the robber birds and the heavy
+strong ones. Why did they make birds so delicate
+and fine as those sea swallows when the ocean can
+be so cruel? She is kind and very beautiful. But
+she can be so cruel and it comes so suddenly and
+such birds that fly, dipping and hunting, with
+their small sad voices are made too delicately for
+the sea."
+
+He always thought of the sea as la mar which is
+what people call her in Spanish when they love
+her. Sometimes those who love her say bad things
+of her but they are always said as though she were
+a woman. Some of the younger fishermen, those who
+used buoys as floats for their lines and had
+motorboats, bought when the shark livers had
+brought much money, spoke of her as el mar which
+is masculine. They spoke of her as a contestant or
+a place or even an enemy. But the old man always
+thought of her as feminine and as something that
+gave or withheld great favours, and if she did
+wild or wicked things it was because she could not
+help them. The moon affects her as it does a
+woman, he thought.
+
+He was rowing steadily and it was no effort for
+him since he kept well within his speed and the
+surface of the ocean was flat except for the
+occasional swirls of the current. He was letting
+the current do a third of the work and as it
+started to be light he saw he was already further
+out than he had hoped to be at this hour.
+
+I worked the deep wells for a week and did
+nothing, he thought. Today I'll work out where the
+schools of bonita and albacore are and maybe there
+will be a big one with them.
+
+Before it was really light he had his baits out
+and was drifting with the current. One bait was
+down forty fathoms. The second was at seventy-five
+and the third and fourth were down in the blue
+water at one hundred and one hundred and
+twenty-five fathoms. Each bait hung head down with
+the shank of the hook inside the bait fish, tied
+and sewed solid and all the projecting part of the
+hook, the curve and the point, was covered with
+fresh sardines. Each sardine was hooked through
+both eyes so that they made a half-garland on the
+projecting steel. There was no part of the hook
+that a great fish could feel which was not sweet
+smelling and good tasting.
diff --git a/userspace/foolshell.c b/userspace/foolshell.c
index e8b384e..4d011da 100644
--- a/userspace/foolshell.c
+++ b/userspace/foolshell.c
@@ -15,9 +15,13 @@
#include <errno.h>
#include <string.h>
+
+#include "newcalls.h"
+
extern char **environ;
bool process(char *buf);
+bool metaprocess(char *buf);
bool cd(char *path);
void version()
@@ -96,7 +100,7 @@ int main(int argc, char **argv)
}
}
- if(!process(buf))break; // process input and return if exit
+ if(!metaprocess(buf))break; // process input and return if exit
}
return 0;
@@ -142,6 +146,52 @@ char **tokenize(char *buf,char chr)
return token;
}
+bool metaprocess2(char *buf);
+bool metaprocess(char *buf)
+{
+ char **token=tokenize(buf,'|');
+ if(token[0]==0 || token[1]==0)return process(buf); // no pipes
+
+ int pid=_fork();
+
+ if(pid==0)
+ {
+ metaprocess2(buf);
+ exit(1);
+ }
+
+ _wait(pid);
+ return true;
+}
+
+bool metaprocess2(char *buf)
+{
+ char **token=tokenize(buf,'|');
+ if(token[0]==0 || token[1]==0)return process(buf); // no pipes
+
+ int fds[2];
+ _pipe(fds);
+
+ int pid=_fork();
+
+ if(pid==0)
+ {
+ // first child shall write to the pipe
+ _close(fds[0]);
+ _dup2(fds[1],1); // replace stdout with the write-end of our pipe
+ process(token[0]);
+ exit(1);
+ }
+
+ _close(fds[1]); // and we read from it
+ _dup2(fds[0],0);
+ metaprocess2(strchr(buf,'|')+1);
+
+ _wait(pid);
+
+ return true;
+}
+
bool process(char *buf)
{
char **token=tokenize(buf,' ');
@@ -179,7 +229,7 @@ bool process(char *buf)
else sprintf(buf,"%s/%s",getenv("PATH"),token[0]);
_execve(buf,token,environ);
printf("foolshell: %s (errno: %d)\n",strerror(errno),errno);
- return false;
+ exit(1);
}
if(token[1]==NULL||strcmp(token[1],"&"))_wait(pid);
diff --git a/userspace/grep.c b/userspace/grep.c
index 68d5b7a..058f1f8 100644
--- a/userspace/grep.c
+++ b/userspace/grep.c
@@ -1,18 +1,73 @@
#include <stdio.h>
#include <stdlib.h>
+// https://www.programmingsimplified.com/c/source-code/c-program-insert-substring-into-string
+//
+char *substring(char *string, int position, int length)
+{
+ char *pointer;
+ int c;
+
+ pointer = malloc(length+1);
+
+ if( pointer == NULL )
+ exit(EXIT_FAILURE);
+
+ for( c = 0 ; c < length ; c++ )
+ *(pointer+c) = *((string+position-1)+c);
+
+ *(pointer+c) = '\0';
+
+ return pointer;
+}
+
+
+void insert_substring(char *a, char *b, int position)
+{
+ char *f, *e;
+ int length;
+
+ length = strlen(a);
+
+ f = substring(a, 1, position - 1 );
+ e = substring(a, position, length-position+1);
+
+ strcpy(a, "");
+ strcat(a, f);
+ free(f);
+ strcat(a, b);
+ strcat(a, e);
+ free(e);
+}
+
int main(int argc, char **argv)
{
+ char col_start[]="\033[31;40m";
+ char col_end[]="\033[37;40m";
+
FILE *in=stdin;
FILE *out=stdout;
- while(1)
+ int i=1;
+ while(!feof(in))
{
- char buf[2];
- int l=fread(buf,1,1,in);
- if(l==0)break;
- buf[l]=0;
- fwrite(buf,1,l,out);
+ char buf[256];
+ char buf2[255];
+ fgets(buf,255,in);
+
+ char *pos=strstr(buf,argv[1]);
+ if(pos)
+ {
+ int p=pos-buf+1;
+ int l=strlen(argv[1])+strlen(col_start);
+
+ insert_substring(buf,col_start,p);
+ insert_substring(buf,col_end,p+l);
+
+ printf("%s",buf);
+ }
+
+ i++;
}
return EXIT_SUCCESS;
diff --git a/userspace/number.c b/userspace/number.c
new file mode 100644
index 0000000..b10bccb
--- /dev/null
+++ b/userspace/number.c
@@ -0,0 +1,22 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char **argv)
+{
+ char col_start[]="\033[34;40m";
+ char col_end[]="\033[37;40m";
+
+ FILE *in=stdin;
+ FILE *out=stdout;
+
+ int i=1;
+ char buf[256];
+ while(NULL!=fgets(buf,255,in))
+ {
+ printf("line %s%i%s: %s",col_start,i,col_end,buf);
+ //printf("line %i : %s",i,buf);
+ i++;
+ }
+
+ return EXIT_SUCCESS;
+}