From 2c7f83e006c3fee8d26e940eee801a4be9443e50 Mon Sep 17 00:00:00 2001 From: neoraider Date: Mon, 18 Apr 2005 15:18:02 +0000 Subject: Verzeichnisstruktur ver?ndert --- system/Makefile | 6 + system/ansi.S | 74 +++++++++++++ system/hex.c | 31 ++++++ system/interrupt.S | 320 +++++++++++++++++++++++++++++++++++++++++++++++++++++ system/kernel.c | 115 +++++++++++++++++++ system/timer.c | 9 ++ 6 files changed, 555 insertions(+) create mode 100644 system/Makefile create mode 100644 system/ansi.S create mode 100644 system/hex.c create mode 100644 system/interrupt.S create mode 100644 system/kernel.c create mode 100644 system/timer.c (limited to 'system') diff --git a/system/Makefile b/system/Makefile new file mode 100644 index 0000000..ade470d --- /dev/null +++ b/system/Makefile @@ -0,0 +1,6 @@ +SYSTEM_FILES = system/kernel.o system/interrupt.o system/ansi.o system/hex.o system/timer.o + +system/system.o : $(SYSTEM_FILES) + @echo Linking $*.o + @ld -r -o $*.o $(SYSTEM_FILES) + @echo diff --git a/system/ansi.S b/system/ansi.S new file mode 100644 index 0000000..d1b5f55 --- /dev/null +++ b/system/ansi.S @@ -0,0 +1,74 @@ +/* ansi.S - ANSI conversion functions */ + +.text + +.global ansi2ascii, ascii2ansi + +ascii2ansi: + push %eax + push %ds + mov $16,%ax + mov %ax,%ds + xor %eax,%eax + mov %dl,%al + add $ascii2ansi_tab,%eax + mov (%eax),%dl + pop %ds + pop %eax + ret + + +ansi2ascii: + push %eax + push %ds + mov $16,%ax + mov %ax,%ds + xor %eax,%eax + mov %dl,%al + add $ansi2ascii_tab,%eax + mov (%eax),%dl + pop %ds + pop %eax + ret + + +.data + +ansi2ascii_tab: + +.byte 0, ' ', ' ', ' ', ' ', ' ', ' ', 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, ' ', ' ' +.byte ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' +.byte ' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/' +.byte '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?' +.byte '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O' +.byte 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_' +.byte '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o' +.byte 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', ' ' +.byte ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' +.byte ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' +.byte ' ', 0xAD, 0x9B, 0x9C, ' ', 0x9D, 0x7C, 0x15, ' ', ' ', 0xA6, 0xAE, 0xAA, 0x2D, ' ', ' ' +.byte 0xF8, 0xF1, 0xFD, ' ', 0x27, 0xE6, 0x14, 0xF9, ' ', ' ', 0xA7, 0xAF, 0xAC, 0xAB, ' ', 0xA8 +.byte ' ', ' ', ' ', ' ', 0x8E, 0x8F, 0x92, 0x80, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' +.byte ' ', 0xA5, ' ', ' ', ' ', ' ', 0x99, ' ', ' ', ' ', ' ', ' ', 0x9A, ' ', ' ', 0xE1 +.byte 0x85, 0xA0, 0x83, ' ', 0x84, 0x86, 0x91, 0x87, 0x8A, 0x82, 0x88, 0x89, 0x8D, 0xA1, 0x8C, 0x8B +.byte ' ', 0xA4, 0x95, 0xA2, 0x93, ' ', 0x94, ' ', ' ', 0x97, 0xA3, 0x96, 0x81, ' ', ' ', 0x98 + + +ascii2ansi_tab: + +.byte 0, ' ', ' ', ' ', ' ', ' ', ' ', 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, ' ', '*' +.byte ' ', ' ', ' ', '!', '¶', '§', '_', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' +.byte ' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/' +.byte '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?' +.byte '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O' +.byte 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_' +.byte '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o' +.byte 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', ' ' +.byte 'Ç', 'ü', 'é', 'â', 'ä', 'à', 'å', 'ç', 'ê', 'ë', 'è', 'ï', 'î', 'ì', 'Ä', 'Å' +.byte 'É', 'æ', 'Æ', 'ô', 'ö', 'ò', 'û', 'ù', 'ÿ', 'Ö', 'Ü', '¢', '£', '¥', ' ', ' ' +.byte 'á', 'í', 'ó', 'ú', 'ñ', 'Ñ', 'ª', 'º', '¿', ' ', '¬', '½', '¼', '¡', '«', '»' +.byte ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' +.byte ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' +.byte ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' +.byte ' ', ' ', ' ', ' ', ' ', ' ', 'µ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' +.byte ' ', '±', ' ', ' ', ' ', ' ', '÷', ' ', '°', '·', ' ', ' ', ' ', '²', '·', ' ' diff --git a/system/hex.c b/system/hex.c new file mode 100644 index 0000000..4374063 --- /dev/null +++ b/system/hex.c @@ -0,0 +1,31 @@ +/* hex.c - hexdecimal print functions */ + +#include + + +extern unsigned char console_std_attr; + +static char hex_values[16] = "0123456789ABCDEF"; + +void print_hex_byte(unsigned char hex) { + print_char(hex_values[(hex >> 4) & 0x0F]); + print_char(hex_values[hex & 0x0F]); +} + +void print_hex_word(unsigned short hex) { + print_char(hex_values[(hex >> 12) & 0x0F]); + print_char(hex_values[(hex >> 8) & 0x0F]); + print_char(hex_values[(hex >> 4) & 0x0F]); + print_char(hex_values[hex & 0x0F]); +} + +void print_hex_long(unsigned long hex) { + print_char(hex_values[(hex >> 28) & 0x0F]); + print_char(hex_values[(hex >> 24) & 0x0F]); + print_char(hex_values[(hex >> 20) & 0x0F]); + print_char(hex_values[(hex >> 16) & 0x0F]); + print_char(hex_values[(hex >> 12) & 0x0F]); + print_char(hex_values[(hex >> 8) & 0x0F]); + print_char(hex_values[(hex >> 4) & 0x0F]); + print_char(hex_values[hex & 0x0F]); +} diff --git a/system/interrupt.S b/system/interrupt.S new file mode 100644 index 0000000..3791ce2 --- /dev/null +++ b/system/interrupt.S @@ -0,0 +1,320 @@ +/* interrupt.S - interrupt handlers */ + +#include + +.text + +.global EXC_DIV_ERROR, EXC_DEBUG, EXC_NMI, EXC_BREAKPOINT +.global EXC_INTO_OVERFLOW, EXC_BOUND_OVERFLOW, EXC_INVAL_OPCODE, EXC_NO_COPROCESSOR +.global EXC_DOUBLE_EXCEPTION, EXC_COPROC_PROT_ERROR, EXC_INVAL_TSS, EXC_SEG_NOT_PRESENT +.global EXC_STACK_FAULT, EXC_GEN_PROT_VIOLATION, EXC_PAGE_FAULT, EXC_RESERVED +.global EXC_COPROCESSOR_ERROR, EXC_ALIGN_ERROR + +EXC_DIV_ERROR: + mov $16,%ax + mov %ax,%ds + pushl $exc_div_error_str + call print + addl $4,%esp + jmp looping + +EXC_DEBUG: + mov $16,%ax + mov %ax,%ds + pushl $exc_debug_str + call print + addl $4,%esp + jmp looping + +EXC_NMI: + mov $16,%ax + mov %ax,%ds + pushl $exc_nmi_str + call print + addl $4,%esp + jmp looping + +EXC_BREAKPOINT: + mov $16,%ax + mov %ax,%ds + pushl $exc_breakpoint_str + call print + addl $4,%esp + jmp looping + +EXC_INTO_OVERFLOW: + mov $16,%ax + mov %ax,%ds + pushl $exc_into_overflow_str + call print + addl $4,%esp + jmp looping + +EXC_BOUND_OVERFLOW: + mov $16,%ax + mov %ax,%ds + pushl $exc_bound_overflow_str + call print + addl $4,%esp + jmp looping + +EXC_INVAL_OPCODE: + mov $16,%ax + mov %ax,%ds + pushl $exc_inval_opcode_str + call print + addl $4,%esp + jmp looping + +EXC_NO_COPROCESSOR: + mov $16,%ax + mov %ax,%ds + pushl $exc_no_coprocessor_str + call print + addl $4,%esp + jmp looping + +EXC_DOUBLE_EXCEPTION: + mov $16,%ax + mov %ax,%ds + pushl $exc_double_exception_str + call print + addl $4,%esp + jmp looping + +EXC_COPROC_PROT_ERROR: + mov $16,%ax + mov %ax,%ds + pushl $exc_coproc_prot_error_str + call print + addl $4,%esp + jmp looping + +EXC_INVAL_TSS: + mov $16,%ax + mov %ax,%ds + pushl $exc_inval_tss_str + call print + addl $4,%esp + jmp looping + +EXC_SEG_NOT_PRESENT: + mov $16,%ax + mov %ax,%ds + pushl $exc_seg_not_present_str + call print + addl $4,%esp + jmp looping + +EXC_STACK_FAULT: + mov $16,%ax + mov %ax,%ds + pushl $exc_stack_fault_str + call print + addl $4,%esp + jmp looping + +EXC_GEN_PROT_VIOLATION: + mov $16,%ax + mov %ax,%ds + pushl $exc_gen_prot_violation_str + call print + addl $4,%esp + jmp looping + +EXC_PAGE_FAULT: + mov $16,%ax + mov %ax,%ds + pushl $exc_page_fault_str + call print + addl $4,%esp + jmp looping + +EXC_RESERVED: + mov $16,%ax + mov %ax,%ds + pushl $exc_reserved_str + call print + addl $4,%esp + jmp looping + +EXC_COPROCESSOR_ERROR: + mov $16,%ax + mov %ax,%ds + pushl $exc_coprocessor_error_str + call print + addl $4,%esp + jmp looping + +EXC_ALIGN_ERROR: + mov $16,%ax + mov %ax,%ds + pushl $exc_align_error_str + call print + addl $4,%esp + +looping: jmp looping + + +.data + +exc_div_error_str: .asciz "EXCEPTION: DIVIDE ERROR\r\n" +exc_debug_str: .asciz "EXCEPTION: DEBUG EXCEPTION\r\n" +exc_nmi_str: .asciz "EXCEPTION: NON-MASKABLE INTERRUPT\r\n" +exc_breakpoint_str: .asciz "EXCEPTION: BREAKPOINT\r\n" +exc_into_overflow_str: .asciz "EXCEPTION: OVERFLOW (INTO)\r\n" +exc_bound_overflow_str: .asciz "EXCEPTION: OVERFLOW (BOUND)\r\n" +exc_inval_opcode_str: .asciz "EXCEPTION: INVALID OPCODE\r\n" +exc_no_coprocessor_str: .asciz "EXCEPTION: NO COPROCESSOR\r\n" +exc_double_exception_str: .asciz "EXCEPTION: DOUBLE EXCEPTION\r\n" +exc_coproc_prot_error_str: .asciz "EXCEPTION: COPROCESSOR PROTECTION ERROR\r\n" +exc_inval_tss_str: .asciz "EXCEPTION: INVALID TSS SEGMENT\r\n" +exc_seg_not_present_str: .asciz "EXCEPTION: SEGMENT NOT PRESENT\r\n" +exc_stack_fault_str: .asciz "EXCEPTION: STACK FAULT\r\n" +exc_gen_prot_violation_str: .asciz "EXCEPTION: GENERAL PROTECTION VIOLATION\r\n" +exc_page_fault_str: .asciz "EXCEPTION: PAGE FAULT\r\n" +exc_reserved_str: .asciz "EXCEPTION: UNKNOWN ERROR\r\n" +exc_coprocessor_error_str: .asciz "EXCEPTION: COPROCESSOR ERROR\r\n" +exc_align_error_str: .asciz "EXCEPTION: ALIGNMENT ERROR\r\n" + + +.text + +.global IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7, IRQ8, IRQ9, IRQ10, IRQ11, IRQ12, IRQ13, IRQ14, IRQ15 + +IRQ0: + pusha + pushf + incb cur_blink_counter + cmpb $CUR_BLINK,cur_blink_counter + jb no_blink + subb $CUR_BLINK,cur_blink_counter + call console_cur_blink +no_blink: + cmpl $0,timers + je no_timer + decl timers +no_timer: + mov $0x20, %al + out %al, $0x20 + popf + popa + iret + +IRQ1: + push %ax + push %ds + push %edx + mov $16,%ax + mov %ax,%ds + in $0x60,%al + call kb_write_keycode + mov $0x20, %al + out %al, $0x20 + pop %edx + pop %ds + pop %ax + iret + +IRQ2: + push %ax + mov $0x20, %al + out %al, $0x20 + pop %ax + iret + +IRQ3: + push %ax + mov $0x20, %al + out %al, $0x20 + pop %ax + iret + +IRQ4: + push %ax + mov $0x20, %al + out %al, $0x20 + pop %ax + iret + +IRQ5: + push %ax + mov $0x20, %al + out %al, $0x20 + pop %ax + iret + +IRQ6: + #push %ax + pushf + pusha + call floppy_IRQ + mov $0x20, %al + out %al, $0x20 + #pop %ax + popa + popf + iret + +IRQ7: + push %ax + mov $0x20, %al + out %al, $0x20 + pop %ax + iret + +IRQ8: + push %ax + mov $0x20, %al + out %al, $0xA0 + pop %ax + iret + +IRQ9: + push %ax + mov $0x20, %al + out %al, $0xA0 + pop %ax + iret + +IRQ10: + push %ax + mov $0x20, %al + out %al, $0xA0 + pop %ax + iret + +IRQ11: + push %ax + mov $0x20, %al + out %al, $0xA0 + pop %ax + iret + +IRQ12: + push %ax + mov $0x20, %al + out %al, $0xA0 + pop %ax + iret + +IRQ13: + push %ax + mov $0x20, %al + out %al, $0xA0 + pop %ax + iret + +IRQ14: + push %ax + mov $0x20, %al + out %al, $0xA0 + pop %ax + iret + +IRQ15: + push %ax + mov $0x20, %al + out %al, $0xA0 + pop %ax + iret diff --git a/system/kernel.c b/system/kernel.c new file mode 100644 index 0000000..e8ad3a9 --- /dev/null +++ b/system/kernel.c @@ -0,0 +1,115 @@ +/* kernel.c - kernel functions */ + +#include +#include + + +extern unsigned char console_std_attr; +extern unsigned short console_cur_pos; +extern unsigned char console_flags; + +unsigned char numprint = 0; + +#define PRINT_ON if(numprint == 0) { \ + asm("cli");\ + console_cursor_off();\ + }\ + numprint++ + +#define PRINT_OFF numprint--;\ + if(numprint == 0) {\ + console_cursor_on();\ + asm("sti");\ + } + + +void print(unsigned char * text) { + print_attr(text, console_std_attr); +} + +void print_attr(unsigned char * text, unsigned char attr) { + PRINT_ON; + while(*text) { + print_char_attr(*text, attr); + text++; + } + PRINT_OFF; +} + +void print_char(unsigned char text) { + print_char_attr(text, console_std_attr); +} + +void print_char_attr(unsigned char text, unsigned char attr) { + PRINT_ON; + switch(text) { + case 0x08: // backspace + if(console_cur_pos) console_cur_pos--; + break; + case 0x09: // tab + console_cur_pos += (8 - (console_cur_pos % 8)); + break; + case 0x0A: // new line + console_cur_pos += (80 - (console_cur_pos % 80)); + break; + case 0x0B: // home + case 0x0C: // form feed + console_cur_pos = 0; + asm( + "cld\n" + "mov $32,%%ax\n" + "mov %%ax,%%es\n" + "xor %%edi,%%edi\n" + "mov %0,%%ah\n" + "mov $0x20,%%al\n" + "mov $2000,%%ecx\n" + "rep stosw" + : : "m" (attr) + ); + break; + case 0x0D: // carriage return + console_cur_pos -= (console_cur_pos % 80); + break; + default: + ANSI2ASCII(text); + asm( + "cld\n" + "mov $32,%%ax\n" + "mov %%ax,%%es\n" + "xor %%eax,%%eax\n" + "mov %0,%%ax\n" + "shl $1,%%eax\n" + "mov %%eax,%%edi\n" + "mov %1,%%al\n" + "mov %2,%%ah\n" + "stosw" + : : "m" (console_cur_pos), "m" (text), "m" (attr) + ); + console_cur_pos++; + } + // scroll + if(console_cur_pos >= 2000) { + console_cur_pos -= 80; + asm( + "cld\n" + "push %%ds\n" + + "mov $32,%%ax\n" + "mov %%ax,%%ds\n" + "mov %%ax,%%es\n" + "mov $1920,%%ecx\n" + "mov $160,%%esi\n" + "xor %%edi,%%edi\n" + "rep movsw\n" + + "mov $80,%%cx\n" + "mov %%cs:%0,%%ah\n" + "mov $0x20,%%al\n" + "rep stosw\n" + + "pop %%ds" + : : "m" (console_std_attr) + ); + } + PRINT_OFF; +} diff --git a/system/timer.c b/system/timer.c new file mode 100644 index 0000000..847cfb0 --- /dev/null +++ b/system/timer.c @@ -0,0 +1,9 @@ +#include +#include + +TIMER timers = {0}; + +void sleep(unsigned long ms) { + timers.time = (ms + 9)/10; + while(timers.time) asm("incl %0; decl %0" : "+m" (timers.time)); +} -- cgit v1.2.3