diff --git a/src/fpu/fpu_instructions.h b/src/fpu/fpu_instructions.h index 0789d497..fa59e4ca 100644 --- a/src/fpu/fpu_instructions.h +++ b/src/fpu/fpu_instructions.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2002-2013 The DOSBox Team + * Copyright (C) 2002-2014 The DOSBox Team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -42,9 +42,7 @@ static void FPU_FNOP(void){ } static void FPU_PUSH(double in){ - TOP = (TOP - 1) &7; - //actually check if empty - fpu.tags[TOP] = TAG_Valid; + FPU_PREP_PUSH(); fpu.regs[TOP].d = in; // LOG(LOG_FPU,LOG_ERROR)("Pushed at %d %g to the stack",newtop,in); return; @@ -52,10 +50,12 @@ static void FPU_PUSH(double in){ static void FPU_PREP_PUSH(void){ TOP = (TOP - 1) &7; + if (GCC_UNLIKELY(fpu.tags[TOP] != TAG_Empty)) E_Exit("FPU stack overflow"); fpu.tags[TOP] = TAG_Valid; } static void FPU_FPOP(void){ + if (GCC_UNLIKELY(fpu.tags[TOP] == TAG_Empty)) E_Exit("FPU stack underflow"); fpu.tags[TOP]=TAG_Empty; //maybe set zero in it as well TOP = ((TOP+1)&7); diff --git a/src/fpu/fpu_instructions_x86.h b/src/fpu/fpu_instructions_x86.h index 1d51e26e..21b2f93d 100644 --- a/src/fpu/fpu_instructions_x86.h +++ b/src/fpu/fpu_instructions_x86.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2002-2013 The DOSBox Team + * Copyright (C) 2002-2014 The DOSBox Team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -957,11 +957,13 @@ static void FPU_FNOP(void){ static void FPU_PREP_PUSH(void){ TOP = (TOP - 1) &7; - fpu.tags[TOP]=TAG_Valid; + if (GCC_UNLIKELY(fpu.tags[TOP] != TAG_Empty)) E_Exit("FPU stack overflow"); + fpu.tags[TOP] = TAG_Valid; } static void FPU_FPOP(void){ - fpu.tags[TOP]=TAG_Empty; + if (GCC_UNLIKELY(fpu.tags[TOP] == TAG_Empty)) E_Exit("FPU stack underflow"); + fpu.tags[TOP] = TAG_Empty; TOP = ((TOP+1)&7); }