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