x86 Handling Exceptions

x86 Handling Exceptions

In previous article we got our CPU into 64 bit mode and were able to run 64 bit programs. Our vCPU is already very useful but it doesn't deal well with issues like division by zero.

In previous article we got our CPU into 64 bit mode and were able to run 64 bit programs. Our vCPU is already very useful but it doesn't deal well with issues like division by zero, page faults or other exceptional cases it might encounter.

Division by zero and page faults are examples of exceptions. Exceptions can happen at any point in time during operation of the processor and they signify an event that needs attention of the processor.

Because the idea of this series of posts is learning we will focus on one of the simpler exceptions - division by zero. After working through this article you should be able to extend the code to handle other exceptions, interrupts or traps.

Triggering interrupts

Division by zero can be solved in software by first checking if divider is equal to zero. If it is, we use INT instruction to trigger an exception. It can also be triggered by CPU automatically. In case of software generated interrupt it's up to us to decide which interrupt handler to use to deal with divide by zero issue. When CPU triggers the handler it choses handler at predefined location.

Exception handlers are normally found via so called Interrupt Descriptor Table or IDT for short. IDT contains up to 256 entries and each of those entries is 16 bytes in size in 64 bit mode. When using software interrupts we can choose any of the entries to place our exception handler but it is customary to have "divide by zero" error as the first entry (index = 0). It also allows us to use the same handler for software generated interrupt as well as hardware generated one.

x86 virtualization assembly nest

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

16/32/64 Bit Assembly Programs

Ok so before we move on and jump into writing and running 64 bit programs (because all programs today are 64bit these days no? j.k.) let's have a look how to compile a simple program for each of those architectures. This knowledge should also help you better understand how to start a nano VM and "debug" problems that might arise.

Virtual Sports Betting Software Development | Virtual Sports Betting Solutions

Get premium virtual sports betting software development solutions from the number one betting software provider company with extensive features and affordable price

On Learning To Use A Virtual Machine

Never used one before the course required me to use one. You might have heard JVM (Java Virtual Machine) coming with the JDK (Java Development Kit) and JRE (Java Runtime Environment). And we have Oracle’s Virtual Box that is equipped with having multiple virtual machines being stored and used if necessary. Now, let’s go into details about how you can use various virtual machines.

Nested class In Java Example | Java Nested Class Tutorial

Java Nested class is defined when a class is present/define within another class. The scope of the nested class is defined within the curly bracket.

How to Install and Configure Kubectl: A Tutorial

Kubectl is a command-line tool for Kubernetes. It allows us to execute Kubernetes operations via the API. We can use Kubectl to deploy apps, check logs as well as manage all the other resources of the cluster.In this article, we will review Kubectl, and outline its installation, configuration, and use.