lunaix-os.git
15 months agoRefinement on documentation (#38)
Lunaixsky [Wed, 14 Aug 2024 13:31:43 +0000 (14:31 +0100)]
Refinement on documentation (#38)

* start a docs series on lunaix-internal

* update readme, include a list for auto-loaded symbols

* tweak the gitignore file
* add a script to dump all .lga symbols

* fix the image link to mem map

* update readme, fix gitignore

15 months agoSecond Extended Filesystem (ext2) and other improvements (#33)
Lunaixsky [Sat, 10 Aug 2024 13:52:28 +0000 (14:52 +0100)]
Second Extended Filesystem (ext2) and other improvements (#33)

* Add a wrapper layer to vfs interface with intension to serve an unified API
  for file-system driver implementation and thus makes the flow clear.
* Localise iso9660's header file
* Make qemu launch cmd out of makefile to enable better flexibility
* remove an out-dated FIXME annotation

* Add ext2 protocol definitions and v_superblock construction

* Sparse Caching: cache framework for caching spatial data unit (#34)

* Add framework for sparse caching facility
Added a spinlock as a future-proof placeholder

* * Add bcache_zone to allow more fine gran control over lru zone used
  when creating a bcache
* Add lock on entire bcache instance to avoid concurrent modification
  on internal data structure
* Add missing free function for lru zone, introduce async freeing when
  a zone is too busy to be freed onsite
* Add interface for destroying spinlock when a guarded object is about
  to be freed, thus avoid locking-after-free.

* Refactor inode pcache to use bcache for better centralisation

* lru: add proper synchronisation ensurance to lru_zone
* lru: add twimap integration to all lru_zones
* lru: add extra statistical metrics
* change naming to spinlock relatives for better clarity
* twimap: go_next now called before read, to capture corner case of empty list
* clean-up and compliation fixes

* * blk_buf: buffering mechanism for blkio requests and their payloads
* Replace locking on each bcache node with ref counter, thus avoid
  creating weired locking pattern and potentially dead lock.
* add documentation on the stages that owloysius will
  recognise
* housekeeping: remove not-needed file

* * ext2: parsing superblock and block descriptor table
* ext2: locating and reading inode
* fsapi: add new helper method for initializing inode
* fsapi: add support to block buffering, allowing read/write
         of file system block to be efficient.

* * ext2: add support to read the inode data block and indirect link
  following.
* ext2: introduce btlb to accelerate indirect link following.
* blkbuf: add `refonce` to increament the internal ref counter for
  better cache management
* housekeeping: make the inline function at hash.h static
* housekeeping: rename fsapi_{get|put}blk to fsblock_{take|put}

* * Change the directory iteration pattern in vfs
  This allow us to add support of lseek functionality to directory. i.e.
  seek to i-th directory entry, similar to seekdir(2)

* * ext2: directory iteration and seeking.
* ext2: add a generic iterator for ext2 objects
* minor refactoring on some code snippet to reduce verbosity

* * ext2: read and read_page support on data blocks

* * proper error handling and reporting on blkbuf and ext2

* * vfs: fix an issue that async freeing of inode and dnode cachings
  could potentially result undefined access to an already freed
  v_superblock object. By tracking the no. of references of vsb and
  free it when and only when nobody is reference it.
* vfs: remove the auto-handling of . and .. dir entry from the readdir
  interface. Thus makes it a file system driver's responsibility
* ext2: fix the incorrect index usage when addressing an ext2 directory
  entry.
* ext2: add strneq for bounded string comparision.
* minor refactoring and tidying.

* * make things compile
* iso9660: fix the issue when selecting name for the 00/01 dir ident

* inode::itype bit-field redefinition & bug fixes

* rework the itype bit-fields for better clarity.
* fix couple of bugs in ls that does not check errno of readdir syscall
* add a new directive '?' to debug_sh (sh) to check exit status of
  previous invocation

* ext2: properly functioned the directory listing

* fix strncpy behavior to be smarter
* corret the inode number offset
* provide v_mount struct before mounting stuff, which makes more sense
* fix issue of btrie tree retrive incorrect leaf when order is a odd number
* fix the itype conversion from ext2 to lunaix

* ext2: basic file read functioning

* fix incorrect return size calculation in ext2::read and pcache::read
* make ext2db_iter terminate when datablock reaching the size of file.
* fix that cat does not check on negative return value of read upon
  read(2) error.

* ext2: inode and data block allocation

* ext2: add support to allocate inode and data block
* ext2: add support to de-allocate inode and data block
* ext2: managing the ext2_gdesc with bcache
* ext2: rename some functions for conciseness
* usr/sh: QoL improvement by faking the PATH env var

* ext2: inode data blocks allocation

* ext2: unifying the indirect block walking
* ext2: data block allocation for inode

* ext2: mkdir, rmdir, generic dir_ent insert/delete

* ext2: add mkdir and rmdir
* ext2: add inode creation
* ext2: add ability to do file write
* vfs: add the missing destruct callback for dnode
* fix: add a null check on bbuf_t related operations

* ext2: symlink, mknod, link/unlink, sync and fixes

* ext2: add support to symlink get/set
* ext2: add support to inode creation
* ext2: add link and unlink
* ext2: directory renaming
* ext2: fsync and full fs syncing
* ext2: add proper un-mounting
* ext2: inode metadata update & sync
* vfs : some refactoring
* vfs : add O_TRUNC and fix O_APPEND behaviour
* vfs : update the fsize after write
* twimap: fix issue that it failed to read mapped content

* update LBuild with new files, fix some issue with LConfig

* fix issue where LConfigProvider::has_config does not capture the case
  of boolean typed config
* fix issue where CHeaderConfigProvider:: try to appened non-str typed
  value to the header file generation flow

* various fixes for merging the master branch

* fix: the incorrect use of clz on unsigned long data type
* ref: add 64bits variances of clzl, llog2. provide handy definition
       of most significant bit index of unsigned long and int.
* ref: uncaptialize the ILOG2
* fix: the kernel stack creation and copy algorithm, make it
  less hacky
* fix: assertion on thread state in pwake is too strong. if a
  thread is already awakened by other event or killed, just remove
  it from wait list
* fix: change the tag calculation in ext2::bTLB, so it can contain
       validity bit
* fix: a block buffer should ref again when inserting into bTLB
* fix: mixed use of size_t and unsigned int, this is not working
       on 64bits platform
* fix: boot disk prober automatically use last device it scaned
       when no blkdev can be identified as boot disk
* feat: qemu.py (autoqemu) will now skip the block device if the
        image is not found, so it provides a less disastrous
        fallback behavior
* fix: always vzalloc for the bltb buffer.

* fix logic error in ext2 file write & inode creation flow

* rename the fsblock_take to fsblock_get
* add the fsblock_take for doing refonce function
* add a test program that write random string into
  file

* fix issues in dirent creation and file write

* fix:  incorrect calaculation of rec_len
* fix:  confusion on inode number (1 based) and inode
        index (0 based)
* fix:  racing when one process creating file while
        other try to read that directory structure.
* fix:  pcache write must not enforce the fpos to be
        page aligned all the time, otherwise, page
        cache paddings will be written.
* fix:  autoqemu: smp and memory parameter not set.
* fix:  rng generator failed to populate whole buffer
        other than the beginning few bytes
* fix:  failsafe unwrapper should follow x86_64 convention.
* fix:  blkbuf: define null bbuf as not initialized.

* modified ext2 now passed the e2fsck validation

* fix:  sync the changes to superblock.
* fix:  correct the rec_len when the dirent is last of this
         data block
* fix:  (ahci) add sanity check on DMA buffer size
* fix:  i_blocks calculation should include the intermediate blocks
         allocated for building indrections.
* ref:  some minor changes to the fsapi_vsb_*
* feat: add a printk emulation for quick log printing without
         the need of explicit specify the LOG_MODULE
* fix:  skip the sync if a blkio_req is pending. previous version
         only skip it after the access flag is changed, which may
         lead to undesired behaviour on some cases.

* fix issue in ext2_mkdir

* fix:   break the pwait into two parts: add to wait list and
          the actual wait start. Thus to resolve the racing
          problem in the blkio by ensure that the active thread
          will always in the blkio_req's waiting list even when
          the completion interrupt arrive before we invoke the
          actual waiting.
* fix:  dirty page cache should be flushed before closing the
          file.
* fix:  make most system calls preemptive in kernel space, to
          increase the responsive time and avoid interrupt
          squashing for i/o intensive device.
* feat: add mkdir program for testing

* protect the blkio and blkbuf with mutex lock.

* ref:   separate the non-reentrant and reentrant (nested)
          mutex locking/unlocking.

* Improvements patch: Kernel preemptions (#42)

* added mechanism for checking any stalling in kernel space

* ref:    wrap the syscall dispatching into a proper C function.
* ref:    separate the sched_pass into two category: yield and preempt
* ref:    add a redirection checking stage prior to the context restore,
           which enable us to extend in the future (if needed)
* feat:   add the to more pwait variant, for indicate that the event
           waiting should be opted in stall checking
* feat:   add thread statistics on kernel/user transition

* fix: outdated kernel stack reclaiming corrupt the other threads

* feat:   add an extra config term to detect dead loop in kernel space.

* minor adjustment on formating

* add comments on explaining switch_signposting

* file deletion and add file resizing

* fix:    tested and fixed the file deletion.
* feat:   inode resizing for dynamically deallocate data block
          that is not used after shrinking.
* fix:    incorrect thread reference when checking stalled task
* feat:   test program for file deletion/unlinking.

* update the inode attrs when setting symlink

* ref:  change some comments
* fix:  add FSTYPE_PSEUDO to distinguish filesystem that is
        capable of device-less mounting
* feat: a wrapper for filesystem registration
* ref:  refactor currently avaliable file system registration
        code with aforementioned wrapper

* update readme

* * rewrite the ext2_rename, to make it right

* feat: add support to FILE_TYPE and LARGE_FILE feature.
* fix:  feature check on mounting.
* fix:  memory leakage on ext2_dnode.
* fix:  double free on ext2_dnode when ext2_mkdir fail.
* fix:  properly release the ext2_dnode after ext2dr_remove.
* ref:  code clean up on ext2.

16 months agouserspace fun: maze game and a new device to support it
FFreestanding [Wed, 31 Jul 2024 09:19:43 +0000 (17:19 +0800)]
userspace fun: maze game and a new device to support it

Maze Game Introduction
WASD: move
H: get cue
Q: quit
N: new maze

16 months agofix: false positive when looking for room to host pmem_list
Minep [Mon, 29 Jul 2024 00:10:38 +0000 (01:10 +0100)]
fix: false positive when looking for room to host pmem_list

  some weird mem region reported by multiboot might be "just"
  enough to house pmem_list, but not considering the L0T alignment

  make it to retry instead of fold up instantly

16 months agoChange of vterm handling logic on backend chardev input event (#40)
Lunaixsky [Sun, 28 Jul 2024 21:50:17 +0000 (22:50 +0100)]
Change of vterm handling logic on backend chardev input event (#40)

* fix: term should not ignore underlying input event

* term should always respond the input event from underlying
  termport awared character device, by process the raw input
  buffer according one's lflags.ICANNO setting when the data
  is avaliable

* fix: race when parent get destroyed before children

* fix: orphan a process's children when it is about to destroy
* fix: devzero: mis-used offset cause segfault

* add support of setting serial io speed

* fix: truncate the overflowed input instead of running over.

* rewrite the line control

* rewrite the line control implementation to make it
  clean and less hacky.
* correct some POSIX compliance issue related to some
  control characters.
* fix issue where ANSI line control failed to echo the
  transformed special character
* add a sanity filter to sh to filter out any unprintable
  character.

* fix: make lxconsole work with vterm refactor

* fix: tdev_do_read do not check the linebuffer::sflag

* add a config term for lxconsole (vgacon)

* rename tty/tty.c to vga_rawtty.c for clarity

16 months agofix: gen_ksymtable does not work on non-English platform
Minep [Sat, 27 Jul 2024 13:50:32 +0000 (14:50 +0100)]
fix: gen_ksymtable does not work on non-English platform

* the grep based method to access ELF class based on readelf
  output assume the English-language output

* fix lunaconfig do not update the config tree when saving

16 months agoadd pre-commit hooks to regulate things
Minep [Sun, 21 Jul 2024 20:30:14 +0000 (21:30 +0100)]
add pre-commit hooks to regulate things

16 months agoPCI 16x50 UART Controller, O2 Enablement (#39)
Lunaixsky [Sun, 21 Jul 2024 19:45:46 +0000 (20:45 +0100)]
PCI 16x50 UART Controller, O2 Enablement (#39)

* add PCI 16x50 uart controller, refactor the 16x50 structure

* refactor the pci detection mechanism, allow custom compatibility
  check logic.

* fix bug in pci device definition binding where only bind once

* refactor the 16x50 controller structure, move pmio and mmio
  as separated component and does not need to couple with interface

* fix issue where x86:isrm_ivexalloc alloc duplicated interrupt vector

* change the signature of ioremap to return ptr_t instead of generic
  pointer

* fix issue in LunaConfig header export, where non string type being
  joined as a string type

* add config term for 16x50 controller.

* rework the usr/testp, allow user to specify serial interface

* usr/ls, add a slash after directory file name to distinguish

* add the implementation for iounmap

* refactor pci dev to use latest change in pci

* remove the out-dated, mask based compatibility check scheme

* rectify the issues with -O2 optimization

* refactor: allow Lunaix to compile with -O2 optimization
* add LConfig terms for PCI related features
* add LConfig terms for AHCI related features
* refactor the pci device code base with latest pci refactoring
* fix: fail to read bool type config term when the value of the
       term is False
* refactor: LConfig: allow omit the `LConfig` when doing include

* remove legacy file

16 months agoadd mem-map for x86_64
Minep [Tue, 16 Jul 2024 23:55:33 +0000 (00:55 +0100)]
add mem-map for x86_64

16 months agoArchitectural Support: x86_64 (#37)
Lunaixsky [Tue, 16 Jul 2024 21:17:07 +0000 (22:17 +0100)]
Architectural Support: x86_64 (#37)

* x86_64 port: exception model, syscall, arch utils

* add port to exception model: hart state transistion, general
interruption hanlding
* add port to syscall: call convention, operand size
* arch utils change: udiv64, add native implementation
* makefile: add dedicated action to do configuration
* trace: port register dumping
* other refactorings

* port: virtual memory inteface, vm partition

* add support to 64bits virtual memory management scheme
* add definitions for memory partition under 64 bits
* refactor: routine clean up, remove deprecated MEM_*
* fix: reverse the order of lo/hi in struct x86_sysdesc

* rename i386 to x86 for clarity

* port: boot code, preliminary memory setup

* add boot code port to x86_64, include IA32e mode switching sequence
  recommended by Intel
* add support of x86_64 to memory setup
* refactor: move boot code into two separated directory for clarity
* refactor: boot_helper: memory reservation code should go to
  arch-specific

* feat: architectural-dependent linking

* preprocess the linker script with gcc's preprocessor before commencing
  the linking
* fix: LConfig: x86_feature setting missing when arch=x86_64

* decouple elf loading. Make thing compile

* decouple the arch-related elf parsing and loading part from the kernel base
* fix compiliation issues when compiling under 64 bit mode
* fix a relocation issue where the boot code reference a symbol exported
  from relocated kernel's LMA for address calculation.
* make thing more unified in LBuild
* port other misc stuff to x86_64

* add boilerplate for multiboot2 bootloader interface

* ensure the i386 invariant after refactroing for baseline

* port: remove hidden assumption of VMS_SELF in vm model

* creation of those lntep pteps mades a hidden assumption of
  VMS_SELF address used, which introduce inflexibility
* adjust the vm map of x86_64 to make sure kernel's address
  can be relocated with R_86_64_32S policy
* port: pplist mapping to x86_64
* refactor: rename all explicity comparision with VMS_SELF
  with an inline of active_vmnt()
* refactor: encapsulate all explicity checking of ptep for
  unpacking into vmnt_packed()

* fix: vmscpy, vmsfree and kmem_init assumption on vm map structure

* fix: linking issue with 64bit addressing

* previous: satisfy R_86_64_32S relocation by adjusting the kernel
  base address
* fixup other issue due to previous refactoring

* enable of x86_64 on usr/

* lunalibc:  port:     x86_64 support

* lunalibc:  fix:      cut down the unnecessary register savings when
                       invoking syscall.

* lunalibc:  refactor: better syscall invocation method

* lunabuild: refactor: rename set() to set_value() to avoid confusion
                       with set declaration

* lunabuild: fix:      cascade updating case stack overflow when triggered
                       by itself through set_value()

* makefile:  fix:      only triggered re-configuration shell when config
                       save is deleted or explicit required.

* makefile:  feat:     add a env variable ARCH= on make, to allow specifiy
                       the targeted ISA without going through all the
                       trouble of configuration shell

* build:     fix:      use mcmode=kernel to allow linking with kernel base
                       relocated to -2GiB while remove the need of the bloat
                       of mcmode=large

* make variadic syscall more portable

* syscall:  fix:  va_list now only cross the kernel broader with a
                  reference rather than value, which make the
                  interface portable as some architecture abi require
                  va_list to be a struct.

* syscall:  ref:  (this is a refactor) remove the need of variadic
                  syscall usage on sys_mmap and syslog. As they are
                  point-less

* fix: issues during the bootstrap stage

* arch/boot:    add missing mode switching from x86_64 compatibility
              mode to full 64-bits (long mode)

* kpt_remap:    rework the kernel high-mem remapping for x86_64.
              isolate the remap logic of x86_64 and i386

* gdt:          when loading gdt, the descriptor must follow the
              i386's format (all field are required), as processor
              will perform all the checks upon loading

* idt:          remove the ist thing, we should reserve it for the
              "ABORT" interrupts to use.

* ctx switch:   fix issue of a register being left in stack

* vm:           add sign extend on virtual address to enforce consistency
              adjust the _PTE_X and introduce _PTE_NX
              minor adjustment on vm mapping for easy setup

* kprintf:      fix the 64-bit integer not being correctly displayed
              in hex.

* acpi:         fix the vague use of generic pointer type as acpi
              require all pointer type must be int32

* variadic:     wrap the va_list unpacking method into arch-specific

* makefile:     invoke correct QEMU depend on build architecture

* lunabuild:    disable the gcc's SSE optimization when LConfig does
              enable this.

* elf64:        typo fix, should check for CLASS64 flag set, rather
              than CLASS32

* pmm:          pplist mapping granularity fix.

* reactor:      some refactorings, clarify things

* fix issues all the way to user space

* interrupt64:    incorrect stack address calculation
                  temp saved %rax not being restored
* kern/syscall:   a confrontation to systemv abi, %rbx is trashed
                   without being saved
                  offset miscalculated, replaced with one defined
                   in interrupt64.S.inc to avoid these magic number!
* usr/syscall:    there is no way to force param pass through stack
                   under x86_64, roll back to use registers

* gdt:            it turns out you still need a valid data seg desc
                   for both R0/R3 data selector

* tss:            fix incorrect offset for tss defined in
                   interrupt64.S.inc

* usr:            use -mcmodel=large to link all user program, we
                   may shift to PIC in the near future

* pagetable:      add __paddr to ensure we the calculated address
                   (physical) does not exceed the maximium allowance
                   (that is, 52 bits)

* mempart:        adjust the memory map to move user stack lower,
                   so we can distinguish it from sign extended
                   kernel address visually
                  add extra term for specifiying max stack size
                   PER THREAD, to avoid confusion.

* tlb:            add couple of invalidation to ensure freshness

* procvm:         fix the page table walking on step out single
                   level when the structure has multiple level
                   chained at the last pte. Which result incorrect
                   L(n-1)TEP returned.
                  fix the issue of ptep calculation for establishing
                   self-reference on mounted vms, when we have ptw
                   more than 2 levels.

* thread:         adjust the guardian pte injection logic, so it will
                   no longer occupying the per-thread stack space

* makefile:       add qemu trace for tracking the interrupt event
                   ( require my customized qemu version)

* misc:           refactorings of course.

* fix issues in execve and lunalibc due to change of ABI

* exec:  fix:  incorrect assumption on argv and envp, according to
               the POSIX, envp and argv in execve are mandatory
               (can not be null).

* exec:  ref:  refactor the parameter injection code, so to be more
               uniform and readable. we also remove the auto injection
               of argv[0], and thus it is programmer's responsibility
               to ensure that.

* libc:  fix:  x86_64 ABI for signal trampoline and crt*.S

* i386:  fix:  i386 failed due to previous refactoring.
               The kernel stack page count must be napot.

* an elegant way of configuring and creating QEMU instance

* feat:   rework the way to config and create QEMU instance,
          abstracting all the qemu specifications into a manifest
          file and thus more clear and less error-prone

* feat:   add ability of lazy evaluation of lunaconfig node, thus
          rendering the loading order insignificant

* ref:    separate the qemu launching task from the makefile.

* ref:    clean up and general house-keeping

* always clear the LCR.DLAB bit before configuring

* when two 16550 devices on different bus (isa and pci this case)
  the LCR.DLAB bit is somehow being set, causing subsequent write
  to register become undefined. It is unclear why qemu left this in
  such undefined state.

* add a qemu-dir to qemu.py to allow override the qemu used

* update readme

* change the th_create syscall interface to be more flexible

* th_create syscall need to be change in order to provide
  better integration with user space where trampoline must
  be used.

* increase the limit of maximium syscall number

* re-implement the pthread_create in lunalibc

* fix issue in the threading interfacing

* fix:  thread handler calling in trampoline
* fix:  mismatch parameter count to the printf fmt in test_pthread,
        which causing segfault
* fix:  debug/trace does not print the $pc when a symbol is fail to
        locate

* ref:  refactor the /sys/version mapping to avoid doing formatting
        as they are all compile time constant
* ref:  remove the x86_recv_interrupt_all as it is too noisy.
* ref:  remove redundant cpu feature from the QEMU specification

* update readme

16 months agold-tool portability fix: MacOS build experience
Minep [Wed, 10 Jul 2024 18:08:56 +0000 (19:08 +0100)]
ld-tool portability fix: MacOS build experience

* fix: makefile fail to build due to line feed character not being
       recognise as valid separator

* change shebang to more portable of /usr/bin/env

17 months agointegrate C/LDFLAGS into LunaBuild flow
Minep [Thu, 4 Jul 2024 18:44:47 +0000 (19:44 +0100)]
integrate C/LDFLAGS into LunaBuild flow

* allow LBuild framework to accept custom generation implementation
* allow LBuild framework to accept custom built-in function
* separate the compilation flags setting by arch

17 months agoIntroducing LunaBuild to the build flow (#36)
Lunaixsky [Thu, 27 Jun 2024 15:11:18 +0000 (16:11 +0100)]
Introducing LunaBuild to the build flow (#36)

* add LunaBuild for better control of source file selections

* remove out-dated template based method
* add LBuild files that follow LunaBuild methodology

* integrate LunaBuild into the building flow

* add documentation on general usage of LunaBuild
* fix `make run` does not work properly

* implement and integrate LConfig language

* implement LConfig language for modularised kernel build experience
* integrate LConfig into build flow
* clean up out-dated files

* Add interactive shell to do configuration

* file clean up

* General clean up

* move grub image stuff to scripts/grub
* remove the code format rule file - we don't need these fancy shit!

* refine the config shell experience

* allow accessing node using posix-path
* able to identify whether the configuration is aborted or exit normally

* fix up the dependencies in makefile, rebuild when needed

* make sure the configuration shell only pop up when:
  1) LConfigs changed
  2) config.h disappeared
* add proper implementation on header files change detection
* add missing doc string on some config nodes

17 months agoDecoupling Architectural-specific Code (#35)
Lunaixsky [Sat, 22 Jun 2024 14:16:00 +0000 (15:16 +0100)]
Decoupling Architectural-specific Code (#35)

* add headers for generic arch implementation

* restructure the arch-dependent file, better separation

* populate generic architecture for templating

* more cleaning and refactoring to keep things stay decoupled
* allow architectural specific code to override klib functions.

* merge lib/ into klibc for uniformity

* add x86 specific crc32 implementation, require SSE4 extension

* rename isr_param to more general hart_state

* isolate: direct reference of memeber inside hart_state

* isolate the hstate dumping part of trace.h.

* general clean up

* decouple gdbstub from architectual code.

* fix the trace_log missing component name
* add reg_t to shadow the explicit typed register value

* rename hart_change_execution to hart_flow_redirect

18 months agohot fix: remove outdated objcpy
Minep [Sun, 2 Jun 2024 18:00:59 +0000 (19:00 +0100)]
hot fix: remove outdated objcpy

19 months ago* fix an issue that execve attempts to parse directory as elf file.
Minep [Mon, 29 Apr 2024 18:51:50 +0000 (19:51 +0100)]
* fix an issue that execve attempts to parse directory as elf file.

19 months agoMerge branch 'master' of github.com:Minep/lunaix-os
Minep [Sat, 20 Apr 2024 10:20:28 +0000 (11:20 +0100)]
Merge branch 'master' of github.com:Minep/lunaix-os

19 months agoproperly update the pprev of next node when deleting hlist_node (close #30)
Minep [Sat, 20 Apr 2024 10:19:15 +0000 (11:19 +0100)]
properly update the pprev of next node when deleting hlist_node (close #30)

20 months agofix issue 31 (#32)
FFreestanding [Tue, 26 Mar 2024 01:42:09 +0000 (09:42 +0800)]
fix issue 31 (#32)

* fix out of bound write in __init_pile

---------

Co-authored-by: ffreestanding <achillesweb@qq.com>
21 months ago* Make the ksym table built-in with kernel image, thus remove the need
Minep [Sat, 2 Mar 2024 15:56:19 +0000 (15:56 +0000)]
* Make the ksym table built-in with kernel image, thus remove the need
  of grub side-loaded module. This include a two-stage linking: first
  pass is used to generate relocated symbol address and populate the
  ksymtable; second pass is to link the ksymtable into the kernel.

* Fix an issue within terminal signal delivery, which always deliver
  SIGINT due to a typo

* Fix the issue where pwait is waken by SIGINT, the next pwait call
  will fail the invariant assertion check

21 months agoUnifying the Lunaix's Physical Memory Model (#28) feat/user_model
Lunaixsky [Sat, 2 Mar 2024 00:22:18 +0000 (00:22 +0000)]
Unifying the Lunaix's Physical Memory Model (#28)

* * Introduce new physical page model, which swap out the previous
  address based one, also support dynamically allocate required
  page list based on system mem map provided by upstream bootloader

* Rename page alignment utils from pagetable.h for better expresivenness

* Rewrite the next fit allocator with order-based free-list caching
  feature. (PMALLOC_SIMPLE)

* Intented to add more advanced pmem allocator.

* Add config.h file that provide finer control on the "hyperparameter"
  of Lunaix kernel (we should switch to tools like kconfig later)

* * Introduce struct leaflet, which is a wrapper around struct ppage
  used to tackle the ambiguity of head or tail when struct ppage
  has a order > 0 base page compounded.

* Refactoring done regarding to this new abstraction.

* * Fix compiler-time errors

* Remove the pmm_init_freeze_range api and init_begin/end things
  this forcing allocator to explicitly initialize entire pplist
  during a single pmm_init invoke

* Address all issues found when doing smoking through bootstraping
  stage

* * Fix issues discovered when preforming smoke test from bootstage to
  initd spawn.

     1. pte skipped from copying for grouped pages.
     2. symlink creation ignore the null terminator in ramfs
     3. Add null-ptr termination on when user-provided envp
        and argc are absent (thus only default one get injected)
     4. physical page does not get marked as initialized when
        allocated from uninitialized memory region
     5. a typo cause vunmap accidentially remove L0T mapping
     6. ahci: fis and cb region should not mapped through ioremap.

* Need investigate: seems the physical page got smashed with each
  other when intensive alloc and freeing taking place. Could be
  issues within allocator

* * Fix issue that dup_leaflet copy incomplete data when dealing with
  leaflet with order > 1. This due to lack of flush ranged tlb records

* Fix a memory leakage on leaflet when releasing thread kstack

* * Rework the tlb flushing functions, introduce the ability to respect
  different address space, this allow seamless porting to architecture
  with TLB ASID-tagging support to eliminate un-needed tlb flushing

* * Remove obsoleted vmm api

* * Move all kernel built-in stack to dedicated section

* Add failsafe stack to run failsafe handler without need to worry
  current stack validity (as everything could be messed up when
  shit happened)

* Add failsafe handler to gather diagnostic info and centralise
  stack trace printing, which is robost as it use an dedicated
  stack and all calling being inlined so avoid any stack operation
  before entering it

* Add check on init stack smashing.

* * (LunaDBG) update pmem profiling to reflect the latest changes

21 months ago7-ps2_keyboard.md and 8-multitasking.md (#29)
FFreestanding [Mon, 26 Feb 2024 22:55:22 +0000 (06:55 +0800)]
7-ps2_keyboard.md and 8-multitasking.md (#29)

Add tutorial on ps2 driver and multitasking stuff
---------

Co-authored-by: ffreestanding <achillesweb@qq.com>
21 months ago6-acpi_and_apic.md (#27)
FFreestanding [Tue, 20 Feb 2024 16:00:16 +0000 (00:00 +0800)]
6-acpi_and_apic.md (#27)

21 months ago* Remove the debugging hack in procvm.c
Minep [Sun, 18 Feb 2024 17:28:12 +0000 (17:28 +0000)]
* Remove the debugging hack in procvm.c

21 months agoA Total Overhaul on the Lunaix's Virtual Memory Model (#26)
Lunaixsky [Sun, 18 Feb 2024 17:15:39 +0000 (17:15 +0000)]
A Total Overhaul on the Lunaix's Virtual Memory Model (#26)

* * Introducing a new declaritive pte manipulation toolset.
  Prior to this patch, the original page table API is a simple,
  straightforward, and yet much verbose design. Which can be seen
  through with following characteristics:

        1. The `vmm_set_mapping` is the only way provided to set pte
           in the page table. It require explicitly specifying the
           physical, virtual and pte attributes, as was by-design to
           provide a comprehensiveness. However, we found that it
           always accompanied with cumbersome address calculations and
           nasty pte bit-masking just for setting these argment right,
           especially when doing non-trivial mapping.

        2. The existing design assume a strict 2-level paging and fixed
           4K page size, tightly coupled with x86's 32-bit paging. It
           makes it impossible to extend beyond these assumption, for
           example, adding huge page or supporting any non-x86 mmu.

        3. Interfacing to page table manipulation is not centralised,
           there is a vast amount of eccentric and yet odd API dangling
           in the kboot area.

  In light of these limitations, we have redesign the entire virtual
  memory interface. By realising the pointer to pte has already encodes
  enough information to complete any pte read/write of any level, and
  the pointer arithematics will automatically result the valid pointer
  to the desired pte, allowing use to remove the bloat of invoking the
  vmm_set_mapping.

  Architectural-dependent information related to PTE are abstracted
  away from the generic kernel code base, giving a pure declaritive
  PTE construction and page table manipulation.

* Refactoring done on making kboot using the new api.

* Refactoring done on pfault handler.

* * Correct ptep address deduction to take account of pte size, which
  previously result an unaligned ptw write

* Correct the use of memset and tlb invalidation when zeroing an
  newly allocated pagetable. Deduce the next-level ptep and use it
  accordingly

* Simplyfy the pre-boot stuff (boot.S) moves the setting of CRx into
  a more readable form.

* Allocate a new stack reside in higher half mem for boostraping stage
  allow us to free the bootctx safely before getting into lunad

* Adjust the bootctx helpers to work with the new vmm api.

* (LunaDBG) update the mm lookup to detect the huge-page mapping
  correctly

* * Dynamically allocate page table when ptep trigger page fault for
  pointing to a pte that do not have containing page table. Which
  previously we always assume that table is allocated before pte
  is written into. This on-demand allocation greatly remove the
  overhead as we need to go through all n-level just to ensure the
  hierarchy.

* Page fault handling procedure is refactored, we put all the
  important information such as faulting pte and eip into a dedicated
  struct fault_context.

* State out the definition we have invented for making things clear.

* Rewrite vmap function with the new ptep feature, the reduction in
  LoC and complexity is significant.

* * Use huge page to perform fast and memory-efficient identity mapping
  on physical address space (first 3GiB). Doing that enable us to
  eliminate the need of selective mapping on bootloader's mem_map.

* Correct the address calculation in __alloc_contig_ptes

* Change the behavior of previously pagetable_alloc, to offload most
  pte setting to it's caller, makes it more portable. We also renamed
  it to 'vmm_alloc_page'

* Perform some formattings to make things more easy to read.

* * Rewrite the vms duplication and deletion. Using the latest vmm
  refactoring, the implementation is much clean and intuitive than
  before, althought the LoC is slightly longer. The rewrited version
  is named to `vmscpy` and `vmsfree` as it remove the assumption of
  source vms to be VMS_SELF

* Add `pmm_free_one` to allow user free the pmm page based on the
  attribute, which is intented to solve the recent discovered leakage
  in physical page resource, where the old pmm_free_page lack the
  feature to free the PP_FGLOCKED page which is allocated to page
  table, thus resulting pages that couldn't be freed by any means.

* Rename some functions for better clarity.

* * Rewrite the vmm_lookupat with new pte interface

* Adjust the memory layout such that the guest vms mount point is
  shifted just before the vms self mounting point. This is remove
  effort to locate it and skip it during vmscpy

* Add empty thread obj as place-holder, to prevent write to undefined
  location when context save/store happened before threaded environment
  is initialized

* * Fix more issues related to recent refactoring

     1. introduce pte_mkhuge to mark pte as a leaf which previously
        confuse the use of PS bit that has another interpretation
        on last level pte

     2. fix the address increamention at vmap

     3. invalidate the tlb cache whenever we dynamically allocated
        a page.

* (LunaDBG) rewrite the vm probing, employing the latest pte interfacing
  and make it much more efficient by actually doing page-walk rather
  than scanning linearly

* * Fix an issue where the boostrap stack is too small that the overflow
  corrupt adjacent kernel structure

* Add assertion in pmm to enforce better consistency and invariants

* Page fault handler how aware of ptep fault and assign suitable permission
  for level creation and page pre-allocation

* Ensure the mapping on dest_mnt are properly invalidated in TLB cache
  after we setup the vms to be copied to.

* (LunaDBG) Fix the ptep calculation at specified level when querying an
  individual pte

* * Rework the vms mount, they are now have more unified interface
  and remove the burden of passing vm_mnt on each function call.
  It also allow us to track any dangling mount points

* Fix a issue that dup_kernel_stack use stack top as start address
  to perform copying. Which cause the subsequent exec address to be
  corrupted

* Fix ptep_step_out failed on non-VMS_SELF mount point

* Change the way that assertion failure reporting, now they just
  report it directly without going into another sys-trap, thus
  preserve the stack around failing point to ease our debugging
  experience.

* * ensure the tail pte checking is peformed regardless the pte value when
  doing page table walking (e.g., vmsfree and vmscpy). Which previously
  is a bug

* the self-mount point is located incorrectly and thus cause wrong one
  being freed (vmsfree)

* ensure we unref the physical page only when the corresponding pte is
  present (thus the pa is meaningful)

* add a flag in fault_context to indicate the mem-access privilege level

* address a issue that stack start ptep calculation is offseted by 1, causing
  a destoryed thread accidentially free adjacent one's kernel stack

* * Purge the old page.h

* * Refactor the fault.c to remove un-needed thing from arch-dependent side.

* (LunaDBG) add utilities to interpret pte value and manipulate the ptep

* * Add generic definition for arch-dependent pagetable

21 months ago5-malloc.md (#25)
FFreestanding [Fri, 9 Feb 2024 01:36:28 +0000 (09:36 +0800)]
5-malloc.md (#25)

Add tutorial on malloc

Fix some previous typos
---------

Co-authored-by: ffreestanding <achillesweb@qq.com>
21 months ago4-virtual_memory.md (#24)
FFreestanding [Tue, 6 Feb 2024 10:38:55 +0000 (18:38 +0800)]
4-virtual_memory.md (#24)

22 months agoSupport to multi-threading and pthread interface (POSIX.1-2008) (#23)
Lunaixsky [Mon, 5 Feb 2024 17:20:02 +0000 (17:20 +0000)]
Support to multi-threading and pthread interface (POSIX.1-2008) (#23)

This patch brings a functional multi-threading support to Lunaix kernel
together with essential syscalls to support POSIX's pthread interfacing.

About the threading model in Lunaix
Like the Linux kernel, the threading feature is built upon the existing
multi-processing infrastructure. However, unlike Linux which uses a more
lazy yet clever approach to implement threads as a specialized process,
Lunaix implements threading that perfectly reflects its orthodox definition.
Which requires a from-scratch and massive refactoring of the existing process
model. Doing this allows us to make things clearer and pursue a true
lightweightness of what threads are supposed to be.

Kernel thread and preemptive kernel
As a natural result of our implementation, we have implemented the concept
of kernel threads, which are subsidiaries of a special process (pid=0) that runs
under kernel mode. Treating the kernel as a dedicated process rather than a
process parasite, enables us to implement an advanced feature of a preemptive
kernel. Unlike in Linux, where the kernel is preemptive anywhere; Things were
different in Lunaix, where only functions called directly from the kernel thread can
be preemptive, which allows us to perform more fine-grand control. This reduces
the effort of refactoring and eases the writing of new kernel code, for which the
non-preemptive assumption can be kept.

Spawning and forking
This patch introduces a set of tools for performing remote virtual memory space
transaction, allow the kernel to inject data into another address space. And will
be used as infrastructure for kernel-level support on the `posix-spawn`
interface, which creates a process from scratch rather than fork from another,
allows us to skip duplicating the process's VM space and reduce overhead.

LunaDBG
LunaDBG has been refactored for modularization and arch-agnostic. New set of
commands are being added:

        mm: a sophisticated tool for examining page table mapping and performing
            physical memory profiling (detailed usage see up-coming documentation)
     sched: tools for examining the scheduler context, listing all threads and
            processes

--------------
All changes included in this patch:

* * Signal mechanism refactor

   The sigctx of proc_info is changed to a pointer reference as well as the
   sigact array is now in favour of storing references. Therefore we can keep
   the overall proc_info and sigctx size small thus to avoid internal fragmentation
   of allocating large cake piece.

   Some refactoring also done on signal related method/struct to improve
   overall readability

* Temporary removal of x87 state from context switching until a space-efficient
  workaround emerged

* Add check on kernel originated seg-fault and halt the kernel (for debugging).
  As by assumption kernel mapping will always present (at least for now, as
  page swapping and stagging is not implemented in Lunaix yet).

* Re-group the fork related functions to a dedicated fork.c file

* Fix a incorrect checking on privilege level of interrupt context when
  printing tracing

* * Make proc_mm as a pointer reference to further reduce the single allocation size
  as well as making things more flexible

* Remove the need of pid when allocating the physicall memory. Due the complexity and
  the dynamics in the ownership of physical page, there is no point to do such checking
  and tracking.

* Add some short-cut for accessing some commonly used proc_mm field, to avoid nasty
  chain of cascading '->' for sake of readbility.

* * Introducing struct thread to represent a light-weighted schedulable element.

  The `struct thread` abstract the execution context out of the process, while the
  latter now composed only descriptors to program resources (e.g., file, memory
  installed signal handlers). This made possible of duplicating concurrent
  execution flow while impose a rather less kernel overhead (e.g., cost to context
  switch, old-fashioned fork()-assisted concurrency).

  Such change to process model require vast amount of refactoring to almost every
  subsystem involving direct use of process. As well as introducing additional
  tools to create the initial process. This commit only contains a perliminary
  refactoring works, some parts require additional work-around is commented out and
  marked with `FIXME`

* Other refactoring and cleaning has been done to improve the semantics of certain
  pieces of code.

* * Process and thread spawning. Allow to reduce the system overhead
  introduced by invoking fork to create process. However, creating
  a process housed executable image is not implemented as it require
  remote injection of user stack for which is still under consideration

* Introducing kernel process and kernel threads. Prior to the threading
  patch, the dummy process is a terrible minick of kernel process
  and used as merely a fallback when no schdulable process can be found.
  This makes it rather useless and a waste of kernel object pool space.
  The introducing of thread and new scheduler deisgn promote Lunaix
  to a full functioning kernel thread, it's preemptiveness enable the
  opportunity to integrating advanced, periodical, event driven kernel
  task (such as memory region coalescing, lightweight irq handler)

* Some minor refactorings are also performed to make things more clean

* Update the virtual memory layout to reflect the current development

* * Fix the issue of transfer context being inject into wrong address
  as the page offset was some-how not considered

* Fix the refactoring and various compile time error

* Adjust the lunadbg to work with latest threading refactoring.

* Also fix the issue that lunadbg's llist iterator had made false
  assumption on the offset of embeded llist_header.

* Rename spawn_thread -> create_thread. And introduce spawn_kthread
  to spawn a kernel thread within kernel process.

* Fix the issue in vmm_lookupat that ignore the present bit when
  doing pte probing

* Leaves some holes for later investigations

* * Make threading feature works properly

* Fixed left-over issues as well as new issues found:

    1. incorrect checking on thread state in 'can_schedule', causing
       scheduler unable to select suitable thread even though there
       exists one

    2. double free struct v_file when destorying process. Which caused
       by a missing vfs_ref_file in elf32_openat

    3. destory_thread removed wrong thread from global thread list

    4. thread-local kernel and user thread don't get released when
       destorying thread

    5. lunad should spawn a new process for user space initd rather than
       kexec on current kernel process

    6. guarding the end of thread entry function with 'thread_exit'
       to prevent run-over into abyss.

    7. fix tracing.c prints wrong context entring-leaving order

    8. zero fill the first pde when duplicating the vm space to avoid
       garbage interfering the vmm

* * Allow each process to store their executable arguments

* Refactor the lunadbg toolset (done: process, thread and scheduler)

* * Fix can_schedule() should check against thread's state rather than process state

* Remove the hack of using ebp in 'syscall_hndlr', thus to prevent it for
  interferencing the stack-walker

* Find tune the output of tracer when incountering unknown symbol

* (LunaDBG) Add implementation for examing sigctx

* * Add related syscall to manipulate threads

* Factorise the access of frame pointer and return address to abi.h

* Shrink the default pre-thread user stack size to 256K, to account
  the shortage on 32-bit virtual address space.

* Add check to kernel preemptible function context

* Add different test cases to exercise various pthread_* api

* * (My Little Pthread Test) Fix the all sorts of issues found in current threading model implementation
  with a set of simple pthread tests.

* Add more sanity checks on tracing and pfault handler, to avoid them spamming the output stream when
  the failure is severe enough to cause infinite nesting (e.g., when vm mapping of kernel stack get
  messed up)

* Add guardian page at the end of thread-local kernel and user stack to detect stack overflow

* Remove an unwanted interrupt enablement in ps2kbd.c (which behaviour is undefined in the booting
  stage)

* Temporary fix issues with vmr dump py utils (need to adapt the new design sooner or later)

* Specify a cpu model for QEMU, which make things more detrerministic

* * Change the mmap flag for creating thread-local user stack to non-FIXED.
  As a previous experiment shows that during high concurrency situtaion,
  the calculation of ustack location for new thread will be affected and
  had risk of smashing existing thread's ustack causing undefined bevhaiour
  when return from kernel (as the stack address is implied from
  proc_info::threads_count) for which reason it should treated as
  hint to mem_map rather than a hard requirement.

* Re-implement the VMR allocation alogirthm that will takes the vicinity of
  the hinted address as high priority search area, rather than dumbly start
  from beginning.

* Remove the undesired pmm_free_page from __dup_kernel_stack. As we
  now skipped the first 4MiB when duplicating the page table. Thus the
  ref counters for these physical page are already 1 after fork. This
  has been identify the root cause of a randomly appearing segfault
  during memory intensive task such as test_pthread, as these falsely
  released physical page will get repurposed. However, this also lead
  to a question in Lunaix's memory utilisation, as the next-free strategy
  is unlikely to visit the previously allocated page when plenty of free
  space ahead. More efforts should be taken into investigating memory
  performance.

* Added more assertion and checks to enhance the robustness and ease
  the debugging experience.

* Adjust some output format and refactor the test_pthread code.

* * (lunadbg) `mm` command for probing page table and physical memory profiling

* Add missing syscall-table doc

* Add more test cases related to pthread

* * (LunaDBG) decouple the pte related operation as arch-dependent feature

* (LunaDBG) adjust the output format

* * (LunaDBG) Refactor VMR dump

* * Adjust the thread id generation to avoid duplication ratio

* Capped the thread limit per process

* (LunaDBG) Fix the issue with display of percentage in pmem profiling

22 months ago2-setup_gdt.md (#22)
FFreestanding [Mon, 22 Jan 2024 14:00:43 +0000 (22:00 +0800)]
2-setup_gdt.md (#22)

22 months ago1-hello_kernel_world.md (#21)
FFreestanding [Fri, 19 Jan 2024 19:07:30 +0000 (03:07 +0800)]
1-hello_kernel_world.md (#21)

* Add files via upload

0-教程介绍和环境搭建

* update README.md and create a tuturial dir

* docs/tutorial/1-hello_kernel_world.md

* Update 1-hello_kernel_world.md

* update 1-hello_kernel_world.md

---------

Co-authored-by: ffreestanding <achillesweb@qq.com>
23 months agofix: corner cases when printing large content through term interface
Minep [Mon, 11 Dec 2023 19:43:48 +0000 (19:43 +0000)]
fix: corner cases when printing large content through term interface
refactor: make usr/ compilation more clean
refactor: clean up unused header files
refactor: renamed things

23 months agoMerge branch 'master' of github.com:Minep/lunaix-os
Minep [Mon, 11 Dec 2023 01:00:23 +0000 (01:00 +0000)]
Merge branch 'master' of github.com:Minep/lunaix-os

23 months agofeat: capability list to enable greater flexibility of devices
Minep [Mon, 11 Dec 2023 00:56:18 +0000 (00:56 +0000)]
feat: capability list to enable greater flexibility of devices
feat: implement termios interface in LunaClib
fix: strange behaviour refered as double mounting and double-mkdir
fix: a mis-used of fpos parameter in some device file read/write invocation
fix: some bugs in user program
chore: edit readme

23 months ago教程介绍和环境搭建 (#19)
FFreestanding [Sun, 10 Dec 2023 15:18:58 +0000 (23:18 +0800)]
教程介绍和环境搭建 (#19)

* Add files via upload

0-教程介绍和环境搭建

* update README.md and create a tuturial dir

---------

Co-authored-by: ffreestanding <achillesweb@qq.com>
23 months agofeat: owloysius - dynamic init function invocator
Minep [Sun, 10 Dec 2023 13:50:32 +0000 (13:50 +0000)]
feat: owloysius - dynamic init function invocator
refactor: add a generic base struct to devices
  this allow us to specialize different kinds of device,
  sparating devfs tree node and real device, to save the overhead
feat: add device aliasing (i.e. hard link in devfs)
feat: add new gdb command to dump system log
feat: make default system console configurable through `console=<dev>` boot command line
fix: trying to delete mount point when unmounted.
fix: ensure frame-point always included regardless optimization level
chore: edit readme
d

23 months agofeat: a better boot command line parser
Minep [Sat, 9 Dec 2023 20:56:32 +0000 (20:56 +0000)]
feat: a better boot command line parser
fix: bugs in term interfacing

23 months agorefactor: add a async read/write variant to device ops, with allow async io to be...
Minep [Fri, 8 Dec 2023 20:30:53 +0000 (20:30 +0000)]
refactor: add a async read/write variant to device ops, with allow async io to be used.
refactor: decouple the gcc version requirement.
refactor: add implementation to arch-aware division, this allows removal of libgcc
fix: couple bugs in builtin user shell

updated readme

2 years agofeat: nearly complete POSIX.1-2008 compliant terminal interface implementation
Minep [Sun, 26 Nov 2023 23:17:42 +0000 (23:17 +0000)]
feat: nearly complete POSIX.1-2008 compliant terminal interface implementation
fix: a corner case in cake allocator
fix: remove a double free and add checks to cake allocator for that
fix: enforcing the termination condition of stackwalker
fix: signal delivery to process group
chore: tweak the clang-formatter config
chore: clean-up and refactors

2 years agofeat: IO polling for file descriptor
Minep [Sat, 18 Nov 2023 18:47:07 +0000 (18:47 +0000)]
feat: IO polling for file descriptor
refactor: remove the need of a separate property to track mmaped file length
  we just bring in an entire page-length of content that contains what
  we care and ignore all that garbage comes with it.
fix: sync the dirty pages in file-maped mem region upon unmapping.
chore: update readme
chore: remove objdump -S of entire kernel.

2 years agofeat: lunadbg GDB plugin to ease kernel debugging process.
Minep [Sun, 5 Nov 2023 17:28:58 +0000 (17:28 +0000)]
feat: lunadbg GDB plugin to ease kernel debugging process.
fix: rewrite mem_unmap for correctness and robustness
fix: offset in divisor cause system timer running a bit slow than expected.
fix: preventing gcc to put everything into a single loadable section when compiling user-space program
fix: nullptr risk when printing kernel stack trace

2 years agorefactor: make pci device driver loading passive, pci bus scanner will not load them...
Minep [Sat, 4 Nov 2023 19:27:18 +0000 (19:27 +0000)]
refactor: make pci device driver loading passive, pci bus scanner will not load them automatically,
          this allow greater flexibility and decouple the pci bus scanning and the driver init dependency.
refactor: move acpi as a loadable device
refactor: remove the nonsense "len" parameter from {read|write}_page file ops
refactor: decouple the ahci main driver from the pci interfacing
refacror: move the mounting of some kernel fs to user space.
refactor: rename the device loading stage to make more sense.
chores: some house-keeping stuff

2 years agofeat: kprintf now goes into dedicated pseudo-dev rather than flooding the framebuffer
Minep [Fri, 3 Nov 2023 19:33:53 +0000 (19:33 +0000)]
feat: kprintf now goes into dedicated pseudo-dev rather than flooding the framebuffer
refactor: a better kprintf buffer design that can carry more information and simplify interface signature
chores: some housekeeping stuff

2 years agofeat: support user-spcae pci rescan
Minep [Thu, 26 Oct 2023 11:29:58 +0000 (12:29 +0100)]
feat: support user-spcae pci rescan
refactor: allow lazy driver binding for pci devices

2 years agofeat: gfxm: a layer provides user space access to low level interfacing of graphic...
Minep [Tue, 24 Oct 2023 14:15:59 +0000 (15:15 +0100)]
feat: gfxm: a layer provides user space access to low level interfacing of graphic adapter
chore: clear things up

2 years agofeat: standard vga support (mode switching, framebuffer remapping)
Minep [Sat, 21 Oct 2023 21:40:52 +0000 (22:40 +0100)]
feat: standard vga support (mode switching, framebuffer remapping)
feat: better tty/term abstraction
feat: mask on pci device id to allow driver do fussy device matching
refactor: the variant field of device id is now to be the instance number
chore: clean up and re-formatting

2 years agofeat: fstat now handle symbolic link
Minep [Thu, 7 Sep 2023 19:55:56 +0000 (20:55 +0100)]
feat: fstat now handle symbolic link
refactor: file type mask rework
fix: device definition should be reflected on the abstract device struct

2 years agoregression: test serial port r/w.
Minep [Tue, 5 Sep 2023 23:50:17 +0000 (00:50 +0100)]
regression: test serial port r/w.
fix: uart register bitmap
fix: refine context switch trace message
feat: add a dedicated program to host all test routines

2 years agofeat: serial device interfacing
Minep [Sun, 3 Sep 2023 23:38:06 +0000 (00:38 +0100)]
feat: serial device interfacing
feat: devzero
feat: simple cat implementation
fix: add default name for nameless device
chore: general clean up

2 years agofeat: device subsystem rework
Minep [Mon, 28 Aug 2023 21:47:39 +0000 (22:47 +0100)]
feat: device subsystem rework
      + dynamic device driver registration and discovery
      + centeralise the device managements
refactor: syslog

2 years agofeat: better rtc framework which aims to remove single rtc restrictions.
Minep [Fri, 25 Aug 2023 22:17:18 +0000 (23:17 +0100)]
feat: better rtc framework which aims to remove single rtc restrictions.
feat: user mode api for timer/rtc through fs mapping.
feat: interrupt handlers now have the option to accept customized payload.
refactor: creare a new device class of pseudo device, hope that it will clear things
refactor: move ps2 keyboard driver out of kernel code base.
fix: pcache is now abandon the use of valloc api, as the access is unaligned when allocating page size buffer.
fix: pcached write/read should use direct file i/o and must not failed with ENOMEM when buffer allocation failed.
chore: group the device file ops for better clarity

2 years agorefactor: use a more decent physical memory map
Minep [Thu, 24 Aug 2023 12:46:14 +0000 (13:46 +0100)]
refactor: use a more decent physical memory map
fix: pde's perm overrides pte's when pte has lower access level.
feat: template generator now with infinite horizon when inferencing the memory region's base and size

2 years agohotfix: a better hinting on non-returning spin function
Minep [Wed, 23 Aug 2023 16:56:09 +0000 (17:56 +0100)]
hotfix: a better hinting on non-returning spin function
fix: make sometimes can't find 'python' if it's alias does not exported to makefile's shell

2 years agoadd lunaix dynamic linker as submodule
Minep [Wed, 23 Aug 2023 16:32:15 +0000 (17:32 +0100)]
add lunaix dynamic linker as submodule
fix: elf32 should load the PT_LOAD segments only
fix: vmap does not respect the passed mapping attribute flags
fix: mmap does not take account of flen
fix: makefile does not recompiled on changed source file.
fix: incorrect modulo operation on PG_SIZE
fix: unwanted infinite loop elimination reported in #16

2 years agoupdate readme for more up-to-date information
Minep [Sun, 20 Aug 2023 19:59:09 +0000 (20:59 +0100)]
update readme for more up-to-date information
chore: housekeeping stuff

2 years agofeat: kernel stack tracing
Minep [Sun, 20 Aug 2023 16:14:13 +0000 (17:14 +0100)]
feat: kernel stack tracing
refactor: move cpu.h to arch specific

2 years agofix: corrected time conversion on alarm/sleep syscall
Minep [Sun, 20 Aug 2023 00:27:12 +0000 (01:27 +0100)]
fix: corrected time conversion on alarm/sleep syscall
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

2 years agorefactor: one more step towards arch-agnostic design
Minep [Sat, 19 Aug 2023 22:54:30 +0000 (23:54 +0100)]
refactor: one more step towards arch-agnostic design
feat: linker generated array to free up the need of those nasty explicit invocation init_* functions

2 years agorefactor: striped more arch-related code from the kernel code base
Minep [Sat, 12 Aug 2023 16:37:14 +0000 (17:37 +0100)]
refactor: striped more arch-related code from the kernel code base
feat: memory map generation from description file

2 years agorefactor: organize all arch related files together.
Minep [Thu, 10 Aug 2023 18:46:04 +0000 (19:46 +0100)]
refactor: organize all arch related files together.
refactor: better code templating

2 years agorefactor: decouple i386 specific instruction invocation
Minep [Tue, 25 Jul 2023 18:24:03 +0000 (19:24 +0100)]
refactor: decouple i386 specific instruction invocation
refactor: re-organize the directory structure

2 years agofix: corner case for x87 context restore on execve
Minep [Sun, 23 Jul 2023 17:45:53 +0000 (18:45 +0100)]
fix: corner case for x87 context restore on execve
chore: clean up unused fields

2 years agorefactor: Optimize the signal context overhead
Minep [Sun, 23 Jul 2023 13:35:18 +0000 (14:35 +0100)]
refactor: Optimize the signal context overhead
refactor: remove kernel memory overhead for saving x87 context by saving it into user stack

2 years agorefactor: Optimize the context switch overhead
Minep [Sun, 23 Jul 2023 10:39:16 +0000 (11:39 +0100)]
refactor: Optimize the context switch overhead

2 years agofix: argv, envp passing
Minep [Sat, 22 Jul 2023 22:17:28 +0000 (23:17 +0100)]
fix: argv, envp passing
chore: take care of some warnings

2 years agoedit readme
Minep [Fri, 21 Jul 2023 18:28:03 +0000 (19:28 +0100)]
edit readme

2 years agorefactor: full rewrite of signal feature
Minep [Fri, 21 Jul 2023 18:19:01 +0000 (19:19 +0100)]
refactor: full rewrite of signal feature
refactor: scheduler logic
refactor: (hhk) initial page mapper.
fix: remove debugging user access to kernel page
feat: make signal.h more posix compliant

2 years agorefactor: rewrite kernel's make script
Minep [Thu, 20 Jul 2023 21:07:37 +0000 (22:07 +0100)]
refactor: rewrite kernel's make script
fix: change linking script to match rewrited kernel makefile
fix: some recent exposed issues.

2 years agorefactor: restructure the user space stuff.
Minep [Mon, 17 Jul 2023 17:17:20 +0000 (18:17 +0100)]
refactor: restructure the user space stuff.
refactor: better isolation between kernel and user header file
refactor: rebuild user space make system

2 years agochore: fix almost *ALL* warnings.
Minep [Sun, 16 Jul 2023 23:05:34 +0000 (00:05 +0100)]
chore: fix almost *ALL* warnings.

2 years agorefactor: decouple the executable file implementations with execve functionality.
Minep [Sun, 16 Jul 2023 17:20:16 +0000 (18:20 +0100)]
refactor: decouple the executable file implementations with execve functionality.

2 years agoedit readme
Minep [Mon, 10 Jul 2023 20:53:58 +0000 (21:53 +0100)]
edit readme

2 years agorefactor: elf parsing utility and exec related
Minep [Mon, 10 Jul 2023 20:37:38 +0000 (21:37 +0100)]
refactor: elf parsing utility and exec related
refactor: ISA abstraction setup

2 years agofeat: refine symbolic link support.
Minep [Sun, 25 Jun 2023 15:47:55 +0000 (16:47 +0100)]
feat: refine symbolic link support.

2 years agofeat: dynamic boot medium probing and mounting
Minep [Sun, 18 Jun 2023 20:27:23 +0000 (21:27 +0100)]
feat: dynamic boot medium probing and mounting
fix: null pointer exception in usr/sh
fix: parameter passing by uwrapper

2 years agofeat: shell and signal demo as loadable user executable
Minep [Sun, 18 Jun 2023 18:08:07 +0000 (19:08 +0100)]
feat: shell and signal demo as loadable user executable
fix: incorrect offset when mmap segments
refactor: streamline loading of memory-mapped file
other minor refactorings

2 years agoMerge branch 'master' into prog-loader
Minep [Wed, 14 Jun 2023 21:34:07 +0000 (22:34 +0100)]
Merge branch 'master' into prog-loader

2 years agofix: the correct way to detect ahci LBA48 support
Minep [Wed, 14 Jun 2023 21:29:22 +0000 (22:29 +0100)]
fix: the correct way to detect ahci LBA48 support

2 years agofix: promote to gcc-12.2.0 (close #15)
Minep [Sat, 10 Jun 2023 20:08:17 +0000 (21:08 +0100)]
fix: promote to gcc-12.2.0 (close #15)

2 years agoupdate readme
Minep [Wed, 22 Feb 2023 19:05:55 +0000 (19:05 +0000)]
update readme

2 years agoMerge branch 'master' into prog-loader
Minep [Tue, 17 Jan 2023 10:30:13 +0000 (10:30 +0000)]
Merge branch 'master' into prog-loader

2 years agoMerge branch 'master' of github.com:Minep/lunaix-os
Minep [Tue, 17 Jan 2023 10:26:31 +0000 (10:26 +0000)]
Merge branch 'master' of github.com:Minep/lunaix-os

2 years agofix: sleeper issue #13
Minep [Tue, 17 Jan 2023 10:21:03 +0000 (10:21 +0000)]
fix: sleeper issue #13

2 years agofeat: brk and sbrk (mmap based)
Minep [Fri, 6 Jan 2023 00:47:54 +0000 (00:47 +0000)]
feat: brk and sbrk (mmap based)
feat: environ access
refactor: status code user space port

2 years agoupdate readmes
Minep [Wed, 4 Jan 2023 22:28:36 +0000 (22:28 +0000)]
update readmes
upload ELF related specification

2 years agofeat: closedir(2)
Minep [Wed, 4 Jan 2023 16:35:48 +0000 (16:35 +0000)]
feat: closedir(2)
regression: execve
fix: wrong signature for printf
fix: sys_readdir context misuse
fix: page fault handler: offset calculation for memory-mapped file
fix: (merged) interrupt reworks in favour of execve.
fix: mmap: gap fitting

2 years agoMerge branch 'interrupt-rework' into prog-loader
Minep [Wed, 4 Jan 2023 16:12:56 +0000 (16:12 +0000)]
Merge branch 'interrupt-rework' into prog-loader

2 years agofix: previous interrupt context lost after a nested interrupt
Minep [Wed, 4 Jan 2023 16:06:20 +0000 (16:06 +0000)]
fix: previous interrupt context lost after a nested interrupt
fix: disable function inlining optimization as it could potentially cause BUGS!

2 years agorefactor: cut off some bloats in intr_ctx
Minep [Wed, 4 Jan 2023 02:15:56 +0000 (02:15 +0000)]
refactor: cut off some bloats in intr_ctx

2 years agofeat: provide some libc routines only for testing
Minep [Mon, 2 Jan 2023 16:47:37 +0000 (16:47 +0000)]
feat: provide some libc routines only for testing
feat: ls
feat: readdir(3) for wrapping sys_readdir(2)
chore: clean ups

2 years agoregression: elf loading
Minep [Mon, 2 Jan 2023 14:25:22 +0000 (14:25 +0000)]
regression: elf loading

2 years agofeat: wrapper function for bootstraping user program
Minep [Sun, 1 Jan 2023 01:44:46 +0000 (01:44 +0000)]
feat: wrapper function for bootstraping user program
feat: user runtime library for writing user space program
wip: initd
refactor: separate user space code from kernel code (syscall and some inits)
refactor: rewrite makefile to make it more flexible and modular

2 years agofeat: heap support and re-worked
Minep [Sat, 31 Dec 2022 21:57:49 +0000 (21:57 +0000)]
feat: heap support and re-worked
refactor: re-worked user program bootstraping
refactor: mm_region interfacings
refactor: remove kalloc, as no longer needed.
regression: mmap, munmap

2 years agofeat: basic elf32 loader (only LOAD segment is supported)
Minep [Sat, 31 Dec 2022 01:26:10 +0000 (01:26 +0000)]
feat: basic elf32 loader (only LOAD segment is supported)
feat: execve(2)
feat: MAP_FIXED, MAP_FIXED_NOREPLACE
refactor: mem_map: improved arguments passing
refactor: mm_region: custom page init policy and managed region_release()
refactor: use mem_map to create user stack
chore: update READMEs

2 years agofeat: msync(2)
Minep [Thu, 29 Dec 2022 20:53:39 +0000 (20:53 +0000)]
feat: msync(2)
fix: sync mappings when destorying process
fix: regression on mmap(2)
refactor: rename PD_REFERENCE to VMS_SELF
refactor: rename PD_MOUNT_1 to VMS_MOUNT_1

2 years agorefactor: separate syscall interfaces from kernel space, into posix compliant structure.
Minep [Thu, 29 Dec 2022 01:03:17 +0000 (01:03 +0000)]
refactor: separate syscall interfaces from kernel space, into posix compliant structure.

2 years agoregression: mmap for fd
Minep [Wed, 28 Dec 2022 23:19:19 +0000 (23:19 +0000)]
regression: mmap for fd
fix: replace %ebp register to %esi for passing 5-th arg when switching to syscall dispatcher.
feat: support for anonymous mapping
refactor: mm_region interfaces
refactor: page fault handler clean up.
refactor: resolve cyclic dependencies between mm.h and fs.h
refactor: rename readdir to sys_readdir to distinguish readdir(3)
wip refactor: separating syscall definitions to userspace.

2 years agoMerge pull request #10 from jackwang0108/master
Lunaixsky [Sun, 11 Dec 2022 14:52:19 +0000 (14:52 +0000)]
Merge pull request #10 from jackwang0108/master

Add all-build tool

2 years agoadd all-build tool. Add qemu support, add configure option support
JackWang [Fri, 9 Dec 2022 15:48:56 +0000 (09:48 -0600)]
add all-build tool. Add qemu support, add configure option support

2 years agoMerge pull request #8 from Catrol-s-Forks/master
Lunaixsky [Thu, 8 Dec 2022 13:27:59 +0000 (13:27 +0000)]
Merge pull request #8 from Catrol-s-Forks/master

Update README.md for link

2 years agoUpdate README_en.md
常青园晚 [Thu, 8 Dec 2022 11:53:54 +0000 (19:53 +0800)]
Update README_en.md