Mirror of CollapseOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.6KB

  1. #include <stdint.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #include "vm.h"
  5. #ifndef BLKFS_PATH
  6. #error BLKFS_PATH needed
  7. #endif
  8. #ifndef FBIN_PATH
  9. #error FBIN_PATH needed
  10. #endif
  11. #define RAMSTART 0
  12. #define STDIO_PORT 0x00
  13. // To know which part of RAM to dump, we listen to port 2, which at the end of
  14. // its compilation process, spits its HERE addr to port 2 (MSB first)
  15. #define HERE_PORT 0x02
  16. VM *vm;
  17. // We support double-pokes, that is, a first poke to tell where to start the
  18. // dump and a second one to tell where to stop. If there is only one poke, it's
  19. // then ending HERE and we start at sizeof(KERNEL).
  20. static uint16_t start_here = 0;
  21. static uint16_t end_here = 0;
  22. static uint8_t iord_stdio()
  23. {
  24. int c = getc(stdin);
  25. if (c == EOF) {
  26. vm->running = false;
  27. }
  28. return (uint8_t)c;
  29. }
  30. static void iowr_stdio(uint8_t val)
  31. {
  32. // comment if you don't like verbose staging output
  33. putc(val, stderr);
  34. }
  35. static void iowr_here(uint8_t val)
  36. {
  37. start_here <<=8;
  38. start_here |= (end_here >> 8);
  39. end_here <<= 8;
  40. end_here |= val;
  41. }
  42. int main(int argc, char *argv[])
  43. {
  44. if (argc < 2) {
  45. vm = VM_init(FBIN_PATH, BLKFS_PATH);
  46. } else {
  47. vm = VM_init(FBIN_PATH, argv[1]);
  48. }
  49. if (vm == NULL) {
  50. return 1;
  51. }
  52. vm->iord[STDIO_PORT] = iord_stdio;
  53. vm->iowr[STDIO_PORT] = iowr_stdio;
  54. vm->iowr[HERE_PORT] = iowr_here;
  55. while (VM_steps(1));
  56. // We're done, now let's spit dict data
  57. for (int i=start_here; i<end_here; i++) {
  58. putchar(vm->mem[i]);
  59. }
  60. VM_printdbg();
  61. VM_deinit();
  62. return 0;
  63. }