make a few variables static, fix some warnings, clean up code

This commit is contained in:
hippoz 2020-11-25 23:43:24 +02:00
parent a4bcf4fe28
commit 7df1bb6478
7 changed files with 34 additions and 44 deletions

View file

@ -111,22 +111,21 @@ _start:
; aligned above and we've since pushed a multiple of 16 bytes to the
; stack since (pushed 0 bytes so far) and the alignment is thus
; preserved and the call is well defined.
; note, that if you are building on Windows, C functions may have "_" prefix in assembly: _kernel_main
extern kernel_main
call kernel_main
; note, that if you are building on Windows, C functions may have "_" prefix in assembly: _kmain
extern kmain
call kmain
; If the system has nothing more to do, put the computer into an
; infinite loop. To do that:
; 1) Disable interrupts with cli (clear interrupt enable in eflags).
; They are already disabled by the bootloader, so this is not needed.
; Mind that you might later enable interrupts and return from
; kernel_main (which is sort of nonsensical to do).
; kmain (which is sort of nonsensical to do).
; 2) Wait for the next interrupt to arrive with hlt (halt instruction).
; Since they are disabled, this will lock up the computer.
; 3) Jump to the hlt instruction if it ever wakes up due to a
; non-maskable interrupt occurring or due to system management mode.
cli
.hang: hlt
jmp .hang
.end:
.end:

View file

