${KERNELBIN}: ${OBJS}
${LD} -z noexecstack -m elf_i386 -M -T$(LINKSCRIPT) $(OBJS) -o $@ > $(SYSTEMMAP)
nm -a $@ > kernel.sym
- #rm kernel/setup.c.o
+ rm kernel/setup.c.o
%.S.o: %.S ${HEADER_FILES}
${CC} ${CFLAGS} $< -o $@
#endif
}
+void init_serial();
void init_ttys();
void setup_gdt();
void setup_idt();
void setup_boot_irqs();
void check_kernel(unsigned long addr, unsigned long magic) {
+ init_serial();
+
init_ttys();
printk("setup gdt\n");
}
assert(pci->intr_line < 16);
if (pci != 0 && pci->intr_line < 16) {
- printk("found pci %03d:%02d.%d #%02d %04X:%04X ProgIF %02x %s\n", pci->bus, pci->dev, pci->devfn,
+ printk("found pci %03d:%02d.%d #%02d %04X:%04X progif %02x %s\n", pci->bus, pci->dev, pci->devfn,
pci->intr_line, pci->vendor, pci->device, pci->progif, pci_get_info(pci->classcode, pci->progif));
// printk("found pci vendor %04x device %04x class %04x intr %d progif: %x\n", pci->vendor, pci->device,
// pci->classcode, pci->intr_line, pci->progif);
--- /dev/null
+/*
+ * ------------------------------------------------------------------------
+ * File Name: serial.c
+ * Author: Zhao Yanbai
+ * 2023-09-26 21:03:27 Tuesday CST
+ * Description: none
+ * ------------------------------------------------------------------------
+ */
+
+#include "io.h"
+
+#define COMM1_PORT 0x3F8
+#define COMM2_PORT 0x2F8
+#define COMM3_PORT 0x3E8
+#define COMM4_PORT 0x2F8
+#define COMM5_PORT 0x5F8
+#define COMM6_PORT 0x4F8
+#define COMM7_PORT 0x5E8
+#define COMM8_PORT 0x4E8
+
+#define SERIAL_PORT COMM1_PORT
+
+void init_serial() {
+ uint32_t port = SERIAL_PORT;
+ outb(0x00, port + 1); // 禁用中断
+ outb(0x80, port + 3);
+ outb(115200 / 9600, port + 0);
+ outb(0x00, port + 1);
+ outb(0x03, port + 3);
+ outb(0xC7, port + 2);
+ outb(0x0B, port + 4);
+}
+
+void serial_putc(char c) {
+ while ((inb(SERIAL_PORT + 5) & 0x20) == 0) {
+ }
+ outb(c, SERIAL_PORT);
+}
+
+void serial_write(const char *buf, size_t size) {
+ // return 0;
+ for (size_t i = 0; i < size; i++) {
+ serial_putc(buf[i]);
+ }
+}
set pagination off
-b init_system_info
+#b init_serial
+
+#b init_system_info
# finish 可以执行到当前函数返回处, 缩写 fin
-b setup_pci
+#b setup_pci
#b setup_kernel
#b e820_init_bootmem_data
#include <tty.h>
int vsprintf(char *buf, const char *fmt, char *args);
+void serial_write(const char *buf, size_t size);
+
char pkbuf[1024];
extern tty_t *const default_tty;
int printk(const char *fmtstr, ...) {
char *args = (char *)(((char *)&fmtstr) + 4);
int size = vsprintf(pkbuf, fmtstr, args);
tty_write(default_tty, pkbuf, (size_t)size);
+ serial_write(pkbuf, (size_t)size);
irq_restore(iflags);
return 0;
}
char *args = (char *)(((char *)&fmtstr) + 4);
int size = vsprintf(pdbuf, fmtstr, args);
tty_write(debug_tty, pdbuf, (size_t)size);
+ serial_write(pdbuf, (size_t)size);
irq_restore(iflags);
return 0;
}
-device ich9-ahci,id=ahci \
&
+# -serial tcp::8888,server,nowait \
# -device ich9-ahci,id=ahci \
# -machine accel=tcg \
# -serial stdio \