2

私は動作するシンプルなカスタム OS を持っています (今のところあまり機能しません:D)。現在、キーボードをサポートしていないアセンブリ ファイル (boot.s) を使用しています。

アセンブリ ファイル (boot.s):

# set magic number to 0x1BADB002 to identified by bootloader 
.set MAGIC,    0x1BADB002
# set flags to 0
.set FLAGS,    0
# set the checksum
.set CHECKSUM, -(MAGIC + FLAGS)
# set multiboot enabled
.section .multiboot
# define type to long for each data defined as above
.long MAGIC
.long FLAGS
.long CHECKSUM
# set the stack bottom 
stackBottom:
# define the maximum size of stack to 512 bytes
.skip 512
# set the stack top which grows from higher to lower
stackTop:
.section .text
.global _start
.type _start, @function

_start:
  # assign current stack pointer location to stackTop
    mov $stackTop, %esp
  # call the kernel main source
    call KERNEL_MAIN
    cli
# put system in infinite loop
hltLoop:
    hlt
    jmp hltLoop
.size _start, . - _start

これは欠けている部分だと思いますが、インテルの構文であり、使用できません。

load_idt:
mov edx, [esp + 4]
lidt [edx]
sti
ret

read_port:
mov edx, [esp + 4]
in al, dx   
ret

write_port:
mov edx, [esp + 4]    
mov al, [esp + 4 + 4]  
out dx, al  
ret

keyboard_handler:                 
call keyboard_handler
iretd

次のコマンドで boot.s をコンパイルしています。

as --32 boot.s -o boot.o

キーボード部分 (Intel 構文) を AT&T に変換するのを手伝ってくれる人はいますか? :)

4

1 に答える 1

4

NASM Intel 構文を GAS の AT&T 構文に変換する方法に関する情報は、このStackoverflow Answerにあり、多くの有用な情報がこのIBM articleに記載されています。特にあなたのコードは次のようになります:

load_idt:
    mov 4(%esp), %edx
    lidt (%edx)
    sti
    ret

read_port:
    mov 4(%esp), %edx
    in %dx, %al
    ret

write_port:
    mov 4(%esp), %edx
    mov 8(%esp), %al
    out %al, %dx
    ret

keyboard_handler:                 
    call keyboard_handler
    iret

一般に、最大の違いは次のとおりです。

  • AT&T 構文では、送信元が左側、送信先が右側、Intel はその逆です。
  • AT&T 構文では、レジスタ名の前に%
  • AT&T 構文では、即時値の前に$
  • メモリ オペランドは、おそらく最大の違いです。NASM は、GAS のsegment:disp(base, index, scale)の構文の代わりに[segment:disp+base+index*scale]を使用します。

その他の観察

スタックをマルチブート セクションからセクションに移動することをお勧めします.bss。通常、BSS セクションは、出力実行可能ファイルのスペースを占有しません (適切なリンカー スクリプトまたはデフォルトのリンカー スクリプトを使用していると仮定します)。.textスタックは、セクションの後に次のように定義できます。

.section .bss
    .lcomm stackBottom 512
stackTop:
于 2019-03-02T18:50:24.687 に答える