aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile5
-rw-r--r--src/boot/boot.S53
-rw-r--r--src/boot/multiboot2.cc4
-rw-r--r--src/boot/multiboot2.hpp1
-rw-r--r--src/boot/trampoline.cc94
-rw-r--r--src/boucane.cc39
-rw-r--r--src/core/apic.cc11
-rw-r--r--src/core/apic.hpp2
-rw-r--r--src/core/gdt.S25
-rw-r--r--src/core/idt.cc28
-rw-r--r--src/core/idt.hpp5
-rw-r--r--src/core/int.S4
-rw-r--r--src/core/paging.cc62
-rw-r--r--src/core/paging.hpp16
-rw-r--r--src/drivers/vga_t.cc9
-rw-r--r--src/drivers/vga_t.hpp2
-rw-r--r--src/include/boucane.hpp2
-rw-r--r--src/linker.ld49
18 files changed, 285 insertions, 126 deletions
diff --git a/src/Makefile b/src/Makefile
index 32c8a7a..e4b2a82 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,5 +1,5 @@
EXEC := boucane
-CC := g++ -nostdlib -nostdinc -no-pie -fno-builtin -fno-stack-protector -I ./ -I include
+CC := g++ -mcmodel=large -nostdlib -nostdinc -no-pie -fno-builtin -fno-stack-protector -I ./ -I include
LD_SCRIPT := linker.ld
# Note that BOOT_OBJ do not match boot.S
@@ -14,8 +14,7 @@ RES_OBJ := $(addsuffix .o,$(basename $(shell find ./res -type f)))
all: $(EXEC)
$(EXEC): boot/boot.o $(BOOT_OBJ) $(DRIVERS_OBJ) $(LIBS_OBJ) $(CORE_OBJ) $(RES_OBJ) boucane.o
- echo "Resource: $(RES_OBJ)"
- $(CC) -n -T $(LD_SCRIPT) -nostdlib -o $@ $^
+ $(CC) -T $(LD_SCRIPT) -nostdlib -o $@ $^
%.o: %.S
as -o $@ $^
diff --git a/src/boot/boot.S b/src/boot/boot.S
index 7f12eed..73ee637 100644
--- a/src/boot/boot.S
+++ b/src/boot/boot.S
@@ -2,9 +2,7 @@
.globl MB_INFO
.extern _bss_start
.extern _bss_end
-.extern boucane
-
-.set STACK_LOCATION, 0x1FFFFF
+.extern higherhalf
.section .multiboot
@@ -37,7 +35,7 @@ mb_header_start:
# ----------- End tag
# ----------- Ask framebuffer tag
.align 8
-.short 5
+.short 6
.short 1
.int 20
.int 0
@@ -57,16 +55,6 @@ MB_INFO: # Will contains the Multiboot2 information data structure address
_start:
mov %ebx, (MB_INFO)
-# Zeroing the .bss section
-mov $_bss_start, %eax
-mov $_bss_end, %ebx
-start_zeroing:
- movb $0x0, (%eax)
- cmp %eax, %ebx
- je end_zeroing
- inc %eax
- jmp start_zeroing
-end_zeroing:
# ----- Setup PAE Paging (identity on the first 10MB)
mov $8192, %ecx # 8*4096/4 (8 tables of 4096 byte each divide by 4 because of movl)
mov $0, %eax
@@ -117,7 +105,7 @@ mov %eax, %cr0
# Now we are in Compatibility mode
# Now we need to set CS.L=1 (setting up a 64 bit GDT)
-lgdt (gdtr)
+lgdt (boot_gdtr)
ljmp $0x08, $new_cs
new_cs:
@@ -132,27 +120,42 @@ mov %ax, %es
mov %ax, %fs
mov %ax, %gs
mov %ax, %ss
-mov $STACK_LOCATION, %esp
+mov $__stack_pma, %esp
+
+# Setup
+call trampoline
+mov $__kernel_vma, %rsp
+
+# Zeroing the .bss section
+mov $__bss_start, %rax
+mov $__bss_end, %rbx
+start_zeroing:
+ movb $0x0, (%rax)
+ cmp %rax, %rbx
+ je end_zeroing
+ inc %rax
+ jmp start_zeroing
+end_zeroing:
-# Run boucane
-jmp boucane
+# Launch kernel
+call boucane
# GDT
-gdt64:
- gdt64_null:
+boot_gdt64:
+ boot_gdt64_null:
.long 0
.long 0
- gdt64_cs:
+ boot_gdt64_cs:
.long 0
.byte 0
.byte 0b10011100
.byte 0b00100000
.byte 0
- gdt64_ds:
+ boot_gdt64_ds:
.long 0
.byte 0
.byte 0b10010010
.word 0
-gdtr:
- .word . - gdt64 - 1
- .quad gdt64
+boot_gdtr:
+ .word . - boot_gdt64 - 1
+ .quad boot_gdt64
diff --git a/src/boot/multiboot2.cc b/src/boot/multiboot2.cc
index d1a912d..532012e 100644
--- a/src/boot/multiboot2.cc
+++ b/src/boot/multiboot2.cc
@@ -1,9 +1,13 @@
#include "multiboot2.hpp"
+#include "core/paging.hpp"
#include "libs/string.hpp"
#include "libs/stdio.hpp"
u32* mb2_find_tag(u32 *mb2_info_addr, char type){
+ PAGING_MAP(mb2_info_addr);
u32 size=(u32)mb2_info_addr[0];
+ for(u64 i=0;i<size/8;i++)
+ PAGING_MAP(mb2_info_addr+i*4096);
char *location=((char*)mb2_info_addr)+8; // Goto first tag
char *start=(char*)mb2_info_addr;
diff --git a/src/boot/multiboot2.hpp b/src/boot/multiboot2.hpp
index cc28109..db946a7 100644
--- a/src/boot/multiboot2.hpp
+++ b/src/boot/multiboot2.hpp
@@ -1,6 +1,7 @@
#pragma once
#include "core/types.hpp"
+#include "include/boucane.hpp"
typedef struct TAG_HEADER {
u32 type;
diff --git a/src/boot/trampoline.cc b/src/boot/trampoline.cc
new file mode 100644
index 0000000..b03bd43
--- /dev/null
+++ b/src/boot/trampoline.cc
@@ -0,0 +1,94 @@
+/**
+ * The usage of data that could goes
+ * to the .bss section is forbidden here
+ */
+
+#include "core/types.hpp"
+#include "core/paging.hpp"
+
+
+/// @brief Define where first PAE paging paging will be
+u64 trampoline_next_page;
+
+u64 trampoline_paging_allocate_table(){
+ for(u64 i=0;i<512;i++)
+ ((u64*)trampoline_next_page)[i]=0;
+ u64 ret=trampoline_next_page;
+ trampoline_next_page+=4096;
+ return ret;
+}
+
+
+void trampoline_paging_allocate_addr(u64* pml4_table, u64 virt, u64 phy, u16 options){
+ u64 pml4=virt>>39&0x1FF;
+ u64 pdp=virt>>30&0x1FF;
+ u64 pd=virt>>21&0x1FF;
+ u64 pt=virt>>12&0x1FF;
+ options&=0xFFF; // Ensure options are on 12bits
+
+
+ // Solve pdp
+ if(pml4_table[pml4] == 0){
+ pml4_table[pml4]=(u64)trampoline_paging_allocate_table();
+ pml4_table[pml4]|=options;
+ trampoline_paging_allocate_addr(pml4_table,virt,phy,options);
+ return;
+ }
+
+ // Solve pd
+ u64* pdp_table=(u64*)PAGE(pml4_table[pml4]);
+ if(pdp_table[pdp] == 0){
+ pdp_table[pdp]=(u64)trampoline_paging_allocate_table();
+ pdp_table[pdp]|=options;
+ trampoline_paging_allocate_addr(pml4_table,virt,phy,options);
+ return;
+ }
+ // Solve pt
+ u64* pd_table=(u64*)PAGE(pdp_table[pdp]);
+ if(pd_table[pd] == 0){
+ pd_table[pd]=(u64)trampoline_paging_allocate_table();
+ pd_table[pd]|=options;
+ trampoline_paging_allocate_addr(pml4_table,virt,phy,options);
+ return;
+ }
+ // Solve address
+ u64* pt_table=(u64*)PAGE(pd_table[pd]);
+ if(pt_table[pt] == 0){
+ pt_table[pt]=PAGE(phy);
+ pt_table[pt]|=options;
+ return;
+ }
+}
+
+/**
+ * Setup High-Half Kernel Paging
+ */
+extern "C" void trampoline(){
+ u64 kernel_vma,stack_pma;
+ asm("movq $__kernel_vma, %0":"=r"(kernel_vma));
+ asm("movq $__userspace_pma, %0":"=r"(trampoline_next_page));
+ asm("movq $__stack_pma, %0":"=r"(stack_pma));
+
+ // ----- Build the trampoline paging tables
+ u64 *pml4=(u64*)trampoline_paging_allocate_table();
+ // Higher Half kernel
+ for(u64 i=0;i<=0x1000000;i+=4096){
+ trampoline_paging_allocate_addr(pml4,kernel_vma+i,i,0x3);
+ }
+ // Stack
+ trampoline_paging_allocate_addr(pml4,kernel_vma-4096,stack_pma,0x3);
+ // First bytes for current eip
+ for(u64 i=0;i<=0x1000000;i+=4096){
+ trampoline_paging_allocate_addr(pml4,i,i,0x3);
+ }
+ // Test
+ for(u64 i=0xe0000000;i<=0xef000000;i+=4096){
+ trampoline_paging_allocate_addr(pml4,i,i,0x3);
+ }
+
+ // Load new pml4
+ asm volatile(
+ "movq %0, %%rax \n\t"
+ "movq %%rax, %%cr3 \n\t"
+ :: "r" (pml4));
+} \ No newline at end of file
diff --git a/src/boucane.cc b/src/boucane.cc
index 791c5cc..0209281 100644
--- a/src/boucane.cc
+++ b/src/boucane.cc
@@ -8,25 +8,19 @@
#include "drivers/framebuffer.hpp"
#include "libs/stdio.hpp"
#include "core/asm.hpp"
-extern u32 MB_INFO;
-extern u64 res_binary_res_terminus_psf_start;
-
-
-
-
-
+extern u32 MB_INFO;
+extern u64 res_binary_res_terminus_psf_start;
extern "C" void boucane(){
- //clear();
- //printk("Booting Boucane v%d.%d.%d\n",VERSION_MAJOR,VERSION_MINOR, VERSION_PATH);
- //idt_enable_interrupt();
-
+ // Init data structures
+ LOAD_GDT();
paging_enable();
+ idt_enable_interrupt();
FRAMEBUFFER fb_info;
- if(mb2_find_framebuffer((u32*)MB_INFO, &fb_info)){
+ if(mb2_find_framebuffer((u32*)&MB_INFO, &fb_info)){
if(fb_info.bpp>16){
FB_CFG conf;
conf.depth=fb_info.bpp;
@@ -39,25 +33,10 @@ extern "C" void boucane(){
__putchar=psf_putchar;
}
}
+ vga_t_init();
+ vga_t_clear();
printk("Booting Boucane v%d.%d.%d\n",VERSION_MAJOR,VERSION_MINOR, VERSION_PATH);
- printk("Jean");
-
- printk("Loic");
- //framebuffer_clear();
- //apic_enable();
-
-/* u64 p;
- u32 size;
- if(mb2_find_old_rsdp((u32*)MB_INFO,&p,&size)){
- acpi_init((void*)p);
- }*/
- //FRAMEBUFFER fb;
- //if(mb2_find_framebuffer((u32*)MB_INFO, &fb)){
- //printk("Framebuffer found!");
- //framebuffer_init(fb.addr, fb.pitch, fb.bpp);
- //__putchar=psf_print;
- //printk("Hello");
- //}
+
while(1);
} \ No newline at end of file
diff --git a/src/core/apic.cc b/src/core/apic.cc
index a93e54e..0663014 100644
--- a/src/core/apic.cc
+++ b/src/core/apic.cc
@@ -5,18 +5,17 @@
#include "asm.hpp"
#include "libs/stdio.hpp"
-extern u64* kpml4;
char enable=0;
#define APIC_LAPIC_ADDR 0xFEE00000
#define APIC_IOAPIC_ADDR 0xFEC00000
#define APIC_LAPIC_REG_SPURIOUS 0xF0
void apic_enable(){
- // Allocate APIC registers
- paging_allocate_addr(kpml4, APIC_LAPIC_ADDR, APIC_LAPIC_ADDR,
- PAGING_OPT_RW|PAGING_OPT_P|PAGING_OPT_PCD);
- paging_allocate_addr(kpml4, APIC_IOAPIC_ADDR, APIC_IOAPIC_ADDR,
- PAGING_OPT_RW|PAGING_OPT_P|PAGING_OPT_PCD);
+ // Allocate APIC registers TODODODODOOD!!!!!
+ // paging_allocate_addr(kpml4, APIC_LAPIC_ADDR, APIC_LAPIC_ADDR,
+ //PAGING_OPT_RW|PAGING_OPT_P|PAGING_OPT_PCD);
+ //paging_allocate_addr(kpml4, APIC_IOAPIC_ADDR, APIC_IOAPIC_ADDR,
+ //PAGING_OPT_RW|PAGING_OPT_P|PAGING_OPT_PCD);
// Configure APIC register location
u32 h=APIC_LAPIC_ADDR>>32;
diff --git a/src/core/apic.hpp b/src/core/apic.hpp
index edfeaa3..a2670b3 100644
--- a/src/core/apic.hpp
+++ b/src/core/apic.hpp
@@ -1,6 +1,6 @@
#pragma once
-
+#include "include/boucane.hpp"
void apic_enable(); \ No newline at end of file
diff --git a/src/core/gdt.S b/src/core/gdt.S
new file mode 100644
index 0000000..f928b3f
--- /dev/null
+++ b/src/core/gdt.S
@@ -0,0 +1,25 @@
+.code64
+
+gdt64:
+ gdt64_null:
+ .long 0
+ .long 0
+ gdt64_cs:
+ .long 0
+ .byte 0
+ .byte 0b10011100
+ .byte 0b00100000
+ .byte 0
+ gdt64_ds:
+ .long 0
+ .byte 0
+ .byte 0b10010010
+ .word 0
+gdtr:
+ .word . - gdt64 - 1
+ .quad gdt64
+
+.global load_gdt
+load_gdt:
+ lgdt (gdtr)
+ ret
diff --git a/src/core/idt.cc b/src/core/idt.cc
index a73d92c..25264b6 100644
--- a/src/core/idt.cc
+++ b/src/core/idt.cc
@@ -1,14 +1,16 @@
#include "idt.hpp"
+#include "core/paging.hpp"
#include "libs/string.hpp"
-IDT_REGISTER IDTR = {
- IDT_GATE_SIZE*IDT_MAX_ENTRIES,
- IDT_ADDR
-};
+u32 idt[IDT_MAX_ENTRIES][4] __attribute__((aligned(4096)));;
+IDT_REGISTER IDTR;
extern u64 INT_DEFAULT,INT_0,INT_14,INT_KBD;
void idt_enable_interrupt(void){
+ IDTR.base=((u64)idt);
+ IDTR.limit=sizeof(idt);
+
IDT_DESCRIPTOR d;
d.ign=0;
d.ist=0;
@@ -25,7 +27,7 @@ void idt_enable_interrupt(void){
d.offset=(u64)&INT_14;
idt_write_descriptor(d, i);
}
- else if(i==60){ // Page fault
+ else if(i==60){ // Keyboard
d.offset=(u64)&INT_KBD;
idt_write_descriptor(d, i);
}
@@ -34,12 +36,11 @@ void idt_enable_interrupt(void){
idt_write_descriptor(d, i);
}
}
-
+
// Enable interrupts
asm(
- "lidt (IDTR) \n\t"
- "sti \n\t"
- );
+ "lidt (IDTR) \n\t"
+ "sti \n\t ");
}
void idt_write_descriptor(IDT_DESCRIPTOR desc, u16 index){
@@ -47,9 +48,8 @@ void idt_write_descriptor(IDT_DESCRIPTOR desc, u16 index){
u32 desc32_63=desc.ist | desc.options | (desc.offset&0xFFFF0000);
u32 desc64_95=desc.offset>>32;
u32 desc96_127=desc.ign;
- u32* dst=(u32*)(IDTR.base+index*IDT_GATE_SIZE);
- *dst=desc0_31;
- *(dst+1)=desc32_63;
- *(dst+2)=desc64_95;
- *(dst+3)=desc96_127;
+ idt[index][0]=desc0_31;
+ idt[index][1]=desc32_63;
+ idt[index][2]=desc64_95;
+ idt[index][3]=desc96_127;
} \ No newline at end of file
diff --git a/src/core/idt.hpp b/src/core/idt.hpp
index 2f2050d..1133ad1 100644
--- a/src/core/idt.hpp
+++ b/src/core/idt.hpp
@@ -5,7 +5,7 @@
#define IDT_GATE_SIZE 16
#define IDT_MAX_ENTRIES 200
-#define IDT_ADDR 0x200000
+#define IDT_ADDR 0
#define IDT_OPT_P (1 << 15)
#define IDT_OPT_TYPE_INT 0xE << 8
@@ -27,5 +27,8 @@ typedef struct IDT_DESCRIPTOR {
u32 ign;
} __attribute__((packed)) IDT_DESCRIPTOR;
+/// @brief 3 u32 per entry
+extern u32 idt[IDT_MAX_ENTRIES][4];
+
void idt_enable_interrupt(void);
void idt_write_descriptor(IDT_DESCRIPTOR desc, u16 index); \ No newline at end of file
diff --git a/src/core/int.S b/src/core/int.S
index 1c8d7bb..daf0224 100644
--- a/src/core/int.S
+++ b/src/core/int.S
@@ -1,3 +1,5 @@
+.code64
+
.extern printk
.extern ack
@@ -40,4 +42,4 @@ MSG_INT_14:
MSG_INT_KBD:
.asciz "Key press!"
MSG:
-.asciz "Called :)\n" \ No newline at end of file
+.asciz "Called :)\n"
diff --git a/src/core/paging.cc b/src/core/paging.cc
index 8e58511..73a5c63 100644
--- a/src/core/paging.cc
+++ b/src/core/paging.cc
@@ -4,29 +4,50 @@
#include "libs/string.hpp"
char paging_status[PAGING_MAX_PAGE / 8];
-u64* kpml4;
+u64 kernel_vma,stack_pma,userspace_pma;
+u64 kpages[MAX_TABLES][512] __attribute__((aligned(4096)));
+int kpages_next=1; // First page is for the pml4
+
+u64* paging_allocate_table(){
+ u64 addr=(u64)kpages[kpages_next];
+ u64* allocated=(u64*)(addr-kernel_vma);
+ kpages_next++;
+ return allocated;
+}
void paging_enable() {
+ // Init linker variables
+ asm("movq $__kernel_vma, %0":"=r"(kernel_vma));
+ asm("movq $__userspace_pma, %0":"=r"(userspace_pma));
+ asm("movq $__stack_pma, %0":"=r"(stack_pma));
+
// Init status
for (int i = 0; i < PAGING_MAX_PAGE / 8; i++) {
paging_status[i] = 0;
}
+ // Init tables
+ for(int i=0;i<MAX_TABLES;i++){
+ memset(kpages[i], 0, 512*64);
+ }
+
// Allocate paging for the kernel (to not override the source
// code during the next paging_allocate_table() calls)
- paging_allocate_contiguous(PAGING_KERNEL_USED_PAGE);
+ paging_allocate_contiguous(userspace_pma/4096);
// Setting up new kernel address space
- kpml4=paging_allocate_table();
- for(int i=0;i<PAGING_KERNEL_SPACE_MAX_PAGE;i++){
- int addr=i*4096;
- paging_allocate_addr(kpml4,addr,addr, PAGING_OPT_P|PAGING_OPT_RW); // Identity map
+ for(u64 i=0;i<=0x10000000;i+=4096){
+ paging_allocate_addr(kpages[0],kernel_vma+i,i, 0x3,0); // Identity map
}
+ // 4096 bytes stack
+ paging_allocate_addr(kpages[0],kernel_vma-4096,stack_pma,0x3,0);
+
// Load new pml4
+ u64 kpage_phy=((u64)kpages[0]-kernel_vma);
asm volatile(
- "movq %0, %%rax \n\t"
- "movq %%rax, %%cr3 \n\t"
- :: "r" (kpml4));
+ "mov %0, %%rax \n\t"
+ "mov %%rax, %%cr3 \n\t"
+ :: "r" (kpage_phy));
}
u64 paging_as_phy(u64* pml4_table, u64 virt){
@@ -40,6 +61,7 @@ u64 paging_as_phy(u64* pml4_table, u64 virt){
u64* pt_table=(u64*)PAGE(pd_table[pd]);
return((PAGE(pt_table[pt]))|(virt&0xFFF));
}
+
u64* paging_allocate_contiguous(int npages){
int n_contiguous=0;
for (int i = 0; i < PAGING_MAX_PAGE / 8; i++) {
@@ -116,12 +138,6 @@ void paging_dump(int min, int max) {
}
}
-u64* paging_allocate_table(){
- u64* table=paging_allocate_contiguous(8);
- memset(table, 0, 32768); // nb_entries * entry size = 512 * 64
- return table;
-}
-
void paging_deallocate_table(u64* table){
char *c_table=(char*)PAGE((u64)table);
for(u8 i=0;i<8;i++){
@@ -130,7 +146,7 @@ void paging_deallocate_table(u64* table){
}
}
-void paging_allocate_addr(u64* pml4_table, u64 virt, u64 phy, u16 options){
+void paging_allocate_addr(u64* pml4_table, u64 virt, u64 phy, u16 options, u64 offset){
u16 pml4=virt>>39&0x1FF;
u16 pdp=virt>>30&0x1FF;
u16 pd=virt>>21&0x1FF;
@@ -141,27 +157,29 @@ void paging_allocate_addr(u64* pml4_table, u64 virt, u64 phy, u16 options){
if(pml4_table[pml4] == 0){
pml4_table[pml4]=(u64)paging_allocate_table();
pml4_table[pml4]|=options;
- paging_allocate_addr(pml4_table,virt,phy,options);
+ paging_allocate_addr(pml4_table,virt,phy,options,offset);
return;
}
+
// Solve pd
- u64* pdp_table=(u64*)PAGE(pml4_table[pml4]);
+ u64* pdp_table=(u64*)(PAGE(pml4_table[pml4])+offset);
if(pdp_table[pdp] == 0){
pdp_table[pdp]=(u64)paging_allocate_table();
pdp_table[pdp]|=options;
- paging_allocate_addr(pml4_table,virt,phy,options);
+ paging_allocate_addr(pml4_table,virt,phy,options,offset);
return;
}
+
// Solve pt
- u64* pd_table=(u64*)PAGE(pdp_table[pdp]);
+ u64* pd_table=(u64*)(PAGE(pdp_table[pdp])+offset);
if(pd_table[pd] == 0){
pd_table[pd]=(u64)paging_allocate_table();
pd_table[pd]|=options;
- paging_allocate_addr(pml4_table,virt,phy,options);
+ paging_allocate_addr(pml4_table,virt,phy,options,offset);
return;
}
// Solve address
- u64* pt_table=(u64*)PAGE(pd_table[pd]);
+ u64* pt_table=(u64*)(PAGE(pd_table[pd])+offset);
if(pt_table[pt] == 0){
pt_table[pt]=PAGE(phy);
pt_table[pt]|=options;
diff --git a/src/core/paging.hpp b/src/core/paging.hpp
index 4bb668c..089bd47 100644
--- a/src/core/paging.hpp
+++ b/src/core/paging.hpp
@@ -18,9 +18,14 @@
/// @brief Get page address that contain addr
#define PAGE(addr) (addr&(~(0xFFF)))
-#define PAGING_MAP(addr) paging_allocate_addr(kpml4,(u64)(addr),(u64)(addr),PAGING_OPT_P|PAGING_OPT_RW)
+#define PAGING_MAP(addr) paging_allocate_addr(kpages[0],(u64)(addr),(u64)(addr),PAGING_OPT_P|PAGING_OPT_RW,kernel_vma)
+#define MAX_TABLES 280
-extern u64* kpml4;
+/// @brief All PAE table structures are allocated here
+extern u64 kpages[MAX_TABLES][512];
+
+/// @brief Various variables from the linker
+extern u64 kernel_vma,stack_pma,userspace_pma;
/**
* Setup and enable PAE paging
@@ -56,13 +61,16 @@ void paging_deallocate_table(u64* table);
/**
* Allocate table structure (pml4, pdp etc..)
*/
-u64* paging_allocate_table();
+u64* paging_allocate_table_local();
/**
* Map virtual page associated to virt
* to the physical page associated with phy
+ * Offset can be used to convert pml4_table address
+ * content to virtual addresses (since physical addresses from the pml4_table are not
+ * available after the trampoline into High-Half memory)
*/
-void paging_allocate_addr(u64* pml4_table,u64 virt, u64 phy, u16 options);
+void paging_allocate_addr(u64* pml4_table,u64 virt, u64 phy, u16 options, u64 offset);
/**
* Get associated physical address
diff --git a/src/drivers/vga_t.cc b/src/drivers/vga_t.cc
index 6e50b40..0ff3f82 100644
--- a/src/drivers/vga_t.cc
+++ b/src/drivers/vga_t.cc
@@ -1,5 +1,7 @@
#include "vga_t.hpp"
+#include "include/boucane.hpp"
+
#define MAX_COL 80
#define MAX_LINE 25
@@ -11,6 +13,11 @@ VIDEO_STATE VS={
GRAY,
};
+void vga_t_init(){
+ PAGING_MAP(0xB8000);
+ PAGING_MAP(0xB8000+4096);
+}
+
void vga_t_putchar(char c){
// Handle newline here
if(c=='\n'){
@@ -39,7 +46,7 @@ void vga_t_putchar(char c){
}
}
-void clear(){
+void vga_t_clear(){
for(u8 i=0;i<MAX_LINE;i++){
vga_t_scrollup();
}
diff --git a/src/drivers/vga_t.hpp b/src/drivers/vga_t.hpp
index dd947bd..bf553bf 100644
--- a/src/drivers/vga_t.hpp
+++ b/src/drivers/vga_t.hpp
@@ -16,6 +16,8 @@ typedef struct VIDEO_STATE {
u8 fg;
} VIDEO_STATE;
+void vga_t_init();
+
/**
* Print char
*/
diff --git a/src/include/boucane.hpp b/src/include/boucane.hpp
index 8df2e59..f178f42 100644
--- a/src/include/boucane.hpp
+++ b/src/include/boucane.hpp
@@ -10,4 +10,4 @@
#include "libs/stdio.hpp"
#include "libs/string.hpp"
-extern u64* kpml4; \ No newline at end of file
+#define LOAD_GDT() asm("call load_gdt") \ No newline at end of file
diff --git a/src/linker.ld b/src/linker.ld
index 89e4909..7d7c3a6 100644
--- a/src/linker.ld
+++ b/src/linker.ld
@@ -1,30 +1,45 @@
-ENTRY(_start)
OUTPUT_FORMAT(elf64-x86-64)
+ENTRY(_start)
-SECTIONS {
+__kernel_vma = 0xFFFFFFFF80000000;
+__boot_pma = 1M;
+__stack_pma = 0x3FFFFF;
+__stack_size = 4096;
+__userspace_pma = 0x400000;
- . = 1M;
+PHDRS
+{
+ boot PT_LOAD;
+ kernel PT_LOAD;
+}
- .text : ALIGN(4)
+SECTIONS {
+ . = __boot_pma;
+ .boot ALIGN(4096) :
{
*boot.o(.multiboot)
*boot.o(.text)
- *(.text)
- }
- .rodata : ALIGN(4)
- {
- *(.rodata)
- }
- .data : ALIGN(4)
+ *trampoline.o(.text .text.* .data .data.* .rodata .rodata.* .bss)
+
+ } :boot
+
+ . += __kernel_vma;
+ .text ALIGN(4096) : AT(ADDR(.text)-__kernel_vma)
{
- *(.data)
- }
- .bss : ALIGN(4)
+ *boot.o(.multiboot)
+ *boot.o(.text)
+ *(.text .text.*)
+ *(.rodata .rodata.*)
+ *(.data .data.*)
+ }:kernel
+ .bss ALIGN(4096) : AT(ADDR(.bss)-__kernel_vma)
{
- _bss_start = .;
+ __bss_start = .;
*(.bss);
- _bss_end = .;
+ __bss_end = .;
*(COMMON);
- }
+ ASSERT( (. - ABSOLUTE(__kernel_vma)) < (ABSOLUTE(__stack_pma)-ABSOLUTE(__stack_size)), "No room for stack !!");
+ }:kernel
+ /DISCARD/ : { *(.eh_frame) *(.comment) *(.note*) }
} \ No newline at end of file