/*
    TMClockAsm.S, Copyright  (c) by Lukas Ruf, lr@lpr.ch,
    Swiss Federal Institute of Technology,
    Computer Engineering and Networks Laboratory.

    TOPSY -- A Teachable Operating System.
             Implementation of a tiny and simple
             micro kernel for teaching purposes.

    For further information, please visit http://www.tik.ee.ethz.ch/~topsy

    This software is provided under the terms of the GNU General Public Licence.

    A full copy of the GNU GPL is provided in the file COPYING found in the 
    development root of Topsy.
*/
/*
	
	File:                  $Source: /home/ruf/cvs_Topsy/cvs/Topsy/Threads/ia32/TMClockAsm.S,v $
 	Author(s):             Lukas Ruf, lr@lpr.ch
 	Affiliation:           ETH Zuerich, TIK
 	Version:               $Revision: 3018 $
 	Creation Date:         
 	Last Date of Change:   $Date: 2007-05-02 23:13:29 +0200 (Mit, 02 Mai 2007) $      by: $Author: sryffel $
	
	
	$Log: TMClockAsm.S,v $
	Revision 1.4  2001/02/08 08:29:48  lukas
	FRAME to ASM_PROC_FRAME renamed due to definition conflicts with ETHERNET FRAME defintion
	
	Revision 1.3  2000/11/15 10:13:34  ruf
	ia32Debug and Repository Reorganisation
	
	Revision 1.2  1999/12/13 21:48:34  ruf
	GNU General Public Licence Update
	
	Revision 1.1  1999/05/13 17:05:48  jeker
	Initial revision
	
*/
#include "asm.h"                /* Macros */

#define __SASM__
#include "TMHalAsm.h"
#undef  __SASM__


.section .sasm
.align 4,0x9090

////
// uchar _readRTC(uchar pBYTEtoREAD);
ASM_PROC_FRAME(__readRTC)
        ENTER
        pushfl  
        cli
        xorl    %eax,%eax
        movl    8(%ebp),%eax
        outb    %al,$0x70
        call    __settle
        inb     $0x71,%al
        popfl
        LEAVE

////
// void _writeRTC(uchar pBYTEtoWRITE, uchar pVALUEtoWRITE);
ASM_PROC_FRAME(__writeRTC)
        ENTER
        pushfl
        cli
        pushl   %eax
        movl    8(%ebp),%eax
        outb    %al,$0x70
        call    __settle
        movl    12(%ebp),%eax
        outb    %al,$0x71
        popl    %eax
        popfl   
        LEAVE
        
////
// ulong _tryForPS2();
// Return state of F,E,D,C Ctrl Bytes
ASM_PROC_FRAME(__tryForPS2)
        pushl   %ebx
        xorl    %ebx,%ebx
        
        pushl   $0x0F
        call    __readRTC
        addl    $4,%esp
        movb    %al,%bh
        
        pushl   $0x0E
        call    __readRTC
        addl    $4,%esp
        movb    %al,%bl
        
        shll    $16,%ebx
        
        pushl   $0x0D
        call    __readRTC
        addl    $4,%esp
        movb    %al,%bh
        
        pushl   $0x0C
        call    __readRTC
        addl    $4,%esp
        movb    %al,%bl

        movl    %ebx,%eax
        popl    %ebx
        ret
__settle:
        jmp     _settlen1
_settlen1:
        ret
        

