Tvùrce webu je i pro tebe! Postav tøeba web. Bez grafika. Bez kodéra. Hned.
wz

LITOS.ASM

Main Module

Compilation: NASM16.EXE -o LITOS.SYS LITOS.ASM


; =============================================================================
;
;                              Litos - Kernel
;
; =============================================================================

; The system is loaded from the second 4 KB page of memory (first 4 KB page
; is reserved for BIOS use), e.g. from address 0:1000h, starting with CS=0
; and IP=1000h. It enables easy share code to 16-bit and 32-bit instructions.
; Later it will be relocated to 2 GB position of memory (80000000h) and
; therefore whole kernel is compiled for this address. Real-mode instructions
; accept only low 16 bits of address and then it works mostly with this
; correctly. 

; ------------- Compiler configuration

%define		DEBUG			; config - display DEBUG info
;%define	MINI			; config - generate mini kernel
					;  - only 1 processor (else 32)
					;  - max. 256 MB of RAM (else 2 GB)
					;  - max. 250 tasks (else 4090)
					;  - max. 3FFh I/O port (else 0FFFFh)
					;  - 4 KB task stack (else 8 KB)

; ------------- System version

VER_MAJOR	EQU	0		; version - major
VER_MINOR	EQU	1		; version - minor (in hundredths)
VER_BUILD	EQU	1		; version - build

; ------------- Kernel setup

LINUX_INT	EQU	80h		; Linux system call vector
SYSTEM_INT	EQU	90h		; Litos system call vector

SYSTEM_ADDR	EQU	80000000h	; address of system area (at 2 GB)
					;   It must be multiple of 64KB due
					;   to portability between 32b/16b
%ifdef MINI
SYSTEM_SIZE	EQU	10000000h	; size of system area (256 MB)
%else
SYSTEM_SIZE	EQU	0ffffffffh-SYSTEM_ADDR+1 ; size of system area (2 GB)
%endif

; ------------- Processor

%ifndef MINI
%define	SMP				; flag-enable symetric multiprocessors
%endif

%ifdef	SMP
CPU_MAX		EQU	32		; max. number of CPUs in SMP (max. 32)
%else
CPU_MAX		EQU	1		; maximal number of CPUs in UP
%endif

; -----------------------------------------------------------------------------
;                            Program sections
; -----------------------------------------------------------------------------
; Kernel uses 3 main types of program sections:
;
; - initialized data
; - code section, initialization (16-bit part and 32-bit part)
; - code section, kernel (16-bit part and 32-bit part)
; - exception fixup sections
; - uninitialized data
;
; Initialized data must be accessible from both real mode and protected mode
; and therefore it must lie in first 64 KB memory area (together with 16-bit
; part of code section). Therefore it is the first section of the kernel, so
; "text" section must be used. Behind it lies code section (using "data") and
; then exception services ("fix", "exc") and unitialized data "bss".
; -----------------------------------------------------------------------------

; ------------- Data section

%macro		DATA_SECTION	0
SECTION		.text
%endmacro

SECTION		.text
		org	80001000h	; start address of the system
KernelStart:				; start of kernel (PAGE aligned)
DataStart:				; start of data section

; ------------- Code section (%1 = 32 or 16, e.g. number of bits)

%macro		CODE_SECTION	1
SECTION		.data
BITS		%1
%endmacro

SECTION		.data align=16
DataEnd:				; end of data section
CodeStart:				; start of code section

; ------------- Constant data section

%macro		CONST_SECTION	0
SECTION		.const
%endmacro

SECTION		.const align=16
CodeEnd:				; end of code section
ConstStart:				; start of constant data section

; ------------- Exception fixup section

%macro		FIX_SECTION	0
SECTION		.fix
BITS		32
%endmacro

SECTION		.fix align=16
ConstEnd:				; end of constant data section
FixStart:				; start of exception fixup section

; ------------- Exception table section - exception address

%macro		EXC_SECTION	0
SECTION		.exc
%endmacro

SECTION		.exc align=16
FixEnd:					; end of exception fixup section
ExcStart:				; start of exception table section

; ------------- Exception table section - fixup address

%macro		EXC2_SECTION	0
SECTION		.exc2
%endmacro

SECTION		.exc2
ExcEnd:					; end of exception fixup section
Exc2Start:				; start of exception table section

; ------------- Unitialized section

%macro		BSS_SECTION	0
SECTION		.bss
%endmacro

SECTION		.bss align=4096
Exc2End:				; end of exception table section
BSSStart:				; start of unitialized data

; -----------------------------------------------------------------------------
;         Start of system at 0000:1000  (jump here from BOOT\BOOT.ASM)
; -----------------------------------------------------------------------------

		DATA_SECTION
BITS		16

Start:		jmp	near Start16	; init real mode (-> INIT\INIT.ASM)
		align	4

