Stub Keyboard Driver
This commit is contained in:
parent
4afac67f27
commit
c9dd9ac668
5 changed files with 234 additions and 39 deletions
7
Makefile
7
Makefile
|
@ -29,8 +29,8 @@ all: kernel
|
|||
clean:
|
||||
$(RM) obj/dynamic.o obj/intr_common_handler.o obj/multiboot.o obj/start.o obj/console.o obj/init.o obj/interrupts.o obj/malloc.o obj/pmm.o obj/serial.o obj/stdlib.o obj/timer.o obj/vmm.o obj/cplusplus.o obj/cpp-test.o obj/vm.o obj/cpustatetype.o obj/main.o
|
||||
|
||||
kernel: obj/dynamic.o obj/intr_common_handler.o obj/multiboot.o obj/start.o obj/console.o obj/init.o obj/interrupts.o obj/malloc.o obj/pmm.o obj/serial.o obj/stdlib.o obj/timer.o obj/vmm.o obj/cplusplus.o obj/cpp-test.o obj/vm.o obj/cpustatetype.o obj/main.o conductance/assembly.o conductance/compoundtype.o conductance/opcodes.o conductance/process.o conductance/string.o conductance/thread.o conductance/virtualmachine.o conductance/vmpointertype.o conductance/vmprimitivetype.o conductance/vmtype.o conductance/vmvalue.o conductance/vmvoidtype.o
|
||||
$(LD) $(FLAGS) $(LDFLAGS) -o $@ obj/dynamic.o obj/intr_common_handler.o obj/multiboot.o obj/start.o obj/console.o obj/init.o obj/interrupts.o obj/malloc.o obj/pmm.o obj/serial.o obj/stdlib.o obj/timer.o obj/vmm.o obj/cplusplus.o obj/cpp-test.o obj/vm.o obj/cpustatetype.o obj/main.o conductance/assembly.o conductance/compoundtype.o conductance/opcodes.o conductance/process.o conductance/string.o conductance/thread.o conductance/virtualmachine.o conductance/vmpointertype.o conductance/vmprimitivetype.o conductance/vmtype.o conductance/vmvalue.o conductance/vmvoidtype.o
|
||||
kernel: obj/dynamic.o obj/intr_common_handler.o obj/multiboot.o obj/start.o obj/console.o obj/init.o obj/interrupts.o obj/malloc.o obj/pmm.o obj/serial.o obj/stdlib.o obj/timer.o obj/vmm.o obj/cplusplus.o obj/cpp-test.o obj/vm.o obj/cpustatetype.o obj/main.o conductance/assembly.o conductance/compoundtype.o conductance/instructions.o conductance/opcodes.o conductance/process.o conductance/string.o conductance/thread.o conductance/virtualmachine.o conductance/vmpointertype.o conductance/vmprimitivetype.o conductance/vmtype.o conductance/vmvalue.o conductance/vmvoidtype.o
|
||||
$(LD) $(FLAGS) $(LDFLAGS) -o $@ obj/dynamic.o obj/intr_common_handler.o obj/multiboot.o obj/start.o obj/console.o obj/init.o obj/interrupts.o obj/malloc.o obj/pmm.o obj/serial.o obj/stdlib.o obj/timer.o obj/vmm.o obj/cplusplus.o obj/cpp-test.o obj/vm.o obj/cpustatetype.o obj/main.o conductance/assembly.o conductance/compoundtype.o conductance/instructions.o conductance/opcodes.o conductance/process.o conductance/string.o conductance/thread.o conductance/virtualmachine.o conductance/vmpointertype.o conductance/vmprimitivetype.o conductance/vmtype.o conductance/vmvalue.o conductance/vmvoidtype.o
|
||||
|
||||
# src/console.c
|
||||
obj/console.o: src/console.c include/console.h include/kstdlib.h \
|
||||
|
@ -97,7 +97,8 @@ obj/cpp-test.o: src/cpp-test.cpp include/console.h include/ker/string.hpp \
|
|||
# src/vm.cpp
|
||||
obj/vm.o: src/vm.cpp include/kstdlib.h include/varargs.h include/config.h \
|
||||
include/malloc.h include/timer.h include/dynamic.h include/console.h \
|
||||
include/interrupts.h include/cpustate.h src/../csl/cpustatetype.hpp
|
||||
include/interrupts.h include/cpustate.h src/../csl/cpustatetype.hpp \
|
||||
include/io.h
|
||||
$(CXX) $(FLAGS) $(CXXFLAGS) -o $@ -c src/vm.cpp
|
||||
|
||||
# csl/cpustatetype.cpp
|
||||
|
|
|
@ -56,7 +56,8 @@ SOURCES = ../../Electronics/Electronics/Conductance/types/compoundtype.cpp
|
|||
../../Electronics/Electronics/Conductance/vmvalue.cpp \
|
||||
../ker/string.cpp \
|
||||
../../Electronics/Electronics/Conductance/thread.cpp \
|
||||
../../Electronics/Electronics/Conductance/process.cpp
|
||||
../../Electronics/Electronics/Conductance/process.cpp \
|
||||
../../Electronics/Electronics/Conductance/instructions.cpp
|
||||
OBJECTS = compoundtype.o \
|
||||
vmpointertype.o \
|
||||
vmprimitivetype.o \
|
||||
|
@ -68,7 +69,8 @@ OBJECTS = compoundtype.o \
|
|||
vmvalue.o \
|
||||
string.o \
|
||||
thread.o \
|
||||
process.o
|
||||
process.o \
|
||||
instructions.o
|
||||
DIST = /usr/lib/qt/mkspecs/features/spec_pre.prf \
|
||||
/usr/lib/qt/mkspecs/common/unix.conf \
|
||||
/usr/lib/qt/mkspecs/common/linux.conf \
|
||||
|
@ -254,7 +256,8 @@ DIST = /usr/lib/qt/mkspecs/features/spec_pre.prf \
|
|||
../../Electronics/Electronics/Conductance/vmvalue.cpp \
|
||||
../ker/string.cpp \
|
||||
../../Electronics/Electronics/Conductance/thread.cpp \
|
||||
../../Electronics/Electronics/Conductance/process.cpp
|
||||
../../Electronics/Electronics/Conductance/process.cpp \
|
||||
../../Electronics/Electronics/Conductance/instructions.cpp
|
||||
QMAKE_TARGET = Conductance
|
||||
DESTDIR = #avoid trailing-slash linebreak
|
||||
TARGET = libConductance.a
|
||||
|
@ -867,6 +870,28 @@ process.o: ../../Electronics/Electronics/Conductance/process.cpp ../include/kstd
|
|||
../../Electronics/Electronics/Conductance/types/compoundtype.hpp
|
||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o process.o ../../Electronics/Electronics/Conductance/process.cpp
|
||||
|
||||
instructions.o: ../../Electronics/Electronics/Conductance/instructions.cpp ../include/kstdlib.h \
|
||||
../include/varargs.h \
|
||||
../include/config.h \
|
||||
../include/malloc.h \
|
||||
../../Electronics/Electronics/Conductance/vmtype.hpp \
|
||||
../../Electronics/Electronics/Conductance/vmtypes.hpp \
|
||||
../include/ker/string.hpp \
|
||||
../include/ker/vector.hpp \
|
||||
../include/ker/new.hpp \
|
||||
../../Electronics/Electronics/Conductance/vmvalue.hpp \
|
||||
../../Electronics/Electronics/Conductance/opcodes.hpp \
|
||||
../include/ker/dictionary.hpp \
|
||||
../include/kernel.h \
|
||||
../include/ker/pair.hpp \
|
||||
../../Electronics/Electronics/Tools/fixedstring.hpp \
|
||||
../../Electronics/Electronics/Conductance/virtualmachine.hpp \
|
||||
../../Electronics/Electronics/Tools/binaryreader.hpp \
|
||||
../../Electronics/Electronics/Tools/refcounted.hpp \
|
||||
../../Electronics/Electronics/Conductance/assembly.hpp \
|
||||
../../Electronics/Electronics/Conductance/types/compoundtype.hpp
|
||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o instructions.o ../../Electronics/Electronics/Conductance/instructions.cpp
|
||||
|
||||
####### Install
|
||||
|
||||
install: FORCE
|
||||
|
|
|
@ -1,25 +1,66 @@
|
|||
NATIVE print(...);
|
||||
|
||||
NATIVE outb(port : UINT16, value : UINT8);
|
||||
NATIVE inb(port : UINT16) → UINT8;
|
||||
|
||||
PRI sendCommand(cmd : UINT8)
|
||||
BEGIN
|
||||
# Warten bis die Tastatur bereit ist, und der Befehlspuffer leer ist
|
||||
WHILE (inb(100u16) & 2u8) =/= 0u8 DO
|
||||
|
||||
END
|
||||
outb(96u16, cmd);
|
||||
END
|
||||
|
||||
PRI initKeyboard()
|
||||
BEGIN
|
||||
# Tastaturpuffer leeren
|
||||
WHILE (inb(100u16) & 1u8) =/= 0u8 DO
|
||||
inb(96u16);
|
||||
END
|
||||
|
||||
# Tastatur aktivieren
|
||||
# sendCommand(244u8);
|
||||
END
|
||||
|
||||
PUB main() | i : INT
|
||||
BEGIN
|
||||
native.print("Hello World!\n");
|
||||
print("Initialize keyboard...\n");
|
||||
initKeyboard();
|
||||
|
||||
print("Hello World!\n");
|
||||
1 → i;
|
||||
WHILE i <= 5 DO
|
||||
native.print(i, "\n");
|
||||
print(i, "\n");
|
||||
(i + 1) → i;
|
||||
END
|
||||
END
|
||||
|
||||
PUB irq(id : INT, data : INT)
|
||||
TYPE CpuState IS
|
||||
eax : UINT32;
|
||||
ebx : UINT32;
|
||||
ecx : UINT32;
|
||||
END
|
||||
|
||||
PUB irq(id : INT, data : CpuState) | scancode : UINT8
|
||||
BEGIN
|
||||
native.print("irq:", id, ", ", data.eax, " ", data.ebx, "\n");
|
||||
# print("irq:", id, ", ", data.eax, " ", data.ebx, "\n");
|
||||
IF id = 33 THEN
|
||||
inb(96u16) → scancode;
|
||||
print("keypress: ", scancode, "\n");
|
||||
END
|
||||
END
|
||||
|
||||
#!
|
||||
Was noch gemacht werden muss, bis der Tastatur-Treiber funktionieren könnte:
|
||||
- Support für beliebige Typen in Copper
|
||||
- Pushen von Typen != INT
|
||||
- erweiterung von pushi um typcode (u?int(8|16|32), bool)
|
||||
- erweiterung von pushr um typcode
|
||||
- Bitwise Operations
|
||||
- outb und inb
|
||||
- eventuell hex literals für Copper
|
||||
☑ Support für beliebige Typen in Copper
|
||||
☑ Pushen von Typen != INT
|
||||
☑ erweiterung von pushi um typcode (u?int(8|16|32), bool)
|
||||
☑ erweiterung von pushr um typcode
|
||||
☑ Simple type checks in Copper
|
||||
☑ Custom types in Copper
|
||||
☑ Native function calls in Copper
|
||||
☑ Bitwise Operations
|
||||
☑ outb und inb
|
||||
☐ eventuell hex literals für Copper
|
||||
!#
|
||||
|
|
|
@ -1,57 +1,116 @@
|
|||
; =============================================
|
||||
; compiled with Copper 1.0
|
||||
; 2015-10-09 23:28:07
|
||||
; 2015-10-10 23:51:17
|
||||
; =============================================
|
||||
|
||||
; fndecl
|
||||
; native method: print(…)
|
||||
; native method: outb(…)
|
||||
; native method: inb(…) → UINT8
|
||||
.type CpuState {
|
||||
eax : UINT32;
|
||||
ebx : UINT32;
|
||||
ecx : UINT32;
|
||||
}
|
||||
|
||||
|
||||
|
||||
; 0, sendCommand
|
||||
sendCommand:
|
||||
pushnil ; return value
|
||||
_private_0:
|
||||
pushi 4 100
|
||||
callnr inb 1
|
||||
pushi 3 2
|
||||
op2 12
|
||||
pushi 3 0
|
||||
op2 6
|
||||
jmp_if_not _private_1
|
||||
jmp _private_0
|
||||
_private_1:
|
||||
|
||||
load -1
|
||||
pushi 4 96
|
||||
calln outb 2
|
||||
|
||||
ret
|
||||
; end of sendCommand
|
||||
|
||||
; 0, initKeyboard
|
||||
initKeyboard:
|
||||
pushnil ; return value
|
||||
_private_2:
|
||||
pushi 4 100
|
||||
callnr inb 1
|
||||
pushi 3 1
|
||||
op2 12
|
||||
pushi 3 0
|
||||
op2 6
|
||||
jmp_if_not _private_3
|
||||
pushi 4 96
|
||||
calln inb 1
|
||||
|
||||
jmp _private_2
|
||||
_private_3:
|
||||
|
||||
ret
|
||||
; end of initKeyboard
|
||||
|
||||
; 1, main
|
||||
.export main
|
||||
main:
|
||||
pushnil ; return value
|
||||
pushnil ; i:INT
|
||||
; Here be dragons!
|
||||
pushnil ; i:INT32
|
||||
pusht "Initialize keyboard...\n"
|
||||
calln print 1
|
||||
|
||||
call initKeyboard 0
|
||||
|
||||
pusht "Hello World!\n"
|
||||
calln print 1
|
||||
|
||||
pushi 1
|
||||
pushi 2 1
|
||||
store 1
|
||||
|
||||
_private_0:
|
||||
_private_4:
|
||||
load 1
|
||||
pushi 5
|
||||
pushi 2 5
|
||||
op2 8
|
||||
jmp_if_not _private_1
|
||||
load 1
|
||||
jmp_if_not _private_5
|
||||
pusht "\n"
|
||||
load 1
|
||||
calln print 2
|
||||
|
||||
load 1
|
||||
pushi 1
|
||||
pushi 2 1
|
||||
op2 0
|
||||
store 1
|
||||
|
||||
jmp _private_0
|
||||
_private_1:
|
||||
jmp _private_4
|
||||
_private_5:
|
||||
|
||||
ret
|
||||
; end of main
|
||||
|
||||
; fndecl
|
||||
|
||||
; 1, irq
|
||||
.export irq
|
||||
irq:
|
||||
pushnil ; return value
|
||||
; Here be dragons!
|
||||
pusht "irq:"
|
||||
pushnil ; scancode:UINT8
|
||||
load -1
|
||||
pusht ", "
|
||||
load -2
|
||||
readfld eax
|
||||
pusht " "
|
||||
load -2
|
||||
readfld ebx
|
||||
pushi 2 33
|
||||
op2 5
|
||||
jmp_if_not _private_6
|
||||
pushi 4 96
|
||||
callnr inb 1
|
||||
store 1
|
||||
|
||||
pusht "\n"
|
||||
calln print 7
|
||||
load 1
|
||||
pusht "keypress: "
|
||||
calln print 3
|
||||
|
||||
_private_6:
|
||||
|
||||
ret
|
||||
; end of irq
|
||||
|
|
69
src/vm.cpp
69
src/vm.cpp
|
@ -53,6 +53,35 @@ ExceptionCode printArguments(VMValue &, const VMArray &args)
|
|||
return ExceptionCode::None;
|
||||
}
|
||||
|
||||
#include <io.h>
|
||||
|
||||
ExceptionCode vmOutB(VMValue &, const VMArray &args)
|
||||
{
|
||||
if(args.length() != 2)
|
||||
return ExceptionCode::InvalidArgument;
|
||||
if(args[0].type() != VMType::UInt16)
|
||||
return ExceptionCode::InvalidArgument;
|
||||
if(args[1].type() != VMType::UInt8)
|
||||
return ExceptionCode::InvalidArgument;
|
||||
|
||||
outb(args[0].value<VMUInt16>(), args[1].value<VMUInt8>());
|
||||
|
||||
return ExceptionCode::None;
|
||||
}
|
||||
|
||||
ExceptionCode vmInB(VMValue &result, const VMArray &args)
|
||||
{
|
||||
if(args.length() != 1)
|
||||
return ExceptionCode::InvalidArgument;
|
||||
if(args[0].type() != VMType::UInt16)
|
||||
return ExceptionCode::InvalidArgument;
|
||||
|
||||
result = VMValue::UInt8(
|
||||
inb(args[0].value<VMUInt16>()));
|
||||
|
||||
return ExceptionCode::None;
|
||||
}
|
||||
|
||||
struct dtortest {
|
||||
void *mem;
|
||||
|
||||
|
@ -89,6 +118,31 @@ extern "C" void vm_handle_interrupt(CpuState *state)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
const char *execptionName(ExceptionCode ex)
|
||||
{
|
||||
switch(ex) {
|
||||
#define CASE(ex) case ExceptionCode::ex: return #ex
|
||||
CASE(None);
|
||||
CASE(Terminated);
|
||||
CASE(InvalidOpcode);
|
||||
CASE(InvalidOperands);
|
||||
CASE(StackUnderflow);
|
||||
CASE(StackOverflow);
|
||||
CASE(DivideByZero);
|
||||
CASE(InvalidJump);
|
||||
CASE(CallrWithoutResult);
|
||||
|
||||
CASE(InvalidOperator);
|
||||
CASE(InvalidType);
|
||||
CASE(InvalidGlobal);
|
||||
CASE(NullPointer);
|
||||
CASE(InvalidMember);
|
||||
#undef CASE
|
||||
default: return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void vm_start()
|
||||
{
|
||||
// intr_set_handler(0x20, vm_handle_interrupt);
|
||||
|
@ -97,6 +151,8 @@ extern "C" void vm_start()
|
|||
VirtualMachine machine;
|
||||
machine.type("CPUSTATE") = csl::CpuStateType;
|
||||
machine.import("print") = printArguments;
|
||||
machine.import("inb") = vmInB;
|
||||
machine.import("outb") = vmOutB;
|
||||
|
||||
Assembly *assembly = machine.load(mainAssembly.ptr, mainAssembly.size);
|
||||
if(assembly == nullptr) {
|
||||
|
@ -110,8 +166,12 @@ extern "C" void vm_start()
|
|||
return;
|
||||
}
|
||||
|
||||
Thread *mainThread = irqService->mainThread();
|
||||
|
||||
uint32_t irqRoutine = irqService->assembly()->exports()["irq"];
|
||||
|
||||
bool osIsFailed = false;
|
||||
|
||||
while(machine.step())
|
||||
{
|
||||
// check for IRQ requests
|
||||
|
@ -144,7 +204,16 @@ extern "C" void vm_start()
|
|||
}
|
||||
irq_enable();
|
||||
} while(true);
|
||||
|
||||
if(mainThread->isRunning() == false) {
|
||||
if(osIsFailed == false) {
|
||||
osIsFailed = true;
|
||||
|
||||
kprintf("OS failed with: %s\n", execptionName(mainThread->exception()));
|
||||
}
|
||||
}
|
||||
}
|
||||
mainThread->release();
|
||||
|
||||
irqService->release();
|
||||
irqService = nullptr;
|
||||
|
|
Loading…
Reference in a new issue