nullplan wrote:
Oh dear lord, so many comments...
I like to keep my code commented for both myself and anyone else looking at it, especially ASM. Even for me it's pretty tricky to just read it and understand what's going on. For any beginners I can't even image where they would start. That's why I put so many comments.
nullplan wrote:
On x86_64 (as well as all other architectures I have ever earnestly looked at) stack grows downward. Meaning that subtracting from the stack pointer allocates memory on stack, and adding to it frees it.
I've known that for a long time, it's just hard to wrap my head around the logic of it being in a kind of reverse order like that.
nullplan wrote:
On x86_64 in particular, the instruction "push <number>" pushes eight bytes. Your code pushes two numbers on stack before everything else, so the counter instruction must add sixteen to RSP.
Ah. I really should have caught that. 64 bits / 8 bits per byte is 8 bytes. There's really no excuse for not seeing that
.
nullplan wrote:
Also, since stack grows downward, the address of the start of the structure is the value of RSP after pushing the structure.
Oh. I thought it needed to be at the topmost part of the strut in the stack.
nullplan wrote:
Also, you can push segment registers directly, you don't need to use a temporary register first.
I never actually tried to push ds (and idk why I move ds into ax there) No. You can't:
Code:
hardware/CPU/interrupts/ISRASM.S: Assembler messages:
hardware/CPU/interrupts/ISRASM.S:98: Error: you can't `push %ds'
nullplan wrote:
And technically you need to observe stack alignment when calling C code.
True, didn't think of that.
nullplan wrote:
However, then your problems go on in your C code. What argument type does your ISRHandler function take, and what argument type are you giving it here? That really ought to have been a pointer to the structure. The difference is, if you give the structure itself to the function, not only does the stack alignment not work that way, the registers also become local variable space for the function, and the function is under no obligation to keep these values the same.
I have modified the C code to use pointers for the struct. See
this commit.nullplan wrote:
I have seen that code before. Have you been learning from a bad tutorial?
Possible. I think it's kind of a mishmash of different tutorials.