2022-12-21 08:29:33 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <socks/init.h>
|
2023-12-30 09:09:18 +00:00
|
|
|
#include <socks/arg.h>
|
2023-04-30 21:09:36 +01:00
|
|
|
#include <socks/clock.h>
|
2023-05-10 20:34:53 +01:00
|
|
|
#include <socks/input.h>
|
2023-04-09 16:43:03 +01:00
|
|
|
#include <socks/panic.h>
|
2023-02-26 10:05:39 +00:00
|
|
|
#include <socks/test.h>
|
2023-02-03 20:51:23 +00:00
|
|
|
#include <socks/printk.h>
|
2023-05-10 20:34:53 +01:00
|
|
|
#include <socks/device.h>
|
2023-06-11 14:55:47 +01:00
|
|
|
#include <socks/tty.h>
|
2023-04-08 09:27:21 +01:00
|
|
|
#include <socks/kext.h>
|
2023-03-06 11:08:02 +00:00
|
|
|
#include <socks/object.h>
|
2023-03-06 11:08:26 +00:00
|
|
|
#include <socks/sched.h>
|
2023-12-30 09:09:18 +00:00
|
|
|
#include <socks/libc/stdio.h>
|
2022-12-21 08:29:33 +00:00
|
|
|
#include <socks/machine/init.h>
|
2023-03-18 19:35:00 +00:00
|
|
|
#include <socks/cpu.h>
|
2023-02-04 19:03:45 +00:00
|
|
|
|
2023-06-10 21:41:07 +01:00
|
|
|
#ifdef KEXT_NET_DOORSTUCK_SOCKS_FBCON
|
|
|
|
|
#include <socks/fbcon.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-02-04 19:03:45 +00:00
|
|
|
extern unsigned long get_rflags(void);
|
2022-12-21 08:29:33 +00:00
|
|
|
|
2023-02-05 10:50:13 +00:00
|
|
|
extern char __pstart[], __pend[];
|
|
|
|
|
|
2023-02-04 19:19:48 +00:00
|
|
|
void print_kernel_banner(void)
|
|
|
|
|
{
|
|
|
|
|
printk("Socks kernel version " BUILD_ID);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-10 20:34:53 +01:00
|
|
|
static void hang(void)
|
|
|
|
|
{
|
|
|
|
|
while (1) {
|
2023-12-30 09:09:18 +00:00
|
|
|
printk("%d: tick", this_cpu());
|
2023-05-10 20:34:53 +01:00
|
|
|
milli_sleep(2000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-04 21:43:18 +01:00
|
|
|
void background_thread(void)
|
|
|
|
|
{
|
|
|
|
|
printk("background_thread() running on processor %u", this_cpu());
|
2023-12-30 09:09:18 +00:00
|
|
|
milli_sleep(1000);
|
2023-05-07 12:38:06 +01:00
|
|
|
|
2023-05-04 21:43:18 +01:00
|
|
|
while (1) {
|
2023-12-30 09:09:18 +00:00
|
|
|
printk("%d: tock", this_cpu());
|
2023-05-10 20:34:53 +01:00
|
|
|
milli_sleep(2000);
|
2023-05-04 21:43:18 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-10 20:34:53 +01:00
|
|
|
static void putchar(char c)
|
|
|
|
|
{
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
struct queue *consoles = get_consoles(&flags);
|
|
|
|
|
queue_foreach(struct console, con, consoles, c_list) {
|
|
|
|
|
console_write(con, &c, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
put_consoles(consoles, flags);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-21 08:29:33 +00:00
|
|
|
void kernel_init(uintptr_t arg)
|
|
|
|
|
{
|
2023-02-03 20:24:27 +00:00
|
|
|
ml_init(arg);
|
2023-02-26 10:05:39 +00:00
|
|
|
|
2023-04-09 16:43:03 +01:00
|
|
|
kern_status_t status;
|
|
|
|
|
status = scan_internal_kexts();
|
|
|
|
|
if (status != KERN_OK) {
|
|
|
|
|
panic("scan_internal_kexts() failed with code %s", kern_status_string(status));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status = bring_internal_kexts_online();
|
|
|
|
|
if (status != KERN_OK) {
|
|
|
|
|
panic("bring_internal_kexts_online() failed with code %s", kern_status_string(status));
|
|
|
|
|
}
|
2023-04-08 09:27:21 +01:00
|
|
|
|
2023-06-09 21:24:51 +01:00
|
|
|
scan_all_buses();
|
|
|
|
|
|
2023-03-18 19:35:00 +00:00
|
|
|
printk("kernel_init() running on processor %u", this_cpu());
|
|
|
|
|
|
2023-06-11 09:24:22 +01:00
|
|
|
#ifdef KEXT_NET_DOORSTUCK_SOCKS_FBCON
|
|
|
|
|
struct object *fb;
|
|
|
|
|
status = object_get("/dev/video/fb0", &fb);
|
|
|
|
|
if (status == KERN_OK) {
|
2023-06-11 14:55:47 +01:00
|
|
|
#if 0
|
|
|
|
|
struct framebuffer_varinfo fb_mode;
|
|
|
|
|
struct device *fbdev = cast_to_device(fb);
|
|
|
|
|
framebuffer_get_varinfo(fbdev, &fb_mode);
|
|
|
|
|
fb_mode.fb_xres = 1024;
|
|
|
|
|
fb_mode.fb_yres = 768;
|
|
|
|
|
fb_mode.fb_bpp = 24;
|
|
|
|
|
fb_mode.fb_flags = FB_MODE_RGB;
|
|
|
|
|
framebuffer_set_varinfo(fbdev, &fb_mode);
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-06-11 09:24:22 +01:00
|
|
|
start_console_on_framebuffer(cast_to_device(fb));
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2023-06-11 14:55:47 +01:00
|
|
|
struct object *tty0;
|
|
|
|
|
status = object_get("/dev/tty/tty0", &tty0);
|
|
|
|
|
if (status == KERN_OK) {
|
2023-06-11 16:47:33 +01:00
|
|
|
tty_set_foreground(cast_to_device(tty0));
|
2023-06-11 14:55:47 +01:00
|
|
|
}
|
2023-06-11 09:24:22 +01:00
|
|
|
|
2023-12-30 09:09:18 +00:00
|
|
|
const char *console_tty_name = arg_value("kernel.console");
|
|
|
|
|
if (!console_tty_name) {
|
|
|
|
|
console_tty_name = "tty0";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char console_tty_path[128];
|
|
|
|
|
snprintf(console_tty_path, sizeof console_tty_path, "/dev/tty/%s", console_tty_name);
|
|
|
|
|
|
|
|
|
|
struct object *console_tty = NULL;
|
|
|
|
|
status = object_get(console_tty_path, &console_tty);
|
|
|
|
|
|
|
|
|
|
if (status == KERN_OK) {
|
|
|
|
|
register_tty_console();
|
|
|
|
|
struct device *console_tty_device = cast_to_device(console_tty);
|
|
|
|
|
redirect_printk_to_tty(console_tty_device);
|
|
|
|
|
object_deref(console_tty);
|
|
|
|
|
} else {
|
|
|
|
|
printk("console tty '%s' is unavailable.", console_tty_name);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-04 21:43:18 +01:00
|
|
|
create_kernel_thread(background_thread);
|
|
|
|
|
|
2023-05-14 21:11:32 +01:00
|
|
|
struct object *kbd;
|
2023-05-10 20:34:53 +01:00
|
|
|
|
2023-06-02 19:35:07 +01:00
|
|
|
run_all_tests();
|
2023-05-10 20:34:53 +01:00
|
|
|
|
2023-06-08 20:46:43 +01:00
|
|
|
status = object_get("/dev/input/input0", &kbd);
|
2023-06-11 16:47:33 +01:00
|
|
|
if (status == KERN_OK) {
|
|
|
|
|
tty_connect_foreground_input_device(cast_to_device(kbd));
|
2023-03-19 20:36:36 +00:00
|
|
|
}
|
2023-05-10 20:34:53 +01:00
|
|
|
|
2023-07-09 21:58:40 +01:00
|
|
|
struct object *disk;
|
|
|
|
|
status = object_get("/dev/block/disk0", &disk);
|
|
|
|
|
if (status == KERN_OK) {
|
|
|
|
|
unsigned char buf[32] = {0};
|
|
|
|
|
struct device *disk_dev = cast_to_device(disk);
|
|
|
|
|
size_t nread = 0;
|
|
|
|
|
|
2023-07-11 21:26:22 +01:00
|
|
|
device_lock(disk_dev);
|
2023-07-09 21:58:40 +01:00
|
|
|
status = device_read(disk_dev, buf, 1, 32, &nread, 0);
|
2023-07-11 21:26:22 +01:00
|
|
|
device_unlock(disk_dev);
|
|
|
|
|
|
2023-07-09 21:58:40 +01:00
|
|
|
if (status == KERN_OK) {
|
|
|
|
|
printk("read %zu bytes from /dev/block/disk0:", nread);
|
|
|
|
|
for (int i = 0; i < sizeof buf; i++) {
|
|
|
|
|
printk("%02xh", buf[i]);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
printk("failed to read from block device (%s)", kern_status_string(status));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
printk("cannot open block device (%s)", kern_status_string(status));
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-10 20:34:53 +01:00
|
|
|
hang();
|
2022-12-21 08:29:33 +00:00
|
|
|
}
|