~ubuntu-branches/ubuntu/saucy/bochs/saucy-proposed

« back to all changes in this revision

Viewing changes to fpu/fpu_load_store.cc

  • Committer: Bazaar Package Importer
  • Author(s): David Futcher
  • Date: 2009-04-30 07:46:11 UTC
  • mfrom: (1.1.11 upstream) (4.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090430074611-6dih80a5mk2uvxhk
Tags: 2.3.7+20090416-1ubuntu1
* Merge from debian unstable (LP: #370427), remaining changes:
  - debian/patches/12_no-ssp.patch: Build bios with -fno-stack-protector
  - Add Replaces/Conflicts for bochsbios-qemu (<< 2.3.6-2)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/////////////////////////////////////////////////////////////////////////
2
 
// $Id: fpu_load_store.cc,v 1.24 2008/05/10 13:34:01 sshwarts Exp $
 
2
// $Id: fpu_load_store.cc,v 1.32 2009/03/10 21:43:11 sshwarts Exp $
3
3
/////////////////////////////////////////////////////////////////////////
4
4
//
5
5
//   Copyright (c) 2003 Stanislav Shwartsman
17
17
//
18
18
//  You should have received a copy of the GNU Lesser General Public
19
19
//  License along with this library; if not, write to the Free Software
20
 
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 
20
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
21
21
//
22
22
/////////////////////////////////////////////////////////////////////////
23
23
 
45
45
    return;
46
46
  }
47
47
 
 
48
  floatx80 sti_reg = floatx80_default_nan;
 
49
 
48
50
  if (IS_TAG_EMPTY(i->rm()))
49
51
  {
50
 
    BX_CPU_THIS_PTR FPU_stack_underflow(0);
51
 
    return;
52
 
  }
 
52
    FPU_exception(FPU_EX_Stack_Underflow);
53
53
 
54
 
  floatx80 sti_reg = BX_READ_FPU_REG(i->rm());
 
54
    if (! BX_CPU_THIS_PTR the_i387.is_IA_masked()) 
 
55
      return;
 
56
  }
 
57
  else {
 
58
    sti_reg = BX_READ_FPU_REG(i->rm());
 
59
  }
55
60
 
56
61
  BX_CPU_THIS_PTR the_i387.FPU_push();
57
62
  BX_WRITE_FPU_REG(sti_reg, 0);
75
80
  }
76
81
 
77
82
  float_status_t status =
78
 
     FPU_pre_exception_handling(BX_CPU_THIS_PTR the_i387.get_control_word());
 
83
    FPU_pre_exception_handling(BX_CPU_THIS_PTR the_i387.get_control_word());
79
84
 
80
85
  // convert to floatx80 format
81
86
  floatx80 result = float32_to_floatx80(load_reg, status);
82
87
 
83
 
  if (BX_CPU_THIS_PTR FPU_exception(status.float_exception_flags))
84
 
    return;
85
 
 
86
 
  BX_CPU_THIS_PTR the_i387.FPU_push();
87
 
  BX_WRITE_FPU_REG(result, 0);
 
88
  if (! BX_CPU_THIS_PTR FPU_exception(status.float_exception_flags)) {
 
89
    BX_CPU_THIS_PTR the_i387.FPU_push();
 
90
    BX_WRITE_FPU_REG(result, 0);
 
91
  }
88
92
#else
89
93
  BX_INFO(("FLD_SINGLE_REAL: required FPU, configure --enable-fpu"));
90
94
#endif
105
109
  }
106
110
 
107
111
  float_status_t status =
108
 
     FPU_pre_exception_handling(BX_CPU_THIS_PTR the_i387.get_control_word());
 
112
    FPU_pre_exception_handling(BX_CPU_THIS_PTR the_i387.get_control_word());
109
113
 
110
114
  // convert to floatx80 format
111
115
  floatx80 result = float64_to_floatx80(load_reg, status);
112
116
 
113
 
  if (BX_CPU_THIS_PTR FPU_exception(status.float_exception_flags))
114
 
    return;
115
 
 
116
 
  BX_CPU_THIS_PTR the_i387.FPU_push();
117
 
  BX_WRITE_FPU_REG(result, 0);
 
117
  if (! BX_CPU_THIS_PTR FPU_exception(status.float_exception_flags)) {
 
118
    BX_CPU_THIS_PTR the_i387.FPU_push();
 
119
    BX_WRITE_FPU_REG(result, 0);
 
120
  }
118
121
#else
119
122
  BX_INFO(("FLD_DOUBLE_REAL: required FPU, configure --enable-fpu"));
120
123
#endif
126
129
  BX_CPU_THIS_PTR prepareFPU(i);
127
130
 
128
131
  floatx80 result;
129
 
  read_virtual_tword(i->seg(), RMAddr(i), &result);
 
132
  result.fraction = read_virtual_qword(i->seg(), RMAddr(i));
 
133
  result.exp      = read_virtual_word (i->seg(), RMAddr(i)+8);
130
134
 
131
135
  clear_C1();
132
136
 
133
137
  if (! IS_TAG_EMPTY(-1)) {
134
138
    BX_CPU_THIS_PTR FPU_stack_overflow();
135
 
    return;
136
 
  }
137
 
 
138
 
  BX_CPU_THIS_PTR the_i387.FPU_push();
139
 
 
140
 
  BX_WRITE_FPU_REG(result, 0);
 
139
  }
 
140
  else {
 
141
    BX_CPU_THIS_PTR the_i387.FPU_push();
 
142
    BX_WRITE_FPU_REG(result, 0);
 
143
  }
141
144
#else
142
145
  BX_INFO(("FLD_EXTENDED_REAL: required FPU, configure --enable-fpu"));
143
146
#endif
155
158
 
156
159
  if (! IS_TAG_EMPTY(-1)) {
157
160
    BX_CPU_THIS_PTR FPU_stack_overflow();
158
 
    return;
159
 
  }
160
 
 
161
 
  floatx80 result = int32_to_floatx80((Bit32s) load_reg);
162
 
  BX_CPU_THIS_PTR the_i387.FPU_push();
163
 
  BX_WRITE_FPU_REG(result, 0);
 
161
  }
 
162
  else {
 
163
    floatx80 result = int32_to_floatx80((Bit32s) load_reg);
 
164
    BX_CPU_THIS_PTR the_i387.FPU_push();
 
165
    BX_WRITE_FPU_REG(result, 0);
 
166
  }
164
167
#else
165
168
  BX_INFO(("FILD_WORD_INTEGER: required FPU, configure --enable-fpu"));
166
169
#endif
178
181
 
179
182
  if (! IS_TAG_EMPTY(-1)) {
180
183
    BX_CPU_THIS_PTR FPU_stack_overflow();
181
 
    return;
182
 
  }
183
 
 
184
 
  floatx80 result = int32_to_floatx80(load_reg);
185
 
  BX_CPU_THIS_PTR the_i387.FPU_push();
186
 
  BX_WRITE_FPU_REG(result, 0);
 
184
  }
 
185
  else {
 
186
    floatx80 result = int32_to_floatx80(load_reg);
 
187
    BX_CPU_THIS_PTR the_i387.FPU_push();
 
188
    BX_WRITE_FPU_REG(result, 0);
 
189
  }
187
190
#else
188
191
  BX_INFO(("FILD_DWORD_INTEGER: required FPU, configure --enable-fpu"));
189
192
#endif
201
204
 
202
205
  if (! IS_TAG_EMPTY(-1)) {
203
206
    BX_CPU_THIS_PTR FPU_stack_overflow();
204
 
    return;
205
 
  }
206
 
 
207
 
  floatx80 result = int64_to_floatx80(load_reg);
208
 
  BX_CPU_THIS_PTR the_i387.FPU_push();
209
 
  BX_WRITE_FPU_REG(result, 0);
 
207
  }
 
208
  else {
 
209
    floatx80 result = int64_to_floatx80(load_reg);
 
210
    BX_CPU_THIS_PTR the_i387.FPU_push();
 
211
    BX_WRITE_FPU_REG(result, 0);
 
212
  }
210
213
#else
211
214
  BX_INFO(("FILD_QWORD_INTEGER: required FPU, configure --enable-fpu"));
212
215
#endif
245
248
  val64 += ((hi2>>4) & 0x0f) * scale * 10;
246
249
 
247
250
  floatx80 result = int64_to_floatx80(val64);
248
 
  if (hi2 & 0x8000)     // set negative
 
251
  if (hi2 & 0x8000)        // set negative
249
252
      floatx80_chs(result);
250
253
 
251
254
  BX_CPU_THIS_PTR the_i387.FPU_push();
269
272
 
270
273
  if (IS_TAG_EMPTY(0)) {
271
274
    BX_CPU_THIS_PTR FPU_stack_underflow(i->rm(), pop_stack);
272
 
    return;
273
 
  }
274
 
 
275
 
  floatx80 st0_reg = BX_READ_FPU_REG(0);
276
 
 
277
 
  BX_WRITE_FPU_REG(st0_reg, i->rm());
278
 
  if (pop_stack)
279
 
     BX_CPU_THIS_PTR the_i387.FPU_pop();
 
275
  }
 
