move keyboard and mouse out of HAL into a standalone ps2.sys driver, implement usb stack with xhci controller discovery, hid keyboard/mouse, and bulk-only mass storage, add pci msi support with capability chain walking and software irq vector allocation (slots 16-23), rewrite user virtual memory as a USER_VA_REGION descriptor arena with per-process ownership tracking and guard page support, replacing the old bump allocator and top-down image region, add MmCreateUserRegion/MmDestroyAllUserRegions so process teardown reclaims all user va in one pass, allocate a pool-backed shadow framebuffer in hal_screen to fix cursor tearing and scroll corruption, reserve ap trampoline page below 1mb in uefi bootloader before boot services exit, rewrite memset/memcpy/memmove/memcmp with __stosq/__movsq intrinsics, promote driver flag literals to macros and add multi-tu STANDALONE_DRIVERS table to build.c, split rtl8139/rtl816x into header+source, rename KbReadScancode to KbReadKey, improve page fault output with MmDebugDescribeAddress and user region dump, fix %p to %016llX throughout.

This commit is contained in:
maksw committed 2026-06-02 00:01:20 +02:00
1 parent b970d7f59c
commit b838f8d83d
130 files changed
+8137 -2932

No files matched your search

+97 -8
View File
@@ -1,6 +1,7 @@
// everyone needs a little libc
#include <stdint.h>
#include <stddef.h>
#include <intrin.h>
char* strcpy(char* dest, const char* src) {
char* d = dest;
@@ -100,22 +101,110 @@ char* strrchr(const char* s, int c) {
return (char*)last;
}
void* memset(void* dest, int c, size_t n) {
unsigned char* d = (unsigned char*)dest;
size_t qwords = n / 8;
size_t tail = n % 8;
if (qwords > 0) {
uint64_t value = (unsigned char)c;
value |= value << 8;
value |= value << 16;
value |= value << 32;
__stosq((unsigned __int64*)d, value, qwords);
d += qwords * 8;
}
if (tail > 0) {
__stosb(d, (unsigned char)c, tail);
}
return dest;
}
void* memcpy(void* dest, const void* src, size_t n) {
unsigned char* d = (unsigned char*)dest;
const unsigned char* s = (const unsigned char*)src;
size_t qwords = n / 8;
size_t tail = n % 8;
if (qwords > 0) {
__movsq((unsigned __int64*)d, (const unsigned __int64*)s, qwords);
d += qwords * 8;
s += qwords * 8;
}
if (tail > 0) {
__movsb(d, s, tail);
}
return dest;
}
void* memmove(void* dest, const void* src, size_t n) {
uint8_t* d = (uint8_t *)dest;
const uint8_t* s = (const uint8_t *)src;
unsigned char* d = (unsigned char*)dest;
const unsigned char* s = (const unsigned char*)src;
if (d < s) {
for (size_t i = 0; i < n; i++) d[i] = s[i];
// Forward copy: safe to use chunked __movsq + tail
size_t qwords = n / 8;
size_t tail = n % 8;
if (qwords > 0) {
__movsq((unsigned __int64*)d, (const unsigned __int64*)s, qwords);
d += qwords * 8;
s += qwords * 8;
}
if (tail > 0) {
__movsb(d, s, tail);
}
} else if (d > s) {
for (size_t i = n; i > 0; i--) d[i - 1] = s[i - 1];
// Backward copy: must process from end to avoid corruption
size_t qwords = n / 8;
size_t tail = n % 8;
// Copy tail bytes first from the very end
if (tail > 0) {
for (size_t i = tail; i > 0; i--) {
d[qwords * 8 + i - 1] = s[qwords * 8 + i - 1];
}
}
// Copy 64-bit chunks backward
if (qwords > 0) {
unsigned __int64* dq = (unsigned __int64*)d;
const unsigned __int64* sq = (const unsigned __int64*)s;
for (size_t i = qwords; i > 0; i--) {
dq[i - 1] = sq[i - 1];
}
}
}
return dest;
}
int memcmp(const void* s1, const void* s2, size_t n) {
const uint8_t* a = (const uint8_t *)s1;
const uint8_t* b = (const uint8_t *)s2;
for (size_t i = 0; i < n; i++) {
if (a[i] != b[i]) return a[i] - b[i];
const unsigned __int64* a64 = (const unsigned __int64*)s1;
const unsigned __int64* b64 = (const unsigned __int64*)s2;
size_t qwords = n / 8;
size_t tail = n % 8;
// Compare 8-byte blocks
for (size_t i = 0; i < qwords; i++) {
if (a64[i] != b64[i]) {
// Locate the exact mismatching byte within the quadword
const unsigned char* a8 = (const unsigned char*)&a64[i];
const unsigned char* b8 = (const unsigned char*)&b64[i];
for (size_t j = 0; j < 8; j++) {
if (a8[j] != b8[j]) return (int)a8[j] - (int)b8[j];
}
}
}
// Compare remaining tail bytes
const unsigned char* a8 = (const unsigned char*)(a64 + qwords);
const unsigned char* b8 = (const unsigned char*)(b64 + qwords);
for (size_t i = 0; i < tail; i++) {
if (a8[i] != b8[i]) return (int)a8[i] - (int)b8[i];
}
return 0;
}