Code-base clean-up and refactoring (#47)
authorLunaixsky <lunaixsky@qq.com>
Tue, 24 Sep 2024 18:09:53 +0000 (19:09 +0100)
committerGitHub <noreply@github.com>
Tue, 24 Sep 2024 18:09:53 +0000 (19:09 +0100)
* 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

151 files changed:
lunaix-os/.gitignore
lunaix-os/.vscode/c_cpp_properties.json [deleted file]
lunaix-os/.vscode/launch.json [deleted file]
lunaix-os/.vscode/tasks.json [deleted file]
lunaix-os/arch/LBuild
lunaix-os/arch/README.md
lunaix-os/arch/generic/LBuild [new file with mode: 0644]
lunaix-os/arch/generic/arch.c
lunaix-os/arch/generic/bootmem.c [moved from lunaix-os/arch/x86/boot/bootmem.c with 85% similarity]
lunaix-os/arch/generic/hart.c [deleted file]
lunaix-os/arch/generic/includes/asm-generic/isrm.h [moved from lunaix-os/includes/lunaix/generic/isrm.h with 100% similarity]
lunaix-os/arch/generic/includes/asm-generic/muldiv64.h [new file with mode: 0644]
lunaix-os/arch/generic/includes/sys-generic/bootmem.h [moved from lunaix-os/includes/lunaix/generic/bootmem.h with 100% similarity]
lunaix-os/arch/generic/includes/sys-generic/elf.h [moved from lunaix-os/arch/x86/includes/sys/exebi/elf.h with 88% similarity]
lunaix-os/arch/generic/includes/sys-generic/trace_arch.h [moved from lunaix-os/includes/lunaix/generic/trace_arch.h with 99% similarity]
lunaix-os/arch/generic/includes/sys/abi.h [deleted file]
lunaix-os/arch/generic/includes/sys/cpu.h [deleted file]
lunaix-os/arch/generic/includes/sys/failsafe.h [deleted file]
lunaix-os/arch/generic/includes/sys/gdbstub.h [deleted file]
lunaix-os/arch/generic/includes/sys/hart.h [deleted file]
lunaix-os/arch/generic/includes/sys/mm/memory.h [deleted file]
lunaix-os/arch/generic/includes/sys/mm/mempart.h [deleted file]
lunaix-os/arch/generic/includes/sys/mm/mm_defs.h [deleted file]
lunaix-os/arch/generic/includes/sys/mm/pagetable.h [deleted file]
lunaix-os/arch/generic/includes/sys/mm/physical.h [deleted file]
lunaix-os/arch/generic/includes/sys/mm/tlb.h [deleted file]
lunaix-os/arch/generic/includes/sys/muldiv64.h [deleted file]
lunaix-os/arch/generic/includes/sys/port_io.h [deleted file]
lunaix-os/arch/generic/includes/sys/trace.h [deleted file]
lunaix-os/arch/generic/mm/fault.c [deleted file]
lunaix-os/arch/generic/procvm.c [new file with mode: 0644]
lunaix-os/arch/generic/trace.c [new file with mode: 0644]
lunaix-os/arch/generic/vmutils.c [moved from lunaix-os/arch/generic/mm/mm.c with 84% similarity]
lunaix-os/arch/x86/LBuild
lunaix-os/arch/x86/arch.c
lunaix-os/arch/x86/boot/boot_helper.c
lunaix-os/arch/x86/boot/i386/init32.c
lunaix-os/arch/x86/boot/i386/kremap32.c
lunaix-os/arch/x86/boot/i386/prologue32.S
lunaix-os/arch/x86/boot/kpt_setup.c
lunaix-os/arch/x86/boot/mb_parser.c
lunaix-os/arch/x86/boot/x86_64/boot64.S
lunaix-os/arch/x86/boot/x86_64/init64.c
lunaix-os/arch/x86/boot/x86_64/kremap64.c
lunaix-os/arch/x86/boot/x86_64/prologue64.S
lunaix-os/arch/x86/exceptions/interrupt32.S
lunaix-os/arch/x86/exceptions/interrupt64.S
lunaix-os/arch/x86/exceptions/interrupts.c
lunaix-os/arch/x86/exceptions/intr_routines.c
lunaix-os/arch/x86/exceptions/isrdef.c
lunaix-os/arch/x86/exceptions/isrm.c
lunaix-os/arch/x86/hal/apic.c
lunaix-os/arch/x86/hal/apic_timer.c
lunaix-os/arch/x86/hal/cpu.c
lunaix-os/arch/x86/hal/ioapic.c
lunaix-os/arch/x86/hal/mc146818a.c
lunaix-os/arch/x86/hal/pci.c
lunaix-os/arch/x86/hal/ps2kbd.c
lunaix-os/arch/x86/hart.c
lunaix-os/arch/x86/hart32.c
lunaix-os/arch/x86/hart64.c
lunaix-os/arch/x86/includes/asm/abi.h [moved from lunaix-os/arch/x86/includes/sys/abi.h with 88% similarity]
lunaix-os/arch/x86/includes/asm/cpu.h [new file with mode: 0644]
lunaix-os/arch/x86/includes/asm/hart.h [moved from lunaix-os/arch/x86/includes/sys/hart.h with 97% similarity]
lunaix-os/arch/x86/includes/asm/mempart.h [moved from lunaix-os/arch/x86/includes/sys/mm/mempart.h with 55% similarity]
lunaix-os/arch/x86/includes/asm/mm_defs.h [moved from lunaix-os/arch/x86/includes/sys/mm/mm_defs.h with 100% similarity]
lunaix-os/arch/x86/includes/asm/muldiv64.h [moved from lunaix-os/arch/x86/includes/sys/muldiv64.h with 100% similarity]
lunaix-os/arch/x86/includes/asm/pagetable.h [moved from lunaix-os/arch/x86/includes/sys/mm/pagetable.h with 97% similarity]
lunaix-os/arch/x86/includes/asm/physical.h [moved from lunaix-os/arch/x86/includes/sys/mm/physical.h with 100% similarity]
lunaix-os/arch/x86/includes/asm/soc/apic.h [moved from lunaix-os/arch/x86/includes/sys/apic.h with 99% similarity]
lunaix-os/arch/x86/includes/asm/soc/ioapic.h [moved from lunaix-os/arch/x86/includes/sys/ioapic.h with 91% similarity]
lunaix-os/arch/x86/includes/asm/tlb.h [moved from lunaix-os/arch/x86/includes/sys/mm/tlb.h with 100% similarity]
lunaix-os/arch/x86/includes/asm/variants/abi32.h [moved from lunaix-os/arch/x86/includes/sys/abi32.h with 97% similarity]
lunaix-os/arch/x86/includes/asm/variants/abi64.h [moved from lunaix-os/arch/x86/includes/sys/abi64.h with 97% similarity]
lunaix-os/arch/x86/includes/asm/variants/interrupt32.S.inc [moved from lunaix-os/arch/x86/includes/sys/interrupt32.S.inc with 100% similarity]
lunaix-os/arch/x86/includes/asm/variants/interrupt64.S.inc [moved from lunaix-os/arch/x86/includes/sys/interrupt64.S.inc with 100% similarity]
lunaix-os/arch/x86/includes/asm/variants/mempart32.h [moved from lunaix-os/arch/x86/includes/sys/mm/mempart32.h with 100% similarity]
lunaix-os/arch/x86/includes/asm/variants/mempart64.h [moved from lunaix-os/arch/x86/includes/sys/mm/mempart64.h with 100% similarity]
lunaix-os/arch/x86/includes/asm/variants/pt_def32.h [moved from lunaix-os/arch/x86/includes/sys/mm/pt_def32.h with 100% similarity]
lunaix-os/arch/x86/includes/asm/variants/pt_def64.h [moved from lunaix-os/arch/x86/includes/sys/mm/pt_def64.h with 100% similarity]
lunaix-os/arch/x86/includes/asm/x86.h [moved from lunaix-os/arch/x86/includes/sys/x86_isa.h with 96% similarity]
lunaix-os/arch/x86/includes/asm/x86_cpu.h [moved from lunaix-os/arch/x86/includes/sys/cpu.h with 69% similarity]
lunaix-os/arch/x86/includes/asm/x86_crx.h [moved from lunaix-os/arch/x86/includes/sys/crx.h with 100% similarity]
lunaix-os/arch/x86/includes/asm/x86_ivs.h [moved from lunaix-os/arch/x86/includes/sys/vectors.h with 93% similarity]
lunaix-os/arch/x86/includes/asm/x86_pmio.h [moved from lunaix-os/arch/x86/includes/sys/port_io.h with 100% similarity]
lunaix-os/arch/x86/includes/linking/base_defs.ld.inc
lunaix-os/arch/x86/includes/sys/elf.h [new file with mode: 0644]
lunaix-os/arch/x86/includes/sys/gdbstub.h
lunaix-os/arch/x86/includes/sys/int_handler.h [deleted file]
lunaix-os/arch/x86/includes/sys/mm/memory.h [deleted file]
lunaix-os/arch/x86/mm/fault.c
lunaix-os/arch/x86/mm/gdt.c
lunaix-os/arch/x86/mm/tlb.c
lunaix-os/arch/x86/mm/vmutils.c
lunaix-os/arch/x86/syscall32.S
lunaix-os/arch/x86/syscall64.S
lunaix-os/arch/x86/syscall_nr.inc [new file with mode: 0644]
lunaix-os/hal/ahci/ahci.c
lunaix-os/hal/ahci/io_event.c
lunaix-os/hal/char/serial.c
lunaix-os/hal/char/uart/16x50_isa.c
lunaix-os/hal/char/uart/16x50_mmio.c
lunaix-os/hal/char/uart/16x50_pci.c
lunaix-os/hal/char/uart/16x50_pmio.c
lunaix-os/hal/gfxa/vga/vga.c
lunaix-os/hal/gfxa/vga/vga_rawtty.c
lunaix-os/includes/hal/ahci/ahci.h
lunaix-os/includes/lunaix/boot_generic.h
lunaix-os/includes/lunaix/compiler.h
lunaix-os/includes/lunaix/exebi/elf.h
lunaix-os/includes/lunaix/hart_state.h
lunaix-os/includes/lunaix/kpreempt.h
lunaix-os/includes/lunaix/mm/fault.h
lunaix-os/includes/lunaix/mm/mm.h
lunaix-os/includes/lunaix/mm/pagetable.h
lunaix-os/includes/lunaix/mm/physical.h
lunaix-os/includes/lunaix/mm/procvm.h
lunaix-os/includes/lunaix/mm/vmm.h
lunaix-os/includes/lunaix/mm/vmtlb.h
lunaix-os/includes/lunaix/spike.h
lunaix-os/includes/lunaix/trace.h
lunaix-os/kernel/block/blkbuf.c
lunaix-os/kernel/block/blkio.c
lunaix-os/kernel/block/blkpart_gpt.c
lunaix-os/kernel/boot_helper.c
lunaix-os/kernel/debug/gdbstub.c
lunaix-os/kernel/debug/trace.c
lunaix-os/kernel/exe/elf-generic/elfbfmt.c
lunaix-os/kernel/exe/elf-generic/ldelf.c
lunaix-os/kernel/exe/exec.c
lunaix-os/kernel/fs/iso9660/file.c
lunaix-os/kernel/fs/path_walk.c
lunaix-os/kernel/fs/twifs/twifs.c
lunaix-os/kernel/fs/twimap.c
lunaix-os/kernel/kinit.c
lunaix-os/kernel/mm/fault.c
lunaix-os/kernel/mm/mmap.c
lunaix-os/kernel/mm/procvm.c
lunaix-os/kernel/mm/region.c
lunaix-os/kernel/mm/vmap.c
lunaix-os/kernel/mm/vmm.c
lunaix-os/kernel/process/fork.c
lunaix-os/kernel/process/process.c
lunaix-os/kernel/process/sched.c
lunaix-os/kernel/process/signal.c
lunaix-os/kernel/process/thread.c
lunaix-os/kernel/spike.c
lunaix-os/live_debug.sh
lunaix-os/scripts/build-tools/integration/lunamenu.py
lunaix-os/scripts/makefile
lunaix-os/usr/test_pthread.c

index ea132c4df2b158c437be4988b1148cc6bc958c2d..ea16967ff3e01503e6c4b7a8ae3efdbf254ca73f 100644 (file)
@@ -28,4 +28,6 @@ scripts/*.tool
 __pycache__
 
 .config.json
 __pycache__
 
 .config.json
-.builder
\ No newline at end of file
+.builder
+
+.vscode
\ No newline at end of file
diff --git a/lunaix-os/.vscode/c_cpp_properties.json b/lunaix-os/.vscode/c_cpp_properties.json
deleted file mode 100644 (file)
index b315a23..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-{
-    "configurations": [
-        {
-            "name": "OS-DEV",
-            "includePath": [
-                "${workspaceFolder}/includes",
-                "${workspaceFolder}/includes/usr",
-                "${workspaceFolder}/usr/includes",
-                "${workspaceFolder}/arch/x86/includes",
-            ],
-            "compilerArgs": [
-                "-ffreestanding",
-                "-m32",
-                "-include .builder/configs.h"
-            ],
-            "defines": [],
-            "compilerPath": "/usr/bin/gcc",
-            "cStandard": "gnu99",
-            "intelliSenseMode": "gcc-x86"
-        },
-        {
-            "name": "OS-DEV64",
-            "includePath": [
-                "${workspaceFolder}/includes",
-                "${workspaceFolder}/includes/usr",
-                "${workspaceFolder}/usr/includes",
-                "${workspaceFolder}/arch/x86/includes",
-            ],
-            "compilerArgs": [
-                "-ffreestanding",
-                "-m64",
-                "-include .builder/configs.h"
-            ],
-            "defines": [],
-            "compilerPath": "/usr/bin/gcc",
-            "cStandard": "gnu99",
-            "intelliSenseMode": "gcc-x86"
-        }
-    ],
-    "version": 4
-}
\ No newline at end of file
diff --git a/lunaix-os/.vscode/launch.json b/lunaix-os/.vscode/launch.json
deleted file mode 100644 (file)
index 0a866ca..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-{
-    // 使用 IntelliSense 了解相关属性。 
-    // 悬停以查看现有属性的描述。
-    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
-    "version": "0.2.0",
-    "configurations": [
-        {
-            "type": "gdb",
-            "request": "attach",
-            "name": "LunaixOS",
-            "executable": "${workspaceRoot}/build/bin/kernel.bin",
-            "target": ":1234",
-            "remote": true,
-            "cwd": "${workspaceRoot}",
-            "valuesFormatting": "parseText",
-            "preLaunchTask": "Launch LunaixOS"
-        }
-    ]
-}
\ No newline at end of file
diff --git a/lunaix-os/.vscode/tasks.json b/lunaix-os/.vscode/tasks.json
deleted file mode 100644 (file)
index 88d846c..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-{
-    "version": "2.0.0",
-    "tasks": [
-        {
-            "label": "Launch LunaixOS",
-            "type": "shell",
-            "command": "make debug-qemu-vscode",
-            "isBackground": true,
-            "problemMatcher": {
-                "background": {
-                    "activeOnStart": true,
-                    "endsPattern": "^\\(qemu\\).*"
-                }
-            }
-        }
-    ]
-}
\ No newline at end of file
index 8617597bd3b0ce9b2a9145357cb2bfcfde862d06..703d6921761d430143348276221e2a9afbf44554 100644 (file)
@@ -1,3 +1,5 @@
+use("generic")
+
 use({
     config("arch"): {
         "i386": "x86",
 use({
     config("arch"): {
         "i386": "x86",
index df5349fb3655058b57050fd6034471c3fa94dd9b..68fa2a0ba1de46e9f27bf4ed9c3d390b56751ce1 100644 (file)
 
 This document briefly describe how to add support for other ISA
 
 
 This document briefly describe how to add support for other ISA
 
-## Adding Implementations
+## Introduction
 
 
-Lunaix provide bunch of headers that **MUST** be implemented.
+As of most modern operating system, Lunaix's abstraction layer allow
+a clean separation between regular kernel code and the
+architecture specific code, these parts defined as follow:
+  + kernel code: Provide the functionality of a kernel that do not assume 
+    anything other than the kernel basic service and feature. This part of
+    code is thus said to be architecture-agnostic.
+  + architecture specific code: Provide implementation of low-level operations
+    or features required by the aforementioned kernel kernel basic service and 
+    feature for them to function normally and expected.
 
 
-+ Follow the structure and derive the template header files according to
-  `arch/generic/includes`.
-  ! You **MUST** copy the header file and add your own
-  declaration & other stuffs.
-  ! You **MUST NOT** remove or modify the data structure,
-  function signature or any declaration that already in the template header
-  files unless stated explicitly.
-  ! Read the comment carefully, it may contains implementation recommendation
-  which is vital to the overall correctness.
+## General Structure
 
 
-+ Add implementation to function signature defined in header files under
-  `includes/lunaix/generic`
+Each architectural support is housed under the directory of 
+their respective name. For example, all support for x86 is
+placed under `x86/`. 
 
 
-+ Add implementation of syscall dispatching (Reference: `arhc/x86/syscall.S`)  
+Aside from this, a special architecture
+called `generic` is defined, which designed to be a fallback
+option for any features/operations that are not being implemented or does not required to be implemented in architecture-specific way. However, not all feature/operations
+have their respective fallback; In that case, presence of architectural support for these features/operations are mandatory.
 
 
-+ Add implementation of interrupt handler dispatching  (Reference:
-  `arhc/x86/exceptions/intrhnds.S`)  
+Regardless, a typical architecture support must be a valid derivation of the following subdirectory layout:
 
 
-+ Add implementation of context switching, signal handling. (Reference:
-  `arhc/x86/exceptions/interrupt.S`)  
-  **TODO: make this procedure more standalone**
+```
+<arch>/
+    includes/
+        asm/
+        linking/
+        sys/ 
+    ...
+    (anything you want)
+```
 
 
-## Preparing the Flows
+where:
 
 
-When system boot up, Lunaix start the execution from `start_`, and then the
-control flow will transfer to the `kinit.c::kernel_bootstrap`. A boot hand-over 
-context `struct boot_handoff*` must passed to the bootstrap procedure.
+  + `asm` define all assembly level headers. These header is
+    typically designated to perform low-level architectural
+    tasks such as register manipulation, MMU/TLB
+    maintainance, SoC resource managment, or context saving/restoring.
+  + `sys` define all headers that is related to some kernel 
+    service. These services, similar but unlike the **regular kernel code**, require architectural support or 
+    optimisation. For example, syscall interfacing or cpu state dumping for debugging purpose.
+  + `linking` contain linker scripts that describe the linking
+    procedure for linking the architectural support with other subsystem such that a valid kernel binary can be produced. There is no limit on how many linker script can be put under it, however, only one specific linker script will be taken into account when linking, more detail as follow.
 
 
-Before jumping to `kernel_bootstrap`, one
+An implementation is required to follow this structure and must implement all mandatory header file, as described in the following section.
 
 
-+ Must constructure a proper `struct boot_handoff` context.
-+ Must remap the kernel to architecturally favoured address range. 
-    **TODO: the algorithm for doing kernel remapping should be arch-agnostic**
-+ Must perform any essential CPU statet initialization, for example, setting up
-  address translation scheme, enable/disable ISA extensions, probing CPU/SOC
-  features.
 
 
-## Alternative Implementation
+## Implementation
+
+### Mandatory and Optional Features
+
+Lunaix provide bunch of headers that **MUST** be implemented in order to behave correctly.
+
+```
+includes/asm/cpu.h
+includes/asm-generic/isrm.h
+includes/asm/muldiv64.h
+includes/asm/hart.h
+includes/asm/mempart.h
+includes/asm/abi.h
+includes/asm/tlb.h
+includes/asm/pagetable.h
+
+includes/sys/syscall_utils.h
+includes/sys/failsafe.h
+includes/sys/gdbstub.h
+includes/sys-generic/elf.h
+```
+
+An implementation should copy these file out of `arch/x86`, replacing any `x86` specific function-body/structure-members/macros with the chosen architecture.
+
+Most headers located under `generic/` has default implementation and is designed to eliminate common code. The defaults can be optionally override, except for those with `fail()` as their only definition or those listed in above.
+
+### Preparing Linker Script
+
+Lunaix use CC's preprocessing system on creating modularised linker script. Such linker scripts in denoted with 'ldx' as extension in contrast to the genuine one. 
+
+There is no limit on the number of linker scripts present. However, the following list the mandatory linker scripts required for an architectural support, as these scripts are referenced by the main script.
+
++ `base_defs.ld.inc` Define the macros related to kernel 
+  binary structure, the following macros are mandatory:
+    + `LOAD_OFF` base physical address of kernel when loaded into memory by firmware.
+    + `PAGE_GRAN`  base page granule, used for section alignment
+    + `ENTRY_POINT` the entry point of kernel, where the firmware-kernel hand-off happened.
+    + `KEXEC_BASE` base virtual address of kernel, this define the boundary of kernel and user space.
++ `boot_secs.ldx` Define the sections used by boot code, these section should be normally used without virtual address relocation. **Important: Implementation must not define variable-sized section such as .bss**
+
+### Booting and Initialising
+
+Lunaix will always start the execution from entry point defined by `ENTRY_POINT` (see above section). A boot protocol might be invoked as earlier as possible in this stage. Such protocol defines the format and method to perform message exchange when firmware hand-over the control to the kernel. It is the implementation's responsibility for to decide whether such protocol is necessary and implement it accordingly.
+
+After the completion of architectural tasks defined in boot stage, implementation must hand-over the control to the architecture-agnostic kernel entry-point: `kernel_bootstrap`, together with the an architecture-agnostically defined boot message structure: `struct boot_handoff` as the only parameter taken by the entry-point. In this structure, the implementation must provide **either** the following information:
+
+1. `mem` sub-structure and pointer and length to the kernel command-line raw string.
+2. `dtb_pa`, physical pointer to the devicetree blob (dtb) placed in memory. Fields stated in #1 will be ignored if `dtb_pa` is non-zero.
+
+Implementation may also provide callback to `release` and `prepare` function pointer. Where the implementation-defined action can be performed before and after the kernel initialisation.
+
+### System-on-Chip Resources
+
+Most of the SoC resources such as interrupt controller can be abstracted away by some mandatory headers defined in `asm/`, or as a regular device driver integrated into the Lunaix device subsystem. However, not all SoC resources can be fit into the said framework. The following list the such resources:
+
++ **System Timer** 
+
+### Architectural Optimisation on klibc
 
 Most functions in `klibc` can be override by an architectural port. To achieve
 this, one just need to add definition of such function. This allow port to
 
 Most functions in `klibc` can be override by an architectural port. To achieve
 this, one just need to add definition of such function. This allow port to
diff --git a/lunaix-os/arch/generic/LBuild b/lunaix-os/arch/generic/LBuild
new file mode 100644 (file)
index 0000000..a8cbead
--- /dev/null
@@ -0,0 +1,9 @@
+headers("includes")
+
+sources([
+    "bootmem.c",
+    "trace.c",
+    "vmutils.c",
+    "procvm.c",
+    "arch.c",
+])
\ No newline at end of file
index ac0f0648fb9cc6ec7c188eeb0abcb5c52f0adc57..3e62e7b996f4b637843adaf014eb451ddd57ef4b 100644 (file)
@@ -1,8 +1,8 @@
-#include <lunaix/spike.h>
 #include <hal/hwtimer.h>
 #include <hal/hwtimer.h>
+#include <lunaix/spike.h>
 
 
-struct hwtimer*
+_default struct hwtimer*
 select_platform_timer()
 {
 select_platform_timer()
 {
-    fail("unimplemented");
+    fail("not implemented");
 }
\ No newline at end of file
 }
\ No newline at end of file
similarity index 85%
rename from lunaix-os/arch/x86/boot/bootmem.c
rename to lunaix-os/arch/generic/bootmem.c
index 388511883db4d86c34d2c566d7ed73c81c9858b1..9c067a2b94b19cfec88e0b05e08f57fd2ee81fb7 100644 (file)
@@ -1,4 +1,4 @@
-#include <lunaix/generic/bootmem.h>
+#include <sys-generic/bootmem.h>
 #include <lunaix/sections.h>
 #include <lunaix/spike.h>
 
 #include <lunaix/sections.h>
 #include <lunaix/spike.h>
 
@@ -7,7 +7,7 @@
 static reclaimable char bootmem_pool[BOOTMEM_SIZE];
 static unsigned int pos;
 
 static reclaimable char bootmem_pool[BOOTMEM_SIZE];
 static unsigned int pos;
 
-void*
+_default void*
 bootmem_alloc(unsigned int size)
 {
     ptr_t res;
 bootmem_alloc(unsigned int size)
 {
     ptr_t res;
@@ -18,14 +18,14 @@ bootmem_alloc(unsigned int size)
     pos += size;
 
     if (pos >= BOOTMEM_SIZE) {
     pos += size;
 
     if (pos >= BOOTMEM_SIZE) {
-        asm ("ud2");
+        spin();
         unreachable;
     }
 
     return (void*)res;
 }
 
         unreachable;
     }
 
     return (void*)res;
 }
 
-void
+_default void
 bootmem_free(void* ptr)
 {
     // not need to support, as they are all one-shot
 bootmem_free(void* ptr)
 {
     // not need to support, as they are all one-shot
diff --git a/lunaix-os/arch/generic/hart.c b/lunaix-os/arch/generic/hart.c
deleted file mode 100644 (file)
index 9c74bca..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-#include <lunaix/process.h>
-#include <lunaix/hart_state.h>
-#include <lunaix/mm/vmm.h>
-#include <klibc/string.h>
-
-bool
-install_hart_transition(ptr_t vm_mnt, struct hart_transition* tctx)
-{
-    return false;
-}
-
-void
-hart_prepare_transition(struct hart_transition* tctx, 
-                      ptr_t kstack_tp, ptr_t ustack_pt, 
-                      ptr_t entry, bool to_user) 
-{
-    fail("unimplemented");
-}
\ No newline at end of file
diff --git a/lunaix-os/arch/generic/includes/asm-generic/muldiv64.h b/lunaix-os/arch/generic/includes/asm-generic/muldiv64.h
new file mode 100644 (file)
index 0000000..fefc202
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef __LUNAIX_ARCH_MULDIV64_H
+#define __LUNAIX_ARCH_MULDIV64_H
+
+#include <lunaix/types.h>
+
+#ifdef CONFIG_ARCH_BITS_64
+static inline u64_t
+udiv64(u64_t n, unsigned int base)
+{
+    return n / base;
+}
+
+static inline unsigned int
+umod64(u64_t n, unsigned int base)
+{
+    return n % base;
+}
+#else
+#error "no generic muldiv64 for 32 bits arch"
+#endif
+
+
+#endif /* __LUNAIX_ARCH_MULDIV64_H */
similarity index 88%
rename from lunaix-os/arch/x86/includes/sys/exebi/elf.h
rename to lunaix-os/arch/generic/includes/sys-generic/elf.h
index 1ccf84a961625092fb668debe049b32e095e912d..36246a593007e1300f7b0eeb083ba2afbcdc6a7c 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef __LUNAIX_ARCH_ELF_H
-#define __LUNAIX_ARCH_ELF_H
+#ifndef __LUNAIX_ARCH_GENERIC_ELF_H
+#define __LUNAIX_ARCH_GENERIC_ELF_H
 
 #include <lunaix/types.h>
 
 
 #include <lunaix/types.h>
 
@@ -9,7 +9,7 @@
 #define ELFDATA2LSB 1
 #define ELFDATA2MSB 2
 
 #define ELFDATA2LSB 1
 #define ELFDATA2MSB 2
 
-#ifdef CONFIG_ARCH_X86_64
+#ifdef CONFIG_ARCH_BITS_64
 typedef unsigned long   elf_ptr_t;
 typedef unsigned short  elf_hlf_t;
 typedef unsigned long   elf_off_t;
 typedef unsigned long   elf_ptr_t;
 typedef unsigned short  elf_hlf_t;
 typedef unsigned long   elf_off_t;
@@ -45,7 +45,7 @@ struct elf_ehdr
 
 struct elf_phdr
 {
 
 struct elf_phdr
 {
-#ifdef CONFIG_ARCH_X86_64
+#ifdef CONFIG_ARCH_BITS_64
     elf_wrd_t p_type;
     elf_wrd_t p_flags;
     elf_off_t p_offset;
     elf_wrd_t p_type;
     elf_wrd_t p_flags;
     elf_off_t p_offset;
@@ -66,4 +66,4 @@ struct elf_phdr
 #endif
 };
 
 #endif
 };
 
-#endif /* __LUNAIX_ARCH_ELF_H */
+#endif /* __LUNAIX_ARCH_GENERIC_ELF_H */
similarity index 99%
rename from lunaix-os/includes/lunaix/generic/trace_arch.h
rename to lunaix-os/arch/generic/includes/sys-generic/trace_arch.h
index 384ac7cbc03e1fc522e123f1ab377acefff55b6b..83953d1fb1a9f2bc953f5a5e253c95d135e7e1fd 100644 (file)
@@ -11,5 +11,4 @@ trace_print_transition_full(struct hart_state* hstate);
 
 void
 trace_dump_state(struct hart_state* hstate);
 
 void
 trace_dump_state(struct hart_state* hstate);
-
 #endif /* __LUNAIX_TRACE_ARCH_H */
 #endif /* __LUNAIX_TRACE_ARCH_H */
diff --git a/lunaix-os/arch/generic/includes/sys/abi.h b/lunaix-os/arch/generic/includes/sys/abi.h
deleted file mode 100644 (file)
index bef0f5d..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-#ifndef __LUNAIX_ARCH_ABI_H
-#define __LUNAIX_ARCH_ABI_H
-
-#include <lunaix/types.h>
-
-#define stack_alignment 0
-
-#ifndef __ASM__
-#define align_stack(ptr) ((ptr) & stack_alignment)
-#define store_retval(retval) (void)
-
-#define store_retval_to(th, retval) (void)
-
-static inline void must_inline noret
-j_usr(ptr_t sp, ptr_t pc) 
-{
-
-}
-
-
-static inline void must_inline noret
-switch_context() {
-    unreachable;
-}
-
-#define push_arg1(stack_ptr, arg) (void)
-
-#define push_arg2(stack_ptr, arg1, arg2)                                       \
-    { }
-
-#define push_arg3(stack_ptr, arg1, arg2, arg3)                                 \
-    { }
-
-#define push_arg4(stack_ptr, arg1, arg2, arg3, arg4)                           \
-    { }
-
-
-static inline ptr_t must_inline
-abi_get_callframe()
-{
-    return 0;
-}
-
-static inline ptr_t
-abi_get_retaddr()
-{
-    return 0;
-}
-
-static inline ptr_t
-abi_get_retaddrat(ptr_t fp)
-{
-    return 0;
-}
-
-#endif
-#endif /* __LUNAIX_ABI_H */
-
diff --git a/lunaix-os/arch/generic/includes/sys/cpu.h b/lunaix-os/arch/generic/includes/sys/cpu.h
deleted file mode 100644 (file)
index 952a3de..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-#ifndef __LUNAIX_CPU_H
-#define __LUNAIX_CPU_H
-
-#include <lunaix/types.h>
-
-/**
- * @brief Get processor ID string
- *
- * @param id_out
- */
-void
-cpu_get_id(char* id_out);
-
-void
-cpu_trap_sched();
-
-void
-cpu_trap_panic(char* message);
-
-
-/**
- * @brief Load current processor state
- *
- * @return ptr_t
- */
-ptr_t
-cpu_ldstate();
-
-/**
- * @brief Load current processor config
- *
- * @return ptr_t
- */
-ptr_t
-cpu_ldconfig();
-
-/**
- * @brief Change current processor state
- *
- * @return ptr_t
- */
-void
-cpu_chconfig(ptr_t val);
-
-/**
- * @brief Change current virtual memory space
- *
- * @return ptr_t
- */
-void
-cpu_chvmspace(ptr_t val);
-
-void
-cpu_enable_interrupt();
-
-void
-cpu_disable_interrupt();
-
-void
-cpu_wait();
-
-/**
- * @brief Read exeception address
- *
- * @return ptr_t
- */
-ptr_t
-cpu_ldeaddr();
-
-
-#endif /* __LUNAIX_CPU_H */
diff --git a/lunaix-os/arch/generic/includes/sys/failsafe.h b/lunaix-os/arch/generic/includes/sys/failsafe.h
deleted file mode 100644 (file)
index 26020cd..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-#ifndef __LUNAIX_FAILSAFE_H
-#define __LUNAIX_FAILSAFE_H
-
-#define STACK_SANITY            0xbeefc0de
-
-#ifndef __ASM__
-
-#include <lunaix/types.h>
-
-static inline bool
-check_bootstack_sanity()
-{
-    return true;
-}
-
-static inline void must_inline noret
-failsafe_diagnostic() {
-    unreachable;
-}
-
-#endif
-
-#endif /* __LUNAIX_FAILSAFE_H */
diff --git a/lunaix-os/arch/generic/includes/sys/gdbstub.h b/lunaix-os/arch/generic/includes/sys/gdbstub.h
deleted file mode 100644 (file)
index 70f0df9..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-#ifndef __LUNAIX_ARCH_GDBSTUB_ARCH_H
-#define __LUNAIX_ARCH_GDBSTUB_ARCH_H
-
-#include "sys/hart.h"
-
-enum GDB_REGISTER
-{
-    // TODO add your registers
-    GDB_CPU_NUM_REGISTERS
-};
-
-struct gdb_state;
-
-void
-arch_gdbstub_setup_state(struct gdb_state* state, struct hart_state* hstate);
-
-void
-arch_gdbstub_save_regs(struct gdb_state* state, struct hart_state* hstate);
-
-void
-arch_gdbstub_restore_regs(struct gdb_state* state, struct hart_state* hstate);
-
-int
-gdb_sys_continue(struct gdb_state* state);
-
-int
-gdb_sys_step(struct gdb_state* state);
-
-#endif /* __LUNAIX_ARCH_GDBSTUB_ARCH_H */
\ No newline at end of file
diff --git a/lunaix-os/arch/generic/includes/sys/hart.h b/lunaix-os/arch/generic/includes/sys/hart.h
deleted file mode 100644 (file)
index e820608..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-#ifndef __LUNAIX_ARCH_HART_H
-#define __LUNAIX_ARCH_HART_H
-
-#ifndef __ASM__
-#include <lunaix/compiler.h>
-#include <sys/cpu.h>
-
-struct exec_param;
-
-struct regcontext
-{
-    
-} compact;
-
-struct hart_state
-{
-    
-} compact;
-
-struct exec_param
-{
-    struct hart_state* parent_state;
-} compact;
-
-ptr_t
-hart_pc(struct hart_state* state);
-
-ptr_t
-hart_sp(struct hart_state* state);
-
-bool
-kernel_context(struct hart_state* hstate);
-
-ptr_t
-hart_stack_frame(struct hart_state* hstate);
-
-int
-hart_vector_stamp(struct hart_state* hstate);
-
-unsigned int
-hart_ecause(struct hart_state* hstate);
-
-struct hart_state*
-hart_parent_state(struct hart_state* hstate);
-
-void
-hart_push_state(struct hart_state* p_hstate, struct hart_state* hstate);
-
-#endif
-
-#endif /* __LUNAIX_ARCH_HART_H */
diff --git a/lunaix-os/arch/generic/includes/sys/mm/memory.h b/lunaix-os/arch/generic/includes/sys/mm/memory.h
deleted file mode 100644 (file)
index 2bb4d65..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifndef __LUNAIX_ARCH_MEMORY_H
-#define __LUNAIX_ARCH_MEMORY_H
-
-#include <lunaix/mm/pagetable.h>
-#include <lunaix/mann_flags.h>
-
-static inline pte_attr_t
-translate_vmr_prot(unsigned int vmr_prot)
-{
-    return 0;
-}
-
-
-#endif /* __LUNAIX_ARCH_MEMORY_H */
diff --git a/lunaix-os/arch/generic/includes/sys/mm/mempart.h b/lunaix-os/arch/generic/includes/sys/mm/mempart.h
deleted file mode 100644 (file)
index 055da0c..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-#ifndef __LUNAIX_ARCH_MEMPART_H
-#define __LUNAIX_ARCH_MEMPART_H
-
-
-#define END_POINT(name) (name + name##_SIZE - 1)
-
-#define KSTACK_AREA 0
-#define KSTACK_AREA_SIZE 0
-#define KSTACK_AREA_END END_POINT(KSTACK_AREA)
-
-#define USR_EXEC 0
-#define USR_EXEC_SIZE 0
-#define USR_EXEC_END END_POINT(USR_EXEC)
-
-#define USR_MMAP 0
-#define USR_MMAP_SIZE 0
-#define USR_MMAP_END END_POINT(USR_MMAP)
-
-#define USR_STACK 0
-#define USR_STACK_SIZE 0
-#define USR_STACK_END END_POINT(USR_STACK)
-
-#define KERNEL_IMG 0
-#define KERNEL_IMG_SIZE 0
-#define KERNEL_IMG_END END_POINT(KERNEL_IMG)
-
-#define PG_MOUNT_1 0
-#define PG_MOUNT_1_SIZE 0
-#define PG_MOUNT_1_END END_POINT(PG_MOUNT_1)
-
-#define PG_MOUNT_2 0
-#define PG_MOUNT_2_SIZE 0
-#define PG_MOUNT_2_END END_POINT(PG_MOUNT_2)
-
-#define PG_MOUNT_3 0
-#define PG_MOUNT_3_SIZE 0
-#define PG_MOUNT_3_END END_POINT(PG_MOUNT_3)
-
-#define PG_MOUNT_4 0
-#define PG_MOUNT_4_SIZE 0
-#define PG_MOUNT_4_END END_POINT(PG_MOUNT_4)
-
-#define PG_MOUNT_VAR 0
-#define PG_MOUNT_VAR_SIZE 0
-#define PG_MOUNT_VAR_END END_POINT(PG_MOUNT_VAR)
-
-#define VMAP 0
-#define VMAP_SIZE 0
-#define VMAP_END END_POINT(VMAP)
-
-#define VMS_MOUNT_1 0
-#define VMS_MOUNT_1_SIZE 0
-#define VMS_MOUNT_1_END END_POINT(VMS_MOUNT_1)
-
-#endif
diff --git a/lunaix-os/arch/generic/includes/sys/mm/mm_defs.h b/lunaix-os/arch/generic/includes/sys/mm/mm_defs.h
deleted file mode 100644 (file)
index 6370963..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-#ifndef __LUNAIX_MM_DEFS_H
-#define __LUNAIX_MM_DEFS_H
-
-
-#include "mempart.h"
-#include "pagetable.h"
-
-#define KSTACK_PAGES            3
-#define KSTACK_SIZE             (KSTACK_PAGES * PAGE_SIZE)
-
-/*
-    Regardless architecture we need to draw the line very carefully, and must 
-    take the size of VM into account. In general, we aims to achieve 
-    "sufficiently large" of memory for kernel
-
-    In terms of x86_32:
-        * #768~1022 PTEs of PD      (0x00000000c0000000, ~1GiB)
-    
-    In light of upcomming x86_64 support (for Level 4&5 Paging):
-        * #510 entry of PML4        (0x0000ff0000000000, ~512GiB)
-        * #510 entry of PML5        (0x01fe000000000000, ~256TiB)
-*/
-// Where the kernel getting re-mapped.
-#define KERNEL_RESIDENT         0x0
-
-// Pages reserved for kernel image
-#define KEXEC_RSVD              16
-
-#define kernel_addr(addr)       (addr)
-
-#define to_kphysical(k_va)      ((ptr_t)(k_va))
-#define to_kvirtual(k_pa)       ((ptr_t)(k_pa))
-
-#endif /* __LUNAIX_MM_DEFS_H */
diff --git a/lunaix-os/arch/generic/includes/sys/mm/pagetable.h b/lunaix-os/arch/generic/includes/sys/mm/pagetable.h
deleted file mode 100644 (file)
index 8522a11..0000000
+++ /dev/null
@@ -1,318 +0,0 @@
-/**
- * @file pagetable.h
- * @author Lunaixsky (lunaxisky@qq.com)
- * @brief Generic (skeleton) definition for pagetable.h
- * @version 0.1
- * @date 2024-02-18
- * 
- * @copyright Copyright (c) 2024
- * 
- */
-
-#ifndef __LUNAIX_ARCH_PAGETABLE_H
-#define __LUNAIX_ARCH_PAGETABLE_H
-
-#include <lunaix/types.h>
-#include <lunaix/compiler.h>
-
-/* ******** Page Table Manipulation ******** */
-
-// Levels of page table to traverse for a single page walk
-#define _PTW_LEVEL          2
-
-#define _PAGE_BASE_SHIFT    12
-#define _PAGE_BASE_SIZE     ( 1UL << _PAGE_BASE_SHIFT )
-#define _PAGE_BASE_MASK     ( _PAGE_BASE_SIZE - 1)
-
-#define _PAGE_LEVEL_SHIFT   10
-#define _PAGE_LEVEL_SIZE    ( 1UL << _PAGE_LEVEL_SHIFT )
-#define _PAGE_LEVEL_MASK    ( _PAGE_LEVEL_SIZE - 1 )
-#define _PAGE_Ln_SIZE(n)    ( 1UL << (_PAGE_BASE_SHIFT + _PAGE_LEVEL_SHIFT * (_PTW_LEVEL - (n) - 1)) )
-
-// Note: we set VMS_SIZE = VMS_MASK as it is impossible
-//       to express 4Gi in 32bit unsigned integer
-
-#define VMS_MASK            ( -1UL )
-#define VMS_SIZE            VMS_MASK
-
-/* General size of a LnT huge page */
-
-#define L0T_SIZE            _PAGE_Ln_SIZE(0)
-#define L1T_SIZE            _PAGE_Ln_SIZE(1)
-#define L2T_SIZE            _PAGE_Ln_SIZE(1)
-#define L3T_SIZE            _PAGE_Ln_SIZE(1)
-#define LFT_SIZE            _PAGE_Ln_SIZE(1)
-
-/* General mask to get page offset of a LnT huge page */
-
-#define L0T_MASK            ( L0T_SIZE - 1 )
-#define L1T_MASK            ( L1T_SIZE - 1 )
-#define L2T_MASK            ( L2T_SIZE - 1 )
-#define L3T_MASK            ( L3T_SIZE - 1 )
-#define LFT_MASK            ( LFT_SIZE - 1 )
-
-/* Masks to get index of a LnTE */
-
-#define L0T_INDEX_MASK      ( VMS_MASK ^ L0T_MASK )
-#define L1T_INDEX_MASK      ( L0T_MASK ^ L1T_MASK )
-#define L2T_INDEX_MASK      ( L1T_MASK ^ L2T_MASK )
-#define L3T_INDEX_MASK      ( L2T_MASK ^ L3T_MASK )
-#define LFT_INDEX_MASK      ( L3T_MASK ^ LFT_MASK )
-
-#define PAGE_SHIFT          _PAGE_BASE_SHIFT
-#define PAGE_SIZE           _PAGE_BASE_SIZE
-#define PAGE_MASK           _PAGE_BASE_MASK
-
-#define LEVEL_SHIFT         _PAGE_LEVEL_SHIFT
-#define LEVEL_SIZE          _PAGE_LEVEL_SIZE
-#define LEVEL_MASK          _PAGE_LEVEL_MASK
-
-// max PTEs number
-#define MAX_PTEN            _PAGE_LEVEL_SIZE
-
-// max translation level supported
-#define MAX_LEVEL           _PTW_LEVEL
-
-
-/* ******** PTE Manipulation ******** */
-
-struct __pte {
-    unsigned int val;
-} align(4);
-
-#ifndef pte_t
-typedef struct __pte pte_t;
-#endif
-
-typedef unsigned int pfn_t;
-typedef unsigned int pte_attr_t;
-
-#define _PTE_P                  (0)
-#define _PTE_W                  (0)
-#define _PTE_U                  (0)
-#define _PTE_A                  (0)
-#define _PTE_D                  (0)
-#define _PTE_X                  (0)
-#define _PTE_R                  (0)
-
-#define _PTE_PROT_MASK          ( _PTE_W | _PTE_U | _PTE_X )
-
-#define KERNEL_PAGE             ( _PTE_P )
-#define KERNEL_EXEC             ( KERNEL_PAGE | _PTE_X )
-#define KERNEL_DATA             ( KERNEL_PAGE | _PTE_W  )
-#define KERNEL_RDONLY           ( KERNEL_PAGE )
-
-#define USER_PAGE               ( _PTE_P | _PTE_U )
-#define USER_EXEC               ( USER_PAGE | _PTE_X )
-#define USER_DATA               ( USER_PAGE | _PTE_W )
-#define USER_RDONLY             ( USER_PAGE )
-
-#define SELF_MAP                ( KERNEL_DATA | _PTE_WT | _PTE_CD )
-
-#define __mkpte_from(pte_val)   ((pte_t){ .val = (pte_val) })
-#define __MEMGUARD               0xdeadc0deUL
-
-#define null_pte                ( __mkpte_from(0) )
-#define guard_pte               ( __mkpte_from(__MEMGUARD) )
-#define pte_val(pte)            ( pte.val )
-
-
-static inline bool
-pte_isguardian(pte_t pte)
-{
-    return pte.val == __MEMGUARD;
-}
-
-static inline pte_t
-mkpte_prot(pte_attr_t prot)
-{
-    return null_pte;
-}
-
-static inline pte_t
-mkpte(ptr_t paddr, pte_attr_t prot)
-{
-    return null_pte;
-}
-
-static inline pte_t
-mkpte_root(ptr_t paddr, pte_attr_t prot)
-{
-    return null_pte;
-}
-
-static inline pte_t
-mkpte_raw(unsigned long pte_val)
-{
-    return null_pte;
-}
-
-static inline pte_t
-pte_setpaddr(pte_t pte, ptr_t paddr)
-{
-    return pte;
-}
-
-static inline ptr_t
-pte_paddr(pte_t pte)
-{
-    return 0;
-}
-
-static inline pte_t
-pte_setprot(pte_t pte, ptr_t prot)
-{
-    return pte;
-}
-
-static inline pte_attr_t
-pte_prot(pte_t pte)
-{
-    return 0;
-}
-
-static inline bool
-pte_isnull(pte_t pte)
-{
-    return !pte.val;
-}
-
-static inline pte_t
-pte_mkhuge(pte_t pte) 
-{
-    return pte;
-}
-
-static inline pte_t
-pte_mkvolatile(pte_t pte) 
-{
-    return pte;
-}
-
-static inline pte_t
-pte_mkroot(pte_t pte) 
-{
-    return pte;
-}
-
-static inline pte_t
-pte_usepat(pte_t pte) 
-{
-    return pte;
-}
-
-static inline bool
-pte_huge(pte_t pte) 
-{
-    return false;
-}
-
-static inline pte_t
-pte_mkloaded(pte_t pte) 
-{
-    return pte;
-}
-
-static inline pte_t
-pte_mkunloaded(pte_t pte) 
-{
-    return pte;
-}
-
-static inline bool
-pte_isloaded(pte_t pte) 
-{
-    return false;
-}
-
-static inline pte_t
-pte_mkwprotect(pte_t pte) 
-{
-    return pte;
-}
-
-static inline pte_t
-pte_mkwritable(pte_t pte) 
-{
-    return pte;
-}
-
-static inline bool
-pte_iswprotect(pte_t pte) 
-{
-    return false;
-}
-
-static inline pte_t
-pte_mkuser(pte_t pte) 
-{
-    return pte;
-}
-
-static inline pte_t
-pte_mkkernel(pte_t pte) 
-{
-    return pte;
-}
-
-static inline bool
-pte_allow_user(pte_t pte) 
-{
-    return false;
-}
-
-static inline pte_t
-pte_mkexec(pte_t pte)
-{
-    return pte;
-}
-
-static inline pte_t
-pte_mknonexec(pte_t pte)
-{
-    return pte;
-}
-
-static inline bool
-pte_isexec(pte_t pte)
-{
-    return false;
-}
-
-static inline pte_t
-pte_mkuntouch(pte_t pte) 
-{
-    return pte;
-}
-
-static inline bool
-pte_istouched(pte_t pte) 
-{
-    return false;
-}
-
-static inline pte_t
-pte_mkclean(pte_t pte) 
-{
-    return pte;
-}
-
-static inline bool
-pte_dirty(pte_t pte) 
-{
-    return false;
-}
-
-static inline void
-set_pte(pte_t* ptep, pte_t pte)
-{
-    ptep->val = pte.val;
-}
-
-static inline pte_t
-pte_at(pte_t* ptep) {
-    return *ptep;
-}
-
-
-#endif /* __LUNAIX_ARCH_PAGETABLE_H */
diff --git a/lunaix-os/arch/generic/includes/sys/mm/physical.h b/lunaix-os/arch/generic/includes/sys/mm/physical.h
deleted file mode 100644 (file)
index 2a2cc43..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifndef __LUNAIX_ARCH_PHYSICAL_H
-#define __LUNAIX_ARCH_PHYSICAL_H
-
-#include <lunaix/ds/llist.h>
-#include "mm_defs.h"
-
-#define PPLIST_STARTVM          VMAP
-
-struct ppage_arch
-{
-
-};
-
-#endif /* __LUNAIX_ARCH_PHYSICAL_H */
\ No newline at end of file
diff --git a/lunaix-os/arch/generic/includes/sys/mm/tlb.h b/lunaix-os/arch/generic/includes/sys/mm/tlb.h
deleted file mode 100644 (file)
index 49cc08b..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-#ifndef __LUNAIX_ARCH_TLB_H
-#define __LUNAIX_ARCH_TLB_H
-
-#include <lunaix/compiler.h>
-#include <lunaix/mm/procvm.h>
-#include <lunaix/mm/physical.h>
-
-/**
- * @brief Invalidate entries of all address spaces
- * 
- * @param asid 
- * @param addr 
- * @param npages 
- */
-void 
-tlb_flush_range(ptr_t addr, unsigned int npages);
-
-/**
- * @brief Invalidate entries of an address space identified
- *        by ASID
- * 
- * @param asid 
- * @param addr 
- * @param npages 
- */
-void 
-tlb_flush_asid_range(unsigned int asid, ptr_t addr, unsigned int npages);
-
-/**
- * @brief Invalidate an entry of kernel address spaces
- * 
- * @param asid 
- * @param addr 
- * @param npages 
- */
-void 
-tlb_flush_kernel(ptr_t addr);
-
-/**
- * @brief Invalidate entries of kernel address spaces
- * 
- * @param asid 
- * @param addr 
- * @param npages 
- */
-void 
-tlb_flush_kernel_ranged(ptr_t addr, unsigned int npages);
-
-/**
- * @brief Invalidate an entry within a process memory space
- * 
- * @param asid 
- * @param addr 
- * @param npages 
- */
-void
-tlb_flush_mm(struct proc_mm* mm, ptr_t addr);
-
-/**
- * @brief Invalidate entries within a process memory space
- * 
- * @param asid 
- * @param addr 
- * @param npages 
- */
-void
-tlb_flush_mm_range(struct proc_mm* mm, ptr_t addr, unsigned int npages);
-
-/**
- * @brief Invalidate an entry within a vm region
- * 
- * @param asid 
- * @param addr 
- * @param npages 
- */
-void
-tlb_flush_vmr(struct mm_region* vmr, ptr_t va);
-
-/**
- * @brief Invalidate all entries within a vm region
- * 
- * @param asid 
- * @param addr 
- * @param npages 
- */
-void
-tlb_flush_vmr_all(struct mm_region* vmr);
-
-/**
- * @brief Invalidate entries within a vm region
- * 
- * @param asid 
- * @param addr 
- * @param npages 
- */
-void
-tlb_flush_vmr_range(struct mm_region* vmr, ptr_t addr, unsigned int npages);
-
-#endif /* __LUNAIX_VMTLB_H */
diff --git a/lunaix-os/arch/generic/includes/sys/muldiv64.h b/lunaix-os/arch/generic/includes/sys/muldiv64.h
deleted file mode 100644 (file)
index 2f4f1fd..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef __LUNAIX_ARCH_MULDIV64_H
-#define __LUNAIX_ARCH_MULDIV64_H
-
-
-#include <lunaix/spike.h>
-#include <lunaix/types.h>
-
-u64_t
-udiv64(u64_t n, unsigned int base);
-
-unsigned int
-umod64(u64_t n, unsigned int base);
-
-
-#endif /* __LUNAIX_ARCH_MULDIV64_H */
diff --git a/lunaix-os/arch/generic/includes/sys/port_io.h b/lunaix-os/arch/generic/includes/sys/port_io.h
deleted file mode 100644 (file)
index 09f3adf..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-#ifndef __LUNAIX_ARCH_PORT_IO_H
-#define __LUNAIX_ARCH_PORT_IO_H
-
-#include <lunaix/types.h>
-
-static inline u8_t
-port_rdbyte(int port)
-{
-    return 0;
-}
-
-static inline void
-port_rdbytes(int port, void* addr, int cnt)
-{
-    return;
-}
-
-static inline u16_t
-port_rdword(int port)
-{
-    return 0;
-}
-
-static inline void
-port_rdwords(int port, void* addr, int cnt)
-{
-    asm volatile("cld\n"
-                 "repne\n"
-                 "insw"
-                 : "=D"(addr), "=c"(cnt)
-                 : "d"(port), "0"(addr), "1"(cnt)
-                 : "memory", "cc");
-}
-
-static inline u32_t
-port_rddword(int port)
-{
-    return 0;
-}
-
-static inline void
-port_rddwords(int port, void* addr, int cnt)
-{
-    return;
-}
-
-static inline void
-port_wrbyte(int port, u8_t data)
-{
-    return;
-}
-
-static inline void
-port_wrbytes(int port, const void* addr, int cnt)
-{
-    return;
-}
-
-static inline void
-port_wrword(int port, u16_t data)
-{
-    return;
-}
-
-static inline void
-port_wrwords(int port, const void* addr, int cnt)
-{
-    return;
-}
-
-static inline void
-port_wrdwords(int port, const void* addr, int cnt)
-{
-    return;
-}
-
-static inline void
-port_wrdword(int port, u32_t data)
-{
-    return;
-}
-
-static inline void
-port_delay(int counter)
-{
-    return;
-}
-
-#endif /* __LUNAIX_ARCH_PORT_IO_H */
diff --git a/lunaix-os/arch/generic/includes/sys/trace.h b/lunaix-os/arch/generic/includes/sys/trace.h
deleted file mode 100644 (file)
index 17a39d7..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-#ifndef __LUNAIX_ARCH_TRACE_H
-#define __LUNAIX_ARCH_TRACE_H
-
-#include <lunaix/types.h>
-
-static inline bool 
-arch_valid_fp(ptr_t ptr) {
-    return false;
-}
-
-#endif /* __LUNAIX_ARCH_TRACE_H */
diff --git a/lunaix-os/arch/generic/mm/fault.c b/lunaix-os/arch/generic/mm/fault.c
deleted file mode 100644 (file)
index dd45ee9..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#include <lunaix/mm/fault.h>
-
-bool
-__arch_prepare_fault_context(struct fault_context* fault)
-{
-    return false;
-}
\ No newline at end of file
diff --git a/lunaix-os/arch/generic/procvm.c b/lunaix-os/arch/generic/procvm.c
new file mode 100644 (file)
index 0000000..91c4845
--- /dev/null
@@ -0,0 +1,36 @@
+#include <lunaix/mm/procvm.h>
+#include <lunaix/mm/pagetable.h>
+#include <lunaix/mm/page.h>
+
+_default void
+procvm_link_kernel(ptr_t dest_mnt)
+{
+    pte_t *ptep_smx, *src_smx;
+    struct leaflet* leaflet;
+    unsigned int i;
+    
+    i = va_level_index(KERNEL_RESIDENT, L0T_SIZE);
+    ptep_smx = mkl1tep_va(VMS_SELF, dest_mnt);
+    src_smx  = mkl0tep_va(VMS_SELF, 0);
+
+    for (; i < LEVEL_SIZE; i++)
+    {
+        pte_t* ptep = &ptep_smx[i];
+        pte_t  pte  = pte_at(&src_smx[i]);
+        if (lntep_implie_vmnts(ptep, L0T_SIZE)) {
+            continue;
+        }
+
+        // sanity check
+        leaflet = pte_leaflet_aligned(pte);
+        assert(leaflet_refcount(leaflet) > 0);
+
+        set_pte(ptep, pte);
+    }
+}
+
+_default void
+procvm_unlink_kernel()
+{
+    // nothing to do here.
+}
\ No newline at end of file
diff --git a/lunaix-os/arch/generic/trace.c b/lunaix-os/arch/generic/trace.c
new file mode 100644 (file)
index 0000000..e2bc2bd
--- /dev/null
@@ -0,0 +1,21 @@
+#include <lunaix/trace.h>
+
+#include <sys-generic/trace_arch.h>
+
+_default void
+trace_print_transistion_short(struct hart_state* hstate)
+{
+    trace_log("<not implemented>");
+}
+
+_default void
+trace_print_transition_full(struct hart_state* hstate)
+{
+    trace_log("<not implemented>");
+}
+
+_default void
+trace_dump_state(struct hart_state* hstate)
+{
+    trace_log("<not implemented>");
+}
\ No newline at end of file
similarity index 84%
rename from lunaix-os/arch/generic/mm/mm.c
rename to lunaix-os/arch/generic/vmutils.c
index 7f361b0359d843b384c43d5c0647d8a183948fef..8fc0d820cab2d72c210fb6b3b18d337e06bbb984 100644 (file)
@@ -1,20 +1,20 @@
 #include <lunaix/mm/pagetable.h>
 #include <lunaix/mm/page.h>
 
 #include <lunaix/mm/pagetable.h>
 #include <lunaix/mm/page.h>
 
-struct leaflet*
+_default struct leaflet*
 dup_leaflet(struct leaflet* leaflet)
 {
     fail("unimplemented");
 }
 
 dup_leaflet(struct leaflet* leaflet)
 {
     fail("unimplemented");
 }
 
-void
+_default void
 pmm_arch_init_pool(struct pmem* memory)
 {
     fail("unimplemented");
 }
 
 pmm_arch_init_pool(struct pmem* memory)
 {
     fail("unimplemented");
 }
 
-ptr_t
+_default ptr_t
 pmm_arch_init_remap(struct pmem* memory, struct boot_handoff* bctx)
 {
     fail("unimplemented");
 pmm_arch_init_remap(struct pmem* memory, struct boot_handoff* bctx)
 {
     fail("unimplemented");
-}
\ No newline at end of file
+}
index cb3e7816abd7313b90398aa240c1aada1681550c..9ae21459312017b2927ed1f986e524d25feebc81 100644 (file)
@@ -12,7 +12,6 @@ sources([
     "boot/mb_parser.c",
     "boot/kpt_setup.c",
     "boot/boot_helper.c",
     "boot/mb_parser.c",
     "boot/kpt_setup.c",
     "boot/boot_helper.c",
-    "boot/bootmem.c"
 ])
 
 sources([
 ])
 
 sources([
index 988f97654a4a25cc9beda371425b463da175898e..533ded95c0d398c099a334bb6a1d0bbbfebc07c6 100644 (file)
@@ -1,12 +1,11 @@
 #include <hal/hwtimer.h>
 
 #include <hal/hwtimer.h>
 
-#include <lunaix/generic/isrm.h>
+#include <asm-generic/isrm.h>
 #include <lunaix/spike.h>
 #include <lunaix/process.h>
 
 #include <lunaix/spike.h>
 #include <lunaix/process.h>
 
-#include "sys/int_handler.h"
-#include "sys/x86_isa.h"
-#include "sys/hart.h"
+#include "asm/x86.h"
+#include "asm/hart.h"
 
 #include "hal/apic_timer.h"
 
 
 #include "hal/apic_timer.h"
 
@@ -41,7 +40,7 @@ select_platform_timer()
 
     // TODO select alternatives...
 
 
     // TODO select alternatives...
 
-    panick("no timer to use.");
+    fail("no timer to use.");
 }
 
 void
 }
 
 void
index 3b7b4376e76d328ada1d7a6045b9e770d879ddf3..88ab02592a6ffedc898be07319b788e07ef72208 100644 (file)
@@ -3,10 +3,10 @@
 #include <lunaix/mm/pmm.h>
 #include <lunaix/spike.h>
 #include <lunaix/sections.h>
 #include <lunaix/mm/pmm.h>
 #include <lunaix/spike.h>
 #include <lunaix/sections.h>
-#include <lunaix/generic/bootmem.h>
 
 
-#include <sys/mm/mm_defs.h>
+#include <asm/mm_defs.h>
 #include <sys/boot/bstage.h>
 #include <sys/boot/bstage.h>
+#include <sys-generic/bootmem.h>
 
 #ifdef CONFIG_ARCH_X86_64
 
 
 #ifdef CONFIG_ARCH_X86_64
 
index 0d0615f80c5877e5482b44571328fd663f0ab3fe..db24406063cc21c49d86dcad5713a1442fda08be 100644 (file)
@@ -1,6 +1,5 @@
 #include "sys/boot/archinit.h"
 #include "sys/boot/archinit.h"
-#include "sys/crx.h"
-#include "sys/cpu.h"
+#include "asm/x86_cpu.h"
 
 ptr_t __multiboot_addr boot_data;
 
 
 ptr_t __multiboot_addr boot_data;
 
index e7ff12252c2f84aefe2af89b5fe3e42067d98ac9..eac579315acd89981dfb4fdbf23427240c5c32e1 100644 (file)
@@ -5,7 +5,7 @@
 #include <lunaix/sections.h>
 
 #include <sys/boot/bstage.h>
 #include <lunaix/sections.h>
 
 #include <sys/boot/bstage.h>
-#include <sys/mm/mm_defs.h>
+#include <asm/mm_defs.h>
 
 #define PF_X 0x1
 #define PF_W 0x2
 
 #define PF_X 0x1
 #define PF_W 0x2
index 56ceb9a6102f15f40f258f8bb035368c0f185b10..463118f92c5ea44173d25c5fcf7296104a059e40 100644 (file)
@@ -1,7 +1,7 @@
 /* 高半核入口点 - 0xC0000000 */
 
 #define __ASM__
 /* 高半核入口点 - 0xC0000000 */
 
 #define __ASM__
-#include <sys/abi.h>
+#include <asm/abi.h>
 #include <sys/failsafe.h>
 
 .section .bss.kstack
 #include <sys/failsafe.h>
 
 .section .bss.kstack
index ebcbc0e3181cb824d36d85bdb41e812ed4ef8244..535ad83ca42bf3520bcbff57c97a99e013301f30 100644 (file)
@@ -4,7 +4,7 @@
 #include <lunaix/compiler.h>
 
 #include <sys/boot/bstage.h>
 #include <lunaix/compiler.h>
 
 #include <sys/boot/bstage.h>
-#include <sys/mm/mm_defs.h>
+#include <asm/mm_defs.h>
 
 
 ptr_t boot_text
 
 
 ptr_t boot_text
index f38d7030aebbb0670c52df62aaac17d36b345994..595b5192ffd4a4d19a81c504b1e66cff205a6a1a 100644 (file)
@@ -1,11 +1,12 @@
 #define __BOOT_CODE__
 
 #include <lunaix/boot_generic.h>
 #define __BOOT_CODE__
 
 #include <lunaix/boot_generic.h>
-#include <lunaix/generic/bootmem.h>
 
 #include <sys/boot/bstage.h>
 #include <sys/boot/multiboot.h>
 
 #include <sys/boot/bstage.h>
 #include <sys/boot/multiboot.h>
-#include <sys/mm/mempart.h>
+#include <sys-generic/bootmem.h>
+
+#include <asm/mempart.h>
 
 #include <klibc/string.h>
 
 
 #include <klibc/string.h>
 
index 6cd1fbb4ecd75a4d6b12138ae743929c58499789..382cba247ae706e2ba2b07bf38ef3f9486dd3fe7 100644 (file)
@@ -4,7 +4,7 @@
 #include "sys/boot/multiboot.S.inc"
 #endif
 
 #include "sys/boot/multiboot.S.inc"
 #endif
 
-#include "sys/mm/mempart64.h"
+#include "asm/variants/mempart64.h"
 
 .section .boot.data
     .align 8
 
 .section .boot.data
     .align 8
index ac2c023399973cbfb1c58e120fae9777e0267ad1..ad5de8585500700a5d5ea70ac851c964850f2ee1 100644 (file)
@@ -1,6 +1,5 @@
 #include "sys/boot/archinit.h"
 #include "sys/boot/archinit.h"
-#include "sys/crx.h"
-#include "sys/cpu.h"
+#include "asm/x86_cpu.h"
 
 ptr_t __multiboot_addr boot_data;
 
 
 ptr_t __multiboot_addr boot_data;
 
index 4471398a4b656be99950fa16e50ac073acc631de..4da66fc4f2243e211562b6cf7ed942652f3cbe37 100644 (file)
@@ -5,7 +5,7 @@
 #include <lunaix/sections.h>
 
 #include <sys/boot/bstage.h>
 #include <lunaix/sections.h>
 
 #include <sys/boot/bstage.h>
-#include <sys/mm/mm_defs.h>
+#include <asm/mm_defs.h>
 
 #define RSVD_PAGES 32
 
 
 #define RSVD_PAGES 32
 
index 6fb7236acb9ee861a19cd7d0d0ffef337544a55d..8088d4a5eeef0adb230358cd1d5e273520a28600 100644 (file)
@@ -1,7 +1,7 @@
 /* 高半核入口点 - 0xC0000000 */
 
 #define __ASM__
 /* 高半核入口点 - 0xC0000000 */
 
 #define __ASM__
-#include <sys/abi.h>
+#include <asm/abi.h>
 #include <sys/failsafe.h>
 
 .section .bss.kstack
 #include <sys/failsafe.h>
 
 .section .bss.kstack
index 52f3ad42f93881cbb91333501d29da84a3619e43..6eb5235aca9a55e68db9f3ed57780396f5668743 100644 (file)
@@ -1,7 +1,7 @@
 #define __ASM__
 #define __ASM__
-#include <sys/hart.h>
-#include <sys/abi.h>
-#include <sys/interrupt32.S.inc>
+#include <asm/hart.h>
+#include <asm/abi.h>
+#include <asm/variants/interrupt32.S.inc>
 
 #include <lunaix/syscall.h>
 
 
 #include <lunaix/syscall.h>
 
index 356de950df46dc6c2b2ca4261a015e0a6fee3d27..9a5c9498ec4cde6271f39f0072a6794bcb29eaa1 100644 (file)
@@ -1,7 +1,7 @@
 #define __ASM__
 #define __ASM__
-#include <sys/hart.h>
-#include <sys/abi.h>
-#include <sys/interrupt64.S.inc>
+#include <asm/hart.h>
+#include <asm/abi.h>
+#include <asm/variants/interrupt64.S.inc>
 
 #include <lunaix/syscall.h>
 
 
 #include <lunaix/syscall.h>
 
index 9d127ba5c582b0619439245a675afd7912d1e875..6a9ff812425f4436d5793db505bdb489dee8d354 100644 (file)
@@ -1,11 +1,8 @@
-#include <sys/cpu.h>
-#include <sys/int_handler.h>
-#include <sys/hart.h>
-#include "sys/x86_isa.h"
+#include <asm/hart.h>
+#include "asm/x86.h"
 
 
-#include "sys/x86_isa.h"
+#include <asm-generic/isrm.h>
 
 
-#include <lunaix/generic/isrm.h>
 #include <lunaix/mm/vmm.h>
 #include <lunaix/process.h>
 #include <lunaix/sched.h>
 #include <lunaix/mm/vmm.h>
 #include <lunaix/process.h>
 #include <lunaix/sched.h>
index d355927dd2b83851a052dbb9532b0153fc1ae669..8bc1ca51f202d4504ebb38799e8421a81f4ced3c 100644 (file)
@@ -1,6 +1,6 @@
-#include <sys/hart.h>
+#include <asm/hart.h>
 
 
-#include <lunaix/generic/isrm.h>
+#include <asm-generic/isrm.h>
 #include <lunaix/process.h>
 #include <lunaix/sched.h>
 #include <lunaix/spike.h>
 #include <lunaix/process.h>
 #include <lunaix/sched.h>
 #include <lunaix/spike.h>
@@ -10,8 +10,8 @@
 
 #include <klibc/strfmt.h>
 
 
 #include <klibc/strfmt.h>
 
-#include "sys/apic.h"
-#include <sys/int_handler.h>
+#include "asm/soc/apic.h"
+#include "asm/x86.h"
 
 LOG_MODULE("INTR")
 
 
 LOG_MODULE("INTR")
 
index 23c80b0b9b798648de3d0cfceb07d3e4fe787b7c..c40ee1fbbd41e93fee18c05aab4e1f37a6327d1d 100644 (file)
@@ -1,9 +1,8 @@
 /* Generated from i386_isrdef.c.j2. Do NOT modify */
 
 #include <lunaix/types.h>
 /* Generated from i386_isrdef.c.j2. Do NOT modify */
 
 #include <lunaix/types.h>
-#include "sys/int_handler.h"
-#include "sys/vectors.h"
-#include "sys/x86_isa.h"
+#include "asm/x86_ivs.h"
+#include "asm/x86.h"
 
 #define IDT_INTERRUPT 0x70
 #define IDT_ATTR(dpl, type) (((type) << 5) | ((dpl & 3) << 13) | (1 << 15))
 
 #define IDT_INTERRUPT 0x70
 #define IDT_ATTR(dpl, type) (((type) << 5) | ((dpl & 3) << 13) | (1 << 15))
index dcd576aad1c5f177a873c8e45295e91b22d48973..dea130ccd546db6a13e54a9c19b5914c262ae536 100644 (file)
@@ -1,10 +1,10 @@
-#include <lunaix/generic/isrm.h>
 #include <lunaix/spike.h>
 #include <lunaix/owloysius.h>
 #include <lunaix/spike.h>
 #include <lunaix/owloysius.h>
+#include <asm-generic/isrm.h>
 
 
-#include "sys/x86_isa.h"
-#include "sys/ioapic.h"
-#include "sys/apic.h"
+#include "asm/x86.h"
+#include "asm/soc/ioapic.h"
+#include "asm/soc/apic.h"
 
 /*
     total: 256 ivs
 
 /*
     total: 256 ivs
index 34b243eed6b0ce12f8b28116f9620b23b877f941..ddc2e31ef2471557122b8b6ddb4ab11d0b7b68bd 100644 (file)
@@ -9,11 +9,11 @@
  *
  */
 
  *
  */
 
-#include "sys/x86_isa.h"
-#include <sys/cpu.h>
+#include "asm/x86.h"
+#include "asm/x86_cpu.h"
 
 
-#include "sys/apic.h"
-#include <sys/hart.h>
+#include "asm/soc/apic.h"
+#include <asm/hart.h>
 
 #include <lunaix/mm/mmio.h>
 #include <lunaix/spike.h>
 
 #include <lunaix/mm/mmio.h>
 #include <lunaix/spike.h>
index 9ea0be66f17538c9dff2bcef57ffe2cc91a57048..eae4c3feb76391ff1bf518520cc865ac9b0f9228 100644 (file)
@@ -3,11 +3,11 @@
 
 #include <lunaix/clock.h>
 #include <lunaix/compiler.h>
 
 #include <lunaix/clock.h>
 #include <lunaix/compiler.h>
-#include <lunaix/generic/isrm.h>
+#include <asm-generic/isrm.h>
 #include <lunaix/spike.h>
 #include <lunaix/syslog.h>
 
 #include <lunaix/spike.h>
 #include <lunaix/syslog.h>
 
-#include "sys/apic.h"
+#include "asm/soc/apic.h"
 
 LOG_MODULE("APIC_TIMER")
 
 
 LOG_MODULE("APIC_TIMER")
 
index 00ba7f429fc56cccf1f566d2e474945ad1ed8a7d..e77d14ea3a7c333191df82fe5335724aeb9d3d18 100644 (file)
@@ -1,50 +1,7 @@
-#include <cpuid.h>
 #include <lunaix/types.h>
 #include <lunaix/types.h>
-#include <sys/cpu.h>
-#include <sys/vectors.h>
 
 
-#define BRAND_LEAF 0x80000000UL
-
-void
-cpu_get_model(char* model_out)
-{
-    u32_t* out = (u32_t*)model_out;
-    u32_t eax = 0, ebx = 0, edx = 0, ecx = 0;
-
-    __get_cpuid(0, &eax, &ebx, &ecx, &edx);
-
-    out[0] = ebx;
-    out[1] = edx;
-    out[2] = ecx;
-    model_out[12] = '\0';
-}
-
-int
-cpu_brand_string_supported()
-{
-    u32_t supported = __get_cpuid_max(BRAND_LEAF, 0);
-    return (supported >= 0x80000004UL);
-}
-
-void
-cpu_get_id(char* id_out)
-{
-    if (!cpu_brand_string_supported()) {
-        id_out[0] = '?';
-        id_out[1] = '\0';
-    }
-    u32_t* out = (u32_t*)id_out;
-    u32_t eax = 0, ebx = 0, edx = 0, ecx = 0;
-    for (u32_t i = 2, j = 0; i < 5; i++) {
-        __get_cpuid(BRAND_LEAF + i, &eax, &ebx, &ecx, &edx);
-        out[j] = eax;
-        out[j + 1] = ebx;
-        out[j + 2] = ecx;
-        out[j + 3] = edx;
-        j += 4;
-    }
-    id_out[48] = '\0';
-}
+#include "asm/x86_ivs.h"
+#include "asm/x86_cpu.h"
 
 void
 cpu_rdmsr(u32_t msr_idx, u32_t* reg_high, u32_t* reg_low)
 
 void
 cpu_rdmsr(u32_t msr_idx, u32_t* reg_high, u32_t* reg_low)
@@ -67,9 +24,3 @@ cpu_trap_sched()
 {
     asm("int %0" ::"i"(LUNAIX_SCHED));
 }
 {
     asm("int %0" ::"i"(LUNAIX_SCHED));
 }
-
-void
-cpu_trap_panic(char* message)
-{
-    asm("int %0" ::"i"(LUNAIX_SYS_PANIC), "D"(message));
-}
index 1e0755a1426807990508dc1a78a0b8b809585ba0..e03d4b5d7334ba3183d63e929e5bc21fbca6778c 100644 (file)
@@ -2,9 +2,9 @@
 
 #include <lunaix/mm/mmio.h>
 
 
 #include <lunaix/mm/mmio.h>
 
-#include <sys/hart.h>
-#include "sys/ioapic.h"
-#include "sys/x86_isa.h"
+#include <asm/hart.h>
+#include "asm/soc/ioapic.h"
+#include "asm/x86.h"
 
 #define IOAPIC_IOREGSEL 0x00
 #define IOAPIC_IOWIN 0x10
 
 #define IOAPIC_IOREGSEL 0x00
 #define IOAPIC_IOWIN 0x10
index 96b95e175afc19855c12a349560a196d786d6367..879b4f5c2ced393e1c32a9b093557a433fccc404 100644 (file)
@@ -10,7 +10,7 @@
  *
  */
 
  *
  */
 
-#include <lunaix/generic/isrm.h>
+#include <asm-generic/isrm.h>
 #include <lunaix/mm/valloc.h>
 #include <lunaix/status.h>
 #include <lunaix/hart_state.h>
 #include <lunaix/mm/valloc.h>
 #include <lunaix/status.h>
 #include <lunaix/hart_state.h>
@@ -19,7 +19,7 @@
 
 #include <klibc/string.h>
 
 
 #include <klibc/string.h>
 
-#include <sys/port_io.h>
+#include <asm/x86_pmio.h>
 
 #define RTC_INDEX_PORT 0x70
 #define RTC_TARGET_PORT 0x71
 
 #define RTC_INDEX_PORT 0x70
 #define RTC_TARGET_PORT 0x71
index f1321b2a7a7d71aeb435f0ebce803dc9ad4e3897..d871790b4fcb4359ed160f4ecd97d2261606b23f 100644 (file)
@@ -1,5 +1,5 @@
 #include <hal/pci.h>
 #include <hal/pci.h>
-#include <sys/port_io.h>
+#include <asm/x86_pmio.h>
 
 #ifdef CONFIG_PCI_PMIO
 #define PCI_CONFIG_ADDR 0xcf8
 
 #ifdef CONFIG_PCI_PMIO
 #define PCI_CONFIG_ADDR 0xcf8
index f0d3ba4aca0dcd0abd3a8bf07981153a26c1ce4b..cd5518d8f14afba61c7ad9491de3024ea4e4b4eb 100644 (file)
@@ -1,18 +1,18 @@
 #include <lunaix/clock.h>
 #include <lunaix/ds/mutex.h>
 #include <lunaix/input.h>
 #include <lunaix/clock.h>
 #include <lunaix/ds/mutex.h>
 #include <lunaix/input.h>
-#include <lunaix/generic/isrm.h>
+#include <asm-generic/isrm.h>
 #include <lunaix/keyboard.h>
 #include <lunaix/syslog.h>
 #include <lunaix/timer.h>
 #include <lunaix/hart_state.h>
 
 #include <lunaix/keyboard.h>
 #include <lunaix/syslog.h>
 #include <lunaix/timer.h>
 #include <lunaix/hart_state.h>
 
-#include "sys/x86_isa.h"
+#include "asm/x86.h"
 
 #include <klibc/string.h>
 
 
 #include <klibc/string.h>
 
-#include <sys/cpu.h>
-#include <sys/port_io.h>
+#include "asm/x86_cpu.h"
+#include <asm/x86_pmio.h>
 
 #define PS2_PORT_ENC_DATA 0x60
 #define PS2_PORT_ENC_CMDREG 0x60
 
 #define PS2_PORT_ENC_DATA 0x60
 #define PS2_PORT_ENC_CMDREG 0x60
index 124ea6e9ddbd94dfd90abc4b506b85160fd7c802..a4d8a3d1d7da4ca7fb4fb4ed71f1644bd9971ab8 100644 (file)
@@ -2,7 +2,7 @@
 #include <lunaix/mm/vmm.h>
 #include <klibc/string.h>
 
 #include <lunaix/mm/vmm.h>
 #include <klibc/string.h>
 
-#include <sys/mm/mempart.h>
+#include <asm/mempart.h>
 
 bool
 install_hart_transition(ptr_t vm_mnt, struct hart_transition* ht)
 
 bool
 install_hart_transition(ptr_t vm_mnt, struct hart_transition* ht)
index 7c345730c77417deab2e643a879730d22be673a2..e87e4fbd36a9f791d94912fce504db7e300d9057 100644 (file)
@@ -5,8 +5,8 @@
 #include <lunaix/mm/vmm.h>
 #include <klibc/string.h>
 
 #include <lunaix/mm/vmm.h>
 #include <klibc/string.h>
 
-#include <sys/mm/mempart.h>
-#include <sys/abi.h>
+#include <asm/mempart.h>
+#include <asm/abi.h>
 
 volatile struct x86_tss _tss = { .link = 0,
                                  .esp0 = 0,
 
 volatile struct x86_tss _tss = { .link = 0,
                                  .esp0 = 0,
index af9da33ad103c86a8a5c13e41da5170b860f41f8..b18f296695c5be435add22191a6d571195bf6103 100644 (file)
@@ -5,8 +5,8 @@
 #include <lunaix/mm/vmm.h>
 #include <klibc/string.h>
 
 #include <lunaix/mm/vmm.h>
 #include <klibc/string.h>
 
-#include <sys/mm/mempart.h>
-#include <sys/abi.h>
+#include <asm/mempart.h>
+#include <asm/abi.h>
 
 volatile struct x86_tss _tss = { };
 
 
 volatile struct x86_tss _tss = { };
 
similarity index 88%
rename from lunaix-os/arch/x86/includes/sys/abi.h
rename to lunaix-os/arch/x86/includes/asm/abi.h
index bfa93a742b8559c880ac2aa79d965e1dd75a20c5..392126b64657fd38dcc94cfa6f729658ebac20ce 100644 (file)
@@ -2,9 +2,9 @@
 #define __LUNAIX_I386ABI_H
 
 #ifdef CONFIG_ARCH_X86_64
 #define __LUNAIX_I386ABI_H
 
 #ifdef CONFIG_ARCH_X86_64
-#   include "abi64.h"
+#   include "variants/abi64.h"
 #else
 #else
-#   include "abi32.h"
+#   include "variants/abi32.h"
 #endif
 
 #ifndef __ASM__
 #endif
 
 #ifndef __ASM__
diff --git a/lunaix-os/arch/x86/includes/asm/cpu.h b/lunaix-os/arch/x86/includes/asm/cpu.h
new file mode 100644 (file)
index 0000000..a4fec39
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef __LUNAIX_ARCH_CPU_H
+#define __LUNAIX_ARCH_CPU_H
+
+#include <lunaix/types.h>
+
+void
+cpu_trap_sched();
+
+static inline void
+cpu_enable_interrupt()
+{
+    asm volatile("sti");
+}
+
+static inline void
+cpu_disable_interrupt()
+{
+    asm volatile("cli");
+}
+
+static inline void
+cpu_wait()
+{
+    asm("hlt");
+}
+
+#endif /* __LUNAIX_CPU_H */
similarity index 97%
rename from lunaix-os/arch/x86/includes/sys/hart.h
rename to lunaix-os/arch/x86/includes/asm/hart.h
index ac3801e9afb71a40ad600d9d5a16b61b77f3b75a..f1d8e0de248ed5a9cc3e217a68e971b069ada40d 100644 (file)
@@ -1,12 +1,12 @@
 #ifndef __LUNAIX_ARCH_HART_H
 #define __LUNAIX_ARCH_HART_H
 
 #ifndef __LUNAIX_ARCH_HART_H
 #define __LUNAIX_ARCH_HART_H
 
-#include "vectors.h"
+#include "x86_ivs.h"
 
 #ifndef __ASM__
 
 #ifndef __ASM__
-#include <lunaix/compiler.h>
-#include <sys/cpu.h>
+#include <lunaix/types.h>
 
 
+#include "x86_cpu.h"
 
 struct hart_state;
 
 
 struct hart_state;
 
similarity index 55%
rename from lunaix-os/arch/x86/includes/sys/mm/mempart.h
rename to lunaix-os/arch/x86/includes/asm/mempart.h
index a3ad64635ec90b0f5513fa80ecd5a8be5229d554..64f9bb76f10ce718c777dc0725ba7ed45bfa7432 100644 (file)
@@ -2,9 +2,9 @@
 #define __LUNAIX_MEMPART_H
 
 #ifdef CONFIG_ARCH_X86_64
 #define __LUNAIX_MEMPART_H
 
 #ifdef CONFIG_ARCH_X86_64
-#   include "mempart64.h"
+#   include "variants/mempart64.h"
 #else
 #else
-#   include "mempart32.h"
+#   include "variants/mempart32.h"
 #endif
 
 #endif
\ No newline at end of file
 #endif
 
 #endif
\ No newline at end of file
similarity index 97%
rename from lunaix-os/arch/x86/includes/sys/mm/pagetable.h
rename to lunaix-os/arch/x86/includes/asm/pagetable.h
index 67ade4e84b4a8825d06f4f56417a307e819857f9..af06f3d115432375ac9c8d20d8ec6ef7f9db3d2a 100644 (file)
@@ -8,11 +8,11 @@
 
 #ifdef CONFIG_ARCH_X86_64
 
 
 #ifdef CONFIG_ARCH_X86_64
 
-#include "pt_def64.h"
+#include "variants/pt_def64.h"
 
 #else
 
 
 #else
 
-#include "pt_def32.h"
+#include "variants/pt_def32.h"
 
 #endif
 
 
 #endif
 
@@ -46,9 +46,7 @@
 // max translation level supported
 #define MAX_LEVEL           _PTW_LEVEL
 
 // max translation level supported
 #define MAX_LEVEL           _PTW_LEVEL
 
-#ifndef pte_t
 typedef struct __pte pte_t;
 typedef struct __pte pte_t;
-#endif
 
 
 #define _PTE_PPFN_MASK          ( (~PAGE_MASK & PMS_MASK))
 
 
 #define _PTE_PPFN_MASK          ( (~PAGE_MASK & PMS_MASK))
@@ -291,5 +289,7 @@ pte_at(pte_t* ptep) {
     return *ptep;
 }
 
     return *ptep;
 }
 
+pte_t
+translate_vmr_prot(unsigned int vmr_prot, pte_t pte);
 
 #endif /* __LUNAIX_ARCH_PAGETABLE_H */
 
 #endif /* __LUNAIX_ARCH_PAGETABLE_H */
similarity index 99%
rename from lunaix-os/arch/x86/includes/sys/apic.h
rename to lunaix-os/arch/x86/includes/asm/soc/apic.h
index a74049b0b116e66c51c9a94f5e59a095deb145cc..40c395cee55619389d7e57d29c5074df2ad7c59e 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef __LUNAIX_APIC_H
 #define __LUNAIX_APIC_H
 
 #ifndef __LUNAIX_APIC_H
 #define __LUNAIX_APIC_H
 
-#include "sys/x86_isa.h"
+#include "asm/x86.h"
 #include <lunaix/types.h>
 
 #define __APIC_BASE_PADDR 0xFEE00000
 #include <lunaix/types.h>
 
 #define __APIC_BASE_PADDR 0xFEE00000
similarity index 91%
rename from lunaix-os/arch/x86/includes/sys/ioapic.h
rename to lunaix-os/arch/x86/includes/asm/soc/ioapic.h
index 46916d96a473993977de82040f3de6c9d2ce469b..d87ab18234668522713f6a6bdd2bb607893d57d7 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef __LUNAIX_IOAPIC_H
 #define __LUNAIX_IOAPIC_H
 
 #ifndef __LUNAIX_IOAPIC_H
 #define __LUNAIX_IOAPIC_H
 
-#include "sys/x86_isa.h"
+#include "asm/x86.h"
 
 void
 ioapic_init();
 
 void
 ioapic_init();
similarity index 97%
rename from lunaix-os/arch/x86/includes/sys/abi32.h
rename to lunaix-os/arch/x86/includes/asm/variants/abi32.h
index a5d3db7e6dd9e7dadd6b924fde03221cad6bba68..d62aae379ed2dfd21aea74482ade70a2e5eaa60f 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef __LUNAIX_ARCH_ABI32_H
 #define __LUNAIX_ARCH_ABI32_H
 
 #ifndef __LUNAIX_ARCH_ABI32_H
 #define __LUNAIX_ARCH_ABI32_H
 
-#include "sys/x86_isa.h"
+#include "asm/x86.h"
 
 #define stack_alignment 0xfffffff0
 
 
 #define stack_alignment 0xfffffff0
 
similarity index 97%
rename from lunaix-os/arch/x86/includes/sys/abi64.h
rename to lunaix-os/arch/x86/includes/asm/variants/abi64.h
index 1dce9b03d1842e974d3ffc9e4a08b87d0e2fb7ad..02cf3c97e0ea60ba5f3056bbef4f83cf64103d6a 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef __LUNAIX_ARCH_ABI64_H
 #define __LUNAIX_ARCH_ABI64_H
 
 #ifndef __LUNAIX_ARCH_ABI64_H
 #define __LUNAIX_ARCH_ABI64_H
 
-#include "sys/x86_isa.h"
+#include "asm/x86.h"
 
 #define stack_alignment 0xfffffffffffffff0UL
 
 
 #define stack_alignment 0xfffffffffffffff0UL
 
similarity index 96%
rename from lunaix-os/arch/x86/includes/sys/x86_isa.h
rename to lunaix-os/arch/x86/includes/asm/x86.h
index 34510c821ce2b75343d6439639982d3b80384984..33515a1193b7a76439dd40b4c60456d34e1164fd 100644 (file)
@@ -92,5 +92,11 @@ typedef struct x86_sysdesc x86_segdesc_t;
 
 #endif
 
 
 #endif
 
+void
+exception_install_handler();
+
+void
+intr_routine_init();
+
 #endif
 #endif /* __LUNAIX_I386_ASM_H */
 #endif
 #endif /* __LUNAIX_I386_ASM_H */
similarity index 69%
rename from lunaix-os/arch/x86/includes/sys/cpu.h
rename to lunaix-os/arch/x86/includes/asm/x86_cpu.h
index 2889234e3c2d810555340e17ab92d567481309b7..0dde3e0074e11b09f39118d9bc9a96fb46c166e6 100644 (file)
@@ -1,7 +1,8 @@
-#ifndef __LUNAIX_CPU_H
-#define __LUNAIX_CPU_H
+#ifndef __LUNAIX_CPU_X86_H
+#define __LUNAIX_CPU_X86_H
 
 
-#include <lunaix/types.h>
+#include "cpu.h"
+#include "x86_crx.h"
 
 #ifdef CONFIG_ARCH_X86_64
 #   define _POP "popq "
 
 #ifdef CONFIG_ARCH_X86_64
 #   define _POP "popq "
 #   define _MOV "movl "
 #endif
 
 #   define _MOV "movl "
 #endif
 
-/**
- * @brief Get processor ID string
- *
- * @param id_out
- */
-void
-cpu_get_id(char* id_out);
-
-void
-cpu_trap_sched();
-
-void
-cpu_trap_panic(char* message);
-
 /**
  * @brief Load current processor state
  *
 /**
  * @brief Load current processor state
  *
@@ -88,23 +75,4 @@ cpu_ldeaddr()
     return val;
 }
 
     return val;
 }
 
-
-static inline void
-cpu_enable_interrupt()
-{
-    asm volatile("sti");
-}
-
-static inline void
-cpu_disable_interrupt()
-{
-    asm volatile("cli");
-}
-
-static inline void
-cpu_wait()
-{
-    asm("hlt");
-}
-
-#endif /* __LUNAIX_CPU_H */
+#endif /* __LUNAIX_CPU_X86_H */
similarity index 93%
rename from lunaix-os/arch/x86/includes/sys/vectors.h
rename to lunaix-os/arch/x86/includes/asm/x86_ivs.h
index c055b46c41122ff1c05e45ce0efda3d0c31fbcff..0a5eed2669db28780904e4f0329e97c3abc6c675 100644 (file)
@@ -1,7 +1,5 @@
-#ifndef __LUNAIX_VECTORS_H
-#define __LUNAIX_VECTORS_H
-
-// clang-format off
+#ifndef __LUNAIX_X86IVS_H
+#define __LUNAIX_X86IVS_H
 
 #define TOTAL_IV 256
 
 
 #define TOTAL_IV 256
 
@@ -50,4 +48,4 @@
 
 // clang-format on
 
 
 // clang-format on
 
-#endif /* __LUNAIX_VECTORS_H */
+#endif /* __LUNAIX_X86IVS_H */
index cb7404523084b350bacaa043b9089601f00c1e15..d351d863142e5c3e95c059131423233c71aab334 100644 (file)
@@ -2,7 +2,7 @@
 #define __LUNAIX_BASE_DEFS_LD_INC
 
 #define __LD__
 #define __LUNAIX_BASE_DEFS_LD_INC
 
 #define __LD__
-#include <sys/mm/mempart.h>
+#include <asm/mempart.h>
 
 #define KEXEC_BASE      KERNEL_IMG
 #define PAGE_GRAN       4K
 
 #define KEXEC_BASE      KERNEL_IMG
 #define PAGE_GRAN       4K
diff --git a/lunaix-os/arch/x86/includes/sys/elf.h b/lunaix-os/arch/x86/includes/sys/elf.h
new file mode 100644 (file)
index 0000000..e2b95a2
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef __LUNAIX_ARCH_X86_ELF_H
+#define __LUNAIX_ARCH_X86_ELF_H
+
+#include <sys-generic/elf.h>
+
+#endif /* __LUNAIX_ARCH_X86_ELF_H */
index 8d98cef86ea8ef8070d0f7dad9827a7cec091f4b..dc01a5708734198ec7bea5970e2648da7a35b030 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef __LUNAIX_ARCH_GDBSTUB_ARCH_H
 #define __LUNAIX_ARCH_GDBSTUB_ARCH_H
 
 #ifndef __LUNAIX_ARCH_GDBSTUB_ARCH_H
 #define __LUNAIX_ARCH_GDBSTUB_ARCH_H
 
-#include "sys/hart.h"
+#include "asm/hart.h"
 
 enum GDB_REGISTER
 {
 
 enum GDB_REGISTER
 {
diff --git a/lunaix-os/arch/x86/includes/sys/int_handler.h b/lunaix-os/arch/x86/includes/sys/int_handler.h
deleted file mode 100644 (file)
index aac99d9..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-#ifndef __LUNAIX_INT_HANDLER_H
-#define __LUNAIX_INT_HANDLER_H
-
-void
-exception_install_handler();
-
-void
-intr_routine_init();
-
-#endif /* __LUNAIX_INT_HANDLER_H */
diff --git a/lunaix-os/arch/x86/includes/sys/mm/memory.h b/lunaix-os/arch/x86/includes/sys/mm/memory.h
deleted file mode 100644 (file)
index abccba9..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-#ifndef __LUNAIX_ARCH_MEMORY_H
-#define __LUNAIX_ARCH_MEMORY_H
-
-#include <lunaix/mm/pagetable.h>
-#include <lunaix/mann_flags.h>
-
-static inline pte_t
-translate_vmr_prot(unsigned int vmr_prot, pte_t pte)
-{
-    pte = pte_mkuser(pte);
-
-    if ((vmr_prot & PROT_WRITE)) {
-        pte = pte_mkwritable(pte);
-    }
-
-    if ((vmr_prot & PROT_EXEC)) {
-        pte = pte_mkexec(pte);
-    }
-    else {
-        pte = pte_mknonexec(pte);
-    }
-
-    return pte;
-}
-
-
-#endif /* __LUNAIX_ARCH_MEMORY_H */
index 62f9d8088ed2c60f1afbf877541ff72ffc914f2f..899fe2f8ff17689d805b2f672a629fe5d7c3f159 100644 (file)
@@ -1,10 +1,6 @@
 #include <lunaix/mm/fault.h>
 #include <lunaix/mm/fault.h>
-#include <lunaix/mm/region.h>
-#include <lunaix/process.h>
 #include <lunaix/hart_state.h>
 
 #include <lunaix/hart_state.h>
 
-#include <sys/mm/mm_defs.h>
-
 bool
 __arch_prepare_fault_context(struct fault_context* fault)
 {
 bool
 __arch_prepare_fault_context(struct fault_context* fault)
 {
@@ -21,4 +17,30 @@ __arch_prepare_fault_context(struct fault_context* fault)
     fault->fault_va    = ptr;
 
     return true;
     fault->fault_va    = ptr;
 
     return true;
+}
+
+
+void
+intr_routine_page_fault(const struct hart_state* hstate)
+{
+    if (hstate->depth > 10) {
+        // Too many nested fault! we must messed up something
+        // XXX should we failed silently?
+        spin();
+    }
+
+    struct fault_context fault = { .hstate = hstate };
+
+    if (!__arch_prepare_fault_context(&fault)) {
+        goto failed;
+    }
+
+    if (!handle_page_fault(&fault)) {
+        goto failed;
+    }
+
+    return;
+
+failed:
+    fault_resolving_failed(&fault);
 }
\ No newline at end of file
 }
\ No newline at end of file
index d1b36272839c890b57854aff3ea73a751e7df4c0..ea8a79bca4e324b20744dc4342ca4dec9ccbb4b2 100644 (file)
@@ -1,5 +1,5 @@
 #include <lunaix/types.h>
 #include <lunaix/types.h>
-#include "sys/x86_isa.h"
+#include "asm/x86.h"
 
 #define SD_TYPE(x) (x << 8)
 #define SD_CODE_DATA(x) (x << 12)
 
 #define SD_TYPE(x) (x << 8)
 #define SD_CODE_DATA(x) (x << 12)
index 2ee5d48817e10817de7115b3a0041f961691d623..849792ebc677838743e19d9c4659c3e469818bf4 100644 (file)
@@ -1,4 +1,4 @@
-#include <sys/mm/tlb.h>
+#include <asm/tlb.h>
 #include <lunaix/process.h>
 
 void
 #include <lunaix/process.h>
 
 void
index df831c296ff9edb32f7f58d3caf8ecb69de10a74..5f4d3df88bb1d612b715b2c7eed733e2e62ed5c9 100644 (file)
@@ -1,5 +1,6 @@
 #include <lunaix/mm/page.h>
 #include <lunaix/mm/page.h>
-#include <sys/mm/mm_defs.h>
+
+#include <asm/mm_defs.h>
 
 struct leaflet*
 dup_leaflet(struct leaflet* leaflet)
 
 struct leaflet*
 dup_leaflet(struct leaflet* leaflet)
@@ -36,4 +37,23 @@ dup_leaflet(struct leaflet* leaflet)
     vunmap(dest_va, new_leaflet);
 
     return new_leaflet;
     vunmap(dest_va, new_leaflet);
 
     return new_leaflet;
-}
\ No newline at end of file
+}
+
+pte_t
+translate_vmr_prot(unsigned int vmr_prot, pte_t pte)
+{
+    pte = pte_mkuser(pte);
+
+    if ((vmr_prot & PROT_WRITE)) {
+        pte = pte_mkwritable(pte);
+    }
+
+    if ((vmr_prot & PROT_EXEC)) {
+        pte = pte_mkexec(pte);
+    }
+    else {
+        pte = pte_mknonexec(pte);
+    }
+
+    return pte;
+}
index 650dc1701250597559cab77126c55c50380756f7..b8915ed8a0b165f5e1701c5b650a44d2dcf88d5a 100644 (file)
@@ -1,81 +1,6 @@
 #define __ASM__
 #include <lunaix/syscall.h>
 #define __ASM__
 #include <lunaix/syscall.h>
-
-.section .data
-    /*
-        注意,这里的顺序非常重要。每个系统调用在这个地址表里的索引等于其调用号。
-    */
-    syscall_table:
-        1:
-        .long 0
-        .long __lxsys_fork          /* 1 */
-        .long __lxsys_yield
-        .long __lxsys_sbrk
-        .long __lxsys_brk
-        .long __lxsys_getpid        /* 5 */
-        .long __lxsys_getppid
-        .long __lxsys_sleep
-        .long __lxsys_exit
-        .long __lxsys_wait          
-        .long __lxsys_waitpid       /* 10 */
-        .long __lxsys_sigreturn
-        .long __lxsys_sigprocmask
-        .long __lxsys_sys_sigaction
-        .long __lxsys_pause
-        .long __lxsys_kill          /* 15 */
-        .long __lxsys_alarm
-        .long __lxsys_sigpending
-        .long __lxsys_sigsuspend
-        .long __lxsys_open
-        .long __lxsys_close         /* 20 */
-        .long __lxsys_read
-        .long __lxsys_write
-        .long __lxsys_sys_readdir
-        .long __lxsys_mkdir
-        .long __lxsys_lseek         /* 25 */
-        .long __lxsys_geterrno
-        .long __lxsys_readlink
-        .long __lxsys_readlinkat
-        .long __lxsys_rmdir
-        .long __lxsys_unlink        /* 30 */
-        .long __lxsys_unlinkat
-        .long __lxsys_link
-        .long __lxsys_fsync
-        .long __lxsys_dup
-        .long __lxsys_dup2          /* 35 */
-        .long __lxsys_realpathat
-        .long __lxsys_symlink
-        .long __lxsys_chdir
-        .long __lxsys_fchdir
-        .long __lxsys_getcwd        /* 40 */
-        .long __lxsys_rename
-        .long __lxsys_mount
-        .long __lxsys_unmount
-        .long __lxsys_getxattr
-        .long __lxsys_setxattr      /* 45 */
-        .long __lxsys_fgetxattr
-        .long __lxsys_fsetxattr
-        .long __lxsys_ioctl
-        .long __lxsys_getpgid
-        .long __lxsys_setpgid       /* 50 */
-        .long __lxsys_syslog
-        .long __lxsys_sys_mmap
-        .long __lxsys_munmap
-        .long __lxsys_execve
-        .long __lxsys_fstat         /* 55 */
-        .long __lxsys_pollctl
-        .long __lxsys_th_create
-        .long __lxsys_th_self
-        .long __lxsys_th_exit
-        .long __lxsys_th_join       /* 60 */
-        .long __lxsys_th_kill
-        .long __lxsys_th_detach
-        .long __lxsys_th_sigmask
-        2:
-        .rept __SYSCALL_MAX - (2b - 1b)/4
-            .long 0
-        .endr
-
+#include "syscall_nr.inc"
 
 .section .text
     .type syscall_hndlr, @function
 
 .section .text
     .type syscall_hndlr, @function
index 624002f88319f87f47e43cc8681bf3604994dd99..6125a84f5252d08d05306756febaa4cae0fe6710 100644 (file)
@@ -1,82 +1,7 @@
 #define __ASM__
 #include <lunaix/syscall.h>
 #define __ASM__
 #include <lunaix/syscall.h>
-#include "sys/interrupt64.S.inc"
-
-.section .data
-    /*
-        注意,这里的顺序非常重要。每个系统调用在这个地址表里的索引等于其调用号。
-    */
-    syscall_table:
-        1:
-        .8byte 0
-        .8byte __lxsys_fork          /* 1 */
-        .8byte __lxsys_yield
-        .8byte __lxsys_sbrk
-        .8byte __lxsys_brk
-        .8byte __lxsys_getpid        /* 5 */
-        .8byte __lxsys_getppid
-        .8byte __lxsys_sleep
-        .8byte __lxsys_exit
-        .8byte __lxsys_wait          
-        .8byte __lxsys_waitpid       /* 10 */
-        .8byte __lxsys_sigreturn
-        .8byte __lxsys_sigprocmask
-        .8byte __lxsys_sys_sigaction
-        .8byte __lxsys_pause
-        .8byte __lxsys_kill          /* 15 */
-        .8byte __lxsys_alarm
-        .8byte __lxsys_sigpending
-        .8byte __lxsys_sigsuspend
-        .8byte __lxsys_open
-        .8byte __lxsys_close         /* 20 */
-        .8byte __lxsys_read
-        .8byte __lxsys_write
-        .8byte __lxsys_sys_readdir
-        .8byte __lxsys_mkdir
-        .8byte __lxsys_lseek         /* 25 */
-        .8byte __lxsys_geterrno
-        .8byte __lxsys_readlink
-        .8byte __lxsys_readlinkat
-        .8byte __lxsys_rmdir
-        .8byte __lxsys_unlink        /* 30 */
-        .8byte __lxsys_unlinkat
-        .8byte __lxsys_link
-        .8byte __lxsys_fsync
-        .8byte __lxsys_dup
-        .8byte __lxsys_dup2          /* 35 */
-        .8byte __lxsys_realpathat
-        .8byte __lxsys_symlink
-        .8byte __lxsys_chdir
-        .8byte __lxsys_fchdir
-        .8byte __lxsys_getcwd        /* 40 */
-        .8byte __lxsys_rename
-        .8byte __lxsys_mount
-        .8byte __lxsys_unmount
-        .8byte __lxsys_getxattr
-        .8byte __lxsys_setxattr      /* 45 */
-        .8byte __lxsys_fgetxattr
-        .8byte __lxsys_fsetxattr
-        .8byte __lxsys_ioctl
-        .8byte __lxsys_getpgid
-        .8byte __lxsys_setpgid       /* 50 */
-        .8byte __lxsys_syslog
-        .8byte __lxsys_sys_mmap
-        .8byte __lxsys_munmap
-        .8byte __lxsys_execve
-        .8byte __lxsys_fstat         /* 55 */
-        .8byte __lxsys_pollctl
-        .8byte __lxsys_th_create
-        .8byte __lxsys_th_self
-        .8byte __lxsys_th_exit
-        .8byte __lxsys_th_join       /* 60 */
-        .8byte __lxsys_th_kill
-        .8byte __lxsys_th_detach
-        .8byte __lxsys_th_sigmask
-        2:
-        .rept __SYSCALL_MAX - (2b - 1b) / 8
-            .8byte 0
-        .endr
-
+#include "syscall_nr.inc"
+#include "asm/variants/interrupt64.S.inc"
 
 .section .text
     .type syscall_hndlr, @function
 
 .section .text
     .type syscall_hndlr, @function
diff --git a/lunaix-os/arch/x86/syscall_nr.inc b/lunaix-os/arch/x86/syscall_nr.inc
new file mode 100644 (file)
index 0000000..c30a720
--- /dev/null
@@ -0,0 +1,79 @@
+#ifdef CONFIG_ARCH_X86_64
+#   define PTR     .8byte
+#   define SIZE    8
+#else
+#   define PTR     .4byte
+#   define SIZE    4
+#endif
+
+.section .data
+    syscall_table:
+        1:
+        PTR 0
+        PTR __lxsys_fork          /* 1 */
+        PTR __lxsys_yield
+        PTR __lxsys_sbrk
+        PTR __lxsys_brk
+        PTR __lxsys_getpid        /* 5 */
+        PTR __lxsys_getppid
+        PTR __lxsys_sleep
+        PTR __lxsys_exit
+        PTR __lxsys_wait          
+        PTR __lxsys_waitpid       /* 10 */
+        PTR __lxsys_sigreturn
+        PTR __lxsys_sigprocmask
+        PTR __lxsys_sys_sigaction
+        PTR __lxsys_pause
+        PTR __lxsys_kill          /* 15 */
+        PTR __lxsys_alarm
+        PTR __lxsys_sigpending
+        PTR __lxsys_sigsuspend
+        PTR __lxsys_open
+        PTR __lxsys_close         /* 20 */
+        PTR __lxsys_read
+        PTR __lxsys_write
+        PTR __lxsys_sys_readdir
+        PTR __lxsys_mkdir
+        PTR __lxsys_lseek         /* 25 */
+        PTR __lxsys_geterrno
+        PTR __lxsys_readlink
+        PTR __lxsys_readlinkat
+        PTR __lxsys_rmdir
+        PTR __lxsys_unlink        /* 30 */
+        PTR __lxsys_unlinkat
+        PTR __lxsys_link
+        PTR __lxsys_fsync
+        PTR __lxsys_dup
+        PTR __lxsys_dup2          /* 35 */
+        PTR __lxsys_realpathat
+        PTR __lxsys_symlink
+        PTR __lxsys_chdir
+        PTR __lxsys_fchdir
+        PTR __lxsys_getcwd        /* 40 */
+        PTR __lxsys_rename
+        PTR __lxsys_mount
+        PTR __lxsys_unmount
+        PTR __lxsys_getxattr
+        PTR __lxsys_setxattr      /* 45 */
+        PTR __lxsys_fgetxattr
+        PTR __lxsys_fsetxattr
+        PTR __lxsys_ioctl
+        PTR __lxsys_getpgid
+        PTR __lxsys_setpgid       /* 50 */
+        PTR __lxsys_syslog
+        PTR __lxsys_sys_mmap
+        PTR __lxsys_munmap
+        PTR __lxsys_execve
+        PTR __lxsys_fstat         /* 55 */
+        PTR __lxsys_pollctl
+        PTR __lxsys_th_create
+        PTR __lxsys_th_self
+        PTR __lxsys_th_exit
+        PTR __lxsys_th_join       /* 60 */
+        PTR __lxsys_th_kill
+        PTR __lxsys_th_detach
+        PTR __lxsys_th_sigmask
+        2:
+        .rept __SYSCALL_MAX - (2b - 1b) / SIZE
+            .long 0
+        .endr
\ No newline at end of file
index f4e0dd4bed37f05ea975af584dc3d7ecaebb557b..f40ae2428a135457793da09bf209e42d271ab73c 100644 (file)
 #include <hal/ahci/scsi.h>
 #include <hal/pci.h>
 
 #include <hal/ahci/scsi.h>
 #include <hal/pci.h>
 
-#include <sys/port_io.h>
+#include <asm/x86_pmio.h>
 
 #include <klibc/string.h>
 #include <lunaix/block.h>
 
 #include <klibc/string.h>
 #include <lunaix/block.h>
-#include <lunaix/generic/isrm.h>
+#include <asm-generic/isrm.h>
 #include <lunaix/mm/mmio.h>
 #include <lunaix/mm/valloc.h>
 #include <lunaix/mm/page.h>
 #include <lunaix/mm/mmio.h>
 #include <lunaix/mm/valloc.h>
 #include <lunaix/mm/page.h>
index d37f8e6f7663f2c6255c4ae9ea9548395cb0770b..608634d84e5fdbd52151441380a4ea099ee55e5f 100644 (file)
@@ -1,6 +1,6 @@
 #include <hal/ahci/ahci.h>
 #include <hal/ahci/sata.h>
 #include <hal/ahci/ahci.h>
 #include <hal/ahci/sata.h>
-#include <lunaix/generic/isrm.h>
+#include <asm-generic/isrm.h>
 #include <lunaix/mm/valloc.h>
 #include <lunaix/syslog.h>
 
 #include <lunaix/mm/valloc.h>
 #include <lunaix/syslog.h>
 
index 803fdb59287330a340760eb59c54b5c4287abcb5..d3d14c70eb66dbe13b1e0136aed677a0f4c0537d 100644 (file)
@@ -5,7 +5,7 @@
 #include <lunaix/status.h>
 #include <lunaix/syslog.h>
 
 #include <lunaix/status.h>
 #include <lunaix/syslog.h>
 
-#include <sys/mm/pagetable.h>
+#include <asm/pagetable.h>
 
 #include <hal/serial.h>
 #include <hal/term.h>
 
 #include <hal/serial.h>
 #include <hal/term.h>
index d8d2e1b7d971e06c0d8140f1a4ad9ee966afb6b5..128803e29aa050a4c84fa1c11effcf3aed40146d 100644 (file)
@@ -1,8 +1,8 @@
 #include <lunaix/device.h>
 #include <lunaix/device.h>
-#include <lunaix/generic/isrm.h>
+#include <asm-generic/isrm.h>
 #include <lunaix/syslog.h>
 
 #include <lunaix/syslog.h>
 
-#include <sys/port_io.h>
+#include <asm/x86_pmio.h>
 
 #include "16x50.h"
 
 
 #include "16x50.h"
 
index 2e32b75f4cc1d4393cdbb23c36f5f2c3d5fd5b34..e2116253a37701bda9b4a1c36871a22076b3bebd 100644 (file)
@@ -1,5 +1,5 @@
 #include <lunaix/device.h>
 #include <lunaix/device.h>
-#include <lunaix/generic/isrm.h>
+#include <asm-generic/isrm.h>
 #include <lunaix/mm/mmio.h>
 
 #include "16x50.h"
 #include <lunaix/mm/mmio.h>
 
 #include "16x50.h"
index 880fd2d99f4295d6bfa9421a6e7a4ed78ed4c24c..1d8afd874b1e2322e12843aef551e3678e19154f 100644 (file)
@@ -1,5 +1,5 @@
 #include <lunaix/device.h>
 #include <lunaix/device.h>
-#include <lunaix/generic/isrm.h>
+#include <asm-generic/isrm.h>
 #include <lunaix/syslog.h>
 #include <lunaix/mm/mmio.h>
 
 #include <lunaix/syslog.h>
 #include <lunaix/mm/mmio.h>
 
index 76ab3bc7a814cc0107317c081c34e564f2c8c40f..ea550cbb995f57e664b190d64d001a4851e4ab84 100644 (file)
@@ -9,9 +9,9 @@
  *
  */
 #include <lunaix/device.h>
  *
  */
 #include <lunaix/device.h>
-#include <lunaix/generic/isrm.h>
+#include <asm-generic/isrm.h>
 
 
-#include <sys/port_io.h>
+#include <asm/x86_pmio.h>
 
 #include "16x50.h"
 
 
 #include "16x50.h"
 
index 020e00ce36ab2952df6bddeb76802e40a81d18d6..a3dde122544e104b3dbd508dde4f767d89edc1a7 100644 (file)
@@ -15,7 +15,7 @@
 #include <lunaix/spike.h>
 #include <lunaix/status.h>
 
 #include <lunaix/spike.h>
 #include <lunaix/status.h>
 
-#include <sys/cpu.h>
+#include <asm/cpu.h>
 
 #include "vga.h"
 
 
 #include "vga.h"
 
index 21fcd82aa2f9a55568740dd7e4eb65c998fa19d1..b0861d3c9ed77148fa01ce1a60c8ba2496035bf4 100644 (file)
@@ -6,7 +6,7 @@
 #include <lunaix/mm/pagetable.h>
 #include <lunaix/mm/mmio.h>
 
 #include <lunaix/mm/pagetable.h>
 #include <lunaix/mm/mmio.h>
 
-#include <sys/port_io.h>
+#include <asm/x86_pmio.h>
 
 vga_attribute* tty_vga_buffer;
 
 
 vga_attribute* tty_vga_buffer;
 
index a9d96c7258b9a089fb31650ecab9ddb3e5ea2546..7eaf10d4e012d73f231c457eeddf84a76f1cf57c 100644 (file)
@@ -2,7 +2,7 @@
 #define __LUNAIX_AHCI_H
 
 #include "hba.h"
 #define __LUNAIX_AHCI_H
 
 #include "hba.h"
-#include <lunaix/generic/isrm.h>
+#include <asm-generic/isrm.h>
 
 /*
  * Macro naming rule:
 
 /*
  * Macro naming rule:
index 9ffb7e2ddae015166cf40abcafd7256a06b53606..7830cb2796cede61d2cc33542f6a138c79ee0d95 100644 (file)
@@ -28,7 +28,6 @@ struct boot_modent
 
 struct boot_handoff
 {
 
 struct boot_handoff
 {
-    size_t msize;
     struct
     {
         size_t size;
     struct
     {
         size_t size;
index 570fdcfa00aa6be4ec15ace17d1ecc51526b573e..178c0fedd598a91544d8cbaac81133942ba0430b 100644 (file)
@@ -14,7 +14,7 @@
 #define unreachable             __builtin_unreachable()
 #define no_inline               __attribute__((noinline))
 
 #define unreachable             __builtin_unreachable()
 #define no_inline               __attribute__((noinline))
 
-#define defualt                 weak
+#define _default                weak
 
 #define msbiti                  (sizeof(int) * 8 - 1)
 #define clz(bits)               __builtin_clz(bits)
 
 #define msbiti                  (sizeof(int) * 8 - 1)
 #define clz(bits)               __builtin_clz(bits)
index 73a71e554ff060e91ae980555ad348a730c45deb..be4d628636691bde5e07e77600a47de62d5befbf 100644 (file)
@@ -18,7 +18,7 @@
 #define __LUNAIX_ELF32_H
 
 #include <lunaix/types.h>
 #define __LUNAIX_ELF32_H
 
 #include <lunaix/types.h>
-#include <sys/exebi/elf.h>
+#include <sys/elf.h>
 
 #define ET_EXEC 2
 #define ET_DYN 3
 
 #define ET_EXEC 2
 #define ET_DYN 3
index a9172bdf98f5ee1d6cec9b25d5a678b3a378392b..5ec53bf57e50580d7a08a21f14756ff0da751805 100644 (file)
@@ -6,7 +6,7 @@ struct regcontext;
 struct hart_state;
 
 #include <lunaix/compiler.h>
 struct hart_state;
 
 #include <lunaix/compiler.h>
-#include <sys/hart.h>
+#include <asm/hart.h>
 
 struct hart_transition 
 {
 
 struct hart_transition 
 {
index ef1680b4ca3de1dbd59917bef18fbba81e4bffcd..6fa9d70414cabdc51707c748dbf86230e7813e80 100644 (file)
@@ -1,8 +1,8 @@
 #ifndef __LUNAIX_KPREEMPT_H
 #define __LUNAIX_KPREEMPT_H
 
 #ifndef __LUNAIX_KPREEMPT_H
 #define __LUNAIX_KPREEMPT_H
 
-#include <sys/abi.h>
-#include <sys/cpu.h>
+#include <asm/abi.h>
+#include <asm/cpu.h>
 #include <lunaix/process.h>
 
 static inline void
 #include <lunaix/process.h>
 
 static inline void
index 057ef17164b7b9dbdd4d2f5307532d6a87c38522..abc8b7e14e7b377b9a202fd4fcc2de0fca78be35 100644 (file)
@@ -41,12 +41,16 @@ struct fault_context
     int resolve_type;
 };
 
     int resolve_type;
 };
 
-bool
-__arch_prepare_fault_context(struct fault_context* context);
-
 static inline void
 fault_resolved(struct fault_context* fault, int flags)
 {
     fault->resolve_type |= (flags | RESOLVE_OK);
 }
 static inline void
 fault_resolved(struct fault_context* fault, int flags)
 {
     fault->resolve_type |= (flags | RESOLVE_OK);
 }
+
+bool
+handle_page_fault(struct fault_context* fault);
+
+void noret
+fault_resolving_failed(struct fault_context* fault);
+
 #endif /* __LUNAIX_FAULT_H */
 #endif /* __LUNAIX_FAULT_H */
index d72c405656a86a40c6c553335b19d16f748122f0..abb18cf1545b74b11608db8441aa2bf278153a30 100644 (file)
@@ -4,7 +4,7 @@
 #include <lunaix/types.h>
 #include <lunaix/ds/llist.h>
 
 #include <lunaix/types.h>
 #include <lunaix/ds/llist.h>
 
-#include <sys/mm/memory.h>
+#include <asm/pagetable.h>
 
 #include <usr/lunaix/mann_flags.h>
 
 
 #include <usr/lunaix/mann_flags.h>
 
index f21c321056336ab8bc90898ce356dffa593fc94f..79244eb38cd2b9d519b5aeb7d68a115a1804f4e2 100644 (file)
@@ -99,9 +99,9 @@ struct __pte;
 typedef struct __pte pte_t;
 
 
 typedef struct __pte pte_t;
 
 
-#include <sys/mm/mempart.h>
-#include <sys/mm/pagetable.h>
-#include <sys/cpu.h>
+#include <asm/mempart.h>
+#include <asm/pagetable.h>
+#include <asm/cpu.h>
 
 #define VMS_SELF                VMS_SELF_MOUNT
 #define VMS_SELF_L0TI           (__index(VMS_SELF_MOUNT) / L0T_SIZE)
 
 #define VMS_SELF                VMS_SELF_MOUNT
 #define VMS_SELF_L0TI           (__index(VMS_SELF_MOUNT) / L0T_SIZE)
@@ -529,6 +529,45 @@ mkl3tep_va(ptr_t mnt, ptr_t va)
     return mkl3tep(mkptep_va(mnt, va));
 }
 
     return mkl3tep(mkptep_va(mnt, va));
 }
 
