Permalink
Browse files

Updated interrupts to better support a missing clock device

  • Loading branch information...
1 parent 8cf1402 commit 11d3624607afcf6081e304a5c597038750f9e3a3 @SirCmpwn SirCmpwn committed Oct 8, 2012
Showing with 519 additions and 485 deletions.
  1. +14 −14 README.md
  2. +37 −37 docs/text/bootToDisk.md
  3. +109 −109 docs/text/memorytables.md
  4. +35 −32 inc/equates.dasm
  5. +22 −22 inc/macros.dasm
  6. +12 −12 src/base.dasm
  7. +35 −27 src/boot.dasm
  8. +23 −23 src/drivers/base.dasm
  9. +23 −21 src/drivers/genericclock.dasm
  10. +34 −34 src/hardware.dasm
  11. +28 −28 src/interrupts.dasm
  12. +111 −111 src/memory.dasm
  13. +36 −15 src/threads.dasm
View
@@ -1,15 +1,15 @@
-# 0x42c-kernel
-
-0x42c-kernel is a standalone multithreaded kernel for DCPU-16, which forms the basis for 0x42c.
-
-## Building from Source
-
-Clone the repository and run the appropriate script in build/
-
-Mono is required on Linux and Mac.
-
-## Implementing
-
-Presently, you are not able to use 0x42c-kernel realisticly in your projects. Please await official
-disk drive specifications from Notch, at which point 0x42c-kernel will support loading an operating
+# 0x42c-kernel
+
+0x42c-kernel is a standalone multithreaded kernel for DCPU-16, which forms the basis for 0x42c.
+
+## Building from Source
+
+Clone the repository and run the appropriate script in build/
+
+Mono is required on Linux and Mac.
+
+## Implementing
+
+Presently, you are not able to use 0x42c-kernel realisticly in your projects. Please await official
+disk drive specifications from Notch, at which point 0x42c-kernel will support loading an operating
system from disk and an implementation guide will be written.
@@ -1,38 +1,38 @@
-# 0x42c Boot to Disk
-
-The default boot mechanism for 0x42c is to boot to the supplied disk, using one of
-the default disk drivers. The kernel does the following:
-
-1. Allocate 512 words of memory and copy the first sector of the disk to memory.
-2. Check the header to determine the image type.
-
-The header of this disk includes one word to identify the type. These are:
-0x0000: Directly executable boot sector
-0x0001: Full memory image
-0x0002: Filesystem disk
-
-## Directly executable boot sector
-
-For this type of disk, 0x42c-kernel will relocate the sector. The sector should
-have a relocation table directly following the type identifier. Then, it will
-pass control to the boot sector with interrupts disabled.
-
-## Full memory image
-
-For this type of disk, 0x42c-kernel will copy the contents of the disk from 0x0000-
-0x8000 to DCPU memory, starting at 0x8000. It will then pass control to the image
-with interrupts disabled. Note that memory management routines are not available to
-full memory images.
-
-## Filesystem disk
-
-For this type of disk, the header format is as follows:
-
- 0000: Type ID (0x0002 for filesystem disk)
- 0001: Zero-delimited string of first file to execute (usually /bin/init)
- nnnn: Relocation table for following 0x42c-kernel file stream driver
- nnnn: File stream driver
-
-0x42c-kernel will copy the driver to memory and relocate it, then it will launch the
-specified file as a program and pass execution to it with interrupts and context
+# 0x42c Boot to Disk
+
+The default boot mechanism for 0x42c is to boot to the supplied disk, using one of
+the default disk drivers. The kernel does the following:
+
+1. Allocate 512 words of memory and copy the first sector of the disk to memory.
+2. Check the header to determine the image type.
+
+The header of this disk includes one word to identify the type. These are:
+0x0000: Directly executable boot sector
+0x0001: Full memory image
+0x0002: Filesystem disk
+
+## Directly executable boot sector
+
+For this type of disk, 0x42c-kernel will relocate the sector. The sector should
+have a relocation table directly following the type identifier. Then, it will
+pass control to the boot sector with interrupts disabled.
+
+## Full memory image
+
+For this type of disk, 0x42c-kernel will copy the contents of the disk from 0x0000-
+0x8000 to DCPU memory, starting at 0x8000. It will then pass control to the image
+with interrupts disabled. Note that memory management routines are not available to
+full memory images.
+
+## Filesystem disk
+
+For this type of disk, the header format is as follows:
+
+ 0000: Type ID (0x0002 for filesystem disk)
+ 0001: Zero-delimited string of first file to execute (usually /bin/init)
+ nnnn: Relocation table for following 0x42c-kernel file stream driver
+ nnnn: File stream driver
+
+0x42c-kernel will copy the driver to memory and relocate it, then it will launch the
+specified file as a program and pass execution to it with interrupts and context
switching enabled.
@@ -1,110 +1,110 @@
-# Table structure
-
-0x42c-kernel has several tables in memory for storing information in, including thread
-information, libraries, signals, and more. The structure of these tables is defined in
-this document.
-
-## Thread List
-
-The thread list starts at [thread_table] and is 0x100 words long. Each entry is 8 words
-long, allowing for a total of 32 concurrent threads. Each entry is structured as such:
-
- 0000: Thread ID
- 0001: Address of thread
- 0002: Stack pointer
- 0003: Flags (bit mask)
- 00: May be suspended
- 01: Is suspended
- 02-07: Reserved for future use
- 08-15: User flags
- 0004: Pointer to file path (or 0xFFFF for threads with no related file)
- 0005: Parent thread
- 0006-0007: Reserved for future use
-
-User flags are available for any use, and may be delegated as each thread and its caller
-see fit. When the parent thread is terminated, all child threads are terminated as well.
-
-# Library List
-
-The library list starts at [library_table] and is 0x100 words long. Each entry is 4 words
-long, allowing for a total of 64 concurrently loaded libraries. Each entry is structured
-as such:
-
- 0000: Library ID
- 0001: Address of library
- 0002: Current usage
- 0003: Pointer to library file path
-
-"Current usage" refers to the total number of processes that depend on this library. A
-process is defined as any thread with no parent.
-
-# Signal List
-
-Signals are simple mechanisms for moving data between active threads. The signal list
-starts at [signal_table] and is 0x100 words long. Each entry is 4 words long, allowing
-for a total of 64 pending signals. Ideally, this cap will never be reached, as
-developers are encouraged to consume pending signals quickly. Each entry is structured
-as such:
-
- 0000: Recipient thread ID
- 0001: Originating thread ID
- 0002: Reserved for future use
- 0003: Signal
-
-When more complex data than a single word can represent must be sent between threads,
-developers are encouraged to send a pointer to more data in the signal.
-
-# File List
-
-The file list is a list of active file handles. The file list starts at [file_table] and
-is 0x100 words long. Each entry is 16 words long, allowing for a maximum of 16 active
-file handles. This table is more ambiguously structured, to allow for greater
-flexibility with various storage devices.
-
- 0000: File handle ID
- 0001: Owning thread ID
- 0002: File driver address
- 0003: Flags (bit mask)
- 00: Readable
- 01: Writable
- 02: May seek
- 03-15: Reserved for driver use
- 0004-000F: Reserved for driver use
-
-The file driver address points to a file driver object in memory. The structure of this
-is as such:
-
- 0000: Address of read function
- 0001: Address of write function
- 0002: Address of seek function
- 0003: Address of length function
-
-The signatures of these methods is as such:
-
- void read(uint16 fileHandleId, uint16* destination, uint16 length);
- void write(uint16 fileHandleId, uint16* data, uint16 length);
- void seek(uint16 fileHandleId, uint32 address);
- uint32 length(uint16 fileHandleId);
-
-0x42c-kernel ships with a driver for the M35FD floppy drive. The structure of a file
-handle when being managed by the M35FD driver is as such:
-
- 0000: File handle ID
- 0001: Owning thread ID
- 0002: File driver address
- 0003: Flags (bit mask)
- 00: Readable
- 01: Writable
- 02: May seek
- 03-15: Reserved for future use
- 0004: Disk drive hardware ID
- 0005: Current sector
- 0006: Current address
- 0007: Sector of metadata entry
- 0008: Address of metadata entry
- 0009: Address of data entry
- 000A: Length of file LSB
- 000B: Length of file MSB
- 000C-000F: Reserved for future use
-
+# Table structure
+
+0x42c-kernel has several tables in memory for storing information in, including thread
+information, libraries, signals, and more. The structure of these tables is defined in
+this document.
+
+## Thread List
+
+The thread list starts at [thread_table] and is 0x100 words long. Each entry is 8 words
+long, allowing for a total of 32 concurrent threads. Each entry is structured as such:
+
+ 0000: Thread ID
+ 0001: Address of thread
+ 0002: Stack pointer
+ 0003: Flags (bit mask)
+ 00: May be suspended
+ 01: Is suspended
+ 02-07: Reserved for future use
+ 08-15: User flags
+ 0004: Pointer to file path (or 0xFFFF for threads with no related file)
+ 0005: Parent thread
+ 0006-0007: Reserved for future use
+
+User flags are available for any use, and may be delegated as each thread and its caller
+see fit. When the parent thread is terminated, all child threads are terminated as well.
+
+# Library List
+
+The library list starts at [library_table] and is 0x100 words long. Each entry is 4 words
+long, allowing for a total of 64 concurrently loaded libraries. Each entry is structured
+as such:
+
+ 0000: Library ID
+ 0001: Address of library
+ 0002: Current usage
+ 0003: Pointer to library file path
+
+"Current usage" refers to the total number of processes that depend on this library. A
+process is defined as any thread with no parent.
+
+# Signal List
+
+Signals are simple mechanisms for moving data between active threads. The signal list
+starts at [signal_table] and is 0x100 words long. Each entry is 4 words long, allowing
+for a total of 64 pending signals. Ideally, this cap will never be reached, as
+developers are encouraged to consume pending signals quickly. Each entry is structured
+as such:
+
+ 0000: Recipient thread ID
+ 0001: Originating thread ID
+ 0002: Reserved for future use
+ 0003: Signal
+
+When more complex data than a single word can represent must be sent between threads,
+developers are encouraged to send a pointer to more data in the signal.
+
+# File List
+
+The file list is a list of active file handles. The file list starts at [file_table] and
+is 0x100 words long. Each entry is 16 words long, allowing for a maximum of 16 active
+file handles. This table is more ambiguously structured, to allow for greater
+flexibility with various storage devices.
+
+ 0000: File handle ID
+ 0001: Owning thread ID
+ 0002: File driver address
+ 0003: Flags (bit mask)
+ 00: Readable
+ 01: Writable
+ 02: May seek
+ 03-15: Reserved for driver use
+ 0004-000F: Reserved for driver use
+
+The file driver address points to a file driver object in memory. The structure of this
+is as such:
+
+ 0000: Address of read function
+ 0001: Address of write function
+ 0002: Address of seek function
+ 0003: Address of length function
+
+The signatures of these methods is as such:
+
+ void read(uint16 fileHandleId, uint16* destination, uint16 length);
+ void write(uint16 fileHandleId, uint16* data, uint16 length);
+ void seek(uint16 fileHandleId, uint32 address);
+ uint32 length(uint16 fileHandleId);
+
+0x42c-kernel ships with a driver for the M35FD floppy drive. The structure of a file
+handle when being managed by the M35FD driver is as such:
+
+ 0000: File handle ID
+ 0001: Owning thread ID
+ 0002: File driver address
+ 0003: Flags (bit mask)
+ 00: Readable
+ 01: Writable
+ 02: May seek
+ 03-15: Reserved for future use
+ 0004: Disk drive hardware ID
+ 0005: Current sector
+ 0006: Current address
+ 0007: Sector of metadata entry
+ 0008: Address of metadata entry
+ 0009: Address of data entry
+ 000A: Length of file LSB
+ 000B: Length of file MSB
+ 000C-000F: Reserved for future use
+
The M35FD driver is designed to read files from a 42c file system (FTCFS).
View
@@ -1,33 +1,36 @@
-; Equates for 0x42c-kernel, defining memory locations and other information.
-; Licensed with the MIT license.
-
-; All values are subject to change prior to release
-
-; Memory locations
-kernel_exec .equ 0x0000 ; Executable kernel space
-kernel_data .equ 0x5000
- ; Data tables, such as thread lists
- thread_table .equ 0x5000
- library_table .equ 0x5100
- signal_table .equ 0x5200
- file_table .equ 0x5300 ; open file handles
- interrupt_table .equ 0x5400 ; length: 0x50 words
- ; Kernel variables
- current_thread_index .equ 0x5500
- active_threads .equ 0x5501
- active_libraries .equ 0x5502
- pending_signals .equ 0x5503
- open_file_handles .equ 0x5504
- active_interrupts .equ 0x5505
-
- next_thread_id .equ 0x5510
-kernel_temp .equ 0x6000
-kernel_jump_table .equ 0x7000
-
-userspace_memory .equ 0x8000 ; inclusive
-userspace_memory_end .equ 0x0000 ; non-inclusive
-; Useful values
-null_thread .equ -1
-permenant_memory .equ -2
-
+; Equates for 0x42c-kernel, defining memory locations and other information.
+; Licensed with the MIT license.
+
+; All values are subject to change prior to release
+
+; Memory locations
+kernel_exec .equ 0x0000 ; Executable kernel space
+kernel_data .equ 0x5000
+ ; Data tables, such as thread lists
+ thread_table .equ 0x5000
+ library_table .equ 0x5100
+ signal_table .equ 0x5200
+ file_table .equ 0x5300 ; open file handles
+ interrupt_table .equ 0x5400 ; length: 0x50 words
+ ; Kernel variables
+ current_thread_index .equ 0x5500
+ active_threads .equ 0x5501
+ active_libraries .equ 0x5502
+ pending_signals .equ 0x5503
+ open_file_handles .equ 0x5504
+ active_interrupts .equ 0x5505
+
+ next_thread_id .equ 0x5510
+
+ context_switch_enabled .equ 0x5520
+kernel_temp .equ 0x6000
+kernel_jump_table .equ 0x7000
+
+userspace_memory .equ 0x8000 ; inclusive
+userspace_memory_end .equ 0x0000 ; non-inclusive
+; Useful values
+null_thread .equ -1
+permenant_memory .equ -2
+max_threads .equ 32
+
context_switch_frequency .equ 60 ; The target frequency of context switching, in hertz
Oops, something went wrong.

0 comments on commit 11d3624

Please sign in to comment.