Skip to content

Commit

Permalink
docs: documente ISA/AT buses I/O Port map
Browse files Browse the repository at this point in the history
  • Loading branch information
d0p1s4m4 committed Jul 13, 2023
1 parent a9fec6e commit 08a7d5c
Show file tree
Hide file tree
Showing 14 changed files with 277 additions and 32 deletions.
32 changes: 21 additions & 11 deletions docs/config/Menu.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Group: AT {

File: serial.s (no auto-title, kernel/drivers/serial.s)
} # Group: Driver
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 {
Expand Down
4 changes: 3 additions & 1 deletion kernel/Makefile
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
11 changes: 8 additions & 3 deletions kernel/boot/head.s
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ align 4
section .multiboot.text

;; Function: entry
;;
;; Setup boot page table, map kernel to higher half
;; then jump to <entry_high>
;;
;; in:
;; EAX - Multiboot magic
Expand Down Expand Up @@ -83,16 +84,20 @@ entry:

section .text

;; Function: entry_high
;; Invalidate page[0], setup stack then call <kmain>
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

Expand Down
25 changes: 25 additions & 0 deletions kernel/boot/memory.s
Original file line number Diff line number Diff line change
@@ -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
59 changes: 59 additions & 0 deletions kernel/cpu.inc
Original file line number Diff line number Diff line change
@@ -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
Expand Down
72 changes: 72 additions & 0 deletions kernel/dev/at/cmos.s
Original file line number Diff line number Diff line change
@@ -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





54 changes: 54 additions & 0 deletions kernel/dev/at/intro.txt
Original file line number Diff line number Diff line change
@@ -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 |
> +---------------+-------------------------+

Empty file added kernel/dev/at/kbd.S
Empty file.
15 changes: 15 additions & 0 deletions kernel/dev/at/pit.s
Original file line number Diff line number Diff line change
@@ -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)

File renamed without changes.
11 changes: 2 additions & 9 deletions kernel/i18n/i18n.inc
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions kernel/i18n/lang.inc
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 08a7d5c

Please sign in to comment.