+static inline pte_t*
+mklntep_va(int level, ptr_t mnt, ptr_t va)
+{
+    if (level == 0)
+        return mkl0tep_va(mnt, va);
+    
+#if LnT_ENABLED(1)
+    if (level == 1)
+        return mkl1tep_va(mnt, va);
+#endif
+
+#if LnT_ENABLED(2)
+    if (level == 2)
+        return mkl2tep_va(mnt, va);
+#endif
+
+#if LnT_ENABLED(3)
+    if (level == 3)
+        return mkl3tep_va(mnt, va);
+#endif
+    
+    return mkptep_va(mnt, va);
+}
+
+static inline unsigned long
+lnt_page_size(int level)
+{
+    if (level == 0)
+        return L0T_SIZE;
+    if (level == 1)
+        return L1T_SIZE;
+    if (level == 2)
+        return L2T_SIZE;
+    if (level == 3)
+        return L3T_SIZE;
+    
+    return LFT_SIZE;
+}
+
 static inline bool
 pt_last_level(int level)
 {
 static inline bool
 pt_last_level(int level)
 {
@@ -548,9 +587,9 @@ va_level_index(ptr_t va, size_t lvl_size)
 }
 
 static inline bool
 }
 
 static inline bool
-l0tep_implie(pte_t* ptep, ptr_t addr)
+lntep_implie(pte_t* ptep, ptr_t addr, size_t lvl_size)
 {
 {
-    return ptep_va(ptep, L0T_SIZE) == __vaddr(addr);
+    return ptep_va(ptep, lvl_size) == __vaddr(addr);
 }
 
 static inline bool
 }
 
 static inline bool
