I have something odd going on here.
I pushed this onto the stack. Compiled with nasm
push ds
push es
push fs
push gs
but looking at the stack, it actually pushed double words (4 bytes). Not 2 bytes as a segment register should be. Any thoughts?
weird stack
Re:weird stack
In 32bit mode, stack operations are always 32bits (4 bytes). When you "pop ds", it will remove 32bits from the stack but only loads the first 16 into DS.
As a side note: Do not prefix in the instructions with o16, if you do you will make a mess of the C handler:or
As a side note: Do not prefix in the instructions with o16, if you do you will make a mess of the C handler:
Code: Select all
void ISR(..., unsigned int FSandGS, unsigned int DSandES, ...)
Code: Select all
struct SegRegs { unsigned short FS, GS, DS, ES; } __attribute__((__packed__));
void ISR(..., SegRegs sr, ...)
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:weird stack
Get a look at intel manuals ... that's exactly what's supposed to happen (for performance, alignment and another couple of GoodThings)
Re:weird stack
thanks guys...its just thats its a little ugly for my reg struct...
struct regs { unsigned short ds, unsigned short pading...
you get the idea...
struct regs { unsigned short ds, unsigned short pading...
you get the idea...
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:weird stack
you have the option of declaring 'pure-padding' fields too!
iirc, that's even ANSI C
Code: Select all
struct regs {
unsigned short ds;
unsigned :16;
unsigned short es;
unsigned :16;
...
};
- Colonel Kernel
- Member
- Posts: 1437
- Joined: Tue Oct 17, 2006 6:06 pm
- Location: Vancouver, BC, Canada
- Contact:
Re:weird stack
Anonymous bitfields... hadn't thought of trying that. I wonder if Doxygen will choke on them though...Pype.Clicker wrote: you have the option of declaring 'pure-padding' fields too!
Top three reasons why my OS project died:
- Too much overtime at work
- Got married
- My brain got stuck in an infinite loop while trying to design the memory manager
Re:weird stack
What if you just use unsigned int?
Are the upper two bytes zeroed, or may they contain garbage?
Are the upper two bytes zeroed, or may they contain garbage?