remove boot dir

This commit is contained in:
Murphy 2025-04-08 17:47:04 -04:00
parent f2f42a6688
commit 7c83d33976
Signed by: freya
GPG key ID: 9FBC6FFD6D2DBF17
5 changed files with 0 additions and 1165 deletions

View file

@ -1,666 +0,0 @@
/**
** SCCS ID: @(#)boot.S 2.4 1/22/25
**
** @file boot.S
**
** @author Jon Coles
** copyleft 1999 Jon Coles
**
** @author Warren R. Carithers, K. Reek, Garrett C. Smith
** @author Walter Litwinczyk, David C. Larsen, Sean T. Congden
**
** Bootstrap routine.
**
** This bootstrap program is loaded by the PC BIOS into memory at
** location 0000:7C00. It must be exactly 512 bytes long, and must
** end with the hex sequence AA55 at location 1FE.
**
** The bootstrap initially sets up a stack in low memory. Next, it
** loads a second sector at 0000:7E00 (immediately following the
** boot block). Then it loads the target program at TARGET_ADDR,
** switches to protected mode, and branches to the target program.
**
** NOTE: To zero out the BSS segment, define CLEAR_BSS when this code
** is assembled.
**
** Must assemble this as 16-bit code.
*/
.code16
#define ASM_SRC
#include <bootstrap.h>
#include <bios.h>
#include <arch.h>
/*
** Symbol for locating the beginning of the code.
*/
.globl bootentry
.text
bootentry:
/*
** Entry point. Disable interrupts and set up a runtime stack.
*/
cli
movw $BOOT_SEG, %ax /* data seg. base address */
movw %ax, %ds
movw %ax, %ss /* also stack seg. base */
movw $BOOT_SP_DISP, %ax
movw %ax, %sp
/*
** Next, verify that the disk is there and working.
*/
movb $BD_CHECK, %ah /* test the disk status and make sure */
movb drive, %dl /* it's safe to proceed */
int $BIOS_DISK
jnc diskok
movw $err_diskstatus, %si /* Something went wrong; print a message */
call dispMsg /* and freeze. */
jmp .
/*
** The disk is there. Reset it, and retrieve the disk parameters.
*/
diskok:
movw $BD_RESET, %ax /* Reset the disk */
movb drive, %dl
int $BIOS_DISK
/* determine number of heads and sectors/track */
xorw %ax, %ax /* set ES:DI = 0000:0000 in case of BIOS bugs */
movw %ax, %es
movw %ax, %di
movb $BD_PARAMS, %ah /* get drive parameters */
movb drive, %dl /* hard disk or floppy */
int $BIOS_DISK
/* store (max + 1) - CL[5:0] = maximum head, DH = maximum head */
andb $0x3F, %cl
incb %cl
incb %dh
movb %cl, max_sec
movb %dh, max_head
/*
** The disk is OK, so we now need to load the second half of the bootstrap.
** It must immediately follow the boot sector on the disk, and the target
** program(s) must immediately follow that.
*/
movw $msg_loading, %si /* Print the Loading message */
call dispMsg
movw $1, %ax /* sector count = 1 */
movw $BOOT_SEG, %bx /* read this into memory that */
movw %bx, %es /* immediately follows this code. */
movw $PART2_DISP, %bx
call readprog
/*
** We've got the second block of the bootstrap program in memory. Now
** read all of the user's program blocks. Use %di to point to the
** count field for the next block to load.
*/
movw $k_sect, %di
pushw %ds
movw (%di), %bx
movw $MMAP_SEG, %ax
movw %ax, %ds
movw %bx, MMAP_SECTORS /* store kernel image size */
popw %ds
/*
** Each target program has three values in the array at the end of the
** second half of the bootstrap: the offset and segment base address
** where the program should go, and the sector count.
*/
nextblock:
movw (%di), %ax /* get the # of sectors */
testw %ax, %ax /* is it zero? */
jz done_loading /* yes, nothing more to load. */
subw $2, %di
movw (%di), %bx /* get the segment value */
movw %bx, %es /* and copy it to %es */
subw $2, %di
movw (%di), %bx /* get the address offset */
subw $2, %di
pushw %di /* save di */
call readprog /* read this program block, */
popw %di /* and restore di */
jmp nextblock /* then go back and read the next one. */
/*
** Read one complete program block into memory.
**
** ax: number of sectors to read
** es:bx = starting address for the block
*/
readprog:
pushw %ax /* save sector count */
movw $3, %cx /* initial retry count is 3 */
retry:
pushw %cx /* push the retry count on the stack. */
movw sec, %cx /* get sector number */
movw head, %dx /* get head number */
movb drive, %dl
movw $BD_READ1, %ax /* read 1 sector */
int $BIOS_DISK
jnc readcont /* jmp if it worked ok */
movw $err_diskread, %si /* report the error */
call dispMsg
popw %cx /* get the retry count back */
loop retry /* and go try again. */
movw $err_diskfail, %si /* can't proceed, */
call dispMsg /* print message and freeze. */
jmp .
readcont:
movw $msg_dot, %si /* print status: a dot */
call dispMsg
cmpw $OFFSET_LIMIT, %bx /* have we reached the offset limit? */
je adjust /* Yes--must adjust the es register */
addw $SECTOR_SIZE, %bx /* No--just adjust the block size to */
jmp readcont2 /* the offset and continue. */
adjust:
movw $0, %bx /* start offset over again */
movw %es, %ax
addw $0x1000,%ax /* move segment pointer to next chunk */
movw %ax, %es
readcont2:
incb %cl /* not done - move to the next sector */
cmpb max_sec, %cl /* see if we need */
jnz save_sector /* to switch heads or tracks */
movb $1, %cl /* reset sector number */
incb %dh /* first, switch heads */
cmpb max_head, %dh /* there are only two - if we've already */
jnz save_sector /* used both, we need to switch tracks */
xorb %dh, %dh /* reset to head 0 */
incb %ch /* inc track number */
cmpb $80, %ch /* 80 tracks per side - have we read all? */
jnz save_sector /* read another track */
movw $err_toobig, %si /* report the error */
call dispMsg
jmp . /* and freeze */
save_sector:
movw %cx, sec /* save sector number */
movw %dx, head /* and head number */
popw %ax /* discard the retry count */
popw %ax /* get the sector count from the stack */
decw %ax /* and decrement it. */
jg readprog /* If it is zero, we're done reading. */
readdone:
movw $msg_bar, %si /* print message saying this block is done */
call dispMsg
ret /* and return to the caller */
/*
** We've loaded the whole target program into memory,
** so it's time to transfer to the startup code.
*/
done_loading:
movw $msg_go, %si /* last status message */
call dispMsg
jmp switch /* move to the next phase */
/*
** Support routine - display a message byte by byte to the monitor.
*/
dispMsg:
pushw %ax
pushw %bx
repeat:
lodsb /* grab next character */
movb $BV_W_ADV, %ah /* write and advance cursor */
movw $0x07, %bx /* page 0, white on blank, no blink */
orb %al, %al /* AL is character to write */
jz getOut /* if we've reached the NUL, get out */
int $BIOS_VIDEO /* otherwise, print and repeat */
jmp repeat
getOut: /* we're done, so return */
popw %bx
popw %ax
ret
/*
** Support routine - move the GDT entries from where they are to
** location 0050:0000. We need to add BOOT_ADDR because the bootstrap
** is linked at 0, but loaded at 0x7c00.
*/
move_gdt:
movw %cs, %si
movw %si, %ds
movw $start_gdt + BOOT_ADDR, %si
movw $GDT_SEG, %di
movw %di, %es
xorw %di, %di
movl $gdt_len, %ecx
cld
rep movsb
ret
/*
** DATA AREAS.
**
** Next sector number and head number to read from.
*/
sec: .word 2 /* cylinder=0, sector=1 */
head: .word 0 /* head=0 */
max_sec: .byte 19 /* up to 18 sectors per floppy track */
max_head: .byte 2 /* only two r/w heads per floppy drive */
/*
** Status and error messages.
*/
msg_loading: .asciz "Loading"
msg_dot: .asciz "."
msg_go: .asciz "done."
msg_bar: .asciz "|"
/*
** Error messages.
*/
err_diskstatus: .asciz "Disk not ready.\n\r"
err_diskread: .asciz "Read failed\n\r"
err_toobig: .asciz "Too big\n\r"
err_diskfail: .asciz "Can't proceed\n\r"
/*
** Data areas.
*/
/*
** The GDTR and IDTR contents.
*/
gdt_48:
.word 0x2000 /* 1024 GDT entries x 8 bytes/entry = 8192 */
.quad GDT_ADDR
idt_48:
.word 0x0800 /* 256 interrupts */
.quad IDT_ADDR
/*
** Depending on the age of the BIOS, it may expect there to be a
** partition table for the hard drive you're booting from at this point
** in the boot sector; only the first 446 bytes (0x000-0x1bd) can be
** used for bootstrap code/data. To make life easy, we'll just skip
** over the rest of the sector.
**
** Note: when booting from floppy, this isn't a problem, because floppy
** disks don't have partition tables. On some machines, USB-type storage
** devices are treated as floppies, so they also don't have partition
** maps; however, on other systems, USB storage is treated as hard disk
** storage.
*/
/*
** End of the first sector of the boot program. The last two bytes
** of this sector must be AA55 in order for the disk to be recognized
** by the BIOS as bootable.
*/
.org SECTOR_SIZE-4
drive: .word BDEV /* 0x00 = floppy, 0x80 = usb */
boot_sig:
.word 0xAA55
/*******************************************************
******* BEGINNING OF SECTOR TWO OF THE BOOTSTRAP *******
*******************************************************/
/*
** This code configures the GDT, enters protected mode, and then
** transfers to the OS entry point.
*/
switch:
cli
movb $NMI_DISABLE, %al /* also disable NMIs */
outb %al, $CMOS_ADDR
#ifdef USE_FLOPPY
call floppy_off
#endif
call enable_A20
call move_gdt
#ifdef GET_MMAP
call check_memory
#endif
/*
** Get the memory address for the "user blob" out of the table
** at the end of this sector, and pass the three values to the
** protected mode code in %bx, %cx, and %dx. We could figure out
** how to find it from there, but this is easier.
*/
# movw u_off+BOOT_ADDR, %bx
# movw u_seg+BOOT_ADDR, %cx
# movw u_sect+BOOT_ADDR, %dx
/*
** The IDTR and GDTR are loaded relative to this segment, so we must
** use the full offsets from the beginning of the segment (0000:0000);
** however, we were loaded at 0000:7c00, so we need to add that in.
*/
lidt idt_48 + BOOT_ADDR
lgdt gdt_48 + BOOT_ADDR
movl %cr0, %eax /* get current CR0 */
orl $1, %eax /* set the PE bit */
movl %eax, %cr0 /* and store it back. */
/*
** We'll be in protected mode at the start of the user's code
** right after this jump executes.
**
** First, a byte to force 32-bit mode execution, followed by
** a 32-bit long jump. The long ("far") jump loads both EIP
** and CS with the proper values so that when we land at the
** destination address in protected mode, the next instruction
** fetch doesn't cause a fault.
**
** The old code for this:
**
** .byte 0x66, 0xEA
** .long TARGET_ADDR
** .word GDT_CODE
*/
.byte 0x66
.code32
ljmp $GDT_CODE, $TARGET_ADDR
.code16
/*
** Supporting functions.
*/
#ifdef USE_FLOPPY
/*
** Turn off the motor on the floppy disk drive.
*/
floppy_off:
push %dx
movw $0x3f2, %dx
xorb %al, %al
outb %al, %dx
pop %dx
ret
#endif
/*
** Enable the A20 gate for full memory access.
*/
enable_A20:
call a20wait
movb $KBD_P1_DISABLE, %al
outb %al, $KBD_CMD
call a20wait
movb $KBD_RD_OPORT, %al
outb %al, $KBD_CMD
call a20wait2
inb $KBD_DATA, %al
pushl %eax
call a20wait
movb $KBD_WT_OPORT, %al
outb %al, $KBD_CMD
call a20wait
popl %eax
orb $2, %al
outb %al, $KBD_DATA
call a20wait
mov $KBD_P1_ENABLE, %al
out %al, $KBD_CMD
call a20wait
ret
a20wait: /* wait until bit 1 of the device register is clear */
movl $65536, %ecx /* loop a lot if need be */
wait_loop:
inb $KBD_STAT, %al /* grab the byte */
test $2, %al /* is the bit clear? */
jz wait_exit /* yes */
loop wait_loop /* no, so loop */
jmp a20wait /* if still not clear, go again */
wait_exit:
ret
a20wait2: /* like a20wait, but waits until bit 0 is set. */
mov $65536, %ecx
wait2_loop:
in $KBD_STAT, %al
test $1, %al
jnz wait2_exit
loop wait2_loop
jmp a20wait2
wait2_exit:
ret
#ifdef GET_MMAP
/*
** Query the BIOS to get the list of usable memory regions
**
** Adapted from: http://wiki.osdev.org/Detecting_Memory_%28x86%29
** (see section "BIOS Function INT 0x15. EAX = 0xE820")
**
** After the first 'int', if the location 0x2D00 (4 bytes) contains -1,
** then this method failed to detect memory properly; otherwise, this
** location contains the number of elements read.
**
** The start of the array is at 0x2D04. The elements are tightly
** packed following the layout as defined below. Each entry in the
** array contains the following information:
**
** uint64_t base address of region
** uint64_t length of region (0 --> ignore the entry)
** uint32_t type of region
** uint32_t ACIP 3.0 Extended Attributes
**
** The C struct definition is as follows:
**
** struct MemMapEntry
** {
** uint32_t base[2]; // 64-bit base address
** uint32_t length[2]; // 64-bit length
** uint32_t type; // 32-bit region type
** uint32_t ACPI; // 32-bit ACPI "extended attributes" bitfield
** };
**
** This structure must be packed in memory. This shouldn't be a problem,
** but if it is, you may need to add this attribute at the end of the
** struct declaration before the semicolon:
**
** __attribute__((packed))
**
** Parameters:
** None
**/
check_memory:
// save everything
// pushaw won't work here because we're still in real mode
pushw %ds
pushw %es
pushw %ax
pushw %bx
pushw %cx
pushw %dx
pushw %si
pushw %di
// Set the start of the buffer
movw $MMAP_SEG, %bx // 0x2D0
mov %bx, %ds // Data segment now starts at 0x2D00
mov %bx, %es // Extended segment also starts at 0x2D00
// Reserve the first 4 bytes for the # of entries
movw $0x4, %di
// Make a valid ACPI 3.X entry
movw $1, %es:20(%di)
xorw %bp, %bp // Count of entries in the list
xorl %ebx, %ebx // EBX must contain zeroes
movl $MMAP_MAGIC_NUM, %edx // Magic number into EDX
movl $MMAP_CODE, %eax // E820 memory command
movl $MMAP_ENT, %ecx // Ask the BIOS for 24 bytes
int $BIOS_MISC // Call the BIOS
// check for success
jc cm_failed // C == 1 --> failure
movl $MMAP_MAGIC_NUM, %edx // sometimes EDX changes
cmpl %eax, %edx // EAX should equal EDX after the call
jne cm_failed
testl %ebx, %ebx // Should have at least one more entry
je cm_failed
jmp cm_jumpin // Good to go - start us off
cm_loop:
movl $MMAP_CODE, %eax // Reset our registers
movw $1, 20(%di)
movl $MMAP_ENT, %ecx
int $BIOS_MISC
jc cm_end_of_list // C == 1 --> end of list
movl $MMAP_MAGIC_NUM, %edx
cm_jumpin:
jcxz cm_skip_entry // Did we get any data?
cmp $20, %cl // Check the byte count
jbe cm_no_text // Skip the next test if only 20 bytes
testb $1, %es:20(%di) // Check the "ignore this entry" flag
je cm_skip_entry
cm_no_text:
mov %es:8(%di), %ecx // lower half of length
or %es:12(%di), %ecx // now, full length
jz cm_skip_entry
inc %bp // one more valid entry
// make sure we don't overflow our space
cmpw $MMAP_MAX_ENTS, %bp
jge cm_end_of_list
// we're ok - move the pointer to the next struct in the array
add $24, %di
cm_skip_entry:
// are there more entries to retrieve?
testl %ebx, %ebx
jne cm_loop
cm_end_of_list:
// All done! Store the number of elements in 0x2D00
movw %bp, %ds:0x0
clc // Clear the carry bit and return
jmp cm_ret
cm_failed:
movl $-1, %ds:0x0 // indicate failure
stc
cm_ret:
// restore everything we saved
// popaw won't work here (still in real mode!)
popw %di
popw %si
popw %dx
popw %cx
popw %bx
popw %ax
popw %es
popw %ds
ret
#endif
/*
** The GDT. This cannot be created in C because the bootstrap is not
** linked with that code. We could just have a simple "dummy" GDT here
** but that would only save us a couple of entries. Also, we could save
** some space by not having the separate 'linear' and 'stack' entries
** (they're identical to the 'data' entry).
*/
.p2align 2 // force 4-byte alignment
start_gdt:
// selector 0x0000 is unused
SEGNULL
// selector 0x0008 - basic linear access to all of memory
SEGMENT( 0x0, 0xffffffff, SEG_DPL_0, SEG_DATA_RW )
// selector 0x0010 - kernel code segment
SEGMENT( 0x0, 0xffffffff, SEG_DPL_0, SEG_CODE_XR )
// selector 0x0018 - kernel data segment
SEGMENT( 0x0, 0xffffffff, SEG_DPL_0, SEG_DATA_RW )
// selector 0x0020 - kernel stack segment
SEGMENT( 0x0, 0xffffffff, SEG_DPL_0, SEG_DATA_RW )
// could put additional entries here for user mode - e.g.,
// 0x0028 code: SEGMENT( 0x0, 0xffffffff, SEG_DPL_3, SEG_CODE_XR )
// 0x0030 data: SEGMENT( 0x0, 0xffffffff, SEG_DPL_3, SEG_DATA_RW )
// 0x0038 stack: SEGMENT( 0x0, 0xffffffff, SEG_DPL_3, SEG_DATA_RW )
end_gdt:
gdt_len = end_gdt - start_gdt
/*
** The end of this program will contain a list of the sizes and load
** addresses of all of the blocks to be loaded. These values are
** inserted here by the BuildImage program, which checks that there are
** not so many blocks that the GDT would be overwritten. The layout
** of the data is:
**
** struct info_s {
** short offset;
** short segment;
** short sectors;
** };
**
** with the data for the first program at k_off, k_seg, and k_sect.
** If additional blocks are to be loaded, their values appear just
** before the previous set.
*/
.org BOOT_SIZE-12
u_off: .word 0 // the "user blob"
u_seg: .word 0
u_sect: .word 0
k_off: .word 0 // the kernel
k_seg: .word 0
k_sect: .word 0

