4 ms·
It's my first post. I'd appreciate your feedback :)
by micouay 6y ago
It's my first post. I'd appreciate your feedback :)
- messe 6y agoHey, just a couple of points 1. Don't link the bootsector and the rest of your binary together. It's more trouble than it's worth, and if you ever progress to loading off a filesystem, then you won't be linking them together anyway. 2. You can use LBA addressing in real mode with int 13h (just specify a hard disk rather than a floppy when booting): https://wiki.osdev.org/ATA_in_x86_RealMode_(BIOS)#LBA_in_Extended_Mode https://wiki.osdev.org/ATA_in_x86_RealMode_(BIOS)#LBA_in_Ext... 3. You need to switch to protected mode, set up paging, and then enter long mode. 4. I'd recommend compiling your rust code to an ELF binary, and then using objcopy to create a binary: objcopy -O binary $input.elf $output.bin Alternatively, ELF isn't that hard to parse, so you could load it yourself and then copy sections to the right locations with your bootsector. 5. OSDev.org is your friend. Maybe get a C-based kernel running first, as the toolchain when dealing with freestanding code is a lot friendlier for beginners - https://wiki.osdev.org/Protected_Mode https://wiki.osdev.org/Protected_Mode - https://wiki.osdev.org/Long_Mode#Long_Mode https://wiki.osdev.org/Long_Mode#Long_Mode You might be better off starting with 32-bit rust code instead, in order to avoid paging and long mode at first (you'll still need to switch to protected mode)
- steveklabnik 6y agoI am extremely biased, but I’ve always found the rust tool chain far easier than the C ones, especially as a Windows user. No need to set up a cross compiler, given that rustc already is one, and is easy to add more targets to via the JSON target spec.
- messe 6y agoA cross compiler is easy enough to set up with clang too (just specify the -target command line option). I just think that when starting out in kernel development, you're likely going to be dealing with linker scripts for likely the first time. It's been a while since I tried rust for this, but C generates pretty clean object files, so the linker scripts from the OSDev wiki can often be copied verbatim.
- steveklabnik 6y agoThat’s fair re:clang, seems like gcc is used way more often in tutorials. I don’t think that the linker script stuff ends up different but it’s been a minute since I started from scratch.
- micouay 6y agoThanks! 1. I have a Makefile that links it for me so I don't have to do anything special. I intend the Rust program to work like a second stage bootloader. I'm going to experiment with it and try to get a file system working to load an actual kernel from a file. 2. I'll look into that. 3. That's what the bootloader does. Sorry if I wasn't clear. 4. If I understand correctly if I compile my Rust project to a binary (which is a default output and I don't really understand why I would use objcopy for that) I won't be able to link with with the bootloader. I link them to allow the bootloader to jump to the _start function at the correct address. 5. My Rust program already works in 64-bit so I don't see a reason to change it. In this project I want to explore low level programming and understand things like paging. I appreciate your feedback.
- saagarjha 6y ago(Hacker News likes two eat single newlines. Try using two.)
- steveklabnik 6y agoFull reference here: https://news.ycombinator.com/formatdoc https://news.ycombinator.com/formatdoc
- kens 6y agoInteresting post. I apologize for this feedback but there's a typo "begginer" in the first paragraph. Also "form 1970s" should be "from".
- sowbug 6y agoI think there's a typo in the final screenshot. It looks like your original code outputs "RM" (maybe "real mode" or "hello Rust" in a different language?), but the example source seems like it should output "HR." That or I'm very confused.
- spencerwgreene 6y agoThe HR is in the top left, it overwrites the pre-initialized text console.
- sowbug 6y agoThanks, I see it now!
- micouay 6y agoSorry for that. I thought it would be visible enough in red. RM, LM and PM were printed by the bootloader.