annotate src/swtch.S @ 228:e2520f609094

merge
author menikon <e165723@ie.u-ryukyu.ac.jp>
date Fri, 24 Jan 2020 21:19:48 +0900
parents 83c23a36980d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 # Context switch
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 # void swtch(struct context **old, struct context *new);
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 # Save current register context in old
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 # and then load register context from new.
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 # The stack is as r4_svc-r12_svc, lr_svc, sp_usr, lr_usr, and pc_usr
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 .global swtch
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 swtch:
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 STMFD r13!, {r4-r12, lr} // push svc r4-r12, lr to the stack
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 # switch the stack
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 STR r13, [r0] // save current sp to the old PCB (**old)
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 MOV r13, r1 // load the next stack
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 # load the new registers. pc_usr is not restored here because
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 # LDMFD^ will switch mode if pc_usr is loaded. We just simply
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 # pop it out as pc_usr is saved on the stack, and will be loaded
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 # when we return from kernel to user space (swi or interrupt return)
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 LDMFD r13!, {r4-r12, lr} // pop svc r4-r12, lr
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 # return to the caller
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 bx lr
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26