メモリ管理を追加!
@@ -7,29 +7,38 @@ | ||
7 | 7 | struct VESAINFO *vinfo = (struct VESAINFO *) ADR_VESAINFO; |
8 | 8 | struct FIFO32 sysfifo; |
9 | 9 | struct MOUSE_DECODE mdec; |
10 | + struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; | |
10 | 11 | int fifobuf[256], i = 0,time_tick,mx = binfo->scrnx / 2, my = binfo->scrny / 2; |
11 | 12 | unsigned int all_mem_size = memtest(0x00400000, 0xbffffffff); |
13 | + unsigned int free_mem_size = 0; | |
12 | 14 | init_gdtidt(); |
13 | 15 | init_pic(); |
14 | - init_pit(&time_tick); | |
15 | - | |
16 | 16 | io_sti(); |
17 | 17 | |
18 | + memman_init(memman); | |
19 | + memman_free(0x00001000,0x0009e000); | |
20 | + memman_free(0x00400000,all_mem_size - 0x00400000); | |
18 | 21 | init_scrn_i(vinfo->PhysBasePtr, binfo->scrnx, binfo->scrny, vinfo->BitsPerPixel); |
19 | 22 | fifo32_init(&sysfifo, 256, fifobuf); |
20 | 23 | init_keyboard(&sysfifo, SYSFIFO_KEYB); |
21 | 24 | init_mouse(&sysfifo, SYSFIFO_MOUSE, &mdec); |
25 | + init_pit(&time_tick); | |
22 | 26 | pit_beep_off(); |
23 | 27 | |
28 | + | |
24 | 29 | sprintf(s,"memory %d Byte(%d KB,%d MB)",all_mem_size,all_mem_size/1024, all_mem_size/(1024*1024)); |
25 | 30 | boxfill_i(vinfo->PhysBasePtr, binfo->scrnx, 0x000000, 0,304,INT_MONITOR_LONG,320); |
26 | 31 | putfonts_asc_i(vinfo->PhysBasePtr, binfo->scrnx, 0,304,0xffffff,s); |
27 | - | |
28 | - | |
29 | 32 | |
30 | 33 | for (;;){ |
31 | 34 | io_cli(); |
32 | 35 | if(fifo32_status(&sysfifo) == 0) { |
36 | + | |
37 | + free_mem_size = memman_free_total(); | |
38 | + sprintf(s,"free %d Byte(%d KB,%d MB)",free_mem_size,free_mem_size/1024, free_mem_size/(1024*1024)); | |
39 | + boxfill_i(vinfo->PhysBasePtr, binfo->scrnx, 0x000000, 0,320,INT_MONITOR_LONG,336); | |
40 | + putfonts_asc_i(vinfo->PhysBasePtr, binfo->scrnx, 0,320,0xffffff,s); | |
41 | + | |
33 | 42 | io_stihlt(); |
34 | 43 | } else { |
35 | 44 | i = fifo32_get(&sysfifo); |
@@ -1,5 +1,6 @@ | ||
1 | 1 | #include "core.h" |
2 | 2 | |
3 | +struct MEMMAN *man; | |
3 | 4 | |
4 | 5 | unsigned int memtest(unsigned int start, unsigned int end) |
5 | 6 | { |
@@ -28,3 +29,89 @@ | ||
28 | 29 | return i; |
29 | 30 | |
30 | 31 | } |
32 | + | |
33 | +void memman_init(struct MEMMAN *man0) | |
34 | +{ | |
35 | + man = man0; | |
36 | + man->frees = 0; | |
37 | + man->maxfrees = 0; | |
38 | + man->lostsize = 0; | |
39 | + man->losts = 0; | |
40 | + return; | |
41 | +} | |
42 | + | |
43 | +unsigned int memman_free_total(void) | |
44 | +{ | |
45 | + unsigned int i,t = 0; | |
46 | + for (i = 0; i < man->frees; i++) { | |
47 | + t += man->free[i].size; | |
48 | + } | |
49 | + return t; | |
50 | +} | |
51 | + | |
52 | +unsigned int memman_alloc(unsigned int size) | |
53 | +{ | |
54 | + unsigned int i,a; | |
55 | + for(i = 0; i < man->frees; i++) { | |
56 | + if (man->free[i].size >= size) { | |
57 | + a = man->free[i].addr; | |
58 | + man->free[i].addr += size; | |
59 | + man->free[i].size -= size; | |
60 | + if(man->free[i].size == 0) { | |
61 | + man->frees--; | |
62 | + for (; i < man->frees; i++) { | |
63 | + man->free[i] = man->free[i+1]; | |
64 | + } | |
65 | + } | |
66 | + return a; | |
67 | + } | |
68 | + } | |
69 | + return 0; | |
70 | +} | |
71 | + | |
72 | +int memman_free(unsigned int addr, unsigned int size) | |
73 | +{ | |
74 | + int i, j; | |
75 | + for(i = 0; i < man->frees; i++){ | |
76 | + if(man->free[i].addr > addr) break; | |
77 | + } | |
78 | + if(i > 0) { | |
79 | + if(man->free[i-1].addr + man->free[i-1].size == addr){ | |
80 | + man->free[i-1].size += size; | |
81 | + if(i < man->frees){ | |
82 | + if(addr + size == man->free[i].addr){ | |
83 | + man->free[i-1].size += man->free[i].size; | |
84 | + man->frees--; | |
85 | + for (;i < man->frees; i++){ | |
86 | + man->free[i] = man->free[i+1]; | |
87 | + } | |
88 | + } | |
89 | + } | |
90 | + return 0; | |
91 | + } | |
92 | + } | |
93 | + if(i < man->frees){ | |
94 | + if(addr + size == man->free[i].addr){ | |
95 | + man->free[i].addr = addr; | |
96 | + man->free[i].size += size; | |
97 | + return 0; | |
98 | + } | |
99 | + } | |
100 | + if(man->frees < MEMMAN_FREES){ | |
101 | + for(j = man->frees;j>i;j--) { | |
102 | + man->free[j] = man->free[j-1]; | |
103 | + | |
104 | + } | |
105 | + man->frees++; | |
106 | + if(man->maxfrees < man->frees) man->maxfrees = man->frees; | |
107 | + man->free[i].addr = addr; | |
108 | + man->free[i].size = size; | |
109 | + return 0; | |
110 | + | |
111 | + } | |
112 | + man->losts++; | |
113 | + man->lostsize += size; | |
114 | + return -1; | |
115 | +} | |
116 | + | |
117 | + |
@@ -6,75 +6,7 @@ | ||
6 | 6 | |
7 | 7 | #define RGB16(r,g,b) ((r)<<11|(g)<<5|(b)) |
8 | 8 | |
9 | -/*構造体宣言*/ | |
10 | 9 | |
11 | -struct FIFO32 { | |
12 | - unsigned int *buf; | |
13 | - int p, q, size, free, flags; | |
14 | -}; | |
15 | - | |
16 | -struct MOUSE_DECODE { | |
17 | - unsigned int buf[3]; | |
18 | - int x,y,btn; | |
19 | - unsigned char phase; | |
20 | - | |
21 | -}; | |
22 | - | |
23 | -struct BOOTINFO { /* 0x0ff0-0x0fff 標準*/ | |
24 | - char cyls; /* ブートセクタはどこまでディスクを読んだのか */ | |
25 | - char leds; /* ブート時のキーボードのLEDの状態 */ | |
26 | - char vmode; /* ビデオモード 何ビットカラーか */ | |
27 | - char reserve; | |
28 | - short scrnx, scrny; /* 画面解像度 */ | |
29 | - char *vram; | |
30 | -}; | |
31 | - | |
32 | -struct VESAINFO {/*0xe00--->512byte 標準*/ | |
33 | - unsigned short ModeAttributes; | |
34 | - unsigned char WinAAttributes; | |
35 | - unsigned char WinBAttributes; | |
36 | - unsigned short WinGranularity; | |
37 | - unsigned short WinSize; | |
38 | - unsigned short WinASegment; | |
39 | - unsigned short WinBSegment; | |
40 | - unsigned int WinFuncPtr; | |
41 | - unsigned short BytesPerScanLine; | |
42 | - unsigned short XResolution; | |
43 | - unsigned short YResolution; | |
44 | - unsigned char XCharSize; | |
45 | - unsigned char YCharSize; | |
46 | - unsigned char NumberOfPlanes; | |
47 | - unsigned char BitsPerPixel; | |
48 | - unsigned char NumberOfBanks; | |
49 | - unsigned char MemoryModel; | |
50 | - unsigned char BankSize; | |
51 | - unsigned char NumberOfImagePages; | |
52 | - unsigned char Reserved; | |
53 | - unsigned char RedMaskSize; | |
54 | - unsigned char RedFieldPosition; | |
55 | - unsigned char GreenMaskSize; | |
56 | - unsigned char GreenFieldPosition; | |
57 | - unsigned char BlueMaskSize; | |
58 | - unsigned char BlueFieldPosition; | |
59 | - unsigned char RsvdMaskSize; | |
60 | - unsigned char RsvdFieldPodition; | |
61 | - unsigned char DirectColorModeInfo; | |
62 | - unsigned int *PhysBasePtr; | |
63 | -}; | |
64 | - | |
65 | -struct SEGMENT_DESCRIPTOR { /*0x270000~0x27ffff 標準*/ | |
66 | - short limit_low,base_low; | |
67 | - char base_mid,access_right; | |
68 | - char limit_high,base_high; | |
69 | -}; | |
70 | -struct GATE_DESCRIPTOR { /*0x26f800~0x26ffff 標準*/ | |
71 | - short offset_low,selector; | |
72 | - char dw_count,access_right; | |
73 | - short offset_high; | |
74 | -}; | |
75 | - | |
76 | - | |
77 | - | |
78 | 10 | /*設定数値の定義*/ |
79 | 11 | |
80 | 12 | #define ADR_BOOTINFO 0x00000ff0 |
@@ -122,8 +54,11 @@ | ||
122 | 54 | #define MOUSECMD_ENABLE 0xf4 |
123 | 55 | |
124 | 56 | #define EFLAGS_AC_BIT 0x00040000 |
125 | -#define CR0_CACHE_DISABLE 0x60000000 | |
57 | +#define CR0_CACHE_DISABLE 0x60000000 | |
126 | 58 | |
59 | +#define MEMMAN_FREES 4090 | |
60 | +#define MEMMAN_ADDR 0x003c0000 | |
61 | + | |
127 | 62 | #define SYSFIFO_KEYB 0x100 /*256~511=keycode*/ |
128 | 63 | #define SYSFIFO_MOUSE 0x200 /*512~767=mouse*/ |
129 | 64 |
@@ -160,6 +95,91 @@ | ||
160 | 95 | #define COL8_848484 15 |
161 | 96 | |
162 | 97 | |
98 | + | |
99 | +/*構造体宣言*/ | |
100 | + | |
101 | +struct MEM_FREEINFO { | |
102 | + unsigned int addr, size; | |
103 | +}; | |
104 | + | |
105 | +struct MEMMAN { | |
106 | + int frees,maxfrees,lostsize,losts; | |
107 | + struct MEM_FREEINFO free[MEMMAN_FREES]; | |
108 | +}; | |
109 | + | |
110 | +struct SHEET32 { | |
111 | + unsigned int *buf; | |
112 | + int bxsize,bysize,vx0,vy0,col_inv,height,flags; | |
113 | +}; | |
114 | + | |
115 | +struct FIFO32 { | |
116 | + unsigned int *buf; | |
117 | + int p, q, size, free, flags; | |
118 | +}; | |
119 | + | |
120 | +struct MOUSE_DECODE { | |
121 | + unsigned int buf[3]; | |
122 | + int x,y,btn; | |
123 | + unsigned char phase; | |
124 | + | |
125 | +}; | |
126 | + | |
127 | +struct BOOTINFO { /* 0x0ff0-0x0fff 標準*/ | |
128 | + char cyls; /* ブートセクタはどこまでディスクを読んだのか */ | |
129 | + char leds; /* ブート時のキーボードのLEDの状態 */ | |
130 | + char vmode; /* ビデオモード 何ビットカラーか */ | |
131 | + char reserve; | |
132 | + short scrnx, scrny; /* 画面解像度 */ | |
133 | + char *vram; | |
134 | +}; | |
135 | + | |
136 | +struct VESAINFO {/*0xe00--->512byte 標準*/ | |
137 | + unsigned short ModeAttributes; | |
138 | + unsigned char WinAAttributes; | |
139 | + unsigned char WinBAttributes; | |
140 | + unsigned short WinGranularity; | |
141 | + unsigned short WinSize; | |
142 | + unsigned short WinASegment; | |
143 | + unsigned short WinBSegment; | |
144 | + unsigned int WinFuncPtr; | |
145 | + unsigned short BytesPerScanLine; | |
146 | + unsigned short XResolution; | |
147 | + unsigned short YResolution; | |
148 | + unsigned char XCharSize; | |
149 | + unsigned char YCharSize; | |
150 | + unsigned char NumberOfPlanes; | |
151 | + unsigned char BitsPerPixel; | |
152 | + unsigned char NumberOfBanks; | |
153 | + unsigned char MemoryModel; | |
154 | + unsigned char BankSize; | |
155 | + unsigned char NumberOfImagePages; | |
156 | + unsigned char Reserved; | |
157 | + unsigned char RedMaskSize; | |
158 | + unsigned char RedFieldPosition; | |
159 | + unsigned char GreenMaskSize; | |
160 | + unsigned char GreenFieldPosition; | |
161 | + unsigned char BlueMaskSize; | |
162 | + unsigned char BlueFieldPosition; | |
163 | + unsigned char RsvdMaskSize; | |
164 | + unsigned char RsvdFieldPodition; | |
165 | + unsigned char DirectColorModeInfo; | |
166 | + unsigned int *PhysBasePtr; | |
167 | +}; | |
168 | + | |
169 | +struct SEGMENT_DESCRIPTOR { /*0x270000~0x27ffff 標準*/ | |
170 | + short limit_low,base_low; | |
171 | + char base_mid,access_right; | |
172 | + char limit_high,base_high; | |
173 | +}; | |
174 | +struct GATE_DESCRIPTOR { /*0x26f800~0x26ffff 標準*/ | |
175 | + short offset_low,selector; | |
176 | + char dw_count,access_right; | |
177 | + short offset_high; | |
178 | +}; | |
179 | + | |
180 | +/*関数宣言*/ | |
181 | + | |
182 | + | |
163 | 183 | /*bootpack.c OSメイン*/ |
164 | 184 | |
165 | 185 | /*io.c その他外部装置関係*/ |
@@ -173,7 +193,12 @@ | ||
173 | 193 | |
174 | 194 | /*memory.c メモリ管理関係*/ |
175 | 195 | unsigned int memtest(unsigned int start, unsigned int end); |
196 | +void memman_init(struct MEMMAN *man); | |
197 | +unsigned int memman_free_total(void); | |
198 | +unsigned int memman_alloc(unsigned int size); | |
199 | +int memman_free(unsigned int addr, unsigned int size); | |
176 | 200 | |
201 | + | |
177 | 202 | /*keyboard.c キーボード関係*/ |
178 | 203 | void init_keyboard(struct FIFO32 *fifo, int data0); |
179 | 204 | void inthandler21(int *esp); |