Skip to content

Commit 38ef6ed

Browse files
committed
fix x86 build config
1 parent cbf8594 commit 38ef6ed

7 files changed

Lines changed: 57 additions & 10 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
**/*.log
44
.vscode/
55
.idea/
6+
/build

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
先决条件(WSL2 Ubuntu 22)
110110
```bash
111111
sudo apt-get update
112-
sudo apt-get install -y build-essential qemu-system-x86 xorriso make nasm gcc
112+
sudo apt-get install -y build-essential qemu-system-x86 xorriso nasm mtools git curl unzip
113113
```
114114
下载配置的nightly工具链 `rustup toolchain install`
115115

kernel/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ codegen-units = 1
2525

2626
[lib]
2727
name = "rint_kernel"
28-
crate-type = ["staticlib"]
28+
crate-type = ["rlib", "staticlib"]

kernel/src/lib.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// #![feature(asm_const)]
44

55
use core::fmt::Write;
6+
use core::ptr;
67
use spin::Mutex;
78
use uart_16550::SerialPort;
89
use x86_64::instructions::{hlt, interrupts};
@@ -19,7 +20,7 @@ fn panic(info: &core::panic::PanicInfo) -> ! {
1920
}
2021

2122
#[unsafe(no_mangle)] // 禁止编译器对该函数进行名称改编,确保最终 ELF 里的符号名就是 kstart
22-
extern "C" fn kstart() -> ! {
23+
pub extern "C" fn kstart() -> ! {
2324
init_serial();
2425
banner();
2526

@@ -61,6 +62,38 @@ pub fn kprint(args: core::fmt::Arguments) { // 生成一个封装好的格式化
6162
}
6263
}
6364

65+
// --- Minimal C ABI shims ---
66+
// These satisfy symbols the core/alloc runtime expects when no libc is present.
67+
#[unsafe(no_mangle)]
68+
pub extern "C" fn memcpy(dest: *mut u8, src: *const u8, n: usize) -> *mut u8 {
69+
unsafe{ptr::copy_nonoverlapping(src, dest, n);}
70+
dest
71+
}
72+
73+
#[unsafe(no_mangle)]
74+
pub extern "C" fn memmove(dest: *mut u8, src: *const u8, n: usize) -> *mut u8 {
75+
unsafe { ptr::copy(src, dest, n); }
76+
dest
77+
}
78+
79+
#[unsafe(no_mangle)]
80+
pub extern "C" fn memset(dest: *mut u8, value: i32, n: usize) -> *mut u8 {
81+
unsafe { ptr::write_bytes(dest, value as u8, n); }
82+
dest
83+
}
84+
85+
#[unsafe(no_mangle)]
86+
pub extern "C" fn memcmp(a: *const u8, b: *const u8, n: usize) -> i32 {
87+
for i in 0..n {
88+
let va = unsafe { *a.add(i) };
89+
let vb = unsafe { *b.add(i) };
90+
if va != vb {
91+
return va as i32 - vb as i32;
92+
}
93+
}
94+
0
95+
}
96+
6497
#[macro_export]
6598
macro_rules! kprintln {
6699
// 接受任意格式化参数列表,等同 println! 的可变参数匹配方式

kernel/src/main.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#![no_std]
22
#![no_main]
3+
#![allow(unused_extern_crates)]
4+
5+
extern crate rint_kernel;
36

47
use core::arch::global_asm;
58

@@ -10,20 +13,19 @@ r#"
1013
.section .text._start
1114
.global _start
1215
_start:
13-
leaq stack_top(%rip), %rsp
16+
lea rsp, [rip + stack_top]
1417
call kstart
1518
1619
1: hlt
1720
jmp 1b
1821
19-
.section .bss
22+
.section .bss.stack, "aw", @nobits
2023
.align 16
2124
.global __bootstrap_stack
2225
__bootstrap_stack:
2326
.space 0x8000
2427
2528
.global stack_top
2629
stack_top:
27-
.quad __bootstrap_stack + 0x8000
2830
"#
2931
);

kernel/x86_64-rint.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
{
22
"llvm-target": "x86_64-unknown-none",
3+
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
4+
"target-endian": "little",
35
"arch": "x86_64",
46
"os": "none",
57
"vendor": "unknown",
68
"linker-flavor": "ld.lld",
9+
"linker": "rust-lld",
710
"disable-redzone": true,
811
"features": "+sse,+sse2",
912
"panic-strategy": "abort",
10-
"executables": true
13+
"executables": true,
14+
"target-pointer-width": 64,
15+
"target-c-int-width": 32
1116
}

scripts/make_iso.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ if ! command -v qemu-system-x86_64 >/dev/null; then
2020
echo "Warning: QEMU not found (sudo apt-get install qemu-system-x86). ISO build will continue without QEMU." >&2
2121
fi
2222

23-
# 获取 Limine binary release 并运行 configure
23+
# 获取 Limine binary release;若 CLI 不存在则执行 make(binary 分支不提供 ./configure
2424
if [ ! -d "${LIMINE_DIR}/.git" ]; then
2525
git clone https://codeberg.org/Limine/Limine.git --branch=v10.6.2-binary --depth=1 "${LIMINE_DIR}"
26-
(cd "${LIMINE_DIR}" && ./configure)
26+
fi
27+
28+
# 构建 CLI:优先检查根目录 limine,其次 bin/limine
29+
if [ ! -x "${LIMINE_DIR}/limine" ] && [ ! -x "${LIMINE_DIR}/bin/limine" ]; then
30+
(cd "${LIMINE_DIR}" && make)
2731
fi
2832

2933
# 解析 Limine 产物路径(bin 或 share)
@@ -90,10 +94,12 @@ xorriso -as mkisofs -R -r -J \
9094
LIMINE_CLI=""
9195
if [ -x "${LIMINE_DIR}/bin/limine" ]; then
9296
LIMINE_CLI="${LIMINE_DIR}/bin/limine"
97+
elif [ -x "${LIMINE_DIR}/limine" ]; then
98+
LIMINE_CLI="${LIMINE_DIR}/limine"
9399
elif command -v limine >/dev/null; then
94100
LIMINE_CLI="$(command -v limine)"
95101
else
96-
echo "Limine CLI not found. Ensure ./configure produced bin/limine or install Limine to PATH." >&2
102+
echo "Limine CLI not found. Run 'make' in build/limine or install Limine to PATH." >&2
97103
exit 1
98104
fi
99105

0 commit comments

Comments
 (0)