Forráskód Böngészése

9.742u-mods: add support for pit

rain 5 éve
szülő
commit
b19991386d
10 módosított fájl, 140 hozzáadás és 27 törlés
  1. 1 0
      LINES
  2. 9 13
      Makefile
  3. 3 0
      README.md
  4. 34 0
      include/modules/beep.h
  5. 2 0
      init/main.c
  6. 5 2
      kernel/Makefile
  7. 6 1
      kernel/rlib/Makefile
  8. 5 2
      modules/Makefile
  9. 75 0
      modules/beep.c
  10. 0 9
      modules/ide.c

+ 1 - 0
LINES

@@ -42,4 +42,5 @@
 2021-8-21 9.389: 9389 lines, 59 files, rain
 2021-8-22 9.808: 9808 lines, 63 files, rain
 2021-8-23 9.640: 9640 lines, 63 files, rain
+2021-8-24 9.742: 9742 lines, 65 files, rain
 

+ 9 - 13
Makefile

@@ -1,32 +1,27 @@
-OBJS = boot/bootsect 
+OBJS = init/head.o init/main.o kernel/kernel.o kernel/rlib/rlib.o modules/modules.o  
 BOOT_SRCS = boot/boot.asm boot/loader.asm 
 BOOT_OBJS = boot/boot.bin boot/loader.bin 
-RLIB_SRCS = kernel/rlib/bitman.c kernel/rlib/bitmap.c kernel/rlib/fifo.c 
-RLIB_OBJS = kernel/rlib/bitman.o kernel/rlib/bitmap.o kernel/rlib/fifo.o 
-MODULE_SRCS = modules/ahci.c modules/ide.c 
-MODULE_OBJS = modules/ahci.o modules/ide.o 
-KOBJS = init/head.o init/main.o kernel/int.o kernel/keyboard.o kernel/trap.o kernel/vsprintf.o kernel/irq.o kernel/panic.o kernel/mm.o kernel/pci.o kernel/timer.o kernel/sched.o kernel/sys.o kernel/tty.o kernel/console.o $(RLIB_OBJS) $(MODULE_OBJS) 
-KSRCS = init/head.S init/main.c kernel/int.c kernel/keyboard.c kernel/trap.S kernel/vsprintf.c kernel/irq.c kernel/panic.c kernel/mm.c kernel/pci.c kernel/timer.S kernel/sched.c kernel/sys.c kernel/tty.c kernel/console.c $(RLIB_SRCS) $(MODULE_SRCS) 
+
 
 all: Makefile
 	make -C tools/
 	make -C boot/
 	make -C init/
-	make -C modules/
+	make -C modules/ 
 	make -C kernel/ 
 	make -C kernel/rlib 
 	make xnix.img
 	make vmxnix
 
-kbinary: $(KSRCS) $(KOBJS) $(BOOT_SCS) $(BOOT_OBJS) Makefile
-	ld -b elf64-x86-64 -o kernel.o $(KOBJS) -T kernel.lds
+kbinary: Makefile
+	ld -b elf64-x86-64 -o kernel.o $(OBJS) -T kernel.lds
 	objcopy -I elf64-x86-64 -S -R ".comment" -R ".eh_frame" -O binary kernel.o kbinary
 
-vmxnix: $(KSRCS) $(KOBJS) Makefile 
-	ld -b elf64-x86-64 $(KOBJS) -e init -T kernel.lds -o vmxnix
+vmxnix: Makefile 
+	ld -b elf64-x86-64 $(OBJS) -e init -T kernel.lds -o vmxnix
 
 
-xnix.img: $(BOOT_SRCS) $(BOOT_OBJS) $(KSRCS) $(KOBJS) Makefile kbinary tools/initcfs tools/mkfs 
+xnix.img: Makefile kbinary tools/initcfs tools/mkfs 
 	dd if=/dev/zero of=xnix.img bs=1048576 count=64
 	tools/mkfs xnix.img 
 	tools/initcfs xnix.img boot/boot.bin boot/loader.bin kbinary 
@@ -42,6 +37,7 @@ clear:
 	make -C boot/ clear
 	make -C init/ clear
 	make -C kernel/ clear
+	make -C kernel/rlib clear
 	make -C tools/ clear
 	rm xnix.img kbinary kernel.o vmxnix 
 	make -C modules/ clear

+ 3 - 0
README.md

@@ -169,3 +169,6 @@ source software, you can get its source code from <https://gitee.com/pengruiyang
 &nbsp;&nbsp;&nbsp;&nbsp;now we use another mode to `register_irq`: a new api that `set_irq`. 
 &nbsp;&nbsp;&nbsp;&nbsp;`set_irq` just need 2 arguments, it's simplier, and faster. 
 
+9.742u-mods:  
+&nbsp;&nbsp;&nbsp;&nbsp;add support for beep (in pit). 
+

+ 34 - 0
include/modules/beep.h

