summaryrefslogtreecommitdiff
path: root/debian/patches/bootshell0010-pull-code-from-livecd-XXX-document.patch
blob: 6c33ad06253d65ce51235933de177ceaabda8410 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
From 5b5aaa1031497a9a6d85e45ba2924d54f233d7ec Mon Sep 17 00:00:00 2001
From: Justus Winter <4winter@informatik.uni-hamburg.de>
Date: Mon, 9 Mar 2015 20:51:53 +0100
Subject: [PATCH hurd 10/10] pull code from livecd XXX document

---
 bootshell/runsystem.scm | 206 +++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 170 insertions(+), 36 deletions(-)

diff --git a/bootshell/runsystem.scm b/bootshell/runsystem.scm
index befb07c..af6e943 100644
--- a/bootshell/runsystem.scm
+++ b/bootshell/runsystem.scm
@@ -115,27 +115,65 @@
     (proc->mark-important! p)
     (proc->mark-exec! p)))
 
-(define (bootstrap rootfs-args exec-args)
-  (log "Hurd server bootstrap: ")
+(define (path->string x)
+  (if (string? x) x (symbol->string x)))
+
+(define (start-active-translator path args)
+  (log (path->string path) " ")
+  (bind path (start-translator (task-create mach-task-self 0) args)))
+
+(define messages '())
+(define (log . args)
+  (set! messages (append messages args))
+  (for-each display args))
+(define (replay-log)
+  (for-each display messages))
+
+(define rootfs-control MACH_PORT_NULL)
 
+(define (traditional-first-stage)
   (log "rootfs ")
-  (let ((rootfs-control (bind-root (resume-translator rootfs-server-task
+  (set! rootfs-control (bind-root (resume-translator rootfs-server-task '())))
+  (log "/servers/exec ")
+  (bind "/servers/exec" (resume-translator exec-server-task '())))
+
+(define (first-stage rootfs-device)
+  (set! exec-server-task (task-create mach-task-self 0))
+  (let
+   ((rootfs-args
+     `("rootfs"
+       ,(make-arg "host-priv-port" rootfs-server-task host-priv)
+       ,(make-arg "device-master-port" rootfs-server-task device-master)
+       ,(make-arg "exec-server-task" rootfs-server-task exec-server-task)
+       "-T" "typed" ,(string-append "device:" rootfs-device))))
+   (log "rootfs ")
+   (set! rootfs-control (bind-root (resume-translator rootfs-server-task
 						      rootfs-args)))
-	(startup-control (mach-port-allocate mach-task-self
-					     MACH_PORT_RIGHT_RECEIVE))
-	(proc-task (task-create mach-task-self 0))
-	(auth-task (task-create mach-task-self 0))
-	;; Projections for the cookies returned by bootstrap-*.
-	(:reply car) (:replyPoly cadr) (:server caddr))
+   (log "/servers/exec ")
+   (task-set-name exec-server-task "/hurd/exec")
+   (task-suspend exec-server-task)
+   (elf-exec exec-server-task
+	     `("/lib/ld.so.1" "/hurd/exec"
+	       ,(make-arg "device-master-port" exec-server-task device-master)))
+   (bind "/servers/exec" (resume-translator exec-server-task '()))))
+
+(define (early-startup)
+  (let ((startup-control (mach-port-allocate mach-task-self
+					     MACH_PORT_RIGHT_RECEIVE)))
     (start-handling-early-startup startup-control)
     (set-active-translator "/servers/startup" 0 0
-			   (make-send-right startup-control))
-    (log "exec ")
-    (bind "/servers/exec" (resume-translator exec-server-task exec-args))
+			   (make-send-right startup-control))))
+
+(define (second-stage)
+  (letport
+   ((proc-task (task-create mach-task-self 0))
+    (auth-task (task-create mach-task-self 0)))
 
     ;; Starting proc and auth is tricky, we need to do it simultaneously.
     (let ((pc (bootstrap-proc (start-translator proc-task '("/hurd/proc"))))
-	  (ac (bootstrap-auth (start-translator auth-task '("/hurd/auth")))))
+	  (ac (bootstrap-auth (start-translator auth-task '("/hurd/auth"))))
+	  ;; Projections for the cookies returned by bootstrap-*.
+	  (:reply car) (:replyPoly cadr) (:server caddr))
       (log "proc ")
       (startup-procinit-reply (:reply pc) (:replyPoly pc) ESUCCESS
 			      mach-task-self (:server ac)
@@ -159,26 +197,94 @@
       ;; Supply the proc server with a standard template.
       (proc->auth->set-std-execdata! (:server pc) (:server ac))
 
+      ;; Neither the kernel nor our bootscript task have command line
+      ;; arguments.  Fix that.
+      (frob-task (proc->pid->task (:server pc) 3)
+			   '(gnumach huhu lala XXX))
+      (if (mach-port-valid? bootscript-task)
+	  (frob-task bootscript-task '(/hurd/runsystem.scm)))
+      (frob-task mach-task-self '(/hurd/bootshell))
+
       (mach-port-deallocate mach-task-self (:server pc))
-      (mach-port-deallocate mach-task-self (:server ac))))
+      (mach-port-deallocate mach-task-self (:server ac)))))
+
+(define (run argv)
+  (letport ((proc (getproc))
+	    (task (task-create mach-task-self 0))
+	    (child-proc (proc->task->proc proc task)))
+	   (task-set-name task (car argv))
+	   (_exec (file-name-lookup (car argv) O_EXEC 0)
+		  task argv MACH_PORT_NULL)
+	   (proc->mark-exec! child-proc)
+	   (proc->mark-important! child-proc)
+	   (proc->task->child! proc task)
+	   (copy-send-right task)))
+
+(define (start-hurd-console)
+  (log "hurd-console ")
+  (throw 'notyet) ;; XXX
+  (run '(/bin/console
+	 --driver-path=/usr/lib/hurd/console ;; XXX
+	 --driver=current_vcs
+	 --driver=vga
+	 --driver=pc_kbd --keymap us
+	 --driver=pc_mouse --protocol=ps/2
+	 /dev/vcs))
+
+  ;; XXX
+  (symlink 'tty1 '/dev/console)
+  "/dev/tty1")
+
+(define (start-mach-console)
+  (start-active-translator '/dev/console
+			   '(/hurd/term /dev/console device console))
+  "/dev/console")
 
-  (log "console ")
-  (bind "/dev/console"
-	(start-translator (task-create mach-task-self 0)
-			  '("/hurd/term" "/dev/console" "device" "console")))
+(define (start-terminal)
+  ;; XXX
+  ;;(start-mach-console)
+  (let ((device (catch (begin (log "failed: ")
+			      (log last-exception)
+			      (start-mach-console))
+		       (start-hurd-console))))
+    (letport ((term (file-name-lookup device O_RDWR 0)))
+	     (bind-term term))
 
-  (letport ((term (file-name-lookup "/dev/console" O_RDWR 0)))
-	   (bind-term term))
+    ;; If we got the Hurd console running, it erased the screen.
+    (if (string=? device "/dev/tty1")
+	(begin
+	  (cat "/issue")
+	  (replay-log))))
 
   ;; If we made it this far, we can use libreadline!
-  (enable-readline)
+  (enable-readline))
 
+(define (run-stage stage)
+  (stage))
+
+(define (run-init argv)
+  (letport ((proc (getproc))
+	    (task (task-create mach-task-self 0))
+	    (child-proc (proc->task->proc proc task)))
+	   (proc->task->set-init-task! proc task)
+	   (task-set-name task (car argv))
+
+	   ;; XXX this is roughly what console-run does
+	   ;;(tcsetpgrp 0 (proc->task->pid proc task))
+	   ;;(proc->setsid! child-proc)
+	   ;;(proc->make-login-coll! child-proc)
+
+	   (proc->mark-exec! child-proc)
+	   (proc->mark-important! child-proc)
+	   (proc->task->child! child-proc mach-task-self)
+	   (_exec (file-name-lookup (car argv) O_EXEC 0)
+		  task argv MACH_PORT_NULL)
+	   (copy-send-right task)))
+
+(define (startup-standalone)
   ;; The standalone startup server watches essential servers, and
   ;; handles the system shutdown.
-  (log "startup ")
-  (bind "/servers/startup"
-	(start-translator (task-create mach-task-self 0)
-			  '("/hurd/startup-standalone")))
+  (start-active-translator '/servers/startup '(/hurd/startup-standalone))
 
   ;; Now that we have startup, register all servers to it.
   (letport
@@ -193,19 +299,47 @@
 	  (get-essential-tasks))
      (map (lambda (c)
 	    (startup-request-notification startup (:port c) (:name c)))
-	  (get-registered-tasks))))
-
-  (log "pflocal ")
-  (bind "/servers/socket/1"
-	(start-translator (task-create mach-task-self 0)
-			  '("/hurd/pflocal")))
+	  (get-registered-tasks)))))
 
+(define (bootstrap stages)
+  (log "Hurd server bootstrap: ")
+  (for-each run-stage stages)
   (log "done.\n"))
 
-(define (boot)
+(define (boot!)
+  (run-init '(/sbin/console-run --console=/dev/console -- /sbin/init -a)))
+
+(define (boot-demo . args)
   (catch (panic "Hurd bootstrap failed: " (car last-exception) "\n")
-	 (bootstrap '() '()))
+	 (apply bootstrap args))
+
+  (shell
+   (lambda (prefix)
+     (prompt-append-prefix
+      (string-append "runsystem@" (hostname) " " (getcwd) " ") prefix))))
+
+(define (traditional-boot)
+  (boot-demo (list traditional-first-stage
+		   early-startup
+		   second-stage
+		   make-essential-devices ;; b/c livecd
+		   start-terminal
+		   startup-standalone
+		   boot!)))
+
+(define (boot)
+  (let* ((disks
+	  (filter devprobe? '("hd0s1" "hd1" "hd2" "hd3" "sd0" "sd1" "sd2" "sd3")))
+	 (rootfs-device (car disks)))
+
+    (echo "Devices discovered: "
+	  (filter devprobe? '("hd0" "hd1" "hd2" "hd3" "sd0" "console" "eth0"))
+	  ". Root device: " rootfs-device ".")
 
-  (shell (lambda (prefix)
-	   (prompt-append-prefix
-	    (string-append "runsystem@" (hostname) " " (getcwd) " ") prefix))))
+    (boot-demo (list
+		(lambda () (first-stage rootfs-device))
+		early-startup
+		second-stage
+		start-terminal
+		startup-standalone
+		boot!))))
-- 
2.1.4