48 Commits

Author SHA1 Message Date
zxq5 72fe78cbc6 Merge pull request 'dev' (#4) from dev into main
Continuous integration / build (push) Failing after 2m12s
Reviewed-on: OsDev/FoundryOS#4
2025-02-22 21:32:27 +00:00
zxq5 f9bc75c4f3 added boot messages 2025-02-22 21:30:13 +00:00
zxq5 494d00c53b Update .gitea/workflows/rust.yml 2025-02-22 21:18:14 +00:00
zxq5 114c70ffe9 updated submodules
Continuous integration / build (push) Failing after 2m7s
2025-02-22 21:03:17 +00:00
zxq5 361c67764d totally didn't import an allocator... 2025-02-22 21:02:29 +00:00
zxq5 36cb118933 paging done, starting on allocation.
Continuous integration / build (push) Failing after 1m51s
2025-02-22 16:56:01 +00:00
zxq5 7b3ba170f0 changes to submodules
Continuous integration / build (push) Failing after 1m56s
2025-02-22 15:43:06 +00:00
zxq5 49880fa9d7 Merge remote-tracking branch 'refs/remotes/origin/dev' into dev
merging into dev
2025-02-22 15:41:54 +00:00
zxq5 0bbbf653f8 setup GDT & fixed a deadlock 2025-02-22 15:41:41 +00:00
nullndvoid 40ad5dbbf4 Add page fault handler that does nothing, I am tired
Continuous integration / build (push) Failing after 38m24s
2025-02-22 05:00:18 +00:00
nullndvoid 2b2219f5be Update submodules
Continuous integration / build (push) Failing after 7m47s
2025-02-22 04:00:37 +00:00
nullndvoid c1a8afb836 Formatted random JSON file whoops
Continuous integration / build (push) Has been cancelled
2025-02-22 03:59:28 +00:00
zxq5 28afe25cca check boot was successful else panic
Continuous integration / build (push) Has been cancelled
2025-02-22 03:52:32 +00:00
zxq5 90faace7a2 changed name to snake case
Continuous integration / build (push) Has been cancelled
2025-02-22 03:50:13 +00:00
zxq5 5b1f04c1da changed some code order
Continuous integration / build (push) Has been cancelled
2025-02-22 03:47:54 +00:00
zxq5 3a232c8023 Merge remote-tracking branch 'refs/remotes/origin/dev' into dev (and add cargo fmt on save)
Continuous integration / build (push) Has been cancelled
2025-02-22 03:39:22 +00:00
zxq5 5eaf0d7c69 Merge remote-tracking branch 'refs/remotes/origin/dev' into dev
Continuous integration / build (push) Has been cancelled
2025-02-22 03:36:32 +00:00
zxq5 b4d0b05e13 updated submodule 2025-02-22 03:35:02 +00:00
nullndvoid 969756c691 Suppress erroneous build errors from rust-analyzer.
Continuous integration / build (push) Has been cancelled
2025-02-22 03:33:54 +00:00
zxq5 5c9717d384 cargo fmt
Continuous integration / build (push) Has been cancelled
2025-02-22 03:33:19 +00:00
zxq5 bb5bf9115b fixed weird merge issues
Continuous integration / build (push) Has been cancelled
2025-02-22 03:29:33 +00:00
zxq5 ae82e9c24b idk 2025-02-22 03:27:08 +00:00
zxq5 ab0ec35094 updated submodules
Continuous integration / build (push) Has been cancelled
2025-02-22 03:24:48 +00:00
zxq5 2ee21dea05 did interrupts stuff 2025-02-22 03:19:05 +00:00
zxq5 d12160c5d0 setup TSS 2025-02-22 03:16:13 +00:00
nullndvoid f5f5aeb8dc Formatting changes, called 'cargo fmt'
Continuous integration / build (push) Has been cancelled
2025-02-22 03:09:46 +00:00
nullndvoid 34213ca744 Merge remote into local dev, I should probably find a new branch lol
Continuous integration / build (push) Has been cancelled
2025-02-22 02:44:09 +00:00
nullndvoid 3aca8fd720 Add some docs on building, bumped limine to latest version
No issues occurred having bumped the version, all seems well.
2025-02-22 02:41:23 +00:00
zxq5 a88059c5ff workflow builds nightly
Continuous integration / build (push) Has been cancelled
2025-02-22 02:13:38 +00:00
zxq5 68c3d2fa0e workflow changes
Continuous integration / build (push) Failing after 1m37s
2025-02-22 01:55:36 +00:00
zxq5 af3215d887 changed order of steps in rust.yml
Continuous integration / build (push) Failing after 23m3s
2025-02-22 01:28:31 +00:00
zxq5 11d63535e9 added submodule cloning to rust.yml
Continuous integration / build (push) Has been cancelled
2025-02-22 01:27:08 +00:00
zxq5 ee8dae4981 added rust.yml workflow, probably wont work.
Continuous integration / build (push) Failing after 7m45s
2025-02-22 01:12:15 +00:00
zxq5 650f34f354 removed redundant script 2025-02-22 01:08:07 +00:00
zxq5 1b313c67e0 first interrupt handler + setup IDT 2025-02-22 01:06:55 +00:00
zxq5 cb77883f4c done 2025-02-22 01:06:27 +00:00
zxq5 16d94f37cb moving libs to submodules 2025-02-22 01:05:18 +00:00
zxq5 d9f6b4b69a e 2025-02-22 00:58:51 +00:00
zxq5 cc56dc8072 idk 2025-02-22 00:58:40 +00:00
zxq5 f0e25c7a5d started work on lib_application - progress limited as requires alloc support to make further progress 2025-02-21 16:13:06 +00:00
zxq5 e626a3bcf2 working on colour support 2025-02-21 16:13:27 +00:00
zxq5 34b960c20a println works 2025-02-20 22:59:24 +00:00
zxq5 ee8de361dc Merge remote-tracking branch 'refs/remotes/origin/dev' into dev
merge
2025-02-20 17:13:57 +00:00
zxq5 60efcf39b6 started setting up support for C code in the kernel 2025-02-20 17:13:40 +00:00
zxq5 b028a97a44 vscode workspace setup 2025-02-20 17:12:25 +00:00
zxq5 294e6f0e33 created example lib for sake of testing 2025-02-20 15:52:42 +00:00
zxq5 76f070af8b idk 2025-02-20 02:54:01 +00:00
zxq5 2f0e09b9bc it compiles! 2025-02-20 02:47:18 +00:00
92 changed files with 1393 additions and 301 deletions
+13
View File
@@ -0,0 +1,13 @@
[build]
target = "x86_64-kernel"
target-dir = "build/target"
[unstable]
build-std = ["core", "compiler_builtins", "alloc"]
build-std-features = ["compiler-builtins-mem"]
[env]
RUST_TARGET_PATH = { value = "kernel", relative = true }
[target.x86_64-kernel]
runner = "scripts/run.sh"
+22
View File
@@ -0,0 +1,22 @@
on:
push:
branches: [ main ]
pull-request:
branches: [ main ]
name: Continuous integration
jobs:
build:
name: build
runs-on: ubuntu-latest
steps:
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
target: x86_64-unknown-none
components: rust-src, llvm-tools-preview
toolchain: nightly
- uses: actions/checkout@v4
with:
submodules: true
- run: cargo build
+15 -1
View File
@@ -1 +1,15 @@
/target # Build output directories
/build/
/target/
# Generated files
*.o
*.bin
*.iso
*.img
*.elf
*.efi
*.log
# Rust specific
Cargo.lock
+15
View File
@@ -0,0 +1,15 @@
[submodule "lib/lib_application"]
path = lib/lib_application
url = https://git.zxq5.dev/OsDev/FoundryOS-lib_application.git
[submodule "lib/lib_ascii"]
path = lib/lib_ascii
url = https://git.zxq5.dev/OsDev/FoundryOS-lib_ascii.git
[submodule "lib/lib_framebuffer"]
path = lib/lib_framebuffer
url = https://git.zxq5.dev/OsDev/FoundryOS-lib_framebuffer.git
[submodule "lib/lib_serial"]
path = lib/lib_serial
url = https://git.zxq5.dev/OsDev/FoundryOS-lib_serial.git
[submodule "lib/lib_alloc"]
path = lib/lib_alloc
url = https://git.zxq5.dev/OsDev/FoundryOS-lib_alloc.git
+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>
+9
View File
@@ -0,0 +1,9 @@
{
"rust-analyzer.cargo.allTargets": false,
"rust-analyzer.cargo.target": "x86_64-kernel",
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer",
"editor.formatOnSave": true
}
}
Generated
+170 -1
View File
@@ -2,6 +2,18 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 4 version = 4
[[package]]
name = "autocfg"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
[[package]]
name = "bit_field"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61"
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "2.8.0" version = "2.8.0"
@@ -9,10 +21,79 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36"
[[package]] [[package]]
name = "foundryos_kernel" name = "cc"
version = "1.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c3d1b2e905a3a7b00a6141adb0e4c0bb941d11caf55349d863942a1cc44e3c9"
dependencies = [
"shlex",
]
[[package]]
name = "foundry_os"
version = "0.1.0"
dependencies = [
"cc",
"lib_alloc",
"lib_ascii",
"lib_framebuffer",
"lib_serial",
"limine",
"pc-keyboard",
"pic8259",
"spin",
"x86_64",
]
[[package]]
name = "lazy_static"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
dependencies = [
"spin",
]
[[package]]
name = "lib_alloc"
version = "0.1.0"
dependencies = [
"linked_list_allocator",
"x86_64",
]
[[package]]
name = "lib_application"
version = "0.1.0"
dependencies = [
"lib_ascii",
]
[[package]]
name = "lib_ascii"
version = "0.1.0"
dependencies = [
"lazy_static",
"lib_framebuffer",
"spin",
"x86_64",
]
[[package]]
name = "lib_framebuffer"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"limine", "limine",
"spin",
]
[[package]]
name = "lib_serial"
version = "0.1.0"
dependencies = [
"lazy_static",
"spin",
"x86_64",
] ]
[[package]] [[package]]
@@ -23,3 +104,91 @@ checksum = "9ca87cab008b8efeebdbe037cd4d1438037d48c5cb6fed939ffa5aa06315a321"
dependencies = [ dependencies = [
"bitflags", "bitflags",
] ]
[[package]]
name = "linked_list_allocator"
version = "0.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286"
dependencies = [
"spinning_top",
]
[[package]]
name = "lock_api"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17"
dependencies = [
"autocfg",
"scopeguard",
]
[[package]]
name = "pc-keyboard"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0ca629cbb3f0d5b699c338f0129ff78c9bfd7ea8b1258ad529bff490dc8ed5a"
[[package]]
name = "pic8259"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62d9a86c292b165f757e47e7fd66855def189b2564609bc4203727b27c33db22"
dependencies = [
"x86_64",
]
[[package]]
name = "rustversion"
version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4"
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "spin"
version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
dependencies = [
"lock_api",
]
[[package]]
name = "spinning_top"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b9eb1a2f4c41445a3a0ff9abc5221c5fcd28e1f13cd7c0397706f9ac938ddb0"
dependencies = [
"lock_api",
]
[[package]]
name = "volatile"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "442887c63f2c839b346c192d047a7c87e73d0689c9157b00b53dcc27dd5ea793"
[[package]]
name = "x86_64"
version = "0.15.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f042214de98141e9c8706e8192b73f56494087cc55ebec28ce10f26c5c364ae"
dependencies = [
"bit_field",
"bitflags",
"rustversion",
"volatile",
]
+23 -1
View File
@@ -1,6 +1,11 @@
[workspace] [workspace]
members = [ members = [
"kernel" "lib/lib_framebuffer",
"lib/lib_serial",
"lib/lib_ascii",
"kernel",
"lib/lib_application",
"lib/lib_alloc",
] ]
resolver = "2" resolver = "2"
@@ -8,3 +13,20 @@ resolver = "2"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
[profile.dev]
opt-level = "z"
debug = true
debug-assertions = true
overflow-checks = true
lto = false
incremental = false
codegen-units = 1
[profile.release]
opt-level = 3
debug = false
debug-assertions = false
overflow-checks = false
lto = true
incremental = false
codegen-units = 1
+20
View File
@@ -1,2 +1,22 @@
# FoundryOS # FoundryOS
## Cloning and building
Here are some simple steps to get started:
```sh
# If you have not yet cloned the repo:
git clone --recurse-submodules https://git.zxq5.dev/OsDev/FoundryOS.git
# If you already cloned the repo:
git submodule update --init --recursive
cargo build
# This will build the binaries if required - no need to call cargo build.
cargo run
```
### Build dependencies
* jq: checks whether the app is to be run in debugging mode.
* libisoburn: creates ISO images to be booted from.
* qemu: to run the kernel.
+7 -1
View File
@@ -1,5 +1,11 @@
# Timeout in seconds that Limine will use before automatically booting.
timeout: 1 timeout: 1
# The entry name that will be displayed in the boot menu.
/foundry-os /foundry-os
# We use the Limine boot protocol.
protocol: limine protocol: limine
kernel_path: boot()/boot/kernel
# Path to the kernel to boot. boot():/ represents the partition on which limine.conf is located.
kernel_path: boot():/boot/kernel
-30
View File
@@ -1,30 +0,0 @@
{
"llvm-target": "x86_64-unknown-none",
"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",
"arch": "x86_64",
"target-endian": "little",
"target-pointer-width": "64",
"target-c-int-width": "32",
"os": "none",
"executables": true,
"linker-flavor": "ld.lld",
"linker": "rust-lld",
"panic-strategy": "abort",
"disable-redzone": true,
"features": "-mmx,-sse,+soft-float",
"relocation-model": "static",
"code-model": "kernel",
"pre-link-args": {
"ld.lld": [
"--script=linker/linker.ld",
"-nostdlib",
"--no-dynamic-linker",
"-static",
"--no-pie",
"--gc-sections",
"--build-id=none",
"-z", "max-page-size=0x1000"
]
}
}
+1
View File
@@ -0,0 +1 @@
{}
+1
View File
@@ -0,0 +1 @@
{}
+31
View File
@@ -0,0 +1,31 @@
{
"file-explorer": true,
"global-search": true,
"switcher": true,
"graph": true,
"backlink": true,
"canvas": true,
"outgoing-link": true,
"tag-pane": true,
"properties": false,
"page-preview": true,
"daily-notes": true,
"templates": true,
"note-composer": true,
"command-palette": true,
"slash-command": false,
"editor-status": true,
"bookmarks": true,
"markdown-importer": false,
"zk-prefixer": false,
"random-note": false,
"outline": true,
"word-count": true,
"slides": false,
"audio-recorder": false,
"workspaces": false,
"file-recovery": true,
"publish": false,
"sync": true,
"webviewer": false
}
+22
View File
@@ -0,0 +1,22 @@
{
"collapse-filter": true,
"search": "",
"showTags": false,
"showAttachments": false,
"hideUnresolved": false,
"showOrphans": true,
"collapse-color-groups": true,
"colorGroups": [],
"collapse-display": true,
"showArrow": false,
"textFadeMultiplier": 0,
"nodeSizeMultiplier": 1,
"lineSizeMultiplier": 1,
"collapse-forces": true,
"centerStrength": 0.518713248970312,
"repelStrength": 10,
"linkStrength": 1,
"linkDistance": 250,
"scale": 1,
"close": true
}
+198
View File
@@ -0,0 +1,198 @@
{
"main": {
"id": "20da7b1c0adc4114",
"type": "split",
"children": [
{
"id": "a20540b7c1ddbfca",
"type": "tabs",
"children": [
{
"id": "e1fb15cab546d0b6",
"type": "leaf",
"state": {
"type": "markdown",
"state": {
"file": "Usage/Building The Kernel.md",
"mode": "source",
"source": false
},
"icon": "lucide-file",
"title": "Building The Kernel"
}
}
]
},
{
"id": "6bf1f87bf81a3031",
"type": "tabs",
"children": [
{
"id": "add883d295e04659",
"type": "leaf",
"state": {
"type": "markdown",
"state": {
"file": "Usage/Building The Kernel.md",
"mode": "preview",
"source": false
},
"icon": "lucide-file",
"title": "Building The Kernel"
}
}
]
}
],
"direction": "vertical"
},
"left": {
"id": "8c92fa79437d4f31",
"type": "split",
"children": [
{
"id": "e4a9f8318da249b0",
"type": "tabs",
"children": [
{
"id": "da6fd2aac65f47f1",
"type": "leaf",
"state": {
"type": "file-explorer",
"state": {
"sortOrder": "alphabetical",
"autoReveal": false
},
"icon": "lucide-folder-closed",
"title": "Files"
}
},
{
"id": "3f86b26f003a0d1a",
"type": "leaf",
"state": {
"type": "search",
"state": {
"query": "tag:#usage",
"matchingCase": false,
"explainSearch": false,
"collapseAll": false,
"extraContext": false,
"sortOrder": "alphabetical"
},
"icon": "lucide-search",
"title": "Search"
}
},
{
"id": "39755dd9db653e17",
"type": "leaf",
"state": {
"type": "bookmarks",
"state": {},
"icon": "lucide-bookmark",
"title": "Bookmarks"
}
}
]
}
],
"direction": "horizontal",
"width": 200,
"collapsed": true
},
"right": {
"id": "baa2a8e61b737fa6",
"type": "split",
"children": [
{
"id": "b628e7116722c59a",
"type": "tabs",
"children": [
{
"id": "eb1781be59af8c30",
"type": "leaf",
"state": {
"type": "backlink",
"state": {
"file": "Usage/Building The Kernel.md",
"collapseAll": false,
"extraContext": false,
"sortOrder": "alphabetical",
"showSearch": false,
"searchQuery": "",
"backlinkCollapsed": false,
"unlinkedCollapsed": true
},
"icon": "links-coming-in",
"title": "Backlinks for Building The Kernel"
}
},
{
"id": "18e4602ee5825e11",
"type": "leaf",
"state": {
"type": "outgoing-link",
"state": {
"file": "Usage/Building The Kernel.md",
"linksCollapsed": false,
"unlinkedCollapsed": true
},
"icon": "links-going-out",
"title": "Outgoing links from Building The Kernel"
}
},
{
"id": "df5aadad9f62dff1",
"type": "leaf",
"state": {
"type": "tag",
"state": {
"sortOrder": "frequency",
"useHierarchy": false,
"showSearch": false,
"searchQuery": ""
},
"icon": "lucide-tags",
"title": "Tags"
}
},
{
"id": "9bc68cb074d39ab5",
"type": "leaf",
"state": {
"type": "outline",
"state": {
"file": "Usage/Building The Kernel.md",
"followCursor": false,
"showSearch": false,
"searchQuery": ""
},
"icon": "lucide-list",
"title": "Outline of Building The Kernel"
}
}
],
"currentTab": 2
}
],
"direction": "horizontal",
"width": 300
},
"left-ribbon": {
"hiddenItems": {
"switcher:Open quick switcher": false,
"graph:Open graph view": false,
"canvas:Create new canvas": false,
"daily-notes:Open today's daily note": false,
"templates:Insert template": false,
"command-palette:Open command palette": false
}
},
"active": "e1fb15cab546d0b6",
"lastOpenFiles": [
"Usage",
"Welcome.md",
"Usage/Building The Kernel.md"
]
}
+11
View File
@@ -0,0 +1,11 @@
#usage
### Requirements
- Latest rust nightly release
> rustup update
> rustup override set nightly
- Specific rustup components that can be installed with the following commands:
> rustup component add rust-src
> rustup component add llvm-tools-preview
### Building
run the following command (in the root directory of the project)
> ./run.sh
-7
View File
@@ -1,7 +0,0 @@
[build]
target = "../customos"
target-dir = "./target"
[unstable]
build-std = ["core", "compiler_builtins"]
build-std-features = ["compiler-builtins-mem"]
+19 -1
View File
@@ -1,7 +1,25 @@
[package] [package]
name = "foundryos_kernel" name = "foundry_os"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
limine = "0.3.1" limine = "0.3.1"
lib_framebuffer = { path = "../lib/lib_framebuffer" }
lib_serial = { path = "../lib/lib_serial" }
lib_ascii = { path = "../lib/lib_ascii" }
lib_alloc = { path = "../lib/lib_alloc" }
x86_64 = "0.15.2"
spin = "0.9.8"
pic8259 = "0.11.0"
pc-keyboard = "0.8.0"
[build-dependencies]
cc = "1.2.14"
[features]
default = []
[[bin]]
name = "kernel"
path = "src/main.rs"
+9 -6
View File
@@ -1,7 +1,10 @@
use cc;
use std::process::Command;
use std::{env, path::Path};
fn main() { fn main() {
let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap(); // Tell cargo to rerun if these files change
// Tell cargo to pass the linker script to the linker.. println!("cargo:rerun-if-changed=src");
println!("cargo:rustc-link-arg=-Tlinker-{arch}.ld"); println!("cargo:rerun-if-changed=linker.ld");
// ..and to re-run if it changes. println!("cargo:rerun-if-changed=../config/limine.conf");
println!("cargo:rerun-if-changed=linker-{arch}.ld"); }
}
-3
View File
@@ -1,3 +0,0 @@
Signature: 8a477f597d28d172789f06886806bc55
# This file is a cache directory tag created by cargo.
# For information about cache directory tags see https://bford.info/cachedir/
View File
@@ -1 +0,0 @@
{"rustc":5637828655848808591,"features":"","declared_features":"","target":0,"profile":0,"path":0,"deps":[[16831489395241507197,"build_script_build",false,2449660372133931133]],"local":[{"RerunIfChanged":{"output":"../customos/debug/build/compiler_builtins-7ff902764ead3159/output","paths":["build.rs","configure.rs"]}}],"rustflags":[],"config":0,"compile_kind":0}
@@ -1 +0,0 @@
This file has an mtime of when this was started.
@@ -1 +0,0 @@
{"$message_type":"diagnostic","message":"Error loading target specification: Could not find specification for target \"../customos\". Run `rustc --print target-list` for a list of built-in targets","code":null,"level":"error","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1m\u001b[38;5;9merror\u001b[0m\u001b[0m\u001b[1m: Error loading target specification: Could not find specification for target \"../customos\". Run `rustc --print target-list` for a list of built-in targets\u001b[0m\n\n"}
@@ -1 +0,0 @@
{"rustc":5637828655848808591,"features":"","declared_features":"","target":0,"profile":0,"path":0,"deps":[[16831489395241507197,"build_script_build",false,15090704965883138604],[4566724075159146729,"build_script_build",false,12086878114467551400]],"local":[{"RerunIfChanged":{"output":"../customos/debug/build/foundryos_kernel-15da3dc5b1d972d1/output","paths":["linker-x86_64.ld"]}}],"rustflags":[],"config":0,"compile_kind":0}
@@ -1 +0,0 @@
This file has an mtime of when this was started.
@@ -1,151 +0,0 @@
cargo::rerun-if-changed=build.rs
cargo::rerun-if-changed=configure.rs
cargo::rustc-check-cfg=cfg(__ashldi3, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__ashlsi3, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__ashrdi3, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__ashrsi3, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__bswapsi2, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__bswapdi2, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__bswapti2, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__divdi3, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__divsi3, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__divmoddi4, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__divmodsi4, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__divmodsi4, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__divmodti4, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__lshrdi3, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__lshrsi3, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__moddi3, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__modsi3, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__muldi3, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__udivdi3, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__udivmoddi4, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__udivmodsi4, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__udivsi3, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__umoddi3, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__umodsi3, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_cas1_relax, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_cas1_acq, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_cas1_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_cas1_acq_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_cas2_relax, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_cas2_acq, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_cas2_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_cas2_acq_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_cas4_relax, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_cas4_acq, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_cas4_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_cas4_acq_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_cas8_relax, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_cas8_acq, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_cas8_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_cas8_acq_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_cas16_relax, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_cas16_acq, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_cas16_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_cas16_acq_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldadd1_relax, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldadd1_acq, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldadd1_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldadd1_acq_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldadd2_relax, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldadd2_acq, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldadd2_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldadd2_acq_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldadd4_relax, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldadd4_acq, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldadd4_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldadd4_acq_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldadd8_relax, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldadd8_acq, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldadd8_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldadd8_acq_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldclr1_relax, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldclr1_acq, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldclr1_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldclr1_acq_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldclr2_relax, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldclr2_acq, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldclr2_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldclr2_acq_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldclr4_relax, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldclr4_acq, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldclr4_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldclr4_acq_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldclr8_relax, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldclr8_acq, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldclr8_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldclr8_acq_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldeor1_relax, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldeor1_acq, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldeor1_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldeor1_acq_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldeor2_relax, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldeor2_acq, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldeor2_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldeor2_acq_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldeor4_relax, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldeor4_acq, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldeor4_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldeor4_acq_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldeor8_relax, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldeor8_acq, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldeor8_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldeor8_acq_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldset1_relax, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldset1_acq, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldset1_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldset1_acq_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldset2_relax, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldset2_acq, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldset2_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldset2_acq_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldset4_relax, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldset4_acq, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldset4_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldset4_acq_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldset8_relax, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldset8_acq, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldset8_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_ldset8_acq_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_swp1_relax, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_swp1_acq, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_swp1_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_swp1_acq_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_swp2_relax, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_swp2_acq, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_swp2_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_swp2_acq_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_swp4_relax, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_swp4_acq, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_swp4_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_swp4_acq_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_swp8_relax, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_swp8_acq, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_swp8_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(__aarch64_swp8_acq_rel, values("optimized-c"))
cargo::rustc-check-cfg=cfg(target_feature, values("vis3"))
cargo::rustc-check-cfg=cfg(feature, values("checked"))
cargo::rustc-check-cfg=cfg(assert_no_panic)
cargo::rustc-check-cfg=cfg(f16_enabled)
cargo::rustc-check-cfg=cfg(f128_enabled)
cargo::rustc-cfg=f16_enabled
cargo::rustc-cfg=f128_enabled
cargo:rustc-check-cfg=cfg(intrinsics_enabled)
cargo:rustc-check-cfg=cfg(arch_enabled)
cargo:rustc-check-cfg=cfg(optimizations_enabled)
cargo:rustc-check-cfg=cfg(feature, values("unstable-public-internals"))
cargo:rustc-cfg=intrinsics_enabled
cargo:rustc-cfg=arch_enabled
cargo:rustc-check-cfg=cfg(optimizations_enabled)
cargo:rustc-check-cfg=cfg(x86_no_sse)
cargo:rustc-env=CFG_CARGO_FEATURES=["compiler-builtins", "core", "default", "mem", "rustc-dep-of-std"]
cargo:rustc-env=CFG_OPT_LEVEL=0
cargo:rustc-env=CFG_TARGET_FEATURES=["x87"]
cargo:rustc-cfg=feature="unstable-intrinsics"
cargo:compiler-rt=/home/zxq5/.cargo/bin/registry/src/index.crates.io-1949cf8c6b5b557f/compiler_builtins-0.1.146/compiler-rt
cargo::rustc-check-cfg=cfg(feature, values("mem-unaligned"))
cargo:rustc-cfg=feature="mem-unaligned"
cargo::rustc-check-cfg=cfg(thumb)
cargo::rustc-check-cfg=cfg(thumb_1)
cargo::rustc-check-cfg=cfg(kernel_user_helpers)
@@ -1 +0,0 @@
/home/zxq5/Projects/OSDev/FoundryOS/kernel/./target/../customos/debug/build/compiler_builtins-7ff902764ead3159/out
@@ -1 +0,0 @@
This file has an mtime of when this was started.
@@ -1,2 +0,0 @@
cargo:rustc-link-arg=-Tlinker-x86_64.ld
cargo:rerun-if-changed=linker-x86_64.ld
@@ -1 +0,0 @@
/home/zxq5/Projects/OSDev/FoundryOS/kernel/./target/../customos/debug/build/foundryos_kernel-15da3dc5b1d972d1/out
@@ -9,9 +9,10 @@ ENTRY(kmain)
/* process. */ /* process. */
PHDRS PHDRS
{ {
text PT_LOAD; limine_requests PT_LOAD;
rodata PT_LOAD; text PT_LOAD;
data PT_LOAD; rodata PT_LOAD;
data PT_LOAD;
} }
SECTIONS SECTIONS
@@ -22,6 +23,18 @@ SECTIONS
/* that is the beginning of the region. */ /* that is the beginning of the region. */
. = 0xffffffff80000000; . = 0xffffffff80000000;
/* Define a section to contain the Limine requests and assign it to its own PHDR */
.limine_requests : {
KEEP(*(.limine_requests_start))
KEEP(*(.limine_requests))
KEEP(*(.limine_requests_end))
} :limine_requests
/* Move to the next memory page for .text */
. = ALIGN(CONSTANT(MAXPAGESIZE));
.text : { .text : {
*(.text .text.*) *(.text .text.*)
} :text } :text
@@ -38,12 +51,6 @@ SECTIONS
.data : { .data : {
*(.data .data.*) *(.data .data.*)
/* Place the sections that contain the Limine requests as part of the .data */
/* output section. */
KEEP(*(.requests_start_marker))
KEEP(*(.requests))
KEEP(*(.requests_end_marker))
} :data } :data
/* NOTE: .bss needs to be the last thing mapped to :data, otherwise lots of */ /* NOTE: .bss needs to be the last thing mapped to :data, otherwise lots of */
@@ -60,4 +67,4 @@ SECTIONS
*(.eh_frame*) *(.eh_frame*)
*(.note .note.*) *(.note .note.*)
} }
} }
-4
View File
@@ -1,4 +0,0 @@
[toolchain]
channel = "nightly"
targets = ["rust-src", "llvm-tools-preview", "rustfmt", "clippy"]
components = []
+1
View File
@@ -0,0 +1 @@
pub mod x86_64;
+69
View File
@@ -0,0 +1,69 @@
use x86_64::{
instructions::tables::load_tss,
registers::segmentation::{Segment, CS, DS, ES, SS},
structures::{
gdt::{Descriptor, GlobalDescriptorTable, SegmentSelector},
tss::TaskStateSegment,
},
VirtAddr,
};
use spin::Lazy;
pub const DOUBLE_FAULT_1ST_INDEX: u16 = 0;
static TSS: Lazy<TaskStateSegment> = Lazy::new(|| {
let mut tss = TaskStateSegment::new();
tss.interrupt_stack_table[DOUBLE_FAULT_1ST_INDEX as usize] = {
const STACK_SIZE: usize = 4096 * 8;
static mut STACK: [u8; STACK_SIZE] = [0; STACK_SIZE];
let stack_start = VirtAddr::from_ptr(&raw const STACK);
let stack_end = stack_start + STACK_SIZE.try_into().unwrap();
stack_end
};
tss
});
static GDT: Lazy<(GlobalDescriptorTable, Selectors)> = Lazy::new(|| {
let mut gdt = GlobalDescriptorTable::new();
let code_selector = gdt.append(Descriptor::kernel_code_segment());
let data_selector = gdt.append(Descriptor::kernel_data_segment());
let user_code_selector = gdt.append(Descriptor::user_code_segment());
let user_data_selector = gdt.append(Descriptor::user_data_segment());
let tss_selector = gdt.append(Descriptor::tss_segment(&TSS));
(
gdt,
Selectors {
code_selector,
data_selector,
user_code_selector,
user_data_selector,
tss_selector,
},
)
});
struct Selectors {
code_selector: SegmentSelector,
data_selector: SegmentSelector,
user_code_selector: SegmentSelector,
user_data_selector: SegmentSelector,
tss_selector: SegmentSelector,
}
pub fn init() {
GDT.0.load();
unsafe {
CS::set_reg(GDT.1.code_selector);
load_tss(GDT.1.tss_selector);
DS::set_reg(self::GDT.1.data_selector);
ES::set_reg(self::GDT.1.data_selector);
SS::set_reg(self::GDT.1.data_selector);
}
}
+132
View File
@@ -0,0 +1,132 @@
use lib_ascii::{print, println_log};
use lib_serial::serial_println;
use x86_64::instructions::port::Port;
use x86_64::registers::control::Cr2;
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame, PageFaultErrorCode};
use pic8259::ChainedPics;
use spin::{Lazy, Mutex};
use super::gdt;
static IDT: Lazy<InterruptDescriptorTable> = Lazy::new(|| {
let mut idt = InterruptDescriptorTable::new();
idt.breakpoint.set_handler_fn(breakpoint_handler);
unsafe {
idt.double_fault
.set_handler_fn(double_fault_handler)
.set_stack_index(gdt::DOUBLE_FAULT_1ST_INDEX);
}
idt.general_protection_fault
.set_handler_fn(general_protection_fault_handler);
idt.page_fault.set_handler_fn(page_fault_handler);
idt[InterruptIndex::Timer.as_u8()].set_handler_fn(timer_interrupt_handler);
idt[InterruptIndex::Keyboard.as_u8()].set_handler_fn(keyboard_interrupt_handler);
idt
});
pub const PIC_1_OFFSET: u8 = 32;
pub const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8;
pub static PICS: Mutex<ChainedPics> =
Mutex::new(unsafe { ChainedPics::new(PIC_1_OFFSET, PIC_2_OFFSET) });
#[derive(Debug, Clone, Copy)]
#[repr(u8)]
pub enum InterruptIndex {
Timer = PIC_1_OFFSET,
Keyboard,
}
impl InterruptIndex {
fn as_u8(self) -> u8 {
self as u8
}
fn _as_usize(self) -> usize {
usize::from(self.as_u8())
}
}
pub fn init_idt() {
IDT.load();
unsafe {
PICS.lock().initialize();
PICS.lock().write_masks(0xfc, 0xff);
}
}
extern "x86-interrupt" fn breakpoint_handler(stack_frame: InterruptStackFrame) {
serial_println!("Exception: Breakpoint\n{:#?}", stack_frame);
println_log!("Exception: Breakpoint\n{:#?}", stack_frame);
}
extern "x86-interrupt" fn general_protection_fault_handler(
stack_frame: InterruptStackFrame,
_error_code: u64,
) {
serial_println!("Exception: General Protection Fault\n{:#?}", stack_frame);
panic!("Exception: General Protection Fault\n{:#?}", stack_frame);
}
extern "x86-interrupt" fn double_fault_handler(
stack_frame: InterruptStackFrame,
_error_code: u64,
) -> ! {
serial_println!("Exception: Double Fault\n{:#?}", stack_frame);
panic!("Exception: Double Fault\n{:#?}", stack_frame);
}
extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStackFrame) {
use pc_keyboard::{layouts, DecodedKey, HandleControl, Keyboard, ScancodeSet1};
use spin::Mutex;
use x86_64::instructions::port::Port;
static KEYBOARD: Lazy<Mutex<Keyboard<layouts::Us104Key, ScancodeSet1>>> = Lazy::new(|| {
Mutex::new(Keyboard::new(
ScancodeSet1::new(),
layouts::Us104Key,
HandleControl::Ignore,
))
});
let mut keyboard = KEYBOARD.lock();
let mut port = Port::new(0x60);
let scancode: u8 = unsafe { port.read() };
if let Ok(Some(key_event)) = keyboard.add_byte(scancode) {
if let Some(key) = keyboard.process_keyevent(key_event) {
match key {
DecodedKey::Unicode(character) => print!("{}", character),
DecodedKey::RawKey(key) => print!("{:?}", key),
}
}
}
unsafe {
PICS.lock()
.notify_end_of_interrupt(InterruptIndex::Keyboard.as_u8());
}
}
extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: InterruptStackFrame) {
unsafe {
PICS.lock()
.notify_end_of_interrupt(InterruptIndex::Timer.as_u8());
}
}
extern "x86-interrupt" fn page_fault_handler(
stack_frame: InterruptStackFrame,
error_code: PageFaultErrorCode,
) {
serial_println!("Exception: Page Fault");
serial_println!("Accessed Address: {:?}", Cr2::read());
serial_println!("Error Code: {:?}", error_code);
serial_println!("{:#?}", stack_frame);
crate::hcf();
}
+56
View File
@@ -0,0 +1,56 @@
//! Sets up a memory map using Limine.
use limine::{
request::{HhdmRequest, KernelAddressRequest, MemoryMapRequest},
response::MemoryMapResponse,
};
use spin::Lazy;
#[used]
#[link_section = ".requests"]
static MEMORY_MAP_REQUEST: MemoryMapRequest = MemoryMapRequest::new();
#[used]
#[link_section = ".requests"]
static HIGHER_HALF_DIRECT_MAP_REQUEST: HhdmRequest = HhdmRequest::new();
/// ```rs
/// let virt_addr = phys_addr + offset;
/// let phys_addr = virt_addr - offset; // (given VA is in the HHDM). Do not use for executable code.
/// ```
pub static PHYSICAL_MEMORY_OFFSET: Lazy<u64> = Lazy::new(|| {
HIGHER_HALF_DIRECT_MAP_REQUEST
.get_response()
.unwrap()
.offset()
});
#[used]
#[link_section = ".requests"]
static KERNEL_ADDRESS_REQUEST: KernelAddressRequest = KernelAddressRequest::new();
/// Converts virtual addresses in the kernel to a physical address like this:
/// ```rs
/// let phys_addr = virt_addr - virtual_base + physical_base;
/// ```
///
/// Returns (virtual_base, physical_base)
pub static KERNEL_PHYSICAL_MEMORY_OFFSET: Lazy<(u64, u64)> = Lazy::new(|| {
let resp = KERNEL_ADDRESS_REQUEST.get_response().unwrap();
// These are base addresses, using Limine's built in page table.
(resp.virtual_base(), resp.physical_base())
});
/// Fetches the memory map from Limine.
///
/// # Panics
///
/// Panics if the memory map was not found in MEMORY_MAP_REQUEST.
pub fn get_memory_map() -> &'static MemoryMapResponse {
if let Some(memory_map) = MEMORY_MAP_REQUEST.get_response() {
return memory_map;
} else {
unreachable!("Could not fetch memory map from Limine.")
}
}
+134
View File
@@ -0,0 +1,134 @@
use lib_alloc::allocator::FoundryAllocator;
use limine::{memory_map::EntryType, response::MemoryMapResponse};
use x86_64::{
addr,
registers::control::Cr3,
structures::paging::{
page_table::FrameError, FrameAllocator, OffsetPageTable, PageTable, PhysFrame, Size4KiB,
},
PhysAddr, VirtAddr,
};
/// Returns a mutable reference to the current level 4 page table.
///
/// # Safety
///
/// The caller must ensure that the level 4 page table is not modified
/// simultaneously. The caller must also ensure that the physical memory offset
/// is correct, to ensure that the correct virtual address is constructed.
unsafe fn active_l4_table(physical_memory_offset: VirtAddr) -> &'static mut PageTable {
let (level_4_frame, _) = Cr3::read();
let phys_addr = level_4_frame.start_address();
let virt = phys_addr.as_u64() + physical_memory_offset.as_u64();
&mut *(virt as *mut PageTable)
}
/// Initializes the `OffsetPageTable` for the current CPU architecture.
///
/// # Safety
///
/// This function must be called only once and should be called before any
/// memory operations are performed that rely on virtual memory management.
/// The provided `physical_memory_offset` must be accurate to ensure correct
/// translation of physical addresses.
///
/// # Parameters
///
/// - `physical_memory_offset`: The offset to convert physical addresses to
/// virtual addresses in the higher-half direct map.
///
/// # Returns
///
/// Returns an `OffsetPageTable` that allows for manipulation of the page
/// tables for the current CPU architecture.
pub unsafe fn init(physical_memory_offset: VirtAddr) -> OffsetPageTable<'static> {
let l4_table = active_l4_table(physical_memory_offset);
OffsetPageTable::new(l4_table, physical_memory_offset)
}
pub(crate) struct FoundryOSFrameAllocator {
memory_map: &'static MemoryMapResponse,
next: usize,
}
impl FoundryOSFrameAllocator {
/// Creates a new `FoundryOSFrameAllocator` from a memory map.
///
/// This function takes a reference to a `MemoryMapResponse` and initializes a
/// `FoundryOSFrameAllocator` with it. The `next` field is set to 0, indicating that
/// the first frame to be allocated is the first frame in the memory map.
pub unsafe fn init(memory_map: &'static MemoryMapResponse) -> FoundryOSFrameAllocator {
FoundryOSFrameAllocator {
memory_map,
next: 0,
}
}
/// An iterator over all usable frames in the memory map.
///
/// Yields one `PhysFrame` for each available 4KiB frame in the memory map.
///
/// This function is used to allocate frames for the pagemap.
fn usable_frames(&self) -> impl Iterator<Item = PhysFrame> {
let regions = self.memory_map.entries().iter();
let usable_regions = regions.filter(|region| region.entry_type == EntryType::USABLE);
let addr_ranges = usable_regions.map(|region| region.base..region.base + region.length);
let frame_addresses = addr_ranges.flat_map(|r| r.step_by(4096));
frame_addresses.map(|addr| PhysFrame::from_start_address(PhysAddr::new(addr)).unwrap())
}
}
unsafe impl FrameAllocator<Size4KiB> for FoundryOSFrameAllocator {
/// Allocates a frame from the list of usable frames.
///
/// This function returns the next available `PhysFrame` from the memory map,
/// if one exists. Once a frame is allocated, the internal counter is incremented
/// to point to the next frame for future allocations.
///
/// # Returns
///
/// - `Some(PhysFrame)`: If a usable frame is available.
/// - `None`: If there are no more usable frames to allocate.
fn allocate_frame(&mut self) -> Option<PhysFrame> {
let frame = self.usable_frames().nth(self.next);
self.next += 1;
frame
}
}
// pub unsafe fn translate_addr(addr: VirtAddr, physical_memory_offset: VirtAddr) -> Option<PhysAddr> {
// translate_addr_inner(addr, physical_memory_offset)
// }
// fn translate_addr_inner(addr: VirtAddr, physical_memory_offset: VirtAddr) -> Option<PhysAddr> {
// let (l4_table_frame, _) = Cr3::read();
// let table_indexes = [
// addr.p4_index(),
// addr.p3_index(),
// addr.p2_index(),
// addr.p1_index(),
// ];
// let mut frame = l4_table_frame;
// for &i in &table_indexes {
// let virt = physical_memory_offset + frame.start_address().as_u64();
// let table_ptr: *const PageTable = virt.as_ptr();
// let table = unsafe { &*table_ptr };
// let entry = &table[i];
// frame = match entry.frame() {
// Ok(frame) => frame,
// Err(FrameError::FrameNotPresent) => return None,
// Err(FrameError::HugeFrame) => panic!("huge frames are not supported!"),
// };
// }
// Some(frame.start_address() + u64::from(addr.page_offset()))
// }
+7
View File
@@ -0,0 +1,7 @@
pub mod gdt;
pub mod interrupts;
pub mod memory;
pub(crate) mod memmap;
+95
View File
@@ -0,0 +1,95 @@
#![no_std]
#![feature(abi_x86_interrupt)]
extern crate alloc;
use core::arch::asm;
use lib_alloc::allocator::init_heap;
use limine::request::{RequestsEndMarker, RequestsStartMarker};
use limine::BaseRevision;
pub use lib_ascii::{print, print_log, println, println_log, WRITER};
pub use lib_serial::{serial_print, serial_println, serial_read};
use x86_64::structures::paging::Translate;
use x86_64::{PhysAddr, VirtAddr};
mod arch;
/// Sets the base revision to the latest revision supported by the crate.
/// See specification for further info.
/// Be sure to mark all limine requests with #[used], otherwise they may be removed by the compiler.
#[used]
// The .requests section allows limine to find the requests faster and more safely.
#[link_section = ".requests"]
static BASE_REVISION: BaseRevision = BaseRevision::new();
/// Define the stand and end markers for Limine requests.
#[used]
#[link_section = ".requests_start_marker"]
static _START_MARKER: RequestsStartMarker = RequestsStartMarker::new();
#[used]
#[link_section = ".requests_end_marker"]
static _END_MARKER: RequestsEndMarker = RequestsEndMarker::new();
#[panic_handler]
fn rust_panic(_info: &core::panic::PanicInfo) -> ! {
println!("Kernel panic: {}", _info);
serial_println!("Kernel panic: {}", _info);
hcf();
}
pub fn hcf() -> ! {
loop {
unsafe {
#[cfg(target_arch = "x86_64")]
asm!("hlt");
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
asm!("wfi");
#[cfg(target_arch = "loongarch64")]
asm!("idle 0");
}
}
}
pub fn boot() -> Result<(), &'static str> {
if !BASE_REVISION.is_supported() {
return Err("base revision not supported");
}
use arch::x86_64::{gdt, interrupts, memmap, memory};
let memory_map = memmap::get_memory_map();
print_log!(" Initialising Serial... ");
lib_serial::init()?;
println_log!("[Success]");
print_log!(" Setting Up Global Descriptor Table... ");
gdt::init();
println_log!("[Success]");
print_log!(" Setting Up Interrupt Descriptor Table... ");
interrupts::init_idt();
println_log!("[Success]");
print_log!(" Setting Up Page Table... ");
let mut frame_allocator = unsafe { memory::FoundryOSFrameAllocator::init(memory_map) };
println_log!("[Success]");
print_log!(" Initialising Memory Subsystem... ");
let physical_memory_offset = VirtAddr::new(*memmap::PHYSICAL_MEMORY_OFFSET);
let mut l4_table = unsafe { memory::init(physical_memory_offset) };
println_log!("[Success]");
print_log!(" Initialising Heap... ");
if let Err(e) = init_heap(&mut l4_table, &mut frame_allocator) {
return Err("Failed to initialise heap");
}
println_log!("[Success]");
print_log!(" Enabling Interrupts... ");
x86_64::instructions::interrupts::enable();
println_log!("[Success]");
Ok(())
}
+35 -52
View File
@@ -1,67 +1,50 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
use core::arch::asm; extern crate alloc;
use limine::request::{FramebufferRequest, RequestsEndMarker, RequestsStartMarker}; use alloc::vec::Vec;
use limine::BaseRevision;
/// Sets the base revision to the latest revision supported by the crate. use foundry_os::{println, println_log};
/// See specification for further info.
/// Be sure to mark all limine requests with #[used], otherwise they may be removed by the compiler.
#[used]
// The .requests section allows limine to find the requests faster and more safely.
#[link_section = ".requests"]
static BASE_REVISION: BaseRevision = BaseRevision::new();
#[used]
#[link_section = ".requests"]
static FRAMEBUFFER_REQUEST: FramebufferRequest = FramebufferRequest::new();
/// Define the stand and end markers for Limine requests.
#[used]
#[link_section = ".requests_start_marker"]
static _START_MARKER: RequestsStartMarker = RequestsStartMarker::new();
#[used]
#[link_section = ".requests_end_marker"]
static _END_MARKER: RequestsEndMarker = RequestsEndMarker::new();
#[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
// removed by the linker. // removed by the linker.
assert!(BASE_REVISION.is_supported());
if let Some(framebuffer_response) = FRAMEBUFFER_REQUEST.get_response() { println_log!(" [ Initialising Kernel Systems ] ");
if let Some(framebuffer) = framebuffer_response.framebuffers().next() { if let Err(err) = foundry_os::boot() {
for i in 0..100_u64 { panic!("{}", err);
// Calculate the pixel offset using the framebuffer information we obtained above.
// We skip `i` scanlines (pitch is provided in bytes) and add `i * 4` to skip `i` pixels forward.
let pixel_offset = i * framebuffer.pitch() + i * 4;
// Write 0xFFFFFFFF to the provided pixel offset to fill it white.
*(framebuffer.addr().add(pixel_offset as usize) as *mut u32) = 0xFFFFFFFF;
}
}
} }
hcf(); println_log!("[ Kernel Initialised Successfully ] ");
}
#[panic_handler] let dimensions = lib_ascii::screensize_chars();
fn rust_panic(_info: &core::panic::PanicInfo) -> ! { let dimensions2 = lib_framebuffer::screensize_px();
hcf();
}
fn hcf() -> ! { println!("Dimensions: {}x{} (px)", dimensions2.0, dimensions2.1);
loop { println!("Dimensions: {}x{} (chars)", dimensions.0, dimensions.1);
unsafe {
#[cfg(target_arch = "x86_64")] println!(
asm!("hlt"); "
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))] $$$$$$$$\\ $$\\
asm!("wfi"); $$ _____| $$ |
#[cfg(target_arch = "loongarch64")] $$ | $$$$$$\\ $$\\ $$\\ $$$$$$$\\ $$$$$$$ | $$$$$$\\ $$\\ $$\\
asm!("idle 0"); $$$$$\\ $$ __$$\\ $$ | $$ |$$ __$$\\ $$ __$$ |$$ __$$\\ $$ | $$ |
} $$ __|$$ / $$ |$$ | $$ |$$ | $$ |$$ / $$ |$$ | \\__|$$ | $$ |
} $$ | $$ | $$ |$$ | $$ |$$ | $$ |$$ | $$ |$$ | $$ | $$ |
} $$ | \\$$$$$$ |\\$$$$$$ |$$ | $$ |\\$$$$$$$ |$$ | \\$$$$$$$ |
\\__| \\______/ \\______/ \\__| \\__| \\_______|\\__| \\____$$ |
$$$$$$\\ $$$$$$\\ $$\\ $$\\ $$\\ $$\\ $$ |
$$ __$$\\ $$ __$$\\ $$ | $$ |$$$$ | \\$$$$$$ |
$$ / $$ |$$ / \\__| $$ | $$ |\\_$$ | \\______/
$$ | $$ |\\$$$$$$\\ \\$$\\ $$ | $$ |
$$ | $$ | \\____$$\\ \\$$\\$$ / $$ |
$$ | $$ |$$\\ $$ | \\$$$ / $$ |
$$$$$$ |\\$$$$$$ | \\$ / $$$$$$\\
\\______/ \\______/ \\_/ \\______|
"
);
loop {}
}
-1
View File
@@ -1 +0,0 @@
{"rustc_fingerprint":10191676143533991604,"outputs":{"17747080675513052775":{"success":true,"status":"","code":0,"stdout":"rustc 1.87.0-nightly (827a0d638 2025-02-18)\nbinary: rustc\ncommit-hash: 827a0d638dabc9a22c56f9c37a557568f86ac76c\ncommit-date: 2025-02-18\nhost: x86_64-unknown-linux-gnu\nrelease: 1.87.0-nightly\nLLVM version: 20.1.0\n","stderr":""},"7971740275564407648":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/zxq5/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu\noff\npacked\nunpacked\n___\ndebug_assertions\nfmt_debug=\"full\"\noverflow_checks\npanic=\"unwind\"\nproc_macro\nrelocation_model=\"pic\"\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"x87\"\ntarget_has_atomic\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_has_atomic_equal_alignment=\"16\"\ntarget_has_atomic_equal_alignment=\"32\"\ntarget_has_atomic_equal_alignment=\"64\"\ntarget_has_atomic_equal_alignment=\"8\"\ntarget_has_atomic_equal_alignment=\"ptr\"\ntarget_has_atomic_load_store\ntarget_has_atomic_load_store=\"16\"\ntarget_has_atomic_load_store=\"32\"\ntarget_has_atomic_load_store=\"64\"\ntarget_has_atomic_load_store=\"8\"\ntarget_has_atomic_load_store=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_thread_local\ntarget_vendor=\"unknown\"\nub_checks\nunix\n","stderr":""},"16938275954012004043":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.a\n/home/zxq5/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu\noff\n___\ndebug_assertions\nfmt_debug=\"full\"\noverflow_checks\npanic=\"abort\"\nproc_macro\nrelocation_model=\"static\"\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"\"\ntarget_feature=\"x87\"\ntarget_has_atomic\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_has_atomic_equal_alignment=\"16\"\ntarget_has_atomic_equal_alignment=\"32\"\ntarget_has_atomic_equal_alignment=\"64\"\ntarget_has_atomic_equal_alignment=\"8\"\ntarget_has_atomic_equal_alignment=\"ptr\"\ntarget_has_atomic_load_store\ntarget_has_atomic_load_store=\"16\"\ntarget_has_atomic_load_store=\"32\"\ntarget_has_atomic_load_store=\"64\"\ntarget_has_atomic_load_store=\"8\"\ntarget_has_atomic_load_store=\"ptr\"\ntarget_os=\"none\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nub_checks\n","stderr":"warning: target feature `sse2` must be enabled to ensure that the ABI of the current target can be implemented correctly\n |\n = note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!\n = note: for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>\n\nwarning: dropping unsupported crate type `dylib` for target `../customos`\n\nwarning: dropping unsupported crate type `cdylib` for target `../customos`\n\nwarning: dropping unsupported crate type `proc-macro` for target `../customos`\n\nwarning: 4 warnings emitted\n\n"}},"successes":{}}
-3
View File
@@ -1,3 +0,0 @@
Signature: 8a477f597d28d172789f06886806bc55
# This file is a cache directory tag created by cargo.
# For information about cache directory tags see https://bford.info/cachedir/
View File
@@ -1 +0,0 @@
{"rustc":5637828655848808591,"features":"[\"compiler-builtins\", \"core\", \"default\", \"mem\", \"rustc-dep-of-std\"]","declared_features":"[\"c\", \"cc\", \"compiler-builtins\", \"core\", \"default\", \"mangled-names\", \"mem\", \"no-asm\", \"no-f16-f128\", \"public-test-deps\", \"rustc-dep-of-std\"]","target":5408242616063297496,"profile":15657897354478470176,"path":1296201966205883023,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/compiler_builtins-96bb72fd3eed954b/dep-build-script-build-script-build","checksum":false}}],"rustflags":[],"config":2069994364910194474,"compile_kind":0}
@@ -1 +0,0 @@
This file has an mtime of when this was started.
@@ -1 +0,0 @@
{"rustc":5637828655848808591,"features":"[]","declared_features":"[]","target":5408242616063297496,"profile":8731458305071235362,"path":11588123521703303381,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/foundryos_kernel-4c0b4334571dcf0e/dep-build-script-build-script-build","checksum":false}}],"rustflags":[],"config":2069994364910194474,"compile_kind":0}
@@ -1 +0,0 @@
This file has an mtime of when this was started.
@@ -1,6 +0,0 @@
/home/zxq5/Projects/OSDev/FoundryOS/kernel/./target/debug/build/compiler_builtins-96bb72fd3eed954b/build_script_build-96bb72fd3eed954b: /home/zxq5/.cargo/bin/registry/src/index.crates.io-1949cf8c6b5b557f/compiler_builtins-0.1.146/build.rs /home/zxq5/.cargo/bin/registry/src/index.crates.io-1949cf8c6b5b557f/compiler_builtins-0.1.146/configure.rs
/home/zxq5/Projects/OSDev/FoundryOS/kernel/./target/debug/build/compiler_builtins-96bb72fd3eed954b/build_script_build-96bb72fd3eed954b.d: /home/zxq5/.cargo/bin/registry/src/index.crates.io-1949cf8c6b5b557f/compiler_builtins-0.1.146/build.rs /home/zxq5/.cargo/bin/registry/src/index.crates.io-1949cf8c6b5b557f/compiler_builtins-0.1.146/configure.rs
/home/zxq5/.cargo/bin/registry/src/index.crates.io-1949cf8c6b5b557f/compiler_builtins-0.1.146/build.rs:
/home/zxq5/.cargo/bin/registry/src/index.crates.io-1949cf8c6b5b557f/compiler_builtins-0.1.146/configure.rs:
@@ -1,5 +0,0 @@
/home/zxq5/Projects/OSDev/FoundryOS/kernel/./target/debug/build/foundryos_kernel-4c0b4334571dcf0e/build_script_build-4c0b4334571dcf0e: kernel/build.rs
/home/zxq5/Projects/OSDev/FoundryOS/kernel/./target/debug/build/foundryos_kernel-4c0b4334571dcf0e/build_script_build-4c0b4334571dcf0e.d: kernel/build.rs
kernel/build.rs:
+31
View File
@@ -0,0 +1,31 @@
{
"llvm-target": "x86_64-unknown-none",
"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",
"arch": "x86_64",
"target-endian": "little",
"target-pointer-width": "64",
"target-c-int-width": "32",
"os": "none",
"executables": true,
"linker-flavor": "ld.lld",
"linker": "rust-lld",
"panic-strategy": "abort",
"disable-redzone": true,
"features": "-mmx,-sse,+soft-float",
"rustc-abi": "x86-softfloat",
"relocation-model": "static",
"code-model": "kernel",
"pre-link-args": {
"ld.lld": [
"--script=kernel/linker.ld",
"-nostdlib",
"--no-dynamic-linker",
"-static",
"--no-pie",
"--gc-sections",
"--build-id=none",
"-z",
"max-page-size=0x1000"
]
}
}
Submodule
+1
Submodule lib/lib_alloc added at af814bf2ab
Submodule lib/lib_application added at 4b1c60676a
Submodule
+1
Submodule lib/lib_ascii added at 70d528b2e8
Submodule lib/lib_framebuffer added at 53553278d1
+1
Submodule lib/lib_serial added at ed2fa6b501
+4
View File
@@ -0,0 +1,4 @@
[toolchain]
channel = "nightly"
components = ["rust-src", "llvm-tools-preview", "rustfmt", "clippy"]
targets = ["x86_64-unknown-none"]
Executable
+186
View File
@@ -0,0 +1,186 @@
#!/bin/bash
# Colors
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
BOLD='\033[1m'
NC='\033[0m' # No Color
# Error handling
set -e
trap 'echo -e "${RED}${BOLD}error${NC}: build failed" >&2' ERR
# Get absolute path to project root
script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
project_root=$(cd "$script_dir/.." &>/dev/null && pwd)
# Logging functions
info() {
echo -e "${BLUE}${BOLD}info${NC}: $1"
}
compiling() {
echo -e "${GREEN}${BOLD}Compiling${NC}: $1"
}
warning() {
echo -e "${YELLOW}${BOLD}warning${NC}: $1" >&2
}
building() {
echo -e "${GREEN}${BOLD}Building${NC}: $1"
}
copying() {
echo -e "${GREEN}${BOLD} Copying${NC}: $1 to $2"
}
error() {
echo -e "${RED}${BOLD}error${NC}: $1" >&2
exit 1
}
copy_file() {
copying $1 $2
cp "$1" "$2" || error $3
}
build_dir="$project_root/build"
iso_root="$build_dir/iso_root"
# Check if we're running tests
is_test=0
if [[ $1 == *"deps"* ]]; then
is_test=1
kernel_path="$1"
else
# Build the kernel normally
cd "$project_root"
# cargo build
kernel_path="$build_dir/target/x86_64-kernel/debug/kernel"
fi
# Check for required tools
check_tools() {
local missing=0
for tool in xorriso git qemu-system-x86_64; do
if ! command -v $tool >/dev/null 2>&1; then
error "required tool '$tool' is not installed"
missing=1
fi
done
if [ $missing -eq 1 ]; then
error "missing required tools"
fi
}
# Create build directory structure
info "Creating build directory structure"
mkdir -p "$iso_root/boot/limine"
mkdir -p "$iso_root/EFI/BOOT"
# Clone Limine if needed
if [ ! -d "$build_dir/limine" ]; then
compiling "limine bootloader"
cd "$build_dir"
git clone https://github.com/limine-bootloader/limine.git --branch=v9.x-binary --depth=1 "$build_dir/limine" || error "failed to clone limine"
make -C "$build_dir/limine" || error "failed to build limine"
cd "$project_root"
fi
# Copy files
info "Copying files to ISO root"
copy_file "$kernel_path" "$iso_root/boot/kernel" "failed to copy kernel"
copy_file "$project_root/config/limine.conf" "$iso_root/boot/limine/limine.conf" "failed to copy limine config"
copy_file "$build_dir/limine/limine-bios-cd.bin" "$iso_root/boot/limine/" "failed to copy limine-bios-cd.bin"
copy_file "$build_dir/limine/limine-uefi-cd.bin" "$iso_root/boot/limine/" "failed to copy limine-uefi-cd.bin"
copy_file "$build_dir/limine/limine-bios.sys" "$iso_root/boot/limine/" "failed to copy limine-bios.sys"
copy_file "$build_dir/limine/BOOTX64.EFI" "$iso_root/EFI/BOOT/" "failed to copy BOOTX64.EFI"
copy_file "$build_dir/limine/BOOTIA32.EFI" "$iso_root/EFI/BOOT/" "failed to copy BOOTIA32.EFI"
# Create ISO
building "bootable ISO image"
xorriso -as mkisofs -R -r -J -b boot/limine/limine-bios-cd.bin \
-no-emul-boot -boot-load-size 4 -boot-info-table -hfsplus \
-apm-block-size 2048 --efi-boot boot/limine/limine-uefi-cd.bin \
-efi-boot-part --efi-boot-image --protective-msdos-label \
"$iso_root" -o "$build_dir/image.iso" || error "failed to create ISO"
# Install Limine
info "Installing Limine bootloader"
"$build_dir/limine/limine" bios-install "$build_dir/image.iso" || error "failed to install limine"
# Check if KVM is available
if [ "${KVM_FLAG:-enable}" = "disable" ]; then
warning "KVM acceleration disabled by user"
kvm_flag=""
elif [ -c "/dev/kvm" ] && [ -w "/dev/kvm" ]; then
info "KVM acceleration enabled"
kvm_flag="-enable-kvm"
else
warning "KVM acceleration not available (is kvm module loaded?)"
kvm_flag=""
fi
# Check if we're running in debug mode
if [[ "$(cargo metadata --format-version=1 | jq -r '.workspace_members[0]' | cut -d' ' -f2)" == "(debug)" ]]; then
debug_flags="-s -S"
else
debug_flags=""
fi
# Set up test-specific flags
if [ $is_test -eq 1 ]; then
test_flags="-device isa-debug-exit,iobase=0xf4,iosize=0x04 -display none"
serial_flags="-serial stdio"
else
test_flags=""
# serial_flags="-serial tcp:127.0.0.1:1234,server -monitor telnet:127.0.0.1:1235,server"
serial_flags="-serial stdio"
fi
# Run in QEMU
if [[ ${QEMU_FLAGS} == *-S* ]]; then
info "Running OS in QEMU with GDB debugging enabled"
info "To connect GDB, run: gdb"
info "At the GDB prompt, type: target remote localhost:1234"
else
info "Running OS in QEMU..."
fi
check_test_res() {
qemu_exit_code=$?
if [ $qemu_exit_code -eq 33 ]; then
# Success case (0x10 << 1) | 1 = 33
info "All tests passed"
exit 0
elif [ $qemu_exit_code -eq 35 ]; then
# Failure case (0x11 << 1) | 1 = 35
warning "Some tests failed"
exit 1
else
# Any other exit code is treated as a failure
warning "Some tests failed"
exit 1
fi
}
kvm_flag=""
trap 'check_test_res "tests completed"' ERR
cd "$project_root"
qemu-system-x86_64 -M q35 \
${kvm_flag} \
-cdrom "$build_dir/image.iso" \
-boot d \
-m 2G \
${serial_flags} \
-no-reboot \
${test_flags} \
${debug_flags} \
${QEMU_FLAGS:-}