int 0x80 is triggered (but nothing printed though)

* Better gdb options (hbreak)
* 255 isr can now be registered
* EarlyExceptionHandler is static
This commit is contained in:
Adrien Bourmault 2021-02-26 13:18:20 +01:00
parent fa525fe066
commit e00ce40c6e
9 changed files with 87 additions and 60 deletions

View File

@ -141,4 +141,10 @@ New member of our project : Antoine Cure is a new contributor
2020-02-12 @os-k-team <os-k-team@os-k.eu>
* ACPI : DSDT, MCFG are now detected and parseable
* PCI express : bus enumerating functionnal
* PCI express : bus enumerating functionnal
[...] Corona Time Skip
2021-02-26 @os-k-team <os-k-team@os-k.eu>
* Syscall : interrupt 0x80 will be used
* Userspace : new codesegment added

View File

@ -336,10 +336,11 @@ gdb: all installonimage
-hda $(installdisk) -no-reboot -no-shutdown -d \
cpu_reset,guest_errors,pcall,int -s -S 2> $(BUILDDIR)/qemu.log &
@gdb \
-ex "set arch i386:x86-64:intel" \
-ex "target remote localhost:1234" \
-ex "set arch i386:x86-64" \
-ex "target extended-remote localhost:1234" \
-ex "symbol-file $(BINDIR)/kaleid" \
-ex "break BtStartKern" \
-ex "hbreak BtStartKern" \
ddd: all installonimage
@setsid qemu-system-x86_64 -m $(ram) -enable-kvm -machine type=q35 -rtc base=localtime \
@ -352,10 +353,10 @@ gdbnokvm: all installonimage
-hda $(installdisk) -no-reboot -no-shutdown -d \
cpu_reset,guest_errors,pcall,int -s -S 2> $(BUILDDIR)/qemu.log &
@gdb \
-ex "set arch i386:x86-64:intel" \
-ex "target remote localhost:1234" \
-ex "set arch i386:x86-64" \
-ex "target extended-remote localhost:1234" \
-ex "symbol-file $(BINDIR)/kaleid" \
-ex "break BtStartKern" \
-ex "hbreak BtStartKern" \
dddnokvm: all installonimage
@setsid qemu-system-x86_64 -m $(ram) -machine type=q35 -rtc base=localtime \

View File

@ -43,8 +43,7 @@
├── build
│   ├── create_disk.sh
│   ├── install-os-k.sh
│   ├── kernel.ld
│   └── qemu.log
│   └── kernel.ld
├── docs
│   ├── boot
│   │   ├── grub
@ -180,4 +179,4 @@
├── ProjectTree
└── README.md
39 directories, 116 files
39 directories, 115 files

View File