@ -2,8 +2,8 @@
#include <terminal.h>
struct idt_entry idt[256];
unsigned long idt_address;
unsigned long idt_ptr[2];
static unsigned long idt_address;
static unsigned long idt_ptr[2];
void idt_init() {
idt_address = (unsigned long)idt;

View file

@ -1,72 +1,72 @@
#include <isr.h>
#include <terminal.h>
__attribute__((interrupt)) void isr0(struct interrupt_frame* frame) {
__attribute__((interrupt)) static void isr0(struct interrupt_frame* frame) {
terminal_writeline("Division By Zero");
asm("hlt");
}
__attribute__((interrupt)) void isr1(struct interrupt_frame* frame) {
__attribute__((interrupt)) static void isr1(struct interrupt_frame* frame) {
terminal_writeline("Debug");
asm("hlt");
}
__attribute__((interrupt)) void isr2(struct interrupt_frame* frame) {
__attribute__((interrupt)) static void isr2(struct interrupt_frame* frame) {
terminal_writeline("Non Maskable Interrupt");
asm("hlt");
}
__attribute__((interrupt)) void isr3(struct interrupt_frame* frame) {
__attribute__((interrupt)) static void isr3(struct interrupt_frame* frame) {
terminal_writeline("Breakpoint");
asm("hlt");
}
__attribute__((interrupt)) void isr4(struct interrupt_frame* frame) {
__attribute__((interrupt)) static void isr4(struct interrupt_frame* frame) {
terminal_writeline("Into Detected Overflow");
asm("hlt");
}
__attribute__((interrupt)) void isr5(struct interrupt_frame* frame) {
__attribute__((interrupt)) static void isr5(struct interrupt_frame* frame) {
terminal_writeline("Out of Bounds");
asm("hlt");
}
__attribute__((interrupt)) void isr6(struct interrupt_frame* frame) {
__attribute__((interrupt)) static void isr6(struct interrupt_frame* frame) {
terminal_writeline("Invalid Opcode");
asm("hlt");
}
__attribute__((interrupt)) void isr7(struct interrupt_frame* frame) {
__attribute__((interrupt)) static void isr7(struct interrupt_frame* frame) {
terminal_writeline("No Coprocessor");
asm("hlt");
}
__attribute__((interrupt)) void isr8(struct interrupt_frame* frame) {
__attribute__((interrupt)) static void isr8(struct interrupt_frame* frame) {
terminal_writeline("Double Fault");
asm("hlt");
}
__attribute__((interrupt)) void isr9(struct interrupt_frame* frame) {
__attribute__((interrupt)) static void isr9(struct interrupt_frame* frame) {
terminal_writeline("Coprocessor Segment Overrun");
asm("hlt");
}
__attribute__((interrupt)) void isr10(struct interrupt_frame* frame) {
__attribute__((interrupt)) static void isr10(struct interrupt_frame* frame) {
terminal_writeline("Bad TSS");
asm("hlt");
}
__attribute__((interrupt)) void isr11(struct interrupt_frame* frame) {
__attribute__((interrupt)) static void isr11(struct interrupt_frame* frame) {
terminal_writeline("Segment Not Present");
asm("hlt");
}
__attribute__((interrupt)) void isr12(struct interrupt_frame* frame) {
__attribute__((interrupt)) static void isr12(struct interrupt_frame* frame) {
terminal_writeline("Stack Fault");
asm("hlt");
}
__attribute__((interrupt)) void isr13(struct interrupt_frame* frame) {
__attribute__((interrupt)) static void isr13(struct interrupt_frame* frame) {
terminal_writeline("General Protection Fault");
terminal_writeline("heres some info:");
@ -81,32 +81,32 @@ __attribute__((interrupt)) void isr13(struct interrupt_frame* frame) {
asm("hlt");
}
__attribute__((interrupt)) void isr14(struct interrupt_frame* frame) {
__attribute__((interrupt)) static void isr14(struct interrupt_frame* frame) {
terminal_writeline("Page Fault");
asm("hlt");
}
__attribute__((interrupt)) void isr15(struct interrupt_frame* frame) {
__attribute__((interrupt)) static void isr15(struct interrupt_frame* frame) {
terminal_writeline("Unknown Interrupt");
asm("hlt");
}
__attribute__((interrupt)) void isr16(struct interrupt_frame* frame) {
__attribute__((interrupt)) static void isr16(struct interrupt_frame* frame) {
terminal_writeline("Coprocessor Fault");
asm("hlt");
}
__attribute__((interrupt)) void isr17(struct interrupt_frame* frame) {
__attribute__((interrupt)) static void isr17(struct interrupt_frame* frame) {
terminal_writeline("Alignment Check");
asm("hlt");
}
__attribute__((interrupt)) void isr18(struct interrupt_frame* frame) {
__attribute__((interrupt)) static void isr18(struct interrupt_frame* frame) {
terminal_writeline("Machine Check");
asm("hlt");
}
__attribute__((interrupt)) void isr_reserved(struct interrupt_frame* frame) {
__attribute__((interrupt)) static void isr_reserved(struct interrupt_frame* frame) {
terminal_writeline("Reserved");
asm("hlt");
}

View file

@ -14,7 +14,9 @@
#error "This operating system needs to be compiled with a ix86-elf compiler"
#endif
void kernel_main() {
uint8_t is_running = 1;
void kmain() {
terminal_initialize();
terminal_writeline("Initializing terminal... done");
terminal_writestring("Preparing interrupts... ");
@ -42,12 +44,5 @@ void kernel_main() {
terminal_writeline("hello yes");
terminal_writestring("> ");
while (true);
//while (true) {
// if (inportb(0x64) & 1) {
// const char key = keyboard_to_ascii(parse_keycode(inportb(0x60)));
// terminal_putchar(key);
// }
//}
}
while (is_running);
}

View file

@ -1,3 +1,4 @@
#include <pic.h>
#include <keyboard.h>
#include <stdbool.h>
@ -43,7 +44,7 @@ unsigned char kbdus[128] = {
uint8_t lastkey = 0;
uint8_t __kbd_enabled = 0;
__attribute__((interrupt)) void keyboard_irq(struct interrupt_frame* frame) {
__attribute__((interrupt)) static void keyboard_irq(struct interrupt_frame* frame) {
unsigned char scancode = inportb(0x60);
bool special = true;

View file

@ -10,9 +10,6 @@
extern "C" {
#endif
extern char* keycache;
extern uint16_t key_loc;
void keyboard_init(void);
uint8_t keyboard_enabled(void);

View file

@ -12,8 +12,6 @@ extern "C" {
void* malloc(size_t amount);
static size_t rand_next;
int rand(void);
void srand(size_t seed);
char* itoa(int res);