• R/O
  • SSH
  • HTTPS

haribote: Commit


Commit MetaInfo

Revision204 (tree)
Time2010-03-06 15:17:49
Authortatsupc

Log Message

orbspace

Change Summary

Incremental Difference

--- haribote/trunk/orbspace/qemu/qemu-win.bat (revision 203)
+++ haribote/trunk/orbspace/qemu/qemu-win.bat (revision 204)
@@ -1,4 +1,4 @@
11 @set SDL_VIDEODRIVER=windib
22 @set QEMU_AUDIO_DRV=none
33 @set QEMU_AUDIO_LOG_TO_MONITOR=0
4-qemu.exe -L . -m 32 -localtime -std-vga -hda -hda ..\orbspace.img
\ No newline at end of file
4+qemu.exe -L . -m 32 -localtime -std-vga -hda ..\orbspace.img
\ No newline at end of file
--- haribote/trunk/orbspace/orbspace/main.c (revision 203)
+++ haribote/trunk/orbspace/orbspace/main.c (revision 204)
@@ -1,20 +1,27 @@
11 #include "main.h"
22 #include <stdio.h>
33
4-struct fifo sysfifo;
5-
64 void OrbMain(void)
75 {
8- struct bootinfo *binfo = (struct bootinfo *) 0x0ff0;
9- int fifobuf[128], i;
6+ struct bootinfo *binfo = (struct bootinfo *) BOOTINFO_ADDR;
7+ struct memory *memory = (struct memory *) MEMORY_ADDR;
8+ struct fifo *sysfifo = (struct fifo *) SYSFIFO_ADDR;
9+ int fifobuf[64], i;
1010 unsigned char s[3];
1111
12- fifo_init(&sysfifo, fifobuf, 128);
12+ memory_init(memory, 0x00200000, 0xbfffffff);
13+ memory_free(memory, 0x00001000, 0x00006c00);
14+ memory_free(memory, 0x00200000, memory->total - 0x00200000);
15+ fifo_init(sysfifo, fifobuf, 64);
16+
1317 idt_init();
1418
1519 for (i = 0; i < 1024 * 768; i++) {
1620 binfo->vram[i] = 0;
1721 }
22+ sprintf(s, "%7d / %7d KB", memory_stat(memory) / 1024,
23+ memory->total / 1024);
24+ graphic_puts(binfo->vram, 1024, 0, 16, 0xffffff, s);
1825
1926 outb(PIC0_IMR, 0xf9);
2027 outb(PIC1_IMR, 0xff);
@@ -22,10 +29,10 @@
2229
2330 for(;;) {
2431 cli();
25- if (!fifo_stat(&sysfifo)) {
32+ if (!fifo_stat(sysfifo)) {
2633 stihlt();
2734 } else {
28- i = fifo_pop(&sysfifo);
35+ i = fifo_pop(sysfifo);
2936 sti();
3037
3138 if (256 <= i && i <= 511) {
--- haribote/trunk/orbspace/orbspace/memory.c (nonexistent)
+++ haribote/trunk/orbspace/orbspace/memory.c (revision 204)
@@ -0,0 +1,91 @@
1+#include "main.h"
2+
3+#define EFLAGS_AC 0x00040000
4+#define CR0_CDISABLE 0x60000000
5+
6+void memory_init(struct memory *mem, unsigned int start, unsigned int end)
7+{
8+ char is486 = 0;
9+
10+ eflags_store(eflags_load() | EFLAGS_AC);
11+ if (eflags_load() & EFLAGS_AC) {
12+ is486 = 1;
13+ }
14+ eflags_store(eflags_load() & ~EFLAGS_AC);
15+ if (is486) {
16+ cr0_store(cr0_load() | CR0_CDISABLE);
17+ }
18+ mem->total = memory_test(start, end);
19+ if (is486) {
20+ cr0_store(cr0_load() & ~CR0_CDISABLE);
21+ }
22+
23+ mem->frees = 0;
24+ return;
25+}
26+
27+unsigned int memory_stat(struct memory *mem)
28+{
29+ unsigned int i, t = 0;
30+
31+ for (i = 0; i < mem->frees; i++) {
32+ t += mem->free[i].size;
33+ }
34+ return t;
35+}
36+
37+unsigned int memory_alloc(struct memory *mem, unsigned int size)
38+{
39+ unsigned int addr, i;
40+
41+ for (i = 0; i < mem->frees; i++) {
42+ if (mem->free[i].size >= size) {
43+ addr = mem->free[i].addr;
44+ mem->free[i].addr += size;
45+ if ((mem->free[i].size -= size) == 0) {
46+ mem->frees--;
47+ for (; i < mem->frees; i++) {
48+ mem->free[i] = mem->free[i + 1];
49+ }
50+ }
51+ return addr;
52+ }
53+ }
54+ return 0;
55+}
56+
57+int memory_free(struct memory *mem, unsigned int addr, unsigned int size)
58+{
59+ int i, j;
60+
61+ for (i = 0; i < mem->frees; i++) {
62+ if (mem->free[i].addr > addr) {
63+ break;
64+ }
65+ }
66+ if (i > 0 && mem->free[i - 1].addr + mem->free[i - 1].size == addr) {
67+ mem->free[i - 1].size += size;
68+ if (i < mem->frees && addr + size == mem->free[i].addr) {
69+ mem->free[i - 1].size += mem->free[i].size;
70+ mem->frees--;
71+ for (; i < mem->frees; i++) {
72+ mem->free[i] = mem->free[i + 1];
73+ }
74+ }
75+ return 0;
76+ }
77+ if (i < mem->frees && addr + size == mem->free[i].addr) {
78+ mem->free[i].addr = addr;
79+ mem->free[i].size += size;
80+ return 0;
81+ }
82+ if (mem->frees < 4095) {
83+ for (j = mem->frees++; j > i; j--) {
84+ mem->free[j] = mem->free[j - 1];
85+ }
86+ mem->free[i].addr = addr;
87+ mem->free[i].size = size;
88+ return 0;
89+ }
90+ return -1;
91+}
--- haribote/trunk/orbspace/orbspace/main.h (revision 203)
+++ haribote/trunk/orbspace/orbspace/main.h (revision 204)
@@ -3,7 +3,12 @@
33 unsigned char leds, reserve[3];
44 unsigned int *vram;
55 };
6+#define BOOTINFO_ADDR 0x0ff0
67
8+/* main.c */
9+#define SYSFIFO_ADDR 0x0fd0
10+#define MEMORY_ADDR 0x001f8000
11+
712 /* asmfunc.nas */
813 void hlt(void);
914 void cli(void);
@@ -12,8 +17,13 @@
1217 unsigned int inb(unsigned int port);
1318 void outb(unsigned int port, unsigned int data);
1419 void lidt(unsigned int limit, unsigned int addr);
20+unsigned int cr0_load(void);
21+void cr0_store(unsigned int cr0);
22+unsigned int eflags_load(void);
23+void eflags_store(unsigned int eflags);
1524 void inthandler21(void);
1625 void inthandler27(void);
26+unsigned int memory_test(unsigned int start, unsigned int end);
1727
1828 /* orbfs.c */
1929 #include "orbfs.h"
@@ -24,12 +34,8 @@
2434 unsigned char dw_count, ar;
2535 unsigned short offset_high;
2636 };
27-#define IDT_ADDR 0x00100000
28-#define IDT_LIMIT 0x000007ff
29-#define AR_INTGATE32 0x008e
3037 #define PIC0_IMR 0x0021
3138 #define PIC1_IMR 0x00a1
32-#define PORT_KEYDATA 0x0060
3339 void idt_init(void);
3440
3541 /* fifo.c */
@@ -50,3 +56,16 @@
5056 unsigned int c);
5157 void graphic_puts(unsigned int *buf, unsigned int xsize, unsigned int x,
5258 unsigned int y, unsigned int c, unsigned char *s);
59+
60+/* memory.c */
61+struct freeinfo {
62+ unsigned int addr, size;
63+};
64+struct memory {
65+ unsigned int total, frees;
66+ struct freeinfo free[4095];
67+};
68+void memory_init(struct memory *mem, unsigned int start, unsigned int end);
69+unsigned int memory_stat(struct memory *mem);
70+unsigned int memory_alloc(struct memory *mem, unsigned int size);
71+int memory_free(struct memory *mem, unsigned int addr, unsigned int size);
--- haribote/trunk/orbspace/orbspace/int.c (revision 203)
+++ haribote/trunk/orbspace/orbspace/int.c (revision 204)
@@ -11,6 +11,10 @@
1111 return;
1212 }
1313
14+#define IDT_ADDR 0x00100000
15+#define IDT_LIMIT 0x000007ff
16+#define AR_INTGATE32 0x008e
17+
1418 void idt_init(void)
1519 {
1620 struct gatedesc *idt = (struct gatedesc *) IDT_ADDR;
@@ -25,11 +29,13 @@
2529 return;
2630 }
2731
32+#define PORT_KEYDATA 0x0060
33+
2834 void keyhandler(int *esp)
2935 {
30- extern struct fifo sysfifo;
36+ struct fifo *sysfifo = (struct fifo *) SYSFIFO_ADDR;
3137 unsigned char data = inb(PORT_KEYDATA);
3238
33- fifo_push(&sysfifo, data + 256);
39+ fifo_push(sysfifo, data + 256);
3440 return;
3541 }
--- haribote/trunk/orbspace/orbspace/Makefile (revision 203)
+++ haribote/trunk/orbspace/orbspace/Makefile (revision 204)
@@ -1,5 +1,5 @@
11 OBJS = main.obj asmfunc.obj engfont.obj orbfs.obj int.obj fifo.obj \
2- graphic.obj
2+ graphic.obj memory.obj
33 HEADERS = main.h orbfs.h
44
55 TOOLPATH = ../../z_tools/
Show on old repository browser