Kernel Boots but no GRUB Information (higher-half)
Posted: Sun Sep 29, 2013 12:27 pm
Hi Everyone,
So I have begun implementing a higher-half kernel and can successfully boot into it. I boot into a routine which first enables paging and directly maps the first 4MB of code and stack into memory so then I can proceed with with my "kernel_init()" C method which will in turn initialize a proper memory manager and setup more robust paging.
That said, I am having issues actually getting to the point legitimately. When I boot into my kernel, grub starts at the correct place, but my eax register == 0 (before I execute anything). I am not exactly sure why. So everything works until my kernel_init() method checks for the correct magic number and then, obviously, it breaks down.
I should note that it seems directly related to the fact that my .text section begins above 0xc0010000. When I map this directly into the lower 1MB, I find no problems with the eax register. Let me know if you need more information, but I have shown the relevant sections of my kernel dump as well as the linker script.
.lowermem should be my header for grub and _boot is the working entry point. Notice that I do need to trick the entry point into loading at phys memory. My actual entry point is "boot" (no underscore) defined as follows:
Anyone have any ideas about this? Thanks.
-RageD
EDIT: I should be clearer: I can execute code and access relevant portions of the stack at address 0xc0000000. I have manually setup the relevant page directory and page table entries to do this and it works properly. The problem is that the state of the machine is not what I expect when grub hands off execution to my code.
So I have begun implementing a higher-half kernel and can successfully boot into it. I boot into a routine which first enables paging and directly maps the first 4MB of code and stack into memory so then I can proceed with with my "kernel_init()" C method which will in turn initialize a proper memory manager and setup more robust paging.
That said, I am having issues actually getting to the point legitimately. When I boot into my kernel, grub starts at the correct place, but my eax register == 0 (before I execute anything). I am not exactly sure why. So everything works until my kernel_init() method checks for the correct magic number and then, obviously, it breaks down.
I should note that it seems directly related to the fact that my .text section begins above 0xc0010000. When I map this directly into the lower 1MB, I find no problems with the eax register. Let me know if you need more information, but I have shown the relevant sections of my kernel dump as well as the linker script.
Code: Select all
SECTIONS
{
. = 0x00100000;
.lowermem :
{
*(.lowermem)
}
. += 0xc0000000; /* +3GB -- higher-half skipping mbh */
.text : AT(ADDR(.text) - 0xC0000000)
{
*(.text)
}
Code: Select all
00100000 <.lowermem>:
100000: 02 b0 ad 1b 03 00 add 0x31bad(%eax),%dh
100006: 00 00 add %al,(%eax)
100008: fb sti
100009: 4f dec %edi
10000a: 52 push %edx
10000b: e4 .byte 0xe4
Disassembly of section .text:
c010000c <_boot>:
c010000c: bc 00 b0 90 c0 mov $0xc090b000,%esp
c0100011: 81 ec 00 00 00 c0 sub $0xc0000000,%esp
c0100017: 89 e5 mov %esp,%ebp
c0100019: 50 push %eax
c010001a: 8d 0d 78 01 10 c0 lea 0xc0100178,%ecx
c0100020: 81 e9 00 00 00 c0 sub $0xc0000000,%ecx
c0100026: ff d1 call *%ecx
c0100028: 58 pop %eax
c0100029: 8d 0d 31 00 10 c0 lea 0xc0100031,%ecx
c010002f: ff e1 jmp *%ecx
Code: Select all
.globl boot
.set boot, (_boot - 0xc0000000)
-RageD
EDIT: I should be clearer: I can execute code and access relevant portions of the stack at address 0xc0000000. I have manually setup the relevant page directory and page table entries to do this and it works properly. The problem is that the state of the machine is not what I expect when grub hands off execution to my code.