@@ -573,10 +612,38 @@ active_vms(ptr_t vmnt)
 }
 
 static inline bool
 }
 
 static inline bool
-l0tep_implie_vmnts(pte_t* ptep)
+lntep_implie_vmnts(pte_t* ptep, size_t lvl_size)
 {
 {
-    return l0tep_implie(ptep, VMS_SELF) ||
-           l0tep_implie(ptep, VMS_MOUNT_1);
+    return lntep_implie(ptep, VMS_SELF, lvl_size) ||
+           lntep_implie(ptep, VMS_MOUNT_1, lvl_size);
+}
+
+
+static inline int
+ptep_count_level(pte_t* ptep)
+{
+    int i = 0;
+    ptr_t addr = (ptr_t)ptep;
+
+    if (!is_ptep(addr << (LEVEL_SHIFT * i++)))
+        return MAX_LEVEL - i;
+
+#if LnT_ENABLED(1)
+    if (!is_ptep(addr << (LEVEL_SHIFT * i++)))
+        return MAX_LEVEL - i;
+#endif
+
+#if LnT_ENABLED(2)
+    if (!is_ptep(addr << (LEVEL_SHIFT * i++)))
+        return MAX_LEVEL - i;
+#endif
+
+#if LnT_ENABLED(3)
+    if (!is_ptep(addr << (LEVEL_SHIFT * i++)))
+        return MAX_LEVEL - i;
+#endif
+    
+    return 0;
 }
 
 #endif /* __LUNAIX_PAGETABLE_H */
 }
 
 #endif /* __LUNAIX_PAGETABLE_H */
