mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
Bootloader: Locate the kernel's data segment and clear it.
This was a constant source of stupid bugs and I kept postponing it because I wasn't in the mood to write assembly code. Until now! :^)
This commit is contained in:
parent
781f216676
commit
a1b63bb6d4
Notes:
sideshowbarker
2024-07-19 15:50:58 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/a1b63bb6d4b
@ -21,15 +21,6 @@ namespace AK {
|
|||||||
|
|
||||||
static StringImpl* s_the_empty_stringimpl = nullptr;
|
static StringImpl* s_the_empty_stringimpl = nullptr;
|
||||||
|
|
||||||
void StringImpl::initialize_globals()
|
|
||||||
{
|
|
||||||
s_the_empty_stringimpl = nullptr;
|
|
||||||
#ifdef DEBUG_STRINGIMPL
|
|
||||||
g_stringimpl_count = 0;
|
|
||||||
g_all_live_stringimpls = new HashTable<StringImpl*>;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
StringImpl& StringImpl::the_empty_stringimpl()
|
StringImpl& StringImpl::the_empty_stringimpl()
|
||||||
{
|
{
|
||||||
if (!s_the_empty_stringimpl)
|
if (!s_the_empty_stringimpl)
|
||||||
|
@ -17,7 +17,6 @@ public:
|
|||||||
RetainPtr<StringImpl> to_uppercase() const;
|
RetainPtr<StringImpl> to_uppercase() const;
|
||||||
|
|
||||||
static StringImpl& the_empty_stringimpl();
|
static StringImpl& the_empty_stringimpl();
|
||||||
static void initialize_globals();
|
|
||||||
|
|
||||||
~StringImpl();
|
~StringImpl();
|
||||||
|
|
||||||
|
@ -24,11 +24,6 @@ BochsVGADevice& BochsVGADevice::the()
|
|||||||
return *s_the;
|
return *s_the;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BochsVGADevice::initialize_statics()
|
|
||||||
{
|
|
||||||
s_the = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
BochsVGADevice::BochsVGADevice()
|
BochsVGADevice::BochsVGADevice()
|
||||||
{
|
{
|
||||||
s_the = this;
|
s_the = this;
|
||||||
|
@ -10,7 +10,6 @@ class BochsVGADevice {
|
|||||||
AK_MAKE_ETERNAL
|
AK_MAKE_ETERNAL
|
||||||
public:
|
public:
|
||||||
static BochsVGADevice& the();
|
static BochsVGADevice& the();
|
||||||
static void initialize_statics();
|
|
||||||
|
|
||||||
BochsVGADevice();
|
BochsVGADevice();
|
||||||
|
|
||||||
|
@ -25,9 +25,13 @@ boot:
|
|||||||
mov ax, 0x2401
|
mov ax, 0x2401
|
||||||
int 0x15
|
int 0x15
|
||||||
|
|
||||||
mov bx, 0x1000
|
; HACK: Load the ELF kernel at 0xf000. Assuming that the first
|
||||||
|
; LOAD header has a file offset of 0x1000, this puts _start
|
||||||
|
; at 0x10000 which we jump to later.
|
||||||
|
; This is all quite rickety.
|
||||||
|
mov bx, 0xf00
|
||||||
mov es, bx
|
mov es, bx
|
||||||
xor bx, bx ; Load kernel @ 0x10000
|
xor bx, bx
|
||||||
|
|
||||||
mov cx, word [cur_lba]
|
mov cx, word [cur_lba]
|
||||||
.sector_loop:
|
.sector_loop:
|
||||||
@ -65,6 +69,53 @@ boot:
|
|||||||
xor al, al
|
xor al, al
|
||||||
out dx, al
|
out dx, al
|
||||||
|
|
||||||
|
; Let's look at the ELF header.
|
||||||
|
mov bx, 0xf00
|
||||||
|
mov fs, bx
|
||||||
|
cmp [fs:0], dword 0x464c457f ; ELF magic: { 0x7f "ELF" }
|
||||||
|
jne fug
|
||||||
|
|
||||||
|
cmp [fs:24], dword 0x10000 ; Entry should be 0x10000
|
||||||
|
jne fug
|
||||||
|
|
||||||
|
mov ebx, dword [fs:28] ; EBX <- program header table
|
||||||
|
mov ecx, dword [fs:44] ; ECX <- program header count
|
||||||
|
|
||||||
|
; Let's find the BSS and clear it.
|
||||||
|
|
||||||
|
parse_program_header:
|
||||||
|
cmp [fs:ebx], dword 0x1 ; Is Load segment?
|
||||||
|
jne .next
|
||||||
|
|
||||||
|
cmp [fs:ebx+24], dword 0x6 ; Is read+write but not execute?
|
||||||
|
jne .next
|
||||||
|
|
||||||
|
mov edi, [fs:ebx+8] ; EDI <- p_vaddr
|
||||||
|
add edi, [fs:ebx+16] ; skip over 'p_filesz' bytes (leave them intact)
|
||||||
|
|
||||||
|
push ecx
|
||||||
|
|
||||||
|
sub edi, [fs:ebx+16] ; skip over 'p_filesz' bytes (see above)
|
||||||
|
|
||||||
|
; Since we're in 16-bit real mode, create a segment address.
|
||||||
|
mov eax, edi
|
||||||
|
shr eax, 4
|
||||||
|
mov es, ax
|
||||||
|
and edi, 0xf
|
||||||
|
|
||||||
|
mov ecx, [fs:ebx+20] ; ECX <- p_memsz
|
||||||
|
xor al, al
|
||||||
|
rep stosb
|
||||||
|
|
||||||
|
pop ecx
|
||||||
|
|
||||||
|
.next:
|
||||||
|
add ebx, 32
|
||||||
|
loop parse_program_header
|
||||||
|
|
||||||
|
; Okay we're all set to go!
|
||||||
|
|
||||||
|
lets_go:
|
||||||
lgdt [cs:test_gdt_ptr]
|
lgdt [cs:test_gdt_ptr]
|
||||||
|
|
||||||
mov eax, cr0
|
mov eax, cr0
|
||||||
@ -182,7 +233,7 @@ convert_lba_to_chs:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
cur_lba:
|
cur_lba:
|
||||||
dw 9
|
dw 1
|
||||||
sectors_per_track:
|
sectors_per_track:
|
||||||
dw 18
|
dw 18
|
||||||
heads:
|
heads:
|
||||||
|
@ -23,13 +23,6 @@ HashTable<Inode*>& all_inodes()
|
|||||||
return *s_inode_set;
|
return *s_inode_set;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FS::initialize_globals()
|
|
||||||
{
|
|
||||||
s_lastFileSystemID = 0;
|
|
||||||
s_fs_map = nullptr;
|
|
||||||
s_inode_set = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
FS::FS()
|
FS::FS()
|
||||||
: m_fsid(++s_lastFileSystemID)
|
: m_fsid(++s_lastFileSystemID)
|
||||||
{
|
{
|
||||||
|
@ -23,7 +23,6 @@ class VMObject;
|
|||||||
|
|
||||||
class FS : public Retainable<FS> {
|
class FS : public Retainable<FS> {
|
||||||
public:
|
public:
|
||||||
static void initialize_globals();
|
|
||||||
virtual ~FS();
|
virtual ~FS();
|
||||||
|
|
||||||
unsigned fsid() const { return m_fsid; }
|
unsigned fsid() const { return m_fsid; }
|
||||||
|
@ -12,11 +12,6 @@ PTYMultiplexer& PTYMultiplexer::the()
|
|||||||
return *s_the;
|
return *s_the;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PTYMultiplexer::initialize_statics()
|
|
||||||
{
|
|
||||||
s_the = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
PTYMultiplexer::PTYMultiplexer()
|
PTYMultiplexer::PTYMultiplexer()
|
||||||
: CharacterDevice(5, 2)
|
: CharacterDevice(5, 2)
|
||||||
{
|
{
|
||||||
|
@ -13,7 +13,6 @@ public:
|
|||||||
virtual ~PTYMultiplexer() override;
|
virtual ~PTYMultiplexer() override;
|
||||||
|
|
||||||
static PTYMultiplexer& the();
|
static PTYMultiplexer& the();
|
||||||
static void initialize_statics();
|
|
||||||
|
|
||||||
// ^CharacterDevice
|
// ^CharacterDevice
|
||||||
virtual RetainPtr<FileDescriptor> open(int& error, int options) override;
|
virtual RetainPtr<FileDescriptor> open(int& error, int options) override;
|
||||||
|
@ -12,11 +12,6 @@
|
|||||||
|
|
||||||
void Process::initialize_gui_statics()
|
void Process::initialize_gui_statics()
|
||||||
{
|
{
|
||||||
Font::initialize();
|
|
||||||
WSMessageLoop::initialize();
|
|
||||||
WSWindowManager::initialize();
|
|
||||||
WSScreen::initialize();
|
|
||||||
|
|
||||||
new WSMessageLoop;
|
new WSMessageLoop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,12 +19,6 @@ VFS& VFS::the()
|
|||||||
return *s_the;
|
return *s_the;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VFS::initialize_globals()
|
|
||||||
{
|
|
||||||
s_the = nullptr;
|
|
||||||
FS::initialize_globals();
|
|
||||||
}
|
|
||||||
|
|
||||||
VFS::VFS()
|
VFS::VFS()
|
||||||
{
|
{
|
||||||
#ifdef VFS_DEBUG
|
#ifdef VFS_DEBUG
|
||||||
|
@ -39,8 +39,6 @@ class VFS;
|
|||||||
class VFS {
|
class VFS {
|
||||||
AK_MAKE_ETERNAL
|
AK_MAKE_ETERNAL
|
||||||
public:
|
public:
|
||||||
static void initialize_globals();
|
|
||||||
|
|
||||||
class Mount {
|
class Mount {
|
||||||
public:
|
public:
|
||||||
Mount(InodeIdentifier host, RetainPtr<FS>&&);
|
Mount(InodeIdentifier host, RetainPtr<FS>&&);
|
||||||
|
@ -151,8 +151,6 @@ void init()
|
|||||||
gdt_init();
|
gdt_init();
|
||||||
idt_init();
|
idt_init();
|
||||||
|
|
||||||
PTYMultiplexer::initialize_statics();
|
|
||||||
VFS::initialize_globals();
|
|
||||||
vfs = new VFS;
|
vfs = new VFS;
|
||||||
|
|
||||||
keyboard = new Keyboard;
|
keyboard = new Keyboard;
|
||||||
@ -169,10 +167,6 @@ void init()
|
|||||||
kprintf("Starting Serenity Operating System...\n");
|
kprintf("Starting Serenity Operating System...\n");
|
||||||
|
|
||||||
MemoryManager::initialize();
|
MemoryManager::initialize();
|
||||||
|
|
||||||
StringImpl::initialize_globals();
|
|
||||||
BochsVGADevice::initialize_statics();
|
|
||||||
|
|
||||||
PIT::initialize();
|
PIT::initialize();
|
||||||
|
|
||||||
memset(&system, 0, sizeof(system));
|
memset(&system, 0, sizeof(system));
|
||||||
|
@ -18,8 +18,6 @@ extern "C" int _start()
|
|||||||
__stdio_init();
|
__stdio_init();
|
||||||
__malloc_init();
|
__malloc_init();
|
||||||
|
|
||||||
StringImpl::initialize_globals();
|
|
||||||
|
|
||||||
int status = 254;
|
int status = 254;
|
||||||
int argc;
|
int argc;
|
||||||
char** argv;
|
char** argv;
|
||||||
|
@ -50,12 +50,6 @@ static inline constexpr size_t font_file_size(unsigned glyph_height)
|
|||||||
return sizeof(FontFileHeader) + 256 * sizeof(dword) * glyph_height;
|
return sizeof(FontFileHeader) + 256 * sizeof(dword) * glyph_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Font::initialize()
|
|
||||||
{
|
|
||||||
s_default_font = nullptr;
|
|
||||||
s_default_bold_font = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
Font& Font::default_font()
|
Font& Font::default_font()
|
||||||
{
|
{
|
||||||
static const char* default_font_path = "/res/fonts/LizaRegular8x10.font";
|
static const char* default_font_path = "/res/fonts/LizaRegular8x10.font";
|
||||||
|
@ -62,8 +62,6 @@ public:
|
|||||||
String name() const { return m_name; }
|
String name() const { return m_name; }
|
||||||
void set_name(const String& name) { m_name = name; }
|
void set_name(const String& name) { m_name = name; }
|
||||||
|
|
||||||
static void initialize();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Font(const String& name, unsigned* rows, byte glyph_width, byte glyph_height);
|
Font(const String& name, unsigned* rows, byte glyph_width, byte glyph_height);
|
||||||
|
|
||||||
|
@ -12,11 +12,6 @@
|
|||||||
|
|
||||||
static WSMessageLoop* s_the;
|
static WSMessageLoop* s_the;
|
||||||
|
|
||||||
void WSMessageLoop::initialize()
|
|
||||||
{
|
|
||||||
s_the = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
WSMessageLoop::WSMessageLoop()
|
WSMessageLoop::WSMessageLoop()
|
||||||
{
|
{
|
||||||
if (!s_the)
|
if (!s_the)
|
||||||
|
@ -19,8 +19,6 @@ public:
|
|||||||
|
|
||||||
static WSMessageLoop& the();
|
static WSMessageLoop& the();
|
||||||
|
|
||||||
static void initialize();
|
|
||||||
|
|
||||||
bool running() const { return m_running; }
|
bool running() const { return m_running; }
|
||||||
Process& server_process() { return *m_server_process; }
|
Process& server_process() { return *m_server_process; }
|
||||||
|
|
||||||
|
@ -7,11 +7,6 @@
|
|||||||
|
|
||||||
static WSScreen* s_the;
|
static WSScreen* s_the;
|
||||||
|
|
||||||
void WSScreen::initialize()
|
|
||||||
{
|
|
||||||
s_the = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
WSScreen& WSScreen::the()
|
WSScreen& WSScreen::the()
|
||||||
{
|
{
|
||||||
ASSERT(s_the);
|
ASSERT(s_the);
|
||||||
|
@ -21,8 +21,6 @@ public:
|
|||||||
Size size() const { return { width(), height() }; }
|
Size size() const { return { width(), height() }; }
|
||||||
Rect rect() const { return { 0, 0, width(), height() }; }
|
Rect rect() const { return { 0, 0, width(), height() }; }
|
||||||
|
|
||||||
static void initialize();
|
|
||||||
|
|
||||||
Point cursor_location() const { return m_cursor_location; }
|
Point cursor_location() const { return m_cursor_location; }
|
||||||
bool left_mouse_button_pressed() const { return m_left_mouse_button_pressed; }
|
bool left_mouse_button_pressed() const { return m_left_mouse_button_pressed; }
|
||||||
bool right_mouse_button_pressed() const { return m_right_mouse_button_pressed; }
|
bool right_mouse_button_pressed() const { return m_right_mouse_button_pressed; }
|
||||||
|
@ -75,11 +75,6 @@ WSWindowManager& WSWindowManager::the()
|
|||||||
return *s_the;
|
return *s_the;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WSWindowManager::initialize()
|
|
||||||
{
|
|
||||||
s_the = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char* cursor_bitmap_inner_ascii = {
|
static const char* cursor_bitmap_inner_ascii = {
|
||||||
" # "
|
" # "
|
||||||
" ## "
|
" ## "
|
||||||
|
@ -29,8 +29,6 @@ public:
|
|||||||
|
|
||||||
void move_to_front(WSWindow&);
|
void move_to_front(WSWindow&);
|
||||||
|
|
||||||
static void initialize();
|
|
||||||
|
|
||||||
void draw_cursor();
|
void draw_cursor();
|
||||||
|
|
||||||
void invalidate(const WSWindow&);
|
void invalidate(const WSWindow&);
|
||||||
|
Loading…
Reference in New Issue
Block a user