aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2021-04-08 19:06:44 +0200
committerLoic Guegan <manzerbredes@mailbox.org>2021-04-08 19:06:44 +0200
commit8fee35522dee033863f68c1d2b45f5fe988de9eb (patch)
tree5e094806066d2f13bc5ad1fefe663d132e291f8e /src
parent958e2dae042ca9e28f23e509d541730f30fa8502 (diff)
Handle clock interrupt and cleaning code
Diffstat (limited to 'src')
-rw-r--r--src/Makefile7
-rw-r--r--src/boot/multiboot.c (renamed from src/utils/multiboot.c)17
-rw-r--r--src/boot/multiboot.h (renamed from src/utils/multiboot.h)15
-rw-r--r--src/bringelle.c23
-rw-r--r--src/utils/asm.h1
-rw-r--r--src/utils/pic.c14
-rw-r--r--src/utils/print.c18
-rw-r--r--src/utils/print.h1
8 files changed, 79 insertions, 17 deletions
diff --git a/src/Makefile b/src/Makefile
index 28081af..af32fdd 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,5 +1,5 @@
EXEC := bringelle
-CC := gcc -c -m32 -fno-pie -fno-builtin -fno-stack-protector
+CC := gcc -c -m32 -fno-pie -fno-builtin -fno-stack-protector -I ./
LD_SCRIPT := linker.ld
# Note that BOOT_OBJ do not match boot.S
@@ -10,15 +10,14 @@ UTILS_OBJ := $(addsuffix .o,$(basename $(shell find ./utils -name "*.[c|S]")))
all: $(EXEC)
-$(EXEC): boot/boot.o $(UTILS_OBJ) bringelle.o
+$(EXEC): boot/boot.o $(BOOT_OBJ) $(UTILS_OBJ) bringelle.o
ld -n -T $(LD_SCRIPT) -nostdlib -o bringelle $^
%.o: %.S
- as --32 -o $@ $^ -mx86-used-note=no
+ as --32 -o $@ $^
%.o: %.c
$(CC) -o $@ $<
- #objcopy --remove-section .note.gnu.property $@
clean:
rm -f $(EXEC)
diff --git a/src/utils/multiboot.c b/src/boot/multiboot.c
index 891bd57..0309eb0 100644
--- a/src/utils/multiboot.c
+++ b/src/boot/multiboot.c
@@ -1,5 +1,7 @@
#include "multiboot.h"
+#include "utils/mem.h"
+/// See boot.S
extern u8* MB_INFO;
char mb_load_tag(char **data, char type){
@@ -7,7 +9,8 @@ char mb_load_tag(char **data, char type){
char *c_tag_type=c_info_size+8;
char *c_tag_size=c_info_size+12;
- for(int i=0;i<10;i++){
+ int max_size=*((int*)c_info_size);
+ while(((int)c_tag_type-(int)MB_INFO)<max_size){
int tag_type=*((int*)c_tag_type);
int tag_size=*((int*)c_tag_size);
if(tag_type==type){
@@ -37,3 +40,15 @@ char mb_load_bl_name(MBI_TAG_BL_NAME *data){
}
return 1;
}
+
+char mb_load_fb(MBI_TAG_FB *data){
+ char *to_load;
+ if(!mb_load_tag(&to_load,8)){
+ asm("mov %0, %%ecx;aa:;jmp aa;"::"r"(to_load));
+ memcpy(to_load,data,8);
+ to_load+=8;
+ memcpy(to_load,&(data->framebuffer_addr),8);
+ return 0;
+ }
+ return 1;
+}
diff --git a/src/utils/multiboot.h b/src/boot/multiboot.h
index 4194d00..010f60b 100644
--- a/src/utils/multiboot.h
+++ b/src/boot/multiboot.h
@@ -1,7 +1,7 @@
#ifndef MULTIBOOT_H
#define MULTIBOOT_H
-#include "types.h"
+#include "utils/types.h"
typedef struct MBI_TAG_HEADER {
u32 type;
@@ -13,7 +13,6 @@ typedef struct MBI_TAG_BL_NAME {
u8 *name;
} __attribute__((packed)) MBI_TAG_BL_NAME;
-
typedef struct MBI_TAG_FB {
MBI_TAG_HEADER header;
u64 framebuffer_addr;
@@ -26,7 +25,17 @@ typedef struct MBI_TAG_FB {
u8 *color_infos;
}__attribute__((packed)) MBI_TAG_FB;
-
+/**
+ * Parse Bootloader boot information structure
+ */
char mb_load_tag(char **data, char type);
+/**
+ * Search for Bootloader name
+ */
char mb_load_bl_name(MBI_TAG_BL_NAME *data);
+/**
+ * Search for FrameBuffer structure (TODO: Finish)
+ */
+char mb_load_fb(MBI_TAG_FB *data);
+
#endif \ No newline at end of file
diff --git a/src/bringelle.c b/src/bringelle.c
index 9e17906..f6b099c 100644
--- a/src/bringelle.c
+++ b/src/bringelle.c
@@ -2,22 +2,31 @@
#include "utils/asm.h"
#include "utils/pic.h"
#include "utils/8042.h"
-#include "utils/multiboot.h"
+#include "boot/multiboot.h"
extern char *name_addr;
void bringelle(){
+ clear();
+ printc("Booting Bringelle...\n",GREEN);
+ pic_enable_interrupt();
- // clear();
- //print("Booting Bringelle...");
- //pic_enable_interrupt();
- print("Booting Bringelle...");
+ // Search for bootloader informations
MBI_TAG_BL_NAME bl_infos;
if(!mb_load_bl_name(&bl_infos)){
print(bl_infos.name);
- print(" detected!");
+ print(" detected!\n");
}
-
while(1);
}
+
+void clock(){
+ static int tic=0;
+ static int sec=0;
+ tic++;
+ if(tic>=20){
+ tic=0;
+ sec++;
+ }
+}
diff --git a/src/utils/asm.h b/src/utils/asm.h
index f92195f..be265d8 100644
--- a/src/utils/asm.h
+++ b/src/utils/asm.h
@@ -9,4 +9,5 @@
#define inb(port,dst) \
asm volatile ("inb %%dx, %%al": "=a" (dst) : "d" (port))
+
#endif \ No newline at end of file
diff --git a/src/utils/pic.c b/src/utils/pic.c
index 4459f0d..4806cb9 100644
--- a/src/utils/pic.c
+++ b/src/utils/pic.c
@@ -18,15 +18,22 @@ asm (
"movb $0x20, %al \n\t"
"outb %al, $0x20 \n\t"
"iret \n\t"
+"PIC_IRQ_CLOCK: \n\t"
+ "call clock \n\t"
+ "movb $0x20, %al \n\t"
+ "outb %al, $0x20 \n\t"
+ "iret \n\t"
);
-extern u32 PIC_IRQ_DEFAULT,PIC_IRQ_PRINT;
+extern u32 PIC_IRQ_DEFAULT,PIC_IRQ_PRINT,PIC_IRQ_CLOCK;
void pic_enable_interrupt(){
// Map first default 32 entries
for(int i=0;i<100;i++){
pic_add_idt_entry((IDT_ENTRY){0x08,(u32)&PIC_IRQ_DEFAULT,IDT_TYPE_1},i);
if(i==32)
+ pic_add_idt_entry((IDT_ENTRY){0x08,(u32)&PIC_IRQ_CLOCK,IDT_TYPE_1},i);
+ if(i==33)
pic_add_idt_entry((IDT_ENTRY){0x08,(u32)&PIC_IRQ_PRINT,IDT_TYPE_1},i);
}
@@ -48,6 +55,10 @@ void pic_enable_interrupt(){
outbj(0x21,0x01); // Default operating mode
outbj(0xA1,0x01); // Default operating mode
+ // OCW: Masking
+ outbj(0x21,0);
+
+
asm("lidtl (IDTR)");
asm("sti");
}
@@ -56,6 +67,5 @@ void pic_add_idt_entry(IDT_ENTRY entry, int id){
int descriptor[2];
descriptor[0]=entry.offset & 0xFFFF | entry.segment << 16;
descriptor[1]=entry.type & 0xFFFF | entry.offset & 0xFFFF0000;
-
memcpy((void*)descriptor, (void *)(IDTR.base+(id*8)),8);
}
diff --git a/src/utils/print.c b/src/utils/print.c
index dbed000..c2cdaf1 100644
--- a/src/utils/print.c
+++ b/src/utils/print.c
@@ -20,6 +20,17 @@ VIDEO_STATE VS={
};
void putchar(char c){
+ // Handle newline here
+ if(c=='\n'){
+ VS.col=0;
+ VS.line+=1;
+ if(VS.line>=MAX_LINE){
+ VS.line=MAX_LINE-1;
+ scrollup();
+ }
+ return;
+ }
+
// Print char
VS.mem[VS.col*2+MAX_COL*VS.line*2]=c;
VS.mem[VS.col*2+MAX_COL*VS.line*2+1]=VS.fg|VS.bg<<4;
@@ -44,6 +55,13 @@ void print(char *str){
}
}
+void printc(char* str,VIDEO_COLORS c){
+ VIDEO_COLORS backup=VS.fg;
+ VS.fg=c;
+ print(str);
+ VS.fg=backup;
+}
+
void clear(){
for(char i=0;i<MAX_LINE;i++){
scrollup();
diff --git a/src/utils/print.h b/src/utils/print.h
index d04fed2..163f4ec 100644
--- a/src/utils/print.h
+++ b/src/utils/print.h
@@ -16,6 +16,7 @@ typedef struct VIDEO_STATE VIDEO_STATE;
*/
void putchar(char);
void print(char*);
+void printc(char*,VIDEO_COLORS c);
void scrollup();
void clear();