Compare commits
3 Commits
18e7cf2069
...
45ffa1b79c
Author | SHA1 | Date |
---|---|---|
Bananymous | 45ffa1b79c | |
Bananymous | f37e1c2229 | |
Bananymous | 1bd7b86e60 |
14
README.md
14
README.md
|
@ -18,8 +18,12 @@ You can find a live demo [here](https://bananymous.com/banan-os)
|
||||||
- [x] Network stack
|
- [x] Network stack
|
||||||
- [x] ELF executable loading
|
- [x] ELF executable loading
|
||||||
- [x] AML interpreter (partial)
|
- [x] AML interpreter (partial)
|
||||||
|
- [x] Basic graphical environment
|
||||||
|
- [x] Terminal emulator
|
||||||
|
- [ ] Task bar
|
||||||
|
- [ ] Program launcher
|
||||||
|
- [ ] Some nice apps
|
||||||
- [ ] ELF dynamic linking
|
- [ ] ELF dynamic linking
|
||||||
- [ ] Graphical desktop
|
|
||||||
- [ ] copy-on-write memory
|
- [ ] copy-on-write memory
|
||||||
|
|
||||||
#### Drivers
|
#### Drivers
|
||||||
|
@ -28,7 +32,12 @@ You can find a live demo [here](https://bananymous.com/banan-os)
|
||||||
- [x] E1000 and E1000E NICs
|
- [x] E1000 and E1000E NICs
|
||||||
- [x] PS2 keyboard (all scancode sets)
|
- [x] PS2 keyboard (all scancode sets)
|
||||||
- [x] PS2 mouse
|
- [x] PS2 mouse
|
||||||
- [ ] USB
|
- [x] USB
|
||||||
|
- [x] Keyboard
|
||||||
|
- [x] Mouse
|
||||||
|
- [ ] Hubs
|
||||||
|
- [ ] Mass storage
|
||||||
|
- [ ] ...
|
||||||
- [ ] virtio devices (network, storage)
|
- [ ] virtio devices (network, storage)
|
||||||
|
|
||||||
#### Network
|
#### Network
|
||||||
|
@ -38,6 +47,7 @@ You can find a live demo [here](https://bananymous.com/banan-os)
|
||||||
- [x] UDP
|
- [x] UDP
|
||||||
- [x] TCP (partial and buggy)
|
- [x] TCP (partial and buggy)
|
||||||
- [x] Unix domain sockets
|
- [x] Unix domain sockets
|
||||||
|
- [ ] SSL
|
||||||
|
|
||||||
#### Filesystems
|
#### Filesystems
|
||||||
- [x] Virtual filesystem
|
- [x] Virtual filesystem
|
||||||
|
|
|
@ -9,6 +9,9 @@ extern uint8_t g_kernel_end[];
|
||||||
extern uint8_t g_kernel_execute_start[];
|
extern uint8_t g_kernel_execute_start[];
|
||||||
extern uint8_t g_kernel_execute_end[];
|
extern uint8_t g_kernel_execute_end[];
|
||||||
|
|
||||||
|
extern uint8_t g_kernel_writable_start[];
|
||||||
|
extern uint8_t g_kernel_writable_end[];
|
||||||
|
|
||||||
extern uint8_t g_userspace_start[];
|
extern uint8_t g_userspace_start[];
|
||||||
extern uint8_t g_userspace_end[];
|
extern uint8_t g_userspace_end[];
|
||||||
|
|
||||||
|
@ -148,7 +151,7 @@ namespace Kernel
|
||||||
V2P(g_kernel_start),
|
V2P(g_kernel_start),
|
||||||
(vaddr_t)g_kernel_start,
|
(vaddr_t)g_kernel_start,
|
||||||
g_kernel_end - g_kernel_start,
|
g_kernel_end - g_kernel_start,
|
||||||
Flags::ReadWrite | Flags::Present
|
Flags::Present
|
||||||
);
|
);
|
||||||
|
|
||||||
// Map executable kernel memory as executable
|
// Map executable kernel memory as executable
|
||||||
|
@ -159,6 +162,14 @@ namespace Kernel
|
||||||
Flags::Execute | Flags::Present
|
Flags::Execute | Flags::Present
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Map writable kernel memory as writable
|
||||||
|
map_range_at(
|
||||||
|
V2P(g_kernel_writable_start),
|
||||||
|
(vaddr_t)g_kernel_writable_start,
|
||||||
|
g_kernel_writable_end - g_kernel_writable_start,
|
||||||
|
Flags::ReadWrite | Flags::Present
|
||||||
|
);
|
||||||
|
|
||||||
// Map userspace memory
|
// Map userspace memory
|
||||||
map_range_at(
|
map_range_at(
|
||||||
V2P(g_userspace_start),
|
V2P(g_userspace_start),
|
||||||
|
|
|
@ -34,12 +34,14 @@ SECTIONS
|
||||||
}
|
}
|
||||||
.data ALIGN(4K) : AT(ADDR(.data) - KERNEL_OFFSET)
|
.data ALIGN(4K) : AT(ADDR(.data) - KERNEL_OFFSET)
|
||||||
{
|
{
|
||||||
|
g_kernel_writable_start = .;
|
||||||
*(.data)
|
*(.data)
|
||||||
}
|
}
|
||||||
.bss ALIGN(4K) : AT(ADDR(.bss) - KERNEL_OFFSET)
|
.bss ALIGN(4K) : AT(ADDR(.bss) - KERNEL_OFFSET)
|
||||||
{
|
{
|
||||||
*(COMMON)
|
*(COMMON)
|
||||||
*(.bss)
|
*(.bss)
|
||||||
|
g_kernel_writable_end = .;
|
||||||
}
|
}
|
||||||
g_kernel_end = .;
|
g_kernel_end = .;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,9 @@ extern uint8_t g_kernel_end[];
|
||||||
extern uint8_t g_kernel_execute_start[];
|
extern uint8_t g_kernel_execute_start[];
|
||||||
extern uint8_t g_kernel_execute_end[];
|
extern uint8_t g_kernel_execute_end[];
|
||||||
|
|
||||||
|
extern uint8_t g_kernel_writable_start[];
|
||||||
|
extern uint8_t g_kernel_writable_end[];
|
||||||
|
|
||||||
extern uint8_t g_userspace_start[];
|
extern uint8_t g_userspace_start[];
|
||||||
extern uint8_t g_userspace_end[];
|
extern uint8_t g_userspace_end[];
|
||||||
|
|
||||||
|
@ -170,7 +173,7 @@ namespace Kernel
|
||||||
V2P(g_kernel_start),
|
V2P(g_kernel_start),
|
||||||
(vaddr_t)g_kernel_start,
|
(vaddr_t)g_kernel_start,
|
||||||
g_kernel_end - g_kernel_start,
|
g_kernel_end - g_kernel_start,
|
||||||
Flags::ReadWrite | Flags::Present
|
Flags::Present
|
||||||
);
|
);
|
||||||
|
|
||||||
// Map executable kernel memory as executable
|
// Map executable kernel memory as executable
|
||||||
|
@ -181,6 +184,14 @@ namespace Kernel
|
||||||
Flags::Execute | Flags::Present
|
Flags::Execute | Flags::Present
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Map writable kernel memory as writable
|
||||||
|
map_range_at(
|
||||||
|
V2P(g_kernel_writable_start),
|
||||||
|
(vaddr_t)g_kernel_writable_start,
|
||||||
|
g_kernel_writable_end - g_kernel_writable_start,
|
||||||
|
Flags::ReadWrite | Flags::Present
|
||||||
|
);
|
||||||
|
|
||||||
// Map userspace memory
|
// Map userspace memory
|
||||||
map_range_at(
|
map_range_at(
|
||||||
V2P(g_userspace_start),
|
V2P(g_userspace_start),
|
||||||
|
|
|
@ -34,12 +34,14 @@ SECTIONS
|
||||||
}
|
}
|
||||||
.data ALIGN(4K) : AT(ADDR(.data) - KERNEL_OFFSET)
|
.data ALIGN(4K) : AT(ADDR(.data) - KERNEL_OFFSET)
|
||||||
{
|
{
|
||||||
|
g_kernel_writable_start = .;
|
||||||
*(.data)
|
*(.data)
|
||||||
}
|
}
|
||||||
.bss ALIGN(4K) : AT(ADDR(.bss) - KERNEL_OFFSET)
|
.bss ALIGN(4K) : AT(ADDR(.bss) - KERNEL_OFFSET)
|
||||||
{
|
{
|
||||||
*(COMMON)
|
*(COMMON)
|
||||||
*(.bss)
|
*(.bss)
|
||||||
|
g_kernel_writable_end = .;
|
||||||
}
|
}
|
||||||
g_kernel_end = .;
|
g_kernel_end = .;
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,6 +91,13 @@ void Terminal::run()
|
||||||
|
|
||||||
m_font = MUST(LibFont::Font::load("/usr/share/fonts/lat0-16.psfu"_sv));
|
m_font = MUST(LibFont::Font::load("/usr/share/fonts/lat0-16.psfu"_sv));
|
||||||
|
|
||||||
|
{
|
||||||
|
timespec ts;
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
|
m_cursor_blink_shown = true;
|
||||||
|
m_cursor_blink_ms = ts.tv_sec * 1'000 + ts.tv_nsec / 1'000'000;
|
||||||
|
}
|
||||||
|
|
||||||
MUST(m_cursor_buffer.resize(m_font.width() * m_font.height(), m_bg_color));
|
MUST(m_cursor_buffer.resize(m_font.width() * m_font.height(), m_bg_color));
|
||||||
show_cursor();
|
show_cursor();
|
||||||
|
|
||||||
|
@ -104,13 +111,35 @@ void Terminal::run()
|
||||||
FD_SET(m_shell_info.pts_master, &fds);
|
FD_SET(m_shell_info.pts_master, &fds);
|
||||||
FD_SET(m_window->server_fd(), &fds);
|
FD_SET(m_window->server_fd(), &fds);
|
||||||
|
|
||||||
select(max_fd + 1, &fds, nullptr, nullptr, nullptr);
|
timespec ts;
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
|
const uint64_t current_ms = ts.tv_sec * 1'000 + ts.tv_nsec / 1'000'000;
|
||||||
|
|
||||||
|
const uint64_t ms_until_blink = 500 - BAN::Math::min<uint64_t>(current_ms - m_cursor_blink_ms, 500);
|
||||||
|
|
||||||
|
timeval timeout;
|
||||||
|
timeout.tv_sec = ms_until_blink / 1'000;
|
||||||
|
timeout.tv_usec = ms_until_blink * 1'000;
|
||||||
|
if (select(max_fd + 1, &fds, nullptr, nullptr, &timeout) == 0)
|
||||||
|
{
|
||||||
|
m_cursor_blink_shown = !m_cursor_blink_shown;
|
||||||
|
m_cursor_blink_ms = current_ms + ms_until_blink;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_got_key_event = false;
|
||||||
|
|
||||||
|
hide_cursor();
|
||||||
if (FD_ISSET(m_shell_info.pts_master, &fds))
|
if (FD_ISSET(m_shell_info.pts_master, &fds))
|
||||||
if (!read_shell())
|
if (!read_shell())
|
||||||
break;
|
break;
|
||||||
if (FD_ISSET(m_window->server_fd(), &fds))
|
if (FD_ISSET(m_window->server_fd(), &fds))
|
||||||
m_window->poll_events();
|
m_window->poll_events();
|
||||||
|
if (m_got_key_event)
|
||||||
|
{
|
||||||
|
m_cursor_blink_shown = true;
|
||||||
|
m_cursor_blink_ms = current_ms;
|
||||||
|
}
|
||||||
|
show_cursor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +160,7 @@ void Terminal::show_cursor()
|
||||||
for (uint32_t y = 0; y < m_font.height(); y++)
|
for (uint32_t y = 0; y < m_font.height(); y++)
|
||||||
for (uint32_t x = 0; x < m_font.width(); x++)
|
for (uint32_t x = 0; x < m_font.width(); x++)
|
||||||
m_cursor_buffer[y * m_font.width() + x] = m_window->get_pixel(cursor_base_x + x, cursor_base_y + y);
|
m_cursor_buffer[y * m_font.width() + x] = m_window->get_pixel(cursor_base_x + x, cursor_base_y + y);
|
||||||
if (m_cursor_shown)
|
if (m_cursor_shown && m_cursor_blink_shown)
|
||||||
{
|
{
|
||||||
for (uint32_t y = m_font.height() * 13 / 16; y < m_font.height() - 1; y++)
|
for (uint32_t y = m_font.height() * 13 / 16; y < m_font.height() - 1; y++)
|
||||||
for (uint32_t x = 0; x < m_font.width(); x++)
|
for (uint32_t x = 0; x < m_font.width(); x++)
|
||||||
|
@ -142,8 +171,6 @@ void Terminal::show_cursor()
|
||||||
|
|
||||||
bool Terminal::read_shell()
|
bool Terminal::read_shell()
|
||||||
{
|
{
|
||||||
hide_cursor();
|
|
||||||
|
|
||||||
char buffer[128];
|
char buffer[128];
|
||||||
ssize_t nread = read(m_shell_info.pts_master, buffer, sizeof(buffer) - 1);
|
ssize_t nread = read(m_shell_info.pts_master, buffer, sizeof(buffer) - 1);
|
||||||
if (nread < 0)
|
if (nread < 0)
|
||||||
|
@ -152,9 +179,6 @@ bool Terminal::read_shell()
|
||||||
return false;
|
return false;
|
||||||
for (ssize_t i = 0; i < nread; i++)
|
for (ssize_t i = 0; i < nread; i++)
|
||||||
putchar(buffer[i]);
|
putchar(buffer[i]);
|
||||||
|
|
||||||
show_cursor();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -450,4 +474,5 @@ void Terminal::on_key_event(LibGUI::EventPacket::KeyEvent event)
|
||||||
return;
|
return;
|
||||||
if (const char* text = LibInput::key_to_utf8_ansi(event.key, event.modifier))
|
if (const char* text = LibInput::key_to_utf8_ansi(event.key, event.modifier))
|
||||||
write(m_shell_info.pts_master, text, strlen(text));
|
write(m_shell_info.pts_master, text, strlen(text));
|
||||||
|
m_got_key_event = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,8 +60,11 @@ private:
|
||||||
CSIInfo m_csi_info;
|
CSIInfo m_csi_info;
|
||||||
|
|
||||||
bool m_cursor_shown { true };
|
bool m_cursor_shown { true };
|
||||||
|
bool m_cursor_blink_shown { true };
|
||||||
|
uint64_t m_cursor_blink_ms { 0 };
|
||||||
Cursor m_cursor { 0, 0 };
|
Cursor m_cursor { 0, 0 };
|
||||||
BAN::Vector<uint32_t> m_cursor_buffer;
|
BAN::Vector<uint32_t> m_cursor_buffer;
|
||||||
|
bool m_got_key_event { false };
|
||||||
|
|
||||||
uint8_t m_utf8_index { 0 };
|
uint8_t m_utf8_index { 0 };
|
||||||
uint8_t m_utf8_bytes[4] { };
|
uint8_t m_utf8_bytes[4] { };
|
||||||
|
|
Loading…
Reference in New Issue