feat: test de syscall, implémentation sous forme de macro et handler opérationnel
This commit is contained in:
parent
3129b5edcc
commit
8d3da6480a
|
@ -54,15 +54,6 @@
|
||||||
asm volatile ("movl %%ebp,%[tomem];":: [tomem] "m" (mem)); \
|
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("\
|
#define dumpcpu() asm("\
|
||||||
pushal \n \
|
pushal \n \
|
||||||
pushf \n \
|
pushf \n \
|
||||||
|
|
|
@ -2,57 +2,55 @@
|
||||||
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
|
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
|
||||||
/* */
|
/* */
|
||||||
|
|
||||||
#define sysexit \
|
#define sysexit() asm volatile ("sysexit"::);
|
||||||
asm volatile ("sysexit"::"c");
|
|
||||||
|
|
||||||
|
|
||||||
static inline long syscall(long syscall) {
|
#define inb(port) ({ \
|
||||||
long ret;
|
u8 _v; \
|
||||||
asm volatile (
|
asm volatile ("inb %%dx,%%al" : "=a" (_v) : "d" (port)); \
|
||||||
"pushl %%ecx;\
|
_v; \
|
||||||
pushl %%edx;\
|
})
|
||||||
mov %%esp,%%ecx;\
|
|
||||||
|
|
||||||
|
#define syscall0(syscall) ({ \
|
||||||
|
u32 _v; \
|
||||||
|
asm volatile (\
|
||||||
|
"mov %%esp,%%ecx;\
|
||||||
mov $1f,%%edx;\
|
mov $1f,%%edx;\
|
||||||
sysenter;\
|
sysenter;\
|
||||||
1:" : "=a" (ret) : "a" (syscall): "ecx","edx","memory");
|
1:" : "=a" (_v) : "a" (syscall): "ecx","edx","memory"); \
|
||||||
return ret;
|
_v; \
|
||||||
}
|
})
|
||||||
|
|
||||||
static inline long syscall1(long syscall, long arg1) {
|
#define syscall1(syscall,arg1) ({ \
|
||||||
long ret;
|
u32 _v; \
|
||||||
asm volatile (
|
asm volatile (\
|
||||||
"pushl %%ecx;\
|
"mov %%esp,%%ecx;\
|
||||||
pushl %%edx;\
|
|
||||||
mov %%esp,%%ecx;\
|
|
||||||
mov $1f,%%edx;\
|
mov $1f,%%edx;\
|
||||||
sysenter;\
|
sysenter;\
|
||||||
1:" : "=a" (ret) : "a" (syscall), "b" (arg1) : "ecx","edx","memory");
|
1:" : "=a" (_v) : "a" (syscall), "b" (arg1) : "ecx","edx","memory"); \
|
||||||
return ret;
|
_v; \
|
||||||
}
|
})
|
||||||
|
|
||||||
static inline long syscall2(long syscall, long arg1, long arg2) {
|
#define syscall2(syscall,arg1,arg2) ({ \
|
||||||
long ret;
|
u32 _v; \
|
||||||
asm volatile (
|
asm volatile (\
|
||||||
"pushl %%ecx;\
|
"mov %%esp,%%ecx;\
|
||||||
pushl %%edx;\
|
|
||||||
mov %%esp,%%ecx;\
|
|
||||||
mov $1f,%%edx;\
|
mov $1f,%%edx;\
|
||||||
sysenter;\
|
sysenter;\
|
||||||
1:" : "=a" (ret) : "a" (syscall), "b" (arg1), "S" (arg2) : "ecx","edx","memory");
|
1:" : "=a" (_v) : "a" (syscall), "b" (arg1), "S" (arg2) : "ecx","edx","memory"); \
|
||||||
return ret;
|
_v; \
|
||||||
}
|
})
|
||||||
|
|
||||||
static inline long syscall3(long syscall, long arg1, long arg2, long arg3) {
|
#define syscall3(syscall,arg1,arg2,arg3) ({ \
|
||||||
long ret;
|
u32 _v; \
|
||||||
asm volatile (
|
asm volatile (\
|
||||||
"pushl %%ecx;\
|
"mov %%esp,%%ecx;\
|
||||||
pushl %%edx;\
|
|
||||||
mov %%esp,%%ecx;\
|
|
||||||
mov $1f,%%edx;\
|
mov $1f,%%edx;\
|
||||||
sysenter;\
|
sysenter;\
|
||||||
1:" : "=a" (ret) : "a" (syscall), "b" (arg1), "S" (arg2), "D" (arg3) : "ecx","edx","memory");
|
1:" : "=a" (_v) : "a" (syscall), "b" (arg1), "S" (arg2), "D" (arg3) : "ecx","edx","memory"); \
|
||||||
return ret;
|
_v; \
|
||||||
}
|
})
|
||||||
|
|
||||||
/* Vers 6 arguments maximum */
|
/* Vers 6 arguments maximum */
|
||||||
void initsyscall(void);
|
void initsyscall(void);
|
||||||
|
|
|
@ -23,8 +23,10 @@ void initgdt(u32 offset)
|
||||||
makegdtdes(0x0, 0x00000, 0x00, 0x00, &gdt[0]); /* descripteur nul */
|
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, 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, 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, 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_RING3 | SEG_EXPAND_DOWN | SEG_READ_WRITE | SEG_ACCESSED, GRANULARITY_4K | OPSIZE_32B | SYS_AVAILABLE, &gdt[4]); /* pile -> SEL_USER_STACK */
|
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_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 */
|
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 */
|
||||||
|
|
||||||
|
|
|
@ -156,11 +156,9 @@ void cpuerror(const u8 * src, const save_stack *stack)
|
||||||
void interruption()
|
void interruption()
|
||||||
{
|
{
|
||||||
cli();
|
cli();
|
||||||
pushf();
|
|
||||||
pushad();
|
pushad();
|
||||||
print("Appel d'une interruption\r\n");
|
print("Appel d'une interruption\r\n");
|
||||||
popad();
|
popad();
|
||||||
popf();
|
|
||||||
sti();
|
sti();
|
||||||
iret();
|
iret();
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#include <gdt.h>
|
#include <gdt.h>
|
||||||
#include <asm.h>
|
#include <asm.h>
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
|
#include <interrupts.h>
|
||||||
|
#include <syscall.h>
|
||||||
|
|
||||||
/* 32bit SYSENTER instruction entry.
|
/* 32bit SYSENTER instruction entry.
|
||||||
*
|
*
|
||||||
|
@ -24,8 +26,25 @@
|
||||||
|
|
||||||
void sysenter_handler(void)
|
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)
|
void initsyscall(void)
|
||||||
{
|
{
|
||||||
wrmsr(0x174, SEL_KERNEL_CODE, 0x0);
|
wrmsr(0x174, SEL_KERNEL_CODE, 0x0);
|
||||||
wrmsr(0x175, KERNEL_STACK_ADDR, 0x0);
|
wrmsr(0x175, 0x60000, 0x0);
|
||||||
wrmsr(0x176, &sysenter_handler, 0x0);
|
wrmsr(0x176, &sysenter_handler+6, 0x0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************/
|
/*******************************************************************************/
|
||||||
|
|
Loading…
Reference in New Issue