Implement proc_map () and proc_unmap () syscalls
All checks were successful
Build documentation / build-and-deploy (push) Successful in 21s

This commit is contained in:
2026-01-06 23:32:11 +01:00
parent 9f107a1a5e
commit 28aef30f77
15 changed files with 155 additions and 18 deletions

View File

@@ -5,18 +5,13 @@
int msl_amd64_syscall (int syscall_num, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4,
uintptr_t a5, uintptr_t a6) {
uint64_t result;
__asm__ volatile ("movq %1, %%rax\n"
"movq %2, %%rdi\n"
"movq %3, %%rsi\n"
"movq %4, %%rdx\n"
"movq %5, %%r10\n"
"movq %6, %%r8\n"
"movq %7, %%r9\n"
__asm__ volatile ("movq %[a4], %%r10\n"
"movq %[a5], %%r8\n"
"movq %[a6], %%r9\n"
"syscall\n"
"movq %%rax, %0\n"
: "=r"(result)
: "r"((uint64_t)syscall_num), "r"(a1), "r"(a2), "r"(a3), "r"(a4), "r"(a5),
"r"(a6)
: "memory", "cc", "rcx", "r11");
: "=a"(result)
: "a"(syscall_num), "D"(a1), "S"(a2),
"d"(a3), [a4] "r"(a4), [a5] "r"(a5), [a6] "r"(a6)
: "r10", "r8", "r9", "r11", "rcx", "cc", "memory");
return (int)result;
}

13
libmsl/m/mem.h Normal file
View File

@@ -0,0 +1,13 @@
#ifndef _LIBMSL_M_MEM_H
#define _LIBMSL_M_MEM_H
#if defined(__x86_64__)
#define M_PROC_MAP_BASE 0x0000700000000000
#define M_PAGE_SIZE 4096
#endif
#define PM_PRESENT (1 << 0)
#define PM_RW (1 << 1)
#define PM_USER (1 << 2)
#endif // _LIBMSL_M_MEM_H

View File

@@ -1,6 +1,16 @@
#include <m/syscall.h>
#include <m/syscall_defs.h>
#include <stddef.h>
#include <stdint.h>
int m_proc_quit (void) { return m_syscall (SYS_PROC_QUIT, 0, 0, 0, 0, 0, 0); }
int m_proc_test (void) { return m_syscall (SYS_PROC_TEST, 0, 0, 0, 0, 0, 0); }
int m_proc_map (uintptr_t vaddr, size_t pages, uint32_t flags) {
return m_syscall (SYS_PROC_MAP, vaddr, (uintptr_t)pages, (uintptr_t)flags, 0, 0, 0);
}
int m_proc_unmap (uintptr_t vaddr, size_t pages) {
return m_syscall (SYS_PROC_UNMAP, vaddr, (uintptr_t)pages, 0, 0, 0, 0);
}

View File

@@ -1,8 +1,12 @@
#ifndef _LIBMSL_M_PROC_H
#define _LIBMSL_M_PROC_H
int m_proc_quit (void);
#include <stddef.h>
#include <stdint.h>
int m_proc_quit (void);
int m_proc_test (void);
int m_proc_map (uintptr_t vaddr, size_t pages, uint32_t flags);
int m_proc_unmap (uintptr_t vaddr, size_t pages);
#endif // _LIBMSL_M_PROC_H

View File

@@ -1,3 +1,4 @@
include $(platform)/src.mk
include init/src.mk
include m/src.mk
include string/src.mk

1
libmsl/string/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.o

3
libmsl/string/src.mk Normal file
View File

@@ -0,0 +1,3 @@
c += string/string.c
o += string/string.o

47
libmsl/string/string.c Normal file
View File

@@ -0,0 +1,47 @@
#include <stddef.h>
#include <stdint.h>
#include <string/string.h>
size_t memset (void* dst, uint8_t b, size_t n) {
uint8_t* dst1 = dst;
size_t i;
for (i = 0; i < n; i++)
dst1[i] = b;
return i;
}
size_t memcpy (void* dst, const void* src, size_t n) {
uint8_t* dst1 = dst;
const uint8_t* src1 = src;
size_t i;
for (i = 0; i < n; i++)
dst1[i] = src1[i];
return i;
}
// SOURCE: https://stackoverflow.com/a/48967408
void strncpy (char* dst, const char* src, size_t n) {
size_t i = 0;
while (i++ != n && (*dst++ = *src++))
;
}
size_t strlen (const char* str) {
const char* s;
for (s = str; *s; ++s)
;
return (s - str);
}
int memcmp (const void* s1, const void* s2, size_t n) {
unsigned char* p = (unsigned char*)s1;
unsigned char* q = (unsigned char*)s2;
while (n--) {
if (*p != *q) {
return (int)*p - (int)*q;
}
p++, q++;
}
return 0;
}

13
libmsl/string/string.h Normal file
View File

@@ -0,0 +1,13 @@
#ifndef _LIBMSL_STRING_STRING_H
#define _LIBMSL_STRING_STRING_H
#include <stddef.h>
#include <stdint.h>
size_t memset (void* dst, uint8_t b, size_t n);
size_t memcpy (void* dst, const void* src, size_t n);
void strncpy (char* dst, const char* src, size_t n);
size_t strlen (const char* str);
int memcmp (const void* s1, const void* s2, size_t n);
#endif // _LIBMSL_STRING_STRING_H