@@ -65,7 +65,42 @@ extern {
6565 fn swap_registers ( out_regs : * mut Registers , in_regs : * Registers ) ;
6666}
6767
68- // Definitions of these registers are in rt/arch/x86_64/regs.h
68+ #[ cfg( target_arch = "x86" ) ]
69+ struct Registers {
70+ eax : u32 , ebx : u32 , ecx : u32 , edx : u32 ,
71+ ebp : u32 , esi : u32 , edi : u32 , esp : u32 ,
72+ cs : u16 , ds : u16 , ss : u16 , es : u16 , fs : u16 , gs : u16 ,
73+ eflags : u32 , eip : u32
74+ }
75+
76+ #[ cfg( target_arch = "x86" ) ]
77+ fn new_regs ( ) -> ~Registers {
78+ ~Registers {
79+ eax : 0 , ebx : 0 , ecx : 0 , edx : 0 ,
80+ ebp : 0 , esi : 0 , edi : 0 , esp : 0 ,
81+ cs : 0 , ds : 0 , ss : 0 , es : 0 , fs : 0 , gs : 0 ,
82+ eflags : 0 , eip : 0
83+ }
84+ }
85+
86+ #[ cfg( target_arch = "x86" ) ]
87+ fn initialize_call_frame ( regs : & mut Registers ,
88+ fptr : * c_void , arg : * c_void , sp : * mut uint ) {
89+
90+ let sp = align_down ( sp) ;
91+ let sp = mut_offset ( sp, -4 ) ; // XXX: -4 words? Needs this be done at all?
92+
93+ unsafe { * sp = arg as uint ; }
94+ let sp = mut_offset ( sp, -1 ) ;
95+ unsafe { * sp = 0 ; } // The final return address
96+
97+ regs. esp = sp as u32 ;
98+ regs. eip = fptr as u32 ;
99+
100+ // Last base pointer on the stack is 0
101+ regs. ebp = 0 ;
102+ }
103+
69104#[ cfg( target_arch = "x86_64" ) ]
70105type Registers = [ uint * 22 ] ;
71106
@@ -101,40 +136,42 @@ fn initialize_call_frame(regs: &mut Registers,
101136 regs[ RUSTRT_RBP ] = 0 ;
102137}
103138
104- #[ cfg( target_arch = "x86" ) ]
105- struct Registers {
106- eax : u32 , ebx : u32 , ecx : u32 , edx : u32 ,
107- ebp : u32 , esi : u32 , edi : u32 , esp : u32 ,
108- cs : u16 , ds : u16 , ss : u16 , es : u16 , fs : u16 , gs : u16 ,
109- eflags : u32 , eip : u32
110- }
139+ #[ cfg( target_arch = "arm" ) ]
140+ type Registers = [ uint * 32 ] ;
111141
112- #[ cfg( target_arch = "x86" ) ]
113- fn new_regs ( ) -> ~Registers {
114- ~Registers {
115- eax : 0 , ebx : 0 , ecx : 0 , edx : 0 ,
116- ebp : 0 , esi : 0 , edi : 0 , esp : 0 ,
117- cs : 0 , ds : 0 , ss : 0 , es : 0 , fs : 0 , gs : 0 ,
118- eflags : 0 , eip : 0
119- }
120- }
142+ #[ cfg( target_arch = "arm" ) ]
143+ fn new_regs ( ) -> ~Registers { ~[ 0 , .. 32 ] }
121144
122- #[ cfg( target_arch = "x86 " ) ]
145+ #[ cfg( target_arch = "arm " ) ]
123146fn initialize_call_frame ( regs : & mut Registers ,
124147 fptr : * c_void , arg : * c_void , sp : * mut uint ) {
148+ let sp = mut_offset ( sp, -1 ) ;
125149
126- let sp = align_down ( sp ) ;
127- let sp = mut_offset ( sp , - 4 ) ; // XXX: -4 words? Needs this be done at all?
150+ // The final return address. 0 indicates the bottom of the stack
151+ unsafe { * sp = 0 ; }
128152
129- unsafe { * sp = arg as uint ; }
153+ regs[ 0 ] = arg as uint ; // r0
154+ regs[ 13 ] = sp as uint ; // #53 sp, r13
155+ regs[ 14 ] = fptr as uint ; // #60 pc, r15 --> lr
156+ }
157+
158+ #[ cfg( target_arch = "mips" ) ]
159+ type Registers = [ uint * 32 ] ;
160+
161+ #[ cfg( target_arch = "mips" ) ]
162+ fn new_regs ( ) -> ~Registers { ~[ 0 , .. 32 ] }
163+
164+ #[ cfg( target_arch = "mips" ) ]
165+ fn initialize_call_frame ( regs : & mut Registers ,
166+ fptr : * c_void , arg : * c_void , sp : * mut uint ) {
130167 let sp = mut_offset ( sp, -1 ) ;
131- unsafe { * sp = 0 ; } // The final return address
132168
133- regs . esp = sp as u32 ;
134- regs . eip = fptr as u32 ;
169+ // The final return address. 0 indicates the bottom of the stack
170+ unsafe { * sp = 0 ; }
135171
136- // Last base pointer on the stack is 0
137- regs. ebp = 0 ;
172+ regs[ 4 ] = arg as uint ;
173+ regs[ 29 ] = sp as uint ;
174+ regs[ 31 ] = fptr as uint ;
138175}
139176
140177fn align_down ( sp : * mut uint ) -> * mut uint {
0 commit comments