You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
272 volume VI os16<br />
Script e sorgenti del kernel 273<br />
«<br />
«<br />
«<br />
1710115 | //<br />
1710116 | // Allocate memory for the extra BIOS at the<br />
1710117 | // bottom of the 640 Kibyte.<br />
1710118 | //<br />
1710119 | start = int12 ();<br />
1710120 | start *= 1024;<br />
1710121 | size = 0xA0000L - start;<br />
1710122 | mb_alloc (start, size);<br />
1710123 | //<br />
1710124 | // Enable and disable hardware interrupts (IRQ).<br />
1710125 | //<br />
1710126 | irq_on (0); // timer.<br />
1710127 | irq_on (1); // enable keyboard<br />
1710128 | irq_off (2); //<br />
1710129 | irq_off (3); //<br />
1710130 | irq_off (4); //<br />
1710131 | irq_off (5); //<br />
1710132 | irq_on (6); // floppy (must be on to let int 13 work)!<br />
1710133 | irq_off (7); //<br />
1710134 | //<br />
1710135 | // Interrupts activation.<br />
1710136 | //<br />
1710137 | sti ();<br />
1710138 |}<br />
104.9.7 kernel/proc/proc_reference.c<br />
Si veda la sezione 103.8.7.<br />
1720001 |#include <br />
1720002 |//----------------------------------------------------------------------<br />
1720003 |proc_t *<br />
1720004 |proc_reference (pid_t pid)<br />
1720005 |{<br />
1720006 | if (pid >= 0 && pid < PROCESS_MAX)<br />
1720007 | {<br />
1720008 | return (&proc_table[pid]);<br />
1720009 | }<br />
1720010 | else<br />
1720011 | {<br />
1720012 | return (NULL);<br />
1720013 | }<br />
1720014 |}<br />
104.9.8 kernel/proc/proc_sch_signals.c<br />
Si veda la sezione 103.8.8.<br />
1730001 |#include <br />
1730002 |//----------------------------------------------------------------------<br />
1730003 |void<br />
1730004 |proc_sch_signals (void)<br />
1730005 |{<br />
1730006 | pid_t pid;<br />
1730007 | for (pid = 0; pid < PROCESS_MAX; pid++)<br />
1730008 | {<br />
1730009 | proc_sig_term (pid, SIGHUP);<br />
1730010 | proc_sig_term (pid, SIGINT);<br />
1730011 | proc_sig_core (pid, SIGQUIT);<br />
1730012 | proc_sig_core (pid, SIGILL);<br />
1730013 | proc_sig_core (pid, SIGABRT);<br />
1730014 | proc_sig_core (pid, SIGFPE);<br />
1730015 | proc_sig_term (pid, SIGKILL);<br />
1730016 | proc_sig_core (pid, SIGSEGV);<br />
1730017 | proc_sig_term (pid, SIGPIPE);<br />
1730018 | proc_sig_term (pid, SIGALRM);<br />
1730019 | proc_sig_term (pid, SIGTERM);<br />
1730020 | proc_sig_term (pid, SIGUSR1);<br />
1730021 | proc_sig_term (pid, SIGUSR2);<br />
1730022 | proc_sig_chld (pid, SIGCHLD);<br />
1730023 | proc_sig_cont (pid, SIGCONT);<br />
1730024 | proc_sig_stop (pid, SIGSTOP);<br />
1730025 | proc_sig_stop (pid, SIGTSTP);<br />
1730026 | proc_sig_stop (pid, SIGTTIN);<br />
1730027 | proc_sig_stop (pid, SIGTTOU);<br />
1730028 | }<br />
1730029 |}<br />
104.9.9 kernel/proc/proc_sch_terminals.c<br />
Si veda la sezione 103.8.9.<br />
1740001 |#include <br />
1740002 |#include <br />
1740003 |//----------------------------------------------------------------------<br />
1740004 |void<br />
1740005 |proc_sch_terminals (void)<br />
1740006 |{<br />
1740007 | pid_t pid;<br />
1740008 | int key;<br />
1740009 | tty_t *tty;<br />
1740010 | dev_t device;<br />
1740011 | //<br />
1740012 | // Try to read a key from console keyboard buffer (only consoles<br />
1740013 | // are available).<br />
1740014 | //<br />
1740015 | key = con_char_ready ();<br />
1740016 | if (key == 0)<br />
1740017 | {<br />
1740018 | //<br />
1740019 | // No key is ready on the keyboard buffer: just return.<br />
1740020 | //<br />
1740021 | return;<br />
1740022 | }<br />
1740023 | //<br />
1740024 | // A key is available. Find the currently active console.<br />
1740025 | //<br />
1740026 | device = tty_console ((dev_t) 0);<br />
1740027 | tty = tty_reference (device);<br />
1740028 | if (tty == NULL)<br />
1740029 | {<br />
1740030 | k_printf ("kernel alert: console device 0x%04x not found!\n",<br />
1740031 | device);<br />
1740032 | //<br />
1740033 | // Will send the typed character to the first terminal!<br />
1740034 | //<br />
1740035 | tty = tty_reference ((dev_t) 0);<br />
1740036 | }<br />
1740037 | //<br />
1740038 | // Defined the active console. Put the character there.<br />
1740039 | //<br />
1740040 | if (tty->key == 0)<br />
1740041 | {<br />
1740042 | tty->status = TTY_OK;<br />
1740043 | }<br />
1740044 | else<br />
1740045 | {<br />
1740046 | tty->status = TTY_LOST_KEY;<br />
1740047 | }<br />
1740048 | tty->key = con_char_read ();<br />
1740049 | //<br />
1740050 | // Verify if it is a control key that must be handled. If so, a<br />
1740051 | // signal is sent to all processes with the same control terminal,<br />
1740052 | // excluded the kernel (0) and ‘init’ (1). Such control keys are not<br />
1740053 | // passed to the applications.<br />
1740054 | //<br />
1740055 | // Please note that this a simplified solution, because the signal<br />
1740056 | // should reach only the foreground process of the group. For that<br />
1740057 | // reason, only che [Ctrl C] is taken into consideration, because<br />
1740058 | // processes can ignore the signal ’SIGINT’.<br />
1740059 | //<br />
1740060 | if (tty->pgrp != 0)<br />
1740061 | {<br />
1740062 | //<br />
1740063 | // There is a process group for that terminal.<br />
1740064 | //<br />
1740065 | if (tty->key == 3) // [Ctrl C] -> SIGINT<br />
1740066 | {<br />
1740067 | for (pid = 2; pid < PROCESS_MAX; pid++)<br />
1740068 | {<br />
1740069 | if (proc_table[pid].pgrp == tty->pgrp)<br />
1740070 | {<br />
1740071 | k_kill (pid, SIGINT);<br />
1740072 | }<br />
1740073 | }<br />
1740074 | tty->key = 0; // Reset key and status.<br />
1740075 | tty->status = TTY_OK;<br />
1740076 | }<br />
1740077 | }<br />
1740078 | //<br />
1740079 | // Check for a console switch key combination.<br />
1740080 | //<br />
1740081 | if (tty->key == 0x11) // [Ctrl Q] -> DC1 -> console0.<br />
1740082 | {<br />
1740083 | tty->key = 0; // Reset key and status.<br />
1740084 | tty->status = TTY_OK;<br />
1740085 | tty_console (DEV_CONSOLE0); // Switch.<br />
1740086 | }<br />
1740087 | else if (tty->key == 0x12) // [Ctrl R] -> DC2 -> console1.<br />
1740088 | {<br />
1740089 | tty->key = 0; // Reset key and status.<br />
1740090 | tty->status = TTY_OK;<br />
1740091 | tty_console (DEV_CONSOLE1); // Switch.<br />
1740092 | }<br />
1740093 | else if (tty->key == 0x13) // [Ctrl S] -> DC3 -> console2.<br />
1740094 | {<br />
1740095 | tty->key = 0; // Reset key and status.<br />
1740096 | tty->status = TTY_OK;<br />
1740097 | tty_console (DEV_CONSOLE2); // Switch.<br />
1740098 | }<br />
1740099 | else if (tty->key == 0x14) // [Ctrl T] -> DC4 -> console3.<br />
1740100 | {<br />
1740101 | tty->key = 0; // Reset key and status.<br />
1740102 | tty->status = TTY_OK;<br />
1740103 | tty_console (DEV_CONSOLE3); // Switch.<br />
1740104 | }<br />
1740105 | //<br />
1740106 | // A key was pressed: must wake up all processes waiting for reading<br />
1740107 | // a terminal: all processes must be reactivated, because a process<br />
1740108 | // can read from the device file, and not just from its own<br />
1740109 | // terminal.<br />
1740110 | //<br />
1740111 | for (pid = 0; pid < PROCESS_MAX; pid++)<br />
1740112 | {<br />
1740113 | if ( (proc_table[pid].status == PROC_SLEEPING)<br />
1740114 | && (proc_table[pid].wakeup_events & WAKEUP_EVENT_TTY))<br />
1740115 | {<br />
1740116 | //<br />
1740117 | // A process waiting for that terminal was found:<br />
1740118 | // remove the waiting event and set it ready.<br />
1740119 | //<br />
1740120 | proc_table[pid].wakeup_events &= ~WAKEUP_EVENT_TTY;<br />
1740121 | proc_table[pid].status = PROC_READY;<br />
1740122 | }<br />
1740123 | }<br />
1740124 |}<br />
104.9.10 kernel/proc/proc_sch_timers.c<br />
Si veda la sezione 103.8.10.<br />
1750001 |#include <br />
1750002 |#include <br />
1750003 |//----------------------------------------------------------------------<br />
1750004 |void<br />
1750005 |proc_sch_timers (void)<br />
1750006 |{<br />
1750007 | static unsigned long int previous_time;<br />
1750008 | unsigned long int current_time;<br />
1750009 | unsigned int pid;<br />
1750010 | current_time = k_time (NULL);<br />
1750011 | if (previous_time != current_time)<br />
1750012 | {<br />
1750013 | for (pid = 0; pid < PROCESS_MAX; pid++)<br />
1750014 | {<br />
1750015 | if ( (proc_table[pid].wakeup_events & WAKEUP_EVENT_TIMER)<br />
1750016 | && (proc_table[pid].status == PROC_SLEEPING)<br />
1750017 | && (proc_table[pid].wakeup_timer > 0))<br />
1750018 | {<br />
«