24.01.2014 Views

Codice

Codice

Codice

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

188 volume VI os16<br />

Script e sorgenti del kernel 189<br />

«<br />

80024 | if (rw == DEV_READ)<br />

80025 | {<br />

80026 | n = mem_read ((addr_t) offset, buffer, size);<br />

80027 | }<br />

80028 | else<br />

80029 | {<br />

80030 | n = mem_write ((addr_t) offset, buffer, size);<br />

80031 | }<br />

80032 | }<br />

80033 | else if (device == DEV_NULL) // DEV_NULL<br />

80034 | {<br />

80035 | n = 0;<br />

80036 | }<br />

80037 | else if (device == DEV_ZERO) // DEV_ZERO<br />

80038 | {<br />

80039 | if (rw == DEV_READ)<br />

80040 | {<br />

80041 | for (n = 0; n < size; n++)<br />

80042 | {<br />

80043 | buffer08[n] = 0;<br />

80044 | }<br />

80045 | }<br />

80046 | else<br />

80047 | {<br />

80048 | n = 0;<br />

80049 | }<br />

80050 | }<br />

80051 | else if (device == DEV_PORT) // DEV_PORT<br />

80052 | {<br />

80053 | if (rw == DEV_READ)<br />

80054 | {<br />

80055 | if (size == 1)<br />

80056 | {<br />

80057 | buffer08[0] = in_8 (offset);<br />

80058 | n = 1;<br />

80059 | }<br />

80060 | else if (size == 2)<br />

80061 | {<br />

80062 | buffer16[0] = in_16 (offset);<br />

80063 | n = 2;<br />

80064 | }<br />

80065 | else<br />

80066 | {<br />

80067 | n = 0;<br />

80068 | }<br />

80069 | }<br />

80070 | else<br />

80071 | {<br />

80072 | if (size == 1)<br />

80073 | {<br />

80074 | out_8 (offset, buffer08[0]);<br />

80075 | }<br />

80076 | else if (size == 2)<br />

80077 | {<br />

80078 | out_16 (offset, buffer16[0]);<br />

80079 | n = 2;<br />

80080 | }<br />

80081 | else<br />

80082 | {<br />

80083 | n = 0;<br />

80084 | }<br />

80085 | }<br />

80086 | }<br />

80087 | else<br />

80088 | {<br />

80089 | errset (ENODEV);<br />

80090 | return (-1);<br />

80091 | }<br />

80092 | return (n);<br />

80093 |}<br />

104.2.5 kernel/devices/dev_tty.c<br />

Si veda la sezione 103.1.5.<br />

90042 | //<br />

90043 | if (device == DEV_CONSOLE)<br />

90044 | {<br />

90045 | device = tty_console ((dev_t) 0);<br />

90046 | //<br />

90047 | // As a last resort, use the first console: ‘DEV_CONSOLE0’.<br />

90048 | //<br />

90049 | if (device == 0 || device == DEV_TTY)<br />

90050 | {<br />

90051 | device = DEV_CONSOLE0;<br />

90052 | }<br />

90053 | }<br />

90054 | //<br />

90055 | // Read or write.<br />

90056 | //<br />

90057 | if (rw == DEV_READ)<br />

90058 | {<br />

90059 | for (n = 0; n < size; n++)<br />

90060 | {<br />

90061 | buffer08[n] = tty_read (device);<br />

90062 | if (buffer08[n] == 0)<br />

90063 | {<br />

90064 | //<br />

90065 | // If the pid is not the kernel, should put the process<br />

90066 | // to sleep, waiting for the key.<br />

90067 | //<br />

90068 | if (pid == 0 || ps == NULL)<br />

90069 | {<br />

90070 | //<br />

90071 | // For the kernel there is no sleep and for an<br />

90072 | // unidentified process, either.<br />

90073 | //<br />

90074 | break;<br />

90075 | }<br />

90076 | //<br />

90077 | // Put the process to sleep.<br />

90078 | //<br />

90079 | ps->status = PROC_SLEEPING;<br />

90080 | ps->ret = 0;<br />

90081 | ps->wakeup_events = WAKEUP_EVENT_TTY;<br />

90082 | ps->wakeup_signal = 0;<br />

90083 | ps->wakeup_timer = 0;<br />

90084 | //<br />

90085 | break;<br />

90086 | }<br />

90087 | //<br />

90088 | // Check for control characters.<br />

90089 | //<br />

90090 | if (buffer08[n] == 0x04) // EOT<br />

90091 | {<br />

90092 | //<br />

90093 | // Return EOF.<br />

90094 | //<br />

90095 | *eof = 1;<br />

90096 | break;<br />

90097 | }<br />

90098 | //<br />

90099 | // At this point, show the character on screen, even if it<br />

90100 | // is not nice. It is necessary to show something, because<br />

90101 | // the tty handling is very poor and the library for line<br />

90102 | // input, calculate cursor position based on the characters<br />

90103 | // received.<br />

90104 | //<br />

90105 | tty_write (device, (int) buffer08[n]);<br />

90106 | }<br />

90107 | }<br />

