Quellcode durchsuchen

evx: now add (copy :-) ) a console driver (from xnix-3)

rain vor 5 Jahren
Ursprung
Commit
ea8a328e1d
9 geänderte Dateien mit 366 neuen und 3 gelöschten Zeilen
  1. 2 1
      Makefile
  2. 59 0
      arch/x86/include32/arch/io.h
  3. 61 0
      arch/x86/include64/arch/io.h
  4. 50 0
      include/modules/console.h
  5. 1 1
      init/main.c
  6. 1 1
      kernel/Makefile
  7. 38 0
      kernel/mm.c
  8. 15 0
      modules/Makefile
  9. 139 0
      modules/console.c

+ 2 - 1
Makefile

@@ -51,8 +51,9 @@ ifeq 	($D,)
 # that inside object, and we don't support other objects at this time :-)
 
 obj-i 			+= $(ARCHDIR)/ 
-obj-i 			+= $(PWD)/kernel/ 
 obj-i 			+= $(PWD)/init/ 
+obj-i 			+= $(PWD)/kernel/ 
+obj-i 			+= $(PWD)/modules/ 
 
 
 

+ 59 - 0
arch/x86/include32/arch/io.h

@@ -0,0 +1,59 @@
+/* arch/x86/include32/arch/io.h  
+ * 
+ * This file is part of evx. 
+ * 
+ * evx is free software: you can redistribute it and/or modify 
+ * it under the terms of the GNU General Public License as published by 
+ * the Free Software Foundation, either version 3 of the License, or 
+ * (at your option) any later version. 
+ * 
+ * evx is distributed in the hope that it will be useful, 
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+ * GNU General Public License for more details. 
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with evx. If not, see <https://www.gnu.org/licenses/>
+ */ 
+
+
+
+
+#ifndef __ARCH_IO_H
+#define __ARCH_IO_H
+
+
+#ifndef __ASSEMBLER__
+
+/* we can use assembly here! yeah! */
+
+#define inb(port) ({								\
+		__uint8_t _r;							\
+		__asm__ volatile ("inb %%dx, %%al" : "=a" (_r) : "d" ((port)));	\
+		_r;								\
+	})
+
+
+#define outb(val, port) __asm__ volatile ("outb %%al, %%dx" :: "a" ((val)), "d" ((port)))
+
+
+#define inw(port) ({								\
+		__uint16_t _r;							\
+		__asm__ volatile ("inw %%dx, %%ax" : "=a" (_r) : "d" ((port))); \
+		_r;								\
+	})
+
+#define outw(val, port) __asm__ volatile ("outw %%ax, %%dx" :: "a" ((val)), "d" ((port)))
+
+
+#define inl(port) ({								\
+		__uint32_t _r;							\
+		__asm__ volatile ("inl %%dx, %%eax" : "=a" (_r) : "d" ((port)));\
+		_r;								\
+	})
+
+#define outl(val, port) __asm__ volatile ("outl %%eax, %%dx" :: "a" ((val)), "d" ((port)))
+
+#endif
+
+#endif

+ 61 - 0
arch/x86/include64/arch/io.h

@@ -0,0 +1,61 @@
+/* arch/x86/include64/arch/io.h  
+ * 
+ * This file is part of evx. 
+ * 
+ * evx is free software: you can redistribute it and/or modify 
+ * it under the terms of the GNU General Public License as published by 
+ * the Free Software Foundation, either version 3 of the License, or 
+ * (at your option) any later version. 
+ * 
+ * evx is distributed in the hope that it will be useful, 
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+ * GNU General Public License for more details. 
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with evx. If not, see <https://www.gnu.org/licenses/>
+ */ 
+
+
+
+
+#ifndef __ARCH_IO_H
+#define __ARCH_IO_H
+
+
+#ifndef __ASSEMBLER__
+
+#include <sys/types.h>
+
+/* we can use assembly here! yeah! */
+
+#define inb(port) ({									\
+		__uint8_t _r;								\
+		__asm__ volatile ("inb %%dx, %%al" : "=a" (_r) : "d" ((port)));		\
+		_r;									\
+	})
+
+
+#define outb(val, port) __asm__ volatile ("outb %%al, %%dx" :: "a" ((val)), "d" ((port)))
+
+
+#define inw(port) ({									\
+		__uint16_t _r;								\
+		__asm__ volatile ("inw %%dx, %%ax" : "=a" (_r) : "d" ((port))); 	\
+		_r;									\
+	})
+
+#define outw(val, port) __asm__ volatile ("outw %%ax, %%dx" :: "a" ((val)), "d" ((port)))
+
+
+#define inl(port) ({									\
+		__uint32_t _r;								\
+		__asm__ volatile ("inl %%dx, %%eax" : "=a" (_r) : "d" ((port)));	\
+		_r;									\
+	})
+
+#define outl(val, port) __asm__ volatile ("outl %%eax, %%dx" :: "a" ((val)), "d" ((port)))
+
+#endif
+
+#endif

+ 50 - 0
include/modules/console.h

@@ -0,0 +1,50 @@
+/* include/modules/console.h 
+ * 
+ * This file is part of evx. 
+ * 
+ * evx is free software: you can redistribute it and/or modify 
+ * it under the terms of the GNU General Public License as published by 
+ * the Free Software Foundation, either version 3 of the License, or 
+ * (at your option) any later version. 
+ * 
+ * evx is distributed in the hope that it will be useful, 
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+ * GNU General Public License for more details. 
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with evx. If not, see <https://www.gnu.org/licenses/>
+ */ 
+
+
+
+
+#ifndef __MOD_CONSOLE_H
+#define __MOD_CONSOLE_H
+
+
+#ifndef __ASSEMBLER__
+
+#include <sys/types.h>
+
+
+#define TABSIZE 	8
+
+
+/* for vga 80x25 display */
+
+#define CMD_POS_LO 	0x0f
+#define CMD_POS_HI 	0x0e
+
+#define VGA_INDEX 	0x03d4
+#define VGA_DATA 	0x03d5
+
+#define FB_ADDR 	((__uint16_t *) 0xb8000)
+
+#define COLMS 		80
+#define LINES 		25
+
+#endif
+
+#endif
+

