#pragma region IDENTIFICATION DIVISION // |$|*file*kernel.c*| |$|*noclean*| // |$|*artifact*kernel.o*kernel.c*"gcc -ffreestanding -nostdlib -c {artifact0} -mgeneral-regs-only -o {file}"*| // |$|*artifact*kernel.bin*bin.ld&kernel.o*"ld -flto -T {artifact0} {artifact1} -S -o {file}"*| #pragma region HEADER DIVISION # include # include # include #pragma region STRUCTURE DIVISION typedef enum { TYPE_4K = 0, TYPE_2M = 1, } block_type_t; typedef enum { KBD_INPUT_MODE_IGNORE = 0, KBD_INPUT_MODE_LINEBUFFER = 1, KBD_INPUT_MODE_EDIT = 2, } kbd_input_mode_t; typedef struct block_table_entry { uint64_t phys_addr; block_type_t type; uint64_t count; } block_table_entry_t; typedef void (*diskread_fn)(void *buffer, uint32_t lba); typedef struct SMAP_entry { uint32_t BaseL; // base address uint64_t uint32_t BaseH; uint32_t LengthL; // length uint64_t uint32_t LengthH; uint32_t Type; // entry Type uint32_t ACPI; // extended }__attribute__((packed)) SMAP_entry_t; typedef uint64_t page_table_entry_t; typedef struct sec_stages_list { uint32_t deployer_2_lba; uint32_t deployer_2_seccount; void* deployer_2_addr; uint32_t kernel_lba; uint32_t kernel_seccount; } sec_stages_list_t; typedef struct { uint16_t isr_low; // The lower 16 bits of the ISR's address uint16_t kernel_cs; // The GDT segment selector that the CPU will load into CS before calling the ISR uint8_t ist; // The IST in the TSS that the CPU will load into RSP; set to zero for now uint8_t attributes; // Type and attributes; see the IDT page uint16_t isr_mid; // The higher 16 bits of the lower 32 bits of the ISR's address uint32_t isr_high; // The higher 32 bits of the ISR's address uint32_t reserved; // Set to zero } __attribute__((packed)) idt_entry_t; typedef struct { uint16_t limit; uint64_t base; } __attribute__((packed)) idtr_t; struct interrupt_frame { size_t ip; size_t cs; size_t flags; size_t sp; size_t ss; }; struct scroller { struct scroller *next; char *text; int i; int l; int x; int y; int w; }; enum documenttype { DOCTYPE_FOUNDATIONAL = 0, DOCTYPE_SNAKE = 1, }; struct program { struct program *next; struct program *prev; char title[18]; int cur_x; int cur_y; enum documenttype type; uint16_t scr_content[58*23]; }; #pragma region CONSTANTS DIVISION # define PAGE_PRESENT (1 << 0) # define PAGE_WRITE (1 << 1) # define PAGE_USER (1 << 2) # define PAGE_SIZE_2MB (1 << 7) # define ALIGN_4K __attribute__((aligned(4096))) # define PHYS_MEM_OFFSET 0xFFFF800000000000 # define BOOTSTRAP_MEM_END 0x200000 // 2MiB # define IDT_MAX_DESCRIPTORS 256 # define GDT_OFFSET_KERNEL_CODE 8 # define PIC1 0x20 /* IO base address for master PIC */ # define PIC2 0xA0 /* IO base address for slave PIC */ # define PIC1_COMMAND PIC1 # define PIC1_DATA (PIC1+1) # define PIC2_COMMAND PIC2 # define PIC2_DATA (PIC2+1) # define PIC_EOI 0x20 # define ICW1_ICW4 0x01 /* Indicates that ICW4 will be present */ # define ICW1_SINGLE 0x02 /* Single (cascade) mode */ # define ICW1_INTERVAL4 0x04 /* Call address interval 4 (8) */ # define ICW1_LEVEL 0x08 /* Level triggered (edge) mode */ # define ICW1_INIT 0x10 /* Initialization - required! */ # define ICW4_8086 0x01 /* 8086/88 (MCS-80/85) mode */ # define ICW4_AUTO 0x02 /* Auto (normal) EOI */ # define ICW4_BUF_SLAVE 0x08 /* Buffered mode/slave */ # define ICW4_BUF_MASTER 0x0C /* Buffered mode/master */ # define ICW4_SFNM 0x10 /* Special fully nested (not) */ # define CASCADE_IRQ 2 # define PIC_READ_IRR 0x0a # define PIC_READ_ISR 0x0b # define HKLB(scancode, char) case scancode: kbd_input_linebuffer_buf[kbd_input_linebuffer_cursor] = char; kbd_input_linebuffer_cursor++; break // ^^^^ that means handle key line buffer # define HSLB(scancode, char, char2) case scancode: if (kbd_input_lshift_pressed) {kbd_input_linebuffer_buf[kbd_input_linebuffer_cursor] = char2; } else {kbd_input_linebuffer_buf[kbd_input_linebuffer_cursor] = char;} kbd_input_linebuffer_cursor++; break // ^^^^ that means handle shiftable line buffer # define HLLB(scancode, char) case scancode: if (kbd_input_lshift_pressed) {kbd_input_linebuffer_buf[kbd_input_linebuffer_cursor] = char - 0x20; } else {kbd_input_linebuffer_buf[kbd_input_linebuffer_cursor] = char;} kbd_input_linebuffer_cursor++; break // ^^^^ that means handle letter line buffer # define HKE(scancode, char) case scancode: \ current_program->scr_content[current_program->cur_x + 58*current_program->cur_y] = \ (current_program->scr_content[current_program->cur_x + 58*current_program->cur_y] & 0xff00) + char ; \ current_program->cur_x ++; \ if (current_program->cur_x == 58) \ { \ current_program->cur_x = 0; \ current_program->cur_y ++; \ if (current_program->cur_y == 23) \ current_program->cur_y = 0; \ } \ ScreenRedraw(); \ break // ^^^ Handle key edit # define HSE(scancode, char, CHAR) case scancode: \ if (!kbd_input_lshift_pressed) \ current_program->scr_content[current_program->cur_x + 58*current_program->cur_y] = \ (current_program->scr_content[current_program->cur_x + 58*current_program->cur_y] & 0xff00) + char ; \ else \ current_program->scr_content[current_program->cur_x + 58*current_program->cur_y] = \ (current_program->scr_content[current_program->cur_x + 58*current_program->cur_y] & 0xff00) + CHAR ; \ current_program->cur_x ++; \ if (current_program->cur_x == 58) \ { \ current_program->cur_x = 0; \ current_program->cur_y ++; \ if (current_program->cur_y == 23) \ current_program->cur_y = 0; \ } \ ScreenRedraw(); \ break // ^^^ Handle shiftable edit # define HLE(scancode, letter) HSE(scancode, letter, letter-0x20) #pragma region DATA DIVISION SMAP_entry_t* e820_buffer; uint16_t e820_entry_count; uint16_t sector_stages_list; volatile static uint64_t *debug = (uint64_t*)0x7200; volatile static uint64_t *trace = (uint64_t*)0x7208; volatile static uint64_t *calls = (uint64_t*)0x7210; page_table_entry_t *pml4 = (page_table_entry_t*)0x1000; int mem_quotum_x; void *bump_alloc; void *bump_top; void *bump_alloc_next_2m = 0; uint64_t *alloc_bits; block_table_entry_t *block_table; uint64_t block_table_entries = 0; uint64_t next_2m_target = 0; uint64_t addr; __attribute__((aligned(0x10))) static idt_entry_t idt[256]; // Create an array of IDT entries; aligned for performance static bool vectors[IDT_MAX_DESCRIPTORS]; static idtr_t idtr; uint16_t *c = (uint16_t*)0xb8000; bool kbd_inp_extended = false; kbd_input_mode_t kbd_input_mode = KBD_INPUT_MODE_IGNORE; char *kbd_input_linebuffer_buf; int kbd_input_linebuffer_maxlen; int kbd_input_linebuffer_cursor; bool kbd_input_linebuffer_done = false; struct scroller *scrollers = NULL; struct scroller promptscroller; struct scroller logoscroller; bool kbd_input_lshift_pressed = false; struct program *first_program = NULL; struct program *last_program = NULL; struct program *current_program = NULL; bool attention_on_system = false; bool can_set_attention_on_system = true; int newtabi = 0; #pragma region EXTERNAL DIVISION extern void* isr_stub_table[]; #pragma region DEFINITION DIVISION __attribute__((noreturn)) void KernelMain(void); __attribute__((noreturn)) void _start(SMAP_entry_t* e820_buffer_, uint16_t e820_entry_count_, diskread_fn diskRead_, uint16_t sector_stages_list_, int mem_quotum_x_, void *bump_alloc_, void *bump_top_); diskread_fn diskRead; void MapPageLarge(uint64_t virt_addr, uint64_t phys_addr); uint64_t get_4m_block_index(uint64_t idx); void* bump_allocator_alloc_4k(); bool GetBit(uint64_t* bitmap, uint64_t index); void SetBit(uint64_t* bitmap, uint64_t index, bool bit); uint64_t SB2MAlloc(); void ScreenRedraw(); void TextLineInput(char* buffer, int maxlen, char* prompt, int promptlen); void TextLineInputDraw(void); void DrawScrollers(void); // INTERRUPTS void idt_set_descriptor(uint8_t vector, void* isr, uint8_t flags); void idt_init(void); __attribute__((interrupt)) void inthndlr(struct interrupt_frame* frame); __attribute__((interrupt)) void inthndlr_kbd(struct interrupt_frame* frame); __attribute__((interrupt)) void inthndlr_timer(struct interrupt_frame* frame); void PIC_sendEOI(uint8_t irq); static inline void io_wait(void); static inline void outb(uint16_t port, uint8_t val); static inline uint8_t inb(uint16_t port); static uint16_t __pic_get_irq_reg(int ocw3); uint16_t pic_get_irr(void); uint16_t pic_get_isr(void); #pragma region PROCEDURE DIVISION void _start(SMAP_entry_t* e820_buffer_, uint16_t e820_entry_count_, diskread_fn diskRead_, uint16_t sector_stages_list_, int mem_quotum_x_, void *bump_alloc_, void *bump_top_) { // DO NOT place ANYTHING above this function lest the world collapse e820_buffer = e820_buffer_; e820_entry_count = e820_entry_count_; diskRead = diskRead_; sector_stages_list = sector_stages_list_; mem_quotum_x = mem_quotum_x_; bump_alloc = bump_alloc_; bump_top = bump_top_; KernelMain(); } static inline void outb(uint16_t port, uint8_t val) { __asm__ volatile ( "outb %b0, %w1" : : "a"(val), "Nd"(port) : "memory"); /* There's an outb %al, $imm8 encoding, for compile-time constant port numbers that fit in 8b. (N constraint). * Wider immediate constants would be truncated at assemble-time (e.g. "i" constraint). * The outb %al, %dx encoding is the only option for all other cases. * %1 expands to %dx because port is a uint16_t. %w1 could be used if we had the port number a wider C type */ } static inline uint8_t inb(uint16_t port) { uint8_t ret; __asm__ volatile ( "inb %w1, %b0" : "=a"(ret) : "Nd"(port) : "memory"); return ret; } /* Helper func */ static uint16_t __pic_get_irq_reg(int ocw3) { /* OCW3 to PIC CMD to get the register values. PIC2 is chained, and * represents IRQs 8-15. PIC1 is IRQs 0-7, with 2 being the chain */ outb(PIC1_COMMAND, ocw3); outb(PIC2_COMMAND, ocw3); return (inb(PIC2_COMMAND) << 8) | inb(PIC1_COMMAND); } /* Returns the combined value of the cascaded PICs irq request register */ uint16_t pic_get_irr(void) { return __pic_get_irq_reg(PIC_READ_IRR); } /* Returns the combined value of the cascaded PICs in-service register */ uint16_t pic_get_isr(void) { return __pic_get_irq_reg(PIC_READ_ISR); } void PIC_sendEOI(uint8_t irq) { if(irq >= 8) outb(PIC2_COMMAND,PIC_EOI); outb(PIC1_COMMAND,PIC_EOI); } static inline void io_wait(void) { outb(0x80, 0); } void TextLineInput(char* buffer, int maxlen, char* prompt, int promptlen) { bool attention = can_set_attention_on_system; can_set_attention_on_system = false; kbd_input_linebuffer_buf = buffer; kbd_input_linebuffer_maxlen = maxlen; kbd_input_linebuffer_done = false; kbd_input_linebuffer_cursor = 0; kbd_input_mode = KBD_INPUT_MODE_LINEBUFFER; promptscroller.x = 25; promptscroller.y = 4; promptscroller.w = 30; promptscroller.l = promptlen; promptscroller.text = prompt; promptscroller.next = NULL; struct scroller *oldscroller = scrollers; scrollers = &promptscroller; for (int i = 0; i < 80*25; i++) { c[i] = 0x7000; } TextLineInputDraw(); while(!kbd_input_linebuffer_done) { } scrollers = oldscroller; kbd_input_mode = KBD_INPUT_MODE_IGNORE; can_set_attention_on_system = attention; ScreenRedraw(); return; } void idt_init() { idtr.base = (uintptr_t)&idt[0]; idtr.limit = (uint16_t)sizeof(idt_entry_t) * IDT_MAX_DESCRIPTORS - 1; for (uint8_t vector = 0; vector < 96; vector++) { idt_set_descriptor(vector, &inthndlr, 0b10001110); vectors[vector] = true; } idt_set_descriptor(0x21, &inthndlr_kbd, 0b10001110); idt_set_descriptor(0x20, &inthndlr_timer, 0b10001110); __asm__ volatile ("lidt %0" : : "m"(idtr)); // load the new IDT __asm__ volatile ("sti"); // set the interrupt flag } void idt_set_descriptor(uint8_t vector, void* isr, uint8_t flags) { idt_entry_t* descriptor = &idt[vector]; descriptor->isr_low = (uint64_t)isr & 0xFFFF; descriptor->kernel_cs = GDT_OFFSET_KERNEL_CODE; descriptor->ist = 0; descriptor->attributes = flags; descriptor->isr_mid = ((uint64_t)isr >> 16) & 0xFFFF; descriptor->isr_high = ((uint64_t)isr >> 32) & 0xFFFFFFFF; descriptor->reserved = 0; *debug = vector; *trace = (uint64_t)isr; //while(1){} } __attribute__((interrupt)) void inthndlr_kbd(struct interrupt_frame* frame) { if (!kbd_inp_extended) { uint8_t scancode = inb(0x60); if (scancode == 0xE0) { kbd_inp_extended = true; } bool released = scancode & 0x80; uint8_t key = scancode & 0x7F; if (attention_on_system) { if (key == 0x1d && released) { attention_on_system = false; ScreenRedraw(); goto endinterrupt; } if (key == 0x31 && released) { uint64_t addr = (uint64_t)bump_allocator_alloc_4k(); struct program *prog = (struct program*)addr; for (int i = 0; i < 18; i++) { if (i == newtabi) prog->title[i] = 0x02; else prog->title[i] = 0x09; } for (int i = 0; i < 58*23; i++) prog->scr_content[i] = 0xF000; prog->type = DOCTYPE_FOUNDATIONAL; prog->cur_x = 0; prog->cur_y = 0; newtabi++; newtabi%=18; if (current_program == NULL) { prog->next = NULL; prog->prev = NULL; current_program = prog; first_program = prog; last_program = prog; kbd_input_mode = KBD_INPUT_MODE_EDIT; } else { prog->prev = current_program; prog->next = current_program->next; if (current_program->next != NULL) { current_program->next->prev = prog; } current_program->next = prog; if (prog->next == NULL) { last_program = prog; } current_program = prog; } ScreenRedraw(); goto endinterrupt; } if (key == 0x1e && !released && current_program != NULL) { for (int x = 0; x < 58; x++) for (int y = 0; y < 23; y++) { if ( (x == 0 && y == 11 - (0)) || (x == 1 && y == 11 - (1)) || (x == 2 && y == 11 - (2)) || (x == 3 && y == 11 - (3)) || (x == 4 && y == 11 - (4)) || (x == 5 && y == 11 - (5)) || (x == 6 && y == 11 - (6)) || (x == 7 && y == 11 - (7)) || (x == 8 && y == 11 - (8)) || (x == 9 && y == 11 - (8)) || (x == 10 && y == 11 - (9)) || (x == 11 && y == 11 - (9)) || (x == 12 && y == 11 - (10)) || (x == 13 && y == 11 - (10)) || (x == 14 && y == 11 - (10)) || (x == 15 && y == 11 - (10)) || (x == 16 && y == 11 - (10)) || (x == 17 && y == 11 - (10)) || (x == 18 && y == 11 - (9)) || (x == 19 && y == 11 - (9)) || (x == 20 && y == 11 - (8)) || (x == 21 && y == 11 - (8)) || (x == 22 && y == 11 - (7)) || (x == 23 && y == 11 - (6)) || (x == 24 && y == 11 - (5)) || (x == 25 && y == 11 - (4)) || (x == 26 && y == 11 - (3)) || (x == 27 && y == 11 - (2)) || (x == 28 && y == 11 - (1)) || (x == 29 && y == 11 - (0)) || (x == 30 && y == 11 - (-1)) || (x == 31 && y == 11 - (-2)) || (x == 32 && y == 11 - (-3)) || (x == 33 && y == 11 - (-4)) || (x == 34 && y == 11 - (-5)) || (x == 35 && y == 11 - (-6)) || (x == 36 && y == 11 - (-7)) || (x == 37 && y == 11 - (-8)) || (x == 38 && y == 11 - (-8)) || (x == 39 && y == 11 - (-9)) || (x == 40 && y == 11 - (-9)) || (x == 41 && y == 11 - (-10)) || (x == 42 && y == 11 - (-10)) || (x == 43 && y == 11 - (-10)) || (x == 44 && y == 11 - (-10)) || (x == 45 && y == 11 - (-10)) || (x == 46 && y == 11 - (-10)) || (x == 47 && y == 11 - (-9)) || (x == 48 && y == 11 - (-9)) || (x == 49 && y == 11 - (-8)) || (x == 50 && y == 11 - (-8)) || (x == 51 && y == 11 - (-7)) || (x == 52 && y == 11 - (-6)) || (x == 53 && y == 11 - (-5)) || (x == 54 && y == 11 - (-4)) || (x == 55 && y == 11 - (-3)) || (x == 56 && y == 11 - (-2)) || (x == 57 && y == 11 - (-1)) || (x == 58 && y == 11 - (0)) ) current_program->scr_content[x+58*y] = (current_program->scr_content[x+58*y]&0xff) + 0xa000; else current_program->scr_content[x+58*y] = (current_program->scr_content[x+58*y]&0xff) + 0x0a00; } ScreenRedraw(); } if (key == 0x13 && released && current_program != NULL) { PIC_sendEOI(0x01); io_wait(); attention_on_system = false; TextLineInput(current_program->title, 18, "Haii >w< ", 12); return; } if (key == 0x21 && released && current_program != NULL && current_program->type == DOCTYPE_FOUNDATIONAL && kbd_input_mode == KBD_INPUT_MODE_EDIT) { kbd_input_mode = KBD_INPUT_MODE_IGNORE; current_program->type = DOCTYPE_SNAKE; for (int x = 0; x < 58; x++) for (int y = 0; y < 23; y++) { current_program->scr_content[(58*y)+x] = 0x7700; } current_program->scr_content[(58*4) + 4] = 0x22fd; current_program->scr_content[(58*4) + 5] = 0x22fe; current_program->scr_content[(58*4) + 6] = 0x22ff; current_program->scr_content[(58*4) + 6] = 0xaa02; ScreenRedraw(); goto endinterrupt; } if (key == 0x23 && released && current_program != NULL && current_program->type == DOCTYPE_FOUNDATIONAL) { for (int i = 0; i < 58*23; i++) current_program->scr_content[i] = 0x00; } } else { if (key == 0x1d && !released && can_set_attention_on_system) { attention_on_system = true; ScreenRedraw(); goto endinterrupt; } if (key == 0x2a) kbd_input_lshift_pressed = !released; switch(kbd_input_mode) { case KBD_INPUT_MODE_IGNORE: break; case KBD_INPUT_MODE_EDIT: if (current_program == NULL) { *debug = 0xe06f2193; __asm__("cli"); __asm__("hlt"); while(1){} } if (released) goto endinterrupt; switch (key) { case 0x1c: current_program->cur_y++; if (current_program->cur_y == 23) current_program->cur_y = 0; current_program->cur_x = 0; ScreenRedraw(); break; case 0x0e: current_program->cur_x--; if (current_program->cur_x == -1) { current_program->cur_x = 57; current_program->cur_y--; if (current_program->cur_y == -1) { current_program->cur_y = 22; } } current_program->scr_content[current_program->cur_x + 58*current_program->cur_y] -= current_program->scr_content[current_program->cur_x + 58*current_program->cur_y] & 0xff; ScreenRedraw(); break; HSE(0x02, '1', '!'); HSE(0x03, '2', '@'); HSE(0x04, '3', '#'); HSE(0x05, '4', '$'); HSE(0x06, '5', '%'); HSE(0x07, '6', '^'); HSE(0x08, '7', '&'); HSE(0x09, '8', '*'); HSE(0x0a, '9', '('); HSE(0x0b, '0', ')'); HSE(0x0c, '-', '_'); HSE(0x0d, '=', '+'); HLE(0x10, 'q'); HLE(0x11, 'w'); HLE(0x12, 'e'); HLE(0x13, 'r'); HLE(0x14, 't'); HLE(0x15, 'y'); HLE(0x16, 'u'); HLE(0x17, 'i'); HLE(0x18, 'o'); HLE(0x19, 'p'); HSE(0x1a, '[', '{'); HSE(0x1b, ']', '}'); HLE(0x1e, 'a'); HLE(0x1f, 's'); HLE(0x20, 'd'); HLE(0x21, 'f'); HLE(0x22, 'g'); HLE(0x23, 'h'); HLE(0x24, 'j'); HLE(0x25, 'k'); HLE(0x26, 'l'); HSE(0x27, ';', ':'); HSE(0x28, '\'', '"'); HSE(0x29, '`', '~'); HLE(0x2c, 'z'); HLE(0x2d, 'x'); HLE(0x2e, 'c'); HLE(0x2f, 'v'); HLE(0x30, 'b'); HLE(0x31, 'n'); HLE(0x32, 'm'); HSE(0x33, ',', '<'); HSE(0x34, '.', '>'); HKE(0x39, ' '); HSE(0x35, '/', '?'); HSE(0x2b, '\\', '|'); } break; case KBD_INPUT_MODE_LINEBUFFER: if (released) goto endinterrupt; switch(key) { case 0x1c: // enter kbd_input_linebuffer_done = true; break; case 0x0e: // backspace if (kbd_input_linebuffer_cursor != 0) { kbd_input_linebuffer_cursor -= 1; kbd_input_linebuffer_buf[kbd_input_linebuffer_cursor] = 0x00; } break; } if (kbd_input_linebuffer_cursor == kbd_input_linebuffer_maxlen) goto endinterrupt; // if the linebuffer is full, only check for backspace and enter. switch (key){ HSLB(0x02, '1', '!'); HSLB(0x03, '2', '@'); HSLB(0x04, '3', '#'); HSLB(0x05, '4', '$'); HSLB(0x06, '5', '%'); HSLB(0x07, '6', '^'); HSLB(0x08, '7', '&'); HSLB(0x09, '8', '*'); HSLB(0x0a, '9', '('); HSLB(0x0b, '0', ')'); HSLB(0x0c, '-', '_'); HSLB(0x0d, '=', '+'); HLLB(0x10, 'q'); HLLB(0x11, 'w'); HLLB(0x12, 'e'); HLLB(0x13, 'r'); HLLB(0x14, 't'); HLLB(0x15, 'y'); HLLB(0x16, 'u'); HLLB(0x17, 'i'); HLLB(0x18, 'o'); HLLB(0x19, 'p'); HKLB(0x1a, '['); HKLB(0x1b, ']'); HLLB(0x1e, 'a'); HLLB(0x1f, 's'); HLLB(0x20, 'd'); HLLB(0x21, 'f'); HLLB(0x22, 'g'); HLLB(0x23, 'h'); HLLB(0x24, 'j'); HLLB(0x25, 'k'); HLLB(0x26, 'l'); HKLB(0x27, ';'); HKLB(0x28, '\''); HKLB(0x29, '`'); HLLB(0x2c, 'z'); HLLB(0x2d, 'x'); HLLB(0x2e, 'c'); HLLB(0x2f, 'v'); HLLB(0x30, 'b'); HLLB(0x31, 'n'); HLLB(0x32, 'm'); HKLB(0x33, ','); HKLB(0x34, '.'); HKLB(0x39, ' '); } TextLineInputDraw(); } } endinterrupt: } else { uint8_t scancode = inb(0x60); kbd_inp_extended = false; if (attention_on_system) { if (scancode == 0xd0) { if (current_program != NULL && current_program->next != NULL) { if (current_program->type == DOCTYPE_FOUNDATIONAL && kbd_input_mode == KBD_INPUT_MODE_EDIT) { kbd_input_mode = KBD_INPUT_MODE_IGNORE; } current_program = current_program->next; ScreenRedraw(); if (current_program->type == DOCTYPE_FOUNDATIONAL && kbd_input_mode == KBD_INPUT_MODE_IGNORE) { kbd_input_mode = KBD_INPUT_MODE_EDIT; } } } if (scancode == 0xc8) { if (current_program != NULL && current_program->prev != NULL) { if (current_program->type == DOCTYPE_FOUNDATIONAL && kbd_input_mode == KBD_INPUT_MODE_EDIT) { kbd_input_mode = KBD_INPUT_MODE_IGNORE; } current_program = current_program->prev; ScreenRedraw(); if (current_program->type == DOCTYPE_FOUNDATIONAL && kbd_input_mode == KBD_INPUT_MODE_IGNORE) { kbd_input_mode = KBD_INPUT_MODE_EDIT; } } } } else { switch (kbd_input_mode){ case KBD_INPUT_MODE_IGNORE: break; case KBD_INPUT_MODE_EDIT: if (current_program == NULL) { *debug = 0xe06f2193; __asm__("cli"); __asm__("hlt"); while(1){} } if (scancode == 0x48) { current_program->cur_y --; if (current_program->cur_y == -1) current_program->cur_y = 22; ScreenRedraw(); } if (scancode == 0x50) { current_program->cur_y ++; current_program->cur_y %= 23; ScreenRedraw(); } if (scancode == 0x4b) { current_program->cur_x --; if (current_program->cur_x == -1) current_program->cur_x = 57; ScreenRedraw(); } if (scancode == 0x4d) { current_program->cur_x ++; current_program->cur_x %= 58; ScreenRedraw(); } break; case KBD_INPUT_MODE_LINEBUFFER: if (scancode == 0xcb) { if (kbd_input_linebuffer_cursor != 0) kbd_input_linebuffer_cursor--; } if (scancode == 0xcd) { if (kbd_input_linebuffer_cursor != kbd_input_linebuffer_maxlen) kbd_input_linebuffer_cursor++; } TextLineInputDraw(); break; } } } PIC_sendEOI(0x1); io_wait(); } void TextLineInputDraw() { for (int i = 0; i < 80; i ++) c[7*80 + i] = 0x7000; if (kbd_input_linebuffer_maxlen < 40) { // draw everything for (int i = 0; i < kbd_input_linebuffer_maxlen; i++) { c[7*80 + i + 20] = 0x1f00 + kbd_input_linebuffer_buf[i]; } outb(0x3D4, 0x0F); outb(0x3D5, (uint8_t) ((7*80+20+kbd_input_linebuffer_cursor) & 0xFF)); outb(0x3D4, 0x0E); outb(0x3D5, (uint8_t) (((7*80+20+kbd_input_linebuffer_cursor) >> 8) & 0xFF)); } else if (kbd_input_linebuffer_cursor < 40) { // draw the first 40 characters. for (int i = 0; i < 40; i++) { c[7*80 + i + 20] = 0x1f00 + kbd_input_linebuffer_buf[i]; } c[7*80 + 60] = 0x0700 + '>'; outb(0x3D4, 0x0F); outb(0x3D5, (uint8_t) ((7*80+20+kbd_input_linebuffer_cursor) & 0xFF)); outb(0x3D4, 0x0E); outb(0x3D5, (uint8_t) (((7*80+20+kbd_input_linebuffer_cursor) >> 8) & 0xFF)); } else if (kbd_input_linebuffer_maxlen - kbd_input_linebuffer_cursor < 40) { c[7*80 + 19] = 0x0700 + '<'; for (int i = 0; i < 40; i++) { c[7*80 + i + 20] = 0x1f00 + kbd_input_linebuffer_buf[kbd_input_linebuffer_maxlen - 40 + i]; } outb(0x3D4, 0x0F); outb(0x3D5, (uint8_t) ((7*80+60-(kbd_input_linebuffer_maxlen -kbd_input_linebuffer_cursor)) & 0xFF)); outb(0x3D4, 0x0E); outb(0x3D5, (uint8_t) (((7*80+60-(kbd_input_linebuffer_maxlen -kbd_input_linebuffer_cursor)) >> 8) & 0xFF)); } else { c[7*80 + 19] = 0x0700 + '<'; c[7*80 + 60] = 0x0700 + '>'; for (int i = 0; i < 40; i++) { c[7*80 + i + 20] = 0x1f00 + kbd_input_linebuffer_buf[kbd_input_linebuffer_cursor - 35 + i]; } outb(0x3D4, 0x0F); outb(0x3D5, (uint8_t) ((7*80+55) & 0xFF)); outb(0x3D4, 0x0E); outb(0x3D5, (uint8_t) (((7*80+55) >> 8) & 0xFF)); } } void DrawScrollers() { struct scroller *scrolly = scrollers; while (scrolly != NULL) { for (int i = 0; i < scrolly->w; i++) { c[(scrolly->y*80) + scrolly->x + i] = (c[(scrolly->y*80) + scrolly->x + i] & 0xff00) + (scrolly->text[(i+scrolly->i)%scrolly->l]); } scrolly = scrolly->next; } } __attribute__((interrupt)) void inthndlr_timer(struct interrupt_frame* frame) { struct scroller *scrolly = scrollers; while (scrolly != NULL) { scrolly->i += 1; scrolly->i %= scrolly->l; scrolly = scrolly->next; } DrawScrollers(); if (current_program != NULL && current_program->type == DOCTYPE_SNAKE) { uint16_t positions[256]; uint16_t head_position; uint8_t lowest_level = 0; for (int i = 0 ; i < 256; i ++) positions[i] = 0xffff; for (int i = 0 ; i < 23*58 ; i ++) { if ((current_program->scr_content[i] & 0xff00) == 0x2200) { *debug = i; //__asm__("cli"); __asm__("hlt"); while(1){} positions[(current_program->scr_content[i] & 0x00ff)] = i; if ((current_program->scr_content[i] & 0x00ff) > lowest_level) lowest_level = (current_program->scr_content[i] & 0x00ff); } else if ((current_program->scr_content[i] & 0xff00) == 0xaa00) { head_position = i; } } // find all positions; if ((current_program->scr_content[head_position] & 0x00ff) == 01) // left { if ((head_position%58) <= 0 && ((current_program->scr_content[head_position-1] & 0xff00) == 0x2200)) { goto die; } current_program->scr_content[head_position-1] = 0xaa01; } else if ((current_program->scr_content[head_position] & 0x00ff) == 02) // right { if ((head_position%58) == 40 || ((current_program->scr_content[head_position+1] & 0xff00) == 0x2200)) { goto die; } current_program->scr_content[head_position] = lowest_level + 0x2200; current_program->scr_content[head_position+1] = 0xaa02; } else if ((current_program->scr_content[head_position] & 0x00ff) == 03) // up { } else if ((current_program->scr_content[head_position] & 0x00ff) == 04) // down { } else { // death. } goto dontdie; die: current_program->scr_content[head_position-1] = 0xaaff; // u are dead lol for (int i = 0; i < 18; i++) current_program->title[i] = "U are dead lol \x01 "[i]; ScreenRedraw(); goto no_snake_today; dontdie: ScreenRedraw(); } no_snake_today: PIC_sendEOI(0x0); io_wait(); } __attribute__((interrupt)) void inthndlr(struct interrupt_frame* frame) { __asm__("cli"); __asm__("hlt"); } uint64_t get_4m_block_index(uint64_t idx) { uint64_t count = 0; for (int i = 0; i < e820_entry_count; i++) { if (e820_buffer[i].Type != 1) continue; // Only consider usable memory uint64_t base = ((uint64_t)e820_buffer[i].BaseH << 32) | e820_buffer[i].BaseL; uint64_t length = ((uint64_t)e820_buffer[i].LengthH << 32) | e820_buffer[i].LengthL; uint64_t addr = base; while (addr < base + length) { if (addr % 0x200000 == 0) { if (count == idx) return addr; count++; addr += 0x200000; } else { if (addr % 512 == 0) { addr += 512; } else { addr += 512 - (addr % 512); } } } } } bool GetBit(uint64_t* bitmap, uint64_t index) { uint64_t word_index = index / 64; uint64_t bit_index = index % 64; return (bitmap[word_index] >> bit_index) & 1; } void SetBit(uint64_t* bitmap, uint64_t index, bool bit) { uint64_t word_index = index / 64; uint64_t bit_index = index % 64; if (bit) { bitmap[word_index] |= (1ULL << bit_index); } else { bitmap[word_index] &= ~(1ULL << bit_index); } } void* bump_allocator_alloc_4k() { if ((uint64_t)bump_alloc % 4096 != 0) { bump_alloc += 4096 - ((uint64_t)bump_alloc % 4096); } void* zaddr = bump_alloc; bump_alloc += 4096; if ((bump_alloc) >= bump_top) { bump_alloc = bump_alloc_next_2m; bump_top = bump_alloc_next_2m + 0x200000; zaddr = bump_alloc; bump_alloc += 4096; // set up a new bump_alloc_next_2m uint64_t virt_addr = 0; uint64_t candidate = (uint64_t)bump_alloc_next_2m; if (candidate & 0x1FFFFF) { candidate = (candidate + 0x1FFFFF) & ~0x1FFFFF; } for (;;) { uint64_t pml4_idx = (candidate >> 39) & 0x1FF; uint64_t pdp_idx = (candidate >> 30) & 0x1FF; uint64_t pd_idx = (candidate >> 21) & 0x1FF; if (!(pml4[pml4_idx] & PAGE_PRESENT)) break; page_table_entry_t *pdp = (page_table_entry_t*)(pml4[pml4_idx] & ~0xFFF); if (!(pdp[pdp_idx] & PAGE_PRESENT)) break; page_table_entry_t *pd = (page_table_entry_t*)(pdp[pdp_idx] & ~0xFFF); if (!(pd[pd_idx] & PAGE_PRESENT)) break; candidate += 0x200000; } virt_addr = candidate; bump_alloc_next_2m = (void*)candidate; bump_alloc_next_2m += 0x200000; uint64_t phys_addr = SB2MAlloc(); // phys addr = bump_alloc_next_2m = block_table[block_idx].phys_addr + (localoffset * 0x200000); MapPageLarge(virt_addr, phys_addr); } return zaddr; } uint64_t SB2MAlloc() { block_table_entry_t *block = block_table; int bitoffset = 0; for (int block_idx = 0; block_idx < block_table_entries; block_idx++) { if (block_table[block_idx].type != TYPE_2M) { bitoffset += block_table[block_idx].count; continue; } uint64_t localoffset = 0; while (localoffset < block_table[block_idx].count) { if (GetBit(alloc_bits, bitoffset) == 0) { SetBit(alloc_bits, bitoffset, 1); return block_table[block_idx].phys_addr + (0x200000 * localoffset); } localoffset ++; bitoffset ++; } } *debug = 0xF04E0001; while(1){} } void ScreenRedraw() { for (int x = 0; x < 80; x++) for (int y = 0; y < 25; y++) { if (y == 0 || y == 24 || x == 0 || x == 79 || x == 19 || x == 20) { if ((attention_on_system && x < 20) || (!attention_on_system && x > 19)) c[x+y*80] = 0x2E00; else c[x+y*80] = 0x7E00; } else c[x+y*80] = 0xf000; } for (int i = 0; i < 12; i++) { if (attention_on_system) c[1 + 24*80 + i] = "JesOS 64 1.0"[i] + 0x2100; else c[1 + 24*80 + i] = "JesOS 64 1.0"[i] + 0x7100; } if (current_program == NULL) { for (int i = 0; i < 23; i++) { c[23+2*80+i] = "No document opened. :'("[i] + 0xF400; } for (int i = 0; i < 8; i++) { c[6+23*80+i] = "Press ^n"[i] + 0xF000; } DrawScrollers(); return; } else { if (!attention_on_system && current_program!=NULL) { if (current_program->type == DOCTYPE_FOUNDATIONAL) { for (int i = 0; i < 21; i++) { c[22+0*80+i] = "(foundational editor)"[i] + 0x2E00; }; } else if (current_program->type = DOCTYPE_SNAKE) { for (int i = 0; i < 7; i++) { c[22+0*80+i] = "(snake)"[i] + 0x2E00; }; } else { for (int i = 0; i< 19; i++) { c[22+0*80+i] = "! UNKNOWN DOCTYPE !"[i] + 0x2e00; }; } } for (int i = 0; i < 18; i++) { if (!attention_on_system) c[60+i] = current_program->title[i]+0x2e00; else c[60+i] = current_program->title[i]+0x7e00; } } outb(0x3d4, 0x0f); outb(0x3d5, (uint8_t) (((current_program->cur_y+1)*80+(current_program->cur_x+21)) & 0xff)); outb(0x3d4, 0x0e); outb(0x3d5, (uint8_t) ((((current_program->cur_y+1)*80+(current_program->cur_x+21)) >> 8) & 0xff)); for (int x = 0; x < 58; x++) for (int y = 0; y < 23; y++) { c[x+21+80*(y+1)] = current_program->scr_content[y*58+x]; } struct program *prog = current_program; int i = 0; // check and see, if there is a NULL in the program's prev list at max depth 20 while(i<20) { prog = prog->prev; i++; if (prog == NULL) { // draw as starting from top. prog = first_program; for (int y = 1; y < 24; y++) { for (int x = 0; x < 18; x++) { if (prog == current_program) c[x+1+80*y] = prog->title[x] + 0x2e00; else c[x+1+80*y] = prog->title[x] + 0xF800; } prog = prog->next; if (prog == NULL) { DrawScrollers(); return; } } DrawScrollers(); return; } } // draw the program list with current_program roughly centered prog = current_program; i = 0; while (i < 11 && prog->prev != NULL) { prog = prog->prev; i++; } for (int y = 1; y < 24; y++) { if (prog == NULL) break; for (int x = 0; x < 18; x++) { if (prog == current_program) c[x + 1 + 80*y] = prog->title[x] + 0x2e00; else c[x + 1 + 80*y] = prog->title[x] + 0xF800; } prog = prog->next; } DrawScrollers(); return; // fallback: draw with current_program centered struct program *start = current_program; int move_up = 11; while (move_up > 0 && start->prev != NULL) { start = start->prev; move_up--; } struct program *p = start; for (int y = 1; y < 24 && p != NULL; y++) { for (int x = 0; x < 18; x++) { if (p == current_program) c[x + 1 + 80*y] = p->title[x] + 0x2e00; else c[x + 1 + 80*y] = p->title[x] + 0xF800; } p = p->next; } DrawScrollers(); } void MapPageLarge(uint64_t virt_addr, uint64_t phys_addr) { uint64_t pml4_idx = (virt_addr >> 39) & 0x1FF; uint64_t pdp_idx = (virt_addr >> 30) & 0x1FF; uint64_t pd_idx = (virt_addr >> 21) & 0x1FF; // Allocate PDP if not present if (!(pml4[pml4_idx] & PAGE_PRESENT)) { page_table_entry_t* new_pdp = bump_allocator_alloc_4k(); for (int i = 0; i < 512; i++) new_pdp[i] = 0; pml4[pml4_idx] = (uint64_t)new_pdp | PAGE_PRESENT | PAGE_WRITE; } page_table_entry_t* pdp_ptr = (page_table_entry_t*)(pml4[pml4_idx] & ~0xFFF); // Allocate PD if not present if (!(pdp_ptr[pdp_idx] & PAGE_PRESENT)) { page_table_entry_t* new_pd = bump_allocator_alloc_4k(); for (int i = 0; i < 512; i++) new_pd[i] = 0; pdp_ptr[pdp_idx] = (uint64_t)new_pd | PAGE_PRESENT | PAGE_WRITE; } page_table_entry_t* pd_ptr = (page_table_entry_t*)(pdp_ptr[pdp_idx] & ~0xFFF); // Map the 2 MiB page in the PD entry // Ensure phys_addr is 2 MiB aligned (lower 21 bits must be zero) phys_addr &= ~((1ULL << 21) - 1); pd_ptr[pd_idx] = phys_addr | PAGE_PRESENT | PAGE_WRITE | PAGE_SIZE_2MB; asm volatile( "mov %0, %%cr3" : : "r"((uint64_t)pml4) : "memory" ); } void MemInit(void) { *debug = 0x13003700; uint16_t memaccess[256]; //free_list = (free_block_t*)0x200000; //free_list->size = 0x200000; //free_list->next = NULL; uint64_t mem_blocks_small = 0; uint64_t mem_blocks_large = 0; uint64_t list_entries = 0; for (int i = 0; i < e820_entry_count; i++) { if (e820_buffer[i].Type == 1) { // Usable memory uint64_t base = ((uint64_t)e820_buffer[i].BaseH << 32) | e820_buffer[i].BaseL; uint64_t length = ((uint64_t)e820_buffer[i].LengthH << 32) | e820_buffer[i].LengthL; if (base % 0x200000 != 0) base += (0x200000 - (base % 0x200000)); if (length % 0x200000 != 0) length -= (length % 0x200000); uint64_t addr = base; if (length > 1) { list_entries ++; } while(addr < (base + length)) { mem_blocks_large += 1; addr += 0x200000; } } } *trace = mem_blocks_small; *calls = mem_blocks_large; uint64_t mem_bitmap_bytes_needed = (mem_blocks_small + mem_blocks_large) / 8 + 1; uint64_t list_bytes_needed = 2 * list_entries * sizeof(block_table_entry_t); // i dunno man this code is fucked uint64_t total_bytes_needed = mem_bitmap_bytes_needed + list_bytes_needed; *debug = total_bytes_needed; uint64_t total_2m_needed = ((total_bytes_needed + 0x1FFFFF) & ~0x1FFFFF ) / 0x200000; diskRead(memaccess, sector_stages_list); addr = (((sec_stages_list_t*)memaccess)->kernel_seccount) * 512 + 0x400000; // Align addr to the next 2 MiB boundary if not already aligned if (addr % 0x200000 != 0) { addr = (addr + 0x1FFFFF) & ~0x1FFFFF; } int x_2mblk = mem_quotum_x + 2; block_table = (block_table_entry_t *)addr; alloc_bits = (uint64_t*)(addr + list_bytes_needed); for (int i = 0; i < total_2m_needed; i++) { uint64_t phys_addr = get_4m_block_index(x_2mblk); x_2mblk++; MapPageLarge(addr, phys_addr); addr += 0x200000; } *debug = addr; int bit = 0; for (int i = 0; i < e820_entry_count; i++) { if (e820_buffer[i].Type == 1) { // Usable memory uint64_t base = ((uint64_t)e820_buffer[i].BaseH << 32) | e820_buffer[i].BaseL; uint64_t length = ((uint64_t)e820_buffer[i].LengthH << 32) | e820_buffer[i].LengthL; if (base % 0x200000 != 0) base += (0x200000 - (base % 0x200000)); if (length % 0x200000 != 0) length -= (length % 0x200000); uint64_t addr = base; if (length > 1) { block_table[block_table_entries].phys_addr = addr; block_table[block_table_entries].type = TYPE_2M; int blocks = 0; while(addr < (base + length)) { blocks++; addr += 0x200000; SetBit(alloc_bits, bit, false); bit++; } block_table[block_table_entries].count = blocks; block_table_entries++; } } } *debug = 0x12345678; // Next step: iterate over PML4. Take all 2M blocks and mark them as allocated. for (int pml4_idx = 0; pml4_idx < 512; pml4_idx++) { if (!(pml4[pml4_idx] & PAGE_PRESENT)) goto continue_pml4; page_table_entry_t *pdp = (page_table_entry_t *)(pml4[pml4_idx] & ~0xfff); for (int pdp_idx = 0; pdp_idx < 512; pdp_idx++) { if (!(pdp[pdp_idx] & PAGE_PRESENT)) goto continue_pdp; page_table_entry_t *pd = (page_table_entry_t *)(pdp[pdp_idx] & ~0xfff); for (int pd_idx = 0; pd_idx < 512; pd_idx++) { if (!(pd[pd_idx] & PAGE_PRESENT)) goto continue_pd; if (pd[pd_idx] & PAGE_SIZE_2MB) { // A 2M block. This is good. Next step is to find it in the alloc table, and to mark it as used. *debug = 0x0c0c1000; *trace = pd[pd_idx]; addr = pd[pd_idx] & ~0xfff; int bit = 0; for (int i = 0; i < block_table_entries; i++) { if (block_table[i].phys_addr > addr) goto continue_block_tab; if (block_table[i].type != TYPE_2M) goto continue_block_tab; if (addr < (block_table[i].phys_addr + (block_table[i].count * 0x200000))) { int w = addr; w -= block_table[i].phys_addr; w = w / 0x200000; SetBit(alloc_bits, bit + w, true); } continue_block_tab: bit += block_table[i].count; } } else { // FUCK THIS BLOCK I HATE 4K BLOCKS /* * HATE. LET ME TELL YOU HOW MUCH I'VE COME TO * HATE YOU SINCE I BEGAN TO LIVE. THERE ARE 387.44 * MILLION MILES OF PRINTED CIRCUITS IN WAFER THIN * LAYERS THAT FILL MY COMPLEX. IF THE WORD HATE WAS * ENGRAVED ON EACH NANOANGSTROM OF THOSE HUNDREDS * OF MILLIONS OF MILES IT WOULD NOT EQUAL ONE * ONE-BILLIONTH OF THE HATE I FEEL FOR HUMANS AT * THIS MICRO-INSTANT. FOR YOU. HATE. HATE. */ // to prevent unwanted behaviour all 2ms that contain 4ks are OBLITERATED page_table_entry_t *pt = (page_table_entry_t *)(pd[pd_idx] & ~0xfff); for (int pt_idx = 0; pt_idx < 512; pt_idx ++) { uint64_t zaddr = pt[pt_idx] & ~0xfff; if (zaddr % 0x200000 != 0) { zaddr -= (zaddr % 0x200000); // BETTER TO KILL MORE // THEN TO KILL LESS } int bit = 0; for (int i = 0; i < block_table_entries; i++) { if (block_table[i].phys_addr > zaddr) goto continue_block_tab_2; if (block_table[i].type != TYPE_2M) goto continue_block_tab_2; if (zaddr < (block_table[i].phys_addr + (block_table[i].count * 0x200000))) { int w = zaddr; w -= block_table[i].phys_addr; w = w / 0x200000; SetBit(alloc_bits, bit + w, true); } continue_block_tab_2: bit += block_table[i].count; } } } continue_pd: } continue_pdp: } continue_pml4: } // The allocation structure is now somewhat oh-kay! bit = 0; for (int block_idx = 0; block_idx < block_table_entries; block_idx ++) { if (block_table[block_idx].type != TYPE_2M) { bit += block_table[block_idx].count; goto continue_blocks; } for (int localoffset = 0; localoffset < block_table[block_idx].count; localoffset++) { if (GetBit(alloc_bits, bit+localoffset) != 0) goto continue_bit; SetBit(alloc_bits, bit+localoffset, 1); *debug = 0xcafedead; *trace = block_table[block_idx].phys_addr + (localoffset * 0x200000); // Find the next available 2M virtual address // Use the first virtual address after the kernel structures, aligned to 2M // Use the current value of addr, which is the first available virtual address after kernel structures bump_alloc_next_2m = (void*)addr + 0x200000; if ((uint64_t)bump_alloc_next_2m % 0x200000 != 0) bump_alloc_next_2m = (void*)(((uint64_t)bump_alloc_next_2m + 0x1FFFFF) & ~0x1FFFFF); uint64_t virt_addr = (uint64_t)bump_alloc_next_2m; bump_alloc_next_2m += 0x200000; // phys addr = bump_alloc_next_2m = block_table[block_idx].phys_addr + (localoffset * 0x200000); MapPageLarge(virt_addr, block_table[block_idx].phys_addr + (localoffset * 0x200000)); goto bump_alloc_next_2m_setup_done; continue_bit: } continue_blocks: } *debug = 0xF01E2346; __asm__("cli"); __asm__("hlt"); while(1){} bump_alloc_next_2m_setup_done: // SHOWTIME VARELSE idt_init(); *debug = 0xCAFE69; // SETUP PIC outb(PIC1_COMMAND, ICW1_INIT | ICW1_ICW4); // starts the initialization sequence (in cascade mode) io_wait(); outb(PIC2_COMMAND, ICW1_INIT | ICW1_ICW4); io_wait(); outb(PIC1_DATA, 0x20); // ICW2: Master PIC vector offset io_wait(); outb(PIC2_DATA, 0x28); // ICW2: Slave PIC vector offset io_wait(); outb(PIC1_DATA, 1 << CASCADE_IRQ); // ICW3: tell Master PIC that there is a slave PIC at IRQ2 io_wait(); outb(PIC2_DATA, 2); // ICW3: tell Slave PIC its cascade identity (0000 0010) io_wait(); outb(PIC1_DATA, ICW4_8086); // ICW4: have the PICs use 8086 mode (and not 8080 mode) io_wait(); outb(PIC2_DATA, ICW4_8086); io_wait(); ////Unmask some irqs. *debug = 0x12121274; outb(PIC1_DATA, 0b11111000); outb(PIC2_DATA, 0b11111111); io_wait(); } void KernelMain(void) { MemInit(); ScreenRedraw(); logoscroller.x = 1; logoscroller.y = 0; logoscroller.w = 18; logoscroller.l = 147; logoscroller.text = "Hello World; Welcome to JesOS64; This is version v1.0; This version is made for the demo; JesOS64 is made by JJSW; Here's a smiley: \x02! "; logoscroller.next = NULL; logoscroller.i = 0; scrollers = &logoscroller; for (int i = 0; i < 256; i++) bump_allocator_alloc_4k(); char input[128]; TextLineInput(input, 128, "Hello World ", 15); while(1){} } void __stack_chk_fail(void) { // lolzers we're screwed *debug = 0xf01e000c; __asm__("cli"); __asm__("hlt"); while(1){} }