By setting up a program to load and execute from the boot sector of a diskette, you can run an application directly from a floppy drive without any Operating System. You have to design and code the application to take care of every hardware interface otherwise provided by an operative system. In other words, when you raw boot, you're on your own. You can't use OS-related software interrupt services, only what is provided by BIOS.
Let us start with an experiment to see if we can write a simple "Hello World" statement to the monitor when the PC boots up. First of all we'll need a program that can write our planned application onto the boot sector i.e. onto head 0, track 0, sector 1. The following Turbo Pascal Code (BOOTMKR.PAS) will do just that for you:
program BootMkr;
(*****************************************************************
This program loads the specified binary file onto the boot sector
of the diskette placed in drive 'A'.
*****************************************************************)
USES
crt,
dos;
CONST
DiskInt = $13; { Diskette Interrupt }
DiskReset = 0; { Reset the Drive Subsystem }
DiskStatus = 1; { Get Status of Previous Operation }
DiskRead = 2; { Read the Sectors in Memory }
DiskWrite = 3; { Write to the Disk Sector }
VAR
Regs : registers;
ByteBuffer : array [0..511] of byte; { 512-byte Data Buffer }
Curr_byte : byte;
i : integer;
SourceFile : file of byte; { File to Load into the Diskette }
BEGIN
writeln;
writeln('BOOTMKR 1.0B, (c) Jens Laland 2001');
{ Check Command Line Parameter }
if ParamCount <> 1 then begin
writeln;
writeln(' USAGE: BOOTMKR filename.ext');
writeln;
writeln(' This program loads the specified binary file');
writeln(' onto the boot sector of diskette in drive A.');
halt; end
else begin
Assign(SourceFile, ParamStr(1));
{$I-}
Reset(SourceFile);
{$I+}
{ If file does not exist, or file not found... }
if IOresult <> 0 then begin
writeln(ParamStr(1), ' not found...');
Halt;
end;
{ Ensure that the file is within 512 bytes }
if FileSize(SourceFile) > 512 then begin
writeln('File too large to process [',FileSize(SourceFile),' bytes]');
writeln('File cannot be larger than one 512-byte sector...');
Halt; end
else begin { Put the file on the Diskette }
writeln('Processing ',ParamStr(1),' ',FileSize(SourceFile),' bytes...');
for i := 1 to FileSize(SourceFile) do begin
seek(SourceFile,i - 1);
read(SourceFile,Curr_byte);
ByteBuffer[i - 1] := Curr_byte;
end;
{ Fill rest of 512-byte sector with NOP }
for i := FileSize(SourceFile) to 512 do ByteBuffer[i - 1] := $90;
{ Reset Disk Drive A }
Regs.AH := DiskReset;
Regs.DL := 0;
intr(DiskInt,Regs);
if NOT(Regs.AH = 0) then begin
writeln('Error writing to Drive A...');
Halt; end
else begin { Write File onto Boot Sector }
Regs.AH := DiskWrite; { Write the First Sector }
Regs.DL := 0; { of Disk A }
Regs.DH := 0; { Head 0 }
Regs.CH := 0; { Track 0 }
Regs.CL := 1; { Sector 1 }
Regs.AL := 1; { ONLY 1 Sector }
Regs.BX := Ofs(ByteBuffer[0]); { Buffer Offset }
Regs.ES := Seg(ByteBuffer[0]); { Buffer Segment }
Intr(DiskInt,Regs);
if NOT(Regs.AH = 0) then
writeln('Error writing to Drive A...');
end;
end;
end;
END.
Or you can download the compiled version of the program here: BOOTMKR.EXE [7 kB].
Ok... The following assembler code (BOOT_H.ASM) should at least manage to get the 'H' in 'Hello World' written to the PC monitor:
XPERIMENT SEGMENT ; Using One Segment for Everything
ASSUME CS:XPERIMENT, DS:XPERIMENT, ES:XPERIMENT, SS:XPERIMENT
VIDINT EQU 010h ; BIOS Video Interrupt
VIDWRITE EQU 009h ; Write Attribute/Byte at Cursor Position
org 0
START:
mov AH, VIDWRITE ; Write...
mov AL, 'H'
mov BH, 0 ; onto Video Page 0
mov BL, 7 ; using Grey on Black
mov CX, 1 ; ... 1 Character
int VIDINT
OneMore: ; Endless Loop
jmp SHORT OneMore
XPERIMENT ENDS
END START
Now! Insert a newly formatted diskette in floppy drive A: - then give the binary file (BOOT_H.BIN) as a command line parameter to the BootMaker tool...
C:\MYWORK>BOOTMKR BOOT_H.BIN