Browse Source

First versions

tags/v0.9.3
Michael Brown 19 years ago
parent
commit
58ee2c4b2e
2 changed files with 74 additions and 0 deletions
  1. 49
    0
      src/core/image.c
  2. 25
    0
      src/include/image.h

+ 49
- 0
src/core/image.c View File

@@ -0,0 +1,49 @@
1
+#include "buffer.h"
2
+#include "image.h"
3
+
4
+static struct image images_start[0] __image_start;
5
+static struct image images_end[0] __image_end;
6
+
7
+/*
8
+ * Identify the image format
9
+ *
10
+ */
11
+static struct image * identify_image ( struct buffer *buffer ) {
12
+	struct image_header header;
13
+	int header_len = sizeof ( header );
14
+	off_t len;
15
+	struct image *image;
16
+	
17
+	/* Copy first (up to) 512 bytes of image to easily-accessible
18
+	 * buffer.
19
+	 */
20
+	len = buffer->fill;
21
+	copy_from_phys ( &header, buffer->start,
22
+			 len < header_len ? len : header_len );
23
+	
24
+	for ( image = images_start ; image < images_end ; image++ ) {
25
+		if ( image->probe ( &header, len ) )
26
+			return image;
27
+	}
28
+	
29
+	return NULL;
30
+}
31
+
32
+/*
33
+ * Boot a loaded image
34
+ *
35
+ */
36
+int boot_image ( struct buffer *buffer ) {
37
+	struct image *image;
38
+
39
+	image = identify_image ( buffer );
40
+	if ( ! image ) {
41
+		DBG ( "IMAGE could not identify image format\n" );
42
+		return 0;
43
+	}
44
+
45
+	DBG ( "IMAGE found %s image (length %d)\n",
46
+	      image->name, buffer->fill );
47
+
48
+	return image->boot ( buffer->start, buffer->fill );
49
+}

+ 25
- 0
src/include/image.h View File

@@ -0,0 +1,25 @@
1
+#ifndef IMAGE_H
2
+#define IMAGE_H
3
+
4
+#include "stdint.h"
5
+#include "io.h"
6
+#include "tables.h"
7
+
8
+#define IMAGE_HEADER_SIZE 512
9
+
10
+struct image_header {
11
+	char data[IMAGE_HEADER_SIZE];
12
+};
13
+
14
+struct image {
15
+	char *name;
16
+	int ( * probe ) ( struct image_header *header, off_t len );
17
+	int ( * boot ) ( physaddr_t start, off_t len );
18
+};
19
+
20
+#define __image_start		__table_start(image)
21
+#define __image			__table(image,01)
22
+#define __default_image		__table(image,02)
23
+#define __image_end		__table_end(image)
24
+
25
+#endif /* IMAGE_H */

Loading…
Cancel
Save