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