mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-11 13:35:03 -04:00
Transmit tss as early memory
This commit is contained in:
parent
558e144efc
commit
ad1167f32b
@ -65,4 +65,6 @@ inline void vesa_enabled(bool value){
|
|||||||
*reinterpret_cast<uint32_t*>(vesa_enabled_address) = value ? 1 : 0;
|
*reinterpret_cast<uint32_t*>(vesa_enabled_address) = value ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr const uint32_t tss_address = 0x904A0; // 104 bytes (aligned to 128)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -105,10 +105,10 @@ struct task_state_segment_t {
|
|||||||
uint16_t io_map_base_address;
|
uint16_t io_map_base_address;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern task_state_segment_t tss;
|
|
||||||
|
|
||||||
void flush_tss();
|
void flush_tss();
|
||||||
|
|
||||||
|
task_state_segment_t& tss();
|
||||||
|
|
||||||
} //end of namespace gdt
|
} //end of namespace gdt
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -10,16 +10,15 @@
|
|||||||
#include "boot/code16gcc.h"
|
#include "boot/code16gcc.h"
|
||||||
#include "boot/boot_32.hpp"
|
#include "boot/boot_32.hpp"
|
||||||
|
|
||||||
#include "gdt.hpp"
|
#include "gdt.hpp" // For the types
|
||||||
#include "e820.hpp" // For the types
|
#include "e820.hpp" // For the types
|
||||||
#include "vesa.hpp" // For the types
|
#include "vesa.hpp" // For the types
|
||||||
#include "early_memory.hpp"
|
#include "early_memory.hpp"
|
||||||
|
|
||||||
//The Task State Segment
|
|
||||||
gdt::task_state_segment_t gdt::tss;
|
|
||||||
|
|
||||||
e820::bios_e820_entry bios_e820_entries[e820::MAX_E820_ENTRIES];
|
e820::bios_e820_entry bios_e820_entries[e820::MAX_E820_ENTRIES];
|
||||||
|
|
||||||
|
gdt::task_state_segment_t tss; // TODO Remove this (causes relocation errors for now)
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
vesa::vbe_info_block_t vbe_info_block;
|
vesa::vbe_info_block_t vbe_info_block;
|
||||||
@ -411,7 +410,7 @@ void setup_gdt(){
|
|||||||
|
|
||||||
//2. Init TSS Descriptor
|
//2. Init TSS Descriptor
|
||||||
|
|
||||||
uint32_t base = reinterpret_cast<uint32_t>(&gdt::tss);
|
uint32_t base = tss_address;;
|
||||||
uint32_t limit = base + sizeof(gdt::task_state_segment_t);
|
uint32_t limit = base + sizeof(gdt::task_state_segment_t);
|
||||||
|
|
||||||
auto tss_selector = reinterpret_cast<gdt::tss_descriptor_t*>(&gdt[6]);
|
auto tss_selector = reinterpret_cast<gdt::tss_descriptor_t*>(&gdt[6]);
|
||||||
@ -441,9 +440,8 @@ void setup_gdt(){
|
|||||||
asm volatile("lgdt [%0]" : : "m" (gdtr));
|
asm volatile("lgdt [%0]" : : "m" (gdtr));
|
||||||
|
|
||||||
//5. Zero-out the TSS
|
//5. Zero-out the TSS
|
||||||
auto tss_ptr = reinterpret_cast<char*>(&gdt::tss);
|
for(uint16_t i = 0; i < 128; i += 4){
|
||||||
for(unsigned int i = 0; i < sizeof(gdt::task_state_segment_t); ++i){
|
early_write_32(tss_address + i * 4, 0);
|
||||||
*tss_ptr++ = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,12 @@
|
|||||||
//=======================================================================
|
//=======================================================================
|
||||||
|
|
||||||
#include "gdt.hpp"
|
#include "gdt.hpp"
|
||||||
|
#include "early_memory.hpp"
|
||||||
|
|
||||||
void gdt::flush_tss(){
|
void gdt::flush_tss(){
|
||||||
asm volatile("mov ax, %0; ltr ax;" : : "i" (gdt::TSS_SELECTOR + 0x3) : "rax");
|
asm volatile("mov ax, %0; ltr ax;" : : "i" (gdt::TSS_SELECTOR + 0x3) : "rax");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gdt::task_state_segment_t& gdt::tss(){
|
||||||
|
return *reinterpret_cast<task_state_segment_t*>(tss_address);
|
||||||
|
}
|
||||||
|
@ -289,8 +289,8 @@ void switch_to_process(size_t pid){
|
|||||||
|
|
||||||
process.state = scheduler::process_state::RUNNING;
|
process.state = scheduler::process_state::RUNNING;
|
||||||
|
|
||||||
gdt::tss.rsp0_low = process.process.kernel_rsp & 0xFFFFFFFF;
|
gdt::tss().rsp0_low = process.process.kernel_rsp & 0xFFFFFFFF;
|
||||||
gdt::tss.rsp0_high = process.process.kernel_rsp >> 32;
|
gdt::tss().rsp0_high = process.process.kernel_rsp >> 32;
|
||||||
|
|
||||||
task_switch(old_pid, current_pid);
|
task_switch(old_pid, current_pid);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user