- Initial checkin of the freebios2 tree
[coreboot.git] / src / stream / rom_stream.c
1 #include <console/console.h>
2 #include <stdlib.h>
3 #include <stddef.h>
4 #include <stream/read_bytes.h>
5 #include <string.h>
6
7
8 #ifndef CONFIG_ROM_STREAM_START
9 #define CONFIG_ROM_STREAM_START 0xffff0000UL
10 #endif
11
12 static const unsigned char *rom_start = (void *)CONFIG_ROM_STREAM_START;
13 static const unsigned char *rom_end   = (void *)(CONFIG_ROM_STREAM_START + PAYLOAD_SIZE - 1);
14 static const unsigned char *rom;
15
16 int stream_init(void)
17 {
18         rom = rom_start;
19
20         printk_spew("%6d:%s() - rom_stream: 0x%08lx - 0x%08lx\n"
21                 __LINE__, __FUNCTION__,
22                 (unsigned long)rom_start,
23                 (unsigned long)rom_end);
24         return 0;
25 }
26
27
28 void stream_fini(void)
29 {
30         return;
31 }
32
33 byte_offset_t stream_skip(byte_offset_t count)
34 {
35         byte_offset_t bytes;
36         bytes = count;
37         if ((rom + bytes) > rom_end) {
38                 printk_warning("%6d:%s() - overflowed source buffer\n",
39                         __LINE__, __FUNCTION__);
40                 bytes = 0;
41                 if (rom <= rom_end) {
42                         bytes = (rom_end - rom) + 1;
43                 }
44         }
45         rom += bytes;
46         return bytes;
47 }
48
49 byte_offset_t stream_read(void *vdest, byte_offset_t count)
50 {
51         unsigned char *dest = vdest;
52         const unsigned char *src = rom;
53         byte_offset_t bytes;
54
55         bytes = stream_skip(count);
56         memcpy(dest, src, bytes);
57         return bytes;
58 }