|
|
1.1 ! root 1: / ndpas.s - assembler support for COH386 ndp ! 2: .unixorder ! 3: .globl ndpSave ! 4: .globl ndpRestore ! 5: .globl ndpInit ! 6: .globl ndpSense ! 7: ! 8: / void ndpInit(short cw); ! 9: ndpInit: ! 10: fninit ! 11: fldcw 4(%esp); ! 12: fwait ! 13: ret ! 14: ! 15: / void ndpSave(char * bp); ! 16: ndpSave: ! 17: mov 4(%esp),%eax ! 18: fsetpm ! 19: fnsave (%eax) ! 20: fwait ! 21: ret ! 22: ! 23: / void ndpRestore(char * bp); ! 24: ndpRestore: ! 25: mov 4(%esp),%eax ! 26: fsetpm ! 27: frstor (%eax) ! 28: ret ! 29: ! 30: / int ndpSense(void) ! 31: / call this with EM bit of CR0 off! ! 32: / return values according to NDP_TYPE_* in ndp.c ! 33: ndpSense: ! 34: enter $0,$4 / reserve 4 bytes of auto storage ! 35: movl $1,%eax / ret = 1 (NDP_TYPE_NONE) ! 36: movw $0xffff,-4(%ebp) / write 2 bytes of f's ! 37: fninit / reset FP status word, if any ! 38: fnstsw -4(%ebp) / write SW to memory (should be zero) ! 39: cmpw $0,-4(%ebp) / did we clear memory? ! 40: jnz x01 / if not, NDP_TYPE_NONE ! 41: fnstcw -4(%ebp) / now try to write a control word ! 42: andw $0x103f,-4(%ebp) / mask bits not to be checked ! 43: cmpw $0x003f,-4(%ebp) ! 44: jne x01 / didn't get expected bits - no NDP ! 45: ! 46: / At this point, we know there is an NDP. ! 47: ! 48: / Is there a 486? if so, ndp type is 486DX/487SX ! 49: mov %esp,%ecx / save esp in ecx ! 50: andl $~3,%esp / round esp down to 4-byte boundary ! 51: pushfl ! 52: popl %eax / get PSW into eax ! 53: mov %eax,%edx / save original PSW to edx ! 54: xorl $0x40000,%eax / flip AC bit (only exists in 486) ! 55: andw $~0x0200,%ax / interrupts off for this! ! 56: ! 57: pushl %eax / put back into flags reg ! 58: popfl ! 59: pushfl / get flags again. ho hum. ! 60: popl %eax ! 61: ! 62: pushl %edx / restore old PSW ! 63: popfl ! 64: mov %ecx,%esp / restore old esp ! 65: ! 66: xor %edx,%eax / compare old and new PSW's ! 67: and $0x40000,%eax / only care about AC bit ! 68: movl $4,%eax / ret = NDP_TYPE_486DX ! 69: jne x01 ! 70: ! 71: / By elimination, system consists of 386 plus either 287 or 387. ! 72: / Find out which. Remember, exceptions are now masked. ! 73: fld1 ! 74: fldz ! 75: fdivr / leave 1.0/0.0 on FP stack ! 76: fld %st / duplicate infinity ! 77: fchs / negate ! 78: fcompp / compare and pop FP ! 79: fstsw -4(%ebp) / write FP flags ! 80: movw -4(%ebp),%ax ! 81: sahf / FP flags to PSW ! 82: movl $3,%eax / ret = NDP_TYPE_387 ! 83: jne x01 ! 84: dec %eax / ret = NDP_TYPE_286 ! 85: ! 86: x01: ! 87: leave ! 88: ret
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.