address generate_d2i_wrapper( address fcn ) { StubCodeMark mark(this, "StubRoutines", "d2i_wrapper"); address start = __ pc(); // Capture info about frame layout enum layout { FPUState_off = 0, ebp_off = FPUStateSizeInWords, edi_off, esi_off, ecx_off, ebx_off, saved_argument_off, saved_argument_off2, // 2nd half of double framesize }; assert(FPUStateSizeInWords == 27, "update stack layout"); // Save outgoing argument to stack across push_FPU_state() __ subl(esp, wordSize * 2); __ fstp_d(Address(esp)); // Save CPU & FPU state __ pushl(ebx); __ pushl(ecx); __ pushl(esi); __ pushl(edi); __ pushl(ebp); __ push_FPU_state(); // push_FPU_state() resets the FP top of stack // Load original double into FP top of stack __ fld_d(Address(esp, saved_argument_off * wordSize)); // Store double into stack as outgoing argument __ subl(esp, wordSize*2); __ fst_d(Address(esp)); // Prepare FPU for doing math in C-land __ empty_FPU_stack(); // Call the C code to massage the double. Result in EAX __ call_VM_leaf( fcn, 2 ); // Restore CPU & FPU state __ pop_FPU_state(); __ popl(ebp); __ popl(edi); __ popl(esi); __ popl(ecx); __ popl(ebx); __ addl(esp, wordSize * 2); __ ret(0); return start; }
static void pushf(int cn, const char *fmt, ...) { struct Chan *const c=&chl[cn]; size_t n, blen=c->eol-c->buf; va_list vl; time_t t; struct tm *tm; if (blen+LineLen>=c->sz) { c->sz *= 2; c->buf=realloc(c->buf, c->sz); if (!c->buf) panic("Out of memory."); c->eol=c->buf+blen; } t=time(0); if (!(tm=localtime(&t))) panic("Localtime failed."); n=strftime(c->eol, LineLen, DATEFMT, tm); c->eol[n++] = ' '; va_start(vl, fmt); n+=vsnprintf(c->eol+n, LineLen-n-1, fmt, vl); va_end(vl); strcat(c->eol, "\n"); if (n>=LineLen-1) c->eol+=LineLen-1; else c->eol+=n+1; if (cn==ch && c->n==0) { char *p=c->eol-n-1; if (p!=c->buf) waddch(scr.mw, '\n'); pushl(p, c->eol-1); wrefresh(scr.mw); } }
//--------------------------------------------------------------------------- // The following routine generates a subroutine to throw an asynchronous // UnknownError when an unsafe access gets a fault that could not be // reasonably prevented by the programmer. (Example: SIGBUS/OBJERR.) address generate_handler_for_unsafe_access() { StubCodeMark mark(this, "StubRoutines", "handler_for_unsafe_access"); address start = __ pc(); __ pushl(0); // hole for return address-to-be __ pushad(); // push registers Address next_pc(esp, RegisterImpl::number_of_registers * BytesPerWord); __ call(CAST_FROM_FN_PTR(address, handle_unsafe_access), relocInfo::runtime_call_type); __ movl(next_pc, eax); // stuff next address __ popad(); __ ret(0); // jump to next address return start; }
address generate_atomic_xchg() { StubCodeMark mark(this, "StubRoutines", "atomic_xchg"); address start = __ pc(); __ pushl(edx); Address exchange(esp, 2 * wordSize); Address dest_addr(esp, 3 * wordSize); __ movl(eax, exchange); __ movl(edx, dest_addr); __ xchg(eax, Address(edx, 0)); __ popl(edx); __ ret(0); return start; }
void InterpreterStubs::generate_primordial_to_current_thread() { entry("primordial_to_current_thread"); pushal(); pushl(ebp); movl(Address(Constant("_primordial_sp")), esp); get_thread(ecx); movl(esp, Address(ecx, Constant(Thread::stack_pointer_offset()))); popl(ebp); ret(); entry_end(); // primordial_to_current_thread entry("start_lightweight_thread_asm"); // Should never reach here on x86 int3(); entry_end(); // start_lightweight_thread_asm }
static void tredraw(void) { struct Chan *const c=&chl[ch]; char *q, *p; int llen=0, nl=-1; if (c->eol==c->buf) { wclear(scr.mw); wrefresh(scr.mw); return; } p=c->eol-1; if (c->n) { int i=c->n; for (; p>c->buf; p--) if (*p=='\n' && !i--) break; if (p==c->buf) c->n-=i; } q=p; while (nl<scr.y-2) { llen=0; while (*q!='\n' && q>c->buf) q--, llen++; nl += 1+llen/scr.x; if (q==c->buf) break; q--; } if (q!=c->buf) q+=2; for (llen=0; nl>scr.y-2; ) { /* Maybe we must split the top line. */ if (q[llen]=='\n' || llen>=scr.x) { q+=llen+(q[llen]=='\n'); llen=0; nl--; } else llen++; } wclear(scr.mw); wmove(scr.mw, 0, 0); while (q<p) q=pushl(q, p); wrefresh(scr.mw); }
void exception68(emu68_t * const emu68, const int vector, const int level) { if ( vector & 0x100 ) { /* Those are specific to EMU68 */ switch (vector) { case HWBREAK_VECTOR: case HWTRACE_VECTOR: break; default: assert(!"invalid eception vector"); } } else { int savesr = REG68.sr; int savest = emu68->status; emu68->status = EMU68_XCT; /* enter exception stat */ REG68.sr &= ~SR_T; /* no TRACE */ REG68.sr |= SR_S; /* Supervisor */ if ( savest == EMU68_XCT && ( vector == BUSERR_VECTOR || vector == ADRERR_VECTOR ) ) { /* Double fault ! */ emu68->status = EMU68_ERR; /* Halt processor */ } else if ( vector == RESET_VECTOR ) { REG68.sr |= SR_I; REG68.a[7] = read_L(RESET_SP_VECTOR << 2); REG68.pc = read_L(RESET_PC_VECTOR << 2); } else { if ( (unsigned int)level < 8u ) { SET_IPL(REG68.sr,level); } pushl(REG68.pc); pushw(savesr); REG68.pc = read_L(vector << 2); emu68->status = EMU68_NRM; /* Back to normal mode */ } } if (emu68->handler && emu68->handler(emu68, vector, emu68->cookie) ) { emu68->status = EMU68_BRK; /* User forced exit */ } }
address generate_verify_oop() { StubCodeMark mark(this, "StubRoutines", "verify_oop"); address start = __ pc(); // Incoming arguments on stack after saving eax: // // [tos ]: saved edx // [tos + 1]: saved EFLAGS // [tos + 2]: return address // [tos + 3]: char* error message // [tos + 4]: oop object to verify // [tos + 5]: saved eax - saved by caller and bashed Label exit, error; __ pushfd(); __ incl(Address((int)StubRoutines::verify_oop_count_addr(), relocInfo::none)); __ pushl(edx); // save edx // make sure object is 'reasonable' __ movl(eax, Address(esp, 4 * wordSize)); // get object __ testl(eax, eax); __ jcc(Assembler::zero, exit); // if obj is NULL it is ok // Check if the oop is in the right area of memory const int oop_mask = Universe::verify_oop_mask(); const int oop_bits = Universe::verify_oop_bits(); __ movl(edx, eax); __ andl(edx, oop_mask); __ cmpl(edx, oop_bits); __ jcc(Assembler::notZero, error); // make sure klass is 'reasonable' __ movl(eax, Address(eax, oopDesc::klass_offset_in_bytes())); // get klass __ testl(eax, eax); __ jcc(Assembler::zero, error); // if klass is NULL it is broken // Check if the klass is in the right area of memory const int klass_mask = Universe::verify_klass_mask(); const int klass_bits = Universe::verify_klass_bits(); __ movl(edx, eax); __ andl(edx, klass_mask); __ cmpl(edx, klass_bits); __ jcc(Assembler::notZero, error); // make sure klass' klass is 'reasonable' __ movl(eax, Address(eax, oopDesc::klass_offset_in_bytes())); // get klass' klass __ testl(eax, eax); __ jcc(Assembler::zero, error); // if klass' klass is NULL it is broken __ movl(edx, eax); __ andl(edx, klass_mask); __ cmpl(edx, klass_bits); __ jcc(Assembler::notZero, error); // if klass not in right area // of memory it is broken too. // return if everything seems ok __ bind(exit); __ movl(eax, Address(esp, 5 * wordSize)); // get saved eax back __ popl(edx); // restore edx __ popfd(); // restore EFLAGS __ ret(3 * wordSize); // pop arguments // handle errors __ bind(error); __ movl(eax, Address(esp, 5 * wordSize)); // get saved eax back __ popl(edx); // get saved edx back __ popfd(); // get saved EFLAGS off stack -- will be ignored __ pushad(); // push registers (eip = return address & msg are already pushed) __ call(CAST_FROM_FN_PTR(address, MacroAssembler::debug), relocInfo::runtime_call_type); __ popad(); __ ret(3 * wordSize); // pop arguments return start; }
void handle_v86_fault( Virtual86Regs_s * regs, uint32 nErrorCode ) { unsigned char *csp, *ssp; unsigned long ip, sp; int nInst; // if ( 0xffff == (regs->eip & 0xffff) && 0xffff == regs->cs ) { // return_to_32bit( regs, 0 ); // return; // } csp = ( unsigned char * )( regs->cs << 4 ); ssp = ( unsigned char * )( regs->ss << 4 ); sp = regs->esp & 0xffff; ip = regs->eip & 0xffff; nInst = popb( csp, ip ); switch ( nInst ) { /* Operand size override */ case 0x66: printk( "WARNING : 32 bit code run in v86 mode! Flags are not handled properly!\n" ); nInst = popb( csp, ip ); switch ( nInst ) { /* pushfd */ case 0x9c: regs->esp = ( regs->esp - 4 ) & 0xffff; regs->eip = ( regs->eip + 2 ) & 0xffff; pushl( ssp, sp, regs->eflags ); return; /* popfd */ case 0x9d: regs->esp = ( regs->esp + 4 ) & 0xffff; regs->eip = ( regs->eip + 2 ) & 0xffff; regs->eflags = popl( ssp, sp ); return; /* iretd */ case 0xcf: regs->esp = ( regs->esp + 12 ) & 0xffff; regs->eip = ( uint16 )( popl( ssp, sp ) & 0xffff ); regs->cs = ( uint16 )popl( ssp, sp ); return; /* need this to avoid a fallthrough */ default: printk( "ERROR : unknown v86 32 bit instruction %x\n", nInst ); return_to_32bit( regs, -EFAULT ); } /* pushf */ case 0x9c: regs->esp = ( regs->esp - 2 ) & 0xffff; regs->eip = ( regs->eip + 1 ) & 0xffff; pushw( ssp, sp, regs->eflags & 0xffff ); return; /* popf */ case 0x9d: regs->esp = ( regs->esp + 2 ) & 0xffff; regs->eip = ( regs->eip + 1 ) & 0xffff; regs->eflags = ( regs->eflags & 0xffff0000 ) | ( popw( ssp, sp ) & 0xffff ); return; /* int xx */ case 0xcd: { int intno = popb( csp, ip ); regs->eip = ( regs->eip + 2 ) & 0xffff; do_int( regs, intno, ssp, sp ); return; } /* iret */ case 0xcf: regs->esp = ( regs->esp + 6 ) & 0xffff; regs->eip = popw( ssp, sp ) & 0xffff; regs->cs = popw( ssp, sp ); regs->eflags = ( regs->eflags & 0xffff0000 ) | ( popw( ssp, sp ) & 0xffff ); if ( 0xffff == ( regs->eip & 0xffff ) && 0xffff == regs->cs ) { return_to_32bit( regs, 0 ); } return; /* cli */ case 0xfa: regs->eip = ( regs->eip + 1 ) & 0xffff; regs->eflags &= ~EFLG_IF; return; /* sti */ case 0xfb: /* The interrupts should actually be restored after the NEXT instruction! * Hope this works. As long as no DOS/BIOS code swaps the stack, * nothing bad should happen. */ regs->eip = ( regs->eip + 1 ) & 0xffff; regs->eflags |= EFLG_IF; return; default: printk( "ERROR : unknown v86 16 bit instruction %x\n", nInst ); return_to_32bit( regs, -EFAULT ); } }
void NativeGenerator::generate_native_system_entries() { comment_section("Native entry points for system functions"); rom_linkable_entry("native_jvm_unchecked_byte_arraycopy_entry"); jmp(Constant("native_system_arraycopy_entry")); rom_linkable_entry_end(); rom_linkable_entry("native_jvm_unchecked_char_arraycopy_entry"); jmp(Constant("native_system_arraycopy_entry")); rom_linkable_entry_end(); rom_linkable_entry("native_jvm_unchecked_int_arraycopy_entry"); jmp(Constant("native_system_arraycopy_entry")); rom_linkable_entry_end(); rom_linkable_entry("native_jvm_unchecked_long_arraycopy_entry"); jmp(Constant("native_system_arraycopy_entry")); rom_linkable_entry_end(); rom_linkable_entry("native_jvm_unchecked_obj_arraycopy_entry"); jmp(Constant("native_system_arraycopy_entry")); rom_linkable_entry_end(); rom_linkable_entry("native_system_arraycopy_entry"); wtk_profile_quick_call(/* param_size*/ 5); Label bailout, cont, try_2_byte, try_4_byte, try_8_byte, do_4_byte; // public static native void arraycopy(Object src, int src_position, // Object dst, int dst_position, // int length); comment("preserve method"); pushl(ebx); // 8 is for the preserved method and the return address int length_offset = JavaFrame::arg_offset_from_sp(0) + 8, dst_pos_offset = JavaFrame::arg_offset_from_sp(1) + 8, dst_offset = JavaFrame::arg_offset_from_sp(2) + 8, src_pos_offset = JavaFrame::arg_offset_from_sp(3) + 8, src_offset = JavaFrame::arg_offset_from_sp(4) + 8; comment("load arguments to registers"); movl(ecx, Address(esp, Constant(length_offset))); movl(edi, Address(esp, Constant(dst_pos_offset))); movl(edx, Address(esp, Constant(dst_offset))); movl(esi, Address(esp, Constant(src_pos_offset))); movl(eax, Address(esp, Constant(src_offset))); // eax = src // ebx = tmp register // edx = dst // ecx = length // esi = src_pos // edi = dst_pos comment("if (src == NULL) goto bailout;"); testl( eax, eax ); jcc(zero, Constant(bailout)); comment("if (dst == NULL) goto bailout;"); testl( edx, edx ); jcc(zero, Constant(bailout)); comment("if (length < 0 || src_pos < 0 || dst_pos < 0) goto bailout;"); movl(ebx, ecx); orl(ebx, esi); orl(ebx, edi); jcc(negative, Constant(bailout)); comment("if ((unsigned int) dst.length < (unsigned int) dst_pos + (unsigned int) length) goto bailout;"); movl(ebx, ecx); addl(ebx, edi); cmpl(Address(edx, Constant(Array::length_offset())), ebx); jcc(below, Constant(bailout)); comment("if ((unsigned int) src.length < (unsigned int) src_pos + (unsigned int) length) goto bailout;"); movl(ebx, ecx); addl(ebx, esi); cmpl(Address(eax, Constant(Array::length_offset())), ebx); jcc(below, Constant(bailout)); comment("Same near test"); comment("if (src.near != dst.near) goto bailout;"); movl(ebx, Address(eax, Constant(Oop::klass_offset()))); cmpl(ebx, Address(edx, Constant(Oop::klass_offset()))); jcc(not_equal, Constant(bailout)); comment("load the instance_size"); movl(ebx, Address(ebx, Constant(JavaNear::klass_offset()))); movsxw(ebx, Address(ebx, Constant(FarClass::instance_size_offset()))); comment("if (instance_size != size_type_array_1()) goto try_2_byte"); cmpl(ebx, Constant(InstanceSize::size_type_array_1)); jcc(not_equal, Constant(try_2_byte)); leal(esi, Address(eax, esi, times_1, Constant(Array::base_offset()))); leal(edi, Address(edx, edi, times_1, Constant(Array::base_offset()))); jmp(Constant(cont)); bind(try_2_byte); comment("if (instance_size != size_type_array_2()) goto try_4_byte"); cmpl(ebx, Constant(InstanceSize::size_type_array_2)); jcc(not_equal, Constant(try_4_byte)); leal(esi, Address(eax, esi, times_2, Constant(Array::base_offset()))); leal(edi, Address(edx, edi, times_2, Constant(Array::base_offset()))); shll(ecx, Constant(1)); jmp(Constant(cont)); bind(try_4_byte); comment("if (instance_size == size_type_array_4()) goto do_4_byte"); cmpl(ebx, Constant(InstanceSize::size_type_array_4)); jcc(equal, Constant(do_4_byte) ); comment("if (instance_size != size_obj_array()) goto bailout"); cmpl(ebx, Constant(InstanceSize::size_obj_array)); jcc(not_equal, Constant(bailout)); comment("if (dst < old_generation_end) goto bailout"); cmpl( edx, Address( Constant( "_old_generation_end" ) ) ); jcc( below, Constant(bailout)); bind(do_4_byte); leal(esi, Address(eax, esi, times_4, Constant(Array::base_offset()))); leal(edi, Address(edx, edi, times_4, Constant(Array::base_offset()))); shll(ecx, Constant(2)); bind(cont); comment("memmove(edi, esi, ecx);"); pushl(ecx); pushl(esi); pushl(edi); call(Constant("memmove")); addl(esp, Constant(16)); ret(Constant(5 * BytesPerStackElement)); comment("Bail out to the general arraycopy implementation"); bind(bailout); comment("pop method"); popl(ebx); if (AddExternCUnderscore) { emit_instruction("jmp _interpreter_method_entry"); } else { emit_instruction("jmp interpreter_method_entry"); } rom_linkable_entry_end(); // native_system_arraycopy_entry }
void NativeGenerator::generate_native_string_entries() { comment_section("Native entry points for string functions"); { //--------------------java.lang.String.indexof0--------------------------- rom_linkable_entry("native_string_indexof0_entry"); wtk_profile_quick_call(/* param_size*/ 2); comment("Pop the return address"); popl(edi); comment("Push zero for fromIndex"); pushl(Constant(0)); comment("Push back the return address"); pushl(edi); jmp(Constant("native_string_indexof_entry")); rom_linkable_entry_end(); // native_string_indexof0_entry //--------------------java.lang.String.indexof--------------------------- rom_linkable_entry("native_string_indexof_entry"); Label cont, loop, test, failure, success; wtk_profile_quick_call(/* param_size*/ 3); comment("Pop the return address"); popl(edi); comment("Pop the argument: fromIndex"); pop_int(eax, eax); comment("Pop the argument: ch"); pop_int(ebx, ebx); comment("Pop the receiver"); pop_obj(ecx, ecx); cmpl(ebx, Constant(0xFFFF)); jcc(greater, Constant(failure)); cmpl(eax, Constant(0)); jcc(greater_equal, Constant(cont)); movl(eax, Constant(0)); bind(cont); movl(esi, Address(ecx, Constant(String::count_offset()))); comment("if (fromIndex >= count) { return -1; }"); cmpl(eax, esi); jcc(greater_equal, Constant(failure)); movl(edx, Address(ecx, Constant(String::offset_offset()))); addl(eax, edx); // i = offset + fromIndex addl(edx, esi); // int max = offset + count; movl(esi, Address(ecx, Constant(String::value_offset()))); // v = value. jmp(Constant(test)); bind(loop); cmpw(Address(esi, eax, times_2, Constant(Array::base_offset())), ebx); jcc(equal, Constant(success)); incl(eax); bind(test); cmpl(eax, edx); jcc(less, Constant(loop)); comment("Return -1 by pushing the value and jumping to the return address"); bind(failure); push_int(-1); jmp(edi); comment("Return i - offset by pushing the value and jumping to the return address"); bind(success); movl(esi, Address(ecx, Constant(String::offset_offset()))); // i = offset + fromIndex subl(eax, esi); push_int(eax); jmp(edi); rom_linkable_entry_end(); // native_string_indexof_entry } //----------------------java.lang.String.charAt--------------------------- { rom_linkable_entry("native_string_charAt_entry"); if (AddExternCUnderscore) { emit_instruction("jmp _interpreter_method_entry"); } else { emit_instruction("jmp interpreter_method_entry"); } rom_linkable_entry_end(); } //----------------------java.lang.String(java.lang.StringBuffer)------------- { rom_linkable_entry("native_string_init_entry"); if (AddExternCUnderscore) { emit_instruction("jmp _interpreter_method_entry"); } else { emit_instruction("jmp interpreter_method_entry"); } rom_linkable_entry_end(); } //----------------------java.lang.String.equals(java.lang.Object)------------ { rom_linkable_entry("native_string_equals_entry"); if (AddExternCUnderscore) { emit_instruction("jmp _interpreter_method_entry"); } else { emit_instruction("jmp interpreter_method_entry"); } rom_linkable_entry_end(); } //----------------------java.lang.String.indexOf(java.lang.String)----------- { rom_linkable_entry("native_string_indexof0_string_entry"); if (AddExternCUnderscore) { emit_instruction("jmp _interpreter_method_entry"); } else { emit_instruction("jmp interpreter_method_entry"); } rom_linkable_entry_end(); } //----------------------java.lang.String.indexOf(java.lang.String)----------- { rom_linkable_entry("native_string_indexof_string_entry"); if (AddExternCUnderscore) { emit_instruction("jmp _interpreter_method_entry"); } else { emit_instruction("jmp interpreter_method_entry"); } rom_linkable_entry_end(); } //----------------------java.lang.String.compareTo--------------------------- { // java.lang.String.compareTo // Method int compareTo(java.lang.String) rom_linkable_entry("native_string_compareTo_entry"); wtk_profile_quick_call(/* param_size*/ 2); comment("preserve method"); pushl(ebx); // 8 is return address plus pushed method int str1_offset = JavaFrame::arg_offset_from_sp(0) + 8, str0_offset = JavaFrame::arg_offset_from_sp(1) + 8; comment("load arguments to registers"); movl(ecx, Address(esp, Constant(str1_offset))); movl(eax, Address(esp, Constant(str0_offset))); // eax: str0: this String // ebx: str1: String to compare against Label bailout; comment("Null check"); testl(ecx, ecx); jcc(zero, Constant(bailout)); comment("get str0.value[]"); movl(esi, Address(eax, Constant(String::value_offset()))); comment("get str0.offset"); movl(ebx, Address(eax, Constant(String::offset_offset()))); comment("compute start of character data"); leal(esi, Address(esi, ebx, times_2, Constant(Array::base_offset()))); comment("get str0.count"); movl(eax, Address(eax, Constant(String::count_offset()))); comment("get str1.value[]"); movl(edi, Address(ecx, Constant(String::value_offset()))); comment("get str1.offset"); movl(ebx, Address(ecx, Constant(String::offset_offset()))); comment("compute start of character data"); leal(edi, Address(edi, ebx, times_2, Constant(Array::base_offset()))); comment("get str1.count"); movl(ebx, Address(ecx, Constant(String::count_offset()))); // esi = str0 start of character data // edi = str1 start of character data // eax = str0 length // ebx = str1 length Label str1_longest; subl(eax, ebx); jcc(greater_equal, Constant(str1_longest)); // str1 is longer than str0 addl(ebx, eax); bind(str1_longest); // esi = str0 start of character data // edi = str1 start of character data // eax = str0.count - str1.count // ebx = min(str0.count, str1.count) // save str0.count - str1.count, we might need it later pushl(eax); xorl(ecx, ecx); Label loop, check_lengths, done; bind(loop); cmpl(ecx, ebx); jcc(above_equal, Constant(check_lengths)); movzxw(eax, Address(esi, ecx, times_2)); movzxw(edx, Address(edi, ecx, times_2)); subl(eax, edx); jcc(not_equal, Constant(done)); incl(ecx); jmp(Constant(loop)); bind(check_lengths); movl(eax, Address(esp)); bind(done); popl(ebx); // remove saved length difference // Push result on stack and return to caller popl(ebx); // remove method popl(edi); // pop return address addl(esp, Constant(2 * BytesPerStackElement)); // remove arguments push_int(eax); // push result jmp(edi); // return comment("Bail out to the general compareTo implementation"); bind(bailout); comment("pop method"); popl(ebx); if (AddExternCUnderscore) { emit_instruction("jmp _interpreter_method_entry"); } else { emit_instruction("jmp interpreter_method_entry"); } rom_linkable_entry_end(); // native_string_compareTo_entry } //----------------------java.lang.String.endsWith---------------- { // java.lang.String.endsWith // Method boolean endsWith(java.lang.String) rom_linkable_entry("native_string_endsWith_entry"); wtk_profile_quick_call(/* param_size*/ 2); Label bailout; // 4 is return address int suffix_offset = JavaFrame::arg_offset_from_sp(0) + 4, this_offset = JavaFrame::arg_offset_from_sp(1) + 4; comment("load arguments to registers"); movl(eax, Address(esp, Constant(suffix_offset))); cmpl(eax, Constant(0)); jcc(equal, Constant(bailout)); movl(ecx, Address(esp, Constant(this_offset))); comment("Pop the return address"); popl(edi); movl(edx, Address(ecx, Constant(String::count_offset()))); subl(edx, Address(eax, Constant(String::count_offset()))); comment("Push (this.count - suffix.count) for toffset"); pushl(edx); comment("Push back the return address"); pushl(edi); jmp(Constant("native_string_startsWith_entry")); comment("Bail out to the general startsWith implementation"); bind(bailout); if (AddExternCUnderscore) { emit_instruction("jmp _interpreter_method_entry"); } else { emit_instruction("jmp interpreter_method_entry"); } rom_linkable_entry_end(); // native_string_endsWith_entry } //----------------------java.lang.String.startsWith---------------- { // java.lang.String.startsWith // Method boolean startsWith(java.lang.String) rom_linkable_entry("native_string_startsWith0_entry"); wtk_profile_quick_call(/* param_size*/ 2); Label bailout; // 4 is return address int prefix_offset = JavaFrame::arg_offset_from_sp(0) + 4; comment("Check if prefix is null"); cmpl(Address(esp, Constant(prefix_offset)), Constant(0)); jcc(equal, Constant(bailout)); comment("Pop the return address"); popl(edi); comment("Push zero for toffset"); pushl(Constant(0)); comment("Push back the return address"); pushl(edi); jmp(Constant("native_string_startsWith_entry")); comment("Bail out to the general startsWith implementation"); bind(bailout); if (AddExternCUnderscore) { emit_instruction("jmp _interpreter_method_entry"); } else { emit_instruction("jmp interpreter_method_entry"); } rom_linkable_entry_end(); // native_string_startsWith0_entry } { // ----------- java.lang.String.startsWith ------------------------------ // Method boolean startsWith(java.lang.String,int) rom_linkable_entry("native_string_startsWith_entry"); wtk_profile_quick_call(/* param_size*/ 3); Label bailout, return_false; // 4 is return address int prefix_offset = JavaFrame::arg_offset_from_sp(1) + 4; comment("Check if prefix is null"); cmpl(Address(esp, Constant(prefix_offset)), Constant(0)); jcc(equal, Constant(bailout)); comment("Pop the return address"); popl(edi); comment("Pop the argument: toffset"); pop_int(edx, edx); comment("Pop the argument: prefix"); pop_obj(eax, eax); comment("Pop the receiver"); pop_obj(ecx, ecx); comment("Preserve the return address"); pushl(edi); // ecx: this String // eax: prefix cmpl(edx, Constant(0)); jcc(less, Constant(return_false)); comment("if (toffset > this.count - prefix.count) return false;"); movl(ebx, Address(ecx, Constant(String::count_offset()))); subl(ebx, Address(eax, Constant(String::count_offset()))); cmpl(edx, ebx); jcc(greater, Constant(return_false)); comment("get this.value[]"); movl(esi, Address(ecx, Constant(String::value_offset()))); comment("get this.offset"); movl(ebx, Address(ecx, Constant(String::offset_offset()))); comment("add toffset"); addl(ebx, edx); comment("compute start of character data"); leal(esi, Address(esi, ebx, times_2, Constant(Array::base_offset()))); comment("get prefix.value[]"); movl(edi, Address(eax, Constant(String::value_offset()))); comment("get prefix.offset"); movl(ebx, Address(eax, Constant(String::offset_offset()))); comment("compute start of character data"); leal(edi, Address(edi, ebx, times_2, Constant(Array::base_offset()))); comment("get prefix.count"); movl(ecx, Address(eax, Constant(String::count_offset()))); comment("get the number of bytes to compare"); shll(ecx, Constant(1)); comment("memcmp(edi, esi, ecx);"); pushl(ecx); pushl(esi); pushl(edi); if (GenerateInlineAsm) { // VC++ treats memcmp() as an intrinsic function and would cause // reference to memcmp in Interpreter_i386.c to fail to compile. call(Constant("memcmp_from_interpreter")); } else { call(Constant("memcmp")); } addl(esp, Constant(12)); cmpl(eax, Constant(0)); jcc(not_equal, Constant(return_false)); // Push 1 on stack and return to caller popl(edi); // pop return address push_int(1); // push result jmp(edi); // return bind(return_false); // Push 0 on stack and return to caller popl(edi); // pop return address push_int(0); // push result jmp(edi); // return comment("Bail out to the general startsWith implementation"); bind(bailout); if (AddExternCUnderscore) { emit_instruction("jmp _interpreter_method_entry"); } else { emit_instruction("jmp interpreter_method_entry"); } rom_linkable_entry_end(); // native_string_startsWith_entry } }
void InterpreterStubs::generate_interpreter_fill_in_tags() { comment_section("Interpreter fill in tags"); entry("interpreter_fill_in_tags"); comment("eax: return address of method"); comment("ebx: method"); comment("ecx: size of parameters. Guaranteed to be >= 1"); comment("edx: call info from call site"); comment("Must preserve eax, ebx, ecx"); // stack layout: // sp return address of caller // --> argument n // --> ... // --> argument 0 Label extended_call_info; comment("Compact call info or normal call info?"); testl(edx, edx); jcc(positive, Constant(extended_call_info)); Label loop_entry, loop_condition; comment("We have a compact call info"); movl(edi, ecx); bind(loop_entry); decl(edi); comment("Store int tag"); movl(Address(esp, edi, times_8, Constant(BytesPerWord)), Constant(int_tag)); comment("Test the bit in the call info"); GUARANTEE(CallInfo::format1_tag_start == 0, "Tag must start at bit position 0 for this code to work"); btl(edx, edi); jcc(carry_clear, Constant(loop_condition)); comment("Store obj tag"); movl(Address(esp, edi, times_8, Constant(BytesPerWord)), Constant(obj_tag)); bind(loop_condition); testl(edi, edi); jcc(not_zero, Constant(loop_entry)); ret(); bind(extended_call_info); comment("Normal call info"); // The following code is slightly complicated. "Bit offset" below // pretends like the callinfo's are in a bit array, as follows: // Callinfo describing bci and offset // Size [16 bits] and stack info 0-3 // Stack info 4-11 // We ignore the fact that each of these words is preceded by a byte // that makes it look like an instruction. pushl(ecx); pushl(ebx); Label loopx_entry, loopx_done; comment("Bit offset of first argument in CallInfo array"); movzxw(edx, Address(eax, Constant(5 + 1))); // total number of locals/expr subl(edx, ecx); // number of locals/expr belonging to callee shll(edx, Constant(2)); // number of bits per nybble addl(edx, Constant(32 + 16)); // 48 bits is the 32 bit callinfo and 16bit size info comment("Decrement argument count; move to more convenient register"); leal(esi, Address(ecx, Constant(-1))); comment("Location of tag of esi-th local"); leal(ebx, Address(esp, Constant(3 * BytesPerWord))); bind(loopx_entry); comment("eax holds the return address"); comment("ebx holds address of the esi-th tag"); comment("esi is the local whose tag we are setting"); comment("edx contains the bit offset of Local 0 in the CallInfo array"); comment("Get bit offset of esi-th local"); leal(ecx, Address(edx, esi, times_4)); comment("From bit offset, get word offset, then multiply by 5"); movl(edi, ecx); shrl(edi, Constant(5)); leal(edi, Address(edi, edi, times_4)); comment("Get the appropriate CallInfo word; extract the nybble"); movl(edi, Address(eax, edi, times_1, Constant(1))); shrl(edi); andl(edi, Constant(0xF)); comment("Tag is (1 << value) >> 1. This is 0 when value == 0"); movl(ecx, edi); movl(edi, Constant(1)); shll(edi); shrl(edi, Constant(1)); comment("Store the tag"); movl(Address(ebx), edi); comment("Are we done?"); decl(esi); addl(ebx, Constant(8)); testl(esi, esi); jcc(greater_equal, Constant(loopx_entry)); bind(loopx_done); popl(ebx); popl(ecx); ret(); entry_end(); // interpreter_fill_in_tags }
int new_thread( int type, struct process *proc, struct thread *parent, const char name[NAME_LENGTH], uint32_t entry, int priority, uint32_t data1, uint32_t data2, uint32_t data3, uint32_t data4 ) { struct thread *tr = (struct thread*)malloc( sizeof(struct thread) ); if ( tr == NULL ) return -1; strncpy( tr->name, name, NAME_LENGTH ); tr->tid = next_tid( proc ); tr->state = THREAD_SUSPENDED; tr->process = proc; tr->sched_state = -1; // architecture ... // tr->stack_user = page_find_free( proc->map, sK_BASE, sK_CEILING, sK_PAGES_THREAD + 1 ); tr->stack_user += (sK_PAGES_THREAD + 1) * PAGE_SIZE; // We're leaving a guard page at the bottom (and, // therefore, the top) of every thread stack. user_ensure( proc, tr->stack_user - (sK_PAGES_THREAD * PAGE_SIZE), sK_PAGES_THREAD ); tr->stack_kernel = (uint32_t) memory_alloc( sK_PAGES_KERNEL ); tr->stack_kernel += sK_PAGES_KERNEL * PAGE_SIZE; tr->cpu = -1; tr->cpu_affinity = -1; // No preference. tr->math_state = -1; tr->math = memory_alloc( 1 ); tr->stack = tr->stack_kernel; // ------------ if ( type == 1 ) { // kernel thread pushl( tr, GDT_SYSTEMDATA ); pushl( tr, tr->stack_user ); pushl( tr, EFLAG_BASE | EFLAG_INTERRUPT ); pushl( tr, GDT_SYSTEMCODE ); } else { // user thread pushl( tr, GDT_USERDATA | 3 ); pushl( tr, tr->stack_user ); pushl( tr, EFLAG_BASE | EFLAG_INTERRUPT ); pushl( tr, GDT_USERCODE | 3 ); } pushl( tr, entry ); pushl( tr, GDT_USERDATA | 3 ); // gs pushl( tr, GDT_USERDATA | 3 ); // fs pushl( tr, GDT_USERDATA | 3 ); // ds pushl( tr, GDT_USERDATA | 3 ); // es pushl( tr, data1 ); // eax pushl( tr, data3 ); // ecx pushl( tr, data4 ); // edx pushl( tr, data2 ); // ebx pushl( tr, 0 ); // temp esp pushl( tr, 0 ); // ebp pushl( tr, 0 ); // esi pushl( tr, 0 ); // edi FAMILY_INIT( tr ); LIST_INIT( tr ); // .... if ( proc->threads == NULL ) { proc->threads = tr; } else { if ( parent == NULL ) { family_add_sibling( &(parent->family_tree), &(tr->family_tree) ); list_insertAfter( &(proc->threads->list), &(tr->list) ); } else { family_add_child( &(parent->family_tree), &(tr->family_tree) ); list_insertAfter( &(proc->threads->list), &(tr->list) ); } } htable_insert( proc->threads_htable, tr ); proc->thread_count += 1; return tr->tid; }
//------------------------------------------------------------------------------------------------------------------------ // Continuation point for throwing of implicit exceptions that are not handled in // the current activation. Fabricates an exception oop and initiates normal // exception dispatching in this frame. Since we need to preserve callee-saved values // (currently only for C2, but done for C1 as well) we need a callee-saved oop map and // therefore have to make these stubs into RuntimeStubs rather than BufferBlobs. // If the compiler needs all registers to be preserved between the fault // point and the exception handler then it must assume responsibility for that in // AbstractCompiler::continuation_for_implicit_null_exception or // continuation_for_implicit_division_by_zero_exception. All other implicit // exceptions (e.g., NullPointerException or AbstractMethodError on entry) are // either at call sites or otherwise assume that stack unwinding will be initiated, // so caller saved registers were assumed volatile in the compiler. // // Note: the routine set_pc_not_at_call_for_caller in SharedRuntime.cpp requires // that this code be generated into a RuntimeStub. address StubGenerator::generate_throw_exception(const char* name, address runtime_entry, bool restore_saved_exception_pc) { int insts_size = 256; int locs_size = 32; CodeBuffer* code = new CodeBuffer(insts_size, locs_size, 0, 0, 0, false, NULL, NULL, NULL, false, NULL, name, false); OopMapSet* oop_maps = new OopMapSet(); MacroAssembler* masm = new MacroAssembler(code); address start = __ pc(); // This is an inlined and slightly modified version of call_VM // which has the ability to fetch the return PC out of // thread-local storage and also sets up last_Java_sp slightly // differently than the real call_VM Register java_thread = ebx; __ get_thread(java_thread); if (restore_saved_exception_pc) { __ movl(eax, Address(java_thread, in_bytes(JavaThread::saved_exception_pc_offset()))); __ pushl(eax); } #ifndef COMPILER2 __ enter(); // required for proper stackwalking of RuntimeStub frame #endif COMPILER2 __ subl(esp, framesize * wordSize); // prolog #ifdef COMPILER2 if( OptoRuntimeCalleeSavedFloats ) { if( UseSSE == 1 ) { __ movss(Address(esp,xmm6_off*wordSize),xmm6); __ movss(Address(esp,xmm7_off*wordSize),xmm7); } else if( UseSSE == 2 ) { __ movsd(Address(esp,xmm6_off*wordSize),xmm6); __ movsd(Address(esp,xmm7_off*wordSize),xmm7); } } #endif /* COMPILER2 */ __ movl(Address(esp, ebp_off * wordSize), ebp); __ movl(Address(esp, edi_off * wordSize), edi); __ movl(Address(esp, esi_off * wordSize), esi); // push java thread (becomes first argument of C function) __ movl(Address(esp, thread_off * wordSize), java_thread); // Set up last_Java_sp and last_Java_fp __ set_last_Java_frame(java_thread, esp, ebp, NULL); // Call runtime __ call(runtime_entry, relocInfo::runtime_call_type); // Generate oop map OopMap* map = new OopMap(framesize, 0); #ifdef COMPILER2 // SharedInfo is apparently not initialized if -Xint is specified if (UseCompiler) { map->set_callee_saved(SharedInfo::stack2reg(ebp_off), framesize, 0, OptoReg::Name(EBP_num)); map->set_callee_saved(SharedInfo::stack2reg(edi_off), framesize, 0, OptoReg::Name(EDI_num)); map->set_callee_saved(SharedInfo::stack2reg(esi_off), framesize, 0, OptoReg::Name(ESI_num)); if( OptoRuntimeCalleeSavedFloats ) { map->set_callee_saved(SharedInfo::stack2reg(xmm6_off ), framesize, 0, OptoReg::Name(XMM6a_num)); map->set_callee_saved(SharedInfo::stack2reg(xmm6_off+1), framesize, 0, OptoReg::Name(XMM6b_num)); map->set_callee_saved(SharedInfo::stack2reg(xmm7_off ), framesize, 0, OptoReg::Name(XMM7a_num)); map->set_callee_saved(SharedInfo::stack2reg(xmm7_off+1), framesize, 0, OptoReg::Name(XMM7b_num)); } } #endif #ifdef COMPILER1 map->set_callee_saved(OptoReg::Name(SharedInfo::stack0+ebp_off), framesize, 0, OptoReg::Name(ebp->encoding())); map->set_callee_saved(OptoReg::Name(SharedInfo::stack0+esi_off), framesize, 0, OptoReg::Name(esi->encoding())); map->set_callee_saved(OptoReg::Name(SharedInfo::stack0+edi_off), framesize, 0, OptoReg::Name(edi->encoding())); #endif oop_maps->add_gc_map(__ pc() - start, true, map); // restore the thread (cannot use the pushed argument since arguments // may be overwritten by C code generated by an optimizing compiler); // however can use the register value directly if it is callee saved. __ get_thread(java_thread); __ reset_last_Java_frame(java_thread, false); // Restore callee save registers. This must be done after resetting the Java frame #ifdef COMPILER2 if( OptoRuntimeCalleeSavedFloats ) { if( UseSSE == 1 ) { __ movss(xmm6,Address(esp,xmm6_off*wordSize)); __ movss(xmm7,Address(esp,xmm7_off*wordSize)); } else if( UseSSE == 2 ) { __ movsd(xmm6,Address(esp,xmm6_off*wordSize)); __ movsd(xmm7,Address(esp,xmm7_off*wordSize)); } } #endif /* COMPILER2 */ __ movl(ebp,Address(esp, ebp_off * wordSize)); __ movl(edi,Address(esp, edi_off * wordSize)); __ movl(esi,Address(esp, esi_off * wordSize)); // discard arguments __ addl(esp, framesize * wordSize); // epilog #ifndef COMPILER2 __ leave(); // required for proper stackwalking of RuntimeStub frame #endif COMPILER2 // check for pending exceptions #ifdef ASSERT Label L; __ cmpl(Address(java_thread, Thread::pending_exception_offset()), (int)NULL); __ jcc(Assembler::notEqual, L); __ should_not_reach_here(); __ bind(L); #endif ASSERT __ jmp(StubRoutines::forward_exception_entry(), relocInfo::runtime_call_type); // Note: it seems the frame size reported to the RuntimeStub has // to be incremented by 1 to account for the return PC. It // definitely must be one more than the amount by which SP was // decremented. int extra_words = 1; #ifdef COMPILER1 ++extra_words; // Not strictly necessary since C1 ignores frame size and uses link #endif COMPILER1 RuntimeStub* stub = RuntimeStub::new_runtime_stub(name, code, framesize + extra_words, oop_maps, false); return stub->entry_point(); }
void NativeGenerator::generate_native_math_entries() { comment_section("Native entry points for math functions"); int offset = 0; #if ENABLE_FLOAT stop_code_segment(); start_data_segment(); stop_data_segment(); start_code_segment(); // Generate sinus entry. offset = 0; rom_linkable_entry("native_math_sin_entry"); comment("store return address"); popl(edi); pop_double(eax, ecx); pushl(ecx); pushl(eax); call(Constant("jvm_sin")); addl(esp, Constant(8)); push_from_fpu_stack(double_tag, offset, true); jmp(edi); rom_linkable_entry_end(); // native_math_sin_entry // Generate cosinus entry. offset = 0; rom_linkable_entry("native_math_cos_entry"); comment("store return address"); popl(edi); pop_double(eax, ecx); pushl(ecx); pushl(eax); call(Constant("jvm_cos")); addl(esp, Constant(8)); push_from_fpu_stack(double_tag, offset, true); jmp(edi); rom_linkable_entry_end(); // native_math_cos_entry // Generate tangent entry. offset = 0; rom_linkable_entry("native_math_tan_entry"); comment("store return address"); popl(edi); pop_double(eax, ecx); pushl(ecx); pushl(eax); call(Constant("jvm_tan")); addl(esp, Constant(8)); push_from_fpu_stack(double_tag, offset, true); jmp(edi); rom_linkable_entry_end(); // native_math_tan_entry // Generate square root entry. offset = 0; rom_linkable_entry("native_math_sqrt_entry"); comment("store return address"); popl(edi); pop_double(eax, ecx); pushl(ecx); pushl(eax); call(Constant("jvm_sqrt")); addl(esp, Constant(8)); push_from_fpu_stack(double_tag, offset, true); jmp(edi); rom_linkable_entry_end(); // native_math_sqrt_entry // Generate ceil entry. offset = 0; rom_linkable_entry("native_math_ceil_entry"); comment("store return address"); popl(edi); pop_double(eax, ecx); pushl(ecx); pushl(eax); call(Constant("jvm_ceil")); addl(esp, Constant(8)); push_from_fpu_stack(double_tag, offset, true); jmp(edi); rom_linkable_entry_end(); // native_math_ceil_entry // Generate floor entry. offset = 0; rom_linkable_entry("native_math_floor_entry"); comment("store return address"); popl(edi); pop_double(eax, ecx); pushl(ecx); pushl(eax); call(Constant("jvm_floor")); addl(esp, Constant(8)); push_from_fpu_stack(double_tag, offset, true); jmp(edi); rom_linkable_entry_end(); // native_math_floor_entry #endif /* ENABLE_FLOAT */ }
address generate_call_stub(address& return_address) { StubCodeMark mark(this, "StubRoutines", "call_stub"); address start = __ pc(); // stub code parameters / addresses assert(frame::entry_frame_call_wrapper_offset == 2, "adjust this code"); bool sse_save = false; const Address esp_after_call(ebp, -4 * wordSize); // same as in generate_catch_exception()! const Address mxcsr_save (ebp, -4 * wordSize); const Address result (ebp, 3 * wordSize); const Address result_type (ebp, 4 * wordSize); const Address method (ebp, 5 * wordSize); const Address entry_point (ebp, 6 * wordSize); const Address parameters (ebp, 7 * wordSize); const Address parameter_size(ebp, 8 * wordSize); const Address thread (ebp, 9 * wordSize); // same as in generate_catch_exception()! #ifdef COMPILER2 sse_save = VM_Version::supports_sse(); #endif // stub code __ enter(); // save edi, esi, & ebx, according to C calling conventions __ pushl(edi); __ pushl(esi); __ pushl(ebx); __ subl(esp, wordSize); // space for %mxcsr save // save and initialize %mxcsr if (sse_save) { __ stmxcsr(mxcsr_save); __ ldmxcsr(Address((int) StubRoutines::addr_mxcsr_std(), relocInfo::none)); } #ifdef ASSERT // make sure we have no pending exceptions { Label L; __ movl(ecx, thread); __ cmpl(Address(ecx, Thread::pending_exception_offset()), (int)NULL); __ jcc(Assembler::equal, L); __ stop("StubRoutines::call_stub: entered with pending exception"); __ bind(L); } #endif // pass parameters if any Label parameters_done; __ movl(ecx, parameter_size); // parameter counter __ testl(ecx, ecx); __ jcc(Assembler::zero, parameters_done); // parameter passing loop Label loop; __ movl(edx, parameters); // parameter pointer __ movl(esi, ecx); // parameter counter is in esi now __ movl(ecx, Address(edx)); // get first parameter in case it is a receiver __ bind(loop); __ movl(eax, Address(edx)); // get parameter __ addl(edx, wordSize); // advance to next parameter __ decl(esi); // decrement counter __ pushl(eax); // pass parameter __ jcc(Assembler::notZero, loop); // call Java function __ bind(parameters_done); __ movl(ebx, method); // get methodOop __ movl(esi, entry_point); // get entry_point __ call(esi, relocInfo::none); return_address = __ pc(); // store result depending on type // (everything that is not T_LONG, T_FLOAT or T_DOUBLE is treated as T_INT) __ movl(edi, result); Label is_long, is_float, is_double, exit; __ movl(esi, result_type); __ cmpl(esi, T_LONG); __ jcc(Assembler::equal, is_long); __ cmpl(esi, T_FLOAT); __ jcc(Assembler::equal, is_float); __ cmpl(esi, T_DOUBLE); __ jcc(Assembler::equal, is_double); // handle T_INT case __ movl(Address(edi), eax); __ bind(exit); // pop parameters __ movl(ecx, parameter_size); __ leal(esp, Address(esp, ecx, Address::times_4)); // check if parameters have been popped correctly #ifdef ASSERT Label esp_wrong; __ leal(edi, esp_after_call); __ cmpl(esp, edi); __ jcc(Assembler::notEqual, esp_wrong); #endif // restore %mxcsr if (sse_save) { __ ldmxcsr(mxcsr_save); } // restore edi & esi __ addl(esp, wordSize); // remove %mxcsr save area __ popl(ebx); __ popl(esi); __ popl(edi); // return __ popl(ebp); __ ret(0); // handle return types different from T_INT __ bind(is_long); __ movl(Address(edi, 0 * wordSize), eax); __ movl(Address(edi, 1 * wordSize), edx); __ jmp(exit); __ bind(is_float); __ fstp_s(Address(edi)); __ jmp(exit); __ bind(is_double); __ fstp_d(Address(edi)); __ jmp(exit); #ifdef ASSERT // stack pointer misadjusted __ bind(esp_wrong); __ stop("esp wrong after Java call"); #endif return start; }
int exception(struct trapdata *framedata) { ptptr proc; unsigned int frame, fsize; uint8_t trap = framedata->trap; unsigned int sig = 0; uint16_t m; uint16_t *sp = (uint16_t *)framedata; uint16_t *usp = get_usp(); uint16_t *unwind, *context; uint8_t err = 0; int i; /* We translate debug to SIGIOT and A and F line to SIGILL We will need to fix up 68000 v 68010 move to/from SR */ static const uint8_t trap_to_sig[] = { 0, 0, SIGSEGV, SIGBUS, SIGILL, SIGFPE, SIGABRT/*CHK*/, SIGTRAP/*TRAPV */, SIGILL, SIGIOT, SIGILL, SIGFPE }; proc = udata.u_ptab; if (sysinfo.cpu[0] == 10) { /* Long or short frame: the CPU tells us the frame format */ if (framedata->exception[3] & 0x8000) { fsize = 29; frame = FRAME_C; } else { fsize = 4; frame = FRAME_D; } } else { frame = FRAME_B; fsize = 3; } if (trap == 0) { sig = udata.u_cursig; udata.u_cursig = 0; } else if (trap < 12) { if (trap < 4) { /* On a 68010 this frame is 29 words and the event is restartable (although not always usefully). We need to decide whether to set the restart flag case by case */ if (sysinfo.cpu[0] == 0) { frame = FRAME_A; fsize = 7; } } sig = trap_to_sig[trap]; } else if (trap >= 32 && trap < 48) sig = SIGTRAP; /* This processing only applies to synchronous hardware exceptions */ if (trap) { /* Went boom in kernel space or without a user recovery */ if (kernel_flag || sig == 0) { explode(framedata, frame); panic("trap"); } /* Cheating here .. all our exceptions are low 16 signal */ m = 1 << sig; /* * The caller is ignoring our signal. In some cases this is fine * but in others it's less clear (eg division by zero) and we * may need to take different action. */ if (proc->p_sig[0].s_ignored & m) return 0; /* Weird case - we took a sync signal and the caller wants us to report it later. */ if (proc->p_sig[0].s_held & m) { /* TODO: if it's not meaningfully restartable we should probably treat this as a kill */ ssig(proc, sig); return 0; } recalc_cursig(); /* Put any async signal back */ } if (udata.u_sigvec[sig] == SIG_DFL) { /* Default action for our signal ? */ doexit(dump_core(sig)); /* This will never return. We will go schedule new work */ panic("exret"); } /* build signal frame Our unwinder code does move.l 8(sp),sp movem.l a0-a1/d0-d1,(sp)+ move.w (sp)+,ccr rts */ /* Now update the user stack */ /* - Push the recovery PC */ /* - Patch the kernel exception frame */ if (sysinfo.cpu[0]) { /* FIXME */ err |= pushw(&usp, sp[34]); err |= pushw(&usp, sp[33]); *(uint32_t *)(&sp[33]) = (uint32_t)udata.u_sigvec[sig]; } else { err |= pushw(&usp, sp[31 + fsize]); err |= pushw(&usp, sp[30 + fsize]); *(uint32_t *)(&sp[30 + fsize]) = (uint32_t)udata.u_sigvec[sig]; } /* FIXME: when we do ptrace we will need to support adding the T flag back here as the exception cleared it */ err |= pushw(&usp, framedata->sr); /* Push A1 A0 D1 D0 to match MOVEM.L */ err |= pushl(&usp, framedata->a[1]); err |= pushl(&usp, framedata->a[0]); err |= pushl(&usp, framedata->d[1]); err |= pushl(&usp, framedata->d[0]); /* Remember the target for undoing the frame */ unwind = usp; /* Copy in the signal context itself. 30 words of registers, 2 of trap code and then the hardware exception */ for (i = 0; i < 30 + 2 + fsize; i++) err |= pushw(&usp, *sp++); context = usp; err |= pushl(&usp, (uint32_t)unwind); /* Signal context is a secret extra non portable argument */ err |= pushl(&usp, (uint32_t)context); /* We end it with the call frame as seen from the signal handler, a single argument and a return address */ err |= pushl(&usp, sig); err |= pushl(&usp, udata.u_codebase + 0x04); set_usp(usp); if (err) { doexit(dump_core(SIGSTKFLT)); panic("exret2"); } /* Once built clear the restart state */ udata.u_sigvec[sig] = SIG_DFL; /* Return, RTE and end up on the signal frame */ return 1; }