mirror of
https://github.com/BoredDevNL/BoredOS.git
synced 2026-05-15 10:48:38 +00:00
Merge branch 'BoredDevNL:main' into terminal-fix
This commit is contained in:
commit
8ab28661a1
345 changed files with 38058 additions and 1571 deletions
14
Makefile
14
Makefile
|
|
@ -25,10 +25,10 @@ C_SOURCES = $(wildcard $(SRC_DIR)/core/*.c) \
|
||||||
$(wildcard $(SRC_DIR)/net/nic/*.c) \
|
$(wildcard $(SRC_DIR)/net/nic/*.c) \
|
||||||
$(wildcard $(SRC_DIR)/fs/*.c) \
|
$(wildcard $(SRC_DIR)/fs/*.c) \
|
||||||
$(wildcard $(SRC_DIR)/wm/*.c) \
|
$(wildcard $(SRC_DIR)/wm/*.c) \
|
||||||
$(wildcard $(SRC_DIR)/net/lwip/core/*.c) \
|
$(wildcard $(SRC_DIR)/net/third_party/lwip/core/*.c) \
|
||||||
$(wildcard $(SRC_DIR)/net/lwip/core/ipv4/*.c) \
|
$(wildcard $(SRC_DIR)/net/third_party/lwip/core/ipv4/*.c) \
|
||||||
$(SRC_DIR)/net/lwip/netif/ethernet.c \
|
$(SRC_DIR)/net/third_party/lwip/netif/ethernet.c \
|
||||||
$(SRC_DIR)/net/lwip/netif/bridgeif.c
|
$(SRC_DIR)/net/third_party/lwip/netif/bridgeif.c
|
||||||
|
|
||||||
ASM_SOURCES = $(wildcard $(SRC_DIR)/arch/*.asm)
|
ASM_SOURCES = $(wildcard $(SRC_DIR)/arch/*.asm)
|
||||||
OBJ_FILES = $(patsubst $(SRC_DIR)/core/%.c, $(BUILD_DIR)/%.o, $(wildcard $(SRC_DIR)/core/*.c)) \
|
OBJ_FILES = $(patsubst $(SRC_DIR)/core/%.c, $(BUILD_DIR)/%.o, $(wildcard $(SRC_DIR)/core/*.c)) \
|
||||||
|
|
@ -39,13 +39,13 @@ OBJ_FILES = $(patsubst $(SRC_DIR)/core/%.c, $(BUILD_DIR)/%.o, $(wildcard $(SRC_D
|
||||||
$(patsubst $(SRC_DIR)/net/nic/%.c, $(BUILD_DIR)/%.o, $(wildcard $(SRC_DIR)/net/nic/*.c)) \
|
$(patsubst $(SRC_DIR)/net/nic/%.c, $(BUILD_DIR)/%.o, $(wildcard $(SRC_DIR)/net/nic/*.c)) \
|
||||||
$(patsubst $(SRC_DIR)/fs/%.c, $(BUILD_DIR)/%.o, $(wildcard $(SRC_DIR)/fs/*.c)) \
|
$(patsubst $(SRC_DIR)/fs/%.c, $(BUILD_DIR)/%.o, $(wildcard $(SRC_DIR)/fs/*.c)) \
|
||||||
$(patsubst $(SRC_DIR)/wm/%.c, $(BUILD_DIR)/%.o, $(wildcard $(SRC_DIR)/wm/*.c)) \
|
$(patsubst $(SRC_DIR)/wm/%.c, $(BUILD_DIR)/%.o, $(wildcard $(SRC_DIR)/wm/*.c)) \
|
||||||
$(patsubst $(SRC_DIR)/net/lwip/%.c, $(BUILD_DIR)/lwip/%.o, $(filter $(SRC_DIR)/net/lwip/%.c, $(C_SOURCES))) \
|
$(patsubst $(SRC_DIR)/net/third_party/lwip/%.c, $(BUILD_DIR)/lwip/%.o, $(filter $(SRC_DIR)/net/third_party/lwip/%.c, $(C_SOURCES))) \
|
||||||
$(patsubst $(SRC_DIR)/arch/%.asm, $(BUILD_DIR)/%.o, $(ASM_SOURCES))
|
$(patsubst $(SRC_DIR)/arch/%.asm, $(BUILD_DIR)/%.o, $(ASM_SOURCES))
|
||||||
|
|
||||||
CFLAGS = -g -O2 -pipe -Wall -Wextra -std=gnu11 -ffreestanding \
|
CFLAGS = -g -O2 -pipe -Wall -Wextra -std=gnu11 -ffreestanding \
|
||||||
-fno-stack-protector -fno-stack-check -fno-lto -fPIE \
|
-fno-stack-protector -fno-stack-check -fno-lto -fPIE \
|
||||||
-m64 -march=x86-64 -msse -msse2 -mstackrealign -mno-red-zone \
|
-m64 -march=x86-64 -msse -msse2 -mstackrealign -mno-red-zone \
|
||||||
-I$(SRC_DIR) -I$(SRC_DIR)/net/lwip -I$(SRC_DIR)/core -I$(SRC_DIR)/sys -I$(SRC_DIR)/mem -I$(SRC_DIR)/dev -I$(SRC_DIR)/net -I$(SRC_DIR)/net/nic -I$(SRC_DIR)/fs -I$(SRC_DIR)/wm
|
-I$(SRC_DIR) -I$(SRC_DIR)/net/third_party/lwip -I$(SRC_DIR)/core -I$(SRC_DIR)/sys -I$(SRC_DIR)/mem -I$(SRC_DIR)/dev -I$(SRC_DIR)/net -I$(SRC_DIR)/net/nic -I$(SRC_DIR)/fs -I$(SRC_DIR)/wm
|
||||||
|
|
||||||
LDFLAGS = -m elf_x86_64 -nostdlib -static -pie --no-dynamic-linker \
|
LDFLAGS = -m elf_x86_64 -nostdlib -static -pie --no-dynamic-linker \
|
||||||
-z text -z max-page-size=0x1000 -T linker.ld
|
-z text -z max-page-size=0x1000 -T linker.ld
|
||||||
|
|
@ -112,7 +112,7 @@ $(BUILD_DIR)/%.o: $(SRC_DIR)/wm/%.c | $(BUILD_DIR) limine-setup
|
||||||
mkdir -p $(dir $@)
|
mkdir -p $(dir $@)
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
$(BUILD_DIR)/lwip/%.o: $(SRC_DIR)/net/lwip/%.c | $(BUILD_DIR) limine-setup
|
$(BUILD_DIR)/lwip/%.o: $(SRC_DIR)/net/third_party/lwip/%.c | $(BUILD_DIR) limine-setup
|
||||||
mkdir -p $(dir $@)
|
mkdir -p $(dir $@)
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
|
|
||||||
33
docs/build/toolchain.md
vendored
33
docs/build/toolchain.md
vendored
|
|
@ -18,35 +18,4 @@ To build BoredOS, you need the following tools:
|
||||||
- *Why?* `xorriso` packages the compiled kernel, Limine bootloader, and asset files (fonts, images, userland binaries) into the final bootable `boredos.iso` CD-ROM image.
|
- *Why?* `xorriso` packages the compiled kernel, Limine bootloader, and asset files (fonts, images, userland binaries) into the final bootable `boredos.iso` CD-ROM image.
|
||||||
|
|
||||||
4. **QEMU** (Optional but highly recommended for testing):
|
4. **QEMU** (Optional but highly recommended for testing):
|
||||||
- `qemu-system-x86_64` is used for rapid emulation and testing.
|
- `qemu-system-x86_64` is used to virtualize the OS for testing or to mess around.
|
||||||
|
|
||||||
## Installation (macOS)
|
|
||||||
|
|
||||||
You can easily install the complete toolchain using Homebrew:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
brew install x86_64-elf-binutils x86_64-elf-gcc nasm xorriso qemu
|
|
||||||
```
|
|
||||||
|
|
||||||
## Installation (Linux)
|
|
||||||
|
|
||||||
Depending on your distribution, the installation commands vary. Note that some distributions may require you to build the `x86_64-elf` cross-compiler from source if it isn't available in their default repositories.
|
|
||||||
|
|
||||||
### Debian / Ubuntu
|
|
||||||
```sh
|
|
||||||
sudo apt update
|
|
||||||
sudo apt install build-essential bison flex libgmp3-dev libmpc-dev libmpfr-dev texinfo nasm xorriso qemu-system-x86
|
|
||||||
```
|
|
||||||
*(Note: You will need to build the `x86_64-elf` cross-compiler from source or find a compatible PPA, as it is not in the default Debian/Ubuntu repositories.)*
|
|
||||||
|
|
||||||
### Arch Linux
|
|
||||||
Arch Linux provides the regular tools in its standard repositories and the cross-compiler via the AUR:
|
|
||||||
```sh
|
|
||||||
sudo pacman -S nasm xorriso qemu-full
|
|
||||||
yay -S x86_64-elf-gcc x86_64-elf-binutils
|
|
||||||
```
|
|
||||||
|
|
||||||
### Fedora
|
|
||||||
```sh
|
|
||||||
sudo dnf install make gcc gcc-c++ bison flex gmp-devel mpfr-devel libmpc-devel texinfo nasm xorriso qemu
|
|
||||||
```
|
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,13 @@ extern syscall_handler_c
|
||||||
section .text
|
section .text
|
||||||
|
|
||||||
; Syscall ABI:
|
; Syscall ABI:
|
||||||
; RDI = syscall_num
|
; RAX = syscall_num
|
||||||
; RSI = arg1
|
; RDI = arg1
|
||||||
; RDX = arg2
|
; RSI = arg2
|
||||||
; R10 = arg3
|
; RDX = arg3
|
||||||
; R8 = arg4
|
; R10 = arg4
|
||||||
; R9 = arg5
|
; R8 = arg5
|
||||||
|
; R9 = arg6
|
||||||
|
|
||||||
syscall_entry:
|
syscall_entry:
|
||||||
swapgs
|
swapgs
|
||||||
|
|
|
||||||
|
|
@ -85,11 +85,16 @@ void kconsole_write(const char *s) {
|
||||||
if (!s) return;
|
if (!s) return;
|
||||||
|
|
||||||
uint64_t flags = spinlock_acquire_irqsave(&console_lock);
|
uint64_t flags = spinlock_acquire_irqsave(&console_lock);
|
||||||
|
if (!kconsole_active) {
|
||||||
|
spinlock_release_irqrestore(&console_lock, flags);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
while (*s) {
|
while (*s) {
|
||||||
kconsole_putc_nolock(*s++);
|
kconsole_putc_nolock(*s++);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flip buffer after a write batch during boot
|
// Flip once after a write batch to keep console updates coherent.
|
||||||
graphics_flip_buffer();
|
graphics_flip_buffer();
|
||||||
spinlock_release_irqrestore(&console_lock, flags);
|
spinlock_release_irqrestore(&console_lock, flags);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -371,155 +371,3 @@ MemStats memory_get_stats(void) {
|
||||||
|
|
||||||
return stats;
|
return stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
void memory_print_stats(void) {
|
|
||||||
MemStats stats = memory_get_stats();
|
|
||||||
|
|
||||||
// Use CLI write functions - declare as extern
|
|
||||||
extern void cmd_write(const char *str);
|
|
||||||
extern void cmd_write_int(int n);
|
|
||||||
extern void cmd_putchar(char c);
|
|
||||||
|
|
||||||
cmd_write("\n=== MEMORY STATISTICS ===\n");
|
|
||||||
cmd_write("Total Memory: ");
|
|
||||||
cmd_write_int(stats.total_memory / 1024);
|
|
||||||
cmd_write(" KB\n");
|
|
||||||
|
|
||||||
cmd_write("Used Memory: ");
|
|
||||||
cmd_write_int(stats.used_memory / 1024);
|
|
||||||
cmd_write(" KB\n");
|
|
||||||
|
|
||||||
cmd_write("Available Memory: ");
|
|
||||||
cmd_write_int(stats.available_memory / 1024);
|
|
||||||
cmd_write(" KB\n");
|
|
||||||
|
|
||||||
cmd_write("Allocated Blocks: ");
|
|
||||||
cmd_write_int(stats.allocated_blocks);
|
|
||||||
cmd_write("\n");
|
|
||||||
|
|
||||||
cmd_write("Free Blocks: ");
|
|
||||||
cmd_write_int(stats.free_blocks);
|
|
||||||
cmd_write("\n");
|
|
||||||
|
|
||||||
cmd_write("Largest Free: ");
|
|
||||||
cmd_write_int(stats.largest_free_block / 1024);
|
|
||||||
cmd_write(" KB\n");
|
|
||||||
|
|
||||||
cmd_write("Peak Usage: ");
|
|
||||||
cmd_write_int(stats.peak_memory_used / 1024);
|
|
||||||
cmd_write(" KB\n");
|
|
||||||
|
|
||||||
cmd_write("Fragmentation: ");
|
|
||||||
cmd_write_int(stats.fragmentation_percent);
|
|
||||||
cmd_write("%\n");
|
|
||||||
|
|
||||||
cmd_write("Usage: ");
|
|
||||||
int usage_percent = (stats.used_memory * 100) / stats.total_memory;
|
|
||||||
cmd_write_int(usage_percent);
|
|
||||||
cmd_write("%\n");
|
|
||||||
|
|
||||||
cmd_write("========================\n\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void memory_print_detailed(void) {
|
|
||||||
extern void cmd_write(const char *str);
|
|
||||||
extern void cmd_write_int(int n);
|
|
||||||
extern void cmd_putchar(char c);
|
|
||||||
|
|
||||||
cmd_write("\n=== DETAILED MEMORY BLOCKS ===\n");
|
|
||||||
cmd_write("ID Address Size Status\n");
|
|
||||||
cmd_write("------ -------- -------- --------\n");
|
|
||||||
|
|
||||||
for (int i = 0; i < block_count; i++) {
|
|
||||||
if (block_list[i].size == 0) continue;
|
|
||||||
|
|
||||||
// ID
|
|
||||||
cmd_write_int(block_list[i].allocation_id);
|
|
||||||
cmd_write(" ");
|
|
||||||
|
|
||||||
// Address (simplified hex output)
|
|
||||||
cmd_write("0x");
|
|
||||||
cmd_write_int((uintptr_t)block_list[i].address / 1024);
|
|
||||||
cmd_write(" ");
|
|
||||||
|
|
||||||
// Size
|
|
||||||
cmd_write_int(block_list[i].size / 1024);
|
|
||||||
cmd_write("KB ");
|
|
||||||
|
|
||||||
// Status
|
|
||||||
if (block_list[i].allocated) {
|
|
||||||
cmd_write("ALLOC\n");
|
|
||||||
} else {
|
|
||||||
cmd_write("FREE\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd_write("==============================\n\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void memory_validate(void) {
|
|
||||||
extern void cmd_write(const char *str);
|
|
||||||
extern void cmd_write_int(int n);
|
|
||||||
|
|
||||||
int errors = 0;
|
|
||||||
|
|
||||||
// Check for overlapping blocks
|
|
||||||
for (int i = 0; i < block_count; i++) {
|
|
||||||
for (int j = i + 1; j < block_count; j++) {
|
|
||||||
void *i_start = block_list[i].address;
|
|
||||||
void *i_end = (uint8_t *)i_start + block_list[i].size;
|
|
||||||
void *j_start = block_list[j].address;
|
|
||||||
void *j_end = (uint8_t *)j_start + block_list[j].size;
|
|
||||||
|
|
||||||
if (i_start < j_end && i_end > j_start) {
|
|
||||||
errors++;
|
|
||||||
cmd_write("ERROR: Overlapping blocks detected!\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (errors == 0) {
|
|
||||||
cmd_write("Memory validation: [OK]\n");
|
|
||||||
} else {
|
|
||||||
cmd_write("Memory validation failed with ");
|
|
||||||
cmd_write_int(errors);
|
|
||||||
cmd_write(" errors\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void memory_dump_blocks(void) {
|
|
||||||
extern void cmd_write(const char *str);
|
|
||||||
extern void cmd_write_int(int n);
|
|
||||||
|
|
||||||
cmd_write("\nMemory block dump:\n");
|
|
||||||
cmd_write("Total blocks: ");
|
|
||||||
cmd_write_int(block_count);
|
|
||||||
cmd_write("\n");
|
|
||||||
|
|
||||||
memory_print_detailed();
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t memory_get_peak_usage(void) {
|
|
||||||
return peak_allocated;
|
|
||||||
}
|
|
||||||
|
|
||||||
void memory_reset_peak(void) {
|
|
||||||
peak_allocated = total_allocated;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool memory_is_valid_ptr(void *ptr) {
|
|
||||||
if (ptr == NULL) return false;
|
|
||||||
|
|
||||||
if (!initialized) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if it's an allocated block
|
|
||||||
for (int i = 0; i < block_count; i++) {
|
|
||||||
if (block_list[i].allocated && block_list[i].address == ptr) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -47,16 +47,6 @@ void* krealloc(void *ptr, size_t new_size);
|
||||||
|
|
||||||
// Statistics and Information
|
// Statistics and Information
|
||||||
MemStats memory_get_stats(void);
|
MemStats memory_get_stats(void);
|
||||||
void memory_print_stats(void);
|
|
||||||
void memory_print_detailed(void);
|
|
||||||
|
|
||||||
void memory_validate(void);
|
|
||||||
void memory_dump_blocks(void);
|
|
||||||
|
|
||||||
// Internal utilities
|
|
||||||
size_t memory_get_peak_usage(void);
|
|
||||||
void memory_reset_peak(void);
|
|
||||||
bool memory_is_valid_ptr(void *ptr);
|
|
||||||
|
|
||||||
void mem_memset(void *dest, int val, size_t len);
|
void mem_memset(void *dest, int val, size_t len);
|
||||||
void mem_memcpy(void *dest, const void *src, size_t len);
|
void mem_memcpy(void *dest, const void *src, size_t len);
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue