31 Commity c50efc039e ... 64a2f98d10

Autor SHA1 Wiadomość Data
  coderain 64a2f98d10 Memory manager initialization bugfixes and improvements 5 lat temu
  coderain 487e8f3923 Memory manager improvements 6 lat temu
  coderain 07e7ee3a41 Merge branch 'master' into mm_rewrite 6 lat temu
  coderain cf0e7bf409 Create the bin directories during the build process 6 lat temu
  coderain f873ac437d [sdk] Implement mini lists, which are singly-linked 6 lat temu
  coderain dcef4bcee0 [sdk] Fix incorrect assumptions in the AVL binary search routines 6 lat temu
  coderain a16949de96 Rewrite the system clock to use timestamps instead of calendar time 6 lat temu
  coderain 738cdf14f4 Change the timer syscalls so that sysret_t can be 32-bit 6 lat temu
  coderain 1d2617f421 Reorganize the files. 6 lat temu
  coderain 126dd9162c Implement vectored I/O. 6 lat temu
  coderain fa23adff9e Implement events using semaphores. 6 lat temu
  coderain 93a356d7da Fix pin_memory. 6 lat temu
  coderain 260aea5e3f Fix a stack leak. Prevent the kernel stack from overflowing. 6 lat temu
  coderain c25156ad46 Make sizeof(long) the default heap alignment. 6 lat temu
  coderain fce977c0d1 Get rid of exception_return 6 lat temu
  coderain ae4db17b61 Fix a bug in common.mk. 6 lat temu
  coderain 46c61c61ea Fix a bug in free_page. 6 lat temu
  coderain 95d13d26be Make sure the IOCTL buffers are optional. 6 lat temu
  coderain 82ffccf3e4 Switch to the context of the kernel process in vm86_interrupt. 6 lat temu
  coderain 59661c59c7 Fix a bug in wait_for_objects. 6 lat temu
  coderain 52c5ee0487 Improve process/thread termination. 6 lat temu
  coderain af25f21d70 Fix the security check for framebuffer mapping. 6 lat temu
  coderain 568844d350 Fix bugs in the VESA driver. 6 lat temu
  coderain 77d448de17 Improve logging. 6 lat temu
  coderain 4309b04a86 Fix printf bugs. 6 lat temu
  coderain 49d75449f0 Pass the machine state from the interrupt for kernel crashes. 6 lat temu
  coderain c22193bc7c Fix a minor bug in __crt_vstrprintf. 6 lat temu
  coderain c7aa8cb1d6 The assembler needs to know the instruction size. 6 lat temu
  coderain bb838ae01d Merge branch 'unit_tests' 6 lat temu
  coderain ab00d5b6f4 Update the node balance when deleting a duplicate in the AVL tree. 6 lat temu
  coderain 045be778f3 Begin implementing unit tests. 6 lat temu

+ 5 - 7
.gitignore

