Xv6 with picoc & Linkage editor  v1.0
The project delineate mutual cohesion between c library, linkage editor ( linker), interpreter and operating system by porting the same on xv6 kernel
x86.h
00001 // Routines to let C code use special x86 instructions.
00002 
00003 static inline uchar
00004 inb(ushort port)
00005 {
00006   uchar data;
00007 
00008   asm volatile("in %1,%0" : "=a" (data) : "d" (port));
00009   return data;
00010 }
00011 
00012 static inline void
00013 insl(int port, void *addr, int cnt)
00014 {
00015   asm volatile("cld; rep insl" :
00016                "=D" (addr), "=c" (cnt) :
00017                "d" (port), "0" (addr), "1" (cnt) :
00018                "memory", "cc");
00019 }
00020 
00021 static inline void
00022 outb(ushort port, uchar data)
00023 {
00024   asm volatile("out %0,%1" : : "a" (data), "d" (port));
00025 }
00026 
00027 static inline void
00028 outw(ushort port, ushort data)
00029 {
00030   asm volatile("out %0,%1" : : "a" (data), "d" (port));
00031 }
00032 
00033 static inline void
00034 outsl(int port, const void *addr, int cnt)
00035 {
00036   asm volatile("cld; rep outsl" :
00037                "=S" (addr), "=c" (cnt) :
00038                "d" (port), "0" (addr), "1" (cnt) :
00039                "cc");
00040 }
00041 
00042 static inline void
00043 stosb(void *addr, int data, int cnt)
00044 {
00045   asm volatile("cld; rep stosb" :
00046                "=D" (addr), "=c" (cnt) :
00047                "0" (addr), "1" (cnt), "a" (data) :
00048                "memory", "cc");
00049 }
00050 
00051 static inline void
00052 stosl(void *addr, int data, int cnt)
00053 {
00054   asm volatile("cld; rep stosl" :
00055                "=D" (addr), "=c" (cnt) :
00056                "0" (addr), "1" (cnt), "a" (data) :
00057                "memory", "cc");
00058 }
00059 
00060 struct segdesc;
00061 
00062 static inline void
00063 lgdt(struct segdesc *p, int size)
00064 {
00065   volatile ushort pd[3];
00066 
00067   pd[0] = size-1;
00068   pd[1] = (uint)p;
00069   pd[2] = (uint)p >> 16;
00070 
00071   asm volatile("lgdt (%0)" : : "r" (pd));
00072 }
00073 
00074 struct gatedesc;
00075 
00076 static inline void
00077 lidt(struct gatedesc *p, int size)
00078 {
00079   volatile ushort pd[3];
00080 
00081   pd[0] = size-1;
00082   pd[1] = (uint)p;
00083   pd[2] = (uint)p >> 16;
00084 
00085   asm volatile("lidt (%0)" : : "r" (pd));
00086 }
00087 
00088 static inline void
00089 ltr(ushort sel)
00090 {
00091   asm volatile("ltr %0" : : "r" (sel));
00092 }
00093 
00094 static inline uint
00095 readeflags(void)
00096 {
00097   uint eflags;
00098   asm volatile("pushfl; popl %0" : "=r" (eflags));
00099   return eflags;
00100 }
00101 
00102 static inline void
00103 loadgs(ushort v)
00104 {
00105   asm volatile("movw %0, %%gs" : : "r" (v));
00106 }
00107 
00108 static inline void
00109 cli(void)
00110 {
00111   asm volatile("cli");
00112 }
00113 
00114 static inline void
00115 sti(void)
00116 {
00117   asm volatile("sti");
00118 }
00119 
00120 static inline uint
00121 xchg(volatile uint *addr, uint newval)
00122 {
00123   uint result;
00124   
00125   // The + in "+m" denotes a read-modify-write operand.
00126   asm volatile("lock; xchgl %0, %1" :
00127                "+m" (*addr), "=a" (result) :
00128                "1" (newval) :
00129                "cc");
00130   return result;
00131 }
00132 
00133 static inline uint
00134 rcr2(void)
00135 {
00136   uint val;
00137   asm volatile("movl %%cr2,%0" : "=r" (val));
00138   return val;
00139 }
00140 
00141 static inline void
00142 lcr3(uint val) 
00143 {
00144   asm volatile("movl %0,%%cr3" : : "r" (val));
00145 }
00146 
00147 //PAGEBREAK: 36
00148 // Layout of the trap frame built on the stack by the
00149 // hardware and by trapasm.S, and passed to trap().
00150 struct trapframe {
00151   // registers as pushed by pusha
00152   uint edi;
00153   uint esi;
00154   uint ebp;
00155   uint oesp;      // useless & ignored
00156   uint ebx;
00157   uint edx;
00158   uint ecx;
00159   uint eax;
00160 
00161   // rest of trap frame
00162   ushort gs;
00163   ushort padding1;
00164   ushort fs;
00165   ushort padding2;
00166   ushort es;
00167   ushort padding3;
00168   ushort ds;
00169   ushort padding4;
00170   uint trapno;
00171 
00172   // below here defined by x86 hardware
00173   uint err;
00174   uint eip;
00175   ushort cs;
00176   ushort padding5;
00177   uint eflags;
00178 
00179   // below here only when crossing rings, such as from user to kernel
00180   uint esp;
00181   ushort ss;
00182   ushort padding6;
00183 };
 All Data Structures