Page 1 of 2

memory write error

Posted: Mon Jun 23, 2008 11:27 am
by suthers
well I've recently fixed my memory allocation problems (I messed up my linker script..., so it was calculating the .bss and .data section addresses over the .text section...).
But now I have another weird problem.
I use this code to add an intterupt to my IDT:

Code: Select all

void install_int(unsigned char int_no, unsigned int address, unsigned short gdt_selector, unsigned char flags)
{
	idt[int_no]->address_low = (address & 0xFFFF);
	idt[int_no]->gdt_selector = gdt_selector;
	idt[int_no]->unused = 0;
	idt[int_no]->flags = flags;
	idt[int_no]->address_high = ((address >> 16) & 0xFFFF);
	return;
};
which translates into this in asm:

Code: Select all

00000402  83EC0C            sub esp,byte +0xc
00000405  891C24            mov [esp],ebx
00000408  89742404          mov [esp+0x4],esi
0000040C  897C2408          mov [esp+0x8],edi
00000410  8B5C2414          mov ebx,[esp+0x14]
00000414  8B7C241C          mov edi,[esp+0x1c]
00000418  0FB7742418        movzx esi,word [esp+0x18]
0000041D  0FB64C2410        movzx ecx,byte [esp+0x10]
00000422  BA002C1000        mov edx,0x102c00
00000427  8B048A            mov eax,[edx+ecx*4]
0000042A  668918            mov [eax],bx
0000042D  8B048A            mov eax,[edx+ecx*4]
00000430  66897002          mov [eax+0x2],si
00000434  8B048A            mov eax,[edx+ecx*4]
00000437  C6400400          mov byte [eax+0x4],0x0
0000043B  8B348A            mov esi,[edx+ecx*4]
0000043E  89F8              mov eax,edi
00000440  884605            mov [esi+0x5],al
00000443  8B048A            mov eax,[edx+ecx*4]
00000446  C1EB10            shr ebx,0x10
00000449  66895806          mov [eax+0x6],bx
0000044D  8B1C24            mov ebx,[esp]
00000450  8B742404          mov esi,[esp+0x4]
00000454  8B7C2408          mov edi,[esp+0x8]
00000458  83C40C            add esp,byte +0xc
0000045B  C3                ret
One can clearly see that the IDT is been written to memory at base 0x102C00.
There is a similar thing or my IDT, it is written to 0x1033F0.
But in both cases when I use them in bochs then use the 'x' command to read certain parts of memory, both of these places clearly show up as blank...
This weird, because though there is a clear write, the memory still turns up as blank...
I used bochs to step through my kernel, and these instructions are clearly executed...
But this is the weirdest thing:
I steeped through it in bochs and just after the instruction 'mov eax,[edx+ecx*4]' this is the state of the regs:

Code: Select all

rax: 0x00000000:00000000 rcx: 0x00000000:0000001c
rdx: 0x00000000:00102c00 rbx: 0x00000000:00100148
rsp: 0x00000000:001023b4 rbp: 0x00000000:00000000
rsi: 0x00000000:00000008 rdi: 0x00000000:0000008e
r8 : 0x00000000:00000000 r9 : 0x00000000:00000000
r10: 0x00000000:00000000 r11: 0x00000000:00000000
r12: 0x00000000:00000000 r13: 0x00000000:00000000
r14: 0x00000000:00000000 r15: 0x00000000:00000000
rip: 0x00000000:00100427
eflags 0x00000216
edx is the base of the IDT, ecx is the reference to the entry to the IDT. the value that should be outputted into eax by this would be correct, but for some reason, eax is zero..., the value fits well within 32bits so it isn't an overflow problem.
This is a really weird error, because of this my IDT is being written to 0x00000000 (which weirdly doesn't cause it to crash, but I'll look into that later....)
I'm not aware of any reason why a mov instruction should fail....
Anybody got any explanation for this?
Thanks in advance,

