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.

48 lines
1.4KB

  1. #include <stdint.h>
  2. #include <stdbool.h>
  3. #define SP_ADDR 0xffff
  4. #define RS_ADDR 0xff00
  5. #define SYSVARS RS_ADDR-0x80
  6. typedef uint8_t byte;
  7. typedef uint16_t word;
  8. // Native words in this C Forth VMs are indexed in an array. The word in memory
  9. // is the typical 0x00 to indicate native, followed by an index byte. The
  10. // Execute routine will then know which native word to execute.
  11. typedef void (*NativeWord) ();
  12. typedef byte (*IORD) ();
  13. typedef void (*IOWR) (byte data);
  14. /* Native word placement
  15. Being a C VM, all actual native code is outside the VM's memory. However,
  16. we have a stable ABI to conform to. VM_init() configures the memory by
  17. placing references to stable words at proper offsets, and then add all other
  18. native words next to it. This will result in a "boot binary" that is much
  19. more compact than a real Collapse OS memory layout.
  20. */
  21. typedef struct {
  22. byte mem[0x10000];
  23. word SP;
  24. word RS;
  25. word IP;
  26. NativeWord nativew[0x100];
  27. byte nativew_count;
  28. // Array of 0x100 function pointers to IO read and write routines. Leave to
  29. // NULL when IO port is unhandled.
  30. IORD iord[0x100];
  31. IOWR iowr[0x100];
  32. word xcurrent; // only used during native bootstrap
  33. word maxRS;
  34. word minSP;
  35. bool running;
  36. bool uflw;
  37. } VM;
  38. VM* VM_init();
  39. void VM_deinit();
  40. bool VM_steps(int n);
  41. void VM_memdump();
  42. void VM_debugstr(char *s);
  43. void VM_printdbg();