-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
284 changed files
with
10,236 additions
and
18,900 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,62 @@ | ||
// ====================================================================== | ||
// bios32.c - Handles real-mode interrupt calls in protected mode | ||
// ====================================================================== | ||
|
||
#include "include/bios32.h" // Main header file | ||
|
||
idtPtr_t realModeGDT; | ||
idtPtr_t realModeIDT; | ||
|
||
extern gdtEntry_t gdtEntries[8]; | ||
|
||
void (*bios32_execute)() = (void *)0x7c00; | ||
|
||
void bios32_init() { | ||
// Set up the 16-bit code and data segment in GDT. | ||
gdtSetGate(6, 0, 0xFFFFFFFF, 0x9A, 0x0F); | ||
gdtSetGate(7, 0, 0xFFFFFFFF, 0x92, 0x0F); | ||
|
||
// Setup the real mode GDT ptr | ||
realModeGDT.base_addr = (uint32_t)gdtEntries; | ||
realModeGDT.limit = sizeof(gdtEntries) - 1; | ||
|
||
// Setup the real mode IDT ptr | ||
realModeIDT.base_addr = 0; | ||
realModeIDT.limit = 0x3FF; | ||
} | ||
|
||
// bios32_call(uint8_t interrupt, REGISTERS_16 *in, REGISTERS_16 *out) - Calls bios32. | ||
void bios32_call(uint8_t interrupt, REGISTERS_16 *in, REGISTERS_16 *out) { | ||
serialPrintf("Preparing to call BIOS32 for int 0x%x...\n\tAX = 0x%x BX = 0x%x CX = 0x%x DX = 0x%x\n", interrupt, in->ax, in->bx, in->cx, in->dx); | ||
void *newCodeBase = (void *)0x7c00; | ||
|
||
// Copy the GDT entries to the BIOS32 GDT entries. | ||
memcpy(&bios32_gdt_entries, gdtEntries, sizeof(gdtEntries)); | ||
|
||
// Update the base address of the GDT entries, starting from 0x7C00. | ||
realModeGDT.base_addr = (uint32_t)REBASE_ADDRESS((&bios32_gdt_entries)); | ||
|
||
// Copy the real mode GDT and IDT to their respective pointers. | ||
memcpy(&bios32_gdt_ptr, &realModeGDT, sizeof(idtPtr_t)); | ||
memcpy(&bios32_idt_ptr, &realModeIDT, sizeof(idtPtr_t)); | ||
|
||
// Copy the in registers to their pointers. | ||
memcpy(&bios32_in_reg16_ptr, in, sizeof(REGISTERS_16)); | ||
|
||
// Get the in registers' address. | ||
void *in_reg16_address = REBASE_ADDRESS(&bios32_in_reg16_ptr); | ||
|
||
// Copy the BIOS interrupt number to its respective pointer. | ||
memcpy(&bios32_int_number_ptr, &interrupt, sizeof(uint8_t)); | ||
|
||
// Copy the bios32 code to a new address. | ||
uint32_t size = (uint32_t)BIOS32_END - (uint32_t)BIOS32_START; | ||
memcpy(newCodeBase, BIOS32_START, size); | ||
|
||
// Start executing the BIOS32 code. | ||
bios32_execute(); | ||
|
||
// Copy the output registers to the out ptr. | ||
in_reg16_address = REBASE_ADDRESS(&bios32_out_reg16_ptr); | ||
memcpy(out, in_reg16_address, sizeof(REGISTERS_16)); | ||
} | ||
// ====================================================================== | ||
// bios32.c - Handles real-mode interrupt calls in protected mode | ||
// ====================================================================== | ||
|
||
#include <kernel/bios32.h> // Main header file | ||
|
||
idtPtr_t realModeGDT; | ||
idtPtr_t realModeIDT; | ||
|
||
extern gdtEntry_t gdtEntries[8]; | ||
|
||
void (*bios32_execute)() = (void *)0x7c00; | ||
|
||
void bios32_init() { | ||
// Set up the 16-bit code and data segment in GDT. | ||
gdtSetGate(6, 0, 0xFFFFFFFF, 0x9A, 0x0F); | ||
gdtSetGate(7, 0, 0xFFFFFFFF, 0x92, 0x0F); | ||
|
||
// Setup the real mode GDT ptr | ||
realModeGDT.base_addr = (uint32_t)gdtEntries; | ||
realModeGDT.limit = sizeof(gdtEntries) - 1; | ||
|
||
// Setup the real mode IDT ptr | ||
realModeIDT.base_addr = 0; | ||
realModeIDT.limit = 0x3FF; | ||
} | ||
|
||
// bios32_call(uint8_t interrupt, REGISTERS_16 *in, REGISTERS_16 *out) - Calls bios32. | ||
void bios32_call(uint8_t interrupt, REGISTERS_16 *in, REGISTERS_16 *out) { | ||
serialPrintf("Preparing to call BIOS32 for int 0x%x...\n\tAX = 0x%x BX = 0x%x CX = 0x%x DX = 0x%x\n", interrupt, in->ax, in->bx, in->cx, in->dx); | ||
void *newCodeBase = (void *)0x7c00; | ||
|
||
// Copy the GDT entries to the BIOS32 GDT entries. | ||
memcpy(&bios32_gdt_entries, gdtEntries, sizeof(gdtEntries)); | ||
|
||
// Update the base address of the GDT entries, starting from 0x7C00. | ||
realModeGDT.base_addr = (uint32_t)REBASE_ADDRESS((&bios32_gdt_entries)); | ||
|
||
// Copy the real mode GDT and IDT to their respective pointers. | ||
memcpy(&bios32_gdt_ptr, &realModeGDT, sizeof(idtPtr_t)); | ||
memcpy(&bios32_idt_ptr, &realModeIDT, sizeof(idtPtr_t)); | ||
|
||
// Copy the in registers to their pointers. | ||
memcpy(&bios32_in_reg16_ptr, in, sizeof(REGISTERS_16)); | ||
|
||
// Get the in registers' address. | ||
void *in_reg16_address = REBASE_ADDRESS(&bios32_in_reg16_ptr); | ||
|
||
// Copy the BIOS interrupt number to its respective pointer. | ||
memcpy(&bios32_int_number_ptr, &interrupt, sizeof(uint8_t)); | ||
|
||
// Copy the bios32 code to a new address. | ||
uint32_t size = (uint32_t)BIOS32_END - (uint32_t)BIOS32_START; | ||
memcpy(newCodeBase, BIOS32_START, size); | ||
|
||
// Start executing the BIOS32 code. | ||
bios32_execute(); | ||
|
||
// Copy the output registers to the out ptr. | ||
in_reg16_address = REBASE_ADDRESS(&bios32_out_reg16_ptr); | ||
memcpy(out, in_reg16_address, sizeof(REGISTERS_16)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,56 @@ | ||
// ================================================== | ||
// gdt.c - Global Descriptor Table initializer | ||
// ================================================== | ||
// This file is a part of the reduceOS C kernel. Please credit me if you use this code. | ||
|
||
/* Developer note: When reduceOS switched to multiboot, I totally forgot about this file. I'm not sure if this is why paging is failing, but it would be pretty funny if so. */ | ||
|
||
#include "include/gdt.h" // Main header file | ||
|
||
// Variable definitions | ||
gdtEntry_t gdtEntries[MAX_DESCRIPTORS]; | ||
gdtPtr_t gdtPtr; | ||
|
||
extern void tssFlush(); | ||
|
||
// Functions | ||
|
||
// gdtSetGate(int32_t num, uint32_t base, uint32_t limit, uint8_t access, uint8_t gran) - Set the value of 1 GDT entry. | ||
void gdtSetGate(int32_t num, uint32_t base, uint32_t limit, uint8_t access, uint8_t gran) { | ||
// Sanity check first! | ||
ASSERT(num < MAX_DESCRIPTORS, "gdtSetGate()", "invalid descriptor number"); | ||
|
||
// Now set the proper values in the gdt entries. | ||
gdtEntries[num].baseLow = (base & 0xFFFF); | ||
gdtEntries[num].baseMiddle = (base >> 16) & 0xFF; | ||
gdtEntries[num].baseHigh = (base >> 24) & 0xFF; | ||
|
||
gdtEntries[num].limitLow = (limit & 0xFFFF); | ||
gdtEntries[num].granularity = (limit >> 16) & 0x0F; | ||
|
||
gdtEntries[num].granularity |= gran & 0xF0; | ||
gdtEntries[num].access = access; | ||
} | ||
|
||
|
||
// gdtInit() - Initializes GDT and sets up all the pointers | ||
void gdtInit() { | ||
// Setup the gdtPtr to point to our gdtEntires | ||
gdtPtr.limit = sizeof(gdtEntries)-1; | ||
gdtPtr.base = (uint32_t)&gdtEntries; | ||
|
||
// Now setup the GDT entries | ||
gdtSetGate(0, 0, 0, 0, 0); // Null segment | ||
gdtSetGate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF); // Code segment | ||
gdtSetGate(2, 0, 0xFFFFFFFF, 0x92, 0xCF); // Data segment | ||
gdtSetGate(3, 0, 0xFFFFFFFF, 0xFA, 0xCF); // User mode code segment | ||
gdtSetGate(4, 0, 0xFFFFFFFF, 0xF2, 0xCF); // User mode data segment. | ||
tssWrite(5, 0x10, 0x0); // Task state segment | ||
|
||
// Install the GDT. | ||
install_gdt((uint32_t)&gdtPtr); | ||
|
||
// Flush TSS. | ||
tssFlush(); | ||
|
||
} | ||
// ================================================== | ||
// gdt.c - Global Descriptor Table initializer | ||
// ================================================== | ||
// This file is a part of the reduceOS C kernel. Please credit me if you use this code. | ||
|
||
/* Developer note: When reduceOS switched to multiboot, I totally forgot about this file. I'm not sure if this is why paging is failing, but it would be pretty funny if so. */ | ||
|
||
#include <kernel/gdt.h> // Main header file | ||
|
||
// Variable definitions | ||
gdtEntry_t gdtEntries[MAX_DESCRIPTORS]; | ||
gdtPtr_t gdtPtr; | ||
|
||
extern void tssFlush(); | ||
|
||
// Functions | ||
|
||
// gdtSetGate(int32_t num, uint32_t base, uint32_t limit, uint8_t access, uint8_t gran) - Set the value of 1 GDT entry. | ||
void gdtSetGate(int32_t num, uint32_t base, uint32_t limit, uint8_t access, uint8_t gran) { | ||
// Sanity check first! | ||
ASSERT(num < MAX_DESCRIPTORS, "gdtSetGate()", "invalid descriptor number"); | ||
|
||
// Now set the proper values in the gdt entries. | ||
gdtEntries[num].baseLow = (base & 0xFFFF); | ||
gdtEntries[num].baseMiddle = (base >> 16) & 0xFF; | ||
gdtEntries[num].baseHigh = (base >> 24) & 0xFF; | ||
|
||
gdtEntries[num].limitLow = (limit & 0xFFFF); | ||
gdtEntries[num].granularity = (limit >> 16) & 0x0F; | ||
|
||
gdtEntries[num].granularity |= gran & 0xF0; | ||
gdtEntries[num].access = access; | ||
} | ||
|
||
|
||
// gdtInit() - Initializes GDT and sets up all the pointers | ||
void gdtInit() { | ||
// Setup the gdtPtr to point to our gdtEntires | ||
gdtPtr.limit = sizeof(gdtEntries)-1; | ||
gdtPtr.base = (uint32_t)&gdtEntries; | ||
|
||
// Now setup the GDT entries | ||
gdtSetGate(0, 0, 0, 0, 0); // Null segment | ||
gdtSetGate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF); // Code segment | ||
gdtSetGate(2, 0, 0xFFFFFFFF, 0x92, 0xCF); // Data segment | ||
gdtSetGate(3, 0, 0xFFFFFFFF, 0xFA, 0xCF); // User mode code segment | ||
gdtSetGate(4, 0, 0xFFFFFFFF, 0xF2, 0xCF); // User mode data segment. | ||
tssWrite(5, 0x10, 0x0); // Task state segment | ||
|
||
// Install the GDT. | ||
install_gdt((uint32_t)&gdtPtr); | ||
|
||
// Flush TSS. | ||
tssFlush(); | ||
|
||
} |
Oops, something went wrong.