Jules

Re: memory write error

Posted: Mon Jun 23, 2008 12:29 pm
by Combuster
edx is the base of the IDT, ecx is the reference to the entry to the GDT
(...)
Anybody got any explanation for this?
GDT != IDT? :roll:

Re: memory write error

Posted: Mon Jun 23, 2008 12:39 pm
by suthers
Combuster wrote:
edx is the base of the IDT, ecx is the reference to the entry to the GDT
(...)
Anybody got any explanation for this?
GDT != IDT? :roll:
I really don't know what your talking about... :oops:
Sorry I'm a bit tired, I just finished my exams on Friday and I'm still tired... (and traumatised... :lol: ).
Still don't understand this weird bug...
Thanks in advance,

Jules

Re: memory write error

Posted: Mon Jun 23, 2008 12:46 pm
by Combuster
It looks like you're indexing the IDT with a segment selector, which can't be right...

Re: memory write error

Posted: Mon Jun 23, 2008 1:06 pm
by suthers
What do you mean, I do put a segment selector in the IDs..., but you're supposed to right?
Sorry, I think I'm a bit confused...
Thanks in advance,


Jules

Re: memory write error

Posted: Mon Jun 23, 2008 1:12 pm
by Combuster
goto is bad unless it points to 0xBED

think about it :wink:

Re: memory write error

Posted: Mon Jun 23, 2008 1:27 pm
by suthers
Thinking....
Thinking.....
Thinking......
#TF, brain halted to protect my sanity....
Ok, I'm confused, 'goto', there isn't a jmp or call....
Or am I completely, 1000% confused....
Thanks in advance,

Jules

P.S. I can feel the not fit for OSdev stamp coming, but believe me I'm really tired, but its only 8:30pm here and I've got nothing else to do and I'm in an OSdev mood even though I'm 0xDEAD tired... :wink:

Re: memory write error

Posted: Mon Jun 23, 2008 1:31 pm
by suthers
Or is points the clue?.... :-k
Thanks in advance,

Jules

Re: memory write error

Posted: Mon Jun 23, 2008 1:37 pm
by Combuster
but believe me I'm really tired, but its only 8:30pm here and I've got nothing else to do and I'm in an OSdev mood even though I'm 0xDEAD tired... :wink:
Well the combination doesn't quite seem to work :wink:

Re: memory write error

Posted: Mon Jun 23, 2008 1:44 pm
by suthers
True, it's just that I didn't sleep very well last night...
But just out of interest, is 'points' the clue?
Because I don't understand how it could be anything to do with goto...
Thanks in advance,

Jules

Re: memory write error

Posted: Mon Jun 23, 2008 1:45 pm
by Omega
haha, he said is points the clue... 0xBED... I think goto was the keyword in this case. :)

Re: memory write error

Posted: Mon Jun 23, 2008 1:49 pm
by suthers
](*,) :oops: , bloody hell I'm an idiot, its moving into eax whatever is at that address not the actual number...
Which is zero.
I interpreted the whole thing wrong...
anyway if ecx was referencing the IDT entry, it would have to be ecx * 8 since and IDT entry is 8 bytes long...
Still wondering why the compiler is outputting this..., is this another memory management error...
Any ideas?
Thanks in advance,

Jules

edit: OSdeving when tired is a really bad idea, but I've got nothing else to do and I really want to right now...

Re: memory write error

Posted: Mon Jun 23, 2008 1:56 pm
by suthers
Or am I missing something else?
(That was definitely something I hadn't seen though...)
Thanks in advance,

Jules

Re: memory write error

Posted: Mon Jun 23, 2008 2:01 pm
by Combuster
suthers wrote:edit: OSdeving when tired is a really bad idea, but I've got nothing else to do and I really want to right now...
Then let's start about your OS's name :twisted:

Re: memory write error

Posted: Mon Jun 23, 2008 2:03 pm
by sngskunk
What does you structure look like?