fix: corrected time conversion on alarm/sleep syscall
authorMinep <lunaixsky@qq.com>
Sun, 20 Aug 2023 00:27:12 +0000 (01:27 +0100)
committerMinep <lunaixsky@qq.com>
Sun, 20 Aug 2023 00:33:51 +0000 (01:33 +0100)
fix: makefile does not respond to source file change
feat: makefile respond to header change
chore: add description on arch-specific code
chore: clean up

12 files changed:
lunaix-os/.gitignore
lunaix-os/arch/i386/README [new file with mode: 0644]
lunaix-os/flags.h
lunaix-os/hal/timer/hwtimer.c
lunaix-os/includes/hal/hwtimer.h
lunaix-os/includes/lunaix/process.h
lunaix-os/kernel.mk
lunaix-os/kernel/proc0.c
lunaix-os/kernel/process/sched.c
lunaix-os/kernel/time/clock.c
lunaix-os/makefile
lunaix-os/makeinc/toolchain.mkinc

index 32bb844fc07932810b06e0a973ecc2e6ae08c3f9..b48c6045eadab1375a9423aefe33ab5382727501 100644 (file)
@@ -10,4 +10,5 @@ draft/
 iso_inspect/
 unused/
 
-**.o
\ No newline at end of file
+**.o
+**.d
\ No newline at end of file
diff --git a/lunaix-os/arch/i386/README b/lunaix-os/arch/i386/README
new file mode 100644 (file)
index 0000000..e87a8c0
--- /dev/null
@@ -0,0 +1,32 @@
+Lunaix kernel arch specific ABI
+======
+
+This document provides a checklist if one wants to add support for novel architecture
+
+(It is far from complete, as the refactoring is going on)
+
+Implementation checklist:
+    [ ] An entry point that recieve control from second stage bootloader.
+    [ ] Interrupt vectoring must be done before invoking kernel_bootstrap.
+    [ ] Prepare the boot_handoff state struct, according to system info provided
+        by upstream bootloader
+    [ ] Invoke the kernel_bootstrap, pass the boot_handoff as it's only argument
+        This will transfer the control to Lunaix kernel.
+    [ ] A syscall handler, syscall table, and the syscall vectoring
+    [ ] A interrupt handler, must take care of context save/restore, signal handling
+    [ ] A system virtual memory map
+    [ ] Implement the following abstractions
+Referenced headers
+    * <some_arch>/includes/sys/abi.h
+    * <some_arch>/includes/sys/interrupt.h
+    * <some_arch>/includes/sys/port_io.h
+    * <some_arch>/includes/sys/pci_hba.h
+    * <some_arch>/includes/mm/mempart.h
+    * <some_arch>/includes/cpu.h
+
+Referenced functions
+    * includes/hal/hwtimer.h:hwtimer_choose
+    * includes/hal/hwrtc.h:hwrtc_choose
+    * includes/hal/intc.h:intc_init
+    * includes/lunaix/process.h:proc_init_transfer
\ No newline at end of file
index 61d12c92e729edc1e20f28751ab667919ba5d765..7f9835fb172d8f1e9cb56b8e92e36c80301fcc32 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef __LUNAIX_FLAGS_H
 #define __LUNAIX_FLAGS_H
 
-#ifdef __ARCH_IA32
+#if __ARCH__ == i386
 #define PLATFORM_TARGET "x86_32"
 #else
 #define PLATFORM_TARGET "unknown"
@@ -9,12 +9,6 @@
 
 #define LUNAIX_VER "0.0.1-dev"
 
-/*
-    Uncomment below to force LunaixOS use kernel page table when context switch
-   to kernel space NOTE: This will make the kernel global.
-*/
-// #define USE_KERNEL_PG
-
 /*
     Uncomment below to disable all assertion
 */
index 9c864c7bdd3f29eb03d6926d3ed387ec93921125..bd6477a6173077c287ff93632ce222a2358ed01a 100644 (file)
@@ -1,7 +1,7 @@
 #include <hal/hwtimer.h>
 #include <lunaix/spike.h>
 
