Build your own Operating System #5

IDT from the Intel Architecture Software Developer Manual
Bit:    |   31 … 16   | 15| 14 13|12 | 11 |10 9 8 |7 6 5 |4 3 2 1 0|Content:| offset high | P | DPL  | 0 | D  | 1 1 0 | 0 0 0| reserved|
Bit:     |     31 ……… 16    |   15 ……… 0  |Content: | segment selector | offset low  |
  Name                       Descriptionoffset high       The 16 highest bits of the 32 bit address in the segment.offset low        The 16 lowest bits of the 32 bits address in the segment.   p              If the handler is present in memory or not (1 = present, 0 = not present).  DPL             Descriptor Privilige Level, the privilege level the handler can be called from (0, 1, 2, 3).   D              Size of gate, (1 = 32 bits, 0 = 16 bits).segment selector  The offset in the GDT.   r              Reserved.
0xDEAD8E000x0008BEEF
idt[0] = 0xDEAD8E00idt[1] = 0x0008BEEF
[esp + 12] eflags[esp + 8] cs[esp + 4] eip[esp] error code?
struct cpu_state {    unsigned int eax;    unsigned int ebx;    unsigned int ecx;    .    .    .    unsigned int esp;} __attribute__((packed));struct stack_state {    unsigned int error_code;    unsigned int eip;    unsigned int cs;    unsigned int eflags;} __attribute__((packed));void interrupt_handler(struct cpu_state cpu, struct stack_state stack, unsigned int interrupt);
#include “io.h”#define KEYBOARD_DATA_PORT 0x60/** read_scan_code:* Reads a scan code from the keyboard** @return The scan code (NOT an ASCII character!)*/unsigned char keyboard_read_scan_code(void){    return inb(KEYBOARD_DATA_PORT);}

--

--

--

Software Engineering Undergraduate - University of Kelaniya, Sri Lanka

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

7 Best Practices for building performant Microservices

How I Stay Informed as a Developer

5 reasons why you should use Tailwind CSS

Code with the stabilisers

Growing as a software engineer

ROVI Update #3 | Hologram and Fabricator META | Spectate to Earn

Script Communication in Unity using GetComponent

AMLSim Fraud Detection with TigerGraph and Google Vertex Part I: Preparing the Data

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Gayan Malinda

Gayan Malinda

Software Engineering Undergraduate - University of Kelaniya, Sri Lanka

More from Medium

Using Drafts App With Obsidian: What’s The Big Deal?

Getting Started with FreeRTOS on I.MX8M Mini through UBoot with Linux

Talk: Scaling Babylon’s Workflow Platform

2 years in Lego