bootarg.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* $OpenBSD: bootarg.c,v 1.11 2014/06/27 16:05:20 tobias Exp $ */
  2. /*
  3. * Copyright (c) 1997,1998 Michael Shalayeff
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  16. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  21. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  23. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25. * SUCH DAMAGE.
  26. *
  27. */
  28. #include <lib/libsa/stand.h>
  29. #include <stand/boot/bootarg.h>
  30. static bootarg_t *bootarg_list;
  31. void
  32. addbootarg(int t, size_t l, void *p)
  33. {
  34. bootarg_t *q = alloc(sizeof(*q) + l - sizeof(q->ba_arg));
  35. q->ba_type = t;
  36. q->ba_size = sizeof(*q) + l - sizeof(q->ba_arg);
  37. bcopy(p, q->ba_arg, l);
  38. q->ba_next = bootarg_list;
  39. bootarg_list = q;
  40. }
  41. void
  42. makebootargs(caddr_t v, size_t *lenp)
  43. {
  44. bootarg_t *p;
  45. u_char *q;
  46. size_t l;
  47. /* get total size */
  48. l = sizeof(*p);
  49. for (p = bootarg_list; p != NULL; p = p->ba_next) {
  50. l += p->ba_size;
  51. if (*lenp < l) {
  52. #ifdef DEBUG
  53. printf("makebootargs: too many args\n");
  54. #endif
  55. l -= p->ba_size;
  56. break;
  57. }
  58. }
  59. *lenp = l;
  60. /* copy them out */
  61. for (p = bootarg_list, q = v;
  62. p != NULL && ((q + p->ba_size) - (u_char *)v) <= l - sizeof(*p);
  63. q += p->ba_size, p = p->ba_next) {
  64. #ifdef DEBUG
  65. printf("%d,%d ", p->ba_type, p->ba_size);
  66. #endif
  67. bcopy(p, q, p->ba_size);
  68. }
  69. p = (bootarg_t *)q;
  70. p->ba_type = BOOTARG_END;
  71. }