index 3eac5a1c1d28f0c132c19809e4b6f7049a979d99..e1710bf691e45a67b8ec7a55b579cad9c866779d 100644 (file)
@@ -2,7 +2,7 @@
 #define __LUNAIX_PHYSICAL_H
 
 #include <lunaix/compiler.h>
 #define __LUNAIX_PHYSICAL_H
 
 #include <lunaix/compiler.h>
-#include <sys/mm/physical.h>
+#include <asm/physical.h>
 
 /**
  * @brief 长久页:不会被缓存,但允许释放
 
 /**
  * @brief 长久页:不会被缓存,但允许释放
index 820bf1e61f044a3aeafa4c6f8536f4646548be24..82a2de35a2e252584b3c847041361ba5aeb7bdd4 100644 (file)
@@ -108,4 +108,14 @@ procvm_copy_remote(struct remote_vmctx* rvmctx,
 void
 procvm_exit_remote(struct remote_vmctx* rvmctx);
 
 void
 procvm_exit_remote(struct remote_vmctx* rvmctx);
 
+/*
+    architecture-specific
+*/
+
+void
+procvm_link_kernel(ptr_t dest_mnt);
+
+void
+procvm_unlink_kernel();
+
 #endif /* __LUNAIX_PROCVM_H */
 #endif /* __LUNAIX_PROCVM_H */
