From 1d8bc204e2d384c3a3299805beea19adebd6e7cb Mon Sep 17 00:00:00 2001
From: Amelia Coutard <eliottulio.coutard@gmail.com>
Date: Fri, 6 May 2022 01:25:12 +0200
Subject: [PATCH] Changed os::halt to use inline asm instead of an asm routine,
 and moved the cli instructions around

---
 src/boot.S    | 3 +--
 src/utils.S   | 6 ------
 src/utils.cpp | 9 +++++++++
 src/utils.hpp | 3 ++-
 4 files changed, 12 insertions(+), 9 deletions(-)
 delete mode 100644 src/utils.S
 create mode 100644 src/utils.cpp

diff --git a/src/boot.S b/src/boot.S
index 2be4f42..5c331ef 100644
--- a/src/boot.S
+++ b/src/boot.S
@@ -110,6 +110,7 @@ stack_top:
 .code32
 .globl _start
 _start:
+	cli
 	mov $stack_top - KERNEL_VMA, %esp
 
 	# Save multiboot info:
@@ -131,7 +132,6 @@ _start:
 	popfl
 	xor %ecx, %eax
 	jnz .has_cpuid
-		cli
 	1:	hlt
 		jmp 1b
 	.has_cpuid:
@@ -151,7 +151,6 @@ _start:
 	jz .no_long_mode
 	jmp .has_long_mode
 	.no_long_mode:
-		cli
 	1:	hlt
 		jmp 1b
 	.has_long_mode:
diff --git a/src/utils.S b/src/utils.S
deleted file mode 100644
index f1287d8..0000000
--- a/src/utils.S
+++ /dev/null
@@ -1,6 +0,0 @@
-.section .text
-.globl halt
-halt:
-	cli
-1:	hlt
-	jmp 1b
diff --git a/src/utils.cpp b/src/utils.cpp
new file mode 100644
index 0000000..6c501aa
--- /dev/null
+++ b/src/utils.cpp
@@ -0,0 +1,9 @@
+#include "utils.hpp"
+
+void os::halt() {
+	asm(
+		"cli\n"
+		"\t1:\thlt\n"
+		"\tjmp 1b"
+	);
+}
diff --git a/src/utils.hpp b/src/utils.hpp
index 82abfb6..486d7f6 100644
--- a/src/utils.hpp
+++ b/src/utils.hpp
@@ -1,6 +1,7 @@
 #pragma once
 
 #include <stddef.h>
+#include <stdint.h>
 
 namespace os {
 
@@ -38,5 +39,5 @@ namespace os {
 		uintptr_t phys_addr;
 	};
 
-	extern "C" void halt();
+	void halt();
 } // namespace os
-- 
2.46.0