-// GDT bit manipulation
-#define GDT_BASE(v) ((((u64)(v) & 0xff000000) << 32) \
- | (((u64)(v) & 0x00ffffff) << 16))
-#define GDT_LIMIT(v) ((((u64)(v) & 0x000f0000) << 32) \
- | (((u64)(v) & 0x0000ffff) << 0))
-#define GDT_CODE (0x9bULL << 40) // Code segment - P,R,A bits also set
-#define GDT_DATA (0x93ULL << 40) // Data segment - W,A bits also set
-#define GDT_B (0x1ULL << 54) // Big flag
-#define GDT_G (0x1ULL << 55) // Granularity flag
+static inline u16 __htons_constant(u16 val) {
+ return (val<<8) | (val>>8);
+}
+static inline u32 __htonl_constant(u32 val) {
+ return (val<<24) | ((val&0xff00)<<8) | ((val&0xff0000)>>8) | (val>>24);
+}
+static inline u32 __htonl(u32 val) {
+ asm("bswapl %0" : "+r"(val));
+ return val;
+}
+#define htonl(x) (__builtin_constant_p((u32)(x)) ? __htonl_constant(x) : __htonl(x))
+#define ntohl(x) htonl(x)
+#define htons(x) __htons_constant(x)
+#define ntohs(x) htons(x)
+
+static inline u16 cpu_to_le16(u16 x)
+{
+ return x;
+}
+
+static inline u32 cpu_to_le32(u32 x)
+{
+ return x;
+}
+
+static inline u32 le32_to_cpu(u32 x)
+{
+ return x;
+}
+
+static inline u32 getesp(void) {
+ u32 esp;
+ asm("movl %%esp, %0" : "=rm"(esp));
+ return esp;
+}
+
+static inline void writel(void *addr, u32 val) {
+ *(volatile u32 *)addr = val;
+}
+static inline void writew(void *addr, u16 val) {
+ *(volatile u16 *)addr = val;
+}
+static inline void writeb(void *addr, u8 val) {
+ *(volatile u8 *)addr = val;
+}
+static inline u32 readl(const void *addr) {
+ return *(volatile const u32 *)addr;
+}
+static inline u16 readw(const void *addr) {
+ return *(volatile const u16 *)addr;
+}
+static inline u8 readb(const void *addr) {
+ return *(volatile const u8 *)addr;
+}