@@ -15,14 +15,12 @@
 !tools/packages/*.sig
 !kernel
 !kernel/*
-!crt
-!crt/*
-!library
-!library/*
+!libraries
+!libraries/**
 !tests
-!tests/*
-!manager
-!manager/*
+!tests/**
+!programs
+!programs/**
 !drivers
 !drivers/**
 !sdk

+ 12 - 16
Makefile

@@ -1,4 +1,4 @@
-.PHONY: all clean crt kernel drivers library manager tests generate
+.PHONY: all clean kernel drivers libraries programs tests generate
 
 TOOLSDIR     := tools
 TOOLSROOTDIR := root
@@ -10,20 +10,17 @@ GENERATED_SOURCES := sdk/syscall_enum.h kernel/src/syscall_table.inl library/src
 
 all: livecd.iso tests
 
-crt:
-	$(MAKE) -C crt all
-
-kernel: generate crt
+kernel: generate libraries
 	$(MAKE) -C kernel all
 
 drivers: kernel
 	$(MAKE) -C drivers all
 
-library: generate crt
-	$(MAKE) -C library all
+libraries: generate
+	$(MAKE) -C libraries all
 
-manager: library
-	$(MAKE) -C manager all
+programs: libraries
+	$(MAKE) -C programs all
 
 tests:
 	$(MAKE) -C tests all
@@ -32,25 +29,24 @@ generate: $(GENERATED_SOURCES)
 
 sdk/syscall_enum.h: $(wildcard sdk/*.h) syscalls.awk
 	@echo 'Generating system call sources/headers...'
-	sort sdk/* | awk -v enum_file=sdk/syscall_enum.h -v table_file=kernel/src/syscall_table.inl -v wrappers_file=library/src/wrappers.c -f syscalls.awk
+	sort sdk/* | awk -v enum_file=sdk/syscall_enum.h -v table_file=kernel/src/syscall_table.inl -v wrappers_file=libraries/mlsys/src/wrappers.c -f syscalls.awk
 
 kernel/src/syscall_table.inl: sdk/syscall_enum.h
 
 library/src/wrappers.c: sdk/syscall_enum.h
 
-livecd.iso : kernel drivers library manager
+livecd.iso : kernel drivers libraries programs
 	mkdir -p livecd/monolithium livecd/boot/grub livecd/monolithium/drivers
 	cp kernel/monolithium livecd/monolithium/kernel
-	find drivers -type f -name '*.drv' -exec cp {} livecd/monolithium/drivers/ \;
-	cp manager/manager livecd/monolithium/manager
+	cp drivers/bin/* livecd/monolithium/drivers/
+	cp programs/bin/* livecd/monolithium/
 	cp grub.cfg livecd/boot/grub/grub.cfg
 	grub-mkrescue -o $@ livecd
 
 clean:
-	$(MAKE) -C crt clean
 	$(MAKE) -C kernel clean
 	$(MAKE) -C drivers clean
-	$(MAKE) -C library clean
-	$(MAKE) -C manager clean
+	$(MAKE) -C libraries clean
+	$(MAKE) -C programs clean
 	$(MAKE) -C tests clean
 	rm -f $(GENERATED_SOURCES) livecd.iso

+ 14 - 4
common.mk

@@ -17,7 +17,9 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
-ARCH := i686-elf
+ifndef ARCH
+	ARCH := i686-elf
+endif
 
 # Directories
 SRCDIR       := src
@@ -30,9 +32,17 @@ PROJECT_ROOT := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
 export PATH  := $(PROJECT_ROOT)/$(TOOLSDIR)/$(TOOLSROOTDIR)/bin:$(PATH)
 
 # Compilers and tools
-CC   := $(ARCH)-gcc
+
 ASM  := nasm
-LINK := $(ARCH)-ld
+
+ifneq ($(ARCH), host)
+	CC   := $(ARCH)-gcc
+	LINK := $(ARCH)-ld
+	LDFLAGS_PROGRAM += -eprocess_startup
+else
+	CC   := gcc
+	LINK := gcc
+endif
 
 ifeq ($(DEBUG), yes)
     CFLAGS += -g -DDEBUG
@@ -80,7 +90,7 @@ $(OUTPUT_KERNEL): $(OBJECTS) $(ADDITIONAL_OBJECTS)
 	$(LINK) -o $@ $(OBJECTS) $(LDFLAGS)
 
 $(OUTPUT_PROGRAM): $(OBJECTS)
-	$(LINK) -eprocess_startup -o $@ $(OBJECTS) $(LDFLAGS)
+	$(LINK) -o $@ $(OBJECTS) $(LDFLAGS) $(LDFLAGS_PROGRAM)
 
 $(OUTPUT_STATIC_LIB): $(OBJECTS)
 	$(AR) rcs $@ $^

+ 4 - 1
drivers/Makefile

@@ -17,7 +17,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
-all:
+all: bin
 	$(MAKE) -C acpica all
 	$(MAKE) -C fatfs all
 	$(MAKE) -C floppy all
@@ -36,3 +36,6 @@ clean:
 	$(MAKE) -C serial clean
 	$(MAKE) -C speaker clean
 	$(MAKE) -C vesa clean
+
+bin:
+	mkdir bin

+ 2 - 2
drivers/acpica/Makefile

@@ -21,7 +21,7 @@
 DEBUG := yes
 
 # Flags
-CFLAGS   := -Wall -Werror -Wno-strict-aliasing -ffreestanding -nostdlib -I ../.. -I include -I ../../kernel/include -I ../../crt/include
+CFLAGS   := -Wall -Werror -Wno-strict-aliasing -ffreestanding -nostdlib -I ../.. -I include -I ../../kernel/include -I ../../libraries/mlcrt/include
 ASMFLAGS := -felf
 
 LINK_WITH_LIBGCC := yes
@@ -29,6 +29,6 @@ LINK_WITH_LIBGCC := yes
 # Input and output files
 SOURCES = $(shell find $(SRCDIR) -type f -name \*.c)
 
-OUTPUT_DRIVER := acpica.drv
+OUTPUT_DRIVER := ../bin/acpica.drv
 
 -include ../../common.mk

+ 3 - 3
drivers/acpica/src/osmlxf.c

@@ -244,7 +244,7 @@ ACPI_STATUS AcpiOsSignalSemaphore(ACPI_SEMAPHORE Handle, UINT32 Units)
 
 UINT64 AcpiOsGetTimer(void)
 {
-    return syscall_get_nanoseconds() / 100ULL;
+    return timer_get_nanoseconds() / 100ULL;
 }
 
 void AcpiOsSleep(UINT64 Milliseconds)
@@ -254,8 +254,8 @@ void AcpiOsSleep(UINT64 Milliseconds)
 
 void AcpiOsStall(UINT32 Microseconds)
 {
-    qword_t end_time = syscall_get_nanoseconds() + (qword_t)Microseconds * 1000ULL;
-    while (syscall_get_nanoseconds() < end_time) continue;
+    qword_t end_time = timer_get_nanoseconds() + (qword_t)Microseconds * 1000ULL;
+    while (timer_get_nanoseconds() < end_time) continue;
 }
 
 ACPI_THREAD_ID AcpiOsGetThreadId(void)

+ 2 - 2
drivers/fatfs/Makefile

@@ -21,12 +21,12 @@
 DEBUG := yes
 
 # Flags
-CFLAGS   := -Wall -Werror -Wno-strict-aliasing -ffreestanding -nostdlib -I ../.. -I ../../kernel/include -I ../../crt/include
+CFLAGS   := -Wall -Werror -Wno-strict-aliasing -ffreestanding -nostdlib -I ../.. -I ../../kernel/include -I ../../libraries/mlcrt/include
 ASMFLAGS := -felf
 
 # Input and output files
 SOURCES = $(wildcard $(SRCDIR)/*.c) $(wildcard $(SRCDIR)/*.asm)
 
-OUTPUT_DRIVER := fatfs.drv
+OUTPUT_DRIVER := ../bin/fatfs.drv
 
 -include ../../common.mk

+ 58 - 14
drivers/fatfs/src/main.c

@@ -2,7 +2,7 @@
  * FAT12/16/32 Filesystem Driver
  * main.c
  *
- * Copyright (C) 2016 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * Copyright (C) 2018 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -123,20 +123,64 @@ static void fatfs_set_entry_name(fatfs_dirent_t *dirent, const char *name)
     }
 }
 
-static inline void fatfs_pack_file_time(clock_time_t *os_time, word_t *date, word_t *time)
+static inline void fatfs_pack_file_time(clock_time_t os_time, word_t *date, word_t *time)
 {
-    if (date) *date = (os_time->year << 9) | (os_time->month << 5) | os_time->day;
-    if (time) *time = (os_time->hours << 11) | (os_time->minutes << 5) | (os_time->seconds >> 1);
+    if (os_time < 0) os_time = 0;
+
+    if (date)
+    {
+        clock_time_t total_days = os_time / 86400000000LL;
+
+        int i;
+        for (i = 1980;; i++)
+        {
+            int year_days = (!(i % 400) || (!(i % 4) && (i % 100))) ? 366 : 365;
+            if (total_days < year_days) break;
+            total_days -= year_days;
+        }
+
+        *date = (i - 1980) << 9;
+
+        int month_days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+        if (!(i % 400) || (!(i % 4) && (i % 100))) month_days[1]++;
+        for (i = 1; i <= 12; i++)
+        {
+            if (total_days < month_days[i - 1]) break;
+            total_days -= month_days[i - 1];
+        }
+
+        *date |= (i << 5) | total_days;
+    }
+
+    if (time)
+    {
+        clock_time_t total_seconds = (os_time / 1000000) % 86400;
+        *time = ((total_seconds / 3600) << 11) | (((total_seconds / 60) % 60) << 5) | ((total_seconds % 60) >> 1);
+    }
 }
 
 static inline void fatfs_unpack_file_time(word_t date, word_t time, clock_time_t *os_time)
 {
-    os_time->day = date & 0x1F;
-    os_time->month = (date >> 5) & 0x0F;
-    os_time->year = (date >> 9) & 0x7F;
-    os_time->seconds = (time & 0x1F) << 1;
-    os_time->minutes = (time >> 5) & 0x3F;
-    os_time->hours = (time >> 11) & 0x1F;
+    clock_time_t year = (date >> 9) & 0x7F;
+    clock_time_t month = (date >> 5) & 0x0F;
+    clock_time_t day = date & 0x1F;
+    clock_time_t hour = (time >> 11) & 0x1F;
+    clock_time_t minute = (time >> 5) & 0x3F;
+    clock_time_t second = (time & 0x1F) << 1;
+    clock_time_t total_days = 0;
+
+    int i;
+    for (i = 1980; i < 1980 + year; i++)
+    {
+        total_days += (!(i % 400) || (!(i % 4) && (i % 100))) ? 366 : 365;
+    }
+
+    int month_days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+    if (!(i % 400) || (!(i % 4) && (i % 100))) month_days[1]++;
+    for (i = 1; i < month; i++) total_days += month_days[i - 1];
+    total_days += day - 1;
+
+    *os_time = (60 * (60 * (24 * total_days + hour) + minute) + second) * 1000000;
 }
 
 static dword_t fatfs_get_next_cluster(fatfs_volume_t *volume, dword_t cluster)
@@ -486,7 +530,7 @@ static dword_t fatfs_resize_file(fatfs_file_t *file, qword_t new_size)
     dirent.size = file->header.size;
     dirent.first_cluster_low = file->first_cluster & 0xFFFF;
     dirent.first_cluster_high = file->first_cluster >> 16;
-    fatfs_pack_file_time(&current_time, &dirent.modification_date, &dirent.modification_time);
+    fatfs_pack_file_time(current_time, &dirent.modification_date, &dirent.modification_time);
 
     return device_write(volume->header.device,
                         &dirent,
@@ -782,9 +826,9 @@ static dword_t fatfs_load_file(file_t **_file)
 
         fatfs_set_entry_name(&dirent, file_name);
         dirent.duration = 1;
-        fatfs_pack_file_time(&current_time, &dirent.creation_date, &dirent.creation_time);
-        fatfs_pack_file_time(&current_time, &dirent.modification_date, &dirent.modification_time);
-        fatfs_pack_file_time(&current_time, &dirent.last_accessed_date, NULL);
+        fatfs_pack_file_time(current_time, &dirent.creation_date, &dirent.creation_time);
+        fatfs_pack_file_time(current_time, &dirent.modification_date, &dirent.modification_time);
+        fatfs_pack_file_time(current_time, &dirent.last_accessed_date, NULL);
         dirent.first_cluster_high = 0;
         dirent.first_cluster_low = 0;
         dirent.size = 0;

+ 2 - 2
drivers/floppy/Makefile

@@ -21,12 +21,12 @@
 DEBUG := yes
 
 # Flags
-CFLAGS   := -Wall -Werror -Wno-strict-aliasing -ffreestanding -nostdlib -I ../.. -I ../../kernel/include -I ../../crt/include
+CFLAGS   := -Wall -Werror -Wno-strict-aliasing -ffreestanding -nostdlib -I ../.. -I ../../kernel/include -I ../../libraries/mlcrt/include
 ASMFLAGS := -felf
 
 # Input and output files
 SOURCES = $(wildcard $(SRCDIR)/*.c) $(wildcard $(SRCDIR)/*.asm)
 
-OUTPUT_DRIVER := floppy.drv
+OUTPUT_DRIVER := ../bin/floppy.drv
 
 -include ../../common.mk

+ 0 - 0
drivers/ps2/Makefile


Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików