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?

CUIOS自作 COM実行機能3

Posted at

「手探りでCUI OS作成に挑む」連載

この記事は「手探りでCUI OS作成に挑む」連載の一部です。
全体の目次は「手探りでCUI OS作成に挑む」連載目次を御覧下さい。

ソースコードはこちら:
https://github.com/ooe1220/sourouOS/tree/20250818

主な変更箇所

jmpでCOMを起動した処理が終了したあと、すぐ下のkernel_returnへ返ってくるようにした。
INTを呼ぶとスタックにFLAGSCSIPの3つが詰まれることを知らずはまった。
他のINTIRETで返ることで深く理解する必要はなかったが、AH=4Chの終了処理の場合はIRETを呼ぶと又COMの中へ戻ってしまうため、手動でSPを移動してスタックをずらし、jmp farでカーネルへ戻る必要がある。

command\run.asm
    ; COM実行
    jmp 0x0200:0x0100
            
    kernel_return:
    xor ax, ax
    mov ds, ax
    mov es, ax
    mov byte [com_status], 1   ; COM 正常終了 (DS=0の状態代入)
syscall\int21.asm
; AH=4Ch 終了処理(カーネルに戻る等)
int21_exit:
    pop ds
    popa
    add sp, 6   ; スタックを上に戻す(消す) INTによって詰まれるFLAGS、CS、IPを取り除く
        
    ; PSPセグメントを一時的にDSにセット
    mov ax, 0x0200
    mov ds, ax

    ; far jump でPSPから復帰先を取得してカーネルに戻る
    jmp far [ds:0]
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?