This piece of updated code is more, so it is not convenient to all posted out ... Specific code everyone directly into the group to find it (OS0.3)
In addition, I configured the Bochs virtual machine, so that everyone can be downloaded to use the Bochs virtual machine directly debugging.
Now I'll just post the main code,,,,,,
Setupasm. S (here, jump to C function direct call on it)
Start32:
# Segment Register for each segment in initialize protected mode
MOVW $PROT _mode_dseg,%ax
movw %ax,%ds
movw %ax,%es
MOVW %ax,%fs
movw %ax,%gs
movw %ax,%ss
movl $start,%esp # Before the code was useless, Let's get the stack covered.
# here to jump to the C language program call setupmain
# OK, go here to Die Loop, the next section, C language, so it looks much simpler # in
fact, I think, or this simple
1:
hlt
JMP 1b
SETUPMAIN.C (here directly paste the code of the redirect Elf file, before the PE format, and then looked at the next, PE redirection length is relatively large, so it is directly using the ELF. )
Initialize kernel load address
elf = (struct elfhdr*) 0x10000;
Loaded into kernel
readseg (UINT) elf, sectsize*8, kernel_disk_offset);
Determine if the kernel is an elf file format
if (elf->magic! = elf_magic)
goto bad;
Redirect to elf file
ph = (struct proghdr*) ((uchar*) elf + elf->phoff);
Eph = ph + elf->phnum;
for (; ph < Eph; ph++)
readseg (Ph->va & 0xFFFFFF, Ph->memsz, Ph->offset + kernel_disk_offset); Here is to add the offset, using Winhex to see the ELF header format, can be specific analysis out
//Get the kernel entry point, and jump into the kernel
entry = (void (*) (void)) (Elf->entry & 0xFFFFFF );
Entry (); Jumping into the kernel portal
MAIN.C (here, simply write, to test the setup load kernel is correct, implement the printf function, so it is more convenient to write later)
/**
* Kernel entry
*
/int Kmain ()
{
//here, just display a message, simply
printf ("In the kernel code\n");
In fact, this is not allowed to return.
///But that's it, see if it goes back there's no error return
0;
}
Here's a screenshot of the run ... Feel the map, see more people, so strange
OK, that's all, don't understand the group to ask it [QQ qun:545250960].