clang-format -i *.cc *.c *.h

This commit is contained in:
2025-09-29 18:54:48 +02:00
parent f3057e92be
commit f1b2902640
8 changed files with 194 additions and 249 deletions

View File

@@ -19,8 +19,7 @@ uint16_t crc16(int data_len) {
return crc;
}
asm (
".global main \n"
asm(".global main \n"
"main: \n"
" push %bp \n"
" mov %sp, %bp \n"
@@ -31,5 +30,4 @@ asm (
" mov 6(%bp), %di \n"
" mov %ax, (%di) \n"
" pop %bp \n"
" lret $4 \n"
);
" lret $4 \n");

6
crt0.c
View File

@@ -3,8 +3,7 @@
int main();
asm (
".section .init \n"
asm(".section .init \n"
".global _start \n"
"_start: \n\t"
"mov %cs, %ax \n\t"
@@ -15,8 +14,7 @@ asm (
"mov $0x1000, %ax \n\t"
"mov %ax, %sp \n\t"
"sti \n\t"
"jmp main"
);
"jmp main");
void* memset(void* ptr, int val, size_t len) {
uint8_t* p = ptr;

View File

@@ -8,7 +8,6 @@
#define kRootDirSizeSectors 7
#define kDataRegionStartSector (1 + kFatSizeSectors * 2 + kRootDirSizeSectors)
typedef struct {
char name[8];
char ext[3];
@@ -38,8 +37,8 @@ static int readsector(int c, int h, int s, uint8_t* addr) {
for (int i = 0; i < 3; i++) {
asm volatile("int $0x13"
: "=r"(ret)
: "r" (dest), "r" (nsects), "r" (func), "r" (sect),
"r" (cyl), "r" (head), "r" (drive), "r" (seg));
: "r"(dest), "r"(nsects), "r"(func), "r"(sect), "r"(cyl),
"r"(head), "r"(drive), "r"(seg));
if (ret != 0x80) {
break;
}
@@ -59,7 +58,8 @@ static int readcluster(int cluster) {
}
static void cluster2chs(int cluster, int* c, int* h, int* s) {
int logicalsector = kDataRegionStartSector + (cluster - 2) * kSectorsPerCluster;
int logicalsector =
kDataRegionStartSector + (cluster - 2) * kSectorsPerCluster;
*s = (logicalsector % kSectorsPerTrack) + 1;
*h = (logicalsector / kSectorsPerTrack) % kHeads;
*c = logicalsector / (kHeads * kSectorsPerTrack);

View File

@@ -7,15 +7,12 @@
#define kFatAddress ((void*)0x1000)
#define kRootDirAddress ((void*)0x1200)
static int putchar(int c) {
register uint8_t khar asm("al") = c;
register uint8_t func asm("ah") = 0x0e;
register uint8_t page asm("bh") = 0;
asm volatile ("int $0x10"
:: "r" (khar), "r" (func), "r" (page)
: "bp");
asm volatile("int $0x10" ::"r"(khar), "r"(func), "r"(page) : "bp");
return c;
}
@@ -27,37 +24,30 @@ static int puts(const char* msg) {
return 0;
}
__attribute__((noreturn))
static void die(const char* msg) {
__attribute__((noreturn)) static void die(const char* msg) {
puts(msg);
while (1) {
}
__builtin_unreachable();
}
__attribute__((noreturn))
static void jump(void* addr) {
__attribute__((noreturn)) static void jump(void* addr) {
asm volatile("ljmp $0,%0" ::"i"(addr));
__builtin_unreachable();
}
__attribute__((noreturn))
static void loadpolmon() {
__attribute__((noreturn)) static void loadpolmon() {
if (fat12_init(kFatAddress, kRootDirAddress)) {
die("fi");
}
while (fat12_readfile("POLIO COM", kPolmonAddress)) {
asm volatile (
"mov $00, %%ah \n\t"
"int $0x16 \n\t"
::: "ax"
);
asm volatile("mov $00, %%ah \n\t"
"int $0x16 \n\t" ::
: "ax");
}
jump(kPolmonAddress);
}
int main() {
loadpolmon();
}
int main() { loadpolmon(); }

View File

@@ -47,8 +47,7 @@ uint8_t paracomm_nextbyte() {
mosi_sent = 0;
mosi_state = 2;
return mosi_size;
case 2:
{
case 2: {
uint8_t b = mosi_sendbuf[mosi_sent];
mosi_sent += 1;
@@ -83,8 +82,7 @@ void paracomm_feed(uint8_t n) {
miso_received_nibbles = 0;
miso_state = 3;
break;
case 3:
{
case 3: {
uint8_t idx = miso_received_nibbles / 2;
if (miso_received_nibbles % 2 == 0) {
miso_recvbuf[idx] = n;
@@ -99,8 +97,7 @@ void paracomm_feed(uint8_t n) {
}
miso_state = 0;
}
}
break;
} break;
}
}

View File

@@ -44,26 +44,20 @@ namespace {
int getchar() {
register char c asm("al");
asm volatile (
"movb $0x00, %%ah\n\t"
asm volatile("movb $0x00, %%ah\n\t"
"int $0x16"
: "=r" (c)
:: "ah", "cc"
);
: "=r"(c)::"ah", "cc");
return c;
}
void putchar(int c) {
asm volatile (
"push %%bp \n\t"
asm volatile("push %%bp \n\t"
"mov %0, %%ax \n\t"
"movb $0x0e, %%ah \n\t"
"movb $0, %%bh \n\t"
"int $0x10 \n\t"
"pop %%bp \n\t"
:: "r" (c)
: "ax", "bh", "cc"
);
"pop %%bp \n\t" ::"r"(c)
: "ax", "bh", "cc");
}
#endif // WOZMON
@@ -72,8 +66,7 @@ constexpr int kDumpSize = 16;
// arguments on the stack in reverse order
extern "C" uint16_t Int80h(uint8_t fun, int nargs);
asm (
".section .text.Int80h \n"
asm(".section .text.Int80h \n"
"Int80h: \n"
" push %si \n"
" push %bp \n"
@@ -119,13 +112,9 @@ uint16_t ReadUintN(int n, const char* buf) {
return out;
}
uint8_t ReadUint8(const char* buf) {
return ReadUintN(2, buf);
}
uint8_t ReadUint8(const char* buf) { return ReadUintN(2, buf); }
uint16_t ReadUint16(const char* buf) {
return ReadUintN(4, buf);
}
uint16_t ReadUint16(const char* buf) { return ReadUintN(4, buf); }
void WriteHexNibble(uint8_t c) {
if (c > 9) {
@@ -149,11 +138,7 @@ uint8_t __get_far_u8__(uint16_t addr, uint16_t seg) {
register uint16_t ad asm("si") = addr;
register uint16_t sg asm("ds") = seg;
register uint8_t ret asm("al");
asm (
"lodsb \n\t"
: "=r" (ret)
: "r" (ad), "r" (sg)
);
asm("lodsb \n\t" : "=r"(ret) : "r"(ad), "r"(sg));
return ret;
}
@@ -161,20 +146,13 @@ void __set_far_u8__(uint16_t addr, uint16_t seg, uint8_t val) {
register uint16_t ad asm("di") = addr;
register uint16_t sg asm("es") = seg;
register uint8_t v asm("al") = val;
asm (
"stosb \n\t"
:: "r" (sg), "r" (ad), "r" (v)
: "memory"
);
asm("stosb \n\t" ::"r"(sg), "r"(ad), "r"(v) : "memory");
}
__attribute__((noreturn))
inline static void __basic__() {
asm volatile (
"movw $0x40, %ax \n\t"
__attribute__((noreturn)) inline static void __basic__() {
asm volatile("movw $0x40, %ax \n\t"
"mov %ax, %ds \n\t"
"int $0x18"
);
"int $0x18");
__builtin_unreachable();
}
@@ -213,16 +191,13 @@ void DumpHex(uint16_t addr, uint16_t seg) {
}
void ClearScreen() {
asm volatile (
"movw $0x0002, %%ax \n\t"
"int $0x10"
::: "ax", "cc"
);
asm volatile("movw $0x0002, %%ax \n\t"
"int $0x10" ::
: "ax", "cc");
}
void Status(uint8_t status) {
asm volatile (
"xorb %%bh, %%bh \n\t"
asm volatile("xorb %%bh, %%bh \n\t"
"movb $0x03, %%ah \n\t"
"int $0x10 \n\t"
"mov %%dx, %%di \n\t"
@@ -233,10 +208,9 @@ void Status(uint8_t status) {
"call %1 \n\t"
"movb $0x02, %%ah \n\t"
"movw %%di, %%dx \n\t"
"int $0x10"
:: "rm" (status), "l" (WriteUint8)
: "ax", "bh", "dx", "cx", "di", "cc"
);
"int $0x10" ::"rm"(status),
"l"(WriteUint8)
: "ax", "bh", "dx", "cx", "di", "cc");
}
bool ParseCommand(const char* buf, uint16_t& cur_addr, uint16_t& cur_seg) {
@@ -274,11 +248,8 @@ bool ParseCommand(const char* buf, uint16_t& cur_addr, uint16_t& cur_seg) {
ptr += 4;
}
uint16_t ret = Int80h(fun, nargs);
asm volatile (
"shl %0 \n\t"
"add %0, %%sp"
:: "r"(nargs)
);
asm volatile("shl %0 \n\t"
"add %0, %%sp" ::"r"(nargs));
WriteUint16(ret);
putchar('\r');
putchar('\n');
@@ -368,13 +339,10 @@ void polmon() {
} // namespace
int main() {
polmon();
}
int main() { polmon(); }
#if BOOTSTRAP
__attribute__((section(".init"), noreturn, used))
void _start() {
__attribute__((section(".init"), noreturn, used)) void _start() {
main();
__builtin_unreachable();
}

View File

@@ -1,25 +1,19 @@
int getchar() {
register char c asm("al");
asm volatile (
"movb $0x00, %%ah\n\t"
asm volatile("movb $0x00, %%ah\n\t"
"int $0x16"
: "=r" (c)
:: "ah", "cc"
);
: "=r"(c)::"ah", "cc");
return c;
}
int putchar(int c) {
asm volatile (
"push %%bp \n\t"
asm volatile("push %%bp \n\t"
"mov %0, %%ax \n\t"
"movb $0x0e, %%ah \n\t"
"movb $0, %%bh \n\t"
"int $0x10 \n\t"
"pop %%bp \n\t"
:: "r" (c)
: "ax", "bh", "cc"
);
"pop %%bp \n\t" ::"r"(c)
: "ax", "bh", "cc");
return 0;
}