276
  else {
 
277
    floatx80 st0_reg = BX_READ_FPU_REG(0);
 
278
 
 
279
    BX_WRITE_FPU_REG(st0_reg, i->rm());
 
280
    if (pop_stack)
 
281
      BX_CPU_THIS_PTR the_i387.FPU_pop();
 
282
  }
280
283
#else
281
284
  BX_INFO(("FST(P)_STi: required FPU, configure --enable-fpu"));
282
285
#endif
297
300
  {
298
301
     BX_CPU_THIS_PTR FPU_exception(FPU_EX_Stack_Underflow);
299
302
 
300
 
     if (! (BX_CPU_THIS_PTR the_i387.is_IA_masked()))
 
303
     if (! BX_CPU_THIS_PTR the_i387.is_IA_masked())
301
304
        return;
302
305
  }
303
306
  else
307
310
 
308
311
     save_reg = floatx80_to_float32(BX_READ_FPU_REG(0), status);
309
312
 
310
 
     if (BX_CPU_THIS_PTR FPU_exception(status.float_exception_flags))
 
313
     if (BX_CPU_THIS_PTR FPU_exception(status.float_exception_flags, 1))
311
314
        return;
312
315
  }
313
316
 
335
338
  {
336
339
     BX_CPU_THIS_PTR FPU_exception(FPU_EX_Stack_Underflow);
337
340
 
338
 
     if (! (BX_CPU_THIS_PTR the_i387.is_IA_masked()))
 
341
     if (! BX_CPU_THIS_PTR the_i387.is_IA_masked())
339
342
        return;
340
343
  }
341
344
  else
345
348
 
346
349
     save_reg = floatx80_to_float64(BX_READ_FPU_REG(0), status);
347
350
 
348
 
     if (BX_CPU_THIS_PTR FPU_exception(status.float_exception_flags))
 
351
     if (BX_CPU_THIS_PTR FPU_exception(status.float_exception_flags, 1))
349
352
        return;
350
353
  }
351
354
 
372
375
  {
373
376
     BX_CPU_THIS_PTR FPU_exception(FPU_EX_Stack_Underflow);
374
377
 
375
 
     if (! (BX_CPU_THIS_PTR the_i387.is_IA_masked()))
 
378
     if (! BX_CPU_THIS_PTR the_i387.is_IA_masked())
376
379
        return;
377
380
  }
378
381
  else
380
383
     save_reg = BX_READ_FPU_REG(0);
381
384
  }
382
385
 
383
 
  write_virtual_tword(i->seg(), RMAddr(i), &save_reg);
 
386
  write_virtual_qword(i->seg(), RMAddr(i),     save_reg.fraction);
 
387
  write_virtual_word (i->seg(), RMAddr(i) + 8, save_reg.exp);
384
388
 
385
389
  BX_CPU_THIS_PTR the_i387.FPU_pop();
386
390
#else
403
407
  {
404
408
     BX_CPU_THIS_PTR FPU_exception(FPU_EX_Stack_Underflow);
405
409
 
406
 
     if (! (BX_CPU_THIS_PTR the_i387.is_IA_masked()))
 
410
     if (! BX_CPU_THIS_PTR the_i387.is_IA_masked())
407
411
        return;
408
412
  }
409
413
  else
413
417
 
414
418
     save_reg = floatx80_to_int16(BX_READ_FPU_REG(0), status);
415
419
 
416
 
     if (BX_CPU_THIS_PTR FPU_exception(status.float_exception_flags))
 
420
     if (BX_CPU_THIS_PTR FPU_exception(status.float_exception_flags, 1))
417
421
        return;
418
422
  }
419
423
 
441
445
  {
442
446
     BX_CPU_THIS_PTR FPU_exception(FPU_EX_Stack_Underflow);
443
447
 
444
 
     if (! (BX_CPU_THIS_PTR the_i387.is_IA_masked()))
 
448
     if (! BX_CPU_THIS_PTR the_i387.is_IA_masked())
445
449
        return;
446
450
  }
447
451
  else
451
455
 
452
456
     save_reg = floatx80_to_int32(BX_READ_FPU_REG(0), status);
453
457
 
454
 
     if (BX_CPU_THIS_PTR FPU_exception(status.float_exception_flags))
 
458
     if (BX_CPU_THIS_PTR FPU_exception(status.float_exception_flags, 1))
455
459
         return;
456
460
  }
457
461
 
477
481
  {
478
482
     BX_CPU_THIS_PTR FPU_exception(FPU_EX_Stack_Underflow);
479
483
 
480
 
     if (! (BX_CPU_THIS_PTR the_i387.is_IA_masked()))
 
484
     if (! BX_CPU_THIS_PTR the_i387.is_IA_masked())
481
485
        return;
482
486
  }
483
487
  else
487
491
 
488
492
     save_reg = floatx80_to_int64(BX_READ_FPU_REG(0), status);
