-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Tracking Issue for Second Edition #360
Comments
Do you have any plans to re-implement the kernel code in 100% Rust? I noticed that redox manages to use only Rust for kernel code and thought that might be a good goal for the second edition. Note that there are a dozen calls to the asm! macro in their kernel. And thank you for the work you've put into the blog! It's been so helpful for both getting me started with a Rust kernel and teaching OSDev in general! |
Thanks, glad to hear!
Yes, I even plan to write the bootloader in inline assembly, so that you don't need any other tools to build a bootable disk image (CD images are harder, but maybe we will support that too). The only non-Rust tools we will need are a linker (though I hope that the LLVM linker lld is shipped with the Rust compiler soon) and binutils (stuff like objdump or gdb; we only need it for debugging). |
This would be super awesome, I literally can't wait for it. |
Do you have any plans to put the kernel in the higher half? It's not too hard to do (albeit very easy to get wrong), it's something that isn't terribly well-documented for 64-bit, and it keeps you honest about physical and virtual addresses. |
I also think a higher-half design would teach a lot more. I've come across a few bugs in the tutorial code from where physical and virtual addresses got sort of mixed up (due to the identity mapping, these weren't picked up on I'm guessing) and it would set us up nicely for user-land programming! |
That's a good idea, thanks for the suggestion. I added it to the list. |
I looked into #368 more and determined that it it will be a long time before it can be implemented for The issue is simply that 64-bit x86 javascript emulators do not exist yet. The most mature js emulator I could find is v86, which only supports 32 bit. The maintainer has no immediate plans to implement 64 bit, but the maintainer is working on a WebAssembly port that will make it possible to support 64 bit mode later. I still believe that a javascript emulator has value, but it's clear that it won't be relevant to this project for a while. Maybe I'll write one in Rust so we can implement it for |
One other thing: the blog currently recommends It appears to be simple enough to add them (one macro invocation each) but there may be a good reason for not doing that which I don't know because I'm way out of my depth; in the event it's just that simple, I have a patch ready to go. |
@robert-w-gries Thanks for the update! The lack of 64-bit support is a pity. So I guess we have to wait for the web assembly port. @ketsuban I think you're right that including compiler_builtins is the better solution, I added it to the list. I don't know about the |
I made some progress on the inline assembly bootloader: https://github.com/phil-opp/rustboot-x86. It is still in its early stages, but it already switches to long mode and loads and parses an ELF binary. The next step is to generate page tables to map the kernel to its desired addresses (you will be able to put the kernel to any address you like, including the higher half). After that, we can set up a stack, switch page tables, and jump to the kernel entry point. Unfortunately, we are not done after that. Our kernel needs some information from the BIOS (most importantly a physical memory map) and this information can be only retrieved from the BIOS in real mode. So we need to create some kind of boot information structure, similar to what GRUB does. |
Are you planning on also writing blog posts on how to write the boot loader from scratch, or just have readers use that crate? Personally I would be interested in reading and implementing it myself, but I could imagine some readers wouldn’t be very interested, since it is a lot of assembly code. |
I plan to do it similar to the exceptions posts: A mainline post that just uses the crate and an optional post that explains how it works behind the scenes. |
More bootloader progress: I created a tool named bootimage that does the following:
It is used like this:
The "Hello World!" output comes from the kernel, the other output from the bootloader. The next step is to create a physical memory map and pass it to the kernel. Then I plan to write the corresponding blog posts (first the mainline post that just uses the crate, and then the posts that explain how it works behind the scenes). |
Time for new status update:
|
The first two posts of the second edition landed yesterday in #385! They are published in beta mode (not linked from the front page) at https://os.phil-opp.com/second-edition now. Please take a look and tell me what you think :). Oh, and LLD is very close to be shipped with rustc: rust-lang/rust#48125. As soon as it's in nightly, I plan to add a link to the second edition from the front page and post it to reddit etc. |
Awesome! I have a bunch of CS homework due on Monday, I’ll take a look at these probably on Tuesday. I’ll be a guinea pig and see how well I can follow along.
… On Feb 11, 2018, at 4:38 AM, Philipp Oppermann ***@***.***> wrote:
The first two posts of the second edition landed yesterday in #385 <#385>! They are published at https://os.phil-opp.com/second-edition <https://os.phil-opp.com/second-edition> now. Please take a look and tell me what you think :).
Oh, and LLD is very close to be shipped with rustc: rust-lang/rust#48125 <rust-lang/rust#48125>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#360 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AEiDhCrKkbznhVDoK5f6CppCoKyHjFa5ks5tTt8ugaJpZM4P-zUe>.
|
Hi Phil, I just read over the first article of the second edition, and wrote down nitpicks that I noticed while reading. I wasn't sure how to properly review since stuff was already checked in, so I created a pull request at #389. I didn't try the code though, just read the article. Great work! Cheers, |
@donald-pinckney Thanks, looking forward to your feedback! @andre-richter Thanks a lot! |
390: Nitpicks for second article r=phil-opp a=andre-richter Some nitpick corrections for #360. I am not sure if I understood the following sentence correctly: `- The standard is written for the C programming language. That means lots of C-typical structures are present, such as linked lists in the [boot information].` In its original form it was not really clear what is meant here. I tried to guess and correct in that way, but briefly glancing over the linked boot information, I was not able to spot linked lists 😕
Just went through the first page and code, and it worked great (I'm on macOS 10.13). The only writing nitpick that I found after @andre-richter's merge was:
Maybe it isn't a typo, but it didn't make sense: perhaps derive has too much overloaded meaning for me via |
The second page and code also went swimmingly for me, except for one problem #391 (I need Overall this so far seems much cleaner and more enjoyable than all the GRUB stuff from before, and the
I suppose that it downloads the bootloader, and then somehow combines it with the build executable from xargo to automatically make an image that includes both the bootloader and the executable, but how does the bootloader find the entry point of our executable? I know the point is not to get distracted with too much bootloader stuff in this post, and keeping Great work on all of this so far! |
@donald-pinckney Thanks a lot for the feedback!
Awesome! Glad to hear that!
Very good point. I definitely don't want the posts to become too magical!
It first loads the kernel ELF file into memory and parses it. It then maps each segment to the specified virtual address in a new page table (including the correct read/write/execute bits). The entry point address is stored in the ELF file too, so the bootloader can just jump to it (after doing a address space switch to the new page table). I try to add a similar high-level explanation to the post. |
Is there a clean way that a reader of the series can start from the second edition and transition into implementing features from the first edition of the blog? It seems like that could be an effective holdover until the entire second edition is completed, since there's already so much valuable content! |
Yeah, this is very confusing. |
Maybe you need to restart your shell or something? |
No effect. |
@phil-opp appveyor is using |
@retep998 Seems like I posted the wrong link above. Appveyor is set up to test on msvc as well and it's green too: https://ci.appveyor.com/project/phil-opp/blog-os/build/1.0.134 |
In that case I have absolutely no idea. |
so i installed the mingw version just to ensure that that worked, and > rustup run nightly-x86_64-pc-windows-gnu bootimage --target intermezzos
Compiling core v0.0.0 (file:///C:/Users/steve/.rustup/toolchains/nightly-x86_64-pc-windows-gnu/lib/rustlib/src/rust/src/libcore)
Finished release [optimized] target(s) in 37.10 secs
Compiling intermezzos v0.1.0 (file:///C:/Users/steve/src/intermezzos/kernel-ng)
error: linker `lld` not found
|
= note: The system cannot find the file specified. (os error 2)
So, now i have no idea. |
|
It's needed for the (I tried to only modify the |
Ok, I uninstalled all versions of |
Add |
alex says this is supposed to work, or at least, it is intended to. he's trying to repro locally now. |
The output:
And on travis:
Oh well, seems like appveyor and travis have it in their default path now. I had an earlier build where it couldn't find lld, but it seems like I just used the wrong command ( |
Awesome! Let me know if I can help somewhere! |
I have good news and bad news. Good news: this is intended to work! Bad news:
So yeah. Not sure what strategy we should pursue here. |
Thanks! Makes perfect sense. The only thing I don't quite understand is why I'm going to revert #395 for now until we have a solution. |
alex says:
|
The issue was fixed in japaric/xargo#200, so I re-applied the LLD change in #400. I also wrote a news post and mentioned the second edition on the front page in #401. |
Hey all! About the emulator. I had an idea. Could we use v86, run something like Tiny Core Linux, and then use that to compile the source from the part of the post. Inside of the VM, we could run |
That sounds like it would be very slow, but it could work. |
Sounds interesting! |
Just tested the Docker image, it appears to work from Windows 10 Pro but I had to figure it out and remove the entrypoint from the Dockerfile because I was getting error message supposedly about linebreaks difference in dos/unix. But at the end it booted blog_os in the container successfully(!)
...wait a while...
now clone the blog_os
Success: |
@montao Thanks for testing! I marked it as done in the issue description. |
With the release of the Allocator Designs post, we can finally tick the last missing item from this issue:
At this point, all the content from the first edition that I wanted to keep is now also available in some form in the second edition. So I think we can finally close this issue :). |
Re "javascript emulator": unicorn.js seems to support x86_64. I believe it doesn't support any devices out of the box though. Unicorn does allow you to modify all internal state, so it should be possible to emulate devices. |
Interesting! I don't have the time to look into this at the moment, but I'll keep it in mind. |
Create a second edition of the blog, which reorders the posts (exceptions before page tables) and uses an own bootloader. This should make the posts easier to follow.
Edit: This issue will serve as a tracking issue. The “Second Edition” milestone contains all associated issues and pull requests.
Planned high-level changes
x86_64
cratex86_64
crate very well and ecourage readers to look at itFurther changes
[ ] Put the kernel in the higher half of the address space (see Tracking Issue for Second Edition #360 (comment))maybe sometimes in the future when we introduce linker scriptsOther planned things
rustfmt-nightly
so that the code always has standard format. Check formatting via travis.Maybe
[ ] Use a javascript emulator in blog posts (Use javascript emulator in blog posts #368)Postponed, since there is no 64-bit js emulator yet(This list is far from complete and will be extended over time.)
The text was updated successfully, but these errors were encountered: