From 08a7d5c975201f7402a9da50045e04f0fe8d9a56 Mon Sep 17 00:00:00 2001 From: d0p1 Date: Thu, 13 Jul 2023 13:44:00 +0200 Subject: [PATCH] docs: documente ISA/AT buses I/O Port map --- docs/config/Menu.txt | 32 ++++++++----- kernel/Makefile | 4 +- kernel/boot/head.s | 11 +++-- kernel/boot/memory.s | 25 ++++++++++ kernel/cpu.inc | 59 +++++++++++++++++++++++ kernel/dev/at/cmos.s | 72 ++++++++++++++++++++++++++++ kernel/dev/at/intro.txt | 54 +++++++++++++++++++++ kernel/dev/at/kbd.S | 0 kernel/dev/at/pit.s | 15 ++++++ kernel/{drivers => dev/at}/serial.s | 0 kernel/i18n/i18n.inc | 11 +---- kernel/i18n/lang.inc | 10 ++++ kernel/i18n/msg_en.s | 16 +++---- kernel/intro.txt | Bin 0 -> 486 bytes 14 files changed, 277 insertions(+), 32 deletions(-) create mode 100644 kernel/boot/memory.s create mode 100644 kernel/dev/at/cmos.s create mode 100644 kernel/dev/at/intro.txt create mode 100644 kernel/dev/at/kbd.S create mode 100644 kernel/dev/at/pit.s rename kernel/{drivers => dev/at}/serial.s (100%) create mode 100644 kernel/i18n/lang.inc create mode 100644 kernel/intro.txt diff --git a/docs/config/Menu.txt b/docs/config/Menu.txt index 97fef88..2fda16b 100644 --- a/docs/config/Menu.txt +++ b/docs/config/Menu.txt @@ -41,48 +41,58 @@ Timestamp: Updated yyyy/mm/dd File: Introduction (docs/intro.txt) Link: Source Code (https://github.com/d0p1s4m4/StupidOS) File: Coding Style (docs/coding-style.txt) +File: Building (building.txt) File: FAQ (docs/faq.txt) Group: Kernel { - Group: Boot { + File: Introduction (kernel/intro.txt) + + Group: boot { - File: feat.s (kernel/boot/feat.s) File: head.s (kernel/boot/head.s) - } # Group: Boot + } # Group: boot + File: kernel.s (kernel/kernel.s) File: gdt.s (kernel/gdt.s) File: idt.s (kernel/idt.s) File: pic.s (kernel/pic.s) - Group: Driver { + Group: dev { - File: serial.s (no auto-title, kernel/drivers/serial.s) - } # Group: Driver + Group: AT { + + File: IBM PC/AT (kernel/dev/at/intro.txt) + File: cmos.s (kernel/dev/at/cmos.s) + File: pit.s (kernel/dev/at/pit.s) + File: serial.s (kernel/dev/at/serial.s) + } # Group: AT + + } # Group: dev Group: i18n { File: msg_en.s (kernel/i18n/msg_en.s) } # Group: i18n - File: kernel.s (kernel/kernel.s) File: pmm.s (kernel/pmm.s) - Group: Sys { + Group: sys { File: multiboot.inc (kernel/sys/multiboot.inc) - Group: I386 { + Group: i386 { File: cpuid.inc (kernel/sys/i386/cpuid.inc) File: mmu.inc (kernel/sys/i386/mmu.inc) File: registers.inc (kernel/sys/i386/registers.inc) - } # Group: I386 + } # Group: i386 - } # Group: Sys + } # Group: sys File: vm.inc (kernel/vm/vm.inc) File: pmap.s (kernel/vm/pmap.s) + File: cpu.inc (kernel/cpu.inc) } # Group: Kernel Group: Lib { diff --git a/kernel/Makefile b/kernel/Makefile index 06e6430..ce08cbf 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -1,7 +1,9 @@ KERNEL = vmstupid SRCS = boot/head.s \ kernel.s gdt.s pic.s isr.s idt.s \ - lib/log.s drivers/serial.s + lib/log.s dev/at/serial.s \ + i18n/msg_en.s \ + base/console.s INCS = sys/multiboot.inc \ sys/i386/cpuid.inc \ sys/i386/mmu.inc \ diff --git a/kernel/boot/head.s b/kernel/boot/head.s index 6fb04da..0d7ccb5 100644 --- a/kernel/boot/head.s +++ b/kernel/boot/head.s @@ -30,7 +30,8 @@ align 4 section .multiboot.text ;; Function: entry - ;; + ;; Setup boot page table, map kernel to higher half + ;; then jump to ;; ;; in: ;; EAX - Multiboot magic @@ -83,16 +84,20 @@ entry: section .text + ;; Function: entry_high + ;; Invalidate page[0], setup stack then call entry_high: + ;; unmap first 4MiB, since it's not needed anymore mov dword [boot_page_dir], 0 invlpg [0] + ;; Setup stack extern stack_top mov esp, stack_top xor ebp, ebp - push edi - push esi + push esi ; multiboot struct + push edi ; multiboot magic extern kmain call kmain diff --git a/kernel/boot/memory.s b/kernel/boot/memory.s new file mode 100644 index 0000000..4a666aa --- /dev/null +++ b/kernel/boot/memory.s @@ -0,0 +1,25 @@ + extern kernel_start + extern kernel_end + extern kernel_size + +pmm_check_page_free: + push ebp + mov ebp, esp + + + leave + ret + +pmm_setup_from_multiboot_mmap: + push ebp + mov ebp, esp + push edi + push esi + push ebx + + mov eax, [esi + mb_info.mmap_addr] + pop ebx + pop esi + pop edi + leave + ret diff --git a/kernel/cpu.inc b/kernel/cpu.inc index 16619e7..daeaf18 100644 --- a/kernel/cpu.inc +++ b/kernel/cpu.inc @@ -1,3 +1,62 @@ + ;; File: cpu.inc + + + ;; Structure: tss + ;; + ;; > 31 23 15 7 0 + ;; > +----------|----------+----------|----------+ + ;; > 0x64 | I/O map base | 00000000 0000000T | + ;; > +----------|----------+----------|----------+ + ;; > 0x60 | 00000000 00000000 | LDT | + ;; > +----------|----------+----------|----------+ + ;; > 0x5c | 00000000 00000000 | GS | + ;; > +----------|----------+----------|----------+ + ;; > 0x58 | 00000000 00000000 | FS | + ;; > +----------|----------+----------|----------+ + ;; > 0x54 | 00000000 00000000 | DS | + ;; > +----------|----------+----------|----------+ + ;; > 0x50 | 00000000 00000000 | SS | + ;; > +----------|----------+----------|----------+ + ;; > 0x4C | 00000000 00000000 | CS | + ;; > +----------|----------+----------|----------+ + ;; > 0x48 | 00000000 00000000 | ES | + ;; > +----------|----------+----------|----------+ + ;; > 0x44 | EDI | + ;; > +----------|----------+----------|----------+ + ;; > 0x40 | ESI | + ;; > +----------|----------+----------|----------+ + ;; > 0x3C | EBP | + ;; > +----------|----------+----------|----------+ + ;; > 0x38 | ESP | + ;; > +----------|----------+----------|----------+ + ;; > 0x34 | EBX | + ;; > +----------|----------+----------|----------+ + ;; > 0x30 | EDX | + ;; > +----------|----------+----------|----------+ + ;; > 0x2C | ECX | + ;; > +----------|----------+----------|----------+ + ;; > 0x28 | EAX | + ;; > +----------|----------+----------|----------+ + ;; > 0x24 | EFLAGS | + ;; > +----------|----------+----------|----------+ + ;; > 0x20 | EIP | + ;; > +----------|----------+----------|----------+ + ;; > 0x1C | CR3 | + ;; > +----------|----------+----------|----------+ + ;; > 0x18 | 00000000 00000000 | SS2 | + ;; > +----------|----------+----------|----------+ + ;; > 0x14 | ESP2 | + ;; > +----------|----------+----------|----------+ + ;; > 0x10 | 00000000 00000000 | SS1 | + ;; > +----------|----------+----------|----------+ + ;; > 0x0C | ESP1 | + ;; > +----------|----------+----------|----------+ + ;; > 0x08 | 00000000 00000000 | SS0 | + ;; > +----------|----------+----------|----------+ + ;; > 0x04 | ESP0 | + ;; > +----------|----------+----------|----------+ + ;; > 0x00 | 00000000 00000000 | old TSS selector | + ;; > +----------|----------+----------|----------+ struc tss .link: resw 1 resw 1 diff --git a/kernel/dev/at/cmos.s b/kernel/dev/at/cmos.s new file mode 100644 index 0000000..a5127ee --- /dev/null +++ b/kernel/dev/at/cmos.s @@ -0,0 +1,72 @@ + ;; File: cmos.s + ;; Real/Time Clock/CMOS RAM + ;; + ;; > +-------------+------------------------------+ + ;; > | 0x00 - 0x0D | *Real-time clock information | + ;; > +-------------+------------------------------+ + ;; > | 0x0E | *Diagnostic status byte | + ;; > +-------------+------------------------------+ + ;; > | 0x0F | *Shutdown status byte | + ;; > +-------------+------------------------------+ + ;; > | 0x10 | Diskette drive type byte | + ;; > +-------------+------------------------------+ + ;; > | 0x12 | Fixed disk type byte | + ;; > +-------------+------------------------------+ + ;; > | 0x14 | Equipment byte | + ;; > +-------------+------------------------------+ + ;; > | 0x15 | Low base memory byte | + ;; > +-------------+------------------------------+ + ;; > | 0x16 | High base memory byte | + ;; > +-------------+------------------------------+ + ;; > | 0x17 | Low expansion memory byte | + ;; > +-------------+------------------------------+ + ;; > | 0x18 | High expansion memory byte | + ;; > +-------------+------------------------------+ + ;; > | 0x19 | Disk C extended byte | + ;; > +-------------+------------------------------+ + ;; > | 0x1A | Disk D extended byte | + ;; > +-------------+------------------------------+ + ;; > | 0x2E - 0x2F | CMOS checksum | + ;; > +-------------+------------------------------+ + ;; > | 0x30 | *Low expansion memory byte | + ;; > +-------------+------------------------------+ + ;; > | 0x31 | *High expansion memory byte | + ;; > +-------------+------------------------------+ + ;; > | 0x32 | *Date century byte | + ;; > +-------------+------------------------------+ + ;; > | 0x33 | *Flags | + ;; > +-------------+------------------------------+ + +CMOS_RTC equ 0x00 + +RTC_SECONDS equ 0x00 +RTC_SECOND_ALRM equ 0x01 +RTC_MINUTES equ 0x02 +RTC_MINUTE_ALRM equ 0x03 +RTC_HOURS equ 0x04 +RTC_HOUR_ALRM equ 0x05 +RTC_WEEKDAY equ 0x06 +RTC_DATE_OF_MONTH equ 0x07 +RTC_MONTH equ 0x08 +RTC_YEAR equ 0x09 +RTC_STATUS_REGA equ 0x0A +RTC_STATUS_REGB equ 0x0B +RTC_STATUS_REGC equ 0x0C +RTC_STATUS_REGD equ 0x0D + +STATUS_REGA_UIP equ (1 << 7) + +STATUS_REGB_PIE equ (1 << 6) +STATUS_REGB_AIE equ (1 << 5) +STATUS_REGB_UIE equ (1 << 4) +STATUS_REGB_SQWE equ (1 << 3) +STATUS_REGB_DM equ (1 << 2) +STATUS_REGB_24H equ (1 << 1) +STATUS_REGB_DSE equ (1 << 0) + +CMOS_CENTURY equ 0x32 + + + + + diff --git a/kernel/dev/at/intro.txt b/kernel/dev/at/intro.txt new file mode 100644 index 0000000..4dd7880 --- /dev/null +++ b/kernel/dev/at/intro.txt @@ -0,0 +1,54 @@ +File: IBM PC/AT + +About: I/O Address Map + +> +---------------+-------------------------+ +> | 0x000 - 0x01F | DMA controller 1 | +> +---------------+-------------------------+ +> | 0x020 - 0x03F | 8259A, Primary | +> +---------------+-------------------------+ +> | 0x040 - 0x05F | Timer | +> +---------------+-------------------------+ +> | 0x060 - 0x06F | Keyboard | +> +---------------+-------------------------+ +> | 0x070 - 0x07F | CMOS | +> +---------------+-------------------------+ +> | 0x080 - 0x09F | DMA page register | +> +---------------+-------------------------+ +> | 0x0A0 - 0x0BF | 8259A, Secondary | +> +---------------+-------------------------+ +> | 0x0C0 - 0x0DF | DMA controller 2 | +> +---------------+-------------------------+ +> | 0x0F0 | Clear Math Coprocessor | +> +---------------+-------------------------+ +> | 0x0F1 | Reset Math Coprocessor | +> +---------------+-------------------------+ +> | 0x0F8 - 0x0FF | Math Coprocessor | +> +---------------+-------------------------+ +> | 0x1F0 - 0x1F8 | Fixed Disk | +> +---------------+-------------------------+ +> | 0x200 - 0x207 | Game I/O | +> +---------------+-------------------------+ +> | 0x278 - 0x27F | Parallel printer port 2 | +> +---------------+-------------------------+ +> | 0x2F8 - 0x2FF | Serial port 2 | +> +---------------+-------------------------+ +> | 0x300 - 0x31F | Prototype card | +> +---------------+-------------------------+ +> | 0x360 - 0x363 | PC Network (low) | +> +---------------+-------------------------+ +> | 0x368 - 0x36B | PC Network (high) | +> +---------------+-------------------------+ +> | 0x378 - 0x37F | Parallel printer port 1 | +> +---------------+-------------------------+ +> | 0x380 - 0x38F | SDLC, bisynchronous 2 | +> +---------------+-------------------------+ +> | 0x3B0 - 0x3BF | Monochrome Display | +> +---------------+-------------------------+ +> | 0x3D0 - 0x3DF | Color Monitor Adapter | +> +---------------+-------------------------+ +> | 0x3F0 - 0x3F7 | Diskette controller | +> +---------------+-------------------------+ +> | 0x3F8 - 0x3FF | Serial port 1 | +> +---------------+-------------------------+ + diff --git a/kernel/dev/at/kbd.S b/kernel/dev/at/kbd.S new file mode 100644 index 0000000..e69de29 diff --git a/kernel/dev/at/pit.s b/kernel/dev/at/pit.s new file mode 100644 index 0000000..eeab59f --- /dev/null +++ b/kernel/dev/at/pit.s @@ -0,0 +1,15 @@ + ;; File: pit.s + ;; Programmable Interval Timer (8253/8254) + +PIT_CHAN_0 equ 0x40 +PIT_CHAN_1 equ 0x41 +PIT_CHAN_2 equ 0x42 +PIT_CMD equ 0x43 + +CMD_CHANNEL_1 equ (0x1 << 6) +CMD_CHANNEL_2 equ (0x2 << 6) +CMD_READ_BACK equ (0x3 << 6) +CMD_ACCESS_LO equ (0x1 << 4) +CMD_ACCESS_HI equ (0x2 << 4) +CMD_ACCESS_LO_HI equ (0x3 << 4) + diff --git a/kernel/drivers/serial.s b/kernel/dev/at/serial.s similarity index 100% rename from kernel/drivers/serial.s rename to kernel/dev/at/serial.s diff --git a/kernel/i18n/i18n.inc b/kernel/i18n/i18n.inc index ba59ee3..0b8f8bd 100644 --- a/kernel/i18n/i18n.inc +++ b/kernel/i18n/i18n.inc @@ -1,10 +1,3 @@ -struc lang_entry - .code: resb 2 - .data: resd 1 - .next: resd 1 -endstruc +%include "i18n/lang.inc" -struc msg_table - .hello_world: resd 1 - .cpu_exceptions: resd 32 -endstruc +extern msg_en diff --git a/kernel/i18n/lang.inc b/kernel/i18n/lang.inc new file mode 100644 index 0000000..ba59ee3 --- /dev/null +++ b/kernel/i18n/lang.inc @@ -0,0 +1,10 @@ +struc lang_entry + .code: resb 2 + .data: resd 1 + .next: resd 1 +endstruc + +struc msg_table + .hello_world: resd 1 + .cpu_exceptions: resd 32 +endstruc diff --git a/kernel/i18n/msg_en.s b/kernel/i18n/msg_en.s index a056b17..408ab15 100644 --- a/kernel/i18n/msg_en.s +++ b/kernel/i18n/msg_en.s @@ -1,22 +1,22 @@ ; file: msg_en.s ; English strings -%include "i18n.inc" +%include "i18n/lang.inc" -.section rodata +section .rodata global lang_en lang_en: istruc lang_entry - at lang_entry.code: db "en" - at lang_entry.data: dd msg_en - at lang_entry.next: dd 0 + at lang_entry.code, db "en" + at lang_entry.data, dd msg_en + at lang_entry.next, dd 0 iend +global msg_en msg_en: istruc msg_table - at msg_table.hello_world: dd msg_hello_world - - at msg_table.cpu_exceptions: + at msg_table.hello_world, dd msg_hello_world + at msg_table.cpu_exceptions, dd msg_int_division_zero dd msg_int_debug dd msg_int_nmi diff --git a/kernel/intro.txt b/kernel/intro.txt new file mode 100644 index 0000000000000000000000000000000000000000..3f79d60e6014cdeecf820d996ca96ed2ebef81fa GIT binary patch literal 486 zcmZvZL2JTL5QK*wJ@?qd5)dqu{(w+C3gW>-enB*`K8z-)iR90>ew&z8i6zWvaC$4#X!-I0;#;3MA8-%(OyvrkbNSZD5vg430Z&!7rS+ zQ;)d;+!S$FXalNq}EG5tQ?s5C% z_6h%L4m!f~ZmxO%XTF4fHA>&X*tY3>8Z k`2@?)ph($uTzP(Yc_n?+2KJ7(8+%{W{$PW$VN?HicVWCrbpQYW literal 0 HcmV?d00001