#include "platform.h" #include "diskstru.h" extern St_DOS_BootRecord g_stBootRecord; static BYTE s_bHead; static BYTE s_bTrack; static BYTE s_bSector; static void Lba2CHS(UINT Lba) { _asm mov ax, Lba _asm xor dx, dx _asm mov bx, g_stBootRecord.BPB.SectorsPerTrack _asm div bx _asm inc dx _asm mov s_bSector, dl _asm xor dx, dx _asm mov bx, g_stBootRecord.BPB.Sides _asm div bx _asm mov s_bHead, dl _asm mov s_bTrack, al } static int pascal ReadSector( void far * lpBuff ) { _asm{ mov ax, word ptr [lpBuff+2] mov es, ax mov bx, word ptr [lpBuff] mov ah, 02h mov al, 1 mov ch, s_bTrack mov cl, s_bSector mov dh, s_bHead mov dl, 0 int 13h jc l_error jmp short l_ret } l_error: return 0; l_ret: return 1; } static const char s_szStarting[] = "Starting Myself Operating system..."; static const char s_szFail[] = "Fail to load OsLoader, system halt."; static void TextOut(BYTE x, BYTE y, const char * szText, int n) { _asm { mov cx, n mov dh, y mov dl, x mov bx, 15 mov ax, szText push bp mov bp, ax mov ax, 1300h int 10h pop bp } } void start(void) { UINT uLba, i; BYTE far * lpSect = (BYTE far *)0x80000000; // Clear screen _asm{ mov ax, 3 int 10h } // Display the logo information TextOut( 0, 0, s_szStarting, sizeof(s_szStarting)-1 ); // Calculate the sector number of the first data sector uLba = g_stBootRecord.BPB.ReservedSectors + g_stBootRecord.BPB.FAT_Copies * g_stBootRecord.BPB.SectorsPerFAT + (g_stBootRecord.BPB.RootDirEntries >> 4); uLba = 6; // Load the first 128 data sectors into memory at address 8000h:0000h for( i = 0; i < 10; i ++ ) { Lba2CHS( uLba ); if( !ReadSector( lpSect ) ) { goto l_Fail; } uLba ++; lpSect += 512; } // Execute the fetched OS loader at address 8000h:0100h _asm { mov ax, 0x8000 mov ds, ax mov es, ax mov ss, ax mov sp, 0xFFF0 push ax //push cs mov ax, 0x100 push ax //push ip(0) retf // execute OS } l_Fail: TextOut( 0, 1, s_szFail, sizeof(s_szFail)-1 ); for(;;); }