tomoyuki-nakabayashi / Rustemu86

Apache License 2.0
5 stars 0 forks source link

フェッチした1命令を表現するstructを定義する #9

Closed tomoyuki-nakabayashi closed 6 years ago

tomoyuki-nakabayashi commented 6 years ago
pub struct InstructionX86_64 {
  lecacy_prefix: LegacyPrefix,
  opcode: Opcode,
  mod_rm: ModRm,
  sib: Sib,
  displacement: Displacement,
  immediate: Immediate,
}

バイト列を受け取って、こんな感じで、各フィールドを埋めるまでをやりたい。 具体的な解釈は、decodeステージでやる。

tomoyuki-nakabayashi commented 6 years ago

https://github.com/dzamlo/rust-bitfield https://github.com/phil-opp/rust-bit-field

bit fieldを触れるcrateは2つ見つかった。

tomoyuki-nakabayashi commented 6 years ago

rust-bit-fieldの方が使いやすそう。主にget_bits()/set_bits()が直観的。

tomoyuki-nakabayashi commented 6 years ago

だいたいできたけどもうちょっと。

tomoyuki-nakabayashi commented 6 years ago

https://qiita.com/tatsuya6502/items/cd41599291e2e5f38a4a

fetchをコンビネーターのチェインで表現してはどうだろうか? とりあえずOption<>でチェインしてみよう。

tomoyuki-nakabayashi commented 6 years ago

https://rust-lang-ja.github.io/the-rust-programming-language-ja/1.6/book/method-syntax.html

builderパターンにしてみるか。

tomoyuki-nakabayashi commented 6 years ago

OK!