Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2783 clevermous 1
;
2
; MenuesOS Boot Loader
3
;
4
; Author: Trans
5
; Date:   14.02.03
6
; Version: 1.0
7
;
8
; Current Version: 1.1
9
; Date of modification: 11.06.03
10
;
11
; Compile with FASM
12
;
13
 
14
;--------Code------------
15
    org 100h
16
start:
17
    push cs
18
    pop ds
19
    mov ax,0003h
20
    int 10h
21
 
22
    mov dx,title
23
    call print
24
    mov dx,mes1
25
    call print
26
 
27
    mov dx,img0
28
    call file_open
29
    test ax,ax
30
    jnz loader_continue
31
    mov dx,img2
32
    call file_open
33
    test ax,ax
34
    jne loader_continue
35
    mov dx,img3
36
    call file_open
37
    test ax,ax
38
    je loader_not_find_file
39
loader_continue:
40
    mov [handle],ax
41
 
42
;---------Read boot-sector-----------
43
    mov bx,ax
44
    mov dx,buffer
45
    mov cx,512
46
    call file_read
47
 
48
;--------Read parametrs--------------
49
    mov ax,[buffer+0bh]
50
    mov [SectSize],ax
51
    mov al,[buffer+0dh]
52
    mov [ClustSect],al
53
    mov ax,[buffer+0eh]
54
    mov [ResSect],ax
55
    add ax,[ResRgn]
56
    mov [FATRgn],ax
57
    mov al,[buffer+10h]
58
    mov [FATCnt],al
59
    xor bx,bx
60
    mov bl,al
61
    mov ax,[buffer+11h]
62
    mov [RootEnt],ax
63
    shr ax,4        ; ax=ax*32/512
64
    mov [RootDirRgnSz],ax
65
    mov ax,[buffer+16h]
66
    mov [FATSect],ax
67
    mul bx
68
    mov [FATRgnSz],ax
69
    add ax,[FATRgn]
70
    mov [RootDirRgn],ax
71
    add ax,[RootDirRgnSz]
72
    mov [DataRgn],ax
73
 
74
;------Read FATs and RootDir---------
75
    xor eax,eax
76
    xor edx,edx
77
    mov ax,[FATRgn]
78
    mul [SectSize]
79
    mov cx,dx
80
    mov dx,ax
81
    mov bx,[handle]
82
    call file_offset
83
    mov ax,[FATRgnSz]
84
    mul [SectSize]
85
    mov cx,ax
86
    mov dx,buffer
87
    mov bx,[handle]
88
    call file_read
89
    mov cx,[RootEnt]
90
    shl cx,5
91
    mov dx,Root
92
    mov bx,[handle]
93
    call file_read
94
 
95
;-------Search entry pointer in RootDir---------
96
    push ds
97
    pop es
98
    mov cx,[RootEnt]
99
    mov bx,Root
100
loader_loc_00:
101
    push cx
102
    mov cx,11
103
    mov di,bx
104
    mov si,kernel
105
    repe cmpsb
106
    jnz loader_notfound
107
    pop cx
108
    jmp loader_find
109
loader_notfound:
110
    pop cx
111
    add bx,32
112
    loop loader_loc_00
113
loader_find:
114
 
115
    mov ax,[bx+1ah]
116
    mov [FirstClust],ax
117
    mov eax,[bx+1ch]
118
    mov [filesize],eax
119
 
120
;------Read Kernel----------------------
121
    call read_kernel
122
 
123
;---------------------------------------
124
 
125
    mov bx,[handle]
126
    call file_close
127
;;;;;;;;;;;;;;;;;;;;;;
128
    jmp loader_yes
129
;;;;;;;;;;;;;;;;;;;;;;
130
;    mov dx,mes2
131
;    call print
132
;loader_key:
133
;    mov ah,00h
134
;    int 16h
135
;    cmp al,1bh    ;ESC
136
;    je loader_no
137
;    cmp al,6eh    ;'n'
138
;    je loader_no
139
;    cmp al,4eh    ;'N'
140
;    je loader_no
141
;    cmp al,79h    ;'y'
142
;    je loader_yes
143
;    cmp al,59h    ;'Y'
144
;    je loader_yes
145
;    jmp loader_key
146
 
147
loader_not_find_file:
148
    mov dx,mes4
149
    call print
150
    jmp loader_exit
151
 
152
loader_yes:
153
    mov dx,yes
154
    call print
155
    mov ax,7000h
156
    mov es,ax
157
    mov si,move_kernel
158
    xor di,di
159
    mov cx,len_mk
160
    rep movsb
161
    jmp far 7000h:0000h
162
;    jmp loader_exit
163
loader_no:
164
    mov dx,no
165
    call print
166
 
167
loader_exit:
168
    mov dx,mes3
169
    call print
170
    retn
171
;----Subprogramms--------
172
 
173
print:
174
; in: dx - offset of ASCII string
175
; out:
176
    mov ah,09h
177
    int 21h
178
    retn
179
 
180
file_open:
181
; in: ds:dx - offset of ASCIIZ filename string
182
; out: ax - file handle (ax=0 - not found)
183
    mov ax,3d00h
184
    int 21h
185
    jnc fo_exit
186
    xor ax,ax
187
fo_exit:
188
    retn
189
 
190
file_close:
191
; in: bx - file handle
192
; out:
193
    mov ah,3eh
194
    int 21h
195
    retn
196
 
197
file_read:
198
; in: bx - file handle
199
;     ds:dx - buffer
200
;     cx - numbers of bytes
201
; out:
202
    mov ah,3fh
203
    int 21h
204
    retn
205
 
206
file_offset:
207
; in: bx - file handle
208
;     cx:dx - offset in bytes (cx*65535+dx)
209
; out:
210
    mov ax,4200h
211
    int 21h
212
    retn
213
 
214
sector_find:
215
; in: ax - No of Cluster
216
; out: ax - 1st sector of Cluster
217
    dec ax
218
    dec ax
219
    push bx
220
    xor bx,bx
221
    mov bl,[ClustSect]
222
    mul bx
223
    pop bx
224
    add ax,[DataRgn]
225
    retn
226
 
227
read_cluster:
228
; in: ax - No of Cluster
229
;     ds:dx - buffer
230
; out:
231
    push dx
232
    call sector_find
233
    push ax
234
    xor eax,eax
235
    xor ebx,ebx
236
    pop ax
237
    mov bx,[SectSize]
238
    mul ebx
239
    mov dx,ax
240
    shr eax,16
241
    mov cx,ax
242
    mov bx,[handle]
243
    call file_offset
244
    xor ax,ax
245
    mov al,[ClustSect]
246
    mul [SectSize]
247
    mov cx,ax
248
    mov bx,[handle]
249
    pop dx
250
    call file_read
251
    retn
252
 
253
read_kernel:
254
; in:
255
; out:
256
    mov ax,8000h
257
    mov es,ax    ;8000:0000 = 80000h  - Temporal location of kernel
258
    xor di,di    ;
259
    mov ax,[FirstClust]
260
    mov bp,ax
261
rk_loc_00:
262
    push es
263
    mov dx,Root
264
    call read_cluster
265
    xor ax,ax        ; Moving cluster to area of location kernel
266
    mov al,[ClustSect]    ;
267
    mul [SectSize]        ;
268
    mov cx,ax        ;
269
    pop es                  ;
270
    mov si,Root        ;
271
    rep movsb        ;
272
    cmp di,00h
273
    jne rk_continue
274
    mov ax,es
275
    add ax,1000h
276
    mov es,ax
277
rk_continue:
278
    mov ax,bp
279
    cmp ax,0ff8h
280
    jae rk_done
281
    shl ax,1    ; Val=Clustrer*1,5 //(Cluster*3)/2
282
    add ax,bp    ;
283
    shr ax,1    ;
284
    mov bx,ax
285
    add bx,buffer
286
    mov ax,[bx]
287
    bt bp,0
288
    jc rk_nechet
289
    and ax,0fffh
290
    jmp rk_chet
291
rk_nechet:
292
    shr ax,4
293
rk_chet:
294
    mov bp,ax
295
    jmp rk_loc_00
296
rk_done:
297
    retn
298
 
299
move_kernel:
300
; in:
301
; out:
302
    mov ax,8000h
303
    mov ds,ax
304
    mov ax,1000h
305
    mov es,ax
306
    xor si,si
307
    xor di,di
308
    mov cx,8000h
309
    rep movsb
310
    mov cx,8000h
311
    rep movsb
312
    mov bx,es
313
    add bx,1000h
314
    mov es,bx
315
    mov bx,ds
316
    add bx,1000h
317
    mov ds,bx
318
    mov cx,8000h
319
    rep movsb
320
    mov cx,8000h
321
    rep movsb
322
    mov ax,1000h
323
    mov ds,ax
324
    mov es,ax
325
    jmp far 1000h:0000h
326
    retn
327
len_mk=$-move_kernel
328
 
329
;--------Data------------
330
title    db 'MenuetOS/KolibriOS Boot Loader. Ver.1.1   Copyright(C) 2003, Trans.',0ah,0dh,0ah,0dh,'$'
331
mes1    db 'It is alternative of boot from floppy.',0ah,0dh
332
    db 'You MUST select HD booting !!!',0ah,0dh,0ah,0dh,'$'
333
mes2    db 'Are you sure loading KolibriOS? (Y/N):','$'
334
yes    db 'Y','$'
335
no    db 'N','$'
336
mes3    db 0ah,0dh,0ah,0dh,'See you later ...',0ah,0dh,'$'
337
mes4    db 0ah,0dh,0ah,0dh,'Not Found: '
338
img0    db 'kolibri\kolibri.img',0,', '
339
img2    db 'kolibri.img',0,', '
340
img3    db 'menuet.img',0,' :($'
341
kernel    db 'KERNEL  MNT',0
342
handle    dw ?
343
SectSize    dw ?    ; +0bh
344
ClustSect    db ?    ; +0dh
345
ResSect     dw ?    ; +0eh
346
FATCnt        db ?    ; +10h
347
RootEnt     dw ?    ; +11h
348
FATSect     dw ?    ; +16h
349
filesize    dd ?    ; +1ch
350
FirstClust    dw ?    ; +1ah
351
 
352
ResRgn        dw 0    ; = VolumeStart
353
FATRgn        dw ?    ; = ResRgn+ResSect
354
RootDirRgn    dw ?    ; = FATRgn+(FATCnt*FATSect)
355
DataRgn     dw ?    ; = RootDirRgn+((RootEnt*32)/SectSize)
356
ResRgnSz    dw ?    ; = ResSect
357
FATRgnSz    dw ?    ; = FATCnt*FATSect
358
RootDirRgnSz    dw ?    ; = (RootEnt*32)/SectSize
359
;First sector of cluster N = DataRgn+((N-2)*ClustSect)
360
 
361
buffer:
362
    org 3000h
363
Root:
364