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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. /**
  19. * @file
  20. *
  21. * PXE image format
  22. *
  23. */
  24. #include <pxe.h>
  25. #include <pxe_call.h>
  26. #include <gpxe/uaccess.h>
  27. #include <gpxe/image.h>
  28. #include <gpxe/segment.h>
  29. #include <gpxe/netdevice.h>
  30. /** PXE load address segment */
  31. #define PXE_LOAD_SEGMENT 0
  32. /** PXE load address offset */
  33. #define PXE_LOAD_OFFSET 0x7c00
  34. struct image_type pxe_image_type __image_type ( PROBE_PXE );
  35. /**
  36. * Execute PXE image
  37. *
  38. * @v image PXE image
  39. * @ret rc Return status code
  40. */
  41. static int pxe_exec ( struct image *image __unused ) {
  42. struct net_device *netdev;
  43. int discard_b, discard_c;
  44. uint16_t rc;
  45. /* Ensure that PXE stack is ready to use */
  46. pxe_init_structures();
  47. pxe_hook_int1a();
  48. /* Arbitrarily pick the first open network device to use for PXE */
  49. for_each_netdev ( netdev ) {
  50. pxe_netdev = netdev;
  51. break;
  52. }
  53. /* Far call to PXE NBP */
  54. __asm__ __volatile__ ( REAL_CODE ( "pushw %%cx\n\t"
  55. "pushw %%ax\n\t"
  56. "movw %%cx, %%es\n\t"
  57. "lcall $0, $0x7c00\n\t"
  58. "addw $4, %%sp\n\t" )
  59. : "=a" ( rc ), "=b" ( discard_b ),
  60. "=c" ( discard_c )
  61. : "a" ( & __from_text16 ( ppxe ) ),
  62. "b" ( & __from_text16 ( pxenv ) ),
  63. "c" ( rm_cs )
  64. : "edx", "esi", "edi", "ebp", "memory" );
  65. return rc;
  66. }
  67. /**
  68. * Load PXE image into memory
  69. *
  70. * @v image PXE file
  71. * @ret rc Return status code
  72. */
  73. int pxe_load ( struct image *image ) {
  74. userptr_t buffer = real_to_user ( 0, 0x7c00 );
  75. size_t filesz = image->len;
  76. size_t memsz = image->len;
  77. int rc;
  78. /* There are no signature checks for PXE; we will accept anything */
  79. if ( ! image->type )
  80. image->type = &pxe_image_type;
  81. /* Verify and prepare segment */
  82. if ( ( rc = prep_segment ( buffer, filesz, memsz ) ) != 0 ) {
  83. DBG ( "PXE image could not prepare segment: %s\n",
  84. strerror ( rc ) );
  85. return rc;
  86. }
  87. /* Copy image to segment */
  88. memcpy_user ( buffer, 0, image->data, 0, filesz );
  89. return 0;
  90. }
  91. /** PXE image type */
  92. struct image_type pxe_image_type __image_type ( PROBE_PXE ) = {
  93. .name = "PXE",
  94. .load = pxe_load,
  95. .exec = pxe_exec,
  96. };