; ------------- Identification (offset 4 from the begin)

Ident:		dw	8A26h		; identification word

; ------------- System version (in form: version X.XX)

VersionMinor:	db	VER_MINOR	; version - minor (in hundredths)
VersionMajor:	db	VER_MAJOR	; version - major

; ------------- Size of kernel in memory

		dd	KernelEnd - SYSTEM_ADDR

; ------------- Configuration

ConfigCon:	db	B0		; console configuration
					;	B0: 1=output to display
					;	B1: 1=output to COM1
					;	B2: 1=output to COM2
					;	B3: 1=output to COM3
					;	B4: 1=output to COM4

; -----------------------------------------------------------------------------
;                        Includes - definitions
; -----------------------------------------------------------------------------

%include	"INCLUDE\CONSTANT.INC"	; constants
%include	"INCLUDE\ERRORS.INC"	; error codes
%include	"INCLUDE\EXCEPTION.INC"	; exceptions
%include	"INCLUDE\CPU.INC"	; processor
%include	"INCLUDE\SPINLOCK.INC"	; spin-lock
%include	"INCLUDE\LIST.INC"	; list
%include	"INCLUDE\HASH.INC"	; hash list
%include	"INCLUDE\TREE.INC"	; tree list
%include	"INCLUDE\TASKLOCK.INC"	; task lock
%include	"INCLUDE\SEMAPHOR.INC"	; semaphore and mutex
%include	"INCLUDE\TEXT.INC"	; text string
%include	"INCLUDE\IRQ.INC"	; interrupt request
%include	"INCLUDE\TRAPS.INC"	; traps
%include	"INCLUDE\PAGE.INC"	; memory pages
%include	"INCLUDE\CROSS.INC"	; cross list
%include	"INCLUDE\ALARM.INC"	; alarm
%include	"INCLUDE\BUFFER.INC"	; buffer array
%include	"INCLUDE\RBTREE.INC"	; red-black balanced tree
%include	"INCLUDE\OBJECT.INC"	; objects
%include	"INCLUDE\VIRTMEM.INC"	; virtual memory
%include	"INCLUDE\TASK.INC"	; task
%include	"INCLUDE\PROCESS.INC"	; process
%include	"INCLUDE\GLDT.INC"	; global/local descriptor
%include	"INCLUDE\IDT.INC"	; interrupt descriptor
%include	"INCLUDE\CALENDAR.INC"	; calendar, date and time
%include	"INCLUDE\SIGNAL.INC"	; signals

; ------------- Drivers

%include	"INCLUDE\DRIVERS\DRIVER.INC"	; general driver
%include	"INCLUDE\DRIVERS\CHARSET.INC"	; character sets
%include	"INCLUDE\DRIVERS\DISPLAY.INC"	; general display
%include	"INCLUDE\DRIVERS\KEYBOARD.INC"	; keyboard driver
%include	"INCLUDE\DRIVERS\CONSOLE.INC"	; console
%include	"INCLUDE\DRIVERS\VT102.INC"	; VT102 terminal emulator
%include	"INCLUDE\DRIVERS\DATADEV.INC"	; data device
%include	"INCLUDE\DRIVERS\DISK.INC"	; block device
%include	"INCLUDE\DRIVERS\FLOPPY.INC"	; floppy disk

; -----------------------------------------------------------------------------
;                Unitialized buffers (it must be PAGE aligned!)
; -----------------------------------------------------------------------------

		BSS_SECTION

; ------------- Kernel page directory (4 KB, must be 4 KB aligned)

		align	PAGE_SIZE, resb 1; align to page size (already aligned)
PageDir:	resb	PAGE_SIZE	; page directory (holds 1024 PDEs)

; ------------- Empty zero page (4 KB, must be 4 KB aligned)

		align	PAGE_SIZE, resb 1; align to page size (already aligned)
PageEmpty:	resb	PAGE_SIZE	; empty zero page (contains zeros)

; ------------- System global descriptor table (size 64 KB or 4 KB)

		align	PAGE_SIZE, resb 1; align to page size (already aligned)
SystemGDTTab:	resb	SYSTEM_GDT_NUM*GLDT_size ; system GDT
SystemGDTTabEnd:
TaskLDTTab	EQU	SystemGDTTab+TASK_GDT_LDT*GLDT_size ; task LDT descr.
TaskTSSTab:	EQU	SystemGDTTab+TASK_GDT_TSS*GLDT_size ; task TSS descr.

; ------------- Memory bit map of available 4 KB pages (size 64 KB or 8 KB)
; This bit map will be later (after initialization) freed as free DMA memory.

		align	PAGE_SIZE, resb 1; align to page size (already aligned)
PageMemMap:	resb	SYSTEM_SIZE/PAGE_SIZE/8 ; memory bit map of free pages

