Guest User

Untitled

a guest
Apr 29th, 2013
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.56 KB | None | 0 0
  1. /**
  2.  *   MTGos - LowLevel OS
  3.  *   Copyright (C) 2013 Morten Delenk
  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, either version 3 of the License, or
  8.  *   (at your option) any later version.
  9.  *
  10.  *   This program is distributed in the hope that it will be useful,
  11.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *   GNU General Public License for more details.
  14.  *
  15.  *   You should have received a copy of the GNU General Public License
  16.  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17.  *   Please Read "LICENSE" for the Complete License
  18. **/
  19. static inline dword farpeekl(word sel, void * off)
  20. {
  21.     dword ret;
  22.     asm("push %%fs\n\t"
  23.         "mov %1, %%fs\n\t"
  24.         "mov %%fs:(%2), %0\n\t"
  25.         "pop %%fs"
  26.         : "=r"(ret) : "g"(sel), "r"(off));
  27.     return ret;
  28. }
  29. static inline byte farpeekb(word sel, void * off)
  30. {
  31.     byte ret;
  32.     asm("push %%fs\n\t"
  33.         "mov %1, %%fs\n\t"
  34.         "movb %%fs:(%2), %0\n\t"
  35.         "pop %%fs"
  36.         : "=r"(ret) : "g"(sel), "r"(off));
  37.     return ret;
  38. }
  39. static inline void farpokeb( word sel, void *off, byte v)
  40. {
  41.     asm("push %%fs\n\t"
  42.         "mov %0, %%fs\n\t"
  43.         "movb %2, %%fs:(%1)\n\t"
  44.         "pop %%fs"
  45.         : : "g"(sel), "r"(off), "r"(v));
  46. }
  47. static inline void farpokel( word sel, void *off, dword v)
  48. {
  49.     asm("push %%fs\n\t"
  50.         "mov %0, %%fs\n\t"
  51.         "mov %2, %%fs:(%1)\n\t"
  52.         "pop %%fs"
  53.         : : "g"(sel), "r"(off), "r"(v));
  54. }
  55. static inline void outb(unsigned short port, unsigned char val)
  56. {
  57.     asm volatile("outb %0, %1" : : "a"(val), "Nd"(port) );
  58. }
  59. static inline void outw(unsigned short port, unsigned short val)
  60. {
  61.     asm volatile("outw %0, %1" : : "a"(val), "Nd"(port) );
  62. }
  63. static inline void outl(unsigned short port, unsigned int val)
  64. {
  65.     asm volatile("outl %0, %1" : : "a"(val), "Nd"(port) );
  66. }
  67. static inline unsigned char inb(unsigned short port)
  68. {
  69.     unsigned char ret;
  70.     asm volatile("inb %1, %0" : "=a"(ret) : "Nd"(port) );
  71.     return ret;
  72. }
  73. static inline unsigned short inw(unsigned short port)
  74. {
  75.     unsigned short ret;
  76.     asm volatile("inw %1, %0" : "=a"(ret) : "Nd"(port) );
  77.     return ret;
  78. }
  79. static inline unsigned int inl(unsigned short port)
  80. {
  81.     unsigned int ret;
  82.     asm volatile("inl %1, %0" : "=a"(ret) : "Nd"(port) );
  83.     return ret;
  84. }
  85. static inline void io_wait(void)
  86. {
  87.     asm volatile("jmp 1f\n\t"
  88.             "1:jmp 2f\n\t"
  89.             "2:");
  90. }
  91. static void clearflags(void)
  92. {
  93.     asm("xor eax,eax\n\t"
  94.         "push eax\n\t"
  95.         "popf\n\t");
  96. }
Advertisement
Add Comment
Please, Sign In to add comment