+ 1 - 1
init/main.c

@@ -68,7 +68,7 @@ int do_init_calls(void) {
 		start = init_call_levels[++i];
 		end = init_call_levels[++i];
 
-		int ncalls = (end - start) >> PTRSHIFT;
+		int ncalls = end - start;
 
 
 		for (initcalls = start; ncalls; initcalls++, ncalls--) {

+ 1 - 1
kernel/Makefile

@@ -1,7 +1,7 @@
 # this was called from the Makefile in /, 
 # and we just tell it what objects that he should make. 
 
-obj-i = 
+obj-i = mm.c 
 
 target:
 

+ 38 - 0
kernel/mm.c

@@ -0,0 +1,38 @@
+/* kernel/mm.c 
+ * 
+ * This file is part of evx. 
+ * 
+ * evx is free software: you can redistribute it and/or modify 
+ * it under the terms of the GNU General Public License as published by 
+ * the Free Software Foundation, either version 3 of the License, or 
+ * (at your option) any later version. 
+ * 
+ * evx is distributed in the hope that it will be useful, 
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+ * GNU General Public License for more details. 
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with evx. If not, see <https://www.gnu.org/licenses/>
+ */ 
+
+
+
+
+#include <kernel/init.h>
+#include <kernel/module.h>
+
+#include <arch/archinfo.h>
+
+#include <sys/types.h>
+
+
+
+int mm_init(void) {
+	return 0;
+}
+
+
+kernel_init(mm_init);
+
+

+ 15 - 0
modules/Makefile

@@ -0,0 +1,15 @@
+# this was called from the Makefile in /, 
+# and we just tell it what objects that he should make. 
+
+obj-i = console.c 
+
+target:
+
+ifeq ($(D), )
+	@echo "this should call from the Makefile in directory /, but not typing make in kernel/. :-(" >&2 
+	@exit 1
+endif
+
+# $(PWD) is the / directory of kernel, e.g. /root/evx/
+	@$(MAKE) -C $(PWD) D=$(shell pwd) obj-i="$(obj-i)"
+

+ 139 - 0
modules/console.c

@@ -0,0 +1,139 @@
+/* modules/console.c 
+ * 
+ * This file is part of evx. 
+ * 
+ * evx is free software: you can redistribute it and/or modify 
+ * it under the terms of the GNU General Public License as published by 
+ * the Free Software Foundation, either version 3 of the License, or 
+ * (at your option) any later version. 
+ * 
+ * evx is distributed in the hope that it will be useful, 
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+ * GNU General Public License for more details. 
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with evx. If not, see <https://www.gnu.org/licenses/>
+ */ 
+
+
+
+
+#include <sys/types.h>
+
+#include <kernel/init.h>
+#include <kernel/module.h>
+
+#include <modules/console.h>
+
+#include <arch/io.h>
+
+
+__uint16_t pos = 0;
+__uint16_t x = 0, y = 0;
+
+#define POS2XY(pos) x = pos % 80; y = pos / 80;
+
+static __uint16_t read_cursor(void);
+static void update_cursor(void);
+
+void raw_putc(__uint16_t, __uint8_t, char);
+void cano_putc(char);
+
+
+int __init init_console(void) {
+	pos = read_cursor();
+
+	POS2XY(pos);
+
+	cano_putc('\n');
+
+	return 0;
+}
+
+
+static __uint16_t read_cursor(void) {
+	__uint16_t rv = 0;
+
+	outb(CMD_POS_LO, VGA_INDEX);
+	rv |= (__uint16_t) inb(VGA_DATA);
+
+	outb(CMD_POS_HI, VGA_INDEX);
+	rv |= ((__uint16_t) inb(VGA_DATA)) << 8;
+
+	return rv;
+}
+
+
+void cano_putc(char c) {
+	if (c == '\n') {
+		y++;
+		x = 0;
+
+		goto out;
+	}
+
+	if (c == '\r') {
+		x = 0;
+
+		goto out;
+	}
+
+	if (c == '\t') {
+		__uint32_t t = (x + TABSIZE - 1) & ~(TABSIZE - 1);
+
+		if (t == x) 
+			x += TABSIZE;
+
+		else 
+			x = t;
+
+		if (x == COLMS) {
+			y++;
+			x = TABSIZE;
+		}
+
+		goto out;
+	}
+
+	raw_putc(pos++, 7, c);
+
+	x++;
+
+	if (x == COLMS) {
+		y++;
+		x = 0;
+	}
+
+out:
+	update_cursor();
+
+	return;
+}
+
+
+void raw_putc(__uint16_t pos, __uint8_t color, char c) {
+	__uint16_t *fb = FB_ADDR + pos;
+
+	*fb = (color << 8) + c;
+
+	return;
+}
+
+
+void update_cursor(void) {
+	pos = y * COLMS + x;
+
+	outb(CMD_POS_LO, VGA_INDEX);
+	outb(pos & 0xff, VGA_DATA);
+
+	outb(CMD_POS_HI, VGA_INDEX);
+	outb((pos >> 8) & 0xff, VGA_DATA);
+
+	return;
+}
+
+
+module_init(init_console);
+
+