~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to roms/openbios/arch/sparc64/switch.S

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "pstate.h"
 
2
#include <asm/asi.h>
 
3
#include "cpustate.h"
 
4
#define ASI_BP ASI_M_BYPASS
 
5
#define REGWIN_SZ   0x40
 
6
 
 
7
        .globl  __switch_context, __switch_context_nosave, __exit_context, halt
 
8
 
 
9
        .text
 
10
        .align  4
 
11
        .register %g2, #scratch
 
12
        .register %g3, #scratch
 
13
        .register %g6, #scratch
 
14
        .register %g7, #scratch
 
15
 
 
16
/*
 
17
 * Switch execution context
 
18
 * This saves registers in the stack, then
 
19
 * switches the stack, and restores everything from the new stack.
 
20
 * This function takes no argument. New stack pointer is
 
21
 * taken from global variable __context, and old stack pointer
 
22
 * is also saved to __context. This way we can just jump to
 
23
 * this routine to get back to the original context.
 
24
 */
 
25
 
 
26
__switch_context:
 
27
        /* make sure caller's windows are on caller's stack */
 
28
        flushw;
 
29
 
 
30
        /* Save everything in current stack */
 
31
        stx     %g1, [%sp + 2047 - 0x500 + 0x30]
 
32
        stx     %g2, [%sp + 2047 - 0x500 + 0x38]
 
33
        stx     %g3, [%sp + 2047 - 0x500 + 0x40]
 
34
        stx     %g4, [%sp + 2047 - 0x500 + 0x48]
 
35
        stx     %g5, [%sp + 2047 - 0x500 + 0x50]
 
36
        stx     %g6, [%sp + 2047 - 0x500 + 0x58]
 
37
        stx     %g7, [%sp + 2047 - 0x500 + 0x60]
 
38
        
 
39
        mov     %sp, %g1
 
40
        add     %g1, 2047 - 0x500, %g1
 
41
        
 
42
        /* Return PC value */
 
43
        mov     %o7, %g2
 
44
        add     %g2, 0x8, %g2
 
45
        stx     %g2, [%g1 + 0x4d0]
 
46
        
 
47
        SAVE_CPU_STATE(switch)
 
48
        
 
49
        /* swap context */
 
50
        setx    __context, %g2, %g3
 
51
        ldx     [%g3], %g2
 
52
        stx     %g1, [%g3]
 
53
        mov     %g2, %g1
 
54
        
 
55
        ba      __set_context
 
56
 
 
57
__switch_context_nosave:
 
58
        /* Interrupts are not allowed... */
 
59
        /* make sure caller's windows are on caller's stack */
 
60
        flushw
 
61
        /* Load all registers
 
62
         */
 
63
        setx    __context, %g2, %g1
 
64
        ldx     [%g1], %g1
 
65
        
 
66
__set_context:
 
67
        RESTORE_CPU_STATE(switch)
 
68
        
 
69
        /* Restore globals */
 
70
        mov     %g1, %g2
 
71
        add     %g2, 0x30, %g2
 
72
        stx     %g2, [%sp + 2047 - 8]
 
73
        
 
74
        ldx     [%g1 + 0x38], %g2
 
75
        ldx     [%g1 + 0x40], %g3
 
76
        ldx     [%g1 + 0x48], %g4 
 
77
        ldx     [%g1 + 0x50], %g5 
 
78
        ldx     [%g1 + 0x58], %g6
 
79
        ldx     [%g1 + 0x60], %g7
 
80
 
 
81
        /* Finally, load new %pc */
 
82
        ldx     [%g1 + 0x4d0], %g1
 
83
        jmpl    %g1, %o7
 
84
         ldx    [%sp + 2047 - 8], %g1
 
85
 
 
86
__exit_context:
 
87
        /* Get back to the original context */
 
88
        ba      __switch_context
 
89
         nop