![]() I'm using assembly language for now, in order to keep us clear of compilation issues and symbols that come up when we get into C code. Prepare arguments for the sys_write system call: The _start symbol must be declared for the linker (ld) We'll come back to it later in this article. The part in parens is important, but it's still too early to explain it. (This one byte form is valuable because it can be used to replace the first byte of any instruction with a breakpoint, including other one byte instructions, without over-writing other code). The INT 3 instruction generates a special one byte opcode (CC) that is intended for calling the debug exception handler. Without further ado, I'll quote from the bible itself : The first 32 are reserved by the CPU for itself, and number 3 is the one we're interested in here - it's called "trap to debugger". x86 supports the int instruction with a 8-bit operand specifying the number of the interrupt that occurred, so in theory 256 traps are supported. int is x86 jargon for "trap instruction" - a call to a predefined interrupt handler. Having written the previous section, I can now simply say that breakpoints are implemented on the CPU by a special trap called int 3. But I've digressed too far away from the main topic, so it's time to get back to breakpoints. Here the line between hardware and software blurs, since it's hard to say whether such exceptions are really hardware interrupts or software interrupts. Some programming errors (such as division by 0) are also treated by the CPU as traps, and are frequently referred to as "exceptions". Such "traps" allow many of the wonders of modern OSes (task scheduling, virtual memory, memory protection, debugging) to be implemented efficiently. When such an instruction is executed, the CPU treats it like an interrupt - stops its normal flow of execution, saves its state and jumps to a handler routine. CPUs support special instructions that allow the software to simulate an interrupt. Software interrupts are similar in principle but a bit different in practice. When the handler finishes its work, the CPU resumes execution from where it stopped. This circuitry notices an activation of the interrupt and makes the CPU stop its current execution, save its state, and jump to a predefined address where a handler routine for the interrupt is located. A hardware interrupt is usually a dedicated electrical signal to which a special "response circuitry" is attached. To handle asynchronous events like IO and hardware timers, CPUs use interrupts. Before we get deep into the details, I want to explain the concept of interrupts and traps in general.Ī CPU has a single stream of execution, working through instructions one by one. To implement breakpoints on the x86 architecture, software interrupts (also known as "traps") are used.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |