int main(void) { init_global(); init_gdt(); init_idt(); init_tss(); init_virtual_memory_mapping(); init_process(); init_8259a(); init_clock(); init_keyboard(); init_syscall(); debug_helper(); restart(); }
int main (int argc, char ** argv) { uint64_t * p0; const char * source_fname; size_t embed_minimum_size; if (argc < 2) { fputs ("Usage: winloader.exe <program.prg> [args...]\n", stderr); return 1; } source_fname = argv[1]; embed_minimum_size = init_load (source_fname); p0 = VirtualAlloc (NULL, embed_minimum_size + MAX_HEAP_SIZE, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); assert (p0 != NULL); printf ("p0 = %p\n", p0); init_syscall ((((uint64_t) p0) + embed_minimum_size), (((uint64_t) p0) + embed_minimum_size + MAX_HEAP_SIZE)); do_load (p0, syscall_shim, source_fname); printf ("launch = %p\n\n\n\n", p0); go_shim (p0, argc - 1, &argv[1]); /* failure...! */ return 1; }
NTSTATUS DriverEntry( IN PDRIVER_OBJECT drv_obj, IN PUNICODE_STRING reg_pth ) { // PIMAGE_DOS_HEADER d_head; // PIMAGE_NT_HEADERS n_head; NTSTATUS status = STATUS_UNSUCCESSFUL; HANDLE h_key = NULL; // u32 tstamp; do { if ( (h_key = reg_open_key(reg_pth->Buffer, NULL)) == NULL ) { DbgMsg("can not open service key\n"); break; } /* get ntoskrnl base */ if ( (ntkrn_base = get_kernel_base()) == NULL ) { DbgMsg("kernel base not found\n"); break; } DbgMsg("kernel base: %x\n", ntkrn_base); /* get ntoskrnl timestamp */ /* turned off because of the futility: dbghelp do this stuf if (reg_query_val(h_key, L"sym_timestamp", &tstamp, sizeof(tstamp)) == 0) { DbgMsg("unable to get ntoskrnl timestamp\n"); break; } */ /* validate ntoskrnl timestamp */ /* d_head = ntkrn_base; n_head = addof(d_head, d_head->e_lfanew); if (n_head->FileHeader.TimeDateStamp != tstamp) { DbgMsg("invalid ntoskrnl timestamp\n"); break; } */ if (init_hook_list() == 0){ DbgMsg("init_hook_list failed\n"); break; } if (init_dbg_item(h_key) == 0) { DbgMsg("init_dbg_item failed\n"); break; } if (init_debug(h_key) == 0) { DbgMsg("init_debug failed\n"); break; } if (init_syscall(h_key) == 0) { DbgMsg("init_syscall failed\n"); break; } DbgMsg("dbgapi initialized\n"); status = STATUS_SUCCESS; } while (0); if (h_key != NULL) { ZwClose(h_key); } return status; }
int kmain(unsigned int magic,multibootInfo *mb) { construct(); //construct the global objects char ans; cout<<"Nano OS is booting\n"; String::strcpy(boot_dev,(const char *)mb->bootDevice); memend=mb->memoryUpper*1024+0x100000; //memory end upper memory in bytes +1MB // well now show the world we have managed our Memory ;) multiboot *m_boot; m_boot=multiboot::Instance(); m_boot->set_multiboot_info(mb); m_boot->set_multiboot_hdr(); cout<<"===============================\n"; cout<<"Available Memory : "<<(unsigned int)m_boot->get_mem_avail()/1024<<"\n"; cout<<" Used Memory : "<<(unsigned int)m_boot->get_mem_used()/1024<<"\n"; cout<<"===============================\n"; cout.flags(hex|showbase); cout<<"Kernel start "<<(unsigned int)m_boot->get_k_start()<<" Kernel end "<<(unsigned int)m_boot->get_k_end() \ <<" kernel length ="<<(unsigned int)m_boot->get_k_length()<<"\n"; cout.flags(dec); kend = m_boot->get_k_end(); // Before we do any thing we should initialize our Heap based memory allocator( Thanks to Chris Giese ) init_heap(); // Setup our Descriptor tables GDT and IDT cout<<"Setting up GDT "; GDT::setup(); cout.SetColour(RED,BLACK,0); cout<<"done\n"; cout.SetColour(WHITE,BLACK,0); cout<<"setting up IDT "; IDT::setup(); cout.SetColour(RED,BLACK,0); cout<<"done\n"; cout.SetColour(WHITE,BLACK,0); // After our IDT is loaded We should install our interrupt cout<<"setting up IRQ subsystem "; IRQ::setup(); cout.SetColour(RED,BLACK,0); cout<<"done\n"; cout.SetColour(WHITE,BLACK,0); // Now, as our IRQ subsystem is set we should install keyboard sothat, our system will be interractive. cout<<"installing key board \n"; kbd::setup(); cout.SetColour(RED,BLACK,0); cout<<"done\n"; cout.SetColour(WHITE,BLACK,0); // The operating system and the digital computers are worthless if there is no timer // so install and initialize the timer cout<<"installing timer interrupt "; TIMER *my_timer = TIMER::Instance(); my_timer->setup(); cout.SetColour(RED,BLACK,0); cout<<"done\n"; cout.SetColour(WHITE,BLACK,0); cout<<"my_timer at "<<(unsigned int)my_timer<<"\n"; cout<<"Mboot at "<<(unsigned int)m_boot<<"\n"; // So all the basic systems are in place now // We should initialize the PCI subsystem cout<<"Scanning PCI...\n"; pci_bus *sys_pci_bus=pci_bus::Instance(); sys_pci_bus->scan(); sys_pci_bus->list_dev(); cout.SetColour(RED,BLACK,0); cout<<"done\n"; cout.SetColour(WHITE,BLACK,0); // now we can start our interrupt system cout<<"\n\n"<<"Enabling Interrupts "; enable(); cout.SetColour(RED,BLACK,0); cout<<"done\n"; cout.SetColour(WHITE,BLACK,0); // now check if we have any PCI IDE cout<<"Initilizing storage susbsystem(PCI-IDE) "; init_disks(); cout.SetColour(RED,BLACK,0); cout<<"done\n"; cout.SetColour(WHITE,BLACK,0); cout<<"Initializing Net device..."; detect_netdev(); cout.SetColour(RED,BLACK,0); cout<<"done\n"; cout.SetColour(WHITE,BLACK,0); //cout<<"\nDone\n"; //here let us try our Network ethernet device setup //sys_nic0->send_arp_request(); //cout<<"net init complete\n"; //cout<<"sending\n"; //for(int i=0;i<10;i++) // test_req_arp(); // show which IRQs are installed not necessary but it comes handy while debugging the ISRs. //cout<<"\n"<<"Dumping IRQ routines \n"; //IRQ::dump_irq_routines(); // Our tasks are thread implemented in kernel and it depends on timer interrupt // so now we can start the tasking subsystem //cout<<"Initializing tasking "; //init_tasks(); // bellow this we should not see anything.. why? because in the tasks we started 2 threads // one idle thread and other is our Shell //cout<<"done\n"; init_syscall(); my_test(); for(;;); cout<<"\nReached End of kernel\n shoud not happen \n\nGOODBYE\n"; disable(); halt(); return 0; }