GPT handler detects V86 mode; Interrupt printing fixes
This commit is contained in:
parent
192d4f04ed
commit
8bfcd4fd19
@ -68,7 +68,7 @@ inc al
|
|||||||
cmp eax, 200
|
cmp eax, 200
|
||||||
jl .loop
|
jl .loop
|
||||||
xor ebx, ebx
|
xor ebx, ebx
|
||||||
div bl
|
div bl ; Unhandled DIV0 exception
|
||||||
|
|
||||||
global jmp_usermode_test
|
global jmp_usermode_test
|
||||||
jmp_usermode_test:
|
jmp_usermode_test:
|
||||||
|
11
handler.nasm
11
handler.nasm
@ -12,10 +12,14 @@ jmp .hlt
|
|||||||
extern gpf_handler_v86
|
extern gpf_handler_v86
|
||||||
global gpfHandler
|
global gpfHandler
|
||||||
gpfHandler:
|
gpfHandler:
|
||||||
iret
|
push eax
|
||||||
mov ax, 0x10
|
mov ax, 0x10
|
||||||
mov ds, ax
|
mov ds, ax
|
||||||
;jmp gpf_handler_v86
|
mov eax, dword [esp+16] ; EFLAGS
|
||||||
|
and eax, 1 << 17 ; VM flag
|
||||||
|
test eax, eax
|
||||||
|
pop eax
|
||||||
|
jnz gpf_handler_v86
|
||||||
mov word [0xb8000], 0x0f00 | 'G'
|
mov word [0xb8000], 0x0f00 | 'G'
|
||||||
mov word [0xb8002], 0x0f00 | 'P'
|
mov word [0xb8002], 0x0f00 | 'P'
|
||||||
mov word [0xb8004], 0x0f00 | 'F'
|
mov word [0xb8004], 0x0f00 | 'F'
|
||||||
@ -71,8 +75,7 @@ kbd_wait:
|
|||||||
mov byte [KBDWAIT], 0
|
mov byte [KBDWAIT], 0
|
||||||
.loop:
|
.loop:
|
||||||
hlt
|
hlt
|
||||||
xor eax, eax
|
movzx eax, byte [KBDWAIT]
|
||||||
mov al, [KBDWAIT]
|
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz .loop
|
jz .loop
|
||||||
ret
|
ret
|
||||||
|
74
interrupt.c
74
interrupt.c
@ -1,10 +1,26 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#include "print.h"
|
|
||||||
|
|
||||||
#include "interrupt.h"
|
#include "interrupt.h"
|
||||||
|
|
||||||
|
char int_nibbleToHex(uint8_t n) {
|
||||||
|
return n > 9 ? (n - 10) + 'A' : n + '0';
|
||||||
|
}
|
||||||
|
void int_printByte(uint8_t v, uint16_t *buff) {
|
||||||
|
*(char *)&buff[0] = int_nibbleToHex((v >> 4) & 0xF);
|
||||||
|
*(char *)&buff[1] = int_nibbleToHex(v & 0xF);
|
||||||
|
}
|
||||||
|
__attribute((__no_caller_saved_registers__))
|
||||||
|
void int_printWord(uint16_t v, uint16_t *buff) {
|
||||||
|
int_printByte(v >> 8, buff);
|
||||||
|
int_printByte(v, &buff[2]);
|
||||||
|
}
|
||||||
|
__attribute((__no_caller_saved_registers__))
|
||||||
|
void int_printDword(uint32_t v, uint16_t *buff) {
|
||||||
|
int_printWord(v >> 16, buff);
|
||||||
|
int_printWord(v, &buff[4]);
|
||||||
|
}
|
||||||
|
|
||||||
struct __attribute__((__packed__)) IDTR_t {
|
struct __attribute__((__packed__)) IDTR_t {
|
||||||
uint16_t size;
|
uint16_t size;
|
||||||
uint32_t offset;
|
uint32_t offset;
|
||||||
@ -74,7 +90,7 @@ extern void jmp_usermode_test();
|
|||||||
#define VALID_FLAGS 0xDFF
|
#define VALID_FLAGS 0xDFF
|
||||||
__attribute__ ((interrupt))
|
__attribute__ ((interrupt))
|
||||||
void gpf_handler_v86(struct interrupt_frame *frame, unsigned long error_code) {
|
void gpf_handler_v86(struct interrupt_frame *frame, unsigned long error_code) {
|
||||||
asm volatile("mov %%ax,%%ds"::"a"(0x10));
|
//asm volatile("mov %%ax,%%ds"::"a"(0x10));
|
||||||
uint8_t *ip;
|
uint8_t *ip;
|
||||||
uint16_t *stack;
|
uint16_t *stack;
|
||||||
uint32_t *stack32;
|
uint32_t *stack32;
|
||||||
@ -84,17 +100,17 @@ void gpf_handler_v86(struct interrupt_frame *frame, unsigned long error_code) {
|
|||||||
stack32 = (uint32_t*)stack;
|
stack32 = (uint32_t*)stack;
|
||||||
|
|
||||||
char *vga = (char*)0xb8000 + (160 * 10);
|
char *vga = (char*)0xb8000 + (160 * 10);
|
||||||
vga[0] = 'I'; vga[2] = 'P'; printWord(frame->eip, &vga[4]); vga += 14;
|
vga[0] = 'I'; vga[2] = 'P'; int_printWord(frame->eip, (uint16_t*)&vga[4]); vga += 14;
|
||||||
vga[0] = 'C'; vga[2] = 'S'; printWord(frame->cs, &vga[4]); vga += 14;
|
vga[0] = 'C'; vga[2] = 'S'; int_printWord(frame->cs, (uint16_t*)&vga[4]); vga += 14;
|
||||||
vga[0] = 'F'; vga[2] = 'L'; printDword(frame->eflags, &vga[4]); vga += 14;
|
vga[0] = 'F'; vga[2] = 'L'; int_printDword(frame->eflags, (uint16_t*)&vga[4]); vga += 14;
|
||||||
vga = (char*)0xb8000 + (160 * 11);
|
vga = (char*)0xb8000 + (160 * 11);
|
||||||
vga[0] = 'S'; vga[2] = 'P'; printWord(frame->esp, &vga[4]); vga += 14;
|
vga[0] = 'S'; vga[2] = 'P'; int_printWord(frame->esp, (uint16_t*)&vga[4]); vga += 14;
|
||||||
vga[0] = 'S'; vga[2] = 'S'; printWord(frame->ss, &vga[4]); vga += 14;
|
vga[0] = 'S'; vga[2] = 'S'; int_printWord(frame->ss, (uint16_t*)&vga[4]); vga += 14;
|
||||||
vga = (char*)0xb8000 + (160 * 12);
|
vga = (char*)0xb8000 + (160 * 12);
|
||||||
vga[0] = 'E'; vga[2] = 'S'; printWord(frame->es, &vga[4]); vga += 14;
|
vga[0] = 'E'; vga[2] = 'S'; int_printWord(frame->es, (uint16_t*)&vga[4]); vga += 14;
|
||||||
vga[0] = 'D'; vga[2] = 'S'; printWord(frame->ds, &vga[4]); vga += 14;
|
vga[0] = 'D'; vga[2] = 'S'; int_printWord(frame->ds, (uint16_t*)&vga[4]); vga += 14;
|
||||||
vga[0] = 'F'; vga[2] = 'S'; printWord(frame->fs, &vga[4]); vga += 14;
|
vga[0] = 'F'; vga[2] = 'S'; int_printWord(frame->fs, (uint16_t*)&vga[4]); vga += 14;
|
||||||
vga[0] = 'G'; vga[2] = 'S'; printWord(frame->gs, &vga[4]); vga += 14;
|
vga[0] = 'G'; vga[2] = 'S'; int_printWord(frame->gs, (uint16_t*)&vga[4]); vga += 14;
|
||||||
|
|
||||||
//vga[2]++;
|
//vga[2]++;
|
||||||
//printDword(frame, &vga[20]);
|
//printDword(frame, &vga[20]);
|
||||||
@ -160,7 +176,7 @@ void gpf_handler_v86(struct interrupt_frame *frame, unsigned long error_code) {
|
|||||||
vga[0] = 'I'; vga[2]++; if (vga[2] < '0') vga[2] = '0';
|
vga[0] = 'I'; vga[2]++; if (vga[2] < '0') vga[2] = '0';
|
||||||
switch (ip[1]) {
|
switch (ip[1]) {
|
||||||
case 0x30:
|
case 0x30:
|
||||||
asm("jmp jmp_usermode_test");
|
asm ("jmp jmp_usermode_test");
|
||||||
for(;;);
|
for(;;);
|
||||||
case 0x3:
|
case 0x3:
|
||||||
kbd_wait();
|
kbd_wait();
|
||||||
@ -172,10 +188,10 @@ void gpf_handler_v86(struct interrupt_frame *frame, unsigned long error_code) {
|
|||||||
stack[1] = frame->cs;
|
stack[1] = frame->cs;
|
||||||
stack[2] = (uint16_t) frame->eflags;
|
stack[2] = (uint16_t) frame->eflags;
|
||||||
|
|
||||||
//if (v86_if)
|
if (v86_if)
|
||||||
// stack[2] |= EFLAG_IF;
|
stack[2] |= EFLAG_IF;
|
||||||
//else
|
else
|
||||||
// stack[2] &= ~EFLAG_IF;
|
stack[2] &= ~EFLAG_IF;
|
||||||
|
|
||||||
frame->cs = ivt[ip[1] * 2 + 1];
|
frame->cs = ivt[ip[1] * 2 + 1];
|
||||||
frame->eip = ivt[ip[1] * 2];
|
frame->eip = ivt[ip[1] * 2];
|
||||||
@ -201,19 +217,19 @@ void gpf_handler_v86(struct interrupt_frame *frame, unsigned long error_code) {
|
|||||||
for(;;);
|
for(;;);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
done:
|
done:;
|
||||||
vga = (char*)0xb8000 + (160 * 13);
|
vga = (char*)0xb8000 + (160 * 13);
|
||||||
vga[0] = 'I'; vga[2] = 'P'; printWord(frame->eip, &vga[4]); vga += 14;
|
vga[0] = 'I'; vga[2] = 'P'; int_printWord(frame->eip, (uint16_t*)&vga[4]); vga += 14;
|
||||||
vga[0] = 'C'; vga[2] = 'S'; printWord(frame->cs, &vga[4]); vga += 14;
|
vga[0] = 'C'; vga[2] = 'S'; int_printWord(frame->cs, (uint16_t*)&vga[4]); vga += 14;
|
||||||
vga[0] = 'F'; vga[2] = 'L'; printDword(frame->eflags, &vga[4]); vga += 14;
|
vga[0] = 'F'; vga[2] = 'L'; int_printDword(frame->eflags, (uint16_t*)&vga[4]); vga += 14;
|
||||||
vga = (char*)0xb8000 + (160 * 14);
|
vga = (char*)0xb8000 + (160 * 14);
|
||||||
vga[0] = 'S'; vga[2] = 'P'; printWord(frame->esp, &vga[4]); vga += 14;
|
vga[0] = 'S'; vga[2] = 'P'; int_printWord(frame->esp, (uint16_t*)&vga[4]); vga += 14;
|
||||||
vga[0] = 'S'; vga[2] = 'S'; printWord(frame->ss, &vga[4]); vga += 14;
|
vga[0] = 'S'; vga[2] = 'S'; int_printWord(frame->ss, (uint16_t*)&vga[4]); vga += 14;
|
||||||
vga = (char*)0xb8000 + (160 * 15);
|
vga = (char*)0xb8000 + (160 * 15);
|
||||||
vga[0] = 'E'; vga[2] = 'S'; printWord(frame->es, &vga[4]); vga += 14;
|
vga[0] = 'E'; vga[2] = 'S'; int_printWord(frame->es, (uint16_t*)&vga[4]); vga += 14;
|
||||||
vga[0] = 'D'; vga[2] = 'S'; printWord(frame->ds, &vga[4]); vga += 14;
|
vga[0] = 'D'; vga[2] = 'S'; int_printWord(frame->ds, (uint16_t*)&vga[4]); vga += 14;
|
||||||
vga[0] = 'F'; vga[2] = 'S'; printWord(frame->fs, &vga[4]); vga += 14;
|
vga[0] = 'F'; vga[2] = 'S'; int_printWord(frame->fs, (uint16_t*)&vga[4]); vga += 14;
|
||||||
vga[0] = 'G'; vga[2] = 'S'; printWord(frame->gs, &vga[4]); vga += 14;
|
vga[0] = 'G'; vga[2] = 'S'; int_printWord(frame->gs, (uint16_t*)&vga[4]); vga += 14;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void timerHandler();
|
extern void timerHandler();
|
||||||
@ -252,8 +268,8 @@ void setup_interrupts() {
|
|||||||
|
|
||||||
set_system_gate(0x20, timerHandler);
|
set_system_gate(0x20, timerHandler);
|
||||||
set_system_gate(0x21, keyboardHandler);
|
set_system_gate(0x21, keyboardHandler);
|
||||||
set_trap_gate(13, gpf_handler_v86);
|
//set_trap_gate(13, gpf_handler_v86);
|
||||||
//set_trap_gate(13, gpfHandler);
|
set_trap_gate(13, gpfHandler);
|
||||||
|
|
||||||
asm volatile("lidt %0": : "m"(IDTR));
|
asm volatile("lidt %0": : "m"(IDTR));
|
||||||
picInit();
|
picInit();
|
||||||
|
8
print.c
8
print.c
@ -1,24 +1,16 @@
|
|||||||
#include "print.h"
|
#include "print.h"
|
||||||
|
|
||||||
__attribute((__always_inline__))
|
|
||||||
__attribute((__no_caller_saved_registers__))
|
|
||||||
char nibbleToHex(uint8_t n) {
|
char nibbleToHex(uint8_t n) {
|
||||||
return n > 9 ? (n - 10) + 'A' : n + '0';
|
return n > 9 ? (n - 10) + 'A' : n + '0';
|
||||||
}
|
}
|
||||||
__attribute((__always_inline__))
|
|
||||||
__attribute((__no_caller_saved_registers__))
|
|
||||||
void printByte(uint8_t v, uint16_t *buff) {
|
void printByte(uint8_t v, uint16_t *buff) {
|
||||||
*(char *)&buff[0] = nibbleToHex((v >> 4) & 0xF);
|
*(char *)&buff[0] = nibbleToHex((v >> 4) & 0xF);
|
||||||
*(char *)&buff[1] = nibbleToHex(v & 0xF);
|
*(char *)&buff[1] = nibbleToHex(v & 0xF);
|
||||||
}
|
}
|
||||||
__attribute((__always_inline__))
|
|
||||||
__attribute((__no_caller_saved_registers__))
|
|
||||||
void printWord(uint16_t v, uint16_t *buff) {
|
void printWord(uint16_t v, uint16_t *buff) {
|
||||||
printByte(v >> 8, buff);
|
printByte(v >> 8, buff);
|
||||||
printByte(v, &buff[2]);
|
printByte(v, &buff[2]);
|
||||||
}
|
}
|
||||||
__attribute((__always_inline__))
|
|
||||||
__attribute((__no_caller_saved_registers__))
|
|
||||||
void printDword(uint32_t v, uint16_t *buff) {
|
void printDword(uint32_t v, uint16_t *buff) {
|
||||||
printWord(v >> 16, buff);
|
printWord(v >> 16, buff);
|
||||||
printWord(v, &buff[4]);
|
printWord(v, &buff[4]);
|
||||||
|
3
print.h
3
print.h
@ -1,9 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
__attribute((__no_caller_saved_registers__))
|
|
||||||
void printByte(uint8_t v, uint16_t *buff);
|
void printByte(uint8_t v, uint16_t *buff);
|
||||||
__attribute((__no_caller_saved_registers__))
|
|
||||||
void printWord(uint16_t v, uint16_t *buff);
|
void printWord(uint16_t v, uint16_t *buff);
|
||||||
__attribute((__no_caller_saved_registers__))
|
|
||||||
void printDword(uint32_t v, uint16_t *buff);
|
void printDword(uint32_t v, uint16_t *buff);
|
||||||
|
Loading…
Reference in New Issue
Block a user