forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import the "gerbert" kernel I worked on earlier this year.
It's a lot crappier than I remembered it. It's gonna need a lot of work.
- Loading branch information
1 parent
f608629
commit 9396108
Showing
55 changed files
with
4,600 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.o | ||
.floppy-image | ||
Boot/boot.bin | ||
kernel |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
|
||
#include "VGA.h" | ||
|
||
#define CRASH() do { asm volatile("cli;hlt"); } while(0) | ||
#define ASSERT(x) do { if (!(x)) { vga_set_attr(0x4f); kprintf("ASSERTION FAILED: " #x "\n%s:%u in %s\n", __FILE__, __LINE__, __PRETTY_FUNCTION__); CRASH(); } } while(0) | ||
#define RELEASE_ASSERT(x) do { if (!(x)) CRASH(); } while(0) | ||
#define ASSERT_NOT_REACHED() ASSERT(false) |
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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
; asmsyntax=nasm | ||
|
||
[org 0x7c00] | ||
[bits 16] | ||
|
||
boot: | ||
push cs | ||
pop ds | ||
xor bx, bx | ||
mov ah, 0x0e | ||
mov si, message | ||
lodsb | ||
.lewp: | ||
int 0x10 | ||
lodsb | ||
cmp al, 0 | ||
jne .lewp | ||
|
||
mov bx, 0x1000 | ||
mov es, bx | ||
xor bx, bx ; Load kernel @ 0x10000 | ||
|
||
mov ah, 0x02 ; cmd 0x02 - Read Disk Sectors | ||
mov al, 72 ; 72 sectors (max allowed by bochs BIOS) | ||
mov ch, 0 ; track 0 | ||
mov cl, 10 ; sector 10 | ||
mov dh, 0 ; head 0 | ||
mov dl, 0 ; drive 0 (fd0) | ||
int 0x13 | ||
|
||
jc fug | ||
|
||
mov ah, 0x02 | ||
mov al, 32 | ||
add bx, 0x9000 | ||
mov ch, 2 | ||
mov cl, 10 | ||
mov dh, 0 | ||
mov dl, 0 | ||
int 0x13 | ||
|
||
jc fug | ||
|
||
lgdt [cs:test_gdt_ptr] | ||
|
||
mov eax, cr0 | ||
or al, 1 | ||
mov cr0, eax | ||
|
||
jmp 0x08:pmode | ||
|
||
pmode: | ||
[bits 32] | ||
mov ax, 0x10 | ||
mov ds, ax | ||
mov es, ax | ||
mov fs, ax | ||
mov gs, ax | ||
|
||
mov ss, ax | ||
mov esp, 0x2000 | ||
|
||
jmp 0x10000 | ||
|
||
hlt | ||
|
||
test_gdt_ptr: | ||
dw (test_gdt_end-test_gdt) | ||
dd test_gdt | ||
|
||
test_gdt: | ||
dd 0 | ||
dd 0 | ||
dd 0x0000ffff | ||
dd 0x00cf9a00 | ||
dd 0x0000ffff | ||
dd 0x00cf9200 | ||
dd 0 | ||
dd 0 | ||
dd 0 | ||
dd 0 | ||
test_gdt_end: | ||
|
||
[bits 16] | ||
fug: | ||
xor bx, bx | ||
mov ah, 0x0e | ||
mov si, fug_message | ||
lodsb | ||
.lewp: | ||
int 0x10 | ||
lodsb | ||
cmp al, 0 | ||
jne .lewp | ||
|
||
cli | ||
hlt | ||
message: | ||
db "boot!", 0x0d, 0x0a, 0 | ||
|
||
fug_message: | ||
db "FUG!", 0x0d, 0x0a, 0 | ||
|
||
times 510-($-$$) db 0 | ||
dw 0xaa55 |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "CMOS.h" | ||
#include "IO.h" | ||
|
||
namespace CMOS { | ||
|
||
BYTE read(BYTE index) | ||
{ | ||
IO::out8(0x70, index); | ||
return IO::in8(0x71); | ||
} | ||
|
||
void write(BYTE index, BYTE data) | ||
{ | ||
IO::out8(0x70, index); | ||
IO::out8(0x71, data); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
|
||
#include "types.h" | ||
|
||
namespace CMOS { | ||
|
||
BYTE read(BYTE index); | ||
void write(BYTE index, BYTE data); | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include "DataBuffer.h" | ||
#include "StdLib.h" | ||
|
||
#define SANITIZE_DATABUFFER | ||
|
||
DataBuffer::DataBuffer(size_t length) | ||
: m_length(length) | ||
, m_owned(true) | ||
{ | ||
m_data = new BYTE[m_length]; | ||
#ifdef SANITIZE_DATABUFFER | ||
memset(m_data, 0x1a, length); | ||
#endif | ||
} | ||
|
||
DataBuffer::DataBuffer(BYTE* data, size_t length, ConstructionMode mode) | ||
: m_length(length) | ||
{ | ||
switch (mode) { | ||
case Copy: | ||
m_data = new BYTE[m_length]; | ||
memcpy(m_data, data, m_length); | ||
m_owned = true; | ||
break; | ||
case Adopt: | ||
m_data = data; | ||
m_owned = true; | ||
break; | ||
case Wrap: | ||
m_data = data; | ||
m_owned = false; | ||
break; | ||
} | ||
} | ||
|
||
DataBuffer::~DataBuffer() | ||
{ | ||
clear(); | ||
#ifdef SANITIZE_DATABUFFER | ||
m_data = (BYTE*)0x88888888; | ||
#endif | ||
} | ||
|
||
void DataBuffer::clear() | ||
{ | ||
if (m_owned) { | ||
#ifdef SANITIZE_DATABUFFER | ||
memset(m_data, 0x99, m_length); | ||
#endif | ||
delete [] m_data; | ||
} | ||
m_owned = false; | ||
m_data = nullptr; | ||
m_length = 0; | ||
} | ||
|
||
RefPtr<DataBuffer> DataBuffer::createUninitialized(size_t length) | ||
{ | ||
return adoptRef(new DataBuffer(length)); | ||
} | ||
|
||
RefPtr<DataBuffer> DataBuffer::copy(const BYTE* data, size_t length) | ||
{ | ||
return adoptRef(new DataBuffer(const_cast<BYTE*>(data), length, Copy)); | ||
} | ||
|
||
RefPtr<DataBuffer> DataBuffer::wrap(BYTE* data, size_t length) | ||
{ | ||
return adoptRef(new DataBuffer(data, length, Wrap)); | ||
} | ||
|
||
RefPtr<DataBuffer> DataBuffer::adopt(BYTE* data, size_t length) | ||
{ | ||
return adoptRef(new DataBuffer(data, length, Adopt)); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#pragma once | ||
|
||
#include "types.h" | ||
#include "RefCounted.h" | ||
#include "RefPtr.h" | ||
|
||
class DataBuffer : public RefCounted<DataBuffer> { | ||
public: | ||
~DataBuffer(); | ||
|
||
BYTE operator[](size_t i) const { return m_data[i]; } | ||
bool isEmpty() const { return !m_length; } | ||
size_t length() const { return m_length; } | ||
BYTE* data() { return m_data; } | ||
const BYTE* data() const { return m_data; } | ||
|
||
static RefPtr<DataBuffer> copy(const BYTE*, size_t length); | ||
static RefPtr<DataBuffer> wrap(BYTE*, size_t length); | ||
static RefPtr<DataBuffer> adopt(BYTE*, size_t length); | ||
static RefPtr<DataBuffer> createUninitialized(size_t length); | ||
|
||
void clear(); | ||
void leak() { m_data = nullptr; m_length = 0; m_owned = false; } | ||
|
||
private: | ||
DataBuffer() { } | ||
DataBuffer(DataBuffer&&) = delete; | ||
DataBuffer& operator=(DataBuffer&&) = delete; | ||
|
||
enum ConstructionMode { Copy, Wrap, Adopt }; | ||
explicit DataBuffer(size_t length); | ||
DataBuffer(BYTE*, size_t length, ConstructionMode); | ||
DataBuffer(const DataBuffer&) = delete; | ||
DataBuffer& operator=(const DataBuffer&) = delete; | ||
|
||
BYTE* m_data { nullptr }; | ||
size_t m_length { 0 }; | ||
bool m_owned { false }; | ||
}; |
Oops, something went wrong.