Compare commits

..

3 Commits

Author SHA1 Message Date
Bananymous 45ffa1b79c General: Update README feature list
README did not contain anything about GUI or USB which I have had for
maybe a month now :D
2024-08-12 15:14:04 +03:00
Bananymous f37e1c2229 Kernel: Map .rodata as read only instead of read-write 2024-08-12 14:28:52 +03:00
Bananymous 1bd7b86e60 Terminal: Implement cursor blinking
This looks much nicer than the old static cursor
2024-08-12 14:24:17 +03:00
7 changed files with 75 additions and 11 deletions

View File

@ -18,8 +18,12 @@ You can find a live demo [here](https://bananymous.com/banan-os)
- [x] Network stack
- [x] ELF executable loading
- [x] AML interpreter (partial)
- [x] Basic graphical environment
- [x] Terminal emulator
- [ ] Task bar
- [ ] Program launcher
- [ ] Some nice apps
- [ ] ELF dynamic linking
- [ ] Graphical desktop
- [ ] copy-on-write memory
#### Drivers
@ -28,7 +32,12 @@ You can find a live demo [here](https://bananymous.com/banan-os)
- [x] E1000 and E1000E NICs
- [x] PS2 keyboard (all scancode sets)
- [x] PS2 mouse
- [ ] USB
- [x] USB
- [x] Keyboard
- [x] Mouse
- [ ] Hubs
- [ ] Mass storage
- [ ] ...
- [ ] virtio devices (network, storage)
#### Network
@ -38,6 +47,7 @@ You can find a live demo [here](https://bananymous.com/banan-os)
- [x] UDP
- [x] TCP (partial and buggy)
- [x] Unix domain sockets
- [ ] SSL
#### Filesystems
- [x] Virtual filesystem

View File

@ -9,6 +9,9 @@ extern uint8_t g_kernel_end[];
extern uint8_t g_kernel_execute_start[];
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_end[];
@ -148,7 +151,7 @@ namespace Kernel
V2P(g_kernel_start),
(vaddr_t)g_kernel_start,
g_kernel_end - g_kernel_start,
Flags::ReadWrite | Flags::Present
Flags::Present
);
// Map executable kernel memory as executable
@ -159,6 +162,14 @@ namespace Kernel
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_range_at(
V2P(g_userspace_start),

View File

@ -34,12 +34,14 @@ SECTIONS
}
.data ALIGN(4K) : AT(ADDR(.data) - KERNEL_OFFSET)
{
g_kernel_writable_start = .;
*(.data)
}
.bss ALIGN(4K) : AT(ADDR(.bss) - KERNEL_OFFSET)
{
*(COMMON)
*(.bss)
g_kernel_writable_end = .;
}
g_kernel_end = .;
}

View File

@ -11,6 +11,9 @@ extern uint8_t g_kernel_end[];
extern uint8_t g_kernel_execute_start[];
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_end[];
@ -170,7 +173,7 @@ namespace Kernel
V2P(g_kernel_start),
(vaddr_t)g_kernel_start,
g_kernel_end - g_kernel_start,
Flags::ReadWrite | Flags::Present
Flags::Present
);
// Map executable kernel memory as executable
@ -181,6 +184,14 @@ namespace Kernel
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_range_at(
V2P(g_userspace_start),

View File

@ -34,12 +34,14 @@ SECTIONS
}
.data ALIGN(4K) : AT(ADDR(.data) - KERNEL_OFFSET)
{
g_kernel_writable_start = .;
*(.data)
}
.bss ALIGN(4K) : AT(ADDR(.bss) - KERNEL_OFFSET)
{
*(COMMON)
*(.bss)
g_kernel_writable_end = .;
}
g_kernel_end = .;
}

View File

@ -91,6 +91,13 @@ void Terminal::run()
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));
show_cursor();
@ -104,13 +111,35 @@ void Terminal::run()
FD_SET(m_shell_info.pts_master, &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 (!read_shell())
break;
if (FD_ISSET(m_window->server_fd(), &fds))
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 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);
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 x = 0; x < m_font.width(); x++)
@ -142,8 +171,6 @@ void Terminal::show_cursor()
bool Terminal::read_shell()
{
hide_cursor();
char buffer[128];
ssize_t nread = read(m_shell_info.pts_master, buffer, sizeof(buffer) - 1);
if (nread < 0)
@ -152,9 +179,6 @@ bool Terminal::read_shell()
return false;
for (ssize_t i = 0; i < nread; i++)
putchar(buffer[i]);
show_cursor();
return true;
}
@ -450,4 +474,5 @@ void Terminal::on_key_event(LibGUI::EventPacket::KeyEvent event)
return;
if (const char* text = LibInput::key_to_utf8_ansi(event.key, event.modifier))
write(m_shell_info.pts_master, text, strlen(text));
m_got_key_event = true;
}

View File

@ -60,8 +60,11 @@ private:
CSIInfo m_csi_info;
bool m_cursor_shown { true };
bool m_cursor_blink_shown { true };
uint64_t m_cursor_blink_ms { 0 };
Cursor m_cursor { 0, 0 };
BAN::Vector<uint32_t> m_cursor_buffer;
bool m_got_key_event { false };
uint8_t m_utf8_index { 0 };
uint8_t m_utf8_bytes[4] { };