Home | History | Annotate | Download | only in core
      1 /* ----------------------------------------------------------------------- *
      2  *
      3  *   Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin
      4  *
      5  *   This program is free software; you can redistribute it and/or modify
      6  *   it under the terms of the GNU General Public License as published by
      7  *   the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
      8  *   Boston MA 02110-1301, USA; either version 2 of the License, or
      9  *   (at your option) any later version; incorporated herein by reference.
     10  *
     11  * ----------------------------------------------------------------------- */
     12 
     13 /*
     14  * call16.c
     15  *
     16  * Simple wrapper to call 16-bit core functions from 32-bit code
     17  */
     18 
     19 #include <stddef.h>
     20 #include <stdio.h>
     21 #include "core.h"
     22 
     23 __export const com32sys_t zero_regs;	/* Common all-zero register set */
     24 
     25 static inline uint32_t eflags(void)
     26 {
     27     //uint32_t v;
     28 
     29 #if __SIZEOF_POINTER__ == 4
     30     uint32_t v;
     31     asm volatile("pushfl ; popl %0" : "=rm" (v));
     32 #elif __SIZEOF_POINTER__ == 8
     33     uint64_t v;
     34     asm volatile("pushfq ; pop %0" : "=rm" (v));
     35 #else
     36 #error "Unable to build for to-be-defined architecture type"
     37 #endif
     38     return v;
     39 }
     40 
     41 __export void call16(void (*func)(void), const com32sys_t *ireg,
     42 		     com32sys_t *oreg)
     43 {
     44     com32sys_t xreg = *ireg;
     45 
     46     /* Enable interrupts if and only if they are enabled in the caller */
     47     xreg.eflags.l = (xreg.eflags.l & ~EFLAGS_IF) | (eflags() & EFLAGS_IF);
     48 
     49     core_farcall((size_t)func, &xreg, oreg);
     50 }
     51