mirror of
https://github.com/XunilGroup/XunilOS.git
synced 2026-04-25 19:59:02 +02:00
Add a scheduler which just keeps of processes for now, and a
with_process to interact with them. User space now has it's own address space and mapper which means we will be able to allocate memory for it. I added a bunch of functions as stubs into libxunil which are required for doomgeneric.
This commit is contained in:
66
user/libxunil/src/file.rs
Normal file
66
user/libxunil/src/file.rs
Normal file
@@ -0,0 +1,66 @@
|
||||
use core::ptr::null_mut;
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn fopen(path: *const u8, mode: *const u8) -> *mut u8 {
|
||||
null_mut()
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn fclose(file_ptr: *mut u8) -> i32 {
|
||||
0
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn fprintf(file_ptr: *mut u8, s: *const u8) -> i32 {
|
||||
0
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn fread(ptr: *mut u8, size: i32, nmemb: *const u8, fp: *const u8) -> i32 {
|
||||
0
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn fwrite(ptr: *mut u8, size: i32, nmemb: *const u8, fp: *const u8) -> i32 {
|
||||
0
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn fseek(s: *const u8, size: i32, fp: *const u8) -> i32 {
|
||||
0
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn ftell(fp: *const u8) -> i64 {
|
||||
0
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn fflush(file_ptr: *mut u8) -> i32 {
|
||||
0
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn mkdir(path: *const u8, mode: *const u8) -> i32 {
|
||||
0
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn remove(path: *const u8) -> i32 {
|
||||
0
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn rename(path: *const u8, new_path: *const u8) -> i32 {
|
||||
0
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn vfprintf(stream: *const u8, format: *const u8, args: ...) -> i32 {
|
||||
0
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn vsnprintf(s: *mut u8, n: i32, format: *const u8, args: ...) -> i32 {
|
||||
0
|
||||
}
|
||||
2
user/libxunil/src/include/inttypes.h
Normal file
2
user/libxunil/src/include/inttypes.h
Normal file
@@ -0,0 +1,2 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
42
user/libxunil/src/include/stdio.h
Normal file
42
user/libxunil/src/include/stdio.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
typedef struct _iobuf
|
||||
{
|
||||
char* _ptr;
|
||||
int _cnt;
|
||||
char* _base;
|
||||
int _flag;
|
||||
int _file;
|
||||
int _charbuf;
|
||||
int _bufsiz;
|
||||
char* _tmpfname;
|
||||
} FILE;
|
||||
|
||||
extern FILE *stdin;
|
||||
extern FILE *stdout;
|
||||
extern FILE *stderr;
|
||||
|
||||
#define EOF (-1)
|
||||
|
||||
FILE *fopen(const char *path, const char *mode);
|
||||
int fclose(FILE *fp);
|
||||
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *fp);
|
||||
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *fp);
|
||||
int fseek(FILE *fp, long offset, int whence);
|
||||
long ftell(FILE *fp);
|
||||
int fflush(FILE *fp);
|
||||
char *fgets(char *s, int size, FILE *fp);
|
||||
int fputs(const char *s, FILE *fp);
|
||||
int feof(FILE *fp);
|
||||
int ferror(FILE *fp);
|
||||
|
||||
int printf(const char *fmt, ...);
|
||||
int fprintf(FILE *fp, const char *fmt, ...);
|
||||
int sprintf(char *buf, const char *fmt, ...);
|
||||
int snprintf(char *buf, size_t size, const char *fmt, ...);
|
||||
int vsnprintf(char *buf, size_t size, const char *fmt, va_list ap);
|
||||
int vfprintf(FILE *fp, const char *fmt, va_list ap);
|
||||
void write(int fd, const char* buf, unsigned long count);
|
||||
void exit(int code);
|
||||
20
user/libxunil/src/include/stdlib.h
Normal file
20
user/libxunil/src/include/stdlib.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include <stddef.h>
|
||||
|
||||
void *malloc(size_t size);
|
||||
void *calloc(size_t nmemb, size_t size);
|
||||
void *realloc(void *ptr, size_t size);
|
||||
void free(void *ptr);
|
||||
|
||||
void exit(int status);
|
||||
void abort(void);
|
||||
|
||||
int atoi(const char *s);
|
||||
long atol(const char *s);
|
||||
double atof(const char *s);
|
||||
long strtol(const char *s, char **endptr, int base);
|
||||
double strtod(const char *s, char **endptr);
|
||||
|
||||
char *getenv(const char *name);
|
||||
void qsort(void *base, size_t nmemb, size_t size, int (*cmp)(const void *, const void *));
|
||||
int abs(int x);
|
||||
22
user/libxunil/src/include/string.h
Normal file
22
user/libxunil/src/include/string.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include <stddef.h>
|
||||
|
||||
void *memset(void *s, int c, size_t n);
|
||||
void *memcpy(void *dst, const void *src, size_t n);
|
||||
void *memmove(void *dst, const void *src, size_t n);
|
||||
int memcmp(const void *s1, const void *s2, size_t n);
|
||||
void *memchr(const void *s, int c, size_t n);
|
||||
|
||||
size_t strlen(const char *s);
|
||||
char *strcpy(char *dst, const char *src);
|
||||
char *strncpy(char *dst, const char *src, size_t n);
|
||||
char *strcat(char *dst, const char *src);
|
||||
char *strncat(char *dst, const char *src, size_t n);
|
||||
int strcmp(const char *s1, const char *s2);
|
||||
int strncmp(const char *s1, const char *s2, size_t n);
|
||||
char *strchr(const char *s, int c);
|
||||
char *strrchr(const char *s, int c);
|
||||
char *strstr(const char *haystack, const char *needle);
|
||||
char *strtok(char *str, const char *delim);
|
||||
char *strdup(const char *s);
|
||||
char *strerror(int errnum);
|
||||
8
user/libxunil/src/include/strings.h
Normal file
8
user/libxunil/src/include/strings.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include <stddef.h>
|
||||
|
||||
int strcasecmp(const char *s1, const char *s2);
|
||||
int strncasecmp(const char *s1, const char *s2, size_t n);
|
||||
void bzero(void *s, size_t n);
|
||||
void bcopy(const void *src, void *dest, size_t n);
|
||||
int bcmp(const void *s1, const void *s2, size_t n);
|
||||
@@ -1,20 +1,24 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(c_variadic)]
|
||||
|
||||
use core::ptr::null;
|
||||
|
||||
use crate::syscall::syscall3;
|
||||
|
||||
pub mod file;
|
||||
pub mod mem;
|
||||
pub mod syscall;
|
||||
|
||||
const SYS_EXIT: usize = 1;
|
||||
const SYS_WRITE: usize = 60;
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn write(fd: i32, buf: *const u8, count: usize) -> isize {
|
||||
extern "C" fn write(fd: i64, buf: *const u8, count: usize) -> isize {
|
||||
unsafe { syscall3(SYS_WRITE, fd as usize, buf as usize, count) }
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn exit(code: i32) -> ! {
|
||||
extern "C" fn exit(code: i64) -> ! {
|
||||
unsafe { syscall3(SYS_EXIT, code as usize, 0, 0) };
|
||||
loop {}
|
||||
}
|
||||
@@ -36,14 +40,26 @@ extern "C" fn puts(s: *const u8) -> isize {
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn abs(n: i32) -> i32 {
|
||||
extern "C" fn putchar(s: i32) -> isize {
|
||||
write(1, (s as u8 + b'0') as *const u8, 1);
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn abs(n: i64) -> i64 {
|
||||
n.abs()
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn atoi(mut c: *const u8) -> i32 {
|
||||
let mut value: i32 = 0;
|
||||
let mut sign: i32 = 1;
|
||||
unsafe extern "C" fn printf(format: *const u8, args: ...) {
|
||||
unsafe { syscall3(SYS_WRITE, 1, format as usize, strlen(format)) };
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn atoi(mut c: *const u8) -> i64 {
|
||||
let mut value: i64 = 0;
|
||||
let mut sign: i64 = 1;
|
||||
unsafe {
|
||||
if (*c) == b'+' || (*c) == b'-' {
|
||||
if *c == b'-' {
|
||||
@@ -53,7 +69,7 @@ extern "C" fn atoi(mut c: *const u8) -> i32 {
|
||||
}
|
||||
while (*c).is_ascii_digit() {
|
||||
value *= 10;
|
||||
value += ((*c) - b'0') as i32;
|
||||
value += ((*c) - b'0') as i64;
|
||||
c = c.add(1);
|
||||
}
|
||||
}
|
||||
@@ -61,6 +77,115 @@ extern "C" fn atoi(mut c: *const u8) -> i32 {
|
||||
value * sign
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn atof(mut c: *const u8) -> f64 {
|
||||
0.0
|
||||
}
|
||||
|
||||
pub fn compare_str(str_1: *const u8, str_2: *const u8, case: bool, n: usize) -> i32 {
|
||||
let mut len = 0;
|
||||
|
||||
while len < n {
|
||||
let mut c_1 = unsafe { *str_1.add(len) };
|
||||
let mut c_2 = unsafe { *str_2.add(len) };
|
||||
|
||||
if case {
|
||||
c_1 = c_1.to_ascii_lowercase();
|
||||
c_2 = c_2.to_ascii_lowercase();
|
||||
}
|
||||
|
||||
if c_1 != c_2 {
|
||||
return (c_1 - c_2) as i32;
|
||||
}
|
||||
|
||||
if c_1 == 0 {
|
||||
return 0;
|
||||
}
|
||||
|
||||
len += 1;
|
||||
}
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn strcasecmp(str_1: *const u8, str_2: *const u8) -> i32 {
|
||||
compare_str(str_1, str_2, true, 999999999999999)
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn strcmp(str_1: *const u8, str_2: *const u8) -> i32 {
|
||||
compare_str(str_1, str_2, false, 999999999999999)
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn strncasecmp(str_1: *const u8, str_2: *const u8, n: i32) -> i32 {
|
||||
compare_str(str_1, str_2, true, n as usize)
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn strncmp(str_1: *const u8, str_2: *const u8, n: i32) -> i32 {
|
||||
compare_str(str_1, str_2, false, n as usize)
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn strncopy(s: *const u8, n: i32) -> *const u8 {
|
||||
null()
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn strdup(s: *const u8) -> *const u8 {
|
||||
null()
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn strstr(s: *const u8) -> *const u8 {
|
||||
null()
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn strchr(s: *const u8, ch: u8) -> *const u8 {
|
||||
null()
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn strrchr(s: *const u8, ch: u8) -> *const u8 {
|
||||
let mut n = 0;
|
||||
let mut last: *const u8 = null();
|
||||
|
||||
if ch == 0 {
|
||||
while unsafe { *s.add(n) } != 0 {
|
||||
n += 1;
|
||||
}
|
||||
unsafe { s.add(n + 1) }
|
||||
} else {
|
||||
while unsafe { *s.add(n) } != 0 {
|
||||
let cur_ch = unsafe { s.add(n) };
|
||||
if unsafe { *cur_ch == ch } {
|
||||
last = cur_ch;
|
||||
}
|
||||
n += 1;
|
||||
}
|
||||
|
||||
last
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn toupper(char: u8) -> u8 {
|
||||
char.to_ascii_uppercase()
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn tolower(char: u8) -> u8 {
|
||||
char.to_ascii_lowercase()
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn system(cmd: *const u8) -> i32 {
|
||||
0
|
||||
}
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(_: &core::panic::PanicInfo) -> ! {
|
||||
loop {}
|
||||
|
||||
27
user/libxunil/src/mem.rs
Normal file
27
user/libxunil/src/mem.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use core::ptr::null_mut;
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn calloc(nitems: u64, size: u64) -> *mut u8 {
|
||||
null_mut()
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn free(ptr: *mut u8) {}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn malloc(size: u64) -> *mut u8 {
|
||||
null_mut()
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn memcpy(dest_str: *mut u8, src_str: *const u8, n: u64) {}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn memset(str: *mut u8, c: i64, n: u64) -> *mut u8 {
|
||||
null_mut()
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn realloc(ptr: *mut u8, size: u64) -> *mut u8 {
|
||||
null_mut()
|
||||
}
|
||||
Reference in New Issue
Block a user