mirror of
https://gitlab.os-k.eu/os-k-team/os-k.git
synced 2023-08-25 14:03:10 +02:00
RTC finished !
This commit is contained in:
parent
11792a58f8
commit
0118bfb796
7
Makefile
7
Makefile
@ -197,6 +197,13 @@ gdb: all
|
||||
-ex "symbol-file $(BINDIR)/kaleid" \
|
||||
-ex "break BtStartKern" \
|
||||
|
||||
ddd: all
|
||||
@qemu-system-x86_64 -m 64M -hda $(BUILDDIR)/bin/disk.img -no-reboot \
|
||||
-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
|
||||
@ddd
|
||||
|
||||
install_mbr: $(BINDIR)/disk.img $(MBRDIR)/grub.cfg
|
||||
@mkdir -p $(BINDIR)/disk
|
||||
@echo ${CL2}[$@] ${NC}Installing MBR on image...${CL3}
|
||||
|
@ -45,10 +45,8 @@ struct IRQList_t
|
||||
struct entry {
|
||||
void (*isr)(void);
|
||||
uchar irq;
|
||||
ulong base;
|
||||
ushort selector;
|
||||
uchar flags;
|
||||
} entry[225];
|
||||
} entry[224];
|
||||
};
|
||||
|
||||
static char *IsrExceptions[32] = {
|
||||
|
@ -43,7 +43,7 @@ void IdtRegisterIrq(void (*isr)(void), uchar irq, uchar flags)
|
||||
|
||||
KalAssert(idt[0].flags==0); // IDT uninitialized
|
||||
|
||||
if ((n == 225)) // IRQs not filled
|
||||
if ((n == 224)) // IRQs not filled
|
||||
KeStartPanic("[IdtRegisterIrq] Cannot register IRQ %c function %p !",
|
||||
irq,
|
||||
isr
|
||||
@ -101,13 +101,15 @@ void IdtSetup(void)
|
||||
IdtSetGate(28, (ulong)isr28, codeSeg, 0x8E); // INTEL RESERVED
|
||||
IdtSetGate(29, (ulong)isr29, codeSeg, 0x8E); // INTEL RESERVED
|
||||
IdtSetGate(30, (ulong)isr30, codeSeg, 0x8E); // INTEL RESERVED
|
||||
IdtSetGate(31, (ulong)isr31, codeSeg, 0x8E); // INTEL RESERVED
|
||||
|
||||
// Set the IRQ Driver Gates
|
||||
for (int i = 0 ; i < irqList.n ; i++) {
|
||||
IdtSetGate(irqList.entry[irqList.n].irq,
|
||||
(ulong)irqList.entry[irqList.n].isr,
|
||||
IdtSetGate(
|
||||
irqList.entry[i].irq,
|
||||
(ulong)irqList.entry[i].isr,
|
||||
codeSeg,
|
||||
irqList.entry[irqList.n].flags
|
||||
irqList.entry[i].flags
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -140,5 +140,4 @@ IsrWithoutErrCode 28
|
||||
IsrWithoutErrCode 29
|
||||
IsrWithoutErrCode 30
|
||||
IsrWithoutErrCode 31
|
||||
IsrWithoutErrCode 32
|
||||
|
||||
|
@ -36,8 +36,13 @@ extern void BtInitBootInfo(multiboot_info_t *mbi, void *codeSeg);
|
||||
// io/vga.c
|
||||
extern error_t IoInitVGABuffer(void);
|
||||
|
||||
//io/keyb.
|
||||
extern error_t KeybSetup(void);
|
||||
//io/keyb.c
|
||||
extern void IoSetupKeyb(void);
|
||||
|
||||
//io/rtc.c
|
||||
extern void IoSetupRtc(void);
|
||||
extern void IoEnableRtc(void);
|
||||
extern ulong IoRtcTicks;
|
||||
|
||||
// cpu/idt.c
|
||||
extern void IdtSetup(void);
|
||||
@ -50,7 +55,7 @@ extern void divideByZero(void);
|
||||
|
||||
void test(void)
|
||||
{
|
||||
DebugLog("test\n");
|
||||
asm volatile ("hlt");
|
||||
}
|
||||
|
||||
//
|
||||
@ -79,11 +84,23 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
|
||||
// Several inits
|
||||
MmInitHeap();
|
||||
PsInitSched();
|
||||
KeybSetup();
|
||||
|
||||
// Drivers ISR inits
|
||||
IoSetupRtc();
|
||||
// Interrupts launching
|
||||
IdtSetup();
|
||||
KeEnableIRQs();
|
||||
// Drivers enabling
|
||||
IoEnableRtc();
|
||||
|
||||
KernLog("\nGoodbye!");
|
||||
while (1) {
|
||||
asm volatile ("hlt");
|
||||
if (IoRtcTicks > 2000) {
|
||||
KernLog("CC\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
KernLog("\nGoodbye after %d ticks", IoRtcTicks);
|
||||
|
||||
// End this machine's suffering
|
||||
BFlushBuf(BStdOut);
|
||||
|
@ -23,6 +23,8 @@
|
||||
; along with OS/K. If not, see <https://www.gnu.org/licenses/>. ;
|
||||
;=----------------------------------------------------------------------------=;
|
||||
|
||||
[BITS 64]
|
||||
|
||||
global KeybIsr
|
||||
extern KeybHandler
|
||||
|
||||
|
@ -22,12 +22,14 @@
|
||||
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <kernel/base.h>
|
||||
#include <kernel/iomisc.h>
|
||||
|
||||
extern void KeybIsr(void);
|
||||
extern IdtRegisterIrq(void (*isr)(void), uchar irq, uchar flags);
|
||||
extern void IdtRegisterIrq(void (*isr)(void), uchar irq, uchar flags);
|
||||
extern void SendEOItoPIC(void);
|
||||
|
||||
void KeybSetup(void)
|
||||
void IoSetupKeyb(void)
|
||||
{
|
||||
IdtRegisterIrq(KeybIsr, 0x21, 0x8E);
|
||||
}
|
||||
@ -35,20 +37,20 @@ void KeybSetup(void)
|
||||
|
||||
uchar KeybHandler(void)
|
||||
{
|
||||
uchar status;
|
||||
uchar code;
|
||||
char status;
|
||||
char code = 0;
|
||||
|
||||
// write EOI
|
||||
IoWriteByteOnPort(0x20, 0x20);
|
||||
|
||||
status = IoReadByteFromPort(KeybStatusPort);
|
||||
status = IoReadByteFromPort(0x64);
|
||||
|
||||
if (status & 0x01) {
|
||||
code = IoReadByteFromPort(KeybDataPort);
|
||||
code = IoReadByteFromPort(0x60);
|
||||
|
||||
if(code < 0) return 0;
|
||||
if(code < 0) code = 0;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,3 +22,48 @@
|
||||
; You should have received a copy of the GNU General Public License ;
|
||||
; along with OS/K. If not, see <https://www.gnu.org/licenses/>. ;
|
||||
;=----------------------------------------------------------------------------=;
|
||||
|
||||
[BITS 64]
|
||||
|
||||
global RtcIsr
|
||||
extern RtcHandler
|
||||
|
||||
%macro pushAll 0
|
||||
push rax
|
||||
push rcx
|
||||
push rdx
|
||||
push rbx
|
||||
push rbp
|
||||
push rsi
|
||||
push rdi
|
||||
%endmacro
|
||||
|
||||
%macro popAll 0
|
||||
pop rdi
|
||||
pop rsi
|
||||
pop rbp
|
||||
pop rbx
|
||||
pop rdx
|
||||
pop rcx
|
||||
pop rax
|
||||
%endmacro
|
||||
|
||||
;;
|
||||
;; Keyboard handler
|
||||
;;
|
||||
RtcIsr:
|
||||
cli
|
||||
pushAll
|
||||
|
||||
xor rax, rax
|
||||
mov ax, ds
|
||||
push rax
|
||||
|
||||
call RtcHandler
|
||||
|
||||
pop rax
|
||||
mov ds, ax
|
||||
|
||||
popAll
|
||||
sti
|
||||
iretq
|
||||
|
@ -24,17 +24,60 @@
|
||||
|
||||
#include <kernel/base.h>
|
||||
#include <kernel/iomisc.h>
|
||||
#include <extras/buf.h>
|
||||
|
||||
void CpuEnableRtc(void)
|
||||
extern void RtcIsr(void);
|
||||
extern void SendEOItoPIC(void);
|
||||
extern void IdtRegisterIrq(void (*isr)(void), uchar irq, uchar flags);
|
||||
|
||||
ulong IoRtcTicks = 0;
|
||||
|
||||
void IoSetupRtc(void)
|
||||
{
|
||||
IdtRegisterIrq(RtcIsr, 0x28, 0x8E);
|
||||
}
|
||||
|
||||
void IoEnableRtc(void)
|
||||
{
|
||||
ulong flags = KePauseIRQs();
|
||||
// Setting up the register control
|
||||
IoWriteByteOnPort(0x70, 0x8A); //selects status reg A and DISABLE NMI
|
||||
IoWriteByteOnPort(0x71, 0x20);
|
||||
//Enabling the IRQ 8
|
||||
char readedInterruptConfig;
|
||||
char readedRegister;
|
||||
char readedIrqs;
|
||||
uchar RtcRate;
|
||||
|
||||
// Setting up the register control and interrupt rates
|
||||
RtcRate = 0x05;
|
||||
|
||||
IoWriteByteOnPort(0x70, 0x8B);
|
||||
char read = IoReadByteFromPort(0x71); // Because read causes reset
|
||||
IoWriteByteOnPort(0x70, 0x8B);
|
||||
IoWriteByteOnPort(0x71, read | 0x40);
|
||||
readedRegister = IoReadByteFromPort(0x71);
|
||||
IoWriteByteOnPort(0x70, 0x8B); // Because reading flushes
|
||||
IoWriteByteOnPort(0x71, readedRegister | 0x40);
|
||||
|
||||
IoWriteByteOnPort(0x70, 0x8A);
|
||||
readedInterruptConfig = IoReadByteFromPort(0x71);
|
||||
IoWriteByteOnPort(0x70, 0x8A); // Because reading flushes
|
||||
IoWriteByteOnPort(0x71, (readedInterruptConfig & 0xF0) | RtcRate);
|
||||
IoWriteByteOnPort(0x70, 0x0C);
|
||||
IoReadByteFromPort(0x71); // Flush
|
||||
|
||||
// Setting up the IRQs
|
||||
readedIrqs = IoReadByteFromPort(0xA1);
|
||||
IoWriteByteOnPort(0xA1, 0xFE & readedIrqs); // Enables IRQ on PIC 2
|
||||
readedIrqs = IoReadByteFromPort(0x21);
|
||||
IoWriteByteOnPort(0x21, 0xFB & readedIrqs); // Enables IRQ on PIC 1
|
||||
|
||||
// clean-up
|
||||
IoWriteByteOnPort(0x70, 0x0C); // Select status reg C
|
||||
IoReadByteFromPort(0x71); // Flush
|
||||
KeRestoreIRQs(flags);
|
||||
}
|
||||
|
||||
void RtcHandler(void)
|
||||
{
|
||||
//bprintf(BStdOut, " *RTC - ");
|
||||
IoWriteByteOnPort(0x70, 0x0C); // Selects status reg C
|
||||
IoReadByteFromPort(0x71); // Flush
|
||||
IoRtcTicks++;
|
||||
SendEOItoPIC();
|
||||
//bprintf(BStdOut, " - EOI* ");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user