diff --git a/include/interrupts.h b/include/interrupts.h index 9734b11..0d6f3b6 100755 --- a/include/interrupts.h +++ b/include/interrupts.h @@ -54,15 +54,6 @@ asm volatile ("movl %%ebp,%[tomem];":: [tomem] "m" (mem)); \ }) -#define setEBP(mem) ({ \ - asm volatile ("movl %[tomem],%%ebp;":[tomem] "=m" (mem):); \ -}) - -#define setESP(mem) ({ \ - asm volatile ("movl %[tomem],%%esp;":[tomem] "=m" (mem):); \ -}) - - #define dumpcpu() asm("\ pushal \n \ pushf \n \ diff --git a/include/syscall.h b/include/syscall.h index a0c0e06..300949c 100644 --- a/include/syscall.h +++ b/include/syscall.h @@ -2,57 +2,55 @@ /* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */ /* */ -#define sysexit \ - asm volatile ("sysexit"::"c"); +#define sysexit() asm volatile ("sysexit"::); -static inline long syscall(long syscall) { -long ret; -asm volatile ( -"pushl %%ecx;\ -pushl %%edx;\ -mov %%esp,%%ecx;\ -mov $1f,%%edx;\ -sysenter;\ -1:" : "=a" (ret) : "a" (syscall): "ecx","edx","memory"); -return ret; -} +#define inb(port) ({ \ + u8 _v; \ + asm volatile ("inb %%dx,%%al" : "=a" (_v) : "d" (port)); \ + _v; \ +}) -static inline long syscall1(long syscall, long arg1) { -long ret; -asm volatile ( -"pushl %%ecx;\ -pushl %%edx;\ -mov %%esp,%%ecx;\ -mov $1f,%%edx;\ -sysenter;\ -1:" : "=a" (ret) : "a" (syscall), "b" (arg1) : "ecx","edx","memory"); -return ret; -} -static inline long syscall2(long syscall, long arg1, long arg2) { -long ret; -asm volatile ( -"pushl %%ecx;\ -pushl %%edx;\ -mov %%esp,%%ecx;\ -mov $1f,%%edx;\ -sysenter;\ -1:" : "=a" (ret) : "a" (syscall), "b" (arg1), "S" (arg2) : "ecx","edx","memory"); -return ret; -} +#define syscall0(syscall) ({ \ + u32 _v; \ + asm volatile (\ + "mov %%esp,%%ecx;\ + mov $1f,%%edx;\ + sysenter;\ + 1:" : "=a" (_v) : "a" (syscall): "ecx","edx","memory"); \ + _v; \ +}) -static inline long syscall3(long syscall, long arg1, long arg2, long arg3) { -long ret; -asm volatile ( -"pushl %%ecx;\ -pushl %%edx;\ -mov %%esp,%%ecx;\ -mov $1f,%%edx;\ -sysenter;\ -1:" : "=a" (ret) : "a" (syscall), "b" (arg1), "S" (arg2), "D" (arg3) : "ecx","edx","memory"); -return ret; -} +#define syscall1(syscall,arg1) ({ \ + u32 _v; \ + asm volatile (\ + "mov %%esp,%%ecx;\ + mov $1f,%%edx;\ + sysenter;\ + 1:" : "=a" (_v) : "a" (syscall), "b" (arg1) : "ecx","edx","memory"); \ + _v; \ +}) + +#define syscall2(syscall,arg1,arg2) ({ \ + u32 _v; \ + asm volatile (\ + "mov %%esp,%%ecx;\ + mov $1f,%%edx;\ + sysenter;\ + 1:" : "=a" (_v) : "a" (syscall), "b" (arg1), "S" (arg2) : "ecx","edx","memory"); \ + _v; \ +}) + +#define syscall3(syscall,arg1,arg2,arg3) ({ \ + u32 _v; \ + asm volatile (\ + "mov %%esp,%%ecx;\ + mov $1f,%%edx;\ + sysenter;\ + 1:" : "=a" (_v) : "a" (syscall), "b" (arg1), "S" (arg2), "D" (arg3) : "ecx","edx","memory"); \ + _v; \ +}) /* Vers 6 arguments maximum */ void initsyscall(void); diff --git a/lib/gdt.c b/lib/gdt.c index bc53820..988b88a 100755 --- a/lib/gdt.c +++ b/lib/gdt.c @@ -23,8 +23,10 @@ void initgdt(u32 offset) makegdtdes(0x0, 0x00000, 0x00, 0x00, &gdt[0]); /* descripteur nul */ makegdtdes(0x0, 0xFFFFF, SEG_PRESENT | SEG_NORMAL | SEG_CODE | SEG_RING0 | SEG_READ | SEG_ACCESSED, GRANULARITY_4K | OPSIZE_32B | SYS_AVAILABLE, &gdt[1]); /* code -> SEL_KERNEL_CODE */ makegdtdes(0x0, 0x00000, SEG_PRESENT | SEG_NORMAL | SEG_DATA | SEG_RING0 | SEG_EXPAND_DOWN | SEG_READ_WRITE | SEG_ACCESSED, GRANULARITY_4K | OPSIZE_32B | SYS_AVAILABLE, &gdt[2]); /* pile -> SEL_KERNEL_STACK */ - makegdtdes(0x0, 0xFFFFF, SEG_PRESENT | SEG_NORMAL | SEG_CODE | SEG_RING3 | SEG_CONFORMING | SEG_READ | SEG_ACCESSED, GRANULARITY_4K | OPSIZE_32B | SYS_AVAILABLE, &gdt[3]); /* code -> SEL_USER_CODE */ - makegdtdes(0x0, 0x00000, SEG_PRESENT | SEG_NORMAL | SEG_DATA | SEG_RING3 | SEG_EXPAND_DOWN | SEG_READ_WRITE | SEG_ACCESSED, GRANULARITY_4K | OPSIZE_32B | SYS_AVAILABLE, &gdt[4]); /* pile -> SEL_USER_STACK */ + makegdtdes(0x0, 0xFFFFF, SEG_PRESENT | SEG_NORMAL | SEG_CODE | SEG_RING0 | SEG_READ | SEG_ACCESSED, GRANULARITY_4K | OPSIZE_32B | SYS_AVAILABLE, &gdt[3]); /* code -> SEL_KERNEL_CODE */ + makegdtdes(0x0, 0x00000, SEG_PRESENT | SEG_NORMAL | SEG_DATA | SEG_RING0 | SEG_EXPAND_DOWN | SEG_READ_WRITE | SEG_ACCESSED, GRANULARITY_4K | OPSIZE_32B | SYS_AVAILABLE, &gdt[4]); /* pile -> SEL_KERNEL_STACK */ + makegdtdes(0x0, 0xFFFFF, SEG_PRESENT | SEG_NORMAL | SEG_CODE | SEG_RING3 | SEG_CONFORMING | SEG_READ | SEG_ACCESSED, GRANULARITY_4K | OPSIZE_32B | SYS_AVAILABLE, &gdt[7]); /* code -> SEL_USER_CODE */ + makegdtdes(0x0, 0x00000, SEG_PRESENT | SEG_NORMAL | SEG_DATA | SEG_RING3 | SEG_EXPAND_DOWN | SEG_READ_WRITE | SEG_ACCESSED, GRANULARITY_4K | OPSIZE_32B | SYS_AVAILABLE, &gdt[8]); /* pile -> SEL_USER_STACK */ makegdtdes(0x0, 0xFFFFF, SEG_PRESENT | SEG_NORMAL | SEG_DATA | SEG_RING0 | SEG_READ_WRITE | SEG_ACCESSED, GRANULARITY_4K | OPSIZE_32B | SYS_AVAILABLE, &gdt[5]); /* data -> SEL_KERNEL_DATA */ makegdtdes(0x0, 0xFFFFF, SEG_PRESENT | SEG_NORMAL | SEG_DATA | SEG_RING3 | SEG_READ_WRITE | SEG_ACCESSED, GRANULARITY_4K | OPSIZE_32B | SYS_AVAILABLE, &gdt[6]); /* data -> SEL_USER_DATA */ diff --git a/lib/interrupts.c b/lib/interrupts.c index e55e66a..33d8f8a 100755 --- a/lib/interrupts.c +++ b/lib/interrupts.c @@ -156,11 +156,9 @@ void cpuerror(const u8 * src, const save_stack *stack) void interruption() { cli(); - pushf(); pushad(); print("Appel d'une interruption\r\n"); popad(); - popf(); sti(); iret(); } diff --git a/lib/syscall.c b/lib/syscall.c index fef832a..4477772 100644 --- a/lib/syscall.c +++ b/lib/syscall.c @@ -5,6 +5,8 @@ #include #include #include +#include +#include /* 32bit SYSENTER instruction entry. * @@ -23,8 +25,25 @@ /* Entrée pour les appels système SYSENTER */ void sysenter_handler(void) -{ - +{ + cli(); + save_stack *dump; + dumpcpu(); + getESP(dump); + sti(); + switch (dump->eax) + { + case 0: + printf("Test de fonctionnement syscall\r\n -arguments 1:%Y 2:%Y 3:%Y\r\n", dump->ebx,dump->esi,dump->edi); + dump->eax=0x6666666; + break; + default: + printf("Appel syscall vers fonction inexistante en %Y:%Y", dump->cs,dump->eip); + break; + + } + restdebugcpu(); + sysexit(); } /*******************************************************************************/ @@ -34,8 +53,8 @@ void sysenter_handler(void) void initsyscall(void) { wrmsr(0x174, SEL_KERNEL_CODE, 0x0); - wrmsr(0x175, KERNEL_STACK_ADDR, 0x0); - wrmsr(0x176, &sysenter_handler, 0x0); + wrmsr(0x175, 0x60000, 0x0); + wrmsr(0x176, &sysenter_handler+6, 0x0); } /*******************************************************************************/