Skip to content
Discussion options

You must be logged in to vote

レジスタに入っている値をプロセスの持つスタック内のメモリに退避する で合っていますか

その通りです!C言語で考えると次のようなイメージです。

struct frame {
    uint32_t ra;
    uint32_t s0;
    uint32_t s1;
    uint32_t s2;
    uint32_t s3;
    uint32_t s4;
    uint32_t s5;
    uint32_t s6;
    uint32_t s7;
    uint32_t s8;
    uint32_t s9;
    uint32_t s10;
    uint32_t s11;
};

// 擬似コード。ra, s0, ...はレジスタを操作しているつもり。
void riscv32_task_switch(uint32_t *prev_sp, uint32_t *next_sp) {
    struct frame *f_prev = (スタックポインタからframe構造体の大きさだけ引いたアドレス); // addi sp, sp, -13 * 4
    f_prev->ra = ra;         // sw ra,  0  * 4(sp)
    f_prev->s0 = s0;         // sw s0,  1  * 4(sp)
    f_prev->s1 = s1;         // sw s1,  2  * 4(sp)
    f_prev->s2 = s2;         // sw s2,  3…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@keisuke713
Comment options

@nuta
Comment options

nuta Mar 4, 2024
Maintainer

@keisuke713
Comment options

Answer selected by keisuke713
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants