Fix building C code for 32 bit mode; BIOS string printing

This commit is contained in:
Thomas Oltmann 2026-02-18 00:57:22 +01:00
parent 441d5ef570
commit 68d47cd451
3 changed files with 37 additions and 24 deletions

View file

@ -1,4 +1,8 @@
#include <stdint.h> //#include <stdint.h>
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
#define COM1_BASE_PORT 0x3F8 #define COM1_BASE_PORT 0x3F8
@ -35,15 +39,14 @@ void serial_write(const char *msg)
} }
} }
extern void writechar(); extern void bios_write(const char *msg, unsigned length);
void void
main() main()
{ {
serial_write("init\r\n"); bios_write("init\r\n", 6);
writechar(); bios_write("karlos\r\n", 8);
serial_write("foo\r\n");
for (;;) { for (;;) {
//__asm__ ("hlt" :); __asm__ ("hlt" :);
} }
} }

38
Rnbp.S
View file

@ -71,15 +71,6 @@ _start: cli
mov %ss, %ax mov %ss, %ax
mov %ax, real_ss mov %ax, real_ss
push $msg_start
call dbgmsg
add $2, %sp
xor %bx, %bx
mov $0x0E, %ah
mov $'B', %al
int $0x10
// initialize our own BSS section // initialize our own BSS section
mov $_bss_start, %di mov $_bss_start, %di
mov $_bss_end, %cx mov $_bss_end, %cx
@ -133,22 +124,38 @@ dbgmsg: push %bp
pop %bp pop %bp
ret ret
.global writechar .global bios_write
.code32 .code32
writechar: push %ebp bios_write: push %ebp
mov %esp, %ebp mov %esp, %ebp
push %ebx push %ebx
mov 8+0(%ebp), %edx
mov 8+4(%ebp), %ecx
PROT16 PROT16
.code16 .code16
REAL REAL
.bwloop: test %ecx, %ecx
jz .bwreturn
xor %bx, %bx xor %bx, %bx
mov $0x0E, %ah mov $0x0E, %ah
mov $'A', %al mov (%edx), %al
int $0x10
PROT push %ecx
push %edx
int $0x10
pop %edx
pop %ecx
add $1, %edx
sub $1, %ecx
jmp .bwloop
.bwreturn: PROT
PROT32 PROT32
.code32 .code32
@ -176,7 +183,8 @@ GDT: // entry 0: null descriptor
// TODO: 32-bit TSS // TODO: 32-bit TSS
.set GDT_SIZE, . - GDT .set GDT_SIZE, . - GDT
GDT_PTR: .word GDT_SIZE - 1 GDT_PTR: .word GDT_SIZE - 1
.quad GDT .word GDT
.word 0, 0, 0
msg_start: .asciz "Netboot via fernlader v2 ...\r\n" msg_start: .asciz "Netboot via fernlader v2 ...\r\n"
msg_a20: .asciz " * Enabling A20 Gate\r\n" msg_a20: .asciz " * Enabling A20 Gate\r\n"

View file

@ -1,5 +1,7 @@
CC = cc #CC = /usr/local/x86_64-karlos-toolchain/bin/x86_64-karlos-gcc
#LD = /usr/local/x86_64-karlos-toolchain/bin/x86_64-karlos-ld
CC = gcc
LD = ld LD = ld
CFLAGS = -no-pie -fno-pic -fno-stack-protector CFLAGS = -no-pie -fno-pic -fno-stack-protector -nostdinc -m32
LDFLAGS = -Tfernlader.ld LDFLAGS = -Tfernlader.ld -m elf_i386