@@ -0,0 +1,34 @@
+/* Copyright (C) 2021 Rain */
+
+/* This file is part of XNIX. */
+
+/* 
+  XNIX 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) and later version. 
+*/
+
+/*
+  XNIX 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 XNIX. If not, see <https://www.gnu.org/licenses/>.  
+*/
+
+
+
+#include <kernel/init.h>
+#include <kernel/errno.h>
+#include <kernel/types.h>
+
+
+errno_t beep_init(void);
+void beep(__uint32_t);
+void beep_off(void);
+

+ 2 - 0
init/main.c

@@ -43,6 +43,8 @@
 #include <lib/string.h>
 #include <sys/syscall.h>
 
+#include <modules/beep.h>
+
 #include <arch/io.h>
 #include <arch/sys.h>
 #include <arch/x86/int.h>

+ 5 - 2
kernel/Makefile

@@ -1,7 +1,8 @@
 CFLAGS = -mcmodel=large -fno-builtin -m64 -I ../include/ -Wall -Werror -g
 
-all: int.o trap.o vsprintf.o irq.o panic.o mm.o pci.o timer.o sched.o sys.o keyboard.o tty.o console.o 
+OBJS = int.o trap.o vsprintf.o irq.o panic.o mm.o pci.o timer.o sched.o sys.o keyboard.o tty.o console.o 
 
+all: $(OBJS) kernel.o 
 
 %.o: %.S
 	gcc -E $*.S -I ../include > $*.s
@@ -10,7 +11,9 @@ all: int.o trap.o vsprintf.o irq.o panic.o mm.o pci.o timer.o sched.o sys.o keyb
 %.o: %.c
 	gcc -c $*.c -o $*.o $(CFLAGS)
 
+kernel.o: 
+	ld -r -o kernel.o $(OBJS)
+
 clear:
-	make -C rlib/ clear
 	rm *.o *.s
 

+ 6 - 1
kernel/rlib/Makefile

@@ -1,10 +1,15 @@
 C_FLAGS = -mcmodel=large -m64 -fno-builtin -nostdlib -I ../../include/ -Wall -Werror -O3 -g 
 
-all: bitmap.c bitman.c bitmap.o bitman.o fifo.o 
+OBJS = bitman.o bitmap.o fifo.o 
+
+all: $(OBJS) rlib.o 
 
 %.o: %.c
 	gcc -c $*.c $(C_FLAGS)
 
+rlib.o: 
+	ld -r -o rlib.o $(OBJS)
+
 
 clear:
 	rm *.o

+ 5 - 2
modules/Makefile

@@ -1,11 +1,14 @@
-OBJS = ahci.o ide.o  
+OBJS = ahci.o ide.o beep.o 
 CFLAGS = -mcmodel=large -fno-builtin -m64 -I ../include -Wall -Werror -g
 
-all: $(OBJS)
+all: $(OBJS) modules.o 
 
 %.o: %.c
 	gcc -c $*.c $(CFLAGS)
 
+modules.o: 
+	ld -r -o modules.o $(OBJS)
+
 clear:
 	rm *.o
 

+ 75 - 0
modules/beep.c

@@ -0,0 +1,75 @@
+/* Copyright (C) 2021 Rain */
+
+/* This file is part of XNIX. */
+
+/* 
+  XNIX 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) and later version. 
+*/
+
+/*
+  XNIX 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 XNIX. If not, see <https://www.gnu.org/licenses/>.  
+*/
+
+
+
+
+#include <kernel/init.h>
+#include <kernel/errno.h>
+#include <kernel/types.h>
+
+#include <kernel/console.h>
+#include <kernel/mm.h>
+
+#include <kernel/int.h>
+#include <kernel/panic.h>
+
+#include <arch/io.h>
+#include <modules/beep.h>
+
+
+static void beep_on(void) {
+	__uint8_t a;
+
+	a = (inb(0x61) | 0x03) & 0x0f;
+	outb(a, 0x61);
+
+	return;
+}
+
+void beep_off(void) {
+	__uint8_t a;
+
+	a = inb(0x61) & 0x0d;
+	outb(a, 0x61);
+
+	return;
+}
+
+
+errno_t beep_init(void) {
+	return 0;
+}
+
+void beep(__uint32_t value) {
+	value = 1193180000 / value;
+
+	outb(0xb6, 0x43);
+	outb(value & 0xff, 0x42);
+	outb((value >> 8) & 0xff, 0x42);
+
+	beep_on();
+
+	return;
+}
+

+ 0 - 9
modules/ide.c

@@ -144,15 +144,6 @@ errno_t ide_init(struct pci_header0 *hdr) {
 
 	ide_info("ide_init: id completed. \n");
 
-	ide_cmdout(HD0, BLKREAD, buffer, 1, 0x00000000);
-
-	while (ide_intr) hlt();
-
-	int i;
-
-	for (i = 0; i < 512; i++) 
-		printk(white, "%b", buffer[i]);
-
 	schk_leave();
 
 	return 0;