CTAOS v3
This commit is contained in:
79
SysCore/hal/isrs/BSOD.c
Normal file
79
SysCore/hal/isrs/BSOD.c
Normal file
@ -0,0 +1,79 @@
|
||||
#include <system.h>
|
||||
#include <conio.h>
|
||||
|
||||
char *exception_messages[] = {
|
||||
"Division By Zero Exception",
|
||||
"Debug Exception",
|
||||
"Non Maskable Interrupt Exception",
|
||||
"Breakpoint Exception",
|
||||
"Into Detected Overflow Exception",
|
||||
"Out of Bounds Exception",
|
||||
"Invalid Opcode Exception",
|
||||
"No Coprocessor",
|
||||
"Double Fault Exception",
|
||||
"Coprocessor Segment Overrun Exception",
|
||||
"Bad TSS Exception",
|
||||
"Segment Not Present Exception",
|
||||
"Stack Fault Exception",
|
||||
"General Protection Fault Exception",
|
||||
"Page Fault Exception",
|
||||
"Unknown Interrupt Exception",
|
||||
"Coprocessor Fault Exception",
|
||||
"Alignment Check Exception",
|
||||
"Machine Check Exception",
|
||||
"Reserved Exception",
|
||||
"Reserved Exception",
|
||||
"Reserved Exception",
|
||||
"Reserved Exception",
|
||||
"Reserved Exception",
|
||||
"Reserved Exception",
|
||||
"Reserved Exception",
|
||||
"Reserved Exception",
|
||||
"Reserved Exception",
|
||||
"Reserved Exception",
|
||||
"Reserved Exception",
|
||||
"Reserved Exception"
|
||||
};
|
||||
|
||||
|
||||
void _STOP_ERROR_SCREEN (ISR_stack_regs *r)
|
||||
{
|
||||
set_default_colors (0x01, 0x0F); clrscr();
|
||||
puts (" Blue Screen Of Death\n");
|
||||
int i; for (i = 79; i>=0; i--) putc('=');
|
||||
puts_pos_font (15, 2, "A fatal error has occured, CTA OS has been halted.", 0x01, 0x0C);
|
||||
puts_pos_font (10, 4, "gs", 0x01, 0x0B); put_hex_pos(15, 4, r->gs);
|
||||
puts_pos_font (10, 5, "fs", 0x01, 0x0B); put_hex_pos(15, 5, r->fs);
|
||||
puts_pos_font (10, 6, "es", 0x01, 0x0B); put_hex_pos(15, 6, r->es);
|
||||
puts_pos_font (10, 7, "ds", 0x01, 0x0B); put_hex_pos(15, 7, r->ds);
|
||||
|
||||
puts_pos_font (40, 4, "edi", 0x01, 0x0B); put_hex_pos(45, 4, r->edi);
|
||||
puts_pos_font (40, 5, "esi", 0x01, 0x0B); put_hex_pos(45, 5, r->esi);
|
||||
puts_pos_font (40, 6, "ebp", 0x01, 0x0B); put_hex_pos(45, 6, r->ebp);
|
||||
puts_pos_font (40, 7, "esp", 0x01, 0x0B); put_hex_pos(45, 7, r->esp);
|
||||
|
||||
puts_pos_font (10, 9, "eax", 0x01, 0x0B); put_hex_pos(15, 9, r->eax);
|
||||
puts_pos_font (10, 10, "ebx", 0x01, 0x0B); put_hex_pos(15, 10, r->ebx);
|
||||
puts_pos_font (40, 9, "ecx", 0x01, 0x0B); put_hex_pos(45, 9, r->ecx);
|
||||
puts_pos_font (40, 10, "edx", 0x01, 0x0B); put_hex_pos(45, 10, r->edx);
|
||||
|
||||
puts_pos_font (10, 12, "int_no", 0x01, 0x0B); put_hex_pos(17, 12, r->int_no);
|
||||
puts_pos_font (10, 14, "Error code:", 0x01, 0x0B); put_hex_pos(24, 14, r->err_code);
|
||||
puts_pos_font (10, 15, "Error msg: ", 0x01, 0x0B); puts_pos(24, 15, exception_messages[r->int_no]);
|
||||
|
||||
puts_pos_font (10, 17, "eip", 0x01, 0x0B); put_hex_pos(17, 17, r->eip);
|
||||
puts_pos_font (10, 18, "cs", 0x01, 0x0B); put_hex_pos(17, 18, r->cs);
|
||||
puts_pos_font (10, 19, "eflags", 0x01, 0x0B); put_hex_pos(17, 19, r->eflags);
|
||||
puts_pos_font (10, 20, "useresp", 0x01, 0x0B); put_hex_pos(17, 20, r->useresp);
|
||||
puts_pos_font (10, 21, "ss", 0x01, 0x0B); put_hex_pos(17, 21, r->ss);
|
||||
|
||||
puts_pos_font (29, 24, "!!! System Halted !!!", 0x01, 0x0C);
|
||||
}
|
||||
|
||||
/*void _STOP_ERROR_SCREEN (ISR_stack_regs *r)
|
||||
{
|
||||
puts_pos_font (30, 24, "Stop error 0x", 0x01, 0x0B); put_hex_pos(37, 24, r->int_no);
|
||||
puts_pos(50, 24, exception_messages[r->int_no]);
|
||||
|
||||
puts_pos_font (5, 24, "!!! System Halted !!!", 0x01, 0x0C);
|
||||
}*/
|
20
SysCore/hal/isrs/compile.bat
Normal file
20
SysCore/hal/isrs/compile.bat
Normal file
@ -0,0 +1,20 @@
|
||||
@echo off
|
||||
rem The name of the loader assembly file (without extension, must be .asm):
|
||||
set loader_name=loader
|
||||
|
||||
rem NASM and DJGPP executable paths:
|
||||
set nasm_path=C:\nasm
|
||||
set djgpp_path=C:\DJGPP\bin
|
||||
set objpath=../../objects
|
||||
set incpath=../../include
|
||||
|
||||
@echo on
|
||||
%nasm_path%\nasm.exe -f aout -o %objpath%/isrs_asm.o isrs.asm
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/isrs.o isrs.c
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/BSOD.o BSOD.c
|
||||
|
||||
@echo off
|
||||
@echo .
|
||||
@echo Done!
|
||||
|
||||
@pause
|
217
SysCore/hal/isrs/isrs.asm
Normal file
217
SysCore/hal/isrs/isrs.asm
Normal file
@ -0,0 +1,217 @@
|
||||
bits 32
|
||||
|
||||
; !!! ISRs !!!
|
||||
global _i86_isr0
|
||||
global _i86_isr1
|
||||
global _i86_isr2
|
||||
global _i86_isr3
|
||||
global _i86_isr4
|
||||
global _i86_isr5
|
||||
global _i86_isr6
|
||||
global _i86_isr7
|
||||
global _i86_isr8
|
||||
global _i86_isr9
|
||||
global _i86_isr10
|
||||
global _i86_isr11
|
||||
global _i86_isr12
|
||||
global _i86_isr13
|
||||
global _i86_isr14
|
||||
global _i86_isr15
|
||||
global _i86_isr16
|
||||
global _i86_isr17
|
||||
global _i86_isr18
|
||||
global _i86_isr19
|
||||
global _i86_isr20
|
||||
global _i86_isr21
|
||||
global _i86_isr22
|
||||
global _i86_isr23
|
||||
global _i86_isr24
|
||||
global _i86_isr25
|
||||
global _i86_isr26
|
||||
global _i86_isr27
|
||||
global _i86_isr28
|
||||
global _i86_isr29
|
||||
global _i86_isr30
|
||||
global _i86_isr31
|
||||
|
||||
_i86_isr0:
|
||||
cli
|
||||
push byte 0; A normal ISR stub that pops a dummy error code to keep a
|
||||
; uniform stack frame
|
||||
push byte 0
|
||||
jmp isr_common_stub
|
||||
_i86_isr1:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 1
|
||||
jmp isr_common_stub
|
||||
_i86_isr2:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 2
|
||||
jmp isr_common_stub
|
||||
_i86_isr3:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 3
|
||||
jmp isr_common_stub
|
||||
_i86_isr4:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 4
|
||||
jmp isr_common_stub
|
||||
_i86_isr5:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 5
|
||||
jmp isr_common_stub
|
||||
_i86_isr6:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 6
|
||||
jmp isr_common_stub
|
||||
_i86_isr7:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 7
|
||||
jmp isr_common_stub
|
||||
_i86_isr8:
|
||||
cli
|
||||
push byte 8
|
||||
jmp isr_common_stub
|
||||
_i86_isr9:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 9
|
||||
jmp isr_common_stub
|
||||
_i86_isr10:
|
||||
cli
|
||||
push byte 10
|
||||
jmp isr_common_stub
|
||||
_i86_isr11:
|
||||
cli
|
||||
push byte 11
|
||||
jmp isr_common_stub
|
||||
_i86_isr12:
|
||||
cli
|
||||
push byte 12
|
||||
jmp isr_common_stub
|
||||
_i86_isr13:
|
||||
cli
|
||||
push byte 13
|
||||
jmp isr_common_stub
|
||||
_i86_isr14:
|
||||
cli
|
||||
push byte 14
|
||||
jmp isr_common_stub
|
||||
_i86_isr15:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 15
|
||||
jmp isr_common_stub
|
||||
_i86_isr16:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 16
|
||||
jmp isr_common_stub
|
||||
_i86_isr17:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 17
|
||||
jmp isr_common_stub
|
||||
_i86_isr18:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 18
|
||||
jmp isr_common_stub
|
||||
_i86_isr19:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 19
|
||||
jmp isr_common_stub
|
||||
_i86_isr20:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 20
|
||||
jmp isr_common_stub
|
||||
_i86_isr21:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 21
|
||||
jmp isr_common_stub
|
||||
_i86_isr22:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 22
|
||||
jmp isr_common_stub
|
||||
_i86_isr23:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 23
|
||||
jmp isr_common_stub
|
||||
_i86_isr24:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 24
|
||||
jmp isr_common_stub
|
||||
_i86_isr25:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 25
|
||||
jmp isr_common_stub
|
||||
_i86_isr26:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 26
|
||||
jmp isr_common_stub
|
||||
_i86_isr27:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 27
|
||||
jmp isr_common_stub
|
||||
_i86_isr28:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 28
|
||||
jmp isr_common_stub
|
||||
_i86_isr29:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 29
|
||||
jmp isr_common_stub
|
||||
_i86_isr30:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 30
|
||||
jmp isr_common_stub
|
||||
_i86_isr31:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 31
|
||||
jmp isr_common_stub
|
||||
|
||||
extern _i86_fault_handler
|
||||
|
||||
isr_common_stub:
|
||||
pusha
|
||||
push ds
|
||||
push es
|
||||
push fs
|
||||
push gs
|
||||
mov ax, 0x10 ; Load the Kernel Data Segment descriptor!
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
mov eax, esp ; Push us the stack
|
||||
push eax
|
||||
mov eax, _i86_fault_handler
|
||||
call eax ; A special call, preserves the 'eip' register
|
||||
pop eax
|
||||
pop gs
|
||||
pop fs
|
||||
pop es
|
||||
pop ds
|
||||
popa
|
||||
add esp, 8 ; Cleans up the pushed error code and pushed ISR number
|
||||
iret ; pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP!
|
70
SysCore/hal/isrs/isrs.c
Normal file
70
SysCore/hal/isrs/isrs.c
Normal file
@ -0,0 +1,70 @@
|
||||
#include <system.h>
|
||||
#include "isrs.h"
|
||||
#include "../idt/idt.h"
|
||||
|
||||
extern void _STOP_ERROR_SCREEN(ISR_stack_regs *);
|
||||
/* This is a very repetitive function... it's not hard, it's
|
||||
* just annoying. As you can see, we set the first 32 entries
|
||||
* in the IDT to the first 32 ISRs. We can't use a for loop
|
||||
* for this, because there is no way to get the function names
|
||||
* that correspond to that given entry. We set the access
|
||||
* flags to 0x8E. This means that the entry is present, is
|
||||
* running in ring 0 (kernel level), and has the lower 5 bits
|
||||
* set to the required '14', which is represented by 'E' in
|
||||
* hex. */
|
||||
void i86_isrs_install()
|
||||
{
|
||||
i86_idt_set_gate(0, (unsigned)i86_isr0, 0x08, 0x8E);
|
||||
i86_idt_set_gate(1, (unsigned)i86_isr1, 0x08, 0x8E);
|
||||
i86_idt_set_gate(2, (unsigned)i86_isr2, 0x08, 0x8E);
|
||||
i86_idt_set_gate(3, (unsigned)i86_isr3, 0x08, 0x8E);
|
||||
i86_idt_set_gate(4, (unsigned)i86_isr4, 0x08, 0x8E);
|
||||
i86_idt_set_gate(5, (unsigned)i86_isr5, 0x08, 0x8E);
|
||||
i86_idt_set_gate(6, (unsigned)i86_isr6, 0x08, 0x8E);
|
||||
i86_idt_set_gate(7, (unsigned)i86_isr7, 0x08, 0x8E);
|
||||
i86_idt_set_gate(8, (unsigned)i86_isr8, 0x08, 0x8E);
|
||||
i86_idt_set_gate(9, (unsigned)i86_isr9, 0x08, 0x8E);
|
||||
i86_idt_set_gate(10, (unsigned)i86_isr10, 0x08, 0x8E);
|
||||
i86_idt_set_gate(11, (unsigned)i86_isr11, 0x08, 0x8E);
|
||||
i86_idt_set_gate(12, (unsigned)i86_isr12, 0x08, 0x8E);
|
||||
i86_idt_set_gate(13, (unsigned)i86_isr13, 0x08, 0x8E);
|
||||
i86_idt_set_gate(14, (unsigned)i86_isr14, 0x08, 0x8E);
|
||||
i86_idt_set_gate(15, (unsigned)i86_isr15, 0x08, 0x8E);
|
||||
i86_idt_set_gate(16, (unsigned)i86_isr16, 0x08, 0x8E);
|
||||
i86_idt_set_gate(17, (unsigned)i86_isr17, 0x08, 0x8E);
|
||||
i86_idt_set_gate(18, (unsigned)i86_isr18, 0x08, 0x8E);
|
||||
i86_idt_set_gate(19, (unsigned)i86_isr19, 0x08, 0x8E);
|
||||
i86_idt_set_gate(20, (unsigned)i86_isr20, 0x08, 0x8E);
|
||||
i86_idt_set_gate(21, (unsigned)i86_isr21, 0x08, 0x8E);
|
||||
i86_idt_set_gate(22, (unsigned)i86_isr22, 0x08, 0x8E);
|
||||
i86_idt_set_gate(23, (unsigned)i86_isr23, 0x08, 0x8E);
|
||||
i86_idt_set_gate(24, (unsigned)i86_isr24, 0x08, 0x8E);
|
||||
i86_idt_set_gate(25, (unsigned)i86_isr25, 0x08, 0x8E);
|
||||
i86_idt_set_gate(26, (unsigned)i86_isr26, 0x08, 0x8E);
|
||||
i86_idt_set_gate(27, (unsigned)i86_isr27, 0x08, 0x8E);
|
||||
i86_idt_set_gate(28, (unsigned)i86_isr28, 0x08, 0x8E);
|
||||
i86_idt_set_gate(29, (unsigned)i86_isr29, 0x08, 0x8E);
|
||||
i86_idt_set_gate(30, (unsigned)i86_isr30, 0x08, 0x8E);
|
||||
i86_idt_set_gate(31, (unsigned)i86_isr31, 0x08, 0x8E);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* All of our Exception handling Interrupt Service Routines will
|
||||
* point to this function. This will tell us what exception has
|
||||
* happened! Right now, we simply halt the system by hitting an
|
||||
* endless loop. All ISRs disable interrupts while they are being
|
||||
* serviced as a 'locking' mechanism to prevent an IRQ from
|
||||
* happening and messing up kernel data structures */
|
||||
void i86_fault_handler(ISR_stack_regs *r)
|
||||
{
|
||||
/* Is this a fault whose number is from 0 to 31? */
|
||||
if (r->int_no < 32)
|
||||
{
|
||||
_STOP_ERROR_SCREEN(r);
|
||||
/* Display the description for the Exception that occurred.*/
|
||||
|
||||
/* Put on the BSOD screen*/
|
||||
for (;;);
|
||||
}
|
||||
}
|
40
SysCore/hal/isrs/isrs.h
Normal file
40
SysCore/hal/isrs/isrs.h
Normal file
@ -0,0 +1,40 @@
|
||||
#ifndef __ISRS_H
|
||||
#define __ISRS_H
|
||||
|
||||
extern void i86_isr0();
|
||||
extern void i86_isr1();
|
||||
extern void i86_isr2();
|
||||
extern void i86_isr3();
|
||||
extern void i86_isr4();
|
||||
extern void i86_isr5();
|
||||
extern void i86_isr6();
|
||||
extern void i86_isr7();
|
||||
extern void i86_isr8();
|
||||
extern void i86_isr9();
|
||||
extern void i86_isr10();
|
||||
extern void i86_isr11();
|
||||
extern void i86_isr12();
|
||||
extern void i86_isr13();
|
||||
extern void i86_isr14();
|
||||
extern void i86_isr15();
|
||||
extern void i86_isr16();
|
||||
extern void i86_isr17();
|
||||
extern void i86_isr18();
|
||||
extern void i86_isr19();
|
||||
extern void i86_isr20();
|
||||
extern void i86_isr21();
|
||||
extern void i86_isr22();
|
||||
extern void i86_isr23();
|
||||
extern void i86_isr24();
|
||||
extern void i86_isr25();
|
||||
extern void i86_isr26();
|
||||
extern void i86_isr27();
|
||||
extern void i86_isr28();
|
||||
extern void i86_isr29();
|
||||
extern void i86_isr30();
|
||||
extern void i86_isr31();
|
||||
|
||||
extern void i86_isrs_install();
|
||||
extern void i86_fault_handler(ISR_stack_regs *r);
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user