@@ -116,8 +116,77 @@ static int loongarch_gdb_set_fpu(CPUState *cs, uint8_t *mem_buf, int n)
116116 return length ;
117117}
118118
119+ #define VREG_NUM 32
120+ #define REG64_LEN 64
121+
122+ static int loongarch_gdb_get_vec (CPUState * cs , GByteArray * mem_buf , int n , int vl )
123+ {
124+ LoongArchCPU * cpu = LOONGARCH_CPU (cs );
125+ CPULoongArchState * env = & cpu -> env ;
126+ int i , length = 0 ;
127+
128+ if (0 <= n && n < VREG_NUM ) {
129+ for (i = 0 ; i < vl / REG64_LEN ; i ++ ) {
130+ length += gdb_get_reg64 (mem_buf , env -> fpr [n ].vreg .D (i ));
131+ }
132+ }
133+
134+ return length ;
135+ }
136+
137+ static int loongarch_gdb_set_vec (CPUState * cs , uint8_t * mem_buf , int n , int vl )
138+ {
139+ LoongArchCPU * cpu = LOONGARCH_CPU (cs );
140+ CPULoongArchState * env = & cpu -> env ;
141+ int i , length = 0 ;
142+
143+ if (0 <= n && n < VREG_NUM ) {
144+ for (i = 0 ; i < vl / REG64_LEN ; i ++ ) {
145+ env -> fpr [n ].vreg .D (i ) = ldq_le_p (mem_buf + 8 * i );
146+ length += 8 ;
147+ }
148+ }
149+
150+ return length ;
151+ }
152+
153+ static int loongarch_gdb_get_lsx (CPUState * cs , GByteArray * mem_buf , int n )
154+ {
155+ return loongarch_gdb_get_vec (cs , mem_buf , n , LSX_LEN );
156+ }
157+
158+ static int loongarch_gdb_set_lsx (CPUState * cs , uint8_t * mem_buf , int n )
159+ {
160+ return loongarch_gdb_set_vec (cs , mem_buf , n , LSX_LEN );
161+ }
162+
163+ static int loongarch_gdb_get_lasx (CPUState * cs , GByteArray * mem_buf , int n )
164+ {
165+ return loongarch_gdb_get_vec (cs , mem_buf , n , LASX_LEN );
166+ }
167+
168+ static int loongarch_gdb_set_lasx (CPUState * cs , uint8_t * mem_buf , int n )
169+ {
170+ return loongarch_gdb_set_vec (cs , mem_buf , n , LASX_LEN );
171+ }
172+
119173void loongarch_cpu_register_gdb_regs_for_features (CPUState * cs )
120174{
121- gdb_register_coprocessor (cs , loongarch_gdb_get_fpu , loongarch_gdb_set_fpu ,
122- gdb_find_static_feature ("loongarch-fpu.xml" ), 0 );
175+ LoongArchCPU * cpu = LOONGARCH_CPU (cs );
176+ CPULoongArchState * env = & cpu -> env ;
177+
178+ if (FIELD_EX32 (env -> cpucfg [2 ], CPUCFG2 , FP )) {
179+ gdb_register_coprocessor (cs , loongarch_gdb_get_fpu , loongarch_gdb_set_fpu ,
180+ gdb_find_static_feature ("loongarch-fpu.xml" ), 0 );
181+ }
182+
183+ if (FIELD_EX32 (env -> cpucfg [2 ], CPUCFG2 , LSX )) {
184+ gdb_register_coprocessor (cs , loongarch_gdb_get_lsx , loongarch_gdb_set_lsx ,
185+ gdb_find_static_feature ("loongarch-lsx.xml" ), 0 );
186+ }
187+
188+ if (FIELD_EX32 (env -> cpucfg [2 ], CPUCFG2 , LASX )) {
189+ gdb_register_coprocessor (cs , loongarch_gdb_get_lasx , loongarch_gdb_set_lasx ,
190+ gdb_find_static_feature ("loongarch-lasx.xml" ), 0 );
191+ }
123192}
0 commit comments