algorithman-de / wyoos Goto Github PK
View Code? Open in Web Editor NEWSource codes for the "Write your own Operating System" video-series on YouTube
Home Page: http://wyoos.org
License: GNU General Public License v3.0
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
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
(Sine pull requests dont get accepted i will post this here)
You'll have to wait for the disk to be ready in the Read28 and Write28 functions as well
Found this information here: https://osdev.org/ATA_PIO_Mode
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.
The HandleException
macro assumes that all exceptions have an error code pushed on the stack. The list of exceptions that the CPU pushes an error code/doesn't push can be found here: https://wiki.osdev.org/Exceptions . One option is to split the HandleException
macro into two macros. One that handles exceptions with an error code and one that doesn't. When an error code isn't pushed a dummy value of 0 can be used in its place.
Remove the current HandleException
macro in interruptstubs.s and replace with:
.macro HandleExceptionErrCode num
.global _ZN16InterruptManager19HandleException\num\()Ev
_ZN16InterruptManager19HandleException\num\()Ev:
movb $\num, (interruptnumber)
jmp int_bottom
.endm
.macro HandleExceptionNoErrCode num
.global _ZN16InterruptManager19HandleException\num\()Ev
_ZN16InterruptManager19HandleException\num\()Ev:
movb $\num, (interruptnumber)
push $0x00 # Push Dummy Error Code
jmp int_bottom
.endm
Then generate stubs for all 32 exceptions like this:
HandleExceptionNoErrCode 0x00
HandleExceptionNoErrCode 0x01
HandleExceptionNoErrCode 0x02
HandleExceptionNoErrCode 0x03
HandleExceptionNoErrCode 0x04
HandleExceptionNoErrCode 0x05
HandleExceptionNoErrCode 0x06
HandleExceptionNoErrCode 0x07
HandleExceptionErrCode 0x08
HandleExceptionNoErrCode 0x09
HandleExceptionErrCode 0x0A
HandleExceptionErrCode 0x0B
HandleExceptionErrCode 0x0C
HandleExceptionErrCode 0x0D
HandleExceptionErrCode 0x0E
HandleExceptionNoErrCode 0x0F
HandleExceptionNoErrCode 0x10
HandleExceptionErrCode 0x11
HandleExceptionNoErrCode 0x12
HandleExceptionNoErrCode 0x13
HandleExceptionNoErrCode 0x14
HandleExceptionErrCode 0x15
HandleExceptionNoErrCode 0x16
HandleExceptionNoErrCode 0x17
HandleExceptionNoErrCode 0x18
HandleExceptionNoErrCode 0x19
HandleExceptionNoErrCode 0x1A
HandleExceptionNoErrCode 0x1B
HandleExceptionNoErrCode 0x1C
HandleExceptionErrCode 0x1D
HandleExceptionErrCode 0x1E
HandleExceptionNoErrCode 0x1F
In interrupts.cpp and interrupts.h you can then add all the exception handlers that are missing. The InterruptManager
only supplies default exception handlers for HandleException0x00
to HandleException0x13
, and that can now be up to HandleException0x1f
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.
Why don't you use the makefile ...
Originally posted by @VishnuRathore98 in #25 (comment)
'fatal error: u10073'
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"
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.
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
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.
The desktop GUI is flashing in VirtualBox
I don't see windows on screen in GRAPHICSMODE
.
I've used qemu-system-i386
.
Line 53 in 22bf3f7
Should be
VideoMemory[80*y + x] = (VideoMemory[80u*y + x] & 0xFF00u) | (uint8_t)str[i];
else you end up writing to the color addresses, on most characters with more than 127 as value
./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;
|
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).
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
I get this error when compiling 'mykernel.bin'. I double checked everything to be right multiple times, and still nothing works! Could somebody help me with this? It's very confusing... Thanks in advance.
Can't open YouTube, teach me how to adapt it
Thank you for the videos.
It would be nice if you include a license for these files to see how we can reuse them. Are they GPL, Apache, ... ?
make kernel.o
make: *** No rule to make target 'kernel.o'. Stop.
I'm in part one
https://www.youtube.com/watch?v=1rnA6wpF0o4&t=746s
any help with this error would be greatly appreciated I'm assuming it's a error in the makefile
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));
}
qemu shows with flashing text
The code in GlobalDescriptorTable::GlobalDescriptorTable()
fails to reload the segment registers after creating a GDT and loading it with lgdt
. As a result, the code expects that GRUB's values for the code and data segment selectors are the same as the OS. While the multiboot spec guarantees that the segment registers are loaded with flat descriptors with a maximum limit, the actual selector values can't be assumed to be specific values. In function GlobalDescriptorTable::GlobalDescriptorTable()
in gdt.cpp change:
asm volatile("lgdt (%0)": :"p" (((uint8_t *) i)+2));
to:
asm volatile(
"lgdt %0\n"
"mov %2, %%ds\n" /* Set segments to the data selector */
"mov %2, %%es\n"
"mov %2, %%fs\n"
"mov %2, %%gs\n"
"mov %2, %%ss\n"
"push %1\n" /* Use Far Return to set CS:EIP */
"push $1f\n"
"retf\n"
"1:\n" /* Far return returns to this location */
:
: "m" (*(((uint8_t *) i)+2)),
"r"(CodeSegmentSelector()),
"r"(DataSegmentSelector())
: "memory"
);
Without this change, running QEMU with the -cdrom
option may work but with -kernel
it may not. QEMU isn't buggy in this regard but WYOOS is.
In virtual box driver works good, in qemu cursor is "jumping", but in vmware and on real hardware it does't do anything. How to fix that?
mouse.h: https://pastebin.com/AjbxGS7R
mouse.cpp: https://pastebin.com/jqC959dc
Hello everyone, I really, really hope you can help me.
I'm at minute 55:05 of the Chapter 5 video, in which AlgorithMan successfully compiles its code after changing the first lines of the interruptstubs.s
file. The thing is, it is not working for me. I tried checking everything, even found a typo in my code and corrected it, but I'm still getting these errors:
interrupts.cpp(.text+0xe2): undefined reference to 'InterruptManager::IgnoreInterruptRequest()'
ld: interrupts.cpp(.text+0x111): undefined reference to 'InterruptManager::HandleInterruptRequest0x00()'
ld: interrupts.cpp(.text+0x12e): undefined reference to 'InterruptManager::HandleInterruptRequest0x01()'
For more info, this is how my interruptstubs.s file looks at the moment. I will copy it entirely so you can see:
.set IRQ_BASE, 0x20
.section .text
.extern _ZN16InterruptManager15handleInterruptEhj
.global _ZN16InterruptManager22IgnoreInterruptRequestEv
.macro HandleException num
.global _ZN16InterruptManager16HandleException\num\()Ev
_ZN16InterruptManager16HandleException\num\()Ev:
movb $\num, (interruptnumber)
jmp int_bottom
.endm
.macro HandleInterruptRequest num
.global _ZN16InterruptManager26HandleInterruptRequest\num\()Ev
_ZN16InterruptManager26HandleInterruptRequest\num\()Ev:
movb $\num + IRQ_BASE, (interruptnumber)
jmp int_bottom
.endm
HandleInterruptRequest 0x00
HandleInterruptRequest 0x01
int_bottom:
pusha
pushl %ds
pushl %es
pushl %fs
pushl %gs
pushl %esp
push (interruptnumber)
call _ZN16InterruptManager15handleInterruptEhj
mov %eax, %esp
popl %gs
popl %fs
popl %es
popl %ds
popa
_ZN16InterruptManager22IgnoreInterruptRequestEv:
iret
.data
interruptnumber: .byte 0
And here is the result after executing nm interrupts.o:
U _GLOBAL_OFFSET_TABLE_
00000000 T __x86.get_pc_thunk.ax
00000000 T __x86.get_pc_thunk.bx
U _Z6printfPc
0000017a T _ZN16InterruptManager15handleInterruptEhj
U _ZN16InterruptManager22IgnoreInterruptRequestEv
00000000 B _ZN16InterruptManager24interruptDescriptorTableE
U _ZN16InterruptManager26HandleInterruptRequest0x00Ev
U _ZN16InterruptManager26HandleInterruptRequest0x01Ev
00000000 T _ZN16InterruptManager32SetInterruptDescriptorTableEntryEhtPFvvEhh
00000168 T _ZN16InterruptManager8ActivateEv
0000009e T _ZN16InterruptManagerC1EP21GlobalDescriptorTable
0000009e T _ZN16InterruptManagerC2EP21GlobalDescriptorTable
00000158 T _ZN16InterruptManagerD1Ev
00000158 T _ZN16InterruptManagerD2Ev
U _ZN21GlobalDescriptorTable19CodeSegmentSelectorEv
Please, any help would be appreciated. I'm loving this course and I would hate to fall stuck here and not be able to continue :( Thank you in advance!
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.
After writing the gdt.cpp file and calling the class in kernel.cpp and "make run" i get this error, is there a solution to this ?but the gdt.o is created but i cant compile the .bin file
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.
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.
ld: ./bin/kernel.o: in function fgosMain': kernel.cpp:(.text+0xda): undefined reference to
GlobalDescriptorTable::GlobalDescriptorTable()'
Hello, I don't know how to compile the OS. Can somebody send me a cmd/bat/sh command file to build it please? Thanks in advance.
The desktop and windows are not showing correctly in QEMU
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.