Thiết kế và lập trình hệ thống - Chương 25

10 405 0
Thiết kế và lập trình hệ thống - Chương 25

Đang tải... (xem toàn văn)

Thông tin tài liệu

Thiết kế và lập trình hệ thống - Chương25

Systems Programming 80x86 Assembly VII CMPE 3101 (March 27, 2000 10:41 pm)UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6Intel AssemblyProcedures:CALL: Pushes the address of the instruction following the CALL instruc-tion onto the stack.RET: Pops the address.NEAR CALL:Similar to NEAR jump instruction, e.g. 2nd and 3rd bytes of instruc-tion contain displacement added to IP.FAR CALL:Similar to FAR jump instruction, e.g. 2nd and 3rd bytes of instructioncontain new IP while 4th and 5th bytes contain CS.CALL BX and CALL [BX] versions also exist.SUM PROC NEAR USES BX CX DXADD AX, BXADD AX, CXMOV AX, DXSUM ENDPRET Systems Programming 80x86 Assembly VII CMPE 3102 (March 27, 2000 10:41 pm)UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6Intel AssemblyInterrupts:Hardware generated CALL: I/O DeviceSoftware generated CALL: Internally derived from an instruction orexception.We will look at both of these.Interrupt Vectors:Real Mode: A 4 byte number stored in the first 1024 bytes of memory.Protected Mode: A interrupt descriptor table is used instead.Each descriptor is 8 bytes long.There are 256 interrupt vectors.Intel reserves the 0-31.Interrupts 33-255 are user definable.Vectors 1-6, 7, 9, 16 and 17 function in real and protected mode.The rest function only in protected mode. Systems Programming 80x86 Assembly VII CMPE 3103 (March 27, 2000 10:41 pm)UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6Intel AssemblyInterrupt Vectors:Number Address Microprocessor Function0 00-03 All Divide error1 04-07 All Single step2 08-0B All NMI pin3 0C-0F All Breakpoint4 10-13 All Interrupt on overflow5 14-17 80186-Pentium Bound instruction (print screen)6 18-1B 80186-Pentium Invalid opcode7 1C-1F 80186-Pentium Coprocessor emulation8 20-23 80386-Pentium Double fault (clock tick)9 24-27 80386 Coprocessor segment overrun (keyboard)A 28-2B 80386-Pentium Invalid task state segment (IRQ2)B 2C-2F 80386-Pentium Segment not present (IRQ3)C 30-33 80386-Pentium Stack fault (IRQ4)D 34-37 80386-Pentium General protection fault (IRQ5)E 38-3B 80386-Pentium Page fault (IRQ6)F 3C-3F ----- Reserved (IRQ7)10 40-43 80286-Pentium Floating-point error (Video)11 44-47 80486SX Alignment check interrupt12 48-4F Pentium Machine check exception13-1F 50-7F --- Reserved Systems Programming 80x86 Assembly VII CMPE 3104 (March 27, 2000 10:41 pm)UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6Intel AssemblyInterrupt Instructions.Real mode: Fetches a vector from the vector table (address of ISR).Protected mode: Fetches an interrupt descriptor (contains addr of ISR).Similar to a FAR CALL: pushes both IP/EIP and CS onto stack.3 types are available:• INTThere are 256 software interrupt instructions.The INT instruction takes a numeric operand: 0-255.Real mode: It’s multiplied by 4 to get address of vector.Protected mode: It’s multiplied by 8 (descriptors are 8 bytes long). Systems Programming 80x86 Assembly VII CMPE 3105 (March 27, 2000 10:41 pm)UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6Intel AssemblyINT Instruction.Processing sequence for an INT instruction:• Push FLAGS.• Clear T and I flag bits (hardware interrupts disabled).• Push CS.• Fetch new value for CS from interrupt vector.• Push IP/EIP.• Fetches new value of IP/EIP from vector.• Jump to new location.INT instruction is 2 bytes long.Replaces FAR CALL, which is 5 bytes long.Commonly used to call system functions. Decouples programs fromsystem function addresses.IRET(Real)/IRETD(Protected):Undoes call: POP IP/EIP, POP CS, POP FLAGSPopping FLAGS restores T and I bits. Systems Programming 80x86 Assembly VII CMPE 3106 (March 27, 2000 10:41 pm)UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6Intel AssemblyInterrupt Instructions.2nd type: INTOInterrupt on overflow.Conditional software interrupt that tests the overflow flag (O).If O=0, INTO does nothing.If O=1, the procedure at interrupt vector 4 is called.3rd type: INT3Designed to function like a breakpoint to debug software.It is a 1 byte instruction.Form of an ISR:ISR PROC FAR .ISR ENDPIRET;Pops EIP, CS and FLAGS Systems Programming 80x86 Assembly VII CMPE 3107 (March 27, 2000 10:41 pm)UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6Intel AssemblyHardware Interrupt Control.STI: Places a 1 into the I flag, this enables interr upts.CLI: Places a 0 there, disabling interrupts.Miscellaneous Machine Instructions: STC (set carry), CLC (clear carry) and CMC (complement carry)In addition to propagating carry and borrow in multiple-word/dou-ble-word addition, these are used to return error conditions in sys-tem calls.C = 1: Error occurred.C = 0: No error occurred. HLTStops instruction execution.Three ways to resume execution: interrupt, hardware reset or DMAoperation.Used to synchronize hardware interrupts with system software. Systems Programming 80x86 Assembly VII CMPE 3108 (March 27, 2000 10:41 pm)UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6Intel AssemblyMiscellaneous Machine Instructions. LOCK Prefi x:Appended to an instruction.Toggle the LOCK pin, disabling external bus masters and otherperipherials. ENTER/LEAVEUsed with stack frames, which provide a mechanism to pass stackparameters and allocate storage for local variables for procedures.ENTER pushes BP, and loads BP with the uppermost address of stackframe.Stack variables can then be accessed through the BP register.LEAVE restores previous values of BP and SP, e.g.MOV SP BPPOP BP Systems Programming 80x86 Assembly VII CMPE 3109 (March 27, 2000 10:41 pm)UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6Intel AssemblyENTER/LEAVE:EAXEBXECXEDXESPEBPEDIESICSDSESSSStack Seg3 0 0 0ENTER 8, 0+3FFFCOld BPF F F A3FFFA1) Push oldF F F C*10H3FFFCold SP3FFF83FFF63FFF43FFF22) Set BP3) AllocateStackFrameFFFABPFFF2 Systems Programming 80x86 Assembly VII CMPE 31010 (March 27, 2000 10:41 pm)UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6Intel AssemblyENTER/LEAVE:ENTER 4, 0MOV AX, DATA1MOV [BP-4], AXMOV [BP-2], AXMOV AX, DATA2CALL SYSMOV AX, [BP-4];Save parameters on the stack.;System call that uses stack;parametersMOV RES1, AX;Get resultsMOV AX, [BP-2]MOV RES2, AXLEAVESYS PROC NEAR .;Other code continues here.PUSHAMOV AX, [BP-4]MOV BX, [BP-2] . . 3 4-3 7 80386-Pentium General protection fault (IRQ5)E 3 8-3 B 80386-Pentium Page fault (IRQ6)F 3C-3F -- -- - Reserved (IRQ7)10 4 0-4 3 80286-Pentium Floating-point. (print screen)6 1 8-1 B 80186-Pentium Invalid opcode7 1C-1F 80186-Pentium Coprocessor emulation8 2 0-2 3 80386-Pentium Double fault (clock tick)9 2 4-2 7 80386 Coprocessor

Ngày đăng: 15/11/2012, 11:07

Tài liệu cùng người dùng

Tài liệu liên quan