Skip to content
This repository was archived by the owner on Jan 14, 2026. It is now read-only.

Commit f4d483a

Browse files
committed
fix vga text output logic
1 parent 3419eec commit f4d483a

10 files changed

Lines changed: 257 additions & 113 deletions

File tree

File renamed without changes.

src/kernel/driver/usb/hid.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222

2323
/* Boot Protocol Keyboard Report */
2424
struct hid_keyboard_report {
25-
uint8_t modifier; /* Ctrl, Shift, Alt, GUI */
25+
uint8_t modifier; /* Ctrl, Shift, Alt, */
2626
uint8_t reserved;
27-
uint8_t keycode[6]; /* 同時押し可能なキー(最大6個) */
27+
uint8_t keycode[64]; /* 同時押し可能なキー(最大64個) */
2828
} __attribute__((packed));
2929

3030
/* Modifier bits */

src/kernel/driver/usb/xhci.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
/**
2-
* @file xhci.c
3-
* @brief xHCI (eXtensible Host Controller Interface) USB 3.0 Driver
4-
*
5-
* xHCI仕様に基づくUSBホストコントローラドライバ
6-
* Phase 1: コントローラ検出と基本初期化
7-
*/
8-
91
#include <driver/usb/xhci.h>
102
#include <device/pci.h>
113
#include <util/console.h>

src/kernel/driver/usb/xhci.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -247,40 +247,30 @@ int xhci_init(void);
247247
int xhci_reset_controller(struct xhci_hc *hc);
248248
int xhci_start_controller(struct xhci_hc *hc);
249249
uint32_t xhci_get_port_status(struct xhci_hc *hc, uint32_t port_num);
250-
251-
/* Phase 2: Command/Event Ring functions */
252250
int xhci_setup_command_ring(struct xhci_hc *hc);
253251
int xhci_setup_event_ring(struct xhci_hc *hc);
254252
void xhci_ring_doorbell(struct xhci_hc *hc, uint8_t slot_id, uint8_t target);
255253
int xhci_wait_for_event(struct xhci_hc *hc, struct xhci_trb *event_trb,
256254
uint32_t timeout_ms);
257255
void xhci_handle_events(struct xhci_hc *hc);
258-
259-
/* Phase 3: Device Enumeration functions */
260256
int xhci_enable_slot(struct xhci_hc *hc);
261257
int xhci_address_device(struct xhci_hc *hc, uint8_t slot_id, uint8_t port);
262258
int xhci_configure_endpoint(struct xhci_hc *hc, uint8_t slot_id);
263259
int xhci_reset_port(struct xhci_hc *hc, uint8_t port);
264260
void xhci_handle_port_status_change(struct xhci_hc *hc, uint8_t port);
265-
266-
/* Phase 4: USB Protocol functions */
267261
int xhci_control_transfer(struct xhci_hc *hc, uint8_t slot_id,
268262
uint8_t request_type, uint8_t request, uint16_t value,
269263
uint16_t index, void *data, uint16_t length);
270264
int xhci_get_descriptor(struct xhci_hc *hc, uint8_t slot_id, uint8_t desc_type,
271265
uint8_t desc_index, void *buffer, uint16_t length);
272266
int xhci_set_configuration(struct xhci_hc *hc, uint8_t slot_id,
273267
uint8_t config_value);
274-
275-
/* Helper functions */
276268
void *xhci_alloc_aligned(uint32_t size, uint32_t alignment);
277269
void xhci_free_aligned(void *ptr);
278270
uint8_t xhci_get_keyboard_slot(struct xhci_hc *hc);
279271
int xhci_setup_keyboard_polling(struct xhci_hc *hc, uint8_t slot_id);
280272
int xhci_poll_keyboard(struct xhci_hc *hc, uint8_t slot_id,
281273
uint8_t *report_buffer);
282-
283-
/* HID Keyboard specific */
284274
int xhci_configure_keyboard(struct xhci_hc *hc, uint8_t slot_id);
285275
int xhci_set_boot_protocol(struct xhci_hc *hc, uint8_t slot_id,
286276
uint8_t interface);

src/kernel/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ static BOOT_INFO *g_boot_info = NULL;
3737
void kmain(BOOT_INFO *boot_info) {
3838
g_boot_info = boot_info;
3939

40-
console_init();
4140
console_set_framebuffer(boot_info);
41+
console_init();
4242
set_log_level(ALL);
4343

4444
gdt_build();
@@ -104,4 +104,4 @@ void kloop() {
104104
if (!activity) {
105105
cpu_halt();
106106
}
107-
}
107+
}

src/kernel/util/bdf.c

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,19 @@ static int parse_bdf(const char *data, size_t size) {
135135
printk("BDF: Too many glyphs\n");
136136
return 0;
137137
}
138+
138139
current_glyph = &font.glyphs[font.num_glyphs];
139140
current_glyph->width = font.width;
140141
current_glyph->height = font.height;
141142
current_glyph->x_offset = 0;
142143
current_glyph->y_offset = 0;
143144
current_glyph->encoding = 0;
144145
bitmap_line = 0;
146+
147+
for (int zi = 0; zi < MAX_GLYPH_HEIGHT; zi++) {
148+
current_glyph->bitmap[zi] = 0;
149+
}
150+
145151
in_bitmap = 0;
146152
} else if (starts_with(p, "ENCODING")) {
147153
if (current_glyph) {
@@ -180,23 +186,28 @@ static int parse_bdf(const char *data, size_t size) {
180186
}
181187
in_bitmap = 0;
182188
} else if (in_bitmap && current_glyph) {
183-
// ビットマップデータを読み込む
184189
p = skip_spaces(p);
185-
if ((*p >= '0' && *p <= '9') ||
186-
(*p >= 'A' && *p <= 'F') ||
187-
(*p >= 'a' && *p <= 'f')) {
190+
if ((*p >= '0' && *p <= '9') || (*p >= 'A' && *p <= 'F') ||
191+
(*p >= 'a' && *p <= 'f')) {
188192
if (bitmap_line < MAX_GLYPH_HEIGHT) {
189-
char hex_str[3] = { 0 };
193+
char hex_str[9];
190194
int i = 0;
191-
while (i < 2 &&
192-
((*p >= '0' && *p <= '9') ||
193-
(*p >= 'A' && *p <= 'F') ||
194-
(*p >= 'a' && *p <= 'f'))) {
195+
while (i < (int)(sizeof(hex_str) - 1) &&
196+
((*p >= '0' && *p <= '9') || (*p >= 'A' && *p <= 'F') ||
197+
(*p >= 'a' && *p <= 'f'))) {
195198
hex_str[i++] = *p++;
196199
}
197200
hex_str[i] = '\0';
198-
current_glyph->bitmap[bitmap_line++] =
199-
hex_to_int(hex_str);
201+
uint32_t val = hex_to_int(hex_str);
202+
int hex_len = i;
203+
int total_bits = hex_len * 4;
204+
int width = current_glyph->width ? current_glyph->width : font.width;
205+
if (width <= 0) width = font.width;
206+
if (total_bits > width) {
207+
val >>= (total_bits - width);
208+
}
209+
uint32_t mask = (width >= 32) ? 0xFFFFFFFFu : ((1u << width) - 1u);
210+
current_glyph->bitmap[bitmap_line++] = (uint16_t)(val & mask);
200211
}
201212
}
202213
}

src/kernel/util/bdf.h

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ typedef struct {
1515
uint8_t height; // グリフの高さ
1616
int8_t x_offset; // X方向のオフセット
1717
int8_t y_offset; // Y方向のオフセット
18-
uint8_t bitmap[MAX_GLYPH_HEIGHT]; // ビットマップデータ
18+
uint16_t bitmap[MAX_GLYPH_HEIGHT]; // ビットマップデータ
1919
} bdf_glyph_t;
2020

2121
/**
@@ -31,24 +31,8 @@ typedef struct {
3131
bdf_glyph_t glyphs[MAX_GLYPHS]; // グリフ配列
3232
} bdf_font_t;
3333

34-
/**
35-
* @brief BDFフォントを初期化
36-
* @param path フォントファイルのパス
37-
* @return 成功時は1、失敗時は0
38-
*/
3934
int bdf_init(const char *path);
40-
41-
/**
42-
* @brief 文字コードに対応するグリフを取得
43-
* @param c 文字コード
44-
* @return グリフへのポインタ、見つからない場合はNULL
45-
*/
4635
const bdf_glyph_t *bdf_get_glyph(uint32_t c);
47-
48-
/**
49-
* @brief フォント情報を取得
50-
* @return フォント情報へのポインタ
51-
*/
5236
const bdf_font_t *bdf_get_font(void);
5337

5438
#endif /* _BDF_H */

0 commit comments

Comments
 (0)