From 2808bc9e7c6f3dd0f284b7bbc26147fe8d9b8d27 Mon Sep 17 00:00:00 2001
From: koniifer <koniifer@proton.me>
Date: Sat, 16 Nov 2024 16:34:45 +0000
Subject: [PATCH] various fixes, update to latest rust nightly

---
 Cargo.lock                              | 57 +++++--------------------
 kernel/.cargo/config.toml               |  3 --
 kernel/lds/x86_64.ld                    |  1 +
 kernel/src/arch/mod.rs                  | 12 ++++--
 kernel/src/arch/x86_64/mod.rs           |  6 +--
 kernel/src/lib.rs                       |  3 +-
 kernel/targets/aarch64-virt-ableos.json |  2 +-
 rust-toolchain.toml                     |  4 +-
 8 files changed, 27 insertions(+), 61 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 1e7ac8f..86916ee 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,6 +1,6 @@
 # This file is automatically @generated by Cargo.
 # It is not intended for manual editing.
-version = 3
+version = 4
 
 [[package]]
 name = "aarch64-cpu"
@@ -65,15 +65,6 @@ version = "2.6.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
 
-[[package]]
-name = "bumpalo"
-version = "3.16.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
-dependencies = [
- "allocator-api2",
-]
-
 [[package]]
 name = "byteorder"
 version = "1.5.0"
@@ -208,12 +199,6 @@ dependencies = [
  "wasi",
 ]
 
-[[package]]
-name = "hashbrown"
-version = "0.14.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
-
 [[package]]
 name = "hashbrown"
 version = "0.15.1"