-struct hwtimer_context* sys_hwtctx;
+struct hwtimer_context* current_timer;
 
 void
 hwtimer_init(u32_t hertz, void* tick_callback)
@@ -11,19 +11,19 @@ hwtimer_init(u32_t hertz, void* tick_callback)
     hwt_ctx->init(hwt_ctx, hertz, tick_callback);
     hwt_ctx->running_freq = hertz;
 
-    sys_hwtctx = hwt_ctx;
+    current_timer = hwt_ctx;
 }
 
 ticks_t
 hwtimer_base_frequency()
 {
-    return sys_hwtctx->base_freq;
+    return current_timer->base_freq;
 }
 
 ticks_t
 hwtimer_current_systicks()
 {
-    return sys_hwtctx->systicks();
+    return current_timer->systicks();
 }
 
 ticks_t
@@ -31,10 +31,10 @@ hwtimer_to_ticks(u32_t value, int unit)
 {
     // in case system frequency is less than 1000Hz
     if (unit != TIME_MS) {
-        return sys_hwtctx->running_freq * unit * value;
+        return current_timer->running_freq * unit * value;
     }
 
-    ticks_t freq_ms = sys_hwtctx->running_freq / 1000;
+    ticks_t freq_ms = current_timer->running_freq / 1000;
 
     return freq_ms * value;
 }
\ No newline at end of file
index efa72d8f2d995ce16f2c286648332281f43929dd..bf0595d7df0a177fdab5562e862cfea20f762860 100644 (file)
@@ -18,6 +18,8 @@ struct hwtimer_context
     ticks_t running_freq;
 };
 
+extern struct hwtimer_context* current_timer;
+
 void
 hwtimer_init(u32_t hertz, void* tick_callback);
 
index 6ef1ff0eed297e13f557963a638ff9c9a44e0449..10dc5ec6513a90def740f1b2a82db41b1ca3f7ee 100644 (file)
@@ -198,6 +198,14 @@ proc_clear_signal(struct proc_info* proc);
 // enable interrupt upon transfer
 #define TRANSFER_IE 1
 
+/**
+ * @brief Setup process initial context, used to initiate first switch
+ *
+ * @param proc
+ * @param stop
+ * @param target
+ * @param flags
+ */
 void
 proc_init_transfer(struct proc_info* proc, ptr_t stop, ptr_t target, int flags);
 
index c8447033ed6ac35a4db9a2ddd8d02184895dec69..ba15fa37834e9d35ba2b2460c66b929c8f653233 100644 (file)
@@ -20,6 +20,7 @@ kbin := $(BUILD_NAME)
 
 ksrc_files := $(foreach f, $(ksrc_dirs), $(shell find $(f) -name "*.[cS]"))
 ksrc_objs := $(addsuffix .o,$(ksrc_files))
+ksrc_deps := $(addsuffix .d,$(ksrc_files))
 
 kinc_opts := $(addprefix -I,$(kinc_dirs))
 
@@ -34,7 +35,7 @@ CFLAGS += -include flags.h
        $(call status_,CC,$<)
        @$(CC) $(CFLAGS) $(kinc_opts) -c $< -o $@
 
-$(kbin): $(ksrc_objs) $(kbin_dir)
+$(kbin): $(kbin_dir) $(ksrc_files) $(ksrc_objs)
        $(call status_,LD,$@)
        @$(CC) -T link/linker.ld -o $(kbin) $(ksrc_objs) $(LDFLAGS)
 
@@ -45,4 +46,5 @@ $(kbin_dir)/modksyms: $(kbin)
 all: $(kbin) $(kbin_dir)/modksyms
 
 clean:
-       @rm -f $(ksrc_objs)
\ No newline at end of file
+       @rm -f $(ksrc_objs)
+       @rm -f $(ksrc_deps)
\ No newline at end of file
index 64dbcd9a4520d9c713db77f671111057a748ff44..c30feec0c7081a5bf2910ca30a1603529d2efa06 100644 (file)
@@ -20,8 +20,6 @@
 
 #include <sdbg/protocol.h>
 
