Update of /cvsroot/trion/trion v0.2/loader In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv2298 Modified Files: console.cpp console.hpp entry.asm heap_manager.cpp heap_manager.hpp main.cpp mp_detect.cpp mp_detect.hpp Removed Files: pmode.asm Log Message: no message Index: main.cpp =================================================================== RCS file: /cvsroot/trion/trion v0.2/loader/main.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** main.cpp 2 Jun 2006 21:11:21 -0000 1.18 --- main.cpp 24 Jun 2006 15:01:32 -0000 1.19 *************** *** 38,71 **** // ----------------------------------------------------------------------- ! #include "../object/std_types.hpp" ! #include "console.hpp" ! ! #include "heap_manager.hpp" ! #include "mp_detect.hpp" ! ! #include "../hal/hal_object.hpp" ! #include "../hal/cpu_info.hpp" ! #include "../hal/mmu.hpp" ! #include "../hal/idt.hpp" ! #include "../hal/exception.hpp" ! #include "../hal/apic_local.hpp" ! #include "../hal/timer.hpp" ! #include "../hal/irq.hpp" ! #include "../hal/ipi.hpp" ! #include "../hal/systemcall.hpp" ! #include "../hal/task_context.hpp" ! hal_object* boot_hal; ! extern "C" void user_main() { ! asm("mov %ss, %eax\n" ! "mov %eax, %ds\n" ! "mov %eax, %es\n" ! "mov %eax, %fs\n" ! "mov %eax, %gs\n" ! ); // Print a red 'A' in the upper-left corner of the screen --- 38,66 ---- // ----------------------------------------------------------------------- ! #include <std_types.hpp> ! #include <console.hpp> ! #include <heap_manager.hpp> ! #include <mp_detect.hpp> ! #include <hal_object.hpp> ! #include <mmu.hpp> ! #include <idt.hpp> ! #include <exception.hpp> ! #include <apic_local.hpp> ! #include <timer.hpp> ! #include <irq.hpp> ! #include <ipi.hpp> ! #include <cpu_info.hpp> ! #include <gdt.hpp> ! #include <ports.hpp> ! #include <systemcall.hpp> ! #include <task_context.hpp> ! extern "C" u32b user_main() { ! asm("mov %ss, %eax\n" "mov %eax, %ds\n" "mov %eax, %es\n" ! "mov %eax, %fs\n" "mov %eax, %gs\n"); // Print a red 'A' in the upper-left corner of the screen *************** *** 85,94 **** vidmem[(160+78)*2 + 1] = 4; ! while(true); // Wait for IRQs } ! extern "C" int main(uint image_size, uint processor, uint magic, void* grub) { ! uint number_processors; if(processor == 0) --- 80,96 ---- vidmem[(160+78)*2 + 1] = 4; ! // Try accessing some I/O ports by moving the x86 hardware cursor ! asm("mov $0x0f, %al\n" "mov $0x3d4, %dx\n" "out %al, %dx\n"); ! asm("mov $0x9e, %al\n" "mov $0x3d5, %dx\n" "out %al, %dx\n"); ! ! asm("mov $0x0e, %al\n" "mov $0x3d4, %dx\n" "out %al, %dx\n"); ! asm("mov $0x00, %al\n" "mov $0x3d5, %dx\n" "out %al, %dx\n"); ! ! while(true); // Waiting for IRQs } ! extern "C" int main(u32b image_size, u32b processor, u32b magic, void* grub) { ! static u32b number_processors; if(processor == 0) *************** *** 96,106 **** number_processors = 1; ! // Create the global heap-manager class object ! new (heap_manager_reserved) heap_manager(); ! new (cpu_info_reserved) cpu_info(); ! // Spawn an instance of the mmu class ! hal_object* hal = boot_hal = heap().CreateHalObject(processor); ! hal->memory = new (heap().AllocateMemory(sizeof(mmu))) mmu(0xE0000000 + image_size); // Create a console object to be able to print debug messages --- 98,112 ---- number_processors = 1; ! // Create the global heap-manager object ! new (virt_allocator_reserved) memory_stack(0xE0000000 + image_size + 0x2000); ! new (phys_allocator_reserved) memory_stack(0x00100000 + image_size + 0x5000); ! new (heap_manager_reserved) heap_manager(0xE0000000 + image_size + 0x1000); ! // Create a new hal-object instance ! heap().CreateHalObject(processor); ! hal_object& hal = get_hal_object(); ! ! // Spawn an instance of the memory-mapper class ! hal.set_memory(heap().CreateObject<memory_mapper>(0x00100000 + image_size)); // Create a console object to be able to print debug messages *************** *** 111,132 **** // Enable the IDT and activate exception handling ! hal->vector = new (heap().AllocateMemory(sizeof(idt))) idt(); ! hal->faults = new (heap().AllocateMemory(sizeof(exception))) exception(); // Initialize the local APIC and enable all I/O APICs mp_detect* multi = new (mp_detect_reserved) mp_detect(); ! hal->lapic = new (heap().AllocateMemory(sizeof(local_apic))) local_apic(); ! hal->clock = new (heap().AllocateMemory(sizeof(timer))) timer(); ! hal->inter = new (heap().AllocateMemory(sizeof(ipi))) ipi(); new (irq_logic_reserved) irq_logic(); // Prepare everything for user-mode ! hal->context = new (heap().AllocateMemory(sizeof(task_context))) task_context(); ! hal->syscall = new (heap().AllocateMemory(sizeof(systemcall))) systemcall(); // Enable hyperthreading and try to boot all application processors ! number_processors += multi->EnableHyperthreading(); ! number_processors += multi->BootAllProcessors(); cout() << endl << "All " << number_processors << " processors have been booted" << endl; --- 117,142 ---- // Enable the IDT and activate exception handling ! hal.set_idt(heap().CreateObject<idt_table>()); ! hal.set_exceptions(heap().CreateObject<exception>()); // Initialize the local APIC and enable all I/O APICs mp_detect* multi = new (mp_detect_reserved) mp_detect(); ! ! hal.set_info(heap().CreateObject<cpu_info>()); ! hal.set_lapic(heap().CreateObject<local_apic>()); ! hal.set_timer(heap().CreateObject<apic_timer>()); ! hal.set_ipi(heap().CreateObject<cpu_messages>()); new (irq_logic_reserved) irq_logic(); // Prepare everything for user-mode ! hal.set_gdt(heap().CreateObject<gdt_table>()); ! hal.set_context(heap().CreateObject<task_context>()); ! hal.set_syscall(heap().CreateObject<systemcall>()); ! hal.set_port(heap().CreateObject<port_protect>()); // Enable hyperthreading and try to boot all application processors ! multi->EnableHyperthreading(); ! multi->BootAllProcessors(); cout() << endl << "All " << number_processors << " processors have been booted" << endl; *************** *** 136,171 **** // Install a small user-task for testing purposes ! hal->memory->CreatePageTable(0x00000000, 0x8000, mmu::USER_MODE | mmu::READ_WRITE); ! hal->memory->MapPage((void*)0x00000000, 0x100000, mmu::USER_MODE | mmu::READ_WRITE); // user-mode code ! hal->memory->MapPage((void*)0x00001000, 0x10000, mmu::USER_MODE | mmu::READ_WRITE); // stack space ! hal->memory->MapPage((void*)0x00002000, 0xB8000, mmu::USER_MODE | mmu::READ_WRITE); // video memory ! uint task_entry = (uint)&user_main - 0xE0000000; // Switch to the user-mode code ! hal->syscall->InvokeUserTask(task_entry, 0x2000); } else { ap_flag |= 1; // Indicates that the processor has been booted ! cout() << "An application processor was booted (# "<< processor << ")" << endl; // Spawn an instance of all hal classes.. ! hal_object* hal = boot_hal = heap().CreateHalObject(processor); ! hal->memory = new (heap().AllocateMemory(sizeof(mmu))) mmu(0xE0000000 + image_size); ! hal->vector = new (heap().AllocateMemory(sizeof(idt))) idt(); ! hal->faults = new (heap().AllocateMemory(sizeof(exception))) exception(); ! hal->lapic = new (heap().AllocateMemory(sizeof(local_apic))) local_apic(); ! hal->clock = new (heap().AllocateMemory(sizeof(timer))) timer(); ! hal->inter = new (heap().AllocateMemory(sizeof(ipi))) ipi(); ! number_processors += multiprocessor().EnableHyperthreading(); ap_flag |= 2; // Indicates that the hal is fully initialized, next AP may get started - asm("sti"); while(true) asm("hlt"); } --- 146,191 ---- // Install a small user-task for testing purposes ! hal(memory)[0] = memory_mapper::user_mode(0x8000); // Create a new page-table ! hal(memory)[0][0] = memory_mapper::user_mode(0x100000); // User Code ! hal(memory)[0][1] = memory_mapper::user_mode(0x10000); // Stack Space ! hal(memory)[0][2] = memory_mapper::user_mode(0xB8000); // Video Memory ! u32b task_entry = (u32b)&user_main - 0xE0000000; ! ! // Create a port bitmap for the task and enable the required ports ! hal(port).EnablePort<u08b>(0x3d4); ! hal(port).EnablePort<u08b>(0x3d5); ! ! hal(context).SetPortMap(hal(port).GetPortMap()); // Switch to the user-mode code ! hal(syscall).InvokeUserTask(task_entry, 0x2000); } else { ap_flag |= 1; // Indicates that the processor has been booted ! ! number_processors++; // Spawn an instance of all hal classes.. ! heap().CreateHalObject(processor); ! hal_object& hal = get_hal_object(); ! hal.set_memory(heap().CreateObject<memory_mapper>(0x00100000 + image_size)); ! hal.set_idt(heap().CreateObject<idt_table>()); ! hal.set_exceptions(heap().CreateObject<exception>()); ! hal.set_lapic(heap().CreateObject<local_apic>()); ! hal.set_timer(heap().CreateObject<apic_timer>()); ! hal.set_ipi(heap().CreateObject<cpu_messages>()); ! hal.set_gdt(heap().CreateObject<gdt_table>()); ! hal.set_context(heap().CreateObject<task_context>()); ! hal.set_syscall(heap().CreateObject<systemcall>()); ! hal.set_port(heap().CreateObject<port_protect>()); ap_flag |= 2; // Indicates that the hal is fully initialized, next AP may get started while(true) asm("hlt"); } --- pmode.asm DELETED --- Index: mp_detect.hpp =================================================================== RCS file: /cvsroot/trion/trion v0.2/loader/mp_detect.hpp,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** mp_detect.hpp 22 May 2006 15:19:08 -0000 1.10 --- mp_detect.hpp 24 Jun 2006 15:01:32 -0000 1.11 *************** *** 41,56 **** #define __LOADER__MP_DETECT__ ! #include "../object/std_types.hpp" ! #include "../hal/hal_object.hpp" ! #include "heap_manager.hpp" struct SmpFloatingPointer { ! unsigned long Magic; ! unsigned long Table; ! unsigned char Length; ! unsigned char Version; ! unsigned char Checksum; ! unsigned char Feature[5]; }__attribute__ ((__packed__)); --- 41,56 ---- #define __LOADER__MP_DETECT__ ! #include <std_types.hpp> ! #include <heap_manager.hpp> ! #include <hal_object.hpp> struct SmpFloatingPointer { ! u32b Magic; ! u32b Table; ! u08b Length; ! u08b Version; ! u08b Checksum; ! u08b Feature[5]; }__attribute__ ((__packed__)); *************** *** 58,74 **** struct SmpConfigTable { ! unsigned long Magic; ! unsigned short BaseLength; ! unsigned char Version; ! unsigned char Checksum; ! unsigned char OemString[8]; ! unsigned char ProductString[12]; ! unsigned long OemTable; ! unsigned short OemLength; ! unsigned short EntryCount; ! unsigned long LocalApic; ! unsigned short ExtendedLength; ! unsigned char ExtendedChecksum; ! unsigned char Reserved; }__attribute__ ((__packed__)); --- 58,74 ---- struct SmpConfigTable { ! u32b Magic; ! u16b BaseLength; ! u08b Version; ! u08b Checksum; ! u08b OemString[8]; ! u08b ProductString[12]; ! u32b OemTable; ! u16b OemLength; ! u16b EntryCount; ! u32b LocalApic; ! u16b ExtendedLength; ! u08b ExtendedChecksum; ! u08b Reserved; }__attribute__ ((__packed__)); *************** *** 76,80 **** struct SmpConfigEntry { ! unsigned char Type; }__attribute__((__packed__)); --- 76,80 ---- struct SmpConfigEntry { ! u08b Type; }__attribute__((__packed__)); *************** *** 82,91 **** struct SmpConfigCPU : SmpConfigEntry { ! unsigned char LocalApicID; ! unsigned char LocalApicVersion; ! unsigned char Flags; ! unsigned long Signature; ! unsigned long Features; ! unsigned long Reserved[2]; }__attribute__ ((packed)); --- 82,91 ---- struct SmpConfigCPU : SmpConfigEntry { ! u08b LocalApicID; ! u08b LocalApicVersion; ! u08b Flags; ! u32b Signature; ! u32b Features; ! u32b Reserved[2]; }__attribute__ ((packed)); *************** *** 93,98 **** struct SmpConfigBus : SmpConfigEntry { ! unsigned char BusID; ! unsigned char TypeString[6]; } __attribute__ ((packed)); --- 93,98 ---- struct SmpConfigBus : SmpConfigEntry { ! u08b BusID; ! char TypeString[6]; } __attribute__ ((packed)); *************** *** 100,107 **** struct SmpConfigIOApic : SmpConfigEntry { ! unsigned char ApicID; ! unsigned char ApicVersion; ! unsigned char Flags; ! unsigned long BaseAddr; }__attribute__ ((packed)); --- 100,107 ---- struct SmpConfigIOApic : SmpConfigEntry { ! u08b ApicID; ! u08b ApicVersion; ! u08b Flags; ! u32b BaseAddr; }__attribute__ ((packed)); *************** *** 109,118 **** struct SmpConfigInterrupt : SmpConfigEntry { ! unsigned char IntType; ! unsigned short Flags; ! unsigned char SourceID; ! unsigned char SourceIRQ; ! unsigned char DestID; ! unsigned char DestIRQ; }__attribute__ ((packed)); --- 109,118 ---- struct SmpConfigInterrupt : SmpConfigEntry { ! u08b IntType; ! u16b Flags; ! u08b SourceID; ! u08b SourceIRQ; ! u08b DestID; ! u08b DestIRQ; }__attribute__ ((packed)); *************** *** 132,136 **** private: ! uint entry, last_entry; SmpConfigEntry* address; --- 132,136 ---- private: ! u16b entry, last_entry; SmpConfigEntry* address; *************** *** 145,149 **** bool operator!=(iterator it); ! iterator operator++(int t); SmpConfigEntry* operator*(); --- 145,150 ---- bool operator!=(iterator it); ! iterator& operator++(); ! iterator operator++(int t); SmpConfigEntry* operator*(); *************** *** 154,168 **** private: SmpConfigEntry* config_table; ! uint entry_count, apic_address; vRange* window; ! void RelocateEntrypoint(uint relocation_address); ! uint GetCMOSValue(uint address); ! uint DetectFloatingPointer(uint start_address, uint length); bool CheckBootstrap(iterator cpu); bool CheckDisabled (iterator cpu); ! uint GetLocalApicID(iterator cpu); public: --- 155,170 ---- private: SmpConfigEntry* config_table; ! u32b entry_count, apic_address; vRange* window; ! void RelocateEntrypoint(u32b relocation_address); ! u16b GetCMOSValue(u32b address); ! ! u32b DetectFloatingPointer(u32b start_address, u32b length); bool CheckBootstrap(iterator cpu); bool CheckDisabled (iterator cpu); ! u08b GetLocalApicID(iterator cpu); public: *************** *** 173,182 **** iterator end(); - uint GetNumberEntries(entry_type type); - bool BootProcessor(iterator cpu); - uint BootAllProcessors(); ! uint EnableHyperthreading(); }; --- 175,184 ---- iterator end(); bool BootProcessor(iterator cpu); ! u08b BootAllProcessors(); ! u08b EnableHyperthreading(); ! ! u08b GetNumberEntries(entry_type type); }; *************** *** 184,188 **** mp_detect& multiprocessor(); ! extern volatile uint ap_flag; #endif --- 186,190 ---- mp_detect& multiprocessor(); ! extern volatile u32b ap_flag; #endif Index: mp_detect.cpp =================================================================== RCS file: /cvsroot/trion/trion v0.2/loader/mp_detect.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** mp_detect.cpp 22 May 2006 15:19:08 -0000 1.12 --- mp_detect.cpp 24 Jun 2006 15:01:32 -0000 1.13 *************** *** 38,59 **** // ----------------------------------------------------------------------- ! #include "mp_detect.hpp" ! #include "console.hpp" ! #include "../hal/timer.hpp" ! #include "../hal/ipi.hpp" ! #include "../hal/cpu_info.hpp" ! extern "C" unsigned char ap_code_start[]; ! extern "C" unsigned char ap_code_end[]; ! volatile uint ap_flag; mp_detect::mp_detect() { // Get possible locations of the multiprocessor floating pointer from the CMOS ! uint ebda = GetCMOSValue(0x40E) << 4; ! uint lastK = GetCMOSValue(0x413) << 10; ! uint bios = 0x000F0000; // Relocate the entrypoint to a lower address so that it can be reached from real-mode --- 38,60 ---- // ----------------------------------------------------------------------- ! #include <mp_detect.hpp> ! #include <console.hpp> ! #include <hal_object.hpp> ! #include <cpu_info.hpp> ! #include <timer.hpp> ! #include <ipi.hpp> ! extern "C" u32b ap_code_start[]; ! extern "C" u32b ap_code_end[]; ! volatile u32b ap_flag; mp_detect::mp_detect() { // Get possible locations of the multiprocessor floating pointer from the CMOS ! u32b ebda = GetCMOSValue(0x40E) << 4; ! u32b lastK = GetCMOSValue(0x413) << 10; ! u32b bios = 0x000F0000; // Relocate the entrypoint to a lower address so that it can be reached from real-mode *************** *** 61,66 **** // Search for the multiprocessor floating pointer ! uint table(0); ! uint address = (ebda) ? ebda : lastK; table = DetectFloatingPointer(address, 0x400); --- 62,67 ---- // Search for the multiprocessor floating pointer ! u32b table(0); ! u32b address = (ebda) ? ebda : lastK; table = DetectFloatingPointer(address, 0x400); *************** *** 69,73 **** if(table && !config_table) { ! cout() << "Standard multiprocessor configuration " << reinterpret_cast<uint>(table) << endl; cout() << " will be used" << endl << endl; --- 70,74 ---- if(table && !config_table) { ! cout() << "Standard multiprocessor configuration " << reinterpret_cast<u32b>(table) << endl; cout() << " will be used" << endl << endl; *************** *** 79,92 **** { cout() << "A multiprocessor configuration table was detected "; ! cout() << "at address " << reinterpret_cast<uint>(table) << endl << endl; ! uint table_base = reinterpret_cast<uint>(table) &0xFFFFF000; ! uint table_offset = reinterpret_cast<uint>(table) &0x00000FFF; ! // Map the configuration table statically in ! window = new (heap().AllocateMemory(sizeof(vRange))) vRange(table_base); ! uint virt_address = reinterpret_cast<uint>(window->GetVirtualBase()); ! // Gather the neccessary information from the config table SmpConfigTable* vtable = reinterpret_cast<SmpConfigTable*>(virt_address + table_offset); entry_count = vtable->EntryCount; --- 80,93 ---- { cout() << "A multiprocessor configuration table was detected "; ! cout() << "at address " << reinterpret_cast<u32b>(table) << endl << endl; ! u32b table_base = reinterpret_cast<u32b>(table) &0xFFFFF000; ! u32b table_offset = reinterpret_cast<u32b>(table) &0x00000FFF; ! // Map the configuration table statically ! window = heap().CreateObject<vRange>(table_base); ! u32b virt_address = reinterpret_cast<u32b>(window->GetVirtualBase()); ! // Gather the neccessary information from the configuration table SmpConfigTable* vtable = reinterpret_cast<SmpConfigTable*>(virt_address + table_offset); entry_count = vtable->EntryCount; *************** *** 109,162 **** } ! void mp_detect::RelocateEntrypoint(uint relocation_address) { vRange virt_range(relocation_address); ! uint virt_address = reinterpret_cast<uint>(virt_range.GetVirtualBase()); ! for(uint i = 0; i < (uint)ap_code_end - (uint)ap_code_start; i++) ! ((uchar*)virt_address)[i] = ap_code_start[i]; } ! uint mp_detect::GetCMOSValue(uint address) { vRange virt_range(0); ! uint virt_address = reinterpret_cast<uint>(virt_range.GetVirtualBase()); ! return *(reinterpret_cast<ushort*>(virt_address + address)); } ! uint mp_detect::DetectFloatingPointer(uint start_address, uint length) { ! uint pbase = start_address &0xFFFFF000; ! uint offset = start_address &0xFFF; ! uint pages = (length + offset + 0xFFF)/4096; ! for(uint i=0; i<pages; i++) { vRange virt_range(pbase + i*4096); ! ulong* vpage = static_cast<ulong*>(virt_range.GetVirtualBase()); ! for(int j=0; j<1024; j+=4) { ! if(vpage[j] == '_PM_') { // Calculate the checksume of the structure ! uchar checksum = 0x00000000; ! uchar* mp_float = reinterpret_cast<uchar*>(&vpage[j]); ! for(int k=0; k<16; k++) checksum += mp_float[k]; if(checksum == 0) { ! if(vpage[j+1]) // Return a pointer to the configuration table if available { ! config_table = reinterpret_cast<SmpConfigEntry*>(vpage[j+1]); ! return vpage[j+1]; } ! else // Return the number of the standard configuration used { config_table = 0; ! return vpage[j+3] &0xFF; } } --- 110,168 ---- } ! void mp_detect::RelocateEntrypoint(u32b relocation_address) { vRange virt_range(relocation_address); ! u32b* virt_address = static_cast<u32b*>(virt_range.GetVirtualBase()); ! u16b length = reinterpret_cast<u32b>(ap_code_end) - reinterpret_cast<u32b>(ap_code_start); ! memcopy(ap_code_start, &ap_code_start[length], virt_address); } ! u16b mp_detect::GetCMOSValue(u32b address) { vRange virt_range(0); ! u32b virt_address = reinterpret_cast<u32b>(virt_range.GetVirtualBase()); ! return *reinterpret_cast<u16b*>(virt_address + address); } ! u32b mp_detect::DetectFloatingPointer(u32b start_address, u32b length) { ! u32b pbase = start_address &0xFFFFF000; ! u32b offset = start_address &0xFFF; ! u16b pages = (length + offset + 0xFFF)/4096; ! ! for(u16b i=0; i<pages; i++) { vRange virt_range(pbase + i*4096); ! u32b* vpage = static_cast<u32b*>(virt_range.GetVirtualBase()); ! for(u16b j=0; j<1024; j+=4) { ! SmpFloatingPointer* fp = reinterpret_cast<SmpFloatingPointer*>(&vpage[j]); ! ! if(fp->Magic == '_PM_') { // Calculate the checksume of the structure ! u08b checksum = 0x00; ! u08b* mp_float = reinterpret_cast<u08b*>(fp); ! for(u08b k=0; k<16; k++) checksum += mp_float[k]; if(checksum == 0) { ! if(fp->Table) { ! // Return a pointer to the configuration table if available ! config_table = reinterpret_cast<SmpConfigEntry*>(fp->Table); ! return fp->Table; } ! else { + // Return the number of the standard configuration used config_table = 0; ! return fp->Feature[0]; } } *************** *** 174,178 **** iterator it; it.address = config_table; ! it.entry = 0; it.last_entry = entry_count - 1; --- 180,184 ---- iterator it; it.address = config_table; ! it.entry = 0; it.last_entry = entry_count - 1; *************** *** 199,210 **** } ! uint mp_detect::GetNumberEntries(entry_type type) { ! uint counter = 0; ! ! for(iterator it = begin(type); it != end(); it++) ! { ! counter++; ! } return counter; } --- 205,212 ---- } ! u08b mp_detect::GetNumberEntries(entry_type type) { ! u08b counter = 0; ! for(iterator it = begin(type); it != end(); ++it) counter++; return counter; } *************** *** 220,224 **** } ! uint mp_detect::GetLocalApicID(iterator cpu) { return (static_cast<SmpConfigCPU*>(*cpu)->LocalApicID); --- 222,226 ---- } ! u08b mp_detect::GetLocalApicID(iterator cpu) { return (static_cast<SmpConfigCPU*>(*cpu)->LocalApicID); *************** *** 227,243 **** bool mp_detect::BootProcessor(iterator cpu) { ! heap().AllocateApStack(); ap_flag = 0; ! uint apic_id = GetLocalApicID(cpu); ! boot_hal->inter->SendInitIPI (apic_id); ! boot_hal->inter->SendStartupIPI(apic_id); ! boot_hal->inter->SendStartupIPI(apic_id); ! boot_hal->clock->SetTimer(timer_id(current), 0x1000000); // Check if the processor responds - if so, wait until it finished booting ! while(boot_hal->clock->GetTimer(timer_id(current)) > 0 && !(ap_flag &1)); while(ap_flag &1 && !(ap_flag &2)); --- 229,247 ---- bool mp_detect::BootProcessor(iterator cpu) { ! heap().AllocateMpStack(); ap_flag = 0; ! hal_object& hal = get_hal_object(); ! u08b apic_id = GetLocalApicID(cpu); ! // Start the INIT-SIPI-SIPI sequence ! hal(ipi).SendInitIPI(apic_id); ! hal(ipi).SendStartupIPI(apic_id); ! // hal(ipi).SendStartupIPI(apic_id); NOTE Caused problems on bochs when AP halts immediately ! hal(timer).SetTimer(timer_id(current), 0x1000000); // Check if the processor responds - if so, wait until it finished booting ! while(hal(timer).GetTimer(timer_id(current)) > 0 && !(ap_flag &1)); while(ap_flag &1 && !(ap_flag &2)); *************** *** 245,269 **** } ! uint mp_detect::BootAllProcessors() { ! bool result = true; ! uint num_cpu = 0; ! for(iterator entry = begin(TYPE_CPU); entry != end(); entry++) { if(!CheckBootstrap(entry) && !CheckDisabled(entry)) { ! result &= BootProcessor(entry); num_cpu++; } } ! return (result) ? num_cpu : 0; } ! uint mp_detect::EnableHyperthreading() { ! uint processors = 0; ! if(info().GetProcessorInfo().hyper_threading) { // On hyperthreading CPUs the APIC ID is split into two parts: package ID and logical ID --- 249,272 ---- } ! u08b mp_detect::BootAllProcessors() { ! u08b num_cpu = 0; ! for(iterator entry = begin(TYPE_CPU); entry != end(); ++entry) { if(!CheckBootstrap(entry) && !CheckDisabled(entry)) { ! BootProcessor(entry); num_cpu++; } } ! return num_cpu; } ! u08b mp_detect::EnableHyperthreading() { ! u08b processors = 0; ! if(get_hal_object()(info).GetProcessorInfo().hyper_threading) { // On hyperthreading CPUs the APIC ID is split into two parts: package ID and logical ID *************** *** 271,299 **** // the number of logical processors per physical package: log2(logical_per_package) // Get the number of logical processors per physical CPU ! uint number_logical = ((info().cpuid<cpu_info::EBX>(1) >> 16) &0xff); ! uint current_logical = boot_hal->lapic->GetPhysicalID() &(number_logical-1); if(current_logical++ == 0) // Primary CPU is always booted first { ! for(uint i = current_logical; i < number_logical; i++) { // Cyle through the logical processors and send an SIPI-SIPI_INIT sequence to each of them ! heap().AllocateApStack(); ap_flag = 0; ! uint apic_id = (boot_hal->lapic->GetPhysicalID() &(0xffffffff - (number_logical-1))) | i; ! boot_hal->inter->SendInitIPI (apic_id); ! boot_hal->inter->SendStartupIPI(apic_id); ! boot_hal->inter->SendStartupIPI(apic_id); ! boot_hal->clock->SetTimer(timer_id(current), 0x1000000); // Check if the processor responds - if so, wait until it finished booting ! while(boot_hal->clock->GetTimer(timer_id(current)) > 0 && !(ap_flag &1)); while(ap_flag &1 && !(ap_flag &2)); ! if(ap_flag) processors++; } } --- 274,305 ---- // the number of logical processors per physical package: log2(logical_per_package) + hal_object& hal = get_hal_object(); + // Get the number of logical processors per physical CPU ! u08b number_logical = ((get_hal_object()(info).cpuid<cpu_info::EBX>(1) >> 16) &0xff); ! u08b current_logical = hal(lapic).GetPhysicalID() &(number_logical-1); if(current_logical++ == 0) // Primary CPU is always booted first { ! for(u08b i=current_logical; i<number_logical; i++) { // Cyle through the logical processors and send an SIPI-SIPI_INIT sequence to each of them ! heap().AllocateMpStack(); ap_flag = 0; ! u08b apic_id = (hal(lapic).GetPhysicalID() &(0xffffffff - (number_logical-1))) | i; ! // Start the INIT-SIPI-SIPI sequence ! hal(ipi).SendInitIPI(apic_id); ! hal(ipi).SendStartupIPI(apic_id); ! // hal(ipi).SendStartupIPI(apic_id); NOTE Caused problems on bochs when AP halts immediately ! hal(timer).SetTimer(timer_id(current), 0x1000000); // Check if the processor responds - if so, wait until it finished booting ! while(hal(timer).GetTimer(timer_id(current)) > 0 && !(ap_flag &1)); while(ap_flag &1 && !(ap_flag &2)); ! processors++; } } *************** *** 310,315 **** iterator::iterator(const iterator& it) { ! address = it.address; ! entry = it.entry; last_entry = it.last_entry; } --- 316,321 ---- iterator::iterator(const iterator& it) { ! address = it.address; ! entry = it.entry; last_entry = it.last_entry; } *************** *** 318,332 **** { this->address = address; ! last_entry = entry = 0; } SmpConfigEntry* iterator::GetNext(SmpConfigEntry* current) { ! uchar* tmp = reinterpret_cast<uchar*>(current) + 8; ! ! if(current->Type == TYPE_CPU) ! { ! tmp += sizeof(SmpConfigCPU) - 8; ! } return reinterpret_cast<SmpConfigEntry*>(tmp); } --- 324,334 ---- { this->address = address; ! last_entry = entry = 0; } SmpConfigEntry* iterator::GetNext(SmpConfigEntry* current) { ! // CPU items are 20byte long, all others are 8bytes ! u08b* tmp = (current->Type == TYPE_CPU) ? (u08b*)current + 20 : (u08b*)current + 8; return reinterpret_cast<SmpConfigEntry*>(tmp); } *************** *** 334,348 **** bool iterator::operator==(iterator it) { ! return (entry == it.entry) ? true : false; } bool iterator::operator!=(iterator it) { ! return (entry != it.entry) ? true : false; } ! iterator iterator::operator++(int t) { ! uchar type = address->Type; while(entry <= last_entry) --- 336,350 ---- bool iterator::operator==(iterator it) { ! return entry == it.entry; } bool iterator::operator!=(iterator it) { ! return entry != it.entry; } ! iterator& iterator::operator++() { ! u08b type = address->Type; while(entry <= last_entry) *************** *** 357,360 **** --- 359,378 ---- } + iterator iterator::operator++(int t) + { + iterator temp = *this; + u08b type = address->Type; + + while(entry <= last_entry) + { + address = GetNext(address); + entry++; + + if(address->Type == type) + break; + } + return temp; + } + SmpConfigEntry* iterator::operator*() { Index: console.cpp =================================================================== RCS file: /cvsroot/trion/trion v0.2/loader/console.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** console.cpp 5 Apr 2006 17:12:56 -0000 1.9 --- console.cpp 24 Jun 2006 15:01:32 -0000 1.10 *************** *** 3,7 **** // // Author(s) : ! // Date : DD/MM/2006 // Version : 0.2.0 // Home Page : http://trion.sourceforge.net --- 3,7 ---- // // Author(s) : ! // Date : MM/DD/2006 // Version : 0.2.0 // Home Page : http://trion.sourceforge.net *************** *** 38,52 **** // ----------------------------------------------------------------------- ! #include "console.hpp" ! #include "../hal/hal_object.hpp" ! #include "heap_manager.hpp" ! #include "../hal/mmu.hpp" ! char console::itoa_buffer[] = {'0', 'x', 0, 0, 0, 0, 0, 0, 0, 0, 0}; const char endl = '\n'; console::console() { ! x86_console = reinterpret_cast<uchar*>(heap().CreatePhysicalWindow(0xB8000)); x_offset = y_offset = 0; } --- 38,51 ---- // ----------------------------------------------------------------------- ! #include <console.hpp> ! #include <hal_object.hpp> ! char console::itoa_buffer[] = {'0', 'x', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; const char endl = '\n'; console::console() { ! window = heap().CreateObject<vRange>(0xB8000); ! x86_console = static_cast<u08b*>(window->GetVirtualBase()); x_offset = y_offset = 0; } *************** *** 56,62 **** EnterMutex(); ! for(int i=0; i<80*50; i++) ! x86_console[i] = 0; ! x_offset = y_offset = 0; --- 55,59 ---- EnterMutex(); ! memset(x86_console, &x86_console[80*50], u08b(0)); x_offset = y_offset = 0; *************** *** 67,71 **** { EnterMutex(); ! int index = 0; while(true) --- 64,68 ---- { EnterMutex(); ! u16b index = 0; while(true) *************** *** 83,87 **** else { ! x86_console[y_offset*160+x_offset*2] = string[index]; x86_console[y_offset*160+x_offset*2+1] = 9; x_offset++; --- 80,84 ---- else { ! x86_console[y_offset*160+x_offset*2+0] = string[index]; x86_console[y_offset*160+x_offset*2+1] = 9; x_offset++; *************** *** 97,112 **** // End of line - next line ! x_offset=0; y_offset++; } // End of the screen - move up one line ! int source = 160; ! int dest = 0; ! while(dest < 160*24) ! x86_console[dest++] = x86_console[source++]; ! while(dest < 160*25) ! x86_console[dest++] = 0; x_offset = 0; --- 94,107 ---- // End of line - next line ! x_offset = 0; y_offset++; } // End of the screen - move up one line ! u16b source = 160; ! u16b dest = 0; ! while(dest < 160*24) x86_console[dest++] = x86_console[source++]; ! while(dest < 160*25) x86_console[dest++] = 0; x_offset = 0; *************** *** 118,127 **** } ! console& console::operator<<(uint number) { EnterMutex(); ! int base = 16; ! for(int index = sizeof(itoa_buffer)-2; index > 1; index--) { char digit = number%base; --- 113,122 ---- } ! console& console::operator<<(u32b number) { EnterMutex(); ! u08b base = 16; ! for(u08b index = sizeof(itoa_buffer)-3; index > 1; index--) { char digit = number%base; *************** *** 138,144 **** console& console::operator<<(char character) { ! short buffer = character; ! operator<<(reinterpret_cast<const char*>(&buffer)); ! return *this; } --- 133,138 ---- console& console::operator<<(char character) { ! char dummy[] = { character , 0}; ! operator<<(dummy); return *this; } Index: console.hpp =================================================================== RCS file: /cvsroot/trion/trion v0.2/loader/console.hpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** console.hpp 5 Apr 2006 17:12:56 -0000 1.7 --- console.hpp 24 Jun 2006 15:01:32 -0000 1.8 *************** *** 41,55 **** #define __LOADER__CONSOLE__ ! #include "../object/std_types.hpp" ! #include "../hal/mutex.hpp" ! class console : mutex { private: ! uchar* x86_console; ! uchar x_offset; ! uchar y_offset; ! static char itoa_buffer[11]; public: --- 41,57 ---- #define __LOADER__CONSOLE__ ! #include <std_types.hpp> ! #include <heap_manager.hpp> ! #include <mutex.hpp> ! class console : private mutex { private: ! u08b x_offset, y_offset; ! u08b* x86_console; ! vRange* window; ! ! static char itoa_buffer[12]; public: *************** *** 60,64 **** console& operator<<(const char* string); console& operator<<(char character); ! console& operator<<(uint number); }; --- 62,66 ---- console& operator<<(const char* string); console& operator<<(char character); ! console& operator<<(u32b number); }; Index: heap_manager.hpp =================================================================== RCS file: /cvsroot/trion/trion v0.2/loader/heap_manager.hpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** heap_manager.hpp 2 Jun 2006 21:11:21 -0000 1.8 --- heap_manager.hpp 24 Jun 2006 15:01:32 -0000 1.9 *************** *** 41,85 **** #define __LOADER__HEAP_MANAGER__ ! #include "../object/std_types.hpp" ! #include "../hal/hal_object.hpp" ! extern "C" uint heap_address; class vRange { private: ! void* page_base; ! uint page_size; public: ! vRange(uint physical_base, uint number_pages = 1); ~vRange(); void* GetVirtualBase(); ! uint GetLength(); }; class heap_manager { - friend class vRange; - private: ! uint memory_base, memory_offset, memory_size; ! uint vspace_base, vspace_offset, vspace_size; ! uint vrange_base, pageframe; ! void* AllocateVirtualSpace(uint number_pages); ! void DelocateVirtualSpace(void* address, uint number_pages); public: ! heap_manager(); ! ~heap_manager(); ! void AllocateApStack(); ! hal_object* CreateHalObject(uint processor_number); ! void* AllocateMemory(uint size_bytes); ! void* CreatePhysicalWindow(uint physical_base, uint number_pages = 1); }; --- 41,97 ---- #define __LOADER__HEAP_MANAGER__ ! #include <std_types.hpp> ! #include <hal_object.hpp> ! extern "C" u32b heap_address; ! extern "C" u32b sizeof_hobject_cpp; ! ! class memory_stack ! { ! private: ! u32b stack[32]; ! u16b stack_pointer, stack_underflow; ! ! public: ! memory_stack(u32b heap_begin); ! ! u32b AllocatePage(); ! void DelocatePage(u32b base_address); ! }; class vRange { private: ! u32b page_base, page_size; public: ! vRange(u32b physical_base); ~vRange(); void* GetVirtualBase(); ! u32b GetLength(); }; class heap_manager { private: ! u32b memory_base, memory_left; ! u32b GetStackBase(); ! void RefreshWindow(); public: ! heap_manager(u32b initial_heap); ! void* AllocateMemory(u32b size_bytes); ! void AllocateMpStack(); ! template<class T, class P> T* heap_manager::CreateObject(P parameter) ! { return reinterpret_cast<T*>(new (AllocateMemory(sizeof(T))) T(parameter)); } ! template<class T> T* heap_manager::CreateObject() ! { return reinterpret_cast<T*>(new (AllocateMemory(sizeof(T))) T()); } ! ! hal_object* CreateHalObject(u08b processor); }; *************** *** 87,89 **** --- 99,107 ---- heap_manager& heap(); + extern char virt_allocator_reserved[]; + extern char phys_allocator_reserved[]; + + memory_stack& virtual_allocator(); + memory_stack& physical_allocator(); + #endif Index: heap_manager.cpp =================================================================== RCS file: /cvsroot/trion/trion v0.2/loader/heap_manager.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** heap_manager.cpp 2 Jun 2006 21:11:21 -0000 1.11 --- heap_manager.cpp 24 Jun 2006 15:01:32 -0000 1.12 *************** *** 38,219 **** // ----------------------------------------------------------------------- ! #include "heap_manager.hpp" ! #include "../hal/mmu.hpp" ! #include "console.hpp" ! vRange::vRange(uint physical_base, uint number_pages) { ! page_base = heap().AllocateVirtualSpace(number_pages); ! page_size = number_pages; ! for(uint i=0; i<page_size; i++) ! { ! uint current_page = reinterpret_cast<uint>(page_base) + i*1024; ! boot_hal->memory->MapPage(reinterpret_cast<void*>(current_page), physical_base + i*4096); ! } } ! vRange::~vRange() { ! for(uint i=0; i<page_size; i++) { ! uint current_page = reinterpret_cast<uint>(page_base) + i*1024; ! boot_hal->memory->UmapPage(reinterpret_cast<void*>(current_page)); } ! heap().DelocateVirtualSpace(page_base, page_size); } ! void* vRange::GetVirtualBase() { ! return page_base; } ! uint vRange::GetLength() { ! return page_size*4096; } ! heap_manager::heap_manager() { ! pageframe = heap_address + 4096; ! ! memory_base = heap_address + 0xDFF00000 - 12288; ! memory_offset = 0; ! memory_size = 4096; ! ! vspace_base = vspace_size = vspace_offset = 0; ! vrange_base = 0xE0000000 + 4096*1024; } ! heap_manager::~heap_manager() { ! // TODO - Pass control to the object allocator } ! void heap_manager::AllocateApStack() // Has to be called for each AP to update the ASM heap-pointer { ! heap_address = reinterpret_cast<uint>(CreatePhysicalWindow(0x00000000)) + 4096; ! boot_hal->memory->MapPage(reinterpret_cast<void*>(heap_address), pageframe); ! ! pageframe += 4192; } ! hal_object* heap_manager::CreateHalObject(uint processor_number) { ! uchar* hal_reserved = static_cast<uchar*>(AllocateMemory(sizeof(hal_object))); ! ! // Initialize the hal-object structure with all zeroes ! for(uint i=0; i < sizeof(hal_object); i++) ! hal_reserved[i] = 0x00; ! // Fill in the structure's header ! uint stack_base = 0x00000000; asm("mov %%esp, %%eax" : "=a"(stack_base)); - stack_base = (stack_base + 0xfff) &0xfffff000; ! hal_object* hal = reinterpret_cast<hal_object*>(hal_reserved); ! hal->processor_number = processor_number; ! hal->kernel_stack_base = stack_base; ! ! return hal; } ! void* heap_manager::AllocateVirtualSpace(uint number_pages) { ! uint length = number_pages*4096; ! ! uint memory = memory_base + memory_size; ! uint address = vspace_base + vspace_size; ! ! uint hi_grow = (memory > address) ? memory : address; ! if(vrange_base - length < hi_grow) ! { ! cout() << "Panic: Too many objects created (loader/heap_manager -> AllocateVirtualSpace)"; ! while(true); ! } ! vrange_base -= length; ! return reinterpret_cast<void*>(vrange_base); } ! void heap_manager::DelocateVirtualSpace(void* address, uint number_pages) { ! if(reinterpret_cast<uint>(address) != vrange_base) { ! cout() << "Panic: Memory leak detected (loader/heap_manager -> DelocateVirtualSpace)"; while(true); } ! vrange_base += number_pages*4096; } ! void* heap_manager::AllocateMemory(uint size_bytes) { ! // All objects will be created on a 8byte aligned addresses to speed up memory access ! uint align = ((memory_base + memory_offset + 7) &0xFFFFFFF8) - (memory_base + memory_offset); ! ! while(size_bytes + align > memory_size - memory_offset) ! { ! if(memory_base > vspace_base) ! { ! boot_hal->memory->MapPage((void*)(memory_base + memory_size), pageframe); ! ! memory_size += 4096; ! pageframe += 4096; ! } ! else ! { ! // Jump over the virtual memory section.. ! memory_base = vspace_base + vspace_size; ! memory_size = memory_offset = align = 0; ! } ! if(memory_base + memory_size > vrange_base) ! { ! cout() << "Panic: Too many objects created (/loader/heap_manager -> AllocateMemory)"; ! while(true); ! } ! } ! memory_offset += size_bytes + align; ! return reinterpret_cast<void*>(memory_base + memory_offset - size_bytes); } ! void* heap_manager::CreatePhysicalWindow(uint physical_base, uint number_pages) { ! uint length = number_pages*4096; ! ! for(uint i=0; length > vspace_size - vspace_offset; i++) ! { ! if(vspace_base > memory_base) ! { ! void* window_address = reinterpret_cast<void*>(vspace_base + vspace_size); ! boot_hal->memory->MapPage(window_address, physical_base, 0x10); ! ! vspace_size += 4096; ! physical_base += 4096; ! } ! else ! { ! vspace_base = memory_base + memory_size; ! vspace_offset = vspace_size = 0; ! } ! ! if(vspace_base + vspace_size > vrange_base) ! { ! cout() << "Panic: Too many objects created (/loader/heap_manager -> ReserveVirtualSpace)"; ! while(true); ! } ! } ! vspace_offset += length; ! return reinterpret_cast<void*>(vspace_base + vspace_offset - length); } char heap_manager_reserved[sizeof(heap_manager)]; heap_manager& heap() { return (reinterpret_cast<heap_manager&>(heap_manager_reserved)); } --- 38,175 ---- // ----------------------------------------------------------------------- ! #include <heap_manager.hpp> ! #include <mmu.hpp> ! #include <console.hpp> ! ! memory_stack::memory_stack(u32b heap_begin) { ! // Initialize the stack with sequential addresses ! for(u08b i=0; i<32; i++) stack[i] = heap_begin + 4096*i; ! stack_pointer = 0; // first element ! stack_underflow = 32; // last + 1 } ! u32b memory_stack::AllocatePage() { ! if(stack_pointer == stack_underflow) { ! cout() << "Panic: Ran out of virtual memory"; ! while(true); } ! return stack[stack_pointer++]; } ! void memory_stack::DelocatePage(u32b base_address) { ! stack[--stack_pointer] = base_address; } ! vRange::vRange(u32b physical_base) { ! page_base = virtual_allocator().AllocatePage(); ! page_size = 4096; ! ! get_hal_object()(memory)(page_base) = memory_mapper::kernel_mode(physical_base); } ! vRange::~vRange() { ! get_hal_object()(memory)(page_base) -= map_item(0).Present(); ! virtual_allocator().DelocatePage(page_base); } ! void* vRange::GetVirtualBase() { ! return reinterpret_cast<void*>(page_base); } ! u32b vRange::GetLength() { ! return page_size; } ! heap_manager::heap_manager(u32b initial_heap) { ! memory_base = initial_heap; ! memory_left = 4096 - sizeof_hobject_cpp; ! } ! u32b heap_manager::GetStackBase() ! { ! u32b stack_base(0); asm("mov %%esp, %%eax" : "=a"(stack_base)); ! return (stack_base + 0xfff) &0xfffff000; } ! void heap_manager::RefreshWindow() { ! u32b phys_page = physical_allocator().AllocatePage(); ! u32b virt_page = virtual_allocator().AllocatePage(); ! get_hal_object()(memory)(virt_page) = memory_mapper::kernel_mode(phys_page); ! memory_base = virt_page; ! memory_left = 4096; } ! void* heap_manager::AllocateMemory(u32b size_bytes) { ! // Aligning the allocation size increases performance ! size_bytes = (size_bytes + 7) &0xFFFFFFF8; ! ! if(size_bytes > 4096) { ! cout() << "Panic: heap-manager doesn't support allocations > 4096 byte"; while(true); } + if(memory_left < size_bytes) + RefreshWindow(); ! void* tmp = reinterpret_cast<void*>(memory_base); ! ! memory_base += size_bytes; ! memory_left -= size_bytes; ! return tmp; } ! void heap_manager::AllocateMpStack() { ! // Allocate a new page for the stack & map it in ! u32b phys_page = physical_allocator().AllocatePage(); ! u32b virt_page = virtual_allocator().AllocatePage(); ! get_hal_object()(memory)(virt_page) = memory_mapper::kernel_mode(phys_page); ! heap_address = virt_page + 4096; // Variable used by the loader } ! hal_object* heap_manager::CreateHalObject(u08b processor) { ! u32b hal_location = GetStackBase() - sizeof_hobject_cpp; ! new ((void*)hal_location) hal_object(processor, GetStackBase()); ! return reinterpret_cast<hal_object*>(hal_location); } char heap_manager_reserved[sizeof(heap_manager)]; + char virt_allocator_reserved[sizeof(memory_stack)]; + char phys_allocator_reserved[sizeof(memory_stack)]; + heap_manager& heap() { return (reinterpret_cast<heap_manager&>(heap_manager_reserved)); } + + memory_stack& virtual_allocator() + { + return (reinterpret_cast<memory_stack&>(virt_allocator_reserved)); + } + + memory_stack& physical_allocator() + { + return (reinterpret_cast<memory_stack&>(phys_allocator_reserved)); + } Index: entry.asm =================================================================== RCS file: /cvsroot/trion/trion v0.2/loader/entry.asm,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** entry.asm 2 Jun 2006 21:11:21 -0000 1.11 --- entry.asm 24 Jun 2006 15:01:32 -0000 1.12 *************** *** 49,52 **** --- 49,54 ---- global ap_code_end ; to boot the application cpus + global sizeof_hobject_cpp + section .text bits 32 *************** *** 80,87 **** USER_MODE equ 7 ; ring3 | present | read&write bsp_entrypoint: ! ; Set up a stack and push the information passed to us by GRUB on it mov esp, [heap_address - salt] add esp, stack_addr + 4096 mov ecx, [cpu_id - salt] mov edx, kernel_end --- 82,95 ---- USER_MODE equ 7 ; ring3 | present | read&write + sizeof_hobject_asm equ 32*4 ; Assumed size (needed for memory reservation) + sizeof_hobject_cpp dd 32*4 + bsp_entrypoint: ! ; Set up a stack and reserve some memory for the hal-object mov esp, [heap_address - salt] add esp, stack_addr + 4096 + sub esp, sizeof_hobject_asm + + ; Push the information passed to us by GRUB on the stack mov ecx, [cpu_id - salt] mov edx, kernel_end *************** *** 120,124 **** loop $-6 ! ; Append a pages for the stack and another one for idt & hal at the end of the kernel mov eax, [heap_address - salt] add eax, stack_addr + SUPERVISOR --- 128,132 ---- loop $-6 ! ; Append a page for the stack and another one for the heap at the end of the kernel mov eax, [heap_address - salt] add eax, stack_addr + SUPERVISOR *************** *** 174,178 **** add eax, salt - 12288 mov ebp, eax ! sub eax, 16 mov esp, eax --- 182,186 ---- add eax, salt - 12288 mov ebp, eax ! sub eax, 16 + sizeof_hobject_asm mov esp, eax *************** *** 190,195 **** cld ! push cs ! pop ds lgdt [ap_gdt_selector - ap_code_start] ; Auto-relocatable since cs=ds, and AP's start at EIP=0 --- 198,203 ---- cld ! mov ax, cs ! mov ds, ax lgdt [ap_gdt_selector - ap_code_start] ; Auto-relocatable since cs=ds, and AP's start at EIP=0 *************** *** 232,235 **** --- 240,244 ---- mov eax, [heap_address] mov esp, eax + sub eax, sizeof_hobject_asm mov ebp, eax |