mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-03 18:22:22 +00:00
Implemented a proper libc
This commit is contained in:
@@ -3,8 +3,8 @@ CC := i686-elf-gcc
|
|||||||
LD := i686-elf-ld
|
LD := i686-elf-ld
|
||||||
AS := nasm
|
AS := nasm
|
||||||
|
|
||||||
CFLAGS := -g -std=c17 -ffreestanding -fno-builtin -fno-stack-protector -fno-pie \
|
CCFLAGS := -g -std=c17 -ffreestanding -fno-builtin -fno-stack-protector -fno-pie \
|
||||||
-Os -nostdinc -mgeneral-regs-only -m32 -march=i386 -Wall -Iinclude/c
|
-Os -nostdinc -mgeneral-regs-only -m32 -march=i386 -Wall
|
||||||
LDFLAGS := -z notext -melf_i386 -nostdlib
|
LDFLAGS := -z notext -melf_i386 -nostdlib
|
||||||
ASFLAGS :=
|
ASFLAGS :=
|
||||||
|
|
||||||
@@ -12,61 +12,78 @@ include make.config
|
|||||||
|
|
||||||
SRC := ./src
|
SRC := ./src
|
||||||
BIN := ./bin
|
BIN := ./bin
|
||||||
|
LIBK_INC := ./include
|
||||||
|
LIBC_INC := ./include/libc
|
||||||
|
LIBC_DIR := ./libc
|
||||||
|
LIBK_DIR := ./libk
|
||||||
|
|
||||||
C_FILES := calc edit
|
C_FILES := calc edit
|
||||||
FONTS := testfont term16n
|
FONTS := testfont term16n
|
||||||
|
|
||||||
|
BOOTLOADER := $(BIN)/stage1.bin $(BIN)/stage2.bin $(BIN)/stage3.bin
|
||||||
|
KERNEL := $(BIN)/kernel.bin
|
||||||
|
LIBC := $(BIN)/libc.o
|
||||||
|
# TODO: LIBK := $(BIN)/libk.o
|
||||||
|
ISO := kern.iso
|
||||||
|
|
||||||
.PHONY: os clean run
|
.PHONY: os clean run
|
||||||
|
|
||||||
# Main compilation target
|
# Main compilation target
|
||||||
os: $(BIN) bootloader kernel $(C_FILES) $(FONTS)
|
os: $(ISO)
|
||||||
@cc ./makedisk.c -o ./makedisk
|
$(ISO): $(BIN) $(BOOTLOADER) $(KERNEL) $(C_FILES) $(FONTS)
|
||||||
@./makedisk # TODO: List of files
|
cc ./makedisk.c -o ./makedisk
|
||||||
|
./makedisk # TODO: List of files
|
||||||
@echo "\nDone!\n"
|
@echo "\nDone!\n"
|
||||||
|
|
||||||
$(BIN):
|
$(BIN):
|
||||||
@[ -d $(BIN) ] || mkdir $(BIN)
|
[ -d $(BIN) ] || mkdir $(BIN)
|
||||||
@rm -rf $(BIN)/*
|
rm -rf $(BIN)/*
|
||||||
|
|
||||||
# Bootloader: This target is responsible for creating stage?.bin (1,2,3)
|
# Bootloader: This target is responsible for creating stage?.bin (1,2,3)
|
||||||
bootloader: $(SRC)/stage1.asm $(SRC)/stage2.asm
|
$(BOOTLOADER): $(SRC)/stage1.asm $(SRC)/stage2.asm $(SRC)/stage3.c $(LIBC)
|
||||||
@echo "Assembling $(SRC)/stage1.asm..."
|
@echo "Assembling $(SRC)/stage1.asm..."
|
||||||
@$(AS) -fbin -o $(BIN)/stage1.bin $(SRC)/stage1.asm $(ASFLAGS)
|
$(AS) -fbin -o $(BIN)/stage1.bin $(SRC)/stage1.asm $(ASFLAGS)
|
||||||
@echo "Assembling $(SRC)/stage2.asm..."
|
@echo "Assembling $(SRC)/stage2.asm..."
|
||||||
@$(AS) -fbin -o $(BIN)/stage2.bin $(SRC)/stage2.asm $(ASFLAGS)
|
$(AS) -fbin -o $(BIN)/stage2.bin $(SRC)/stage2.asm $(ASFLAGS)
|
||||||
@echo "Compiling $(SRC)/stage3.c..."
|
@echo "Compiling $(SRC)/stage3.c..."
|
||||||
@$(CC) $(CFLAGS) -Iinclude -o $(BIN)/stage3.o -c $(SRC)/stage3.c
|
$(CC) $(CCFLAGS) -I$(LIBK_INC) -I$(LIBC_INC) -o $(BIN)/stage3.o -c $(SRC)/stage3.c
|
||||||
@$(LD) $(LDFLAGS) -T$(SRC)/stage3.ld --oformat binary -o $(BIN)/stage3.bin $(BIN)/stage3.o
|
$(LD) $(LDFLAGS) -T$(SRC)/stage3.ld --oformat binary -o $(BIN)/stage3.bin $(BIN)/stage3.o $(LIBC)
|
||||||
@rm $(BIN)/stage3.o
|
rm $(BIN)/stage3.o
|
||||||
|
|
||||||
# Kernel: This target is responsible for creating kernel.bin
|
# Kernel: This target is responsible for creating kernel.bin
|
||||||
kernel: $(SRC)/kernel.c
|
$(KERNEL): $(SRC)/kernel.c $(LIBC) #TODO: $(LIBK)
|
||||||
@echo "Compiling $(SRC)/kernel.c..."
|
@echo "Compiling $(SRC)/kernel.c..."
|
||||||
@$(CC) $(CFLAGS) -Iinclude -o $(BIN)/kernel.o -c $(SRC)/kernel.c
|
$(CC) $(CCFLAGS) -I$(LIBK_INC) -I$(LIBC_INC) -o $(BIN)/kernel.o -c $(SRC)/kernel.c
|
||||||
@$(LD) $(LDFLAGS) -T$(SRC)/kernel.ld --oformat binary -o $(BIN)/kernel.bin $(BIN)/kernel.o
|
$(LD) $(LDFLAGS) -T$(SRC)/kernel.ld --oformat binary -o $(BIN)/kernel.bin $(BIN)/kernel.o $(LIBC) #TODO: LIBK
|
||||||
@rm $(BIN)/kernel.o
|
rm $(BIN)/kernel.o
|
||||||
|
|
||||||
# This target compiles *.c (except kernel.c)
|
# This target compiles *.c (except kernel.c)
|
||||||
$(C_FILES):
|
$(C_FILES): $(LIBC)
|
||||||
@echo "Compiling $(SRC)/$@.c..."
|
@echo "Compiling $(SRC)/$@.c..."
|
||||||
@$(CC) $(CFLAGS) -o $(BIN)/$@.o -c $(SRC)/$@.c
|
$(CC) $(CCFLAGS) -I$(LIBC_INC) -o $(BIN)/$@.o -c $(SRC)/$@.c
|
||||||
@$(LD) $(LDFLAGS) -T$(SRC)/$@.ld --oformat binary -o $(BIN)/$@.bin $(BIN)/$@.o
|
$(LD) $(LDFLAGS) -T$(SRC)/$@.ld --oformat binary -o $(BIN)/$@.bin $(BIN)/$@.o $(LIBC)
|
||||||
@rm $(BIN)/$@.o
|
rm $(BIN)/$@.o
|
||||||
|
|
||||||
# This target builds all fonts inside src/fonts
|
$(LIBC): $(LIBC_DIR)/**.c
|
||||||
|
@echo "Compiling $(LIBC)..."
|
||||||
|
mkdir -p $(BIN)/libc
|
||||||
|
for f in libc/*.c; do $(CC) $(CCFLAGS) -I$(LIBC_INC) -o $(BIN)/$$f.o -c $$f; done
|
||||||
|
$(LD) $(LDFLAGS) -r -o $(LIBC) $(BIN)/libc/**.o
|
||||||
|
|
||||||
|
# This target retrieves all fonts inside src/fonts
|
||||||
$(FONTS):
|
$(FONTS):
|
||||||
@cp $(SRC)/fonts/$@.fnt $(BIN)/$@.fnt
|
cp $(SRC)/fonts/$@.fnt $(BIN)/$@.fnt
|
||||||
|
|
||||||
# Run QEMU
|
# Run QEMU
|
||||||
run:
|
run:
|
||||||
qemu-system-x86_64\
|
qemu-system-x86_64\
|
||||||
-drive format=raw,file="./kern.iso",index=0,media=disk\
|
-drive format=raw,file=$(ISO),index=0,media=disk\
|
||||||
-m 256M -accel tcg -monitor stdio\
|
-m 256M -accel tcg -monitor stdio\
|
||||||
-rtc base=localtime,clock=host,driftfix=slew\
|
-rtc base=localtime,clock=host,driftfix=slew\
|
||||||
-audiodev coreaudio,id=audio0 -machine pcspk-audiodev=audio0
|
-audiodev coreaudio,id=audio0 -machine pcspk-audiodev=audio0
|
||||||
|
|
||||||
# Clean all build files
|
# Clean all build files
|
||||||
clean:
|
clean:
|
||||||
@rm -rf $(BIN)
|
rm -rf $(BIN)
|
||||||
@#rm -f kern.iso
|
rm -f makedisk
|
||||||
@rm -f makedisk
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#ifndef COLOR_H
|
||||||
|
#define COLOR_H
|
||||||
|
|
||||||
|
#define BLACK 0x00000000 // 0
|
||||||
|
#define RED 0x00ff0000 // 1
|
||||||
|
#define GREEN 0x0000ff00 // 2
|
||||||
|
#define YELLOW 0x00ffff00 // 3
|
||||||
|
#define BLUE 0x000000ff // 4
|
||||||
|
#define MAGENTA 0x00ff00ff // 5
|
||||||
|
#define CYAN 0x0000ffff // 6
|
||||||
|
#define WHITE 0x00ffffff // 7
|
||||||
|
|
||||||
|
uint32_t codeToColor(uint8_t code);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
#ifndef STDIO_H
|
||||||
|
#define STDIO_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
// Nobody should have to interface with the internals of this structure
|
||||||
|
typedef struct _iobuf { // 24B
|
||||||
|
unsigned char* _ptr; // File buffer base
|
||||||
|
unsigned int _size; // Size of buffer
|
||||||
|
int _offset; // Offset into file
|
||||||
|
unsigned short _flag; // Open flags
|
||||||
|
int _file; // File descriptor
|
||||||
|
|
||||||
|
char __reserved[6];
|
||||||
|
} FILE;
|
||||||
|
|
||||||
|
// Standard file pointers
|
||||||
|
extern FILE* stdin;
|
||||||
|
extern FILE* stdout;
|
||||||
|
extern FILE* stderr;
|
||||||
|
|
||||||
|
/* File IO */
|
||||||
|
FILE* fopen(const char* filename, const char* mode);
|
||||||
|
int fclose(FILE* stream);
|
||||||
|
size_t fread(void* ptr, size_t size, size_t count, FILE* stream);
|
||||||
|
size_t fwrite(const void* ptr, size_t size, size_t count, FILE* stream);
|
||||||
|
int fseek(FILE* stream, long int origin, int offset);
|
||||||
|
long int ftell(FILE* stream);
|
||||||
|
|
||||||
|
/* Terminal IO */
|
||||||
|
int printf(const char* fmt, ...);
|
||||||
|
int sprintf(char* str, const char* fmt, ...);
|
||||||
|
int snprintf(char* str, size_t n, const char* fmt, ...);
|
||||||
|
int fprintf(FILE* stream, const char* fmt, ...);
|
||||||
|
void putc(char c);
|
||||||
|
char getc();
|
||||||
|
void print(const char* str);
|
||||||
|
void clear();
|
||||||
|
void reads(char* str);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef STDLIB_H
|
||||||
|
#define STDLIB_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <syscall.h>
|
||||||
|
|
||||||
|
void* malloc(const uint32_t size);
|
||||||
|
void free(const void* ptr);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#ifndef STRING_H
|
||||||
|
#define STRING_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
void* memcpy(void* src, void* dst, uint32_t length);
|
||||||
|
void* memcpy32(void* src, void* dst, uint32_t length);
|
||||||
|
void* memset(void* dst, uint8_t value, uint32_t length);
|
||||||
|
|
||||||
|
char* itoa(uint32_t val, uint8_t base);
|
||||||
|
uint32_t atoi(const char* str);
|
||||||
|
int isSpace(char c);
|
||||||
|
char* strcpy(char* str1, const char* str2);
|
||||||
|
char* strncpy(char* str1, const char* str2, size_t n);
|
||||||
|
char* strcat(char* str1, const char* str2);
|
||||||
|
char* strncat(char* str1, const char* str2, size_t n);
|
||||||
|
char* strchr(const char* str, char c);
|
||||||
|
char* strrchr(const char* str, char c);
|
||||||
|
int strcmp(const char* str1, const char* str2);
|
||||||
|
int strncmp(const char* str1, const char* str2, size_t n);
|
||||||
|
uint32_t strlen(const char* str);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
#ifndef SYSCALL_H
|
||||||
|
#define SYSCALL_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#define MAX_SYSCALLS 9
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
SYS_RESERVED,
|
||||||
|
SYS_SLEEP,
|
||||||
|
SYS_READ,
|
||||||
|
SYS_WRITE,
|
||||||
|
SYS_OPEN,
|
||||||
|
SYS_CLOSE,
|
||||||
|
SYS_MALLOC,
|
||||||
|
SYS_FREE,
|
||||||
|
SYS_SEEK,
|
||||||
|
} SYSCALL_NUMBERS;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
O_CREAT = 0x01, // Create if does not exist
|
||||||
|
O_RDONLY = 0x02, // Read only
|
||||||
|
O_WRONLY = 0x04, // Write only
|
||||||
|
O_RDWR = 0x08, // Read and write
|
||||||
|
O_APPEND = 0x10, // Always writes at the end (appends)
|
||||||
|
O_TRUNC = 0x20, // Truncate file size and position to 0 on Open
|
||||||
|
O_BIN = 0x40, // Read bytes, not text
|
||||||
|
} OFLAGS;
|
||||||
|
|
||||||
|
int syscall(int nr, int arg0, int arg1, int arg2);
|
||||||
|
|
||||||
|
/* Syscall wrappers */
|
||||||
|
int read(int fd, void* ptr, size_t count);
|
||||||
|
int write(int fd, const void* ptr, size_t count);
|
||||||
|
int open(const char* path, int oflag);
|
||||||
|
int close(int fd);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef TIME_H
|
||||||
|
#define TIME_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
void sleep(uint32_t ms);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,25 +1,8 @@
|
|||||||
#ifndef _FILEIO_H
|
#include <stdio.h>
|
||||||
#define _FILEIO_H
|
|
||||||
|
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
// Nobody should have to interface with the internals of this structure
|
|
||||||
typedef struct _iobuf { // 24B
|
|
||||||
unsigned char* _ptr; // File buffer base
|
|
||||||
unsigned int _size; // Size of buffer
|
|
||||||
int _offset; // Offset into file
|
|
||||||
unsigned short _flag; // Open flags
|
|
||||||
int _file; // File descriptor
|
|
||||||
|
|
||||||
char __reserved[6];
|
|
||||||
} FILE;
|
|
||||||
|
|
||||||
FILE* stdin;
|
|
||||||
FILE* stdout;
|
|
||||||
FILE* stderr;
|
|
||||||
|
|
||||||
FILE* fopen(const char* filename, const char* mode) {
|
FILE* fopen(const char* filename, const char* mode) {
|
||||||
int oflag = O_RDWR | O_CREAT | O_BIN; // TODO!
|
int oflag = O_RDWR | O_CREAT | O_BIN; // TODO!
|
||||||
|
|
||||||
@@ -79,5 +62,3 @@ long int ftell(FILE* stream) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1,14 +1,11 @@
|
|||||||
#ifndef _PRINTF_H
|
#include <stdio.h>
|
||||||
#define _PRINTF_H
|
|
||||||
|
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <_fileio.h>
|
|
||||||
|
|
||||||
// Warning: returns a allocated buffer, must be freed!
|
// Warning: returns an allocated buffer, must be freed!
|
||||||
char* _format(const char* fmt, va_list args) {
|
char* _format(const char* fmt, va_list args) {
|
||||||
static char* buffer;
|
static char* buffer;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
@@ -126,5 +123,3 @@ int printf(const char* fmt, ...) {
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1,14 +1,5 @@
|
|||||||
#ifndef COLOR_H
|
#include <stdint.h>
|
||||||
#define COLOR_H
|
#include <color.h>
|
||||||
|
|
||||||
#define BLACK 0x00000000 // 0
|
|
||||||
#define RED 0x00ff0000 // 1
|
|
||||||
#define GREEN 0x0000ff00 // 2
|
|
||||||
#define YELLOW 0x00ffff00 // 3
|
|
||||||
#define BLUE 0x000000ff // 4
|
|
||||||
#define MAGENTA 0x00ff00ff // 5
|
|
||||||
#define CYAN 0x0000ffff // 6
|
|
||||||
#define WHITE 0x00ffffff // 7
|
|
||||||
|
|
||||||
uint32_t codeToColor(uint8_t code) {
|
uint32_t codeToColor(uint8_t code) {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
@@ -24,4 +15,3 @@ uint32_t codeToColor(uint8_t code) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef MATH_H
|
||||||
|
#define MATH_H
|
||||||
|
|
||||||
|
// Constants
|
||||||
|
#define PI 3.141592653589 // Should be good enough
|
||||||
|
#define E 2.718281828459
|
||||||
|
|
||||||
|
// Macros
|
||||||
|
#define abs(x) ( (x) > 0 ? (x) : -(x) )
|
||||||
|
#define sign(x) ( (x) == 0 ? 0 : ((x) < 0 ? -1 : 1 ) )
|
||||||
|
|
||||||
|
#define floor(x) ( (int)(x) ) // C floors floats when converting to ints
|
||||||
|
#define round(x) ( (int)((x) + 0.5) ) // Normal rounding
|
||||||
|
#define ceil(x) ( (int)((x) + 1) ) // Always rounds up
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef STDARG_H
|
||||||
|
#define STDARG_H
|
||||||
|
|
||||||
|
typedef char* va_list;
|
||||||
|
#define va_start(ap, paramn) (void)((ap) = (char*)(&(paramn) + 1))
|
||||||
|
#define va_end(ap) (void)((ap) = 0)
|
||||||
|
#define va_arg(ap, type) (((type*)((ap) = ((ap) + sizeof(type))))[-1])
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef BOOL_H
|
||||||
|
#define BOOL_H
|
||||||
|
|
||||||
|
#define bool _Bool
|
||||||
|
#define true 1
|
||||||
|
#define false 0
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#ifndef STDDEF_H
|
||||||
|
#define STDDEF_H
|
||||||
|
|
||||||
|
#define NULL ((void*)0)
|
||||||
|
|
||||||
|
typedef unsigned int size_t;
|
||||||
|
typedef signed int ssize_t;
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
#ifndef STDINT_H
|
||||||
|
#define STDINT_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
// Signed ints
|
||||||
|
typedef signed char int8_t;
|
||||||
|
typedef signed short int16_t;
|
||||||
|
typedef signed int int32_t;
|
||||||
|
typedef signed long long int64_t;
|
||||||
|
|
||||||
|
// Unsigned ints
|
||||||
|
typedef unsigned char uint8_t;
|
||||||
|
typedef unsigned short uint16_t;
|
||||||
|
typedef unsigned int uint32_t;
|
||||||
|
typedef unsigned long long uint64_t;
|
||||||
|
|
||||||
|
// TODO: floats
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,20 +1,12 @@
|
|||||||
#ifndef STDIO_H
|
#include <stdio.h>
|
||||||
#define STDIO_H
|
|
||||||
|
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
/* Declarations */
|
FILE* stdin;
|
||||||
void putc(char);
|
FILE* stdout;
|
||||||
char getc();
|
FILE* stderr;
|
||||||
|
|
||||||
int printf(const char*, ...);
|
|
||||||
|
|
||||||
/* STDIO Include */
|
|
||||||
#include <_fileio.h>
|
|
||||||
#include <_printf.h>
|
|
||||||
|
|
||||||
void putc(char c) {
|
void putc(char c) {
|
||||||
// write(stdout, &c, 1); TODO: This doesn't work and we need to use a static variable
|
// write(stdout, &c, 1); TODO: This doesn't work and we need to use a static variable
|
||||||
@@ -59,4 +51,3 @@ void reads(char* buffer) {
|
|||||||
buffer[len] = '\0'; // Null terminate
|
buffer[len] = '\0'; // Null terminate
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
#ifndef STDLIB_H
|
|
||||||
#define STDLIB_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
void* malloc(const uint32_t size) {
|
void* malloc(const uint32_t size) {
|
||||||
return (void*)syscall(SYS_MALLOC, size, 0, 0);
|
return (void*)syscall(SYS_MALLOC, size, 0, 0);
|
||||||
@@ -12,4 +10,3 @@ void free(const void* ptr) {
|
|||||||
syscall(SYS_FREE, (int)ptr, 0, 0);
|
syscall(SYS_FREE, (int)ptr, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,12 +1,6 @@
|
|||||||
#ifndef STRING_H
|
#include <string.h>
|
||||||
#define STRING_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
void* memcpy(void* src, void* dst, uint32_t length);
|
|
||||||
void* memcpy32(void* src, void* dst, uint32_t length);
|
|
||||||
void* memset(void* dst, uint8_t value, uint32_t length);
|
|
||||||
|
|
||||||
// Source: http://www.strudel.org.uk/itoa/
|
// Source: http://www.strudel.org.uk/itoa/
|
||||||
char* itoa(uint32_t val, uint8_t base) {
|
char* itoa(uint32_t val, uint8_t base) {
|
||||||
static char buf[32] = { 0 };
|
static char buf[32] = { 0 };
|
||||||
@@ -84,7 +78,7 @@ char* strchr(const char* str, char c) {
|
|||||||
return (*s == c) ? (char*)s : NULL;
|
return (*s == c) ? (char*)s : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// char* strrchr(const char* str, char c);
|
char* strrchr(const char* str, char c) { return NULL; } // TODO
|
||||||
|
|
||||||
int strcmp(const char* str1, const char* str2) {
|
int strcmp(const char* str1, const char* str2) {
|
||||||
while (*str1 != '\0' && *str1 == *str2) {
|
while (*str1 != '\0' && *str1 == *str2) {
|
||||||
@@ -140,4 +134,3 @@ void* memset(void* dst, uint8_t value, uint32_t length) {
|
|||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,32 +1,8 @@
|
|||||||
#ifndef SYSCALL_H
|
#include <syscall.h>
|
||||||
#define SYSCALL_H
|
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#define MAX_SYSCALLS 9
|
#define MAX_SYSCALLS 9
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
SYS_RESERVED,
|
|
||||||
SYS_SLEEP,
|
|
||||||
SYS_READ,
|
|
||||||
SYS_WRITE,
|
|
||||||
SYS_OPEN,
|
|
||||||
SYS_CLOSE,
|
|
||||||
SYS_MALLOC,
|
|
||||||
SYS_FREE,
|
|
||||||
SYS_SEEK,
|
|
||||||
} SYSCALL_NUMBERS;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
O_CREAT = 0x01, // Create if does not exist
|
|
||||||
O_RDONLY = 0x02, // Read only
|
|
||||||
O_WRONLY = 0x04, // Write only
|
|
||||||
O_RDWR = 0x08, // Read and write
|
|
||||||
O_APPEND = 0x10, // Always writes at the end (appends)
|
|
||||||
O_TRUNC = 0x20, // Truncate file size and position to 0 on Open
|
|
||||||
O_BIN = 0x40, // Read bytes, not text
|
|
||||||
} OFLAGS;
|
|
||||||
|
|
||||||
int syscall(int nr, int arg0, int arg1, int arg2) {
|
int syscall(int nr, int arg0, int arg1, int arg2) {
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
__asm__ volatile ("int $0x80" : "=a"(ret) : "a"(nr), "b"(arg0), "c"(arg1), "d"(arg2));
|
__asm__ volatile ("int $0x80" : "=a"(ret) : "a"(nr), "b"(arg0), "c"(arg1), "d"(arg2));
|
||||||
@@ -54,4 +30,3 @@ int close(int fd) {
|
|||||||
return syscall(SYS_CLOSE, fd, 0, 0);
|
return syscall(SYS_CLOSE, fd, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,11 +1,7 @@
|
|||||||
#ifndef TIME_H
|
#include <time.h>
|
||||||
#define TIME_H
|
|
||||||
|
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
void sleep(uint32_t ms) {
|
void sleep(uint32_t ms) {
|
||||||
syscall(SYS_SLEEP, ms, 0, 0);
|
syscall(SYS_SLEEP, ms, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -93,6 +93,7 @@ void main() {
|
|||||||
// Run Interactive Shell Program
|
// Run Interactive Shell Program
|
||||||
// TODO: Make it in another file
|
// TODO: Make it in another file
|
||||||
while (1) {
|
while (1) {
|
||||||
|
printf("\e[6M\x7f\x80\n");
|
||||||
printf("\e[6M\e[8N%s \e[2M%s \e[8M", cwd, PROMPT);
|
printf("\e[6M\e[8N%s \e[2M%s \e[8M", cwd, PROMPT);
|
||||||
char input[256];
|
char input[256];
|
||||||
char* inputPtr = input;
|
char* inputPtr = input;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <fs/fs.h>
|
#include <fs/fs.h>
|
||||||
#include <screen/gfxmode.h>
|
#include <screen/gfxmode.h>
|
||||||
#include <error/bigerr.h>
|
#include <error/bigerr.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
void bigError();
|
void bigError();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user