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
 
17
start:
18
    push cs
19
    pop ds
20
    mov ax,0003h
21
    int 10h
22
 
23
    mov dx,title
24
    call print
25
    mov dx,title_1
26
    call print
27
;    mov dx,mes1
28
;    call print
29
 
30
;-------open Msetup.exe--------------
31
    mov dx,img0
32
    call file_open
33
    cmp ax,00h
34
    je loader_next_file_search_0
35
    mov [handle],ax
36
    mov [foffset],dword 00h
37
    jmp loader_continue
38
loader_next_file_search_0:
39
    mov dx,img1
40
    call file_open
41
    cmp ax,00h
42
    je loader_next_file_search_00
43
    mov [handle],ax
44
    jmp loader_continue
45
loader_next_file_search_00:
46
    mov dx,img2
47
    call file_open
48
    cmp ax,00h
49
    je loader_next_file_search_01
50
    mov [handle],ax
51
    mov [foffset],dword 00h
52
    jmp loader_continue
53
loader_next_file_search_01:
54
    mov dx,img3
55
    call file_open
56
    cmp ax,00h
57
    je loader_not_find_file
58
    mov [handle],ax
59
    mov [foffset],dword 00h
60
loader_continue:
61
 
62
;******* Load IMAGE in memory***************************************************
63
    mov dx,start_img_read
64
    call print
65
 
66
    mov bx,ax
67
    xor cx,cx       ;  cx:dx - offset in bytes (cx*65535+dx)
68
    xor edx,edx
69
    call file_offset
70
    mov  [image_counter],0
71
 @@_1:
72
    mov bx,[handle]
73
    mov dx,buffer        ;ds:dx - buffer
74
    mov cx,512*96
75
    call file_read
76
 
77
    push  fs
78
    xor     ax,ax           ;AX = 0
79
    mov     fs,ax           ;DS = AX = 0  ..Èñïîëüçóåò ËÈÍÅÉÍÎÅ ÀÄÐÅÑÎÂÀÍÈÅ!
80
    mov  ecx,512*96
81
    mov  si,buffer
82
    movzx  edi,[image_counter]
83
    imul edi,48*1024
84
    add  edi,0x100000
85
@@:
86
    mov  al,[si]
87
    mov  [fs:edi],al
88
    inc  edi
89
    inc  esi
90
    loop @b
91
    pop  fs
92
 
93
    mov dx,progress_img_read
94
    call print
95
 
96
    inc  [image_counter]
97
    mov bx,[handle] ;ax
98
    movzx edx,[image_counter]
99
    imul edx,48*1024
100
    mov ecx,edx
101
    shr ecx,16
102
    call file_offset
103
    cmp  [image_counter],30
104
    jne  @@_1
105
 
106
    mov dx,end_img_read
107
    call print
108
 
109
    mov dx,start_kernel_read
110
    call print
111
;*******************************************************************************
112
;-------Move pointer to boot-sector--
113
    mov bx,[handle] ;ax
114
    xor cx,cx
115
    mov edx,[foffset]
116
    call file_offset
117
 
118
;---------Read boot-sector-----------
119
    mov bx,[handle]
120
    mov dx,buffer
121
    mov cx,512
122
    call file_read
123
 
124
;--------Read parametrs--------------
125
    mov ax,[buffer+0bh]
126
    mov [SectSize],ax
127
    mov al,[buffer+0dh]
128
    mov [ClustSect],al
129
    mov ax,[buffer+0eh]
130
    mov [ResSect],ax
131
    add ax,[ResRgn]
132
    mov [FATRgn],ax
133
    mov al,[buffer+10h]
134
    mov [FATCnt],al
135
    xor bx,bx
136
    mov bl,al
137
    mov ax,[buffer+11h]
138
    mov [RootEnt],ax
139
    shr ax,4        ; ax=ax*32/512
140
    mov [RootDirRgnSz],ax
141
    mov ax,[buffer+16h]
142
    mov [FATSect],ax
143
    mul bx
144
    mov [FATRgnSz],ax
145
    add ax,[FATRgn]
146
    mov [RootDirRgn],ax
147
    add ax,[RootDirRgnSz]
148
    mov [DataRgn],ax
149
 
150
;------Read FATs and RootDir---------
151
    xor eax,eax
152
    xor edx,edx
153
    mov ax,[FATRgn]
154
    mul [SectSize]
155
    add eax,[foffset]
156
    mov cx,dx
157
    mov dx,ax
158
    mov bx,[handle]
159
    call file_offset
160
    mov ax,[FATRgnSz]
161
    mul [SectSize]
