Execute the continuation file.

parent d30ee8e5
Pipeline #59280472 passed with stages
in 30 minutes and 56 seconds
#include "asmc.h"
#include "ipxe_asmc_structs.h"
downloaded_file *download_file(const char *url);
void *compile_file(const char *code, const char *symbol, void **buffer);
......@@ -31,6 +31,11 @@ const char *includes[] = {
IPXE_PREFIX "/arch/i386/include/pcbios",
};
const char *includes2[] = {
ASMC_PREFIX,
ASMC_PREFIX "/stdlib",
};
const char *sources[][2] = {
{ASMC_PREFIX "/run_ipxe.c", IPXE_TEMP "/run_ipxe.o"},
{ASMC_PREFIX "/tinycc/lib/libtcc1.c", IPXE_TEMP "/libtcc1.o"},
......@@ -255,12 +260,59 @@ void *pop_from_ipxe() {
coro_t *coro_ipxe;
downloaded_file *download_file(const char *url) {
downloaded_file *download_file(const char *url, const char *dest_file) {
push_to_ipxe(strdup("download"));
push_to_ipxe(strdup(url));
coro_enter(coro_ipxe);
downloaded_file *df = pop_from_ipxe();
return df;
assert(df->size > 0);
/*printf("Received document of %d bytes!\n", df->size);
printf("---\n");
for (size_t i = 0; i < df->size; i++) {
putchar(df->data[i]);
}
printf("---\n");*/
FILE *fout = fopen(dest_file, "wb");
fwrite(df->data, 1, df->size, fout);
fclose(fout);
free(df->data);
free(df);
}
void *compile_file(const char *filename, const char *symbol, void **buffer) {
TCCState *state = tcc_new();
tcc_set_options(state, "-nostdinc -nostdlib");
tcc_set_output_type(state, TCC_OUTPUT_OBJ);
char buf[1024];
sprintf(buf, "%d", __get_handles());
tcc_define_symbol(state, "__HANDLES", buf);
int res;
for (int i = 0; i < sizeof(includes2) / sizeof(includes2[0]); i++) {
res = tcc_add_include_path(state, includes2[i]);
if (res) {
printf("tcc_add_include_path() failed...\n");
return 1;
}
}
res = tcc_add_file(state, filename);
if (res) {
printf("tcc_compile_string() failed...\n");
return 1;
}
int size = tcc_relocate(state, NULL);
if (size < 0) {
printf("tcc_relocate() failed...\n");
return 1;
}
*buffer = malloc(size);
size = tcc_relocate(state, *buffer);
if (size < 0) {
printf("second tcc_relocate() failed...\n");
return 1;
}
void *symb = tcc_get_symbol(state, symbol);
tcc_delete(state);
return symb;
}
int main(int argc, char *argv[]) {
......@@ -342,16 +394,12 @@ int main(int argc, char *argv[]) {
// Download the continuation program
const char *url = "http://10.0.2.2:8080/continue.c";
printf("Request to download %s\n", url);
downloaded_file *df = download_file(url);
assert(df->size > 0);
printf("Received document of %d bytes!\n", df->size);
printf("---\n");
for (size_t i = 0; i < df->size; i++) {
putchar(df->data[i]);
}
printf("---\n");
free(df->data);
free(df);
download_file(url, "/ram/continue.c");
void *cont_buf;
int (*cont_symb)(int, char*[]) = compile_file("/ram/continue.c", "_start", &cont_buf);
char *cont_argv[] = {"_main"};
cont_symb(sizeof(cont_argv) / sizeof(cont_argv[0]), cont_argv);
free(cont_buf);
printf("Request to exit iPXE\n");
push_to_ipxe(strdup("exit"));
......
Markdown is supported
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