@ -9,7 +9,9 @@ For changelog, see [ChangeLog](ChangeLog)
For structure of the sources, see [ProjectTree](ProjectTree)
For our IRC channel, see `#os.k-devel` on [Freenode](https://webchat.freenode.net)
We have an IRC channel, see `#os.k-devel` on [Freenode](https://webchat.freenode.net)
For our XMPP public chat, see [os-k-team@conference.os-k.eu](xmpp:os-k-team@conference.os-k.eu?join)
Note that every file within OS/K is written using spaces for tabulation, with each
tabulation being 4 spaces long.

View File

@ -91,6 +91,25 @@ void KeBrkDumpRegisters(ISRFrame_t *regs);
_isr1(0,1,2,3,4,5,6,7,8,9); _isr1(10,11,12,13,14,15,16,17,18,19);
_isr1(20,21,22,23,24,25,26,27,28,29); _isr1(30,31,32,33,34,35,36,37,38,39);
_isr1(40,41,42,43,44,45,46,47,48,49); _isr1(50,51,52,53,54,55,56,57,58,59);
_isr1(60,61,62,63,64,65,66,67,68,69); _isr1(70,71,72,73,74,75,76,77,78,79);
_isr1(80,81,82,83,84,85,86,87,88,89); _isr1(90,91,92,93,94,95,96,97,98,99);
_isr1(100,101,102,103,104,105,106,107,108,109);
_isr1(110,111,112,113,114,115,116,117,118,119);
_isr1(120,121,122,123,124,125,126,127,128,129);
_isr1(130,131,132,133,134,135,136,137,138,139);
_isr1(140,141,142,143,144,145,146,147,148,149);
_isr1(150,151,152,153,154,155,156,157,158,159);
_isr1(160,161,162,163,164,165,166,167,168,169);
_isr1(170,171,172,173,174,175,176,177,178,179);
_isr1(180,181,182,183,184,185,186,187,188,189);
_isr1(190,191,192,193,194,195,196,197,198,199);
_isr1(200,201,202,203,204,205,206,207,208,209);
_isr1(210,211,212,213,214,215,216,217,218,219);
_isr1(220,221,222,223,224,225,226,227,228,229);
_isr1(230,231,232,233,234,235,236,237,238,239);
_isr1(240,241,242,243,244,245,246,247,248,249);
_isr0(250,251,252,253,254);
void isr255();
#undef _isr1
#undef _isr0

View File

@ -99,6 +99,8 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
"This program comes with ABSOLUTELY NO WARRANTY.\n"
"This is free software, type `ver' for details.\n");
interrupt(0x80);
ShStartShell();
//KeCrashSystem();

View File

@ -74,13 +74,14 @@ static char *ExceptionsChar[32] = {
static void EnablePIC(void);
static void EarlyExceptionHandler(ISRFrame_t *regs);
static void DoubleFaultHandler(ISRFrame_t *regs);
static void EarlySyscallHandler(ISRFrame_t *regs);
//
// Registers an isr with his IRQ to handle driver interrupts
//
error_t KeRegisterISR(void (*isr)(ISRFrame_t *regs), uchar isrNo)
{
uchar n = isrList.n;
uchar n = isrList.n; // Number of registered entries
int OverWriting = 0;
assert(KeIdtIsInitialized); // IDT initialized
@ -88,14 +89,16 @@ error_t KeRegisterISR(void (*isr)(ISRFrame_t *regs), uchar isrNo)
if (n == 0) goto settingUp;
for (int i = 0; i < n; i++) {
if (isrNo == isrList.entry[i].isrNo) {
if (isrNo == isrList.entry[i].isrNo) { // If that isr is already
// registered, overwrite using
// the same entry
n = i;
OverWriting++;
break;
}
}
if ((n == 255)) // IRQs not filled
if ((n == 255)) // That IRQ cannot exists
return ENOMEM;
settingUp:
@ -132,10 +135,10 @@ void KeSetupIDT(void)
KeSetIDTGate(0x07, (ulong)isr7, codeSeg, 0x8E, 2); // XXX device not available, useful for FPU save/restore when multitasking
KeSetIDTGate(0x08, (ulong)isr8, codeSeg, 0x8E, 1); // DOUBLE FAULT
KeSetIDTGate(0x09, (ulong)isr9, codeSeg, 0x8E, 2);
KeSetIDTGate(0x0A, (ulong)isr10, codeSeg, 0x8E, 0); // INVALID TSS
KeSetIDTGate(0x0A, (ulong)isr10, codeSeg, 0x8E, 0); // INVALID TSS, 0 means don't use Interrupt Stack Table
KeSetIDTGate(0x0B, (ulong)isr11, codeSeg, 0x8E, 2);
KeSetIDTGate(0x0C, (ulong)isr12, codeSeg, 0x8E, 1); // STACK SEGMENT FAULT
KeSetIDTGate(0x0D, (ulong)isr13, codeSeg, 0x8E, 2);
KeSetIDTGate(0x0D, (ulong)isr13, codeSeg, 0x8E, 2); // GPF
KeSetIDTGate(0x0E, (ulong)isr14, codeSeg, 0x8E, 2);
KeSetIDTGate(0x0F, (ulong)isr15, codeSeg, 0x8E, 2); // INTEL RESERVED
KeSetIDTGate(0x10, (ulong)isr16, codeSeg, 0x8E, 2);
@ -156,7 +159,7 @@ void KeSetupIDT(void)
KeSetIDTGate(0x1F, (ulong)isr31, codeSeg, 0x8E, 2); // INTEL RESERVED
// Set IDT IRQs Gates
KeSetIDTGate(0x20, (ulong)isr32, codeSeg, 0x8E, 0);
KeSetIDTGate(0x20, (ulong)isr32, codeSeg, 0x8E, 0); // 0 means don't use Interrupt Stack Table
KeSetIDTGate(0x21, (ulong)isr33, codeSeg, 0x8E, 3);
KeSetIDTGate(0x22, (ulong)isr34, codeSeg, 0x8E, 3); // NEVER RAISED : cascaded
KeSetIDTGate(0x23, (ulong)isr35, codeSeg, 0x8E, 3);
@ -172,16 +175,20 @@ void KeSetupIDT(void)
KeSetIDTGate(0x2D, (ulong)isr45, codeSeg, 0x8E, 3);
KeSetIDTGate(0x2E, (ulong)isr46, codeSeg, 0x8E, 3);
KeSetIDTGate(0x2F, (ulong)isr47, codeSeg, 0x8E, 3);
// SYSCALL
KeSetIDTGate(0x80, (ulong)isr128, codeSeg, 0x8E, 3);
KeIdtIsInitialized++;
//Setup Early Exception handler
for (uchar i = 0 ; i < 0x20 ; i++) {
for (uchar i = 0 ; i < 0x2F ; i++) {
KeRegisterISR(EarlyExceptionHandler, i);
}
KeRegisterISR(KeBrkDumpRegisters, 0x3);
KeRegisterISR(DoubleFaultHandler, 0x8);
KeRegisterISR(EarlySyscallHandler, 0x80);
// Load IDT
KeLoadIDT();
@ -219,7 +226,7 @@ static void EnablePIC(void)
// Set ICW2 (IRQ base offsets)
IoWriteByteOnPort(0x21, 0x20); // 0x20 is the first free interrupt for IRQ0
IoWriteByteOnPort(0xa1, 0x28); // PIC2 is offseted to 0x28
IoWriteByteOnPort(0xa1, 0x28); // PIC2 is offseted to 0x28, just after PIC1
// Set ICW3
IoWriteByteOnPort(0x21, 0x4); // A slave exists
@ -320,7 +327,7 @@ void _KeHandleISR(ISRFrame_t *regs)
return; // INTEL RESERVED
// Spurious interrupt handling.
if (regs->intNo > 0x20 && !(KeGetIrqRegister(0x0b) & (1<<(regs->intNo - 0x20)))) {
if (regs->intNo >= 0x20 && regs->intNo <= 0x2F && !(KeGetIrqRegister(0x0b) & (1<<(regs->intNo - 0x20)))) {
KeSpuriousCount++;
return;
}
@ -384,6 +391,11 @@ static void DoubleFaultHandler(ISRFrame_t *regs)
KeHaltCPU();
}
static void EarlySyscallHandler(ISRFrame_t *regs)
{
DebugLog("Got a system call !\n");
}
void KeBrkDumpRegisters(ISRFrame_t *regs)
{
IoDoBeepNoIdt();

View File

@ -58,11 +58,11 @@ isrPreHandler:
push rax
; Check if we are switching from user mode to supervisor mode
mov rax, [rsp + 152]
and rax, 0x3000
jz .SEnter
;mov rax, [rsp + 152]
;and rax, 0x3000
;jz .SEnter
swapgs ; XXX need TSS
;swapgs ; XXX need TSS
.SEnter:
; Increment mask count as we configure all interrupts to mask IF
@ -79,11 +79,11 @@ isrPreHandler:
dec qword [gs:8]
; check if we are switching from supervisor to user mode
mov rax, [rsp + 152]
and rax, 0x3000
jz .SExit
;mov rax, [rsp + 152]
;and rax, 0x3000
;jz .SExit
swapgs ; XXX need TSS
;swapgs ; XXX need TSS
.SExit:
; pop the control registers
@ -176,7 +176,7 @@ IsrWithoutErrCode 31
;; IRQs
%assign i 32
%rep 225
%rep 255
IsrWithoutErrCode i
%assign i i+1
%endrep

View File

@ -27,13 +27,13 @@
#include <init/boot.h>
GdtPtr_t gdtPtr;
GdtEntry_t gdt[4] __attribute__((__aligned__(KPAGESIZE)));
GdtEntry_t gdt[5] __attribute__((__aligned__(KPAGESIZE)));
TssDescriptor_t tssDesc __attribute__((__aligned__(KPAGESIZE)));
Tss_t tss __attribute__((__aligned__(KPAGESIZE)));
void MmInitGdt(void)
{
ushort tssOffset = (ushort)((ulong)(&gdt[2]) - (ulong)(&gdt[0]));
ushort tssOffset = (ushort)((ulong)(&gdt[3]) - (ulong)(&gdt[0]));
gdtPtr.base = (ulong)&gdt[0];
gdtPtr.limit = sizeof(gdt) - 1;
@ -42,12 +42,14 @@ void MmInitGdt(void)
memzero((void *)&tssDesc, sizeof(tssDesc));
memzero((void *)&tss, sizeof(tss));
// Kernel codeseg
gdt[1].lowLimit = 0xFFFF;
gdt[1].access = 0x98;
gdt[1].flags = 0x20;
// User codeseg
gdt[2].lowLimit = 0xFFFF;
gdt[2].access = 0x98;
gdt[2].access = 0xF8;
gdt[2].flags = 0x20;
tssDesc.access = 0x89;
@ -61,6 +63,7 @@ void MmInitGdt(void)
tss.ist1 = (ulong)memalign(4*MB, 4*KB) + 4*MB; // ISR RESCUE STACK
tss.ist2 = (ulong)memalign(4*MB, 4*KB) + 4*MB; // ISR STACK
tss.ist3 = (ulong)memalign(4*MB, 4*KB) + 4*MB; // ISR STACK
tss.rsp0 = (ulong)memalign(4*MB, 4*KB) + 4*MB; // Another Stack
tss.iomap_base = sizeof(tss);
DebugLog("ISR Stacks initialized : Rescue %p, Normal %p, %p\n",
@ -68,34 +71,17 @@ void MmInitGdt(void)
tss.ist2,
tss.ist3);
memmove(&gdt[2], &tssDesc, sizeof(TssDescriptor_t));
memmove(&gdt[3], &tssDesc, sizeof(TssDescriptor_t));
DebugLog("TSS setting up :\n"
"gdt[0] %#x\n"
"gdt[2] %#x\n"
"access : %#x\n"
"flags : %#x\n"
"lowBase : %#x\n"
"middleBase : %#x\n"
"highBase : %#x\n"
"veryHighBase: %#x\n"
"lowLimit : %#x\n"
"ist : %#x\n"
"iomap_base : %#x\n"
"offset : %#x\n",
&gdt[0],
&gdt[2],
tssDesc.access,
tssDesc.flags,
tssDesc.lowBase,
tssDesc.middleBase,
tssDesc.highBase,
tssDesc.veryHighBase,
tssDesc.lowLimit,
tss.ist1,
tss.iomap_base,
tssOffset
);
DebugLog("GDT & TSS initialized\n");
DebugLog(" gdt[0] : %#x\n", &gdt[0]);
DebugLog(" gdt[1] : %#x\n", &gdt[1]);
DebugLog(" gdt[2] : %#x\n", &gdt[2]);
DebugLog(" tss : %#x\n", &gdt[3]);
DebugLog(" ist1 : %#x\n", tss.ist1);
DebugLog(" ist2 : %#x\n", tss.ist2);
DebugLog(" ist3 : %#x\n", tss.ist3);
DebugLog(" rsp0 : %#x\n", tss.ist1);
MmLoadGdt(&gdtPtr, tssOffset);
}