cbtable.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2007,2008,2013 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <grub/i386/coreboot/memory.h>
  19. #include <grub/coreboot/lbio.h>
  20. #include <grub/types.h>
  21. #include <grub/err.h>
  22. #include <grub/misc.h>
  23. #include <grub/dl.h>
  24. #pragma GCC diagnostic ignored "-Wcast-align"
  25. /* Helper for grub_linuxbios_table_iterate. */
  26. int
  27. grub_linuxbios_check_signature (grub_linuxbios_table_header_t tbl_header)
  28. {
  29. if (! grub_memcmp (tbl_header->signature, "LBIO", 4))
  30. return 1;
  31. return 0;
  32. }
  33. grub_err_t
  34. grub_linuxbios_table_iterate (int (*hook) (grub_linuxbios_table_item_t,
  35. void *),
  36. void *hook_data)
  37. {
  38. grub_linuxbios_table_header_t table_header = grub_linuxbios_get_tables ();
  39. grub_linuxbios_table_item_t table_item;
  40. if (!table_header)
  41. return 0;
  42. signature_found:
  43. table_item =
  44. (grub_linuxbios_table_item_t) ((char *) table_header +
  45. table_header->header_size);
  46. for (; table_item < (grub_linuxbios_table_item_t) ((char *) table_header
  47. + table_header->header_size
  48. + table_header->table_size);
  49. table_item = (grub_linuxbios_table_item_t) ((char *) table_item + table_item->size))
  50. {
  51. if (table_item->tag == GRUB_LINUXBIOS_MEMBER_LINK
  52. && grub_linuxbios_check_signature ((grub_linuxbios_table_header_t) (grub_addr_t)
  53. *(grub_uint64_t *) (table_item + 1)))
  54. {
  55. table_header = (grub_linuxbios_table_header_t) (grub_addr_t)
  56. *(grub_uint64_t *) (table_item + 1);
  57. goto signature_found;
  58. }
  59. if (hook (table_item, hook_data))
  60. return 1;
  61. }
  62. return 0;
  63. }