1
0

ipxe_handover.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* This file is part of asmc, a bootstrapping OS with minimal seed
  2. Copyright (C) 2019 Giovanni Mascellani <gio@debian.org>
  3. https://gitlab.com/giomasce/asmc
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <https://www.gnu.org/licenses/>. */
  14. #ifndef __IPXE_HANDOVER_H
  15. #define __IPXE_HANDOVER_H
  16. typedef struct {
  17. char *name;
  18. char *data;
  19. int len;
  20. } table_sect;
  21. typedef struct ipxe_list_elem {
  22. struct ipxe_list_elem *next;
  23. void *msg;
  24. } ipxe_list_elem;
  25. typedef struct ipxe_list {
  26. ipxe_list_elem *head;
  27. ipxe_list_elem *tail;
  28. } ipxe_list;
  29. typedef struct {
  30. int sects_num;
  31. table_sect *sects;
  32. ipxe_list to_ipxe;
  33. ipxe_list from_ipxe;
  34. void (*coro_yield)();
  35. void *(*malloc)(size_t size);
  36. void (*free)(void *ptr);
  37. void *(*realloc)(void *ptr, size_t size);
  38. } ipxe_handover;
  39. static void ipxe_list_reset(ipxe_list *list) {
  40. list->head = 0;
  41. list->tail = 0;
  42. }
  43. static void ipxe_list_push(ipxe_handover *ih, ipxe_list *list, void *msg) {
  44. ipxe_list_elem *e = ih->malloc(sizeof(ipxe_list_elem));
  45. e->next = 0;
  46. e->msg = msg;
  47. if (!list->head) {
  48. // Empty list, this is the first and last item
  49. list->head = e;
  50. list->tail = e;
  51. } else {
  52. // Pushing after tail
  53. list->tail->next = e;
  54. list->tail = e;
  55. }
  56. }
  57. static void *ipxe_list_pop(ipxe_handover *ih, ipxe_list *list) {
  58. ipxe_list_elem *e = list->head;
  59. if (!e) {
  60. // Empty list, return zero
  61. return 0;
  62. } else {
  63. // Return head element
  64. void *msg = e->msg;
  65. list->head = e->next;
  66. if (!list->head) {
  67. list->tail = 0;
  68. }
  69. ih->free(e);
  70. return msg;
  71. }
  72. }
  73. #endif