feat: ajout de wrappers pour SYSENTER et pour toutes les exceptions. Génération automatique des API par métadonnées dans le source.

This commit is contained in:
Nicolas Hordé 2018-12-16 01:50:03 +01:00
parent 3c3f0bb88e
commit 0af99c069b
12 changed files with 337 additions and 275 deletions

View File

@ -2,7 +2,7 @@
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */ /* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
/* */ /* */
#include "types.h" #include "types.h"
__attribute__ ((noreturn)) void exception_handler(regs *dump);
__attribute__((interrupt)) void interruption(exception_stack_noerror *caller); __attribute__((interrupt)) void interruption(exception_stack_noerror *caller);
void exception0(); void exception0();
void exception1(); void exception1();

View File

@ -48,15 +48,10 @@
/* fréquence pour timer dans un PC ou AT */ /* fréquence pour timer dans un PC ou AT */
# define HZ 100 /* Fréquence d'horloge (ajutste logiciellement sur IBM-PC) */ # define HZ 100 /* Fréquence d'horloge (ajutste logiciellement sur IBM-PC) */
# define getESP(mem) ({ \ # define setESP(mem) ({ \
asm volatile ("movl %%esp,%[tomem];":: [tomem] "m" (mem)); \ asm volatile ("movl %[frommem],%%esp;":[frommem] "=m" (mem):); \
}) })
# define getEBP(mem) ({ \
asm volatile ("movl %%ebp,%[tomem];":: [tomem] "m" (mem)); \
})
# define savecpu(dump,caller,oldesp) ({\ # define savecpu(dump,caller,oldesp) ({\
getEBP(oldesp);\ getEBP(oldesp);\
dumpcpu();\ dumpcpu();\
@ -168,24 +163,18 @@
pushl %%eax":::);\ pushl %%eax":::);\
}) })
# define restcpu() ({\ # define restcpu_kernel() ({\
asm("\ asm("\
popl %%eax \n \ popl %%eax \n \
popl %%edx \n \ popl %%edx \n \
mov $0xC0000080, %%ecx \n \ mov $0xC0000080, %%ecx \n \
wrmsr\n \ wrmsr\n \
popl %%eax\n \ popl %%eax\n \
mov %%eax,%%dr7 \n \
popl %%eax \n \ popl %%eax \n \
mov %%eax,%%dr6 \n \
popl %%eax \n \ popl %%eax \n \
mov %%eax,%%dr3 \n \
popl %%eax \n \ popl %%eax \n \
mov %%eax,%%dr2 \n \
popl %%eax \n \ popl %%eax \n \
mov %%eax,%%dr1 \n \
popl %%eax \n \ popl %%eax \n \
mov %%eax,%%dr0 \n \
popl %%eax \n \ popl %%eax \n \
popl %%eax \n \ popl %%eax \n \
mov %%eax,%%cr3 \n \ mov %%eax,%%cr3 \n \
@ -196,15 +185,26 @@
popl %%esi\n \ popl %%esi\n \
popl %%edx\n \ popl %%edx\n \
popl %%ecx\n \ popl %%ecx\n \
mov 36(%%esp),%%eax\n \
mov 32(%%esp),%%ebx\n \
mov %%ebx,-4(%%eax)\n \
mov 28(%%esp),%%ebx\n \
mov %%ebx,-8(%%eax)\n \
mov 24(%%esp),%%ebx\n \
mov %%ebx,-12(%%eax)\n \
popl %%ebx\n \ popl %%ebx\n \
popl %%eax\n \ popl %%eax\n \
popl %%gs\n \ popl %%gs\n \
popl %%fs\n \ popl %%fs\n \
popl %%es\n \ popl %%es\n \
popl %%ds\n \"::);\ popl %%ds\n \
add $12,%%esp\n \
popl %%esp\n \
sub $12,%%esp\n \
iret ":::);\
}) })
# define restdebugcpu() ({\ # define restcpu_user() ({\
asm("\ asm("\
popl %%eax \n \ popl %%eax \n \
popl %%edx \n \ popl %%edx \n \
@ -234,6 +234,7 @@
popl %%ds":::);\ popl %%ds":::);\
}) })
/* /*
lors d'un iret en mode user: lors d'un iret en mode user:
pushl %%ss\n \ pushl %%ss\n \

View File

@ -47,4 +47,5 @@
/* Vers 6 arguments maximum */ /* Vers 6 arguments maximum */
void initsyscall(void); void initsyscall(void);
__attribute__ ((noreturn)) void sysenter_handler(void); __attribute__ ((noreturn)) void sysenter_handler(regs *dump);

