source: mainline/uspace/rd/rd.c@ ea7890e7

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since ea7890e7 was ff3a34b, checked in by Martin Decky <martin@…>, 18 years ago

initial merge of branches/fs
(not finished, huge cleanup is needed)

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 * Copyright (c) 2007 Michal Konopa
3 * Copyright (c) 2007 Martin Jelen
4 * Copyright (c) 2007 Peter Majer
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * - The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/** @addtogroup rd
32 * @{
33 */
34
35/**
36 * @file rd.c
37 * @brief Initial RAM disk for HelenOS.
38 */
39
40#include <ipc/ipc.h>
41#include <ipc/services.h>
42#include <ipc/ns.h>
43#include <sysinfo.h>
44#include <as.h>
45#include <ddi.h>
46#include <align.h>
47#include <bool.h>
48#include <errno.h>
49#include <async.h>
50#include <stdlib.h>
51#include <unistd.h>
52#include <align.h>
53#include <async.h>
54#include <ddi.h>
55#include <libarch/ddi.h>
56#include <stdio.h>
57#include "rd.h"
58
59static void *rd_addr;
60static void *fs_addr;
61
62static void rd_connection(ipc_callid_t iid, ipc_call_t *icall)
63{
64 ipc_callid_t callid;
65 ipc_call_t call;
66 int retval;
67
68 ipc_answer_fast(iid, 0, 0, 0);
69 ipcarg_t offset;
70
71 while (1) {
72 callid = async_get_call(&call);
73 switch (IPC_GET_METHOD(call)) {
74 case IPC_M_PHONE_HUNGUP:
75 ipc_answer_fast(callid, 0,0,0);
76 return;
77 case IPC_M_AS_AREA_SEND:
78 ipc_answer_fast(callid, 0, (uintptr_t)fs_addr, 0);
79 continue;
80 case RD_READ_BLOCK:
81 offset = IPC_GET_ARG1(call);
82 memcpy((void *)fs_addr, rd_addr+offset, BLOCK_SIZE);
83 retval = EOK;
84 break;
85 default:
86 retval = EINVAL;
87 }
88 ipc_answer_fast(callid, retval, 0, 0);
89 }
90}
91
92
93static bool rd_init(void)
94{
95 int retval, flags;
96
97 size_t rd_size = sysinfo_value("rd.size");
98 void * rd_ph_addr = (void *) sysinfo_value("rd.address.physical");
99
100 if (rd_size == 0)
101 return false;
102
103 rd_addr = as_get_mappable_page(rd_size);
104
105 flags = AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE;
106 retval = physmem_map(rd_ph_addr, rd_addr, ALIGN_UP(rd_size, PAGE_SIZE) >> PAGE_WIDTH, flags);
107
108 if (retval < 0)
109 return false;
110
111 size_t fs_size = ALIGN_UP(BLOCK_SIZE * sizeof(char), PAGE_SIZE);
112 fs_addr = as_get_mappable_page(fs_size);
113
114 return true;
115}
116
117int main(int argc, char **argv)
118{
119 if (rd_init()) {
120 ipcarg_t phonead;
121
122 async_set_client_connection(rd_connection);
123
124 /* Register service at nameserver */
125 if (ipc_connect_to_me(PHONE_NS, SERVICE_RD, 0, &phonead) != 0)
126 return -1;
127
128 async_manager();
129
130 /* Never reached */
131 return 0;
132 }
133
134 return -1;
135}
136
137/**
138 * @}
139 */
Note: See TracBrowser for help on using the repository browser.