fix(baremetal,net): fix bare-metal boot freezes and implement real internet stack
- Zero user PML4 and allocated page tables in VMM to prevent dirty RAM crash on real hardware - Probe UART existence and add timeout to prevent infinite freeze on motherboards without COM1 - Clamp SMP AP boot to MAX_CPUS to prevent GDT/TSS corruption on multi-core CPUs - Add kernel early framebuffer console (FbConsole) with 8x16 font for direct HDMI/DP screen output - Configure Limine resolution and dynamic 4K draw buffers in gui_server to fix 1080p black screen - Implement RFC 793 TCP pseudo-header checksum and full TCP 3-way handshake - Implement DHCP client (UDP 67/68) and DNS client (UDP 53) - Add dns, dhcp commands to shell and update web browser with live URL loading
This commit is contained in:
+23
-32
@@ -46,10 +46,11 @@ static lv_indev_t *g_mouse_indev = NULL;
|
||||
static lv_indev_t *g_kbd_indev = NULL;
|
||||
static lv_group_t *g_input_group = NULL;
|
||||
|
||||
// Double-buffering: 200-row raster bands for high-speed full-band flush (4 sweeps for 1280x800)
|
||||
#define BUF_HEIGHT 200
|
||||
static lv_color_t g_buf1[1280 * BUF_HEIGHT];
|
||||
static lv_color_t g_buf2[1280 * BUF_HEIGHT];
|
||||
// Double-buffering: dynamically scaled raster bands up to 4K (3840x2160)
|
||||
#define MAX_HOR_RES 3840
|
||||
#define BUF_HEIGHT 100
|
||||
static lv_color_t g_buf1[MAX_HOR_RES * BUF_HEIGHT];
|
||||
static lv_color_t g_buf2[MAX_HOR_RES * BUF_HEIGHT];
|
||||
static lv_disp_draw_buf_t g_draw_buf;
|
||||
|
||||
// 16x24 High-Contrast Arrow Cursor Bitmap
|
||||
@@ -275,9 +276,9 @@ static void win_drag_event_cb(lv_event_t *e) {
|
||||
|
||||
// Keep window inside screen bounds
|
||||
if (x < 0) x = 0;
|
||||
if (x > 1280 - 100) x = 1280 - 100;
|
||||
if (x > (lv_coord_t)g_fb.width - 100) x = (lv_coord_t)g_fb.width - 100;
|
||||
if (y < 0) y = 0;
|
||||
if (y > 800 - 80) y = 800 - 80;
|
||||
if (y > (lv_coord_t)g_fb.height - 80) y = (lv_coord_t)g_fb.height - 80;
|
||||
|
||||
lv_obj_set_pos(win, x, y);
|
||||
}
|
||||
@@ -623,37 +624,25 @@ static void ping_btn_event_cb(lv_event_t *e) {
|
||||
static void browser_go_event_cb(lv_event_t *e) {
|
||||
(void)e;
|
||||
const char *url = lv_textarea_get_text(g_ta_browser_url);
|
||||
if (!url || !*url) url = "http://10.0.2.2/index.html";
|
||||
|
||||
char buf[128];
|
||||
snprintf(buf, sizeof(buf), "Connecting to %s...", url ? url : "10.0.2.2");
|
||||
snprintf(buf, sizeof(buf), "Connecting to %s...", url);
|
||||
lv_label_set_text(g_lbl_browser_status, buf);
|
||||
|
||||
char body[1500];
|
||||
char body[2048];
|
||||
memset(body, 0, sizeof(body));
|
||||
|
||||
uint32_t target_ip = g_net_cfg.gateway;
|
||||
uint16_t port = 80;
|
||||
const char *path = "/";
|
||||
|
||||
if (url && *url) {
|
||||
const char *p = url;
|
||||
if (strncmp(p, "http://", 7) == 0) p += 7;
|
||||
char host[64] = {0};
|
||||
int hi = 0;
|
||||
while (*p && *p != '/' && *p != ':' && hi < 63) {
|
||||
host[hi++] = *p++;
|
||||
}
|
||||
if (*host) target_ip = parse_ip(host);
|
||||
if (*p == '/') path = p;
|
||||
}
|
||||
|
||||
int res = net_http_get(target_ip, port, path, body, sizeof(body));
|
||||
int res = net_http_get_url(url, body, sizeof(body));
|
||||
if (res == 200) {
|
||||
lv_label_set_text(g_lbl_browser_status, "HTTP/1.1 200 OK | TCP Connected (10.0.2.15 -> Gateway:80)");
|
||||
char st[128];
|
||||
snprintf(st, sizeof(st), "HTTP/1.1 200 OK | TCP Connected (%s)", url);
|
||||
lv_label_set_text(g_lbl_browser_status, st);
|
||||
lv_textarea_set_text(g_txt_browser_content, body);
|
||||
show_desktop_toast("Web Browser", "Webpage loaded successfully over TCP/IPv4!");
|
||||
show_desktop_toast("Web Browser", "Live webpage loaded successfully!");
|
||||
} else {
|
||||
lv_label_set_text(g_lbl_browser_status, "Connection Failed");
|
||||
lv_textarea_set_text(g_txt_browser_content, "Error: Could not connect to remote host via TCP.\nCheck network status in Network Center.");
|
||||
lv_label_set_text(g_lbl_browser_status, "Connection Failed / Timeout");
|
||||
lv_textarea_set_text(g_txt_browser_content, body[0] ? body : "Error: Could not connect to remote host via TCP.\nCheck DNS/DHCP network status.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -972,7 +961,7 @@ static void create_desktop_environment() {
|
||||
// 6. BOTTOM TASKBAR (Windows / KDE Plasma Style)
|
||||
// =========================================================================
|
||||
lv_obj_t *taskbar = lv_obj_create(scr);
|
||||
lv_obj_set_size(taskbar, 1280, 48);
|
||||
lv_obj_set_size(taskbar, g_fb.width, 48);
|
||||
lv_obj_align(taskbar, LV_ALIGN_BOTTOM_MID, 0, 0);
|
||||
lv_obj_set_style_bg_color(taskbar, lv_color_hex(0x141824), 0);
|
||||
lv_obj_set_style_border_color(taskbar, lv_color_hex(0x2a3447), 0);
|
||||
@@ -1273,8 +1262,10 @@ int main() {
|
||||
net_init();
|
||||
printf("[GUI-SERVER] net_init() OK.\n");
|
||||
|
||||
// 3. Register Framebuffer Display Driver (Double-buffered with 200 rows)
|
||||
lv_disp_draw_buf_init(&g_draw_buf, g_buf1, g_buf2, 1280 * BUF_HEIGHT);
|
||||
// 3. Register Framebuffer Display Driver (Double-buffered with dynamically scaled rows)
|
||||
uint32_t buf_pixels = (uint32_t)g_fb.width * BUF_HEIGHT;
|
||||
if (buf_pixels > MAX_HOR_RES * BUF_HEIGHT) buf_pixels = MAX_HOR_RES * BUF_HEIGHT;
|
||||
lv_disp_draw_buf_init(&g_draw_buf, g_buf1, g_buf2, buf_pixels);
|
||||
lv_disp_drv_init(&g_disp_drv);
|
||||
g_disp_drv.hor_res = (lv_coord_t)g_fb.width;
|
||||
g_disp_drv.ver_res = (lv_coord_t)g_fb.height;
|
||||
|
||||
+44
-21
@@ -317,32 +317,51 @@ static void cmd_modules() {
|
||||
}
|
||||
|
||||
static void cmd_curl(const char *target) {
|
||||
char body[1024];
|
||||
memset(body, 0, sizeof(body));
|
||||
uint32_t ip = g_net_cfg.gateway;
|
||||
uint16_t port = 80;
|
||||
const char *path = "/";
|
||||
|
||||
if (target && *target) {
|
||||
if (strncmp(target, "http://", 7) == 0) target += 7;
|
||||
char host[64] = {0};
|
||||
int hi = 0;
|
||||
while (*target && *target != '/' && *target != ':' && hi < 63) {
|
||||
host[hi++] = *target++;
|
||||
}
|
||||
if (*host) ip = parse_ip(host);
|
||||
if (*target == '/') path = target;
|
||||
if (!target || !*target) {
|
||||
puts("Usage: curl <http://domain-or-ip/path>");
|
||||
return;
|
||||
}
|
||||
char body[2048];
|
||||
memset(body, 0, sizeof(body));
|
||||
|
||||
char ip_str[32];
|
||||
format_ip(ip, ip_str);
|
||||
printf("[curl] Connecting to %s:%u (Path: %s) via TCP/IPv4...\n", ip_str, port, path);
|
||||
int status = net_http_get(ip, port, path, body, sizeof(body));
|
||||
printf("[curl] Fetching '%s' over TCP/IPv4...\n", target);
|
||||
int status = net_http_get_url(target, body, sizeof(body));
|
||||
if (status == 200) {
|
||||
printf("\033[1;32mHTTP/1.1 200 OK\033[0m (TCP Connected)\n\n");
|
||||
printf("\033[1;32mHTTP/1.1 200 OK\033[0m (Bytes read: %d)\n\n", (int)strlen(body));
|
||||
puts(body);
|
||||
} else {
|
||||
printf("[curl] Connection to %s:%u failed.\n", ip_str, port);
|
||||
printf("[curl] HTTP request returned status %d\n", status);
|
||||
if (*body) puts(body);
|
||||
}
|
||||
}
|
||||
|
||||
static void cmd_dns(const char *domain) {
|
||||
if (!domain || !*domain) {
|
||||
puts("Usage: dns <hostname> (e.g. dns httpbin.org)");
|
||||
return;
|
||||
}
|
||||
printf("[dns] Querying DNS nameserver for '%s' (UDP port 53)...\n", domain);
|
||||
uint32_t ip = 0;
|
||||
if (net_dns_resolve(domain, &ip) == 0) {
|
||||
char ip_str[32];
|
||||
format_ip(ip, ip_str);
|
||||
printf(" \033[1;32m%s\033[0m has address \033[1;36m%s\033[0m\n", domain, ip_str);
|
||||
} else {
|
||||
printf("[dns] Host '%s' not found (NXDOMAIN / timeout)\n", domain);
|
||||
}
|
||||
}
|
||||
|
||||
static void cmd_dhcp() {
|
||||
puts("[dhcp] Broadcasting DHCPDISCOVER (UDP 68 -> 67)...");
|
||||
if (net_dhcp_discover() == 0) {
|
||||
char ip[32], gw[32], dns[32];
|
||||
format_ip(g_net_cfg.ip, ip);
|
||||
format_ip(g_net_cfg.gateway, gw);
|
||||
format_ip(g_net_cfg.dns_server, dns);
|
||||
printf("\033[1;32m[dhcp] Lease acquired successfully!\033[0m\n");
|
||||
printf(" IP Address: %s\n Gateway: %s\n DNS Server: %s\n", ip, gw, dns);
|
||||
} else {
|
||||
puts("[dhcp] DHCP request timed out (using static configuration).");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -839,6 +858,10 @@ static void handle_command(char *cmd) {
|
||||
cmd_curl(cmd + 5);
|
||||
} else if (strncmp(cmd, "fetch ", 6) == 0) {
|
||||
cmd_curl(cmd + 6);
|
||||
} else if (strncmp(cmd, "dns ", 4) == 0) {
|
||||
cmd_dns(cmd + 4);
|
||||
} else if (strcmp(cmd, "dhcp") == 0) {
|
||||
cmd_dhcp();
|
||||
} else if (strcmp(cmd, "fastfetch") == 0 || strcmp(cmd, "neofetch") == 0) {
|
||||
print_fastfetch();
|
||||
} else if (strcmp(cmd, "clear") == 0) {
|
||||
|
||||
Reference in New Issue
Block a user