mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 13:12:46 +00:00 
			
		
		
		
	UserspaceEmulator: Make SBB actually respect the SoftCPU carry flag
We were forgetting to set the host CPU's carry flag before executing the SBB instruction. This made the result a bit unpredictable. :^)
This commit is contained in:
		
							parent
							
								
									a9f92e5d75
								
							
						
					
					
						commit
						6230c60296
					
				
					 1 changed files with 15 additions and 2 deletions
				
			
		|  | @ -343,12 +343,17 @@ static T op_sub(SoftCPU& cpu, const T& dest, const T& src) | |||
|     return result; | ||||
| } | ||||
| 
 | ||||
| template<typename T> | ||||
| static T op_sbb(SoftCPU& cpu, const T& dest, const T& src) | ||||
| template<typename T, bool cf> | ||||
| static T op_sbb_impl(SoftCPU& cpu, const T& dest, const T& src) | ||||
| { | ||||
|     T result = 0; | ||||
|     u32 new_flags = 0; | ||||
| 
 | ||||
|     if constexpr (cf) | ||||
|         asm volatile("stc"); | ||||
|     else | ||||
|         asm volatile("clc"); | ||||
| 
 | ||||
|     if constexpr (sizeof(T) == 4) { | ||||
|         asm volatile("sbbl %%ecx, %%eax\n" | ||||
|                      : "=a"(result) | ||||
|  | @ -374,6 +379,14 @@ static T op_sbb(SoftCPU& cpu, const T& dest, const T& src) | |||
|     return result; | ||||
| } | ||||
| 
 | ||||
| template<typename T> | ||||
| static T op_sbb(SoftCPU& cpu, T& dest, const T& src) | ||||
| { | ||||
|     if (cpu.cf()) | ||||
|         return op_sbb_impl<T, true>(cpu, dest, src); | ||||
|     return op_sbb_impl<T, false>(cpu, dest, src); | ||||
| } | ||||
| 
 | ||||
| template<typename T> | ||||
| static T op_add(SoftCPU& cpu, T& dest, const T& src) | ||||
| { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling