add IDT and add a movecursorpos funtion

This commit is contained in:
Tyler McGurrin 2024-12-18 18:26:45 -05:00
parent b9e4cbfbe3
commit 46da32cfcc
9 changed files with 153 additions and 11 deletions

View File

@ -0,0 +1,24 @@
;/////////////////////;
;Nanite OS ;
;COPYRIGHT (C) 2024 ;
;Tyler McGurrin ;
;/////////////////////;
[bits 32]
;void __attribute__((cdecl)) i686_IDT_Load(IDTDescriptor* idtDescriptor);
global i686_IDT_Load
i686_IDT_Load:
; make new call frame
push ebp ; save old call frame
mov ebp, esp ; initialize new call frame
; load IDT
mov eax, [ebp + 8]
lgdt [eax]
; restore old call frame
mov esp, ebp
pop ebp
ret

View File

@ -0,0 +1,50 @@
/*----------------*\
|Nanite OS |
|Copyright (C) 2024|
|Tyler McGurrin |
\*----------------*/
#include "idt.h"
#include <stdint.h>
#include <util/binary.h>
typedef struct {
uint16_t BaseLow;
uint16_t SegmentSelector;
uint8_t Reserved;
uint8_t Flags;
uint16_t BaseHigh;
} __attribute__((packed)) IDTEntry;
typedef struct {
uint16_t Limit;
IDTEntry* Ptr;
} __attribute__((packed)) IDTDescriptor;
IDTEntry g_IDT[256];
IDTDescriptor g_IDTDescriptor = {sizeof(g_IDT) -1, g_IDT};
void __attribute__((cdecl)) i686_IDT_Load(IDTDescriptor* idtDescriptor);
void i686_IDT_SetGate(int interupt, void* base, uint16_t segmentDescriptor, uint8_t flags) {
g_IDT[interupt].BaseLow = ((uint32_t)base) & 0xFFFF;
g_IDT[interupt].SegmentSelector = segmentDescriptor;
g_IDT[interupt].Reserved = 0;
g_IDT[interupt].Flags = flags;
g_IDT[interupt].BaseHigh = ((uint32_t)base >> 16) & 0xFFFF;
}
void i686_IDT_EnableGate(int interupt) {
FLAG_SET(g_IDT[interupt].Flags, IDT_FLAG_PRESENT);
}
void i686_IDT_DisableGate(int interupt) {
FLAG_UNSET(g_IDT[interupt].Flags, IDT_FLAG_PRESENT);
}
void i686_IDT_Initialize() {
i686_IDT_Load(&g_IDTDescriptor);
}

View File

@ -3,3 +3,27 @@
|Copyright (C) 2024| |Copyright (C) 2024|
|Tyler McGurrin | |Tyler McGurrin |
\*----------------*/ \*----------------*/
#pragma once
#include <stdint.h>
void i686_IDT_Initialize();
void i686_IDT_DisableGate(int interupt);
void i686_IDT_EnableGate(int interupt);
void i686_IDT_SetGate(int interupt, void* base, uint16_t segmentDescriptor, uint8_t flags);
typedef enum {
IDT_FLAG_GATE_TASK = 0x5,
IDT_FLAG_GATE_16BIT_INT = 0x6,
IDT_FLAG_GATE_16BIT_TRAP = 0x7,
IDT_FLAG_GATE_32BIT_INT = 0xE,
IDT_FLAG_GATE_32BIT_TRAP = 0xF,
IDT_FLAG_RING0 = (0 << 5),
IDT_FLAG_RING1 = (1 << 5),
IDT_FLAG_RING2 = (2 << 5),
IDT_FLAG_RING3 = (3 << 5),
IDT_FLAG_PRESENT = 0x80,
} IDT_FLAGS;

View File

@ -1,6 +1,18 @@
/*----------------*\
|Nanite OS |
|Copyright (C) 2024|
|Tyler McGurrin |
\*----------------*/
#include "hal.h" #include "hal.h"
#include <arch/i686/gdt.h> #include <arch/i686/gdt.h>
#include <arch/i686/idt.h>
#include <stdio.h>
void HAL_Initialize() { void HAL_Initialize() {
printf("> Initializing GDT...");
i686_GDT_Initialize(); i686_GDT_Initialize();
printf("Done!\n");
printf("> Initializing IDT...");
i686_IDT_Initialize();
printf("Done!\n");
} }

View File

@ -1,3 +1,8 @@
/*----------------*\
|Nanite OS |
|Copyright (C) 2024|
|Tyler McGurrin |
\*----------------*/
#pragma once #pragma once
void HAL_Initialize(); void HAL_Initialize();

View File

@ -21,9 +21,13 @@ extern uint8_t __end;
printf("Loaded Kernel!\n"); printf("Loaded Kernel!\n");
// init HAL // init HAL
printf("Initializing HAL..."); printf("Initializing HAL...\n");
int halx, haly = 0;
HAL_Initialize(); HAL_Initialize();
printf("Done!\n"); movecursorpos(19, 8);
printf("Done!\n\n\n");
end: end:
for (;;); for (;;);

View File

@ -8,13 +8,25 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h> #include <stdbool.h>
const uint8_t DEFAULT_COLOUR = 0x7;
const unsigned SCREEN_WIDTH = 80; const unsigned SCREEN_WIDTH = 80;
const unsigned SCREEN_HEIGHT = 25; const unsigned SCREEN_HEIGHT = 25;
const uint8_t DEFAULT_COLOUR = 0x7;
uint8_t* g_ScreenBuffer = (uint8_t*)0xB8000; uint8_t* g_ScreenBuffer = (uint8_t*)0xB8000;
int g_ScreenX = 0, g_ScreenY = 0; int g_ScreenX = 0, g_ScreenY = 0;
void movecursorpos(int x, int y) {
g_ScreenX = x;
g_ScreenY = y;
}
void getcursorpos(int x, int y) {
x = g_ScreenX;
y = g_ScreenY;
}
void putchr(int x, int y, char c) void putchr(int x, int y, char c)
{ {
g_ScreenBuffer[2 * (y * SCREEN_WIDTH + x)] = c; g_ScreenBuffer[2 * (y * SCREEN_WIDTH + x)] = c;

View File

@ -6,9 +6,11 @@
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>
void clrscr(); void clrscr();
void putc(char c); void putc(char c);
void puts(const char* str); void puts(const char* str);
void printf(const char* fmt, ...); void printf(const char* fmt, ...);
void print_buffer(const char* msg, const void* buffer, uint32_t count); void print_buffer(const char* msg, const void* buffer, uint32_t count);
void setcursor(int x, int y); void movecursorpos(int x, int y);
void getcursorpos(int x, int y);

9
src/kernel/util/binary.h Normal file
View File

@ -0,0 +1,9 @@
/*----------------*\
|Nanite OS |
|Copyright (C) 2024|
|Tyler McGurrin |
\*----------------*/
#pragma once
#define FLAG_SET(x, flag) x |= (flag)
#define FLAG_UNSET(x, flag) x &= ~(flag)