make arch specific stuff better

This commit is contained in:
Xircon 2026-03-08 09:59:16 -04:00
parent 81c7f94632
commit ab0b7adb7a
31 changed files with 245 additions and 30 deletions

3
.ccls
View File

@ -1,4 +1,5 @@
clang
%c -std=c99
%c -isystem./src/kernel/
%c -fno-builtin
%c -fno-builtin
%c -D__I686

View File

@ -1,5 +1,5 @@
TARGET_ASMFLAGS += -f elf
TARGET_CFLAGS += -ffreestanding -nostdlib -I.
TARGET_CFLAGS += -ffreestanding -nostdlib -I. -D__I686
TARGET_LIBS += -lgcc
TARGET_LINKFLAGS += -T linker.ld -nostdlib

View File

@ -2,4 +2,20 @@
;Nanite OS ;
;COPYRIGHT (C) 2026 ;
;Xircon ;
;/////////////////////;
;/////////////////////;
global CPUID_Check_Supported
CPUID_Check_Supported:
pushfd ;Save EFLAGS
pushfd ;Store EFLAGS
xor dword [esp],0x00200000 ;Invert the ID bit in stored EFLAGS
popfd ;Load stored EFLAGS (with ID bit inverted)
pushfd ;Store EFLAGS again (ID bit may or may not be inverted)
pop eax ;eax = modified EFLAGS (ID bit may or may not be inverted)
xor eax,[esp] ;eax = whichever bits were changed
popfd ;Restore original EFLAGS
and eax,0x00200000 ;eax = zero if ID bit can't be changed, else non-zero
ret
global CPUID_Gather_Info
CPUID_Gather_Info:

View File

@ -0,0 +1,23 @@
/*----------------*\
|Nanite OS |
|Copyright (C) 2026|
|Xircon |
\*----------------*/
#ifdef __I686
#include "cpuid.h"
#include <stdint.h>
char CPUID_Get_Vendor() {
uint32_t eax, ebx, ecx, edx;
eax = 0x00;
ecx = 0x0;
__asm__ volatile (
"cpuid"
: "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
: "a"(eax), "c"(ecx)
);
char returnme = ebx+ecx+edx;
return ebx;
}
#endif

View File