View File

@ -22,156 +22,6 @@ __attribute__((interrupt)) void interruption(exception_stack_noerror *caller)
/******************************************************************************/ /******************************************************************************/
/* Les expections */ /* Les expections */
void exception0()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#DE Divide error", dump, false);
}
void exception1()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
changevc(6);
clearscreen();
show_lightcpu(dump);
printf("\r\n\033[7m[P]\033[0m PAS A PAS \033[7m D \033[0m PAS A PAS DETAILLE \033[7m C \033[0m CONTINUER \033[7m S \033[0m STOPPER \033[7m V \033[0m VOIR \033[7m S \033[0m SCINDER");
sti();
u8 ascii = waitascii();
cli();
if (ascii == 'P' || ascii == 'p')
setdebugreg(0,
caller->eip + disasm(caller->eip, NULL, false),
DBG_EXEC);
else if (ascii == 'D' || ascii == 'd')
setdebugreg(0, 0, DBG_CLEAR);
else if (ascii == 'C' || ascii == 'c')
setdebugreg(0, 0, DBG_CLEAR);
else if (ascii == 'S' || ascii == 's')
{
changevc(0);
sti();
initselectors(getinitretry());
}
changevc(0);
restdebugcpu();
iret();
}
void exception2()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("NMI Non-maskable hardware interrupt", dump, false);
}
void exception3()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#BP INT3 instruction", dump, true);
iret();
}
void exception4()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#OF INTO instruction detected overflow", dump, false);
}
void exception5()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#BR BOUND instruction detected overrange", dump, false);
}
void exception6()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#UD Invalid instruction opcode", dump, false);
}
void exception7()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#NM No coprocessor", dump, false);
}
void exception8()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#DF Double fault", dump, false);
}
void exception9()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("Coprocessor segment overrun", dump, false);
}
void exception10()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#TS Invalid task state segment (TSS)", dump, false);
}
void exception11()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#NP Segment not present", dump, false);
}
void exception12()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu_noerror(dump, caller, oldesp);
cpuerror("#SS Stack fault", dump, false);
}
void exception13()
{
regs *dump;
exception_stack_noerror *caller;
u32 *oldesp;
savecpu(dump, caller, oldesp);
cpuerror("#GP General protection fault (GPF)", dump, false);
}
static u8 ex14_errors1[] = static u8 ex14_errors1[] =
"Supervisory process tried to read a non-present page entry"; "Supervisory process tried to read a non-present page entry";
static u8 ex14_errors2[] = static u8 ex14_errors2[] =
@ -193,75 +43,135 @@ static u8 *ex14_errors[] =
&ex14_errors5, &ex14_errors6, &ex14_errors7, &ex14_errors8 &ex14_errors5, &ex14_errors6, &ex14_errors7, &ex14_errors8
}; };
void exception14() __attribute__ ((noreturn)) void exception_handler(regs *dump)
{ {
regs *dump; u32 exception=dump->eip;
exception_stack *caller; exception_stack_noerror *caller = (exception_stack_noerror*) ((u32*)dump->esp+1);
u32 *oldesp; bool noerror,user;
getEBP(oldesp); if (caller->cs==SEL_KERNEL_CODE || caller->cs==SEL_USER_CODE)
dumpcpu();
getESP(dump);
dump->ebp = *oldesp;
dump->eip = caller->eip;
dump->cs = caller->cs;
if (caller->cs == SEL_KERNEL_CODE)
dump->esp = (u32) oldesp + sizeof(exception_stack);
else
{ {
dump->esp = (u32) ((exception_stack_user *) caller)->esp; noerror=true;
dump->ss = (u32) ((exception_stack_user *) caller)->ss; dump->eip = caller->eip;
} dump->cs = caller->cs;
if (dump->cr2 >= USER_CODE && dump->cr2 < USER_STACK) dump->eflags = caller->eflags;
{ if (dump->cs==SEL_KERNEL_CODE)
virtual_range_new(getcurrentprocess()->pdd, {
(u8 *) (dump->cr2 & 0xFFFFF000), dump->esp = (u32) caller + sizeof(exception_stack_noerror);
PAGESIZE, PAGE_ALL); user=false;
}
else
{
dump->esp = (u32) ((exception_stack_noerror_user*) caller)->esp;
dump->ss = (u32) ((exception_stack_noerror_user*) caller)->ss;
user=true;
}
} }
else else
{ {
printf("Page fault - %s at adress %Y cs:eip - %Y:%Y\r\n", noerror=false;
ex14_errors[caller->error_code & 0xF], dump->cr2, dump->eip = ((exception_stack*)caller)->eip;
dump->cs, dump->eip); dump->cs = ((exception_stack*)caller)->cs;
cpuerror("#PGF Page fault", dump, false); if (dump->cs==SEL_KERNEL_CODE)
{
dump->esp = (u32) caller + sizeof(exception_stack);
user=false;
}
else
{
dump->esp = (u32) ((exception_stack_user*) caller)->esp;
dump->ss = (u32) ((exception_stack_user*) caller)->ss;
user=true;
}
} }
restdebugcpu(); switch (exception)
iret(); {
} case 0:
cpuerror("#DE Divide error", dump, false);
void exception15() case 1:
{ changevc(6);
regs *dump; clearscreen();
exception_stack_noerror *caller; show_lightcpu(dump);
u32 *oldesp; printf("\r\n\033[7m[P]\033[0m PAS A PAS \033[7m D \033[0m PAS A PAS DETAILLE \033[7m C \033[0m CONTINUER \033[7m S \033[0m STOPPER \033[7m V \033[0m VOIR \033[7m S \033[0m SCINDER");
savecpu_noerror(dump, caller, oldesp); sti();
cpuerror("(reserved)", dump, false); u8 ascii = waitascii();
} cli();
if (ascii == 'P' || ascii == 'p')
void exception16() setdebugreg(0,
{ caller->eip + disasm(caller->eip, NULL, false),
regs *dump; DBG_EXEC);
exception_stack_noerror *caller; else if (ascii == 'D' || ascii == 'd')
u32 *oldesp; setdebugreg(0, 0, DBG_CLEAR);
savecpu_noerror(dump, caller, oldesp); else if (ascii == 'C' || ascii == 'c')
cpuerror("#MF Coprocessor error", dump, false); setdebugreg(0, 0, DBG_CLEAR);
} else if (ascii == 'S' || ascii == 's')
{
void exception17() changevc(0);
{ sti();
regs *dump; initselectors(getinitretry());
exception_stack_noerror *caller; }
u32 *oldesp; changevc(0);
savecpu_noerror(dump, caller, oldesp); goto endofexception;
cpuerror("#AC Alignment check", dump, false); case 2:
} cpuerror("NMI Non-maskable hardware interrupt", dump, false);
case 3:
void exception18() cpuerror("#BP INT3 instruction", dump, true);
{ iret();
regs *dump; case 4:
exception_stack_noerror *caller; cpuerror("#OF INTO instruction detected overflow", dump, false);
u32 *oldesp; case 5:
savecpu_noerror(dump, caller, oldesp); cpuerror("#BR BOUND instruction detected overrange", dump, false);
cpuerror("#MC Machine check", dump, false); case 6:
cpuerror("#UD Invalid instruction opcode", dump, false);
case 7:
cpuerror("#NM No coprocessor", dump, false);
case 8:
cpuerror("#DF Double fault", dump, false);
case 9:
cpuerror("Coprocessor segment overrun", dump, false);
case 10:
cpuerror("#TS Invalid task state segment (TSS)", dump, false);
case 11:
cpuerror("#NP Segment not present", dump, false);
case 12:
cpuerror("#SS Stack fault", dump, false);
case 13:
cpuerror("#GP General protection fault (GPF)", dump, false);
case 14:
if (dump->cr2 >= USER_CODE && dump->cr2 < USER_STACK)
{
virtual_range_new(getcurrentprocess()->pdd,
(u8 *) (dump->cr2 & 0xFFFFF000),
PAGESIZE, PAGE_ALL);
}
else
{
printf("Page fault - %s at adress %Y cs:eip - %Y:%Y\r\n",
ex14_errors[((exception_stack*) caller)->error_code & 0xF], dump->cr2,
dump->cs, dump->eip);
cpuerror("#PGF Page fault", dump, false);
}
goto endofexception;
case 15:
cpuerror("(reserved)", dump, false);
case 16:
cpuerror("#MF Coprocessor error", dump, false);
case 17:
cpuerror("#AC Alignment check", dump, false);
case 18:
cpuerror("#MC Machine check", dump, false);
}
endofexception:
if (dump->cs==SEL_KERNEL_CODE)
{
setESP(dump);
restcpu_kernel();
}
else
{
setESP(dump);
restcpu_user();
iret();
}
} }
/******************************************************************************/ /******************************************************************************/

