diff options
| author | Loic Guegan <manzerbredes@mailbox.org> | 2021-04-09 18:18:15 +0200 |
|---|---|---|
| committer | Loic Guegan <manzerbredes@mailbox.org> | 2021-04-09 18:18:15 +0200 |
| commit | c6aa00eea71c91a219dae8688530ff0a3b83bcd4 (patch) | |
| tree | e2f4d26362e8a57b5fba1a3392b947b95cb40039 | |
| parent | deabd68158b865f2bcf928c604d6c46f73832d0a (diff) | |
Enable TSS segment
| -rw-r--r-- | src/boot/boot.S | 4 | ||||
| -rw-r--r-- | src/boot/multiboot.c | 4 | ||||
| -rw-r--r-- | src/bringelle.c | 21 | ||||
| -rw-r--r-- | src/utils/gdt.c | 56 | ||||
| -rw-r--r-- | src/utils/gdt.h | 31 | ||||
| -rw-r--r-- | tools/ram.svg | 164 |
6 files changed, 263 insertions, 17 deletions
diff --git a/src/boot/boot.S b/src/boot/boot.S index 77b04c0..ba25a84 100644 --- a/src/boot/boot.S +++ b/src/boot/boot.S @@ -67,6 +67,10 @@ movw $0x18, %ax movw %ax, %ss movl $0x50000,%esp +# Load +mov $0x38, %eax +ltr %ax + # Start kernel main function call bringelle diff --git a/src/boot/multiboot.c b/src/boot/multiboot.c index 0309eb0..c41aeb7 100644 --- a/src/boot/multiboot.c +++ b/src/boot/multiboot.c @@ -20,11 +20,11 @@ char mb_load_tag(char **data, char type){ c_tag_type=c_tag_type+tag_size+4; // Skip padding for 64 bits - int p=c_tag_type; + int p=(int)c_tag_type; while((p & 0x7) != 0) p++; // Assign address after padding - c_tag_type=p; + c_tag_type=(char *)p; c_tag_size=c_tag_type+4; } diff --git a/src/bringelle.c b/src/bringelle.c index 5431ad4..5fd315b 100644 --- a/src/bringelle.c +++ b/src/bringelle.c @@ -1,15 +1,28 @@ #include "libc/stdio.h" #include "utils/pic.h" #include "boot/multiboot.h" +#include "utils/mem.h" + +char show_tics=0; + +void utask(){ + while(1); +} void bringelle(){ clear(); - printc("Booting Bringelle...",GREEN); + printc("Booting Bringelle...\n",GREEN); // Kernel boot sequence pic_enable_interrupt(); + print("Interrupts enabled!\n"); - printc(" done!\n",GREEN); + + // Utask + memcpy((void*)utask,(void*)0x300000, 100); // 100 bytes seems reasonable to load utask + + print("Kernel started "); + show_tics=1; while(1); } @@ -20,5 +33,9 @@ void clock(){ if(tic>=20){ tic=0; sec++; + if(show_tics) + putchar('.'); } } + + diff --git a/src/utils/gdt.c b/src/utils/gdt.c index e82ebe4..fd86f5f 100644 --- a/src/utils/gdt.c +++ b/src/utils/gdt.c @@ -2,11 +2,14 @@ #include "mem.h" struct GDT_REGISTER GDTR = { 0, 0 }; +GDT_TSS TSS; void gdt_memcpy(){ - GDTR.limit=8*4; // Each entry is 8 bytes and 4 entries + GDTR.limit=8*8; // Each entry is 8 bytes and 8 entries GDTR.base=0x800; - + gdt_write_entry((GDT_ENTRY){0,0,0,0},0); // First one must be null + + // ----- Kernel Segments GDT_ENTRY cs_desc; cs_desc.base=0; cs_desc.limit=0xFFFFF; @@ -26,13 +29,50 @@ void gdt_memcpy(){ ss_desc.access=GDT_PR|GDT_PRVL_0|GDT_S|GDT_RW|GDT_DC; // Write GDT descriptors into memory - gdt_write_entry((GDT_ENTRY){0,0,0,0},GDTR.base); // First one must be null - gdt_write_entry(cs_desc, GDTR.base+8); // Each entry is 64 bits (8 bytes) - gdt_write_entry(ds_desc, GDTR.base+8*2); - gdt_write_entry(ss_desc, GDTR.base+8*3); + gdt_write_entry(cs_desc, 1); + gdt_write_entry(ds_desc, 2); + gdt_write_entry(ss_desc, 3); + + // ----- User Segments + GDT_ENTRY ucs_desc; + ucs_desc.base=0x300000; + ucs_desc.limit=0xFFFFF; + ucs_desc.flags=GDT_SZ|GDT_GR; + ucs_desc.access=GDT_PR|GDT_PRVL_3|GDT_S|GDT_EXEC|GDT_RW|GDT_DC; + + GDT_ENTRY uds_desc; + uds_desc.base=0x300000; + uds_desc.limit=0xFFFFF; + uds_desc.flags=GDT_SZ|GDT_GR; + uds_desc.access=GDT_PR|GDT_PRVL_3|GDT_S|GDT_RW; + + GDT_ENTRY uss_desc; + uss_desc.base=0; // Not used in stack descriptor + uss_desc.limit=0x64; // Define how much entry it can contains + uss_desc.flags=GDT_SZ|GDT_GR; + uss_desc.access=GDT_PR|GDT_PRVL_3|GDT_S|GDT_RW|GDT_DC; + + // Write GDT descriptors into memory + gdt_write_entry(ucs_desc, 4); // Each entry is 64 bits (8 bytes) + gdt_write_entry(uds_desc, 5); + gdt_write_entry(uss_desc, 6); + + // Init TSS segment + TSS.t_reserved=0; + TSS.io_map=0; + TSS.ss0=0x18; + TSS.esp0=0x50000; + + GDT_ENTRY tss_desc; + tss_desc.base=(u32)&TSS; // Not used in stack descriptor + tss_desc.limit=0x68; // Define how much entry it can contains + tss_desc.flags=0; + tss_desc.access=0x89 | GDT_PRVL_3; // Note that 0x89 is specific to TSS! + gdt_write_entry(tss_desc, 7); + } -void gdt_write_entry(GDT_ENTRY entry, u32 addr){ +void gdt_write_entry(GDT_ENTRY entry, u32 id){ int descriptor[2]; // First row of the descriptor @@ -47,5 +87,5 @@ void gdt_write_entry(GDT_ENTRY entry, u32 addr){ descriptor[1]=base|access<<8|limit<<16|flags<<20|base2<<24; // Copy descriptor into memory - memcpy(descriptor,(void*)addr,8); + memcpy(descriptor,(void*)GDTR.base+8*id,8); // Each entry is 64 bits (8 bytes) } diff --git a/src/utils/gdt.h b/src/utils/gdt.h index 85a75aa..01a01bf 100644 --- a/src/utils/gdt.h +++ b/src/utils/gdt.h @@ -31,6 +31,35 @@ struct GDT_REGISTER { u32 base; } __attribute__((packed)); +typedef struct GDT_TSS { + u16 previous_task,previous_task_unused; + u32 esp0; + u16 ss0, ss0_unused; + u32 esp1; + u16 ss1, ss1_unused; + u32 esp2; + u16 ss2, ss2_unused; + u32 cr3; + u32 eip; + u32 eflags; + u32 eax; + u32 ecx; + u32 edx; + u32 ebx; + u32 esp; + u32 ebp; + u32 esi; + u32 edi; + u16 es, es_reserved; + u16 cs, cs_reserved; + u16 ss, ss_reserved; + u16 ds, ds_reserved; + u16 fs, fs_reserved; + u16 gs, gs_reserved; + u16 ldtss, ldtss_reserved; + u16 t_reserved, io_map; +} __attribute__((packed)) GDT_TSS; + /** * Copy GDT in memory */ @@ -39,6 +68,6 @@ void gdt_memcpy(); /** * Write a GDT entry at address addr */ -void gdt_write_entry(GDT_ENTRY entry, u32 addr); +void gdt_write_entry(GDT_ENTRY entry, u32 id); #endif diff --git a/tools/ram.svg b/tools/ram.svg index 7d09ae4..a66a4b5 100644 --- a/tools/ram.svg +++ b/tools/ram.svg @@ -23,9 +23,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="1.6327754" - inkscape:cx="257.73147" - inkscape:cy="345.55194" + inkscape:zoom="2.3090931" + inkscape:cx="401.30631" + inkscape:cy="290.44939" inkscape:document-units="mm" inkscape:current-layer="layer1" inkscape:document-rotation="0" @@ -43,7 +43,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -58,5 +58,161 @@ height="112.65762" x="43.210255" y="34.834328" /> + <text + xml:space="preserve" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:8.46667px;line-height:1.25;font-family:Ubuntu;-inkscape-font-specification:'Ubuntu Bold';fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583" + x="115.61518" + y="150.39668" + id="text855"><tspan + sodipodi:role="line" + id="tspan853" + x="115.61518" + y="150.39668" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:8.46667px;font-family:Ubuntu;-inkscape-font-specification:'Ubuntu Bold';stroke-width:0.264583">0x0</tspan></text> + <text + xml:space="preserve" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:8.46666667px;line-height:1.25;font-family:Ubuntu;-inkscape-font-specification:'Ubuntu Bold';fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583;" + x="115.61518" + y="140.70641" + id="text843"><tspan + sodipodi:role="line" + id="tspan841" + x="115.61518" + y="140.70641" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-family:Ubuntu;-inkscape-font-specification:'Ubuntu Bold';stroke-width:0.264583;font-size:8.46666667px;">0x640</tspan></text> + <text + xml:space="preserve" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:8.46666667px;line-height:1.25;font-family:Ubuntu;-inkscape-font-specification:'Ubuntu Bold';fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583;" + x="115.61518" + y="130.68584" + id="text847"><tspan + sodipodi:role="line" + id="tspan845" + x="115.61518" + y="130.68584" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-family:Ubuntu;-inkscape-font-specification:'Ubuntu Bold';stroke-width:0.264583;font-size:8.46666667px;">0x800</tspan></text> + <text + xml:space="preserve" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:8.46666667px;line-height:1.25;font-family:Ubuntu;-inkscape-font-specification:'Ubuntu Bold';fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583;" + x="115.61518" + y="120.51859" + id="text851"><tspan + sodipodi:role="line" + id="tspan849" + x="115.61518" + y="120.51859" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-family:Ubuntu;-inkscape-font-specification:'Ubuntu Bold';stroke-width:0.264583;font-size:8.46666667px;">0x850</tspan></text> + <rect + style="fill:none;stroke:#333333;stroke-width:2" + id="rect853" + width="67.534943" + height="11.90126" + x="43.210255" + y="135.59068" /> + <text + xml:space="preserve" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:10.5833px;line-height:1.25;font-family:Ubuntu;-inkscape-font-specification:'Ubuntu Bold';fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583" + x="67.960762" + y="145.20314" + id="text859"><tspan + sodipodi:role="line" + id="tspan857" + x="67.960762" + y="145.20314" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-family:Ubuntu;-inkscape-font-specification:'Ubuntu Bold';stroke-width:0.264583">IDT</tspan></text> + <rect + style="fill:none;stroke:#333333;stroke-width:2" + id="rect861" + width="67.534943" + height="11.90126" + x="43.210255" + y="117.08315" /> + <text + xml:space="preserve" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:10.5833px;line-height:1.25;font-family:Ubuntu;-inkscape-font-specification:'Ubuntu Bold';fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583" + x="66.076935" + y="126.71677" + id="text865"><tspan + sodipodi:role="line" + id="tspan863" + x="66.076935" + y="126.71677" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-family:Ubuntu;-inkscape-font-specification:'Ubuntu Bold';stroke-width:0.264583">GDT</tspan></text> + <rect + style="fill:none;stroke:#333333;stroke-width:2" + id="rect867" + width="67.534943" + height="11.90126" + x="43.210255" + y="80.192589" /> + <text + xml:space="preserve" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:10.5833px;line-height:1.25;font-family:Ubuntu;-inkscape-font-specification:'Ubuntu Bold';fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583" + x="60.023312" + y="90.175453" + id="text871"><tspan + sodipodi:role="line" + id="tspan869" + x="60.023312" + y="90.175453" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-family:Ubuntu;-inkscape-font-specification:'Ubuntu Bold';stroke-width:0.264583">Kernel</tspan></text> + <text + xml:space="preserve" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:8.46667px;line-height:1.25;font-family:Ubuntu;-inkscape-font-specification:'Ubuntu Bold';fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583" + x="115.61518" + y="94.123299" + id="text875"><tspan + sodipodi:role="line" + id="tspan873" + x="115.61518" + y="94.123299" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:8.46667px;font-family:Ubuntu;-inkscape-font-specification:'Ubuntu Bold';stroke-width:0.264583">0x100000</tspan></text> + <rect + style="fill:none;stroke:#333333;stroke-width:2" + id="rect877" + width="67.534943" + height="11.90126" + x="43.210255" + y="100.01691" /> + <text + xml:space="preserve" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:8.46667px;line-height:1.25;font-family:Ubuntu;-inkscape-font-specification:'Ubuntu Bold';fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583" + x="115.61518" + y="103.22851" + id="text881"><tspan + sodipodi:role="line" + id="tspan879" + x="115.61518" + y="103.22851" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:8.46667px;font-family:Ubuntu;-inkscape-font-specification:'Ubuntu Bold';stroke-width:0.264583">0x50000</tspan></text> + <text + xml:space="preserve" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:10.5833px;line-height:1.25;font-family:Ubuntu;-inkscape-font-specification:'Ubuntu Bold';fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583" + x="62.875507" + y="109.58773" + id="text885"><tspan + sodipodi:role="line" + id="tspan883" + x="62.875507" + y="109.58773" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-family:Ubuntu;-inkscape-font-specification:'Ubuntu Bold';stroke-width:0.264583">Stack</tspan></text> + <rect + style="fill:none;stroke:#333333;stroke-width:2" + id="rect887" + width="67.142853" + height="40.376717" + x="43.210255" + y="34.834328" /> + <text + xml:space="preserve" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:8.46667px;line-height:1.25;font-family:Ubuntu;-inkscape-font-specification:'Ubuntu Bold';fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583" + x="115.61518" + y="78.103249" + id="text891"><tspan + sodipodi:role="line" + id="tspan889" + x="115.61518" + y="78.103249" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:8.46667px;font-family:Ubuntu;-inkscape-font-specification:'Ubuntu Bold';stroke-width:0.264583">0x200000</tspan></text> </g> </svg> |
