Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | jermar | 1 | # |
2 | # Copyright (C) 2001-2004 Jakub Jermar |
||
3 | # All rights reserved. |
||
4 | # |
||
5 | # Redistribution and use in source and binary forms, with or without |
||
6 | # modification, are permitted provided that the following conditions |
||
7 | # are met: |
||
8 | # |
||
9 | # - Redistributions of source code must retain the above copyright |
||
10 | # notice, this list of conditions and the following disclaimer. |
||
11 | # - Redistributions in binary form must reproduce the above copyright |
||
12 | # notice, this list of conditions and the following disclaimer in the |
||
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 |
||
15 | # derived from this software without specific prior written permission. |
||
16 | # |
||
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 |
||
19 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
20 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
21 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
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 |
||
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 |
||
26 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | # |
||
28 | |||
29 | # This is a very primitive boot.s |
||
30 | |||
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). |
||
33 | # Next kernel sectors follow on disk sector 3, 4, ... |
||
34 | # |
||
35 | |||
36 | |||
37 | .text |
||
38 | .global _start_0x7c00 |
||
39 | |||
40 | .code16 |
||
41 | _start_0x7c00: |
||
42 | xorw %ax,%ax # reset, %al will be used below |
||
43 | movw %ax,%dx # fd0, %dh and %dl will be used below |
||
44 | int $0x13 |
||
45 | jc stop_trying |
||
46 | |||
47 | movb $2,%ah # read |
||
48 | incb %al # one sector |
||
49 | movb %ah,%cl # from disk sector 2 |
||
50 | movw %dx,%es |
||
51 | movw $0x8000,%bx # at %es:%bx |
||
52 | int $0x13 |
||
53 | jc stop_trying |
||
54 | |||
55 | pushw $('.') |
||
56 | call echo_mark |
||
57 | add $2,%sp |
||
58 | |||
59 | movw %dx,%ds |
||
60 | |||
61 | # KERNEL_SIZE is passed from the outside to the preprocessor |
||
62 | movl $(KERNEL_SIZE),%edi |
||
63 | |||
64 | shrl $9,%edi # number of sectors that kernel occupies (%edi div 512) |
||
65 | |||
66 | read_next: |
||
67 | test %edi,%edi |
||
68 | jnz read_sectors |
||
69 | |||
70 | movb $12,%al |
||
71 | movw $0x3f2,%dx |
||
72 | outb %al,%dx |
||
73 | |||
74 | pushw $('$') |
||
75 | call echo_mark |
||
76 | add $2,%sp |
||
77 | |||
78 | jmpl $0,$0x8000 |
||
79 | |||
80 | read_sectors: |
||
81 | pushw $('.') |
||
82 | call echo_mark |
||
83 | add $2,%sp |
||
84 | |||
85 | decl %edi |
||
86 | incw logical_sector |
||
87 | movw %es,%si |
||
88 | addw $0x20,%si |
||
89 | movw %si,%es |
||
90 | |||
91 | movw logical_sector,%ax |
||
92 | divb sectors |
||
93 | |||
94 | movb %ah,%cl |
||
95 | incb %cl # sector |
||
96 | |||
97 | movb %al,%ch |
||
98 | shrb $1,%ch # track |
||
99 | |||
100 | movb %al,%dh |
||
101 | andb $1,%dh # head |
||
102 | |||
103 | movw $0x0201,%ax |
||
104 | int $0x13 |
||
105 | jnc read_next |
||
106 | |||
107 | pushw $('R') |
||
108 | call echo_mark |
||
109 | add $2,%sp |
||
110 | |||
111 | xorw %ax,%ax # try to reset |
||
112 | movw %ax,%dx # fd0 |
||
113 | int $0x13 |
||
114 | jnc read_next |
||
115 | |||
116 | stop_trying: |
||
117 | pushw $('F') |
||
118 | call echo_mark |
||
119 | add $2,%sp |
||
120 | |||
121 | cli |
||
122 | hlt |
||
123 | |||
124 | CH=4 |
||
125 | echo_mark: |
||
126 | push %bp |
||
127 | movw %sp,%bp |
||
128 | pusha |
||
129 | |||
130 | movw CH(%bp),%ax |
||
131 | movb $0xe,%ah |
||
132 | movb $7,%bl |
||
133 | int $0x10 |
||
134 | |||
135 | popa |
||
136 | pop %bp |
||
137 | ret |
||
138 | |||
139 | # current logical sector from the beginning of the disk |
||
140 | logical_sector: |
||
141 | .word 1 |
||
142 | |||
143 | # number of sectors per track on 1440 floppy |
||
144 | sectors: |
||
145 | .byte 18 |
||
146 | |||
147 | |||
148 | # boot floppy signature |
||
149 | .org 0x1fe |
||
150 | boot_floppy_signature: |
||
151 | .byte 0x55 |
||
152 | .byte 0xaa |