162
    mov cx,ax
163
    mov dx,buffer
164
    mov bx,[handle]
165
    call file_read
166
    mov cx,[RootEnt]
167
    shl cx,5
168
    mov dx,Root
169
    mov bx,[handle]
170
    call file_read
171
 
172
;-------Search entry pointer in RootDir---------
173
    push ds
174
    pop es
175
    mov cx,[RootEnt]
176
    mov bx,Root
177
loader_loc_00:
178
    push cx
179
    mov cx,11
180
    mov di,bx
181
    mov si,kernel
182
    repe cmpsb
183
    jnz loader_notfound
184
    pop cx
185
    jmp loader_find
186
loader_notfound:
187
    pop cx
188
    add bx,32
189
    loop loader_loc_00
190
loader_find:
191
 
192
    mov ax,[bx+1ah]
193
    mov [FirstClust],ax
194
    mov eax,[bx+1ch]
195
    mov [filesize],eax
196
 
197
;------Read Kernel----------------------
198
    call read_kernel
199
 
200
;---------------------------------------
201
 
202
    mov bx,[handle]
203
    call file_close
204
;;;;;;;;;;;;;;;;;;;;;;
205
    jmp loader_yes
206
;;;;;;;;;;;;;;;;;;;;;;
207
;    mov dx,mes2
208
;    call print
209
;loader_key:
210
;    mov ah,00h
211
;    int 16h
212
;    cmp al,1bh    ;ESC
213
;    je loader_no
214
;    cmp al,6eh    ;'n'
215
;    je loader_no
216
;    cmp al,4eh    ;'N'
217
;    je loader_no
218
;    cmp al,79h    ;'y'
219
;    je loader_yes
220
;    cmp al,59h    ;'Y'
221
;    je loader_yes
222
;    jmp loader_key
223
 
224
loader_not_find_file:
225
    mov dx,mes4
226
    call print
227
    jmp loader_exit
228
 
229
loader_yes:
230
    mov dx,yes
231
    call print
232
    mov ax,7000h
233
    mov es,ax
234
    mov si,move_kernel
235
    xor di,di
236
    mov cx,len_mk
237
    rep movsb
238
    jmp far 7000h:0000h
239
;    jmp loader_exit
240
loader_no:
241
    mov dx,no
242
    call print
243
 
244
loader_exit:
245
    mov dx,mes3
246
    call print
247
    retn
248
;----Subprogramms--------
249
 
250
print:
251
; in: dx - offset of ASCII string
252
; out:
253
    mov ah,09h
254
    int 21h
255
    retn
256
 
257
file_open:
258
; in: ds:dx - offset of ASCIIZ filename string
259
; out: ax - file handle (ax=0 - not found)
260
    mov ax,3d00h
261
    int 21h
262
    jnc fo_exit
263
    xor ax,ax
264
fo_exit:
265
    retn
266
 
267
file_close:
268
; in: bx - file handle
269
; out:
270
    mov ah,3eh
271
    int 21h
272
    retn
273
 
274
file_read:
275
; in: bx - file handle
276
;     ds:dx - buffer
277
;     cx - numbers of bytes
278
; out:
279
    mov ah,3fh
280
    int 21h
281
    retn
282
 
283
file_offset:
284
; in: bx - file handle
285
;     cx:dx - offset in bytes (cx*65535+dx)
286
; out:
287
    mov ax,4200h
288
    int 21h
289
    retn
290
 
291
sector_find:
292
; in: ax - No of Cluster
293
; out: ax - 1st sector of Cluster
294
    dec ax
295
    dec ax
296
    push bx
297
    xor bx,bx
298
    mov bl,[ClustSect]
299
    mul bx
300
    pop bx
301
    add ax,[DataRgn]
302
    retn
303
 
304
read_cluster:
305
; in: ax - No of Cluster
306
;     ds:dx - buffer
307
; out:
308
    push dx
309
    call sector_find
310
    push ax
311
    xor eax,eax
312
    xor ebx,ebx
313
    pop ax
314
    mov bx,[SectSize]
315
    mul ebx
316
    add eax,[foffset]
317
    mov dx,ax
318
    shr eax,16
319
    mov cx,ax
320
    mov bx,[handle]
321
    call file_offset
322
    xor ax,ax
323
    mov al,[ClustSect]
324
    mul [SectSize]
325
    mov cx,ax
326
    mov bx,[handle]
327
    pop dx
328
    call file_read
329
    retn
330
 
331
read_kernel:
332
; in:
333
; out:
334
    mov ax,8000h
