cyr1x wrote:Try "pushl" instead of "push". AFAIK "push" will sign-extend the operand.
this is what my function looks like at the moment:
Code: Select all
.code32
.inter_syntax noprefix
--snip--
.extern fault_handler
isr_common_stub:
xchg bx, bx
pusha
push ds
push es
push fs
push gs
xchg bx, bx
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov eax, esp
push eax
xchg bx, bx
lea eax, fault_handler
xchg bx, bx
call eax
xchg bx, bx
pop eax
pop gs
pop fs
pop es
pop ds
popa
add esp, 8
iret
--snip--
in bochs with the AT&T switch enable it looks like this:
Code: Select all
xchgw %bx, %bx
pushal
pushl %ds
pushl %es
pushl %fs
pushl %gs
xchgw %bx, %bx
movw $0x0010, %ax
movw %ax, %ds
movw %ax, %es
movw %ax, %fs
movw %ax, %gs
movl %esp, %eax
pushl %eax
xchgw %bx, %bx
leal %ds:0x1009e0, %eax
xchgw %bx, %bx
call %eax
xchgw %bx, %bx
popl %eax
popl %gs
popl %fs
popl %es
popl %ds
popal
addl $0x00000008, %esp
iretd
(btw it won't let me assemble it if change it to pushl manually guessing that has to do with the .intel_syntax)
while using objdump it gives me this:
Code: Select all
100176: 66 87 db xchg %bx,%bx
100179: 60 pusha
10017a: 1e push %ds
10017b: 06 push %es
10017c: 0f a0 push %fs
10017e: 0f a8 push %gs
100180: 66 87 db xchg %bx,%bx
100183: 66 b8 10 00 mov $0x10,%ax
100187: 8e d8 mov %eax,%ds
100189: 8e c0 mov %eax,%es
10018b: 8e e0 mov %eax,%fs
10018d: 8e e8 mov %eax,%gs
10018f: 89 e0 mov %esp,%eax
100191: 50 push %eax
100192: 66 87 db xchg %bx,%bx
100195: 8d 05 e0 09 10 00 lea 0x1009e0,%eax
10019b: 66 87 db xchg %bx,%bx
10019e: ff d0 call *%eax
1001a0: 66 87 db xchg %bx,%bx
1001a3: 58 pop %eax
1001a4: 0f a9 pop %gs
1001a6: 0f a1 pop %fs
1001a8: 07 pop %es
1001a9: 1f pop %ds
1001aa: 61 popa
1001ab: 83 c4 08 add $0x8,%esp
1001ae: cf iret
now my function is called but it still gets the wrong data
if it helps here is the data that are in the registers when it handles the error:
Code: Select all
pushad
eax 13 0xd
ebx 65536 0x10000
ecx 4 0x4
edx 981 0x3d5
esi 0
edi 0
ebp 0
esp 1079388 0x10785c
eip 1048953 0x100179
eflags 0x200097
cs 0x8
ds 0x10
es 0x10
ss 0x10
fs 0x10
gs 0x10
after push
esp 1079340 0x10782c
eip 1048963 0x100179
after mov
eax 1079340 0x10782c
esp 1079336 0x107828
eip 1048981 0x100195
call
eax 1051104 0x1009e0 <- address of C function
eip 1048990 0x10019e
printing error number
eax 0 0x0
ebx 1048682 0x1006a
esi 1079340 0x10782c
esp 1079304 0x107808
eip 1051129 0x1009f9
eflags 0x200046
and this is my stack before isr_common_stub is called:
Code: Select all
10785C 1048682 0x10006a
107860 3 0x3
107864 0 0x0
107868 1051270 0x100a86
10786C 16 0x10
107870 2097815 0x200297
107874 13 0xd
107878 0 0x0
10787C 0 0x0
107880 0 0x0
107884 0 0x0
107888 0 0x0
10788C 65536 0x10000
107890 1048598 0x100016
107894 1342177283 0x50000003
107898 1183036943 0x4683b60f
10789C 1342177283 0x50000003
1078A0 0 0x0
1078A4 0 0x0
1078A8 0 0x0
1078AC 0 0x0
1078B0 0 0x0
1078B4 1048576 0x100000
1078B8 0 0x0
1078BC 65539 0x10003
1078C0 0 0x0
1078C4 1052470 0x0100f36
1078C8 0 0x0
1078CC 131075 0x20003
1078D0 0 0x0
1078D4 1052908 0x1010ec
1078D8 0 0x0
1078DC 196611 0x30003
1078E0 0 0x0
1078E4 1056768 0x102000
1078E8 0 0x0
1078EC 262147 0x40003
1078F0 0 0x0
1078F4 1060864 0x103000
1078F8 0 0x0
1078FC 327683 0x50003
107900 0 0x0
107904 0 0x0
107908 0 0x0
10790C 393219 0x6003
107910 1 0x1
107914 0 0x0
107918 0 0x0
10791C -983036 0xfff10004
107920 13 0xd
and this is my stack just before the call to the C function:
Code: Select all
107828 1079340 0x10782c
10782C 16 0x10
107830 1048592 0x100010
107834 16 0x10
107838 16 0x10
10783C 0 0x0
107840 0 0x0
107844 0 0x0
107848 1079388 0x10785c
10784C 65536 0x10000
107850 981 0x3d5
107854 4 0x4
107858 13 0xd
10785C 1048682 0x10006a
107860 3 0x3
107864 0 0x0
107868 1051270 0x100a86
10786C 16 0x10
107870 2097815 0x200297
107874 13 0xd
107878 0 0x0
10787C 0 0x0
107880 0 0x0
107884 0 0x0
107888 0 0x0
10788C 65536 0x10000
107890 1048598 0x100016
107894 1342177283 0x50000003
107898 1183036943 0x4683b60f
10789C 1342177283 0x50000003
1078A0 0 0x0
1078A4 0 0x0
1078A8 0 0x0
1078AC 0 0x0
1078B0 0 0x0
1078B4 1048576 0x100000
1078B8 0 0x0
1078BC 65539 0x10003
1078C0 0 0x0
1078C4 1052470 0x0100f36
1078C8 0 0x0
1078CC 131075 0x20003
1078D0 0 0x0
1078D4 1052908 0x1010ec
1078D8 0 0x0
1078DC 196611 0x30003
1078E0 0 0x0
1078E4 1056768 0x102000
1078E8 0 0x0
1078EC 262147 0x40003
Edit: Seems if found out what was causing bad info to be passed to the C was the isr_common_stub was being "called" instead of being "jumped" to
XD ninjad by jnc100