Help with scheduler (source attached)
Posted: Wed Jul 18, 2007 7:47 am
I'm in the process of transferring my old C kernel over into C++ (I've completely restructured the code and how everything works). I'm having a problem with my scheduler.
In kernel/timer.cpp, there's a method Timer::Handler() that gets called upon each clock interrupt. This function is suppose to rotate the system between tasks. Here is what it currently looks like:
What that function should do:
- Set m_currentThread (the currently loaded thread) to the next thread on the linked list.
- If m_currentThread points to 0 (either we've passed the end of the list, or it's the first call and nothing is currently running) then point to the first thread again (m_firstThread).
- Set the active thread to m_firstThread. The active thread is currently hard coded, and it's the thread keyboard events are sent to.
- Load the thread's page table into memory.
(Actually I should replace the name Thread with Process because while they started out as threads, they now each have their own address space.)
All the function does is keep the system running m_firstThread. If I manually enter above memory.LoadProcessPageTable I know there is nothing wrong with my code since it will place the system in the 2nd thread.
I think it may have something to do with optimization, but I am compiling with: (where $GPP='i586-elf-g++' and $FILE='memory.cpp')
I have included my kernel if someone would please have a look at it if you have the time. To build the source, just run build.sh from bash (you will want to edit it and change the cd path first). There's also a build.bat which runs build.sh through Cygwin's bash. The 4 folders included in the attachment are:
- Kernel - The kernel (it builds kernel.bin). The disk image is call stored in here (dev_kernel_grub.img).
- Sample Program - My testing program. It should loop and print a yellow '!' on the screen (SampleProgram.prog).
- Library - My user library (generates Library.lib which is statically linked to .prog files).
- AnnoyMe - It should flood the screen with white 'a''s (AnnoyMe.prog).
The programs are loaded through Grub with the module command. Everything works fine if I only load one module, but I would like my OS to be a multitasking system. The desired effect I'm looking for is to visually see the operating system switch between the two programs (by outputting "!!!!!!!!!!!!aaaaaaaaa!!!!!!!!!!!aaaaaaaaaaa" so I can see each program output while it has its share of the processor).
EDIT: This forum has a 64KB limit and the .zip is 125KB. So I uploaded it to my website instead: http://messiahandrw.netfast.org/Source.zip
EDIT 2: I may just be my browser, that link brings up advertisements when I click on it. Copying and pasting the address works fine.
In kernel/timer.cpp, there's a method Timer::Handler() that gets called upon each clock interrupt. This function is suppose to rotate the system between tasks. Here is what it currently looks like:
Code: Select all
unsigned int Timer::Handler(unsigned int oldEsp)
{
if(m_currentThread != 0)
{
m_currentThread->GetStack()->esp0 = (unsigned int *)oldEsp;
m_currentThread = m_currentThread->GetNext();
}
if(m_currentThread == 0)
{
m_currentThread = m_firstThread;
}
m_activeThread = m_firstThread;
memory.LoadProcessPageTable(m_currentThread->GetPageTable());
return (unsigned int)m_currentThread->GetStack()->esp0;
}
- Set m_currentThread (the currently loaded thread) to the next thread on the linked list.
- If m_currentThread points to 0 (either we've passed the end of the list, or it's the first call and nothing is currently running) then point to the first thread again (m_firstThread).
- Set the active thread to m_firstThread. The active thread is currently hard coded, and it's the thread keyboard events are sent to.
- Load the thread's page table into memory.
(Actually I should replace the name Thread with Process because while they started out as threads, they now each have their own address space.)
All the function does is keep the system running m_firstThread. If I manually enter
Code: Select all
m_currentThread = m_firstThread->GetNext();
I think it may have something to do with optimization, but I am compiling with: (where $GPP='i586-elf-g++' and $FILE='memory.cpp')
Code: Select all
$GPP -c $FILE -nostdlib -fno-builtin -fno-rtti -fno-exceptions
- Kernel - The kernel (it builds kernel.bin). The disk image is call stored in here (dev_kernel_grub.img).
- Sample Program - My testing program. It should loop and print a yellow '!' on the screen (SampleProgram.prog).
- Library - My user library (generates Library.lib which is statically linked to .prog files).
- AnnoyMe - It should flood the screen with white 'a''s (AnnoyMe.prog).
The programs are loaded through Grub with the module command. Everything works fine if I only load one module, but I would like my OS to be a multitasking system. The desired effect I'm looking for is to visually see the operating system switch between the two programs (by outputting "!!!!!!!!!!!!aaaaaaaaa!!!!!!!!!!!aaaaaaaaaaa" so I can see each program output while it has its share of the processor).
EDIT: This forum has a 64KB limit and the .zip is 125KB. So I uploaded it to my website instead: http://messiahandrw.netfast.org/Source.zip
EDIT 2: I may just be my browser, that link brings up advertisements when I click on it. Copying and pasting the address works fine.