Code: Select all
.global outportb
.type outportb, @function
outportb:
movb 4(%esp), %al # the byte sized value
movw 5(%esp), %dx # our port, right?
outb %al, %dx
ret
.global inportb
.type inportb, @function
inportb:
movw 4(%esp), %dx
inb %dx, %al # since AL is part of EAX, this should satisfy the System V ABI
ret
Their C headers:
Code: Select all
void outportb(uint16_t port, uint8_t thevalue);
uint8_t inportb(uint16_t port);
However, the C function that called it apparently did this in assembly when it called it (compare it with the corresponding C code):
Code: Select all
1000aa: 6a 0e push $0xe
1000ac: 68 d4 03 00 00 push $0x3d4
1000b1: e8 4f 01 00 00 call 100205 <outportb>
Code: Select all
outportb(0x3D4, 0xE);
Why isn't it pushing the arguments the OTHER way around? And why isn't it specifying that they should be a byte and a short respectively (the assembly is in AT&T syntax)? These are my first two questions.
Now, my second question resulted in what happened after I changed my outportb to be more cooperative with the C code (in other words, make it so DX got the first two bytes on the top of the stack (if you skip the return address, of course) and al got the byte below that. Changed code:
Code: Select all
outportb:
movw 4(%esp), %dx
movb 6(%esp), %al
outb %al, %dx
ret
However, when I used QEMU and GDB together, when I stepped through the first instruction of outportb (with the C call being the same one I talked about prior), EDX became 0x3D4. However, upon stepping through the NEXT one, EAX didn't change from zero to 0xE at all. Is QEMU and my cross compiler going nuts, or am I just doing a mistake only a newbie would? Any help would be appreciated.
NOTE:
I accidentally posted this when it was only half done, so if you saw only half the post, sorry, my bad!