Placing kernel in 4MB in RAM on real hardware.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Placing kernel in 4MB in RAM on real hardware.
Of course it's not a good solution as long as you don't know why.
Re: Placing kernel in 4MB in RAM on real hardware.
No, of course it's not but I wondered if You could give me possible explanation for such behaviour.Combuster wrote:Of course it's not a good solution as long as you don't know why.
Maybe this could be a little help --> this code works as well:
Code: Select all
/* Initializing IDT */
_idtr.limit = sizeof(struct idt_deskryptor) * MAX_INTERRUPTS -1;
_idtr.base = (unsigned int)&_idt;
printf("Test\n");
idt_install();
install_isrs();
install_irq();
Any clues, Combuster?
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Placing kernel in 4MB in RAM on real hardware.
Use the debugger, Luke!
Re: Placing kernel in 4MB in RAM on real hardware.
Like I didn't before...Combuster wrote:Use the debugger, Luke!
What to look for? What kind of changes in registers?
I can tell you excactly where the IDT changes (breaks/corrupts) but I can't explain it.
I can provide you with information about registers/line number/etc. if it's ok for you.
I'd really appreciate your help
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Placing kernel in 4MB in RAM on real hardware.
That sounds like exactly the thing you should have posted the first time
Re: Placing kernel in 4MB in RAM on real hardware.
Ok, I narrowed the problem as much as I can
So, after loading idt with:
I get (inside bochs using: info idt) something like this:
The clue to make code working is to put functions in right order.
For example:
has valid IDT until it enters install_irq() routine.
If I change order:
it works until it enter install_isrs() routine.
And for example this code:
breaks code after entering printf.
By breaking code I mean that after routine running in bochs: info idt gives:
GDT is ok.
Looks like IDTR (register) somehow zeroes itself (because printf() gives good address, so struct is all good).
This only happens with -O3 or -O2 flag enabled. Otherwise it works as expected.
So, after loading idt with:
Code: Select all
lidt [_idtr]
Code: Select all
<bochs:2> info idt
Interrupt Descriptor Table (base=0x00000000c0007060, limit=2047):
IDT[0x00]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x01]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x02]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x03]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x04]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x05]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x06]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x07]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x08]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x09]=??? descriptor hi=0x00000000, lo=0x00000000
[... rest of the code ...]
For example:
Code: Select all
/* Initializing IDT */
_idtr.limit = sizeof(struct idt_deskryptor) * MAX_INTERRUPTS -1;
_idtr.base = (unsigned int)&_idt;
idt_install();
install_isrs();
install_irq();
If I change order:
Code: Select all
/* Initializing IDT */
_idtr.limit = sizeof(struct idt_deskryptor) * MAX_INTERRUPTS -1;
_idtr.base = (unsigned int)&_idt;
printf("Test\n");
idt_install();
install_irq();
install_isrs();
And for example this code:
Code: Select all
/* Initializing IDT */
_idtr.limit = sizeof(struct idt_deskryptor) * MAX_INTERRUPTS -1;
_idtr.base = (unsigned int)&_idt;
printf("Test\n");
idt_install();
printf("%a", _idtr.base);
install_isrs();
install_irq();
By breaking code I mean that after routine running in bochs: info idt gives:
Code: Select all
<bochs:2> info idt
Interrupt Descriptor Table (base=0x0000000000000000, limit=2047):
IDT[0x00]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x01]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x02]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x03]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x04]=32-Bit TSS (Available) at 0xf087f000, length 0x0fea5
IDT[0x05]=32-Bit TSS (Available) at 0xf0dff000, length 0x0e9df
IDT[0x06]=32-Bit TSS (Available) at 0xf0dff000, length 0x0e9df
IDT[0x07]=32-Bit TSS (Available) at 0xf0dff000, length 0x0ef57
IDT[0x08]=Code segment, base=0xf04dc000, limit=0x0000014a, Execute-Only, Non-Conforming, 16-bit
IDT[0x09]=16-Bit TSS (Busy) at 0xf0fef000, length 0x0f841
IDT[0x0a]=Code segment, base=0xf059f000, limit=0x0000e739, Execute-Only, Non-Conforming, 16-bit
IDT[0x0b]=32-Bit Trap Gate target=0xf000:0xf000e82e, DPL=3
IDT[0x0c]=16-Bit Interrupt Gate target=0xf000:0xf0009695, DPL=3
IDT[0x0d]=Code segment, base=0xf053f000, limit=0x0000fe6e, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x0e]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x0f]=Data segment, base=0xc078f000, limit=0x0000efde, Read/Write, Accessed
IDT[0x10]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x11]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x12]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x13]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x14]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x15]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x16]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x17]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x18]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x19]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x1a]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x1b]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x1c]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x1d]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x1e]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x1f]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x20]=??? descriptor hi=0x9fc0003d, lo=0xf000ec59
IDT[0x21]=Task Gate target=0xf000:0xc000ff53, DPL=1
IDT[0x22]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x23]=Code segment, base=0xf0539fc0, limit=0x0000004d, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x24]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x25]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x26]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x27]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x28]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x29]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x2a]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x2b]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x2c]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x2d]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x2e]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x2f]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x30]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x31]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x32]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x33]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x34]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x35]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x36]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x37]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x38]=32-Bit TSS (Available) at 0xf0d6f000, length 0x0fe93
IDT[0x39]=32-Bit TSS (Available) at 0xf0e5f000, length 0x0e9e5
IDT[0x3a]=LDT
IDT[0x3b]=32-Bit TSS (Available) at 0xf0e5f000, length 0x09a5a
IDT[0x3c]=??? descriptor hi=0x00000000, lo=0xf000ff53
IDT[0x3d]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x3e]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x3f]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x40]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x41]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x42]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x43]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x44]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x45]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x46]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x47]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x48]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x49]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x4a]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x4b]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x4c]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x4d]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x4e]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x4f]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x50]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x51]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x52]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x53]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x54]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x55]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x56]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x57]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x58]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x59]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x5a]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x5b]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x5c]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x5d]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x5e]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x5f]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x60]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x61]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x62]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x63]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x64]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x65]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x66]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x67]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x68]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x69]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x6a]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x6b]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x6c]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x6d]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x6e]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x6f]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x70]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x71]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x72]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x73]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x74]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x75]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x76]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x77]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x78]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x79]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x7a]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x7b]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x7c]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x7d]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x7e]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x7f]=Code segment, base=0xf053f000, limit=0x0000ff53, Execute/Read, Conforming, Accessed, 16-bit
IDT[0x80]=??? descriptor hi=0x00000000, lo=0x000003f8
IDT[0x81]=??? descriptor hi=0x9fc00000, lo=0x00000378
IDT[0x82]=??? descriptor hi=0x00000002, lo=0x7f004227
IDT[0x83]=??? descriptor hi=0x0000001e, lo=0x001e0000
IDT[0x84]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x85]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x86]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x87]=??? descriptor hi=0x00010000, lo=0x00000000
IDT[0x88]=16-Bit TSS (Busy) at 0x01000000, length 0x00025
IDT[0x89]=Data segment, base=0x00000050, limit=0x00000302, Read-Only
IDT[0x8a]=??? descriptor hi=0x00000000, lo=0x00001717
IDT[0x8b]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x8c]=??? descriptor hi=0xfa000003, lo=0xd4000607
IDT[0x8d]=16-Bit TSS (Busy) at 0x00a20000, length 0x500ff
IDT[0x8e]=??? descriptor hi=0x00c00000, lo=0x00000000
IDT[0x8f]=??? descriptor hi=0x0000000a, lo=0x00000014
IDT[0x90]=Data segment, base=0x6018003e, limit=0x0000001e, Read-Only
IDT[0x91]=??? descriptor hi=0x07000000, lo=0x000851f9
IDT[0x92]=??? descriptor hi=0x00100002, lo=0x00000017
IDT[0x93]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x94]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x95]=??? descriptor hi=0x00000000, lo=0xc0003611
IDT[0x96]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x97]=??? descriptor hi=0x00000000, lo=0x00000100
IDT[0x98]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x99]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x9a]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x9b]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x9c]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x9d]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x9e]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x9f]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0xa0]=??? descriptor hi=0x74c008ac, lo=0x6004c6e9
IDT[0xa1]=32-Bit TSS (Busy) at 0x6110cd0e, length 0x5b406
IDT[0xa2]=??? descriptor hi=0x0b8000bf, lo=0x600000c3
IDT[0xa3]=??? descriptor hi=0x000000a0, lo=0xb9c03100
IDT[0xa4]=Data segment, base=0x50000005, limit=0x112a0fff, Read/Write, Expand-down, Accessed
IDT[0xa5]=Data segment, base=0xf6000005, limit=0x000211a0, Read-Only, Accessed
IDT[0xa6]=32-Bit TSS (Available) at 0xc731c801, length 0x159e1
IDT[0xa7]=??? descriptor hi=0xb6da880f, lo=0x740afb80
IDT[0xa8]=Task Gate target=0x1789:0x0511663f, DPL=0
IDT[0xa9]=Task Gate target=0x0deb:0x05110000, DPL=0
IDT[0xaa]=Data segment, base=0x0005fe00, limit=0x00050000, Read/Write
IDT[0xab]=Code segment, base=0x1f5360c3, limit=0xa6100fff, Execute/Read, Conforming, Accessed, 16-bit
IDT[0xac]=??? descriptor hi=0xffa9e808, lo=0x7400fb80
IDT[0xad]=??? descriptor hi=0x123d8af1, lo=0xeb47ffff
IDT[0xae]=Data segment, base=0x001d8a00, limit=0x00050005, Read-Only, Accessed
IDT[0xaf]=??? descriptor hi=0xc3610000, lo=0x0002e800
IDT[0xb0]=??? descriptor hi=0x00000050, lo=0xb9c03160
IDT[0xb1]=Code segment, base=0xc300e1f7, limit=0x9f888fff, Execute-Only, Non-Conforming, 16-bit
IDT[0xb2]=16-Bit TSS (Busy) at 0x88d4ba66, length 0xe0fb0
IDT[0xb3]=32-Bit Interrupt Gate target=0xd5ba:0xc03166d8, DPL=3
IDT[0xb4]=16-Bit TSS (Busy) at 0x88d4ba66, length 0xe0eb0
IDT[0xb5]=32-Bit Interrupt Gate target=0xd5ba:0xc36166f8, DPL=3
IDT[0xb6]=32-Bit TSS (Busy) at 0x668000bf, length 0x0fc60
IDT[0xb7]=Data segment, base=0xf33fb407, limit=0x0000d0b9, Read-Only
IDT[0xb8]=Task Gate target=0x05c6:0x0000ab66, DPL=0
IDT[0xb9]=??? descriptor hi=0x00000005, lo=0x1205c600
IDT[0xba]=Task Gate target=0xa260:0x0000c361, DPL=0
IDT[0xbb]=??? descriptor hi=0xc3610000, lo=0x05122588
IDT[0xbc]=LDT
IDT[0xbd]=??? descriptor hi=0x00000000, lo=0x0000c361
IDT[0xbe]=??? descriptor hi=0x9b000000, lo=0xffff0000
IDT[0xbf]=??? descriptor hi=0x93000000, lo=0xffff00cf
IDT[0xc0]=Task Gate target=0x0017:0x000000cf, DPL=0
IDT[0xc1]=16-Bit Call Gate target=0xddb0:0xc35850fa, DPL=3
IDT[0xc2]=Data segment, base=0xe6002fe8, limit=0xd60fafff, Read-Only
IDT[0xc3]=Data segment, base=0x64b00028, limit=0x6e864fff, Read-Only
IDT[0xc4]=16-Bit Interrupt Gate target=0xe400:0xe85028e8, DPL=3
IDT[0xc5]=16-Bit Call Gate target=0xd1b0:0x13e8001a, DPL=3
IDT[0xc6]=16-Bit Interrupt Gate target=0x0c58:0xe8606600, DPL=3
IDT[0xc7]=16-Bit Call Gate target=0xaeb0:0x03e8000a, DPL=3
IDT[0xc8]=16-Bit Call Gate target=0xc3fb:0x02a86100, DPL=3
IDT[0xc9]=??? descriptor hi=0x7401a864, lo=0xe4c3fa75
IDT[0xca]=16-Bit Call Gate target=0xb860:0x15cdc3fa, DPL=1
IDT[0xcb]=16-Bit Interrupt Gate target=0xb050:0x5892c361, DPL=3
IDT[0xcc]=Data segment, base=0x204f2079, limit=0x00004dc3, Read/Write, Accessed
IDT[0xcd]=??? descriptor hi=0xe0020001, lo=0x01020020
IDT[0xce]=??? descriptor hi=0x00120009, lo=0xf00b4000
IDT[0xcf]=??? descriptor hi=0x00000000, lo=0x00000002
IDT[0xd0]=16-Bit TSS (Busy) at 0xa1290000, length 0x20000
IDT[0xd1]=16-Bit Interrupt Gate target=0x534f:0x4f4c4da0, DPL=2
IDT[0xd2]=16-Bit TSS (available) at 0x31462059, length 0x45050
IDT[0xd3]=??? descriptor hi=0x0fff0021, lo=0x20202032
IDT[0xd4]=LDT
IDT[0xd5]=16-Bit TSS (available) at 0x06f7066b, length 0x30e8a
IDT[0xd6]=Data segment, base=0x76d231c3, limit=0x0006069c, Read/Write, Expand-down, Accessed
IDT[0xd7]=??? descriptor hi=0x3106a016, lo=0x88c2fe06
IDT[0xd8]=??? descriptor hi=0xa1168806, lo=0x7836f7d2
IDT[0xd9]=Code segment, base=0x00c306a2, limit=0x0005a206, Execute/Read, Conforming, Accessed, 16-bit
IDT[0xda]=Code segment, base=0x02dde851, limit=0x45350fff, Execute/Read, Conforming, Accessed, 64-bit
IDT[0xdb]=16-Bit Interrupt Gate target=0x2e8a:0x0e8a01b0, DPL=0
IDT[0xdc]=16-Bit Interrupt Gate target=0x368a:0x168a06a0, DPL=0
IDT[0xdd]=32-Bit Call Gate target=0x13cd:0xc0310682, DPL=0
IDT[0xde]=Code segment, base=0xd85b594f, limit=0x000513cd, Execute-Only, Non-Conforming, 32-bit
IDT[0xdf]=16-Bit TSS (Busy) at 0x69585b59, length 0xe18cd
IDT[0xe0]=??? descriptor hi=0x310660c3, lo=0xc9e24006
IDT[0xe1]=??? descriptor hi=0x26f70020, lo=0xb8d231c9
IDT[0xe2]=16-Bit Interrupt Gate target=0x36f7:0xa091066f, DPL=0
IDT[0xe3]=16-Bit Interrupt Gate target=0x26f7:0x0603066e, DPL=0
IDT[0xe4]=16-Bit TSS (available) at 0x9c069ca3, length 0xe066c
IDT[0xe5]=Code segment, base=0x000702e0, limit=0x00006806, Execute/Read, Non-Conforming, Accessed, 16-bit
IDT[0xe6]=16-Bit TSS (Busy) at 0x066107ff, length 0x09ae8
IDT[0xe7]=Data segment, base=0x74066ea0, limit=0x0006c031, Read/Write, Expand-down, Accessed
IDT[0xe8]=16-Bit Interrupt Gate target=0xa1c1:0xc0688906, DPL=0
IDT[0xe9]=Code segment, base=0x07e8db31, limit=0xf0702fff, Execute/Read, Conforming, 32-bit
IDT[0xea]=32-Bit TSS (Available) at 0x8b535251, length 0x3c361
IDT[0xeb]=32-Bit Interrupt Gate target=0xbf06:0x51fc6f0e, DPL=1
IDT[0xec]=Data segment, base=0xa6de8900, limit=0x30bb9fff, Read/Write, Expand-down, Accessed
IDT[0xed]=16-Bit Trap Gate target=0x590d:0xe220745f, DPL=2
IDT[0xee]=Code segment, base=0xc3b8595a, limit=0xf5beefff, Execute/Read, Conforming, Accessed, 32-bit
IDT[0xef]=16-Bit Interrupt Gate target=0x595a:0xc9315b58, DPL=3
IDT[0xf0]=32-Bit TSS (Busy) at 0x83e85553, length 0xf5166
IDT[0xf1]=Code segment, base=0x595d0875, limit=0x0006fff8, Execute/Read, Non-Conforming, Accessed, 32-bit
IDT[0xf2]=16-Bit TSS (available) at 0x0066c3ff, length 0xfffb8
IDT[0xf3]=??? descriptor hi=0x002e002d, lo=0x6600002e
IDT[0xf4]=16-Bit Interrupt Gate target=0x02e0:0x558b6800, DPL=1
IDT[0xf5]=Code segment, base=0x53069e16, limit=0x0007891a, Execute/Read, Non-Conforming, Accessed, 16-bit
IDT[0xf6]=Code segment, base=0x07a1ff82, limit=0x0006e806, Execute/Read, Conforming, 16-bit
IDT[0xf7]=32-Bit TSS (Available) at 0x0e31fee7, length 0xae85b
IDT[0xf8]=16-Bit Interrupt Gate target=0x08e8:0x6659066b, DPL=3
IDT[0xf9]=Code segment, base=0x02065351, limit=0x06641fff, Execute-Only, Non-Conforming, 32-bit
IDT[0xfa]=Code segment, base=0x89a1db31, limit=0x0006c08e, Execute/Read, Conforming, 16-bit
IDT[0xfb]=16-Bit TSS (available) at 0xbbead1c2, length 0x189c1
IDT[0xfc]=32-Bit TSS (Busy) at 0xa926cb01, length 0x70000
IDT[0xfd]=LDT
IDT[0xfe]=32-Bit TSS (Available) at 0x9e04eac1, length 0x603eb
IDT[0xff]=Data segment, base=0x070ff0fa, limit=0x58106fff, Read/Write
You can list individual entries with 'info idt [NUM]' or groups with 'info idt [NUM] [NUM]'
Looks like IDTR (register) somehow zeroes itself (because printf() gives good address, so struct is all good).
This only happens with -O3 or -O2 flag enabled. Otherwise it works as expected.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Placing kernel in 4MB in RAM on real hardware.
So, if lidt [_idtr] is in all cases reached and IDTR (the CPU version) has the correct value afterwards, then either:
- lidt gets called again
- the machine crashed/rebooted.
And I would guess you already eliminated the second option because that would give you fancy crashdumps even without a debugger.
Interestingly, in all cases the IDT is broken again after exactly one function call, which feels like it is some sort of stack corruption. Either way, order your functions so that you have the least instructions between correct and failed state, and then single-step through them and compare them to the disassembled version to see where the flow goes off in the wrong direction.
- lidt gets called again
- the machine crashed/rebooted.
And I would guess you already eliminated the second option because that would give you fancy crashdumps even without a debugger.
Interestingly, in all cases the IDT is broken again after exactly one function call, which feels like it is some sort of stack corruption. Either way, order your functions so that you have the least instructions between correct and failed state, and then single-step through them and compare them to the disassembled version to see where the flow goes off in the wrong direction.
Re: Placing kernel in 4MB in RAM on real hardware.
Ok, I'll try to look for it this weekend.Combuster wrote:So, if lidt [_idtr] is in all cases reached and IDTR (the CPU version) has the correct value afterwards, then either:
- lidt gets called again
- the machine crashed/rebooted.
And I would guess you already eliminated the second option because that would give you fancy crashdumps even without a debugger.
Interestingly, in all cases the IDT is broken again after exactly one function call, which feels like it is some sort of stack corruption. Either way, order your functions so that you have the least instructions between correct and failed state, and then single-step through them and compare them to the disassembled version to see where the flow goes off in the wrong direction.
Thanks for the tips!
Ok, so I have found that the stack (indeed) becomes corrupted.
After first function it is: ESP=c02ffdf8 but right after second (where the IDT becomes messed up) it's: ESP=c02ffdec.
What's more here is code:
Code: Select all
function1(); // after exiting I have ESP = c02ffdf8
function2(); // after exiting I have ESP = c02ffdec
[...]
void function2()
{
// here I have ESP = c02ffdf8!!!! (looks like EIP is not pushed here? maybe because of the optimalization O3)
outportb(0xA0, 0x11); // ICW 1 // here, after exiting the ESP = c02ffdcc
[... some code ...]
}
Re: Placing kernel in 4MB in RAM on real hardware.
Regarding my problems.
I'm sure it's caused by not using the cross-compiler (because O3 flag on my x86_64 architecture makes code totally not bootable).
So in the near future I'm going to do the cross-compiling stuff.
I have question though: is it ok to select i686-elf architecture but compiling to flat binary?
EDIT:
I managed to create i686-elf-gcc cross-compiler.
Because I wanted just to see if it works I compiled every C-code and then linked it using ld (yes, I know it's a bad practise - I just wanted to check if everything can compile).
Aaaaand.... It partially works!
I mean flags like -O or -O2 work, and there are no problems with stack!!! I'll test it on real hardware shortly.
But the -O3 flags gives something like that during linking:.
Of course I don't have such function in my kernel, or anywhere. I also don't use -O3 flag anywhere in my system, because I've heard it can cause problems.
But is it possible that gcc (even if instructed not to use any standard libraries) tries to put something on its own?
I'm sure it's caused by not using the cross-compiler (because O3 flag on my x86_64 architecture makes code totally not bootable).
So in the near future I'm going to do the cross-compiling stuff.
I have question though: is it ok to select i686-elf architecture but compiling to flat binary?
EDIT:
I managed to create i686-elf-gcc cross-compiler.
Because I wanted just to see if it works I compiled every C-code and then linked it using ld (yes, I know it's a bad practise - I just wanted to check if everything can compile).
Aaaaand.... It partially works!
I mean flags like -O or -O2 work, and there are no problems with stack!!! I'll test it on real hardware shortly.
But the -O3 flags gives something like that during linking:
Code: Select all
[name of the function in file] undefined reference to `memset'
Of course I don't have such function in my kernel, or anywhere. I also don't use -O3 flag anywhere in my system, because I've heard it can cause problems.
But is it possible that gcc (even if instructed not to use any standard libraries) tries to put something on its own?
Re: Placing kernel in 4MB in RAM on real hardware.
Read the gcc documentation for -ffreestanding. You must supply memset, memcpy, memcmp and memmove.