summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile8
-rw-r--r--README.md1
-rw-r--r--asm/int_syscall_handler.asm10
-rw-r--r--kernel/config.h1
-rw-r--r--kernel/interrupts.c15
-rw-r--r--kernel/kernel.c17
-rw-r--r--kernel/syscalls.c23
-rw-r--r--kernel/vesa.c23
-rw-r--r--userspace/Makefile14
-rw-r--r--userspace/crt0.S9
-rw-r--r--userspace/linker.ld4
-rw-r--r--userspace/test.c104
12 files changed, 199 insertions, 30 deletions
diff --git a/Makefile b/Makefile
index fc7dec2..9dac9b0 100644
--- a/Makefile
+++ b/Makefile
@@ -105,9 +105,10 @@ FoolOS.img: $(MBR) $(STAGE2) kernel.bin $(FILLUP) FoolData.img
binfont.img: binfont.bin
cat $^ > $@
-FoolData.img: binfont.bin $(MP_BIN)
+FoolData.img: binfont.bin $(MP_BIN) userspace/userprog
dd if=$(MP_BIN) of=$@ bs=512 seek=0 conv=notrunc
dd if=binfont.bin of=$@ bs=512 seek=1 conv=notrunc
+ dd if=userspace/userprog of=$@ bs=512 seek=4 conv=notrunc
############ vm stuff ############
@@ -121,10 +122,15 @@ run: all
clean:
-rm *.bin *.img bochs.log $(KERNEL_ENTRY) $(ASMOBJECTS) $(OBJECTS) $(FILLUP) $(MBR) $(MP_BIN) bochs.out ne2k-tx.log ne2k-txdump.txt $(STAGE2)
+ make -C userspace clean
+
release: all
-rm *.bin FoolData.img binfont.img bochs.log $(KERNEL_ENTRY) $(ASMOBJECTS) $(OBJECTS) $(FILLUP) $(MBR) $(MP_BIN) bochs.out ne2k-tx.log ne2k-txdump.txt $(STAGE2)
+userspace/userprog:
+ make -C userspace
+
############ test stuff ############
stick: FoolOS.img
diff --git a/README.md b/README.md
index c1d32f7..3a5a418 100644
--- a/README.md
+++ b/README.md
@@ -67,6 +67,7 @@ Please note that all features are only very rudimentary and buggy.
Todos
-----
+* set up os-specific toolchain
* set dependancies in the makefile!
* Port newlib and gcc
* Shell
diff --git a/asm/int_syscall_handler.asm b/asm/int_syscall_handler.asm
index e607ff5..37bc71a 100644
--- a/asm/int_syscall_handler.asm
+++ b/asm/int_syscall_handler.asm
@@ -3,6 +3,8 @@ global int_syscall_handler
[extern example_syscall]
[extern example_syscall_2]
+[extern syscall_outbyte]
+
[bits 32]
int_syscall_handler:
@@ -18,6 +20,9 @@ int_syscall_handler:
cmp eax, 20
je call_example_syscall_2
+ cmp eax, 61
+ je call_outbyte
+
done:
pop ebx
@@ -39,3 +44,8 @@ call_example_syscall:
call_example_syscall_2
call example_syscall_2
jmp done
+
+call_outbyte
+ call syscall_outbyte
+ jmp done
+
diff --git a/kernel/config.h b/kernel/config.h
index 02ba57c..3870673 100644
--- a/kernel/config.h
+++ b/kernel/config.h
@@ -1,2 +1,3 @@
//#define FOOLOS_COMPILE_FLOPPY
+#define FOOLOS_CONSOLE_AUTOBREAK //add newline automatically at end of line
diff --git a/kernel/interrupts.c b/kernel/interrupts.c
index 56fa09f..80375c2 100644
--- a/kernel/interrupts.c
+++ b/kernel/interrupts.c
@@ -83,21 +83,6 @@ void int_irq16(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Coprocessor error");
void int_irq17(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Alignment Check"); X86_IRQ_END }
void int_irq18(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Machine Check"); X86_IRQ_END }
-//
-int example_syscall(int x,int y)
-{
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"example syscall called with %d + %d",x,y);
- return x+y;
-
-}
-
-int example_syscall_2(int x,int y)
-{
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"example syscall 2 called with %d - %d",x,y);
- return x-y;
-}
-
-//
//set a handler for a specific interrupt
void int_install_ir(int irq, uint16_t flags, uint16_t sel, void *addr)
diff --git a/kernel/kernel.c b/kernel/kernel.c
index 811f4c1..3372b75 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -18,9 +18,6 @@ uint32_t c1,c2,c3;
volatile uint8_t proc;
uint32_t cpu_counter[SMP_MAX_PROC];
-volatile int16_t mouse_x;
-volatile int16_t mouse_y;
-
void kernel_ap()
{
proc++;
@@ -35,12 +32,16 @@ void kernel_ap()
}
}
+
+volatile int16_t mouse_x;
+volatile int16_t mouse_y;
+
+
//
// KERNEL MAIN
// this is the very heart of our operating system!
//
-
void kernel_main(uint32_t initial_stack, int mp)
{
@@ -60,7 +61,7 @@ void kernel_main(uint32_t initial_stack, int mp)
proc=c1=c2=c3=0;
for(int i=0;i<SMP_MAX_PROC;i++)cpu_counter[i]=0;
-
+
/////////////////// BULLSHIT ABOVE THIS LINE: TODO: CLEANUP
//
@@ -149,8 +150,8 @@ void kernel_main(uint32_t initial_stack, int mp)
//
// Start the other Processors (also before paging for some reason!)
//
- smp_log_procdata(&procdata);
- smp_start_aps(&procdata,0x80000); // starts at 0x80000
+ //smp_log_procdata(&procdata);
+ //smp_start_aps(&procdata,0x80000); // starts at 0x80000
// but it will be copied over mbr
@@ -192,7 +193,7 @@ void kernel_main(uint32_t initial_stack, int mp)
// For now this starts three "tasks" which are scheduled
// round robin style.
//
- task_init();
+ //task_init();
//
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
new file mode 100644
index 0000000..bf875fd
--- /dev/null
+++ b/kernel/syscalls.c
@@ -0,0 +1,23 @@
+#define FOOLOS_MODULE_NAME "syscalls"
+#include "lib/logger/log.h"
+
+//
+void syscall_outbyte(char c)
+{
+ PutConsoleChar(c,0b1111111111000000);
+}
+
+int example_syscall(int x,int y)
+{
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"example syscall called with %d + %d",x,y);
+ return x+y;
+
+}
+
+int example_syscall_2(int x,int y)
+{
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"example syscall 2 called with %d - %d",x,y);
+ return x-y;
+}
+
+//
diff --git a/kernel/vesa.c b/kernel/vesa.c
index 0619f1a..7001e02 100644
--- a/kernel/vesa.c
+++ b/kernel/vesa.c
@@ -1,6 +1,7 @@
//http://wiki.osdev.org/GUI
#include <stdarg.h>
#include "kernel.h"
+#include "config.h"
#include "lib/logger/log.h" // logger facilities
#include "lib/int/stdint.h"
@@ -80,7 +81,7 @@ uint32_t vesa_init(vbeinfo *info,vbemodeinfo *mode,foolfont *rawfont)
console_cols=mode->Xres/col_width;
// vesa info
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"setup complete. vbe version: 0x%x / video mode ptr: 0x%x 0x%x",
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"vbe version: 0x%x / video mode ptr: 0x%x 0x%x",
info->VbeVersion, info->VideoModePtr[1], info->VideoModePtr[0]);
// vesa info on selected mode:
@@ -89,8 +90,10 @@ uint32_t vesa_init(vbeinfo *info,vbemodeinfo *mode,foolfont *rawfont)
mode->green_position,mode->green_mask,
mode->blue_position,mode->blue_mask);
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"res: %d * %d / banks: %d / attr: 0x%x / bpp: %d / physbase: 0x%x",
- mode->Xres, mode->Yres, mode->banks, mode->attributes, mode->bpp,mode->physbase);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"res: %d * %d / banks: %d / attr: 0x%x",
+ mode->Xres, mode->Yres, mode->banks, mode->attributes);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"bpp: %d / physbase: 0x%x",
+ mode->bpp,mode->physbase);
// vesa modes
// todo: take segment from vbeinfo!
#ifdef FOOLSOS_SHOW_VESAMODES
@@ -167,15 +170,23 @@ void PutString(char *str, int x,int y, int color, va_list va)
}
+void PutConsoleChar(char c, int color)
+{
+ PutFont(c, console_x*10,console_y*12, color);
+ console_x++;
+
+ #ifdef FOOLOS_CONSOLE_AUTOBREAK
+ if(console_x>console_cols)PutConsoleNL();
+ #endif
+}
+
void PutConsole(char *str, int color)
{
while((*str)!=0)
{
- PutFont(*str, console_x*10,console_y*12, color);
+ PutConsoleChar(*str,color);
str++;
- console_x++;
- if(console_x>console_cols);//PutConsoleNL();
}
}
diff --git a/userspace/Makefile b/userspace/Makefile
new file mode 100644
index 0000000..2a286da
--- /dev/null
+++ b/userspace/Makefile
@@ -0,0 +1,14 @@
+#i686-elf-gcc test.c -L/home/miguel/temp/fool-os-stuff/newlib-build-clean/i686-elf/newlib/ -I/home/miguel/temp/fool-os-stuff/newlib-2.1.0/newlib/libc/include/ -L/home/miguel/temp/fool-os-stuff/newlib-build-clean/i686-elf/libgloss/libnosys/
+
+CC=i686-elf-gcc
+LD=i686-elf-ld
+
+CFLAGS=-I/home/miguel/temp/fool-os-stuff/newlib-2.1.0/newlib/libc/include
+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: test.o crt0.o
+ ${CC} -T linker.ld ${LDFLAGS} test.o -Wl,--oformat,binary -o userprog
+clean:
+ -rm *.o *.out userprog
diff --git a/userspace/crt0.S b/userspace/crt0.S
new file mode 100644
index 0000000..9f7dab1
--- /dev/null
+++ b/userspace/crt0.S
@@ -0,0 +1,9 @@
+.global _start
+.extern main
+.extern exit
+_start:
+call main
+call _exit
+.wait:
+ hlt
+jmp .wait
diff --git a/userspace/linker.ld b/userspace/linker.ld
new file mode 100644
index 0000000..bfaae93
--- /dev/null
+++ b/userspace/linker.ld
@@ -0,0 +1,4 @@
+SECTIONS
+{
+ . = 0x80800;
+}
diff --git a/userspace/test.c b/userspace/test.c
new file mode 100644
index 0000000..bdc6da0
--- /dev/null
+++ b/userspace/test.c
@@ -0,0 +1,104 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+
+//printf needs following syscalls: sbrk write close fstat isatty lseek read
+//
+
+#include <sys/stat.h>
+
+int close(int file)
+{
+ return -1;
+}
+
+int fstat(int file, struct stat *st)
+{
+ st->st_mode = S_IFCHR;
+ return 0;
+}
+
+int isatty(int file) {
+ return 1;
+}
+
+int lseek(int file, int ptr, int dir) {
+ return 0;
+}
+
+int read(int file, char *ptr, int len) {
+ return 0;
+}
+
+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)
+
+ asm("mov %0,%%edx"::"m"(byt));
+ //asm("mov $88,%edx");
+
+ asm("int $0x80"); // actual syscall ! interrupt
+ asm("mov %%ebx, %0": "=b" (ebx));
+ asm("popa");
+ //
+
+ }
+ return len;
+}
+
+caddr_t sbrk(int incr)
+{
+
+// extern char _end; /* Defined by the linker */
+ char _end;
+ static char *heap_end;
+ char *prev_heap_end;
+
+ if (heap_end == 0) {
+ heap_end = &_end;
+ }
+ prev_heap_end = heap_end;
+ /*
+ if (heap_end + incr > stack_ptr) {
+ write (1, "Heap and stack collision\n", 25);
+ abort ();
+ }
+ */
+
+ heap_end += incr;
+ return (caddr_t) prev_heap_end;
+}
+
+//
+
+int main()
+{
+ int x=atoi("33");
+ int *mem=0x80000;
+ int *mem2=0x80010;
+
+ int y=0;
+ *mem=x;
+
+ while(1)
+ {
+ printf("test printf");
+// write(1,"dupa",4);
+// y=example_call();
+ y++;
+ *mem2=y;
+ }
+
+
+}