add memory detection
This commit is contained in:
parent
a40ab1c13a
commit
e38974d290
@ -7,6 +7,8 @@ SOURCES_C=$(wildcard *.c)
|
|||||||
SOURCES_ASM=$(wildcard *.asm)
|
SOURCES_ASM=$(wildcard *.asm)
|
||||||
OBJECTS_C=$(patsubst %.c, $(BUILD_DIR)/stage2/c/%.obj, $(SOURCES_C))
|
OBJECTS_C=$(patsubst %.c, $(BUILD_DIR)/stage2/c/%.obj, $(SOURCES_C))
|
||||||
OBJECTS_ASM=$(patsubst %.asm, $(BUILD_DIR)/stage2/asm/%.obj, $(SOURCES_ASM))
|
OBJECTS_ASM=$(patsubst %.asm, $(BUILD_DIR)/stage2/asm/%.obj, $(SOURCES_ASM))
|
||||||
|
HEADERS_C= $(wildcard ../../libs/*.h) \
|
||||||
|
$(wildcard ../../libs/*/*.h)
|
||||||
|
|
||||||
.PHONY: all stage2 clean always
|
.PHONY: all stage2 clean always
|
||||||
|
|
||||||
@ -17,7 +19,7 @@ stage2: $(BUILD_DIR)/stage2.bin
|
|||||||
$(BUILD_DIR)/stage2.bin: $(OBJECTS_ASM) $(OBJECTS_C)
|
$(BUILD_DIR)/stage2.bin: $(OBJECTS_ASM) $(OBJECTS_C)
|
||||||
$(TARGET_LD) $(TARGET_LINKFLAGS) -Wl,-Map=$(BUILD_DIR)/stage2.map -o $@ $^ $(TARGET_LIBS)
|
$(TARGET_LD) $(TARGET_LINKFLAGS) -Wl,-Map=$(BUILD_DIR)/stage2.map -o $@ $^ $(TARGET_LIBS)
|
||||||
|
|
||||||
$(BUILD_DIR)/stage2/c/%.obj: %.c always
|
$(BUILD_DIR)/stage2/c/%.obj: %.c always $(HEADERS_C)
|
||||||
$(TARGET_CC) $(TARGET_CFLAGS) -c -o $@ $<
|
$(TARGET_CC) $(TARGET_CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
$(BUILD_DIR)/stage2/asm/%.obj: %.asm always
|
$(BUILD_DIR)/stage2/asm/%.obj: %.asm always
|
||||||
|
|||||||
@ -10,13 +10,18 @@
|
|||||||
#include "fat.h"
|
#include "fat.h"
|
||||||
#include "memdefs.h"
|
#include "memdefs.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "../../version.h"
|
#include "memdetect.h"
|
||||||
|
#include "../../libs/version.h"
|
||||||
|
#include "../../libs/boot/bootparams.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint8_t* KernelLoadBuffer = (uint8_t*)MEMORY_LOAD_KERNEL;
|
uint8_t* KernelLoadBuffer = (uint8_t*)MEMORY_LOAD_KERNEL;
|
||||||
uint8_t* Kernel = (uint8_t*)MEMORY_KERNEL_ADDR;
|
uint8_t* Kernel = (uint8_t*)MEMORY_KERNEL_ADDR;
|
||||||
|
BootParams g_BootParams;
|
||||||
|
|
||||||
typedef void (*KernelStart)();
|
|
||||||
|
typedef void (*KernelStart)(BootParams* bootParams);
|
||||||
|
|
||||||
void* g_data = (void*)0x20000;
|
void* g_data = (void*)0x20000;
|
||||||
|
|
||||||
@ -82,6 +87,12 @@ void* g_data = (void*)0x20000;
|
|||||||
}
|
}
|
||||||
FAT_Close(ft);
|
FAT_Close(ft);
|
||||||
|
|
||||||
|
printf("Detecting Memory...\n");
|
||||||
|
// prep boot params
|
||||||
|
g_BootParams.BootDevice = bootDrive;
|
||||||
|
Memory_Detect(&g_BootParams.Memory);
|
||||||
|
|
||||||
|
|
||||||
// load kernel from disk
|
// load kernel from disk
|
||||||
printf("Loading Kernel...");
|
printf("Loading Kernel...");
|
||||||
FAT_File* fd = FAT_Open(&disk, "/kernel.bin"); // move to /boot later????? (TM)
|
FAT_File* fd = FAT_Open(&disk, "/kernel.bin"); // move to /boot later????? (TM)
|
||||||
@ -96,7 +107,7 @@ void* g_data = (void*)0x20000;
|
|||||||
|
|
||||||
// execute kernel
|
// execute kernel
|
||||||
KernelStart kernelStart = (KernelStart)Kernel;
|
KernelStart kernelStart = (KernelStart)Kernel;
|
||||||
kernelStart();
|
kernelStart(&g_BootParams);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
40
src/bootloader/stage2/memdetect.c
Normal file
40
src/bootloader/stage2/memdetect.c
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/*----------------*\
|
||||||
|
|Nanite OS |
|
||||||
|
|Copyright (C) 2024|
|
||||||
|
|Tyler McGurrin |
|
||||||
|
\*----------------*/
|
||||||
|
#include "x86.h"
|
||||||
|
#include "stdio.h"
|
||||||
|
#include "../../libs/boot/bootparams.h"
|
||||||
|
|
||||||
|
#define MAX_REGIONS 256
|
||||||
|
|
||||||
|
MemoryRegion g_MemRegions[MAX_REGIONS];
|
||||||
|
int g_MemRegionCount;
|
||||||
|
|
||||||
|
void Memory_Detect(MemoryInfo* memoryInfo)
|
||||||
|
{
|
||||||
|
E820MemoryBlock block;
|
||||||
|
uint32_t continuation = 0;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
g_MemRegionCount = 0;
|
||||||
|
ret = x86_E820GetNextBlock(&block, &continuation);
|
||||||
|
|
||||||
|
while (ret > 0 && continuation != 0)
|
||||||
|
{
|
||||||
|
g_MemRegions[g_MemRegionCount].Begin = block.Base;
|
||||||
|
g_MemRegions[g_MemRegionCount].Length = block.Length;
|
||||||
|
g_MemRegions[g_MemRegionCount].Type = block.Type;
|
||||||
|
g_MemRegions[g_MemRegionCount].ACPI = block.ACPI;
|
||||||
|
++g_MemRegionCount;
|
||||||
|
|
||||||
|
printf("E820: base=0x%llx length=0x%llx type=0x%x\n", block.Base, block.Length, block.Type);
|
||||||
|
|
||||||
|
ret = x86_E820GetNextBlock(&block, &continuation);
|
||||||
|
}
|
||||||
|
|
||||||
|
// fill meminfo structure
|
||||||
|
memoryInfo->RegionCount = g_MemRegionCount;
|
||||||
|
memoryInfo->Regions = g_MemRegions;
|
||||||
|
}
|
||||||
10
src/bootloader/stage2/memdetect.h
Normal file
10
src/bootloader/stage2/memdetect.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
/*----------------*\
|
||||||
|
|Nanite OS |
|
||||||
|
|Copyright (C) 2024|
|
||||||
|
|Tyler McGurrin |
|
||||||
|
\*----------------*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../../libs/boot/bootparams.h"
|
||||||
|
|
||||||
|
void Memory_Detect(MemoryInfo* memoryInfo);
|
||||||
@ -162,11 +162,12 @@ void printf_signed(long long number, int radix)
|
|||||||
#define PRINTF_LENGTH_LONG 3
|
#define PRINTF_LENGTH_LONG 3
|
||||||
#define PRINTF_LENGTH_LONG_LONG 4
|
#define PRINTF_LENGTH_LONG_LONG 4
|
||||||
|
|
||||||
void printf(const char* fmt, ...) {
|
void printf(const char* fmt, ...)
|
||||||
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
|
|
||||||
int state= PRINTF_STATE_NORMAL;
|
int state = PRINTF_STATE_NORMAL;
|
||||||
int length = PRINTF_LENGTH_DEFAULT;
|
int length = PRINTF_LENGTH_DEFAULT;
|
||||||
int radix = 10;
|
int radix = 10;
|
||||||
bool sign = false;
|
bool sign = false;
|
||||||
@ -209,7 +210,7 @@ void printf(const char* fmt, ...) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case PRINTF_STATE_LENGTH_LONG:
|
case PRINTF_STATE_LENGTH_LONG:
|
||||||
if (*fmt == 'h')
|
if (*fmt == 'l')
|
||||||
{
|
{
|
||||||
length = PRINTF_LENGTH_LONG_LONG;
|
length = PRINTF_LENGTH_LONG_LONG;
|
||||||
state = PRINTF_STATE_SPEC;
|
state = PRINTF_STATE_SPEC;
|
||||||
@ -224,16 +225,15 @@ void printf(const char* fmt, ...) {
|
|||||||
case 'c': putc((char)va_arg(args, int));
|
case 'c': putc((char)va_arg(args, int));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 's': puts(va_arg(args, const char*));
|
case 's':
|
||||||
|
puts(va_arg(args, const char*));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '%': putc('%');
|
case '%': putc('%');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'd':
|
case 'd':
|
||||||
case 'i': radix = 10;
|
case 'i': radix = 10; sign = true; number = true;
|
||||||
sign = true;
|
|
||||||
number = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'u': radix = 10; sign = false; number = true;
|
case 'u': radix = 10; sign = false; number = true;
|
||||||
@ -247,9 +247,10 @@ void printf(const char* fmt, ...) {
|
|||||||
case 'o': radix = 8; sign = false; number = true;
|
case 'o': radix = 8; sign = false; number = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//ignore invalid specifiers (specs)
|
// ignore invalid spec
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (number)
|
if (number)
|
||||||
{
|
{
|
||||||
if (sign)
|
if (sign)
|
||||||
@ -258,14 +259,13 @@ void printf(const char* fmt, ...) {
|
|||||||
{
|
{
|
||||||
case PRINTF_LENGTH_SHORT_SHORT:
|
case PRINTF_LENGTH_SHORT_SHORT:
|
||||||
case PRINTF_LENGTH_SHORT:
|
case PRINTF_LENGTH_SHORT:
|
||||||
case PRINTF_LENGTH_DEFAULT:
|
case PRINTF_LENGTH_DEFAULT: printf_signed(va_arg(args, int), radix);
|
||||||
printf_signed(va_arg(args, int), radix);
|
|
||||||
break;
|
break;
|
||||||
case PRINTF_LENGTH_LONG:
|
|
||||||
printf_signed(va_arg(args, long), radix);
|
case PRINTF_LENGTH_LONG: printf_signed(va_arg(args, long), radix);
|
||||||
break;
|
break;
|
||||||
case PRINTF_LENGTH_LONG_LONG:
|
|
||||||
printf_signed(va_arg(args, long long), radix);
|
case PRINTF_LENGTH_LONG_LONG: printf_signed(va_arg(args, long long), radix);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -275,25 +275,24 @@ void printf(const char* fmt, ...) {
|
|||||||
{
|
{
|
||||||
case PRINTF_LENGTH_SHORT_SHORT:
|
case PRINTF_LENGTH_SHORT_SHORT:
|
||||||
case PRINTF_LENGTH_SHORT:
|
case PRINTF_LENGTH_SHORT:
|
||||||
case PRINTF_LENGTH_DEFAULT:
|
case PRINTF_LENGTH_DEFAULT: printf_unsigned(va_arg(args, unsigned int), radix);
|
||||||
printf_unsigned(va_arg(args, unsigned int), radix);
|
|
||||||
break;
|
break;
|
||||||
case PRINTF_LENGTH_LONG:
|
|
||||||
printf_unsigned(va_arg(args, unsigned long), radix);
|
case PRINTF_LENGTH_LONG: printf_unsigned(va_arg(args, unsigned long), radix);
|
||||||
break;
|
break;
|
||||||
case PRINTF_LENGTH_LONG_LONG:
|
|
||||||
printf_unsigned(va_arg(args, unsigned long long), radix);
|
case PRINTF_LENGTH_LONG_LONG: printf_unsigned(va_arg(args, unsigned long long), radix);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//reset state
|
// reset state
|
||||||
state = PRINTF_STATE_NORMAL;
|
state = PRINTF_STATE_NORMAL;
|
||||||
length = PRINTF_LENGTH_DEFAULT;
|
length = PRINTF_LENGTH_DEFAULT;
|
||||||
radix = 10;
|
radix = 10;
|
||||||
sign = false;
|
sign = false;
|
||||||
bool number = false;
|
number = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -278,3 +278,73 @@ x86_realmode_putc:
|
|||||||
mov esp, ebp
|
mov esp, ebp
|
||||||
pop ebp
|
pop ebp
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
;
|
||||||
|
; int ASMCALL x86_E820GetNextBlock(E820MemoryBlock* block, uint32_t* continuationId);
|
||||||
|
;
|
||||||
|
E820Signature equ 0x534D4150
|
||||||
|
|
||||||
|
global x86_E820GetNextBlock
|
||||||
|
x86_E820GetNextBlock:
|
||||||
|
|
||||||
|
; make new call frame
|
||||||
|
push ebp ; save old call frame
|
||||||
|
mov ebp, esp ; initialize new call frame
|
||||||
|
|
||||||
|
x86_EnterRealMode
|
||||||
|
|
||||||
|
; save modified regs
|
||||||
|
push ebx
|
||||||
|
push ecx
|
||||||
|
push edx
|
||||||
|
push esi
|
||||||
|
push edi
|
||||||
|
push ds
|
||||||
|
push es
|
||||||
|
|
||||||
|
; setup params
|
||||||
|
LinearToSegOffset [bp + 8], es, edi, di ; es:di pointer to structure
|
||||||
|
|
||||||
|
LinearToSegOffset [bp + 12], ds, esi, si ; ebx - pointer to continuationId
|
||||||
|
mov ebx, ds:[si]
|
||||||
|
|
||||||
|
mov eax, 0xE820 ; eax - function
|
||||||
|
mov edx, E820Signature ; edx - signature
|
||||||
|
mov ecx, 24 ; ecx - size of structure
|
||||||
|
|
||||||
|
; call interrupt
|
||||||
|
int 0x15
|
||||||
|
|
||||||
|
; test results
|
||||||
|
cmp eax, E820Signature
|
||||||
|
jne .Error
|
||||||
|
|
||||||
|
.IfSuccedeed:
|
||||||
|
mov eax, ecx ; return size
|
||||||
|
mov ds:[si], ebx ; fill continuation parameter
|
||||||
|
jmp .EndIf
|
||||||
|
|
||||||
|
.Error:
|
||||||
|
mov eax, -1
|
||||||
|
|
||||||
|
.EndIf:
|
||||||
|
|
||||||
|
; restore regs
|
||||||
|
pop es
|
||||||
|
pop ds
|
||||||
|
pop edi
|
||||||
|
pop esi
|
||||||
|
pop edx
|
||||||
|
pop ecx
|
||||||
|
pop ebx
|
||||||
|
|
||||||
|
push eax
|
||||||
|
|
||||||
|
x86_EnterProtectedMode
|
||||||
|
|
||||||
|
pop eax
|
||||||
|
|
||||||
|
; restore old call frame
|
||||||
|
mov esp, ebp
|
||||||
|
pop ebp
|
||||||
|
ret
|
||||||
@ -7,22 +7,46 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
void __attribute__((cdecl)) x86_outb(uint16_t port, uint8_t value);
|
#define ASMCALL __attribute__((cdecl))
|
||||||
uint8_t __attribute__((cdecl)) x86_inb(uint16_t port);
|
|
||||||
|
|
||||||
void __attribute__((cdecl)) x86_realmode_putc(char c);
|
|
||||||
|
|
||||||
bool __attribute__((cdecl)) x86_Disk_GetDriveParams(uint8_t drive,
|
void ASMCALL x86_outb(uint16_t port, uint8_t value);
|
||||||
|
uint8_t ASMCALL x86_inb(uint16_t port);
|
||||||
|
|
||||||
|
void ASMCALL x86_realmode_putc(char c);
|
||||||
|
|
||||||
|
bool ASMCALL x86_Disk_GetDriveParams(uint8_t drive,
|
||||||
uint8_t* driveTypeOut,
|
uint8_t* driveTypeOut,
|
||||||
uint16_t* cylindersOut,
|
uint16_t* cylindersOut,
|
||||||
uint16_t* sectorsOut,
|
uint16_t* sectorsOut,
|
||||||
uint16_t* headsOut);
|
uint16_t* headsOut);
|
||||||
|
|
||||||
bool __attribute__((cdecl)) x86_Disk_Reset(uint8_t drive);
|
bool ASMCALL x86_Disk_Reset(uint8_t drive);
|
||||||
|
|
||||||
bool __attribute__((cdecl)) x86_Disk_Read(uint8_t drive,
|
bool ASMCALL x86_Disk_Read(uint8_t drive,
|
||||||
uint16_t cylinder,
|
uint16_t cylinder,
|
||||||
uint16_t sector,
|
uint16_t sector,
|
||||||
uint16_t head,
|
uint16_t head,
|
||||||
uint8_t count,
|
uint8_t count,
|
||||||
void* lowerDataOut);
|
void* lowerDataOut);
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint64_t Base;
|
||||||
|
uint64_t Length;
|
||||||
|
uint32_t Type;
|
||||||
|
uint32_t ACPI;
|
||||||
|
|
||||||
|
} E820MemoryBlock;
|
||||||
|
|
||||||
|
enum E820MemoryBlockType {
|
||||||
|
|
||||||
|
E820_USABLE = 1,
|
||||||
|
E820_RESERVED = 2,
|
||||||
|
E820_ACPI_RECLAIMABLE = 3,
|
||||||
|
E820_ACPI_NVS = 4,
|
||||||
|
E820_BAD_MEMORY = 5,
|
||||||
|
};
|
||||||
|
|
||||||
|
int ASMCALL x86_E820GetNextBlock(E820MemoryBlock* block, uint32_t* continuationId);
|
||||||
@ -6,7 +6,9 @@ TARGET_LINKFLAGS += -T linker.ld -nostdlib
|
|||||||
HEADERS_C = $(wildcard *.h) \
|
HEADERS_C = $(wildcard *.h) \
|
||||||
$(wildcard */*.h) \
|
$(wildcard */*.h) \
|
||||||
$(wildcard */*/*.h) \
|
$(wildcard */*/*.h) \
|
||||||
$(wildcard */*/*/*.h)
|
$(wildcard */*/*/*.h) \
|
||||||
|
$(wildcard ../libs/*.h) \
|
||||||
|
$(wildcard ../libs/*/*.h)
|
||||||
|
|
||||||
SOURCES_C = $(wildcard *.c) \
|
SOURCES_C = $(wildcard *.c) \
|
||||||
$(wildcard */*.c) \
|
$(wildcard */*.c) \
|
||||||
|
|||||||
6
src/kernel/dri/keyboard.c
Normal file
6
src/kernel/dri/keyboard.c
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
/*----------------*\
|
||||||
|
|Nanite OS |
|
||||||
|
|Copyright (C) 2024|
|
||||||
|
|Tyler McGurrin |
|
||||||
|
\*----------------*/
|
||||||
|
#include "keyboard.h"
|
||||||
6
src/kernel/dri/keyboard.h
Normal file
6
src/kernel/dri/keyboard.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
/*----------------*\
|
||||||
|
|Nanite OS |
|
||||||
|
|Copyright (C) 2024|
|
||||||
|
|Tyler McGurrin |
|
||||||
|
\*----------------*/
|
||||||
|
#pragma once
|
||||||
@ -10,17 +10,19 @@
|
|||||||
#include <arch/i686/io.h>
|
#include <arch/i686/io.h>
|
||||||
#include <arch/i686/irq.h>
|
#include <arch/i686/irq.h>
|
||||||
#include <arch/i686/basicfunc.h>
|
#include <arch/i686/basicfunc.h>
|
||||||
#include "../version.h"
|
#include "../libs/version.h"
|
||||||
|
#include "../libs/boot/bootparams.h"
|
||||||
|
|
||||||
extern uint8_t __bss_start;
|
extern uint8_t __bss_start;
|
||||||
extern uint8_t __end;
|
extern uint8_t __end;
|
||||||
|
|
||||||
void timer(Registers* regs)
|
void timer(Registers* regs)
|
||||||
{
|
{
|
||||||
printf(".");
|
int uptime;
|
||||||
|
uptime++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void __attribute__((section(".entry"))) start(uint16_t bootDrive) {
|
void __attribute__((section(".entry"))) start(BootParams* bootParams) {
|
||||||
|
|
||||||
// print logo
|
// print logo
|
||||||
clrscr();
|
clrscr();
|
||||||
@ -35,6 +37,13 @@ void __attribute__((section(".entry"))) start(uint16_t bootDrive) {
|
|||||||
printf("Done!\n\n\n\n\n");
|
printf("Done!\n\n\n\n\n");
|
||||||
|
|
||||||
i686_IRQ_RegisterHandler(0, timer);
|
i686_IRQ_RegisterHandler(0, timer);
|
||||||
|
printf("Boot Device: %x\n", bootParams->BootDevice);
|
||||||
|
printf("Memory Region Count: %x\n", bootParams->Memory.RegionCount);
|
||||||
|
for (int i = 0; i < bootParams->Memory.RegionCount; i++) {
|
||||||
|
printf("Memory: start=0x%llx length=0x%llx type=0x%x\n",
|
||||||
|
bootParams->Memory.Regions[i].Begin, bootParams->Memory.Regions[i].Length, bootParams->Memory.Regions[i].Type);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end:
|
end:
|
||||||
|
|||||||
@ -174,11 +174,12 @@ void printf_signed(long long number, int radix)
|
|||||||
#define PRINTF_LENGTH_LONG 3
|
#define PRINTF_LENGTH_LONG 3
|
||||||
#define PRINTF_LENGTH_LONG_LONG 4
|
#define PRINTF_LENGTH_LONG_LONG 4
|
||||||
|
|
||||||
void printf(const char* fmt, ...) {
|
void printf(const char* fmt, ...)
|
||||||
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
|
|
||||||
int state= PRINTF_STATE_NORMAL;
|
int state = PRINTF_STATE_NORMAL;
|
||||||
int length = PRINTF_LENGTH_DEFAULT;
|
int length = PRINTF_LENGTH_DEFAULT;
|
||||||
int radix = 10;
|
int radix = 10;
|
||||||
bool sign = false;
|
bool sign = false;
|
||||||
@ -221,7 +222,7 @@ void printf(const char* fmt, ...) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case PRINTF_STATE_LENGTH_LONG:
|
case PRINTF_STATE_LENGTH_LONG:
|
||||||
if (*fmt == 'h')
|
if (*fmt == 'l')
|
||||||
{
|
{
|
||||||
length = PRINTF_LENGTH_LONG_LONG;
|
length = PRINTF_LENGTH_LONG_LONG;
|
||||||
state = PRINTF_STATE_SPEC;
|
state = PRINTF_STATE_SPEC;
|
||||||
@ -236,16 +237,15 @@ void printf(const char* fmt, ...) {
|
|||||||
case 'c': putc((char)va_arg(args, int));
|
case 'c': putc((char)va_arg(args, int));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 's': puts(va_arg(args, const char*));
|
case 's':
|
||||||
|
puts(va_arg(args, const char*));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '%': putc('%');
|
case '%': putc('%');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'd':
|
case 'd':
|
||||||
case 'i': radix = 10;
|
case 'i': radix = 10; sign = true; number = true;
|
||||||
sign = true;
|
|
||||||
number = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'u': radix = 10; sign = false; number = true;
|
case 'u': radix = 10; sign = false; number = true;
|
||||||
@ -259,9 +259,10 @@ void printf(const char* fmt, ...) {
|
|||||||
case 'o': radix = 8; sign = false; number = true;
|
case 'o': radix = 8; sign = false; number = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//ignore invalid specifiers (specs)
|
// ignore invalid spec
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (number)
|
if (number)
|
||||||
{
|
{
|
||||||
if (sign)
|
if (sign)
|
||||||
@ -270,14 +271,13 @@ void printf(const char* fmt, ...) {
|
|||||||
{
|
{
|
||||||
case PRINTF_LENGTH_SHORT_SHORT:
|
case PRINTF_LENGTH_SHORT_SHORT:
|
||||||
case PRINTF_LENGTH_SHORT:
|
case PRINTF_LENGTH_SHORT:
|
||||||
case PRINTF_LENGTH_DEFAULT:
|
case PRINTF_LENGTH_DEFAULT: printf_signed(va_arg(args, int), radix);
|
||||||
printf_signed(va_arg(args, int), radix);
|
|
||||||
break;
|
break;
|
||||||
case PRINTF_LENGTH_LONG:
|
|
||||||
printf_signed(va_arg(args, long), radix);
|
case PRINTF_LENGTH_LONG: printf_signed(va_arg(args, long), radix);
|
||||||
break;
|
break;
|
||||||
case PRINTF_LENGTH_LONG_LONG:
|
|
||||||
printf_signed(va_arg(args, long long), radix);
|
case PRINTF_LENGTH_LONG_LONG: printf_signed(va_arg(args, long long), radix);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -287,26 +287,24 @@ void printf(const char* fmt, ...) {
|
|||||||
{
|
{
|
||||||
case PRINTF_LENGTH_SHORT_SHORT:
|
case PRINTF_LENGTH_SHORT_SHORT:
|
||||||
case PRINTF_LENGTH_SHORT:
|
case PRINTF_LENGTH_SHORT:
|
||||||
case PRINTF_LENGTH_DEFAULT:
|
case PRINTF_LENGTH_DEFAULT: printf_unsigned(va_arg(args, unsigned int), radix);
|
||||||
printf_unsigned(va_arg(args, unsigned int), radix);
|
|
||||||
break;
|
break;
|
||||||
case PRINTF_LENGTH_LONG:
|
|
||||||
printf_unsigned(va_arg(args, unsigned long), radix);
|
case PRINTF_LENGTH_LONG: printf_unsigned(va_arg(args, unsigned long), radix);
|
||||||
break;
|
break;
|
||||||
case PRINTF_LENGTH_LONG_LONG:
|
|
||||||
printf_unsigned(va_arg(args, unsigned long long), radix);
|
case PRINTF_LENGTH_LONG_LONG: printf_unsigned(va_arg(args, unsigned long long), radix);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//reset state
|
// reset state
|
||||||
state = PRINTF_STATE_NORMAL;
|
state = PRINTF_STATE_NORMAL;
|
||||||
length = PRINTF_LENGTH_DEFAULT;
|
length = PRINTF_LENGTH_DEFAULT;
|
||||||
radix = 10;
|
radix = 10;
|
||||||
sign = false;
|
sign = false;
|
||||||
bool number = false;
|
number = false;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
26
src/libs/boot/bootparams.h
Normal file
26
src/libs/boot/bootparams.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/*----------------*\
|
||||||
|
|Nanite OS |
|
||||||
|
|Copyright (C) 2024|
|
||||||
|
|Tyler McGurrin |
|
||||||
|
\*----------------*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint64_t Begin, Length;
|
||||||
|
uint32_t Type;
|
||||||
|
uint32_t ACPI;
|
||||||
|
} MemoryRegion;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int RegionCount;
|
||||||
|
MemoryRegion* Regions;
|
||||||
|
} MemoryInfo;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
MemoryInfo Memory;
|
||||||
|
uint8_t BootDevice;
|
||||||
|
} BootParams;
|
||||||
Loading…
x
Reference in New Issue
Block a user