Skip to content

Commit 9d39ff1

Browse files
author
Yuma Arakawa
committed
fs: fs_init追加
1 parent aab20ae commit 9d39ff1

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

kernel/include/memory.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef __MEMORY_H__
22
#define __MEMORY_H__
33

4+
#define PAGE_SIZE 0x1000
5+
46
struct page_directory_entry {
57
union {
68
struct {

kernel/main.c

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,25 @@
99
#include <kern_task.h>
1010
#include <shell_init.h>
1111
#include <uptime_init.h>
12+
#include <list.h>
13+
#include <queue.h>
1214

1315
#define GDT_IDX_OFS 3
1416
#define APP_ENTRY_POINT 0x20000020
1517
#define APP_STACK_BASE 0x20002000
1618

19+
struct file_head {
20+
struct list lst;
21+
unsigned char num_files;
22+
} fhead;
23+
24+
struct file {
25+
struct list lst;
26+
unsigned int fid;
27+
char *name;
28+
void *data_base_addr;
29+
} fshell, fuptime;
30+
1731
void kern_lock(unsigned char *if_bit)
1832
{
1933
/* Save EFlags.IF */
@@ -168,6 +182,38 @@ static void task_init(unsigned short task_id, unsigned int phys_binary_base)
168182
sched_runq_enq(new_task);
169183
}
170184

185+
void fs_init(void *fs_base_addr)
186+
{
187+
queue_init((struct list *)&fhead);
188+
fhead.num_files = *(unsigned char *)fs_base_addr;
189+
190+
fshell.fid = 1;
191+
fshell.name = (char *)fs_base_addr + PAGE_SIZE;
192+
fshell.data_base_addr = (char *)fs_base_addr + PAGE_SIZE + 32;
193+
queue_enq((struct list *)&fshell, (struct list *)&fhead);
194+
195+
fuptime.fid = 2;
196+
fuptime.name = (char *)fs_base_addr + (PAGE_SIZE * 2);
197+
fuptime.data_base_addr = (char *)fs_base_addr + (PAGE_SIZE * 2) + 32;
198+
queue_enq((struct list *)&fuptime, (struct list *)&fhead);
199+
}
200+
201+
int fs_open(const char *name)
202+
{
203+
/* 将来的には、struct fileのtask_idメンバにopenしたタスクの
204+
* TASK_IDを入れるようにする。そして、openしようとしているファ
205+
* イルのtask_idが既に設定されていれば、fs_openはエラーを返す
206+
* ようにする */
207+
return 0;
208+
}
209+
210+
int fs_close(unsigned int fid)
211+
{
212+
/* 将来的には、fidに対応するstruct fileのtask_idメンバーを設定
213+
* なし(0)にする。 */
214+
return 0;
215+
}
216+
171217
int main(void)
172218
{
173219
extern unsigned char syscall_handler;
@@ -208,10 +254,13 @@ int main(void)
208254
timer_init();
209255
mem_init();
210256

257+
/* Setup File System */
258+
fs_init((void *)0x00011000);
259+
211260
/* Setup tasks */
212261
kern_task_init();
213-
task_init(SHELL_ID, 0x00012000);
214-
task_init(UPTIME_ID, 0x00013000);
262+
task_init(SHELL_ID, (unsigned int)fshell.name);
263+
task_init(UPTIME_ID, (unsigned int)fuptime.name);
215264

216265
/* Start paging */
217266
mem_page_start();

kernel/memory.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#define CR4_BIT_PGE (1U << 7)
55
#define MAX_HEAP_PAGES 11
66
#define HEAP_START_ADDR 0x00095000
7-
#define PAGE_SIZE 0x1000
87

98
static char heap_alloc_table[MAX_HEAP_PAGES] = {0};
109

0 commit comments

Comments
 (0)