Mirror of CollapseOS
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

68 rindas
1.5KB

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