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
+8
View File
@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
+12
View File
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="EMPTY_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/kernel/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/lib_example/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/FoundryOS.iml" filepath="$PROJECT_DIR$/.idea/FoundryOS.iml" />
</modules>
</component>
</project>
Generated
+7
View File
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$/build/limine" vcs="Git" />
</component>
</project>
Generated
+16
View File
@@ -8,10 +8,20 @@ version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36"
[[package]]
name = "cc"
version = "1.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c3d1b2e905a3a7b00a6141adb0e4c0bb941d11caf55349d863942a1cc44e3c9"
dependencies = [
"shlex",
]
[[package]] [[package]]
name = "kernel" name = "kernel"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"cc",
"lib_example", "lib_example",
"limine", "limine",
] ]
@@ -28,3 +38,9 @@ checksum = "9ca87cab008b8efeebdbe037cd4d1438037d48c5cb6fed939ffa5aa06315a321"
dependencies = [ dependencies = [
"bitflags", "bitflags",
] ]
[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
+4 -1
View File
@@ -7,9 +7,12 @@ edition = "2021"
limine = "0.3.1" limine = "0.3.1"
lib_example = { path = "../lib_example" } lib_example = { path = "../lib_example" }
[build-dependencies]
cc = "1.2.14"
[features] [features]
default = [] default = []
[[bin]] [[bin]]
name = "kernel" name = "kernel"
path = "src/main.rs" path = "src/main.rs"
+6 -1
View File
@@ -1,9 +1,14 @@
use std::process::Command; use std::process::Command;
use std::{env, path::Path}; use std::{env, path::Path};
use cc;
fn main() { fn main() {
// Tell cargo to rerun if these files change // Tell cargo to rerun if these files change
println!("cargo:rerun-if-changed=src"); println!("cargo:rerun-if-changed=src");
println!("cargo:rerun-if-changed=linker.ld"); println!("cargo:rerun-if-changed=linker.ld");
println!("cargo:rerun-if-changed=../config/limine.conf"); 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"] #[link_section = ".requests_end_marker"]
static _END_MARKER: RequestsEndMarker = RequestsEndMarker::new(); static _END_MARKER: RequestsEndMarker = RequestsEndMarker::new();
extern "C" {
pub fn add(x: i32, y: i32) -> i32;
}
#[no_mangle] #[no_mangle]
unsafe extern "C" fn kmain() -> ! { unsafe extern "C" fn kmain() -> ! {
// All limine requests must also be referenced in a called function, otherwise they may be // 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()); assert!(BASE_REVISION.is_supported());
lib_example::add_nums(1, 2); lib_example::add_nums(1, 2);
add(1, 2);
if let Some(framebuffer_response) = FRAMEBUFFER_REQUEST.get_response() { if let Some(framebuffer_response) = FRAMEBUFFER_REQUEST.get_response() {
if let Some(framebuffer) = framebuffer_response.framebuffers().next() { if let Some(framebuffer) = framebuffer_response.framebuffers().next() {