↑ Back to main site.

EPOS

Experimental Protected-mode Operating System

bios.c
/*
EPOS
http://www.atanaslaskov.com/epos/

FILE:         bios.c
DESCRIPTION:  Accessing BIOS calls
 
BSD LICENSE
Copyright (c) 2006, Atanas Laskov
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
   1. Redistributions of source code must retain the above copyright notice,
   this list of conditions and the following disclaimer.
   2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL ATANAS LASKOV BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "bios.h"
#include "..\..\init\init.h"

// Call a BIOS function
//
void biosCall(BIOSREGS* p)
{
    // Restore low interrupt numbers
    // to hardware IRQs
    //
    access_cli;
    access_out(0x20, 0x11); //ICW1
    access_out(0xA0, 0x11);
    access_out(0x21, 9); //ICW2
    access_out(0xA1, 9+8);
    access_out(0x21, 4); //ICW3
    access_out(0xA1, 2);
    access_out(0x21, 1); //ICW4
    access_out(0xA1, 1);

    // Set register values for the call
    //
    access_getprmregs()->nInt = p->nInt;
    access_getprmregs()->ax = p->ax;
    access_getprmregs()->bx = p->bx;
    access_getprmregs()->cx = p->cx;
    access_getprmregs()->dx = p->dx;
    access_getprmregs()->si = p->si;
    access_getprmregs()->di = p->di;
    access_getprmregs()->bp = p->bp;
    access_getprmregs()->ds = p->ds;
    access_getprmregs()->es = p->es;

    // Perform BIOS call
    access_bios();

    // Restore registers
    //
    p->ax = access_getprmregs()->ax;
    p->bx = access_getprmregs()->bx;
    p->cx = access_getprmregs()->cx;
    p->dx = access_getprmregs()->dx;
    p->si = access_getprmregs()->si;
    p->di = access_getprmregs()->di;
    p->bp = access_getprmregs()->bp;
    p->ds = access_getprmregs()->ds;
    p->es = access_getprmregs()->es;

    // Back to higher interrupt numbers
    //
    access_out(0x20, 0x11); //ICW1
    access_out(0xA0, 0x11);
    access_out(0x21, KRNL_FIRST_IRQ);   //ICW2
    access_out(0xA1, KRNL_FIRST_IRQ+8);
    access_out(0x21, 4);    //ICW3
    access_out(0xA1, 2);
    access_out(0x21, 1);    //ICW4
    access_out(0xA1, 1);
    access_sti;
}