Bootstrap.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include <string.h>
  2. #include "pal.h"
  3. #include "pal_debug.h"
  4. static int test_data = 0;
  5. static int test_func(void) {
  6. return 0;
  7. }
  8. int main(int argc, char** argv, char** envp) {
  9. /* check if the program is loaded */
  10. pal_printf("User Program Started\n");
  11. /* check control block */
  12. /* check executable name */
  13. pal_printf("Loaded Executable: %s\n", pal_control.executable);
  14. /* check manifest name */
  15. char manifest[30];
  16. DkStreamGetName(pal_control.manifest_handle, manifest, 30);
  17. pal_printf("Loaded Manifest: %s\n", manifest);
  18. /* check arguments */
  19. pal_printf("# of Arguments: %d\n", argc);
  20. for (int i = 0; i < argc; i++) {
  21. pal_printf("argv[%d] = %s\n", i, argv[i]);
  22. }
  23. /* unique process ID */
  24. pal_printf("Process ID: %016lx\n", pal_control.process_id);
  25. /* unique host ID */
  26. pal_printf("Host ID: %016lx\n", pal_control.host_id);
  27. /* parent process */
  28. pal_printf("Parent Process: %p\n", pal_control.parent_process);
  29. /* test debug stream */
  30. char* msg = "Written to Debug Stream\n";
  31. DkStreamWrite(pal_control.debug_stream, 0, strlen(msg), msg, NULL);
  32. /* Allocation Alignment */
  33. pal_printf("Allocation Alignment: %ld\n", pal_control.alloc_align);
  34. /* user address range */
  35. pal_printf("User Address Range: %p - %p\n", pal_control.user_address.start,
  36. pal_control.user_address.end);
  37. if (pal_control.user_address.start && pal_control.user_address.end &&
  38. pal_control.user_address.start < pal_control.user_address.end)
  39. pal_printf("User Address Range OK\n");
  40. /* executable address range */
  41. pal_printf("Executable Range: %p - %p\n", pal_control.executable_range.start,
  42. pal_control.executable_range.end);
  43. if (pal_control.executable_range.start && pal_control.executable_range.end &&
  44. pal_control.executable_range.start < (void*)&test_data &&
  45. (void*)&test_data < pal_control.executable_range.end &&
  46. pal_control.executable_range.start < (void*)&test_func &&
  47. (void*)&test_func < pal_control.executable_range.end)
  48. pal_printf("Executable Range OK\n");
  49. pal_printf("CPU num: %ld\n", pal_control.cpu_info.cpu_num);
  50. pal_printf("CPU vendor: %s\n", pal_control.cpu_info.cpu_vendor);
  51. pal_printf("CPU brand: %s\n", pal_control.cpu_info.cpu_brand);
  52. pal_printf("CPU family: %ld\n", pal_control.cpu_info.cpu_family);
  53. pal_printf("CPU model: %ld\n", pal_control.cpu_info.cpu_model);
  54. pal_printf("CPU stepping: %ld\n", pal_control.cpu_info.cpu_stepping);
  55. pal_printf("CPU flags: %s\n", pal_control.cpu_info.cpu_flags);
  56. return 0;
  57. }