Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
639389e
fixed stupid bug, struct was not repr C
sagi21805 Dec 5, 2025
f24380a
Added ahci base address register
sagi21805 Dec 5, 2025
0820165
added custom runner and build script
sagi21805 Dec 5, 2025
3779d12
added basic simplified flag macros for flags on ahci
sagi21805 Dec 6, 2025
2924a96
added part of the configuration of ahci
sagi21805 Dec 6, 2025
5463c2a
updated word list
sagi21805 Dec 6, 2025
6f760c6
fixed super dump bug where the last mapping would be of the table ins…
sagi21805 Dec 8, 2025
7a0de3d
removed wrong reading of base address.
sagi21805 Dec 8, 2025
a141848
added correct reading of address from bars, and corrected the scan of…
sagi21805 Dec 8, 2025
9508723
added the ahci device that is used on qemu
sagi21805 Dec 8, 2025
e06cf60
added io flags
sagi21805 Dec 8, 2025
f17b1e0
printed version of ahci!
sagi21805 Dec 8, 2025
b1b2832
updated machine chipset
sagi21805 Dec 8, 2025
a44c0d9
added port structures, still without implementations
sagi21805 Dec 9, 2025
5cc2160
printed generation of ahci driver
sagi21805 Dec 9, 2025
e496f3a
added num-enum for clean enum syntax
sagi21805 Dec 10, 2025
96c8334
added anchors
sagi21805 Dec 10, 2025
e8d9bba
added more struct implementations and optimized bit shifts with compi…
sagi21805 Dec 10, 2025
4007f2f
more ahci implementation
sagi21805 Dec 11, 2025
46e579c
minimal test to see available ports
sagi21805 Dec 11, 2025
72698e7
added flag for huge io pages
sagi21805 Dec 11, 2025
d9f1a5c
added num-enum
sagi21805 Dec 11, 2025
876cd18
updated some configuration
sagi21805 Dec 13, 2025
616c4ef
added error enum for ahci
sagi21805 Dec 13, 2025
e8d8b6c
finished initial hba layout configuration
sagi21805 Dec 14, 2025
8562afb
removed second disk with the same file, because of a locking issue tha
sagi21805 Dec 15, 2025
4d41426
added inforamation about fis structres
sagi21805 Dec 15, 2025
c1f21e4
renamed to hba.rs
sagi21805 Dec 16, 2025
11f282f
implemented some fises
sagi21805 Dec 17, 2025
caa599c
included all mode info under this
sagi21805 Dec 17, 2025
23dee20
added Sized trait for Conversion Error
sagi21805 Dec 17, 2025
8b47e45
renamed
sagi21805 Dec 17, 2025
8acb627
used Color enum
sagi21805 Dec 17, 2025
55287c5
added information about recieved fis, cmd table, cmd table entry
sagi21805 Dec 17, 2025
29c58e2
added ata commands
sagi21805 Dec 19, 2025
42479f8
used strum to iterator over variants and fix the map command
sagi21805 Dec 19, 2025
3313694
using expr on alloc pages
sagi21805 Dec 19, 2025
ee03993
used ata command instead of u8 on fis
sagi21805 Dec 19, 2025
2d16399
wrote alloc a bit nicer
sagi21805 Dec 19, 2025
5fcb090
created another util functions for the hba and for mapping the ports
sagi21805 Dec 19, 2025
24d39e2
wrote nicer
sagi21805 Dec 19, 2025
880d8c4
Can now create, probe and generate an AhciDeviceController!
sagi21805 Dec 19, 2025
9646fc4
updated ahci controller, corrently hangs on the stop command, maybe
sagi21805 Dec 20, 2025
26b1356
fixed stupid bug where flags weren't volatile and the compiler optimzed
sagi21805 Dec 21, 2025
4c69fdf
attempted to read identity packet from the disk, probably should do a
sagi21805 Dec 21, 2025
c6560ef
added alignment and change port cmd ptr to be physicall address instead
sagi21805 Dec 22, 2025
655075b
change pic to not be uninit
sagi21805 Dec 22, 2025
c9f2d33
included in the pci devic the bus, device and funciton number of the
sagi21805 Dec 22, 2025
64103cb
temp change to initial mapping to be io one
sagi21805 Dec 22, 2025
e9f22b9
changed unset to also be volatile
sagi21805 Dec 22, 2025
78472fc
corrected false resolve, added set_flags function for a given address
sagi21805 Dec 22, 2025
b0e1441
added informational prints
sagi21805 Dec 22, 2025
f4be72e
updated zed settings
sagi21805 Dec 22, 2025
c030c51
set interrupt handler, but it didn't trigger
sagi21805 Dec 23, 2025
1cb868c
correction of spelling
sagi21805 Dec 24, 2025
f8d1b2d
fixed find_available_page function
sagi21805 Dec 24, 2025
768ed98
renamed and added doc
sagi21805 Dec 24, 2025
bef5611
added a function to get the index in the table of an entry
sagi21805 Dec 24, 2025
16dec01
dump commit of working command sending
sagi21805 Dec 26, 2025
caa31a8
commited changes before rebase
sagi21805 Dec 30, 2025
94905e1
started writing buddy allocator
sagi21805 Dec 30, 2025
ebb3c7e
added some buddy allocator data
sagi21805 Jan 1, 2026
93abeb6
implement initialization for page map
sagi21805 Jan 1, 2026
dbc2b61
implemented deref and derefmut
sagi21805 Jan 1, 2026
6137774
added simple init to the buddy allocator
sagi21805 Jan 3, 2026
ee9d9d9
added multiple util functions for the page allocator
sagi21805 Jan 3, 2026
3cdd0ac
renamed
sagi21805 Jan 3, 2026
5725b3d
added a file for the buddy order enum
sagi21805 Jan 3, 2026
ac8aafd
finished untested implementation of buddy allocator
sagi21805 Jan 4, 2026
648868c
fixed some bugs on buddy allocator, still has some to fix
sagi21805 Jan 5, 2026
95c390e
mapped more memory so the buddy allocator would be happy.
sagi21805 Jan 5, 2026
f35c51d
fixed stupid bugs on the buddy allocation, seems to work now.
sagi21805 Jan 7, 2026
40415ee
slight changes
sagi21805 Jan 8, 2026
1d01045
fixed a bug where the found half of a page would be wrong on a split
sagi21805 Jan 9, 2026
914c174
currently disabled scan because allocator is not implemented on the b…
sagi21805 Jan 9, 2026
4ec0bad
separated buddy allocator to a different file
sagi21805 Jan 9, 2026
8a21efa
used buddy allocator instead of the bitmap allocator
sagi21805 Jan 9, 2026
29a186f
separated late init into a different file
sagi21805 Jan 9, 2026
69cf55f
added some of the slab allocator structures
sagi21805 Jan 10, 2026
143b456
added slab structs
sagi21805 Jan 11, 2026
5c73aa5
added an alloc function and used nonmax crate
sagi21805 Jan 11, 2026
ecf0701
added default trait implementation
sagi21805 Jan 12, 2026
8963857
derived copy and clone for unassigned
sagi21805 Jan 12, 2026
c717c9a
added utility function and moved references into nonnull pointers
sagi21805 Jan 12, 2026
9af1cc8
added a macro to generate slabs, slab array, and position trait.
sagi21805 Jan 13, 2026
d7b295e
remove slab caches union as it is not needed, and added assign and un…
sagi21805 Jan 13, 2026
fd8775f
Changed T to implement SlabPosition
sagi21805 Jan 14, 2026
8c2a249
more progress!
sagi21805 Jan 14, 2026
c69a8bb
split slab allocation into files for organization and fixed paths tha…
sagi21805 Jan 14, 2026
28ce7b8
added generic slab types
sagi21805 Jan 14, 2026
f5417a0
added alloc function
sagi21805 Jan 14, 2026
192f31a
fixed message on debug print
sagi21805 Jan 14, 2026
f628485
added implementation of the init function for all the slabs the are c…
sagi21805 Jan 14, 2026
f172370
changed function name into alloc, and now returns the address without…
sagi21805 Jan 15, 2026
31961c2
removed regular allocator and switched to using nonnull
sagi21805 Jan 17, 2026
7fd37f6
fixed a bug where prev was not treated on next and prev
sagi21805 Jan 17, 2026
19d4f8b
initial draft for fixed initialization of the buddy allocator to igno…
sagi21805 Jan 17, 2026
724c2e7
tests and fixes
sagi21805 Jan 19, 2026
399066f
added some function templates that should be implemented.
sagi21805 Jan 20, 2026
8088b9a
added a macro to generate generic struct and implement the generic tr…
sagi21805 Jan 21, 2026
4adc63a
added macro implementation of the generic structs and traits via macro
sagi21805 Jan 21, 2026
3224d64
changed implementation of the allocator trait to the slab allocator s…
sagi21805 Jan 21, 2026
50336de
added a note on dealloc function
sagi21805 Jan 21, 2026
301171e
changed constant address into the one saved in the static because it …
sagi21805 Jan 22, 2026
7e95dda
moved page map and page meta to their own modules
sagi21805 Jan 23, 2026
cf4dc4f
added assign and unassign traits for slabs
sagi21805 Jan 23, 2026
7781894
changed to full specialization
sagi21805 Jan 24, 2026
637858e
moved functions from page into buddy
sagi21805 Jan 24, 2026
26fffca
added traits
sagi21805 Jan 24, 2026
77589ce
added page flags to slab
sagi21805 Jan 24, 2026
0929350
changed to div ceil
sagi21805 Jan 24, 2026
9b7ad7d
added initi function to here
sagi21805 Jan 24, 2026
c8c44a9
made meta fields public
sagi21805 Jan 24, 2026
c33f194
made allocator virtual address
sagi21805 Jan 24, 2026
1bb6bb4
removed legacy mapping
sagi21805 Jan 24, 2026
d5a4ff8
changed the set flags function to accept page size and number of page…
sagi21805 Jan 25, 2026
ac83bd8
derived copy
sagi21805 Jan 25, 2026
6fcbd7e
used net set flags definition
sagi21805 Jan 25, 2026
9050cfa
added a new slab trait
sagi21805 Jan 28, 2026
fe2358b
added new nightly feature
sagi21805 Jan 28, 2026
ef5fa1f
used new slab trait, and added a grow function
sagi21805 Jan 28, 2026
5afa822
changed name of position into slab_position for clarity
sagi21805 Jan 30, 2026
7e4acba
initialized the page od the initial descriptor in the constructor of …
sagi21805 Jan 30, 2026
305058c
Added some useful functions to translate between virtual address, page
sagi21805 Jan 31, 2026
3d2167c
Change the grow function, and used take_ownership on the initial
sagi21805 Jan 31, 2026
e40432f
improved trait implementation
sagi21805 Jan 31, 2026
5db72a6
added page size field to SlabFlags trait
sagi21805 Jan 31, 2026
b945393
used new functionality
sagi21805 Jan 31, 2026
755d0c0
replaced unassigned with ()
sagi21805 Feb 1, 2026
c55ccee
started implementing a walk function for virtual address
sagi21805 Feb 2, 2026
85ef13c
addde translate and walk function
sagi21805 Feb 2, 2026
7027ade
started changing &'static mut into NonNull
sagi21805 Feb 2, 2026
f8031ab
Changed necessary fields to non_null and the fields that are actually…
sagi21805 Feb 6, 2026
59aab94
Merge pull request #58 from sagi21805/feat/io-mem-alloc
sagi21805 Feb 6, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@ build-std-features = ["compiler-builtins-mem"]
unstable-options = true
[build]
rustflags = ["-Zpolonius"]

