started setting up support for C code in the kernel

This commit is contained in:
2025-02-20 17:13:40 +00:00
parent 294e6f0e33
commit 60efcf39b6
9 changed files with 71 additions and 2 deletions
+4 -1
View File
@@ -7,9 +7,12 @@ edition = "2021"
limine = "0.3.1"
lib_example = { path = "../lib_example" }
[build-dependencies]
cc = "1.2.14"
[features]
default = []
[[bin]]
name = "kernel"
path = "src/main.rs"
path = "src/main.rs"
+6 -1
View File
@@ -1,9 +1,14 @@
use std::process::Command;
use std::{env, path::Path};
use cc;
fn main() {
// Tell cargo to rerun if these files change
println!("cargo:rerun-if-changed=src");
println!("cargo:rerun-if-changed=linker.ld");
println!("cargo:rerun-if-changed=../config/limine.conf");
}
cc::Build::new()
.file("src/main.c")
.compile("lib");
}
+3
View File
@@ -0,0 +1,3 @@
int add(int x, int y) {
return x+y;
}
+7
View File
@@ -28,6 +28,11 @@ static _START_MARKER: RequestsStartMarker = RequestsStartMarker::new();
#[link_section = ".requests_end_marker"]
static _END_MARKER: RequestsEndMarker = RequestsEndMarker::new();
extern "C" {
pub fn add(x: i32, y: i32) -> i32;
}
#[no_mangle]
unsafe extern "C" fn kmain() -> ! {
// All limine requests must also be referenced in a called function, otherwise they may be
@@ -35,6 +40,8 @@ unsafe extern "C" fn kmain() -> ! {
assert!(BASE_REVISION.is_supported());
lib_example::add_nums(1, 2);
add(1, 2);
if let Some(framebuffer_response) = FRAMEBUFFER_REQUEST.get_response() {
if let Some(framebuffer) = framebuffer_response.framebuffers().next() {