From 6eba03dd5881f69140e5a23ae420f3700277eb35 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Tue, 27 Sep 2016 13:24:01 +0200 Subject: [PATCH 1/3] Update bit_field to 0.5.0 and use new API --- Cargo.toml | 2 +- src/interrupts/idt.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e658a294..5d8c70e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ name = "blog_os" version = "0.1.0" [dependencies] -bit_field = "0.1.0" +bit_field = "0.5.0" bitflags = "0.7.0" once = "0.3.2" rlibc = "0.1.4" diff --git a/src/interrupts/idt.rs b/src/interrupts/idt.rs index 810a38a1..668c3ba5 100644 --- a/src/interrupts/idt.rs +++ b/src/interrupts/idt.rs @@ -66,11 +66,11 @@ impl Entry { use bit_field::BitField; #[derive(Debug, Clone, Copy)] -pub struct EntryOptions(BitField); +pub struct EntryOptions(u16); impl EntryOptions { fn minimal() -> Self { - let mut options = BitField::new(0); + let mut options = 0; options.set_range(9..12, 0b111); // 'must-be-one' bits EntryOptions(options) } From 2639a46a5e67fb60764fa92b1205f2546262fb80 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Tue, 27 Sep 2016 13:24:43 +0200 Subject: [PATCH 2/3] Reorder items to cargo-edit format --- Cargo.toml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5d8c70e1..71f35bcf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,10 @@ spin = "0.3.4" [dependencies.hole_list_allocator] path = "libs/hole_list_allocator" +[dependencies.lazy_static] +features = ["spin_no_std"] +version = "0.2.1" + [dependencies.multiboot2] git = "https://github.com/phil-opp/multiboot2-elf64" @@ -20,17 +24,15 @@ git = "https://github.com/phil-opp/multiboot2-elf64" default-features = false version = "0.7.1" -[dependencies.lazy_static] -version = "0.2.1" -features = ["spin_no_std"] - [lib] crate-type = ["staticlib"] -[workspace] +[profile] [profile.dev] panic = "abort" [profile.release] panic = "abort" + +[workspace] From 4db15a7e80a76f54ea7f76f53ac3535a5c179dcd Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Tue, 27 Sep 2016 13:25:03 +0200 Subject: [PATCH 3/3] Update post to new bit_field code --- blog/post/09-catching-exceptions.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/blog/post/09-catching-exceptions.md b/blog/post/09-catching-exceptions.md index 11d70757..40ee25fe 100644 --- a/blog/post/09-catching-exceptions.md +++ b/blog/post/09-catching-exceptions.md @@ -146,7 +146,7 @@ Or: self.0 = ((self.0 >> 3) << 3) | stack_index; ``` -Well, none of these variants is really _readable_ and it's very easy to make mistakes somewhere. Therefore I created a `BitField` type with the following [Range]-based API: +Well, none of these variants is really _readable_ and it's very easy to make mistakes somewhere. Therefore I created a `BitField` trait that provides the following [Range]-based API: [Range]: https://doc.rust-lang.org/nightly/core/ops/struct.Range.html @@ -154,11 +154,11 @@ Well, none of these variants is really _readable_ and it's very easy to make mis self.0.set_range(0..3, stack_index); ``` -I think it is much more readable, since we abstracted away all bit-masking details. The `BitField` type is contained in the [bit_field] crate. (It's pretty new, so it might still contain bugs.) To add it as dependency, we run `cargo add bit_field` and add `extern crate bit_field;` to our `src/lib.rs`. +I think it is much more readable, since we abstracted away all bit-masking details. The `BitField` trait is contained in the [bit_field] crate. (It's pretty new, so it might still contain bugs.) To add it as dependency, we run `cargo add bit_field` and add `extern crate bit_field;` to our `src/lib.rs`. [bit_field]: https://crates.io/crates/bit_field -Now we can use the crate to implement the methods of `EntryOptions`: +Now we can use the trait to implement the methods of `EntryOptions`: ```rust // in src/interrupts/idt.rs @@ -166,11 +166,11 @@ Now we can use the crate to implement the methods of `EntryOptions`: use bit_field::BitField; #[derive(Debug, Clone, Copy)] -pub struct EntryOptions(BitField); +pub struct EntryOptions(u16); impl EntryOptions { fn minimal() -> Self { - let mut options = BitField::new(0); + let mut options = 0; options.set_range(9..12, 0b111); // 'must-be-one' bits EntryOptions(options) }