@ -2,4 +2,116 @@
|Nanite OS |
|Copyright (C) 2026|
|Xircon |
\*----------------*/
\*----------------*/
#ifdef __I686
#pragma once
#include <stdint.h>
// Vendor strings from CPUs.
#define CPUID_VENDOR_AMD "AuthenticAMD"
#define CPUID_VENDOR_AMD_OLD "AMDisbetter!" // Early engineering samples of AMD K5 processor
#define CPUID_VENDOR_INTEL "GenuineIntel"
#define CPUID_VENDOR_VIA "VIA VIA VIA "
#define CPUID_VENDOR_TRANSMETA "GenuineTMx86"
#define CPUID_VENDOR_TRANSMETA_OLD "TransmetaCPU"
#define CPUID_VENDOR_CYRIX "CyrixInstead"
#define CPUID_VENDOR_CENTAUR "CentaurHauls"
#define CPUID_VENDOR_NEXGEN "NexGenDriven"
#define CPUID_VENDOR_UMC "UMC UMC UMC "
#define CPUID_VENDOR_SIS "SiS SiS SiS "
#define CPUID_VENDOR_NSC "Geode by NSC"
#define CPUID_VENDOR_RISE "RiseRiseRise"
#define CPUID_VENDOR_VORTEX "Vortex86 SoC"
#define CPUID_VENDOR_AO486 "MiSTer AO486"
#define CPUID_VENDOR_AO486_OLD "GenuineAO486"
#define CPUID_VENDOR_ZHAOXIN " Shanghai "
#define CPUID_VENDOR_HYGON "HygonGenuine"
#define CPUID_VENDOR_ELBRUS "E2K MACHINE "
// Vendor strings from hypervisors.
#define CPUID_VENDOR_QEMU "TCGTCGTCGTCG"
#define CPUID_VENDOR_KVM " KVMKVMKVM "
#define CPUID_VENDOR_VMWARE "VMwareVMware"
#define CPUID_VENDOR_VIRTUALBOX "VBoxVBoxVBox"
#define CPUID_VENDOR_XEN "XenVMMXenVMM"
#define CPUID_VENDOR_HYPERV "Microsoft Hv"
#define CPUID_VENDOR_PARALLELS " prl hyperv "
#define CPUID_VENDOR_PARALLELS_ALT " lrpepyh vr " // Sometimes Parallels incorrectly encodes "prl hyperv" as "lrpepyh vr" due to an endianness mismatch.
#define CPUID_VENDOR_BHYVE "bhyve bhyve "
#define CPUID_VENDOR_QNX " QNXQVMBSQG "
extern int CPUID_Check_Supported();
extern char CPUID_Get_Vendor();
enum {
CPUID_FEAT_EBX_BRAND_INDEX = 0xFF << 0,
CPUID_FEAT_EBX_CLFLUSH_LINE_SIZE = 0xFF << 8,
CPUID_FEAT_EBX_APIC_ID_SPACE = 0xFF << 16,
CPUID_FEAT_EBX_INITIAL_APIC_ID = 0xFF << 24,
CPUID_FEAT_ECX_SSE3 = 1 << 0,
CPUID_FEAT_ECX_PCLMUL = 1 << 1,
CPUID_FEAT_ECX_DTES64 = 1 << 2,
CPUID_FEAT_ECX_MONITOR = 1 << 3,
CPUID_FEAT_ECX_DS_CPL = 1 << 4,
CPUID_FEAT_ECX_VMX = 1 << 5,
CPUID_FEAT_ECX_SMX = 1 << 6,
CPUID_FEAT_ECX_EST = 1 << 7,
CPUID_FEAT_ECX_TM2 = 1 << 8,
CPUID_FEAT_ECX_SSSE3 = 1 << 9,
CPUID_FEAT_ECX_CID = 1 << 10,
CPUID_FEAT_ECX_SDBG = 1 << 11,
CPUID_FEAT_ECX_FMA = 1 << 12,
CPUID_FEAT_ECX_CX16 = 1 << 13,
CPUID_FEAT_ECX_XTPR = 1 << 14,
CPUID_FEAT_ECX_PDCM = 1 << 15,
CPUID_FEAT_ECX_PCID = 1 << 17,
CPUID_FEAT_ECX_DCA = 1 << 18,
CPUID_FEAT_ECX_SSE4_1 = 1 << 19,
CPUID_FEAT_ECX_SSE4_2 = 1 << 20,
CPUID_FEAT_ECX_X2APIC = 1 << 21,
CPUID_FEAT_ECX_MOVBE = 1 << 22,
CPUID_FEAT_ECX_POPCNT = 1 << 23,
CPUID_FEAT_ECX_TSC = 1 << 24,
CPUID_FEAT_ECX_AES = 1 << 25,
CPUID_FEAT_ECX_XSAVE = 1 << 26,
CPUID_FEAT_ECX_OSXSAVE = 1 << 27,
CPUID_FEAT_ECX_AVX = 1 << 28,
CPUID_FEAT_ECX_F16C = 1 << 29,
CPUID_FEAT_ECX_RDRAND = 1 << 30,
CPUID_FEAT_ECX_HYPERVISOR = 1 << 31,
CPUID_FEAT_EDX_FPU = 1 << 0,
CPUID_FEAT_EDX_VME = 1 << 1,
CPUID_FEAT_EDX_DE = 1 << 2,
CPUID_FEAT_EDX_PSE = 1 << 3,
CPUID_FEAT_EDX_TSC = 1 << 4,
CPUID_FEAT_EDX_MSR = 1 << 5,
CPUID_FEAT_EDX_PAE = 1 << 6,
CPUID_FEAT_EDX_MCE = 1 << 7,
CPUID_FEAT_EDX_CX8 = 1 << 8,
CPUID_FEAT_EDX_APIC = 1 << 9,
CPUID_FEAT_EDX_SEP = 1 << 11,
CPUID_FEAT_EDX_MTRR = 1 << 12,
CPUID_FEAT_EDX_PGE = 1 << 13,
CPUID_FEAT_EDX_MCA = 1 << 14,
CPUID_FEAT_EDX_CMOV = 1 << 15,
CPUID_FEAT_EDX_PAT = 1 << 16,
CPUID_FEAT_EDX_PSE36 = 1 << 17,
CPUID_FEAT_EDX_PSN = 1 << 18,
CPUID_FEAT_EDX_CLFLUSH = 1 << 19,
CPUID_FEAT_EDX_DS = 1 << 21,
CPUID_FEAT_EDX_ACPI = 1 << 22,
CPUID_FEAT_EDX_MMX = 1 << 23,
CPUID_FEAT_EDX_FXSR = 1 << 24,
CPUID_FEAT_EDX_SSE = 1 << 25,
CPUID_FEAT_EDX_SSE2 = 1 << 26,
CPUID_FEAT_EDX_SS = 1 << 27,
CPUID_FEAT_EDX_HTT = 1 << 28,
CPUID_FEAT_EDX_TM = 1 << 29,
CPUID_FEAT_EDX_IA64 = 1 << 30,
CPUID_FEAT_EDX_PBE = 1 << 31
};
#endif

