nss/login: relicense as MIT
[hvf.git] / nss / login / main.c
blob22f064aa9256b188148bdb69564209698a9b2d10
1 /*
2 * Copyright (c) 2007-2019 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
23 #include <arch.h>
24 #include <string.h>
25 #include "int.h"
26 #include "misc.h"
29 * This guest OS has a very simple purpose. It is responsible for
30 * displaying the login splash, prompting the user for a username and
31 * password, and then querying CP to verify that the password is correct.
32 * If correct, CP will detach the rdev from this guest, and attach it to the
33 * user's guest.
35 * +------------------------------------------------+
36 * | +------------------------------------+ |
37 * | | virt_sys | |
38 * | | +--------+ +-------+ +---------+ | +----+|
39 * | | |virt_cpu| |storage| |virt_cons|<--+-->|rdev||
40 * | | +--------+ +-------+ +---------+ | +----+|
41 * | | /\ | |
42 * | | || | |
43 * | | \/ | |
44 * | | +--------+ +--------+ +--------+ | |
45 * | | |virt_dev| |virt_dev| |virt_dev| | |
46 * | | +--------+ +--------+ +--------+ | |
47 * | +------------------------------------+ |
48 * | |
49 * | +------------------------------------+ |
50 * | | virt_sys | |
51 * | | +--------+ +-------+ +---------+ | +----+|
52 * | | |virt_cpu| |storage| |virt_cons|<--+-->|rdev||
53 * | | +--------+ +-------+ +---------+ | +----+|
54 * | | /\ | |
55 * | | || | |
56 * | | \/ | |
57 * | | +--------+ +--------+ +--------+ | |
58 * | | |virt_dev| |virt_dev| |virt_dev| | |
59 * | | +--------+ +--------+ +--------+ | |
60 * | +------------------------------------+ |
61 * | |
62 * | : |
63 * | : |
64 * | : |
65 * | |
66 * | +------------------------------------+ |
67 * | | virt_sys (*LOGIN) | |
68 * | | +--------+ +-------+ +---------+ | |
69 * | | |virt_cpu| |storage| |virt_cons| | |
70 * | | +--------+ +-------+ +---------+ | |
71 * | | +--------+ | +----+|
72 * | | |virt_dev|<--+-->|rdev||
73 * | | +--------+ | +----+|
74 * | | +--------+ | +----+|
75 * | | |virt_dev|<--+-->|rdev||
76 * | | +--------+ | +----+|
77 * | | +--------+ | +----+|
78 * | | |virt_dev|<--+-->|rdev||
79 * | | +--------+ | +----+|
80 * | +------------------------------------+ |
81 * +------------------------------------------------+
84 * In other words, here are the actions that CP takes:
86 * host IPL:
87 * - ipl *LOGIN
88 * - attach operator console to *LOGIN
90 * login:
91 * - alloc virt sys, virt cpu, virt devices, virt cons, storage
92 * - detach console rdev from *LOGIN
93 * - attach console rdev to virt cons
95 * logout/force:
96 * - free virt sys, virt cpu, virt devices, virt cons, storage
97 * - attach console rdev to *LOGIN
99 * disconnect:
100 * - detach console rdev from virt cons
101 * - attach console rdev to *LOGIN
103 * reconnect:
104 * - detach console rdev from *LOGIN
105 * - attach console rdev to virt cons
108 struct psw disabled_wait = { .w = 1, .ea = 1, .ba = 1, .ptr = 0xfafafa, };
109 struct psw enabled_wait = { .io = 1, .m = 1, .w = 1, .ea = 1, .ba = 1, };
111 static struct psw __new_rst = { .ea = 1, .ba = 1, .ptr = ADDR64(&rst_int), };
112 static struct psw __new_ext = { .ea = 1, .ba = 1, .ptr = ADDR64(&ext_int), };
113 static struct psw __new_svc = { .ea = 1, .ba = 1, .ptr = ADDR64(&svc_int), };
114 static struct psw __new_prg = { .ea = 1, .ba = 1, .ptr = ADDR64(&prg_int), };
115 static struct psw __new_mch = { .ea = 1, .ba = 1, .ptr = ADDR64(&mch_int), };
116 static struct psw __new_io = { .ea = 1, .ba = 1, .ptr = ADDR64(&io_int), };
118 static void init_io(void)
120 u64 cr6;
122 cr6 = get_cr(6);
124 /* enable all I/O interrupt classes */
125 cr6 |= BIT64(32);
126 cr6 |= BIT64(33);
127 cr6 |= BIT64(34);
128 cr6 |= BIT64(35);
129 cr6 |= BIT64(36);
130 cr6 |= BIT64(37);
131 cr6 |= BIT64(38);
132 cr6 |= BIT64(39);
134 set_cr(6, cr6);
137 static void init_mch(void)
139 u64 cr14;
141 cr14 = get_cr(14);
143 /* enable Channel-Report-Pending Machine Check Interruption subclass */
144 cr14 |= BIT64(35);
146 set_cr(14, cr14);
149 void start()
151 /* set up interrupt PSWs */
152 memcpy(&psw_rst_new, &__new_rst, sizeof(struct psw));
153 memcpy(&psw_ext_new, &__new_ext, sizeof(struct psw));
154 memcpy(&psw_svc_new, &__new_svc, sizeof(struct psw));
155 memcpy(&psw_prg_new, &__new_prg, sizeof(struct psw));
156 memcpy(&psw_mch_new, &__new_mch, sizeof(struct psw));
157 memcpy(&psw_io_new, &__new_io, sizeof(struct psw));
159 /* enable all 8 I/O classes */
160 init_io();
162 init_mch();
164 /* this enables I/O & MCH interrupts */
165 lpswe(&enabled_wait);
167 die();