[target.'cfg(target_os = "windows")']
runner = ".\\build\\runner\\runner.bat"

[target.'cfg(target_os = "macos")']
runner = ["sh", "./build/runner/runner.sh"]

[target.'cfg(target_os = "linux")']
runner = ["sh", "./build/runner/runner.sh"]
133 changes: 131 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,180 @@
],
"rust-analyzer.cargo.target": "x86_64-unknown-linux-gnu",
"cSpell.words": [
"abar",
"acmd",
"ACPI",
"ACPINVS",
"adse",
"AHCI",
"alhd",
"alpe",
"APIC",
"apst",
"apste",
"avavilable",
"BIST",
"BOHC",
"bootable",
"capslock",
"cardbus",
"cccs",
"cfis",
"clbu",
"CLFSH",
"CMOV",
"CNXT",
"colorcode",
"cpde",
"cpds",
"Cpuid",
"ctba",
"ctbau",
"dbau",
"desciprtor",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Fix typos in spell checker dictionary.

The spell checker dictionary contains misspellings:

  • Line 42: "desciprtor" should be "descriptor"
  • Line 121: "purporse" should be "purpose"

Adding misspellings to the dictionary defeats the purpose of spell checking.

🔎 Proposed fix
-        "desciprtor",
+        "descriptor",
-        "purporse",
+        "purpose",

Also applies to: 121-121

🤖 Prompt for AI Agents
.vscode/settings.json around lines 42 and 121: the spell-check dictionary
contains typos; replace "desciprtor" on line 42 with "descriptor" and replace
"purporse" on line 121 with "purpose" so the dictionary only contains correctly
spelled words.

"deto",
"devsel",
"devslp",
"dhre",
"dhrs",
"dlae",
"dmpe",
"dmps",
"DPIO",
"dsfis",
"DTES",
"dwords",
"EFER",
"EHCI",
"EISA",
"fbscp",
"fbss",
"FDDI",
"firewire",
"freelist",
"FXSR",
"Gameport",
"GPIB",
"hbde",
"hbds",
"hbfe",
"hbfs",
"Hotplug",
"hpcp",
"HPET",
"ilog",
"infe",
"infs",
"inval",
"iopl",
"ipme",
"IPMIPI",
"ipms",
"IRDA",
"ISDN",
"kfree",
"kmalloc",
"lctrl",
"Learnix",
"lgdt",
"ljmp",
"lshift",
"mdat",
"metavar",
"mmap",
"MOVBE",
"mpsp",
"mpss",
"mrsm",
"MTRR",
"Multiport",
"nomem",
"nonmax",
"nostack",
"notif",
"NVME",
"NVMHCI",
"nvmp",
"OHCI",
"okprintln",
"OSXSAVE",
"outb",
"outl",
"PCID",
"PCLMUL",
"PDCM",
"PDPT",
"peekable",
"PICMG",
"PICPI",
"PIIX",
"POPCNT",
"popfq",
"prce",
"prcs",
"prdb",
"Prdt",
"prdtl",
"prefetchable",
"psfis",
"purporse",
"pushfq",
"rdmsr",
"RDRAND",
"realtek",
"repr",
"rfis",
"rflags",
"rodata",
"rshift",
"RTCPI",
"rustc",
"sact",
"sadm",
"safte",
"salp",
"scancode",
"sctl",
"sdbe",
"sdbfis",
"SDBG",
"sdbs",
"SERCOS",
"serr",
"sgpio",
"SMAP",
"SMIC",
"smps",
"snqc",
"sntf",
"sofware",
"sooe",
"ssntf",
"SSSE",
"ssts",
"superkey",
"tfee",
"tfes",
"thiserror",
"udma",
"ufis",
"UHCI",
"Unassignment",
"Uninit",
"USBPI",
"virt",
"virtio",
"wrmsr",
"xchg"
"xchg",
"XHCI",
"XSAVE",
"XTPR"
],
"rust-analyzer.inlayHints.chainingHints.enable": false,
"rust-analyzer.inlayHints.chainingHints.enable": true,
"rust-analyzer.check.command": "clippy",
"rust-analyzer.check.extraArgs": [
"--release"
],
"rust-analyzer.cargo.extraEnv": {
"RUSTFLAGS": "-Zpolonius"
},
Expand Down
60 changes: 54 additions & 6 deletions .zed/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,61 @@
// For a full list of overridable settings, and general information on folder-specific settings,
// see the documentation: https://zed.dev/docs/configuring-zed#settings-files
{
"minimap": {
"display_in": "active_editor",
"show": "always",
},
"inlay_hints": {
"show_background": true,
"enabled": true,
},
"relative_line_numbers": "enabled",
"show_edit_predictions": false,
"terminal": {},
"lsp_document_colors": "inlay",
"indent_guides": {
"coloring": "fixed",
"background_coloring": "disabled",
},
"colorize_brackets": true,
"features": {
"edit_prediction_provider": "zed",
},
"telemetry": {
"diagnostics": true,
"metrics": true,
},
"vim_mode": true,
"icon_theme": {
"mode": "dark",
"light": "Zed (Default)",
"dark": "Material Icon Theme",
},
"base_keymap": "VSCode",
"ui_font_size": 16,
"buffer_font_size": 15,
"theme": {
"mode": "dark",
"light": "One Dark",
"dark": "One Dark Pro",
},
"lsp": {
"rust-analyzer": {
"initialization_options": {
"cargo": {
"target": "x86_64-unknown-linux-none"
}
}
}
}
"inlayHints": {
"maxLength": null,
"lifetimeElisionHints": {
"useParameterNames": true,
},
"closureReturnTypeHints": {
"enable": "always",
},
},
"check": {
"command": "clippy",
"extraArgs": ["--release"],
},
},
},
},
Comment on lines +6 to +62
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove trailing commas to ensure strict JSON compliance.