-#include <hal/acpi/acpi.h>
-#include <hal/ahci/ahci.h>
 #include <hal/pci.h>
 
 #include <klibc/string.h>
@@ -78,8 +76,8 @@ void
 __proc0()
 {
     /*
-     * We must defer boot code/data cleaning after we successfully escape that
-     * area
+     * We must defer boot code/data cleaning to here, after we successfully
+     * escape that area
      */
     boot_cleanup();
 
@@ -104,15 +102,17 @@ init_platform()
 
     twifs_register_plugins();
 
-    /* we must start probing pci after all drivers are registered! */
+    /*
+     * all device registering and loading must defered to here!
+     * due to limited stack size and partial scheduling context
+     */
     pci_load_devices();
 
     // debugger
     serial_init();
     sdbg_init();
 
-    // FIXME ps2 kbd is x86 PC specific, not here.
-    // peripherals & chipset features
+    // FIXME ps2 kbd is a device, must not be here
     ps2_kbd_init();
 
     // console
index 651ab0ea863022e2d689561e249b52565ed1d799..82c73c0ee6d4a3d26cce6b93516bc4f807042417 100644 (file)
@@ -196,7 +196,7 @@ __DEFINE_LXSYSCALL1(unsigned int, sleep, unsigned int, seconds)
     }
 
     struct proc_info* root_proc = sched_ctx._procs[0];
-    __current->sleep.wakeup_time = clock_systime() + seconds * 1000;
+    __current->sleep.wakeup_time = clock_systime() + seconds;
 
     if (llist_empty(&__current->sleep.sleepers)) {
         llist_append(&root_proc->sleep.sleepers, &__current->sleep.sleepers);
@@ -210,15 +210,12 @@ __DEFINE_LXSYSCALL1(unsigned int, sleep, unsigned int, seconds)
     return 0;
 }
 
-// FIXME issue with alarm, paused parent process never got wake up, check what
-// has been fucked up by refactoring.
-
 __DEFINE_LXSYSCALL1(unsigned int, alarm, unsigned int, seconds)
 {
     time_t prev_ddl = __current->sleep.alarm_time;
     time_t now = clock_systime();
 
-    __current->sleep.alarm_time = seconds ? now + seconds * 1000 : 0;
+    __current->sleep.alarm_time = seconds ? now + seconds : 0;
 
     struct proc_info* root_proc = sched_ctx._procs[0];
     if (llist_empty(&__current->sleep.sleepers)) {
index 726e333b87d14f57a0db2db08310afc551c4b207..2dc4e8153359fc91c3137db86021b1bd86b457ee 100644 (file)
@@ -69,7 +69,7 @@ time_t
 clock_systime()
 {
     ticks_t t = hwtimer_current_systicks();
-    return t / hwtimer_base_frequency();
+    return t / current_timer->running_freq;
 }
 
 void
index e8deacf55c399343fc96376639dd96ed7165d5ae..75135161de33113b4d8b938d09b57894aa2f4e0a 100644 (file)
@@ -5,7 +5,6 @@ include $(mkinc_dir)/toolchain.mkinc
 include $(mkinc_dir)/qemu.mkinc
 include $(mkinc_dir)/utils.mkinc
 
-
 ARCH ?= i386
 export ARCH
 
index b629d6fc974d07078a4c0732f217487b620c21f5..70ef37bf9c989ad716a2719e2cb722f7fa127ea8 100644 (file)
@@ -23,7 +23,7 @@ OFLAGS := -fno-gcse\
                  -fno-inline-small-functions \
                  -fno-indirect-inlining
 
-CFLAGS := -std=gnu99 -ffreestanding $(OFLAGS) $(W) $(ARCH_OPT)
+CFLAGS := -std=gnu99 -ffreestanding -MMD $(OFLAGS) $(W) $(ARCH_OPT)
 
 ifeq ($(BUILD_MODE),debug)
        O = -Og