Code: Select all
push byte 0
push byte 1
etc
GAS only accepts "push something". What does nasm do here, and how would I do it in gas?
thanks
Code: Select all
push byte 0
push byte 1
etc
Code: Select all
isr0: # divide by zero
cli
pushl 0
pushl 1
jmp isr_common_stub
.extern fault_handler
isr_common_stub:
pusha
push %ds
push %es
push %fs
push %gs
mov %ax, 0x10
mov %ds, %ax
mov %es, %ax
mov %fs, %ax
mov %gs, %ax
mov %eax, %esp
push %eax
mov %eax, fault_handler
call *%eax
pop %eax
pop %gs
pop %fs
pop %es
pop %ds
popa
add %esp, 8
iret
Code: Select all
#include <kernel.h>
/* Function prototypes. */
void isr0();
void isrs_install(void)
{
idt_set_gate(0, (unsigned)isr0, 0x08, 0x8E);
}
char *exceptions[] = {
"Division by zero"
};
void fault_handler(struct regs *r)
{
if (r->int_no < 32) { /* Exception */
puts("Exception: ");
puts(exceptions[r->int_no]);
puts(". System halted!");
for (;;);
}
}
Code: Select all
00018114804e[CPU0 ] fetch_raw_descriptor: GDT: index (ff57)1fea > limit (17)
00018114804e[CPU0 ] interrupt(): gate descriptor is not valid sys seg
00018114804e[CPU0 ] interrupt(): gate descriptor is not valid sys seg
Code: Select all
push byte 0
push byte 1
etc
Code: Select all
/* This defines what the stack looks like after an ISR was running */
struct regs
{
unsigned int ds, es, fs, gs;
unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax;
unsigned int int_no, err_code;
unsigned int eip, cs, eflags, useresp, ss;
};
Code: Select all
PUSH whatever
PUSH whatever
Code: Select all
bits 16
push byte 1 ;Opcode: 1 byte --- Value: 1 byte
push word 1 ;Opcode: 1 byte --- Value: 2 bytes
push dword 1 ;Opcode: 2 bytes --- Value: 4 byte
bits 32
push byte 1 ;Opcode: 1 byte --- Value: 1 byte
push word 1 ;Opcode: 2 bytes --- Value: 2 bytes
push dword 1 ;Opcode: 1 bytes --- Value: 4 bytes
Code: Select all
bits 16
push byte 0
pop ds
Code: Select all
PUSH BYTE 0
Code: Select all
PUSH DWORD 0
Code: Select all
ALIGN 0x02, DB 0x00
__MyAlignedProcedure:
;~
Code: Select all
ALIGN 0x04, NOP
__MyAlignedProcedure:
;~
That would happen in 32-bit mode.XCHG wrote:~:
I think you should be more careful about using the adjective "aligned" because when you do this:
The stack segment wouldn't get "aligned" but the sign bit of the pushed byte will get extended into the other three bytes left in the DWORD and finally a DWORD will be pushed onto the stack. You might have an unaligned stack segment but after doing the above, your stack segment will not get aligned or anything. You will still have an unaligned stack.Code: Select all
PUSH BYTE 0
Code: Select all
bits 32
push ax ;Pushes a WORD, doesn't extend into a DWORD
Code: Select all
bits 32
pop ax ;Pops the previous WORD
Code: Select all
bits 16
push byte 1 ;Opcode: 1 byte --- Value: 1 byte --- Total: 2 bytes
push word 1 ;Opcode: 1 byte --- Value: 2 bytes --- Total: 3 bytes
push dword 1 ;Opcode: 2 bytes --- Value: 4 byte --- Total: 6 bytes
bits 32
push byte 1 ;Opcode: 1 byte --- Value: 1 byte --- Total: 2 bytes
push word 1 ;Opcode: 2 bytes --- Value: 2 bytes --- Total: 4 bytes
push dword 1 ;Opcode: 1 bytes --- Value: 4 bytes --- Total: 5 bytes