More general cleanup

This commit is contained in:
Thomas Oltmann 2025-07-17 08:26:46 +02:00
parent 68eb1914b1
commit 4e6c29c621
2 changed files with 66 additions and 103 deletions

View file

@ -5,16 +5,17 @@ PHDRS {
SECTIONS {
.text 0x7C00: {
lboot.o(.text)
*(.text, .rodata*)
*(.text*, .rodata*)
} :all
.data : {
*(.data)
*(.data*)
} :all
_bss_start = .;
.bss (NOLOAD) : {
*(.bss, COMMON)
_bss_start = .;
*(COMMON)
*(.bss)
. = ALIGN(4K);
*(.bootboot)
} :all
_bss_end = .;
} :all
}

158
lboot.S
View file

@ -104,18 +104,18 @@ _start: cli
jmp hang
.set COM1, 0x3F8
.macro com1_write offset=0, byte
.macro COM1_WRITE offset, byte
mov $COM1+\offset, %dx
mov $\byte, %al
outb %al, %dx
.endm
// init_com1: Set up COM1 port for debug output
init_com1: com1_write 1, 0x00 // clear interrupts
com1_write 3, 0x80 // set DLAB to 1
com1_write 0, 0x0C // 9600 baud rate
com1_write 1, 0x00
com1_write 3, 0x07 // 8 bit data + 1 parity bit
init_com1: COM1_WRITE 1, 0x00 // clear interrupts
COM1_WRITE 3, 0x80 // set DLAB to 1
COM1_WRITE 0, 0x0C // 9600 baud rate
COM1_WRITE 1, 0x00
COM1_WRITE 3, 0x07 // 8 bit data + 1 parity bit
ret
// enable_a20: Allow use of 'high' (>1Mb) memory
@ -278,6 +278,18 @@ out_of_mem: mov $msg_memerr, %si
call print
jmp hang
.data
heap_mment: .long tx_buf
.lcomm heap_ptr, 4
.lcomm heap_end, 4
// Long mode initial page tables
.lcomm pd_ptr, 4
.lcomm pdp_ptr, 4
.lcomm pml4_ptr, 4
/***********************************\
* Networked File Access
\***********************************/
@ -287,7 +299,13 @@ out_of_mem: mov $msg_memerr, %si
.set PXE_TFTP_CLOSE, 0x0021
.set PXE_TFTP_READ, 0x0022
.macro pxe_call, opcode
.lcomm pxe_api, 4
.lcomm server_ip, 4
.lcomm gateway_ip, 4
.text
.macro PXE_CALL, opcode
push %eax
push %ebx
push %ecx
@ -345,7 +363,7 @@ pxe_getinfo:push %eax
push $TX_BUF_SIZE
push $2
push $0
pxe_call PXE_GET_CACHED_INFO
PXE_CALL PXE_GET_CACHED_INFO
add $12, %sp
mov tx_buf+20, %eax
mov %eax, server_ip
@ -398,7 +416,7 @@ tftp_open: push %ecx
mov $128, %ecx
call dump
pxe_call PXE_TFTP_OPEN
PXE_CALL PXE_TFTP_OPEN
leave
pop %edi
@ -414,7 +432,7 @@ tftp_close: push %bp
call print
push $0
pxe_call PXE_TFTP_CLOSE
PXE_CALL PXE_TFTP_CLOSE
leave
ret
@ -432,7 +450,7 @@ tftp_read: push %ebx
push $0
push $0
push $0
pxe_call PXE_TFTP_READ
PXE_CALL PXE_TFTP_READ
mov %sp, %bx
mov %ss:4(%bx), %ax
@ -535,12 +553,19 @@ dump: push %eax
pop %eax
ret
.data
hex_digits: .ascii "0123456789ABCDEF"
/***********************************\
* Framebuffer Configuration
\***********************************/
vbe_setup:
push %eax
.lcomm vbe_info, 512
.text
vbe_setup: push %eax
push %ecx
push %esi
push %bp
@ -576,17 +601,13 @@ _vbenext: mov %fs:(%si), %cx
or $0x4000, %bx
call vbe_setmode
jmp _vbedone
_vbedone:
leave
_vbedone: leave
pop %esi
pop %ecx
pop %eax
ret
vbe_getinfo:
push %eax
vbe_getinfo:push %eax
push %edi
push %bp
mov %sp, %bp
@ -598,25 +619,17 @@ vbe_getinfo:
int $0x10
cmp $0x4F, %ax
je 1f
mov $msg_vbeerr, %si
call print
jmp hang
1:
jne _vbeerr
cmpl $0x41534556, vbe_info // "VESA"
je 1f
mov $msg_vbeerr, %si
call print
jmp hang
jne _vbeerr
1: leave
leave
pop %edi
pop %eax
ret
vbe_getmode:
push %eax
vbe_getmode:push %eax
push %edi
push %bp
mov %sp, %bp
@ -626,18 +639,14 @@ vbe_getmode:
int $0x10
cmp $0x4F, %ax
je 1f
mov $msg_vbeerr, %si
call print
jmp hang
jne _vbeerr
1: leave
leave
pop %edi
pop %eax
ret
vbe_setmode:
push %eax
vbe_setmode:push %eax
push %bp
mov %sp, %bp
@ -645,20 +654,15 @@ vbe_setmode:
int $0x10
cmp $0x4F, %ax
je 1f
mov $msg_vbeerr, %si
call print
jmp hang
jne _vbeerr
1: leave
leave
pop %eax
ret
.bss
vbe_info: .space 512
.text
_vbeerr: mov $msg_vbeerr, %si
call print
jmp hang
// long: Enter long mode
long:
@ -701,47 +705,22 @@ hang: hlt
// gdt16: Protected mode / Unreal mode 16-bit GDT
gdt16: // entry 0: null descriptor
.word 0
.word 0
.byte 0
.byte 0
.byte 0
.byte 0
.space 8, 0
// entry 1: code segment
.word 0xFFFF
.word 0
.byte 0
.byte 0b10011010
.byte 0x8F
.byte 0
.byte 0xFF, 0xFF, 0, 0, 0, 0b10011010, 0x8F, 0
// entry 2: data segment
.word 0xFFFF
.word 0
.byte 0
.byte 0b10010010
.byte 0x8F
.byte 0
.byte 0xFF, 0xFF, 0, 0, 0, 0b10010010, 0x8F, 0
.set gdt16_size, .-gdt16
gdt16_ptr: .word gdt16_size-1
.long gdt16
// gdt64: Long mode 64-bit GDT
gdt64: // entry 0: null descriptor
.quad 0
.space 8, 0
// entry 1: code segment
.word 0
.word 0
.byte 0
.byte 0x98
.byte 0x60
.byte 0
.byte 0, 0, 0, 0, 0, 0x98, 0x60, 0
// entry 2: data segment
.word 0
.word 0
.byte 0
.byte 0x92
.byte 0x00
.byte 0
.byte 0, 0, 0, 0, 0, 0x92, 0x00, 0
.set gdt64_size, .-gdt64
gdt64_ptr: .word gdt64_size-1
.quad gdt64
@ -766,25 +745,10 @@ msg_tread: .asciz "tftp_read\r\n"
fn_initrd: .asciz "initrd"
pxe_api: .long 0
server_ip: .space 4
gateway_ip: .space 4
heap_ptr: .long 0
heap_end: .long 0
heap_mment: .long tx_buf
// Long mode initial page tables
pd_ptr: .long 0
pdp_ptr: .long 0
pml4_ptr: .long 0
// Points to the end of the memory map
memmap_end: .short 0
.lcomm memmap_end, 2
.bss
tx_buf: .space TX_BUF_SIZE
.lcomm tx_buf, TX_BUF_SIZE
.code64
.text
@ -848,8 +812,6 @@ type_table: .byte 0
.byte 2
.byte 0
hex_digits: .ascii "0123456789ABCDEF"
.section .bootboot
bootboot: .space 4