index 92f7684e600d1dd53b42493a9c0efc339a903199..a5bde364761c53c1d5441ead8805a1b05fa156b7 100644 (file)
@@ -6,13 +6,6 @@
 #include <lunaix/process.h>
 #include <lunaix/types.h>
 
 #include <lunaix/process.h>
 #include <lunaix/types.h>
 
-/**
- * @brief 初始化虚拟内存管理器
- *
- */
-void
-vmm_init();
-
 static inline void 
 vmm_set_ptes_contig(pte_t* ptep, pte_t pte, size_t lvl_size, size_t n)
 {
 static inline void 
 vmm_set_ptes_contig(pte_t* ptep, pte_t pte, size_t lvl_size, size_t n)
 {
index d4baf85de719bf99e1dee6a9007b34de996c3f18..c17ffcd2d3b162d5edf97e8a28a6821f57f72f92 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef __LUNAIX_TLB_H
 #define __LUNAIX_TLB_H
 
 #ifndef __LUNAIX_TLB_H
 #define __LUNAIX_TLB_H
 
-#include <sys/mm/tlb.h>
+#include <asm/tlb.h>
 
 // TODO
 
 
 // TODO
 
index 8abd8b0aaecfec6c9358511ee6ba6ecc45d31e88..b2a335b00d50cf57906f6314a035985060540684 100644 (file)
@@ -115,9 +115,6 @@ __assert_fail(const char* expr, const char* file, unsigned int line)
 
 #endif // CONFIG_NO_ASSERT
 
 
 #endif // CONFIG_NO_ASSERT
 
-void noret
-panick(const char* msg);
-
 #define wait_until(cond)                                                       \
     while (!(cond))                                                            \
         ;
 #define wait_until(cond)                                                       \
     while (!(cond))                                                            \
         ;
index c89a8b33dc08246e7d380356fcf2a8904803af74..8111a4e193d1da765c69d7d830d7ac83d928e43f 100644 (file)
@@ -3,7 +3,8 @@
 
 #include <lunaix/boot_generic.h>
 #include <lunaix/hart_state.h>
 
 #include <lunaix/boot_generic.h>
 #include <lunaix/hart_state.h>
-#include <lunaix/generic/trace_arch.h>
+
+#include <sys-generic/trace_arch.h>
 
 struct ksym_entry
 {
 
 struct ksym_entry
 {
index 302cd962e659458be8d708b0450c6c197933498b..862a48e9c019c2491793b20cf4896a9d979340b7 100644 (file)
@@ -3,7 +3,7 @@
 #include <lunaix/mm/valloc.h>
 #include <lunaix/owloysius.h>
 #include <lunaix/syslog.h>
 #include <lunaix/mm/valloc.h>
 #include <lunaix/owloysius.h>
 #include <lunaix/syslog.h>
-#include <sys/muldiv64.h>
+#include <asm/muldiv64.h>
 
 LOG_MODULE("blkbuf")  
 
 
 LOG_MODULE("blkbuf")  
 
index 481092558da302ecce59ba891174af3e5db432c3..aa4ebb18ce18bdc36a62fd4199f36c9fa62ce320 100644 (file)
@@ -3,7 +3,7 @@
 #include <lunaix/mm/cake.h>
 #include <lunaix/mm/valloc.h>
 
 #include <lunaix/mm/cake.h>
 #include <lunaix/mm/valloc.h>
 
-#include <sys/cpu.h>
+#include <asm/cpu.h>
 
 static struct cake_pile* blkio_reqpile;
 
 
 static struct cake_pile* blkio_reqpile;
 
index e9770ceaeb8beaebd084c1ad6a8d92f683cfe2b4..4ffff4deb2864f3ca76311acc5114bb2a92d3fa2 100644 (file)
@@ -5,7 +5,7 @@
 #include <lunaix/status.h>
 #include <lunaix/syslog.h>
 
 #include <lunaix/status.h>
 #include <lunaix/syslog.h>
 
-#include <sys/muldiv64.h>
+#include <asm/muldiv64.h>
 
 #include <klibc/crc.h>
 
 
 #include <klibc/crc.h>
 
index ebc60d75cd88da21fe81d8dadafd1b5903a23468..37e6bb4775ce991c1522c7e59d54a6ecae1f8e1c 100644 (file)
@@ -5,7 +5,7 @@
 #include <lunaix/spike.h>
 #include <lunaix/kcmd.h>
 #include <lunaix/sections.h>
 #include <lunaix/spike.h>
 #include <lunaix/kcmd.h>
 #include <lunaix/sections.h>
-#include <sys/mm/mm_defs.h>
+#include <asm/mm_defs.h>
 
 /**
  * @brief Reserve memory for kernel bootstrapping initialization
 
 /**
  * @brief Reserve memory for kernel bootstrapping initialization
index f84aab9fe1e3bbb2bde3bf70f7b1c3f523fa0680..1ae44802ba57616bb5f4e5980fa9a4d179897e42 100644 (file)
@@ -36,8 +36,8 @@
 #include <klibc/string.h>
 #include <sdbg/gdbstub.h>
 
 #include <klibc/string.h>
 #include <sdbg/gdbstub.h>
 
-#include <sys/port_io.h>
-#include <sys/cpu.h>
+#include <asm/x86_pmio.h>
+#include <asm/cpu.h>
 
 /*****************************************************************************
  * Macros
 
 /*****************************************************************************
  * Macros
index a2459bd64d00f4a8407af62733d1462c52e95b7a..77b332081adb652ea71f6f46508ac9fd977499d0 100644 (file)
@@ -5,8 +5,8 @@
 #include <lunaix/trace.h>
 #include <lunaix/sections.h>
 
 #include <lunaix/trace.h>
 #include <lunaix/sections.h>
 
-#include <sys/abi.h>
-#include <sys/mm/mm_defs.h>
+#include <asm/abi.h>
+#include <asm/mm_defs.h>
 #include <sys/trace.h>
 
 #include <klibc/string.h>
 #include <sys/trace.h>
 
 #include <klibc/string.h>
index d7b09f1d7ccd76e20b2f44791d90f2db95a5217e..1dbfd4555d712adc28411899193c3d5f51d80833 100644 (file)
@@ -32,7 +32,7 @@ elf_do_open(struct elf* elf, struct v_file* elf_file)
     return 0;
 }
 
     return 0;
 }
 
-defualt int
+_default int
 elf_open(struct elf* elf, const char* path)
 {
     struct v_dnode* elfdn;
 elf_open(struct elf* elf, const char* path)
 {
     struct v_dnode* elfdn;
@@ -50,7 +50,7 @@ elf_open(struct elf* elf, const char* path)
     return elf_do_open(elf, elffile);
 }
 
     return elf_do_open(elf, elffile);
 }
 
-defualt int
+_default int
 elf_openat(struct elf* elf, void* elf_vfile)
 {
     // so the ref count kept in sync
 elf_openat(struct elf* elf, void* elf_vfile)
 {
     // so the ref count kept in sync
@@ -58,7 +58,7 @@ elf_openat(struct elf* elf, void* elf_vfile)
     return elf_do_open(elf, elf_vfile);
 }
 
     return elf_do_open(elf, elf_vfile);
 }
 
-defualt int
+_default int
 elf_close(struct elf* elf)
 {
     if (elf->pheaders) {
 elf_close(struct elf* elf)
 {
     if (elf->pheaders) {
@@ -74,7 +74,7 @@ elf_close(struct elf* elf)
     return 0;
 }
 
     return 0;
 }
 
-defualt int
+_default int
 elf_static_linked(const struct elf* elf)
 {
     for (size_t i = 0; i < elf->eheader.e_phnum; i++) {
 elf_static_linked(const struct elf* elf)
 {
     for (size_t i = 0; i < elf->eheader.e_phnum; i++) {
@@ -86,7 +86,7 @@ elf_static_linked(const struct elf* elf)
     return 1;
 }
 
     return 1;
 }
 
-defualt size_t
+_default size_t
 elf_loadable_memsz(const struct elf* elf)
 {
     // XXX: Hmmmm, I am not sure if we need this. This is designed to be handy
 elf_loadable_memsz(const struct elf* elf)
 {
     // XXX: Hmmmm, I am not sure if we need this. This is designed to be handy
@@ -105,7 +105,7 @@ elf_loadable_memsz(const struct elf* elf)
     return sz;
 }
 
     return sz;
 }
 
-defualt int
+_default int
 elf_find_loader(const struct elf* elf, char* path_out, size_t len)
 {
     int retval = NO_LOADER;
 elf_find_loader(const struct elf* elf, char* path_out, size_t len)
 {
     int retval = NO_LOADER;
@@ -135,7 +135,7 @@ elf_find_loader(const struct elf* elf, char* path_out, size_t len)
     return retval;
 }
 
     return retval;
 }
 
-defualt int
+_default int
 elf_read_ehdr(struct elf* elf)
 {
     struct v_file* elfile = (struct v_file*)elf->elf_file;
 elf_read_ehdr(struct elf* elf)
 {
     struct v_file* elfile = (struct v_file*)elf->elf_file;
@@ -143,7 +143,7 @@ elf_read_ehdr(struct elf* elf)
     return elf_read(elfile, (void*)&elf->eheader, 0, SIZE_EHDR);
 }
 
     return elf_read(elfile, (void*)&elf->eheader, 0, SIZE_EHDR);
 }
 
-defualt int
+_default int
 elf_read_phdr(struct elf* elf)
 {
     int status = 0;
 elf_read_phdr(struct elf* elf)
 {
     int status = 0;
@@ -170,7 +170,7 @@ elf_read_phdr(struct elf* elf)
     return entries;
 }
 
     return entries;
 }
 
-defualt int
+_default int
 elf_check_exec(const struct elf* elf, int type)
 {
     const struct elf_ehdr* ehdr = &elf->eheader;
 elf_check_exec(const struct elf* elf, int type)
 {
     const struct elf_ehdr* ehdr = &elf->eheader;
@@ -178,7 +178,7 @@ elf_check_exec(const struct elf* elf, int type)
     return (ehdr->e_entry) && ehdr->e_type == type;
 }
 
     return (ehdr->e_entry) && ehdr->e_type == type;
 }
 
-defualt int
+_default int
 elf_check_arch(const struct elf* elf)
 {
     const struct elf_ehdr* ehdr = &elf->eheader;
 elf_check_arch(const struct elf* elf)
 {
     const struct elf_ehdr* ehdr = &elf->eheader;
index eaabf16bf8450d344e54c2e2f67e3c6a172a6ef3..124f9165acee3f71a928663f83c825002b2f8f3f 100644 (file)
@@ -4,7 +4,7 @@
 #include <lunaix/mm/valloc.h>
 #include <lunaix/spike.h>
 
 #include <lunaix/mm/valloc.h>
 #include <lunaix/spike.h>
 
-#include <sys/mm/mempart.h>
+#include <asm/mempart.h>
 
 int
 elf_smap(struct load_context* ldctx,
 
 int
 elf_smap(struct load_context* ldctx,
index 38c21210557b55ffca7ce7f50c55dd2d025b06f7..0dace13e9352ec6d2e2009968972846c01bcb8b5 100644 (file)
@@ -11,8 +11,8 @@
 #include <lunaix/syscall.h>
 #include <lunaix/syscall_utils.h>
 
 #include <lunaix/syscall.h>
 #include <lunaix/syscall_utils.h>
 
-#include <sys/abi.h>
-#include <sys/mm/mm_defs.h>
+#include <asm/abi.h>
+#include <asm/mm_defs.h>
 
 #include <klibc/string.h>
 
 
 #include <klibc/string.h>
 
index b1ac0302525bd6e698402bd9fcf753ebb1fe8a9b..e00013c247301a437c70ca107d24ce93e7395705 100644 (file)
@@ -4,7 +4,7 @@
 #include <lunaix/spike.h>
 
 #include <klibc/string.h>
 #include <lunaix/spike.h>
 
 #include <klibc/string.h>
-#include <sys/mm/pagetable.h>
+#include <asm/pagetable.h>
 
 int
 iso9660_open(struct v_inode* this, struct v_file* file)
 
 int
 iso9660_open(struct v_inode* this, struct v_file* file)
index 783d9b40fc062b5a0d2c124b97e8c445fdbbdeb3..84e04d0e9bb0eed8ae229e7818f259951b24ead3 100644 (file)
@@ -32,7 +32,7 @@ __vfs_walk(struct v_dnode* start,
         } else {
             start = vfs_sysroot;
             if (!vfs_sysroot->mnt) {
         } else {
             start = vfs_sysroot;
             if (!vfs_sysroot->mnt) {
-                panick("vfs: no root");
+                fail("vfs: no root");
             }
         }
 
             }
         }
 
index 8f4ed8d05becfd6dcc290914cdae45af5bf6112b..165d0bd0a17070c6099717ec06c3d11cff21a85c 100644 (file)
@@ -18,7 +18,7 @@
 #include <lunaix/mm/valloc.h>
 #include <lunaix/spike.h>
 
 #include <lunaix/mm/valloc.h>
 #include <lunaix/spike.h>
 
-#include <sys/mm/pagetable.h>
+#include <asm/pagetable.h>
 
 static struct twifs_node* fs_root;
 
 
 static struct twifs_node* fs_root;
 
index dff2de3f769569b0c6582e0193dc05d1ea148a90..62bdaeda41a53b27a520ffdb8f06826cb4ef0e8d 100644 (file)
@@ -6,7 +6,7 @@
 #include <klibc/strfmt.h>
 #include <klibc/string.h>
 
 #include <klibc/strfmt.h>
 #include <klibc/string.h>
 
-#include <sys/mm/pagetable.h>
+#include <asm/pagetable.h>
 
 #define TWIMAP_BUFFER_SIZE PAGE_SIZE
 
 
 #define TWIMAP_BUFFER_SIZE PAGE_SIZE
 
index a08418303f030c558e36a425d1172990eb9d5722..16c7976867e7da0252ec6fe3890a3d6245a3c95b 100644 (file)
@@ -2,13 +2,14 @@
 #include <lunaix/block.h>
 #include <lunaix/boot_generic.h>
 #include <lunaix/device.h>
 #include <lunaix/block.h>
 #include <lunaix/boot_generic.h>
 #include <lunaix/device.h>
-#include <lunaix/foptions.h>
 #include <lunaix/input.h>
 #include <lunaix/input.h>
+
 #include <lunaix/mm/cake.h>
 #include <lunaix/mm/pmm.h>
 #include <lunaix/mm/page.h>
 #include <lunaix/mm/valloc.h>
 #include <lunaix/mm/vmm.h>
 #include <lunaix/mm/cake.h>
 #include <lunaix/mm/pmm.h>
 #include <lunaix/mm/page.h>
 #include <lunaix/mm/valloc.h>
 #include <lunaix/mm/vmm.h>
+
 #include <lunaix/process.h>
 #include <lunaix/sched.h>
 #include <lunaix/spike.h>
 #include <lunaix/process.h>
 #include <lunaix/sched.h>
 #include <lunaix/spike.h>
 #include <lunaix/syslog.h>
 #include <lunaix/sections.h>
 
 #include <lunaix/syslog.h>
 #include <lunaix/sections.h>
 
-#include <hal/acpi/acpi.h>
 #include <hal/devtree.h>
 
 #include <hal/devtree.h>
 
-#include <sys/abi.h>
-#include <sys/mm/mm_defs.h>
-
-#include <klibc/strfmt.h>
-#include <klibc/string.h>
+#include <asm/mm_defs.h>
 
 LOG_MODULE("kinit")
 
 
 LOG_MODULE("kinit")
 
@@ -59,7 +55,7 @@ kmem_init(struct boot_handoff* bhctx)
 
     unsigned int i = ptep_vfn(ptep);
     do {
 
     unsigned int i = ptep_vfn(ptep);
     do {
-        if (l0tep_implie_vmnts(ptep)) {
+        if (lntep_implie_vmnts(ptep, L0T_SIZE)) {
             ptep++;
             continue;
         }
             ptep++;
             continue;
         }
@@ -118,8 +114,6 @@ __remap_and_load_dtb(struct boot_handoff* bhctx)
 void
 kernel_bootstrap(struct boot_handoff* bhctx)
 {
 void
 kernel_bootstrap(struct boot_handoff* bhctx)
 {
-    vmm_init();
-
     pmm_init(bhctx);
     // now we can start reserving physical space
 
     pmm_init(bhctx);
     // now we can start reserving physical space
 
index cffde1b73da750b9de8c7f62ac7b21d388600f81..f40e765b4ba8c91b8253c78bf33442ae88583cdc 100644 (file)
@@ -10,7 +10,7 @@
 #include <lunaix/hart_state.h>
 #include <lunaix/failsafe.h>
 
 #include <lunaix/hart_state.h>
 #include <lunaix/failsafe.h>
 
-#include <sys/mm/mm_defs.h>
+#include <asm/mm_defs.h>
 
 #include <klibc/string.h>
 
 
 #include <klibc/string.h>
 
@@ -77,15 +77,9 @@ done:
     context->fault_refva = refva;
 }
 
     context->fault_refva = refva;
 }
 
-static bool
+static void
 __prepare_fault_context(struct fault_context* fault)
 {
 __prepare_fault_context(struct fault_context* fault)
 {
-    if (!__arch_prepare_fault_context(fault)) {
-        return false;
-    }
-
-    __gather_memaccess_info(fault);
-
     pte_t* fault_ptep      = fault->fault_ptep;
     ptr_t  fault_va        = fault->fault_va;
     pte_t  fault_pte       = *fault_ptep;
     pte_t* fault_ptep      = fault->fault_ptep;
     ptr_t  fault_va        = fault->fault_va;
     pte_t  fault_pte       = *fault_ptep;
@@ -114,8 +108,6 @@ __prepare_fault_context(struct fault_context* fault)
     fault->resolving = pte_mkloaded(fault_pte);
     fault->kernel_vmfault = kernel_vmfault;
     fault->kernel_access  = kernel_context(fault->hstate);
     fault->resolving = pte_mkloaded(fault_pte);
     fault->kernel_vmfault = kernel_vmfault;
     fault->kernel_access  = kernel_context(fault->hstate);
-
-    return true;
 }
 
 static inline void
 }
 
 static inline void
@@ -269,8 +261,8 @@ fault_prealloc_page(struct fault_context* fault)
 }
 
 
 }
 
 
-static void noret
-__fail_to_resolve(struct fault_context* fault)
+void noret
+fault_resolving_failed(struct fault_context* fault)
 {
     if (fault->prealloc) {
         leaflet_return(fault->prealloc);
 {
     if (fault->prealloc) {
         leaflet_return(fault->prealloc);
@@ -340,32 +332,24 @@ done:
     return !!(fault->resolve_type & RESOLVE_OK);
 }
 
     return !!(fault->resolve_type & RESOLVE_OK);
 }
 
-void
-intr_routine_page_fault(const struct hart_state* hstate)
+bool
+handle_page_fault(struct fault_context* fault)
 {
 {
-    if (hstate->depth > 10) {
-        // Too many nested fault! we must messed up something
-        // XXX should we failed silently?
-        spin();
-    }
-
-    struct fault_context fault = { .hstate = hstate };
-
-    if (!__prepare_fault_context(&fault)) {
-        __fail_to_resolve(&fault);
-    }
+    __gather_memaccess_info(fault);
+    __prepare_fault_context(fault);
 
 
-    fault_prealloc_page(&fault);
+    fault_prealloc_page(fault);
 
 
-    if (!__try_resolve_fault(&fault)) {
-        __fail_to_resolve(&fault);
+    if (!__try_resolve_fault(fault)) {
+        return false;
     }
 
     }
 
-    if ((fault.resolve_type & NO_PREALLOC)) {
-        if (fault.prealloc) {
-            leaflet_return(fault.prealloc);
+    if ((fault->resolve_type & NO_PREALLOC)) {
+        if (fault->prealloc) {
+            leaflet_return(fault->prealloc);
         }
     }
 
         }
     }
 
-    tlb_flush_kernel(fault.fault_va);
-}
\ No newline at end of file
+    tlb_flush_kernel(fault->fault_va);
+    return true;
+}
index 972bbee150b80bfdbca41bd41a1489d6852b76f3..493d26cf3fe0876df64b1d5594f64fcfda67bd01 100644 (file)
@@ -5,7 +5,7 @@
 #include <lunaix/syscall.h>
 #include <lunaix/syscall_utils.h>
 
 #include <lunaix/syscall.h>
 #include <lunaix/syscall_utils.h>
 
-#include <sys/mm/mm_defs.h>
+#include <asm/mm_defs.h>
 
 #include <usr/lunaix/mann_flags.h>
 
 
 #include <usr/lunaix/mann_flags.h>
 
index 119efde25b389eae2750218665bd2a9d3428bb1c..31d9f3f5503ead2155867c4c9c9f01c1294a852f 100644 (file)
@@ -5,7 +5,7 @@
 #include <lunaix/mm/mmap.h>
 #include <lunaix/process.h>
 
 #include <lunaix/mm/mmap.h>
 #include <lunaix/process.h>
 
-#include <sys/mm/mm_defs.h>
+#include <asm/mm_defs.h>
 
 #include <klibc/string.h>
 
 
 #include <klibc/string.h>
 
@@ -29,158 +29,125 @@ __ptep_advancement(struct leaflet* leaflet, int level)
     return (1 << (leaflet_order(leaflet) % shifts)) - 1;
 }
 
     return (1 << (leaflet_order(leaflet) % shifts)) - 1;
 }
 
-static ptr_t
-vmscpy(ptr_t dest_mnt, ptr_t src_mnt, bool only_kernel)
+static inline int
+__descend(ptr_t dest_mnt, ptr_t src_mnt, ptr_t va, bool alloc)
 {
 {
-    pte_t* ptep_dest    = mkl0tep(mkptep_va(dest_mnt, 0));
-    pte_t* ptep         = mkl0tep(mkptep_va(src_mnt, 0));
-    pte_t* ptepd_kernel = mkl0tep(mkptep_va(dest_mnt, KERNEL_RESIDENT));
-    pte_t* ptep_kernel  = mkl0tep(mkptep_va(src_mnt, KERNEL_RESIDENT));
+    pte_t *dest, *src, pte;
 
 
-    // Build the self-reference on dest vms
+    int i = 0;
+    while (!pt_last_level(i))
+    {
+        dest = mklntep_va(i, dest_mnt, va);
+        src  = mklntep_va(i, src_mnt, va);
+        pte  = pte_at(src);
 
 
-    /* 
-     *        -- What the heck are ptep_ssm and ptep_sms ? --
-     *      
-     *      ptep_dest point to the pagetable itself that is mounted
-     *          at dest_mnt (or simply mnt): 
-     *              mnt -> self -> self -> self -> L0TE@offset
-     * 
-     *      ptep_sms shallowed the recursion chain:
-     *              self -> mnt -> self -> self -> L0TE@self
-     * 
-     *      ptep_ssm shallowed the recursion chain:
-     *              self -> self -> mnt -> self -> L0TE@self
-     *      
-     *      Now, here is the problem, back to x86_32, the translation is 
-     *      a depth-3 recursion:
-     *              L0T -> LFT -> Page
-     *      
-     *      So ptep_ssm will terminate at mnt and give us a leaf
-     *      slot for allocate a fresh page table for mnt:
-     *              self -> self -> L0TE@mnt
-     * 
-     *      but in x86_64 translation has extra two more step:
-     *              L0T -> L1T -> L2T -> LFT -> Page
-     *      
-     *      So we must continue push down.... 
-     *      ptep_sssms shallowed the recursion chain:
-     *              self -> self -> self -> mnt  -> L0TE@self
-     * 
-     *      ptep_ssssm shallowed the recursion chain:
-     *              self -> self -> self -> self -> L0TE@mnt
-     * 
-     *      Note: PML4: 2 extra steps
-     *            PML5: 3 extra steps
-    */
-    pte_t* ptep_ssm     = mkl0tep_va(VMS_SELF, dest_mnt);
-    pte_t* ptep_sms     = mkl1tep_va(VMS_SELF, dest_mnt) + VMS_SELF_L0TI;
-    pte_t  pte_sms      = mkpte_prot(KERNEL_PGTAB);
+        if (!pte_isloaded(pte) || pte_huge(pte)) {
+            break;
+        }
 
 
-    pte_sms = alloc_kpage_at(ptep_ssm, pte_sms, 0);
-    set_pte(ptep_sms, pte_sms);    
+        if (alloc && pte_isnull(pte_at(dest))) {
+            alloc_kpage_at(dest, pte, 0);
+        }
+
+        i++;
+    }
+
+    return i;
+}
+
+static inline void
+copy_leaf(pte_t* dest, pte_t* src, pte_t pte, int level)
+{
+    struct leaflet* leaflet;
+
+    set_pte(dest, pte);
+
+    if (!pte_isloaded(pte)) {
+        return;
+    }
+
+    leaflet = pte_leaflet(pte);
+    assert(leaflet_refcount(leaflet));
     
     
-    tlb_flush_kernel((ptr_t)dest_mnt);
-    tlb_flush_kernel((ptr_t)ptep_sms);
-
-    if (only_kernel) {
-        ptep = ptep_kernel;
-        ptep_dest += ptep_vfn(ptep_kernel);
-    } else {
-        ptep++;
-        ptep_dest++;
+    if (leaflet_ppfn(leaflet) == pte_ppfn(pte)) {
+        leaflet_borrow(leaflet);
     }
     }
+}
 
 
-    int level = 0;
+static inline void
+copy_root(pte_t* dest, pte_t* src, pte_t pte, int level)
+{
+    alloc_kpage_at(dest, pte, 0);
+}
+
+static void
+vmrcpy(ptr_t dest_mnt, ptr_t src_mnt, struct mm_region* region)
+{
+    pte_t *src, *dest;
+    ptr_t loc;
+    int level;
     struct leaflet* leaflet;
 
     struct leaflet* leaflet;
 
-    while (ptep < ptep_kernel)
+    loc  = region->start;
+    src  = mkptep_va(src_mnt, loc);
+    dest = mkptep_va(dest_mnt, loc);
+
+    level = __descend(dest_mnt, src_mnt, loc, true);
+
+    while (loc < region->end)
     {
     {
-        pte_t pte = *ptep;
+        pte_t pte = *src;
 
         if (pte_isnull(pte)) {
             goto cont;
         } 
         
         if (pt_last_level(level) || pte_huge(pte)) {
 
         if (pte_isnull(pte)) {
             goto cont;
         } 
         
         if (pt_last_level(level) || pte_huge(pte)) {
-            set_pte(ptep_dest, pte);
-
-            if (pte_isloaded(pte)) {
-                leaflet = pte_leaflet(pte);
-                assert(leaflet_refcount(leaflet));
-                
-                if (leaflet_ppfn(leaflet) == pte_ppfn(pte)) {
-                    leaflet_borrow(leaflet);
-                }
-            }
+            copy_leaf(dest, src, pte, level);
+            goto cont;
         }
         }
-        else if (!pt_last_level(level)) {
-            alloc_kpage_at(ptep_dest, pte, 0);
+        
+        if (!pt_last_level(level)) {
+            copy_root(dest, src, pte, level);
 
 
-            ptep = ptep_step_into(ptep);
-            ptep_dest = ptep_step_into(ptep_dest);
+            src = ptep_step_into(src);
+            dest = ptep_step_into(dest);
             level++;
 
             continue;
         }
         
     cont:
             level++;
 
             continue;
         }
         
     cont:
-        while (ptep_vfn(ptep) == MAX_PTEN - 1) {
+        loc += lnt_page_size(level);
+        while (ptep_vfn(src) == MAX_PTEN - 1) {
             assert(level > 0);
             assert(level > 0);
-            ptep = ptep_step_out(ptep);
-            ptep_dest = ptep_step_out(ptep_dest);
+            src = ptep_step_out(src);
+            dest = ptep_step_out(dest);
             level--;
         }
 
             level--;
         }
 
-        ptep++;
-        ptep_dest++;
-    }
-
-    // Ensure we step back to L0T
-    assert(!level);
-    assert(ptep_dest == ptepd_kernel);
-    
-    // Carry over the kernel (exclude last two entry)
-    unsigned int i = ptep_vfn(ptep);
-    while (i++ < MAX_PTEN) {
-        pte_t pte = *ptep;
-
-        if (l0tep_implie_vmnts(ptep)) {
-            goto _cont;
-        }
-
-        assert(!pte_isnull(pte));
-
-        // Ensure it is a next level pagetable,
-        //  we MAY relax this later allow kernel
-        //  to have huge leaflet mapped at L0T
-        leaflet = pte_leaflet_aligned(pte);
-        assert(leaflet_order(leaflet) == 0);
-
-        set_pte(ptep_dest, pte);
-        leaflet_borrow(leaflet);
-    
-    _cont:
-        ptep++;
-        ptep_dest++;
+        src++;
+        dest++;
     }
     }
-
-    return pte_paddr(pte_sms);
 }
 
 static void
 }
 
 static void
-vmsfree(ptr_t vm_mnt)
+vmrfree(ptr_t vm_mnt, struct mm_region* region)
 {
 {
+    pte_t *src, *end;
+    ptr_t loc;
+    int level;
     struct leaflet* leaflet;
     struct leaflet* leaflet;
-    pte_t* ptep_head    = mkl0tep(mkptep_va(vm_mnt, 0));
-    pte_t* ptep_self    = mkl0tep(mkptep_va(vm_mnt, VMS_SELF));
-    pte_t* ptep_kernel  = mkl0tep(mkptep_va(vm_mnt, KERNEL_RESIDENT));
 
 
-    int level = 0;
-    pte_t* ptep = ptep_head;
-    while (ptep < ptep_kernel)
+    loc  = region->start;
+    src  = mkptep_va(vm_mnt, region->start);
+    end  = mkptep_va(vm_mnt, region->end);
+
+    level = __descend(0, vm_mnt, loc, false);
+
+    while (src < end)
     {
     {
-        pte_t pte = *ptep;
+        pte_t pte = *src;
         ptr_t pa  = pte_paddr(pte);
 
         if (pte_isnull(pte)) {
         ptr_t pa  = pte_paddr(pte);
 
         if (pte_isnull(pte)) {
@@ -188,7 +155,7 @@ vmsfree(ptr_t vm_mnt)
         } 
 
         if (!pt_last_level(level) && !pte_huge(pte)) {
         } 
 
         if (!pt_last_level(level) && !pte_huge(pte)) {
-            ptep = ptep_step_into(ptep);
+            src = ptep_step_into(src);
             level++;
 
             continue;
             level++;
 
             continue;
@@ -198,13 +165,13 @@ vmsfree(ptr_t vm_mnt)
             leaflet = pte_leaflet_aligned(pte);
             leaflet_return(leaflet);
 
             leaflet = pte_leaflet_aligned(pte);
             leaflet_return(leaflet);
 
-            ptep += __ptep_advancement(leaflet, level);
+            src += __ptep_advancement(leaflet, level);
         }
 
     cont:
         }
 
     cont:
-        while (ptep_vfn(ptep) == MAX_PTEN - 1) {
-            ptep = ptep_step_out(ptep);
-            leaflet = pte_leaflet_aligned(pte_at(ptep));
+        while (ptep_vfn(src) == MAX_PTEN - 1) {
+            src = ptep_step_out(src);
+            leaflet = pte_leaflet_aligned(pte_at(src));
             
             assert(leaflet_order(leaflet) == 0);
             leaflet_return(leaflet);
             
             assert(leaflet_order(leaflet) == 0);
             leaflet_return(leaflet);
@@ -212,9 +179,100 @@ vmsfree(ptr_t vm_mnt)
             level--;
         }
 
             level--;
         }
 
-        ptep++;
+        src++;
+    }
+}
+
+static void
+vmscpy(struct proc_mm* dest_mm, struct proc_mm* src_mm)
+{
+    // Build the self-reference on dest vms
+
+    /* 
+     *        -- What the heck are ptep_ssm and ptep_sms ? --
+     *      
+     *      ptep_dest point to the pagetable itself that is mounted
+     *          at dest_mnt (or simply mnt): 
+     *              mnt -> self -> self -> self -> L0TE@offset
+     * 
+     *      ptep_sms shallowed the recursion chain:
+     *              self -> mnt -> self -> self -> L0TE@self
+     * 
+     *      ptep_ssm shallowed the recursion chain:
+     *              self -> self -> mnt -> self -> L0TE@self
+     *      
+     *      Now, here is the problem, back to x86_32, the translation is 
+     *      a depth-3 recursion:
+     *              L0T -> LFT -> Page
+     *      
+     *      So ptep_ssm will terminate at mnt and give us a leaf
+     *      slot for allocate a fresh page table for mnt:
+     *              self -> self -> L0TE@mnt
+     * 
+     *      but in x86_64 translation has extra two more step:
+     *              L0T -> L1T -> L2T -> LFT -> Page
+     *      
+     *      So we must continue push down.... 
+     *      ptep_sssms shallowed the recursion chain:
+     *              self -> self -> self -> mnt  -> L0TE@self
+     * 
+     *      ptep_ssssm shallowed the recursion chain:
+     *              self -> self -> self -> self -> L0TE@mnt
+     * 
+     *      Note: PML4: 2 extra steps
+     *            PML5: 3 extra steps
+    */
+
+    ptr_t  dest_mnt, src_mnt;
+    
+    dest_mnt = dest_mm->vm_mnt;
+    assert(dest_mnt);
+
+    pte_t* ptep_ssm     = mkl0tep_va(VMS_SELF, dest_mnt);
+    pte_t* ptep_smx     = mkl1tep_va(VMS_SELF, dest_mnt);
+    pte_t  pte_sms      = mkpte_prot(KERNEL_PGTAB);
+
+    pte_sms = alloc_kpage_at(ptep_ssm, pte_sms, 0);
+    set_pte(&ptep_smx[VMS_SELF_L0TI], pte_sms);
+    
+    tlb_flush_kernel((ptr_t)dest_mnt);
+
+    if (!src_mm) {
+        goto done;
+    }
+
+    src_mnt = src_mm->vm_mnt;
+
+    struct mm_region *pos, *n;
+    llist_for_each(pos, n, &src_mm->regions, head)
+    {
+        vmrcpy(dest_mnt, src_mnt, pos);
     }
 
     }
 
+done:;
+    procvm_link_kernel(dest_mnt);
+    
+    dest_mm->vmroot = pte_paddr(pte_sms);
+}
+
+static void
+vmsfree(struct proc_mm* mm)
+{
+    struct leaflet* leaflet;
+    ptr_t vm_mnt;
+    pte_t* ptep_self;
+    
+    vm_mnt    = mm->vm_mnt;
+    ptep_self = mkl0tep(mkptep_va(vm_mnt, VMS_SELF));
+
+    struct mm_region *pos, *n;
+    llist_for_each(pos, n, &mm->regions, head)
+    {
+        vmrfree(vm_mnt, pos);
+    }
+
+    procvm_unlink_kernel();
+
     leaflet = pte_leaflet_aligned(pte_at(ptep_self));
     leaflet_return(leaflet);
 }
     leaflet = pte_leaflet_aligned(pte_at(ptep_self));
     leaflet_return(leaflet);
 }
@@ -251,8 +309,8 @@ procvm_dupvms_mount(struct proc_mm* mm) {
    
     mm->heap = mm_current->heap;
     mm->vm_mnt = VMS_MOUNT_1;
    
     mm->heap = mm_current->heap;
     mm->vm_mnt = VMS_MOUNT_1;
-    mm->vmroot = vmscpy(VMS_MOUNT_1, VMS_SELF, false);
     
     
+    vmscpy(mm, mm_current);  
     region_copy_mm(mm_current, mm);
 }
 
     region_copy_mm(mm_current, mm);
 }
 
