feat: test de syscall, implémentation sous forme de macro et handler opérationnel

This commit is contained in:
Nicolas Hordé 2018-12-05 16:42:25 +01:00
parent 3129b5edcc
commit 8d3da6480a
5 changed files with 71 additions and 63 deletions

View File

@ -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 \

View File

@ -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;\
#define inb(port) ({ \
u8 _v; \
asm volatile ("inb %%dx,%%al" : "=a" (_v) : "d" (port)); \
_v; \
})
#define syscall0(syscall) ({ \
u32 _v; \
asm volatile (\
"mov %%esp,%%ecx;\
mov $1f,%%edx;\
sysenter;\
1:" : "=a" (ret) : "a" (syscall): "ecx","edx","memory");
return ret;
}
1:" : "=a" (_v) : "a" (syscall): "ecx","edx","memory"); \
_v; \
})
static inline long syscall1(long syscall, long arg1) {
long ret;
asm volatile (
"pushl %%ecx;\
pushl %%edx;\
mov %%esp,%%ecx;\
#define syscall1(syscall,arg1) ({ \
u32 _v; \
asm volatile (\
"mov %%esp,%%ecx;\
mov $1f,%%edx;\
sysenter;\
1:" : "=a" (ret) : "a" (syscall), "b" (arg1) : "ecx","edx","memory");
return ret;
}
1:" : "=a" (_v) : "a" (syscall), "b" (arg1) : "ecx","edx","memory"); \
_v; \
})
static inline long syscall2(long syscall, long arg1, long arg2) {
long ret;
asm volatile (
"pushl %%ecx;\
pushl %%edx;\
mov %%esp,%%ecx;\
#define syscall2(syscall,arg1,arg2) ({ \
u32 _v; \
asm volatile (\
"mov %%esp,%%ecx;\
mov $1f,%%edx;\
sysenter;\
1:" : "=a" (ret) : "a" (syscall), "b" (arg1), "S" (arg2) : "ecx","edx","memory");
return ret;
}
1:" : "=a" (_v) : "a" (syscall), "b" (arg1), "S" (arg2) : "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;\
#define syscall3(syscall,arg1,arg2,arg3) ({ \
u32 _v; \
asm volatile (\
"mov %%esp,%%ecx;\
mov $1f,%%edx;\
sysenter;\
1:" : "=a" (ret) : "a" (syscall), "b" (arg1), "S" (arg2), "D" (arg3) : "ecx","edx","memory");
return ret;
}
1:" : "=a" (_v) : "a" (syscall), "b" (arg1), "S" (arg2), "D" (arg3) : "ecx","edx","memory"); \
_v; \
})
/* Vers 6 arguments maximum */
void initsyscall(void);

View File

@ -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 */

View File

@ -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();
}

View File

@ -5,6 +5,8 @@
#include <gdt.h>
#include <asm.h>
#include <memory.h>
#include <interrupts.h>
#include <syscall.h>
/* 32bit SYSENTER instruction entry.
*
@ -24,8 +26,25 @@
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);
}
/*******************************************************************************/