move version to its own file, and uhhhhh add GDT..? (also started HAL and IDT)
This commit is contained in:
parent
4d55b05585
commit
b9e4cbfbe3
@ -10,9 +10,7 @@
|
||||
#include "fat.h"
|
||||
#include "memdefs.h"
|
||||
#include "memory.h"
|
||||
|
||||
#define LOGO " _ _____ _ __________________\n / | / / | / | / / _/_ __/ ____/\n / |/ / /| | / |/ // / / / / __/ \n / /| / ___ |/ /| // / / / / /___ \n/_/ |_/_/ |_/_/ |_/___/ /_/ /_____/ \n"
|
||||
#define VERSION "v0.0.1"
|
||||
#include "../../version.h"
|
||||
|
||||
|
||||
uint8_t* KernelLoadBuffer = (uint8_t*)MEMORY_LOAD_KERNEL;
|
||||
@ -32,8 +30,8 @@ void* g_data = (void*)0x20000;
|
||||
void __attribute__((cdecl)) start(uint16_t bootDrive) {
|
||||
// Clear screen and Print Startup logo
|
||||
clrscr();
|
||||
printf("%s", LOGO);
|
||||
printf("The Nano OS %s\n-------------------------------------\n", VERSION);
|
||||
printf("%s", BOOTLOGO);
|
||||
printf("The Nano Loader %s\n------------------------------\n", VERSION);
|
||||
|
||||
// Test Real Mode
|
||||
printf("Testing Real Mode...");
|
||||
|
||||
40
src/kernel/arch/i686/gdt.asm
Normal file
40
src/kernel/arch/i686/gdt.asm
Normal file
@ -0,0 +1,40 @@
|
||||
;/////////////////////;
|
||||
;Nanite OS ;
|
||||
;COPYRIGHT (C) 2024 ;
|
||||
;Tyler McGurrin ;
|
||||
;/////////////////////;
|
||||
[bits 32]
|
||||
|
||||
; void __attribute__((cdecl)) i686_GDT_Load(GDTDescriptor* descriptor, uint16_t codeSegment, uint16_t dataSegment);
|
||||
global i686_GDT_Load
|
||||
i686_GDT_Load:
|
||||
; make new call frame
|
||||
push ebp ; save old call frame
|
||||
mov ebp, esp ; initialize new call frame
|
||||
|
||||
; load GDT
|
||||
mov eax, [ebp + 8]
|
||||
lgdt [eax]
|
||||
|
||||
; Reload Code Segment
|
||||
mov eax, [ebp + 12]
|
||||
push eax
|
||||
push .reload_cs
|
||||
retf
|
||||
|
||||
.reload_cs:
|
||||
|
||||
; reload data segments
|
||||
mov ax, [ebp + 16]
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax,
|
||||
mov ss, ax
|
||||
|
||||
|
||||
|
||||
; restore old call frame
|
||||
mov esp, ebp
|
||||
pop ebp
|
||||
ret
|
||||
92
src/kernel/arch/i686/gdt.c
Normal file
92
src/kernel/arch/i686/gdt.c
Normal file
@ -0,0 +1,92 @@
|
||||
/*----------------*\
|
||||
|Nanite OS |
|
||||
|Copyright (C) 2024|
|
||||
|Tyler McGurrin |
|
||||
\*----------------*/
|
||||
#include "gdt.h"
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
uint16_t LimitLow;
|
||||
uint16_t BaseLow;
|
||||
uint8_t BaseMiddle;
|
||||
uint8_t Access;
|
||||
uint8_t FlagsLimitHi;
|
||||
uint8_t BaseHigh;
|
||||
} __attribute__((packed)) GDTEntry;
|
||||
|
||||
typedef struct {
|
||||
uint16_t Limit;
|
||||
GDTEntry* Ptr;
|
||||
} __attribute__((packed)) GDTDescriptor;
|
||||
|
||||
typedef enum {
|
||||
GDT_ACCESS_CODE_READABLE = 0x02,
|
||||
GDT_ACCESS_DATA_WRITEABLE = 0x02,
|
||||
|
||||
GDT_ACCESS_CODE_CONFORMING = 0x04,
|
||||
GDT_ACCESS_DATA_DIRECTION_NORMAL = 0x00,
|
||||
GDT_ACCESS_DATA_DIRECTION_DOWN = 0x04,
|
||||
|
||||
GDT_ACCESS_DATA_SEGMENT = 0x10,
|
||||
GDT_ACCESS_CODE_SEGMENT = 0x18,
|
||||
|
||||
GDT_ACCESS_DESCRIPTOR_TSS = 0x00,
|
||||
|
||||
GDT_ACCESS_RING0 = 0x00,
|
||||
GDT_ACCESS_RING1 = 0x20,
|
||||
GDT_ACCESS_RING2 = 0x40,
|
||||
GDT_ACCESS_RING3 = 0x60,
|
||||
|
||||
GDT_ACCESS_PRESENT = 0x80,
|
||||
|
||||
} GDT_ACCESS;
|
||||
|
||||
typedef enum {
|
||||
GDT_FLAG_64BIT = 0x20,
|
||||
GDT_FLAG_32BIT = 0x40,
|
||||
GDT_FLAG_16BIT = 0x00,
|
||||
|
||||
GDT_FLAG_GRANULARITY_1B = 0x00,
|
||||
GDT_FLAG_GRANULARITY_4k = 0x80,
|
||||
} GDT_FLAGS;
|
||||
|
||||
// macros!
|
||||
|
||||
#define GDT_LIMIT_LOW(limit) (limit & 0xFFFF)
|
||||
#define GDT_BASE_LOW(base) (base & 0xFFFF)
|
||||
#define GDT_BASE_MIDDLE(base) ((base >> 16) & 0xFF)
|
||||
#define GDT_FLAGS_LIMIT_HI(limit, flags)(((limit >> 16) & 0xF) | (flags & 0xF0))
|
||||
#define GDT_BASE_HIGH(base) ((base >> 24) & 0xFF)
|
||||
|
||||
#define GDT_ENTRY(base, limit, access, flags){ \
|
||||
GDT_LIMIT_LOW(limit), \
|
||||
GDT_BASE_LOW(base), \
|
||||
GDT_BASE_MIDDLE(base), \
|
||||
access, \
|
||||
GDT_FLAGS_LIMIT_HI(limit, flags), \
|
||||
GDT_BASE_HIGH(base) \
|
||||
}
|
||||
GDTEntry g_GDT[] = {
|
||||
// NULL
|
||||
GDT_ENTRY(0, 0, 0, 0),
|
||||
|
||||
// 32-bit kernel code
|
||||
GDT_ENTRY(0,
|
||||
0xFFFFF,
|
||||
GDT_ACCESS_PRESENT | GDT_ACCESS_RING0 | GDT_ACCESS_CODE_SEGMENT | GDT_ACCESS_CODE_READABLE,
|
||||
GDT_FLAG_32BIT | GDT_FLAG_GRANULARITY_4k),
|
||||
// 32-bit data segment
|
||||
GDT_ENTRY(0,
|
||||
0xFFFFF,
|
||||
GDT_ACCESS_PRESENT | GDT_ACCESS_RING0 | GDT_ACCESS_DATA_SEGMENT | GDT_ACCESS_DATA_WRITEABLE,
|
||||
GDT_FLAG_32BIT | GDT_FLAG_GRANULARITY_4k),
|
||||
};
|
||||
|
||||
GDTDescriptor g_GDTDescriptor = { sizeof(g_GDT) - 1, g_GDT};
|
||||
|
||||
void __attribute__((cdecl)) i686_GDT_Load(GDTDescriptor* descriptor, uint16_t codeSegment, uint16_t dataSegment);
|
||||
|
||||
void i686_GDT_Initialize() {
|
||||
i686_GDT_Load(&g_GDTDescriptor, i686_GDT_CODE_SEGMENT, i686_GDT_DATA_SEGMENT);
|
||||
}
|
||||
11
src/kernel/arch/i686/gdt.h
Normal file
11
src/kernel/arch/i686/gdt.h
Normal file
@ -0,0 +1,11 @@
|
||||
/*----------------*\
|
||||
|Nanite OS |
|
||||
|Copyright (C) 2024|
|
||||
|Tyler McGurrin |
|
||||
\*----------------*/
|
||||
#pragma once
|
||||
|
||||
#define i686_GDT_CODE_SEGMENT 0x8
|
||||
#define i686_GDT_DATA_SEGMENT 0x10
|
||||
|
||||
void i686_GDT_Initialize();
|
||||
5
src/kernel/arch/i686/idt.h
Normal file
5
src/kernel/arch/i686/idt.h
Normal file
@ -0,0 +1,5 @@
|
||||
/*----------------*\
|
||||
|Nanite OS |
|
||||
|Copyright (C) 2024|
|
||||
|Tyler McGurrin |
|
||||
\*----------------*/
|
||||
6
src/kernel/hal/hal.c
Normal file
6
src/kernel/hal/hal.c
Normal file
@ -0,0 +1,6 @@
|
||||
#include "hal.h"
|
||||
#include <arch/i686/gdt.h>
|
||||
|
||||
void HAL_Initialize() {
|
||||
i686_GDT_Initialize();
|
||||
}
|
||||
3
src/kernel/hal/hal.h
Normal file
3
src/kernel/hal/hal.h
Normal file
@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
void HAL_Initialize();
|
||||
@ -5,19 +5,25 @@
|
||||
\*----------------*/
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <memory.h"
|
||||
|
||||
#define LOGO " _ _____ _ __________________\n / | / / | / | / / _/_ __/ ____/\n / |/ / /| | / |/ // / / / / __/ \n / /| / ___ |/ /| // / / / / /___ \n/_/ |_/_/ |_/_/ |_/___/ /_/ /_____/ \n"
|
||||
#define VERSION "v0.0.1"
|
||||
#include <memory.h>
|
||||
#include <hal/hal.h>
|
||||
#include "../version.h"
|
||||
|
||||
extern uint8_t __bss_start;
|
||||
extern uint8_t __end;
|
||||
|
||||
void __attribute__((section(".entry"))) start(uint16_t bootDrive) {
|
||||
|
||||
// print logo
|
||||
clrscr();
|
||||
printf("%s", LOGO);
|
||||
printf("The Nano OS %s\n-------------------------------------\n", VERSION);
|
||||
printf("Kernel Loaded!");
|
||||
printf("Loaded Kernel!\n");
|
||||
|
||||
// init HAL
|
||||
printf("Initializing HAL...");
|
||||
HAL_Initialize();
|
||||
printf("Done!\n");
|
||||
|
||||
end:
|
||||
for (;;);
|
||||
|
||||
10
src/version.h
Normal file
10
src/version.h
Normal file
@ -0,0 +1,10 @@
|
||||
/*----------------*\
|
||||
|Nanite OS |
|
||||
|Copyright (C) 2024|
|
||||
|Tyler McGurrin |
|
||||
\*----------------*/
|
||||
#pragma once
|
||||
|
||||
#define LOGO " _ _____ _ __________________\n / | / / | / | / / _/_ __/ ____/\n / |/ / /| | / |/ // / / / / __/ \n / /| / ___ |/ /| // / / / / /___ \n/_/ |_/_/ |_/_/ |_/___/ /_/ /_____/ \n"
|
||||
#define VERSION "v0.0.1"
|
||||
#define BOOTLOGO " _ ______ ____ ____ ______\n / | / / __ )/ __ \\/ __ /_ __/\n / |/ / __ / / / / / / // / \n / /| / /_/ / /_/ / /_/ // / \n/_/ |_/_____/\\____/\\____//_/ \n"
|
||||
Loading…
x
Reference in New Issue
Block a user