// Starts the kernel's idle process. This process has kernel permissions. int idle_main(int argc, char ** params) { int i = 0; char a[] = { ' ', 0x07 }; for(; i < 2000; ++i) { memcpy((char*)0xb8000 + i * 2, a, 2); } // The funny message, windows says starting windows... why shouldn't we? D: char start_msg[][2] = { { 'S', 0x07 }, { 't', 0x08 }, { 'a', 0x09 }, { 'r', 0x0a }, { 't', 0x0b }, { 'i', 0x0c }, { 'n', 0x0d }, { 'g', 0x0e }, { ' ', 0x0f }, { 'M', 0x02 }, { 'o', 0x03 }, { 'n', 0x04 }, { 'i', 0x05 }, { 'x', 0x06 }, { ' ', 0x0f }, { '\001', 0x5f }, }; i = 0; for(; i < 16; ++i) { memcpy((char*)0xb8000 + i * 2, start_msg[i], 2); _setCursor(i); } Cli(); make_atomic(); mount(); // Mount or start the FS tty_init(0); // Load up the TTY's tty_init(1); tty_init(2); tty_init(3); tty_init(4); tty_init(5); setready(); // Set the kernel as ready and the FS as loaded users_init(); // Init the users fs_finish(); release_atomic(); Sti(); while(1) { _Halt(); // Now set to idle. } }
void Timer::set(unsigned int newTimeout) { int e = LoadEflags(); Cli(); if (!running) { Timer *timer0, *timer1; timeout = newTimeout + TimerController::count; // 絶対時間に変換 running = true; timer0 = TimerController::t0; if (timeout <= timer0->timeout) { // 先頭に入る TimerController::t0 = this; next = timer0; TimerController::next = timeout; } else { // this が入る位置を決める do { timer1 = timer0; timer0 = timer0->next; } while (timeout > timer0->timeout); timer1->next = this; next = timer0; } } StoreEflags(e); }
void SysinfoMain(Tab *tab) { Task *task = TaskSwitcher::getNowTask(); int count = 0, count0 = 0; Sheet *sht = tab->sheet; // タイマー作成 Timer *timer = new Timer(task->queue); // タブが閉じられた時消えるように tab->timer = timer; // タイマーセット (1s) timer->set(100); showSysInfo(sht, 0); for (;;) { ++count; Cli(); if (task->queue->isempty()) { //task->sleep(); ベンチマーク測定のため Sti(); } else { int data = task->queue->pop(); Sti(); if (data == timer->data) { showSysInfo(sht, count - count0); count0 = count; timer->set(100); } } } }
void __showerror(char *format, const IPTR *args) { struct IntuitionBase *IntuitionBase; struct DosLibrary *DOSBase = NULL; const char *name = FindTask(NULL)->tc_Node.ln_Name; if ( !__forceerrorrequester && (DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 0)) != NULL && Cli() != NULL ) { if (name) { PutStr(name); PutStr(": "); } if (args) VPrintf(format, args); else PutStr(format); PutStr("\n"); } else if ((IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 0))) { struct EasyStruct es = { sizeof(struct EasyStruct), 0, name, format, "Exit" }; EasyRequestArgs(NULL, &es, NULL, args); CloseLibrary((struct Library *)IntuitionBase); } else { if (name) kprintf("%s: ", name); if (args) { vkprintf(format, args); kprintf("\n"); } else kprintf("%s\n", format); } if (DOSBase != NULL) CloseLibrary((struct Library *)DOSBase); }
//Proceso Top int Tope(int argc, char* argv[]) { char* video= (char*)0xb8000; int proce[65]; char Mensaje [10]; int salto; int i; char a; k_clear_screen(); message("Top V1.0: Procesos y porcentaje de CPU utilizada",0,10); message("PID CPU% TTY NAME",2,0); Sti(); while(a!=68) { a=GetKey(); salto=3; for(i=0;i<65;i++) { proce[i]=0; } for(i=0;i<100;i++) { proce[last100[i]]++; } Cli(); for(i=0;i<65;i++) { PROCESS* p=GetProcessByPID(i); if(p->free==0) { itoa2(i,Mensaje); message(Mensaje,salto,0); itoa2(proce[i],Mensaje); message(Mensaje,salto,28); itoa2(p->tty,Mensaje); message(Mensaje,salto,56); message(p->name,salto,78); salto=salto+1; } message(" ",salto,0); } if (argc>1) i=atoi2(argv[1]); else i=0; Sti(); Sleep(i); } return 0; }
//Funcion a donde van a parar las funciones que terminan. void Cleaner(void) { char Men[10]; Cli(); Destroy(CurrentPID); k_clear_screen(); mess("==>"); Sti(); while(1); }
void __initdetach(void) { struct Library *DOSBase,*SysBase = *(struct Library **)4; struct SignalSemaphore *sema; if (_WBenchMsg) return; if ((sema=sem)) { /* I must be the child process */ ObtainSemaphore(sema); /* Assert that my parent is already dead */ ReleaseSemaphore(sema); FreeMem(sema,sizeof(*sema)); return; } /* I must be the parent */ if ((sem=sema=(struct SignalSemaphore *)AllocMem(sizeof(*sema),MEMF_PUBLIC|MEMF_CLEAR))) { InitSemaphore(sema); if ((DOSBase=OpenLibrary(__dosname,30))) { struct CommandLineInterface *cli = Cli(); APTR pr,stack = __SaveSP; ObtainSemaphore(sema); /* Assert that my child is suspended until I'm finished */ pr = CreateNewProcTags(NP_Seglist,cli->cli_Module, /* child process gets my seglist */ NP_FreeSeglist,1, /* and must free it */ NP_Cli,1, /* it must be a CLI process */ NP_StackSize,__stack, /* it gets a stack */ NP_Name,(ULONG)__procname, /* a name */ NP_Priority,__priority, /* a priority */ NP_Arguments,(ULONG)__commandline,/* and my commandline Arguments */ TAG_END); CloseLibrary(DOSBase); if (pr) { cli->cli_Module = 0; /* I'm no longer owner of this */ /* Adjust stack, release semaphore and return 0 in one. * Maybe the 3 movel are a bit too cautious, but they ARE working */ asm("movel %0,sp;movel %1,a6;movel %2,a0;moveql #0,d0;jmp a6@(-570)":: "r"(stack),"r"(SysBase),"r"(sema):"sp","a6","a0"); } ReleaseSemaphore(sema); /* Again only caution - you never know */ } FreeMem(sema,sizeof(*sema)); /* Couldn't start child :( */ }
static int WBOpen(LIBBASETYPEPTR LIBBASE) { ObtainSemaphore(&(WorkbenchBase->wb_InitializationSemaphore)); if (!(WorkbenchBase->wb_Initialized)) { struct CommandLineInterface *cli; /* Duplicate the search path ---------------------------------------*/ if ((cli = Cli()) != NULL) { WorkbenchBase->wb_SearchPath = DuplicateSearchPath ( cli->cli_CommandDir ); } const struct TagItem tags[]= { {NP_Entry , (IPTR)WorkbenchHandler }, {NP_Name , (IPTR)"Workbench Handler" }, {NP_UserData , (IPTR)WorkbenchBase }, {NP_StackSize, 8129 }, {TAG_DONE , 0 } }; /* Start workbench handler -----------------------------------------*/ if ((CreateNewProc(tags)) != NULL) { /* Prevent expunging while the handler is running */ AROS_ATOMIC_INC(WorkbenchBase->LibNode.lib_OpenCnt); } else { // FIXME: free resources return FALSE; } WorkbenchBase->wb_Initialized = TRUE; } ReleaseSemaphore(&(WorkbenchBase->wb_InitializationSemaphore)); return TRUE; } /* L_OpenLib */
int _dfill (int argc, char ** argv) { int j = 0; for(j = 0; j < 1000; ++j) { int count = 384; int bytes = 65536; int sector = 1 + j * 128; if(argc > 1) { int i; sector = atoi(argv[1]); for(i = 0; i < 65536; ++i) { ans[i] = '0' + (i / 512) % 10; } int offset = 0; int ata = ATA0; Cli(); _disk_write(ata, ans, count, sector); for(i = 0; i < 65536; ++i) { ans[i] = 0; } // _disk_read(ata, ans, count, sector); Sti(); printf("%d\n", j); // for(i = 0; i < count; ++i) { // if(ans[i * 512] != i % 10 + '0') { // printf("Err %d %d %d %d\n", i % 10 + '0', ans[i * 512], i, j); // getC(); // break; // } // } } } return 0; }
bool Timer::cancel() { int e = LoadEflags(); Cli(); if (running) { if (this == TimerController::t0) { // 先頭だった場合 TimerController::t0 = next; TimerController::next = next->timeout; } else { // 1つ前と1つ後をつなげる Timer *timer = TimerController::t0; while (timer->next != this) { timer = timer->next; } timer->next = next; } running = false; StoreEflags(e); return true; } StoreEflags(e); return false; }
/********************************************** kmain() Punto de entrada de código C. *************************************************/ kmain() { int i, num; // Paging.start(0x200000); // init_malloc(); initialize_pics(0x20,0x70); setup_IDT_entry(&idt[0x70], 0x08, (dword) & _rtc, ACS_INT, 0); _cache_init(); hdd_init(); /* CARGA DE IDT CON LA RUTINA DE ATENCION DE IRQ0 */ setup_IDT_entry (&idt[0x00], 0x08, (dword)&_int_00_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x01], 0x08, (dword)&_int_01_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x02], 0x08, (dword)&_int_02_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x03], 0x08, (dword)&_int_03_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x04], 0x08, (dword)&_int_04_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x05], 0x08, (dword)&_int_05_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x06], 0x08, (dword)&_int_06_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x07], 0x08, (dword)&_int_07_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x08], 0x08, (dword)&_int_08_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x09], 0x08, (dword)&_int_09_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x0A], 0x08, (dword)&_int_0A_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x0B], 0x08, (dword)&_int_0B_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x0C], 0x08, (dword)&_int_0C_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x0D], 0x08, (dword)&_int_0D_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x0E], 0x08, (dword)&_int_0E_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x0F], 0x08, (dword)&_int_0F_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x10], 0x08, (dword)&_int_10_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x11], 0x08, (dword)&_int_11_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x12], 0x08, (dword)&_int_12_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x13], 0x08, (dword)&_int_13_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x14], 0x08, (dword)&_int_14_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x15], 0x08, (dword)&_int_15_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x16], 0x08, (dword)&_int_16_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x17], 0x08, (dword)&_int_17_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x18], 0x08, (dword)&_int_18_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x19], 0x08, (dword)&_int_19_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x1A], 0x08, (dword)&_int_1A_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x1B], 0x08, (dword)&_int_1B_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x1C], 0x08, (dword)&_int_1C_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x1D], 0x08, (dword)&_int_1D_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x1E], 0x08, (dword)&_int_1E_hand, ACS_INT, 0); setup_IDT_entry (&idt[0x1F], 0x08, (dword)&_int_1F_hand, ACS_INT, 0); // setup_IDT_entry (&idt[0x20], 0x08, (dword)&_int_20_hand, ACS_INT, 0); // setup_IDT_entry (&idt[0x21], 0x08, (dword)&_int_21_hand, ACS_INT, 0); setup_IDT_entry(&idt[0x20], 0x08, (dword) & _timer_tick_hand, ACS_INT, 0); /* CARGA DE IDT CON LA RUTINA DE ATENCION DE IRQ1 */ setup_IDT_entry(&idt[0x21], 0x08, (dword) & _KB_hand, ACS_INT, 0); /* CARGA DE IDT CON LA RUTINA DE ATENCION DE int80h */ setup_IDT_entry(&idt[0x80], 0x08, (dword) & _int_80_hand, ACS_INT, 0); /* CARGA DE IDT CON LA RUTINA DE ATENCION DE int79h */ setup_IDT_entry(&idt[0x79], 0x08, (dword) & _int_79_hand, ACS_INT, 0); /* Carga de IDTR */ idtr.base = 0; idtr.base += (dword) & idt; idtr.limit = sizeof(idt) - 1; _lidt(&idtr); Cli(); int rate = 0x06; _outb(0x70, 0x0A); //set index to register A char prev=_inb(0x71); //get initial value of register A _outb(0x70, 0x0A); //reset index to A _outb(0x71, (prev & 0xF0) | rate); //write only our rate to A. Note, rate is the bottom 4 bits. init_paging(); scheduler_init(); /* Habilito interrupcion de timer tick*/ _mascaraPIC1(0xFC); _mascaraPIC2(0xFE); _outb(0x70, 0x0B); //set the index to register B prev= _inb(0x71); //read the current value of register B _outb(0x70, 0x0B); //set the index again(a read will reset the index to register D) _outb(0x71, prev | 0x40); //write the previous value or'd with 0x40. This turns on bit 6 of register B Sti(); idle = create_process("idle", idle_main, 0, 0, 0, 0, 0, 0, 0, NULL, 0); // We soon exit out of here :) while (1); }
/********************************************** kmain() Punto de entrada de código C. *************************************************/ kmain() { int i, num; setup_IDT_entry(&idt[0x70], 0x08, (dword) & _rtc, ACS_INT, 0); /* CARGA DE IDT CON LA RUTINA DE ATENCION DE IRQ0 */ setup_IDT_entry(&idt[0x08], 0x08, (dword) & _int_08_hand, ACS_INT, 0); /* CARGA DE IDT CON LA RUTINA DE ATENCION DE IRQ1 */ setup_IDT_entry(&idt[0x09], 0x08, (dword) & _int_09_hand, ACS_INT, 0); /* CARGA DE IDT CON LA RUTINA DE ATENCION DE int80h */ setup_IDT_entry(&idt[0x80], 0x08, (dword) & _int_80_hand, ACS_INT, 0); /* CARGA DE IDT CON LA RUTINA DE ATENCION DE int79h */ setup_IDT_entry(&idt[0x79], 0x08, (dword) & _int_79_hand, ACS_INT, 0); /* Carga de IDTR */ idtr.base = 0; idtr.base += (dword) & idt; idtr.limit = sizeof(idt) - 1; _lidt(&idtr); Cli(); int rate = 0x06; _outb(0x70, 0x0A); //set index to register A char prev=_inb(0x71); //get initial value of register A _outb(0x70, 0x0A); //reset index to A _outb(0x71, (prev & 0xF0) | rate); //write only our rate to A. Note, rate is the bottom 4 bits. scheduler_init(); /* Habilito interrupcion de timer tick*/ _mascaraPIC1(0x00); _mascaraPIC2(0x00); _outb(0x70, 0x0B); //set the index to register B prev= _inb(0x71); //read the current value of register B _outb(0x70, 0x0B); //set the index again(a read will reset the index to register D) _outb(0x71, prev | 0x40); //write the previous value or'd with 0x40. This turns on bit 6 of register B Sti(); idle = create_process("idle", idle_main, 0, 0, 0, 0, 0, 0, 0, NULL, 0); // We soon exit out of here :) while (1); }
static void __startup_detach(void) { struct CommandLineInterface *cli; struct Process *newproc; BPTR mysegment = NULL; STRPTR detached_name; D(bug("Entering __startup_detach(\"%s\", %d, %x)\n", argstr, argsize, SysBase)); cli = Cli(); /* Without a CLI detaching makes no sense, just jump to the real program. */ if (!cli) { __startup_entries_next(); } else { mysegment = cli->cli_Module; cli->cli_Module = NULL; detached_name = __detached_name ? __detached_name : (STRPTR)FindTask(NULL)->tc_Node.ln_Name; { struct TagItem tags[] = { { NP_Seglist, (IPTR)mysegment }, { NP_Entry, (IPTR)&__detach_trampoline }, { NP_Name, (IPTR)detached_name }, { NP_Arguments, (IPTR)__argstr }, { NP_Cli, TRUE }, { TAG_DONE, 0 } }; __detacher_process = (struct Process *)FindTask(NULL); /* CreateNewProc() will take care of freeing the seglist */ newproc = CreateNewProc(tags); } if (!newproc) { cli->cli_Module = mysegment; __detached_return_value = RETURN_ERROR; } else while (!__detacher_go_away) Wait(SIGF_SINGLE); if (__detached_return_value != RETURN_OK) { PutStr(FindTask(NULL)->tc_Node.ln_Name); PutStr(": Failed to detach.\n"); } if (newproc) { Forbid(); Signal(&newproc->pr_Task, SIGF_SINGLE); } __aros_startup.as_startup_error = __detached_return_value; } D(bug("Leaving __startup_detach\n")); }