package msgview
import (
"git.sr.ht/~sircmpwn/aerc/commands"
)
var (
MessageViewCommands *commands.Commands
)
func register(name string, cmd commands.AercCommand) pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */#include "screen.h"
#include "common.h"
#include "descriptortables.h"
#include "isr.h"
#include "process.h"
extern void flushGdt(uint32);
extern void flushIdt(uint32);
extern void flushTss();
static void initializeGdt();
static void initializeIdt();
static void setGdtEntry(int32 num, uint32 base, uint32 limit, uint8 access, uint8 gran);
static void setIdtEntry(uint8 num, uint32 base, uint16 sel, uint8 flags);
GdtEntry gGdtEntries[6];
GdtPointer gGdtPointer;
IdtEntry gIdtEntries[256];
IdtPointer gIdtPointer;
Tss gTss;
extern IsrFunction gInterruptHandlers[];
static void handleDoubleFault(Registers *regs);
static void handleGeneralProtectionFault(Registers *regs);
void initializeDescriptorTables() {
initializeGdt();
initializeIdt();
memset((uint8*)&gInterruptHandlers, 0, sizeof(IsrFunction)*256);
registerInterruptHandler(8, handleDoubleFault);
registerInterruptHandler(13, handleGeneralProtectionFault);
}
static void initializeGdt() {
gGdtPointer.limit = (sizeof(GdtEntry) * 6) - 1;
gGdtPointer.base = (uint32)&gGdtEntries;
setGdtEntry(0, 0, 0, 0, 0); // 0x00 Null segment
setGdtEntry(1, 0, 0xFFFFFFFF, 0x9A, 0xCF); // 0x08 Code segment
setGdtEntry(2, 0, 0xFFFFFFFF, 0x92, 0xCF); // 0x10 Data segment
setGdtEntry(3, 0, 0xFFFFFFFF, 0xFA, 0xCF); // 0x18 User mode code segment
setGdtEntry(4, 0, 0xFFFFFFFF, 0xF2, 0xCF); // 0x20 User mode data segment
//TSS
memset((uint8*)&gTss, 0, sizeof(gTss));
gTss.debug_flag = 0x00;
gTss.io_map = 0x00;
gTss.esp0 = 0;//0x1FFF0;
gTss.ss0 = 0x10;//0x18;
gTss.cs = 0x0B; //from ring 3 - 0x08 | 3 = 0x0B
gTss.ss = gTss.ds = gTss.es = gTss.fs = gTss.gs = 0x13; //from ring 3 = 0x10 | 3 = 0x13
uint32 tss_base = (uint32) &gTss;
uint32 tss_limit = tss_base + sizeof(gTss);
setGdtEntry(5, tss_base, tss_limit, 0xE9, 0x00);
flushGdt((uint32)&gGdtPointer);
flushTss();
}
// Set the value of one GDT entry.
static void setGdtEntry(int32 num, uint32 base, uint32 limit, uint8 access, uint8 gran) {
gGdtEntries[num].base_low = (base & 0xFFFF);
gGdtEntries[num].base_middle = (base >> 16) & 0xFF;
gGdtEntries[num].base_high = (base >> 24) & 0xFF;
gGdtEntries[num].limit_low = (limit & 0xFFFF);
gGdtEntries[num].granularity = (limit >> 16) & 0x0F;
gGdtEntries[num].granularity |= gran & 0xF0;
gGdtEntries[num].access = access;
}
void irqTimer();
static void initializeIdt() {
gIdtPointer.limit = sizeof(IdtEntry) * 256 -1;
gIdtPointer.base = (uint32)&gIdtEntries;
memset((uint8*)&gIdtEntries, 0, sizeof(IdtEntry)*256);
// Remap the irq table.
outb(0x20, 0x11);
outb(0xA0, 0x11);
outb(0x21, 0x20);
outb(0xA1, 0x28);
outb(0x21, 0x04);
outb(0xA1, 0x02);
outb(0x21, 0x01);
outb(0xA1, 0x01);
outb(0x21, 0x0);
outb(0xA1, 0x0);
setIdtEntry( 0, (uint32)isr0 , 0x08, 0x8E);
setIdtEntry( 1, (uint32)isr1 , 0x08, 0x8E);
setIdtEntry( 2, (uint32)isr2 , 0x08, 0x8E);
setIdtEntry( 3, (uint32)isr3 , 0x08, 0x8E);
setIdtEntry( 4, (uint32)isr4 , 0x08, 0x8E);
setIdtEntry( 5, (uint32)isr5 , 0x08, 0x8E);
setIdtEntry( 6, (uint32)isr6 , 0x08, 0x8E);
setIdtEntry( 7, (uint32)isr7 , 0x08, 0x8E);
setIdtEntry( 8, (uint32)isr8 , 0x08, 0x8E);
setIdtEntry( 9, (uint32)isr9 , 0x08, 0x8E);
setIdtEntry(10, (uint32)isr10, 0x08, 0x8E);
setIdtEntry(11, (uint32)isr11, 0x08, 0x8E);
setIdtEntry(12, (uint32)isr12, 0x08, 0x8E);
setIdtEntry(13, (uint32)isr13, 0x08, 0x8E);
setIdtEntry(14, (uint32)isr14, 0x08, 0x8E);
setIdtEntry(15, (uint32)isr15, 0x08, 0x8E);
setIdtEntry(16, (uint32)isr16, 0x08, 0x8E);
setIdtEntry(17, (uint32)isr17, 0x08, 0x8E);
setIdtEntry(18, (uint32)isr18, 0x08, 0x8E);
setIdtEntry(19, (uint32)isr19, 0x08, 0x8E);
setIdtEntry(20, (uint32)isr20, 0x08, 0x8E);
setIdtEntry(21, (uint32)isr21, 0x08, 0x8E);
setIdtEntry(22, (uint32)isr22, 0x08, 0x8E);
setIdtEntry(23, (uint32)isr23, 0x08, 0x8E);
setIdtEntry(24, (uint32)isr24, 0x08, 0x8E);
setIdtEntry(25, (uint32)isr25, 0x08, 0x8E);
setIdtEntry(26, (uint32)isr26, 0x08, 0x8E);
setIdtEntry(27, (uint32)isr27, 0x08, 0x8E);
setIdtEntry(28, (uint32)isr28, 0x08, 0x8E);
setIdtEntry(29, (uint32)isr29, 0x08, 0x8E);
setIdtEntry(30, (uint32)isr30, 0x08, 0x8E);
setIdtEntry(31, (uint32)isr31, 0x08, 0x8E);
setIdtEntry(32, (uint32)irqTimer, 0x08, 0x8E);
setIdtEntry(33, (uint32)irq1, 0x08, 0x8E);
setIdtEntry(34, (uint32)irq2, 0x08, 0x8E);
setIdtEntry(35, (uint32)irq3, 0x08, 0x8E);
setIdtEntry(36, (uint32)irq4, 0x08, 0x8E);
setIdtEntry(37, (uint32)irq5, 0x08, 0x8E);
setIdtEntry(38, (uint32)irq6, 0x08, 0x8E);
setIdtEntry(39, (uint32)irq7, 0x08, 0x8E);
setIdtEntry(40, (uint32)irq8, 0x08, 0x8E);
setIdtEntry(41, (uint32)irq9, 0x08, 0x8E);
setIdtEntry(42, (uint32)irq10, 0x08, 0x8E);
setIdtEntry(43, (uint32)irq11, 0x08, 0x8E);
setIdtEntry(44, (uint32)irq12, 0x08, 0x8E);
setIdtEntry(45, (uint32)irq13, 0x08, 0x8E);
setIdtEntry(46, (uint32)irq14, 0x08, 0x8E);
setIdtEntry(47, (uint32)irq15, 0x08, 0x8E);
setIdtEntry(128, (uint32)isr128, 0x08, 0x8E);
flushIdt((uint32)&gIdtPointer);
}
static void setIdtEntry(uint8 num, uint32 base, uint16 sel, uint8 flags) {
gIdtEntries[num].base_lo = base & 0xFFFF;
gIdtEntries[num].base_hi = (base >> 16) & 0xFFFF;
gIdtEntries[num].sel = sel;
gIdtEntries[num].always0 = 0;
gIdtEntries[num].flags = flags | 0x60;
}
static void handleDoubleFault(Registers *regs) {
printkf("Double fault!!! Error code:%d\n", regs->errorCode);
PANIC("Double fault!!!");
}
static void handleGeneralProtectionFault(Registers *regs) {
printkf("General protection fault!!! Error code:%d - IP:%x\n", regs->errorCode, regs->eip);
Thread* faultingThread = getCurrentThread();
if (NULL != faultingThread) {
Thread* mainThread = getMainKernelThread();
if (mainThread == faultingThread) {
PANIC("General protection fault in Kernel main thread!!!");
}
else {
printkf("Faulting thread is %d\n", faultingThread->threadId);
if (faultingThread->userMode) {
printkf("Destroying process %d\n", faultingThread->owner->pid);
destroyProcess(faultingThread->owner);
}
else {
printkf("Destroying kernel thread %d\n", faultingThread->threadId);
destroyThread(faultingThread);
}
waitForSchedule();
}
}
else {
PANIC("General protection fault!!!");
}
}