Browse Source

Can start a Linux kernel directly (albeit with no initrd support)

tags/v0.9.3
Michael Brown 18 years ago
parent
commit
97a3037f76
1 changed files with 29 additions and 8 deletions
  1. 29
    8
      src/arch/i386/image/bzimage.c

+ 29
- 8
src/arch/i386/image/bzimage.c View File

35
 
35
 
36
 struct image_type bzimage_image_type __image_type ( PROBE_NORMAL );
36
 struct image_type bzimage_image_type __image_type ( PROBE_NORMAL );
37
 
37
 
38
+/**
39
+ * bzImage execution context
40
+ */
41
+union bzimage_exec_context {
42
+	/** Real-mode parameters */
43
+	struct {
44
+		/** Kernel real-mode data segment */
45
+		uint16_t kernel_seg;
46
+		/** Kernel real-mode stack pointer */
47
+		uint16_t stack;
48
+	} rm;
49
+	unsigned long ul;
50
+};
51
+
38
 /**
52
 /**
39
  * Execute bzImage image
53
  * Execute bzImage image
40
  *
54
  *
42
  * @ret rc		Return status code
56
  * @ret rc		Return status code
43
  */
57
  */
44
 static int bzimage_exec ( struct image *image ) {
58
 static int bzimage_exec ( struct image *image ) {
45
-	unsigned long rm_kernel_seg = image->priv.ul;
59
+	union bzimage_exec_context context;
60
+
61
+	/* Retrieve stored execution context */
62
+	context.ul = image->priv.ul;
46
 
63
 
47
 	/* Prepare for exiting */
64
 	/* Prepare for exiting */
48
 	shutdown();
65
 	shutdown();
57
 					   "pushw %w2\n\t"
74
 					   "pushw %w2\n\t"
58
 					   "pushw $0\n\t"
75
 					   "pushw $0\n\t"
59
 					   "lret\n\t" )
76
 					   "lret\n\t" )
60
-			       : : "r" ( rm_kernel_seg ),
61
-			           "i" ( BZI_STACK_SIZE ),
62
-			           "r" ( rm_kernel_seg + 0x20 ) );
77
+			       : : "r" ( context.rm.kernel_seg ),
78
+			           "r" ( context.rm.stack ),
79
+			           "r" ( context.rm.kernel_seg + 0x20 ) );
63
 
80
 
64
 	/* There is no way for the image to return, since we provide
81
 	/* There is no way for the image to return, since we provide
65
 	 * no return address.
82
 	 * no return address.
66
 	 */
83
 	 */
84
+	assert ( 0 );
67
 
85
 
68
 	return -ECANCELED; /* -EIMPOSSIBLE */
86
 	return -ECANCELED; /* -EIMPOSSIBLE */
69
 }
87
 }
76
  */
94
  */
77
 int bzimage_load ( struct image *image ) {
95
 int bzimage_load ( struct image *image ) {
78
 	struct bzimage_header bzhdr;
96
 	struct bzimage_header bzhdr;
79
-	unsigned int rm_kernel_seg = 0x7c0; /* place RM kernel at 07c0:0000 */
97
+	union bzimage_exec_context context;
98
+	unsigned int rm_kernel_seg = 0x1000; /* place RM kernel at 1000:0000 */
80
 	userptr_t rm_kernel = real_to_user ( rm_kernel_seg, 0 );
99
 	userptr_t rm_kernel = real_to_user ( rm_kernel_seg, 0 );
81
 	userptr_t pm_kernel;
100
 	userptr_t pm_kernel;
82
 	size_t rm_filesz;
101
 	size_t rm_filesz;
115
 	DBGC ( image, "bzImage %p version %04x\n", image, bzhdr.version );
134
 	DBGC ( image, "bzImage %p version %04x\n", image, bzhdr.version );
116
 
135
 
117
 	/* Check size of base memory portions */
136
 	/* Check size of base memory portions */
118
-	rm_filesz = ( ( bzhdr.setup_sects ? bzhdr.setup_sects : 4 ) << 9 );
137
+	rm_filesz = ( ( bzhdr.setup_sects ? bzhdr.setup_sects : 4 ) + 1 ) << 9;
119
 	if ( rm_filesz > image->len ) {
138
 	if ( rm_filesz > image->len ) {
120
 		DBGC ( image, "bzImage %p too short for %zd byte of setup\n",
139
 		DBGC ( image, "bzImage %p too short for %zd byte of setup\n",
121
 		       image, rm_filesz );
140
 		       image, rm_filesz );
177
 	}
196
 	}
178
 	copy_to_user ( rm_kernel, BZI_HDR_OFFSET, &bzhdr, sizeof ( bzhdr ) );
197
 	copy_to_user ( rm_kernel, BZI_HDR_OFFSET, &bzhdr, sizeof ( bzhdr ) );
179
 
198
 
180
-	/* Record segment address in image private data field */
181
-	image->priv.ul = rm_kernel_seg;
199
+	/* Record execution context in image private data field */
200
+	context.rm.kernel_seg = rm_kernel_seg;
201
+	context.rm.stack = rm_heap_end;
202
+	image->priv.ul = context.ul;
182
 
203
 
183
 	return 0;
204
 	return 0;
184
 }
205
 }

Loading…
Cancel
Save