First steps: include Limine, kernel entry point, framebuffer request
This commit is contained in:
116
src/kmain.c
Normal file
116
src/kmain.c
Normal file
@@ -0,0 +1,116 @@
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <limine.h>
|
||||
|
||||
// Limine version used
|
||||
__attribute__((used, section(".limine_requests")))
|
||||
static volatile LIMINE_BASE_REVISION(3);
|
||||
|
||||
// Framebuffer request
|
||||
__attribute__((used, section(".limine_requests")))
|
||||
static volatile struct limine_framebuffer_request framebuffer_request = {
|
||||
.id = LIMINE_FRAMEBUFFER_REQUEST,
|
||||
.revision = 0
|
||||
};
|
||||
|
||||
__attribute__((used, section(".limine_requests_start")))
|
||||
static volatile LIMINE_REQUESTS_START_MARKER;
|
||||
|
||||
__attribute__((used, section(".limine_requests_end")))
|
||||
static volatile LIMINE_REQUESTS_END_MARKER;
|
||||
|
||||
// We won't be linked to standard library, but still need the basic mem* functions
|
||||
// so everything goes allright with the compiler
|
||||
|
||||
// We use the "restrict" keyword on pointers so that the compiler knows it can
|
||||
// do more optimization on them (and as it's a much used function, it's good to
|
||||
// be able to do that)
|
||||
void* memcpy(void* restrict dest, const void* restrict src, size_t n)
|
||||
{
|
||||
uint8_t* restrict pdest = (uint8_t* restrict)dest;
|
||||
const uint8_t* restrict psrc = (const uint8_t* restrict)src;
|
||||
|
||||
for (size_t i=0; i<n; i++)
|
||||
{
|
||||
pdest[i] = psrc[i];
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
void* memset(void* s, int c, size_t n)
|
||||
{
|
||||
uint8_t* p = (uint8_t*)s;
|
||||
|
||||
for (size_t i=0; i<n; i++)
|
||||
{
|
||||
p[i] = (uint8_t)c;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void* memmove(void *dest, const void* src, size_t n)
|
||||
{
|
||||
uint8_t* pdest = (uint8_t*)dest;
|
||||
const uint8_t* psrc = (uint8_t*)src;
|
||||
|
||||
if (src > dest)
|
||||
{
|
||||
for (size_t i=0; i<n; i++)
|
||||
{
|
||||
pdest[i] = psrc[i];
|
||||
}
|
||||
} else if (src < dest)
|
||||
{
|
||||
for (size_t i=n; i>0; i--)
|
||||
{
|
||||
pdest[i-1] = psrc[i-1];
|
||||
}
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
int memcmp(const void* s1, const void* s2, size_t n)
|
||||
{
|
||||
const uint8_t* p1 = (const uint8_t*)s1;
|
||||
const uint8_t* p2 = (const uint8_t*)s2;
|
||||
|
||||
for (size_t i=0; i<n; i++)
|
||||
{
|
||||
if (p1[i] != p2[i])
|
||||
{
|
||||
return p1[i] < p2[i] ? -1 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Panic
|
||||
static void hcf()
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
asm("hlt");
|
||||
}
|
||||
}
|
||||
|
||||
// This is our entry point
|
||||
void kmain()
|
||||
{
|
||||
if (!LIMINE_BASE_REVISION_SUPPORTED) hcf();
|
||||
if (framebuffer_request.response == NULL || framebuffer_request.response->framebuffer_count < 1) hcf();
|
||||
|
||||
// Get the first framebuffer from the response
|
||||
struct limine_framebuffer* framebuffer = framebuffer_request.response->framebuffers[0];
|
||||
|
||||
// Draw something
|
||||
for (size_t i=0; i<100; i++)
|
||||
{
|
||||
volatile uint32_t* fb_ptr = framebuffer->address;
|
||||
fb_ptr[i*(framebuffer->pitch/4) + i] = 0xffffff;
|
||||
}
|
||||
|
||||
hcf();
|
||||
}
|
||||
Reference in New Issue
Block a user