; ------------- System interrupt descriptor table (6 KB or 2 KB)
; Correction of Intel Pentium F00F bug: see InitPDE in INIT\INIT_32.ASM.

		align	PAGE_SIZE,resb 1; align to page size (already aligned)
		resb	PAGE_SIZE - 56	; 56 bytes before end of page
SystemIDTTab:	resb	256*8		; system interrupt descriptor table

; -----------------------------------------------------------------------------
;                                Includes - code
; -----------------------------------------------------------------------------

; ------------- Initialization in real mode

%include	"INIT\INIT.ASM"		; initialization, real mode
%include	"INIT\INIT_DBG.ASM"	; initialization, debug
%include	"INIT\INIT_GRA.ASM"	; initialize graphics card
%include	"INIT\INIT_HD.ASM"	; initialize hard drives
%include	"INIT\INIT_MEM.ASM"	; initialize memory map
%include	"INIT\INIT_APM.ASM"	; initialize advanced power management
%include	"INIT\INIT_A20.ASM"	; initialize A20 address line

; ------------- Initialization in protected mode

%include	"INIT\INIT_32.ASM"	; initialization, protected mode
%include	"INIT\INIT_CPU.ASM"	; initialize CPU
%include	"INIT\INIT_SYS.ASM"	; initialize kernel

; ------------- Utilities

%include	"UTIL\SPINLOCK.ASM"	; spin-lock
%include	"UTIL\LIST.ASM"		; list
%include	"UTIL\HASH.ASM"		; hash list
%include	"UTIL\TREE.ASM"		; tree list
%include	"UTIL\RWLOCK.ASM"	; read/write spin-lock (unused now)
%include	"UTIL\TASKLOCK.ASM"	; task lock
%include	"UTIL\SEMAPHOR.ASM"	; semaphore and mutex
%include	"UTIL\RBTREE.ASM"	; red-black balanced tree
%include	"UTIL\RANDOM.ASM"	; random generator
%include	"UTIL\OBJECT.ASM"	; objects
%include	"UTIL\BUFFER.ASM"	; buffer array
%include	"UTIL\TEXT.ASM"		; text string

; ------------- Kernel

%include	"KERNEL\SYSMEM.ASM"	; system memory allocator
%include	"KERNEL\VIRTMEM.ASM"	; virtual memory
%include	"KERNEL\PAGE.ASM"	; memory pages
%include	"KERNEL\CPU.ASM"	; processor
%include	"KERNEL\DMA.ASM"	; DMA channel
%include	"KERNEL\IRQ.ASM"	; interrupt request
%include	"KERNEL\TASK.ASM"	; task
%include	"KERNEL\TRAPS.ASM"	; traps
%include	"KERNEL\SYSTEM.ASM"	; system calls
%include	"KERNEL\LINUX.ASM"	; Linux system calls
%include	"KERNEL\TIME.ASM"	; time
%include	"KERNEL\ALARM.ASM"	; alarm
%include	"KERNEL\CALENDAR.ASM"	; calendar
%include	"KERNEL\SCHEDULE.ASM"	; scheduler
%include	"KERNEL\SIGNAL.ASM"	; signals

; ------------- Drivers

%include	"DRIVERS\FONT\F08.ASM"		; font 8x8
%include	"DRIVERS\FONT\F10.ASM"		; font 8x10
%include	"DRIVERS\FONT\F14.ASM"		; font 8x14
%include	"DRIVERS\DRIVER.ASM"		; general driver
%include	"DRIVERS\CHARSET.ASM"		; character sets
%include	"DRIVERS\VIDEO\DISPLAY.ASM"	; general display
%include	"DRIVERS\VIDEO\TXT.ASM"		; TXT display
%include	"DRIVERS\VIDEO\HGC.ASM"		; HGC display (Hercules)
%include	"DRIVERS\VIDEO\CGA.ASM"		; CGA display
%include	"DRIVERS\VIDEO\EGA.ASM"		; EGA display
%include	"DRIVERS\VIDEO\VGA.ASM"		; VGA display
%include	"DRIVERS\VIDEO\SVGA.ASM"	; SVGA display
%include	"DRIVERS\KEYBOARD.ASM"		; keyboard driver
%include	"DRIVERS\CONSOLE.ASM"		; console
%include	"DRIVERS\VT102.ASM"		; VT102 terminal emulator
%include	"DRIVERS\DATADEV.ASM"		; data device
%include	"DRIVERS\DISK.ASM"		; block device
%include	"DRIVERS\FLOPPY.ASM"		; floppy disk

; -----------------------------------------------------------------------------
;                       End of unitialized data
; -----------------------------------------------------------------------------

		BSS_SECTION

		align	PAGE_SIZE, resb 1
BSSEnd:					; end of unitialized data (PAGE align.)
KernelEnd:				; end of kernel (PAGE aligned)

Back to source browser