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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. /*
  44. This is a minimal boot sector. If anyone tries to execute it (e.g., if
  45. a .lilo file is dd'ed to a floppy), print an error message.
  46. */
  47. bootsector:
  48. jmp $BOOTSEG, $1f /* reload cs:ip to match relocation addr */
  49. 1:
  50. movw $0x2000, %di /* 0x2000 is arbitrary value >= length
  51. of bootsect + room for stack */
  52. movw $BOOTSEG, %ax
  53. movw %ax,%ds
  54. movw %ax,%es
  55. cli
  56. movw %ax, %ss /* put stack at BOOTSEG:0x2000. */
  57. movw %di,%sp
  58. sti
  59. movw $why_end-why, %cx
  60. movw $why, %si
  61. movw $0x0007, %bx /* page 0, attribute 7 (normal) */
  62. movb $0x0e, %ah /* write char, tty mode */
  63. prloop:
  64. lodsb
  65. int $0x10
  66. loop prloop
  67. freeze: jmp freeze
  68. why: .ascii "This image cannot be loaded from a floppy disk.\r\n"
  69. why_end:
  70. .org 497
  71. setup_sects:
  72. .byte SETUPSECS
  73. root_flags:
  74. .word 0
  75. syssize:
  76. .word _load_size_pgh - PREFIXPGH
  77. swap_dev:
  78. .word 0
  79. ram_size:
  80. .word 0
  81. vid_mode:
  82. .word 0
  83. root_dev:
  84. .word 0
  85. boot_flag:
  86. .word 0xAA55
  87. .org 512
  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. /* Etherboot expects to be contiguous in memory once loaded.
  98. * LILO doesn't do this, but since we don't need any
  99. * information that's left in the prefix, it doesn't matter:
  100. * we just have to ensure that %cs:0000 is where the start of
  101. * the Etherboot image *would* be.
  102. */
  103. ljmp $(SYSSEG-(PREFIXSIZE/16)), $run_etherboot
  104. .org PREFIXSIZE
  105. /*
  106. We're now at the beginning of the kernel proper.
  107. */
  108. run_etherboot:
  109. call install
  110. /* Jump to .text16 segment */
  111. pushw %ax
  112. pushw $1f
  113. lret
  114. .section ".text16", "awx", @progbits
  115. 1:
  116. pushl $main
  117. pushw %cs
  118. call prot_call
  119. popl %eax /* discard */
  120. /* Boot next device */
  121. int $0x18