Rev 18 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 18 | Rev 125 | ||
---|---|---|---|
1 | # |
1 | # |
2 | # Copyright (C) 2001-2004 Jakub Jermar |
2 | # Copyright (C) 2001-2004 Jakub Jermar |
3 | # All rights reserved. |
3 | # All rights reserved. |
4 | # |
4 | # |
5 | # Redistribution and use in source and binary forms, with or without |
5 | # Redistribution and use in source and binary forms, with or without |
6 | # modification, are permitted provided that the following conditions |
6 | # modification, are permitted provided that the following conditions |
7 | # are met: |
7 | # are met: |
8 | # |
8 | # |
9 | # - Redistributions of source code must retain the above copyright |
9 | # - Redistributions of source code must retain the above copyright |
10 | # notice, this list of conditions and the following disclaimer. |
10 | # notice, this list of conditions and the following disclaimer. |
11 | # - Redistributions in binary form must reproduce the above copyright |
11 | # - Redistributions in binary form must reproduce the above copyright |
12 | # notice, this list of conditions and the following disclaimer in the |
12 | # notice, this list of conditions and the following disclaimer in the |
13 | # documentation and/or other materials provided with the distribution. |
13 | # documentation and/or other materials provided with the distribution. |
14 | # - The name of the author may not be used to endorse or promote products |
14 | # - The name of the author may not be used to endorse or promote products |
15 | # derived from this software without specific prior written permission. |
15 | # derived from this software without specific prior written permission. |
16 | # |
16 | # |
17 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | # |
27 | # |
28 | 28 | ||
29 | # This is a very primitive boot.s |
29 | # This is a very primitive boot.s |
30 | 30 | ||
31 | # It assumes that the first sector of the kernel image is found |
31 | # It assumes that the first sector of the kernel image is found |
32 | # on head 0, track 0, sector 2 of the first floppy drive (1440K). |
32 | # on head 0, track 0, sector 2 of the first floppy drive (1440K). |
33 | # Next kernel sectors follow on disk sector 3, 4, ... |
33 | # Next kernel sectors follow on disk sector 3, 4, ... |
34 | # |
34 | # |
35 | 35 | ||
36 | 36 | ||
37 | # KERNEL_SIZE is passed from the outside to the preprocessor |
37 | # KERNEL_SIZE is passed from the outside to the preprocessor |
38 | #if (KERNEL_SIZE%512>0) |
38 | #if (KERNEL_SIZE%512>0) |
39 | #define TAIL 1 |
39 | #define TAIL 1 |
40 | #else |
40 | #else |
41 | #define TAIL 0 |
41 | #define TAIL 0 |
42 | #endif |
42 | #endif |
43 | 43 | ||
44 | #define SECTORS (KERNEL_SIZE/512+TAIL) |
44 | #define SECTORS (KERNEL_SIZE/512+TAIL) |
45 | 45 | ||
46 | .text |
46 | .text |
47 | .global _start_0x7c00 |
47 | .global _start_0x7c00 |
48 | 48 | ||
49 | .code16 |
49 | .code16 |
50 | _start_0x7c00: |
50 | _start_0x7c00: |
51 | xorw %ax,%ax # reset, %al will be used below |
51 | xorw %ax,%ax # reset, %al will be used below |
52 | movw %ax,%dx # fd0, %dh and %dl will be used below |
52 | movw %ax,%dx # fd0, %dh and %dl will be used below |
53 | movw %dx,%ds |
53 | movw %dx,%ds |
54 | 54 | ||
55 | movw %dx,%ss # initialize stack |
55 | movw %dx,%ss # initialize stack |
56 | movw $stack,%sp |
56 | movw $stack,%sp |
57 | 57 | ||
58 | int $0x13 # reset floppy |
58 | int $0x13 # reset floppy |
59 | jc stop_trying |
59 | jc stop_trying |
60 | 60 | ||
61 | movw %dx,%ds |
61 | movw %dx,%ds |
62 | movw %dx,%ss |
62 | movw %dx,%ss |
63 | movw $0x7c00,%sp |
63 | movw $0x7c00,%sp |
64 | movw $0xffe0,%si # after next increment, %si will become 0x0000 |
64 | movw $0xffe0,%si # after next increment, %si will become 0x0000 |
65 | movw %si,%es |
65 | movw %si,%es |
66 | movw $0x8000,%bx # at %es:%bx |
66 | movw $0x8000,%bx # at %es:%bx |
67 | 67 | ||
68 | movl $(SECTORS),%edi |
68 | movl $(SECTORS),%edi |
69 | 69 | ||
70 | read_next: |
70 | read_next: |
71 | test %edi,%edi |
71 | test %edi,%edi |
72 | jnz read_sectors |
72 | jnz read_sectors |
73 | 73 | ||
74 | movb $12,%al |
74 | movb $12,%al |
75 | movw $0x3f2,%dx |
75 | movw $0x3f2,%dx |
76 | outb %al,%dx |
76 | outb %al,%dx |
77 | 77 | ||
78 | movb $('$'),%al |
78 | movb $('$'),%al |
79 | call echo_mark |
79 | call echo_mark |
80 | 80 | ||
81 | jmpl $0,$0x8000 |
81 | jmpl $0,$0x8000 |
82 | 82 | ||
83 | read_sectors: |
83 | read_sectors: |
84 | movb $('.'),%al |
84 | movb $('.'),%al |
85 | call echo_mark |
85 | call echo_mark |
86 | 86 | ||
87 | decl %edi |
87 | decl %edi |
88 | incw logical_sector |
88 | incw logical_sector |
89 | movw %es,%si |
89 | movw %es,%si |
90 | addw $0x20,%si |
90 | addw $0x20,%si |
91 | movw %si,%es |
91 | movw %si,%es |
92 | 92 | ||
93 | movw logical_sector,%ax |
93 | movw logical_sector,%ax |
94 | divb sectors |
94 | divb sectors |
95 | 95 | ||
96 | movb %ah,%cl |
96 | movb %ah,%cl |
97 | incb %cl # sector |
97 | incb %cl # sector |
98 | 98 | ||
99 | movb %al,%ch |
99 | movb %al,%ch |
100 | shrb $1,%ch # track |
100 | shrb $1,%ch # track |
101 | 101 | ||
102 | movb %al,%dh |
102 | movb %al,%dh |
103 | andb $1,%dh # head |
103 | andb $1,%dh # head |
104 | 104 | ||
105 | movw $0x0201,%ax |
105 | movw $0x0201,%ax |
106 | int $0x13 |
106 | int $0x13 |
107 | jnc read_next |
107 | jnc read_next |
108 | 108 | ||
109 | movb $('R'),%al |
109 | movb $('R'),%al |
110 | call echo_mark |
110 | call echo_mark |
111 | 111 | ||
112 | xorw %ax,%ax # try to reset |
112 | xorw %ax,%ax # try to reset |
113 | movw %ax,%dx # fd0 |
113 | movw %ax,%dx # fd0 |
114 | int $0x13 |
114 | int $0x13 |
115 | jnc read_next |
115 | jnc read_next |
116 | 116 | ||
117 | stop_trying: |
117 | stop_trying: |
118 | movb $('F'),%al |
118 | movb $('F'),%al |
119 | call echo_mark |
119 | call echo_mark |
120 | 120 | ||
121 | cli |
121 | cli |
122 | hlt |
122 | hlt |
123 | 123 | ||
124 | CH=4 |
124 | CH=4 |
125 | echo_mark: |
125 | echo_mark: |
126 | push %bp |
126 | push %bp |
127 | movw %sp,%bp |
127 | movw %sp,%bp |
128 | pusha |
128 | pusha |
129 | 129 | ||
130 | movb $0xe,%ah |
130 | movb $0xe,%ah |
131 | movb $7,%bl |
131 | movb $7,%bl |
132 | int $0x10 |
132 | int $0x10 |
133 | 133 | ||
134 | popa |
134 | popa |
135 | pop %bp |
135 | pop %bp |
136 | ret |
136 | ret |
137 | 137 | ||
138 | # current logical sector from the beginning of the disk |
138 | # current logical sector from the beginning of the disk |
139 | logical_sector: |
139 | logical_sector: |
140 | .word 0 |
140 | .word 0 |
141 | 141 | ||
142 | # number of sectors per track on 1440 floppy |
142 | # number of sectors per track on 1440 floppy |
143 | sectors: |
143 | sectors: |
144 | .byte 18 |
144 | .byte 18 |
145 | 145 | ||
146 | # boot floppy signature |
146 | # boot floppy signature |
147 | .org 0x1fe |
147 | .org 0x1fe |
148 | boot_floppy_signature: |
148 | boot_floppy_signature: |
149 | .byte 0x55 |
149 | .byte 0x55 |
150 | .byte 0xaa |
150 | .byte 0xaa |
151 | stack: |
151 | stack: |
152 | 152 |