Debian Codegraph @

historic,v

raw
1 head 1.6;
2 access;
3 symbols
4 MBR_1_1_3:1.6
5 MBR_1_1_2:1.5
6 MBR_1_1_1:1.4
7 MBR_1_1_0:1.3
8 MBR_1_0_1:1.2
9 MBR_1_0_0:1.1;
10 locks
11 neil:1.6; strict;
12 comment @# @;
13
14
15 1.6
16 date 2001.09.14.22.09.41; author neil; state Exp;
17 branches;
18 next 1.5;
19
20 1.5
21 date 2001.09.14.22.09.41; author neil; state Exp;
22 branches;
23 next 1.4;
24
25 1.4
26 date 2001.09.14.22.09.41; author neil; state Exp;
27 branches;
28 next 1.3;
29
30 1.3
31 date 2001.09.14.22.09.41; author neil; state Exp;
32 branches;
33 next 1.2;
34
35 1.2
36 date 2001.09.14.22.09.41; author neil; state Exp;
37 branches;
38 next 1.1;
39
40 1.1
41 date 2001.09.14.22.09.40; author neil; state Exp;
42 branches;
43 next ;
44
45
46 desc
47 @@
48
49
50 1.6
51 log
52 @mbr-1.1.3.S86
53 @
54 text
55 @! mbr.S - a replacement master boot record
56 ! Copyright (C) 1995,1999-2001 Neil Turton
57 ! See the file AUTHORS for a list of contributors.
58 !
59 ! This program is free software; you can redistribute it and/or modify
60 ! it under the terms of the GNU General Public License as published by
61 ! the Free Software Foundation; either version 2 of the License, or
62 ! (at your option) any later version.
63 !
64 ! This program is distributed in the hope that it will be useful,
65 ! but WITHOUT ANY WARRANTY; without even the implied warranty of
66 ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67 ! GNU General Public License for more details.
68 !
69 ! You should have received a copy of the GNU General Public License
70 ! along with this program; if not, write to the Free Software
71 ! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
72 !
73 #define LOGO
74 #undef COMPAT
75 !
76 ! We are loaded at 0:0x7c00 by the BIOS, but need to load boot sectors
77 ! here, so we have got to move out of the way. We move to 0:DEST_ADDR
78 ! 0x600 is as good a place as any.
79 #define LOAD_ADDR 0x7c00
80 #define DEST_ADDR 0x600
81 ! The time when we started up.
82 stime equ 0x800
83 .org DEST_ADDR
84 ! Do not use DL here; we need the value later. It contains
85 ! the drive which the MBR was loaded from.
86 cld
87 xor ax,ax
88 mov ss,ax
89 xor sp,sp ! First word pushed goes to 0000:FFFE.
90 mov ds,ax
91 mov es,ax
92 mov si,#LOAD_ADDR
93 #ifdef Y2KBUG
94 #undef LOGO
95 ! We need dx and cx for locating and updating the MBR
96 pusha ! MBR data: cx=cylinder/sector dx=head/drive si=address
97 #endif
98 mov di,#DEST_ADDR ! Here will do
99 mov cx,#0x100
100 repz
101 movsw
102 mov si,#table+0x30 ! Set bootable flags from partition table
103 mov al,#8 ! AH=0 is set from above
104 jmp 0:cont ! Switch to the newly made copy. From now on labels work.
105 cont:
106 cmpb drive,#0xFF ! If drive==0xFF, use the value in DL instead.
107 jne ptloop
108 mov drive,dl ! Now DL is free for use
109 ptloop: cmpb [si],#0 ! Check for bootable flag
110 jz l7
111 or flags,al ! Set in flags
112 l7: sub si,#0x10
113 shr al,1
114 jnc ptloop ! Repeat until bit gets shifted out of al
115
116 int 0x1a ! AH=0: Get time
117 mov stime,dx
118
119 #ifdef Y2KBUG
120 ! Address the year in the loaded copy.
121 #define YEAR #(year-DEST_ADDR+LOAD_ADDR)
122
123 mov ah,#4
124 int 0x1a ! cx=year(bcd) dh=month(bcd) dl=day(bcd)
125 mov si,YEAR
126 lodsw ! DF=0 set before
127 cmp [si],dh ! compare last month, against this month
128 pushf
129 mov [si],dh
130 jbe setdate ! if CF=1 jump
131 inc ax ! we need to enter here with CF=0, inc doe not set it
132 daa
133 xchg ah,al
134 adc al,#0
135 daa
136 xchg ah,al
137 mov [si-2],ax
138 setdate:
139 mov cx,ax
140 mov ah,#5
141 int 0x1a
142 popf
143 popa
144 je nowrite
145 mov bx,si
146 mov ax,#0x0301
147 int 0x13
148 nowrite:
149
150 #endif
151
152 #ifdef LOGO
153 call show_logo
154 #endif
155
156 cmpb delay,#255
157 jz l3 ! Immediate interrupt
158 l0: testb def,#0x80 ! Key press interrupt allowed
159 jz l1
160 mov ah,#1
161 int 0x16
162 jnz l3 ! Interrupted
163 l1: testb def,#0x40 ! Shift/Ctrl allowed
164 jz l2
165 test byte 0x417,#0xf ! Check shift status
166 jnz l3 ! Interrupted
167 l2: xor ax,ax ! Check timer.
168 int 0x1a
169 sub dx,stime ! This code gets confused at midnight (FIXME)
170 sub dl,delay
171 sbb dh,#0
172 jb l0 ! Time not passed
173
174 l4: mov al,def ! Boot default
175 and al,#7
176 cmp al,#7
177 jnz boot2 ! Boot number al
178 mov si,#table ! Boot first partition marked bootable
179 mov al,#0
180 mov cx,#4
181 l5: cmpb [si],#0
182 boot2: jnz boot
183 inc al
184 add si,#0x10
185 loop l5 ! Try next partition
186
187 ! Display the prompt
188 l3:
189 #ifdef LOGO
190 call show_logo
191 #else
192 xor bx,bx
193 #endif
194 mov ah,#0xe ! Print char
195 mov si,#chars ! List of chars to print
196 mov cl,flags ! Interrupted (or no default)
197 l9: lodsb
198 shr cl,#1 ! Shift next bit into carry
199 jnb l8
200 int 0x10
201 l8: or cl,cl ! Any more bits set?
202 jnz l9
203 mov al,#0x3a ! Print a colon
204 int 0x10
205 l11: xor ax,ax ! Get user input
206 int 0x16
207 cmp al,#0
208 jz l11 ! Skip extended chars
209 cmp al,#13 ! RETURN pressed
210 jz l4 ! Boot default
211 cmp al,#'a ! CPP isn't quite compatible with as86
212 jb l10
213 cmp al,#'z ! ' This may make it a bit more obvious
214 ja l10
215 sub al,#0x20 ! Upper case input
216
217 l10: mov bl,al
218 mov si,#chars
219 mov cl,flags
220 l12: lodsb
221 shr cl,#1
222 jnb l13
223 cmp bl,al
224 jz l14
225 l13: or cl,cl
226 jnz l12
227 jmp l11
228 l14: mov ax,#0xe0d
229 xor bx,bx
230 int 0x10
231 ! FIXME: This could be shortened.
232 lea ax, 0xff&-(chars+1)[si]
233 cmp al,#7 ! Check if advanced mode selected
234 jnz boot
235 mov al,#0x1f
236 mov flags,al
237 il3: jmp l3
238
239 boot: ! Boot partition al
240 #ifdef LOGO
241 ! Re-display the logo, so the prompt is right if we get an
242 ! error.
243 call show_logo
244 #endif
245 xor dx,dx
246 mov cx,#1
247 cmp al,#4
248 jz sdr ! Boot from floppy (DL=0)
249 jnb il3 ! Illegal - interrupt
250
251 xor ah,ah
252 mov cl,#4
253 shl al,cl
254 mov si,#table
255 add si,ax
256 mov dl,drive
257
258 ! Entry:
259 ! SI -> Partition record
260 ! DL = Drive number
261 sread: test dl, #0x80 ! Only try the extended interface on
262 je sdi ! hard disks.
263
264 mov ah, #0x41
265 mov bx, #0x55aa
266 push si
267 push dx
268 int #0x13
269 pop dx
270 pop si
271 jb sdi
272 cmp bx, #0xaa55 ! Check the signature
273 jnz sdi
274 test cl, #1 ! Check the API support bitmap
275 jz sdi
276
277 ! That will do. The big disk extenstion is there.
278 mov ax, 8[si]
279 mov bx, 10[si]
280 mov si, #request
281 mov 8[si], ax
282 mov 10[si], bx
283 mov ah, #0x42
284 jmp cdi
285
286 ! Entry:
287 ! SI -> Partition record
288 ! DL = Drive number
289 sdi: mov dh,[si+1]
290 mov cx,[si+2]
291
292 ! Entry:
293 ! DH = head
294 ! CX = cylinder/sector
295 ! DL = Drive number
296 sdr: mov ax,#0x201
297 mov bx,#LOAD_ADDR
298 cdi: mov di,#5 ! number of retries
299 l6: push ax
300 mov byte [request+2], #1 ! Reset count to 1
301 int 0x13
302 pop ax
303 jnb lbit
304 dec di
305 jnz l6
306 iil3: jmp il3
307 lbit: cmp 0x7dfe,#0xaa55
308 jnz iil3
309 #ifdef LOGO
310 ! Start the next line.
311 xor bx, bx
312 mov ax, #0xe0d
313 int 0x10
314 mov al, #0xa
315 int 0x10
316 #endif
317 jmp 0:LOAD_ADDR
318
319 #ifdef LOGO
320 ! Corrupts si, cx. Returns with bx=0
321 show_logo:
322 ! Code to print the word "MBR" at boot time, to let people
323 ! know that we are here. - Tom Rothamel <tom-10990@@onegeek.org>
324 ! Inspired by a discussion on debian-devel.
325 push ax
326 mov ax,#0xe0d ! Print char CR
327 xor bx,bx
328 int 0x10
329 mov si,#logo
330 mov cx,#logolen
331 logol:
332 lodsb
333 int 0x10
334 loop logol
335 pop ax
336 ret
337
338 logo: .ascii "MBR "
339 logo_end:
340 logolen equ logo_end-logo ! The length of the logo string.
341 #endif
342
343 request:.byte 0x10, 0, 1, 0
344 .word LOAD_ADDR, 0
345 .word 0, 0, 0, 0
346 chars: db '1,'2,'3,'4,'F,0,0,'A
347 ! The data area follows. Access to this data area from
348 ! external code should be via the pointer at offset 0x1bc.
349 ! Check the signature and version numbers. If the program
350 ! knows about version V, it may access the data if X<=V<=Y.
351 ! While the version is still 0.0, just check X against 0.0.
352 !
353 ! There used to be 2 bytes for the version number. I now see
354 ! this as overkill. 1 byte should be enough for the version
355 ! number. The spare byte in the real version will be assembly
356 ! flags. The spare byte in the compat version will be
357 ! reserved for future expansion.
358 data: .ascii "NDTmbr" ! Sig string
359 db 0 ! Reserved. Zero so that old installers accept this.
360 db 0 ! From version X=0 i.e. Compat version
361 #ifndef Y2KBUG
362 db 0 ! Assembly flags: none
363 #else
364 db 1 ! Assembly flags: y2k
365 #endif
366 db 1 ! To version Y=1 i.e. Real version
367 #ifndef COMPAT
368 ! Setup the flags with cool settings. Have no delay, but allow
369 ! interrupt. We mark everything bootable, but default to booting
370 ! the active partition.
371 flags: db 0x90 ! Floppy bootable. Advanced mode available.
372 def: db 0xc7 ! Interrupt by anything.
373 delay: db 18 ! About 1 second
374 drive: db 0x80 ! /dev/hda
375 #else
376 ! Setup the flags to mimic standard MBRs unless interrupted
377 ! flags:bits 0-4 marks partitions 1-4 and floppy bootable
378 ! bit 7 = unlocked
379 ! def: bits 0-2 default boot partition (0-3, 4=floppy or 7=active)
380 ! bits 6,7 interrupt on (shift/ctrl,key press)
381 flags: db 0 ! No specially bootable partitions. Advanced mode disabled.
382 def: db 7 ! Boot active partition
383 delay: db 0 ! Delay in timer ticks. 0=>No delay. 255=>Interrupt.
384 drive: db 0x80
385 #endif
386 #ifdef Y2KBUG
387 .org DEST_ADDR+0x1b9
388 year: dw 0x2001 ! Year
389 db 1 ! Month
390 #endif
391 .org DEST_ADDR+0x1bc
392 dw data-DEST_ADDR ! Pointer to the data
393 ! Format of partition table entry
394 ! 00 byte Boot indicator
395 ! 01 byte start head
396 ! 02 byte start sector
397 ! 03 byte start cylinder
398 ! 04 byte type
399 ! 05 byte end head
400 ! 06 byte end sector
401 ! 07 byte end cylinder
402 ! 08 dw sectors before partition
403 ! 0c dw sectors in partition
404 table: .space 0x40 ! The partition table
405 dw 0xaa55
406
407 ! Local Variables:
408 ! mode:asm
409 ! End:
410 @
411
412
413 1.5
414 log
415 @mbr-1.1.2.S86
416 @
417 text
418 @d2 2
419 a3 1
420 ! Copyright (C) 1995 Neil Turton
421 d25 1
422 d38 6
423 a43 1
424 mov si,#0x7c00
425 d62 36
426 a103 2
427 int 0x1a ! AH=0: Get time
428 mov stime,dx
429 d243 1
430 a243 1
431 mov bx,#0x7c00
432 d263 1
433 a263 1
434 jmp 0:0x7c00
435 d290 1
436 a290 1
437 .word 0x7c00, 0
438 d298 6
439 d305 8
440 a312 2
441 db 0,0 ! From version X=0.0
442 db 0,0 ! to version Y=0.0
443 d331 5
444 @
445
446
447 1.4
448 log
449 @mbr-1.1.1.S86
450 @
451 text
452 @d18 1
453 d44 2
454 a45 1
455 cont: cmpb drive,#0xFF ! If drive==0xFF, use the value in DL instead.
456 d54 5
457 a61 1
458 mov stime+2,cx
459 d74 1
460 a74 2
461 sub dx,stime ! This code gets confused at midnight
462 sbb cx,stime+2 ! (FIXME)
463 a76 1
464 sbb cx,#0
465 d78 1
466 d91 9
467 a99 1
468 l3: mov cl,flags ! Interrupted (or no default)
469 d101 1
470 a104 2
471 mov ah,#0xe ! Print char
472 xor bx,bx
473 d108 1
474 a108 2
475 mov ax,#0xe3a ! Print a colon
476 xor bx,bx
477 d121 1
478 d136 2
479 a137 2
480 mov ax,si
481 sub ax,#chars+1
482 d144 7
483 a150 1
484 boot: xor dx,dx ! Boot partition al
485 d155 1
486 d204 1
487 a204 4
488 l6: push cx
489 push dx
490 push di
491 push ax
492 a207 3
493 pop di
494 pop dx
495 pop cx
496 d211 1
497 a211 1
498 jmp il3
499 d213 9
500 a221 1
501 jnz il3
502 d223 25
503 @
504
505
506 1.3
507 log
508 @mbr-1.1.0.S86
509 @
510 text
511 @d158 1
512 a158 1
513 cmp bx, #0xaa55
514 d160 2
515 d188 1
516 d191 1
517 @
518
519
520 1.2
521 log
522 @mbr-1.0.1.S86
523 @
524 text
525 @d64 1
526 a64 1
527 test 0x417,#0xf ! Check shift status
528 d135 1
529 a135 1
530 jz sread ! Boot from floppy
531 d143 31
532 a173 1
533 mov dh,[si+1]
534 d175 8
535 a182 1
536 sread: mov di,#5 ! number of retries
537 d186 1
538 a186 2
539 mov ax,#0x201
540 mov bx,#0x7c00
541 d189 1
542 a189 1
543 pop bx
544 d198 3
545 d222 1
546 a222 1
547 ! def: bits 0-2 default boot partition (0-4 or 7=active)
548 d244 4
549 @
550
551
552 1.1
553 log
554 @mbr-1.0.0.S86
555 @
556 text
557 @d27 2
558 d31 2
559 d41 1
560 a41 1
561 mov al,#8
562 d43 4
563 a46 1
564 cont: cmpb [si],#0 ! Check for bootable flag
565 d51 1
566 a51 1
567 jnc cont ! Repeat until bit gets shifted out of al
568 d54 1
569 a54 1
570 int 0x1a ! Get time
571 d142 1
572 a142 1
573 mov dl,#0x80
574 d145 1
575 a145 1
576 sread: mov di,#5
577 d163 5
578 d169 2
579 a170 2
580 db 0,0 ! From version 0.0
581 db 0,0 ! to version 0.0
582 d178 1
583 a178 1
584 drive: db 0x80 ! /dev/hda1
585 @