Some general unrelated questions
Posted: Fri Dec 26, 2014 7:01 am
Hi,
I have been working on OS development for the past 1 & 1/2 year, and I have learned a lot from OSDEV. I also have been followng James Molly Tutorial vry closely but I tried the concepta and as much as the code of the tutorial that I can migrate to 64-bit.
I was able to write my own hobby OS for learning which included:
I was using this environment as a sandbox for trying out things and playing around, and I did not intend by any means of having a good looking products. So what I have right now is not a pretty clean hobby OS, rather the code is dirty and not very optimum and organized.
I now feel that I have reached a rescratch point which I will need to write a cleaner version with the knowledge and the experimence I gained so far; I had this case more than once which is while I am adding a new thing I say for example if the memory mapper was implemented in a different way it would have been better.
Also, I reached a point were the code is more difficult to manage and this encourages me to start it from a clean ground.
Nevertheless, I would like to make use of what I have right now, through asking questions about problems and situations I am facing as well as situations that I would like and expect to have while I am starting the relatively clean second round.
I would appreciate if anyone has answers to all or subset of my questions below. I would also appreciate that people who are willing to respond do respond even if they find that others responded.
My questions are:
Q1: Is it possible that I enable PIC on the BSP and APIC on the APs. I have read that to be able to enable APIC you need to disable PIC, but I don't really see a conflict; PIC is configured to interrupt the BSP only, so is there a way to enable APIC on the APs?
Q2: In long mode, I undertand that memory is a contigeous space that can be used without any care for segmentation. Is there any restriction on the size of the code of my OS. Is there anything that need to be done in case my code exceeded 64 KB? As my kernel started to get bigger, weird inconsistent symptoms started to happen. For example, some methods in my classes points to memory locations outside the code segment, so whenever I call such methods I get page faults .
Q3: Some times Qemu reboots unexpectedly. When I looked into the problem I dicovered that it happens during the initialization of the PIC. This does not happen consistently, it the PIC initialization is passed everything is stable and the kernel can run for hours. I have discovered that this happens between initailizing the PIC and setting the flags of all the interrupts to mask it. The below code shows what I mean:
Q5: My kernel runs when I use --enable-kvm while it crashes when I remove this flag from the Qemu Command line.
Q6: How can I use Bochs to run my OS with more than 2048 MB. Is there a way?
Thanks a lot.
Karim
I have been working on OS development for the past 1 & 1/2 year, and I have learned a lot from OSDEV. I also have been followng James Molly Tutorial vry closely but I tried the concepta and as much as the code of the tutorial that I can migrate to 64-bit.
I was able to write my own hobby OS for learning which included:
- Booting my own boot loader
Switching to 64-bit Long Mode
Paging
Memory Heaps
IDT with PIC, RTC, and Keyboard
A driver for Realtec network card on Qemu.
A simple scheduler within the PIC
IPI and interrupt forwarding from BSP to APs
I was using this environment as a sandbox for trying out things and playing around, and I did not intend by any means of having a good looking products. So what I have right now is not a pretty clean hobby OS, rather the code is dirty and not very optimum and organized.
I now feel that I have reached a rescratch point which I will need to write a cleaner version with the knowledge and the experimence I gained so far; I had this case more than once which is while I am adding a new thing I say for example if the memory mapper was implemented in a different way it would have been better.
Also, I reached a point were the code is more difficult to manage and this encourages me to start it from a clean ground.
Nevertheless, I would like to make use of what I have right now, through asking questions about problems and situations I am facing as well as situations that I would like and expect to have while I am starting the relatively clean second round.
I would appreciate if anyone has answers to all or subset of my questions below. I would also appreciate that people who are willing to respond do respond even if they find that others responded.
My questions are:
Q1: Is it possible that I enable PIC on the BSP and APIC on the APs. I have read that to be able to enable APIC you need to disable PIC, but I don't really see a conflict; PIC is configured to interrupt the BSP only, so is there a way to enable APIC on the APs?
Q2: In long mode, I undertand that memory is a contigeous space that can be used without any care for segmentation. Is there any restriction on the size of the code of my OS. Is there anything that need to be done in case my code exceeded 64 KB? As my kernel started to get bigger, weird inconsistent symptoms started to happen. For example, some methods in my classes points to memory locations outside the code segment, so whenever I call such methods I get page faults .
Q3: Some times Qemu reboots unexpectedly. When I looked into the problem I dicovered that it happens during the initialization of the PIC. This does not happen consistently, it the PIC initialization is passed everything is stable and the kernel can run for hours. I have discovered that this happens between initailizing the PIC and setting the flags of all the interrupts to mask it. The below code shows what I mean:
Q4: The important question about Q3 is that I cannot debug this with Qemu, as it does not crash it just keep on rebooting when the problem occurs. Also, it is very difficult to debug with Qemu+GDB on 64-bit. I have read multiple posts on this forum about Qemu+x86_64+GDB and I gave it some time trying making it work but I could not get it to work.Ports::outportb(PIC1_DATA, 0xff);
Ports::outportb(PIC2_DATA, 0xff);
Ports::outportb(0x20, 0x11);
Ports::outportb(0xA0, 0x11);
Ports::outportb(0x21, 0x20);
Ports::outportb(0xA1, 0x28);
Ports::outportb(0x21, 0x04);
Ports::outportb(0xA1, 0x02);
Ports::outportb(0x21, 0x01);
Ports::outportb(0xA1, 0x01);
// If some relatively long time takes place here Qemu reboots. I over imposed the situation by inserting an infinite loop here
// for(;;); -> this cause the problem, and without it the problem occurs every now and then.
for ( unsigned char c = 0 ; c < 48 ; c++)
irqSetMask(c);
Q5: My kernel runs when I use --enable-kvm while it crashes when I remove this flag from the Qemu Command line.
Q6: How can I use Bochs to run my OS with more than 2048 MB. Is there a way?
Thanks a lot.
Karim