diff --git a/Makefile b/Makefile index 77a0081..844e096 100644 --- a/Makefile +++ b/Makefile @@ -94,7 +94,8 @@ KernSources = libbuf/buf.c libbuf/bputc.c libbuf/bscroll.c \ kernel/mm/heap.c kernel/mm/malloc.c \ kernel/mm/gdt.c kernel/ps/sched.c \ kernel/init/info.c kernel/init/ssp.c \ - kernel/io/rtc.c kernel/io/keyb.c + kernel/io/rtc.c kernel/io/keyb.c \ + kernel/io/spkr.c LibCObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(LibCSources)) @@ -156,20 +157,20 @@ $(KOBJDIR)/%.o: %.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR) @echo ${CL2}[$@] ${CL}Compiled.${CL3} test: all - @qemu-system-x86_64 -rtc base=localtime -m 4G -hda $(BUILDDIR)/bin/disk.img \ + @qemu-system-x86_64 -rtc base=localtime -m 4G -hda $(BUILDDIR)/bin/disk.img -soundhw pcspk \ -d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log & test32: all @qemu-system-i386 -hda $(BUILDDIR)/bin/disk.img -d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log & debug: all - @qemu-system-x86_64 -m 64M -hda $(BUILDDIR)/bin/disk.img -no-reboot \ + @qemu-system-x86_64 -m 64M -hda $(BUILDDIR)/bin/disk.img -no-reboot -soundhw pcspk \ -no-shutdown -d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log & @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 64 > $(BUILDDIR)/kaleid64_disasm.asm @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > $(BUILDDIR)/kaleid32_disasm.asm gdb: all - @qemu-system-x86_64 -m 64M -hda $(BUILDDIR)/bin/disk.img -no-reboot \ + @qemu-system-x86_64 -m 64M -hda $(BUILDDIR)/bin/disk.img -no-reboot -soundhw pcspk \ -no-shutdown -d cpu_reset,guest_errors,pcall,int -s -S 2> $(BUILDDIR)/qemu.log & @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 64 > kaleid64_disasm.asm @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > kaleid32_disasm.asm @@ -180,7 +181,7 @@ gdb: all -ex "break BtStartKern" \ ddd: all - @qemu-system-x86_64 -m 64M -hda $(BUILDDIR)/bin/disk.img -no-reboot \ + @qemu-system-x86_64 -m 64M -hda $(BUILDDIR)/bin/disk.img -no-reboot -soundhw pcspk \ -no-shutdown -d cpu_reset,guest_errors,pcall,int -s -S 2> $(BUILDDIR)/qemu.log & @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 64 > kaleid64_disasm.asm @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > kaleid32_disasm.asm diff --git a/include/kernel/base.h b/include/kernel/base.h index b15326d..362c9b0 100644 --- a/include/kernel/base.h +++ b/include/kernel/base.h @@ -101,19 +101,19 @@ struct Processor_t }; struct ISRFrame_t { -/* the register file */ - ulong regs[15]; + /* The register file */ + ulong regs[15]; - /* the error code and interrupt id */ - ulong intNo; - ulong ErrorCode; + /* The error code and interrupt id */ + ulong intNo; + ulong ErrorCode; - /* these are pushed automatically by the CPU */ - ulong rip; - ulong cs; - ulong rflags; - ulong rsp; - ulong ss; + /* These are pushed automatically by the CPU */ + ulong rip; + ulong cs; + ulong rflags; + ulong rsp; + ulong ss; } __attribute__((__packed__)); diff --git a/include/kernel/speaker.h b/include/kernel/speaker.h new file mode 100644 index 0000000..d898953 --- /dev/null +++ b/include/kernel/speaker.h @@ -0,0 +1,41 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Desc: Speaker functions // +// // +// // +// Copyright © 2018-2019 The OS/K Team // +// // +// This file is part of OS/K. // +// // +// OS/K 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 // +// any later version. // +// // +// OS/K 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 OS/K. If not, see . // +//----------------------------------------------------------------------------// + +#ifndef _KALKERN_BASE_H +#include +#endif + +#ifndef _KALKERN_SPEAKER_H +#define _KALKERN_SPEAKER_H + +//----------------------------------------------------------------------------// + +void IoStartSpeaker(int freq); +void IoQuietSpeaker(void); +void IoDoBeep(void); + +//----------------------------------------------------------------------------// + +#endif + diff --git a/include/kernel/time.h b/include/kernel/time.h index fc8fc67..a15a5c9 100644 --- a/include/kernel/time.h +++ b/include/kernel/time.h @@ -22,6 +22,15 @@ // along with OS/K. If not, see . // //----------------------------------------------------------------------------// +#ifndef _KALKERN_BASE_H +#include +#endif + +#ifndef _KALKERN_TIME_H +#define _KALKERN_TIME_H + +//----------------------------------------------------------------------------// + typedef struct { uchar sec; @@ -42,3 +51,7 @@ extern Time_t* IoGetRtcTime(void); extern char* IoGetRtcTimeChar(void); //static char* WeekDays[7] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; +//----------------------------------------------------------------------------// + +#endif + diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index d580101..a9384b1 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -29,6 +29,7 @@ #include #include #include +#include // info.c extern void BtDoSanityChecks(uint mbMagic); @@ -94,7 +95,9 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg) /* i++; */ /* } */ - KernLog("Goodbye at %s", IoGetRtcTimeChar()); + KernLog("Goodbye at %s\n", IoGetRtcTimeChar()); + + IoDoBeep(); // End this machine's suffering BStdOut->flusher(BStdOut); diff --git a/kaleid/kernel/io/spkr.c b/kaleid/kernel/io/spkr.c new file mode 100644 index 0000000..301c3dc --- /dev/null +++ b/kaleid/kernel/io/spkr.c @@ -0,0 +1,60 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Desc: Speaker functions // +// // +// // +// Copyright © 2018-2019 The OS/K Team // +// // +// This file is part of OS/K. // +// // +// OS/K 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 // +// any later version. // +// // +// OS/K 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 OS/K. If not, see . // +//----------------------------------------------------------------------------// + +#include +#include +#include + +void IoStartSpeaker(int freq) +{ + char temp; + int pitf = 1193180 / freq; + + IoWriteByteOnPort(0x43, 0xB6); + IoWriteByteOnPort(0x42, (char)pitf); + IoWriteByteOnPort(0x42, (char)(pitf >> 8)); + + temp = IoReadByteFromPort(0x61); + if (temp != (temp | 3)) { + IoWriteByteOnPort(0x61, temp | 3); + } +} + +void IoQuietSpeaker(void) +{ + IoWriteByteOnPort(0x61, IoReadByteFromPort(0x61) & 0xFC); +} + +void IoDoBeep(void) +{ + IoStartSpeaker(1000); + + // Worst possible way of waiting + // We need actual timers + ulong ticks = IoGetRtcTicks(); + while (IoGetRtcTicks() < ticks + 512); + + IoQuietSpeaker(); +} + diff --git a/kaleid/kernel/ps/sched.c b/kaleid/kernel/ps/sched.c index b27a178..5e8e525 100644 --- a/kaleid/kernel/ps/sched.c +++ b/kaleid/kernel/ps/sched.c @@ -372,8 +372,6 @@ void PrintList(ListHead_t *head) void pstest(void) { - //ClearTerm(StdOut); - KernLog("\nTime Critical: "); PrintList(TimeCritProcs);