summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2014-10-17 01:00:27 +0200
committerMichal Idziorek <m.i@gmx.at>2014-10-17 01:00:27 +0200
commit3983a157056f10651f120cf39c5d3637aa956903 (patch)
tree5d956c9dfb4c625d975a2bc035fd32aa1950b84b
parent1580f8b4401b5f7e6ead12c94cafd42bb045ec6b (diff)
added simple syscall interface
-rw-r--r--asm/int_syscall_handler.asm41
-rw-r--r--kernel/interrupts.c20
-rw-r--r--kernel/kernel.c6
-rw-r--r--kernel/shell.c36
-rw-r--r--lib/string/string.c8
5 files changed, 104 insertions, 7 deletions
diff --git a/asm/int_syscall_handler.asm b/asm/int_syscall_handler.asm
new file mode 100644
index 0000000..e607ff5
--- /dev/null
+++ b/asm/int_syscall_handler.asm
@@ -0,0 +1,41 @@
+global int_syscall_handler
+
+[extern example_syscall]
+[extern example_syscall_2]
+
+[bits 32]
+int_syscall_handler:
+
+ cli
+
+ push ebx
+ push ecx
+ push edx
+
+ cmp eax, 10
+ je call_example_syscall
+
+ cmp eax, 20
+ je call_example_syscall_2
+
+done:
+
+ pop ebx
+ pop ecx
+ pop edx
+
+ mov ebx,eax
+
+ mov al, 0x20 ;Port number AND command number to Acknowledge IRQ
+ out 0x20, al ;Acknowledge IRQ, so we keep getting interrupts
+
+ sti
+ iret ;Interrupt-Return
+
+call_example_syscall:
+ call example_syscall
+ jmp done
+
+call_example_syscall_2
+ call example_syscall_2
+ jmp done
diff --git a/kernel/interrupts.c b/kernel/interrupts.c
index f5bd18f..56fa09f 100644
--- a/kernel/interrupts.c
+++ b/kernel/interrupts.c
@@ -9,6 +9,7 @@
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();
@@ -82,6 +83,22 @@ 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)
{
@@ -145,6 +162,9 @@ void int_init(uint16_t sel)
//mouse
int_install_ir(44, 0b10001110, 0x08,&mouse_handler);
+ //system calls
+ int_install_ir(0x80, 0b10001110, 0x08,&int_syscall_handler);
+
int_install();
diff --git a/kernel/kernel.c b/kernel/kernel.c
index 04eaa50..811f4c1 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -30,7 +30,7 @@ void kernel_ap()
cpu_counter[p]++;
lock_spin(0);
- if(cpu_counter[p]%1000000==0)log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"cpu[%d] %d",p,cpu_counter[p]);
+ if(cpu_counter[p]%1000000==0)log(FOOLOS_MODULE_NAME,FOOLOS_LOG_DEBUG,"cpu[%d] %d",p,cpu_counter[p]);
lock_release(0);
}
}
@@ -116,7 +116,6 @@ void kernel_main(uint32_t initial_stack, int mp)
// mouse driver init (before interrupts)
mouse_init();
-
//
// Setup Interrupts (code segment: 0x08)
//
@@ -128,7 +127,6 @@ void kernel_main(uint32_t initial_stack, int mp)
//
smp_processors procdata;
- // try to find acpi tables
if(!acpi_find(&procdata))
if(!mp_find(&procdata))
panic(FOOLOS_MODULE_NAME,"ACPI and MP search failed! I do not want to continue!");
@@ -148,7 +146,6 @@ void kernel_main(uint32_t initial_stack, int mp)
// init spinlocks
init_spinlocks();
-
//
// Start the other Processors (also before paging for some reason!)
//
@@ -189,7 +186,6 @@ void kernel_main(uint32_t initial_stack, int mp)
//
shell_init();
-
//
// Initialize Multitasking
//
diff --git a/kernel/shell.c b/kernel/shell.c
index b377ce0..2e00bd0 100644
--- a/kernel/shell.c
+++ b/kernel/shell.c
@@ -82,6 +82,42 @@ void shell_execute()
{
// uint8_t *read= flpydsk_read_sector (10);
}
+ else if(1==strcmp(command,"SYSCALL",0))
+ {
+
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"system call 10");
+ uint32_t ebx; // will hold return value;
+ // system call
+ asm("pusha");
+ asm("mov $10,%eax"); // select syscall 10 (example_syscall)
+ asm("mov $666,%edx");
+ asm("mov $333,%ecx");
+ asm("int $0x80"); // actual syscall ! interrupt
+ asm("mov %%ebx, %0": "=b" (ebx));
+ asm("popa");
+ //
+
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"system call returned %d",ebx);
+
+ }
+ else if(1==strcmp(command,"TWO",0))
+ {
+
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"system call 20");
+ uint32_t ebx; // will hold return value;
+ // system call
+ asm("pusha");
+ asm("mov $20,%eax"); // select syscall2 20 (example_syscall)
+ asm("mov $566,%edx");
+ asm("mov $233,%ecx");
+ asm("int $0x80"); // actual syscall ! interrupt
+ asm("mov %%ebx, %0": "=b" (ebx));
+ asm("popa");
+ //
+
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"system call returned %d",ebx);
+
+ }
else
{
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"command unknown");
diff --git a/lib/string/string.c b/lib/string/string.c
index bdd92c9..9f58c43 100644
--- a/lib/string/string.c
+++ b/lib/string/string.c
@@ -1,6 +1,5 @@
#include "lib/bool/bool.h"
-
//length 0 for null terminated strings;
bool strcmp(char *str1, char *str2, int length)
{
@@ -11,6 +10,11 @@ bool strcmp(char *str1, char *str2, int length)
i++;
if(i==length) return true;
- if(length==0&&str1[i]==0&&str2[i]==0) return true;
+ if(str1[i]==0||str2[i]==0)
+ {
+ if(str1[i]==str2[i])return true;
+ return false;
+ }
}
+
}