/ / File: istartup.s / Author: John van Groningen / Machine: Intel 386 #define K6_0 0 #define d0 %eax #define d1 %ebx #define a0 %ecx #define a1 %edx #define a2 %ebp #define a3 %esi #define a4 %edi #define sp %esp #define d0w %ax #define d1w %bx #define a0w %cx #define a1w %dx #define a2w %bp #define a3w %si #define a4w %di #define d0b %al #define d1b %bl #define a0b %cl #define a1b %dl #define d0lb %al #define d0hb %ah #define d1lb %bl #define d1hb %bh #define SHARE_CHAR_INT #define MY_ITOS #define FINALIZERS #undef STACK_OVERFLOW_EXCEPTION_HANDLER #define WRITE_HEAP #undef MEASURE_GC #undef DEBUG #undef PREFETCH2 #define NO_BIT_INSTRUCTIONS #define ADJUST_HEAP_SIZE #define MARK_GC #define MARK_AND_COPY_GC #define NEW_DESCRIPTORS / #define PROFILE #define MODULE_NAMES_IN_TIME_PROFILER #undef COMPACT_GC_ONLY #define MINIMUM_HEAP_SIZE 8000 #define MINIMUM_HEAP_SIZE_2 4000 #if defined(_WINDOWS_) || defined (ELF) # define align(n) .align (1< a0: array _create_r_array: movl 4(sp),a1 pushl d0 shl $2,a1 movl free_heap_offset(a4),a2 lea 12-32(a2),a2 _sub_size_lp: addl a1,a2 subl $1,d0 jne _sub_size_lp popl d0 cmpl end_heap_offset(a4),a2 jb no_collect_4586 call collect_1l no_collect_4586: movl a0,a2 movl free_heap_offset(a4),a0 popl 8(a0) pop a1 movl $__ARRAY__+2,(a0) movl a1,4(a0) addl $12,a0 / a1: number of elements, a0: array / d0: element size, d1: element a size a2:a_element test d1,d1 je _create_r_array_0 subl $2,d1 jc _create_r_array_1 je _create_r_array_2 subl $2,d1 jc _create_r_array_3 je _create_r_array_4 jmp _create_r_array_5 _create_r_array_0: movl free_heap_offset(a4),d1 shl $2,a1 jmp _st_fillr0_array _fillr0_array: addl a1,a0 _st_fillr0_array: subl $1,d0 jnc _fillr0_array movl a0,free_heap_offset(a4) movl d1,a0 ret _create_r_array_1: movl free_heap_offset(a4),d1 shl $2,d0 jmp _st_fillr1_array _fillr1_array: movl a2,(a0) addl d0,a0 _st_fillr1_array: subl $1,a1 jnc _fillr1_array movl a0,free_heap_offset(a4) movl d1,a0 ret _create_r_array_2: movl free_heap_offset(a4),d1 shl $2,d0 jmp _st_fillr2_array _fillr2_array: movl a2,(a0) movl a2,4(a0) addl d0,a0 _st_fillr2_array: subl $1,a1 jnc _fillr2_array movl a0,free_heap_offset(a4) movl d1,a0 ret _create_r_array_3: movl free_heap_offset(a4),d1 shl $2,d0 jmp _st_fillr3_array _fillr3_array: movl a2,(a0) movl a2,4(a0) movl a2,8(a0) addl d0,a0 _st_fillr3_array: subl $1,a1 jnc _fillr3_array movl free_heap_offset(a4),a0 movl a0,free_heap_offset(a4) movl d1,a0 ret _create_r_array_4: movl free_heap_offset(a4),d1 shl $2,d0 jmp _st_fillr4_array _fillr4_array: movl a2,(a0) movl a2,4(a0) movl a2,8(a0) movl a2,12(a0) addl d0,a0 _st_fillr4_array: subl $1,a1 jnc _fillr4_array movl a0,free_heap_offset(a4) movl d1,a0 ret _create_r_array_5: push a3 movl d1,a3 subl $4,d0 subl d1,d0 subl $1,a3 shl $2,d0 jmp _st_fillr5_array _fillr5_array: movl a2,(a0) movl a2,4(a0) movl a2,8(a0) movl a2,12(a0) addl $16,a0 movl a3,d1 _copy_elem_5_lp: movl a2,(a0) addl $4,a0 subl $1,d1 jnc _copy_elem_5_lp addl d0,a0 _st_fillr5_array: subl $1,a1 jnc _fillr5_array pop a3 movl free_heap_offset(a4),d1 movl a0,free_heap_offset(a4) movl d1,a0 ret create_arrayB: movl d1,a1 addl $3,d1 shr $2,d1 movl free_heap_offset(a4),a0 lea -32+12(a0,d1,4),a2 cmpl end_heap_offset(a4),a2 jb no_collect_4575 pushl a1 call collect_0l popl a1 movl free_heap_offset(a4),a0 no_collect_4575: movl d0,a2 shl $8,a2 orl a2,d0 movl d0,a2 shl $16,a2 orl a2,d0 movl $__ARRAY__+2,(a0) movl a1,4(a0) movl $BOOL+2,8(a0) lea 12(a0),a2 jmp create_arrayBCI create_arrayC: movl d1,a1 addl $3,d1 shr $2,d1 movl free_heap_offset(a4),a0 lea -32+8(a0,d1,4),a2 cmpl end_heap_offset(a4),a2 jb no_collect_4578 pushl a1 call collect_0l popl a1 movl free_heap_offset(a4),a0 no_collect_4578: movl d0,a2 shl $8,a2 orl a2,d0 movl d0,a2 shl $16,a2 orl a2,d0 movl $__STRING__+2,(a0) movl a1,4(a0) lea 8(a0),a2 jmp create_arrayBCI create_arrayI: movl free_heap_offset(a4),a0 lea -32+12(a0,d1,4),a2 cmpl end_heap_offset(a4),a2 jb no_collect_4577 call collect_0l movl free_heap_offset(a4),a0 no_collect_4577: movl $__ARRAY__+2,(a0) movl d1,4(a0) lea 0(,d1,4),a1 movl $INT+2,8(a0) lea 12(a0),a2 create_arrayBCI: mov d1,a1 shr $1,d1 testb $1,a1b je st_filli_array movl d0,(a2) addl $4,a2 jmp st_filli_array filli_array: movl d0,(a2) movl d0,4(a2) addl $8,a2 st_filli_array: subl $1,d1 jnc filli_array movl a2,free_heap_offset(a4) ret create_arrayR: fstl -8(sp) movl free_heap_offset(a4),a0 lea -32+12+4(a0,d0,8),a2 movl -8(sp),d1 movl -4(sp),a1 cmpl end_heap_offset(a4),a2 jb no_collect_4579 pushl a1 call collect_0l popl a1 movl free_heap_offset(a4),a0 no_collect_4579: orl $4,a0 movl $__ARRAY__+2,(a0) movl d0,4(a0) movl $REAL+2,8(a0) movl a0,a2 addl $12,a2 jmp st_fillr_array fillr_array: movl d1,(a2) movl a1,4(a2) addl $8,a2 st_fillr_array: subl $1,d0 jnc fillr_array movl a2,free_heap_offset(a4) ret create_array: movl free_heap_offset(a4),a1 lea -32+12(a1,d0,4),a2 cmpl end_heap_offset(a4),a2 jb no_collect_4576 call collect_1l movl free_heap_offset(a4),a1 no_collect_4576: movl a0,d1 movl a1,a0 movl $__ARRAY__+2,(a1) movl d0,4(a1) movl $0,8(a1) lea 12(a1),a2 jmp fillr1_array / in 4(sp): number of elements, (sp): element descriptor / d0: element size, d1: element a size -> a0: array create_R_array: subl $2,d0 jc create_R_array_1 je create_R_array_2 subl $2,d0 jc create_R_array_3 je create_R_array_4 jmp create_R_array_5 create_R_array_1: pop a1 pop d0 / d0: number of elements, a1: element descriptor / d1: element a size movl free_heap_offset(a4),a0 lea -32+12(a0,d0,4),a2 cmpl end_heap_offset(a4),a2 jb no_collect_4581 pushl a1 call collect_0l popl a1 movl free_heap_offset(a4),a0 no_collect_4581: movl $__ARRAY__+2,(a0) movl d0,4(a0) movl a1,8(a0) lea 12(a0),a2 test d1,d1 je r_array_1_b movl -4(a3),d1 jmp fillr1_array r_array_1_b: movl 4(sp),d1 fillr1_array: movl d0,a1 shr $1,d0 testb $1,a1b je st_fillr1_array_1 movl d1,(a2) addl $4,a2 jmp st_fillr1_array_1 fillr1_array_lp: movl d1,(a2) movl d1,4(a2) addl $8,a2 st_fillr1_array_1: subl $1,d0 jnc fillr1_array_lp movl a2,free_heap_offset(a4) ret create_R_array_2: pop a1 pop d0 / d0: number of elements, a1: element descriptor / d1: element a size movl free_heap_offset(a4),a0 lea -32+12(a0,d0,8),a2 cmpl end_heap_offset(a4),a2 jb no_collect_4582 pushl a1 call collect_0 popl a1 movl free_heap_offset(a4),a0 no_collect_4582: movl $__ARRAY__+2,(a0) movl d0,4(a0) movl a1,8(a0) lea 12(a0),a2 cmpl $1,d1 jc r_array_2_bb movl -4(a3),d1 je r_array_2_ab r_array_2_aa: movl -8(a3),a1 jmp st_fillr2_array r_array_2_ab: movl 4(sp),a1 jmp st_fillr2_array r_array_2_bb: movl 4(sp),d1 movl 8(sp),a1 jmp st_fillr2_array fillr2_array_1: movl d1,(a2) movl a1,4(a2) addl $8,a2 st_fillr2_array: subl $1,d0 jnc fillr2_array_1 movl a2,free_heap_offset(a4) ret create_R_array_3: pop a1 pop d0 / d0: number of elements, a1: element descriptor / d1: element a size movl free_heap_offset(a4),a0 lea -32+12(a0,d0,8),a2 lea (a2,d0,4),a2 cmpl end_heap_offset(a4),a2 jb no_collect_4583 pushl a1 call collect_0l popl a1 movl free_heap_offset(a4),a0 no_collect_4583: movl $__ARRAY__+2,(a0) movl d0,4(a0) movl a1,8(a0) lea 12(a0),a2 cmpl $1,d1 jc r_array_3_bbb movl -4(a3),a0 je r_array_3_abb movl -8(a3),a1 cmpl $2,d1 je r_array_3_aab r_array_3_aaa: movl -12(a3),d1 jmp st_fillr3_array r_array_3_aab: movl (sp),d1 jmp st_fillr3_array r_array_3_abb: movl (sp),a1 movl 4(sp),d1 jmp st_fillr3_array r_array_3_bbb: movl (sp),a0 movl 4(sp),a1 movl 8(sp),d1 jmp st_fillr3_array fillr3_array_1: movl a0,(a2) movl a1,4(a2) movl d1,8(a2) addl $12,a2 st_fillr3_array: subl $1,d0 jnc fillr3_array_1 movl free_heap_offset(a4),a0 movl a2,free_heap_offset(a4) ret create_R_array_4: pop a1 pop d0 / d0: number of elements, a1: element descriptor / d1: element a size movl d0,a2 shl $4,a2 movl free_heap_offset(a4),a0 lea -32+12(a0,a2),a2 cmpl end_heap_offset(a4),a2 jb no_collect_4584 pushl a1 call collect_0l popl a1 movl free_heap_offset(a4),a0 no_collect_4584: movl $__ARRAY__+2,(a0) movl d0,4(a0) movl a1,8(a0) lea 12(a0),a2 push a3 cmp $1,d1 jc r_array_4_bbbb movl -4(a3),a0 je r_array_4_abbb movl -8(a3),a1 cmp $3,d1 jc r_array_4_aabb movl -12(a3),d1 je r_array_4_aaab r_array_4_aaaa: movl -16(a3),a3 jmp st_fillr4_array r_array_4_aaab: movl (sp),a3 jmp st_fillr4_array r_array_4_aabb: movl 0(sp),d1 movl 4(sp),a3 jmp st_fillr4_array r_array_4_abbb: movl (sp),a1 movl 4(sp),d1 movl 8(sp),a3 jmp st_fillr4_array r_array_4_bbbb: movl (sp),a0 movl 4(sp),a1 movl 8(sp),d1 movl 12(sp),a3 jmp st_fillr4_array fillr4_array: movl a0,(a2) movl a1,4(a2) movl d1,8(a2) movl a3,12(a2) addl $16,a2 st_fillr4_array: subl $1,d0 jnc fillr4_array pop a3 movl free_heap_offset(a4),a0 movl a2,free_heap_offset(a4) ret create_R_array_5: pop a1 pop a0 / a0: number of elements, a1: element descriptor / d0: element size-4, d1: element a size movl a0,a2 shl $4,a2 add $12-32,a2 addl free_heap_offset(a4),a2 subl $1,d0 pushl d0 sub_size_lp: lea (a2,a0,4),a2 subl $1,d0 jnc sub_size_lp popl d0 cmpl end_heap_offset(a4),a2 jb no_collect_4585 pushl a1 pushl a0 call collect_0l popl a0 popl a1 no_collect_4585: movl free_heap_offset(a4),a2 movl $__ARRAY__+2,(a2) movl a0,4(a2) movl a1,8(a2) popl a1 movl sp,4(a3) movl a1,(a3) test d1,d1 je r_array_5 movl d1,a1 shl $2,a1 negl a1 addl a3,a1 subl $1,d1 copy_a_to_b_lp5: pushl (a1) addl $4,a1 subl $1,d1 jnc copy_a_to_b_lp5 r_array_5: addl $12,a2 pushl a3 jmp st_fillr5_array fillr5_array_1: movl 4(sp),d1 movl d1,(a2) movl 8(sp),d1 movl d1,4(a2) movl 12(sp),d1 movl d1,8(a2) movl 16(sp),d1 movl d1,12(a2) lea 20(sp),a3 addl $16,a2 movl d0,a1 copy_elem_lp5: movl (a3),d1 addl $4,a3 movl d1,(a2) addl $4,a2 subl $1,a1 jnc copy_elem_lp5 st_fillr5_array: subl $1,a0 jnc fillr5_array_1 popl a3 movl free_heap_offset(a4),a0 movl a2,free_heap_offset(a4) movl 4(a3),sp jmp *(a3) repl_args_b: test d0,d0 jle repl_args_b_1 dec d0 je repl_args_b_4 mov 8(a0),a1 sub $2,d1 jne repl_args_b_2 mov a1,(a3) add $4,a3 jmp repl_args_b_4 repl_args_b_2: lea (a1,d0,4),a1 repl_args_b_3: mov -4(a1),a2 sub $4,a1 mov a2,(a3) add $4,a3 dec d0 jne repl_args_b_3 repl_args_b_4: mov 4(a0),a2 mov a2,(a3) add $4,a3 repl_args_b_1: ret push_arg_b: cmp $2,d1 jb push_arg_b_1 jne push_arg_b_2 cmp d0,d1 je push_arg_b_1 push_arg_b_2: mov 8(a0),a0 sub $2,d1 push_arg_b_1: mov (a0,d1,4),a0 ret del_args: mov (a0),d1 sub d0,d1 movswl -2(d1),d0 sub $2,d0 jge del_args_2 mov d1,(a1) mov 4(a0),a2 mov a2,4(a1) mov 8(a0),a2 mov a2,8(a1) ret del_args_2: jne del_args_3 mov d1,(a1) mov 4(a0),a2 mov a2,4(a1) mov 8(a0),a2 mov (a2),a2 mov a2,8(a1) ret del_args_3: movl free_heap_offset(a4),a2 lea -32(a2,d0,4),a2 cmpl end_heap_offset(a4),a2 jae del_args_gc del_args_r_gc: mov d1,(a1) mov a4,8(a1) mov 4(a0),a2 mov 8(a0),a0 mov a2,4(a1) movl free_heap_offset(a4),a2 del_args_copy_args: mov (a0),d1 add $4,a0 mov d1,(a2) add $4,a2 sub $1,d0 jg del_args_copy_args movl a2,free_heap_offset(a4) ret del_args_gc: call collect_2l jmp del_args_r_gc #if 0 o__S_P2: mov (a0),d0 mov 8(a0),a0 cmpw $2,-2(d0) je o__S_P2_2 mov (a0),a0 o__S_P2_2: ret ea__S_P2: mov 4(a1),d0 movl $__indirection,(a1) mov a0,4(a1) mov d0,a1 mov (a1),d0 testb $2,d0 jne ea__S_P2_1 mov a0,(a3) add $4,a3 mov a1,a0 call *d0 mov a0,a1 mov -4(a3),a0 sub $4,a3 ea__S_P2_1: mov (a1),d0 mov 8(a1),a1 cmpw $2,-2(d0) je ea__S_P2_2 mov (a1),a1 ea__S_P2_2: mov (a1),d0 testb $2,d0 jne ea__S_P2_3 sub $20,d0 jmp *d0 ea__S_P2_3: mov d0,(a0) mov 4(a1),a2 mov a2,4(a0) mov 8(a1),a2 mov a2,8(a0) ret #endif #ifdef NOCLIB tan_real: fptan fstsw %ax testb $0x04,%ah fstp %st(0) jnz tan_real_1 ret tan_real_1: fldl NAN_real fstp %st(1) ret asin_real: fld %st(0) fmul %st(0) fsubrl one_real fsqrt fpatan ret acos_real: fld %st(0) fmul %st(0) fsubrl one_real fsqrt fxch %st(1) fpatan ret atan_real: fldl one_real fpatan ret ln_real: fldln2 fxch %st(1) fyl2x ret @c_log10: fldl 4(sp) log10_real: fldlg2 fxch %st(1) fyl2x ret exp_real: fldl2e subl $16, sp fmulp %st(1) fstcw 8(sp) movw 8(sp),%ax andw $0xf3ff,%ax orw $0x0400,%ax movw %ax,10(sp) exp2_real_: fld %st fldcw 10(sp) frndint fldcw 8(sp) fsubr %st,%st(1) fxch %st(1) f2xm1 faddl one_real fscale addl $16,sp fstp %st(1) ret pow_real: sub $16,sp fstcw 8(sp) movw 8(sp),%ax andw $0xf3ff,%ax fxch %st(1) movw %ax,10(sp) fcoml zero_real fnstsw %ax sahf jz pow_zero jc pow_negative pow_real_: fyl2x jmp exp2_real_ pow_negative: fld %st(1) fldcw 10(sp) frndint fistl 12(sp) fldcw 8(sp) fsub %st(2),%st fcompl zero_real fstsw %ax sahf jnz pow_real_ fchs fyl2x fld %st fldcw 10(sp) frndint fldcw 8(sp) fsubr %st,%st(1) fxch %st(1) f2xm1 faddl one_real fscale testl $1,12(sp) fstp %st(1) jz exponent_even fchs exponent_even: add $16,sp ret pow_zero: fld %st(1) fcompl zero_real fnstsw %ax sahf jbe pow_real_ fldl zero_real fstp %st(1) add $16,sp ret truncate_real: subl $8,sp fstcw (sp) movw (sp),%ax orw $0x0c00,%ax movw %ax,2(sp) fldcw 2(sp) fistl 4(sp) fldcw (sp) movl 4(sp),d0 addl $8,sp ret entier_real: subl $8,sp fstcw (sp) movw (sp),%ax andw $0xf3ff,%ax orw $0x0400,%ax movw %ax,2(sp) fldcw 2(sp) fistl 4(sp) fldcw (sp) movl 4(sp),d0 addl $8,sp ret ceiling_real: subl $8,sp fstcw (sp) movw (sp),%ax andw $0xf3ff,%ax orw $0x0800,%ax movw %ax,2(sp) fldcw 2(sp) fistl 4(sp) fldcw (sp) movl 4(sp),d0 addl $8,sp ret round__real64: fistpll 12(%ecx) fldz ret truncate__real64: subl $4,sp fstcw (sp) movw (sp),%ax orw $0x0c00,%ax movw %ax,2(sp) fldcw 2(sp) fistpll 12(%ecx) fldcw (sp) addl $4,sp fldz ret entier__real64: subl $4,sp fstcw (sp) movw (sp),%ax andw $0xf3ff,%ax orw $0x0400,%ax movw %ax,2(sp) fldcw 2(sp) fistpll 12(%ecx) fldcw (sp) addl $4,sp fldz ret ceiling__real64: subl $4,sp fstcw (sp) movw (sp),%ax andw $0xf3ff,%ax orw $0x0800,%ax movw %ax,2(sp) fldcw 2(sp) fistpll 12(%ecx) fldcw (sp) addl $4,sp fldz ret int64a__to__real: fildll 12(%ecx) fstp %st(1) ret @c_pow: fldl 4(sp) fldl 12(sp) call pow_real fstp %st(1) ret @c_entier: fldl 4(sp) call entier_real fstp %st(0) ret #else section (tan_real) tan_real: sub $8,sp fstpl (sp) ffree %st(0) ffree %st(1) ffree %st(2) ffree %st(3) ffree %st(4) ffree %st(5) ffree %st(6) ffree %st(7) call @tan add $8,sp ret section (asin_real) asin_real: sub $8,sp fstpl (sp) ffree %st(0) ffree %st(1) ffree %st(2) ffree %st(3) ffree %st(4) ffree %st(5) ffree %st(6) ffree %st(7) call @asin add $8,sp ret section (acos_real) acos_real: sub $8,sp fstpl (sp) ffree %st(0) ffree %st(1) ffree %st(2) ffree %st(3) ffree %st(4) ffree %st(5) ffree %st(6) ffree %st(7) call @acos add $8,sp ret section (atan_real) atan_real: sub $8,sp fstpl (sp) ffree %st(0) ffree %st(1) ffree %st(2) ffree %st(3) ffree %st(4) ffree %st(5) ffree %st(6) ffree %st(7) call @atan add $8,sp ret section (ln_real) ln_real: sub $8,sp fstpl (sp) ffree %st(0) ffree %st(1) ffree %st(2) ffree %st(3) ffree %st(4) ffree %st(5) ffree %st(6) ffree %st(7) call @log add $8,sp ret section (log10_real) log10_real: sub $8,sp fstpl (sp) ffree %st(0) ffree %st(1) ffree %st(2) ffree %st(3) ffree %st(4) ffree %st(5) ffree %st(6) ffree %st(7) call @log10 add $8,sp ret section (exp_real) exp_real: sub $8,sp fstpl (sp) ffree %st(0) ffree %st(1) ffree %st(2) ffree %st(3) ffree %st(4) ffree %st(5) ffree %st(6) ffree %st(7) call @exp add $8,sp ret section (pow_real) pow_real: sub $16,sp fstpl 8(sp) fstpl (sp) ffree %st(0) ffree %st(1) ffree %st(2) ffree %st(3) ffree %st(4) ffree %st(5) ffree %st(6) ffree %st(7) call @pow add $16,sp ret section (entier_real) entier_real: sub $8,sp fstpl (sp) ffree %st(0) ffree %st(1) ffree %st(2) ffree %st(3) ffree %st(4) ffree %st(5) ffree %st(6) ffree %st(7) call @floor add $8,sp #endif r_to_i_real: subl $4,sp fistl (sp) pop d0 ret #ifdef NEW_DESCRIPTORS # include "iap.s" #endif #include "ithread.s"