The static analysis tool flagged trailing commas before closing braces on lines 9, 13, 21, 25, 29, 35, 43, 51, 54, and 59. While Zed may support JSONC (which allows trailing commas), removing them ensures compatibility with strict JSON parsers.

🔎 Proposed fix
   "minimap": {
     "display_in": "active_editor",
-    "show": "always",
+    "show": "always"
   },
   "inlay_hints": {
     "show_background": true,
-    "enabled": true,
+    "enabled": true
   },
   "indent_guides": {
     "coloring": "fixed",
-    "background_coloring": "disabled",
+    "background_coloring": "disabled"
   },
   "features": {
-    "edit_prediction_provider": "zed",
+    "edit_prediction_provider": "zed"
   },
   "telemetry": {
     "diagnostics": true,
-    "metrics": true,
+    "metrics": true
   },
   "icon_theme": {
     "mode": "dark",
     "light": "Zed (Default)",
-    "dark": "Material Icon Theme",
+    "dark": "Material Icon Theme"
   },
   "theme": {
     "mode": "dark",
     "light": "One Dark",
-    "dark": "One Dark Pro",
+    "dark": "One Dark Pro"
   },
         "inlayHints": {
           "maxLength": null,
           "lifetimeElisionHints": {
-            "useParameterNames": true,
+            "useParameterNames": true
           },
           "closureReturnTypeHints": {
-            "enable": "always",
+            "enable": "always"
           },
         },
         "check": {
           "command": "clippy",
-          "extraArgs": ["--release"],
+          "extraArgs": ["--release"]
         },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"minimap": {
"display_in": "active_editor",
"show": "always",
},
"inlay_hints": {
"show_background": true,
"enabled": true,
},
"relative_line_numbers": "enabled",
"show_edit_predictions": false,
"terminal": {},
"lsp_document_colors": "inlay",
"indent_guides": {
"coloring": "fixed",
"background_coloring": "disabled",
},
"colorize_brackets": true,
"features": {
"edit_prediction_provider": "zed",
},
"telemetry": {
"diagnostics": true,
"metrics": true,
},
"vim_mode": true,
"icon_theme": {
"mode": "dark",
"light": "Zed (Default)",
"dark": "Material Icon Theme",
},
"base_keymap": "VSCode",
"ui_font_size": 16,
"buffer_font_size": 15,
"theme": {
"mode": "dark",
"light": "One Dark",
"dark": "One Dark Pro",
},
"lsp": {
"rust-analyzer": {
"initialization_options": {
"cargo": {
"target": "x86_64-unknown-linux-none"
}
}
}
}
"inlayHints": {
"maxLength": null,
"lifetimeElisionHints": {
"useParameterNames": true,
},
"closureReturnTypeHints": {
"enable": "always",
},
},
"check": {
"command": "clippy",
"extraArgs": ["--release"],
},
},
},
},
"minimap": {
"display_in": "active_editor",
"show": "always"
},
"inlay_hints": {
"show_background": true,
"enabled": true
},
"relative_line_numbers": "enabled",
"show_edit_predictions": false,
"terminal": {},
"lsp_document_colors": "inlay",
"indent_guides": {
"coloring": "fixed",
"background_coloring": "disabled"
},
"colorize_brackets": true,
"features": {
"edit_prediction_provider": "zed"
},
"telemetry": {
"diagnostics": true,
"metrics": true
},
"vim_mode": true,
"icon_theme": {
"mode": "dark",
"light": "Zed (Default)",
"dark": "Material Icon Theme"
},
"base_keymap": "VSCode",
"ui_font_size": 16,
"buffer_font_size": 15,
"theme": {
"mode": "dark",
"light": "One Dark",
"dark": "One Dark Pro"
},
"lsp": {
"rust-analyzer": {
"initialization_options": {
"inlayHints": {
"maxLength": null,
"lifetimeElisionHints": {
"useParameterNames": true
},
"closureReturnTypeHints": {
"enable": "always"
}
},
"check": {
"command": "clippy",
"extraArgs": ["--release"]
}
}
}
}
🧰 Tools
🪛 Biome (2.1.2)

