| Target | Magic instruction | ||
| x86 | xchg %bx, %bx | encoding: 66 87 DB | |
| ARM | orreq rn, rn, rn | 0 <= n < 15 | |
| PowerPC 32-bit | mr n, n | 0 <= n < 32 | |
| PowerPC 64-bit | fmr n, n | 0 <= n < 32 | |
| SPARC | sethi n, %g0 | 1 <= n < 0x400000 | |
CogIA32Compiler>concretizeMagic
CogIA32Compiler>dispatchConcretize
CogRTLOpcodes>>initializeAdd "Magic" to the end and send #initialize. Now our abstract RTL has the magic instruction.
Cogit>>Magic <inline:true> <returnTypeC:#'AbstractInstruction*'> ^self gen: Magic
genGetClassFormatOfNonInt: instReg
into: destReg
scratchReg: scratchReg
"Fetch the instance's class format into destReg,
assuming the object is non-int."
| jumpCompact jumpGotClass |
<var: #jumpCompact type: #'AbstractInstruction *'>
<var: #jumpGotClass type: #'AbstractInstruction *'>
cogit Magic. "THIS WILL STOP SIMULATION"
"Get header word in destReg"
cogit MoveMw: 0 r: instReg R: destReg.
... "rest of method"
32-bit legacy protected mode eax = 0x00000001, ax = 0x0001, ah = 0x00, al = 0x01 ecx = 0x00000006, cx = 0x0006, ch = 0x00, cl = 0x06 edx = 0x944f9540, dx = 0x9540, dh = 0x95, dl = 0x40 ebx = 0x00000004, bx = 0x0004, bh = 0x00, bl = 0x04 esp = 0xbf869670, sp = 0x9670 ebp = 0xbf869680, bp = 0x9680 esi = 0x00000003, si = 0x0003 edi = 0x00000003, di = 0x0003 eip = 0x93cff260, linear = 0x93cff260 eflags = 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 = 0x00000202receiver in %EDX
l:0x944f9540 1d04 9a12 ← receiver's object header
class oop in header word 2, offset -4:
simics> x l:0x944f953C 4l:0x944f9530 813e 1194 ← class oop
def print_class_of_oop(oop):
if ((oop & 1)==1):
print "SmallInteger"
else:
headerType = smalltalk_headerType(oop)
if (headerType==3):
print "...looks like compact class..."
else:
word2 = read_virt_value(oop-4, 4)
classOop = word2&0xFFFFFFFC
print "class oop: ", hex(classOop)
classNameOop = read_virt_value(classOop+32, 4)
print "class name oop: ", hex(classNameOop)
str=""
for offset in range(smalltalk_objByteSize(classNameOop)):
str += "%c" % read_virt_value(classNameOop + 4 + offset, 1)
print str
new_command("print-class-of-oop", print_class_of_oop,
[arg(int_t, "oop")],
type = "Debugging",
see_also = [],
short = "describe an oop",
doc = """
Print the class of oop.""")
class oop: 0x94113E80L class name oop: 0x93F401CCL WeakAnnouncementSubscriptionsimics> print-class-of-oop 0x93F401CC
class oop: 0x940FB4B4L class name oop: 0x93E94140L ByteSymbol