90108 | else<br />

90109 | {<br />

90110 | for (n = 0; n < size; n++)<br />

90111 | {<br />

90112 | tty_write (device, (int) buffer08[n]);<br />

90113 | }<br />

90114 | }<br />

90115 | return (n);<br />

90116 |}<br />

90001 |#include <br />

90002 |#include <br />

90003 |#include <br />

90004 |#include <br />

90005 |#include <br />

90006 |#include <br />

90007 |#include <br />

90008 |#include <br />

90009 |#include <br />

90010 |#include <br />

90011 |#include <br />

90012 |#include <br />

90013 |//----------------------------------------------------------------------<br />

90014 |ssize_t<br />

90015 |dev_tty (pid_t pid, dev_t device, int rw, off_t offset, void *buffer,<br />

90016 | size_t size, int *eof)<br />

90017 |{<br />

90018 | uint8_t *buffer08 = (uint8_t *) buffer;<br />

90019 | ssize_t n;<br />

90020 | proc_t *ps;<br />

90021 | //<br />

90022 | // Get process. Variable ‘ps’ will be ‘NULL’ if the process ID is<br />

90023 | // not valid.<br />

90024 | //<br />

90025 | ps = proc_reference (pid);<br />

90026 | //<br />

90027 | // Convert ‘DEV_TTY’ with the controlling terminal for the process.<br />

90028 | //<br />

90029 | if (device == DEV_TTY)<br />

90030 | {<br />

90031 | device = ps->device_tty;<br />

90032 | //<br />

90033 | // As a last resort, use the generic ‘DEV_CONSOLE’.<br />

90034 | //<br />

90035 | if (device == 0 || device == DEV_TTY)<br />

90036 | {<br />

90037 | device = DEV_CONSOLE;<br />

90038 | }<br />

90039 | }<br />

90040 | //<br />

90041 | // Convert ‘DEV_CONSOLE’ to the currently active console.<br />

104.3 os16: «kernel/diag.h»<br />

Si veda la sezione 103.2.<br />

100001 |#ifndef _KERNEL_DIAG_H<br />

100002 |#define _KERNEL_DIAG_H 1<br />

100003 |<br />

100004 |#include <br />

100005 |#include <br />

100006 |#include <br />

100007 |#include <br />

100008 |<br />

100009 |//----------------------------------------------------------------------<br />

100010 |uint8_t reverse_8_bit (uint8_t source);<br />

100011 |uint16_t reverse_16_bit (uint16_t source);<br />

100012 |uint32_t reverse_32_bit (uint32_t source);<br />

100013 |<br />

100014 |#define reverse_char(s) ((char) reverse_8_bit ((uint8_t) s))<br />

100015 |#define reverse_short(s) ((short) reverse_16_bit ((uint16_t) s))<br />

100016 |#define reverse_int(s) ((int) reverse_16_bit ((uint16_t) s))<br />

100017 |#define reverse_long(s) ((long) reverse_32_bit ((uint32_t) s))<br />

100018 |#define reverse_long_int(s) ((long int) reverse_32_bit ((uint32_t) s))<br />

100019 |//----------------------------------------------------------------------<br />

100020 |void print_hex_8 (void *data, size_t elements);<br />

100021 |void print_hex_16 (void *data, size_t elements);<br />

100022 |void print_hex_32 (void *data, size_t elements);<br />

100023 |<br />

100024 |#define print_hex_char(d, e) (print_hex_8 (d, e))<br />

100025 |#define print_hex_short(d, e) (print_hex_16 (d, e))<br />

100026 |#define print_hex_int(d, e) (print_hex_16 (d, e))<br />

100027 |#define print_hex_long(d, e) (print_hex_32 (d, e))<br />

100028 |#define print_hex_long_int(d, e) (print_hex_32 (d, e))<br />

100029 |//----------------------------------------------------------------------<br />

100030 |void print_hex_8_reverse (void *data, size_t elements);<br />

100031 |void print_hex_16_reverse (void *data, size_t elements);<br />

100032 |void print_hex_32_reverse (void *data, size_t elements);<br />

100033 |<br />

100034 |#define print_hex_char_reverse(d, e) (print_hex_8_reverse (d, e))<br />

100035 |#define print_hex_short_reverse(d, e) (print_hex_16_reverse (d, e))<br />

«

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!