Skip to content
Snippets Groups Projects
Commit e7a34ff2 authored by John Hodge's avatar John Hodge
Browse files

Kernel - Remove PHP scripts (replaced with either perl or C)

parent f7177483
Branches
No related merge requests found
<?php
$gLines = file("syscalls.lst");
$lSyscalls = array();
$i = 0;
foreach($gLines as $line)
{
$line = trim($line);
if(empty($line)) continue;
if( intVal($line) != 0)
$i = $line;
else
$lSyscalls[$i++] = explode("\t", $line, 3);
}
$lMax = $i;
$lAsmInc = "; Acess2
; System Calls List
;
";
$lHeader = "/*
* AcessOS Microkernel Version
* syscalls.h
*/
#ifndef _SYSCALLS_H
#define _SYSCALLS_H
";
$i = 0;
foreach($lSyscalls as $num=>$call)
{
if($i != $num) {
$lHeader .= "\n";
$lAsmInc .= "\n";
}
$lHeader .= "#define {$call[0]}\t{$num}";
$lHeader .= "\t// {$num} - {$call[1]}\n";
$lAsmInc .= "%define {$call[0]}\t{$num}\t; {$call[1]}\n";
if($i != $num)
$i = $num+1;
else
$i ++;
}
$lHeader .= "#define NUM_SYSCALLS\t$i\n";
$lHeader .= "#define SYS_DEBUG\t0x100 // 0x100 - Print a debug string\n";
$lHeader .= "\n";
$lHeader .= "#ifdef __GNUC__\n";
$lHeader .= "static const char *cSYSCALL_NAMES[] = {\n\t";
$j = 0;
for($i=0;$i<$lMax;$i++)
{
if(!isset($lSyscalls[$i]))
$lHeader .= "\"\",";
else
$lHeader .= "\"".$lSyscalls[$i][0]."\",";
$j ++;
if($j == 6) {
$lHeader .= "\n\t";
$j = 0;
}
}
$lHeader .= "\"\"\n};\n"
$lHeader .= "#endif\n";
$lHeader .= "#endif\n";
$fp = fopen("include/syscalls.h", "w"); fwrite($fp, $lHeader); fclose($fp);
$fp = fopen("include/syscalls.inc.asm", "w"); fwrite($fp, $lAsmInc); fclose($fp);
?>
<?php
date_default_timezone_set("UTC");
$lGenDate = date("Y-m-d H:i");
$gOutput = <<<EOF
/*
* Acess2 InitRD
* InitRD Data
* Generated $lGenDate
*/
#include "initrd.h"
EOF;
define("DEBUG_ENABLED", false);
$ACESSDIR = getenv("ACESSDIR");
$ARCH = getenv("ARCH");
$gInputFile = $argv[1];
$gOutputFile = $argv[2];
$gOutputLDOptsFile = $argv[3];
$gDepFile = ($argc > 4 ? $argv[4] : false);
$gDependencies = array();
$lines = file($argv[1]);
$lDepth = 0;
$lTree = array();
$lStack = array( array("",array()) );
foreach($lines as $line)
{
$line = trim($line);
if($line == "" || $line[0] == "#") continue;
// Directory
if(preg_match('/^Dir\s+"([^"]+)"\s+{$/', $line, $matches))
{
$new = array($matches[1], array());
array_push($lStack, $new);
$lDepth ++;
}
// End of a block
elseif($line == "}")
{
$lDepth --;
$lStack[$lDepth][1][] = array_pop($lStack);
}
// File
elseif(preg_match('/^((?:Opt)?)File\s+"([^"]+)"(?:\s+"([^"]+)")?$/', $line, $matches))
{
$isOptional = $matches[1];
$dstfile = $matches[2];
$path = isset($matches[3]) ? $matches[3] : "";
if( $path == "" ) {
$path = $dstfile;
$dstfile = basename($dstfile);
}
// Parse path components
$path = str_replace("__EXT__", "$ACESSDIR/Externals/Output/$ARCH", $path);
$path = str_replace("__BIN__", "$ACESSDIR/Usermode/Output/$ARCH", $path);
$path = str_replace("__FS__", "$ACESSDIR/Usermode/Filesystem", $path);
$path = str_replace("__SRC__", "$ACESSDIR", $path);
$gDependencies[] = $path;
if( !file_exists($path) )
{
if( $isOptional == "" )
{
// Oops
echo "ERROR: '{$path}' does not exist\n",
exit(1);
}
else
{
// optional file
}
}
else
{
$lStack[$lDepth][1][] = array($dstfile, $path, $isOptional);
}
}
else
{
echo "ERROR: $line\n";
exit(0);
}
}
function hd($fp)
{
//return "0x".str_pad( dechex(ord(fgetc($fp))), 8, "0", STR_PAD_LEFT );
$val = unpack("I", fread($fp, 4));
//print_r($val); exit -1;
return "0x".dechex($val[1]);
}
function hd8($fp)
{
return "0x".str_pad( dechex(ord(fgetc($fp))), 2, "0", STR_PAD_LEFT );
}
$inode = 0;
$gSymFiles = array();
function ProcessFolder($prefix, $items)
{
global $gOutput, $gDependencies;
global $ACESSDIR, $ARCH;
global $inode;
global $gSymFiles;
foreach($items as $i=>$item)
{
$inode ++;
if(is_array($item[1]))
{
ProcessFolder("{$prefix}_{$i}", $item[1]);
$gOutput .= "tInitRD_File {$prefix}_{$i}_entries[] = {\n";
foreach($item[1] as $j=>$child)
{
if($j) $gOutput .= ",\n";
$gOutput .= "\t{\"".addslashes($child[0])."\",&{$prefix}_{$i}_{$j}}";
}
$gOutput .= "\n};\n";
$size = count($item[1]);
$gOutput .= <<<EOF
tVFS_Node {$prefix}_{$i} = {
.NumACLs = 1,
.ACLs = &gVFS_ACL_EveryoneRX,
.Flags = VFS_FFLAG_DIRECTORY,
.Size = $size,
.Inode = {$inode},
.ImplPtr = {$prefix}_{$i}_entries,
.Type = &gInitRD_DirType
};
EOF;
}
else
{
$path = $item[1];
if( DEBUG_ENABLED )
echo $path,"\n";
$size = filesize($path);
$_sym = "_binary_".str_replace(array("/","-",".","+"), "_", $path)."_start";
$gOutput .= "extern Uint8 {$_sym}[];";
$gSymFiles[] = $path;
$gOutput .= <<<EOF
tVFS_Node {$prefix}_{$i} = {
.NumACLs = 1,
.ACLs = &gVFS_ACL_EveryoneRX,
.Flags = 0,
.Size = $size,
.Inode = {$inode},
.ImplPtr = $_sym,
.Type = &gInitRD_FileType
};
EOF;
}
}
}
//print_r($lStack);
//exit(1);
ProcessFolder("gInitRD_Files", $lStack[0][1]);
$gOutput .= "tInitRD_File gInitRD_Root_Files[] = {\n";
foreach($lStack[0][1] as $j=>$child)
{
if($j) $gOutput .= ",\n";
$gOutput .= "\t{\"".addslashes($child[0])."\",&gInitRD_Files_{$j}}";
}
$gOutput .= "\n};\n";
$nRootFiles = count($lStack[0][1]);
$gOutput .= <<<EOF
tVFS_Node gInitRD_RootNode = {
.NumACLs = 1,
.ACLs = &gVFS_ACL_EveryoneRX,
.Flags = VFS_FFLAG_DIRECTORY,
.Size = $nRootFiles,
.ImplPtr = gInitRD_Root_Files,
.Type = &gInitRD_DirType
};
EOF;
$gOutput .= <<<EOF
tVFS_Node * const gInitRD_FileList[] = {
&gInitRD_RootNode
EOF;
function PutNodePointers($prefix, $items)
{
global $gOutput;
foreach($items as $i=>$item)
{
$gOutput .= ",&{$prefix}_{$i}";
if(is_array($item[1]))
{
PutNodePointers("{$prefix}_{$i}", $item[1]);
}
}
}
PutNodePointers("gInitRD_Files", $lStack[0][1]);
$gOutput .= <<<EOF
};
const int giInitRD_NumFiles = sizeof(gInitRD_FileList)/sizeof(gInitRD_FileList[0]);
EOF;
$fp = fopen($gOutputFile, "w");
fputs($fp, $gOutput);
fclose($fp);
// - Create options call
$fp = fopen($gOutputLDOptsFile, "w");
fputs($fp, "--format binary\n");
foreach($gSymFiles as $sym=>$file)
{
fputs($fp, "$file\n");
// fputs($fp, "--defsym $sym=_binary_".$sym_filename."_start\n");
}
fclose($fp);
if($gDepFile !== false)
{
$fp = fopen($gDepFile, "w");
$line = $gOutputFile.":\t".implode(" ", $gDependencies)."\n";
fputs($fp, $line);
foreach( $gDependencies as $dep )
fputs($fp, "$dep: \n");
fclose($fp);
}
?>
...@@ -19,11 +19,6 @@ enum eToken { ...@@ -19,11 +19,6 @@ enum eToken {
TOK_STRING, TOK_STRING,
}; };
struct sPath {
const struct sPath* prev;
const char* name;
};
struct sLexer { struct sLexer {
FILE* file; FILE* file;
enum eToken last_tok; enum eToken last_tok;
...@@ -34,8 +29,11 @@ typedef struct sLexer tLexer; ...@@ -34,8 +29,11 @@ typedef struct sLexer tLexer;
struct sOutState { struct sOutState {
unsigned int next_inode_idx; unsigned int next_inode_idx;
FILE* out_c; FILE* out_c;
FILE* out_dep;
FILE* out_ldopts; FILE* out_ldopts;
//FILE* out_dep;
char** dependencies;
unsigned int num_dependencies;
}; };
typedef struct sOutState tOutState; typedef struct sOutState tOutState;
...@@ -56,8 +54,9 @@ char* Lex_ConsumeYield(struct sLexer* lex); ...@@ -56,8 +54,9 @@ char* Lex_ConsumeYield(struct sLexer* lex);
void Lex_Error(struct sLexer* lex, const char* message); void Lex_Error(struct sLexer* lex, const char* message);
void Lex_Expect(struct sLexer* lex, enum eToken exp); void Lex_Expect(struct sLexer* lex, enum eToken exp);
void ProcessDir(struct sLexer* lex, tOutState* os, unsigned int inode, enum eToken end, const struct sPath* parent_path); void ProcessDir(struct sLexer* lex, tOutState* os, unsigned int inode, enum eToken end);
void AddFile(tOutState* os, tDirEnts* dents, bool is_opt, const struct sPath* dir_path, const char* name, const char* path); void AddFile(tOutState* os, tDirEnts* dents, bool is_opt, const char* name, const char* path);
char* strdup(const char* s);
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
...@@ -99,8 +98,9 @@ int main(int argc, const char *argv[]) ...@@ -99,8 +98,9 @@ int main(int argc, const char *argv[])
tOutState os = { tOutState os = {
1, 1,
fopen(outfile_c, "w"), fopen(outfile_c, "w"),
fopen(outfile_dep, "w"),
fopen(outfile_ldopts, "w"), fopen(outfile_ldopts, "w"),
//fopen(outfile_dep, "w"),
NULL, 0,
}; };
fprintf(os.out_c, fprintf(os.out_c,
...@@ -115,21 +115,32 @@ int main(int argc, const char *argv[]) ...@@ -115,21 +115,32 @@ int main(int argc, const char *argv[])
fprintf(os.out_ldopts, "--format binary\n"); fprintf(os.out_ldopts, "--format binary\n");
struct sPath path = {NULL, ""}; ProcessDir(&lex, &os, 0, TOK_EOF);
ProcessDir(&lex, &os, 0, TOK_EOF, &path);
fprintf(os.out_c, // --- Finalize the C file (node list)
"tVFS_Node * const gInitRD_FileList[] = {" fprintf(os.out_c, "tVFS_Node * const gInitRD_FileList[] = {");
//"&gInitRD_RootNode"
);
for(unsigned int i = 0; i < os.next_inode_idx; i ++ ) for(unsigned int i = 0; i < os.next_inode_idx; i ++ )
fprintf(os.out_c, "&INITRD_%u, ", i); fprintf(os.out_c, "&INITRD_%u, ", i);
fprintf(os.out_c, "};\n"); fprintf(os.out_c, "};\n");
// --- Close running output files
fclose(os.out_c); fclose(os.out_c);
fclose(os.out_dep);
fclose(os.out_ldopts); fclose(os.out_ldopts);
// --- Write the dependency file
FILE* depfile = fopen(outfile_dep, "w");
assert(depfile);
fprintf(depfile, "%s:", outfile_c);
for(unsigned int i = 0; i < os.num_dependencies; i ++)
fprintf(depfile, " %s", os.dependencies[i]);
fprintf(depfile, "\n");
for(unsigned int i = 0; i < os.num_dependencies; i ++) {
fprintf(depfile, "%s:\n", os.dependencies[i]);
free(os.dependencies[i]);
}
free(os.dependencies);
fclose(depfile);
return 0; return 0;
} }
...@@ -140,10 +151,11 @@ void add_dir_ent(tDirEnts* dents, const char* name, unsigned int inode) { ...@@ -140,10 +151,11 @@ void add_dir_ent(tDirEnts* dents, const char* name, unsigned int inode) {
dents->num_ents += 1; dents->num_ents += 1;
dents->ents = realloc( dents->ents, sizeof(tDirEnt*) * dents->num_ents ); dents->ents = realloc( dents->ents, sizeof(tDirEnt*) * dents->num_ents );
assert(dents->ents);
dents->ents[dents->num_ents-1] = de; dents->ents[dents->num_ents-1] = de;
} }
void ProcessDir(struct sLexer* lex, tOutState* os, unsigned int inode, enum eToken end, const struct sPath* parent_path) void ProcessDir(struct sLexer* lex, tOutState* os, unsigned int inode, enum eToken end)
{ {
tDirEnts dents = { 0, NULL }; tDirEnts dents = { 0, NULL };
while( lex->last_tok != end ) while( lex->last_tok != end )
...@@ -164,8 +176,7 @@ void ProcessDir(struct sLexer* lex, tOutState* os, unsigned int inode, enum eTok ...@@ -164,8 +176,7 @@ void ProcessDir(struct sLexer* lex, tOutState* os, unsigned int inode, enum eTok
unsigned int child_inode = os->next_inode_idx ++; unsigned int child_inode = os->next_inode_idx ++;
struct sPath path = {parent_path, name}; ProcessDir(lex, os, child_inode, TOK_BRACE_CLOSE);
ProcessDir(lex, os, child_inode, TOK_BRACE_CLOSE, &path);
add_dir_ent(&dents, name, child_inode); add_dir_ent(&dents, name, child_inode);
...@@ -187,7 +198,7 @@ void ProcessDir(struct sLexer* lex, tOutState* os, unsigned int inode, enum eTok ...@@ -187,7 +198,7 @@ void ProcessDir(struct sLexer* lex, tOutState* os, unsigned int inode, enum eTok
} }
Lex_Expect(lex, TOK_NEWLINE); Lex_Expect(lex, TOK_NEWLINE);
AddFile(os, &dents, is_optional, parent_path, name, path); AddFile(os, &dents, is_optional, name, path);
free(name); free(name);
free(path); free(path);
...@@ -296,7 +307,7 @@ size_t ld_mangle(char* out, const char* in) { ...@@ -296,7 +307,7 @@ size_t ld_mangle(char* out, const char* in) {
return rv; return rv;
} }
void AddFile(tOutState* os, tDirEnts* dents, bool is_opt, const struct sPath* dir_path, const char* name, const char* path) void AddFile(tOutState* os, tDirEnts* dents, bool is_opt, const char* name, const char* path)
{ {
char* realpath; char* realpath;
{ {
...@@ -344,7 +355,12 @@ void AddFile(tOutState* os, tDirEnts* dents, bool is_opt, const struct sPath* di ...@@ -344,7 +355,12 @@ void AddFile(tOutState* os, tDirEnts* dents, bool is_opt, const struct sPath* di
, node_idx, file_size, node_idx, binary_sym , node_idx, file_size, node_idx, binary_sym
); );
free(binary_sym); free(binary_sym);
free(realpath);
os->num_dependencies += 1;
os->dependencies = realloc( os->dependencies, sizeof(*os->dependencies) * os->num_dependencies );
assert(os->dependencies);
os->dependencies[os->num_dependencies-1] = realpath;
//free(realpath);
add_dir_ent(dents, name, node_idx); add_dir_ent(dents, name, node_idx);
} }
...@@ -379,6 +395,7 @@ enum eToken get_token_int(FILE* ifp, char** string) ...@@ -379,6 +395,7 @@ enum eToken get_token_int(FILE* ifp, char** string)
while( isalnum(ch) ) { while( isalnum(ch) ) {
len += 1; len += 1;
s = realloc(s, len+1); s = realloc(s, len+1);
assert(s);
s[len-1] = ch; s[len-1] = ch;
ch = fgetc(ifp); ch = fgetc(ifp);
...@@ -393,6 +410,7 @@ enum eToken get_token_int(FILE* ifp, char** string) ...@@ -393,6 +410,7 @@ enum eToken get_token_int(FILE* ifp, char** string)
{ {
len += 1; len += 1;
s = realloc(s, len+1); s = realloc(s, len+1);
assert(s);
s[len-1] = ch; s[len-1] = ch;
} }
s[len] = '\0'; s[len] = '\0';
...@@ -445,6 +463,7 @@ char* Lex_ConsumeYield(struct sLexer* lex) ...@@ -445,6 +463,7 @@ char* Lex_ConsumeYield(struct sLexer* lex)
} }
void Lex_Error(struct sLexer* lex, const char* string) void Lex_Error(struct sLexer* lex, const char* string)
{ {
(void)lex;
fprintf(stderr, "Parse error: %s\n", string); fprintf(stderr, "Parse error: %s\n", string);
exit(1); exit(1);
} }
...@@ -456,3 +475,12 @@ void Lex_Expect(struct sLexer* lex, enum eToken exp) ...@@ -456,3 +475,12 @@ void Lex_Expect(struct sLexer* lex, enum eToken exp)
} }
} }
char* strdup(const char* s)
{
char* rv = malloc(strlen(s) + 1);
if( rv == NULL )
return NULL;
strcpy(rv, s);
return rv;
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment