;************************************************************************* ; BOOT - program to boot TUOX operating system ; - store loader from disk into memory to address FIRST_MODUL ; ; Modified by Radim Drobek & Rene Kohut after Old BOOTSTRAP group ; from VSB TU Ostrava,members of BOOTSTRAP group ; ; 14.1.1998 ;************************************************************************* Ideal model TINY P286 DataSeg STACK_TOP = 7C00H SHIFT = 7C00H - 103H ; PSP = 100H bytes, JMP BOOT_BEGIN = 3 bytes FIRST_MODUL = 0700H ; Address that first modul is to load DRIVE = 0H ; drive where you make boot disk 0=first (A) org 100h CodeSeg STARTUPCODE JMP BOOT_BEGIN ; TUOX boot record,some is the same as MS-DOS boot record (version 4.0 or higher) Boot_Start: JMP SHORT @@Start ; Jump over data NOP ; Near jump expected, short one used ; so we need one extra byte here VersionID db 'TUOX1.1',0 ; Company and version BytesPerSec dw ? ; 512B per sector db ? ; Unused StartImageSecs dw ? ; Start sector of 1st free space LoaderSize db 0 ; Size of LOADER in sectors SizeImageSec dw ? ; Image size in sectors TotalSectors dw ? ; Total sector number on the disk FormatID db ? ; F0 = HD 1,44M (same as 1st byte in FAT) LoaderDataSec dw ? ; First sector of LOADER SectorsPerCyl dw ? ; Sectors per track (cylinder) Sides dw ? ; Diskette -> 2 sides dw ? ; Unused dw ? ; Unused dd ? ; Unused DriveNo db 0 ; 0 = floppy db ? ; Unused db ? ; Unused VolumeSerialNo db 1,0,1,0 ; Volume serial number 0001-0001 VolumeLabel db 'TUOXsysdisk' ; Volume label (max. 11 chars) db 8 dup (?) ; 8 bytes ; Boot record end (total 62 bytes) ; Here come the variables that TUOX needs RAMDiskSize dw 8192 ; Size of memory block reserved for RAM disk ; in paragraphs (131072 bytes - enough?) ; This variables are used in boot code, not neccessary outside @@Start: CLI XOR AX, AX MOV SS, AX MOV SP, STACK_TOP ; Stack initiation MOV DS, AX MOV ES, AX STI ; Look if LOADER in disk MOV AL, [LoaderSize + SHIFT] OR AL,AL JZ @@Boot_Failure XOR AX,AX MOV DL, [BYTE DriveNo + SHIFT] INT 13H ; Device reset (AH = 0) JC @@Boot_Failure ; Reset error MOV SI, OFFSET StartMsg1 + SHIFT CALL WriteString ; Print message MOV SI, OFFSET VersionID + SHIFT CALL WriteString ; Print message MOV SI, OFFSET StartMsg2 + SHIFT CALL WriteString ; Print message MOV CX,3 MOV BX, FIRST_MODUL shr 4 MOV ES, BX XOR BX, BX ; First modul begins at 0070:0000 ; Now we'll read the loader from reserved sector @@Read_Continue: MOV AX, [LoaderDataSec + SHIFT] CALL CalcSector @@three: PUSH CX MOV AX, 0201h ; BIOS service - 1 sector read INT 13H POP CX JNC @@Continue LOOP @@three JMP SHORT @@Boot_Failure @@Continue: INC [LoaderDataSec + SHIFT] ; Next sector to read ADD BX, [BytesPerSec + SHIFT] ; BX = new address to read to DEC [LoaderSize + SHIFT] JNZ @@Read_Continue MOV SI, OFFSET OKMsg + SHIFT CALL WriteString ; Print message JMP FAR (FIRST_MODUL-100h) shr 4 : 0100h ; 100h = loader PSP ; Boot failed (read error, loader not found), message & try again @@Boot_Failure: MOV SI, OFFSET BootFailMsg + SHIFT CALL WriteString ; Print error message XOR AH, AH ; BIOS keyboard service INT 16H ; Wait for key stroke INT 19H ; Try to load boot sector again proc WriteString near ; Print an ASCIIZ string at DS:SI @@Write_Begin: LODSB ; Next character OR AL, AL JZ @@Write_End ; NUL = end of ASCIIZ string MOV AH, 0EH ; BIOS service - write character MOV BL, 0FFH ; Char's attribute INT 10H JMP SHORT @@Write_Begin @@Write_End: RET endp WriteString proc CalcSector near ; Calculates side, cylinder & abs. sector number from relative sector number ; Input: AX = relative sector ; Relative sector = Cyl# * SPC * HD + Head# * SPC + Sec# - 1 (zero base) ; Results: pripare register to int 13/[02 or 03] (without AX) ; Modified registers: AX, DX, CX XOR DX, DX DIV [WORD SectorsPerCyl+SHIFT] INC DL PUSH DX XOR DX, DX DIV [WORD Sides+SHIFT] MOV CH, AL MOV CL, AH ROR CL, 2 ; CYLINDER MOV DH, DL ; HEAD POP AX OR CL, AL ; AND SECTOR MOV DL, [DriveNo+SHIFT] ; DRIVE NUMBER RET endp CalcSector BootFailMsg db 'Non-System disk or disk error', 10, 13 KeyPressMsg db 'Insert TUOX diskette and press any key...', 10, 13, 0 StartMsg1 db 'Starting ',0 StartMsg2 db ' Operating System ... ', 0 OKMsg db 'OK', 10, 13, 0 @@BootCode_End: BOOT_BEGIN: ; Read orig. BOOT first before Write Boot sector to disk MOV BX, OFFSET BootBuffer MOV DL, DRIVE MOV DH, 0 MOV CX, 3 @@TryRead: PUSH CX MOV CX, 0001H MOV AX, 0201H ;read boot of 1. disk ("0") INT 13H ;to buffer POP CX JNC @@OKRead LOOP @@TryRead MOV SI, OFFSET DiskReadErr JMP @@Do_Write @@OKRead: MOV SI, OFFSET Boot_Start MOV DI, OFFSET BootBuffer MOV CX, 11 REP MOVSB ; write my boot to buffer, but ADD SI, 27 ; skip diskete parametrs 12-38 byte ADD DI, 27 MOV CX, 472/2 REP MOVSW MOV AX, 0AA55H ; End of boot sector signature STOSW MOV CX, 3 @@TryWrite: PUSH CX MOV DL, DRIVE MOV DH, 0 MOV CX, 0001H MOV AX, 0301H MOV BX, OFFSET BootBuffer INT 13H ; Write buffer to boot sector POP CX JNC @@Write_OK LOOP @@TryWrite MOV SI, OFFSET WriteErrorMsg JMP SHORT @@Do_Write @@Write_OK: MOV SI, OFFSET WriteOKMsg @@Do_Write: CALL WriteString EXITCODE WriteErrorMsg db 'Boot Writing Error.', 10, 13, 0 DiskReadErr db 'Boot Reading Error.', 10, 13, 0 WriteOKMsg db 'Boot Was Successfully Written.', 10, 13 db 'Load System Files Now.', 10, 13, 0 BootBuffer db 512 dup (?) ends end