GithubHelp home page GithubHelp logo

algorithman-de / wyoos Goto Github PK

View Code? Open in Web Editor NEW
717.0 717.0 223.0 83 KB

Source codes for the "Write your own Operating System" video-series on YouTube

Home Page: http://wyoos.org

License: GNU General Public License v3.0

C++ 96.30% Assembly 2.17% Makefile 1.53%

wyoos's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wyoos's Issues

memorymanagement.cpp bug

Ok, so I ran the makefile which did pretty good at building the os. however A few files may need a little help? I wondered if anyone else encountered this.

memorymanagement.cpp and memorymanagement.h
are both complaining about the first parameter of allocation function must be of type 'size_t'/ from the operator new.

this also affects pci.cpp, tcp.cpp, udp.cpp files in pretty much the same manner but gives a hint to a unsigned long? in my intellisense.

though in the build proccess that make ran, only complained about:

src/memorymanagement.cpp: In function ‘void* operator new(unsigned int)’:
src/memorymanagement.cpp:97:16: warning: ‘operator new’ must not return NULL unless it is declared ‘throw()’ (or -fcheck-new is in effect)
return 0;
^
src/memorymanagement.cpp: In function ‘void* operator new [](unsigned int)’:
src/memorymanagement.cpp:104:16: warning: ‘operator new’ must not return NULL unless it is declared ‘throw()’ (or -fcheck-new is in effect)
return 0;

I couldnt find any other issues.

Slow VGA Fill?

Not sure if this is an issue exactly. But I just got done with vid n.12. And in the video, his goes from the terminal then quickly to a screen with that glitchy background but fills to blue almost immediately. Mine takes about 2 seconds or so.

I've checked through my code base with the commit and some of the notes. I don't see if I did anything wrong? Is it something wrong with vm box? I gave it plenty of vram, memory, and I even tried to see if giving it more cores help (which I'd assume not because I would assume I need to make manual work of that in a custom os build).

VGA.hpp

class VGA {
protected:
    Port8Bit miscPort;
    Port8Bit crtcIndexPort;
    Port8Bit crtcDataPort;
    Port8Bit sequencerIndexPort;
    Port8Bit sequencerDataPort;
    Port8Bit graphicsControllerIndexPort;
    Port8Bit graphicsControllerDataPort;
    Port8Bit attributeControllerIndexPort;
    Port8Bit attributeControllerReadPort;
    Port8Bit attributeControllerWritePort;
    Port8Bit attributeControllerResetPort;

    void WriteRegisters(uint8* registers);
    uint8* GetFrameBufferSegment();
public:
    VGA();
    ~VGA();

    virtual bool SupportsMode(uint32 width, uint32 height, uint32 colorDepth);
    virtual bool SetMode(uint32 width, uint32 height, uint32 colorDepth);
    virtual uint8 GetColorIndex(uint8 r, uint8 g, uint8 b);
    virtual void SetPixel(uint32 x, uint32 y, uint8 colorIndex);
    virtual void SetPixel(uint32 x, uint32 y, uint8 r, uint8 g, uint8 b);
};

VGA.cpp

void VGA::WriteRegisters(uint8* registers) {
    miscPort.Write(*(registers++));

    for (uint8 i = 0; i < 5; i++) {
        sequencerIndexPort.Write(i);
        sequencerDataPort.Write(*(registers++));
    }
    
/*
    crtcIndexPort.Write(0x03);
    crtcDataPort.Write(crtcDataPort.Read() | 0x80);
    crtcIndexPort.Write(0x11);
    crtcDataPort.Write(crtcDataPort.Read() & ~0x80);

    registers[0x03] = registers[0x03] | 0x80;
    registers[0x11] = registers[0x11] & ~0x80;
    */
    crtcIndexPort.Write(0x09);
    crtcDataPort.Write(crtcDataPort.Read() | 0x80);
    crtcIndexPort.Write(0x16);
    crtcDataPort.Write(crtcDataPort.Read() & ~0x80);

    registers[0x09] = registers[0x09] | 0x80;
    registers[0x16] = registers[0x16] & ~0x80;

    for (uint8 i = 0; i < 25; i++) {
        crtcIndexPort.Write(i);
        crtcDataPort.Write(*(registers++));
    }
    
    for (uint8 i = 0; i < 9; i++) {
        graphicsControllerIndexPort.Write(i);
        graphicsControllerDataPort.Write(*(registers++));
    }

    for (uint8 i = 0; i < 21; i++) {
        attributeControllerResetPort.Read();
        attributeControllerIndexPort.Write(i);
        attributeControllerWritePort.Write(*(registers++));
    }

    attributeControllerResetPort.Read();
    attributeControllerIndexPort.Write(0x20);
}
uint8* VGA::GetFrameBufferSegment() {
    graphicsControllerIndexPort.Write(0x06);
    uint8 segmentNumber = graphicsControllerDataPort.Read() & (3 << 2);

    switch (segmentNumber) {
    default:
    case(0 << 2): return (uint8*)0x00000;
    case(1 << 2): return (uint8*)0xA0000;
    case(2 << 2): return (uint8*)0xB0000;
    case(3 << 2): return (uint8*)0xB8000;
    }
}


VGA::VGA() :
miscPort(0x3C2),
crtcIndexPort(0x3D4),
crtcDataPort(0x3D5),
sequencerIndexPort(0x3C4),
sequencerDataPort(0x3C5),
graphicsControllerIndexPort(0x3CE),
graphicsControllerDataPort(0x3CF),
attributeControllerIndexPort(0x3C0),
attributeControllerReadPort(0x3C1),
attributeControllerWritePort(0x3C0),
attributeControllerResetPort(0x3DA) {
    //
}
VGA::~VGA() {
    //
}

bool VGA::SupportsMode(uint32 width, uint32 height, uint32 colorDepth) {
    return width == 320 && height == 200 && colorDepth == 8;
}
bool VGA::SetMode(uint32 width, uint32 height, uint32 colorDepth) {
    if (!SupportsMode(width, height, colorDepth)) return false;

    unsigned char g_320x200x256[] = {
    /* MISC */
        0x63,
    /* SEQ */
        0x03, 0x01, 0x0F, 0x00, 0x0E,
    /* CRTC */
        0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0xBF, 0x1F,
        0x00, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x9C, 0x0E, 0x8F, 0x28,	0x40, 0x96, 0xB9, 0xA3,
        0xFF,
    /* GC */
        0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F,
        0xFF,
    /* AC */
        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
        0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
        0x41, 0x00, 0x0F, 0x00,	0x00
    };

    WriteRegisters(g_320x200x256);
    return true;
}
uint8 VGA::GetColorIndex(uint8 r, uint8 g, uint8 b) {
    if (r == 0x00 && g == 0x00 && 0xA8)
        return 0x01;
    return 0x00;
}
void VGA::SetPixel(uint32 x, uint32 y, uint8 colorIndex) {
    uint8* pixelAddr = GetFrameBufferSegment() + 320*y + x;
    *pixelAddr = colorIndex;
}
void VGA::SetPixel(uint32 x, uint32 y, uint8 r, uint8 g, uint8 b) {
    SetPixel(x,y,GetColorIndex(r, g, b));
}

Probable bug in gdt.cpp

Line 35 in gdt.cpp reads: "if (limit <= 65536)". This is a reference to a memory adress, and a memory adress always start at 0. I recognize the number 65536 as 2^16 so the correct line should probably be "if (limit < 65536)", allowing for memory address from 0 to 65535. Please examine the code and check if I have noticed a bona fide bug.

Excuse me

Can't open YouTube, teach me how to adapt it

Package grub-legacy is not available

Package grub-legacy is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
  grub-coreboot:i386 grub-coreboot grub2-common:i386 grub-pc:i386 grub-ieee1275:i386 grub-efi-ia32:i386
  grub-efi-amd64:i386 grub2-common grub-pc grub-ieee1275 grub-efi-ia32 grub-efi-amd64

E: Package 'grub-legacy' has no installation candidate

Error received on Linux Mint 19.1.

Invalid 'asm': invalid expression as operand

I am getting the following error when trying to compile the code at the end of video 3.

g++ -m32 -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -o gdt.o -c gdt.cpp
gdt.cpp: In constructor ‘GlobalDescriptorTable::GlobalDescriptorTable()’:
gdt.cpp:13:5: error: invalid 'asm': invalid expression as operand
   13 |     asm volatile("lgdt (%0)": : "p" (((uint8_t *) i)+2));
      |     ^~~
make: *** [Makefile:8: gdt.o] Error 1

I have tried a number of things. Tried different versions of GCC (5 and 6 as well as 10.3.0). I have also tried both 32bit and 64bit versions of gcc.

OS Part 7 : Mouse observations

I like your idea of the video series, keep up the good work! A couple of observations regarding the mouse. The mouse X (buffer[1]) and Y (buffer[2]) values are actually part of a 9-bit 2s complement value. Bit 8 (top bit) for X is actually in buffer[0] at bit 4, and Bit 8 (top bit) for Y is in buffer[0] at bit 5. These bits should be taken into account or you could be interpreting some values from the mouse incorrectly. Something like this should work:

/* Bit 4 of buffer[0] is X's sign bit
   Bit 5 of buffer[0] is Y's sign bit */
x += buffer[1] - (0x100 & (buffer[0] << (8-4)));
y -= buffer[2] - (0x100 & (buffer[0] << (8-5)));`

Of course with code as I suggest buffer would be an array of 3 uint8_t, and x and y would have to be a signed integer big enough to hold the values you need (int16_t or int32_t).

Write your own Operating System 5: Interrupts

I am trying to implement the YouTube series "Writing your own OS".

You can find my code at "https://github.com/tiagomendes7/Build_Your_Own_OS/tree/main".

Unfortunately i came across this error and i don't know how to solve it.
I believe it has to do with the file "interruptstubs.s" and the code in the line 19 and line 20:

global _ZN16InterruptManager26HandleInterruptRequest\num\()Ev
_ZN16InterruptManager26HandleInterruptRequest\num\()Ev:

Below you can find the output of the command "make mykernel.iso":

as --32 -o loader.o loader.s

g++ -m32 -Iinclude -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -Wno-write-strings -o port.o -c port.cpp

g++ -m32 -Iinclude -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -Wno-write-strings -o gdt.o -c gdt.cpp

g++ -m32 -Iinclude -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -Wno-write-strings -o interrupts.o -c interrupts.cpp

as --32 -o interruptstubs.o interruptstubs.s

g++ -m32 -Iinclude -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -Wno-write-strings -o kernel.o -c kernel.cpp

ld -melf_i386 -T linkder.ld -o mykernel.bin loader.o port.o gdt.o interrupts.o interruptstubs.o kernel.o

ld: interruptstubs.o: in function `InterruptManager::HandleInterruptRequest0x00()':
(.text+0x0): multiple definition of `InterruptManager::HandleInterruptRequest0x00()'; interrupts.o:interrupts.cpp:(.text+0x34a): first defined here

ld: interruptstubs.o: in function `InterruptManager::HandleInterruptRequest0x01()':
(.text+0xb): multiple definition of `InterruptManager::HandleInterruptRequest0x01()'; interrupts.o:interrupts.cpp:(.text+0x35a): first defined here

make: *** [Makefile:15: mykernel.bin] Error 1

Linker Issue

ld: interrupts.o: in function InterruptManager::InterruptManager(GlobalDescriptorTable*)': interrupts.cpp:(.text+0x111): undefined reference to InterruptManager::HandleInterruptRequest0x00()'
ld: interrupts.cpp:(.text+0x12e): undefined reference to `InterruptManager::HandleInterruptRequest0x01()'
make: *** [Makefile:19: kernel.bin] Error 1

I dunno what's wrong

AMD am79c973

When i start my virtual machine (im using vmware right now because virtualbox loves me (NOT)), I get the error: "AMD am79c973" after "SEND: FF FF FF FF 0A 00 02 02"

Possible typo in ata driver

You're writing to the LbaLowPort, then the LbaMidPort, and then the LbaLowPort again. It is possible that you meant to do LbaLowPort then LbaMidPort then LbaHighPort.

error: cast from ‘GlobalDescriptorTable*’ to ‘uint32_t’

./src/gdt.cpp: In constructor ‘GlobalDescriptorTable::GlobalDescriptorTable()’:
./src/gdt.cpp:10:22: error: cast from ‘GlobalDescriptorTable*’ to ‘uint32_t’ {aka ‘unsigned int’} loses precision [-fpermissive]
10 | i[1] = (uint32_t)this;
|

Error in keyboard driver

Multimedia keys send multiple interrupts when pressed.
First the code 0xe0 and than a keycode.
This would make the code incorect for e.g.:

(multimedia) mute pressed -> 0xE0, 0x20 -> This would call OnKeyDown('d').
(keypad) '/' -> 0xe0, 0x35 -> OnKeyDown('-').

I just wanted to put this out there cuzz it took me quite some time to figure this out.

“lgdt” ASM code results in an error when compiler is optimised on level 2

To load the Global Descriptor Table, the instruction “lgdt” when called from C code, gets discarded, and results in an error “Invalid asm operand: invalid expression”. This is only valid if the compiler is run in a level 2 optimised mode. If it’s not optimized, the compiler runs without any problem.

Tutorial 5: Error when executing 'asm("sti");'

If i execute the line you see above. VirtualBox is crashing and spamming my terminal with many lines but i dont know 1. Why it is crashing and 2. How can I fix this crash

Pls help me i am lost

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.