Compare commits

..
5 Commits
Author SHA1 Message Date
freywar 8cb3ace92f Add the most important part of README 2026-08-25 21:44:01 +03:00
freywar 46f0202222 Fix minor issues in user apps
Uninitialized variables, reading past array end, etc.
2026-08-25 21:41:25 +03:00
freywar 7d274da197 Finalize xHCI and USB modules
Scratchpad buffers allocation added to xHCI. Missing initialization steps
for keyboards - set configuration and set idle - added to USB. (Even
though they are specific to HID protocol, they go through USB command
endpoint, and with current module contents it's cleaner to have them
in USB module.)
2026-08-25 21:20:53 +03:00
freywar a3240d9316 Fix LOG_X usage crashing the system
Each `LOG_X` call declared a rather huge variable on the stack,
and using it to dump a whole structure often led to a page fault.
Now the temporary variables are `static`, which is a bit wasteful
on the kernel binary size, but easier to maintain.

Additionally bootloader updated to load kernels bigger than 64K.
2026-08-25 17:20:34 +03:00
freywar c92ccd41ce Improve installation process
`meson.build` rewritten with DRY principle. `deploy.sh` added,
which deploys the image on a installation USB stick borrowed from
another project. Image name aligned with the installer's expectations.
2026-08-25 17:14:50 +03:00
4 changed files with 8 additions and 17 deletions
+1 -1
View File
@@ -357,7 +357,7 @@ fs_node_t *fat16_open_at(const fs_node_t *directory, uint16_t index, uint64_t fl
ei++;
}
fs_node_t *result = ei < entries_count ? open_entry(dir_cluster, entries, ei) : NUL;
fs_node_t *result = open_entry(dir_cluster, entries, ei);
memory_free(entries);
+5 -14
View File
@@ -538,7 +538,7 @@ uint64_t xhci_control_transfer(xhci_slot_t slot, uint64_t setup, void *data, uin
}
xhci_endpoint_t xhci_open_endpoint(xhci_slot_t slot, uint8_t address, uint8_t type, uint16_t max_packet_size, uint8_t interval) {
LOG_LN_STEP("Opening endpoint slot %d address %hhx...", slot, address);
LOG_LN_INFO("Opening endpoint slot %d address %hhx...", slot, address);
ASSERT(slot < MAX_SLOTS, "xhci_control_transfer: Slot does not exist.");
ASSERT(tsf_r_attached_slot == slot, "xhci_open_endpoint: Slot is not attached.");
@@ -549,11 +549,11 @@ xhci_endpoint_t xhci_open_endpoint(xhci_slot_t slot, uint8_t address, uint8_t ty
uint8_t ep_dir = (address >> 7) & 1;
uint8_t dci = ep_num * 2 + ep_dir;
LOG_LN_STEP("Setting up endpoint ring...");
LOG_LN_INFO("Setting up endpoint ring...");
RING_WRAP(ep);
XHCI_TRB_CYCLE_W(&ep_r[RING_LENGTH], ep_r_cycle);
LOG_LN_STEP("Configuring endpoint...");
LOG_LN_INFO("Configuring endpoint...");
memory_set(0, sizeof(xhci_input_ctx_t), &input_ctx);
input_ctx.slot = device_ctx.slot;
input_ctx.control.add_flags = (1 << 0) | (1 << dci);
@@ -597,10 +597,9 @@ uint16_t xhci_read_endpoint(xhci_slot_t slot, xhci_endpoint_t endpoint, uint16_t
XHCI_TRB_TRB_TYPE_W(ere, XHCI_TRB_TYPE_TRANSFER_NORMAL);
XHCI_TRB_IOC_W(ere, 1);
XHCI_TRB_CYCLE_W(ere, ep_r_cycle);
RING_ADVANCE(ep);
}
ep_r_cycle ^= 1;
db_regs[tsf_r_attached_slot] = ep_r_attached_endpoint;
return 0;
@@ -608,14 +607,6 @@ uint16_t xhci_read_endpoint(xhci_slot_t slot, xhci_endpoint_t endpoint, uint16_t
uint16_t transferred = 0;
while (XHCI_TRB_CYCLE_R(&evt_r[evt_r_i]) == evt_r_cycle && !transferred) {
if (ep_processed_events == 0) {
// A bit of a hack: flip link TRB cycle only after the first event is processed. There is some delay between controller
// posting the last success event of the batch, and consuming the link TRB. Flipping the link cycle together with the batch
// might happen before the controller got a chance to check the link cycle, and stall the consumption. If we received the
// first event of the next batch, we're certain the link TRB has just been processed, and there's plenty of time before the next loop.
XHCI_TRB_CYCLE_W(&ep_r[RING_LENGTH], !ep_r_cycle);
}
xhci_trb_t *cmp = &evt_r[evt_r_i];
if (XHCI_TRB_TRB_TYPE_R(cmp) != XHCI_TRB_TYPE_EVENT_TRANSFER_COMPLETION) {
@@ -657,7 +648,7 @@ uint16_t xhci_read_endpoint(xhci_slot_t slot, xhci_endpoint_t endpoint, uint16_t
}
void xhci_close_endpoint(xhci_slot_t slot, xhci_endpoint_t endpoint) {
LOG_LN_STEP("Closing endpoind %hhx...", endpoint);
LOG_LN_INFO("Closing endpoind %hhx...", endpoint);
ASSERT(slot < MAX_SLOTS, "xhci_control_transfer: Slot does not exist.");
ASSERT(tsf_r_attached_slot == slot, "xhci_close_endpoint: Slot is not attached.");
+1 -1
View File
@@ -5,7 +5,7 @@
#define BLOCK_SIZE 65536
exit_code_t pass(uint64_t fd) {
static char buffer[BLOCK_SIZE];
char buffer[BLOCK_SIZE];
uint64_t bytes;
while ((bytes = read(fd, BLOCK_SIZE, buffer))) {
if (bytes == (uint64_t)-1) {
+1 -1
View File
@@ -6,7 +6,7 @@
#define BLOCK_SIZE 65536
exit_code_t pass(uint64_t fd) {
static char buffer[BLOCK_SIZE];
char buffer[BLOCK_SIZE];
uint64_t bytes;
uint64_t total = 0;
while ((bytes = read(fd, BLOCK_SIZE, buffer))) {