memory write error

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

memory write error

Post 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
Last edited by suthers on Mon Jun 23, 2008 12:37 pm, edited 1 time in total.
User avatar
Combuster
Member
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: memory write error

Post 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:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Re: memory write error

Post 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
User avatar
Combuster
Member
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: memory write error

Post by Combuster »

It looks like you're indexing the IDT with a segment selector, which can't be right...
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Re: memory write error

Post 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
User avatar
Combuster
Member
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: memory write error

Post by Combuster »

goto is bad unless it points to 0xBED

think about it :wink:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Re: memory write error

Post 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:
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Re: memory write error

Post by suthers »

Or is points the clue?.... :-k
Thanks in advance,

Jules
User avatar
Combuster
Member
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: memory write error

Post 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:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Re: memory write error

Post 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
User avatar
Omega
Member
Member
Posts: 250
Joined: Sun May 25, 2008 2:04 am
Location: United States
Contact:

Re: memory write error

Post by Omega »

haha, he said is points the clue... 0xBED... I think goto was the keyword in this case. :)
Free energy is indeed evil for it absorbs the light.
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Re: memory write error

Post 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...
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Re: memory write error

Post by suthers »

Or am I missing something else?
(That was definitely something I hadn't seen though...)
Thanks in advance,

Jules
User avatar
Combuster
Member
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: memory write error

Post 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:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
sngskunk
Member
Member
Posts: 47
Joined: Mon Mar 31, 2008 1:00 pm
Location: Louisville, KY, USA

Re: memory write error

Post by sngskunk »

What does you structure look like?
Currently Working On:
Bootloader (Stage 1) (Complete)
Bootloader (Stage 2) (Inprogress)
Post Reply