Rev 534 | Rev 1777 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 534 | Rev 669 | ||
---|---|---|---|
Line 33... | Line 33... | ||
33 | #include <arch/types.h> |
33 | #include <arch/types.h> |
34 | 34 | ||
35 | ofw_entry ofw; |
35 | ofw_entry ofw; |
36 | 36 | ||
37 | phandle ofw_chosen; |
37 | phandle ofw_chosen; |
- | 38 | ihandle ofw_stdin; |
|
38 | ihandle ofw_stdout; |
39 | ihandle ofw_stdout; |
39 | 40 | ||
40 | void ofw_init(void) |
41 | void ofw_init(void) |
41 | { |
42 | { |
42 | ofw_chosen = ofw_find_device("/chosen"); |
43 | ofw_chosen = ofw_find_device("/chosen"); |
43 | if (ofw_chosen == -1) |
44 | if (ofw_chosen == -1) |
44 | ofw_done(); |
45 | ofw_done(); |
45 | 46 | ||
- | 47 | if (ofw_get_property(ofw_chosen, "stdin", &ofw_stdin, sizeof(ofw_stdin)) <= 0) |
|
- | 48 | ofw_stdin = 0; |
|
- | 49 | ||
46 | if (ofw_get_property(ofw_chosen, "stdout", &ofw_stdout, sizeof(ofw_stdout)) <= 0) |
50 | if (ofw_get_property(ofw_chosen, "stdout", &ofw_stdout, sizeof(ofw_stdout)) <= 0) |
47 | ofw_stdout = 0; |
51 | ofw_stdout = 0; |
48 | } |
52 | } |
49 | 53 | ||
50 | void ofw_done(void) |
54 | void ofw_done(void) |
51 | { |
55 | { |
52 | (void) ofw_call("exit", 0, 0); |
56 | (void) ofw_call("exit", 0, 0); |
Line 82... | Line 86... | ||
82 | return; |
86 | return; |
83 | 87 | ||
84 | (void) ofw_call("write", 3, 1, ofw_stdout, &ch, 1); |
88 | (void) ofw_call("write", 3, 1, ofw_stdout, &ch, 1); |
85 | } |
89 | } |
86 | 90 | ||
- | 91 | /** Read character from OFW's input. |
|
- | 92 | * |
|
- | 93 | * This call is non-blocking. |
|
- | 94 | * |
|
- | 95 | * @return 0 if no character was read, character read otherwise. |
|
- | 96 | */ |
|
- | 97 | char ofw_getchar(void) |
|
- | 98 | { |
|
- | 99 | char ch; |
|
- | 100 | ||
- | 101 | if (ofw_stdin == 0) |
|
- | 102 | return 0; |
|
- | 103 | ||
- | 104 | if (ofw_call("read", 3, 1, ofw_stdin, &ch, 1) == 1) |
|
- | 105 | return ch; |
|
- | 106 | else |
|
- | 107 | return 0; |
|
- | 108 | } |
|
- | 109 | ||
87 | phandle ofw_find_device(const char *name) |
110 | phandle ofw_find_device(const char *name) |
88 | { |
111 | { |
89 | return (phandle) ofw_call("finddevice", 1, 1, name); |
112 | return (phandle) ofw_call("finddevice", 1, 1, name); |
90 | } |
113 | } |
91 | 114 |