mirror of
https://github.com/rvtr/twl_wrapsdk.git
synced 2025-06-18 22:35:34 -04:00

git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/twl_wrapsdk/trunk@156 4ee2a332-4b2b-5046-8439-1ba90f034370
280 lines
9.5 KiB
C
280 lines
9.5 KiB
C
/*---------------------------------------------------------------------------*
|
||
Project: tools - makedsrom
|
||
File: makesdrom.c
|
||
|
||
Copyright 2006,2007 Nintendo. All rights reserved.
|
||
|
||
These coded instructions, statements, and computer programs contain
|
||
proprietary information of Nintendo of America Inc. and/or Nintendo
|
||
Company Ltd., and are protected by Federal copyright law. They may
|
||
not be disclosed to third parties or copied or duplicated in any form,
|
||
in whole or in part, without the prior written consent of Nintendo.
|
||
|
||
|
||
$NoKeywords: $
|
||
*---------------------------------------------------------------------------*/
|
||
#include <stdio.h>
|
||
#include <stdlib.h> // atoi()
|
||
#include <string.h>
|
||
#include <ctype.h>
|
||
#include <getopt.h> // getopt()
|
||
#include "version.h"
|
||
#include "types.h"
|
||
#include "elf.h"
|
||
#include "elf_loader.h"
|
||
#include "searcharg.h"
|
||
|
||
|
||
|
||
#define DS_ROM_HEADER_SIZE 0x4000
|
||
|
||
char c_source_line_str[256];
|
||
|
||
#define C_SOURCE_FILENAME "staticsymlist.c"
|
||
FILE* CSourceFilep;
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
*
|
||
*---------------------------------------------------------------------------*/
|
||
u32 adr_ALIGN( u32 addr, u32 align_size);
|
||
void file_write( char* c_str, FILE* Fp);
|
||
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
*
|
||
*---------------------------------------------------------------------------*/
|
||
u16 dbg_print_flag;
|
||
u16 unresolved_table_block_flag = 0;
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
* MAIN
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
int main(int argc, char *argv[])
|
||
{
|
||
int i;
|
||
FILE *FHp;
|
||
u32 binbuf[4];
|
||
ELHandle ElfH;
|
||
char* c_filename;
|
||
SAArgInfo ArgInfo;
|
||
u16 result;
|
||
|
||
// printf( "binbuf : %x\n", binbuf);
|
||
/*
|
||
for( i=0; i<argc; i++) {
|
||
fprintf(stdout, "%s\n", argv[i]);
|
||
}
|
||
*/
|
||
|
||
/*-----------------------------------------------------*/
|
||
dbg_print_flag = 0;
|
||
SA_searchopt( &ArgInfo, argc, argv);
|
||
// SA_printf( &ArgInfo);
|
||
|
||
/*<2A>I<EFBFBD>v<EFBFBD>V<EFBFBD><56><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȃ<EFBFBD><C882>Ƃ<EFBFBD>*/
|
||
if( argc == 1) {
|
||
printf( "Development Tool - makelst - Make \"C\" source file\n");
|
||
printf( "Build %s\n\n", __DATE__);
|
||
printf( "Usage: makelst [-o output-file] [-static static-files ...] [-dll dll-files ...]\n\n");
|
||
exit( 1);
|
||
}
|
||
|
||
/*-d <20>I<EFBFBD>v<EFBFBD>V<EFBFBD><56><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>f<CE83>o<EFBFBD>b<EFBFBD>O<EFBFBD>\<5C><><EFBFBD>t<EFBFBD><74><EFBFBD>O<EFBFBD><4F><EFBFBD>Z<EFBFBD>b<EFBFBD>g*/
|
||
/* for( i=0; i<ArgList.opt_num; i++) {
|
||
if( strcmp( ArgList.opt[i], "-d") == 0) {
|
||
if( ArgList.opt_arg[i] == NULL) {
|
||
dbg_print_flag = 1;
|
||
break;
|
||
}else{
|
||
printf( "Illegal argument \"%s\"\n", ArgList.opt_arg[i]);
|
||
exit( 1);
|
||
}
|
||
}
|
||
}*/
|
||
|
||
|
||
/*---------- <20>s<EFBFBD><73><EFBFBD>ȓ<EFBFBD><C893>͂<EFBFBD><CD82>x<EFBFBD><78> ----------*/
|
||
{
|
||
/*<2A>I<EFBFBD>v<EFBFBD>V<EFBFBD><56><EFBFBD><EFBFBD><EFBFBD>Ȃ<EFBFBD><C882>̈<EFBFBD><CC88><EFBFBD><EFBFBD>`<60>F<EFBFBD>b<EFBFBD>N*/
|
||
SAOptList* CurrentOptList;
|
||
CurrentOptList = SA_IsThereOpt( &ArgInfo, "\0");
|
||
if( CurrentOptList != NULL) {
|
||
printf( "invalid argument (%s)\n", CurrentOptList->NameList->name);
|
||
exit( 0);
|
||
}
|
||
|
||
/*<2A>s<EFBFBD><73><EFBFBD>I<EFBFBD>v<EFBFBD>V<EFBFBD><56><EFBFBD><EFBFBD><EFBFBD>`<60>F<EFBFBD>b<EFBFBD>N*/
|
||
CurrentOptList = ArgInfo.OptList;
|
||
for( i=0; i<(ArgInfo.opt_num); i++) {
|
||
if( ( strcmp(CurrentOptList->opt_name, "\0" ) != 0) &&
|
||
( strcmp(CurrentOptList->opt_name, "-d\0" ) != 0) &&
|
||
( strcmp(CurrentOptList->opt_name, "-o\0" ) != 0) &&
|
||
( strcmp(CurrentOptList->opt_name, "-dll\0" ) != 0) &&
|
||
( strcmp(CurrentOptList->opt_name, "-static\0") != 0)) {
|
||
printf( "invalid option (%s)\n", CurrentOptList->opt_name);
|
||
exit( 0);
|
||
}
|
||
CurrentOptList = CurrentOptList->next;
|
||
}
|
||
}
|
||
/*--------------------------------------*/
|
||
|
||
EL_Init();
|
||
unresolved_table_block_flag = 0; //Unresolved<65>e<EFBFBD>[<5B>u<EFBFBD><75><EFBFBD>ւ̒lj<CC92><C789>֎~<7E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
/*----------- -dll<6C>I<EFBFBD>v<EFBFBD>V<EFBFBD><56><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ----------------*/
|
||
{
|
||
SAOptList* CurrentOptList;
|
||
SANameList* CurrentNameList;
|
||
CurrentOptList = SA_IsThereOpt( &ArgInfo, "-dll\0");
|
||
|
||
if( CurrentOptList) {
|
||
|
||
if( CurrentOptList->name_num == 0) {
|
||
printf( "no input dll file(s).\n");
|
||
exit( 0);
|
||
}
|
||
|
||
CurrentNameList = CurrentOptList->NameList;
|
||
for( i=0; i<(CurrentOptList->name_num); i++) {
|
||
FHp = fopen( CurrentNameList->name, "rb");
|
||
if( FHp == NULL) {
|
||
printf( "cannot open file \"%s\".\n", CurrentNameList->name);
|
||
exit( 1);
|
||
}
|
||
EL_InitHandle( &ElfH);
|
||
result = EL_LoadLibraryfromFile( &ElfH, FHp, binbuf);
|
||
fclose( FHp);
|
||
|
||
CurrentNameList = CurrentNameList->next;
|
||
}
|
||
}else{
|
||
printf( "no input dll file(s).\n");
|
||
exit( 0);
|
||
}
|
||
}
|
||
/*-----------------------------------------------*/
|
||
|
||
EL_ResolveAllLibrary();
|
||
|
||
|
||
/*------------- -s<>I<EFBFBD>v<EFBFBD>V<EFBFBD><56><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> --------------*/
|
||
unresolved_table_block_flag = 1; //Unresolved<65>e<EFBFBD>[<5B>u<EFBFBD><75><EFBFBD>ɒlj<C992><C789><EFBFBD><EFBFBD>Ȃ<EFBFBD><C882>悤<EFBFBD>ɂ<EFBFBD><C982><EFBFBD>
|
||
{
|
||
SAOptList* CurrentOptList;
|
||
SANameList* CurrentNameList;
|
||
CurrentOptList = SA_IsThereOpt( &ArgInfo, "-static\0");
|
||
|
||
if( CurrentOptList) {
|
||
|
||
if( CurrentOptList->name_num == 0) {
|
||
printf( "no input static file(s).\n");
|
||
exit( 0);
|
||
}
|
||
|
||
CurrentNameList = CurrentOptList->NameList;
|
||
for( i=0; i<(CurrentOptList->name_num); i++) {
|
||
FHp = fopen( CurrentNameList->name, "rb");
|
||
if( FHp == NULL) {
|
||
printf( "cannot open file \"%s\".\n", CurrentNameList->name);
|
||
exit( 1);
|
||
}
|
||
EL_InitHandle( &ElfH);
|
||
result = EL_LoadLibraryfromFile( &ElfH, FHp, binbuf);
|
||
fclose( FHp);
|
||
|
||
CurrentNameList = CurrentNameList->next;
|
||
}
|
||
}else{
|
||
printf( "no input static file(s).\n");
|
||
exit( 0);
|
||
}
|
||
}
|
||
/*---------------------------------------------*/
|
||
|
||
|
||
/*<2A><><EFBFBD><EFBFBD>C<EFBFBD>\<5C>[<5B>X<EFBFBD>t<EFBFBD>@<40>C<EFBFBD><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||
c_filename = malloc( strlen( C_SOURCE_FILENAME));
|
||
strcpy( c_filename, C_SOURCE_FILENAME);
|
||
/*-o <20>I<EFBFBD>v<EFBFBD>V<EFBFBD><56><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ύw<CE8E><77><EFBFBD>t<EFBFBD>@<40>C<EFBFBD><43><EFBFBD><EFBFBD><EFBFBD>ɕύX*/
|
||
{
|
||
SAOptList* CurrentOptList;
|
||
SANameList* CurrentNameList;
|
||
CurrentOptList = SA_IsThereOpt( &ArgInfo, "-o\0");
|
||
|
||
if( CurrentOptList) {
|
||
if( CurrentOptList->name_num != 0) {
|
||
CurrentNameList = CurrentOptList->NameList;
|
||
c_filename = CurrentNameList->name;
|
||
}else{
|
||
printf( "error : no filename after \"-o\" option.\n\n");
|
||
exit( 1);
|
||
}
|
||
}
|
||
}
|
||
|
||
CSourceFilep = fopen( c_filename, "w");
|
||
if( !CSourceFilep) {
|
||
printf( "error : cannot create file \"%s\".\n\n", c_filename);
|
||
exit( 1);
|
||
}
|
||
file_write( "/*This file generated automatically by the \"makelst\".*/\n", CSourceFilep);
|
||
file_write( "\n", CSourceFilep);
|
||
file_write( "#ifndef __STATIC_SYM_LIST__\n", CSourceFilep);
|
||
file_write( "#define __STATIC_SYM_LIST__\n", CSourceFilep);
|
||
file_write( "\n", CSourceFilep);
|
||
file_write( "#include <twl.h>\n", CSourceFilep);
|
||
file_write( "#include <el/elf_loader.h>\n", CSourceFilep);
|
||
file_write( "\n", CSourceFilep);
|
||
|
||
EL_ResolveAllLibrary(); //<2F><><EFBFBD>o<EFBFBD>V<EFBFBD><56><EFBFBD>{<7B><><EFBFBD>̃}<7D>[<5B>L<EFBFBD><4C><EFBFBD>O
|
||
EL_ExtractStaticSym1(); //<2F>\<5C><><EFBFBD>̐ݒ蕔<DD92><E89594>
|
||
file_write( "\n\n", CSourceFilep);
|
||
|
||
file_write( "/*--------------------------------\n", CSourceFilep);
|
||
file_write( " API\n", CSourceFilep);
|
||
file_write( " --------------------------------*/\n", CSourceFilep);
|
||
file_write( "void elAddStaticSym( void)\n", CSourceFilep);
|
||
file_write( "{\n", CSourceFilep);
|
||
EL_ExtractStaticSym2(); //API<50>Ăяo<D18F><6F><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
file_write( "}\n", CSourceFilep);
|
||
|
||
unresolved_table_block_flag = 0; //Unresolved<65>e<EFBFBD>[<5B>u<EFBFBD><75><EFBFBD>ւ̒lj<CC92><C789>֎~<7E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
|
||
file_write( "\n", CSourceFilep);
|
||
file_write( "#endif /*__STATIC_SYM_LIST__*/\n", CSourceFilep);
|
||
fclose( CSourceFilep);
|
||
/*---------------------------------------------*/
|
||
|
||
printf( "\"C\" source file \"%s\" is generated.\n\n", c_filename);
|
||
exit( 0);
|
||
|
||
/*-----------------------------------------------------*/
|
||
|
||
return 0;
|
||
}
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
* <20>A<EFBFBD>h<EFBFBD><68><EFBFBD>X<EFBFBD>̃A<CC83><41><EFBFBD>C<EFBFBD><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>g
|
||
*---------------------------------------------------------------------------*/
|
||
u32 adr_ALIGN( u32 addr, u32 align_size)
|
||
{
|
||
u32 aligned_addr;
|
||
|
||
if( (addr % align_size) == 0) {
|
||
aligned_addr = addr;
|
||
}else{
|
||
aligned_addr = (((addr) & ~((align_size) - 1)) + (align_size));
|
||
}
|
||
|
||
return aligned_addr;
|
||
}
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
* <20>t<EFBFBD>@<40>C<EFBFBD><43><EFBFBD>ɕ<EFBFBD><C995><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
*---------------------------------------------------------------------------*/
|
||
void file_write( char* c_str, FILE* Fp)
|
||
{
|
||
fwrite( c_str, 1, strlen( c_str), Fp);
|
||
}
|