SYSENTER/SYSCALL support

. add cpufeature detection of both
	. use it for both ipc and kernelcall traps, using a register
	  for call number
	. SYSENTER/SYSCALL does not save any context, therefore userland
	  has to save it
	. to accomodate multiple kernel entry/exit types, the entry
	  type is recorded in the process struct. hitherto all types
	  were interrupt (soft int, exception, hard int); now SYSENTER/SYSCALL
	  is new, with the difference that context is not fully restored
	  from proc struct when running the process again. this can't be
	  done as some information is missing.
	. complication: cases in which the kernel has to fully change
	  process context (i.e. sigreturn). in that case the exit type
	  is changed from SYSENTER/SYSEXIT to soft-int (i.e. iret) and
	  context is fully restored from the proc struct. this does mean
	  the PC and SP must change, as the sysenter/sysexit userland code
	  will otherwise try to restore its own context. this is true in the
	  sigreturn case.
	. override all usage by setting libc_ipc=1
This commit is contained in:
Ben Gras
2012-06-10 17:50:17 +00:00
parent 629829e69c
commit 2d72cbec41
38 changed files with 643 additions and 79 deletions

View File

@@ -9,40 +9,40 @@
/* IPC assembly routines * */
/**========================================================================* */
/* all message passing routines save ebx, but destroy eax and ecx. */
ENTRY(_send)
ENTRY(_send_orig)
push %ebp
movl %esp, %ebp
push %ebx
movl SRC_DST(%ebp), %eax /* eax = dest-src */
movl MESSAGE(%ebp), %ebx /* ebx = message pointer */
movl $SEND, %ecx /* _send(dest, ptr) */
int $IPCVEC /* trap to the kernel */
int $IPCVEC_ORIG /* trap to the kernel */
pop %ebx
pop %ebp
ret
ENTRY(_receive)
ENTRY(_receive_orig)
push %ebp
movl %esp, %ebp
push %ebx
movl SRC_DST(%ebp), %eax /* eax = dest-src */
movl MESSAGE(%ebp), %ebx /* ebx = message pointer */
movl $RECEIVE, %ecx /* _receive(src, ptr) */
int $IPCVEC /* trap to the kernel */
int $IPCVEC_ORIG /* trap to the kernel */
movl STATUS(%ebp), %ecx /* ecx = status pointer */
movl %ebx, (%ecx)
pop %ebx
pop %ebp
ret
ENTRY(_sendrec)
ENTRY(_sendrec_orig)
push %ebp
movl %esp, %ebp
push %ebx
movl SRC_DST(%ebp), %eax /* eax = dest-src */
movl MESSAGE(%ebp), %ebx /* ebx = message pointer */
movl $SENDREC, %ecx /* _sendrec(srcdest, ptr) */
int $IPCVEC /* trap to the kernel */
int $IPCVEC_ORIG /* trap to the kernel */
pop %ebx
pop %ebp
ret
@@ -54,38 +54,38 @@ ENTRY(_minix_kernel_info_struct)
movl $0, %eax
movl $0, %ebx
movl $MINIX_KERNINFO, %ecx
int $IPCVEC /* trap to the kernel */
int $IPCVEC_ORIG /* trap to the kernel */
movl 8(%ebp), %ecx /* ecx = return struct ptr */
movl %ebx, (%ecx)
pop %ebx
pop %ebp
ret
ENTRY(_notify)
ENTRY(_notify_orig)
push %ebp
movl %esp, %ebp
push %ebx
movl SRC_DST(%ebp), %eax /* eax = destination */
movl $NOTIFY, %ecx /* _notify(srcdst) */
int $IPCVEC /* trap to the kernel */
int $IPCVEC_ORIG /* trap to the kernel */
pop %ebx
pop %ebp
ret
ENTRY(_sendnb)
ENTRY(_sendnb_orig)
push %ebp
movl %esp, %ebp
push %ebx
movl SRC_DST(%ebp), %eax /* eax = dest-src */
movl MESSAGE(%ebp), %ebx /* ebx = message pointer */
movl $SENDNB, %ecx /* _sendnb(dest, ptr) */
int $IPCVEC /* trap to the kernel */
int $IPCVEC_ORIG /* trap to the kernel */
pop %ebx
pop %ebp
ret
ENTRY(_do_kernel_call)
ENTRY(_do_kernel_call_orig)
/* pass the message pointer to kernel in the %eax register */
movl 4(%esp), %eax
int $KERVEC
int $KERVEC_ORIG
ret

View File

@@ -4,7 +4,7 @@
MSGTAB = 8 /* message table */
TABCOUNT = 12 /* number of entries in message table */
ENTRY(_senda)
ENTRY(_senda_orig)
push %ebp
movl %esp, %ebp
push %ebx

View File

@@ -2,15 +2,29 @@
#include <stdio.h>
#include <minix/ipc.h>
/* Minix kernel info, IPC functions pointers */
struct minix_kerninfo *_minix_kerninfo = NULL;
void __minix_init(void) __attribute__((__constructor__, __used__));
struct minix_ipcvecs _minix_ipcvecs = {
.sendrec_ptr = _sendrec_orig,
.send_ptr = _send_orig,
.notify_ptr = _notify_orig,
.senda_ptr = _senda_orig,
.sendnb_ptr = _sendnb_orig,
.receive_ptr = _receive_orig,
.do_kernel_call_ptr = _do_kernel_call_orig,
};
void __minix_init(void)
{
if((_minix_kernel_info_struct(&_minix_kerninfo)) != 0
|| _minix_kerninfo->kerninfo_magic != KERNINFO_MAGIC) {
_minix_kerninfo = NULL;
}
} else if((_minix_kerninfo->ki_flags & MINIX_KIF_IPCVECS) &&
_minix_kerninfo->minix_ipcvecs) {
_minix_ipcvecs = *_minix_kerninfo->minix_ipcvecs;
}
}

View File

@@ -11,7 +11,7 @@ int _syscall(endpoint_t who, int syscallnr, message *msgptr)
int status;
msgptr->m_type = syscallnr;
status = _sendrec(who, msgptr);
status = sendrec(who, msgptr);
if (status != 0) {
/* 'sendrec' itself failed. */
/* XXX - strerror doesn't know all the codes */

View File

@@ -13,6 +13,7 @@
#include <minix/com.h>
#include <minix/callnr.h>
#include <minix/vm.h>
#include <minix/ipc.h>
#include <minix/syslib.h>
#include <sys/mman.h>
#include <machine/elf.h>

View File

@@ -3,10 +3,14 @@
#include <minix/minlib.h>
#include <minix/cpufeature.h>
#include <machine/vm.h>
#include <string.h>
int _cpufeature(int cpufeature)
{
u32_t eax, ebx, ecx, edx;
u32_t ef_eax = 0, ef_ebx = 0, ef_ecx = 0, ef_edx = 0;
unsigned int family, model, stepping;
int is_intel = 0, is_amd = 0;
eax = ebx = ecx = edx = 0;
@@ -14,8 +18,34 @@ int _cpufeature(int cpufeature)
eax = 0;
_cpuid(&eax, &ebx, &ecx, &edx);
if(eax > 0) {
char vendor[12];
memcpy(vendor, &ebx, sizeof(ebx));
memcpy(vendor+4, &edx, sizeof(edx));
memcpy(vendor+8, &ecx, sizeof(ecx));
if(!strncmp(vendor, "GenuineIntel", sizeof(vendor)))
is_intel = 1;
if(!strncmp(vendor, "AuthenticAMD", sizeof(vendor)))
is_amd = 1;
eax = 1;
_cpuid(&eax, &ebx, &ecx, &edx);
} else return 0;
stepping = eax & 0xf;
model = (eax >> 4) & 0xf;
if(model == 0xf || model == 0x6) {
model += ((eax >> 16) & 0xf) << 4;
}
family = (eax >> 8) & 0xf;
if(family == 0xf) {
family += (eax >> 20) & 0xff;
}
if(is_amd) {
ef_eax = 0x80000001;
_cpuid(&ef_eax, &ef_ebx, &ef_ecx, &ef_edx);
}
switch(cpufeature) {
@@ -53,6 +83,15 @@ int _cpufeature(int cpufeature)
return edx & CPUID1_EDX_HTT;
case _CPUF_I386_HTT_MAX_NUM:
return (ebx >> 16) & 0xff;
case _CPUF_I386_SYSENTER:
if(!is_intel) return 0;
if(!(edx & CPUID1_EDX_SYSENTER)) return 0;
if(family == 6 && model < 3 && stepping < 3) return 0;
return 1;
case _CPUF_I386_SYSCALL:
if(!is_amd) return 0;
if(!(ef_edx & CPUID_EF_EDX_SYSENTER)) return 0;
return 1;
}
return 0;

View File

@@ -4,6 +4,6 @@
int _kernel_call(int syscallnr, message *msgptr)
{
msgptr->m_type = syscallnr;
_do_kernel_call(msgptr);
do_kernel_call(msgptr);
return(msgptr->m_type);
}

View File

@@ -14,7 +14,7 @@ register message *msgptr;
int status;
msgptr->m_type = syscallnr;
status = _sendrec(who, msgptr);
status = sendrec(who, msgptr);
if (status != 0) return(status);
return(msgptr->m_type);
}