View File

@ -3,6 +3,7 @@
|Copyright (C) 2026|
|Xircon |
\*----------------*/
#ifdef __I686
#include "gdt.h"
#include <stdint.h>
@ -89,4 +90,5 @@ void __attribute__((cdecl)) GDT_Load(GDTDescriptor* descriptor, uint16_t codeSeg
void GDT_Initialize() {
GDT_Load(&g_GDTDescriptor, GDT_CODE_SEGMENT, GDT_DATA_SEGMENT);
}
}
#endif

View File

@ -3,9 +3,11 @@
|Copyright (C) 2026|
|Xircon |
\*----------------*/
#ifdef __I686
#pragma once
#define GDT_CODE_SEGMENT 0x8
#define GDT_DATA_SEGMENT 0x10
void GDT_Initialize();
void GDT_Initialize();
#endif

View File

@ -1,4 +1,5 @@
// THIS FILE IS AUTOGENERATED VIA genISR.sh, because im pacient but not THAT pacient good lord its 500 lines of pure hell also like i have no braincells left...
#ifdef __I686
#include "idt.h"
#include "gdt.h"
@ -518,3 +519,4 @@ void ISR_InitializeGates()
IDT_SetGate(254, ISR254, GDT_CODE_SEGMENT, IDT_FLAG_RING0 | IDT_FLAG_GATE_32BIT_INT);
IDT_SetGate(255, ISR255, GDT_CODE_SEGMENT, IDT_FLAG_RING0 | IDT_FLAG_GATE_32BIT_INT);
}
#endif

View File

@ -3,6 +3,7 @@
|Copyright (C) 2026|
|Xircon |
\*----------------*/
#ifdef __I686
#include "idt.h"
#include <stdint.h>
#include <util/binary.h>
@ -47,4 +48,4 @@ void IDT_DisableGate(int interupt) {
void IDT_Initialize() {
IDT_Load(&g_IDTDescriptor);
}
#endif

View File

@ -3,6 +3,7 @@
|Copyright (C) 2026|
|Xircon |
\*----------------*/
#ifdef __I686
#pragma once
#include <stdint.h>
@ -26,4 +27,5 @@ typedef enum {
IDT_FLAG_PRESENT = 0x80,
} IDT_FLAGS;
} IDT_FLAGS;
#endif

View File

@ -3,6 +3,7 @@
|Copyright (C) 2026|
|Xircon |
\*----------------*/
#ifdef __I686
#include "io.h"
#define UNUSED_PORT 0x80
@ -10,4 +11,5 @@
void iowait()
{
outb(UNUSED_PORT, 0);
}
}
#endif

View File

@ -3,6 +3,7 @@
|Copyright (C) 2026|
|Xircon |
\*----------------*/
#ifdef __I686
#pragma once
#include <stdint.h>
#include <stdbool.h>
@ -14,3 +15,4 @@ uint8_t __attribute__((cdecl)) DisableInterrupts();
void iowait();
void __attribute__((cdecl)) kernel_panic();
#endif

View File

@ -3,6 +3,7 @@
|Copyright (C) 2026|
|Xircon |
\*----------------*/
#ifdef __I686
#include "irq.h"
#include "pic.h"
#include "io.h"
@ -48,4 +49,5 @@ void IRQ_Initialize()
void IRQ_RegisterHandler(int irq, IRQHandler handler)
{
g_IRQHandlers[irq] = handler;
}
}
#endif

View File

@ -3,10 +3,12 @@
|Copyright (C) 2026|
|Xircon |
\*----------------*/
#ifdef __I686
#pragma once
#include "isr.h"
typedef void (*IRQHandler)(Registers* regs);
void IRQ_Initialize();
void IRQ_RegisterHandler(int irq, IRQHandler handler);
void IRQ_RegisterHandler(int irq, IRQHandler handler);
#endif

View File

@ -3,6 +3,7 @@
|Copyright (C) 2026|
|Xircon |
\*----------------*/
#ifdef __I686
#include "isr.h"
#include "idt.h"
#include "gdt.h"
@ -76,7 +77,7 @@ void __attribute__((cdecl)) ISR_Handler(Registers* regs) {
printf(" EAX=%x EBX=%x ECX=%x EDX=%x ESI=%x EDI=%x\n", regs->eax, regs->ebx, regs->ecx, regs->edx, regs->esi, regs->edi);
printf(" ESP=%x EBP=%x EIP=%x EFLAGS=%x CS=%x DS=%x SS=%x\n", regs->esp, regs->ebp, regs->eip, regs->eflags, regs->cs, regs->ds, regs->ss);
printf(" INTERRUPT=%x ERRORCODE=%x\n", regs->interrupt, regs->error);
printf("KERNEL PANIC!\n");
printf("KERNEL PANIC!\nWell Fuck!\n");
kernel_panic();
}
@ -85,4 +86,5 @@ void ISR_RegisterHandler(int interrupt, ISRHandler handler)
{
g_ISRHandlers[interrupt] = handler;
IDT_EnableGate(interrupt);
}
}
#endif

View File

@ -3,6 +3,7 @@
|Copyright (C) 2026|
|Xircon |
\*----------------*/
#ifdef __I686
#pragma once
#include <stdint.h>
@ -19,4 +20,5 @@ typedef struct
typedef void (*ISRHandler)(Registers* regs);
void ISR_Initialize();
void ISR_RegisterHandler(int interrupt, ISRHandler handler);
void ISR_RegisterHandler(int interrupt, ISRHandler handler);
#endif

View File

@ -3,6 +3,7 @@
|Copyright (C) 2026|
|Xircon |
\*----------------*/
#ifdef __I686
#include "pic.h"
#include "io.h"
@ -128,4 +129,5 @@ uint16_t PIC_ReadInServiceRegister()
outb(PIC1_COMMAND_PORT, PIC_CMD_READ_ISR);
outb(PIC2_COMMAND_PORT, PIC_CMD_READ_ISR);
return inb(PIC2_COMMAND_PORT) | (inb(PIC2_COMMAND_PORT) << 8);
}
}
#endif

View File

@ -3,6 +3,7 @@
|Copyright (C) 2026|
|Xircon |
\*----------------*/
#ifdef __I686
#pragma once
#include <stdint.h>
@ -12,4 +13,5 @@ void PIC_Disable();
void PIC_Mask(int irq);
void PIC_Unmask(int irq);
uint16_t PIC_ReadIRQRequestRegister();
uint16_t PIC_ReadInServiceRegister();
uint16_t PIC_ReadInServiceRegister();
#endif

View File

@ -3,6 +3,7 @@
|Copyright (C) 2026|
|Xircon |
\*----------------*/
#ifdef __I686
#pragma once
#include <stdint.h>
@ -12,3 +13,4 @@ uint32_t __attribute__((cdecl)) Read_CR0();
void __attribute__((cdecl)) Write_CR0(uint32_t value);
uint32_t* __attribute__((cdecl)) Read_CR3();
void __attribute__((cdecl)) Write_CR3(uint32_t* value);
#endif

View File

@ -5,7 +5,10 @@
\*----------------*/
#include "dma.h"
#ifdef __I686
#include <arch/i686/io.h>
#endif
#include <stdint.h>
#include <stdbool.h>