@@ -301,7 +359,7 @@ procvm_initvms_mount(struct proc_mm* mm)
     __attach_to_current_vms(mm);
 
     mm->vm_mnt = VMS_MOUNT_1;
     __attach_to_current_vms(mm);
 
     mm->vm_mnt = VMS_MOUNT_1;
-    mm->vmroot = vmscpy(VMS_MOUNT_1, VMS_SELF, true);
+    vmscpy(mm, NULL);
 }
 
 void
 }
 
 void
@@ -314,9 +372,9 @@ procvm_unmount_release(struct proc_mm* mm) {
         region_release(pos);
     }
 
         region_release(pos);
     }
 
-    vfree(mm);
-    vmsfree(vm_mnt);
+    vmsfree(mm);
     vms_unmount(vm_mnt);
     vms_unmount(vm_mnt);
+    vfree(mm);
 
     __detach_from_current_vms(mm);
 }
 
     __detach_from_current_vms(mm);
 }
index d8035db4fef36d9d532206bcd95fb3b736e9ef4e..8e9b5c7fa105d9625fce2a4914e2ddee2f4ee24e 100644 (file)
@@ -3,7 +3,7 @@
 #include <lunaix/spike.h>
 #include <lunaix/process.h>
 
 #include <lunaix/spike.h>
 #include <lunaix/process.h>
 