[error] 9-9: Expected a property but instead found '}'.

Expected a property here.

(parse)


[error] 13-13: Expected a property but instead found '}'.

Expected a property here.

(parse)


[error] 21-21: Expected a property but instead found '}'.

Expected a property here.

(parse)


[error] 25-25: Expected a property but instead found '}'.

Expected a property here.

(parse)


[error] 29-29: Expected a property but instead found '}'.

Expected a property here.

(parse)


[error] 35-35: Expected a property but instead found '}'.

Expected a property here.

(parse)


[error] 43-43: Expected a property but instead found '}'.

Expected a property here.

(parse)


[error] 51-51: Expected a property but instead found '}'.

Expected a property here.

(parse)


[error] 54-54: Expected a property but instead found '}'.

Expected a property here.

(parse)


[error] 55-55: Expected a property but instead found '}'.

Expected a property here.

(parse)


[error] 59-59: Expected a property but instead found '}'.

Expected a property here.

(parse)


[error] 60-60: Expected a property but instead found '}'.

Expected a property here.

(parse)


[error] 61-61: Expected a property but instead found '}'.

Expected a property here.

(parse)


[error] 62-62: Expected a property but instead found '}'.

Expected a property here.

(parse)

🤖 Prompt for AI Agents
In .zed/settings.json around lines 6 to 62, several object and property entries
contain trailing commas (lines 9, 13, 21, 25, 29, 35, 43, 51, 54, 59) which
violate strict JSON; remove each trailing comma before the corresponding closing
brace or bracket so every object/array member list ends without a comma, then
validate the file with a strict JSON linter or parser to ensure there are no
remaining trailing commas or syntax errors.

}
2 changes: 1 addition & 1 deletion build/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn main() -> io::Result<()> {
"targets/32bit_target.json",
"release",
);
build_stage("../kernel", "targets/64bit_target.json", &profile);
build_stage("../kernel", "targets/64bit_target.json", "release");

