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 { SECTIONS {
.text 0x7C00: { .text 0x7C00: {
lboot.o(.text) lboot.o(.text)
*(.text, .rodata*) *(.text*, .rodata*)
} :all } :all
.data : { .data : {
*(.data) *(.data*)
} :all } :all
_bss_start = .;
.bss (NOLOAD) : { .bss (NOLOAD) : {
*(.bss, COMMON) _bss_start = .;
*(COMMON)
*(.bss)
. = ALIGN(4K); . = ALIGN(4K);
*(.bootboot) *(.bootboot)
_bss_end = .;
} :all } :all
_bss_end = .;
} }

158
lboot.S
View file

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