Rewrite the lunabuild toolchain with enhanced feature (#60)
[lunaix-os.git] / lunaix-os / arch / LConfig
1 from . import x86
2
3 @"Platform"
4 def architecture_support():
5     """
6         Config ISA related features
7     """
8
9     @flag
10     def arch_x86_32() -> bool:
11         when (arch is "i386")
12     
13     @flag
14     def arch_x86_64() -> bool:
15         when (arch is "x86_64")
16     
17     @flag
18     def arch_x86() -> bool:
19         when (arch is "i386")
20         when (arch is "x86_64")
21
22     @flag
23     def arch_bits_64() -> bool:
24         when (arch_bits is 64)
25
26     @flag
27     def arch_bits_32() -> bool:
28         when (arch_bits is 32)
29
30     @"Architecture"
31     def arch() -> "i386" | "x86_64":
32         """ 
33             Config ISA support 
34         """
35
36         match env("ARCH"):
37             case "i386": 
38                 return "i386"
39             case "aarch64": 
40                 return "aarch64"
41             case "rv64": 
42                 return "rv64"
43             case "x86_64": 
44                 return "x86_64"
45
46         print("unknown ARCH:", env("ARCH"), "default to x86_64")
47         return "x86_64"
48
49     @"Base operand size"
50     @readonly
51     def arch_bits() -> 32 | 64:
52         """ 
53             Defines the base size of a general register of the 
54             current selected ISA.
55
56             This the 'bits' part when we are talking about a CPU
57         """
58
59         match arch.val:
60             case "i386": 
61                 return 32
62             case "aarch64": 
63                 return 64
64             case "rv64": 
65                 return 64
66             case "x86_64": 
67                 return 64
68             case _:
69                 return 32
70