-#include <sys/mm/mempart.h>
+#include <asm/mempart.h>
 
 #include <klibc/string.h>
 
 
 #include <klibc/string.h>
 
index 6ec714a28c3229ac577a8c526c902a38853c20de..349f1fb1ef3def73cdc410e8a1645946bfdab0b6 100644 (file)
@@ -3,7 +3,7 @@
 #include <lunaix/spike.h>
 #include <lunaix/syslog.h>
 
 #include <lunaix/spike.h>
 #include <lunaix/syslog.h>
 
-#include <sys/mm/mempart.h>
+#include <asm/mempart.h>
 
 static ptr_t start = VMAP;
 static volatile ptr_t prev_va = 0;
 
 static ptr_t start = VMAP;
 static volatile ptr_t prev_va = 0;
index 24fa4227999a410bd9737c584e0b0f53422b6169..180d7f40fb55e93a52b33eddb76414026b1eeb8d 100644 (file)
@@ -3,17 +3,11 @@
 #include <lunaix/spike.h>
 #include <lunaix/syslog.h>
 
 #include <lunaix/spike.h>
 #include <lunaix/syslog.h>
 
-#include <sys/cpu.h>
-#include <sys/mm/mm_defs.h>
+#include <asm/cpu.h>
+#include <asm/mm_defs.h>
 
 LOG_MODULE("VM")
 
 
 LOG_MODULE("VM")
 