// Combine binaries into one image
let input_dir = PathBuf::from("bin");
Expand Down
8 changes: 8 additions & 0 deletions build/runner/runner.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@echo off


qemu-system-x86_64 ^
-M q35 ^
-drive id=disk0,file=build/image.bin,if=none,format=raw ^
-device ide-hd,drive=disk0,bus=ide.0,rotation_rate=1 ^
-monitor stdio
9 changes: 9 additions & 0 deletions build/runner/runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

qemu-system-x86_64 \
-M q35 \
-drive id=disk0,format=raw,file=build/image.bin,if=none \
-drive id=disk1,format=raw,file=build/bin/first_stage,if=none \
-device ide-hd,drive=disk0,bus=ide.0 \
-device ide-hd,drive=disk1,bus=ide.1 \
-monitor stdio
Comment on lines 3 to 9
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

❓ Verification inconclusive

Script executed:

cat -n build/runner/runner.sh

Repository: sagi21805/LearnixOS


Repository: sagi21805/LearnixOS
Exit code: 0

stdout:

     1	#!/bin/sh
     2	
     3	qemu-system-x86_64 \
     4	    -M q35 \
     5	    -drive id=disk0,format=raw,file=build/image.bin,if=none \
     6	    -device ide-hd,drive=disk0,bus=ide.0 \
     7	    -monitor stdio

