PowerPC WIP. Some of this is indeed hacky and will be changed.

svn path=/branches/powerpc/; revision=22591
This commit is contained in:
Art Yerkes 2006-06-24 21:27:06 +00:00
parent 1f7943c579
commit e1850b5ee7
11 changed files with 191 additions and 117 deletions

View file

@ -30,11 +30,11 @@ NCI_HOST_LFLAGS = $(TOOLS_LFLAGS)
$(NCI_TARGET): $(NCI_OBJECTS) | $(NCI_OUT)
$(ECHO_LD)
${host_gcc} $(NCI_OBJECTS) $(NCI_HOST_LFLAGS) -o $@
${host_gcc} -g $(NCI_OBJECTS) $(NCI_HOST_LFLAGS) -o $@
$(NCI_INT_)ncitool.o: $(NCI_BASE_)ncitool.c | $(NCI_INT)
$(ECHO_CC)
${host_gcc} $(NCI_HOST_CFLAGS) -c $< -o $@
${host_gcc} -g $(NCI_HOST_CFLAGS) -c $< -o $@
.PHONY: nci_clean
nci_clean:
@ -63,7 +63,7 @@ NCI_SERVICE_FILES = \
$(NCI_SERVICE_FILES): $(NCI_TARGET) $(KERNEL_SVC_DB) $(WIN32K_SVC_DB)
$(ECHO_NCI)
$(Q)$(NCI_TARGET) \
$(Q)$(NCI_TARGET) -arch $(ARCH) \
$(KERNEL_SVC_DB) \
$(WIN32K_SVC_DB) \
$(KERNEL_SERVICE_TABLE) \

View file

