1 from pathlib import Path
3 intr_handler_h = "arch/x86/intrhnds.h"
4 intr_handler_c = "kernel/asm/x86/intrhnds.c"
5 intr_handler_s = "kernel/asm/x86/intrhnds.S"
8 # default value for each interrupt vector config
38 'vtype': 'IDT_INTERRUPT',
44 def get_workspace() -> Path:
46 return file.parent.parent.absolute()
49 def export_h(src: Path):
50 hfile = src.joinpath("includes", intr_handler_h)
51 code = '\n'.join(["ISR(%s)" % x for x in range(0, 256)])
52 with hfile.open(mode='w+') as f:
54 #ifndef __LUNAIX_INTRHNDS_H
55 #define __LUNAIX_INTRHNDS_H
56 #define ISR(iv) void _asm_isr##iv();
62 def get_vector_config(vec_num, cfg_name):
65 return config['default'][cfg_name]
67 if cfg_name not in attr:
68 return config['default'][cfg_name]
72 def export_c(src: Path):
73 cfile = src.joinpath(intr_handler_c)
75 for i in range(0, 256):
76 seg = get_vector_config(i, "seg")
77 dpl = get_vector_config(i, "dpl")
78 vtype = get_vector_config(i, "vtype")
80 f' _set_idt_entry({i}, {seg}, _asm_isr{i}, {dpl}, {vtype});')
81 code = '\n'.join(expr_list)
82 with cfile.open(mode='w+') as f:
84 #include <arch/x86/idt.h>
86 #include <{intr_handler_h}>
90 uint64_t _idt[IDT_ENTRY];
91 uint16_t _idt_limit = sizeof(_idt) - 1;
93 _set_idt_entry(u32_t vector,
94 uint16_t seg_selector,
99 uintptr_t offset = (uintptr_t)isr;
100 _idt[vector] = (offset & 0xffff0000) | IDT_ATTR(dpl, type);
102 _idt[vector] |= (seg_selector << 16) | (offset & 0x0000ffff);
111 def export_s(src: Path):
112 sfile = src.joinpath(intr_handler_s)
114 for i in range(0, 256):
115 has_errno = get_vector_config(i, "with_errno")
117 f" isr_template {i}, no_error_code={'0' if has_errno else '1'}")
119 code = '\n'.join(expr_list)
120 marco = '''.macro isr_template vector, no_error_code=1
121 .global _asm_isr\\vector
122 .type _asm_isr\\vector, @function
128 jmp interrupt_wrapper
130 with sfile.open(mode='w+') as f:
140 src = get_workspace()
146 if __name__ == "__main__":