Fixed a problem we had with bool parameters (probably with all types that consume more storage when being passed as function parameters).

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8784 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2004-09-01 20:17:57 +00:00
parent 75df143732
commit d21749db83
2 changed files with 52 additions and 9 deletions

View File

@ -35,16 +35,15 @@ GenSyscallInfos $(syscallInfos) : $(syscallsHeaderPP) ;
BuildPlatformMain gensyscalls : gensyscalls.cpp $(syscallInfos:S=$(SUFOBJ)) ; BuildPlatformMain gensyscalls : gensyscalls.cpp $(syscallInfos:S=$(SUFOBJ)) ;
LinkSharedOSLibs gensyscalls : stdc++.r4 ; LinkSharedOSLibs gensyscalls : stdc++.r4 ;
UsePrivateObjectHeaders gensyscalls.cpp : kernel ;
UseArchObjectHeaders gensyscalls.cpp : $(OBOS_ARCH) ;
# generate the output files # generate the output files
# place them where there are needed # place them where there are needed
local syscallFiles = <syscalls>syscalls.S.inc <syscalls>syscall_dispatcher.h ;
MakeLocate <syscalls>syscalls.S.inc : [ FObjectsDir src kernel libroot os ] ; MakeLocate <syscalls>syscalls.S.inc : [ FObjectsDir src kernel libroot os ] ;
MakeLocate <syscalls>syscall_dispatcher.h : [ FObjectsDir src kernel core ] ; MakeLocate <syscalls>syscall_dispatcher.h : [ FObjectsDir src kernel core ] ;
#Depends <syscalls>generatedFiles : $(syscallFiles) ;
#NotFile <syscalls>generatedFiles ;
Depends <dir>objects/x86.R1/kernel/core : <dir>objects/x86.R1/kernel ; Depends <dir>objects/x86.R1/kernel/core : <dir>objects/x86.R1/kernel ;
@ -66,7 +65,6 @@ actions GenSyscallsDispatcher1 {
$(2[1]) -d $(1) $(2[1]) -d $(1)
} }
#GenSyscalls $(syscallFiles) ;
GenSyscallsFile <syscalls>syscalls.S.inc ; GenSyscallsFile <syscalls>syscalls.S.inc ;
GenSyscallsDispatcher <syscalls>syscall_dispatcher.h ; GenSyscallsDispatcher <syscalls>syscall_dispatcher.h ;

View File

@ -5,6 +5,8 @@
#include <fstream> #include <fstream>
#include <string> #include <string>
#include "arch_cpu.h"
#include "gensyscalls.h" #include "gensyscalls.h"
#include "gensyscalls_common.h" #include "gensyscalls_common.h"
@ -32,6 +34,10 @@ print_usage(bool error)
fprintf((error ? stderr : stdout), kUsage); fprintf((error ? stderr : stdout), kUsage);
} }
enum {
PARAMETER_ALIGNMENT = sizeof(FUNCTION_CALL_PARAMETER_ALIGNMENT_TYPE)
};
// Main // Main
class Main { class Main {
public: public:
@ -64,6 +70,7 @@ public:
} }
} }
fSyscallInfos = gensyscall_get_infos(&fSyscallCount); fSyscallInfos = gensyscall_get_infos(&fSyscallCount);
_UpdateSyscallInfos();
if (!syscallsFile && !dispatcherFile) { if (!syscallsFile && !dispatcherFile) {
printf("Found %d syscalls.\n", fSyscallCount); printf("Found %d syscalls.\n", fSyscallCount);
return 0; return 0;
@ -88,6 +95,8 @@ public:
int paramCount = syscall.parameter_count; int paramCount = syscall.parameter_count;
int paramSize = 0; int paramSize = 0;
gensyscall_parameter_info* parameters = syscall.parameters; gensyscall_parameter_info* parameters = syscall.parameters;
// XXX: Currently the SYSCALL macros support 4 byte aligned
// parameters only. This has to change, of course.
for (int k = 0; k < paramCount; k++) { for (int k = 0; k < paramCount; k++) {
int size = parameters[k].actual_size; int size = parameters[k].actual_size;
paramSize += (size + 3) / 4 * 4; paramSize += (size + 3) / 4 * 4;
@ -114,10 +123,25 @@ public:
int paramCount = syscall.parameter_count; int paramCount = syscall.parameter_count;
if (paramCount > 0) { if (paramCount > 0) {
gensyscall_parameter_info* parameters = syscall.parameters; gensyscall_parameter_info* parameters = syscall.parameters;
file << "*(" << _GetPointerType(parameters[0].type) << ")args"; if (parameters[0].size < PARAMETER_ALIGNMENT) {
file << "(" << parameters[0].type << ")*("
<< "FUNCTION_CALL_PARAMETER_ALIGNMENT_TYPE"
<< "*)args";
} else {
file << "*(" << _GetPointerType(parameters[0].type)
<< ")args";
}
for (int k = 1; k < paramCount; k++) { for (int k = 1; k < paramCount; k++) {
file << ", *(" << _GetPointerType(parameters[k].type) if (parameters[k].size < PARAMETER_ALIGNMENT) {
<< ")((char*)args + " << parameters[k].offset << ")"; file << ", (" << parameters[k].type << ")*("
<< "FUNCTION_CALL_PARAMETER_ALIGNMENT_TYPE"
<< "*)((char*)args + " << parameters[k].offset
<< ")";
} else {
file << ", *(" << _GetPointerType(parameters[k].type)
<< ")((char*)args + " << parameters[k].offset
<< ")";
}
} }
} }
file << ");" << endl; file << ");" << endl;
@ -134,9 +158,30 @@ public:
return string(type, parenthesis - type) + "*" + parenthesis; return string(type, parenthesis - type) + "*" + parenthesis;
} }
void _UpdateSyscallInfos()
{
// Since getting the parameter offsets and actual sizes doesn't work
// as it is now, we overwrite them with values computed using the
// parameter alignment type.
for (int i = 0; i < fSyscallCount; i++) {
gensyscall_syscall_info &syscall = fSyscallInfos[i];
int paramCount = syscall.parameter_count;
gensyscall_parameter_info* parameters = syscall.parameters;
int offset = 0;
for (int k = 0; k < paramCount; k++) {
if (parameters[k].size < PARAMETER_ALIGNMENT)
parameters[k].actual_size = PARAMETER_ALIGNMENT;
else
parameters[k].actual_size = parameters[k].size;
parameters[k].offset = offset;
offset += parameters[k].actual_size;
}
}
}
private: private:
const gensyscall_syscall_info *fSyscallInfos; gensyscall_syscall_info *fSyscallInfos;
int fSyscallCount; int fSyscallCount;
}; };
// main // main