View file

@ -1,9 +0,0 @@
OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
OUTPUT_ARCH(i386)
ENTRY(bootentry)
SECTIONS
{
. = 0x0;
.text : { *(.text .stub .text.*) }
}

View file

@ -1,302 +0,0 @@
/*
** @file arch.h
**
** @author Warren R. Carithers
** @author K. Reek
**
** Definitions of constants and macros for use
** with the x86 architecture and registers.
**
*/
#ifndef X86ARCH_H_
#define X86ARCH_H_
/*
** Video stuff
*/
#define VID_BASE_ADDR 0xB8000
/*
** Memory management
*/
#define SEG_PRESENT 0x80
#define SEG_PL_0 0x00
#define SEG_PL_1 0x20
#define SEG_PL_2 0x40
#define SEG_PL_3 0x50
#define SEG_SYSTEM 0x00
#define SEG_NON_SYSTEM 0x10
#define SEG_32BIT 0x04
#define DESC_IGATE 0x06
/*
** Exceptions
*/
#define N_EXCEPTIONS 256
/*
** Bit definitions in registers
**
** See IA-32 Intel Architecture SW Dev. Manual, Volume 3: System
** Programming Guide, page 2-8.
*/
/*
** EFLAGS
*/
#define EFL_RSVD 0xffc00000 /* reserved */
#define EFL_MB0 0x00008020 /* must be zero */
#define EFL_MB1 0x00000002 /* must be 1 */
#define EFL_ID 0x00200000
#define EFL_VIP 0x00100000
#define EFL_VIF 0x00080000
#define EFL_AC 0x00040000
#define EFL_VM 0x00020000
#define EFL_RF 0x00010000
#define EFL_NT 0x00004000
#define EFL_IOPL 0x00003000
#define EFL_OF 0x00000800
#define EFL_DF 0x00000400
#define EFL_IF 0x00000200
#define EFL_TF 0x00000100
#define EFL_SF 0x00000080
#define EFL_ZF 0x00000040
#define EFL_AF 0x00000010
#define EFL_PF 0x00000004
#define EFL_CF 0x00000001
/*
** CR0, CR1, CR2, CR3, CR4
**
** IA-32 V3, page 2-12.
*/
#define CR0_RSVD 0x1ffaffc0
#define CR0_PG 0x80000000
#define CR0_CD 0x40000000
#define CR0_NW 0x20000000
#define CR0_AM 0x00040000
#define CR0_WP 0x00010000
#define CR0_NE 0x00000020
#define CR0_ET 0x00000010
#define CR0_TS 0x00000008
#define CR0_EM 0x00000004
#define CR0_MP 0x00000002
#define CR0_PE 0x00000001
#define CR1_RSVD 0xffffffff
#define CR2_RSVD 0x00000000
#define CR2_PF_LIN_ADDR 0xffffffff
#define CR3_RSVD 0x00000fe7
#define CR3_PD_BASE 0xfffff000
#define CR3_PCD 0x00000010
#define CR3_PWT 0x00000008
#define CR4_RSVD 0xfd001000
#define CR4_UINT 0x02000000
#define CR4_PKS 0x01000000
#define CR4_CET 0x00800000
#define CR4_PKE 0x00400000
#define CR4_SMAP 0x00200000
#define CR4_SMEP 0x00100000
#define CR4_KL 0x00080000
#define CR4_OSXS 0x00040000
#define CR4_PCID 0x00020000
#define CR4_FSGS 0x00010000
#define CR4_SMXE 0x00004000
#define CR4_VMXE 0x00002000
#define CR4_LA57 0x00001000
#define CR4_UMIP 0x00000800
#define CR4_OSXMMEXCPT 0x00000400
#define CR4_OSFXSR 0x00000200
#define CR4_PCE 0x00000100
#define CR4_PGE 0x00000080
#define CR4_MCE 0x00000040
#define CR4_PAE 0x00000020
#define CR4_PSE 0x00000010
#define CR4_DE 0x00000008
#define CR4_TSD 0x00000004
#define CR4_PVI 0x00000002
#define CR4_VME 0x00000001
/*
** PMode segment selector field masks
**
** IA-32 V3, page 3-8.
*/
#define SEG_SEL_IX_MASK 0xfff8
#define SEG_SEL_TI_MASK 0x0004
#define SEG_SEL_RPL_MASK 0x0003
/*
** Segment descriptor bytes
**
** IA-32 V3, page 3-10.
**
** Bytes:
** 0, 1: segment limit 15:0
** 2, 3: base address 15:0
** 4: base address 23:16
** 7: base address 31:24
*/
/*
** Byte 5: access control bits
** 7: present
** 6-5: DPL
** 4: system/user
** 3-0: type
*/
#define SEG_ACCESS_P_MASK 0x80
#define SEG_PRESENT 0x80
#define SEG_NOT_PRESENT 0x00
#define SEG_ACCESS_DPL_MASK 0x60
#define SEG_DPL_0 0x00
#define SEG_DPL_1 0x20
#define SEG_DPL_2 0x40
#define SEG_DPL_3 0x60
#define SEG_ACCESS_S_MASK 0x10
#define SEG_SYSTEM 0x00
#define SEG_NON_SYSTEM 0x10
#define SEG_TYPE_MASK 0x0f
#define SEG_DATA_A_BIT 0x1
#define SEG_DATA_W_BIT 0x2
#define SEG_DATA_E_BIT 0x4
#define SEG_CODE_A_BIT 0x1
#define SEG_CODE_R_BIT 0x2
#define SEG_CODE_C_BIT 0x4
#define SEG_DATA_RO 0x0
#define SEG_DATA_ROA 0x1
#define SEG_DATA_RW 0x2
#define SEG_DATA_RWA 0x3
#define SEG_DATA_RO_XD 0x4
#define SEG_DATA_RO_XDA 0x5
#define SEG_DATA_RW_XW 0x6
#define SEG_DATA_RW_XWA 0x7
#define SEG_CODE_XO 0x8
#define SEG_CODE_XOA 0x9
#define SEG_CODE_XR 0xa
#define SEG_CODE_XRA 0xb
#define SEG_CODE_XO_C 0xc
#define SEG_CODE_XO_CA 0xd
#define SEG_CODE_XR_C 0xe
#define SEG_CODE_XR_CA 0xf
/*
** Byte 6: sizes
** 7: granularity
** 6: d/b
** 5: long mode
** 4: available!
** 3-0: upper 4 bits of limit
** 7: base address 31:24
*/
#define SEG_SIZE_G_MASK 0x80
#define SEG_GRAN_BYTE 0x00
#define SEG_GRAN_4KBYTE 0x80
#define SEG_SIZE_D_B_MASK 0x40
#define SEG_DB_16BIT 0x00
#define SEG_DB_32BIT 0x40
#define SEG_SIZE_L_MASK 0x20
#define SEG_L_64BIT 0x20
#define SEG_L_32BIT 0x00
#define SEG_SIZE_AVL_MASK 0x10
#define SEG_SIZE_LIM_19_16_MASK 0x0f
/*
** System-segment and gate-descriptor types
**
** IA-32 V3, page 3-15.
*/
// type 0: reserved
#define SEG_SYS_16BIT_TSS_AVAIL 0x1
#define SEG_SYS_LDT 0x2
#define SEG_SYS_16BIT_TSS_BUSY 0x3
#define SEG_SYS_16BIT_CALL_GATE 0x4
#define SEG_SYS_TASK_GATE 0x5
#define SEG_SYS_16BIT_INT_GATE 0x6
#define SEG_SYS_16BIT_TRAP_GATE 0x7
// type 8: reserved
#define SEG_SYS_32BIT_TSS_AVAIL 0x9
// type A: reserved
#define SEG_SYS_32BIT_TSS_BUSY 0xb
#define SEG_SYS_32BIT_CALL_GATE 0xc
// type D: reserved
#define SEG_SYS_32BIT_INT_GATE 0xe
#define SEG_SYS_32BIT_TRAP_GATE 0xf
/*
** IDT Descriptors
**
** IA-32 V3, page 5-13.
**
** All have a segment selector in bytes 2 and 3; Task Gate descriptors
** have bytes 0, 1, 4, 6, and 7 reserved; others have bytes 0, 1, 6,
** and 7 devoted to the 16 bits of the Offset, with the low nybble of
** byte 4 reserved.
*/
#define IDT_PRESENT 0x8000
#define IDT_DPL_MASK 0x6000
#define IDT_DPL_0 0x0000
#define IDT_DPL_1 0x2000
#define IDT_DPL_2 0x4000
#define IDT_DPL_3 0x6000
#define IDT_GATE_TYPE 0x0f00
#define IDT_TASK_GATE 0x0500
#define IDT_INT16_GATE 0x0600
#define IDT_INT32_GATE 0x0e00
#define IDT_TRAP16_GATE 0x0700
#define IDT_TRAP32_GATE 0x0f00
/*
** Interrupt vectors
*/
// predefined by the architecture
#define VEC_DIVIDE_ERROR 0x00
#define VEC_DEBUG_EXCEPTION 0x01
#define VEC_NMI_INTERRUPT 0x02
#define VEC_BREAKPOINT 0x03
#define VEC_OVERFLOW 0x04
#define VEC_BOUND_RANGE_EXCEEDED 0x05
#define VEC_INVALID_OPCODE 0x06
#define VEC_DEVICE_NOT_AVAILABLE 0x07
#define VEC_DOUBLE_FAULT 0x08
#define VEC_COPROCESSOR_OVERRUN 0x09
#define VEC_INVALID_TSS 0x0a
#define VEC_SEGMENT_NOT_PRESENT 0x0b
#define VEC_STACK_FAULT 0x0c
#define VEC_GENERAL_PROTECTION 0x0d
#define VEC_PAGE_FAULT 0x0e
// 0x0f is reserved - unused
#define VEC_FPU_ERROR 0x10
#define VEC_ALIGNMENT_CHECK 0x11
#define VEC_MACHINE_CHECK 0x12
#define VEC_SIMD_FP_EXCEPTION 0x13
#define VEC_VIRT_EXCEPTION 0x14
#define VEC_CTRL_PROT_EXCEPTION 0x15
// 0x16 through 0x1f are reserved
// 0x20 through 0xff are user-defined, non-reserved
// IRQ0 through IRQ15 will use vectors 0x20 through 0x2f
#define VEC_TIMER 0x20
#define VEC_KBD 0x21
#define VEC_COM2 0x23
#define VEC_COM1 0x24
#define VEC_PARALLEL 0x25
#define VEC_FLOPPY 0x26
#define VEC_MYSTERY 0x27
#define VEC_MOUSE 0x2c
#endif

