Clean up jump into RING 3

dev
Nigel Barink 2023-02-17 14:46:44 +01:00
parent 4ce7cc093b
commit ecab248cd6
5 changed files with 51 additions and 35 deletions

View File

@ -99,11 +99,9 @@ isPaging:
# Unmap the identity mapping as it is now unnecessary # Unmap the identity mapping as it is now unnecessary
# movl $0, boot_page_directory + 0 # movl $0, boot_page_directory + 0
call kernel
call early_main
cli cli
1: hlt 1: hlt
@ -115,4 +113,18 @@ isPaging:
.include "./source/kernel/irq_table.s" .include "./source/kernel/irq_table.s"
.include "./source/kernel/interrupts/idt.s" .include "./source/kernel/interrupts/idt.s"
.globl jump_usermode
jump_usermode:
mov $((4*8) | 3) , %ax
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
mov %esp, %eax
push $( (3*8) | 3)
push %eax
pushf
push $( ( 3 * 8) | 3)
push startSuperVisorTerminal
iret

View File

@ -4,6 +4,6 @@
*/ */
#define __DEBUG__ false #define __DEBUG__ false
#define KERNEL_VERSION 0 #define KERNEL_VERSION 0.03
#define ARCHITECTURE "I386" #define ARCHITECTURE "I386"

View File

@ -21,6 +21,7 @@ extern "C"{
#include "interrupts/idt.h" #include "interrupts/idt.h"
#include "serial.h" #include "serial.h"
extern "C" void LoadGlobalDescriptorTable(); extern "C" void LoadGlobalDescriptorTable();
extern "C" void jump_usermode();
void set_protected_bit() void set_protected_bit()
{ {
@ -63,18 +64,13 @@ extern "C" void kernel ()
printf("Enable Protected mode and jump to kernel main\n"); printf("Enable Protected mode and jump to kernel main\n");
// Set the protected bit of control register 0 set_protected_bit();
// this will put the CPU into protected mode
// NOTE: This should really be a assembly procedure
// We cant directly write to control register 0
// therefor we copy the value of control register 0 into eax
// once we are done manipulating the value we write the value in
// eax back to control register 0
asm volatile("mov %cr0, %eax "); #ifdef USERMODE_RELEASE
asm volatile("or $1, %eax"); // Lets jump into user mode
asm volatile("mov %eax, %cr0"); jump_usermode();
#else
pit_initialise(); startSuperVisorTerminal();
#endif
} }

View File

@ -4,7 +4,13 @@
#include "../filesystem/FAT/BiosParameterBlock.h" #include "../filesystem/FAT/BiosParameterBlock.h"
#include "../filesystem/FAT/DirectoryEntry.h" #include "../filesystem/FAT/DirectoryEntry.h"
bool isRunning = true; bool isRunning = true;
void startSuperVisorTerminal(){ extern "C" void startSuperVisorTerminal()
{
/*
* Show a little banner for cuteness
*/
printf("|=== BarinkOS ===|\n");
while (isRunning){ while (isRunning){
printf("SUPERVISOR:>$ " ); printf("SUPERVISOR:>$ " );
@ -115,7 +121,7 @@ void startSuperVisorTerminal(){
uint16_t biosparameterblock[256]; uint16_t biosparameterblock[256];
ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER, mbr->TableEntries[0].LBA_partition_start, biosparameterblock); ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER, mbr->TableEntries[0].LBA_partition_start, biosparameterblock);
BiosParameterBlock* bpb = (BiosParameterBlock*) biosparameterblock; auto* bpb = (BiosParameterBlock*) biosparameterblock;
printf("\nBPB: Bytes per Sector %d\n", bpb->BytesPerSector ); printf("\nBPB: Bytes per Sector %d\n", bpb->BytesPerSector );
@ -138,8 +144,8 @@ void startSuperVisorTerminal(){
ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER, FATAddress, FAT ); ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER, FATAddress, FAT );
// Show data in terminal // Show data in terminal
for(int i = 0; i < 256; i++ ) { for(unsigned short i : FAT) {
printf("%x ", FAT[i]); printf("%x ", i);
} }
kterm_put('\n'); kterm_put('\n');
@ -149,33 +155,35 @@ void startSuperVisorTerminal(){
uint16_t data2 [256]; uint16_t data2 [256];
ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER, RootDirectoryRegion, data2 ); ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER, RootDirectoryRegion, data2 );
DirectoryEntry* RootDirectory = (DirectoryEntry*) data2; auto* RootDirectory = (DirectoryEntry*) data2;
// List files in root // List files in root
for(int i= 0; i < bpb->NumberOfDirectoryEntries ; i++ ) for(int i= 0; i < bpb->NumberOfDirectoryEntries ; i++ )
{ {
DirectoryEntry* entry = (DirectoryEntry*)((uint32_t) RootDirectory + (i * sizeof(DirectoryEntry))); auto* entry = (DirectoryEntry*)((uint32_t) RootDirectory + (i * sizeof(DirectoryEntry)));
if( entry->filename[0] == (uint8_t) 0x00 ) if( entry->filename[0] == (uint8_t) 0x00 )
break; // There are no more entries in this directory or the entry is free break; // There are no more entries in this directory or the entry is free
if( entry->attribute & 0x01 == 0x01 || entry->attribute & 0x20 == 0x20) if( (entry->attribute & 0x01) == 0x01 || (entry->attribute & 0x20) == 0x20)
continue; // Skip listing if hidden or Achieve flag is set continue; // Skip listing if hidden or Achieve flag is set
// Print the filename; // Print the filename;
for( int n = 0; n < 8; n++ ){ for(char n : entry->filename){
if(entry->filename[n] == 0x20) if(n == 0x20)
break; break;
kterm_put(entry->filename[n]); kterm_put(n);
}kterm_put('\n'); }
kterm_put('\n');
for( int n = 0; n < 3; n++){ for(unsigned char n : entry->Extension){
kterm_put(entry->Extension[n]); kterm_put(n);
}kterm_put('\n'); }
kterm_put('\n');
printf("Attribute: %x \n" , entry->attribute); printf("Attribute: %x \n" , entry->attribute);
printf("FileSize: %d Bytes\n", entry->FilesizeInBytes); printf("FileSize: %d Bytes\n", entry->FilesizeInBytes);
if( entry->FilesizeInBytes != 0x0 || entry->attribute & 0x8 == 0x0){ if( entry->FilesizeInBytes != 0x0 || (entry->attribute & 0x8) == 0x0){
printf("Show contents"); printf("Show contents");
printf( "Start cluster of the file: 0x%x\n" , entry->StartingCluster); printf( "Start cluster of the file: 0x%x\n" , entry->StartingCluster);
@ -187,11 +195,11 @@ void startSuperVisorTerminal(){
uint16_t dataBlob [256]; uint16_t dataBlob [256];
ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER, sector, dataBlob ); ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER, sector, dataBlob );
for( int n = 0; n < 256; n++) for(unsigned short n : dataBlob)
{ {
kterm_put(dataBlob[n] & 0x00ff); kterm_put(n & 0x00ff);
kterm_put(dataBlob[n] >> 8); kterm_put(n >> 8);
}kterm_put('\n'); }kterm_put('\n');

View File

@ -8,4 +8,4 @@ extern "C" {
#include "../../lib/include/string.h" #include "../../lib/include/string.h"
} }
void startSuperVisorTerminal(); extern "C" void startSuperVisorTerminal();