Lunaixsky [Mon, 5 May 2025 00:29:33 +0000 (01:29 +0100)]
make rule for user header file install
+ and syscall header file auto generation
+ some clean up
Lunaixsky [Sun, 4 May 2025 18:33:51 +0000 (19:33 +0100)]
Fix file system racing and ext2 directory insertion (#58)
* fix: ext2 directory insertion; racing on inode create
use nesting lock for v_inode and v_dnode locking.
hold the lock on the parent directory upon creating inode
prevent contention across multiple process that partakes
similar actions
fix the edge case of dirent insertion with data block
boundary crossing.
fix the incorrect calculation between fsblock index and
ext2 data block/inode index.
new test case: fragfile - random file spammer
* add locks to the shared objects of ext2 fs
* fix missing locks in the vfs subsystem
* add locks to dnode and inode cache
* add locks to fdtable for resolving inter-threads contentions
* scale up the fragfile sample size
Lunaixsky [Sat, 3 May 2025 17:22:20 +0000 (18:22 +0100)]
fix page mounting contention (close #57)
Lunaixsky [Tue, 1 Apr 2025 19:08:48 +0000 (20:08 +0100)]
Multiuser, Capabilities and Access Controls (#54)
* basic user, group and capability housekeeping.
add usrscope for process-wise user management
implement {get,set}*{uid,euid,gid,egid,groups} syscalls
basic acl checking mechanism
move common syscall table to arch/generic.
* patch file systems with the acl checks
make sure the user scope is copied upon fork
* syscalls: chroot, fchmodat, fchownat, faccessat
enable access check in path walker
add default directory permission for ramfs and devfs
* release the dnode lock after EACCESS in path walk
make struct stats conforming to POSIX
minor tweaks stock shell environment for better look and feel
* allow specifiying access mode when creating twifs file node
twifs: refactor the interface for easy twimap/twifs export
cake: fix overflow of index guessing when freeing, causing false
positive and possibly failing double free assertion
Lunaixsky [Tue, 1 Apr 2025 13:30:06 +0000 (14:30 +0100)]
make log a bit verbose for some useful information
change the versioing scheme: major.[.minor.patch][.build_seq]
Lunaixsky [Mon, 31 Mar 2025 20:27:18 +0000 (21:27 +0100)]
reorganise the readme
Lunaixsky [Mon, 31 Mar 2025 17:20:29 +0000 (18:20 +0100)]
update readme introduction part, add demo screen-shot
Lunaixsky [Mon, 31 Mar 2025 16:39:41 +0000 (17:39 +0100)]
fix potens not being set in ttyFB* device
mkrootfs: ensure mkfs.* invoked with root privilege
qemu.py: put extra options before the generated ones
Lunaixsky [Sun, 16 Mar 2025 16:22:43 +0000 (16:22 +0000)]
refine the live_debug.sh, move gdb to new tmux window
add some informative logging output
Lunaixsky [Fri, 14 Mar 2025 01:41:06 +0000 (01:41 +0000)]
fix typos, some refinements
Lunaixsky [Fri, 14 Mar 2025 00:39:02 +0000 (00:39 +0000)]
update the readme
Lunaixsky [Mon, 27 Jan 2025 12:15:27 +0000 (12:15 +0000)]
Fix: stale dnode caching instance cause locked-up upon accessing (#52)
* demote dnode cache to superblock level
* refactor the vmnt and mnt_point semantics
* change hashing function for lowering standard deviation of key
distribution amongst small amount of buckets (<32)
* vfs: ref counter fix up
Lunaixsky [Sun, 15 Dec 2024 01:40:25 +0000 (01:40 +0000)]
Unifying External Interrupt System (#51)
* rework external irq system, introduce hierarchical irq
* add btrie_map() for allocating free slot, remove isrm
* rewrite the btrie key allocation algorithm for better uniformity
* optimize the tests makefiles, add unit tests for btrie key allocator
* add simple memory allocation monitor for checking leakage and usage
* reduce verbosity of unit test ouput, some clean up
* make irq specifier to be provided when assigining irq
* general fix around.
Lunaixsky [Thu, 28 Nov 2024 01:08:29 +0000 (01:08 +0000)]
Unit testing framework and devicetree framework refactoring (#50)
* re-write the fdt iterator and parsing procedure
* unit test framework and devtree testings
* add expect_* assertions, test statistics, more dt test cases
* basic.dts : basic dt property testing: trivial, simple prop_encoded,
mixed prop_encoded
* inheritence.dts : #address-cell, #size-cell and #interrupt-cell parent
inheritence test.
* regression fix on dt, add dt prop extractor api (dtpx)
* tests for interrupt node and rework dtpi api
* add tests for interrupt node, exercise interrupt mask and interrupt map
* redesign the dtpi api to make it simpler to use
* rename dt_node_* and dt_prop_* struct to dtn_* and dtp_* to make it
adhere to related functions
* struct dtspec: unified specifier-map representation
* add correpsond unit test.
* fix minor issues, integrate the test into main makefile
* api: dt_interrupt_at to query interrupt specifier at given location
* add unit test cases for interrupt node related test
* rewrite FDT iterator, enable in-place DT lookup
* add alloc-less iterator for /memory, /reserved-memory nodes
* unit tests for the rewrited iterators
* unit test for fdt-memscan
* fix detected issues
* fix indentations
Lunaixsky [Wed, 20 Nov 2024 00:49:12 +0000 (00:49 +0000)]
rewrite the device subsystem interfaces (#48)
* add a new initfn stage for decoupling, adjust loading orders
* promote x86 intc to proper device rather than init fn
* add devtree compatible driver manager
* fix some issues in the devtree implementation
* rewrite pci device model for peripherals
* introduce changeling, or morphable. with main purpose of managing and
decouple the objects that are passing around within the kernel,
especially in device subsystem, things getting even more chaos.
* rewrite the pci device model such that it:
1. provides unified way to export device driver, we completely remove
the use of EXPORT_PCI_DEVICE
2. better integration with devicetree assisted device initialisation
and configuration.
3. give the entire freedom to driver decide how to spawn their
struct device instance.
* re-organise the deivce_def to make the hooks more general and
universal.
* refactor device_def and device numbering
* refactor the declaration of device_def more intuitive, enhance
readbility
* rename the device capability into potens
* refactor the device numbering, using enum, remove the need of manually
maintain the number. New macros allow developer to focus only on the
name rather than prefixes/conventions.
* minor fixes.
* refactor the hwtimer/hwrtc with potens.
* load and init of hwtimer and hwrtc are now done through the potens.
* streamline the term dev creation by unifying with the potens.
* move the *.lst file to a dedicated directory
* minor cleanups
* glue the device objects into devfs using changelings.
* minor code cleanup
* cleanup: remove the lx_timer_context
* use safer method to resolve inode embedded device morpher
* rework the dtm and allow pattern based compat field matching
* add implementation for fast strlen and strnlen for x86
* use weak alias to decouple realm-specific impl. of hooks
* replace device interface with device vendor in devclass
* rename the weak to _weak for avoid accidential expansion
* enable small function inlining as default optimization
* move isrm_ivosalloc and isrm_ivexalloc to x86 specific
* add comment regarding the regular expr used by pattern matcher
Lunaixsky [Thu, 10 Oct 2024 22:39:07 +0000 (23:39 +0100)]
cherry pick device tree modifications from isa/arm64
+ squashed of:
a2e1b06 and
9293880
Lunaixsky [Tue, 8 Oct 2024 20:16:06 +0000 (21:16 +0100)]
move msi-related functionality to generic isrm
* msi-related functionality are now part of generic isrm, as message
based interrupt are actually de facto part of modern interrupt
infrastructure.
* move bindirq and bindiv to x86-specific extension of isrm.
* ldelf will check the architecture before proceed to read anything
other than elf-header.
* other minor tweaks
Lunaixsky [Sun, 29 Sep 2024 15:55:55 +0000 (16:55 +0100)]
add generic kremap for kernel remapping
* add generic utility to allocate pagetable from static pool for initial
mmu setup
* fix incorrect pte advancement in set_ptes_contig
* always dump the configured headers when performing `make config`
* add custom qemu trace event for logging pagefaults in x86
* refactor the generic parts of bstage.h to asm-generic/boot_stage.h
* make the rootfs accessible if `make root` is invoked directly from
sudo
Lunaixsky [Tue, 24 Sep 2024 18:09:53 +0000 (19:09 +0100)]
Code-base clean-up and refactoring (#47)
* clean up the cpu.h abstraction
* refactor the pte copy algorithm for per-vmr copy
* draw a line between sys/ and asm/; make use of generic arch
restructure the arch/* directory to differentiate the functionality
of sys/ and asm/. In which the former refer to arch-specific kernel
service; the latter refer to code related to low-level architectural
feature.
make use the arch/generic which will serve as a supplier of default
implementation, to allow sharing common code across different arch.
* fix a missing return statement in usr/test_pthread.c
* clean up redundant header files, add default for hwtimer selection
* add documentation on porting to other ISAs
* move asm/isrm to asm-generic for sharing the header
* remove redundancy in syscall numbering
Lunaixsky [Fri, 30 Aug 2024 23:53:01 +0000 (00:53 +0100)]
Boot framework rework (#45)
* remove need of grub and iso image booting
* adjust the build process and bootstrap procedure, to bypass the
need of boot from iso image
* feat: allow custom rootfs.
* feat: add script to package rootfs with default layout.
* fix: some left-over bugs in x86_32
* ref: change a typo
* add `init=...` kernel option, decouple the init location
* (multiboot) use address header to instruct multiboot compliance
to load our kernel, to give us more flexibility
* ref: make mkrootfs more flexible, by moving the rootfs structuring
to usr/makefile
* ref: some refectoring
* fix: old mount point not being recovered when mount failed
* fix deadlock when process killed while blocked by file io
* fix: deadlock when process killed while blocked by file io.
this bug is addressed somewhere in the past, however the latest
refactoring break the logic.
* fix: signal delivery does not check if the process being destroyed.
* fix: procvm_mount and unmount now simply return if current mm is
already the active one.
* fix: signal group delivery always deliver the current one, which is
not essentially true.
* fix: incorrect thread group being terminated during terminate_process
* fix: wake the blocked reader on line_in buffer when a signal is raised
by some control character.
* ref: some refectoring
* introduce bootmem to handle memory allocation at boot stage
* feat: bootmem is introduce to provide memory service before
lunaix's mm is avaliable. The implementation detail is
left to archiecture
* ref: we moved the preparation of boot_handoff after we have
setup the virtual memory, to remove abuse of .*.boot sections
* fix: remove the .bss.boot, it is not a good idea to have that
in the middle of address space.
* feat: add a reclaimable region that will automatically unmapped
after exiting the bootstrapping stage. All temporary stuff
that only matter during bootstrapping should go there.
* fix a statistical error in pmem usage stat
* ref: change u32_t to unsigned int
* dtb support (devicetre specification v0.4)
* ref: remove trailing spaces
* remap and load the dtb during kinit stage.
* adjust the memory map of x86_32 to make room for dtb
* injection of sanitized LOAD PHDRs for kernel to setup page tables
* feat: add a small program: elftool that give less verbose output
than readelf. This program relies purely on standard POSIX
library thus maximizing portability.
* manually planned program headers to make thing certain.
* remove iso packing and boot disk probing
* move -kernel/-append to autoqemu config
* dynamic high-memory setup based on linking time generated map
* fix: (vm) NX bit being lost due to incorrect pte attribute mask
* fix: (vm) instruction fetch permission issue. differentiate the
permission for intermediate level from leaf level.
* fix: unify all auto-generated data, now their exposed symbol
are starts with __autogen_
* update readme, clean up out-dated stuff
Minep [Sun, 25 Aug 2024 12:24:25 +0000 (13:24 +0100)]
optimize the menuconfig redrawing
Lunaixsky [Sun, 25 Aug 2024 00:55:17 +0000 (01:55 +0100)]
Menuconfig Implementation and auto-qemu refactoring (#44)
* unify the chardev backend definitions
* add --dry option for dry-running
* allow supply extra raw qemu options
* implement ncurses based tui framework
* basic lunamenu framework built on top libtui
* (libtui) add scrollable, list, textbox
* (menu) add listview, dialogue
* interface LunaConfig into menuconfig
* remove flickering when new context being added and redrawn
* add ability to navigate, edit the config node
* adjust the layout parameters
* some refactors
* add help dialogue
* layout refinement
* add <BACKSPACE> as hot key to navigate up level
* add confirmation dialogue for exiting
* refactors
* add user friendly alias to LConfig terms
* fix the focusing problem with textbox
* bypass the configuration for user program generation
* bypass the showing of config view during usr program generation, use
default value instead
* house keeping stuff
* add terminal dimension check and fallback to prompt based
* replenish the help messages
* fix: udiv64 is not used when doing u64 division
Lunaixsky [Wed, 14 Aug 2024 21:54:37 +0000 (22:54 +0100)]
Improve cake allocator's memory utilisation (#43)
* allow cake metadata to be separated and improve the utilisation
* add method to reclaim the freed cakes
* adjust threshold to make all valloc > 128 use non-embed pile
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
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.
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
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
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
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
Minep [Sun, 21 Jul 2024 20:30:14 +0000 (21:30 +0100)]
add pre-commit hooks to regulate things
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
Minep [Tue, 16 Jul 2024 23:55:33 +0000 (00:55 +0100)]
add mem-map for x86_64
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
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
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
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
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
Minep [Sun, 2 Jun 2024 18:00:59 +0000 (19:00 +0100)]
hot fix: remove outdated objcpy
Minep [Mon, 29 Apr 2024 18:51:50 +0000 (19:51 +0100)]
* fix an issue that execve attempts to parse directory as elf file.
Minep [Sat, 20 Apr 2024 10:20:28 +0000 (11:20 +0100)]
Merge branch 'master' of github.com:Minep/lunaix-os
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)
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>
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
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
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>
FFreestanding [Tue, 20 Feb 2024 16:00:16 +0000 (00:00 +0800)]
6-acpi_and_apic.md (#27)
Minep [Sun, 18 Feb 2024 17:28:12 +0000 (17:28 +0000)]
* Remove the debugging hack in procvm.c
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
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>
FFreestanding [Tue, 6 Feb 2024 10:38:55 +0000 (18:38 +0800)]
4-virtual_memory.md (#24)
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
FFreestanding [Mon, 22 Jan 2024 14:00:43 +0000 (22:00 +0800)]
2-setup_gdt.md (#22)
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>
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
Minep [Mon, 11 Dec 2023 01:00:23 +0000 (01:00 +0000)]
Merge branch 'master' of github.com:Minep/lunaix-os
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
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>
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
Minep [Sat, 9 Dec 2023 20:56:32 +0000 (20:56 +0000)]
feat: a better boot command line parser
fix: bugs in term interfacing
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
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
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.
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Minep [Sun, 20 Aug 2023 19:59:09 +0000 (20:59 +0100)]
update readme for more up-to-date information
chore: housekeeping stuff
Minep [Sun, 20 Aug 2023 16:14:13 +0000 (17:14 +0100)]
feat: kernel stack tracing
refactor: move cpu.h to arch specific
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
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
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
Minep [Thu, 10 Aug 2023 18:46:04 +0000 (19:46 +0100)]
refactor: organize all arch related files together.
refactor: better code templating
Minep [Tue, 25 Jul 2023 18:24:03 +0000 (19:24 +0100)]
refactor: decouple i386 specific instruction invocation
refactor: re-organize the directory structure
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
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
Minep [Sun, 23 Jul 2023 10:39:16 +0000 (11:39 +0100)]
refactor: Optimize the context switch overhead
Minep [Sat, 22 Jul 2023 22:17:28 +0000 (23:17 +0100)]
fix: argv, envp passing
chore: take care of some warnings
Minep [Fri, 21 Jul 2023 18:28:03 +0000 (19:28 +0100)]
edit readme
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
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.
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
Minep [Sun, 16 Jul 2023 23:05:34 +0000 (00:05 +0100)]
chore: fix almost *ALL* warnings.
Minep [Sun, 16 Jul 2023 17:20:16 +0000 (18:20 +0100)]
refactor: decouple the executable file implementations with execve functionality.
Minep [Mon, 10 Jul 2023 20:53:58 +0000 (21:53 +0100)]
edit readme
Minep [Mon, 10 Jul 2023 20:37:38 +0000 (21:37 +0100)]
refactor: elf parsing utility and exec related
refactor: ISA abstraction setup
Minep [Sun, 25 Jun 2023 15:47:55 +0000 (16:47 +0100)]
feat: refine symbolic link support.
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
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
Minep [Wed, 14 Jun 2023 21:34:07 +0000 (22:34 +0100)]
Merge branch 'master' into prog-loader
Minep [Wed, 14 Jun 2023 21:29:22 +0000 (22:29 +0100)]
fix: the correct way to detect ahci LBA48 support