Author: tkreuzer Date: Wed Jul 23 17:00:43 2008 New Revision: 34700
URL: http://svn.reactos.org/svn/reactos?rev=34700&view=rev Log: Make ncitool create syscall stubs for amd64. We use the same as for x86 for now.
Modified: branches/ros-amd64-bringup/reactos/tools/nci/ncitool.c
Modified: branches/ros-amd64-bringup/reactos/tools/nci/ncitool.c URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/tools/... ============================================================================== --- branches/ros-amd64-bringup/reactos/tools/nci/ncitool.c [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/tools/nci/ncitool.c [iso-8859-1] Wed Jul 23 17:00:43 2008 @@ -4,7 +4,7 @@ * PROJECT: Native Call Interface Support Tool * PURPOSE: Generates NCI Tables and Stubs. * PROGRAMMER; Alex Ionescu (alex@relsoft.net) - * CHANGE HISTORY: 14/01/05 - Created. Based on original code by + * CHANGE HISTORY: 14/01/05 - Created. Based on original code by * KJK::Hyperion and Emanuelle Aliberti. * */ @@ -44,9 +44,9 @@ /********** Stub Code ************/
/* - * This stubs calls into KUSER_SHARED_DATA where either a + * This stubs calls into KUSER_SHARED_DATA where either a * sysenter or interrupt is performed, depending on CPU support. - */ + */ #if defined(__GNUC__) #define UserModeStub_x86 " movl $0x%x, %%eax\n" \ " movl $KUSER_SHARED_SYSCALL, %%ecx\n" \ @@ -84,7 +84,7 @@
/* * This stub calls KiSystemService directly with a fake INT2E stack. - * Because EIP is pushed during the call, the handler will return here. + * Because EIP is pushed during the call, the handler will return here. */ #if defined(__GNUC__) #define KernelModeStub_x86 " movl $0x%x, %%eax\n" \ @@ -129,6 +129,8 @@
struct ncitool_data_t ncitool_data[] = { { "i386", 4, KernelModeStub_x86, UserModeStub_x86, + ".global _%s@%d\n", "_%s@%d:\n" }, + { "amd64", 4, KernelModeStub_x86, UserModeStub_x86, ".global _%s@%d\n", "_%s@%d:\n" }, { "powerpc", 4, KernelModeStub_ppc, UserModeStub_ppc, "\t.globl %s\n", "%s:\n" }, @@ -148,7 +150,7 @@ /* FUNCTIONS ****************************************************************/
/*++ - * WriteFileHeader + * WriteFileHeader * * Prints out the File Header for a Stub File. * @@ -166,7 +168,7 @@ * FileLocation is only used for printing the header. * *--*/ -void +void WriteFileHeader(FILE * StubFile, char* FileDescription, char* FileLocation) @@ -185,7 +187,7 @@ }
/*++ - * WriteFileHeader + * WriteFileHeader * * Prints out the File Header for a Stub File. * @@ -203,21 +205,21 @@ * FileLocation is only used for printing the header. * *--*/ -void -WriteStubHeader(FILE* StubFile, - char* SyscallName, +void +WriteStubHeader(FILE* StubFile, + char* SyscallName, unsigned StackBytes) { /* Export the function */ fprintf(StubFile, GlobalHeader, SyscallName, StackBytes); - + /* Define it */ fprintf(StubFile, Declaration, SyscallName, StackBytes); }
- + /*++ - * WriteKernelModeStub + * WriteKernelModeStub * * Prints out the Kernel Mode Stub for a System Call. * @@ -237,12 +239,12 @@ * On i386, StackBytes is the number of arguments x 4. * *--*/ -void -WriteKernelModeStub(FILE* StubFile, - char* SyscallName, +void +WriteKernelModeStub(FILE* StubFile, + char* SyscallName, unsigned StackBytes, unsigned int SyscallId) -{ +{ /* Write the Stub Header and export the Function */ WriteStubHeader(StubFile, SyscallName, StackBytes);
@@ -251,7 +253,7 @@ }
/*++ - * WriteUserModeStub + * WriteUserModeStub * * Prints out the User Mode Stub for a System Call. * @@ -271,12 +273,12 @@ * On i386, StackBytes is the number of arguments x 4. * *--*/ -void -WriteUserModeStub(FILE* StubFile, - char* SyscallName, +void +WriteUserModeStub(FILE* StubFile, + char* SyscallName, unsigned StackBytes, unsigned int SyscallId) -{ +{ /* Write the Stub Header and export the Function */ WriteStubHeader(StubFile, SyscallName, StackBytes);
@@ -285,7 +287,7 @@ }
/*++ - * GetNameAndArgumentsFromDb + * GetNameAndArgumentsFromDb * * Parses an entry from a System Call Database, extracting * the function's name and arguments that it takes. @@ -305,23 +307,23 @@ * On i386, StackBytes is the number of arguments x 4. * *--*/ -void +void GetNameAndArgumentsFromDb(char Line[], char ** NtSyscallName, char ** SyscallArguments) { char *s; char *stmp; - + /* Remove new line */ if ((s = (char *) strchr(Line,'\r')) != NULL) { *s = '\0'; } - + /* Skip comments (#) and empty lines */ s = &Line[0]; if ((*s) != '#' && (*s) != '\0') { - + /* Extract the NtXXX name */ *NtSyscallName = (char *)strtok(s," \t");
@@ -332,9 +334,9 @@ if ((stmp = strchr(*SyscallArguments, '\n')) != NULL) { *stmp = '\0'; } - + } else { - + /* Skip this entry */ *NtSyscallName = NULL; *SyscallArguments = NULL; @@ -342,7 +344,7 @@ }
/*++ - * CreateStubs + * CreateStubs * * Parses a System Call Database and creates stubs for all the entries. * @@ -379,28 +381,28 @@ char *SyscallArguments; int SyscallId; unsigned StackBytes; - + /* We loop, incrementing the System Call Index, until the end of the file */ for (SyscallId = 0; ((!feof(SyscallDb)) && (fgets(Line, sizeof(Line), SyscallDb) != NULL));) { - + /* Extract the Name and Arguments */ - GetNameAndArgumentsFromDb(Line, &NtSyscallName, &SyscallArguments); + GetNameAndArgumentsFromDb(Line, &NtSyscallName, &SyscallArguments); if (SyscallArguments != NULL) StackBytes = ARGS_TO_BYTES(strtoul(SyscallArguments, NULL, 0)); else StackBytes = 0; - + /* Make sure we really extracted something */ if (NtSyscallName) { - + /* Create Usermode Stubs for Nt/Zw syscalls in each Usermode file */ int i; for (i= 0; i < UserFiles; i++) { - + /* Write the Nt Version */ - WriteUserModeStub(UserModeFiles[i], - NtSyscallName, - StackBytes, + WriteUserModeStub(UserModeFiles[i], + NtSyscallName, + StackBytes, SyscallId | Index);
/* If a Zw Version is needed (was specified), write it too */ @@ -426,7 +428,7 @@ StackBytes, SyscallId | Index); } - + /* Only increase if we actually added something */ SyscallId++; } @@ -434,7 +436,7 @@ }
/*++ - * CreateSystemServiceTable + * CreateSystemServiceTable * * Parses a System Call Database and creates a System Call Service Table for it. * @@ -455,7 +457,7 @@ * *--*/ void -CreateSystemServiceTable(FILE *SyscallDb, +CreateSystemServiceTable(FILE *SyscallDb, FILE *SyscallTable, char * Name, char * FileLocation) @@ -477,21 +479,21 @@
/* Extract the Name and Arguments */ GetNameAndArgumentsFromDb(Line, &NtSyscallName, &SyscallArguments); - + /* Make sure we really extracted something */ if (NtSyscallName) { - + /* Add a new line */ if (SyscallId > 0) fprintf(SyscallTable,",\n"); - + /* Write the syscall name in the service table. */ fprintf(SyscallTable,"\t\t(ULONG_PTR)%s", NtSyscallName); - + /* Only increase if we actually added something */ SyscallId++; } } - + /* Close the service table (C syntax) */ fprintf(SyscallTable,"\n};\n");
@@ -504,24 +506,24 @@
/* Extract the Name and Arguments */ GetNameAndArgumentsFromDb(Line, &NtSyscallName, &SyscallArguments); - + /* Make sure we really extracted something */ if (NtSyscallName) { - + /* Add a new line */ if (SyscallId > 0) fprintf(SyscallTable,",\n"); - + /* Write the syscall arguments in the argument table. */ if (SyscallArguments != NULL) fprintf(SyscallTable,"\t\t%lu * sizeof(void *)",strtoul(SyscallArguments, NULL, 0)); else fprintf(SyscallTable,"\t\t0"); - + /* Only increase if we actually added something */ SyscallId++; } } - + /* Close the service table (C syntax) */ fprintf(SyscallTable,"\n};\n");
@@ -574,14 +576,14 @@ usage(argv[0]); return(1); } - + /* Open all Output and bail out if any fail */ for (FileNumber = 0; FileNumber < Arguments; FileNumber++) { - + /* Open the File */ if (FileNumber == 2) OpenType = "wb"; Files[FileNumber] = fopen(argv[FileNumber + ArgOffset], OpenType); - + /* Check for failure and error out if so */ if (!Files[FileNumber]) { perror(argv[FileNumber + ArgOffset]); @@ -590,32 +592,32 @@ }
/* Write the File Headers */ - WriteFileHeader(Files[NtosUserStubs], - "System Call Stubs for Native API", + WriteFileHeader(Files[NtosUserStubs], + "System Call Stubs for Native API", argv[NtosUserStubs + ArgOffset]); - - WriteFileHeader(Files[NtosKernelStubs], - "System Call Stubs for Native API", + + WriteFileHeader(Files[NtosKernelStubs], + "System Call Stubs for Native API", argv[NtosKernelStubs + ArgOffset]); fputs("#include <ndk/asm.h>\n\n", Files[NtosKernelStubs]);
- WriteFileHeader(Files[Win32kStubs], - "System Call Stubs for Native API", + WriteFileHeader(Files[Win32kStubs], + "System Call Stubs for Native API", argv[Win32kStubs + ArgOffset]);
/* Create the System Stubs */ CreateStubs(Files[NativeSystemDb], - &Files[NtosUserStubs], - Files[NtosKernelStubs], - MAIN_INDEX, + &Files[NtosUserStubs], + Files[NtosKernelStubs], + MAIN_INDEX, 1, 1);
/* Create the Graphics Stubs */ - CreateStubs(Files[NativeGuiDb], - &Files[Win32kStubs], - NULL, - WIN32K_INDEX, + CreateStubs(Files[NativeGuiDb], + &Files[Win32kStubs], + NULL, + WIN32K_INDEX, 1, 0);
@@ -624,22 +626,22 @@ rewind(Files[NativeGuiDb]);
/* Create the Service Tables */ - CreateSystemServiceTable(Files[NativeSystemDb], + CreateSystemServiceTable(Files[NativeSystemDb], Files[NtosServiceTable], "Main", argv[NtosServiceTable + ArgOffset]); - - CreateSystemServiceTable(Files[NativeGuiDb], + + CreateSystemServiceTable(Files[NativeGuiDb], Files[Win32kServiceTable], "Win32k", argv[Win32kServiceTable + ArgOffset]);
/* Close all files */ for (FileNumber = 0; FileNumber < Arguments-ArgOffset; FileNumber++) { - + /* Close the File */ fclose(Files[FileNumber]); - + }
return(0);