summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--asm/int_mouse_handler.asm5
-rw-r--r--asm/int_syscall_handler.asm4
-rw-r--r--asm/task.s75
-rw-r--r--driver/keyboard.c1
-rw-r--r--kernel/interrupts.c1
-rw-r--r--kernel/kernel.c8
-rw-r--r--kernel/task.c67
-rw-r--r--kernel/usermode.c15
-rw-r--r--lib/logger/log.c2
9 files changed, 156 insertions, 22 deletions
diff --git a/asm/int_mouse_handler.asm b/asm/int_mouse_handler.asm
index 6872af0..9816950 100644
--- a/asm/int_mouse_handler.asm
+++ b/asm/int_mouse_handler.asm
@@ -7,9 +7,10 @@ int_mouse_handler:
call mouse_handler
- mov al, 0x20 ;Port number AND command number to Acknowledge IRQ
+ mov al, 0x20 ; Port number AND command number to Acknowledge IRQ
out 0xa0, al ; came from slave
- out 0x20, al ;Acknowledge IRQ, so we keep getting interrupts
+ out 0x20, al ; Acknowledge IRQ, so we keep getting interrupts
+
popa
iret ;Interrupt-Return
diff --git a/asm/int_syscall_handler.asm b/asm/int_syscall_handler.asm
index 952faae..a26592f 100644
--- a/asm/int_syscall_handler.asm
+++ b/asm/int_syscall_handler.asm
@@ -221,8 +221,8 @@ call_unhandled:
;; TODO: redesign this shit!
call_read:
- mov al, 0x20 ;Port number AND command number to Acknowledge IRQ
- out 0x20, al ;Acknowledge IRQ, so we keep getting interrupts
+ ;//mov al, 0x20 ;Port number AND command number to Acknowledge IRQ
+ ;//out 0x20, al ;Acknowledge IRQ, so we keep getting interrupts
sti
call syscall_read
diff --git a/asm/task.s b/asm/task.s
new file mode 100644
index 0000000..7611d4a
--- /dev/null
+++ b/asm/task.s
@@ -0,0 +1,75 @@
+.global task_pusha
+task_pusha:
+
+ pushf
+
+ push $0x8
+ push $userfunc
+
+ pusha
+ /*
+ now stack looks like:
+
+ param // esp+48
+ returnaddy
+
+ eflags
+ code segment
+ userfunc
+
+ eax // rest by popa
+ ecx
+ edx
+ ebx
+ esp
+ ebp
+ esi
+ edi
+
+ */
+
+ mov 48(%esp),%eax // get address of alternative stack where we want to simulate the pusha
+
+ mov (%esp),%ecx
+ mov %ecx,(%eax)
+
+ mov 4(%esp),%ecx
+ mov %ecx,4(%eax)
+
+ mov 8(%esp),%ecx
+ mov %ecx,8(%eax)
+
+ mov 12(%esp),%ecx
+ mov %ecx,12(%eax)
+
+ mov 16(%esp),%ecx
+ mov %ecx,16(%eax)
+
+ mov 20(%esp),%ecx
+ mov %ecx,20(%eax)
+
+ mov 24(%esp),%ecx
+ mov %ecx,24(%eax)
+
+ mov 28(%esp),%ecx
+ mov %ecx,28(%eax)
+
+ mov 32(%esp),%ecx
+ mov %ecx,32(%eax)
+
+ mov 36(%esp),%ecx
+ mov %ecx,36(%eax)
+
+ mov 40(%esp),%ecx
+ mov %ecx,40(%eax)
+
+ mov 44(%esp),%ecx
+ mov %ecx,44(%eax)
+
+ pop %eax
+ pop %eax
+ pop %eax
+
+ popa
+
+ ret
diff --git a/driver/keyboard.c b/driver/keyboard.c
index d35ef6d..52e6454 100644
--- a/driver/keyboard.c
+++ b/driver/keyboard.c
@@ -21,7 +21,6 @@ static void put(uint8_t c)
void keyboard_init(uint32_t s)
{
kb_stream=s;
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Keyboard Initialized");
}
void keyboard_handle(uint8_t in)
diff --git a/kernel/interrupts.c b/kernel/interrupts.c
index 96446f3..9b08475 100644
--- a/kernel/interrupts.c
+++ b/kernel/interrupts.c
@@ -51,6 +51,7 @@ void exception_handle()
void int_default()
{
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"default handler");
+ panic(FOOLOS_MODULE_NAME,"unhandled interrupt (is this a panic or should just iognore?)");
}
void show_error(uint32_t err)
diff --git a/kernel/kernel.c b/kernel/kernel.c
index ea14869..e1076a9 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -35,6 +35,7 @@ void kernel_main(uint32_t eax,uint32_t ebx)
// KEYBOARD DRIVER
keyboard_init(0); //sstdin
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Keyboard Initialized");
// MOUSE DRIVER
mouse_init();
@@ -80,13 +81,10 @@ void kernel_main(uint32_t eax,uint32_t ebx)
uint32_t sstdout = syscall_open("term",0,0); // stdout 1
uint32_t sstderr = syscall_open("stderr",0,0); // stderr 2
- // START INTERRUPTS (code segment: 0x08)
+ // INSTALL INTERRUPTS (code segment: 0x08)
int_init(0x08);
- // INIT MULTITASKING (and switch to our pseudo-usermode)
+ // INIT MULTITASKING (and start scheduler)
task_init(dir);
- // we should never reach this
- panic(FOOLOS_MODULE_NAME,"reached end of kernel.c !!");
-
}
diff --git a/kernel/task.c b/kernel/task.c
index c281821..395c196 100644
--- a/kernel/task.c
+++ b/kernel/task.c
@@ -45,7 +45,6 @@ volatile int add_task(uint32_t esp, uint32_t vmem)
task_list[i].waiting=false;
task_list[i].skipwait=false;
task_list[i].brk=task_list[current_task].brk;
-
return i;
}
}
@@ -53,9 +52,29 @@ volatile int add_task(uint32_t esp, uint32_t vmem)
panic(FOOLOS_MODULE_NAME,"out of task slots!");
}
+//
+// REMEMBER WE ARE INSIDE AN INTERRUPT HERE - DON'T WASTE TIME!
+//
+// oldesp - is the adress of the stack pointer when pit_interrupt_handler was entered.
+// registers have been pushed with pusha to this old stack.
+//
+// stack pointer was moved to the 16kb stack we have from multiboot.s
+//
+// we need to return a NEW stack pointer where popa will get the registers the new task requires
+//
+static int first=1;
volatile uint32_t my_scheduler(uint32_t oldesp)
{
- task_list[current_task].esp=oldesp;
+
+ // allows skipping scheduling from gdb
+ volatile int skippy=0;
+ if(skippy)return oldesp;
+
+ if(!first)
+ {
+ task_list[current_task].esp=oldesp;
+ }
+ first=0;
for(int i=0;i<MAX_TASKS;i++)
{
@@ -89,6 +108,7 @@ volatile uint32_t task_switch_next(uint32_t oldesp)
//TODO: notify waiting parent when child finished;
volatile uint32_t task_exit(uint32_t oldesp)
{
+
task_list[current_task].active=false;
int parent_pid=task_list[current_task].parent;
@@ -140,16 +160,51 @@ volatile uint32_t task_fork(uint32_t oldesp)
// init task (root of all other tasks / processes) //
volatile void task_init(pdirectory *dir)
{
-
+ current_task=0;
+
// this is our main task on slot 0
task_list[0].parent=0;
task_list[0].active=true;
task_list[0].waiting=false;
task_list[0].vmem=dir;
- task_list[0].esp = 0; // will be set by next task_switch_next() call.
+ task_list[0].esp = kballoc(4); // 0; // will be set by next task_switch_next() call.
+
+ task_list[1].parent=0;
+ task_list[1].active=true;
+ task_list[1].waiting=false;
+ task_list[1].vmem=dir;
+ task_list[1].esp = kballoc(4); // fresh 16kb stack from here.
+
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"fresh esp on: 0x%08X",1,task_list[1].esp);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"fresh esp on: 0x%08X",0,task_list[0].esp);
+
+ task_pusha(task_list[1].esp); // pusha but to alternative location
+ task_pusha(task_list[0].esp); // pusha but to alternative location
+
+ /*
current_task=0;
-
- switch_to_user_mode();
+ unsigned esp, ebp, eax, ebx, ecx, edx;
+
+ asm(
+ "movl %%esp, %0;"
+ "movl %%ebp, %1;"
+ "movl %%eax, %2;"
+ "movl %%ebx, %3;"
+ "movl %%ecx, %4;"
+ "movl %%edx, %5;"
+ :"=r"(esp), "=r"(ebp), "=r"(eax), "=r"(ebx), "=r"(ecx), "=r"(edx)
+ );
+
+ // TODO: prepare stack so popa get's what it wants!
+ int i=task_fork(esp);
+ */
+
+ // finally enable interrrupts so the scheduler is called (by timer)
+ x86_sti();
+
+ // loop until scheduler kicks in and reschedules us...
+ while(1);
+
}
volatile int task_get_current_pid()
diff --git a/kernel/usermode.c b/kernel/usermode.c
index 76558d8..81dc5c1 100644
--- a/kernel/usermode.c
+++ b/kernel/usermode.c
@@ -26,11 +26,18 @@ void install_tss(int cpu_no){
// sys_tss.iomap = ( unsigned short ) sizeof( tss_struct );
}
-// THIS IS THE FUNCTION TO BE RUN IN RING 3 // USER MODE
-static void userfunc()
+void userfunc()
{
- syscall(SYSCALL_EXECVE,BIN_INIT,NULL,NULL);
- while(1); // we should never get here.
+ // we need enable here again (since the pushed eflags have it disabled)!
+ x86_sti();
+
+ // if we are pid 0, replace ourselves with /bin/init TODO: switch to usermode before!
+ if(task_get_current_pid()==0)syscall(SYSCALL_EXECVE,BIN_INIT,NULL,NULL);
+
+ // kernel worker thread
+ if(task_get_current_pid()==1)
+ {
+ }
}
void switch_to_user_mode()
diff --git a/lib/logger/log.c b/lib/logger/log.c
index a5925e9..968d978 100644
--- a/lib/logger/log.c
+++ b/lib/logger/log.c
@@ -13,12 +13,10 @@
static void log_string(char *str)
{
// if(get_max_fd()>=2) syscall_write(2,str,strlen(str));
-
while(*str!=0)
{
serial_write(*str++);
}
-
}
void log(char *module_name, int log_level, char *format_string, ...)