boot.lst

来自「DOS SOURCE CODE,DOS-C started in 1988 as」· LST 代码 · 共 727 行 · 第 1/3 页

LST
727
字号


    221						     jne     fat_12
    222						     cmp     byte ptr filesys[4], '6'  ; check for FAT-16 system
    223						     je	     fat_16
    224
    225						     ; This is a FAT-12	disk.
    226
    227				     fat_12:	     add     si, si	     ; multiply	cluster	number by 3...
    228						     add     si, ax
    229						     shr     si, 1	     ; ...and divide by	2
    230						     lodsw
    231
    232						     ; If the cluster number was even, the cluster value is now	in
    233						     ; bits 0-11 of AX.	If the cluster number was odd, the cluster
    234						     ; value is	in bits	4-15, and must be shifted right	4 bits.	If
    235						     ; the number was odd, CF was set in the last shift	instruction.
    236
    237						     jnc     fat_even
    238						     mov     cl, 4
    239						     shr     ax, cl	     ; shift the cluster number
    240
    241				     fat_even:	     and     ah, 0fh	     ; mask off	the highest 4 bits
    242						     cmp     ax, 0fffh	     ; check for EOF
    243						     jmp     short next_test
    244
    245						     ; This is a FAT-16	disk. The maximal size of a 16-bit FAT
    246						     ; is 128 kb, so it	may not	fit within a single 64 kb segment.
    247
    248				     fat_16:	     mov     dx, tempbuf
    249						     add     si, si	     ; multiply	cluster	number by two
    250						     jnc     first_half	     ; if overflow...
    251						     add     dh, 10h	     ; ...add 64 kb to segment value
    252
    253				     first_half:     mov     ds, dx	     ; DS:SI = pointer to next cluster
    254						     lodsw		     ; AX = next cluster
    255
    256						     cmp     ax, 0fff8h	     ; >= FFF8 = 16-bit	EOF
    257				     next_test:	     jb	     next_clust	     ; continue	if not EOF
    258
    259				     finished:	     ; Mark end	of FAT chain with 0, so	we have	a single
    260						     ; EOF marker for both FAT-12 and FAT-16 systems.
    261
    262						     xor     ax, ax
    263						     stosw
    264				     fatError:
    265						     ENDM
    266
    267				     ;	     loadFile: Loads the file into memory, one cluster at a time.
    268
    269				     loadFile	     MACRO
    270						     mov     es, tempbuf     ; set ES:BX to load address
    271						     xor     bx, bx
    272
    273						     mov     si, FATBUF	     ; set DS:SI to the	FAT chain
    274						     push    cs
    275						     pop     ds
Turbo Assembler	 Version 3.1	    04/11/13 12:54:48	    Page 6
boot.ASM



    276
    277				     next_cluster:   lodsw			     ; AX = next cluster to read
    278						     or	     ax, ax		     ; if EOF...
    279						     je	     boot_success	     ; ...boot was successful
    280
    281						     dec     ax			     ; cluster numbers start with 2
    282						     dec     ax
    283
    284						     mov     di, word ptr sectPerCluster
    285						     and     di, 0ffh		     ; DI = sectors per	cluster
    286						     mul     di
    287						     add     ax, data_start
    288						     adc     dx, data_start+2	     ; DX:AX = first sector to read
    289						     call    readDisk
    290						     jnc     next_cluster
    291
    292						     ENDM
    293
    294						     org     BASE+3eh
    295
    296	      =	[bp+3eh]	     tempbuf	     equ     [bp+3eh]
    297	003E  2000		     load_seg	     dw	     LOADSEG
    298
    299	0040  FA		     real_start:     cli
    300	0041  FC				     cld
    301	0042  8C C8				     mov     ax, cs
    302	0044  8E D0				     mov     ss, ax	     ; initialize stack
    303	0046  BD 7C00				     mov     bp, 7c00h
    304	0049  8D 66 E0				     lea     sp, [bp-20h]
    305	004C  FB				     sti
    306
    307	004D  8E C0				     mov     es, ax
    308	004F  8E D8				     mov     ds, ax
    309	0051  88 56 24				     mov     drive, dl	     ; BIOS passes drive number	in DL
    310
    311						     GETDRIVEPARMS
