summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile9
-rw-r--r--README.md1
-rw-r--r--asm/asm.h5
-rw-r--r--asm/int_clock_handler.asm11
-rw-r--r--asm/int_default_handler.asm9
-rw-r--r--asm/int_irq0.asm9
-rw-r--r--asm/int_kb_handler.asm28
-rw-r--r--fs/ext2.c4
-rw-r--r--fs/ext2.h3
-rw-r--r--kernel/console.c4
-rw-r--r--kernel/console.h2
-rw-r--r--kernel/interrupts.c67
-rw-r--r--kernel/interrupts.h2
-rw-r--r--kernel/kernel.c28
-rw-r--r--kernel/keyboard.c40
-rw-r--r--kernel/mem.c53
-rw-r--r--kernel/mem.h2
-rw-r--r--kernel/spinlock.c6
-rw-r--r--kernel/spinlock.h4
-rw-r--r--kernel/syscalls.c40
-rw-r--r--kernel/syscalls.h2
-rw-r--r--kernel/task.c50
-rw-r--r--kernel/timer.c2
-rw-r--r--kernel/vmem.c13
-rw-r--r--kernel/x86.c11
-rw-r--r--kernel/x86.h8
-rw-r--r--lib/bool/bool.h2
-rw-r--r--lib/buffer/ringbuffer.c43
-rw-r--r--lib/buffer/ringbuffer.h4
-rw-r--r--lib/int/stdint.h2
-rw-r--r--lib/string/string.c2
-rw-r--r--userspace/Makefile1
-rw-r--r--userspace/add.c14
-rw-r--r--userspace/checker.c1
-rw-r--r--userspace/foolshell.c19
-rw-r--r--userspace/simple.c2
-rw-r--r--video/console.c8
-rw-r--r--video/console.h2
38 files changed, 312 insertions, 201 deletions
diff --git a/Makefile b/Makefile
index 57d01fa..1953ff3 100644
--- a/Makefile
+++ b/Makefile
@@ -28,12 +28,13 @@ CC=i686-foolos-gcc
############ compiler flags ############
CFLAGS=
-CFLAGS+=-fstack-protector-all
-CFLAGS+=-w
+#CFLAGS+=-fstack-protector-all
+#CFLAGS+=-w
CFLAGS+=-ffreestanding
CFLATS+=-Wall
CFLAGS+=-Wextra
-#CFLAGS+=-O2
+#CFLAGS+=-O0
+CFLAGS+=-O3
#CFLAGS+=-nostdlib
CFLAGS+=-std=gnu11
CFLAGS+=-I.
@@ -149,7 +150,7 @@ run-bochs: all
run-qemu: all
qemu-system-i386 $(FOOLOS)
-run: run-qemu
+run: run-bochs
newrun: clean run
diff --git a/README.md b/README.md
index 1b55462..e475e17 100644
--- a/README.md
+++ b/README.md
@@ -98,7 +98,6 @@ Issues
* implement posix(?) getdents instead of our own readdir.
* Turning on some gcc optimizations breaks the kernel
* Assumed support for VESA mode 0x114 with linear addressing.
-* Protect ringbuffer in syscall? disable interrupts on local cpu before spinlocking
Organization
diff --git a/asm/asm.h b/asm/asm.h
index 6be89ca..c9a1fa3 100644
--- a/asm/asm.h
+++ b/asm/asm.h
@@ -1 +1,6 @@
void pic_setup();
+void int_kb_handler();
+void int_default_handler();
+void int_clock_handler();
+void int_syscall_handler();
+void int_irq0();
diff --git a/asm/int_clock_handler.asm b/asm/int_clock_handler.asm
index 03685fd..c6c91fc 100644
--- a/asm/int_clock_handler.asm
+++ b/asm/int_clock_handler.asm
@@ -19,13 +19,12 @@ int_clock_handler:
; mov byte [CLOCK_COUNTER], 0x00
- pusha ;Push all standard registers
-
+pusha ;Push all standard registers
push esp ;Push pointer to all the stuff we just pushed
call task_switch_next ;Call C code
- pop ebx
+ ;pop ebx
;compare:
;cmp eax,ebx
@@ -34,12 +33,12 @@ int_clock_handler:
mov esp, eax ;Replace the stack with what the C code gave us
- popa ;Put the standard registers back
; skip_clock:
-
mov al, 0x20 ;Port number AND command number to Acknowledge IRQ
- out 0x20, al ;Acknowledge IRQ, so we keep getting interrupts
+ out 0x20, al ;Acknowledge IRQ, so we keep getting interrupts
+
+ popa ;Put the standard registers back
;We didn't push an error code or IRQ number, so we don't have to edit esp now
sti
diff --git a/asm/int_default_handler.asm b/asm/int_default_handler.asm
index 4515482..b86eeae 100644
--- a/asm/int_default_handler.asm
+++ b/asm/int_default_handler.asm
@@ -5,12 +5,17 @@ global int_default_handler
[bits 32]
int_default_handler:
+
cli
-
+ pusha
+
call int_default
mov al, 0x20 ;Port number AND command number to Acknowledge IRQ
- out 0x20, al ;Acknowledge IRQ, so we keep getting interrupts
+ out 0x20, al ;Acknowledge IRQ, so we keep getting interrupts
+ popa
sti
+
+
iret ;Interrupt-Return
diff --git a/asm/int_irq0.asm b/asm/int_irq0.asm
new file mode 100644
index 0000000..a713774
--- /dev/null
+++ b/asm/int_irq0.asm
@@ -0,0 +1,9 @@
+global int_irq0
+[extern exception_handle]
+
+[bits 32]
+int_irq0:
+
+ cli
+ call exception_handle ;this will never return due to panic!
+ jmp $
diff --git a/asm/int_kb_handler.asm b/asm/int_kb_handler.asm
new file mode 100644
index 0000000..f2e33bf
--- /dev/null
+++ b/asm/int_kb_handler.asm
@@ -0,0 +1,28 @@
+global int_kb_handler
+[extern keyboard_handle]
+[extern int_default]
+
+[bits 32]
+
+int_kb_handler:
+cli
+
+pusha
+
+ mov eax,0x0
+ in al,0x60
+
+ push eax
+ call keyboard_handle
+
+ pop eax
+; call int_default
+
+ mov al, 0x20 ;Port number AND command number to Acknowledge IRQ
+ out 0x20, al ;Acknowledge IRQ, so we keep getting interrupts
+
+popa
+
+sti
+
+iretd ;Interrupt-Return
diff --git a/fs/ext2.c b/fs/ext2.c
index 55322dd..a530ce6 100644
--- a/fs/ext2.c
+++ b/fs/ext2.c
@@ -4,10 +4,12 @@
#define FOOLOS_MODULE_NAME "ext2"
#include <stdbool.h>
+#include <stdint.h>
-#include "lib/int/stdint.h"
+#include "lib/string/string.h"
#include "lib/logger/log.h"
#include "fs.h"
+#include "ext2.h"
typedef struct ext2_superblock_struct
{
diff --git a/fs/ext2.h b/fs/ext2.h
index a5f46b3..1307347 100644
--- a/fs/ext2.h
+++ b/fs/ext2.h
@@ -1,5 +1,6 @@
-#include "lib/int/stdint.h"
+#include <stdint.h>
int ext2_check(uint8_t *ram);
int ext2_inode_content(char *ram,int inode_nr,uint8_t *ramdest,int max);
int ext2_read_dir(uint8_t *ram, int inode_nr,fs_dirent *dirs,int max);
+int ext2_filename_to_inode(uint8_t *ram, char *path);
diff --git a/kernel/console.c b/kernel/console.c
index 80e2157..564806f 100644
--- a/kernel/console.c
+++ b/kernel/console.c
@@ -10,7 +10,9 @@
#include "video/console.h"
void console_init(){scr_clear();}
-void console_put_char(char c){scr_put_char(c,SCR_RED);}
+void console_put_char(char c){scr_put_char(c,SCR_LGREEN);}
+void console_put_char_red(char c){scr_put_char(c,SCR_WHITE);}
+void console_del_char(){scr_backspace();}
void console_put_str(char *s){scr_put_string(s);}
#else
diff --git a/kernel/console.h b/kernel/console.h
index 93008ab..a344c90 100644
--- a/kernel/console.h
+++ b/kernel/console.h
@@ -4,7 +4,9 @@
void console_init();
void console_put_char(char);
+void console_put_char_red(char);
void console_put_str(char *);
+void console_del_char();
#endif
diff --git a/kernel/interrupts.c b/kernel/interrupts.c
index ac200e5..f82c59c 100644
--- a/kernel/interrupts.c
+++ b/kernel/interrupts.c
@@ -2,15 +2,12 @@
#include "lib/logger/log.h" // logger facilities
+#include "asm/asm.h"
#include "interrupts.h"
+#include "console.h"
#include "x86.h"
-
-void int_clock_handler();
-void int_kb_handler();
-void int_syscall_handler();
void int_install_ir(int irq, uint16_t flags, uint16_t sel, void *addr);
-void int_default_handler();
//void mouse_handler();
@@ -34,11 +31,16 @@ static struct idt_desc
} idtd;
+void exception_handle()
+{
+ panic(FOOLOS_MODULE_NAME,"exception interrupt");
+}
void int_default()
{
-
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"default handler");
}
+/*
void show_error(uint32_t err)
{
@@ -48,7 +50,7 @@ void show_error(uint32_t err)
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Selector: %x",err&0b1111111111111000);
}
-void int_irq0(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Divide by 0"); X86_IRQ_END }
+//void int_irq0(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Divide by 0"); X86_IRQ_END }
void int_irq1(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Single step (debugger)"); X86_IRQ_END }
void int_irq2(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Non Maskable Interrupt"); X86_IRQ_END }
void int_irq3(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Breakpoint (debugger)"); X86_IRQ_END }
@@ -81,7 +83,7 @@ void int_irq15(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Unassigned"); X86_I
void int_irq16(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Coprocessor error"); X86_IRQ_END }
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 }
-
+*/
//set a handler for a specific interrupt
void int_install_ir(int irq, uint16_t flags, uint16_t sel, void *addr)
@@ -100,6 +102,11 @@ void int_install_ir(int irq, uint16_t flags, uint16_t sel, void *addr)
// set default handler for all interrupts for a start
void int_init(uint16_t sel)
{
+ //
+ // Setup PIC
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"setting up PIC",&idt,&idtd);
+ pic_setup();
+
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"initializing. IDT: 0x%08x, IDTD: 0x%08X",&idt,&idtd);
int i;
@@ -109,25 +116,28 @@ void int_init(uint16_t sel)
}
// exceptions
+
int_install_ir(0, 0b10001110, 0x08,&int_irq0);
- int_install_ir(1, 0b10001110, 0x08,&int_irq1);
- int_install_ir(2, 0b10001110, 0x08,&int_irq2);
- int_install_ir(3, 0b10001110, 0x08,&int_irq3);
- int_install_ir(4, 0b10001110, 0x08,&int_irq4);
- int_install_ir(5, 0b10001110, 0x08,&int_irq5);
- int_install_ir(6, 0b10001110, 0x08,&int_irq6);
- int_install_ir(7, 0b10001110, 0x08,&int_irq7);
- int_install_ir(8, 0b10001110, 0x08,&int_irq8);
- int_install_ir(9, 0b10001110, 0x08,&int_irq9);
- int_install_ir(10, 0b10001110, 0x08,&int_irq10);
- int_install_ir(11, 0b10001110, 0x08,&int_irq11);
- int_install_ir(12, 0b10001110, 0x08,&int_irq12);
- int_install_ir(13, 0b10001110, 0x08,&int_irq13);
- int_install_ir(14, 0b10001110, 0x08,&int_irq14);
- int_install_ir(15, 0b10001110, 0x08,&int_irq15);
- int_install_ir(16, 0b10001110, 0x08,&int_irq16);
- int_install_ir(17, 0b10001110, 0x08,&int_irq17);
- int_install_ir(18, 0b10001110, 0x08,&int_irq18);
+ int_install_ir(1, 0b10001110, 0x08,&int_irq0);
+ int_install_ir(2, 0b10001110, 0x08,&int_irq0);
+ int_install_ir(3, 0b10001110, 0x08,&int_irq0);
+ int_install_ir(4, 0b10001110, 0x08,&int_irq0);
+ int_install_ir(5, 0b10001110, 0x08,&int_irq0);
+ int_install_ir(6, 0b10001110, 0x08,&int_irq0);
+ int_install_ir(7, 0b10001110, 0x08,&int_irq0);
+ int_install_ir(8, 0b10001110, 0x08,&int_irq0);
+ int_install_ir(9, 0b10001110, 0x08,&int_irq0);
+ int_install_ir(10, 0b10001110, 0x08,&int_irq0);
+ int_install_ir(11, 0b10001110, 0x08,&int_irq0);
+ int_install_ir(12, 0b10001110, 0x08,&int_irq0);
+ int_install_ir(13, 0b10001110, 0x08,&int_irq0);
+ int_install_ir(14, 0b10001110, 0x08,&int_irq0);
+ int_install_ir(15, 0b10001110, 0x08,&int_irq0);
+ int_install_ir(16, 0b10001110, 0x08,&int_irq0);
+ int_install_ir(17, 0b10001110, 0x08,&int_irq0);
+ int_install_ir(18, 0b10001110, 0x08,&int_irq0);
+
+
// setup some custom interrupts
// remember that we shifted all interrupts with the pic by 32
@@ -138,11 +148,6 @@ void int_init(uint16_t sel)
// install keyboard interrupt handler (irq 1 => 33)
int_install_ir(33, 0b10001110, 0x08,&int_kb_handler);
- #ifdef FOOLOS_COMPILE_FLOPPY
- // install floppy interrupt handler (irq 6 => 38)
- int_install_ir(38, 0b10001110, 0x08,&int_floppy_handler);
- #endif
-
//mouse
// int_install_ir(44, 0b10001110, 0x08,&mouse_handler);
diff --git a/kernel/interrupts.h b/kernel/interrupts.h
index f708210..bd110d4 100644
--- a/kernel/interrupts.h
+++ b/kernel/interrupts.h
@@ -1,7 +1,7 @@
#ifndef INTERRUPTS_H
#define INTERRUPTS_H
-#include "lib/int/stdint.h"
+#include <stdint.h>
#define INT_MAX 255 // size of our interrupts table
diff --git a/kernel/kernel.c b/kernel/kernel.c
index ecb42eb..773ebad 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -7,27 +7,24 @@
#include <stdint.h>
#include "config.h"
-#include "asm/asm.h" // TODO: ?!?!
#include "lib/logger/log.h"
-#include "lib/buffer/ringbuffer.h"
#include "timer.h"
-#include "spinlock.h"
-#include "syscalls.h"
#include "mem.h"
#include "vmem.h"
#include "interrupts.h"
-#include "keyboard.h"
+
+#include "syscalls.h" // for syscall_execve
+
+
#include "console.h"
-#include "fs/fs.h"
-#include "fs/ext2.h"
+// for built-in shell
+#include "lib/buffer/ringbuffer.h"
#include "task.h"
-#include <stdint.h>
-#include <stdlib.h>
// CODE FOR Stack Smashing Protector, TODO: MOVE / and do not duplicate
// with sys.c
@@ -70,7 +67,7 @@ void kernel_main(uint32_t initial_stack, int mp)
//
// Activate Virtual Memory (paging)
//
- vmem_init();
+ //vmem_init();
//
// init output to screen
@@ -81,16 +78,12 @@ void kernel_main(uint32_t initial_stack, int mp)
// log buffered messages to console
log_log();
-
- //
- // Setup PIC (interrupts)
- // TODO: log!
- pic_setup();
-
//
// Setup Interrupts (code segment: 0x08)
//
int_init(0x08);
+
+
//
@@ -108,6 +101,9 @@ void kernel_main(uint32_t initial_stack, int mp)
*/
+ // task_init();
+ // while(1);
+
// load and run foolshell
// we will come back into the kernel only on interrupts...
asm("mov $0x05bff,%esp"); // set stack pointer
diff --git a/kernel/keyboard.c b/kernel/keyboard.c
index 32f28f0..0274748 100644
--- a/kernel/keyboard.c
+++ b/kernel/keyboard.c
@@ -1,16 +1,15 @@
#define FOOLOS_MODULE_NAME "keyboard"
-#include "kernel.h"
-#include "console.h"
#include "x86.h"
+#include "console.h"
#include "lib/buffer/ringbuffer.h"
#include "lib/logger/log.h" // logger facilities
-#include "lib/bool/bool.h"
/// keyboard driver ////
// http://www.computer-engineering.org/ps2keyboard/scancodes1.html
+static bool ctrl_l=false;
static bool shift_l=false;
static bool shift_r=false;
static bool capslock=false;
@@ -108,12 +107,18 @@ void keyboard_handle(uint8_t in)
uint8_t break_caps_lock=0xba;
uint8_t break_slash=0xb5;
+ uint8_t make_ctrl_l=0x1d;
+ uint8_t break_ctrl_l=0x9d;
+
if(make_key_shift_l==in)shift_l=true;
if(break_key_shift_l==in)shift_l=false;;
if(make_key_shift_r==in)shift_r=true;
if(break_key_shift_r==in)shift_r=false;;
+ if(make_ctrl_l==in)ctrl_l=true;
+ if(break_ctrl_l==in)ctrl_l=false;
+
if(break_caps_lock==in)capslock=!capslock;
@@ -121,12 +126,20 @@ void keyboard_handle(uint8_t in)
bool match=false;
// optimize this!
+ if(ctrl_l)
+ {
+ if(in==0xa0)
+ {
+ ascii=4; //end of transmission ctrl-d
+ match=true;
+ }
+ }
if(break_slash==in)
{
ascii='/';
match=true;
}
- if(break_key_space==in)
+ else if(break_key_space==in)
{
ascii=' ';
match=true;
@@ -163,7 +176,7 @@ void keyboard_handle(uint8_t in)
}
else if(break_key_backspace==in)
{
- ascii='x';
+ ascii=0x08;
match=true;
}
@@ -175,6 +188,7 @@ void keyboard_handle(uint8_t in)
else for(int i=0;i<26;i++)
{
+ if(match)break;
if(break_alpha[i]==in)
{
ascii=('a'+i);
@@ -201,8 +215,6 @@ void keyboard_handle(uint8_t in)
if(match)
{
-// PutConsoleChar(ascii,0b1111100000011111);
- console_put_char(ascii);
if(!ringbuffer_put(ascii))
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"ringbuffer full..");
@@ -210,19 +222,5 @@ void keyboard_handle(uint8_t in)
}
-void int_kb_handler()
-{
-
- X86_IRQ_BEGIN
-
- static uint8_t kb_in;
- __asm__("in $0x60, %al");
- __asm__("mov %%al, %0"::"m" (kb_in));
- //log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"scancode 0x%x",kb_in);
- keyboard_handle(kb_in);
-
- X86_IRQ_END
-
-}
diff --git a/kernel/mem.c b/kernel/mem.c
index cf0c673..ec99732 100644
--- a/kernel/mem.c
+++ b/kernel/mem.c
@@ -28,6 +28,7 @@ char *memmap_type_to_string[]=
"ACPI NVS",
"Bad Memory"
};
+
// bit funcs!
void mmap_set(int bit)
{
@@ -126,6 +127,7 @@ void* pmmngr_alloc_block ()
mem_free_blocks--;
uint32_t addr = frame * PMMNGR_BLOCK_SIZE;
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"alloc block (%d) 0x%08X)",frame,addr);
return (void*)addr;
}
@@ -164,6 +166,8 @@ void pmmngr_free_block (void* p)
mmap_unset (frame);
mem_free_blocks++;
}
+
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"free block (%d) 0x%08X)",frame,addr);
}
@@ -172,59 +176,46 @@ void mem_init(uint16_t *memmap,uint16_t entries)
// log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"the memory map contains %d entries.",entries);
// count available mem
- uint32_t total_mem=0, highest_end=0, high_end_low=0,last_end=0;
+ uint32_t total_mem=0, highest_end;
- // preserve pointer
- uint16_t save=memmap;
+ //save pointer to memmap
+ uint16_t *save=memmap;
//print memory map and calc blocks.
for(int i=0;i<entries;i++)
{
+ int mem=(memmap[4]+(memmap[5]<<16));
uint32_t low_end=(((uint32_t)memmap[1])<<16)+memmap[0];
- uint32_t high_end=(((uint32_t)memmap[1])<<16)+memmap[0]-1
- +(((uint32_t)memmap[5])<<16)+memmap[4];
+ uint32_t high_end=low_end+mem-1;
+
#ifdef MEM_PRINT_MEMORYMAP
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"range: 0x%08x - 0x%08x (%s)",
- low_end,high_end,memmap_type_to_string[memmap[8]-1]);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"range: 0x%08x - 0x%08x (%s %d KB)",
+ low_end,high_end,memmap_type_to_string[memmap[8]-1],mem/1024);
#endif
//reclaimable OR usable
if(memmap[8]==1||memmap[8]==3)
{
- total_mem+=memmap[4]+(memmap[5]<<16);
+ total_mem+=mem;
+ highest_end=high_end;
- if(high_end>highest_end)
- {
- highest_end=high_end;
- high_end_low=last_end;
- }
- }
- else
- {
- last_end=high_end+1;
}
- memmap+=12;
-
+ memmap+=12; // next entry;
}
- // restore pointer
- memmap=save;
int blocks=highest_end/4096+1;
mem_array_size=blocks/32+1;
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Highest end area: 0x%08X - 0x%08X",high_end_low,highest_end);
- if(highest_end-high_end_low<mem_array_size*4)
- {
- panic(FOOLOS_MODULE_NAME,"not enough space at high end :( sorry.");
- }
-
- _mmngr_memory_map=highest_end-mem_array_size*4;
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Initializing bitmap for 0x%X blocks at 0x%08X",blocks,_mmngr_memory_map);
+ _mmngr_memory_map=0x500000;
+
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Init bitmap for 0x%X blocks (size: %d bytes)",blocks,mem_array_size*4);
- pmmngr_init ();
+ pmmngr_init (); //clear memmap
+ //restore pointer to memmap
+ memmap=save;
for(int i=0;i<entries;i++)
{
@@ -240,7 +231,7 @@ void mem_init(uint16_t *memmap,uint16_t entries)
pmmngr_deinit_region(0x0,0x500000);
// and here is the memory map that we JUST created!
- pmmngr_deinit_region(_mmngr_memory_map,mem_array_size*4);
+ pmmngr_deinit_region(0x500000,mem_array_size*4+PMMNGR_BLOCK_SIZE);
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Usable Mem: %d (0x%X) bytes. (~%d MB)",total_mem,total_mem,total_mem/1024/1024);
diff --git a/kernel/mem.h b/kernel/mem.h
index d574fec..efc3ebe 100644
--- a/kernel/mem.h
+++ b/kernel/mem.h
@@ -1,5 +1,5 @@
-#include "lib/int/stdint.h"
+#include <stdint.h>
void* pmmngr_alloc_block ();
//void* pmmngr_alloc_blocks (uint32_t size);
void pmmngr_free_block (void* p);
diff --git a/kernel/spinlock.c b/kernel/spinlock.c
index 2c6d161..945d8ee 100644
--- a/kernel/spinlock.c
+++ b/kernel/spinlock.c
@@ -2,12 +2,12 @@
#include "lib/logger/log.h"
#include "spinlock.h"
+#include "x86.h"
// https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html
#define NUMBER_SPINLOCKS 16
-
-spinlock spinlocks[NUMBER_SPINLOCKS];
+static spinlock spinlocks[NUMBER_SPINLOCKS];
void check_spinlocks()
{
@@ -16,7 +16,6 @@ void check_spinlocks()
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%d",spinlocks[i]);
}
-
void lock_spin(spinlock i)
{
@@ -31,7 +30,6 @@ void lock_release(spinlock i)
// log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"unlocking %d",i);
spinlock *addr=spinlocks+i;
-
asm("movb $0,%0"::"m"(*addr));
}
diff --git a/kernel/spinlock.h b/kernel/spinlock.h
index 43cd82f..40d9194 100644
--- a/kernel/spinlock.h
+++ b/kernel/spinlock.h
@@ -3,9 +3,9 @@
#include <stdint.h>
-typedef uint8_t spinlock;
+typedef volatile uint8_t spinlock;
-volatile void lock_spin(spinlock);
+void lock_spin(spinlock);
void lock_release(spinlock);
#endif
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index e4d31b5..5939cff 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -114,29 +114,55 @@ int syscall_write(int file, char *buf, int len)
int syscall_read(int file, char *buf, int len)
{
+ static bool eof=false;
#ifdef LOG_SYSCALLS
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"read(file=%d, buf=0x%08X, len=%d)", file,buf,len);
#endif
- if(file!=0) panic(FOOLOS_MODULE_NAME,"unhandled syscall");
-
// stdin TODO: other descroptiors!
+ if(file!=0) panic(FOOLOS_MODULE_NAME,"unhandled syscall");
{
+ if(eof)
+ {
+ eof=false;
+ return 0;
+ }
char c;
+ int l=0;
while(1)
{
- asm("cli");
bool ret=ringbuffer_get(&c);
- asm("sti");
if(ret)
{
- *buf=c;
- if(c=='X')return 0;
- return 1;
+ if(c==0x08)
+ {
+ if(l>0)
+ {
+ console_del_char();
+ buf--;
+ l--;
+ }
+ }
+ else{
+
+ *buf=c;
+ buf++;
+ l++;
+ if(c!=0x04)console_put_char_red(c);
+ if(c=='\n')return l;
+ if(c==0x04)
+ {
+ l--;
+ buf--;
+ eof=true;
+ return l;
+ }
+ }
+
}
}
diff --git a/kernel/syscalls.h b/kernel/syscalls.h
index 432bd2c..fc5f5bf 100644
--- a/kernel/syscalls.h
+++ b/kernel/syscalls.h
@@ -31,6 +31,7 @@
#define SYSCALL_WAIT 77
#define SYSCALL_GETPID 78
+int syscall_execve(char *name, char **argv, char **env);
/*
int syscall_readdir(const char *name,struct fs_dirent *dirs,int max);
@@ -38,7 +39,6 @@ int syscall_exit(int ret, int none1, int none2);
int syscall_open(char *name, int flags, int len);
int syscall_write(int file, char *buf, int len);
int syscall_read(int file, char *buf, int len);
-int syscall_execve(char *name, char **argv, char **env);
int syscall_close(int file,int none1,int none2);
int syscall_fstat(int file, struct stat *st,int none);
int syscall_isatty(int file,int none1,int none2);
diff --git a/kernel/task.c b/kernel/task.c
index df48afb..7e39a30 100644
--- a/kernel/task.c
+++ b/kernel/task.c
@@ -3,9 +3,11 @@
//
#include "kernel.h"
#include "lib/logger/log.h" // logger facilities
-#include "lib/int/stdint.h"
+#include "lib/buffer/ringbuffer.h"
#include "mem.h"
#include "timer.h"
+#include "console.h"
+#include "x86.h"
#include "syscalls.h"
#include "fs/fs.h"
@@ -13,31 +15,29 @@
#define FOOLOS_MODULE_NAME "task"
int started;
-
-static uint32_t c1,c2,c3;
+static volatile int c1,c2,c3;
void task_test1()
{
- //ext2_check(EXT2_RAM_ADDRESS);
- //syscall_execve(15,0,0);
-// syscall_execve(18,0,0);
-
+ // simple built-in shell
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"spawning build-in shell");
+
while(1)
{
+
+ char c;
+ if(ringbuffer_get(&c))
+ {
+ console_put_char(c);
+ }
+ }
- int cc2,cc3;
-
- asm("cli");
-
- cc2=c2;
- cc3=c3;
-
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"tasks progress: %d %d", cc2, cc3);
- asm("sti");
-
- c1++;
+ /*
+ c1++;
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"task 1 progress: %d", c1);
+ sleep(2);
+ */
- }
}
@@ -47,6 +47,8 @@ void task_test2()
while(1)
{
c2++;
+ //log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"task 2 progress: %d", c2);
+// sleep(2);
}
@@ -57,6 +59,8 @@ void task_test3()
while(1)
{
c3++;
+// log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"task 3 progress: %d", c3);
+// sleep(2);
}
}
@@ -112,22 +116,26 @@ void task_create(int pid,void(*thread)())
uint32_t task_switch_next(uint32_t oldesp)
{
- timer_tick();
+ //console_put_char('.');
+ timer_tick();
if(started!=0xabcde) return oldesp;
if(CurrentTask!=-1)Threads[CurrentTask].esp0=oldesp;
CurrentTask++;
if(CurrentTask>2)CurrentTask=0;
+ /*
log(
FOOLOS_MODULE_NAME,
- FOOLOS_LOG_FINE,
+ FOOLOS_LOG_INFO,
"oldesp: 0x%08X saved / next task: %d (esp: 0x%08X) ",
oldesp,
CurrentTask,
Threads[CurrentTask].esp0);
// return oldesp;
+// */
+
return Threads[CurrentTask].esp0; //Return new stack pointer to ASM
}
diff --git a/kernel/timer.c b/kernel/timer.c
index 676be48..5adc986 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -36,7 +36,7 @@
#include "lib/logger/log.h" // logger facilities
-static uint64_t task_system_clock=0;
+static volatile uint64_t task_system_clock=0;
void timer_init()
{
diff --git a/kernel/vmem.c b/kernel/vmem.c
index 502b700..c22f764 100644
--- a/kernel/vmem.c
+++ b/kernel/vmem.c
@@ -223,7 +223,7 @@ void vmem_init()
uint32_t virt_addr=0;
// first pages are identity mapped
- for(int j=0;j<20;j++)
+ for(int j=0;j<3;j++)
{
ptable* table = (ptable*) pmmngr_alloc_block ();
@@ -271,3 +271,14 @@ void vmem_init()
}
+void set_vmem1()
+{
+
+}
+
+void set_vmem2()
+{
+
+}
+
+
diff --git a/kernel/x86.c b/kernel/x86.c
index 725c50d..81b0e20 100644
--- a/kernel/x86.c
+++ b/kernel/x86.c
@@ -9,18 +9,17 @@
// suffix (b, w, l, q for byte, word, dword, and qword).
//
+
void sleep(int i)
{
- volatile uint64_t clock=timer_get_ticks();
+ uint64_t clock=timer_get_ticks();
+
-// while(clock+i>task_system_clock)
-// {
-// log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"It is %d but I will sleep until %d...",task_system_clock,clock+i);
- for(int j=0;j<i;j++)asm("hlt");
+ while(clock+i>timer_get_ticks());
- // }
}
+
// disable interrupts
void x86_int_disable()
{
diff --git a/kernel/x86.h b/kernel/x86.h
index 9d1ba93..919879a 100644
--- a/kernel/x86.h
+++ b/kernel/x86.h
@@ -1,13 +1,9 @@
#ifndef FOOLOS_X86_H
#define FOOLOS_X86_H
-#include "lib/int/stdint.h"
+#include <stdint.h>
-// todo: cli/sti??
// http://wiki.osdev.org/Interrupt_Service_Routines
-// Black Magic: Strongly Discouraged!
-#define X86_IRQ_BEGIN asm("\ncli\npusha");
-#define X86_IRQ_END asm("mov $0x20, %al\nout %al, $0x20\nmov $0x20, %al\noutb %al,$0xa0\npopa\nleave\nsti\niret");
void sleep(int i); // TODO : Real sleep!
@@ -21,11 +17,13 @@ void x86_set_pdbr(uint32_t addr);
void x86_paging_enable();
void x86_flush_tlb(uint32_t addr);
void x86_int_enable();
+void x86_int_disable();
uint32_t x86_get_cr0();
uint32_t x86_get_cr1();
uint32_t x86_get_cr2();
uint32_t x86_get_cr3();
uint32_t x86_get_cr4();
uint8_t x86_xchg(uint8_t *addr, uint8_t val);
+void sleep(int i);
#endif
diff --git a/lib/bool/bool.h b/lib/bool/bool.h
index be2cbd4..c2c6171 100644
--- a/lib/bool/bool.h
+++ b/lib/bool/bool.h
@@ -1,6 +1,8 @@
+/*
#include "lib/int/stdint.h"
#define false 0
#define true !false
#define bool uint8_t
+*/
diff --git a/lib/buffer/ringbuffer.c b/lib/buffer/ringbuffer.c
index dcf7bc2..a121df1 100644
--- a/lib/buffer/ringbuffer.c
+++ b/lib/buffer/ringbuffer.c
@@ -4,27 +4,32 @@
#define FOOLOS_MODULE_NAME "ringbuffer"
-#include "lib/bool/bool.h"
+#include "ringbuffer.h"
+#include "kernel/x86.h"
#include "lib/logger/log.h"
#include "kernel/spinlock.h"
#define RINGBUFFER_SIZE 10
-static volatile int size=RINGBUFFER_SIZE;
+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)
{
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"put wants lock)");
- lock_spin(3);
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"locked by put)");
+ 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(3);
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by put)");
+ lock_release(sl);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by put");
+ x86_int_enable();
return false;
}
@@ -34,22 +39,25 @@ bool ringbuffer_put(char c)
back+=size;
back%=size;
- lock_release(3);
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by put)");
+ lock_release(sl);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by put");
+ x86_int_enable();
return true;
}
bool ringbuffer_get(char *c)
{
-
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"get wants lock)");
- lock_spin(3);
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"locked by get)");
+ 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(3);
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by get)");
+ lock_release(sl);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by get");
+ x86_int_enable();
+ *c='_';
return false;
}
@@ -60,8 +68,9 @@ bool ringbuffer_get(char *c)
front+=size;
front%=size;
- lock_release(3);
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by get)");
+ 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
index 2bb6528..038e33a 100644
--- a/lib/buffer/ringbuffer.h
+++ b/lib/buffer/ringbuffer.h
@@ -1,5 +1,3 @@
-#include "lib/bool/bool.h"
-
-void ringbuffer_init();
+#include <stdbool.h>
bool ringbuffer_put(char c);
bool ringbuffer_get(char *c);
diff --git a/lib/int/stdint.h b/lib/int/stdint.h
index 38b7040..f2b975f 100644
--- a/lib/int/stdint.h
+++ b/lib/int/stdint.h
@@ -1,3 +1,5 @@
+/*
#include <stdint.h>
+*/
diff --git a/lib/string/string.c b/lib/string/string.c
index 9f58c43..d5c27f7 100644
--- a/lib/string/string.c
+++ b/lib/string/string.c
@@ -1,4 +1,4 @@
-#include "lib/bool/bool.h"
+#include <stdbool.h>
//length 0 for null terminated strings;
bool strcmp(char *str1, char *str2, int length)
diff --git a/userspace/Makefile b/userspace/Makefile
index 7efc161..5d94a41 100644
--- a/userspace/Makefile
+++ b/userspace/Makefile
@@ -5,6 +5,7 @@ CFLAGS=
CFLAGS+=-I..
CFLAGS+=-w
CFLAGS+=-std=gnu11
+CFLAGS+=-O3
PROGS=foolshell ls simple brainfuck add checker clear
diff --git a/userspace/add.c b/userspace/add.c
index 2a13adf..3a624be 100644
--- a/userspace/add.c
+++ b/userspace/add.c
@@ -6,18 +6,16 @@
int main(int argc, char **argv)
{
- FILE *input;
- input=fopen("input2.txt","r"); //stdin
-
int sum=0;
int 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,input);
+ fgets(buf,255,stdin);
if(buf[1]=='x')break;
@@ -25,8 +23,12 @@ int main(int argc, char **argv)
sum+=atoi(buf);
}
- printf("sum = %i \n",sum);
- printf("avg = %i \n\n",sum/i);
+ if(i!=0)
+ {
+ puts("--------");
+ printf("sum = %i \n",sum);
+ printf("avg = %i \n\n",sum/i);
+ }
return 0;
}
diff --git a/userspace/checker.c b/userspace/checker.c
index e5352f6..ac0bcc9 100644
--- a/userspace/checker.c
+++ b/userspace/checker.c
@@ -9,6 +9,7 @@ int ch; /* Each character read. */
int checksum = 0; /* The checksum mod 2^16. */
int count=0;
+printf("this will calc a simple checksum of the enered text\nPress Left Control + D to signify end of file \n",checksum,count);
while ((ch = getc(fp)) != EOF) {
checksum = (checksum >> 1) + ((checksum & 1) << 15);
checksum +=(int) ch;
diff --git a/userspace/foolshell.c b/userspace/foolshell.c
index faa46be..e010c18 100644
--- a/userspace/foolshell.c
+++ b/userspace/foolshell.c
@@ -16,11 +16,12 @@ void hello()
" / __/ / /_/ / /_/ / / / /_/ /___/ / \n"
" /_/ \\____/\\____/_/ \\____//____/ \n"
" \n"
- "Welcome to FoolShell v0.3 (Compiled on " __DATE__ " at " __TIME__ "\n"
+ "Welcome to FoolShell v0.4 (Compiled on " __DATE__ " at " __TIME__ "\n"
"------------------------------------------------------------------\n\n"
"Please type 'help' anytime, to show shell \"built-ins\" or execute \n"
"user programms that are in you $PATH directory by simply typing \n"
- "their filenames.\n"
+ "their filenames. You can get additional information for many commands\n"
+ "by invking them with the --help or -h flag (e.g. ls --help) \n"
);
printf("Your $PATH is currently set to: %s\n\n",getenv("PATH"));
@@ -210,13 +211,23 @@ int process(char *buf)
}
else
{
- execve(token[0],token,0);
char buf[256];
- sprintf(buf,"/bin/%s",token[0]);
+ sprintf(buf,"%s/%s",getenv("PATH"),token[0]);
+
asm("mov $0x05bff,%esp"); // set stack pointer
execve(buf,token,environ);
+ asm("mov $0x07000,%esp"); // set stack pointer
+
puts("foolshell: command not found");
+
+ asm("mov $0x05bff,%esp"); // set stack pointer
+ static char *argv[]={"shell","--silent",NULL};
+ execve("/bin/foolshell",argv,environ); // start shell
+
+
+
}
+ return 0;
}
diff --git a/userspace/simple.c b/userspace/simple.c
index e84b072..0a04791 100644
--- a/userspace/simple.c
+++ b/userspace/simple.c
@@ -4,10 +4,8 @@ extern char **environ;
int main(int argc, char **argv)
{
-
printf("argv: 0x%08X\n",argv);
-
printf("env: 0x%08X\n",environ);
int i=0;
diff --git a/video/console.c b/video/console.c
index 5b6e103..743aaac 100644
--- a/video/console.c
+++ b/video/console.c
@@ -1,4 +1,5 @@
#include "console.h"
+#include "kernel/spinlock.h"
#include "kernel/config.h"
//#define FOOLOS_CONSOLE
@@ -109,11 +110,12 @@ void scr_nextline()
void scr_put_char(char ch,char col)
{
+ lock_spin(6);
if(ch=='\n')scr_nextline();
else if(posx<SCR_WIDTH)
{
- print_char_col(posx,posy,ch,SCR_GREEN);
+ print_char_col(posx,posy,ch,col);
posx++;
}
@@ -121,6 +123,8 @@ void scr_put_char(char ch,char col)
if(posx>=SCR_WIDTH)scr_nextline();
#endif
+ lock_release(6);
+
}
@@ -161,7 +165,7 @@ void scr_put_string(char *str)
void scr_backspace()
{
if(posx==0)return;
- print_char_col(posx-1,posy,'@',SCR_LGREEN);
+ print_char_col(posx-1,posy,' ',SCR_LGREEN);
posx--;
}
diff --git a/video/console.h b/video/console.h
index 74ec50c..71c3c72 100644
--- a/video/console.h
+++ b/video/console.h
@@ -3,7 +3,7 @@
// 80 x 24
// TODO: implement VT100
-#include "lib/int/stdint.h"
+#include <stdint.h>
#define SCR_VIDEOMEM 0xb8000