diff --git a/Worksheet2_2/Makefile b/Worksheet2_2/Makefile deleted file mode 100644 index c63025fc3f287d073e4a7679d032850d35638103..0000000000000000000000000000000000000000 --- a/Worksheet2_2/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -LD = ld -CC = gcc -CFLAGS = -m32 -ffreestanding -nostdlib -fno-stack-protector -AS = nasm -ASFLAGS = -f elf - -SRC_DIR = . -SOURCES = $(SRC_DIR)/kmain.c $(SRC_DIR)/pic.c $(SRC_DIR)/interrupts.c $(SRC_DIR)/keyboard.c -ASM_SOURCES = $(SRC_DIR)/io.s $(SRC_DIR)/interrupt_asm.s $(SRC_DIR)/interrupt_handlers.s -OBJECTS = $(SOURCES:.c=.o) $(ASM_SOURCES:.s=.o) - -all: kernel.elf - -kernel.elf: $(OBJECTS) - $(LD) -m elf_i386 -Ttext 0x1000 -o kernel.elf $(OBJECTS) - -$(SRC_DIR)/%.o: $(SRC_DIR)/%.c - $(CC) $(CFLAGS) -c $< -o $@ - -$(SRC_DIR)/%.o: $(SRC_DIR)/%.s - $(AS) $(ASFLAGS) $< -o $@ - -clean: - rm -f $(SRC_DIR)/*.o kernel.elf diff --git a/Worksheet2_2/frame_buffer.c b/Worksheet2_2/frame_buffer.c deleted file mode 100644 index f6eff01b49a2445bc73c67ae81da4607ab533306..0000000000000000000000000000000000000000 --- a/Worksheet2_2/frame_buffer.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "frame_buffer.h" -#include "io.h" - -#define FRAME_BUFFER_ADDRESS 0xB8000 -#define MAX_COLS 80 -#define MAX_ROWS 25 - -void fb_write_cell(u32int index, char c, u8int fg, u8int bg) { - volatile char *fb = (volatile char *)FRAME_BUFFER_ADDRESS; - fb[index * 2] = c; - fb[index * 2 + 1] = (bg << 4) | (fg & 0x0F); -} diff --git a/Worksheet2_2/frame_buffer.h b/Worksheet2_2/frame_buffer.h deleted file mode 100644 index 2351f7ea637d45b54e63d4f22a2d01d2203b6c54..0000000000000000000000000000000000000000 --- a/Worksheet2_2/frame_buffer.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef INCLUDE_FRAME_BUFFER_H -#define INCLUDE_FRAME_BUFFER_H - -#include "types.h" - -#define FB_DARK_GREY 8 -#define FB_GREEN 2 - -void fb_write_cell(u32int index, char c, u8int fg, u8int bg); - -#endif diff --git a/Worksheet2_2/hardware_interrupt_enabler.s b/Worksheet2_2/hardware_interrupt_enabler.s deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/Worksheet2_2/interrupt_asm.o b/Worksheet2_2/interrupt_asm.o deleted file mode 100644 index c189cad33ad2baedfad434b3ae14e29085b216ca..0000000000000000000000000000000000000000 Binary files a/Worksheet2_2/interrupt_asm.o and /dev/null differ diff --git a/Worksheet2_2/interrupt_asm.s b/Worksheet2_2/interrupt_asm.s deleted file mode 100644 index da09acbed2ae8894d896b24cec82d4f87805a5f0..0000000000000000000000000000000000000000 --- a/Worksheet2_2/interrupt_asm.s +++ /dev/null @@ -1,6 +0,0 @@ -global load_idt - -load_idt: - mov eax, [esp + 4] - lidt [eax] - ret diff --git a/Worksheet2_2/interrupt_handlers.o b/Worksheet2_2/interrupt_handlers.o deleted file mode 100644 index 3c001059dbf17659fcea2285aa91ae9f13215e8e..0000000000000000000000000000000000000000 Binary files a/Worksheet2_2/interrupt_handlers.o and /dev/null differ diff --git a/Worksheet2_2/interrupt_handlers.s b/Worksheet2_2/interrupt_handlers.s deleted file mode 100644 index 35fa4bcc3e9305e1f9742fc3e665a33fba633111..0000000000000000000000000000000000000000 --- a/Worksheet2_2/interrupt_handlers.s +++ /dev/null @@ -1,17 +0,0 @@ -extern interrupt_handler - -%macro no_error_code_interrupt_handler 1 -global interrupt_handler_%1 -interrupt_handler_%1: - push dword 0 - push dword %1 - jmp common_interrupt_handler -%endmacro - -common_interrupt_handler: - pushad - call interrupt_handler - popad - iret - -no_error_code_interrupt_handler 33 diff --git a/Worksheet2_2/interrupts.c b/Worksheet2_2/interrupts.c deleted file mode 100644 index 80e84cce4229f80f93dcc9d399936a13bc5bde3e..0000000000000000000000000000000000000000 --- a/Worksheet2_2/interrupts.c +++ /dev/null @@ -1,115 +0,0 @@ -#include "interrupts.h" -#include "pic.h" -#include "io.h" -#include "frame_buffer.h" -#include "keyboard.h" -#include "types.h" - -#define INTERRUPTS_DESCRIPTOR_COUNT 256 -#define INTERRUPTS_KEYBOARD 33 -#define INPUT_BUFFER_SIZE 256 - -u8int input_buffer[INPUT_BUFFER_SIZE]; -u8int buffer_index = 0; - -struct IDTDescriptor idt_descriptors[INTERRUPTS_DESCRIPTOR_COUNT]; -struct IDT idt; - -u32int BUFFER_COUNT; - -void interrupts_init_descriptor(s32int index, u32int address) -{ - idt_descriptors[index].offset_high = (address >> 16) & 0xFFFF; // offset bits 0..15 - idt_descriptors[index].offset_low = (address & 0xFFFF); // offset bits 16..31 - - idt_descriptors[index].segment_selector = 0x08; // The second (code) segment selector in GDT: one segment is 64b. - idt_descriptors[index].reserved = 0x00; // Reserved. - - /* - Bit: | 31 16 | 15 | 14 13 | 12 | 11 10 9 8 | 7 6 5 | 4 3 2 1 0 | - Content: | offset high | P | DPL | S | D and GateType | 0 0 0 | reserved - P If the handler is present in memory or not (1 = present, 0 = not present). Set to 0 for unused interrupts or for Paging. - DPL Descriptor Privilige Level, the privilege level the handler can be called from (0, 1, 2, 3). - S Storage Segment. Set to 0 for interrupt gates. - D Size of gate, (1 = 32 bits, 0 = 16 bits). - */ - idt_descriptors[index].type_and_attr = (0x01 << 7) | // P - (0x00 << 6) | (0x00 << 5) | // DPL - 0xe; // 0b1110=0xE 32-bit interrupt gate -} - -void interrupts_install_idt() -{ - - interrupts_init_descriptor(INTERRUPTS_KEYBOARD, (u32int) interrupt_handler_33); - - - idt.address = (s32int) &idt_descriptors; - idt.size = sizeof(struct IDTDescriptor) * INTERRUPTS_DESCRIPTOR_COUNT; - load_idt((s32int) &idt); - - /*pic_remap(PIC_PIC1_OFFSET, PIC_PIC2_OFFSET);*/ - pic_remap(PIC_1_OFFSET, PIC_2_OFFSET); - - // Unmask keyboard interrupt (IRQ1) - outb(0x21, inb(0x21) & ~(1 << 1)); -} - - -/* Interrupt handlers ********************************************************/ - -void interrupt_handler(__attribute__((unused)) struct cpu_state cpu, u32int interrupt, __attribute__((unused)) struct stack_state stack) { - u8int input; - u8int ascii; - static u32int fe_count = 0; - static u32int debug_count = 0; - - switch (interrupt) { - case INTERRUPTS_KEYBOARD: - while ((inb(0x64) & 1)) { - input = keyboard_read_scan_code(); - - // Debug output - /*fb_write_cell(debug_count * 3 + 0, 'x', FB_GREEN, FB_DARK_GREY); - fb_write_cell(debug_count * 3 + 1, "0123456789ABCDEF"[input >> 4], FB_GREEN, FB_DARK_GREY); - fb_write_cell(debug_count * 3 + 2, "0123456789ABCDEF"[input & 0xF], FB_GREEN, FB_DARK_GREY);*/ - debug_count++; - - // Track FE codes - if (input == 0xFE) { - fe_count++; - continue; - } - - // Only process if it's not a break code - if (!(input & 0x80)) { - if (input <= KEYBOARD_MAX_ASCII) { - ascii = keyboard_scan_code_to_ascii(input); - if (ascii != 0) { - if (ascii == '\b') { - if (BUFFER_COUNT > 0) { - BUFFER_COUNT--; - fb_write_cell(BUFFER_COUNT, ' ', FB_DARK_GREY, FB_GREEN); - } - } - else if (ascii == '\n') { - BUFFER_COUNT = ((BUFFER_COUNT / 80) + 1) * 80; - } - else { - fb_write_cell(BUFFER_COUNT, ascii, FB_DARK_GREY, FB_GREEN); - BUFFER_COUNT++; - } - } - } - } - - buffer_index = (buffer_index + 1) % INPUT_BUFFER_SIZE; - } - - pic_acknowledge(interrupt); - break; - - default: - break; - } -} \ No newline at end of file diff --git a/Worksheet2_2/interrupts.h b/Worksheet2_2/interrupts.h deleted file mode 100644 index be53adce00c6327ba977e3376b80ae44300eba45..0000000000000000000000000000000000000000 --- a/Worksheet2_2/interrupts.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef INCLUDE_INTERRUPTS_H -#define INCLUDE_INTERRUPTS_H - -#include "types.h" - -struct IDT { - u16int size; - u32int address; -} __attribute__((packed)); - -struct IDTDescriptor { - u16int offset_low; - u16int segment_selector; - u8int reserved; - u8int type_and_attr; - u16int offset_high; -} __attribute__((packed)); - -struct cpu_state { - u32int eax; - u32int ebx; - u32int ecx; - u32int edx; - u32int esi; - u32int edi; - u32int ebp; -} __attribute__((packed)); - -struct stack_state { - u32int error_code; - u32int eip; - u32int cs; - u32int eflags; -} __attribute__((packed)); - -void interrupts_install_idt(); -void interrupt_handler_33(); -void load_idt(u32int idt_address); // Declaration for the `load_idt` function - -#endif diff --git a/Worksheet2_2/interrupts.o b/Worksheet2_2/interrupts.o deleted file mode 100644 index 0979c78593cea0b72d4753ce773c4c1251ec9911..0000000000000000000000000000000000000000 Binary files a/Worksheet2_2/interrupts.o and /dev/null differ diff --git a/Worksheet2_2/io.h b/Worksheet2_2/io.h deleted file mode 100644 index 79bcf8c3ebc85981e15a792e7fd55c2acc6fff49..0000000000000000000000000000000000000000 --- a/Worksheet2_2/io.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef INCLUDE_IO_H -#define INCLUDE_IO_H - -void outb(unsigned short port, unsigned char value); // Writes a byte to the given I/O port -unsigned char inb(unsigned short port); // Reads a byte from the given I/O port - -#endif diff --git a/Worksheet2_2/io.o b/Worksheet2_2/io.o deleted file mode 100644 index 5eeb851de12d0a5f894a747042e4a05b097f548b..0000000000000000000000000000000000000000 Binary files a/Worksheet2_2/io.o and /dev/null differ diff --git a/Worksheet2_2/io.s b/Worksheet2_2/io.s deleted file mode 100644 index da2d5f99d6a9bd2471ef39bdb7c4cdfba6968ed7..0000000000000000000000000000000000000000 --- a/Worksheet2_2/io.s +++ /dev/null @@ -1,9 +0,0 @@ -global outb - -; outb - Writes a byte to the given I/O port -; Parameters: AL contains the byte to write, DX contains the port address -outb: - mov dx, [esp + 4] ; Load the I/O port address into DX - mov al, [esp + 8] ; Load the value into AL - out dx, al ; Write the value to the port - ret diff --git a/Worksheet2_2/keyboard.c b/Worksheet2_2/keyboard.c deleted file mode 100644 index 56a7d6cb711a1664c90720032fde3d4e8298acbc..0000000000000000000000000000000000000000 --- a/Worksheet2_2/keyboard.c +++ /dev/null @@ -1,43 +0,0 @@ -#include "keyboard.h" -#include "io.h" - -#define KEYBOARD_DATA_PORT 0x60 - -u8int keyboard_read_scan_code() { - return inb(KEYBOARD_DATA_PORT); -} - -u8int keyboard_scan_code_to_ascii(u8int scan_code) { - switch (scan_code) { - case 0x1E: return 'a'; - case 0x30: return 'b'; - case 0x2E: return 'c'; - case 0x20: return 'd'; - case 0x12: return 'e'; - case 0x21: return 'f'; - case 0x22: return 'g'; - case 0x23: return 'h'; - case 0x17: return 'i'; - case 0x24: return 'j'; - case 0x25: return 'k'; - case 0x26: return 'l'; - case 0x32: return 'm'; - case 0x31: return 'n'; - case 0x18: return 'o'; - case 0x19: return 'p'; - case 0x10: return 'q'; - case 0x13: return 'r'; - case 0x1F: return 's'; - case 0x14: return 't'; - case 0x16: return 'u'; - case 0x2F: return 'v'; - case 0x11: return 'w'; - case 0x2D: return 'x'; - case 0x15: return 'y'; - case 0x2C: return 'z'; - case 0x39: return ' '; - case 0x0E: return '\b'; - case 0x1C: return '\n'; - default: return 0; - } -} diff --git a/Worksheet2_2/keyboard.h b/Worksheet2_2/keyboard.h deleted file mode 100644 index aea190f689a0228df4fb33cbbaa50b17dea1f8aa..0000000000000000000000000000000000000000 --- a/Worksheet2_2/keyboard.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef INCLUDE_KEYBOARD_H -#define INCLUDE_KEYBOARD_H - -#include "types.h" - -#define KEYBOARD_MAX_ASCII 127 // Maximum ASCII value supported by the keyboard - -u8int keyboard_read_scan_code(); -u8int keyboard_scan_code_to_ascii(u8int scan_code); - -#endif diff --git a/Worksheet2_2/keyboard.o b/Worksheet2_2/keyboard.o deleted file mode 100644 index 7b401d5ea7ed604a6cb2ccef719e7e63d1bc2981..0000000000000000000000000000000000000000 Binary files a/Worksheet2_2/keyboard.o and /dev/null differ diff --git a/Worksheet2_2/kmain.c b/Worksheet2_2/kmain.c deleted file mode 100644 index 4806ffe101da8c1e900539f593ddcf8b63fcb8ef..0000000000000000000000000000000000000000 --- a/Worksheet2_2/kmain.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "interrupts.h" -#include "pic.h" -#include "keyboard.h" - -void kmain() { - // Initialize IDT and interrupts - interrupts_install_idt(); - - // Main terminal loop - while (1) { - // Continuously process user input - } -} diff --git a/Worksheet2_2/kmain.o b/Worksheet2_2/kmain.o deleted file mode 100644 index d7f6124a36047132193b1be82c5ec58f7dbeb105..0000000000000000000000000000000000000000 Binary files a/Worksheet2_2/kmain.o and /dev/null differ diff --git a/Worksheet2_2/loader.s b/Worksheet2_2/loader.s deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/Worksheet2_2/pic.c b/Worksheet2_2/pic.c deleted file mode 100644 index 2e598792815eda23f5efea33088ef0006beaa3b7..0000000000000000000000000000000000000000 --- a/Worksheet2_2/pic.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "io.h" -#include "pic.h" -#include "types.h" - -void pic_remap(s32int offset1, s32int offset2) { - outb(PIC_1, 0x11); - outb(PIC_2, 0x11); - outb(PIC_1 + 1, offset1); - outb(PIC_2 + 1, offset2); - outb(PIC_1 + 1, 0x04); - outb(PIC_2 + 1, 0x02); - outb(PIC_1 + 1, 0x01); - outb(PIC_2 + 1, 0x01); -} - -void pic_acknowledge(u32int interrupt) { - if (interrupt < 40) outb(PIC_1, 0x20); - if (interrupt >= 40) outb(PIC_2, 0x20); -} diff --git a/Worksheet2_2/pic.h b/Worksheet2_2/pic.h deleted file mode 100644 index b3fda581ed8d1eb427c14e0a9589811850db0951..0000000000000000000000000000000000000000 --- a/Worksheet2_2/pic.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef INCLUDE_PIC_H -#define INCLUDE_PIC_H - -#include "types.h" - -#define PIC_1 0x20 -#define PIC_2 0xA0 -#define PIC_1_OFFSET 0x20 // Interrupt vector offset for PIC1 -#define PIC_2_OFFSET 0x28 // Interrupt vector offset for PIC2 - -void pic_remap(s32int offset1, s32int offset2); -void pic_acknowledge(u32int interrupt); - -#endif diff --git a/Worksheet2_2/pic.o b/Worksheet2_2/pic.o deleted file mode 100644 index 97a4d53beebf351f120dc505b4738deb2d0dbe68..0000000000000000000000000000000000000000 Binary files a/Worksheet2_2/pic.o and /dev/null differ diff --git a/Worksheet2_2/types.h b/Worksheet2_2/types.h deleted file mode 100644 index f41731178528e2dbd9a1eb01a388dcfff030d3e5..0000000000000000000000000000000000000000 --- a/Worksheet2_2/types.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef INCLUDE_TYPES_H -#define INCLUDE_TYPES_H - -typedef unsigned char u8int; // 8-bit unsigned integer -typedef char s8int; // 8-bit signed integer - -typedef unsigned short u16int; // 16-bit unsigned integer -typedef short s16int; // 16-bit signed integer - -typedef unsigned int u32int; // 32-bit unsigned integer -typedef int s32int; // 32-bit signed integer - -#endif