summaryrefslogtreecommitdiff
path: root/userspace
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2014-10-21 19:08:03 +0200
committerMichal Idziorek <m.i@gmx.at>2014-10-21 19:08:03 +0200
commitd25834310293c8a30b4a31418ff4ffd8fad8ef24 (patch)
tree97ae696211f7709002d80ecbfb8595123611d3c1 /userspace
parent5b9ea685dfd12415774e4e97ad387c601dd2b43b (diff)
started implementing our first fool-shell.
Diffstat (limited to 'userspace')
-rw-r--r--userspace/Makefile4
-rw-r--r--userspace/foolshell.c34
-rw-r--r--userspace/syscalls.c60
3 files changed, 68 insertions, 30 deletions
diff --git a/userspace/Makefile b/userspace/Makefile
index 21c4560..fc5e2dd 100644
--- a/userspace/Makefile
+++ b/userspace/Makefile
@@ -8,7 +8,7 @@ LDFLAGS=-L/home/miguel/temp/fool-os-stuff/newlib-build-clean/i686-elf/newlib/ \
-L/home/miguel/temp/fool-os-stuff/newlib-build-clean/i686-elf/libgloss/libnosys/ \
-lnosys
-all: brainfuck.o crt0.o
- ${CC} -T linker.ld ${LDFLAGS} brainfuck.o -Wl,--oformat,binary -o userprog
+all: foolshell.o crt0.o
+ ${CC} -T linker.ld ${LDFLAGS} $< -Wl,--oformat,binary -o userprog
clean:
-rm *.o *.out userprog
diff --git a/userspace/foolshell.c b/userspace/foolshell.c
new file mode 100644
index 0000000..bc02102
--- /dev/null
+++ b/userspace/foolshell.c
@@ -0,0 +1,34 @@
+#include <stdio.h>
+#include "syscalls.c"
+
+void hello() {
+ puts(
+ "Welcome to FoolShell v0.1"
+ );
+}
+
+void prompt() {
+ printf(
+ "$ "
+ );
+}
+int main(int argc, char **argv)
+{
+ syscalls_init();
+ hello();
+
+ FILE *input;
+ input=fopen(1,"r");
+ char *buf=malloc(256);
+
+ while(1)
+ {
+ prompt();
+ fgets(buf,255,input);
+ buf[strlen(buf)-1]=0;
+ puts(buf);
+ }
+
+
+ return 0;
+}
diff --git a/userspace/syscalls.c b/userspace/syscalls.c
index 7b0f563..f4e77a1 100644
--- a/userspace/syscalls.c
+++ b/userspace/syscalls.c
@@ -45,23 +45,27 @@ int lseek(int file, int ptr, int dir)
int read(int file, char *ptr, int len)
{
-// easywrite("syscall: read\n");
+ int ebx; // will hold return value;
+
+ asm("pusha");
+
+ // select syscall
+ asm("mov $62,%eax");
- int i;
- char buf[]="++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.";
+ // pass params
+ asm("mov %0,%%edx"::"m"(file));
+ asm("mov %0,%%ecx"::"m"(ptr));
+ asm("mov %0,%%ebx"::"m"(len));
- if(preread>=strlen(buf)){
-// easywrite("syscall: read = EOF\n");
- return 0; //EOF
- }
+ // interrrupt
+ asm("int $0x80");
- for(i=0;i<len;i++)
- {
- if(preread>=strlen(buf))return i;
- ptr[i]=buf[preread++];
- }
+ // get return value
+ asm("mov %%ebx, %0": "=b" (ebx));
+
+ asm("popa");
- return len;
+ return ebx;
}
int open(const char *name, int flags, int mode)
@@ -73,28 +77,28 @@ int open(const char *name, int flags, int mode)
int write(int file, char *ptr, int len)
{
- int todo;
- for (todo = 0; todo < len; todo++)
- {
-
- char byte=(*ptr++);
- int byt=byte;
int ebx; // will hold return value;
- // system call
+
asm("pusha");
- asm("mov $61,%eax"); // select syscall)
+
+ // select syscall
+ asm("mov $61,%eax");
- asm("mov %0,%%edx"::"m"(byt));
- //asm("mov $88,%edx");
+ // pass params
+ asm("mov %0,%%edx"::"m"(file));
+ asm("mov %0,%%ecx"::"m"(ptr));
+ asm("mov %0,%%ebx"::"m"(len));
+
+ // interrupt
+ asm("int $0x80");
+
+ // get return value
+ asm("mov %%ebx, %0": "=b" (ebx));
- asm("int $0x80"); // actual syscall ! interrupt
- asm("mov %%ebx, %0": "=b" (ebx));
asm("popa");
- //
- }
- return len;
+ return ebx;
}