Boot framework rework (#45)
[lunaix-os.git] / lunaix-os / arch / README.md
1 # Porting Lunaix to Other ISAs
2
3 This document briefly describe how to add support for other ISA
4
5 ## Adding Implementations
6
7 Lunaix provide bunch of headers that **MUST** be implemented.
8
9 + Follow the structure and derive the template header files according to
10   `arch/generic/includes`.
11   ! You **MUST** copy the header file and add your own
12   declaration & other stuffs.
13   ! You **MUST NOT** remove or modify the data structure,
14   function signature or any declaration that already in the template header
15   files unless stated explicitly.
16   ! Read the comment carefully, it may contains implementation recommendation
17   which is vital to the overall correctness.
18
19 + Add implementation to function signature defined in header files under
20   `includes/lunaix/generic`
21
22 + Add implementation of syscall dispatching (Reference: `arhc/x86/syscall.S`)  
23
24 + Add implementation of interrupt handler dispatching  (Reference:
25   `arhc/x86/exceptions/intrhnds.S`)  
26
27 + Add implementation of context switching, signal handling. (Reference:
28   `arhc/x86/exceptions/interrupt.S`)  
29   **TODO: make this procedure more standalone**
30
31 ## Preparing the Flows
32
33 When system boot up, Lunaix start the execution from `start_`, and then the
34 control flow will transfer to the `kinit.c::kernel_bootstrap`. A boot hand-over 
35 context `struct boot_handoff*` must passed to the bootstrap procedure.
36
37 Before jumping to `kernel_bootstrap`, one
38
39 + Must constructure a proper `struct boot_handoff` context.
40 + Must remap the kernel to architecturally favoured address range. 
41     **TODO: the algorithm for doing kernel remapping should be arch-agnostic**
42 + Must perform any essential CPU statet initialization, for example, setting up
43   address translation scheme, enable/disable ISA extensions, probing CPU/SOC
44   features.
45
46 ## Alternative Implementation
47
48 Most functions in `klibc` can be override by an architectural port. To achieve
49 this, one just need to add definition of such function. This allow port to
50 provide better performance on these library functions by exploiting the
51 architectural specific feature.
52
53 All non-static function from these header can be overriden:
54
55 + `klibc/string.h`
56 + `klibc/crc.h`
57 + `klibc/hash.h`