Author Topic: Quick and ditry x86 boot loader  (Read 13791 times)

Offline TightCoderEx

  • Full Member
  • **
  • Posts: 103
Quick and ditry x86 boot loader
« on: February 12, 2013, 12:45:56 PM »
This code is quick and dirty, with the only purpose of perserving in a known place all registers at statup and loading second phase (next 32 sectors) into lower memory.

From what I understand, not all BIOS's begin with CS = 0000 & IP = 7C00. For my segmentation model, I want 7C0:0006
 
Code: [Select]

  -  00  EA0600C007        jmp word 7c0:06
 
  -  06  FA                cli
 

On the machines I have to work with, I've discovered inital SP is at either 7C00 or 400. When lower, the pointer is actually at 3EC so after this it would be 3D4. In that case, hopefully this doesn't trash BIOS IVT.

Code: [Select]

  -  07  60                pushaw
  -  08  16                push ss
  -  09  06                push es
  -  0A  1E                push ds
  -  0B  0E                push cs
 

Code: [Select]
 
  Stack is about to be trashed so, SS:SP need to be kept in a safe place temporarily
 
  -  0C  8CD3              mov bx,ss
  -  0E  89E6              mov si,sp
 
  If for no other reason that I can, I've choosen to place bottom of stack at what
  BIOS believes to be top of memory.
 
  -  10  B84000            mov ax,40
  -  13  8ED8              mov ds,ax
  -  15  A11300            mov ax,[13] Usually somewhere between 280H & 27FH
  -  18  C1E002            shl ax,2
  -  1B  BC2000            mov sp,20
  -  1E  29E0              sub ax,sp
  -  20  8ED0              mov ss,ax
  -  22  C1E404            shl sp,4 Room for 256 words.  Should be enough
 
  Subsequent code will alter stack until these pieces of data have been displayed.
 
  -  25  53                push bx
  -  26  56                push si
  -  27  52                push dx
 
  Finish by setting Data & Extra segments appropriately.
 
  -  28  8CC8              mov ax,cs
  -  2A  8ED8              mov ds,ax
  -  2C  8EC0              mov es,ax
 
  -  2E  FB                sti
 

The lions share of work is done from this point, but as not to be restricted by space (512 bytes), The next 32 sectors second phase is loaded @ 80:0
 
Code: [Select]

  -  2F  06                push es
  -  30  B88000            mov ax,80
  -  33  8EC0              mov es,ax
  -  35  31DB              xor bx,bx
  -  37  B90200            mov cx,2
  -  3A  B82002            mov ax,220
  -  3D  CD13              int 13
  -  3F  07                pop es
  -  40  723E              jc 80


Complete source attached.