QEMU ahci controller ide-hd bus attachment disk


Short answer: create an AHCI controller device, create a drive with if=none, then attach it with ide-hd on the controller's channel/bus. Example CLI (replace IMAGE with your file):

  • drive + controller + device example:
    -drive id=disk,file=IMAGE,format=qcow2,if=none
    -device ahci,id=ahci0,multifunction=on,bus=pci.0,addr=0x7
    -device ide-hd,drive=disk,bus=ahci0.0,id=sata0

Notes:

  • Some docs/examples use "ahci.0" instead of "ahci0.0"; the bus name is based on the controller id you pass to -device (here id=ahci0). [1][2][3]

References:
[1] Gentoo Wiki / QEMU AHCI example (via StackOverflow).
[2] QEMU AHCI / -drive if=ahci discussion (qemu-devel mailing list).
[3] Example usage in proxmox/pve and patches showing -device ahci + ide-hd,bus=ahci0.0.


QEMU ide-hd vs sata-hd ahci bus connection


Short answer

  • ide-hd is the legacy IDE/PATA device model (master/slave semantics). sata-hd is the SATA device model intended for AHCI controllers. To get a real AHCI/SATA device on the AHCI controller use sata-hd (or attach a -drive to an AHCI controller). [1][2][3]

Details and practical notes

  • An AHCI port accepts one SATA device (ports 0..5); IDE buses accept two devices (master/slave). Mapping an if=ide/ide-hd onto an AHCI controller can cause confusing unit/bus re‑mapping or make QEMU/guest see the drive as legacy IDE. Q35/ahci behaviour has historically tried to map if=ide drives to AHCI ports (causing addressing/compatibility issues). Use sata-hd (or -device ahci,id=... plus -device sata-hd,bus=ahciX.N,drive=...) when you want a true AHCI/SATA attachment. [2][1][3]

