snaka; 第5章 文字表示とコンソールクラス - uchan-nos/os-from-zero GitHub Wiki

環境

osbook_day05a の実行結果

objcopy のオプション

$ objcopy -I binary -O elf64-x86-64 -B i386:x86-64 hankaku.bin hankaku.o

[-I bfdname|--input-target=bfdname]
    Consider the source file's object format to be bfdname, rather than attempting to deduce it.

[-O bfdname|--output-target=bfdname]
     Write the output file using the object format bfdname.

[-B bfdarch|--binary-architecture=bfdarch]
     Useful when transforming a architecture-less input file into an object file.  In this case the output architecture can be set to bfdarch.
     This option will be ignored if the input file has a known bfdarch.  You can access this binary data inside a program by referencing the
     special symbols that are created by the conversion process.  These symbols are called _binary_objfile_start, _binary_objfile_end and
     _binary_objfile_size.  e.g. you can transform a picture file into an object file and then access it in your code using these symbols.

osbook_day05c の実行結果

osbook_day05d の実行結果

osbook_day05e の実行結果


呼び出し規約 (Calling Convention)

  • 関数を呼び出す際の決まりごと
    • 引数の渡し方
    • 戻り値の返し方
    • 関数の中で変更して良いレジスタはどれか

Syatem V AMD64 ABI の呼び出し規約

  • 引数
    • 先頭から RDI, RSI, RDX, RCX, R8, R9 の順番にレジスタを割り当てる
  • 戻り値
    • RAX, RDX の順番で使う
    • RAX に値をセットした状態で ret 命令を実行することで値を返す
  • レジスタの保存と退避
    • 関数呼び出しの前後で以下のレジスタの値が保たれていなければならない
      • RSP,RBP,RBX,R12,R13,R14,R15
    • スタックに一時的に退避して関数を実行
    • 関数から抜けるときに退避していたスタックからレジスタを復旧する