When booting kernel in QEMU, QEMU just stays idle...
-
- Posts: 20
- Joined: Sun Jan 02, 2011 4:46 pm
When booting kernel in QEMU, QEMU just stays idle...
I've created a C kernel, and I've booted my kernel using the QEMU emulator. No error occurs, but QEMU emulator window just stays idle and prints 'Booting Hard Disk...'. Does it take that long to boot a small a** kernel... *cough* excuse my French. There is a screenshot attached below if you would like to see for your self what I'm taking about. I'll also post the source code below too as an attachment.
- Attachments
-
- Kernel.c
- The kernel's C source file.
- (1.02 KiB) Downloaded 166 times
-
- Kernel.asm
- The kernel's assembler source.
- (227 Bytes) Downloaded 123 times
Re: When booting kernel in QEMU, QEMU just stays idle...
When you hlt with interrupts disabled in qemu, qemu will stop updating the display. This will be one of your problems.
This will also be a problemVideo memory is at 0xb8000.
This will also be a problem
Code: Select all
volatile char* videomem = (volatile char*) 0xB800;
If a trainstation is where trains stop, what is a workstation ?
-
- Posts: 20
- Joined: Sun Jan 02, 2011 4:46 pm
Re: When booting kernel in QEMU, QEMU just stays idle...
I've did some changes, to both Kernel.asm and Kernel.c, but still the QEMU emulator just stays still and doesn't do anything. Here is command I used to start QEMU:
Code For Kernel.asm:
Code For Kernel.c:
P.S By the way my OS is Windows 7, but you probably could tell because of the file directory...
Code: Select all
qemu -L "C:\Program Files (x86)\Qemu\pc-bios" -hda win.qcow -kernel Kernel.bin -boot c
Code: Select all
;NASM Code For The Kernel
[BITS 32] ; Sets up 32-bit protected mode for the kernel!
[global start]
[extern _dmain]
start:
call _dmain ; Invokes the main function which is located in C the code.
hlt
Code: Select all
// This source file contains the main algorithm for the Kernel.
// Written in C and written by Daniel Lopez
//Global variable, containing the pointer to the video memory.gcc
volatile char* videomem = (volatile char*) 0xb800;
void print_string(int color, char* string)
{
while(*string != 0)
{
*videomem = *string; // Assign each character to memory location 0xB800.
*videomem++;
string++;
*videomem = color;
videomem++;
}
}
int string_length(char* string) // This subroutine determines a string's length but not including the null terminating character.
{
int length = 0;
while(*string++)
{
length++;
}
return length;
}
void reverse_string(char* string, char* reversed_string) // This subroutine reverses a char array.
{
int length = string_length(string) + 1;
while(length == 0) // Loops until the length is equal to zero.
{
*reversed_string = string[length];
length--;
reversed_string++;
}
}
dmain(void)
{
print_string(8, "This is my first kernel!\n\nWelcome!");
}
Re: When booting kernel in QEMU, QEMU just stays idle...
Rather than Wouldn't be better ?
Code: Select all
volatile char* videomem = (volatile char*) 0xb800;
Code: Select all
volatile char* videomem = (volatile char*) 0xb8000;
If a trainstation is where trains stop, what is a workstation ?
-
- Posts: 20
- Joined: Sun Jan 02, 2011 4:46 pm
Re: When booting kernel in QEMU, QEMU just stays idle...
Damn...I didn't see the lack of a zero...sorry about that...I feel like a newbie...actually I'm . But still when I change the hex address to the correct address. It still stays idle and on top of that my AV scanner thinks my kernel is some trojan / virus which is a fallacy. But that is irrelevant to the problem. Oh...thanks for the help I appreciate your time and effort.
Re: When booting kernel in QEMU, QEMU just stays idle...
Hello,
You are overwriting your character with the attribute byte. Also, I would personally recommend rewriting your print_string routine. It can be written much better.
Code: Select all
*videomem++;
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Re: When booting kernel in QEMU, QEMU just stays idle...
Sorry, am I missing something here about QEMU or the original post?monsterhunter445 wrote:Code: Select all
;NASM Code For The Kernel [BITS 32] ; Sets up 32-bit protected mode for the kernel! [global start] [extern _dmain] start: call _dmain ; Invokes the main function which is located in C the code. hlt
It doesn't look to me like the OP actually sets up protected mode, his stack segment, or anything else about his environment.. Nor does he specify that he is one of those odd folk using one of a handful of real mode C compilers.
Re: When booting kernel in QEMU, QEMU just stays idle...
Can we have your bootloader source code? May be you have not loaded enough sectors from the disk(with respect to the size of the kernel). Did it ever work at some point of time?
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
- xenos
- Member
- Posts: 1121
- Joined: Thu Aug 11, 2005 11:00 pm
- Libera.chat IRC: xenos1984
- Location: Tartu, Estonia
- Contact:
Re: When booting kernel in QEMU, QEMU just stays idle...
According to the QEMU docs, a kernel loaded by the -kernel command line option needs to be either a bzImage or Multiboot compliant. It seems that your kernel does not belong to any of these categories. Probably the easiest way to fix this is to include a Multiboot header (see the link above) in your code.monsterhunter445 wrote:Code: Select all
qemu -L "C:\Program Files (x86)\Qemu\pc-bios" -hda win.qcow -kernel Kernel.bin -boot c
(I never used the -kernel option, though.)
Re: When booting kernel in QEMU, QEMU just stays idle...
Personally, I would consider writing my own boot loader. Also, as it seems, you have done nothing in the way of initialisation. How does the kernel know where all of its data is going? Consider setting yourself up properly. On top of this, set yourself up in PMode, OR, write the whole thing in ASM. As well, [bits 32] comes later, when PMode has been set up. Put your multiboot header in, if you wish to use QEMU's loader, or GRUB, or anything else, for that matter, other than your own. Sorry, got a bit carried away there. But there is significantly a lot you can do. What does your makefile look like? Because, no offence, but judging by the mistakes you have made so far, its possible you are linking to ELF, or PE format. I don't know what formats QEMU supports in the way of multiboot executables, but I know that it would probably be wise to go flat binary.
- 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: When booting kernel in QEMU, QEMU just stays idle...
Will you please read up on multiboot before making incorrect or misleading claims, like most if not all of your post.death2all wrote:I don't know what formats QEMU supports in the way of multiboot executables, but I know that it would probably be wise to go flat binary.
- xenos
- Member
- Posts: 1121
- Joined: Thu Aug 11, 2005 11:00 pm
- Libera.chat IRC: xenos1984
- Location: Tartu, Estonia
- Contact:
Re: When booting kernel in QEMU, QEMU just stays idle...
I don't know what the heck QEMU is doing to make my (as I thought) Multiboot compliant ELF kernel crash completely when I try to load it with the -kernel option o.O Not even my physical memory manager works, even though the Multiboot info seems to be fine... I'm really curious to find out what's going on there, although I guess it would need a lot of debugging, and the result would not be of any practical use since my kernel will never be loaded this way.
I recommend using GRUB instead - it can save you a lot of trouble. (But if you want to go through a lot of trouble in order to learn something, start writing a boot loader from scratch, learn about the transition to protected mode and have fun )
I recommend using GRUB instead - it can save you a lot of trouble. (But if you want to go through a lot of trouble in order to learn something, start writing a boot loader from scratch, learn about the transition to protected mode and have fun )
- xenos
- Member
- Posts: 1121
- Joined: Thu Aug 11, 2005 11:00 pm
- Libera.chat IRC: xenos1984
- Location: Tartu, Estonia
- Contact:
Re: When booting kernel in QEMU, QEMU just stays idle...
I found the reason why my kernel crashes when it gets loaded by QEMU with the -kernel option: Im simulating a machine with 128 MB RAM. In the Multiboot structure, QEMU reports 128 MB of upper memory - but it should report only 127 MB since the first 1 MB belongs to lower memory. This causes my memory manager to assume that there is 1 MB more memory and it starts allocating pages and placing page tables in this non-existing area, which quickly leads to a page fault...