commit 5ddcd61e944b7764c9717e508a63de16518767d7
parent 201b91d44e0983c43f6b460e0b6da9f8d0f458b4
Author: erai <erai@omiltem.net>
Date: Fri, 31 Jan 2025 16:20:09 +0000
use the standard calling convetion in the kernel
Diffstat:
M | cc0.c | | | 333 | +++++++++++++++++++++++++++++++++---------------------------------------------- |
M | cc1.om | | | 381 | ++++++++++++++++++++++++++++++++++++------------------------------------------- |
2 files changed, 311 insertions(+), 403 deletions(-)
diff --git a/cc0.c b/cc0.c
@@ -2752,241 +2752,209 @@ void( my_emit_builtin)(struct my_compiler* my_c){
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RDI),(my_R_RBP),(0UL),(0UL),(16UL));
+ (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RCX));
+ (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RDX));
+ (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RSI));
+ (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RDI));
(my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RDI),(0UL),(0UL),(0UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RDI),(my_R_RBP),(0UL),(0UL),(24UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RCX),(my_R_RDI),(0UL),(0UL),(0UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RDI),(my_R_RBP),(0UL),(0UL),(32UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RDX),(my_R_RDI),(0UL),(0UL),(0UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RDI),(my_R_RBP),(0UL),(0UL),(40UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RBX),(my_R_RDI),(0UL),(0UL),(0UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RCX),(my_R_RSI),(0UL),(0UL),(0UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RDX),(my_R_RDX),(0UL),(0UL),(0UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RBX),(my_R_RCX),(0UL),(0UL),(0UL));
(my_as_op)(((my_c)->my_s),(my_OP_CPUID));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RDI),(my_R_RBP),(0UL),(0UL),(16UL));
+ (my_as_opr)(((my_c)->my_s),(my_OP_POPR),(my_R_RDI));
+ (my_as_opr)(((my_c)->my_s),(my_OP_POPR),(my_R_RSI));
+ (my_as_opr)(((my_c)->my_s),(my_OP_POPR),(my_R_RDX));
+ (my_as_opr)(((my_c)->my_s),(my_OP_POPR),(my_R_RCX));
(my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RAX),(my_R_RDI),(0UL),(0UL),(0UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RDI),(my_R_RBP),(0UL),(0UL),(24UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RCX),(my_R_RDI),(0UL),(0UL),(0UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RDI),(my_R_RBP),(0UL),(0UL),(32UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RDX),(my_R_RDI),(0UL),(0UL),(0UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RDI),(my_R_RBP),(0UL),(0UL),(40UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RBX),(my_R_RDI),(0UL),(0UL),(0UL));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RCX),(my_R_RSI),(0UL),(0UL),(0UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RDX),(my_R_RDX),(0UL),(0UL),(0UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RBX),(my_R_RCX),(0UL),(0UL),(0UL));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"inb"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RDX),(my_R_RBP),(0UL),(0UL),(16UL));
+ (my_as_modrr)(((my_c)->my_s),(my_OP_MOVE),(my_R_RDX),(my_R_RDI));
(my_as_op)(((my_c)->my_s),(my_OP_IN));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"outb"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RDX),(my_R_RBP),(0UL),(0UL),(16UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(24UL));
+ (my_as_modrr)(((my_c)->my_s),(my_OP_MOVE),(my_R_RDX),(my_R_RDI));
+ (my_as_modrr)(((my_c)->my_s),(my_OP_MOVE),(my_R_RAX),(my_R_RSI));
(my_as_op)(((my_c)->my_s),(my_OP_OUT));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"inw"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RDX),(my_R_RBP),(0UL),(0UL),(16UL));
+ (my_as_modrr)(((my_c)->my_s),(my_OP_MOVE),(my_R_RDX),(my_R_RDI));
(my_as_emit)(((my_c)->my_s),(my_OP_OS));
(my_as_op)(((my_c)->my_s),(my_OP_IND));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"outw"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RDX),(my_R_RBP),(0UL),(0UL),(16UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(24UL));
+ (my_as_modrr)(((my_c)->my_s),(my_OP_MOVE),(my_R_RDX),(my_R_RDI));
+ (my_as_modrr)(((my_c)->my_s),(my_OP_MOVE),(my_R_RAX),(my_R_RSI));
(my_as_emit)(((my_c)->my_s),(my_OP_OS));
(my_as_op)(((my_c)->my_s),(my_OP_OUTD));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"ind"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RDX),(my_R_RBP),(0UL),(0UL),(16UL));
+ (my_as_modrr)(((my_c)->my_s),(my_OP_MOVE),(my_R_RDX),(my_R_RDI));
(my_as_op)(((my_c)->my_s),(my_OP_IND));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"outd"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RDX),(my_R_RBP),(0UL),(0UL),(16UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(24UL));
+ (my_as_modrr)(((my_c)->my_s),(my_OP_MOVE),(my_R_RDX),(my_R_RDI));
+ (my_as_modrr)(((my_c)->my_s),(my_OP_MOVE),(my_R_RAX),(my_R_RSI));
(my_as_op)(((my_c)->my_s),(my_OP_OUTD));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"rdmsr"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RCX),(my_R_RBP),(0UL),(0UL),(16UL));
+ (my_as_modrr)(((my_c)->my_s),(my_OP_MOVE),(my_R_RCX),(my_R_RDI));
(my_as_op)(((my_c)->my_s),(my_OP_RDMSR));
(my_as_modri)(((my_c)->my_s),(my_OP_MOVI),(my_R_RCX),(32UL));
(my_as_modr)(((my_c)->my_s),(my_OP_SHLM),(my_R_RDX));
(my_as_modrr)(((my_c)->my_s),(my_OP_ORRM),(my_R_RAX),(my_R_RDX));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"wrmsr"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(24UL));
- (my_as_modrr)(((my_c)->my_s),(my_OP_MOVE),(my_R_RDX),(my_R_RAX));
+ (my_as_modrr)(((my_c)->my_s),(my_OP_MOVE),(my_R_RAX),(my_R_RSI));
+ (my_as_modrr)(((my_c)->my_s),(my_OP_MOVE),(my_R_RDX),(my_R_RSI));
(my_as_modri)(((my_c)->my_s),(my_OP_MOVI),(my_R_RCX),(32UL));
(my_as_modr)(((my_c)->my_s),(my_OP_SHRM),(my_R_RDX));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RCX),(my_R_RBP),(0UL),(0UL),(16UL));
+ (my_as_modrr)(((my_c)->my_s),(my_OP_MOVE),(my_R_RCX),(my_R_RDI));
(my_as_op)(((my_c)->my_s),(my_OP_WRMSR));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"rdcr0"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
(my_as_modrr)(((my_c)->my_s),(my_OP_RDCRR),(my_R_CR0),(my_R_RAX));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"wrcr0"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RCX),(my_R_RBP),(0UL),(0UL),(16UL));
- (my_as_modrr)(((my_c)->my_s),(my_OP_WRCRR),(my_R_CR0),(my_R_RAX));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_modrr)(((my_c)->my_s),(my_OP_WRCRR),(my_R_CR0),(my_R_RDI));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"rdcr2"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
(my_as_modrr)(((my_c)->my_s),(my_OP_RDCRR),(my_R_CR2),(my_R_RAX));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"wrcr2"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RCX),(my_R_RBP),(0UL),(0UL),(16UL));
- (my_as_modrr)(((my_c)->my_s),(my_OP_WRCRR),(my_R_CR2),(my_R_RAX));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_modrr)(((my_c)->my_s),(my_OP_WRCRR),(my_R_CR2),(my_R_RDI));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"rdcr3"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
(my_as_modrr)(((my_c)->my_s),(my_OP_RDCRR),(my_R_CR3),(my_R_RAX));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"wrcr3"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RCX),(my_R_RBP),(0UL),(0UL),(16UL));
- (my_as_modrr)(((my_c)->my_s),(my_OP_WRCRR),(my_R_CR3),(my_R_RAX));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_modrr)(((my_c)->my_s),(my_OP_WRCRR),(my_R_CR3),(my_R_RDI));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"rdcr4"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
(my_as_modrr)(((my_c)->my_s),(my_OP_RDCRR),(my_R_CR4),(my_R_RAX));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"wrcr4"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RCX),(my_R_RBP),(0UL),(0UL),(16UL));
- (my_as_modrr)(((my_c)->my_s),(my_OP_WRCRR),(my_R_CR4),(my_R_RAX));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_modrr)(((my_c)->my_s),(my_OP_WRCRR),(my_R_CR4),(my_R_RDI));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"lgdt"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
(my_as_modri)(((my_c)->my_s),(my_OP_SUBI),(my_R_RSP),(16UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(24UL));
- (my_as_modri)(((my_c)->my_s),(my_OP_SUBI),(my_R_RAX),(1UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RAX),(my_R_RSP),(0UL),(0UL),(0UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(16UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RAX),(my_R_RSP),(0UL),(0UL),(2UL));
+ (my_as_modri)(((my_c)->my_s),(my_OP_SUBI),(my_R_RSI),(1UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RSI),(my_R_RSP),(0UL),(0UL),(0UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RDI),(my_R_RSP),(0UL),(0UL),(2UL));
(my_as_modm)(((my_c)->my_s),(my_OP_LGDTM),(my_R_RSP),(0UL),(0UL),(0UL));
(my_as_modri)(((my_c)->my_s),(my_OP_ADDI),(my_R_RSP),(16UL));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"lidt"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
(my_as_modri)(((my_c)->my_s),(my_OP_SUBI),(my_R_RSP),(16UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(24UL));
- (my_as_modri)(((my_c)->my_s),(my_OP_SUBI),(my_R_RAX),(1UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RAX),(my_R_RSP),(0UL),(0UL),(0UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(16UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RAX),(my_R_RSP),(0UL),(0UL),(2UL));
+ (my_as_modri)(((my_c)->my_s),(my_OP_SUBI),(my_R_RSI),(1UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RSI),(my_R_RSP),(0UL),(0UL),(0UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RDI),(my_R_RSP),(0UL),(0UL),(2UL));
(my_as_modm)(((my_c)->my_s),(my_OP_LIDTM),(my_R_RSP),(0UL),(0UL),(0UL));
(my_as_modri)(((my_c)->my_s),(my_OP_ADDI),(my_R_RSP),(16UL));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"lldt"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(16UL));
- (my_as_modr)(((my_c)->my_s),(my_OP_LLDTM),(my_R_RAX));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_modr)(((my_c)->my_s),(my_OP_LLDTM),(my_R_RDI));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"ltr"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(16UL));
- (my_as_modr)(((my_c)->my_s),(my_OP_LTRM),(my_R_RAX));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_modr)(((my_c)->my_s),(my_OP_LTRM),(my_R_RDI));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"lseg"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(24UL));
- (my_as_modrr)(((my_c)->my_s),(my_OP_WRSR),(my_R_ES),(my_R_RAX));
- (my_as_modrr)(((my_c)->my_s),(my_OP_WRSR),(my_R_DS),(my_R_RAX));
- (my_as_modrr)(((my_c)->my_s),(my_OP_WRSR),(my_R_FS),(my_R_RAX));
- (my_as_modrr)(((my_c)->my_s),(my_OP_WRSR),(my_R_GS),(my_R_RAX));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RBP));
+ (my_as_modrr)(((my_c)->my_s),(my_OP_MOVE),(my_R_RBP),(my_R_RSP));
+ (my_as_modrr)(((my_c)->my_s),(my_OP_WRSR),(my_R_ES),(my_R_RSI));
+ (my_as_modrr)(((my_c)->my_s),(my_OP_WRSR),(my_R_DS),(my_R_RSI));
+ (my_as_modrr)(((my_c)->my_s),(my_OP_WRSR),(my_R_FS),(my_R_RSI));
+ (my_as_modrr)(((my_c)->my_s),(my_OP_WRSR),(my_R_GS),(my_R_RSI));
+ (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RSI));
(my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RBP));
(my_as_op)(((my_c)->my_s),(my_OP_PUSHF));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(16UL));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RDI));
(my_as_op)(((my_c)->my_s),(my_OP_CALL));
(my_as_emit)(((my_c)->my_s),(5UL));
(my_as_emit)(((my_c)->my_s),(0UL));
@@ -2998,204 +2966,181 @@ void( my_emit_builtin)(struct my_compiler* my_c){
(my_as_emit)(((my_c)->my_s),(0UL));
(my_as_emit)(((my_c)->my_s),(0UL));
(my_as_op)(((my_c)->my_s),(my_OP_IRETQ));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_opr)(((my_c)->my_s),(my_OP_POPR),(my_R_RBP));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"hlt"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
(my_as_op)(((my_c)->my_s),(my_OP_HLT));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"cli"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
(my_as_op)(((my_c)->my_s),(my_OP_CLI));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"sti"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
(my_as_op)(((my_c)->my_s),(my_OP_STI));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"rdflags"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
(my_as_op)(((my_c)->my_s),(my_OP_PUSHF));
+ (my_as_opr)(((my_c)->my_s),(my_OP_POPR),(my_R_RAX));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"wrflags"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
- (my_as_op)(((my_c)->my_s),(my_OP_PUSHF));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(16UL));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RDI));
(my_as_op)(((my_c)->my_s),(my_OP_POPF));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"wbinvld"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(16UL));
- (my_as_modm)(((my_c)->my_s),(my_OP_WBINVD),(my_R_RAX),(0UL),(0UL),(0UL));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_modm)(((my_c)->my_s),(my_OP_WBINVD),(my_R_RDI),(0UL),(0UL),(0UL));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"invlpg"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(16UL));
- (my_as_modm)(((my_c)->my_s),(my_OP_INVLPGM),(my_R_RAX),(0UL),(0UL),(0UL));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_modm)(((my_c)->my_s),(my_OP_INVLPGM),(my_R_RDI),(0UL),(0UL),(0UL));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"_ssr0"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
(my_emit_ssr)((my_c));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"_isr0"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
(my_emit_isr)((my_c));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"_rgs"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
(my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RSI),(my_R_RBP),(0UL),(0UL),(16UL));
(my_as_emit)(((my_c)->my_s),(my_OP_GS));
(my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RSI),(0UL),(0UL),(0UL));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"_r32"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RSI),(my_R_RBP),(0UL),(0UL),(16UL));
(((my_c)->my_s)->my_bits32)=(1UL);
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RSI),(0UL),(0UL),(0UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RDI),(0UL),(0UL),(0UL));
(((my_c)->my_s)->my_bits32)=(0UL);
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"_w32"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RDI),(my_R_RBP),(0UL),(0UL),(16UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(24UL));
(((my_c)->my_s)->my_bits32)=(1UL);
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RAX),(my_R_RDI),(0UL),(0UL),(0UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RSI),(my_R_RDI),(0UL),(0UL),(0UL));
(((my_c)->my_s)->my_bits32)=(0UL);
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"_r16"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RSI),(my_R_RBP),(0UL),(0UL),(16UL));
(my_as_modrr)(((my_c)->my_s),(my_OP_XORRM),(my_R_RAX),(my_R_RAX));
(((my_c)->my_s)->my_bits32)=(1UL);
(my_as_modrm)(((my_c)->my_s),(my_OP_LOAD16),(my_R_RAX),(my_R_RDI),(0UL),(0UL),(0UL));
(((my_c)->my_s)->my_bits32)=(0UL);
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"_w16"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RDI),(my_R_RBP),(0UL),(0UL),(16UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(24UL));
(((my_c)->my_s)->my_bits32)=(1UL);
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE16),(my_R_RAX),(my_R_RDI),(0UL),(0UL),(0UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE16),(my_R_RSI),(my_R_RDI),(0UL),(0UL),(0UL));
(((my_c)->my_s)->my_bits32)=(0UL);
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"_rdrand"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
(my_as_modr)(((my_c)->my_s),(my_OP_RDRAND),(my_R_RAX));
+ (my_as_op)(((my_c)->my_s),(my_OP_RET));
}
(my_d)=((my_find)((my_c),((unsigned char *)"taskswitch"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&((unsigned long)(!(((my_d)->my_func_label)->my_fixed))))) {
(my_fixup_label)(((my_c)->my_s),((my_d)->my_func_label));
(my_add_symbol)(((my_c)->my_s),((my_d)->my_name),((my_d)->my_func_label));
- (my_as_op)(((my_c)->my_s),(my_OP_UD2));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RBP));
- (my_as_op)(((my_c)->my_s),(my_OP_PUSHF));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RBP),(my_R_RSP),(0UL),(0UL),(24UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(0UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RCX),(my_R_RBP),(0UL),(0UL),(8UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RDX),(my_R_RBP),(0UL),(0UL),(16UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RBX),(my_R_RBP),(0UL),(0UL),(24UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LEA),(my_R_RAX),(my_R_RSP),(0UL),(0UL),(24UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(32UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RSP),(0UL),(0UL),(8UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(40UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RSI),(my_R_RBP),(0UL),(0UL),(48UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RDI),(my_R_RBP),(0UL),(0UL),(56UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_R8),(my_R_RBP),(0UL),(0UL),(64UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_R9),(my_R_RBP),(0UL),(0UL),(72UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_R10),(my_R_RBP),(0UL),(0UL),(80UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_R11),(my_R_RBP),(0UL),(0UL),(88UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_R12),(my_R_RBP),(0UL),(0UL),(96UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_R13),(my_R_RBP),(0UL),(0UL),(104UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_R14),(my_R_RBP),(0UL),(0UL),(112UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_R15),(my_R_RBP),(0UL),(0UL),(120UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RSP),(0UL),(0UL),(16UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(128UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RSP),(0UL),(0UL),(0UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(136UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RAX),(my_R_RDI),(0UL),(0UL),(0UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RCX),(my_R_RDI),(0UL),(0UL),(8UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RDX),(my_R_RDI),(0UL),(0UL),(16UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RBX),(my_R_RDI),(0UL),(0UL),(24UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RBP),(my_R_RDI),(0UL),(0UL),(40UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RSI),(my_R_RDI),(0UL),(0UL),(48UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RDI),(my_R_RDI),(0UL),(0UL),(56UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_R8),(my_R_RDI),(0UL),(0UL),(64UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_R9),(my_R_RDI),(0UL),(0UL),(72UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_R10),(my_R_RDI),(0UL),(0UL),(80UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_R11),(my_R_RDI),(0UL),(0UL),(88UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_R12),(my_R_RDI),(0UL),(0UL),(96UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_R13),(my_R_RDI),(0UL),(0UL),(104UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_R14),(my_R_RDI),(0UL),(0UL),(112UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_R15),(my_R_RDI),(0UL),(0UL),(120UL));
+ (my_as_opr)(((my_c)->my_s),(my_OP_POPR),(my_R_RAX));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RAX),(my_R_RDI),(0UL),(0UL),(128UL));
(my_as_modrr)(((my_c)->my_s),(my_OP_RDSR),(my_R_CS),(my_R_RAX));
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(144UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RAX),(my_R_RDI),(0UL),(0UL),(144UL));
+ (my_as_op)(((my_c)->my_s),(my_OP_PUSHF));
+ (my_as_opr)(((my_c)->my_s),(my_OP_POPR),(my_R_RAX));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RAX),(my_R_RDI),(0UL),(0UL),(136UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RSP),(my_R_RDI),(0UL),(0UL),(32UL));
(my_as_modrr)(((my_c)->my_s),(my_OP_RDSR),(my_R_SS),(my_R_RAX));
- (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(152UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RBP),(my_R_RSP),(0UL),(0UL),(32UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RCX),(my_R_RBP),(0UL),(0UL),(8UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RDX),(my_R_RBP),(0UL),(0UL),(16UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RBX),(my_R_RBP),(0UL),(0UL),(24UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RSI),(my_R_RBP),(0UL),(0UL),(48UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RDI),(my_R_RBP),(0UL),(0UL),(56UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_R8),(my_R_RBP),(0UL),(0UL),(64UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_R9),(my_R_RBP),(0UL),(0UL),(72UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_R10),(my_R_RBP),(0UL),(0UL),(80UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_R11),(my_R_RBP),(0UL),(0UL),(88UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_R12),(my_R_RBP),(0UL),(0UL),(96UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_R13),(my_R_RBP),(0UL),(0UL),(104UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_R14),(my_R_RBP),(0UL),(0UL),(112UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_R15),(my_R_RBP),(0UL),(0UL),(120UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(152UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RAX),(my_R_RDI),(0UL),(0UL),(152UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RCX),(my_R_RDI),(0UL),(0UL),(8UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RDX),(my_R_RDI),(0UL),(0UL),(16UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RBX),(my_R_RDI),(0UL),(0UL),(24UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RBP),(my_R_RDI),(0UL),(0UL),(40UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RDI),(my_R_RDI),(0UL),(0UL),(56UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_R8),(my_R_RDI),(0UL),(0UL),(64UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_R9),(my_R_RDI),(0UL),(0UL),(72UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_R10),(my_R_RDI),(0UL),(0UL),(80UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_R11),(my_R_RDI),(0UL),(0UL),(88UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_R12),(my_R_RDI),(0UL),(0UL),(96UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_R13),(my_R_RDI),(0UL),(0UL),(104UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_R14),(my_R_RDI),(0UL),(0UL),(112UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_R15),(my_R_RDI),(0UL),(0UL),(120UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RSI),(0UL),(0UL),(152UL));
(my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(32UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RSI),(0UL),(0UL),(32UL));
(my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(136UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RSI),(0UL),(0UL),(136UL));
(my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(144UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RSI),(0UL),(0UL),(144UL));
(my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(128UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RSI),(0UL),(0UL),(128UL));
(my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(0UL));
- (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RBP),(my_R_RBP),(0UL),(0UL),(40UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RSI),(0UL),(0UL),(0UL));
+ (my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RSI),(my_R_RSI),(0UL),(0UL),(40UL));
(my_as_op)(((my_c)->my_s),(my_OP_IRETQ));
}
}
@@ -3257,7 +3202,6 @@ void( my_emit_isr)(struct my_compiler* my_c){
(my_as_modri)(((my_c)->my_s),(my_OP_SUBI),(my_R_RSP),(176UL));
(my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RBP),(my_R_RSP),(0UL),(0UL),(40UL));
(my_as_modrr)(((my_c)->my_s),(my_OP_MOVE),(my_R_RBP),(my_R_RSP));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RBP));
(my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(0UL));
(my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RCX),(my_R_RBP),(0UL),(0UL),(8UL));
(my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RDX),(my_R_RBP),(0UL),(0UL),(16UL));
@@ -3286,6 +3230,7 @@ void( my_emit_isr)(struct my_compiler* my_c){
(my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(32UL));
(my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RBP),(0UL),(0UL),((unsigned long)(((unsigned long)(176UL))+((unsigned long)(48UL)))));
(my_as_modrm)(((my_c)->my_s),(my_OP_STORE),(my_R_RAX),(my_R_RBP),(0UL),(0UL),(152UL));
+ (my_as_modrr)(((my_c)->my_s),(my_OP_MOVE),(my_R_RDI),(my_R_RBP));
(my_d)=((my_find)((my_c),((unsigned char *)"_isr"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&(((my_d)->my_func_label)->my_fixed))) {
(my_as_jmp)(((my_c)->my_s),(my_OP_CALL),((my_d)->my_func_label));
@@ -3315,7 +3260,7 @@ void( my_emit_isr)(struct my_compiler* my_c){
(my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_R14),(my_R_RBP),(0UL),(0UL),(112UL));
(my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_R15),(my_R_RBP),(0UL),(0UL),(120UL));
(my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RBP),(my_R_RBP),(0UL),(0UL),(40UL));
- (my_as_modri)(((my_c)->my_s),(my_OP_ADDI),(my_R_RSP),((unsigned long)(((unsigned long)(176UL))+((unsigned long)((unsigned long)(((long)(3UL))*((long)(8UL))))))));
+ (my_as_modri)(((my_c)->my_s),(my_OP_ADDI),(my_R_RSP),((unsigned long)(((unsigned long)(176UL))+((unsigned long)((unsigned long)(((long)(2UL))*((long)(8UL))))))));
(my_as_op)(((my_c)->my_s),(my_OP_IRETQ));
}
void( my_emit_kstart)(struct my_assembler* my_c){
@@ -3657,13 +3602,13 @@ void( my_emit_ssr)(struct my_compiler* my_c){
(my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RBP));
(my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RBP));
(my_as_modrr)(((my_c)->my_s),(my_OP_MOVE),(my_R_RBP),(my_R_RSP));
- (my_as_opr)(((my_c)->my_s),(my_OP_PUSHR),(my_R_RAX));
+ (my_as_modrr)(((my_c)->my_s),(my_OP_MOVE),(my_R_RDI),(my_R_RAX));
(my_d)=((my_find)((my_c),((unsigned char *)"_ssr"),((void *)0),(1UL)));
if ((unsigned long)(((my_d)->my_func_defined)&&(((my_d)->my_func_label)->my_fixed))) {
(my_as_jmp)(((my_c)->my_s),(my_OP_CALL),((my_d)->my_func_label));
}
(my_as_op)(((my_c)->my_s),(my_OP_CLI));
- (my_as_modri)(((my_c)->my_s),(my_OP_ADDI),(my_R_RSP),((unsigned long)(((long)(3UL))*((long)(8UL)))));
+ (my_as_modri)(((my_c)->my_s),(my_OP_ADDI),(my_R_RSP),((unsigned long)(((long)(2UL))*((long)(8UL)))));
(my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RAX),(my_R_RSP),(0UL),(0UL),(0UL));
(my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RDX),(my_R_RSP),(0UL),(0UL),(16UL));
(my_as_modrm)(((my_c)->my_s),(my_OP_LOAD),(my_R_RBX),(my_R_RSP),(0UL),(0UL),(24UL));
diff --git a/cc1.om b/cc1.om
@@ -1378,6 +1378,7 @@ func emit_ssr(c: *compiler) {
cdie(c, "no _save");
}
+ // Save the current stack
as_emit(c.s, OP_GS);
as_modra(c.s, OP_STORE, R_RSP, v.member_offset);
@@ -1386,6 +1387,7 @@ func emit_ssr(c: *compiler) {
cdie(c, "no global.curtask");
}
+ // Load the current task
as_emit(c.s, OP_GS);
as_modra(c.s, OP_LOAD, R_RSP, v.member_offset);
@@ -1394,9 +1396,11 @@ func emit_ssr(c: *compiler) {
cdie(c, "no task.stack");
}
+ // Load the kernel stack but reserve some space for the regs struct
as_modrm(c.s, OP_LOAD, R_RSP, R_RSP, 0, 0, v.member_offset);
as_modri(c.s, OP_ADDI, R_RSP, 4096 - 176);
+ // Save general purpose registers
as_modrm(c.s, OP_STORE, R_RAX, R_RSP, 0, 0, 0);
as_modrm(c.s, OP_STORE, R_RDX, R_RSP, 0, 0, 16);
as_modrm(c.s, OP_STORE, R_RBX, R_RSP, 0, 0, 24);
@@ -1413,12 +1417,14 @@ func emit_ssr(c: *compiler) {
as_modrm(c.s, OP_STORE, R_RCX, R_RSP, 0, 0, 128);
as_modrm(c.s, OP_STORE, R_R11, R_RSP, 0, 0, 136);
+ // Clear rcx, r11, trap, err
as_modrr(c.s, OP_XORRM, R_RAX, R_RAX);
as_modrm(c.s, OP_STORE, R_RAX, R_RSP, 0, 0, 8);
as_modrm(c.s, OP_STORE, R_RAX, R_RSP, 0, 0, 88);
as_modrm(c.s, OP_STORE, R_RAX, R_RSP, 0, 0, 160);
as_modrm(c.s, OP_STORE, R_RAX, R_RSP, 0, 0, 168);
+ // Save cs and ds
as_modri(c.s, OP_MOVI, R_RAX, 43);
as_modrm(c.s, OP_STORE, R_RAX, R_RSP, 0, 0, 144);
as_modri(c.s, OP_MOVI, R_RAX, 35);
@@ -1429,18 +1435,21 @@ func emit_ssr(c: *compiler) {
cdie(c, "no _save");
}
+ // Save the saved stack and switch back
as_emit(c.s, OP_GS);
as_modra(c.s, OP_LOAD, R_RAX, v.member_offset);
as_modrm(c.s, OP_STORE, R_RAX, R_RSP, 0, 0, 32);
as_modrr(c.s, OP_MOVE, R_RAX, R_RSP);
+ // Create a frame
as_modrr(c.s, OP_XORRM, R_RBP, R_RBP);
as_opr(c.s, OP_PUSHR, R_RBP);
as_opr(c.s, OP_PUSHR, R_RBP);
as_modrr(c.s, OP_MOVE, R_RBP, R_RSP);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_modrr(c.s, OP_MOVE, R_RDI, R_RAX);
+ // Call _ssr
d = find(c, "_ssr", nil, 1);
if (d.func_defined && d.func_label.fixed) {
as_jmp(c.s, OP_CALL, d.func_label);
@@ -1448,8 +1457,10 @@ func emit_ssr(c: *compiler) {
as_op(c.s, OP_CLI);
- as_modri(c.s, OP_ADDI, R_RSP, 3 * 8);
+ // Delete the frame
+ as_modri(c.s, OP_ADDI, R_RSP, 2 * 8);
+ // Restore the old registers
as_modrm(c.s, OP_LOAD, R_RAX, R_RSP, 0, 0, 0);
as_modrm(c.s, OP_LOAD, R_RDX, R_RSP, 0, 0, 16);
as_modrm(c.s, OP_LOAD, R_RBX, R_RSP, 0, 0, 24);
@@ -1469,6 +1480,7 @@ func emit_ssr(c: *compiler) {
as_modrm(c.s, OP_LOAD, R_RSP, R_RSP, 0, 0, 32);
+ // Return to the user
as_rex(c.s, OP_SYSRET, 0, 0, 0);
as_op(c.s, OP_SYSRET);
}
@@ -1486,41 +1498,53 @@ func emit_isr(c: *compiler) {
break;
}
reserve(c.s, 16);
+
if i == 8 || i == 10 || i == 11 || i == 12
|| i == 13 || i == 14 || i == 17 || i == 21
|| i == 29 || i == 30 {
+ // nop
as_emit(c.s, 0x90);
as_emit(c.s, 0x90);
} else {
+ // push 0
as_emit(c.s, 0x6a);
as_emit(c.s, 0x00);
}
+
+ // push i
as_emit(c.s, 0x68);
as_emit(c.s, i);
as_emit(c.s, 0x00);
as_emit(c.s, 0x00);
as_emit(c.s, 0x00);
+
+ // jmp out
as_emit(c.s, 0xe9);
as_emit(c.s, 0x00);
as_emit(c.s, 0x00);
as_emit(c.s, 0x00);
as_emit(c.s, 0x00);
addfixup(c.s, out);
+
+ // Align to 16
as_emit(c.s, 0x90);
as_emit(c.s, 0x90);
as_emit(c.s, 0x90);
as_emit(c.s, 0x90);
+
i = i + 1;
}
fixup_label(c.s, out);
- // save regs
+ // Allocate a regs struct
as_modri(c.s, OP_SUBI, R_RSP, 176);
+
+ // Save rbp and use it as the regs pointer
as_modrm(c.s, OP_STORE, R_RBP, R_RSP, 0, 0, 40);
as_modrr(c.s, OP_MOVE, R_RBP, R_RSP);
- as_opr(c.s, OP_PUSHR, R_RBP);
+ // Save general purpose registers
as_modrm(c.s, OP_STORE, R_RAX, R_RBP, 0, 0, 0);
as_modrm(c.s, OP_STORE, R_RCX, R_RBP, 0, 0, 8);
as_modrm(c.s, OP_STORE, R_RDX, R_RBP, 0, 0, 16);
@@ -1558,6 +1582,8 @@ func emit_isr(c: *compiler) {
as_modrm(c.s, OP_LOAD, R_RAX, R_RBP, 0, 0, 176 + 48);
as_modrm(c.s, OP_STORE, R_RAX, R_RBP, 0, 0, 152);
+ // Call _isr
+ as_modrr(c.s, OP_MOVE, R_RDI, R_RBP);
d = find(c, "_isr", nil, 1);
if (d.func_defined && d.func_label.fixed) {
as_jmp(c.s, OP_CALL, d.func_label);
@@ -1579,7 +1605,7 @@ func emit_isr(c: *compiler) {
as_modrm(c.s, OP_LOAD, R_RAX, R_RBP, 0, 0, 152);
as_modrm(c.s, OP_STORE, R_RAX, R_RBP, 0, 0, 176 + 48);
- // restore regs
+ // Restore general purpose registers
as_modrm(c.s, OP_LOAD, R_RAX, R_RBP, 0, 0, 0);
as_modrm(c.s, OP_LOAD, R_RCX, R_RBP, 0, 0, 8);
as_modrm(c.s, OP_LOAD, R_RDX, R_RBP, 0, 0, 16);
@@ -1595,9 +1621,11 @@ func emit_isr(c: *compiler) {
as_modrm(c.s, OP_LOAD, R_R14, R_RBP, 0, 0, 112);
as_modrm(c.s, OP_LOAD, R_R15, R_RBP, 0, 0, 120);
+ // Restore rbp
as_modrm(c.s, OP_LOAD, R_RBP, R_RBP, 0, 0, 40);
- as_modri(c.s, OP_ADDI, R_RSP, 176 + 3 * 8);
+ // Clean up regs + trap + err
+ as_modri(c.s, OP_ADDI, R_RSP, 176 + 2 * 8);
as_op(c.s, OP_IRETQ);
}
@@ -1646,267 +1674,235 @@ func emit_builtin(c: *compiler) {
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
- as_modrm(c.s, OP_LOAD, R_RDI, R_RBP, 0, 0, 16);
+ as_opr(c.s, OP_PUSHR, R_RCX);
+ as_opr(c.s, OP_PUSHR, R_RDX);
+ as_opr(c.s, OP_PUSHR, R_RSI);
+ as_opr(c.s, OP_PUSHR, R_RDI);
as_modrm(c.s, OP_LOAD, R_RAX, R_RDI, 0, 0, 0);
- as_modrm(c.s, OP_LOAD, R_RDI, R_RBP, 0, 0, 24);
- as_modrm(c.s, OP_LOAD, R_RCX, R_RDI, 0, 0, 0);
- as_modrm(c.s, OP_LOAD, R_RDI, R_RBP, 0, 0, 32);
- as_modrm(c.s, OP_LOAD, R_RDX, R_RDI, 0, 0, 0);
- as_modrm(c.s, OP_LOAD, R_RDI, R_RBP, 0, 0, 40);
- as_modrm(c.s, OP_LOAD, R_RBX, R_RDI, 0, 0, 0);
+ as_modrm(c.s, OP_LOAD, R_RCX, R_RSI, 0, 0, 0);
+ as_modrm(c.s, OP_LOAD, R_RDX, R_RDX, 0, 0, 0);
+ as_modrm(c.s, OP_LOAD, R_RBX, R_RCX, 0, 0, 0);
as_op(c.s, OP_CPUID);
- as_modrm(c.s, OP_LOAD, R_RDI, R_RBP, 0, 0, 16);
+ as_opr(c.s, OP_POPR, R_RDI);
+ as_opr(c.s, OP_POPR, R_RSI);
+ as_opr(c.s, OP_POPR, R_RDX);
+ as_opr(c.s, OP_POPR, R_RCX);
as_modrm(c.s, OP_STORE, R_RAX, R_RDI, 0, 0, 0);
- as_modrm(c.s, OP_LOAD, R_RDI, R_RBP, 0, 0, 24);
- as_modrm(c.s, OP_STORE, R_RCX, R_RDI, 0, 0, 0);
- as_modrm(c.s, OP_LOAD, R_RDI, R_RBP, 0, 0, 32);
- as_modrm(c.s, OP_STORE, R_RDX, R_RDI, 0, 0, 0);
- as_modrm(c.s, OP_LOAD, R_RDI, R_RBP, 0, 0, 40);
- as_modrm(c.s, OP_STORE, R_RBX, R_RDI, 0, 0, 0);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_modrm(c.s, OP_STORE, R_RCX, R_RSI, 0, 0, 0);
+ as_modrm(c.s, OP_STORE, R_RDX, R_RDX, 0, 0, 0);
+ as_modrm(c.s, OP_STORE, R_RBX, R_RCX, 0, 0, 0);
+ as_op(c.s, OP_RET);
}
d = find(c, "inb", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
- as_modrm(c.s, OP_LOAD, R_RDX, R_RBP, 0, 0, 16);
+ as_modrr(c.s, OP_MOVE, R_RDX, R_RDI);
as_op(c.s, OP_IN);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_op(c.s, OP_RET);
}
d = find(c, "outb", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
- as_modrm(c.s, OP_LOAD, R_RDX, R_RBP, 0, 0, 16);
- as_modrm(c.s, OP_LOAD, R_RAX, R_RBP, 0, 0, 24);
+ as_modrr(c.s, OP_MOVE, R_RDX, R_RDI);
+ as_modrr(c.s, OP_MOVE, R_RAX, R_RSI);
as_op(c.s, OP_OUT);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_op(c.s, OP_RET);
}
d = find(c, "inw", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
- as_modrm(c.s, OP_LOAD, R_RDX, R_RBP, 0, 0, 16);
+ as_modrr(c.s, OP_MOVE, R_RDX, R_RDI);
as_emit(c.s, OP_OS);
as_op(c.s, OP_IND);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_op(c.s, OP_RET);
}
d = find(c, "outw", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
- as_modrm(c.s, OP_LOAD, R_RDX, R_RBP, 0, 0, 16);
- as_modrm(c.s, OP_LOAD, R_RAX, R_RBP, 0, 0, 24);
+ as_modrr(c.s, OP_MOVE, R_RDX, R_RDI);
+ as_modrr(c.s, OP_MOVE, R_RAX, R_RSI);
as_emit(c.s, OP_OS);
as_op(c.s, OP_OUTD);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_op(c.s, OP_RET);
}
d = find(c, "ind", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
- as_modrm(c.s, OP_LOAD, R_RDX, R_RBP, 0, 0, 16);
+ as_modrr(c.s, OP_MOVE, R_RDX, R_RDI);
as_op(c.s, OP_IND);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_op(c.s, OP_RET);
}
d = find(c, "outd", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
- as_modrm(c.s, OP_LOAD, R_RDX, R_RBP, 0, 0, 16);
- as_modrm(c.s, OP_LOAD, R_RAX, R_RBP, 0, 0, 24);
+ as_modrr(c.s, OP_MOVE, R_RDX, R_RDI);
+ as_modrr(c.s, OP_MOVE, R_RAX, R_RSI);
as_op(c.s, OP_OUTD);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_op(c.s, OP_RET);
}
d = find(c, "rdmsr", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
- as_modrm(c.s, OP_LOAD, R_RCX, R_RBP, 0, 0, 16);
+ as_modrr(c.s, OP_MOVE, R_RCX, R_RDI);
as_op(c.s, OP_RDMSR);
as_modri(c.s, OP_MOVI, R_RCX, 32);
as_modr(c.s, OP_SHLM, R_RDX);
as_modrr(c.s, OP_ORRM, R_RAX, R_RDX);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_op(c.s, OP_RET);
}
d = find(c, "wrmsr", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
- as_modrm(c.s, OP_LOAD, R_RAX, R_RBP, 0, 0, 24);
- as_modrr(c.s, OP_MOVE, R_RDX, R_RAX);
+ as_modrr(c.s, OP_MOVE, R_RAX, R_RSI);
+ as_modrr(c.s, OP_MOVE, R_RDX, R_RSI);
as_modri(c.s, OP_MOVI, R_RCX, 32);
as_modr(c.s, OP_SHRM, R_RDX);
- as_modrm(c.s, OP_LOAD, R_RCX, R_RBP, 0, 0, 16);
+ as_modrr(c.s, OP_MOVE, R_RCX, R_RDI);
as_op(c.s, OP_WRMSR);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_op(c.s, OP_RET);
}
d = find(c, "rdcr0", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
as_modrr(c.s, OP_RDCRR, R_CR0, R_RAX);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_op(c.s, OP_RET);
}
d = find(c, "wrcr0", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
- as_modrm(c.s, OP_LOAD, R_RCX, R_RBP, 0, 0, 16);
- as_modrr(c.s, OP_WRCRR, R_CR0, R_RAX);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_modrr(c.s, OP_WRCRR, R_CR0, R_RDI);
+ as_op(c.s, OP_RET);
}
d = find(c, "rdcr2", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
as_modrr(c.s, OP_RDCRR, R_CR2, R_RAX);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_op(c.s, OP_RET);
}
d = find(c, "wrcr2", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
- as_modrm(c.s, OP_LOAD, R_RCX, R_RBP, 0, 0, 16);
- as_modrr(c.s, OP_WRCRR, R_CR2, R_RAX);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_modrr(c.s, OP_WRCRR, R_CR2, R_RDI);
+ as_op(c.s, OP_RET);
}
d = find(c, "rdcr3", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
as_modrr(c.s, OP_RDCRR, R_CR3, R_RAX);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_op(c.s, OP_RET);
}
d = find(c, "wrcr3", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
- as_modrm(c.s, OP_LOAD, R_RCX, R_RBP, 0, 0, 16);
- as_modrr(c.s, OP_WRCRR, R_CR3, R_RAX);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_modrr(c.s, OP_WRCRR, R_CR3, R_RDI);
+ as_op(c.s, OP_RET);
}
d = find(c, "rdcr4", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
as_modrr(c.s, OP_RDCRR, R_CR4, R_RAX);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_op(c.s, OP_RET);
}
d = find(c, "wrcr4", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
- as_modrm(c.s, OP_LOAD, R_RCX, R_RBP, 0, 0, 16);
- as_modrr(c.s, OP_WRCRR, R_CR4, R_RAX);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_modrr(c.s, OP_WRCRR, R_CR4, R_RDI);
+ as_op(c.s, OP_RET);
}
d = find(c, "lgdt", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
as_modri(c.s, OP_SUBI, R_RSP, 16);
- as_modrm(c.s, OP_LOAD, R_RAX, R_RBP, 0, 0, 24);
- as_modri(c.s, OP_SUBI, R_RAX, 1);
- as_modrm(c.s, OP_STORE, R_RAX, R_RSP, 0, 0, 0);
- as_modrm(c.s, OP_LOAD, R_RAX, R_RBP, 0, 0, 16);
- as_modrm(c.s, OP_STORE, R_RAX, R_RSP, 0, 0, 2);
+ as_modri(c.s, OP_SUBI, R_RSI, 1);
+ as_modrm(c.s, OP_STORE, R_RSI, R_RSP, 0, 0, 0);
+ as_modrm(c.s, OP_STORE, R_RDI, R_RSP, 0, 0, 2);
as_modm(c.s, OP_LGDTM, R_RSP, 0, 0, 0);
as_modri(c.s, OP_ADDI, R_RSP, 16);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_op(c.s, OP_RET);
}
d = find(c, "lidt", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
as_modri(c.s, OP_SUBI, R_RSP, 16);
- as_modrm(c.s, OP_LOAD, R_RAX, R_RBP, 0, 0, 24);
- as_modri(c.s, OP_SUBI, R_RAX, 1);
- as_modrm(c.s, OP_STORE, R_RAX, R_RSP, 0, 0, 0);
- as_modrm(c.s, OP_LOAD, R_RAX, R_RBP, 0, 0, 16);
- as_modrm(c.s, OP_STORE, R_RAX, R_RSP, 0, 0, 2);
+ as_modri(c.s, OP_SUBI, R_RSI, 1);
+ as_modrm(c.s, OP_STORE, R_RSI, R_RSP, 0, 0, 0);
+ as_modrm(c.s, OP_STORE, R_RDI, R_RSP, 0, 0, 2);
as_modm(c.s, OP_LIDTM, R_RSP, 0, 0, 0);
as_modri(c.s, OP_ADDI, R_RSP, 16);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_op(c.s, OP_RET);
}
d = find(c, "lldt", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
- as_modrm(c.s, OP_LOAD, R_RAX, R_RBP, 0, 0, 16);
- as_modr(c.s, OP_LLDTM, R_RAX);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_modr(c.s, OP_LLDTM, R_RDI);
+ as_op(c.s, OP_RET);
}
d = find(c, "ltr", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
- as_modrm(c.s, OP_LOAD, R_RAX, R_RBP, 0, 0, 16);
- as_modr(c.s, OP_LTRM, R_RAX);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_modr(c.s, OP_LTRM, R_RDI);
+ as_op(c.s, OP_RET);
}
d = find(c, "lseg", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
+ as_opr(c.s, OP_PUSHR, R_RBP);
+ as_modrr(c.s, OP_MOVE, R_RBP, R_RSP);
// es ds fs gs
- as_modrm(c.s, OP_LOAD, R_RAX, R_RBP, 0, 0, 24);
- as_modrr(c.s, OP_WRSR, R_ES, R_RAX);
- as_modrr(c.s, OP_WRSR, R_DS, R_RAX);
- as_modrr(c.s, OP_WRSR, R_FS, R_RAX);
- as_modrr(c.s, OP_WRSR, R_GS, R_RAX);
+ as_modrr(c.s, OP_WRSR, R_ES, R_RSI);
+ as_modrr(c.s, OP_WRSR, R_DS, R_RSI);
+ as_modrr(c.s, OP_WRSR, R_FS, R_RSI);
+ as_modrr(c.s, OP_WRSR, R_GS, R_RSI);
// ss
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_opr(c.s, OP_PUSHR, R_RSI);
// rsp
as_opr(c.s, OP_PUSHR, R_RBP);
// flags
as_op(c.s, OP_PUSHF);
// cs
- as_modrm(c.s, OP_LOAD, R_RAX, R_RBP, 0, 0, 16);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_opr(c.s, OP_PUSHR, R_RDI);
// rip
as_op(c.s, OP_CALL);
as_emit(c.s, 5);
@@ -1919,151 +1915,133 @@ func emit_builtin(c: *compiler) {
as_emit(c.s, 0);
as_emit(c.s, 0);
as_op(c.s, OP_IRETQ);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_opr(c.s, OP_POPR, R_RBP);
+ as_op(c.s, OP_RET);
}
d = find(c, "hlt", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
as_op(c.s, OP_HLT);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_op(c.s, OP_RET);
}
d = find(c, "cli", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
as_op(c.s, OP_CLI);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_op(c.s, OP_RET);
}
d = find(c, "sti", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
as_op(c.s, OP_STI);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_op(c.s, OP_RET);
}
d = find(c, "rdflags", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
as_op(c.s, OP_PUSHF);
+ as_opr(c.s, OP_POPR, R_RAX);
+ as_op(c.s, OP_RET);
}
d = find(c, "wrflags", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
- as_op(c.s, OP_PUSHF);
- as_modrm(c.s, OP_LOAD, R_RAX, R_RBP, 0, 0, 16);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_opr(c.s, OP_PUSHR, R_RDI);
as_op(c.s, OP_POPF);
+ as_op(c.s, OP_RET);
}
d = find(c, "wbinvld", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
- as_modrm(c.s, OP_LOAD, R_RAX, R_RBP, 0, 0, 16);
- as_modm(c.s, OP_WBINVD, R_RAX, 0, 0, 0);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_modm(c.s, OP_WBINVD, R_RDI, 0, 0, 0);
+ as_op(c.s, OP_RET);
}
d = find(c, "invlpg", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
- as_modrm(c.s, OP_LOAD, R_RAX, R_RBP, 0, 0, 16);
- as_modm(c.s, OP_INVLPGM, R_RAX, 0, 0, 0);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_modm(c.s, OP_INVLPGM, R_RDI, 0, 0, 0);
+ as_op(c.s, OP_RET);
}
d = find(c, "_ssr0", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
emit_ssr(c);
+ as_op(c.s, OP_RET);
}
d = find(c, "_isr0", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
emit_isr(c);
+ as_op(c.s, OP_RET);
}
d = find(c, "_rgs", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
as_modrm(c.s, OP_LOAD, R_RSI, R_RBP, 0, 0, 16);
as_emit(c.s, OP_GS);
as_modrm(c.s, OP_LOAD, R_RAX, R_RSI, 0, 0, 0);
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_op(c.s, OP_RET);
}
d = find(c, "_r32", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
- as_modrm(c.s, OP_LOAD, R_RSI, R_RBP, 0, 0, 16);
c.s.bits32 = 1;
- as_modrm(c.s, OP_LOAD, R_RAX, R_RSI, 0, 0, 0);
+ as_modrm(c.s, OP_LOAD, R_RAX, R_RDI, 0, 0, 0);
c.s.bits32 = 0;
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_op(c.s, OP_RET);
}
d = find(c, "_w32", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
- as_modrm(c.s, OP_LOAD, R_RDI, R_RBP, 0, 0, 16);
- as_modrm(c.s, OP_LOAD, R_RAX, R_RBP, 0, 0, 24);
c.s.bits32 = 1;
- as_modrm(c.s, OP_STORE, R_RAX, R_RDI, 0, 0, 0);
+ as_modrm(c.s, OP_STORE, R_RSI, R_RDI, 0, 0, 0);
c.s.bits32 = 0;
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_op(c.s, OP_RET);
}
d = find(c, "_r16", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
- as_modrm(c.s, OP_LOAD, R_RSI, R_RBP, 0, 0, 16);
as_modrr(c.s, OP_XORRM, R_RAX, R_RAX);
c.s.bits32 = 1;
as_modrm(c.s, OP_LOAD16, R_RAX, R_RDI, 0, 0, 0);
c.s.bits32 = 0;
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_op(c.s, OP_RET);
}
d = find(c, "_w16", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
- as_modrm(c.s, OP_LOAD, R_RDI, R_RBP, 0, 0, 16);
- as_modrm(c.s, OP_LOAD, R_RAX, R_RBP, 0, 0, 24);
c.s.bits32 = 1;
- as_modrm(c.s, OP_STORE16, R_RAX, R_RDI, 0, 0, 0);
+ as_modrm(c.s, OP_STORE16, R_RSI, R_RDI, 0, 0, 0);
c.s.bits32 = 0;
- as_opr(c.s, OP_PUSHR, R_RAX);
+ as_op(c.s, OP_RET);
}
d = find(c, "_rdrand", nil, 1);
@@ -2071,96 +2049,81 @@ func emit_builtin(c: *compiler) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
as_modr(c.s, OP_RDRAND, R_RAX);
+ as_op(c.s, OP_RET);
}
d = find(c, "taskswitch", nil, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
- as_op(c.s, OP_UD2);
-
- as_opr(c.s, OP_PUSHR, R_RBP);
- as_op(c.s, OP_PUSHF);
-
- as_modrm(c.s, OP_LOAD, R_RBP, R_RSP, 0, 0, 24);
// save
- as_modrm(c.s, OP_STORE, R_RAX, R_RBP, 0, 0, 0);
- as_modrm(c.s, OP_STORE, R_RCX, R_RBP, 0, 0, 8);
- as_modrm(c.s, OP_STORE, R_RDX, R_RBP, 0, 0, 16);
- as_modrm(c.s, OP_STORE, R_RBX, R_RBP, 0, 0, 24);
-
- // rsp
- as_modrm(c.s, OP_LEA, R_RAX, R_RSP, 0, 0, 24);
- as_modrm(c.s, OP_STORE, R_RAX, R_RBP, 0, 0, 32);
-
- // rbp
- as_modrm(c.s, OP_LOAD, R_RAX, R_RSP, 0, 0, 8);
- as_modrm(c.s, OP_STORE, R_RAX, R_RBP, 0, 0, 40);
-
- as_modrm(c.s, OP_STORE, R_RSI, R_RBP, 0, 0, 48);
- as_modrm(c.s, OP_STORE, R_RDI, R_RBP, 0, 0, 56);
- as_modrm(c.s, OP_STORE, R_R8, R_RBP, 0, 0, 64);
- as_modrm(c.s, OP_STORE, R_R9, R_RBP, 0, 0, 72);
- as_modrm(c.s, OP_STORE, R_R10, R_RBP, 0, 0, 80);
- as_modrm(c.s, OP_STORE, R_R11, R_RBP, 0, 0, 88);
- as_modrm(c.s, OP_STORE, R_R12, R_RBP, 0, 0, 96);
- as_modrm(c.s, OP_STORE, R_R13, R_RBP, 0, 0, 104);
- as_modrm(c.s, OP_STORE, R_R14, R_RBP, 0, 0, 112);
- as_modrm(c.s, OP_STORE, R_R15, R_RBP, 0, 0, 120);
+ as_modrm(c.s, OP_STORE, R_RAX, R_RDI, 0, 0, 0);
+ as_modrm(c.s, OP_STORE, R_RCX, R_RDI, 0, 0, 8);
+ as_modrm(c.s, OP_STORE, R_RDX, R_RDI, 0, 0, 16);
+ as_modrm(c.s, OP_STORE, R_RBX, R_RDI, 0, 0, 24);
+ as_modrm(c.s, OP_STORE, R_RBP, R_RDI, 0, 0, 40);
+ as_modrm(c.s, OP_STORE, R_RSI, R_RDI, 0, 0, 48);
+ as_modrm(c.s, OP_STORE, R_RDI, R_RDI, 0, 0, 56);
+ as_modrm(c.s, OP_STORE, R_R8, R_RDI, 0, 0, 64);
+ as_modrm(c.s, OP_STORE, R_R9, R_RDI, 0, 0, 72);
+ as_modrm(c.s, OP_STORE, R_R10, R_RDI, 0, 0, 80);
+ as_modrm(c.s, OP_STORE, R_R11, R_RDI, 0, 0, 88);
+ as_modrm(c.s, OP_STORE, R_R12, R_RDI, 0, 0, 96);
+ as_modrm(c.s, OP_STORE, R_R13, R_RDI, 0, 0, 104);
+ as_modrm(c.s, OP_STORE, R_R14, R_RDI, 0, 0, 112);
+ as_modrm(c.s, OP_STORE, R_R15, R_RDI, 0, 0, 120);
// rip
- as_modrm(c.s, OP_LOAD, R_RAX, R_RSP, 0, 0, 16);
- as_modrm(c.s, OP_STORE, R_RAX, R_RBP, 0, 0, 128);
-
- // flags
- as_modrm(c.s, OP_LOAD, R_RAX, R_RSP, 0, 0, 0);
- as_modrm(c.s, OP_STORE, R_RAX, R_RBP, 0, 0, 136);
-
+ as_opr(c.s, OP_POPR, R_RAX);
+ as_modrm(c.s, OP_STORE, R_RAX, R_RDI, 0, 0, 128);
// cs
as_modrr(c.s, OP_RDSR, R_CS, R_RAX);
- as_modrm(c.s, OP_STORE, R_RAX, R_RBP, 0, 0, 144);
-
+ as_modrm(c.s, OP_STORE, R_RAX, R_RDI, 0, 0, 144);
+ // flags
+ as_op(c.s, OP_PUSHF);
+ as_opr(c.s, OP_POPR, R_RAX);
+ as_modrm(c.s, OP_STORE, R_RAX, R_RDI, 0, 0, 136);
+ // rsp
+ as_modrm(c.s, OP_STORE, R_RSP, R_RDI, 0, 0, 32);
// ss
as_modrr(c.s, OP_RDSR, R_SS, R_RAX);
- as_modrm(c.s, OP_STORE, R_RAX, R_RBP, 0, 0, 152);
-
- as_modrm(c.s, OP_LOAD, R_RBP, R_RSP, 0, 0, 32);
+ as_modrm(c.s, OP_STORE, R_RAX, R_RDI, 0, 0, 152);
// restore
- as_modrm(c.s, OP_LOAD, R_RCX, R_RBP, 0, 0, 8);
- as_modrm(c.s, OP_LOAD, R_RDX, R_RBP, 0, 0, 16);
- as_modrm(c.s, OP_LOAD, R_RBX, R_RBP, 0, 0, 24);
- as_modrm(c.s, OP_LOAD, R_RSI, R_RBP, 0, 0, 48);
- as_modrm(c.s, OP_LOAD, R_RDI, R_RBP, 0, 0, 56);
- as_modrm(c.s, OP_LOAD, R_R8, R_RBP, 0, 0, 64);
- as_modrm(c.s, OP_LOAD, R_R9, R_RBP, 0, 0, 72);
- as_modrm(c.s, OP_LOAD, R_R10, R_RBP, 0, 0, 80);
- as_modrm(c.s, OP_LOAD, R_R11, R_RBP, 0, 0, 88);
- as_modrm(c.s, OP_LOAD, R_R12, R_RBP, 0, 0, 96);
- as_modrm(c.s, OP_LOAD, R_R13, R_RBP, 0, 0, 104);
- as_modrm(c.s, OP_LOAD, R_R14, R_RBP, 0, 0, 112);
- as_modrm(c.s, OP_LOAD, R_R15, R_RBP, 0, 0, 120);
+ as_modrm(c.s, OP_STORE, R_RCX, R_RDI, 0, 0, 8);
+ as_modrm(c.s, OP_STORE, R_RDX, R_RDI, 0, 0, 16);
+ as_modrm(c.s, OP_STORE, R_RBX, R_RDI, 0, 0, 24);
+ as_modrm(c.s, OP_STORE, R_RBP, R_RDI, 0, 0, 40);
+ as_modrm(c.s, OP_STORE, R_RDI, R_RDI, 0, 0, 56);
+ as_modrm(c.s, OP_STORE, R_R8, R_RDI, 0, 0, 64);
+ as_modrm(c.s, OP_STORE, R_R9, R_RDI, 0, 0, 72);
+ as_modrm(c.s, OP_STORE, R_R10, R_RDI, 0, 0, 80);
+ as_modrm(c.s, OP_STORE, R_R11, R_RDI, 0, 0, 88);
+ as_modrm(c.s, OP_STORE, R_R12, R_RDI, 0, 0, 96);
+ as_modrm(c.s, OP_STORE, R_R13, R_RDI, 0, 0, 104);
+ as_modrm(c.s, OP_STORE, R_R14, R_RDI, 0, 0, 112);
+ as_modrm(c.s, OP_STORE, R_R15, R_RDI, 0, 0, 120);
// ss
- as_modrm(c.s, OP_LOAD, R_RAX, R_RBP, 0, 0, 152);
+ as_modrm(c.s, OP_LOAD, R_RAX, R_RSI, 0, 0, 152);
as_opr(c.s, OP_PUSHR, R_RAX);
// rsp
- as_modrm(c.s, OP_LOAD, R_RAX, R_RBP, 0, 0, 32);
+ as_modrm(c.s, OP_LOAD, R_RAX, R_RSI, 0, 0, 32);
as_opr(c.s, OP_PUSHR, R_RAX);
// flags
- as_modrm(c.s, OP_LOAD, R_RAX, R_RBP, 0, 0, 136);
+ as_modrm(c.s, OP_LOAD, R_RAX, R_RSI, 0, 0, 136);
as_opr(c.s, OP_PUSHR, R_RAX);
// cs
- as_modrm(c.s, OP_LOAD, R_RAX, R_RBP, 0, 0, 144);
+ as_modrm(c.s, OP_LOAD, R_RAX, R_RSI, 0, 0, 144);
as_opr(c.s, OP_PUSHR, R_RAX);
// rip
- as_modrm(c.s, OP_LOAD, R_RAX, R_RBP, 0, 0, 128);
+ as_modrm(c.s, OP_LOAD, R_RAX, R_RSI, 0, 0, 128);
as_opr(c.s, OP_PUSHR, R_RAX);
- // finish up restore
- as_modrm(c.s, OP_LOAD, R_RAX, R_RBP, 0, 0, 0);
- as_modrm(c.s, OP_LOAD, R_RBP, R_RBP, 0, 0, 40);
+ // restore temporaries
+ as_modrm(c.s, OP_LOAD, R_RAX, R_RSI, 0, 0, 0);
+ as_modrm(c.s, OP_LOAD, R_RSI, R_RSI, 0, 0, 40);
// iretq
as_op(c.s, OP_IRETQ);