Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * MTGos - LowLevel OS
- * Copyright (C) 2013 Morten Delenk
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * Please Read "LICENSE" for the Complete License
- **/
- static inline dword farpeekl(word sel, void * off)
- {
- dword ret;
- asm("push %%fs\n\t"
- "mov %1, %%fs\n\t"
- "mov %%fs:(%2), %0\n\t"
- "pop %%fs"
- : "=r"(ret) : "g"(sel), "r"(off));
- return ret;
- }
- static inline byte farpeekb(word sel, void * off)
- {
- byte ret;
- asm("push %%fs\n\t"
- "mov %1, %%fs\n\t"
- "movb %%fs:(%2), %0\n\t"
- "pop %%fs"
- : "=r"(ret) : "g"(sel), "r"(off));
- return ret;
- }
- static inline void farpokeb( word sel, void *off, byte v)
- {
- asm("push %%fs\n\t"
- "mov %0, %%fs\n\t"
- "movb %2, %%fs:(%1)\n\t"
- "pop %%fs"
- : : "g"(sel), "r"(off), "r"(v));
- }
- static inline void farpokel( word sel, void *off, dword v)
- {
- asm("push %%fs\n\t"
- "mov %0, %%fs\n\t"
- "mov %2, %%fs:(%1)\n\t"
- "pop %%fs"
- : : "g"(sel), "r"(off), "r"(v));
- }
- static inline void outb(unsigned short port, unsigned char val)
- {
- asm volatile("outb %0, %1" : : "a"(val), "Nd"(port) );
- }
- static inline void outw(unsigned short port, unsigned short val)
- {
- asm volatile("outw %0, %1" : : "a"(val), "Nd"(port) );
- }
- static inline void outl(unsigned short port, unsigned int val)
- {
- asm volatile("outl %0, %1" : : "a"(val), "Nd"(port) );
- }
- static inline unsigned char inb(unsigned short port)
- {
- unsigned char ret;
- asm volatile("inb %1, %0" : "=a"(ret) : "Nd"(port) );
- return ret;
- }
- static inline unsigned short inw(unsigned short port)
- {
- unsigned short ret;
- asm volatile("inw %1, %0" : "=a"(ret) : "Nd"(port) );
- return ret;
- }
- static inline unsigned int inl(unsigned short port)
- {
- unsigned int ret;
- asm volatile("inl %1, %0" : "=a"(ret) : "Nd"(port) );
- return ret;
- }
- static inline void io_wait(void)
- {
- asm volatile("jmp 1f\n\t"
- "1:jmp 2f\n\t"
- "2:");
- }
- static void clearflags(void)
- {
- asm("xor eax,eax\n\t"
- "push eax\n\t"
- "popf\n\t");
- }
Advertisement
Add Comment
Please, Sign In to add comment