@@ -228,24 +213,23 @@ dependencies = [
 [[package]]
 name = "hbbytecode"
 version = "0.1.0"
-source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#baa70d3f1272c2cbb208ca17115dc54b7d31af5c"
+source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#4088bd18b189b15996a4bdd6ab47141372457875"
 
 [[package]]
 name = "hblang"
 version = "0.1.0"
-source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#baa70d3f1272c2cbb208ca17115dc54b7d31af5c"
+source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#4088bd18b189b15996a4bdd6ab47141372457875"
 dependencies = [
- "hashbrown 0.15.1",
+ "hashbrown",
  "hbbytecode",
  "hbvm",
  "log",
- "regalloc2",
 ]
 
 [[package]]
 name = "hbvm"
 version = "0.1.0"
-source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#baa70d3f1272c2cbb208ca17115dc54b7d31af5c"
+source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#4088bd18b189b15996a4bdd6ab47141372457875"
 dependencies = [
  "hbbytecode",
 ]
@@ -396,7 +380,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da"
 dependencies = [
  "equivalent",
- "hashbrown 0.15.1",
+ "hashbrown",
 ]
 
 [[package]]
@@ -406,7 +390,7 @@ dependencies = [
  "aarch64-cpu",
  "crossbeam-queue",
  "derive_more",
- "hashbrown 0.15.1",
+ "hashbrown",
  "hbvm",
  "limine",
  "log",
@@ -428,9 +412,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
 
 [[package]]
 name = "libc"
-version = "0.2.163"
+version = "0.2.164"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1fdaeca4cf44ed4ac623e86ef41f056e848dbeab7ec043ecb7326ba300b36fd0"
+checksum = "433bfe06b8c75da9b2e3fbea6e5329ff87748f0b144ef75306e674c3f6f7c13f"
 
 [[package]]
 name = "limine"
@@ -553,19 +537,6 @@ dependencies = [
  "bitflags 2.6.0",
 ]
 
-[[package]]
-name = "regalloc2"
-version = "0.10.2"
-source = "git+https://github.com/jakubDoka/regalloc2?branch=reuse-allocations#21c43e3ee182824e92e2b25f1d3c03ed47f9c02b"
-dependencies = [
- "allocator-api2",
- "bumpalo",
- "hashbrown 0.14.5",
- "log",
- "rustc-hash",
- "smallvec",
-]
-
 [[package]]
 name = "regex-syntax"
 version = "0.8.5"
@@ -602,12 +573,6 @@ dependencies = [
  "windows-sys",
 ]
 
-[[package]]
-name = "rustc-hash"
-version = "2.0.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152"
-
 [[package]]
 name = "rustc_version"
 version = "0.4.1"
@@ -619,9 +584,9 @@ dependencies = [
 
 [[package]]
 name = "rustls"
-version = "0.23.16"
+version = "0.23.17"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "eee87ff5d9b36712a58574e12e9f0ea80f915a5b0ac518d322b24a465617925e"
+checksum = "7f1a745511c54ba6d4465e8d5dfbd81b45791756de28d4981af70d6dca128f1e"
 dependencies = [
  "log",
  "once_cell",
diff --git a/kernel/.cargo/config.toml b/kernel/.cargo/config.toml
index e052590..422bf9d 100644
--- a/kernel/.cargo/config.toml
+++ b/kernel/.cargo/config.toml
@@ -1,6 +1,3 @@
 [unstable]
 build-std = ["core", "compiler_builtins", "alloc"]
 build-std-features = ["compiler-builtins-mem"]
-
-[build]
-target = "./targets/x86_64-ableos.json"
diff --git a/kernel/lds/x86_64.ld b/kernel/lds/x86_64.ld
index 8e899a4..19ee79f 100644
--- a/kernel/lds/x86_64.ld
+++ b/kernel/lds/x86_64.ld
@@ -38,6 +38,7 @@ SECTIONS
 
     .data : {
         *(.data .data.*)
+        *(.got .got.*)
     } :data
 
     .bss : {
diff --git a/kernel/src/arch/mod.rs b/kernel/src/arch/mod.rs
index 30621ca..305872f 100644
--- a/kernel/src/arch/mod.rs
+++ b/kernel/src/arch/mod.rs
@@ -14,11 +14,16 @@ arch_cond!(
     riscv64: "riscv64",
     x86_64: "x86_64",
 );
+
+#[cfg(target_arch = "x86_64")]
 use {crate::arch::interrupts::Interrupt, alloc::string::String};
+#[cfg(target_arch = "x86_64")]
 pub struct InterruptList {
     list: HashMap<Interrupt, String>,
 }
+#[cfg(target_arch = "x86_64")]
 use hashbrown::HashMap;
+#[cfg(target_arch = "x86_64")]
 impl InterruptList {
     pub fn new() -> Self {
         Self {
@@ -26,10 +31,9 @@ impl InterruptList {
         }
     }
 }
-use {
-    alloc::vec::Vec,
-    spin::{Lazy, Mutex},
-};
+#[cfg(target_arch = "x86_64")]
+use spin::{Lazy, Mutex};
+#[cfg(target_arch = "x86_64")]
 pub static INTERRUPT_LIST: Lazy<Mutex<InterruptList>> = Lazy::new(|| {
     let mut il = InterruptList::new();
     use crate::alloc::string::ToString;
diff --git a/kernel/src/arch/x86_64/mod.rs b/kernel/src/arch/x86_64/mod.rs
index aa4f6cd..fbc362c 100644
--- a/kernel/src/arch/x86_64/mod.rs
+++ b/kernel/src/arch/x86_64/mod.rs
@@ -33,7 +33,7 @@ const INITIAL_KERNEL_HEAP_SIZE: *const () = _initial_kernel_heap_size as _;
 #[cfg(not(target_feature = "avx2"))]
 unsafe extern "C" fn _kernel_start() -> ! {
     // Initialise SSE, then jump to kernel entrypoint
-    core::arch::asm!(
+    core::arch::naked_asm!(
         // Initialise SSE
         "mov rax, cr0",
         "and ax, 0xfffb",
@@ -46,7 +46,6 @@ unsafe extern "C" fn _kernel_start() -> ! {
         // Jump to the kernel entry point
         "jmp {}",
         sym start,
-        options(noreturn),
     )
 }
 
@@ -54,7 +53,7 @@ unsafe extern "C" fn _kernel_start() -> ! {
 #[naked]
 #[cfg(target_feature = "avx2")]
 unsafe extern "C" fn _kernel_start() -> ! {
-    core::arch::asm!(
+    core::arch::naked_asm!(
         // Enable protected mode and configure control registers
         "mov rax, cr0",
         "and ax, 0xFFFB",  // Clear CR0.EM (bit 2) for coprocessor emulation
@@ -100,7 +99,6 @@ unsafe extern "C" fn _kernel_start() -> ! {
         "jmp {0}",
         sym start,
         sym oops,
-        options(noreturn),
     )
 }
 
diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs
index a94f94b..3eff39d 100644
--- a/kernel/src/lib.rs
+++ b/kernel/src/lib.rs
@@ -5,7 +5,6 @@
 #![feature(
     slice_split_once,
     exclusive_wrapper,
-    new_uninit,
     core_intrinsics,
     abi_x86_interrupt,
     alloc_error_handler,
@@ -15,7 +14,7 @@
     pointer_is_aligned_to
 )]
 #![test_runner(crate::test_runner)]
-#![allow(dead_code, internal_features)]
+#![allow(dead_code, internal_features, static_mut_refs)]
 extern crate alloc;
 
 mod allocator;
diff --git a/kernel/targets/aarch64-virt-ableos.json b/kernel/targets/aarch64-virt-ableos.json
index fcb14d0..9ee18cf 100644
--- a/kernel/targets/aarch64-virt-ableos.json
+++ b/kernel/targets/aarch64-virt-ableos.json
@@ -1,6 +1,6 @@
 {
     "arch": "aarch64",
-    "data-layout": "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128",
+    "data-layout": "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32",
     "disable-redzone": true,
     "env": "",
     "executables": true,
diff --git a/rust-toolchain.toml b/rust-toolchain.toml
index 9353a54..e66400a 100644
--- a/rust-toolchain.toml
+++ b/rust-toolchain.toml
@@ -1,3 +1,5 @@
 [toolchain]
-channel = "nightly-2024-07-27"
+# old toolchain
+# channel = "nightly-2024-07-27"
+channel = "nightly"
 components = ["rust-src", "llvm-tools"]