diff options
| author | Nic Gaffney <gaffney_nic@protonmail.com> | 2023-12-10 09:48:53 -0600 |
|---|---|---|
| committer | Nic Gaffney <gaffney_nic@protonmail.com> | 2023-12-10 09:48:53 -0600 |
| commit | 8fcd0cf7d6a2c891422c7101840778043207a60d (patch) | |
| tree | 5527b605fdaee1ad4404bef6418f1a5e34e31d52 /src/kernel/gdt.c | |
| parent | 87d1e83a0ea5e20e535e3378e57f1fe0e9818a64 (diff) | |
| download | gftos-8fcd0cf7d6a2c891422c7101840778043207a60d.tar.gz | |
Changed to the based ASM syntax and implemented a rudementary GDT
Diffstat (limited to 'src/kernel/gdt.c')
| -rw-r--r-- | src/kernel/gdt.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/kernel/gdt.c b/src/kernel/gdt.c new file mode 100644 index 0000000..cf0f487 --- /dev/null +++ b/src/kernel/gdt.c @@ -0,0 +1,51 @@ +#include "gdt.h" +#include <stdint.h> + +uint8_t make_access(uint8_t DPL, uint8_t type, uint8_t exec, uint8_t direction, + uint8_t read_write) { + uint8_t access = 0; + access |= (1 << 7); + access |= (DPL << 5); + access |= (type << 4); + access |= (exec << 3); + access |= (direction << 2); + access |= (read_write << 1); // 10 + return access; +} + +uint16_t make_code(uint8_t priv, uint8_t dc, uint8_t rw) { + uint16_t access = 0; + access |= (1 << 7); + access |= (priv << 5); + access |= (0b11 << 3); + access |= (dc << 2); + access |= (rw << 1); // 10 + access <<= 8; + access |= FLAG; + return access; +} + +uint16_t make_data(uint8_t priv, uint8_t dc, uint8_t rw) { + uint16_t access = 0; + access |= (1 << 7); + access |= (priv << 5); + access |= (0b10 << 3); + access |= (dc << 2); + access |= (rw << 1); // 10 + access <<= 8; + access |= FLAG; + return access; +} + +Segment_Descriptor_t make_descriptor(uint32_t base, uint32_t limit, + uint16_t access_flag) { + uint16_t lim_low = limit; + uint16_t base_low = base; + uint8_t base_mid = (base >> 16); + uint8_t access_byte = access_flag >> 8; + uint8_t lim_flag = ((access_flag << 4) | (limit >> 16)); + uint8_t base_high = (base >> 24); + return (Segment_Descriptor_t){ + lim_low, base_low, base_mid, access_byte, lim_flag, base_high, + }; +} |
