add IDT and add a movecursorpos funtion
This commit is contained in:
parent
b9e4cbfbe3
commit
46da32cfcc
24
src/kernel/arch/i686/idt.asm
Normal file
24
src/kernel/arch/i686/idt.asm
Normal 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
|
||||
50
src/kernel/arch/i686/idt.c
Normal file
50
src/kernel/arch/i686/idt.c
Normal 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);
|
||||
}
|
||||
|
||||
@ -2,4 +2,28 @@
|
||||
|Nanite OS |
|
||||
|Copyright (C) 2024|
|
||||
|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;
|
||||
@ -1,6 +1,18 @@
|
||||
/*----------------*\
|
||||
|Nanite OS |
|
||||
|Copyright (C) 2024|
|
||||
|Tyler McGurrin |
|
||||
\*----------------*/
|
||||
#include "hal.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();
|
||||
printf("Done!\n");
|
||||
printf("> Initializing IDT...");
|
||||
i686_IDT_Initialize();
|
||||
printf("Done!\n");
|
||||
}
|
||||
@ -1,3 +1,8 @@
|
||||
/*----------------*\
|
||||
|Nanite OS |
|
||||
|Copyright (C) 2024|
|
||||
|Tyler McGurrin |
|
||||
\*----------------*/
|
||||
#pragma once
|
||||
|
||||
void HAL_Initialize();
|
||||
@ -21,9 +21,13 @@ extern uint8_t __end;
|
||||
printf("Loaded Kernel!\n");
|
||||
|
||||
// init HAL
|
||||
printf("Initializing HAL...");
|
||||
printf("Initializing HAL...\n");
|
||||
int halx, haly = 0;
|
||||
HAL_Initialize();
|
||||
printf("Done!\n");
|
||||
movecursorpos(19, 8);
|
||||
printf("Done!\n\n\n");
|
||||
|
||||
|
||||
|
||||
end:
|
||||
for (;;);
|
||||
|
||||
@ -8,13 +8,25 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
const uint8_t DEFAULT_COLOUR = 0x7;
|
||||
|
||||
const unsigned SCREEN_WIDTH = 80;
|
||||
const unsigned SCREEN_HEIGHT = 25;
|
||||
const uint8_t DEFAULT_COLOUR = 0x7;
|
||||
|
||||
uint8_t* g_ScreenBuffer = (uint8_t*)0xB8000;
|
||||
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)
|
||||
{
|
||||
g_ScreenBuffer[2 * (y * SCREEN_WIDTH + x)] = c;
|
||||
@ -37,12 +49,12 @@ uint8_t getcolour(int x, int y)
|
||||
|
||||
void setcursor(int x, int y)
|
||||
{
|
||||
int pos = y * SCREEN_WIDTH + x;
|
||||
int pos = y * SCREEN_WIDTH + x;
|
||||
|
||||
x86_outb(0x3D4, 0x0F);
|
||||
x86_outb(0x3D5, (uint8_t)(pos & 0xFF));
|
||||
x86_outb(0x3D4, 0x0E);
|
||||
x86_outb(0x3D5, (uint8_t)((pos >> 8) & 0xFF));
|
||||
x86_outb(0x3D4, 0x0F);
|
||||
x86_outb(0x3D5, (uint8_t)(pos & 0xFF));
|
||||
x86_outb(0x3D4, 0x0E);
|
||||
x86_outb(0x3D5, (uint8_t)((pos >> 8) & 0xFF));
|
||||
}
|
||||
|
||||
void clrscr()
|
||||
|
||||
@ -6,9 +6,11 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
void clrscr();
|
||||
void putc(char c);
|
||||
void puts(const char* str);
|
||||
void printf(const char* fmt, ...);
|
||||
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
9
src/kernel/util/binary.h
Normal 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)
|
||||
Loading…
x
Reference in New Issue
Block a user