489
493
 
490
 
     if (BX_CPU_THIS_PTR FPU_exception(status.float_exception_flags))
 
494
     if (BX_CPU_THIS_PTR FPU_exception(status.float_exception_flags, 1))
491
495
         return;
492
496
  }
493
497
 
517
521
  {
518
522
     BX_CPU_THIS_PTR FPU_exception(FPU_EX_Stack_Underflow);
519
523
 
520
 
     if (! (BX_CPU_THIS_PTR the_i387.is_IA_masked()))
 
524
     if (! BX_CPU_THIS_PTR the_i387.is_IA_masked())
521
525
        return;
522
526
  }
523
527
  else
555
559
    }
556
560
 
557
561
    /* check for fpu arithmetic exceptions */
558
 
    if (BX_CPU_THIS_PTR FPU_exception(status.float_exception_flags))
 
562
    if (BX_CPU_THIS_PTR FPU_exception(status.float_exception_flags, 1))
559
563
        return;
560
564
  }
561
565
 
583
587
  {
584
588
     BX_CPU_THIS_PTR FPU_exception(FPU_EX_Stack_Underflow);
585
589
 
586
 
     if (! (BX_CPU_THIS_PTR the_i387.is_IA_masked()))
 
590
     if (! BX_CPU_THIS_PTR the_i387.is_IA_masked())
587
591
        return;
588
592
  }
589
593
  else
593
597
 
594
598
     save_reg = floatx80_to_int16_round_to_zero(BX_READ_FPU_REG(0), status);
595
599
 
596
 
     if (BX_CPU_THIS_PTR FPU_exception(status.float_exception_flags))
 
600
     if (BX_CPU_THIS_PTR FPU_exception(status.float_exception_flags, 1))
597
601
        return;
598
602
  }
599
603
 
601
605
  BX_CPU_THIS_PTR the_i387.FPU_pop();
602
606
#else
603
607
  BX_INFO(("FISTTP16: required SSE3, use --enable-sse option"));
604
 
  UndefinedOpcode(i);
 
608
  exception(BX_UD_EXCEPTION, 0, 0);
605
609
#endif
606
610
}
607
611
 
619
623
  {
620
624
     BX_CPU_THIS_PTR FPU_exception(FPU_EX_Stack_Underflow);
621
625
 
622
 
     if (! (BX_CPU_THIS_PTR the_i387.is_IA_masked()))
 
626
     if (! BX_CPU_THIS_PTR the_i387.is_IA_masked())
623
627
        return;
624
628
  }
625
629
  else
629
633
 
630
634
     save_reg = floatx80_to_int32_round_to_zero(BX_READ_FPU_REG(0), status);
631
635
 
632
 
     if (BX_CPU_THIS_PTR FPU_exception(status.float_exception_flags))
633
 
         return;
 
636
     if (BX_CPU_THIS_PTR FPU_exception(status.float_exception_flags, 1))
 
637
        return;
634
638
  }
635
639
 
636
640
  write_virtual_dword(i->seg(), RMAddr(i), (Bit32u)(save_reg));
637
641
  BX_CPU_THIS_PTR the_i387.FPU_pop();
638
642
#else
639
643
  BX_INFO(("FISTTP32: required SSE3, use --enable-sse option"));
640
 
  UndefinedOpcode(i);
 
644
  exception(BX_UD_EXCEPTION, 0, 0);
641
645
#endif
642
646
}
643
647
 
655
659
  {
656
660
     BX_CPU_THIS_PTR FPU_exception(FPU_EX_Stack_Underflow);
657
661
 
658
 
     if (! (BX_CPU_THIS_PTR the_i387.is_IA_masked()))
 
662
     if (! BX_CPU_THIS_PTR the_i387.is_IA_masked())
659
663
        return;
660
664
  }
661
665
  else
665
669
 
666
670
     save_reg = floatx80_to_int64_round_to_zero(BX_READ_FPU_REG(0), status);
667
671
 
668
 
     if (BX_CPU_THIS_PTR FPU_exception(status.float_exception_flags))
669
 
         return;
 
672
     if (BX_CPU_THIS_PTR FPU_exception(status.float_exception_flags, 1))
 
673
        return;
670
674
  }
671
675
 
672
676
  write_virtual_qword(i->seg(), RMAddr(i), (Bit64u)(save_reg));
673
677
  BX_CPU_THIS_PTR the_i387.FPU_pop();
674
678
#else
675
679
  BX_INFO(("FISTTP64: required SSE3, use --enable-sse option"));
676
 
  UndefinedOpcode(i);
 
680
  exception(BX_UD_EXCEPTION, 0, 0);
677
681
#endif
678
682
}
679
683