summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-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
17 files changed, 184 insertions, 150 deletions
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