I tried to separate the architecture code from the kernel, for example gdt idt IRQs ... are part of the architecture, while the rest of the code that runs it is kernel
Using grub as bootloader loads the module named rom_mngr.sys (arch part / gdt, idt, IRQs ...) to an address. The kernel looks for the structure of the address modules (rom_mngr) and calls him, but something goes wrong (triple fault when loading the gdt and isr ... And not printing text KPRINTF). It all works if it stays in the kernel (without being called from the address)
The system '32bit binary format, I often have alignment issues with binary format (sometimes adding some "null printf" it all works )
I remember that all works in kernel (without dynamic memory load [arch code / rom_mngr]
Public part of the code and ask you for help
main.c ( KERNEL )
Code: Select all
#define MAX_MODULES 16
int kmain(unsigned int magic, multiboot_info_t *mbinfo)
{
if (magic != MULTIBOOT_BOOTLOADER_MAGIC)
{
//panic("invalid multiboot magic\n");
return 1;
}
multiboot_module_t modules[MAX_MODULES]; // Create array for modules loaded from grub
for (unsigned int i = 0; i < mbinfo->mods_count; i++)
{
if ( i < MAX_MODULES)
{
multiboot_module_t* module = (multiboot_module_t*) (mbinfo->mods_addr + sizeof(multiboot_module_t) * i);
modules[i].cmdline = module->cmdline;
modules[i].mod_start = module->mod_start;
modules[i].mod_end = module->mod_end;
rom_mngr_module = 0; // static (in my code is dynamic)
.....
} else {
.....
}
.....
int (*myfunc)(unsigned , unsigned);
myfunc = ( int (*)(unsigned , unsigned) ) modules[rom_mngr_module].mod_start; // pointer to ROM MANAGER function
int ss = myfunc(mbinfo->mem_upper + mbinfo->mem_lower, modules[(mbinfo->mods_count)-1].mod_end); // and call
kprintf("ss:%d", ss); // for return testing
.....
}
Code: Select all
int rom_main(unsigned memSize, unsigned endKernelAddress)
{
char *str = "It\'s OK", *ch; // print only first char
unsigned short *vidmem = (unsigned short*) 0xb8000;
unsigned i;
for (ch = str, i = 0; *ch; ch++, i++)
vidmem[i] = (unsigned char) *ch | 0x0700;
kprint("print text for testing"); // Not work
init_gdt();
init_idt();
return 55; // test for return to main it work
}
Code: Select all
Triple fault
CPU Reset (CPU 0)
EAX=000000e6 EBX=0000000e ECX=00000000 EDX=00000000
ESI=00000001 EDI=00103f0e EBP=00103f16 ESP=00103e36
EIP=000000e5 EFL=00000007 [-----PC] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
CS =0008 00000000 ffffffff 00cf9a00 DPL=0 CS32 [-R-]
SS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
DS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
FS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
GS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT= 00004040 00000027
IDT= 00000000 000003ff
CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=00000000 DR1=00000000 DR2=00000000 DR3=00000000
DR6=ffff0ff0 DR7=00000400
CCS=00000001 CCD=005343de CCO=INCL
EFER=0000000000000000
FCW=037f FSW=0000 [ST=0] FTW=00 MXCSR=00001f80
FPR0=0000000000000000 0000 FPR1=0000000000000000 0000
FPR2=0000000000000000 0000 FPR3=0000000000000000 0000
FPR4=0000000000000000 0000 FPR5=0000000000000000 0000
FPR6=0000000000000000 0000 FPR7=0000000000000000 0000
XMM00=00000000000000000000000000000000 XMM01=00000000000000000000000000000000
XMM02=00000000000000000000000000000000 XMM03=00000000000000000000000000000000
XMM04=00000000000000000000000000000000 XMM05=00000000000000000000000000000000
XMM06=00000000000000000000000000000000 XMM07=00000000000000000000000000000000
menu.lst
Code: Select all
title SkyLine (fd0)
root (fd0)
kernel /kernel32.sys
module /rom_mngr.sys
boot