Recommendation

  • For AHCI/SATA: create a -drive id=...,if=none,... then attach with -device sata-hd,drive=,bus=ahci0..
  • For legacy IDE (PIIX/PIIX3): use -device ide-hd (or -drive if=ide) attached to the IDE controller.
  • When using libvirt, be careful with libvirt’s bus/unit -> ahci port mapping (libvirt historically used unit as bus and needs correct bus/unit values). [3]

References
[1] QEMU-devel discussion on AHCI/IDE mapping and limitations.
[2] Patch/discussion explaining how -drive if=ide was mapped to AHCI on q35 (and master/slave vs single-port issues).
[3] QEMU/Xilinx wiki example showing attaching a disk to an AHCI controller with -device sata/ahci.


Wire the disk through an AHCI controller using the correct device type.

Right now the VM attaches the disk via the legacy IDE bus (-device ide-hd,drive=disk0,bus=ide.0), so your AHCI/DMA path may never be tested. To attach a disk to an AHCI controller, use -device sata-hd (not ide-hd, which is a legacy PATA device):

 qemu-system-x86_64 \
     -M q35 \
+    -device ahci,id=ahci0 \
     -drive id=disk0,format=raw,file=build/image.bin,if=none \
-    -device ide-hd,drive=disk0,bus=ide.0 \
+    -device sata-hd,drive=disk0,bus=ahci0.0 \
     -monitor stdio

The original suggestion to attach ide-hd to an AHCI bus will not properly exercise the AHCI driver; sata-hd is the correct device model for AHCI attachment.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
qemu-system-x86_64 \
-M q35 \
-drive id=disk0,format=raw,file=build/image.bin,if=none \
-device ide-hd,drive=disk0,bus=ide.0 \
-monitor stdio
qemu-system-x86_64 \
-M q35 \
-device ahci,id=ahci0 \
-drive id=disk0,format=raw,file=build/image.bin,if=none \
-device sata-hd,drive=disk0,bus=ahci0.0 \
-monitor stdio
🤖 Prompt for AI Agents
In build/runner/runner.sh around lines 3 to 7 the disk is attached as a legacy
IDE device (ide-hd) so the AHCI/DMA path won’t be exercised; replace the IDE
setup with an AHCI controller and attach the disk using the correct SATA device
model (create an AHCI controller, e.g. -device ahci,id=ahci and attach the drive
with -device sata-hd,drive=disk0,bus=ahci.0) so the VM uses the AHCI path
instead of legacy PATA.

7 changes: 6 additions & 1 deletion build/targets/64bit_target.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
"position-independent-executables": true,
"relro-level": "off",
"stack-probes": {
"kind": "call"
"kind": "inline-or-call",
"min-llvm-version-for-inline": [
16,
0,
0
]
},
"static-position-independent-executables": true,
"target-pointer-width": 64,
Expand Down
6 changes: 6 additions & 0 deletions kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,11 @@ cpu_utils = { path = "../shared/cpu_utils" }
derive_more = { version = "2.0.1", default-features = false, features = [
"full",
] }
num_enum = { version = "0.7.5", default-features = false, features = [
"complex-expressions",
] }
extend = "1.2.0"
learnix-macros = { path = "../learnix-macros" }
strum_macros = { version = "0.27", default-features = false }
strum = { version = "0.27", default-features = false }
nonmax = { version = "0.5.5", default-features = false }
Loading