Skip to content

Commit

Permalink
vita-libs-gen: Use firmware field
Browse files Browse the repository at this point in the history
if filled `firmware` in the root and this value isn't `3.60`,
will attach postfix before `_stub.a`

eg;
pass to
```
firmware: 3.67
```
all generated libs will end with `_367_stub.a` like `libSceCpuForKernel_367_stub.a`

Related vitasdk/vita-headers#300
  • Loading branch information
d3m3vilurr committed Mar 5, 2018
1 parent c15d514 commit ef8d82b
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 41 deletions.
30 changes: 23 additions & 7 deletions src/vita-import-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,33 @@ vita_imports_t *read_vita_imports(yaml_document *doc) {
for(int n = 0; n < root->count; n++){
// check lhs is a scalar
if (is_scalar(root->pairs[n]->lhs)) {

if (strcmp(root->pairs[n]->lhs->data.scalar.value, "modules")==0) {
const char *root_value = root->pairs[n]->lhs->data.scalar.value;
if (strcmp(root_value, "firmware") == 0) {
if (!is_scalar(root->pairs[n]->rhs))
return NULL;
const char *firm = root->pairs[n]->rhs->data.scalar.value;
// skip default firmware
if (strcmp(firm, "3.60") == 0)
continue;
imports->firmware = strdup(firm);
int i = 0;
int j = 0;
imports->postfix[j++] = '_';
while (firm[i]) {
const char v = firm[i++];
if (v == '.')
continue;
imports->postfix[j++] = v;
}
}
else if (strcmp(root_value, "modules") == 0) {
if (yaml_iterate_mapping(root->pairs[n]->rhs, (mapping_functor)process_import_list, imports) < 0)
return NULL;
continue;
}

fprintf(stderr, "warning: line: %zd, column: %zd, unknow tag '%s'.\n", root->pairs[n]->lhs->position.line, root->pairs[n]->lhs->position.column, root->pairs[n]->lhs->data.scalar.value);

else {
fprintf(stderr, "warning: line: %zd, column: %zd, unknow tag '%s'.\n", root->pairs[n]->lhs->position.line, root->pairs[n]->lhs->position.column, root->pairs[n]->lhs->data.scalar.value);
}
}

}

return imports;
Expand Down
9 changes: 9 additions & 0 deletions src/vita-import.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ vita_imports_t *vita_imports_new(int n_libs)
if (imp == NULL)
return NULL;

imp->postfix = calloc(64, sizeof(char));

imp->firmware = NULL;

imp->n_libs = n_libs;

imp->libs = calloc(n_libs, sizeof(*imp->libs));
Expand All @@ -22,6 +26,11 @@ void vita_imports_free(vita_imports_t *imp)
for (i = 0; i < imp->n_libs; i++) {
vita_imports_lib_free(imp->libs[i]);
}

if (imp->firmware)
free(imp->firmware);

free(imp->postfix);
free(imp);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/vita-import.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ typedef struct {
} vita_imports_lib_t;

typedef struct {
char *firmware;
char *postfix;
vita_imports_lib_t **libs;
int n_libs;
} vita_imports_t;
Expand Down
82 changes: 48 additions & 34 deletions src/vita-libs-gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@

#define KERNEL_LIBS_STUB "SceKernel"

typedef struct {
int num;
struct {
const char *name;
const char *postfix;
} names[1024];
} libs_t;

void usage();
int generate_assembly(vita_imports_t **imports, int imports_count);
int generate_makefile(vita_imports_t **imports, int imports_count);
Expand Down Expand Up @@ -92,6 +100,7 @@ int generate_assembly(vita_imports_t **imports, int imports_count)

for (h = 0; h < imports_count; h++) {
vita_imports_t *imp = imports[h];

for (i = 0; i < imp->n_libs; i++) {
vita_imports_lib_t *library = imp->libs[i];
for (j = 0; j < library->n_modules; j++) {
Expand All @@ -101,7 +110,7 @@ int generate_assembly(vita_imports_t **imports, int imports_count)
vita_imports_stub_t *function = module->functions[k];
const char *fname = function->name;
char filename[4096];
snprintf(filename, sizeof(filename), "%s_%s_%s.S", library->name, module->name, fname);
snprintf(filename, sizeof(filename), "%s_%s_%s%s.S", library->name, module->name, fname, imp->postfix);
if ((fp = fopen(filename, "w")) == NULL)
return 0;
fprintf(fp, ".arch armv7a\n\n");
Expand Down Expand Up @@ -129,7 +138,7 @@ int generate_assembly(vita_imports_t **imports, int imports_count)
vita_imports_stub_t *variable = module->variables[k];
const char *vname = variable->name;
char filename[4096];
snprintf(filename, sizeof(filename), "%s_%s_%s.S", library->name, module->name, vname);
snprintf(filename, sizeof(filename), "%s_%s_%s%s.S", library->name, module->name, vname, imp->postfix);
if ((fp = fopen(filename, "w")) == NULL)
return 0;
fprintf(fp, ".arch armv7a\n\n");
Expand Down Expand Up @@ -177,21 +186,21 @@ void write_symbol(const char *symbol, int is_kernel)
fprintf(fp, "%s", symbol); // write regardless if its kernel or not
}

void write_cmake_sources(FILE *fp, const char *modname, vita_imports_module_t *library)
void write_cmake_sources(FILE *fp, const char *modname, const char *postfix, vita_imports_module_t *library)
{
int k;

for (k = 0; k < library->n_functions; k++) {
vita_imports_stub_t *function = library->functions[k];
fprintf(fp, "\t\"%s_%s_%s.S\"\n", modname, library->name, function->name);
fprintf(fp, "\t\"%s_%s_%s%s.S\"\n", modname, library->name, function->name, postfix);
}
for (k = 0; k < library->n_variables; k++) {
vita_imports_stub_t *variable = library->variables[k];
fprintf(fp, "\t\"%s_%s_%s.S\"\n", modname, library->name, variable->name);
fprintf(fp, "\t\"%s_%s_%s%s.S\"\n", modname, library->name, variable->name, postfix);
}
}

int generate_cmake_user(FILE *fp, vita_imports_lib_t *module)
int generate_cmake_user(FILE *fp, const char *postfix, vita_imports_lib_t *module)
{
int i;
int found_libs = 0;
Expand All @@ -206,11 +215,11 @@ int generate_cmake_user(FILE *fp, vita_imports_lib_t *module)

if (!found_libs)
{
fprintf(fp, "set(%s_ASM\n", module->name);
fprintf(fp, "set(%s%s_ASM\n", module->name, postfix);
found_libs = 1;
}

write_cmake_sources(fp, module->name, library);
write_cmake_sources(fp, module->name, postfix, library);
}

if (found_libs)
Expand All @@ -221,13 +230,13 @@ int generate_cmake_user(FILE *fp, vita_imports_lib_t *module)
return found_libs;
}

int generate_cmake_kernel(FILE *fp, const char *modname, vita_imports_module_t *library)
int generate_cmake_kernel(FILE *fp, const char *modname, const char *postfix, vita_imports_module_t *library)
{
if (!library->n_functions && !library->n_variables)
return 0;

fprintf(fp, "set(%s_ASM\n", library->name);
write_cmake_sources(fp, modname, library);
fprintf(fp, "set(%s%s_ASM\n", library->name, postfix);
write_cmake_sources(fp, modname, postfix, library);
fputs(")\n\n", fp);

return 1;
Expand All @@ -239,10 +248,8 @@ int generate_cmake(vita_imports_t **imports, int imports_count)
int is_special;

// TODO: something dynamic
const char *user_libs[1024];
int num_user_libs = 0;
const char *kernel_libs[1024];
int num_kernel_libs = 0;
libs_t user_libs = {0};
libs_t kernel_libs = {0};

if ((fp = fopen("CMakeLists.txt", "w")) == NULL) {
return 0;
Expand All @@ -269,9 +276,11 @@ int generate_cmake(vita_imports_t **imports, int imports_count)
vita_imports_lib_t *module = imp->libs[i];

// generate user libs first
if (generate_cmake_user(fp, module))
if (generate_cmake_user(fp, imp->postfix, module))
{
user_libs[num_user_libs++] = module->name;
user_libs.names[user_libs.num].name = module->name;
user_libs.names[user_libs.num].postfix = imp->postfix;
user_libs.num++;
}

for (j = 0; j < imp->libs[i]->n_modules; j++)
Expand All @@ -281,39 +290,41 @@ int generate_cmake(vita_imports_t **imports, int imports_count)
if (!library->is_kernel)
continue;

if (generate_cmake_kernel(fp, module->name, library))
if (generate_cmake_kernel(fp, module->name, imp->postfix, library))
{
kernel_libs[num_kernel_libs++] = library->name;
kernel_libs.names[kernel_libs.num].name = library->name;
kernel_libs.names[kernel_libs.num].postfix = imp->postfix;
kernel_libs.num++;
}
}
}
}

if (num_user_libs > 0)
if (user_libs.num > 0)
{
fputs("set(USER_LIBRARIES\n", fp);

for (i = 0; i < num_user_libs; ++i)
for (i = 0; i < user_libs.num; ++i)
{
fprintf(fp, "\t\"%s\"\n", user_libs[i]);
fprintf(fp, "\t\"%s%s\"\n", user_libs.names[i].name, user_libs.names[i].postfix);
}

fputs(")\n\n", fp);
}

if (num_kernel_libs > 0)
if (kernel_libs.num > 0)
{
fputs("set(KERNEL_LIBRARIES\n", fp);

for (i = 0; i < num_kernel_libs; ++i)
for (i = 0; i < kernel_libs.num; ++i)
{
fprintf(fp, "\t\"%s\"\n", kernel_libs[i]);
fprintf(fp, "\t\"%s%s\"\n", kernel_libs.names[i].name, kernel_libs.names[i].postfix);
}

fputs(")\n\n", fp);
}

if (num_user_libs > 0)
if (user_libs.num > 0)
{
fputs(
"foreach(library ${USER_LIBRARIES})\n"
Expand All @@ -324,7 +335,7 @@ int generate_cmake(vita_imports_t **imports, int imports_count)
"endforeach(library)\n\n", fp);
}

if (num_kernel_libs > 0)
if (kernel_libs.num > 0)
{
fputs(
"foreach(library ${KERNEL_LIBRARIES})\n"
Expand Down Expand Up @@ -363,32 +374,35 @@ int generate_makefile(vita_imports_t **imports, int imports_count)

for (h = 0; h < imports_count; h++) {
vita_imports_t *imp = imports[h];

for (i = 0; i < imp->n_libs; i++) {
fprintf(fp, " lib%s_stub.a", imp->libs[i]->name);
fprintf(fp, " lib%s%s_stub.a", imp->libs[i]->name, imp->postfix);

for (j = 0; j < imp->libs[i]->n_modules; j++) {
vita_imports_module_t *module = imp->libs[i]->modules[j];

if (!module->is_kernel)
continue;

fprintf(fp, " lib%s_stub.a", module->name);
fprintf(fp, " lib%s%s_stub.a", module->name, imp->postfix);
}
}
}

fprintf(fp, "\nTARGETS_WEAK =");
for (h = 0; h < imports_count; h++) {
vita_imports_t *imp = imports[h];

for (i = 0; i < imp->n_libs; i++) {
fprintf(fp, " lib%s_stub_weak.a", imp->libs[i]->name);
fprintf(fp, " lib%s%s_stub_weak.a", imp->libs[i]->name, imp->postfix);
}
}

fprintf(fp, "\n\n");

for (h = 0; h < imports_count; h++) {
vita_imports_t *imp = imports[h];

for (i = 0; i < imp->n_libs; i++) {
vita_imports_lib_t *library = imp->libs[i];
is_special = (strcmp(KERNEL_LIBS_STUB, library->name) == 0);
Expand All @@ -407,12 +421,12 @@ int generate_makefile(vita_imports_t **imports, int imports_count)
char buf[4096];
for (k = 0; k < module->n_functions; k++) {
vita_imports_stub_t *function = module->functions[k];
snprintf(buf, sizeof(buf), " %s_%s_%s.%s", library->name, module->name, function->name, weak ? "wo" : "o");
snprintf(buf, sizeof(buf), " %s_%s_%s%s.%s", library->name, module->name, function->name, imp->postfix, weak ? "wo" : "o");
write_symbol(buf, is_special);
}
for (k = 0; k < module->n_variables; k++) {
vita_imports_stub_t *variable = module->variables[k];
snprintf(buf, sizeof(buf), " %s_%s_%s.%s", library->name, module->name, variable->name, weak ? "wo" : "o");
snprintf(buf, sizeof(buf), " %s_%s_%s%s.%s", library->name, module->name, variable->name, imp->postfix, weak ? "wo" : "o");
write_symbol(buf, is_special);
}
}
Expand All @@ -434,13 +448,13 @@ int generate_makefile(vita_imports_t **imports, int imports_count)

for (k = 0; k < module->n_functions; k++) {
vita_imports_stub_t *function = module->functions[k];
snprintf(buf, sizeof(buf), " %s_%s_%s.o", library->name, module->name, function->name);
snprintf(buf, sizeof(buf), " %s_%s_%s%s.o", library->name, module->name, function->name, imp->postfix);
write_symbol(buf, 1);
}

for (k = 0; k < module->n_variables; k++) {
vita_imports_stub_t *variable = module->variables[k];
snprintf(buf, sizeof(buf), " %s_%s_%s.o", library->name, module->name, variable->name);
snprintf(buf, sizeof(buf), " %s_%s_%s%s.o", library->name, module->name, variable->name, imp->postfix);
write_symbol(buf, 1);
}

Expand Down

0 comments on commit ef8d82b

Please sign in to comment.