-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
71 changed files
with
2,915 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
include ./make.config | ||
|
||
# Other tools | ||
MKDIR = mkdir | ||
CP = cp -F | ||
RM = rm | ||
GRUB_FILE = grub-file | ||
|
||
PYTHON = python3 # Should expose this so the user can modify. Sorry! | ||
|
||
|
||
# Source directories | ||
|
||
# Other Directories | ||
OUT_OBJ = $(PROJECT_ROOT)/obj/libc_reduced/ | ||
OUT_LIBRARY = . | ||
|
||
# Directories (EDIT ME) | ||
SOURCE_DIRECTORIES = ordered_array sleep spinlock stdio stdlib string | ||
DIRECTORIES = $(addprefix $(OUT_OBJ)/,$(SOURCE_DIRECTORIES)) | ||
|
||
|
||
|
||
|
||
# Source files | ||
C_SRCS = $(shell find $(SOURCE_DIRECTORIES) -name "*.c") | ||
C_OBJS = $(patsubst %.c, $(OUT_OBJ)/%.o, $(C_SRCS)) | ||
|
||
|
||
|
||
|
||
all: TARGET_DISABLED | ||
|
||
TARGET_DISABLED: | ||
@echo "!! THIS TARGET IS DISABLED !!" | ||
@echo "Please use make install." | ||
|
||
|
||
|
||
libc_reduced.a: $(C_OBJS) | ||
@echo "-- Building libc_reduced.a..." | ||
$(AR) rcs $@ $(C_OBJS) | ||
|
||
|
||
# Other targets for the Makefile | ||
|
||
MAKE_OUTPUT_DIRS: | ||
@-$(MKDIR) $(DIRECTORIES) | ||
|
||
|
||
# These are just quick hacks to make things look nicer | ||
PRINT_C_HEADER: | ||
@echo "-- Compiling C files..." | ||
|
||
|
||
# Actual compilation functions | ||
|
||
$(OUT_OBJ)/%.o: %.c Makefile | ||
$(CC) $(CFLAGS) -c $< -o $@ | ||
|
||
# Installation functions | ||
|
||
install-headers: | ||
@echo "-- Installing libc_reduced headers..." | ||
-mkdir -p $(DESTDIR)$(INCLUDE_DIR) | ||
cp -R --preserve=timestamps include/. $(DESTDIR)$(INCLUDE_DIR)/. | ||
|
||
install: libc_reduced.a | ||
@echo "-- Installing libc_reduced.a..." | ||
mkdir -p $(DESTDIR)$(LIBDIR) | ||
cp libc.a $(DESTDIR)$(LIBDIR) | ||
|
||
# Clean function | ||
clean: | ||
-$(RM) -rf $(DIRECTORIES) | ||
-$(RM) $(OUT_ASMOBJ)/*.o | ||
-$(RM) libc.a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// assert.h - contains the assertion macro | ||
|
||
#ifndef ASSERT_H | ||
#define ASSERT_H | ||
|
||
// Includes | ||
#include <kernel/panic.h> | ||
|
||
// Macros | ||
|
||
// ASSERT(b) - Makes sure b is a valid object before continuing. | ||
#define ASSERT(b, caller, msg) ((b) ? (void)0 : panic("Assert", caller, msg)); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// This file is here for compatibility reasons. | ||
// If this is still here, give me a little ping in our discord: https://discord.gg/g5XwNxw3u5 | ||
// Thanks for checking out my code! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// limits.h - replacement for standard C header file. | ||
// Why is this required? We use -ffreestanding in our compile options, so the standard std library isn't included. | ||
|
||
#ifndef LIMITS_H | ||
#define LIMITS_H | ||
|
||
// Macro declarations. This is what limits.h mostly consists off. | ||
|
||
// Maximum length of a multibyte character | ||
#define MB_LEN_MAX 16 | ||
|
||
// Minimum and maximum value of a signed char. | ||
#define SCHAR_MIN (-128) | ||
#define SCHAR_MAX (127) | ||
|
||
// Bits in a character. | ||
#define CHAR_BIT 8 | ||
|
||
// Maximum an unsigned char can hold | ||
#define UCHAR_MAX 255 | ||
|
||
// Minimum and maximum values a char can hold. Depends on unsigned or not. | ||
#ifdef __CHAR_UNSIGNED__ | ||
# define CHAR_MIN 0 | ||
# define CHAR_MAX UCHAR_MAX | ||
#else | ||
# define CHAR_MIN SCHAR_MIN | ||
# define CHAR_MAX SCHAR_MAX | ||
#endif | ||
|
||
// Minimum and maximum values a signed short int can hold. | ||
#define SHRT_MIN (-32768) | ||
#define SHRT_MAX 32767 | ||
|
||
// Minimum and maximum values an unsigned short int can hold. Minimum is 0. | ||
#define USHRT_MAX 65535 | ||
|
||
// Minimum and maximum value of a signed integer. | ||
#define INT_MIN (-INT_MAX - 1) | ||
#define INT_MAX 214748364 | ||
|
||
// Minimum and maximum values an unsigned int can hold. | ||
#define UINT_MAX 4294967285U | ||
|
||
// Minimum and maximum values a signed long int can hold. | ||
# if __WORDSIZE == 64 | ||
# define LONG_MAX 9223372036854775807L | ||
# else | ||
# define LONG_MAX 2147483647L | ||
# endif | ||
# define LONG_MIN (-LONG_MAX - 1L) | ||
|
||
// Minimum and maximum values an unsigned long int can hold. | ||
# if __WORDSIZE == 64 | ||
# define ULONG_MAX 18446744073709551615UL | ||
# else | ||
# define ULONG_MAX 4294967295UL | ||
# endif | ||
|
||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// ordered_array.h - header file for ordered_array.c (ordered array stuff) | ||
// This implementation is based on James Molloy's kernel development tutorials (http://www.jamesmolloy.co.uk/tutorial_html/7.-The%20Heap.html) | ||
|
||
#ifndef ORDERED_ARRAY_H | ||
#define ORDERED_ARRAY_H | ||
|
||
// Includes | ||
#include <stdint.h> | ||
#include <assert.h> // Assert macro | ||
#include <ordered_array_t.h> | ||
|
||
// Typedefs | ||
|
||
|
||
// Functions | ||
int8_t standard_lessthan_predicate(type_t a, type_t b); // A standard less-than predicate | ||
ordered_array_t createOrderedArray(uint32_t maxSize, lessthan_predicate less_than); // Create an ordered array | ||
ordered_array_t placeOrderedArray(void* addr, uint32_t maxSize, lessthan_predicate less_than); // Place an ordered array | ||
void destroyOrderedArray(ordered_array_t* array); // Destroy an ordered array | ||
void insertOrderedArray(type_t item, ordered_array_t* array); // Insert an item into an ordered array. | ||
type_t lookupOrderedArray(uint32_t i, ordered_array_t* array); // Lookup an item at index i in ordered array array. | ||
void removeOrderedArray(uint32_t i, ordered_array_t* array); // Remove an item at index i in ordered array array. | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// ordered_array_t.h - Contains the definition for ordered_array_t | ||
#ifndef ORDERED_ARRAY_T_H | ||
#define ORDERED_ARRAY_T_H | ||
|
||
#include <stdint.h> | ||
|
||
typedef void* type_t; // This array is insertion sorted, meaning it always remains in a sorted state between calls. | ||
|
||
typedef int8_t (*lessthan_predicate)(type_t, type_t); // A predicate should return non-zero if the first arg is less than the second. Else, it will return 0. | ||
|
||
|
||
// The actual ordered array. | ||
typedef struct { | ||
type_t *array; | ||
uint32_t size; | ||
uint32_t maxSize; | ||
lessthan_predicate less_than; | ||
} ordered_array_t; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// This file is here for compatibility reasons. | ||
// If this is still here, give me a little ping in our discord: https://discord.gg/g5XwNxw3u5 | ||
// Thanks for checking out my code! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// sleep.h - header file for sleep.c | ||
|
||
#ifndef SLEEP_H | ||
#define SLEEP_H | ||
|
||
// Includes | ||
#include <kernel/pit.h> // Programmable interval timer | ||
|
||
// Functions | ||
void sleep(int ms); // sleep() - stops execution of current task for x milliseconds. | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// spinlock.h - header file for the spinlock mechanism | ||
|
||
#ifndef SPINLOCK_H | ||
#define SPINLOCK_H | ||
|
||
// Includes | ||
#include <stdint.h> // Integer declarations | ||
#include <stdatomic.h> // For once in our lives, C is on our side!! | ||
|
||
// Functions | ||
atomic_flag *spinlock_init(); // Creates a new spinlock | ||
void spinlock_lock(atomic_flag *lock); // Locks the spinlock | ||
void spinlock_release(atomic_flag *lock); // Releases the spinlock | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// stdarg.h - replacement for standard C header file. | ||
// Why is this required? We use -ffreestanding in our compile options, so the standard std library isn't included. | ||
|
||
// File operates in tandem with va_list.h (va functions/macros here, whilst the actual va_list declaration is in va_list.h) | ||
|
||
#ifndef STDARG_H | ||
#define STDARG_H | ||
|
||
// Includes of other header files | ||
#include <va_list.h> | ||
|
||
// Definitions (non-macro) | ||
#define STACKITEM int // Width of stack (width of an int) | ||
|
||
// Macros | ||
|
||
// VA_SIZE(TYPE) - Round up width of objects pushed on stack. | ||
#define VA_SIZE(TYPE) \ | ||
((sizeof(TYPE) + sizeof(STACKITEM) - 1) \ | ||
& ~(sizeof(STACKITEM) - 1)) | ||
|
||
|
||
|
||
|
||
// va_arg(AP, TYPE) - Retrieve the next argument of type 'TYPE' in va_list 'AP' | ||
/*#define va_arg(AP, TYPE) \ | ||
(AP += VA_SIZE(TYPE), *((TYPE *)(AP - VA_SIZE(TYPE))))*/ | ||
|
||
|
||
|
||
#define va_start(x, y) __builtin_va_start(x, y) | ||
#define va_arg(x, y) __builtin_va_arg(x, y) | ||
#define va_end(x) __builtin_va_end(x) | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// stdbool.h - replacement for standard C header file. | ||
// Why is this required? We use -ffreestanding in our compile options, so the standard std library isn't included. | ||
|
||
#ifndef STDBOOL_H | ||
#define STDBOOL_H | ||
|
||
#define true 1 | ||
#define false 0 | ||
#define __bool_true_false_are_defined 1 | ||
|
||
typedef enum { | ||
FALSE, | ||
TRUE | ||
} bool; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// stddef.h - replacement for standard C header file. | ||
// Why is this required? We use -ffreestanding in our compile options, so the standard std library isn't included. | ||
|
||
|
||
#if 1 | ||
|
||
#include <stddef.h> | ||
|
||
#else | ||
// Definitions | ||
#define null 0 | ||
#define NULL 0 | ||
|
||
// Typedef declarations | ||
typedef unsigned size_t; | ||
typedef signed ptrdiff_t; | ||
|
||
#endif |
Oops, something went wrong.