120
lib/handlers_asm.S Normal file
View File

@ -0,0 +1,120 @@
/*******************************************************************************/
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
/* */
.section .text
.macro exception num
.global wrapper_exception\num
wrapper_exception\num:
pushl %ss
pushl %esp
pushf
pushl %cs
pushl $\num
jmp dumpcpu
.endm
exception 0
exception 1
exception 2
exception 3
exception 4
exception 5
exception 6
exception 7
exception 8
exception 9
exception 10
exception 11
exception 12
exception 13
exception 14
exception 15
exception 16
exception 17
exception 18
.global wrapper_sysenter
wrapper_sysenter:
pushl %ss
pushl %esp
pushf
pushl %cs
pushl $0x00
pushl %ds
pushl %es
pushl %fs
pushl %gs
pushl %eax
pushl %ebx
pushl %ecx
pushl %edx
pushl %esi
pushl %edi
pushl %ebp
mov %cr0, %eax
pushl %eax
mov %cr2, %eax
pushl %eax
mov %cr3, %eax
pushl %eax
mov %cr4, %eax
pushl %eax
mov %dr0, %eax
pushl %eax
mov %dr1, %eax
pushl %eax
mov %dr2, %eax
pushl %eax
mov %dr3, %eax
pushl %eax
mov %dr6, %eax
pushl %eax
mov %dr7, %eax
pushl %eax
mov $0xC0000080, %ecx
rdmsr
pushl %edx
pushl %eax
pushl %esp
call sysenter_handler
dumpcpu:
pushl %ds
pushl %es
pushl %fs
pushl %gs
pushl %eax
pushl %ebx
pushl %ecx
pushl %edx
pushl %esi
pushl %edi
pushl %ebp
mov %cr0, %eax
pushl %eax
mov %cr2, %eax
pushl %eax
mov %cr3, %eax
pushl %eax
mov %cr4, %eax
pushl %eax
mov %dr0, %eax
pushl %eax
mov %dr1, %eax
pushl %eax
mov %dr2, %eax
pushl %eax
mov %dr3, %eax
pushl %eax
mov %dr6, %eax
pushl %eax
mov %dr7, %eax
pushl %eax
mov $0xC0000080, %ecx
rdmsr
pushl %edx
pushl %eax
pushl %esp
call exception_handler

