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.

liloprefix.S 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. Copyright (C) 2000, Entity Cyber, Inc.
  3. Authors: Gary Byers (gb@thinguin.org)
  4. Marty Connor (mdc@thinguin.org)
  5. This software may be used and distributed according to the terms
  6. of the GNU Public License (GPL), incorporated herein by reference.
  7. Description:
  8. This is just a little bit of code and data that can get prepended
  9. to an Etherboot ROM image in order to allow LILO to load the
  10. result as if it were a Linux kernel image.
  11. A real Linux kernel image consists of a one-sector boot loader
  12. (to load the image from a floppy disk), followed a few sectors
  13. of setup code, followed by the kernel code itself. There's
  14. a table in the first sector (starting at offset 497) that indicates
  15. how many sectors of setup code follow the first sector and which
  16. contains some other parameters that aren't interesting in this
  17. case.
  18. When LILO loads the sectors that comprise a kernel image, it doesn't
  19. execute the code in the first sector (since that code would try to
  20. load the image from a floppy disk.) The code in the first sector
  21. below doesn't expect to get executed (and prints an error message
  22. if it ever -is- executed.) LILO's only interested in knowing the
  23. number of setup sectors advertised in the table (at offset 497 in
  24. the first sector.)
  25. Etherboot doesn't require much in the way of setup code.
  26. Historically, the Linux kernel required at least 4 sectors of
  27. setup code. Current versions of LILO look at the byte at
  28. offset 497 in the first sector to indicate how many sectors
  29. of setup code are contained in the image.
  30. */
  31. #define SETUPSECS 4 /* Minimal nr of setup-sectors */
  32. #define PREFIXSIZE ((SETUPSECS+1)*512)
  33. #define PREFIXPGH (PREFIXSIZE / 16 )
  34. #define BOOTSEG 0x07C0 /* original address of boot-sector */
  35. #define INITSEG 0x9000 /* we move boot here - out of the way */
  36. #define SETUPSEG 0x9020 /* setup starts here */
  37. #define SYSSEG 0x1000 /* system loaded at 0x10000 (65536). */
  38. .text
  39. .code16
  40. .arch i386
  41. .org 0
  42. .section ".prefix", "ax", @progbits
  43. _prefix:
  44. /*
  45. This is a minimal boot sector. If anyone tries to execute it (e.g., if
  46. a .lilo file is dd'ed to a floppy), print an error message.
  47. */
  48. bootsector:
  49. jmp $BOOTSEG, $go - _prefix /* reload cs:ip to match relocation addr */
  50. go:
  51. movw $0x2000, %di /* 0x2000 is arbitrary value >= length
  52. of bootsect + room for stack */
  53. movw $BOOTSEG, %ax
  54. movw %ax,%ds
  55. movw %ax,%es
  56. cli
  57. movw %ax, %ss /* put stack at BOOTSEG:0x2000. */
  58. movw %di,%sp
  59. sti
  60. movw $why_end-why, %cx
  61. movw $why - _prefix, %si
  62. movw $0x0007, %bx /* page 0, attribute 7 (normal) */
  63. movb $0x0e, %ah /* write char, tty mode */
  64. prloop:
  65. lodsb
  66. int $0x10
  67. loop prloop
  68. freeze: jmp freeze
  69. why: .ascii "This image cannot be loaded from a floppy disk.\r\n"
  70. why_end:
  71. .org 497
  72. setup_sects:
  73. .byte SETUPSECS
  74. root_flags:
  75. .word 0
  76. syssize:
  77. .word _verbatim_size_pgh - PREFIXPGH
  78. swap_dev:
  79. .word 0
  80. ram_size:
  81. .word 0
  82. vid_mode:
  83. .word 0
  84. root_dev:
  85. .word 0
  86. boot_flag:
  87. .word 0xAA55
  88. /*
  89. We're now at the beginning of the second sector of the image -
  90. where the setup code goes.
  91. We don't need to do too much setup for Etherboot.
  92. This code gets loaded at SETUPSEG:0. It wants to start
  93. executing the Etherboot image that's loaded at SYSSEG:0 and
  94. whose entry point is SYSSEG:0.
  95. */
  96. setup_code:
  97. pushl $0 /* No parameters to preserve for exit path */
  98. pushw $0 /* Use prefix exit path mechanism */
  99. /* Etherboot expects to be contiguous in memory once loaded.
  100. * LILO doesn't do this, but since we don't need any
  101. * information that's left in the prefix, it doesn't matter:
  102. * we just have to ensure that %cs:0000 is where the start of
  103. * the Etherboot image *would* be.
  104. */
  105. ljmp $(SYSSEG-(PREFIXSIZE/16)), $_start
  106. .section ".text16", "ax", @progbits
  107. prefix_exit:
  108. int $0x19 /* should try to boot machine */
  109. prefix_exit_end:
  110. .previous
  111. .org (PREFIXSIZE-1)
  112. .byte 0
  113. prefix_end:
  114. /*
  115. That's about it.
  116. */