:: commit 1bb1bd220199865af345e083fc747375b883addc

mintsuki <mintsuki@protonmail.com> — 2020-09-16 15:22

parents: e7838e854f

Revert to -masm=intel for inline assembly

diff --git a/decompressor/Makefile b/decompressor/Makefile
index aac8135a..734a309b 100644
--- a/decompressor/Makefile
+++ b/decompressor/Makefile
@@ -10,6 +10,7 @@ INTERNAL_CFLAGS =  \
 	-fno-stack-protector \
 	-fno-pic \
 	-fomit-frame-pointer \
+	-masm=intel \
 	-mno-80387 \
 	-mno-mmx \
 	-mno-3dnow \
diff --git a/decompressor/lib/asm.h b/decompressor/lib/asm.h
deleted file mode 100644
index 560057c0..00000000
--- a/decompressor/lib/asm.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef __LIB__ASM_H__
-#define __LIB__ASM_H__
-
-#define ASM(body, ...) asm volatile (".intel_syntax noprefix\n\t" body ".att_syntax prefix" : __VA_ARGS__)
-#define ASM_BASIC(body) asm (".intel_syntax noprefix\n\t" body ".att_syntax prefix")
-
-#define FARJMP16(seg, off) \
-    ".byte 0xea\n\t" \
-    ".2byte " off "\n\t" \
-    ".2byte " seg "\n\t" \
-
-#define FARJMP32(seg, off) \
-    ".byte 0xea\n\t" \
-    ".4byte " off "\n\t" \
-    ".2byte " seg "\n\t" \
-
-#endif
diff --git a/decompressor/main.c b/decompressor/main.c
index c097769a..b1c9ffa2 100644
--- a/decompressor/main.c
+++ b/decompressor/main.c
@@ -1,6 +1,4 @@
-#include <lib/asm.h>
-
-ASM_BASIC(
+asm (
     ".section .entry\n\t"
 
     "cld\n\t"
diff --git a/limine.bin b/limine.bin
index e21149f6..9026b15d 100644
Binary files a/limine.bin and b/limine.bin differ
diff --git a/stage2/Makefile b/stage2/Makefile
index c14a94c7..ef8d88fa 100644
--- a/stage2/Makefile
+++ b/stage2/Makefile
@@ -10,6 +10,7 @@ INTERNAL_CFLAGS =  \
 	-fno-stack-protector \
 	-fno-pic \
 	-fomit-frame-pointer \
+	-masm=intel \
 	-mno-80387 \
 	-mno-mmx \
 	-mno-3dnow \
diff --git a/stage2/lib/asm.h b/stage2/lib/asm.h
deleted file mode 100644
index 560057c0..00000000
--- a/stage2/lib/asm.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef __LIB__ASM_H__
-#define __LIB__ASM_H__
-
-#define ASM(body, ...) asm volatile (".intel_syntax noprefix\n\t" body ".att_syntax prefix" : __VA_ARGS__)
-#define ASM_BASIC(body) asm (".intel_syntax noprefix\n\t" body ".att_syntax prefix")
-
-#define FARJMP16(seg, off) \
-    ".byte 0xea\n\t" \
-    ".2byte " off "\n\t" \
-    ".2byte " seg "\n\t" \
-
-#define FARJMP32(seg, off) \
-    ".byte 0xea\n\t" \
-    ".4byte " off "\n\t" \
-    ".2byte " seg "\n\t" \
-
-#endif
diff --git a/stage2/lib/blib.c b/stage2/lib/blib.c
index e5fe0558..62f5eacd 100644
--- a/stage2/lib/blib.c
+++ b/stage2/lib/blib.c
@@ -9,7 +9,6 @@
 #include <lib/cio.h>
 #include <lib/e820.h>
 #include <lib/print.h>
-#include <lib/asm.h>
 
 uint8_t bcd_to_int(uint8_t val) {
     return (val & 0x0f) + ((val & 0xf0) >> 4) * 10;
@@ -18,18 +17,20 @@ uint8_t bcd_to_int(uint8_t val) {
 int cpuid(uint32_t leaf, uint32_t subleaf,
           uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) {
     uint32_t cpuid_max;
-    ASM("cpuid\n\t", "=a" (cpuid_max)
-                   : "a" (leaf & 0x80000000)
-                   : "ebx", "ecx", "edx");
+    asm volatile ("cpuid"
+                  : "=a" (cpuid_max)
+                  : "a" (leaf & 0x80000000)
+                  : "ebx", "ecx", "edx");
     if (leaf > cpuid_max)
         return 1;
-    ASM("cpuid\n\t", "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
-                   : "a" (leaf), "c" (subleaf));
+    asm volatile ("cpuid"
+                  : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
+                  : "a" (leaf), "c" (subleaf));
     return 0;
 }
 
 __attribute__((noreturn)) void panic(const char *fmt, ...) {
-    ASM("cli\n\t", :: "memory");
+    asm volatile ("cli" ::: "memory");
 
     va_list args;
 
@@ -41,7 +42,7 @@ __attribute__((noreturn)) void panic(const char *fmt, ...) {
     va_end(args);
 
     for (;;) {
-        ASM("hlt\n\t", :: "memory");
+        asm volatile ("hlt" ::: "memory");
     }
 }
 
diff --git a/stage2/lib/cio.h b/stage2/lib/cio.h
index 76053099..ac1c88ce 100644
--- a/stage2/lib/cio.h
+++ b/stage2/lib/cio.h
@@ -2,35 +2,34 @@
 #define __CIO_H__
 
 #include <stdint.h>
-#include <lib/asm.h>
 
 static inline void port_out_b(uint16_t port, uint8_t value) {
-    ASM("out dx, al\n\t",  : "a" (value), "d" (port) : "memory");
+    asm volatile ("out dx, al"  : : "a" (value), "d" (port) : "memory");
 }
 
 static inline void port_out_w(uint16_t port, uint16_t value) {
-    ASM("out dx, ax\n\t",  : "a" (value), "d" (port) : "memory");
+    asm volatile ("out dx, ax"  : : "a" (value), "d" (port) : "memory");
 }
 
 static inline void port_out_d(uint16_t port, uint32_t value) {
-    ASM("out dx, eax\n\t", : "a" (value), "d" (port) : "memory");
+    asm volatile ("out dx, eax" : : "a" (value), "d" (port) : "memory");
 }
 
 static inline uint8_t port_in_b(uint16_t port) {
     uint8_t value;
-    ASM("in al, dx\n\t",  "=a" (value) : "d" (port) : "memory");
+    asm volatile ("in al, dx"  : "=a" (value) : "d" (port) : "memory");
     return value;
 }
 
 static inline uint16_t port_in_w(uint16_t port) {
     uint16_t value;
-    ASM("in ax, dx\n\t",  "=a" (value) : "d" (port) : "memory");
+    asm volatile ("in ax, dx"  : "=a" (value) : "d" (port) : "memory");
     return value;
 }
 
 static inline uint32_t port_in_d(uint16_t port) {
     uint32_t value;
-    ASM("in eax, dx\n\t", "=a" (value) : "d" (port) : "memory");
+    asm volatile ("in eax, dx" : "=a" (value) : "d" (port) : "memory");
     return value;
 }
 
diff --git a/stage2/lib/libc.c b/stage2/lib/libc.c
index 11b46fc3..c11d7b9e 100644
--- a/stage2/lib/libc.c
+++ b/stage2/lib/libc.c
@@ -1,7 +1,6 @@
 #include <stddef.h>
 #include <stdint.h>
 #include <lib/libc.h>
-#include <lib/asm.h>
 
 int toupper(int c) {
     if (c >= 'a' && c <= 'z') {
diff --git a/stage2/main.c b/stage2/main.c
index e8e75e0a..d2bf6a60 100644
--- a/stage2/main.c
+++ b/stage2/main.c
@@ -1,6 +1,4 @@
-#include <lib/asm.h>
-
-ASM_BASIC(
+asm (
     ".section .entry\n\t"
 
     "cld\n\t"
diff --git a/stage2/protos/chainload.c b/stage2/protos/chainload.c
index f073db13..26f9e546 100644
--- a/stage2/protos/chainload.c
+++ b/stage2/protos/chainload.c
@@ -6,7 +6,6 @@
 #include <lib/blib.h>
 #include <drivers/disk.h>
 #include <lib/term.h>
-#include <lib/asm.h>
 
 void chainload(void) {
     int part; {
@@ -36,9 +35,9 @@ void chainload(void) {
         read(drive, (void *)0x7c00, 0, 512);
     }
 
-    ASM(
+    asm volatile (
         // Jump to real mode
-        FARJMP32("0x08", "1f")
+        "jmp 0x08:1f\n\t"
         "1: .code16\n\t"
         "mov ax, 0x10\n\t"
         "mov ds, ax\n\t"
@@ -49,7 +48,7 @@ void chainload(void) {
         "mov eax, cr0\n\t"
         "and al, 0xfe\n\t"
         "mov cr0, eax\n\t"
-        FARJMP16("0", "1f")
+        "jmp 0x0000:1f\n\t"
         "1:\n\t"
         "mov ax, 0\n\t"
         "mov ds, ax\n\t"
@@ -60,7 +59,8 @@ void chainload(void) {
         "push 0\n\t"
         "push 0x7c00\n\t"
         "retf\n\t"
-        ".code32\n\t",
+        ".code32\n\t"
+        :
         : "d" (drive)
         : "memory"
     );
diff --git a/stage2/protos/linux.c b/stage2/protos/linux.c
index 3e38f3b7..0c3d9483 100644
--- a/stage2/protos/linux.c
+++ b/stage2/protos/linux.c
@@ -8,7 +8,6 @@
 #include <lib/config.h>
 #include <lib/print.h>
 #include <lib/memmap.h>
-#include <lib/asm.h>
 
 #define KERNEL_LOAD_ADDR ((size_t)0x100000)
 #define INITRD_LOAD_ADDR ((size_t)0x1000000)
@@ -137,11 +136,11 @@ void linux_load(char *cmdline, int boot_drive) {
 
     term_deinit();
 
-    ASM(
+    asm volatile (
         "cli\n\t"
         "cld\n\t"
 
-        FARJMP32("0x08", "1f")
+        "jmp 0x08:1f\n\t"
         "1: .code16\n\t"
         "mov ax, 0x10\n\t"
         "mov ds, ax\n\t"
@@ -152,7 +151,7 @@ void linux_load(char *cmdline, int boot_drive) {
         "mov eax, cr0\n\t"
         "and al, 0xfe\n\t"
         "mov cr0, eax\n\t"
-        FARJMP16("0", "1f")
+        "jmp 0x0000:1f\n\t"
         "1:\n\t"
         "mov ds, bx\n\t"
         "mov es, bx\n\t"
@@ -164,7 +163,8 @@ void linux_load(char *cmdline, int boot_drive) {
 
         "push cx\n\t"
         "push 0\n\t"
-        "retf\n\t",
+        "retf\n\t"
+        :
         : "b" (real_mode_code_seg), "c" (kernel_entry_seg)
         : "memory"
     );
diff --git a/stage2/protos/stivale.c b/stage2/protos/stivale.c
index b964b9b3..0f07ed7f 100644
--- a/stage2/protos/stivale.c
+++ b/stage2/protos/stivale.c
@@ -15,7 +15,6 @@
 #include <lib/term.h>
 #include <drivers/pic.h>
 #include <fs/file.h>
-#include <lib/asm.h>
 #include <mm/vmm64.h>
 
 struct stivale_header {
@@ -266,10 +265,10 @@ __attribute__((noreturn)) void stivale_spinup(int bits, bool level5pg,
     if (bits == 64) {
         if (level5pg) {
             // Enable CR4.LA57
-            ASM(
+            asm volatile (
                 "mov eax, cr4\n\t"
                 "bts eax, 12\n\t"
-                "mov cr4, eax\n\t", :: "eax", "memory"
+                "mov cr4, eax\n\t" ::: "eax", "memory"
             );
         }
 
@@ -304,7 +303,7 @@ __attribute__((noreturn)) void stivale_spinup(int bits, bool level5pg,
             }
         }
 
-        ASM(
+        asm volatile (
             "cli\n\t"
             "cld\n\t"
             "mov cr3, eax\n\t"
@@ -318,7 +317,7 @@ __attribute__((noreturn)) void stivale_spinup(int bits, bool level5pg,
             "mov eax, cr0\n\t"
             "or eax, 1 << 31\n\t"
             "mov cr0, eax\n\t"
-            FARJMP32("0x28", "1f")
+            "jmp 0x28:1f\n\t"
             "1: .code64\n\t"
             "mov ax, 0x30\n\t"
             "mov ds, ax\n\t"
@@ -349,13 +348,14 @@ __attribute__((noreturn)) void stivale_spinup(int bits, bool level5pg,
             "xor r15, r15\n\t"
 
             "iretq\n\t"
-            ".code32\n\t",
+            ".code32\n\t"
+            :
             : "a" (pagemap.top_level), "b" (&entry_point),
               "D" (stivale_struct), "S" (&stack)
             : "memory"
         );
     } else if (bits == 32) {
-        ASM(
+        asm volatile (
             "cli\n\t"
             "cld\n\t"
 
@@ -376,7 +376,8 @@ __attribute__((noreturn)) void stivale_spinup(int bits, bool level5pg,
             "xor edi, edi\n\t"
             "xor ebp, ebp\n\t"
 
-            "iret\n\t",
+            "iret\n\t"
+            :
             : "b" (&entry_point), "D" (stivale_struct), "S" (&stack)
             : "memory"
         );
diff --git a/stage2/protos/stivale2.c b/stage2/protos/stivale2.c
index 3c56edac..e4d91c5a 100644
--- a/stage2/protos/stivale2.c
+++ b/stage2/protos/stivale2.c
@@ -18,7 +18,6 @@
 #include <lib/term.h>
 #include <drivers/pic.h>
 #include <fs/file.h>
-#include <lib/asm.h>
 
 struct stivale2_tag {
     uint64_t identifier;
tab: 248 wrap: offon