Skip to content

Commit

Permalink
Font, README, & work on paging
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeSteinburger committed Jul 31, 2024
1 parent 947f522 commit cbef05b
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 2,607 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ qemu-system-x86_64 disk.img
You'll obviously need Qemu installed.

### On real hardware
This is ***not recommended***, and it has ***not been tested***, however you're welcome to give it a shot. In the directory of the .bin file, run:
This is ***not recommended***, and it has ***not been tested***, however you're welcome to give it a shot. In the directory of the .img file, run:

```
sudo dd if=SpecOS/scripts/disk.img of=/dev/sdN bs=4M status=progress
sudo dd if=disk.img of=/dev/sdN bs=4M status=progress
```

With /dev/sdN being the name of your USB. Then in your device's unique BIOS, change the boot order so it will boot from USB before your current OS, and restart with your now-formatted USB plugged in.
Expand Down Expand Up @@ -101,3 +101,9 @@ Some things that I gotta do, and some things that I have done, in SpecOS. Yeah,
It's a road to running DOOM!

Note that a lot of this is unrealistic and probably won't happen - it's a lot easier said that done. But my hopes are high (:

## Special thanks
You didn't *really* think that *I* could do this alone of all people, did you? I'm not a genius! Thank you so, so much to these people who have made my journey in operating system development so much easier!

- [Bananymous](https://github.com/Bananymous) is a super smart guy, who taught me a *ton*. He also wrote the amazing [Banan-OS](https://github.com/Bananymous/banan-os)!
- [Dcraftbg](https://github.com/Dcraftbg) has taught me a whole lot about paging and a few other topics. He also just managed to enter userspace on his [MinOS](https://github.com/Dcraftbg/MinOS), nice one :D
8 changes: 4 additions & 4 deletions drivers/vga.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ void drawPix(int x, int y, int colour) {
}

void drawChar(int xOffset, int yOffset, int colour, char ch) {
int firstByteIdx = ch * 8;
int firstByteIdx = ch * 16;
bool doDrawBuffer;
int colourBuffer;
for (int by = 0; by < 8; by++) {
for (int by = 0; by < 16; by++) {
for (int bi = 0; bi < 8; bi++) {
doDrawBuffer = (fontdata_8x8[firstByteIdx + by] >> (7 - bi)) & 1;
doDrawBuffer = (fontGlyphBuffer[firstByteIdx + by] >> (7 - bi)) & 1;
if (doDrawBuffer)
colourBuffer = colour;
else
Expand All @@ -75,7 +75,7 @@ void writeChar(char ch, int colour) {
}

void newline() {
kernel.chY += 10;
kernel.chY += 16;
kernel.chX = 5;
}

Expand Down
26 changes: 13 additions & 13 deletions kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void initKernelData() {
void _start() {
initKernelData();
init_serial();
initVGA();
initVGA();
// Just send output to a serial port to test
writestring("Trying to initialise GDT...\n");
initGDT();
Expand All @@ -65,18 +65,18 @@ void _start() {
writestring("\nStarting physical memory manager...");
initPMM();
// this is commented out cos paging doesn't work yet and it's still in progress.
//writestring("\nInitiating paging...");
//initPaging();
char buffer[10];
uint64_t tableSingle;
for (int i = 0; i < 5; i++) {
for (int y = 0; y < 10; y++)
buffer[y] = 0;
tableSingle = *(uint64_t*)&(kernel.GDT)[i];
uint64_to_hex_string((uint64_t)tableSingle, buffer);
writestring("\nGDT contents: 0x");
writestring(buffer);
}
/*writestring("\nInitiating paging...");
struct pmlEntry* pml4Address = initPaging();
printf("\nPages mapped, trying to reload cr3...");
// load a pointer to pml4 into cr3 and change the stack to point elsewhere
__asm__ volatile (
// "movq %0, %%rsp;"
// "movq %1, %%rbp;"
"movq %1, %%cr3"
: : "r" ((uint64_t) 0xfffffffffffff000),
"r" ((uint64_t) pml4Address)
);
printf("\nPaging successfully enabled!");*/
test_userspace();
for (;;);
}
18 changes: 17 additions & 1 deletion mem/include/paging.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@
#ifndef PAGING_H
#define PAGING_H

void initPaging();
struct pmlEntry {
uint8_t isPresent : 1;
uint8_t isReadOrWrite : 1;
uint8_t isUserOrSupervisor : 1;
uint8_t pwt : 1;
uint8_t cacheDisable : 1;
uint8_t accessed : 1;
uint8_t avaliable : 1;
uint8_t rsvdOrPageSize : 1; // rsvd if normal pml entry, page size if it's a pdpt entry or page directory entry. doesn't really matter cos it's 0 either way.
uint8_t avaliable2 : 4;
uint64_t address : 40;
// think there should be reserved bits here? think again! assume M = 51.
uint16_t available3 : 11;
uint8_t executeDisable : 1;
} __attribute__((packed));

struct pmlEntry* initPaging();

#endif
29 changes: 3 additions & 26 deletions mem/paging.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,6 @@
// make it know what stuff is
// this is one definition, cos pml 1->4 are all basically the same
// it's just layers of page directories
struct pmlEntry {
uint8_t isPresent : 1;
uint8_t isReadOrWrite : 1;
uint8_t isUserOrSupervisor : 1;
uint8_t pwt : 1;
uint8_t cacheDisable : 1;
uint8_t accessed : 1;
uint8_t avaliable : 1;
uint8_t rsvdOrPageSize : 1; // rsvd if normal pml entry, page size if it's a pdpt entry or page directory entry. doesn't really matter cos it's 0 either way.
uint8_t avaliable2 : 4;
uint64_t address : 40;
// think there should be reserved bits here? think again! assume M = 51.
uint16_t available3 : 11;
uint8_t executeDisable : 1;
} __attribute__((packed));

// set up the structure
struct pmlEntry pml4[512] __attribute__((aligned(4096)));

Expand Down Expand Up @@ -117,7 +101,7 @@ void mapConsecutivePages(struct pmlEntry pml4[], uint64_t startingPhysAddr, uint
}
}

void initPaging() {
struct pmlEntry* initPaging() {
/* page entries will be defined later when filling pml1
* and so will the pdpt when loading it into cr3
* fill up pml1 with mappings
Expand All @@ -133,15 +117,8 @@ void initPaging() {
for (uint64_t i = startingPageFrame; i < endPageFrame; i++) {
mapPage(pml4, (uint64_t) kmalloc(), i, true);
}
printf("\nPages mapped, trying to reload cr3...");
// load a pointer to pml4 into cr3 and change the stack to point elsewhere
__asm__ volatile (
"movq %0, %%cr3;"
"movq %1, %%rsp"
: : "r" ((uint64_t) pml4 + kernel.hhdm),
"r" ((uint64_t) 0xfffffffffffff000)
);
printf("\nPaging successfully enabled!");
// return some stuff so the entry point function of the kernel can reload cr3
return pml4 + kernel.hhdm;
// no need to enable paging, limine already enables it :D
}

Expand Down
Loading

0 comments on commit cbef05b

Please sign in to comment.