1   312	0054  8B 76 1C				     mov     si, word ptr nHidden
1   313	0057  8B 7E 1E				     mov     di, word ptr nHidden+2
1   314	005A  03 76 0E				     add     si, word ptr resSectors
1   315	005D  83 D7 00				     adc     di, 0		     ; DI:SI = first FAT sector
1   316	0060  89 76 FC				     mov     word ptr fat_start, si
1   317	0063  89 7E FE				     mov     word ptr fat_start+2, di
1   318	0066  8A 46 10				     mov     al, nFats
1   319	0069  32 E4				     xor     ah, ah
1   320	006B  F7 66 16				     mul     word ptr sectPerFat     ; DX:AX = total number of FAT sectors
1   321	006E  03 F0				     add     si, ax
1   322	0070  13 FA				     adc     di, dx		     ; DI:SI = first root directory sector
1   323	0072  89 76 F8				     mov     word ptr root_dir_start, si
1   324	0075  89 7E FA				     mov     word ptr root_dir_start+2,	di
1   325	0078  8B 5E 0B				     mov     bx, bytesPerSector
1   326	007B  B1 05				     mov     cl, 5		     ; divide BX by 32
1   327	007D  D3 EB				     shr     bx, cl		     ; BX = directory entries per sector
1   328	007F  8B 46 11				     mov     ax, nRootDir
1   329	0082  33 D2				     xor     dx, dx
1   330	0084  F7 F3				     div     bx
Turbo Assembler	 Version 3.1	    04/11/13 12:54:48	    Page 7
boot.ASM



1   331	0086  89 46 11				     mov     nRootDir, ax	     ; AX = sectors per	root directory
1   332	0089  03 F0				     add     si, ax
1   333	008B  83 D7 00				     adc     di, 0		     ; DI:SI = first data sector
1   334	008E  89 76 F4				     mov     data_start, si
1   335	0091  89 7E F6				     mov     data_start+2, di
    336
    337						     FINDFILE		     ; locate file in root directory
1   338	0094  8B 46 F8				     mov     ax, word ptr root_dir_start
1   339	0097  8B 56 FA				     mov     dx, word ptr root_dir_start+2
1   340	009A  8B 7E 11				     mov     di, nRootDir
1   341	009D  33 DB				     xor     bx, bx
1   342	009F  8E 46 3E				     mov     es, tempbuf
1   343	00A2  E8 00B9				     call    readDisk
1   344	00A5  72 1D				     jc	     ffDone
1   345	00A7  33 FF				     xor     di, di
1   346	00A9  B9 000B		     next_entry:     mov     cx, 11
1   347	00AC  BE 7DEEr				     mov     si, offset	filename+7c00h
1   348	00AF  57				     push    di
1   349	00B0  F3> A6				     repe    cmpsb
1   350	00B2  5F				     pop     di
1   351	00B3  26: 8B 45	1A			     mov     ax, es:[di][1ah]	 ; get cluster number from directory entry
1   352	00B7  F8				     clc
1   353	00B8  74 0A				     je	     ffDone
1   354	00BA  83 C7 20				     add     di, 20h		 ; go to next directory	entry
1   355	00BD  26: 80 3D	00			     cmp     byte ptr es:[di], 0     ; if the first byte of the	name is	0,
1   356	00C1  75 E6				     jnz     next_entry		     ; there is	no more	files in the directory
1   357	00C3  F9				     stc
1   358	00C4			     ffDone:
    359	00C4  72 7A				     jc	     boot_error	     ; fail if not found
    360
    361						     GETFATCHAIN	     ; read FAT	chain
1   362	00C6  50				     push    ax			     ; store first cluster number
1   363	00C7  8E 46 3E				     mov     es, tempbuf
1   364	00CA  33 DB				     xor     bx, bx
1   365	00CC  8B 7E 16				     mov     di, sectPerFat
1   366	00CF  8B 46 FC				     mov     ax, word ptr fat_start
1   367	00D2  8B 56 FE				     mov     dx, word ptr fat_start+2
1   368	00D5  E8 0086				     call    readDisk
1   369	00D8  58				     pop     ax			     ; restore first cluster number
1   370	00D9  72 65				     jc	     boot_error
1   371	00DB  1E				     push    ds
1   372	00DC  06				     push    es
1   373	00DD  1F				     pop     ds
1   374	00DE  07				     pop     es
1   375	00DF  BF 4000				     mov     di, FATBUF
1   376	00E2  AB		     next_clust:     stosw			     ; store cluster number
1   377	00E3  8B F0				     mov     si, ax		     ; SI = cluster number
1   378	00E5  80 7E 26 29			     cmp     byte ptr extBoot, 29h
1   379	00E9  75 06				     jne     fat_12
1   380	00EB  80 7E 3A 36			     cmp     byte ptr filesys[4], '6'  ; check for FAT-16 system
1   381	00EF  74 15				     je	     fat_16
1   382	00F1  03 F6		     fat_12:	     add     si, si	     ; multiply	cluster	number by 3...
1   383	00F3  03 F0				     add     si, ax
1   384	00F5  D1 EE				     shr     si, 1	     ; ...and divide by	2
1   385	00F7  AD				     lodsw
Turbo Assembler	 Version 3.1	    04/11/13 12:54:48	    Page 8
boot.ASM



1   386	00F8  73 04				     jnc     fat_even
1   387	00FA  B1 04				     mov     cl, 4
1   388	00FC  D3 E8				     shr     ax, cl	     ; shift the cluster number
1   389	00FE  80 E4 0F		     fat_even:	     and     ah, 0fh	     ; mask off	the highest 4 bits
1   390	0101  3D 0FFF				     cmp     ax, 0fffh	     ; check for EOF
1   391	0104  EB 10				     jmp     short next_test
1   392	0106  8B 56 3E		     fat_16:	     mov     dx, tempbuf
1   393	0109  03 F6				     add     si, si	     ; multiply	cluster	number by two
1   394	010B  73 03				     jnc     first_half	     ; if overflow...
1   395	010D  80 C6 10				     add     dh, 10h	     ; ...add 64 kb to segment value
1   396	0110  8E DA		     first_half:     mov     ds, dx	     ; DS:SI = pointer to next cluster
1   397	0112  AD				     lodsw		     ; AX = next cluster
1   398	0113  3D FFF8				     cmp     ax, 0fff8h	     ; >= FFF8 = 16-bit	EOF
1   399	0116  72 CA		     next_test:	     jb	     next_clust	     ; continue	if not EOF
1   400	0118			     finished:	     ; Mark end	of FAT chain with 0, so	we have	a single
1   401	0118  33 C0				     xor     ax, ax
1   402	011A  AB				     stosw
1   403	011B			     fatError:
    404						     LOADFILE		     ; load file (jumps	to boot_sucess if successful)
1   405	011B  8E 46 3E				     mov     es, tempbuf     ; set ES:BX to load address
1   406	011E  33 DB				     xor     bx, bx
1   407	0120  BE 4000				     mov     si, FATBUF	     ; set DS:SI to the	FAT chain
1   408	0123  0E				     push    cs
1   409	0124  1F				     pop     ds
1   410	0125  AD		     next_cluster:   lodsw			     ; AX = next cluster to read
1   411	0126  0B C0				     or	     ax, ax		     ; if EOF...
1   412	0128  74 2C				     je	     boot_success	     ; ...boot was successful
1   413	012A  48				     dec     ax			     ; cluster numbers start with 2
1   414	012B  48				     dec     ax
1   415	012C  8B 7E 0D				     mov     di, word ptr sectPerCluster
1   416	012F  81 E7 00FF			     and     di, 0ffh		     ; DI = sectors per	cluster
1   417	0133  F7 E7				     mul     di
1   418	0135  03 46 F4				     add     ax, data_start
1   419	0138  13 56 F6				     adc     dx, data_start+2	     ; DX:AX = first sector to read
1   420	013B  E8 0020				     call    readDisk
1   421	013E  73 E5				     jnc     next_cluster
    422
    423	0140  B9 000A 90	     boot_error:     mov     cx, ERRMSGLEN
    424	0144  BE 7DE4r				     mov     si, offset	errmsg+7c00h
    425
    426	0147  AC		     next_char:	     lodsb		     ; print error message
    427	0148  B4 0E				     mov     ah, 0eh
    428	014A  32 FF				     xor     bh, bh
    429	014C  CD 10				     int     10h
    430	014E  E2 F7				     loop    next_char
    431
    432	0150  32 E4				     xor     ah, ah
    433	0152  CD 16				     int     16h	     ; wait for	keystroke
    434	0154  CD 19				     int     19h	     ; invoke bootstrap	loader
    435
    436	0156  8A 56 24		     boot_success:   mov     dl, drive
    437
    438	0159  EA				     db	     0eah	     ; far jump	to LOADSEG:0000
    439	015A  0000				     dw	     0
    440	015C  2000				     dw	     LOADSEG
Turbo Assembler	 Version 3.1	    04/11/13 12:54:48	    Page 9
boot.ASM



    441

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?