2018-09-28 20:35:51 +02:00
|
|
|
/*******************************************************************************/
|
2018-12-14 01:06:37 +01:00
|
|
|
/* COS2000 - Compatible Operating System - LGPL v3 - Horde Nicolas */
|
2018-09-28 20:35:51 +02:00
|
|
|
/* */
|
2018-09-18 14:29:35 +02:00
|
|
|
#include <types.h>
|
2018-09-27 17:47:27 +02:00
|
|
|
#include <gdt.h>
|
|
|
|
#include <asm.h>
|
2018-10-02 02:16:14 +02:00
|
|
|
#include <memory.h>
|
2018-12-05 16:42:25 +01:00
|
|
|
#include <interrupts.h>
|
|
|
|
#include <syscall.h>
|
2018-12-12 17:57:23 +01:00
|
|
|
#include <process.h>
|
2018-09-18 14:29:35 +02:00
|
|
|
|
2018-09-18 15:11:50 +02:00
|
|
|
/* 32bit SYSENTER instruction entry.
|
2018-09-27 17:47:27 +02:00
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* %eax System call number.
|
|
|
|
* %ebx Arg1
|
2018-12-14 01:06:37 +01:00
|
|
|
* %esi Arg2
|
2018-12-15 19:13:26 +01:00
|
|
|
* %edi Arg3*/
|
|
|
|
|
2018-12-16 01:50:03 +01:00
|
|
|
extern wrapper_sysenter;
|
|
|
|
|
2018-12-14 01:06:37 +01:00
|
|
|
/*******************************************************************************/
|
2018-12-15 19:13:26 +01:00
|
|
|
/* Initialise les appels système par SYSENTER/SYSEXIT */
|
2018-12-14 01:06:37 +01:00
|
|
|
|
2018-12-15 19:13:26 +01:00
|
|
|
void initsyscall(void)
|
|
|
|
{
|
|
|
|
wrmsr(0x174, SEL_KERNEL_CODE, 0x0);
|
|
|
|
wrmsr(0x175, 0x60000, 0x0);
|
2018-12-16 01:50:03 +01:00
|
|
|
wrmsr(0x176, &wrapper_sysenter, 0x0);
|
|
|
|
return;
|
2018-12-15 19:13:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
2018-12-14 01:06:37 +01:00
|
|
|
/* Fonction permettant de tester le fonctionnement de SYSENTER */
|
|
|
|
/* SYSCALL
|
|
|
|
{
|
|
|
|
"ID":0,
|
|
|
|
"LIBRARY":"libsys",
|
|
|
|
"NAME":"testapi",
|
|
|
|
"INTERNALNAME":"testapi",
|
|
|
|
"DESCRIPTION":"Simple function to test if SYSCALL API is correctly running",
|
|
|
|
"ARGS": [
|
|
|
|
{"TYPE":"u32","NAME":"arg1","DESCRIPTION":"first argument of your choice"},
|
|
|
|
{"TYPE":"u32","NAME":"arg2","DESCRIPTION":"second argument of your choice"},
|
|
|
|
{"TYPE":"u32","NAME":"arg3","DESCRIPTION":"third argument of your choice"}
|
|
|
|
],
|
|
|
|
"RETURN":"u32",
|
|
|
|
"DUMP":"yes"
|
|
|
|
}
|
|
|
|
END */
|
|
|
|
|
|
|
|
u32 testapi(u32 arg1, u32 arg2, u32 arg3, regs* dump)
|
|
|
|
{
|
|
|
|
printf("Appel syscall %u depuis %Y:%Y avec arguments => ARG1:%Y ARG2:%Y ARG3:%Y\r\n", dump->eax, (u32) dump->cs, dump->eip, arg1, arg2, arg3);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
2018-09-18 14:29:35 +02:00
|
|
|
/* Entrée pour les appels système SYSENTER */
|
2018-12-16 01:50:03 +01:00
|
|
|
__attribute__ ((noreturn)) void sysenter_handler(regs *dump)
|
2018-12-12 15:25:04 +01:00
|
|
|
{
|
|
|
|
sti();
|
2018-12-05 16:42:25 +01:00
|
|
|
switch (dump->eax)
|
|
|
|
{
|
2018-12-14 01:06:37 +01:00
|
|
|
case 2:
|
|
|
|
dump->eax=(u32) print(dump->ebx);
|
|
|
|
break;
|
2018-12-19 12:06:05 +01:00
|
|
|
case 0:
|
|
|
|
dump->eax=(u32) testapi(dump->ebx, dump->esi, dump->edi, dump);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
dump->eax=(u32) gettimer();
|
|
|
|
break;
|
2018-12-14 01:06:37 +01:00
|
|
|
case 1:
|
|
|
|
dump->eax=(u32) waitascii();
|
|
|
|
break;
|
2018-12-19 12:06:05 +01:00
|
|
|
case 5:
|
|
|
|
processexit(dump->ebx);
|
2018-12-05 16:42:25 +01:00
|
|
|
break;
|
2018-12-12 15:25:04 +01:00
|
|
|
|
2018-12-14 01:06:37 +01:00
|
|
|
default:
|
2018-12-15 19:13:26 +01:00
|
|
|
printf("Appel syscall vers fonction inexistante en %Y:%Y", dump->cs, dump->eip);
|
2018-12-14 01:06:37 +01:00
|
|
|
break;
|
2018-12-05 16:42:25 +01:00
|
|
|
}
|
2018-12-16 01:50:03 +01:00
|
|
|
//dump->eflags &= ~(1 << 6);
|
|
|
|
dump->eflags |= (1 << 6);
|
|
|
|
setESP(dump);
|
|
|
|
restcpu_user();
|
2018-12-12 15:25:04 +01:00
|
|
|
sysexit();
|
2018-09-18 14:29:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
|