'Implementing Multitasking' for a beginner

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
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:'Implementing Multitasking' for a beginner

Post by Pype.Clicker »

adeelmahmood1 wrote: i get the same old annoying bochs error
fetch-raw-descriptor LDTR.valid=0
and sometimes i get a
load-seg-reg GDT es.index (1fea) >es.limit (00019)
so wat do u think
ur help is greatly appreciated
I think you're loading garbage into your ES register, and that garbage is simply asking the CPU to access a descriptor that is in the LDT (which hasn't been set yet) or far beyond the GDT limit ...

Check your "pop es", and your "mov es, ..." instructions ...
adeelmahmood1

Re:'Implementing Multitasking' for a beginner

Post by adeelmahmood1 »

hi
well atleast for the
fetch-raw-descriptor LDTR.valid=0
i have found out the problem. actually the problem is in my kernel loader it is not loading the kernel properly in the memory.. i checked this by adding a long function which was just printing text on the screen and then it gave m,e the same error

so it means that there is a certain size limit upto which my kernel is being loaded in the memory and when the size of the kernel goes beyond that limit then it doesnt load the remaining part in the memory thus resulting in an incomplete kernel in the memory

lets say if my kenrel is 12,000 bytes (actually its 9,000 bytes right now) so 12000/512 = 24 sectors
and this is the code i m using for loading it into the memory

Code: Select all

readFloppy:
???;es:bx==> 0000:5000h
???mov ax,0
???mov es,ax
???mov bx,5000h
???
???mov ah,2
???mov al,17???
???mov ch,0???;cylinder=0
???mov cl,3???;sector=2
???mov dh,0???;head=0
???mov dl,0???;floppy drive
???int 13h ???;read it
???jc readFloppy

readFloppy2:
???mov al,17?????????;load another full head
???inc dh
???int 13h
???jc readFloppy2
i know it juts got off-topic but these are all the problems i m having in my way to multitasking

ok now the thing is that before i knew this size problem i just had this readFloppy function to load the kernel in the memory i just added this readFloppy2 and after adding this when i called the setup_GDT() from my kernel i got these bochs errors

00000578434i[FDD ] partial read() on floppy image returns 352/512
00000578946i[FDD ] read() on floppy image returns 0
00008892552p[CPU ] >>PANIC<< prefetch: running in bogus memory

so
1. wat do u think about this size problem do i need to load more sectors off the floppy image coz even this readFloppy2 isnt enough when i write some more functions .. is there any way to load the whole image

2.wat do u think about this GDT thingy .. is there any problem with the GDT code which i attached in my previous post or anything else

desperately waiting for reply
ur help is greatly appreciated
adeelmahmood1

Re:'Implementing Multitasking' for a beginner

Post by adeelmahmood1 »

[tt]??[/tt]
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:'Implementing Multitasking' for a beginner

Post by Pype.Clicker »

adeelmahmood1 wrote: ok now the thing is that before i knew this size problem i just had this readFloppy function to load the kernel in the memory i just added this readFloppy2 and after adding this when i called the setup_GDT() from my kernel i got these bochs errors

00000578434i[FDD ] partial read() on floppy image returns 352/512
00000578946i[FDD ] read() on floppy image returns 0
00008892552p[CPU ] >>PANIC<< prefetch: running in bogus memory
Well, i'm not sure, but it seems that your floppy image is not N*512 bytes, so when bochs tries to load its end, it cannot load a complete sector :(
adeelmahmood1

Re:'Implementing Multitasking' for a beginner

Post by adeelmahmood1 »

ok
just leave everything .. all that size crap ill figure it out some how .. u just plz tell me is this a valid GDT code coz this is wat i need the most

Code: Select all

void setup_GDT_entry (DESCR_SEG *item,
                      dword base, dword limit, byte access, byte attribs) {
  item->base_l = base & 0xFFFF;
  item->base_m = (base >> 16) & 0xFF;
  item->base_h = base >> 24;
  item->limit = limit & 0xFFFF;
  item->attribs = attribs | ((limit >> 16) & 0x0F);
  item->access = access;
}
void setup_GDT() {
  dword tmp;

  /* 0x00 -- null descriptor */
  setup_GDT_entry (&gdt[0], 0, 0, 0, 0);

  /* 0x08 -- code segment descriptor */
  setup_GDT_entry (&gdt[1], ((dword)_CS)<<4, 0xFFFF, ACS_CODE, 0);

  /* 0x10 -- data segment descriptor */
  setup_GDT_entry (&gdt[2], ((dword)_DS)<<4, 0xFFFF, ACS_DATA, 0);

  /* 0x18 -- stack segment descriptor */
  setup_GDT_entry (&gdt[3], ((dword)_SS)<<4, 0xFFFF, ACS_STACK, 0);

  /* 0x20 -- text video mode segment descriptor */
  setup_GDT_entry (&gdt[4], 0xB8000L, 0xFFFF, ACS_DATA, 0);
  /* setting up the GDTR register */
  gdtr.base = ((dword)_DS)<<4;
  gdtr.base += (word)&gdt;
  gdtr.limit = sizeof(gdt)-1;
  lgdt (&gdtr);
}
BTW thanx for ur help
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:'Implementing Multitasking' for a beginner

Post by Pype.Clicker »

well, it seems fine to me except you declared every segment to be 64K-wide (which is pretty unusual :) )

maybe you could check sizeof(gdt) and sizeof(DESCR_SEG) have the expected values... The compiler sometimes require a -O flag or something similar to pack structures so that they really reflect the expected architectural structure.
Tim

Re:'Implementing Multitasking' for a beginner

Post by Tim »

Also, what are _CS, _DS, etc.? These don't have any meaning in any 32-bit compiler I know of.
adeelmahmood1

Re:'Implementing Multitasking' for a beginner

Post by adeelmahmood1 »

well wat do u mean that i have declared every segment 64k wide .. i mean am i not supposed to do that .. if not then wat should i do ??

_CS=0x08
_DS=0x10
_SS=0x18
and pype about this packing the structure ..actually i need to align these segment descriptors to the default boundary and these access bytes for the SEG_DESCR to be aligned on a byte boundary .. how can i do that
thanx for ur help
Post Reply