FreeNOS
BootImageStorage.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2009 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <FreeNOS/User.h>
19#include <MemoryBlock.h>
20#include "BootImageStorage.h"
21
23 : m_image(image != ZERO ? image : load())
24{
25}
26
28{
30 read(0, &header, sizeof(header));
31 return header;
32}
33
35{
36 if (m_image == ZERO)
37 {
39 }
40
41 if (m_image->magic[0] == BOOTIMAGE_MAGIC0 &&
44 {
46 }
47 else
48 {
49 ERROR("invalid BootImage: signature = " <<
50 m_image->magic[0] << ", " << m_image->magic[1] <<
51 " revision = " << m_image->layoutRevision);
53 }
54}
55
56FileSystem::Result BootImageStorage::read(const u64 offset, void *buffer, const Size size) const
57{
58 const u8 *data = ((const u8 *)(m_image)) + offset;
59 MemoryBlock::copy(buffer, data, size);
61}
62
67
69{
70 const SystemInformation info;
71 Memory::Range range;
72
73 // Request boot image memory
74 range.size = info.bootImageSize;
75 range.access = Memory::User |
77 range.virt = ZERO;
78 range.phys = info.bootImageAddress;
79
80 // Map BootImage into our address space
81 const API::Result r = VMCtl(SELF, MapContiguous, &range);
82 if (r != API::Success)
83 {
84 ERROR("failed to map BootImage using VMCtl: result = " << (int) r);
85 return ZERO;
86 }
87
88 return (const BootImage *) range.virt;
89}
SystemDescriptorHeader header
Definition IntelACPI.h:0
Result
Enumeration of generic kernel API result codes.
Definition API.h:69
@ Success
Definition API.h:70
const BootImage bootImage() const
Get BootImage header.
virtual FileSystem::Result initialize()
Initialize the Storage device.
virtual FileSystem::Result read(const u64 offset, void *buffer, const Size size) const
Reads data from the boot image.
const BootImage * load() const
Loads the BootImage into virtual memory.
const BootImage * m_image
Pointer to the BootImage.
virtual u64 capacity() const
Retrieve maximum storage capacity.
BootImageStorage(const BootImage *image=ZERO)
Constructor function.
static Size copy(void *dest, const void *src, Size count)
Copy memory from one place to another.
#define SELF
Definition ProcessID.h:35
API::Result VMCtl(const ProcessID procID, const MemoryOperation op, Memory::Range *range=ZERO)
Prototype for user applications.
Definition VMCtl.h:61
@ MapContiguous
Definition VMCtl.h:37
#define BOOTIMAGE_MAGIC0
First magic byte.
Definition BootImage.h:30
#define BOOTIMAGE_REVISION
Version of the boot image layout.
Definition BootImage.h:36
#define BOOTIMAGE_MAGIC1
Second magic byte.
Definition BootImage.h:33
#define ERROR(msg)
Output an error message.
Definition Log.h:61
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
#define ZERO
Zero value.
Definition Macros.h:43
unsigned long long u64
Unsigned 64-bit number.
Definition Types.h:50
unsigned char u8
Unsigned 8-bit number.
Definition Types.h:59
Result
Result code for filesystem Actions.
Definition FileSystem.h:53
@ InvalidArgument
Definition FileSystem.h:55
@ User
Definition Memory.h:44
@ Readable
Definition Memory.h:41
BootImage contains executable programs to be loaded at system bootup.
Definition BootImage.h:45
u32 magic[2]
Magic numbers to detect a valid boot image.
Definition BootImage.h:47
u8 layoutRevision
Version of the boot image layout.
Definition BootImage.h:50
u32 bootImageSize
Total size of the boot image in bytes.
Definition BootImage.h:53
Memory range.
Definition Memory.h:56
Size size
Size in number of bytes.
Definition Memory.h:59
Address phys
Physical address.
Definition Memory.h:58
Address virt
Virtual address.
Definition Memory.h:57
Access access
Page access flags.
Definition Memory.h:60
System information structure.
Definition SystemInfo.h:80
Address bootImageAddress
BootImage physical address.
Definition SystemInfo.h:108
Size bootImageSize
BootImage size.
Definition SystemInfo.h:111