View file

@ -1,73 +0,0 @@
/*
** @file bios.h
**
** @author Warren R. Carithers
**
** BIOS-related declarations
*/
#ifndef BIOS_H_
#define BIOS_H_
/*
** BIOS-related memory addresses
*/
#define BIOS_BDA 0x0400
/*
** Selected BIOS interrupt numbers
*/
#define BIOS_TIMER 0x08
#define BIOS_KBD 0x09
#define BIOS_VIDEO 0x10
#define BIOS_EQUIP 0x11
#define BIOS_MSIZ 0x12
#define BIOS_DISK 0x13
#define BIOS_SERIAL 0x14
#define BIOS_MISC 0x15
#define BIOS_KBDSVC 0x16
#define BIOS_PRTSVC 0x17
#define BIOS_BOOT 0x19
#define BIOS_RTCPCI 0x1a
// BIOS video commands (AH)
#define BV_W_ADV 0x0e
// BIOS disk commands (AH)
#define BD_RESET 0x00
#define BD_CHECK 0x01
#define BD_RDSECT 0x02
#define BD_WRSECT 0x03
#define BD_PARAMS 0x08
// BIOS disk commands with parameters (AX)
#define BD_READ(n) ((BD_RDSECT << 8) | (n))
#define BD_READ1 0x0201
// CMOS ports (used for masking NMIs)
#define CMOS_ADDR 0x70
#define CMOS_DATA 0x71
// important related commands
#define NMI_ENABLE 0x00
#define NMI_DISABLE 0x80
/*
** Physical Memory Map Table (0000:2D00 - 0000:7c00)
**
** Primarily used with the BIOS_MISC interrupt
*/
#define MMAP_SEG 0x02D0
#define MMAP_DISP 0x0000
#define MMAP_ADDR ((MMAP_SEG << 4) + MMAP_DISP)
#define MMAP_SECTORS 0x0a
#define MMAP_ENT 24 /* bytes per entry */
#define MMAP_MAX_ENTS (BOOT_ADDR - MMAP_ADDR - 4) / 24
#define MMAP_CODE 0xE820 /* int 0x15 code */
#define MMAP_MAGIC_NUM 0x534D4150 /* for 0xE820 interrupt */
#endif

