5 Layout of standard saved context on stack
\r
6 (this is the format that we write and read contexts):
\r
8 (low addr.) (high addr.)
\r
9 | | | | | | | | | | | | | | | | | | |
\r
10 | frame | z | xy | tmp | P | CCR | B | A | X | Y | Addr |
\r
12 \------------------ softregs -------------------/
\r
14 P = PPAGE, the bank nr. of the return address
\r
17 Layout of function call context on stack,
\r
18 before we convert it to standard:
\r
20 (low addr.) (high addr.)
\r
25 Layout of interrupt context on stack,
\r
26 before we convert it to standard:
\r
28 (low addr.) (high addr.)
\r
30 | CCR | B | A | X | Y | Addr |
\r
35 .macro SAVE_CONTEXT_FROM_FUNCTION
\r
36 staa -4, sp // save A -> ctx(A)
\r
37 ldaa 0, sp // load callctx(P) -> A *
\r
38 sty 1, -sp // save Y -> ctx(Y)
\r
39 stx 2, -sp // save X -> ctx(X)
\r
40 stab 2, -sp // save B -> ctx(B) (skipping ctx(A))
\r
42 pshc // save CCR -> ctx(CCR)
\r
45 .short 0x1839 // save CCR -> ctx(CCR)
\r
47 psha // save P -> ctx(P) *
\r
48 movw _.tmp ,2,-sp // save tmp -> ctx(tmp)
\r
49 movw _.xy, 2,-sp // save xy -> ctx(xy)
\r
50 movw _.z, 2,-sp // save z -> ctx(z)
\r
51 movw _.frame, 2,-sp // save frame -> ctx(frame)
\r
54 .macro RESTORE_CONTEXT_FOR_FUNCTION
\r
55 movw 2,sp+, _.frame // load frame <- ctx(frame)
\r
56 movw 2,sp+, _.z // load z <- ctx(z)
\r
57 movw 2,sp+, _.xy // load xy <- ctx(xy)
\r
58 movw 2,sp+, _.tmp // load tmp <- ctx(tmp)
\r
59 ldy Y_SP_OFFSET,sp // load Y <- ctx(Y)
\r
60 movb 1,sp+, Y_SP_OFFSET,sp // move ctx(P) -> callctx(P)
\r
62 pulc // save CCR -> ctx(CCR)
\r
65 .short 0x1838 // load CCR <- ctx(CCR)
\r
67 puld // load D <- ctx(D)
\r
68 pulx // load X <- ctx(X)
\r
69 ins // skipping ctx(Yh)
\r
74 .macro SAVE_CONTEXT_FROM_INTERRUPT
\r
75 movb PPAGE, 1,-sp // save P -> ctx(P)
\r
76 movw _.tmp ,2,-sp // save tmp -> ctx(tmp)
\r
77 movw _.xy, 2,-sp // save xy -> ctx(xy)
\r
78 movw _.z, 2,-sp // save z -> ctx(z)
\r
79 movw _.frame, 2,-sp // save frame -> ctx(frame)
\r
82 .macro RESTORE_CONTEXT_FOR_INTERRUPT
\r
83 movw 2,sp+, _.frame // load frame <- ctx(frame)
\r
84 movw 2,sp+, _.z // load z <- ctx(z)
\r
85 movw 2,sp+, _.xy // load xy <- ctx(xy)
\r
86 movw 2,sp+, _.tmp // load tmp <- ctx(tmp)
\r
87 movb 1,sp+, PPAGE // load P <- ctx(P)
\r