-void
-vmm_init()
-{
-    // XXX: something here?
-}
-
 pte_t
 vmm_tryptep(pte_t* ptep, size_t lvl_size)
 {
 pte_t
 vmm_tryptep(pte_t* ptep, size_t lvl_size)
 {
index 9f257aa72b73c22d7af6c4e6581d6f4e1d760531..6a6be4b3c15ae2321d9d67c49f8f714c69ff8793 100644 (file)
@@ -10,8 +10,8 @@
 #include <lunaix/signal.h>
 #include <lunaix/kpreempt.h>
 
 #include <lunaix/signal.h>
 #include <lunaix/kpreempt.h>
 
-#include <sys/abi.h>
-#include <sys/mm/mm_defs.h>
+#include <asm/abi.h>
+#include <asm/mm_defs.h>
 
 #include <klibc/string.h>
 
 
 #include <klibc/string.h>
 
index de533c7f5eda32e4292a55f495f1e900f50f1aad..bb5008df3dee688bf1de4d6c0a9eea511b18db02 100644 (file)
@@ -12,8 +12,8 @@
 #include <lunaix/exec.h>
 #include <lunaix/fs.h>
 
 #include <lunaix/exec.h>
 #include <lunaix/fs.h>
 
-#include <sys/abi.h>
-#include <sys/mm/mm_defs.h>
+#include <asm/abi.h>
+#include <asm/mm_defs.h>
 
 LOG_MODULE("PROC")
 
 
 LOG_MODULE("PROC")
 
index 945fc01bf6db0a8ae5edb1fcc48f867732fb3cbd..31775bfdf7c36d19c77120c3a67d76da2e11d747 100644 (file)
@@ -1,7 +1,7 @@
-#include <sys/abi.h>
-#include <sys/mm/mempart.h>
+#include <asm/abi.h>
+#include <asm/mempart.h>
 
 
-#include <sys/cpu.h>
+#include <asm/cpu.h>
 
 #include <lunaix/fs/taskfs.h>
 #include <lunaix/mm/cake.h>
 
 #include <lunaix/fs/taskfs.h>
 #include <lunaix/mm/cake.h>
@@ -20,7 +20,7 @@
 #include <lunaix/hart_state.h>
 #include <lunaix/kpreempt.h>
 
 #include <lunaix/hart_state.h>
 #include <lunaix/kpreempt.h>
 
-#include <lunaix/generic/isrm.h>
+#include <asm-generic/isrm.h>
 
 #include <klibc/string.h>
 
 
 #include <klibc/string.h>
 
@@ -346,7 +346,7 @@ get_free_pid() {
         ;
     
     if (unlikely(i == MAX_PROCESS)) {
         ;
     
     if (unlikely(i == MAX_PROCESS)) {
-        panick("Panic in Ponyville shimmer!");
+        fail("Panic in Ponyville shimmer!");
     }
 
     return i;
     }
 
     return i;
@@ -593,7 +593,7 @@ terminate_proccess(struct proc_info* proc, int exit_code) {
     assert(!kernel_process(proc));
 
     if (proc->pid == 1) {
     assert(!kernel_process(proc));
 
     if (proc->pid == 1) {
-        panick("Attempt to kill init");
+        fail("Attempt to kill init");
     }
 
     terminate_proc_only(proc, exit_code);
     }
 
     terminate_proc_only(proc, exit_code);
index a426ab39cdcccda3ac72d682366e341be2d8327f..0389a4a1ba0938c47f345bc0375ebec62185e517 100644 (file)
@@ -11,7 +11,7 @@
 
 #include <klibc/string.h>
 
 
 #include <klibc/string.h>
 
-#include <sys/mm/mempart.h>
+#include <asm/mempart.h>
 
 LOG_MODULE("SIG")
 
 
 LOG_MODULE("SIG")
 
index 493ed99cc61bd2e6102b571ec9a5b523b3a3661e..78cce8b53b89c8ff323b729af407289cc8a558c3 100644 (file)
@@ -9,8 +9,8 @@
 
 #include <usr/lunaix/threads.h>
 
 
 #include <usr/lunaix/threads.h>
 
-#include <sys/abi.h>
-#include <sys/mm/mm_defs.h>
+#include <asm/abi.h>
+#include <asm/mm_defs.h>
 
 LOG_MODULE("THREAD")
 
 
 LOG_MODULE("THREAD")
 
index 86eaf94ce67d83acac371388ac541c838369a3ce..e1983df04f74830678baac8e42eddb6d2546e694 100644 (file)
@@ -16,11 +16,4 @@ __assert_fail(const char* expr, const char* file, unsigned int line)
     ERROR("assertion fail (%s:%u)\n\t%s", file, line, expr);
     
     failsafe_diagnostic();
     ERROR("assertion fail (%s:%u)\n\t%s", file, line, expr);
     
     failsafe_diagnostic();
-}
-
-void noret
-panick(const char* msg)
-{
-    cpu_trap_panic(msg);
-    spin();
-}
+}
\ No newline at end of file
index af0f4883322b4f8c5cec88532a8b457d97f922f7..71da3355cb25be1037d04beda140345b77301c1b 100755 (executable)
@@ -18,4 +18,6 @@ make CMDLINE=${default_cmd} ARCH=${ARCH} MODE=${MODE:-debug} all -j5 || exit -1
     -- \
     -nographic &
 
     -- \
     -nographic &
 
-QMPORT=${hmp_port} gdb build/bin/kernel.bin -ex "target remote localhost:${gdb_port}"
\ No newline at end of file
+QMPORT=${hmp_port} gdb-multiarch \
+    build/bin/kernel.bin \
+    -ex "target remote localhost:${gdb_port}"
\ No newline at end of file
index c8d0730a7279f75cefecef48fbcdb39d7fd4408e..7b1f16baf5142ab0127c46cb1d855578425dffa9 100644 (file)
@@ -118,7 +118,7 @@ class MainMenuContext(tui.TuiContext):
 
         t = menu.create_title(self, "Lunaix Kernel Configuration" + suffix)
         t2 = menu.create_title(self, repo_info)
 
         t = menu.create_title(self, "Lunaix Kernel Configuration" + suffix)
         t2 = menu.create_title(self, repo_info)
-        t2.set_alignment(Alignment.BOT | Alignment.RIGHT)
+        t2.set_alignment(Alignment.BOT | Alignment.LEFT)
 
         root.add(t)
         root.add(t2)
 
         root.add(t)
         root.add(t2)
index 7858d7a5404dafdbe033184011fdfd95d4e642cd..55453f5b2d419b9d63a60a9264f0c6d425ada00b 100644 (file)
@@ -8,7 +8,7 @@ OUT  := $(addsuffix .tool,$(SRC))
 
 %.tool : %.c
        $(call status,CC,$<)
 
 %.tool : %.c
        $(call status,CC,$<)
-       @$(CC) $< -o $@
+       @cc $< -o $@
 
 .PHONY: all clean
 
 
 .PHONY: all clean
 
index 0c1dfe64286540fe231f3ec05597de893c7e5c27..18cce1cc830e7c7156ac60712c0acfb44d2ec549 100644 (file)
@@ -198,4 +198,6 @@ int main()
 
     // TODO test pthread + signal
     printf("All test passed.\n");
 
     // TODO test pthread + signal
     printf("All test passed.\n");
+
+    return 0;
 }
\ No newline at end of file
 }
\ No newline at end of file