View file

@ -1,115 +0,0 @@
/*
** SCCS ID: @(#)bootstrap.h 2.4 1/22/25
**
** @file bootstrap.h
**
** @author K. Reek
** @author Warren R. Carithers, Garrett C. Smith
**
** Addresses where various stuff goes in memory.
*/
#ifndef BOOTSTRAP_H_
#define BOOTSTRAP_H_
/*
** The boot device
*/
#define BDEV_FLOPPY 0x00
#define BDEV_USB 0x80 /* hard drive */
#define BDEV BDEV_USB /* default */
/*
** Bootstrap definitions
*/
#define BOOT_SEG 0x07c0 /* 07c0:0000 */
#define BOOT_DISP 0x0000
#define BOOT_ADDR (BOOT_SEG << 4 + BOOT_DISP)
#define PART2_DISP 0x0200 /* 07c0:0200 */
#define PART2_ADDR (BOOT_SEG << 4 + PART2_DISP)
#define SECTOR_SIZE 0x200 /* 512 bytes */
/* Note: this assumes the bootstrap is two sectors long! */
#define BOOT_SIZE (SECTOR_SIZE + SECTOR_SIZE)
#define OFFSET_LIMIT (0x10000 - SECTOR_SIZE)
#define BOOT_SP_DISP 0x4000 /* stack pointer 07c0:4000, or 0xbc00 */
#define BOOT_SP_ADDR (BOOT_SEG << 4 + BOOT_SP_DISP)
#define SECTOR1_END (BOOT_ADDR + SECTOR_SIZE)
#define SECTOR2_END (BOOT_ADDR + BOOT_SIZE)
/*
** The target program itself
*/
#define TARGET_SEG 0x00001000 /* 1000:0000 */
#define TARGET_ADDR 0x00010000 /* and upward */
#define TARGET_STACK 0x00010000 /* and downward */
/*
** The Global Descriptor Table (0000:0500 - 0000:2500)
*/
#define GDT_SEG 0x00000050
#define GDT_ADDR 0x00000500
/* segment register values */
#define GDT_LINEAR 0x0008 /* All of memory, R/W */
#define GDT_CODE 0x0010 /* All of memory, R/E */
#define GDT_DATA 0x0018 /* All of memory, R/W */
#define GDT_STACK 0x0020 /* All of memory, R/W */
/*
** The Interrupt Descriptor Table (0000:2500 - 0000:2D00)
*/
#define IDT_SEG 0x00000250
#define IDT_ADDR 0x00002500
/*
** Additional I/O ports used by the bootstrap code
*/
// keyboard controller
#define KBD_DATA 0x60
#define KBD_CMD 0x64
#define KBD_STAT 0x64
// status register bits
#define KBD_OBSTAT 0x01
#define KBD_IBSTAT 0x02
#define KBD_SYSFLAG 0x04
#define KBD_CMDDAT 0x08
// commands
#define KBD_P1_DISABLE 0xad
#define KBD_P1_ENABLE 0xae
#define KBD_RD_OPORT 0xd0
#define KBD_WT_OPORT 0xd1
#ifdef ASM_SRC
// segment descriptor macros for use in assembly source files
// layout:
// .word lower 16 bits of limit
// .word lower 16 bits of base
// .byte middle 8 bits of base
// .byte type byte
// .byte granularity byte
// .byte upper 8 bits of base
// we use 4K units, so we ignore the lower 12 bits of the limit
#define SEGNULL .word 0, 0, 0, 0
#define SEGMENT(base, limit, dpl, type) \
.word(((limit) >> 12) & 0xffff); \
.word((base) & 0xffff); \
.byte(((base) >> 16) & 0xff); \
.byte(SEG_PRESENT | (dpl) | SEG_NON_SYSTEM | (type)); \
.byte(SEG_GRAN_4KBYTE | SEG_DB_32BIT | (((limit) >> 28) & 0xf)); \
.byte(((base) >> 24) & 0xff)
#endif /* ASM_SRC */
#endif