@ -53,6 +53,16 @@
" movl $KUSER_SHARED_SYSCALL, %%ecx\n" \
" call *%%ecx\n" \
" ret $0x%x\n\n"
#define UserModeStub_ppc " mflr 0\n" \
" addi 1,1,-16\n" \
" li 0,%x\n" \
" stw 0,1(0)\n" \
" sc\n" \
" lwz 0,1(0)\n" \
" mtlr 0\n" \
" addi 1,1,16\n" \
" blr\n"
#elif defined(_MSC_VER)
#define UserModeStub_x86 " asm { \n" \
" mov eax, %xh\n" \
@ -75,6 +85,9 @@
" pushl $KGDT_R0_CODE\n" \
" call _KiSystemService\n" \
" ret $0x%x\n\n"
#define KernelModeStub_ppc " bl KiSystemService\n" \
" rfi\n"
#elif defined(_MSC_VER)
#define KernelModeStub_x86 " asm { \n" \
" mov eax, %xh\n" \
@ -89,14 +102,28 @@
#endif
/***** Arch Dependent Stuff ******/
//#ifdef _M_IX86
#define ARGS_TO_BYTES(x) x*4
#define UserModeStub UserModeStub_x86
#define KernelModeStub KernelModeStub_x86
struct ncitool_data_t {
const char *arch;
int args_to_bytes;
const char *km_stub;
const char *um_stub;
const char *global_header;
const char *declaration;
};
//#elseif
//#error Unsupported Architecture
//#endif
struct ncitool_data_t ncitool_data[] = {
{ "x86", 4, KernelModeStub_x86, UserModeStub_x86,
".global _%s@%d\n", "_%s@%d:\n" },
{ "powerpc", 4, KernelModeStub_ppc, UserModeStub_ppc,
"\t.globl %s\n", "%s:\n" },
{ 0 }
};
int arch_sel = 0;
#define ARGS_TO_BYTES(x) 4*(ncitool_data[arch_sel].args_to_bytes)
#define UserModeStub ncitool_data[arch_sel].um_stub
#define KernelModeStub ncitool_data[arch_sel].km_stub
#define GlobalHeader ncitool_data[arch_sel].global_header
#define Declaration ncitool_data[arch_sel].declaration
/* FUNCTIONS ****************************************************************/
@ -162,10 +189,10 @@ WriteStubHeader(FILE* StubFile,
unsigned StackBytes)
{
/* Export the function */
fprintf(StubFile, ".global _%s@%d\n", SyscallName, StackBytes);
fprintf(StubFile, GlobalHeader, SyscallName, StackBytes);
/* Define it */
fprintf(StubFile, "_%s@%d:\n\n", SyscallName, StackBytes);
fprintf(StubFile, Declaration, SyscallName, StackBytes);
}
@ -489,7 +516,7 @@ CreateSystemServiceTable(FILE *SyscallDb,
void usage(char * argv0)
{
printf("Usage: %s sysfuncs.lst w32ksvc.db napi.h ssdt.h napi.S zw.S win32k.S win32k.S\n"
printf("Usage: %s [-arch <arch>] sysfuncs.lst w32ksvc.db napi.h ssdt.h napi.S zw.S win32k.S win32k.S\n"
" sysfuncs.lst native system functions database\n"
" w32ksvc.db native graphic functions database\n"
" napi.h NTOSKRNL service table\n"
@ -497,19 +524,31 @@ void usage(char * argv0)
" napi.S NTDLL stubs\n"
" zw.S NTOSKRNL Zw stubs\n"
" win32k.S GDI32 stubs\n"
" win32k.S USER32 stubs\n",
" win32k.S USER32 stubs\n"
" -arch is optional, default is x86\n",
argv0
);
}
int main(int argc, char* argv[])
{
FILE * Files[Arguments];
int FileNumber;
FILE * Files[Arguments] = { };
int FileNumber, ArgOffset = 1;
char * OpenType = "r";
/* Catch architecture argument */
if (argc > 3 && !strcmp(argv[1],"-arch")) {
int i;
for( i = 0; ncitool_data[arch_sel].arch && strcmp(argv[2],ncitool_data[i].arch); i++ );
if (!ncitool_data[arch_sel].arch) {
usage(argv[0]);
return 1;
}
arch_sel = i;
ArgOffset = 3;
}
/* Make sure all arguments all there */
if (argc != Arguments + 1) {
if (argc != Arguments + ArgOffset) {
usage(argv[0]);
return(1);
}
@ -519,11 +558,11 @@ int main(int argc, char* argv[])
/* Open the File */
if (FileNumber == 2) OpenType = "wb";
Files[FileNumber] = fopen(argv[FileNumber + 1], OpenType);
Files[FileNumber] = fopen(argv[FileNumber + ArgOffset], OpenType);
/* Check for failure and error out if so */
if (!Files[FileNumber]) {
perror(argv[FileNumber + 1]);
perror(argv[FileNumber + ArgOffset]);
return (1);
}
@ -532,20 +571,20 @@ int main(int argc, char* argv[])
/* Write the File Headers */
WriteFileHeader(Files[NtosUserStubs],
"System Call Stubs for Native API",
argv[NtosUserStubs + 1]);
argv[NtosUserStubs + ArgOffset]);
WriteFileHeader(Files[NtosKernelStubs],
"System Call Stubs for Native API",
argv[NtosKernelStubs + 1]);
argv[NtosKernelStubs + ArgOffset]);
fputs("#include <ndk/asm.h>\n\n", Files[NtosKernelStubs]);
WriteFileHeader(Files[Win32kGdiStubs],
"System Call Stubs for Native API",
argv[Win32kGdiStubs + 1]);
argv[Win32kGdiStubs + ArgOffset]);
WriteFileHeader(Files[Win32kUserStubs],
"System Call Stubs for Native API",
argv[Win32kUserStubs + 1]);
argv[Win32kUserStubs + ArgOffset]);
/* Create the System Stubs */
@ -572,15 +611,15 @@ int main(int argc, char* argv[])
CreateSystemServiceTable(Files[NativeSystemDb],
Files[NtosServiceTable],
"Main",
argv[NtosServiceTable + 1]);
argv[NtosServiceTable + ArgOffset]);
CreateSystemServiceTable(Files[NativeGuiDb],
Files[Win32kServiceTable],
"Win32k",
argv[Win32kServiceTable + 1]);
argv[Win32kServiceTable + ArgOffset]);
/* Close all files */
for (FileNumber = 0; FileNumber < Arguments; FileNumber++) {
for (FileNumber = 0; FileNumber < Arguments-ArgOffset; FileNumber++) {
/* Close the File */
fclose(Files[FileNumber]);

View file

@ -24,11 +24,11 @@ pefixup: $(PEFIXUP_TARGET)
$(PEFIXUP_TARGET): $(PEFIXUP_OBJECTS) | $(PEFIXUP_OUT)
$(ECHO_LD)
${host_gcc} $(PEFIXUP_OBJECTS) $(PEFIXUP_HOST_LFLAGS) -o $@
${host_gcc} -g $(PEFIXUP_OBJECTS) $(PEFIXUP_HOST_LFLAGS) -o $@
$(PEFIXUP_INT_)pefixup.o: $(PEFIXUP_BASE_)pefixup.c | $(PEFIXUP_INT)
$(ECHO_CC)
${host_gcc} $(PEFIXUP_HOST_CFLAGS) -c $< -o $@
${host_gcc} -g $(PEFIXUP_HOST_CFLAGS) -c $< -o $@
.PHONY: pefixup_clean
pefixup_clean:

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,12 @@
#!/bin/sh
export PATH=$PATH:/usr/local/pkg/reactos-powerpc/bin
make \
HOST=mingw32-linux \
ROS_INTERMEDIATE=obj-ppc \
ROS_OUTPUT=output-ppc \
ROS_PREFIX=reactos-powerpc \
ROS_INSTALL=rosppc \
ROS_AUTOMAKE=makefile.ppc \
ROS_RBUILDFLAGS=-rReactOS-ppc.rbuild \
$*

View file

@ -27,6 +27,35 @@
#include "rsym.h"
static inline WORD dtohs(WORD in)
{
PBYTE in_ptr = (PBYTE)&in;
return in_ptr[0] | (in_ptr[1] << 8);
}
static inline WORD htods(WORD in)
{
WORD out;
PBYTE out_ptr = (PBYTE)&out;
out_ptr[0] = in; out_ptr[1] = in >> 8;
return out;
}
static inline DWORD dtohl(DWORD in)
{
PBYTE in_ptr = (PBYTE)&in;
return in_ptr[0] | (in_ptr[1] << 8) | (in_ptr[2] << 16) | (in_ptr[3] << 24);
}
static inline DWORD htodl(DWORD in)
{
DWORD out;
PBYTE out_ptr = (PBYTE)&out;
out_ptr[0] = in ; out_ptr[1] = in >> 8;
out_ptr[2] = in >> 16; out_ptr[3] = in >> 24;
return out;
}
static int
CompareSymEntry(const PROSSYM_ENTRY SymEntry1, const PROSSYM_ENTRY SymEntry2)
{
@ -814,6 +843,9 @@ int main(int argc, char* argv[])
/* Check if MZ header exists */
PEDosHeader = (PIMAGE_DOS_HEADER) FileData;
PEDosHeader->e_magic = dtohs(PEDosHeader->e_magic);
PEDosHeader->e_lfanew = dtohl(PEDosHeader->e_lfanew);
if (PEDosHeader->e_magic != IMAGE_DOS_MAGIC || PEDosHeader->e_lfanew == 0L)
{
perror("Input file is not a PE image.\n");

View file

@ -10,7 +10,7 @@
#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
typedef unsigned char BYTE;
typedef unsigned char BYTE, *PBYTE;
typedef unsigned char UCHAR;
typedef unsigned short WORD;
typedef unsigned short USHORT;

View file

@ -690,6 +690,7 @@ wnumberf(std::wstring& f, double __n, wchar_t exp_sign, int size, int precision
return true;
}
#ifdef __i386__
static bool
numberfl(std::string& f, long double __n, char exp_sign, int size, int precision, int type)
{
@ -1091,6 +1092,7 @@ wnumberfl(std::wstring& f, long double __n, wchar_t exp_sign, int size, int pre
}
return true;
}
#endif
static int
do_string(std::string& f, const char* s, int len, int field_width, int precision, int flags)
@ -1507,7 +1509,9 @@ ssvprintf ( const char *fmt, va_list args )
} else {
if ( precision == -1 )
precision = 6;
#ifdef __i386__
result = numberfl(f,_ldouble,*fmt,field_width,precision,flags);
#endif
if (result < 0)
{
assert(!"TODO FIXME handle error better");
@ -1831,7 +1835,9 @@ sswvprintf ( const wchar_t* fmt, va_list args )
} else {
if ( precision == -1 )
precision = 6;
#ifdef __i386__
result = wnumberfl(f,_ldouble,*fmt,field_width,precision,flags);
#endif
if (result < 0)
{
assert(!"TODO FIXME handle error better");

View file

@ -69,6 +69,29 @@ __NEW_STRUCT_FUNC(string)
__NEW_STRUCT_FUNC(toolbar_item)
__NEW_STRUCT_FUNC(ani_any)
void hdump( void *v, int l ) {
int i;
char *c = (char *)v, *begin = c;
while( l > 0 ) {
if( (c - begin) )
printf("\n");
printf("%08x:", c);
for( i = 0; i < l && i < 16; i++ ) {
printf(" %02x", c[i] & 0xff);
}
for( ; i < 16; i++ ) {
printf(" ");
}
printf(" -- ");
for( i = 0; i < l && i < 16; i++ ) {
printf("%c", isprint(c[i]) ? c[i] : '.');
}
c += 16; l -= 16;
}
printf("\n");
}
/* New instances for all types of structures */
/* Very inefficient (in size), but very functional :-]
* Especially for type-checking.
@ -984,7 +1007,10 @@ ver_words_t *add_ver_words(ver_words_t *w, int i)
return w;
}
#define MSGTAB_BAD_PTR(p, b, l, r) (((l) - ((char *)(p) - (char *)(b))) > (r))
#define MSGTAB_BAD_PTR(p, b, l, r) \
(printf("MSGTAB_BAD_PTR(%x,%x,%d,r) => %x > r=%x\n", p,b,l, \
((l) - ((char *)(p) - (char *)(b))), r), \
(((l) - ((char *)(p) - (char *)(b))) > (r)))
messagetable_t *new_messagetable(raw_data_t *rd, int *memopt)
{
messagetable_t *msg = (messagetable_t *)xmalloc(sizeof(messagetable_t));
@ -1023,97 +1049,48 @@ messagetable_t *new_messagetable(raw_data_t *rd, int *memopt)
if(!hi && !lo)
yyerror("Invalid messagetable block count 0");
if(!hi && lo) /* Messagetable byteorder == native byteorder */
{
#ifdef WORDS_BIGENDIAN
if(byteorder != WRC_BO_LITTLE) goto out;
if(byteorder != WRC_BO_LITTLE) goto out;
#else
if(byteorder != WRC_BO_BIG) goto out;
if(byteorder != WRC_BO_BIG) goto out;
#endif
/* Resource byteorder != native byteorder */
mbp = (msgtab_block_t *)&(((DWORD *)rd->data)[1]);
if(MSGTAB_BAD_PTR(mbp, rd->data, rd->size, nblk * sizeof(*mbp)))
yyerror("Messagetable's blocks are outside of defined data");
for(i = 0; i < nblk; i++)
{
msgtab_entry_t *mep, *next_mep;
DWORD id;
mep = (msgtab_entry_t *)(((char *)rd->data) + mbp[i].offset);
for(id = mbp[i].idlo; id <= mbp[i].idhi; id++)
{
if(MSGTAB_BAD_PTR(mep, rd->data, rd->size, mep->length))
yyerror("Messagetable's data for block %d, ID 0x%08lx is outside of defined data", (int)i, id);
if(mep->flags == 1) /* Docu says 'flags == 0x0001' for unicode */
{
WORD *wp = (WORD *)&mep[1];
int l = mep->length/2 - 2; /* Length included header */
int n;
if(mep->length & 1)
yyerror("Message 0x%08lx is unicode (block %d), but has odd length (%d)", id, (int)i, mep->length);
for(n = 0; n < l; n++)
wp[n] = BYTESWAP_WORD(wp[n]);
}
next_mep = (msgtab_entry_t *)(((char *)mep) + mep->length);
mep->length = BYTESWAP_WORD(mep->length);
mep->flags = BYTESWAP_WORD(mep->flags);
mep = next_mep;
}
mbp[i].idlo = BYTESWAP_DWORD(mbp[i].idlo);
mbp[i].idhi = BYTESWAP_DWORD(mbp[i].idhi);
mbp[i].offset = BYTESWAP_DWORD(mbp[i].offset);
}
}
if(hi && !lo) /* Messagetable byteorder != native byteorder */
/* Resource byteorder != native byteorder */
mbp = BYTESWAP_DWORD((msgtab_block_t *)&(((DWORD *)rd->data)[1]));
if(MSGTAB_BAD_PTR(mbp, rd->data, rd->size, nblk * sizeof(*mbp)))
yyerror("[1] Messagetable's blocks are outside of defined data");
for(i = 0; i < nblk; i++)
{
#ifdef WORDS_BIGENDIAN
if(byteorder == WRC_BO_LITTLE) goto out;
#else
if(byteorder == WRC_BO_BIG) goto out;
#endif
/* Resource byteorder == native byteorder */
mbp = (msgtab_block_t *)&(((DWORD *)rd->data)[1]);
nblk = BYTESWAP_DWORD(nblk);
if(MSGTAB_BAD_PTR(mbp, rd->data, rd->size, nblk * sizeof(*mbp)))
yyerror("Messagetable's blocks are outside of defined data");
for(i = 0; i < nblk; i++)
msgtab_entry_t *mep, *next_mep;
DWORD id;
mep = (msgtab_entry_t *)(((char *)rd->data) + mbp[i].offset);
for(id = mbp[i].idlo; id <= mbp[i].idhi; id++)
{
if(MSGTAB_BAD_PTR(mep, rd->data, rd->size, mep->length))
yyerror("Messagetable's data for block %d, ID 0x%08lx is outside of defined data", (int)i, id);
if(BYTESWAP_DWORD(mep->flags) == 1) /* Docu says 'flags == 0x0001' for unicode */
{
msgtab_entry_t *mep;
DWORD id;
mbp[i].idlo = BYTESWAP_DWORD(mbp[i].idlo);
mbp[i].idhi = BYTESWAP_DWORD(mbp[i].idhi);
mbp[i].offset = BYTESWAP_DWORD(mbp[i].offset);
mep = (msgtab_entry_t *)(((char *)rd->data) + mbp[i].offset);
for(id = mbp[i].idlo; id <= mbp[i].idhi; id++)
{
mep->length = BYTESWAP_WORD(mep->length);
mep->flags = BYTESWAP_WORD(mep->flags);
if(MSGTAB_BAD_PTR(mep, rd->data, rd->size, mep->length))
yyerror("Messagetable's data for block %d, ID 0x%08lx is outside of defined data", (int)i, id);
if(mep->flags == 1) /* Docu says 'flags == 0x0001' for unicode */
{
WORD *wp = (WORD *)&mep[1];
int l = mep->length/2 - 2; /* Length included header */
int n;
if(mep->length & 1)
yyerror("Message 0x%08lx is unicode (block %d), but has odd length (%d)", id, (int)i, mep->length);
for(n = 0; n < l; n++)
wp[n] = BYTESWAP_WORD(wp[n]);
}
mep = (msgtab_entry_t *)(((char *)mep) + mep->length);
}
WORD *wp = (WORD *)&mep[1];
int l = BYTESWAP_DWORD(mep->length)/2 - 2; /* Length included header */
int n;
if(BYTESWAP_DWORD(mep->length) & 1)
yyerror("Message 0x%08lx is unicode (block %d), but has odd length (%d)", id, (int)i, BYTESWAP_DWORD(mep->length));
for(n = 0; n < l; n++)
wp[n] = BYTESWAP_WORD(wp[n]);
}
next_mep = (msgtab_entry_t *)(((char *)mep) + BYTESWAP_DWORD(mep->length));
mep->length = BYTESWAP_WORD(mep->length);
mep->flags = BYTESWAP_WORD(mep->flags);
mep = next_mep;
}
mbp[i].idlo = BYTESWAP_DWORD(mbp[i].idlo);
mbp[i].idhi = BYTESWAP_DWORD(mbp[i].idhi);
mbp[i].offset = BYTESWAP_DWORD(mbp[i].offset);
}
out:

View file

@ -70,7 +70,7 @@ wrc: $(WRC_TARGET)
$(WRC_TARGET): $(WRC_OBJECTS) $(WRC_LIBS) | $(WRC_OUT)
$(ECHO_LD)
${host_gcc} $(WRC_OBJECTS) $(WRC_LIBS) $(WRC_HOST_LFLAGS) -o $@
${host_gcc} -g $(WRC_OBJECTS) $(WRC_LIBS) $(WRC_HOST_LFLAGS) -o $@
$(WRC_INT_)dumpres.o: $(WRC_BASE_)dumpres.c | $(WRC_INT)
$(ECHO_CC)
@ -82,7 +82,7 @@ $(WRC_INT_)genres.o: $(WRC_BASE_)genres.c | $(WRC_INT)
$(WRC_INT_)newstruc.o: $(WRC_BASE_)newstruc.c | $(WRC_INT)
$(ECHO_CC)
${host_gcc} $(WRC_HOST_CFLAGS) -c $< -o $@
${host_gcc} -g $(WRC_HOST_CFLAGS) -c $< -o $@
$(WRC_INT_)readres.o: $(WRC_BASE_)readres.c | $(WRC_INT)
$(ECHO_CC)

View file

@ -80,8 +80,13 @@
#define WRC_HIBYTE(w) (((WORD)(w) >> 8) & 0xff)
#define WRC_LOWORD(d) ((DWORD)(d) & 0xffff)
#define WRC_HIWORD(d) (((DWORD)(d) >> 16) & 0xffff)
#ifndef WORDS_BIGENDIAN
#define BYTESWAP_WORD(w) ((WORD)(((WORD)WRC_LOBYTE(w) << 8) + (WORD)WRC_HIBYTE(w)))
#define BYTESWAP_DWORD(d) ((DWORD)(((DWORD)BYTESWAP_WORD(WRC_LOWORD(d)) << 16) + ((DWORD)BYTESWAP_WORD(WRC_HIWORD(d)))))
#else
#define BYTESWAP_WORD(w) ((WORD)(w))
3define BYTESWAP_DWORD(d) ((DWORD)(d))
#endif
/* Binary resource structure */
#define RES_BLOCKSIZE 512