View File

@ -4,10 +4,14 @@
|Xircon |
\*----------------*/
#include "hal.h"
#ifdef __I686
#include <arch/i686/gdt.h>
#include <arch/i686/idt.h>
#include <arch/i686/isr.h>
#include <arch/i686/irq.h>
#endif
#include <stdio.h>
void HAL_Initialize() {

View File

@ -5,10 +5,14 @@
\*----------------*/
#include "page.h"
// Arch stuff
#ifdef __I686
#include <arch/i686/util.h>
#endif
#include <stdio.h>
#include <stdint.h>
#include <dri/serial.h>
#include <arch/i686/util.h>
extern uint16_t DEBUG_COM_PORT;

View File

@ -5,11 +5,14 @@
\*----------------*/
#include "cmos.h"
#include <stdio.h>
#include <stdint.h>
// Arch Specific
#ifdef __I686
#include <arch/i686/io.h>
#include <arch/i686/irq.h>
#endif
#include <stdio.h>
#include <stdint.h>
#include <util/binary.h>

View File

@ -5,11 +5,15 @@
\*----------------*/
#include "floppy.h"
// Arch specific stuff
#ifdef __I686
#include <arch/i686/io.h>
#include <arch/i686/irq.h>
#endif
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include <arch/i686/io.h>
#include <arch/i686/irq.h>
#include <dri/serial.h>
#include <core/dma/dma.h>

View File

@ -5,11 +5,15 @@
\*----------------*/
#include "keyboard.h"
#include <stdint.h>
#include <stdbool.h>
// Arch Specific
#ifdef __I686
#include <arch/i686/irq.h>
#include <arch/i686/io.h>
#include <arch/i686/util.h>
#endif
#include <stdint.h>
#include <stdbool.h>
#include <dri/serial.h>
#include <stdio.h>
@ -34,7 +38,7 @@ void Keyboard_Handler()
if(_keyboard_scancode == 42) _shift = true;
if(_keyboard_scancode == 170) _shift = false;
// If CTRL+ALT+DEL Reboot
// Three finger salute (lol)
if(_keyboard_scancode == 224 && _ctrl == true && _alt == true) Reboot();
// If CTRL+ALT+ESC Shut Down
if(_keyboard_scancode == 1 && _ctrl == true && _alt == true); // Shutdown();

View File

@ -5,10 +5,14 @@
\*----------------*/
#include "serial.h"
// Arch Specific
#ifdef __I686
#include <arch/i686/io.h>
#endif
#include <stdint.h>
#include <stdarg.h>
#include <stdio.h>
#include <arch/i686/io.h>
char Serial_Read_Buffer;
char Serial_Write_Buffer;

View File

@ -5,12 +5,15 @@
\*----------------*/
#include "pcspeaker.h"
// Arch Specific Stuff
#ifdef __I686
#include <arch/i686/io.h>
#endif
#include <stdint.h>
#include <util/binary.h>
#include <arch/i686/io.h>
#include <dri/timer.h>
#include <dri/cmos.h>
#include <dri/serial.h>

View File

@ -6,9 +6,12 @@
// Architecture specific
#ifdef __I686
#include <arch/i686/io.h>
#include <arch/i686/irq.h>
#include <arch/i686/util.h>
#include <arch/i686/cpuid.h>
#endif
// stdlibs
@ -75,7 +78,7 @@ void start() {
// Storage
// Floppy_Init(); // This should always be last; its slow as fuck
printf("Done!\n");
// Serial_Printf(DEBUG_COM_PORT, "CPU Vendor: %s\n", CPUID_Get_Vendor()); // CPUID Stuff is pain and suffering, like page faults pain and suffering
printf("Initializing Memory Paging...");
Memory = Detect_Memory();
Serial_Printf(DEBUG_COM_PORT, "MEMORY:> There is %dKB of Memory Available\n", Memory);

View File

@ -3,8 +3,12 @@
|Copyright (C) 2026|
|Xircon |
\*----------------*/
#include <stdio.h>
// Arch Specific
#ifdef __I686
#include <arch/i686/io.h>
#endif
#include <stdio.h>
#include <stdarg.h>
#include <stdbool.h>