0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

MIPSのアーキテクチャ

Last updated at Posted at 2022-03-23

ここに資料があります。

gccは-march=hogeで設定します。gcc4では以下のような設定が可能です・

The ISA names are: 'mips1', 'mips2', 'mips3', 'mips4', 'mips32', 'mips32r2', 'mips64' and 'mips64r2'.

以前から気になっていたのですがZRouterでビルドするとへんてこな状態でした。

% file Onion_Omega_kernel
Onion_Omega_kernel: ELF 32-bit MSB executable, MIPS, MIPS32 version 1 (FreeBSD), dynamically linked, interpreter /red/herring, not stripped
% file Onion_Omega_rootfs/bin/ls
Onion_Omega_rootfs/bin/ls: ELF 32-bit MSB executable, MIPS, MIPS-III version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, FreeBSD-style, for FreeBSD 12.3 (1203506), stripped

SIMDのサポートを調べていてリンクできないので確認しなおしました。

MIPSの互換性の高さと、FreeBSDのコードが古いアーキテクチャで作られたもので、新しいアーキテクチャの機能を使っていないので、問題が起きないのだと思います。

これはkernelはsys/conf/Makefile.mipsでmips32が指定されるのでmips32になりますが、ユーザーランドはgccのデフォルトでビルドされるためこうなってしまいます。

いとしのRT3050はmips32r2です。

  • MIPS32 Enhanced Architecture (Release 2) Features

直しました。

% file Fon_FON2305E_FDT_kernel
Fon_FON2305E_FDT_kernel: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (FreeBSD), dynamically linked, interpreter /red/herring, not stripped
% file Fon_FON2305E_FDT_rootfs/bin/ls
Fon_FON2305E_FDT_rootfs/bin/ls: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, FreeBSD-style, for FreeBSD 12.3 (1203506), stripped

もちろん問題なく起動できました。

socのmkでTARGET_CPUTYPEを指定してARCH_FLAGSを無効化しました。

portsもどきの方にも効くようです。よく分かってないのですが、rayが作り込んでいたところが機能しているんだと思われます。

kernelだけmarchを設定する仕組みは最初のようなおかしな状態を作り出すので正しくありません。kernel,userland共通のTARGET_CPUTYPEを使うのが正しいです。

古参のコミッターのjhbさんがレビューD22030でいじっているのですが、あまり良い修正ではないです。

FreeBSDはmips32以降しかサポートしてないので、本当はクロスとセルフのgccのデフォルトをmips32にするのが正解なのですが、もはやgccをいじりたくないというのもあるので、小手先で対応する事になります。

セルフでgccがある場合、コンパイルでライブラリとオブジェクトのABIが違っているとリンクできなくなるので、ユーザーランドをデフォルトのMIPS-IIIにしておくのは間違いではありません。

とはいえセルフでgccを持たないなのであれば、デフォルト以外に変更しても問題ありません。

buildworld,buildkernelのクロスコンパイルの仕組みは非常によく出来ていると思いますが、分かれてしまっているのでZRouterのようにまとめるラッパーは正解だと思います。

mips32とmips32r2がの分水嶺がよくわかりません。

mips32r3,r5などもあるようですが、ほとんど実在して無いと思います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?