HACKING 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. Copyright (C) 2018 Ariadne Devos
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. -----
  13. See process/patches.md for how to send patches upstream.
  14. See process/bugs.md for a list of known bugs to hack upon.
  15. See process/bug-reporting.md for how to report bugs.
  16. # Support a new architecture
  17. (BUG: unportable)
  18. See README for a list of supported architectures.
  19. (This assumes an architecture with a stack. You can do things differently, this
  20. is only a proposal.)
  21. Create a file lco-$ARCH.S (replace $ARCH with your architecture). Export two
  22. functions: _lco_switch and _lco_call. _lco_switch is a two-argument function,
  23. declared in lco.c. It switches from one coroutine to another.
  24. > extern void
  25. > _lco_switch(void *next_sp, void **current_sp);
  26. This function must save all registers that might be clobbered by the next
  27. coroutine on the stack, that must remain intact according to the ABI if this
  28. function would be a normal C function, except the stack pointer.
  29. (Probably, save all callee-saved registers except the stack pointer).
  30. The stack pointer must be saved in *current_sp.
  31. Then change stack pointer to next_sp, restore saved registers and return.
  32. _lco_call is the starting point for a coroutine.
  33. _lco_call is a function with a non-standard ABI. Let it take an argument from
  34. a normally callee-saved register. This is a lco_coroutine co. Do a tail-call
  35. into co->entry(co).