1 Turbo Assembler Version 3.1 11/25/94 10:53:02 Page 1
\r
7 2 ;This boot sector is STUFFed to the gills to do a single
\r
8 3 ;stage boot of the MMURTL OS which is about 150K stored as
\r
9 4 ;a loadable image beginning at cluster 2 on the disk. The OS must
\r
10 5 ;be stored contiguously in each of the following logical sectors.
\r
11 6 ;The actual number of sectors is stored in the data param nOSSectors.
\r
13 8 0000 CSEG SEGMENT WORD 'Code' USE16
\r
14 9 ASSUME CS:CSEG, DS:CSEG, ES:Nothing
\r
18 13 0000 EB 48 JMP SHORT Bootup
\r
19 14 0002 90 NOP ;To use 3 bytes which aligned data
\r
21 16 ;OS Herald, Partition info begins here
\r
23 18 0003 4D 55 52 54 4C 31 2E+ Herald DB 'MURTL1.0'
\r
25 20 000B 0200 nBytesPerSect DW 0200h ;nBytes/Sector
\r
26 21 000D 01 nSectPerClstr DB 01h ;Sect/Cluster
\r
27 22 000E 0001 nRsvdSect DW 0001h ;Resvd sectors
\r
28 23 0010 02 nFATS DB 02 ;nFATs
\r
29 24 0011 00E0 nRootDirEnts DW 00E0h ;Root Dir entries max
\r
30 25 0013 0B40 nTotalSectors DW 0B40h ;nTotal Sectors (0 = <32Mb)
\r
31 26 0015 F0 bMedia DB 0F0h ;media desc. (worthless)
\r
32 27 0016 0009 nSectPerFAT DW 0009h ;nSect in FAT
\r
33 28 0018 0012 nSectPerTrack DW 0012h ;nSectors/track
\r
34 29 001A 0002 nHeads DW 0002h ;nHeads
\r
35 30 001C 00000000 nHidden DD 00000000h ;nHidden Sectors (first whole track on HD)
\r
36 31 0020 00000000 nTotalSect32 DD 00000000h ;nTotalSectors if > 32Mb
\r
38 33 0024 00 bBootDrive DB 00h ;Drive boot sector came from
\r
40 35 0025 00 ResvdByte DB 00h ;Used for temp storage of Sector to Read
\r
42 37 0026 29 ExtBootSig DB 29h ; Ext Boot Signature (always 29h)
\r
43 38 0027 0140 nOSSectors DW 0140h ; (140 sectors max) Was Volume ID number
\r
44 39 0029 0000 ResvdWord DW 0000h
\r
45 40 002B 52 49 43 48 20 20 20+ Volname DB 'RICH ' ;11 bytes for volume name
\r
47 42 0036 46 41 54 31 32 20 20+ FatType DB 'FAT12 ' ;8 bytes for FAT name (Type)
\r
50 45 003E 07FF IDTptr DW 7FFh ;LIMIT 256 IDT Slots
\r
51 46 0040 00000000 DD 0000h ;BASE (Linear)
\r
53 48 0044 17FF GDTptr DW 17FFh ;LIMIT 768 slots
\r
54 49 0046 00000800 DD 0800h ;BASE (Linear)
\r
56 51 ;Herald and partiton info ends here
\r
60 55 ;Boot blocks first instruction starts here after initial jump from beginning
\r
61 56 004A FA CLI ;Clear interrupts
\r
63 \fTurbo Assembler Version 3.1 11/25/94 10:53:02 Page 2
\r
68 58 ;Stick the stack at 98000h
\r
70 60 004B B8 9000 MOV AX,9000h
\r
71 61 004E 8E D0 MOV SS, AX
\r
72 62 0050 BC 8000 MOV SP, 8000h
\r
74 64 ;Move this boot sector UP to 90000h Linear.
\r
76 66 0053 B8 9000 MOV AX, 09000h
\r
77 67 0056 8E C0 MOV ES, AX
\r
78 68 0058 33 FF XOR DI, DI
\r
79 69 005A B8 07C0 MOV AX, 7C0h
\r
80 70 005D 8E D8 MOV DS, AX
\r
81 71 005F 33 F6 XOR SI, SI
\r
82 72 0061 B9 0200 MOV CX, 512
\r
83 73 0064 F3> A4 REP MOVSB
\r
85 75 ; Now we jump UP to where we moved it.
\r
87 77 0066 B8 9000 MOV AX, 09000h ;Segment
\r
89 79 006A B8 006F MOV AX, 6Fh ;Offset
\r
93 83 ; Now set DS equal to ES which is 9000h
\r
96 86 0071 8B 0E 0018r MOV CX, nSectPerTrack
\r
98 88 0075 33 C0 XOR AX, AX
\r
99 89 0077 8E D8 MOV DS, AX
\r
100 90 0079 BB 0078 MOV BX, 0078h ;Int 1E FDC Params!
\r
101 91 007C C5 37 LDS SI, DS:[BX]
\r
103 93 007E 88 4C 04 MOV BYTE PTR [SI+4], CL
\r
104 94 0081 C6 44 09 0F MOV BYTE PTR [SI+9], 0Fh
\r
112 102 0089 8A 16 0024r MOV DL, bBootDrive ;Required for Disk System Reset
\r
113 103 008D 33 C0 XOR AX, AX
\r
115 105 008F CD 13 INT 13h ;Reset Disk Controller (DL has drive num)
\r
116 106 0091 72 33 JC SHORT BadBoot ;Reset failed...
\r
120 110 ;The controller is reset, now let's read some stuff!!
\r
121 111 ;We are gonna skip checking to see if the first file
\r
122 112 ;really IS the OS. We need the space for other code.
\r
124 114 0094 BE 01EBr MOV SI, OFFSET MsgLoad
\r
125 \fTurbo Assembler Version 3.1 11/25/94 10:53:02 Page 3
\r
130 115 0097 E8 0038 CALL PutChars
\r
132 117 ;What we do now is calcualte our way to the third cluster
\r
133 118 ;on the disk and read in the total number of OS sectors in
\r
134 119 ;logical sector order. (3rd cluster is really the first allocated
\r
135 120 ; cluster because first 2 are unused).
\r
136 121 ;The layout of the Disk is:
\r
137 122 ; Boot Sector (at logical sector 0)
\r
138 123 ; Hidden Sectors (optional)
\r
139 124 ; FATS (1 or more)
\r
140 125 ; Additional Reserved sectors (optional)
\r
141 126 ; Root Directory (n Sectors long)
\r
143 128 009A 33 C0 XOR AX, AX
\r
144 129 009C A0 0010r MOV AL, nFATS
\r
145 130 009F F7 26 0016r MUL WORD PTR nSectPerFAT
\r
146 131 00A3 03 06 001Cr ADD AX, WORD PTR nHidden ;
\r
147 132 00A7 13 16 001Er ADC DX, WORD PTR nHidden+2
\r
148 133 00AB 03 06 000Er ADD AX, nRsvdSect
\r
149 134 00AF 8B C8 MOV CX, AX ;Save in CX
\r
151 136 ;CX now has a Word that contains the sector of the Root
\r
153 138 ;Calculate the size of the root directory and skip past it
\r
154 139 ;to the first allocated sectors (this is where the OS or
\r
155 140 ;stage one of the a two stage loader should be).
\r
157 142 00B1 B8 0020 MOV AX,0020h ;Size of Dir Entry
\r
158 143 00B4 F7 26 0011r MUL WORD PTR nRootDirEnts
\r
159 144 00B8 8B 1E 000Br MOV BX, nBytesPerSect
\r
160 145 00BC F7 F3 DIV BX
\r
161 146 00BE 03 C1 ADD AX, CX
\r
163 148 ;AX is at sector for cluster 0, but cluster 0 and 1 don't exist
\r
164 149 ;so we are really at cluster 2 like we want to be.
\r
166 151 00C0 8B 0E 0027r MOV CX, nOSSectors ;Number of OS sectors to read
\r
167 152 00C4 EB 1B JMP SHORT ContinueBoot
\r
169 154 ;Bad boot goes here and displays a message then
\r
170 155 ;waits for a key to reboot (or tries to) via int 19h
\r
173 158 00C6 BE 01DAr MOV SI, OFFSET MsgBadDisk
\r
174 159 00C9 E8 0006 CALL PutChars
\r
176 161 00CC 33 C0 XOR AX,AX
\r
177 162 00CE CD 16 INT 16h ;Wait for keystroke
\r
178 163 00D0 CD 19 INT 19h ;Sys Reboot
\r
182 167 00D3 0A C0 OR AL,AL
\r
183 168 00D5 74 09 JZ SHORT Done
\r
184 169 00D7 B4 0E MOV AH, 0Eh
\r
185 170 00D9 BB 0007 MOV BX,0007
\r
186 171 00DC CD 10 INT 10h
\r
187 \fTurbo Assembler Version 3.1 11/25/94 10:53:02 Page 4
\r
192 172 00DE EB F2 JMP SHORT PutChars
\r
196 176 00E1 ContinueBoot:
\r
197 177 00E1 BB 6000 MOV BX, 06000h ;This is segment where we load the OS.
\r
198 178 00E4 8E C3 MOV ES, BX
\r
200 180 00E6 NextSector:
\r
201 181 00E6 50 PUSH AX
\r
202 182 00E7 51 PUSH CX
\r
203 183 00E8 52 PUSH DX
\r
204 184 00E9 06 PUSH ES
\r
206 186 00EA 33 DB XOR BX, BX
\r
208 188 ; Read a logical sector to ES:BX
\r
209 189 ; AX has Logical Sector Number
\r
211 191 00EC 8B 36 0018r MOV SI, nSectPerTrack
\r
212 192 00F0 F7 F6 DIV SI ;Divide LogicalSect by nSectPerTrack
\r
213 193 00F2 FE C2 INC DL ;Sector numbering begins at 1 (not 0)
\r
214 194 00F4 88 16 0025r MOV ResvdByte, DL ;Sector to read
\r
215 195 00F8 33 D2 XOR DX, DX ;Logical Track left in AX
\r
216 196 00FA F7 36 001Ar DIV WORD PTR nHeads ;Leaves Head in DL, Cyl in AX
\r
217 197 00FE 8A 36 0024r MOV DH, bBootDrive
\r
218 198 0102 86 D6 XCHG DL, DH ;Head to DH, Drive to DL
\r
219 199 0104 8B C8 MOV CX, AX ;Cyl into CX
\r
220 200 0106 86 CD XCHG CL, CH ;Low 8 bits of Cyl to CH, Hi 2 bits to CL
\r
221 201 0108 C0 E1 06 SHL CL, 6 ; shifted to bits 6 and 7
\r
222 202 010B 0A 0E 0025r OR CL, BYTE PTR ResvdByte ;OR with Sector number
\r
223 203 010F B0 01 MOV AL, 1 ;Number of sectors
\r
224 204 0111 B4 02 MOV AH, 2 ;Read
\r
225 205 0113 CD 13 INT 13h ;Read that sucker!
\r
226 206 0115 72 AF JC SHORT BadBoot
\r
228 208 0117 BE 01FCr MOV SI, OFFSET MsgDot
\r
229 209 011A E8 FFB5 CALL PutChars
\r
236 216 0121 8C C3 MOV BX, ES
\r
237 217 0123 83 C3 20 ADD BX, 20h ;512 bytes for segment
\r
238 218 0126 8E C3 MOV ES, BX
\r
239 219 0128 40 INC AX ;Next Sector
\r
240 220 0129 E2 BB LOOP NextSector
\r
242 222 ;At this point we have the OS loaded in a contigous section
\r
243 223 ;from 60000 linear up to about 80000 linear.
\r
244 224 ;Now we disable interrupts, turn on the A20 line, move
\r
245 225 ;it down to address 0, set protected mode and JUMP!
\r
248 228 012C 33 C9 XOR CX,CX
\r
249 \fTurbo Assembler Version 3.1 11/25/94 10:53:02 Page 5
\r
255 230 012E E4 64 IN AL,64h
\r
256 231 0130 A8 02 TEST AL,02h
\r
257 232 0132 E0 FA LOOPNZ IBEmm0
\r
258 233 0134 B0 D1 MOV AL,0D1h
\r
259 234 0136 E6 64 OUT 64h,AL
\r
260 235 0138 33 C9 XOR CX,CX
\r
262 237 013A E4 64 IN AL,64h
\r
263 238 013C A8 02 TEST AL,02h
\r
264 239 013E E0 FA LOOPNZ IBEmm1
\r
265 240 0140 B0 DF MOV AL,0DFh
\r
266 241 0142 E6 60 OUT 60h,AL
\r
267 242 0144 33 C9 XOR CX,CX
\r
269 244 0146 E4 64 IN AL,64h
\r
270 245 0148 A8 02 TEST AL,02h
\r
271 246 014A E0 FA LOOPNZ IBEmm2
\r
273 248 ;A20 line should be ON Now
\r
274 249 ;So move the OS
\r
276 251 ; Set up our new DS to where we moved the data
\r
277 252 ; We must do this before each 32K load cause we use DS */
\r
279 254 014C BA 8000 MOV DX, 8000h
\r
281 256 ; Move 64K data chunk from linear 60000h to linear 0
\r
283 258 014F BB 6000 MOV BX, 06000h
\r
284 259 0152 8E DB MOV DS, BX
\r
285 260 0154 33 F6 XOR SI, SI
\r
286 261 0156 33 C0 XOR AX, AX
\r
287 262 0158 8E C0 MOV ES,AX
\r
288 263 015A 33 FF XOR DI,DI
\r
289 264 015C 8B CA MOV CX, DX
\r
291 266 015F F3> A5 REP MOVSW ;WORD move
\r
293 268 ; Move first 64K code chunk from linear 70000h to 10000h
\r
295 270 0161 BB 7000 MOV BX, 07000h
\r
296 271 0164 8E DB MOV DS, BX
\r
297 272 0166 33 F6 XOR SI, SI
\r
298 273 0168 B8 1000 MOV AX,1000h
\r
299 274 016B 8E C0 MOV ES,AX
\r
300 275 016D 33 FF XOR DI,DI
\r
301 276 016F 8B CA MOV CX, DX
\r
302 277 0171 F3> A5 REP MOVSW ;WORD move
\r
304 279 ; Move last code (32K) from linear 80000h to 18000h
\r
306 281 0173 8E DA MOV DS, DX ;DX is 8000h anyway
\r
307 282 0175 33 F6 XOR SI, SI
\r
308 283 0177 B8 2000 MOV AX,2000h
\r
309 284 017A 8E C0 MOV ES,AX
\r
310 285 017C 33 FF XOR DI,DI
\r
311 \fTurbo Assembler Version 3.1 11/25/94 10:53:02 Page 6
\r
316 286 017E 8B CA MOV CX, DX
\r
317 287 0180 F3> A4 REP MOVSB ;BYTE move
\r
319 289 0182 BB 9000 MOV BX, 9000h
\r
320 290 0185 8E DB MOV DS, BX
\r
322 292 0187 66| 33 D2 XOR EDX, EDX
\r
323 293 018A 8A 16 0024r MOV DL, bBootDrive ;OS can find bootdrive in DL on entry
\r
325 295 018E 0F 01 1E 003Er LIDT FWORD PTR IDTptr
\r
326 296 0193 0F 01 16 0044r LGDT FWORD PTR GDTptr
\r
328 298 0198 0F 20 C0 MOV EAX,CR0
\r
329 299 019B 0C 01 OR AL,1
\r
330 300 019D 0F 22 C0 MOV CR0,EAX
\r
331 301 01A0 EB 00 JMP $+2
\r
335 305 01A4 BB 0010 MOV BX, 10h
\r
336 306 01A7 8E DB MOV DS,BX
\r
337 307 01A9 8E C3 MOV ES,BX
\r
338 308 01AB 8E E3 MOV FS,BX
\r
339 309 01AD 8E EB MOV GS,BX
\r
340 310 01AF 8E D3 MOV SS,BX
\r
342 312 ;We define a far jump with 46 bit pointer manually
\r
346 316 01B3 EA DB 0EAh
\r
347 317 01B4 00010000 DD 10000h
\r
348 318 01B8 0008 DW 8h
\r
350 320 01BA 20 20 20 20 20 20 20+ MsgNone DB ' '
\r
351 321 20 20 20 20 20 20 20+
\r
352 322 20 20 20 20 20 20 20+
\r
353 323 20 20 20 20 20 20 20+
\r
355 325 01DA 0D 0A 42 61 64 20 42+ MsgBadDisk DB 0Dh, 0Ah, 'Bad Boot Disk!', 00h
\r
356 326 6F 6F 74 20 44 69 73+
\r
358 328 01EB 0D 0A 4C 6F 61 64 69+ MsgLoad DB 0Dh, 0Ah, 'Loading MMURTL', 00h
\r
359 329 6E 67 20 4D 4D 55 52+
\r
361 331 01FC 2E 00 MsgDot DB '.', 00h
\r
363 333 01FE AA5F BootSig DW 0AA5Fh
\r
367 \fTurbo Assembler Version 3.1 11/25/94 10:53:02 Page 7
\r
373 Symbol Name Type Value
\r
375 ??DATE Text "11/25/94"
\r
376 ??FILENAME Text "Bootblok"
\r
377 ??TIME Text "10:53:02"
\r
378 ??VERSION Number 030A
\r
381 @FILENAME Text BOOTBLOK
\r
383 BADBOOT Near CSEG:00C6
\r
384 BBOOTDRIVE Byte CSEG:0024
\r
385 BMEDIA Byte CSEG:0015
\r
386 BOOTSIG Word CSEG:01FE
\r
387 BOOTUP Near CSEG:004A
\r
388 CONTINUEBOOT Near CSEG:00E1
\r
389 DONE Near CSEG:00E0
\r
390 EXTBOOTSIG Byte CSEG:0026
\r
391 FATTYPE Byte CSEG:0036
\r
392 GDTPTR Word CSEG:0044
\r
393 HERALD Byte CSEG:0003
\r
394 IBEMM0 Near CSEG:012E
\r
395 IBEMM1 Near CSEG:013A
\r
396 IBEMM2 Near CSEG:0146
\r
397 IDTPTR Word CSEG:003E
\r
398 MSGBADDISK Byte CSEG:01DA
\r
399 MSGDOT Byte CSEG:01FC
\r
400 MSGLOAD Byte CSEG:01EB
\r
401 MSGNONE Byte CSEG:01BA
\r
402 NBYTESPERSECT Word CSEG:000B
\r
403 NEXTSECTOR Near CSEG:00E6
\r
404 NFATS Byte CSEG:0010
\r
405 NHEADS Word CSEG:001A
\r
406 NHIDDEN Dword CSEG:001C
\r
407 NOSSECTORS Word CSEG:0027
\r
408 NROOTDIRENTS Word CSEG:0011
\r
409 NRSVDSECT Word CSEG:000E
\r
410 NSECTPERCLSTR Byte CSEG:000D
\r
411 NSECTPERFAT Word CSEG:0016
\r
412 NSECTPERTRACK Word CSEG:0018
\r
413 NTOTALSECT32 Dword CSEG:0020
\r
414 NTOTALSECTORS Word CSEG:0013
\r
415 PUTCHARS Near CSEG:00D2
\r
416 RESVDBYTE Byte CSEG:0025
\r
417 RESVDWORD Word CSEG:0029
\r
418 VOLNAME Byte CSEG:002B
\r
420 Groups & Segments Bit Size Align Combine Class
\r
422 CSEG 16 0200 Word none CODE
\r