📄 bootload.lst
字号:
1 BITS 16
2 SECTION .text
3 buffer EQU 512
4 image_size EQU 512
5 ; ================================================================
6 ; IBM-PC DISK BOOT LOADER FOR PROTECTED MODE EMBEDDED APPLICATIONS
7 ;
8 ; This boot laoder loads a file called "EMBEDDED.BIN" from
9 ; the same diskette into memory starting at physical address
10 ; zero. Before transferring control to the application, it
11 ; enables the A20 line to make memory above 1MB accessible
12 ; and disables the interrupt system. The application is
13 ; responsible for establishing its own protected mode
14 ; interrupt service routines and for putting the processor
15 ; into protected mode.
16 ; ================================================================
17
18 ; ----------------------------------------------------------------
19 ; Disk Area Sectors
20 ; ----------------------- ----------------------------------
21 ; Boot Loader (this code) 1
22 ; FAT #1 sctrs_per_fat
23 ; FAT #2 sctrs_per_fat
24 ; Root Directory (32 * dir_entries) / bytes_per_sctr
25 ; Files Area .....
26 ; ----------------------------------------------------------------
27
28 ORG 0
29 00000000 E95600 Boot_Loader: JMP start
30
31 00000003 454D424544444544 oem_name: DB 'EMBEDDED' ; Windows writes over these bytes!
32
33 ; ----------------------------------------------------------------
34 ; Bios Parameter Block (BPB)
35 ; ----------------------------------------------------------------
36 0000000B 0002 bytes_per_sctr: DW 512 ; Bytes per sector
37 0000000D 01 sctrs_per_clust:DB 1 ; Sectors per cluster
38 0000000E 0100 rsvd_sectors: DW 1 ; Reserved sectors (the boot sector)
39 00000010 02 number_fats: DB 2 ; Number of FATs
40 00000011 E000 dir_entries: DW 224 ; Number of root-directory entries
41 00000013 400B total_sctrs: DW 2880 ; Total sectors in logical volume
42 00000015 F0 media_desc: DB 0F0h ; Media descriptor byte
43 00000016 0900 sctrs_per_fat: DW 9 ; Sectors per FAT
44
45 ; ----------------------------------------------------------------
46 ; Additional information (MS/DOS 3.0)
47 ; ----------------------------------------------------------------
48 00000018 1200 sctrs_per_track:DW 18 ; Sectors per track
49 0000001A 0200 number_heads: DW 2 ; Number of heads
50 0000001C 0000 hidden_sctrs: DW 0 ; Number of hidden sectors
51
52 ; ----------------------------------------------------------------
53 ; Additional information (MS/DOS 4.0)
54 ; ----------------------------------------------------------------
55 0000001E 0000 DW 0 ; MSW of 'hidden_sctrs' (above)
56 00000020 00000000 ttl_sctrs_vol: DD 0 ; total log sctrs in log volume
57 00000024 00 phys_drive: DB 0 ; physical drive number
58 00000025 00 DB 0 ; reserved
59 00000026 29 ext_boot_sig: DB 29h ; extended boot signature
60 00000027 00000000 volume_id: DD 0 ; 32-bit binary volume ID
61 0000002B 424F4F542E4C4F4144- volume_label: DB 'BOOT.LOADER' ; volume label
62 00000034 4552
63 00000036 3F3F3F3F3F3F3F3F DB '????????' ; reserved
64
65 ; ----------------------------------------------------------------
66 ; Additional information written by COPYBOOT.EXE
67 ; ----------------------------------------------------------------
68 0000003E 0000 fat_nibbles: DW 0 ; 4-bit Nibbles per FAT entry
69 00000040 0000 bytes_per_clust:DW 0 ; Bytes per cluster
70 00000042 0000 dir_sector0: DW 0 ; log sctr # of 1st sctr in dir area
71 00000044 0000 data_sector0: DW 0 ; log sctr # of 1st sctr in files area
72 00000046 0000 dir_sectors: DW 0 ; # directory sectors
73 00000048 0000 paras_per_clust:DW 0 ; paragraphs per cluster
74 0000004A 0000 kb_needed: DW 0 ; total KB memory req'd by loader
75 0000004C 0000 end_of_chain: DW 0 ; FAT12 => 0FFFH or FAT16 => FFFFH
76
77 ; ----------------------------------------------------------------
78 ; Additional data NOT written by COPYBOOT.EXE
79 ; ----------------------------------------------------------------
80 0000004E 454D42454444454442- file2load: DB 'EMBEDDEDBIN' ; Filename: "EMBEDDED.BIN"
81 00000057 494E
82
83 ; ----------------------------------------------------------------
84 start: ; Loader routine starts here
85 ; ----------------------------------------------------------------
86 00000059 FB STI ; Just in case
87 0000005A FC CLD ; Needed by all REP's that follow
88 0000005B 31C0 XOR AX,AX
89 0000005D 8ED0 MOV SS,AX ; The ROM BIOS only uses the lower
90 0000005F BC0004 MOV SP,0400h ; half of the interrupt vector table
91
92 ; Relocate myself to the top of base memory
93
94 00000062 0E PUSH CS
95 00000063 1F POP DS
96 00000064 E80000 CALL next ; PUSH offset of 'next'
97 00000067 5E next: POP SI
98 00000068 81EE[6700] SUB SI,next ; DS:SI = source address
99 0000006C CD12 INT 12H ; AX = Memory Size in KB
100 0000006E 2B84[4A00] SUB AX,[kb_needed+SI] ; Reserve room for loader
101 00000072 C1E006 SHL AX,6 ; AX = target segment
102 00000075 8EC0 MOV ES,AX
103 00000077 31FF XOR DI,DI ; ES:DI = target address
104 00000079 B90002 MOV CX,image_size
105 0000007C F3A4 REP MOVSB
106 0000007E 06 PUSH ES
107 0000007F B8[8400] MOV AX,continue
108 00000082 50 PUSH AX
109 00000083 CB RETF
110
111 00000084 8CC8 continue: MOV AX,CS ; Now initialize DS and ES
112 00000086 8ED8 MOV DS,AX ; so that our offsets are
113 00000088 8EC0 MOV ES,AX ; meaningful.
114
115 0000008A 8B3E[4200] MOV DI,[dir_sector0]; Load root directory
116 0000008E 8B2E[4600] MOV BP,[dir_sectors]; into the buffer
117 00000092 8D1E0002 LEA BX,[buffer]
118 00000096 E8D100 CALL Read_Sectors ; (Modifies AX,BX,CX,DX,SI,DI,BP)
119 00000099 E85A00 CALL Find_File ; (Modifies BX,CX,BP,SI)
120
121 0000009C 57 PUSH DI ; DI = 1st cluster #
122 0000009D 8B3E[0E00] MOV DI,[rsvd_sectors] ; Load FAT into the buffer
123 000000A1 8B2E[1600] MOV BP,[sctrs_per_fat]
124 000000A5 8D1E0002 LEA BX,[buffer]
125 000000A9 E8BE00 CALL Read_Sectors ; (Modifies AX,BX,CX,DX,SI,DI,BP)
126 000000AC 5F POP DI
127
128 000000AD BB8000 MOV BX,0080H ; load address = 0080:0000
129 000000B0 8EC3 MOV ES,BX
130 000000B2 E87100 BL1: CALL Read_Cluster ; (Modifies AX, CX, DX, BP, SI, ES)
131 000000B5 E88E00 CALL Next_Cluster ; (Modifies AX, CX, DX)
132 000000B8 89F8 MOV AX,DI
133 000000BA 25F0FF AND AX,0FFF0h
134 000000BD 3B06[4C00] CMP AX,[end_of_chain]
135 000000C1 75EF JNE BL1
136
137 ; save ending paragraph # for later
138
139 000000C3 06 PUSH ES
140
141 ; Turn off floppy drive light
142
143 000000C4 B96400 MOV CX,100
144 000000C7 CD08 WaitForDrive: INT 08h ; Forced timer tick
145 000000C9 E2FC LOOP WaitForDrive
146
147 ; Make memory above 1MB accessible
148
149 000000CB E8D800 CALL Enable_A20
150
151 ; The BIOS, its ISRs, and the interrupt vector
152 ; table are no longer needed. Disable interrupts
153 ; before writing over the interrupt vector table
154 ; and the BIOS data area just above it.
155
156 000000CE FA CLI
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -