tomoyuki-nakabayashi / Rustemu86

Apache License 2.0
5 stars 0 forks source link

Zephyrをブートする #51

Closed tomoyuki-nakabayashi closed 5 years ago

tomoyuki-nakabayashi commented 5 years ago

割り込みとタイマを実装すれば、動きそう。

tomoyuki-nakabayashi commented 5 years ago
$ riscv32-unknown-elf-readelf -l zephyr.elf

Elf file type is EXEC (Executable file)
Entry point 0x20400000
There are 3 program headers, starting at offset 52

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x000094 0x20400000 0x20400000 0x036c8 0x036c8 RWE 0x4
  LOAD           0x00375c 0x80000000 0x204036c8 0x00080 0x00080 RW  0x4
  LOAD           0x0037e0 0x80000080 0x80000080 0x00000 0x00f50 RW  0x10

 Section to Segment mapping:
  Segment Sections...
   00     vector exceptions text sw_isr_table devconfig rodata 
   01     datas initlevel _k_mutex_area 
   02     bss noinit

プログラムヘッダ、すごいシンプル。手動で書けるレベル。

tomoyuki-nakabayashi commented 5 years ago

GPIOとPINMUXがいるかも?

tomoyuki-nakabayashi commented 5 years ago

あー、dataセクションがROMにもRAMにも必要だから面倒だな…。

tomoyuki-nakabayashi commented 5 years ago

コード確認しないとわからんけど、ROMからRAMにコピーするよなぁ、多分。

tomoyuki-nakabayashi commented 5 years ago

割り込みコントローラの初期化で止まっちゃったな。 とりあえずダミーのメモリ用意しておけば通るかな?

tomoyuki-nakabayashi commented 5 years ago
                plic: interrupt-controller@c000000 {
                        #interrupt-cells = <0x01>;
                        compatible = "riscv,plic0";
                        interrupt-controller;
                        interrupts-extended = <0x08 0x0b>;
                        reg = <0xc000000 0x2000 0xc002000 0x1fe000 0xc200000 0x2000000>;
                        reg-names = "prio", "irq_en", "reg";
                        riscv,max-priority = <0x07>;
                        riscv,ndev = <0x34>;
                        phandle = <0x07>;
                };

0x0c000_000 - 0x0c00_2000までを確保すれば良さそうかな。

tomoyuki-nakabayashi commented 5 years ago

シリアルアクセスまできた!sifive_uartを作るか。

tomoyuki-nakabayashi commented 5 years ago

clintへのアクセスが発生している。 やっぱりタイマ割り込みか。

http://msyksphinz.hatenablog.com/entry/2018/08/09/040000

tomoyuki-nakabayashi commented 5 years ago
                clint: clint@2000000 {
                        compatible = "riscv,clint0";
                        interrupts-extended = <0x08 0x03 0x08 0x07>;
                        reg = <0x2000000 0x10000>;
                        reg-names = "control";
                };

一旦適当に、領域を作って様子みるか。

tomoyuki-nakabayashi commented 5 years ago
                Priv(op) => match op {
                    PrivOp::ECALL => {
                        use crate::isa::csr_map::mcause;
                        self.pc = 0x8000_0004; // trap vector for riscv-tests
                        self.csr.write_u32(mcause, 11);
                    }

ecallでriscv-testsのトラップベクタに飛んでしまっているな。

tomoyuki-nakabayashi commented 5 years ago
Disassembly of section exceptions:

20400010 <__irq_wrapper>:

ここに飛ぶっぽいな。

tomoyuki-nakabayashi commented 5 years ago

image

やったぜ!