335
    mov es,ax    ;8000:0000 = 80000h  - Temporal location of kernel
336
    xor di,di    ;
337
    mov ax,[FirstClust]
338
    mov bp,ax
339
rk_loc_00:
340
    push es
341
    mov dx,Root
342
    call read_cluster
343
    xor ax,ax        ; Moving cluster to area of location kernel
344
    mov al,[ClustSect]    ;
345
    mul [SectSize]        ;
346
    mov cx,ax        ;
347
    pop es                  ;
348
    mov si,Root        ;
349
    rep movsb        ;
350
    cmp di,00h
351
    jne rk_continue
352
    mov ax,es
353
    add ax,1000h
354
    mov es,ax
355
rk_continue:
356
    mov ax,bp
357
    cmp ax,0ff8h
358
    jae rk_done
359
    shl ax,1    ; Val=Clustrer*1,5 //(Cluster*3)/2
360
    add ax,bp    ;
361
    shr ax,1    ;
362
    mov bx,ax
363
    add bx,buffer
364
    mov ax,[bx]
365
    bt bp,0
366
    jc rk_nechet
367
    and ax,0fffh
368
    jmp rk_chet
369
rk_nechet:
370
    shr ax,4
371
rk_chet:
372
    mov bp,ax
373
    jmp rk_loc_00
374
rk_done:
375
    retn
376
 
377
move_kernel:
378
; in:
379
; out:
380
    mov ax,8000h
381
    mov ds,ax
382
    mov ax,1000h
383
    mov es,ax
384
    xor si,si
385
    xor di,di
386
    mov cx,8000h
387
    rep movsb
388
    mov cx,8000h
389
    rep movsb
390
    mov bx,es
391
    add bx,1000h
392
    mov es,bx
393
    mov bx,ds
394
    add bx,1000h
395
    mov ds,bx
396
    mov cx,8000h
397
    rep movsb
398
    mov cx,8000h
399
    rep movsb
400
    mov ax,1000h
401
    mov ds,ax
402
    mov es,ax
403
    jmp far 1000h:0000h
404
    retn
405
len_mk=$-move_kernel
406
 
407
;--------Data------------
408
title    db 'KolibriOS\MenuetOS Boot Loader. Ver.1.2  Copyright(C) 2003, Trans.',0ah,0dh,0ah,0dh,'$'
409
title_1  db 'Addition 2005-2006 by Mario79 - for boot Flash RAM.',0ah,0dh,0ah,0dh,'$'
410
;mes1    db 'It is alternative of boot from floppy.',0ah,0dh
411
;    db 'You MUST select HD booting !!!',0ah,0dh,0ah,0dh,'$'
412
;mes2    db 'Are you sure loading MeOS? (Y/N):','$'
413
start_img_read db 'Read IMG file: ','$'
414
progress_img_read db '#','$'
415
end_img_read db 0ah,0dh,0ah,0dh,'$'
416
start_kernel_read db 'Start kernel read ','$'
417
yes    db 'Y','$'
418
no    db 'N','$'
419
mes3    db 0ah,0dh,0ah,0dh,'See you later ...',0ah,0dh,'$'
420
mes4    db 0ah,0dh,0ah,0dh,'Not Found: '
421
img0    db 'kolibri\kolibri.img',0,', '
422
img1    db 'msetup.exe',0,', '
423
img2    db 'menuet.img',0,', '
424
img3    db 'kolibri.img',0,' :($'
425
image_counter db 0
426
kernel    db 'KERNEL  MNT',0
427
handle    dw ?
428
foffset    dd 20480
429
SectSize    dw ?    ; +0bh
430
ClustSect    db ?    ; +0dh
431
ResSect     dw ?    ; +0eh
432
FATCnt        db ?    ; +10h
433
RootEnt     dw ?    ; +11h
434
FATSect     dw ?    ; +16h
435
filesize    dd ?    ; +1ch
436
FirstClust    dw ?    ; +1ah
437
 
438
ResRgn        dw 0    ; = VolumeStart
439
FATRgn        dw ?    ; = ResRgn+ResSect
440
RootDirRgn    dw ?    ; = FATRgn+(FATCnt*FATSect)
441
DataRgn     dw ?    ; = RootDirRgn+((RootEnt*32)/SectSize)
442
ResRgnSz    dw ?    ; = ResSect
443
FATRgnSz    dw ?    ; = FATCnt*FATSect
444
RootDirRgnSz    dw ?    ; = (RootEnt*32)/SectSize
445
;First sector of cluster N = DataRgn+((N-2)*ClustSect)
446
buffer:
447
    org 3000h
448
Root:
449