View File

@ -22,6 +22,25 @@ static idtdes idt[IDT_SIZE];
static u32 retry_address; static u32 retry_address;
extern wrapper_exception0;
extern wrapper_exception1;
extern wrapper_exception2;
extern wrapper_exception3;
extern wrapper_exception4;
extern wrapper_exception5;
extern wrapper_exception6;
extern wrapper_exception7;
extern wrapper_exception8;
extern wrapper_exception9;
extern wrapper_exception10;
extern wrapper_exception11;
extern wrapper_exception12;
extern wrapper_exception13;
extern wrapper_exception14;
extern wrapper_exception15;
extern wrapper_exception16;
extern wrapper_exception17;
extern wrapper_exception18;
/******************************************************************************/ /******************************************************************************/
/* Initialise la reprise après erreur */ /* Initialise la reprise après erreur */
@ -149,43 +168,43 @@ void putidt(u32 offset, u16 select, u16 type, u16 index)
void initidt(void) void initidt(void)
{ {
u16 i; u16 i;
putidt((u32) exception0, SEL_KERNEL_CODE, putidt((u32) &wrapper_exception0, SEL_KERNEL_CODE,
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 0); ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 0);
putidt((u32) exception1, SEL_KERNEL_CODE, putidt((u32) &wrapper_exception1, SEL_KERNEL_CODE,
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 1); ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 1);
putidt((u32) exception2, SEL_KERNEL_CODE, putidt((u32) &wrapper_exception2, SEL_KERNEL_CODE,
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 2); ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 2);
putidt((u32) exception3, SEL_KERNEL_CODE, putidt((u32) &wrapper_exception3, SEL_KERNEL_CODE,
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 3); ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 3);
putidt((u32) exception4, SEL_KERNEL_CODE, putidt((u32) &wrapper_exception4, SEL_KERNEL_CODE,
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 4); ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 4);
putidt((u32) exception5, SEL_KERNEL_CODE, putidt((u32) &wrapper_exception5, SEL_KERNEL_CODE,
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 5); ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 5);
putidt((u32) exception6, SEL_KERNEL_CODE, putidt((u32) &wrapper_exception6, SEL_KERNEL_CODE,
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 6); ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 6);
putidt((u32) exception7, SEL_KERNEL_CODE, putidt((u32) &wrapper_exception7, SEL_KERNEL_CODE,
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 7); ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 7);
putidt((u32) exception8, SEL_KERNEL_CODE, putidt((u32) &wrapper_exception8, SEL_KERNEL_CODE,
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 8); ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 8);
putidt((u32) exception9, SEL_KERNEL_CODE, putidt((u32) &wrapper_exception9, SEL_KERNEL_CODE,
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 9); ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 9);
putidt((u32) exception10, SEL_KERNEL_CODE, putidt((u32) &wrapper_exception10, SEL_KERNEL_CODE,
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 10); ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 10);
putidt((u32) exception11, SEL_KERNEL_CODE, putidt((u32) &wrapper_exception11, SEL_KERNEL_CODE,
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 11); ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 11);
putidt((u32) exception12, SEL_KERNEL_CODE, putidt((u32) &wrapper_exception12, SEL_KERNEL_CODE,
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 12); ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 12);
putidt((u32) exception13, SEL_KERNEL_CODE, putidt((u32) &wrapper_exception13, SEL_KERNEL_CODE,
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 13); ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 13);
putidt((u32) exception14, SEL_KERNEL_CODE, putidt((u32) &wrapper_exception14, SEL_KERNEL_CODE,
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 14); ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 14);
putidt((u32) exception15, SEL_KERNEL_CODE, putidt((u32) &wrapper_exception15, SEL_KERNEL_CODE,
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 15); ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 15);
putidt((u32) exception16, SEL_KERNEL_CODE, putidt((u32) &wrapper_exception16, SEL_KERNEL_CODE,
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 16); ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 16);
putidt((u32) exception17, SEL_KERNEL_CODE, putidt((u32) &wrapper_exception17, SEL_KERNEL_CODE,
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 17); ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 17);
putidt((u32) exception18, SEL_KERNEL_CODE, putidt((u32) &wrapper_exception18, SEL_KERNEL_CODE,
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 18); ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 18);
for (i = 19; i < 32; i++) for (i = 19; i < 32; i++)
{ {

View File

@ -1,7 +1,10 @@
CC=gcc -O0 -g -nostdinc -ffreestanding -fno-builtin -Wall -w -m32 -F elf_i386 -fno-pie -no-pie -I ../include -c CC=gcc -O0 -g -nostdinc -ffreestanding -fno-builtin -Wall -w -m32 -F elf_i386 -fno-pie -no-pie -I ../include -c
ASM=gcc -nostdinc -ffreestanding -fno-builtin -m32 -c -fno-pie -no-pie
LINK=ld -m elf_i386 -r -o LINK=ld -m elf_i386 -r -o
SRCS= $(wildcard *.c) SRCS= $(wildcard *.c)
OBJS= $(SRCS:.c=.o) OBJS= $(SRCS:.c=.o)
SRCASM= $(wildcard *.S)
OBJASM= $(SRCASM:.S=.o)
CONVERT=dos2unix CONVERT=dos2unix
INDENT=indent -nhnl -l75 -ppi3 -ts8 -bls -nbc -di8 -nbad -nbap -nsob -i8 -bl -bli0 -ncdw -nce -cli8 -cbi0 -npcs -cs -saf -sai -saw -nprs -lp -npsl INDENT=indent -nhnl -l75 -ppi3 -ts8 -bls -nbc -di8 -nbad -nbap -nsob -i8 -bl -bli0 -ncdw -nce -cli8 -cbi0 -npcs -cs -saf -sai -saw -nprs -lp -npsl
REMOVE=rm -f REMOVE=rm -f
@ -12,8 +15,11 @@ all: libs.o
togit: clean indent togit: clean indent
libs.o:$(OBJS) libs.o:$(OBJS) $(OBJASM)
$(LINK) libs.o $(OBJS) $(LINK) libs.o $(OBJS) $(OBJASM)
.o: .S
$(ASM) $^
handlers.o:handlers.c handlers.o:handlers.c
$(CC) -mgeneral-regs-only $^ $(CC) -mgeneral-regs-only $^

View File

@ -235,7 +235,10 @@ void task_switch(u32 pid, bool fromkernelmode)
setTSS(0x0, 0x0); setTSS(0x0, 0x0);
current->dump.eflags = (current->dump.eflags | 0x200) & 0xFFFFBFFF; current->dump.eflags = (current->dump.eflags | 0x200) & 0xFFFFBFFF;
createdump(current->dump); createdump(current->dump);
restdebugcpu(); if (current->dump.cs==SEL_KERNEL_CODE)
restcpu_kernel();
else
restcpu_user();
iret(); iret();
} }

View File

@ -17,6 +17,8 @@
* %esi Arg2 * %esi Arg2
* %edi Arg3*/ * %edi Arg3*/
extern wrapper_sysenter;
/*******************************************************************************/ /*******************************************************************************/
/* Initialise les appels système par SYSENTER/SYSEXIT */ /* Initialise les appels système par SYSENTER/SYSEXIT */
@ -24,7 +26,8 @@ void initsyscall(void)
{ {
wrmsr(0x174, SEL_KERNEL_CODE, 0x0); wrmsr(0x174, SEL_KERNEL_CODE, 0x0);
wrmsr(0x175, 0x60000, 0x0); wrmsr(0x175, 0x60000, 0x0);
wrmsr(0x176, &sysenter_handler, 0x0); wrmsr(0x176, &wrapper_sysenter, 0x0);
return;
} }
/*******************************************************************************/ /*******************************************************************************/
@ -54,15 +57,8 @@ u32 testapi(u32 arg1, u32 arg2, u32 arg3, regs* dump)
/*******************************************************************************/ /*******************************************************************************/
/* Entrée pour les appels système SYSENTER */ /* Entrée pour les appels système SYSENTER */
__attribute__ ((noreturn)) void sysenter_handler(regs *dump)
__attribute__ ((noreturn)) void sysenter_handler(void)
{ {
cli();
regs *dump;
dumpcpu();
getESP(dump);
dump->cs=SEL_USER_CODE;
dump->eip=dump->edx;
sti(); sti();
switch (dump->eax) switch (dump->eax)
{ {
@ -86,7 +82,10 @@ __attribute__ ((noreturn)) void sysenter_handler(void)
printf("Appel syscall vers fonction inexistante en %Y:%Y", dump->cs, dump->eip); printf("Appel syscall vers fonction inexistante en %Y:%Y", dump->cs, dump->eip);
break; break;
} }
restdebugcpu(); //dump->eflags &= ~(1 << 6);
dump->eflags |= (1 << 6);
setESP(dump);
restcpu_user();
sysexit(); sysexit();
} }

View File

@ -9,6 +9,11 @@ bits64: ARCH=bits64
bits64: lib/libs.o system/system.sys bits64: lib/libs.o system/system.sys
sync sync
syscall: clean remakeapi all
remakeapi:
python makesyscall.py
programs: programs/test lib/TEST/test.c programs: programs/test lib/TEST/test.c
lib/TEST/test.c: lib/TEST/test.c:

View File

@ -8,8 +8,8 @@
void main(void) void main(void)
{ {
//u32 result = testapi(0x1234,0x88888888,0x2505); u32 result = testapi(0x1234,0x88888888,0x2505);
print("ceci est un test d'appel"); print("ceci est un test d'appel");
waitkey(); waitkey();
//exit(result); exit(result);
} }

View File

@ -17,6 +17,8 @@
* %esi Arg2 * %esi Arg2
* %edi Arg3*/ * %edi Arg3*/
extern wrapper_sysenter;
/*******************************************************************************/ /*******************************************************************************/
/* Initialise les appels système par SYSENTER/SYSEXIT */ /* Initialise les appels système par SYSENTER/SYSEXIT */
@ -24,7 +26,7 @@ void initsyscall(void)
{ {
wrmsr(0x174, SEL_KERNEL_CODE, 0x0); wrmsr(0x174, SEL_KERNEL_CODE, 0x0);
wrmsr(0x175, 0x60000, 0x0); wrmsr(0x175, 0x60000, 0x0);
wrmsr(0x176, &sysenter_handler, 0x0); wrmsr(0x176, &wrapper_sysenter, 0x0);
return; return;
} }
@ -55,15 +57,8 @@ u32 testapi(u32 arg1, u32 arg2, u32 arg3, regs* dump)
/*******************************************************************************/ /*******************************************************************************/
/* Entrée pour les appels système SYSENTER */ /* Entrée pour les appels système SYSENTER */
__attribute__ ((noreturn)) void sysenter_handler(regs *dump)
__attribute__ ((noreturn)) void sysenter_handler(void)
{ {
cli();
regs *dump;
dumpcpu();
getESP(dump);
dump->cs=SEL_USER_CODE;
dump->eip=dump->edx;
sti(); sti();
switch (dump->eax) switch (dump->eax)
{ {
@ -72,7 +67,10 @@ __attribute__ ((noreturn)) void sysenter_handler(void)
printf("Appel syscall vers fonction inexistante en %Y:%Y", dump->cs, dump->eip); printf("Appel syscall vers fonction inexistante en %Y:%Y", dump->cs, dump->eip);
break; break;
} }
restdebugcpu(); //dump->eflags &= ~(1 << 6);
dump->eflags |= (1 << 6);
setESP(dump);
restcpu_user();
sysexit(); sysexit();
} }