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.

hdprefix.S 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. FILE_LICENCE ( GPL2_OR_LATER )
  2. .text
  3. .arch i386
  4. .section ".prefix", "awx", @progbits
  5. .code16
  6. .org 0
  7. movw $load_image, %bp
  8. jmp find_active_partition
  9. #include "bootpart.S"
  10. load_image:
  11. /* Get disk geometry */
  12. pushal
  13. pushw %es
  14. movb $0x08, %ah
  15. int $0x13
  16. jc load_failed
  17. movb %cl, max_sector
  18. movb %dh, max_head
  19. popw %es
  20. popal
  21. 1: /* Read to end of current track */
  22. movb %cl, %al
  23. negb %al
  24. addb max_sector, %al
  25. incb %al
  26. andb $0x3f, %al
  27. movzbl %al, %eax
  28. call *read_sectors
  29. jc load_failed
  30. /* Update %es */
  31. movw %es, %bx
  32. shll $5, %eax
  33. addw %ax, %bx
  34. movw %bx, %es
  35. shrl $5, %eax
  36. /* Update LBA address */
  37. addl %eax, %edi
  38. adcl $0, %esi
  39. /* Update CHS address */
  40. andb $0xc0, %cl
  41. orb $0x01, %cl
  42. incb %dh
  43. cmpb max_head, %dh
  44. jbe 2f
  45. xorb %dh, %dh
  46. incb %ch
  47. jnc 2f
  48. addb $0xc0, %cl
  49. 2:
  50. /* Loop until whole image is read */
  51. subl %eax, load_length
  52. ja 1b
  53. ljmp $BOOT_SEG, $start_image
  54. max_sector:
  55. .byte 0
  56. max_head:
  57. .byte 0
  58. load_length:
  59. .long 0
  60. .section ".zinfo.fixup", "a", @progbits /* Compressor fixups */
  61. .ascii "ADDL"
  62. .long load_length
  63. .long 512
  64. .long 0
  65. .previous
  66. load_failed:
  67. movw $10f, %si
  68. jmp boot_error
  69. 10: .asciz "Could not load iPXE\r\n"
  70. .org 510
  71. .byte 0x55, 0xaa
  72. start_image:
  73. /* Install iPXE */
  74. call install
  75. /* Set up real-mode stack */
  76. movw %bx, %ss
  77. movw $_estack16, %sp
  78. /* Jump to .text16 segment */
  79. pushw %ax
  80. pushw $1f
  81. lret
  82. .section ".text16", "awx", @progbits
  83. 1:
  84. pushl $main
  85. pushw %cs
  86. call prot_call
  87. popl %ecx /* discard */
  88. /* Uninstall iPXE */
  89. call uninstall
  90. /* Boot next device */
  91. int $0x18