:: commit ddd4172dcdef54c98aa31c7254a8c989f8ef495c

mintsuki <mintsuki@protonmail.com> — 2020-07-24 13:38

parents: e45f8ac41a

Add memory clobbers where missing and remove useless stivale signature

diff --git a/Makefile b/Makefile
index d69f1781..f2bebc75 100644
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,7 @@ test.img:
 	dd if=/dev/zero bs=1M count=0 seek=4096 of=test.img
 ifeq ($(OS), Linux)
 	parted -s test.img mklabel msdos
-	parted -s test.img mkpart primary 100%
+	parted -s test.img mkpart primary 0% 100%
 else ifeq ($(OS), FreeBSD)
 	sudo mdconfig -a -t vnode -f test.img -u md9
 	sudo gpart create -s mbr md9
diff --git a/STIVALE.md b/STIVALE.md
index 9dce822a..adfa8ff9 100644
--- a/STIVALE.md
+++ b/STIVALE.md
@@ -73,8 +73,6 @@ PIC/APIC IRQs are all masked.
 
 `rdi` will point to the stivale structure (described below).
 
-`rax` contains the stivale signature `0x73746976616c6521` (`stivale!` in ASCII).
-
 All other general purpose registers are set to 0.
 
 ### 32-bit kernel
@@ -101,8 +99,6 @@ PIC/APIC IRQs are all masked.
 
 `esp` is set to the requested stack as per stivale header.
 
-`edx:eax` contain the stivale signature `0x73746976:0x616c6521` (`stivale!` in ASCII).
-
 A pointer to the stivale structure (described below) is pushed onto this stack
 before the entry point is called.
 
diff --git a/qloader2.bin b/qloader2.bin
index 4e3a00fb..9e32a7dc 100644
Binary files a/qloader2.bin and b/qloader2.bin differ
diff --git a/src/lib/blib.c b/src/lib/blib.c
index 1bdf2999..38136ff5 100644
--- a/src/lib/blib.c
+++ b/src/lib/blib.c
@@ -30,7 +30,7 @@ int cpuid(uint32_t leaf, uint32_t subleaf,
 }
 
 __attribute__((noreturn)) void panic(const char *fmt, ...) {
-    asm volatile ("cli");
+    asm volatile ("cli" ::: "memory");
 
     va_list args;
 
@@ -42,7 +42,7 @@ __attribute__((noreturn)) void panic(const char *fmt, ...) {
     va_end(args);
 
     for (;;) {
-        asm volatile ("hlt");
+        asm volatile ("hlt" ::: "memory");
     }
 }
 
diff --git a/src/lib/cio.h b/src/lib/cio.h
index 5c23e5d4..f33a7afc 100644
--- a/src/lib/cio.h
+++ b/src/lib/cio.h
@@ -7,21 +7,21 @@
 	asm volatile (	"out dx, al"				\
 					:							\
 					: "a" (value), "d" (port)	\
-					: );						\
+					: "memory" );						\
 })
 
 #define port_out_w(port, value) ({				\
 	asm volatile (	"out dx, ax"				\
 					:							\
 					: "a" (value), "d" (port)	\
-					: );						\
+					: "memory" );						\
 })
 
 #define port_out_d(port, value) ({				\
 	asm volatile (	"out dx, eax"				\
 					:							\
 					: "a" (value), "d" (port)	\
-					: );						\
+					: "memory" );						\
 })
 
 #define port_in_b(port) ({						\
@@ -29,7 +29,7 @@
 	asm volatile (	"in al, dx"					\
 					: "=a" (value)				\
 					: "d" (port)				\
-					: );						\
+					: "memory" );						\
 	value;										\
 })
 
@@ -38,7 +38,7 @@
 	asm volatile (	"in ax, dx"					\
 					: "=a" (value)				\
 					: "d" (port)				\
-					: );						\
+					: "memory" );						\
 	value;										\
 })
 
@@ -47,13 +47,8 @@
 	asm volatile (	"in eax, dx"				\
 					: "=a" (value)				\
 					: "d" (port)				\
-					: );						\
+					: "memory" );						\
 	value;										\
 })
 
-#define io_wait() ({ port_out_b(0x80, 0x00); })
-
-#define disable_interrupts() ({ asm volatile ("cli"); })
-#define enable_interrupts() ({ asm volatile ("sti"); })
-
 #endif
diff --git a/src/protos/chainload.c b/src/protos/chainload.c
index 09311c3a..2e6249a6 100644
--- a/src/protos/chainload.c
+++ b/src/protos/chainload.c
@@ -62,5 +62,6 @@ void chainload(void) {
         ".code32\n\t"
         :
         : "d" (drive)
+        : "memory"
     );
 }
diff --git a/src/protos/linux.c b/src/protos/linux.c
index 851a9d73..59cb83a0 100644
--- a/src/protos/linux.c
+++ b/src/protos/linux.c
@@ -166,5 +166,6 @@ void linux_load(char *cmdline, int boot_drive) {
         "retf\n\t"
         :
         : "b" (real_mode_code_seg), "c" (kernel_entry_seg)
+        : "memory"
     );
 }
diff --git a/src/protos/stivale.c b/src/protos/stivale.c
index d943170d..1c5b9bc3 100644
--- a/src/protos/stivale.c
+++ b/src/protos/stivale.c
@@ -353,8 +353,7 @@ void stivale_load(char *cmdline, int boot_drive) {
             "push 0x28\n\t"
             "push [rbx]\n\t"
 
-            "mov rax, 0x73746976616c6521\n\t"
-
+            "xor rax, rax\n\t"
             "xor rbx, rbx\n\t"
             "xor rcx, rcx\n\t"
             "xor rdx, rdx\n\t"
@@ -390,11 +389,10 @@ void stivale_load(char *cmdline, int boot_drive) {
             "push 0x18\n\t"
             "push [ebx]\n\t"
 
-            "mov edx, 0x73746976\n\t"
-            "mov eax, 0x616c6521\n\t"
-
+            "xor eax, eax\n\t"
             "xor ebx, ebx\n\t"
             "xor ecx, ecx\n\t"
+            "xor edx, edx\n\t"
             "xor esi, esi\n\t"
             "xor edi, edi\n\t"
             "xor ebp, ebp\n\t"
tab: 248 wrap: offon