Browse Source

Debug code.

Giovanni Mascellani 4 years ago
parent
commit
1a9fb94dda
2 changed files with 9 additions and 2 deletions
  1. 4 0
      diskfs/coros.h
  2. 5 2
      diskfs/run_tcc_ipxe.c

+ 4 - 0
diskfs/coros.h

@@ -3,6 +3,7 @@
 #include <stdbool.h>
 #include <string.h>
 #include <setjmp.h>
+#include <stdio.h>
 
 typedef struct {
     bool runnable;
@@ -19,9 +20,11 @@ void coro_enter(coro_t *coro) {
     _force_assert(!curr_coro);
     _force_assert(coro->runnable);
     curr_coro = coro;
+    printf("Entering coroutine...\n");
     if (setjmp(coro->caller_regs) == 0) {
         longjmp(coro->callee_regs, 1);
     }
+    printf("Exiting coroutine...\n");
     curr_coro = NULL;
 }
 
@@ -53,6 +56,7 @@ coro_t *coro_init_with_stack_size(void (*target)(void*), void *ctx, size_t stack
     ret->ctx = ctx;
     ret->callee_regs.esp = ((unsigned long) ret->stack) + stack_size;
     ret->callee_regs.eip = (unsigned long) &coro_wrapper;
+    printf("Creating coroutine with stack %x:%x and target %x\n", ret->stack, ret->stack + stack_size, target);
     return ret;
 }
 

+ 5 - 2
diskfs/run_tcc_ipxe.c

@@ -387,13 +387,15 @@ int main(int argc, char *argv[]) {
             return 1;
         }
     }
-    //res = tcc_output_file(state, IPXE_TEMP "/ipxe.o");
-    res = tcc_relocate(state, TCC_RELOCATE_AUTO);
+    size_t ipxe_size = tcc_relocate(state, NULL);
+    void *ipxe_buf = malloc(ipxe_size);
+    res = tcc_relocate(state, ipxe_buf);
     if (res) {
         printf("tcc_relocate() failed...\n");
         return 1;
     }
     printf(" done!\n");
+    printf("iPXE compiled to %x:%x\n", ipxe_buf, ipxe_buf + ipxe_size);
 
     // Start iPXE in a dedicated coroutine
     void (*main_symb)(void*) = tcc_get_symbol(state, "pre_main");
@@ -431,6 +433,7 @@ int main(int argc, char *argv[]) {
     printf("Returning from iPXE!\n");
     coro_destroy(coro_ipxe);
     free_handover(&ih);
+    free(ipxe_buf);
     tcc_delete(state);
 
     return res;